blob: a2b08b7f72af3a9e4ee29e9d9c3c606b795b5ca4 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001#include "sta_cli.h"
2#include "lynq_wifi.h"
3#include "mbtk_log.h"
4#include "mbtk_wifi_ap.h"
5
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10
11
12
13#define STA_BUF_SIZE 2048
14#define PATH_MAX_LEN 64
15#define DEF_INTERFACE "wlan0"
16static lynq_wifi_event_handle_sta g_event_handle_sta_cb = NULL;
17static lynq_wifi_status_e g_ap_status = LYNQ_WIFI_AP_STATUS_NONE;
18
19
20
21int qser_wifi_enable(void)
22{
23 static char sta_cli_buf[STA_BUF_SIZE] = "OPEN";
24 char reply[STA_BUF_SIZE];
25 if(sta_cli_cmd_parse(sta_cli_buf, reply, STA_BUF_SIZE))
26 {
27 if(strlen(reply) > 0)
28 {
29 LOGE("reply data(%s).\n",reply);
30 }
31 else
32 {
33 LOGE("No reply data(%s).\n",sta_cli_buf);
34 return LYNQ_ERR_FAIL;
35 }
36 }
37 else
38 {
39 LOGE("Parse cmd fail.\n");
40 return LYNQ_ERR_FAIL;
41 }
42
43 g_ap_status = LYNQ_WIFI_AP_STATUS_ENABLING;
44 return LYNQ_ERR_SUCCESS;
45}
46
47
48int qser_wifi_disable(void)
49{
50 static char sta_cli_buf[STA_BUF_SIZE] = "CLOSE";
51 char reply[STA_BUF_SIZE];
52 if(sta_cli_cmd_parse(sta_cli_buf, reply, STA_BUF_SIZE)){
53 if(strlen(reply) > 0)
54 {
55 LOGE("reply data(%s).\n",reply);
56 }
57 else
58 {
59 LOGE("No reply data(%s).\n",sta_cli_buf);
60 return LYNQ_ERR_FAIL;
61 }
62 }
63 else
64 {
65 LOGE("Parse cmd fail.\n");
66 return LYNQ_ERR_FAIL;
67 }
68
69 g_ap_status = LYNQ_WIFI_AP_STATUS_IDLE;
70 return LYNQ_ERR_SUCCESS;
71}
72
73int qser_wifi_work_mode_set(lynq_wifi_work_mode_e type)
74{
75 int ret = 0;
76 if(LYNQ_WIFI_WORK_MODE_AP0 == type)
77 {
78 ret = mbtk_wifi_set_setting(SETTING_FILE, "hw_mode", "g");
79 }
80 else
81 {
82 ret = mbtk_wifi_set_setting(SETTING_FILE, "hw_mode", "a");
83 }
84
85 if(0 > ret)
86 {
87 LOGE("qser wifi fail");
88 return LYNQ_ERR_FAIL;
89 }
90
91 return LYNQ_ERR_SUCCESS;
92}
93
94int qser_wifi_work_mode_get(lynq_wifi_work_mode_e *type)
95{
96 int ret = 0;
97 char value[SETTING_VALUE_MAX_LEN] = {0};
98
99 if(NULL == type)
100 {
101 LOGE("qser wifi ptr is null");
102 return LYNQ_ERR_BADPARAM;
103 }
104
105 ret = mbtk_wifi_get_setting(SETTING_FILE, "hw_mode", value, SETTING_VALUE_MAX_LEN);
106
107 if(0 > ret)
108 {
109 LOGE("qser wifi fail");
110 return LYNQ_ERR_FAIL;
111 }
112
113 if('g' == value[0])
114 {
115 *type = LYNQ_WIFI_AP_INDEX_AP0;
116 }
117 else
118 {
119 *type = LYNQ_WIFI_AP_INDEX_AP1;
120 }
121
122 return LYNQ_ERR_SUCCESS;
123}
124
125
126int qser_wifi_ap_get_status(lynq_wifi_ap_index_e idx, lynq_wifi_ap_status_t* ap_stat)
127{
128 if(NULL == ap_stat)
129 {
130 LOGE("qser wifi ptr is null");
131 return LYNQ_ERR_BADPARAM;
132 }
133
134 int ret = mbtk_wifi_get_setting(SETTING_FILE, "ssid", ap_stat->bssid, SETTING_VALUE_MAX_LEN);
135
136 if(0 > ret)
137 {
138 LOGE("qser wifi fail");
139 return LYNQ_ERR_FAIL;
140 }
141
142 ap_stat->status = g_ap_status;
143 memcpy(ap_stat->ifname, DEF_INTERFACE, strlen(DEF_INTERFACE));
144
145 return LYNQ_ERR_SUCCESS;
146}
147
148
149int qser_wifi_ap_acl_set(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e acl_rule, char *mac_list)
150{
151 int ret = 0;
152 char path[PATH_MAX_LEN] = {0};
153
154 if(NULL == mac_list)
155 {
156 LOGE("qser wifi ptr is null");
157 return LYNQ_ERR_BADPARAM;
158 }
159
160 if(LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST == acl_rule)
161 {
162 ret = mbtk_wifi_set_setting(SETTING_FILE, "macaddr_acl", "1");
163 memcpy(path, ACL_ACCEPT_FILE, strlen(ACL_ACCEPT_FILE));
164
165 }
166 else if(LYNQ_WIFI_MAC_ACL_RULE_BLACK_LIST == acl_rule)
167 {
168 ret = mbtk_wifi_set_setting(SETTING_FILE, "macaddr_acl", "0");
169 memcpy(path, ACL_DENY_FILE, strlen(ACL_DENY_FILE));
170 }
171 else
172 {
173 LOGE("qser_wifi_ap_acl_set LYNQ_WIFI_MAC_ACL_RULE_NONE");
174 return LYNQ_ERR_SUCCESS;
175 }
176
177 if(0 > ret)
178 {
179 LOGE("qser wifi fail");
180 return LYNQ_ERR_FAIL;
181 }
182
183 ret = mbtk_wifi_set_file(path, mac_list);
184 if(0 > ret)
185 {
186 LOGE("qser wifi fail");
187 return LYNQ_ERR_FAIL;
188 }
189
190
191 return LYNQ_ERR_SUCCESS;
192}
193
194int qser_wifi_ap_acl_get(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e *acl_rule, char *mac_list)
195{
196 int ret = 0;
197 char value[SETTING_VALUE_MAX_LEN] = {0};
198 char path[PATH_MAX_LEN] = {0};
199
200 if(NULL == acl_rule || NULL == mac_list)
201 {
202 LOGE("qser wifi ptr is null");
203 return LYNQ_ERR_BADPARAM;
204 }
205
206 ret = mbtk_wifi_get_setting(SETTING_FILE, "macaddr_acl", value, SETTING_LINE_MAX_LEN);
207
208 if(0 > ret)
209 {
210 LOGE("qser wifi fail");
211 return LYNQ_ERR_FAIL;
212 }
213
214 if('1' == value[0])
215 {
216 *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST;
217 memcpy(path, ACL_ACCEPT_FILE, strlen(ACL_ACCEPT_FILE));
218 }
219 else if('0' == value[0])
220 {
221 *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_BLACK_LIST;
222 memcpy(path, ACL_DENY_FILE, strlen(ACL_DENY_FILE));
223 }
224 else
225 {
226 *acl_rule = LYNQ_WIFI_MAC_ACL_RULE_NONE;
227 LOGE("qser_wifi_ap_acl_get LYNQ_WIFI_MAC_ACL_RULE_NONE");
228 return LYNQ_ERR_SUCCESS;
229 }
230
231 ret = mbtk_wifi_get_file(path, mac_list, SETTING_LINE_MAX_LEN);
232 if(0 > ret)
233 {
234 LOGE("qser wifi fail");
235 return LYNQ_ERR_FAIL;
236 }
237
238 return LYNQ_ERR_SUCCESS;
239}
240
241
242int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
243{
244 int ret = 0;
245
246 if(NULL == ssid)
247 {
248 LOGE("qser wifi ptr is null");
249 return LYNQ_ERR_BADPARAM;
250 }
251
252 ret = mbtk_wifi_set_setting(SETTING_FILE, "ssid", ssid);
253
254 if(0 > ret)
255 {
256 LOGE("qser wifi fail");
257 return LYNQ_ERR_FAIL;
258 }
259
260 return LYNQ_ERR_SUCCESS;
261}
262
263int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
264{
265 int ret = 0;
266
267 if(NULL == ssid)
268 {
269 LOGE("qser wifi ptr is null");
270 return LYNQ_ERR_BADPARAM;
271 }
272
273 ret = mbtk_wifi_get_setting(SETTING_FILE, "ssid", ssid, SETTING_VALUE_MAX_LEN);
274
275 if(0 > ret)
276 {
277 LOGE("qser wifi fail");
278 return LYNQ_ERR_FAIL;
279 }
280
281 return LYNQ_ERR_SUCCESS;
282}
283
284int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx,bool hide)
285{
286 int ret = 0;
287 if(true == hide)
288 {
289 ret = mbtk_wifi_set_setting(SETTING_FILE, "ignore_broadcast_ssid", "0");
290 }
291 else
292 {
293 ret = mbtk_wifi_set_setting(SETTING_FILE, "ignore_broadcast_ssid", "1");
294 }
295
296 if(0 > ret)
297 {
298 LOGE("qser wifi fail");
299 return LYNQ_ERR_FAIL;
300 }
301
302 return LYNQ_ERR_SUCCESS;
303}
304
305int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx,bool* hide)
306{
307 int ret = 0;
308 char value[SETTING_VALUE_MAX_LEN] = {0};
309
310 if(NULL == hide)
311 {
312 LOGE("qser wifi ptr is null");
313 return LYNQ_ERR_BADPARAM;
314 }
315
316 ret = mbtk_wifi_get_setting(SETTING_FILE, "ignore_broadcast_ssid", value, SETTING_VALUE_MAX_LEN);
317
318 if(0 > ret)
319 {
320 LOGE("qser wifi fail");
321 return LYNQ_ERR_FAIL;
322 }
323
324 if('0' == value[0])
325 {
326 *hide = true;
327 }
328 else
329 {
330 *hide = false;
331 }
332
333 return LYNQ_ERR_SUCCESS;
334}
335
336int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
337{
338 int ret = 0;
339 if(LYNQ_WIFI_MODE_80211B == mode)
340 {
341 ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211b", "1");
342 }
343 else if(LYNQ_WIFI_MODE_80211BG == mode)
344 {
345 ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211bg", "1");
346 }
347 else if(LYNQ_WIFI_MODE_80211BGN == mode)
348 {
349 ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211bgn", "1");
350 }
351 else if(LYNQ_WIFI_MODE_80211A == mode)
352 {
353 ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211a", "1");
354 }
355 else if(LYNQ_WIFI_MODE_80211AN == mode)
356 {
357 ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211an", "1");
358 }
359 else if(LYNQ_WIFI_MODE_80211AC == mode)
360 {
361 ret = mbtk_wifi_set_setting(SETTING_FILE, "ieee80211ac", "1");
362 }
363
364 if(0 > ret)
365 {
366 LOGE("qser wifi fail");
367 return LYNQ_ERR_FAIL;
368 }
369
370 return LYNQ_ERR_SUCCESS;
371}
372
373
374int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e* mode)
375{
376 int ret = 0;
377 char value[SETTING_VALUE_MAX_LEN] = {0};
378
379 if(NULL == mode)
380 {
381 LOGE("qser wifi ptr is null");
382 return LYNQ_ERR_BADPARAM;
383 }
384
385 ret = mbtk_wifi_get_setting(SETTING_FILE, "ieee80211b", value, SETTING_VALUE_MAX_LEN);
386
387 if(0 > ret)
388 {
389 LOGE("qser wifi fail");
390 return LYNQ_ERR_FAIL;
391 }
392
393 if('1' == value[0])
394 {
395 *mode = LYNQ_WIFI_MODE_80211B;
396 }
397
398 memset(value, 0, SETTING_VALUE_MAX_LEN);
399 ret = mbtk_wifi_get_setting(SETTING_FILE, "ieee80211bg", value, SETTING_VALUE_MAX_LEN);
400
401 if(0 > ret)
402 {
403 LOGE("qser wifi fail");
404 return LYNQ_ERR_FAIL;
405 }
406
407 if('1' == value[0])
408 {
409 *mode = LYNQ_WIFI_MODE_80211BG;
410 }
411
412 return LYNQ_ERR_SUCCESS;
413}
414
415
416int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
417{
418 int ret = 0;
419 if(LYNQ_WIFI_BANDWIDTH_HT20 == bandwidth)
420 {
421 ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "0");
422 }
423 else if(LYNQ_WIFI_BANDWIDTH_HT40 == bandwidth)
424 {
425 ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "1");
426 }
427 else if(LYNQ_WIFI_BANDWIDTH_HT80 == bandwidth)
428 {
429 ret = mbtk_wifi_set_setting(SETTING_FILE, "vht_oper_chwidth", "2");
430 }
431
432 if(0 > ret)
433 {
434 LOGE("qser wifi fail");
435 return LYNQ_ERR_FAIL;
436 }
437
438 return LYNQ_ERR_SUCCESS;
439
440}
441
442int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
443{
444 int ret = 0;
445 char value[SETTING_VALUE_MAX_LEN] = {0};
446
447 if(NULL == bandwidth)
448 {
449 LOGE("qser wifi ptr is null");
450 return LYNQ_ERR_BADPARAM;
451 }
452
453 ret = mbtk_wifi_get_setting(SETTING_FILE, "vht_oper_chwidth", value, SETTING_VALUE_MAX_LEN);
454
455 if(0 > ret)
456 {
457 LOGE("qser wifi fail");
458 return LYNQ_ERR_FAIL;
459 }
460
461 if('0' == value[0])
462 {
463 *bandwidth = LYNQ_WIFI_BANDWIDTH_HT20;
464 }
465 else if ('1' == value[0])
466 {
467 *bandwidth = LYNQ_WIFI_BANDWIDTH_HT40;
468 }
469 else if ('2' == value[0])
470 {
471 *bandwidth = LYNQ_WIFI_BANDWIDTH_HT80;
472 }
473
474
475 return LYNQ_ERR_SUCCESS;
476}
477
478
479int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx,const char* country_code, int channel)
480{
481 int ret = 0;
482 char value[SETTING_VALUE_MAX_LEN] = {0};
483
484 if(NULL == country_code)
485 {
486 LOGE("qser wifi ptr is null");
487 return LYNQ_ERR_BADPARAM;
488 }
489
490 ret = mbtk_wifi_set_setting(SETTING_FILE, "country_code", country_code);
491
492 if(0 > ret)
493 {
494 LOGE("qser wifi fail");
495 return LYNQ_ERR_FAIL;
496 }
497
498 sprintf(value, "%d", channel);
499 ret = mbtk_wifi_set_setting(SETTING_FILE, "channel", value);
500
501 if(0 > ret)
502 {
503 LOGE("qser wifi fail");
504 return LYNQ_ERR_FAIL;
505 }
506
507 return LYNQ_ERR_SUCCESS;
508}
509
510int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx,char* country_code, int* channel)
511{
512 int ret = 0;
513 char value[SETTING_VALUE_MAX_LEN] = {0};
514
515 if(NULL == country_code || NULL ==channel)
516 {
517 LOGE("qser wifi ptr is null");
518 return LYNQ_ERR_BADPARAM;
519 }
520
521 ret = mbtk_wifi_get_setting(SETTING_FILE, "country_code", country_code, SETTING_VALUE_MAX_LEN);
522
523 if(0 > ret)
524 {
525 LOGE("qser wifi fail");
526 return LYNQ_ERR_FAIL;
527 }
528
529 ret = mbtk_wifi_get_setting(SETTING_FILE, "channel", value, SETTING_VALUE_MAX_LEN);
530
531 if(0 > ret)
532 {
533 LOGE("qser wifi fail");
534 return LYNQ_ERR_FAIL;
535 }
536
537 *channel = atoi(value);
538 return LYNQ_ERR_SUCCESS;
539}
540
541
542int qser_wifi_ap_auth_set(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e auth_mode, const char * auth_passwd)
543{
544 int ret = 0;
545
546 if(NULL == auth_passwd)
547 {
548 LOGE("qser wifi ptr is null");
549 return LYNQ_ERR_BADPARAM;
550 }
551
552 ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa", "2");
553
554 if(0 > ret)
555 {
556 LOGE("qser wifi fail");
557 return LYNQ_ERR_FAIL;
558 }
559
560 ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa_key_mgmt", "WPA-PSK");
561
562 if(0 > ret)
563 {
564 LOGE("qser wifi fail");
565 return LYNQ_ERR_FAIL;
566 }
567
568 ret = mbtk_wifi_set_setting(SETTING_FILE, "wpa_passphrase", auth_passwd);
569
570 if(0 > ret)
571 {
572 LOGE("qser wifi fail");
573 return LYNQ_ERR_FAIL;
574 }
575
576 return LYNQ_ERR_SUCCESS;
577
578}
579
580int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char * auth_passwd)
581{
582 int ret = 0;
583
584 if(NULL == auth_mode || NULL == auth_passwd)
585 {
586 LOGE("qser wifi ptr is null");
587 return LYNQ_ERR_BADPARAM;
588 }
589
590 ret = mbtk_wifi_get_setting(SETTING_FILE, "wpa_passphrase", auth_passwd, SETTING_VALUE_MAX_LEN);
591
592 if(0 > ret)
593 {
594 LOGE("qser wifi fail");
595 return LYNQ_ERR_FAIL;
596 }
597
598 return LYNQ_ERR_SUCCESS;
599}
600
601int qser_wifi_ap_auth_get_s(lynq_wifi_ap_index_e idx, lynq_wifi_ap_auth_t* auth_mode)
602{
603 int ret = 0;
604
605 if(NULL == auth_mode)
606 {
607 LOGE("qser wifi ptr is null");
608 return LYNQ_ERR_BADPARAM;
609 }
610
611 ret = mbtk_wifi_get_setting(SETTING_FILE, "wpa_passphrase", auth_mode->passwd, SETTING_VALUE_MAX_LEN);
612
613 if(0 > ret)
614 {
615 LOGE("qser wifi fail");
616 return LYNQ_ERR_FAIL;
617 }
618
619 return LYNQ_ERR_SUCCESS;
620}
621
622
623int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
624{
625 int ret = 0;
626 char value[SETTING_VALUE_MAX_LEN] = {0};
627
628 sprintf(value, "%d", max_sta_num);
629 ret = mbtk_wifi_set_setting(SETTING_FILE, "max_num_sta", value);
630
631 if(0 > ret)
632 {
633 LOGE("qser wifi fail");
634 return LYNQ_ERR_FAIL;
635 }
636
637 return LYNQ_ERR_SUCCESS;
638}
639
640int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int* max_sta_num)
641{
642 int ret = 0;
643 char value[SETTING_VALUE_MAX_LEN] = {0};
644
645 if(NULL == max_sta_num)
646 {
647 LOGE("qser wifi ptr is null");
648 return LYNQ_ERR_BADPARAM;
649 }
650
651 ret = mbtk_wifi_get_setting(SETTING_FILE, "max_num_sta", value, SETTING_VALUE_MAX_LEN);
652
653 if(0 > ret)
654 {
655 LOGE("qser wifi fail");
656 return LYNQ_ERR_FAIL;
657 }
658
659 *max_sta_num = atoi(value);
660
661 return LYNQ_ERR_SUCCESS;
662
663}
664
665
666
667int qser_wifi_lanhost_get_list(lynq_lanhost_ts* lynq_arrays)
668{
669 if(NULL == lynq_arrays)
670 {
671 LOGE("qser wifi ptr is null");
672 return LYNQ_ERR_BADPARAM;
673 }
674
675 if(0 > mbtk_wifi_get_dhcp((mbtk_lanhost_ts*)lynq_arrays))
676 {
677 LOGE("qser wifi get lanhost fail");
678 return LYNQ_ERR_FAIL;
679 }
680
681
682 if(0 > mbkt_wifi_get_uptime((mbtk_lanhost_ts*)lynq_arrays))
683 {
684 LOGE("qser wifi get lanhost fail");
685 return LYNQ_ERR_FAIL;
686 }
687
688 return LYNQ_ERR_SUCCESS;
689}
690
691
692int qser_wifi_get_ap_pkt_stats(lynq_wifi_ap_index_e idx, lynq_wifi_pkt_stats_t *pkt_stat)
693{
694 if(NULL == pkt_stat)
695 {
696 LOGE("qser wifi ptr is null");
697 return LYNQ_ERR_BADPARAM;
698 }
699
700 if(0 > mbtk_wifi_get_pkt((mbtk_wifi_pkt_stats_t*)pkt_stat))
701 {
702 LOGE("qser wifi get pkt fail");
703 return LYNQ_ERR_FAIL;
704 }
705
706 return LYNQ_ERR_SUCCESS;
707}
708
709
710int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
711{
712 int ret = 0;
713
714 if(LYNQ_WIFI_AP_INDEX_AP0 == idx)
715 {
716 ret = qser_wifi_work_mode_set(LYNQ_WIFI_AP_INDEX_AP0);
717 }
718 else
719 {
720 ret = qser_wifi_work_mode_set(LYNQ_WIFI_AP_INDEX_AP1);
721 }
722 LOGI("qser_wifi_ap_start set hw_mode ret:%d\n", ret);
723 if(0 > ret)
724 {
725 LOGE("qser wifi fail");
726 return LYNQ_ERR_FAIL;
727 }
728
729 if(0 > mbtk_wifi_ap_start())
730 {
731 return LYNQ_ERR_FAIL;
732 }
733
734
735 g_ap_status = LYNQ_WIFI_AP_STATUS_ENABLED;
736 return LYNQ_ERR_SUCCESS;
737}
738
739int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
740{
741 if(0 > mbtk_wifi_ap_stop())
742 {
743 return LYNQ_ERR_FAIL;
744 }
745
746 g_ap_status = LYNQ_WIFI_AP_STATUS_DISABLING;
747 return LYNQ_ERR_SUCCESS;
748}
749
750int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
751{
752 if(0 > mbtk_wifi_ap_stop())
753 {
754 return LYNQ_ERR_FAIL;
755 }
756
757 if(0 > mbtk_wifi_ap_start())
758 {
759 return LYNQ_ERR_FAIL;
760 }
761
762 return LYNQ_ERR_SUCCESS;
763}
764
765int qser_wifi_register_handle(lynq_wifi_event_handle event_handle, lynq_wifi_event_handle_sta event_handle_sta, void *arg)
766{
767 if(NULL != event_handle_sta)
768 {
769 g_event_handle_sta_cb = event_handle_sta;
770
771 }
772 else
773 {
774 LOGE("qser wifi ptr is null");
775 return LYNQ_ERR_BADPARAM;
776 }
777
778 return LYNQ_ERR_SUCCESS;
779}
780
781
782int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *param_stat)
783{
784 if(NULL == param_stat)
785 {
786 LOGE("qser wifi ptr is null");
787 return LYNQ_ERR_BADPARAM;
788 }
789
790 sta_cli_ssid_set(param_stat->ssid);
791 sta_cli_psk_set(param_stat->passwd);
792 return LYNQ_ERR_SUCCESS;
793}
794
795
796int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *param_stat)
797{
798 int len = 0;
799
800 if(NULL == param_stat)
801 {
802 LOGE("qser wifi ptr is null");
803 return LYNQ_ERR_BADPARAM;
804 }
805
806 sta_cli_ssid_get(param_stat->ssid);
807 len = strlen(param_stat->ssid);
808 param_stat->ssid[len - 1] = '\0';
809 sta_cli_psk_get(param_stat->passwd);
810 len = strlen(param_stat->passwd);
811 param_stat->passwd[len - 1] = '\0';
812
813 LOGE("ssid: %s, passwd: %s", param_stat->ssid, param_stat->passwd);
814
815 return LYNQ_ERR_SUCCESS;
816}
817
818int qser_wifi_sta_start(void)
819{
820 char reply[STA_BUF_SIZE];
821
822 if(sta_cli_cmd_parse("ADD_NETWORK", reply, STA_BUF_SIZE))
823 {
824 if(strlen(reply) > 0)
825 {
826 LOGE("reply data(%s).\n",reply);
827 }else
828 {
829 LOGE("No reply data\n");
830 }
831 }
832 else
833 {
834 LOGE("Parse cmd fail.\n");
835 }
836
837
838 if(sta_cli_cmd_parse("SELECT_NETWORK", reply, STA_BUF_SIZE))
839 {
840 if(strlen(reply) > 0)
841 {
842 LOGE("reply data(%s).\n",reply);
843 }else
844 {
845 LOGE("No reply data\n");
846 }
847 }
848 else
849 {
850 LOGE("Parse cmd fail.\n");
851 }
852
853 if(sta_cli_cmd_parse("ENABLE_NETWORK", reply, STA_BUF_SIZE))
854 {
855 if(strlen(reply) > 0)
856 {
857 LOGE("reply data(%s).\n",reply);
858 }else
859 {
860 LOGE("No reply data\n");
861 }
862 }
863 else
864 {
865 LOGE("Parse cmd fail.\n");
866 }
867
868 if(0 > system("udhcpc -i wlan0"))
869 {
870 return LYNQ_ERR_FAIL;
871 }
872
873
874 return LYNQ_ERR_SUCCESS;
875}
876
877int qser_wifi_sta_stop(void)
878{
879 char reply[STA_BUF_SIZE];
880
881 if(sta_cli_cmd_parse("DISABLE_NETWORK", reply, STA_BUF_SIZE))
882 {
883 if(strlen(reply) > 0)
884 {
885 LOGE("reply data(%s).\n",reply);
886 }else
887 {
888 LOGE("No reply data\n");
889 }
890 }
891 else
892 {
893 LOGE("Parse cmd fail.\n");
894 }
895
896 if(sta_cli_cmd_parse("REMOVE_NETWORK", reply, STA_BUF_SIZE))
897 {
898 if(strlen(reply) > 0)
899 {
900 LOGE("reply data(%s).\n",reply);
901 }else
902 {
903 LOGE("No reply data\n");
904 }
905 }
906 else
907 {
908 LOGE("Parse cmd fail.\n");
909 }
910
911 return LYNQ_ERR_SUCCESS;
912}
913
914int qser_wifi_sta_get_status(lynq_wifi_sta_status_t *status_stat)
915{
916 char reply[STA_BUF_SIZE];
917 int i = 0, j = 0;
918 int status_flag = 0;
919
920 if(NULL == status_stat)
921 {
922 LOGE("qser wifi ptr is null");
923 return LYNQ_ERR_BADPARAM;
924 }
925
926 if(sta_cli_cmd_parse("STATUS", reply, STA_BUF_SIZE))
927 {
928 if(strlen(reply) > 0)
929 {
930 LOGE("reply data(%s).\n",reply);
931 }else
932 {
933 LOGE("No reply data\n");
934 }
935 }
936 else
937 {
938 LOGE("Parse cmd fail.\n");
939 }
940
941
942 for(i = 0; i < strlen(reply); i++)
943 {
944 if(',' == reply[i])
945 {
946 j = 0;
947 status_flag++;
948 continue;
949 }
950
951 if(0 == status_flag)
952 {
953 status_stat->status = 4;
954 j++;
955 }
956 else if(1 == status_flag)
957 {
958 status_stat->ap_bssid[j] = reply[i];
959 j++;
960 }
961 else if(2 == status_flag)
962 {
963 status_stat->ifname[j] = reply[i];
964 j++;
965 }
966 else if(8 == status_flag)
967 {
968 status_stat->has_addr = '1';
969 status_stat->addr[0].addr[j] = reply[i];
970 j++;
971 }
972
973
974
975 }
976 LOGE("state:%d, ap_bssid:%s, ifname:%s, has_addr:%c, addr:%s\n", status_stat->status, status_stat->ap_bssid, status_stat->ifname, status_stat->has_addr,
977 status_stat->addr[0].addr);
978
979 return LYNQ_ERR_SUCCESS;
980
981}
982
983
984int qser_wifi_get_sta_pkt_stats(lynq_wifi_pkt_stats_t *pkt_stat)
985{
986 if(NULL == pkt_stat)
987 {
988 LOGE("qser wifi ptr is null");
989 return LYNQ_ERR_BADPARAM;
990 }
991
992 if(0 > mbtk_wifi_get_pkt((mbtk_wifi_pkt_stats_t*)pkt_stat))
993 {
994 LOGE("qser wifi get pkt fail");
995 return LYNQ_ERR_FAIL;
996 }
997
998 return LYNQ_ERR_SUCCESS;
999}
1000
1001
1002int qser_wifi_sta_start_scan(void)
1003{
1004 char reply[STA_BUF_SIZE] = {0};
1005 lynq_wifi_sta_scan_list_t scan_list = {0};
1006 int i = 0, j = 0;
1007 int status_flag = 0;
1008
1009 if(sta_cli_cmd_parse("SCAN", reply, STA_BUF_SIZE))
1010 {
1011 if(strlen(reply) > 0)
1012 {
1013 LOGE("reply data(%s).\n",reply);
1014 }else
1015 {
1016 LOGE("No reply data\n");
1017 }
1018 }
1019 else
1020 {
1021 LOGE("Parse cmd fail.\n");
1022 }
1023
1024
1025
1026 scan_list.cnt = 1;
1027
1028 for(i = 0; i < strlen(reply); i++)
1029 {
1030 if(',' == reply[i])
1031 {
1032 j = 0;
1033 status_flag++;
1034 continue;
1035 }
1036
1037 if(0 == status_flag)
1038 {
1039 scan_list.info[0].bssid[j] = reply[i];
1040 j++;
1041 }
1042 else if(1 == status_flag)
1043 {
1044 //scan_list.info[0].bssid = reply[i];
1045 j++;
1046 }
1047 else if(2 == status_flag)
1048 {
1049 //scan_list.info[0].signal = atoi(reply[i]);
1050 j++;
1051 }
1052 else if(4 == status_flag)
1053 {
1054 scan_list.info[0].essid[j] = reply[i];
1055 j++;
1056 }
1057
1058
1059
1060 }
1061
1062
1063
1064 g_event_handle_sta_cb(&scan_list);
1065 return LYNQ_ERR_SUCCESS;
1066}
1067
1068/*
1069 void lynq_wifi_event_handle_demo(lynq_wifi_event_s *event, void *arg)
1070 {
1071 if(event->id == LYNQ_WIFI_EVENT_AP_STATION)
1072 LOGE("[lynq-wifi-demo] %s:event-id = %d- %d\n", __func__, event->id, event->status);
1073 else if(event->id == LYNQ_WIFI_EVENT_AP_STA_STATUS)
1074 LOGE("[lynq-wifi-demo] %s:event-id = %d,%d,%s,%s\n", __func__, event->id,
1075 event->ap_sta_info.connected, event->ap_sta_info.mac,event->ap_sta_info.hostname);
1076 if(event->id == LYNQ_WIFI_EVENT_STA_STATUS)
1077 LOGE("[lynq-wifi-demo] %s:event-id = %d- %d\n", __func__, event->id, event->status);
1078 else
1079 return;
1080 }
1081 */
1082
1083 void lynq_wifi_event_handle_sta_demo(lynq_wifi_sta_scan_list_t *event)
1084 {
1085 int i = 0;
1086 if(NULL == event)
1087 {
1088 LOGE("qser wifi ptr is null");
1089 return;
1090 }
1091
1092 for (i = 0; i < event->cnt; i++)
1093 {
1094 LOGE("[lynq-wifi-demo] %s : ap[%d]:%s,%d,%d,%d,%s,%d,%d,%d\n", __func__, i,
1095 event->info[i].essid, event->info[i].auth,
1096 event->info[i].cipher, event->info[i].channel, event->info[i].bssid,
1097 event->info[i].signal_level,event->info[i].frequency,event->info[i].signal);
1098 }
1099 }
1100
1101
1102
1103