blob: f3cb0bf4866748e6b7331bd5a71f8033231302f5 [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
30/********************************************************************
31* @brief: lynq_to_sc_auth_mode, The encryption mode of wifi is changed from api to platform
wz.wang0feef142024-04-23 18:08:39 +080032* @return :sc_wifi_auth_e, all
wz.wang9f658672024-04-15 14:23:58 +080033* @todo: NA
34* @see: NA
35* @warning: NA
36*********************************************************************/
37static sc_wifi_auth_e lynq_to_sc_auth_mode(lynq_wifi_auth_e auth_mode)
38{
39 sc_wifi_auth_e type;
40 switch (auth_mode)
41 {
42 case LYNQ_WIFI_AUTH_OPEN:
43 type = SC_WIFI_AUTH_OPEN;
44 break;
45 case LYNQ_WIFI_AUTH_WPA2_PSK:
46 type = SC_WIFI_AUTH_WPA2_PSK;
47 break;
48 case LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
49 type = SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
50 break;
51 case LYNQ_WIFI_AUTH_WPA3_PSK:
52 type = SC_WIFI_AUTH_WPA3_PSK;
53 break;
54 case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
55 type = SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
56 break;
57 default:
58 type = SC_WIFI_AUTH_MIN;
59 break;
60 }
wz.wang0feef142024-04-23 18:08:39 +080061 return type;
62}
wz.wang9f658672024-04-15 14:23:58 +080063
64/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +080065* @brief: sc_to_lynq_auth_mode, The wifi protocol moves from platform to api
66* @return :lynq_wifi_auth_e, all
wz.wang9f658672024-04-15 14:23:58 +080067* @todo: NA
68* @see: NA
69* @warning: NA
70*********************************************************************/
71static lynq_wifi_auth_e sc_to_lynq_auth_mode(sc_wifi_auth_e auth_mode)
72{
73 lynq_wifi_auth_e type;
74 switch (auth_mode)
75 {
76 case SC_WIFI_AUTH_OPEN:
77 type = LYNQ_WIFI_AUTH_OPEN;
78 break;
79 case SC_WIFI_AUTH_WPA2_PSK:
80 type = LYNQ_WIFI_AUTH_WPA2_PSK;
81 break;
82 case SC_WIFI_AUTH_WPA_WPA2_PSK_BOTH:
83 type = LYNQ_WIFI_AUTH_WPA_WPA2_PSK_BOTH;
84 break;
85 case SC_WIFI_AUTH_WPA3_PSK:
86 type = LYNQ_WIFI_AUTH_WPA3_PSK;
87 break;
88 case SC_WIFI_AUTH_WPA2_WPA3_PSK_BOTH:
89 type = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK_BOTH;
90 break;
91 default:
92 type = LYNQ_WIFI_AUTH_MIN;
93 break;
94 }
wz.wang0feef142024-04-23 18:08:39 +080095 return type;
96}
97
98/********************************************************************
99* @brief: lynq_to_sc_mode, The wifi protocol is transferred from api to platform
100* @return :sc_wifi_ap_mode_type_e, all
101* @todo: NA
102* @see: NA
103* @warning: NA
104*********************************************************************/
105static sc_wifi_ap_mode_type_e lynq_to_sc_mode(lynq_wifi_mode_type_e mode)
106{
107 sc_wifi_ap_mode_type_e type;
108 switch (mode)
109 {
110 case LYNQ_WIFI_MODE_80211BGN:
111 type = SC_WIFI_AP_MODE_80211BGN;
112 break;
113 case LYNQ_WIFI_MODE_80211BGNAX_2G:
114 type = SC_WIFI_AP_MODE_80211BGNAX_2G;
115 break;
116 case LYNQ_WIFI_MODE_80211AN:
117 type = SC_WIFI_AP_MODE_80211AN;
118 break;
119 case LYNQ_WIFI_MODE_80211ANAC:
120 type = SC_WIFI_AP_MODE_80211ANAC;
121 break;
122 case LYNQ_WIFI_MODE_80211ANACAX_5G:
123 type = SC_WIFI_AP_MODE_80211ANACAX_5G;
124 break;
125 default:
126 type = SC_WIFI_AP_MODE_MIN;
127 break;
128 }
129 return type;
130}
131
132/********************************************************************
133* @brief: sc_to_lynq_mode, The encryption mode of wifi is changed from platform to api
134* @return :lynq_wifi_mode_type_e, all
135* @todo: NA
136* @see: NA
137* @warning: NA
138*********************************************************************/
139static lynq_wifi_mode_type_e sc_to_lynq_mode(sc_wifi_ap_mode_type_e mode)
140{
141 lynq_wifi_mode_type_e type;
142 switch (mode)
143 {
144 case SC_WIFI_AP_MODE_80211BGN:
145 type = LYNQ_WIFI_MODE_80211BGN;
146 break;
147 case SC_WIFI_AP_MODE_80211BGNAX_2G:
148 type = LYNQ_WIFI_MODE_80211BGNAX_2G;
149 break;
150 case SC_WIFI_AP_MODE_80211AN:
151 type = LYNQ_WIFI_MODE_80211AN;
152 break;
153 case SC_WIFI_AP_MODE_80211ANAC:
154 type = LYNQ_WIFI_MODE_80211ANAC;
155 break;
156 case SC_WIFI_AP_MODE_80211ANACAX_5G:
157 type = LYNQ_WIFI_MODE_80211ANACAX_5G;
158 break;
159 default:
160 type = LYNQ_WIFI_MODE_MIN;
161 break;
162 }
163 return type;
164}
wz.wang9f658672024-04-15 14:23:58 +0800165
166/********************************************************************
zw.wang0044b012024-08-08 11:48:49 +0800167* @brief: sc_to_lynq_sta_status, sc_wifi_sta_status_t to lynq_wifi_sta_status_t
168* @return :int, all
169* @todo: NA
170* @see: NA
171* @warning: NA
172*********************************************************************/
173static int sc_to_lynq_sta_status(sc_wifi_sta_status_t *stat, lynq_wifi_sta_status_t *status_stat)
174{
175 status_stat->status = (lynq_wifi_sta_status_e)stat->status;
176 status_stat->signal_level = stat->signal_level;
177 status_stat->has_addr = stat->has_addr;
178 status_stat->has_addr6 = stat->has_addr6;
179 status_stat->reason_code = (lynq_wifi_reason_code_e)stat->reason_code;
180 strncpy(status_stat->ifname, stat->ifname, sizeof(stat->ifname) - 1);
181 strncpy(status_stat->ap_bssid, stat->ap_bssid, sizeof(stat->ap_bssid) - 1);
182 if (status_stat->has_addr == 1)
183 {
184 strncpy(status_stat->addr.addr, stat->addr.addr, sizeof(status_stat->addr.addr) - 1);
185 strncpy(status_stat->addr.netmask, stat->addr.netmask, sizeof(status_stat->addr.netmask) - 1);
186 status_stat->addr.subnet_bits = stat->addr.subnet_bits;
187 strncpy(status_stat->addr.gateway, stat->addr.gateway, sizeof(status_stat->addr.gateway) - 1);
188 strncpy(status_stat->addr.dnsp, stat->addr.dnsp, sizeof(status_stat->addr.dnsp) - 1);
189 strncpy(status_stat->addr.dnss, stat->addr.dnss, sizeof(status_stat->addr.dnss) - 1);
190 }
191 if (status_stat->has_addr6 == 1)
192 {
193 strncpy(status_stat->addr6.addr, stat->addr6.addr, sizeof(status_stat->addr6.addr) - 1);
194 strncpy(status_stat->addr6.prefix, stat->addr6.prefix, sizeof(status_stat->addr6.prefix) - 1);
195 status_stat->addr6.prefix_bits = stat->addr6.prefix_bits;
196 strncpy(status_stat->addr6.gateway, stat->addr6.gateway, sizeof(status_stat->addr6.gateway) - 1);
197 strncpy(status_stat->addr6.dnsp, stat->addr6.dnsp, sizeof(status_stat->addr6.dnsp) - 1);
198 strncpy(status_stat->addr6.dnss, stat->addr6.dnss, sizeof(status_stat->addr6.dnss) - 1);
199 }
200 return 0;
201}
202
203/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +0800204* @brief: lynq_user_status, wifi startup callback
205* @return : NA
206* @todo: NA
207* @see: NA
208* @warning: NA
209*********************************************************************/
210static void lynq_user_status(sc_wifi_enable_status_e pre_status, sc_wifi_enable_status_e status)
211{
zw.wangf4578ce2024-08-14 10:58:38 +0800212 wifi_enable_flag = status;
213 LYINFLOG("%s:%d,%d wifi_enable_flag:%d\n", __func__, pre_status, status, wifi_enable_flag);
wz.wang9f658672024-04-15 14:23:58 +0800214}
215
216/********************************************************************
217* @brief: lynq_user_wifi_service_error, wifi service status callback
218* @return : NA
219* @todo: NA
220* @see: NA
221* @warning: NA
222*********************************************************************/
223static void lynq_user_wifi_service_error(int error)
224{
225 LYINFLOG("%s: %d\n", __func__, error);
226}
227
228/********************************************************************
229* @brief: lynq_user_ap_status, wifi Obtains the ap status callback
230* @return : NA
231* @todo: NA
232* @see: NA
233* @warning: NA
234*********************************************************************/
235static 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)
236{
wz.wang5bbe6d62024-05-29 13:39:35 +0800237 lynq_wifi_event_s event;
238 if (wifi_event_handle != NULL && global_arg != NULL)
wz.wang9f658672024-04-15 14:23:58 +0800239 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800240 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
241 {
242 return;
243 }
zw.wang0044b012024-08-08 11:48:49 +0800244 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
wz.wang5bbe6d62024-05-29 13:39:35 +0800245 event.id = LYNQ_WIFI_EVENT_AP_STATION;
zw.wangf6fbbc02024-09-02 11:43:46 +0800246 event.status = (lynq_wifi_status_e)p_msg->status;
wz.wang5bbe6d62024-05-29 13:39:35 +0800247 wifi_event_handle(&event, global_arg);
wz.wang9f658672024-04-15 14:23:58 +0800248 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800249 else
250 {
wz.wang9f658672024-04-15 14:23:58 +0800251 LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
252 }
wz.wang9f658672024-04-15 14:23:58 +0800253}
254
255/********************************************************************
256* @brief: lynq_user_ap_sta_conn_status, wifi as ap is sta information callback
257* @return : NA
258* @todo: NA
259* @see: NA
260* @warning: NA
261*********************************************************************/
262static void lynq_user_ap_sta_conn_status(sc_wifi_ap_index_e index, sc_wifi_sta_connect_status_t *p_msg)
263{
wz.wang5bbe6d62024-05-29 13:39:35 +0800264 char hostname[32] = {0};
265 lynq_wifi_event_s event;
266 int ret = sc_wifi_get_hostname_by_mac(p_msg->macaddr, hostname, sizeof(hostname));
267 if (ret == 0)
wz.wang9f658672024-04-15 14:23:58 +0800268 {
zw.wang0044b012024-08-08 11:48:49 +0800269 LYINFLOG("sta ip not assigned, try again later!\n");
wz.wang9f658672024-04-15 14:23:58 +0800270 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800271 if (wifi_event_handle != NULL && global_arg != NULL)
272 {
273 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
274 {
275 return;
276 }
zw.wang0044b012024-08-08 11:48:49 +0800277 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
278 event.id = LYNQ_WIFI_EVENT_AP_STA_STATUS;
wz.wang5bbe6d62024-05-29 13:39:35 +0800279 event.ap_sta_info.connected = p_msg->is_connected;
280 strncpy(event.ap_sta_info.mac, p_msg->macaddr,
281 sizeof(event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(event.ap_sta_info.mac) : sizeof(p_msg->macaddr));
282 strncpy(event.ap_sta_info.hostname, hostname, sizeof(hostname));
283 wifi_event_handle(&event, global_arg);
wz.wang9f658672024-04-15 14:23:58 +0800284 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800285 else
286 {
287 LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
288 }
289}
wz.wang9f658672024-04-15 14:23:58 +0800290
291/********************************************************************
292* @brief: print_sta_status, wifi gets the status callback in sta mode
293* @return : NA
294* @todo: NA
295* @see: NA
296* @warning: NA
297*********************************************************************/
298static void print_sta_status(sc_wifi_sta_status_t *p_msg)
299{
wz.wang72c432c2024-06-18 09:16:26 +0800300 LYINFLOG("%s: %d, %s, %s, %d, %d\n", __func__, p_msg->status, p_msg->ifname, p_msg->ap_bssid,
301 p_msg->signal_level, p_msg->reason_code);
wz.wang9f658672024-04-15 14:23:58 +0800302
wz.wang72c432c2024-06-18 09:16:26 +0800303 if (p_msg->has_addr == 1)
304 {
305 LYINFLOG("[%s]addr ip:%s, netmask:%s, subnet_bits:%d, gateway:%s, dnsp:%s, dnss:%s\n", __func__,
306 p_msg->addr.addr, p_msg->addr.netmask, p_msg->addr.subnet_bits,
307 p_msg->addr.gateway, p_msg->addr.dnsp, p_msg->addr.dnss);
308 }
wz.wang9f658672024-04-15 14:23:58 +0800309
wz.wang72c432c2024-06-18 09:16:26 +0800310 if (p_msg->has_addr6 == 1)
311 {
312 LYINFLOG("[%s]addr6 ip:%s, prefix:%s, prefix_bits:%d, gateway:%s, dnsp:%s, dnss:%s\n", __func__,
313 p_msg->addr6.addr, p_msg->addr6.prefix, p_msg->addr6.prefix_bits,
314 p_msg->addr6.gateway, p_msg->addr6.dnsp, p_msg->addr6.dnss);
315 }
316 LYINFLOG("%s : sta_status end\n", __func__);
wz.wang9f658672024-04-15 14:23:58 +0800317}
318
319/********************************************************************
320* @brief: lynq_user_sta_status_ind, wifi gets the status callback in sta mode
321* @return : NA
322* @todo: NA
323* @see: NA
324* @warning: NA
325*********************************************************************/
326static void lynq_user_sta_status_ind(sc_wifi_sta_status_e pre_status,
327 sc_wifi_sta_status_t *p_msg)
328{
zw.wang0044b012024-08-08 11:48:49 +0800329 if (wifi_event_handle != NULL && global_arg != NULL)
330 {
331 lynq_wifi_event_s event;
332 if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
333 {
334 return;
335 }
336 LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
337 event.id = LYNQ_WIFI_EVENT_STA_STATUS;
338 if(p_msg->status == SC_WIFI_STA_STATUS_CONNECTED)
339 event.sta_status = LYNQ_WIFI_STATION_CONNECTED;
340 else if(p_msg->status == SC_WIFI_STA_STATUS_DISCONNECTED)
341 event.sta_status = LYNQ_WIFI_STATION_DISCONNECTED;
342 else
343 event.sta_status = LYNQ_WIFI_STATION_DISABLE;
344 sc_to_lynq_sta_status(p_msg, &event.sta_status_all);
345 event.sta_status_all.sta_status = event.sta_status;
346 wifi_event_handle(&event, global_arg);
347 }
348 else
349 {
350 print_sta_status(p_msg);
351 }
352
wz.wang9f658672024-04-15 14:23:58 +0800353}
354
355/********************************************************************
356* @brief: lynq_user_sta_scan_result_ind, wifi gets the callback of sta mode traversing the hotspot
357* @return : NA
358* @todo: NA
359* @see: NA
360* @warning: NA
361*********************************************************************/
362static void lynq_user_sta_scan_result_ind(sc_wifi_sta_scan_list_t *p_msg)
363{
wz.wang0feef142024-04-23 18:08:39 +0800364 int i = 0;
365 LYINFLOG("%s : user_sta_scan_result_ind_cb:%d\n", __func__, p_msg->cnt);
366 if (p_msg->cnt <= 0)
367 {
368 return;
369 }
370 if (wifi_event_handle_sta != NULL)
371 {
372 lynq_wifi_sta_scan_list_t event;
373 event.cnt = p_msg->cnt;
374 for (i = 0; i < event.cnt; i++)
375 {
376 strncpy(event.info[i].essid, p_msg->info[i].essid, sizeof(p_msg->info[i].essid));
377 strncpy(event.info[i].bssid, p_msg->info[i].bssid, sizeof(p_msg->info[i].bssid));
378 event.info[i].auth = sc_to_lynq_auth_mode(p_msg->info[i].auth);
379 event.info[i].cipher = (lynq_wifi_auth_wpa_psk_e)p_msg->info[i].cipher;
380 event.info[i].channel = p_msg->info[i].channel;
381 event.info[i].signal_level = p_msg->info[i].signal_level;
wz.wang5bbe6d62024-05-29 13:39:35 +0800382 event.info[i].frequency = p_msg->info[i].frequency;
383 event.info[i].signal = p_msg->info[i].signal;
wz.wang0feef142024-04-23 18:08:39 +0800384 }
385 wifi_event_handle_sta(&event);
386 }
387 else
388 {
389 for (i = 0; i < p_msg->cnt; i++)
390 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800391 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),
392 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 +0800393 }
394 }
395}
396
397/********************************************************************
398* @brief: qser_wifi_work_mode_set, 2.4g or 5g working mode Settings
399* @param type [IN]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Settings
400* @return : int, If equal to 0 succeeds, others fail
401* @todo: NA
402* @see: NA
403* @warning: NA
404*********************************************************************/
405int qser_wifi_work_mode_set(lynq_wifi_work_mode_e type)
406{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800407 WIFI_ENABLE_JUDGE();
wz.wang0feef142024-04-23 18:08:39 +0800408 int ret = -1;
wz.wang5bbe6d62024-05-29 13:39:35 +0800409 sc_wifi_work_mode_e mode;
410 ret = sc_wifi_work_mode_get(&mode);
411 if (0 != ret)
412 {
413 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
414 return ret;
415 }
416 if(mode == (sc_wifi_work_mode_e)type) //The same value is returned
417 {
418 return 0;
419 }
wz.wang0feef142024-04-23 18:08:39 +0800420 ret = sc_wifi_work_mode_set((sc_wifi_work_mode_e)type);
421 if (0 != ret)
422 {
wz.wang5bbe6d62024-05-29 13:39:35 +0800423 LYERRLOG("[%s ] work_mode set ret = %d\n", __func__,ret);
wz.wang0feef142024-04-23 18:08:39 +0800424 return ret;
425 }
426 LYINFLOG("[%s ]\n", __func__);
427 return 0;
wz.wang9f658672024-04-15 14:23:58 +0800428}
429
430/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +0800431* @brief: qser_wifi_work_mode_get, 2.4g or 5g working mode Gettings
432* @param type [OUT]: lynq_wifi_work_mode_e, 2.4G or 5G working mode Gettings
433* @return : int, If equal to 0 succeeds, others fail
434* @todo: NA
435* @see: NA
436* @warning: NA
437*********************************************************************/
438int qser_wifi_work_mode_get(lynq_wifi_work_mode_e *type)
439{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800440 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800441 int ret = -1;
442 sc_wifi_work_mode_e mode;
443 ret = sc_wifi_work_mode_get(&mode);
444 if (0 != ret)
445 {
446 LYERRLOG("[%s ] work_mode get ret = %d\n", __func__,ret);
447 return ret;
448 }
449 *type = (lynq_wifi_work_mode_e)mode;
450 LYINFLOG("[%s ]\n", __func__);
451 return 0;
452}
453
454/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +0800455* @brief: qser_wifi_register_handle, Register callback functions
wz.wang0feef142024-04-23 18:08:39 +0800456* @param event_handle [IN]: lynq_wifi_event_handle, Register the ap event callback function
457* @param event_handle_sta [IN]: Register sta's event callback function
458* @param arg [IN]: void *, Not currently used, but cannot pass a null pointer
wz.wang9f658672024-04-15 14:23:58 +0800459* @return :int, If equal to 0 succeeds, others fail
460* @todo: NA
461* @see: NA
462* @warning: NA
463*********************************************************************/
wz.wang0feef142024-04-23 18:08:39 +0800464int 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 +0800465{
wz.wang0feef142024-04-23 18:08:39 +0800466 if((event_handle == NULL && event_handle_sta == NULL) || arg == NULL)
wz.wang9f658672024-04-15 14:23:58 +0800467 {
468 LYERRLOG("[%s ] NUll pointer event_handle = 0x%p arg = 0x%p\n", __func__, event_handle, arg);
469 return -1;
470 }
wz.wang5bbe6d62024-05-29 13:39:35 +0800471 if(*(int *)arg <= LYNQ_WIFI_EVENT_MIN || *(int *)arg >= LYNQ_WIFI_EVENT_MAX)
472 {
473 LYERRLOG("[%s ] The value of arg can only be an integer ranging from 0 to 3p, arg = %d\n", __func__, arg);
474 return -1;
475 }
wz.wang0feef142024-04-23 18:08:39 +0800476 wifi_event_handle_sta = event_handle_sta;
wz.wang9f658672024-04-15 14:23:58 +0800477 wifi_event_handle = event_handle;
478 global_arg = arg;
479 return 0;
480}
481
wz.wang73504132024-03-19 16:38:37 +0800482/********************************************************************
483* @brief: qser_wifi_enable, Enable WiFi function
484* @return : int, If equal to 0 succeeds, others fail
485* @todo: NA
486* @see: NA
487* @warning: NA
488*********************************************************************/
489int qser_wifi_enable(void)
490{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800491 if(lynq_wifi_enable)
492 {
493 LYERRLOG("[%s ] The wifi is enabled\n", __func__);
494 return -1;
495 }
zw.wangf4578ce2024-08-14 10:58:38 +0800496 wifi_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
zw.wang0044b012024-08-08 11:48:49 +0800497 char wifiAvailable[8] = {0};
498 sc_cfg_get("wifiAvailable", wifiAvailable, sizeof(wifiAvailable));
499 if (!strcmp(wifiAvailable, "0"))
500 {
501 LYERRLOG("[%s ] wifiAvailable has been set to 0. If WiFi is used, set 1 to enable it\n", __func__);
502 return -1;
503 }
wz.wange5a0b912024-03-22 19:11:59 +0800504 int ret = -1;
505 ret = sc_wifi_init();
wz.wang73504132024-03-19 16:38:37 +0800506 if (0 != ret)
507 {
wz.wang9f658672024-04-15 14:23:58 +0800508 LYERRLOG("[%s ] init wifi ret = %d fail\n", __func__,ret);
509 return ret;
510 }
511
512 //wifi
513 ret = sc_wifi_set_enable_status_ind_cb(lynq_user_status);
514 if (0 != ret)
515 {
516 LYERRLOG("[%s ] Request lynq_user_status ret = %d fail\n", __func__,ret);
517 return ret;
518 }
519
520 //ap
521 ret = sc_wifi_ap_set_status_ind_cb(lynq_user_ap_status);
522 if (0 != ret)
523 {
524 LYERRLOG("[%s ] Request lynq_user_ap_status ret = %d fail\n", __func__,ret);
525 return ret;
526 }
527 ret = sc_wifi_set_ap_sta_connect_ind_cb(lynq_user_ap_sta_conn_status);
528 if (0 != ret)
529 {
530 LYERRLOG("[%s ] Request lynq_user_ap_sta_conn_status ret = %d fail\n", __func__,ret);
531 return ret;
532 }
533
534 //sta
535 ret = sc_wifi_sta_set_status_ind_cb(lynq_user_sta_status_ind);
536 if (0 != ret)
537 {
538 LYERRLOG("[%s ] Request lynq_user_sta_status_ind ret = %d fail\n", __func__,ret);
539 return ret;
540 }
541 ret = sc_wifi_sta_set_scan_result_ind_cb(lynq_user_sta_scan_result_ind);
542 if (0 != ret)
543 {
544 LYERRLOG("[%s ] Request lynq_user_sta_scan_result_ind ret = %d fail\n", __func__,ret);
545 return ret;
546 }
547 //proxy
548 ret = sc_wifi_set_service_error_cb(lynq_user_wifi_service_error);
549 if (0 != ret)
550 {
551 LYERRLOG("[%s ] Request lynq_user_wifi_service_error ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800552 return ret;
wz.wang73504132024-03-19 16:38:37 +0800553 }
wz.wange5a0b912024-03-22 19:11:59 +0800554
555 ret = sc_wifi_enable();
556 if (0 != ret)
557 {
wz.wang9f658672024-04-15 14:23:58 +0800558 LYERRLOG("[%s ] enable wifi ret = %d fail\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800559 return ret;
560 }
zw.wangf4578ce2024-08-14 10:58:38 +0800561 for(int i = 0; i < WIFI_ENABLE_FLAG_TIME_OUT; i++)
562 {
563 if(wifi_enable_flag == WIFI_ENABLE_FLAG_DEFAULT)
564 sleep(1);
565 else
566 break;
567 }
568 switch (wifi_enable_flag)
569 {
570 case SC_WIFI_STATUS_DISABLED:
571 ret = 1;
572 break;
573 case SC_WIFI_STATUS_ENABLED:
574 ret = 0;
575 break;
576 case SC_WIFI_STATUS_INVALID_MAC:
577 ret = 7;
578 break;
579 case SC_WIFI_STATUS_DEV_INIT_FAIL:
580 ret = 6;
581 break;
582 case SC_WIFI_STATUS_FIRMWARE_CRASH:
583 ret = 12;
584 break;
585 default:
586 ret = -1;
587 break;
588 }
zw.wangb8e9b0c2024-09-05 13:53:33 +0800589 LYINFLOG("[%s ] ret = %d\n", __func__,ret);
590 if(ret != 0)
591 {
592 int ret_uninit = sc_wifi_uninit();
593 if (0 != ret_uninit)
594 {
595 LYERRLOG("[%s ] uninit ret = %d\n", __func__,ret_uninit);
596 }
597 }
598 else
599 lynq_wifi_enable = true;
zw.wangf4578ce2024-08-14 10:58:38 +0800600 return ret;
wz.wang73504132024-03-19 16:38:37 +0800601}
602
603/********************************************************************
604* @brief: qser_wifi_disable, Turn off WiFi
605* @return : int, If equal to 0 succeeds, others fail
606* @todo: NA
607* @see: NA
608* @warning: NA
609*********************************************************************/
610int qser_wifi_disable(void)
611{
wz.wange5a0b912024-03-22 19:11:59 +0800612 int ret = -1;
zw.wangf4578ce2024-08-14 10:58:38 +0800613 wifi_enable_flag = WIFI_ENABLE_FLAG_DEFAULT;
zw.wangb8e9b0c2024-09-05 13:53:33 +0800614 if(lynq_wifi_enable == false)
615 {
616 LYERRLOG("[%s ] WiFi not turned on\n", __func__);
617 return -1;
618 }
wz.wange5a0b912024-03-22 19:11:59 +0800619 ret = sc_wifi_disable();
wz.wang73504132024-03-19 16:38:37 +0800620 if (0 != ret)
621 {
wz.wang0feef142024-04-23 18:08:39 +0800622 LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800623 return ret;
wz.wang73504132024-03-19 16:38:37 +0800624 }
zw.wangf4578ce2024-08-14 10:58:38 +0800625 for(int i = 0; i < WIFI_ENABLE_FLAG_TIME_OUT; i++)
626 {
627 if(wifi_enable_flag == WIFI_ENABLE_FLAG_DEFAULT)
628 sleep(1);
629 else
630 break;
631 }
632 switch (wifi_enable_flag)
633 {
634 case SC_WIFI_STATUS_DISABLED:
635 ret = 0;
636 break;
637 case SC_WIFI_STATUS_INVALID_MAC:
638 ret = 7;
639 break;
640 case SC_WIFI_STATUS_DEV_INIT_FAIL:
641 ret = 6;
642 break;
643 case SC_WIFI_STATUS_FIRMWARE_CRASH:
644 ret = 12;
645 break;
646 default:
647 ret = -1;
648 break;
649 }
650 if (0 != ret)
651 {
652 LYERRLOG("[%s ] disable ret = %d\n", __func__,ret);
653 return ret;
654 }
zw.wangb8e9b0c2024-09-05 13:53:33 +0800655 lynq_wifi_enable = false;
wz.wange5a0b912024-03-22 19:11:59 +0800656 ret = sc_wifi_uninit();
657 if (0 != ret)
658 {
wz.wang0feef142024-04-23 18:08:39 +0800659 LYERRLOG("[%s ] uninit ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +0800660 return ret;
661 }
662 LYINFLOG("[%s ]\n", __func__);
663 return 0;
wz.wang73504132024-03-19 16:38:37 +0800664}
665
666/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +0800667* @brief: qser_wifi_ap_get_status, Example Query ap working status
668* @param type [OUT]: lynq_wifi_ap_status_t *, ap working status
669* @return : int, If equal to 0 succeeds, others fail
670* @todo: NA
671* @see: NA
672* @warning: NA
673*********************************************************************/
674int qser_wifi_ap_get_status(lynq_wifi_ap_index_e idx, lynq_wifi_ap_status_t *ap_stat)
675{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800676 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800677 int ret = -1;
678 sc_wifi_ap_status_t stat;
679 ret = sc_wifi_ap_get_status((sc_wifi_ap_index_e)idx, &stat);
680 if (0 != ret)
681 {
682 LYERRLOG("[%s ] wifi_ap_get ret = %d\n", __func__,ret);
683 return ret;
684 }
685 LYINFLOG("[%s ] idx = %d ifname = %s status = %d bssid = %s \n", __func__, idx, stat.ifname, stat.status, stat.bssid);
686 strncpy(ap_stat->ifname, stat.ifname, sizeof(stat.ifname) - 1);
687 ap_stat->status = (lynq_wifi_status_e)stat.status;
688 strncpy(ap_stat->bssid, stat.bssid, sizeof(stat.bssid) - 1);
689 return 0;
690}
691
692/********************************************************************
693* @brief: qser_wifi_ap_acl_set, Set the WiFi2.4G or 5G whitelist
694* @param idx [IN]: int, Set 2.4G or 5G
695* @param acl_rule [IN]: lynq_wifi_mac_acl_rule_e, Set the blacklist and whitelist mode
696* @param mac_list [IN]: char *, Set the mac address of the whitelist
697* @return : int, If equal to 0 succeeds, others fail
698* @todo: NA
699* @see: NA
700* @warning: NA
701*********************************************************************/
702int qser_wifi_ap_acl_set(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e acl_rule, char *mac_list)
703{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800704 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800705 int ret = -1;
706 if (mac_list == NULL)
707 {
708 LYERRLOG("[%s ] Null pointer mac_list = 0x%p \n", __func__, mac_list);
709 return ret;
710 }
711 if(acl_rule == LYNQ_WIFI_MAC_ACL_RULE_BLACK)
712 ret = sc_wifi_ap_acl_set((sc_wifi_ap_index_e)idx, SC_WIFI_MAC_ACL_RULE_WHITE, mac_list);
713 ret = sc_wifi_ap_acl_set((sc_wifi_ap_index_e)idx, (sc_wifi_mac_acl_rule_e)acl_rule, mac_list);
714 if (0 != ret)
715 {
716 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
717 return ret;
718 }
719 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, acl_rule, mac_list);
720 return 0;
721}
722
723/********************************************************************
724* @brief: qser_wifi_ap_acl_get, Get the WiFi2.4G or 5G whitelist
725* @param idx [IN]: int, Set 2.4G or 5G
726* @param acl_rule [OUT]: lynq_wifi_mac_acl_rule_e *, Get the blacklist and whitelist mode
727* @param mac_list [OUT]: char *, Get the mac address of the whitelist
728* @return : int, If equal to 0 succeeds, others fail
729* @todo: NA
730* @see: NA
731* @warning: NA
732*********************************************************************/
733int qser_wifi_ap_acl_get(lynq_wifi_ap_index_e idx, lynq_wifi_mac_acl_rule_e *acl_rule, char *mac_list)
734{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800735 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +0800736 int ret = -1;
737 sc_wifi_ap_param_t param = {0};
738 if (mac_list == NULL || acl_rule == NULL)
739 {
740 LYERRLOG("[%s ] Null pointer acl_rule = 0x%p mac_list = 0x%p \n", __func__, acl_rule, mac_list);
741 return ret;
742 }
743 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
744 if (0 != ret)
745 {
746 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
747 return ret;
748 }
749 *acl_rule = (lynq_wifi_mac_acl_rule_e)param.acl_rule;
750 strncpy(mac_list, param.mac_list, sizeof(param.mac_list) - 1);
751 LYINFLOG("[%s ] idx = %d acl_rule = %d mac_list = %s \n", __func__, idx, param.acl_rule, param.mac_list);
752 return 0;
753}
754
755/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800756* @brief: qser_wifi_ap_ssid_set, Set the name of the ssid of 2.4G or 5G
757* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800758* @param ssid [IN]: const char *, Set the ssid name
759* @return : int, If equal to 0 succeeds, others fail
760* @todo: NA
761* @see: NA
762* @warning: NA
763*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800764int qser_wifi_ap_ssid_set(lynq_wifi_ap_index_e idx, const char *ssid)
wz.wang73504132024-03-19 16:38:37 +0800765{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800766 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800767 int ret = -1;
768 if (ssid == NULL)
769 {
770 LYERRLOG("[%s ] Null pointer ssid = 0x%p \n", __func__, ssid);
771 return ret;
772 }
773 ret = sc_wifi_ap_ssid_set((sc_wifi_ap_index_e)idx, ssid);
774 if (0 != ret)
775 {
776 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
777 return ret;
778 }
779 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, ssid);
780 return 0;
781}
782
783/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800784* @brief: qser_wifi_ap_ssid_get, Get the name of the ssid of 2.4G or 5G
785* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800786* @param ssid [OUT]: char *, Get the ssid name
787* @return : int, If equal to 0 succeeds, others fail
788* @todo: NA
789* @see: NA
790* @warning: NA
791*********************************************************************/
792int qser_wifi_ap_ssid_get(lynq_wifi_ap_index_e idx, char *ssid)
793{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800794 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800795 int ret = -1;
796 sc_wifi_ap_param_t param = {0};
797 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
798 if (0 != ret)
799 {
800 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
801 return ret;
802 }
803 LYINFLOG("[%s ] idx = %d ssid = %s \n", __func__, idx, param.ssid);
804 strncpy(ssid, param.ssid, sizeof(param.ssid) - 1);
805 return 0;
wz.wang73504132024-03-19 16:38:37 +0800806}
807
808/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800809* @brief: qser_wifi_ap_ssid_hide_set, Set whether the ssid of 2.4G or 5G is hidden
810* @param idx [IN]: int, Set 2.4G or 5G
wz.wang9f658672024-04-15 14:23:58 +0800811* @param hide [IN]: bool, Set whether the ssid is hidden
812* @return : int, If equal to 0 succeeds, others fail
813* @todo: NA
814* @see: NA
815* @warning: NA
816*********************************************************************/
817int qser_wifi_ap_ssid_hide_set(lynq_wifi_ap_index_e idx, bool hide)
818{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800819 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +0800820 int ret = -1;
821 ret = sc_wifi_ap_ssid_hidden_set((sc_wifi_ap_index_e)idx, (int)hide);
822 if (0 != ret)
823 {
824 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
825 return ret;
826 }
827 LYINFLOG("[%s ] idx = %d hide = %d \n", __func__, idx, hide);
828 return 0;
829}
830
831/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800832* @brief: qser_wifi_ap_ssid_hide_get, Get whether the ssid of 2.4G or 5G is hidden
833* @param idx [IN]: int, Set 2.4G or 5G
wz.wang9f658672024-04-15 14:23:58 +0800834* @param hide [OUT]: bool *, Get whether the ssid is hidden
835* @return : int, If equal to 0 succeeds, others fail
836* @todo: NA
837* @see: NA
838* @warning: NA
839*********************************************************************/
840int qser_wifi_ap_ssid_hide_get(lynq_wifi_ap_index_e idx, bool *hide)
841{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800842 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +0800843 int ret = -1;
844 sc_wifi_ap_param_t param = {0};
845 if (hide == NULL)
846 {
847 LYERRLOG("[%s ] Null pointer hide = 0x%p \n", __func__, hide);
848 return ret;
849 }
850 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
851 if (0 != ret)
852 {
853 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
854 return ret;
855 }
856 LYINFLOG("[%s ] idx = %d ssid_hide = %d \n", __func__, idx, param.ssid_hide);
857 *hide = (bool)param.ssid_hide;
858 return 0;
859}
860
861/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800862* @brief: qser_wifi_ap_mode_set, Set the working protocol mode of 2.4G or 5G
863* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800864* @param mode [IN]: lynq_wifi_mode_type_e, Set the working protocol mode
865* @return : int, If equal to 0 succeeds, others fail
866* @todo: NA
867* @see: NA
868* @warning: NA
869*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800870int qser_wifi_ap_mode_set(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e mode)
wz.wang73504132024-03-19 16:38:37 +0800871{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800872 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800873 int ret = -1;
wz.wang0feef142024-04-23 18:08:39 +0800874 ret = sc_wifi_ap_mode_set((sc_wifi_ap_index_e)idx, lynq_to_sc_mode(mode));
wz.wange5a0b912024-03-22 19:11:59 +0800875 if (0 != ret)
876 {
877 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
878 return ret;
879 }
880 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, mode);
881 return 0;
882}
883
884/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800885* @brief: qser_wifi_ap_mode_get, Get the working protocol mode of 2.4G or 5G
886* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800887* @param mode [OUT]: lynq_wifi_mode_type_e *, Get the working protocol mode
888* @return : int, If equal to 0 succeeds, others fail
889* @todo: NA
890* @see: NA
891* @warning: NA
892*********************************************************************/
893int qser_wifi_ap_mode_get(lynq_wifi_ap_index_e idx, lynq_wifi_mode_type_e *mode)
894{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800895 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800896 int ret = -1;
897 sc_wifi_ap_param_t param = {0};
898 if (mode == NULL)
899 {
900 LYERRLOG("[%s ] Null pointer mode = 0x%p \n", __func__, mode);
901 return ret;
902 }
903 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
904 if (0 != ret)
905 {
906 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
907 return ret;
908 }
909 LYINFLOG("[%s ] idx = %d mode = %d \n", __func__, idx, param.mode);
wz.wang0feef142024-04-23 18:08:39 +0800910 *mode = sc_to_lynq_mode(param.mode);
wz.wange5a0b912024-03-22 19:11:59 +0800911 return 0;
wz.wang73504132024-03-19 16:38:37 +0800912}
913
914/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800915* @brief: qser_wifi_ap_bandwidth_set, Set the bandwidth of 2.4G or 5G
916* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800917* @param bandwidth [IN]: lynq_wifi_bandwidth_type_e, Set the bandwidth
918* @return : int, If equal to 0 succeeds, others fail
919* @todo: NA
920* @see: NA
921* @warning: NA
922*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800923int qser_wifi_ap_bandwidth_set(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e bandwidth)
wz.wang73504132024-03-19 16:38:37 +0800924{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800925 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800926 int ret = -1;
927 ret = sc_wifi_ap_bandwidth_set((sc_wifi_ap_index_e)idx, (sc_wifi_bandwidth_e)bandwidth);
928 if (0 != ret)
929 {
930 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
931 return ret;
932 }
933 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, bandwidth);
934 return 0;
935}
936
937/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800938* @brief: qser_wifi_ap_bandwidth_get, Get the bandwidth of 2.4G or 5G
939* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800940* @param bandwidth [OUT]: lynq_wifi_bandwidth_type_e *, Get the bandwidth
941* @return : int, If equal to 0 succeeds, others fail
942* @todo: NA
943* @see: NA
944* @warning: NA
945*********************************************************************/
946int qser_wifi_ap_bandwidth_get(lynq_wifi_ap_index_e idx, lynq_wifi_bandwidth_type_e *bandwidth)
947{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800948 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800949 int ret = -1;
950 sc_wifi_ap_param_t param = {0};
951 if (bandwidth == NULL)
952 {
953 LYERRLOG("[%s ] Null pointer bandwidth = 0x%p \n", __func__, bandwidth);
954 return ret;
955 }
956 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
957 if (0 != ret)
958 {
959 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
960 return ret;
961 }
962 LYINFLOG("[%s ] idx = %d bandwidth = %d \n", __func__, idx, param.bandwidth);
963 *bandwidth = (lynq_wifi_bandwidth_type_e)param.bandwidth;
964 return 0;
wz.wang73504132024-03-19 16:38:37 +0800965}
966
967/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800968* @brief: qser_wifi_ap_channel_set, Set the channel for 2.4G or 5G
969* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +0800970* @param country_code [IN]: const char *, Set country code
971* @param channel [IN]: int, Set the channel
972* @return : int, If equal to 0 succeeds, others fail
973* @todo: NA
974* @see: NA
975* @warning: NA
976*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +0800977int qser_wifi_ap_channel_set(lynq_wifi_ap_index_e idx, const char *country_code, int channel)
wz.wang73504132024-03-19 16:38:37 +0800978{
zw.wangb8e9b0c2024-09-05 13:53:33 +0800979 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +0800980 int ret = -1;
981 if (country_code == NULL)
982 {
983 LYERRLOG("[%s ] Null pointer country_code = 0x%p \n", __func__, country_code);
984 return ret;
985 }
986 ret = sc_wifi_ap_cc_ch_set((sc_wifi_ap_index_e)idx, country_code, channel);
987 if (0 != ret)
988 {
989 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
990 return ret;
991 }
992 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, country_code, channel);
993 return 0;
994}
995
996/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +0800997* @brief: qser_wifi_ap_channel_get, Get the channel for 2.4G or 5G
998* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +0800999* @param country_code [OUT]: char *, Get country code
1000* @param channel [OUT]: int *, Get the channel
1001* @return : int, If equal to 0 succeeds, others fail
1002* @todo: NA
1003* @see: NA
1004* @warning: NA
1005*********************************************************************/
1006int qser_wifi_ap_channel_get(lynq_wifi_ap_index_e idx, char *country_code, int *channel)
1007{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001008 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001009 int ret = -1;
1010 sc_wifi_ap_param_t param = {0};
1011 if (country_code == NULL || channel == NULL)
1012 {
1013 LYERRLOG("[%s ] Null pointer country_code = 0x%p channel = 0x%p\n", __func__, country_code, channel);
1014 return ret;
1015 }
1016 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1017 if (0 != ret)
1018 {
1019 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1020 return ret;
1021 }
1022 LYINFLOG("[%s ] idx = %d country_code = %s channel = %d\n", __func__, idx, param.countrycode, param.channel);
1023 strncpy(country_code, param.countrycode, sizeof(param.countrycode) - 1);
1024 *channel = param.channel;
1025 return 0;
wz.wang73504132024-03-19 16:38:37 +08001026}
1027
1028/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001029* @brief: qser_wifi_ap_auth_set, Set the security authentication mode and password of 2.4G or 5G
1030* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001031* @param auth_mode [IN]: lynq_wifi_auth_e, Set the security authentication mode
1032* @param auth_passwd [IN]: const char *, Set password
1033* @return : int, If equal to 0 succeeds, others fail
1034* @todo: NA
1035* @see: NA
1036* @warning: NA
1037*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001038int 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 +08001039{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001040 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001041 int ret = -1;
wz.wange5a0b912024-03-22 19:11:59 +08001042 if (auth_passwd == NULL)
1043 {
1044 LYERRLOG("[%s ] Null pointer auth_passwd = 0x%p\n", __func__, auth_passwd);
1045 return ret;
1046 }
wz.wang9f658672024-04-15 14:23:58 +08001047
wz.wang73504132024-03-19 16:38:37 +08001048 sc_wifi_ap_auth_t auth;
wz.wang9f658672024-04-15 14:23:58 +08001049 auth.auth = lynq_to_sc_auth_mode(auth_mode);
wz.wang73504132024-03-19 16:38:37 +08001050 strncpy(auth.passwd, auth_passwd, sizeof(auth.passwd) - 1);
wz.wange5a0b912024-03-22 19:11:59 +08001051 ret = sc_wifi_ap_auth_set((sc_wifi_ap_index_e)idx, &auth);
1052 if (0 != ret)
1053 {
1054 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1055 return ret;
1056 }
wz.wang9f658672024-04-15 14:23:58 +08001057 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s\n", __func__, idx, auth_mode, "******");
wz.wange5a0b912024-03-22 19:11:59 +08001058 return 0;
1059}
1060
1061/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001062* @brief: qser_wifi_ap_auth_get, Get the security authentication mode and password of 2.4G or 5G
1063* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +08001064* @param auth_mode [OUT]: lynq_wifi_auth_e *, Get the security authentication mode
1065* @param auth_passwd [OUT]: char *, Get password
1066* @return : int, If equal to 0 succeeds, others fail
1067* @todo: NA
1068* @see: NA
1069* @warning: NA
1070*********************************************************************/
1071int qser_wifi_ap_auth_get(lynq_wifi_ap_index_e idx, lynq_wifi_auth_e *auth_mode, char *auth_passwd)
1072{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001073 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001074 int ret = -1;
1075 sc_wifi_ap_param_t param = {0};
1076 if (auth_mode == NULL || auth_passwd == NULL)
1077 {
1078 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p auth_passwd = 0x%p\n", __func__, auth_mode, auth_passwd);
1079 return ret;
1080 }
1081 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1082 if (0 != ret)
1083 {
1084 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1085 return ret;
1086 }
1087 LYINFLOG("[%s ] idx = %d auth_mode = %d auth_passwd = %s \n", __func__, idx, param.auth.auth, param.auth.passwd);
1088 strncpy(auth_passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
wz.wang9f658672024-04-15 14:23:58 +08001089
1090 *auth_mode = sc_to_lynq_auth_mode(param.auth.auth);
wz.wange5a0b912024-03-22 19:11:59 +08001091 return 0;
wz.wang73504132024-03-19 16:38:37 +08001092}
1093
1094/********************************************************************
wz.wang5bbe6d62024-05-29 13:39:35 +08001095* @brief: qser_wifi_ap_auth_get_s, Get the security authentication mode , password group_rekey and pairwise of 2.4G or 5G
1096* @param idx [IN]: int, Set 2.4G or 5G
1097* @param auth_mode [OUT]: lynq_wifi_ap_auth_t *, Get the security authentication mode
1098* @return : int, If equal to 0 succeeds, others fail
1099* @todo: NA
1100* @see: NA
1101* @warning: NA
1102*********************************************************************/
1103int qser_wifi_ap_auth_get_s(lynq_wifi_ap_index_e idx, lynq_wifi_ap_auth_t *auth_mode)
1104{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001105 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +08001106 int ret = -1;
1107 sc_wifi_ap_param_t param = {0};
1108 if (auth_mode == NULL)
1109 {
1110 LYERRLOG("[%s ] Null pointer auth_mode = 0x%p\n", __func__, auth_mode);
1111 return ret;
1112 }
1113 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1114 if (0 != ret)
1115 {
1116 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1117 return ret;
1118 }
1119 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);
1120 strncpy(auth_mode->passwd, param.auth.passwd, sizeof(param.auth.passwd) - 1);
1121 auth_mode->group_rekey = param.auth.group_rekey;
1122 auth_mode->pairwise = (lynq_wifi_auth_wpa_psk_e)param.auth.pairwise;
1123 auth_mode->auth = sc_to_lynq_auth_mode(param.auth.auth);
1124 return 0;
1125}
1126
1127/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001128* @brief: qser_wifi_ap_max_sta_set, Set the maximum number of STAs for 2.4G or 5G
1129* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001130* @param max_sta_num [IN]: int, Set the maximum number
1131* @return : int, If equal to 0 succeeds, others fail
1132* @todo: NA
1133* @see: NA
1134* @warning: NA
1135*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001136int qser_wifi_ap_max_sta_set(lynq_wifi_ap_index_e idx, int max_sta_num)
wz.wang73504132024-03-19 16:38:37 +08001137{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001138 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001139 int ret = -1;
1140 ret = sc_wifi_ap_max_sta_num_set((sc_wifi_ap_index_e)idx, max_sta_num);
1141 if (0 != ret)
1142 {
1143 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1144 return ret;
1145 }
1146 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, max_sta_num);
1147 return 0;
1148}
1149
1150/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001151* @brief: qser_wifi_ap_max_sta_get, Get the maximum number of STAs for 2.4G or 5G
1152* @param idx [IN]: int, Set 2.4G or 5G
wz.wange5a0b912024-03-22 19:11:59 +08001153* @param max_sta_num [OUT]: int *, Get the maximum number
1154* @return : int, If equal to 0 succeeds, others fail
1155* @todo: NA
1156* @see: NA
1157* @warning: NA
1158*********************************************************************/
1159int qser_wifi_ap_max_sta_get(lynq_wifi_ap_index_e idx, int *max_sta_num)
1160{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001161 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001162 int ret = -1;
1163 sc_wifi_ap_param_t param = {0};
1164 if (max_sta_num == NULL)
1165 {
1166 LYERRLOG("[%s ] Null pointer max_sta_num = 0x%p\n", __func__,max_sta_num);
1167 return ret;
1168 }
1169 ret = sc_wifi_ap_param_get((sc_wifi_ap_index_e)idx, &param);
1170 if (0 != ret)
1171 {
1172 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1173 return ret;
1174 }
1175 LYINFLOG("[%s ] idx = %d max_sta_num = %d \n", __func__, idx, param.max_sta_num);
1176 *max_sta_num = param.max_sta_num;
1177 return 0;
wz.wang73504132024-03-19 16:38:37 +08001178}
1179
1180/********************************************************************
wz.wang72c432c2024-06-18 09:16:26 +08001181* @brief: qser_wifi_lanhost_get_list, Get sta device information received as an ap for 2.4G or 5G
1182* @param lynq_arrays [OUT]: lynq_lanhost_ts *, Get sta device information received as an ap
1183* @return : int, If equal to 0 succeeds, others fail
1184* @todo: NA
1185* @see: NA
1186* @warning: NA
1187*********************************************************************/
1188int qser_wifi_lanhost_get_list(lynq_lanhost_ts *lynq_arrays)
1189{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001190 WIFI_ENABLE_JUDGE();
wz.wang72c432c2024-06-18 09:16:26 +08001191 int ret = -1;
1192 int i = 0;
1193 sc_lanhost_t array[32] = {0};
1194 if (lynq_arrays == NULL)
1195 {
1196 LYERRLOG("[%s ] Null pointer lynq_arrays = 0x%p\n", __func__, lynq_arrays);
1197 return ret;
1198 }
1199 lynq_arrays->array_len = 32;
zw.wang0044b012024-08-08 11:48:49 +08001200 ret = sc_wifi_lanhost_get_list(array, &lynq_arrays->array_len);
wz.wang72c432c2024-06-18 09:16:26 +08001201 if (0 != ret)
1202 {
1203 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
1204 return ret;
1205 }
1206 LYINFLOG("[%s]ap_lanhost len[%d]\n", __func__, lynq_arrays->array_len);
1207 for (i = 0; i < lynq_arrays->array_len; i++)
1208 {
1209 LYINFLOG("[%s]Element : [%d] ifname = %s macaddr = %s addr = %s name = %s uptime = %d\n", __func__, i,
1210 array[i].ifname, array[i].macaddr, array[i].addr, array[i].name, array[i].uptime);
1211 strncpy(lynq_arrays->array[i].ifname, array[i].ifname, sizeof(lynq_arrays->array[i].ifname) - 1);
1212 strncpy(lynq_arrays->array[i].macaddr, array[i].macaddr, sizeof(lynq_arrays->array[i].macaddr) - 1);
1213 strncpy(lynq_arrays->array[i].addr, array[i].addr, sizeof(lynq_arrays->array[i].addr) - 1);
1214 strncpy(lynq_arrays->array[i].name, array[i].name, sizeof(lynq_arrays->array[i].name) - 1);
1215 lynq_arrays->array[i].uptime = array[i].uptime;
1216 }
1217 return 0;
1218}
1219
1220/********************************************************************
1221* @brief: qser_wifi_get_ap_pkt_stats, Obtain data packets sent and received by ap for 2.4G or 5G
1222* @param idx [IN]: int, Set 2.4G or 5G
1223* @param pkt_stat [OUT]: lynq_wifi_pkt_stats_t *, Obtain data packets sent and received by ap
1224* @return : int, If equal to 0 succeeds, others fail
1225* @todo: NA
1226* @see: NA
1227* @warning: NA
1228*********************************************************************/
1229int qser_wifi_get_ap_pkt_stats(lynq_wifi_ap_index_e idx, lynq_wifi_pkt_stats_t *pkt_stat)
1230{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001231 WIFI_ENABLE_JUDGE();
wz.wang72c432c2024-06-18 09:16:26 +08001232 int ret = -1;
1233 sc_wifi_pkt_stats_t stat = {0};
1234 if (pkt_stat == NULL)
1235 {
1236 LYERRLOG("[%s ] Null pointer pkt_stat = 0x%p\n", __func__, pkt_stat);
1237 return ret;
1238 }
1239 idx = LYNQ_WIFI_AP_INDEX_AP0;
1240 ret = sc_wifi_get_ap_pkt_stats((sc_wifi_ap_index_e)idx, &stat);
1241 if (0 != ret)
1242 {
1243 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
1244 return ret;
1245 }
1246 LYINFLOG("[%s ]ap_pkt_get[%d] rx[%llu, %llu, %llu, %llu] tx[%llu, %llu, %llu, %llu]\n", __func__, idx,
1247 stat.rx_packets, stat.rx_bytes, stat.rx_errors, stat.rx_dropped,
1248 stat.tx_packets, stat.tx_bytes, stat.tx_errors, stat.tx_dropped);
1249 pkt_stat->rx_packets = stat.rx_packets;
1250 pkt_stat->rx_bytes = stat.rx_bytes;
1251 pkt_stat->rx_errors = stat.rx_errors;
1252 pkt_stat->rx_dropped = stat.rx_dropped;
1253 pkt_stat->tx_packets = stat.tx_packets;
1254 pkt_stat->tx_bytes = stat.tx_bytes;
1255 pkt_stat->tx_errors = stat.tx_errors;
1256 pkt_stat->tx_dropped = stat.tx_dropped;
1257 return 0;
1258}
1259
1260/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001261* @brief: qser_wifi_ap_start, Set the ap mode of 2.4G or 5G to enable
1262* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001263* @return : int, If equal to 0 succeeds, others fail
1264* @todo: NA
1265* @see: NA
1266* @warning: NA
1267*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001268int qser_wifi_ap_start(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001269{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001270 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001271 int ret = -1;
1272 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
1273 if (0 != ret)
1274 {
1275 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1276 return ret;
1277 }
1278 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1279 return 0;
wz.wang73504132024-03-19 16:38:37 +08001280}
1281
1282/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001283* @brief: qser_wifi_ap_stop, Disable ap mode for 2.4G or 5G
1284* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001285* @return : int, If equal to 0 succeeds, others fail
1286* @todo: NA
1287* @see: NA
1288* @warning: NA
1289*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001290int qser_wifi_ap_stop(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001291{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001292 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001293 int ret = -1;
1294 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
1295 if (0 != ret)
1296 {
1297 LYERRLOG("[%s ] ret = %d\n", __func__,ret);
1298 return ret;
1299 }
1300 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1301 return 0;
wz.wang73504132024-03-19 16:38:37 +08001302}
1303
1304/********************************************************************
wz.wang0feef142024-04-23 18:08:39 +08001305* @brief: qser_wifi_ap_restart, Set the ap mode of 2.4G or 5G to restart
1306* @param idx [IN]: int, Set 2.4G or 5G
wz.wang73504132024-03-19 16:38:37 +08001307* @return : int, If equal to 0 succeeds, others fail
1308* @todo: NA
1309* @see: NA
1310* @warning: NA
1311*********************************************************************/
wz.wange5a0b912024-03-22 19:11:59 +08001312int qser_wifi_ap_restart(lynq_wifi_ap_index_e idx)
wz.wang73504132024-03-19 16:38:37 +08001313{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001314 WIFI_ENABLE_JUDGE();
wz.wange5a0b912024-03-22 19:11:59 +08001315 int ret = -1;
1316 ret = sc_wifi_ap_stop((sc_wifi_ap_index_e)idx);
wz.wang73504132024-03-19 16:38:37 +08001317 if (0 != ret)
1318 {
wz.wang9f658672024-04-15 14:23:58 +08001319 LYERRLOG("[%s ] stop ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +08001320 return ret;
wz.wang73504132024-03-19 16:38:37 +08001321 }
wz.wange5a0b912024-03-22 19:11:59 +08001322 ret = sc_wifi_ap_start((sc_wifi_ap_index_e)idx);
1323 if (0 != ret)
1324 {
wz.wang9f658672024-04-15 14:23:58 +08001325 LYERRLOG("[%s ] start ret = %d\n", __func__,ret);
wz.wange5a0b912024-03-22 19:11:59 +08001326 return ret;
1327 }
1328 LYINFLOG("[%s ] idx = %d \n", __func__, idx);
1329 return 0;
wz.wang73504132024-03-19 16:38:37 +08001330}
1331
wz.wang9f658672024-04-15 14:23:58 +08001332/********************************************************************
1333* @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 +08001334* @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 +08001335* @return : int, If equal to 0 succeeds, others fail
1336* @todo: NA
1337* @see: NA
1338* @warning: NA
1339*********************************************************************/
wz.wang5bbe6d62024-05-29 13:39:35 +08001340int qser_wifi_sta_param_set(lynq_wifi_sta_param_t *param_stat)
wz.wang9f658672024-04-15 14:23:58 +08001341{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001342 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001343 int ret = -1;
1344 sc_wifi_sta_param_t stat = {0};
wz.wang5bbe6d62024-05-29 13:39:35 +08001345 stat.auth = lynq_to_sc_auth_mode(param_stat->auth);
1346 stat.pairwise = (sc_wifi_auth_wpa_psk_e )param_stat->pairwise;
1347 strncpy(stat.ssid, param_stat->ssid, sizeof(stat.ssid) - 1);
1348 strncpy(stat.passwd, param_stat->passwd, sizeof(stat.passwd) - 1);
wz.wang9f658672024-04-15 14:23:58 +08001349 ret = sc_wifi_sta_param_set(&stat);
1350 if (0 != ret)
1351 {
1352 LYERRLOG("[%s ] sta_param_set ret = %d\n", __func__,ret);
1353 return ret;
1354 }
1355 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1356 return 0;
1357}
1358
1359/********************************************************************
1360* @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 +08001361* @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 +08001362* @return : int, If equal to 0 succeeds, others fail
1363* @todo: NA
1364* @see: NA
1365* @warning: NA
1366*********************************************************************/
wz.wang5bbe6d62024-05-29 13:39:35 +08001367int qser_wifi_sta_param_get(lynq_wifi_sta_param_t *param_stat)
wz.wang9f658672024-04-15 14:23:58 +08001368{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001369 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001370 int ret = -1;
1371 sc_wifi_sta_param_t stat = {0};
1372 ret = sc_wifi_sta_param_get(&stat);
1373 if (0 != ret)
1374 {
1375 LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__,ret);
1376 return ret;
1377 }
wz.wang5bbe6d62024-05-29 13:39:35 +08001378 param_stat->auth = sc_to_lynq_auth_mode(stat.auth);
1379 param_stat->pairwise = (lynq_wifi_auth_wpa_psk_e )stat.pairwise;
1380 strncpy(param_stat->ssid, stat.ssid, sizeof(stat.ssid) - 1);
1381 strncpy(param_stat->passwd, stat.passwd, sizeof(stat.passwd) -1);
1382 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1383 return 0;
1384}
1385
1386/********************************************************************
1387* @brief: qser_wifi_sta_get_status, Gets the status value associated with sta
1388* @param status_stat [OUT]: lynq_wifi_sta_status_t *, Gets the status value associated with sta
1389* @return : int, If equal to 0 succeeds, others fail
1390* @todo: NA
1391* @see: NA
1392* @warning: NA
1393*********************************************************************/
wz.wang72c432c2024-06-18 09:16:26 +08001394int qser_wifi_sta_get_status(lynq_wifi_sta_status_t *status_stat)
wz.wang5bbe6d62024-05-29 13:39:35 +08001395{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001396 WIFI_ENABLE_JUDGE();
wz.wang5bbe6d62024-05-29 13:39:35 +08001397 int ret = -1;
1398 sc_wifi_sta_status_t stat;
1399 ret = sc_wifi_sta_get_status(&stat);
1400 if (0 != ret)
1401 {
wz.wang72c432c2024-06-18 09:16:26 +08001402 LYERRLOG("[%s ] sta_param_get ret = %d\n", __func__, ret);
wz.wang5bbe6d62024-05-29 13:39:35 +08001403 return ret;
1404 }
wz.wang72c432c2024-06-18 09:16:26 +08001405 print_sta_status(&stat);
zw.wang0044b012024-08-08 11:48:49 +08001406 sc_to_lynq_sta_status(&stat, status_stat);
wz.wang9f658672024-04-15 14:23:58 +08001407 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1408 return 0;
1409}
1410
1411/********************************************************************
wz.wang72c432c2024-06-18 09:16:26 +08001412* @brief: qser_wifi_get_sta_pkt_stats, Obtain data packets sent and received by sta for 2.4G or 5G
1413* @param pkt_stat [OUT]: lynq_wifi_pkt_stats_t *, Obtain data packets sent and received by sta
1414* @return : int, If equal to 0 succeeds, others fail
1415* @todo: NA
1416* @see: NA
1417* @warning: NA
1418*********************************************************************/
1419int qser_wifi_get_sta_pkt_stats(lynq_wifi_pkt_stats_t *pkt_stat)
1420{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001421 WIFI_ENABLE_JUDGE();
wz.wang72c432c2024-06-18 09:16:26 +08001422 int ret = -1;
1423 sc_wifi_pkt_stats_t stat = {0};
1424 if (pkt_stat == NULL)
1425 {
1426 LYERRLOG("[%s ] Null pointer pkt_stat = 0x%p\n", __func__, pkt_stat);
1427 return ret;
1428 }
1429 ret = sc_wifi_get_sta_pkt_stats(&stat);
1430 if (0 != ret)
1431 {
1432 LYERRLOG("[%s ] ret = %d\n", __func__, ret);
1433 return ret;
1434 }
1435 LYINFLOG("[%s ]sta_pkt_get rx[%llu, %llu, %llu, %llu] tx[%llu, %llu, %llu, %llu]\n", __func__,
1436 stat.rx_packets, stat.rx_bytes, stat.rx_errors, stat.rx_dropped,
1437 stat.tx_packets, stat.tx_bytes, stat.tx_errors, stat.tx_dropped);
1438 pkt_stat->rx_packets = stat.rx_packets;
1439 pkt_stat->rx_bytes = stat.rx_bytes;
1440 pkt_stat->rx_errors = stat.rx_errors;
1441 pkt_stat->rx_dropped = stat.rx_dropped;
1442 pkt_stat->tx_packets = stat.tx_packets;
1443 pkt_stat->tx_bytes = stat.tx_bytes;
1444 pkt_stat->tx_errors = stat.tx_errors;
1445 pkt_stat->tx_dropped = stat.tx_dropped;
1446 return 0;
1447}
1448
1449/********************************************************************
wz.wang9f658672024-04-15 14:23:58 +08001450* @brief: qser_wifi_sta_start_scan, Scan for ap nodes and return them through callback
1451* @return : int, If equal to 0 succeeds, others fail
1452* @todo: NA
1453* @see: NA
1454* @warning: NA
1455*********************************************************************/
1456int qser_wifi_sta_start_scan(void)
1457{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001458 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001459 int ret = -1;
1460 ret = sc_wifi_sta_start_scan();
1461 if (0 != ret)
1462 {
1463 LYERRLOG("[%s ] scan ret = %d\n", __func__,ret);
1464 return ret;
1465 }
1466 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1467 return 0;
1468}
1469
1470/********************************************************************
1471* @brief: qser_wifi_sta_start, To enable sta mode, you need to enable ap mode first
1472* @return : int, If equal to 0 succeeds, others fail
1473* @todo: NA
1474* @see: NA
1475* @warning: NA
1476*********************************************************************/
1477int qser_wifi_sta_start(void)
1478{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001479 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001480 int ret = -1;
1481 ret = sc_wifi_sta_start();
1482 if (0 != ret)
1483 {
1484 LYERRLOG("[%s ] sta_start ret = %d\n", __func__,ret);
1485 return ret;
1486 }
1487 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1488 return 0;
1489}
1490
1491/********************************************************************
1492* @brief: qser_wifi_sta_stop, To disable sta mode.
1493* @return : int, If equal to 0 succeeds, others fail
1494* @todo: NA
1495* @see: NA
1496* @warning: NA
1497*********************************************************************/
1498int qser_wifi_sta_stop(void)
1499{
zw.wangb8e9b0c2024-09-05 13:53:33 +08001500 WIFI_ENABLE_JUDGE();
wz.wang9f658672024-04-15 14:23:58 +08001501 int ret = -1;
1502 ret = sc_wifi_sta_stop();
1503 if (0 != ret)
1504 {
1505 LYERRLOG("[%s ] sta_stop ret = %d\n", __func__,ret);
1506 return ret;
1507 }
1508 LYINFLOG("[%s ] ret = %d \n", __func__, ret);
1509 return 0;
1510}
1511
wz.wange5a0b912024-03-22 19:11:59 +08001512DEFINE_LYNQ_LIB_LOG(LYNQ_WIFI)
wz.wang73504132024-03-19 16:38:37 +08001513
1514#ifdef __cplusplus
1515}
1516#endif