promiscuous mode in ESP32 SDK

panjikuai
Posts: 4
Joined: Tue Feb 28, 2017 7:03 am

promiscuous mode in ESP32 SDK

Postby panjikuai » 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.

emaayan
Posts: 12
Joined: Sun Mar 05, 2023 6:16 pm

Re: promiscuous mode in ESP32 SDK

Postby emaayan » Tue Aug 01, 2023 6:09 am

to my understanding and code i saw this is the strcut

Code: Select all

typedef struct
{
    int16_t fctl;      // frame control
    int16_t duration;  // duration id
    uint8_t da[6];     // receiver address(addr1)
    uint8_t sa[6];     // sender address(addr2)
    uint8_t bssid[6];  // filtering address(addr3)
    int16_t seqctl;    // sequence control
    uint8_t *payload; // network data(includes addr4)
} __attribute__((packed)) wifi_mgmt_hdr;


Who is online

Users browsing this forum: No registered users and 223 guests