espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.62k stars 7.28k forks source link

Wifi Promiscous Mode Crashed in Version 2.0.6 (IDFGH-9095) #10499

Closed Harshit200107 closed 8 months ago

Harshit200107 commented 1 year ago

Answers checklist.

IDF version.

2.0.6

Operating System used.

Windows

How did you build your project?

Other (please specify in More Information)

If you are using Windows, please specify command line type.

None

Development Kit.

ESP-WROOM-32

Power Supply used.

USB

What is the expected behavior?

....... 18:19:19.055 -> WiFi connected to: IktaraWifi 18:19:19.055 -> IP address: 18:19:19.055 -> 192.168.1.177 18:19:21.118 -> Message published 18:19:22.099 -> 18:19:22.612 -> Channel Change Done, channel=10 18:19:22.612 -> The Test Count is 140 18:19:22.612 -> Current wifiget value:IktaraWifi 18:19:22.612 -> Current wifiget value:0276b5c1 18:19:22.612 -> Current wifiget value:testclient 18:19:22.612 -> Current wifiget value:1883 18:19:22.612 -> Current wifiget value:testpub 18:19:22.612 -> Current wifiget value:192.168.1.100 18:19:22.612 -> Current wifiget value:client1 18:19:22.660 -> Current wifiget value:admin 18:19:23.131 -> .... 18:19:24.666 -> WiFi connected to: IktaraWifi 18:19:24.666 -> IP address: 18:19:24.666 -> 192.168.1.178 18:19:26.717 -> Message published 18:19:27.743 -> 18:19:28.264 -> Channel Change Done, channel=11 18:19:28.264 -> The Test Count is 141 18:19:28.264 -> Current wifiget value:IktaraWifi 18:19:28.264 -> Current wifiget value:0276b5c1 18:19:28.264 -> Current wifiget value:testclient 18:19:28.264 -> Current wifiget value:1883 18:19:28.264 -> Current wifiget value:testpub 18:19:28.264 -> Current wifiget value:192.168.1.100 18:19:28.264 -> Current wifiget value:client1 18:19:28.264 -> Current wifiget value:admin 18:19:28.779 -> ..... 18:19:30.796 -> WiFi connected to: IktaraWifi 18:19:30.796 -> IP address: 18:19:30.796 -> 192.168.1.179 18:19:35.589 -> Message published

What is the actual behavior?

