From c5d82fb1e03149226ccf88c7de60863a690c24dc Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 2 Apr 2018 02:59:55 +0200 Subject: [PATCH] Removed Vendor filter for BLE Scan --- src/macsniff.cpp | 65 ++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 43d9567a..65092091 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -11,9 +11,9 @@ #endif #ifdef VENDORFILTER - #include - #include - #include "vendor_array.h" + #include + #include + #include "vendor_array.h" #endif // Local logging tag @@ -27,8 +27,8 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { char counter [11]; // uint32_t -> 4 byte -> 10 decimals + '0' terminator -> 11 chars char macbuf [21]; // uint64_t -> 8 byte -> 20 decimals + '0' terminator -> 21 chars - char typebuff[8] ; - bool added = false; + char typebuff[8] ; + bool added = false; uint32_t hashedmac, vendor2int; uint64_t addr2int; std::pair::iterator, bool> newmac; @@ -38,35 +38,36 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { #ifdef VENDORFILTER vendor2int = ( (uint32_t)paddr[2] ) | ( (uint32_t)paddr[1] << 8 ) | ( (uint32_t)paddr[0] << 16 ); - if ( std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end() ) { + // No vendor filter for BLE + if ( (sniff_type==MAC_SNIFF_BLE) || std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end() ) { #endif - //if (!(addr2int & WIFI_MAC_FILTER_MASK)) { // filter local and group MACs + //if (!(addr2int & WIFI_MAC_FILTER_MASK)) { // filter local and group MACs - // salt and hash MAC, and if new unique one, store hash in container and increment counter on display - addr2int <<= 8; - addr2int += salt; // append salt value to MAC before hashing it - itoa(addr2int, macbuf, 10); // convert 64 bit MAC to base 10 decimal string - hashedmac = rokkit(macbuf, 10); // hash MAC for privacy, use 10 chars to fit in uint32_t container + // salt and hash MAC, and if new unique one, store hash in container and increment counter on display + addr2int <<= 8; + addr2int += salt; // append salt value to MAC before hashing it + itoa(addr2int, macbuf, 10); // convert 64 bit MAC to base 10 decimal string + hashedmac = rokkit(macbuf, 10); // hash MAC for privacy, use 10 chars to fit in uint32_t container - if (sniff_type == MAC_SNIFF_WIFI ) { - newmac = wifis.insert(hashedmac); // store hashed MAC if new unique - strcpy(typebuff, "WiFi"); - } else if (sniff_type == MAC_SNIFF_BLE ) { - newmac = bles.insert(hashedmac); // store hashed MAC if new unique - strcpy(typebuff, "BLE "); - } + if (sniff_type == MAC_SNIFF_WIFI ) { + newmac = wifis.insert(hashedmac); // store hashed MAC if new unique + strcpy(typebuff, "WiFi"); + } else if (sniff_type == MAC_SNIFF_BLE ) { + newmac = bles.insert(hashedmac); // store hashed MAC if new unique + strcpy(typebuff, "BLE "); + } - if (newmac.second) { // first time seen this WIFI/BLE MAC - // Insert to glbal counter - macs.insert(hashedmac); - added = true; - itoa(macs.size(), counter, 10); // base 10 decimal counter value - u8x8.draw2x2String(0, 0, counter); - ESP_LOGI(TAG, "%s RSSI %04d -> Hash %010u -> #%04i", typebuff, rssi, hashedmac, macs.size()); - } else { - ESP_LOGI(TAG, "%s RSSI %04d -> already seen", typebuff, rssi); - } + if (newmac.second) { // first time seen this WIFI/BLE MAC + // Insert to glbal counter + macs.insert(hashedmac); + added = true; + itoa(macs.size(), counter, 10); // base 10 decimal counter value + u8x8.draw2x2String(0, 0, counter); + ESP_LOGI(TAG, "%s RSSI %04d -> Hash %010u -> #%04i", typebuff, rssi, hashedmac, macs.size()); + } else { + ESP_LOGI(TAG, "%s RSSI %04d -> already seen", typebuff, rssi); + } #ifdef VENDORFILTER } else { @@ -75,7 +76,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { } #endif - // True if MAC (WiFi/BLE was new) + // True if MAC (WiFi/BLE was new) return added; } @@ -94,7 +95,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { }; void BLECount() { - int blenum = 0; // Total device seen on this scan session + int blenum = 0; // Total device seen on this scan session currentScanDevice = 0; // Set 0 seen device on this scan session u8x8.clearLine(3); u8x8.drawString(0,3,"BLE Scan..."); @@ -103,7 +104,7 @@ void BLECount() { pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster BLEScanResults foundDevices = pBLEScan->start(cfg.blescancycle); - blenum=foundDevices.getCount(); + blenum=foundDevices.getCount(); u8x8.clearLine(3); u8x8.setCursor(0,3); u8x8.printf("BLE#: %-5i %-3i",bles.size(), blenum);