wifi_cmd.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "esp_log.h"
  9. #include "freertos/FreeRTOS.h"
  10. #include "freertos/event_groups.h"
  11. #include "ping/ping_sock.h"
  12. #include "lwip/inet.h"
  13. #include "lwip/netdb.h"
  14. #include "esp_mac.h"
  15. #include "wifi_cmd.h"
  16. #if CONFIG_SOC_WIFI_HE_SUPPORT
  17. #include "esp_console.h"
  18. #include "argtable3/argtable3.h"
  19. #include "esp_netif.h"
  20. #include "esp_event.h"
  21. #include "esp_wifi.h"
  22. #include "esp_wifi_types.h"
  23. #include "esp_wifi_he.h"
  24. #include "esp_private/esp_wifi_he_private.h"
  25. /*******************************************************
  26. * Macros
  27. *******************************************************/
  28. /*
  29. * enable/disable rx/tx statistics after wifi started:
  30. * (1) esp_wifi_enable_rx_statistics(true, true);
  31. * (2) esp_wifi_enable_tx_statistics(ESP_WIFI_ACI_BE, true);
  32. */
  33. /*******************************************************
  34. * Constants
  35. *******************************************************/
  36. static const char *TAG = "cmd";
  37. /*******************************************************
  38. * Structures
  39. *******************************************************/
  40. typedef struct {
  41. struct arg_dbl *read;
  42. struct arg_dbl *write;
  43. struct arg_dbl *value;
  44. struct arg_end *end;
  45. } reg_rw_args_t;
  46. typedef struct {
  47. struct arg_dbl *disable;
  48. struct arg_end *end;
  49. } wifi_stbc_args_t;
  50. typedef struct {
  51. struct arg_dbl *disable;
  52. struct arg_end *end;
  53. } wifi_bmfmee_args_t;
  54. typedef struct {
  55. struct arg_dbl *ul_mu_disable;
  56. struct arg_dbl *ul_mu_data_disable;
  57. struct arg_dbl *ersu_disable;
  58. struct arg_dbl *report;
  59. struct arg_dbl *resounding;
  60. struct arg_end *end;
  61. } wifi_omctrl_args_t;
  62. typedef struct {
  63. struct arg_dbl *tf_padding;
  64. struct arg_end *end;
  65. } wifi_tf_padding_args_t;
  66. typedef struct {
  67. struct arg_int *enable;
  68. struct arg_int *txq;
  69. struct arg_end *end;
  70. } wifi_edca_args_t;
  71. typedef struct {
  72. struct arg_int *reset_timer;
  73. struct arg_int *read_timer;
  74. struct arg_end *end;
  75. } wifi_muedca_args_t;
  76. typedef struct {
  77. struct arg_dbl *enable;
  78. struct arg_end *end;
  79. } wifi_cca_ignore_args_t;
  80. typedef struct {
  81. struct arg_dbl *timeout;
  82. struct arg_dbl *interval;
  83. struct arg_int *data_size;
  84. struct arg_int *count;
  85. struct arg_int *tos;
  86. struct arg_str *host;
  87. struct arg_lit *abort;
  88. struct arg_end *end;
  89. } wifi_ping_args_t;
  90. typedef struct {
  91. struct arg_str *ip;
  92. struct arg_str *gw;
  93. struct arg_str *netmask;
  94. struct arg_end *end;
  95. } static_ip_args_t;
  96. typedef struct {
  97. struct arg_str *proto;
  98. struct arg_end *end;
  99. } wifi_proto_args_t;
  100. typedef struct {
  101. struct arg_int *val;
  102. struct arg_end *end;
  103. } wifi_inactive_time_args_t;
  104. typedef struct {
  105. struct arg_int *format;
  106. struct arg_int *rate;
  107. struct arg_end *end;
  108. } wifi_sounding_rate_t;
  109. typedef struct {
  110. struct arg_int *mcs;
  111. struct arg_int *power;
  112. struct arg_end *end;
  113. } wifi_tx_pwr_t;
  114. /*******************************************************
  115. * Variable Definitions
  116. *******************************************************/
  117. static reg_rw_args_t reg_rw_args;
  118. static wifi_stbc_args_t stbc_args;
  119. static wifi_bmfmee_args_t bmfmee_args;
  120. static wifi_omctrl_args_t omctrl_args;
  121. static wifi_tf_padding_args_t tf_padding_args;
  122. static wifi_edca_args_t edca_args;
  123. static wifi_cca_ignore_args_t cca_args;
  124. static wifi_ping_args_t ping_args;
  125. static static_ip_args_t static_ip_args;
  126. static wifi_proto_args_t proto_args;
  127. static wifi_inactive_time_args_t inactive_time_args;
  128. static wifi_sounding_rate_t wifi_sounding_rate_args;
  129. static wifi_muedca_args_t muedca_args;
  130. static wifi_tx_pwr_t tx_pwr_args;
  131. extern esp_netif_t *netif_ap;
  132. extern esp_netif_t *netif_sta;
  133. extern EventGroupHandle_t wifi_event_group;
  134. extern const int CONNECTED_BIT;
  135. /*******************************************************
  136. * Function Declarations
  137. *******************************************************/
  138. /*******************************************************
  139. * Function Definitions
  140. *******************************************************/
  141. static int wifi_cmd_get_mac(int argc, char **argv)
  142. {
  143. uint8_t mac[6] = { 0, };
  144. if (esp_wifi_get_mac(WIFI_IF_STA, mac) == ESP_OK) {
  145. ESP_LOGW(TAG, "sta mac: " MACSTR "", MAC2STR(mac));
  146. }
  147. if (esp_wifi_get_mac(WIFI_IF_AP, mac) == ESP_OK) {
  148. ESP_LOGW(TAG, "ap mac: " MACSTR "", MAC2STR(mac));
  149. }
  150. return 0;
  151. }
  152. static int wifi_cmd_set_omc(int argc, char **argv)
  153. {
  154. //TODO ER-SU
  155. esp_wifi_htc_omc_t omc = { 0, };
  156. esp_err_t err = ESP_OK;
  157. int nerrors = arg_parse(argc, argv, (void **) &omctrl_args);
  158. if (nerrors != 0) {
  159. arg_print_errors(stderr, omctrl_args.end, argv[0]);
  160. return 1;
  161. }
  162. do {
  163. if (!omctrl_args.ul_mu_disable->count && !omctrl_args.ul_mu_data_disable->count) {
  164. omc.ul_mu_disable = 1;
  165. omc.ul_mu_data_disable = 0;
  166. break;
  167. }
  168. /* parse inputs */
  169. if (omctrl_args.ul_mu_disable->count) {
  170. omc.ul_mu_disable = omctrl_args.ul_mu_disable->dval[0];
  171. }
  172. if (omctrl_args.ul_mu_data_disable->count) {
  173. omc.ul_mu_data_disable = omctrl_args.ul_mu_data_disable->dval[0];
  174. }
  175. if (omctrl_args.ersu_disable->count) {
  176. omc.er_su_disable = omctrl_args.ersu_disable->dval[0];
  177. }
  178. if (omctrl_args.resounding->count) {
  179. omc.dl_mu_mimo_resounding_recommendation = omctrl_args.resounding->dval[0];
  180. }
  181. } while (0);
  182. if (omctrl_args.report->count && omctrl_args.report->dval[0] == 0) {
  183. /* not report to ap the om control */
  184. hal_he_set_ul_mu(omc.ul_mu_disable, omc.ul_mu_data_disable);
  185. ESP_LOGW(TAG, "(omc)(internal)disable ul mu(%d, data:%d) successfully", omc.ul_mu_disable,
  186. omc.ul_mu_data_disable);
  187. } else {
  188. err = esp_wifi_set_htc_omc(&omc);
  189. if (err != ESP_OK) {
  190. ESP_LOGW(TAG, "(omc)disable ul mu(%d, data:%d) failed, err:0x%x", omc.ul_mu_disable, omc.ul_mu_data_disable,
  191. err);
  192. } else {
  193. ESP_LOGW(TAG, "(omc)disable ul mu(%d, data:%d) successfully", omc.ul_mu_disable, omc.ul_mu_data_disable);
  194. }
  195. }
  196. return 0;
  197. }
  198. static int wifi_cmd_edca_tx(int argc, char **argv)
  199. {
  200. int nerrors = arg_parse(argc, argv, (void **) &edca_args);
  201. if (nerrors != 0) {
  202. arg_print_errors(stderr, edca_args.end, argv[0]);
  203. return 1;
  204. }
  205. int txq = 2;
  206. if (!edca_args.enable->count && !edca_args.txq->count) {
  207. esp_test_disable_edca_tx(txq);
  208. ESP_LOGW(TAG, "(tx)disable edca, txq[%d]", txq);
  209. return 0;
  210. }
  211. txq = edca_args.txq->count ? edca_args.txq->ival[0] : txq;
  212. if (edca_args.enable->ival[0] == 0) {
  213. esp_test_disable_edca_tx(txq);
  214. ESP_LOGW(TAG, "(tx)disable edca, txq[%d]", txq);
  215. } else {
  216. esp_test_enable_edca_tx(txq);
  217. ESP_LOGW(TAG, "(tx)enable edca, txq[%d]", txq);
  218. }
  219. return 0;
  220. }
  221. static int wifi_cmd_reg_rw(int argc, char **argv)
  222. {
  223. int nerrors = arg_parse(argc, argv, (void **) &reg_rw_args);
  224. uint32_t addr;
  225. if (nerrors != 0) {
  226. arg_print_errors(stderr, reg_rw_args.end, argv[0]);
  227. return 1;
  228. }
  229. if (reg_rw_args.read->count) {
  230. addr = (uint32_t) reg_rw_args.read->dval[0];
  231. ESP_LOGW(TAG, "reg read 0x%08x : 0x%08x\n", addr, REG_READ(addr));
  232. } else if (reg_rw_args.write->count && (uint32_t) reg_rw_args.value->count) {
  233. addr = (uint32_t) reg_rw_args.write->dval[0];
  234. ESP_LOGW(TAG, "reg write 0x%8x : 0x%8x\n", addr, (uint32_t) reg_rw_args.value->dval[0]);
  235. REG_WRITE(addr, (uint32_t ) reg_rw_args.value->dval[0]);
  236. ESP_LOGW(TAG, "reg read 0x%08x : 0x%08x\n", addr, REG_READ(addr));
  237. } else {
  238. printf("Input Error\n");
  239. }
  240. return 0;
  241. }
  242. static int wifi_cmd_set_tf_padding(int argc, char **argv)
  243. {
  244. int nerrors = arg_parse(argc, argv, (void **) &tf_padding_args);
  245. if (nerrors != 0) {
  246. arg_print_errors(stderr, tf_padding_args.end, argv[0]);
  247. return 1;
  248. }
  249. if (tf_padding_args.tf_padding->count) {
  250. esp_wifi_set_tf_padding_duration((int)tf_padding_args.tf_padding->dval[0]);
  251. ESP_LOGW(TAG, "(test)set trigger frame mac padding duration:%d", (int)tf_padding_args.tf_padding->dval[0]);
  252. } else {
  253. printf("Input Error\n");
  254. }
  255. return 0;
  256. }
  257. static int wifi_cmd_tb(int argc, char **argv)
  258. {
  259. dbg_read_axtb_diag();
  260. dbg_read_ax_diag(1);
  261. return 0;
  262. }
  263. static int wifi_cmd_stbc(int argc, char **argv)
  264. {
  265. int nerrors = arg_parse(argc, argv, (void **) &stbc_args);
  266. if (nerrors != 0) {
  267. arg_print_errors(stderr, stbc_args.end, argv[0]);
  268. return 1;
  269. }
  270. if (stbc_args.disable->count) {
  271. esp_wifi_enable_rx_stbc(0);
  272. ESP_LOGI(TAG, "(cfg)disable he stbc");
  273. } else {
  274. esp_wifi_enable_rx_stbc(1);
  275. ESP_LOGI(TAG, "(cfg)enable he stbc");
  276. }
  277. return 0;
  278. }
  279. static int wifi_cmd_su_bmfmee(int argc, char **argv)
  280. {
  281. int nerrors = arg_parse(argc, argv, (void **) &bmfmee_args);
  282. if (nerrors != 0) {
  283. arg_print_errors(stderr, bmfmee_args.end, argv[0]);
  284. return 1;
  285. }
  286. if (bmfmee_args.disable->count) {
  287. esp_wifi_enable_su_bmfmee(0);
  288. ESP_LOGI(TAG, "(cfg)disable he su bmfmee");
  289. } else {
  290. esp_wifi_enable_su_bmfmee(1);
  291. ESP_LOGI(TAG, "(cfg)enable he su bmfmee");
  292. }
  293. return 0;
  294. }
  295. static int wifi_cmd_ignore_cca(int argc, char **argv)
  296. {
  297. int nerrors = arg_parse(argc, argv, (void **) &cca_args);
  298. if (nerrors != 0) {
  299. arg_print_errors(stderr, cca_args.end, argv[0]);
  300. return 1;
  301. }
  302. if (cca_args.enable->count) {
  303. dbg_tb_ignore_cca_enable(1);
  304. } else {
  305. dbg_tb_ignore_cca_enable(0);
  306. }
  307. return 0;
  308. }
  309. static int wifi_cmd_set_ps_type(int argc, char **argv)
  310. {
  311. ESP_LOGW(TAG, "set to WIFI_PS_MIN_MODEM");
  312. ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
  313. return 0;
  314. }
  315. static void cmd_ping_on_ping_success(esp_ping_handle_t hdl, void *args)
  316. {
  317. uint8_t ttl;
  318. uint16_t seqno;
  319. uint32_t elapsed_time, recv_len;
  320. ip_addr_t target_addr;
  321. esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno));
  322. esp_ping_get_profile(hdl, ESP_PING_PROF_TTL, &ttl, sizeof(ttl));
  323. esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
  324. esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len));
  325. esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
  326. printf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n",
  327. recv_len, inet_ntoa(target_addr.u_addr.ip4), seqno, ttl, elapsed_time);
  328. }
  329. static void cmd_ping_on_ping_timeout(esp_ping_handle_t hdl, void *args)
  330. {
  331. uint16_t seqno;
  332. ip_addr_t target_addr;
  333. esp_ping_get_profile(hdl, ESP_PING_PROF_SEQNO, &seqno, sizeof(seqno));
  334. esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
  335. printf("From %s icmp_seq=%d timeout\n", inet_ntoa(target_addr.u_addr.ip4), seqno);
  336. }
  337. static void cmd_ping_on_ping_end(esp_ping_handle_t hdl, void *args)
  338. {
  339. ip_addr_t target_addr;
  340. uint32_t transmitted;
  341. uint32_t received;
  342. uint32_t total_time_ms;
  343. esp_ping_get_profile(hdl, ESP_PING_PROF_REQUEST, &transmitted, sizeof(transmitted));
  344. esp_ping_get_profile(hdl, ESP_PING_PROF_REPLY, &received, sizeof(received));
  345. esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
  346. esp_ping_get_profile(hdl, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms));
  347. uint32_t loss = (uint32_t)((1 - ((float)received) / transmitted) * 100);
  348. if (IP_IS_V4(&target_addr)) {
  349. printf("\n--- %s ping statistics ---\n", inet_ntoa(*ip_2_ip4(&target_addr)));
  350. } else {
  351. printf("\n--- %s ping statistics ---\n", inet6_ntoa(*ip_2_ip6(&target_addr)));
  352. }
  353. printf("%d packets transmitted, %d received, %d%% packet loss, time %dms\n",
  354. transmitted, received, loss, total_time_ms);
  355. // delete the ping sessions, so that we clean up all resources and can create a new ping session
  356. // we don't have to call delete function in the callback, instead we can call delete function from other tasks
  357. esp_ping_delete_session(hdl);
  358. }
  359. static int do_ping_cmd(int argc, char **argv)
  360. {
  361. esp_ping_config_t config = ESP_PING_DEFAULT_CONFIG();
  362. static esp_ping_handle_t ping;
  363. int nerrors = arg_parse(argc, argv, (void **)&ping_args);
  364. if (nerrors != 0) {
  365. arg_print_errors(stderr, ping_args.end, argv[0]);
  366. return 1;
  367. }
  368. if (ping_args.timeout->count > 0) {
  369. config.timeout_ms = (uint32_t)(ping_args.timeout->dval[0] * 1000);
  370. }
  371. if (ping_args.interval->count > 0) {
  372. config.interval_ms = (uint32_t)(ping_args.interval->dval[0] * 1000);
  373. }
  374. if (ping_args.data_size->count > 0) {
  375. config.data_size = (uint32_t)(ping_args.data_size->ival[0]);
  376. }
  377. if (ping_args.count->count > 0) {
  378. config.count = (uint32_t)(ping_args.count->ival[0]);
  379. }
  380. if (ping_args.tos->count > 0) {
  381. config.tos = (uint32_t)(ping_args.tos->ival[0]);
  382. }
  383. if (ping_args.abort->count) {
  384. esp_ping_stop(ping);
  385. return 0;
  386. }
  387. // parse IP address
  388. ip_addr_t target_addr;
  389. struct addrinfo hint;
  390. struct addrinfo *res = NULL;
  391. memset(&hint, 0, sizeof(hint));
  392. memset(&target_addr, 0, sizeof(target_addr));
  393. /* convert domain name to IP address */
  394. if (getaddrinfo(ping_args.host->sval[0], NULL, &hint, &res) != 0) {
  395. printf("ping: unknown host %s\n", ping_args.host->sval[0]);
  396. return 1;
  397. }
  398. if (res->ai_family == AF_INET) {
  399. struct in_addr addr4 = ((struct sockaddr_in *) (res->ai_addr))->sin_addr;
  400. inet_addr_to_ip4addr(ip_2_ip4(&target_addr), &addr4);
  401. } else {
  402. struct in6_addr addr6 = ((struct sockaddr_in6 *) (res->ai_addr))->sin6_addr;
  403. inet6_addr_to_ip6addr(ip_2_ip6(&target_addr), &addr6);
  404. }
  405. freeaddrinfo(res);
  406. config.target_addr = target_addr;
  407. /* set callback functions */
  408. esp_ping_callbacks_t cbs = {
  409. .on_ping_success = cmd_ping_on_ping_success,
  410. .on_ping_timeout = cmd_ping_on_ping_timeout,
  411. .on_ping_end = cmd_ping_on_ping_end,
  412. .cb_args = NULL
  413. };
  414. esp_ping_new_session(&config, &cbs, &ping);
  415. esp_ping_start(ping);
  416. return 0;
  417. }
  418. extern bool pm_is_waked(void);
  419. extern bool pm_is_sleeping(void);
  420. extern bool pm_is_dream(void);
  421. static int wifi_cmd_get_ps_state(int argc, char **argv)
  422. {
  423. ESP_LOGW(TAG, "ps: awake:%d, sleep:%d, dream:%d", pm_is_waked(), pm_is_sleeping(), pm_is_dream());
  424. return 0;
  425. }
  426. esp_err_t esp_netif_set_static_ip(esp_netif_t *netif_sta, uint32_t ip, uint32_t gw,
  427. uint32_t netmask)
  428. {
  429. esp_netif_dhcpc_stop(netif_sta);
  430. esp_netif_ip_info_t ip_info;
  431. esp_netif_set_ip4_addr(&ip_info.ip, ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF,
  432. (ip >> 24) & 0xFF);
  433. esp_netif_set_ip4_addr(&ip_info.gw, gw & 0xFF, (gw >> 8) & 0xFF, (gw >> 16) & 0xFF,
  434. (gw >> 24) & 0xFF);
  435. esp_netif_set_ip4_addr(&ip_info.netmask, netmask & 0xFF, (netmask >> 8) & 0xFF,
  436. (netmask >> 16) & 0xFF, (netmask >> 24) & 0xFF);
  437. esp_netif_set_ip_info(netif_sta, &ip_info);
  438. return ESP_OK;
  439. }
  440. static int wifi_cmd_set_ip(int argc, char **argv)
  441. {
  442. uint32_t ip = 0, gw = 0, netmask = 0;
  443. int nerrors = arg_parse(argc, argv, (void **) &static_ip_args);
  444. if (nerrors != 0) {
  445. arg_print_errors(stderr, static_ip_args.end, argv[0]);
  446. return 0;
  447. }
  448. if (static_ip_args.ip->count != 0) {
  449. ip = esp_ip4addr_aton(static_ip_args.ip->sval[0]);
  450. }
  451. if (static_ip_args.gw->count != 0) {
  452. gw = esp_ip4addr_aton(static_ip_args.gw->sval[0]);
  453. }
  454. if (static_ip_args.netmask->count != 0) {
  455. netmask = esp_ip4addr_aton(static_ip_args.netmask->sval[0]);
  456. }
  457. if (!ip || !netmask) {
  458. return 0;
  459. }
  460. /* set static IP settings */
  461. esp_netif_set_static_ip(netif_sta, ip, gw, netmask);
  462. ESP_LOGD(TAG, "ip:%d.%d.%d.%d, gateway:%d.%d.%d.%d, netmask:%d.%d.%d.%d,", ip & 0xFF,
  463. (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF, gw & 0xFF, (gw >> 8) & 0xFF,
  464. (gw >> 16) & 0xFF, (gw >> 24) & 0xFF, netmask & 0xFF, (netmask >> 8) & 0xFF,
  465. (netmask >> 16) & 0xFF, (netmask >> 24) & 0xFF);
  466. return 0;
  467. }
  468. void wifi_get_local_ip(esp_netif_ip_info_t *ip_info)
  469. {
  470. int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
  471. esp_netif_t *netif = netif_ap;
  472. wifi_mode_t mode;
  473. esp_wifi_get_mode(&mode);
  474. if (WIFI_MODE_STA == mode) {
  475. bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
  476. if (bits & CONNECTED_BIT) {
  477. netif = netif_sta;
  478. } else {
  479. ESP_LOGE(TAG, "sta has no IP");
  480. }
  481. }
  482. esp_netif_get_ip_info(netif, ip_info);
  483. }
  484. static int wifi_cmd_query(int argc, char **argv)
  485. {
  486. wifi_config_t cfg;
  487. wifi_bandwidth_t cbw;
  488. uint8_t mac[6];
  489. esp_netif_ip_info_t ip_info = { 0, };
  490. wifi_mode_t mode;
  491. esp_wifi_get_mode(&mode);
  492. wifi_get_local_ip(&ip_info);
  493. bool is_sta_disconnect = false;
  494. char temp_ssid[33] = { 0 };
  495. printf("Wireless info:");
  496. if (WIFI_MODE_AP == mode) {
  497. esp_wifi_get_config(WIFI_IF_AP, &cfg);
  498. esp_wifi_get_bandwidth(WIFI_IF_AP, &cbw);
  499. printf("\n");
  500. printf("\tmode: ap\n");
  501. strncpy(temp_ssid, (char *) cfg.ap.ssid, 32);
  502. printf("\tssid: %s\n", temp_ssid);
  503. printf("\tpassword: %s\n", cfg.ap.password);
  504. printf("\tchannel: %d\n", cfg.ap.channel);
  505. if (cbw == WIFI_BW_HT20) {
  506. printf("\tcbw: 20 MHz\n");
  507. } else if (cbw == WIFI_BW_HT40) {
  508. printf("\tcbw: 40 MHz\n");
  509. }
  510. if (esp_wifi_get_mac(WIFI_IF_AP, mac) == ESP_OK) {
  511. printf("\tap mac: "MACSTR, MAC2STR(mac));
  512. printf("\n");
  513. }
  514. printf("\tip: %d.%d.%d.%d\n", ip_info.ip.addr & 0xFF, (ip_info.ip.addr >> 8) & 0xFF,
  515. (ip_info.ip.addr >> 16) & 0xFF, (ip_info.ip.addr >> 24) & 0xFF);
  516. printf("\tnetmask: %d.%d.%d.%d\n", ip_info.netmask.addr & 0xFF,
  517. (ip_info.netmask.addr >> 8) & 0xFF, (ip_info.netmask.addr >> 16) & 0xFF,
  518. (ip_info.netmask.addr >> 24) & 0xFF);
  519. printf("\tgateway: %d.%d.%d.%d\n", ip_info.gw.addr & 0xFF, (ip_info.gw.addr >> 8) & 0xFF,
  520. (ip_info.gw.addr >> 16) & 0xFF, (ip_info.gw.addr >> 24) & 0xFF);
  521. printf("\n");
  522. } else if (WIFI_MODE_STA == mode) {
  523. int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
  524. if (bits & CONNECTED_BIT) {
  525. is_sta_disconnect = false;
  526. esp_wifi_get_config(WIFI_IF_STA, &cfg);
  527. esp_wifi_get_bandwidth(WIFI_IF_STA, &cbw);
  528. printf("\n");
  529. printf("\tmode: station\n");
  530. printf("\tstatus: connected\n");
  531. strncpy(temp_ssid, (char *) cfg.sta.ssid, 32);
  532. printf("\tssid: %s\n", temp_ssid);
  533. printf("\tbssid: "MACSTR, MAC2STR(cfg.sta.bssid));
  534. printf("\n");
  535. printf("\tchannel: %d\n", cfg.sta.channel);
  536. printf("\taid: %d\n", cfg.sta.aid);
  537. if (cfg.sta.pmf_cfg.capable) {
  538. if (cfg.sta.pmf_cfg.required) {
  539. printf("\tpmf: required\n");
  540. } else {
  541. printf("\tpmf: optional\n");
  542. }
  543. } else {
  544. printf("\tpmf: disabled\n");
  545. }
  546. if (cbw == WIFI_BW_HT20) {
  547. printf("\tcbw: 20 MHz\n");
  548. } else if (cbw == WIFI_BW_HT40) {
  549. printf("\tcbw: 40 MHz\n");
  550. }
  551. if (esp_wifi_get_mac(WIFI_IF_STA, mac) == ESP_OK) {
  552. printf("\tsta mac: "MACSTR, MAC2STR(mac));
  553. printf("\n");
  554. }
  555. printf("\tip: %d.%d.%d.%d\n", ip_info.ip.addr & 0xFF, (ip_info.ip.addr >> 8) & 0xFF,
  556. (ip_info.ip.addr >> 16) & 0xFF, (ip_info.ip.addr >> 24) & 0xFF);
  557. printf("\tnetmask: %d.%d.%d.%d\n", ip_info.netmask.addr & 0xFF,
  558. (ip_info.netmask.addr >> 8) & 0xFF, (ip_info.netmask.addr >> 16) & 0xFF,
  559. (ip_info.netmask.addr >> 24) & 0xFF);
  560. printf("\tgateway: %d.%d.%d.%d\n", ip_info.gw.addr & 0xFF,
  561. (ip_info.gw.addr >> 8) & 0xFF, (ip_info.gw.addr >> 16) & 0xFF,
  562. (ip_info.gw.addr >> 24) & 0xFF);
  563. printf("\n");
  564. } else {
  565. printf("\n");
  566. printf("\tmode: disconnected\n");
  567. is_sta_disconnect = true;
  568. }
  569. }
  570. if (WIFI_MODE_NULL == mode || is_sta_disconnect) {
  571. printf("\n");
  572. if (WIFI_MODE_NULL == mode) {
  573. printf("\tmode: null\n");
  574. }
  575. if (esp_wifi_get_mac(WIFI_IF_AP, mac) == ESP_OK) {
  576. printf("\tap mac: "MACSTR, MAC2STR(mac));
  577. printf("\n");
  578. }
  579. if (esp_wifi_get_mac(WIFI_IF_STA, mac) == ESP_OK) {
  580. printf("\tsta mac: "MACSTR, MAC2STR(mac));
  581. printf("\n");
  582. }
  583. return 0;
  584. }
  585. return 0;
  586. }
  587. static int wifi_cmd_proto(int argc, char **argv)
  588. {
  589. int nerrors = arg_parse(argc, argv, (void **)&proto_args);
  590. if (nerrors != 0) {
  591. arg_print_errors(stderr, proto_args.end, argv[0]);
  592. return 1;
  593. }
  594. wifi_mode_t mode;
  595. esp_wifi_get_mode(&mode);
  596. int ifx = (WIFI_MODE_STA == mode) ? 0 : 1;
  597. if (proto_args.proto->count) {
  598. if (!strcmp(proto_args.proto->sval[0], "ax")) {
  599. ESP_ERROR_CHECK(esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX));
  600. printf("(%s)set to 11ax\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  601. } else if (!strcmp(proto_args.proto->sval[0], "bgn")) {
  602. ESP_ERROR_CHECK(esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N));
  603. printf("(%s)set to bgn\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  604. } else if (!strcmp(proto_args.proto->sval[0], "bg")) {
  605. ESP_ERROR_CHECK(esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G));
  606. printf("(%s)set to bg\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  607. } else {
  608. ESP_ERROR_CHECK(esp_wifi_set_protocol(ifx, WIFI_PROTOCOL_11B));
  609. printf("(%s)set to b\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  610. }
  611. }
  612. uint8_t protocol_bitmap = 0;
  613. ESP_ERROR_CHECK(esp_wifi_get_protocol(ifx, &protocol_bitmap) );
  614. if (protocol_bitmap & WIFI_PROTOCOL_11AX) {
  615. printf("(%s)11ax\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  616. } else if (protocol_bitmap & WIFI_PROTOCOL_11N) {
  617. printf("(%s)bgn\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  618. } else if (protocol_bitmap & WIFI_PROTOCOL_11G) {
  619. printf("(%s)bg\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  620. } else if (protocol_bitmap & WIFI_PROTOCOL_11B) {
  621. printf("(%s)b\n", (ifx == WIFI_IF_STA) ? "sta" : "ap");
  622. }
  623. return 0;
  624. }
  625. static int wifi_disconnect(int argc, char **argv)
  626. {
  627. wifi_mode_t mode;
  628. esp_wifi_get_mode(&mode);
  629. if (WIFI_MODE_AP == mode) {
  630. // TODO
  631. ESP_LOGI(TAG, "WIFI_MODE_AP, not support");
  632. } else if (WIFI_MODE_STA == mode) {
  633. esp_wifi_disconnect();
  634. printf("disconnect\n");
  635. } else {
  636. ESP_LOGI(TAG, "NULL mode");
  637. }
  638. return 0;
  639. }
  640. static int wifi_cmd_inactive_time(int argc, char **argv)
  641. {
  642. int nerrors = arg_parse(argc, argv, (void **)&inactive_time_args);
  643. if (nerrors != 0) {
  644. arg_print_errors(stderr, inactive_time_args.end, argv[0]);
  645. return 1;
  646. }
  647. esp_err_t err = ESP_OK;
  648. wifi_mode_t mode;
  649. esp_wifi_get_mode(&mode);
  650. if ((mode & WIFI_MODE_AP) && inactive_time_args.val->count) {
  651. err = esp_wifi_set_inactive_time(ESP_IF_WIFI_AP, inactive_time_args.val->ival[0]);
  652. if (err != ESP_OK) {
  653. ESP_LOGW(TAG, "set softAP inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0], err);
  654. } else {
  655. ESP_LOGI(TAG, "set softAP inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0]);
  656. }
  657. }
  658. //WIFI_MODE_STA or WIFI_MODE_APSTA
  659. if ((mode & WIFI_MODE_STA) && inactive_time_args.val->count) {
  660. err = esp_wifi_set_inactive_time(ESP_IF_WIFI_STA, inactive_time_args.val->ival[0]);
  661. if (err != ESP_OK) {
  662. ESP_LOGW(TAG, "set STA inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0], err);
  663. } else {
  664. ESP_LOGI(TAG, "set STA inactive time to %d seconds, err:0x%x\n", inactive_time_args.val->ival[0]);
  665. }
  666. }
  667. uint16_t secs = 0;
  668. esp_wifi_get_inactive_time(ESP_IF_WIFI_STA, &secs);
  669. printf("inactive time: %d seconds\n", secs);
  670. return 0;
  671. }
  672. static int wifi_cmd_sounding_rate(int argc, char **argv)
  673. {
  674. int nerrors = arg_parse(argc, argv, (void **)&wifi_sounding_rate_args);
  675. if (nerrors != 0) {
  676. arg_print_errors(stderr, wifi_sounding_rate_args.end, argv[0]);
  677. return 1;
  678. }
  679. if (wifi_sounding_rate_args.format->count && wifi_sounding_rate_args.rate->count) {
  680. if (wifi_sounding_rate_args.format->ival[0] == SIG_MODE_LEGACY) {
  681. if (wifi_sounding_rate_args.rate->ival[0] < WIFI_PHY_RATE_MCS0_LGI &&
  682. wifi_sounding_rate_args.rate->ival[0] >= 0) {
  683. hal_he_set_bf_report_rate(SIG_MODE_LEGACY, wifi_sounding_rate_args.rate->ival[0]);
  684. } else {
  685. ESP_LOGW(TAG, "need correct legacy rate(0-%d)", WIFI_PHY_RATE_9M);
  686. }
  687. } else {
  688. if (wifi_sounding_rate_args.rate->ival[0] >= WIFI_PHY_RATE_MCS0_LGI &&
  689. wifi_sounding_rate_args.rate->ival[0] <= WIFI_PHY_RATE_MCS9_SGI) {
  690. hal_he_set_bf_report_rate(wifi_sounding_rate_args.format->ival[0],
  691. wifi_sounding_rate_args.rate->ival[0]);
  692. } else {
  693. ESP_LOGW(TAG, "need correct mcs(%d-%d)", WIFI_PHY_RATE_MCS0_LGI, WIFI_PHY_RATE_MCS9_SGI);
  694. }
  695. }
  696. } else {
  697. ESP_LOGW(TAG, "set rate fail");
  698. }
  699. return 0;
  700. }
  701. static int wifi_cmd_muedca(int argc, char **argv)
  702. {
  703. int nerrors = arg_parse(argc, argv, (void **)&muedca_args);
  704. if (nerrors != 0) {
  705. arg_print_errors(stderr, muedca_args.end, argv[0]);
  706. return 1;
  707. }
  708. if (muedca_args.reset_timer->count) {
  709. esp_wifi_sta_reset_muedca_timer(muedca_args.reset_timer->ival[0]);
  710. }
  711. uint8_t aci_bitmap = 0;
  712. if (muedca_args.read_timer->count) {
  713. aci_bitmap = muedca_args.read_timer->ival[0];
  714. if (aci_bitmap & BIT(0)) {
  715. dbg_read_muedca_timer(3);
  716. }
  717. if (aci_bitmap & BIT(1)) {
  718. dbg_read_muedca_timer(2);
  719. }
  720. if (aci_bitmap & BIT(2)) {
  721. dbg_read_muedca_timer(1);
  722. }
  723. if (aci_bitmap & BIT(3)) {
  724. dbg_read_muedca_timer(0);
  725. }
  726. }
  727. return 0;
  728. }
  729. static int wifi_cmd_set_tx_pwr(int argc, char **argv)
  730. {
  731. int nerrors = arg_parse(argc, argv, (void **)&tx_pwr_args);
  732. if (nerrors != 0) {
  733. arg_print_errors(stderr, tx_pwr_args.end, argv[0]);
  734. return 1;
  735. }
  736. if (tx_pwr_args.mcs->count && tx_pwr_args.power->count) {
  737. if (tx_pwr_args.mcs->ival[0] <= 9 && tx_pwr_args.mcs->ival[0] >= 0) {
  738. if (tx_pwr_args.power->ival[0] >= -13 &&
  739. tx_pwr_args.power->ival[0] <= 20) {
  740. esp_test_set_tx_mcs_pwr(tx_pwr_args.mcs->ival[0] + WIFI_PHY_RATE_MCS0_LGI, tx_pwr_args.power->ival[0]);
  741. ESP_LOGW(TAG, "set MCS%d TX PWR to %d", tx_pwr_args.mcs->ival[0], tx_pwr_args.power->ival[0]);
  742. } else if (tx_pwr_args.power->ival[0] == 0xff) {
  743. esp_test_set_tx_mcs_pwr(tx_pwr_args.mcs->ival[0] + WIFI_PHY_RATE_MCS0_LGI, tx_pwr_args.power->ival[0]);
  744. ESP_LOGW(TAG, "set MCS%d TX PWR to default value", tx_pwr_args.mcs->ival[0], tx_pwr_args.power->ival[0]);
  745. }
  746. } else {
  747. ESP_LOGW(TAG, "Set TX power fail, MCS should in range [0,9], power should in range [-13, 30] or set 0xFF for default");
  748. }
  749. }
  750. return 0;
  751. }
  752. static int wifi_read_avgsnr(int argc, char **argv)
  753. {
  754. wifi_mode_t mode;
  755. esp_wifi_get_mode(&mode);
  756. if (WIFI_MODE_AP == mode) {
  757. // TODO
  758. ESP_LOGI(TAG, "WIFI_MODE_AP, not support");
  759. } else if (WIFI_MODE_STA == mode || WIFI_MODE_APSTA == mode) {
  760. printf("%.2f\n", esp_test_get_bfr_avgsnr());
  761. } else {
  762. ESP_LOGI(TAG, "NULL mode");
  763. }
  764. return 0;
  765. }
  766. void register_wifi_cmd(void)
  767. {
  768. /* mac */
  769. const esp_console_cmd_t maccmd = {
  770. .command = "mac",
  771. .help = "get mac",
  772. .hint = NULL,
  773. .func = &wifi_cmd_get_mac,
  774. };
  775. ESP_ERROR_CHECK(esp_console_cmd_register(&maccmd));
  776. /* disable edca */
  777. edca_args.enable = arg_int0("e", "enable", "[enable]", "enable edca tx");
  778. edca_args.txq = arg_int0("q", "txq", "[txq]", "enable edca txq");
  779. edca_args.end = arg_end(1);
  780. const esp_console_cmd_t edca_cmd = {
  781. .command = "edca",
  782. .help = "enable/disable edca",
  783. .hint = NULL,
  784. .func = &wifi_cmd_edca_tx,
  785. };
  786. ESP_ERROR_CHECK(esp_console_cmd_register(&edca_cmd));
  787. /* read/write hw registers */
  788. reg_rw_args.read = arg_dbl0("r", NULL, "<read_addr>", "read register address");
  789. reg_rw_args.write = arg_dbl0("w", NULL, "<write_addr>", "write register address");
  790. reg_rw_args.value = arg_dbl0("v", NULL, "<value>", "write value");
  791. reg_rw_args.end = arg_end(2);
  792. const esp_console_cmd_t reg_rw_cmd = {
  793. .command = "reg",
  794. .help = "r/w hw register",
  795. .hint = NULL,
  796. .func = &wifi_cmd_reg_rw,
  797. .argtable = &reg_rw_args,
  798. };
  799. ESP_ERROR_CHECK(esp_console_cmd_register(&reg_rw_cmd));
  800. /* om control */
  801. omctrl_args.ul_mu_disable = arg_dbl0("u", "ulmu", "[ulmu]", "disable ul mu");
  802. omctrl_args.ul_mu_data_disable = arg_dbl0("d", "uldata", "[uldata]", "disable ul mu data");
  803. omctrl_args.ersu_disable = arg_dbl0("e", "ersu", "[ersu]", "disable ersu");
  804. omctrl_args.report = arg_dbl0("r", "report", "[report]", "report om control to ap");
  805. omctrl_args.resounding = arg_dbl0("s", "resounding", "[resounding]", "DL MU-MIMO resound Recoummendation");
  806. omctrl_args.end = arg_end(1);
  807. const esp_console_cmd_t omctrl_cmd = {
  808. .command = "omc",
  809. .help = "om control",
  810. .hint = NULL,
  811. .func = &wifi_cmd_set_omc,
  812. .argtable = &omctrl_args,
  813. };
  814. ESP_ERROR_CHECK(esp_console_cmd_register(&omctrl_cmd));
  815. /* stbc */
  816. stbc_args.disable = arg_dbl0("d", "disable", "[disable]", "disable stbc");
  817. stbc_args.end = arg_end(1);
  818. const esp_console_cmd_t stbc_cmd = {
  819. .command = "stbc",
  820. .help = "configure stbc",
  821. .hint = NULL,
  822. .func = &wifi_cmd_stbc,
  823. .argtable = &stbc_args
  824. };
  825. ESP_ERROR_CHECK(esp_console_cmd_register(&stbc_cmd));
  826. /* su bmfmee */
  827. bmfmee_args.disable = arg_dbl0("d", "disable", "[disable]", "disable bmfmee");
  828. bmfmee_args.end = arg_end(1);
  829. const esp_console_cmd_t bmfmee_cmd = {
  830. .command = "bmfmee",
  831. .help = "configure su bmfmee",
  832. .hint = NULL,
  833. .func = &wifi_cmd_su_bmfmee,
  834. .argtable = &bmfmee_args
  835. };
  836. ESP_ERROR_CHECK(esp_console_cmd_register(&bmfmee_cmd));
  837. /* set trigger frame mac padding duration */
  838. tf_padding_args.tf_padding = arg_dbl0("p", "padding", "[padding]", "set trigger frame mac padding duration");
  839. tf_padding_args.end = arg_end(1);
  840. const esp_console_cmd_t tf_padding_cmd = {
  841. .command = "tf",
  842. .help = "set padding",
  843. .hint = NULL,
  844. .func = &wifi_cmd_set_tf_padding,
  845. .argtable = &tf_padding_args,
  846. };
  847. ESP_ERROR_CHECK(esp_console_cmd_register(&tf_padding_cmd));
  848. /* ignore cca */
  849. cca_args.enable = arg_dbl0("e", "enable", "[enable]", "enable ignore cca");
  850. cca_args.end = arg_end(1);
  851. const esp_console_cmd_t cca_cmd = {
  852. .command = "cca",
  853. .help = "ignore cca",
  854. .hint = NULL,
  855. .func = &wifi_cmd_ignore_cca,
  856. .argtable = &cca_args,
  857. };
  858. ESP_ERROR_CHECK(esp_console_cmd_register(&cca_cmd));
  859. /* dump tx tb ppdu */
  860. const esp_console_cmd_t tb_cmd = {
  861. .command = "tb",
  862. .help = "dump tx tb ppdu",
  863. .hint = NULL,
  864. .func = &wifi_cmd_tb,
  865. };
  866. ESP_ERROR_CHECK(esp_console_cmd_register(&tb_cmd));
  867. /* set ps type */
  868. const esp_console_cmd_t ps_cmd = {
  869. .command = "ps",
  870. .help = "set ps type",
  871. .hint = NULL,
  872. .func = &wifi_cmd_set_ps_type,
  873. };
  874. ESP_ERROR_CHECK(esp_console_cmd_register(&ps_cmd));
  875. /* ping test */
  876. ping_args.timeout = arg_dbl0("W", "timeout", "<t>", "Time to wait for a response, in seconds");
  877. ping_args.interval = arg_dbl0("i", "interval", "<t>", "Wait interval seconds between sending each packet");
  878. ping_args.data_size = arg_int0("s", "size", "<n>", "Specify the number of data bytes to be sent");
  879. ping_args.count = arg_int0("c", "count", "<n>", "Stop after sending count packets");
  880. ping_args.tos = arg_int0("Q", "tos", "<n>", "Set Type of Service related bits in IP datagrams");
  881. ping_args.host = arg_str0(NULL, NULL, "[host]", "Host address");
  882. ping_args.abort = arg_lit0("a", "abort", "abort");
  883. ping_args.end = arg_end(1);
  884. const esp_console_cmd_t ping_cmd = {
  885. .command = "ping",
  886. .help = "send ICMP ECHO_REQUEST to network hosts",
  887. .hint = NULL,
  888. .func = &do_ping_cmd,
  889. .argtable = &ping_args
  890. };
  891. ESP_ERROR_CHECK(esp_console_cmd_register(&ping_cmd));
  892. /* get ps state */
  893. const esp_console_cmd_t pss_cmd = {
  894. .command = "pss",
  895. .help = "get ps state",
  896. .hint = NULL,
  897. .func = &wifi_cmd_get_ps_state,
  898. };
  899. ESP_ERROR_CHECK(esp_console_cmd_register(&pss_cmd));
  900. /* ip */
  901. static_ip_args.ip = arg_str0("i", "ip", "<ip>", "ip address");
  902. static_ip_args.gw = arg_str0("g", "gateway", "<gw>", "gateway address");
  903. static_ip_args.netmask = arg_str0("n", "netmask", "<netmask>", "netmask addess");
  904. static_ip_args.end = arg_end(1);
  905. const esp_console_cmd_t static_ip_cmd = {
  906. .command = "ip",
  907. .help = "ip settings",
  908. .hint = NULL,
  909. .func = &wifi_cmd_set_ip,
  910. .argtable = &static_ip_args,
  911. };
  912. ESP_ERROR_CHECK(esp_console_cmd_register(&static_ip_cmd));
  913. /* query */
  914. const esp_console_cmd_t query_cmd = {
  915. .command = "query",
  916. .help = "query WiFi info",
  917. .hint = NULL,
  918. .func = &wifi_cmd_query,
  919. };
  920. ESP_ERROR_CHECK(esp_console_cmd_register(&query_cmd));
  921. /* proto */
  922. proto_args.proto = arg_str0(NULL, NULL, "<proto>", "proto [ax,bgn,bg,b]");
  923. proto_args.end = arg_end(1);
  924. const esp_console_cmd_t proto_cmd = {
  925. .command = "proto",
  926. .help = "set wifi protocol",
  927. .hint = NULL,
  928. .func = &wifi_cmd_proto,
  929. .argtable = &proto_args
  930. };
  931. ESP_ERROR_CHECK(esp_console_cmd_register(&proto_cmd));
  932. /* disconnect */
  933. const esp_console_cmd_t disconnect_cmd = {
  934. .command = "disconnect",
  935. .help = "disconnect",
  936. .hint = NULL,
  937. .func = &wifi_disconnect,
  938. };
  939. ESP_ERROR_CHECK(esp_console_cmd_register(&disconnect_cmd));
  940. /* inactive time */
  941. inactive_time_args.val = arg_int0("t", "time", "time", "set inactive time, in seconds");
  942. inactive_time_args.end = arg_end(1);
  943. const esp_console_cmd_t inactive_cmd = {
  944. .command = "inactive",
  945. .help = "inactive time, unit: seconds",
  946. .hint = NULL,
  947. .func = &wifi_cmd_inactive_time,
  948. .argtable = &inactive_time_args,
  949. };
  950. ESP_ERROR_CHECK(esp_console_cmd_register(&inactive_cmd));
  951. /* set beamforming report rate */
  952. wifi_sounding_rate_args.format = arg_int0("f", "format", "format", "set format");
  953. wifi_sounding_rate_args.rate = arg_int0("r", "rate", "rate", "set rate");
  954. wifi_sounding_rate_args.end = arg_end(1);
  955. const esp_console_cmd_t sounding_rate_cmd = {
  956. .command = "sounding",
  957. .help = "set beamforming report rate",
  958. .hint = NULL,
  959. .func = &wifi_cmd_sounding_rate,
  960. .argtable = &wifi_sounding_rate_args,
  961. };
  962. ESP_ERROR_CHECK(esp_console_cmd_register(&sounding_rate_cmd));
  963. /* muedca */
  964. muedca_args.reset_timer = arg_int0("r", NULL, "reset timer", "reset muedca timer");
  965. muedca_args.read_timer = arg_int0("d", NULL, "read timer", "read muedca timer");
  966. muedca_args.end = arg_end(1);
  967. const esp_console_cmd_t reg_muedca_cmd = {
  968. .command = "muedca",
  969. .help = "Reset/Read muedca timer",
  970. .hint = NULL,
  971. .func = &wifi_cmd_muedca,
  972. .argtable = &muedca_args,
  973. };
  974. ESP_ERROR_CHECK(esp_console_cmd_register(&reg_muedca_cmd));
  975. /* tx_pwr */
  976. tx_pwr_args.mcs = arg_int0("m", NULL, "[0, 9]", "force tx power on MCSX");
  977. tx_pwr_args.power = arg_int0("p", NULL, "[-13, 20]", "set max power, set 0xFF for default");
  978. tx_pwr_args.end = arg_end(1);
  979. const esp_console_cmd_t reg_tx_pwr_cmd = {
  980. .command = "txpwr",
  981. .help = "force tx power on MCSX",
  982. .hint = NULL,
  983. .func = &wifi_cmd_set_tx_pwr,
  984. .argtable = &tx_pwr_args,
  985. };
  986. ESP_ERROR_CHECK(esp_console_cmd_register(&reg_tx_pwr_cmd));
  987. /* avgSNR */
  988. const esp_console_cmd_t avgsnr_cmd = {
  989. .command = "avgsnr",
  990. .help = "show avgSnr in beamforming memory",
  991. .hint = NULL,
  992. .func = &wifi_read_avgsnr,
  993. };
  994. ESP_ERROR_CHECK(esp_console_cmd_register(&avgsnr_cmd));
  995. }
  996. #else
  997. void register_wifi_cmd(void)
  998. {
  999. ;
  1000. }
  1001. #endif /* CONFIG_SOC_WIFI_HE_SUPPORT */