blob: 21d19012a474aaf232dffa4c3b76f8c601471601 [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
zw.wang0044b012024-08-08 11:48:49 +080010#include <cfg_api.h>
wz.wang73504132024-03-19 16:38:37 +080011#include "sc_tel_types.h"
12#include "sc_wifi.h"
13#include "lynq-qser-wifi.h"
zw.wangf4578ce2024-08-14 10:58:38 +080014#define WIFI_ENABLE_FLAG_TIME_OUT 10
15#define WIFI_ENABLE_FLAG_DEFAULT -100
wz.wang73504132024-03-19 16:38:37 +080016
wz.wang0feef142024-04-23 18:08:39 +080017static lynq_wifi_event_handle wifi_event_handle = NULL;
18static lynq_wifi_event_handle_sta wifi_event_handle_sta = NULL;
wz.wang9f658672024-04-15 14:23:58 +080019static void *global_arg = NULL;
zw.wangf4578ce2024-08-14 10:58:38 +080020static int wifi_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
zw.wangb8e9b0c2024-09-05 13:53:33 +080021static bool lynq_wifi_enable = false;
22#define WIFI_ENABLE_JUDGE() do{ \
23 if(lynq_wifi_enable == false) \
24 { \
25 LYINFLOG("[%s ] wifi not enable\n", __func__); \
26 return -1; \
27 } \
28}while (0);
wz.wang9f658672024-04-15 14:23:58 +080029
you.chen154c1912025-06-25 17:12:30 +080030static lynq_wifi_event_handle wifi2_event_handle = NULL;
31static lynq_wifi_event_handle_sta wifi2_event_handle_sta = NULL;
32static void *global_arg_2 = NULL;
33static int wifi2_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
34static bool lynq_wifi2_enable = false;
35#define WIFI2_ENABLE_JUDGE() do{ \
36 if(lynq_wifi2_enable== false) \
37 { \
38 LYINFLOG("[%s ] wifi 2 not enable\n", __func__); \
39 return -1; \
40 } \
41}while (0);
42
wz.wang9f658672024-04-15 14:23:58 +080043/********************************************************************
44* @brief: lynq_to_sc_auth_mode, The encryption mode of wifi is changed from api to platform
wz.wang0feef142024-04-23 18:08:39 +080045* @return :sc_wifi_auth_e, all
wz.wang9f658672024-04-15 14:23:58 +080046* @todo: NA
47* @see: NA
48* @warning: NA
49*********************************************************************/
50static sc_wifi_auth_e lynq_to_sc_auth_mode(lynq_wifi_auth_e auth_mode)
51{
52 sc_wifi_auth_e type;
53 switch (auth_mode)
54 {
55 case LYNQ_WIFI_AUTH_OPEN:
56 type = SC_WIFI_AUTH_OPEN;
57 break;
58 case LYNQ_WIFI_AUTH_WPA2_PSK:
59 type = SC_WIFI_AUTH_WPA2_PSK;
60 break;
61 case LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
62 type = SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
63 break;
64 case LYNQ_WIFI_AUTH_WPA3_PSK:
65 type = SC_WIFI_AUTH_WPA3_PSK;
66 break;
67 case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
68 type = SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
69 break;
70 default:
71 type = SC_WIFI_AUTH_MIN;
72 break;
73 }
wz.wang0feef142024-04-23 18:08:39 +080074 return type;
75}
wz.wang9f658672024-04-15 14:23:58 +080076
77/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +080078* @brief: sc_to_lynq_auth_mode, The wifi protocol moves from platform to api
79* @return :lynq_wifi_auth_e, all
wz.wang9f658672024-04-15 14:23:58 +080080* @todo: NA
81* @see: NA
82* @warning: NA
83*********************************************************************/
84static lynq_wifi_auth_e sc_to_lynq_auth_mode(sc_wifi_auth_e auth_mode)
85{
86 lynq_wifi_auth_e type;
87 switch (auth_mode)
88 {
89 case SC_WIFI_AUTH_OPEN:
90 type = LYNQ_WIFI_AUTH_OPEN;
91 break;
92 case SC_WIFI_AUTH_WPA2_PSK:
93 type = LYNQ_WIFI_AUTH_WPA2_PSK;
94 break;
95 case SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
96 type = LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
97 break;
98 case SC_WIFI_AUTH_WPA3_PSK:
99 type = LYNQ_WIFI_AUTH_WPA3_PSK;
100 break;
101 case SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
102 type = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
103 break;
104 default:
105 type = LYNQ_WIFI_AUTH_MIN;
106 break;
107 }
wz.wang0feef142024-04-23 18:08:39 +0800108 return type;
109}
110
111/********************************************************************
112* @brief: lynq_to_sc_mode, The wifi protocol is transferred from api to platform
113* @return :sc_wifi_ap_mode_type_e, all
114* @todo: NA
115* @see: NA
116* @warning: NA
117*********************************************************************/
118static sc_wifi_ap_mode_type_e lynq_to_sc_mode(lynq_wifi_mode_type_e mode)
119{
120 sc_wifi_ap_mode_type_e type;
121 switch (mode)
122 {
123 case LYNQ_WIFI_MODE_80211BGN:
124 type = SC_WIFI_AP_MODE_80211BGN;
125 break;
126 case LYNQ_WIFI_MODE_80211BGNAX_2G:
127 type = SC_WIFI_AP_MODE_80211BGNAX_2G;
128 break;
129 case LYNQ_WIFI_MODE_80211AN:
130 type = SC_WIFI_AP_MODE_80211AN;
131 break;
132 case LYNQ_WIFI_MODE_80211ANAC:
133 type = SC_WIFI_AP_MODE_80211ANAC;
134 break;
135 case LYNQ_WIFI_MODE_80211ANACAX_5G:
136 type = SC_WIFI_AP_MODE_80211ANACAX_5G;
137 break;
138 default:
139 type = SC_WIFI_AP_MODE_MIN;
140 break;
141 }
142 return type;
143}
144
145/********************************************************************
146* @brief: sc_to_lynq_mode, The encryption mode of wifi is changed from platform to api
147* @return :lynq_wifi_mode_type_e, all
148* @todo: NA
149* @see: NA
150* @warning: NA
151*********************************************************************/
152static lynq_wifi_mode_type_e sc_to_lynq_mode(sc_wifi_ap_mode_type_e mode)
153{
154 lynq_wifi_mode_type_e type;
155 switch (mode)
156 {
157 case SC_WIFI_AP_MODE_80211BGN:
158 type = LYNQ_WIFI_MODE_80211BGN;
159 break;
160 case SC_WIFI_AP_MODE_80211BGNAX_2G:
161 type = LYNQ_WIFI_MODE_80211BGNAX_2G;
162 break;
163 case SC_WIFI_AP_MODE_80211AN:
164 type = LYNQ_WIFI_MODE_80211AN;
165 break;
166 case SC_WIFI_AP_MODE_80211ANAC:
167 type = LYNQ_WIFI_MODE_80211ANAC;
168 break;
169 case SC_WIFI_AP_MODE_80211ANACAX_5G:
170 type = LYNQ_WIFI_MODE_80211ANACAX_5G;
171 break;
172 default:
173 type = LYNQ_WIFI_MODE_MIN;
174 break;
175 }
176 return type;
177}
wz.wang9f658672024-04-15 14:23:58 +0800178
179/********************************************************************
zw.wang0044b012024-08-08 11:48:49 +0800180* @brief: sc_to_lynq_sta_status, sc_wifi_sta_status_t to lynq_wifi_sta_status_t
181* @return :int, all
182* @todo: NA
183* @see: NA
184* @warning: NA
185*********************************************************************/
186static int sc_to_lynq_sta_status(sc_wifi_sta_status_t *stat, lynq_wifi_sta_status_t *status_stat)
187{
188 status_stat->status = (lynq_wifi_sta_status_e)stat->status;
189 status_stat->signal_level = stat->signal_level;
190 status_stat->has_addr = stat->has_addr;
191 status_stat->has_addr6 = stat->has_addr6;
192 status_stat->reason_code = (lynq_wifi_reason_code_e)stat->reason_code;
193 strncpy(status_stat->ifname, stat->ifname, sizeof(stat->ifname) - 1);
194 strncpy(status_stat->ap_bssid, stat->ap_bssid, sizeof(stat->ap_bssid) - 1);
195 if (status_stat->has_addr == 1)
196 {
197 strncpy(status_stat->addr.addr, stat->addr.addr, sizeof(status_stat->addr.addr) - 1);
198 strncpy(status_stat->addr.netmask, stat->addr.netmask, sizeof(status_stat->addr.netmask) - 1);
199 status_stat->addr.subnet_bits = stat->addr.subnet_bits;
200 strncpy(status_stat->addr.gateway, stat->addr.gateway, sizeof(status_stat->addr.gateway) - 1);
201 strncpy(status_stat->addr.dnsp, stat->addr.dnsp, sizeof(status_stat->addr.dnsp) - 1);
202 strncpy(status_stat->addr.dnss, stat->addr.dnss, sizeof(status_stat->addr.dnss) - 1);
203 }
204 if (status_stat->has_addr6 == 1)
205 {
206 strncpy(status_stat->addr6.addr, stat->addr6.addr, sizeof(status_stat->addr6.addr) - 1);
207 strncpy(status_stat->addr6.prefix, stat->addr6.prefix, sizeof(status_stat->addr6.prefix) - 1);
208 status_stat->addr6.prefix_bits = stat->addr6.prefix_bits;
209 strncpy(status_stat->addr6.gateway, stat->addr6.gateway, sizeof(status_stat->addr6.gateway) - 1);
210 strncpy(status_stat->addr6.dnsp, stat->addr6.dnsp, sizeof(status_stat->addr6.dnsp) - 1);
211 strncpy(status_stat->addr6.dnss, stat->addr6.dnss, sizeof(status_stat->addr6.dnss) - 1);
212 }
213 return 0;
214}
215
216/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +0800217* @brief: lynq_user_status, wifi startup callback
218* @return : NA
219* @todo: NA
220* @see: NA
221* @warning: NA
222*********************************************************************/
223static void lynq_user_status(sc_wifi_enable_status_e pre_status, sc_wifi_enable_status_e status)
224{
zw.wangf4578ce2024-08-14 10:58:38 +0800225 wifi_enable_flag = status;
226 LYINFLOG("%s:%d,%d wifi_enable_flag:%d\n", __func__, pre_status, status, wifi_enable_flag);
wz.wang9f658672024-04-15 14:23:58 +0800227}
you.chen154c1912025-06-25 17:12:30 +0800228static void lynq_user2_status(sc_wifi_enable_status_e pre_status, sc_wifi_enable_status_e status)
229{
230 wifi2_enable_flag = status;
231 LYINFLOG("%s:%d,%d wifi2_enable_flag:%d\n", __func__, pre_status, status, wifi2_enable_flag);
232}
wz.wang9f658672024-04-15 14:23:58 +0800233
234/********************************************************************
235* @brief: lynq_user_wifi_service_error, wifi service status callback
236* @return : NA
237* @todo: NA
238* @see: NA
239* @warning: NA
240*********************************************************************/
241static void lynq_user_wifi_service_error(int error)
242{
243 LYINFLOG("%s: %d\n", __func__, error);
244}
you.chen154c1912025-06-25 17:12:30 +0800245static void lynq_user2_wifi_service_error(int error)
246{
247 LYINFLOG("%s: %d\n", __func__, error);
248}
wz.wang9f658672024-04-15 14:23:58 +0800249
250/********************************************************************
251* @brief: lynq_user_ap_status, wifi Obtains the ap status callback
252* @return : NA
253* @todo: NA
254* @see: NA
255* @warning: NA
256*********************************************************************/
257static 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)
258{
wz.wang5bbe6d62024-05-29 13:39:35 +0800259 lynq_wifi_event_s event;
260 if (wifi_event_handle != NULL && global_arg != NULL)
wz.wang9f658672024-04-15 14:23:58 +0800261 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800262 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
263 {
264 return;
265 }
zw.wang0044b012024-08-08 11:48:49 +0800266 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
wz.wang5bbe6d62024-05-29 13:39:35 +0800267 event.id = LYNQ_WIFI_EVENT_AP_STATION;
zw.wangf6fbbc02024-09-02 11:43:46 +0800268 event.status = (lynq_wifi_status_e)p_msg->status;
wz.wang5bbe6d62024-05-29 13:39:35 +0800269 wifi_event_handle(&event, global_arg);
wz.wang9f658672024-04-15 14:23:58 +0800270 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800271 else
272 {
wz.wang9f658672024-04-15 14:23:58 +0800273 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
274 }
wz.wang9f658672024-04-15 14:23:58 +0800275}
you.chen154c1912025-06-25 17:12:30 +0800276static void lynq_user2_ap_status(sc_wifi_ap_index_e index, sc_wifi_ap_status_e pre_status, sc_wifi_ap_status_t *p_msg)
277{
278 lynq_wifi_event_s event;
279 if (wifi2_event_handle != NULL && global_arg_2 != NULL)
280 {
281 if (*(int *)global_arg_2 == LYNQ_WIFI_EVENT_DISABLE_STATUS)
282 {
283 return;
284 }
285 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
286 event.id = LYNQ_WIFI_EVENT_AP_STATION;
287 event.status = (lynq_wifi_status_e)p_msg->status;
288 wifi2_event_handle(&event, global_arg_2);
289 }
290 else
291 {
292 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
293 }
294}
wz.wang9f658672024-04-15 14:23:58 +0800295
296/********************************************************************
297* @brief: lynq_user_ap_sta_conn_status, wifi as ap is sta information callback
298* @return : NA
299* @todo: NA
300* @see: NA
301* @warning: NA
302*********************************************************************/
303static void lynq_user_ap_sta_conn_status(sc_wifi_ap_index_e index, sc_wifi_sta_connect_status_t *p_msg)
304{
wz.wang5bbe6d62024-05-29 13:39:35 +0800305 char hostname[32] = {0};
306 lynq_wifi_event_s event;
307 int ret = sc_wifi_get_hostname_by_mac(p_msg->macaddr, hostname, sizeof(hostname));
308 if (ret == 0)
wz.wang9f658672024-04-15 14:23:58 +0800309 {
zw.wang0044b012024-08-08 11:48:49 +0800310 LYINFLOG("sta ip not assigned, try again later!\n");
wz.wang9f658672024-04-15 14:23:58 +0800311 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800312 if (wifi_event_handle != NULL && global_arg != NULL)
313 {
314 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
315 {
316 return;
317 }
zw.wang0044b012024-08-08 11:48:49 +0800318 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
319 event.id = LYNQ_WIFI_EVENT_AP_STA_STATUS;
wz.wang5bbe6d62024-05-29 13:39:35 +0800320 event.ap_sta_info.connected = p_msg->is_connected;
321 strncpy(event.ap_sta_info.mac, p_msg->macaddr,
322 sizeof(event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(event.ap_sta_info.mac) : sizeof(p_msg->macaddr));
323 strncpy(event.ap_sta_info.hostname, hostname, sizeof(hostname));
324 wifi_event_handle(&event, global_arg);
wz.wang9f658672024-04-15 14:23:58 +0800325 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800326 else
327 {
328 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
329 }
330}
you.chen154c1912025-06-25 17:12:30 +0800331static void lynq_user2_ap_sta_conn_status(sc_wifi_ap_index_e index, sc_wifi_sta_connect_status_t *p_msg)
332{
333 char hostname[32] = {0};
334 lynq_wifi_event_s event;
335 int ret = sc_wifi_get_hostname_by_mac_ext(1, p_msg->macaddr, hostname, sizeof(hostname));
336 if (ret == 0)
337 {
338 LYINFLOG("sta ip not assigned, try again later!\n");
339 }
340 if (wifi2_event_handle != NULL && global_arg_2 != NULL)
341 {
342 if (*(int *)global_arg_2 == LYNQ_WIFI_EVENT_DISABLE_STATUS)
343 {
344 return;
345 }
346 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
347 event.id = LYNQ_WIFI_EVENT_AP_STA_STATUS;
348 event.ap_sta_info.connected = p_msg->is_connected;
349 strncpy(event.ap_sta_info.mac, p_msg->macaddr,
350 sizeof(event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(event.ap_sta_info.mac) : sizeof(p_msg->macaddr));
351 strncpy(event.ap_sta_info.hostname, hostname, sizeof(hostname));
352 wifi2_event_handle(&event, global_arg_2);
353 }
354 else
355 {
356 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
357 }
358}
wz.wang9f658672024-04-15 14:23:58 +0800359/********************************************************************
360* @brief: print_sta_status, wifi gets the status callback in sta mode
361* @return : NA
362* @todo: NA
363* @see: NA
364* @warning: NA
365*********************************************************************/
366static void print_sta_status(sc_wifi_sta_status_t *p_msg)
367{
wz.wang72c432c2024-06-18 09:16:26 +0800368 LYINFLOG("%s: %d, %s, %s, %d, %d\n", __func__, p_msg->status, p_msg->ifname, p_msg->ap_bssid,
369 p_msg->signal_level, p_msg->reason_code);
wz.wang9f658672024-04-15 14:23:58 +0800370
wz.wang72c432c2024-06-18 09:16:26 +0800371 if (p_msg->has_addr == 1)
372 {
373 LYINFLOG("[%s]addr ip:%s, netmask:%s, subnet_bits:%d, gateway:%s, dnsp:%s, dnss:%s\n", __func__,
374 p_msg->addr.addr, p_msg->addr.netmask, p_msg->addr.subnet_bits,
375 p_msg->addr.gateway, p_msg->addr.dnsp, p_msg->addr.dnss);
376 }
wz.wang9f658672024-04-15 14:23:58 +0800377
wz.wang72c432c2024-06-18 09:16:26 +0800378 if (p_msg->has_addr6 == 1)
379 {
380 LYINFLOG("[%s]addr6 ip:%s, prefix:%s, prefix_bits:%d, gateway:%s, dnsp:%s, dnss:%s\n", __func__,
381 p_msg->addr6.addr, p_msg->addr6.prefix, p_msg->addr6.prefix_bits,
382 p_msg->addr6.gateway, p_msg->addr6.dnsp, p_msg->addr6.dnss);
383 }
384 LYINFLOG("%s : sta_status end\n", __func__);
wz.wang9f658672024-04-15 14:23:58 +0800385}
386
387/********************************************************************
388* @brief: lynq_user_sta_status_ind, wifi gets the status callback in sta mode
389* @return : NA
390* @todo: NA
391* @see: NA
392* @warning: NA
393*********************************************************************/
394static void lynq_user_sta_status_ind(sc_wifi_sta_status_e pre_status,
395 sc_wifi_sta_status_t *p_msg)
396{
zw.wang0044b012024-08-08 11:48:49 +0800397 if (wifi_event_handle != NULL && global_arg != NULL)
398 {
399 lynq_wifi_event_s event;
400 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
401 {
402 return;
403 }
404 LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
405 event.id = LYNQ_WIFI_EVENT_STA_STATUS;
406 if(p_msg->status == SC_WIFI_STA_STATUS_CONNECTED)
407 event.sta_status = LYNQ_WIFI_STATION_CONNECTED;
408 else if(p_msg->status == SC_WIFI_STA_STATUS_DISCONNECTED)
409 event.sta_status = LYNQ_WIFI_STATION_DISCONNECTED;
410 else
411 event.sta_status = LYNQ_WIFI_STATION_DISABLE;
412 sc_to_lynq_sta_status(p_msg, &event.sta_status_all);
413 event.sta_status_all.sta_status = event.sta_status;
414 wifi_event_handle(&event, global_arg);
415 }
416 else
417 {
418 print_sta_status(p_msg);
419 }
420
wz.wang9f658672024-04-15 14:23:58 +0800421}
you.chen154c1912025-06-25 17:12:30 +0800422static void lynq_user2_sta_status_ind(sc_wifi_sta_status_e pre_status,
423 sc_wifi_sta_status_t *p_msg)
424{
425 if (wifi2_event_handle != NULL && global_arg_2 != NULL)
426 {
427 lynq_wifi_event_s event;
428 if (*(int *)global_arg_2 == LYNQ_WIFI_EVENT_DISABLE_STATUS)
429 {
430 return;
431 }
432 LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
433 event.id = LYNQ_WIFI_EVENT_STA_STATUS;
434 if(p_msg->status == SC_WIFI_STA_STATUS_CONNECTED)
435 event.sta_status = LYNQ_WIFI_STATION_CONNECTED;
436 else if(p_msg->status == SC_WIFI_STA_STATUS_DISCONNECTED)
437 event.sta_status = LYNQ_WIFI_STATION_DISCONNECTED;
438 else
439 event.sta_status = LYNQ_WIFI_STATION_DISABLE;
440 sc_to_lynq_sta_status(p_msg, &event.sta_status_all);
441 event.sta_status_all.sta_status = event.sta_status;
442 wifi2_event_handle(&event, global_arg_2);
443 }
444 else
445 {
446 print_sta_status(p_msg);
447 }
448
449}
wz.wang9f658672024-04-15 14:23:58 +0800450/********************************************************************
451* @brief: lynq_user_sta_scan_result_ind, wifi gets the callback of sta mode traversing the hotspot
452* @return : NA
453* @todo: NA
454* @see: NA
455* @warning: NA
456*********************************************************************/
457static void lynq_user_sta_scan_result_ind(sc_wifi_sta_scan_list_t *p_msg)
458{
wz.wang0feef142024-04-23 18:08:39 +0800459 int i = 0;
460 LYINFLOG("%s : user_sta_scan_result_ind_cb:%d\n", __func__, p_msg->cnt);
461 if (p_msg->cnt <= 0)
462 {
463 return;
464 }
465 if (wifi_event_handle_sta != NULL)
466 {
467 lynq_wifi_sta_scan_list_t event;
468 event.cnt = p_msg->cnt;
469 for (i = 0; i < event.cnt; i++)
470 {
471 strncpy(event.info[i].essid, p_msg->info[i].essid, sizeof(p_msg->info[i].essid));
472 strncpy(event.info[i].bssid, p_msg->info[i].bssid, sizeof(p_msg->info[i].bssid));
473 event.info[i].auth = sc_to_lynq_auth_mode(p_msg->info[i].auth);
474 event.info[i].cipher = (lynq_wifi_auth_wpa_psk_e)p_msg->info[i].cipher;
475 event.info[i].channel = p_msg->info[i].channel;
476 event.info[i].signal_level = p_msg->info[i].signal_level;
wz.wang5bbe6d62024-05-29 13:39:35 +0800477 event.info[i].frequency = p_msg->info[i].frequency;
478 event.info[i].signal = p_msg->info[i].signal;
wz.wang0feef142024-04-23 18:08:39 +0800479 }
480 wifi_event_handle_sta(&event);
481 }
482 else
483 {
484 for (i = 0; i < p_msg->cnt; i++)
485 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800486 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),
487 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 +0800488 }
489 }
490}
you.chen154c1912025-06-25 17:12:30 +0800491static void lynq_user2_sta_scan_result_ind(sc_wifi_sta_scan_list_t *p_msg)
492{
493 int i = 0;
494 LYINFLOG("%s : user2_sta_scan_result_ind_cb:%d\n", __func__, p_msg->cnt);
495 if (p_msg->cnt <= 0)
496 {
497 return;
498 }
499 if (wifi2_event_handle_sta != NULL)
500 {
501 lynq_wifi_sta_scan_list_t event;
502 event.cnt = p_msg->cnt;
503 for (i = 0; i < event.cnt; i++)
504 {
505 strncpy(event.info[i].essid, p_msg->info[i].essid, sizeof(p_msg->info[i].essid));
506 strncpy(event.info[i].bssid, p_msg->info[i].bssid, sizeof(p_msg->info[i].bssid));
507 event.info[i].auth = sc_to_lynq_auth_mode(p_msg->info[i].auth);
508 event.info[i].cipher = (lynq_wifi_auth_wpa_psk_e)p_msg->info[i].cipher;
509 event.info[i].channel = p_msg->info[i].channel;
510 event.info[i].signal_level = p_msg->info[i].signal_level;
511 event.info[i].frequency = p_msg->info[i].frequency;
512 event.info[i].signal = p_msg->info[i].signal;
513 }
514 wifi2_event_handle_sta(&event);
515 }
516 else
517 {
518 for (i = 0; i < p_msg->cnt; i++)
519 {
520 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),
521 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);
522 }
523 }
524}
wz.wang0feef142024-04-23 18:08:39 +0800525/********************************************************************
526* @brief: qser_wifi_work_mode_set, 2.4g or 5g working mode Settings
527* @param type [IN]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Settings
528* @return : int, If equal to 0 succeeds, others fail
529* @todo: NA
530* @see: NA
531* @warning: NA
532*********************************************************************/
533int qser_wifi_work_mode_set(lynq_wifi_work_mode_e type)
534{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800535 WIFI_ENABLE_JUDGE();
wz.wang0feef142024-04-23 18:08:39 +0800536 int ret = -1;
wz.wang5bbe6d62024-05-29 13:39:35 +0800537 sc_wifi_work_mode_e mode;
538 ret = sc_wifi_work_mode_get(&mode);
539 if (0 != ret)
540 {
541 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
542 return ret;
543 }
544 if(mode == (sc_wifi_work_mode_e)type) //The same value is returned
545 {
546 return 0;
547 }
wz.wang0feef142024-04-23 18:08:39 +0800548 ret = sc_wifi_work_mode_set((sc_wifi_work_mode_e)type);
549 if (0 != ret)
550 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800551 LYERRLOG("[%s ] work_mode set ret = %d\n", __func__,ret);
wz.wang0feef142024-04-23 18:08:39 +0800552 return ret;
553 }
554 LYINFLOG("[%s ]\n", __func__);
555 return 0;
wz.wang9f658672024-04-15 14:23:58 +0800556}
557
558/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +0800559* @brief: qser_wifi_work_mode_get, 2.4g or 5g working mode Gettings
560* @param type [OUT]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Gettings
561* @return : int, If equal to 0 succeeds, others fail
562* @todo: NA
563* @see: NA
564* @warning: NA
565*********************************************************************/
566int qser_wifi_work_mode_get(lynq_wifi_work_mode_e *type)
567{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800568 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800569 int ret = -1;
570 sc_wifi_work_mode_e mode;
571 ret = sc_wifi_work_mode_get(&mode);
572 if (0 != ret)
573 {
574 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
575 return ret;
576 }
577 *type = (lynq_wifi_work_mode_e)mode;
578 LYINFLOG("[%s ]\n", __func__);
579 return 0;
580}
581
582/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +0800583* @brief: qser_wifi_register_handle, Register callback functions
wz.wang0feef142024-04-23 18:08:39 +0800584* @param event_handle [IN]: lynq_wifi_event_handle, Register the ap event callback function
585* @param event_handle_sta [IN]: Register sta's event callback function
586* @param arg [IN]: void *, Not currently used, but cannot pass a null pointer
wz.wang9f658672024-04-15 14:23:58 +0800587* @return :int, If equal to 0 succeeds, others fail
588* @todo: NA
589* @see: NA
590* @warning: NA
591*********************************************************************/
wz.wang0feef142024-04-23 18:08:39 +0800592int 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 +0800593{
wz.wang0feef142024-04-23 18:08:39 +0800594 if((event_handle == NULL && event_handle_sta == NULL) || arg == NULL)
wz.wang9f658672024-04-15 14:23:58 +0800595 {
596 LYERRLOG("[%s ] NUll pointer event_handle = 0x%p arg = 0x%p\n", __func__, event_handle, arg);
597 return -1;
598 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800599 if(*(int *)arg <= LYNQ_WIFI_EVENT_MIN || *(int *)arg >= LYNQ_WIFI_EVENT_MAX)
600 {
601 LYERRLOG("[%s ] The value of arg can only be an integer ranging from 0 to 3p, arg = %d\n", __func__, arg);
602 return -1;
603 }
wz.wang0feef142024-04-23 18:08:39 +0800604 wifi_event_handle_sta = event_handle_sta;
wz.wang9f658672024-04-15 14:23:58 +0800605 wifi_event_handle = event_handle;
606 global_arg = arg;
607 return 0;
608}
609
wz.wang73504132024-03-19 16:38:37 +0800610/********************************************************************
611* @brief: qser_wifi_enable, Enable WiFi function
612* @return : int, If equal to 0 succeeds, others fail
613* @todo: NA
614* @see: NA
615* @warning: NA
616*********************************************************************/
617int qser_wifi_enable(void)
618{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800619 if(lynq_wifi_enable)
620 {
621 LYERRLOG("[%s ] The wifi is enabled\n", __func__);
622 return -1;
623 }
zw.wangf4578ce2024-08-14 10:58:38 +0800624 wifi_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
zw.wang0044b012024-08-08 11:48:49 +0800625 char wifiAvailable[8] = {0};
626 sc_cfg_get("wifiAvailable", wifiAvailable, sizeof(wifiAvailable));
627 if (!strcmp(wifiAvailable, "0"))
628 {
629 LYERRLOG("[%s ] wifiAvailable has been set to 0. If WiFi is used, set 1 to enable it\n", __func__);
630 return -1;
631 }
wz.wange5a0b912024-03-22 19:11:59 +0800632 int ret = -1;
633 ret = sc_wifi_init();
wz.wang73504132024-03-19 16:38:37 +0800634 if (0 != ret)
635 {
wz.wang9f658672024-04-15 14:23:58 +0800636 LYERRLOG("[%s ] init wifi ret = %d fail\n", __func__,ret);
637 return ret;
638 }
639
640 //wifi
641 ret = sc_wifi_set_enable_status_ind_cb(lynq_user_status);
642 if (0 != ret)
643 {
644 LYERRLOG("[%s ] Request lynq_user_status ret = %d fail\n", __func__,ret);
645 return ret;
646 }
647
648 //ap
649 ret = sc_wifi_ap_set_status_ind_cb(lynq_user_ap_status);
650 if (0 != ret)
651 {
652 LYERRLOG("[%s ] Request lynq_user_ap_status ret = %d fail\n", __func__,ret);
653 return ret;
654 }
655 ret = sc_wifi_set_ap_sta_connect_ind_cb(lynq_user_ap_sta_conn_status);
656 if (0 != ret)
657 {
658 LYERRLOG("[%s ] Request lynq_user_ap_sta_conn_status ret = %d fail\n", __func__,ret);
659 return ret;
660 }
661
662 //sta
663 ret = sc_wifi_sta_set_status_ind_cb(lynq_user_sta_status_ind);
664 if (0 != ret)
665 {
666 LYERRLOG("[%s ] Request lynq_user_sta_status_ind ret = %d fail\n", __func__,ret);
667 return ret;
668 }
669 ret = sc_wifi_sta_set_scan_result_ind_cb(lynq_user_sta_scan_result_ind);
670 if (0 != ret)
671 {
672 LYERRLOG("[%s ] Request lynq_user_sta_scan_result_ind ret = %d fail\n", __func__,ret);
673 return ret;
674 }
675 //proxy
676 ret = sc_wifi_set_service_error_cb(lynq_user_wifi_service_error);
677 if (0 != ret)
678 {
679 LYERRLOG("[%s ] Request lynq_user_wifi_service_error ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800680 return ret;
wz.wang73504132024-03-19 16:38:37 +0800681 }
wz.wange5a0b912024-03-22 19:11:59 +0800682
683 ret = sc_wifi_enable();
684 if (0 != ret)
685 {
wz.wang9f658672024-04-15 14:23:58 +0800686 LYERRLOG("[%s ] enable wifi ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800687 return ret;
688 }
zw.wangf4578ce2024-08-14 10:58:38 +0800689 for(int i = 0; i < WIFI_ENABLE_FLAG_TIME_OUT; i++)
690 {
691 if(wifi_enable_flag == WIFI_ENABLE_FLAG_DEFAULT)
692 sleep(1);
693 else
694 break;
695 }
696 switch (wifi_enable_flag)
697 {
698 case SC_WIFI_STATUS_DISABLED:
699 ret = 1;
700 break;
701 case SC_WIFI_STATUS_ENABLED:
702 ret = 0;
703 break;
704 case SC_WIFI_STATUS_INVALID_MAC:
705 ret = 7;
706 break;
707 case SC_WIFI_STATUS_DEV_INIT_FAIL:
708 ret = 6;
709 break;
710 case SC_WIFI_STATUS_FIRMWARE_CRASH:
711 ret = 12;
712 break;
713 default:
714 ret = -1;
715 break;
716 }
zw.wangb8e9b0c2024-09-05 13:53:33 +0800717 LYINFLOG("[%s ] ret = %d\n", __func__,ret);
718 if(ret != 0)
719 {
720 int ret_uninit = sc_wifi_uninit();
721 if (0 != ret_uninit)
722 {
723 LYERRLOG("[%s ] uninit ret = %d\n", __func__,ret_uninit);
724 }
725 }
726 else
727 lynq_wifi_enable = true;
zw.wangf4578ce2024-08-14 10:58:38 +0800728 return ret;
wz.wang73504132024-03-19 16:38:37 +0800729}
730
731/********************************************************************
732* @brief: qser_wifi_disable, Turn off WiFi
733* @return : int, If equal to 0 succeeds, others fail
734* @todo: NA
735* @see: NA
736* @warning: NA
737*********************************************************************/
738int qser_wifi_disable(void)
739{
wz.wange5a0b912024-03-22 19:11:59 +0800740 int ret = -1;
zw.wangf4578ce2024-08-14 10:58:38 +0800741 wifi_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
zw.wangb8e9b0c2024-09-05 13:53:33 +0800742 if(lynq_wifi_enable == false)
743 {
744 LYERRLOG("[%s ] WiFi not turned on\n", __func__);
745 return -1;
746 }
wz.wange5a0b912024-03-22 19:11:59 +0800747 ret = sc_wifi_disable();
wz.wang73504132024-03-19 16:38:37 +0800748 if (0 != ret)
749 {
wz.wang0feef142024-04-23 18:08:39 +0800750 LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800751 return ret;
wz.wang73504132024-03-19 16:38:37 +0800752 }
zw.wangf4578ce2024-08-14 10:58:38 +0800753 for(int i = 0; i < WIFI_ENABLE_FLAG_TIME_OUT; i++)
754 {
755 if(wifi_enable_flag == WIFI_ENABLE_FLAG_DEFAULT)
756 sleep(1);
757 else
758 break;
759 }
760 switch (wifi_enable_flag)
761 {
762 case SC_WIFI_STATUS_DISABLED:
763 ret = 0;
764 break;
765 case SC_WIFI_STATUS_INVALID_MAC:
766 ret = 7;
767 break;
768 case SC_WIFI_STATUS_DEV_INIT_FAIL:
769 ret = 6;
770 break;
771 case SC_WIFI_STATUS_FIRMWARE_CRASH:
772 ret = 12;
773 break;
774 default:
775 ret = -1;
776 break;
777 }
778 if (0 != ret)
779 {
780 LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
781 return ret;
782 }
zw.wangb8e9b0c2024-09-05 13:53:33 +0800783 lynq_wifi_enable = false;
wz.wange5a0b912024-03-22 19:11:59 +0800784 ret = sc_wifi_uninit();
785 if (0 != ret)
786 {
wz.wang0feef142024-04-23 18:08:39 +0800787 LYERRLOG("[%s ] uninit ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800788 return ret;
789 }
790 LYINFLOG("[%s ]\n", __func__);
791 return 0;
wz.wang73504132024-03-19 16:38:37 +0800792}
793
794/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +0800795* @brief: qser_wifi_ap_get_status, Example Query ap working status
796* @param type [OUT]: lynq_wifi_ap_status_t *, ap working status
797* @return : int, If equal to 0 succeeds, others fail
798* @todo: NA
799* @see: NA
800* @warning: NA
801*********************************************************************/
802int qser_wifi_ap_get_status(lynq_wifi_ap_index_e idx, lynq_wifi_ap_status_t *ap_stat)
803{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800804 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800805 int ret = -1;
806 sc_wifi_ap_status_t stat;
807 ret = sc_wifi_ap_get_status((sc_wifi_ap_index_e)idx, &stat);
808 if (0 != ret)
809 {
810 LYERRLOG("[%s ] wifi_ap_get ret = %d\n", __func__,ret);
811 return ret;
812 }
813 LYINFLOG("[%s ] idx = %d ifname = %s status = %d bssid = %s \n", __func__, idx, stat.ifname, stat.status, stat.bssid);
814 strncpy(ap_stat->ifname, stat.ifname, sizeof(stat.ifname) - 1);
815 ap_stat->status = (lynq_wifi_status_e)stat.status;
816 strncpy(ap_stat->bssid, stat.bssid, sizeof(stat.bssid) - 1);
817 return 0;
818}
819
820/********************************************************************
821* @brief: qser_wifi_ap_acl_set, Set the WiFi2.4G or 5G whitelist
822* @param idx [IN]: int, Set 2.4G or 5G
823* @param acl_rule [IN]: lynq_wifi_mac_acl_rule_e, Set the blacklist and whitelist mode
824* @param mac_list [IN]: char *, Set the mac address of the whitelist
825* @return : int, If equal to 0 succeeds, others fail
826* @todo: NA
827* @see: NA
828* @warning: NA
829*********************************************************************/
830int qser_wifi_ap_acl_set(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e acl_rule, char *mac_list)
831{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800832 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800833 int ret = -1;
834 if (mac_list == NULL)
835 {
836 LYERRLOG("[%s ] Null pointer mac_list = 0x%p \n", __func__, mac_list);
837 return ret;
838 }
839 if(acl_rule == LYNQ_WIFI_MAC_ACL_RULE_BLACK)
840 ret = sc_wifi_ap_acl_set((sc_wifi_ap_index_e)idx, SC_WIFI_MAC_ACL_RULE_WHITE, mac_list);
841 ret = sc_wifi_ap_acl_set((sc_wifi_ap_index_e)idx, (sc_wifi_mac_acl_rule_e)acl_rule, mac_list);
842 if (0 != ret)
843 {
844 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
845 return ret;
846 }
847 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, acl_rule, mac_list);
848 return 0;
849}
850
851/********************************************************************
852* @brief: qser_wifi_ap_acl_get, Get the WiFi2.4G or 5G whitelist
853* @param idx [IN]: int, Set 2.4G or 5G
854* @param acl_rule [OUT]: lynq_wifi_mac_acl_rule_e *, Get the blacklist and whitelist mode
855* @param mac_list [OUT]: char *, Get the mac address of the whitelist
856* @return : int, If equal to 0 succeeds, others fail
857* @todo: NA
858* @see: NA
859* @warning: NA
860*********************************************************************/
861int qser_wifi_ap_acl_get(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e *acl_rule, char *mac_list)
862{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800863 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800864 int ret = -1;
865 sc_wifi_ap_param_t param = {0};
866 if (mac_list == NULL || acl_rule == NULL)
867 {
868 LYERRLOG("[%s ] Null pointer acl_rule = 0x%p mac_list = 0x%p \n", __func__, acl_rule, mac_list);
869 return ret;
870 }
871 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
872 if (0 != ret)
873 {
874 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
875 return ret;
876 }
877 *acl_rule = (lynq_wifi_mac_acl_rule_e)param.acl_rule;
878 strncpy(mac_list, param.mac_list, sizeof(param.mac_list) - 1);
879 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, param.acl_rule, param.mac_list);
880 return 0;
881}
882
883/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800884* @brief: qser_wifi_ap_ssid_set, Set the name of the ssid of 2.4G or 5G
885* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800886* @param ssid [IN]: const char *, Set the ssid name
887* @return : int, If equal to 0 succeeds, others fail
888* @todo: NA
889* @see: NA
890* @warning: NA
891*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800892int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
wz.wang73504132024-03-19 16:38:37 +0800893{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800894 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800895 int ret = -1;
896 if (ssid == NULL)
897 {
898 LYERRLOG("[%s ] Null pointer ssid = 0x%p \n", __func__, ssid);
899 return ret;
900 }
901 ret = sc_wifi_ap_ssid_set((sc_wifi_ap_index_e)idx, ssid);
902 if (0 != ret)
903 {
904 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
905 return ret;
906 }
907 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, ssid);
908 return 0;
909}
910
911/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800912* @brief: qser_wifi_ap_ssid_get, Get the name of the ssid of 2.4G or 5G
913* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800914* @param ssid [OUT]: char *, Get the ssid name
915* @return : int, If equal to 0 succeeds, others fail
916* @todo: NA
917* @see: NA
918* @warning: NA
919*********************************************************************/
920int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
921{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800922 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800923 int ret = -1;
924 sc_wifi_ap_param_t param = {0};
925 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
926 if (0 != ret)
927 {
928 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
929 return ret;
930 }
931 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, param.ssid);
932 strncpy(ssid, param.ssid, sizeof(param.ssid) - 1);
933 return 0;
wz.wang73504132024-03-19 16:38:37 +0800934}
935
936/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800937* @brief: qser_wifi_ap_ssid_hide_set, Set whether the ssid of 2.4G or 5G is hidden
938* @param idx [IN]: int, Set 2.4G or 5G
wz.wang9f658672024-04-15 14:23:58 +0800939* @param hide [IN]: bool, Set whether the ssid is hidden
940* @return : int, If equal to 0 succeeds, others fail
941* @todo: NA
942* @see: NA
943* @warning: NA
944*********************************************************************/
945int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx, bool hide)
946{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800947 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +0800948 int ret = -1;
949 ret = sc_wifi_ap_ssid_hidden_set((sc_wifi_ap_index_e)idx, (int)hide);
950 if (0 != ret)
951 {
952 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
953 return ret;
954 }
955 LYINFLOG("[%s ] idx = %d hide = %d \n", __func__, idx, hide);
956 return 0;
957}
958
959/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800960* @brief: qser_wifi_ap_ssid_hide_get, Get whether the ssid of 2.4G or 5G is hidden
961* @param idx [IN]: int, Set 2.4G or 5G
wz.wang9f658672024-04-15 14:23:58 +0800962* @param hide [OUT]: bool *, Get whether the ssid is hidden
963* @return : int, If equal to 0 succeeds, others fail
964* @todo: NA
965* @see: NA
966* @warning: NA
967*********************************************************************/
968int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx, bool *hide)
969{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800970 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +0800971 int ret = -1;
972 sc_wifi_ap_param_t param = {0};
973 if (hide == NULL)
974 {
975 LYERRLOG("[%s ] Null pointer hide = 0x%p \n", __func__, hide);
976 return ret;
977 }
978 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
979 if (0 != ret)
980 {
981 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
982 return ret;
983 }
984 LYINFLOG("[%s ] idx = %d ssid_hide = %d \n", __func__, idx, param.ssid_hide);
985 *hide = (bool)param.ssid_hide;
986 return 0;
987}
988
989/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800990* @brief: qser_wifi_ap_mode_set, Set the working protocol mode of 2.4G or 5G
991* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800992* @param mode [IN]: lynq_wifi_mode_type_e, Set the working protocol mode
993* @return : int, If equal to 0 succeeds, others fail
994* @todo: NA
995* @see: NA
996* @warning: NA
997*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800998int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
wz.wang73504132024-03-19 16:38:37 +0800999{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001000 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001001 int ret = -1;
wz.wang0feef142024-04-23 18:08:39 +08001002 ret = sc_wifi_ap_mode_set((sc_wifi_ap_index_e)idx, lynq_to_sc_mode(mode));
wz.wange5a0b912024-03-22 19:11:59 +08001003 if (0 != ret)
1004 {
1005 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1006 return ret;
1007 }
1008 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, mode);
1009 return 0;
1010}
1011
1012/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001013* @brief: qser_wifi_ap_mode_get, Get the working protocol mode of 2.4G or 5G
1014* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +08001015* @param mode [OUT]: lynq_wifi_mode_type_e *, Get the working protocol mode
1016* @return : int, If equal to 0 succeeds, others fail
1017* @todo: NA
1018* @see: NA
1019* @warning: NA
1020*********************************************************************/
1021int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e *mode)
1022{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001023 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001024 int ret = -1;
1025 sc_wifi_ap_param_t param = {0};
1026 if (mode == NULL)
1027 {
1028 LYERRLOG("[%s ] Null pointer mode = 0x%p \n", __func__, mode);
1029 return ret;
1030 }
1031 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1032 if (0 != ret)
1033 {
1034 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1035 return ret;
1036 }
1037 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, param.mode);
wz.wang0feef142024-04-23 18:08:39 +08001038 *mode = sc_to_lynq_mode(param.mode);
wz.wange5a0b912024-03-22 19:11:59 +08001039 return 0;
wz.wang73504132024-03-19 16:38:37 +08001040}
1041
1042/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001043* @brief: qser_wifi_ap_bandwidth_set, Set the bandwidth of 2.4G or 5G
1044* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001045* @param bandwidth [IN]: lynq_wifi_bandwidth_type_e, Set the bandwidth
1046* @return : int, If equal to 0 succeeds, others fail
1047* @todo: NA
1048* @see: NA
1049* @warning: NA
1050*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001051int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
wz.wang73504132024-03-19 16:38:37 +08001052{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001053 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001054 int ret = -1;
1055 ret = sc_wifi_ap_bandwidth_set((sc_wifi_ap_index_e)idx, (sc_wifi_bandwidth_e)bandwidth);
1056 if (0 != ret)
1057 {
1058 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1059 return ret;
1060 }
1061 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, bandwidth);
1062 return 0;
1063}
1064
1065/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001066* @brief: qser_wifi_ap_bandwidth_get, Get the bandwidth of 2.4G or 5G
1067* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +08001068* @param bandwidth [OUT]: lynq_wifi_bandwidth_type_e *, Get the bandwidth
1069* @return : int, If equal to 0 succeeds, others fail
1070* @todo: NA
1071* @see: NA
1072* @warning: NA
1073*********************************************************************/
1074int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
1075{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001076 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001077 int ret = -1;
1078 sc_wifi_ap_param_t param = {0};
1079 if (bandwidth == NULL)
1080 {
1081 LYERRLOG("[%s ] Null pointer bandwidth = 0x%p \n", __func__, bandwidth);
1082 return ret;
1083 }
1084 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1085 if (0 != ret)
1086 {
1087 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1088 return ret;
1089 }
1090 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, param.bandwidth);
1091 *bandwidth = (lynq_wifi_bandwidth_type_e)param.bandwidth;
1092 return 0;
wz.wang73504132024-03-19 16:38:37 +08001093}
1094
1095/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001096* @brief: qser_wifi_ap_channel_set, Set the channel for 2.4G or 5G
1097* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001098* @param country_code [IN]: const char *, Set country code
1099* @param channel [IN]: int, Set the channel
1100* @return : int, If equal to 0 succeeds, others fail
1101* @todo: NA
1102* @see: NA
1103* @warning: NA
1104*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001105int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx, const char *country_code, int channel)
wz.wang73504132024-03-19 16:38:37 +08001106{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001107 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001108 int ret = -1;
1109 if (country_code == NULL)
1110 {
1111 LYERRLOG("[%s ] Null pointer country_code = 0x%p \n", __func__, country_code);
1112 return ret;
1113 }
1114 ret = sc_wifi_ap_cc_ch_set((sc_wifi_ap_index_e)idx, country_code, channel);
1115 if (0 != ret)
1116 {
1117 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1118 return ret;
1119 }
1120 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, country_code, channel);
1121 return 0;
1122}
1123
1124/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001125* @brief: qser_wifi_ap_channel_get, Get the channel for 2.4G or 5G
1126* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +08001127* @param country_code [OUT]: char *, Get country code
1128* @param channel [OUT]: int *, Get the channel
1129* @return : int, If equal to 0 succeeds, others fail
1130* @todo: NA
1131* @see: NA
1132* @warning: NA
1133*********************************************************************/
1134int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx, char *country_code, int *channel)
1135{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001136 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001137 int ret = -1;
1138 sc_wifi_ap_param_t param = {0};
1139 if (country_code == NULL || channel == NULL)
1140 {
1141 LYERRLOG("[%s ] Null pointer country_code = 0x%p channel = 0x%p\n", __func__, country_code, channel);
1142 return ret;
1143 }
1144 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1145 if (0 != ret)
1146 {
1147 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1148 return ret;
1149 }
1150 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, param.countrycode, param.channel);
1151 strncpy(country_code, param.countrycode, sizeof(param.countrycode) - 1);
1152 *channel = param.channel;
1153 return 0;
wz.wang73504132024-03-19 16:38:37 +08001154}
1155
1156/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001157* @brief: qser_wifi_ap_auth_set, Set the security authentication mode and password of 2.4G or 5G
1158* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001159* @param auth_mode [IN]: lynq_wifi_auth_e, Set the security authentication mode
1160* @param auth_passwd [IN]: const char *, Set password
1161* @return : int, If equal to 0 succeeds, others fail
1162* @todo: NA
1163* @see: NA
1164* @warning: NA
1165*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001166int 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 +08001167{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001168 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001169 int ret = -1;
wz.wange5a0b912024-03-22 19:11:59 +08001170 if (auth_passwd == NULL)
1171 {
1172 LYERRLOG("[%s ] Null pointer auth_passwd = 0x%p\n", __func__, auth_passwd);
1173 return ret;
1174 }
wz.wang9f658672024-04-15 14:23:58 +08001175
wz.wang73504132024-03-19 16:38:37 +08001176 sc_wifi_ap_auth_t auth;
wz.wang9f658672024-04-15 14:23:58 +08001177 auth.auth = lynq_to_sc_auth_mode(auth_mode);
wz.wang73504132024-03-19 16:38:37 +08001178 strncpy(auth.passwd, auth_passwd, sizeof(auth.passwd) - 1);
wz.wange5a0b912024-03-22 19:11:59 +08001179 ret = sc_wifi_ap_auth_set((sc_wifi_ap_index_e)idx, &auth);
1180 if (0 != ret)
1181 {
1182 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1183 return ret;
1184 }
wz.wang9f658672024-04-15 14:23:58 +08001185 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s\n", __func__, idx, auth_mode, "******");
wz.wange5a0b912024-03-22 19:11:59 +08001186 return 0;
1187}
1188
1189/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001190* @brief: qser_wifi_ap_auth_get, Get the security authentication mode and password of 2.4G or 5G
1191* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +08001192* @param auth_mode [OUT]: lynq_wifi_auth_e *, Get the security authentication mode
1193* @param auth_passwd [OUT]: char *, Get password
1194* @return : int, If equal to 0 succeeds, others fail
1195* @todo: NA
1196* @see: NA
1197* @warning: NA
1198*********************************************************************/
1199int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char *auth_passwd)
1200{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001201 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001202 int ret = -1;
1203 sc_wifi_ap_param_t param = {0};
1204 if (auth_mode == NULL || auth_passwd == NULL)
1205 {
1206 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p auth_passwd = 0x%p\n", __func__, auth_mode, auth_passwd);
1207 return ret;
1208 }
1209 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1210 if (0 != ret)
1211 {
1212 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1213 return ret;
1214 }
1215 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s \n", __func__, idx, param.auth.auth, param.auth.passwd);
1216 strncpy(auth_passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
wz.wang9f658672024-04-15 14:23:58 +08001217
1218 *auth_mode = sc_to_lynq_auth_mode(param.auth.auth);
wz.wange5a0b912024-03-22 19:11:59 +08001219 return 0;
wz.wang73504132024-03-19 16:38:37 +08001220}
1221
1222/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +08001223* @brief: qser_wifi_ap_auth_get_s, Get the security authentication mode , password group_rekey and pairwise of 2.4G or 5G
1224* @param idx [IN]: int, Set 2.4G or 5G
1225* @param auth_mode [OUT]: lynq_wifi_ap_auth_t *, Get the security authentication mode
1226* @return : int, If equal to 0 succeeds, others fail
1227* @todo: NA
1228* @see: NA
1229* @warning: NA
1230*********************************************************************/
1231int qser_wifi_ap_auth_get_s(lynq_wifi_ap_index_e idx, lynq_wifi_ap_auth_t *auth_mode)
1232{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001233 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +08001234 int ret = -1;
1235 sc_wifi_ap_param_t param = {0};
1236 if (auth_mode == NULL)
1237 {
1238 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p\n", __func__, auth_mode);
1239 return ret;
1240 }
1241 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1242 if (0 != ret)
1243 {
1244 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1245 return ret;
1246 }
1247 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);
1248 strncpy(auth_mode->passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
1249 auth_mode->group_rekey = param.auth.group_rekey;
1250 auth_mode->pairwise = (lynq_wifi_auth_wpa_psk_e)param.auth.pairwise;
1251 auth_mode->auth = sc_to_lynq_auth_mode(param.auth.auth);
1252 return 0;
1253}
1254
1255/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001256* @brief: qser_wifi_ap_max_sta_set, Set the maximum number of STAs for 2.4G or 5G
1257* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001258* @param max_sta_num [IN]: int, Set the maximum number
1259* @return : int, If equal to 0 succeeds, others fail
1260* @todo: NA
1261* @see: NA
1262* @warning: NA
1263*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001264int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
wz.wang73504132024-03-19 16:38:37 +08001265{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001266 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001267 int ret = -1;
zw.wang48647fb2024-10-11 10:47:36 +08001268 if(max_sta_num >= 32)
1269 {
1270 LYERRLOG("[%s ] fail max_sta_num = %d\n", __func__,max_sta_num);
1271 return -1;
1272 }
wz.wange5a0b912024-03-22 19:11:59 +08001273 ret = sc_wifi_ap_max_sta_num_set((sc_wifi_ap_index_e)idx, max_sta_num);
1274 if (0 != ret)
1275 {
1276 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1277 return ret;
1278 }
1279 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, max_sta_num);
1280 return 0;
1281}
1282
1283/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001284* @brief: qser_wifi_ap_max_sta_get, Get the maximum number of STAs for 2.4G or 5G
1285* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +08001286* @param max_sta_num [OUT]: int *, Get the maximum number
1287* @return : int, If equal to 0 succeeds, others fail
1288* @todo: NA
1289* @see: NA
1290* @warning: NA
1291*********************************************************************/
1292int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int *max_sta_num)
1293{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001294 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001295 int ret = -1;
1296 sc_wifi_ap_param_t param = {0};
1297 if (max_sta_num == NULL)
1298 {
1299 LYERRLOG("[%s ] Null pointer max_sta_num = 0x%p\n", __func__,max_sta_num);
1300 return ret;
1301 }
1302 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1303 if (0 != ret)
1304 {
1305 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1306 return ret;
1307 }
1308 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, param.max_sta_num);
1309 *max_sta_num = param.max_sta_num;
1310 return 0;
wz.wang73504132024-03-19 16:38:37 +08001311}
1312
1313/********************************************************************
wz.wang72c432c2024-06-18 09:16:26 +08001314* @brief: qser_wifi_lanhost_get_list, Get sta device information received as an ap for 2.4G or 5G
1315* @param lynq_arrays [OUT]: lynq_lanhost_ts *, Get sta device information received as an ap
1316* @return : int, If equal to 0 succeeds, others fail
1317* @todo: NA
1318* @see: NA
1319* @warning: NA
1320*********************************************************************/
1321int qser_wifi_lanhost_get_list(lynq_lanhost_ts *lynq_arrays)
1322{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001323 WIFI_ENABLE_JUDGE();
wz.wang72c432c2024-06-18 09:16:26 +08001324 int ret = -1;
1325 int i = 0;
1326 sc_lanhost_t array[32] = {0};
1327 if (lynq_arrays == NULL)
1328 {
1329 LYERRLOG("[%s ] Null pointer lynq_arrays = 0x%p\n", __func__, lynq_arrays);
1330 return ret;
1331 }
1332 lynq_arrays->array_len = 32;
zw.wang0044b012024-08-08 11:48:49 +08001333 ret = sc_wifi_lanhost_get_list(array, &lynq_arrays->array_len);
wz.wang72c432c2024-06-18 09:16:26 +08001334 if (0 != ret)
1335 {
1336 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
1337 return ret;
1338 }
1339 LYINFLOG("[%s]ap_lanhost len[%d]\n", __func__, lynq_arrays->array_len);
1340 for (i = 0; i < lynq_arrays->array_len; i++)
1341 {
1342 LYINFLOG("[%s]Element : [%d] ifname = %s macaddr = %s addr = %s name = %s uptime = %d\n", __func__, i,
1343 array[i].ifname, array[i].macaddr, array[i].addr, array[i].name, array[i].uptime);
1344 strncpy(lynq_arrays->array[i].ifname, array[i].ifname, sizeof(lynq_arrays->array[i].ifname) - 1);
1345 strncpy(lynq_arrays->array[i].macaddr, array[i].macaddr, sizeof(lynq_arrays->array[i].macaddr) - 1);
1346 strncpy(lynq_arrays->array[i].addr, array[i].addr, sizeof(lynq_arrays->array[i].addr) - 1);
1347 strncpy(lynq_arrays->array[i].name, array[i].name, sizeof(lynq_arrays->array[i].name) - 1);
1348 lynq_arrays->array[i].uptime = array[i].uptime;
1349 }
1350 return 0;
1351}
1352
1353/********************************************************************
1354* @brief: qser_wifi_get_ap_pkt_stats, Obtain data packets sent and received by ap for 2.4G or 5G
1355* @param idx [IN]: int, Set 2.4G or 5G
1356* @param pkt_stat [OUT]: lynq_wifi_pkt_stats_t *, Obtain data packets sent and received by ap
1357* @return : int, If equal to 0 succeeds, others fail
1358* @todo: NA
1359* @see: NA
1360* @warning: NA
1361*********************************************************************/
1362int qser_wifi_get_ap_pkt_stats(lynq_wifi_ap_index_e idx, lynq_wifi_pkt_stats_t *pkt_stat)
1363{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001364 WIFI_ENABLE_JUDGE();
wz.wang72c432c2024-06-18 09:16:26 +08001365 int ret = -1;
1366 sc_wifi_pkt_stats_t stat = {0};
1367 if (pkt_stat == NULL)
1368 {
1369 LYERRLOG("[%s ] Null pointer pkt_stat = 0x%p\n", __func__, pkt_stat);
1370 return ret;
1371 }
1372 idx = LYNQ_WIFI_AP_INDEX_AP0;
1373 ret = sc_wifi_get_ap_pkt_stats((sc_wifi_ap_index_e)idx, &stat);
1374 if (0 != ret)
1375 {
1376 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
1377 return ret;
1378 }
1379 LYINFLOG("[%s ]ap_pkt_get[%d] rx[%llu, %llu, %llu, %llu] tx[%llu, %llu, %llu, %llu]\n", __func__, idx,
1380 stat.rx_packets, stat.rx_bytes, stat.rx_errors, stat.rx_dropped,
1381 stat.tx_packets, stat.tx_bytes, stat.tx_errors, stat.tx_dropped);
1382 pkt_stat->rx_packets = stat.rx_packets;
1383 pkt_stat->rx_bytes = stat.rx_bytes;
1384 pkt_stat->rx_errors = stat.rx_errors;
1385 pkt_stat->rx_dropped = stat.rx_dropped;
1386 pkt_stat->tx_packets = stat.tx_packets;
1387 pkt_stat->tx_bytes = stat.tx_bytes;
1388 pkt_stat->tx_errors = stat.tx_errors;
1389 pkt_stat->tx_dropped = stat.tx_dropped;
1390 return 0;
1391}
1392
1393/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001394* @brief: qser_wifi_ap_start, Set the ap mode of 2.4G or 5G to enable
1395* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001396* @return : int, If equal to 0 succeeds, others fail
1397* @todo: NA
1398* @see: NA
1399* @warning: NA
1400*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001401int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001402{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001403 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001404 int ret = -1;
1405 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
1406 if (0 != ret)
1407 {
1408 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1409 return ret;
1410 }
1411 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1412 return 0;
wz.wang73504132024-03-19 16:38:37 +08001413}
1414
1415/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001416* @brief: qser_wifi_ap_stop, Disable ap mode for 2.4G or 5G
1417* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001418* @return : int, If equal to 0 succeeds, others fail
1419* @todo: NA
1420* @see: NA
1421* @warning: NA
1422*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001423int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001424{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001425 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001426 int ret = -1;
1427 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
1428 if (0 != ret)
1429 {
1430 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1431 return ret;
1432 }
1433 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1434 return 0;
wz.wang73504132024-03-19 16:38:37 +08001435}
1436
1437/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001438* @brief: qser_wifi_ap_restart, Set the ap mode of 2.4G or 5G to restart
1439* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001440* @return : int, If equal to 0 succeeds, others fail
1441* @todo: NA
1442* @see: NA
1443* @warning: NA
1444*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001445int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001446{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001447 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001448 int ret = -1;
1449 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
wz.wang73504132024-03-19 16:38:37 +08001450 if (0 != ret)
1451 {
wz.wang9f658672024-04-15 14:23:58 +08001452 LYERRLOG("[%s ] stop ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +08001453 return ret;
wz.wang73504132024-03-19 16:38:37 +08001454 }
wz.wange5a0b912024-03-22 19:11:59 +08001455 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
1456 if (0 != ret)
1457 {
wz.wang9f658672024-04-15 14:23:58 +08001458 LYERRLOG("[%s ] start ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +08001459 return ret;
1460 }
1461 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1462 return 0;
wz.wang73504132024-03-19 16:38:37 +08001463}
1464
wz.wang9f658672024-04-15 14:23:58 +08001465/********************************************************************
1466* @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 +08001467* @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 +08001468* @return : int, If equal to 0 succeeds, others fail
1469* @todo: NA
1470* @see: NA
1471* @warning: NA
1472*********************************************************************/
wz.wang5bbe6d62024-05-29 13:39:35 +08001473int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *param_stat)
wz.wang9f658672024-04-15 14:23:58 +08001474{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001475 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001476 int ret = -1;
1477 sc_wifi_sta_param_t stat = {0};
wz.wang5bbe6d62024-05-29 13:39:35 +08001478 stat.auth = lynq_to_sc_auth_mode(param_stat->auth);
1479 stat.pairwise = (sc_wifi_auth_wpa_psk_e )param_stat->pairwise;
1480 strncpy(stat.ssid, param_stat->ssid, sizeof(stat.ssid) - 1);
1481 strncpy(stat.passwd, param_stat->passwd, sizeof(stat.passwd) - 1);
wz.wang9f658672024-04-15 14:23:58 +08001482 ret = sc_wifi_sta_param_set(&stat);
1483 if (0 != ret)
1484 {
1485 LYERRLOG("[%s ] sta_param_set ret = %d\n", __func__,ret);
1486 return ret;
1487 }
1488 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1489 return 0;
1490}
1491
1492/********************************************************************
1493* @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 +08001494* @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 +08001495* @return : int, If equal to 0 succeeds, others fail
1496* @todo: NA
1497* @see: NA
1498* @warning: NA
1499*********************************************************************/
wz.wang5bbe6d62024-05-29 13:39:35 +08001500int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *param_stat)
wz.wang9f658672024-04-15 14:23:58 +08001501{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001502 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001503 int ret = -1;
1504 sc_wifi_sta_param_t stat = {0};
1505 ret = sc_wifi_sta_param_get(&stat);
1506 if (0 != ret)
1507 {
1508 LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__,ret);
1509 return ret;
1510 }
wz.wang5bbe6d62024-05-29 13:39:35 +08001511 param_stat->auth = sc_to_lynq_auth_mode(stat.auth);
1512 param_stat->pairwise = (lynq_wifi_auth_wpa_psk_e )stat.pairwise;
1513 strncpy(param_stat->ssid, stat.ssid, sizeof(stat.ssid) - 1);
1514 strncpy(param_stat->passwd, stat.passwd, sizeof(stat.passwd) -1);
1515 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1516 return 0;
1517}
1518
1519/********************************************************************
1520* @brief: qser_wifi_sta_get_status, Gets the status value associated with sta
1521* @param status_stat [OUT]: lynq_wifi_sta_status_t *, Gets the status value associated with sta
1522* @return : int, If equal to 0 succeeds, others fail
1523* @todo: NA
1524* @see: NA
1525* @warning: NA
1526*********************************************************************/
wz.wang72c432c2024-06-18 09:16:26 +08001527int qser_wifi_sta_get_status(lynq_wifi_sta_status_t *status_stat)
wz.wang5bbe6d62024-05-29 13:39:35 +08001528{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001529 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +08001530 int ret = -1;
1531 sc_wifi_sta_status_t stat;
1532 ret = sc_wifi_sta_get_status(&stat);
1533 if (0 != ret)
1534 {
wz.wang72c432c2024-06-18 09:16:26 +08001535 LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__, ret);
wz.wang5bbe6d62024-05-29 13:39:35 +08001536 return ret;
1537 }
wz.wang72c432c2024-06-18 09:16:26 +08001538 print_sta_status(&stat);
zw.wang0044b012024-08-08 11:48:49 +08001539 sc_to_lynq_sta_status(&stat, status_stat);
wz.wang9f658672024-04-15 14:23:58 +08001540 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1541 return 0;
1542}
1543
1544/********************************************************************
wz.wang72c432c2024-06-18 09:16:26 +08001545* @brief: qser_wifi_get_sta_pkt_stats, Obtain data packets sent and received by sta for 2.4G or 5G
1546* @param pkt_stat [OUT]: lynq_wifi_pkt_stats_t *, Obtain data packets sent and received by sta
1547* @return : int, If equal to 0 succeeds, others fail
1548* @todo: NA
1549* @see: NA
1550* @warning: NA
1551*********************************************************************/
1552int qser_wifi_get_sta_pkt_stats(lynq_wifi_pkt_stats_t *pkt_stat)
1553{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001554 WIFI_ENABLE_JUDGE();
wz.wang72c432c2024-06-18 09:16:26 +08001555 int ret = -1;
1556 sc_wifi_pkt_stats_t stat = {0};
1557 if (pkt_stat == NULL)
1558 {
1559 LYERRLOG("[%s ] Null pointer pkt_stat = 0x%p\n", __func__, pkt_stat);
1560 return ret;
1561 }
1562 ret = sc_wifi_get_sta_pkt_stats(&stat);
1563 if (0 != ret)
1564 {
1565 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
1566 return ret;
1567 }
1568 LYINFLOG("[%s ]sta_pkt_get rx[%llu, %llu, %llu, %llu] tx[%llu, %llu, %llu, %llu]\n", __func__,
1569 stat.rx_packets, stat.rx_bytes, stat.rx_errors, stat.rx_dropped,
1570 stat.tx_packets, stat.tx_bytes, stat.tx_errors, stat.tx_dropped);
1571 pkt_stat->rx_packets = stat.rx_packets;
1572 pkt_stat->rx_bytes = stat.rx_bytes;
1573 pkt_stat->rx_errors = stat.rx_errors;
1574 pkt_stat->rx_dropped = stat.rx_dropped;
1575 pkt_stat->tx_packets = stat.tx_packets;
1576 pkt_stat->tx_bytes = stat.tx_bytes;
1577 pkt_stat->tx_errors = stat.tx_errors;
1578 pkt_stat->tx_dropped = stat.tx_dropped;
1579 return 0;
1580}
1581
1582/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +08001583* @brief: qser_wifi_sta_start_scan, Scan for ap nodes and return them through callback
1584* @return : int, If equal to 0 succeeds, others fail
1585* @todo: NA
1586* @see: NA
1587* @warning: NA
1588*********************************************************************/
1589int qser_wifi_sta_start_scan(void)
1590{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001591 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001592 int ret = -1;
1593 ret = sc_wifi_sta_start_scan();
1594 if (0 != ret)
1595 {
1596 LYERRLOG("[%s ] scan ret = %d\n", __func__,ret);
1597 return ret;
1598 }
1599 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1600 return 0;
1601}
1602
1603/********************************************************************
1604* @brief: qser_wifi_sta_start, To enable sta mode, you need to enable ap mode first
1605* @return : int, If equal to 0 succeeds, others fail
1606* @todo: NA
1607* @see: NA
1608* @warning: NA
1609*********************************************************************/
1610int qser_wifi_sta_start(void)
1611{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001612 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001613 int ret = -1;
1614 ret = sc_wifi_sta_start();
1615 if (0 != ret)
1616 {
1617 LYERRLOG("[%s ] sta_start ret = %d\n", __func__,ret);
1618 return ret;
1619 }
1620 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1621 return 0;
1622}
1623
1624/********************************************************************
1625* @brief: qser_wifi_sta_stop, To disable sta mode.
1626* @return : int, If equal to 0 succeeds, others fail
1627* @todo: NA
1628* @see: NA
1629* @warning: NA
1630*********************************************************************/
1631int qser_wifi_sta_stop(void)
1632{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001633 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001634 int ret = -1;
1635 ret = sc_wifi_sta_stop();
1636 if (0 != ret)
1637 {
1638 LYERRLOG("[%s ] sta_stop ret = %d\n", __func__,ret);
1639 return ret;
1640 }
1641 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1642 return 0;
1643}
1644
you.chen154c1912025-06-25 17:12:30 +08001645
1646//wifi2
1647
1648/********************************************************************
1649* @brief: qser_wifi_work_mode_set, 2.4g or 5g working mode Settings
1650* @param type [IN]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Settings
1651* @return : int, If equal to 0 succeeds, others fail
1652* @todo: NA
1653* @see: NA
1654* @warning: NA
1655*********************************************************************/
1656int qser_wifi2_work_mode_set(lynq_wifi_work_mode_e type)
1657{
1658 WIFI2_ENABLE_JUDGE();
1659 int ret = -1;
1660 sc_wifi_work_mode_e mode;
1661 ret = sc_wifi_work_mode_get_ext(1, &mode);
1662 if (0 != ret)
1663 {
1664 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
1665 return ret;
1666 }
1667 if(mode == (sc_wifi_work_mode_e)type) //The same value is returned
1668 {
1669 return 0;
1670 }
1671 ret = sc_wifi_work_mode_set_ext(1, (sc_wifi_work_mode_e)type);
1672 if (0 != ret)
1673 {
1674 LYERRLOG("[%s ] work_mode set ret = %d\n", __func__,ret);
1675 return ret;
1676 }
1677 LYINFLOG("[%s ]\n", __func__);
1678 return 0;
1679}
1680
1681/********************************************************************
1682* @brief: qser_wifi_work_mode_get, 2.4g or 5g working mode Gettings
1683* @param type [OUT]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Gettings
1684* @return : int, If equal to 0 succeeds, others fail
1685* @todo: NA
1686* @see: NA
1687* @warning: NA
1688*********************************************************************/
1689int qser_wifi2_work_mode_get(lynq_wifi_work_mode_e *type)
1690{
1691 WIFI2_ENABLE_JUDGE();
1692 int ret = -1;
1693 sc_wifi_work_mode_e mode;
1694 ret = sc_wifi_work_mode_get_ext(1, &mode);
1695 if (0 != ret)
1696 {
1697 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
1698 return ret;
1699 }
1700 *type = (lynq_wifi_work_mode_e)mode;
1701 LYINFLOG("[%s ]\n", __func__);
1702 return 0;
1703}
1704
1705/********************************************************************
1706* @brief: qser_wifi_register_handle, Register callback functions
1707* @param event_handle [IN]: lynq_wifi_event_handle, Register the ap event callback function
1708* @param event_handle_sta [IN]: Register sta's event callback function
1709* @param arg [IN]: void *, Not currently used, but cannot pass a null pointer
1710* @return :int, If equal to 0 succeeds, others fail
1711* @todo: NA
1712* @see: NA
1713* @warning: NA
1714*********************************************************************/
1715int qser_wifi2_register_handle(lynq_wifi_event_handle event_handle, lynq_wifi_event_handle_sta event_handle_sta, void *arg)
1716{
1717 if((event_handle == NULL && event_handle_sta == NULL) || arg == NULL)
1718 {
1719 LYERRLOG("[%s ] NUll pointer event_handle = 0x%p arg = 0x%p\n", __func__, event_handle, arg);
1720 return -1;
1721 }
1722 if(*(int *)arg <= LYNQ_WIFI_EVENT_MIN || *(int *)arg >= LYNQ_WIFI_EVENT_MAX)
1723 {
1724 LYERRLOG("[%s ] The value of arg can only be an integer ranging from 0 to 3p, arg = %d\n", __func__, arg);
1725 return -1;
1726 }
1727 wifi2_event_handle_sta = event_handle_sta;
1728 wifi2_event_handle = event_handle;
1729 global_arg_2 = arg;
1730 return 0;
1731}
1732
1733/********************************************************************
1734* @brief: qser_wifi_enable, Enable WiFi function
1735* @return : int, If equal to 0 succeeds, others fail
1736* @todo: NA
1737* @see: NA
1738* @warning: NA
1739*********************************************************************/
1740int qser_wifi2_enable(void)
1741{
1742 if(lynq_wifi2_enable)
1743 {
1744 LYERRLOG("[%s ] The wifi is enabled\n", __func__);
1745 return -1;
1746 }
1747 wifi2_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
1748 char wifiAvailable[8] = {0};
1749 sc_cfg_get("wifiAvailable", wifiAvailable, sizeof(wifiAvailable));
1750 if (!strcmp(wifiAvailable, "0"))
1751 {
1752 LYERRLOG("[%s ] wifiAvailable has been set to 0. If WiFi is used, set 1 to enable it\n", __func__);
1753 return -1;
1754 }
1755 int ret = -1;
1756 ret = sc_wifi_init();
1757 if (0 != ret)
1758 {
1759 LYERRLOG("[%s ] init wifi ret = %d fail\n", __func__,ret);
1760 return ret;
1761 }
1762 //wifi
1763 ret = sc_wifi_set_enable_status_ind_cb_ext(1, lynq_user2_status);
1764 if (0 != ret)
1765 {
1766 LYERRLOG("[%s ] Request lynq_user_status ret = %d fail\n", __func__,ret);
1767 return ret;
1768 }
1769
1770 //ap
1771 ret = sc_wifi_ap_set_status_ind_cb_ext(1, lynq_user2_ap_status);
1772 if (0 != ret)
1773 {
1774 LYERRLOG("[%s ] Request lynq_user_ap_status ret = %d fail\n", __func__,ret);
1775 return ret;
1776 }
1777 ret = sc_wifi_set_ap_sta_connect_ind_cb_ext(1, lynq_user2_ap_sta_conn_status);
1778 if (0 != ret)
1779 {
1780 LYERRLOG("[%s ] Request lynq_user_ap_sta_conn_status ret = %d fail\n", __func__,ret);
1781 return ret;
1782 }
1783
1784 //sta
1785 ret = sc_wifi_sta_set_status_ind_cb_ext(1, lynq_user2_sta_status_ind);
1786 if (0 != ret)
1787 {
1788 LYERRLOG("[%s ] Request lynq_user_sta_status_ind ret = %d fail\n", __func__,ret);
1789 return ret;
1790 }
1791 ret = sc_wifi_sta_set_scan_result_ind_cb_ext(1, lynq_user2_sta_scan_result_ind);
1792 if (0 != ret)
1793 {
1794 LYERRLOG("[%s ] Request lynq_user_sta_scan_result_ind ret = %d fail\n", __func__,ret);
1795 return ret;
1796 }
1797 //proxy
1798 ret = sc_wifi_set_service_error_cb(lynq_user2_wifi_service_error);
1799 if (0 != ret)
1800 {
1801 LYERRLOG("[%s ] Request lynq_user_wifi_service_error ret = %d fail\n", __func__,ret);
1802 return ret;
1803 }
1804
1805 ret = sc_wifi_enable_ext(1);
1806 if (0 != ret)
1807 {
1808 LYERRLOG("[%s ] enable wifi ret = %d fail\n", __func__,ret);
1809 return ret;
1810 }
1811 for(int i = 0; i < WIFI_ENABLE_FLAG_TIME_OUT; i++)
1812 {
1813 if(wifi2_enable_flag == WIFI_ENABLE_FLAG_DEFAULT)
1814 sleep(1);
1815 else
1816 break;
1817 }
1818 switch (wifi2_enable_flag)
1819 {
1820 case SC_WIFI_STATUS_DISABLED:
1821 ret = 1;
1822 break;
1823 case SC_WIFI_STATUS_ENABLED:
1824 ret = 0;
1825 break;
1826 case SC_WIFI_STATUS_INVALID_MAC:
1827 ret = 7;
1828 break;
1829 case SC_WIFI_STATUS_DEV_INIT_FAIL:
1830 ret = 6;
1831 break;
1832 case SC_WIFI_STATUS_FIRMWARE_CRASH:
1833 ret = 12;
1834 break;
1835 default:
1836 ret = -1;
1837 break;
1838 }
1839 LYINFLOG("[%s ] ret = %d\n", __func__,ret);
1840 if(ret == 0)
1841 lynq_wifi2_enable = true;
1842 return ret;
1843}
1844
1845/********************************************************************
1846* @brief: qser_wifi_disable, Turn off WiFi
1847* @return : int, If equal to 0 succeeds, others fail
1848* @todo: NA
1849* @see: NA
1850* @warning: NA
1851*********************************************************************/
1852int qser_wifi2_disable(void)
1853{
1854 int ret = -1;
1855 wifi2_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
1856 if(lynq_wifi2_enable == false)
1857 {
1858 LYERRLOG("[%s ] WiFi not turned on\n", __func__);
1859 return -1;
1860 }
1861 ret = sc_wifi_disable_ext(1);
1862 if (0 != ret)
1863 {
1864 LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
1865 return ret;
1866 }
1867 for(int i = 0; i < WIFI_ENABLE_FLAG_TIME_OUT; i++)
1868 {
1869 if(wifi2_enable_flag == WIFI_ENABLE_FLAG_DEFAULT)
1870 sleep(1);
1871 else
1872 break;
1873 }
1874 switch (wifi2_enable_flag)
1875 {
1876 case SC_WIFI_STATUS_DISABLED:
1877 ret = 0;
1878 break;
1879 case SC_WIFI_STATUS_INVALID_MAC:
1880 ret = 7;
1881 break;
1882 case SC_WIFI_STATUS_DEV_INIT_FAIL:
1883 ret = 6;
1884 break;
1885 case SC_WIFI_STATUS_FIRMWARE_CRASH:
1886 ret = 12;
1887 break;
1888 default:
1889 ret = -1;
1890 break;
1891 }
1892 if (0 != ret)
1893 {
1894 LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
1895 return ret;
1896 }
1897 lynq_wifi2_enable = false;
1898 ret = sc_wifi_uninit();
1899 if (0 != ret)
1900 {
1901 LYERRLOG("[%s ] uninit ret = %d\n", __func__,ret);
1902 return ret;
1903 }
1904 LYINFLOG("[%s ]\n", __func__);
1905 return 0;
1906}
1907
1908/********************************************************************
1909* @brief: qser_wifi_ap_get_status, Example Query ap working status
1910* @param type [OUT]: lynq_wifi_ap_status_t *, ap working status
1911* @return : int, If equal to 0 succeeds, others fail
1912* @todo: NA
1913* @see: NA
1914* @warning: NA
1915*********************************************************************/
1916int qser_wifi2_ap_get_status(lynq_wifi_ap_index_e idx, lynq_wifi_ap_status_t *ap_stat)
1917{
1918 WIFI2_ENABLE_JUDGE();
1919 int ret = -1;
1920 sc_wifi_ap_status_t stat;
1921 ret = sc_wifi_ap_get_status_ext(1, (sc_wifi_ap_index_e)idx, &stat);
1922 if (0 != ret)
1923 {
1924 LYERRLOG("[%s ] wifi_ap_get ret = %d\n", __func__,ret);
1925 return ret;
1926 }
1927 LYINFLOG("[%s ] idx = %d ifname = %s status = %d bssid = %s \n", __func__, idx, stat.ifname, stat.status, stat.bssid);
1928 strncpy(ap_stat->ifname, stat.ifname, sizeof(stat.ifname) - 1);
1929 ap_stat->status = (lynq_wifi_status_e)stat.status;
1930 strncpy(ap_stat->bssid, stat.bssid, sizeof(stat.bssid) - 1);
1931 return 0;
1932}
1933
1934/********************************************************************
1935* @brief: qser_wifi_ap_acl_set, Set the WiFi2.4G or 5G whitelist
1936* @param idx [IN]: int, Set 2.4G or 5G
1937* @param acl_rule [IN]: lynq_wifi_mac_acl_rule_e, Set the blacklist and whitelist mode
1938* @param mac_list [IN]: char *, Set the mac address of the whitelist
1939* @return : int, If equal to 0 succeeds, others fail
1940* @todo: NA
1941* @see: NA
1942* @warning: NA
1943*********************************************************************/
1944int qser_wifi2_ap_acl_set(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e acl_rule, char *mac_list)
1945{
1946 WIFI2_ENABLE_JUDGE();
1947 int ret = -1;
1948 if (mac_list == NULL)
1949 {
1950 LYERRLOG("[%s ] Null pointer mac_list = 0x%p \n", __func__, mac_list);
1951 return ret;
1952 }
1953 if(acl_rule == LYNQ_WIFI_MAC_ACL_RULE_BLACK)
1954 ret = sc_wifi_ap_acl_set_ext(1, (sc_wifi_ap_index_e)idx, SC_WIFI_MAC_ACL_RULE_WHITE, mac_list);
1955 ret = sc_wifi_ap_acl_set_ext(1, (sc_wifi_ap_index_e)idx, (sc_wifi_mac_acl_rule_e)acl_rule, mac_list);
1956 if (0 != ret)
1957 {
1958 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1959 return ret;
1960 }
1961 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, acl_rule, mac_list);
1962 return 0;
1963}
1964
1965/********************************************************************
1966* @brief: qser_wifi_ap_acl_get, Get the WiFi2.4G or 5G whitelist
1967* @param idx [IN]: int, Set 2.4G or 5G
1968* @param acl_rule [OUT]: lynq_wifi_mac_acl_rule_e *, Get the blacklist and whitelist mode
1969* @param mac_list [OUT]: char *, Get the mac address of the whitelist
1970* @return : int, If equal to 0 succeeds, others fail
1971* @todo: NA
1972* @see: NA
1973* @warning: NA
1974*********************************************************************/
1975int qser_wifi2_ap_acl_get(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e *acl_rule, char *mac_list)
1976{
1977 WIFI2_ENABLE_JUDGE();
1978 int ret = -1;
1979 sc_wifi_ap_param_t param = {0};
1980 if (mac_list == NULL || acl_rule == NULL)
1981 {
1982 LYERRLOG("[%s ] Null pointer acl_rule = 0x%p mac_list = 0x%p \n", __func__, acl_rule, mac_list);
1983 return ret;
1984 }
1985 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
1986 if (0 != ret)
1987 {
1988 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1989 return ret;
1990 }
1991 *acl_rule = (lynq_wifi_mac_acl_rule_e)param.acl_rule;
1992 strncpy(mac_list, param.mac_list, sizeof(param.mac_list) - 1);
1993 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, param.acl_rule, param.mac_list);
1994 return 0;
1995}
1996
1997/********************************************************************
1998* @brief: qser_wifi_ap_ssid_set, Set the name of the ssid of 2.4G or 5G
1999* @param idx [IN]: int, Set 2.4G or 5G
2000* @param ssid [IN]: const char *, Set the ssid name
2001* @return : int, If equal to 0 succeeds, others fail
2002* @todo: NA
2003* @see: NA
2004* @warning: NA
2005*********************************************************************/
2006int qser_wifi2_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
2007{
2008 WIFI2_ENABLE_JUDGE();
2009 int ret = -1;
2010 if (ssid == NULL)
2011 {
2012 LYERRLOG("[%s ] Null pointer ssid = 0x%p \n", __func__, ssid);
2013 return ret;
2014 }
2015 ret = sc_wifi_ap_ssid_set_ext(1, (sc_wifi_ap_index_e)idx, ssid);
2016 if (0 != ret)
2017 {
2018 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2019 return ret;
2020 }
2021 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, ssid);
2022 return 0;
2023}
2024
2025/********************************************************************
2026* @brief: qser_wifi_ap_ssid_get, Get the name of the ssid of 2.4G or 5G
2027* @param idx [IN]: int, Set 2.4G or 5G
2028* @param ssid [OUT]: char *, Get the ssid name
2029* @return : int, If equal to 0 succeeds, others fail
2030* @todo: NA
2031* @see: NA
2032* @warning: NA
2033*********************************************************************/
2034int qser_wifi2_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
2035{
2036 WIFI2_ENABLE_JUDGE();
2037 int ret = -1;
2038 sc_wifi_ap_param_t param = {0};
2039 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2040 if (0 != ret)
2041 {
2042 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2043 return ret;
2044 }
2045 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, param.ssid);
2046 strncpy(ssid, param.ssid, sizeof(param.ssid) - 1);
2047 return 0;
2048}
2049
2050/********************************************************************
2051* @brief: qser_wifi_ap_ssid_hide_set, Set whether the ssid of 2.4G or 5G is hidden
2052* @param idx [IN]: int, Set 2.4G or 5G
2053* @param hide [IN]: bool, Set whether the ssid is hidden
2054* @return : int, If equal to 0 succeeds, others fail
2055* @todo: NA
2056* @see: NA
2057* @warning: NA
2058*********************************************************************/
2059int qser_wifi2_ap_ssid_hide_set(lynq_wifi_ap_index_e idx, bool hide)
2060{
2061 WIFI2_ENABLE_JUDGE();
2062 int ret = -1;
2063 ret = sc_wifi_ap_ssid_hidden_set_ext(1, (sc_wifi_ap_index_e)idx, (int)hide);
2064 if (0 != ret)
2065 {
2066 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2067 return ret;
2068 }
2069 LYINFLOG("[%s ] idx = %d hide = %d \n", __func__, idx, hide);
2070 return 0;
2071}
2072
2073/********************************************************************
2074* @brief: qser_wifi_ap_ssid_hide_get, Get whether the ssid of 2.4G or 5G is hidden
2075* @param idx [IN]: int, Set 2.4G or 5G
2076* @param hide [OUT]: bool *, Get whether the ssid is hidden
2077* @return : int, If equal to 0 succeeds, others fail
2078* @todo: NA
2079* @see: NA
2080* @warning: NA
2081*********************************************************************/
2082int qser_wifi2_ap_ssid_hide_get(lynq_wifi_ap_index_e idx, bool *hide)
2083{
2084 WIFI2_ENABLE_JUDGE();
2085 int ret = -1;
2086 sc_wifi_ap_param_t param = {0};
2087 if (hide == NULL)
2088 {
2089 LYERRLOG("[%s ] Null pointer hide = 0x%p \n", __func__, hide);
2090 return ret;
2091 }
2092 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2093 if (0 != ret)
2094 {
2095 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2096 return ret;
2097 }
2098 LYINFLOG("[%s ] idx = %d ssid_hide = %d \n", __func__, idx, param.ssid_hide);
2099 *hide = (bool)param.ssid_hide;
2100 return 0;
2101}
2102
2103/********************************************************************
2104* @brief: qser_wifi_ap_mode_set, Set the working protocol mode of 2.4G or 5G
2105* @param idx [IN]: int, Set 2.4G or 5G
2106* @param mode [IN]: lynq_wifi_mode_type_e, Set the working protocol mode
2107* @return : int, If equal to 0 succeeds, others fail
2108* @todo: NA
2109* @see: NA
2110* @warning: NA
2111*********************************************************************/
2112int qser_wifi2_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
2113{
2114 WIFI2_ENABLE_JUDGE();
2115 int ret = -1;
2116 ret = sc_wifi_ap_mode_set_ext(1, (sc_wifi_ap_index_e)idx, lynq_to_sc_mode(mode));
2117 if (0 != ret)
2118 {
2119 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2120 return ret;
2121 }
2122 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, mode);
2123 return 0;
2124}
2125
2126/********************************************************************
2127* @brief: qser_wifi_ap_mode_get, Get the working protocol mode of 2.4G or 5G
2128* @param idx [IN]: int, Set 2.4G or 5G
2129* @param mode [OUT]: lynq_wifi_mode_type_e *, Get the working protocol mode
2130* @return : int, If equal to 0 succeeds, others fail
2131* @todo: NA
2132* @see: NA
2133* @warning: NA
2134*********************************************************************/
2135int qser_wifi2_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e *mode)
2136{
2137 WIFI2_ENABLE_JUDGE();
2138 int ret = -1;
2139 sc_wifi_ap_param_t param = {0};
2140 if (mode == NULL)
2141 {
2142 LYERRLOG("[%s ] Null pointer mode = 0x%p \n", __func__, mode);
2143 return ret;
2144 }
2145 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2146 if (0 != ret)
2147 {
2148 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2149 return ret;
2150 }
2151 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, param.mode);
2152 *mode = sc_to_lynq_mode(param.mode);
2153 return 0;
2154}
2155
2156/********************************************************************
2157* @brief: qser_wifi_ap_bandwidth_set, Set the bandwidth of 2.4G or 5G
2158* @param idx [IN]: int, Set 2.4G or 5G
2159* @param bandwidth [IN]: lynq_wifi_bandwidth_type_e, Set the bandwidth
2160* @return : int, If equal to 0 succeeds, others fail
2161* @todo: NA
2162* @see: NA
2163* @warning: NA
2164*********************************************************************/
2165int qser_wifi2_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
2166{
2167 WIFI2_ENABLE_JUDGE();
2168 int ret = -1;
2169 ret = sc_wifi_ap_bandwidth_set_ext(1, (sc_wifi_ap_index_e)idx, (sc_wifi_bandwidth_e)bandwidth);
2170 if (0 != ret)
2171 {
2172 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2173 return ret;
2174 }
2175 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, bandwidth);
2176 return 0;
2177}
2178
2179/********************************************************************
2180* @brief: qser_wifi_ap_bandwidth_get, Get the bandwidth of 2.4G or 5G
2181* @param idx [IN]: int, Set 2.4G or 5G
2182* @param bandwidth [OUT]: lynq_wifi_bandwidth_type_e *, Get the bandwidth
2183* @return : int, If equal to 0 succeeds, others fail
2184* @todo: NA
2185* @see: NA
2186* @warning: NA
2187*********************************************************************/
2188int qser_wifi2_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
2189{
2190 WIFI2_ENABLE_JUDGE();
2191 int ret = -1;
2192 sc_wifi_ap_param_t param = {0};
2193 if (bandwidth == NULL)
2194 {
2195 LYERRLOG("[%s ] Null pointer bandwidth = 0x%p \n", __func__, bandwidth);
2196 return ret;
2197 }
2198 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2199 if (0 != ret)
2200 {
2201 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2202 return ret;
2203 }
2204 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, param.bandwidth);
2205 *bandwidth = (lynq_wifi_bandwidth_type_e)param.bandwidth;
2206 return 0;
2207}
2208
2209/********************************************************************
2210* @brief: qser_wifi_ap_channel_set, Set the channel for 2.4G or 5G
2211* @param idx [IN]: int, Set 2.4G or 5G
2212* @param country_code [IN]: const char *, Set country code
2213* @param channel [IN]: int, Set the channel
2214* @return : int, If equal to 0 succeeds, others fail
2215* @todo: NA
2216* @see: NA
2217* @warning: NA
2218*********************************************************************/
2219int qser_wifi2_ap_channel_set(lynq_wifi_ap_index_e idx, const char *country_code, int channel)
2220{
2221 WIFI2_ENABLE_JUDGE();
2222 int ret = -1;
2223 if (country_code == NULL)
2224 {
2225 LYERRLOG("[%s ] Null pointer country_code = 0x%p \n", __func__, country_code);
2226 return ret;
2227 }
2228 ret = sc_wifi_ap_cc_ch_set_ext(1, (sc_wifi_ap_index_e)idx, country_code, channel);
2229 if (0 != ret)
2230 {
2231 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2232 return ret;
2233 }
2234 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, country_code, channel);
2235 return 0;
2236}
2237
2238/********************************************************************
2239* @brief: qser_wifi_ap_channel_get, Get the channel for 2.4G or 5G
2240* @param idx [IN]: int, Set 2.4G or 5G
2241* @param country_code [OUT]: char *, Get country code
2242* @param channel [OUT]: int *, Get the channel
2243* @return : int, If equal to 0 succeeds, others fail
2244* @todo: NA
2245* @see: NA
2246* @warning: NA
2247*********************************************************************/
2248int qser_wifi2_ap_channel_get(lynq_wifi_ap_index_e idx, char *country_code, int *channel)
2249{
2250 WIFI2_ENABLE_JUDGE();
2251 int ret = -1;
2252 sc_wifi_ap_param_t param = {0};
2253 if (country_code == NULL || channel == NULL)
2254 {
2255 LYERRLOG("[%s ] Null pointer country_code = 0x%p channel = 0x%p\n", __func__, country_code, channel);
2256 return ret;
2257 }
2258 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2259 if (0 != ret)
2260 {
2261 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2262 return ret;
2263 }
2264 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, param.countrycode, param.channel);
2265 strncpy(country_code, param.countrycode, sizeof(param.countrycode) - 1);
2266 *channel = param.channel;
2267 return 0;
2268}
2269
2270/********************************************************************
2271* @brief: qser_wifi_ap_auth_set, Set the security authentication mode and password of 2.4G or 5G
2272* @param idx [IN]: int, Set 2.4G or 5G
2273* @param auth_mode [IN]: lynq_wifi_auth_e, Set the security authentication mode
2274* @param auth_passwd [IN]: const char *, Set password
2275* @return : int, If equal to 0 succeeds, others fail
2276* @todo: NA
2277* @see: NA
2278* @warning: NA
2279*********************************************************************/
2280int qser_wifi2_ap_auth_set(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e auth_mode, const char *auth_passwd)
2281{
2282 WIFI2_ENABLE_JUDGE();
2283 int ret = -1;
2284 if (auth_passwd == NULL)
2285 {
2286 LYERRLOG("[%s ] Null pointer auth_passwd = 0x%p\n", __func__, auth_passwd);
2287 return ret;
2288 }
2289
2290 sc_wifi_ap_auth_t auth;
2291 auth.auth = lynq_to_sc_auth_mode(auth_mode);
2292 strncpy(auth.passwd, auth_passwd, sizeof(auth.passwd) - 1);
2293 ret = sc_wifi_ap_auth_set_ext(1, (sc_wifi_ap_index_e)idx, &auth);
2294 if (0 != ret)
2295 {
2296 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2297 return ret;
2298 }
2299 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s\n", __func__, idx, auth_mode, "******");
2300 return 0;
2301}
2302
2303/********************************************************************
2304* @brief: qser_wifi_ap_auth_get, Get the security authentication mode and password of 2.4G or 5G
2305* @param idx [IN]: int, Set 2.4G or 5G
2306* @param auth_mode [OUT]: lynq_wifi_auth_e *, Get the security authentication mode
2307* @param auth_passwd [OUT]: char *, Get password
2308* @return : int, If equal to 0 succeeds, others fail
2309* @todo: NA
2310* @see: NA
2311* @warning: NA
2312*********************************************************************/
2313int qser_wifi2_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char *auth_passwd)
2314{
2315 WIFI2_ENABLE_JUDGE();
2316 int ret = -1;
2317 sc_wifi_ap_param_t param = {0};
2318 if (auth_mode == NULL || auth_passwd == NULL)
2319 {
2320 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p auth_passwd = 0x%p\n", __func__, auth_mode, auth_passwd);
2321 return ret;
2322 }
2323 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2324 if (0 != ret)
2325 {
2326 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2327 return ret;
2328 }
2329 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s \n", __func__, idx, param.auth.auth, param.auth.passwd);
2330 strncpy(auth_passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
2331
2332 *auth_mode = sc_to_lynq_auth_mode(param.auth.auth);
2333 return 0;
2334}
2335
2336/********************************************************************
2337* @brief: qser_wifi_ap_auth_get_s, Get the security authentication mode , password group_rekey and pairwise of 2.4G or 5G
2338* @param idx [IN]: int, Set 2.4G or 5G
2339* @param auth_mode [OUT]: lynq_wifi_ap_auth_t *, Get the security authentication mode
2340* @return : int, If equal to 0 succeeds, others fail
2341* @todo: NA
2342* @see: NA
2343* @warning: NA
2344*********************************************************************/
2345int qser_wifi2_ap_auth_get_s(lynq_wifi_ap_index_e idx, lynq_wifi_ap_auth_t *auth_mode)
2346{
2347 WIFI2_ENABLE_JUDGE();
2348 int ret = -1;
2349 sc_wifi_ap_param_t param = {0};
2350 if (auth_mode == NULL)
2351 {
2352 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p\n", __func__, auth_mode);
2353 return ret;
2354 }
2355 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2356 if (0 != ret)
2357 {
2358 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2359 return ret;
2360 }
2361 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);
2362 strncpy(auth_mode->passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
2363 auth_mode->group_rekey = param.auth.group_rekey;
2364 auth_mode->pairwise = (lynq_wifi_auth_wpa_psk_e)param.auth.pairwise;
2365 auth_mode->auth = sc_to_lynq_auth_mode(param.auth.auth);
2366 return 0;
2367}
2368
2369/********************************************************************
2370* @brief: qser_wifi_ap_max_sta_set, Set the maximum number of STAs for 2.4G or 5G
2371* @param idx [IN]: int, Set 2.4G or 5G
2372* @param max_sta_num [IN]: int, Set the maximum number
2373* @return : int, If equal to 0 succeeds, others fail
2374* @todo: NA
2375* @see: NA
2376* @warning: NA
2377*********************************************************************/
2378int qser_wifi2_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
2379{
2380 WIFI2_ENABLE_JUDGE();
2381 int ret = -1;
2382 if(max_sta_num >= 32)
2383 {
2384 LYERRLOG("[%s ] fail max_sta_num = %d\n", __func__,max_sta_num);
2385 return -1;
2386 }
2387 ret = sc_wifi_ap_max_sta_num_set_ext(1, (sc_wifi_ap_index_e)idx, max_sta_num);
2388 if (0 != ret)
2389 {
2390 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2391 return ret;
2392 }
2393 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, max_sta_num);
2394 return 0;
2395}
2396
2397/********************************************************************
2398* @brief: qser_wifi_ap_max_sta_get, Get the maximum number of STAs for 2.4G or 5G
2399* @param idx [IN]: int, Set 2.4G or 5G
2400* @param max_sta_num [OUT]: int *, Get the maximum number
2401* @return : int, If equal to 0 succeeds, others fail
2402* @todo: NA
2403* @see: NA
2404* @warning: NA
2405*********************************************************************/
2406int qser_wifi2_ap_max_sta_get(lynq_wifi_ap_index_e idx, int *max_sta_num)
2407{
2408 WIFI2_ENABLE_JUDGE();
2409 int ret = -1;
2410 sc_wifi_ap_param_t param = {0};
2411 if (max_sta_num == NULL)
2412 {
2413 LYERRLOG("[%s ] Null pointer max_sta_num = 0x%p\n", __func__,max_sta_num);
2414 return ret;
2415 }
2416 ret = sc_wifi_ap_param_get_ext(1, (sc_wifi_ap_index_e)idx, &param);
2417 if (0 != ret)
2418 {
2419 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2420 return ret;
2421 }
2422 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, param.max_sta_num);
2423 *max_sta_num = param.max_sta_num;
2424 return 0;
2425}
2426
2427/********************************************************************
2428* @brief: qser_wifi_lanhost_get_list, Get sta device information received as an ap for 2.4G or 5G
2429* @param lynq_arrays [OUT]: lynq_lanhost_ts *, Get sta device information received as an ap
2430* @return : int, If equal to 0 succeeds, others fail
2431* @todo: NA
2432* @see: NA
2433* @warning: NA
2434*********************************************************************/
2435int qser_wifi2_lanhost_get_list(lynq_lanhost_ts *lynq_arrays)
2436{
2437 WIFI2_ENABLE_JUDGE();
2438 int ret = -1;
2439 int i = 0;
2440 sc_lanhost_t array[32] = {0};
2441 if (lynq_arrays == NULL)
2442 {
2443 LYERRLOG("[%s ] Null pointer lynq_arrays = 0x%p\n", __func__, lynq_arrays);
2444 return ret;
2445 }
2446 lynq_arrays->array_len = 32;
2447 ret = sc_wifi_lanhost_get_list_ext(1, array, &lynq_arrays->array_len);
2448 if (0 != ret)
2449 {
2450 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
2451 return ret;
2452 }
2453 LYINFLOG("[%s]ap_lanhost len[%d]\n", __func__, lynq_arrays->array_len);
2454 for (i = 0; i < lynq_arrays->array_len; i++)
2455 {
2456 LYINFLOG("[%s]Element : [%d] ifname = %s macaddr = %s addr = %s name = %s uptime = %d\n", __func__, i,
2457 array[i].ifname, array[i].macaddr, array[i].addr, array[i].name, array[i].uptime);
2458 strncpy(lynq_arrays->array[i].ifname, array[i].ifname, sizeof(lynq_arrays->array[i].ifname) - 1);
2459 strncpy(lynq_arrays->array[i].macaddr, array[i].macaddr, sizeof(lynq_arrays->array[i].macaddr) - 1);
2460 strncpy(lynq_arrays->array[i].addr, array[i].addr, sizeof(lynq_arrays->array[i].addr) - 1);
2461 strncpy(lynq_arrays->array[i].name, array[i].name, sizeof(lynq_arrays->array[i].name) - 1);
2462 lynq_arrays->array[i].uptime = array[i].uptime;
2463 }
2464 return 0;
2465}
2466
2467/********************************************************************
2468* @brief: qser_wifi_get_ap_pkt_stats, Obtain data packets sent and received by ap for 2.4G or 5G
2469* @param idx [IN]: int, Set 2.4G or 5G
2470* @param pkt_stat [OUT]: lynq_wifi_pkt_stats_t *, Obtain data packets sent and received by ap
2471* @return : int, If equal to 0 succeeds, others fail
2472* @todo: NA
2473* @see: NA
2474* @warning: NA
2475*********************************************************************/
2476int qser_wifi2_get_ap_pkt_stats(lynq_wifi_ap_index_e idx, lynq_wifi_pkt_stats_t *pkt_stat)
2477{
2478 WIFI2_ENABLE_JUDGE();
2479 int ret = -1;
2480 sc_wifi_pkt_stats_t stat = {0};
2481 if (pkt_stat == NULL)
2482 {
2483 LYERRLOG("[%s ] Null pointer pkt_stat = 0x%p\n", __func__, pkt_stat);
2484 return ret;
2485 }
2486 idx = LYNQ_WIFI_AP_INDEX_AP0;
2487 ret = sc_wifi_get_ap_pkt_stats_ext(1, (sc_wifi_ap_index_e)idx, &stat);
2488 if (0 != ret)
2489 {
2490 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
2491 return ret;
2492 }
2493 LYINFLOG("[%s ]ap_pkt_get[%d] rx[%llu, %llu, %llu, %llu] tx[%llu, %llu, %llu, %llu]\n", __func__, idx,
2494 stat.rx_packets, stat.rx_bytes, stat.rx_errors, stat.rx_dropped,
2495 stat.tx_packets, stat.tx_bytes, stat.tx_errors, stat.tx_dropped);
2496 pkt_stat->rx_packets = stat.rx_packets;
2497 pkt_stat->rx_bytes = stat.rx_bytes;
2498 pkt_stat->rx_errors = stat.rx_errors;
2499 pkt_stat->rx_dropped = stat.rx_dropped;
2500 pkt_stat->tx_packets = stat.tx_packets;
2501 pkt_stat->tx_bytes = stat.tx_bytes;
2502 pkt_stat->tx_errors = stat.tx_errors;
2503 pkt_stat->tx_dropped = stat.tx_dropped;
2504 return 0;
2505}
2506
2507/********************************************************************
2508* @brief: qser_wifi_ap_start, Set the ap mode of 2.4G or 5G to enable
2509* @param idx [IN]: int, Set 2.4G or 5G
2510* @return : int, If equal to 0 succeeds, others fail
2511* @todo: NA
2512* @see: NA
2513* @warning: NA
2514*********************************************************************/
2515int qser_wifi2_ap_start(lynq_wifi_ap_index_e idx)
2516{
2517 WIFI2_ENABLE_JUDGE();
2518 int ret = -1;
2519 ret = sc_wifi_ap_start_ext(1, (sc_wifi_ap_index_e)idx);
2520 if (0 != ret)
2521 {
2522 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2523 return ret;
2524 }
2525 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
2526 return 0;
2527}
2528
2529/********************************************************************
2530* @brief: qser_wifi_ap_stop, Disable ap mode for 2.4G or 5G
2531* @param idx [IN]: int, Set 2.4G or 5G
2532* @return : int, If equal to 0 succeeds, others fail
2533* @todo: NA
2534* @see: NA
2535* @warning: NA
2536*********************************************************************/
2537int qser_wifi2_ap_stop(lynq_wifi_ap_index_e idx)
2538{
2539 WIFI2_ENABLE_JUDGE();
2540 int ret = -1;
2541 ret = sc_wifi_ap_stop_ext(1, (sc_wifi_ap_index_e)idx);
2542 if (0 != ret)
2543 {
2544 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
2545 return ret;
2546 }
2547 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
2548 return 0;
2549}
2550
2551/********************************************************************
2552* @brief: qser_wifi_ap_restart, Set the ap mode of 2.4G or 5G to restart
2553* @param idx [IN]: int, Set 2.4G or 5G
2554* @return : int, If equal to 0 succeeds, others fail
2555* @todo: NA
2556* @see: NA
2557* @warning: NA
2558*********************************************************************/
2559int qser_wifi2_ap_restart(lynq_wifi_ap_index_e idx)
2560{
2561 WIFI2_ENABLE_JUDGE();
2562 int ret = -1;
2563 ret = sc_wifi_ap_stop_ext(1, (sc_wifi_ap_index_e)idx);
2564 if (0 != ret)
2565 {
2566 LYERRLOG("[%s ] stop ret = %d\n", __func__,ret);
2567 return ret;
2568 }
2569 ret = sc_wifi_ap_start_ext(1, (sc_wifi_ap_index_e)idx);
2570 if (0 != ret)
2571 {
2572 LYERRLOG("[%s ] start ret = %d\n", __func__,ret);
2573 return ret;
2574 }
2575 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
2576 return 0;
2577}
2578
wz.wange5a0b912024-03-22 19:11:59 +08002579DEFINE_LYNQ_LIB_LOG(LYNQ_WIFI)
wz.wang73504132024-03-19 16:38:37 +08002580
2581#ifdef __cplusplus
2582}
2583#endif