blob: da282c875970b954fdd11b038306659d7c07b905 [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.wang0feef142024-04-23 18:08:39 +080014static lynq_wifi_event_handle wifi_event_handle = NULL;
15static lynq_wifi_event_handle_sta wifi_event_handle_sta = NULL;
wz.wang9f658672024-04-15 14:23:58 +080016static void *global_arg = NULL;
wz.wang9f658672024-04-15 14:23:58 +080017
18/********************************************************************
19* @brief: lynq_to_sc_auth_mode, The encryption mode of wifi is changed from api to platform
wz.wang0feef142024-04-23 18:08:39 +080020* @return :sc_wifi_auth_e, all
wz.wang9f658672024-04-15 14:23:58 +080021* @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 }
wz.wang0feef142024-04-23 18:08:39 +080049 return type;
50}
wz.wang9f658672024-04-15 14:23:58 +080051
52/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +080053* @brief: sc_to_lynq_auth_mode, The wifi protocol moves from platform to api
54* @return :lynq_wifi_auth_e, all
wz.wang9f658672024-04-15 14:23:58 +080055* @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 }
wz.wang0feef142024-04-23 18:08:39 +080083 return type;
84}
85
86/********************************************************************
87* @brief: lynq_to_sc_mode, The wifi protocol is transferred from api to platform
88* @return :sc_wifi_ap_mode_type_e, all
89* @todo: NA
90* @see: NA
91* @warning: NA
92*********************************************************************/
93static sc_wifi_ap_mode_type_e lynq_to_sc_mode(lynq_wifi_mode_type_e mode)
94{
95 sc_wifi_ap_mode_type_e type;
96 switch (mode)
97 {
98 case LYNQ_WIFI_MODE_80211BGN:
99 type = SC_WIFI_AP_MODE_80211BGN;
100 break;
101 case LYNQ_WIFI_MODE_80211BGNAX_2G:
102 type = SC_WIFI_AP_MODE_80211BGNAX_2G;
103 break;
104 case LYNQ_WIFI_MODE_80211AN:
105 type = SC_WIFI_AP_MODE_80211AN;
106 break;
107 case LYNQ_WIFI_MODE_80211ANAC:
108 type = SC_WIFI_AP_MODE_80211ANAC;
109 break;
110 case LYNQ_WIFI_MODE_80211ANACAX_5G:
111 type = SC_WIFI_AP_MODE_80211ANACAX_5G;
112 break;
113 default:
114 type = SC_WIFI_AP_MODE_MIN;
115 break;
116 }
117 return type;
118}
119
120/********************************************************************
121* @brief: sc_to_lynq_mode, The encryption mode of wifi is changed from platform to api
122* @return :lynq_wifi_mode_type_e, all
123* @todo: NA
124* @see: NA
125* @warning: NA
126*********************************************************************/
127static lynq_wifi_mode_type_e sc_to_lynq_mode(sc_wifi_ap_mode_type_e mode)
128{
129 lynq_wifi_mode_type_e type;
130 switch (mode)
131 {
132 case SC_WIFI_AP_MODE_80211BGN:
133 type = LYNQ_WIFI_MODE_80211BGN;
134 break;
135 case SC_WIFI_AP_MODE_80211BGNAX_2G:
136 type = LYNQ_WIFI_MODE_80211BGNAX_2G;
137 break;
138 case SC_WIFI_AP_MODE_80211AN:
139 type = LYNQ_WIFI_MODE_80211AN;
140 break;
141 case SC_WIFI_AP_MODE_80211ANAC:
142 type = LYNQ_WIFI_MODE_80211ANAC;
143 break;
144 case SC_WIFI_AP_MODE_80211ANACAX_5G:
145 type = LYNQ_WIFI_MODE_80211ANACAX_5G;
146 break;
147 default:
148 type = LYNQ_WIFI_MODE_MIN;
149 break;
150 }
151 return type;
152}
wz.wang9f658672024-04-15 14:23:58 +0800153
154/********************************************************************
155* @brief: lynq_user_status, wifi startup callback
156* @return : NA
157* @todo: NA
158* @see: NA
159* @warning: NA
160*********************************************************************/
161static void lynq_user_status(sc_wifi_enable_status_e pre_status, sc_wifi_enable_status_e status)
162{
163 LYINFLOG("%s:%d,%d\n", __func__, pre_status, status);
164}
165
166/********************************************************************
167* @brief: lynq_user_wifi_service_error, wifi service status callback
168* @return : NA
169* @todo: NA
170* @see: NA
171* @warning: NA
172*********************************************************************/
173static void lynq_user_wifi_service_error(int error)
174{
175 LYINFLOG("%s: %d\n", __func__, error);
176}
177
178/********************************************************************
179* @brief: lynq_user_ap_status, wifi Obtains the ap status callback
180* @return : NA
181* @todo: NA
182* @see: NA
183* @warning: NA
184*********************************************************************/
185static 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)
186{
wz.wang5bbe6d62024-05-29 13:39:35 +0800187 lynq_wifi_event_s event;
188 if (wifi_event_handle != NULL && global_arg != NULL)
wz.wang9f658672024-04-15 14:23:58 +0800189 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800190 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
191 {
192 return;
193 }
194 if (*(int *)global_arg != LYNQ_WIFI_EVENT_AP_STATION)
195 {
196 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
197 }
198 event.id = LYNQ_WIFI_EVENT_AP_STATION;
199 event.status = (lynq_wifi_status_e)pre_status;
200 wifi_event_handle(&event, global_arg);
wz.wang9f658672024-04-15 14:23:58 +0800201 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800202 else
203 {
wz.wang9f658672024-04-15 14:23:58 +0800204 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
205 }
wz.wang9f658672024-04-15 14:23:58 +0800206}
207
208/********************************************************************
209* @brief: lynq_user_ap_sta_conn_status, wifi as ap is sta information callback
210* @return : NA
211* @todo: NA
212* @see: NA
213* @warning: NA
214*********************************************************************/
215static void lynq_user_ap_sta_conn_status(sc_wifi_ap_index_e index, sc_wifi_sta_connect_status_t *p_msg)
216{
wz.wang5bbe6d62024-05-29 13:39:35 +0800217 char hostname[32] = {0};
218 lynq_wifi_event_s event;
219 int ret = sc_wifi_get_hostname_by_mac(p_msg->macaddr, hostname, sizeof(hostname));
220 if (ret == 0)
wz.wang9f658672024-04-15 14:23:58 +0800221 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800222 printf("[wifi_demo]sta ip not assigned, try again later!\n");
wz.wang9f658672024-04-15 14:23:58 +0800223 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800224 if (wifi_event_handle != NULL && global_arg != NULL)
225 {
226 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
227 {
228 return;
229 }
230 if (*(int *)global_arg != LYNQ_WIFI_EVENT_STA_STATUS)
231 {
232 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
233 }
234 event.id = LYNQ_WIFI_EVENT_STA_STATUS;
235 event.ap_sta_info.connected = p_msg->is_connected;
236 strncpy(event.ap_sta_info.mac, p_msg->macaddr,
237 sizeof(event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(event.ap_sta_info.mac) : sizeof(p_msg->macaddr));
238 strncpy(event.ap_sta_info.hostname, hostname, sizeof(hostname));
239 wifi_event_handle(&event, global_arg);
wz.wang9f658672024-04-15 14:23:58 +0800240 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800241 else
242 {
243 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
244 }
245}
wz.wang9f658672024-04-15 14:23:58 +0800246
247/********************************************************************
248* @brief: print_sta_status, wifi gets the status callback in sta mode
249* @return : NA
250* @todo: NA
251* @see: NA
252* @warning: NA
253*********************************************************************/
wz.wang5bbe6d62024-05-29 13:39:35 +0800254/*
wz.wang9f658672024-04-15 14:23:58 +0800255static void print_sta_status(sc_wifi_sta_status_t *p_msg)
256{
257 LYINFLOG("%s: %d, %s, %s, %d, %d\n", __func__, p_msg->status, p_msg->ifname, p_msg->ap_bssid,
258 p_msg->signal_level, p_msg->reason_code);
259
260 if (p_msg->has_addr == 1) {
261 char addrtxt[48] = {0};
262 inet_ntop(AF_INET, &p_msg->addr, addrtxt, sizeof(addrtxt));
263 LYINFLOG("%s : addr inet_ntop: %s\n", __func__, addrtxt);
264
265 LYINFLOG("%s : addr: %08X\n", __func__, p_msg->addr.s_addr);
266 }
267
268 if (p_msg->has_addr6 == 1) {
269 char addrtxt[48] = {0};
270 inet_ntop(AF_INET6, &p_msg->addr6, addrtxt, sizeof(addrtxt));
271 LYINFLOG("%s : addr6 inet_ntop: %s\n", __func__, addrtxt);
272
273 LYINFLOG("%s : addr6: %02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X\n",__func__,
274 p_msg->addr6.s6_addr[0], p_msg->addr6.s6_addr[1], p_msg->addr6.s6_addr[2], p_msg->addr6.s6_addr[3],
275 p_msg->addr6.s6_addr[4], p_msg->addr6.s6_addr[5], p_msg->addr6.s6_addr[6], p_msg->addr6.s6_addr[7],
276 p_msg->addr6.s6_addr[8], p_msg->addr6.s6_addr[9], p_msg->addr6.s6_addr[10], p_msg->addr6.s6_addr[11],
277 p_msg->addr6.s6_addr[12], p_msg->addr6.s6_addr[13], p_msg->addr6.s6_addr[14], p_msg->addr6.s6_addr[15]);
278 }
279 LYINFLOG("%s : sta_status end\n",__func__);
280}
wz.wang5bbe6d62024-05-29 13:39:35 +0800281*/
wz.wang9f658672024-04-15 14:23:58 +0800282
283/********************************************************************
284* @brief: lynq_user_sta_status_ind, wifi gets the status callback in sta mode
285* @return : NA
286* @todo: NA
287* @see: NA
288* @warning: NA
289*********************************************************************/
290static void lynq_user_sta_status_ind(sc_wifi_sta_status_e pre_status,
291 sc_wifi_sta_status_t *p_msg)
292{
293 LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
wz.wang5bbe6d62024-05-29 13:39:35 +0800294 //print_sta_status(p_msg);
wz.wang9f658672024-04-15 14:23:58 +0800295}
296
297/********************************************************************
298* @brief: lynq_user_sta_scan_result_ind, wifi gets the callback of sta mode traversing the hotspot
299* @return : NA
300* @todo: NA
301* @see: NA
302* @warning: NA
303*********************************************************************/
304static void lynq_user_sta_scan_result_ind(sc_wifi_sta_scan_list_t *p_msg)
305{
wz.wang0feef142024-04-23 18:08:39 +0800306 int i = 0;
307 LYINFLOG("%s : user_sta_scan_result_ind_cb:%d\n", __func__, p_msg->cnt);
308 if (p_msg->cnt <= 0)
309 {
310 return;
311 }
312 if (wifi_event_handle_sta != NULL)
313 {
314 lynq_wifi_sta_scan_list_t event;
315 event.cnt = p_msg->cnt;
316 for (i = 0; i < event.cnt; i++)
317 {
318 strncpy(event.info[i].essid, p_msg->info[i].essid, sizeof(p_msg->info[i].essid));
319 strncpy(event.info[i].bssid, p_msg->info[i].bssid, sizeof(p_msg->info[i].bssid));
320 event.info[i].auth = sc_to_lynq_auth_mode(p_msg->info[i].auth);
321 event.info[i].cipher = (lynq_wifi_auth_wpa_psk_e)p_msg->info[i].cipher;
322 event.info[i].channel = p_msg->info[i].channel;
323 event.info[i].signal_level = p_msg->info[i].signal_level;
wz.wang5bbe6d62024-05-29 13:39:35 +0800324 event.info[i].frequency = p_msg->info[i].frequency;
325 event.info[i].signal = p_msg->info[i].signal;
wz.wang0feef142024-04-23 18:08:39 +0800326 }
327 wifi_event_handle_sta(&event);
328 }
329 else
330 {
331 for (i = 0; i < p_msg->cnt; i++)
332 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800333 LYINFLOG("%s : ap[%d]:%s,%d,%d,%d,%s,%d,%d,%d\n", __func__, i, p_msg->info[i].essid, sc_to_lynq_auth_mode(p_msg->info[i].auth),
334 p_msg->info[i].cipher, p_msg->info[i].channel, p_msg->info[i].bssid, p_msg->info[i].signal_level,p_msg->info[i].frequency,p_msg->info[i].signal);
wz.wang0feef142024-04-23 18:08:39 +0800335 }
336 }
337}
338
339/********************************************************************
340* @brief: qser_wifi_work_mode_set, 2.4g or 5g working mode Settings
341* @param type [IN]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Settings
342* @return : int, If equal to 0 succeeds, others fail
343* @todo: NA
344* @see: NA
345* @warning: NA
346*********************************************************************/
347int qser_wifi_work_mode_set(lynq_wifi_work_mode_e type)
348{
349 int ret = -1;
wz.wang5bbe6d62024-05-29 13:39:35 +0800350 sc_wifi_work_mode_e mode;
351 ret = sc_wifi_work_mode_get(&mode);
352 if (0 != ret)
353 {
354 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
355 return ret;
356 }
357 if(mode == (sc_wifi_work_mode_e)type) //The same value is returned
358 {
359 return 0;
360 }
wz.wang0feef142024-04-23 18:08:39 +0800361 ret = sc_wifi_work_mode_set((sc_wifi_work_mode_e)type);
362 if (0 != ret)
363 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800364 LYERRLOG("[%s ] work_mode set ret = %d\n", __func__,ret);
wz.wang0feef142024-04-23 18:08:39 +0800365 return ret;
366 }
367 LYINFLOG("[%s ]\n", __func__);
368 return 0;
wz.wang9f658672024-04-15 14:23:58 +0800369}
370
371/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +0800372* @brief: qser_wifi_work_mode_get, 2.4g or 5g working mode Gettings
373* @param type [OUT]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Gettings
374* @return : int, If equal to 0 succeeds, others fail
375* @todo: NA
376* @see: NA
377* @warning: NA
378*********************************************************************/
379int qser_wifi_work_mode_get(lynq_wifi_work_mode_e *type)
380{
381 int ret = -1;
382 sc_wifi_work_mode_e mode;
383 ret = sc_wifi_work_mode_get(&mode);
384 if (0 != ret)
385 {
386 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
387 return ret;
388 }
389 *type = (lynq_wifi_work_mode_e)mode;
390 LYINFLOG("[%s ]\n", __func__);
391 return 0;
392}
393
394/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +0800395* @brief: qser_wifi_register_handle, Register callback functions
wz.wang0feef142024-04-23 18:08:39 +0800396* @param event_handle [IN]: lynq_wifi_event_handle, Register the ap event callback function
397* @param event_handle_sta [IN]: Register sta's event callback function
398* @param arg [IN]: void *, Not currently used, but cannot pass a null pointer
wz.wang9f658672024-04-15 14:23:58 +0800399* @return :int, If equal to 0 succeeds, others fail
400* @todo: NA
401* @see: NA
402* @warning: NA
403*********************************************************************/
wz.wang0feef142024-04-23 18:08:39 +0800404int qser_wifi_register_handle(lynq_wifi_event_handle event_handle, lynq_wifi_event_handle_sta event_handle_sta, void *arg)
wz.wang9f658672024-04-15 14:23:58 +0800405{
wz.wang0feef142024-04-23 18:08:39 +0800406 if((event_handle == NULL && event_handle_sta == NULL) || arg == NULL)
wz.wang9f658672024-04-15 14:23:58 +0800407 {
408 LYERRLOG("[%s ] NUll pointer event_handle = 0x%p arg = 0x%p\n", __func__, event_handle, arg);
409 return -1;
410 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800411 if(*(int *)arg <= LYNQ_WIFI_EVENT_MIN || *(int *)arg >= LYNQ_WIFI_EVENT_MAX)
412 {
413 LYERRLOG("[%s ] The value of arg can only be an integer ranging from 0 to 3p, arg = %d\n", __func__, arg);
414 return -1;
415 }
wz.wang0feef142024-04-23 18:08:39 +0800416 wifi_event_handle_sta = event_handle_sta;
wz.wang9f658672024-04-15 14:23:58 +0800417 wifi_event_handle = event_handle;
418 global_arg = arg;
419 return 0;
420}
421
wz.wang73504132024-03-19 16:38:37 +0800422/********************************************************************
423* @brief: qser_wifi_enable, Enable WiFi function
424* @return : int, If equal to 0 succeeds, others fail
425* @todo: NA
426* @see: NA
427* @warning: NA
428*********************************************************************/
429int qser_wifi_enable(void)
430{
wz.wange5a0b912024-03-22 19:11:59 +0800431 int ret = -1;
432 ret = sc_wifi_init();
wz.wang73504132024-03-19 16:38:37 +0800433 if (0 != ret)
434 {
wz.wang9f658672024-04-15 14:23:58 +0800435 LYERRLOG("[%s ] init wifi ret = %d fail\n", __func__,ret);
436 return ret;
437 }
438
439 //wifi
440 ret = sc_wifi_set_enable_status_ind_cb(lynq_user_status);
441 if (0 != ret)
442 {
443 LYERRLOG("[%s ] Request lynq_user_status ret = %d fail\n", __func__,ret);
444 return ret;
445 }
446
447 //ap
448 ret = sc_wifi_ap_set_status_ind_cb(lynq_user_ap_status);
449 if (0 != ret)
450 {
451 LYERRLOG("[%s ] Request lynq_user_ap_status ret = %d fail\n", __func__,ret);
452 return ret;
453 }
454 ret = sc_wifi_set_ap_sta_connect_ind_cb(lynq_user_ap_sta_conn_status);
455 if (0 != ret)
456 {
457 LYERRLOG("[%s ] Request lynq_user_ap_sta_conn_status ret = %d fail\n", __func__,ret);
458 return ret;
459 }
460
461 //sta
462 ret = sc_wifi_sta_set_status_ind_cb(lynq_user_sta_status_ind);
463 if (0 != ret)
464 {
465 LYERRLOG("[%s ] Request lynq_user_sta_status_ind ret = %d fail\n", __func__,ret);
466 return ret;
467 }
468 ret = sc_wifi_sta_set_scan_result_ind_cb(lynq_user_sta_scan_result_ind);
469 if (0 != ret)
470 {
471 LYERRLOG("[%s ] Request lynq_user_sta_scan_result_ind ret = %d fail\n", __func__,ret);
472 return ret;
473 }
474 //proxy
475 ret = sc_wifi_set_service_error_cb(lynq_user_wifi_service_error);
476 if (0 != ret)
477 {
478 LYERRLOG("[%s ] Request lynq_user_wifi_service_error ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800479 return ret;
wz.wang73504132024-03-19 16:38:37 +0800480 }
wz.wange5a0b912024-03-22 19:11:59 +0800481
482 ret = sc_wifi_enable();
483 if (0 != ret)
484 {
wz.wang9f658672024-04-15 14:23:58 +0800485 LYERRLOG("[%s ] enable wifi ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800486 return ret;
487 }
488 LYINFLOG("[%s ]\n", __func__);
489 return 0;
wz.wang73504132024-03-19 16:38:37 +0800490}
491
492/********************************************************************
493* @brief: qser_wifi_disable, Turn off WiFi
494* @return : int, If equal to 0 succeeds, others fail
495* @todo: NA
496* @see: NA
497* @warning: NA
498*********************************************************************/
499int qser_wifi_disable(void)
500{
wz.wange5a0b912024-03-22 19:11:59 +0800501 int ret = -1;
502 ret = sc_wifi_disable();
wz.wang73504132024-03-19 16:38:37 +0800503 if (0 != ret)
504 {
wz.wang0feef142024-04-23 18:08:39 +0800505 LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800506 return ret;
wz.wang73504132024-03-19 16:38:37 +0800507 }
wz.wange5a0b912024-03-22 19:11:59 +0800508
509 ret = sc_wifi_uninit();
510 if (0 != ret)
511 {
wz.wang0feef142024-04-23 18:08:39 +0800512 LYERRLOG("[%s ] uninit ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800513 return ret;
514 }
515 LYINFLOG("[%s ]\n", __func__);
516 return 0;
wz.wang73504132024-03-19 16:38:37 +0800517}
518
519/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +0800520* @brief: qser_wifi_ap_get_status, Example Query ap working status
521* @param type [OUT]: lynq_wifi_ap_status_t *, ap working status
522* @return : int, If equal to 0 succeeds, others fail
523* @todo: NA
524* @see: NA
525* @warning: NA
526*********************************************************************/
527int qser_wifi_ap_get_status(lynq_wifi_ap_index_e idx, lynq_wifi_ap_status_t *ap_stat)
528{
529 int ret = -1;
530 sc_wifi_ap_status_t stat;
531 ret = sc_wifi_ap_get_status((sc_wifi_ap_index_e)idx, &stat);
532 if (0 != ret)
533 {
534 LYERRLOG("[%s ] wifi_ap_get ret = %d\n", __func__,ret);
535 return ret;
536 }
537 LYINFLOG("[%s ] idx = %d ifname = %s status = %d bssid = %s \n", __func__, idx, stat.ifname, stat.status, stat.bssid);
538 strncpy(ap_stat->ifname, stat.ifname, sizeof(stat.ifname) - 1);
539 ap_stat->status = (lynq_wifi_status_e)stat.status;
540 strncpy(ap_stat->bssid, stat.bssid, sizeof(stat.bssid) - 1);
541 return 0;
542}
543
544/********************************************************************
545* @brief: qser_wifi_ap_acl_set, Set the WiFi2.4G or 5G whitelist
546* @param idx [IN]: int, Set 2.4G or 5G
547* @param acl_rule [IN]: lynq_wifi_mac_acl_rule_e, Set the blacklist and whitelist mode
548* @param mac_list [IN]: char *, Set the mac address of the whitelist
549* @return : int, If equal to 0 succeeds, others fail
550* @todo: NA
551* @see: NA
552* @warning: NA
553*********************************************************************/
554int qser_wifi_ap_acl_set(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e acl_rule, char *mac_list)
555{
556 int ret = -1;
557 if (mac_list == NULL)
558 {
559 LYERRLOG("[%s ] Null pointer mac_list = 0x%p \n", __func__, mac_list);
560 return ret;
561 }
562 if(acl_rule == LYNQ_WIFI_MAC_ACL_RULE_BLACK)
563 ret = sc_wifi_ap_acl_set((sc_wifi_ap_index_e)idx, SC_WIFI_MAC_ACL_RULE_WHITE, mac_list);
564 ret = sc_wifi_ap_acl_set((sc_wifi_ap_index_e)idx, (sc_wifi_mac_acl_rule_e)acl_rule, mac_list);
565 if (0 != ret)
566 {
567 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
568 return ret;
569 }
570 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, acl_rule, mac_list);
571 return 0;
572}
573
574/********************************************************************
575* @brief: qser_wifi_ap_acl_get, Get the WiFi2.4G or 5G whitelist
576* @param idx [IN]: int, Set 2.4G or 5G
577* @param acl_rule [OUT]: lynq_wifi_mac_acl_rule_e *, Get the blacklist and whitelist mode
578* @param mac_list [OUT]: char *, Get the mac address of the whitelist
579* @return : int, If equal to 0 succeeds, others fail
580* @todo: NA
581* @see: NA
582* @warning: NA
583*********************************************************************/
584int qser_wifi_ap_acl_get(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e *acl_rule, char *mac_list)
585{
586 int ret = -1;
587 sc_wifi_ap_param_t param = {0};
588 if (mac_list == NULL || acl_rule == NULL)
589 {
590 LYERRLOG("[%s ] Null pointer acl_rule = 0x%p mac_list = 0x%p \n", __func__, acl_rule, mac_list);
591 return ret;
592 }
593 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
594 if (0 != ret)
595 {
596 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
597 return ret;
598 }
599 *acl_rule = (lynq_wifi_mac_acl_rule_e)param.acl_rule;
600 strncpy(mac_list, param.mac_list, sizeof(param.mac_list) - 1);
601 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, param.acl_rule, param.mac_list);
602 return 0;
603}
604
605/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800606* @brief: qser_wifi_ap_ssid_set, Set the name of the ssid of 2.4G or 5G
607* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800608* @param ssid [IN]: const char *, Set the ssid name
609* @return : int, If equal to 0 succeeds, others fail
610* @todo: NA
611* @see: NA
612* @warning: NA
613*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800614int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
wz.wang73504132024-03-19 16:38:37 +0800615{
wz.wange5a0b912024-03-22 19:11:59 +0800616 int ret = -1;
617 if (ssid == NULL)
618 {
619 LYERRLOG("[%s ] Null pointer ssid = 0x%p \n", __func__, ssid);
620 return ret;
621 }
622 ret = sc_wifi_ap_ssid_set((sc_wifi_ap_index_e)idx, ssid);
623 if (0 != ret)
624 {
625 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
626 return ret;
627 }
628 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, ssid);
629 return 0;
630}
631
632/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800633* @brief: qser_wifi_ap_ssid_get, Get the name of the ssid of 2.4G or 5G
634* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800635* @param ssid [OUT]: char *, Get the ssid name
636* @return : int, If equal to 0 succeeds, others fail
637* @todo: NA
638* @see: NA
639* @warning: NA
640*********************************************************************/
641int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
642{
643 int ret = -1;
644 sc_wifi_ap_param_t param = {0};
645 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
646 if (0 != ret)
647 {
648 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
649 return ret;
650 }
651 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, param.ssid);
652 strncpy(ssid, param.ssid, sizeof(param.ssid) - 1);
653 return 0;
wz.wang73504132024-03-19 16:38:37 +0800654}
655
656/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800657* @brief: qser_wifi_ap_ssid_hide_set, Set whether the ssid of 2.4G or 5G is hidden
658* @param idx [IN]: int, Set 2.4G or 5G
wz.wang9f658672024-04-15 14:23:58 +0800659* @param hide [IN]: bool, Set whether the ssid is hidden
660* @return : int, If equal to 0 succeeds, others fail
661* @todo: NA
662* @see: NA
663* @warning: NA
664*********************************************************************/
665int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx, bool hide)
666{
667 int ret = -1;
668 ret = sc_wifi_ap_ssid_hidden_set((sc_wifi_ap_index_e)idx, (int)hide);
669 if (0 != ret)
670 {
671 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
672 return ret;
673 }
674 LYINFLOG("[%s ] idx = %d hide = %d \n", __func__, idx, hide);
675 return 0;
676}
677
678/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800679* @brief: qser_wifi_ap_ssid_hide_get, Get whether the ssid of 2.4G or 5G is hidden
680* @param idx [IN]: int, Set 2.4G or 5G
wz.wang9f658672024-04-15 14:23:58 +0800681* @param hide [OUT]: bool *, Get whether the ssid is hidden
682* @return : int, If equal to 0 succeeds, others fail
683* @todo: NA
684* @see: NA
685* @warning: NA
686*********************************************************************/
687int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx, bool *hide)
688{
689 int ret = -1;
690 sc_wifi_ap_param_t param = {0};
691 if (hide == NULL)
692 {
693 LYERRLOG("[%s ] Null pointer hide = 0x%p \n", __func__, hide);
694 return ret;
695 }
696 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
697 if (0 != ret)
698 {
699 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
700 return ret;
701 }
702 LYINFLOG("[%s ] idx = %d ssid_hide = %d \n", __func__, idx, param.ssid_hide);
703 *hide = (bool)param.ssid_hide;
704 return 0;
705}
706
707/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800708* @brief: qser_wifi_ap_mode_set, Set the working protocol mode of 2.4G or 5G
709* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800710* @param mode [IN]: lynq_wifi_mode_type_e, Set the working protocol mode
711* @return : int, If equal to 0 succeeds, others fail
712* @todo: NA
713* @see: NA
714* @warning: NA
715*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800716int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
wz.wang73504132024-03-19 16:38:37 +0800717{
wz.wange5a0b912024-03-22 19:11:59 +0800718 int ret = -1;
wz.wang0feef142024-04-23 18:08:39 +0800719 ret = sc_wifi_ap_mode_set((sc_wifi_ap_index_e)idx, lynq_to_sc_mode(mode));
wz.wange5a0b912024-03-22 19:11:59 +0800720 if (0 != ret)
721 {
722 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
723 return ret;
724 }
725 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, mode);
726 return 0;
727}
728
729/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800730* @brief: qser_wifi_ap_mode_get, Get the working protocol mode of 2.4G or 5G
731* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800732* @param mode [OUT]: lynq_wifi_mode_type_e *, Get the working protocol mode
733* @return : int, If equal to 0 succeeds, others fail
734* @todo: NA
735* @see: NA
736* @warning: NA
737*********************************************************************/
738int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e *mode)
739{
740 int ret = -1;
741 sc_wifi_ap_param_t param = {0};
742 if (mode == NULL)
743 {
744 LYERRLOG("[%s ] Null pointer mode = 0x%p \n", __func__, mode);
745 return ret;
746 }
747 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
748 if (0 != ret)
749 {
750 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
751 return ret;
752 }
753 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, param.mode);
wz.wang0feef142024-04-23 18:08:39 +0800754 *mode = sc_to_lynq_mode(param.mode);
wz.wange5a0b912024-03-22 19:11:59 +0800755 return 0;
wz.wang73504132024-03-19 16:38:37 +0800756}
757
758/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800759* @brief: qser_wifi_ap_bandwidth_set, Set the bandwidth of 2.4G or 5G
760* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800761* @param bandwidth [IN]: lynq_wifi_bandwidth_type_e, Set the bandwidth
762* @return : int, If equal to 0 succeeds, others fail
763* @todo: NA
764* @see: NA
765* @warning: NA
766*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800767int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
wz.wang73504132024-03-19 16:38:37 +0800768{
wz.wange5a0b912024-03-22 19:11:59 +0800769 int ret = -1;
770 ret = sc_wifi_ap_bandwidth_set((sc_wifi_ap_index_e)idx, (sc_wifi_bandwidth_e)bandwidth);
771 if (0 != ret)
772 {
773 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
774 return ret;
775 }
776 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, bandwidth);
777 return 0;
778}
779
780/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800781* @brief: qser_wifi_ap_bandwidth_get, Get the bandwidth of 2.4G or 5G
782* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800783* @param bandwidth [OUT]: lynq_wifi_bandwidth_type_e *, Get the bandwidth
784* @return : int, If equal to 0 succeeds, others fail
785* @todo: NA
786* @see: NA
787* @warning: NA
788*********************************************************************/
789int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
790{
791 int ret = -1;
792 sc_wifi_ap_param_t param = {0};
793 if (bandwidth == NULL)
794 {
795 LYERRLOG("[%s ] Null pointer bandwidth = 0x%p \n", __func__, bandwidth);
796 return ret;
797 }
798 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
799 if (0 != ret)
800 {
801 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
802 return ret;
803 }
804 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, param.bandwidth);
805 *bandwidth = (lynq_wifi_bandwidth_type_e)param.bandwidth;
806 return 0;
wz.wang73504132024-03-19 16:38:37 +0800807}
808
809/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800810* @brief: qser_wifi_ap_channel_set, Set the channel for 2.4G or 5G
811* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800812* @param country_code [IN]: const char *, Set country code
813* @param channel [IN]: int, Set the channel
814* @return : int, If equal to 0 succeeds, others fail
815* @todo: NA
816* @see: NA
817* @warning: NA
818*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800819int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx, const char *country_code, int channel)
wz.wang73504132024-03-19 16:38:37 +0800820{
wz.wange5a0b912024-03-22 19:11:59 +0800821 int ret = -1;
822 if (country_code == NULL)
823 {
824 LYERRLOG("[%s ] Null pointer country_code = 0x%p \n", __func__, country_code);
825 return ret;
826 }
827 ret = sc_wifi_ap_cc_ch_set((sc_wifi_ap_index_e)idx, country_code, channel);
828 if (0 != ret)
829 {
830 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
831 return ret;
832 }
833 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, country_code, channel);
834 return 0;
835}
836
837/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800838* @brief: qser_wifi_ap_channel_get, Get the channel for 2.4G or 5G
839* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800840* @param country_code [OUT]: char *, Get country code
841* @param channel [OUT]: int *, Get the channel
842* @return : int, If equal to 0 succeeds, others fail
843* @todo: NA
844* @see: NA
845* @warning: NA
846*********************************************************************/
847int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx, char *country_code, int *channel)
848{
849 int ret = -1;
850 sc_wifi_ap_param_t param = {0};
851 if (country_code == NULL || channel == NULL)
852 {
853 LYERRLOG("[%s ] Null pointer country_code = 0x%p channel = 0x%p\n", __func__, country_code, channel);
854 return ret;
855 }
856 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
857 if (0 != ret)
858 {
859 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
860 return ret;
861 }
862 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, param.countrycode, param.channel);
863 strncpy(country_code, param.countrycode, sizeof(param.countrycode) - 1);
864 *channel = param.channel;
865 return 0;
wz.wang73504132024-03-19 16:38:37 +0800866}
867
868/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800869* @brief: qser_wifi_ap_auth_set, Set the security authentication mode and password of 2.4G or 5G
870* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800871* @param auth_mode [IN]: lynq_wifi_auth_e, Set the security authentication mode
872* @param auth_passwd [IN]: const char *, Set password
873* @return : int, If equal to 0 succeeds, others fail
874* @todo: NA
875* @see: NA
876* @warning: NA
877*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800878int 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 +0800879{
wz.wange5a0b912024-03-22 19:11:59 +0800880 int ret = -1;
wz.wange5a0b912024-03-22 19:11:59 +0800881 if (auth_passwd == NULL)
882 {
883 LYERRLOG("[%s ] Null pointer auth_passwd = 0x%p\n", __func__, auth_passwd);
884 return ret;
885 }
wz.wang9f658672024-04-15 14:23:58 +0800886
wz.wang73504132024-03-19 16:38:37 +0800887 sc_wifi_ap_auth_t auth;
wz.wang9f658672024-04-15 14:23:58 +0800888 auth.auth = lynq_to_sc_auth_mode(auth_mode);
wz.wang73504132024-03-19 16:38:37 +0800889 strncpy(auth.passwd, auth_passwd, sizeof(auth.passwd) - 1);
wz.wange5a0b912024-03-22 19:11:59 +0800890 ret = sc_wifi_ap_auth_set((sc_wifi_ap_index_e)idx, &auth);
891 if (0 != ret)
892 {
893 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
894 return ret;
895 }
wz.wang9f658672024-04-15 14:23:58 +0800896 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s\n", __func__, idx, auth_mode, "******");
wz.wange5a0b912024-03-22 19:11:59 +0800897 return 0;
898}
899
900/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800901* @brief: qser_wifi_ap_auth_get, Get the security authentication mode and password of 2.4G or 5G
902* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800903* @param auth_mode [OUT]: lynq_wifi_auth_e *, Get the security authentication mode
904* @param auth_passwd [OUT]: char *, Get password
905* @return : int, If equal to 0 succeeds, others fail
906* @todo: NA
907* @see: NA
908* @warning: NA
909*********************************************************************/
910int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char *auth_passwd)
911{
912 int ret = -1;
913 sc_wifi_ap_param_t param = {0};
914 if (auth_mode == NULL || auth_passwd == NULL)
915 {
916 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p auth_passwd = 0x%p\n", __func__, auth_mode, auth_passwd);
917 return ret;
918 }
919 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
920 if (0 != ret)
921 {
922 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
923 return ret;
924 }
925 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s \n", __func__, idx, param.auth.auth, param.auth.passwd);
926 strncpy(auth_passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
wz.wang9f658672024-04-15 14:23:58 +0800927
928 *auth_mode = sc_to_lynq_auth_mode(param.auth.auth);
wz.wange5a0b912024-03-22 19:11:59 +0800929 return 0;
wz.wang73504132024-03-19 16:38:37 +0800930}
931
932/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +0800933* @brief: qser_wifi_ap_auth_get_s, Get the security authentication mode , password group_rekey and pairwise of 2.4G or 5G
934* @param idx [IN]: int, Set 2.4G or 5G
935* @param auth_mode [OUT]: lynq_wifi_ap_auth_t *, Get the security authentication mode
936* @return : int, If equal to 0 succeeds, others fail
937* @todo: NA
938* @see: NA
939* @warning: NA
940*********************************************************************/
941int qser_wifi_ap_auth_get_s(lynq_wifi_ap_index_e idx, lynq_wifi_ap_auth_t *auth_mode)
942{
943 int ret = -1;
944 sc_wifi_ap_param_t param = {0};
945 if (auth_mode == NULL)
946 {
947 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p\n", __func__, auth_mode);
948 return ret;
949 }
950 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
951 if (0 != ret)
952 {
953 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
954 return ret;
955 }
956 LYINFLOG("[%s ] idx = %d auth = %d passwd = %s group_rekey = %d pairwise = %d\n", __func__, idx, param.auth.auth, param.auth.passwd, param.auth.group_rekey, param.auth.pairwise);
957 strncpy(auth_mode->passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
958 auth_mode->group_rekey = param.auth.group_rekey;
959 auth_mode->pairwise = (lynq_wifi_auth_wpa_psk_e)param.auth.pairwise;
960 auth_mode->auth = sc_to_lynq_auth_mode(param.auth.auth);
961 return 0;
962}
963
964/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800965* @brief: qser_wifi_ap_max_sta_set, Set the maximum number of STAs for 2.4G or 5G
966* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800967* @param max_sta_num [IN]: int, Set the maximum number
968* @return : int, If equal to 0 succeeds, others fail
969* @todo: NA
970* @see: NA
971* @warning: NA
972*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800973int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
wz.wang73504132024-03-19 16:38:37 +0800974{
wz.wange5a0b912024-03-22 19:11:59 +0800975 int ret = -1;
976 ret = sc_wifi_ap_max_sta_num_set((sc_wifi_ap_index_e)idx, max_sta_num);
977 if (0 != ret)
978 {
979 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
980 return ret;
981 }
982 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, max_sta_num);
983 return 0;
984}
985
986/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800987* @brief: qser_wifi_ap_max_sta_get, Get the maximum number of STAs for 2.4G or 5G
988* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800989* @param max_sta_num [OUT]: int *, Get the maximum number
990* @return : int, If equal to 0 succeeds, others fail
991* @todo: NA
992* @see: NA
993* @warning: NA
994*********************************************************************/
995int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int *max_sta_num)
996{
997 int ret = -1;
998 sc_wifi_ap_param_t param = {0};
999 if (max_sta_num == NULL)
1000 {
1001 LYERRLOG("[%s ] Null pointer max_sta_num = 0x%p\n", __func__,max_sta_num);
1002 return ret;
1003 }
1004 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1005 if (0 != ret)
1006 {
1007 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1008 return ret;
1009 }
1010 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, param.max_sta_num);
1011 *max_sta_num = param.max_sta_num;
1012 return 0;
wz.wang73504132024-03-19 16:38:37 +08001013}
1014
1015/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001016* @brief: qser_wifi_ap_start, Set the ap mode of 2.4G or 5G to enable
1017* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001018* @return : int, If equal to 0 succeeds, others fail
1019* @todo: NA
1020* @see: NA
1021* @warning: NA
1022*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001023int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001024{
wz.wange5a0b912024-03-22 19:11:59 +08001025 int ret = -1;
1026 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
1027 if (0 != ret)
1028 {
1029 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1030 return ret;
1031 }
1032 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1033 return 0;
wz.wang73504132024-03-19 16:38:37 +08001034}
1035
1036/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001037* @brief: qser_wifi_ap_stop, Disable ap mode for 2.4G or 5G
1038* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001039* @return : int, If equal to 0 succeeds, others fail
1040* @todo: NA
1041* @see: NA
1042* @warning: NA
1043*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001044int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001045{
wz.wange5a0b912024-03-22 19:11:59 +08001046 int ret = -1;
1047 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
1048 if (0 != ret)
1049 {
1050 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1051 return ret;
1052 }
1053 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1054 return 0;
wz.wang73504132024-03-19 16:38:37 +08001055}
1056
1057/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001058* @brief: qser_wifi_ap_restart, Set the ap mode of 2.4G or 5G to restart
1059* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001060* @return : int, If equal to 0 succeeds, others fail
1061* @todo: NA
1062* @see: NA
1063* @warning: NA
1064*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001065int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001066{
wz.wange5a0b912024-03-22 19:11:59 +08001067 int ret = -1;
1068 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
wz.wang73504132024-03-19 16:38:37 +08001069 if (0 != ret)
1070 {
wz.wang9f658672024-04-15 14:23:58 +08001071 LYERRLOG("[%s ] stop ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +08001072 return ret;
wz.wang73504132024-03-19 16:38:37 +08001073 }
wz.wange5a0b912024-03-22 19:11:59 +08001074 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
1075 if (0 != ret)
1076 {
wz.wang9f658672024-04-15 14:23:58 +08001077 LYERRLOG("[%s ] start ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +08001078 return ret;
1079 }
1080 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1081 return 0;
wz.wang73504132024-03-19 16:38:37 +08001082}
1083
wz.wang9f658672024-04-15 14:23:58 +08001084/********************************************************************
1085* @brief: qser_wifi_sta_param_set, Set the ssid and password that you need to connect to the access point
wz.wang5bbe6d62024-05-29 13:39:35 +08001086* @param param_stat [IN]: sc_wifi_sta_param_t *, Set parameters such as ssid and password that you want to connect to the access point
wz.wang9f658672024-04-15 14:23:58 +08001087* @return : int, If equal to 0 succeeds, others fail
1088* @todo: NA
1089* @see: NA
1090* @warning: NA
1091*********************************************************************/
wz.wang5bbe6d62024-05-29 13:39:35 +08001092int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *param_stat)
wz.wang9f658672024-04-15 14:23:58 +08001093{
1094 int ret = -1;
1095 sc_wifi_sta_param_t stat = {0};
wz.wang5bbe6d62024-05-29 13:39:35 +08001096 stat.auth = lynq_to_sc_auth_mode(param_stat->auth);
1097 stat.pairwise = (sc_wifi_auth_wpa_psk_e )param_stat->pairwise;
1098 strncpy(stat.ssid, param_stat->ssid, sizeof(stat.ssid) - 1);
1099 strncpy(stat.passwd, param_stat->passwd, sizeof(stat.passwd) - 1);
wz.wang9f658672024-04-15 14:23:58 +08001100 ret = sc_wifi_sta_param_set(&stat);
1101 if (0 != ret)
1102 {
1103 LYERRLOG("[%s ] sta_param_set ret = %d\n", __func__,ret);
1104 return ret;
1105 }
1106 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1107 return 0;
1108}
1109
1110/********************************************************************
1111* @brief: qser_wifi_sta_param_get, Get the ssid and password that you need to connect to the access point
wz.wang5bbe6d62024-05-29 13:39:35 +08001112* @param param_stat [OUT]: sc_wifi_sta_param_t *, Get parameters such as ssid and password that you want to connect to the access point
wz.wang9f658672024-04-15 14:23:58 +08001113* @return : int, If equal to 0 succeeds, others fail
1114* @todo: NA
1115* @see: NA
1116* @warning: NA
1117*********************************************************************/
wz.wang5bbe6d62024-05-29 13:39:35 +08001118int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *param_stat)
wz.wang9f658672024-04-15 14:23:58 +08001119{
1120 int ret = -1;
1121 sc_wifi_sta_param_t stat = {0};
1122 ret = sc_wifi_sta_param_get(&stat);
1123 if (0 != ret)
1124 {
1125 LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__,ret);
1126 return ret;
1127 }
wz.wang5bbe6d62024-05-29 13:39:35 +08001128 param_stat->auth = sc_to_lynq_auth_mode(stat.auth);
1129 param_stat->pairwise = (lynq_wifi_auth_wpa_psk_e )stat.pairwise;
1130 strncpy(param_stat->ssid, stat.ssid, sizeof(stat.ssid) - 1);
1131 strncpy(param_stat->passwd, stat.passwd, sizeof(stat.passwd) -1);
1132 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1133 return 0;
1134}
1135
1136/********************************************************************
1137* @brief: qser_wifi_sta_get_status, Gets the status value associated with sta
1138* @param status_stat [OUT]: lynq_wifi_sta_status_t *, Gets the status value associated with sta
1139* @return : int, If equal to 0 succeeds, others fail
1140* @todo: NA
1141* @see: NA
1142* @warning: NA
1143*********************************************************************/
1144int qser_wifi_sta_get_status(lynq_wifi_sta_status_t *status_stat)
1145{
1146 int ret = -1;
1147 sc_wifi_sta_status_t stat;
1148 ret = sc_wifi_sta_get_status(&stat);
1149 if (0 != ret)
1150 {
1151 LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__,ret);
1152 return ret;
1153 }
1154 //print_sta_status(&stat);
1155 status_stat->status = (lynq_wifi_sta_status_e)stat.status;
1156 status_stat->signal_level = stat.signal_level;
1157 status_stat->has_addr = stat.has_addr;
1158 status_stat->has_addr6 = stat.has_addr6;
1159 status_stat->reason_code = (lynq_wifi_reason_code_e)stat.reason_code;
1160 strncpy(status_stat->ifname, stat.ifname, sizeof(stat.ifname) - 1);
1161 strncpy(status_stat->ap_bssid, stat.ap_bssid, sizeof(stat.ap_bssid) - 1);
1162 if (status_stat->has_addr == 1)
1163 {
1164 //inet_ntop(AF_INET, &stat.addr, status_stat->addr, sizeof(status_stat->addr));
1165 }
1166 if (status_stat->has_addr6 == 1)
1167 {
1168 //inet_ntop(AF_INET6, &stat.addr6, status_stat->addr6, sizeof(status_stat->addr6));
1169 }
wz.wang9f658672024-04-15 14:23:58 +08001170 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1171 return 0;
1172}
1173
1174/********************************************************************
1175* @brief: qser_wifi_sta_start_scan, Scan for ap nodes and return them through callback
1176* @return : int, If equal to 0 succeeds, others fail
1177* @todo: NA
1178* @see: NA
1179* @warning: NA
1180*********************************************************************/
1181int qser_wifi_sta_start_scan(void)
1182{
1183 int ret = -1;
1184 ret = sc_wifi_sta_start_scan();
1185 if (0 != ret)
1186 {
1187 LYERRLOG("[%s ] scan ret = %d\n", __func__,ret);
1188 return ret;
1189 }
1190 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1191 return 0;
1192}
1193
1194/********************************************************************
1195* @brief: qser_wifi_sta_start, To enable sta mode, you need to enable ap mode first
1196* @return : int, If equal to 0 succeeds, others fail
1197* @todo: NA
1198* @see: NA
1199* @warning: NA
1200*********************************************************************/
1201int qser_wifi_sta_start(void)
1202{
1203 int ret = -1;
1204 ret = sc_wifi_sta_start();
1205 if (0 != ret)
1206 {
1207 LYERRLOG("[%s ] sta_start ret = %d\n", __func__,ret);
1208 return ret;
1209 }
1210 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1211 return 0;
1212}
1213
1214/********************************************************************
1215* @brief: qser_wifi_sta_stop, To disable sta mode.
1216* @return : int, If equal to 0 succeeds, others fail
1217* @todo: NA
1218* @see: NA
1219* @warning: NA
1220*********************************************************************/
1221int qser_wifi_sta_stop(void)
1222{
1223 int ret = -1;
1224 ret = sc_wifi_sta_stop();
1225 if (0 != ret)
1226 {
1227 LYERRLOG("[%s ] sta_stop ret = %d\n", __func__,ret);
1228 return ret;
1229 }
1230 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1231 return 0;
1232}
1233
wz.wange5a0b912024-03-22 19:11:59 +08001234DEFINE_LYNQ_LIB_LOG(LYNQ_WIFI)
wz.wang73504132024-03-19 16:38:37 +08001235
1236#ifdef __cplusplus
1237}
1238#endif