some fixes in macsniff.cpp

This commit is contained in:
Klaus K Wilting 2018-04-02 14:34:16 +02:00
parent cbecfb4463
commit 60b1d31f6a
4 changed files with 39 additions and 43 deletions

View File

@ -186,7 +186,8 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
byte 11: BLE scan cycle duration in seconds (0..255)
byte 12: BLE scan mode (1=on, 0=0ff)
byte 13: Wifi antenna switch (0=internal, 1=external)
bytes 14-23: Software version (ASCII format)
byte 14: RGB LED luminosity (0..100 %)
bytes 15-24: Software version (ASCII format)
0x81 get device uptime

View File

@ -28,7 +28,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
char counter [6]; // uint16_t -> 2 byte -> 5 decimals + '0' terminator -> 6 chars
char macbuf [21]; // uint64_t -> 8 byte -> 20 decimals + '0' terminator -> 21 chars
char typebuff[8];
bool added = false;
uint64_t addr2int;
uint32_t vendor2int;
uint16_t hashedmac;
@ -49,25 +48,21 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
addr2int |= (uint64_t) salt << 48; // prepend 16-bit salt to 48-bit MAC
snprintf(macbuf, 21, "%llx", addr2int); // convert unsigned 64-bit salted MAC to 16 digit hex string
hashedmac = rokkit(macbuf, 5); // hash MAC string, use 5 chars to fit hash in uint16_t container
newmac = macs.insert(hashedmac); // store hashed MAC only if first time seen
newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique
if (sniff_type == MAC_SNIFF_WIFI ) {
newmac = wifis.insert(hashedmac); // store hashed MAC if new unique
newmac = wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique
strcpy(typebuff, "WiFi");
} else if (sniff_type == MAC_SNIFF_BLE ) {
newmac = bles.insert(hashedmac); // store hashed MAC if new unique
newmac = bles.insert(hashedmac); // add hashed MAC to BLE container if new unique
strcpy(typebuff, "BLE ");
}
if (newmac.second) { // first time seen this WIFI/BLE MAC
// Insert to global counter
macs.insert(hashedmac);
added = true;
if (newmac.second) { // first time seen this WIFI or BLE MAC
snprintf(counter, 6, "%i", macs.size()); // convert 16-bit MAC counter to decimal counter value
//itoa(macs.size(), counter, 10); // base 10 decimal counter value
u8x8.draw2x2String(0, 0, counter);
ESP_LOGI(TAG, "%s RSSI %04d -> Hash %04x -> #%05i", typebuff, rssi, hashedmac, macs.size());
} else {
} else { // already seen WIFI or BLE MAC
ESP_LOGI(TAG, "%s RSSI %04d -> already seen", typebuff, rssi);
}
@ -78,8 +73,8 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
}
#endif
// True if MAC (WiFi/BLE was new)
return added;
// True if MAC WiFi/BLE was new
return newmac.second;
}
#ifdef BLECOUNTER

View File

@ -49,11 +49,11 @@ int macnum = 0, salt;
uint64_t uptimecounter = 0;
bool joinstate = false;
std::set<uint16_t> macs; // associative container holds filtered total unique MAC adress hashes (Wifi + BLE)
std::set<uint16_t> wifis; // associative container holds filtered Wifi MAC adress hashes
std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE)
std::set<uint16_t> wifis; // associative container holds unique Wifi MAC adress hashes
#ifdef BLECOUNTER
std::set<uint16_t> bles; // associative container holds filtered BLE MAC adresses hashes
std::set<uint16_t> bles; // associative container holds unique BLE MAC adresses hashes
int scanTime;
#endif
@ -250,7 +250,18 @@ void wifi_sniffer_loop(void * pvParameters) {
int nloop=0, lorawait=0;
while (true) {
nloop++;
nloop++; // acutal number of wifi loops
// execute BLE count if BLE function is enabled
#ifdef BLECOUNTER
// Once 2 full Wifi Channels scan, do a BLE scan
if (nloop % (WIFI_CHANNEL_MAX*2) == 0 ) {
// execute BLE count if BLE function is enabled
if (cfg.blescan)
BLECount();
}
#endif
vTaskDelay(cfg.wifichancycle*10 / portTICK_PERIOD_MS);
yield();
wifi_sniffer_set_channel(channel);
@ -264,16 +275,6 @@ void wifi_sniffer_loop(void * pvParameters) {
u8x8.setCursor(0,4);
u8x8.printf("MAC#: %-5i", wifis.size());
// execute BLE count if BLE function is enabled
#ifdef BLECOUNTER
// Once 2 full Wifi Channels scan, do a BLE scan
if (nloop % (WIFI_CHANNEL_MAX*2) == 0 ) {
// execute BLE count if BLE function is enabled
if (cfg.blescan)
BLECount();
}
#endif
// duration of one wifi scan loop reached? then send data and begin new scan cycle
if( nloop >= ((100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) ) {
u8x8.setPowerSave(!cfg.screenon); // set display on if enabled
@ -291,7 +292,6 @@ void wifi_sniffer_loop(void * pvParameters) {
#ifdef BLECOUNTER
bles.clear(); // clear BLE macs counter
#endif
salt = random(65536); // get new 16bit random for salting hashes
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
}
@ -457,7 +457,7 @@ void setup() {
antenna_init();
#endif
// initialize salt value using esp_random() called by random in arduino-esp32 core
// initialize salt value using esp_random() called by random() in arduino-esp32 core
salt = random(65536); // get new 16bit random for salting hashes
// initialize display

View File

@ -1,5 +1,5 @@
// program version
#define PROGVERSION "1.2.71" // use max 10 chars here!
#define PROGVERSION "1.2.8" // use max 10 chars here!
#define PROGNAME "PAXCNT"
// Verbose enables serial output