blob: b8f5189c2134b5106e5c3b4712da2ce34b31c20c [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001#include "sta_cli.h"
2#include "lynq_wifi.h"
3
4#include <stdio.h>
5#include <stdlib.h>
6
7
8#define MAX_LEN 15
9#define MAX_VALUE_LEN 512
10
11#define ENABLE "enable"
12#define DISABLE "disable"
13#define MODE_SET "mode_set"
14#define MODE_GET "mode_get"
15#define AP_GET_STATUS "ap_get_status"
16#define AP_ACL_SET "ap_acl_set"
17#define AP_ACL_GET "ap_acl_get"
18#define AP_SSID_SET "ap_ssid_set"
19#define AP_SSID_GET "ap_ssid_get"
20#define AP_SSID_HIDE_SET "ap_ssid_hide_set"
21#define AP_SSID_HIDE_GET "ap_ssid_hide_get"
22#define AP_MODE_SET "ap_mode_set"
23#define AP_MODE_GET "ap_mode_get"
24#define AP_BAND_SET "ap_band_set"
25#define AP_BAND_GET "ap_band_get"
26#define AP_CHANNEL_SET "ap_channel_set"
27#define AP_CHANNEL_GET "ap_channel_get"
28#define AP_AUTH_SET "ap_auth_set"
29#define AP_AUTH_GET "ap_auth_get"
30#define AP_auth_GET_S "ap_auth_get_s"
31#define AP_MAX_STA_SET "ap_max_sta_set"
32#define AP_MAX_STA_GET "ap_max_sta_get"
33#define AP_LIST_GET "list_get"
34#define AP_PKT_GET "ap_pkt_get"
35#define AP_START "ap_start"
36#define AP_STOP "ap_stop"
37#define AP_RESTART "ap_restart"
38#define AP_REG_HANDLE "reg_handle"
39#define STA_PARAM_SET "sta_param_set"
40#define STA_PARAM_GET "sta_param_get"
41#define STA_START "sta_start"
42#define STA_STOP "sta_stop"
43#define STA_STATUS_GET "sta_status_get"
44#define STA_PKT_GET "sta_pkt_get"
45#define STA_SCAN "sta_scan"
46
47void lynq_wifi_event_handle_sta_demo(lynq_wifi_sta_scan_list_t *event)
48{
49 int i = 0;
50 for (i = 0; i < event->cnt; i++)
51 {
52 printf("[lynq-wifi-demo] %s : ap[%d]:%s,%d,%d,%d,%s,%d,%d,%d\n", __func__, i,
53 event->info[i].essid, event->info[i].auth,
54 event->info[i].cipher, event->info[i].channel, event->info[i].bssid,
55 event->info[i].signal_level,event->info[i].frequency,event->info[i].signal);
56 }
57}
58
59
60static void help()
61{
62 printf("please read the define \n");
63
64}
65
66int main(int argc, char *argv[])
67{
68 int test_int = 0;
69 char value[MAX_VALUE_LEN] = {0};
70 lynq_wifi_ap_auth_t auth_mode = {0};
71 lynq_lanhost_ts lanhost = {0};
72 lynq_wifi_pkt_stats_t pkt_stat = {0};
73 lynq_wifi_sta_param_t sta_param = {0};
74 lynq_wifi_sta_status_t sta_status = {0};
75
76 printf(">>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:\n");
77 char cmd[MAX_VALUE_LEN];
78 while(1)
79 {
80 memset(cmd, 0, MAX_VALUE_LEN);
81 test_int = 0;
82 memset(value, 0, MAX_VALUE_LEN);
83 memset(&auth_mode, 0, sizeof(lynq_wifi_ap_auth_t));
84 memset(&lanhost, 0, sizeof(lynq_lanhost_ts));
85 memset(&pkt_stat, 0, sizeof(lynq_wifi_pkt_stats_t));
86 memset(&sta_param, 0, sizeof(lynq_wifi_sta_param_t));
87 memset(&sta_status, 0, sizeof(lynq_wifi_sta_status_t));
88 if(fgets(cmd, MAX_VALUE_LEN, stdin))
89 {
90 char *ptr = cmd + strlen(cmd) - 1;
91 while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n'))
92 {
93 *ptr-- = '\0';
94 }
95
96 if(!strncasecmp(cmd, ENABLE, strlen(ENABLE)))
97 {
98 if(LYNQ_ERR_SUCCESS != qser_wifi_enable())
99 {
100 printf("LYNQ_ERR_FAIL\n");
101 }
102 else
103 {
104 printf("LYNQ_ERR_SUCCESS\n");
105 }
106 }
107 else if(!strncasecmp(cmd, DISABLE, strlen(DISABLE)))
108 {
109 if(LYNQ_ERR_SUCCESS != qser_wifi_disable())
110 {
111 printf("LYNQ_ERR_FAIL\n");
112 }
113 else
114 {
115 printf("LYNQ_ERR_SUCCESS\n");
116 }
117 }
118 else if(!strncasecmp(cmd, MODE_SET, strlen(MODE_SET)))
119 {
120 if(LYNQ_ERR_SUCCESS != qser_wifi_work_mode_set(LYNQ_WIFI_WORK_MODE_AP0))
121 {
122 printf("LYNQ_ERR_FAIL\n");
123 }
124 else
125 {
126 printf("LYNQ_ERR_SUCCESS\n");
127 }
128 }
129 else if(!strncasecmp(cmd, MODE_GET, strlen(MODE_GET)))
130 {
131 if(LYNQ_ERR_SUCCESS != qser_wifi_work_mode_get(&test_int))
132 {
133 printf("LYNQ_ERR_FAIL\n");
134 }
135 else
136 {
137 printf("mode:%d\n",test_int);
138 printf("LYNQ_ERR_SUCCESS\n");
139 }
140 }
141 else if(!strncasecmp(cmd, AP_ACL_SET, strlen(AP_ACL_SET)))
142 {
143 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_acl_set(LYNQ_WIFI_AP_INDEX_AP1,
144 LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST, "AA:BB:CC:DD:EE:01;AA:BB:CC:01:EE:00;AA:BB:01:DD:EE:00"))
145 {
146 printf("LYNQ_ERR_FAIL\n");
147 }
148 else
149 {
150 printf("LYNQ_ERR_SUCCESS\n");
151 }
152 }
153 else if(!strncasecmp(cmd, AP_ACL_GET, strlen(AP_ACL_GET)))
154 {
155 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_acl_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int, value))
156 {
157 printf("LYNQ_ERR_FAIL\n");
158 }
159 else
160 {
161 printf("value:%s\n",value);
162 printf("mode:%d\n",test_int);
163 printf("LYNQ_ERR_SUCCESS\n");
164 }
165 }
166 else if(!strncasecmp(cmd, AP_SSID_SET, strlen(AP_SSID_SET)))
167 {
168 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_set(LYNQ_WIFI_AP_INDEX_AP1, "testssid"))
169 {
170 printf("LYNQ_ERR_FAIL\n");
171 }
172 else
173 {
174 printf("LYNQ_ERR_SUCCESS\n");
175 }
176 }
177 else if(!strncasecmp(cmd, AP_SSID_GET, strlen(AP_SSID_GET)))
178 {
179 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_get(LYNQ_WIFI_AP_INDEX_AP1, value))
180 {
181 printf("LYNQ_ERR_FAIL\n");
182 }
183 else
184 {
185 printf("value:%s\n",value);
186 printf("LYNQ_ERR_SUCCESS\n");
187 }
188 }
189 else if(!strncasecmp(cmd, AP_SSID_HIDE_SET, strlen(AP_SSID_HIDE_SET)))
190 {
191 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_hide_set(LYNQ_WIFI_AP_INDEX_AP1, 1))
192 {
193 printf("LYNQ_ERR_FAIL\n");
194 }
195 else
196 {
197 printf("LYNQ_ERR_SUCCESS\n");
198 }
199 }
200 else if(!strncasecmp(cmd, AP_SSID_HIDE_GET, strlen(AP_SSID_HIDE_GET)))
201 {
202 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_hide_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
203 {
204 printf("LYNQ_ERR_FAIL\n");
205 }
206 else
207 {
208
209 printf("value:%d\n", test_int);
210 printf("LYNQ_ERR_SUCCESS\n");
211 }
212 }
213 else if(!strncasecmp(cmd, AP_MODE_SET, strlen(AP_MODE_SET)))
214 {
215 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_mode_set(LYNQ_WIFI_AP_INDEX_AP1, 1))
216 {
217 printf("LYNQ_ERR_FAIL\n");
218 }
219 else
220 {
221 printf("LYNQ_ERR_SUCCESS\n");
222 }
223 }
224 else if(!strncasecmp(cmd, AP_MODE_GET, strlen(AP_MODE_GET)))
225 {
226 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_mode_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
227 {
228 printf("LYNQ_ERR_FAIL\n");
229 }
230 else
231 {
232 printf("value:%d\n", test_int);
233 printf("LYNQ_ERR_SUCCESS\n");
234 }
235 }
236 else if(!strncasecmp(cmd, AP_BAND_SET, strlen(AP_BAND_SET)))
237 {
238 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_bandwidth_set(LYNQ_WIFI_AP_INDEX_AP1, 2))
239 {
240 printf("LYNQ_ERR_FAIL\n");
241 }
242 else
243 {
244 printf("LYNQ_ERR_SUCCESS\n");
245 }
246 }
247 else if(!strncasecmp(cmd, AP_BAND_GET, strlen(AP_BAND_GET)))
248 {
249 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_bandwidth_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
250 {
251 printf("LYNQ_ERR_FAIL\n");
252 }
253 else
254 {
255 printf("value:%d\n", test_int);
256 printf("LYNQ_ERR_SUCCESS\n");
257 }
258 }
259 else if(!strncasecmp(cmd, AP_CHANNEL_SET, strlen(AP_CHANNEL_SET)))
260 {
261 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_channel_set(LYNQ_WIFI_AP_INDEX_AP1, "CN", 35))
262 {
263 printf("LYNQ_ERR_FAIL\n");
264 }
265 else
266 {
267 printf("LYNQ_ERR_SUCCESS\n");
268 }
269 }
270 else if(!strncasecmp(cmd, AP_CHANNEL_GET, strlen(AP_CHANNEL_GET)))
271 {
272 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_channel_get(LYNQ_WIFI_AP_INDEX_AP1, value, &test_int))
273 {
274 printf("LYNQ_ERR_FAIL\n");
275 }
276 else
277 {
278 printf("country:%s, channel:%d\n", value, test_int);
279 printf("LYNQ_ERR_SUCCESS\n");
280 }
281 }
282 else if(!strncasecmp(cmd, AP_AUTH_SET, strlen(AP_AUTH_SET)))
283 {
284 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_auth_set(LYNQ_WIFI_AP_INDEX_AP1, 1, "123456"))
285 {
286 printf("LYNQ_ERR_FAIL\n");
287 }
288 else
289 {
290 printf("LYNQ_ERR_SUCCESS\n");
291 }
292 }
293 else if(!strncasecmp(cmd, AP_AUTH_GET, strlen(AP_AUTH_GET)))
294 {
295 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_auth_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int, value))
296 {
297 printf("LYNQ_ERR_FAIL\n");
298 }
299 else
300 {
301 printf("value:%s\n", value);
302 printf("LYNQ_ERR_SUCCESS\n");
303 }
304 }
305 else if(!strncasecmp(cmd, AP_auth_GET_S, strlen(AP_auth_GET_S)))
306 {
307 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_auth_get_s(LYNQ_WIFI_AP_INDEX_AP1, &auth_mode))
308 {
309 printf("LYNQ_ERR_FAIL\n");
310 }
311 else
312 {
313 printf("auth_mode:%s\n", auth_mode.passwd);
314 printf("LYNQ_ERR_SUCCESS\n");
315 }
316 }
317 else if(!strncasecmp(cmd, AP_MAX_STA_SET, strlen(AP_MAX_STA_SET)))
318 {
319 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_max_sta_set(LYNQ_WIFI_AP_INDEX_AP1, 8))
320 {
321 printf("LYNQ_ERR_FAIL\n");
322 }
323 else
324 {
325 printf("LYNQ_ERR_SUCCESS\n");
326 }
327 }
328 else if(!strncasecmp(cmd, AP_MAX_STA_GET, strlen(AP_MAX_STA_GET)))
329 {
330 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_max_sta_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
331 {
332 printf("LYNQ_ERR_FAIL\n");
333 }
334 else
335 {
336 printf("max_sta:%d\n",test_int);
337 printf("LYNQ_ERR_SUCCESS\n");
338 }
339 }
340 else if(!strncasecmp(cmd, AP_LIST_GET, strlen(AP_LIST_GET)))
341 {
342 if(LYNQ_ERR_SUCCESS != qser_wifi_lanhost_get_list(&lanhost))
343 {
344 printf("LYNQ_ERR_FAIL\n");
345 }
346 else
347 {
348 printf("LYNQ_ERR_SUCCESS\n");
349 }
350 }
351 else if(!strncasecmp(cmd, AP_PKT_GET, strlen(AP_PKT_GET)))
352 {
353 if(LYNQ_ERR_SUCCESS != qser_wifi_get_ap_pkt_stats(LYNQ_WIFI_AP_INDEX_AP1, &pkt_stat))
354 {
355 printf("LYNQ_ERR_FAIL\n");
356 }
357 else
358 {
359 printf("LYNQ_ERR_SUCCESS\n");
360 }
361 }
362 else if(!strncasecmp(cmd, AP_START, strlen(AP_START)))
363 {
364 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_start(LYNQ_WIFI_AP_INDEX_AP1))
365 {
366 printf("LYNQ_ERR_FAIL\n");
367 }
368 else
369 {
370 printf("LYNQ_ERR_SUCCESS\n");
371 }
372 }
373 else if(!strncasecmp(cmd, AP_STOP, strlen(AP_STOP)))
374 {
375 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_stop(LYNQ_WIFI_AP_INDEX_AP1))
376 {
377 printf("LYNQ_ERR_FAIL\n");
378 }
379 else
380 {
381 printf("LYNQ_ERR_SUCCESS\n");
382 }
383 }
384 else if(!strncasecmp(cmd, AP_RESTART, strlen(AP_RESTART)))
385 {
386 if(LYNQ_ERR_SUCCESS != qser_wifi_ap_restart(LYNQ_WIFI_AP_INDEX_AP1))
387 {
388 printf("LYNQ_ERR_FAIL\n");
389 }
390 else
391 {
392 printf("LYNQ_ERR_SUCCESS\n");
393 }
394 }
395 else if(!strncasecmp(cmd, AP_REG_HANDLE, strlen(AP_REG_HANDLE)))
396 {
397 if(LYNQ_ERR_SUCCESS != qser_wifi_register_handle(NULL, lynq_wifi_event_handle_sta_demo, NULL))
398 {
399 printf("LYNQ_ERR_FAIL\n");
400 }
401 else
402 {
403 printf("LYNQ_ERR_SUCCESS\n");
404 }
405 }
406 else if(!strncasecmp(cmd, STA_PARAM_SET, strlen(STA_PARAM_SET)))
407 {
408 strcpy(sta_param.ssid, "test");
409 strcpy(sta_param.passwd, "123456");
410 if(LYNQ_ERR_SUCCESS != qser_wifi_sta_param_set(&sta_param))
411 {
412 printf("LYNQ_ERR_FAIL\n");
413 }
414 else
415 {
416 printf("LYNQ_ERR_SUCCESS\n");
417 }
418 }
419 else if(!strncasecmp(cmd, STA_PARAM_GET, strlen(STA_PARAM_GET)))
420 {
421 if(LYNQ_ERR_SUCCESS != qser_wifi_sta_param_get(&sta_param))
422 {
423 printf("LYNQ_ERR_FAIL\n");
424 }
425 else
426 {
427 printf("ssid:%s, passwd:%s\n", sta_param.ssid, sta_param.passwd);
428 printf("LYNQ_ERR_SUCCESS\n");
429 }
430 }
431 else if(!strncasecmp(cmd, STA_START, strlen(STA_START)))
432 {
433 if(LYNQ_ERR_SUCCESS != qser_wifi_sta_start())
434 {
435 printf("LYNQ_ERR_FAIL\n");
436 }
437 else
438 {
439 printf("LYNQ_ERR_SUCCESS\n");
440 }
441 }
442 else if(!strncasecmp(cmd, STA_STOP, strlen(STA_STOP)))
443 {
444 if(LYNQ_ERR_SUCCESS != qser_wifi_sta_stop())
445 {
446 printf("LYNQ_ERR_FAIL\n");
447 }
448 else
449 {
450 printf("LYNQ_ERR_SUCCESS\n");
451 }
452 }
453 else if(!strncasecmp(cmd, STA_STATUS_GET, strlen(STA_STATUS_GET)))
454 {
455 if(LYNQ_ERR_SUCCESS != qser_wifi_sta_get_status(&sta_status))
456 {
457 printf("LYNQ_ERR_FAIL\n");
458 }
459 else
460 {
461 printf("LYNQ_ERR_SUCCESS\n");
462 }
463 }
464 else if(!strncasecmp(cmd, STA_PKT_GET, strlen(STA_PKT_GET)))
465 {
466 if(LYNQ_ERR_SUCCESS != qser_wifi_get_sta_pkt_stats(&pkt_stat))
467 {
468 printf("LYNQ_ERR_FAIL\n");
469 }
470 else
471 {
472 printf("LYNQ_ERR_SUCCESS\n");
473 }
474 }
475 else if(!strncasecmp(cmd, STA_SCAN, strlen(STA_SCAN)))
476 {
477 if(LYNQ_ERR_SUCCESS != qser_wifi_sta_start_scan())
478 {
479 printf("LYNQ_ERR_FAIL\n");
480 }
481 else
482 {
483 printf("LYNQ_ERR_SUCCESS\n");
484 }
485 }
486
487 else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help"))
488 {
489 help();
490 }
491 else if(!strcasecmp(cmd, "q"))
492 {
493 break;
494 }
495 else
496 {
497 printf("unknown command\n");
498 }
499 }
500 }
501
502
503 return 0;
504}
505