wifi_cmd.c 37 KB

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