Merge branch 'bugfix/simple_sniffer_c3' into 'master'

examples/simple_sniffer: only enable apptrace if JTAG is selected

Closes ESPCS-583

See merge request espressif/esp-idf!12718
This commit is contained in:
Michael (XIAO Xufeng) 2021-04-27 03:37:33 +00:00
commit 8e599a2365
4 changed files with 81 additions and 24 deletions

View File

@ -1,6 +1,3 @@
| Supported Targets | ESP32 | ESP32-S2 |
| ----------------- | ----- | ------- |
# Simple Sniffer Example # Simple Sniffer Example
(See the README.md file in the upper level 'examples' directory for more information about examples.) (See the README.md file in the upper level 'examples' directory for more information about examples.)
@ -26,8 +23,8 @@ Open the project configuration menu (`idf.py menuconfig`). Then go into `Example
- Check `Store command history in flash` if you want to save command history into flash (recommend). - Check `Store command history in flash` if you want to save command history into flash (recommend).
- Select where to save the pcap file in `Select destination to store pcap file` menu item. - Select where to save the pcap file in `Select destination to store pcap file` menu item.
- `SD Card` means saving packets (pcap format) into the SD card you plug in. - `SD Card` means saving packets (pcap format) into the SD card you plug in. The default SD card work mode is set to SDMMC for target ESP32 and ESP32S3, but SPI is the only choice for other targets.
- `JTAG (App Trace)` means sending packets (pcap format) to host via JTAG interface. This feature depends on [app trace component](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/app_trace.html). - `JTAG (App Trace)` means sending packets (pcap format) to host via JTAG interface. This feature depends on [app trace component](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/app_trace.html), Component config -> Application Lelvel Tracing -> Data Destination -> Trace memory should be enabled to choose `JTAG (App Trace)` as destination.
- Set the mount point in your filesystem in `SD card mount point in the filesystem` menu item. This configuration only takes effect when you choose to save packets into SD card. - Set the mount point in your filesystem in `SD card mount point in the filesystem` menu item. This configuration only takes effect when you choose to save packets into SD card.
- Set max name length of pcap file in `Max name length of pcap file` menu item. - Set max name length of pcap file in `Max name length of pcap file` menu item.
- Set the length of sniffer work queue in `Length of sniffer work queue` menu item. - Set the length of sniffer work queue in `Length of sniffer work queue` menu item.
@ -85,7 +82,7 @@ The `sniffer` command support some important options as follow:
| | | |
======================================================= =======================================================
esp32> mount sd sniffer> mount sd
I (158912) example: Initializing SD card I (158912) example: Initializing SD card
I (158912) example: Using SDMMC peripheral I (158912) example: Using SDMMC peripheral
I (158912) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 I (158912) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
@ -98,13 +95,13 @@ Size: 14832MB
### Start Sniffer ### Start Sniffer
```bash ```bash
esp32> sniffer -f sniffer-example -i wlan -c 2 sniffer> sniffer -f sniffer-example -i wlan -c 2
I (8946) cmd_sniffer: open file successfully I (8946) cmd_sniffer: open file successfully
W (8966) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration W (8966) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (9176) phy: phy_version: 4100, 6fa5e27, Jan 25 2019, 17:02:06, 0, 2 I (9176) phy: phy_version: 4100, 6fa5e27, Jan 25 2019, 17:02:06, 0, 2
I (9186) wifi: ic_enable_sniffer I (9186) wifi: ic_enable_sniffer
I (9196) cmd_sniffer: start WiFi promiscuous ok I (9196) cmd_sniffer: start WiFi promiscuous ok
esp32> sniffer --stop sniffer> sniffer --stop
I (31456) wifi: ic_disable_sniffer I (31456) wifi: ic_disable_sniffer
I (31456) wifi: flush txq I (31456) wifi: flush txq
I (31456) wifi: stop sw txq I (31456) wifi: stop sw txq
@ -115,7 +112,7 @@ I (31456) cmd_sniffer: stop WiFi promiscuous ok
### Unmount SD Card ### Unmount SD Card
```bash ```bash
esp32> unmount sd sniffer> unmount sd
I (248800) example: Card unmounted I (248800) example: Card unmounted
``` ```

View File

@ -9,22 +9,37 @@ menu "Example Configuration"
choice SNIFFER_PCAP_DESTINATION choice SNIFFER_PCAP_DESTINATION
prompt "Select destination to store pcap file" prompt "Select destination to store pcap file"
default SNIFFER_PCAP_DESTINATION_SD if IDF_TARGET_ESP32 default SNIFFER_PCAP_DESTINATION_SD
default SNIFFER_PCAP_DESTINATION_JTAG if IDF_TARGET_ESP32S2
help help
Select where to store the pcap file. Select where to store the pcap file.
Currently support storing files to SD card or to host via JTAG interface. Currently support storing files to SD card or to host via JTAG interface with 'Trace memory' enabled.
config SNIFFER_PCAP_DESTINATION_SD config SNIFFER_PCAP_DESTINATION_SD
bool "SD Card" bool "SD Card"
help help
Store pcap file to SD card. Store pcap file to SD card.
config SNIFFER_PCAP_DESTINATION_JTAG config SNIFFER_PCAP_DESTINATION_JTAG
bool "JTAG (App Trace)" bool "JTAG (App Trace)"
depends on APPTRACE_DEST_TRAX
help help
Store pcap file to host via JTAG interface. Store pcap file to host via JTAG interface.
endchoice endchoice
if SNIFFER_PCAP_DESTINATION_SD if SNIFFER_PCAP_DESTINATION_SD
choice SNIFFER_SD_MODE
prompt "Select SD card work mode"
default SNIFFER_SD_SDMMC_MODE
help
Select whitch peripheral SD card should use.
config SNIFFER_SD_SDMMC_MODE
bool "SDMMC"
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
help
Use SDMMC mode (Not support on esp32c3).
config SNIFFER_SD_SPI_MODE
bool "SPI"
help
Use SPI mode.
endchoice
config SNIFFER_MOUNT_POINT config SNIFFER_MOUNT_POINT
string "SD card mount point in the filesystem" string "SD card mount point in the filesystem"
default "/sdcard" default "/sdcard"

View File

@ -22,6 +22,7 @@
#if CONFIG_SNIFFER_PCAP_DESTINATION_SD #if CONFIG_SNIFFER_PCAP_DESTINATION_SD
#include "driver/sdmmc_host.h" #include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h" #include "driver/sdspi_host.h"
#include "driver/spi_common.h"
#endif #endif
#include "nvs_flash.h" #include "nvs_flash.h"
#include "sdmmc_cmd.h" #include "sdmmc_cmd.h"
@ -33,6 +34,23 @@
#define HISTORY_FILE_PATH HISTORY_MOUNT_POINT "/history.txt" #define HISTORY_FILE_PATH HISTORY_MOUNT_POINT "/history.txt"
#endif #endif
#if CONFIG_SNIFFER_SD_SPI_MODE
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
#define PIN_NUM_MISO 2
#define PIN_NUM_MOSI 15
#define PIN_NUM_CLK 14
#define PIN_NUM_CS 13
#elif CONFIG_IDF_TARGET_ESP32C3
#define PIN_NUM_MISO 18
#define PIN_NUM_MOSI 9
#define PIN_NUM_CLK 8
#define PIN_NUM_CS 19
#endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
#endif // CONFIG_SNIFFER_SD_SPI_MODE
static const char *TAG = "example"; static const char *TAG = "example";
#if CONFIG_SNIFFER_STORE_HISTORY #if CONFIG_SNIFFER_STORE_HISTORY
@ -82,6 +100,8 @@ static struct {
/** 'mount' command */ /** 'mount' command */
static int mount(int argc, char **argv) static int mount(int argc, char **argv)
{ {
esp_err_t ret;
int nerrors = arg_parse(argc, argv, (void **)&mount_args); int nerrors = arg_parse(argc, argv, (void **)&mount_args);
if (nerrors != 0) { if (nerrors != 0) {
arg_print_errors(stderr, mount_args.end, argv[0]); arg_print_errors(stderr, mount_args.end, argv[0]);
@ -90,6 +110,41 @@ static int mount(int argc, char **argv)
/* mount sd card */ /* mount sd card */
if (!strncmp(mount_args.device->sval[0], "sd", 2)) { if (!strncmp(mount_args.device->sval[0], "sd", 2)) {
ESP_LOGI(TAG, "Initializing SD card"); ESP_LOGI(TAG, "Initializing SD card");
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = true,
.max_files = 4,
.allocation_unit_size = 16 * 1024
};
// initialize SD card and mount FAT filesystem.
sdmmc_card_t *card;
#if CONFIG_SNIFFER_SD_SPI_MODE
ESP_LOGI(TAG, "Using SPI peripheral");
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
spi_bus_config_t bus_cfg = {
.mosi_io_num = PIN_NUM_MOSI,
.miso_io_num = PIN_NUM_MISO,
.sclk_io_num = PIN_NUM_CLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 4000,
};
ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CH_AUTO);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize bus.");
return 1;
}
// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = PIN_NUM_CS;
slot_config.host_id = host.slot;
ret = esp_vfs_fat_sdspi_mount(CONFIG_SNIFFER_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
#else
ESP_LOGI(TAG, "Using SDMMC peripheral"); ESP_LOGI(TAG, "Using SDMMC peripheral");
sdmmc_host_t host = SDMMC_HOST_DEFAULT(); sdmmc_host_t host = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
@ -100,15 +155,9 @@ static int mount(int argc, char **argv)
gpio_set_pull_mode(12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only gpio_set_pull_mode(12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
gpio_set_pull_mode(13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes gpio_set_pull_mode(13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
esp_vfs_fat_sdmmc_mount_config_t mount_config = { ret = esp_vfs_fat_sdmmc_mount(CONFIG_SNIFFER_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
.format_if_mount_failed = true, #endif
.max_files = 4,
.allocation_unit_size = 16 * 1024
};
// initialize SD card and mount FAT filesystem.
sdmmc_card_t *card;
esp_err_t ret = esp_vfs_fat_sdmmc_mount(CONFIG_SNIFFER_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) { if (ret != ESP_OK) {
if (ret == ESP_FAIL) { if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount filesystem. " ESP_LOGE(TAG, "Failed to mount filesystem. "

View File

@ -19,7 +19,3 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
# FatFS # FatFS
CONFIG_FATFS_LFN_HEAP=y CONFIG_FATFS_LFN_HEAP=y
CONFIG_FATFS_MAX_LFN=31 CONFIG_FATFS_MAX_LFN=31
# App trace
CONFIG_APPTRACE_DEST_TRAX=y
CONFIG_APPTRACE_ENABLE=y