1 /*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2018-08-13 tyx the first version
9 * 2024-03-24 Evlers fixed a duplicate issue with the wifi scan command
10 */
11
12 #include <rtthread.h>
13 #include <rthw.h>
14 #include <dev_wlan_mgnt.h>
15 #include <dev_wlan_cfg.h>
16 #include <dev_wlan_prot.h>
17
18 #define DBG_TAG "WLAN.cmd"
19 #ifdef RT_WLAN_MGNT_DEBUG
20 #define DBG_LVL DBG_LOG
21 #else
22 #define DBG_LVL DBG_INFO
23 #endif /* RT_WLAN_MGNT_DEBUG */
24 #include <rtdbg.h>
25
26 static struct rt_wlan_scan_result scan_result;
27 static struct rt_wlan_info *scan_filter = RT_NULL;
28
29 #if defined(RT_WLAN_MANAGE_ENABLE) && defined(RT_WLAN_MSH_CMD_ENABLE)
30
31 struct wifi_cmd_des
32 {
33 const char *cmd;
34 int (*fun)(int argc, char *argv[]);
35 };
36
37 static int wifi_help(int argc, char *argv[]);
38 static int wifi_scan(int argc, char *argv[]);
39 static int wifi_status(int argc, char *argv[]);
40 static int wifi_join(int argc, char *argv[]);
41 static int wifi_ap(int argc, char *argv[]);
42 static int wifi_list_sta(int argc, char *argv[]);
43 static int wifi_disconnect(int argc, char *argv[]);
44 static int wifi_ap_stop(int argc, char *argv[]);
45
46 #ifdef RT_WLAN_CMD_DEBUG
47 /* just for debug */
48 static int wifi_debug(int argc, char *argv[]);
49 static int wifi_debug_save_cfg(int argc, char *argv[]);
50 static int wifi_debug_dump_cfg(int argc, char *argv[]);
51 static int wifi_debug_clear_cfg(int argc, char *argv[]);
52 static int wifi_debug_dump_prot(int argc, char *argv[]);
53 static int wifi_debug_set_mode(int argc, char *argv[]);
54 static int wifi_debug_set_prot(int argc, char *argv[]);
55 static int wifi_debug_set_autoconnect(int argc, char *argv[]);
56 #endif
57
58 /* cmd table */
59 static const struct wifi_cmd_des cmd_tab[] =
60 {
61 {"scan", wifi_scan},
62 {"help", wifi_help},
63 {"status", wifi_status},
64 {"join", wifi_join},
65 {"ap", wifi_ap},
66 {"list_sta", wifi_list_sta},
67 {"disc", wifi_disconnect},
68 {"ap_stop", wifi_ap_stop},
69 {"smartconfig", RT_NULL},
70 #ifdef RT_WLAN_CMD_DEBUG
71 {"-d", wifi_debug},
72 #endif
73 };
74
75 #ifdef RT_WLAN_CMD_DEBUG
76 /* debug cmd table */
77 static const struct wifi_cmd_des debug_tab[] =
78 {
79 {"save_cfg", wifi_debug_save_cfg},
80 {"dump_cfg", wifi_debug_dump_cfg},
81 {"clear_cfg", wifi_debug_clear_cfg},
82 {"dump_prot", wifi_debug_dump_prot},
83 {"mode", wifi_debug_set_mode},
84 {"prot", wifi_debug_set_prot},
85 {"auto", wifi_debug_set_autoconnect},
86 };
87 #endif
88
wifi_help(int argc,char * argv[])89 static int wifi_help(int argc, char *argv[])
90 {
91 rt_kprintf("wifi\n");
92 rt_kprintf("wifi help\n");
93 rt_kprintf("wifi scan [SSID]\n");
94 rt_kprintf("wifi join [SSID] [PASSWORD]\n");
95 rt_kprintf("wifi ap SSID [PASSWORD]\n");
96 rt_kprintf("wifi disc\n");
97 rt_kprintf("wifi ap_stop\n");
98 rt_kprintf("wifi status\n");
99 rt_kprintf("wifi smartconfig\n");
100 #ifdef RT_WLAN_CMD_DEBUG
101 rt_kprintf("wifi -d debug command\n");
102 #endif
103 return 0;
104 }
105
wifi_status(int argc,char * argv[])106 static int wifi_status(int argc, char *argv[])
107 {
108 int rssi;
109 struct rt_wlan_info info;
110
111 if (argc > 2)
112 return -1;
113
114 if (rt_wlan_is_connected() == 1)
115 {
116 rssi = rt_wlan_get_rssi();
117 rt_wlan_get_info(&info);
118 rt_kprintf("Wi-Fi STA Info\n");
119 rt_kprintf("SSID : %-.32s\n", &info.ssid.val[0]);
120 rt_kprintf("MAC Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", info.bssid[0],
121 info.bssid[1],
122 info.bssid[2],
123 info.bssid[3],
124 info.bssid[4],
125 info.bssid[5]);
126 rt_kprintf("Channel: %d\n", info.channel);
127 rt_kprintf("DataRate: %dMbps\n", info.datarate / 1000000);
128 rt_kprintf("RSSI: %d\n", rssi);
129 }
130 else
131 {
132 rt_kprintf("wifi disconnected!\n");
133 }
134
135 if (rt_wlan_ap_is_active() == 1)
136 {
137 rt_wlan_ap_get_info(&info);
138 rt_kprintf("Wi-Fi AP Info\n");
139 rt_kprintf("SSID : %-.32s\n", &info.ssid.val[0]);
140 rt_kprintf("MAC Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", info.bssid[0],
141 info.bssid[1],
142 info.bssid[2],
143 info.bssid[3],
144 info.bssid[4],
145 info.bssid[5]);
146 rt_kprintf("Channel: %d\n", info.channel);
147 rt_kprintf("DataRate: %dMbps\n", info.datarate / 1000000);
148 rt_kprintf("hidden: %s\n", info.hidden ? "Enable" : "Disable");
149 }
150 else
151 {
152 rt_kprintf("wifi ap not start!\n");
153 }
154 rt_kprintf("Auto Connect status:%s!\n", (rt_wlan_get_autoreconnect_mode() ? "Enable" : "Disable"));
155 return 0;
156 }
157
158
wifi_info_isequ(struct rt_wlan_info * info1,struct rt_wlan_info * info2)159 static rt_bool_t wifi_info_isequ(struct rt_wlan_info *info1, struct rt_wlan_info *info2)
160 {
161 rt_bool_t is_equ = 1;
162 rt_uint8_t bssid_zero[RT_WLAN_BSSID_MAX_LENGTH] = { 0 };
163
164 if (is_equ && (info1->security != SECURITY_UNKNOWN) && (info2->security != SECURITY_UNKNOWN))
165 {
166 is_equ &= info2->security == info1->security;
167 }
168 if (is_equ && ((info1->ssid.len > 0) && (info2->ssid.len > 0)))
169 {
170 is_equ &= info1->ssid.len == info2->ssid.len;
171 is_equ &= rt_memcmp(&info2->ssid.val[0], &info1->ssid.val[0], info1->ssid.len) == 0;
172 }
173 if (is_equ && (rt_memcmp(&info1->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH)) &&
174 (rt_memcmp(&info2->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH)))
175 {
176 is_equ &= rt_memcmp(&info1->bssid[0], &info2->bssid[0], RT_WLAN_BSSID_MAX_LENGTH) == 0;
177 }
178 if (is_equ && info1->datarate && info2->datarate)
179 {
180 is_equ &= info1->datarate == info2->datarate;
181 }
182 if (is_equ && (info1->channel >= 0) && (info2->channel >= 0))
183 {
184 is_equ &= info1->channel == info2->channel;
185 }
186 if (is_equ && (info1->rssi < 0) && (info2->rssi < 0))
187 {
188 is_equ &= info1->rssi == info2->rssi;
189 }
190 return is_equ;
191 }
192
wifi_scan_result_cache(struct rt_wlan_info * info)193 static rt_err_t wifi_scan_result_cache(struct rt_wlan_info *info)
194 {
195 struct rt_wlan_info *ptable;
196 rt_err_t err = RT_EOK;
197 int i, insert = -1;
198 rt_base_t level;
199
200 if ((info == RT_NULL) || (info->ssid.len == 0)) return -RT_EINVAL;
201
202 LOG_D("ssid:%s len:%d mac:%02x:%02x:%02x:%02x:%02x:%02x", info->ssid.val, info->ssid.len,
203 info->bssid[0], info->bssid[1], info->bssid[2], info->bssid[3], info->bssid[4], info->bssid[5]);
204
205 /* scanning result filtering */
206 level = rt_hw_interrupt_disable();
207 if (scan_filter)
208 {
209 struct rt_wlan_info _tmp_info = *scan_filter;
210 rt_hw_interrupt_enable(level);
211 if (wifi_info_isequ(&_tmp_info, info) != RT_TRUE)
212 {
213 return RT_EOK;
214 }
215 }
216 else
217 {
218 rt_hw_interrupt_enable(level);
219 }
220
221 /* de-duplicatio */
222 for (i = 0; i < scan_result.num; i++)
223 {
224 if ((info->ssid.len == scan_result.info[i].ssid.len) &&
225 (rt_memcmp(&info->bssid[0], &scan_result.info[i].bssid[0], RT_WLAN_BSSID_MAX_LENGTH) == 0))
226 {
227 return RT_EOK;
228 }
229 #ifdef RT_WLAN_SCAN_SORT
230 if (insert >= 0)
231 {
232 continue;
233 }
234 /* Signal intensity comparison */
235 if ((info->rssi < 0) && (scan_result.info[i].rssi < 0))
236 {
237 if (info->rssi > scan_result.info[i].rssi)
238 {
239 insert = i;
240 continue;
241 }
242 else if (info->rssi < scan_result.info[i].rssi)
243 {
244 continue;
245 }
246 }
247
248 /* Channel comparison */
249 if (info->channel < scan_result.info[i].channel)
250 {
251 insert = i;
252 continue;
253 }
254 else if (info->channel > scan_result.info[i].channel)
255 {
256 continue;
257 }
258
259 /* data rate comparison */
260 if ((info->datarate > scan_result.info[i].datarate))
261 {
262 insert = i;
263 continue;
264 }
265 else if (info->datarate < scan_result.info[i].datarate)
266 {
267 continue;
268 }
269 #endif
270 }
271
272 /* Insert the end */
273 if (insert == -1)
274 insert = scan_result.num;
275
276 if (scan_result.num >= RT_WLAN_SCAN_CACHE_NUM)
277 return RT_EOK;
278
279 /* malloc memory */
280 ptable = rt_malloc(sizeof(struct rt_wlan_info) * (scan_result.num + 1));
281 if (ptable == RT_NULL)
282 {
283 LOG_E("wlan info malloc failed!");
284 return -RT_ENOMEM;
285 }
286 scan_result.num ++;
287
288 /* copy info */
289 for (i = 0; i < scan_result.num; i++)
290 {
291 if (i < insert)
292 {
293 ptable[i] = scan_result.info[i];
294 }
295 else if (i > insert)
296 {
297 ptable[i] = scan_result.info[i - 1];
298 }
299 else if (i == insert)
300 {
301 ptable[i] = *info;
302 }
303 }
304 rt_free(scan_result.info);
305 scan_result.info = ptable;
306 return err;
307 }
308
309
310
wifi_scan_result_clean(void)311 static void wifi_scan_result_clean(void)
312 {
313
314 /* If there is data */
315 if (scan_result.num)
316 {
317 scan_result.num = 0;
318 rt_free(scan_result.info);
319 scan_result.info = RT_NULL;
320 }
321 }
322
print_ap_info(struct rt_wlan_info * info,int index)323 static void print_ap_info(struct rt_wlan_info *info,int index)
324 {
325 char *security;
326
327 if(index == 0)
328 {
329 rt_kprintf(" SSID MAC security rssi chn Mbps\n");
330 rt_kprintf("------------------------------- ----------------- -------------- ---- --- ----\n");
331 }
332
333 {
334 rt_kprintf("%-32.32s", &(info->ssid.val[0]));
335 rt_kprintf("%02x:%02x:%02x:%02x:%02x:%02x ",
336 info->bssid[0],
337 info->bssid[1],
338 info->bssid[2],
339 info->bssid[3],
340 info->bssid[4],
341 info->bssid[5]
342 );
343 switch (info->security)
344 {
345 case SECURITY_OPEN:
346 security = "OPEN";
347 break;
348 case SECURITY_WEP_PSK:
349 security = "WEP_PSK";
350 break;
351 case SECURITY_WEP_SHARED:
352 security = "WEP_SHARED";
353 break;
354 case SECURITY_WPA_TKIP_PSK:
355 security = "WPA_TKIP_PSK";
356 break;
357 case SECURITY_WPA_AES_PSK:
358 security = "WPA_AES_PSK";
359 break;
360 case SECURITY_WPA2_AES_PSK:
361 security = "WPA2_AES_PSK";
362 break;
363 case SECURITY_WPA2_TKIP_PSK:
364 security = "WPA2_TKIP_PSK";
365 break;
366 case SECURITY_WPA2_MIXED_PSK:
367 security = "WPA2_MIXED_PSK";
368 break;
369 case SECURITY_WPS_OPEN:
370 security = "WPS_OPEN";
371 break;
372 case SECURITY_WPS_SECURE:
373 security = "WPS_SECURE";
374 break;
375 default:
376 security = "UNKNOWN";
377 break;
378 }
379 rt_kprintf("%-14.14s ", security);
380 rt_kprintf("%-4d ", info->rssi);
381 rt_kprintf("%3d ", info->channel);
382 rt_kprintf("%4d\n", info->datarate / 1000000);
383 }
384
385 }
386
user_ap_info_callback(int event,struct rt_wlan_buff * buff,void * parameter)387 static void user_ap_info_callback(int event, struct rt_wlan_buff *buff, void *parameter)
388 {
389 struct rt_wlan_info *info = RT_NULL;
390 int index = 0;
391 int ret = RT_EOK;
392 rt_uint32_t last_num = scan_result.num;
393
394 RT_ASSERT(event == RT_WLAN_EVT_SCAN_REPORT);
395 RT_ASSERT(buff != RT_NULL);
396 RT_ASSERT(parameter != RT_NULL);
397
398 info = (struct rt_wlan_info *)buff->data;
399 index = *((int *)(parameter));
400
401 ret = wifi_scan_result_cache(info);
402 if(ret == RT_EOK)
403 {
404 if(scan_filter == RT_NULL ||
405 (scan_filter != RT_NULL &&
406 scan_filter->ssid.len == info->ssid.len &&
407 rt_memcmp(&scan_filter->ssid.val[0], &info->ssid.val[0], scan_filter->ssid.len) == 0))
408 {
409 /*Check whether a new ap is added*/
410 if (last_num < scan_result.num)
411 {
412 /*Print the info*/
413 print_ap_info(info,index);
414 }
415
416 index++;
417 *((int *)(parameter)) = index;
418 }
419 }
420
421 }
wifi_scan(int argc,char * argv[])422 static int wifi_scan(int argc, char *argv[])
423 {
424 struct rt_wlan_info *info = RT_NULL;
425 struct rt_wlan_info filter;
426 int ret = 0;
427 int i = 0;
428
429 if (argc > 3)
430 return -1;
431
432 if (argc == 3)
433 {
434 INVALID_INFO(&filter);
435 SSID_SET(&filter, argv[2]);
436 info = &filter;
437 }
438
439 ret = rt_wlan_register_event_handler(RT_WLAN_EVT_SCAN_REPORT,user_ap_info_callback,&i);
440 if(ret != RT_EOK)
441 {
442 LOG_E("Scan register user callback error:%d!\n",ret);
443 return 0;
444 }
445
446 if(info)
447 {
448 scan_filter = info;
449 }
450
451
452 /*Todo: what can i do for it return val */
453 ret = rt_wlan_scan_with_info(info);
454 if(ret != RT_EOK)
455 {
456 LOG_E("Scan with info error:%d!\n",ret);
457 }
458
459 /* clean scan result */
460 wifi_scan_result_clean();
461 if(info)
462 {
463 scan_filter = RT_NULL;
464 }
465 return 0;
466 }
467
wifi_join(int argc,char * argv[])468 static int wifi_join(int argc, char *argv[])
469 {
470 const char *ssid = RT_NULL;
471 const char *key = RT_NULL;
472 struct rt_wlan_cfg_info cfg_info;
473
474 rt_memset(&cfg_info, 0, sizeof(cfg_info));
475 if (argc == 2)
476 {
477 #ifdef RT_WLAN_CFG_ENABLE
478 /* get info to connect */
479 if (rt_wlan_cfg_read_index(&cfg_info, 0) == 1)
480 {
481 ssid = (char *)(&cfg_info.info.ssid.val[0]);
482 if (cfg_info.key.len)
483 key = (char *)(&cfg_info.key.val[0]);
484 }
485 else
486 #endif
487 {
488 rt_kprintf("not find connect info\n");
489 }
490 }
491 else if (argc == 3)
492 {
493 /* ssid */
494 ssid = argv[2];
495 }
496 else if (argc == 4)
497 {
498 ssid = argv[2];
499 /* password */
500 key = argv[3];
501 }
502 else
503 {
504 return -1;
505 }
506 rt_wlan_connect(ssid, key);
507 return 0;
508 }
509
wifi_ap(int argc,char * argv[])510 static int wifi_ap(int argc, char *argv[])
511 {
512 const char *ssid = RT_NULL;
513 const char *key = RT_NULL;
514
515 if (argc == 3)
516 {
517 ssid = argv[2];
518 }
519 else if (argc == 4)
520 {
521 ssid = argv[2];
522 key = argv[3];
523 }
524 else
525 {
526 return -1;
527 }
528
529 rt_wlan_start_ap(ssid, key);
530 return 0;
531 }
532
wifi_list_sta(int argc,char * argv[])533 static int wifi_list_sta(int argc, char *argv[])
534 {
535 struct rt_wlan_info *sta_info;
536 int num, i;
537
538 if (argc > 2)
539 return -1;
540 num = rt_wlan_ap_get_sta_num();
541 sta_info = rt_malloc(sizeof(struct rt_wlan_info) * num);
542 if (sta_info == RT_NULL)
543 {
544 rt_kprintf("num:%d\n", num);
545 return 0;
546 }
547 rt_wlan_ap_get_sta_info(sta_info, num);
548 rt_kprintf("num:%d\n", num);
549 for (i = 0; i < num; i++)
550 {
551 rt_kprintf("sta mac %02x:%02x:%02x:%02x:%02x:%02x\n",
552 sta_info[i].bssid[0], sta_info[i].bssid[1], sta_info[i].bssid[2],
553 sta_info[i].bssid[3], sta_info[i].bssid[4], sta_info[i].bssid[5]);
554 }
555 rt_free(sta_info);
556 return 0;
557 }
558
wifi_disconnect(int argc,char * argv[])559 static int wifi_disconnect(int argc, char *argv[])
560 {
561 if (argc != 2)
562 {
563 return -1;
564 }
565
566 rt_wlan_disconnect();
567 return 0;
568 }
569
wifi_ap_stop(int argc,char * argv[])570 static int wifi_ap_stop(int argc, char *argv[])
571 {
572 if (argc != 2)
573 {
574 return -1;
575 }
576
577 rt_wlan_ap_stop();
578 return 0;
579 }
580
581 #ifdef RT_WLAN_CMD_DEBUG
582 /* just for debug */
wifi_debug_help(int argc,char * argv[])583 static int wifi_debug_help(int argc, char *argv[])
584 {
585 rt_kprintf("save_cfg ssid [password]\n");
586 rt_kprintf("dump_cfg\n");
587 rt_kprintf("clear_cfg\n");
588 rt_kprintf("dump_prot\n");
589 rt_kprintf("mode sta/ap dev_name\n");
590 rt_kprintf("prot lwip dev_name\n");
591 rt_kprintf("auto enable/disable\n");
592 return 0;
593 }
594
wifi_debug_save_cfg(int argc,char * argv[])595 static int wifi_debug_save_cfg(int argc, char *argv[])
596 {
597 struct rt_wlan_cfg_info cfg_info;
598 int len;
599 char *ssid = RT_NULL, *password = RT_NULL;
600
601 rt_memset(&cfg_info, 0, sizeof(cfg_info));
602 INVALID_INFO(&cfg_info.info);
603 if (argc == 2)
604 {
605 ssid = argv[1];
606 }
607 else if (argc == 3)
608 {
609 ssid = argv[1];
610 password = argv[2];
611 }
612 else
613 {
614 return -1;
615 }
616
617 if (ssid != RT_NULL)
618 {
619 len = rt_strlen(ssid);
620 if (len > RT_WLAN_SSID_MAX_LENGTH)
621 {
622 rt_kprintf("ssid is to long");
623 return 0;
624 }
625 rt_memcpy(&cfg_info.info.ssid.val[0], ssid, len);
626 cfg_info.info.ssid.len = len;
627 }
628
629 if (password != RT_NULL)
630 {
631 len = rt_strlen(password);
632 if (len > RT_WLAN_PASSWORD_MAX_LENGTH)
633 {
634 rt_kprintf("password is to long");
635 return 0;
636 }
637 rt_memcpy(&cfg_info.key.val[0], password, len);
638 cfg_info.key.len = len;
639 }
640 #ifdef RT_WLAN_CFG_ENABLE
641 rt_wlan_cfg_save(&cfg_info);
642 #endif
643 return 0;
644 }
645
wifi_debug_dump_cfg(int argc,char * argv[])646 static int wifi_debug_dump_cfg(int argc, char *argv[])
647 {
648 if (argc == 1)
649 {
650 #ifdef RT_WLAN_CFG_ENABLE
651 rt_wlan_cfg_dump();
652 #endif
653 }
654 else
655 {
656 return -1;
657 }
658 return 0;
659 }
660
wifi_debug_clear_cfg(int argc,char * argv[])661 static int wifi_debug_clear_cfg(int argc, char *argv[])
662 {
663 if (argc == 1)
664 {
665 #ifdef RT_WLAN_CFG_ENABLE
666 rt_wlan_cfg_delete_all();
667 rt_wlan_cfg_cache_save();
668 #endif
669 }
670 else
671 {
672 return -1;
673 }
674 return 0;
675 }
676
wifi_debug_dump_prot(int argc,char * argv[])677 static int wifi_debug_dump_prot(int argc, char *argv[])
678 {
679 if (argc == 1)
680 {
681 rt_wlan_prot_dump();
682 }
683 else
684 {
685 return -1;
686 }
687 return 0;
688 }
689
wifi_debug_set_mode(int argc,char * argv[])690 static int wifi_debug_set_mode(int argc, char *argv[])
691 {
692 rt_wlan_mode_t mode;
693
694 if (argc != 3)
695 return -1;
696
697 if (rt_strcmp("sta", argv[1]) == 0)
698 {
699 mode = RT_WLAN_STATION;
700 }
701 else if (rt_strcmp("ap", argv[1]) == 0)
702 {
703 mode = RT_WLAN_AP;
704 }
705 else if (rt_strcmp("none", argv[1]) == 0)
706 {
707 mode = RT_WLAN_NONE;
708 }
709 else
710 return -1;
711
712 rt_wlan_set_mode(argv[2], mode);
713 return 0;
714 }
715
wifi_debug_set_prot(int argc,char * argv[])716 static int wifi_debug_set_prot(int argc, char *argv[])
717 {
718 if (argc != 3)
719 {
720 return -1;
721 }
722
723 rt_wlan_prot_attach(argv[2], argv[1]);
724 return 0;
725 }
726
wifi_debug_set_autoconnect(int argc,char * argv[])727 static int wifi_debug_set_autoconnect(int argc, char *argv[])
728 {
729 if (argc == 2)
730 {
731 if (rt_strcmp(argv[1], "enable") == 0)
732 rt_wlan_config_autoreconnect(RT_TRUE);
733 else if (rt_strcmp(argv[1], "disable") == 0)
734 rt_wlan_config_autoreconnect(RT_FALSE);
735 }
736 else
737 {
738 return -1;
739 }
740 return 0;
741 }
742
wifi_debug(int argc,char * argv[])743 static int wifi_debug(int argc, char *argv[])
744 {
745 int i, result = 0;
746 const struct wifi_cmd_des *run_cmd = RT_NULL;
747
748 if (argc < 3)
749 {
750 wifi_debug_help(0, RT_NULL);
751 return 0;
752 }
753
754 for (i = 0; i < sizeof(debug_tab) / sizeof(debug_tab[0]); i++)
755 {
756 if (rt_strcmp(debug_tab[i].cmd, argv[2]) == 0)
757 {
758 run_cmd = &debug_tab[i];
759 break;
760 }
761 }
762
763 if (run_cmd == RT_NULL)
764 {
765 wifi_debug_help(0, RT_NULL);
766 return 0;
767 }
768
769 if (run_cmd->fun != RT_NULL)
770 {
771 result = run_cmd->fun(argc - 2, &argv[2]);
772 }
773
774 if (result)
775 {
776 wifi_debug_help(argc - 2, &argv[2]);
777 }
778 return 0;
779 }
780 #endif
781
wifi_msh(int argc,char * argv[])782 static int wifi_msh(int argc, char *argv[])
783 {
784 int i, result = 0;
785 const struct wifi_cmd_des *run_cmd = RT_NULL;
786
787 if (argc == 1)
788 {
789 wifi_help(argc, argv);
790 return 0;
791 }
792
793 /* find fun */
794 for (i = 0; i < sizeof(cmd_tab) / sizeof(cmd_tab[0]); i++)
795 {
796 if (rt_strcmp(cmd_tab[i].cmd, argv[1]) == 0)
797 {
798 run_cmd = &cmd_tab[i];
799 break;
800 }
801 }
802
803 /* not find fun, print help */
804 if (run_cmd == RT_NULL)
805 {
806 wifi_help(argc, argv);
807 return 0;
808 }
809
810 /* run fun */
811 if (run_cmd->fun != RT_NULL)
812 {
813 result = run_cmd->fun(argc, argv);
814 }
815
816 if (result)
817 {
818 wifi_help(argc, argv);
819 }
820 return 0;
821 }
822
823 #if defined(RT_USING_FINSH)
824 MSH_CMD_EXPORT_ALIAS(wifi_msh, wifi, wifi command);
825 #endif
826
827 #endif
828