Wifi sniffer promiscuous & BLE coexistence

malaimo
Posts: 17
Joined: Mon Sep 25, 2017 6:28 am

Wifi sniffer promiscuous & BLE coexistence

Postby malaimo » Mon Sep 25, 2017 6:51 am

I need to sniffer around macs, and then post them to android phone via BLE.
But It comes to error.
my code is

Code: Select all

// init wifi sniffer
    esp_err_t ret;
    // Initialize NVS
    ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    
    tcpip_adapter_init();
    one_shot_timer_start();

    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_storage(WIFI_STORAGE_RAM));

    // ESP_ERROR_CHECK(esp_wifi_set_promiscuous_filter(WIFI_PROMIS_FILTER_MASK_MGMT));
    ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb));
    ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
    
    // ble init
    
    
    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ret = esp_bt_controller_init(&bt_cfg);
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s initialize controller failed\n", __func__);
        return;
    }

    ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s enable controller failed\n", __func__);
        return;
    }
    ret = esp_bluedroid_init();
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s init bluetooth failed\n", __func__);
        return;
    }
    ret = esp_bluedroid_enable();
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s enable bluetooth failed\n", __func__);
        return;
    }

    ret = esp_ble_gatts_register_callback(gatts_event_handler);
    if (ret){
        ESP_LOGE(GATTS_TAG, "gatts register error, error code = %x", ret);
        return;
    }
    ret = esp_ble_gap_register_callback(gap_event_handler);
    if (ret){
        ESP_LOGE(GATTS_TAG, "gap register error, error code = %x", ret);
        return;
    }
    ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
    if (ret){
        ESP_LOGE(GATTS_TAG, "gatts app register error, error code = %x", ret);
        return;
    }
    
    // ret = esp_ble_gatts_app_register(PROFILE_B_APP_ID);
    // if (ret){
    //     ESP_LOGE(GATTS_TAG, "gatts app register error, error code = %x", ret);
    //     return;
    // }

    esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
    if (local_mtu_ret){
        ESP_LOGE(GATTS_TAG, "set local  MTU failed, error code = %x", local_mtu_ret);
    }
crash message:

Code: Select all

I (1370) cpu_start: App cpu up.
I (1383) heap_init: Initializing. RAM available for dynamic allocation:
I (1404) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (1423) heap_init: At 3FFD9270 len 00006D90 (27 KiB): DRAM
I (1442) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (1462) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1482) heap_init: At 400923CC len 0000DC34 (55 KiB): IRAM
I (1501) cpu_start: Pro cpu start user code
assertion "res == pdTRUE" failed: file "/Users/wiki/esp/esp-idf/components/esp32/./dport_access.c", line 184, function: esp_dport_access_int_init
abort() was called at PC 0x40100c8b on core 0
0x40100c8b: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)


Backtrace: 0x400892e4:0x3ffe3b50 0x400893e3:0x3ffe3b70 0x40100c8b:0x3ffe3b90 0x400d0e9a:0x3ffe3bc0 0x40080e3c:0x3ffe3bf0 0x4008107d:0x3ffe3c20 0x40078c12:0x3ffe3c40 0x40078cc5:0x3ffe3c70 0x40078f2e:0x3ffe3cb0 0x40079073:0x3ffe3e70 0x40007c31:0x3ffe3eb0 0x4000073d:0x3ffe3f20
0x400892e4: invoke_abort at /Users/wiki/esp/esp-idf/components/esp32/./panic.c:553

0x400893e3: abort at /Users/wiki/esp/esp-idf/components/esp32/./panic.c:553

0x40100c8b: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

0x400d0e9a: esp_dport_access_int_init at /Users/wiki/esp/esp-idf/components/esp32/./dport_access.c:184 (discriminator 1)

0x40080e3c: start_cpu0_default at /Users/wiki/esp/esp-idf/components/esp32/./cpu_start.c:324

0x4008107d: call_start_cpu0 at /Users/wiki/esp/esp-idf/components/esp32/./cpu_start.c:207

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Wifi sniffer promiscuous & BLE coexistence

Postby kolban » Mon Oct 30, 2017 4:50 am

I think it would probably help if you related your posted code to file names and line numbers. In the trace we see errors in "file X" and "line Y" but in your pasted code, we can't map those back to which line in your source caused the exception.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: Wifi sniffer promiscuous & BLE coexistence

Postby chegewara » Mon Oct 30, 2017 5:01 am

By looking at amount of free heap i can say its most likely the reason:
I (1404) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (1423) heap_init: At 3FFD9270 len 00006D90 (27 KiB): DRAM
I have similar errors with even more free DRAM when i try to run WiFi with BLE.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Wifi sniffer promiscuous & BLE coexistence

Postby ESP_Sprite » Mon Oct 30, 2017 5:49 pm

Actually, there still is a (somewhat low but perfectly usable) amount of DRAM available: the D/IRAM regions can be used as both DRAM as well as IRAM.

I'm not entirely sure what's going on here... it seems like the creation of an internal task failed, even before app_main is called, because there's not enough memory available. Could you maybe have modified the stack sizes for various tasks (idle, timers, ...) in menuconfig in such a way they take up so much memory that there's none left for internal tasks?

Who is online

Users browsing this forum: ESP_rrtandler and 107 guests