E (501) event: system event loop not initialized via esp_event_loop_init 14:12:13.069 -> E (7709) event: system event loop not initialized via esp_event_loop_init 14:12:14.189 -> E (8823) event: system event loop not initialized via esp_event_loop_init 14:12:15.214 -> E (9863) event: system event loop not initialized via esp_event_loop_init 14:12:16.335 -> E (10973) event: system event loop not initialized via esp_event_loop_init 14:12:16.477 -> E (11093) event: system event loop not initialized via esp_event_loop_init 14:12:18.811 -> E (13462) event: system event loop not initialized via esp_event_loop_init 14:12:18.811 -> E (13462) esp_netif_lwip: dhcpc cb: failed to post got ip event (103) 14:12:19.095 -> wifi_promiscuous_mode_init 14:12:19.095 -> Setup done 14:12:19.095 -> event_handler Functionevent_handler FunctionGuru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. 14:12:19.095 -> 14:12:19.095 -> Core 1 register dump: 14:12:19.095 -> PC : 0x4008a4a1 PS : 0x00060d30 A0 : 0x80157d58 A1 : 0x3ffb21d0
14:12:19.095 -> A2 : 0x00000000 A3 : 0xfffffffc A4 : 0x000000ff A5 : 0x0000ff00
14:12:19.143 -> A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x00000004
14:12:19.143 -> A10 : 0x00060f23 A11 : 0x3ffc603c A12 : 0x00000004 A13 : 0x00060f23
14:12:19.143 -> A14 : 0x007bf538 A15 : 0x003fffff SAR : 0x0000001d EXCCAUSE: 0x0000001c
14:12:19.143 -> EXCVADDR: 0x00000000 LBEG : 0x4008a4a1 LEND : 0x4008a4b1 LCOUNT : 0xffffffff
14:12:19.143 -> 14:12:19.143 -> 14:12:19.143 -> Backtrace: 0x4008a49e:0x3ffb21d0 0x40157d55:0x3ffb21e0 0x4015c8c2:0x3ffb24f0 0x4015c8fe:0x3ffb2580 0x400daf16:0x3ffb25c0 0x400d4f1d:0x3ffb2660 0x400dc18d:0x3ffb2820 14:12:19.143 -> 14:12:19.143 -> 14:12:19.143 -> 14:12:19.143 -> 14:12:19.143 -> ELF file SHA256: 37f170b21eea5986 14:12:19.189 -> 14:12:19.377 -> Rebooting... 14:12:19.377 -> ets Jul 29 2019 12:21:46 14:12:19.377 -> 14:12:19.377 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 14:12:19.377 -> configsip: 0, SPIWP:0xee 14:12:19.377 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 14:12:19.377 -> mode:DIO, clock div:1 14:12:19.377 -> load:0x3fff0030,len:1344 14:12:19.377 -> load:0x40078000,len:13836 14:12:19.377 -> load:0x40080400,len:3608 14:12:19.377 -> entry 0x400805f0 14:12:19.842 -> E (500) event: system event loop not initialized via esp_event_loop_init 14:12:26.870 -> E (7507) event: system event loop not initialized via esp_event_loop_init 14:12:27.897 -> E (8565) event: system event loop not initialized via esp_event_loop_init 14:12:28.931 -> E (9599) event: system event loop not initialized via esp_event_loop_init 14:12:29.957 -> E (10622) event: system event loop not initialized via esp_event_loop_init 14:12:30.982 -> E (11657) event: system event loop not initialized via esp_event_loop_init 14:12:31.214 -> E (11861) event: system event loop not initialized via esp_event_loop_init 14:12:32.891 -> wifi_promiscuous_mode_init 14:12:32.891 -> Setup done 14:12:32.891 -> event_handler Functionevent_handler FunctionGuru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Steps to reproduce.

  1. Step
  2. Step
  3. Step ... //

    include "Test1.h"

    include "Test2.h"

    //////#include "Test3.h"

    include

include //Wifi library

include "esp_wifi.h"

include "esp_wifi_types.h"

include "esp_system.h"

include "esp_event.h"

include "esp_event_loop.h"

include "nvs_flash.h"

using namespace std;

include

include

define WIFI_COUNTRY_CODE "GB"

define WIFI_CHANNEL_SWITCH_INTERVAL (500)

define WIFI_CHANNEL_MAX (13)

// Packet sub type mapping

define SUB_TYPE_ASSOCIATION_RESPONSE 16 // 0001

define SUB_TYPE_REASSOCIATION_REQUEST 32 // 0010

define SUB_TYPE_REASSOCIATION_RESPONSE 48 // 0011

define SUB_TYPE_PROBE_REQUEST 64 // 0100

define SUB_TYPE_PROBE_RESPONSE 80 // 0101

define SUB_TYPE_BEACON 128 // 1000

define SUB_TYPE_ATIM 144 // 1001

define SUB_TYPE_DISASSOCIATION 160 // 1010

define SUB_TYPE_AUTHENTICATION 176 // 1011

define SUB_TYPE_DEAUTHENTICATION 192 // 1100

define SUB_TYPE_ACTION 208 // 1101

define SUB_TYPE_ACTION_NO_ACK 224 // 1110

// Packet sub types enum sub_type {ASSOCIATION_REQUEST, ASSOCIATION_RESPONSE, REASSOCIATION_REQUEST, REASSOCIATION_RESPONSE, PROBE_REQUEST, PROBE_RESPONSE, BEACON, ATIM, DISASSOCIATION, AUTHENTICATION, DEAUTHENTICATION, ACTION, ACTION_NO_ACK};

