• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Beken Corporation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <string.h>
17 #include <common/sys_config.h>
18 #include "bk_uart.h"
19 #include "param_config.h"
20 #include "bk_private/bk_wifi_wrapper.h"
21 #if CONFIG_LWIP
22 #include "net.h"
23 #endif
24 #include "bk_private/bk_wifi.h"
25 #include "bk_wifi_private.h"
26 #include "bk_cli.h"
27 #include "cli.h"
28 #include <components/event.h>
29 #include <components/netif.h>
30 #include "bk_wifi_wpa.h"
31 #include "bk_wifi_wpa_cmd.h"
32 #include "bk_wifi_frame.h"
33 #include "bk_wifi_types.h"
34 #if CONFIG_WIFI6_CODE_STACK
35 #include "bk_wifi_netif.h"
36 #include "bk_wifi.h"
37 #endif
38 #include "bk_wifi_rw.h"
39 
40 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
41 #include "driver/flash.h"
42 #include <driver/flash_partition.h>
43 #include <lwip/sockets.h>
44 #include "bk_wifi_private.h"
45 #include "boot.h"
46 #endif
47 
48 #define TAG "wifi_cli"
49 #define CMD_WLAN_MAX_BSS_CNT	50
50 
51 #if (CLI_CFG_WIFI == 1)
52 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
53 typedef struct bk_fast_connect_t
54 {
55 	uint8_t flag;		//to check if ssid/pwd saved in easy flash is valid, default 0x70
56 					//bit[0]:write sta deault info;bit[1]:write ap deault info
57 	uint8_t sta_ssid[33];
58 	uint8_t sta_pwd[65];
59 	uint8_t ap_ssid[33];
60 	uint8_t ap_pwd[65];
61 	uint8_t ap_channel;
62 }BK_FAST_CONNECT_T;
63 
wifi_cli_find_id(int argc,char ** argv,char * param)64 int wifi_cli_find_id(int argc, char **argv, char *param)
65 {
66 	int i;
67 	int index;
68 
69 	index = -1;
70 	if (NULL == param)
71 		goto find_over;
72 
73 	for (i = 1; i < argc; i ++) {
74 		if (os_strcmp(argv[i], param) == 0) {
75 			index = i;
76 			break;
77 		}
78 	}
79 
80 find_over:
81 	return index;
82 }
83 
84 static BK_FAST_CONNECT_T info_t;
fast_connect_cb(void * arg,event_module_t event_module,int event_id,void * event_data)85 static int fast_connect_cb(void *arg, event_module_t event_module,
86                 int event_id, void *event_data)
87 {
88 	bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG);
89 	BK_FAST_CONNECT_T info_tmp;
90 
91 	CLI_LOGI("%s, flag:%x\r\n", __func__, info_t.flag);
92 	bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096,
93 						(uint8_t *)&info_tmp, sizeof(BK_FAST_CONNECT_T));
94 
95 	if (info_t.flag == 0x71l) {
96 		if ((info_tmp.flag & 0xf8l) == 0x70l)
97 			info_tmp.flag |= 0x1l;
98 		else
99 			info_tmp.flag = 0x71l;
100 		os_strcpy((char *)info_tmp.sta_ssid, (char *)info_t.sta_ssid);
101 		os_strcpy((char *)info_tmp.sta_pwd, (char *)info_t.sta_pwd);
102 	} else if (info_t.flag == 0x72l) {
103 		if ((info_tmp.flag & 0xf8l) == 0x70l)
104 			info_tmp.flag |= 0x2l;
105 		else
106 			info_tmp.flag = 0x72l;
107 		os_strcpy((char *)info_tmp.ap_ssid, (char *)info_t.ap_ssid);
108 		os_strcpy((char *)info_tmp.ap_pwd, (char *)info_t.ap_pwd);
109 	} else
110 		return -1;
111 
112 	bk_flash_set_protect_type(FLASH_PROTECT_NONE);
113 	bk_flash_erase_sector(pt->partition_start_addr + pt->partition_length -4096);
114 	bk_flash_write_bytes(pt->partition_start_addr + pt->partition_length -4096,
115 						(uint8_t *)&info_tmp, sizeof(BK_FAST_CONNECT_T));
116 	bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK);
117 
118 	return 0;
119 }
120 
121 #if 0
122 static int  demo_tcp_send(void *arg, event_module_t event_module,
123                 int event_id, void *event_data)
124 {
125 	struct sockaddr_in addr;
126 	int flag = 1, sock, ret = -1, len = 40*1024;
127 	struct timeval tv;
128 	uint8_t *send_buf;
129 
130 	send_buf = (uint8_t *) os_malloc(len);
131 	for (int i = 0; i < len; i++)
132 		send_buf[i] = i & 0xff;
133 
134 	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
135 	if (sock < 0) {
136 		CLI_LOGI("create socket failed, err=%d!\n", errno);
137 		return -1;
138 	}
139 	addr.sin_family = PF_INET;
140 	addr.sin_port = htons(5001);
141 	addr.sin_addr.s_addr = inet_addr((char *)"192.168.1.102");
142 
143 	ret = connect(sock, (const struct sockaddr *)&addr, sizeof(addr));
144 	if (ret == -1) {
145 		CLI_LOGI("connect failed, err=%d!\n", errno);
146 		closesocket(sock);
147 		return -1;
148 	}
149 
150 	setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
151 			   (void *)&flag, sizeof(int));
152 
153 	tv.tv_sec = 3;
154 	tv.tv_usec = 0;
155 	setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
156 
157 	tv.tv_sec = 3;
158 	tv.tv_usec = 0;
159 	setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
160 
161 	ret = send(sock, send_buf, len, 0);
162 
163 	closesocket(sock);
164 
165 	return 0;
166 }
167 #endif
168 
demo_wifi_fast_connect(void)169 void demo_wifi_fast_connect(void)
170 {
171 	bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG);
172 	BK_FAST_CONNECT_T info;
173 
174 	bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096,
175 						(uint8_t *)&info, sizeof(BK_FAST_CONNECT_T));
176 	CLI_LOGD("%s, flag:%x\r\n", __func__, info.flag);
177 	if (info.flag == 0x71l) {
178 		demo_sta_app_init((char *)info.sta_ssid, (char *)info.sta_pwd);
179 #if 0
180 		bk_event_register_cb(EVENT_MOD_NETIF, EVENT_NETIF_GOT_IP4,
181 								demo_tcp_send, &info_t);
182 #endif
183 	} else if (info.flag == 0x72l) {
184 		demo_softap_app_init((char *)info.ap_ssid, (char *)info.ap_pwd, NULL);
185 	} else if (info.flag == 0x73l) {
186 		demo_sta_app_init((char *)info.sta_ssid, (char *)info.sta_pwd);
187 		demo_softap_app_init((char *)info.ap_ssid, (char *)info.ap_pwd, NULL);
188 	}
189 }
190 #endif
191 
cli_wifi_scan_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)192 void cli_wifi_scan_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
193 {
194 	if (argc < 2) {
195 		demo_scan_app_init();
196 		return;
197 	} else {
198 		uint8_t *ap_ssid;
199 
200 		ap_ssid = (uint8_t *)argv[1];
201 		demo_scan_adv_app_init(ap_ssid);
202 	}
203 }
204 
cli_wifi_ap_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)205 void cli_wifi_ap_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
206 {
207 	char *ap_ssid = NULL;
208 	char *ap_key = "";
209 	char *ap_channel = NULL;
210 
211 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
212 	if (wifi_cli_find_id(argc, argv, "-w") > 0 ||
213 		wifi_cli_find_id(argc, argv, "-e") > 0) {
214 		if (argc == 3)
215 			ap_ssid = argv[2];
216 		else if (argc == 4) {
217 			ap_ssid = argv[2];
218 			if (os_strlen(argv[3]) <= 2)
219 				ap_channel = argv[3];
220 			else
221 				ap_key = argv[3];
222 		} else if (argc == 5) {
223 			ap_ssid = argv[2];
224 			ap_key = argv[3];
225 			ap_channel = argv[4];
226 		}
227 	} else {
228 #endif
229 		if (argc == 2)
230 			ap_ssid = argv[1];
231 		else if (argc == 3) {
232 			ap_ssid = argv[1];
233 			if (os_strlen(argv[2]) <= 2)
234 				ap_channel = argv[2];
235 			else
236 				ap_key = argv[2];
237 		} else if (argc == 4) {
238 			ap_ssid = argv[1];
239 			ap_key = argv[2];
240 			ap_channel = argv[3];
241 		}
242 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
243 	}
244 #endif
245 
246 	if (ap_ssid) {
247 		demo_softap_app_init(ap_ssid, ap_key, ap_channel);
248 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
249 		bk_event_unregister_cb(EVENT_MOD_WIFI, EVENT_WIFI_STA_CONNECTED,
250 								fast_connect_cb);
251 		if (wifi_cli_find_id(argc, argv, "-w") > 0) {
252 			bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG);
253 
254 			bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096,
255 						(uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T));
256 			if ((info_t.flag & 0xf0l) == 0x70l)
257 				info_t.flag |= 0x2l;
258 			else
259 				info_t.flag = 0x72l;
260 			os_strcpy((char *)info_t.ap_ssid, (char *)ap_ssid);
261 			os_strcpy((char *)info_t.ap_pwd, ap_key);
262 			fast_connect_cb(NULL, 0, 0, NULL);
263 		} else if (wifi_cli_find_id(argc, argv, "-e") > 0) {
264 			bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG);
265 
266 			bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096,
267 						(uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T));
268 			if (info_t.flag == 0x72l || info_t.flag == 0x73l) {
269 				info_t.flag &= ~0x2l;
270 				bk_flash_set_protect_type(FLASH_PROTECT_NONE);
271 				bk_flash_erase_sector(pt->partition_start_addr + pt->partition_length -4096);
272 				bk_flash_write_bytes(pt->partition_start_addr + pt->partition_length -4096,
273 									(uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T));
274 				bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK);
275 			}
276 		}
277 #endif
278 	}
279 }
280 
cli_wifi_stop_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)281 void cli_wifi_stop_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
282 {
283 	if (argc == 2) {
284 		if (os_strcmp(argv[1], "sta") == 0) {
285 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
286 			bk_event_unregister_cb(EVENT_MOD_WIFI, EVENT_WIFI_STA_CONNECTED,
287 									fast_connect_cb);
288 #endif
289 			BK_LOG_ON_ERR(bk_wifi_sta_stop());
290 		} else if (os_strcmp(argv[1], "ap") == 0)
291 			BK_LOG_ON_ERR(bk_wifi_ap_stop());
292 		else
293 			CLI_LOGI("unknown WiFi interface\n");
294 	} else
295 		CLI_LOGI("bad parameters\r\n");
296 }
297 
cli_wifi_iplog_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)298 void cli_wifi_iplog_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
299 {
300 	char *iplog_mode = NULL;
301 
302 	if (argc == 2)
303 		iplog_mode = argv[1];
304 
305 	if (iplog_mode)
306 		demo_wifi_iplog_init(iplog_mode);
307 }
cli_wifi_ipdbg_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)308 void cli_wifi_ipdbg_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
309 {
310 	char *ipdbg_module = NULL;
311 	char *ipdbg_para = NULL;
312 	char *ipdbg_para_value = NULL;
313 
314 	if (argc == 3)
315 	{
316 		ipdbg_module = argv[1];
317 		ipdbg_para = argv[2];
318 		if (ipdbg_module && ipdbg_para)
319 			demo_wifi_ipdbg_init(ipdbg_module, ipdbg_para, ipdbg_para_value);
320 		else
321 			CLI_LOGI("cli_wifi_ipdbg_cmd:invalid argc param\r\n");
322 	}
323 	else if(argc == 4)
324 	{
325 		ipdbg_module = argv[1];
326 		ipdbg_para = argv[2];
327 		ipdbg_para_value = argv[3];
328 		if (ipdbg_module && ipdbg_para && ipdbg_para_value)
329 			demo_wifi_ipdbg_init(ipdbg_module, ipdbg_para, ipdbg_para_value);
330 		else
331 			CLI_LOGI("cli_wifi_ipdbg_cmd:invalid argc param\r\n");
332 	}
333 	else
334 	{
335 		CLI_LOGI("cli_wifi_ipdbg_cmd:invalid argc num\r\n");
336 		return;
337 	}
338 }
339 
340 typedef struct {
341 	uint8_t channel;
342 	uint32_t rx_cnt_mgmt;
343 	uint32_t rx_cnt_data;
344 	uint32_t rx_cnt_ctrl;
345 	uint32_t rx_cnt_0_255;
346 	uint32_t rx_cnt_256_511;
347 	uint32_t rx_cnt_512_1023;
348 	uint32_t rx_cnt_1024;
349 	uint32_t rx_cnt_total;
350 } cli_monitor_result_t;
351 static cli_monitor_result_t *s_monitor_result = NULL;
352 
cli_monitor_cb(const uint8_t * data,uint32_t len,const wifi_frame_info_t * info)353 bk_err_t cli_monitor_cb(const uint8_t *data, uint32_t len, const wifi_frame_info_t *info)
354 {
355 	if (s_monitor_result) {
356 		s_monitor_result->rx_cnt_total++;
357 
358 		if (data) {
359 			if ((data[0] & 0xc) == 0x8)
360 				s_monitor_result->rx_cnt_data ++;
361 			else if ((data[0] & 0xc) == 0x0)
362 				s_monitor_result->rx_cnt_mgmt ++;
363 			else
364 				s_monitor_result->rx_cnt_ctrl ++;
365 		}
366 
367 		if (len < 256)
368 			s_monitor_result->rx_cnt_0_255++;
369 		else if (len < 512)
370 			s_monitor_result->rx_cnt_256_511++;
371 		else if (len < 1024)
372 			s_monitor_result->rx_cnt_512_1023++;
373 		else
374 			s_monitor_result->rx_cnt_1024++;
375 	}
376 
377 	return BK_OK;
378 }
379 
cli_monitor_show(void)380 void cli_monitor_show(void)
381 {
382 	if (s_monitor_result) {
383 		BK_LOG_RAW("total:      %u\n", s_monitor_result->rx_cnt_total);
384 		BK_LOG_RAW("mgmt:       %u\n", s_monitor_result->rx_cnt_mgmt);
385 		BK_LOG_RAW("data:       %u\n", s_monitor_result->rx_cnt_data);
386 		BK_LOG_RAW("ctrl:       %u\n", s_monitor_result->rx_cnt_ctrl);
387 		BK_LOG_RAW("0 - 255:    %u\n", s_monitor_result->rx_cnt_0_255);
388 		BK_LOG_RAW("256 - 511:  %u\n", s_monitor_result->rx_cnt_256_511);
389 		BK_LOG_RAW("512 - 1023: %u\n", s_monitor_result->rx_cnt_512_1023);
390 		BK_LOG_RAW(">=1024:     %u\n", s_monitor_result->rx_cnt_1024);
391 	}
392 }
393 
cli_wifi_set_interval_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)394 void cli_wifi_set_interval_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
395 {
396 	uint8_t interval = 0;
397 	int ret = 0;
398 
399 	if (argc < 2) {
400 		CLI_LOGI("invalid argc num");
401 		return;
402 	}
403 
404 	interval = (uint8_t)os_strtoul(argv[1], NULL, 10);
405 	ret = bk_wifi_send_listen_interval_req(interval);
406 
407 	if (!ret)
408 		CLI_LOGI("set_interval ok");
409 	else
410 		CLI_LOGI("set_interval failed");
411 }
412 
cli_monitor_stop(void)413 void cli_monitor_stop(void)
414 {
415 	if (s_monitor_result) {
416 		os_free(s_monitor_result);
417 		s_monitor_result = NULL;
418 	}
419 
420 	BK_LOG_ON_ERR(bk_wifi_monitor_stop());
421 }
422 
cli_monitor_start(uint32_t primary_channel)423 void cli_monitor_start(uint32_t primary_channel)
424 {
425 	wifi_channel_t chan = {0};
426 
427 	chan.primary = primary_channel;
428 
429 	if (!s_monitor_result) {
430 		s_monitor_result = os_zalloc(sizeof(cli_monitor_result_t));
431 		if (!s_monitor_result)
432 			CLI_LOGI("failed to alloc monitor result\n");
433 	}
434 
435 	BK_LOG_ON_ERR(bk_wifi_monitor_register_cb(cli_monitor_cb));
436 	BK_LOG_ON_ERR(bk_wifi_monitor_start());
437 	BK_LOG_ON_ERR(bk_wifi_monitor_set_channel(&chan));
438 }
439 
cli_wifi_monitor_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)440 void cli_wifi_monitor_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
441 {
442 	uint32_t primary_channel;
443 
444 	if (argc != 2) {
445 		CLI_LOGI("monitor_parameter invalid\r\n");
446 		return;
447 	}
448 
449 	primary_channel = os_strtoul(argv[1], NULL, 10);
450 	if (99 == primary_channel)
451 		cli_monitor_stop();
452 	else if ((primary_channel > 0) && (primary_channel < 15))
453 		cli_monitor_start(primary_channel);
454 	else
455 		cli_monitor_show();
456 }
457 
458 #include "conv_utf8_pub.h"
cli_wifi_sta_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)459 void cli_wifi_sta_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
460 {
461 	char *ssid = NULL;
462 	char *password = "";
463 
464 	if ((argc < 2) || (argc > 6)) {
465 		CLI_LOGI("invalid argc number\n");
466 		return;
467 	}
468 
469 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
470 	if (wifi_cli_find_id(argc, argv, "-w") > 0 ||
471 		wifi_cli_find_id(argc, argv, "-e") > 0) {
472 		if (argc >= 2)
473 			ssid = argv[2];
474 
475 		if (argc >= 3)
476 			password = argv[3];
477 	} else {
478 #endif
479 		if (argc >= 2)
480 			ssid = argv[1];
481 
482 		if (argc >= 3)
483 			password = argv[2];
484 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
485 	}
486 #endif
487 
488 #if 0 //TODO support BSSID/Channel configuration
489 	if (argc >= 4)
490 		bssid = argv[3];
491 
492 	if (argc >= 5)
493 		channel = argv[4];
494 #endif
495 
496 	char *oob_ssid_tp = ssid;
497 #if CONFIG_USE_CONV_UTF8
498 	oob_ssid_tp = (char *)conv_utf8((uint8_t *)ssid);
499 #endif
500 
501 	if (oob_ssid_tp) {
502 		demo_sta_app_init((char *)oob_ssid_tp, password);
503 #if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT
504 		if (wifi_cli_find_id(argc, argv, "-w") > 0) {
505 			bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG);
506 			bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096,
507 						(uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T));
508 			if ((info_t.flag & 0xf0l) == 0x70l)
509 				info_t.flag |= 0x1l;
510 			else
511 				info_t.flag = 0x71l;
512 			os_strcpy((char *)info_t.sta_ssid, (char *)oob_ssid_tp);
513 			os_strcpy((char *)info_t.sta_pwd, password);
514 			bk_event_register_cb(EVENT_MOD_WIFI, EVENT_WIFI_STA_CONNECTED,
515 									fast_connect_cb, &info_t);
516 		} else if (wifi_cli_find_id(argc, argv, "-e") > 0) {
517 			bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG);
518 
519 			bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096,
520 						(uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T));
521 			if (info_t.flag == 0x71l || info_t.flag == 0x73l) {
522 				info_t.flag &= ~0x1l;
523 				bk_flash_set_protect_type(FLASH_PROTECT_NONE);
524 				bk_flash_write_bytes(pt->partition_start_addr + pt->partition_length -4096,
525 									(uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T));
526 				bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK);
527 			}
528 		}
529 #endif
530 #if CONFIG_USE_CONV_UTF8
531 		os_free(oob_ssid_tp);
532 #endif
533 	} else {
534 		CLI_LOGI("not buf for utf8\r\n");
535 	}
536 }
537 
538 #if CONFIG_COMPONENTS_WPA2_ENTERPRISE
539 /**
540  * cli command: sta_eap <ssid>, connect to EAP-TLS AP.
541  *
542  * restrictions: EAP-TLS is based on PKI, both AP and STA may have certificate. So
543  * we must install certificate and private key to system. For example, `beken-iot-1.pem'
544  * is STA's certificate, `beken-iot-1.key' is private key, `rootca.pem' is the RootCA.
545  * These certificates and private key may be registered to system via `register_xfile'
546  * function.
547  */
cli_wifi_sta_eap_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)548 void cli_wifi_sta_eap_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
549 {
550 	char *ssid = NULL;
551 	char *ca = argv[3];
552 	char *client_cert = argv[5];
553 	char *private_key = argv[6];
554 	char *private_key_passwd = argv[2];
555 	char *identity = argv[4];
556 
557 	if ((argc < 2) || (argc > 7)) {
558 		CLI_LOGI("invalid argc number\n");
559 		return;
560 	}
561 
562 	ssid = argv[1];
563 
564 	char *oob_ssid_tp = ssid;
565 #if CONFIG_USE_CONV_UTF8
566 	oob_ssid_tp = (char *)conv_utf8((uint8_t *)ssid);
567 #endif
568 
569 	if (oob_ssid_tp) {
570 		int len;
571 		wifi_sta_config_t *sta_config;
572 
573 		len = os_strlen((char *)oob_ssid_tp);
574 		if (WLAN_SSID_MAX_LEN < len) {
575 			CLI_LOGI("ssid name more than 32 Bytes\n");
576 			return;
577 		}
578 
579 		sta_config = os_zalloc(sizeof(*sta_config));
580 		if (!sta_config) {
581 			CLI_LOGI("Cannot alloc STA config\n");
582 			return;
583 		}
584 
585 		os_strlcpy(sta_config->ssid, oob_ssid_tp, sizeof(sta_config->ssid));
586 		sta_config->password[0] = '\0';	// No passwd needed fo EAP.
587 		os_strlcpy(sta_config->eap, "TLS", sizeof(sta_config->eap));
588 		os_strlcpy(sta_config->identity, identity, sizeof(sta_config->identity));
589 		os_strlcpy(sta_config->ca, ca, sizeof(sta_config->ca));
590 		os_strlcpy(sta_config->client_cert, client_cert, sizeof(sta_config->client_cert));
591 		os_strlcpy(sta_config->private_key, private_key, sizeof(sta_config->private_key));
592 		os_strlcpy(sta_config->private_key_passwd, private_key_passwd, sizeof(sta_config->private_key_passwd));
593 		os_strlcpy(sta_config->phase1, "tls_disable_time_checks=1", sizeof(sta_config->phase1));
594 
595 		CLI_LOGI("ssid:%s key:%s\n", sta_config->ssid, sta_config->password);
596 		CLI_LOGI("eap:%s identity:%s\n", sta_config->eap, sta_config->identity);
597 		CLI_LOGI("ca:%s client_cert:%s\n", sta_config->ca, sta_config->client_cert);
598 		CLI_LOGI("private_key:%s\n", sta_config->private_key);
599 		BK_LOG_ON_ERR(bk_wifi_sta_set_config(sta_config));
600 		BK_LOG_ON_ERR(bk_wifi_sta_start());
601 
602 		os_free(sta_config);
603 
604 #if CONFIG_USE_CONV_UTF8
605 		os_free(oob_ssid_tp);
606 #endif
607 	} else {
608 		CLI_LOGI("not buf for utf8\r\n");
609 	}
610 }
611 #endif
612 
cli_wifi_state_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)613 void cli_wifi_state_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
614 {
615 	demo_state_app_init();
616 }
617 
618 #if CONFIG_WIFI_SENSOR
cli_wifi_sensor_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)619 static void cli_wifi_sensor_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
620 {
621 	int status;
622 
623 	if (argc != 2)
624 		bk_printf("param error");
625 
626 
627 	if (os_strcmp(argv[1], "start") == 0)
628 		bk_wifi_detect_movement_start();
629 
630 	if (os_strcmp(argv[1], "stop") == 0)
631 		bk_wifi_detect_movement_stop();
632 
633 	if (os_strcmp(argv[1], "status") == 0) {
634 		status = bk_get_movement_status();
635 
636 		if (status == 0)
637 			bk_printf("detect something");
638 		else
639 			bk_printf("detect nothing");
640 	}
641 }
642 #endif
643 
644 #if CONFIG_COMPONENTS_WFA_CA
645 extern void wfa_ca_start();
646 extern void wfa_ca_stop();
647 
cli_wifi_wfa_ca_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)648 void cli_wifi_wfa_ca_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
649 {
650 	if (argc != 2) {
651 		os_printf("param error");
652 		return;
653 	}
654 
655 	if (os_strcmp(argv[1], "start") == 0)
656 		wfa_ca_start();
657 	else if (os_strcmp(argv[1], "stop") == 0)
658 		wfa_ca_stop();
659 }
660 #endif
661 
662 typedef struct {
663 	uint16_t cnt_probe_req;
664 	uint16_t cnt_probe_rsp;
665 	uint16_t cnt_beacon;
666 	uint16_t cnt_action;
667 	uint16_t cnt_auth;
668 	uint16_t cnt_assoc_req;
669 	uint16_t cnt_assoc_rsp;
670 	uint16_t cnt_others;
671 	uint16_t cnt_total;
672 } wifi_filter_result_t;
673 
674 static wifi_filter_result_t *s_filter_result = NULL;
675 
wifi_filter_cb(const uint8_t * data,uint32_t len,const wifi_frame_info_t * frame_info)676 static int wifi_filter_cb(const uint8_t *data, uint32_t len, const wifi_frame_info_t *frame_info)
677 {
678 	if (!data) {
679 		CLI_LOGE("null data\n");
680 		return BK_OK;
681 	}
682 
683 	if (!s_filter_result)
684 		return BK_OK;
685 
686 	uint16_t framectrl = *(uint16_t*)(data);
687 	uint16_t type_subtype = framectrl & MAC_FCTRL_TYPESUBTYPE_MASK;
688 
689 	if (type_subtype == MAC_FCTRL_BEACON)
690 		s_filter_result->cnt_beacon ++;
691 	else if (type_subtype == MAC_FCTRL_PROBEREQ)
692 		s_filter_result->cnt_probe_req++;
693 	else if (type_subtype == MAC_FCTRL_PROBERSP)
694 		s_filter_result->cnt_probe_rsp++;
695 	else if (type_subtype == MAC_FCTRL_ACTION)
696 		s_filter_result->cnt_action++;
697 	else if (type_subtype == MAC_FCTRL_AUTHENT)
698 		s_filter_result->cnt_auth++;
699 	else if (type_subtype == MAC_FCTRL_ASSOCREQ)
700 		s_filter_result->cnt_assoc_req++;
701 	else if (type_subtype == MAC_FCTRL_ASSOCRSP)
702 		s_filter_result->cnt_assoc_rsp++;
703 	else
704 		s_filter_result->cnt_others++;
705 
706 	s_filter_result->cnt_total++;
707 	return BK_OK;
708 }
709 
wifi_filter_result_dump(void)710 static void wifi_filter_result_dump(void)
711 {
712 	if (!s_filter_result)
713 		return;
714 
715 	bk_printf("filter result:\n");
716 	bk_printf("total: %u\n", s_filter_result->cnt_total);
717 	bk_printf("beacon: %u\n", s_filter_result->cnt_beacon);
718 	bk_printf("probe req: %u\n", s_filter_result->cnt_probe_req);
719 	bk_printf("probe rsp: %u\n", s_filter_result->cnt_probe_rsp);
720 	bk_printf("auth: %u\n", s_filter_result->cnt_auth);
721 	bk_printf("assoc req: %u\n", s_filter_result->cnt_assoc_req);
722 	bk_printf("assoc rsp: %u\n", s_filter_result->cnt_assoc_rsp);
723 	bk_printf("action: %u\n", s_filter_result->cnt_action);
724 	bk_printf("others: %u\n", s_filter_result->cnt_others);
725 }
726 
wifi_mgmt_filter_help(void)727 static void wifi_mgmt_filter_help(void)
728 {
729 	bk_printf("filter {filter_bitmap}\n");
730 	bk_printf("    bit0 - default management\n");
731 	bk_printf("    bit1 - probe req\n");
732 	bk_printf("    bit2 - probe rsp\n");
733 	bk_printf("    bit3 - all beacon\n");
734 	bk_printf("    bit4 - action\n");
735 	bk_printf("       0 - stop filter\n");
736 	bk_printf("      -1 - display result\n");
737 }
738 
cli_wifi_filter_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)739 static void cli_wifi_filter_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
740 {
741 	wifi_filter_config_t filter_config = {0};
742 	uint32_t filter = 0;
743 
744 	if (argc != 2) {
745 		wifi_mgmt_filter_help();
746 		return;
747 	}
748 
749 	filter = os_strtoul(argv[1], NULL, 0);
750 
751 	if (filter == 0) {
752 		if (s_filter_result) {
753 			os_free(s_filter_result);
754 			s_filter_result = NULL;
755 		}
756 		BK_LOG_ON_ERR(bk_wifi_filter_set_config(&filter_config));
757 		BK_LOG_ON_ERR(bk_wifi_filter_register_cb(NULL));
758 		return;
759 	} else if (filter == -1) {
760 		wifi_filter_result_dump();
761 		return;
762 	}
763 
764 	if (!s_filter_result) {
765 		s_filter_result = (wifi_filter_result_t *)os_zalloc(sizeof(wifi_filter_result_t));
766 		if (!s_filter_result)
767 			return;
768 	}
769 
770 	if (filter & (1 << 0))
771 		filter_config.rx_all_default_mgmt = 1;
772 
773 	if (filter & (1 << 1))
774 		filter_config.rx_probe_req = 1;
775 
776 	if (filter & (1 << 2))
777 		filter_config.rx_probe_rsp = 1;
778 
779 	if (filter & (1 << 3))
780 		filter_config.rx_all_beacon = 1;
781 
782 	if (filter & (1 << 4))
783 		filter_config.rx_action = 1;
784 
785 	BK_LOG_ON_ERR(bk_wifi_filter_set_config(&filter_config));
786 	BK_LOG_ON_ERR(bk_wifi_filter_register_cb(wifi_filter_cb));
787 }
788 
789 #if CONFIG_WIFI_RAW_TX_TEST
790 
791 typedef struct {
792 	uint32_t interval;
793 	uint32_t counter;
794 } wifi_raw_tx_param_t;
795 
wifi_raw_tx_thread(void * arg)796 static void wifi_raw_tx_thread(void *arg)
797 {
798 	char frame[] = {
799 		0xB0, //version, type, subtype
800 		0x00, //frame control
801 		0x3A, 0x01, //duration
802 		0xC8, 0x47, 0x8C, 0x42, 0x00, 0x48, //Address1 - destination
803 		0x4C, 0xD1, 0xA1, 0xC5, 0x38, 0xE4, //Address2 - source
804 		0x4C, 0xD1, 0xA1, 0xC5, 0x38, 0xE4, //Address3 - bssid
805 		0x20, 0xC0, //sequence
806 
807 		//Auth Response
808 		0x00, 0x00, //Auth algorithm - open system
809 		0x02, 0x00, //Auth seq num
810 		0x00, 0x00, //Status code
811 	};
812 	wifi_raw_tx_param_t *tx_param;
813 	int ret;
814 
815 	tx_param = (wifi_raw_tx_param_t *)arg;
816 	CLI_LOGI("wifi raw tx begin, interval=%u counter=%d\n", tx_param->interval,
817 			 tx_param->counter);
818 
819 	for (uint32_t i = 0; i < tx_param->counter; i++) {
820 		ret = bk_wlan_send_80211_raw_frame((unsigned char *)frame, sizeof(frame));
821 		if (ret != kNoErr)
822 			CLI_LOGI("raw tx error, ret=%d\n", ret);
823 
824 		rtos_delay_milliseconds(tx_param->interval);
825 	}
826 
827 	os_free(arg);
828 	CLI_LOGI("wifi raw tx end\n");
829 	rtos_delete_thread(NULL);
830 }
831 
cli_wifi_raw_tx_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)832 static void cli_wifi_raw_tx_cmd(char *pcWriteBuffer, int xWriteBufferLen,
833 								int argc, char **argv)
834 {
835 	bk_err_t ret;
836 
837 	if (argc != 3) {
838 		CLI_LOGE("param error");
839 		CLI_LOGI("usage: wifi_raw_tx interval counter");
840 		return;
841 	}
842 
843 	wifi_raw_tx_param_t *tx_param;
844 	tx_param = (wifi_raw_tx_param_t *)os_malloc(sizeof(wifi_raw_tx_param_t));
845 	if (!tx_param) {
846 		CLI_LOGE("out of memory\n");
847 		return;
848 	}
849 
850 	tx_param->interval = os_strtoul(argv[1], NULL, 10);
851 	tx_param->counter = os_strtoul(argv[2], NULL, 10);
852 	ret = rtos_create_thread(NULL, 2, "raw_tx",
853 		(beken_thread_function_t)wifi_raw_tx_thread,
854 		2048, tx_param);
855 	if (kNoErr != ret) {
856 		os_free(tx_param);
857 		CLI_LOGI("Create raw tx thread failed, ret=%d\r\n", ret);
858 		return;
859 	}
860 }
861 #endif
862 
cli_wifi_monitor_channel_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)863 static void cli_wifi_monitor_channel_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
864 {
865 	wifi_channel_t chan = {0};
866 	int channel, i = 0;
867 
868 	if (argc == 1) {
869 		CLI_LOGI("Usage: channel [1~13].");
870 		return;
871 	}
872 
873 	while (argv[1][i]) {
874 		if ((argv[1][i] < '0') || (argv[1][i] > '9')) {
875 			CLI_LOGE("parameter should be a number\r\n");
876 			return ;
877 		}
878 		i++;
879 	}
880 
881 	channel = atoi(argv[1]);
882 
883 	if ((channel < 1) || (channel > 13)) {
884 		CLI_LOGE("Invalid channel number \r\n");
885 		return ;
886 	}
887 	BK_LOG_RAW("monitor mode, set to channel %d\r\n", channel);
888 	chan.primary = channel;
889 	BK_LOG_ON_ERR(bk_wifi_monitor_set_channel(&chan));
890 }
891 
cli_netif_event_cb(void * arg,event_module_t event_module,int event_id,void * event_data)892 int cli_netif_event_cb(void *arg, event_module_t event_module,
893 					   int event_id, void *event_data)
894 {
895 	netif_event_got_ip4_t *got_ip;
896 
897 	switch (event_id) {
898 	case EVENT_NETIF_GOT_IP4:
899 		got_ip = (netif_event_got_ip4_t *)event_data;
900 		CLI_LOGI("%s got ip\n", got_ip->netif_if == NETIF_IF_STA ? "BK STA" : "unknown netif");
901 #if CONFIG_WIFI6_CODE_STACK
902 		unsigned char vif_idx = wifi_netif_mac_to_vifid((uint8_t*)&g_sta_param_ptr->own_mac);
903               wlan_dhcp_done_ind(vif_idx);
904 #endif
905 		break;
906 	default:
907 		CLI_LOGI("rx event <%d %d>\n", event_module, event_id);
908 		break;
909 	}
910 
911 	return BK_OK;
912 }
913 
cli_wifi_event_cb(void * arg,event_module_t event_module,int event_id,void * event_data)914 int cli_wifi_event_cb(void *arg, event_module_t event_module,
915 					  int event_id, void *event_data)
916 {
917 	wifi_event_sta_disconnected_t *sta_disconnected;
918 	wifi_event_sta_connected_t *sta_connected;
919 	wifi_event_ap_disconnected_t *ap_disconnected;
920 	wifi_event_ap_connected_t *ap_connected;
921 
922 	switch (event_id) {
923 	case EVENT_WIFI_STA_CONNECTED:
924 		sta_connected = (wifi_event_sta_connected_t *)event_data;
925 		CLI_LOGI("BK STA connected %s\n", sta_connected->ssid);
926 		break;
927 
928 	case EVENT_WIFI_STA_DISCONNECTED:
929 		sta_disconnected = (wifi_event_sta_disconnected_t *)event_data;
930 		CLI_LOGI("BK STA disconnected, reason(%d)%s\n", sta_disconnected->disconnect_reason,
931 			sta_disconnected->local_generated ? ", local_generated" : "");
932 		break;
933 
934 	case EVENT_WIFI_AP_CONNECTED:
935 		ap_connected = (wifi_event_ap_connected_t *)event_data;
936 		CLI_LOGI(BK_MAC_FORMAT" connected to BK AP\n", BK_MAC_STR(ap_connected->mac));
937 		break;
938 
939 	case EVENT_WIFI_AP_DISCONNECTED:
940 		ap_disconnected = (wifi_event_ap_disconnected_t *)event_data;
941 		CLI_LOGI(BK_MAC_FORMAT" disconnected from BK AP\n", BK_MAC_STR(ap_disconnected->mac));
942 		break;
943 
944 	default:
945 		CLI_LOGI("rx event <%d %d>\n", event_module, event_id);
946 		break;
947 	}
948 
949 	return BK_OK;
950 }
951 
cli_wifi_net_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)952 void cli_wifi_net_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
953 {
954 	char buf[128];
955 	int i, left = sizeof(buf) - 1, len = 0;
956 
957 	// net sta xxx
958 	// net ap xxx
959 	if (argc <= 2) {
960 		CLI_LOGI("Usage: net sta/ap <param...>\n");
961 		return;
962 	}
963 
964 	buf[0] = 0;
965 	for (i = 2; i < argc; i++) {
966 		len = os_strlen(buf);
967 		snprintf(buf + len, left - len, "%s ", argv[i]);
968 	}
969 	buf[strlen(buf) - 1] = 0;
970 	//CLI_LOGI("CMD: |%s|\n", buf);
971 
972 #if 1
973 	if (os_strcmp(argv[1], "sta") == 0)
974 		cmd_wlan_sta_exec(buf);
975 	else if (os_strcmp(argv[1], "ap") == 0)
976 		cmd_wlan_ap_exec(buf);
977 #if CONFIG_COMPONENTS_P2P
978 	else if (os_strcmp(argv[1], "p2p") == 0)
979 		cmd_wlan_p2p_exec(buf);
980 #endif
981 	else {
982 		CLI_LOGI("Usage: net sta/ap <param...>\n");
983 		return;
984 	}
985 #endif
986 }
987 
cli_wifi_get_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)988 void cli_wifi_get_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) {
989 	// get pm status
990 	// get xx status
991 	if (argc <= 2) {
992 		CLI_LOGI("Usage get xx status\n");
993 		return;
994 	}
995 
996 	if(os_strcmp(argv[1], "ps") == 0) {
997 		int state = 0;
998 		if(os_strcmp(argv[2], "status") == 0) {
999 			state = cmd_wlan_get_ps_status();
1000 			CLI_LOGI("ps status: %s \n", (state?"sleep":"active"));
1001 		} else {
1002 			CLI_LOGI("Usage get ps status\n");
1003 		}
1004 	}
1005 	else if (os_strcmp(argv[1], "mac_trx") == 0) {
1006 
1007 		bool reset_status = false;
1008 
1009 		if ((argc == 4) && (os_strcmp(argv[3], "-r") == 0))
1010 		{
1011 			reset_status = true;
1012 		}
1013 
1014 		if(os_strcmp(argv[2], "status") == 0) {
1015 			bk_wifi_get_mac_trx_status(reset_status);
1016 		} else {
1017 			CLI_LOGI("Usage get MAC TRX status\n");
1018 		}
1019 	}
1020 }
cli_wifi_rc_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)1021 void cli_wifi_rc_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) {
1022 
1023 	uint8_t sta_idx = 0;
1024 	uint16_t rate_cfg = 0;
1025 
1026 	if (argc <= 2) {
1027 		CLI_LOGI("invalid RC command\n");
1028 		return;
1029 	}
1030 
1031 	if(os_strcmp(argv[1], "set_fixrate") == 0) {
1032 		sta_idx = os_strtoul(argv[2], NULL, 10) & 0xFFFF;
1033 		rate_cfg = os_strtoul(argv[3], NULL, 10) & 0xFFFF;
1034 		bk_wifi_rc_config(sta_idx, rate_cfg);
1035 	}
1036 	else {
1037 		CLI_LOGI("invalid RC paramter\n");
1038 	}
1039 }
cli_wifi_capa_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)1040 void cli_wifi_capa_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) {
1041 	uint32_t capa_id = 0;
1042 	uint32_t capa_val = 0;
1043 
1044 	if (argc <= 2) {
1045 		CLI_LOGI("invalid CAPA command\n");
1046 		return;
1047 	}
1048 
1049 	if(os_strcmp(argv[1], "ht") == 0) {
1050 		capa_id = WIFI_CAPA_ID_HT_EN;
1051 	}
1052 	else if(os_strcmp(argv[1], "vht") == 0) {
1053 		capa_id = WIFI_CAPA_ID_VHT_EN;
1054 	}
1055 	else if(os_strcmp(argv[1], "he") == 0) {
1056 		capa_id = WIFI_CAPA_ID_HE_EN;
1057 	}
1058 	else if(os_strcmp(argv[1], "tx_ampdu") == 0) {
1059 		capa_id = WIFI_CAPA_ID_TX_AMPDU_EN;
1060 	}
1061 	else if(os_strcmp(argv[1], "rx_ampdu") == 0) {
1062 		capa_id = WIFI_CAPA_ID_RX_AMPDU_EN;
1063 	}
1064 	else if(os_strcmp(argv[1], "he_mcs") == 0) {
1065 		capa_id = WIFI_CAPA_ID_HE_MCS;
1066 	}
1067 	else {
1068 		CLI_LOGI("invalid CAPA paramter\n");
1069 		return;
1070 	}
1071 
1072 	capa_val = os_strtoul(argv[2], NULL, 10) & 0xFFFF;
1073 	bk_wifi_capa_config(capa_id, capa_val);
1074 }
1075 
1076 #ifdef CONFIG_COMPONENTS_WPA_TWT_TEST
cli_wifi_twt_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)1077 void cli_wifi_twt_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
1078 {
1079 	uint16_t mantissa = 0;
1080 	uint8_t min_twt = 0;
1081 
1082 	if(os_strcmp(argv[1], "setup") == 0) {
1083 		int setup_command = 0;
1084 
1085 		if(os_strcmp(argv[2], "suggest") == 0) {
1086 			setup_command = 1;
1087 		}
1088 		else if(os_strcmp(argv[2], "demand") == 0) {
1089 			setup_command = 2;
1090 		}
1091 		else {
1092 			CLI_LOGI("Usage: twt setup suggest/demand <param...>\n");
1093 			return;
1094 		}
1095 		mantissa = os_strtoul(argv[3], NULL, 10) & 0xFF;
1096 		min_twt = os_strtoul(argv[4], NULL, 10) & 0xFF;
1097 		bk_wifi_twt_setup(setup_command, mantissa, min_twt);
1098 	}
1099 	else if (os_strcmp(argv[1], "teardown") == 0)
1100 		bk_wifi_twt_teardown();
1101 	else
1102 		CLI_LOGI("Usage: twt setup/teardown \n");
1103 }
1104 #endif
1105 
1106 #define WIFI_CMD_CNT (sizeof(s_wifi_commands) / sizeof(struct cli_command))
1107 static const struct cli_command s_wifi_commands[] = {
1108 	{"scan", "scan [ssid]", cli_wifi_scan_cmd},
1109 	{"ap", "ap ssid [password] [channel[1:14]]", cli_wifi_ap_cmd},
1110 	{"sta", "sta ssid [password][bssid][channel]", cli_wifi_sta_cmd}, //TODO support connect speicific BSSID
1111 #if CONFIG_COMPONENTS_WPA2_ENTERPRISE
1112 	{"sta_eap", "sta_eap ssid password [ca] [identity] [client_cert] [private_key]", cli_wifi_sta_eap_cmd},
1113 #endif
1114 	{"stop", "stop {sta|ap}", cli_wifi_stop_cmd},
1115 	{"set_interval", "set listen interval}", cli_wifi_set_interval_cmd},
1116 	{"monitor", "monitor {1~13|15|99}", cli_wifi_monitor_cmd},
1117 	{"state", "state - show STA/AP state", cli_wifi_state_cmd},
1118 	{"channel", "channel {1~13} - set monitor channel", cli_wifi_monitor_channel_cmd},
1119 	{"net", "net {sta/ap} ... - wifi net config", cli_wifi_net_cmd},
1120 	{"get", "get wifi status", cli_wifi_get_cmd},
1121 	{"iplog", "iplog [modle]", cli_wifi_iplog_cmd},
1122 	{"ipdbg", "ipdbg [module][para][value]", cli_wifi_ipdbg_cmd},
1123 
1124 #ifdef CONFIG_COMPONENTS_WPA_TWT_TEST
1125 	{"twt", "twt {setup|teardown}", cli_wifi_twt_cmd},
1126 #endif
1127 
1128 #if CONFIG_COMPONENTS_WFA_CA
1129 	{"wfa_ca", "wfa_ca <start|stop>", cli_wifi_wfa_ca_cmd},
1130 #endif
1131 
1132 #if CONFIG_WIFI_SENSOR
1133 	{"wifisensor", "wifi sensor", cli_wifi_sensor_cmd},
1134 #endif
1135 	{"filter", "filter <bits> - bit0/d, 1/preq, 2/prsp, 3/b, 4/a", cli_wifi_filter_cmd},
1136 #if CONFIG_WIFI_RAW_TX_TEST
1137 	{"wifi_tx", "wifi_tx - Tx WiFi raw frame", cli_wifi_raw_tx_cmd},
1138 #endif
1139 	{"rc", "wifi rate control config", cli_wifi_rc_cmd},
1140 	{"capa", "wifi capability config", cli_wifi_capa_cmd},
1141 };
1142 
cli_wifi_init(void)1143 int cli_wifi_init(void)
1144 {
1145 	BK_LOG_ON_ERR(bk_event_register_cb(EVENT_MOD_WIFI, EVENT_ID_ALL, cli_wifi_event_cb, NULL));
1146 	BK_LOG_ON_ERR(bk_event_register_cb(EVENT_MOD_NETIF, EVENT_ID_ALL, cli_netif_event_cb, NULL));
1147 	return cli_register_commands(s_wifi_commands, WIFI_CMD_CNT);
1148 }
1149 
1150 #endif //#if (CLI_CFG_WIFI == 1)
1151