new feature: rcmd 0x17 wifi sniffer on/off
This commit is contained in:
parent
55951ca41c
commit
39c68d7d7f
@ -422,6 +422,11 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
|
|||||||
0 = battery data off [default]
|
0 = battery data off [default]
|
||||||
1 = battery data on, sends voltage on port 8
|
1 = battery data on, sends voltage on port 8
|
||||||
|
|
||||||
|
0x17 set Wifi scanner
|
||||||
|
|
||||||
|
0 = disabled
|
||||||
|
1 = enabled [default]
|
||||||
|
|
||||||
0x80 get device configuration
|
0x80 get device configuration
|
||||||
|
|
||||||
Device answers with it's current configuration on Port 3.
|
Device answers with it's current configuration on Port 3.
|
||||||
|
@ -72,6 +72,7 @@ typedef struct {
|
|||||||
uint8_t wifichancycle; // wifi channel switch cycle [seconds/100]
|
uint8_t wifichancycle; // wifi channel switch cycle [seconds/100]
|
||||||
uint8_t blescantime; // BLE scan cycle duration [seconds]
|
uint8_t blescantime; // BLE scan cycle duration [seconds]
|
||||||
uint8_t blescan; // 0=disabled, 1=enabled
|
uint8_t blescan; // 0=disabled, 1=enabled
|
||||||
|
uint8_t wifiscan; // 0=disabled, 1=enabled
|
||||||
uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
|
uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||||
uint8_t vendorfilter; // 0=disabled, 1=enabled
|
uint8_t vendorfilter; // 0=disabled, 1=enabled
|
||||||
uint8_t rgblum; // RGB Led luminosity (0..100%)
|
uint8_t rgblum; // RGB Led luminosity (0..100%)
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "lorawan.h"
|
#include "lorawan.h"
|
||||||
#endif
|
#endif
|
||||||
#include "macsniff.h"
|
#include "macsniff.h"
|
||||||
|
#include "wifiscan.h"
|
||||||
#include <rom/rtc.h>
|
#include <rom/rtc.h>
|
||||||
#include "cyclic.h"
|
#include "cyclic.h"
|
||||||
#include "timekeeper.h"
|
#include "timekeeper.h"
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
void wifi_sniffer_init(void);
|
void wifi_sniffer_init(void);
|
||||||
|
void switch_wifi_sniffer (uint8_t state);
|
||||||
static void IRAM_ATTR wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
|
static void IRAM_ATTR wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
|
||||||
void switchWifiChannel(TimerHandle_t xTimer);
|
void switchWifiChannel(TimerHandle_t xTimer);
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
; ---> SELECT THE TARGET PLATFORM HERE! <---
|
; ---> SELECT THE TARGET PLATFORM HERE! <---
|
||||||
[board]
|
[board]
|
||||||
halfile = generic.h
|
;halfile = generic.h
|
||||||
;halfile = ebox.h
|
;halfile = ebox.h
|
||||||
;halfile = eboxtube.h
|
;halfile = eboxtube.h
|
||||||
;halfile = ecopower.h
|
;halfile = ecopower.h
|
||||||
;halfile = heltec.h
|
halfile = heltec.h
|
||||||
;halfile = heltecv2.h
|
;halfile = heltecv2.h
|
||||||
;halfile = ttgov1.h
|
;halfile = ttgov1.h
|
||||||
;halfile = ttgov2.h
|
;halfile = ttgov2.h
|
||||||
@ -43,7 +43,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
|
|||||||
|
|
||||||
[common]
|
[common]
|
||||||
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
||||||
release_version = 1.9.71
|
release_version = 1.9.8
|
||||||
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
||||||
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
||||||
debug_level = 3
|
debug_level = 3
|
||||||
@ -51,7 +51,7 @@ extra_scripts = pre:build.py
|
|||||||
otakeyfile = ota.conf
|
otakeyfile = ota.conf
|
||||||
lorakeyfile = loraconf.h
|
lorakeyfile = loraconf.h
|
||||||
lmicconfigfile = lmic_config.h
|
lmicconfigfile = lmic_config.h
|
||||||
platform_espressif32 = espressif32@1.11.0
|
platform_espressif32 = espressif32@1.11.1
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
upload_speed = 115200
|
upload_speed = 115200
|
||||||
lib_deps_lora =
|
lib_deps_lora =
|
||||||
|
@ -29,6 +29,7 @@ void defaultConfig() {
|
|||||||
BLESCANINTERVAL /
|
BLESCANINTERVAL /
|
||||||
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
|
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
|
||||||
cfg.blescan = BLECOUNTER; // 0=disabled, 1=enabled
|
cfg.blescan = BLECOUNTER; // 0=disabled, 1=enabled
|
||||||
|
cfg.wifiscan = WIFICOUNTER; // 0=disabled, 1=enabled
|
||||||
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||||
cfg.vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled
|
cfg.vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled
|
||||||
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
|
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
|
||||||
@ -136,6 +137,10 @@ void saveConfig() {
|
|||||||
flash8 != cfg.blescan)
|
flash8 != cfg.blescan)
|
||||||
nvs_set_i8(my_handle, "blescanmode", cfg.blescan);
|
nvs_set_i8(my_handle, "blescanmode", cfg.blescan);
|
||||||
|
|
||||||
|
if (nvs_get_i8(my_handle, "wifiscanmode", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.wifiscan)
|
||||||
|
nvs_set_i8(my_handle, "wifiscanmode", cfg.wifiscan);
|
||||||
|
|
||||||
if (nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK ||
|
if (nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK ||
|
||||||
flash8 != cfg.wifiant)
|
flash8 != cfg.wifiant)
|
||||||
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
|
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
|
||||||
@ -321,6 +326,14 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nvs_get_i8(my_handle, "wifiscanmode", &flash8) == ESP_OK) {
|
||||||
|
cfg.wifiscan = flash8;
|
||||||
|
ESP_LOGI(TAG, "WIFIscanmode = %d", flash8);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "WIFIscanmode set to default %d", cfg.wifiscan);
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
if (nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK) {
|
if (nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK) {
|
||||||
cfg.rssilimit = flash16;
|
cfg.rssilimit = flash16;
|
||||||
ESP_LOGI(TAG, "rssilimit = %d", flash16);
|
ESP_LOGI(TAG, "rssilimit = %d", flash16);
|
||||||
|
@ -224,6 +224,13 @@ void set_blescan(uint8_t val[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_wifiscan(uint8_t val[]) {
|
||||||
|
ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s",
|
||||||
|
val[0] ? "on" : "off");
|
||||||
|
cfg.wifiscan = val[0] ? 1 : 0;
|
||||||
|
switch_wifi_sniffer(cfg.wifiscan);
|
||||||
|
}
|
||||||
|
|
||||||
void set_wifiant(uint8_t val[]) {
|
void set_wifiant(uint8_t val[]) {
|
||||||
ESP_LOGI(TAG, "Remote command: set Wifi antenna to %s",
|
ESP_LOGI(TAG, "Remote command: set Wifi antenna to %s",
|
||||||
val[0] ? "external" : "internal");
|
val[0] ? "external" : "internal");
|
||||||
@ -348,10 +355,11 @@ static cmd_t table[] = {
|
|||||||
{0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false},
|
{0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false},
|
||||||
{0x13, set_sensor, 2, true}, {0x14, set_payloadmask, 1, true},
|
{0x13, set_sensor, 2, true}, {0x14, set_payloadmask, 1, true},
|
||||||
{0x15, set_bme, 1, true}, {0x16, set_batt, 1, true},
|
{0x15, set_bme, 1, true}, {0x16, set_batt, 1, true},
|
||||||
{0x80, get_config, 0, false}, {0x81, get_status, 0, false},
|
{0x17, set_wifiscan, 1, true}, {0x80, get_config, 0, false},
|
||||||
{0x83, get_batt, 0, false}, {0x84, get_gps, 0, false},
|
{0x81, get_status, 0, false}, {0x83, get_batt, 0, false},
|
||||||
{0x85, get_bme, 0, false}, {0x86, get_time, 0, false},
|
{0x84, get_gps, 0, false}, {0x85, get_bme, 0, false},
|
||||||
{0x87, set_time, 0, false}, {0x99, set_flush, 0, false}};
|
{0x86, get_time, 0, false}, {0x87, set_time, 0, false},
|
||||||
|
{0x99, set_flush, 0, false}};
|
||||||
|
|
||||||
static const uint8_t cmdtablesize =
|
static const uint8_t cmdtablesize =
|
||||||
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
||||||
|
@ -29,8 +29,8 @@ typedef struct {
|
|||||||
} wifi_ieee80211_packet_t;
|
} wifi_ieee80211_packet_t;
|
||||||
|
|
||||||
// using IRAM_:ATTR here to speed up callback function
|
// using IRAM_:ATTR here to speed up callback function
|
||||||
static IRAM_ATTR void wifi_sniffer_packet_handler(void *buff,
|
static IRAM_ATTR void
|
||||||
wifi_promiscuous_pkt_type_t type) {
|
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 =
|
const wifi_ieee80211_packet_t *ipkt =
|
||||||
@ -72,7 +72,6 @@ void wifi_sniffer_init(void) {
|
|||||||
esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM
|
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_mode(WIFI_MODE_NULL));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); // no modem power saving
|
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); // no modem power saving
|
||||||
ESP_ERROR_CHECK(esp_wifi_start()); // must be started to be able to switch ch
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_filter(&filter)); // set frame filter
|
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_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode
|
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode
|
||||||
@ -81,6 +80,19 @@ void wifi_sniffer_init(void) {
|
|||||||
WifiChanTimer =
|
WifiChanTimer =
|
||||||
xTimerCreate("WifiChannelTimer", pdMS_TO_TICKS(cfg.wifichancycle * 10),
|
xTimerCreate("WifiChannelTimer", pdMS_TO_TICKS(cfg.wifichancycle * 10),
|
||||||
pdTRUE, (void *)0, switchWifiChannel);
|
pdTRUE, (void *)0, switchWifiChannel);
|
||||||
|
switch_wifi_sniffer(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void switch_wifi_sniffer(uint8_t state) {
|
||||||
assert(WifiChanTimer);
|
assert(WifiChanTimer);
|
||||||
xTimerStart(WifiChanTimer, 0);
|
if ((state ? 1 : 0) == 1) {
|
||||||
|
// switch wifi sniffer on
|
||||||
|
xTimerStart(WifiChanTimer, 0);
|
||||||
|
esp_wifi_set_promiscuous(true);
|
||||||
|
} else {
|
||||||
|
// switch wifi sniffer off
|
||||||
|
xTimerStop(WifiChanTimer, 0);
|
||||||
|
esp_wifi_set_promiscuous(false);
|
||||||
|
macs_wifi = 0; // clear WIFI counter
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user