reduced mac and ble counter to 16bit

This commit is contained in:
Klaus K Wilting 2018-03-31 23:12:27 +02:00
parent 527f47d558
commit cf2a620e8a
6 changed files with 21 additions and 18 deletions

View File

@ -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

View File

@ -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<uint32_t> macs;
extern std::set<uint16_t> macs;
#ifdef HAS_DISPLAY
extern HAS_DISPLAY u8x8;

View File

@ -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) {

View File

@ -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<uint32_t> macs; // associative container holds filtered MAC adresses
std::set<uint16_t> 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

View File

@ -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

View File

@ -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<std::set<uint32_t>::iterator, bool> newmac;
uint32_t vendor2int;
uint16_t hashedmac;
std::pair<std::set<uint16_t>::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);