uint8_t level = 0, channel = 1; static wifi_country_t wifi_country = {.cc = WIFI_COUNTRY_CODE, .schan = 1, .nchan = 13}; // Most recent esp32 library struct

// Packet header struct typedef struct wifi_ieee80211_mac_hdr_t { unsigned frame_ctrl:16; unsigned duration_id:16; uint8_t addr1[6]; // receiver address uint8_t addr2[6]; // sender address uint8_t addr3[6]; // filtering address unsigned sequence_ctrl:16; uint8_t pad[2]; u_char ssid[32]; } wifi_ieee80211_mac_hdr_t;

// Packet struct typedef struct wifi_ieee80211_packet_t { wifi_ieee80211_mac_hdr_t hdr; uint8_t payload[0]; // network data ended with 4 bytes csum (CRC32) } wifi_ieee80211_packet_t;

// Function prototypes static esp_err_t event_handler(void ctx, system_event_t event); static void wifi_collector_init(void); static void wifi_sniffer_set_channel(uint8_t channel); static const char *wifi_sniffer_packet_type2str(wifi_promiscuous_pkt_type_t type);

//#Latest Code Include String maclist[128]; bool flag = false; int res = 0; int purge_count = 0; set st_val;

const char server_address="http://192.168.1.100:7072"; const char ssid = "IktaraWifi"; const char* password = "0276b5c1";

// Event handler esp_err_t event_handler(void ctx, system_event_t event) { Serial.printf("event_handler Function"); return ESP_OK; }

// Wifi Sniffer Packet handler void wifi_sniffer_packet_handler(void * buff, wifi_promiscuous_pkt_type_t type) {

// Only monitoring management packets if (type != WIFI_PKT_MGMT) return;

// Packet variables 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; // Serial.printf("The Subtype is %d/n",hdr->frame_ctrl); if (!((hdr->frame_ctrl == SUB_TYPE_BEACON)||(hdr->frame_ctrl == SUB_TYPE_PROBE_REQUEST))) return;

////Example Code ----1 Total Length of the sniffed packet // int len = ppkt->rx_ctrl.sig_len; // Serial.printf("The Total Length of the Sniffed Packet is %d\n",len); //
////Example Code 2 Length of Payload // len -= sizeof(wifi_ieee80211_packet_t); // Serial.printf("The Total Length of the Payload Packet is %d\n",len);

// Example Code 3 Get the Mac Address
String packet; String mac; // int fctl = ntohs(ipkt->fctl); for(int i=8;i<=8+6+1;i++){ // This reads the first couple of bytes of the packet. This is where you can read the whole packet replaceing the "8+6+1" with "p->rx_ctrl.sig_len" packet += String(ppkt->payload[i],HEX); } for(int i=4;i<=15;i++){ // This removes the 'nibble' bits from the stat and end of the data we want. So we only get the mac address. mac += packet[i]; } mac.toUpperCase(); // Serial.printf("The Mac address is %s\n",mac);

//Example Find Unique Number of Mac Address Using Hash Procesdure // int n = (sizeof(maclist) / sizeof(maclist[0])); if(st_val.find(mac) == st_val.end()){ st_val.insert(mac); res++; // Serial.printf("\n"); // Serial.printf("The Inserted Mac Address Is :%s\n.The number of unique mac address is %d\n",mac,res); // Serial.printf("\n"); } // else{ // Serial.printf("################################\n"); // Serial.printf("Found the Duplicate Mac Address Is :%s\n.The number of unique mac address is %d\n",mac,res); // Serial.printf("###################################\n");

// } //%%To print Number of elements in Set
// set :: iterator itr; // for (itr = st_val.begin(); itr != st_val.end(); itr++){ // Serial.printf("%s\n",*itr); // } //

