1 /** @file wlan_tests.c
2 *
3 * @brief This file provides WLAN Test API
4 *
5 * Copyright 2008-2024 NXP
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 *
9 */
10
11 #include <string.h>
12 #include <osa.h>
13 #include <wm_net.h> /* for net_inet_aton */
14 #include <wlan.h>
15 #include <wifi.h>
16 #include <wlan_tests.h>
17 #include <wlan_11d.h>
18 #if CONFIG_WPS2
19 #include <wifi_nxp_wps.h>
20 #endif
21 #if CONFIG_WPA_SUPP_DPP
22 #include "dpp.h"
23 #endif
24
25 #if CONFIG_MEM_POOLS
26 #include <mem_pool_config.h>
27 #endif
28
29 #include <cli_utils.h>
30 #include "wifi_shell.h"
31
32 /*
33 * NXP Test Framework (MTF) functions
34 */
35
36 #if (CONFIG_CSI) || (CONFIG_NET_MONITOR)
37 static uint8_t broadcast_mac[MLAN_MAC_ADDR_LENGTH] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
38 #endif
39
40 #if CONFIG_CSI
41 wlan_csi_config_params_t g_csi_params;
42 #endif
43
44 #if CONFIG_NET_MONITOR
45 wlan_net_monitor_t g_net_monitor_param;
46 #endif
47
48 #if CONFIG_HOST_SLEEP
49 extern uint64_t rtc_timeout;
50 #endif
51 extern char *net_sprint_addr(sa_family_t af, const void *addr);
52 #if defined(RW610)
53 extern int wlan_send_hostcmd(const void *cmd_buf, uint32_t cmd_buf_len, void *host_resp_buf, uint32_t resp_buf_len, uint32_t *reqd_resp_len);
54 #endif
55
print_role(enum wlan_bss_role role)56 static const char *print_role(enum wlan_bss_role role)
57 {
58 if (role == WLAN_BSS_ROLE_STA)
59 {
60 return "Infra";
61 }
62 else if (role == WLAN_BSS_ROLE_UAP)
63 {
64 return "uAP";
65 }
66 else if (role == WLAN_BSS_ROLE_ANY)
67 {
68 return "any";
69 }
70 else
71 {
72 return "unknown";
73 }
74 }
75
76 #if CONFIG_WPA_SUPP_WPS
77 /** Enum that indicates type of WPS session
78 * either a push button or a PIN based session is
79 * determined by value fo this enum
80 */
81 enum wps_session_types
82 {
83 /** WPS session is not active */
84 WPS_SESSION_INACTIVE = 0xffff,
85 /** WPS Push Button session active */
86 WPS_SESSION_PBC = 0x0004,
87 /** WPS PIN session active */
88 WPS_SESSION_PIN = 0x0000,
89 };
90 #endif
91
__scan_cb(unsigned int count)92 static int __scan_cb(unsigned int count)
93 {
94 struct wlan_scan_result res;
95 unsigned int i;
96 int err;
97
98 if (count == 0U)
99 {
100 (void)PRINTF("no networks found\r\n");
101 return 0;
102 }
103
104 (void)PRINTF("%d network%s found:\r\n", count, count == 1U ? "" : "s");
105
106 for (i = 0; i < count; i++)
107 {
108 err = wlan_get_scan_result(i, &res);
109 if (err != 0)
110 {
111 (void)PRINTF("Error: can't get scan res %d\r\n", i);
112 continue;
113 }
114
115 print_mac(res.bssid);
116
117 if (res.ssid[0] != '\0')
118 {
119 (void)PRINTF(" \"%s\" %s\r\n", res.ssid, print_role(res.role));
120 }
121 else
122 {
123 (void)PRINTF(" (hidden) %s\r\n", print_role(res.role));
124 }
125 (void)PRINTF("\tmode: ");
126 #if CONFIG_11AC
127 #if CONFIG_11AX
128 if (res.dot11ax != 0U)
129 {
130 (void)PRINTF("802.11AX ");
131 }
132 else
133 #endif
134 if (res.dot11ac != 0U)
135 {
136 (void)PRINTF("802.11AC ");
137 }
138 else
139 #endif
140 if (res.dot11n != 0U)
141 {
142 (void)PRINTF("802.11N ");
143 }
144 else
145 {
146 if (res.channel <= 14)
147 {
148 (void)PRINTF("802.11BG ");
149 }
150 else
151 {
152 (void)PRINTF("802.11A ");
153 }
154 }
155 (void)PRINTF("\r\n");
156
157 (void)PRINTF("\tchannel: %d\r\n", res.channel);
158 (void)PRINTF("\trssi: -%d dBm\r\n", res.rssi);
159 (void)PRINTF("\tsecurity: ");
160 if (res.wep != 0U)
161 {
162 (void)PRINTF("WEP ");
163 }
164 if ((res.wpa != 0U) && (res.wpa2 != 0U))
165 {
166 (void)PRINTF("WPA/WPA2 Mixed ");
167 }
168 else if ((res.wpa2 != 0U) && (res.wpa3_sae != 0U))
169 {
170 (void)PRINTF("WPA2/WPA3 SAE Mixed ");
171 }
172 else
173 {
174 if (res.wpa != 0U)
175 {
176 (void)PRINTF("WPA ");
177 }
178 if (res.wpa2 != 0U)
179 {
180 (void)PRINTF("WPA2 ");
181 }
182 if (res.wpa2_sha256 != 0U)
183 {
184 (void)PRINTF("WPA2-SHA256");
185 }
186 if (res.wpa3_sae != 0U)
187 {
188 (void)PRINTF("WPA3-SAE ");
189 }
190 #if CONFIG_DRIVER_OWE
191 if (res.owe != 0U)
192 {
193 (void)PRINTF("OWE Only");
194 }
195 #endif
196 if (res.wpa2_entp != 0U)
197 {
198 (void)PRINTF("WPA2 Enterprise ");
199 }
200 if (res.wpa3_entp != 0U)
201 {
202 (void)PRINTF("WPA3 Enterprise ");
203 }
204 if (res.wpa3_1x_sha256 != 0U)
205 {
206 (void)PRINTF("WPA3 Enterprise SuiteB ");
207 }
208 if (res.wpa3_1x_sha384 != 0U)
209 {
210 (void)PRINTF("WPA3 Enterprise SuiteB-192 ");
211 }
212 }
213 #if (CONFIG_11R)
214 if (res.ft_1x != 0U)
215 {
216 (void)PRINTF("with FT_802.1x");
217 }
218 if (res.ft_psk != 0U)
219 {
220 (void)PRINTF("with FT_PSK");
221 }
222 if (res.ft_sae != 0U)
223 {
224 (void)PRINTF("with FT_SAE");
225 }
226 if (res.ft_1x_sha384 != 0U)
227 {
228 (void)PRINTF("with FT_802.1x SHA384");
229 }
230 #endif
231 if (!((res.wep != 0U) || (res.wpa != 0U) || (res.wpa2 != 0U) || (res.wpa3_sae != 0U) || (res.wpa2_entp != 0U) ||
232 (res.wpa2_sha256 != 0U) ||
233 #if CONFIG_DRIVER_OWE
234 (res.owe != 0U) ||
235 #endif
236 (res.wpa3_entp != 0U) || (res.wpa3_1x_sha256 != 0U) || (res.wpa3_1x_sha384 != 0U)))
237 {
238 (void)PRINTF("OPEN ");
239 }
240 (void)PRINTF("\r\n");
241
242 (void)PRINTF("\tWMM: %s\r\n", (res.wmm != 0U) ? "YES" : "NO");
243
244 #if CONFIG_11K
245 if (res.neighbor_report_supported == true)
246 {
247 (void)PRINTF("\t802.11K: YES\r\n");
248 }
249 #endif
250 #if CONFIG_11V
251 if (res.bss_transition_supported == true)
252 {
253 (void)PRINTF("\t802.11V: YES\r\n");
254 }
255 #endif
256 if ((res.ap_mfpc == true) && (res.ap_mfpr == true))
257 {
258 (void)PRINTF("\t802.11W: Capable, Required\r\n");
259 }
260 if ((res.ap_mfpc == true) && (res.ap_mfpr == false))
261 {
262 (void)PRINTF("\t802.11W: Capable\r\n");
263 }
264 if ((res.ap_mfpc == false) && (res.ap_mfpr == false))
265 {
266 (void)PRINTF("\t802.11W: NA\r\n");
267 }
268 #if CONFIG_WPA_SUPP_WPS
269 if (res.wps)
270 {
271 if (res.wps_session == WPS_SESSION_PBC)
272 (void)PRINTF("\tWPS: %s, Session: %s\r\n", "YES", "Push Button");
273 else if (res.wps_session == WPS_SESSION_PIN)
274 (void)PRINTF("\tWPS: %s, Session: %s\r\n", "YES", "PIN");
275 else
276 (void)PRINTF("\tWPS: %s, Session: %s\r\n", "YES", "Not active");
277 }
278 else
279 (void)PRINTF("\tWPS: %s \r\n", "NO");
280 #endif
281 #if CONFIG_DRIVER_OWE
282 if (res.trans_ssid_len != 0U)
283 {
284 (void)PRINTF("\tOWE BSSID: ");
285 print_mac(res.trans_bssid);
286 (void)PRINTF("\r\n\tOWE SSID:");
287 if (res.trans_ssid_len != 0U)
288 {
289 (void)PRINTF(" \"%s\"\r\n", res.trans_ssid);
290 }
291 }
292 #endif
293 }
294 #if CONFIG_WIFI_SMOKE_TESTS
295 PRINTF("SCAN COMPLETED !\r\n");
296 #endif
297 return 0;
298 }
299
test_wlan_thread_info(int argc,char ** argv)300 static void test_wlan_thread_info(int argc, char **argv)
301 {
302 /* TODO: implement for Zephyr */
303 }
304
305 #if CONFIG_SCHED_SWITCH_TRACE
test_wlan_sched_switch_debug(int argc,char ** argv)306 static void test_wlan_sched_switch_debug(int argc, char **argv)
307 {
308 if (strncmp(argv[1], "start", strlen("start") + 1))
309 ncp_debug_task_switch_start = 1;
310 else if (strncmp(argv[1], "stop", strlen("stop") + 1))
311 ncp_debug_task_switch_start = 0;
312 else if (strncmp(argv[1], "print", strlen("print") + 1))
313 trace_task_switch_print();
314 }
315 #endif
316
test_wlan_net_stats(int argc,char ** argv)317 static void test_wlan_net_stats(int argc, char **argv)
318 {
319 net_stat();
320 }
321
test_wlan_scan(int argc,char ** argv)322 static void test_wlan_scan(int argc, char **argv)
323 {
324 if (wlan_scan(__scan_cb) != 0)
325 {
326 (void)PRINTF("Error: scan request failed\r\n");
327 }
328 else
329 {
330 (void)PRINTF("Scan scheduled...\r\n");
331 }
332 }
333
dump_wlan_scan_opt_usage(void)334 static void dump_wlan_scan_opt_usage(void)
335 {
336 (void)PRINTF("Usage:\r\n");
337 (void)PRINTF(
338 " wlan-scan-opt ssid <ssid> bssid <bssid> "
339 #if CONFIG_SCAN_WITH_RSSIFILTER
340 "channel <channel> probes <probes> rssi_threshold <rssi_threshold>"
341 #else
342 "channel <channel> probes <probes>"
343 #endif
344 "\r\n");
345 }
346
test_wlan_scan_opt(int argc,char ** argv)347 static void test_wlan_scan_opt(int argc, char **argv)
348 {
349 wlan_scan_params_v2_t wlan_scan_param;
350 int arg = 1;
351 #if CONFIG_COMBO_SCAN
352 int num_ssid = 0;
353 #endif
354 struct
355 {
356 unsigned ssid : 1;
357 unsigned bssid : 1;
358 unsigned channel : 1;
359 unsigned probes : 1;
360 #if CONFIG_SCAN_WITH_RSSIFILTER
361 unsigned rssi_threshold : 1;
362 #endif
363 } info;
364
365 (void)memset(&info, 0, sizeof(info));
366 (void)memset(&wlan_scan_param, 0, sizeof(wlan_scan_params_v2_t));
367
368 if (argc < 3)
369 {
370 dump_wlan_scan_opt_usage();
371 (void)PRINTF("Error: invalid number of arguments\r\n");
372 return;
373 }
374 do
375 {
376 #if CONFIG_COMBO_SCAN
377 if (string_equal("ssid", argv[arg]))
378 {
379 if (num_ssid >= MAX_NUM_SSID)
380 {
381 (void)PRINTF("Error: the number of SSID is more than 2\r\n");
382 return;
383 }
384 #else
385 if ((info.ssid == 0U) && string_equal("ssid", argv[arg]))
386 {
387 #endif
388 if (strlen(argv[arg + 1]) > IEEEtypes_SSID_SIZE)
389 {
390 (void)PRINTF("Error: SSID is too long\r\n");
391 return;
392 }
393 #if CONFIG_COMBO_SCAN
394 (void)memcpy(wlan_scan_param.ssid[num_ssid], argv[arg + 1], strlen(argv[arg + 1]));
395 num_ssid++;
396 #else
397 (void)memcpy(wlan_scan_param.ssid, argv[arg + 1], strlen(argv[arg + 1]));
398 #endif
399 arg += 2;
400 info.ssid = 1;
401 }
402 else if ((info.bssid == 0U) && string_equal("bssid", argv[arg]))
403 {
404 if (get_mac(argv[arg + 1], (char *)wlan_scan_param.bssid, ':') != false)
405 {
406 (void)PRINTF(
407 "Error: invalid BSSID argument"
408 "\r\n");
409 return;
410 }
411 arg += 2;
412 info.bssid = 1;
413 }
414 else if ((info.channel == 0U) && string_equal("channel", argv[arg]))
415 {
416 if (arg + 1 >= argc ||
417 get_uint(argv[arg + 1], (unsigned int *)(void *)&wlan_scan_param.chan_list[0].chan_number,
418 strlen(argv[arg + 1])))
419 {
420 (void)PRINTF(
421 "Error: invalid channel"
422 " argument\n");
423 return;
424 }
425 wlan_scan_param.num_channels = 1;
426 wlan_scan_param.chan_list[0].scan_type = MLAN_SCAN_TYPE_ACTIVE;
427 wlan_scan_param.chan_list[0].scan_time = 120;
428 arg += 2;
429 info.channel = 1;
430 }
431 else if ((info.probes == 0U) && string_equal("probes", argv[arg]))
432 {
433 if (arg + 1 >= argc ||
434 get_uint(argv[arg + 1], (unsigned int *)(void *)&wlan_scan_param.num_probes, strlen(argv[arg + 1])))
435 {
436 (void)PRINTF(
437 "Error: invalid probes"
438 " argument\n");
439 return;
440 }
441 if (wlan_scan_param.num_probes > 4U)
442 {
443 (void)PRINTF(
444 "Error: invalid number of probes"
445 "\r\n");
446 return;
447 }
448 arg += 2;
449 info.probes = 1;
450 }
451 #if CONFIG_SCAN_WITH_RSSIFILTER
452 else if (!info.rssi_threshold && string_equal("rssi_threshold", argv[arg]))
453 {
454 if (arg + 1 >= argc)
455 {
456 (void)PRINTF(
457 "Error: invalid rssi threshold"
458 " argument\n");
459 return;
460 }
461 wlan_scan_param.rssi_threshold = atoi(argv[arg + 1]);
462 if (wlan_scan_param.rssi_threshold < -101)
463 {
464 (void)PRINTF(
465 "Error: invalid value of rssi threshold"
466 "\r\n");
467 return;
468 }
469 arg += 2;
470 info.rssi_threshold = 1;
471 }
472 #endif
473 else
474 {
475 dump_wlan_scan_opt_usage();
476 (void)PRINTF("Error: argument %d is invalid\r\n", arg);
477 return;
478 }
479 } while (arg < argc);
480
481 if ((info.ssid == 0U) && (info.bssid == 0U))
482 {
483 dump_wlan_scan_opt_usage();
484 (void)PRINTF("Error: specify at least the SSID or BSSID\r\n");
485 return;
486 }
487
488 wlan_scan_param.cb = __scan_cb;
489
490 if (wlan_scan_with_opt(wlan_scan_param) != 0)
491 {
492 (void)PRINTF("Error: scan request failed\r\n");
493 }
494 else
495 {
496 (void)PRINTF("Scan for ");
497 if (info.ssid != 0U)
498 {
499 #if CONFIG_COMBO_SCAN
500 (void)PRINTF("ssid \"%s\" ", wlan_scan_param.ssid[0]);
501 #else
502 (void)PRINTF("ssid \"%s\" ", wlan_scan_param.ssid);
503 #endif
504 }
505 if (info.bssid != 0U)
506 {
507 (void)PRINTF("bssid ");
508 print_mac((const char *)wlan_scan_param.bssid);
509 }
510 if (info.probes != 0U)
511 {
512 (void)PRINTF("with %d probes ", wlan_scan_param.num_probes);
513 #if CONFIG_SCAN_WITH_RSSIFILTER
514 wlan_set_rssi_threshold(wlan_scan_param.rssi_threshold);
515 if (info.rssi_threshold != 0U)
516 (void)PRINTF("with %d rssi_threshold ", wlan_scan_param.rssi_threshold);
517 #endif
518 }
519 (void)PRINTF("scheduled...\r\n");
520 }
521 }
522
523 static void test_wlan_ieee_ps(int argc, char **argv)
524 {
525 int choice = -1;
526 int ret = -WM_FAIL;
527 unsigned int condition = 0;
528
529 if (argc < 2)
530 {
531 (void)PRINTF("Usage: %s <0/1>\r\n", argv[0]);
532 (void)PRINTF("Error: Specify 0 to Disable or 1 to Enable\r\n");
533 return;
534 }
535
536 errno = 0;
537 choice = strtol(argv[1], NULL, 10);
538 if (errno != 0)
539 {
540 (void)PRINTF("Error during strtol:mfpc errno:%d\r\n", errno);
541 return;
542 }
543
544 if (choice == 0)
545 {
546 ret = wlan_ieeeps_off();
547 if (ret == WM_SUCCESS)
548 {
549 (void)PRINTF("Turned off IEEE Power Save mode\r\n");
550 }
551 }
552 else if (choice == 1)
553 {
554 ret = wlan_ieeeps_on(condition);
555 if (ret == WM_SUCCESS)
556 {
557 (void)PRINTF("Turned on IEEE Power Save mode\r\n");
558 }
559 else
560 {
561 (void)PRINTF("Failed to turn on IEEE Power Save mode or WNM Power Save mode is enabled\r\n");
562 }
563 }
564 else
565 {
566 (void)PRINTF("Error: Specify 0 to Disable or 1 to Enable\r\n");
567 }
568 }
569
570 static void test_wlan_set_ps_cfg(int argc, char **argv)
571 {
572 struct wlan_ieeeps_config pscfg;
573 int ret = -WM_FAIL;
574
575 if (argc < 2)
576 {
577 (void)PRINTF("Usage: %s <null_pkt_interval>\r\n", argv[0]);
578 (void)PRINTF("null_pkt_interval (0: Unchanged, -1: Disable, n: Interval in seconds)\r\n");
579 return;
580 }
581
582 (void)memset(&pscfg, 0, sizeof(pscfg));
583 pscfg.ps_null_interval = atoi(argv[1]);
584
585 ret = wlan_set_ieeeps_cfg(&pscfg);
586 if (ret == WM_SUCCESS)
587 (void)PRINTF("Set power save cfg successfully");
588 else
589 (void)PRINTF("Failed to set power save cfg, error: %d", ret);
590 }
591
592 #if (CONFIG_WNM_PS)
593 static void test_wlan_wnm_ps(int argc, char **argv)
594 {
595 int choice = -1;
596 int ret = -WM_FAIL;
597 unsigned int condition = 0;
598 unsigned int wnm_interval = 0;
599
600 if (argc < 2)
601 {
602 (void)PRINTF("Usage: %s <0/1>\r\n", argv[0]);
603 (void)PRINTF("Error: Specify 0 to Disable or 1 to Enable\r\n");
604 (void)PRINTF("If enable, please specify sleep_interval\r\n");
605 (void)PRINTF("Example:\r\n");
606 (void)PRINTF(" wlan-wnm-ps 1 5\r\n");
607 return;
608 }
609
610 choice = atoi(argv[1]);
611
612 if (choice == 0)
613 {
614 ret = wlan_wnmps_off();
615 if (ret == WM_SUCCESS)
616 (void)PRINTF("Turned off WNM Power Save mode\r\n");
617 else
618 (void)PRINTF("Failed to turn off WNM Power Save mode\r\n");
619 }
620 else if (choice == 1)
621 {
622 if (get_uint(argv[2], &wnm_interval, strlen(argv[2])) == 0)
623 {
624 ret = wlan_wnmps_on(condition, (t_u16)wnm_interval);
625 }
626 else
627 {
628 (void)PRINTF("Error: please specify sleep_interval\r\n");
629 return;
630 }
631
632 if (ret == WM_SUCCESS)
633 (void)PRINTF("Turned on WNM Power Save mode\r\n");
634 else
635 (void)PRINTF("Failed to turn on WNM Power Save mode or IEEE Power Save mode is enabled\r\n");
636 }
637 else
638 {
639 (void)PRINTF("Error: Specify 0 to Disable or 1 to Enable\r\n");
640 }
641 }
642 #endif
643
644 static void test_wlan_deep_sleep_ps(int argc, char **argv)
645 {
646 int choice = -1;
647 int ret = -WM_FAIL;
648
649 if (argc < 2)
650 {
651 (void)PRINTF("Usage: %s <0/1>\r\n", argv[0]);
652 (void)PRINTF("Error: Specify 0 to Disable or 1 to Enable\r\n");
653 return;
654 }
655
656 errno = 0;
657 choice = strtol(argv[1], NULL, 10);
658 if (errno != 0)
659 {
660 (void)PRINTF("Error during strtol:deep_sleep_ps errno:%d\r\n", errno);
661 return;
662 }
663
664 if (choice == 0)
665 {
666 ret = wlan_deepsleepps_off();
667 if (ret == WM_SUCCESS)
668 {
669 (void)PRINTF("Turned off Deep Sleep Power Save mode\r\n");
670 }
671 else
672 {
673 (void)PRINTF("Failed to turn off Deep Sleep Power Save mode\r\n");
674 }
675 }
676 else if (choice == 1)
677 {
678 ret = wlan_deepsleepps_on();
679 if (ret == WM_SUCCESS)
680 {
681 (void)PRINTF("Turned on Deep Sleep Power Save mode\r\n");
682 }
683 else
684 {
685 (void)PRINTF("Failed to turn on Deep Sleep Power Save mode\r\n");
686 }
687 }
688 else
689 {
690 (void)PRINTF("Error: Specify 0 to Disable or 1 to Enable\r\n");
691 }
692 }
693 #if CONFIG_WIFI_TX_PER_TRACK
694 static void dump_wlan_tx_pert_usage(void)
695 {
696 (void)PRINTF("Usage:\r\n");
697 (void)PRINTF(
698 " wlan-tx-pert <0/1> <STA/AP> <p:tx_pert_check_period> "
699 "<r:tx_pert_check_ratio> <n:tx_pert_check_num>"
700 "\r\n");
701 (void)PRINTF("Options:\r\n");
702 (void)PRINTF(" <0/1>: Disable/enable Tx Pert tracking.\r\n");
703 (void)PRINTF(" <STA/UAP>: User needs to indicate which interface this tracking for.\r\n");
704 (void)PRINTF(" <p>: Tx Pert check period. Unit is second.\r\n");
705 (void)PRINTF(
706 " <r>: Tx Pert ratio threshold (unit 10 percent). (Fail TX packet)/(Total TX packets). The default value is "
707 "5.\r\n");
708 (void)PRINTF(
709 " <n>: A watermark of check number (default 5). Fw will start tracking Tx Pert after sending n "
710 "packets.\r\n");
711 (void)PRINTF("Example:\r\n");
712 (void)PRINTF(" wlan-tx-pert 1 UAP 5 3 5\r\n");
713 (void)PRINTF("Note:\r\n");
714 (void)PRINTF(" Please verify by iperf or ping\r\n");
715 (void)PRINTF(" When the traffic quality is good enough, it will not be triggered\r\n");
716 }
717
718 static void test_wlan_tx_pert(int argc, char **argv)
719 {
720 struct wlan_tx_pert_info tx_pert;
721 mlan_bss_type bss_type = MLAN_BSS_TYPE_STA;
722
723 if (argc < 2)
724 {
725 dump_wlan_tx_pert_usage();
726 (void)PRINTF("Error: invalid number of arguments\r\n");
727 return;
728 }
729 (void)memset(&tx_pert, 0, sizeof(tx_pert));
730 tx_pert.tx_pert_check = atoi(argv[1]);
731 if (tx_pert.tx_pert_check == 1 && argc < 6)
732 {
733 (void)PRINTF("Error: invalid number of arguments.\r\n");
734 (void)PRINTF(
735 "Need specify bss_type tx_pert_chk_prd, tx_perf_chk_ratio and tx_pert_chk_num"
736 "\r\n");
737 return;
738 }
739 if (string_equal("STA", argv[2]))
740 bss_type = MLAN_BSS_TYPE_STA;
741 else if (string_equal("UAP", argv[2]))
742 bss_type = MLAN_BSS_TYPE_UAP;
743 if (tx_pert.tx_pert_check == 1)
744 {
745 tx_pert.tx_pert_check_peroid = (t_u8)atoi(argv[3]);
746 tx_pert.tx_pert_check_ratio = (t_u8)atoi(argv[4]);
747 tx_pert.tx_pert_check_num = atoi(argv[5]);
748 }
749 wlan_set_tx_pert(&tx_pert, bss_type);
750 }
751 #endif
752
753 #if CONFIG_TX_RX_HISTOGRAM
754 static void dump_wlan_txrx_histogram_usage()
755 {
756 (void)PRINTF("Usage:\r\n");
757 (void)PRINTF(" wlan_txrx_histogram <action> <enable>\r\n");
758 (void)PRINTF(" <enable> : 0 - disable TX/RX statistics\r\n");
759 (void)PRINTF(" 1 - enable TX/RX statistics\r\n");
760 (void)PRINTF(" 2 - get TX/RX statistics\r\n");
761 (void)PRINTF(" <action> : 1 - enable/disable/get TX statistics\r\n");
762 (void)PRINTF(" 2 - enable/disable/get RX statistics\r\n");
763 (void)PRINTF(" 3 - enable/disable/get TX and RX statistics\r\n");
764 (void)PRINTF("Note:\r\n");
765 (void)PRINTF(" When enable is 0 or 1, the action parameter should not be entered\r\n");
766 (void)PRINTF("Example:\r\n");
767 (void)PRINTF(" wlan_txrx_histogram 2 3\r\n");
768 }
769
770 static void test_wlan_txrx_histogram(int argc, char **argv)
771 {
772 struct wlan_txrx_histogram_info txrx_histogram;
773 t_u8 *buf = NULL;
774
775 tx_pkt_ht_rate_info *tx_ht_info;
776 tx_pkt_vht_rate_info *tx_vht_info;
777 tx_pkt_he_rate_info *tx_he_info;
778 tx_pkt_rate_info *tx_info;
779 rx_pkt_ht_rate_info *rx_ht_info;
780 rx_pkt_vht_rate_info *rx_vht_info;
781 rx_pkt_he_rate_info *rx_he_info;
782 rx_pkt_rate_info *rx_info;
783
784 t_u8 *pos = NULL;
785 t_u16 resp_value_size = 0;
786 int i = 0;
787 t_u16 buf_size = 0;
788
789 if (argc < 2)
790 {
791 (void)PRINTF("Error: invalid number of arguments\r\n");
792 dump_wlan_txrx_histogram_usage();
793 return;
794 }
795
796 (void)memset(&txrx_histogram, 0, sizeof(txrx_histogram));
797 txrx_histogram.enable = atoi(argv[1]);
798 if (argc == 2)
799 {
800 txrx_histogram.action = 0;
801 }
802 else
803 {
804 txrx_histogram.action = atoi(argv[2]);
805 }
806
807 if ((txrx_histogram.enable > 2) || (txrx_histogram.action > 3))
808 {
809 (void)PRINTF("Error: invalid arguments.\r\n");
810 dump_wlan_txrx_histogram_usage();
811 return;
812 }
813 if ((txrx_histogram.enable == 0 || txrx_histogram.enable == 1) && (txrx_histogram.action != 0))
814 {
815 (void)PRINTF("Error: invalid arguments.\r\n");
816 dump_wlan_txrx_histogram_usage();
817 return;
818 }
819
820 if (txrx_histogram.enable & GET_TX_RX_HISTOGRAM)
821 {
822 if (txrx_histogram.action == FLAG_TX_HISTOGRAM)
823 {
824 buf_size = sizeof(resp_value_size) + sizeof(tx_pkt_ht_rate_info) + sizeof(tx_pkt_vht_rate_info) +
825 sizeof(tx_pkt_he_rate_info) + sizeof(tx_pkt_rate_info);
826 }
827 else if (txrx_histogram.action == FLAG_RX_HISTOGRAM)
828 {
829 buf_size = sizeof(resp_value_size) + sizeof(rx_pkt_ht_rate_info) + sizeof(rx_pkt_vht_rate_info) +
830 sizeof(rx_pkt_he_rate_info) + sizeof(rx_pkt_rate_info);
831 }
832 else if ((txrx_histogram.action & FLAG_TX_HISTOGRAM) && (txrx_histogram.action & FLAG_RX_HISTOGRAM))
833 {
834 buf_size = sizeof(resp_value_size) + sizeof(tx_pkt_ht_rate_info) + sizeof(tx_pkt_vht_rate_info) +
835 sizeof(tx_pkt_he_rate_info) + sizeof(tx_pkt_rate_info) + sizeof(rx_pkt_ht_rate_info) +
836 sizeof(rx_pkt_vht_rate_info) + sizeof(rx_pkt_he_rate_info) + sizeof(rx_pkt_rate_info);
837 }
838 }
839 if (buf_size > 0)
840 {
841 buf = OSA_MemoryAllocate(buf_size);
842 if (!buf)
843 {
844 PRINTF("test_wlan_txrx_histogram buf allocate memory failed\r\n");
845 return;
846 }
847 (void)memset(buf, 0, sizeof(buf_size));
848 (void)memcpy(buf, &buf_size, sizeof(buf_size));
849 }
850
851 wlan_set_txrx_histogram(&txrx_histogram, buf);
852
853 if (buf == NULL)
854 {
855 return;
856 }
857
858 /*Make the pos pointer points to the size*/
859 pos = (t_u8 *)buf;
860 memcpy(&resp_value_size, pos, sizeof(resp_value_size));
861 /*Make the pos pointer points to the data replied by fw*/
862 pos += sizeof(resp_value_size);
863
864 if (txrx_histogram.enable & GET_TX_RX_HISTOGRAM)
865 {
866 if (txrx_histogram.action & FLAG_TX_HISTOGRAM)
867 {
868 PRINTF("The TX histogram statistic:\n");
869 PRINTF("============================================\n");
870 tx_ht_info = (tx_pkt_ht_rate_info *)pos;
871 for (i = 0; i < 16; i++)
872 {
873 PRINTF("htmcs_txcnt[%d] = %u\n", i, tx_ht_info->htmcs_txcnt[i]);
874 PRINTF("htsgi_txcnt[%d] = %u\n", i, tx_ht_info->htsgi_txcnt[i]);
875 PRINTF("htstbcrate_txcnt[%d] = %u\n", i, tx_ht_info->htstbcrate_txcnt[i]);
876 }
877 pos += sizeof(tx_pkt_ht_rate_info);
878 tx_vht_info = (tx_pkt_vht_rate_info *)pos;
879 for (i = 0; i < 10; i++)
880 {
881 PRINTF("vhtmcs_txcnt[%d] = %u\n", i, tx_vht_info->vhtmcs_txcnt[i]);
882 PRINTF("vhtsgi_txcnt[%d] = %u\n", i, tx_vht_info->vhtsgi_txcnt[i]);
883 PRINTF("vhtstbcrate_txcnt[%d] = %u\n", i, tx_vht_info->vhtstbcrate_txcnt[i]);
884 }
885 pos += sizeof(tx_pkt_vht_rate_info);
886 if (resp_value_size == (sizeof(tx_pkt_ht_rate_info) + sizeof(tx_pkt_vht_rate_info) +
887 sizeof(tx_pkt_he_rate_info) + sizeof(tx_pkt_rate_info)) ||
888 resp_value_size ==
889 (sizeof(tx_pkt_ht_rate_info) + sizeof(tx_pkt_vht_rate_info) + sizeof(tx_pkt_he_rate_info) +
890 sizeof(tx_pkt_rate_info) + sizeof(rx_pkt_ht_rate_info) + sizeof(rx_pkt_vht_rate_info) +
891 sizeof(rx_pkt_he_rate_info) + sizeof(rx_pkt_rate_info)))
892 {
893 tx_he_info = (tx_pkt_he_rate_info *)pos;
894 for (i = 0; i < 12; i++)
895 {
896 PRINTF("hemcs_txcnt[%d] = %u\n", i, tx_he_info->hemcs_txcnt[i]);
897 PRINTF("hestbcrate_txcnt[%d] = %u\n", i, tx_he_info->hestbcrate_txcnt[i]);
898 }
899 pos += sizeof(tx_pkt_he_rate_info);
900 }
901 tx_info = (tx_pkt_rate_info *)pos;
902 for (i = 0; i < 2; i++)
903 PRINTF("nss_txcnt[%d] = %u\n", i, tx_info->nss_txcnt[i]);
904 for (i = 0; i < 3; i++)
905 PRINTF("bandwidth_txcnt[%d] = %u\n", i, tx_info->bandwidth_txcnt[i]);
906 for (i = 0; i < 4; i++)
907 PRINTF("preamble_txcnt[%d] = %u\n", i, tx_info->preamble_txcnt[i]);
908 PRINTF("ldpc_txcnt = %u\n", tx_info->ldpc_txcnt);
909 PRINTF("rts_txcnt = %u\n", tx_info->rts_txcnt);
910 PRINTF("ack_RSSI = %d\n\n", tx_info->ack_RSSI);
911 pos += sizeof(tx_pkt_rate_info);
912 }
913 if (txrx_histogram.action & FLAG_RX_HISTOGRAM)
914 {
915 PRINTF("The RX histogram statistic:\n");
916 PRINTF("============================================\n");
917 rx_ht_info = (rx_pkt_ht_rate_info *)pos;
918 for (i = 0; i < 16; i++)
919 {
920 PRINTF("htmcs_rxcnt[%d] = %u\n", i, rx_ht_info->htmcs_rxcnt[i]);
921 PRINTF("htsgi_rxcnt[%d] = %u\n", i, rx_ht_info->htsgi_rxcnt[i]);
922 PRINTF("htstbcrate_rxcnt[%d] = %u\n", i, rx_ht_info->htstbcrate_rxcnt[i]);
923 }
924 pos += sizeof(rx_pkt_ht_rate_info);
925 rx_vht_info = (rx_pkt_vht_rate_info *)pos;
926 for (i = 0; i < 10; i++)
927 {
928 PRINTF("vhtmcs_rxcnt[%d] = %u\n", i, rx_vht_info->vhtmcs_rxcnt[i]);
929 PRINTF("vhtsgi_rxcnt[%d] = %u\n", i, rx_vht_info->vhtsgi_rxcnt[i]);
930 PRINTF("vhtstbcrate_rxcnt[%d] = %u\n", i, rx_vht_info->vhtstbcrate_rxcnt[i]);
931 }
932 pos += sizeof(rx_pkt_vht_rate_info);
933 if (resp_value_size == (sizeof(rx_pkt_ht_rate_info) + sizeof(rx_pkt_vht_rate_info) +
934 sizeof(rx_pkt_he_rate_info) + sizeof(rx_pkt_rate_info)) ||
935 resp_value_size ==
936 (sizeof(tx_pkt_ht_rate_info) + sizeof(tx_pkt_vht_rate_info) + sizeof(tx_pkt_he_rate_info) +
937 sizeof(tx_pkt_rate_info) + sizeof(rx_pkt_ht_rate_info) + sizeof(rx_pkt_vht_rate_info) +
938 sizeof(rx_pkt_he_rate_info) + sizeof(rx_pkt_rate_info)))
939 {
940 rx_he_info = (rx_pkt_he_rate_info *)pos;
941 for (i = 0; i < 12; i++)
942 {
943 PRINTF("hemcs_rxcnt[%d] = %u\n", i, rx_he_info->hemcs_rxcnt[i]);
944 PRINTF("hestbcrate_rxcnt[%d] = %u\n", i, rx_he_info->hestbcrate_rxcnt[i]);
945 }
946 pos += sizeof(rx_pkt_he_rate_info);
947 }
948 rx_info = (rx_pkt_rate_info *)pos;
949 for (i = 0; i < 2; i++)
950 PRINTF("nss_rxcnt[%d] = %u\n", i, rx_info->nss_rxcnt[i]);
951 PRINTF("nsts_rxcnt = %u\n", rx_info->nsts_rxcnt);
952 for (i = 0; i < 3; i++)
953 PRINTF("bandwidth_rxcnt[%d] = %u\n", i, rx_info->bandwidth_rxcnt[i]);
954 for (i = 0; i < 6; i++)
955 PRINTF("preamble_rxcnt[%d] = %u\n", i, rx_info->preamble_rxcnt[i]);
956 for (i = 0; i < 2; i++)
957 PRINTF("ldpc_txbfcnt[%d] = %u\n", i, rx_info->ldpc_txbfcnt[i]);
958 for (i = 0; i < 2; i++)
959 PRINTF("rssi_value[%d] = %d\n", i, rx_info->rssi_value[i]);
960 for (i = 0; i < 4; i++)
961 PRINTF("rssi_chain0[%d] = %d\n", i, rx_info->rssi_chain0[i]);
962 for (i = 0; i < 4; i++)
963 PRINTF("rssi_chain1[%d] = %d\n", i, rx_info->rssi_chain1[i]);
964 PRINTF("\n");
965 }
966 }
967 else if (txrx_histogram.enable & ENABLE_TX_RX_HISTOGRAM)
968 PRINTF("Enable the TX and RX histogram statistic\n");
969 else
970 {
971 PRINTF("Disable the TX and RX histogram statistic\n");
972 }
973 if (buf)
974 {
975 OSA_MemoryFree(buf);
976 }
977 }
978 #endif
979
980 #if CONFIG_ROAMING
981 static void dump_wlan_roaming_usage(void)
982 {
983 (void)PRINTF("Usage:\r\n");
984 (void)PRINTF(
985 " wlan-roaming <0/1> <rssi_threshold>"
986 "\r\n");
987 (void)PRINTF("Example:\r\n");
988 (void)PRINTF(" wlan-roaming 1 40\r\n");
989 }
990
991 static void test_wlan_roaming(int argc, char **argv)
992 {
993 int enable = 0;
994 uint8_t rssi_low_threshold = 0;
995
996 if ((argc != 2) && (argc != 3))
997 {
998 dump_wlan_roaming_usage();
999 (void)PRINTF("Error: invalid number of arguments\r\n");
1000 return;
1001 }
1002
1003 errno = 0;
1004 enable = (int)strtol(argv[1], NULL, 10);
1005 if (errno != 0)
1006 {
1007 (void)PRINTF("Error during strtol:wlan roaming errno:%d\r\n", errno);
1008 return;
1009 }
1010
1011 if (argc == 3)
1012 {
1013 errno = 0;
1014 rssi_low_threshold = (uint8_t)strtol(argv[2], NULL, 10);
1015 if (errno != 0)
1016 {
1017 (void)PRINTF("Error during strtol:rssi_threshold errno:%d\r\n", errno);
1018 return;
1019 }
1020 }
1021
1022 wlan_set_roaming(enable, rssi_low_threshold);
1023 return;
1024 }
1025 #endif
1026
1027 #if CONFIG_WIFI_RTS_THRESHOLD
1028 static void test_wlan_set_rts(int argc, char **argv)
1029 {
1030 int rthr;
1031 int ret;
1032 mlan_bss_type bss_type = MLAN_BSS_TYPE_STA;
1033
1034 if (argc != 3)
1035 {
1036 (void)PRINTF("Usage: %s <sta/uap> <rts threshold>\r\n", argv[0]);
1037 return;
1038 }
1039 if (string_equal("sta", argv[1]))
1040 bss_type = MLAN_BSS_TYPE_STA;
1041 else if (string_equal("uap", argv[1]))
1042 bss_type = MLAN_BSS_TYPE_UAP;
1043 else
1044 {
1045 (void)PRINTF("Usage: %s <sta/uap> <rts threshold>\r\n", argv[0]);
1046 return;
1047 }
1048
1049 rthr = atoi(argv[2]);
1050
1051 if (bss_type == MLAN_BSS_TYPE_STA)
1052 ret = wlan_set_rts(rthr);
1053 else
1054 ret = wlan_set_uap_rts(rthr);
1055
1056 if (ret != WM_SUCCESS)
1057 {
1058 (void)PRINTF("Failed to set rts threshold\r\n");
1059 }
1060 }
1061 #endif
1062
1063 #if CONFIG_WIFI_FRAG_THRESHOLD
1064 static void test_wlan_set_frag(int argc, char **argv)
1065 {
1066 int frag;
1067 int ret;
1068 mlan_bss_type bss_type = MLAN_BSS_TYPE_STA;
1069
1070 if (argc != 3)
1071 {
1072 (void)PRINTF("Usage: %s <sta/uap> <fragment threshold>\r\n", argv[0]);
1073 return;
1074 }
1075
1076 if (string_equal("sta", argv[1]))
1077 bss_type = MLAN_BSS_TYPE_STA;
1078 else if (string_equal("uap", argv[1]))
1079 bss_type = MLAN_BSS_TYPE_UAP;
1080 else
1081 {
1082 (void)PRINTF("Usage: %s <sta/uap> <fragment threshold>\r\n", argv[0]);
1083 return;
1084 }
1085
1086 frag = atoi(argv[2]);
1087
1088 if (bss_type == MLAN_BSS_TYPE_STA)
1089 ret = wlan_set_frag(frag);
1090 else
1091 ret = wlan_set_uap_frag(frag);
1092
1093 if (ret != WM_SUCCESS)
1094 {
1095 (void)PRINTF("Failed to set fragment threshold\r\n");
1096 }
1097 }
1098 #endif
1099
1100 #if (CONFIG_11MC) || (CONFIG_11AZ)
1101 static void dump_wlan_ftm_ctrl_usage()
1102 {
1103 (void)PRINTF("Usage:\r\n");
1104 (void)PRINTF("wlan-ftm-ctrl <action> loop_cnt <count> channel <channel> mac <peer_mac>\r\n");
1105 (void)PRINTF("action: 1 start 2: stop \r\n");
1106 (void)PRINTF("loop_cnt: number of ftm sessions to run repeatedly (default:1, 0:non-stop, n:times>)\r\n");
1107 (void)PRINTF("channel: Channel on which FTM must be started\r\n");
1108 (void)PRINTF("mac: Mac address of the peer with whom FTM session is required\r\n");
1109 (void)PRINTF("Example:\r\n");
1110 (void)PRINTF("Start ftm:\r\n");
1111 (void)PRINTF("wlan-ftm-ctrl 1 loop_cnt 2 channel 36 mac 00:50:43:20:bc:44\r\n");
1112 (void)PRINTF("Stop ftm:\r\n");
1113 (void)PRINTF("wlan-ftm-ctrl 2\r\n");
1114 }
1115 static void test_wlan_ftm_ctrl(int argc, char **argv)
1116 {
1117 unsigned action, loop_cnt, channel;
1118 int arg = 2;
1119 t_u8 peer_mac[MLAN_MAC_ADDR_LENGTH];
1120 struct
1121 {
1122 unsigned loop_cnt : 1;
1123 unsigned channel : 1;
1124 unsigned mac : 1;
1125 } info;
1126
1127 (void)memset(&info, 0, sizeof(info));
1128
1129 if (argc < 2 || argc > 8)
1130 {
1131 (void)PRINTF("Error: invalid number of arguments\r\n");
1132 dump_wlan_ftm_ctrl_usage();
1133 return;
1134 }
1135
1136 action = a2hex_or_atoi(argv[1]);
1137 if (action != 1 && action != 2)
1138 {
1139 dump_wlan_ftm_ctrl_usage();
1140 return;
1141 }
1142
1143 if (action == 2)
1144 goto done;
1145
1146 do
1147 {
1148 if (!info.loop_cnt && string_equal("loop_cnt", argv[arg]))
1149 {
1150 if (get_uint(argv[arg + 1], &loop_cnt, strlen(argv[arg + 1])))
1151 {
1152 (void)PRINTF("Error: invalid loop_cnt argument\r\n");
1153 dump_wlan_ftm_ctrl_usage();
1154 return;
1155 }
1156 arg += 2;
1157 info.loop_cnt = 1;
1158 }
1159 else if (!info.channel && string_equal("channel", argv[arg]))
1160 {
1161 if (get_uint(argv[arg + 1], &channel, strlen(argv[arg + 1])))
1162 {
1163 (void)PRINTF("Error: invalid channel argument\r\n");
1164 dump_wlan_ftm_ctrl_usage();
1165 return;
1166 }
1167 arg += 2;
1168 info.channel = 1;
1169 }
1170 else if (!info.mac && string_equal("mac", argv[arg]))
1171 {
1172 if (get_mac(argv[arg + 1], (char *)peer_mac, ':'))
1173 {
1174 (void)PRINTF("Error: invalid MAC argument\r\n");
1175 dump_wlan_ftm_ctrl_usage();
1176 return;
1177 }
1178 arg += 2;
1179 info.mac = 1;
1180 }
1181 else
1182 {
1183 (void)PRINTF("Error: invalid argument\r\n");
1184 dump_wlan_ftm_ctrl_usage();
1185 return;
1186 }
1187 } while (arg < argc);
1188 done:
1189 wlan_ftm_start_stop(action, loop_cnt, peer_mac, channel);
1190 }
1191
1192 static void dump_wlan_11mc_nego_cfg()
1193 {
1194 (void)PRINTF("Usage:\r\n");
1195 (void)PRINTF(
1196 "wlan-11mc-nego-cfg burst_dur <burst_dur> min_delta <min_delta> asap <asap>"
1197 " ftm_per_burst <ftm_per_burst> BW <bw> burst_period <burst_period>\r\n");
1198
1199 (void)PRINTF("burst_dur: 2 or 11\r\n");
1200 (void)PRINTF("min_delta: 1 to 63\r\n");
1201 (void)PRINTF("asap: 0 or 1\r\n");
1202 (void)PRINTF("ftm_per_burst: 2 to 10\r\n");
1203 (void)PRINTF("BW: 9 to 13\r\n");
1204 (void)PRINTF("burst_period: 1 to 10\r\n");
1205 (void)PRINTF(
1206 "Example:\r\n"
1207 "wlan-11mc-nego-cfg burst_dur 11 min_delta 60 asap 1 ftm_per_burst 5 BW 13 burst_period 10");
1208 }
1209
1210 static void dump_wlan_civ_cfg()
1211 {
1212 (void)PRINTF("Usage:\r\n");
1213 (void)PRINTF(
1214 "wlan-civ-cfg civ_req <civ_req> loc_type <loc_type> country_code <country_code>"
1215 " addr_type <addr_type>\r\n");
1216
1217 (void)PRINTF("civ_req: 0 or 1\r\n");
1218 (void)PRINTF("loc_type: 1\r\n");
1219 (void)PRINTF("country_code: 0 for USA\r\n");
1220 (void)PRINTF("addr_type: 22\r\n");
1221 (void)PRINTF(
1222 "Example:\r\n"
1223 "wlan-civ-cfg civ_req 1 loc_type 1 country_code 0 addr_type 22");
1224 }
1225
1226 static void dump_wlan_loc_cfg()
1227 {
1228 (void)PRINTF("Usage:\r\n");
1229 (void)PRINTF(
1230 "wlan-loc-cfg lci_req <lci request> latit <latitude> longi <longitude> altit <altitude>"
1231 " lat_uncert <latitude uncertainity> lon_uncert <longitude uncertainity> alt_uncert <altitude "
1232 "uncertainity>\r\n");
1233
1234 (void)PRINTF("lci_req: 0 or 1\r\n");
1235 (void)PRINTF("latitude: -180.0 to 180.0\r\n");
1236 (void)PRINTF("longitude: -180.0 to 180.0\r\n");
1237 (void)PRINTF("altitude: -180.0 to 180.0\r\n");
1238 (void)PRINTF("latitude uncertainity: 0 to 255\r\n");
1239 (void)PRINTF("longitude uncertainity: 0 to 255\r\n");
1240 (void)PRINTF("altitude uncertainity: 0 to 255\r\n");
1241 (void)PRINTF(
1242 "Example:\r\n"
1243 "wlan-loc-cfg lci_req 1 latit -111.111 longi 222.222 altit 33.333 lat_uncert 1 lon_uncert 2 alt_uncert 3");
1244 }
1245
1246 static void dump_wlan_11az_rang_cfg()
1247 {
1248 (void)PRINTF("Usage:\r\n");
1249 (void)PRINTF(
1250 "wlan-11az-rang-cfg <protocol> format_bw <format_bw> num_measurements <num_measurements>"
1251 " measurement_freq <measurement_freq> i2r_sts <i2r_sts> r2i_sts <r2i_sts> i2r_lmr <i2r_lmr>\r\n");
1252
1253 (void)PRINTF("protocol: 0 or 1\r\n");
1254 (void)PRINTF("format_bw: 0 to 2\r\n");
1255 (void)PRINTF("num_measurements: 1 to 10\r\n");
1256 (void)PRINTF("measurement_freq: 1 to 10\r\n");
1257 (void)PRINTF("i2r_sts: 0/1 - Num of antennas: 0=>1 antenna and 1=>2 antennas\r\n");
1258 (void)PRINTF("r2i_sts: 0/1 - Num of antennas: 0=>1 antenna and 1=>2 antennas\r\n");
1259 (void)PRINTF("i2r_lmr: 0 never, 1 always, 2 up to RSTA\r\n");
1260 (void)PRINTF(
1261 "Example:\r\n"
1262 "wlan-11az-rang-cfg 1 format_bw 2 num_measurements 5 measurement_freq 4 i2r_sts 0 r2i_sts 0 i2r_lmr 0\r\n");
1263 }
1264
1265 static void test_wlan_loc_cfg(int argc, char **argv)
1266 {
1267 unsigned lci_req, lati_uncertanity, longi_uncertanity, alti_uncertanity;
1268 double latitude, longitude, altitude;
1269 location_cfg_info_t lci;
1270 int arg = 1;
1271 if (argc != 15)
1272 {
1273 (void)PRINTF("Error: invalid number of arguments\r\n");
1274 dump_wlan_loc_cfg();
1275 return;
1276 }
1277
1278 if (argc >= 2)
1279 {
1280 lci_req = 0;
1281 latitude = LCI_LATITIUDE;
1282 longitude = LCI_LONGITUDE;
1283 altitude = LCI_ALTITUDE;
1284 lati_uncertanity = LCI_LATITUDE_UNCERTAINITY;
1285 longi_uncertanity = LCI_LONGITUDE_UNCERTAINITY;
1286 alti_uncertanity = LCI_ALTITUDE_UNCERTAINITY;
1287 }
1288
1289 while (arg < argc)
1290 {
1291 if (string_equal("lci_req", argv[arg]))
1292 {
1293 if (get_uint(argv[arg + 1], &lci_req, strlen(argv[arg + 1])))
1294 {
1295 (void)PRINTF("Error: invalid number of LCI require argument\r\n");
1296 dump_wlan_loc_cfg();
1297 return;
1298 }
1299 }
1300 else if (string_equal("latit", argv[arg]))
1301 {
1302 latitude = strtod(argv[arg + 1], NULL);
1303 if (!latitude)
1304 {
1305 (void)PRINTF("Error: invalid latitude argument\r\n");
1306 dump_wlan_loc_cfg();
1307 return;
1308 }
1309 }
1310 else if (string_equal("longi", argv[arg]))
1311 {
1312 longitude = strtod(argv[arg + 1], NULL);
1313 if (!longitude)
1314 {
1315 (void)PRINTF("Error: invalid longitude argument\r\n");
1316 dump_wlan_loc_cfg();
1317 return;
1318 }
1319 }
1320 else if (string_equal("altit", argv[arg]))
1321 {
1322 altitude = strtod(argv[arg + 1], NULL);
1323 if (!latitude)
1324 {
1325 (void)PRINTF("Error: invalid latitude argument\r\n");
1326 dump_wlan_loc_cfg();
1327 return;
1328 }
1329 }
1330 else if (string_equal("lat_uncert", argv[arg]))
1331 {
1332 if (get_uint(argv[arg + 1], &lati_uncertanity, strlen(argv[arg + 1])))
1333 {
1334 (void)PRINTF("Error: invalid latitude uncertanity argument\r\n");
1335 dump_wlan_loc_cfg();
1336 return;
1337 }
1338 }
1339 else if (string_equal("lon_uncert", argv[arg]))
1340 {
1341 if (get_uint(argv[arg + 1], &longi_uncertanity, strlen(argv[arg + 1])))
1342 {
1343 (void)PRINTF("Error: invalid longitude uncertanity argument\r\n");
1344 dump_wlan_loc_cfg();
1345 return;
1346 }
1347 }
1348 else if (string_equal("alt_uncert", argv[arg]))
1349 {
1350 if (get_uint(argv[arg + 1], &alti_uncertanity, strlen(argv[arg + 1])))
1351 {
1352 (void)PRINTF("Error: invalid altitude uncertanity argument\r\n");
1353 dump_wlan_loc_cfg();
1354 return;
1355 }
1356 }
1357 else
1358 {
1359 (void)PRINTF("Error: invalid [%s] argument\r\n", argv[arg]);
1360 dump_wlan_loc_cfg();
1361 return;
1362 }
1363 arg += 2;
1364 }
1365
1366 lci.lci_req = lci_req;
1367 lci.longitude = longitude;
1368 lci.latitude = latitude;
1369 lci.altitude = altitude;
1370 lci.lat_unc = lati_uncertanity;
1371 lci.long_unc = longi_uncertanity;
1372 lci.alt_unc = alti_uncertanity;
1373
1374 wlan_ftm_location_cfg(&lci);
1375 return;
1376 }
1377
1378 static void test_wlan_civ_cfg(int argc, char **argv)
1379 {
1380 unsigned civ_req, loc_type, addr_type, addr_len, country_code;
1381 location_civic_rep_t lcr;
1382 int arg = 1;
1383 char *civ_addr = CIVIC_ADDRESS;
1384 if (argc != 9)
1385 {
1386 (void)PRINTF("Error: invalid number of arguments\r\n");
1387 dump_wlan_civ_cfg();
1388 return;
1389 }
1390
1391 civ_req = 0;
1392 loc_type = CIVIC_LOCATION_TYPE;
1393 addr_type = CIVIC_ADDRESS_TYPE;
1394 country_code = CIVIC_COUNTRY_CODE;
1395
1396 while (arg < argc)
1397 {
1398 if (string_equal("civ_req", argv[arg]))
1399 {
1400 if (get_uint(argv[arg + 1], &civ_req, strlen(argv[arg + 1])))
1401 {
1402 (void)PRINTF("Error: invalid number of civic require argument\r\n");
1403 dump_wlan_civ_cfg();
1404 return;
1405 }
1406 }
1407 else if (string_equal("loc_type", argv[arg]))
1408 {
1409 if (get_uint(argv[arg + 1], &loc_type, strlen(argv[arg + 1])))
1410 {
1411 (void)PRINTF("Error: invalid location type argument\r\n");
1412 dump_wlan_civ_cfg();
1413 return;
1414 }
1415 }
1416 else if (string_equal("addr_type", argv[arg]))
1417 {
1418 if (get_uint(argv[arg + 1], &addr_type, strlen(argv[arg + 1])))
1419 {
1420 (void)PRINTF("Error: invalid address type argument\r\n");
1421 dump_wlan_civ_cfg();
1422 return;
1423 }
1424 }
1425 else if (string_equal("country_code", argv[arg]))
1426 {
1427 if (get_uint(argv[arg + 1], &country_code, strlen(argv[arg + 1])))
1428 {
1429 (void)PRINTF("Error: invalid address length argument\r\n");
1430 dump_wlan_civ_cfg();
1431 return;
1432 }
1433 }
1434 else
1435 {
1436 (void)PRINTF("Error: invalid [%s] argument\r\n", argv[arg]);
1437 dump_wlan_civ_cfg();
1438 return;
1439 }
1440 arg += 2;
1441 }
1442
1443 lcr.civic_req = civ_req;
1444 lcr.civic_location_type = loc_type;
1445 lcr.civic_address_type = addr_type;
1446 lcr.country_code = country_code;
1447
1448 wlan_ftm_civic_cfg(&lcr);
1449 return;
1450 }
1451
1452 static void test_wlan_11mc_nego_cfg(int argc, char **argv)
1453 {
1454 unsigned burst_exp, burst_dur, min_delta, asap, ftm_per_burst, bw, burst_period;
1455 ftm_11mc_nego_cfg_t dot11mc_cfg;
1456 int arg = 1;
1457 char *civ_addr = CIVIC_ADDRESS;
1458 if (argc != 13)
1459 {
1460 (void)PRINTF("Error: invalid number of arguments\r\n");
1461 dump_wlan_11mc_nego_cfg();
1462 return;
1463 }
1464
1465 burst_exp = 0;
1466 burst_dur = BURST_DURATION;
1467 min_delta = MIN_DELTA;
1468 asap = IS_ASAP;
1469 ftm_per_burst = FTM_PER_BURST;
1470 bw = BW;
1471 burst_period = BURST_PERIOD;
1472
1473 while (arg < argc)
1474 {
1475 if (string_equal("burst_dur", argv[arg]))
1476 {
1477 if (get_uint(argv[arg + 1], &burst_dur, strlen(argv[arg + 1])))
1478 {
1479 (void)PRINTF("Error: invalid value of burst duration argument\r\n");
1480 dump_wlan_11mc_nego_cfg();
1481 return;
1482 }
1483 }
1484 else if (string_equal("min_delta", argv[arg]))
1485 {
1486 if (get_uint(argv[arg + 1], &min_delta, strlen(argv[arg + 1])))
1487 {
1488 (void)PRINTF("Error: invalid minimum delta argument\r\n");
1489 dump_wlan_11mc_nego_cfg();
1490 return;
1491 }
1492 }
1493 else if (string_equal("asap", argv[arg]))
1494 {
1495 if (get_uint(argv[arg + 1], &asap, strlen(argv[arg + 1])))
1496 {
1497 (void)PRINTF("Error: invalid ASAP argument\r\n");
1498 dump_wlan_11mc_nego_cfg();
1499 return;
1500 }
1501 }
1502 else if (string_equal("ftm_per_burst", argv[arg]))
1503 {
1504 if (get_uint(argv[arg + 1], &ftm_per_burst, strlen(argv[arg + 1])))
1505 {
1506 (void)PRINTF("Error: invalid frames per burst argument\r\n");
1507 dump_wlan_11mc_nego_cfg();
1508 return;
1509 }
1510 }
1511 else if (string_equal("BW", argv[arg]))
1512 {
1513 if (get_uint(argv[arg + 1], &bw, strlen(argv[arg + 1])))
1514 {
1515 (void)PRINTF("Error: invalid bandwidth argument\r\n");
1516 dump_wlan_11mc_nego_cfg();
1517 return;
1518 }
1519 }
1520 else if (string_equal("burst_period", argv[arg]))
1521 {
1522 if (get_uint(argv[arg + 1], &burst_period, strlen(argv[arg + 1])))
1523 {
1524 (void)PRINTF("Error: invalid burst period argument\r\n");
1525 dump_wlan_11mc_nego_cfg();
1526 return;
1527 }
1528 }
1529 else
1530 {
1531 (void)PRINTF("Error: invalid [%s] argument\r\n", argv[arg]);
1532 dump_wlan_11mc_nego_cfg();
1533 return;
1534 }
1535 arg += 2;
1536 }
1537
1538 dot11mc_cfg.burst_exponent = burst_exp;
1539 dot11mc_cfg.burst_duration = burst_dur;
1540 dot11mc_cfg.min_delta_FTM = min_delta;
1541 dot11mc_cfg.is_ASAP = asap;
1542 dot11mc_cfg.per_burst_FTM = ftm_per_burst;
1543 dot11mc_cfg.channel_spacing = bw;
1544 dot11mc_cfg.burst_period = burst_period;
1545
1546 wlan_ftm_11mc_cfg(&dot11mc_cfg);
1547 return;
1548 }
1549
1550 static void test_wlan_11az_rang_cfg(int argc, char **argv)
1551 {
1552 unsigned protocol, format_bw, num_measurements, measurement_freq, i2r_sts, r2i_sts, i2r_lmr, civic_req, lci_req;
1553 ranging_11az_cfg_t cfg_11az;
1554 int arg = 2;
1555
1556 if (argc != 14)
1557 {
1558 (void)PRINTF("Error: invalid number of arguments\r\n");
1559 dump_wlan_11az_rang_cfg();
1560 return;
1561 }
1562
1563 if (get_uint(argv[1], &protocol, strlen(argv[1])))
1564 {
1565 (void)PRINTF("Error: invalid protocol argument\r\n");
1566 dump_wlan_11az_rang_cfg();
1567 return;
1568 }
1569
1570 if (protocol != 0 && protocol != 1)
1571 {
1572 (void)PRINTF("Error: invalid protocol argument\r\n");
1573 dump_wlan_11az_rang_cfg();
1574 return;
1575 }
1576
1577 format_bw = FORMAT_BW;
1578 num_measurements = AZ_NUMBER_OF_MEASUREMENTS;
1579 measurement_freq = AZ_MEASUREMENT_FREQ;
1580 i2r_sts = MAX_I2R_STS_UPTO80;
1581 r2i_sts = MAX_R2I_STS_UPTO80;
1582 i2r_lmr = I2R_LMR_FEEDBACK;
1583 civic_req = CIVIC_REQUEST;
1584 lci_req = LCI_REQUEST;
1585
1586 while (arg < argc)
1587 {
1588 if (string_equal("num_measurements", argv[arg]))
1589 {
1590 if (get_uint(argv[arg + 1], &num_measurements, strlen(argv[arg + 1])))
1591 {
1592 (void)PRINTF("Error: invalid number of measurements argument\r\n");
1593 dump_wlan_11az_rang_cfg();
1594 return;
1595 }
1596 }
1597 else if (string_equal("measurement_freq", argv[arg]))
1598 {
1599 if (get_uint(argv[arg + 1], &measurement_freq, strlen(argv[arg + 1])))
1600 {
1601 (void)PRINTF("Error: invalid measurement frequency argument\r\n");
1602 dump_wlan_11az_rang_cfg();
1603 return;
1604 }
1605 }
1606 else if (string_equal("i2r_sts", argv[arg]))
1607 {
1608 if (get_uint(argv[arg + 1], &i2r_sts, strlen(argv[arg + 1])))
1609 {
1610 (void)PRINTF("Error: invalid I2R STS argument\r\n");
1611 dump_wlan_11az_rang_cfg();
1612 return;
1613 }
1614 }
1615 else if (string_equal("r2i_sts", argv[arg]))
1616 {
1617 if (get_uint(argv[arg + 1], &r2i_sts, strlen(argv[arg + 1])))
1618 {
1619 (void)PRINTF("Error: invalid R2I STS argument\r\n");
1620 dump_wlan_11az_rang_cfg();
1621 return;
1622 }
1623 }
1624 else if (string_equal("i2r_lmr", argv[arg]))
1625 {
1626 if (get_uint(argv[arg + 1], &i2r_lmr, strlen(argv[arg + 1])))
1627 {
1628 (void)PRINTF("Error: invalid R2I STS argument\r\n");
1629 dump_wlan_11az_rang_cfg();
1630 return;
1631 }
1632 }
1633 else if (string_equal("format_bw", argv[arg]))
1634 {
1635 if (get_uint(argv[arg + 1], &format_bw, strlen(argv[arg + 1])))
1636 {
1637 (void)PRINTF("Error: invalid format bandwidth argument\r\n");
1638 dump_wlan_11az_rang_cfg();
1639 return;
1640 }
1641 }
1642 else
1643 {
1644 (void)PRINTF("Error: invalid [%s] argument\r\n", argv[arg]);
1645 dump_wlan_11az_rang_cfg();
1646 return;
1647 }
1648 arg += 2;
1649 }
1650
1651 cfg_11az.format_bw = format_bw;
1652 cfg_11az.max_i2r_sts_upto80 = i2r_sts;
1653 cfg_11az.max_r2i_sts_upto80 = r2i_sts;
1654 cfg_11az.az_measurement_freq = measurement_freq;
1655 cfg_11az.az_number_of_measurements = num_measurements;
1656 cfg_11az.i2r_lmr_feedback = i2r_lmr;
1657
1658 cfg_11az.civic_req = civic_req;
1659 cfg_11az.lci_req = lci_req;
1660
1661 wlan_ftm_cfg(protocol, &cfg_11az);
1662 return;
1663 }
1664 #endif
1665 #if CONFIG_UAP_STA_MAC_ADDR_FILTER
1666 /**
1667 * @brief Show usage information for the sta_filter_table command
1668 *
1669 * $return N/A
1670 */
1671 static void print_sta_filter_table_usage(void)
1672 {
1673 (void)PRINTF("\r\nUsage : sta_filter_table <FILTERMODE> <MACADDRESS_LIST>\r\n");
1674 (void)PRINTF("\r\nOptions: FILTERMODE : 0 - Disable filter table");
1675 (void)PRINTF("\r\n 1 - allow MAC addresses specified in the allowed list");
1676 (void)PRINTF("\r\n 2 - block MAC addresses specified in the banned list");
1677 (void)PRINTF("\r\n MACADDRESS_LIST is the list of MAC addresses to be acted upon. Each");
1678 (void)PRINTF("\r\n MAC address must be separated with a space. Maximum of");
1679 (void)PRINTF("\r\n 16 MAC addresses are supported.\r\n");
1680 return;
1681 }
1682
1683 static void test_wlan_set_sta_filter(int argc, char **argv)
1684 {
1685 int i = 0;
1686 int ret = WM_SUCCESS;
1687 int filter_mode = 0;
1688 int mac_count = 0;
1689 unsigned char mac_addr[WLAN_MAX_STA_FILTER_NUM * WLAN_MAC_ADDR_LENGTH];
1690
1691 if (argc < 2 || argc > (WLAN_MAX_STA_FILTER_NUM + 2))
1692 {
1693 (void)PRINTF("ERR:Too many or too few farguments.\r\n");
1694 print_sta_filter_table_usage();
1695 return;
1696 }
1697
1698 argc--;
1699 argv++;
1700
1701 if (((atoi(argv[0]) < 0) || (atoi(argv[0]) > 2)))
1702 {
1703 (void)PRINTF("ERR:Illegal FILTERMODE parameter %s. Must be either '0', '1', or '2'.\r\n", argv[1]);
1704 print_sta_filter_table_usage();
1705 return;
1706 }
1707
1708 filter_mode = atoi(argv[0]);
1709
1710 mac_count = argc - 1;
1711
1712 if (mac_count)
1713 {
1714 for (i = 0; i < mac_count; i++)
1715 {
1716 ret = get_mac(argv[i + 1], (char *)&mac_addr[i * WLAN_MAC_ADDR_LENGTH], ':');
1717 if (ret != 0)
1718 {
1719 (void)PRINTF("Error: invalid MAC argument\r\n");
1720 return;
1721 }
1722 }
1723 }
1724 else
1725 {
1726 memset(mac_addr, 0, 16 * WLAN_MAC_ADDR_LENGTH);
1727 }
1728
1729 wlan_set_sta_mac_filter(filter_mode, mac_count, mac_addr);
1730
1731 return;
1732 }
1733 #endif
1734
1735 #if CONFIG_WIFI_GET_LOG
1736 static void test_wlan_get_log(int argc, char **argv)
1737 {
1738 wlan_pkt_stats_t stats;
1739 int ret, i;
1740
1741 if (argc < 2)
1742 {
1743 (void)PRINTF("Usage: %s <sta/uap> <ext>\r\n", argv[0]);
1744 return;
1745 }
1746
1747 if (string_equal("sta", argv[1]))
1748 ret = wlan_get_log(&stats);
1749 else if (string_equal("uap", argv[1]))
1750 ret = wlan_uap_get_log(&stats);
1751 else
1752 {
1753 (void)PRINTF("Usage: %s <sta/uap> <ext>\r\n", argv[0]);
1754 return;
1755 }
1756
1757 if (ret != WM_SUCCESS)
1758 {
1759 (void)PRINTF("Failed to get log\r\n");
1760 }
1761 else
1762 {
1763 (void)PRINTF(
1764 "dot11GroupTransmittedFrameCount %u\r\n"
1765 "dot11FailedCount %u\r\n"
1766 "dot11RetryCount %u\r\n"
1767 "dot11MultipleRetryCount %u\r\n"
1768 "dot11FrameDuplicateCount %u\r\n"
1769 "dot11RTSSuccessCount %u\r\n"
1770 "dot11RTSFailureCount %u\r\n"
1771 "dot11ACKFailureCount %u\r\n"
1772 "dot11ReceivedFragmentCount %u\r\n"
1773 "dot11GroupReceivedFrameCount %u\r\n"
1774 "dot11FCSErrorCount %u\r\n"
1775 "dot11TransmittedFrameCount %u\r\n"
1776 "wepicverrcnt-1 %u\r\n"
1777 "wepicverrcnt-2 %u\r\n"
1778 "wepicverrcnt-3 %u\r\n"
1779 "wepicverrcnt-4 %u\r\n"
1780 "beaconReceivedCount %u\r\n"
1781 "beaconMissedCount %u\r\n",
1782 stats.mcast_tx_frame, stats.failed, stats.retry, stats.multi_retry, stats.frame_dup, stats.rts_success,
1783 stats.rts_failure, stats.ack_failure, stats.rx_frag, stats.mcast_rx_frame, stats.fcs_error, stats.tx_frame,
1784 stats.wep_icv_error[0], stats.wep_icv_error[1], stats.wep_icv_error[2], stats.wep_icv_error[3],
1785 stats.bcn_rcv_cnt, stats.bcn_miss_cnt);
1786
1787 if (argc == 3 && !(strcmp(argv[2], "ext")))
1788 {
1789 (void)PRINTF(
1790 "rxStuckIssueCount-1 %u\r\n"
1791 "rxStuckIssueCount-2 %u\r\n"
1792 "rxStuckRecoveryCount %u\r\n"
1793 "rxStuckTsf-1 %llu\r\n"
1794 "rxStuckTsf-2 %llu\r\n"
1795 "txWatchdogRecoveryCount %u\r\n"
1796 "txWatchdogTsf-1 %llu\r\n"
1797 "txWatchdogTsf-2 %llu\r\n"
1798 "channelSwitchAnnouncementSent %u\r\n"
1799 "channelSwitchState %u\r\n"
1800 "registerClass %u\r\n"
1801 "channelNumber %u\r\n"
1802 "channelSwitchMode %u\r\n"
1803 "RxResetRecoveryCount %u\r\n"
1804 "RxIsr2NotDoneCnt %u\r\n"
1805 "gdmaAbortCnt %u\r\n"
1806 "gResetRxMacCnt %u\r\n"
1807 "gOwnrshpCtlErrCnt %u\r\n"
1808 "gOwnrshpBcnErrCnt %u\r\n"
1809 "gOwnrshpMgtErrCnt %u\r\n"
1810 "gOwnrshpDatErrCnt %u\r\n"
1811 "bigtk_mmeGoodCnt %u\r\n"
1812 "bigtk_replayErrCnt %u\r\n"
1813 "bigtk_micErrCnt %u\r\n"
1814 "bigtk_mmeNotFoundCnt %u\r\n",
1815 stats.rx_stuck_issue_cnt[0], stats.rx_stuck_issue_cnt[1], stats.rx_stuck_recovery_cnt,
1816 stats.rx_stuck_tsf[0], stats.rx_stuck_tsf[1], stats.tx_watchdog_recovery_cnt, stats.tx_watchdog_tsf[0],
1817 stats.tx_watchdog_tsf[1], stats.channel_switch_ann_sent, stats.channel_switch_state, stats.reg_class,
1818 stats.channel_number, stats.channel_switch_mode, stats.rx_reset_mac_recovery_cnt,
1819 stats.rx_Isr2_NotDone_Cnt, stats.gdma_abort_cnt, stats.g_reset_rx_mac_cnt, stats.dwCtlErrCnt,
1820 stats.dwBcnErrCnt, stats.dwMgtErrCnt, stats.dwDatErrCnt, stats.bigtk_mmeGoodCnt,
1821 stats.bigtk_replayErrCnt, stats.bigtk_micErrCnt, stats.bigtk_mmeNotFoundCnt);
1822 }
1823
1824 (void)PRINTF("dot11TransmittedFragmentCount %u\r\n", stats.tx_frag_cnt);
1825 (void)PRINTF("dot11QosTransmittedFragmentCount ");
1826 for (i = 0; i < 8; i++)
1827 {
1828 (void)PRINTF("%u ", stats.qos_tx_frag_cnt[i]);
1829 }
1830 (void)PRINTF("\r\ndot11QosFailedCount ");
1831 for (i = 0; i < 8; i++)
1832 {
1833 (void)PRINTF("%u ", stats.qos_failed_cnt[i]);
1834 }
1835 (void)PRINTF("\r\ndot11QosRetryCount ");
1836 for (i = 0; i < 8; i++)
1837 {
1838 (void)PRINTF("%u ", stats.qos_retry_cnt[i]);
1839 }
1840 (void)PRINTF("\r\ndot11QosMultipleRetryCount ");
1841 for (i = 0; i < 8; i++)
1842 {
1843 (void)PRINTF("%u ", stats.qos_multi_retry_cnt[i]);
1844 }
1845 (void)PRINTF("\r\ndot11QosFrameDuplicateCount ");
1846 for (i = 0; i < 8; i++)
1847 {
1848 (void)PRINTF("%u ", stats.qos_frm_dup_cnt[i]);
1849 }
1850 (void)PRINTF("\r\ndot11QosRTSSuccessCount ");
1851 for (i = 0; i < 8; i++)
1852 {
1853 (void)PRINTF("%u ", stats.qos_rts_suc_cnt[i]);
1854 }
1855 (void)PRINTF("\r\ndot11QosRTSFailureCount ");
1856 for (i = 0; i < 8; i++)
1857 {
1858 (void)PRINTF("%u ", stats.qos_rts_failure_cnt[i]);
1859 }
1860 (void)PRINTF("\r\ndot11QosACKFailureCount ");
1861 for (i = 0; i < 8; i++)
1862 {
1863 (void)PRINTF("%u ", stats.qos_ack_failure_cnt[i]);
1864 }
1865 (void)PRINTF("\r\ndot11QosReceivedFragmentCount ");
1866 for (i = 0; i < 8; i++)
1867 {
1868 (void)PRINTF("%u ", stats.qos_rx_frag_cnt[i]);
1869 }
1870 (void)PRINTF("\r\ndot11QosTransmittedFrameCount ");
1871 for (i = 0; i < 8; i++)
1872 {
1873 (void)PRINTF("%u ", stats.qos_tx_frm_cnt[i]);
1874 }
1875 (void)PRINTF("\r\ndot11QosDiscardedFrameCount ");
1876 for (i = 0; i < 8; i++)
1877 {
1878 (void)PRINTF("%u ", stats.qos_discarded_frm_cnt[i]);
1879 }
1880 (void)PRINTF("\r\ndot11QosMPDUsReceivedCount ");
1881 for (i = 0; i < 8; i++)
1882 {
1883 (void)PRINTF("%u ", stats.qos_mpdus_rx_cnt[i]);
1884 }
1885 (void)PRINTF("\r\ndot11QosRetriesReceivedCount ");
1886 for (i = 0; i < 8; i++)
1887 {
1888 (void)PRINTF("%u ", stats.qos_retries_rx_cnt[i]);
1889 }
1890 (void)PRINTF(
1891 "\r\ndot11RSNAStatsCMACICVErrors %u\r\n"
1892 "dot11RSNAStatsCMACReplays %u\r\n"
1893 "dot11RSNAStatsRobustMgmtCCMPReplays %u\r\n"
1894 "dot11RSNAStatsTKIPICVErrors %u\r\n"
1895 "dot11RSNAStatsTKIPReplays %u\r\n"
1896 "dot11RSNAStatsCCMPDecryptErrors %u\r\n"
1897 "dot11RSNAstatsCCMPReplays %u\r\n"
1898 "dot11TransmittedAMSDUCount %u\r\n"
1899 "dot11FailedAMSDUCount %u\r\n"
1900 "dot11RetryAMSDUCount %u\r\n"
1901 "dot11MultipleRetryAMSDUCount %u\r\n"
1902 "dot11TransmittedOctetsInAMSDUCount %llu\r\n"
1903 "dot11AMSDUAckFailureCount %u\r\n"
1904 "dot11ReceivedAMSDUCount %u\r\n"
1905 "dot11ReceivedOctetsInAMSDUCount %llu\r\n"
1906 "dot11TransmittedAMPDUCount %u\r\n"
1907 "dot11TransmittedMPDUsInAMPDUCount %u\r\n"
1908 "dot11TransmittedOctetsInAMPDUCount %llu\r\n"
1909 "dot11AMPDUReceivedCount %u\r\n"
1910 "dot11MPDUInReceivedAMPDUCount %u\r\n"
1911 "dot11ReceivedOctetsInAMPDUCount %llu\r\n"
1912 "dot11AMPDUDelimiterCRCErrorCount %u\r\n",
1913 stats.cmacicv_errors, stats.cmac_replays, stats.mgmt_ccmp_replays, stats.tkipicv_errors, stats.tkip_replays,
1914 stats.ccmp_decrypt_errors, stats.ccmp_replays, stats.tx_amsdu_cnt, stats.failed_amsdu_cnt,
1915 stats.retry_amsdu_cnt, stats.multi_retry_amsdu_cnt, stats.tx_octets_in_amsdu_cnt,
1916 stats.amsdu_ack_failure_cnt, stats.rx_amsdu_cnt, stats.rx_octets_in_amsdu_cnt, stats.tx_ampdu_cnt,
1917 stats.tx_mpdus_in_ampdu_cnt, stats.tx_octets_in_ampdu_cnt, stats.ampdu_rx_cnt, stats.mpdu_in_rx_ampdu_cnt,
1918 stats.rx_octets_in_ampdu_cnt, stats.ampdu_delimiter_crc_error_cnt);
1919 }
1920 }
1921 #endif
1922
1923 #if CONFIG_MEF_CFG
1924 static void dump_multiple_mef_config_usage()
1925 {
1926 (void)PRINTF("Usage:\r\n");
1927 (void)PRINTF(" wlan-multi-mef <ping/arp/multicast/ns/del> [<action>]\r\n");
1928 (void)PRINTF(" ping/arp/multicast/ns\r\n");
1929 (void)PRINTF(" -- MEF entry type, will add one mef entry at a time\r\n");
1930 (void)PRINTF(" del -- Delete all previous MEF entries\r\n");
1931 (void)PRINTF(" action -- 0--discard and not wake host\r\n");
1932 (void)PRINTF(" 1--discard and wake host\r\n");
1933 (void)PRINTF(" 3--allow and wake host\r\n");
1934 (void)PRINTF("Example:\r\n");
1935 (void)PRINTF(" wlan-multi-mef ping 3\r\n");
1936 (void)PRINTF(" wlan-multi-mef del\r\n");
1937 }
1938
1939 static void test_wlan_set_multiple_mef_config(int argc, char **argv)
1940 {
1941 int type = MEF_TYPE_END;
1942 t_u8 mef_action = 0;
1943 if (argc < 2)
1944 {
1945 dump_multiple_mef_config_usage();
1946 (void)PRINTF("Error: invalid number of arguments\r\n");
1947 return;
1948 }
1949 /* Delete previous MEF configure */
1950 if (argc == 2)
1951 {
1952 if (string_equal("del", argv[1]))
1953 type = MEF_TYPE_DELETE;
1954 else
1955 {
1956 dump_multiple_mef_config_usage();
1957 (void)PRINTF("Error: invalid mef type\r\n");
1958 return;
1959 }
1960 }
1961 /* Add MEF entry */
1962 else if (argc >= 3)
1963 {
1964 if (string_equal("ping", argv[1]))
1965 {
1966 type = MEF_TYPE_PING;
1967 mef_action = (t_u8)atoi(argv[2]);
1968 }
1969 else if (string_equal("arp", argv[1]))
1970 {
1971 type = MEF_TYPE_ARP;
1972 mef_action = (t_u8)atoi(argv[2]);
1973 }
1974 else if (string_equal("multicast", argv[1]))
1975 {
1976 type = MEF_TYPE_MULTICAST;
1977 mef_action = (t_u8)atoi(argv[2]);
1978 }
1979 else if (string_equal("ns", argv[1]))
1980 {
1981 type = MEF_TYPE_IPV6_NS;
1982 mef_action = (t_u8)atoi(argv[2]);
1983 }
1984 else
1985 {
1986 (void)PRINTF("Error: invalid mef type\r\n");
1987 return;
1988 }
1989 }
1990 wlan_config_mef(type, mef_action);
1991 }
1992 #endif
1993
1994 #if CONFIG_HOST_SLEEP
1995 #ifdef RW610
1996 static void test_wlan_wakeup_condition(int argc, char **argv)
1997 {
1998 #if CONFIG_MEF_CFG
1999 uint8_t is_mef = MFALSE;
2000 #endif
2001 uint32_t wake_up_conds = 0;
2002
2003 #if CONFIG_MEF_CFG
2004 if (argc < 2 || argc > 3)
2005 #else
2006 if (argc != 3)
2007 #endif
2008 {
2009 (void)PRINTF("Error: invalid number of arguments\r\n");
2010 (void)PRINTF("Usage:\r\n");
2011 #if CONFIG_MEF_CFG
2012 (void)PRINTF(" wlan-wakeup-condition <mef/wowlan wake_up_conds>\r\n");
2013 #else
2014 (void)PRINTF(" wlan-wakeup-condition <wowlan wake_up_conds>\r\n");
2015 #endif
2016 (void)PRINTF(" wowlan -- default host wakeup\r\n");
2017 (void)PRINTF(" [wake_up_conds] -- value for wowlan host wakeup conditions only\r\n");
2018 (void)PRINTF(" bit 0: WAKE_ON_ALL_BROADCAST\r\n");
2019 (void)PRINTF(" bit 1: WAKE_ON_UNICAST\r\n");
2020 (void)PRINTF(" bit 2: WAKE_ON_MAC_EVENT\r\n");
2021 (void)PRINTF(" bit 3: WAKE_ON_MULTICAST\r\n");
2022 (void)PRINTF(" bit 4: WAKE_ON_ARP_BROADCAST\r\n");
2023 (void)PRINTF(" bit 6: WAKE_ON_MGMT_FRAME\r\n");
2024 (void)PRINTF(" All bit 0 discard and not wakeup host\r\n");
2025 #if CONFIG_MEF_CFG
2026 (void)PRINTF(" mef -- MEF host wakeup\r\n");
2027 #endif
2028 (void)PRINTF("Example:\r\n");
2029 #if CONFIG_MEF_CFG
2030 (void)PRINTF(" wlan-wakeup-condition mef\r\n");
2031 #endif
2032 (void)PRINTF(" wlan-wakeup-condition wowlan 0x1e\r\n");
2033 return;
2034 }
2035 #if CONFIG_MEF_CFG
2036 if (string_equal("mef", argv[1]))
2037 {
2038 is_mef = MTRUE;
2039 }
2040 else
2041 #endif
2042 if (string_equal("wowlan", argv[1]))
2043 {
2044 if (argc < 3)
2045 {
2046 (void)PRINTF("wake_up_conds need be specified\r\n");
2047 return;
2048 }
2049
2050 errno = 0;
2051 wake_up_conds = (int)strtol(argv[2], NULL, 16);
2052 if (errno != 0)
2053 {
2054 (void)PRINTF("Error during strtol:wake_up_conds errno:%d\r\n", errno);
2055 return;
2056 }
2057 }
2058 else
2059 {
2060 #if CONFIG_MEF_CFG
2061 (void)PRINTF("wowlan/mef need be specified\r\n");
2062 #else
2063 (void)PRINTF("wowlan need be specified\r\n");
2064 #endif
2065 return;
2066 }
2067 #if CONFIG_MEF_CFG
2068 wlan_wowlan_config(is_mef, wake_up_conds);
2069 #else
2070 wlan_wowlan_config(wake_up_conds);
2071 #endif
2072 return;
2073 }
2074 #endif /*RW610*/
2075
2076 #if CONFIG_MEF_CFG
2077 extern wlan_flt_cfg_t g_flt_cfg;
2078 #endif
2079
2080 #ifndef RW610
2081 static void test_wlan_host_sleep(int argc, char **argv)
2082 {
2083 int choice = -1, wowlan = 0;
2084 int ret = -WM_FAIL;
2085
2086 if ((argc < 2) || (argc > 4))
2087 {
2088 goto done;
2089 }
2090
2091 errno = 0;
2092 choice = (int)strtol(argv[1], NULL, 10);
2093 if (errno != 0)
2094 {
2095 (void)PRINTF("Error during strtol:host_sleep errno:%d\r\n", errno);
2096 goto done;
2097 }
2098 if ((choice != 0) && (choice != 1))
2099 {
2100 goto done;
2101 }
2102
2103 if (choice == 0)
2104 {
2105 ret = wlan_send_host_sleep(HOST_SLEEP_CFG_CANCEL);
2106 if (ret == WM_SUCCESS)
2107 {
2108 (void)PRINTF("Cancel Previous configured Host sleep configuration");
2109 }
2110 else
2111 {
2112 (void)PRINTF("Failed to Cancel Previous configured Host sleep configuration, error: %d", ret);
2113 }
2114 }
2115 else if (choice == 1)
2116 {
2117 #if CONFIG_MEF_CFG
2118 if (argc < 3)
2119 #else
2120 if (argc < 4)
2121 #endif
2122 {
2123 goto done;
2124 }
2125
2126 if (string_equal(argv[2], "wowlan"))
2127 {
2128 errno = 0;
2129 wowlan = (int)strtol(argv[3], NULL, 16);
2130 if (errno != 0)
2131 {
2132 (void)PRINTF("Error during strtol:wowlan errno:%d\r\n", errno);
2133 return;
2134 }
2135
2136 ret = wlan_send_host_sleep(wowlan);
2137 if (ret == WM_SUCCESS)
2138 {
2139 (void)PRINTF("Host sleep configuration req sent");
2140 }
2141 else
2142 {
2143 (void)PRINTF("Failed to host sleep configuration, error: %d", ret);
2144 }
2145 }
2146 #if CONFIG_MEF_CFG
2147 else if (string_equal(argv[2], "mef"))
2148 {
2149 ret = wlan_send_host_sleep(HOST_SLEEP_NO_COND);
2150 if (ret == WM_SUCCESS)
2151 {
2152 (void)PRINTF("Host sleep configuration successs with MEF");
2153 }
2154 else
2155 {
2156 (void)PRINTF("Failed to host sleep configuration, error: %d", ret);
2157 }
2158 }
2159 #endif
2160 else
2161 {
2162 goto done;
2163 }
2164 }
2165 else
2166 {
2167 done:
2168 (void)PRINTF("Error: invalid number of arguments\r\n");
2169 (void)PRINTF("Usage:\r\n");
2170 (void)PRINTF(" wlan-host-sleep <1/0> <wowlan [wake_up_conds]/mef>\r\n");
2171 (void)PRINTF(" [wake_up_conds] -- value for host wakeup conditions\r\n");
2172 (void)PRINTF(" bit 0: WAKE_ON_ALL_BROADCAST\r\n");
2173 (void)PRINTF(" bit 1: WAKE_ON_UNICAST\r\n");
2174 (void)PRINTF(" bit 2: WAKE_ON_MAC_EVENT\r\n");
2175 (void)PRINTF(" bit 3: WAKE_ON_MULTICAST\r\n");
2176 (void)PRINTF(" bit 4: WAKE_ON_ARP_BROADCAST\r\n");
2177 (void)PRINTF(" bit 6: WAKE_ON_MGMT_FRAME\r\n");
2178 (void)PRINTF(" All bit 0 discard and not wakeup host\r\n");
2179 (void)PRINTF(" All bit 1 cancel host sleep configuration\r\n");
2180 #if CONFIG_MEF_CFG
2181 (void)PRINTF(" mef -- MEF host wakeup\r\n");
2182 (void)PRINTF("Example:\r\n");
2183 (void)PRINTF(" wlan-host-sleep <1/0> mef\r\n");
2184 (void)PRINTF(" wlan-host-sleep <1/0> wowlan 0x1e\r\n");
2185 #endif
2186 (void)PRINTF(" wlan-host-sleep <1/0> wowlan 0x1e\r\n");
2187 return;
2188 }
2189 }
2190 #endif
2191
2192 #ifdef RW610
2193 #if !(CONFIG_WIFI_BLE_COEX_APP)
2194 static void test_wlan_auto_host_sleep(int argc, char **argv)
2195 {
2196 bool is_manual = MFALSE;
2197 t_u8 is_periodic = 0;
2198 t_u8 enable = 0;
2199
2200 if (argc > 3 || argc < 2)
2201 {
2202 (void)PRINTF("Error: invalid number of arguments\r\n");
2203 (void)PRINTF("Usage:\r\n");
2204 (void)PRINTF(" wlan-auto-host-sleep <enable> <periodic>\r\n");
2205 (void)PRINTF(" enable -- enable/disable host sleep\r\n");
2206 (void)PRINTF(" 0 - disable host sleep\r\n");
2207 (void)PRINTF(" 1 - enable host sleep\r\n");
2208 (void)PRINTF(" periodic -- Host enter low power periodically or oneshot\r\n");
2209 (void)PRINTF(
2210 " 0 - Oneshot. Host will enter low power only once and keep full power after "
2211 "waking "
2212 "up.\r\n");
2213 (void)PRINTF(" 1 - Periodic. Host will enter low power periodically.\r\n");
2214 (void)PRINTF("Examples:\r\n");
2215 (void)PRINTF(" wlan-auto-host-sleep 1 1\r\n");
2216 (void)PRINTF(" wlan-auto-host-sleep 0\r\n");
2217 return;
2218 }
2219 enable = (t_u8)atoi(argv[1]);
2220 if (enable != 0 && enable != 1)
2221 {
2222 (void)PRINTF("Error! Invalid input of parameter <enable>\r\n");
2223 return;
2224 }
2225 /* Disable auto host sleep */
2226 if (enable == 0)
2227 {
2228 wlan_cancel_host_sleep();
2229 wlan_clear_host_sleep_config();
2230 (void)PRINTF("Auto Host Sleep disabled\r\n");
2231 return;
2232 }
2233 is_periodic = (t_u8)atoi(argv[2]);
2234 wlan_config_host_sleep(is_manual, is_periodic);
2235 }
2236 #else
2237 static void test_wlan_ns_offload(int argc, char **argv)
2238 {
2239 int ret = -WM_FAIL;
2240 ret = wlan_set_ipv6_ns_offload();
2241 if (ret == WM_SUCCESS)
2242 {
2243 (void)PRINTF("Enabled wlan IPv6 NS offload feature");
2244 }
2245 else
2246 {
2247 (void)PRINTF("Failed to enabled wlan auto arp offload, error: %d", ret);
2248 }
2249 }
2250
2251 static void test_wlan_auto_arp(int argc, char **argv)
2252 {
2253 int ret = -WM_FAIL;
2254 ret = wlan_set_auto_arp();
2255 if (ret == WM_SUCCESS)
2256 (void)PRINTF("Enabled wlan auto arp offload feature\r\n");
2257 else
2258 (void)PRINTF("Failed to enabled wlan auto arp offload, error: %d\r\n", ret);
2259 }
2260
2261 #if CONFIG_MEF_CFG
2262 static void dump_wlan_add_packet_filter()
2263 {
2264 (void)PRINTF("Usage:\r\n");
2265 (void)PRINTF("For wowlan Add packet filter\r\n");
2266 (void)PRINTF("wowlan magic filter:\r\n");
2267 (void)PRINTF("wlan_add_packet_filter 1:\r\n");
2268 (void)PRINTF("wowlan User defined pattren packet filter:\r\n");
2269 (void)PRINTF("wlan_add_packet_filter 0 <number of patterns> <ptn_len> <pkt_offset> <ptn> ........:\r\n");
2270 (void)PRINTF(
2271 "For 2 number of patterns Usage \r\nwlan_add_packet_filter 0 2 6 0 0xff 0xff 0xff 0xff 0xff 0xff 4 20 192 168 "
2272 "10 1\r\n");
2273 (void)PRINTF("wowlan User defined pattren and magic packet filter:\r\n");
2274 (void)PRINTF("wlan_add_packet_filter 1 <number of patterns> <ptn_len> <pkt_offset> <ptn> ........:\r\n");
2275 (void)PRINTF(
2276 "For 2 number of patterns Usage \r\nwlan_add_packet_filter 1 2 6 0 0xff 0xff 0xff 0xff 0xff 0xff 4 20 192 168 "
2277 "10 1\r\n");
2278 }
2279
2280 static void test_wlan_add_packet_filter(int argc, char **argv)
2281 {
2282 int ret = -WM_FAIL;
2283 t_u8 i = 0, j = 0, k = 0;
2284 wlan_wowlan_ptn_cfg_t wowlan_ptn_cfg;
2285 if (argc < 2)
2286 {
2287 (void)PRINTF("Usage: %s <0/1>\r\n", argv[0]);
2288 (void)PRINTF("Error: Specify 1 to magic filter\r\n");
2289 dump_wlan_add_packet_filter();
2290 return;
2291 }
2292 if (argc > 3 && atoi(argv[2]) != argc - 3)
2293 {
2294 (void)PRINTF("Usage: %s 0/1 <patterns number> <ptn_len> <pkt_offset> <ptn> ...........\r\n", argv[0]);
2295 dump_wlan_add_packet_filter();
2296 return;
2297 }
2298 (void)memset(&wowlan_ptn_cfg, 0, sizeof(wlan_wowlan_ptn_cfg_t));
2299 wowlan_ptn_cfg.enable = atoi(argv[1]);
2300 if (argc > 2)
2301 {
2302 wowlan_ptn_cfg.n_patterns = atoi(argv[2]);
2303 for (i = 0, k = 0; (i + 3 < argc) && k < MAX_NUM_FILTERS; k++)
2304 {
2305 wowlan_ptn_cfg.patterns[k].pattern_len = atoi(argv[i + 3]);
2306 i++;
2307 wowlan_ptn_cfg.patterns[k].pkt_offset = atoi(argv[i + 3]);
2308 i++;
2309 for (j = 0; j < wowlan_ptn_cfg.patterns[k].pattern_len; j++)
2310 wowlan_ptn_cfg.patterns[k].pattern[j] = atoi(argv[j + i + 3]);
2311 i = +j;
2312 (void)memset(wowlan_ptn_cfg.patterns[k].mask, 0x3f, 6);
2313 }
2314 }
2315 ret = wlan_wowlan_cfg_ptn_match(&wowlan_ptn_cfg);
2316 if (ret == WM_SUCCESS)
2317 (void)PRINTF("Enabled pkt filter offload feature");
2318 else
2319 (void)PRINTF("Failed to enabled magic pkt filter offload, error: %d", ret);
2320 }
2321 #endif /* CONFIG_MEF_CFG */
2322 #endif /*RW610*/
2323 #else
2324 static void test_wlan_ns_offload(int argc, char **argv)
2325 {
2326 int ret = -WM_FAIL;
2327 ret = wlan_set_ipv6_ns_offload();
2328 if (ret == WM_SUCCESS)
2329 {
2330 (void)PRINTF("Enabled wlan IPv6 NS offload feature");
2331 }
2332 else
2333 {
2334 (void)PRINTF("Failed to enabled wlan auto arp offload, error: %d", ret);
2335 }
2336 }
2337
2338 static void test_wlan_auto_arp(int argc, char **argv)
2339 {
2340 int ret = -WM_FAIL;
2341 ret = wlan_set_auto_arp();
2342 if (ret == WM_SUCCESS)
2343 (void)PRINTF("Enabled wlan auto arp offload feature\r\n");
2344 else
2345 (void)PRINTF("Failed to enabled wlan auto arp offload, error: %d\r\n", ret);
2346 }
2347
2348 #if CONFIG_MEF_CFG
2349 static void dump_wlan_add_packet_filter()
2350 {
2351 (void)PRINTF("Usage:\r\n");
2352 (void)PRINTF("For wowlan Add packet filter\r\n");
2353 (void)PRINTF("wowlan magic filter:\r\n");
2354 (void)PRINTF("wlan_add_packet_filter 1:\r\n");
2355 (void)PRINTF("wowlan User defined pattren packet filter:\r\n");
2356 (void)PRINTF("wlan_add_packet_filter 0 <number of patterns> <ptn_len> <pkt_offset> <ptn> ........:\r\n");
2357 (void)PRINTF(
2358 "For 2 number of patterns Usage \r\nwlan_add_packet_filter 0 2 6 0 0xff 0xff 0xff 0xff 0xff 0xff 4 20 192 168 "
2359 "10 1\r\n");
2360 (void)PRINTF("wowlan User defined pattren and magic packet filter:\r\n");
2361 (void)PRINTF("wlan_add_packet_filter 1 <number of patterns> <ptn_len> <pkt_offset> <ptn> ........:\r\n");
2362 (void)PRINTF(
2363 "For 2 number of patterns Usage \r\nwlan_add_packet_filter 1 2 6 0 0xff 0xff 0xff 0xff 0xff 0xff 4 20 192 168 "
2364 "10 1\r\n");
2365 }
2366
2367 static void test_wlan_add_packet_filter(int argc, char **argv)
2368 {
2369 int ret = -WM_FAIL;
2370 t_u8 i = 0, j = 0, k = 0;
2371 wlan_wowlan_ptn_cfg_t wowlan_ptn_cfg;
2372 if (argc < 2)
2373 {
2374 (void)PRINTF("Usage: %s <0/1>\r\n", argv[0]);
2375 (void)PRINTF("Error: Specify 1 to magic filter\r\n");
2376 dump_wlan_add_packet_filter();
2377 return;
2378 }
2379 if (argc > 3 && atoi(argv[2]) != argc - 3)
2380 {
2381 (void)PRINTF("Usage: %s 0/1 <patterns number> <ptn_len> <pkt_offset> <ptn> ...........\r\n", argv[0]);
2382 dump_wlan_add_packet_filter();
2383 return;
2384 }
2385 (void)memset(&wowlan_ptn_cfg, 0, sizeof(wlan_wowlan_ptn_cfg_t));
2386 wowlan_ptn_cfg.enable = atoi(argv[1]);
2387 if (argc > 2)
2388 {
2389 wowlan_ptn_cfg.n_patterns = atoi(argv[2]);
2390 for (i = 0, k = 0; (i + 3 < argc) && k < MAX_NUM_FILTERS; k++)
2391 {
2392 wowlan_ptn_cfg.patterns[k].pattern_len = atoi(argv[i + 3]);
2393 i++;
2394 wowlan_ptn_cfg.patterns[k].pkt_offset = atoi(argv[i + 3]);
2395 i++;
2396 for (j = 0; j < wowlan_ptn_cfg.patterns[k].pattern_len; j++)
2397 wowlan_ptn_cfg.patterns[k].pattern[j] = atoi(argv[j + i + 3]);
2398 i = +j;
2399 (void)memset(wowlan_ptn_cfg.patterns[k].mask, 0x3f, 6);
2400 }
2401 }
2402 ret = wlan_wowlan_cfg_ptn_match(&wowlan_ptn_cfg);
2403 if (ret == WM_SUCCESS)
2404 (void)PRINTF("Enabled pkt filter offload feature");
2405 else
2406 (void)PRINTF("Failed to enabled magic pkt filter offload, error: %d", ret);
2407 }
2408 #endif /* CONFIG_MEF_CFG */
2409 #endif /*RW610*/
2410 #endif /* CONFIG_HOST_SLEEP */
2411
2412 #define HOSTCMD_RESP_BUFF_SIZE 1024
2413 static uint8_t host_cmd_resp_buf[HOSTCMD_RESP_BUFF_SIZE] = {0};
2414 /* Command taken from robust_btc.conf*/
2415 static uint8_t host_cmd_buf[] = {0xe0, 0, 0x12, 0, 0x3c, 0, 0, 0, 0x01, 0, 0, 0, 0x38, 0x02, 0x02, 0, 0x07, 0x01};
2416
2417 static void test_wlan_send_hostcmd(int argc, char **argv)
2418 {
2419 int ret = -WM_FAIL;
2420 uint32_t reqd_len = 0;
2421 uint32_t len;
2422
2423 ret = wlan_send_hostcmd(host_cmd_buf, sizeof(host_cmd_buf) / sizeof(uint8_t), host_cmd_resp_buf,
2424 HOSTCMD_RESP_BUFF_SIZE, &reqd_len);
2425
2426 if (ret == WM_SUCCESS)
2427 {
2428 (void)PRINTF("Hostcmd success, response is");
2429 for (len = 0; len < reqd_len; len++)
2430 {
2431 (void)PRINTF("%x\t", host_cmd_resp_buf[len]);
2432 }
2433 }
2434 else
2435 {
2436 (void)PRINTF("Hostcmd failed error: %d", ret);
2437 }
2438 }
2439
2440 #if defined(RW610) || defined(SD9177)
2441 static void test_wlan_ext_coex_uwb_usage(void)
2442 {
2443 (void)PRINTF("Usage:\r\n");
2444 (void)PRINTF(" wlan-ext-coex-uwb \r\n");
2445 (void)PRINTF(" - Enable UWB Coex\r\n");
2446 (void)PRINTF("Example:\r\n");
2447 (void)PRINTF(" wlan-ext-coex-uwb \r\n");
2448 (void)PRINTF(" - Enable UWB Coex \r\n");
2449 }
2450
2451 static void test_wlan_ext_coex_uwb(int argc, char **argv)
2452 {
2453 int ret = -WM_FAIL;
2454 uint32_t reqd_len = 0;
2455
2456 t_u8 cmd_buf[] = {0xe0, 0x00, 0x11, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x01 /* Get/Set */,
2457 0x00, 0x00, 0x00, 0x38, 0x02, 0x01, 0x00, 0x03};
2458 t_u8 resp_buf[64] = {0};
2459
2460 /**
2461 * Command taken from robust_btc.conf
2462 * external_coex_uwb_config={
2463 * CmdCode=0x00e0
2464 * Action:2=1 # 0x0 get, 0x1 set
2465 * RSVD:2=0
2466 * RobustCoexTlvType:2=0x0238 # TLV ID
2467 * RobustCoexTlvLength:2={
2468 * Enabled:1=0x03 # 0x03 to configure UWB
2469 * }
2470 *}
2471 */
2472
2473 if (argc > 1)
2474 {
2475 (void)PRINTF("Error: invalid number of arguments\r\n");
2476 test_wlan_ext_coex_uwb_usage();
2477 return;
2478 }
2479
2480 ret = wlan_send_hostcmd(cmd_buf, sizeof(cmd_buf) / sizeof(t_u8), resp_buf, sizeof(resp_buf), &reqd_len);
2481
2482 if (ret == WM_SUCCESS)
2483 {
2484 (void)PRINTF("Hostcmd success, response is\r\n");
2485 for (ret = 0; ret < reqd_len; ret++)
2486 (void)PRINTF("%x\t", resp_buf[ret]);
2487 }
2488 else
2489 {
2490 (void)PRINTF("Hostcmd failed error: %d", ret);
2491 }
2492 }
2493 #endif
2494
2495 #ifdef SD8801
2496 static void test_wlan_8801_enable_ext_coex(int argc, char **argv)
2497 {
2498 int ret = -WM_FAIL;
2499 wlan_ext_coex_config_t ext_coex_config;
2500
2501 ext_coex_config.Enabled = 1;
2502 ext_coex_config.IgnorePriority = 0;
2503 ext_coex_config.DefaultPriority = 0;
2504 ext_coex_config.EXT_RADIO_REQ_ip_gpio_num = 3;
2505 ext_coex_config.EXT_RADIO_REQ_ip_gpio_polarity = 1;
2506 ext_coex_config.EXT_RADIO_PRI_ip_gpio_num = 2;
2507 ext_coex_config.EXT_RADIO_PRI_ip_gpio_polarity = 1;
2508 ext_coex_config.WLAN_GRANT_op_gpio_num = 1;
2509 ext_coex_config.WLAN_GRANT_op_gpio_polarity = 0;
2510 ext_coex_config.reserved_1 = 0x28;
2511 ext_coex_config.reserved_2 = 0x3c;
2512
2513 ret = wlan_set_ext_coex_config(ext_coex_config);
2514
2515 if (ret == WM_SUCCESS)
2516 {
2517 (void)PRINTF("8801 External Coex Config set successfully");
2518 }
2519 else
2520 {
2521 (void)PRINTF("8801 External Coex Config error: %d", ret);
2522 }
2523 }
2524
2525 static void test_wlan_8801_ext_coex_stats(int argc, char **argv)
2526 {
2527 int ret = -WM_FAIL;
2528 wlan_ext_coex_stats_t ext_coex_stats;
2529
2530 ret = wlan_get_ext_coex_stats(&ext_coex_stats);
2531
2532 if (ret != WM_SUCCESS)
2533 {
2534 (void)PRINTF("Unable to get external Coex statistics\r\n");
2535 }
2536 else
2537 {
2538 (void)PRINTF("BLE_EIP: %d, BLE_PRI: %d, WLAN_EIP: %d\r\n", ext_coex_stats.ext_radio_req_count,
2539 ext_coex_stats.ext_radio_pri_count, ext_coex_stats.wlan_grant_count);
2540 }
2541 }
2542 #endif
2543 #if CONFIG_WIFI_MEM_ACCESS
2544 static void dump_wlan_mem_access_usage(void)
2545 {
2546 (void)PRINTF("Usage:\r\n");
2547 (void)PRINTF("Get value of memory:\r\n");
2548 (void)PRINTF(" wlan-mem-access <memeory_address>\r\n");
2549 (void)PRINTF("Set value of memory:\r\n");
2550 (void)PRINTF(" wlan-mem-access <memeory_address> <value>\r\n");
2551 (void)PRINTF("The format of memory address and value:\r\n");
2552 (void)PRINTF(
2553 " Hexadecimal value. For example:\r\n"
2554 " 0x00001200\r\n"
2555 " 0X00001200\r\n"
2556 " 0x1200\r\n"
2557 " 0X1200\r\n");
2558 }
2559
2560 static void test_wlan_mem_access(int argc, char **argv)
2561 {
2562 int ret;
2563 uint16_t action = 0;
2564 uint32_t address = 0;
2565 uint32_t value = 0;
2566 if (argc < 2 || argc > 3)
2567 {
2568 dump_wlan_mem_access_usage();
2569 (void)PRINTF("Error: invalid number of arguments\r\n");
2570 return;
2571 }
2572 else if (argc == 2)
2573 action = ACTION_GET;
2574 else
2575 {
2576 action = ACTION_SET;
2577 if (argv[2][0] == '0' && (argv[2][1] == 'x' || argv[2][1] == 'X'))
2578 value = a2hex_or_atoi(argv[2]);
2579 else
2580 {
2581 dump_wlan_mem_access_usage();
2582 (void)PRINTF("Error: invalid value argument\r\n");
2583 return;
2584 }
2585 }
2586 if (argv[1][0] == '0' && (argv[1][1] == 'x' || argv[1][1] == 'X'))
2587 address = a2hex_or_atoi(argv[1]);
2588 else
2589 {
2590 dump_wlan_mem_access_usage();
2591 (void)PRINTF("Error: invalid address argument\r\n");
2592 return;
2593 }
2594
2595 ret = wlan_mem_access(action, address, &value);
2596
2597 if (ret == WM_SUCCESS)
2598 {
2599 if (action == ACTION_GET)
2600 (void)PRINTF("At Memory 0x%x: 0x%x\r\n", address, value);
2601 else
2602 (void)PRINTF("Set the Memory successfully\r\n");
2603 }
2604 else
2605 wlcm_e("Read/write Mem failed");
2606 }
2607 #endif
2608
2609 #if CONFIG_WIFI_BOOT_SLEEP
2610 static void dump_wlan_boot_sleep_usage(void)
2611 {
2612 (void)PRINTF("Usage:\r\n");
2613 (void)PRINTF("Get boot sleep status:\r\n");
2614 (void)PRINTF(" wlan-boot-sleep \r\n");
2615 (void)PRINTF("Set boot sleep:\r\n");
2616 (void)PRINTF(" wlan-boot-sleep <0/1>\r\n");
2617 }
2618
2619 static void test_wlan_boot_sleep(int argc, char **argv)
2620 {
2621 int ret;
2622 uint16_t action = 0;
2623 uint16_t enable = 0;
2624 if (argc < 1 || argc > 2)
2625 {
2626 dump_wlan_boot_sleep_usage();
2627 (void)PRINTF("Error: invalid number of arguments\r\n");
2628 return;
2629 }
2630 else if (argc == 1)
2631 action = ACTION_GET;
2632 else
2633 {
2634 action = ACTION_SET;
2635 enable = a2hex_or_atoi(argv[1]);
2636 }
2637
2638 ret = wlan_boot_sleep(action, &enable);
2639
2640 if (ret == WM_SUCCESS)
2641 {
2642 if (action == ACTION_GET)
2643 (void)PRINTF("Boot sleep status: %d\r\n", enable);
2644 else
2645 (void)PRINTF("Boot sleep status is: %s\r\n", enable == 1 ? "Enabled" : "Disabled");
2646 }
2647 else
2648 {
2649 dump_wlan_boot_sleep_usage();
2650 wlcm_e("Wlan boot sleep failed");
2651 }
2652 }
2653 #endif
2654 #if CONFIG_HEAP_STAT
2655 static void test_heap_stat(int argc, char **argv)
2656 {
2657 OSA_DumpMemStats();
2658 }
2659 #endif
2660
2661 #if CONFIG_WIFI_EU_CRYPTO
2662 static void dump_wlan_eu_crypto_rc4(void)
2663 {
2664 (void)PRINTF("Usage:\r\n");
2665 (void)PRINTF("Algorithm RC4 encryption and decryption verification\r\n");
2666 (void)PRINTF("wlan-eu-crypto-rc4 <EncDec>\r\n");
2667 (void)PRINTF("EncDec: 0-Decrypt, 1-Encrypt\r\n");
2668 }
2669 static void test_wlan_eu_crypto_rc4(int argc, char **argv)
2670 {
2671 unsigned int EncDec = 0U;
2672 t_u8 DATA[80] = {0};
2673 t_u16 Length;
2674 int ret;
2675 t_u16 Dec_DataLength;
2676 t_u16 Enc_DataLength;
2677 t_u16 KeyLength;
2678 t_u16 KeyIVLength;
2679 if (argc != 2)
2680 {
2681 dump_wlan_eu_crypto_rc4();
2682 (void)PRINTF("Error: invalid number of arguments\r\n");
2683 return;
2684 }
2685 (void)get_uint(argv[1], &EncDec, 1);
2686 if (EncDec != 0U && EncDec != 1U)
2687 {
2688 dump_wlan_eu_crypto_rc4();
2689 (void)PRINTF("Error: invalid EncDec\r\n");
2690 return;
2691 }
2692 /*Algorithm: RC4*/
2693 t_u8 Key[16] = {0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};
2694 KeyLength = 16;
2695 t_u8 EncData[16] = {0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12};
2696 Enc_DataLength = 16;
2697 t_u8 DecData[16] = {0xd9, 0x90, 0x42, 0xad, 0x51, 0xab, 0x11, 0x3f, 0x24, 0x46, 0x69, 0xe6, 0xf1, 0xac, 0x49, 0xf5};
2698 Dec_DataLength = 16;
2699 t_u8 KeyIV[8] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};
2700 KeyIVLength = 8;
2701
2702 if (EncDec == 0U)
2703 {
2704 (void)memcpy(DATA, DecData, Dec_DataLength);
2705 Length = Dec_DataLength;
2706 ret = wlan_set_crypto_RC4_decrypt(Key, KeyLength, KeyIV, KeyIVLength, DATA, &Length);
2707 }
2708 else
2709 {
2710 (void)memcpy(DATA, EncData, Enc_DataLength);
2711 Length = Enc_DataLength;
2712 ret = wlan_set_crypto_RC4_encrypt(Key, KeyLength, KeyIV, KeyIVLength, DATA, &Length);
2713 }
2714 if (ret == WM_SUCCESS)
2715 {
2716 (void)PRINTF("Raw Data:\r\n");
2717 if (EncDec == 0U)
2718 {
2719 dump_hex((t_u8 *)DecData, Dec_DataLength);
2720 (void)PRINTF("Decrypted Data:\r\n");
2721 dump_hex((t_u8 *)DATA, Length);
2722 }
2723 else
2724 {
2725 dump_hex((t_u8 *)EncData, Enc_DataLength);
2726 (void)PRINTF("Encrypted Data:\r\n");
2727 dump_hex((t_u8 *)DATA, Length);
2728 }
2729 }
2730 else
2731 {
2732 (void)PRINTF("Hostcmd failed error: %d", ret);
2733 }
2734 }
2735
2736 static void dump_wlan_eu_crypto_aes_ecb(void)
2737 {
2738 (void)PRINTF("Usage:\r\n");
2739 (void)PRINTF("Algorithm AES-ECB encryption and decryption verification\r\n");
2740 (void)PRINTF("wlan-eu-crypto-aes-ecb <EncDec>\r\n");
2741 (void)PRINTF("EncDec: 0-Decrypt, 1-Encrypt\r\n");
2742 }
2743 static void test_wlan_eu_crypto_aes_ecb(int argc, char **argv)
2744 {
2745 unsigned int EncDec = 0U;
2746 t_u8 DATA[80] = {0};
2747 t_u16 Length;
2748 int ret;
2749 t_u16 Dec_DataLength;
2750 t_u16 Enc_DataLength;
2751 t_u16 KeyLength;
2752 t_u16 KeyIVLength;
2753 if (argc != 2)
2754 {
2755 dump_wlan_eu_crypto_aes_ecb();
2756 (void)PRINTF("Error: invalid number of arguments\r\n");
2757 return;
2758 }
2759 (void)get_uint(argv[1], &EncDec, 1);
2760 if (EncDec != 0U && EncDec != 1U)
2761 {
2762 dump_wlan_eu_crypto_aes_ecb();
2763 (void)PRINTF("Error: invalid EncDec\r\n");
2764 return;
2765 }
2766 /*Algorithm: AES_ECB*/
2767 t_u8 Key[16] = {0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};
2768 KeyLength = 16;
2769 t_u8 EncData[16] = {0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12};
2770 Enc_DataLength = 16;
2771 t_u8 DecData[16] = {0xc6, 0x93, 0x9d, 0xaa, 0xd1, 0xd0, 0x68, 0x28, 0xfe, 0x88, 0x52, 0x75, 0xa9, 0x43, 0xf9, 0xc0};
2772 Dec_DataLength = 16;
2773 t_u8 KeyIV[8] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};
2774 KeyIVLength = 8;
2775
2776 if (EncDec == 0U)
2777 {
2778 (void)memcpy(DATA, DecData, Dec_DataLength);
2779 Length = Dec_DataLength;
2780 ret = wlan_set_crypto_AES_ECB_decrypt(Key, KeyLength, KeyIV, KeyIVLength, DATA, &Length);
2781 }
2782 else
2783 {
2784 (void)memcpy(DATA, EncData, Enc_DataLength);
2785 Length = Enc_DataLength;
2786 ret = wlan_set_crypto_AES_ECB_encrypt(Key, KeyLength, KeyIV, KeyIVLength, DATA, &Length);
2787 }
2788 if (ret == WM_SUCCESS)
2789 {
2790 (void)PRINTF("Raw Data:\r\n");
2791 if (EncDec == 0U)
2792 {
2793 dump_hex((t_u8 *)DecData, Dec_DataLength);
2794 (void)PRINTF("Decrypted Data:\r\n");
2795 dump_hex((t_u8 *)DATA, Length);
2796 }
2797 else
2798 {
2799 dump_hex((t_u8 *)EncData, Enc_DataLength);
2800 (void)PRINTF("Encrypted Data:\r\n");
2801 dump_hex((t_u8 *)DATA, Length);
2802 }
2803 }
2804 else
2805 {
2806 (void)PRINTF("Hostcmd failed error: %d", ret);
2807 }
2808 }
2809
2810 static void dump_wlan_eu_crypto_aes_wrap(void)
2811 {
2812 (void)PRINTF("Usage:\r\n");
2813 (void)PRINTF("Algorithm AES-WRAP encryption and decryption verification\r\n");
2814 (void)PRINTF("wlan-eu-crypto-aes-wrap <EncDec>\r\n");
2815 (void)PRINTF("EncDec: 0-Decrypt, 1-Encrypt\r\n");
2816 }
2817 static void test_wlan_eu_crypto_aes_wrap(int argc, char **argv)
2818 {
2819 unsigned int EncDec = 0U;
2820 t_u8 DATA[80] = {0};
2821 t_u16 Length;
2822 int ret;
2823 t_u16 Dec_DataLength;
2824 t_u16 Enc_DataLength;
2825 t_u16 KeyLength;
2826 t_u16 KeyIVLength;
2827 if (argc != 2)
2828 {
2829 dump_wlan_eu_crypto_aes_wrap();
2830 (void)PRINTF("Error: invalid number of arguments\r\n");
2831 return;
2832 }
2833 (void)get_uint(argv[1], &EncDec, 1);
2834 if (EncDec != 0U && EncDec != 1U)
2835 {
2836 dump_wlan_eu_crypto_aes_wrap();
2837 (void)PRINTF("Error: invalid EncDec\r\n");
2838 return;
2839 }
2840 /*Algorithm: AES_WRAP*/
2841 t_u8 Key[16] = {0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};
2842 KeyLength = 16;
2843 t_u8 EncData[16] = {0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12};
2844 Enc_DataLength = 16;
2845 t_u8 DecData[24] = {0xfa, 0xda, 0x96, 0x53, 0x30, 0x97, 0x4b, 0x61, 0x77, 0xc6, 0xd4, 0x3c,
2846 0xd2, 0x0e, 0x1f, 0x6d, 0x43, 0x8a, 0x0a, 0x1c, 0x4f, 0x6a, 0x1a, 0xd7};
2847 Dec_DataLength = 24;
2848 t_u8 KeyIV[8] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};
2849 KeyIVLength = 8;
2850
2851 if (EncDec == 0U)
2852 {
2853 (void)memcpy(DATA, DecData, Dec_DataLength);
2854 Length = Dec_DataLength;
2855 ret = wlan_set_crypto_AES_WRAP_decrypt(Key, KeyLength, KeyIV, KeyIVLength, DATA, &Length);
2856 }
2857 else
2858 {
2859 (void)memcpy(DATA, EncData, Enc_DataLength);
2860 Length = Enc_DataLength;
2861 ret = wlan_set_crypto_AES_WRAP_encrypt(Key, KeyLength, KeyIV, KeyIVLength, DATA, &Length);
2862 }
2863 if (ret == WM_SUCCESS)
2864 {
2865 (void)PRINTF("Raw Data:\r\n");
2866 if (EncDec == 0U)
2867 {
2868 dump_hex((t_u8 *)DecData, Dec_DataLength);
2869 (void)PRINTF("Decrypted Data:\r\n");
2870 dump_hex((t_u8 *)DATA, Length);
2871 }
2872 else
2873 {
2874 dump_hex((t_u8 *)EncData, Enc_DataLength);
2875 (void)PRINTF("Encrypted Data:\r\n");
2876 dump_hex((t_u8 *)DATA, Length);
2877 }
2878 }
2879 else
2880 {
2881 (void)PRINTF("Hostcmd failed error: %d", ret);
2882 }
2883 }
2884
2885 static void dump_wlan_eu_crypto_ccmp_128(void)
2886 {
2887 (void)PRINTF("Usage:\r\n");
2888 (void)PRINTF("Algorithm AES-CCMP-128 encryption and decryption verification\r\n");
2889 (void)PRINTF("wlan-eu-crypto-ccmp-128 <EncDec>\r\n");
2890 (void)PRINTF("EncDec: 0-Decrypt, 1-Encrypt\r\n");
2891 }
2892 static void test_wlan_eu_crypto_ccmp_128(int argc, char **argv)
2893 {
2894 unsigned int EncDec = 0U;
2895 t_u8 DATA[80] = {0};
2896 t_u16 Length;
2897 int ret;
2898 t_u16 Dec_DataLength;
2899 t_u16 Enc_DataLength;
2900 t_u16 KeyLength;
2901 t_u16 NonceLength;
2902 t_u16 AADLength;
2903 if (argc != 2)
2904 {
2905 dump_wlan_eu_crypto_ccmp_128();
2906 (void)PRINTF("Error: invalid number of arguments\r\n");
2907 return;
2908 }
2909 (void)get_uint(argv[1], &EncDec, 1);
2910 if (EncDec != 0U && EncDec != 1U)
2911 {
2912 dump_wlan_eu_crypto_ccmp_128();
2913 (void)PRINTF("Error: invalid EncDec\r\n");
2914 return;
2915 }
2916 /*Algorithm: AES_CCMP_128*/
2917 t_u8 Key[16] = {0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85, 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f};
2918 KeyLength = 16;
2919 t_u8 EncData[20] = {0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae, 0x96, 0x7b,
2920 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb, 0x7e, 0x78, 0xa0, 0x50};
2921 Enc_DataLength = 20;
2922 t_u8 DecData[28] = {0xf3, 0xd0, 0xa2, 0xfe, 0x9a, 0x3d, 0xbf, 0x23, 0x42, 0xa6, 0x43, 0xe4, 0x32, 0x46,
2923 0xe8, 0x0c, 0x3c, 0x04, 0xd0, 0x19, 0x78, 0x45, 0xce, 0x0b, 0x16, 0xf9, 0x76, 0x23};
2924 Dec_DataLength = 28;
2925 t_u8 Nonce[13] = {0x00, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0xb5, 0x03, 0x97, 0x76, 0xe7, 0x0c};
2926 NonceLength = 13;
2927 t_u8 AAD[22] = {0x08, 0x40, 0x0f, 0xd2, 0xe1, 0x28, 0xa5, 0x7c, 0x50, 0x30, 0xf1,
2928 0x84, 0x44, 0x08, 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x00, 0x00};
2929 AADLength = 22;
2930
2931 if (EncDec == 0U)
2932 {
2933 (void)memcpy(DATA, DecData, Dec_DataLength);
2934 Length = Dec_DataLength;
2935 ret = wlan_set_crypto_AES_CCMP_decrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
2936 }
2937 else
2938 {
2939 (void)memcpy(DATA, EncData, Enc_DataLength);
2940 Length = Enc_DataLength;
2941 ret = wlan_set_crypto_AES_CCMP_encrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
2942 }
2943 if (ret == WM_SUCCESS)
2944 {
2945 (void)PRINTF("Raw Data:\r\n");
2946 if (EncDec == 0U)
2947 {
2948 dump_hex((t_u8 *)DecData, Dec_DataLength);
2949 (void)PRINTF("Decrypted Data:\r\n");
2950 dump_hex((t_u8 *)DATA, Length);
2951 }
2952 else
2953 {
2954 dump_hex((t_u8 *)EncData, Enc_DataLength);
2955 (void)PRINTF("Encrypted Data:\r\n");
2956 dump_hex((t_u8 *)DATA, Length);
2957 }
2958 }
2959 else
2960 {
2961 (void)PRINTF("Hostcmd failed error: %d", ret);
2962 }
2963 }
2964
2965 static void dump_wlan_eu_crypto_ccmp_256(void)
2966 {
2967 (void)PRINTF("Usage:\r\n");
2968 (void)PRINTF("Algorithm AES-CCMP-256 encryption and decryption verification\r\n");
2969 (void)PRINTF("wlan-eu-crypto-ccmp-256 <EncDec>\r\n");
2970 (void)PRINTF("EncDec: 0-Decrypt, 1-Encrypt\r\n");
2971 }
2972 static void test_wlan_eu_crypto_ccmp_256(int argc, char **argv)
2973 {
2974 unsigned int EncDec = 0U;
2975 t_u8 DATA[80] = {0};
2976 t_u16 Length;
2977 int ret;
2978 t_u16 Dec_DataLength;
2979 t_u16 Enc_DataLength;
2980 t_u16 KeyLength;
2981 t_u16 NonceLength;
2982 t_u16 AADLength;
2983 if (argc != 2)
2984 {
2985 dump_wlan_eu_crypto_ccmp_256();
2986 (void)PRINTF("Error: invalid number of arguments\r\n");
2987 return;
2988 }
2989 (void)get_uint(argv[1], &EncDec, 1);
2990 if (EncDec != 0U && EncDec != 1U)
2991 {
2992 dump_wlan_eu_crypto_ccmp_256();
2993 (void)PRINTF("Error: invalid EncDec\r\n");
2994 return;
2995 }
2996 /*Algorithm: AES_WRAP*/
2997 t_u8 Key[32] = {0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85, 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
2998 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
2999 KeyLength = 32;
3000 t_u8 EncData[20] = {0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae, 0x96, 0x7b,
3001 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb, 0x7e, 0x78, 0xa0, 0x50};
3002 Enc_DataLength = 20;
3003 t_u8 DecData[36] = {0x6d, 0x15, 0x5d, 0x88, 0x32, 0x66, 0x82, 0x56, 0xd6, 0xa9, 0x2b, 0x78,
3004 0xe1, 0x1d, 0x8e, 0x54, 0x49, 0x5d, 0xd1, 0x74, 0x80, 0xaa, 0x56, 0xc9,
3005 0x49, 0x2e, 0x88, 0x2b, 0x97, 0x64, 0x2f, 0x80, 0xd5, 0x0f, 0xe9, 0x7b};
3006 Dec_DataLength = 36;
3007 t_u8 Nonce[13] = {0x00, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0xb5, 0x03, 0x97, 0x76, 0xe7, 0x0c};
3008 NonceLength = 13;
3009 t_u8 AAD[22] = {0x08, 0x40, 0x0f, 0xd2, 0xe1, 0x28, 0xa5, 0x7c, 0x50, 0x30, 0xf1,
3010 0x84, 0x44, 0x08, 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x00, 0x00};
3011 AADLength = 22;
3012
3013 if (EncDec == 0U)
3014 {
3015 (void)memcpy(DATA, DecData, Dec_DataLength);
3016 Length = Dec_DataLength;
3017 ret = wlan_set_crypto_AES_CCMP_decrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
3018 }
3019 else
3020 {
3021 (void)memcpy(DATA, EncData, Enc_DataLength);
3022 Length = Enc_DataLength;
3023 ret = wlan_set_crypto_AES_CCMP_encrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
3024 }
3025 if (ret == WM_SUCCESS)
3026 {
3027 (void)PRINTF("Raw Data:\r\n");
3028 if (EncDec == 0U)
3029 {
3030 dump_hex((t_u8 *)DecData, Dec_DataLength);
3031 (void)PRINTF("Decrypted Data:\r\n");
3032 dump_hex((t_u8 *)DATA, Length);
3033 }
3034 else
3035 {
3036 dump_hex((t_u8 *)EncData, Enc_DataLength);
3037 (void)PRINTF("Encrypted Data:\r\n");
3038 dump_hex((t_u8 *)DATA, Length);
3039 }
3040 }
3041 else
3042 {
3043 (void)PRINTF("Hostcmd failed error: %d", ret);
3044 }
3045 }
3046
3047 static void dump_wlan_eu_crypto_gcmp_128(void)
3048 {
3049 (void)PRINTF("Usage:\r\n");
3050 (void)PRINTF("Algorithm AES-GCMP-128 encryption and decryption verification\r\n");
3051 (void)PRINTF("wlan-eu-crypto-gcmp-128 <EncDec>\r\n");
3052 (void)PRINTF("EncDec: 0-Decrypt, 1-Encrypt\r\n");
3053 }
3054 static void test_wlan_eu_crypto_gcmp_128(int argc, char **argv)
3055 {
3056 unsigned int EncDec = 0U;
3057 t_u8 DATA[80] = {0};
3058 t_u16 Length;
3059 int ret;
3060 t_u16 Dec_DataLength;
3061 t_u16 Dec_DataOnlyLength;
3062 t_u16 Dec_TagLength;
3063 t_u16 Enc_DataLength;
3064 t_u16 KeyLength;
3065 t_u16 NonceLength;
3066 t_u16 AADLength;
3067 if (argc != 2)
3068 {
3069 dump_wlan_eu_crypto_gcmp_128();
3070 (void)PRINTF("Error: invalid number of arguments\r\n");
3071 return;
3072 }
3073 (void)get_uint(argv[1], &EncDec, 1);
3074 if (EncDec != 0U && EncDec != 1U)
3075 {
3076 dump_wlan_eu_crypto_gcmp_128();
3077 (void)PRINTF("Error: invalid EncDec\r\n");
3078 return;
3079 }
3080 /*Algorithm: AES_WRAP*/
3081 t_u8 Key[16] = {0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85, 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f};
3082 KeyLength = 16;
3083 t_u8 EncData[40] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
3084 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
3085 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};
3086 Enc_DataLength = 40;
3087 t_u8 DecDataOnly[40] = {0x60, 0xe9, 0x70, 0x0c, 0xc4, 0xd4, 0x0a, 0xc6, 0xd2, 0x88, 0xb2, 0x01, 0xc3, 0x8f,
3088 0x5b, 0xf0, 0x8b, 0x80, 0x74, 0x42, 0x64, 0x0a, 0x15, 0x96, 0xe5, 0xdb, 0xda, 0xd4,
3089 0x1d, 0x1f, 0x36, 0x23, 0xf4, 0x5d, 0x7a, 0x12, 0xdb, 0x7a, 0xfb, 0x23};
3090 Dec_DataOnlyLength = 40;
3091 #if defined(SD9177) || defined(RW610)
3092 t_u8 DecTag[16] = {0xde, 0xf6, 0x19, 0xc2, 0xa3, 0x74, 0xb6, 0xdf, 0x66, 0xff, 0xa5, 0x3b, 0x6c, 0x69, 0xd7, 0x9e};
3093 #else
3094 t_u8 DecTag[16] = {0xe9, 0x04, 0x97, 0xa1, 0xec, 0x9c, 0x5e, 0x8b, 0x85, 0x5b, 0x9d, 0xc3, 0xa8, 0x16, 0x91, 0xa3};
3095 #endif
3096 Dec_TagLength = 16;
3097
3098 t_u8 DecData[56] = {0}; /*Dec-data-only + Tag*/
3099 memcpy(DecData, DecDataOnly, Dec_DataOnlyLength);
3100 memcpy(DecData + Dec_DataOnlyLength, DecTag, Dec_TagLength);
3101 Dec_DataLength = Dec_DataOnlyLength + Dec_TagLength;
3102
3103 t_u8 Nonce[12] = {0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x00, 0x89, 0x5f, 0x5f, 0x2b, 0x08};
3104 NonceLength = 12;
3105 t_u8 AAD[24] = {0x88, 0x48, 0x0f, 0xd2, 0xe1, 0x28, 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84,
3106 0x44, 0x08, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33, 0x03, 0x00};
3107 AADLength = 24;
3108
3109 if (EncDec == 0U)
3110 {
3111 (void)memcpy(DATA, DecData, Dec_DataLength);
3112 Length = Dec_DataLength;
3113 ret = wlan_set_crypto_AES_GCMP_decrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
3114 }
3115 else
3116 {
3117 (void)memcpy(DATA, EncData, Enc_DataLength);
3118 Length = Enc_DataLength;
3119 ret = wlan_set_crypto_AES_GCMP_encrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
3120 }
3121 if (ret == WM_SUCCESS)
3122 {
3123 (void)PRINTF("Raw Data:\r\n");
3124 if (EncDec == 0U)
3125 {
3126 dump_hex((t_u8 *)DecData, Dec_DataLength);
3127 (void)PRINTF("Decrypted Data:\r\n");
3128 dump_hex((t_u8 *)DATA, Length);
3129 }
3130 else
3131 {
3132 dump_hex((t_u8 *)EncData, Enc_DataLength);
3133 (void)PRINTF("Encrypted Data:\r\n");
3134 dump_hex((t_u8 *)DATA, Length);
3135 }
3136 }
3137 else
3138 {
3139 (void)PRINTF("Hostcmd failed error: %d", ret);
3140 }
3141 }
3142
3143 static void dump_wlan_eu_crypto_gcmp_256(void)
3144 {
3145 (void)PRINTF("Usage:\r\n");
3146 (void)PRINTF("Algorithm AES-GCMP-256 encryption and decryption verification\r\n");
3147 (void)PRINTF("wlan-eu-crypto-gcmp-256 <EncDec>\r\n");
3148 (void)PRINTF("EncDec: 0-Decrypt, 1-Encrypt\r\n");
3149 }
3150 static void test_wlan_eu_crypto_gcmp_256(int argc, char **argv)
3151 {
3152 unsigned int EncDec = 0U;
3153 t_u8 DATA[80] = {0};
3154 t_u16 Length;
3155 int ret;
3156 t_u16 Dec_DataLength;
3157 t_u16 Dec_DataOnlyLength;
3158 t_u16 Dec_TagLength;
3159 t_u16 Enc_DataLength;
3160 t_u16 KeyLength;
3161 t_u16 NonceLength;
3162 t_u16 AADLength;
3163 if (argc != 2)
3164 {
3165 dump_wlan_eu_crypto_gcmp_256();
3166 (void)PRINTF("Error: invalid number of arguments\r\n");
3167 return;
3168 }
3169 (void)get_uint(argv[1], &EncDec, 1);
3170 if (EncDec != 0U && EncDec != 1U)
3171 {
3172 dump_wlan_eu_crypto_gcmp_256();
3173 (void)PRINTF("Error: invalid EncDec\r\n");
3174 return;
3175 }
3176 /*Algorithm: AES_WRAP*/
3177 t_u8 Key[32] = {0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85, 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
3178 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
3179 KeyLength = 32;
3180 t_u8 EncData[40] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
3181 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
3182 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};
3183 Enc_DataLength = 40;
3184
3185 t_u8 DecDataOnly[40] = {0x65, 0x83, 0x43, 0xc8, 0xb1, 0x44, 0x47, 0xd9, 0x21, 0x1d, 0xef, 0xd4, 0x6a, 0xd8,
3186 0x9c, 0x71, 0x0c, 0x6f, 0xc3, 0x33, 0x33, 0x23, 0x6e, 0x39, 0x97, 0xb9, 0x17, 0x6a,
3187 0x5a, 0x8b, 0xe7, 0x79, 0xb2, 0x12, 0x66, 0x55, 0x5e, 0x70, 0xad, 0x79};
3188 Dec_DataOnlyLength = 40;
3189
3190 #if defined(SD9177) || defined(RW610)
3191 t_u8 DecTag[16] = {0x11, 0x43, 0x16, 0x85, 0x90, 0x95, 0x47, 0x3d, 0x5b, 0x1b, 0xd5, 0x96, 0xb3, 0xde, 0xa3, 0xbf};
3192 #else
3193 t_u8 DecTag[16] = {0x11, 0x53, 0x9a, 0x0e, 0x22, 0xc1, 0x26, 0x0c, 0xbb, 0xe8, 0x35, 0x93, 0x35, 0xf3, 0x37, 0x65};
3194 #endif
3195 Dec_TagLength = 16;
3196
3197 t_u8 DecData[56] = {0}; /*Dec-data-only + Tag*/
3198 memcpy(DecData, DecDataOnly, Dec_DataOnlyLength);
3199 memcpy(DecData + Dec_DataOnlyLength, DecTag, Dec_TagLength);
3200 Dec_DataLength = Dec_DataOnlyLength + Dec_TagLength;
3201
3202 t_u8 Nonce[12] = {0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x00, 0x89, 0x5f, 0x5f, 0x2b, 0x08};
3203 NonceLength = 12;
3204 t_u8 AAD[24] = {0x88, 0x48, 0x0f, 0xd2, 0xe1, 0x28, 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84,
3205 0x44, 0x08, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33, 0x03, 0x00};
3206 AADLength = 24;
3207
3208 if (EncDec == 0U)
3209 {
3210 (void)memcpy(DATA, DecData, Dec_DataLength);
3211 Length = Dec_DataLength;
3212 ret = wlan_set_crypto_AES_GCMP_decrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
3213 }
3214 else
3215 {
3216 (void)memcpy(DATA, EncData, Enc_DataLength);
3217 Length = Enc_DataLength;
3218 ret = wlan_set_crypto_AES_GCMP_encrypt(Key, KeyLength, AAD, AADLength, Nonce, NonceLength, DATA, &Length);
3219 }
3220 if (ret == WM_SUCCESS)
3221 {
3222 (void)PRINTF("Raw Data:\r\n");
3223 if (EncDec == 0U)
3224 {
3225 dump_hex((t_u8 *)DecData, Dec_DataLength);
3226 (void)PRINTF("Decrypted Data:\r\n");
3227 dump_hex((t_u8 *)DATA, Length);
3228 }
3229 else
3230 {
3231 dump_hex((t_u8 *)EncData, Enc_DataLength);
3232 (void)PRINTF("Encrypted Data:\r\n");
3233 dump_hex((t_u8 *)DATA, Length);
3234 }
3235 }
3236 else
3237 {
3238 (void)PRINTF("Hostcmd failed error: %d", ret);
3239 }
3240 }
3241 #endif
3242
3243 #if CONFIG_HEAP_DEBUG
3244 int os_mem_alloc_cnt = 0;
3245 int os_mem_free_cnt = 0;
3246
3247 static void test_wlan_os_mem_stat(int argc, char **argv)
3248 {
3249 (void)PRINTF("os_mem_alloc_cnt: %d \r\n", os_mem_alloc_cnt);
3250 (void)PRINTF("os_mem_free_cnt : %d \r\n", os_mem_free_cnt);
3251 (void)PRINTF("FreeHeapSize : %d \r\n\r\n", xPortGetFreeHeapSize());
3252 wlan_show_os_mem_stat();
3253 }
3254 #endif
3255
3256 #if CONFIG_RX_ABORT_CFG
3257 static void dump_wlan_rx_abort_cfg_usage()
3258 {
3259 (void)PRINTF("Usage:\r\n");
3260 (void)PRINTF("Get rx abort config:\r\n");
3261 (void)PRINTF(" wlan-rx-abort-cfg\r\n");
3262 (void)PRINTF("Set rx abort config:\r\n");
3263 (void)PRINTF(" wlan-rx-abort-cfg <enable> <rssi_threshold>\r\n");
3264 (void)PRINTF("Options: \r\n");
3265 (void)PRINTF(" <enable> : 1--Enable 0--Disable\r\n");
3266 (void)PRINTF(" <rssi_threshold>: weak RSSI pkt threshold in dBm (absolute value)\r\n");
3267 (void)PRINTF(" (default = 70)\r\n");
3268 (void)PRINTF("For example:\r\n");
3269 (void)PRINTF(" wlan-rx-abort-cfg : Get current rx abort config\r\n");
3270 (void)PRINTF(" wlan-rx-abort-cfg 1 40 : Enable rx abort and set weak RSSI Threshold to -40 dBm\r\n");
3271 (void)PRINTF(" wlan-rx-abort-cfg 0 : Disable rx abort\r\n");
3272 }
3273
3274 static void test_wlan_rx_abort_cfg(int argc, char **argv)
3275 {
3276 struct wlan_rx_abort_cfg cfg;
3277
3278 if (argc > 3)
3279 {
3280 (void)PRINTF("Error: invalid number of arguments\r\n");
3281 dump_wlan_rx_abort_cfg_usage();
3282 return;
3283 }
3284 (void)memset(&cfg, 0, sizeof(cfg));
3285 /* GET */
3286 if (argc == 1)
3287 {
3288 dump_wlan_rx_abort_cfg_usage();
3289 wlan_set_get_rx_abort_cfg(&cfg, ACTION_GET);
3290 (void)PRINTF("Static Rx Abort %s\r\n", cfg.enable == 1 ? "enabled" : "disabled");
3291 if (cfg.enable == 1)
3292 {
3293 (void)PRINTF("RSSI threshold : %ddBm\r\n", cfg.rssi_threshold);
3294 }
3295 }
3296 /* SET */
3297 else
3298 {
3299 cfg.enable = (t_u8)atoi(argv[1]);
3300 if (cfg.enable)
3301 {
3302 if (argc == 2)
3303 {
3304 cfg.rssi_threshold = 70;
3305 (void)PRINTF("No RSSI threshold set by user.\r\n");
3306 (void)PRINTF("Use default value 70 instead.\r\n");
3307 }
3308 else
3309 {
3310 cfg.rssi_threshold = (int)atoi(argv[2]);
3311 if (cfg.rssi_threshold > 0x7f)
3312 {
3313 (void)PRINTF("Invalid threshold value\r\n");
3314 (void)PRINTF("RSSI threshold should less than 0x7f\r\n");
3315 return;
3316 }
3317 }
3318 }
3319 wlan_set_get_rx_abort_cfg(&cfg, ACTION_SET);
3320 }
3321 return;
3322 }
3323 #endif
3324
3325 #if CONFIG_RX_ABORT_CFG_EXT
3326 static void dump_wlan_rx_abort_cfg_ext_usage()
3327 {
3328 (void)PRINTF("Usage:\r\n");
3329 (void)PRINTF("Get dynamic rx abort cfg:\r\n");
3330 (void)PRINTF(" wlan-get-rx-abort-cfg-ext\r\n");
3331 (void)PRINTF("Set dynamic rx abort cfg:\r\n");
3332 (void)PRINTF(
3333 " wlan-set-rx-abort-cfg-ext enable <enable/disable> margin <margin> ceil <ceil_rssi_thresh> "
3334 "floor <floor_rssi_thresh>\r\n");
3335 (void)PRINTF("Options: \r\n");
3336 (void)PRINTF(" enable <enable>\r\n");
3337 (void)PRINTF(" 0 -- Disable Rx abort\r\n");
3338 (void)PRINTF(" 1 -- Enable Rx abort of pkt having weak RSSI\r\n");
3339 (void)PRINTF(" margin <margin>\r\n");
3340 (void)PRINTF(" rssi margin in dBm (absolute val)\r\n");
3341 (void)PRINTF(" (default = 10)\r\n");
3342 (void)PRINTF(" ceil <ceil_rssi_thresh>\r\n");
3343 (void)PRINTF(" rceiling weak RSSI pkt threshold in dBm (absolute val)\r\n");
3344 (void)PRINTF(" (default = 62)\r\n");
3345 (void)PRINTF(" floor <floor_rssi_thresh>\r\n");
3346 (void)PRINTF(" floor weak RSSI pkt threshold in dBm (absolute val)\r\n");
3347 (void)PRINTF(" (default = 82)\r\n");
3348 (void)PRINTF("For example:\r\n");
3349 (void)PRINTF(" wlan-get-rx-abort-cfg-ext: Display current rx abort configuration\r\n");
3350 (void)PRINTF(" wlan-set-rx-abort-cfg-ext enable 1 margin 5 ceil 40 floor 70 :\r\n");
3351 (void)PRINTF(
3352 " Enable dynamic rx abort,set margin to -5 dBm, set ceil RSSI Threshold to -40 dBm and set floor RSSI "
3353 "threshold to -70 dbm\r\n");
3354 (void)PRINTF(" wlan-set-rx-abort-cfg-ext enable 1\r\n");
3355 (void)PRINTF(" Don't set RSSI margin, drive will set defult RSSI margin threshold value.\r\n");
3356 (void)PRINTF(" Don't set ceil RSSI threshold, driver will set default ceil RSSI threshold value.\r\n");
3357 (void)PRINTF(" Don't set floor RSSI threshold, driver will set default floor RSSI threshold value.\r\n");
3358 (void)PRINTF("\r\n");
3359 (void)PRINTF(" wlan-set-rx-abort-cfg-ext enable 1 ceil 255 \r\n");
3360 (void)PRINTF(" Don't set RSSI margin, drive will set defult RSSI margin threshold value.\r\n");
3361 (void)PRINTF(
3362 " Input ceil RSSI threshold to 0xff, set ceil value to default based on EDMAC enabled or disabled "
3363 "status.\r\n");
3364 (void)PRINTF(" In this case, don't set floor RSSI threshold.\r\n");
3365 (void)PRINTF(" wlan-set-rx-abort-cfg-ext enable 0 : Disable dynamic rx abort\r\n");
3366 }
3367
3368 static void test_wlan_get_rx_abort_cfg_ext(int argc, char **argv)
3369 {
3370 struct wlan_rx_abort_cfg_ext *cfg =
3371 (struct wlan_rx_abort_cfg_ext *)OSA_MemoryAllocate(sizeof(struct wlan_rx_abort_cfg_ext));
3372 (void)memset(cfg, 0, sizeof(*cfg));
3373
3374 wlan_get_rx_abort_cfg_ext(cfg);
3375
3376 (void)PRINTF("Dynamic Rx Abort %s\r\n", cfg->enable == 1 ? "enabled" : "disabled");
3377 if (cfg->enable == 1)
3378 {
3379 int rssi;
3380 rssi = cfg->rssi_margin;
3381 if (rssi > 0x7f)
3382 rssi = -(256 - rssi);
3383 (void)PRINTF("Margin RSSI: %s%d dbm\r\n", ((rssi > 0) ? "-" : ""), rssi);
3384
3385 rssi = cfg->ceil_rssi_threshold;
3386 if (rssi > 0x7f)
3387 rssi = -(256 - rssi);
3388 (void)PRINTF("Ceil RSSI threshold: %s%d dbm\r\n", ((rssi > 0) ? "-" : ""), rssi);
3389
3390 rssi = cfg->floor_rssi_threshold;
3391 if (rssi > 0x7f)
3392 rssi = -(256 - rssi);
3393 (void)PRINTF("Floor rssi threshold: %s%d dbm\r\n", ((rssi > 0) ? "-" : ""), rssi);
3394
3395 rssi = cfg->current_dynamic_rssi_threshold;
3396 if (rssi > 0x7f)
3397 rssi = -(256 - rssi);
3398 (void)PRINTF("Dynamic RSSI Threshold : %d dbm (%s)\r\n", rssi,
3399 cfg->rssi_default_config ? (cfg->edmac_enable ? "EDMAC based" : "Default") : "Config based");
3400 }
3401 (void)PRINTF("\r\n");
3402 OSA_MemoryFree(cfg);
3403 return;
3404 }
3405
3406 static void test_wlan_set_rx_abort_cfg_ext(int argc, char **argv)
3407 {
3408 int arg = 0;
3409 unsigned int value;
3410 struct wlan_rx_abort_cfg_ext cfg;
3411
3412 struct
3413 {
3414 uint8_t enable : 1;
3415 uint8_t margin : 1;
3416 uint8_t ceil_thresh : 1;
3417 uint8_t floor_thresh : 1;
3418 } info;
3419
3420 (void)memset(&info, 0, sizeof(info));
3421
3422 (void)memset(&cfg, 0, sizeof(cfg));
3423
3424 if (argc < 3 && argc > 9)
3425 {
3426 (void)PRINTF("Error: invalid number of arguments\r\n");
3427 dump_wlan_rx_abort_cfg_ext_usage();
3428 return;
3429 }
3430 arg++;
3431 do
3432 {
3433 if (!info.enable && string_equal("enable", argv[arg]))
3434 {
3435 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
3436 {
3437 (void)PRINTF("Error: invalid enable argument\r\n");
3438 dump_wlan_rx_abort_cfg_ext_usage();
3439 return;
3440 }
3441 if (value != 0 && value != 1)
3442 {
3443 (void)PRINTF("Error: invalid action argument\r\n");
3444 dump_wlan_rx_abort_cfg_ext_usage();
3445 return;
3446 }
3447 if (value == 0) /*Disable dynamic rx bort config*/
3448 {
3449 cfg.enable = 0;
3450 break;
3451 }
3452 else /* Enable dynamic rx abort config*/
3453 {
3454 cfg.enable = 1;
3455 }
3456 arg += 2;
3457 info.enable = 1;
3458 }
3459 else if (!info.margin && string_equal("margin", argv[arg]))
3460 {
3461 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
3462 {
3463 (void)PRINTF("Error: invalid margin argument\r\n");
3464 dump_wlan_rx_abort_cfg_ext_usage();
3465 return;
3466 }
3467 if (value > 0x7f)
3468 {
3469 (void)PRINTF("Error: Invalid Margin value\r\n");
3470 dump_wlan_rx_abort_cfg_ext_usage();
3471 return;
3472 }
3473 cfg.rssi_margin = value;
3474 arg += 2;
3475 info.margin = 1;
3476 }
3477 else if (!info.ceil_thresh && string_equal("ceil", argv[arg]))
3478 {
3479 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
3480 {
3481 (void)PRINTF("Error: invalid ceil argument\r\n");
3482 dump_wlan_rx_abort_cfg_ext_usage();
3483 return;
3484 }
3485 if (value > 0x7f && value != 0xff)
3486 {
3487 (void)PRINTF("Error: Invalid ceil value\r\n");
3488 dump_wlan_rx_abort_cfg_ext_usage();
3489 return;
3490 }
3491 cfg.ceil_rssi_threshold = value;
3492 arg += 2;
3493 info.ceil_thresh = 1;
3494 }
3495 else if (!info.floor_thresh && string_equal("floor", argv[arg]))
3496 {
3497 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
3498 {
3499 (void)PRINTF("Error: invalid floor argument\r\n");
3500 dump_wlan_rx_abort_cfg_ext_usage();
3501 return;
3502 }
3503 if (value > 0x7f)
3504 {
3505 (void)PRINTF("Error: Invalid floor value\r\n");
3506 dump_wlan_rx_abort_cfg_ext_usage();
3507 return;
3508 }
3509 cfg.floor_rssi_threshold = value;
3510 arg += 2;
3511 info.floor_thresh = 1;
3512 }
3513 else
3514 {
3515 (void)PRINTF("Error: argument %d is invalid\r\n", arg);
3516 dump_wlan_rx_abort_cfg_ext_usage();
3517 return;
3518 }
3519 } while (arg < argc);
3520
3521 if (cfg.enable == 0)
3522 {
3523 (void)PRINTF("Disable dynamic rx abort config\r\n");
3524 wlan_set_rx_abort_cfg_ext((const struct wlan_rx_abort_cfg_ext *)&cfg);
3525 return;
3526 }
3527 if (cfg.rssi_margin == 0)
3528 {
3529 (void)PRINTF("No Margin RSSI is set by user.\r\n");
3530 (void)PRINTF(" Use default value instead.\r\n");
3531 cfg.rssi_margin = 10;
3532 }
3533
3534 if (cfg.ceil_rssi_threshold == 0)
3535 {
3536 (void)PRINTF("No Ceil RSSI threshold is set by user.\r\n");
3537 (void)PRINTF(" Use default value instead.\r\n");
3538 cfg.ceil_rssi_threshold = 62;
3539 }
3540
3541 if (cfg.floor_rssi_threshold == 0)
3542 {
3543 if (cfg.ceil_rssi_threshold == 0xff)
3544 {
3545 (void)PRINTF("No Floor rssi threshold is set by user.\r\n");
3546 (void)PRINTF(" Driver set floor rssi threshold to 0xff.\r\n");
3547 cfg.floor_rssi_threshold = 0xff;
3548 }
3549 else
3550 {
3551 (void)PRINTF("No Floor rssi threshold is set by user.\r\n");
3552 (void)PRINTF(" Use default value instead.\r\n");
3553 cfg.floor_rssi_threshold = 82;
3554 }
3555 }
3556
3557 wlan_set_rx_abort_cfg_ext((const struct wlan_rx_abort_cfg_ext *)&cfg);
3558
3559 return;
3560 }
3561 #endif
3562
3563 #if CONFIG_CCK_DESENSE_CFG
3564 static void dump_wlan_cck_desense_cfg_usage()
3565 {
3566 (void)PRINTF("Usage:\r\n");
3567 (void)PRINTF("Get current cck desense config:\r\n");
3568 (void)PRINTF(" wlan-cck-desense-cfg\r\n");
3569 (void)PRINTF("Set cck desense config:\r\n");
3570 (void)PRINTF(" wlan-cck-desense-cfg <mode> <margin ceil_thresh> <num_on_intervals num_off_intervals>\r\n");
3571 (void)PRINTF("Options: \r\n");
3572 (void)PRINTF(" <enable> :0 - Disable cck desense\r\n");
3573 (void)PRINTF(" 1 - Enable dynamic cck desense mode\r\n");
3574 (void)PRINTF(" 2 - Enable dynamic enhanced cck desense mode\r\n");
3575 (void)PRINTF(" <margin> :rssi margin in dBm (absolute val)\r\n");
3576 (void)PRINTF(" (default = 10)\r\n");
3577 (void)PRINTF(" <ceil_thresh> :ceiling weak RSSI pkt threshold in dBm (absolute val)\r\n");
3578 (void)PRINTF(" (default = 70)\r\n");
3579 (void)PRINTF(" <num_on_intervals> :number of rateadapt intervals to keep cck desense \"on\"\r\n");
3580 (void)PRINTF(" [for mode 2 only] (default = 20)\r\n");
3581 (void)PRINTF(" <num_off_intervals> :number of rateadapt intervals to keep cck desense \"off\"\r\n");
3582 (void)PRINTF(" [for mode 2 only] (default = 3)\r\n");
3583 (void)PRINTF("For example:\r\n");
3584 (void)PRINTF(" wlan-cck-desense-cfg : Get current cck desense config\r\n");
3585 (void)PRINTF(" wlan-cck-desense-cfg 0 : Disable cck desense\r\n");
3586 (void)PRINTF(
3587 " wlan-cck-desense-cfg 1 10 70 : Set dynamic mode, margin to -10 dBm and ceil RSSI Threshold to -70 "
3588 "dBm\r\n");
3589 (void)PRINTF(
3590 " wlan-cck-desense-cfg 2 10 60 30 5 : Set dynamic enhanced mode, margin to -10 dBm, ceil RSSI Threshold to "
3591 "-60 dBm,\r\n");
3592 (void)PRINTF(" num on intervals to 30 and num off intervals to 5\r\n");
3593 (void)PRINTF(
3594 " wlan-cck-desense-cfg 2 5 60 : Set dynamic enhanced mode, set margin to -5 dBm, set ceil RSSI "
3595 "Threshold to -60 dBm,\r\n");
3596 (void)PRINTF(" and retain previous num on/off intervals setting.\r\n");
3597 }
3598
3599 static void test_wlan_cck_desense_cfg(int argc, char **argv)
3600 {
3601 struct wlan_cck_desense_cfg cfg;
3602 int num_on_intervals = 0;
3603 int num_off_intervals = 0;
3604
3605 if (argc > 6)
3606 {
3607 (void)PRINTF("Error: invalid number of arguments\r\n");
3608 dump_wlan_cck_desense_cfg_usage();
3609 return;
3610 }
3611 memset(&cfg, 0x0, sizeof(cfg));
3612 /* GET */
3613 if (argc == 1)
3614 {
3615 dump_wlan_cck_desense_cfg_usage();
3616 wlan_set_get_cck_desense_cfg(&cfg, ACTION_GET);
3617 (void)PRINTF("CCK Desense %s\r\n", (cfg.mode) ? "enabled" : "disabled");
3618 if (cfg.mode != CCK_DESENSE_MODE_DISABLED)
3619 {
3620 (void)PRINTF("Mode: %s\r\n", (cfg.mode == CCK_DESENSE_MODE_DYNAMIC) ? "Dynamic" : "Dynamic Enhanced");
3621 (void)PRINTF("Margin : %ddBm\r\n", cfg.margin);
3622 (void)PRINTF("Ceil RSSI Threshold : %ddBm\r\n", cfg.ceil_thresh);
3623 }
3624 if (cfg.mode == CCK_DESENSE_MODE_DYN_ENH)
3625 {
3626 (void)PRINTF("Num ON intervals : %d\r\n", cfg.num_on_intervals);
3627 (void)PRINTF("Num OFF intervals : %d\r\n", cfg.num_off_intervals);
3628 }
3629 }
3630 /* SET */
3631 else
3632 {
3633 cfg.mode = (t_u16)atoi(argv[1]);
3634 if (cfg.mode > CCK_DESENSE_MODE_DYN_ENH)
3635 {
3636 (void)PRINTF("Invalid cck desense mode\r\n");
3637 dump_wlan_cck_desense_cfg_usage();
3638 return;
3639 }
3640 if ((cfg.mode == CCK_DESENSE_MODE_DISABLED && argc > 2) ||
3641 (cfg.mode == CCK_DESENSE_MODE_DYNAMIC && argc != 4) ||
3642 (cfg.mode == CCK_DESENSE_MODE_DYN_ENH && (argc < 4 || argc == 5)))
3643 {
3644 (void)PRINTF("Invalid number of args for requested mode\r\n");
3645 dump_wlan_cck_desense_cfg_usage();
3646 return;
3647 }
3648 if (argc > 2)
3649 {
3650 cfg.margin = (int)atoi(argv[2]);
3651 cfg.ceil_thresh = (int)atoi(argv[3]);
3652 if (cfg.margin > 0x7f)
3653 {
3654 (void)PRINTF("Invalid margin value\r\n");
3655 (void)PRINTF("The margin should less than 0x7f\r\n");
3656 return;
3657 }
3658 if (cfg.ceil_thresh > 0x7f)
3659 {
3660 (void)PRINTF("Invalid ceil threshold value\r\n");
3661 (void)PRINTF("The ceil threshold should less than 0x7f\r\n");
3662 return;
3663 }
3664 }
3665 if (argc > 4)
3666 {
3667 num_on_intervals = atoi(argv[4]);
3668 num_off_intervals = atoi(argv[5]);
3669 if (num_on_intervals > 0xff || num_off_intervals > 0xff)
3670 {
3671 (void)PRINTF("Invalid ON/OFF intervals value\r\n");
3672 (void)PRINTF("The ON/OFF interval should less than 0xff\r\n");
3673 return;
3674 }
3675 cfg.num_on_intervals = (t_u8)num_on_intervals;
3676 cfg.num_off_intervals = (t_u8)num_off_intervals;
3677 }
3678 wlan_set_get_cck_desense_cfg(&cfg, ACTION_SET);
3679 }
3680 return;
3681 }
3682 #endif
3683
3684 #if CONFIG_MULTI_CHAN
3685 static void test_wlan_set_multi_chan_status(int argc, char **argv)
3686 {
3687 int ret;
3688 int enable;
3689
3690 if (argc != 2)
3691 {
3692 (void)PRINTF("Invalid arguments\r\n");
3693 return;
3694 }
3695
3696 errno = 0;
3697 enable = strtol(argv[1], NULL, 10);
3698 if (errno != 0)
3699 {
3700 (void)PRINTF("Error during strtol:enable multi chan status errno:%d\r\n", errno);
3701 return;
3702 }
3703
3704 ret = wlan_set_multi_chan_status(enable);
3705 if (ret != WM_SUCCESS)
3706 {
3707 (void)PRINTF("Set multi_chan_status fail, please set before uap start/sta connect\r\n");
3708 }
3709 }
3710
3711 static void test_wlan_get_multi_chan_status(int argc, char **argv)
3712 {
3713 int ret;
3714 int enable;
3715
3716 ret = wlan_get_multi_chan_status(&enable);
3717 if (ret != WM_SUCCESS)
3718 {
3719 (void)PRINTF("Get multi_chan_policy fail\r\n");
3720 return;
3721 }
3722
3723 (void)PRINTF("Get multi_chan_policy %d\r\n", enable);
3724 }
3725
3726 static void dump_drcs_cfg(void)
3727 {
3728 (void)PRINTF("wlan-set-drcs usage:\r\n");
3729 (void)PRINTF("arguments group <channel_time> <switch_time> <undoze_time> <mode>\r\n");
3730 (void)PRINTF("input one group, same settings for both channel 0 and channel 1\r\n");
3731 (void)PRINTF("input two groups, different settings for channel 0 first and then channel 1\r\n");
3732 (void)PRINTF("channel_time: Channel time stayed (in TU 1024us) for chan_idx\r\n");
3733 (void)PRINTF(
3734 "switch_time: Channel switch time (in TU 1024us) for chan_idx, including doze for old channel and undoze for "
3735 "new channel\r\n");
3736 (void)PRINTF("undoze_time: Undoze time during switch time (in TU 1024us) for chan_idx\r\n");
3737 (void)PRINTF("mode: Channel switch scheme 0-PM1, 1-Null2Self\r\n");
3738 (void)PRINTF("Example for same settings for channel 0 and 1:\r\n");
3739 (void)PRINTF("wlan-set-drcs 15 10 5 0:\r\n");
3740 (void)PRINTF("Example for different settings for channel 0 and 1:\r\n");
3741 (void)PRINTF("wlan-set-drcs 15 10 5 0 16 8 4 1:\r\n");
3742 }
3743
3744 static void get_drcs_cfg(char **data, wlan_drcs_cfg_t *drcs_cfg)
3745 {
3746 errno = 0;
3747 drcs_cfg->chantime = (t_u8)strtol(data[0], NULL, 10);
3748 if (errno != 0)
3749 {
3750 (void)PRINTF("Error during strtol:drcs_cfg chantime errno:%d\r\n", errno);
3751 return;
3752 }
3753
3754 errno = 0;
3755 drcs_cfg->switchtime = (t_u8)strtol(data[1], NULL, 10);
3756 if (errno != 0)
3757 {
3758 (void)PRINTF("Error during strtol:drcs_cfg switchtime errno:%d\r\n", errno);
3759 return;
3760 }
3761
3762 errno = 0;
3763 drcs_cfg->undozetime = (t_u8)strtol(data[2], NULL, 10);
3764 if (errno != 0)
3765 {
3766 (void)PRINTF("Error during strtol:drcs_cfg undozetime errno:%d\r\n", errno);
3767 return;
3768 }
3769
3770 errno = 0;
3771 drcs_cfg->mode = (t_u8)strtol(data[3], NULL, 10);
3772 if (errno != 0)
3773 {
3774 (void)PRINTF("Error during strtol:drcs_cfg mode errno:%d\r\n", errno);
3775 return;
3776 }
3777 }
3778
3779 static void test_wlan_set_drcs_cfg(int argc, char **argv)
3780 {
3781 wlan_drcs_cfg_t drcs_cfg[2] = {0};
3782
3783 if (argc != 5 && argc != 9)
3784 {
3785 dump_drcs_cfg();
3786 return;
3787 }
3788
3789 if (argc == 5)
3790 {
3791 get_drcs_cfg(&argv[1], &drcs_cfg[0]);
3792 drcs_cfg[0].chan_idx = 0x03;
3793 }
3794 else
3795 {
3796 get_drcs_cfg(&argv[1], &drcs_cfg[0]);
3797 get_drcs_cfg(&argv[5], &drcs_cfg[1]);
3798 drcs_cfg[0].chan_idx = 0x01;
3799 drcs_cfg[1].chan_idx = 0x02;
3800 }
3801
3802 (void)wlan_set_drcs_cfg(&drcs_cfg[0], 2);
3803 }
3804
3805 static void test_wlan_get_drcs_cfg(int argc, char **argv)
3806 {
3807 int ret;
3808 wlan_drcs_cfg_t drcs_cfg[2] = {0};
3809
3810 ret = wlan_get_drcs_cfg(&drcs_cfg[0], 2);
3811 if (ret != WM_SUCCESS)
3812 {
3813 (void)PRINTF("get drcs cfg fail\r\n");
3814 return;
3815 }
3816
3817 (void)PRINTF("chan_idx: 0x%02x\r\n", drcs_cfg[0].chan_idx);
3818 (void)PRINTF("chan_time: %d\r\n", drcs_cfg[0].chantime);
3819 (void)PRINTF("switch_time: %d\r\n", drcs_cfg[0].switchtime);
3820 (void)PRINTF("undoze_time: %d\r\n", drcs_cfg[0].undozetime);
3821 (void)PRINTF("mode: %d\r\n", drcs_cfg[0].mode);
3822 if (drcs_cfg[0].chan_idx != (t_u16)0x03U)
3823 {
3824 (void)PRINTF("chan_idx: 0x%02x\r\n", drcs_cfg[1].chan_idx);
3825 (void)PRINTF("chan_time: %d\r\n", drcs_cfg[1].chantime);
3826 (void)PRINTF("switch_time: %d\r\n", drcs_cfg[1].switchtime);
3827 (void)PRINTF("undoze_time: %d\r\n", drcs_cfg[1].undozetime);
3828 (void)PRINTF("mode: %d\r\n", drcs_cfg[1].mode);
3829 }
3830 }
3831 #endif
3832
3833 #ifndef STREAM_2X2
3834 static void dump_wlan_set_antcfg_usage(void)
3835 {
3836 (void)PRINTF("Usage:\r\n");
3837 #ifndef RW610
3838 (void)PRINTF("wlan-set-antcfg <ant mode> [evaluate_time] \r\n");
3839 #else
3840 (void)PRINTF("wlan-set-antcfg <ant_mode> <evaluate_time> <evaluate_mode>\r\n");
3841 #endif
3842 (void)PRINTF("\r\n");
3843 (void)PRINTF("\t<ant_mode>: \r\n");
3844 (void)PRINTF("\t 1 -- Tx/Rx antenna 1\r\n");
3845 (void)PRINTF("\t 2 -- Tx/Rx antenna 2\r\n");
3846 (void)PRINTF("\t 0xFFFF -- Tx/Rx antenna diversity\r\n");
3847 (void)PRINTF("\t[evaluate_time]: \r\n");
3848 (void)PRINTF("\t If ant mode = 0xFFFF, use this to configure\r\n");
3849 (void)PRINTF("\t SAD evaluate time interval in milli seconds unit.\r\n");
3850 (void)PRINTF("\t MAX evaluate time is 65535ms.\r\n");
3851 (void)PRINTF("\t If not specified, default value is 6000 milli seconds.\r\n");
3852 #ifdef RW610
3853 (void)PRINTF("\t<evaluate_mode>: \r\n");
3854 (void)PRINTF("\t 0: Ant1 + Ant2\r\n");
3855 (void)PRINTF("\t 1: Ant2 + Ant3\r\n");
3856 (void)PRINTF("\t 2: Ant1 + Ant3\r\n");
3857 (void)PRINTF("\t 255: invalid evaluate mode\r\n");
3858 (void)PRINTF("\t If not used, just keep this field empty.\r\n");
3859 #endif
3860 (void)PRINTF("Examples:\r\n");
3861 (void)PRINTF("wlan-set-antcfg 1\r\n");
3862 (void)PRINTF("wlan-set-antcfg 0xffff\r\n");
3863 (void)PRINTF("wlan-set-antcfg 0xffff 5000\r\n");
3864 #ifdef RW610
3865 (void)PRINTF("wlan-set-antcfg 0xffff 6000 0\r\n");
3866 #endif
3867 }
3868
3869 #ifndef RW610
3870 static void wlan_antcfg_set(int argc, char *argv[])
3871 {
3872 int ret;
3873 uint32_t ant_mode;
3874 uint16_t evaluate_time = 0;
3875
3876 if (!(argc >= 2 && argc <= 3))
3877 {
3878 dump_wlan_set_antcfg_usage();
3879 return;
3880 }
3881
3882 errno = 0;
3883 ant_mode = (uint32_t)strtol(argv[1], NULL, 16);
3884 if (errno != 0)
3885 {
3886 (void)PRINTF("Error during strtol errno:%d", errno);
3887 return;
3888 }
3889
3890 if ((argc == 3) && (ant_mode != 0xFFFFU))
3891 {
3892 dump_wlan_set_antcfg_usage();
3893 return;
3894 }
3895
3896 errno = 0;
3897 if (argc == 3)
3898 {
3899 evaluate_time = (uint16_t)strtol(argv[2], NULL, 10);
3900 }
3901 if (errno != 0)
3902 {
3903 (void)PRINTF("Error during strtol errno:%d", errno);
3904 return;
3905 }
3906
3907 ret = wlan_set_antcfg(ant_mode, evaluate_time);
3908 if (ret == WM_SUCCESS)
3909 {
3910 (void)PRINTF("Antenna configuration successful\r\n");
3911 }
3912 else
3913 {
3914 (void)PRINTF("Antenna configuration failed\r\n");
3915 dump_wlan_set_antcfg_usage();
3916 }
3917 }
3918 #else
3919 static void wlan_antcfg_set(int argc, char *argv[])
3920 {
3921 int ret;
3922 uint32_t ant_mode;
3923 uint16_t evaluate_time = 0;
3924 uint8_t evaluate_mode = 0xFF;
3925
3926 if (argc < 2 || argc > 4)
3927 {
3928 dump_wlan_set_antcfg_usage();
3929 (void)PRINTF("Error: invalid number of arguments\r\n");
3930 return;
3931 }
3932
3933 errno = 0;
3934 ant_mode = (uint32_t)strtol(argv[1], NULL, 16);
3935 if (errno != 0)
3936 {
3937 (void)PRINTF("Error during strtol errno:%d", errno);
3938 return;
3939 }
3940
3941 if ((argc == 3 || argc == 4) && (ant_mode != 0xFFFFU))
3942 {
3943 dump_wlan_set_antcfg_usage();
3944 (void)PRINTF("Error: invalid ant_mode\r\n");
3945 return;
3946 }
3947
3948 errno = 0;
3949 if (argc == 3 || argc == 4)
3950 {
3951 evaluate_time = (uint16_t)strtol(argv[2], NULL, 10);
3952
3953 if (errno != 0)
3954 {
3955 (void)PRINTF("Error during strtol errno:%d", errno);
3956 return;
3957 }
3958 }
3959
3960 errno = 0;
3961 if (argc == 4)
3962 {
3963 evaluate_mode = (uint8_t)strtol(argv[3], NULL, 10);
3964
3965 if (errno != 0)
3966 {
3967 (void)PRINTF("Error during strtol errno:%d", errno);
3968 return;
3969 }
3970
3971 if ((evaluate_mode != 0) && (evaluate_mode != 1) && (evaluate_mode != 2) && (evaluate_mode != 255))
3972 {
3973 dump_wlan_set_antcfg_usage();
3974 (void)PRINTF("Error: invalid evaluate_mode\r\n");
3975 return;
3976 }
3977 }
3978
3979 ret = wlan_set_antcfg(ant_mode, evaluate_time, evaluate_mode);
3980 if (ret == WM_SUCCESS)
3981 {
3982 (void)PRINTF("Antenna configuration successful\r\n");
3983 }
3984 else
3985 {
3986 (void)PRINTF("Antenna configuration failed\r\n");
3987 dump_wlan_set_antcfg_usage();
3988 }
3989 }
3990 #endif /*RW610*/
3991
3992 static void dump_wlan_get_antcfg_usage(void)
3993 {
3994 (void)PRINTF("Usage:\r\n");
3995 (void)PRINTF("wlan-get-antcfg \r\n");
3996 }
3997
3998 static void wlan_antcfg_get(int argc, char *argv[])
3999 {
4000 int ret = -WM_FAIL;
4001 uint32_t ant_mode = 0;
4002 uint16_t evaluate_time = 0;
4003 #ifdef RW610
4004 uint8_t evaluate_mode = 0;
4005 #endif
4006 uint16_t current_antenna = 0;
4007
4008 if (argc != 1)
4009 {
4010 dump_wlan_get_antcfg_usage();
4011 return;
4012 }
4013
4014 #ifndef RW610
4015 ret = wlan_get_antcfg(&ant_mode, &evaluate_time, ¤t_antenna);
4016 #else
4017 ret = wlan_get_antcfg(&ant_mode, &evaluate_time, &evaluate_mode, ¤t_antenna);
4018 #endif
4019 if (ret == WM_SUCCESS)
4020 {
4021 (void)PRINTF("Mode of Tx/Rx path is : %x\r\n", ant_mode);
4022 if (ant_mode == 0XFFFFU)
4023 {
4024 (void)PRINTF("Evaluate time : %d\r\n", evaluate_time);
4025 #ifdef RW610
4026 if (evaluate_mode == 0)
4027 (void)PRINTF("Evaluate mode : Ant1 + Ant2\r\n");
4028 if (evaluate_mode == 1)
4029 (void)PRINTF("Evaluate mode : Ant2 + Ant3\r\n");
4030 if (evaluate_mode == 2)
4031 (void)PRINTF("Evaluate mode : Ant1 + Ant3\r\n");
4032 if (evaluate_mode == 0xFF)
4033 (void)PRINTF("Default diversity mode.\r\n");
4034 #endif
4035 }
4036 if (current_antenna > 0)
4037 {
4038 (void)PRINTF("Current antenna is Ant%d\n", current_antenna);
4039 }
4040 }
4041 else
4042 {
4043 (void)PRINTF("antcfg configuration read failed\r\n");
4044 dump_wlan_get_antcfg_usage();
4045 }
4046 }
4047 #endif
4048
4049 #if CONFIG_SCAN_CHANNEL_GAP
4050 static void test_wlan_set_scan_channel_gap(int argc, char **argv)
4051 {
4052 unsigned scan_chan_gap;
4053 if (argc != 2)
4054 {
4055 (void)PRINTF("Invalid arguments\r\n");
4056 (void)PRINTF("Usage:\r\n");
4057 (void)PRINTF("wlan-scan-channel-gap <scan_gap_value>\r\n");
4058 (void)PRINTF("scan_gap_value: [2,500]\r\n");
4059 return;
4060 }
4061 scan_chan_gap = a2hex_or_atoi(argv[1]);
4062 if (scan_chan_gap < 2 || scan_chan_gap > 500)
4063 {
4064 (void)PRINTF("Invaild scan_gap value!\r\n");
4065 (void)PRINTF("Usage:\r\n");
4066 (void)PRINTF("wlan-scan-channel-gap <scan_gap_value>\r\n");
4067 (void)PRINTF("scan_gap_value: [2,500]\r\n");
4068 return;
4069 }
4070 wlan_set_scan_channel_gap(scan_chan_gap);
4071 }
4072 #endif
4073
4074 #if CONFIG_WMM
4075 static void test_wlan_wmm_tx_stats(int argc, char **argv)
4076 {
4077 int bss_type = atoi(argv[1]);
4078
4079 wlan_wmm_tx_stats_dump(bss_type);
4080 }
4081 #endif
4082
4083 static void test_wlan_set_mac_address(int argc, char **argv)
4084 {
4085 int ret;
4086 uint8_t raw_mac[MLAN_MAC_ADDR_LENGTH];
4087
4088 if (argc != 2)
4089 {
4090 (void)PRINTF("Usage: %s MAC_Address\r\n", argv[0]);
4091 return;
4092 }
4093
4094 ret = get_mac(argv[1], (char *)raw_mac, ':');
4095 if (ret != 0)
4096 {
4097 (void)PRINTF("Error: invalid MAC argument\r\n");
4098 return;
4099 }
4100
4101 wlan_set_mac_addr(raw_mac);
4102 }
4103
4104 #if defined(RW610) && (CONFIG_WIFI_RESET)
4105 static void test_wlan_reset(int argc, char **argv)
4106 {
4107 int option;
4108
4109 option = atoi(argv[1]);
4110 if (argc != 2 || (option != 0 && option != 1 && option != 2))
4111 {
4112 (void)PRINTF("Usage: %s <options>\r\n", argv[0]);
4113 (void)PRINTF("0 to Disable WiFi\r\n");
4114 (void)PRINTF("1 to Enable WiFi\r\n");
4115 (void)PRINTF("2 to Reset WiFi\r\n");
4116 return;
4117 }
4118 #if CONFIG_CSI
4119 if (option == 2)
4120 {
4121 (void)memset((void*)&g_csi_params, 0, sizeof(g_csi_params));
4122 }
4123 #endif
4124 #if CONFIG_NET_MONITOR
4125 if (option == 2)
4126 {
4127 (void)memset((void*)&g_net_monitor_param, 0, sizeof(g_net_monitor_param));
4128 }
4129 #endif
4130
4131 wlan_reset((cli_reset_option)option);
4132 }
4133 #endif
4134
4135 #if CONFIG_ECSA
4136 static void test_wlan_uap_set_ecsa_cfg(int argc, char **argv)
4137 {
4138 int ret;
4139 t_u8 block_tx = 0;
4140 t_u8 oper_class = 0;
4141 t_u8 new_channel = 0;
4142 t_u8 switch_count = 0;
4143 t_u8 band_width = 0;
4144
4145 if ((5 == argc) || (6 == argc))
4146 {
4147 block_tx = (t_u8)atoi(argv[1]);
4148 oper_class = (t_u8)atoi(argv[2]);
4149 new_channel = (t_u8)atoi(argv[3]);
4150 switch_count = (t_u8)atoi(argv[4]);
4151
4152 if (6 == argc)
4153 {
4154 band_width = (t_u8)atoi(argv[5]);
4155 }
4156 }
4157 else
4158 {
4159 (void)PRINTF("Error : invalid number of arguments \r\n");
4160 (void)PRINTF("Usage : %s <block_tx> <oper_class> <new_channel> <switch_count> <bandwidth>\r\n", argv[0]);
4161 (void)PRINTF("block_tx : 0 -- no need to block traffic, 1 -- need block traffic \r\n");
4162 (void)PRINTF(
4163 "oper_class : Operating class according to IEEE std802.11 spec. when 0 is used, only CSA IE will be "
4164 "used\r\n");
4165 (void)PRINTF("new_channel : The channel will switch to \r\n");
4166 (void)PRINTF("switch count : Channel switch time to send ECSA ie \r\n");
4167 (void)PRINTF("bandwidth : Channel width switch to(optional),RW610 only support 20M channels \r\n");
4168
4169 (void)PRINTF("\r\nUsage example : wlan-set-ecsa-cfg 1 0 36 10 1 \r\n");
4170
4171 return;
4172 }
4173
4174 /* Disable action Temporary */
4175 if (0 == switch_count)
4176 {
4177 (void)PRINTF("Error : invalid arguments \r\n");
4178 (void)PRINTF("argv[4] switch_count cannot be 0\r\n");
4179 return;
4180 }
4181
4182 ret = wlan_uap_set_ecsa_cfg(block_tx, oper_class, new_channel, switch_count, band_width);
4183
4184 if (ret != WM_SUCCESS)
4185 {
4186 (void)PRINTF("Failed to set ecsa cfg \r\n");
4187 }
4188 }
4189 #endif /* CONFIG_ECSA */
4190
4191 #if CONFIG_11AX
4192 #if CONFIG_MMSF
4193 static void dump_wlan_set_mmsf_usage()
4194 {
4195 (void)PRINTF("Usage:\r\n");
4196 (void)PRINTF("set mmsf:\r\n");
4197 (void)PRINTF("wlan-set-mmsf <enable> <Density> <MMSF>\r\n");
4198 (void)PRINTF("enable:\r\n");
4199 (void)PRINTF(" 0: disable\r\n");
4200 (void)PRINTF(" 1: enable\r\n");
4201 (void)PRINTF("Density:\r\n");
4202 (void)PRINTF(" Range: [0x0,0xFF]. Default value is 0x30.\r\n");
4203 (void)PRINTF(" Pls enter value like this: 0x20 or 0X20\r\n");
4204 (void)PRINTF("MMSF:\r\n");
4205 (void)PRINTF(" Range: [0x0,0xFF]. Default value is 0x6.\r\n");
4206 (void)PRINTF(" Pls enter value like this: 0x20 or 0X20\r\n");
4207 }
4208
4209 static void test_wlan_set_mmsf(int argc, char **argv)
4210 {
4211 t_u32 value;
4212 int ret;
4213 t_u8 enable, Density, MMSF;
4214
4215 if (argc < 2 || argc > 4)
4216 {
4217 dump_wlan_set_mmsf_usage();
4218 return;
4219 }
4220
4221 if (argc >= 2)
4222 {
4223 if (get_uint(argv[1], &value, strlen(argv[1])) || (value != 0 && value != 1))
4224 {
4225 dump_wlan_set_mmsf_usage();
4226 return;
4227 }
4228 enable = value & 0xFF;
4229 Density = WLAN_AMPDU_DENSITY;
4230 MMSF = WLAN_AMPDU_MMSF;
4231 }
4232
4233 if (argc >= 3)
4234 {
4235 if (argv[2][0] == '0' && (argv[2][1] == 'x' || argv[2][1] == 'X'))
4236 value = a2hex_or_atoi(argv[2]);
4237 else
4238 {
4239 dump_wlan_set_mmsf_usage();
4240 return;
4241 }
4242 Density = value & 0xFF;
4243 }
4244
4245 if (argc == 4)
4246 {
4247 if (argv[3][0] == '0' && (argv[3][1] == 'x' || argv[3][1] == 'X'))
4248 value = a2hex_or_atoi(argv[3]);
4249 else
4250 {
4251 dump_wlan_set_mmsf_usage();
4252 return;
4253 }
4254 MMSF = value & 0xFF;
4255 }
4256
4257 ret = wlan_set_mmsf(enable, Density, MMSF);
4258
4259 if (ret != WM_SUCCESS)
4260 {
4261 (void)PRINTF("Failed to set MMSF config.\r\n");
4262 }
4263 else
4264 {
4265 (void)PRINTF("Success to set MMSF config.\r\n");
4266 }
4267
4268 return;
4269 }
4270
4271 static void test_wlan_get_mmsf(int argc, char **argv)
4272 {
4273 int ret;
4274 t_u8 enable, Density, MMSF;
4275 (void)memset(&enable, 0x0, sizeof(t_u8));
4276 (void)memset(&Density, 0x0, sizeof(t_u8));
4277 (void)memset(&MMSF, 0x0, sizeof(t_u8));
4278
4279 ret = wlan_get_mmsf(&enable, &Density, &MMSF);
4280
4281 if (ret != WM_SUCCESS)
4282 {
4283 (void)PRINTF("Failed to get MMSF configure.\r\n");
4284 }
4285 else
4286 {
4287 (void)PRINTF("MMSF configure:\r\n");
4288 (void)PRINTF("Enable MMSF: %s\r\n", enable == 0 ? "Disable" : "Enable");
4289 (void)PRINTF("Density: 0x%02x\r\n", Density);
4290 (void)PRINTF("MMSF: 0x%02x\r\n", MMSF);
4291 }
4292
4293 return;
4294 }
4295 #endif
4296 #endif /* CONFIG_11AX */
4297
4298 #if CONFIG_WIFI_RECOVERY
4299 static void test_wlan_recovery_test(int argc, char **argv)
4300 {
4301 int ret;
4302 ret = wlan_recovery_test();
4303
4304 if (ret != WM_SUCCESS)
4305 {
4306 (void)PRINTF("timeout happends.\r\n");
4307 }
4308 return;
4309 }
4310 #endif
4311
4312 #if CONFIG_SUBSCRIBE_EVENT_SUPPORT
4313 /**
4314 * @brief This function print the get subscribe event from firmware for user test.
4315 */
4316 static void print_get_sub_event(wlan_ds_subscribe_evt *sub_evt)
4317 {
4318 t_u16 evt_bitmap = sub_evt->evt_bitmap;
4319 PRINTF("evt_bitmap = %u\r\n", evt_bitmap);
4320 if (evt_bitmap & SUBSCRIBE_EVT_RSSI_LOW)
4321 {
4322 PRINTF("rssi low is enabled! ");
4323 PRINTF("value = %u, freq = %u\r\n", sub_evt->low_rssi, sub_evt->low_rssi_freq);
4324 }
4325 if (evt_bitmap & SUBSCRIBE_EVT_RSSI_HIGH)
4326 {
4327 PRINTF("rssi high is enabled! ");
4328 PRINTF("value = %u, freq = %u\r\n", sub_evt->high_rssi, sub_evt->high_rssi_freq);
4329 }
4330 if (evt_bitmap & SUBSCRIBE_EVT_SNR_LOW)
4331 {
4332 PRINTF("snr low is enabled! ");
4333 PRINTF("value = %u, freq = %u\r\n", sub_evt->low_snr, sub_evt->low_snr_freq);
4334 }
4335 if (evt_bitmap & SUBSCRIBE_EVT_SNR_HIGH)
4336 {
4337 PRINTF("snr high is enabled! ");
4338 PRINTF("value = %u, freq = %u\r\n", sub_evt->high_snr, sub_evt->high_snr_freq);
4339 }
4340 if (evt_bitmap & SUBSCRIBE_EVT_MAX_FAIL)
4341 {
4342 PRINTF("max fail is enabled! ");
4343 PRINTF("value = %u, freq = %u\r\n", sub_evt->failure_count, sub_evt->failure_count_freq);
4344 }
4345 if (evt_bitmap & SUBSCRIBE_EVT_BEACON_MISSED)
4346 {
4347 PRINTF("beacon miss is enabled! ");
4348 PRINTF("value = %u, freq = %u\r\n", sub_evt->beacon_miss, sub_evt->beacon_miss_freq);
4349 }
4350 if (evt_bitmap & SUBSCRIBE_EVT_DATA_RSSI_LOW)
4351 {
4352 PRINTF("data rssi low is enabled! ");
4353 PRINTF("value = %u, freq = %u\r\n", sub_evt->data_low_rssi, sub_evt->data_low_rssi_freq);
4354 }
4355 if (evt_bitmap & SUBSCRIBE_EVT_DATA_RSSI_HIGH)
4356 {
4357 PRINTF("data rssi high is enabled! ");
4358 PRINTF("value = %u, freq = %u\r\n", sub_evt->data_high_rssi, sub_evt->data_high_rssi_freq);
4359 }
4360 if (evt_bitmap & SUBSCRIBE_EVT_DATA_SNR_LOW)
4361 {
4362 PRINTF("data snr low is enabled! ");
4363 PRINTF("value = %u, freq = %u\r\n", sub_evt->data_low_snr, sub_evt->data_low_snr_freq);
4364 }
4365 if (evt_bitmap & SUBSCRIBE_EVT_DATA_SNR_HIGH)
4366 {
4367 PRINTF("data snr high is enabled! ");
4368 PRINTF("value = %u, freq = %u\r\n", sub_evt->data_high_snr, sub_evt->data_high_snr_freq);
4369 }
4370 if (evt_bitmap & SUBSCRIBE_EVT_LINK_QUALITY)
4371 {
4372 PRINTF("link quality is enabled! ");
4373 PRINTF(
4374 "link_snr = %u, link_snr_freq = %u, "
4375 "link_rate = %u, link_rate_freq = %u, "
4376 "link_tx_latency = %u, link_tx_lantency_freq = %u\r\n",
4377 sub_evt->link_snr, sub_evt->link_snr_freq, sub_evt->link_rate, sub_evt->link_rate_freq,
4378 sub_evt->link_tx_latency, sub_evt->link_tx_lantency_freq);
4379 }
4380 if (evt_bitmap & SUBSCRIBE_EVT_PRE_BEACON_LOST)
4381 {
4382 PRINTF("pre beacon lost is enabled! ");
4383 PRINTF("value = %u\r\n", sub_evt->pre_beacon_miss);
4384 }
4385 }
4386
4387 /**
4388 * @brief This function dump the usage of wlan-subscribe-event cmd for user test.
4389 */
4390 static void dump_wlan_subscribe_event_usage(void)
4391 {
4392 (void)PRINTF("Usage:\r\n");
4393 (void)PRINTF("Subscribe event to firmware:\r\n");
4394 (void)PRINTF(" wlan-subscribe-event <action> <type> <value> <freq>\r\n");
4395 (void)PRINTF("Options: \r\n");
4396 (void)PRINTF(" <action> : 1:set, 2:get, 3:clear\r\n");
4397 (void)PRINTF(
4398 " <type>: 0:rssi_low, 1:rssi_high 2:snr_low, 3:snr_high, 4:max_fail, 5:beacon_missed, 6:data_rssi_low, "
4399 "7:data_rssi_high, 8:data_snr_low, 9:data_snr_high, 10:link_quality, 11:pre_beacon_lost\r\n");
4400 (void)PRINTF(" <value> : when action is set, specific int type value\r\n");
4401 (void)PRINTF(
4402 " <freq> : when action is set, specific unsigned int type freq, when the freq = 0, "
4403 "the event will trigger one time, and the freq = 1, the event will continually trigger.\r\n");
4404 (void)PRINTF("For example:\r\n");
4405 (void)PRINTF(
4406 " wlan-subscribe-event set 0 50 0 : Subscribe the rssi low event, threshold is 50, freq is 0\r\n"
4407 " wlan-subscribe-event set 2 50 0 : Subscribe the snr low event, threshold is 50, freq is 0\r\n"
4408 " wlan-subscribe-event set 4 50 0 : Subscribe the max_fail event, threshold is 50, freq is 0\r\n"
4409 " wlan-subscribe-event set 5 50 0 : Subscribe the beacon_missed event, threshold is 50, freq is 0\r\n"
4410 " wlan-subscribe-event set 6 50 0 : Subscribe the data rssi low event, threshold is 50, freq is 0\r\n"
4411 " wlan-subscribe-event set 8 50 0 : Subscribe the data snr low event, threshold is 50, freq is 0\r\n"
4412 " wlan-subscribe-event set 11 50 0 : Subscribe the pre_beacon_lost event, threshold is 50, freq is 0\r\n");
4413 (void)PRINTF(
4414 " wlan-subscribe-event set 10 5 0 5 0 5 0 : Subscribe the link quanlity event"
4415 " link_snr threshold is 5, link_snr freq is 0"
4416 " link_rate threshold is 5, link_rate freq is 0"
4417 " link_tx_latency threshold is 5, link_tx_latency freq is 0\r\n");
4418 (void)PRINTF(" wlan-subscribe-event get : Get the all subscribe event parameter\r\n");
4419 (void)PRINTF(
4420 " wlan-subscribe-event clear 0 : Disable the rssi_low event\r\n"
4421 " wlan-subscribe-event clear 2 : Disable the snr_low event\r\n"
4422 " wlan-subscribe-event clear 4 : Disable the max_fail event\r\n"
4423 " wlan-subscribe-event clear 5 : Disable the beacon_missed event\r\n"
4424 " wlan-subscribe-event clear 6 : Disable the data_rssi_low event\r\n"
4425 " wlan-subscribe-event clear 8 : Disable the data_snr_low event\r\n"
4426 " wlan-subscribe-event clear 10 : Disable the link_quality event\r\n"
4427 " wlan-subscribe-event clear 11 : Disable the pre_beacon_lost event\r\n");
4428 }
4429
4430 /**
4431 * @brief This function subscribe event to firmware for user test.
4432 */
4433 static void test_wlan_subscribe_event(int argc, char **argv)
4434 {
4435 int ret = 0;
4436 unsigned int thresh_value = 0, freq = 0;
4437
4438 /*analyse action type*/
4439 switch (argc)
4440 {
4441 case 2:
4442 {
4443 if (strncmp(argv[1], "get", strlen(argv[1])))
4444 {
4445 dump_wlan_subscribe_event_usage();
4446 return;
4447 }
4448 wlan_ds_subscribe_evt sub_evt;
4449 ret = wlan_get_subscribe_event(&sub_evt);
4450 if (ret == WM_SUCCESS)
4451 print_get_sub_event(&sub_evt);
4452 break;
4453 }
4454 case 3:
4455 {
4456 if (strncmp(argv[1], "clear", strlen(argv[1])))
4457 {
4458 dump_wlan_subscribe_event_usage();
4459 return;
4460 }
4461 unsigned int event_id = MAX_EVENT_ID;
4462 if (get_uint(argv[2], &event_id, strlen(argv[2])))
4463 {
4464 dump_wlan_subscribe_event_usage();
4465 return;
4466 }
4467 if (event_id >= MAX_EVENT_ID)
4468 {
4469 dump_wlan_subscribe_event_usage();
4470 return;
4471 }
4472 ret = wlan_clear_subscribe_event(event_id);
4473 break;
4474 }
4475 case 5:
4476 {
4477 if (strncmp(argv[1], "set", strlen(argv[1])))
4478 {
4479 dump_wlan_subscribe_event_usage();
4480 return;
4481 }
4482 if (get_uint(argv[3], &thresh_value, strlen(argv[3])) || get_uint(argv[4], &freq, strlen(argv[4])))
4483 {
4484 dump_wlan_subscribe_event_usage();
4485 return;
4486 }
4487 unsigned int event_id = MAX_EVENT_ID;
4488 if (get_uint(argv[2], &event_id, strlen(argv[2])))
4489 {
4490 dump_wlan_subscribe_event_usage();
4491 return;
4492 }
4493 if (event_id >= MAX_EVENT_ID)
4494 {
4495 dump_wlan_subscribe_event_usage();
4496 return;
4497 }
4498 ret = wlan_set_subscribe_event(event_id, thresh_value, freq);
4499 break;
4500 }
4501 case 9:
4502 {
4503 unsigned int link_snr = 0, link_snr_freq = 0, link_rate = 0;
4504 unsigned int link_rate_freq = 0, link_tx_latency = 0, link_tx_lantency_freq = 0;
4505 if (strncmp(argv[1], "set", strlen(argv[1])))
4506 {
4507 dump_wlan_subscribe_event_usage();
4508 return;
4509 }
4510 if (get_uint(argv[3], &link_snr, strlen(argv[3])))
4511 {
4512 dump_wlan_subscribe_event_usage();
4513 return;
4514 }
4515 if (get_uint(argv[4], &link_snr_freq, strlen(argv[4])))
4516 {
4517 dump_wlan_subscribe_event_usage();
4518 return;
4519 }
4520 if (get_uint(argv[5], &link_rate, strlen(argv[5])))
4521 {
4522 dump_wlan_subscribe_event_usage();
4523 return;
4524 }
4525 if (get_uint(argv[6], &link_rate_freq, strlen(argv[6])))
4526 {
4527 dump_wlan_subscribe_event_usage();
4528 return;
4529 }
4530 if (get_uint(argv[7], &link_tx_latency, strlen(argv[7])))
4531 {
4532 dump_wlan_subscribe_event_usage();
4533 return;
4534 }
4535 if (get_uint(argv[8], &link_tx_lantency_freq, strlen(argv[8])))
4536 {
4537 dump_wlan_subscribe_event_usage();
4538 return;
4539 }
4540 unsigned int event_id = MAX_EVENT_ID;
4541 if (get_uint(argv[2], &event_id, strlen(argv[2])))
4542 {
4543 dump_wlan_subscribe_event_usage();
4544 return;
4545 }
4546 if (event_id >= MAX_EVENT_ID)
4547 {
4548 dump_wlan_subscribe_event_usage();
4549 return;
4550 }
4551 ret = wlan_set_threshold_link_quality(event_id, link_snr, link_snr_freq, link_rate, link_rate_freq,
4552 link_tx_latency, link_tx_lantency_freq);
4553 }
4554 break;
4555 default:
4556 dump_wlan_subscribe_event_usage();
4557 return;
4558 }
4559 if (ret == WM_E_INVAL)
4560 dump_wlan_subscribe_event_usage();
4561 else if (ret != WM_SUCCESS)
4562 (void)PRINTF("wlan-subscribe-event unkown fail\r\n");
4563 return;
4564 }
4565 #endif
4566
4567 #if CONFIG_WIFI_REG_ACCESS
4568 static void dump_wlan_reg_access_usage()
4569 {
4570 (void)PRINTF("Usage:\r\n");
4571 (void)PRINTF("Read the register:\r\n");
4572 (void)PRINTF(" wlan-reg-access <type> <offset>\r\n");
4573 (void)PRINTF("Write the register:\r\n");
4574 (void)PRINTF(" wlan-reg-access <type> <offset> <value>\r\n");
4575 (void)PRINTF("Options: \r\n");
4576 (void)PRINTF(" <type> : 1:MAC, 2:BBP, 3:RF, 4:CAU\r\n");
4577 (void)PRINTF(" <offset>: offset of register\r\n");
4578 (void)PRINTF("For example:\r\n");
4579 (void)PRINTF(" wlan-reg-access 1 0x9b8 : Read the MAC register\r\n");
4580 (void)PRINTF(" wlan-reg-access 1 0x9b8 0x80000000 : Write 0x80000000 to MAC register\r\n");
4581 }
4582
4583 static void test_wlan_reg_access(int argc, char **argv)
4584 {
4585 t_u32 type, offset;
4586 t_u32 value = 0;
4587 t_u16 action = ACTION_GET;
4588 int ret;
4589
4590 if (argc < 3 || argc > 4)
4591 {
4592 dump_wlan_reg_access_usage();
4593 (void)PRINTF("Error: invalid number of arguments\r\n");
4594 return;
4595 }
4596
4597 if ((a2hex_or_atoi(argv[1]) != 1 && a2hex_or_atoi(argv[1]) != 2 && a2hex_or_atoi(argv[1]) != 3 &&
4598 a2hex_or_atoi(argv[1]) != 4))
4599 {
4600 dump_wlan_reg_access_usage();
4601 (void)PRINTF("Error: Illegal register type %s. Must be either '1','2','3' or '4'.\r\n", argv[1]);
4602 return;
4603 }
4604 type = a2hex_or_atoi(argv[1]);
4605 offset = a2hex_or_atoi(argv[2]);
4606 if (argc == 4)
4607 {
4608 action = ACTION_SET;
4609 value = a2hex_or_atoi(argv[3]);
4610 }
4611
4612 ret = wlan_reg_access((wifi_reg_t)type, action, offset, (uint32_t *)&value);
4613
4614 if (ret == WM_SUCCESS)
4615 {
4616 if (action == ACTION_GET)
4617 (void)PRINTF("Value = 0x%x\r\n", value);
4618 else
4619 (void)PRINTF("Set the register successfully\r\n");
4620 }
4621 else
4622 (void)PRINTF("Read/write register failed");
4623 }
4624 #endif
4625
4626 #if CONFIG_WMM_UAPSD
4627 static void test_wlan_wmm_uapsd_qosinfo(int argc, char **argv)
4628 {
4629 unsigned int qos_info = 0xf;
4630 if (argc == 1)
4631 {
4632 wlan_wmm_uapsd_qosinfo((t_u8 *)&qos_info, 0);
4633 (void)PRINTF("qos_info = %d\r\n", qos_info);
4634 }
4635 else if (argc == 2 && !get_uint(argv[1], &qos_info, strlen(argv[1])))
4636 {
4637 if (qos_info == 0)
4638 (void)PRINTF("qos_info can't be zero, input %s\r\n", argv[1]);
4639 else
4640 wlan_wmm_uapsd_qosinfo((t_u8 *)&qos_info, 1);
4641 }
4642 else
4643 {
4644 (void)PRINTF("Usage: %s <null|qos_info>\r\n", argv[0]);
4645 (void)PRINTF("set qos_info value to UAPSD QOS_INFO\r\n");
4646 (void)PRINTF("bit0:VO; bit1:VI; bit2:BK; bit3:BE\r\n");
4647 return;
4648 }
4649 }
4650 static void test_wlan_set_wmm_uapsd(int argc, char **argv)
4651 {
4652 t_u8 enable;
4653
4654 enable = atoi(argv[1]);
4655 if (argc != 2 || (enable != 0 && enable != 1))
4656 {
4657 (void)PRINTF("Usage: %s <enable>\r\n", argv[0]);
4658 (void)PRINTF("0 to Disable UAPSD\r\n");
4659 (void)PRINTF("1 to Enable UAPSD\r\n");
4660 return;
4661 }
4662
4663 (void)wlan_set_wmm_uapsd(enable);
4664 }
4665
4666 static void test_wlan_sleep_period(int argc, char **argv)
4667 {
4668 unsigned int period = 0;
4669 if (argc == 1)
4670 {
4671 wlan_sleep_period(&period, 0);
4672 (void)PRINTF("period = %d\r\n", period);
4673 }
4674 else if (argc == 2 && !get_uint(argv[1], &period, strlen(argv[1])))
4675 wlan_sleep_period(&period, 1);
4676 else
4677 {
4678 (void)PRINTF("Usage: %s <period(ms)>\r\n", argv[0]);
4679 }
4680 }
4681 #endif
4682
4683 #if CONFIG_WIFI_AMPDU_CTRL
4684 static void dump_wlan_ampdu_enable_usage()
4685 {
4686 (void)PRINTF("Usage:\r\n");
4687 (void)PRINTF("wlan-ampdu-enable <sta/uap> <xx: rx:tx bit map. Tx (bit 0), Rx (bit 1> <xx: TID bit map> \r\n");
4688 (void)PRINTF("xx: TID bit map\r\n");
4689 (void)PRINTF(" 1 - TID 0 enable \r\n");
4690 (void)PRINTF(" 2 - TID 1 enable\r\n");
4691 (void)PRINTF(" 4 - TID 2 enable\r\n");
4692 (void)PRINTF(" 7 - TID0, 1, 2 enable\r\n");
4693 (void)PRINTF(" ---------\r\n");
4694 (void)PRINTF(" 255 - TID 0-7 enable \r\n");
4695 (void)PRINTF(" 0 - Disable ampdu \r\n");
4696 (void)PRINTF("Example: disable sta rx/tx ampdu\r\n");
4697 (void)PRINTF(" wlan-ampdu-enable sta 3 0\r\n");
4698 }
4699
4700 static void test_wlan_ampdu_enable(int argc, char **argv)
4701 {
4702 t_u8 tid;
4703 t_u8 direction;
4704 int bss_type = 0;
4705
4706 if (argc != 4)
4707 {
4708 dump_wlan_ampdu_enable_usage();
4709 return;
4710 }
4711
4712 if (string_equal("sta", argv[1]))
4713 bss_type = MLAN_BSS_TYPE_STA;
4714 else if (string_equal("uap", argv[1]))
4715 bss_type = MLAN_BSS_TYPE_UAP;
4716 else
4717 {
4718 dump_wlan_ampdu_enable_usage();
4719 return;
4720 }
4721
4722 direction = atoi(argv[2]);
4723 tid = atoi(argv[3]);
4724
4725 if (bss_type == MLAN_BSS_TYPE_STA)
4726 {
4727 if (is_sta_connected())
4728 {
4729 (void)PRINTF("Error: configure ampdu control before sta connection!\r\n", argv[0]);
4730 return;
4731 }
4732
4733 if (tid)
4734 {
4735 if (direction & 0x01)
4736 {
4737 wlan_sta_ampdu_tx_enable();
4738 wlan_sta_ampdu_tx_enable_per_tid(tid);
4739 }
4740
4741 if (direction & 0x02)
4742 {
4743 wlan_sta_ampdu_rx_enable();
4744 wlan_sta_ampdu_rx_enable_per_tid(tid);
4745 }
4746 }
4747 else
4748 {
4749 if (direction & 0x01)
4750 {
4751 wlan_sta_ampdu_tx_disable();
4752 wlan_sta_ampdu_tx_enable_per_tid(tid);
4753 }
4754
4755 if (direction & 0x02)
4756 {
4757 wlan_sta_ampdu_rx_disable();
4758 wlan_sta_ampdu_rx_enable_per_tid(tid);
4759 }
4760 }
4761 }
4762 else
4763 {
4764 if (is_uap_started())
4765 {
4766 (void)PRINTF("Error: configure ampdu control before uap start!\r\n", argv[0]);
4767 return;
4768 }
4769 if (tid)
4770 {
4771 if (direction & 0x01)
4772 {
4773 wlan_uap_ampdu_tx_enable();
4774 wlan_uap_ampdu_tx_enable_per_tid(tid);
4775 }
4776
4777 if (direction & 0x02)
4778 {
4779 wlan_uap_ampdu_rx_enable();
4780 wlan_uap_ampdu_rx_enable_per_tid(tid);
4781 }
4782 }
4783 else
4784 {
4785 if (direction & 0x01)
4786 {
4787 wlan_uap_ampdu_tx_disable();
4788 wlan_uap_ampdu_tx_enable_per_tid(tid);
4789 }
4790
4791 if (direction & 0x02)
4792 {
4793 wlan_uap_ampdu_rx_disable();
4794 wlan_uap_ampdu_rx_enable_per_tid(tid);
4795 }
4796 }
4797 }
4798 }
4799 #endif
4800
4801 #if CONFIG_TX_AMPDU_PROT_MODE
4802 static void dump_wlan_tx_ampdu_prot_mode_usage()
4803 {
4804 (void)PRINTF("Usage:\r\n");
4805 (void)PRINTF(" wlan-tx-ampdu-prot-mode <mode>\r\n");
4806 (void)PRINTF(" <mode>: 0 - Set RTS/CTS mode \r\n");
4807 (void)PRINTF(" 1 - Set CTS2SELF mode \r\n");
4808 (void)PRINTF(" 2 - Disable Protection mode \r\n");
4809 (void)PRINTF(" 3 - Set Dynamic RTS/CTS mode \r\n");
4810 (void)PRINTF("Example:\r\n");
4811 (void)PRINTF(" wlan-tx-ampdu-prot-mode\r\n");
4812 (void)PRINTF(" - Get currently set protection mode for TX AMPDU.\r\n");
4813 (void)PRINTF(" wlan-tx-ampdu-prot-mode 1\r\n");
4814 (void)PRINTF(" - Set protection mode for TX AMPDU to CTS2SELF.\r\n");
4815 }
4816
4817 static void test_wlan_tx_ampdu_prot_mode(int argc, char **argv)
4818 {
4819 tx_ampdu_prot_mode_para data;
4820
4821 if (argc > 2)
4822 {
4823 (void)PRINTF("Error: invalid number of arguments\r\n");
4824 dump_wlan_tx_ampdu_prot_mode_usage();
4825 return;
4826 }
4827
4828 /* GET */
4829 if (argc == 1)
4830 {
4831 dump_wlan_tx_ampdu_prot_mode_usage();
4832 wlan_tx_ampdu_prot_mode(&data, ACTION_GET);
4833 (void)PRINTF("\r\nTx AMPDU protection mode: ");
4834 switch (data.mode)
4835 {
4836 case TX_AMPDU_RTS_CTS:
4837 (void)PRINTF("RTS/CTS\r\n");
4838 break;
4839 case TX_AMPDU_CTS_2_SELF:
4840 (void)PRINTF("CTS-2-SELF\r\n");
4841 break;
4842 case TX_AMPDU_DISABLE_PROTECTION:
4843 (void)PRINTF("Disabled\r\n");
4844 break;
4845 case TX_AMPDU_DYNAMIC_RTS_CTS:
4846 (void)PRINTF("DYNAMIC RTS/CTS\r\n");
4847 break;
4848 default:
4849 (void)PRINTF("Invalid protection mode\r\n");
4850 break;
4851 }
4852 }
4853 else /* SET */
4854 {
4855 data.mode = atoi(argv[1]);
4856 if (data.mode < 0 || data.mode > 3)
4857 {
4858 (void)PRINTF("Error: invalid protection mode\r\n");
4859 dump_wlan_tx_ampdu_prot_mode_usage();
4860 return;
4861 }
4862 wlan_tx_ampdu_prot_mode(&data, ACTION_SET);
4863 }
4864 }
4865 #endif
4866
4867 #if CONFIG_CSI
4868 static void dump_wlan_csi_filter_usage()
4869 {
4870 (void)PRINTF("Error: invalid number of arguments\r\n");
4871 (void)PRINTF("Usage : wlan-set-csi-filter <opt> <macaddr> <pkt_type> <type> <flag>\r\n");
4872 (void)PRINTF("opt : add/delete/clear/dump \r\n");
4873 (void)PRINTF("add : All options need to be filled in \r\n");
4874 (void)PRINTF("delete: Delete recent filter information \r\n");
4875 (void)PRINTF("clear : Clear all filter information \r\n");
4876 (void)PRINTF("dump : Dump csi cfg information \r\n");
4877
4878 (void)PRINTF("\r\nUsage example : \r\n");
4879 (void)PRINTF("wlan-set-csi-filter add 00:18:E7:ED:2D:C1 255 255 0 \r\n");
4880 (void)PRINTF("wlan-set-csi-filter delete \r\n");
4881 (void)PRINTF("wlan-set-csi-filter clear \r\n");
4882 (void)PRINTF("wlan-set-csi-filter dump \r\n");
4883 }
4884
4885 void dump_csi_param_header()
4886 {
4887 (void)PRINTF("\r\nThe current csi_param is: \r\n");
4888 if (g_csi_params.bss_type == 0)
4889 (void)PRINTF("bss_type : sta\r\n");
4890 else
4891 (void)PRINTF("bss_type : uap\r\n");
4892 (void)PRINTF("csi_enable : %d \r\n", g_csi_params.csi_enable);
4893 (void)PRINTF("head_id : %d \r\n", g_csi_params.head_id);
4894 (void)PRINTF("tail_id : %d \r\n", g_csi_params.tail_id);
4895 (void)PRINTF("csi_filter_cnt: %d \r\n", g_csi_params.csi_filter_cnt);
4896 (void)PRINTF("chip_id : %d \r\n", g_csi_params.chip_id);
4897 (void)PRINTF("band_config : %d \r\n", g_csi_params.band_config);
4898 (void)PRINTF("channel : %d \r\n", g_csi_params.channel);
4899 (void)PRINTF("csi_monitor_enable : %d \r\n", g_csi_params.csi_monitor_enable);
4900 (void)PRINTF("ra4us : %d \r\n", g_csi_params.ra4us);
4901
4902 (void)PRINTF("\r\n");
4903 }
4904
4905 void set_csi_param_header(t_u8 bss_type,
4906 t_u16 csi_enable,
4907 t_u32 head_id,
4908 t_u32 tail_id,
4909 t_u8 chip_id,
4910 t_u8 band_config,
4911 t_u8 channel,
4912 t_u8 csi_monitor_enable,
4913 t_u8 ra4us)
4914 {
4915 g_csi_params.bss_type = bss_type;
4916 g_csi_params.csi_enable = csi_enable;
4917 g_csi_params.head_id = head_id;
4918 g_csi_params.tail_id = tail_id;
4919 g_csi_params.chip_id = chip_id;
4920 g_csi_params.band_config = band_config;
4921 g_csi_params.channel = channel;
4922 g_csi_params.csi_monitor_enable = csi_monitor_enable;
4923 g_csi_params.ra4us = ra4us;
4924
4925 dump_csi_param_header();
4926 }
4927
4928 void set_csi_filter(t_u8 pkt_type, t_u8 subtype, t_u8 flags, int op_index, t_u8 *mac)
4929 {
4930 t_u8 temp_filter_cnt = g_csi_params.csi_filter_cnt;
4931 int i = 0;
4932
4933 switch (op_index)
4934 {
4935 case CSI_FILTER_OPT_ADD:
4936 if (temp_filter_cnt < CSI_FILTER_MAX)
4937 {
4938 (void)memcpy(&g_csi_params.csi_filter[temp_filter_cnt].mac_addr[0], mac, MLAN_MAC_ADDR_LENGTH);
4939 g_csi_params.csi_filter[temp_filter_cnt].pkt_type = pkt_type;
4940 g_csi_params.csi_filter[temp_filter_cnt].subtype = subtype;
4941 g_csi_params.csi_filter[temp_filter_cnt].flags = flags;
4942 g_csi_params.csi_filter_cnt++;
4943 }
4944 else
4945 {
4946 (void)PRINTF("max csi filter cnt is 16 \r\n");
4947 return;
4948 }
4949 break;
4950
4951 case CSI_FILTER_OPT_DELETE:
4952 if (temp_filter_cnt > 0)
4953 {
4954 memset(&g_csi_params.csi_filter[temp_filter_cnt], 0, sizeof(wifi_csi_filter_t));
4955 g_csi_params.csi_filter_cnt--;
4956 }
4957 else
4958 {
4959 (void)PRINTF("csi filter cnt is 0 \r\n");
4960 return;
4961 }
4962 break;
4963
4964 case CSI_FILTER_OPT_CLEAR:
4965 for (i = 0; i < temp_filter_cnt; i++)
4966 {
4967 memset(&g_csi_params.csi_filter[i], 0, sizeof(wifi_csi_filter_t));
4968 }
4969 g_csi_params.csi_filter_cnt = 0;
4970 break;
4971
4972 case CSI_FILTER_OPT_DUMP:
4973 dump_csi_param_header();
4974
4975 for (i = 0; i < temp_filter_cnt; i++)
4976 {
4977 (void)PRINTF("mac_addr : %02X:%02X:%02X:%02X:%02X:%02X \r\n",
4978 g_csi_params.csi_filter[i].mac_addr[0], g_csi_params.csi_filter[i].mac_addr[1],
4979 g_csi_params.csi_filter[i].mac_addr[2], g_csi_params.csi_filter[i].mac_addr[3],
4980 g_csi_params.csi_filter[i].mac_addr[4], g_csi_params.csi_filter[i].mac_addr[5]);
4981
4982 (void)PRINTF("pkt_type : %d \r\n", g_csi_params.csi_filter[i].pkt_type);
4983 (void)PRINTF("subtype : %d \r\n", g_csi_params.csi_filter[i].subtype);
4984 (void)PRINTF("flags : %d \r\n", g_csi_params.csi_filter[i].flags);
4985 (void)PRINTF("\r\n");
4986 }
4987 break;
4988
4989 default:
4990 (void)PRINTF("unknown argument!\r\n");
4991 break;
4992 }
4993 }
4994
4995 int csi_data_recv_user(void *buffer, size_t data_len)
4996 {
4997 PRINTF("CSI user callback: Event CSI data\r\n");
4998 dump_hex(buffer, data_len);
4999 return WM_SUCCESS;
5000 }
5001
5002 static void test_wlan_set_csi_param_header(int argc, char **argv)
5003 {
5004 t_u8 bss_type = 0;
5005 t_u16 csi_enable = 0;
5006 t_u32 head_id = 0;
5007 t_u32 tail_id = 0;
5008 t_u8 chip_id = 0;
5009 t_u8 band_config = 0;
5010 t_u8 channel = 0;
5011 t_u8 csi_monitor_enable = 0;
5012 t_u8 ra4us = 0;
5013 int ret = -1;
5014
5015 if (argc != 10)
5016 {
5017 (void)PRINTF("Error: invalid number of arguments\r\n");
5018 (void)PRINTF(
5019 "Usage: %s <sta/uap> <csi_enable> <head_id> <tail_id> <chip_id> <band_config> <channel> "
5020 "<csi_monitor_enable> "
5021 "<ra4us>\r\n\r\n",
5022 argv[0]);
5023
5024 (void)PRINTF("[csi_enable] :1/2 to Enable/Disable CSI\r\n");
5025 (void)PRINTF("[head_id, head_id, chip_id] are used to seperate CSI event records received from FW\r\n");
5026 (void)PRINTF(
5027 "[Bandcfg] defined as below: \r\n"
5028 " Band Info - (00)=2.4GHz, (01)=5GHz \r\n"
5029 " t_u8 chanBand : 2;\r\n"
5030 " Channel Width - (00)=20MHz, (10)=40MHz, (11)=80MHz\r\n"
5031 " t_u8 chanWidth : 2;\r\n"
5032 " Secondary Channel Offset - (00)=None, (01)=Above, (11)=Below\r\n"
5033 " t_u8 chan2Offset : 2;\r\n"
5034 " Channel Selection Mode - (00)=manual, (01)=ACS, (02)=Adoption mode\r\n"
5035 " t_u8 scanMode : 2;\r\n");
5036 (void)PRINTF("[channel] : monitor channel number\r\n");
5037 (void)PRINTF("[csi_monitor_enable] : 1-csi_monitor enable, 0-MAC filter enable\r\n");
5038 (void)PRINTF(
5039 "[ra4us] : 1/0 to Enable/DisEnable CSI data received in cfg channel with mac addr filter, not only RA is "
5040 "us or other\r\n");
5041
5042 (void)PRINTF("\r\nUsage example : \r\n");
5043 (void)PRINTF("wlan-set-csi-param-header sta 1 66051 66051 170 0 11 1 1\r\n");
5044
5045 dump_csi_param_header();
5046
5047 return;
5048 }
5049
5050 /*
5051 * csi param header headid, tailid, chipid are used to seperate CSI event records received from FW.
5052 * FW adds user configured headid, chipid and tailid for each CSI event record.
5053 * User could configure these fields and used these fields to parse CSI event buffer and do verification.
5054 * All the CSI filters share the same CSI param header.
5055 */
5056 if (string_equal("sta", argv[1]))
5057 bss_type = 0;
5058 else if (string_equal("uap", argv[1]))
5059 bss_type = 1;
5060 else
5061 {
5062 PRINTF("Please put sta or uap\r\n");
5063 return;
5064 }
5065 csi_enable = (t_u16)atoi(argv[2]);
5066 head_id = (t_u32)atoi(argv[3]);
5067 tail_id = (t_u32)atoi(argv[4]);
5068 chip_id = (t_u8)atoi(argv[5]);
5069 band_config = (t_u8)atoi(argv[6]);
5070 channel = (t_u8)atoi(argv[7]);
5071 csi_monitor_enable = (t_u8)atoi(argv[8]);
5072 ra4us = (t_u8)atoi(argv[9]);
5073
5074 if (csi_enable == 1)
5075 {
5076 ret = wlan_register_csi_user_callback(csi_data_recv_user);
5077 if (ret != WM_SUCCESS)
5078 {
5079 PRINTF("Error during register csi user callback\r\n");
5080 }
5081 }
5082
5083 set_csi_param_header(bss_type, csi_enable, head_id, tail_id, chip_id, band_config, channel, csi_monitor_enable,
5084 ra4us);
5085 }
5086
5087 static void test_wlan_set_csi_filter(int argc, char **argv)
5088 {
5089 int ret = 0;
5090 t_u8 raw_mac[MLAN_MAC_ADDR_LENGTH];
5091 t_u8 pkt_type = 0;
5092 t_u8 subtype = 0;
5093 t_u8 flags = 0;
5094 int op_index = 0;
5095
5096 if (argc < 2)
5097 {
5098 dump_wlan_csi_filter_usage();
5099 return;
5100 }
5101
5102 if (string_equal("add", argv[1]))
5103 {
5104 if (6 == argc)
5105 {
5106 ret = get_mac(argv[2], (char *)raw_mac, ':');
5107 if (ret != 0)
5108 {
5109 (void)PRINTF("Error: invalid MAC argument\r\n");
5110 return;
5111 }
5112 if ((memcmp(&raw_mac[0], broadcast_mac, MLAN_MAC_ADDR_LENGTH) == 0) || (raw_mac[0] & 0x01))
5113 {
5114 (void)PRINTF("Error: only support unicast mac\r\n");
5115 return;
5116 }
5117
5118 /*
5119 * pkt_type and subtype are the 802.11 framecontrol pkttype and subtype
5120 * flags:
5121 * bit0 reserved, must be 0
5122 * bit1 set to 1: wait for trigger
5123 * bit2 set to 1: send csi error event when timeout
5124 */
5125 pkt_type = (t_u8)atoi(argv[3]);
5126 subtype = (t_u8)atoi(argv[4]);
5127 flags = (t_u8)atoi(argv[5]);
5128
5129 op_index = CSI_FILTER_OPT_ADD;
5130 }
5131 else
5132 {
5133 dump_wlan_csi_filter_usage();
5134 return;
5135 }
5136 }
5137 else if (string_equal("delete", argv[1]))
5138 op_index = CSI_FILTER_OPT_DELETE;
5139 else if (string_equal("clear", argv[1]))
5140 op_index = CSI_FILTER_OPT_CLEAR;
5141 else if (string_equal("dump", argv[1]))
5142 op_index = CSI_FILTER_OPT_DUMP;
5143 else
5144 {
5145 (void)PRINTF("Unknown argument!\r\n");
5146 return;
5147 }
5148
5149 set_csi_filter(pkt_type, subtype, flags, op_index, raw_mac);
5150 }
5151
5152 static void test_wlan_csi_cfg(int argc, char **argv)
5153 {
5154 int ret;
5155
5156 ret = wlan_csi_cfg(&g_csi_params);
5157
5158 if (ret != WM_SUCCESS)
5159 {
5160 (void)PRINTF("Failed to send csi cfg\r\n");
5161 }
5162 }
5163 #endif
5164
5165 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_11R) || (CONFIG_ROAMING)
5166 static void test_wlan_rssi_low_threshold(int argc, char **argv)
5167 {
5168 uint8_t rssi_threshold;
5169
5170 if (argc < 2)
5171 {
5172 (void)PRINTF("Usage: %s <rssi threshold value>\r\n", argv[0]);
5173 (void)PRINTF("Error: Default value is 70. Specify the value you want to set as threshold.\r\n");
5174 return;
5175 }
5176
5177 errno = 0;
5178 rssi_threshold = (uint8_t)strtol(argv[1], NULL, 10);
5179 if (errno != 0)
5180 {
5181 (void)PRINTF("Error during strtol:rssi_threshold errno:%d\r\n", errno);
5182 return;
5183 }
5184
5185 wlan_set_rssi_low_threshold(rssi_threshold);
5186
5187 (void)PRINTF("rssi threshold set successfully.\r\n");
5188 }
5189 #endif
5190
5191 #if CONFIG_NET_MONITOR
5192 static void dump_wlan_set_monitor_filter_usage()
5193 {
5194 (void)PRINTF("Error : invalid arguments\r\n");
5195 (void)PRINTF("Usage : wlan-set-monitor-filter <opt> <macaddr>\r\n");
5196 (void)PRINTF("opt : add/delete/clear/dump \r\n");
5197 (void)PRINTF("add : All options need to be filled in \r\n");
5198 (void)PRINTF("delete: Delete recent mac addr \r\n");
5199 (void)PRINTF("clear : Clear all mac addr \r\n");
5200 (void)PRINTF("dump : Dump monitor cfg information \r\n");
5201
5202 (void)PRINTF("\r\nUsage example :\r\n");
5203 (void)PRINTF("wlan-set-monitor-filter add 64:64:4A:D6:FA:7B \r\n");
5204 (void)PRINTF("wlan-set-monitor-filter delete \r\n");
5205 (void)PRINTF("wlan-set-monitor-filter clear \r\n");
5206 (void)PRINTF("wlan-set-monitor-filter dump \r\n");
5207 }
5208
5209 static void dump_monitor_param()
5210 {
5211 int i = 0;
5212
5213 (void)PRINTF("\r\n");
5214 (void)PRINTF("current parameters: \r\n");
5215 (void)PRINTF("action : %d \r\n", g_net_monitor_param.action);
5216 (void)PRINTF("monitor_activity : %d \r\n", g_net_monitor_param.monitor_activity);
5217 (void)PRINTF("filter_flags : %d \r\n", g_net_monitor_param.filter_flags);
5218 (void)PRINTF("radio_type : %d \r\n", g_net_monitor_param.radio_type);
5219 (void)PRINTF("chan_number : %d \r\n", g_net_monitor_param.chan_number);
5220 (void)PRINTF("filter_num : %d \r\n", g_net_monitor_param.filter_num);
5221 (void)PRINTF("\r\n");
5222
5223 for (i = 0; i < g_net_monitor_param.filter_num; i++)
5224 {
5225 (void)PRINTF("mac_addr : %02X:%02X:%02X:%02X:%02X:%02X \r\n", g_net_monitor_param.mac_addr[i][0],
5226 g_net_monitor_param.mac_addr[i][1], g_net_monitor_param.mac_addr[i][2],
5227 g_net_monitor_param.mac_addr[i][3], g_net_monitor_param.mac_addr[i][4],
5228 g_net_monitor_param.mac_addr[i][5]);
5229 }
5230 }
5231
5232 static void test_wlan_set_monitor_param(int argc, char **argv)
5233 {
5234 if (argc != 6)
5235 {
5236 (void)PRINTF("Error : invalid number of arguments\r\n");
5237 (void)PRINTF("Usage : %s <action> <monitor_activity> <filter_flags> <radio_type> <chan_number>\r\n",
5238 argv[0]);
5239 (void)PRINTF("action : 0/1 to Action Get/Set \r\n");
5240 (void)PRINTF("monitor_activity : 1 to enable and other parameters to disable monitor activity \r\n");
5241 (void)PRINTF("filter_flags : network monitor fitler flag \r\n");
5242 (void)PRINTF("chan_number : channel to monitor \r\n");
5243
5244 (void)PRINTF("\r\nUsage example :\r\n");
5245 (void)PRINTF("wlan-set-monitor-param 1 1 7 0 1 \r\n");
5246
5247 dump_monitor_param();
5248 return;
5249 }
5250
5251 g_net_monitor_param.action = (t_u16)atoi(argv[1]);
5252 g_net_monitor_param.monitor_activity = (t_u16)atoi(argv[2]);
5253
5254 /*
5255 * filter_flags:
5256 * bit 0: (1/0) enable/disable management frame
5257 * bit 1: (1/0) enable/disable control frame
5258 * bit 2: (1/0) enable/disable data frame
5259 */
5260 g_net_monitor_param.filter_flags = (t_u16)atoi(argv[3]);
5261
5262 /*
5263 * radio_type:
5264 * Band Info - (00)=2.4GHz, (01)=5GHz
5265 * t_u8 chanBand : 2;
5266 * Channel Width - (00)=20MHz, (10)=40MHz, (11)=80MHz
5267 * t_u8 chanWidth : 2;
5268 * Secondary Channel Offset - (00)=None, (01)=Above, (11)=Below
5269 * t_u8 chan2Offset : 2;
5270 * Channel Selection Mode - (00)=manual, (01)=ACS, (02)=Adoption mode
5271 * t_u8 scanMode : 2;
5272 */
5273 g_net_monitor_param.radio_type = (t_u8)atoi(argv[4]);
5274 g_net_monitor_param.chan_number = (t_u8)atoi(argv[5]);
5275
5276 dump_monitor_param();
5277 }
5278
5279 void set_monitor_filter(int op_index, t_u8 *mac)
5280 {
5281 t_u8 temp_filter_num = g_net_monitor_param.filter_num;
5282
5283 switch (op_index)
5284 {
5285 case MONITOR_FILTER_OPT_ADD_MAC:
5286 if (temp_filter_num < MAX_MONIT_MAC_FILTER_NUM)
5287 {
5288 (void)memcpy(&g_net_monitor_param.mac_addr[temp_filter_num], mac, MLAN_MAC_ADDR_LENGTH);
5289 g_net_monitor_param.filter_num++;
5290 }
5291 else
5292 {
5293 (void)PRINTF("Max filter num is 3 \r\n");
5294 return;
5295 }
5296 break;
5297
5298 case MONITOR_FILTER_OPT_DELETE_MAC:
5299 if (temp_filter_num > 0)
5300 {
5301 memset(&g_net_monitor_param.mac_addr[temp_filter_num], 0, MLAN_MAC_ADDR_LENGTH);
5302 g_net_monitor_param.filter_num--;
5303 }
5304 else
5305 {
5306 (void)PRINTF("Monitor filter num is 0 \r\n");
5307 return;
5308 }
5309 break;
5310
5311 case MONITOR_FILTER_OPT_CLEAR_MAC:
5312 memset(&g_net_monitor_param.mac_addr[0], 0, MAX_MONIT_MAC_FILTER_NUM * MLAN_MAC_ADDR_LENGTH);
5313 g_net_monitor_param.filter_num = 0;
5314 break;
5315
5316 case MONITOR_FILTER_OPT_DUMP:
5317 dump_monitor_param();
5318 break;
5319
5320 default:
5321 (void)PRINTF("unknown argument!\r\n");
5322 break;
5323 }
5324 }
5325
5326 static void test_wlan_set_monitor_filter(int argc, char **argv)
5327 {
5328 int ret = 0;
5329 t_u8 raw_mac[MLAN_MAC_ADDR_LENGTH];
5330 int op_index = 0;
5331
5332 if (3 == argc)
5333 {
5334 if (string_equal("add", argv[1]))
5335 {
5336 ret = get_mac(argv[2], (char *)raw_mac, ':');
5337 if (ret != 0)
5338 {
5339 (void)PRINTF("Error: invalid MAC argument\r\n");
5340 return;
5341 }
5342 if ((memcmp(&raw_mac[0], broadcast_mac, MLAN_MAC_ADDR_LENGTH) == 0) || (raw_mac[0] & 0x01))
5343 {
5344 (void)PRINTF("Error: only support unicast mac\r\n");
5345 return;
5346 }
5347 op_index = MONITOR_FILTER_OPT_ADD_MAC;
5348 }
5349 else
5350 {
5351 dump_wlan_set_monitor_filter_usage();
5352 return;
5353 }
5354 }
5355 else if (2 == argc)
5356 {
5357 if (string_equal("delete", argv[1]))
5358 op_index = MONITOR_FILTER_OPT_DELETE_MAC;
5359 else if (string_equal("clear", argv[1]))
5360 op_index = MONITOR_FILTER_OPT_CLEAR_MAC;
5361 else if (string_equal("dump", argv[1]))
5362 op_index = MONITOR_FILTER_OPT_DUMP;
5363 else
5364 {
5365 (void)PRINTF("Unknown argument!\r\n\r\n");
5366 dump_wlan_set_monitor_filter_usage();
5367 return;
5368 }
5369 }
5370 else
5371 {
5372 dump_wlan_set_monitor_filter_usage();
5373 return;
5374 }
5375
5376 set_monitor_filter(op_index, raw_mac);
5377 }
5378
5379 /* Due to hardware issues, 9177 needs to scan the specified channel
5380 * that will be monitored before run wlan-net-monitor-cfg
5381 */
5382 static void test_wlan_net_monitor_cfg(int argc, char **argv)
5383 {
5384 int ret;
5385
5386 ret = wlan_net_monitor_cfg(&g_net_monitor_param);
5387
5388 if (ret != WM_SUCCESS)
5389 {
5390 (void)PRINTF("Failed to send monitor cfg\r\n");
5391 }
5392 }
5393 #endif
5394
5395 #if CONFIG_CPU_TASK_STATUS
5396 void test_wlan_cpu_task_info(int argc, char **argv)
5397 {
5398 #if !CONFIG_MEM_POOLS
5399 char *CPU_RunInfo = (char *)OSA_MemoryAllocate(MAX_TASK_INFO_BUF);
5400 #else
5401 char *CPU_RunInfo = (char *)OSA_MemoryPoolAllocate(buf_1024_MemoryPool);
5402 #endif
5403
5404 if (CPU_RunInfo == NULL)
5405 {
5406 (void)PRINTF("os mem alloc failed for CPU run info \r\n");
5407 return;
5408 }
5409
5410 memset(CPU_RunInfo, 0, sizeof(CPU_RunInfo));
5411 // Get tasks status
5412 OSA_GetTaskList(CPU_RunInfo);
5413
5414 /*Relationship between task status and show info
5415 *
5416 * task status show info
5417 * tskRUNNING X
5418 * tskBLOCKED B
5419 * tskREADY R
5420 * tskDELETED D
5421 * tskSUSPENDED S
5422 */
5423 (void)PRINTF("---------------------------------------------\r\n");
5424 (void)PRINTF("taskName Status priority freeStack pid\r\n");
5425 (void)PRINTF("%s", CPU_RunInfo);
5426 (void)PRINTF("---------------------------------------------\r\n");
5427
5428 memset(CPU_RunInfo, 0, task_status_len);
5429 // Get tasks percentage
5430 OSA_GetRuntimeStats(CPU_RunInfo);
5431 (void)PRINTF("taskName runTime Percentage\r\n");
5432 (void)PRINTF("%s", CPU_RunInfo);
5433 (void)PRINTF("---------------------------------------------\r\n\n");
5434
5435 #if !CONFIG_MEM_POOLS
5436 OSA_MemoryFree(CPU_RunInfo);
5437 #else
5438 OSA_MemoryPoolFree(buf_1024_MemoryPool, CPU_RunInfo);
5439 ;
5440 #endif
5441 }
5442 #endif
5443
5444 #if CONFIG_CPU_LOADING
5445 static void dump_wlan_cpu_loading_usage()
5446 {
5447 (void)PRINTF("Usage:\r\n");
5448 (void)PRINTF(" wlan-cpu-loading start <start> sample_loops <number> sample_period <period>\r\n");
5449 (void)PRINTF(" <start>: \r\n");
5450 (void)PRINTF(" 0: stop ongoing collecting cpu loading info.\r\n");
5451 (void)PRINTF(" 1: start collecting cpu loading info.\r\n");
5452 (void)PRINTF(" <number>: \r\n");
5453 (void)PRINTF(" The cycle numbers to collect cpu loading info.\r\n");
5454 (void)PRINTF(
5455 " If no value is set, will keep collect cpu loading info until a stop command is received.\r\n");
5456 (void)PRINTF(" <period>: \r\n");
5457 (void)PRINTF(" The period to collect cpu loading info.\r\n");
5458 (void)PRINTF(" If no value is set, period is asigned as 2s.\r\n");
5459 (void)PRINTF(" Note: The smaller the period, the greater the impact on performance.\r\n");
5460 (void)PRINTF(" For example:\r\n");
5461 (void)PRINTF(" wlan-cpu-loading start 0\r\n");
5462 (void)PRINTF(" stop ongoing collecting cpu loading info.\r\n");
5463 (void)PRINTF(" wlan-cpu-loading start 1 sample_loops 10\r\n");
5464 (void)PRINTF(
5465 " The cycle numbers of collecting cpu loading is 10 and collect period is default value 2s.\r\n");
5466 (void)PRINTF(" wlan-cpu-loading start 1 sample_loops 10 sample_period 5\r\n");
5467 (void)PRINTF(" The cycle numbers of collecting cpu loading is 10 and collect period is 5s.\r\n");
5468 (void)PRINTF(" wlan-cpu-loading start 1\r\n");
5469 (void)PRINTF(" Ongoing colloecting cpu loading info until execute 'wlan-cpu-loading 0'.\r\n");
5470 (void)PRINTF(" wlan-cpu-loading start 1 sample_period 4\r\n");
5471 (void)PRINTF(
5472 " Ongoing colloecting cpu loading info until execute 'wlan-cpu-loading 0'. And the collect period "
5473 "is 4s.\r\n");
5474 }
5475
5476 static void test_wlan_cpu_loading(int argc, char **argv)
5477 {
5478 int arg = 0;
5479 unsigned int value;
5480 uint8_t start, period = 0;
5481 uint32_t number = 0;
5482
5483 struct
5484 {
5485 uint8_t start : 1;
5486 uint8_t number : 1;
5487 uint8_t period : 1;
5488 } info;
5489
5490 (void)memset(&info, 0, sizeof(info));
5491
5492 if (argc < 2 && argc > 4)
5493 {
5494 (void)PRINTF("Error: invalid number of arguments\r\n");
5495 dump_wlan_cpu_loading_usage();
5496 return;
5497 }
5498
5499 arg++;
5500 do
5501 {
5502 if (!info.start && string_equal("start", argv[arg]))
5503 {
5504 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
5505 {
5506 (void)PRINTF("Error: invalid <start> argument\r\n");
5507 dump_wlan_cpu_loading_usage();
5508 return;
5509 }
5510 if (value != 0 && value != 1)
5511 {
5512 (void)PRINTF("Error: invalid <start> argument\r\n");
5513 dump_wlan_cpu_loading_usage();
5514 return;
5515 }
5516
5517 start = value & 0xFF;
5518 arg += 2;
5519 info.start = 1;
5520 }
5521 else if (!info.number && string_equal("sample_loops", argv[arg]))
5522 {
5523 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
5524 {
5525 (void)PRINTF("Error: invalid <number> argument\r\n");
5526 dump_wlan_cpu_loading_usage();
5527 return;
5528 }
5529
5530 number = value;
5531 arg += 2;
5532 info.number = 1;
5533 }
5534 else if (!info.period && string_equal("sample_period", argv[arg]))
5535 {
5536 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
5537 {
5538 (void)PRINTF("Error: invalid <period> argument\r\n");
5539 dump_wlan_cpu_loading_usage();
5540 return;
5541 }
5542
5543 period = value & 0xFF;
5544 arg += 2;
5545 info.period = 1;
5546 }
5547 else
5548 {
5549 (void)PRINTF("Error: argument %d is invalid\r\n", arg);
5550 dump_wlan_cpu_loading_usage();
5551 return;
5552 }
5553 } while (arg < argc);
5554
5555 if (start == 1)
5556 {
5557 (void)PRINTF("Start cpu loading test:\r\n");
5558 if (number == 0)
5559 (void)PRINTF("%s\r\n", "Keeping CPU loading test");
5560 else
5561 (void)PRINTF("Cycle numbers of CPU loading test: %d\r\n", number);
5562
5563 if (period == 0)
5564 (void)PRINTF("Period of CPU loading test: 2s\r\n");
5565 else
5566 (void)PRINTF("Period of CPU loading test: %d s\r\n", period);
5567 }
5568
5569 wlan_cpu_loading(start, number, period);
5570 }
5571 #endif
5572
5573 #if CONFIG_TSP
5574 static void dump_wlan_tsp_cfg_usage()
5575 {
5576 (void)PRINTF("Usage:\r\n");
5577 (void)PRINTF(
5578 " wlan-set-tsp-cfg en <0/1> bo <0-20> high <0-300> low <0-300> "
5579 "dcstep <1-100> dcmin <0-100> hightemp <-100-150> lowtemp <-100-150>\r\n");
5580 (void)PRINTF(" <en>: 0 -- disable 1 -- enable\r\n");
5581 (void)PRINTF(" <bo>: power backoff [0...20]\r\n");
5582 (void)PRINTF(" <high>: High power Threshold [0...300]\r\n");
5583 (void)PRINTF(" <low>: Low power Threshold [0...300]\r\n");
5584 (void)PRINTF(" <dcstep>: Duty Cycle setp [1...100]\r\n");
5585 (void)PRINTF(" <dcmin>: Duty Cycle min [0...100]\r\n");
5586 (void)PRINTF(" <hightemp>: High Throttle Threshold temperature [-100...150]\r\n");
5587 (void)PRINTF(" <lowtemp>: Low Throttle Threshold temperature [-100...150]\r\n");
5588 (void)PRINTF(" High Threshold must be greater than Low Threshold\r\n");
5589 (void)PRINTF(" High Throttle Threshold temperature must be greater than Low Throttle Threshold temperature.\r\n");
5590 (void)PRINTF(" If you want to get tsp cfg, you can just use wlan-get-tsp-cfg.\r\n");
5591 (void)PRINTF("\r\nUsage example : \r\n");
5592 (void)PRINTF(
5593 "wlan-set-tsp-cfg wlan-set-tsp-cfg en 1 bo 0 high 93 low 83 dcstep 5 dcmin 10 hightemp 120 lowtemp 110 \r\n");
5594 (void)PRINTF("wlan-set-tsp-cfg en 0 \r\n");
5595 }
5596 static void test_wlan_set_tsp_cfg(int argc, char **argv)
5597 {
5598 int arg = 0;
5599 unsigned int value;
5600 int tempvalue;
5601 t_u16 enable = 0;
5602 t_u32 back_off = 0;
5603 t_u32 highThreshold = 0;
5604 t_u32 lowThreshold = 0;
5605 t_u32 dutycycstep = 0;
5606 t_u32 dutycycmin = 0;
5607 int highthrtemp = 0;
5608 int lowthrtemp = 0;
5609 int ret = WM_SUCCESS;
5610
5611 struct
5612 {
5613 unsigned enable : 1;
5614 unsigned backoff : 1;
5615 unsigned high : 1;
5616 unsigned low : 1;
5617 unsigned dutycycstep : 1;
5618 unsigned dutycycmin : 1;
5619 unsigned highthrtemp : 1;
5620 unsigned lowthrtemp : 1;
5621 } info;
5622
5623 (void)memset(&info, 0, sizeof(info));
5624
5625 if (argc < 3 || argc > 17)
5626 {
5627 (void)PRINTF("Error: invalid number of arguments\r\n");
5628 dump_wlan_tsp_cfg_usage();
5629 return;
5630 }
5631
5632 arg++;
5633 do
5634 {
5635 if (!info.enable && string_equal("en", argv[arg]))
5636 {
5637 if (get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])) || (value != 0 && value != 1))
5638 {
5639 (void)PRINTF("Error: invalid enable argument\r\n");
5640 dump_wlan_tsp_cfg_usage();
5641 return;
5642 }
5643 arg += 2;
5644 info.enable = 1;
5645 enable = value & 0xFF;
5646 }
5647 else if (!info.backoff && string_equal("bo", argv[arg]))
5648 {
5649 if (get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])) || value > 20)
5650 {
5651 (void)PRINTF("Error: invalid backoff argument\r\n");
5652 dump_wlan_tsp_cfg_usage();
5653 return;
5654 }
5655 arg += 2;
5656 info.backoff = 1;
5657 back_off = value;
5658 }
5659 else if (!info.high && string_equal("high", argv[arg]))
5660 {
5661 if (get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])) || value > 300)
5662 {
5663 (void)PRINTF("Error: invalid high threshold argument\r\n");
5664 dump_wlan_tsp_cfg_usage();
5665 return;
5666 }
5667 arg += 2;
5668 info.high = 1;
5669 highThreshold = value;
5670 }
5671 else if (!info.low && string_equal("low", argv[arg]))
5672 {
5673 if (get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])) || value > 300)
5674 {
5675 (void)PRINTF("Error: invalid low threshold argument\r\n");
5676 dump_wlan_tsp_cfg_usage();
5677 return;
5678 }
5679 arg += 2;
5680 info.low = 1;
5681 lowThreshold = value;
5682 }
5683 else if (!info.dutycycstep && string_equal("dcstep", argv[arg]))
5684 {
5685 if (get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])) || value > 100)
5686 {
5687 (void)PRINTF("Error: invalid dutycycstep argument\r\n");
5688 dump_wlan_tsp_cfg_usage();
5689 return;
5690 }
5691 arg += 2;
5692 info.dutycycstep = 1;
5693 dutycycstep = value;
5694 }
5695 else if (!info.dutycycmin && string_equal("dcmin", argv[arg]))
5696 {
5697 if (get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])) || value > 100)
5698 {
5699 (void)PRINTF("Error: invalid dutycycmin argument\r\n");
5700 dump_wlan_tsp_cfg_usage();
5701 return;
5702 }
5703 arg += 2;
5704 info.dutycycmin = 1;
5705 dutycycmin = value;
5706 }
5707 else if (!info.highthrtemp && string_equal("hightemp", argv[arg]))
5708 {
5709 tempvalue = (int)atoi(argv[arg + 1]);
5710 if (tempvalue < -100 || tempvalue > 150)
5711 {
5712 (void)PRINTF("Error: invalid high throttle temperature threshold argument\r\n");
5713 dump_wlan_tsp_cfg_usage();
5714 return;
5715 }
5716 arg += 2;
5717 info.highthrtemp = 1;
5718 highthrtemp = tempvalue;
5719 }
5720 else if (!info.lowthrtemp && string_equal("lowtemp", argv[arg]))
5721 {
5722 tempvalue = (int)atoi(argv[arg + 1]);
5723 if (tempvalue < -100 || tempvalue > 150)
5724 {
5725 (void)PRINTF("Error: invalid low throttle temperature threshold argument\r\n");
5726 dump_wlan_tsp_cfg_usage();
5727 return;
5728 }
5729 arg += 2;
5730 info.lowthrtemp = 1;
5731 lowthrtemp = tempvalue;
5732 }
5733 else
5734 {
5735 (void)PRINTF("Error: invalid [%d] argument\r\n", arg + 1);
5736 dump_wlan_tsp_cfg_usage();
5737 return;
5738 }
5739 } while (arg < argc);
5740
5741 if (enable && ((highThreshold <= lowThreshold) || (highthrtemp <= lowthrtemp)))
5742 {
5743 (void)PRINTF("Error: High Threshold must be greater than Low Threshold\r\n");
5744 dump_wlan_tsp_cfg_usage();
5745 return;
5746 }
5747
5748 ret = wlan_set_tsp_cfg(enable, back_off, highThreshold, lowThreshold, dutycycstep, dutycycmin, highthrtemp,
5749 lowthrtemp);
5750
5751 if (ret != WM_SUCCESS)
5752 {
5753 (void)PRINTF("Unable to set TSP config\r\n");
5754 return;
5755 }
5756 }
5757
5758 static void test_wlan_get_tsp_cfg(int argc, char **argv)
5759 {
5760 t_u16 enable = 0;
5761 t_u32 back_off = 0;
5762 t_u32 highThreshold = 0;
5763 t_u32 lowThreshold = 0;
5764 t_u32 dutycycstep = 0;
5765 t_u32 dutycycmin = 0;
5766 int highthrtemp = 0;
5767 int lowthrtemp = 0;
5768 int currCAUTemp = 0;
5769 int currRFUTemp = 0;
5770
5771 int ret = WM_SUCCESS;
5772
5773 if (argc != 1)
5774 {
5775 dump_wlan_tsp_cfg_usage();
5776 return;
5777 }
5778
5779 ret = wlan_get_tsp_cfg(&enable, &back_off, &highThreshold, &lowThreshold, &dutycycstep, &dutycycmin, &highthrtemp,
5780 &lowthrtemp, &currCAUTemp, &currRFUTemp);
5781
5782 if (ret != WM_SUCCESS)
5783 {
5784 (void)PRINTF("Unable to get TSP config\r\n");
5785 return;
5786 }
5787
5788 (void)PRINTF("TSP Configuration:\r\n");
5789 (void)PRINTF(" Enable TSP Algorithm: %d\r\n", enable);
5790 (void)PRINTF(" 0: disable 1: enable\r\n");
5791 (void)PRINTF(" Power Management Backoff: %d dB\r\n", back_off);
5792 (void)PRINTF(" Low Power BOT Threshold(celcius): %d\r\n", lowThreshold);
5793 (void)PRINTF(" High Power BOT Threshold(celcius): %d\r\n", highThreshold);
5794 (void)PRINTF(" Duty Cycle setp(percentage): %d\r\n", dutycycstep);
5795 (void)PRINTF(" Duty Cycle min (percentage): %d\r\n", dutycycmin);
5796 (void)PRINTF(" High Throttle Threshold temperature(celcius): %d\r\n", highthrtemp);
5797 (void)PRINTF(" Low Throttle Threshold temperature(celcius): %d\r\n", lowthrtemp);
5798 (void)PRINTF(" CAU TSEN Temperature(celcius): %d\r\n", currCAUTemp);
5799 (void)PRINTF(" RFU Temperature(celcius): %d\r\n", currRFUTemp);
5800 }
5801 #endif
5802
5803 #if CONFIG_CLOUD_KEEP_ALIVE
5804
5805 #include "lwip/priv/tcp_priv.h"
5806 #include "lwip/stats.h"
5807 #include "lwip/inet.h"
5808 #include "lwip/inet_chksum.h"
5809
5810 #define DATA_LEN 1460
5811
5812 static void dump_wlan_tcp_client_usage(void)
5813 {
5814 (void)PRINTF("Usage:\r\n");
5815 (void)PRINTF(" wlan-tcp-client dst_ip <dst_ip> src_port <src_port> dst_port <dst_port>\r\n");
5816 (void)PRINTF(" <dst_ip> Destination IP\r\n");
5817 (void)PRINTF(" <src_port> Source port\r\n");
5818 (void)PRINTF(" <dst_port> Destination port\r\n");
5819 (void)PRINTF(" Please specify dst_ip src_port and dst_port\r\n");
5820 (void)PRINTF(" wlan-tcp-client dst_ip 192.168.1.50 src_port 54236 dst_port 9526\r\n");
5821 }
5822
5823 static err_t wlan_tcp_client_connected(void *arg, struct tcp_pcb *pcb, err_t err)
5824 {
5825 char clientString[] = "hello\r\n";
5826 t_u8 count = 5;
5827 char *clientData = NULL;
5828
5829 clientData = OSA_MemoryAllocate(DATA_LEN);
5830 (void)memset((t_u8 *)clientData, 0, DATA_LEN);
5831 (void)memcpy(clientData, clientString, sizeof(clientString));
5832
5833 while (count--)
5834 {
5835 tcp_write(pcb, clientData, DATA_LEN, TCP_WRITE_FLAG_COPY);
5836 tcp_output(pcb);
5837 }
5838
5839 return ERR_OK;
5840 }
5841
5842 static void test_wlan_tcp_client(int argc, char **argv)
5843 {
5844 struct tcp_pcb *tcp_client_pcb;
5845 ip_addr_t ipaddr;
5846 int arg = 0;
5847 int dst_ip_set = 0;
5848 int src_port_set = 0;
5849 int dst_port_set = 0;
5850 t_u32 dst_ip = 0;
5851 t_u16 src_port = 0;
5852 t_u16 dst_port = 0;
5853 unsigned int port = 0;
5854
5855 if (argc < 2)
5856 {
5857 (void)PRINTF("Error: invalid number of arguments\r\n");
5858 dump_wlan_tcp_client_usage();
5859 return;
5860 }
5861
5862 if (!is_sta_connected())
5863 {
5864 (void)PRINTF("Can not start wlan_tcp_client in disconnected state\r\n");
5865 return;
5866 }
5867
5868 arg += 1;
5869 do
5870 {
5871 if (string_equal("dst_ip", argv[arg]))
5872 {
5873 dst_ip = net_inet_aton(argv[arg + 1]);
5874 dst_ip_set = 1;
5875 arg += 2;
5876 }
5877 else if (string_equal("src_port", argv[arg]))
5878 {
5879 if (arg + 1 >= argc || get_uint(argv[arg + 1], (unsigned int *)&port, strlen(argv[arg + 1])))
5880 {
5881 (void)PRINTF("Error: invalid src_port argument\r\n");
5882 return;
5883 }
5884 src_port = (uint16_t)(port & 0XFFFF);
5885 src_port_set = 1;
5886 arg += 2;
5887 }
5888 else if (string_equal("dst_port", argv[arg]))
5889 {
5890 if (arg + 1 >= argc || get_uint(argv[arg + 1], (unsigned int *)&port, strlen(argv[arg + 1])))
5891 {
5892 (void)PRINTF("Error: invalid dst_port argument\r\n");
5893 return;
5894 }
5895 dst_port = (uint16_t)(port & 0XFFFF);
5896 dst_port_set = 1;
5897 arg += 2;
5898 }
5899 else
5900 {
5901 (void)PRINTF("Error: argument %d is invalid\r\n", arg);
5902 dump_wlan_tcp_client_usage();
5903 return;
5904 }
5905 } while (arg < argc);
5906
5907 if (!dst_ip_set || !src_port_set || !dst_port_set)
5908 {
5909 dump_wlan_tcp_client_usage();
5910 (void)PRINTF("Error: please specify dst_ip src_port and dst_port\r\n");
5911 return;
5912 }
5913
5914 if (!wlan_cloud_keep_alive_enabled(dst_ip, dst_port))
5915 {
5916 (void)PRINTF("Cloud keep alive not started for given destination ip and port\r\n");
5917 return;
5918 }
5919
5920 (void)memcpy(&ipaddr.u_addr.ip4, &dst_ip, sizeof(ip4_addr_t));
5921 #if CONFIG_IPV6
5922 ipaddr.type = IPADDR_TYPE_V4;
5923 #endif
5924
5925 tcp_client_pcb = tcp_new();
5926 tcp_bind(tcp_client_pcb, IP_ADDR_ANY, src_port);
5927
5928 if (tcp_client_pcb != NULL)
5929 {
5930 tcp_connect(tcp_client_pcb, &ipaddr, dst_port, wlan_tcp_client_connected);
5931 }
5932 }
5933
5934 static void dump_wlan_cloud_keep_alive_usage(void)
5935 {
5936 (void)PRINTF("Usage:\r\n");
5937 (void)PRINTF(" wlan-cloud-keep-alive start id <id> dst_mac <dst_mac> dst_ip <dst_ip> dst_port <dst_port>\r\n");
5938 (void)PRINTF(" <id> Keep alive id from 0 to 3\r\n");
5939 (void)PRINTF(" <dst_mac> Destination MAC address\r\n");
5940 (void)PRINTF(" <dst_ip> Destination IP\r\n");
5941 (void)PRINTF(" <dst_port> Destination port\r\n");
5942 (void)PRINTF(" Please specify dst_mac, dst_ip and dst_port\r\n");
5943 (void)PRINTF(" wlan-cloud-keep-alive stop\r\n");
5944 (void)PRINTF(" wlan-cloud-keep-alive reset\r\n");
5945 }
5946
5947 static void test_wlan_cloud_keep_alive(int argc, char **argv)
5948 {
5949 int ret = -WM_FAIL;
5950 int arg = 1;
5951 int id_set = 0;
5952 int dst_mac_set = 0;
5953 int dst_ip_set = 0;
5954 int dst_port_set = 0;
5955
5956 wlan_cloud_keep_alive_t cloud_keep_alive;
5957
5958 /* Period to send keep alive packet, set the default value to 55s(The unit is milliseconds) */
5959 t_u32 send_interval_default = 55000;
5960
5961 /* Period to send retry packet, set the default value to 20s(The unit is milliseconds) */
5962 t_u16 retry_interval_default = 20000;
5963
5964 /* Count to send retry packet, set the default value to 3 */
5965 t_u16 retry_count_default = 3;
5966
5967 if (argc < 2)
5968 {
5969 (void)PRINTF("Error: invalid number of arguments\r\n");
5970 dump_wlan_cloud_keep_alive_usage();
5971 return;
5972 }
5973
5974 memset(&cloud_keep_alive, 0x00, sizeof(wlan_cloud_keep_alive_t));
5975
5976 if (string_equal("start", argv[1]))
5977 {
5978 /* Period to send keep alive packet, set the default value to 55s(The unit is milliseconds) */
5979 cloud_keep_alive.send_interval = send_interval_default;
5980 /* Period to send retry packet, set the default value to 20s(The unit is milliseconds) */
5981 cloud_keep_alive.retry_interval = retry_interval_default;
5982 /* Count to send retry packet, set the default value to 3 */
5983 cloud_keep_alive.retry_count = retry_count_default;
5984
5985 arg += 1;
5986 do
5987 {
5988 if (string_equal("id", argv[arg]))
5989 {
5990 errno = 0;
5991 cloud_keep_alive.mkeep_alive_id = strtol(argv[arg + 1], NULL, 10);
5992 if (errno != 0)
5993 {
5994 (void)PRINTF("Error during strtol:id errno:%d\r\n", errno);
5995 return;
5996 }
5997
5998 id_set = 1;
5999 arg += 2;
6000 }
6001 else if (string_equal("dst_mac", argv[arg]))
6002 {
6003 ret = get_mac(argv[arg + 1], (char *)&cloud_keep_alive.dst_mac, ':');
6004 if (ret != 0)
6005 {
6006 (void)PRINTF("Error: invalid dst_mac argument\r\n");
6007 return;
6008 }
6009 dst_mac_set = 1;
6010 arg += 2;
6011 }
6012 else if (string_equal("dst_ip", argv[arg]))
6013 {
6014 cloud_keep_alive.dst_ip = net_inet_aton(argv[arg + 1]);
6015 dst_ip_set = 1;
6016 arg += 2;
6017 }
6018 else if (string_equal("dst_port", argv[arg]))
6019 {
6020 unsigned int dst_port;
6021
6022 if (arg + 1 >= argc || get_uint(argv[arg + 1], (unsigned int *)&dst_port, strlen(argv[arg + 1])))
6023 {
6024 (void)PRINTF("Error: invalid dst_port argument\r\n");
6025 return;
6026 }
6027 cloud_keep_alive.dst_port = (uint16_t)(dst_port & 0XFFFF);
6028 dst_port_set = 1;
6029 arg += 2;
6030 }
6031 else
6032 {
6033 (void)PRINTF("Error: argument %d is invalid\r\n", arg);
6034 dump_wlan_cloud_keep_alive_usage();
6035 return;
6036 }
6037 } while (arg < argc);
6038 if (!id_set || !dst_mac_set || !dst_ip_set || !dst_port_set)
6039 {
6040 dump_wlan_cloud_keep_alive_usage();
6041 (void)PRINTF("Error: please specify dst_mac, dst_ip and dst_port\r\n");
6042 return;
6043 }
6044
6045 cloud_keep_alive.enable = MTRUE;
6046 }
6047 else if (string_equal("stop", argv[1]))
6048 {
6049 cloud_keep_alive.enable = MFALSE;
6050 cloud_keep_alive.reset = MFALSE;
6051 }
6052 else if (string_equal("reset", argv[1]))
6053 {
6054 cloud_keep_alive.enable = MFALSE;
6055 cloud_keep_alive.reset = MTRUE;
6056 }
6057 else
6058 {
6059 (void)PRINTF("Error: invalid [%d] argument, give start/stop/reset\r\n", arg + 1);
6060 dump_wlan_cloud_keep_alive_usage();
6061 return;
6062 }
6063 if (cloud_keep_alive.enable == MTRUE)
6064 {
6065 ret = wlan_save_cloud_keep_alive_params(&cloud_keep_alive, 0, 0, 0, 0, MTRUE);
6066 }
6067 else
6068 {
6069 ret = wlan_stop_cloud_keep_alive(&cloud_keep_alive);
6070 }
6071 }
6072 #endif
6073
6074 #if STA_SUPPORT
6075 static void test_wlan_get_signal(int argc, char **argv)
6076 {
6077 wlan_rssi_info_t signal;
6078 int ret = WM_SUCCESS;
6079
6080 if (!is_sta_connected())
6081 {
6082 (void)PRINTF("Can not get RSSI information in disconnected state\r\n");
6083 return;
6084 }
6085
6086 (void)memset(&signal, 0, sizeof(wlan_rssi_info_t));
6087
6088 ret = wlan_get_signal_info(&signal);
6089 if (ret != WM_SUCCESS)
6090 {
6091 (void)PRINTF("Unable to get RSSI information\r\n");
6092 return;
6093 }
6094 (void)PRINTF("\tBeaconLast\tBeacon Average\tData Last\tData Average\r\n");
6095 (void)PRINTF("RSSI\t%-10d \t%-10d \t%-10d \t%-10d\r\n", (int)signal.bcn_rssi_last, (int)signal.bcn_rssi_avg,
6096 (int)signal.data_rssi_last, (int)signal.data_rssi_avg);
6097 (void)PRINTF("SNR \t%-10d \t%-10d \t%-10d \t%-10d\r\n", (int)signal.bcn_snr_last, (int)signal.bcn_snr_avg,
6098 (int)signal.data_snr_last, (int)signal.data_snr_avg);
6099 (void)PRINTF("NF \t%-10d \t%-10d \t%-10d \t%-10d\r\n", (int)signal.bcn_nf_last, (int)signal.bcn_nf_avg,
6100 (int)signal.data_nf_last, (int)signal.data_nf_avg);
6101 }
6102 #endif
6103
6104 static void dump_wlan_bandcfg_bit_usage(void)
6105 {
6106 (void)PRINTF(" Bits in Band:\r\n");
6107 (void)PRINTF(" bit 0: B (Not support set)\r\n");
6108 (void)PRINTF(" bit 1: G (Not support set)\r\n");
6109 (void)PRINTF(" bit 2: A (Not support set)\r\n");
6110 (void)PRINTF(" bit 3: GN (Not support set)\r\n");
6111 (void)PRINTF(" bit 4: AN (Not support set)\r\n");
6112 #if CONFIG_11AC
6113 (void)PRINTF(" bit 5: AC 2.4G (Not support set)\r\n");
6114 (void)PRINTF(" bit 6: AC 5G (Not support set)\r\n");
6115 #endif
6116 #if CONFIG_11AX
6117 (void)PRINTF(" bit 8: AX 2.4G\r\n");
6118 (void)PRINTF(" bit 9: AX 5G\r\n");
6119 #endif
6120 }
6121
6122 static void test_wlan_get_bandcfg(int argc, char **argv)
6123 {
6124 wlan_bandcfg_t bandcfg;
6125 int ret = WM_SUCCESS;
6126
6127 (void)memset(&bandcfg, 0, sizeof(bandcfg));
6128
6129 ret = wlan_get_bandcfg(&bandcfg);
6130 if (ret != WM_SUCCESS)
6131 {
6132 (void)PRINTF("Unable to get bandcfg\r\n");
6133 return;
6134 }
6135 (void)PRINTF("\tconfig band: 0x%x\r\n", bandcfg.config_bands);
6136 (void)PRINTF("\tfw band: 0x%x\r\n", bandcfg.fw_bands);
6137 dump_wlan_bandcfg_bit_usage();
6138 }
6139
6140 #if CONFIG_11AX
6141 static void dump_wlan_set_bandcfg(void)
6142 {
6143 (void)PRINTF("Usage:\r\n");
6144 (void)PRINTF(" wlan-set-bandcfg <value>\r\n");
6145 dump_wlan_bandcfg_bit_usage();
6146 }
6147 #endif
6148
6149 static void test_wlan_set_bandcfg(int argc, char **argv)
6150 {
6151 #if CONFIG_11AX
6152 wlan_bandcfg_t bandcfg;
6153 uint32_t bandcfg_11ax_2G = 0;
6154 uint32_t bandcfg_11ax_5G = 0;
6155 uint32_t val = 0;
6156 int ret = WM_SUCCESS;
6157 #endif
6158
6159 #if !CONFIG_11AX
6160 (void)PRINTF("Block set bandcfg when 11AX is not supported.\r\n");
6161 return;
6162 #else
6163
6164 if (argc != 2)
6165 {
6166 (void)PRINTF("Error: invalid number of arguments\r\n");
6167 dump_wlan_set_bandcfg();
6168 return;
6169 }
6170
6171 val = a2hex_or_atoi(argv[1]);
6172
6173 bandcfg_11ax_2G = (val & MBIT(8));
6174 bandcfg_11ax_5G = (val & MBIT(9));
6175
6176 if ((bandcfg_11ax_2G && !bandcfg_11ax_5G) ||
6177 (!bandcfg_11ax_2G && bandcfg_11ax_5G))
6178 {
6179 (void)PRINTF("Please set 11ax 2G/5G bit both 0 or both 1.\r\n");
6180 dump_wlan_set_bandcfg();
6181 return;
6182 }
6183
6184 (void)memset(&bandcfg, 0, sizeof(bandcfg));
6185 ret = wlan_get_bandcfg(&bandcfg);
6186 if (ret != WM_SUCCESS)
6187 {
6188 (void)PRINTF("Unable to get bandcfg\r\n");
6189 return;
6190 }
6191
6192 if (bandcfg_11ax_2G)
6193 {
6194 bandcfg.config_bands |= (MBIT(8));
6195 }
6196 else
6197 {
6198 bandcfg.config_bands &= ~(MBIT(8));
6199 }
6200
6201 if (bandcfg_11ax_5G)
6202 {
6203 bandcfg.config_bands |= (MBIT(9));
6204 }
6205 else
6206 {
6207 bandcfg.config_bands &= ~(MBIT(9));
6208 }
6209
6210 ret = wlan_set_bandcfg(&bandcfg);
6211 if (ret != WM_SUCCESS)
6212 {
6213 (void)PRINTF("Unable to set bandcfg\r\n");
6214 return;
6215 }
6216 #endif
6217 }
6218
6219 static void dump_wlan_set_multiple_dtim_usage(void)
6220 {
6221 (void)PRINTF("Usage:\r\n");
6222 (void)PRINTF(" This command is to set Next Wakeup RX Beacon Time\r\n");
6223 (void)PRINTF(" Will take effect after enter power save mode by command wlan-ieee-ps 1\r\n");
6224 (void)PRINTF(" Next Wakeup RX Beacon Time = DTIM * BeaconPeriod * multiple_dtim\r\n");
6225
6226 (void)PRINTF(" wlan-set-multiple-dtim <value>\r\n");
6227 (void)PRINTF(" <value> Value of multiple dtim, range[1,20]\r\n");
6228 }
6229
6230 static void test_wlan_set_multiple_dtim(int argc, char **argv)
6231 {
6232 uint8_t multiple_dtim = 0;
6233
6234 if (argc != 2)
6235 {
6236 (void)PRINTF("Error: invalid number of arguments\r\n");
6237 dump_wlan_set_multiple_dtim_usage();
6238 return;
6239 }
6240
6241 multiple_dtim = (t_u8)atoi(argv[1]);
6242
6243 if (multiple_dtim < 1 || multiple_dtim > 20)
6244 {
6245 (void)PRINTF("Error: value of multiple dtim is out of range\r\n");
6246 dump_wlan_set_multiple_dtim_usage();
6247 return;
6248 }
6249
6250 wlan_set_ps_cfg(multiple_dtim, 5, 0, 0, PS_MODE_AUTO, DELAY_TO_PS_DEFAULT);
6251 (void)PRINTF("Set multiple dtim to %d\r\n", multiple_dtim);
6252 }
6253
6254 #if CONFIG_SET_SU
6255 static void dump_wlan_set_su_usage(void)
6256 {
6257 (void)PRINTF("Usage:\r\n");
6258 (void)PRINTF(" wlan-set-su <0/1>\r\n");
6259 (void)PRINTF(" <start/stop>: 1 -- stop su\r\n");
6260 (void)PRINTF(" 0 -- start su\r\n");
6261 (void)PRINTF("Example:\r\n");
6262 (void)PRINTF(" wlan-set-su\r\n");
6263 (void)PRINTF(" - Get current su state.\r\n");
6264 (void)PRINTF(" wlan-set-su 1\r\n");
6265 (void)PRINTF(" - stop su\r\n");
6266 }
6267
6268 static void test_wlan_set_su(int argc, char **argv)
6269 {
6270 int ret = -WM_FAIL;
6271 uint32_t reqd_len = 0;
6272 uint8_t state;
6273 uint8_t debug_resp_buf[64] = {0};
6274
6275 (void)memset(debug_resp_buf, 0, sizeof(debug_resp_buf));
6276 /**
6277 * Command taken from debug.conf
6278 * start_su={
6279 * CmdCode=0x008b
6280 * Action:2=1
6281 * SUBID:2=0x101
6282 * Value:4=1 # 1 -- stop_su;
6283 * # 0 -- start_su;
6284 */
6285 uint8_t debug_cmd_buf[] = {0x8b, 0, 0x10, 0, 0, 0, 0, 0, 0x01, 0, 0x01, 0x01, 0x01, 0, 0, 0};
6286
6287 if (argc > 2)
6288 {
6289 (void)PRINTF("Error: invalid number of arguments\r\n");
6290 dump_wlan_set_su_usage();
6291 return;
6292 }
6293
6294 /* SET */
6295 if (argc == 2)
6296 {
6297 state = atoi(argv[1]);
6298 debug_cmd_buf[12] = state;
6299 }
6300 else /* GET */
6301 {
6302 debug_cmd_buf[8] = 0;
6303 }
6304
6305 ret = wlan_send_hostcmd(debug_cmd_buf, sizeof(debug_cmd_buf) / sizeof(uint8_t), debug_resp_buf,
6306 sizeof(debug_resp_buf), &reqd_len);
6307
6308 if (ret == WM_SUCCESS)
6309 {
6310 (void)PRINTF("Hostcmd success, response is\r\n");
6311 for (ret = 0; ret < reqd_len; ret++)
6312 (void)PRINTF("%x\t", debug_resp_buf[ret]);
6313 }
6314 else
6315 {
6316 (void)PRINTF("Hostcmd failed error: %d", ret);
6317 }
6318 }
6319 #endif
6320
6321 #if CONFIG_WIFI_FORCE_RTS
6322 #define HOSTCMD_RESP_BUFF_SIZE 1024
6323 uint8_t debug_resp_buf[HOSTCMD_RESP_BUFF_SIZE] = {0};
6324
6325 static void dump_wlan_set_forceRTS_usage(void)
6326 {
6327 (void)PRINTF("Usage:\r\n");
6328 (void)PRINTF(" wlan-set-forceRTS <0/1>\r\n");
6329 (void)PRINTF(" <start/stop>: 1 -- start forceRTS\r\n");
6330 (void)PRINTF(" 0 -- stop forceRTS\r\n");
6331 (void)PRINTF("Example:\r\n");
6332 (void)PRINTF(" wlan-set-forceRTS\r\n");
6333 (void)PRINTF(" - Get current forceRTS state.\r\n");
6334 (void)PRINTF(" wlan-set-forceRTS 1\r\n");
6335 (void)PRINTF(" - Set start forceRTS\r\n");
6336 }
6337
6338 /* Bypass wmmTurboMode TxopLimit setting if for certificate is true, for BE traffic only. (Case: HE 5.71.1) */
6339 static void test_wlan_set_forceRTS(int argc, char **argv)
6340 {
6341 int ret = -WM_FAIL;
6342 uint32_t reqd_len = 0;
6343 uint8_t state;
6344 /**
6345 * Command taken from debug.conf
6346 * start_forceRTS={
6347 * CmdCode=0x008b
6348 * Action:2=1
6349 * SUBID:2=0x104
6350 * Value:1=1 # 1 -- start forceRTS;
6351 * # 0 -- stop forceRTS;
6352 */
6353 uint8_t debug_cmd_buf[] = {0x8b, 0, 0x0d, 0, 0, 0, 0, 0, 0x01, 0, 0x04, 0x01, 0x01};
6354
6355 if (argc > 2)
6356 {
6357 (void)PRINTF("Error: invalid number of arguments\r\n");
6358 dump_wlan_set_forceRTS_usage();
6359 return;
6360 }
6361
6362 /* SET */
6363 if (argc == 2)
6364 {
6365 state = atoi(argv[1]);
6366 debug_cmd_buf[12] = state;
6367 }
6368 else /* GET */
6369 {
6370 dump_wlan_set_forceRTS_usage();
6371 debug_cmd_buf[8] = 0;
6372 }
6373
6374 ret = wlan_send_hostcmd(debug_cmd_buf, sizeof(debug_cmd_buf) / sizeof(uint8_t), debug_resp_buf,
6375 HOSTCMD_RESP_BUFF_SIZE, &reqd_len);
6376
6377 if (ret == WM_SUCCESS)
6378 {
6379 (void)PRINTF("Hostcmd success, response is\r\n");
6380 for (ret = 0; ret < reqd_len; ret++)
6381 (void)PRINTF("%x\t", debug_resp_buf[ret]);
6382 }
6383 else
6384 {
6385 (void)PRINTF("Hostcmd failed error: %d", ret);
6386 }
6387 }
6388 #endif
6389
6390 #if (CONFIG_IPS)
6391 static void dump_wlan_set_ips_usage()
6392 {
6393 (void)PRINTF("Usage:\r\n");
6394 (void)PRINTF("wlan-set-ips option\r\n");
6395 (void)PRINTF("option:\r\n");
6396 (void)PRINTF("0: disable ips enhance\r\n");
6397 (void)PRINTF("1: enable ips enhance\r\n");
6398 }
6399 static void test_wlan_set_ips(int argc, char **argv)
6400 {
6401 unsigned int option;
6402
6403 if (argc != 2)
6404 {
6405 (void)PRINTF("Error: invalid number of arguments\r\n");
6406 dump_wlan_set_ips_usage();
6407 return;
6408 }
6409
6410 if (get_uint(argv[1], &option, strlen(argv[1])))
6411 {
6412 (void)PRINTF("Error: invalid option argument\r\n");
6413 dump_wlan_set_ips_usage();
6414 return;
6415 }
6416
6417 if (option != 0 && option != 1)
6418 {
6419 (void)PRINTF("Error: invalid option argument\r\n");
6420 dump_wlan_set_ips_usage();
6421 return;
6422 }
6423
6424 wlan_set_ips(option);
6425 }
6426 #endif
6427
6428 #if (CONFIG_WPA_SUPP_WPS) || (CONFIG_WPS2)
6429 static void test_wlan_start_wps_pbc(int argc, char **argv)
6430 {
6431 int ret;
6432
6433 if (argc != 1)
6434 {
6435 (void)PRINTF("Error: invalid number of arguments\r\n");
6436 return;
6437 }
6438
6439 ret = wlan_start_wps_pbc();
6440
6441 if (ret == -WM_FAIL)
6442 {
6443 PRINTF("Start WPS PBC failed\r\n");
6444 }
6445 else if (ret == -2)
6446 {
6447 PRINTF("FAIL-PBC-OVERLAP\r\n");
6448 }
6449 else
6450 {
6451 PRINTF("Started WPS PBC session\r\n");
6452 }
6453 }
6454
6455 static void test_wlan_start_wps_pin(int argc, char **argv)
6456 {
6457 int ret = -WM_FAIL;
6458
6459 if (argc != 2)
6460 {
6461 (void)PRINTF("Error: invalid number of arguments\r\n");
6462 return;
6463 }
6464
6465 #if (CONFIG_WPA_SUPP_WPS)
6466 ret = wlan_start_wps_pin(argv[1]);
6467 #else
6468 ret = wlan_start_wps_pin((uint32_t)atoi(argv[1]));
6469 #endif
6470
6471 if (ret != WM_SUCCESS)
6472 {
6473 PRINTF("Invalid PIN entered\r\n");
6474 }
6475 else
6476 {
6477 PRINTF("Started WPS PIN session with pin as: %s\r\n", argv[1]);
6478 }
6479 }
6480
6481 static void test_wlan_wps_generate_pin(int argc, char **argv)
6482 {
6483 uint32_t pin = 0;
6484
6485 if (argc != 1)
6486 {
6487 (void)PRINTF("Error: invalid number of arguments\r\n");
6488 return;
6489 }
6490
6491 wlan_wps_generate_pin(&pin);
6492 PRINTF("WPS PIN is: %08d\r\n", pin);
6493 }
6494 #endif
6495 #if CONFIG_WPA_SUPP_WPS
6496 static void test_wlan_wps_cancel(int argc, char **argv)
6497 {
6498 int ret;
6499
6500 if (argc != 1)
6501 {
6502 (void)PRINTF("Error: invalid number of arguments\r\n");
6503 return;
6504 }
6505
6506 ret = wlan_wps_cancel();
6507
6508 if (ret != WM_SUCCESS)
6509 {
6510 PRINTF("Cancel WPS failed\r\n");
6511 }
6512 }
6513 #if CONFIG_WPA_SUPP_AP
6514 static void test_wlan_start_ap_wps_pbc(int argc, char **argv)
6515 {
6516 int ret;
6517
6518 if (argc != 1)
6519 {
6520 (void)PRINTF("Error: invalid number of arguments\r\n");
6521 return;
6522 }
6523
6524 ret = wlan_start_ap_wps_pbc();
6525
6526 if (ret != WM_SUCCESS)
6527 {
6528 PRINTF("Start AP WPS PBC failed\r\n");
6529 }
6530 }
6531
6532 static void test_wlan_start_ap_wps_pin(int argc, char **argv)
6533 {
6534 int ret = -WM_FAIL;
6535
6536 if (argc != 2)
6537 {
6538 (void)PRINTF("Error: invalid number of arguments\r\n");
6539 return;
6540 }
6541
6542 ret = wlan_start_ap_wps_pin(argv[1]);
6543
6544 if (ret != WM_SUCCESS)
6545 {
6546 PRINTF("Start AP WPS PIN failed\r\n");
6547 }
6548 else
6549 {
6550 PRINTF("Started AP WPS PIN session with pin as: %s\r\n", argv[1]);
6551 }
6552 }
6553
6554 static void test_wlan_wps_ap_cancel(int argc, char **argv)
6555 {
6556 int ret;
6557
6558 if (argc != 1)
6559 {
6560 (void)PRINTF("Error: invalid number of arguments\r\n");
6561 return;
6562 }
6563
6564 ret = wlan_wps_ap_cancel();
6565
6566 if (ret != WM_SUCCESS)
6567 {
6568 PRINTF("Cancel WPS failed\r\n");
6569 }
6570 }
6571 #endif
6572 #endif
6573
6574 #if CONFIG_TURBO_MODE
6575 static void test_wlan_get_turbo_mode(int argc, char **argv)
6576 {
6577 int ret = -WM_FAIL;
6578 uint8_t mode;
6579 int bss_type = MLAN_BSS_TYPE_ANY;
6580 if (argc != 2)
6581 {
6582 (void)PRINTF("Error: invalid number of arguments\r\n");
6583 (void)PRINTF("Usage: wlan-get-turbo-mode STA/UAP\r\n");
6584 return;
6585 }
6586
6587 if (string_equal("STA", argv[1]))
6588 {
6589 bss_type = MLAN_BSS_TYPE_STA;
6590 ret = wlan_get_turbo_mode(&mode);
6591 }
6592 else if (string_equal("UAP", argv[1]))
6593 {
6594 bss_type = MLAN_BSS_TYPE_UAP;
6595 ret = wlan_get_uap_turbo_mode(&mode);
6596 }
6597 else
6598 {
6599 (void)PRINTF("Error: invalid BSS type\r\n");
6600 (void)PRINTF("Usage: wlan-get-turbo-mode STA/UAP\r\n");
6601 return;
6602 }
6603
6604 if (ret == WM_SUCCESS)
6605 {
6606 (void)PRINTF("%s Turbo mode: %d\r\n", bss_type == MLAN_BSS_TYPE_STA ? "STA" : "UAP", mode);
6607 }
6608 else
6609 {
6610 (void)PRINTF("Failed to get %s turbo mode\r\n", bss_type == MLAN_BSS_TYPE_STA ? "STA" : "UAP");
6611 }
6612
6613 return;
6614 }
6615
6616 static void dump_wlan_set_turbo_mode_usage()
6617 {
6618 (void)PRINTF("Usage: wlan-set-turbo-mode <STA/UAP> <mode>\r\n");
6619 (void)PRINTF(" <STA/UAP> 'STA' or 'UAP' \r\n");
6620 (void)PRINTF(" <mode> can be 0,1,2,3\r\n");
6621 }
6622
6623 static void test_wlan_set_turbo_mode(int argc, char **argv)
6624 {
6625 int ret = -WM_FAIL;
6626 unsigned int value;
6627 uint8_t mode;
6628 int bss_type;
6629 if (argc != 3)
6630 {
6631 (void)PRINTF("Error: invalid number of arguments\r\n");
6632 dump_wlan_set_turbo_mode_usage();
6633 return;
6634 }
6635
6636 if (string_equal("STA", argv[1]))
6637 bss_type = MLAN_BSS_TYPE_STA;
6638 else if (string_equal("UAP", argv[1]))
6639 bss_type = MLAN_BSS_TYPE_UAP;
6640 else
6641 {
6642 (void)PRINTF("Error: invalid BSS type\r\n");
6643 dump_wlan_set_turbo_mode_usage();
6644 return;
6645 }
6646
6647 if (get_uint(argv[2], &value, strlen(argv[2])) && value > 3)
6648 {
6649 (void)PRINTF("Invalid mode argument\r\n");
6650 dump_wlan_set_turbo_mode_usage();
6651 return;
6652 }
6653 mode = value & 0xFF;
6654
6655 if (bss_type == MLAN_BSS_TYPE_STA)
6656 {
6657 ret = wlan_set_turbo_mode(mode);
6658 }
6659 else
6660 {
6661 ret = wlan_set_uap_turbo_mode(mode);
6662 }
6663
6664 if (ret == WM_SUCCESS)
6665 {
6666 (void)PRINTF("Set %s turbo mode to %d\r\n", bss_type == MLAN_BSS_TYPE_STA ? "STA" : "UAP", mode);
6667 }
6668 else
6669 {
6670 (void)PRINTF("Failed to set %s turbo mode\r\n", bss_type == MLAN_BSS_TYPE_STA ? "STA" : "UAP");
6671 }
6672
6673 return;
6674 }
6675 #endif
6676
6677 #if CONFIG_11AX
6678 #if CONFIG_WIFI_HTC_DEBUG
6679 static void dump_wlan_set_debug_htc_usage(void)
6680 {
6681 (void)PRINTF("Usage:\r\n");
6682 (void)PRINTF(" wlan-set-debug-htc \r\n");
6683 (void)PRINTF(" <count>:1\r\n");
6684 (void)PRINTF(" <vht:1>\r\n");
6685 (void)PRINTF(" <he:1>\r\n");
6686 (void)PRINTF(" <rxNss:1>\r\n");
6687 (void)PRINTF(" <channelWidth:1>\r\n");
6688 (void)PRINTF(" <ulMuDisable:1>\r\n");
6689 (void)PRINTF(" <txNSTS:1>\r\n");
6690 (void)PRINTF(" <erSuDisable:1>\r\n");
6691 (void)PRINTF(" <dlResoundRecomm:1>\r\n");
6692 (void)PRINTF(" <ulMuDataDisable:1>\r\n");
6693 }
6694
6695 static void test_wlan_set_debug_htc(int argc, char **argv)
6696 {
6697 int ret = -WM_FAIL;
6698 uint8_t count, vht, he, rxNss, channelWidth, ulMuDisable, txNSTS, erSuDisable, dlResoundRecomm, ulMuDataDisable;
6699 /**
6700 * Command taken from debug.conf
6701 * send_om_set={
6702 * CmdCode=0x008b # do NOT change this line
6703 * Action:2=1 # 1 - HE-TB-PPDU with dummy UPH
6704 * SUBID:2=0x111 # Send NULL
6705 * count:1=0x40 # Count of packets with OM in HE-TB-PPDU format
6706 * vht:1=1 # HT Control Field: For HT Variant-0, VHT variant-1, HE Variant-1
6707 * he:1=1 # HT Control Field: For VHT Variant-0, HE variant-1
6708 * rxNss:1=0
6709 * channelWidth:1=0
6710 * ulMuDisable:1=0
6711 * txNSTS:1=0
6712 * erSuDisable:1=0
6713 * dlResoundRecomm:1=0
6714 * ulMuDataDisable:1=0
6715 * }
6716 *
6717 */
6718
6719 if (argc != 11)
6720 {
6721 (void)PRINTF("Error: invalid number of arguments\r\n");
6722 dump_wlan_set_debug_htc_usage();
6723 return;
6724 }
6725
6726 count = atoi(argv[1]);
6727 vht = atoi(argv[2]);
6728 he = atoi(argv[3]);
6729 rxNss = atoi(argv[4]);
6730 channelWidth = atoi(argv[5]);
6731 ulMuDisable = atoi(argv[6]);
6732 txNSTS = atoi(argv[7]);
6733 erSuDisable = atoi(argv[8]);
6734 dlResoundRecomm = atoi(argv[9]);
6735 ulMuDataDisable = atoi(argv[10]);
6736
6737 ret = wlan_send_debug_htc(count, vht, he, rxNss, channelWidth, ulMuDisable, txNSTS, erSuDisable, dlResoundRecomm,
6738 ulMuDataDisable);
6739
6740 if (ret == WM_SUCCESS)
6741 (void)PRINTF("HTC parameter set successfully\r\n");
6742 else
6743 (void)PRINTF("Failed to set HTC parameter\r\n");
6744 }
6745 #endif
6746
6747 static void dump_wlan_enable_disable_htc_usage()
6748 {
6749 (void)PRINTF("Usage: wlan-enable-disable-htc <option>\r\n");
6750 (void)PRINTF(" <option> 0 => disable \r\n");
6751 (void)PRINTF(" 1 => enable \r\n");
6752 }
6753
6754 static void test_wlan_enable_disable_htc(int argc, char **argv)
6755 {
6756 int ret = -WM_FAIL;
6757 unsigned int option;
6758
6759 if (argc != 2)
6760 {
6761 (void)PRINTF("Error: invalid number of arguments\r\n");
6762 dump_wlan_enable_disable_htc_usage();
6763 return;
6764 }
6765 if (get_uint(argv[1], &option, strlen(argv[1])) && option > 1)
6766 {
6767 (void)PRINTF("Invalid option argument\r\n");
6768 dump_wlan_enable_disable_htc_usage();
6769 return;
6770 }
6771
6772 ret = wlan_enable_disable_htc((uint8_t)option);
6773
6774 if (ret == WM_SUCCESS)
6775 {
6776 if (option)
6777 (void)PRINTF("HTC enabled\r\n");
6778 else
6779 (void)PRINTF("HTC disabled\r\n");
6780 }
6781 else
6782 {
6783 (void)PRINTF("Failed to enable/disable HTC\r\n");
6784 }
6785 }
6786 #endif
6787
6788 static void dump_wlan_set_country_ie_ignore_usage(void)
6789 {
6790 (void)PRINTF("Usage:\r\n");
6791 (void)PRINTF(" wlan-set-country-ignore-ie <0/1>\r\n");
6792 (void)PRINTF(" <enable/disable>: 1 -- Ignore country ie\r\n");
6793 (void)PRINTF(" 0 -- Use country ie(default)\r\n");
6794 }
6795
6796 static void test_wlan_set_country_ie_ignore(int argc, char **argv)
6797 {
6798 int ret = -WM_FAIL;
6799 uint8_t ignore = 0;
6800
6801 if (argc > 2)
6802 {
6803 (void)PRINTF("Error: invalid number of arguments\r\n");
6804 dump_wlan_set_country_ie_ignore_usage();
6805 return;
6806 }
6807
6808 /* SET */
6809 if (argc == 2)
6810 {
6811 ignore = atoi(argv[1]);
6812 }
6813
6814 ret = wlan_set_country_ie_ignore(&ignore);
6815
6816 if (ret != WM_SUCCESS)
6817 {
6818 (void)PRINTF("Set country ie ignore is failed\r\n");
6819 }
6820 else
6821 {
6822 (void)PRINTF("Country ie \"%s\" is set\r\n", ignore == 0 ? "follow" : "ignore");
6823 }
6824 }
6825
6826 #if CONFIG_COEX_DUTY_CYCLE
6827 static void dump_wlan_single_ant_duty_cycle_usage()
6828 {
6829 (void)PRINTF("Usage: wlan-single-ant-duty-cycle <enable/disable> [<Ieee154Duration> <TotalDuration>]\r\n");
6830 (void)PRINTF(" <enable/disable> Enable - 1, Disable - 0\r\n");
6831 (void)PRINTF(" <Ieee154Duration> Enter value in Units (1Unit = 1ms), no more than TotalDuration\r\n");
6832 (void)PRINTF(" <TotalDuration> Enter value in Units (1Unit = 1ms), total duty cycle time\r\n");
6833 (void)PRINTF(" Ieee154Duration should not equal to TotalDuration-Ieee154Duration\r\n");
6834 }
6835
6836 static void test_wlan_single_ant_duty_cycle(int argc, char **argv)
6837 {
6838 int ret = -WM_FAIL;
6839 unsigned int enable, nbTime, wlanTime;
6840 if (argc != 4 && argc != 2)
6841 {
6842 (void)PRINTF("Error: invalid number of arguments\r\n");
6843 dump_wlan_single_ant_duty_cycle_usage();
6844 return;
6845 }
6846
6847 if (get_uint(argv[1], &enable, strlen(argv[1])))
6848 {
6849 (void)PRINTF("Invalid arguments\r\n");
6850 dump_wlan_single_ant_duty_cycle_usage();
6851 return;
6852 }
6853
6854 if (enable == 1 && argc == 4)
6855 {
6856 if (get_uint(argv[2], &nbTime, strlen(argv[2])) || get_uint(argv[3], &wlanTime, strlen(argv[3])))
6857 {
6858 (void)PRINTF("Invalid arguments\r\n");
6859 dump_wlan_single_ant_duty_cycle_usage();
6860 return;
6861 }
6862
6863 if ((nbTime > wlanTime) || (nbTime == (wlanTime - nbTime)))
6864 {
6865 (void)PRINTF("Invalid arguments\r\n");
6866 dump_wlan_single_ant_duty_cycle_usage();
6867 return;
6868 }
6869 }
6870 else
6871 {
6872 nbTime = 0;
6873 wlanTime = 0;
6874 }
6875
6876 ret = wlan_single_ant_duty_cycle((t_u16)enable, (t_u16)nbTime, (t_u16)wlanTime);
6877
6878 if (ret == WM_SUCCESS)
6879 {
6880 (void)PRINTF("Set single ant duty cycle successfully\r\n");
6881 }
6882 else
6883 {
6884 (void)PRINTF("Failed to set single ant duty cycle\r\n");
6885 }
6886
6887 return;
6888 }
6889
6890 static void dump_wlan_dual_ant_duty_cycle_usage()
6891 {
6892 (void)PRINTF(
6893 "Usage: wlan-dual-ant-duty-cycle <enable/disable> [<Ieee154Duration> <TotalDuration> "
6894 "<Ieee154FarRangeDuration>]\r\n");
6895 (void)PRINTF(" <enable/disable> Enable - 1, Disable - 0\r\n");
6896 (void)PRINTF(" <Ieee154Duration> Enter value in Units (1Unit = 1ms), no more than TotalDuration\r\n");
6897 (void)PRINTF(" <TotalDuration> Enter value in Units (1Unit = 1ms)\r\n");
6898 (void)PRINTF(" <Ieee154FarRangeDuration> Enter value in Units (1Unit = 1ms)\r\n");
6899 (void)PRINTF(" Ieee154Duration, TotalDuration and Ieee154FarRangeDuration should not equal to each other\r\n");
6900 }
6901
6902 static void test_wlan_dual_ant_duty_cycle(int argc, char **argv)
6903 {
6904 int ret = -WM_FAIL;
6905 unsigned int enable, nbTime, wlanTime, wlanBlockTime;
6906 if (argc != 5 && argc != 2)
6907 {
6908 (void)PRINTF("Error: invalid number of arguments\r\n");
6909 dump_wlan_dual_ant_duty_cycle_usage();
6910 return;
6911 }
6912
6913 if (get_uint(argv[1], &enable, strlen(argv[1])))
6914 {
6915 (void)PRINTF("Invalid arguments\r\n");
6916 dump_wlan_dual_ant_duty_cycle_usage();
6917 return;
6918 }
6919
6920 if (enable == 1 && argc == 5)
6921 {
6922 if (get_uint(argv[2], &nbTime, strlen(argv[2])) || get_uint(argv[3], &wlanTime, strlen(argv[3])) ||
6923 get_uint(argv[4], &wlanBlockTime, strlen(argv[4])))
6924 {
6925 (void)PRINTF("Invalid arguments\r\n");
6926 dump_wlan_dual_ant_duty_cycle_usage();
6927 return;
6928 }
6929
6930 if ((nbTime > wlanTime) || (nbTime == (wlanTime - nbTime)) || (nbTime == wlanBlockTime) ||
6931 (wlanBlockTime == (wlanTime - nbTime)))
6932 {
6933 (void)PRINTF("Invalid arguments\r\n");
6934 dump_wlan_dual_ant_duty_cycle_usage();
6935 return;
6936 }
6937 }
6938 else
6939 {
6940 nbTime = 0;
6941 wlanTime = 0;
6942 wlanBlockTime = 0;
6943 }
6944
6945 ret = wlan_dual_ant_duty_cycle((t_u16)enable, (t_u16)nbTime, (t_u16)wlanTime, (t_u16)wlanBlockTime);
6946
6947 if (ret == WM_SUCCESS)
6948 {
6949 (void)PRINTF("Set dual ant duty cycle successfully\r\n");
6950 }
6951 else
6952 {
6953 (void)PRINTF("Failed to set dual ant duty cycle\r\n");
6954 }
6955
6956 return;
6957 }
6958 #endif
6959
6960 #if CONFIG_EXTERNAL_COEX_PTA
6961
6962 static void dump_wlan_external_coex_pta_usage()
6963 {
6964 (void)PRINTF(
6965 "Usage: wlan-external-coex-pta enable <PTA/WCI-2/WCI-2 GPIO> ExtWifiBtArb <enable/disable> PolGrantPin "
6966 "<high/low> "
6967 "PriPtaInt <enable/disable> StateFromPta <state pin/ priority pin/ state input disable> SampTiming <Sample "
6968 "timing> "
6969 "InfoSampTiming <Sample timing> TrafficPrio <enable/disable> CoexHwIntWic <enable/disable>\r\n");
6970 (void)PRINTF(" enable <enable/disable>\r\n");
6971 (void)PRINTF(" Select PTA interface: 5, Select WCI-2 interface: 6, Select WCI-2 GPIO interface: 7.\r\n");
6972 (void)PRINTF(" ExtWifiBtArb <enable/disable>\r\n");
6973 (void)PRINTF(" Enable Ext-WifiBtArb: 1, Disbale Ext-WifiBtArb: 0.\r\n");
6974 (void)PRINTF(" PolGrantPin <high/low> \r\n");
6975 (void)PRINTF(" Active High: 0, Active Low: 1.\r\n");
6976 (void)PRINTF(" PriPtaInt <enable/disable> \r\n");
6977 (void)PRINTF(" Enable PriPta-Init: 1, Disable PriPta-Init: 0.\r\n");
6978 (void)PRINTF(" StateFromPta <state pin/ priority pin/ state input disable> \r\n");
6979 (void)PRINTF(" State input disbale : 0.\r\n");
6980 (void)PRINTF(" State info is from state pin : 1.\r\n");
6981 (void)PRINTF(" State info is sampled on priority pin: 2.\r\n");
6982 (void)PRINTF(" SampTiming <Sample timing> \r\n");
6983 (void)PRINTF(" Timing to sample Priority bit.\r\n");
6984 (void)PRINTF(" Sample timing range [20, 200].\r\n");
6985 (void)PRINTF(" Defalut value: 100.\r\n");
6986 (void)PRINTF(" InfoSampTiming <Sample timing> \r\n");
6987 (void)PRINTF(" Timing to sample Tx/Rx info.\r\n");
6988 (void)PRINTF(" Sample timing range [20, 200].\r\n");
6989 (void)PRINTF(" Defalut value: 100.\r\n");
6990 (void)PRINTF(" TrafficPrio <enable/disable> \r\n");
6991 (void)PRINTF(" Enable external traffic Tx/Rx Priority: 1.\r\n");
6992 (void)PRINTF(" Disable external traffic Tx/Rx Priority: 0.\r\n");
6993 (void)PRINTF(" CoexHwIntWic <enable/disable> \r\n");
6994 (void)PRINTF(" Enable WCI-2 interface: 1.\r\n");
6995 (void)PRINTF(" Disable WCI-2 interface: 0.\r\n");
6996 }
6997
6998 static void test_wlan_external_coex_pta(int argc, char **argv)
6999 {
7000 int ret = 0, arg = 0;
7001 unsigned int value;
7002 ext_coex_pta_cfg coex_pta_config;
7003
7004 if (argc < 2 || argc > 19)
7005 {
7006 (void)PRINTF("Error: invalid number of arguments.\r\n");
7007 dump_wlan_external_coex_pta_usage();
7008 return;
7009 }
7010
7011 struct
7012 {
7013 unsigned enable : 1;
7014 unsigned ExtWifiBtArb : 1;
7015 unsigned PolGrantPin : 1;
7016 unsigned PriPtaInt : 2;
7017 unsigned StateFromPta : 1;
7018 unsigned SampTiming : 1;
7019 unsigned InfoSampTiming : 1;
7020 unsigned TrafficPrio : 1;
7021 unsigned CoexHwIntWic : 1;
7022 } info;
7023
7024 arg++;
7025 (void)memset(&coex_pta_config, 0x0, sizeof(ext_coex_pta_cfg));
7026 (void)memset(&info, 0x0, sizeof(info));
7027
7028 do
7029 {
7030 if (!info.enable && string_equal("enable", argv[arg]))
7031 {
7032 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7033 {
7034 (void)PRINTF("Invalid enable argument.\r\n");
7035 dump_wlan_external_coex_pta_usage();
7036 return;
7037 }
7038
7039 if (value != EXT_COEX_PTA_INTERFACE && value != EXT_COEX_WCI2_INTERFACE &&
7040 value != EXT_COEX_WCI2_GPIO_INTERFACE)
7041 {
7042 (void)PRINTF("Invalid enable argument.\r\n");
7043 dump_wlan_external_coex_pta_usage();
7044 return;
7045 }
7046 coex_pta_config.enabled = value & 0xFF;
7047 info.enable = 1;
7048 arg += 2;
7049 }
7050 else if (!info.ExtWifiBtArb && string_equal("ExtWifiBtArb", argv[arg]))
7051 {
7052 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7053 {
7054 (void)PRINTF("Invalid ExtWifiBtArb argument.\r\n");
7055 dump_wlan_external_coex_pta_usage();
7056 return;
7057 }
7058
7059 if (value != COEX_PTA_FEATURE_ENABLE && value != COEX_PTA_FEATURE_DISABLE)
7060 {
7061 (void)PRINTF("Invalid ExtWifiBtArb argument.\r\n");
7062 dump_wlan_external_coex_pta_usage();
7063 return;
7064 }
7065 coex_pta_config.ext_WifiBtArb = value & 0xFF;
7066 info.ExtWifiBtArb = 1;
7067 arg += 2;
7068 }
7069 else if (!info.PolGrantPin && string_equal("PolGrantPin", argv[arg]))
7070 {
7071 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7072 {
7073 (void)PRINTF("Invalid PolGrantPin argument.\r\n");
7074 dump_wlan_external_coex_pta_usage();
7075 return;
7076 }
7077
7078 if (value != POL_GRANT_PIN_HIGH && value != POL_GRANT_PIN_LOW)
7079 {
7080 (void)PRINTF("Invalid PolGrantPin argument.\r\n");
7081 dump_wlan_external_coex_pta_usage();
7082 return;
7083 }
7084 coex_pta_config.polGrantPin = value & 0x0FF;
7085 info.PolGrantPin = 1;
7086 arg += 2;
7087 }
7088 else if (!info.PriPtaInt && string_equal("PriPtaInt", argv[arg]))
7089 {
7090 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7091 {
7092 (void)PRINTF("Invalid PolGrantPin argument.\r\n");
7093 dump_wlan_external_coex_pta_usage();
7094 return;
7095 }
7096
7097 if (value != COEX_PTA_FEATURE_ENABLE && value != COEX_PTA_FEATURE_DISABLE)
7098 {
7099 (void)PRINTF("Invalid PolGrantPin argument.\r\n");
7100 dump_wlan_external_coex_pta_usage();
7101 return;
7102 }
7103 coex_pta_config.enable_PriPtaInt = value & 0xFF;
7104 info.PriPtaInt = 1;
7105 arg += 2;
7106 }
7107 else if (!info.StateFromPta && string_equal("StateFromPta", argv[arg]))
7108 {
7109 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7110 {
7111 (void)PRINTF("Invalid StateFromPta argument.\r\n");
7112 dump_wlan_external_coex_pta_usage();
7113 return;
7114 }
7115
7116 if (value != STATE_INPUT_DISABLE && value != STATE_PTA_PIN && value != STATE_PRIORITY_PIN)
7117 {
7118 (void)PRINTF("Invalid StateFromPta argument.\r\n");
7119 dump_wlan_external_coex_pta_usage();
7120 return;
7121 }
7122 coex_pta_config.enable_StatusFromPta = value & 0xFF;
7123 info.StateFromPta = 1;
7124 arg += 2;
7125 }
7126 else if (!info.SampTiming && string_equal("SampTiming", argv[arg]))
7127 {
7128 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7129 {
7130 (void)PRINTF("Invalid SampTiming argument.\r\n");
7131 dump_wlan_external_coex_pta_usage();
7132 return;
7133 }
7134
7135 if (value < MIN_SAMP_TIMING || value > MAX_SAMP_TIMING)
7136 {
7137 (void)PRINTF("Invalid SampTiming argument.\r\n");
7138 dump_wlan_external_coex_pta_usage();
7139 return;
7140 }
7141 coex_pta_config.setPriSampTiming = value & 0xFFFF;
7142 info.SampTiming = 1;
7143 arg += 2;
7144 }
7145 else if (!info.InfoSampTiming && string_equal("InfoSampTiming", argv[arg]))
7146 {
7147 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7148 {
7149 (void)PRINTF("Invalid InfoSampTiming argument.\r\n");
7150 dump_wlan_external_coex_pta_usage();
7151 return;
7152 }
7153
7154 if (value < MIN_SAMP_TIMING || value > MAX_SAMP_TIMING)
7155 {
7156 (void)PRINTF("Invalid InfoSampTiming argument.\r\n");
7157 dump_wlan_external_coex_pta_usage();
7158 return;
7159 }
7160 coex_pta_config.setStateInfoSampTiming = value & 0xFFFF;
7161 info.InfoSampTiming = 1;
7162 arg += 2;
7163 }
7164 else if (!info.TrafficPrio && string_equal("TrafficPrio", argv[arg]))
7165 {
7166 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7167 {
7168 (void)PRINTF("Invalid TrafficPrio argument.\r\n");
7169 dump_wlan_external_coex_pta_usage();
7170 return;
7171 }
7172
7173 if (value != COEX_PTA_FEATURE_ENABLE && value != COEX_PTA_FEATURE_DISABLE)
7174 {
7175 (void)PRINTF("Invalid TrafficPrio argument.\r\n");
7176 dump_wlan_external_coex_pta_usage();
7177 return;
7178 }
7179 coex_pta_config.extRadioTrafficPrio = value & 0xFF;
7180 info.TrafficPrio = 1;
7181 arg += 2;
7182 }
7183 else if (!info.CoexHwIntWic && string_equal("CoexHwIntWic", argv[arg]))
7184 {
7185 if (arg + 1 >= argc || get_uint(argv[arg + 1], &value, strlen(argv[arg + 1])))
7186 {
7187 (void)PRINTF("Invalid CoexHwIntWic argument.\r\n");
7188 dump_wlan_external_coex_pta_usage();
7189 return;
7190 }
7191
7192 if (value != COEX_PTA_FEATURE_ENABLE && value != COEX_PTA_FEATURE_DISABLE)
7193 {
7194 (void)PRINTF("Invalid CoexHwIntWic argument.\r\n");
7195 dump_wlan_external_coex_pta_usage();
7196 return;
7197 }
7198 coex_pta_config.extCoexHwIntWci2 = value & 0xFF;
7199 info.CoexHwIntWic = 1;
7200 arg += 2;
7201 }
7202 else
7203 {
7204 (void)PRINTF("Invalid %d argument %s\r\n", arg, argv[arg]);
7205 dump_wlan_external_coex_pta_usage();
7206 return;
7207 }
7208 } while (arg < argc);
7209
7210 if (info.enable != 1)
7211 {
7212 (void)PRINTF("Error: Missing <enable> argument.\r\n");
7213 ret++;
7214 }
7215 if (info.ExtWifiBtArb != 1)
7216 {
7217 (void)PRINTF("Error: Missing <ExtWifiBtArb> argument.\r\n");
7218 ret++;
7219 }
7220 if (info.PolGrantPin != 1)
7221 {
7222 (void)PRINTF("Error: Missing <PolGrantPin> argument.\r\n");
7223 ret++;
7224 }
7225 if (info.PriPtaInt != 1)
7226 {
7227 (void)PRINTF("Error: Missing <PriPtaInt> argument.\r\n");
7228 ret++;
7229 }
7230 if (info.StateFromPta != 1)
7231 {
7232 (void)PRINTF("Error: Missing <StateFromPta> argument.\r\n");
7233 ret++;
7234 }
7235 if (info.SampTiming != 1)
7236 {
7237 coex_pta_config.setPriSampTiming = SAMPLE_TIMING_VALUE;
7238 (void)PRINTF("Info: Missing <SampTiming> argument. Use default value 100.\r\n");
7239 }
7240 if (info.InfoSampTiming != 1)
7241 {
7242 coex_pta_config.setStateInfoSampTiming = SAMPLE_TIMING_VALUE;
7243 (void)PRINTF("Info: Missing <InfoSampTiming> argument. Use default value 100.\r\n");
7244 }
7245 if (info.TrafficPrio != 1)
7246 {
7247 (void)PRINTF("Error: Missing <TrafficPrio> argument.\r\n");
7248 ret++;
7249 }
7250 if (info.CoexHwIntWic != 1)
7251 {
7252 (void)PRINTF("Error: Missing <CoexHwIntWic> argument.\r\n");
7253 ret++;
7254 }
7255
7256 if (ret != 0)
7257 {
7258 dump_wlan_external_coex_pta_usage();
7259 return;
7260 }
7261
7262 ret = wlan_external_coex_pta_cfg(coex_pta_config);
7263
7264 if (ret == WM_SUCCESS)
7265 {
7266 (void)PRINTF("Success to set external coex pta config:\r\n");
7267 (void)PRINTF("Enable ");
7268 if (coex_pta_config.enabled == EXT_COEX_PTA_INTERFACE)
7269 (void)PRINTF("PTA interface.\r\n");
7270 else if (coex_pta_config.enabled == EXT_COEX_WCI2_INTERFACE)
7271 (void)PRINTF("WCI-2 interface.\r\n");
7272 else if (coex_pta_config.enabled == EXT_COEX_WCI2_GPIO_INTERFACE)
7273 (void)PRINTF("WCI-2 GPIO interface.\r\n");
7274 else
7275 (void)PRINTF("Unknow interface.\r\n");
7276
7277 (void)PRINTF("%s WifiBtArb.\r\n",
7278 coex_pta_config.ext_WifiBtArb == COEX_PTA_FEATURE_ENABLE ? "Enable" : "Disbale");
7279 (void)PRINTF("PolGrantPin active %s.\r\n", coex_pta_config.polGrantPin == POL_GRANT_PIN_HIGH ? "High" : "Low");
7280 (void)PRINTF("%s PriPtaInt.\r\n",
7281 coex_pta_config.enable_PriPtaInt == COEX_PTA_FEATURE_ENABLE ? "Enable" : "Disbale");
7282 if (coex_pta_config.enable_StatusFromPta == STATE_INPUT_DISABLE)
7283 (void)PRINTF("State input disable.\r\n");
7284 else if (coex_pta_config.enable_StatusFromPta == STATE_PTA_PIN)
7285 (void)PRINTF("State info is from state pin.\r\n");
7286 else if (coex_pta_config.enable_StatusFromPta == STATE_PRIORITY_PIN)
7287 (void)PRINTF("State info is sampled on priority pin.\r\n");
7288 else
7289 (void)PRINTF("Unknow state pin info\r\n");
7290
7291 (void)PRINTF("Timing to sample Priority bit: %d.\r\n", coex_pta_config.setPriSampTiming);
7292 (void)PRINTF("Timing to sample Tx/Rx info: %d.\r\n", coex_pta_config.setStateInfoSampTiming);
7293 (void)PRINTF("%s external traffic Tx/Rx Priority.\r\n",
7294 coex_pta_config.extRadioTrafficPrio == COEX_PTA_FEATURE_ENABLE ? "Enable" : "Disbale");
7295 (void)PRINTF("%s WCI-2 interface.\r\n",
7296 coex_pta_config.extCoexHwIntWci2 == COEX_PTA_FEATURE_ENABLE ? "Enable" : "Disbale");
7297 }
7298 else
7299 (void)PRINTF("Failed to set external coex pta parameters.\r\n");
7300
7301 return;
7302 }
7303 #endif
7304
7305 #if CONFIG_IMD3_CFG
7306
7307 static void dump_wlan_imd3_cfg_usage(void)
7308 {
7309 (void)PRINTF("Usage:\r\n");
7310 (void)PRINTF(" wlan-imd3-cfg <enable / disable> <isolation index>\r\n");
7311 (void)PRINTF(" <enable> 1: enable / 0: disable\r\n");
7312 (void)PRINTF(" <isolation index> range: 1 ~ 5 or 15\r\n");
7313 (void)PRINTF(" If set index to 15, use default value.");
7314 (void)PRINTF("Fox example:\r\n");
7315 (void)PRINTF(" wlan-imd3-cfg 0 \r\n");
7316 (void)PRINTF(" wlan-imd3-cfg 1 3\r\n");
7317 }
7318
7319 static void test_wlan_imd3_cfg(int argc, char **argv)
7320 {
7321 int ret = 0;
7322 uint8_t enable, index, imd3_cfg = 0;
7323 unsigned int value;
7324
7325 if (argc != 2 && argc != 3)
7326 {
7327 (void)PRINTF("Error: invalid number of arguments.\r\n");
7328 dump_wlan_imd3_cfg_usage();
7329 return;
7330 }
7331
7332 if (get_uint(argv[1], &value, strlen(argv[1])) || (value != 1 && value != 0))
7333 {
7334 (void)PRINTF("Invalid <enable> argument \r\n");
7335 dump_wlan_imd3_cfg_usage();
7336 return;
7337 }
7338
7339 enable = value & 0xFF;
7340
7341 if (enable == 1 && argc == 2)
7342 {
7343 (void)PRINTF("Missing <isolation index> argument \r\n");
7344 dump_wlan_imd3_cfg_usage();
7345 return;
7346 }
7347
7348 if (enable == 1 && argc == 3)
7349 {
7350 if (get_uint(argv[2], &value, strlen(argv[2])) || ((value < 1 || value > 5) && value != 15))
7351 {
7352 (void)PRINTF("Invalid <index> argument \r\n");
7353 dump_wlan_imd3_cfg_usage();
7354 return;
7355 }
7356
7357 index = value & 0xFF;
7358 /* imd3_cfg --> low 4 bits: enable / high 4 bits: index*/
7359 imd3_cfg |= enable;
7360 index <<= 4;
7361 imd3_cfg |= index;
7362 }
7363
7364 ret = wlan_imd3_cfg(imd3_cfg);
7365
7366 if (ret == WM_SUCCESS)
7367 {
7368 (void)PRINTF("Success to set IMD cfg.\r\n");
7369 }
7370 else
7371 {
7372 (void)PRINTF("Failed to set IMD cfg.\r\n");
7373 }
7374 }
7375 #endif
7376
7377 #if CONFIG_AUTO_RECONNECT
7378 #define AUTO_RECON_CNT_DEF 255U
7379 #define AUTO_RECON_TIME_INT_DEF 10U
7380 #define AUTO_RECON_FLAG_DEF 0U
7381
7382 static void dump_wlan_auto_reconnect_usage(void)
7383 {
7384 (void)PRINTF("Usage:\r\n");
7385 (void)PRINTF(" wlan-auto-reconnect <0/1/2> [<reconnect counter> <reconnect interval> <flags>]\r\n");
7386 (void)PRINTF(" <0/1/2> : 0 - Disable auto reconnect\r\n");
7387 (void)PRINTF(" 1 - Enable auto reconnect\r\n");
7388 (void)PRINTF(" 2 - Get auto reconnect configuration\r\n");
7389 (void)PRINTF(" <reconnect counter> : 1-255 Auto reconnect attempts (Defult:255 - retry forever)\r\n");
7390 (void)PRINTF(" <reconnect interval> : 0-255 Auto reconnect time period in seconds(Default:10 sec)\r\n");
7391 (void)PRINTF(
7392 " <flags> : 0-15, 0: Default, Don't report link loss, 1: Report link loss to host, 2-15: Reserved\r\n");
7393 (void)PRINTF("Examples:\r\n");
7394 (void)PRINTF(" wlan-auto-reconnect 0\r\n");
7395 (void)PRINTF(" wlan-auto-reconnect 1 10 10 0\r\n");
7396 (void)PRINTF(" wlan-auto-reconnect 2\r\n");
7397 return;
7398 }
7399
7400 static void test_wlan_auto_reconnect(int argc, char **argv)
7401 {
7402 int ret = -WM_FAIL;
7403 char *endptr = NULL;
7404 int enable = -1;
7405 wlan_auto_reconnect_config_t recon_config;
7406
7407 uint8_t recon_counter = AUTO_RECON_CNT_DEF;
7408 uint8_t recon_interval = AUTO_RECON_TIME_INT_DEF;
7409 uint16_t flags = AUTO_RECON_FLAG_DEF;
7410
7411 if (argc < 2 || argc > 5)
7412 {
7413 (void)PRINTF("Error: invalid number of arguments\r\n");
7414 goto done;
7415 }
7416
7417 errno = 0;
7418 enable = (int)strtol(argv[1], &endptr, 10);
7419 if (errno != 0 || *endptr != '\0')
7420 {
7421 (void)PRINTF("Error during strtol:enable\r\n");
7422 goto done;
7423 }
7424
7425 if (enable == 0)
7426 {
7427 ret = wlan_auto_reconnect_disable();
7428 if (ret == WM_SUCCESS)
7429 {
7430 (void)PRINTF("Disabled auto reconnect\r\n");
7431 }
7432 else
7433 {
7434 (void)PRINTF("Failed to disable auto reconnect, error: %d\r\n", ret);
7435 }
7436 }
7437 else if (enable == 1)
7438 {
7439 if (argc > 2)
7440 {
7441 errno = 0;
7442 recon_counter = (uint8_t)strtol(argv[2], &endptr, 10);
7443 if (errno != 0 || *endptr != '\0')
7444 {
7445 (void)PRINTF("Error during strtol:reconnect counter\r\n");
7446 goto done;
7447 }
7448 }
7449
7450 if (recon_counter == 0)
7451 {
7452 (void)PRINTF("Auto reconnect counter can not be 0\r\n");
7453 goto done;
7454 }
7455
7456 if (argc > 3)
7457 {
7458 errno = 0;
7459 recon_interval = (uint8_t)strtol(argv[3], &endptr, 10);
7460 if (errno != 0 || *endptr != '\0')
7461 {
7462 (void)PRINTF("Error during strtol:reconnect interval\r\n");
7463 goto done;
7464 }
7465 }
7466
7467 if (argc > 4)
7468 {
7469 errno = 0;
7470 flags = (uint16_t)strtol(argv[4], &endptr, 10);
7471 if (errno != 0 || *endptr != '\0')
7472 {
7473 (void)PRINTF("Error during strtol:flags\r\n");
7474 goto done;
7475 }
7476 }
7477
7478 recon_config.reconnect_counter = recon_counter;
7479 recon_config.reconnect_interval = recon_interval;
7480 recon_config.flags = flags;
7481
7482 ret = wlan_auto_reconnect_enable(recon_config);
7483 if (ret == WM_SUCCESS)
7484 {
7485 (void)PRINTF("Enabled auto reconnect\r\n");
7486 }
7487 else
7488 {
7489 (void)PRINTF("Failed to enable auto reconnect, error: %d\r\n", ret);
7490 }
7491 }
7492 else if (enable == 2)
7493 {
7494 ret = wlan_get_auto_reconnect_config(&recon_config);
7495 if (ret == WM_SUCCESS)
7496 {
7497 (void)PRINTF("Auto Reconnect Counter = %d\r\n", recon_config.reconnect_counter);
7498 (void)PRINTF("Auto Reconnect Interval = %d\r\n", recon_config.reconnect_interval);
7499 (void)PRINTF("Auto Reconnect Flags = %d\r\n", recon_config.flags);
7500 }
7501 else
7502 {
7503 (void)PRINTF("Failed to get auto reconnect configuration, error: %d\r\n", ret);
7504 }
7505 }
7506 else
7507 {
7508 (void)PRINTF("Error: Specify 0/1/2 to Disable/Enable/Get auto reconnect configuration\r\n");
7509 goto done;
7510 }
7511
7512 return;
7513
7514 done:
7515 dump_wlan_auto_reconnect_usage();
7516 return;
7517 }
7518 #endif
7519
7520 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
7521 static void dump_wlan_set_ind_rst_cfg_usage(void)
7522 {
7523 (void)PRINTF("Usage : \r\n");
7524 (void)PRINTF(" wlan-set-indrstcfg <ir_mode> [gpio_pin] \r\n");
7525 (void)PRINTF(" ir_mode : 0 -- Disable \r\n");
7526 (void)PRINTF(" 1 -- Enable out band reset, disable in band \r\n");
7527 (void)PRINTF(" 2 -- Enable in band, disable out band \r\n");
7528 (void)PRINTF(" gpio_pin : 255 -- Default pin for reset \r\n");
7529 (void)PRINTF(" any other number for changing the gpio for reset. \r\n");
7530 (void)PRINTF("Example : \r\n");
7531 (void)PRINTF(" wlan-set-indrstcfg 1 255 : Set default pin as reset pin \r\n");
7532 (void)PRINTF(" wlan-set-indrstcfg 0 : Disable the independent reset \r\n");
7533 (void)PRINTF(" wlan-set-indrstcfg 2 : Enable in band reset mode \r\n");
7534 }
7535
7536 static void test_set_indrst_cfg(int argc, char **argv)
7537 {
7538 wifi_indrst_cfg_t indrst_cfg;
7539
7540 if (argc < 2 || argc > 3)
7541 {
7542 dump_wlan_set_ind_rst_cfg_usage();
7543 return;
7544 }
7545
7546 memset(&indrst_cfg, 0, sizeof(wifi_indrst_cfg_t));
7547
7548 if ((argc == 2) || (argc == 3))
7549 {
7550 errno = 0;
7551 indrst_cfg.ir_mode = (uint8_t)strtol(argv[1], NULL, 0);
7552
7553 if (errno != 0)
7554 {
7555 (void)PRINTF("Error during strtoul errno:%d", errno);
7556 }
7557
7558 /* ir_mode */
7559 if (indrst_cfg.ir_mode < 0 || indrst_cfg.ir_mode > 2)
7560 {
7561 (void)PRINTF("Invalid ir mode parameter (0/1/2)!\n\r");
7562 return;
7563 }
7564
7565 /* gpio_pin */
7566 if (argc == 3)
7567 {
7568 errno = 0;
7569 indrst_cfg.gpio_pin = (uint8_t)strtol(argv[2], NULL, 0);
7570
7571 if (errno != 0)
7572 {
7573 (void)PRINTF("Error during strtoul errno:%d", errno);
7574 }
7575
7576 if ((indrst_cfg.gpio_pin != 0xFF) && (indrst_cfg.gpio_pin < 0))
7577 {
7578 (void)PRINTF("Invalid gpio pin no !\n\r");
7579 return;
7580 }
7581 }
7582 }
7583
7584 int rv = wlan_set_indrst_cfg(&indrst_cfg);
7585
7586 if (rv != WM_SUCCESS)
7587 {
7588 (void)PRINTF("Unable to set independent reset config\r\n");
7589 }
7590 else
7591 {
7592 (void)PRINTF("Independent Reset Mode set as: %s\n\r",
7593 (indrst_cfg.ir_mode == 0) ? "disabled" : ((indrst_cfg.ir_mode == 1) ? "Out Band" : "In Band"));
7594 }
7595 }
7596
7597 static void test_get_indrst_cfg(int argc, char **argv)
7598 {
7599 wifi_indrst_cfg_t indrst_cfg;
7600
7601 memset(&indrst_cfg, 0, sizeof(wifi_indrst_cfg_t));
7602 int rv = wlan_get_indrst_cfg(&indrst_cfg);
7603
7604 if (rv != WM_SUCCESS)
7605 {
7606 (void)PRINTF("Unable to get independent reset config\r\n");
7607 }
7608 else
7609 {
7610 if ((indrst_cfg.ir_mode < 0) || (indrst_cfg.ir_mode > 2))
7611 {
7612 (void)PRINTF("FW error Mode must be 0, 1 or 2\n");
7613 return;
7614 }
7615 PRINTF("Independent Reset Mode = %s\r\n",
7616 (indrst_cfg.ir_mode == 0) ? "disabled" : ((indrst_cfg.ir_mode == 1) ? "Out Band" : "In Band"));
7617 if (indrst_cfg.ir_mode == 1)
7618 (void)PRINTF("GPIO Pin = %d\n\n", indrst_cfg.gpio_pin);
7619 }
7620 }
7621
7622 static void dump_wlan_independent_reset_usage(void)
7623 {
7624 (void)PRINTF("Usage : \r\n");
7625 (void)PRINTF(" wlan-independent-reset \r\n");
7626 }
7627
7628 static void test_wlan_independent_reset(int argc, char **argv)
7629 {
7630 int ret = -WM_FAIL;
7631
7632 if (argc != 1)
7633 {
7634 dump_wlan_independent_reset_usage();
7635 return;
7636 }
7637
7638 ret = wlan_independent_reset();
7639
7640 if (ret == WM_SUCCESS)
7641 {
7642 (void)PRINTF("Independent reset success\r\n");
7643 }
7644 else
7645 {
7646 (void)PRINTF("Independent reset failed\r\n");
7647 }
7648 }
7649 #endif
7650
7651 #if CONFIG_INACTIVITY_TIMEOUT_EXT
7652 static void dump_wlan_sta_inactivityto_usage(void)
7653 {
7654 (void)PRINTF("Usage:\r\n");
7655 (void)PRINTF(" wlan-sta-inactivityto <n> <m> <l> [k] [j]\r\n");
7656 (void)PRINTF("where the parameter are:\r\n");
7657 (void)PRINTF(" <n>: timeout unit in microseconds.\r\n");
7658 (void)PRINTF(" <m>: Inactivity timeout for unicast data.\r\n");
7659 (void)PRINTF(" <l>: Inactivity timeout for multicast data.\r\n");
7660 (void)PRINTF(" [k]: Inactivity timeout for new Rx traffic after PS notification to AP.\r\n");
7661 (void)PRINTF(" [j]: Inactivity timeout for cmd.\r\n");
7662 (void)PRINTF("Fox example:\r\n");
7663 (void)PRINTF(" wlan-sta-inactivityto : Get the timeout value\r\n");
7664 (void)PRINTF(" wlan-sta-inactivityto 1000 2 3 : Set timeout unit to 1000 us (1 ms),\r\n");
7665 (void)PRINTF(" inactivity timeout for unicast data is 2 ms,\r\n");
7666 (void)PRINTF(" inactivity timeout for multicast data is 3 ms\r\n");
7667 }
7668
7669 static void test_wlan_sta_inactivityto(int argc, char **argv)
7670 {
7671 int ret = 0;
7672 t_u16 action = 0;
7673 wlan_inactivity_to_t inac_to;
7674
7675 (void)memset(&inac_to, 0, sizeof(wlan_inactivity_to_t));
7676
7677 /* Check if arguments are valid */
7678 if ((argc != 1) && (argc != 4) && (argc != 5) && (argc != 6))
7679 {
7680 (void)PRINTF("Error: invalid number of arguments.\r\n");
7681 dump_wlan_sta_inactivityto_usage();
7682 return;
7683 }
7684
7685 /* GET operation */
7686 if (argc == 1)
7687 {
7688 action = ACTION_GET;
7689 }
7690 else /* SET operation */
7691 {
7692 action = ACTION_SET;
7693 inac_to.timeout_unit = strtol(argv[1], NULL, 0);
7694 inac_to.unicast_timeout = strtol(argv[2], NULL, 0);
7695 inac_to.mcast_timeout = strtol(argv[3], NULL, 0);
7696 if (argc >= 5)
7697 inac_to.ps_entry_timeout = strtol(argv[4], NULL, 0);
7698 if (argc == 6)
7699 inac_to.ps_cmd_timeout = strtol(argv[5], NULL, 0);
7700 }
7701
7702 ret = wlan_sta_inactivityto(&inac_to, action);
7703 if (ret == WM_SUCCESS)
7704 {
7705 if (action == ACTION_GET)
7706 {
7707 (void)PRINTF("Timeout unit is %d us\r\n", inac_to.timeout_unit);
7708 (void)PRINTF("Inactivity timeout for unicast data is %d ms\r\n", inac_to.unicast_timeout);
7709 (void)PRINTF("Inactivity timeout for multicast data is %d ms\r\n", inac_to.mcast_timeout);
7710 (void)PRINTF("Inactivity timeout for new Rx traffic is %d ms\r\n", inac_to.ps_entry_timeout);
7711 (void)PRINTF("Inactivity timeout for cmd is %d ms\r\n", inac_to.ps_cmd_timeout);
7712 }
7713 else
7714 {
7715 (void)PRINTF("Success to set STA inactivity timeout.\r\n");
7716 }
7717 }
7718 else
7719 {
7720 (void)PRINTF("Failed to set STA inactivity timeout.\r\n");
7721 }
7722 }
7723 #endif
7724
7725 #ifdef RW610
7726 static void test_wlan_get_temperature(int argc, char **argv)
7727 {
7728 int32_t board_temperature = 0;
7729
7730 board_temperature = wlan_get_temperature();
7731
7732 (void)PRINTF("Board temperature :%d \r\n", board_temperature);
7733 }
7734 #endif
7735
7736 #if CONFIG_AUTO_NULL_TX
7737 static void dump_wlan_auto_null_tx_usage(void)
7738 {
7739 (void)PRINTF("Usage:\r\n");
7740 (void)PRINTF(" wlan-auto-null-tx <sta/uap> start interval <interval> dst_mac <dst_mac>\r\n");
7741 (void)PRINTF(" <interval> bit15:14 unit: 00-s 01-us 10-ms 11-one_shot bit13-0: interval\r\n");
7742 (void)PRINTF(" Please set interval Hexadecimal value. For example: 0x8064\r\n");
7743 (void)PRINTF(" <dst_mac> Destination MAC address\r\n");
7744 (void)PRINTF(" Please specify dst_mac if bss_type is uAP, and dst_mac should be of STA which connected to uAP\r\n");
7745 (void)PRINTF(" If bss_type is not uAP, no need to input dst_mac\r\n");
7746 (void)PRINTF(" wlan-auto-null-tx sta stop\r\n");
7747 }
7748
7749 static void test_wlan_auto_null_tx(int argc, char **argv)
7750 {
7751 int ret = -WM_FAIL;
7752 int arg = 2;
7753 mlan_bss_type bss_type = (mlan_bss_type)0;
7754
7755 wlan_auto_null_tx_t auto_null_tx;
7756
7757 if (argc < 3)
7758 {
7759 (void)PRINTF("Error: invalid number of arguments\r\n");
7760 dump_wlan_auto_null_tx_usage();
7761 return;
7762 }
7763
7764 memset(&auto_null_tx, 0x00, sizeof(wlan_auto_null_tx_t));
7765
7766 if (string_equal("sta", argv[1]))
7767 bss_type = MLAN_BSS_TYPE_STA;
7768 else if (string_equal("uap", argv[1]))
7769 bss_type = MLAN_BSS_TYPE_UAP;
7770 else
7771 {
7772 (void)PRINTF("Invalid bss type selection\r\n");
7773 return;
7774 }
7775
7776 if (string_equal("start", argv[2]))
7777 {
7778 auto_null_tx.start = MTRUE;
7779 arg += 1;
7780 if (string_equal("interval", argv[arg]))
7781 {
7782 if (argv[arg + 1][0] == '0' && (argv[arg + 1][1] == 'x' || argv[arg + 1][1] == 'X'))
7783 {
7784 auto_null_tx.interval = a2hex_or_atoi(argv[arg + 1]);
7785 }
7786 else
7787 {
7788 (void)PRINTF("Error: invalid interval argument\r\n");
7789 dump_wlan_auto_null_tx_usage();
7790 return;
7791 }
7792 arg += 2;
7793 }
7794 else
7795 {
7796 (void)PRINTF("Error: argument %d is invalid\r\n", arg);
7797 dump_wlan_auto_null_tx_usage();
7798 return;
7799 }
7800
7801 if (bss_type == MLAN_BSS_TYPE_STA)
7802 {
7803 if (is_sta_connected())
7804 {
7805 ret = wlan_get_current_network_bssid((char *)&auto_null_tx.dst_mac);
7806 if (ret != 0)
7807 {
7808 (void)PRINTF("Error: could not get current network bssid\r\n");
7809 return;
7810 }
7811 }
7812 else
7813 {
7814 (void)PRINTF("Error: not conneted AP\r\n");
7815 return;
7816 }
7817 }
7818 #if UAP_SUPPORT
7819 if (bss_type == MLAN_BSS_TYPE_UAP)
7820 {
7821 wifi_sta_list_t *sl = NULL;
7822 (void)wifi_uap_bss_sta_list(&sl);
7823 if (!sl)
7824 {
7825 (void)PRINTF("Failed to get sta list\n\r");
7826 return;
7827 }
7828 if (is_uap_started() && (sl->count > 0))
7829 {
7830 wifi_sta_info_t *si = (wifi_sta_info_t *)(void *)(&sl->count + 1);
7831 if (string_equal("dst_mac", argv[arg]))
7832 {
7833 unsigned int mac_matched = 0;
7834 ret = get_mac(argv[arg + 1], (char *)&auto_null_tx.dst_mac, ':');
7835 if (ret != 0)
7836 {
7837 dump_wlan_auto_null_tx_usage();
7838 (void)PRINTF("Error: invalid dst_mac argument\r\n");
7839 return;
7840 }
7841 for (int i = 0; i < sl->count; i++)
7842 {
7843 if (!memcmp(si[i].mac, auto_null_tx.dst_mac, 6))
7844 {
7845 mac_matched = 1;
7846 break;
7847 }
7848 }
7849 if (mac_matched == 0)
7850 {
7851 (void)PRINTF("Error: wrong dst_mac, please put one connected STA mac address\r\n");
7852 return;
7853 }
7854 arg += 2;
7855 }
7856 else
7857 {
7858 (void)PRINTF("Error: argument %d is invalid\r\n", arg);
7859 dump_wlan_auto_null_tx_usage();
7860 return;
7861 }
7862 }
7863 else
7864 {
7865 if (!is_uap_started())
7866 (void)PRINTF("uap isn't up\r\n");
7867 else
7868 (void)PRINTF("There is no STA connected to uAP\r\n");
7869 }
7870 }
7871 #endif
7872 }
7873 else if (string_equal("stop", argv[2]))
7874 {
7875 auto_null_tx.start = MFALSE;
7876 }
7877 else
7878 {
7879 (void)PRINTF("Error: invalid [%d] argument, give start/stop\r\n", arg + 1);
7880 dump_wlan_auto_null_tx_usage();
7881 return;
7882 }
7883
7884 /* bit7-4: bandwidth. bit3-0: priority, ignored if non-WMM */
7885 auto_null_tx.priority = 0x07;
7886
7887 ret = wlan_auto_null_tx(&auto_null_tx, bss_type);
7888 }
7889 #endif
7890
7891 #if defined(RW610) && (CONFIG_ANT_DETECT)
7892 static void swap_scan_entry(scan_result_entry_t *pEntry1, scan_result_entry_t *pEntry2)
7893 {
7894 scan_result_entry_t temp;
7895
7896 (void)memcpy((void *)&temp, (const void *)pEntry1, sizeof(scan_result_entry_t));
7897 (void)memcpy((void *)pEntry1, (const void *)pEntry2, sizeof(scan_result_entry_t));
7898 (void)memcpy((void *)pEntry2, (const void *)&temp, sizeof(scan_result_entry_t));
7899 }
7900
7901 static void copy_scan_result(scan_result_entry_t *pDst, struct wifi_scan_result2 *pSrc)
7902 {
7903 (void)memcpy((void *)&pDst->bssid[0], (const void *)&pSrc->bssid[0], sizeof(pSrc->bssid));
7904 (void)memcpy((void *)&pDst->ssid[0], (const void *)((char *)&pSrc->ssid[0]), (size_t)pSrc->ssid_len);
7905 pDst->ssid[pSrc->ssid_len] = (char)0;
7906 pDst->ssid_len = (size_t)pSrc->ssid_len;
7907 pDst->channel = pSrc->Channel;
7908 pDst->rssi = pSrc->RSSI;
7909 }
7910
7911 static void wlan_sort_scan_entry(scan_result_entry_t *pScan_entry)
7912 {
7913 unsigned int i;
7914 unsigned int j;
7915 unsigned int minIdx;
7916
7917 /* selection sort */
7918 for (i = 0; i < (ANT_DETECT_MAX_SCAN_ENTRY - 1); i++)
7919 {
7920 minIdx = i;
7921 for (j = i + 1; j < ANT_DETECT_MAX_SCAN_ENTRY; j++)
7922 {
7923 if (pScan_entry[j].rssi < pScan_entry[minIdx].rssi)
7924 {
7925 minIdx = j;
7926 }
7927 }
7928
7929 if (minIdx != i)
7930 {
7931 swap_scan_entry(&pScan_entry[minIdx], &pScan_entry[i]);
7932 }
7933 }
7934 }
7935
7936 static unsigned char wlan_calculate_avg_rssi(scan_result_entry_t *pScan_entry)
7937 {
7938 unsigned int i;
7939 unsigned char avg_rssi = 0;
7940 uint16_t sum_rssi = 0;
7941 uint8_t valid_entry = 0;
7942
7943 for (i = 0; i < ANT_DETECT_MAX_SCAN_ENTRY; i++)
7944 {
7945 if (pScan_entry[i].rssi == 0xff)
7946 {
7947 break;
7948 }
7949 else if (i > 0)
7950 {
7951 if (pScan_entry[i].rssi - pScan_entry[0].rssi >= 30)
7952 {
7953 break;
7954 }
7955 else
7956 {
7957 valid_entry++;
7958 }
7959 }
7960 else
7961 {
7962 valid_entry++;
7963 }
7964 }
7965
7966 if (valid_entry > 0 && valid_entry <= ANT_DETECT_MAX_SCAN_ENTRY)
7967 {
7968 (void)PRINTF("%d valid scan entry found\r\n", valid_entry);
7969 for (i = 0; i < valid_entry; i++)
7970 {
7971 sum_rssi += pScan_entry[i].rssi;
7972 }
7973 avg_rssi = sum_rssi / valid_entry;
7974 }
7975
7976 return avg_rssi;
7977 }
7978
7979 /** Find top 5 best scan info (with high RSSI) and save to scan entry
7980 *
7981 * If scan_networks_count is no more than 5, just copy scan info and sort;
7982 * Otherwise, use below logic:
7983 * 1.Get the first 5 scan results in scan table to scan entries;
7984 * 2.sort scan info in scan entries from high rssi to low rssi;
7985 * 3.then when get a new scan results in scan table, if it has
7986 * high rssi than the lowest one in scan entries, replace the
7987 * lowest entry with the new scan info and re-sort scan entries.
7988 *
7989 */
7990 static void wlan_get_best_scan_info(wlan_ant_detect_data_t *pData, unsigned int scan_networks_count)
7991 {
7992 int ret;
7993 unsigned int i;
7994 unsigned int net_count = scan_networks_count;
7995 unsigned int entry_count = ANT_DETECT_MAX_SCAN_ENTRY;
7996 wlan_ant_scan_info_t *pInfo = &pData->scan_info[pData->current_ant - 1];
7997 struct wifi_scan_result2 *res;
7998
7999 if (net_count <= entry_count)
8000 {
8001 for (i = 0; i < net_count; i++)
8002 {
8003 ret = wifi_get_scan_result(i, &res);
8004 if (ret == WM_SUCCESS)
8005 {
8006 copy_scan_result(&pInfo->scan_entry[i], res);
8007 }
8008 else
8009 {
8010 PRINTF("Error: can't get scan res %d\r\n", i);
8011 }
8012 }
8013 wlan_sort_scan_entry(&pInfo->scan_entry[0]);
8014 }
8015 else
8016 {
8017 unsigned int lowest_rssi_index = entry_count - 1;
8018 for (i = 0; i < net_count; i++)
8019 {
8020 ret = wifi_get_scan_result(i, &res);
8021 if (ret == WM_SUCCESS)
8022 {
8023 if (i < entry_count)
8024 {
8025 copy_scan_result(&pInfo->scan_entry[i], res);
8026
8027 if (i == entry_count - 1)
8028 {
8029 wlan_sort_scan_entry(&pInfo->scan_entry[0]);
8030 }
8031 }
8032 else
8033 {
8034 if (res->RSSI < pInfo->scan_entry[lowest_rssi_index].rssi)
8035 {
8036 copy_scan_result(&pInfo->scan_entry[lowest_rssi_index], res);
8037 wlan_sort_scan_entry(&pInfo->scan_entry[0]);
8038 }
8039 }
8040 }
8041 else
8042 {
8043 PRINTF("Error: can't get scan res %d\r\n", i);
8044 }
8045 }
8046 }
8047
8048 PRINTF("List top %d best scanned AP's info:\r\n", entry_count);
8049 for (i = 0; i < entry_count; i++)
8050 {
8051 print_mac(pInfo->scan_entry[i].bssid);
8052 PRINTF(" \"%s\"\r\n", pInfo->scan_entry[i].ssid);
8053 PRINTF("\tchannel: %d\r\n", pInfo->scan_entry[i].channel);
8054 PRINTF("\trssi: -%d dBm\r\n", pInfo->scan_entry[i].rssi);
8055 }
8056
8057 if (pData->detect_mode != PCB_DETECT_MODE)
8058 {
8059 pInfo->avg_rssi = wlan_calculate_avg_rssi(&pInfo->scan_entry[0]);
8060 PRINTF("avg_rssi: -%d dBm\r\n", pInfo->avg_rssi);
8061 }
8062 }
8063
8064 static void wlan_get_specific_scan_info(wlan_ant_scan_info_t *pInfo, unsigned int scan_networks_count)
8065 {
8066 int ret;
8067 unsigned int i;
8068 unsigned int count = scan_networks_count;
8069 struct wifi_scan_result2 *res;
8070
8071 for (i = 0; i < count; i++)
8072 {
8073 ret = wifi_get_scan_result(i, &res);
8074 if (ret == WM_SUCCESS)
8075 {
8076 copy_scan_result(&pInfo->scan_entry[pInfo->entry_idx], res);
8077 }
8078 else
8079 {
8080 PRINTF("Error: can't get scan res %d\r\n", i);
8081 }
8082 }
8083
8084 print_mac(pInfo->scan_entry[pInfo->entry_idx].bssid);
8085 PRINTF(" \"%s\"\r\n", pInfo->scan_entry[pInfo->entry_idx].ssid);
8086 PRINTF("\tchannel: %d\r\n", pInfo->scan_entry[pInfo->entry_idx].channel);
8087 PRINTF("\trssi: -%d dBm\r\n", pInfo->scan_entry[pInfo->entry_idx].rssi);
8088 }
8089
8090 static void wlan_get_best_two_ants(wlan_ant_detect_data_t *pData)
8091 {
8092 uint16_t i;
8093 uint16_t minIdx1;
8094 uint16_t minIdx2;
8095 wlan_ant_scan_info_t *pScan_info = &pData->scan_info[0];
8096
8097 if (pScan_info[0].avg_rssi < pScan_info[1].avg_rssi)
8098 {
8099 minIdx1 = 0;
8100 minIdx2 = 1;
8101 }
8102 else
8103 {
8104 minIdx1 = 1;
8105 minIdx2 = 0;
8106 }
8107
8108 for (i = 2; i < pData->ant_port_count; i++)
8109 {
8110 if (pScan_info[i].avg_rssi < pScan_info[minIdx1].avg_rssi)
8111 {
8112 minIdx2 = minIdx1;
8113 minIdx1 = i;
8114 }
8115 else if (pScan_info[i].avg_rssi < pScan_info[minIdx2].avg_rssi)
8116 {
8117 minIdx2 = i;
8118 }
8119 }
8120
8121 pData->best_ant = minIdx1 + 1;
8122 pData->next_best_ant = minIdx2 + 1;
8123 pData->detect_done = 1;
8124 }
8125
8126 static void wlan_evaluate_ant_by_avg_rssi(wlan_ant_detect_data_t *pData)
8127 {
8128 uint16_t i;
8129 uint8_t valid_res = pData->ant_port_count;
8130 wlan_ant_scan_info_t *pScan_info = &pData->scan_info[0];
8131
8132 (void)PRINTF("\nEvaluate result:\r\n");
8133 (void)PRINTF("\t avg_rssi\r\n");
8134 for (i = 0; i < pData->ant_port_count; i++)
8135 {
8136 (void)PRINTF("Antenna %d", i + 1);
8137 (void)PRINTF("\t-%d dBm\r\n", pScan_info[i].avg_rssi);
8138 if (pScan_info[i].avg_rssi == 0xff)
8139 {
8140 valid_res--;
8141 }
8142 }
8143
8144 (void)PRINTF("There are %d antenna with valid result%s.\r\n", valid_res, valid_res <= 1U ? "" : "s");
8145 if (valid_res <= 1)
8146 {
8147 pData->detect_done = -1;
8148 return;
8149 }
8150
8151 wlan_get_best_two_ants(pData);
8152 }
8153
8154 /** Evaluate all antennas by one common device
8155 *
8156 * This function is to find one common BSSID in all antennas' scan entries,
8157 * and to find 2 best antennas based on the common BSSID's rssi value.
8158 *
8159 * The logic is:
8160 * 1.Find the ant who has the best scan RSSI of all antennas' scan entries;
8161 * 2.Take this ant and its best scan BSSID as a reference;
8162 * 3.Loop the reference ant's scan entried (rssi from high to low) and check
8163 * whether the same BSSID is in other antennas;
8164 * 4.If find the same BSSID in one antenna, record its entry idx to the
8165 * corresponding location in array com_idx_per_ant[];
8166 * 5.As com_idx_per_ant[] is initialized as 0xff, check its value and we can
8167 * we can know whether find a common BSSID or not.
8168 * 6.Rank and find 2 best antennas based on the common BSSID's rssi value.
8169 *
8170 * \return 1 if find one common BSSID.
8171 * \return -1 if no common BSSID.
8172 *
8173 */
8174 static int wlan_evaluate_ant_by_common_device(wlan_ant_detect_data_t *pData)
8175 {
8176 uint8_t i;
8177 uint8_t j;
8178 uint8_t com_idx_per_ant[MAX_ANTENNA_PORT_NUM];
8179 uint8_t current_best_ant;
8180 int detect_done = 0;
8181 t_u8 zero_bssid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
8182 wlan_ant_scan_info_t *pScan_info = &pData->scan_info[0];
8183 wlan_ant_scan_info_t *pRef_info = NULL;
8184
8185 current_best_ant = 0;
8186 for (i = 1; i < pData->ant_port_count; i++)
8187 {
8188 if (pData->scan_info[i].scan_entry[0].rssi < pData->scan_info[current_best_ant].scan_entry[0].rssi)
8189 {
8190 current_best_ant = i;
8191 }
8192 }
8193
8194 pRef_info = &pData->scan_info[current_best_ant];
8195
8196 memset((void *)&com_idx_per_ant[0], 0xff, pData->ant_port_count);
8197 for (i = 0; i < ANT_DETECT_MAX_SCAN_ENTRY; i++)
8198 {
8199 uint8_t temp = 0;
8200 if (memcmp(pRef_info->scan_entry[i].bssid, zero_bssid, 6) == 0)
8201 {
8202 break;
8203 }
8204
8205 for (uint8_t ant_idx = 0; ant_idx < pData->ant_port_count; ant_idx++)
8206 {
8207 if (ant_idx == current_best_ant)
8208 {
8209 continue;
8210 }
8211
8212 for (j = 0; j < ANT_DETECT_MAX_SCAN_ENTRY; j++)
8213 {
8214 if (memcmp(pScan_info[ant_idx].scan_entry[j].bssid, zero_bssid, 6) == 0)
8215 {
8216 break;
8217 }
8218
8219 if (memcmp(pRef_info->scan_entry[i].bssid, pScan_info[ant_idx].scan_entry[j].bssid, 6) == 0)
8220 {
8221 com_idx_per_ant[ant_idx] = j;
8222 break;
8223 }
8224 }
8225 }
8226
8227 for (uint8_t k = 0; k < pData->ant_port_count; k++)
8228 {
8229 if (com_idx_per_ant[k] == 0xff)
8230 {
8231 temp++;
8232 }
8233 }
8234
8235 /*
8236 * if other antennas have the same BSSID as reference ant,
8237 * then the corresponding value in com_idx_per_ant[] array
8238 * is not 0xff and temp should be 1
8239 */
8240 if (temp == 1)
8241 {
8242 com_idx_per_ant[current_best_ant] = i;
8243 detect_done = 1;
8244 break;
8245 }
8246 else // if (temp > 1)
8247 {
8248 if (i == ANT_DETECT_MAX_SCAN_ENTRY - 1)
8249 {
8250 detect_done = -1;
8251 break;
8252 }
8253 else
8254 {
8255 memset((void *)&com_idx_per_ant[0], 0xff, pData->ant_port_count);
8256 }
8257 }
8258 }
8259
8260 if (detect_done == 1)
8261 {
8262 (void)PRINTF("\nFind one common device\r\n");
8263 (void)PRINTF("List the info on every antenna for this common device\r\n");
8264 for (i = 0; i < pData->ant_port_count; i++)
8265 {
8266 PRINTF("Antenna %d:\r\n", i + 1);
8267 print_mac(pScan_info[i].scan_entry[com_idx_per_ant[i]].bssid);
8268 PRINTF(" \"%s\"\r\n", pScan_info[i].scan_entry[com_idx_per_ant[i]].ssid);
8269 PRINTF("\trssi[%d]: -%d dBm\r\n", i, pScan_info[i].scan_entry[com_idx_per_ant[i]].rssi);
8270 pScan_info[i].avg_rssi = pScan_info[i].scan_entry[com_idx_per_ant[i]].rssi;
8271 }
8272 wlan_get_best_two_ants(pData);
8273 }
8274 else
8275 {
8276 detect_done = -1;
8277 }
8278
8279 return detect_done;
8280 }
8281
8282 uint8_t device_count_to_check = PCB_DETECT_MODE_CHECK_DEVICE_COUNT;
8283 static void wlan_evaluate_ant_by_specific_device(wlan_ant_detect_data_t *pData)
8284 {
8285 unsigned int i;
8286 unsigned int j;
8287 uint16_t sum_rssi = 0;
8288 wlan_ant_scan_info_t *pScan_info = &pData->scan_info[0];
8289
8290 (void)PRINTF("\nEvaluate result:\r\n");
8291 (void)PRINTF("\t avg_rssi\r\n");
8292 for (i = 0; i < pData->ant_port_count; i++)
8293 {
8294 sum_rssi = 0;
8295 (void)PRINTF("Antenna %d", i + 1);
8296 for (j = 0; j < device_count_to_check; j++)
8297 {
8298 sum_rssi += pScan_info[i].scan_entry[j].rssi;
8299 }
8300 pScan_info[i].avg_rssi = sum_rssi / device_count_to_check;
8301 PRINTF("\t-%d dBm\r\n", pScan_info[i].avg_rssi);
8302 }
8303
8304 wlan_get_best_two_ants(pData);
8305 }
8306
8307 wlan_ant_detect_data_t wlan_ant_detect_data;
8308 static int __ant_detect_scan_cb(unsigned int count)
8309 {
8310 wlan_ant_detect_data_t *pData = (wlan_ant_detect_data_t *)&wlan_ant_detect_data;
8311 wlan_ant_scan_info_t *pInfo = (wlan_ant_scan_info_t *)&pData->scan_info[pData->current_ant - 1];
8312
8313 if (count == 0U)
8314 {
8315 pInfo->avg_rssi = 0xff;
8316 (void)PRINTF("no networks found\r\n");
8317 goto end;
8318 }
8319
8320 (void)PRINTF("%d network%s found\r\n", count, (count == 1U ? "" : "s"));
8321 if (pData->detect_mode == PCB_DETECT_MODE)
8322 {
8323 if (pData->current_ant == 1)
8324 {
8325 if (count == 1)
8326 {
8327 device_count_to_check = 1;
8328 }
8329 wlan_get_best_scan_info(pData, count);
8330 }
8331 else
8332 {
8333 wlan_get_specific_scan_info(pInfo, count);
8334 }
8335 }
8336 else
8337 {
8338 wlan_get_best_scan_info(pData, count);
8339 }
8340
8341 end:
8342 pInfo->scan_done = MTRUE;
8343 if (pData->detect_mode == PCB_DETECT_MODE)
8344 {
8345 if (count == 0 && pData->current_ant == 1)
8346 {
8347 pData->detect_done = -1;
8348 }
8349 else if (pData->current_ant == pData->ant_port_count && pInfo->entry_idx == device_count_to_check - 1)
8350 {
8351 (void)PRINTF("evaluate ant by specific device\r\n");
8352 wlan_evaluate_ant_by_specific_device(pData);
8353 }
8354 }
8355 else if (pData->current_ant == pData->ant_port_count)
8356 {
8357 if (wlan_evaluate_ant_by_common_device(pData) == 1)
8358 {
8359 pData->detect_done = 1;
8360 }
8361 else
8362 {
8363 wlan_evaluate_ant_by_avg_rssi(pData);
8364 }
8365 }
8366
8367 return 0;
8368 }
8369
8370 static int wlan_detect_ant_start_scan(wlan_scan_params_v2_t wlan_scan_param)
8371 {
8372 char zero_bssid[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
8373 int ret;
8374 ret = wlan_scan_with_opt(wlan_scan_param);
8375
8376 if (ret != 0)
8377 {
8378 (void)PRINTF("Error: scan request failed\r\n");
8379 }
8380 else
8381 {
8382 (void)PRINTF("Scan on ");
8383 if (wlan_scan_param.num_channels > 1)
8384 {
8385 (void)PRINTF("%d channels ", wlan_scan_param.num_channels);
8386 }
8387 else if (wlan_scan_param.num_channels == 1)
8388 {
8389 (void)PRINTF("channel %d ", wlan_scan_param.chan_list[0].chan_number);
8390 }
8391 else
8392 {
8393 (void)PRINTF("full channel ");
8394 }
8395
8396 if (memcmp(&wlan_scan_param.bssid[0], &zero_bssid[0], 6))
8397 {
8398 (void)PRINTF("and for bssid ");
8399 print_mac((const char *)wlan_scan_param.bssid);
8400 }
8401 (void)PRINTF("scheduled...\r\n");
8402 }
8403
8404 return ret;
8405 }
8406
8407 static void wlan_detect_ant_set_mode(uint16_t best_ant, uint16_t next_best_ant)
8408 {
8409 int ret;
8410 uint32_t ant_mode;
8411 uint16_t evaluate_time = 0x0;
8412 uint8_t evaluate_mode = 0xff;
8413 uint8_t evaluate_mode_lookup_table[3][3] = {
8414 /* next best ant */
8415 /* Ant1 Ant2 Ant3 */
8416 {0xff, 0, 2}, /* Ant1 */
8417 {0, 0xff, 1},
8418 /* Ant2 */ /* best ant */
8419 {2, 1, 0xff}, /* Ant3 */
8420 };
8421
8422 evaluate_mode = evaluate_mode_lookup_table[best_ant - 1][next_best_ant - 1];
8423 ant_mode = 0xffff;
8424 ret = wlan_set_antcfg(ant_mode, evaluate_time, evaluate_mode);
8425 if (ret == WM_SUCCESS)
8426 {
8427 (void)PRINTF("Enable Antenna diversity with evaluate mode %d successful\r\n", evaluate_mode);
8428 }
8429 else
8430 {
8431 (void)PRINTF("Enable Antenna diversity with evaluate mode %d failed\r\n", evaluate_mode);
8432 }
8433 }
8434
8435 static void wlan_start_detect_ant(void)
8436 {
8437 int ret = -1;
8438 uint32_t ant_mode;
8439 uint16_t evaluate_time = 0x0;
8440 uint8_t evaluate_mode = 0xff;
8441 uint16_t current_antenna;
8442 unsigned int i = 0;
8443 unsigned int chIdx = 0;
8444 wlan_ant_detect_data_t *pDetect_data = (wlan_ant_detect_data_t *)&wlan_ant_detect_data;
8445 wlan_scan_params_v2_t wlan_scan_param;
8446
8447 (void)memset(&wlan_scan_param, 0, sizeof(wlan_scan_params_v2_t));
8448 if (pDetect_data->detect_mode == QUICK_DETECT_MODE)
8449 {
8450 wlan_scan_param.num_channels = 1;
8451 }
8452 else if (pDetect_data->detect_mode == NORMAL_DETECT_MODE)
8453 {
8454 wlan_scan_param.num_channels = pDetect_data->channel_list->num_channels;
8455 for (i = 0; i < pDetect_data->channel_list->num_channels; i++)
8456 {
8457 wlan_scan_param.chan_list[i].chan_number = pDetect_data->channel_list->chan_number[i];
8458 }
8459 }
8460 wlan_scan_param.cb = __ant_detect_scan_cb;
8461
8462 do
8463 {
8464 pDetect_data->detect_done = 0;
8465
8466 if (pDetect_data->detect_mode == QUICK_DETECT_MODE)
8467 {
8468 wlan_scan_param.chan_list[0].chan_number = pDetect_data->channel_list->chan_number[chIdx];
8469 }
8470
8471 for (current_antenna = 1; current_antenna <= pDetect_data->ant_port_count; current_antenna++)
8472 {
8473 ant_mode = (1 << (current_antenna - 1));
8474
8475 ret = wlan_set_antcfg(ant_mode, evaluate_time, evaluate_mode);
8476 if (ret == WM_SUCCESS)
8477 {
8478 (void)PRINTF("\nStart to evaluate antenna %d\r\n", current_antenna);
8479 pDetect_data->current_ant = current_antenna;
8480
8481 if (pDetect_data->detect_mode == PCB_DETECT_MODE && current_antenna > 1)
8482 {
8483 for (i = 0; i < device_count_to_check; i++)
8484 {
8485 scan_result_entry_t *pSpecInfo = &pDetect_data->scan_info[0].scan_entry[i];
8486 (void)memcpy((void *)&wlan_scan_param.bssid[0], (const void *)&pSpecInfo->bssid[0],
8487 sizeof(wlan_scan_param.bssid));
8488 wlan_scan_param.num_channels = 1;
8489 wlan_scan_param.chan_list[0].chan_number = pSpecInfo->channel;
8490
8491 pDetect_data->scan_info[current_antenna - 1].scan_done = MFALSE;
8492 pDetect_data->scan_info[current_antenna - 1].entry_idx = i;
8493 ret = wlan_detect_ant_start_scan(wlan_scan_param);
8494 if (ret != 0)
8495 {
8496 break;
8497 }
8498 else
8499 {
8500 while (pDetect_data->scan_info[current_antenna - 1].scan_done != MTRUE)
8501 {
8502 OSA_TimeDelay(3);
8503 }
8504 }
8505 }
8506 }
8507 else
8508 {
8509 ret = wlan_detect_ant_start_scan(wlan_scan_param);
8510 if (ret != 0)
8511 {
8512 break;
8513 }
8514 else
8515 {
8516 while (pDetect_data->scan_info[current_antenna - 1].scan_done != MTRUE)
8517 {
8518 OSA_TimeDelay(3);
8519 }
8520 }
8521 }
8522 }
8523 else
8524 {
8525 (void)PRINTF("\nError: Failed to set Antenna %d\r\n", current_antenna);
8526 break;
8527 }
8528 }
8529
8530 if (ret != 0)
8531 {
8532 break;
8533 }
8534
8535 while (pDetect_data->detect_done == 0)
8536 {
8537 // wait untill evaluation complete
8538 OSA_TimeDelay(2);
8539 }
8540
8541 if (pDetect_data->detect_mode == QUICK_DETECT_MODE)
8542 {
8543 if (pDetect_data->detect_done == 1)
8544 {
8545 break;
8546 }
8547 else if (pDetect_data->detect_done == -1)
8548 {
8549 chIdx++;
8550 if (chIdx >= pDetect_data->channel_list->num_channels)
8551 {
8552 break;
8553 }
8554 }
8555 }
8556 else
8557 {
8558 break;
8559 }
8560 } while (pDetect_data->detect_done != 1);
8561
8562 if (pDetect_data->detect_done == 1)
8563 {
8564 (void)PRINTF("\nCurrently, best antenna is %d, next best antenna is %d\r\n", pDetect_data->best_ant,
8565 pDetect_data->next_best_ant);
8566 wlan_detect_ant_set_mode(pDetect_data->best_ant, pDetect_data->next_best_ant);
8567 }
8568 else
8569 {
8570 ant_mode = 1;
8571 ret = wlan_set_antcfg(ant_mode, evaluate_time, evaluate_mode);
8572 (void)PRINTF("\nFailed to detect antenna\r\n");
8573 }
8574 }
8575
8576 static void dump_wlan_detect_ant_usage(void)
8577 {
8578 (void)PRINTF("Usage:\r\n");
8579 (void)PRINTF("wlan-detect-ant <detect_mode> <ant_port_count> channel <channel> ... \r\n");
8580 (void)PRINTF("\r\n");
8581 (void)PRINTF("\t<detect_mode>: \r\n");
8582 (void)PRINTF("\t 0 -- normal detect mode: scan on all cfg channel list antenna by antenna.\r\n");
8583 (void)PRINTF("\t 1 -- quick detect mode: scan channel by channel on all antennas,\r\n");
8584 (void)PRINTF("\t and stop detect once detect done on one of channel in channel list.\r\n");
8585 (void)PRINTF("\t 2 -- PCB detect mode: scan on full channel list with PCB antenna firstly,\r\n");
8586 (void)PRINTF(
8587 "\t and select best 2 ex-APs, for the other antennas, just scan the specific channel\r\n");
8588 (void)PRINTF(
8589 "\t and the specific BSSID of 2 ex-APs; then compare scan RSSI and find best 2 ANTs.\r\n");
8590 (void)PRINTF("\t<ant_port_count>: \r\n");
8591 (void)PRINTF("\t total count of antenna port, max 4\r\n");
8592 (void)PRINTF("\tchannel <channel> ...: \r\n");
8593 (void)PRINTF("\t You can specify one or more channels to scan.\r\n");
8594 (void)PRINTF("\t If configure more than one channel, please seperate with ','.\r\n");
8595 (void)PRINTF("\t If not specified, will scan on full channel list.\r\n");
8596 (void)PRINTF("Examples:\r\n");
8597 (void)PRINTF("wlan-detect-ant 1 3 channel 1\r\n");
8598 (void)PRINTF("wlan-detect-ant 1 3 channel 1,6,11,36,40,44\r\n");
8599 (void)PRINTF("wlan-detect-ant 1 3\r\n");
8600 (void)PRINTF("wlan-detect-ant 0 3\r\n");
8601 (void)PRINTF("wlan-detect-ant 2 3\r\n");
8602 }
8603
8604 static void test_wlan_detect_ant(int argc, char **argv)
8605 {
8606 unsigned start_msec;
8607 unsigned end_msec;
8608 int arg = 1;
8609 uint8_t i;
8610 uint8_t j;
8611 uint8_t detect_mode = 0;
8612 uint8_t antenna_port_count = 0;
8613 wlan_ant_detect_data_t *pDetect_data = NULL;
8614 cfg_scan_channel_list_t *cfg_channel_list = NULL;
8615
8616 if (argc < 3 || argc == 4)
8617 {
8618 dump_wlan_detect_ant_usage();
8619 (void)PRINTF("Error: invalid number of arguments\r\n");
8620 return;
8621 }
8622
8623 detect_mode = (uint8_t)atoi(argv[arg]);
8624 if (detect_mode != NORMAL_DETECT_MODE && detect_mode != QUICK_DETECT_MODE && detect_mode != PCB_DETECT_MODE)
8625 {
8626 dump_wlan_detect_ant_usage();
8627 (void)PRINTF("Error: invalid detect_mode\r\n");
8628 return;
8629 }
8630
8631 arg = 2;
8632 antenna_port_count = (uint8_t)atoi(argv[arg]);
8633 if (antenna_port_count > MAX_ANTENNA_PORT_NUM || antenna_port_count < 3)
8634 {
8635 dump_wlan_detect_ant_usage();
8636 (void)PRINTF("Error: invalid antenna_port_count\r\n");
8637 return;
8638 }
8639
8640 arg = 3;
8641 (void)memset(&wlan_ant_detect_data, 0x00, sizeof(wlan_ant_detect_data_t));
8642 pDetect_data = (wlan_ant_detect_data_t *)&wlan_ant_detect_data;
8643 for (i = 0; i < antenna_port_count; i++)
8644 {
8645 wlan_ant_scan_info_t *pInfo = (wlan_ant_scan_info_t *)&pDetect_data->scan_info[i];
8646 for (j = 0; j < ANT_DETECT_MAX_SCAN_ENTRY; j++)
8647 {
8648 pInfo->scan_entry[j].rssi = 0xff;
8649 }
8650 }
8651
8652 pDetect_data->detect_mode = detect_mode;
8653 pDetect_data->ant_port_count = antenna_port_count;
8654 if (pDetect_data->detect_mode == PCB_DETECT_MODE)
8655 {
8656 goto start_detect;
8657 }
8658
8659 cfg_channel_list = (cfg_scan_channel_list_t *)OSA_MemoryAllocate(sizeof(cfg_scan_channel_list_t));
8660 if (cfg_channel_list == NULL)
8661 {
8662 (void)PRINTF("Failed to alloc buffer for channel list\r\n");
8663 return;
8664 }
8665 (void)memset(cfg_channel_list, 0, sizeof(cfg_scan_channel_list_t));
8666
8667 if (argc > 4 && string_equal("channel", argv[arg]))
8668 {
8669 if (get_channel_list(argv[arg + 1], (uint8_t *)&cfg_channel_list->num_channels,
8670 (uint8_t *)&cfg_channel_list->chan_number[0], ',') != false)
8671 {
8672 (void)PRINTF(
8673 "Error: invalid channel"
8674 " argument\n");
8675 OSA_MemoryFree(cfg_channel_list);
8676 return;
8677 }
8678 }
8679 else
8680 {
8681 // get full channel list
8682 wlan_chanlist_t chanlist;
8683 (void)memset(&chanlist, 0x00, sizeof(wlan_chanlist_t));
8684 int rv = wlan_get_chanlist(&chanlist);
8685 if (rv != WM_SUCCESS)
8686 {
8687 (void)PRINTF("Unable to get channel list configuration\r\n");
8688 OSA_MemoryFree(cfg_channel_list);
8689 return;
8690 }
8691 else
8692 {
8693 uint8_t i = 0;
8694 cfg_channel_list->num_channels = chanlist.num_chans;
8695 for (i = 0; i < chanlist.num_chans; i++)
8696 {
8697 cfg_channel_list->chan_number[i] = chanlist.chan_info[i].chan_num;
8698 }
8699 }
8700 }
8701
8702 pDetect_data->channel_list = cfg_channel_list;
8703
8704 start_detect:
8705 start_msec = OSA_TicksToMsec(OSA_TicksGet());
8706 (void)PRINTF("%d: Start to detect ant\r\n", start_msec);
8707 wlan_start_detect_ant();
8708 if (cfg_channel_list)
8709 {
8710 OSA_MemoryFree(cfg_channel_list);
8711 }
8712 end_msec = OSA_TicksToMsec(OSA_TicksGet());
8713 (void)PRINTF("%d: End of detect ant\r\n", end_msec);
8714 (void)PRINTF("It cost %dms to detect ant\r\n", end_msec - start_msec);
8715 }
8716 #endif
8717
8718 static void test_wlan_get_max_clients_count(int argc, char **argv)
8719 {
8720 unsigned int max_sta_num;
8721 int ret = -WM_FAIL;
8722
8723 ret = wlan_get_uap_max_clients(&max_sta_num);
8724 if (ret != WM_SUCCESS)
8725 {
8726 (void)PRINTF("Failed to get maximum number of stations\r\n");
8727 return;
8728 }
8729
8730 (void)PRINTF("Maximum number of stations: %d\r\n", max_sta_num);
8731 }
8732
8733 static void test_wlan_get_ps_cfg(int argc, char **argv)
8734 {
8735 struct {
8736 uint8_t cm_ieeeps_configured : 1;
8737 uint8_t cm_deepsleepps_configured : 1;
8738 #if CONFIG_WNM_PS
8739 uint8_t cm_wnmps_configured : 1;
8740 #endif
8741 } ps_mode_cfg = {0};
8742 int ret = -WM_FAIL;
8743
8744 ret = wlan_get_ps_mode_cfg((uint8_t *)&ps_mode_cfg);
8745 if (ret != WM_SUCCESS)
8746 {
8747 (void)PRINTF("Failed to get power save mode setting\r\n");
8748 return;
8749 }
8750
8751 (void)PRINTF("Power save mode setting: \r\n");
8752 (void)PRINTF(" IEEE ps : %d\r\n", ps_mode_cfg.cm_ieeeps_configured);
8753 (void)PRINTF(" Deep sleep: %d\r\n", ps_mode_cfg.cm_deepsleepps_configured);
8754 #if CONFIG_WNM_PS
8755 (void)PRINTF(" WNM ps : %d\r\n", ps_mode_cfg.cm_wnmps_configured);
8756 #endif
8757 }
8758
8759 static struct cli_command tests[] = {
8760 {"wlan-thread-info", NULL, test_wlan_thread_info},
8761 #if CONFIG_SCHED_SWITCH_TRACE
8762 {"wlan-sched-switch-debug", NULL, test_wlan_sched_switch_debug},
8763 #endif
8764 {"wlan-net-stats", NULL, test_wlan_net_stats},
8765 {"wlan-set-mac", "<MAC_Address>", test_wlan_set_mac_address},
8766 {"wlan-scan", NULL, test_wlan_scan},
8767 {"wlan-scan-opt", "ssid <ssid> bssid ...", test_wlan_scan_opt},
8768 {"wlan-ieee-ps", "<0/1>", test_wlan_ieee_ps},
8769 {"wlan-set-ps-cfg", "<null_pkt_interval>", test_wlan_set_ps_cfg},
8770 {"wlan-deep-sleep-ps", "<0/1>", test_wlan_deep_sleep_ps},
8771 #if (CONFIG_WNM_PS)
8772 {"wlan-wnm-ps", "<0/1> <sleep_interval>", test_wlan_wnm_ps},
8773 #endif
8774 #if CONFIG_WIFI_RTS_THRESHOLD
8775 {"wlan-rts", "<sta/uap> <rts threshold>", test_wlan_set_rts},
8776 #endif
8777 #if CONFIG_WIFI_FRAG_THRESHOLD
8778 {"wlan-frag", "<sta/uap> <fragment threshold>", test_wlan_set_frag},
8779 #endif
8780 #if (CONFIG_11MC) || (CONFIG_11AZ)
8781 {"wlan-ftm-ctrl", "<action> <loop_cnt> <peer_mac> <channel>", test_wlan_ftm_ctrl},
8782 {"wlan-11mc-nego-cfg", "<burst_inst> <burst_dur> <min_delta> <asap> <ftm_per_burst> <bw> <burst_period>",
8783 test_wlan_11mc_nego_cfg},
8784 {"wlan-loc-cfg", "<lci_req> <latit> <longi> <altit> <lat_uncert> <lon_uncert> <alt_uncert>", test_wlan_loc_cfg},
8785 {"wlan-civ-cfg", "<civ_loc> <civ_loc_type> <country_code> <civ_add_type>", test_wlan_civ_cfg},
8786 {"wlan-11az-rang-cfg", "<protocol> <format_bw> <num_measurements> <measurement_freq> <i2r_sts> <r2i_sts> <i2r_lmr>",
8787 test_wlan_11az_rang_cfg},
8788 #endif
8789 #if CONFIG_WIFI_GET_LOG
8790 {"wlan-get-log", "<sta/uap> <ext>", test_wlan_get_log},
8791 #endif
8792 #if CONFIG_WIFI_TX_PER_TRACK
8793 {"wlan-tx-pert", "<0/1> <STA/UAP> <p> <r> <n>", test_wlan_tx_pert},
8794 #endif
8795 #if CONFIG_ROAMING
8796 {"wlan-roaming", "<0/1> <rssi_threshold>", test_wlan_roaming},
8797 #endif
8798 #if CONFIG_MEF_CFG
8799 {"wlan-multi-mef", "<ping/arp/multicast/del> [<action>]", test_wlan_set_multiple_mef_config},
8800 #endif
8801 #if CONFIG_HOST_SLEEP
8802 #ifdef RW610
8803 #if CONFIG_MEF_CFG
8804 {"wlan-wakeup-condition", "<mef/wowlan wake_up_conds>", test_wlan_wakeup_condition},
8805 #else
8806 {"wlan-wakeup-condition", "<wowlan wake_up_conds>", test_wlan_wakeup_condition},
8807 #endif /*CONFIG_MEF_CFG*/
8808 #if !defined(CONFIG_WIFI_BLE_COEX_APP)
8809 {"wlan-auto-host-sleep", "<enable> <periodic>", test_wlan_auto_host_sleep},
8810 #endif
8811 #else
8812 {"enable-ns-offload", NULL, test_wlan_ns_offload},
8813 {"wlan-auto-arp", NULL, test_wlan_auto_arp},
8814 #if CONFIG_MEF_CFG
8815 {"wlan-add-packet-filter", "0/1 <patterns number> <ptn_len> <pkt_offset> <ptn> ...........",
8816 test_wlan_add_packet_filter},
8817 {"wlan-host-sleep", "<0/1> mef/wowlan <wake_up_conds>", test_wlan_host_sleep},
8818 #else
8819 {"wlan-host-sleep", "<0/1> wowlan <wake_up_conds>", test_wlan_host_sleep},
8820 #endif /*CONFIG_MEF_CFG*/
8821 #endif /*RW610*/
8822 #endif /*CONFIG_HOST_SLEEP*/
8823 {"wlan-send-hostcmd", NULL, test_wlan_send_hostcmd},
8824 #if defined(RW610) || defined(SD9177)
8825 {"wlan-ext-coex-uwb", NULL, test_wlan_ext_coex_uwb},
8826 #endif
8827 #ifdef SD8801
8828 {"wlan-8801-enable-ext-coex", NULL, test_wlan_8801_enable_ext_coex},
8829 {"wlan-8801-get-ext-coex-stats", NULL, test_wlan_8801_ext_coex_stats},
8830 #endif
8831 #if CONFIG_WIFI_EU_CRYPTO
8832 {"wlan-eu-crypto-rc4", "<EncDec>", test_wlan_eu_crypto_rc4},
8833 {"wlan-eu-crypto-aes-wrap", "<EncDec>", test_wlan_eu_crypto_aes_wrap},
8834 {"wlan-eu-crypto-aes-ecb", "<EncDec>", test_wlan_eu_crypto_aes_ecb},
8835 {"wlan-eu-crypto-ccmp-128", "<EncDec>", test_wlan_eu_crypto_ccmp_128},
8836 {"wlan-eu-crypto-ccmp-256", "<EncDec>", test_wlan_eu_crypto_ccmp_256},
8837 {"wlan-eu-crypto-gcmp-128", "<EncDec>", test_wlan_eu_crypto_gcmp_128},
8838 {"wlan-eu-crypto-gcmp-256", "<EncDec>", test_wlan_eu_crypto_gcmp_256},
8839 #endif
8840 #if CONFIG_WIFI_MEM_ACCESS
8841 {"wlan-mem-access", "<memory_address> [<value>]", test_wlan_mem_access},
8842 #endif
8843 #if CONFIG_WIFI_BOOT_SLEEP
8844 {"wlan-boot-sleep", "<0/1> 0:Disable 1:Enable", test_wlan_boot_sleep},
8845 #endif
8846 #if CONFIG_HEAP_STAT
8847 {"heap-stat", NULL, test_heap_stat},
8848 #endif
8849 #if CONFIG_HEAP_DEBUG
8850 {"wlan-os-mem-stat", NULL, test_wlan_os_mem_stat},
8851 #endif
8852 #if CONFIG_MULTI_CHAN
8853 {"wlan-set-mc-policy", "<0/1>(disable/enable)", test_wlan_set_multi_chan_status},
8854 {"wlan-get-mc-policy", NULL, test_wlan_get_multi_chan_status},
8855 {"wlan-set-drcs",
8856 "<channel_time> <switch_time> <undoze_time> <mode> [<channel_time> <switch_time> <undoze_time> <mode>]",
8857 test_wlan_set_drcs_cfg},
8858 {"wlan-get-drcs", NULL, test_wlan_get_drcs_cfg},
8859 #endif
8860 #ifndef STREAM_2X2
8861 #ifndef RW610
8862 {"wlan-set-antcfg", "<ant mode> [evaluate_time]", wlan_antcfg_set},
8863 #else
8864 {"wlan-set-antcfg", "<ant_mode> <evaluate_time> <evaluate_mode>", wlan_antcfg_set},
8865 #endif
8866 {"wlan-get-antcfg", NULL, wlan_antcfg_get},
8867 #endif
8868 #if CONFIG_SCAN_CHANNEL_GAP
8869 {"wlan-scan-channel-gap", "<channel_gap_value>", test_wlan_set_scan_channel_gap},
8870 #endif
8871 #if CONFIG_WMM
8872 {"wlan-wmm-stat", "<bss_type>", test_wlan_wmm_tx_stats},
8873 #endif
8874 #if defined(RW610) && (CONFIG_WIFI_RESET)
8875 {"wlan-reset", NULL, test_wlan_reset},
8876 #endif
8877 #if CONFIG_ECSA
8878 {"wlan-uap-set-ecsa-cfg", "<block_tx> <oper_class> <new_channel> <switch_count> <bandwidth>",
8879 test_wlan_uap_set_ecsa_cfg},
8880 #endif
8881 #if CONFIG_CSI
8882 {"wlan-csi-cfg", NULL, test_wlan_csi_cfg},
8883 {"wlan-set-csi-param-header",
8884 " <sta/uap> <csi_enable> <head_id> <tail_id> <chip_id> <band_config> <channel> <csi_monitor_enable> <ra4us>",
8885 test_wlan_set_csi_param_header},
8886 {"wlan-set-csi-filter", "<opt> <macaddr> <pkt_type> <type> <flag>", test_wlan_set_csi_filter},
8887 #endif
8888 #if CONFIG_TX_RX_HISTOGRAM
8889 {"wlan-txrx-histogram", "<action> <enable>", test_wlan_txrx_histogram},
8890 #endif
8891 #if CONFIG_SUBSCRIBE_EVENT_SUPPORT
8892 {"wlan-subscribe-event", "<action> <type> <value> <freq>", test_wlan_subscribe_event},
8893 #endif
8894 #if CONFIG_WIFI_REG_ACCESS
8895 {"wlan-reg-access", "<type> <offset> [value]", test_wlan_reg_access},
8896 #endif
8897 #if CONFIG_WMM_UAPSD
8898 {"wlan-uapsd-enable", "<uapsd_enable>", test_wlan_set_wmm_uapsd},
8899 {"wlan-uapsd-qosinfo", "<qos_info>", test_wlan_wmm_uapsd_qosinfo},
8900 {"wlan-uapsd-sleep-period", "<sleep_period>", test_wlan_sleep_period},
8901 #endif
8902 #if CONFIG_WIFI_AMPDU_CTRL
8903 {"wlan-ampdu-enable", "<sta/uap> <xx: rx/tx bit map. Tx(bit 0), Rx(bit 1> <xx: TID bit map>",
8904 test_wlan_ampdu_enable},
8905 #endif
8906 #if CONFIG_TX_AMPDU_PROT_MODE
8907 {"wlan-tx-ampdu-prot-mode", "<mode>", test_wlan_tx_ampdu_prot_mode},
8908 #endif
8909 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_11R) || (CONFIG_ROAMING)
8910 {"wlan-rssi-low-threshold", "<threshold_value>", test_wlan_rssi_low_threshold},
8911 #endif
8912 #if CONFIG_RX_ABORT_CFG
8913 {"wlan-rx-abort-cfg", NULL, test_wlan_rx_abort_cfg},
8914 #endif
8915 #if CONFIG_RX_ABORT_CFG_EXT
8916 {"wlan-set-rx-abort-cfg-ext", "enable <enable> margin <margin> ceil <ceil_thresh> floor <floor_thresh>",
8917 test_wlan_set_rx_abort_cfg_ext},
8918 {"wlan-get-rx-abort-cfg-ext", NULL, test_wlan_get_rx_abort_cfg_ext},
8919 #endif
8920 #if CONFIG_CCK_DESENSE_CFG
8921 {"wlan-cck-desense-cfg", NULL, test_wlan_cck_desense_cfg},
8922 #endif
8923 #if CONFIG_NET_MONITOR
8924 {"wlan-net-monitor-cfg", NULL, test_wlan_net_monitor_cfg},
8925 {"wlan-set-monitor-filter", "<opt> <macaddr>", test_wlan_set_monitor_filter},
8926 {"wlan-set-monitor-param", "<action> <monitor_activity> <filter_flags> <radio_type> <chan_number>",
8927 test_wlan_set_monitor_param},
8928 #endif
8929 #if CONFIG_TSP
8930 {"wlan-set-tsp-cfg",
8931 "<enable> <backoff> <highThreshold> <lowThreshold> <dutycycstep> <dutycycmin> <highthrtemp> <lowthrtemp>",
8932 test_wlan_set_tsp_cfg},
8933 {"wlan-get-tsp-cfg", NULL, test_wlan_get_tsp_cfg},
8934 #endif
8935 #if CONFIG_CPU_TASK_STATUS
8936 {"wlan-cpu-task-info", NULL, test_wlan_cpu_task_info},
8937 #endif
8938 #if CONFIG_CPU_LOADING
8939 {"wlan-cpu-loading", "start <start> sample_loops <number> sample_period <period>", test_wlan_cpu_loading},
8940 #endif
8941 #if STA_SUPPORT
8942 {"wlan-get-signal", NULL, test_wlan_get_signal},
8943 #endif
8944 {"wlan-set-bandcfg", NULL, test_wlan_set_bandcfg},
8945 {"wlan-get-bandcfg", NULL, test_wlan_get_bandcfg},
8946 #if (CONFIG_IPS)
8947 {"wlan-set-ips", "<option>", test_wlan_set_ips},
8948 #endif
8949 #if CONFIG_11AX
8950 #if CONFIG_WIFI_HTC_DEBUG
8951 {"wlan-set-debug-htc",
8952 "<count> <vht> <he> <rxNss> <channelWidth> <ulMuDisable> <txNSTS> <erSuDisable> <erSuDisable> <erSuDisable>",
8953 test_wlan_set_debug_htc},
8954 #endif
8955 {"wlan-enable-disable-htc", "<option>", test_wlan_enable_disable_htc},
8956 #endif
8957 #if CONFIG_SET_SU
8958 {"wlan-set-su", "<0/1>", test_wlan_set_su},
8959 #endif
8960 #if CONFIG_WIFI_FORCE_RTS
8961 {"wlan-set-forceRTS", "<0/1>", test_wlan_set_forceRTS},
8962 #endif
8963 #if CONFIG_11AX
8964 #if CONFIG_MMSF
8965 {"wlan-set-mmsf", "<enable> <Density> <MMSF>", test_wlan_set_mmsf},
8966 {"wlan-get-mmsf", NULL, test_wlan_get_mmsf},
8967 #endif
8968 #endif
8969 #if CONFIG_TURBO_MODE
8970 {"wlan-get-turbo-mode", "<STA/UAP>", test_wlan_get_turbo_mode},
8971 {"wlan-set-turbo-mode", "<STA/UAP> <mode>", test_wlan_set_turbo_mode},
8972 #endif
8973 {"wlan-set-multiple-dtim", "<value>", test_wlan_set_multiple_dtim},
8974 #if CONFIG_CLOUD_KEEP_ALIVE
8975 {"wlan-cloud-keep-alive", "<start/stop/reset>", test_wlan_cloud_keep_alive},
8976 {"wlan_tcp_client", "dst_ip <dst_ip> src_port <src_port> dst_port <dst_port>", test_wlan_tcp_client},
8977 #endif
8978 {"wlan-set-country-ie-ignore", "<0/1>", test_wlan_set_country_ie_ignore},
8979 #if CONFIG_COEX_DUTY_CYCLE
8980 {"wlan-single-ant-duty-cycle", "<enable/disable> [<Ieee154Duration> <TotalDuration>]",
8981 test_wlan_single_ant_duty_cycle},
8982 {"wlan-dual-ant-duty-cycle", "<enable/disable> [<Ieee154Duration> <TotalDuration> <Ieee154FarRangeDuration>]",
8983 test_wlan_dual_ant_duty_cycle},
8984 #endif
8985 #if CONFIG_EXTERNAL_COEX_PTA
8986 {"wlan-external-coex-pta",
8987 "enable <PTA/WCI-2/WCI-2 GPIO> ExtWifiBtArb <enable/disable> PolGrantPin <high/low> PriPtaInt <enable/disable> "
8988 "StateFromPta <state pin/ priority pin/ state input disable> SampTiming <Sample timing> InfoSampTiming <Sample "
8989 "timing> "
8990 "TrafficPrio <enable/disable> CoexHwIntWic <enable/disable>",
8991 test_wlan_external_coex_pta},
8992 #endif
8993 #if CONFIG_IMD3_CFG
8994 {"wlan-imd3-cfg", "<enable>", test_wlan_imd3_cfg},
8995 #endif
8996 #if CONFIG_AUTO_RECONNECT
8997 {"wlan-auto-reconnect", "<0/1/2> [<reconnect counter> <reconnect interval> <flags>]", test_wlan_auto_reconnect},
8998 #endif
8999 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
9000 {"wlan-set-indrstcfg", "<mode> <gpio_pin>", test_set_indrst_cfg},
9001 {"wlan-get-indrstcfg", NULL, test_get_indrst_cfg},
9002 {"wlan-independent-reset", "<mode>", test_wlan_independent_reset},
9003 #endif
9004 #if CONFIG_INACTIVITY_TIMEOUT_EXT
9005 {"wlan-sta-inactivityto", "<n> <m> <l> [k] [j]", test_wlan_sta_inactivityto},
9006 #endif
9007 #ifdef RW610
9008 {"wlan-get-temperature", NULL, test_wlan_get_temperature},
9009 #endif
9010 #if CONFIG_AUTO_NULL_TX
9011 {"wlan-auto-null-tx", "<sta/uap> <start/stop>", test_wlan_auto_null_tx},
9012 #endif
9013 #if defined(RW610) && (CONFIG_ANT_DETECT)
9014 {"wlan-detect-ant", "<detect_mode> <ant_port_count> channel <channel> ...", test_wlan_detect_ant},
9015 #endif
9016 #if CONFIG_WIFI_RECOVERY
9017 {"wlan-recovery-test", NULL, test_wlan_recovery_test},
9018 #endif
9019 {"wlan-get-max-clients-count", NULL, test_wlan_get_max_clients_count},
9020 {"wlan-get-ps-cfg", NULL, test_wlan_get_ps_cfg}
9021 };
9022
9023 /* Register our commands with the MTF. */
9024 int wlan_cli_init(void)
9025 {
9026 int i;
9027
9028 i = wlan_basic_cli_init();
9029 if (i != WLAN_ERROR_NONE)
9030 {
9031 return i;
9032 }
9033
9034 if (cli_register_commands(tests, (int)(sizeof(tests) / sizeof(struct cli_command))) != 0)
9035 {
9036 return -WM_FAIL;
9037 }
9038
9039 return WM_SUCCESS;
9040 }
9041
9042 /* Unregister our commands with the MTF. */
9043 int wlan_cli_deinit(void)
9044 {
9045 int i;
9046
9047 if (cli_unregister_commands(tests, (int)(sizeof(tests) / sizeof(struct cli_command))) != 0)
9048 {
9049 return -WM_FAIL;
9050 }
9051
9052 i = wlan_basic_cli_deinit();
9053 if (i != WLAN_ERROR_NONE)
9054 {
9055 return i;
9056 }
9057
9058 return WM_SUCCESS;
9059 }
9060