mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/simple_sniffer_example_v4.3' into 'release/v4.3'
examples/simple_sniffer: only enable apptrace if JTAG is selected (backport v4.3) See merge request espressif/esp-idf!13269
This commit is contained in:
commit
d1107db72d
@ -1,6 +1,3 @@
|
||||
| Supported Targets | ESP32 | ESP32-S2 |
|
||||
| ----------------- | ----- | ------- |
|
||||
|
||||
# Simple Sniffer Example
|
||||
|
||||
(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).
|
||||
- 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.
|
||||
- `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).
|
||||
- `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), 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 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.
|
||||
@ -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: Using SDMMC peripheral
|
||||
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
|
||||
|
||||
```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
|
||||
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 (9186) wifi: ic_enable_sniffer
|
||||
I (9196) cmd_sniffer: start WiFi promiscuous ok
|
||||
esp32> sniffer --stop
|
||||
sniffer> sniffer --stop
|
||||
I (31456) wifi: ic_disable_sniffer
|
||||
I (31456) wifi: flush txq
|
||||
I (31456) wifi: stop sw txq
|
||||
@ -115,7 +112,7 @@ I (31456) cmd_sniffer: stop WiFi promiscuous ok
|
||||
### Unmount SD Card
|
||||
|
||||
```bash
|
||||
esp32> unmount sd
|
||||
sniffer> unmount sd
|
||||
I (248800) example: Card unmounted
|
||||
```
|
||||
|
||||
|
@ -9,22 +9,37 @@ menu "Example Configuration"
|
||||
|
||||
choice SNIFFER_PCAP_DESTINATION
|
||||
prompt "Select destination to store pcap file"
|
||||
default SNIFFER_PCAP_DESTINATION_SD if IDF_TARGET_ESP32
|
||||
default SNIFFER_PCAP_DESTINATION_JTAG if IDF_TARGET_ESP32S2
|
||||
default SNIFFER_PCAP_DESTINATION_SD
|
||||
help
|
||||
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
|
||||
bool "SD Card"
|
||||
help
|
||||
Store pcap file to SD card.
|
||||
config SNIFFER_PCAP_DESTINATION_JTAG
|
||||
bool "JTAG (App Trace)"
|
||||
depends on APPTRACE_DEST_TRAX
|
||||
help
|
||||
Store pcap file to host via JTAG interface.
|
||||
endchoice
|
||||
|
||||
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
|
||||
string "SD card mount point in the filesystem"
|
||||
default "/sdcard"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#if CONFIG_SNIFFER_PCAP_DESTINATION_SD
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdspi_host.h"
|
||||
#include "driver/spi_common.h"
|
||||
#endif
|
||||
#include "nvs_flash.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
@ -33,6 +34,23 @@
|
||||
#define HISTORY_FILE_PATH HISTORY_MOUNT_POINT "/history.txt"
|
||||
#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";
|
||||
|
||||
#if CONFIG_SNIFFER_STORE_HISTORY
|
||||
@ -82,6 +100,8 @@ static struct {
|
||||
/** 'mount' command */
|
||||
static int mount(int argc, char **argv)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
int nerrors = arg_parse(argc, argv, (void **)&mount_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, mount_args.end, argv[0]);
|
||||
@ -90,6 +110,41 @@ static int mount(int argc, char **argv)
|
||||
/* mount sd card */
|
||||
if (!strncmp(mount_args.device->sval[0], "sd", 2)) {
|
||||
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");
|
||||
sdmmc_host_t host = SDMMC_HOST_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(13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
|
||||
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = true,
|
||||
.max_files = 4,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
ret = esp_vfs_fat_sdmmc_mount(CONFIG_SNIFFER_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
|
||||
#endif
|
||||
|
||||
// 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_FAIL) {
|
||||
ESP_LOGE(TAG, "Failed to mount filesystem. "
|
||||
|
@ -19,7 +19,3 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
# FatFS
|
||||
CONFIG_FATFS_LFN_HEAP=y
|
||||
CONFIG_FATFS_MAX_LFN=31
|
||||
|
||||
# App trace
|
||||
CONFIG_APPTRACE_DEST_TRAX=y
|
||||
CONFIG_APPTRACE_ENABLE=y
|
||||
|
Loading…
Reference in New Issue
Block a user