From 5d57c69179e1b7df2ac1e83564bcb4baad9953d0 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 19 Oct 2022 18:35:07 +0200 Subject: [PATCH 01/16] fix issue #19 --- CHANGELOG.md | 3 +++ lib/libpax/libpax_api.cpp | 4 ++-- lib/libpax/libpax_api.h | 2 +- lib/libpax/wifiscan.cpp | 25 +++++++------------------ lib/libpax/wifiscan.h | 2 +- library.json | 2 +- platformio.ini | 2 +- 7 files changed, 16 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8eec63..1e8823a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.0.2] - 2022-10-19 +- Adapt Wifi country settings to ESP IDF v4.4 Wi-Fi API + ## [1.0.1] - 2022-04-14 - Count randomized MACs only (Wifi and BLE) - fix use LSB format to interprete BLE MACS diff --git a/lib/libpax/libpax_api.cpp b/lib/libpax/libpax_api.cpp index 3e8c318..49af8c9 100644 --- a/lib/libpax/libpax_api.cpp +++ b/lib/libpax/libpax_api.cpp @@ -95,7 +95,7 @@ void libpax_default_config(struct libpax_config_t* configuration) { memset(configuration, 0, sizeof(struct libpax_config_t)); configuration->blecounter = 0; configuration->wificounter = 1; - configuration->wifi_my_country = 1; + strcpy(configuration->wifi_my_country, "01"); configuration->wifi_channel_map = 0b100010100100100; configuration->wifi_channel_switch_interval = 50; configuration->wifi_rssi_threshold = 0; @@ -173,10 +173,10 @@ int libpax_counter_start() { return -1; } if (current_config.wificounter) { + wifi_sniffer_init(current_config.wifi_channel_switch_interval); set_wifi_country(current_config.wifi_my_country); set_wifi_channels(current_config.wifi_channel_map); set_wifi_rssi_filter(current_config.wifi_rssi_threshold); - wifi_sniffer_init(current_config.wifi_channel_switch_interval); } if (current_config.wificounter && current_config.blecounter) { esp_wifi_set_ps(WIFI_PS_MIN_MODEM); diff --git a/lib/libpax/libpax_api.h b/lib/libpax/libpax_api.h index 5d72e4c..908e084 100644 --- a/lib/libpax/libpax_api.h +++ b/lib/libpax/libpax_api.h @@ -31,7 +31,7 @@ struct libpax_config_t { // <- 13 ..........1 -> // 0b1010000001001 would be Channel: 1, 4, 11, 13 uint8_t wificounter; // set to 0 if you do not want to install the WiFi sniffer - uint8_t wifi_my_country; // e.g 0 = "EU", etc. select locale for WiFi RF settings + char wifi_my_country[3]; // set country code for WiFi RF settings, e.g. "01", "DE", etc. uint16_t wifi_channel_switch_interval; // [seconds/100] -> 0,5 sec. int wifi_rssi_threshold; // Filter for how strong the wifi signal should be to be counted int ble_rssi_threshold; // Filter for how strong the bluetooth signal should be to be counted diff --git a/lib/libpax/wifiscan.cpp b/lib/libpax/wifiscan.cpp index 61d8e01..d57a343 100644 --- a/lib/libpax/wifiscan.cpp +++ b/lib/libpax/wifiscan.cpp @@ -39,12 +39,7 @@ TimerHandle_t WifiChanTimer; int initialized_wifi = 0; int wifi_rssi_threshold = 0; uint16_t channels_map = WIFI_CHANNEL_ALL; - -#define WIFI_CHANNEL_MAX 13 -// default values for country configuration -static wifi_country_t wifi_country = {"EU", 1, - WIFI_CHANNEL_MAX, 100, - WIFI_COUNTRY_POLICY_MANUAL}; +static wifi_country_t country; void wifi_noop_sniffer(void* buff, wifi_promiscuous_pkt_type_t type) {} @@ -66,17 +61,16 @@ wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { void switchWifiChannel(TimerHandle_t xTimer) { configASSERT(xTimer); do { channel = - (channel % WIFI_CHANNEL_MAX) + 1; // rotate channels in bitmap + (channel % country.nchan) + 1; // rotate channels in bitmap } while (!(channels_map >> (channel - 1) & 1)); esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); } -void set_wifi_country(uint8_t cc) { - switch(cc) { - case 1: - memcpy(wifi_country.cc, "EU", sizeof("EU")); - break; - } +void set_wifi_country(const char* country_code) { + ESP_ERROR_CHECK( + esp_wifi_set_country_code(country_code, true)); + ESP_ERROR_CHECK( + esp_wifi_get_country(&country)); } void set_wifi_channels(uint16_t set_channels_map) { @@ -102,15 +96,12 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { WIFI_PROMIS_FILTER_MASK_DATA}; ESP_ERROR_CHECK(esp_wifi_init(&wificfg)); // configure Wifi with cfg - ESP_ERROR_CHECK( - esp_wifi_set_country(&wifi_country)); // set locales for RF and channels ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); ESP_ERROR_CHECK( esp_wifi_set_promiscuous_filter(&filter)); // set frame filter ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler)); - ESP_ERROR_CHECK(esp_wifi_start()); // for esp_wifi v3.3 ESP_ERROR_CHECK( esp_wifi_set_promiscuous(true)); // now switch on monitor mode @@ -121,7 +112,6 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { assert(WifiChanTimer); xTimerStart(WifiChanTimer, 0); } - ESP_ERROR_CHECK(esp_wifi_start()); esp_wifi_set_promiscuous(true); initialized_wifi = 1; #endif @@ -134,7 +124,6 @@ void wifi_sniffer_stop() { ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_noop_sniffer)); ESP_ERROR_CHECK( esp_wifi_set_promiscuous(false)); // now switch off monitor mode - ESP_ERROR_CHECK(esp_wifi_stop()); esp_wifi_deinit(); ESP_ERROR_CHECK(esp_coex_preference_set(ESP_COEX_PREFER_BT)); initialized_wifi = 0; diff --git a/lib/libpax/wifiscan.h b/lib/libpax/wifiscan.h index 8239109..1b4a207 100644 --- a/lib/libpax/wifiscan.h +++ b/lib/libpax/wifiscan.h @@ -18,7 +18,7 @@ typedef struct { uint8_t payload[0]; // network data ended with 4 bytes csum (CRC32) } wifi_ieee80211_packet_t; -void set_wifi_country(uint8_t country_code); +void set_wifi_country(const char* country_code); void set_wifi_channels(uint16_t channels_map); void set_wifi_rssi_filter(int set_rssi_threshold); diff --git a/library.json b/library.json index 1681ebf..cd16a9c 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "libpax", - "version":"1.0.1", + "version":"1.0.2", "keywords": "libpax", "description": "Library for PAX counting using BLE and WiFi", "repository": diff --git a/platformio.ini b/platformio.ini index 6d50a7a..73461ec 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,7 +5,7 @@ default_envs = espidf [env] board = ttgo-t-beam monitor_speed = 115200 -platform = espressif32@3.5.0 +platform = espressif32@5.2.0 [env:espidf] framework = espidf From 4744dd05591e961a3a18dcce6e86b2b4aeedf929 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 19 Oct 2022 18:48:31 +0200 Subject: [PATCH 02/16] remove unnecessary wifi settings --- lib/libpax/wifiscan.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libpax/wifiscan.cpp b/lib/libpax/wifiscan.cpp index d57a343..f46bf4a 100644 --- a/lib/libpax/wifiscan.cpp +++ b/lib/libpax/wifiscan.cpp @@ -96,9 +96,9 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { WIFI_PROMIS_FILTER_MASK_DATA}; ESP_ERROR_CHECK(esp_wifi_init(&wificfg)); // configure Wifi with cfg - ESP_ERROR_CHECK( - esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); + //ESP_ERROR_CHECK( + // esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM + //ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); ESP_ERROR_CHECK( esp_wifi_set_promiscuous_filter(&filter)); // set frame filter ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler)); From 362631ef1efc9a0782b9be63d9bfbc10d4cc65b0 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 19 Oct 2022 19:00:56 +0200 Subject: [PATCH 03/16] code sanitizations --- lib/libpax/wifiscan.cpp | 45 +++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/libpax/wifiscan.cpp b/lib/libpax/wifiscan.cpp index f46bf4a..54c7d00 100644 --- a/lib/libpax/wifiscan.cpp +++ b/lib/libpax/wifiscan.cpp @@ -32,8 +32,9 @@ Which in turn is based of Łukasz Marcin Podkalicki's ESP32/016 WiFi Sniffer #include "globals.h" #include -#include "wifiscan.h" #include "libpax.h" +#include "wifiscan.h" + TimerHandle_t WifiChanTimer; int initialized_wifi = 0; @@ -44,33 +45,31 @@ static wifi_country_t country; void wifi_noop_sniffer(void* buff, wifi_promiscuous_pkt_type_t type) {} // using IRAM_ATTR here to speed up callback function -static IRAM_ATTR void -wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { +static IRAM_ATTR 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; if ((wifi_rssi_threshold) && (ppkt->rx_ctrl.rssi < wifi_rssi_threshold)) // rssi is negative value - return; - else - mac_add((uint8_t *)hdr->addr2, MAC_SNIFF_WIFI); + return; + else + mac_add((uint8_t*)hdr->addr2, MAC_SNIFF_WIFI); } // Software-timer driven Wifi channel rotation callback function void switchWifiChannel(TimerHandle_t xTimer) { configASSERT(xTimer); - do { channel = - (channel % country.nchan) + 1; // rotate channels in bitmap + do { + channel = (channel % country.nchan) + 1; // rotate channels in bitmap } while (!(channels_map >> (channel - 1) & 1)); esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); } void set_wifi_country(const char* country_code) { - ESP_ERROR_CHECK( - esp_wifi_set_country_code(country_code, true)); - ESP_ERROR_CHECK( - esp_wifi_get_country(&country)); + ESP_ERROR_CHECK(esp_wifi_set_country_code(country_code, true)); + ESP_ERROR_CHECK(esp_wifi_get_country(&country)); } void set_wifi_channels(uint16_t set_channels_map) { @@ -82,7 +81,7 @@ void set_wifi_rssi_filter(int set_rssi_threshold) { } void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { - #ifdef LIBPAX_WIFI +#ifdef LIBPAX_WIFI wifi_init_config_t wificfg = WIFI_INIT_CONFIG_DEFAULT(); wificfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM wificfg.wifi_task_core_id = 0; // we want wifi task running on core 0 @@ -96,9 +95,6 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { WIFI_PROMIS_FILTER_MASK_DATA}; ESP_ERROR_CHECK(esp_wifi_init(&wificfg)); // configure Wifi with cfg - //ESP_ERROR_CHECK( - // esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM - //ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); ESP_ERROR_CHECK( esp_wifi_set_promiscuous_filter(&filter)); // set frame filter ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler)); @@ -106,21 +102,22 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { esp_wifi_set_promiscuous(true)); // now switch on monitor mode // setup wifi channel rotation timer - if(wifi_channel_switch_interval > 0) { - WifiChanTimer = xTimerCreate("WifiChannelTimer", pdMS_TO_TICKS(wifi_channel_switch_interval * 10), - pdTRUE, (void*)0, switchWifiChannel); + if (wifi_channel_switch_interval > 0) { + WifiChanTimer = xTimerCreate( + "WifiChannelTimer", pdMS_TO_TICKS(wifi_channel_switch_interval * 10), + pdTRUE, (void*)0, switchWifiChannel); assert(WifiChanTimer); xTimerStart(WifiChanTimer, 0); } esp_wifi_set_promiscuous(true); initialized_wifi = 1; - #endif +#endif } void wifi_sniffer_stop() { - #ifdef LIBPAX_WIFI - if(initialized_wifi) { - if(WifiChanTimer) xTimerStop(WifiChanTimer, 0); +#ifdef LIBPAX_WIFI + if (initialized_wifi) { + if (WifiChanTimer) xTimerStop(WifiChanTimer, 0); ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_noop_sniffer)); ESP_ERROR_CHECK( esp_wifi_set_promiscuous(false)); // now switch off monitor mode @@ -128,5 +125,5 @@ void wifi_sniffer_stop() { ESP_ERROR_CHECK(esp_coex_preference_set(ESP_COEX_PREFER_BT)); initialized_wifi = 0; } - #endif +#endif } From cf2b95630a1feebce97619aac58a156713dec515 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 19 Oct 2022 19:03:28 +0200 Subject: [PATCH 04/16] remove redundant set promiscous true --- lib/libpax/wifiscan.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/libpax/wifiscan.cpp b/lib/libpax/wifiscan.cpp index 54c7d00..5e6efc2 100644 --- a/lib/libpax/wifiscan.cpp +++ b/lib/libpax/wifiscan.cpp @@ -35,7 +35,6 @@ Which in turn is based of Łukasz Marcin Podkalicki's ESP32/016 WiFi Sniffer #include "libpax.h" #include "wifiscan.h" - TimerHandle_t WifiChanTimer; int initialized_wifi = 0; int wifi_rssi_threshold = 0; @@ -109,7 +108,7 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { assert(WifiChanTimer); xTimerStart(WifiChanTimer, 0); } - esp_wifi_set_promiscuous(true); + initialized_wifi = 1; #endif } From 0f95805ce719b139633bccbcae5b285bebbea043 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Thu, 20 Oct 2022 08:34:45 +0200 Subject: [PATCH 05/16] add v1.0.1 backward compatibility --- lib/libpax/wifiscan.cpp | 9 +++++++++ lib/libpax/wifiscan.h | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/libpax/wifiscan.cpp b/lib/libpax/wifiscan.cpp index 5e6efc2..ca47ebd 100644 --- a/lib/libpax/wifiscan.cpp +++ b/lib/libpax/wifiscan.cpp @@ -71,6 +71,15 @@ void set_wifi_country(const char* country_code) { ESP_ERROR_CHECK(esp_wifi_get_country(&country)); } +// Keep this a while for compatibility with 1.0.1 +void set_wifi_country(uint8_t cc) { + switch (cc) { + case 1: + set_wifi_country("DE"); + break; + } +} + void set_wifi_channels(uint16_t set_channels_map) { channels_map = set_channels_map; } diff --git a/lib/libpax/wifiscan.h b/lib/libpax/wifiscan.h index 1b4a207..285acdc 100644 --- a/lib/libpax/wifiscan.h +++ b/lib/libpax/wifiscan.h @@ -19,6 +19,7 @@ typedef struct { } wifi_ieee80211_packet_t; void set_wifi_country(const char* country_code); +void set_wifi_country(uint8_t cc); void set_wifi_channels(uint16_t channels_map); void set_wifi_rssi_filter(int set_rssi_threshold); From 0f6c9dc887df660cf2752a47389d8ed0fba548f9 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 29 Oct 2022 12:46:19 +0200 Subject: [PATCH 06/16] fix backward compatibility --- lib/libpax/libpax.h | 4 ++-- lib/libpax/libpax_api.cpp | 8 ++++++-- lib/libpax/libpax_api.h | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/libpax/libpax.h b/lib/libpax/libpax.h index ce68fd6..801f59f 100644 --- a/lib/libpax/libpax.h +++ b/lib/libpax/libpax.h @@ -6,7 +6,7 @@ #include "wifiscan.h" #define CONFIG_MAJOR_VERSION 1 -#define CONFIG_MINOR_VERSION 0 +#define CONFIG_MINOR_VERSION 1 /* Memory payload structure for persiting configurations @@ -20,7 +20,7 @@ struct libpax_config_storage_t { // Added for structure alignment uint8_t pad; // reserved for future use - uint8_t reserved_end[25]; + uint8_t reserved_end[22]; uint8_t checksum[4]; }; diff --git a/lib/libpax/libpax_api.cpp b/lib/libpax/libpax_api.cpp index 49af8c9..9d7cf9e 100644 --- a/lib/libpax/libpax_api.cpp +++ b/lib/libpax/libpax_api.cpp @@ -95,7 +95,7 @@ void libpax_default_config(struct libpax_config_t* configuration) { memset(configuration, 0, sizeof(struct libpax_config_t)); configuration->blecounter = 0; configuration->wificounter = 1; - strcpy(configuration->wifi_my_country, "01"); + strcpy(configuration->wifi_my_country_str, "01"); configuration->wifi_channel_map = 0b100010100100100; configuration->wifi_channel_switch_interval = 50; configuration->wifi_rssi_threshold = 0; @@ -130,6 +130,10 @@ int libpax_update_config(struct libpax_config_t* configuration) { if (result == 0) { memcpy(¤t_config, configuration, sizeof(struct libpax_config_t)); + // this if to keep v1.0.1 backward compatibility + if (strcmp(current_config.wifi_my_country_str, "")) { + strcpy(current_config.wifi_my_country_str, current_config.wifi_my_country ? "DE" : "01"); + } config_set = 1; } return result; @@ -174,7 +178,7 @@ int libpax_counter_start() { } if (current_config.wificounter) { wifi_sniffer_init(current_config.wifi_channel_switch_interval); - set_wifi_country(current_config.wifi_my_country); + set_wifi_country(current_config.wifi_my_country_str); set_wifi_channels(current_config.wifi_channel_map); set_wifi_rssi_filter(current_config.wifi_rssi_threshold); } diff --git a/lib/libpax/libpax_api.h b/lib/libpax/libpax_api.h index 908e084..a19e8f2 100644 --- a/lib/libpax/libpax_api.h +++ b/lib/libpax/libpax_api.h @@ -31,7 +31,7 @@ struct libpax_config_t { // <- 13 ..........1 -> // 0b1010000001001 would be Channel: 1, 4, 11, 13 uint8_t wificounter; // set to 0 if you do not want to install the WiFi sniffer - char wifi_my_country[3]; // set country code for WiFi RF settings, e.g. "01", "DE", etc. + uint8_t wifi_my_country; // e.g 0 = "EU", etc. select locale for WiFi RF settings uint16_t wifi_channel_switch_interval; // [seconds/100] -> 0,5 sec. int wifi_rssi_threshold; // Filter for how strong the wifi signal should be to be counted int ble_rssi_threshold; // Filter for how strong the bluetooth signal should be to be counted @@ -39,6 +39,7 @@ struct libpax_config_t { uint32_t blescantime; // [seconds] scan duration, 0 means infinite [default] uint16_t blescanwindow; // [milliseconds] scan window, see below, 3 ... 10240, default 80ms uint16_t blescaninterval; // [illiseconds] scan interval, see below, 3 ... 10240, default 80ms = 100% duty cycle + char wifi_my_country_str[3]; // set country code for WiFi RF settings, e.g. "01", "DE", etc. }; From f38196b5edbc396eea9fa52728f1c1afdc1e6827 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 29 Oct 2022 12:55:36 +0200 Subject: [PATCH 07/16] update changelog.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e8823a..fed734d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [1.0.2] - 2022-10-19 +## [1.1.0] - 2022-10-29 - Adapt Wifi country settings to ESP IDF v4.4 Wi-Fi API +- Keep backward compatibility to 1.0.1 ## [1.0.1] - 2022-04-14 - Count randomized MACs only (Wifi and BLE) From fd04a38d42f67f31d8632b19ba662d123f36af63 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 15 Nov 2022 12:06:02 +0100 Subject: [PATCH 08/16] Update libpax_api.cpp --- lib/libpax/libpax_api.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/libpax/libpax_api.cpp b/lib/libpax/libpax_api.cpp index 9d7cf9e..4e21556 100644 --- a/lib/libpax/libpax_api.cpp +++ b/lib/libpax/libpax_api.cpp @@ -196,6 +196,9 @@ int libpax_counter_start() { } int libpax_counter_stop() { + if (PaxReportTimer == NULL) { + return -1; + } wifi_sniffer_stop(); stop_BLE_scan(); xTimerStop(PaxReportTimer, 0); From 2f774b58334f7ebf2e4ed42f0879e8493ddb2be5 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 26 Nov 2022 17:36:36 +0100 Subject: [PATCH 09/16] adjust config storage struct --- lib/libpax/libpax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libpax/libpax.h b/lib/libpax/libpax.h index 801f59f..8ef4b79 100644 --- a/lib/libpax/libpax.h +++ b/lib/libpax/libpax.h @@ -18,9 +18,9 @@ struct libpax_config_storage_t { uint8_t reserved_start[2]; struct libpax_config_t config; // Added for structure alignment - uint8_t pad; - // reserved for future use - uint8_t reserved_end[22]; + uint8_t pad[2]; + // reserved for future use + uint8_t reserved_end[21]; uint8_t checksum[4]; }; From 1402107a27552f148a63ae54adc92baffd1bea98 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 27 Nov 2022 21:59:37 +0100 Subject: [PATCH 10/16] ensure compatibility with ESP-IDF logging --- lib/libpax/blescan.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libpax/blescan.cpp b/lib/libpax/blescan.cpp index 81cdffb..3228706 100644 --- a/lib/libpax/blescan.cpp +++ b/lib/libpax/blescan.cpp @@ -12,8 +12,10 @@ #define BLESCANINTERVAL 80 // [illiseconds] #endif -// local Tag for logging -static const char TAG[] = "bluetooth"; +#ifndef TAG +#define TAG __FILE__ +#endif + int initialized_ble = 0; int ble_rssi_threshold = 0; From 738c2a6d4bcca7b5e4e66e81cf2ec96afd0d68b1 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 10 Dec 2022 15:25:34 +0100 Subject: [PATCH 11/16] fix integration test --- test/libpax_test_cases.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libpax_test_cases.cpp b/test/libpax_test_cases.cpp index fcbe663..547a967 100644 --- a/test/libpax_test_cases.cpp +++ b/test/libpax_test_cases.cpp @@ -122,7 +122,7 @@ void test_callback() { TEST_ASSERT_EQUAL(0, err_code); printf("libpax should be running\n"); - vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(6000)); + vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(6010)); TEST_ASSERT_EQUAL(6, time_called_back); } From 2eebe1df0aa9a9424c001595ee4d901157e480e7 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 10 Dec 2022 15:25:49 +0100 Subject: [PATCH 12/16] bump to v1.1.0 --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index cd16a9c..bb919a2 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "libpax", - "version":"1.0.2", + "version":"1.1.0", "keywords": "libpax", "description": "Library for PAX counting using BLE and WiFi", "repository": From 6730acff4d62028e7cd0d2237f67d178505d7b0c Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 10 Dec 2022 21:11:55 +0100 Subject: [PATCH 13/16] remove unnecessary modem ps code --- lib/libpax/libpax_api.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/libpax/libpax_api.cpp b/lib/libpax/libpax_api.cpp index 4e21556..9885890 100644 --- a/lib/libpax/libpax_api.cpp +++ b/lib/libpax/libpax_api.cpp @@ -182,11 +182,6 @@ int libpax_counter_start() { set_wifi_channels(current_config.wifi_channel_map); set_wifi_rssi_filter(current_config.wifi_rssi_threshold); } - if (current_config.wificounter && current_config.blecounter) { - esp_wifi_set_ps(WIFI_PS_MIN_MODEM); - } else { - esp_wifi_set_ps(WIFI_PS_NONE); - } if (current_config.blecounter) { set_BLE_rssi_filter(current_config.ble_rssi_threshold); start_BLE_scan(current_config.blescantime, current_config.blescanwindow, From 45020e240ec432c9a99db7d483e9480b9705d567 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 13 Dec 2022 13:58:24 +0100 Subject: [PATCH 14/16] remove deprecated esp_coex_preference_set --- lib/libpax/blescan.cpp | 1 - lib/libpax/wifiscan.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/libpax/blescan.cpp b/lib/libpax/blescan.cpp index 3228706..42a1d4d 100644 --- a/lib/libpax/blescan.cpp +++ b/lib/libpax/blescan.cpp @@ -284,7 +284,6 @@ void stop_BLE_scan(void) { ESP_ERROR_CHECK(esp_bt_controller_disable()); ESP_ERROR_CHECK(esp_bt_controller_deinit()); #endif - ESP_ERROR_CHECK(esp_coex_preference_set(ESP_COEX_PREFER_WIFI)); ESP_LOGI(TAG, "Bluetooth scanner stopped"); initialized_ble = 0; } diff --git a/lib/libpax/wifiscan.cpp b/lib/libpax/wifiscan.cpp index ca47ebd..845d64a 100644 --- a/lib/libpax/wifiscan.cpp +++ b/lib/libpax/wifiscan.cpp @@ -130,7 +130,6 @@ void wifi_sniffer_stop() { ESP_ERROR_CHECK( esp_wifi_set_promiscuous(false)); // now switch off monitor mode esp_wifi_deinit(); - ESP_ERROR_CHECK(esp_coex_preference_set(ESP_COEX_PREFER_BT)); initialized_wifi = 0; } #endif From 0a44314f66cd6b1396fa807ade17c3b904ef5fa2 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 13 Dec 2022 14:17:46 +0100 Subject: [PATCH 15/16] enable BT before WIFI --- lib/libpax/libpax_api.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/libpax/libpax_api.cpp b/lib/libpax/libpax_api.cpp index 9885890..8c96683 100644 --- a/lib/libpax/libpax_api.cpp +++ b/lib/libpax/libpax_api.cpp @@ -176,17 +176,19 @@ int libpax_counter_start() { ESP_LOGE("configuration", "Configuration was not yet set."); return -1; } + // turn on BT before Wifi, since the ESP32 API coexistence configuration option depends + // on the Bluetooth configuration option + if (current_config.blecounter) { + set_BLE_rssi_filter(current_config.ble_rssi_threshold); + start_BLE_scan(current_config.blescantime, current_config.blescanwindow, + current_config.blescaninterval); + } if (current_config.wificounter) { wifi_sniffer_init(current_config.wifi_channel_switch_interval); set_wifi_country(current_config.wifi_my_country_str); set_wifi_channels(current_config.wifi_channel_map); set_wifi_rssi_filter(current_config.wifi_rssi_threshold); } - if (current_config.blecounter) { - set_BLE_rssi_filter(current_config.ble_rssi_threshold); - start_BLE_scan(current_config.blescantime, current_config.blescanwindow, - current_config.blescaninterval); - } return 0; } From 52968004c204d3457d18150544992df30b95074d Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Tue, 13 Dec 2022 18:59:08 +0100 Subject: [PATCH 16/16] some comment sanitizations --- lib/libpax/wifiscan.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/libpax/wifiscan.cpp b/lib/libpax/wifiscan.cpp index 845d64a..ae6491b 100644 --- a/lib/libpax/wifiscan.cpp +++ b/lib/libpax/wifiscan.cpp @@ -94,20 +94,17 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) { wificfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM wificfg.wifi_task_core_id = 0; // we want wifi task running on core 0 - // wifi_promiscuous_filter_t filter = { - // .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames - // .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames - + // filter management and data frames to the sniffer wifi_promiscuous_filter_t filter = {.filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA}; ESP_ERROR_CHECK(esp_wifi_init(&wificfg)); // configure Wifi with cfg ESP_ERROR_CHECK( - esp_wifi_set_promiscuous_filter(&filter)); // set frame filter + esp_wifi_set_promiscuous_filter(&filter)); // enable frame filtering ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler)); ESP_ERROR_CHECK( - esp_wifi_set_promiscuous(true)); // now switch on monitor mode + esp_wifi_set_promiscuous(true)); // start sniffer mode // setup wifi channel rotation timer if (wifi_channel_switch_interval > 0) {