diff --git a/src/blecount.cpp b/src/blecount.cpp index 3872d360..c5b1a780 100644 --- a/src/blecount.cpp +++ b/src/blecount.cpp @@ -27,6 +27,6 @@ void BLECount() { u8x8.clearLine(3); u8x8.setCursor(0,3); blenum=foundDevices.getCount(); - u8x8.printf("BLE#: %4i",blenum); + u8x8.printf("BLE#: %5i",blenum); } #endif \ No newline at end of file diff --git a/src/globals.h b/src/globals.h index 4d356a7f..18f99c07 100644 --- a/src/globals.h +++ b/src/globals.h @@ -32,9 +32,10 @@ extern configData_t cfg; extern uint8_t mydata[]; extern uint64_t uptimecounter; extern osjob_t sendjob; -extern int macnum, blenum, countermode, screensaver, adrmode, lorasf, txpower, rlim, salt; +extern uint16_t macnum, blenum; +extern int countermode, screensaver, adrmode, lorasf, txpower, rlim, salt; extern bool joinstate; -extern std::set macs; +extern std::set macs; #ifdef HAS_DISPLAY extern HAS_DISPLAY u8x8; diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 85164280..64eea864 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -79,10 +79,10 @@ void printKeys(void) { #endif // VERBOSE void do_send(osjob_t* j){ - mydata[0] = (macnum & 0x0000ff00) >> 8; - mydata[1] = macnum & 0x000000ff; - mydata[2] = (blenum & 0x0000ff00) >> 8; - mydata[3] = blenum & 0x000000ff; + mydata[0] = (macnum & 0xff00) >> 8; + mydata[1] = macnum & 0x00ff; + mydata[2] = (blenum & 0xff00) >> 8; + mydata[3] = blenum & 0x00ff; // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { diff --git a/src/main.cpp b/src/main.cpp index 47b6d84b..0dbc02af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,11 +42,12 @@ configData_t cfg; // struct holds current device configuration osjob_t sendjob, initjob; // LMIC // Initialize global variables -int macnum = 0, blenum = 0, salt; +uint16_t macnum = 0, blenum = 0; +int salt; uint64_t uptimecounter = 0; bool joinstate = false; -std::set macs; // associative container holds filtered MAC adresses +std::set macs; // associative container holds filtered MAC adresses // this variable will be changed in the ISR, and read in main loop static volatile bool ButtonTriggered = false; @@ -211,7 +212,7 @@ void wifi_sniffer_loop(void * pvParameters) { // Prepare and execute LoRaWAN data upload u8x8.setCursor(0,4); - u8x8.printf("MAC#: %4i", macnum); + u8x8.printf("MAC#: %i", macnum); do_send(&sendjob); // send payload vTaskDelay(500/portTICK_PERIOD_MS); yield(); @@ -388,7 +389,7 @@ void setup() { init_display(PROGNAME, PROGVERSION); u8x8.setPowerSave(!cfg.screenon); // set display off if disabled u8x8.setCursor(0,5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit); u8x8.drawString(0,6,"Join Wait "); // output LoRaWAN keys to console diff --git a/src/main.h b/src/main.h index dadeac93..ce960cd2 100644 --- a/src/main.h +++ b/src/main.h @@ -1,5 +1,5 @@ // program version -#define PROGVERSION "1.2.61" // use max 10 chars here! +#define PROGVERSION "1.2.62" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output diff --git a/src/wifisniffer.cpp b/src/wifisniffer.cpp index deb73e60..301e9343 100644 --- a/src/wifisniffer.cpp +++ b/src/wifisniffer.cpp @@ -59,11 +59,12 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff; const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload; const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr; - char counter [11]; // uint32_t -> 4 byte -> 10 decimals + '0' terminator -> 11 chars + 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 - uint32_t hashedmac, vendor2int; uint64_t addr2int; - std::pair::iterator, bool> newmac; + uint32_t vendor2int; + uint16_t hashedmac; + std::pair::iterator, bool> newmac; if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value addr2int = ( (uint64_t)hdr->addr2[0] ) | ( (uint64_t)hdr->addr2[1] << 8 ) | ( (uint64_t)hdr->addr2[2] << 16 ) | \ @@ -78,16 +79,16 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { //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 <<= 8; // left shift out msb of vendor oui 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 + hashedmac = rokkit(macbuf, 5); // hash MAC for privacy, use 5 chars to fit in uint16_t container newmac = macs.insert(hashedmac); // store hashed MAC if new unique if (newmac.second) { // first time seen MAC macnum++; // increment MAC counter itoa(macnum, counter, 10); // base 10 decimal counter value u8x8.draw2x2String(0, 0, counter); - ESP_LOGI(TAG, "RSSI %04d -> Hash %010u -> #%04i", ppkt->rx_ctrl.rssi, hashedmac, macnum); + ESP_LOGI(TAG, "RSSI %04d -> Hash %05u -> #%05i", ppkt->rx_ctrl.rssi, hashedmac, macnum); } else // already seen MAC ESP_LOGI(TAG, "RSSI %04d -> already seen", ppkt->rx_ctrl.rssi);