// To purge the Mac Address Set and Remove the unique number of mac address if (purge_count == 600){ Preferences preferences; purge_count=0; st_val.clear(); preferences.begin("mac-app", false); preferences.putUInt("count", res); preferences.end(); res = 0; flag = true; Serial.printf("################# The Mac Address List is purged##################\n"); }

/ Sub type filter /

// Serial.printf( "%02x:%02x:%02x:%02x:%02x:%02x:" , hdr-> addr2[0], hdr-> addr2[1], hdr-> addr2[2], hdr-> addr2[3], hdr-> addr2[4], hdr->addr2[5]);

}

// Wifi Promiscuous Mode initialisation void wifi_promiscuous_mode_change_channel(void) { // Loop around monitor channels vTaskDelay(WIFI_CHANNEL_SWITCH_INTERVAL / portTICK_PERIOD_MS); esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); Serial.printf("Channel Change Done, channel=%2d\n",channel ); channel = (channel % WIFI_CHANNEL_MAX) + 1; purge_count +=1; Serial.printf("The Test Count is %d\n",purge_count);

}

// Wifi Promiscuous Mode initialisation void wifi_promiscuous_mode_init(void) { Serial.println("wifi_promiscuous_mode_init"); nvs_flash_init(); tcpip_adapter_init(); ESP_ERROR_CHECK(esp_event_loop_init(nullptr, nullptr)); // 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_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() ); esp_wifi_set_promiscuous(true); esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler); }

void setup() { // put your setup code here, to run once: Serial.begin(115200); http_preference_publish(ssid,password,server_address); delay(1000); wifi_promiscuous_mode_init(); Serial.println("Setup done");

}

