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