diff --git a/deauth_detector/Mac.cpp b/deauth_detector/Mac.cpp index 0e406b3..01b588b 100644 --- a/deauth_detector/Mac.cpp +++ b/deauth_detector/Mac.cpp @@ -6,6 +6,15 @@ Mac::Mac(){ } } +Mac::Mac(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth){ + adress[0] = first; + adress[1] = second; + adress[2] = third; + adress[3] = fourth; + adress[4] = fifth; + adress[5] = sixth; +} + void Mac::set(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth){ adress[0] = first; adress[1] = second; diff --git a/deauth_detector/Mac.h b/deauth_detector/Mac.h index f9eeebe..909c643 100644 --- a/deauth_detector/Mac.h +++ b/deauth_detector/Mac.h @@ -7,6 +7,8 @@ class Mac { public: Mac(); + Mac(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth); + void set(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth); void setAt(uint8_t first, int num); void setMac(Mac adr); @@ -16,6 +18,7 @@ class Mac uint8_t _get(int num); bool compare(Mac target); bool valid(); + private: uint8_t adress[6]; }; diff --git a/deauth_detector/deauth_detector.ino b/deauth_detector/deauth_detector.ino index 4d088f8..1b88b86 100644 --- a/deauth_detector/deauth_detector.ino +++ b/deauth_detector/deauth_detector.ino @@ -6,39 +6,41 @@ extern "C" { } //===== SETTINGS =====// -#define channel 1 //the channel it should scan on (1-14) +#define channel 1 //the channel to start scanning (1-14) #define channelHopping true //scan on all channels -#define maxChannel 13 //US = 11, EU = 13, Japan = 14 +#define maxChannel 11 //US = 11, EU = 13, Japan = 14 #define ledPin 2 //led pin ( 2 = built-in LED) #define inverted true // invert HIGH/LOW for the LED #define packetRate 3 //min. packets before it gets recognized as an attack #define scanTime 500 //scan time per channel in ms - -//Mac from; -//Mac to; -unsigned long c = 0; +unsigned long count = 0; unsigned long prevTime = 0; -unsigned long curTime = 0; int curChannel = channel; -void sniffer(uint8_t *buf, uint16_t len) { - //if(len>27){ - //from.set(buf[16],buf[17],buf[18],buf[19],buf[20],buf[21]); - //to.set(buf[22],buf[23],buf[24],buf[25],buf[26],buf[27]); - - if(buf[12] == 0xA0 || buf[12] == 0xC0){ - /*Serial.print("From "); - from._println(); - Serial.print("To "); - to._println(); - Serial.println();*/ - - c++; - } +void dumpPacket(uint8_t* buf, uint16_t len) { + if(buf == nullptr || len <= 27) + return; - //} + Mac from(buf[16],buf[17],buf[18],buf[19],buf[20],buf[21]); + Mac to(buf[22],buf[23],buf[24],buf[25],buf[26],buf[27]); + + Serial.print("Chan "); + Serial.println(curChannel); + Serial.print("From "); + from._println(); + Serial.print("To "); + to._println(); + Serial.println(); +} + +void sniffer(uint8_t* buf, uint16_t len) { + if(buf == nullptr || len <= 12 || (buf[12] != 0xA0 && buf[12] != 0xC0)) + return; + + count++; + // dumpPacket(buf, len); } void setup() { @@ -54,30 +56,25 @@ void setup() { pinMode(ledPin, OUTPUT); Serial.println("starting!"); - } void loop() { - curTime = millis(); + unsigned long curTime = millis(); + unsigned long delta = curTime - prevTime; + if (delta < scanTime) + delay(scanTime - delta); + + digitalWrite(ledPin, (count >= packetRate) ^ inverted); + + Serial.print(curChannel); + Serial.print(": "); + Serial.println(count); - if(curTime - prevTime >= scanTime){ - prevTime = curTime; - Serial.println((String)c); - - if(c >= packetRate){ - if(inverted) digitalWrite(ledPin, LOW); - else digitalWrite(ledPin, HIGH); - }else{ - if(inverted) digitalWrite(ledPin, HIGH); - else digitalWrite(ledPin, LOW); - } - - c = 0; - if(channelHopping){ - curChannel++; - if(curChannel > maxChannel) curChannel = 1; - wifi_set_channel(curChannel); - } - } + prevTime = curTime; + count = 0; + if(channelHopping){ + curChannel = curChannel % maxChannel + 1; + wifi_set_channel(curChannel); + } }