|
|
|
@ -4,20 +4,132 @@
|
|
|
|
#include "argtable3/argtable3.h"
|
|
|
|
#include "argtable3/argtable3.h"
|
|
|
|
#include "wifi_cfg.h"
|
|
|
|
#include "wifi_cfg.h"
|
|
|
|
#include "iperf.h"
|
|
|
|
#include "iperf.h"
|
|
|
|
#include "wifi_controller.h" // Required for Mode Switching
|
|
|
|
#include "wifi_controller.h"
|
|
|
|
|
|
|
|
#include "esp_wifi.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
|
|
|
|
// Helper to refresh prompt at end of commands
|
|
|
|
// --- Helper: Prompt Update ---
|
|
|
|
|
|
|
|
// Updates the "esp32>" vs "esp32*>" prompt based on dirty state
|
|
|
|
static void end_cmd(void) {
|
|
|
|
static void end_cmd(void) {
|
|
|
|
app_console_update_prompt();
|
|
|
|
app_console_update_prompt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// COMMAND: nvs (Storage Management)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
|
|
|
struct arg_lit *dump;
|
|
|
|
|
|
|
|
struct arg_lit *clear_all;
|
|
|
|
|
|
|
|
struct arg_lit *help;
|
|
|
|
|
|
|
|
struct arg_end *end;
|
|
|
|
|
|
|
|
} nvs_args;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void print_nvs_key_str(nvs_handle_t h, const char *key, const char *label) {
|
|
|
|
|
|
|
|
char buf[64] = {0};
|
|
|
|
|
|
|
|
size_t len = sizeof(buf);
|
|
|
|
|
|
|
|
if (nvs_get_str(h, key, buf, &len) == ESP_OK) {
|
|
|
|
|
|
|
|
printf(" %-12s : %s\n", label, buf);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf(" %-12s : <empty>\n", label);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void print_nvs_key_u32(nvs_handle_t h, const char *key, const char *label) {
|
|
|
|
|
|
|
|
uint32_t val = 0;
|
|
|
|
|
|
|
|
if (nvs_get_u32(h, key, &val) == ESP_OK) {
|
|
|
|
|
|
|
|
printf(" %-12s : %" PRIu32 "\n", label, val);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf(" %-12s : <empty>\n", label);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void print_nvs_key_u8(nvs_handle_t h, const char *key, const char *label) {
|
|
|
|
|
|
|
|
uint8_t val = 0;
|
|
|
|
|
|
|
|
if (nvs_get_u8(h, key, &val) == ESP_OK) {
|
|
|
|
|
|
|
|
printf(" %-12s : %u\n", label, val);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf(" %-12s : <empty>\n", label);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int cmd_nvs(int argc, char **argv) {
|
|
|
|
|
|
|
|
int nerrors = arg_parse(argc, argv, (void **)&nvs_args);
|
|
|
|
|
|
|
|
if (nerrors > 0) {
|
|
|
|
|
|
|
|
arg_print_errors(stderr, nvs_args.end, argv[0]);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nvs_args.help->count > 0) {
|
|
|
|
|
|
|
|
printf("Usage: nvs [--dump] [--clear-all]\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- CLEAR ALL ---
|
|
|
|
|
|
|
|
if (nvs_args.clear_all->count > 0) {
|
|
|
|
|
|
|
|
printf("Erasing ALL settings from NVS...\n");
|
|
|
|
|
|
|
|
wifi_cfg_clear_credentials();
|
|
|
|
|
|
|
|
wifi_cfg_clear_monitor_channel();
|
|
|
|
|
|
|
|
iperf_param_clear();
|
|
|
|
|
|
|
|
printf("Done. Please reboot.\n");
|
|
|
|
|
|
|
|
end_cmd();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- DUMP ---
|
|
|
|
|
|
|
|
printf("\n--- [WiFi Config (netcfg)] ---\n");
|
|
|
|
|
|
|
|
nvs_handle_t h;
|
|
|
|
|
|
|
|
if (nvs_open("netcfg", NVS_READONLY, &h) == ESP_OK) {
|
|
|
|
|
|
|
|
print_nvs_key_str(h, "ssid", "SSID");
|
|
|
|
|
|
|
|
print_nvs_key_str(h, "pass", "Password");
|
|
|
|
|
|
|
|
print_nvs_key_str(h, "ip", "Static IP");
|
|
|
|
|
|
|
|
print_nvs_key_str(h, "mask", "Netmask");
|
|
|
|
|
|
|
|
print_nvs_key_str(h, "gw", "Gateway");
|
|
|
|
|
|
|
|
print_nvs_key_u8 (h, "dhcp", "DHCP");
|
|
|
|
|
|
|
|
print_nvs_key_u8 (h, "mon_ch", "Monitor Ch");
|
|
|
|
|
|
|
|
nvs_close(h);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf("Failed to open 'netcfg' namespace.\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n--- [iPerf Config (storage)] ---\n");
|
|
|
|
|
|
|
|
if (nvs_open("storage", NVS_READONLY, &h) == ESP_OK) {
|
|
|
|
|
|
|
|
print_nvs_key_str(h, "iperf_dst_ip", "Dest IP");
|
|
|
|
|
|
|
|
print_nvs_key_u32(h, "iperf_port", "Port");
|
|
|
|
|
|
|
|
print_nvs_key_u32(h, "iperf_pps", "Target PPS");
|
|
|
|
|
|
|
|
print_nvs_key_u32(h, "iperf_len", "Packet Len");
|
|
|
|
|
|
|
|
print_nvs_key_u32(h, "iperf_burst", "Burst");
|
|
|
|
|
|
|
|
nvs_close(h);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf("Failed to open 'storage' namespace.\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
end_cmd();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_nvs_cmd(void) {
|
|
|
|
|
|
|
|
nvs_args.dump = arg_lit0(NULL, "dump", "Show all");
|
|
|
|
|
|
|
|
nvs_args.clear_all = arg_lit0(NULL, "clear-all", "Factory Reset");
|
|
|
|
|
|
|
|
nvs_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
|
|
|
|
nvs_args.end = arg_end(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = {
|
|
|
|
|
|
|
|
.command = "nvs",
|
|
|
|
|
|
|
|
.help = "Storage Management",
|
|
|
|
|
|
|
|
.func = &cmd_nvs,
|
|
|
|
|
|
|
|
.argtable = &nvs_args
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
// COMMAND: iperf
|
|
|
|
// COMMAND: iperf
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
static struct {
|
|
|
|
static struct {
|
|
|
|
struct arg_lit *start, *stop, *status, *save, *reload;
|
|
|
|
struct arg_lit *start, *stop, *status, *save, *reload;
|
|
|
|
|
|
|
|
struct arg_lit *clear_nvs;
|
|
|
|
struct arg_str *ip;
|
|
|
|
struct arg_str *ip;
|
|
|
|
struct arg_int *port, *pps, *len, *burst;
|
|
|
|
struct arg_int *port, *pps, *len, *burst;
|
|
|
|
struct arg_lit *help;
|
|
|
|
struct arg_lit *help;
|
|
|
|
@ -35,10 +147,17 @@ static int cmd_iperf(int argc, char **argv) {
|
|
|
|
printf("Usage: iperf [options]\n");
|
|
|
|
printf("Usage: iperf [options]\n");
|
|
|
|
printf(" --start Start traffic\n");
|
|
|
|
printf(" --start Start traffic\n");
|
|
|
|
printf(" --stop Stop traffic\n");
|
|
|
|
printf(" --stop Stop traffic\n");
|
|
|
|
printf(" --status Show stats\n");
|
|
|
|
|
|
|
|
printf(" --save Save config to NVS\n");
|
|
|
|
printf(" --save Save config to NVS\n");
|
|
|
|
printf(" -c <ip> Set Destination IP\n");
|
|
|
|
printf(" --clear-nvs Reset to defaults\n");
|
|
|
|
printf(" --pps <n> Set Packets Per Second\n");
|
|
|
|
printf(" -c <ip> Set Dest IP\n");
|
|
|
|
|
|
|
|
printf(" --pps <n> Set Packets Per Sec\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (iperf_args.clear_nvs->count > 0) {
|
|
|
|
|
|
|
|
iperf_param_clear();
|
|
|
|
|
|
|
|
printf("iPerf Configuration cleared (Reset to defaults).\n");
|
|
|
|
|
|
|
|
end_cmd();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,9 +175,8 @@ static int cmd_iperf(int argc, char **argv) {
|
|
|
|
if (iperf_args.len->count > 0) { cfg.send_len = (uint32_t)iperf_args.len->ival[0]; config_changed = true; }
|
|
|
|
if (iperf_args.len->count > 0) { cfg.send_len = (uint32_t)iperf_args.len->ival[0]; config_changed = true; }
|
|
|
|
if (iperf_args.burst->count > 0) { cfg.burst_count = (uint32_t)iperf_args.burst->ival[0]; config_changed = true; }
|
|
|
|
if (iperf_args.burst->count > 0) { cfg.burst_count = (uint32_t)iperf_args.burst->ival[0]; config_changed = true; }
|
|
|
|
if (iperf_args.pps->count > 0) {
|
|
|
|
if (iperf_args.pps->count > 0) {
|
|
|
|
int pps = iperf_args.pps->ival[0];
|
|
|
|
if (iperf_args.pps->ival[0] > 0) {
|
|
|
|
if (pps > 0) {
|
|
|
|
cfg.target_pps = (uint32_t)iperf_args.pps->ival[0];
|
|
|
|
cfg.target_pps = (uint32_t)pps;
|
|
|
|
|
|
|
|
config_changed = true;
|
|
|
|
config_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -85,13 +203,31 @@ static int cmd_iperf(int argc, char **argv) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_iperf_cmd(void) {
|
|
|
|
|
|
|
|
iperf_args.start = arg_lit0(NULL, "start", "Start");
|
|
|
|
|
|
|
|
iperf_args.stop = arg_lit0(NULL, "stop", "Stop");
|
|
|
|
|
|
|
|
iperf_args.status = arg_lit0(NULL, "status", "Status");
|
|
|
|
|
|
|
|
iperf_args.save = arg_lit0(NULL, "save", "Save");
|
|
|
|
|
|
|
|
iperf_args.reload = arg_lit0(NULL, "reload", "Reload");
|
|
|
|
|
|
|
|
iperf_args.clear_nvs = arg_lit0(NULL, "clear-nvs", "Clear NVS");
|
|
|
|
|
|
|
|
iperf_args.ip = arg_str0("c", "client", "<ip>", "IP");
|
|
|
|
|
|
|
|
iperf_args.port = arg_int0("p", "port", "<port>", "Port");
|
|
|
|
|
|
|
|
iperf_args.pps = arg_int0(NULL, "pps", "<n>", "PPS");
|
|
|
|
|
|
|
|
iperf_args.len = arg_int0(NULL, "len", "<bytes>", "Len");
|
|
|
|
|
|
|
|
iperf_args.burst = arg_int0(NULL, "burst", "<count>", "Burst");
|
|
|
|
|
|
|
|
iperf_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
|
|
|
|
iperf_args.end = arg_end(20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = { .command = "iperf", .help = "Traffic Gen", .func = &cmd_iperf, .argtable = &iperf_args };
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
// COMMAND: monitor (Switch STA/MONITOR)
|
|
|
|
// COMMAND: monitor
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
static struct {
|
|
|
|
static struct {
|
|
|
|
struct arg_lit *start;
|
|
|
|
struct arg_lit *start, *stop, *status, *save, *reload;
|
|
|
|
struct arg_lit *stop;
|
|
|
|
struct arg_lit *clear_nvs;
|
|
|
|
struct arg_lit *status;
|
|
|
|
|
|
|
|
struct arg_int *channel;
|
|
|
|
struct arg_int *channel;
|
|
|
|
struct arg_lit *help;
|
|
|
|
struct arg_lit *help;
|
|
|
|
struct arg_end *end;
|
|
|
|
struct arg_end *end;
|
|
|
|
@ -105,30 +241,40 @@ static int cmd_monitor(int argc, char **argv) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mon_args.help->count > 0) {
|
|
|
|
if (mon_args.help->count > 0) {
|
|
|
|
printf("Usage: monitor [--start] [--stop] [-c <ch>]\n");
|
|
|
|
printf("Usage: monitor [--start|--stop] [-c <ch>] [--save|--reload]\n");
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Handle Channel Set
|
|
|
|
if (mon_args.clear_nvs->count > 0) {
|
|
|
|
uint8_t ch = 0;
|
|
|
|
wifi_ctl_param_clear();
|
|
|
|
if (mon_args.channel->count > 0) {
|
|
|
|
printf("Monitor config cleared (Defaulting to Ch 6).\n");
|
|
|
|
ch = (uint8_t)mon_args.channel->ival[0];
|
|
|
|
end_cmd();
|
|
|
|
// Note: You could add a setter to wifi_controller here if you want it staged
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mon_args.reload->count > 0) {
|
|
|
|
|
|
|
|
wifi_ctl_param_reload();
|
|
|
|
|
|
|
|
printf("Config reloaded from NVS.\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mon_args.channel->count > 0) {
|
|
|
|
|
|
|
|
wifi_ctl_param_set_monitor_channel((uint8_t)mon_args.channel->ival[0]);
|
|
|
|
|
|
|
|
printf("Channel set to %d (RAM).\n", mon_args.channel->ival[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mon_args.save->count > 0) {
|
|
|
|
|
|
|
|
if (wifi_ctl_param_save()) printf("Configuration saved to NVS.\n");
|
|
|
|
|
|
|
|
else printf("No changes to save (NVS matches RAM).\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Handle Actions
|
|
|
|
|
|
|
|
if (mon_args.stop->count > 0) {
|
|
|
|
if (mon_args.stop->count > 0) {
|
|
|
|
wifi_ctl_switch_to_sta(WIFI_BW_HT20);
|
|
|
|
wifi_ctl_switch_to_sta(WIFI_BW_HT20);
|
|
|
|
printf("Switched to Station Mode.\n");
|
|
|
|
printf("Switched to Station Mode.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mon_args.start->count > 0) {
|
|
|
|
if (mon_args.start->count > 0) {
|
|
|
|
// If ch is 0, controller uses default/staged
|
|
|
|
if (wifi_ctl_switch_to_monitor(0, WIFI_BW_HT20) == ESP_OK) printf("Monitor Mode Started.\n");
|
|
|
|
if (wifi_ctl_switch_to_monitor(ch, WIFI_BW_HT20) == ESP_OK) {
|
|
|
|
else printf("Failed to start Monitor Mode.\n");
|
|
|
|
printf("Monitor Mode Started%s.\n", (ch > 0) ? " (Channel Override)" : "");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf("Failed to start Monitor Mode.\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mon_args.status->count > 0) {
|
|
|
|
if (mon_args.status->count > 0) {
|
|
|
|
@ -136,15 +282,31 @@ static int cmd_monitor(int argc, char **argv) {
|
|
|
|
printf("MONITOR STATUS:\n");
|
|
|
|
printf("MONITOR STATUS:\n");
|
|
|
|
printf(" Mode: %s\n", (mode == WIFI_CTL_MODE_MONITOR) ? "MONITOR" : "STATION");
|
|
|
|
printf(" Mode: %s\n", (mode == WIFI_CTL_MODE_MONITOR) ? "MONITOR" : "STATION");
|
|
|
|
printf(" Active: Ch %d\n", (mode == WIFI_CTL_MODE_MONITOR) ? wifi_ctl_get_monitor_channel() : 0);
|
|
|
|
printf(" Active: Ch %d\n", (mode == WIFI_CTL_MODE_MONITOR) ? wifi_ctl_get_monitor_channel() : 0);
|
|
|
|
printf(" Frames: %lu\n", (unsigned long)wifi_ctl_get_monitor_frame_count());
|
|
|
|
printf(" Staged: Ch %d\n", wifi_ctl_param_get_monitor_channel());
|
|
|
|
|
|
|
|
printf(" Frames: %" PRIu32 "\n", wifi_ctl_get_monitor_frame_count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
end_cmd();
|
|
|
|
end_cmd();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_monitor_cmd(void) {
|
|
|
|
|
|
|
|
mon_args.start = arg_lit0(NULL, "start", "Start");
|
|
|
|
|
|
|
|
mon_args.stop = arg_lit0(NULL, "stop", "Stop");
|
|
|
|
|
|
|
|
mon_args.status = arg_lit0(NULL, "status", "Status");
|
|
|
|
|
|
|
|
mon_args.save = arg_lit0(NULL, "save", "Save");
|
|
|
|
|
|
|
|
mon_args.reload = arg_lit0(NULL, "reload", "Reload");
|
|
|
|
|
|
|
|
mon_args.clear_nvs = arg_lit0(NULL, "clear-nvs", "Clear NVS");
|
|
|
|
|
|
|
|
mon_args.channel = arg_int0("c", "channel", "<n>", "Chan");
|
|
|
|
|
|
|
|
mon_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
|
|
|
|
mon_args.end = arg_end(20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = { .command = "monitor", .help = "Monitor Mode", .func = &cmd_monitor, .argtable = &mon_args };
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
// COMMAND: scan (List Networks)
|
|
|
|
// COMMAND: scan
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
static struct {
|
|
|
|
static struct {
|
|
|
|
struct arg_lit *help;
|
|
|
|
struct arg_lit *help;
|
|
|
|
@ -165,17 +327,11 @@ static int cmd_scan(int argc, char **argv) {
|
|
|
|
|
|
|
|
|
|
|
|
printf("Starting WiFi Scan...\n");
|
|
|
|
printf("Starting WiFi Scan...\n");
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure we are in a mode that supports scanning (STA or NULL)
|
|
|
|
// Force STA mode to allow scanning
|
|
|
|
wifi_ctl_switch_to_sta(WIFI_BW_HT20);
|
|
|
|
wifi_ctl_switch_to_sta(WIFI_BW_HT20);
|
|
|
|
|
|
|
|
|
|
|
|
wifi_scan_config_t scan_config = {
|
|
|
|
wifi_scan_config_t scan_config = { .show_hidden = true };
|
|
|
|
.ssid = 0,
|
|
|
|
esp_err_t err = esp_wifi_scan_start(&scan_config, true);
|
|
|
|
.bssid = 0,
|
|
|
|
|
|
|
|
.channel = 0,
|
|
|
|
|
|
|
|
.show_hidden = true
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t err = esp_wifi_scan_start(&scan_config, true); // true = blocking
|
|
|
|
|
|
|
|
if (err != ESP_OK) {
|
|
|
|
if (err != ESP_OK) {
|
|
|
|
printf("Scan failed: %s\n", esp_err_to_name(err));
|
|
|
|
printf("Scan failed: %s\n", esp_err_to_name(err));
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
@ -192,11 +348,7 @@ static int cmd_scan(int argc, char **argv) {
|
|
|
|
printf("%-32s | %-4s | %-4s | %-3s\n", "SSID", "RSSI", "CH", "Auth");
|
|
|
|
printf("%-32s | %-4s | %-4s | %-3s\n", "SSID", "RSSI", "CH", "Auth");
|
|
|
|
printf("----------------------------------------------------------\n");
|
|
|
|
printf("----------------------------------------------------------\n");
|
|
|
|
for (int i = 0; i < ap_count; i++) {
|
|
|
|
for (int i = 0; i < ap_count; i++) {
|
|
|
|
printf("%-32s | %-4d | %-4d | %d\n",
|
|
|
|
printf("%-32s | %-4d | %-4d | %d\n", (char *)ap_list[i].ssid, ap_list[i].rssi, ap_list[i].primary, ap_list[i].authmode);
|
|
|
|
(char *)ap_list[i].ssid,
|
|
|
|
|
|
|
|
ap_list[i].rssi,
|
|
|
|
|
|
|
|
ap_list[i].primary,
|
|
|
|
|
|
|
|
ap_list[i].authmode);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(ap_list);
|
|
|
|
free(ap_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -204,6 +356,13 @@ static int cmd_scan(int argc, char **argv) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_scan_cmd(void) {
|
|
|
|
|
|
|
|
scan_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
|
|
|
|
scan_args.end = arg_end(1);
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = { .command = "scan", .help = "WiFi Scan", .func = &cmd_scan, .argtable = &scan_args };
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
// COMMAND: wifi_config
|
|
|
|
// COMMAND: wifi_config
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
@ -212,6 +371,7 @@ static struct {
|
|
|
|
struct arg_str *pass;
|
|
|
|
struct arg_str *pass;
|
|
|
|
struct arg_str *ip;
|
|
|
|
struct arg_str *ip;
|
|
|
|
struct arg_lit *dhcp;
|
|
|
|
struct arg_lit *dhcp;
|
|
|
|
|
|
|
|
struct arg_lit *clear_nvs;
|
|
|
|
struct arg_lit *help;
|
|
|
|
struct arg_lit *help;
|
|
|
|
struct arg_end *end;
|
|
|
|
struct arg_end *end;
|
|
|
|
} wifi_args;
|
|
|
|
} wifi_args;
|
|
|
|
@ -224,7 +384,13 @@ static int cmd_wifi_config(int argc, char **argv) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (wifi_args.help->count > 0) {
|
|
|
|
if (wifi_args.help->count > 0) {
|
|
|
|
printf("Usage: wifi_config -s <ssid> -p <pass> [-i <ip>] [-d]\n");
|
|
|
|
printf("Usage: wifi_config -s <ssid> [-p <pass>] [--clear-nvs]\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wifi_args.clear_nvs->count > 0) {
|
|
|
|
|
|
|
|
wifi_cfg_clear_credentials();
|
|
|
|
|
|
|
|
printf("WiFi Credentials CLEARED from NVS.\n");
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -238,9 +404,8 @@ static int cmd_wifi_config(int argc, char **argv) {
|
|
|
|
const char* ip = (wifi_args.ip->count > 0) ? wifi_args.ip->sval[0] : NULL;
|
|
|
|
const char* ip = (wifi_args.ip->count > 0) ? wifi_args.ip->sval[0] : NULL;
|
|
|
|
bool dhcp = (wifi_args.dhcp->count > 0);
|
|
|
|
bool dhcp = (wifi_args.dhcp->count > 0);
|
|
|
|
|
|
|
|
|
|
|
|
printf("Saving WiFi Config to NVS: SSID='%s' DHCP=%d\n", ssid, dhcp);
|
|
|
|
printf("Saving WiFi Config: SSID='%s' DHCP=%d\n", ssid, dhcp);
|
|
|
|
|
|
|
|
|
|
|
|
// This immediately writes to NVS via wifi_cfg.c
|
|
|
|
|
|
|
|
wifi_cfg_set_credentials(ssid, pass);
|
|
|
|
wifi_cfg_set_credentials(ssid, pass);
|
|
|
|
|
|
|
|
|
|
|
|
if (ip) {
|
|
|
|
if (ip) {
|
|
|
|
@ -248,7 +413,7 @@ static int cmd_wifi_config(int argc, char **argv) {
|
|
|
|
char gw[32];
|
|
|
|
char gw[32];
|
|
|
|
strlcpy(gw, ip, sizeof(gw));
|
|
|
|
strlcpy(gw, ip, sizeof(gw));
|
|
|
|
char *last_dot = strrchr(gw, '.');
|
|
|
|
char *last_dot = strrchr(gw, '.');
|
|
|
|
if (last_dot) strcpy(last_dot, ".1"); // Guess Gateway
|
|
|
|
if (last_dot) strcpy(last_dot, ".1");
|
|
|
|
|
|
|
|
|
|
|
|
wifi_cfg_set_static_ip(ip, mask, gw);
|
|
|
|
wifi_cfg_set_static_ip(ip, mask, gw);
|
|
|
|
wifi_cfg_set_dhcp(false);
|
|
|
|
wifi_cfg_set_dhcp(false);
|
|
|
|
@ -261,57 +426,16 @@ static int cmd_wifi_config(int argc, char **argv) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// REGISTRATION
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_iperf_cmd(void) {
|
|
|
|
|
|
|
|
iperf_args.start = arg_lit0(NULL, "start", "Start");
|
|
|
|
|
|
|
|
iperf_args.stop = arg_lit0(NULL, "stop", "Stop");
|
|
|
|
|
|
|
|
iperf_args.status = arg_lit0(NULL, "status", "Status");
|
|
|
|
|
|
|
|
iperf_args.save = arg_lit0(NULL, "save", "Save");
|
|
|
|
|
|
|
|
iperf_args.reload = arg_lit0(NULL, "reload", "Reload");
|
|
|
|
|
|
|
|
iperf_args.ip = arg_str0("c", "client", "<ip>", "IP");
|
|
|
|
|
|
|
|
iperf_args.port = arg_int0("p", "port", "<port>", "Port");
|
|
|
|
|
|
|
|
iperf_args.pps = arg_int0(NULL, "pps", "<n>", "PPS");
|
|
|
|
|
|
|
|
iperf_args.len = arg_int0(NULL, "len", "<bytes>", "Len");
|
|
|
|
|
|
|
|
iperf_args.burst = arg_int0(NULL, "burst", "<count>", "Burst");
|
|
|
|
|
|
|
|
iperf_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
|
|
|
|
iperf_args.end = arg_end(20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = { .command = "iperf", .help = "Traffic Gen", .func = &cmd_iperf, .argtable = &iperf_args };
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_monitor_cmd(void) {
|
|
|
|
|
|
|
|
mon_args.start = arg_lit0(NULL, "start", "Start Monitor");
|
|
|
|
|
|
|
|
mon_args.stop = arg_lit0(NULL, "stop", "Stop (STA)");
|
|
|
|
|
|
|
|
mon_args.status = arg_lit0(NULL, "status", "Status");
|
|
|
|
|
|
|
|
mon_args.channel = arg_int0("c", "channel", "<n>", "Channel");
|
|
|
|
|
|
|
|
mon_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
|
|
|
|
mon_args.end = arg_end(20);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = { .command = "monitor", .help = "Switch Mode (STA/Monitor)", .func = &cmd_monitor, .argtable = &mon_args };
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_scan_cmd(void) {
|
|
|
|
|
|
|
|
scan_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
|
|
|
|
scan_args.end = arg_end(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = { .command = "scan", .help = "Scan WiFi", .func = &cmd_scan, .argtable = &scan_args };
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void register_wifi_cmd(void) {
|
|
|
|
static void register_wifi_cmd(void) {
|
|
|
|
wifi_args.ssid = arg_str0("s", "ssid", "<ssid>", "SSID");
|
|
|
|
wifi_args.ssid = arg_str0("s", "ssid", "<ssid>", "SSID");
|
|
|
|
wifi_args.pass = arg_str0("p", "password", "<pass>", "Pass");
|
|
|
|
wifi_args.pass = arg_str0("p", "password", "<pass>", "Pass");
|
|
|
|
wifi_args.ip = arg_str0("i", "ip", "<ip>", "Static IP");
|
|
|
|
wifi_args.ip = arg_str0("i", "ip", "<ip>", "Static IP");
|
|
|
|
wifi_args.dhcp = arg_lit0("d", "dhcp", "DHCP");
|
|
|
|
wifi_args.dhcp = arg_lit0("d", "dhcp", "Enable DHCP");
|
|
|
|
|
|
|
|
wifi_args.clear_nvs = arg_lit0(NULL, "clear-nvs", "Clear NVS");
|
|
|
|
wifi_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
wifi_args.help = arg_lit0("h", "help", "Help");
|
|
|
|
wifi_args.end = arg_end(20);
|
|
|
|
wifi_args.end = arg_end(20);
|
|
|
|
|
|
|
|
|
|
|
|
const esp_console_cmd_t cmd = { .command = "wifi_config", .help = "Setup WiFi Creds", .func = &cmd_wifi_config, .argtable = &wifi_args };
|
|
|
|
const esp_console_cmd_t cmd = { .command = "wifi_config", .help = "Configure WiFi", .func = &cmd_wifi_config, .argtable = &wifi_args };
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -320,4 +444,5 @@ void app_console_register_commands(void) {
|
|
|
|
register_monitor_cmd();
|
|
|
|
register_monitor_cmd();
|
|
|
|
register_scan_cmd();
|
|
|
|
register_scan_cmd();
|
|
|
|
register_wifi_cmd();
|
|
|
|
register_wifi_cmd();
|
|
|
|
|
|
|
|
register_nvs_cmd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|