cmd_wifi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /* Iperf Example - wifi commands
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <inttypes.h>
  10. #include "esp_log.h"
  11. #include "esp_console.h"
  12. #include "argtable3/argtable3.h"
  13. #include "cmd_decl.h"
  14. #include "freertos/FreeRTOS.h"
  15. #include "freertos/event_groups.h"
  16. #include "esp_wifi.h"
  17. #include "esp_netif.h"
  18. #include "esp_event.h"
  19. #include "esp_mac.h"
  20. #include "iperf.h"
  21. #include "esp_coexist.h"
  22. #include "wifi_cmd.h"
  23. #include "esp_wifi_he.h"
  24. typedef struct {
  25. struct arg_str *ip;
  26. struct arg_lit *server;
  27. struct arg_lit *udp;
  28. struct arg_lit *version;
  29. struct arg_int *port;
  30. struct arg_int *length;
  31. struct arg_int *interval;
  32. struct arg_int *time;
  33. struct arg_int *bw_limit;
  34. struct arg_lit *abort;
  35. struct arg_end *end;
  36. } wifi_iperf_t;
  37. typedef struct {
  38. struct arg_str *ssid;
  39. struct arg_str *password;
  40. struct arg_end *end;
  41. } wifi_args_t;
  42. typedef struct {
  43. struct arg_str *ssid;
  44. struct arg_end *end;
  45. } wifi_scan_arg_t;
  46. static wifi_iperf_t iperf_args;
  47. static wifi_args_t sta_args;
  48. static wifi_scan_arg_t scan_args;
  49. static wifi_args_t ap_args;
  50. static bool reconnect = true;
  51. static const char *TAG = "cmd_wifi";
  52. esp_netif_t *netif_ap = NULL;
  53. esp_netif_t *netif_sta = NULL;
  54. EventGroupHandle_t wifi_event_group;
  55. const int CONNECTED_BIT = BIT0;
  56. const int DISCONNECTED_BIT = BIT1;
  57. static void scan_done_handler(void *arg, esp_event_base_t event_base,
  58. int32_t event_id, void *event_data)
  59. {
  60. uint16_t sta_number = 0;
  61. uint8_t i;
  62. wifi_ap_record_t *ap_list_buffer;
  63. esp_wifi_scan_get_ap_num(&sta_number);
  64. if (!sta_number) {
  65. ESP_LOGE(TAG, "No AP found");
  66. return;
  67. }
  68. ap_list_buffer = malloc(sta_number * sizeof(wifi_ap_record_t));
  69. if (ap_list_buffer == NULL) {
  70. ESP_LOGE(TAG, "Failed to malloc buffer to print scan results");
  71. return;
  72. }
  73. if (esp_wifi_scan_get_ap_records(&sta_number, (wifi_ap_record_t *)ap_list_buffer) == ESP_OK) {
  74. for (i = 0; i < sta_number; i++) {
  75. #if CONFIG_SOC_WIFI_HE_SUPPORT
  76. char ssid_rssi[46] = { 0, };
  77. sprintf(ssid_rssi, "[%s][rssi=%d]", ap_list_buffer[i].ssid, ap_list_buffer[i].rssi);
  78. if (ap_list_buffer[i].phy_11ax) {
  79. ESP_LOGW(TAG,
  80. "[%2d]%45s authmode:0x%x, channel:%2d[%d], phymode:%4s, "MACSTR", bssid-index:%d, bss_color:%d, disabled:%d",
  81. i, ssid_rssi, ap_list_buffer[i].authmode,
  82. ap_list_buffer[i].primary, ap_list_buffer[i].second,
  83. ap_list_buffer[i].phy_11ax ? "11ax" : (ap_list_buffer[i].phy_11n ? "11n" :
  84. (ap_list_buffer[i].phy_11g ? "11g" : (ap_list_buffer[i].phy_11b ? "11b" : ""))),
  85. MAC2STR(ap_list_buffer[i].bssid), ap_list_buffer[i].he_ap.bssid_index,
  86. ap_list_buffer[i].he_ap.bss_color, ap_list_buffer[i].he_ap.bss_color_disabled);
  87. } else {
  88. ESP_LOGI(TAG,
  89. "[%2d]%45s authmode:0x%x, channel:%2d[%d], phymode:%4s, "MACSTR"",
  90. i, ssid_rssi, ap_list_buffer[i].authmode,
  91. ap_list_buffer[i].primary, ap_list_buffer[i].second,
  92. ap_list_buffer[i].phy_11ax ? "11ax" : (ap_list_buffer[i].phy_11n ? "11n" :
  93. (ap_list_buffer[i].phy_11g ? "11g" : (ap_list_buffer[i].phy_11b ? "11b" : ""))),
  94. MAC2STR(ap_list_buffer[i].bssid));
  95. }
  96. #else
  97. ESP_LOGI(TAG, "[%s][rssi=%d]", ap_list_buffer[i].ssid, ap_list_buffer[i].rssi);
  98. #endif
  99. }
  100. }
  101. free(ap_list_buffer);
  102. ESP_LOGI(TAG, "sta scan done");
  103. }
  104. static void got_ip_handler(void *arg, esp_event_base_t event_base,
  105. int32_t event_id, void *event_data)
  106. {
  107. xEventGroupClearBits(wifi_event_group, DISCONNECTED_BIT);
  108. xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
  109. }
  110. static void disconnect_handler(void *arg, esp_event_base_t event_base,
  111. int32_t event_id, void *event_data)
  112. {
  113. if (reconnect) {
  114. ESP_LOGI(TAG, "sta disconnect, reconnect...");
  115. esp_wifi_connect();
  116. } else {
  117. ESP_LOGI(TAG, "sta disconnect");
  118. }
  119. xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
  120. xEventGroupSetBits(wifi_event_group, DISCONNECTED_BIT);
  121. }
  122. void initialise_wifi(void)
  123. {
  124. esp_log_level_set("wifi", ESP_LOG_WARN);
  125. static bool initialized = false;
  126. if (initialized) {
  127. return;
  128. }
  129. ESP_ERROR_CHECK(esp_netif_init());
  130. wifi_event_group = xEventGroupCreate();
  131. ESP_ERROR_CHECK( esp_event_loop_create_default() );
  132. netif_ap = esp_netif_create_default_wifi_ap();
  133. assert(netif_ap);
  134. netif_sta = esp_netif_create_default_wifi_sta();
  135. assert(netif_sta);
  136. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  137. ESP_ERROR_CHECK(esp_wifi_init(&cfg));
  138. ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
  139. WIFI_EVENT_SCAN_DONE,
  140. &scan_done_handler,
  141. NULL,
  142. NULL));
  143. ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
  144. WIFI_EVENT_STA_DISCONNECTED,
  145. &disconnect_handler,
  146. NULL,
  147. NULL));
  148. ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
  149. IP_EVENT_STA_GOT_IP,
  150. &got_ip_handler,
  151. NULL,
  152. NULL));
  153. ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM) );
  154. ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL) );
  155. ESP_ERROR_CHECK(esp_wifi_start() );
  156. #if CONFIG_EXTERNAL_COEX_ENABLE
  157. esp_external_coex_gpio_set_t gpio_pin;
  158. gpio_pin.request = 1;
  159. gpio_pin.priority = 2;
  160. gpio_pin.grant = 3;
  161. #if SOC_EXTERNAL_COEX_LEADER_TX_LINE
  162. gpio_pin.tx_line = 4;
  163. #endif
  164. esp_external_coex_set_work_mode(EXTERNAL_COEX_LEADER_ROLE);
  165. #if SOC_EXTERNAL_COEX_LEADER_TX_LINE
  166. ESP_ERROR_CHECK(esp_enable_extern_coex_gpio_pin(EXTERN_COEX_WIRE_4, gpio_pin));
  167. #else
  168. ESP_ERROR_CHECK(esp_enable_extern_coex_gpio_pin(EXTERN_COEX_WIRE_3, gpio_pin));
  169. #endif /* SOC_EXTERNAL_COEX_LEADER_TX_LINE */
  170. #endif /* CONFIG_EXTERNAL_COEX_ENABLE */
  171. #if CONFIG_ESP_WIFI_ENABLE_WIFI_RX_STATS
  172. #if CONFIG_ESP_WIFI_ENABLE_WIFI_RX_MU_STATS
  173. esp_wifi_enable_rx_statistics(true, true);
  174. #else
  175. esp_wifi_enable_rx_statistics(true, false);
  176. #endif
  177. #endif
  178. #if CONFIG_ESP_WIFI_ENABLE_WIFI_TX_STATS
  179. esp_wifi_enable_tx_statistics(ESP_WIFI_ACI_BE, true);
  180. #endif
  181. initialized = true;
  182. }
  183. static bool wifi_cmd_sta_join(const char *ssid, const char *pass, bool enable_he_mcs9)
  184. {
  185. int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
  186. wifi_config_t wifi_config = { 0 };
  187. strlcpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
  188. if (pass) {
  189. strlcpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
  190. }
  191. if (enable_he_mcs9 == true) {
  192. wifi_config.sta.he_mcs9_enabled = 1;
  193. }
  194. if (bits & CONNECTED_BIT) {
  195. reconnect = false;
  196. xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
  197. ESP_ERROR_CHECK( esp_wifi_disconnect() );
  198. xEventGroupWaitBits(wifi_event_group, DISCONNECTED_BIT, 0, 1, portTICK_PERIOD_MS);
  199. }
  200. reconnect = true;
  201. ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
  202. ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
  203. esp_wifi_connect();
  204. xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 5000 / portTICK_PERIOD_MS);
  205. return true;
  206. }
  207. static int wifi_cmd_sta(int argc, char **argv)
  208. {
  209. int nerrors = arg_parse(argc, argv, (void **) &sta_args);
  210. if (nerrors != 0) {
  211. arg_print_errors(stderr, sta_args.end, argv[0]);
  212. return 1;
  213. }
  214. ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]);
  215. ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
  216. wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], false);
  217. return 0;
  218. }
  219. static int wifi_cmd_sta40(int argc, char **argv)
  220. {
  221. int nerrors = arg_parse(argc, argv, (void **) &sta_args);
  222. if (nerrors != 0) {
  223. arg_print_errors(stderr, sta_args.end, argv[0]);
  224. return 1;
  225. }
  226. ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
  227. ESP_ERROR_CHECK(esp_wifi_set_protocol(0, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N));
  228. ESP_ERROR_CHECK(esp_wifi_set_bandwidth(0, WIFI_BW_HT40));
  229. ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
  230. ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]);
  231. wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], false);
  232. return 0;
  233. }
  234. static int wifi_cmd_sta_mcs89(int argc, char **argv)
  235. {
  236. #if CONFIG_SOC_WIFI_HE_SUPPORT
  237. int nerrors = arg_parse(argc, argv, (void **) &sta_args);
  238. if (nerrors != 0) {
  239. arg_print_errors(stderr, sta_args.end, argv[0]);
  240. return 1;
  241. }
  242. ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
  243. ESP_ERROR_CHECK(esp_wifi_set_protocol(0, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX));
  244. ESP_ERROR_CHECK(esp_wifi_set_bandwidth(0, WIFI_BW_HT20));
  245. ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
  246. ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]);
  247. wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], true);
  248. #else
  249. ESP_LOGW(TAG, "HE-MCS[0, 9] is not supported");
  250. #endif
  251. return 0;
  252. }
  253. static bool wifi_cmd_sta_scan(const char *ssid)
  254. {
  255. wifi_scan_config_t scan_config = { 0 };
  256. scan_config.ssid = (uint8_t *) ssid;
  257. ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
  258. esp_wifi_scan_start(&scan_config, false);
  259. return true;
  260. }
  261. static int wifi_cmd_scan(int argc, char **argv)
  262. {
  263. int nerrors = arg_parse(argc, argv, (void **) &scan_args);
  264. if (nerrors != 0) {
  265. arg_print_errors(stderr, scan_args.end, argv[0]);
  266. return 1;
  267. }
  268. ESP_LOGI(TAG, "sta start to scan");
  269. if ( scan_args.ssid->count == 1 ) {
  270. wifi_cmd_sta_scan(scan_args.ssid->sval[0]);
  271. } else {
  272. wifi_cmd_sta_scan(NULL);
  273. }
  274. return 0;
  275. }
  276. static bool wifi_cmd_ap_set(const char *ssid, const char *pass)
  277. {
  278. wifi_config_t wifi_config = {
  279. .ap = {
  280. .ssid = "",
  281. .ssid_len = 0,
  282. .max_connection = 4,
  283. .password = "",
  284. .authmode = WIFI_AUTH_WPA_WPA2_PSK
  285. },
  286. };
  287. reconnect = false;
  288. strlcpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
  289. if (pass) {
  290. if (strlen(pass) != 0 && strlen(pass) < 8) {
  291. reconnect = true;
  292. ESP_LOGE(TAG, "password less than 8");
  293. return false;
  294. }
  295. strlcpy((char *) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
  296. }
  297. if (strlen(pass) == 0) {
  298. wifi_config.ap.authmode = WIFI_AUTH_OPEN;
  299. }
  300. ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
  301. ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
  302. return true;
  303. }
  304. static int wifi_cmd_ap(int argc, char **argv)
  305. {
  306. int nerrors = arg_parse(argc, argv, (void **) &ap_args);
  307. if (nerrors != 0) {
  308. arg_print_errors(stderr, ap_args.end, argv[0]);
  309. return 1;
  310. }
  311. wifi_cmd_ap_set(ap_args.ssid->sval[0], ap_args.password->sval[0]);
  312. ESP_LOGI(TAG, "AP mode, %s %s", ap_args.ssid->sval[0], ap_args.password->sval[0]);
  313. return 0;
  314. }
  315. static int wifi_cmd_query(int argc, char **argv)
  316. {
  317. wifi_config_t cfg;
  318. wifi_mode_t mode;
  319. esp_wifi_get_mode(&mode);
  320. if (WIFI_MODE_AP == mode) {
  321. esp_wifi_get_config(WIFI_IF_AP, &cfg);
  322. ESP_LOGI(TAG, "AP mode, %s %s", cfg.ap.ssid, cfg.ap.password);
  323. } else if (WIFI_MODE_STA == mode) {
  324. int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
  325. if (bits & CONNECTED_BIT) {
  326. esp_wifi_get_config(WIFI_IF_STA, &cfg);
  327. ESP_LOGI(TAG, "sta mode, connected %s", cfg.ap.ssid);
  328. } else {
  329. ESP_LOGI(TAG, "sta mode, disconnected");
  330. }
  331. } else {
  332. ESP_LOGI(TAG, "NULL mode");
  333. return 0;
  334. }
  335. return 0;
  336. }
  337. static uint32_t wifi_get_local_ip(void)
  338. {
  339. int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
  340. esp_netif_t *netif = netif_ap;
  341. esp_netif_ip_info_t ip_info;
  342. wifi_mode_t mode;
  343. esp_wifi_get_mode(&mode);
  344. if (WIFI_MODE_STA == mode) {
  345. bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
  346. if (bits & CONNECTED_BIT) {
  347. netif = netif_sta;
  348. } else {
  349. ESP_LOGE(TAG, "sta has no IP");
  350. return 0;
  351. }
  352. }
  353. esp_netif_get_ip_info(netif, &ip_info);
  354. return ip_info.ip.addr;
  355. }
  356. static int wifi_cmd_iperf(int argc, char **argv)
  357. {
  358. int nerrors = arg_parse(argc, argv, (void **) &iperf_args);
  359. iperf_cfg_t cfg;
  360. if (nerrors != 0) {
  361. arg_print_errors(stderr, iperf_args.end, argv[0]);
  362. return 0;
  363. }
  364. memset(&cfg, 0, sizeof(cfg));
  365. // now wifi iperf only support IPV4 address
  366. cfg.type = IPERF_IP_TYPE_IPV4;
  367. if ( iperf_args.abort->count != 0) {
  368. iperf_stop();
  369. return 0;
  370. }
  371. if ( ((iperf_args.ip->count == 0) && (iperf_args.server->count == 0)) ||
  372. ((iperf_args.ip->count != 0) && (iperf_args.server->count != 0)) ) {
  373. ESP_LOGE(TAG, "should specific client/server mode");
  374. return 0;
  375. }
  376. if (iperf_args.ip->count == 0) {
  377. cfg.flag |= IPERF_FLAG_SERVER;
  378. } else {
  379. cfg.destination_ip4 = esp_ip4addr_aton(iperf_args.ip->sval[0]);
  380. cfg.flag |= IPERF_FLAG_CLIENT;
  381. }
  382. cfg.source_ip4 = wifi_get_local_ip();
  383. if (cfg.source_ip4 == 0) {
  384. return 0;
  385. }
  386. if (iperf_args.udp->count == 0) {
  387. cfg.flag |= IPERF_FLAG_TCP;
  388. } else {
  389. cfg.flag |= IPERF_FLAG_UDP;
  390. }
  391. if (iperf_args.length->count == 0) {
  392. cfg.len_send_buf = 0;
  393. } else {
  394. cfg.len_send_buf = iperf_args.length->ival[0];
  395. }
  396. if (iperf_args.port->count == 0) {
  397. cfg.sport = IPERF_DEFAULT_PORT;
  398. cfg.dport = IPERF_DEFAULT_PORT;
  399. } else {
  400. if (cfg.flag & IPERF_FLAG_SERVER) {
  401. cfg.sport = iperf_args.port->ival[0];
  402. cfg.dport = IPERF_DEFAULT_PORT;
  403. } else {
  404. cfg.sport = IPERF_DEFAULT_PORT;
  405. cfg.dport = iperf_args.port->ival[0];
  406. }
  407. }
  408. if (iperf_args.interval->count == 0) {
  409. cfg.interval = IPERF_DEFAULT_INTERVAL;
  410. } else {
  411. cfg.interval = iperf_args.interval->ival[0];
  412. if (cfg.interval <= 0) {
  413. cfg.interval = IPERF_DEFAULT_INTERVAL;
  414. }
  415. }
  416. if (iperf_args.time->count == 0) {
  417. cfg.time = IPERF_DEFAULT_TIME;
  418. } else {
  419. cfg.time = iperf_args.time->ival[0];
  420. if (cfg.time <= cfg.interval) {
  421. cfg.time = cfg.interval;
  422. }
  423. }
  424. /* iperf -b */
  425. if (iperf_args.bw_limit->count == 0) {
  426. cfg.bw_lim = IPERF_DEFAULT_NO_BW_LIMIT;
  427. } else {
  428. cfg.bw_lim = iperf_args.bw_limit->ival[0];
  429. if (cfg.bw_lim <= 0) {
  430. cfg.bw_lim = IPERF_DEFAULT_NO_BW_LIMIT;
  431. }
  432. }
  433. ESP_LOGI(TAG, "mode=%s-%s sip=%" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 ":%d,\
  434. dip=%" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 ":%d,\
  435. interval=%" PRId32 ", time=%" PRId32 "",
  436. cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp",
  437. cfg.flag & IPERF_FLAG_SERVER ? "server" : "client",
  438. cfg.source_ip4 & 0xFF, (cfg.source_ip4 >> 8) & 0xFF, (cfg.source_ip4 >> 16) & 0xFF,
  439. (cfg.source_ip4 >> 24) & 0xFF, cfg.sport,
  440. cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF,
  441. (cfg.destination_ip4 >> 16) & 0xFF, (cfg.destination_ip4 >> 24) & 0xFF, cfg.dport,
  442. cfg.interval, cfg.time);
  443. iperf_start(&cfg);
  444. return 0;
  445. }
  446. void register_wifi(void)
  447. {
  448. sta_args.ssid = arg_str1(NULL, NULL, "<ssid>", "SSID of AP");
  449. sta_args.password = arg_str0(NULL, NULL, "<pass>", "password of AP");
  450. sta_args.end = arg_end(2);
  451. const esp_console_cmd_t sta_cmd = {
  452. .command = "sta",
  453. .help = "WiFi is station mode, join specified soft-AP",
  454. .hint = NULL,
  455. .func = &wifi_cmd_sta,
  456. .argtable = &sta_args
  457. };
  458. ESP_ERROR_CHECK( esp_console_cmd_register(&sta_cmd) );
  459. const esp_console_cmd_t sta40_cmd = {
  460. .command = "sta40",
  461. .help = "WiFi is station mode, set protocol to bgn and cbw to 40MHz, join a specified AP",
  462. .hint = NULL,
  463. .func = &wifi_cmd_sta40,
  464. .argtable = &sta_args
  465. };
  466. ESP_ERROR_CHECK( esp_console_cmd_register(&sta40_cmd) );
  467. const esp_console_cmd_t stamcs89_cmd = {
  468. .command = "stamcs89",
  469. .help = "WiFi is station mode, set protocol to ax and mcs set to HE-MCS[0,9], join a specified AP",
  470. .hint = NULL,
  471. .func = &wifi_cmd_sta_mcs89,
  472. .argtable = &sta_args
  473. };
  474. ESP_ERROR_CHECK( esp_console_cmd_register(&stamcs89_cmd) );
  475. scan_args.ssid = arg_str0(NULL, NULL, "<ssid>", "SSID of AP want to be scanned");
  476. scan_args.end = arg_end(1);
  477. const esp_console_cmd_t scan_cmd = {
  478. .command = "scan",
  479. .help = "WiFi is station mode, start scan ap",
  480. .hint = NULL,
  481. .func = &wifi_cmd_scan,
  482. .argtable = &scan_args
  483. };
  484. ap_args.ssid = arg_str1(NULL, NULL, "<ssid>", "SSID of AP");
  485. ap_args.password = arg_str0(NULL, NULL, "<pass>", "password of AP");
  486. ap_args.end = arg_end(2);
  487. ESP_ERROR_CHECK( esp_console_cmd_register(&scan_cmd) );
  488. const esp_console_cmd_t ap_cmd = {
  489. .command = "ap",
  490. .help = "AP mode, configure ssid and password",
  491. .hint = NULL,
  492. .func = &wifi_cmd_ap,
  493. .argtable = &ap_args
  494. };
  495. ESP_ERROR_CHECK( esp_console_cmd_register(&ap_cmd) );
  496. const esp_console_cmd_t query_cmd = {
  497. .command = "query",
  498. .help = "query WiFi info",
  499. .hint = NULL,
  500. .func = &wifi_cmd_query,
  501. };
  502. ESP_ERROR_CHECK( esp_console_cmd_register(&query_cmd) );
  503. iperf_args.ip = arg_str0("c", "client", "<ip>", "run in client mode, connecting to <host>");
  504. iperf_args.server = arg_lit0("s", "server", "run in server mode");
  505. iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP");
  506. iperf_args.version = arg_lit0("V", "ipv6_domain", "use IPV6 address rather than IPV4");
  507. iperf_args.port = arg_int0("p", "port", "<port>", "server port to listen on/connect to");
  508. iperf_args.length = arg_int0("l", "len", "<length>", "Set read/write buffer size");
  509. iperf_args.interval = arg_int0("i", "interval", "<interval>", "seconds between periodic bandwidth reports");
  510. iperf_args.time = arg_int0("t", "time", "<time>", "time in seconds to transmit for (default 10 secs)");
  511. iperf_args.bw_limit = arg_int0("b", "bandwidth", "<bandwidth>", "bandwidth to send at in Mbits/sec");
  512. iperf_args.abort = arg_lit0("a", "abort", "abort running iperf");
  513. iperf_args.end = arg_end(1);
  514. const esp_console_cmd_t iperf_cmd = {
  515. .command = "iperf",
  516. .help = "iperf command",
  517. .hint = NULL,
  518. .func = &wifi_cmd_iperf,
  519. .argtable = &iperf_args
  520. };
  521. ESP_ERROR_CHECK( esp_console_cmd_register(&iperf_cmd) );
  522. register_wifi_cmd();
  523. register_wifi_stats();
  524. }