created first version with hash
This commit is contained in:
parent
b0cd39cafa
commit
df6cb25b38
@ -70,7 +70,9 @@ board = esp32dev
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_baud = 115200
|
monitor_baud = 115200
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
lib_deps = U8g2
|
lib_deps =
|
||||||
|
U8g2
|
||||||
|
ESP32 BLE Arduino@>=0.4.9
|
||||||
build_flags =
|
build_flags =
|
||||||
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||||
|
@ -34,7 +34,7 @@ extern uint64_t uptimecounter;
|
|||||||
extern osjob_t sendjob;
|
extern osjob_t sendjob;
|
||||||
extern int macnum, blenum, countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
extern int macnum, blenum, countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
||||||
extern bool joinstate;
|
extern bool joinstate;
|
||||||
extern std::set<uint64_t> macs;
|
extern std::set<uint32_t> macs;
|
||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
extern HAS_DISPLAY u8x8;
|
extern HAS_DISPLAY u8x8;
|
||||||
|
@ -46,7 +46,7 @@ int macnum = 0, blenum = 0;
|
|||||||
uint64_t uptimecounter = 0;
|
uint64_t uptimecounter = 0;
|
||||||
bool joinstate = false;
|
bool joinstate = false;
|
||||||
|
|
||||||
std::set<uint64_t> macs; // associative container holds filtered MAC adresses
|
std::set<uint32_t> macs; // associative container holds filtered MAC adresses
|
||||||
|
|
||||||
// this variable will be changed in the ISR, and read in main loop
|
// this variable will be changed in the ISR, and read in main loop
|
||||||
static volatile bool ButtonTriggered = false;
|
static volatile bool ButtonTriggered = false;
|
||||||
@ -67,7 +67,6 @@ void eraseConfig(void);
|
|||||||
void saveConfig(void);
|
void saveConfig(void);
|
||||||
void loadConfig(void);
|
void loadConfig(void);
|
||||||
|
|
||||||
|
|
||||||
/* begin LMIC specific parts ------------------------------------------------------------ */
|
/* begin LMIC specific parts ------------------------------------------------------------ */
|
||||||
|
|
||||||
// LMIC enhanced Pin mapping
|
// LMIC enhanced Pin mapping
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// program version
|
// program version
|
||||||
#define PROGVERSION "1.2.53" // use max 10 chars here!
|
#define PROGVERSION "1.2.54" // use max 10 chars here!
|
||||||
#define PROGNAME "PAXCNT"
|
#define PROGNAME "PAXCNT"
|
||||||
|
|
||||||
// Verbose enables serial output
|
// Verbose enables serial output
|
||||||
|
75
src/rokkithash.cpp
Normal file
75
src/rokkithash.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
Porting - 2014 Alex K
|
||||||
|
Algorithm (c) Paul Hsieh http://www.azillionmonkeys.com/qed/hash.html
|
||||||
|
|
||||||
|
|
||||||
|
The latest version of this library may be found at:
|
||||||
|
https://github.com/mrbio/Arduino-rokkit-hash
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
uint32_t rokkit(const char * data, int len) {
|
||||||
|
uint32_t hash, tmp;
|
||||||
|
int rem;
|
||||||
|
|
||||||
|
if (len <= 0 || data == 0) return 0;
|
||||||
|
hash = len;
|
||||||
|
rem = len & 3;
|
||||||
|
len >>= 2;
|
||||||
|
|
||||||
|
/* Main loop */
|
||||||
|
while (len > 0) {
|
||||||
|
hash += *((uint16_t*)data);
|
||||||
|
tmp = (*((uint16_t*)(data+2)) << 11) ^ hash;
|
||||||
|
hash = (hash << 16) ^ tmp;
|
||||||
|
data += 2*2;
|
||||||
|
hash += hash >> 11;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle end cases */
|
||||||
|
switch (rem) {
|
||||||
|
case 3: hash += *((uint16_t*)data);
|
||||||
|
hash ^= hash << 16;
|
||||||
|
hash ^= ((signed char)data[2]) << 18;
|
||||||
|
hash += hash >> 11;
|
||||||
|
break;
|
||||||
|
case 2: hash += *((uint16_t*)data);
|
||||||
|
hash ^= hash << 11;
|
||||||
|
hash += hash >> 17;
|
||||||
|
break;
|
||||||
|
case 1: hash += (signed char)*data;
|
||||||
|
hash ^= hash << 10;
|
||||||
|
hash += hash >> 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Force "avalanching" of final 127 bits */
|
||||||
|
hash ^= hash << 3;
|
||||||
|
hash += hash >> 5;
|
||||||
|
hash ^= hash << 4;
|
||||||
|
hash += hash >> 17;
|
||||||
|
hash ^= hash << 25;
|
||||||
|
hash += hash >> 6;
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
@ -14,6 +14,9 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char *TAG = "wifisniffer";
|
static const char *TAG = "wifisniffer";
|
||||||
|
|
||||||
|
// function defined in rokkithash.cpp
|
||||||
|
uint32_t rokkit(const char * , int );
|
||||||
|
|
||||||
static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL};
|
static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -56,8 +59,10 @@ 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_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff;
|
||||||
const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
|
const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
|
||||||
const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
|
const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
|
||||||
char counter [10];
|
char counter [11]; // uint32_t -> 4 byte -> 10 decimals + '0' terminator -> 11 chars
|
||||||
std::pair<std::set<uint64_t>::iterator, bool> newmac;
|
char macbuf [21]; // uint64_t -> 8 byte -> 20 decimals + '0' terminator -> 21 chars
|
||||||
|
uint32_t hashedmac;
|
||||||
|
std::pair<std::set<uint32_t>::iterator, bool> newmac;
|
||||||
|
|
||||||
if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value
|
if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value
|
||||||
uint64_t addr2int = ( (uint64_t)hdr->addr2[0] ) | ( (uint64_t)hdr->addr2[1] << 8 ) | ( (uint64_t)hdr->addr2[2] << 16 ) | \
|
uint64_t addr2int = ( (uint64_t)hdr->addr2[0] ) | ( (uint64_t)hdr->addr2[1] << 8 ) | ( (uint64_t)hdr->addr2[2] << 16 ) | \
|
||||||
@ -69,17 +74,20 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
|
|||||||
if ( std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end() ) {
|
if ( std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end() ) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// INFO: RSSI when found MAC in range
|
// log rssi info for scanned MAC
|
||||||
ESP_LOGI(TAG, "WiFi RSSI: %02d", ppkt->rx_ctrl.rssi);
|
ESP_LOGI(TAG, "WiFi RSSI: %02d", ppkt->rx_ctrl.rssi);
|
||||||
|
|
||||||
// if new unique MAC logged increment counter on display
|
// if found new unique MAC hash it and increment counter on display
|
||||||
newmac = macs.insert(addr2int);
|
itoa(addr2int, macbuf, 10); // convert 64 bit MAC to decimal string
|
||||||
|
hashedmac = rokkit(macbuf, 10); // hash MAC for privacy, use 10 chars to store in uint32_t set
|
||||||
|
newmac = macs.insert(hashedmac); // store hashed MAC if new unique
|
||||||
|
//if ( (newmac.second) && ((uint32_t)hdr->addr2[0] & 0x03 == 0) ) { // filter local and group MACs
|
||||||
if (newmac.second) {
|
if (newmac.second) {
|
||||||
macnum++;
|
macnum++;
|
||||||
itoa(macnum, counter, 10);
|
itoa(macnum, counter, 10); // 10 -> decimal counter value
|
||||||
u8x8.draw2x2String(0, 0, counter);
|
u8x8.draw2x2String(0, 0, counter);
|
||||||
ESP_LOGI(TAG, "MAC counter: %4i", macnum);
|
ESP_LOGI(TAG, "#%04i -> Hash %u", macnum, hashedmac);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VENDORFILTER
|
#ifdef VENDORFILTER
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user