wifisniffer.cpp: code improvements
This commit is contained in:
parent
4e0cae7ec3
commit
875ad77967
@ -10,9 +10,9 @@
|
||||
|
||||
; ---> SELECT TARGET PLATFORM HERE! <---
|
||||
[platformio]
|
||||
env_default = heltec_wifi_lora_32
|
||||
;env_default = heltec_wifi_lora_32
|
||||
;env_default = ttgov1
|
||||
;env_default = ttgov2
|
||||
env_default = ttgov2
|
||||
;env_default = lopy
|
||||
;env_default = lopy4
|
||||
;env_default = lolin32lite_lora
|
||||
|
@ -35,7 +35,8 @@ extern uint64_t uptimecounter;
|
||||
extern osjob_t sendjob;
|
||||
extern int macnum, blenum, countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
||||
extern bool joinstate;
|
||||
extern std::set<uint64_t, std::greater <uint64_t> > macs;
|
||||
//extern std::set<uint64_t, std::greater <uint64_t> > macs;
|
||||
extern std::set<uint64_t> macs;
|
||||
|
||||
#ifdef HAS_DISPLAY
|
||||
extern HAS_DISPLAY u8x8;
|
||||
|
@ -49,7 +49,7 @@ int macnum = 0, blenum = 0;
|
||||
uint64_t uptimecounter = 0;
|
||||
bool joinstate = false;
|
||||
|
||||
std::set<uint64_t, std::greater <uint64_t> > macs; // storage holds MAC frames
|
||||
std::set<uint64_t> macs; // storage holds MAC frames
|
||||
|
||||
// this variable will be changed in the ISR, and read in main loop
|
||||
static volatile bool ButtonTriggered = false;
|
||||
@ -208,7 +208,7 @@ void wifi_sniffer_loop(void * pvParameters) {
|
||||
|
||||
// execute BLE count if BLE function is enabled
|
||||
#ifdef BLECOUNTER
|
||||
if ( cfg.blescan )
|
||||
if (cfg.blescan)
|
||||
BLECount();
|
||||
#endif
|
||||
|
||||
@ -220,8 +220,9 @@ void wifi_sniffer_loop(void * pvParameters) {
|
||||
yield();
|
||||
|
||||
// clear counter if not in cumulative counter mode
|
||||
if ( cfg.countermode != 1 ) {
|
||||
macs.erase(macs.begin(), macs.end()); // clear RAM
|
||||
if (cfg.countermode != 1) {
|
||||
//macs.erase(macs.begin(), macs.end()); // clear RAM
|
||||
macs.clear(); // clear macs container
|
||||
macnum = 0;
|
||||
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// program version
|
||||
#define PROGVERSION "1.2.5" // use max 10 chars here!
|
||||
#define PROGVERSION "1.2.51" // use max 10 chars here!
|
||||
#define PROGNAME "PAXCNT"
|
||||
|
||||
// Verbose enables serial output
|
||||
|
@ -67,7 +67,8 @@ void set_reset(int val) {
|
||||
break;
|
||||
case 1: // reset MAC counter
|
||||
ESP_LOGI(TAG, "Remote command: reset MAC counter");
|
||||
macs.erase(macs.begin(), macs.end()); // clear RAM
|
||||
//macs.erase(macs.begin(), macs.end()); // clear RAM
|
||||
macs.clear(); // clear macs container
|
||||
macnum = 0;
|
||||
u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter
|
||||
u8x8.clearLine(5);
|
||||
|
@ -38,13 +38,11 @@ extern void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t
|
||||
void wifi_sniffer_init(void) {
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
cfg.nvs_enable = 0; // we don't want wifi settings from NVRAM
|
||||
wifi_promiscuous_filter_t filter = {.filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // we need only MGMT frames
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_country(&wifi_country));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM) );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL) );
|
||||
//ESP_ERROR_CHECK(esp_wifi_start()); // not sure if we need this in this application?
|
||||
//ESP_ERROR_CHECK(esp_wifi_set_max_tx_power(-128)); // we don't need to TX, so we use lowest power level to save energy
|
||||
wifi_promiscuous_filter_t filter = {.filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // we need only MGMT frames
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_filter(&filter)); // set MAC frame filter
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
|
||||
@ -59,6 +57,7 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
|
||||
const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
|
||||
const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
|
||||
char counter [10];
|
||||
std::pair<std::set<uint64_t>::iterator, bool> newmac;
|
||||
|
||||
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 ) | \
|
||||
@ -69,19 +68,18 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
|
||||
|
||||
if ( std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end() ) {
|
||||
#endif
|
||||
macs.insert(addr2int);
|
||||
|
||||
// INFO: RSSI when adding MAC
|
||||
|
||||
// INFO: RSSI when found MAC in range
|
||||
ESP_LOGI(TAG, "WiFi RSSI: %02d", ppkt->rx_ctrl.rssi);
|
||||
|
||||
// if new unique MAC logged increment counter on display
|
||||
if ( macs.size() > macnum ) {
|
||||
macnum = macs.size();
|
||||
newmac = macs.insert(addr2int);
|
||||
if (newmac.second) {
|
||||
macnum++;
|
||||
itoa(macnum, counter, 10);
|
||||
u8x8.draw2x2String(0, 0, counter);
|
||||
ESP_LOGI(TAG, "MAC counter: %4i", macnum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef VENDORFILTER
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user