promiscuous mode in ESP32 SDK
Posted: Tue Feb 28, 2017 7:18 am
There is only two functuions for wifi promiscuous mode:
esp_err_t esp_wifi_set_promiscuous(bool en);//for enabling promiscuous mode
esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb); //Register the RX callback function in the promiscuous mode
typedef void (* wifi_promiscuous_cb_t)(void *buf, wifi_promiscuous_pkt_type_t type);//RX callback function in the promiscuous mode
in RX callback function, probably the wifi header (as blelow:)was not included in rx buff.
typedef struct{
uint8_t u8FrameType;
/*!< It must use values from tenuWifiFrameType.
*/
uint8_t u8FrameSubtype;
/*!< It must use values from tenuSubTypes.
*/
uint8_t u8ServiceClass;
/*!< Service class from Wi-Fi header.
*/
uint8_t u8Priority;
/*!< Priority from Wi-Fi header.
*/
uint8_t u8HeaderLength;
/*!< Frame Header length.
*/
uint8_t u8CipherType;
/*!< Encryption type for the rx packet.
*/
uint8_t au8SrcMacAddress[6];
/* ZERO means DO NOT FILTER Source address.
*/
uint8_t au8DstMacAddress[6];
/* ZERO means DO NOT FILTER Destination address.
*/
uint8_t au8BSSID[6];
/* ZERO means DO NOT FILTER BSSID.
*/
uint16_t u16DataLength;
/*!< Data payload length (Header excluded).
*/
uint16_t u16FrameLength;
/*!< Total frame length (Header + Data).
*/
uint32_t u32DataRateKbps;
/*!< Data Rate in Kbps.
*/
int8_t s8RSSI;
/*!< RSSI.
*/
uint8_t __PAD24__[3];
/*!< Padding bytes for forcing 4-byte alignment
*/
}WifiRxPacketInfo_t;
for example:
setting WIFI to promiscuous mode:
#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
typedef struct{
uint8_t u8FrameType;
/*!< It must use values from tenuWifiFrameType.
*/
uint8_t u8FrameSubtype;
/*!< It must use values from tenuSubTypes.
*/
uint8_t u8ServiceClass;
/*!< Service class from Wi-Fi header.
*/
uint8_t u8Priority;
/*!< Priority from Wi-Fi header.
*/
uint8_t u8HeaderLength;
/*!< Frame Header length.
*/
uint8_t u8CipherType;
/*!< Encryption type for the rx packet.
*/
uint8_t au8SrcMacAddress[6];
/* ZERO means DO NOT FILTER Source address.
*/
uint8_t au8DstMacAddress[6];
/* ZERO means DO NOT FILTER Destination address.
*/
uint8_t au8BSSID[6];
/* ZERO means DO NOT FILTER BSSID.
*/
uint16_t u16DataLength;
/*!< Data payload length (Header excluded).
*/
uint16_t u16FrameLength;
/*!< Total frame length (Header + Data).
*/
uint32_t u32DataRateKbps;
/*!< Data Rate in Kbps.
*/
int8_t s8RSSI;
/*!< RSSI.
*/
uint8_t __PAD24__[3];
/*!< Padding bytes for forcing 4-byte alignment
*/
}M2MWifiRxPacketInfo_t;
esp_err_t event_handler(void *ctx, system_event_t *event)
{
return ESP_OK;
}
void wifi_promiscuous_callback(void *buf, wifi_promiscuous_pkt_type_t type)
{
WifiRxPacketInfo_t *rxPacket;
wifi_promiscuous_pkt_t *rxBuffer = (wifi_promiscuous_pkt_t *)buf;
if (type == WIFI_PKT_DATA){
for (uint16_t i = 0; i < rxBuffer->rx_ctrl.sig_len; i++){
printf("%02x ",rxBuffer->payload);
}
printf("\r\n");
}
}
void app_main(void)
{
nvs_flash_init();
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_callback));
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
int level = 0;
uint8_t channel = 1;
if (0 != esp_wifi_set_channel(3,0)){
printf(" wifi channel : 3\r\n");
}
while (true) {
gpio_set_level(GPIO_NUM_2, level);
level = !level;
vTaskDelay(500 / portTICK_PERIOD_MS);
}
From the above code, I only can get the data type from "wifi_promiscuous_pkt_type_t" , but I can't get any info about header info "WifiRxPacketInfo_t"
Also there is no place to set fliters for receiving.
for the above issues, please comment it.
esp_err_t esp_wifi_set_promiscuous(bool en);//for enabling promiscuous mode
esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb); //Register the RX callback function in the promiscuous mode
typedef void (* wifi_promiscuous_cb_t)(void *buf, wifi_promiscuous_pkt_type_t type);//RX callback function in the promiscuous mode
in RX callback function, probably the wifi header (as blelow:)was not included in rx buff.
typedef struct{
uint8_t u8FrameType;
/*!< It must use values from tenuWifiFrameType.
*/
uint8_t u8FrameSubtype;
/*!< It must use values from tenuSubTypes.
*/
uint8_t u8ServiceClass;
/*!< Service class from Wi-Fi header.
*/
uint8_t u8Priority;
/*!< Priority from Wi-Fi header.
*/
uint8_t u8HeaderLength;
/*!< Frame Header length.
*/
uint8_t u8CipherType;
/*!< Encryption type for the rx packet.
*/
uint8_t au8SrcMacAddress[6];
/* ZERO means DO NOT FILTER Source address.
*/
uint8_t au8DstMacAddress[6];
/* ZERO means DO NOT FILTER Destination address.
*/
uint8_t au8BSSID[6];
/* ZERO means DO NOT FILTER BSSID.
*/
uint16_t u16DataLength;
/*!< Data payload length (Header excluded).
*/
uint16_t u16FrameLength;
/*!< Total frame length (Header + Data).
*/
uint32_t u32DataRateKbps;
/*!< Data Rate in Kbps.
*/
int8_t s8RSSI;
/*!< RSSI.
*/
uint8_t __PAD24__[3];
/*!< Padding bytes for forcing 4-byte alignment
*/
}WifiRxPacketInfo_t;
for example:
setting WIFI to promiscuous mode:
#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
typedef struct{
uint8_t u8FrameType;
/*!< It must use values from tenuWifiFrameType.
*/
uint8_t u8FrameSubtype;
/*!< It must use values from tenuSubTypes.
*/
uint8_t u8ServiceClass;
/*!< Service class from Wi-Fi header.
*/
uint8_t u8Priority;
/*!< Priority from Wi-Fi header.
*/
uint8_t u8HeaderLength;
/*!< Frame Header length.
*/
uint8_t u8CipherType;
/*!< Encryption type for the rx packet.
*/
uint8_t au8SrcMacAddress[6];
/* ZERO means DO NOT FILTER Source address.
*/
uint8_t au8DstMacAddress[6];
/* ZERO means DO NOT FILTER Destination address.
*/
uint8_t au8BSSID[6];
/* ZERO means DO NOT FILTER BSSID.
*/
uint16_t u16DataLength;
/*!< Data payload length (Header excluded).
*/
uint16_t u16FrameLength;
/*!< Total frame length (Header + Data).
*/
uint32_t u32DataRateKbps;
/*!< Data Rate in Kbps.
*/
int8_t s8RSSI;
/*!< RSSI.
*/
uint8_t __PAD24__[3];
/*!< Padding bytes for forcing 4-byte alignment
*/
}M2MWifiRxPacketInfo_t;
esp_err_t event_handler(void *ctx, system_event_t *event)
{
return ESP_OK;
}
void wifi_promiscuous_callback(void *buf, wifi_promiscuous_pkt_type_t type)
{
WifiRxPacketInfo_t *rxPacket;
wifi_promiscuous_pkt_t *rxBuffer = (wifi_promiscuous_pkt_t *)buf;
if (type == WIFI_PKT_DATA){
for (uint16_t i = 0; i < rxBuffer->rx_ctrl.sig_len; i++){
printf("%02x ",rxBuffer->payload);
}
printf("\r\n");
}
}
void app_main(void)
{
nvs_flash_init();
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_callback));
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
int level = 0;
uint8_t channel = 1;
if (0 != esp_wifi_set_channel(3,0)){
printf(" wifi channel : 3\r\n");
}
while (true) {
gpio_set_level(GPIO_NUM_2, level);
level = !level;
vTaskDelay(500 / portTICK_PERIOD_MS);
}
From the above code, I only can get the data type from "wifi_promiscuous_pkt_type_t" , but I can't get any info about header info "WifiRxPacketInfo_t"
Also there is no place to set fliters for receiving.
for the above issues, please comment it.