blob: 664fcbe1e3dd0a5360131efa10a27f6ed1254402 [file] [log] [blame]
wz.wang73504132024-03-19 16:38:37 +08001#include <stdint.h>
2#include <stdio.h>
3#include <string.h>
wz.wange5a0b912024-03-22 19:11:59 +08004#include "liblog/lynq_deflog.h"
wz.wang73504132024-03-19 16:38:37 +08005
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#include "sc_tel_types.h"
11#include "sc_wifi.h"
12#include "lynq-qser-wifi.h"
13
wz.wang9f658672024-04-15 14:23:58 +080014static lynq_wifi_event_handle wifi_event_handle = NULL;
15static void *global_arg = NULL;
16static lynq_wifi_event_s global_event ;
17
18/********************************************************************
19* @brief: lynq_to_sc_auth_mode, The encryption mode of wifi is changed from api to platform
20* @return : NA
21* @todo: NA
22* @see: NA
23* @warning: NA
24*********************************************************************/
25static sc_wifi_auth_e lynq_to_sc_auth_mode(lynq_wifi_auth_e auth_mode)
26{
27 sc_wifi_auth_e type;
28 switch (auth_mode)
29 {
30 case LYNQ_WIFI_AUTH_OPEN:
31 type = SC_WIFI_AUTH_OPEN;
32 break;
33 case LYNQ_WIFI_AUTH_WPA2_PSK:
34 type = SC_WIFI_AUTH_WPA2_PSK;
35 break;
36 case LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
37 type = SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
38 break;
39 case LYNQ_WIFI_AUTH_WPA3_PSK:
40 type = SC_WIFI_AUTH_WPA3_PSK;
41 break;
42 case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
43 type = SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
44 break;
45 default:
46 type = SC_WIFI_AUTH_MIN;
47 break;
48 }
49 return type;
50}
51
52/********************************************************************
53* @brief: sc_to_lynq_auth_mode, The encryption mode of wifi is changed from platform to api
54* @return : NA
55* @todo: NA
56* @see: NA
57* @warning: NA
58*********************************************************************/
59static lynq_wifi_auth_e sc_to_lynq_auth_mode(sc_wifi_auth_e auth_mode)
60{
61 lynq_wifi_auth_e type;
62 switch (auth_mode)
63 {
64 case SC_WIFI_AUTH_OPEN:
65 type = LYNQ_WIFI_AUTH_OPEN;
66 break;
67 case SC_WIFI_AUTH_WPA2_PSK:
68 type = LYNQ_WIFI_AUTH_WPA2_PSK;
69 break;
70 case SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
71 type = LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
72 break;
73 case SC_WIFI_AUTH_WPA3_PSK:
74 type = LYNQ_WIFI_AUTH_WPA3_PSK;
75 break;
76 case SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
77 type = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
78 break;
79 default:
80 type = LYNQ_WIFI_AUTH_MIN;
81 break;
82 }
83 return type;
84}
85
86/********************************************************************
87* @brief: lynq_user_status, wifi startup callback
88* @return : NA
89* @todo: NA
90* @see: NA
91* @warning: NA
92*********************************************************************/
93static void lynq_user_status(sc_wifi_enable_status_e pre_status, sc_wifi_enable_status_e status)
94{
95 LYINFLOG("%s:%d,%d\n", __func__, pre_status, status);
96}
97
98/********************************************************************
99* @brief: lynq_user_wifi_service_error, wifi service status callback
100* @return : NA
101* @todo: NA
102* @see: NA
103* @warning: NA
104*********************************************************************/
105static void lynq_user_wifi_service_error(int error)
106{
107 LYINFLOG("%s: %d\n", __func__, error);
108}
109
110/********************************************************************
111* @brief: lynq_user_ap_status, wifi Obtains the ap status callback
112* @return : NA
113* @todo: NA
114* @see: NA
115* @warning: NA
116*********************************************************************/
117static void lynq_user_ap_status(sc_wifi_ap_index_e index, sc_wifi_ap_status_e pre_status, sc_wifi_ap_status_t *p_msg)
118{
119 if(wifi_event_handle != NULL && global_arg != NULL)
120 {
121 global_event.idx = (lynq_wifi_ap_index_e)index;
122 global_event.status = (lynq_wifi_status_e)pre_status;
123 wifi_event_handle(&global_event, global_arg);
124 }
125 else{
126 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
127 }
128
129}
130
131/********************************************************************
132* @brief: lynq_user_ap_sta_conn_status, wifi as ap is sta information callback
133* @return : NA
134* @todo: NA
135* @see: NA
136* @warning: NA
137*********************************************************************/
138static void lynq_user_ap_sta_conn_status(sc_wifi_ap_index_e index, sc_wifi_sta_connect_status_t *p_msg)
139{
140 if(wifi_event_handle != NULL && global_arg != NULL)
141 {
142 global_event.idx = (lynq_wifi_ap_index_e)index;
143 global_event.ap_sta_info.connected = p_msg->is_connected;
144 strncpy(global_event.ap_sta_info.mac, p_msg->macaddr,
145 sizeof(global_event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(global_event.ap_sta_info.mac):sizeof(p_msg->macaddr));
146 wifi_event_handle(&global_event, global_arg);
147 }
148 else{
149 LYINFLOG("%s:%d,%d,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr);
150 }
151
152}
153
154/********************************************************************
155* @brief: print_sta_status, wifi gets the status callback in sta mode
156* @return : NA
157* @todo: NA
158* @see: NA
159* @warning: NA
160*********************************************************************/
161static void print_sta_status(sc_wifi_sta_status_t *p_msg)
162{
163 LYINFLOG("%s: %d, %s, %s, %d, %d\n", __func__, p_msg->status, p_msg->ifname, p_msg->ap_bssid,
164 p_msg->signal_level, p_msg->reason_code);
165
166 if (p_msg->has_addr == 1) {
167 char addrtxt[48] = {0};
168 inet_ntop(AF_INET, &p_msg->addr, addrtxt, sizeof(addrtxt));
169 LYINFLOG("%s : addr inet_ntop: %s\n", __func__, addrtxt);
170
171 LYINFLOG("%s : addr: %08X\n", __func__, p_msg->addr.s_addr);
172 }
173
174 if (p_msg->has_addr6 == 1) {
175 char addrtxt[48] = {0};
176 inet_ntop(AF_INET6, &p_msg->addr6, addrtxt, sizeof(addrtxt));
177 LYINFLOG("%s : addr6 inet_ntop: %s\n", __func__, addrtxt);
178
179 LYINFLOG("%s : addr6: %02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X\n",__func__,
180 p_msg->addr6.s6_addr[0], p_msg->addr6.s6_addr[1], p_msg->addr6.s6_addr[2], p_msg->addr6.s6_addr[3],
181 p_msg->addr6.s6_addr[4], p_msg->addr6.s6_addr[5], p_msg->addr6.s6_addr[6], p_msg->addr6.s6_addr[7],
182 p_msg->addr6.s6_addr[8], p_msg->addr6.s6_addr[9], p_msg->addr6.s6_addr[10], p_msg->addr6.s6_addr[11],
183 p_msg->addr6.s6_addr[12], p_msg->addr6.s6_addr[13], p_msg->addr6.s6_addr[14], p_msg->addr6.s6_addr[15]);
184 }
185 LYINFLOG("%s : sta_status end\n",__func__);
186}
187
188/********************************************************************
189* @brief: lynq_user_sta_status_ind, wifi gets the status callback in sta mode
190* @return : NA
191* @todo: NA
192* @see: NA
193* @warning: NA
194*********************************************************************/
195static void lynq_user_sta_status_ind(sc_wifi_sta_status_e pre_status,
196 sc_wifi_sta_status_t *p_msg)
197{
198 LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
199 print_sta_status(p_msg);
200}
201
202/********************************************************************
203* @brief: lynq_user_sta_scan_result_ind, wifi gets the callback of sta mode traversing the hotspot
204* @return : NA
205* @todo: NA
206* @see: NA
207* @warning: NA
208*********************************************************************/
209static void lynq_user_sta_scan_result_ind(sc_wifi_sta_scan_list_t *p_msg)
210{
211 int i = 0;
212 LYINFLOG("%s : user_sta_scan_result_ind_cb:%d\n", __func__, p_msg->cnt);
213 if (p_msg->cnt <= 0) {
214 return;
215 }
216 for (i = 0; i < p_msg->cnt; i++) {
217 LYINFLOG("%s : ap[%d]:%s,%d,%d,%d,%s,%d\n", __func__, i, p_msg->info[i].essid, sc_to_lynq_auth_mode(p_msg->info[i].auth),
218 p_msg->info[i].cipher, p_msg->info[i].channel, p_msg->info[i].bssid, p_msg->info[i].signal_level);
219 }
220}
221
222/********************************************************************
223* @brief: qser_wifi_register_handle, Register callback functions
224* @return :int, If equal to 0 succeeds, others fail
225* @todo: NA
226* @see: NA
227* @warning: NA
228*********************************************************************/
229int qser_wifi_register_handle(lynq_wifi_event_handle event_handle, void *arg)
230{
231 if(event_handle == NULL || arg == NULL)
232 {
233 LYERRLOG("[%s ] NUll pointer event_handle = 0x%p arg = 0x%p\n", __func__, event_handle, arg);
234 return -1;
235 }
236 wifi_event_handle = event_handle;
237 global_arg = arg;
238 return 0;
239}
240
wz.wang73504132024-03-19 16:38:37 +0800241/********************************************************************
242* @brief: qser_wifi_enable, Enable WiFi function
243* @return : int, If equal to 0 succeeds, others fail
244* @todo: NA
245* @see: NA
246* @warning: NA
247*********************************************************************/
248int qser_wifi_enable(void)
249{
wz.wange5a0b912024-03-22 19:11:59 +0800250 int ret = -1;
251 ret = sc_wifi_init();
wz.wang73504132024-03-19 16:38:37 +0800252 if (0 != ret)
253 {
wz.wang9f658672024-04-15 14:23:58 +0800254 LYERRLOG("[%s ] init wifi ret = %d fail\n", __func__,ret);
255 return ret;
256 }
257
258 //wifi
259 ret = sc_wifi_set_enable_status_ind_cb(lynq_user_status);
260 if (0 != ret)
261 {
262 LYERRLOG("[%s ] Request lynq_user_status ret = %d fail\n", __func__,ret);
263 return ret;
264 }
265
266 //ap
267 ret = sc_wifi_ap_set_status_ind_cb(lynq_user_ap_status);
268 if (0 != ret)
269 {
270 LYERRLOG("[%s ] Request lynq_user_ap_status ret = %d fail\n", __func__,ret);
271 return ret;
272 }
273 ret = sc_wifi_set_ap_sta_connect_ind_cb(lynq_user_ap_sta_conn_status);
274 if (0 != ret)
275 {
276 LYERRLOG("[%s ] Request lynq_user_ap_sta_conn_status ret = %d fail\n", __func__,ret);
277 return ret;
278 }
279
280 //sta
281 ret = sc_wifi_sta_set_status_ind_cb(lynq_user_sta_status_ind);
282 if (0 != ret)
283 {
284 LYERRLOG("[%s ] Request lynq_user_sta_status_ind ret = %d fail\n", __func__,ret);
285 return ret;
286 }
287 ret = sc_wifi_sta_set_scan_result_ind_cb(lynq_user_sta_scan_result_ind);
288 if (0 != ret)
289 {
290 LYERRLOG("[%s ] Request lynq_user_sta_scan_result_ind ret = %d fail\n", __func__,ret);
291 return ret;
292 }
293 //proxy
294 ret = sc_wifi_set_service_error_cb(lynq_user_wifi_service_error);
295 if (0 != ret)
296 {
297 LYERRLOG("[%s ] Request lynq_user_wifi_service_error ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800298 return ret;
wz.wang73504132024-03-19 16:38:37 +0800299 }
wz.wange5a0b912024-03-22 19:11:59 +0800300
301 ret = sc_wifi_enable();
302 if (0 != ret)
303 {
wz.wang9f658672024-04-15 14:23:58 +0800304 LYERRLOG("[%s ] enable wifi ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800305 return ret;
306 }
307 LYINFLOG("[%s ]\n", __func__);
308 return 0;
wz.wang73504132024-03-19 16:38:37 +0800309}
310
311/********************************************************************
312* @brief: qser_wifi_disable, Turn off WiFi
313* @return : int, If equal to 0 succeeds, others fail
314* @todo: NA
315* @see: NA
316* @warning: NA
317*********************************************************************/
318int qser_wifi_disable(void)
319{
wz.wange5a0b912024-03-22 19:11:59 +0800320 int ret = -1;
321 ret = sc_wifi_disable();
wz.wang73504132024-03-19 16:38:37 +0800322 if (0 != ret)
323 {
wz.wange5a0b912024-03-22 19:11:59 +0800324 LYERRLOG("[%s ] disable : %d ret = %d\n", __func__,ret);
325 return ret;
wz.wang73504132024-03-19 16:38:37 +0800326 }
wz.wange5a0b912024-03-22 19:11:59 +0800327
328 ret = sc_wifi_uninit();
329 if (0 != ret)
330 {
331 LYERRLOG("[%s ] uninit: %d ret = %d\n", __func__,ret);
332 return ret;
333 }
334 LYINFLOG("[%s ]\n", __func__);
335 return 0;
wz.wang73504132024-03-19 16:38:37 +0800336}
337
338/********************************************************************
339* @brief: qser_wifi_ap_ssid_set, Set the name of the ssid of wlan0 or wlan1
340* @param idx [IN]: int, Set wlan0 or wlan1
341* @param ssid [IN]: const char *, Set the ssid name
342* @return : int, If equal to 0 succeeds, others fail
343* @todo: NA
344* @see: NA
345* @warning: NA
346*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800347int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
wz.wang73504132024-03-19 16:38:37 +0800348{
wz.wange5a0b912024-03-22 19:11:59 +0800349 int ret = -1;
350 if (ssid == NULL)
351 {
352 LYERRLOG("[%s ] Null pointer ssid = 0x%p \n", __func__, ssid);
353 return ret;
354 }
355 ret = sc_wifi_ap_ssid_set((sc_wifi_ap_index_e)idx, ssid);
356 if (0 != ret)
357 {
358 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
359 return ret;
360 }
361 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, ssid);
362 return 0;
363}
364
365/********************************************************************
366* @brief: qser_wifi_ap_ssid_get, Get the name of the ssid of wlan0 or wlan1
367* @param idx [IN]: int, Set wlan0 or wlan1
368* @param ssid [OUT]: char *, Get the ssid name
369* @return : int, If equal to 0 succeeds, others fail
370* @todo: NA
371* @see: NA
372* @warning: NA
373*********************************************************************/
374int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
375{
376 int ret = -1;
377 sc_wifi_ap_param_t param = {0};
378 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
379 if (0 != ret)
380 {
381 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
382 return ret;
383 }
384 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, param.ssid);
385 strncpy(ssid, param.ssid, sizeof(param.ssid) - 1);
386 return 0;
wz.wang73504132024-03-19 16:38:37 +0800387}
388
389/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +0800390* @brief: qser_wifi_ap_ssid_hide_set, Set whether the ssid of wlan0 or wlan1 is hidden
391* @param idx [IN]: int, Set wlan0 or wlan1
392* @param hide [IN]: bool, Set whether the ssid is hidden
393* @return : int, If equal to 0 succeeds, others fail
394* @todo: NA
395* @see: NA
396* @warning: NA
397*********************************************************************/
398int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx, bool hide)
399{
400 int ret = -1;
401 ret = sc_wifi_ap_ssid_hidden_set((sc_wifi_ap_index_e)idx, (int)hide);
402 if (0 != ret)
403 {
404 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
405 return ret;
406 }
407 LYINFLOG("[%s ] idx = %d hide = %d \n", __func__, idx, hide);
408 return 0;
409}
410
411/********************************************************************
412* @brief: qser_wifi_ap_ssid_hide_get, Get whether the ssid of wlan0 or wlan1 is hidden
413* @param idx [IN]: int, Set wlan0 or wlan1
414* @param hide [OUT]: bool *, Get whether the ssid is hidden
415* @return : int, If equal to 0 succeeds, others fail
416* @todo: NA
417* @see: NA
418* @warning: NA
419*********************************************************************/
420int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx, bool *hide)
421{
422 int ret = -1;
423 sc_wifi_ap_param_t param = {0};
424 if (hide == NULL)
425 {
426 LYERRLOG("[%s ] Null pointer hide = 0x%p \n", __func__, hide);
427 return ret;
428 }
429 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
430 if (0 != ret)
431 {
432 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
433 return ret;
434 }
435 LYINFLOG("[%s ] idx = %d ssid_hide = %d \n", __func__, idx, param.ssid_hide);
436 *hide = (bool)param.ssid_hide;
437 return 0;
438}
439
440/********************************************************************
wz.wang73504132024-03-19 16:38:37 +0800441* @brief: qser_wifi_ap_mode_set, Set the working protocol mode of wlan0 or wlan1
442* @param idx [IN]: int, Set wlan0 or wlan1
443* @param mode [IN]: lynq_wifi_mode_type_e, Set the working protocol mode
444* @return : int, If equal to 0 succeeds, others fail
445* @todo: NA
446* @see: NA
447* @warning: NA
448*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800449int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
wz.wang73504132024-03-19 16:38:37 +0800450{
wz.wange5a0b912024-03-22 19:11:59 +0800451 int ret = -1;
wz.wang73504132024-03-19 16:38:37 +0800452 sc_wifi_ap_mode_type_e type;
453 switch(mode)
454 {
455 case LYNQ_WIFI_MODE_80211BGN:
456 type = SC_WIFI_AP_MODE_80211BGN;
457 break;
458 case LYNQ_WIFI_MODE_80211BGNAX_2G:
459 type = SC_WIFI_AP_MODE_80211BGNAX_2G;
460 break;
461 default:
462 type = SC_WIFI_AP_MODE_MIN;
463 break;
464 }
wz.wange5a0b912024-03-22 19:11:59 +0800465 ret = sc_wifi_ap_mode_set((sc_wifi_ap_index_e)idx, type);
466 if (0 != ret)
467 {
468 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
469 return ret;
470 }
471 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, mode);
472 return 0;
473}
474
475/********************************************************************
476* @brief: qser_wifi_ap_mode_get, Get the working protocol mode of wlan0 or wlan1
477* @param idx [IN]: int, Set wlan0 or wlan1
478* @param mode [OUT]: lynq_wifi_mode_type_e *, Get the working protocol mode
479* @return : int, If equal to 0 succeeds, others fail
480* @todo: NA
481* @see: NA
482* @warning: NA
483*********************************************************************/
484int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e *mode)
485{
486 int ret = -1;
487 sc_wifi_ap_param_t param = {0};
488 if (mode == NULL)
489 {
490 LYERRLOG("[%s ] Null pointer mode = 0x%p \n", __func__, mode);
491 return ret;
492 }
493 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
494 if (0 != ret)
495 {
496 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
497 return ret;
498 }
499 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, param.mode);
500 lynq_wifi_mode_type_e type;
501 switch(param.mode)
502 {
503 case SC_WIFI_AP_MODE_80211BGN:
504 type = LYNQ_WIFI_MODE_80211BGN;
505 break;
506 case SC_WIFI_AP_MODE_80211BGNAX_2G:
507 type = LYNQ_WIFI_MODE_80211BGNAX_2G;
508 break;
509 default:
510 type = LYNQ_WIFI_MODE_MIN;
511 break;
512 }
513 *mode = type;
514 return 0;
wz.wang73504132024-03-19 16:38:37 +0800515}
516
517/********************************************************************
518* @brief: qser_wifi_ap_bandwidth_set, Set the bandwidth of wlan0 or wlan1
519* @param idx [IN]: int, Set wlan0 or wlan1
520* @param bandwidth [IN]: lynq_wifi_bandwidth_type_e, Set the bandwidth
521* @return : int, If equal to 0 succeeds, others fail
522* @todo: NA
523* @see: NA
524* @warning: NA
525*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800526int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
wz.wang73504132024-03-19 16:38:37 +0800527{
wz.wange5a0b912024-03-22 19:11:59 +0800528 int ret = -1;
529 ret = sc_wifi_ap_bandwidth_set((sc_wifi_ap_index_e)idx, (sc_wifi_bandwidth_e)bandwidth);
530 if (0 != ret)
531 {
532 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
533 return ret;
534 }
535 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, bandwidth);
536 return 0;
537}
538
539/********************************************************************
540* @brief: qser_wifi_ap_bandwidth_get, Get the bandwidth of wlan0 or wlan1
541* @param idx [IN]: int, Set wlan0 or wlan1
542* @param bandwidth [OUT]: lynq_wifi_bandwidth_type_e *, Get the bandwidth
543* @return : int, If equal to 0 succeeds, others fail
544* @todo: NA
545* @see: NA
546* @warning: NA
547*********************************************************************/
548int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
549{
550 int ret = -1;
551 sc_wifi_ap_param_t param = {0};
552 if (bandwidth == NULL)
553 {
554 LYERRLOG("[%s ] Null pointer bandwidth = 0x%p \n", __func__, bandwidth);
555 return ret;
556 }
557 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
558 if (0 != ret)
559 {
560 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
561 return ret;
562 }
563 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, param.bandwidth);
564 *bandwidth = (lynq_wifi_bandwidth_type_e)param.bandwidth;
565 return 0;
wz.wang73504132024-03-19 16:38:37 +0800566}
567
568/********************************************************************
569* @brief: qser_wifi_ap_channel_set, Set the channel for wlan0 or wlan1
570* @param idx [IN]: int, Set wlan0 or wlan1
571* @param country_code [IN]: const char *, Set country code
572* @param channel [IN]: int, Set the channel
573* @return : int, If equal to 0 succeeds, others fail
574* @todo: NA
575* @see: NA
576* @warning: NA
577*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800578int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx, const char *country_code, int channel)
wz.wang73504132024-03-19 16:38:37 +0800579{
wz.wange5a0b912024-03-22 19:11:59 +0800580 int ret = -1;
581 if (country_code == NULL)
582 {
583 LYERRLOG("[%s ] Null pointer country_code = 0x%p \n", __func__, country_code);
584 return ret;
585 }
586 ret = sc_wifi_ap_cc_ch_set((sc_wifi_ap_index_e)idx, country_code, channel);
587 if (0 != ret)
588 {
589 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
590 return ret;
591 }
592 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, country_code, channel);
593 return 0;
594}
595
596/********************************************************************
597* @brief: qser_wifi_ap_channel_get, Get the channel for wlan0 or wlan1
598* @param idx [IN]: int, Set wlan0 or wlan1
599* @param country_code [OUT]: char *, Get country code
600* @param channel [OUT]: int *, Get the channel
601* @return : int, If equal to 0 succeeds, others fail
602* @todo: NA
603* @see: NA
604* @warning: NA
605*********************************************************************/
606int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx, char *country_code, int *channel)
607{
608 int ret = -1;
609 sc_wifi_ap_param_t param = {0};
610 if (country_code == NULL || channel == NULL)
611 {
612 LYERRLOG("[%s ] Null pointer country_code = 0x%p channel = 0x%p\n", __func__, country_code, channel);
613 return ret;
614 }
615 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
616 if (0 != ret)
617 {
618 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
619 return ret;
620 }
621 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, param.countrycode, param.channel);
622 strncpy(country_code, param.countrycode, sizeof(param.countrycode) - 1);
623 *channel = param.channel;
624 return 0;
wz.wang73504132024-03-19 16:38:37 +0800625}
626
627/********************************************************************
628* @brief: qser_wifi_ap_auth_set, Set the security authentication mode and password of wlan0 or wlan1
629* @param idx [IN]: int, Set wlan0 or wlan1
630* @param auth_mode [IN]: lynq_wifi_auth_e, Set the security authentication mode
631* @param auth_passwd [IN]: const char *, Set password
632* @return : int, If equal to 0 succeeds, others fail
633* @todo: NA
634* @see: NA
635* @warning: NA
636*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800637int qser_wifi_ap_auth_set(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e auth_mode, const char *auth_passwd)
wz.wang73504132024-03-19 16:38:37 +0800638{
wz.wange5a0b912024-03-22 19:11:59 +0800639 int ret = -1;
wz.wange5a0b912024-03-22 19:11:59 +0800640 if (auth_passwd == NULL)
641 {
642 LYERRLOG("[%s ] Null pointer auth_passwd = 0x%p\n", __func__, auth_passwd);
643 return ret;
644 }
wz.wang9f658672024-04-15 14:23:58 +0800645
wz.wang73504132024-03-19 16:38:37 +0800646 sc_wifi_ap_auth_t auth;
wz.wang9f658672024-04-15 14:23:58 +0800647 auth.auth = lynq_to_sc_auth_mode(auth_mode);
wz.wang73504132024-03-19 16:38:37 +0800648 strncpy(auth.passwd, auth_passwd, sizeof(auth.passwd) - 1);
wz.wange5a0b912024-03-22 19:11:59 +0800649 ret = sc_wifi_ap_auth_set((sc_wifi_ap_index_e)idx, &auth);
650 if (0 != ret)
651 {
652 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
653 return ret;
654 }
wz.wang9f658672024-04-15 14:23:58 +0800655 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s\n", __func__, idx, auth_mode, "******");
wz.wange5a0b912024-03-22 19:11:59 +0800656 return 0;
657}
658
659/********************************************************************
660* @brief: qser_wifi_ap_auth_get, Get the security authentication mode and password of wlan0 or wlan1
661* @param idx [IN]: int, Set wlan0 or wlan1
662* @param auth_mode [OUT]: lynq_wifi_auth_e *, Get the security authentication mode
663* @param auth_passwd [OUT]: char *, Get password
664* @return : int, If equal to 0 succeeds, others fail
665* @todo: NA
666* @see: NA
667* @warning: NA
668*********************************************************************/
669int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char *auth_passwd)
670{
671 int ret = -1;
672 sc_wifi_ap_param_t param = {0};
673 if (auth_mode == NULL || auth_passwd == NULL)
674 {
675 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p auth_passwd = 0x%p\n", __func__, auth_mode, auth_passwd);
676 return ret;
677 }
678 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
679 if (0 != ret)
680 {
681 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
682 return ret;
683 }
684 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s \n", __func__, idx, param.auth.auth, param.auth.passwd);
685 strncpy(auth_passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
wz.wang9f658672024-04-15 14:23:58 +0800686
687 *auth_mode = sc_to_lynq_auth_mode(param.auth.auth);
wz.wange5a0b912024-03-22 19:11:59 +0800688 return 0;
wz.wang73504132024-03-19 16:38:37 +0800689}
690
691/********************************************************************
692* @brief: qser_wifi_ap_max_sta_set, Set the maximum number of STAs for wlan0 or wlan1
693* @param idx [IN]: int, Set wlan0 or wlan1
694* @param max_sta_num [IN]: int, Set the maximum number
695* @return : int, If equal to 0 succeeds, others fail
696* @todo: NA
697* @see: NA
698* @warning: NA
699*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800700int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
wz.wang73504132024-03-19 16:38:37 +0800701{
wz.wange5a0b912024-03-22 19:11:59 +0800702 int ret = -1;
703 ret = sc_wifi_ap_max_sta_num_set((sc_wifi_ap_index_e)idx, max_sta_num);
704 if (0 != ret)
705 {
706 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
707 return ret;
708 }
709 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, max_sta_num);
710 return 0;
711}
712
713/********************************************************************
714* @brief: qser_wifi_ap_max_sta_get, Get the maximum number of STAs for wlan0 or wlan1
715* @param idx [IN]: int, Set wlan0 or wlan1
716* @param max_sta_num [OUT]: int *, Get the maximum number
717* @return : int, If equal to 0 succeeds, others fail
718* @todo: NA
719* @see: NA
720* @warning: NA
721*********************************************************************/
722int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int *max_sta_num)
723{
724 int ret = -1;
725 sc_wifi_ap_param_t param = {0};
726 if (max_sta_num == NULL)
727 {
728 LYERRLOG("[%s ] Null pointer max_sta_num = 0x%p\n", __func__,max_sta_num);
729 return ret;
730 }
731 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
732 if (0 != ret)
733 {
734 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
735 return ret;
736 }
737 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, param.max_sta_num);
738 *max_sta_num = param.max_sta_num;
739 return 0;
wz.wang73504132024-03-19 16:38:37 +0800740}
741
742/********************************************************************
743* @brief: qser_wifi_ap_start, Set the ap mode of wlan0 or wlan1 to enable
744* @param idx [IN]: int, Set wlan0 or wlan1
745* @return : int, If equal to 0 succeeds, others fail
746* @todo: NA
747* @see: NA
748* @warning: NA
749*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800750int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +0800751{
wz.wange5a0b912024-03-22 19:11:59 +0800752 int ret = -1;
753 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
754 if (0 != ret)
755 {
756 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
757 return ret;
758 }
759 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
760 return 0;
wz.wang73504132024-03-19 16:38:37 +0800761}
762
763/********************************************************************
764* @brief: qser_wifi_ap_stop, Disable ap mode for wlan0 or wlan1
765* @param idx [IN]: int, Set wlan0 or wlan1
766* @return : int, If equal to 0 succeeds, others fail
767* @todo: NA
768* @see: NA
769* @warning: NA
770*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800771int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +0800772{
wz.wange5a0b912024-03-22 19:11:59 +0800773 int ret = -1;
774 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
775 if (0 != ret)
776 {
777 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
778 return ret;
779 }
780 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
781 return 0;
wz.wang73504132024-03-19 16:38:37 +0800782}
783
784/********************************************************************
785* @brief: qser_wifi_ap_restart, Set the ap mode of wlan0 or wlan1 to restart
786* @param idx [IN]: int, Set wlan0 or wlan1
787* @return : int, If equal to 0 succeeds, others fail
788* @todo: NA
789* @see: NA
790* @warning: NA
791*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800792int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +0800793{
wz.wange5a0b912024-03-22 19:11:59 +0800794 int ret = -1;
795 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
wz.wang73504132024-03-19 16:38:37 +0800796 if (0 != ret)
797 {
wz.wang9f658672024-04-15 14:23:58 +0800798 LYERRLOG("[%s ] stop ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800799 return ret;
wz.wang73504132024-03-19 16:38:37 +0800800 }
wz.wange5a0b912024-03-22 19:11:59 +0800801 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
802 if (0 != ret)
803 {
wz.wang9f658672024-04-15 14:23:58 +0800804 LYERRLOG("[%s ] start ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800805 return ret;
806 }
807 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
808 return 0;
wz.wang73504132024-03-19 16:38:37 +0800809}
810
wz.wang9f658672024-04-15 14:23:58 +0800811/********************************************************************
812* @brief: qser_wifi_sta_param_set, Set the ssid and password that you need to connect to the access point
813* @param lynq_stat [IN]: sc_wifi_sta_param_t *, Set parameters such as ssid and password that you want to connect to the access point
814* @return : int, If equal to 0 succeeds, others fail
815* @todo: NA
816* @see: NA
817* @warning: NA
818*********************************************************************/
819int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *lynq_stat)
820{
821 int ret = -1;
822 sc_wifi_sta_param_t stat = {0};
823 stat.auth = lynq_to_sc_auth_mode(lynq_stat->auth);
824 stat.pairwise = (sc_wifi_auth_wpa_psk_e )lynq_stat->pairwise;
825 strncpy(stat.ssid, lynq_stat->ssid, sizeof(stat.ssid));
826 strncpy(stat.passwd, lynq_stat->passwd, sizeof(stat.passwd));
827 ret = sc_wifi_sta_param_set(&stat);
828 if (0 != ret)
829 {
830 LYERRLOG("[%s ] sta_param_set ret = %d\n", __func__,ret);
831 return ret;
832 }
833 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
834 return 0;
835}
836
837/********************************************************************
838* @brief: qser_wifi_sta_param_get, Get the ssid and password that you need to connect to the access point
839* @param lynq_stat [OUT]: sc_wifi_sta_param_t *, Get parameters such as ssid and password that you want to connect to the access point
840* @return : int, If equal to 0 succeeds, others fail
841* @todo: NA
842* @see: NA
843* @warning: NA
844*********************************************************************/
845int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *lynq_stat)
846{
847 int ret = -1;
848 sc_wifi_sta_param_t stat = {0};
849 ret = sc_wifi_sta_param_get(&stat);
850 if (0 != ret)
851 {
852 LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__,ret);
853 return ret;
854 }
855 lynq_stat->auth = sc_to_lynq_auth_mode(stat.auth);
856 lynq_stat->pairwise = (lynq_wifi_auth_wpa_psk_e )stat.pairwise;
857 strncpy(lynq_stat->ssid, stat.ssid, sizeof(stat.ssid));
858 strncpy(lynq_stat->passwd, stat.passwd, sizeof(stat.passwd));
859 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
860 return 0;
861}
862
863/********************************************************************
864* @brief: qser_wifi_sta_start_scan, Scan for ap nodes and return them through callback
865* @return : int, If equal to 0 succeeds, others fail
866* @todo: NA
867* @see: NA
868* @warning: NA
869*********************************************************************/
870int qser_wifi_sta_start_scan(void)
871{
872 int ret = -1;
873 ret = sc_wifi_sta_start_scan();
874 if (0 != ret)
875 {
876 LYERRLOG("[%s ] scan ret = %d\n", __func__,ret);
877 return ret;
878 }
879 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
880 return 0;
881}
882
883/********************************************************************
884* @brief: qser_wifi_sta_start, To enable sta mode, you need to enable ap mode first
885* @return : int, If equal to 0 succeeds, others fail
886* @todo: NA
887* @see: NA
888* @warning: NA
889*********************************************************************/
890int qser_wifi_sta_start(void)
891{
892 int ret = -1;
893 ret = sc_wifi_sta_start();
894 if (0 != ret)
895 {
896 LYERRLOG("[%s ] sta_start ret = %d\n", __func__,ret);
897 return ret;
898 }
899 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
900 return 0;
901}
902
903/********************************************************************
904* @brief: qser_wifi_sta_stop, To disable sta mode.
905* @return : int, If equal to 0 succeeds, others fail
906* @todo: NA
907* @see: NA
908* @warning: NA
909*********************************************************************/
910int qser_wifi_sta_stop(void)
911{
912 int ret = -1;
913 ret = sc_wifi_sta_stop();
914 if (0 != ret)
915 {
916 LYERRLOG("[%s ] sta_stop ret = %d\n", __func__,ret);
917 return ret;
918 }
919 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
920 return 0;
921}
922
wz.wange5a0b912024-03-22 19:11:59 +0800923DEFINE_LYNQ_LIB_LOG(LYNQ_WIFI)
wz.wang73504132024-03-19 16:38:37 +0800924
925#ifdef __cplusplus
926}
927#endif