2018-09-26 23:24:12 -04:00
|
|
|
/* Sniffer example.
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2020-02-03 05:01:04 -05:00
|
|
|
#include "sdkconfig.h"
|
2018-09-26 23:24:12 -04:00
|
|
|
#include "linenoise/linenoise.h"
|
|
|
|
#include "argtable3/argtable3.h"
|
|
|
|
#include "esp_console.h"
|
2018-11-20 05:26:53 -05:00
|
|
|
#include "esp_event.h"
|
2018-09-26 23:24:12 -04:00
|
|
|
#include "esp_vfs_fat.h"
|
|
|
|
#include "esp_wifi.h"
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_log.h"
|
2020-06-02 05:38:22 -04:00
|
|
|
#if CONFIG_SNIFFER_PCAP_DESTINATION_SD
|
2018-09-26 23:24:12 -04:00
|
|
|
#include "driver/sdmmc_host.h"
|
|
|
|
#include "driver/sdspi_host.h"
|
2021-04-21 02:31:42 -04:00
|
|
|
#include "driver/spi_common.h"
|
2020-06-02 05:38:22 -04:00
|
|
|
#endif
|
2018-09-26 23:24:12 -04:00
|
|
|
#include "nvs_flash.h"
|
|
|
|
#include "sdmmc_cmd.h"
|
2020-02-03 05:01:04 -05:00
|
|
|
#include "cmd_system.h"
|
|
|
|
#include "cmd_sniffer.h"
|
2021-05-12 13:52:28 -04:00
|
|
|
#if CONFIG_ETH_USE_SPI_ETHERNET
|
|
|
|
#include "driver/spi_master.h"
|
|
|
|
#endif // CONFIG_ETH_USE_SPI_ETHERNET
|
2018-09-26 23:24:12 -04:00
|
|
|
|
2019-05-09 10:43:06 -04:00
|
|
|
#if CONFIG_SNIFFER_STORE_HISTORY
|
2018-09-26 23:24:12 -04:00
|
|
|
#define HISTORY_MOUNT_POINT "/data"
|
|
|
|
#define HISTORY_FILE_PATH HISTORY_MOUNT_POINT "/history.txt"
|
|
|
|
#endif
|
|
|
|
|
2021-04-21 02:31:42 -04:00
|
|
|
#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
|
|
|
|
|
2018-09-26 23:24:12 -04:00
|
|
|
static const char *TAG = "example";
|
|
|
|
|
2019-05-09 10:43:06 -04:00
|
|
|
#if CONFIG_SNIFFER_STORE_HISTORY
|
2018-09-26 23:24:12 -04:00
|
|
|
/* Initialize filesystem for command history store */
|
2019-07-16 05:33:30 -04:00
|
|
|
static void initialize_filesystem(void)
|
2018-09-26 23:24:12 -04:00
|
|
|
{
|
|
|
|
static wl_handle_t wl_handle;
|
|
|
|
const esp_vfs_fat_mount_config_t mount_config = {
|
|
|
|
.max_files = 4,
|
|
|
|
.format_if_mount_failed = true
|
|
|
|
};
|
|
|
|
esp_err_t err = esp_vfs_fat_spiflash_mount(HISTORY_MOUNT_POINT, "storage", &mount_config, &wl_handle);
|
|
|
|
if (err != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
static void initialize_nvs(void)
|
2018-09-26 23:24:12 -04:00
|
|
|
{
|
|
|
|
esp_err_t err = nvs_flash_init();
|
|
|
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
|
|
err = nvs_flash_init();
|
|
|
|
}
|
|
|
|
ESP_ERROR_CHECK(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize wifi with tcp/ip adapter */
|
2019-07-16 05:33:30 -04:00
|
|
|
static void initialize_wifi(void)
|
2018-09-26 23:24:12 -04:00
|
|
|
{
|
|
|
|
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_mode(WIFI_MODE_NULL));
|
|
|
|
}
|
|
|
|
|
2021-05-12 13:52:28 -04:00
|
|
|
#ifndef CONFIG_SNIFFER_NO_ETHERNET
|
|
|
|
/** Event handler for Ethernet events */
|
|
|
|
static void eth_event_handler(void *arg, esp_event_base_t event_base,
|
|
|
|
int32_t event_id, void *event_data)
|
|
|
|
{
|
|
|
|
uint8_t mac_addr[6] = {0};
|
|
|
|
/* we can get the ethernet driver handle from event data */
|
|
|
|
esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
|
|
|
|
|
|
|
|
switch (event_id) {
|
|
|
|
case ETHERNET_EVENT_CONNECTED:
|
|
|
|
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
|
|
|
|
printf("\n");
|
|
|
|
ESP_LOGI(TAG, "Ethernet Link Up");
|
|
|
|
ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
|
|
|
break;
|
|
|
|
case ETHERNET_EVENT_DISCONNECTED:
|
|
|
|
printf("\n");
|
|
|
|
ESP_LOGI(TAG, "Ethernet Link Down");
|
|
|
|
break;
|
|
|
|
case ETHERNET_EVENT_START:
|
|
|
|
printf("\n");
|
|
|
|
ESP_LOGI(TAG, "Ethernet Started");
|
|
|
|
break;
|
|
|
|
case ETHERNET_EVENT_STOP:
|
|
|
|
printf("\n");
|
|
|
|
ESP_LOGI(TAG, "Ethernet Stopped");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initialize_eth(void)
|
|
|
|
{
|
|
|
|
// Register user defined event handers
|
|
|
|
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL));
|
|
|
|
|
|
|
|
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
|
|
|
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
|
|
|
phy_config.phy_addr = CONFIG_SNIFFER_ETH_PHY_ADDR;
|
|
|
|
phy_config.reset_gpio_num = CONFIG_SNIFFER_ETH_PHY_RST_GPIO;
|
|
|
|
#if CONFIG_SNIFFER_USE_INTERNAL_ETHERNET
|
|
|
|
mac_config.smi_mdc_gpio_num = CONFIG_SNIFFER_ETH_MDC_GPIO;
|
|
|
|
mac_config.smi_mdio_gpio_num = CONFIG_SNIFFER_ETH_MDIO_GPIO;
|
|
|
|
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
|
|
|
|
#if CONFIG_SNIFFER_ETH_PHY_IP101
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config);
|
|
|
|
#elif CONFIG_SNIFFER_ETH_PHY_RTL8201
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_rtl8201(&phy_config);
|
|
|
|
#elif CONFIG_SNIFFER_ETH_PHY_LAN8720
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
|
|
|
|
#elif CONFIG_SNIFFER_ETH_PHY_DP83848
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
|
|
|
|
#elif CONFIG_SNIFFER_ETH_PHY_KSZ8041
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8041(&phy_config);
|
|
|
|
#elif CONFIG_SNIFFER_ETH_PHY_KSZ8081
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8081(&phy_config);
|
|
|
|
#endif
|
|
|
|
#elif CONFIG_ETH_USE_SPI_ETHERNET
|
|
|
|
gpio_install_isr_service(0);
|
|
|
|
spi_device_handle_t spi_handle = NULL;
|
|
|
|
spi_bus_config_t buscfg = {
|
|
|
|
.miso_io_num = CONFIG_SNIFFER_ETH_SPI_MISO_GPIO,
|
|
|
|
.mosi_io_num = CONFIG_SNIFFER_ETH_SPI_MOSI_GPIO,
|
|
|
|
.sclk_io_num = CONFIG_SNIFFER_ETH_SPI_SCLK_GPIO,
|
|
|
|
.quadwp_io_num = -1,
|
|
|
|
.quadhd_io_num = -1,
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_SNIFFER_ETH_SPI_HOST, &buscfg, 1));
|
|
|
|
|
|
|
|
#if CONFIG_SNIFFER_USE_KSZ8851SNL
|
|
|
|
spi_device_interface_config_t devcfg = {
|
|
|
|
.mode = 0,
|
|
|
|
.clock_speed_hz = CONFIG_SNIFFER_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
|
|
|
.spics_io_num = CONFIG_SNIFFER_ETH_SPI_CS_GPIO,
|
|
|
|
.queue_size = 20
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_SNIFFER_ETH_SPI_HOST, &devcfg, &spi_handle));
|
|
|
|
/* KSZ8851SNL ethernet driver is based on spi driver */
|
|
|
|
eth_ksz8851snl_config_t ksz8851snl_config = ETH_KSZ8851SNL_DEFAULT_CONFIG(spi_handle);
|
|
|
|
ksz8851snl_config.int_gpio_num = CONFIG_SNIFFER_ETH_SPI_INT_GPIO;
|
|
|
|
esp_eth_mac_t *mac = esp_eth_mac_new_ksz8851snl(&ksz8851snl_config, &mac_config);
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8851snl(&phy_config);
|
|
|
|
#elif CONFIG_SNIFFER_USE_DM9051
|
|
|
|
spi_device_interface_config_t devcfg = {
|
|
|
|
.command_bits = 1,
|
|
|
|
.address_bits = 7,
|
|
|
|
.mode = 0,
|
|
|
|
.clock_speed_hz = CONFIG_SNIFFER_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
|
|
|
.spics_io_num = CONFIG_SNIFFER_ETH_SPI_CS_GPIO,
|
|
|
|
.queue_size = 20
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_SNIFFER_ETH_SPI_HOST, &devcfg, &spi_handle));
|
|
|
|
/* dm9051 ethernet driver is based on spi driver */
|
|
|
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
|
|
|
dm9051_config.int_gpio_num = CONFIG_SNIFFER_ETH_SPI_INT_GPIO;
|
|
|
|
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
|
|
|
#elif CONFIG_SNIFFER_USE_W5500
|
|
|
|
spi_device_interface_config_t devcfg = {
|
|
|
|
.command_bits = 16, // Actually it's the address phase in W5500 SPI frame
|
|
|
|
.address_bits = 8, // Actually it's the control phase in W5500 SPI frame
|
|
|
|
.mode = 0,
|
|
|
|
.clock_speed_hz = CONFIG_SNIFFER_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
|
|
|
.spics_io_num = CONFIG_SNIFFER_ETH_SPI_CS_GPIO,
|
|
|
|
.queue_size = 20
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_SNIFFER_ETH_SPI_HOST, &devcfg, &spi_handle));
|
|
|
|
/* w5500 ethernet driver is based on spi driver */
|
|
|
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
|
|
|
w5500_config.int_gpio_num = CONFIG_SNIFFER_ETH_SPI_INT_GPIO;
|
|
|
|
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
|
|
|
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
|
|
|
|
#endif
|
|
|
|
#endif // CONFIG_ETH_USE_SPI_ETHERNET
|
|
|
|
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
|
|
|
esp_eth_handle_t eth_handle = NULL;
|
|
|
|
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
|
|
|
#if !CONFIG_SNIFFER_USE_INTERNAL_ETHERNET
|
|
|
|
/* The SPI Ethernet module might doesn't have a burned factory MAC address, we cat to set it manually.
|
|
|
|
02:00:00 is a Locally Administered OUI range so should not be used except when testing on a LAN under your control.
|
|
|
|
*/
|
|
|
|
ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR, (uint8_t[]) {
|
|
|
|
0x02, 0x00, 0x00, 0x12, 0x34, 0x56
|
|
|
|
}));
|
|
|
|
#endif
|
|
|
|
/* start Ethernet driver state machine */
|
|
|
|
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
|
|
|
|
|
|
|
|
/* Register Ethernet interface to could be used by sniffer */
|
|
|
|
ESP_ERROR_CHECK(sniffer_reg_eth_intf(eth_handle));
|
|
|
|
}
|
|
|
|
#endif // CONFIG_SNIFFER_NO_ETHERNET
|
|
|
|
|
2019-01-25 04:03:01 -05:00
|
|
|
#if CONFIG_SNIFFER_PCAP_DESTINATION_SD
|
2018-09-26 23:24:12 -04:00
|
|
|
static struct {
|
|
|
|
struct arg_str *device;
|
|
|
|
struct arg_end *end;
|
|
|
|
} mount_args;
|
|
|
|
|
|
|
|
/** 'mount' command */
|
|
|
|
static int mount(int argc, char **argv)
|
|
|
|
{
|
2021-04-21 02:31:42 -04:00
|
|
|
esp_err_t ret;
|
|
|
|
|
2018-09-26 23:24:12 -04:00
|
|
|
int nerrors = arg_parse(argc, argv, (void **)&mount_args);
|
|
|
|
if (nerrors != 0) {
|
|
|
|
arg_print_errors(stderr, mount_args.end, argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* mount sd card */
|
|
|
|
if (!strncmp(mount_args.device->sval[0], "sd", 2)) {
|
|
|
|
ESP_LOGI(TAG, "Initializing SD card");
|
2021-04-21 02:31:42 -04:00
|
|
|
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
|
2018-09-26 23:24:12 -04:00
|
|
|
ESP_LOGI(TAG, "Using SDMMC peripheral");
|
|
|
|
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
|
|
|
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
|
|
|
|
|
|
|
gpio_set_pull_mode(15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1-line modes
|
|
|
|
gpio_set_pull_mode(2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
|
|
|
|
gpio_set_pull_mode(4, GPIO_PULLUP_ONLY); // D1, 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
|
|
|
|
|
2021-04-21 02:31:42 -04:00
|
|
|
ret = esp_vfs_fat_sdmmc_mount(CONFIG_SNIFFER_MOUNT_POINT, &host, &slot_config, &mount_config, &card);
|
|
|
|
#endif
|
2018-09-26 23:24:12 -04:00
|
|
|
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
if (ret == ESP_FAIL) {
|
|
|
|
ESP_LOGE(TAG, "Failed to mount filesystem. "
|
|
|
|
"If you want the card to be formatted, set format_if_mount_failed = true.");
|
|
|
|
} else {
|
|
|
|
ESP_LOGE(TAG, "Failed to initialize the card (%s). "
|
|
|
|
"Make sure SD card lines have pull-up resistors in place.",
|
|
|
|
esp_err_to_name(ret));
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* print card info if mount successfully */
|
|
|
|
sdmmc_card_print_info(stdout, card);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
static void register_mount(void)
|
2018-09-26 23:24:12 -04:00
|
|
|
{
|
|
|
|
mount_args.device = arg_str1(NULL, NULL, "<sd>", "choose a proper device to mount/unmount");
|
|
|
|
mount_args.end = arg_end(1);
|
|
|
|
const esp_console_cmd_t cmd = {
|
|
|
|
.command = "mount",
|
|
|
|
.help = "mount the filesystem",
|
|
|
|
.hint = NULL,
|
|
|
|
.func = &mount,
|
|
|
|
.argtable = &mount_args
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unmount(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int nerrors = arg_parse(argc, argv, (void **)&mount_args);
|
|
|
|
if (nerrors != 0) {
|
|
|
|
arg_print_errors(stderr, mount_args.end, argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
2019-01-25 04:03:01 -05:00
|
|
|
/* unmount sd card */
|
2018-09-26 23:24:12 -04:00
|
|
|
if (!strncmp(mount_args.device->sval[0], "sd", 2)) {
|
|
|
|
if (esp_vfs_fat_sdmmc_unmount() != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Card unmount failed");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Card unmounted");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
static void register_unmount(void)
|
2018-09-26 23:24:12 -04:00
|
|
|
{
|
|
|
|
mount_args.device = arg_str1(NULL, NULL, "<sd>", "choose a proper device to mount/unmount");
|
|
|
|
mount_args.end = arg_end(1);
|
|
|
|
const esp_console_cmd_t cmd = {
|
|
|
|
.command = "unmount",
|
|
|
|
.help = "unmount the filesystem",
|
|
|
|
.hint = NULL,
|
|
|
|
.func = &unmount,
|
|
|
|
.argtable = &mount_args
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
}
|
2019-01-25 04:03:01 -05:00
|
|
|
#endif // CONFIG_SNIFFER_PCAP_DESTINATION_SD
|
2018-09-26 23:24:12 -04:00
|
|
|
|
|
|
|
void app_main(void)
|
|
|
|
{
|
|
|
|
initialize_nvs();
|
|
|
|
|
2021-05-12 13:52:28 -04:00
|
|
|
/*--- Initialize Network ---*/
|
|
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
2020-02-03 05:01:04 -05:00
|
|
|
/* Initialize WiFi */
|
|
|
|
initialize_wifi();
|
2021-05-12 13:52:28 -04:00
|
|
|
#ifndef CONFIG_SNIFFER_NO_ETHERNET
|
|
|
|
/* Initialize Ethernet */
|
|
|
|
initialize_eth();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*--- Initialize Console ---*/
|
2020-05-27 23:00:56 -04:00
|
|
|
esp_console_repl_t *repl = NULL;
|
2020-02-03 05:01:04 -05:00
|
|
|
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
2019-05-09 10:43:06 -04:00
|
|
|
#if CONFIG_SNIFFER_STORE_HISTORY
|
2018-09-26 23:24:12 -04:00
|
|
|
initialize_filesystem();
|
2020-02-03 05:01:04 -05:00
|
|
|
repl_config.history_save_path = HISTORY_FILE_PATH;
|
2018-09-26 23:24:12 -04:00
|
|
|
#endif
|
2020-02-03 05:01:04 -05:00
|
|
|
repl_config.prompt = "sniffer>";
|
2020-10-14 06:10:11 -04:00
|
|
|
|
|
|
|
// install console REPL environment
|
|
|
|
#if CONFIG_ESP_CONSOLE_UART
|
|
|
|
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
2020-05-27 23:00:56 -04:00
|
|
|
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
2020-10-14 06:10:11 -04:00
|
|
|
#elif CONFIG_ESP_CONSOLE_USB_CDC
|
|
|
|
esp_console_dev_usb_cdc_config_t cdc_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT();
|
|
|
|
ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&cdc_config, &repl_config, &repl));
|
|
|
|
#endif
|
2018-09-26 23:24:12 -04:00
|
|
|
|
|
|
|
/* Register commands */
|
2019-01-25 04:03:01 -05:00
|
|
|
#if CONFIG_SNIFFER_PCAP_DESTINATION_SD
|
2018-09-26 23:24:12 -04:00
|
|
|
register_mount();
|
|
|
|
register_unmount();
|
2019-01-25 04:03:01 -05:00
|
|
|
#endif
|
2018-09-26 23:24:12 -04:00
|
|
|
register_sniffer();
|
|
|
|
register_system();
|
|
|
|
|
|
|
|
printf("\n =======================================================\n");
|
|
|
|
printf(" | Steps to sniffer WiFi packets |\n");
|
|
|
|
printf(" | |\n");
|
2021-05-12 13:52:28 -04:00
|
|
|
printf(" | 1. Enter 'help' to check all commands usage |\n");
|
2018-09-26 23:24:12 -04:00
|
|
|
printf(" | 2. Enter 'mount <device>' to mount filesystem |\n");
|
|
|
|
printf(" | 3. Enter 'sniffer' to start capture packets |\n");
|
|
|
|
printf(" | 4. Enter 'unmount <device>' to unmount filesystem |\n");
|
|
|
|
printf(" | |\n");
|
|
|
|
printf(" =======================================================\n\n");
|
|
|
|
|
2020-05-27 23:00:56 -04:00
|
|
|
// start console REPL
|
|
|
|
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
2018-09-26 23:24:12 -04:00
|
|
|
}
|