void loop() { // put your main code here, to run repeatedly: Serial.begin(115200); Serial.printf("The loop function starts ###################### flag value is %s\n",flag); wifi_promiscuous_mode_change_channel(); StaticJsonDocument<200> doc; long randNumber = random(0, 500); doc["req_Count"] = randNumber; doc["device"] = "Device07"; doc["time_stamp"] = 1351824120; char output[128]; serializeJson(doc, output); publish_mqtt(output); //// SECOND FUNCTION TO PUBLISH THE OUTPUT TO THE MQTT SERVER if (flag == true){ publish_mqtt(output); } delay(1000); Serial.println(); // delay(30000); }

Debug Logs.

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
14:12:05.416 -> configsip: 0, SPIWP:0xee
14:12:05.416 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
14:12:05.416 -> mode:DIO, clock div:1
14:12:05.416 -> load:0x3fff0030,len:1344
14:12:05.416 -> load:0x40078000,len:13836
14:12:05.416 -> load:0x40080400,len:3608
14:12:05.416 -> entry 0x400805f0
14:12:05.883 -> E (501) event: system event loop not initialized via esp_event_loop_init
14:12:13.069 -> E (7709) event: system event loop not initialized via esp_event_loop_init
14:12:14.189 -> E (8823) event: system event loop not initialized via esp_event_loop_init
14:12:15.214 -> E (9863) event: system event loop not initialized via esp_event_loop_init
14:12:16.335 -> E (10973) event: system event loop not initialized via esp_event_loop_init
14:12:16.477 -> E (11093) event: system event loop not initialized via esp_event_loop_init
14:12:18.811 -> E (13462) event: system event loop not initialized via esp_event_loop_init
14:12:18.811 -> E (13462) esp_netif_lwip: dhcpc cb: failed to post got ip event (103)
14:12:19.095 -> wifi_promiscuous_mode_init
14:12:19.095 -> Setup done
14:12:19.095 -> event_handler Functionevent_handler FunctionGuru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
14:12:19.095 -> 
14:12:19.095 -> Core  1 register dump:
14:12:19.095 -> PC      : 0x4008a4a1  PS      : 0x00060d30  A0      : 0x80157d58  A1      : 0x3ffb21d0  
14:12:19.095 -> A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
14:12:19.143 -> A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x00000004  
14:12:19.143 -> A10     : 0x00060f23  A11     : 0x3ffc603c  A12     : 0x00000004  A13     : 0x00060f23  
14:12:19.143 -> A14     : 0x007bf538  A15     : 0x003fffff  SAR     : 0x0000001d  EXCCAUSE: 0x0000001c  
14:12:19.143 -> EXCVADDR: 0x00000000  LBEG    : 0x4008a4a1  LEND    : 0x4008a4b1  LCOUNT  : 0xffffffff  
14:12:19.143 -> 
14:12:19.143 -> 
14:12:19.143 -> Backtrace: 0x4008a49e:0x3ffb21d0 0x40157d55:0x3ffb21e0 0x4015c8c2:0x3ffb24f0 0x4015c8fe:0x3ffb2580 0x400daf16:0x3ffb25c0 0x400d4f1d:0x3ffb2660 0x400dc18d:0x3ffb2820
14:12:19.143 -> 
14:12:19.143 -> 
14:12:19.143 -> 
14:12:19.143 -> 
14:12:19.143 -> ELF file SHA256: 37f170b21eea5986
14:12:19.189 -> 
14:12:19.377 -> Rebooting...
14:12:19.377 -> ets Jul 29 2019 12:21:46
14:12:19.377 -> 
14:12:19.377 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
14:12:19.377 -> configsip: 0, SPIWP:0xee
14:12:19.377 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
14:12:19.377 -> mode:DIO, clock div:1
14:12:19.377 -> load:0x3fff0030,len:1344
14:12:19.377 -> load:0x40078000,len:13836
14:12:19.377 -> load:0x40080400,len:3608
14:12:19.377 -> entry 0x400805f0
14:12:19.842 -> E (500) event: system event loop not initialized via esp_event_loop_init
14:12:26.870 -> E (7507) event: system event loop not initialized via esp_event_loop_init
14:12:27.897 -> E (8565) event: system event loop not initialized via esp_event_loop_init
14:12:28.931 -> E (9599) event: system event loop not initialized via esp_event_loop_init
14:12:29.957 -> E (10622) event: system event loop not initialized via esp_event_loop_init
14:12:30.982 -> E (11657) event: system event loop not initialized via esp_event_loop_init
14:12:31.214 -> E (11861) event: system event loop not initialized via esp_event_loop_init
14:12:32.891 -> wifi_promiscuous_mode_init
14:12:32.891 -> Setup done
14:12:32.891 -> event_handler Functionevent_handler FunctionGuru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
14:12:32.891 -> 
14:12:32.891 -> Core  1 register dump:
14:12:32.891 -> PC      : 0x4008a4a1  PS      : 0x00060d30  A0      : 0x80157d58  A1      : 0x3ffb21d0  
14:12:32.891 -> A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
14:12:32.891 -> A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x00000004  
14:12:32.938 -> A10     : 0x00060f23  A11     : 0x3ffc603c  A12     : 0x00000004  A13     : 0x00060f23  
14:12:32.938 -> A14     : 0x007bf538  A15     : 0x003fffff  SAR     : 0x0000001d  EXCCAUSE: 0x0000001c  
14:12:32.938 -> EXCVADDR: 0x00000000  LBEG    : 0x4008a4a1  LEND    : 0x4008a4b1  LCOUNT  : 0xffffffff  
14:12:32.938 -> 
14:12:32.938 -> 
14:12:32.938 -> Backtrace: 0x4008a49e:0x3ffb21d0 0x40157d55:0x3ffb21e0 0x4015c8c2:0x3ffb24f0 0x4015c8fe:0x3ffb2580 0x400daf16:0x3ffb25c0 0x400d4f1d:0x3ffb2660 0x400dc18d:0x3ffb2820
14:12:32.938 -> 
14:12:32.938 -> 
14:12:32.938 ->

More Information.

No response

nishanth-radja commented 1 year ago

@Harshit200107 can you also pls attach the ELF file

Alvin1Zhang commented 8 months ago

Thanks for reporting, will close due to short of feedback, feel free to reopen with more updates.