1 /** @file wlan.c
2 *
3 * @brief This file provides Core WLAN definition
4 *
5 * Copyright 2008-2024 NXP
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 *
9 */
10
11 #include <string.h>
12 #include <wm_utils.h>
13 #include <wlan.h>
14 #include <wifi.h>
15 #include <osa.h>
16 #include <wm_net.h>
17 #include <wifi-debug.h>
18 #include <wlan_11d.h>
19 #if CONFIG_WMSTATS
20 #include <wmstats.h>
21 #endif /* CONFIG_WMSTATS */
22 #include <stdint.h>
23 #ifndef RW610
24 #include <mlan_sdio_api.h>
25 #endif
26 #if (CONFIG_HOST_PMK) || (CONFIG_WPS2)
27 #include <wm_mbedtls_helper_api.h>
28 #include <mbedtls/x509_crt.h>
29 #endif /* (CONFIG_HOST_PMK) || (CONFIG_WPS2) */
30 #ifdef RW610
31 #include <wifi_cal_data_ext.h>
32 #endif
33 #ifdef OVERRIDE_CALIBRATION_DATA
34 #include OVERRIDE_CALIBRATION_DATA
35 #else
36 #include <wifi_cal_data_ext.h>
37 #endif
38 #ifdef RW610
39 #include "fsl_loader.h"
40 #endif
41
42 #if CONFIG_SIGMA_AGENT
43 #include "wifi_ping.h"
44 #endif
45
46 #if CONFIG_HOST_SLEEP
47 #ifdef RW610
48 #include "fsl_power.h"
49 #endif
50 #endif
51 #if CONFIG_WPS2
52 #include <wifi_nxp_wps.h>
53 #include <wps_def.h>
54 #endif
55 #if CONFIG_WPA_SUPP
56 #include <supp_main.h>
57 #include <supp_api.h>
58 #include <wifi_nxp.h>
59 #include "utils/common.h"
60 #include "rtos_wpa_supp_if.h"
61 #if CONFIG_WIFI_SHELL
62 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
63 #include "wpa_cli.h"
64 #endif
65 #endif
66 #endif
67
68 #if (CONFIG_WPA2_ENTP) || ((CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE || CONFIG_WIFI_NM_HOSTAPD_CRYPTO_ENTERPRISE) && !(CONFIG_WIFI_USB_FILE_ACCESS))
69 #include "ca-cert.h"
70 #include "client-cert.h"
71 #include "client-key.h"
72 #include "dh-param.h"
73 #include "server-cert.h"
74 #include "server-key.h"
75 #endif
76 #include "mlan_decl.h"
77
78 #if CONFIG_NCP_BRIDGE
79 #include "app_notify.h"
80 #endif
81
82 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
83 #include "board.h"
84
85 #if (defined(CPU_MIMXRT1062DVMAA_cm7) || defined(CPU_MIMXRT1062DVL6A_cm7) || defined (CPU_MIMXRT1062DVL6B_cm7))
86 #if defined(SD8978) || defined(SD8987)
87 /* IR-OOB TRIGGER Connect Fly-Wire between J16.1 and J108.4 for 1XK-M2, 1ZM-M2*/
88 #define IR_OUTBAND_TRIGGER_GPIO GPIO1
89 #define IR_OUTBAND_TRIGGER_GPIO_PIN (23U)
90 #define IR_OUTBAND_TRIGGER_GPIO_NAME "GPIO1"
91 //#define IOMUXC_GPIO_IR_OUTBAND_TRIGGER IOMUXC_GPIO_AD_B1_07_GPIO1_IO23
92 #elif defined(SD9177)
93 /* IR-OOB TRIGGER for 2EL-M2, Internal Routing to M2 Slot*/
94 #define IR_OUTBAND_TRIGGER_GPIO GPIO1
95 #define IR_OUTBAND_TRIGGER_GPIO_PIN (24U)
96 #define IR_OUTBAND_TRIGGER_GPIO_NAME "GPIO1"
97 //#define IOMUXC_GPIO_IR_OUTBAND_TRIGGER IOMUXC_GPIO_AD_B1_08_GPIO1_IO24
98 #endif
99
100 #elif defined(CPU_MIMXRT1176DVMAA_cm7) // For RT1170
101 /* IR OUT-BAND TRIGGER GPIO*/
102 /*Output GPIO J9 PIN2 (IOMUXC_GPIO_DISP_B2_11) for RT1170-EVKA/B*/
103 #define IR_OUTBAND_TRIGGER_GPIO GPIO5
104 #define IR_OUTBAND_TRIGGER_GPIO_PIN (12U)
105 #define IR_OUTBAND_TRIGGER_GPIO_NAME "GPIO5"
106
107 #endif /* (defined(CPU_MIMXRT1062DVMAA_cm7) || (CPU_MIMXRT1062DVL6A_cm7)) */
108 #endif
109
110 #define DELAYED_SLP_CFM_DUR 10U
111 #define BAD_MIC_TIMEOUT (60 * 1000)
112
113 #if CONFIG_WPA_SUPP
114 #define SUPP_STATUS_TIMEOUT (2 * 1000)
115 #define ROAM_SCAN_TIMEOUT (60 * 1000)
116 #endif
117
118 #define WL_ID_CONNECT "wifi_connect"
119 #define WL_ID_DEEPSLEEP_SM "wlcm_deepsleep_sm"
120 #define WL_ID_WIFI_RSSI "wifi_rssi"
121
122 /** Find maximum */
123 #ifndef MAX
124 #define MAX(a, b) ((a) > (b) ? (a) : (b))
125 #endif
126
127 #if CONFIG_ECSA
128 #define DEF_SWITCH_COUNT 10
129 #endif
130
131 #if CONFIG_BG_SCAN
132 #define BG_SCAN_LIMIT 3
133 #endif
134
135 static bool wlan_uap_scan_chan_list_set;
136
137 #if CONFIG_MEF_CFG
138 wlan_flt_cfg_t g_flt_cfg;
139 #endif
140 #ifdef RW610
141 #if (CONFIG_NXP_MONOLITHIC_WIFI)
142 extern const unsigned char *wlan_fw_bin;
143 extern const unsigned int wlan_fw_bin_len;
144 #else
145 const unsigned char *wlan_fw_bin = (const unsigned char *)(void *)0;
146 const unsigned int wlan_fw_bin_len = 0;
147 #endif /* CONFIG_NXP_MONOLITHIC_WIFI */
148 extern int nxp_wifi_wlan_event_callback(enum wlan_event_reason reason, void *data);
149 #define wlan_event_callback nxp_wifi_wlan_event_callback
150 #endif
151
152 static int wifi_wakeup_card_cb(osa_rw_lock_t *plock, unsigned int wait_time);
153
154 #if CONFIG_WPA2_ENTP
155 extern int wpa2_ent_connect(struct wlan_network *wpa2_network);
156 extern void wpa2_shutdown();
157 #endif
158
159 #if CONFIG_NCP_BRIDGE
160 /* uap provision callbacks */
161 int (*uap_prov_deinit_cb)(void) = NULL;
162 void (*uap_prov_cleanup_cb)(void) = NULL;
163 #endif
164
165 #if CONFIG_WMSTATS
166 struct wm_stats g_wm_stats;
167 #endif /* CONFIG_WMSTATS */
168
169 osa_rw_lock_t sleep_rwlock;
170
171 #if CONFIG_WMM_UAPSD
172 OSA_SEMAPHORE_HANDLE_DEFINE(uapsd_sem);
173 #endif
174
175 #if CONFIG_CPU_LOADING
176 #define CPU_LOADING_ACTION_STOP 0
177 #define CPU_LOADING_ACTION_START 1
178 #define CPU_LOADING_STATUS_ONGOING 2
179 #define CPU_LOADING_STATUS_ENDING 3
180 #define CPU_LOADING_STATUS_DEAD 4
181 #define CPU_LOADING_PERIOD 2000
182 #define CPU_LOADING_TASK_NUM 20
183 #define CPU_LOADING_KEEPING -1
184
185 #define CONFIG_CPU_LOADING_STACK_SIZE (2048)
186
187 static void cpu_loading_task(osa_task_param_t arg);
188
189 /* OSA_TASKS: name, priority, instances, stackSz, useFloat */
190 static OSA_TASK_DEFINE(cpu_loading_task, OSA_PRIORITY_HIGH, 1, CONFIG_CPU_LOADING_STACK_SIZE, 0);
191
192 static struct
193 {
194 /*The number of tasks.*/
195 uint8_t task_nums;
196 /*The total length of cpu info struct*/
197 uint32_t task_status_len;
198 /*Pointer to buffer of storing cpu Loading info.*/
199 char *cpu_loading_info;
200 /*CPU loading status: CPU_LOADING_STATUS_ENDING / CPU_LOADING_STATUS_ONGOING / CPU_LOADING_STATUS_DEAD*/
201 uint8_t status;
202 /*Index of collecting CPU loading info.*/
203 uint32_t index;
204 /*Remaining time of collecting CPU loading info.*/
205 int sampling_loops;
206 /*The value of timer time out*/
207 uint32_t sampling_period;
208 /*CPU loading timer.*/
209 OSA_TIMER_HANDLE_DEFINE(cpu_loading_timer);
210 /*CPU loading thread.*/
211 OSA_TASK_HANDLE_DEFINE(cpu_loading_task_Handle);
212
213 /*Array of recording names of tasks.*/
214 char task_name[CPU_LOADING_TASK_NUM][configMAX_TASK_NAME_LEN];
215 /*Array of recording runing time of tasks.*/
216 uint64_t data_cur[CPU_LOADING_TASK_NUM];
217 uint64_t data_pre[CPU_LOADING_TASK_NUM];
218 /*Array of recording the first runing time of tasks.*/
219 uint64_t first_data[CPU_LOADING_TASK_NUM];
220 }cpu_loading;
221
222 char task_string_name[CPU_LOADING_TASK_NUM][configMAX_TASK_NAME_LEN];
223
224 #endif
225
226 #if ((CONFIG_11MC) || (CONFIG_11AZ)) && (CONFIG_WLS_CSI_PROC)
227 OSA_SEMAPHORE_HANDLE_DEFINE(wls_csi_sem);
228 #endif
229
230 #if CONFIG_WPS2
231 int prov_session_attempt = PROV_NON_SESSION_ATTEMPT;
232 extern WPS_DATA wps_global;
233 #endif
234
235 #define MAX_EVENTS 20
236 #define CONNECTION_EVENT(r, data) \
237 if (wlan.cb != NULL) \
238 { \
239 (void)wlan.cb(r, data); \
240 }
241
242 #ifdef RW610
243 OSA_MUTEX_HANDLE_DEFINE(reset_lock);
244 /* Mon thread */
245 static bool mon_thread_init = 0;
246 #endif
247
248 #if CONFIG_HOST_SLEEP
249 #if CONFIG_POWER_MANAGER
250 #if !(CONFIG_WIFI_BLE_COEX_APP)
251 int wlan_host_sleep_state = HOST_SLEEP_DISABLE;
252 #else
253 int wlan_host_sleep_state = HOST_SLEEP_PERIODIC;
254 #endif
255 #if CONFIG_UART_INTERRUPT
256 /* This flag is used for Power Manager only.
257 * When using Power Manager, the uart task holds the rxSemaphore and waits
258 * on uart event group to receive input from uart. With this flag, uart task
259 * will have chance to release the lock so that IDLE task can do uart deinit
260 * before entering PM3.
261 * When using suspend mode, no such observations.
262 */
263 bool usart_suspend_flag = false;
264 #endif
265 OSA_TIMER_HANDLE_DEFINE(wake_timer);
266 #endif
267 int is_hs_handshake_done = 0;
268
269 extern OSA_SEMAPHORE_HANDLE_DEFINE(wakelock);
270 extern int wakeup_by;
271
272 bool wlan_is_manual = false;
273 #endif
274
275 #if CONFIG_SCAN_CHANNEL_GAP
276 static t_u16 scan_channel_gap = (t_u16)SCAN_CHANNEL_GAP_VALUE;
277 #endif
278
279 #if (CONFIG_11K) || (CONFIG_11V)
280 #define NEIGHBOR_REQ_TIMEOUT (60 * 1000)
281 #endif
282
283 #if CONFIG_11R
284 #if CONFIG_WPA_SUPP
285 #define FT_ROAM_TIMEOUT (20 * 1000)
286 #endif
287 #endif
288
289 #if CONFIG_POWER_MANAGER
290 #define WAKE_TIMEOUT (5 * 1000)
291 #endif
292
293 #ifdef RW610
294 #define TEMPERATURE_MON_TIMEOUT (5 * 1000)
295 OSA_TIMER_HANDLE_DEFINE(temperature_mon_timer);
296 #endif
297
298 enum user_request_type
299 {
300 /* we append our user-generated events to the wifi interface events and
301 * handle them accordingly */
302 CM_STA_USER_REQUEST_CONNECT = WIFI_EVENT_LAST + 1,
303 CM_STA_USER_REQUEST_DISCONNECT,
304 CM_STA_USER_REQUEST_SCAN,
305 #if (CONFIG_11K) || (CONFIG_11V)
306 CM_STA_USER_REQUEST_SET_RSSI_THRESHOLD,
307 #endif
308 #if CONFIG_HOST_SLEEP
309 CM_STA_USER_REQUEST_HS,
310 #endif
311 CM_STA_USER_REQUEST_PS_ENTER,
312 CM_STA_USER_REQUEST_PS_EXIT,
313 #if CONFIG_CPU_LOADING
314 CM_STA_USER_REQUEST_CPU_LOADING,
315 #endif
316 CM_STA_USER_REQUEST_LAST,
317 /* All the STA related request are above and uAP related requests are
318 below */
319 CM_UAP_USER_REQUEST_START,
320 CM_UAP_USER_REQUEST_STOP,
321 CM_UAP_USER_REQUEST_PS_ENTER,
322 CM_UAP_USER_REQUEST_PS_EXIT,
323 CM_UAP_USER_REQUEST_LAST,
324 CM_WLAN_USER_REQUEST_DEINIT,
325 CM_WLAN_USER_REQUEST_SHUTDOWN
326 };
327
328 static int send_user_request(enum user_request_type request, unsigned int data);
329
330 enum cm_sta_state
331 {
332 CM_STA_INITIALIZING = 0,
333 CM_STA_IDLE,
334 CM_STA_SCANNING,
335 CM_STA_SCANNING_USER,
336 CM_STA_ASSOCIATING,
337 CM_STA_ASSOCIATED,
338 CM_STA_AUTHENTICATED,
339 CM_STA_REQUESTING_ADDRESS,
340 CM_STA_OBTAINING_ADDRESS,
341 CM_STA_CONNECTED,
342 };
343
344 enum cm_uap_state
345 {
346 CM_UAP_INITIALIZING = 0,
347 CM_UAP_CONFIGURED,
348 CM_UAP_STARTED,
349 CM_UAP_IP_UP,
350 };
351
352 static struct wifi_scan_params_t g_wifi_scan_params = {NULL,
353 NULL,
354 {
355 0,
356 },
357 BSS_ANY,
358 60,
359 250};
360
361 #define CONFIG_WLCMGR_STACK_SIZE (5120)
362
363 static void wlcmgr_task(osa_task_param_t arg);
364
365 /* OSA_TASKS: name, priority, instances, stackSz, useFloat */
366 static OSA_TASK_DEFINE(wlcmgr_task, OSA_PRIORITY_HIGH, 1, CONFIG_WLCMGR_STACK_SIZE, 0);
367
368 #if CONFIG_WPS2
369 #define CONFIG_WPS_STACK_SIZE (5120)
370
371 static void wps_task(osa_task_param_t arg);
372
373 /* OSA_TASKS: name, priority, instances, stackSz, useFloat */
374 static OSA_TASK_DEFINE(wps_task, OSA_PRIORITY_NORMAL, 1, CONFIG_WPS_STACK_SIZE, 0);
375
376 static int wlcm_wps_callback(enum wps_event event, void *data, uint16_t len);
377
378 typedef enum
379 {
380 PROV_WPS_NONE,
381 PROV_WPS_STARTED, /* WPS provisioning started */
382 PROV_WPS_PBC_ENABLED, /* WPS pushbutton attempt enabled */
383 PROV_WPS_PIN_ENABLED, /* WPS PIN attempt enabled */
384 PROV_WPS_SUCCESSFUL, /* WPS based provisioning successful */
385 } wps_state_t;
386
387 static struct
388 {
389 wps_state_t wps_state;
390 enum wps_session_command wps_cmd;
391 uint32_t wps_pin;
392
393 /* WPS thread */
394 OSA_TASK_HANDLE_DEFINE(wps_task_Handle);
395
396 OSA_SEMAPHORE_HANDLE_DEFINE(wps_scan_done);
397 struct wlan_scan_result wps_res;
398 } wlan_wps;
399
400 static struct wps_config wps_conf = {
401 .role = 1, //WPS_ENROLLEE
402 .pin_generator = 1,
403 .version = 0x20,
404 .version2 = 0x20,
405 .device_name = "Redfinch",
406 .manufacture = "NXP",
407 .model_name = "rw610",
408 .model_number = "0001",
409 .serial_number = "0001",
410 .config_methods = 0x2388,
411 .primary_dev_category = 01,
412 .primary_dev_subcategory = 01,
413 .rf_bands = 2,
414 .os_version = 0xFFFFFFFF,
415 .wps_msg_max_retry = 5,
416 .wps_msg_timeout = 5000,
417 .pin_len = 8,
418 .wps_callback = wlcm_wps_callback,
419 .prov_session = PROV_NON_SESSION_ATTEMPT,
420 };
421 #endif /* CONFIG_WPS2 */
422 #ifdef RW610
423
424 /*wlmon_mon_task takes 2640B with supplicant control interface API*/
425 #define CONFIG_WLCMGR_MON_STACK_SIZE (3072)
426
427 static void wlcmgr_mon_task(osa_task_param_t arg);
428
429 /* OSA_TASKS: name, priority, instances, stackSz, useFloat */
430 static OSA_TASK_DEFINE(wlcmgr_mon_task, OSA_PRIORITY_NORMAL , 1, CONFIG_WLCMGR_MON_STACK_SIZE, 0);
431
432 /* The monitor thread event queue receives events from the power manager
433 * wlan notifier when idle hook is invoked and host is ready to enter
434 * specific low power mode
435 */
436 OSA_MSGQ_HANDLE_DEFINE(mon_thread_events, MAX_EVENTS, sizeof(struct wlan_message));
437
438 #endif
439 typedef enum
440 {
441 WLCMGR_INACTIVE,
442 WLCMGR_INIT_DONE,
443 WLCMGR_ACTIVATED,
444 WLCMGR_THREAD_STOPPED,
445 WLCMGR_THREAD_DELETED,
446 } wlcmgr_status_t;
447
448 static struct
449 {
450 /* This lock enables the scan response data to be accessed by multiple
451 * threads with the expectation that any thread accessing the scan lock may
452 * have to sleep until it is available. The lock is taken by calling
453 * wlan_scan() and it is released by the WLAN Connection Manager main
454 * thread when the scan response data has been handled and
455 * is therefore free for another user. This lock must never be taken
456 * in the WLAN Connection Manager main thread and it must only be
457 * released by that thread. The lock count must be 0 or 1. */
458 OSA_SEMAPHORE_HANDLE_DEFINE(scan_lock);
459 bool is_scan_lock;
460
461 /* The WLAN Connection Manager event queue receives events (command
462 * responses, WiFi events, TCP stack events) from the wifi interface as
463 * well as user requests (connect, disconnect, scan). This is the main
464 * blocking point for the main thread and acts as the state machine tick.*/
465 OSA_MSGQ_HANDLE_DEFINE(events, MAX_EVENTS, sizeof(struct wifi_message));
466
467 /* internal state */
468 enum cm_sta_state sta_state, sta_ipv4_state;
469 #if CONFIG_IPV6
470 enum cm_sta_state sta_ipv6_state;
471 #endif
472 enum cm_sta_state sta_return_to;
473 enum cm_uap_state uap_state;
474 enum cm_uap_state uap_return_to;
475 /* store sta mac addr */
476 uint8_t sta_mac[MLAN_MAC_ADDR_LENGTH];
477 /* store uap mac addr */
478 uint8_t uap_mac[MLAN_MAC_ADDR_LENGTH];
479 #if CONFIG_P2P
480 uint8_t wfd_mac[MLAN_MAC_ADDR_LENGTH];
481 #endif
482 /* callbacks */
483 int (*cb)(enum wlan_event_reason reason, void *data);
484 int (*scan_cb)(unsigned int count);
485 void (*event_cb)(int type);
486
487 /* known networks list */
488 struct wlan_network networks[WLAN_MAX_KNOWN_NETWORKS];
489 int cur_network_idx;
490 int cur_uap_network_idx;
491
492 unsigned int num_networks;
493 unsigned int scan_count;
494
495 unsigned int uap_supported_max_sta_num;
496
497 /* CM thread */
498 OSA_TASK_HANDLE_DEFINE(wlcmgr_task_Handle);
499
500 unsigned running : 1;
501 unsigned stop_request : 1;
502 wlcmgr_status_t status;
503
504 /*
505 * Power save state configuration
506 * These are states corresponding to the network that we are currently
507 * connected to. Not relevant, when we are not connected.
508 */
509 bool cm_ieeeps_configured : 1;
510 bool cm_deepsleepps_configured : 1;
511 bool connect_wakelock_taken : 1;
512 unsigned int wakeup_conditions;
513 #if CONFIG_HOST_SLEEP
514 bool is_hs_configured : 1;
515 #endif
516 #if CONFIG_MEF_CFG
517 bool is_mef_enabled : 1;
518 #endif
519 #if (CONFIG_WNM_PS)
520 bool cm_wnmps_configured;
521 t_u16 wnm_sleep_time;
522 #endif
523 wifi_fw_version_ext_t fw_ver_ext;
524
525 #if CONFIG_WLAN_FAST_PATH
526 /* Data structures for fast path connection */
527 bool auth_cache_valid : 1;
528 bool fast_path_cache_valid : 1;
529 uint8_t fast_path_bss[MLAN_MAC_ADDR_LENGTH];
530 unsigned int fp_network;
531 #endif /* CONFIG_WLAN_FAST_PATH */
532 int uap_rsn_ie_index;
533 bool smart_mode_active : 1;
534 #if CONFIG_WPA_SUPP
535 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
536 OSA_TIMER_HANDLE_DEFINE(supp_status_timer);
537 int status_timeout;
538 bool connect : 1;
539 #endif
540 bool pending_disconnect_request : 1;
541 #if CONFIG_WPA_SUPP_WPS
542 int wps_session_attempt;
543 #endif
544 #endif
545 #if (CONFIG_WPA2_ENTP) || ((CONFIG_WPA_SUPP) && (CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE))
546 t_u8 *ca_cert_data;
547 t_u32 ca_cert_len;
548 t_u8 *client_cert_data;
549 t_u32 client_cert_len;
550 t_u8 *client_key_data;
551 t_u32 client_key_len;
552 t_u8 *ca_cert2_data;
553 t_u32 ca_cert2_len;
554 t_u8 *client_cert2_data;
555 t_u32 client_cert2_len;
556 t_u8 *client_key2_data;
557 t_u32 client_key2_len;
558 #if CONFIG_WPA_SUPP_AP
559 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
560 t_u8 *dh_data;
561 t_u32 dh_len;
562 t_u8 *server_cert_data;
563 t_u32 server_cert_len;
564 t_u8 *server_key_data;
565 t_u32 server_key_len;
566 #endif
567 #endif
568 #endif
569 OSA_TIMER_HANDLE_DEFINE(assoc_timer);
570 bool assoc_paused : 1;
571 bool pending_assoc_request : 1;
572 bool reassoc_control : 1;
573 bool reassoc_request : 1;
574 unsigned int reassoc_count;
575 bool hs_enabled;
576 bool hs_configured;
577 unsigned int hs_wakeup_condition;
578 wifi_scan_chan_list_t scan_chan_list;
579 #if CONFIG_WPA2_ENTP
580 bool allow_wpa2_enterprise_ap_only : 1;
581 #endif
582 bool hidden_scan_on : 1;
583 #if CONFIG_ROAMING
584 bool roaming_enabled : 1;
585 #endif
586 #if CONFIG_11R
587 bool ft_bss : 1;
588 #endif
589 bool same_ess : 1;
590 #if CONFIG_BG_SCAN
591 unsigned int bgscan_attempt;
592 #endif
593 bool roam_reassoc : 1;
594 #if CONFIG_WIFI_FW_DEBUG
595 void (*wlan_usb_init_cb)(void);
596 #endif
597 #if CONFIG_11R
598 #if CONFIG_WPA_SUPP
599 OSA_TIMER_HANDLE_DEFINE(ft_roam_timer);
600 #endif
601 #endif
602 #if CONFIG_11K
603 bool enable_11k : 1;
604 wlan_rrm_scan_cb_param rrm_scan_cb_param;
605 #endif
606 #if (CONFIG_11K) || (CONFIG_11V)
607 OSA_TIMER_HANDLE_DEFINE(neighbor_req_timer);
608 bool neighbor_req : 1;
609 #endif
610 #if (CONFIG_11K) || (CONFIG_11V)
611 wlan_nlist_report_param nlist_rep_param;
612 wlan_rrm_neighbor_report_t nbr_rpt;
613 #endif
614 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_11R) || (CONFIG_ROAMING)
615 uint8_t rssi_low_threshold;
616 #endif
617 uint8_t ind_reset;
618 #if CONFIG_HOST_SLEEP
619 uint8_t hs_dummy_send;
620 #endif
621 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
622 uint8_t ir_mode;
623 #endif
624 bool internal : 1;
625 } wlan;
626
627 OSA_TASK_HANDLE_DEFINE(wlcmgr_mon_task_Handle);
628 bool wlan_in_reset = false;
629
630 #if CONFIG_CLOUD_KEEP_ALIVE
631 #define MIN_KEEP_ALIVE_ID 0
632 #define MAX_KEEP_ALIVE_ID 4
633 wlan_cloud_keep_alive_t cloud_keep_alive_param[MAX_KEEP_ALIVE_ID];
634 #endif
635
636 void wlan_wake_up_card(void);
637
638 #if CONFIG_WLCMGR_DEBUG
dbg_sta_state_name(enum cm_sta_state state)639 static char *dbg_sta_state_name(enum cm_sta_state state)
640 {
641 switch (state)
642 {
643 case CM_STA_INITIALIZING:
644 return "initializing";
645 case CM_STA_IDLE:
646 return "idle";
647 case CM_STA_SCANNING:
648 return "scanning";
649 case CM_STA_SCANNING_USER:
650 return "user scanning";
651 case CM_STA_ASSOCIATING:
652 return "associating";
653 case CM_STA_ASSOCIATED:
654 return "associated";
655 case CM_STA_AUTHENTICATED:
656 return "authenticated";
657 case CM_STA_REQUESTING_ADDRESS:
658 return "requesting address";
659 case CM_STA_OBTAINING_ADDRESS:
660 return "obtaining address";
661 case CM_STA_CONNECTED:
662 return "connected";
663 default:
664 return "unknown";
665 }
666 }
667
dbg_uap_state_name(enum cm_uap_state state)668 static char *dbg_uap_state_name(enum cm_uap_state state)
669 {
670 switch (state)
671 {
672 case CM_UAP_INITIALIZING:
673 return "initializing";
674 case CM_UAP_CONFIGURED:
675 return "configured";
676 case CM_UAP_STARTED:
677 return "started";
678 case CM_UAP_IP_UP:
679 return "IP configured";
680 default:
681 return "unknown";
682 }
683 }
684
dbg_lock_info(void)685 static void dbg_lock_info(void)
686 {
687 #if 0
688 int ret;
689 char *name;
690 unsigned long cur_val, suspended_count;
691 TX_THREAD *first_suspended;
692 TX_SEMAPHORE *next;
693
694 ret = tx_semaphore_info_get(&wlan.scan_lock, &name, &cur_val,
695 &first_suspended, &suspended_count, &next);
696 if (ret) {
697 wlcm_e("unable to fetch scan lock info");
698 return;
699 }
700
701 wlcm_d("scan lock info: count=%ld, suspended=%ld", cur_val,
702 suspended_count);
703 #endif
704 }
705 #else
706 #define dbg_lock_info(...)
707 #define dbg_sta_state_name(...)
708 #define dbg_uap_state_name(...)
709 #endif /* CONFIG_WLCMGR_DEBUG */
710
711 /*
712 * Utility Functions
713 */
714
verify_scan_duration_value(int scan_duration)715 int verify_scan_duration_value(int scan_duration)
716 {
717 if (scan_duration >= 50 && scan_duration <= 500)
718 {
719 return WM_SUCCESS;
720 }
721 return -WM_FAIL;
722 }
723
verify_scan_channel_value(int channel)724 int verify_scan_channel_value(int channel)
725 {
726 if (channel >= 0 && channel <= 11)
727 {
728 return WM_SUCCESS;
729 }
730 return -WM_FAIL;
731 }
732
verify_split_scan_delay(int delay)733 int verify_split_scan_delay(int delay)
734 {
735 if (delay >= 30 && delay <= 300)
736 {
737 return WM_SUCCESS;
738 }
739 return -WM_FAIL;
740 }
741
set_scan_params(struct wifi_scan_params_t * wifi_scan_params)742 int set_scan_params(struct wifi_scan_params_t *wifi_scan_params)
743 {
744 if (!verify_scan_duration_value(wifi_scan_params->scan_duration))
745 {
746 g_wifi_scan_params.scan_duration = wifi_scan_params->scan_duration;
747 }
748 if (!verify_scan_channel_value(wifi_scan_params->channel[0]))
749 {
750 g_wifi_scan_params.channel[0] = wifi_scan_params->channel[0];
751 }
752 if (!verify_split_scan_delay(wifi_scan_params->split_scan_delay))
753 {
754 g_wifi_scan_params.split_scan_delay = wifi_scan_params->split_scan_delay;
755 }
756 return WM_SUCCESS;
757 }
758
759 #if CONFIG_RX_ABORT_CFG
wlan_set_get_rx_abort_cfg(struct wlan_rx_abort_cfg * cfg,t_u16 action)760 int wlan_set_get_rx_abort_cfg(struct wlan_rx_abort_cfg *cfg, t_u16 action)
761 {
762 return wifi_set_get_rx_abort_cfg((void *)cfg, action);
763 }
764 #endif
765
766 #if CONFIG_RX_ABORT_CFG_EXT
wlan_set_rx_abort_cfg_ext(const struct wlan_rx_abort_cfg_ext * cfg)767 int wlan_set_rx_abort_cfg_ext(const struct wlan_rx_abort_cfg_ext *cfg)
768 {
769 return wifi_set_get_rx_abort_cfg_ext((void *)cfg, ACTION_SET);
770 }
771
wlan_get_rx_abort_cfg_ext(struct wlan_rx_abort_cfg_ext * cfg)772 int wlan_get_rx_abort_cfg_ext(struct wlan_rx_abort_cfg_ext *cfg)
773 {
774 return wifi_set_get_rx_abort_cfg_ext((void *)cfg, ACTION_GET);
775 }
776 #endif
777
778 #if CONFIG_CCK_DESENSE_CFG
wlan_set_get_cck_desense_cfg(struct wlan_cck_desense_cfg * cfg,t_u16 action)779 int wlan_set_get_cck_desense_cfg(struct wlan_cck_desense_cfg *cfg, t_u16 action)
780 {
781 return wifi_set_get_cck_desense_cfg((void *)cfg, action);
782 }
783 #endif
784
get_scan_params(struct wifi_scan_params_t * wifi_scan_params)785 int get_scan_params(struct wifi_scan_params_t *wifi_scan_params)
786 {
787 wifi_scan_params->scan_duration = g_wifi_scan_params.scan_duration;
788 wifi_scan_params->channel[0] = g_wifi_scan_params.channel[0];
789 wifi_scan_params->split_scan_delay = g_wifi_scan_params.split_scan_delay;
790 return WM_SUCCESS;
791 }
792
wlan_dhcp_cleanup()793 void wlan_dhcp_cleanup()
794 {
795 net_interface_dhcp_stop(net_get_mlan_handle());
796 }
797
798 #if CONFIG_HOST_SLEEP
wlan_map_to_wifi_wakeup_condtions(const uint32_t wlan_wakeup_condtions)799 static uint32_t wlan_map_to_wifi_wakeup_condtions(const uint32_t wlan_wakeup_condtions)
800 {
801 uint32_t conditions = 0;
802 if ((wlan_wakeup_condtions & WAKE_ON_UNICAST) != 0U)
803 {
804 conditions |= WIFI_WAKE_ON_UNICAST;
805 }
806
807 if ((wlan_wakeup_condtions & WAKE_ON_ALL_BROADCAST) != 0U)
808 {
809 conditions |= WIFI_WAKE_ON_ALL_BROADCAST;
810 }
811
812 if ((wlan_wakeup_condtions & WAKE_ON_MULTICAST) != 0U)
813 {
814 conditions |= WIFI_WAKE_ON_MULTICAST;
815 }
816
817 if ((wlan_wakeup_condtions & WAKE_ON_ARP_BROADCAST) != 0U)
818 {
819 conditions |= WIFI_WAKE_ON_ARP_BROADCAST;
820 }
821
822 if ((wlan_wakeup_condtions & WAKE_ON_MAC_EVENT) != 0U)
823 {
824 conditions |= WIFI_WAKE_ON_MAC_EVENT;
825 }
826
827 if ((wlan_wakeup_condtions & WAKE_ON_MGMT_FRAME) != 0U)
828 {
829 conditions |= WIFI_WAKE_ON_MGMT_FRAME;
830 }
831
832 return conditions;
833 }
834 #endif
835
wlan_is_started()836 int wlan_is_started()
837 {
838 return ((wlan.running == 1) && (wlan.status == WLCMGR_ACTIVATED));
839 }
840
is_user_scanning(void)841 static bool is_user_scanning(void)
842 {
843 return (wlan.sta_state == CM_STA_SCANNING_USER);
844 }
845
is_state(enum cm_sta_state state)846 static bool is_state(enum cm_sta_state state)
847 {
848 if (is_user_scanning() == true)
849 {
850 return (wlan.sta_return_to == state);
851 }
852
853 return (wlan.sta_state == state);
854 }
855
856 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
is_uap_state(int state)857 static bool is_uap_state(int state)
858 {
859 int curr_state = wifi_nxp_hapd_state();
860
861 return (state == curr_state);
862 }
863 #else
is_uap_state(enum cm_uap_state state)864 static bool is_uap_state(enum cm_uap_state state)
865 {
866 return (wlan.uap_state == state);
867 }
868 #endif
869
is_uap_starting(void)870 static bool is_uap_starting(void)
871 {
872 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
873 int state = wifi_nxp_hapd_state();
874
875 return ((state > HAPD_IFACE_DISABLED) && (state <= HAPD_IFACE_ENABLED));
876 #else
877 return ((wlan.uap_state > CM_UAP_INITIALIZING) && (wlan.uap_state <= CM_UAP_IP_UP));
878 #endif
879 }
880
wlan_get_ipv4_addr(unsigned int * ipv4_addr)881 static int wlan_get_ipv4_addr(unsigned int *ipv4_addr)
882 {
883 return net_get_if_ip_addr(ipv4_addr, net_get_sta_handle());
884 }
885
886 #if (CONFIG_HOST_SLEEP) || (CONFIG_MEF_CFG)
wlan_get_uap_ipv4_addr(unsigned int * ipv4_addr)887 static int wlan_get_uap_ipv4_addr(unsigned int *ipv4_addr)
888 {
889 return net_get_if_ip_addr(ipv4_addr, net_get_uap_handle());
890 }
891 #endif
892
893 static int wlan_set_pmfcfg(uint8_t mfpc, uint8_t mfpr);
894
895 #if CONFIG_HOST_SLEEP
wlan_send_host_sleep_int(uint32_t wake_up_conds,bool is_config)896 static int wlan_send_host_sleep_int(uint32_t wake_up_conds, bool is_config)
897 {
898 int ret = WM_SUCCESS;
899 unsigned int ipv4_addr = 0;
900 enum wlan_bss_type type = WLAN_BSS_TYPE_STA;
901
902 if (!wlan_is_started())
903 {
904 (void)PRINTF("Wakeup condition configure is not allowed when WIFI is disabled\r\n");
905 return -WM_FAIL;
906 }
907
908 /* Check if wake_up_conds is valid or not */
909 if (wake_up_conds && (wake_up_conds != HOST_SLEEP_CFG_CANCEL) && (wake_up_conds & 0x20))
910 {
911 (void)PRINTF("Invalid wake_up_conds. Bit 5 is reserved.\r\n");
912 return -WM_FAIL;
913 }
914
915 if (!is_sta_connected() && !mlan_adap->priv[1]->media_connected)
916 {
917 if ((wake_up_conds & (WAKE_ON_ALL_BROADCAST | WAKE_ON_UNICAST | WAKE_ON_MULTICAST
918 | WAKE_ON_ARP_BROADCAST | WAKE_ON_MGMT_FRAME)) != 0)
919 {
920 wlcm_e("Connection on STA or uAP is required for configured bitmap!\r\n");
921 ret = -WM_FAIL;
922 return ret;
923 }
924 }
925
926 if (wake_up_conds == HOST_SLEEP_CFG_CANCEL)
927 {
928 wlan.hs_enabled = MFALSE;
929 wlan.hs_configured = MFALSE;
930 wlan.hs_wakeup_condition = wake_up_conds;
931 #if CONFIG_MEF_CFG
932 wlan.is_mef_enabled = MFALSE;
933 (void)memset(&g_flt_cfg, 0, sizeof(wlan_flt_cfg_t));
934 wifi_set_packet_filters(&g_flt_cfg);
935 #endif
936 }
937 #if CONFIG_CLOUD_KEEP_ALIVE
938 else if(is_config == MFALSE)
939 {
940 wlan_start_cloud_keep_alive();
941 }
942 #endif
943
944 #ifndef RW610
945 #if CONFIG_MEF_CFG
946 if (wake_up_conds == HOST_SLEEP_NO_COND)
947 {
948 wlan.hs_enabled = MTRUE;
949 wlan.hs_wakeup_condition = wake_up_conds;
950 if (g_flt_cfg.nentries == 0 && (is_config == MFALSE))
951 {
952 (void)PRINTF("No user configured MEF entries, use default ARP filters.\r\n");
953 /* User doesn't configure MEF, use default MEF entry */
954 wlan_mef_set_auto_arp(MEF_ACTION_ALLOW_AND_WAKEUP_HOST);
955 }
956 if (wlan.is_mef_enabled == MFALSE)
957 {
958 wlan.is_mef_enabled = MTRUE;
959 wifi_set_packet_filters(&g_flt_cfg);
960 }
961 }
962 else
963 #endif
964 #endif
965 {
966 wlan.hs_enabled = MTRUE;
967 wlan.hs_wakeup_condition = wlan_map_to_wifi_wakeup_condtions(wake_up_conds);
968 }
969
970 if (is_sta_ipv4_connected() != 0)
971 {
972 ret = wlan_get_ipv4_addr(&ipv4_addr);
973 if (ret != WM_SUCCESS)
974 {
975 wlcm_e("HS: cannot get STA IP, check if STA disconnected");
976 return -WM_FAIL;
977 }
978 }
979 else if (is_uap_started())
980 {
981 ret = wlan_get_uap_ipv4_addr(&ipv4_addr);
982 if (ret != WM_SUCCESS)
983 {
984 wlcm_e("HS: cannot get UAP IP, check if uAP stopped");
985 return -WM_FAIL;
986 }
987 type = WLAN_BSS_TYPE_UAP;
988 }
989 else
990 {
991 ipv4_addr = 0;
992 }
993
994 if (wlan.hs_dummy_send == MFALSE || is_config == MFALSE)
995 {
996 ret = wifi_send_hs_cfg_cmd((mlan_bss_type)type, ipv4_addr, HS_CONFIGURE, wlan.hs_wakeup_condition);
997 if (ret == WM_SUCCESS)
998 {
999 if (wake_up_conds != HOST_SLEEP_CFG_CANCEL)
1000 {
1001 wlan.hs_configured = MTRUE;
1002 }
1003 }
1004 wlan.hs_dummy_send = MTRUE;
1005 }
1006 return ret;
1007 }
1008
wlan_hs_pre_cfg(void)1009 void wlan_hs_pre_cfg(void)
1010 {
1011 if (wlan.hs_enabled == MTRUE)
1012 {
1013 (void)wlan_send_host_sleep_int(wlan.hs_wakeup_condition, MFALSE);
1014 /** Wait for HS Activate to complete */
1015 OSA_TimeDelay(1000);
1016 }
1017 }
1018
wlan_hs_post_cfg(void)1019 void wlan_hs_post_cfg(void)
1020 {
1021 uint16_t hs_wakeup_reason;
1022
1023 if (wlan.hs_enabled == MTRUE)
1024 {
1025 (void)wifi_get_wakeup_reason(&hs_wakeup_reason);
1026
1027 (void)wifi_print_wakeup_reason(hs_wakeup_reason);
1028 }
1029 }
1030
wlan_send_host_sleep(uint32_t wake_up_conds)1031 int wlan_send_host_sleep(uint32_t wake_up_conds)
1032 {
1033 if (!wlan.running)
1034 {
1035 return WLAN_ERROR_STATE;
1036 }
1037
1038 wakelock_get();
1039
1040 (void)send_user_request(CM_STA_USER_REQUEST_HS, wake_up_conds);
1041
1042 return WM_SUCCESS;
1043 }
1044
wlan_get_wakeup_reason(uint16_t * hs_wakeup_reason)1045 int wlan_get_wakeup_reason(uint16_t *hs_wakeup_reason)
1046 {
1047 return wifi_get_wakeup_reason(hs_wakeup_reason);
1048 }
1049
1050 #endif
1051
1052 #if CONFIG_HOST_SLEEP
1053 #ifdef RW610
wlan_hs_send_event(int id,void * data)1054 status_t wlan_hs_send_event(int id, void *data)
1055 {
1056 struct wlan_message msg;
1057
1058 (void)memset(&msg, 0U, sizeof(struct wlan_message));
1059 msg.data = data;
1060 msg.id = id;
1061 if (OSA_MsgQPut((osa_msgq_handle_t)mon_thread_events, &msg) != KOSA_StatusSuccess)
1062 {
1063 (void)PRINTF("PM: Failed to send msg to queue\r\n");
1064 return -WM_FAIL;
1065 }
1066 return WM_SUCCESS;
1067 }
1068 #endif
1069
1070 #if CONFIG_POWER_MANAGER
wake_timer_cb(osa_timer_arg_t arg)1071 static void wake_timer_cb(osa_timer_arg_t arg)
1072 {
1073 if(wakelock_isheld())
1074 wakelock_put();
1075 }
1076 #endif
1077
1078 #if CONFIG_MEF_CFG
wlan_wowlan_config(uint8_t is_mef,t_u32 wake_up_conds)1079 int wlan_wowlan_config(uint8_t is_mef, t_u32 wake_up_conds)
1080 #else
1081 int wlan_wowlan_config(t_u32 wake_up_conds)
1082 #endif
1083 {
1084 int ret = WM_SUCCESS;
1085
1086 if (!wlan_is_started())
1087 {
1088 (void)PRINTF("Wakeup condition configure is not allowed when WIFI is disabled\r\n");
1089 return -WM_FAIL;
1090 }
1091
1092 /* Check if wake_up_conds is valid or not */
1093 if (wake_up_conds && (wake_up_conds & 0x20))
1094 {
1095 (void)PRINTF("Invalid wake_up_conds. Bit 5 is reserved.\r\n");
1096 return -WM_FAIL;
1097 }
1098
1099 if (!is_sta_connected() && !mlan_adap->priv[1]->media_connected)
1100 {
1101 #if CONFIG_MEF_CFG
1102 if (is_mef)
1103 {
1104 wlcm_e("Connection on STA or uAP is required for MEF configuration\r\n");
1105 ret = -WM_FAIL;
1106 return ret;
1107 }
1108 else
1109 #endif
1110 if ((wake_up_conds & (WAKE_ON_ALL_BROADCAST | WAKE_ON_UNICAST | WAKE_ON_MULTICAST
1111 | WAKE_ON_ARP_BROADCAST | WAKE_ON_MGMT_FRAME)) != 0)
1112 {
1113 wlcm_e("Connection on STA or uAP is required for configured bitmap!\r\n");
1114 ret = -WM_FAIL;
1115 return ret;
1116 }
1117 }
1118
1119 #if CONFIG_MEF_CFG
1120 if (is_mef)
1121 {
1122 wlan.wakeup_conditions = 0;
1123 if (g_flt_cfg.nentries == 0)
1124 {
1125 (void)PRINTF("No user configured MEF entries, use default ARP filters.\r\n");
1126 /* User doesn't configure MEF, use default MEF entry */
1127 wlan_mef_set_auto_arp(MEF_ACTION_ALLOW_AND_WAKEUP_HOST);
1128 }
1129 wifi_set_packet_filters(&g_flt_cfg);
1130 }
1131 else
1132 #endif
1133 {
1134 wlan.wakeup_conditions = wake_up_conds;
1135 if (wake_up_conds & WIFI_WAKE_ON_MGMT_FRAME)
1136 {
1137 /* Set management frame wakeup filter config */
1138 mlan_adap->mgmt_filter[0].action = 0x3; /* not discard packet, wakeup host */
1139 mlan_adap->mgmt_filter[0].type = 0xff; /* management frames */
1140 mlan_adap->mgmt_filter[0].frame_mask = 0x3C0F; /* Frame-Mask bits :
1141 : Bit 0 - Association Request(unmask)
1142 : Bit 1 - Association Response(unmask)
1143 : Bit 2 - Re-Association Request(unmask)
1144 : Bit 3 - Re-Association Response(unmask)
1145 : Bit 4 - Probe Request(mask)
1146 : Bit 5 - Probe Response(mask)
1147 : Bit 8 - Beacon Frames(mask)
1148 : Bit 10 - Disassociation(unmask)
1149 : Bit 11 - Authentication(unmask)
1150 : Bit 12 - Deauthentication(unmask)
1151 : Bit 13 - Action Frames(unmask)
1152 */
1153 }
1154 #if CONFIG_MEF_CFG
1155 /* Clear previous MEF entries */
1156 if (g_flt_cfg.nentries != 0)
1157 {
1158 (void)memset(&g_flt_cfg, 0, sizeof(wlan_flt_cfg_t));
1159 wifi_set_packet_filters(&g_flt_cfg);
1160 }
1161 #endif
1162 }
1163
1164 return ret;
1165 }
1166
wlan_config_host_sleep(bool is_manual,t_u8 is_periodic)1167 void wlan_config_host_sleep(bool is_manual, t_u8 is_periodic)
1168 {
1169 int ret = 0;
1170
1171 #if CONFIG_WMM_UAPSD
1172 if (mlan_adap && mlan_adap->pps_uapsd_mode)
1173 {
1174 wlcm_e("Host sleep is not allowed if UAPSD/PPS is activated");
1175 return;
1176 }
1177 #endif
1178 wlan_is_manual = is_manual;
1179 if (!wlan_is_manual)
1180 {
1181 #if CONFIG_POWER_MANAGER
1182 if (!wlan_is_started())
1183 {
1184 wlcm_e("Host sleep is not allowed when WIFI is disabled\r\n");
1185 return;
1186 }
1187 if (is_periodic)
1188 wlan_host_sleep_state = HOST_SLEEP_PERIODIC;
1189 else
1190 wlan_host_sleep_state = HOST_SLEEP_ONESHOT;
1191 #endif
1192 }
1193 else
1194 {
1195 #if CONFIG_POWER_MANAGER
1196 /* Reset flag and stop timer if manual mode is selected without cancel periodic sleep */
1197 wlan_host_sleep_state = HOST_SLEEP_DISABLE;
1198 if (OSA_TimerIsRunning((osa_timer_handle_t)wake_timer))
1199 {
1200 OSA_TimerDeactivate((osa_timer_handle_t)wake_timer);
1201 wakelock_put();
1202 }
1203 #endif
1204 if (wlan.status == WLCMGR_ACTIVATED)
1205 {
1206 #if CONFIG_HOST_SLEEP
1207 /* Start host sleep handshake here if manual mode is selected */
1208 ret = wlan_send_host_sleep_int(wlan.wakeup_conditions, MFALSE);
1209 if (ret != WM_SUCCESS)
1210 {
1211 #if CONFIG_NCP_BRIDGE
1212 app_notify_event(APP_EVT_HS_CONFIG, APP_EVT_REASON_FAILURE, NULL, 0);
1213 #endif
1214 wlcm_e("Error: Failed to config host sleep");
1215 return;
1216 }
1217 #endif
1218 }
1219 }
1220 }
1221
wlan_cancel_host_sleep()1222 void wlan_cancel_host_sleep()
1223 {
1224 int ret = 0;
1225 enum wlan_bss_type type = WLAN_BSS_TYPE_STA;
1226
1227 if (!wlan_is_started())
1228 {
1229 PRINTF("Wlan not started, can't cancel host sleep\r\n");
1230 return;
1231 }
1232
1233 if (is_uap_started() != 0)
1234 type = WLAN_BSS_TYPE_UAP;
1235 ret = wifi_cancel_host_sleep((mlan_bss_type)type);
1236 if (ret != WM_SUCCESS)
1237 {
1238 wlcm_e("Error: Failed to send host sleep cancel command");
1239 return;
1240 }
1241 }
1242
wlan_clear_host_sleep_config()1243 void wlan_clear_host_sleep_config()
1244 {
1245 wlan_is_manual = MFALSE;
1246 #if CONFIG_POWER_MANAGER
1247 wlan_host_sleep_state = HOST_SLEEP_DISABLE;
1248 #if CONFIG_UART_INTERRUPT
1249 usart_suspend_flag = MFALSE;
1250 #endif
1251 if (OSA_TimerIsRunning((osa_timer_handle_t)wake_timer))
1252 {
1253 OSA_TimerDeactivate((osa_timer_handle_t)wake_timer);
1254 wakelock_put();
1255 }
1256 is_hs_handshake_done = 0;
1257 #endif
1258 #if CONFIG_MEF_CFG
1259 memset(&g_flt_cfg, 0x0, sizeof(wlan_flt_cfg_t));
1260
1261 if (wlan_is_started())
1262 {
1263 wifi_set_packet_filters(&g_flt_cfg);
1264 }
1265 #endif
1266 wakeup_by = 0;
1267 wifi_clear_wakeup_reason();
1268 wlan.wakeup_conditions = 0;
1269 wlan.is_hs_configured = MFALSE;
1270 }
1271 #endif
1272
wlan_send_sleep_confirm(void)1273 static void wlan_send_sleep_confirm(void)
1274 {
1275 enum wlan_bss_type type = WLAN_BSS_TYPE_STA;
1276
1277 if (is_uap_started() != 0)
1278 {
1279 type = WLAN_BSS_TYPE_UAP;
1280 }
1281
1282 send_sleep_confirm_command((mlan_bss_type)type);
1283 }
1284
is_bssid_any(char * b)1285 static int is_bssid_any(char *b)
1286 {
1287 return (int)(!b[0] && !b[1] && !b[2] && !b[3] && !b[4] && !b[5]);
1288 }
1289
1290 /* Check to see if the security features of our network, 'config', match with
1291 * those of a scan result, 'res' and return 1 if they do, 0 if they do not. */
security_profile_matches(const struct wlan_network * network,const struct wifi_scan_result2 * res)1292 static int security_profile_matches(const struct wlan_network *network, const struct wifi_scan_result2 *res)
1293 {
1294 const struct wlan_network_security *config = &network->security;
1295
1296 /* No security: just check that the scan result doesn't specify security */
1297 if (config->type == WLAN_SECURITY_NONE)
1298 {
1299 #if CONFIG_WPS2
1300 if (res->wps_session != WPS_SESSION_INACTIVE)
1301 return 1;
1302 #endif
1303 #if CONFIG_DRIVER_OWE
1304 if (res->trans_mode == OWE_TRANS_MODE_OPEN)
1305 {
1306 return res->trans_ssid_len;
1307 }
1308 else if (res->trans_mode == OWE_TRANS_MODE_OWE)
1309 {
1310 return res->WPA_WPA2_WEP.wpa2;
1311 }
1312 else
1313 { /* Do Nothing */
1314 }
1315 #endif
1316
1317 if (res->WPA_WPA2_WEP.wepStatic || res->WPA_WPA2_WEP.wpa2 || res->WPA_WPA2_WEP.wpa)
1318 {
1319 return WM_SUCCESS;
1320 }
1321
1322 return 1;
1323 }
1324
1325 /* WEP mode: if we are using WEP, the AP must use static WEP */
1326 if (config->type == WLAN_SECURITY_WEP_OPEN || config->type == WLAN_SECURITY_WEP_SHARED)
1327 {
1328 if (res->phtcap_ie_present)
1329 {
1330 wlcm_e(
1331 "As per Wi-Fi Certification WEP "
1332 "is not used with HT associations "
1333 "in 11n devices");
1334 return 0;
1335 }
1336 return (int)res->WPA_WPA2_WEP.wepStatic;
1337 }
1338
1339 /* WPA/WPA2 mode: if we are using WPA/WPA2, the AP must use WPA/WPA2 */
1340 if (config->type == WLAN_SECURITY_WPA_WPA2_MIXED)
1341 {
1342 return (int)(res->WPA_WPA2_WEP.wpa | res->WPA_WPA2_WEP.wpa2);
1343 }
1344
1345 /* WPA2 mode: if we are using WPA2, the AP must use WPA2 */
1346 if (config->type == WLAN_SECURITY_WPA2)
1347 {
1348 return (int)(res->WPA_WPA2_WEP.wpa2 | res->WPA_WPA2_WEP.wpa2_sha256);
1349
1350 }
1351
1352 #if CONFIG_11R
1353 /* WPA2_FT mode: if we are using WPA2, the AP must use WPA2_FT */
1354 if (config->type == WLAN_SECURITY_WPA2_FT)
1355 {
1356 return (int)(res->WPA_WPA2_WEP.ft_psk);
1357
1358 }
1359 #endif
1360
1361 /* OWE mode: if we are using OWE, the AP must use OWE */
1362 #if CONFIG_DRIVER_OWE
1363 if (config->type == WLAN_SECURITY_OWE_ONLY)
1364 {
1365 if (res->trans_mode == OWE_TRANS_MODE_OPEN)
1366 {
1367 return res->trans_ssid_len;
1368 }
1369 else
1370 {
1371 return (int)res->WPA_WPA2_WEP.owe;
1372 }
1373 }
1374 #endif
1375
1376 /* WPA mode: if we are using WPA, the AP must use WPA */
1377 if (config->type == WLAN_SECURITY_WPA)
1378 {
1379 if (res->wpa_ucstCipher.tkip != 0U)
1380 {
1381 wlcm_e(
1382 "As per Wi-Fi Certification security "
1383 "combinations \"WPA\" alone is not allowed "
1384 "security type.");
1385 wlcm_e(
1386 "Please use WLAN_SECURITY_WPA_WPA2_MIXED "
1387 "security type to connect to "
1388 "WPA(TKIP) Only AP.");
1389 return (int)!res->wpa_ucstCipher.tkip;
1390 }
1391 return (int)res->WPA_WPA2_WEP.wpa;
1392 }
1393
1394 #if CONFIG_WPA2_ENTP
1395 /* WPA2 Enterprise mode: if we are using WPA2 Enterprise,
1396 * the AP must use WPA2 Enterpise */
1397 if (config->type == WLAN_SECURITY_EAP_TLS || config->type == WLAN_SECURITY_EAP_PEAP_MSCHAPV2)
1398 return res->wpa2_entp_IE_exist;
1399 #endif
1400
1401 if ((config->type == WLAN_SECURITY_WPA3_SAE) || (config->type == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED))
1402 {
1403 uint8_t mfpc, mfpr;
1404
1405 (void)wlan_get_pmfcfg(&mfpc, &mfpr);
1406
1407 if (!mfpc && !mfpr)
1408 {
1409 wlcm_e("As per WPA3 SAE Certification, PMF is mandatory.\r\n");
1410 return WM_SUCCESS;
1411 }
1412 if (config->type == WLAN_SECURITY_WPA3_SAE)
1413 return (int)(res->WPA_WPA2_WEP.wpa3_sae);
1414 if (config->type == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED)
1415 return (int)(res->WPA_WPA2_WEP.wpa3_sae | res->WPA_WPA2_WEP.wpa2 | res->WPA_WPA2_WEP.wpa2_sha256);
1416 }
1417 return WM_SUCCESS;
1418 }
1419
1420 /* Check if 'network' matches the scan result 'res' based on network properties
1421 * and the security profile. If we found a match, update 'network' with any
1422 * new information discovered when parsing 'res'. 192 We may update the channel,
1423 * BSSID, or SSID but not the security profile. */
network_matches_scan_result(const struct wlan_network * network,const struct wifi_scan_result2 * res,uint8_t * num_channels,wlan_scan_channel_list_t * chan_list)1424 static int network_matches_scan_result(const struct wlan_network *network,
1425 const struct wifi_scan_result2 *res,
1426 uint8_t *num_channels,
1427 wlan_scan_channel_list_t *chan_list)
1428 {
1429 uint8_t null_ssid[IEEEtypes_SSID_SIZE] = {0};
1430 uint16_t idx = 0;
1431
1432 #if CONFIG_11V
1433 if ((wlan.roam_reassoc == true) && (wlan.nlist_rep_param.nlist_mode == WLAN_NLIST_11V) &&
1434 ((wlan.nlist_rep_param.btm_mode & 0x1C) != 0U))
1435 {
1436 if (memcmp((const void *)network->bssid, (const void *)res->bssid, (size_t)IEEEtypes_ADDRESS_SIZE) == 0)
1437 {
1438 return -WM_FAIL;
1439 }
1440 }
1441 #endif
1442 /* Check basic network information that we know */
1443 if (network->channel_specific && network->channel != res->Channel)
1444 {
1445 wlcm_d("%s: Channel mismatch. Got: %d Expected: %d", network->ssid, res->Channel, network->channel);
1446 return -WM_FAIL;
1447 }
1448 if (network->bssid_specific && memcmp(network->bssid, res->bssid, 6))
1449 {
1450 wlcm_d("%s: bssid mismatch.", network->ssid);
1451 return -WM_FAIL;
1452 }
1453
1454 if (network->ssid_specific != 0U)
1455 {
1456 if (!wlan.hidden_scan_on && (!memcmp(null_ssid, (const char *)res->ssid, (size_t)res->ssid_len)))
1457 {
1458 chan_list[*num_channels].chan_number = res->Channel;
1459 chan_list[*num_channels].scan_type = MLAN_SCAN_TYPE_ACTIVE;
1460 chan_list[*num_channels].scan_time = 150;
1461 (*num_channels)++;
1462 }
1463 if ((res->ssid_len == 0) ||
1464 ((strncmp((const char *)network->ssid, (const char *)res->ssid,
1465 (size_t)MAX(strlen(network->ssid), (unsigned int)res->ssid_len)) != 0)
1466 #if CONFIG_DRIVER_OWE
1467 && ((res->trans_mode == OWE_TRANS_MODE_OWE) &&
1468 (strncmp((const char *)network->trans_ssid, (const char *)res->ssid,
1469 (size_t)MAX(strlen(network->trans_ssid), (unsigned int)res->ssid_len))) != 0)
1470 #endif
1471 #if CONFIG_WLAN_BRIDGE
1472 && (strncmp((const char *)network->bridge_ssid, (const char *)res->ssid,
1473 (size_t)MAX(strlen(network->bridge_ssid), (unsigned int)res->ssid_len)) != 0)
1474 #endif
1475 ))
1476 {
1477 wlcm_d("ssid mismatch: Got: %s Expected: %s", (char *)res->ssid, network->ssid);
1478 return -WM_FAIL;
1479 }
1480 }
1481
1482 /* In case of CONFIG_WD_EXTERAL we don't parse and
1483 store the security profile.
1484 Instead the respective IE are stored in network struct as is */
1485 /* Check security information */
1486 if (network->security_specific != 0U)
1487 {
1488 if (!security_profile_matches(network, res))
1489 {
1490 wlcm_d("%s: security profile mismatch", network->ssid);
1491 return -WM_FAIL;
1492 }
1493 }
1494
1495 if (!(res->WPA_WPA2_WEP.wepStatic || res->WPA_WPA2_WEP.wpa3_sae || res->WPA_WPA2_WEP.wpa2 || res->WPA_WPA2_WEP.wpa || res->WPA_WPA2_WEP.wpa2_sha256) && (network->security.psk_len || network->security.password_len))
1496 {
1497 wlcm_d("%s: security profile mismatch", network->ssid);
1498 return -WM_FAIL;
1499 }
1500
1501 if (!wifi_11d_is_channel_allowed((int)res->Channel))
1502 {
1503 wlcm_d("%d: Channel not allowed.", res->Channel);
1504 return -WM_FAIL;
1505 }
1506
1507 if ((res->ap_pwe != network->security.pwe_derivation) && ((res->ap_pwe | network->security.pwe_derivation) == 1))
1508 {
1509 wlcm_d("%d: H2E configuration mismatch", res->ap_pwe);
1510 return -WM_FAIL;
1511 }
1512 #if CONFIG_DRIVER_MBO
1513 if (res->mbo_assoc_disallowed)
1514 {
1515 wlcm_d("%s: MBO Association disallowed.", network->ssid);
1516 return -WM_FAIL;
1517 }
1518 #endif
1519
1520 #if CONFIG_DRIVER_OWE
1521 wlcm_d("%s: Match successful", res->trans_mode == OWE_TRANS_MODE_OWE ? res->ssid : res->trans_ssid);
1522 #endif
1523 /* If the bss blacklist is not empty, check whether the network is in the blacklist or not. */
1524 /* If yes, skip this network. */
1525 if(mlan_adap->blacklist_bss.num_bssid)
1526 {
1527 for(idx = 0; idx < mlan_adap->blacklist_bss.num_bssid; idx++)
1528 {
1529 if(!memcmp(res->bssid, mlan_adap->blacklist_bss.bssids[idx], MLAN_MAC_ADDR_LENGTH))
1530 {
1531 wlcm_d("%02X:%02X:%02X:%02X:%02X:%02X : BSSID is not allowed.", res->bssid[0], res->bssid[1], res->bssid[2],
1532 res->bssid[3], res->bssid[4], res->bssid[5]);
1533 return WM_SUCCESS;
1534 }
1535 }
1536 }
1537 return WM_SUCCESS;
1538 }
1539
1540 #if CONFIG_WPA2_ENTP
wpa2_tls_init(struct wlan_network * network)1541 static int wpa2_tls_init(struct wlan_network *network)
1542 {
1543 network->security.wlan_ctx =
1544 wm_mbedtls_ssl_config_new(&network->security.tls_cert, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_VERIFY_NONE);
1545
1546 if (!network->security.wlan_ctx)
1547 {
1548 wlcm_e("TLS session init failed (ctx failed)");
1549 return -WM_FAIL;
1550 }
1551
1552 network->security.wlan_ssl = wm_mbedtls_ssl_new(network->security.wlan_ctx, 0, NULL);
1553
1554 if (!network->security.wlan_ssl)
1555 {
1556 wlcm_e("TLS session init failed (ssl failed)");
1557 wm_mbedtls_ssl_config_free(network->security.wlan_ctx);
1558 network->security.wlan_ctx = NULL;
1559 return -WM_FAIL;
1560 }
1561
1562 /* Disable SSL application data splitting as FreeRADIUS fails to
1563 * process splitted data
1564 */
1565 mbedtls_ssl_conf_cbc_record_splitting(network->security.wlan_ctx, MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED);
1566
1567 return WM_SUCCESS;
1568 }
1569
wpa2_tls_cleanup(struct wlan_network * network,bool force)1570 static void wpa2_tls_cleanup(struct wlan_network *network, bool force)
1571 {
1572 if (force)
1573 {
1574 if (network->security.wlan_ssl)
1575 {
1576 wm_mbedtls_ssl_free(network->security.wlan_ssl);
1577 network->security.wlan_ssl = NULL;
1578 if (network->security.wlan_ctx)
1579 {
1580 wm_mbedtls_ssl_config_free(network->security.wlan_ctx);
1581 network->security.wlan_ctx = NULL;
1582 }
1583 }
1584 }
1585
1586 wpa2_shutdown();
1587 wlan_set_prov_session(PROV_NON_SESSION_ATTEMPT);
1588 }
1589 #endif
1590
1591 static void wlcm_request_reconnect(enum cm_sta_state *next, struct wlan_network *network);
1592 int load_wep_key(const uint8_t *input, uint8_t *output, uint8_t *output_len, const unsigned max_output_len);
1593
1594 /* Configure the firmware and PSK Supplicant for the security settings
1595 * specified in 'network'. For WPA and WPA2 networks, we must chose between
1596 * the older TKIP cipher or the newer CCMP cipher. We prefer CCMP, however we
1597 * will chose TKIP if the AP doesn't report CCMP support. CCMP is optional for
1598 * WPA and required for WPA2, however a WPA2 AP may still have it disabled. */
configure_security(struct wlan_network * network,struct wifi_scan_result2 * res)1599 static int configure_security(struct wlan_network *network, struct wifi_scan_result2 *res)
1600 {
1601 int ret = WM_SUCCESS;
1602 switch (network->security.type)
1603 {
1604 #if CONFIG_WPA2_ENTP
1605 case WLAN_SECURITY_EAP_TLS:
1606 case WLAN_SECURITY_EAP_PEAP_MSCHAPV2:
1607 if (network->security.pmk_valid == false)
1608 {
1609 wlan_set_prov_session(PROV_ENTP_SESSION_ATTEMPT);
1610 ret = wpa2_tls_init(network);
1611 if (ret != WM_SUCCESS)
1612 return -WM_FAIL;
1613 }
1614
1615 ret = wifi_send_enable_supplicant(network->role, network->ssid);
1616 if (ret != WM_SUCCESS)
1617 return -WM_FAIL;
1618
1619 break;
1620 #endif
1621 case WLAN_SECURITY_WPA:
1622 case WLAN_SECURITY_WPA2:
1623 case WLAN_SECURITY_WPA_WPA2_MIXED:
1624 #if CONFIG_WPS2
1625 wlan_set_prov_session(PROV_NON_SESSION_ATTEMPT);
1626 #endif
1627 if (network->security.type == WLAN_SECURITY_WPA)
1628 {
1629 wlcm_d("configuring WPA security");
1630 }
1631 else if (network->security.type == WLAN_SECURITY_WPA2)
1632 {
1633 wlcm_d("configuring WPA2 security");
1634 }
1635 else
1636 {
1637 wlcm_d("configuring WPA/WPA2 Mixed security");
1638 }
1639
1640 /* the handler for the "add PSK" command calls supplicantEnable() so we
1641 * don't do it here
1642 *
1643 * TODO: at this time, the firmware will not generate a specific
1644 * response to the command sent by wifi_add_wpa_psk(). The
1645 * command+response sequence should be worked into the WLAN Connection
1646 * Manager once this is fixed.
1647 *
1648 * TODO: at this time, the PSK Supplicant caches passphrases on the
1649 * SSID however this won't work for networks with a hidden SSID. The
1650 * WLAN Connection manager will need to be updated once that's
1651 * resolved. */
1652 if (network->security.pmk_valid)
1653 {
1654 wlcm_d("adding SSID and PMK to supplicant cache");
1655
1656 /* Do not pass BSSID here as embedded supplicant fails
1657 * to derive session keys
1658 */
1659 ret = wifi_send_add_wpa_pmk((int)network->role, network->ssid, NULL, network->security.pmk,
1660 WLAN_PMK_LENGTH);
1661 }
1662 else
1663 {
1664 #if CONFIG_11R
1665 if (!wlan.ft_bss)
1666 #endif
1667 {
1668 wlcm_d("adding SSID and PSK to supplicant cache");
1669 ret = wifi_send_add_wpa_psk((int)network->role, network->ssid, network->security.psk,
1670 (unsigned int)network->security.psk_len);
1671 }
1672 }
1673
1674 if (ret != WM_SUCCESS)
1675 {
1676 return -WM_FAIL;
1677 }
1678 #if CONFIG_WLAN_BRIDGE
1679 if (network->bridge_ssid)
1680 {
1681 if (network->security.bridge_pmk_valid)
1682 {
1683 ret = wifi_send_add_wpa_pmk(network->role, network->bridge_ssid, NULL, network->security.bridge_pmk,
1684 WLAN_PMK_LENGTH);
1685 }
1686 else
1687 {
1688 ret = wifi_send_add_wpa_psk(network->role, network->bridge_ssid, network->security.bridge_psk,
1689 network->security.bridge_psk_len);
1690 }
1691
1692 if (ret != WM_SUCCESS)
1693 return -WM_FAIL;
1694 }
1695 #endif
1696 break;
1697 #if CONFIG_DRIVER_OWE
1698 case WLAN_SECURITY_OWE_ONLY:
1699 if (res->WPA_WPA2_WEP.owe != 0U)
1700 {
1701 /** This is dummy command to enable the embedded supplicant in Wi-Fi fimrware, OWE never uses any password */
1702 wlcm_d("configuring OWE security");
1703 ret = wifi_send_add_wpa3_password((int)network->role, network->ssid, "12345678",
1704 8U);
1705 }
1706 else
1707 { /* Do Nothing */
1708 }
1709 if (ret != WM_SUCCESS)
1710 {
1711 return -WM_FAIL;
1712 }
1713 break;
1714 #endif
1715 case WLAN_SECURITY_WPA3_SAE:
1716 case WLAN_SECURITY_WPA2_WPA3_SAE_MIXED:
1717 if (res->WPA_WPA2_WEP.wpa3_sae != 0U)
1718 {
1719 wlcm_d("configuring WPA3 SAE security");
1720 wlcm_d("adding SSID and WPA3 SAE PASSWORD to supplicant cache");
1721 ret = wifi_send_add_wpa3_password((int)network->role, network->ssid, network->security.password,
1722 network->security.password_len);
1723 }
1724 else if (res->WPA_WPA2_WEP.wpa2 != 0U || res->WPA_WPA2_WEP.wpa2_sha256 != 0U)
1725 {
1726 wlcm_d("configuring WPA2 security");
1727 wlcm_d("adding SSID and PSK to supplicant cache");
1728 ret = wifi_send_add_wpa_psk((int)network->role, network->ssid, network->security.password,
1729 network->security.password_len);
1730 }
1731 else
1732 { /* Do Nothing */
1733 }
1734 if (ret != WM_SUCCESS)
1735 {
1736 return -WM_FAIL;
1737 }
1738 break;
1739 case WLAN_SECURITY_WEP_OPEN:
1740 case WLAN_SECURITY_WEP_SHARED:
1741 ret = load_wep_key((const uint8_t *)network->security.psk, (uint8_t *)network->security.psk,
1742 (uint8_t *)&network->security.psk_len, sizeof(network->security.psk));
1743 if (ret != WM_SUCCESS)
1744 {
1745 return -WM_E_INVAL;
1746 }
1747
1748 ret = wifi_set_key(BSS_TYPE_STA, true, 0U, (const uint8_t *)network->security.psk,
1749 (unsigned)network->security.psk_len, NULL, 0, (const uint8_t *)network->bssid, 0);
1750
1751 if (ret != WM_SUCCESS)
1752 {
1753 return -WM_FAIL;
1754 }
1755 break;
1756
1757 case WLAN_SECURITY_NONE:
1758 #if CONFIG_WPS2
1759 if (network->wps_specific && res->wps_session != WPS_SESSION_INACTIVE)
1760 wlan_set_prov_session(PROV_WPS_SESSION_ATTEMPT);
1761 #endif
1762 break;
1763 default:
1764 wlcm_d("Unexpected wlan security");
1765 break;
1766 }
1767
1768 return WM_SUCCESS;
1769 }
1770
is_running(void)1771 static bool is_running(void)
1772 {
1773 return (wlan.running && wlan.sta_state >= CM_STA_IDLE);
1774 }
1775
is_sta_connecting(void)1776 static bool is_sta_connecting(void)
1777 {
1778 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
1779 int state = wifi_nxp_supp_state();
1780
1781 return ((state >= WPA_SCANNING) && (state <= WPA_COMPLETED));
1782 #else
1783 return ((wlan.sta_state > CM_STA_ASSOCIATING) && (wlan.sta_state <= CM_STA_CONNECTED));
1784 #endif
1785 }
1786
is_sta_idle(void)1787 static bool is_sta_idle(void)
1788 {
1789 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
1790 int state = wifi_nxp_supp_state();
1791
1792 return (state == WPA_DISCONNECTED);
1793 #else
1794 return (wlan.sta_state == CM_STA_IDLE);
1795 #endif
1796 }
1797
1798 /* Check whether we are allowed to start a user-requested scan right now. */
is_scanning_allowed(void)1799 static bool is_scanning_allowed(void)
1800 {
1801 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
1802 return (is_state(CM_STA_IDLE) || is_state(CM_STA_CONNECTED) || is_state(CM_STA_AUTHENTICATED));
1803 #else
1804 return true;
1805 #endif
1806 }
1807
1808 /*
1809 * Connection Manager actions
1810 */
do_scan(struct wlan_network * network)1811 static void do_scan(struct wlan_network *network)
1812 {
1813 int ret;
1814 uint8_t *bssid = NULL;
1815 char *ssid = NULL;
1816 #if CONFIG_WLAN_BRIDGE
1817 char *bridge_ssid = NULL;
1818 #endif
1819 unsigned int channel = 0;
1820 IEEEtypes_Bss_t type;
1821 wlan_scan_channel_list_t chan_list[1];
1822 (void)memset((uint8_t *)chan_list, 0x00, sizeof(wlan_scan_channel_list_t) * 1);
1823
1824 wlcm_d("initiating scan for network \"%s\"", network->name);
1825
1826 if (network->bssid_specific != 0U)
1827 {
1828 bssid = (uint8_t *)network->bssid;
1829 }
1830 if (network->ssid_specific != 0U)
1831 {
1832 ssid = network->ssid;
1833 #if CONFIG_WLAN_BRIDGE
1834 bridge_ssid = network->bridge_ssid;
1835 #endif
1836 }
1837 #if CONFIG_DRIVER_OWE
1838 if (network->owe_trans_mode == OWE_TRANS_MODE_OPEN)
1839 {
1840 ssid = network->trans_ssid;
1841 channel = network->channel;
1842 }
1843 #endif
1844 if (network->channel_specific != 0U)
1845 {
1846 channel = network->channel;
1847 }
1848
1849 switch (network->role)
1850 {
1851 case WLAN_BSS_ROLE_STA:
1852 type = BSS_INFRASTRUCTURE;
1853 break;
1854 default:
1855 type = BSS_INFRASTRUCTURE;
1856 break;
1857 }
1858
1859 wlan.sta_state = CM_STA_SCANNING;
1860
1861 /* comment out this, need to check if 11d needs 3 times full channel scan */
1862 /*
1863 if (wrapper_wlan_11d_support_is_enabled() && wlan.scan_count < WLAN_11D_SCAN_LIMIT)
1864 {
1865 ret = wifi_send_scan_cmd((t_u8)g_wifi_scan_params.bss_type, g_wifi_scan_params.bssid, g_wifi_scan_params.ssid,
1866 NULL, 0, NULL, 0,
1867 #if CONFIG_SCAN_WITH_RSSIFILTER
1868 0,
1869 #endif
1870 #if CONFIG_SCAN_CHANNEL_GAP
1871 scan_channel_gap,
1872 #endif
1873 false, false);
1874 }
1875 else
1876 */
1877 {
1878 if (channel != 0)
1879 {
1880 chan_list[0].chan_number = (t_u8)channel;
1881 chan_list[0].scan_type = MLAN_SCAN_TYPE_ACTIVE;
1882 chan_list[0].scan_time = 120;
1883 #if CONFIG_WLAN_BRIDGE
1884 ret = wifi_send_scan_cmd((t_u8)type, bssid, ssid, bridge_ssid, 1, chan_list, 0,
1885 #if CONFIG_SCAN_CHANNEL_GAP
1886 scan_channel_gap,
1887 #endif
1888 false, false);
1889 #else
1890 #if CONFIG_SCAN_WITH_RSSIFILTER
1891 ret = wifi_send_scan_cmd((t_u8)type, bssid, ssid, 1, 1, chan_list, 0, 0,
1892 #if CONFIG_SCAN_CHANNEL_GAP
1893 scan_channel_gap,
1894 #endif
1895 false, false);
1896 #else
1897 ret = wifi_send_scan_cmd((t_u8)type, bssid, ssid, 1, 1, chan_list, 0,
1898 #if CONFIG_SCAN_CHANNEL_GAP
1899 scan_channel_gap,
1900 #endif
1901 false, false);
1902 #endif
1903 #endif
1904 }
1905 else
1906 {
1907 #if CONFIG_SCAN_WITH_RSSIFILTER
1908 ret = wifi_send_scan_cmd((t_u8)type, bssid, ssid, 1, 0, NULL, 0, 0,
1909 #if CONFIG_SCAN_CHANNEL_GAP
1910 scan_channel_gap,
1911 #endif
1912 false, false);
1913 #else
1914 ret = wifi_send_scan_cmd((t_u8)type, bssid, ssid, 1, 0, NULL, 0,
1915 #if CONFIG_SCAN_CHANNEL_GAP
1916 scan_channel_gap,
1917 #endif
1918 false, false);
1919 #endif
1920 }
1921 }
1922 if (ret != 0)
1923 {
1924 (void)wlan_wlcmgr_send_msg(WIFI_EVENT_SCAN_RESULT, WIFI_EVENT_REASON_FAILURE, NULL);
1925 wlcm_e("error: scan failed");
1926 }
1927 else
1928 {
1929 wlan.scan_count++;
1930 }
1931 }
1932
do_hidden_scan(struct wlan_network * network,uint8_t num_channels,wlan_scan_channel_list_t * chan_list)1933 static void do_hidden_scan(struct wlan_network *network, uint8_t num_channels, wlan_scan_channel_list_t *chan_list)
1934 {
1935 int ret;
1936 uint8_t *bssid = NULL;
1937 char *ssid = NULL;
1938 IEEEtypes_Bss_t type;
1939
1940 wlcm_d("initiating scan for hidden network \"%s\"", network->name);
1941
1942 if (network->bssid_specific != 0U)
1943 {
1944 bssid = (uint8_t *)network->bssid;
1945 }
1946 if (network->ssid_specific != 0U)
1947 {
1948 ssid = network->ssid;
1949 }
1950
1951 switch (network->role)
1952 {
1953 case WLAN_BSS_ROLE_STA:
1954 type = BSS_INFRASTRUCTURE;
1955 break;
1956 default:
1957 type = BSS_INFRASTRUCTURE;
1958 break;
1959 }
1960
1961 wlan.sta_state = CM_STA_SCANNING;
1962
1963 #if CONFIG_SCAN_WITH_RSSIFILTER
1964 ret = wifi_send_scan_cmd((t_u8)type, bssid, ssid, 1, num_channels, chan_list, 0, 0,
1965 #if CONFIG_SCAN_CHANNEL_GAP
1966 scan_channel_gap,
1967 #endif
1968 false, true);
1969 #else
1970 ret = wifi_send_scan_cmd((t_u8)type, bssid, ssid, 1, num_channels, chan_list, 0,
1971 #if CONFIG_SCAN_CHANNEL_GAP
1972 scan_channel_gap,
1973 #endif
1974 false, true);
1975 #endif
1976 if (ret != 0)
1977 {
1978 (void)wlan_wlcmgr_send_msg(WIFI_EVENT_SCAN_RESULT, WIFI_EVENT_REASON_FAILURE, NULL);
1979 wlcm_e("error: scan failed");
1980 }
1981 }
1982
1983 static void do_connect_failed(enum wlan_event_reason reason);
1984
1985 #if !CONFIG_WPA_SUPP
1986 /* Start a connection attempt. To do this we choose a specific network to scan
1987 * for or the first of our list of known networks. If that network uses WEP
1988 * security, we first issue the WEP configuration command and enter the
1989 * CM_STA_CONFIGURING state, we'll get a response to this command which will
1990 * transition us to the CM_STA_SCANNING state. Otherwise we issue a scan and
1991 * enter the CM_STA_SCANNING state now. */
do_connect(int netindex)1992 static int do_connect(int netindex)
1993 {
1994 #if CONFIG_WLAN_FAST_PATH
1995 int ret;
1996 #endif /* CONFIG_WLAN_FAST_PATH */
1997
1998 #if CONFIG_WMSTATS
1999 g_wm_stats.wm_conn_att++;
2000 #endif /* CONFIG_WMSTATS */
2001
2002 /* try the specified network */
2003 if (wlan.networks[netindex].role != WLAN_BSS_ROLE_STA)
2004 {
2005 return -WM_E_INVAL;
2006 }
2007
2008 #if CONFIG_DRIVER_OWE
2009 wlan.networks[netindex].owe_trans_mode = 0;
2010 #endif
2011 wlan.cur_network_idx = netindex;
2012 wlan.scan_count = 0;
2013
2014 #if CONFIG_WLAN_FAST_PATH
2015 if (((wlan.auth_cache_valid == true) || (wlan.fast_path_cache_valid == true)) &&
2016 (wlan.cur_network_idx == wlan.fp_network))
2017 {
2018 wlcm_d("Fast Path: Taking fast path");
2019
2020 /* Fast path: Jump directly to associating state */
2021 wlan.sta_state = CM_STA_ASSOCIATING;
2022 ret = wrapper_wifi_assoc(wlan.fast_path_bss, wlan.networks[wlan.cur_network_idx].security.type,
2023 wlan.networks[wlan.cur_network_idx].security.ucstCipher.tkip, 0, false);
2024 if (ret == WM_SUCCESS)
2025 return WM_SUCCESS;
2026
2027 wlcm_d("Fast path assoc failed. Will try normal assoc");
2028 wlan.auth_cache_valid = false;
2029 wlan.fast_path_cache_valid = false;
2030 }
2031
2032 #endif /* CONFIG_WLAN_FAST_PATH */
2033 do_scan(&wlan.networks[netindex]);
2034
2035 return WM_SUCCESS;
2036 }
2037 #endif
2038 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
do_start(struct wlan_network * network)2039 static int do_start(struct wlan_network *network)
2040 {
2041 int ret = 0;
2042 uint8_t active_chan_list[40];
2043 uint8_t active_num_chans = 0;
2044 wifi_scan_chan_list_t scan_chan_list;
2045 #if CONFIG_WPA_SUPP
2046 struct netif *netif = net_get_uap_interface();
2047 #else
2048 uint8_t i;
2049 #endif
2050
2051 if (network->role == WLAN_BSS_ROLE_UAP)
2052 {
2053 if (network->channel_specific == 0U)
2054 {
2055 network->channel = UAP_DEFAULT_CHANNEL;
2056
2057 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED)))
2058 {
2059 network->channel = wlan.networks[wlan.cur_network_idx].channel;
2060 #if CONFIG_WPA_SUPP
2061 network->sec_channel_offset = wifi_get_sec_channel_offset(network->channel);
2062 if (network->channel == 14)
2063 {
2064 wpa_supp_set_ap_bw(netif, 1);
2065 }
2066 #endif
2067 }
2068 else
2069 {
2070 if (!wlan_uap_scan_chan_list_set)
2071 {
2072 wifi_get_active_channel_list(active_chan_list, &active_num_chans,
2073 wlan.networks[wlan.cur_uap_network_idx].acs_band);
2074
2075 if (active_num_chans != 0U)
2076 {
2077 scan_chan_list.num_of_chan = active_num_chans;
2078 (void)memcpy((void *)scan_chan_list.chan_number, (const void *)active_chan_list,
2079 active_num_chans);
2080 wlan_uap_set_scan_chan_list(scan_chan_list);
2081 }
2082 }
2083 }
2084 }
2085 else
2086 {
2087 #if CONFIG_11AC
2088 t_u8 bandwidth = wifi_uap_get_bandwidth();
2089 if (bandwidth == BANDWIDTH_80MHZ)
2090 {
2091 if ((wlan.networks[wlan.cur_uap_network_idx].acs_band == 0)
2092 #if CONFIG_WIFI_CAPA
2093 || ((wlan.networks[wlan.cur_uap_network_idx].acs_band == 1) && (!(network->wlan_capa & (WIFI_SUPPORT_11AX | WIFI_SUPPORT_11AC))))
2094 #endif
2095 )
2096 {
2097 wlcm_e("uAP configured bandwidth not allowed");
2098 CONNECTION_EVENT(WLAN_REASON_UAP_START_FAILED, NULL);
2099 wlan.cur_uap_network_idx = -1;
2100 return -WM_FAIL;
2101 }
2102 }
2103 #endif
2104 #if CONFIG_WPA_SUPP
2105 network->sec_channel_offset = wifi_get_sec_channel_offset(network->channel);
2106 if (network->channel == 14)
2107 {
2108 wpa_supp_set_ap_bw(netif, 1);
2109 }
2110 #else
2111 wifi_get_active_channel_list(active_chan_list, &active_num_chans,
2112 wlan.networks[wlan.cur_uap_network_idx].acs_band);
2113
2114 for (i = 0; i < active_num_chans; i++)
2115 {
2116 if (network->channel == active_chan_list[i])
2117 {
2118 break;
2119 }
2120 }
2121 if (i == active_num_chans)
2122 {
2123 wlcm_e("uAP configured channel not allowed");
2124 CONNECTION_EVENT(WLAN_REASON_UAP_START_FAILED, NULL);
2125 wlan.cur_uap_network_idx = -1;
2126 return -WM_FAIL;
2127 }
2128 #endif
2129 }
2130
2131 wlcm_d("starting our own network");
2132
2133 #if CONFIG_WIFI_CAPA
2134 if (network->channel == 14)
2135 {
2136 wifi_uap_config_wifi_capa(WIFI_SUPPORT_LEGACY);
2137 }
2138 else
2139 {
2140 wifi_uap_config_wifi_capa(network->wlan_capa);
2141 }
2142 #endif
2143
2144 #if CONFIG_WPA_SUPP
2145 if (network->bssid_specific == 0U)
2146 {
2147 (void)memcpy(&network->bssid[0], &wlan.uap_mac[0], MLAN_MAC_ADDR_LENGTH);
2148 }
2149
2150 t_u8 bandwidth = wifi_uap_get_bandwidth();
2151
2152 #if defined(SD8801) || defined(RW610)
2153 wpa_supp_set_ap_bw(netif, 1);
2154 #else
2155 wpa_supp_set_ap_bw(netif, bandwidth);
2156 #endif
2157 ret = wpa_supp_start_ap(netif, network, 0);
2158 #else
2159 if (network->channel == 14)
2160 {
2161 wifi_uap_set_bandwidth(BANDWIDTH_20MHZ);
2162 }
2163
2164 ret = wifi_uap_start((mlan_bss_type)network->type, network->ssid,
2165 #if CONFIG_P2P
2166 wlan.wfd_mac,
2167 #else
2168 wlan.uap_mac,
2169 #endif
2170 (int)network->security.type, network->security.key_mgmt, &network->security.psk[0], &network->security.password[0],
2171 (int)network->channel, wlan.scan_chan_list,
2172 network->security.pwe_derivation,
2173 network->security.transition_disable,
2174 network->security.mfpc,
2175 #if CONFIG_WIFI_DTIM_PERIOD
2176 network->security.mfpr, network->dtim_period
2177 #else
2178 network->security.mfpr
2179 #endif
2180 );
2181 #endif
2182 if (ret != WM_SUCCESS)
2183 {
2184 wlcm_e("uAP start failed, giving up");
2185 CONNECTION_EVENT(WLAN_REASON_UAP_START_FAILED, NULL);
2186 wlan.cur_uap_network_idx = -1;
2187 return -WM_FAIL;
2188 }
2189
2190 #if CONFIG_WPA_SUPP
2191 if (ret == WM_SUCCESS)
2192 {
2193 wlan.connect = false;
2194 wlan.status_timeout = 0;
2195 (void)OSA_TimerActivate((osa_timer_handle_t)wlan.supp_status_timer);
2196 }
2197 #endif
2198
2199 wlan.uap_state = CM_UAP_CONFIGURED;
2200 }
2201 return WM_SUCCESS;
2202 }
2203
do_stop(struct wlan_network * network)2204 static int do_stop(struct wlan_network *network)
2205 {
2206 int ret = WM_SUCCESS;
2207 #if CONFIG_WPA_SUPP
2208 struct netif *netif = net_get_uap_interface();
2209 #endif
2210
2211 wlcm_d("stopping our own network");
2212
2213 if (network->role == WLAN_BSS_ROLE_UAP)
2214 {
2215 #if CONFIG_WPA_SUPP
2216 ret = wpa_supp_stop_ap(netif, network);
2217 #else
2218 ret = wifi_uap_stop();
2219 #endif
2220 if (ret != 0)
2221 {
2222 wlcm_e("uAP stop failed, giving up");
2223 CONNECTION_EVENT(WLAN_REASON_UAP_STOP_FAILED, NULL);
2224 return -WM_FAIL;
2225 }
2226 wlan_uap_set_bandwidth(UAP_DEFAULT_BANDWIDTH);
2227 wlan_uap_set_beacon_period(UAP_DEFAULT_BEACON_PERIOD);
2228 wlan_uap_set_hidden_ssid(UAP_DEFAULT_HIDDEN_SSID);
2229 wlan.uap_state = CM_UAP_INITIALIZING;
2230 wlan.cur_uap_network_idx = -1;
2231 }
2232
2233 return WM_SUCCESS;
2234 }
2235 #endif
2236 /* A connection attempt has failed for 'reason', decide whether to try to
2237 * connect to another network (in that case, tell the state machine to
2238 * transition to CM_STA_CONFIGURING to try that network) or finish attempting to
2239 * connect by releasing the scan lock and informing the user. */
do_connect_failed(enum wlan_event_reason reason)2240 static void do_connect_failed(enum wlan_event_reason reason)
2241 {
2242 #if (CONFIG_DRIVER_OWE) || (CONFIG_WPA2_ENTP)
2243 struct wlan_network *network = &wlan.networks[wlan.cur_network_idx];
2244 #endif
2245 #if CONFIG_WMSTATS
2246 g_wm_stats.wm_conn_fail++;
2247 switch (reason)
2248 {
2249 case WLAN_REASON_NETWORK_AUTH_FAILED:
2250 g_wm_stats.wm_auth_fail++;
2251 break;
2252 case WLAN_REASON_NETWORK_NOT_FOUND:
2253 g_wm_stats.wm_nwnt_found++;
2254 break;
2255 default:
2256 wlcm_d("Unexpected connect fail reason");
2257 break;
2258 }
2259 #endif /* CONFIG_WMSTATS */
2260
2261 #if CONFIG_WPA2_ENTP
2262 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
2263 {
2264 wpa2_tls_cleanup(network, false);
2265 }
2266 #endif
2267 if (wlan.connect_wakelock_taken)
2268 {
2269 #if CONFIG_HOST_SLEEP
2270 wakelock_put();
2271 #endif
2272 wlan.connect_wakelock_taken = false;
2273 }
2274
2275 #if CONFIG_DRIVER_OWE
2276 if (network->trans_ssid_specific && network->trans_ssid_len)
2277 {
2278 (void)memset(&network->trans_ssid, 0x00, sizeof(network->trans_ssid));
2279 network->trans_ssid_len = 0;
2280 }
2281 #endif
2282
2283 wlcm_d("connecting to \"%s\" failed", wlan.networks[wlan.cur_network_idx].name);
2284
2285 if (wlan.sta_state == CM_STA_SCANNING_USER)
2286 {
2287 wlan.sta_return_to = CM_STA_IDLE;
2288 }
2289
2290 wlan.sta_state = CM_STA_IDLE;
2291 CONNECTION_EVENT(reason, NULL);
2292 }
2293
report_scan_results(void)2294 static void report_scan_results(void)
2295 {
2296 unsigned int count;
2297 if (wlan.scan_cb != NULL)
2298 {
2299 if (wifi_get_scan_result_count(&count) != WM_SUCCESS)
2300 {
2301 count = 0;
2302 }
2303 (void)wlan.scan_cb(count);
2304 wlan.scan_cb = NULL;
2305 }
2306 }
2307
update_network_params(struct wlan_network * network,const struct wifi_scan_result2 * res)2308 static void update_network_params(struct wlan_network *network, const struct wifi_scan_result2 *res)
2309 {
2310 if (!network->security_specific)
2311 {
2312 /* Wildcard: If wildcard security is specified, copy the highest
2313 * security available in the scan result to the configuration
2314 * structure
2315 */
2316 enum wlan_security_type t = WLAN_SECURITY_NONE;
2317 int key_mgmt = WLAN_KEY_MGMT_NONE;
2318
2319 if ((res->WPA_WPA2_WEP.wpa3_sae != 0U) && (res->WPA_WPA2_WEP.wpa2 != 0U))
2320 {
2321 t = WLAN_SECURITY_WPA2_WPA3_SAE_MIXED;
2322 key_mgmt = WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_SAE;
2323 }
2324 else if (res->WPA_WPA2_WEP.wpa3_sae != 0U)
2325 {
2326 t = WLAN_SECURITY_WPA3_SAE;
2327 key_mgmt = WLAN_KEY_MGMT_SAE;
2328 }
2329 else if (res->WPA_WPA2_WEP.wpa2 != 0U)
2330 {
2331 t = WLAN_SECURITY_WPA2;
2332 key_mgmt = WLAN_KEY_MGMT_PSK;
2333 }
2334 else if (res->WPA_WPA2_WEP.wpa != 0U)
2335 {
2336 t = WLAN_SECURITY_WPA_WPA2_MIXED;
2337 key_mgmt = WLAN_KEY_MGMT_PSK;
2338 }
2339 else if (res->WPA_WPA2_WEP.wepStatic != 0U)
2340 {
2341 t = WLAN_SECURITY_WEP_OPEN;
2342 }
2343 #if CONFIG_DRIVER_OWE
2344 else if (res->WPA_WPA2_WEP.wpa2 && res->WPA_WPA2_WEP.owe)
2345 {
2346 t = WLAN_SECURITY_OWE_ONLY;
2347 key_mgmt = WLAN_KEY_MGMT_OWE;
2348 }
2349 #endif
2350 else
2351 {
2352 t = WLAN_SECURITY_NONE;
2353 key_mgmt = WLAN_KEY_MGMT_NONE;
2354 }
2355
2356 network->security.type = t;
2357 network->security.key_mgmt = key_mgmt;
2358
2359 if ((network->security.type == WLAN_SECURITY_WPA2) || (network->security.type == WLAN_SECURITY_WPA3_SAE) || (network->security.type == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED))
2360 {
2361 network->security.mfpr = 0;
2362 (void)wlan_set_pmfcfg((t_u8)network->security.mfpc, (t_u8)network->security.mfpr);
2363 }
2364 }
2365
2366 network->dot11n = res->phtcap_ie_present;
2367
2368 #if CONFIG_11AC
2369 network->dot11ac = res->pvhtcap_ie_present;
2370 #endif
2371 #if CONFIG_11AX
2372 network->dot11ax = res->phecap_ie_present;
2373 #endif
2374
2375 #if CONFIG_11R
2376
2377 network->mdid = res->mdid;
2378
2379 if (res->WPA_WPA2_WEP.ft_1x != 0U)
2380 {
2381 network->ft_1x = 1;
2382 }
2383 else if (res->WPA_WPA2_WEP.ft_psk != 0U)
2384 {
2385 network->ft_psk = 1;
2386 }
2387 else if (res->WPA_WPA2_WEP.ft_sae != 0U)
2388 {
2389 network->ft_sae = 1;
2390 }
2391 else
2392 {
2393 /* Do nothing */
2394 }
2395 #endif
2396
2397 /* We have a match based on the criteria we checked, update the known
2398 * network with any additional information that we got from the scan but
2399 * did not know before */
2400 if (!network->channel_specific)
2401 {
2402 network->channel = res->Channel;
2403 }
2404 if (!network->bssid_specific)
2405 {
2406 (void)memcpy((void *)network->bssid, (const void *)res->bssid, MLAN_MAC_ADDR_LENGTH);
2407 }
2408 if (!network->ssid_specific)
2409 {
2410 (void)memcpy((void *)network->ssid, (const void *)res->ssid, (size_t)res->ssid_len);
2411 }
2412
2413 network->beacon_period = res->beacon_period;
2414 network->dtim_period = res->dtim_period;
2415 #if CONFIG_DRIVER_OWE
2416 network->owe_trans_mode = res->trans_mode;
2417
2418 if (res->trans_mode == OWE_TRANS_MODE_OPEN)
2419 {
2420 (void)memset(&network->trans_ssid, 0x00, sizeof(network->trans_ssid));
2421 (void)memcpy((void *)network->trans_ssid, (const void *)res->trans_ssid, res->trans_ssid_len);
2422 network->trans_ssid_len = res->trans_ssid_len;
2423 }
2424 #endif
2425
2426 #if CONFIG_11K
2427 if (res->neighbor_report_supported == true)
2428 {
2429 network->neighbor_report_supported = true;
2430 }
2431 else
2432 {
2433 network->neighbor_report_supported = false;
2434 }
2435 #endif
2436
2437 #if CONFIG_11V
2438 if (res->bss_transition_supported == true)
2439 {
2440 network->bss_transition_supported = true;
2441 }
2442 else
2443 {
2444 network->bss_transition_supported = false;
2445 }
2446 #endif
2447
2448 network->security.is_pmf_required = res->is_pmf_required;
2449
2450 switch (network->security.type)
2451 {
2452 case WLAN_SECURITY_WPA:
2453 network->security.mcstCipher.tkip = res->wpa_mcstCipher.tkip;
2454 network->security.ucstCipher.tkip = res->wpa_ucstCipher.tkip;
2455 network->security.mcstCipher.ccmp = res->wpa_mcstCipher.ccmp;
2456 network->security.ucstCipher.ccmp = res->wpa_ucstCipher.ccmp;
2457 break;
2458 case WLAN_SECURITY_WPA2:
2459 case WLAN_SECURITY_WPA_WPA2_MIXED:
2460 #if CONFIG_WPA2_ENTP
2461 case WLAN_SECURITY_EAP_TLS:
2462 case WLAN_SECURITY_EAP_PEAP_MSCHAPV2:
2463 #endif
2464 network->security.mcstCipher.ccmp = res->rsn_mcstCipher.ccmp;
2465 network->security.ucstCipher.ccmp = res->rsn_ucstCipher.ccmp;
2466 if (!res->rsn_mcstCipher.ccmp)
2467 {
2468 network->security.mcstCipher.tkip = res->rsn_mcstCipher.tkip;
2469 }
2470 if (!res->rsn_ucstCipher.ccmp)
2471 {
2472 network->security.ucstCipher.tkip = res->rsn_ucstCipher.tkip;
2473 }
2474 if (!res->rsn_mcstCipher.tkip && !res->rsn_ucstCipher.tkip && !res->rsn_mcstCipher.ccmp &&
2475 !res->rsn_ucstCipher.ccmp)
2476 {
2477 network->security.mcstCipher.ccmp = res->wpa_mcstCipher.ccmp;
2478 network->security.ucstCipher.ccmp = res->wpa_ucstCipher.ccmp;
2479 if (!res->wpa_mcstCipher.ccmp)
2480 {
2481 network->security.mcstCipher.tkip = res->wpa_mcstCipher.tkip;
2482 }
2483 if (!res->wpa_ucstCipher.ccmp)
2484 {
2485 network->security.ucstCipher.tkip = res->wpa_ucstCipher.tkip;
2486 }
2487 }
2488 break;
2489 case WLAN_SECURITY_NONE:
2490 break;
2491 default:
2492 wlcm_d("Unexpected security nw param");
2493 break;
2494 }
2495 }
2496
start_association(struct wlan_network * network,struct wifi_scan_result2 * res)2497 static int start_association(struct wlan_network *network, struct wifi_scan_result2 *res)
2498 {
2499 int ret = WM_SUCCESS;
2500 unsigned int owe_trans_mode = 0;
2501 bool is_ft = false;
2502
2503 wlcm_d("starting association to \"%s\"", network->name);
2504 wlan.roam_reassoc = false;
2505 ret = configure_security(network, res);
2506 if (ret != 0)
2507 {
2508 wlcm_d("setting security params failed");
2509 do_connect_failed(WLAN_REASON_NETWORK_AUTH_FAILED);
2510 return -WM_FAIL;
2511 }
2512 #if CONFIG_DRIVER_OWE
2513 owe_trans_mode = res->trans_mode;
2514 #endif
2515 #if CONFIG_11R
2516 is_ft = wlan.ft_bss;
2517 wlan.ft_bss = false;
2518 #endif
2519
2520 ret = wrapper_wifi_assoc(res->bssid, (int)network->security.type, (bool)network->security.ucstCipher.tkip,
2521 owe_trans_mode, is_ft);
2522 if (ret != WM_SUCCESS)
2523 {
2524 wlcm_d("association failed");
2525 #if CONFIG_WLAN_FAST_PATH
2526 wlan.auth_cache_valid = false;
2527 wlan.fast_path_cache_valid = false;
2528 #endif /* CONFIG_WLAN_FAST_PATH */
2529 do_connect_failed(WLAN_REASON_NETWORK_AUTH_FAILED);
2530 return -WM_FAIL;
2531 }
2532 #if CONFIG_WLAN_FAST_PATH
2533 else
2534 {
2535 /* cache the scan result for fast path.
2536 * It will be marked as valid only on
2537 * successful association and authentication */
2538 wlan.auth_cache_valid = false;
2539 wlan.fast_path_cache_valid = false;
2540 (void)memcpy((void *)wlan.fast_path_bss, (const void *)res->bssid, MLAN_MAC_ADDR_LENGTH);
2541 wlan.fp_network = wlan.cur_network_idx;
2542 }
2543 #endif /* CONFIG_WLAN_FAST_PATH */
2544
2545 return ret;
2546 }
2547
2548 #if CONFIG_11V
wlan_send_btm_response(t_u8 * bssid,enum wnm_btm_status_code status)2549 static void wlan_send_btm_response(t_u8 *bssid, enum wnm_btm_status_code status)
2550 {
2551 wlan_send_mgmt_wnm_btm_resp(wlan.nlist_rep_param.dialog_token, status, wlan.nlist_rep_param.dst_addr, wlan.sta_mac,
2552 bssid, NULL, 0, wlan.nlist_rep_param.protect);
2553
2554 memset(&wlan.nlist_rep_param, 0x00, sizeof(wlan_nlist_report_param));
2555 }
2556 #endif
2557
handle_scan_results(void)2558 static void handle_scan_results(void)
2559 {
2560 unsigned int count;
2561 int ret;
2562 unsigned int i;
2563 struct wifi_scan_result2 *res;
2564 struct wlan_network *network = &wlan.networks[wlan.cur_network_idx];
2565 bool matching_ap_found = false;
2566 uint8_t num_channels = 0;
2567 wlan_scan_channel_list_t chan_list[40];
2568
2569 /* comment out this, need to check if 11d needs 3 times full channel scan */
2570 /*
2571 if (wrapper_wlan_11d_support_is_enabled() && wlan.scan_count < WLAN_11D_SCAN_LIMIT)
2572 {
2573 wlcm_d("11D enabled, re-scanning");
2574 do_scan(network);
2575 return;
2576 }
2577 */
2578
2579 /*
2580 * We need an allocation here because the lower layer puts all the
2581 * results into the same global buffer. Hence, we need a private
2582 * copy. fixme: Can be removed after this issue is fixed in the
2583 * lower layer.
2584 */
2585 #if !CONFIG_MEM_POOLS
2586 struct wifi_scan_result2 *best_ap = OSA_MemoryAllocate(sizeof(struct wifi_scan_result2));
2587 #else
2588 struct wifi_scan_result2 *best_ap = OSA_MemoryPoolAllocate(buf_512_MemoryPool);
2589 #endif
2590
2591 if (best_ap == NULL)
2592 {
2593 wlcm_d("%s: Failed to alloc scan result object", __func__);
2594 return;
2595 }
2596
2597 /* We're associating unless an error occurs, in which case we make a
2598 * decision to rescan (transition to CM_STA_SCANNING) or fail
2599 * (transition to CM_STA_IDLE or a new connection attempt) */
2600 wlan.sta_state = CM_STA_ASSOCIATING;
2601
2602 ret = wifi_get_scan_result_count(&count);
2603 if (ret != 0)
2604 {
2605 count = 0;
2606 }
2607
2608 /* 'count' scan results available, is our network there? */
2609 for (i = 0; i < count; i++)
2610 {
2611 ret = wifi_get_scan_result(i, &res);
2612 if (ret == WM_SUCCESS)
2613 {
2614 ret = network_matches_scan_result(network, res, &num_channels, chan_list);
2615 if (ret == WM_SUCCESS)
2616 {
2617 if (!matching_ap_found)
2618 {
2619 /* First matching AP found */
2620 (void)memcpy((void *)best_ap, (const void *)res, sizeof(struct wifi_scan_result2));
2621 matching_ap_found = true;
2622 /*
2623 * Continue the search. There may be an AP
2624 * with same name but better RSSI.
2625 */
2626 continue;
2627 }
2628
2629 wlcm_d("RSSI: Best AP=%d Result AP=%d", best_ap->RSSI, res->RSSI);
2630 if (best_ap->RSSI > res->RSSI)
2631 {
2632 /*
2633 * We found a network better that current
2634 * best_ap
2635 */
2636 wlcm_d("Found better AP %s on channel %d", res->ssid, res->Channel);
2637 /* Assign the new found as curr_best */
2638 (void)memcpy((void *)best_ap, (const void *)res, sizeof(struct wifi_scan_result2));
2639 }
2640
2641 /* Continue the search */
2642 }
2643 }
2644 }
2645
2646 if (matching_ap_found)
2647 {
2648 if (wlan.roam_reassoc == true)
2649 {
2650 if (memcmp((const void *)network->bssid, (const void *)best_ap->bssid, (size_t)IEEEtypes_ADDRESS_SIZE) == 0)
2651 {
2652 #if CONFIG_11V
2653 if (wlan.nlist_rep_param.nlist_mode == WLAN_NLIST_11V)
2654 {
2655 wlan_send_btm_response(NULL, WNM_BTM_REJECT_NO_SUITABLE_CANDIDATES);
2656 }
2657 #endif
2658 wlan.sta_state = CM_STA_CONNECTED;
2659 wlan.roam_reassoc = false;
2660 #if CONFIG_11R
2661 wlan.ft_bss = false;
2662 #endif
2663 #if !CONFIG_MEM_POOLS
2664 OSA_MemoryFree((void *)best_ap);
2665 #else
2666 OSA_MemoryPoolFree(buf_512_MemoryPool, best_ap);
2667 #endif
2668 return;
2669 }
2670 #if CONFIG_11V
2671 if (wlan.nlist_rep_param.nlist_mode == WLAN_NLIST_11V)
2672 {
2673 wlan_send_btm_response(best_ap->bssid, WNM_BTM_ACCEPT);
2674 }
2675 #endif
2676 }
2677
2678 wlan.same_ess = false;
2679
2680 #if CONFIG_11R
2681 if ((wlan.ft_bss == true) && (network->mdid == best_ap->mdid))
2682 {
2683 wlan.same_ess = true;
2684 }
2685 #endif
2686 wlan.same_ess |= wlan.roam_reassoc;
2687
2688 update_network_params(network, best_ap);
2689 #if CONFIG_DRIVER_OWE
2690 if (network->owe_trans_mode == OWE_TRANS_MODE_OPEN)
2691 {
2692 wlcm_d("do scan for OWE Transition SSID: %s", network->trans_ssid);
2693 #if !CONFIG_MEM_POOLS
2694 OSA_MemoryFree((void *)best_ap);
2695 #else
2696 OSA_MemoryPoolFree(buf_512_MemoryPool, best_ap);
2697 #endif
2698 do_scan(network);
2699 return;
2700 }
2701 else
2702 {
2703 #endif
2704 ret = start_association(network, best_ap);
2705 if (ret == WM_SUCCESS)
2706 {
2707 #if !CONFIG_MEM_POOLS
2708 OSA_MemoryFree((void *)best_ap);
2709 #else
2710 OSA_MemoryPoolFree(buf_512_MemoryPool, best_ap);
2711 #endif
2712 return;
2713 }
2714 #if CONFIG_DRIVER_OWE
2715 }
2716 #endif
2717 }
2718 else if (num_channels != 0U)
2719 {
2720 #if !CONFIG_MEM_POOLS
2721 OSA_MemoryFree((void *)best_ap);
2722 #else
2723 OSA_MemoryPoolFree(buf_512_MemoryPool, best_ap);
2724 #endif
2725 wlan.hidden_scan_on = true;
2726 do_hidden_scan(network, num_channels, chan_list);
2727 return;
2728 }
2729 else
2730 {
2731 /* Do Nothing */
2732 }
2733
2734 #if !CONFIG_MEM_POOLS
2735 OSA_MemoryFree((void *)best_ap);
2736 #else
2737 OSA_MemoryPoolFree(buf_512_MemoryPool, best_ap);
2738 #endif
2739
2740 if (wlan.roam_reassoc == true)
2741 {
2742 wlan.sta_state = CM_STA_CONNECTED;
2743 wlan.roam_reassoc = false;
2744 #if CONFIG_11R
2745 wlan.ft_bss = false;
2746 #endif
2747 return;
2748 }
2749
2750 #ifdef RW610
2751 /* If reset is in process, skip re-scan */
2752 if (OSA_MutexLock((osa_mutex_handle_t)reset_lock, 0) != WM_SUCCESS)
2753 {
2754 (void)PRINTF("skip re-scan when reset is in process\r\n");
2755 return;
2756 }
2757 OSA_MutexUnlock((osa_mutex_handle_t)reset_lock);
2758 #endif
2759
2760 /* We didn't find our network in the scan results set: rescan if we
2761 * have rescan attempts remaining, otherwise give up.
2762 */
2763 if (wlan.scan_count < WLAN_RESCAN_LIMIT)
2764 {
2765 wlcm_d("network not found, re-scanning");
2766 wlan.hidden_scan_on = false;
2767 do_scan(network);
2768 }
2769 else
2770 {
2771 wlcm_d("rescan limit exceeded, giving up");
2772 do_connect_failed(WLAN_REASON_NETWORK_NOT_FOUND);
2773
2774 if (wlan.reassoc_control)
2775 {
2776 wlcm_request_reconnect(&wlan.sta_state, network);
2777 }
2778 }
2779 }
2780
wlan_disable_power_save(int action)2781 static void wlan_disable_power_save(int action)
2782 {
2783 switch (action)
2784 {
2785 case WLAN_DEEP_SLEEP:
2786 wlcm_d("stopping deep sleep ps mode");
2787 (void)wifi_exit_deepsleep_power_save();
2788 break;
2789 case WLAN_IEEE:
2790 wlcm_d("stopping IEEE ps mode");
2791 (void)wifi_exit_ieee_power_save();
2792 break;
2793 #if (CONFIG_WNM_PS)
2794 case WLAN_WNM:
2795 wlcm_d("stopping WNM ps mode");
2796 (void)wifi_exit_wnm_power_save();
2797 break;
2798 #endif
2799 default:
2800 wlcm_d("Unexpected disable ps action");
2801 break;
2802 }
2803 }
2804
wlan_enable_power_save(int action)2805 static void wlan_enable_power_save(int action)
2806 {
2807 switch (action)
2808 {
2809 case WLAN_DEEP_SLEEP:
2810 wlcm_d("starting deep sleep ps mode");
2811 (void)wifi_enter_deepsleep_power_save();
2812 break;
2813 case WLAN_IEEE:
2814 wlcm_d("starting IEEE ps mode");
2815 (void)wifi_enter_ieee_power_save();
2816 break;
2817 #if (CONFIG_WNM_PS)
2818 case WLAN_WNM:
2819 wlcm_d("starting WNM ps mode");
2820 (void)wifi_enter_wnm_power_save(wlan.wnm_sleep_time);
2821 break;
2822 #endif
2823 default:
2824 wlcm_d("Unexpected ps mode");
2825 break;
2826 }
2827 }
2828
wlcm_process_sleep_event(void)2829 static void wlcm_process_sleep_event(void)
2830 {
2831 wlan_send_sleep_confirm();
2832 }
2833
wlcm_process_ieeeps_event(struct wifi_message * msg)2834 static void wlcm_process_ieeeps_event(struct wifi_message *msg)
2835 {
2836 ENH_PS_MODES action = (ENH_PS_MODES)(*((uint32_t *)msg->data));
2837 wlcm_d("got msg data :: %x", action);
2838 #if !CONFIG_MEM_POOLS
2839 OSA_MemoryFree(msg->data);
2840 #else
2841 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
2842 #endif
2843
2844 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
2845 {
2846 if (action == EN_AUTO_PS)
2847 {
2848 if (!wlan.cm_ieeeps_configured)
2849 {
2850 CONNECTION_EVENT(WLAN_REASON_PS_ENTER, (void *)WLAN_IEEE);
2851 wlan.cm_ieeeps_configured = true;
2852 }
2853 }
2854 else if (action == DIS_AUTO_PS)
2855 {
2856 wlan.cm_ieeeps_configured = false;
2857 CONNECTION_EVENT(WLAN_REASON_PS_EXIT, (void *)WLAN_IEEE);
2858 }
2859 else if (action == SLEEP_CONFIRM)
2860 {
2861 }
2862 else
2863 { /* Do Nothing */
2864 }
2865 }
2866 }
2867
wlcm_process_deepsleep_event(struct wifi_message * msg,enum cm_sta_state * next)2868 static void wlcm_process_deepsleep_event(struct wifi_message *msg, enum cm_sta_state *next)
2869 {
2870 ENH_PS_MODES action = (ENH_PS_MODES)(*((uint32_t *)msg->data));
2871 #if CONFIG_WIFI_PS_DEBUG
2872 wlcm_d("got msg data :: %x", action);
2873 #endif
2874 #if !CONFIG_MEM_POOLS
2875 OSA_MemoryFree(msg->data);
2876 #else
2877 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
2878 #endif
2879
2880 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
2881 {
2882 if (action == EN_AUTO_PS)
2883 {
2884 if(!wlan.cm_deepsleepps_configured)
2885 {
2886 CONNECTION_EVENT(WLAN_REASON_PS_ENTER, (void *)WLAN_DEEP_SLEEP);
2887 wlan.cm_deepsleepps_configured = true;
2888 }
2889 }
2890 else if (action == DIS_AUTO_PS)
2891 {
2892 wlan.cm_deepsleepps_configured = false;
2893 // CONNECTION_EVENT(WLAN_REASON_INITIALIZED, NULL);
2894 /* Skip ps-exit event for the first time
2895 after waking from PM4+DS. This will ensure
2896 that we do not send ps-exit event until
2897 wlan-init event has been sent */
2898 CONNECTION_EVENT(WLAN_REASON_PS_EXIT, (void *)WLAN_DEEP_SLEEP);
2899 }
2900 else if (action == SLEEP_CONFIRM)
2901 {
2902 }
2903 else
2904 { /* Do Nothing */
2905 }
2906 }
2907 }
2908
2909 #if (CONFIG_WNM_PS)
wlcm_process_wnmps_event(struct wifi_message * msg)2910 static void wlcm_process_wnmps_event(struct wifi_message *msg)
2911 {
2912 uint16_t action = (uint16_t)(*((uint32_t *)msg->data));
2913 wnm_sleep_result_t *wnm_sleep_result = (wnm_sleep_result_t *)&action;
2914
2915 #if !CONFIG_MEM_POOLS
2916 OSA_MemoryFree(msg->data);
2917 #else
2918 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
2919 #endif
2920
2921 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
2922 {
2923 if ((wnm_sleep_result->action == 0) && (wnm_sleep_result->result == 0))
2924 {
2925 wlcm_d("WNM enable success event: action %x result %x", wnm_sleep_result->action, wnm_sleep_result->result);
2926 if (!wlan.cm_wnmps_configured)
2927 {
2928 CONNECTION_EVENT(WLAN_REASON_PS_ENTER, (void *)WLAN_WNM);
2929 wlan.cm_wnmps_configured = true;
2930 }
2931 }
2932 else if ((wnm_sleep_result->action == 0) && (wnm_sleep_result->result == 1))
2933 {
2934 wlcm_d("WNM enable fail event: action %x result %x", wnm_sleep_result->action, wnm_sleep_result->result);
2935 wlan.cm_wnmps_configured = false;
2936 }
2937 else if (action == DIS_WNM_PS)
2938 {
2939 wlcm_d("WNM disable success event");
2940 wlan.cm_wnmps_configured = false;
2941 CONNECTION_EVENT(WLAN_REASON_PS_EXIT, (void *)WLAN_WNM);
2942 }
2943 else
2944 {
2945 /* Do nothing */
2946 }
2947 }
2948 }
2949 #endif
2950
2951 #define WL_ID_STA_DISCONN "sta_disconnected"
2952
2953 /* fixme: duplicated from legacy. Needs to be removed later. */
2954 #define IEEEtypes_REASON_MIC_FAILURE 14U
2955 #define IEEEtypes_REASON_4WAY_HANDSHK_TIMEOUT 15
2956 #define WPA2_ENTERPRISE_FAILED 0xFF
2957
wlcm_process_scan_result_event(struct wifi_message * msg,enum cm_sta_state * next)2958 static void wlcm_process_scan_result_event(struct wifi_message *msg, enum cm_sta_state *next)
2959 {
2960 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
2961 {
2962 wifi_scan_process_results();
2963 }
2964
2965 if (wlan.sta_state == CM_STA_SCANNING)
2966 {
2967 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
2968 {
2969 handle_scan_results();
2970 }
2971 *next = wlan.sta_state;
2972 wlcm_d("SM: returned to %s", dbg_sta_state_name(*next));
2973 wlcm_d("releasing scan lock (connect scan)");
2974 }
2975 else if (wlan.sta_state == CM_STA_SCANNING_USER)
2976 {
2977 #if CONFIG_WPA_SUPP
2978 #if CONFIG_11K
2979 if (wlan.enable_11k == 1U)
2980 {
2981 wifi_scan_done(msg);
2982 /*
2983 * Subscribe EVENT_RSSI_LOW if roaming is enabled.
2984 * Do this here in case roaming is not happened or failed in wpa_supplicant.
2985 */
2986 wlan_subscribe_rssi_low_event();
2987 }
2988 #endif
2989 #endif
2990 /*
2991 * zephyr l2 mgmt scan needs scan results to clear scan callback,
2992 * even if scan is failed
2993 */
2994 report_scan_results();
2995 *next = wlan.sta_return_to;
2996 wlcm_d("SM: returned to %s", dbg_sta_state_name(*next));
2997 wlcm_d("releasing scan lock (user scan)");
2998 }
2999 else
3000 {
3001 #if CONFIG_WPA_SUPP
3002 if (wlan.is_scan_lock)
3003 {
3004 wlcm_d("releasing scan lock (connect scan)");
3005 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
3006 wlan.is_scan_lock = 0;
3007 }
3008
3009 wifi_scan_done(msg);
3010 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
3011 /*
3012 * Subscribe EVENT_RSSI_LOW if roaming is enabled.
3013 * Do this here in case roaming is not happened or failed in wpa_supplicant.
3014 */
3015 wlan_subscribe_rssi_low_event();
3016
3017 /*
3018 * Zephyr l2 mgmt scan needs call report_scan_results() to clear scan callback.
3019 *
3020 * If wlan.sta_state is modified to non-CM_STA_SCANNING_USER before receiving
3021 * scan report, also should call this function to clear scan callback function.
3022 *
3023 * Otherwise scan_cb can't be cleared and will failed to do l2 mgmt scan next time.
3024 */
3025 if(wlan.scan_cb != NULL)
3026 report_scan_results();
3027 #endif
3028
3029 return;
3030 #else
3031 if (wlan.roam_reassoc == true)
3032 {
3033 if (wlan.sta_state == CM_STA_CONNECTED)
3034 {
3035 wlcm_d("SM: returned to %s", dbg_sta_state_name(*next));
3036 handle_scan_results();
3037 *next = wlan.sta_state;
3038 return;
3039 }
3040 }
3041 #endif
3042 }
3043
3044 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
3045 wlan.is_scan_lock = 0;
3046 }
3047
wlcm_process_sta_addr_config_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)3048 static void wlcm_process_sta_addr_config_event(struct wifi_message *msg,
3049 enum cm_sta_state *next,
3050 struct wlan_network *network)
3051 {
3052 /* We have a response to our configuration request from the TCP stack.
3053 * If we configured the stack with a static IP address and this was
3054 * successful, we are effectively connected so we can report success
3055 * and proceed to CM_STA_CONNECTED. If we configured the stack with
3056 * DHCP and the response is successful then the TCP stack is trying to
3057 * obtain an address for us and we should proceed to the
3058 * CM_STA_OBTAINING_ADDRESS state and wait for the
3059 * WIFI_EVENT_DHCP_CONFIG event,
3060 * which will tell us whether or not the DHCP address was
3061 * obtained. Otherwise, if we got an unsuccessful response then we
3062 * must report a connection error.
3063 *
3064 * This event is only relevant if we are connecting and have requested
3065 * a TCP stack configuration (that is, we are in the
3066 * CM_STA_REQUESTING_ADDRESS state). Otherwise, we ignore it. */
3067
3068 if (!is_state(CM_STA_REQUESTING_ADDRESS))
3069 {
3070 if (wlan.connect_wakelock_taken)
3071 {
3072 #if CONFIG_HOST_SLEEP
3073 wakelock_put();
3074 #endif
3075 wlan.connect_wakelock_taken = false;
3076 }
3077 wlcm_d("ignoring TCP configure response");
3078 return;
3079 }
3080 if (msg->reason != WIFI_EVENT_REASON_SUCCESS)
3081 {
3082 do_connect_failed(WLAN_REASON_ADDRESS_FAILED);
3083 *next = wlan.sta_state;
3084 return;
3085 }
3086 void *if_handle = NULL;
3087 switch (network->ip.ipv4.addr_type)
3088 {
3089 case ADDR_TYPE_STATIC:
3090 #if CONFIG_WMSTATS
3091 g_wm_stats.wm_addr_type = 0;
3092 #endif /* CONFIG_WMSTATS */
3093 net_configure_dns((struct net_ip_config *)&network->ip, network->role);
3094 if (network->type == WLAN_BSS_TYPE_STA)
3095 {
3096 if_handle = net_get_mlan_handle();
3097 }
3098 #if CONFIG_P2P
3099 else if (network->type == WLAN_BSS_TYPE_WIFIDIRECT)
3100 if_handle = net_get_wfd_handle();
3101 #endif /* CONFIG_P2P */
3102 (void)net_get_if_addr((struct net_ip_config *)&network->ip, if_handle);
3103 wlan.sta_state = CM_STA_CONNECTED;
3104 if (wlan.connect_wakelock_taken)
3105 {
3106 #if CONFIG_HOST_SLEEP
3107 wakelock_put();
3108 #endif
3109 wlan.connect_wakelock_taken = false;
3110 }
3111 *next = CM_STA_CONNECTED;
3112 wlan.sta_ipv4_state = CM_STA_CONNECTED;
3113 #if CONFIG_P2P
3114 if (network->security.type != WLAN_SECURITY_NONE)
3115 #endif
3116 if (wlan.reassoc_control && wlan.reassoc_request)
3117 {
3118 wlan.reassoc_count = 0;
3119 wlan.reassoc_request = false;
3120 }
3121 mlan_adap->skip_dfs = false;
3122 CONNECTION_EVENT(WLAN_REASON_SUCCESS, NULL);
3123 #if CONFIG_P2P
3124 wifi_wfd_event(false, false, (void *)1);
3125 #endif
3126 break;
3127 case ADDR_TYPE_DHCP:
3128 case ADDR_TYPE_LLA:
3129 #if CONFIG_WMSTATS
3130 g_wm_stats.wm_addr_type = 1;
3131 #endif /* CONFIG_WMSTATS */
3132 *next = CM_STA_OBTAINING_ADDRESS;
3133 wlan.sta_ipv4_state = CM_STA_OBTAINING_ADDRESS;
3134 break;
3135 default:
3136 wlcm_d("Unexpected addr type");
3137 break;
3138 } /* end of switch */
3139 #if CONFIG_IPV6
3140 /* Set the ipv6 state to obtaining address */
3141 wlan.sta_ipv6_state = CM_STA_OBTAINING_ADDRESS;
3142 #endif
3143 }
3144
wlcm_process_channel_switch_ann(enum cm_sta_state * next,struct wlan_network * network)3145 static void wlcm_process_channel_switch_ann(enum cm_sta_state *next, struct wlan_network *network)
3146 {
3147 if (!wifi_is_ecsa_enabled())
3148 {
3149 if (is_state(CM_STA_CONNECTED))
3150 {
3151 wlcm_d("Sending deauth because of channel switch");
3152 set_event_chanswann();
3153 (void)wifi_deauthenticate((uint8_t *)network->bssid);
3154 /*
3155 This function call is already present in
3156 wlan_11h_handle_event_chanswann(). Remove it from here when
3157 that function is used directly.
3158 */
3159 wrapper_wlan_11d_clear_parsedtable();
3160 wrapper_clear_media_connected_event();
3161 #if CONFIG_WLAN_FAST_PATH
3162 /*
3163 * Flush fast path cache. We do not want fast path code to
3164 * push out assoc requests on the same channel on which
3165 * radar interference was detected.
3166 */
3167 wlan.auth_cache_valid = false;
3168 wlan.fast_path_cache_valid = false;
3169 #endif /* CONFIG_WLAN_FAST_PATH */
3170 clear_event_chanswann();
3171 wlan.sta_state = CM_STA_IDLE;
3172 *next = CM_STA_IDLE;
3173 CONNECTION_EVENT(WLAN_REASON_CHAN_SWITCH, NULL);
3174 }
3175 }
3176 }
3177
3178 #if CONFIG_WPA_SUPP
wlan_get_chan_type(nxp_wifi_ch_switch_info chandef)3179 enum mlan_channel_type wlan_get_chan_type(nxp_wifi_ch_switch_info chandef)
3180 {
3181 switch (chandef.ch_width) {
3182 case CHAN_BAND_WIDTH_20_NOHT:
3183 return CHAN_NO_HT;
3184 case CHAN_BAND_WIDTH_20:
3185 return CHAN_HT20;
3186 case CHAN_BAND_WIDTH_40:
3187 if (chandef.center_freq1 > chandef.center_freq)
3188 return CHAN_HT40PLUS;
3189 return CHAN_HT40MINUS;
3190 default:
3191
3192 return CHAN_NO_HT;
3193 }
3194 }
3195
wlan_get_chan_offset(int width,int freq,int cf1,int cf2)3196 int wlan_get_chan_offset(int width, int freq, int cf1, int cf2)
3197 {
3198 int freq1 = 0;
3199
3200 switch (width)
3201 {
3202 case CHAN_BAND_WIDTH_20_NOHT:
3203 case CHAN_BAND_WIDTH_20:
3204 return 0;
3205 case CHAN_BAND_WIDTH_40:
3206 freq1 = cf1 - 10;
3207 break;
3208 case CHAN_BAND_WIDTH_80:
3209 freq1 = cf1 - 30;
3210 break;
3211 case CHAN_BAND_WIDTH_160:
3212 freq1 = cf1 - 70;
3213 break;
3214 case CHAN_BAND_WIDTH_80P80:
3215 freq1 = cf1 - 30;
3216 break;
3217 default:
3218 /* FIXME: implement this */
3219 return 0;
3220 }
3221
3222 return (abs(freq - freq1) / 20) % 2 == 0 ? 1 : -1;
3223 }
3224
wlcm_process_channel_switch_supp(struct wifi_message * msg)3225 static void wlcm_process_channel_switch_supp(struct wifi_message *msg)
3226 {
3227 chan_band_info pchan_band_info ;
3228 nxp_wifi_ch_switch_info chandef = {0,};
3229 t_u8 band = BAND_2GHZ;
3230 enum mlan_channel_type ch_type = CHAN_NO_HT;
3231 uint8_t bss_type = 0;
3232 pmlan_private pmpriv = NULL;
3233 wifi_ecsa_info *pchan_info = NULL;
3234 t_u8 channel= 0 ;
3235 const chan_freq_power_t *cfp = MNULL;
3236 mlan_adapter *pmadapter = NULL;
3237
3238 if (wifi_is_ecsa_enabled())
3239 {
3240 if (msg->data != NULL)
3241 {
3242 memset(&pchan_band_info , 0, sizeof(chan_band_info));
3243 pchan_info = (wifi_ecsa_info *)msg->data;
3244 bss_type = pchan_info->bss_type;
3245 pmpriv = mlan_adap->priv[bss_type];
3246 pmadapter = pmpriv->adapter;
3247 channel = pchan_info->channel;
3248
3249 if(is_uap_started())
3250 {
3251 pmpriv->uap_channel = channel;
3252 pmpriv->uap_state_chan_cb.channel = channel;
3253 pmpriv->uap_state_chan_cb.band_config = pchan_info->band_config;
3254 pchan_band_info.is_11n_enabled = pmpriv->is_11n_enabled;
3255 }
3256
3257 if (is_sta_connected())
3258 {
3259 wifi_set_curr_bss_channel(channel);
3260 #define MAX_CHANNEL_BAND_B 14
3261 if (channel <= MAX_CHANNEL_BAND_B)
3262 cfp = wlan_find_cfp_by_band_and_channel(pmadapter, BAND_B, channel);
3263 #if CONFIG_5GHz_SUPPORT
3264 else
3265 cfp = wlan_find_cfp_by_band_and_channel(pmadapter, BAND_A, channel);
3266 #endif
3267 if (cfp)
3268 pmpriv->curr_bss_params.bss_descriptor.freq = cfp->freq;
3269 else
3270 pmpriv->curr_bss_params.bss_descriptor.freq = 0;
3271 }
3272
3273 /* Handle Host-based DFS and non-DFS(normal uap) case */
3274 memcpy((t_u8 *)&pchan_band_info.bandcfg,(t_u8 *)&pchan_info->band_config, sizeof(pchan_info->band_config));
3275 pchan_band_info.channel = channel;
3276 #if (CONFIG_11AC)
3277 if (pchan_band_info.bandcfg.chanWidth == CHAN_BW_80MHZ)
3278 pchan_band_info.center_chan = wlan_get_center_freq_idx(pmpriv, BAND_AAC,channel,CHANNEL_BW_80MHZ);
3279 #endif
3280
3281 /*Get freq and width info*/
3282 memset(&chandef,0, sizeof(nxp_wifi_ch_switch_info));
3283 chandef.center_freq2 = 0;
3284
3285 if (pchan_band_info.bandcfg.chanBand == BAND_2GHZ)
3286 band = BAND_2GHZ;
3287 else if (pchan_band_info.bandcfg.chanBand == BAND_5GHZ)
3288 band = BAND_5GHZ;
3289
3290 chandef.center_freq = channel_to_frequency(pchan_band_info.channel, band);
3291
3292 switch (pchan_band_info.bandcfg.chanWidth)
3293 {
3294 case CHAN_BW_20MHZ:
3295 if (pchan_band_info.is_11n_enabled)
3296 chandef.ch_width = CHAN_BAND_WIDTH_20;
3297 else
3298 chandef.ch_width = CHAN_BAND_WIDTH_20_NOHT;
3299 chandef.center_freq1 = chandef.center_freq;
3300 break;
3301
3302 case CHAN_BW_40MHZ:
3303 chandef.ch_width = CHAN_BAND_WIDTH_40;
3304 if (pchan_band_info.bandcfg.chan2Offset == SEC_CHAN_ABOVE)
3305 chandef.center_freq1 = chandef.center_freq + 10;
3306 else if (pchan_band_info.bandcfg.chan2Offset == SEC_CHAN_BELOW)
3307 chandef.center_freq1 = chandef.center_freq - 10;
3308 break;
3309
3310 #if (CONFIG_11AC)
3311 case CHAN_BW_80MHZ:
3312 chandef.ch_width = CHAN_BAND_WIDTH_80;
3313 chandef.center_freq1 = channel_to_frequency(pchan_band_info.center_chan, band);
3314 break;
3315 #endif
3316
3317 default:
3318 break;
3319 }
3320
3321 /*Get type*/
3322 switch (chandef.ch_width)
3323 {
3324 case CHAN_BAND_WIDTH_20_NOHT:
3325 case CHAN_BAND_WIDTH_20:
3326 case CHAN_BAND_WIDTH_40:
3327 ch_type = wlan_get_chan_type(chandef);
3328 break;
3329 default:
3330 break;
3331 }
3332
3333 chandef.ht_enabled = 1;
3334 /*Get ht and ch_offset info*/
3335 switch (ch_type)
3336 {
3337 case CHAN_NO_HT:
3338 chandef.ht_enabled = 0;
3339 break;
3340 case CHAN_HT20:
3341 break;
3342 case CHAN_HT40PLUS:
3343 chandef.ch_offset = 1;
3344 break;
3345 case CHAN_HT40MINUS:
3346 chandef.ch_offset = -1;
3347 break;
3348 default:
3349 if (chandef.ch_width && chandef.center_freq1)
3350 {
3351 /* This can happen for example with VHT80 ch switch */
3352 chandef.ch_offset = wlan_get_chan_offset(chandef.ch_width, chandef.center_freq, chandef.center_freq1, chandef.center_freq2 ? chandef.center_freq2 : 0);
3353 }
3354 else
3355 {
3356 PRINTF("Unknown secondary channel information - following channel definition calculations may fail\r\n");
3357 }
3358 break;
3359 }
3360
3361 if(is_uap_started())
3362 {
3363 wm_wifi.supp_if_callbk_fns->ecsa_complete_callbk_fn(wm_wifi.hapd_if_priv, &chandef);
3364 (void)PRINTF("uap switch to channel %d success!\r\n", channel);
3365 }
3366
3367 if (is_sta_connected())
3368 {
3369 wm_wifi.supp_if_callbk_fns->ecsa_complete_callbk_fn(wm_wifi.if_priv, &chandef);
3370 (void)PRINTF("sta switch to channel %d success!\r\n", channel);
3371 }
3372 #if !CONFIG_MEM_POOLS
3373 OSA_MemoryFree((void *)msg->data);
3374 #else
3375 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
3376 #endif
3377 }
3378
3379 #if CONFIG_ECSA
3380 wifi_put_ecsa_sem();
3381 set_ecsa_block_tx_flag(false);
3382 #endif
3383 }
3384 else
3385 {
3386 wlcm_d("ECSA not support");
3387 if (msg->data != NULL)
3388 {
3389 #if !CONFIG_MEM_POOLS
3390 OSA_MemoryFree((void *)msg->data);
3391 #else
3392 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
3393 #endif
3394 }
3395 }
3396 }
3397 #else
wlcm_process_channel_switch(struct wifi_message * msg)3398 static void wlcm_process_channel_switch(struct wifi_message *msg)
3399 {
3400 t_u8 channel= 0 ;
3401 wifi_ecsa_info *pchan_info = NULL;
3402
3403 if (wifi_is_ecsa_enabled())
3404 {
3405 if (msg->data != NULL)
3406 {
3407 pchan_info = (wifi_ecsa_info *)msg->data;
3408 channel= pchan_info->channel;
3409
3410 if(is_uap_started())
3411 {
3412 (void)PRINTF("uap switch to channel %d success!\r\n", channel);
3413 wlan.networks[wlan.cur_uap_network_idx].channel = channel;
3414 }
3415
3416 if (is_sta_connected())
3417 {
3418 (void)PRINTF("sta switch to channel %d success!\r\n", channel);
3419 wlan.networks[wlan.cur_network_idx].channel = channel;
3420 wifi_set_curr_bss_channel(wlan.networks[wlan.cur_network_idx].channel);
3421 }
3422 #if !CONFIG_MEM_POOLS
3423 OSA_MemoryFree((void *)msg->data);
3424 #else
3425 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
3426 #endif
3427 }
3428
3429 #if CONFIG_ECSA
3430 wifi_put_ecsa_sem();
3431 set_ecsa_block_tx_flag(false);
3432 #endif
3433 }
3434 else
3435 {
3436 wlcm_d("ECSA not support");
3437 if (msg->data != NULL)
3438 {
3439 #if !CONFIG_MEM_POOLS
3440 OSA_MemoryFree((void *)msg->data);
3441 #else
3442 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
3443 #endif
3444 }
3445 }
3446 }
3447 #endif /*End of CONFIG_WPA_SUPP*/
3448
3449 #if CONFIG_HOST_SLEEP
wlcm_process_hs_config_event(void)3450 static void wlcm_process_hs_config_event(void)
3451 {
3452 /* host sleep config done event received */
3453 int ret = WM_SUCCESS;
3454 unsigned int ipv4_addr = 0;
3455 enum wlan_bss_type type = WLAN_BSS_TYPE_STA;
3456
3457 if(is_sta_ipv4_connected() != 0)
3458 {
3459 ret = wlan_get_ipv4_addr(&ipv4_addr);
3460 if (ret != WM_SUCCESS)
3461 {
3462 wlcm_e("HS : Cannot get STA IP, check if STA disconnected");
3463 return;
3464 }
3465 }
3466 /* If uap interface is up
3467 * configure host sleep for uap interface
3468 * else confiugre host sleep for station
3469 * interface.
3470 */
3471 else if (is_uap_started() != 0)
3472 {
3473 ret = wlan_get_uap_ipv4_addr(&ipv4_addr);
3474 if (ret != WM_SUCCESS)
3475 {
3476 wlcm_e("HS: Cannot get UAP IP, check if uAP stopped");
3477 return;
3478 }
3479 type = WLAN_BSS_TYPE_UAP;
3480 }
3481 else
3482 ipv4_addr = 0;
3483
3484 (void)wifi_send_hs_cfg_cmd((mlan_bss_type)type, ipv4_addr, (uint16_t)HS_ACTIVATE, 0);
3485 }
3486 #endif
3487
3488 #if CONFIG_11N
wlcm_process_addba_request(struct wifi_message * msg)3489 static void wlcm_process_addba_request(struct wifi_message *msg)
3490 {
3491 if (is_state(CM_STA_ASSOCIATED) || is_state(CM_STA_REQUESTING_ADDRESS) || is_state(CM_STA_OBTAINING_ADDRESS) ||
3492 is_state(CM_STA_CONNECTED) || is_uap_started())
3493 {
3494 (void)wrapper_wlan_cmd_11n_addba_rspgen(msg->data);
3495 }
3496 else
3497 {
3498 wlcm_d("Ignore ADDBA Request event in disconnected state");
3499 #if !CONFIG_MEM_POOLS
3500 OSA_MemoryFree((void *)msg->data);
3501 #else
3502 OSA_MemoryPoolFree(buf_256_MemoryPool, msg->data);
3503 #endif
3504 }
3505 }
3506
wlcm_process_delba_request(struct wifi_message * msg)3507 static void wlcm_process_delba_request(struct wifi_message *msg)
3508 {
3509 if (is_state(CM_STA_ASSOCIATED) || is_state(CM_STA_REQUESTING_ADDRESS) || is_state(CM_STA_OBTAINING_ADDRESS) ||
3510 is_state(CM_STA_CONNECTED) || is_uap_started())
3511 {
3512 (void)wrapper_wlan_cmd_11n_delba_rspgen(msg->data);
3513 }
3514 else
3515 {
3516 wlcm_d("Ignore DELBA Request event in disconnected state");
3517 #if !CONFIG_MEM_POOLS
3518 OSA_MemoryFree((void *)msg->data);
3519 #else
3520 OSA_MemoryPoolFree(buf_256_MemoryPool, msg->data);
3521 #endif
3522 }
3523 }
3524
wlcm_process_ba_stream_timeout_request(struct wifi_message * msg)3525 static void wlcm_process_ba_stream_timeout_request(struct wifi_message *msg)
3526 {
3527 if (is_state(CM_STA_ASSOCIATED) || is_state(CM_STA_REQUESTING_ADDRESS) || is_state(CM_STA_OBTAINING_ADDRESS) ||
3528 is_state(CM_STA_CONNECTED) || is_uap_started())
3529 {
3530 (void)wrapper_wlan_cmd_11n_ba_stream_timeout(msg->data);
3531 }
3532 else
3533 {
3534 wlcm_d(
3535 "Ignore BA STREAM TIMEOUT Request"
3536 " event in disconnected state");
3537 #if !CONFIG_MEM_POOLS
3538 OSA_MemoryFree((void *)msg->data);
3539 #else
3540 OSA_MemoryPoolFree(buf_256_MemoryPool, msg->data);
3541 #endif
3542 }
3543 }
3544 #endif
3545
wlcm_process_association_event(struct wifi_message * msg,enum cm_sta_state * next)3546 static void wlcm_process_association_event(struct wifi_message *msg, enum cm_sta_state *next)
3547 {
3548 #if CONFIG_WPA2_ENTP
3549 int ret;
3550 struct wlan_network *network = &wlan.networks[wlan.cur_network_idx];
3551 #endif
3552
3553 #if CONFIG_WLAN_FAST_PATH
3554 if (wlan.is_scan_lock)
3555 {
3556 wlcm_d("releasing scan lock for fast path");
3557 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
3558 wlan.is_scan_lock = 0;
3559 }
3560 #endif
3561 #if CONFIG_WPA_SUPP
3562 if (wlan.is_scan_lock)
3563 {
3564 wlcm_d("releasing scan lock (connect scan)");
3565 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
3566 wlan.is_scan_lock = 0;
3567 }
3568 #endif
3569
3570 /* We have received a response to the association command. We may now
3571 * proceed to authenticating if it was successful, otherwise this
3572 * connection attempt has failed.
3573 *
3574 * This event is only relevant if we have sent an association command
3575 * while connecting (that is, we are in the CM_STA_ASSOCIATING state).
3576 * Otherwise, it is ignored. */
3577
3578 #if !CONFIG_WPA_SUPP
3579 if (!is_state(CM_STA_ASSOCIATING))
3580 {
3581 wlcm_d("ignoring association result event");
3582 return;
3583 }
3584 #endif
3585
3586 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
3587 {
3588 wlan.sta_state = CM_STA_ASSOCIATED;
3589 *next = CM_STA_ASSOCIATED;
3590
3591 #if CONFIG_WPA2_ENTP
3592 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
3593 {
3594 ret = wpa2_ent_connect(network);
3595 if (ret != WM_SUCCESS)
3596 {
3597 wlcm_e("wpa2_ent_connect failed");
3598 }
3599 }
3600 #endif
3601 wlan.scan_count = 0;
3602 }
3603 #if !CONFIG_WPA_SUPP
3604 else if (wlan.scan_count < WLAN_RESCAN_LIMIT)
3605 {
3606 wlcm_d("association failed, re-scanning");
3607 #if CONFIG_WPA2_ENTP
3608 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
3609 {
3610 wpa2_tls_cleanup(network, true);
3611 }
3612 #endif
3613 /*
3614 * this scan does not hold scan lock as it was already put by wlcmgr task
3615 * need to check if need to hold scan lock again
3616 */
3617 do_scan(&wlan.networks[wlan.cur_network_idx]);
3618 *next = CM_STA_SCANNING;
3619 }
3620 #endif
3621 else
3622 {
3623 #if CONFIG_WPA2_ENTP
3624 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
3625 {
3626 wpa2_tls_cleanup(network, true);
3627 }
3628 #endif
3629 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
3630 #if CONFIG_WPA_SUPP
3631 OSA_TimerDeactivate((osa_timer_handle_t)wlan.supp_status_timer);
3632 wlan.status_timeout = 0;
3633 #endif
3634 #endif
3635
3636 #if !CONFIG_WPA_SUPP
3637 do_connect_failed(WLAN_REASON_NETWORK_AUTH_FAILED);
3638
3639 if (wlan.reassoc_control)
3640 {
3641 wlcm_request_reconnect(next, &wlan.networks[wlan.cur_network_idx]);
3642 }
3643 #endif
3644 *next = wlan.sta_state;
3645 }
3646 }
3647
3648 #if CONFIG_WPA_SUPP
3649 #if CONFIG_AUTO_RECONNECT
3650
wlcm_process_association_notify_event(struct wifi_message * msg,enum cm_sta_state * next)3651 static void wlcm_process_association_notify_event(struct wifi_message *msg, enum cm_sta_state *next)
3652 {
3653 struct netif *netif = net_get_sta_interface();
3654
3655 (void)msg;
3656 (void)next;
3657
3658 if (wlan.roam_reassoc == false)
3659 {
3660 (void)wpa_supp_notify_assoc(netif);
3661 }
3662 }
3663
3664 #endif
3665 #endif
3666
wlcm_process_pmk_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)3667 static void wlcm_process_pmk_event(struct wifi_message *msg, enum cm_sta_state *next, struct wlan_network *network)
3668 {
3669 char *bssid = network->bssid;
3670
3671 if (msg->data != NULL)
3672 {
3673 network->security.pmk_valid = true;
3674 (void)memcpy((void *)network->security.pmk, (const void *)msg->data, WLAN_PMK_LENGTH);
3675 if (network->role == WLAN_BSS_ROLE_STA)
3676 {
3677 #if CONFIG_WPA2_ENTP
3678 if (network->security.type == WLAN_SECURITY_EAP_TLS)
3679 {
3680 /* OKC-802.1X case, roaming without specifying bssid */
3681 bssid = NULL;
3682 }
3683 #endif
3684 (void)wifi_send_add_wpa_pmk((int)network->role, network->ssid, bssid, network->security.pmk,
3685 WLAN_PMK_LENGTH);
3686 }
3687 }
3688 }
3689
wlcm_process_authentication_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)3690 static void wlcm_process_authentication_event(struct wifi_message *msg,
3691 enum cm_sta_state *next,
3692 struct wlan_network *network)
3693 {
3694 #if CONFIG_STA_AUTO_DHCPV4
3695 int ret = 0;
3696 #endif
3697 void *if_handle = NULL;
3698 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
3699 #if CONFIG_WPA_SUPP
3700 struct netif *netif = net_get_sta_interface();
3701 #endif
3702 #endif
3703
3704 #if CONFIG_WPS2
3705 if (wlan_get_prov_session() == PROV_WPS_SESSION_ATTEMPT)
3706 {
3707 if(wlan.connect_wakelock_taken)
3708 {
3709 #if CONFIG_HOST_SLEEP
3710 wakelock_put();
3711 #endif
3712 wlan.connect_wakelock_taken = false;
3713 }
3714 return;
3715 }
3716 #endif
3717
3718 if (!is_state(CM_STA_ASSOCIATING) && !is_state(CM_STA_ASSOCIATED) && !is_state(CM_STA_REQUESTING_ADDRESS) &&
3719 !is_state(CM_STA_OBTAINING_ADDRESS) && !is_state(CM_STA_CONNECTED))
3720 {
3721 if (wlan.connect_wakelock_taken)
3722 {
3723 #if CONFIG_HOST_SLEEP
3724 wakelock_put();
3725 #endif
3726 wlan.connect_wakelock_taken = false;
3727 }
3728 wlcm_d("ignoring authentication event");
3729 return;
3730 }
3731
3732 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
3733 {
3734 #if CONFIG_WMSTATS
3735 g_wm_stats.wm_conn_succ++;
3736 #endif /* CONFIG_WMSTATS */
3737 #if CONFIG_WLAN_FAST_PATH
3738 if (wlan.fast_path_cache_valid == true && (wlan.cur_network_idx == wlan.fp_network))
3739 {
3740 if_handle = net_get_mlan_handle();
3741 net_interface_up(if_handle);
3742 // wakelock_put(WL_ID_CONNECT);
3743 // wlan.connect_wakelock_taken = false;
3744 wlan.sta_ipv4_state = CM_STA_CONNECTED;
3745 *next = CM_STA_CONNECTED;
3746
3747 if (wlan.reassoc_control && wlan.reassoc_request)
3748 {
3749 wlan.reassoc_count = 0;
3750 wlan.reassoc_request = false;
3751 }
3752 mlan_adap->skip_dfs = false;
3753 CONNECTION_EVENT(WLAN_REASON_SUCCESS, NULL);
3754 }
3755 else
3756 {
3757 #endif /* CONFIG_WLAN_FAST_PATH */
3758 if (network->type == WLAN_BSS_TYPE_STA)
3759 {
3760 if_handle = net_get_mlan_handle();
3761 }
3762 #if CONFIG_P2P
3763 else if (network->type == WLAN_BSS_TYPE_WIFIDIRECT)
3764 {
3765 if_handle = net_get_wfd_handle();
3766 }
3767 else
3768 {
3769 /* Do nothing */
3770 }
3771 #endif /* CONFIG_P2P */
3772 CONNECTION_EVENT(WLAN_REASON_AUTH_SUCCESS, NULL);
3773
3774 #if CONFIG_BG_SCAN
3775 wlan.bgscan_attempt = 0;
3776 #endif
3777 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
3778 #if CONFIG_WPA_SUPP
3779 OSA_TimerDeactivate((osa_timer_handle_t)wlan.supp_status_timer);
3780 wlan.status_timeout = 0;
3781
3782 wpa_supp_network_status(netif, network);
3783 #endif
3784 #endif
3785 #if CONFIG_WPA_SUPP
3786 #if CONFIG_11R
3787 wlan.same_ess = wifi_same_ess_ft();
3788 #endif
3789 wlan.roam_reassoc = false;
3790 #endif
3791 if (wlan.same_ess == true)
3792 {
3793 #if CONFIG_11R
3794 wlan.ft_bss = false;
3795 #endif
3796 (void)net_get_if_addr((struct net_ip_config *)&network->ip, if_handle);
3797 wlan.sta_state = CM_STA_CONNECTED;
3798 *next = CM_STA_CONNECTED;
3799 wlan.sta_ipv4_state = CM_STA_CONNECTED;
3800
3801 if (wlan.reassoc_control && wlan.reassoc_request)
3802 {
3803 wlan.reassoc_count = 0;
3804 wlan.reassoc_request = false;
3805 }
3806 mlan_adap->skip_dfs = false;
3807 CONNECTION_EVENT(WLAN_REASON_SUCCESS, NULL);
3808 return;
3809 }
3810
3811 #if CONFIG_STA_AUTO_DHCPV4
3812 ret = net_configure_address((struct net_ip_config *)&network->ip, if_handle);
3813 if (ret != 0)
3814 {
3815 wlcm_e("Configure Address failed");
3816 do_connect_failed(WLAN_REASON_ADDRESS_FAILED);
3817 *next = wlan.sta_state;
3818 }
3819 else
3820 {
3821 *next = CM_STA_REQUESTING_ADDRESS;
3822 wlan.sta_ipv4_state = CM_STA_REQUESTING_ADDRESS;
3823 #if CONFIG_IPV6
3824 wlan.sta_ipv6_state = CM_STA_REQUESTING_ADDRESS;
3825 #endif
3826 }
3827 #else
3828 *next = CM_STA_AUTHENTICATED;
3829 wlan.sta_ipv4_state = CM_STA_AUTHENTICATED;
3830 #if CONFIG_IPV6
3831 wlan.sta_ipv6_state = CM_STA_AUTHENTICATED;
3832 #endif
3833 #endif
3834
3835 #if CONFIG_WLAN_FAST_PATH
3836 wlan.auth_cache_valid = false;
3837 /* Mark the fast path cache valid after
3838 * successful connection. */
3839 wlcm_d("Fast Path: validating settings");
3840 wlan.fast_path_cache_valid = true;
3841 }
3842 #endif /* CONFIG_WLAN_FAST_PATH */
3843 #if CONFIG_WPA2_ENTP
3844 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT &&
3845 (network->security.type != WLAN_SECURITY_EAP_PEAP_MSCHAPV2))
3846 {
3847 wpa2_tls_cleanup(network, false);
3848 }
3849 #endif
3850 }
3851 else
3852 {
3853 #if CONFIG_WLAN_FAST_PATH
3854 wlan.auth_cache_valid = true;
3855 /* Mark the fast path cache invalid. */
3856 wlan.fast_path_cache_valid = false;
3857 #endif /* CONFIG_WLAN_FAST_PATH */
3858 #if CONFIG_WPA2_ENTP
3859 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
3860 {
3861 wpa2_tls_cleanup(network, false);
3862 }
3863 else if (wlan_get_prov_session() == PROV_NON_SESSION_ATTEMPT &&
3864 network->security.pmk_valid == true &&
3865 (network->security.type == WLAN_SECURITY_EAP_TLS || network->security.type == WLAN_SECURITY_EAP_PEAP_MSCHAPV2)
3866 )
3867 {
3868 /* If EAP_TLS re-connected but get auth failed, clear pmk_valid/pmk and enter "PROV_ENTP_SESSION_ATTEMPT" again */
3869 network->security.pmk_valid = false;
3870 memset(network->security.pmk, 0, WLAN_PMK_LENGTH);
3871 }
3872 #endif
3873 if (*((uint16_t *)msg->data) == IEEEtypes_REASON_MIC_FAILURE)
3874 {
3875 wlan.assoc_paused = true;
3876 (void)OSA_TimerActivate((osa_timer_handle_t)wlan.assoc_timer);
3877 }
3878
3879 if (is_state(CM_STA_REQUESTING_ADDRESS) || is_state(CM_STA_OBTAINING_ADDRESS))
3880 {
3881 void *if_handle = NULL;
3882 /* On Link loss, we need to take down the interface. */
3883 if (network->type == WLAN_BSS_TYPE_STA)
3884 {
3885 if_handle = net_get_mlan_handle();
3886 }
3887
3888 if (if_handle != NULL)
3889 {
3890 /* Forcefully stop dhcp on given interface.
3891 * net_interface_dhcp_stop internally does nothing
3892 * if dhcp client is not started.
3893 */
3894 net_interface_dhcp_stop(if_handle);
3895 net_interface_down(if_handle);
3896 }
3897 }
3898
3899 #if !CONFIG_WPA_SUPP
3900 if (is_state(CM_STA_ASSOCIATED))
3901 {
3902 (void)wifi_deauthenticate((uint8_t *)network->bssid);
3903 }
3904 #endif
3905 wlan.sta_return_to = CM_STA_IDLE;
3906 wlan.sta_state = CM_STA_IDLE;
3907 *next = CM_STA_IDLE;
3908 wlan.sta_ipv4_state = CM_STA_IDLE;
3909 #if CONFIG_IPV6
3910 wlan.sta_ipv6_state = CM_STA_IDLE;
3911 #endif
3912
3913 #if !CONFIG_WPA_SUPP
3914 do_connect_failed(WLAN_REASON_NETWORK_AUTH_FAILED);
3915 #endif
3916
3917 if (wlan.reassoc_control)
3918 {
3919 wlcm_request_reconnect(next, network);
3920 }
3921
3922 #if CONFIG_P2P
3923 wifi_wfd_event(false, false, NULL);
3924 #endif
3925 }
3926 }
3927
3928 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_ROAMING)
3929 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
wlcm_process_rssi_low_event(struct wifi_message * msg)3930 static void wlcm_process_rssi_low_event(struct wifi_message *msg)
3931 {
3932 t_s16 curr_rssi = *(t_s16 *)msg->data;
3933
3934 wm_wifi.supp_if_callbk_fns->signal_change_callbk_fn(wm_wifi.if_priv, &curr_rssi);
3935 #if !CONFIG_MEM_POOLS
3936 OSA_MemoryFree(msg->data);
3937 #else
3938 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
3939 #endif
3940 }
3941 #else
3942 /** Try to roaming if enabled based on priority:
3943 * 1. 11R roaming (full channel scan)
3944 * 2. 11K roaming
3945 * 3. 11V roaming
3946 * 4. Legacy roaming (full channel scan)
3947 *
3948 * If not trigger roaming, subscribe RSSI low event again
3949 */
wlcm_process_rssi_low_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)3950 static void wlcm_process_rssi_low_event(struct wifi_message *msg, enum cm_sta_state *next, struct wlan_network *network)
3951 {
3952 #if !CONFIG_ROAMING
3953 wlcm_d("wlcm_process_rssi_low_event roaming not support");
3954 return;
3955 #else
3956 bool set_rssi_threshold = false;
3957 #if CONFIG_BG_SCAN || CONFIG_11K || CONFIG_11V
3958 int ret;
3959 #endif
3960
3961 if (wlan.roaming_enabled == false)
3962 {
3963 wlcm_d("wlcm_process_rssi_low_event roaming disabled");
3964 return;
3965 }
3966
3967 #if CONFIG_11R
3968 if (wlan.roam_reassoc == false)
3969 {
3970 wlan.ft_bss = false;
3971 if ((network->ft_psk | network->ft_1x | network->ft_sae) == 1U)
3972 {
3973 wlan.ft_bss = true;
3974 wlan.roam_reassoc = true;
3975
3976 #if CONFIG_BG_SCAN
3977 ret = wifi_config_bgscan_and_rssi(network->ssid);
3978 if (ret == WM_SUCCESS)
3979 {
3980 wlcm_d("bgscan config successful");
3981 return;
3982 }
3983 #endif
3984 wlan.roam_reassoc = false;
3985 set_rssi_threshold = true;
3986 }
3987 }
3988 else
3989 {
3990 wlcm_d("11R Roaming already in progress");
3991 (void)wifi_set_rssi_low_threshold(&wlan.rssi_low_threshold);
3992 return;
3993 }
3994 #endif
3995
3996 #if CONFIG_11K
3997 if (network->neighbor_report_supported == true)
3998 {
3999 ret = wlan_host_11k_neighbor_req((const char *)network->ssid);
4000 if (ret == WM_SUCCESS)
4001 {
4002 wlcm_d("Sent 11K neighbor request");
4003 return;
4004 }
4005 set_rssi_threshold = true;
4006 }
4007 #endif /* CONFIG_11K */
4008
4009 #if CONFIG_11V
4010 if (network->bss_transition_supported == true)
4011 {
4012 ret = wlan_host_11v_bss_trans_query(0x10);
4013 if (ret == WM_SUCCESS)
4014 {
4015 wlcm_d("Sent 11V bss transition query");
4016 return;
4017 }
4018 set_rssi_threshold = true;
4019 }
4020 #endif /* CONFIG_11V */
4021
4022 if (wlan.roam_reassoc == false)
4023 {
4024 wlan.roam_reassoc = true;
4025 #if CONFIG_BG_SCAN
4026 ret = wifi_config_bgscan_and_rssi(network->ssid);
4027 if (ret == WM_SUCCESS)
4028 {
4029 wlcm_d("bgscan config successful");
4030 return;
4031 }
4032 #endif
4033 wlan.roam_reassoc = false;
4034 set_rssi_threshold = true;
4035 }
4036 else
4037 {
4038 wlcm_d("Roaming already in progress");
4039 set_rssi_threshold = true;
4040 }
4041
4042 if (set_rssi_threshold == true)
4043 {
4044 (void)wifi_set_rssi_low_threshold(&wlan.rssi_low_threshold);
4045 }
4046 #endif /* CONFIG_ROAMING */
4047 }
4048 #endif
4049 #endif
4050
4051 #if (CONFIG_11K) || (CONFIG_11V)
wlan_sort_nlist_channels(wlan_nlist_report_param * pnlist_rep_param)4052 static void wlan_sort_nlist_channels(wlan_nlist_report_param *pnlist_rep_param)
4053 {
4054 t_u8 i, j;
4055
4056 /* Bubble sort */
4057 for (i = 0; i < pnlist_rep_param->num_channels; i++)
4058 {
4059 for (j = 1; j < pnlist_rep_param->num_channels - i; j++)
4060 {
4061 if ((t_u8)pnlist_rep_param->channels[j - 1] > (t_u8)pnlist_rep_param->channels[j])
4062 {
4063 SWAP_U8(pnlist_rep_param->channels[j - 1], pnlist_rep_param->channels[j]);
4064 }
4065 }
4066 }
4067 }
4068
4069 #if CONFIG_WPA_SUPP
4070 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wlan_11k_roam()4071 int wlan_11k_roam()
4072 {
4073 int ret;
4074 struct wlan_network *network = &wlan.networks[wlan.cur_network_idx];
4075 wlan_nlist_report_param *pnlist_rep_param = (wlan_nlist_report_param *)&wlan.nlist_rep_param;
4076 t_u8 i;
4077 wlan_scan_params_v2_t params;
4078 struct netif *netif = net_get_sta_interface();
4079
4080 if (is_state(CM_STA_IDLE))
4081 {
4082 (void)PRINTF("Station is not connected\r\n");
4083 return -WM_FAIL;
4084 }
4085
4086 memset(¶ms, 0x00, sizeof(wlan_scan_params_v2_t));
4087
4088 memcpy(params.ssid, network->ssid, strlen(network->ssid));
4089 params.is_ssid = 1;
4090
4091 params.num_channels = pnlist_rep_param->num_channels;
4092
4093 for (i = 0; i < pnlist_rep_param->num_channels; i++)
4094 {
4095 params.chan_list[i].chan_number = (t_u8)pnlist_rep_param->channels[i];
4096 params.chan_list[i].scan_type = MLAN_SCAN_TYPE_ACTIVE;
4097 params.chan_list[i].scan_time = 60;
4098
4099 }
4100
4101 ret = wpa_supp_roam(netif, NULL);
4102 if (ret != WM_SUCCESS)
4103 {
4104 wlcm_e("wlan ft roam failed");
4105 return -WM_FAIL;
4106 }
4107
4108 ret = wpa_supp_scan(netif, ¶ms);
4109 if (ret != WM_SUCCESS)
4110 {
4111 wlcm_e("wlan ft roam scan failed");
4112 return -WM_FAIL;
4113 }
4114
4115 return WM_SUCCESS;
4116 }
4117 #endif
wlcm_process_neighbor_list_report_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4118 static void wlcm_process_neighbor_list_report_event(struct wifi_message *msg,
4119 enum cm_sta_state *next,
4120 struct wlan_network *network)
4121 {
4122 // unsigned int i;
4123 int ret = WM_SUCCESS;
4124 wlan_nlist_report_param *pnlist_rep_param = (wlan_nlist_report_param *)&wlan.nlist_rep_param;
4125
4126 if (is_state(CM_STA_IDLE) || (pnlist_rep_param == NULL))
4127 {
4128 wlcm_d("ignoring neighbor list report event in idle state");
4129 return;
4130 }
4131
4132 #if CONFIG_11K
4133 if (pnlist_rep_param->nlist_mode == WLAN_NLIST_11K)
4134 {
4135 wlan.neighbor_req = false;
4136 (void)OSA_TimerDeactivate((osa_timer_handle_t)wlan.neighbor_req_timer);
4137 }
4138 #endif
4139
4140 wlan_sort_nlist_channels(pnlist_rep_param);
4141 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
4142 ret = wlan_11k_roam();
4143 #endif
4144 if (ret != WM_SUCCESS)
4145 {
4146 wlcm_e("11k roam failed");
4147 }
4148
4149 memset(&wlan.nlist_rep_param, 0x00, sizeof(wlan_nlist_report_param));
4150 }
4151 #else
wlcm_process_neighbor_list_report_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4152 static void wlcm_process_neighbor_list_report_event(struct wifi_message *msg,
4153 enum cm_sta_state *next,
4154 struct wlan_network *network)
4155 {
4156 unsigned int i;
4157 int ret;
4158 wlan_scan_channel_list_t chan_list[MAX_NUM_CHANS_IN_NBOR_RPT];
4159 t_u8 *bssid = NULL;
4160 wlan_nlist_report_param *pnlist_rep_param = (wlan_nlist_report_param *)msg->data;
4161
4162 wlan.roam_reassoc = false;
4163
4164 if (is_state(CM_STA_IDLE) || (pnlist_rep_param == NULL))
4165 {
4166 wlcm_d("ignoring neighbor list report event in idle state");
4167 return;
4168 }
4169
4170 #if CONFIG_11K
4171 if (pnlist_rep_param->nlist_mode == WLAN_NLIST_11K)
4172 {
4173 wlan.neighbor_req = false;
4174 (void)OSA_TimerDeactivate((osa_timer_handle_t)wlan.neighbor_req_timer);
4175 }
4176 #endif
4177
4178 #if CONFIG_11V
4179 if ((pnlist_rep_param->nlist_mode == WLAN_NLIST_11V) || (pnlist_rep_param->nlist_mode == WLAN_NLIST_11V_PREFERRED))
4180 {
4181 wlan.neighbor_req = false;
4182 (void)OSA_TimerDeactivate((osa_timer_handle_t)wlan.neighbor_req_timer);
4183 }
4184 #endif
4185
4186 wlan_sort_nlist_channels(pnlist_rep_param);
4187 memcpy(&wlan.nlist_rep_param, pnlist_rep_param, sizeof(wlan_nlist_report_param));
4188
4189 #if CONFIG_11V
4190 if (pnlist_rep_param->nlist_mode == WLAN_NLIST_11V_PREFERRED)
4191 {
4192 bssid = pnlist_rep_param->bssid;
4193 }
4194 #endif
4195
4196 for (i = 0; i < pnlist_rep_param->num_channels; i++)
4197 {
4198 chan_list[i].chan_number = (t_u8)pnlist_rep_param->channels[i];
4199 chan_list[i].scan_type = MLAN_SCAN_TYPE_ACTIVE;
4200 chan_list[i].scan_time = 60;
4201 }
4202
4203 #if CONFIG_11R
4204 wlan.ft_bss = false;
4205 if ((network->ft_psk | network->ft_1x | network->ft_sae) == 1U)
4206 {
4207 wlan.ft_bss = true;
4208 }
4209 #endif
4210 wlan.roam_reassoc = true;
4211 ret = wifi_send_scan_cmd((t_u8)BSS_INFRASTRUCTURE, bssid, network->ssid, 1, pnlist_rep_param->num_channels,
4212 chan_list, 0,
4213 #if CONFIG_SCAN_WITH_RSSIFILTER
4214 0,
4215 #endif
4216 #if CONFIG_SCAN_CHANNEL_GAP
4217 scan_channel_gap,
4218 #endif
4219 false, false);
4220 if (ret != WM_SUCCESS)
4221 {
4222 wlcm_e("neighbor list scan failed");
4223 #if CONFIG_11R
4224 wlan.ft_bss = false;
4225 #endif
4226 wlan.roam_reassoc = false;
4227 }
4228
4229 if (pnlist_rep_param != NULL)
4230 {
4231 #if !CONFIG_MEM_POOLS
4232 OSA_MemoryFree((void *)pnlist_rep_param);
4233 #else
4234 OSA_MemoryPoolFree(buf_128_MemoryPool, pnlist_rep_param);
4235 #endif
4236 }
4237 }
4238 #endif
4239 #endif
4240
4241 #if CONFIG_11R
4242 #if CONFIG_WPA_SUPP
4243 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wlan_ft_roam(const t_u8 * bssid,const t_u8 channel)4244 int wlan_ft_roam(const t_u8 *bssid, const t_u8 channel)
4245 {
4246 int ret;
4247 wlan_scan_params_v2_t params;
4248 t_u8 curr_bss[MLAN_MAC_ADDR_LENGTH] = {0};
4249
4250 struct netif *netif = net_get_sta_interface();
4251
4252 if (is_state(CM_STA_IDLE))
4253 {
4254 (void)PRINTF("Station is not connected\r\n");
4255 return -WM_FAIL;
4256 }
4257 if (wlan.roam_reassoc == true)
4258 {
4259 (void)PRINTF("Roaming already in progress\r\n");
4260 return WM_SUCCESS;
4261 }
4262
4263 wlan.roam_reassoc = false;
4264
4265 memset(¶ms, 0x00, sizeof(wlan_scan_params_v2_t));
4266
4267 if (bssid)
4268 {
4269 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED)))
4270 {
4271 memcpy(curr_bss, wlan.networks[wlan.cur_network_idx].bssid, MLAN_MAC_ADDR_LENGTH);
4272 if(memcmp(curr_bss, bssid, MLAN_MAC_ADDR_LENGTH) == 0)
4273 {
4274 (void)PRINTF("Already connected to this BSS. Skip roaming.\r\n");
4275 return WM_SUCCESS;
4276 }
4277 }
4278 memcpy(params.bssid, bssid, MLAN_MAC_ADDR_LENGTH);
4279 params.is_bssid = 1;
4280 }
4281
4282 if (channel)
4283 {
4284 params.num_channels = 1;
4285 params.chan_list[0].chan_number = channel;
4286 }
4287
4288 ret = wpa_supp_roam(netif, (t_u8 *)bssid);
4289 if (ret != WM_SUCCESS)
4290 {
4291 wlcm_d("wlan ft roam failed");
4292 return -WM_FAIL;
4293 }
4294
4295 ret = wpa_supp_scan(netif, ¶ms);
4296 if (ret != WM_SUCCESS)
4297 {
4298 wlcm_d("wlan ft roam scan failed");
4299 return -WM_FAIL;
4300 }
4301
4302 wlan.roam_reassoc = true;
4303
4304 (void)OSA_TimerActivate((osa_timer_handle_t)wlan.ft_roam_timer);
4305
4306 (void)PRINTF("Started FT Roaming...\r\n");
4307
4308 return WM_SUCCESS;
4309 }
4310 #endif
4311 #else
wlan_ft_roam(const t_u8 * bssid,const t_u8 channel)4312 int wlan_ft_roam(const t_u8 *bssid, const t_u8 channel)
4313 {
4314 struct wlan_network *network = &wlan.networks[wlan.cur_network_idx];
4315
4316 if (is_state(CM_STA_IDLE))
4317 {
4318 (void)PRINTF("Station is not connected\r\n");
4319 return -WM_FAIL;
4320 }
4321
4322 if ((network->ft_psk | network->ft_1x | network->ft_sae) == 1U)
4323 {
4324 int ret;
4325 wlan_scan_channel_list_t chan_list;
4326
4327 chan_list.chan_number = channel;
4328 chan_list.scan_type = MLAN_SCAN_TYPE_ACTIVE;
4329 chan_list.scan_time = 120;
4330
4331 wlan.ft_bss = true;
4332 wlan.roam_reassoc = true;
4333 ret = wifi_send_scan_cmd((t_u8)BSS_INFRASTRUCTURE, bssid, network->ssid, 1, 1, &chan_list, 0,
4334 #if CONFIG_SCAN_WITH_RSSIFILTER
4335 0,
4336 #endif
4337 #if CONFIG_SCAN_CHANNEL_GAP
4338 scan_channel_gap,
4339 #endif
4340 false, false);
4341 if (ret != WM_SUCCESS)
4342 {
4343 wlcm_e("wlan ft roam scan failed");
4344 wlan.ft_bss = false;
4345 wlan.roam_reassoc = false;
4346 return -WM_FAIL;
4347 }
4348
4349 return WM_SUCCESS;
4350 }
4351 else
4352 {
4353 (void)PRINTF("Current associated AP do not support FT BSS transition\r\n");
4354 }
4355
4356 return -WM_FAIL;
4357 }
4358 #endif
4359 #endif
4360
4361 #if CONFIG_ECSA
wlan_check_valid_channel_operclass(t_u8 channel,t_u8 oper_class)4362 static int wlan_check_valid_channel_operclass(t_u8 channel, t_u8 oper_class)
4363 {
4364 int ret = 0;
4365 mlan_ioctl_req req;
4366 mlan_ds_misc_cfg *misc = NULL;
4367 mlan_status status = MLAN_STATUS_SUCCESS;
4368
4369 (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
4370
4371 misc = OSA_MemoryAllocate(sizeof(mlan_ds_misc_cfg));
4372 if (misc == NULL)
4373 {
4374 return -WM_FAIL;
4375 }
4376
4377 req.bss_index = MLAN_BSS_ROLE_UAP;
4378 req.pbuf = (t_u8 *)misc;
4379 misc->sub_command = MLAN_OID_MISC_OPER_CLASS_CHECK;
4380 req.req_id = MLAN_IOCTL_MISC_CFG;
4381 req.action = MLAN_ACT_GET;
4382 misc->param.bw_chan_oper.oper_class = oper_class;
4383 misc->param.bw_chan_oper.channel = channel;
4384
4385 status = wlan_ops_uap_ioctl(mlan_adap, &req);
4386 if (status != MLAN_STATUS_SUCCESS)
4387 {
4388 PRINTM(MERROR, "Failed to get operclass\n");
4389 OSA_MemoryFree(misc);
4390 return -WM_FAIL;
4391 }
4392
4393 OSA_MemoryFree(misc);
4394
4395 return ret;
4396 }
4397
wlan_set_uap_ecsa_cfg(t_u8 block_tx,t_u8 oper_class,t_u8 channel,t_u8 switch_count,t_u8 band_width,t_u8 ecsa)4398 static int wlan_set_uap_ecsa_cfg(
4399 t_u8 block_tx, t_u8 oper_class, t_u8 channel, t_u8 switch_count, t_u8 band_width, t_u8 ecsa)
4400 {
4401 mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[1];
4402 bool block_tx_flag = (1 == block_tx) ? true : false;
4403
4404 if (wlan_11h_radar_detect_required(pmpriv, channel))
4405 {
4406 wlcm_e("Please set non-dfs channel");
4407 return -WM_FAIL;
4408 }
4409
4410 if ((channel > MAX_CHANNELS_BG) && ISSUPP_NO5G(mlan_adap->fw_cap_ext))
4411 {
4412 wlcm_e("Not support 5G, please set 2G channel");
4413 return -WM_FAIL;
4414 }
4415
4416 if (wlan_check_channel_by_region_table(pmpriv, channel) == MFALSE)
4417 {
4418 (void)PRINTF("uAP target channel not allowed\n\r");
4419 return -WM_FAIL;
4420 }
4421
4422 if (is_uap_started() && (!is_sta_connected()))
4423 {
4424 if (oper_class)
4425 {
4426 if (wlan_check_valid_channel_operclass(channel, oper_class))
4427 {
4428 wlcm_e("Wrong channel switch parameters!");
4429 return -EINVAL;
4430 }
4431 }
4432
4433 set_ecsa_block_tx_flag(block_tx_flag);
4434
4435 if (0 != switch_count)
4436 {
4437 set_ecsa_block_tx_time(switch_count);
4438 return wifi_set_ecsa_cfg(block_tx, oper_class, channel, switch_count, band_width, ecsa);
4439 }
4440 else
4441 {
4442 return wifi_set_action_ecsa_cfg(block_tx, oper_class, channel, switch_count);
4443 }
4444 }
4445 else
4446 {
4447 wlcm_e("uap isn't up");
4448 return -WM_FAIL;
4449 }
4450 }
4451
wlan_switch_to_nondfs_channel(void)4452 static void wlan_switch_to_nondfs_channel(void)
4453 {
4454 mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[1];
4455 t_u8 uap_channel = 0;
4456 t_u8 block_tx = 1;
4457 t_u8 oper_class = 0;
4458 t_u8 switch_count = DEF_SWITCH_COUNT;
4459 t_u8 band_width = 0;
4460 t_u8 ecsa = MTRUE;
4461
4462 if (is_uap_started())
4463 {
4464 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
4465 uap_channel = mlan_adap->priv[1]->uap_channel;
4466 #else
4467 uap_channel = (t_u8)wlan.networks[wlan.cur_uap_network_idx].channel;
4468 #endif
4469
4470 if (MTRUE == wlan_11h_radar_detect_required(pmpriv, uap_channel))
4471 {
4472 if (MLAN_STATUS_SUCCESS == wlan_get_non_dfs_chan(pmpriv, &uap_channel))
4473 {
4474 wlan_set_uap_ecsa_cfg(block_tx, oper_class, uap_channel, switch_count, band_width, ecsa);
4475 }
4476 else
4477 {
4478 return;
4479 }
4480 }
4481 }
4482 }
4483 #endif
4484
4485 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wlcm_process_link_loss_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4486 static void wlcm_process_link_loss_event(struct wifi_message *msg,
4487 enum cm_sta_state *next,
4488 struct wlan_network *network)
4489 {
4490 /* We're being informed about an asynchronous link loss (ex: beacon loss
4491 * counter detected that the AP is gone, security failure, etc). If we
4492 * were connected, we need to report this event and proceed to idle.
4493 * If we were in the middle of a connection attempt, we need to treat
4494 * this as a connection attempt failure via do_connect_fail() and
4495 * proceed accordingly.
4496 */
4497 #if CONFIG_WMSTATS
4498 g_wm_stats.wm_lloss++;
4499 #endif /* CONFIG_WMSTATS */
4500 if (is_state(CM_STA_IDLE))
4501 {
4502 wlcm_d("ignoring link loss event in idle state");
4503 return;
4504 }
4505
4506 void *if_handle = NULL;
4507 /* On Link loss, we need to take down the interface. */
4508 if (network->type == WLAN_BSS_TYPE_STA)
4509 {
4510 if_handle = net_get_mlan_handle();
4511 }
4512
4513 if (if_handle != NULL)
4514 {
4515 /* Forcefully stop dhcp on given interface.
4516 * net_interface_dhcp_stop internally does nothing
4517 * if dhcp client is not started.
4518 */
4519 net_interface_dhcp_stop(if_handle);
4520 net_interface_down(if_handle);
4521 }
4522
4523 /* If we were connected and lost the link, we must report that now and
4524 * return to CM_STA_IDLE
4525 */
4526 if (is_state(CM_STA_CONNECTED))
4527 {
4528 if (is_user_scanning() != 0)
4529 {
4530 wlan.sta_return_to = CM_STA_IDLE;
4531 }
4532 else
4533 {
4534 *next = CM_STA_IDLE;
4535 }
4536 wlan.sta_state = CM_STA_IDLE;
4537 wlan.sta_ipv4_state = CM_STA_IDLE;
4538 #if CONFIG_IPV6
4539 wlan.sta_ipv6_state = CM_STA_IDLE;
4540 #endif
4541 if ((int)msg->data == IEEEtypes_REASON_MIC_FAILURE)
4542 {
4543 /* In case of a LINK loss because of bad MIC
4544 * failure, directly send a deauth.
4545 */
4546 wlcm_d(
4547 "Sending deauth because of"
4548 " successive bad MIC failures");
4549 (void)wlan_disconnect();
4550 *next = CM_STA_IDLE;
4551 }
4552
4553 CONNECTION_EVENT(WLAN_REASON_LINK_LOST, NULL);
4554 #if CONFIG_ECSA
4555 wrapper_clear_media_connected_event();
4556 wlan_switch_to_nondfs_channel();
4557 #endif
4558 }
4559 else
4560 {
4561 /* Stop the dhcp timer first after link lost occurs, as the dhcp timer
4562 * callback may lead to that the connection state is out-of-sync with FW */
4563 net_stop_dhcp_timer();
4564
4565 /* we were attempting a connection and lost the link,
4566 * so treat this as a connection attempt failure
4567 */
4568 switch ((int)msg->data)
4569 {
4570 case IEEEtypes_REASON_4WAY_HANDSHK_TIMEOUT:
4571 do_connect_failed(WLAN_REASON_NETWORK_AUTH_FAILED);
4572 break;
4573 default:
4574 do_connect_failed(WLAN_REASON_NETWORK_AUTH_FAILED);
4575 break;
4576 }
4577 *next = wlan.sta_state;
4578 }
4579 #if CONFIG_WPA2_ENTP
4580 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
4581 {
4582 wpa2_tls_cleanup(network, false);
4583 }
4584 #endif
4585 #if CONFIG_P2P
4586 wifi_wfd_event(false, false, NULL);
4587 #endif
4588
4589 #if !CONFIG_WPA_SUPP
4590 if (wlan.reassoc_control)
4591 {
4592 wlcm_request_reconnect(next, network);
4593 }
4594 #endif
4595 }
4596 #endif
4597
4598 #if CONFIG_WLAN_BRIDGE
wlcm_process_network_switch_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4599 static void wlcm_process_network_switch_event(struct wifi_message *msg,
4600 enum cm_sta_state *next,
4601 struct wlan_network *network)
4602 {
4603 Event_AutoLink_SW_Node_t *pnewNode = (Event_AutoLink_SW_Node_t *)msg->data;
4604
4605 char *p = OSA_MemoryAllocate(pnewNode->len_ssid + 1);
4606
4607 /*print new network info*/
4608 (void)PRINTF("\r\nBssid=");
4609 extern void print_mac(const char *mac);
4610 print_mac((char *)pnewNode->peer_mac_addr);
4611 if (p)
4612 {
4613 (void)memcpy((void *)p, (const void *)pnewNode->ssid, pnewNode->len_ssid);
4614 (void)PRINTF("\r\nSsid=%s\r\n", p);
4615 OSA_MemoryFree(p);
4616 }
4617 (void)PRINTF("channel=%d,chanBand=%d,chanWidth=%d,chan2Offset=%d,scanMode=%d", pnewNode->chanBand.chanNum,
4618 pnewNode->chanBand.bandConfig.chanBand, pnewNode->chanBand.bandConfig.chanWidth,
4619 pnewNode->chanBand.bandConfig.chan2Offset, pnewNode->chanBand.bandConfig.scanMode);
4620 (void)PRINTF("\r\nSecurityType=%d", pnewNode->secutype);
4621 (void)PRINTF("\r\nmcstCipher=%d", pnewNode->mcstcipher);
4622 (void)PRINTF("\r\nucstCipher=%d\r\n", pnewNode->ucstcipher);
4623
4624 OSA_MemoryFree(msg->data);
4625 }
4626 #endif
4627
wlcm_process_disassoc_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4628 static void wlcm_process_disassoc_event(struct wifi_message *msg, enum cm_sta_state *next, struct wlan_network *network)
4629 {
4630 /* We're being informed about an asynchronous disassociation from AP
4631 * As were in the middle of a connection attempt, we need to treat
4632 * this as a connection attempt failure via do_connect_fail() and
4633 * proceed accordingly.
4634 */
4635 #if CONFIG_WPA2_ENTP
4636 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
4637 {
4638 wpa2_tls_cleanup(network, false);
4639 }
4640 else if (wlan_get_prov_session() == PROV_NON_SESSION_ATTEMPT && is_state(CM_STA_CONNECTED) &&
4641 network->security.pmk_valid == true &&
4642 (network->security.type == WLAN_SECURITY_EAP_TLS || network->security.type == WLAN_SECURITY_EAP_PEAP_MSCHAPV2)
4643 )
4644 {
4645 /* Connects with security EAP_TLS, if AP reset PMK and send disassoc, STA clear pmk_valid/pmk and enter "PROV_ENTP_SESSION_ATTEMPT" again */
4646 network->security.pmk_valid = false;
4647 memset(network->security.pmk, 0, WLAN_PMK_LENGTH);
4648 }
4649 #endif
4650 #if CONFIG_P2P
4651 wifi_wfd_event(false, false, NULL);
4652 #endif
4653 if (is_user_scanning() != 0)
4654 {
4655 wlan.sta_return_to = CM_STA_IDLE;
4656 }
4657 *next = CM_STA_IDLE;
4658 wlan.sta_state = CM_STA_IDLE;
4659
4660 do_connect_failed(WLAN_REASON_NETWORK_AUTH_FAILED);
4661
4662 if (wlan.reassoc_control)
4663 {
4664 wlcm_request_reconnect(next, network);
4665 }
4666 }
4667
wlcm_process_deauthentication_event(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4668 static void wlcm_process_deauthentication_event(struct wifi_message *msg,
4669 enum cm_sta_state *next,
4670 struct wlan_network *network)
4671 {
4672 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
4673 struct netif *netif = net_get_sta_interface();
4674 struct wifi_connect_req_params params = {0};
4675
4676 supplicant_get_wifi_conn_params(net_if_get_device((void *)netif), ¶ms);
4677 #endif
4678
4679 #if CONFIG_WPA2_ENTP
4680 if (wlan_get_prov_session() == PROV_ENTP_SESSION_ATTEMPT)
4681 {
4682 wpa2_tls_cleanup(network, false);
4683 }
4684 #endif
4685 #if CONFIG_P2P
4686 wifi_wfd_event(false, false, NULL);
4687 #endif
4688 #if CONFIG_WPA_SUPP
4689 if (
4690 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
4691 (params.security == WIFI_SECURITY_TYPE_SAE)
4692 #else
4693 (network->security.type == WLAN_SECURITY_WPA3_SAE ||
4694 network->security.type == WLAN_SECURITY_WPA3_SAE_EXT_KEY)
4695 #endif
4696 && (msg->reason == WLAN_REASON_PREV_AUTH_NOT_VALID ||
4697 msg->reason == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4698 msg->reason == WLAN_REASON_INVALID_IE))
4699 {
4700 /*
4701 * Clear pmksa cache in case AP wants to redo sae auth.
4702 * But send successful assoc resp and send deauth right after.
4703 * Then we will always using pmksa cache if it exists.
4704 */
4705 wlan_pmksa_flush();
4706 }
4707
4708 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
4709 wlan_handle_disconnect_event(mlan_adap->priv[0]);
4710
4711 if(is_uap_started())
4712 {
4713 while (is_sta_connected())
4714 OSA_TimeDelay(100);
4715 wlan_switch_to_nondfs_channel();
4716 }
4717 #endif
4718 #endif
4719 }
4720
wlcm_process_net_dhcp_config(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4721 static void wlcm_process_net_dhcp_config(struct wifi_message *msg,
4722 enum cm_sta_state *next,
4723 struct wlan_network *network)
4724 {
4725 /* We have received a response from the embedded DHCP client. If
4726 * successful, we now have a DHCP lease and can update our IP address
4727 * information and procceed to the CM_STA_CONNECTED state, otherwise we
4728 * failed to obtain a DHCP lease and report that we failed to connect.
4729 *
4730 * This event is only relevant if we are attempting a connection and
4731 * are in the CM_STA_OBTAINING_ADDRESS state (due to configuring the TCP
4732 * stack with DHCP), otherwise we ignore it. */
4733
4734 void *if_handle = NULL;
4735 // wakelock_put(WL_ID_CONNECT);
4736 // wlan.connect_wakelock_taken = false;
4737 if (wlan.sta_ipv4_state == CM_STA_OBTAINING_ADDRESS)
4738 {
4739 if (wlan.connect_wakelock_taken)
4740 {
4741 #if CONFIG_HOST_SLEEP
4742 wakelock_put();
4743 #endif
4744 wlan.connect_wakelock_taken = false;
4745 }
4746 if (msg->reason != WIFI_EVENT_REASON_SUCCESS)
4747 {
4748 #if CONFIG_WMSTATS
4749 g_wm_stats.wm_dhcp_fail++;
4750 #endif /* CONFIG_WMSTATS */
4751 wlcm_d("got event: DHCP failure");
4752 #if CONFIG_IPV6
4753 if (wlan.sta_ipv6_state != CM_STA_CONNECTED)
4754 {
4755 #endif
4756 #if CONFIG_WLAN_FAST_PATH
4757 /* Mark the fast path cache invalid. */
4758 wlan.auth_cache_valid = false;
4759 wlan.fast_path_cache_valid = false;
4760 #endif /* CONFIG_WLAN_FAST_PATH */
4761
4762 do_connect_failed(WLAN_REASON_ADDRESS_FAILED);
4763
4764 if (wlan.reassoc_control)
4765 {
4766 wlcm_request_reconnect(next, network);
4767 }
4768
4769 *next = wlan.sta_state;
4770 #if CONFIG_IPV6
4771 }
4772 else if (wlan.sta_ipv6_state == CM_STA_CONNECTED)
4773 {
4774 wlan.sta_state = CM_STA_CONNECTED;
4775 *next = CM_STA_CONNECTED;
4776 if (network->type == WLAN_BSS_TYPE_STA)
4777 {
4778 if_handle = net_get_mlan_handle();
4779 }
4780
4781 net_interface_up(if_handle);
4782 mlan_adap->skip_dfs = false;
4783 CONNECTION_EVENT(WLAN_REASON_SUCCESS, NULL);
4784 }
4785 else
4786 {
4787 /* Do Nothing */
4788 }
4789 #endif
4790 return;
4791 }
4792 char ip[16];
4793 #if CONFIG_WMSTATS
4794 g_wm_stats.wm_dhcp_succ++;
4795 #endif /* CONFIG_WMSTATS */
4796 wlcm_d("got event: DHCP success");
4797 net_stop_dhcp_timer();
4798 net_configure_dns((struct net_ip_config *)&network->ip, network->role);
4799 if (network->type == WLAN_BSS_TYPE_STA)
4800 {
4801 if_handle = net_get_mlan_handle();
4802 }
4803 #if CONFIG_P2P
4804 else if (network->type == WLAN_BSS_TYPE_WIFIDIRECT)
4805 if_handle = net_get_wfd_handle();
4806 #endif /* CONFIG_P2P */
4807 (void)net_get_if_addr((struct net_ip_config *)&network->ip, if_handle);
4808 // net_inet_ntoa(network->ip.ipv4.address, ip);
4809 wlan.sta_state = CM_STA_CONNECTED;
4810 *next = CM_STA_CONNECTED;
4811 wlan.sta_ipv4_state = CM_STA_CONNECTED;
4812
4813 #if CONFIG_WPS2
4814 wlan_set_prov_session(PROV_NON_SESSION_ATTEMPT);
4815 #endif
4816 if (wlan.reassoc_control && wlan.reassoc_request)
4817 {
4818 wlan.reassoc_count = 0;
4819 wlan.reassoc_request = false;
4820 }
4821 mlan_adap->skip_dfs = false;
4822 CONNECTION_EVENT(WLAN_REASON_SUCCESS, &ip);
4823
4824 #if CONFIG_P2P
4825 wifi_wfd_event(false, false, (void *)1);
4826 #endif
4827 }
4828 else
4829 {
4830 wlcm_d("got event from dhcp client %d", msg->reason);
4831 if (msg->reason != WIFI_EVENT_REASON_SUCCESS)
4832 {
4833 #if CONFIG_WMSTATS
4834 g_wm_stats.wm_leas_fail++;
4835 #endif /* CONFIG_WMSTATS */
4836 /* There was some problem with dhcp lease
4837 * renewal, so just disconnect from wlan.
4838 */
4839
4840 #if CONFIG_IPV6
4841 /* Do not disconnect-connect if the STA interface has
4842 * obtained IPv6 address */
4843 if (wlan.sta_ipv6_state != CM_STA_CONNECTED)
4844 {
4845 #endif
4846 if (wlan.sta_ipv4_state == CM_STA_CONNECTED)
4847 {
4848 wlcm_d("Lease renewal failed, disconnecting");
4849
4850 #if CONFIG_WLAN_FAST_PATH
4851 /* Mark the fast path cache invalid. */
4852 wlan.auth_cache_valid = false;
4853 wlan.fast_path_cache_valid = false;
4854 #endif /* CONFIG_WLAN_FAST_PATH */
4855
4856 do_connect_failed(WLAN_REASON_ADDRESS_FAILED);
4857
4858 if (wlan.reassoc_control)
4859 {
4860 wlcm_request_reconnect(next, network);
4861 }
4862
4863 *next = wlan.sta_state;
4864 }
4865 #if CONFIG_IPV6
4866 }
4867 #endif
4868 return;
4869 }
4870 #if CONFIG_WMSTATS
4871 g_wm_stats.wm_leas_succ++;
4872 #endif /* CONFIG_WMSTATS */
4873 /* Successful in getting ip address, so update
4874 * local wlan-info params */
4875 wlcm_d("update wlan-info params");
4876 if (network->type == WLAN_BSS_TYPE_STA)
4877 {
4878 if_handle = net_get_mlan_handle();
4879 }
4880 #if CONFIG_P2P
4881 else if (network->type == WLAN_BSS_TYPE_WIFIDIRECT)
4882 {
4883 if_handle = net_get_wfd_handle();
4884 }
4885 else
4886 {
4887 /*Do nothing*/
4888 }
4889 #endif /* CONFIG_P2P */
4890 (void)net_get_if_addr((struct net_ip_config *)&network->ip, if_handle);
4891 CONNECTION_EVENT(WLAN_REASON_ADDRESS_SUCCESS, NULL);
4892 }
4893 }
4894
4895 #if CONFIG_IPV6
wlcm_process_net_ipv6_config(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)4896 static void wlcm_process_net_ipv6_config(struct wifi_message *msg,
4897 enum cm_sta_state *next,
4898 struct wlan_network *network)
4899 {
4900 void *if_handle = net_get_mlan_handle();
4901 int i, found = 0;
4902 if (network->type != WLAN_BSS_TYPE_STA || (if_handle == NULL))
4903 {
4904 return;
4905 }
4906
4907 net_get_if_ipv6_addr((struct net_ip_config *)&network->ip, if_handle);
4908 for (i = 0; i < CONFIG_MAX_IPV6_ADDRESSES && i < network->ip.ipv6_count; i++)
4909 {
4910 if ((network->ip.ipv6[i].addr_state == NET_ADDR_TENTATIVE) ||
4911 (network->ip.ipv6[i].addr_state == NET_ADDR_PREFERRED))
4912 {
4913 found++;
4914 /* Not considering link-local address as of now */
4915 if (wlan.sta_ipv6_state != CM_STA_CONNECTED)
4916 {
4917 wlan.sta_ipv6_state = CM_STA_CONNECTED;
4918
4919 if (wlan.reassoc_control && wlan.reassoc_request)
4920 {
4921 wlan.reassoc_count = 0;
4922 wlan.reassoc_request = false;
4923 }
4924 }
4925 }
4926 }
4927
4928 if (wlan.sta_ipv6_state >= CM_STA_OBTAINING_ADDRESS && !found)
4929 {
4930 /* If the state is either obtaining address or connected and
4931 * if none of the IP addresses is preferred, then
4932 * change/maintain the state to obtaining address */
4933 wlan.sta_ipv6_state = CM_STA_OBTAINING_ADDRESS;
4934 }
4935 }
4936 #endif /* CONFIG_IPV6 */
4937
wlan_rx_mgmt_indication(const enum wlan_bss_type bss_type,const uint32_t mgmt_subtype_mask,int (* rx_mgmt_callback)(const enum wlan_bss_type bss_type,const wlan_mgmt_frame_t * frame,const size_t len))4938 int wlan_rx_mgmt_indication(const enum wlan_bss_type bss_type,
4939 const uint32_t mgmt_subtype_mask,
4940 int (*rx_mgmt_callback)(const enum wlan_bss_type bss_type,
4941 const wlan_mgmt_frame_t *frame,
4942 const size_t len))
4943 {
4944 #ifdef MGMT_RX
4945 if (mgmt_subtype_mask)
4946 rx_mgmt_register_callback(rx_mgmt_callback);
4947 else
4948 rx_mgmt_deregister_callback();
4949 #endif
4950
4951 return wifi_set_rx_mgmt_indication(bss_type, mgmt_subtype_mask);
4952 }
4953
4954 #if CONFIG_WPA_SUPP
4955 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wlcm_process_scan_failed()4956 static void wlcm_process_scan_failed()
4957 {
4958 if (wlan.pending_disconnect_request == true)
4959 {
4960 wlan_disconnect();
4961 }
4962 }
4963 #endif
4964 #define IEEEtypes_REASON_DEAUTH_LEAVING 3
4965 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wlcm_process_disconnected()4966 static void wlcm_process_disconnected()
4967 {
4968 (void)wifi_event_completion(WIFI_EVENT_LINK_LOSS, WIFI_EVENT_REASON_FAILURE, (void *)IEEEtypes_REASON_DEAUTH_LEAVING);
4969 }
4970 #endif
4971 #if CONFIG_11K
4972 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wlan_parse_neighbor_report_response(const char * nbr_response,wlan_rrm_neighbor_report_t * nbr_rpt)4973 static void wlan_parse_neighbor_report_response(const char *nbr_response, wlan_rrm_neighbor_report_t *nbr_rpt)
4974 {
4975 char event[32] = {0};
4976 char bssid[32] = {0};
4977 char info[32] = {0};
4978 int op_class,channel,phy_type;
4979
4980 if (!nbr_response || nbr_response[0] == '\0')
4981 {
4982 wlcm_e("11K: Neighbor response is NULL");
4983 return;
4984 }
4985 else if (!nbr_rpt)
4986 {
4987 wlcm_e("11K: Input Neighbor report is NULL");
4988 return;
4989 }
4990
4991 // Sample Response Pattern
4992 //<3>RRM-NEIGHBOR-REP-RECEIVED bssid=ec:aa:a0:81:7f:20 info=0x1801 op_class=0 chan=153 phy_type=1 lci=0100080010000000000000000000000000000000000406000000000000060101 civic=02000b0000ed000000
4993
4994 if (sscanf(nbr_response,"%s bssid=%s info=%s op_class=%d chan=%d phy_type=%d", event, bssid, info, &op_class, &channel, &phy_type) == 6)
4995 {
4996 int i;
4997 int match = 0;
4998 size_t len = 0;
4999
5000 // Check if the bssid is already present in list
5001
5002 for (i = 0; i < nbr_rpt->neighbor_cnt; i++)
5003 {
5004 if (strncmp((const char *)nbr_rpt->neighbor_ap[i].bssid, bssid, 32) == 0)
5005 {
5006 match = 1;
5007 break;
5008 }
5009
5010 if (nbr_rpt->neighbor_ap[i].channel == channel)
5011 {
5012 match = 1;
5013 break;
5014 }
5015 }
5016
5017 if (!match && (nbr_rpt->neighbor_cnt < MAX_NEIGHBOR_AP_LIMIT))
5018 {
5019 strncpy((char *)nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssid, bssid, sizeof(nbr_rpt->neighbor_ap->bssid));
5020 len = strlen(bssid);
5021 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssid[len] = (t_u8)'\0';
5022
5023 strncpy((char *)nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssidInfo, info, sizeof(nbr_rpt->neighbor_ap->bssidInfo));
5024 len = strlen(info);
5025 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssidInfo[len] = (t_u8)'\0';
5026
5027 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].channel = channel;
5028 wlan.nlist_rep_param.channels[wlan.nlist_rep_param.num_channels] = channel;
5029 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].op_class = op_class;
5030 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].phy_type = phy_type;
5031 //nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].freq = wifi_getRadioFrequencyFromChannel(channel);
5032
5033 wlcm_d("RRM Neighbor[%d] - Bssid = %s , Info = %s, op_class=%d, Channel = %d, Phy_Type = %d, Freq=%d ", nbr_rpt->neighbor_cnt, nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssid, nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssidInfo, nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].op_class, nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].channel,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].phy_type,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].freq);
5034
5035 nbr_rpt->neighbor_cnt += 1;
5036 wlan.nlist_rep_param.num_channels += 1;
5037
5038 wlan.nlist_rep_param.nlist_mode = WLAN_NLIST_11K;
5039 }
5040 else if (match)
5041 {
5042 wlcm_d("BSSID already present in neighbor list, Skipping %s ",bssid);
5043 }
5044 else
5045 {
5046 wlcm_d("Maximum neighbors added to list, Skipping.");
5047 }
5048 }
5049 else
5050 {
5051 wlcm_d("Failed to Parse Neighbor Report - Skipping entry\n");
5052 }
5053 }
5054 #endif
5055 #endif
5056
5057 #if CONFIG_WPA_SUPP
5058 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wlcm_process_add_unspecified_network(const char * name)5059 static int wlcm_process_add_unspecified_network(const char *name)
5060 {
5061 int ret, i;
5062 struct wlan_network *network;
5063 size_t len = 0;
5064 const char *ssid = "w";
5065
5066 network = OSA_MemoryAllocate(sizeof(struct wlan_network));
5067
5068 if (network == NULL)
5069 {
5070 wlcm_d("%s: Failed to alloc wlan_network network", __func__);
5071 return -WM_FAIL;
5072 }
5073
5074 (void)memset(network, 0, sizeof(struct wlan_network));
5075 (void)memcpy(network->name, name, strlen(name));
5076 len = strlen(name);
5077 network->name[len] = '\0';
5078 (void)memcpy(network->ssid, ssid, strlen(ssid));
5079
5080 network->ip.ipv4.addr_type = ADDR_TYPE_DHCP;
5081
5082 ret = wlan_add_network(network);
5083
5084 OSA_MemoryFree(network);
5085
5086 if (ret != WM_SUCCESS)
5087 {
5088 wlcm_e("Failed to add wps network");
5089 return ret;
5090 }
5091 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
5092 {
5093 if (wlan.networks[i].name[0] != '\0' && strlen(wlan.networks[i].name) == len &&
5094 !strncmp(wlan.networks[i].name, name, len))
5095 {
5096 wlan.cur_network_idx = i;
5097 break;
5098 }
5099 }
5100 return WM_SUCCESS;
5101 }
5102 #endif
5103 #endif
5104 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
wpa_supplicant_msg_cb(const char * buf,size_t len)5105 static void wpa_supplicant_msg_cb(const char *buf, size_t len)
5106 {
5107 const char *s;
5108 unsigned char is_11n_enabled;
5109 int ret;
5110 struct netif *netif = net_get_uap_interface();
5111 struct netif *sta_netif = net_get_sta_interface();
5112 struct wlan_network *network = &wlan.networks[wlan.cur_network_idx];
5113
5114 wlcm_d("%s: %s", __func__, buf);
5115
5116 if (strstr(buf, WPA_EVENT_SCAN_FAILED))
5117 {
5118 wlcm_process_scan_failed();
5119 }
5120 else if (strstr(buf, WPA_EVENT_DISCONNECTED))
5121 {
5122 wlcm_process_disconnected();
5123 wlan_handle_disconnect_event(mlan_adap->priv[0]);
5124 }
5125 else if (strstr(buf, WPA_EVENT_NETWORK_NOT_FOUND))
5126 {
5127 wlcm_d("No suitable network was found");
5128
5129 if (wlan.roam_reassoc == true)
5130 {
5131 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_ROAMING)
5132 (void)wifi_set_rssi_low_threshold(&wlan.rssi_low_threshold);
5133 wlan.roam_reassoc = false;
5134 #endif
5135 }
5136 else
5137 {
5138 wlan.scan_count++;
5139
5140 do_connect_failed(WLAN_REASON_NETWORK_NOT_FOUND);
5141
5142 if (wlan.scan_count > WLAN_RESCAN_LIMIT)
5143 {
5144 wlan.cur_network_idx = -1;
5145 (void)wpa_supp_disable(sta_netif, network);
5146 }
5147 }
5148 }
5149 else if (strstr(buf, WPA_EVENT_AUTH_REJECT))
5150 {
5151 wlcm_d("Authentication rejected during connection attempt");
5152 if ((wlan.roam_reassoc != true) && (!(strlen(buf) > strlen(WPA_EVENT_AUTH_REJECT))))
5153 {
5154 (void)send_user_request(CM_STA_USER_REQUEST_CONNECT, wlan.cur_network_idx);
5155 }
5156 wlan.roam_reassoc = false;
5157 }
5158 #if CONFIG_WPA_SUPP_AP
5159 else if (strstr(buf, AP_STA_CONNECTED))
5160 {
5161 wlcm_d("AP: Station connected");
5162 t_u8 addr[MLAN_MAC_ADDR_LENGTH];
5163
5164 s = strchr(buf, ' ');
5165 if (s == NULL)
5166 return;
5167
5168 if (hwaddr_aton(s + 1, addr))
5169 return;
5170
5171 ret = wpa_supp_get_sta_info(netif, addr, &is_11n_enabled);
5172 if (ret != 0)
5173 return;
5174
5175 wifi_uap_client_assoc(addr, is_11n_enabled);
5176
5177 CONNECTION_EVENT(WLAN_REASON_UAP_CLIENT_CONN, addr);
5178 }
5179 if (strstr(buf, AP_STA_DISCONNECTED))
5180 {
5181 wlcm_d("AP: Station dis-connected");
5182
5183 wifi_uap_client_disassoc_t disassoc_resp;
5184
5185 disassoc_resp.reason_code = 0;
5186
5187 s = strchr(buf, ' ');
5188 if (s == NULL)
5189 return;
5190
5191 if (hwaddr_aton(s + 1, disassoc_resp.sta_addr))
5192 return;
5193
5194 wifi_uap_client_deauth(disassoc_resp.sta_addr);
5195
5196 CONNECTION_EVENT(WLAN_REASON_UAP_CLIENT_DISSOC, (void *)&disassoc_resp);
5197 }
5198 #endif
5199 #if CONFIG_WPA_SUPP_WPS
5200 else if (strstr(buf, WPS_EVENT_OVERLAP))
5201 {
5202 wlcm_d("WPS overlap detected in PBC mode");
5203 }
5204 else if (strstr(buf, WPS_EVENT_AP_AVAILABLE_PBC))
5205 {
5206 wlcm_d("Available WPS AP with active PBC found in scan results");
5207 }
5208 else if (strstr(buf, WPS_EVENT_AP_AVAILABLE_PIN))
5209 {
5210 wlcm_d("Available WPS AP with recently selected PIN registrar found in scan results");
5211 }
5212 else if (strstr(buf, WPS_EVENT_AP_AVAILABLE))
5213 {
5214 wlcm_d("Available WPS AP found in scan results");
5215 }
5216 else if (strstr(buf, WPS_EVENT_CRED_RECEIVED))
5217 {
5218 wlcm_d("A new credential received");
5219 }
5220 else if (strstr(buf, WPS_EVENT_DISABLE))
5221 {
5222 wlcm_d("PBC mode was disabled");
5223 wlan.wps_session_attempt = 0;
5224 }
5225 else if (strstr(buf, WPS_EVENT_ACTIVE))
5226 {
5227 wlcm_d("PBC mode was activated");
5228 wlan.wps_session_attempt = 1;
5229 }
5230 else if (strstr(buf, WPS_EVENT_PIN_ACTIVE))
5231 {
5232 wlcm_d("PIN mode was activated");
5233 wlan.wps_session_attempt = 1;
5234 }
5235 else if (strstr(buf, WPS_EVENT_TIMEOUT))
5236 {
5237 wlcm_d("WPS enrollment attempt timed out and was terminated");
5238 wlan.wps_session_attempt = 0;
5239 }
5240 else if (strstr(buf, WPS_EVENT_FAIL))
5241 {
5242 wlcm_d("WPS registration failed after M2/M2D");
5243 wlan.wps_session_attempt = 0;
5244 }
5245 else if (strstr(buf, WPS_EVENT_SUCCESS))
5246 {
5247 wlcm_d("WPS registration completed successfully");
5248 if (wlan.wps_session_attempt)
5249 {
5250 if (wlcm_process_add_unspecified_network("wps_network") == WM_SUCCESS)
5251 {
5252 wlan.wps_session_attempt = 0;
5253 }
5254 }
5255 }
5256 else
5257 #endif
5258 #if CONFIG_11K
5259 if (strstr(buf, RRM_EVENT_NEIGHBOR_REP_RXED))
5260 {
5261 wlcm_d("11K RRM event neighbor response received");
5262 wlan_parse_neighbor_report_response(buf, &wlan.nbr_rpt);
5263 }
5264 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
5265 else if (strstr(buf, RRM_EVENT_NEIGHBOR_REP_COMPLETED))
5266 {
5267 if (wlan.nbr_rpt.neighbor_cnt != 0U)
5268 {
5269 memset(&wlan.nbr_rpt, 0x00, sizeof(wlan_rrm_neighbor_report_t));
5270 (void)wifi_event_completion(WIFI_EVENT_NLIST_REPORT, WIFI_EVENT_REASON_SUCCESS, NULL);
5271 }
5272 }
5273 #endif
5274 else if (strstr(buf, RRM_EVENT_NEIGHBOR_REP_FAILED))
5275 {
5276 wlcm_d("11K RRM event neighbor report request failed");
5277 }
5278 else
5279 #endif
5280 #if CONFIG_WPA_SUPP_DPP
5281 if (strstr(buf, DPP_EVENT_CONF_RECEIVED))
5282 {
5283 if (!is_uap_started())
5284 {
5285 wlcm_d("DPP starts to new a network profile");
5286 (void)wlcm_process_add_unspecified_network("dpp_network");
5287 }
5288 }
5289 else if (strstr(buf, DPP_EVENT_CONFOBJ_AKM))
5290 {
5291 unsigned int network_idx = -1;
5292
5293 if (is_uap_started())
5294 {
5295 network_idx = wlan.cur_uap_network_idx;
5296 }
5297 else
5298 {
5299 network_idx = wlan.cur_network_idx;
5300 }
5301 /* Only for STA associate */
5302 mlan_adap->priv[0]->is_dpp_connect = MTRUE;
5303 if (network_idx < WLAN_MAX_KNOWN_NETWORKS)
5304 {
5305 struct wlan_network_security *security = &(wlan.networks[network_idx].security);
5306 const char *pos = buf + sizeof(DPP_EVENT_CONFOBJ_AKM) - 1;
5307 security->pmk_valid = false;
5308 security->type = WLAN_SECURITY_NONE;
5309 if (memcmp("psk", pos, strlen("psk")) == 0)
5310 {
5311 security->type = WLAN_SECURITY_WPA2;
5312 security->key_mgmt = WLAN_KEY_MGMT_PSK;
5313 }
5314 else if (memcmp("sae", pos, strlen("sae")) == 0)
5315 {
5316 security->type = WLAN_SECURITY_WPA3_SAE;
5317 security->key_mgmt = WLAN_KEY_MGMT_SAE;
5318 }
5319 else if ((memcmp("psk-sae", pos, strlen("psk-sae")) == 0) ||
5320 (memcmp("psk+sae", pos, strlen("psk+sae")) == 0))
5321 {
5322 security->type = WLAN_SECURITY_WPA2_WPA3_SAE_MIXED;
5323 security->key_mgmt = WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_SAE;
5324 }
5325 else if ((memcmp("sae-dpp", pos, strlen("sae-dpp")) == 0) ||
5326 (memcmp("dpp+sae", pos, strlen("dpp+sae")) == 0))
5327 {
5328 security->type = WLAN_SECURITY_WPA3_SAE;
5329 security->key_mgmt = WLAN_KEY_MGMT_DPP | WLAN_KEY_MGMT_SAE;
5330 }
5331 else if ((memcmp("psk-sae-dpp", pos, strlen("psk-sae-dpp")) == 0) ||
5332 (memcmp("dpp+psk+sae", pos, strlen("dpp+psk+sae")) == 0))
5333 {
5334 security->type = WLAN_SECURITY_WPA2_WPA3_SAE_MIXED;
5335 security->key_mgmt = WLAN_KEY_MGMT_DPP | WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_SAE;
5336 }
5337 else if (memcmp("dpp", pos, strlen("dpp")) == 0)
5338 {
5339 security->type = WLAN_SECURITY_DPP;
5340 security->key_mgmt = WLAN_KEY_MGMT_DPP;
5341 }
5342 else if (memcmp("dot1x", pos, strlen("dot1x")) == 0)
5343 {
5344 #if CONFIG_EAP_TLS
5345 security->type = WLAN_SECURITY_EAP_TLS_SHA256;
5346 #endif
5347 security->key_mgmt = WLAN_KEY_MGMT_IEEE8021X;
5348 }
5349 else
5350 {
5351 wlcm_e("DPP AKM type(%s) unknown!", pos);
5352 return ;
5353 }
5354 security->pairwise_cipher = 0x10; /* CCMP */
5355 security->mfpc = 1;
5356 security->mfpr = 1;
5357 wlan_set_pmfcfg(security->mfpc, security->mfpr);
5358 }
5359 }
5360 else if (strstr(buf, DPP_EVENT_CONFOBJ_SSID))
5361 {
5362 unsigned int network_idx = -1;
5363
5364 if (is_uap_started())
5365 {
5366 network_idx = wlan.cur_uap_network_idx;
5367 }
5368 else
5369 {
5370 network_idx = wlan.cur_network_idx;
5371 }
5372 if (network_idx < WLAN_MAX_KNOWN_NETWORKS)
5373 {
5374 const char *pos = buf + sizeof(DPP_EVENT_CONFOBJ_SSID) - 1;
5375 if (strlen(pos) < IEEEtypes_SSID_SIZE)
5376 {
5377 (void)memcpy(wlan.networks[network_idx].ssid, pos, strlen(pos));
5378 }
5379 }
5380 }
5381 else if (strstr(buf, DPP_EVENT_CONFOBJ_PASS))
5382 {
5383 unsigned int network_idx = -1;
5384
5385 if (is_uap_started())
5386 {
5387 network_idx = wlan.cur_uap_network_idx;
5388 }
5389 else
5390 {
5391 network_idx = wlan.cur_network_idx;
5392 }
5393 if (network_idx < WLAN_MAX_KNOWN_NETWORKS)
5394 {
5395 char psk[WLAN_PSK_MAX_LENGTH];
5396 unsigned int hex_len = 0;
5397 struct wlan_network_security *security = &(wlan.networks[network_idx].security);
5398 const char *pos = buf + sizeof(DPP_EVENT_CONFOBJ_PASS) - 1;
5399
5400 hex_len = strlen(pos);
5401 if (hex_len <= (WLAN_PSK_MAX_LENGTH * 2))
5402 {
5403 memset(psk, 0, sizeof(psk));
5404 hexstr2bin(pos, (unsigned char *)psk, hex_len/2);
5405 security->psk_len = strlen(psk);
5406 (void)strcpy(security->psk, psk);
5407 security->password_len = strlen(psk);
5408 (void)strcpy(security->password, psk);
5409 }
5410 }
5411 }
5412 else if (strstr(buf, DPP_EVENT_CONFOBJ_PSK))
5413 {
5414 unsigned int network_idx = -1;
5415
5416 if (is_uap_started())
5417 {
5418 network_idx = wlan.cur_uap_network_idx;
5419 }
5420 else
5421 {
5422 network_idx = wlan.cur_network_idx;
5423 }
5424 if (network_idx < WLAN_MAX_KNOWN_NETWORKS)
5425 {
5426 char pmk[WLAN_PMK_LENGTH];
5427 unsigned int hex_len = 0;
5428 struct wlan_network_security *security = &(wlan.networks[network_idx].security);
5429 const char *pos = buf + sizeof(DPP_EVENT_CONFOBJ_PSK) - 1;
5430
5431 hex_len = strlen(pos);
5432 if (hex_len <= (WLAN_PMK_LENGTH * 2))
5433 {
5434 memset(pmk, 0, sizeof(pmk));
5435 hexstr2bin(pos, (unsigned char *)pmk, hex_len/2);
5436 security->pmk_valid = true;
5437 (void)memcpy(security->pmk, pmk, WLAN_PMK_LENGTH);
5438 }
5439 }
5440 }
5441 else if (strstr(buf, DPP_EVENT_CONNECTOR))
5442 {
5443 unsigned int network_idx = -1;
5444
5445 if (is_uap_started())
5446 {
5447 network_idx = wlan.cur_uap_network_idx;
5448 }
5449 else
5450 {
5451 network_idx = wlan.cur_network_idx;
5452 }
5453 if (network_idx < WLAN_MAX_KNOWN_NETWORKS)
5454 {
5455 struct wlan_network_security *security = &(wlan.networks[network_idx].security);
5456 const char *pos = buf + sizeof(DPP_EVENT_CONNECTOR) - 1;
5457
5458 if (security->dpp_connector)
5459 {
5460 OSA_MemoryFree(security->dpp_connector);
5461 }
5462 security->dpp_connector = OSA_MemoryAllocate(strlen(pos) + 1);
5463 if (security->dpp_connector == NULL)
5464 {
5465 wlcm_e("Allocate %s memory failed!", DPP_EVENT_CONNECTOR);
5466 return ;
5467 }
5468 (void)memcpy(security->dpp_connector, pos, strlen(pos));
5469 }
5470 }
5471 else if (strstr(buf, DPP_EVENT_C_SIGN_KEY))
5472 {
5473 unsigned int network_idx = -1;
5474
5475 if (is_uap_started())
5476 {
5477 network_idx = wlan.cur_uap_network_idx;
5478 }
5479 else
5480 {
5481 network_idx = wlan.cur_network_idx;
5482 }
5483 if (network_idx < WLAN_MAX_KNOWN_NETWORKS)
5484 {
5485 struct wlan_network_security *security = &(wlan.networks[network_idx].security);
5486 const char *pos = buf + sizeof(DPP_EVENT_C_SIGN_KEY) - 1;
5487
5488 if (security->dpp_c_sign_key)
5489 {
5490 OSA_MemoryFree(security->dpp_c_sign_key);
5491 }
5492 security->dpp_c_sign_key = OSA_MemoryAllocate(strlen(pos) + 1);
5493 if (security->dpp_c_sign_key == NULL)
5494 {
5495 wlcm_e("Allocate %s memory failed!", DPP_EVENT_C_SIGN_KEY);
5496 return ;
5497 }
5498 (void)memcpy(security->dpp_c_sign_key, pos, strlen(pos));
5499 }
5500 }
5501 else if (strstr(buf, DPP_EVENT_NET_ACCESS_KEY))
5502 {
5503 unsigned int network_idx = -1;
5504
5505 if (is_uap_started())
5506 {
5507 network_idx = wlan.cur_uap_network_idx;
5508 }
5509 else
5510 {
5511 network_idx = wlan.cur_network_idx;
5512 }
5513 if (network_idx < WLAN_MAX_KNOWN_NETWORKS)
5514 {
5515 struct wlan_network_security *security = &(wlan.networks[network_idx].security);
5516 const char *pos = buf + sizeof(DPP_EVENT_NET_ACCESS_KEY) - 1;
5517
5518 if (security->dpp_net_access_key)
5519 {
5520 OSA_MemoryFree(security->dpp_net_access_key);
5521 }
5522 security->dpp_net_access_key = OSA_MemoryAllocate(strlen(pos) + 1);
5523 if (security->dpp_net_access_key == NULL)
5524 {
5525 wlcm_e("Allocate %s memory failed!", DPP_EVENT_NET_ACCESS_KEY);
5526 return ;
5527 }
5528 (void)memcpy(security->dpp_net_access_key, pos, strlen(pos));
5529 if (is_uap_started())
5530 {
5531 wlcm_d("DPP reload uap");
5532 wlan_enable_uap_11d(MTRUE);
5533 wpa_supp_start_ap(netif, &wlan.networks[network_idx], 1);
5534 }
5535 }
5536 }
5537 else if (strstr(buf, DPP_EVENT_INTRO))
5538 {
5539 wlan_deepsleepps_on();
5540 wlan_ieeeps_on(wlan.wakeup_conditions);
5541 }
5542 else
5543 #endif
5544 {
5545 }
5546 }
5547 #endif
5548 #endif
5549
5550 #define MAX_RETRY_TICKS 50
5551
wlcm_process_init_params()5552 static void wlcm_process_init_params()
5553 {
5554 wlan.cm_ieeeps_configured = false;
5555
5556 wlan.cm_deepsleepps_configured = false;
5557
5558 #if (CONFIG_WNM_PS)
5559 wlan.cm_wnmps_configured = false;
5560 wlan.wnm_sleep_time = 0;
5561 #endif
5562 #if (CONFIG_11K) || (CONFIG_11V)
5563 memset(&wlan.nlist_rep_param, 0x00, sizeof(wlan_nlist_report_param));
5564 #endif
5565
5566 #if CONFIG_BG_SCAN
5567 wlan.bgscan_attempt = 0;
5568 #endif
5569
5570 wlan.cur_network_idx = -1;
5571 wlan.cur_uap_network_idx = -1;
5572 }
5573
wlcm_process_init(enum cm_sta_state * next)5574 static void wlcm_process_init(enum cm_sta_state *next)
5575 {
5576 int ret;
5577 (void)ret;
5578
5579 wlan.sta_state = CM_STA_IDLE;
5580 *next = CM_STA_IDLE;
5581
5582 wlcm_process_init_params();
5583
5584 #if CONFIG_P2P
5585 /* This call is made to initiate WFD, We are not interested
5586 * in the response since mac addr is already populated in
5587 * wlan_start
5588 */
5589 wifi_get_wfd_mac_address();
5590 #endif
5591
5592 #if OTP_CHANINFO
5593 (void)wifi_get_fw_region_and_cfp_tables();
5594 #endif
5595
5596 (void)wifi_get_uap_max_clients(&wlan.uap_supported_max_sta_num);
5597
5598 #if CONFIG_WPA_SUPP
5599 #if CONFIG_WPA_SUPP_AP
5600 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
5601 struct netif *uap_netif = net_get_uap_interface();
5602
5603 wpa_supp_set_ap_max_num_sta(uap_netif, wlan.uap_supported_max_sta_num);
5604 #endif
5605 #endif
5606 #endif
5607
5608 (void)wrapper_wlan_cmd_get_hw_spec();
5609
5610 #ifndef RW610
5611 wlan_ed_mac_ctrl_t wlan_ed_mac_ctrl = {
5612 0x01,
5613 CONFIG_NXP_WIFI_ED_OFFSET_2G
5614 #if CONFIG_5GHz_SUPPORT
5615 ,
5616 0x01,
5617 CONFIG_NXP_WIFI_ED_OFFSET_5G
5618 #endif
5619 };
5620 (void)wlan_set_ed_mac_mode(wlan_ed_mac_ctrl);
5621 (void)wlan_set_uap_ed_mac_mode(wlan_ed_mac_ctrl);
5622 #endif
5623
5624 (void)wifi_enable_ecsa_support();
5625
5626 // uint16_t ant = 1; //board_antenna_select();
5627 // if (board_antenna_switch_ctrl())
5628 // rfctrl_set_config(ant);
5629
5630 #ifdef STREAM_2X2
5631 uint8_t tx_antenna = 3, rx_antenna = 3;
5632
5633 ret = wifi_set_antenna(tx_antenna, rx_antenna);
5634 if (ret != WM_SUCCESS)
5635 {
5636 wlcm_e("Failed to set antenna configuration");
5637 return;
5638 }
5639 wlcm_d("Antenna selected: tx: %d, rx:%x", tx_antenna, rx_antenna);
5640 #if 0
5641 uint16_t httxcfg = 0x1FF;
5642
5643 ret = wifi_set_11n_cfg(httxcfg);
5644 if (ret != WM_SUCCESS) {
5645 wlcm_e("Failed to set 11n ht tx configuration");
5646 return;
5647 }
5648 #endif
5649
5650 #if CONFIG_11AC
5651 uint32_t vhtcap = 0x33D179B0;
5652 uint16_t tx_mcs_map = 0xfffa;
5653 uint16_t rx_mcs_map = 0xfffa;
5654
5655 ret = wifi_set_11ac_cfg(vhtcap, tx_mcs_map, rx_mcs_map);
5656 if (ret != WM_SUCCESS)
5657 {
5658 wlcm_e("Failed to set 11ac configuration");
5659 return;
5660 }
5661 #endif
5662 #else
5663 #if defined(SD8801) || defined(SD8978) || defined(SD8987)
5664 uint32_t ant = 1;
5665 uint16_t evaluate_time = 0x1770;
5666
5667 ret = wifi_set_antenna(ant, evaluate_time);
5668 if (ret != WM_SUCCESS)
5669 {
5670 wlcm_d("Failed to set antenna configuration");
5671 }
5672 else
5673 {
5674 wlcm_d("Antenna selected: %d", ant);
5675 }
5676 #endif /* defined(SD8801, 8978, 8987) */
5677 #endif
5678
5679 wifi_set_packet_retry_count(MAX_RETRY_TICKS);
5680
5681 #if defined(SD8978) || defined(SD8987) || defined(SD8997) || defined(SD9097) || defined(SD9098) || defined(SD9177)
5682
5683 wifi_set_txbfcap(0x19e74608);
5684
5685 /*Enabling 20/40MHz enable(bit 1)
5686 * enabling Short GI in 40 Mhz(bit 6)
5687 * and 20MHz(bit 5),
5688 * Reserved bits to be set to 1 (Bits 2,3)*/
5689 uint16_t httxcfg = 0x6E; // TODO need to add defines for this setting
5690
5691 ret = wlan_set_httxcfg(httxcfg);
5692 if (ret != WM_SUCCESS)
5693 {
5694 wlcm_e("Failed to set HT TX configuration");
5695 return;
5696 }
5697
5698 wlan_uap_set_httxcfg(httxcfg);
5699 #endif
5700
5701 #if CONFIG_11K
5702 (void)wifi_host_11k_cfg(1);
5703 #endif
5704 #if CONFIG_11K_OFFLOAD
5705 (void)wifi_11k_cfg(1);
5706 (void)wifi_11h_enable();
5707 #endif
5708 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_1AS)
5709 #if !CONFIG_WPA_SUPP
5710 (void)wlan_rx_mgmt_indication(WLAN_BSS_TYPE_STA, WLAN_MGMT_ACTION, NULL);
5711 #endif
5712 #endif
5713
5714 #if !CONFIG_WPA_SUPP
5715 #if CONFIG_DRIVER_MBO
5716 wifi_host_mbo_cfg(1);
5717 #endif
5718 #endif
5719
5720 #if CONFIG_WIFI_AUTO_POWER_SAVE
5721 wlan_deepsleepps_on();
5722 wifi_set_power_save_mode();
5723 wlan_ieeeps_on(wlan.wakeup_conditions);
5724 #endif
5725
5726 wlan_set_11d_state(WLAN_BSS_TYPE_UAP, 1);
5727 wlan_set_11d_state(WLAN_BSS_TYPE_STA, 1);
5728 }
5729
wlcm_process_net_if_config_event(struct wifi_message * msg,enum cm_sta_state * next)5730 static void wlcm_process_net_if_config_event(struct wifi_message *msg, enum cm_sta_state *next)
5731 {
5732 #if CONFIG_WPA_SUPP
5733 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
5734 struct netif *netif = net_get_sta_interface();
5735 #endif
5736 int ret;
5737 #endif
5738
5739 if (wlan.sta_state != CM_STA_INITIALIZING)
5740 {
5741 wlcm_d("ignoring TCP configure response");
5742 return;
5743 }
5744
5745 if (msg->reason != WIFI_EVENT_REASON_SUCCESS)
5746 {
5747 wlcm_e("Interfaces init failed");
5748 CONNECTION_EVENT(WLAN_REASON_INITIALIZATION_FAILED, NULL);
5749 /* stay here until user re-inits */
5750 *next = CM_STA_INITIALIZING;
5751 return;
5752 }
5753 #if CONFIG_WPA_SUPP
5754 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
5755 ret = wpa_supp_init(wpa_supplicant_msg_cb);
5756 if (ret != 0)
5757 {
5758 wlcm_e("wpa_supp_init failed. status code %d", ret);
5759 return;
5760 }
5761 #endif
5762 ret = wifi_supp_init();
5763 if (ret != 0)
5764 {
5765 wlcm_e("wifi_supp_init failed. status code %d", ret);
5766 return;
5767 }
5768 wifi_set_rx_mgmt_indication(WLAN_BSS_ROLE_STA, WLAN_MGMT_ACTION);
5769 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
5770 ret = wpa_supp_status(netif);
5771 if (ret != 0)
5772 {
5773 wlcm_e("wpa_supp_status failed. status code %d", ret);
5774 return;
5775 }
5776
5777 /* ret = monitor_start();
5778 if (ret != 0)
5779 {
5780 wlcm_e("monitor_start failed. status code %d", ret);
5781 return;
5782 } */
5783 #endif
5784 #endif
5785
5786 wlcm_process_init(next);
5787 }
5788
5789 static void wlcm_request_disconnect(enum cm_sta_state *next, struct wlan_network *curr_nw);
5790
5791 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
wlcm_process_fw_hang_event(struct wifi_message * msg,enum cm_sta_state * next)5792 static void wlcm_process_fw_hang_event(struct wifi_message *msg, enum cm_sta_state *next)
5793 {
5794 #if CONFIG_WPA_SUPP
5795 struct netif *netif = net_get_sta_interface();
5796 #endif
5797
5798 (void)msg;
5799
5800 CONNECTION_EVENT(WLAN_REASON_FW_HANG, NULL);
5801
5802 if (wlan.sta_state > CM_STA_IDLE)
5803 {
5804 #if CONFIG_WPA_SUPP
5805 wpa_supp_disconnect(netif);
5806 #endif
5807 wlcm_request_disconnect(next, &wlan.networks[wlan.cur_network_idx]);
5808 wlan_dhcp_cleanup();
5809 }
5810
5811 if (wlan.uap_state > CM_UAP_INITIALIZING)
5812 {
5813 (void)do_stop(&wlan.networks[wlan.cur_uap_network_idx]);
5814 }
5815 }
5816
wlcm_process_fw_reset_event(struct wifi_message * msg,enum cm_sta_state * next)5817 static void wlcm_process_fw_reset_event(struct wifi_message *msg, enum cm_sta_state *next)
5818 {
5819 (void)msg;
5820 (void)next;
5821
5822 wlan.ind_reset = 1;
5823
5824 wlcm_process_init(next);
5825
5826 CONNECTION_EVENT(WLAN_REASON_FW_RESET, NULL);
5827 }
5828 #endif
5829
5830 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
wlan_notify_uap_chan_switch(t_u8 channel)5831 static void wlan_notify_uap_chan_switch(t_u8 channel)
5832 {
5833 wifi_ecsa_info *pecsa_info = NULL;
5834
5835 #if !CONFIG_MEM_POOLS
5836 pecsa_info = OSA_MemoryAllocate(sizeof(wifi_ecsa_info));
5837 #else
5838 pecsa_info = OSA_MemoryPoolAllocate(buf_32_MemoryPool);
5839 #endif
5840 if (!pecsa_info)
5841 {
5842 wlcm_w("No mem. Cannot process new channel from channel switch");
5843 return;
5844 }
5845 pecsa_info->bss_type = WLAN_BSS_TYPE_UAP;
5846 pecsa_info->channel = channel;
5847 pecsa_info->band_config = (channel > 14) ? BAND_5GHZ: BAND_2GHZ;
5848
5849 if (wifi_event_completion(WIFI_EVENT_CHAN_SWITCH, WIFI_EVENT_REASON_SUCCESS, pecsa_info) != WM_SUCCESS)
5850 {
5851 /* If fail to send message on queue, free allocated memory ! */
5852 #if !CONFIG_MEM_POOLS
5853 OSA_MemoryFree((void *)pecsa_info);
5854 #else
5855 OSA_MemoryPoolFree(buf_32_MemoryPool, pecsa_info);
5856 #endif
5857 }
5858 }
5859 #endif
5860
uap_state_machine(struct wifi_message * msg)5861 static enum cm_uap_state uap_state_machine(struct wifi_message *msg)
5862 {
5863 struct wlan_network *network = NULL;
5864 enum cm_uap_state next = wlan.uap_state;
5865 void *if_handle = NULL;
5866 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
5867 int ret = 0;
5868 #endif
5869 #if CONFIG_WPA_SUPP
5870 struct netif *netif = net_get_uap_interface();
5871 #endif
5872
5873 network = &wlan.networks[wlan.cur_uap_network_idx];
5874
5875 switch (msg->event)
5876 {
5877 case CM_UAP_USER_REQUEST_START:
5878 wlan.cur_uap_network_idx = (int)msg->data;
5879 wlan.scan_count = 0;
5880 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
5881 (void)do_start(&wlan.networks[wlan.cur_uap_network_idx]);
5882 #endif
5883 next = wlan.uap_state;
5884 break;
5885 case CM_UAP_USER_REQUEST_STOP:
5886 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
5887 supplicant_ap_disable(net_if_get_device((void *)netif));
5888 #else
5889 if (wlan.uap_state < CM_UAP_CONFIGURED)
5890 {
5891 break;
5892 }
5893
5894 (void)do_stop(&wlan.networks[wlan.cur_uap_network_idx]);
5895 next = wlan.uap_state;
5896 #if CONFIG_WPA_SUPP
5897 if (wlan.status_timeout)
5898 {
5899 OSA_TimerDeactivate((osa_timer_handle_t)wlan.supp_status_timer);
5900 wlan.status_timeout = 0;
5901 CONNECTION_EVENT(WLAN_REASON_UAP_START_FAILED, NULL);
5902 }
5903 #endif
5904 #endif
5905 break;
5906 case WIFI_EVENT_UAP_STARTED:
5907 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
5908 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
5909 {
5910 t_u8 sta_channel = mlan_adap->priv[0]->curr_bss_params.bss_descriptor.channel;
5911 t_u8 uap_channel = mlan_adap->priv[1]->uap_channel;
5912
5913 CONNECTION_EVENT(WLAN_REASON_UAP_SUCCESS, NULL);
5914 if(is_sta_connected() && uap_channel != sta_channel)
5915 {
5916 while(!is_uap_started())
5917 OSA_TimeDelay(10);
5918 PRINTF("Station has connection on channel %d, switch to this channel\r\n", sta_channel);
5919 wlan_notify_uap_chan_switch(sta_channel);
5920 }
5921 }
5922 #else
5923 if (!is_uap_state(CM_UAP_CONFIGURED))
5924 {
5925 wlcm_w(
5926 "Ignoring address config event as uap not "
5927 "in configured state");
5928 break;
5929 }
5930
5931 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
5932 {
5933 if (network->type == WLAN_BSS_TYPE_UAP)
5934 {
5935 (void)memcpy((void *)&network->bssid[0], (const void *)&wlan.uap_mac[0], 6);
5936 if_handle = net_get_uap_handle();
5937 }
5938 #if CONFIG_P2P
5939 else if (network->type == WLAN_BSS_TYPE_WIFIDIRECT)
5940 {
5941 (void)memcpy((void *)&network->bssid[0], (const void *)&wlan.wfd_mac[0], 6);
5942 if_handle = net_get_wfd_handle();
5943 }
5944 #endif /* CONFIG_P2P */
5945 #if CONFIG_WPA_SUPP
5946 OSA_TimerDeactivate((osa_timer_handle_t)wlan.supp_status_timer);
5947 wlan.status_timeout = 0;
5948
5949 wpa_supp_network_status(netif, network);
5950 #endif
5951 ret = net_configure_address((struct net_ip_config *)&network->ip, if_handle);
5952 if (ret != 0)
5953 {
5954 wlcm_e("TCP/IP stack setup failed");
5955 CONNECTION_EVENT(WLAN_REASON_ADDRESS_FAILED, NULL);
5956 }
5957 else
5958 {
5959 next = CM_UAP_STARTED;
5960 }
5961 }
5962 else
5963 {
5964 CONNECTION_EVENT(WLAN_REASON_UAP_START_FAILED, NULL);
5965 }
5966 #endif
5967 break;
5968 case WIFI_EVENT_UAP_CLIENT_ASSOC:
5969 #if CONFIG_WIFI_UAP_WORKAROUND_STICKY_TIM
5970 if (network->type == WLAN_BSS_TYPE_UAP)
5971 {
5972 wifi_uap_enable_sticky_bit(msg->data);
5973 }
5974 #endif /* CONFIG_WIFI_UAP_WORKAROUND_STICKY_TIM */
5975 CONNECTION_EVENT(WLAN_REASON_UAP_CLIENT_ASSOC, msg->data);
5976 /* This was allocated by the sender */
5977 #if !CONFIG_MEM_POOLS
5978 OSA_MemoryFree(msg->data);
5979 #else
5980 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
5981 #endif
5982 break;
5983 case WIFI_EVENT_UAP_CLIENT_CONN:
5984 CONNECTION_EVENT(WLAN_REASON_UAP_CLIENT_CONN, msg->data);
5985 /* This was allocated by the sender */
5986 #if !CONFIG_MEM_POOLS
5987 OSA_MemoryFree(msg->data);
5988 #else
5989 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
5990 #endif
5991 break;
5992 case WIFI_EVENT_UAP_CLIENT_DEAUTH:
5993 #ifdef CONFIG_WPA_SUPP_AP
5994 {
5995 wlan_uap_client_disassoc_t *disassoc_resp = msg->data;
5996 /* BIT 14 indicate deauth is initiated by FW */
5997 if(!(disassoc_resp->reason_code & MBIT(14)))
5998 {
5999 wifi_nxp_sta_remove(disassoc_resp->sta_addr);
6000 }
6001 }
6002 #else
6003 CONNECTION_EVENT(WLAN_REASON_UAP_CLIENT_DISSOC, msg->data);
6004 #endif
6005 /* This was allocated by the sender */
6006 #if !CONFIG_MEM_POOLS
6007 OSA_MemoryFree(msg->data);
6008 #else
6009 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
6010 #endif
6011 break;
6012 case WIFI_EVENT_UAP_STOPPED:
6013 CONNECTION_EVENT(WLAN_REASON_UAP_STOPPED, NULL);
6014 break;
6015 case WIFI_EVENT_UAP_NET_ADDR_CONFIG:
6016 if (!is_uap_state(CM_UAP_STARTED))
6017 {
6018 wlcm_w(
6019 "Ignoring address config event as uap not "
6020 "in started state");
6021 break;
6022 }
6023
6024 if (msg->reason == WIFI_EVENT_REASON_SUCCESS && network->ip.ipv4.addr_type == ADDR_TYPE_STATIC)
6025 {
6026 if (network->type == WLAN_BSS_TYPE_UAP)
6027 {
6028 if_handle = net_get_uap_handle();
6029 }
6030 #if CONFIG_P2P
6031 else if (network->type == WLAN_BSS_TYPE_WIFIDIRECT)
6032 {
6033 if_handle = net_get_wfd_handle();
6034 }
6035 else
6036 {
6037 /*Do Nothing*/
6038 }
6039 #endif /* CONFIG_P2P */
6040
6041 (void)net_get_if_addr((struct net_ip_config *)&network->ip, if_handle);
6042 /* UAP case set dns same as gateway */
6043 network->ip.ipv4.dns1 = network->ip.ipv4.gw;
6044 network->ip.ipv4.dns2 = 0;
6045 #if CONFIG_IPV6
6046 (void)net_get_if_ipv6_addr((struct net_ip_config *)&network->ip, if_handle);
6047 #endif
6048 next = CM_UAP_IP_UP;
6049 CONNECTION_EVENT(WLAN_REASON_UAP_SUCCESS, NULL);
6050 }
6051 else
6052 {
6053 CONNECTION_EVENT(WLAN_REASON_ADDRESS_FAILED, NULL);
6054 next = CM_UAP_INITIALIZING;
6055 }
6056 break;
6057 default:
6058 wlcm_w("got unknown message UAP : %d", msg->event);
6059 break;
6060 }
6061 return next;
6062 }
6063
wlcm_request_scan(struct wifi_message * msg,enum cm_sta_state * next)6064 static void wlcm_request_scan(struct wifi_message *msg, enum cm_sta_state *next)
6065 {
6066 char ssid[(MLAN_MAX_SSID_LENGTH + 1) * MRVDRV_MAX_SSID_LIST_LENGTH] = {0};
6067 uint8_t ssid_num = 0, ssid_off = 0;
6068 if (msg->data == NULL)
6069 {
6070 wlcm_w("ignoring scan request with NULL scan params");
6071 wlcm_d("releasing scan lock");
6072 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
6073 wlan.is_scan_lock = 0;
6074 return;
6075 }
6076
6077 wlan_scan_params_v2_t *wlan_scan_param = (wlan_scan_params_v2_t *)msg->data;
6078
6079 if ((!is_scanning_allowed())
6080 #if CONFIG_WPS2
6081 || (wlan_get_prov_session() != PROV_NON_SESSION_ATTEMPT)
6082 #endif
6083 )
6084 {
6085 wlcm_w("ignoring scan result in invalid state");
6086 wlcm_d("releasing scan lock");
6087 /* Free allocated wifi scan parameters */
6088 #if !CONFIG_MEM_POOLS
6089 OSA_MemoryFree(wlan_scan_param);
6090 #else
6091 OSA_MemoryPoolFree(buf_128_MemoryPool, wlan_scan_param);
6092 #endif
6093 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
6094 wlan.is_scan_lock = 0;
6095 return;
6096 }
6097
6098 memcpy(ssid+ssid_off, wlan_scan_param->ssid[0], strlen(wlan_scan_param->ssid[0]));
6099 ssid_off += strlen(wlan_scan_param->ssid[0]);
6100 ssid[ssid_off] = '\0';
6101 ssid_off++;
6102 ssid_num++;
6103 #if CONFIG_COMBO_SCAN
6104 if (strlen(wlan_scan_param->ssid[1]))
6105 {
6106 memcpy(ssid+ssid_off, wlan_scan_param->ssid[1], strlen(wlan_scan_param->ssid[1]));
6107 ssid_off += strlen(wlan_scan_param->ssid[1]);
6108 ssid[ssid_off] = '\0';
6109 ssid_num++;
6110 }
6111 #endif
6112 #if CONFIG_SCAN_CHANNEL_GAP
6113 if (is_uap_started() || is_sta_connected())
6114 wlan_scan_param->scan_chan_gap = scan_channel_gap;
6115 else
6116 wlan_scan_param->scan_chan_gap = 0;
6117 #endif
6118
6119 #if CONFIG_WPA_SUPP
6120 #if CONFIG_11K
6121 if (wlan.enable_11k == 1U)
6122 {
6123 wm_wifi.wpa_supp_scan = true;
6124 wm_wifi.external_scan = true;
6125 }
6126 #endif
6127 #endif
6128
6129 wlcm_d("initiating wlan-scan (return to %s)", dbg_sta_state_name(wlan.sta_state));
6130
6131 wlan.scan_cb = (int (*)(unsigned int count))(wlan_scan_param->cb);
6132
6133 int ret = wifi_send_scan_cmd((t_u8)g_wifi_scan_params.bss_type, wlan_scan_param->bssid,
6134 ssid, ssid_num,
6135 wlan_scan_param->num_channels, wlan_scan_param->chan_list, wlan_scan_param->num_probes,
6136 #if CONFIG_SCAN_WITH_RSSIFILTER
6137 wlan_scan_param->rssi_threshold,
6138 #endif
6139 #if CONFIG_SCAN_CHANNEL_GAP
6140 wlan_scan_param->scan_chan_gap,
6141 #endif
6142 false, false);
6143 if (ret != WM_SUCCESS)
6144 {
6145 wlcm_e("wifi send scan cmd failed");
6146 (void)wlan.scan_cb(0);
6147 wlan.scan_cb = NULL;
6148 *next = wlan.sta_state;
6149 #if CONFIG_WPA_SUPP
6150 wm_wifi.wpa_supp_scan = false;
6151 wm_wifi.external_scan = false;
6152 #endif
6153 wlcm_d("releasing scan lock");
6154 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
6155 wlan.is_scan_lock = 0;
6156 }
6157 else
6158 {
6159 wlan.sta_return_to = wlan.sta_state;
6160 *next = CM_STA_SCANNING_USER;
6161 }
6162 /* Free allocated wifi scan parameters */
6163 #if !CONFIG_MEM_POOLS
6164 OSA_MemoryFree(wlan_scan_param);
6165 #else
6166 OSA_MemoryPoolFree(buf_128_MemoryPool, wlan_scan_param);
6167 #endif
6168 }
6169
wlcm_deinit(int action)6170 static void wlcm_deinit(int action)
6171 {
6172 if ((wlan.status != WLCMGR_ACTIVATED) && (wlan.status != WLCMGR_INIT_DONE))
6173 {
6174 wlcm_e("cannot deinit wlcmgr. unexpected status: %d\n\r", wlan.status);
6175 return;
6176 }
6177
6178 wifi_scan_stop();
6179 wifi_deinit();
6180
6181 wlan.status = WLCMGR_INACTIVE;
6182 }
6183
wlcm_request_disconnect(enum cm_sta_state * next,struct wlan_network * curr_nw)6184 static void wlcm_request_disconnect(enum cm_sta_state *next, struct wlan_network *curr_nw)
6185 {
6186 void *if_handle = NULL;
6187 /* On disconnect request, we need to take down the interface.
6188 This is required to fix bug # 52964 */
6189 if (curr_nw->type == WLAN_BSS_TYPE_STA)
6190 {
6191 if_handle = net_get_mlan_handle();
6192 }
6193 #if CONFIG_P2P
6194 else if (curr_nw->type == WLAN_BSS_TYPE_WIFIDIRECT)
6195 {
6196 if_handle = net_get_wfd_handle();
6197 }
6198 else
6199 {
6200 /* Do Nothing */
6201 }
6202 #endif /* CONFIG_P2P */
6203 if (if_handle == NULL)
6204 {
6205 #if CONFIG_NCP_BRIDGE
6206 CONNECTION_EVENT(WLAN_REASON_USER_DISCONNECT, (void *)(-WM_FAIL));
6207 #endif
6208 #if CONFIG_HOST_SLEEP
6209 wakelock_put();
6210 #endif
6211 wlcm_w("No interface is up\r\n");
6212 return;
6213 }
6214 net_stop_dhcp_timer();
6215 /* Forcefully stop dhcp on given interface.
6216 * net_interface_dhcp_stop internally does nothing
6217 * if dhcp client is not started.
6218 */
6219 net_interface_dhcp_stop(if_handle);
6220 net_interface_down(if_handle);
6221
6222 if (
6223 #if CONFIG_WPS2
6224 (wlan_get_prov_session() == PROV_NON_SESSION_ATTEMPT) &&
6225 #endif
6226 (wlan.sta_state < CM_STA_IDLE || is_state(CM_STA_IDLE)))
6227 {
6228 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6229 #if CONFIG_WPA_SUPP
6230 if (wlan.status_timeout)
6231 {
6232 OSA_TimerDeactivate((osa_timer_handle_t)wlan.supp_status_timer);
6233 wlan.status_timeout = 0;
6234 CONNECTION_EVENT(WLAN_REASON_USER_DISCONNECT, NULL);
6235 }
6236 else
6237 #endif
6238 #endif
6239 {
6240 #if CONFIG_NCP_BRIDGE
6241 CONNECTION_EVENT(WLAN_REASON_USER_DISCONNECT, (void *)(-WM_FAIL));
6242 #endif
6243 }
6244 if (wlan.connect_wakelock_taken)
6245 {
6246 wlan.connect_wakelock_taken = false;
6247 }
6248
6249 #if CONFIG_HOST_SLEEP
6250 wakelock_put();
6251 #endif
6252 wlan.cur_network_idx = -1;
6253 return;
6254 }
6255
6256 if (is_user_scanning() && wlan.sta_return_to != CM_STA_IDLE)
6257 {
6258 /* we're in a user scan: we'll need to disconnect and
6259 * return to the idle state once this scan completes */
6260 if (wlan.sta_return_to >= CM_STA_ASSOCIATING)
6261 {
6262 #if !CONFIG_WPA_SUPP
6263 (void)wifi_deauthenticate((uint8_t *)curr_nw->bssid);
6264 #endif
6265 wlan.sta_return_to = CM_STA_IDLE;
6266 *next = CM_STA_IDLE;
6267 wlan.sta_ipv4_state = CM_STA_IDLE;
6268 #if CONFIG_IPV6
6269 wlan.sta_ipv6_state = CM_STA_IDLE;
6270 #endif
6271 }
6272 }
6273 else if (wlan.sta_state >= CM_STA_ASSOCIATING)
6274 {
6275 /* if we aren't idle or user scanning,
6276 * we'll need to actually
6277 * disconnect */
6278 #if !CONFIG_WPA_SUPP
6279 (void)wifi_deauthenticate((uint8_t *)curr_nw->bssid);
6280 #endif
6281 if (wlan.is_scan_lock)
6282 {
6283 wlcm_d("releasing scan lock");
6284 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
6285 wlan.is_scan_lock = 0;
6286 }
6287 wlan.sta_return_to = CM_STA_IDLE;
6288 wlan.sta_state = CM_STA_IDLE;
6289 *next = CM_STA_IDLE;
6290 wlan.sta_ipv4_state = CM_STA_IDLE;
6291 #if CONFIG_IPV6
6292 wlan.sta_ipv6_state = CM_STA_IDLE;
6293 #endif
6294 }
6295 else if (wlan.sta_state == CM_STA_SCANNING)
6296 {
6297 wlan.sta_state = CM_STA_IDLE;
6298 *next = CM_STA_IDLE;
6299 wlan.sta_ipv4_state = CM_STA_IDLE;
6300 #if CONFIG_IPV6
6301 wlan.sta_ipv6_state = CM_STA_IDLE;
6302 #endif
6303 }
6304 else
6305 { /* Do Nothing */
6306 }
6307 wlan.cur_network_idx =-1;
6308
6309 #if CONFIG_WPS2
6310 if (wlan_get_prov_session() == PROV_WPS_SESSION_ATTEMPT)
6311 {
6312 CONNECTION_EVENT(WLAN_REASON_WPS_DISCONNECT, NULL);
6313 wlan_set_prov_session(PROV_NON_SESSION_ATTEMPT);
6314 }
6315 else
6316 #endif
6317 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6318 #if CONFIG_WPA_SUPP
6319 if (wlan.status_timeout)
6320 {
6321 #if CONFIG_WPA_SUPP_WPS
6322 wlan.wps_session_attempt = 0;
6323 #endif
6324 OSA_TimerDeactivate((osa_timer_handle_t)wlan.supp_status_timer);
6325 wlan.status_timeout = 0;
6326 }
6327 #endif
6328 #endif
6329 CONNECTION_EVENT(WLAN_REASON_USER_DISCONNECT, NULL);
6330
6331 if (wlan.reassoc_control && wlan.reassoc_request)
6332 {
6333 wlan.scan_count = WLAN_RESCAN_LIMIT;
6334 wlan.reassoc_count = WLAN_RECONNECT_LIMIT;
6335 wlan.reassoc_request = false;
6336 }
6337
6338 if (wlan.connect_wakelock_taken)
6339 {
6340 #if CONFIG_HOST_SLEEP
6341 wakelock_put();
6342 #endif
6343 wlan.connect_wakelock_taken = false;
6344 }
6345 #if CONFIG_HOST_SLEEP
6346 /* The wakelock will be taken when user issue disconnect command and this time flag wlan.connect_wakelock_taken is false.
6347 * Release wakelock when disconnect process is done without check.
6348 */
6349 wakelock_put();
6350 #endif
6351 }
6352
wlcm_request_connect(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)6353 static void wlcm_request_connect(struct wifi_message *msg, enum cm_sta_state *next, struct wlan_network *network)
6354 {
6355 int ret = WM_SUCCESS;
6356 struct wlan_network *new_network = &wlan.networks[(unsigned int)msg->data];
6357 #if CONFIG_WPA_SUPP
6358 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6359 struct netif *netif = net_get_sta_interface();
6360 #endif
6361 #endif
6362
6363 #if CONFIG_HOST_SLEEP
6364 if (!wlan.connect_wakelock_taken)
6365 {
6366 wakelock_get();
6367 wlan.connect_wakelock_taken = true;
6368 }
6369 #endif
6370 #if CONFIG_WLAN_FAST_PATH
6371 /* Mark the fast path cache invalid. */
6372 if ((int)msg->data != wlan.cur_network_idx)
6373 wlan.auth_cache_valid = false;
6374 #endif /* CONFIG_WLAN_FAST_PATH */
6375
6376 (void)wlan_set_pmfcfg((t_u8)new_network->security.mfpc, (t_u8)new_network->security.mfpr);
6377
6378 if ((wlan.roam_reassoc == false) && (wlan.sta_state >= CM_STA_ASSOCIATING))
6379 {
6380 if (new_network->role == WLAN_BSS_ROLE_STA)
6381 {
6382 wlcm_d(
6383 "deauthenticating before"
6384 " attempting new connection");
6385 (void)wifi_deauthenticate((uint8_t *)network->bssid);
6386 }
6387 }
6388
6389 wlcm_d("starting %s to network: %d", wlan.roam_reassoc == false ? "connection" : "reassociation", (int)msg->data);
6390
6391 #if !CONFIG_WPA_SUPP
6392 ret = do_connect((int)msg->data);
6393 #else
6394 wlan.scan_count = 0;
6395 wlan.cur_network_idx = (int)msg->data;
6396 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6397 if (wlan.roam_reassoc == true)
6398 {
6399 ret = wpa_supp_reassociate(netif);
6400 }
6401 else
6402 {
6403 ret = wpa_supp_connect(netif, new_network);
6404 }
6405 #endif
6406 #endif
6407
6408 /* Release the connect scan lock if do_connect fails,
6409 * in successful case it gets freed in scan result event.
6410 */
6411 if (ret != WM_SUCCESS)
6412 {
6413 if (wlan.is_scan_lock)
6414 {
6415 wlcm_d("releasing scan lock (connect scan)");
6416 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
6417 wlan.is_scan_lock = 0;
6418 }
6419 wlan.cur_network_idx = -1;
6420 CONNECTION_EVENT(WLAN_REASON_CONNECT_FAILED, NULL);
6421 }
6422 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6423 #if CONFIG_WPA_SUPP
6424 if (ret == WM_SUCCESS)
6425 {
6426 wlan.sta_state = CM_STA_ASSOCIATING;
6427 wlan.connect = true;
6428 wlan.status_timeout = 0;
6429 (void)OSA_TimerActivate((osa_timer_handle_t)wlan.supp_status_timer);
6430 }
6431 #endif
6432 #endif
6433
6434 *next = wlan.sta_state;
6435 }
6436
wlcm_request_reconnect(enum cm_sta_state * next,struct wlan_network * network)6437 static void wlcm_request_reconnect(enum cm_sta_state *next, struct wlan_network *network)
6438 {
6439 struct wifi_message msg;
6440 msg.event = 0;
6441 msg.reason = WIFI_EVENT_REASON_SUCCESS;
6442 msg.data = (void *)(wlan.cur_network_idx);
6443
6444 wlcm_d("Reconnect in progress ...");
6445
6446 wlan.reassoc_request = true;
6447
6448 if (wlan.reassoc_count < WLAN_RECONNECT_LIMIT)
6449 {
6450 wlcm_d("Reconnect attempt # %d", wlan.reassoc_count + 1);
6451 wlan.reassoc_count++;
6452 wlcm_request_connect(&msg, next, network);
6453 }
6454 else
6455 {
6456 wlcm_d("Reconnection failed. Giving up.");
6457 wlan.reassoc_request = false;
6458 wlan.reassoc_count = 0;
6459
6460 wlan.cur_network_idx = -1;
6461 CONNECTION_EVENT(WLAN_REASON_CONNECT_FAILED, NULL);
6462
6463 wlcm_d("Disconnecting ... ");
6464 (void)wlan_disconnect();
6465 }
6466 }
6467
6468 #if CONFIG_BG_SCAN
wifi_process_bg_scan_stopped(struct wifi_message * msg)6469 static void wifi_process_bg_scan_stopped(struct wifi_message *msg)
6470 {
6471 (void)msg;
6472
6473 if (wlan.roam_reassoc && wlan.bgscan_attempt < BG_SCAN_LIMIT)
6474 {
6475 wlan.bgscan_attempt++;
6476 wlan.roam_reassoc = false;
6477 (void)wifi_event_completion(WIFI_EVENT_RSSI_LOW, WIFI_EVENT_REASON_SUCCESS, NULL);
6478 }
6479 else
6480 {
6481 wlan.bgscan_attempt = 0;
6482 wlan.roam_reassoc = false;
6483 PRINTF("Soft Roam: AP with better RSSI not found");
6484 CONNECTION_EVENT(WLAN_REASON_BGSCAN_NETWORK_NOT_FOUND, NULL);
6485 }
6486 }
6487
wlcm_process_bg_scan_report(void)6488 static void wlcm_process_bg_scan_report(void)
6489 {
6490 wifi_send_scan_query();
6491 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_ROAMING)
6492 /* Set rssi low threshold and subscribe rssi low event again */
6493 (void)wifi_set_rssi_low_threshold(&wlan.rssi_low_threshold);
6494 #endif
6495 }
6496 #endif
6497
wlcm_process_get_hw_spec_event(void)6498 static void wlcm_process_get_hw_spec_event(void)
6499 {
6500 #if CONFIG_WMM
6501 (void)wifi_wmm_init();
6502 #endif
6503
6504 #if CONFIG_WIFI_SMOKE_TESTS
6505 extern int initNetwork(void);
6506 /* network enet init */
6507 int ret = initNetwork();
6508 if (ret != WM_SUCCESS)
6509 {
6510 PRINTF("FAILED to init network (ret=%d). Reboot the board and try again.\r\n", ret);
6511 }
6512 #endif
6513
6514 #if CONFIG_SIGMA_AGENT
6515 extern int sigma_agent_init(void);
6516
6517 (void)sigma_agent_init();
6518 #endif
6519
6520 /* Set Tx Power Limits in Wi-Fi firmware */
6521 (void)wlan_set_wwsm_txpwrlimit();
6522
6523 if (wlan.ind_reset == 0)
6524 {
6525 CONNECTION_EVENT(WLAN_REASON_INITIALIZED, NULL);
6526 }
6527 #if CONFIG_WIFI_IND_RESET
6528 wlan.ind_reset = 0;
6529 #endif
6530 }
6531
wlcm_process_mgmt_frame(void * data)6532 static void wlcm_process_mgmt_frame(void *data)
6533 {
6534 RxPD *rxpd = (RxPD *)(net_stack_buffer_get_payload(data));
6535 wlan_mgmt_pkt *pmgmt_pkt_hdr = NULL;
6536
6537 pmgmt_pkt_hdr = (wlan_mgmt_pkt *)(void *)((uint8_t *)rxpd + rxpd->rx_pkt_offset);
6538 pmgmt_pkt_hdr->frm_len = wlan_le16_to_cpu(pmgmt_pkt_hdr->frm_len);
6539 if ((pmgmt_pkt_hdr->wlan_header.frm_ctl & (t_u16)IEEE80211_FC_MGMT_FRAME_TYPE_MASK) == (t_u16)0U)
6540 {
6541 // coverity[overrun-buffer-val:SUPPRESS]
6542 (void)wlan_process_802dot11_mgmt_pkt(
6543 mlan_adap->priv[0], (t_u8 *)&pmgmt_pkt_hdr->wlan_header,
6544 pmgmt_pkt_hdr->frm_len + sizeof(wlan_mgmt_pkt) - sizeof(pmgmt_pkt_hdr->frm_len), rxpd);
6545 }
6546 }
6547
6548 #if (CONFIG_11MC) || (CONFIG_11AZ)
wlcm_process_ftm_complete_event()6549 static int wlcm_process_ftm_complete_event()
6550 {
6551 return wifi_process_wlc_ftm_event();
6552 }
6553
6554 #if CONFIG_WLS_CSI_PROC
wlcm_process_wls_csi_event(void * p_data)6555 static int wlcm_process_wls_csi_event(void *p_data)
6556 {
6557 return wifi_process_wls_csi_event(p_data);
6558 }
6559
wifi_get_wls_csi_sem(void)6560 int wifi_get_wls_csi_sem(void)
6561 {
6562 osa_status_t status = KOSA_StatusSuccess;
6563
6564 status = OSA_SemaphoreWait((osa_semaphore_handle_t)wls_csi_sem, osaWaitForever_c);
6565
6566 if (status != KOSA_StatusSuccess)
6567 {
6568 return -WM_FAIL;
6569 }
6570
6571 return WM_SUCCESS;
6572 }
6573
wifi_put_wls_csi_sem(void)6574 int wifi_put_wls_csi_sem(void)
6575 {
6576 osa_status_t status = KOSA_StatusSuccess;
6577
6578 status = OSA_SemaphorePost((osa_semaphore_handle_t)wls_csi_sem);
6579
6580 if (status != KOSA_StatusSuccess)
6581 {
6582 return -WM_FAIL;
6583 }
6584
6585 return WM_SUCCESS;
6586 }
6587 #endif
6588
6589 #endif
6590
wlcm_process_region_power_cfg(struct wifi_message * msg)6591 static void wlcm_process_region_power_cfg(struct wifi_message *msg)
6592 {
6593 t_u8 *country_code = (t_u8 *)msg->data;
6594
6595 #if CONFIG_COMPRESS_TX_PWTBL
6596 t_u8 region_code;
6597
6598 region_code = region_string_2_region_code(country_code);
6599 wlan_set_rg_power_cfg(region_code);
6600 #endif
6601
6602 OSA_MemoryFree(country_code);
6603 }
6604
6605 #if (CONFIG_11K) || (CONFIG_11V)
wlcm_set_rssi_low_threshold(enum cm_sta_state * next,struct wlan_network * curr_nw)6606 static void wlcm_set_rssi_low_threshold(enum cm_sta_state *next, struct wlan_network *curr_nw)
6607 {
6608 (void)next;
6609 (void)curr_nw;
6610
6611 (void)wifi_set_rssi_low_threshold(&wlan.rssi_low_threshold);
6612 }
6613 #endif
6614
6615 #if CONFIG_HOST_SLEEP
wlcm_send_host_sleep(struct wifi_message * msg,enum cm_sta_state * next,struct wlan_network * network)6616 static void wlcm_send_host_sleep(struct wifi_message *msg, enum cm_sta_state *next, struct wlan_network *network)
6617 {
6618 uint32_t wake_up_conds = (uint32_t)msg->data;
6619
6620 (void)next;
6621 (void)network;
6622
6623 (void)wlan_send_host_sleep_int(wake_up_conds, MTRUE);
6624 }
6625 #endif
6626
6627 #if CONFIG_CPU_LOADING
wlan_cpu_loading_info_display(void)6628 static void wlan_cpu_loading_info_display(void)
6629 {
6630 uint64_t total_runtime = 0;
6631 uint64_t task_runtime[CPU_LOADING_TASK_NUM] = {0};
6632 float task_runtime_percentage[CPU_LOADING_TASK_NUM] = {0};
6633 uint8_t task_index = 0, i = 0;
6634 uint32_t collect_time = 0;
6635 char cpu_loading_task_name[] = "cpu_loading_task";
6636
6637 for(i = 0; i < cpu_loading.task_nums; i++) //Don't calculate cpu info of cpu_loading_thread task.
6638 {
6639 if(!memcmp(cpu_loading_task_name, cpu_loading.task_name[i], strlen(cpu_loading_task_name)))
6640 continue;
6641
6642 if(cpu_loading.status == CPU_LOADING_STATUS_ONGOING)
6643 task_runtime[i] = cpu_loading.data_cur[i] - cpu_loading.data_pre[i];
6644 else
6645 task_runtime[i] = cpu_loading.data_cur[i] - cpu_loading.first_data[i];
6646
6647 total_runtime += task_runtime[i];
6648 }
6649
6650 collect_time = ((cpu_loading.index - 1) * cpu_loading.sampling_period) /1000;
6651 (void)PRINTF("\r\n");
6652 if(cpu_loading.status != CPU_LOADING_STATUS_ENDING)
6653 (void)PRINTF("CPU loading: %ds ~ %ds \r\n", (collect_time - cpu_loading.sampling_period /1000) + 1, collect_time);
6654 else
6655 (void)PRINTF("Total CPU loading info in previous %d seconds\r\n", cpu_loading.index * cpu_loading.sampling_period / 1000);
6656
6657 (void)PRINTF("taskName \t\tPercentage\r\n");
6658 for(int i = 0; i < cpu_loading.task_nums; i++)
6659 {
6660 if(!memcmp(cpu_loading_task_name, cpu_loading.task_name[i], strlen(cpu_loading_task_name)))
6661 continue;
6662 task_runtime_percentage[i] = (float)(((float)(task_runtime[i]) / total_runtime) * 100);
6663 (void)PRINTF("%s \t\t%6.2f%%\r\n", task_string_name[i], task_runtime_percentage[i]);
6664 }
6665 }
6666
wlan_cpu_loading_stop()6667 static int wlan_cpu_loading_stop()
6668 {
6669 cpu_loading.status = CPU_LOADING_STATUS_ENDING;
6670 wlan_cpu_loading_info_display();
6671
6672 cpu_loading.index = 0;
6673
6674 (void)send_user_request(CM_STA_USER_REQUEST_CPU_LOADING, 0); // Notify wlcmgr task to destory cpu_loading_thread task.
6675
6676 return WM_SUCCESS;
6677 }
6678
wlan_cpu_loading_request()6679 static void wlan_cpu_loading_request()
6680 {
6681 osa_status_t status;
6682
6683 status = OSA_TimerDestroy((osa_timer_handle_t)cpu_loading.cpu_loading_timer);
6684 if (status != KOSA_StatusSuccess)
6685 {
6686 (void)PRINTF("Failed to delete cpu loading timer: %d.\r\n", ret);
6687 }
6688
6689 OSA_MemoryFree(cpu_loading.cpu_loading_info);
6690
6691 status = OSA_TaskDestroy((osa_task_handle_t)cpu_loading.cpu_loading_task_Handle);
6692 if (status != KOSA_StatusSuccess)
6693 {
6694 (void)PRINTF("Failed to delete cpu_loading_task: %d.\r\n", ret);
6695 }
6696
6697 cpu_loading.status = CPU_LOADING_STATUS_DEAD;
6698
6699 (void)PRINTF("Success to stop CPU loading test.\r\n");
6700 }
6701 #endif
6702
6703 /*
6704 * Event Handlers
6705 */
6706
handle_message(struct wifi_message * msg)6707 static enum cm_sta_state handle_message(struct wifi_message *msg)
6708 {
6709 enum cm_sta_state next = wlan.sta_state;
6710 struct wlan_network *network = NULL;
6711 #if CONFIG_WPA_SUPP
6712 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6713 int ret = WM_SUCCESS;
6714 #endif
6715 struct netif *netif = net_get_sta_interface();
6716 #endif
6717
6718 network = &wlan.networks[wlan.cur_network_idx];
6719
6720 switch (msg->event)
6721 {
6722 case CM_STA_USER_REQUEST_CONNECT:
6723 wlan.pending_assoc_request = false;
6724 if (!wlan.assoc_paused)
6725 {
6726 wlcm_request_connect(msg, &next, network);
6727 }
6728 else
6729 {
6730 wlan.pending_assoc_request = true;
6731 }
6732 break;
6733
6734 case CM_STA_USER_REQUEST_DISCONNECT:
6735 #if CONFIG_WPA_SUPP
6736 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6737 wlan.pending_disconnect_request = false;
6738 ret = wpa_supp_abort_scan(netif);
6739 if (ret == WM_SUCCESS)
6740 {
6741 wlan.pending_disconnect_request = true;
6742 }
6743 wpa_supp_disconnect(netif);
6744 #else
6745 supplicant_disconnect(net_if_get_device((void *)netif));
6746 #endif
6747 #endif
6748 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
6749 {
6750 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
6751 #if CONFIG_HOST_SLEEP
6752 wakelock_put();
6753 #endif
6754 #endif
6755 break;
6756 }
6757
6758 wlcm_request_disconnect(&next, network);
6759 break;
6760
6761 case CM_STA_USER_REQUEST_SCAN:
6762 wlcm_request_scan(msg, &next);
6763 break;
6764 #if (CONFIG_11K) || (CONFIG_11V)
6765 case CM_STA_USER_REQUEST_SET_RSSI_THRESHOLD:
6766 wlcm_set_rssi_low_threshold(&next, network);
6767 break;
6768 #endif
6769 #if CONFIG_HOST_SLEEP
6770 case CM_STA_USER_REQUEST_HS:
6771 wlcm_send_host_sleep(msg, &next, network);
6772 break;
6773 #endif
6774 case CM_STA_USER_REQUEST_PS_ENTER:
6775 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
6776 int state = wifi_nxp_supp_state();
6777
6778 if ((state >= WPA_SCANNING) && (state < WPA_COMPLETED))
6779 #else
6780 if (wlan.sta_state >= CM_STA_SCANNING && wlan.sta_state <= CM_STA_OBTAINING_ADDRESS)
6781 #endif
6782 {
6783 wlcm_w("ignoring ps enter in invalid state");
6784 wlcm_e("Error entering power save mode");
6785 break;
6786 }
6787 if (msg->data == NULL)
6788 {
6789 wlcm_w("ignoring ps enter request with NULL ps mode");
6790 wlcm_e("entering power save mode");
6791 break;
6792 }
6793 wlan_enable_power_save((int)msg->data);
6794 break;
6795 case CM_STA_USER_REQUEST_PS_EXIT:
6796 if (msg->data == NULL)
6797 {
6798 wlcm_w("ignoring ps exit request with NULL ps mode");
6799 break;
6800 }
6801 wlan_disable_power_save((int)msg->data);
6802 break;
6803 #if CONFIG_CPU_LOADING
6804 case CM_STA_USER_REQUEST_CPU_LOADING:
6805 wlan_cpu_loading_request();
6806 break;
6807 #endif
6808 case WIFI_EVENT_SCAN_START:
6809 #if CONFIG_WPA_SUPP
6810 wifi_scan_start(msg);
6811 #endif
6812 break;
6813 case WIFI_EVENT_SCAN_RESULT:
6814 wlcm_d("got event: scan result");
6815 wlcm_process_scan_result_event(msg, &next);
6816 break;
6817
6818 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
6819 case WIFI_EVENT_FW_HANG:
6820 wlcm_d("got event: fw hang");
6821 wlcm_process_fw_hang_event(msg, &next);
6822 break;
6823 case WIFI_EVENT_FW_RESET:
6824 wlcm_d("got event: fw reset");
6825 wlcm_process_fw_reset_event(msg, &next);
6826 break;
6827 #endif
6828
6829 #if CONFIG_WPA_SUPP
6830 case WIFI_EVENT_SURVEY_RESULT_GET:
6831 wifi_survey_result_get(msg);
6832 break;
6833 #endif
6834
6835 case WIFI_EVENT_ASSOCIATION:
6836 wlcm_d("got event: association result: %s",
6837 msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
6838 if (msg->reason == WIFI_EVENT_REASON_SUCCESS)
6839 {
6840 CONNECTION_EVENT(WLAN_REASON_ASSOC_SUCCESS, NULL);
6841 }
6842 wlcm_process_association_event(msg, &next);
6843 break;
6844
6845 #if CONFIG_WPA_SUPP
6846 #if CONFIG_AUTO_RECONNECT
6847 case WIFI_EVENT_ASSOCIATION_NOTIFY:
6848 wlcm_d("got event: association notify: %s",
6849 msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
6850
6851 wlcm_process_association_notify_event(msg, &next);
6852 break;
6853 #endif
6854 #endif
6855
6856 case WIFI_EVENT_PMK:
6857 wlcm_d("got event: PMK result: %s", msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
6858 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
6859 break;
6860
6861 wlcm_process_pmk_event(msg, &next, network);
6862 break;
6863 /* We have received a event from firmware whether
6864 * authentication with given wireless credentials was successful
6865 * or not. If successful, we are authenticated and can proceed
6866 * to IP-level setup by configuring the TCP stack for our
6867 * desired address and transitioning to the
6868 * CM_STA_REQUESTING_ADDRESS state where we wait for the TCP
6869 * stack configuration response. Otherwise we have failed to
6870 * connect to the network.
6871 */
6872 case WIFI_EVENT_AUTHENTICATION:
6873 wlcm_d("got event: authentication result: %s",
6874 msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
6875 if(msg->reason == WIFI_EVENT_REASON_FAILURE)
6876 {
6877 #if CONFIG_ECSA
6878 wrapper_clear_media_connected_event();
6879 wlan_switch_to_nondfs_channel();
6880 #endif
6881 }
6882 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
6883 break;
6884
6885 wlcm_process_authentication_event(msg, &next, network);
6886 break;
6887 case WIFI_EVENT_LINK_LOSS:
6888 wlcm_d("got event: link loss, code=%d", (int)msg->data);
6889 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
6890 if (is_sta_connected())
6891 {
6892 CONNECTION_EVENT(WLAN_REASON_LINK_LOST, NULL);
6893 #if CONFIG_ECSA
6894 wrapper_clear_media_connected_event();
6895 wlan_switch_to_nondfs_channel();
6896 #endif
6897 }
6898 #else
6899 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
6900 break;
6901
6902 wlcm_process_link_loss_event(msg, &next, network);
6903 #endif
6904 break;
6905 case WIFI_EVENT_RSSI_LOW:
6906 wlcm_d("got event: rssi low");
6907 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
6908 wlcm_process_rssi_low_event(msg);
6909 #else
6910 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
6911 break;
6912 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_ROAMING)
6913 wlcm_process_rssi_low_event(msg, &next, network);
6914 #else
6915 CONNECTION_EVENT(WLAN_REASON_RSSI_LOW, NULL);
6916 #endif
6917 #endif
6918 break;
6919 #if CONFIG_SUBSCRIBE_EVENT_SUPPORT
6920 case WIFI_EVENT_RSSI_HIGH:
6921 wlcm_d("got event: RSSI high");
6922 CONNECTION_EVENT(WLAN_REASON_RSSI_HIGH, NULL);
6923 break;
6924 case WIFI_EVENT_SNR_LOW:
6925 wlcm_d("got event: SNR low");
6926 CONNECTION_EVENT(WLAN_REASON_SNR_LOW, NULL);
6927 break;
6928 case WIFI_EVENT_SNR_HIGH:
6929 wlcm_d("got event: SNR high");
6930 CONNECTION_EVENT(WLAN_REASON_SNR_HIGH, NULL);
6931 break;
6932 case WIFI_EVENT_MAX_FAIL:
6933 wlcm_d("got event: MAX fail");
6934 CONNECTION_EVENT(WLAN_REASON_MAX_FAIL, NULL);
6935 break;
6936 case WIFI_EVENT_BEACON_MISSED:
6937 wlcm_d("got event: Beacon missed");
6938 CONNECTION_EVENT(WLAN_REASON_BEACON_MISSED, NULL);
6939 break;
6940 case WIFI_EVENT_DATA_RSSI_LOW:
6941 wlcm_d("got event: DATA_RSSI low");
6942 CONNECTION_EVENT(WLAN_REASON_DATA_RSSI_LOW, NULL);
6943 break;
6944 case WIFI_EVENT_DATA_RSSI_HIGH:
6945 wlcm_d("got event: DATA_RSSI high");
6946 CONNECTION_EVENT(WLAN_REASON_DATA_RSSI_HIGH, NULL);
6947 break;
6948 case WIFI_EVENT_DATA_SNR_LOW:
6949 wlcm_d("got event: DATA_SNR low");
6950 CONNECTION_EVENT(WLAN_REASON_DATA_SNR_LOW, NULL);
6951 break;
6952 case WIFI_EVENT_DATA_SNR_HIGH:
6953 wlcm_d("got event: DATA_SNR high");
6954 CONNECTION_EVENT(WLAN_REASON_DATA_SNR_HIGH, NULL);
6955 break;
6956 case WIFI_EVENT_FW_LINK_QUALITY:
6957 wlcm_d("got event: LINK_QUALITY");
6958 CONNECTION_EVENT(WLAN_REASON_LINK_QUALITY, NULL);
6959 break;
6960 case WIFI_EVENT_FW_PRE_BCN_LOST:
6961 wlcm_d("got event: PRE_BEACON_LOST");
6962 CONNECTION_EVENT(WLAN_REASON_PRE_BEACON_LOST, NULL);
6963 break;
6964 #endif
6965 #if CONFIG_HOST_SLEEP
6966 case WIFI_EVENT_HS_ACTIVATED:
6967 case WIFI_EVENT_SLEEP_CONFIRM_DONE:
6968 if (wlan.hs_configured == MTRUE)
6969 {
6970 wlan.hs_configured = MFALSE;
6971 #if CONFIG_POWER_MANAGER
6972 if (!wlan_is_manual)
6973 {
6974 is_hs_handshake_done = WLAN_HOSTSLEEP_SUCCESS;
6975 #ifdef RW610
6976 (void)OSA_TimerDeactivate((osa_timer_handle_t)temperature_mon_timer);
6977 #endif
6978 }
6979 #endif
6980 }
6981 break;
6982 #endif
6983 #if (CONFIG_11K) || (CONFIG_11V)
6984 case WIFI_EVENT_NLIST_REPORT:
6985 wlcm_d("got event: neighbor list report");
6986 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
6987 break;
6988
6989 wlcm_process_neighbor_list_report_event(msg, &next, network);
6990 break;
6991 #endif
6992 #if CONFIG_WLAN_BRIDGE
6993 case WIFI_EVENT_AUTOLINK_NETWORK_SWITCHED:
6994 wlcm_d("got event: auto link switch network");
6995 wlcm_process_network_switch_event(msg, &next, network);
6996 break;
6997 #endif
6998 case WIFI_EVENT_DISASSOCIATION:
6999 wlcm_d("got event: disassociation, code=%d", (int)(msg->data));
7000 #if CONFIG_ECSA
7001 wrapper_clear_media_connected_event();
7002 wlan_switch_to_nondfs_channel();
7003 #endif
7004 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
7005 break;
7006
7007 wlcm_process_disassoc_event(msg, &next, network);
7008 break;
7009
7010 case WIFI_EVENT_DEAUTHENTICATION:
7011 wlcm_d("got event: deauthentication");
7012 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
7013 CONNECTION_EVENT(WLAN_REASON_DISCONNECTED, NULL);
7014 #endif
7015 wlcm_process_deauthentication_event(msg, &next, network);
7016 break;
7017
7018 case WIFI_EVENT_NET_STA_ADDR_CONFIG:
7019 wlcm_d("got event: TCP configured");
7020 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
7021 break;
7022
7023 wlcm_process_sta_addr_config_event(msg, &next, network);
7024 break;
7025
7026 case WIFI_EVENT_GET_HW_SPEC:
7027 wlcm_process_get_hw_spec_event();
7028 break;
7029
7030 case WIFI_EVENT_NET_INTERFACE_CONFIG:
7031 wlcm_d("got event: Interfaces configured");
7032 wlcm_process_net_if_config_event(msg, &next);
7033 break;
7034
7035 case WIFI_EVENT_NET_DHCP_CONFIG:
7036 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
7037 break;
7038
7039 wlcm_process_net_dhcp_config(msg, &next, network);
7040 break;
7041 #if CONFIG_IPV6
7042 case WIFI_EVENT_NET_IPV6_CONFIG:
7043 wlcm_d("got event: net ipv6 config");
7044 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
7045 break;
7046
7047 wlcm_process_net_ipv6_config(msg, &next, network);
7048 break;
7049 #endif /* CONFIG_IPV6 */
7050
7051 case WIFI_EVENT_CHAN_SWITCH_ANN:
7052 wlcm_d("got event: channel switch announcement");
7053 if (wlan.cur_network_idx >= WLAN_MAX_KNOWN_NETWORKS)
7054 break;
7055
7056 wlcm_process_channel_switch_ann(&next, network);
7057 break;
7058 case WIFI_EVENT_CHAN_SWITCH:
7059 wlcm_d("got event: channel switch");
7060 #if CONFIG_WPA_SUPP
7061 wlcm_process_channel_switch_supp(msg);
7062 #else
7063 wlcm_process_channel_switch(msg);
7064 #endif
7065 break;
7066
7067 case WIFI_EVENT_SLEEP:
7068 #if CONFIG_WIFI_PS_DEBUG
7069 wlcm_d("got event: sleep");
7070 #endif
7071 wlcm_process_sleep_event();
7072 break;
7073
7074 case WIFI_EVENT_IEEE_PS:
7075 #if CONFIG_WIFI_PS_DEBUG
7076 wlcm_d("got event: IEEE ps result: %s", msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
7077 #endif
7078 wlcm_process_ieeeps_event(msg);
7079 break;
7080
7081 case WIFI_EVENT_DEEP_SLEEP:
7082 #if CONFIG_WIFI_PS_DEBUG
7083 wlcm_d("got event: deep sleep result: %s",
7084 msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
7085 #endif
7086 wlcm_process_deepsleep_event(msg, &next);
7087
7088 break;
7089 #if (CONFIG_WNM_PS)
7090 case WIFI_EVENT_WNM_PS:
7091 #if CONFIG_WIFI_PS_DEBUG
7092 wlcm_d("got event: WNM ps result: %s", msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
7093 #endif
7094 wlcm_process_wnmps_event(msg);
7095 break;
7096 #endif
7097 case WIFI_EVENT_IEEE_DEEP_SLEEP:
7098 #if CONFIG_WIFI_PS_DEBUG
7099 wlcm_d("got event: IEEE deep sleep result: %s",
7100 msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
7101 #endif
7102 #if !CONFIG_MEM_POOLS
7103 OSA_MemoryFree(msg->data);
7104 #else
7105 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
7106 #endif
7107 break;
7108 case WIFI_EVENT_WNM_DEEP_SLEEP:
7109 #if CONFIG_WIFI_PS_DEBUG
7110 wlcm_d("got event: WNM deep sleep result: %s",
7111 msg->reason == WIFI_EVENT_REASON_SUCCESS ? "success" : "failure");
7112 #endif
7113 #if !CONFIG_MEM_POOLS
7114 OSA_MemoryFree(msg->data);
7115 #else
7116 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
7117 #endif
7118 break;
7119 #if CONFIG_HOST_SLEEP
7120 case WIFI_EVENT_HS_CONFIG:
7121 if (wlan.hs_configured == MTRUE)
7122 {
7123 wlcm_process_hs_config_event();
7124 }
7125 break;
7126 #endif
7127 #if CONFIG_11N
7128 case WIFI_EVENT_11N_ADDBA:
7129 wlcm_process_addba_request(msg);
7130 break;
7131 case WIFI_EVENT_11N_DELBA:
7132 wlcm_process_delba_request(msg);
7133 break;
7134 case WIFI_EVENT_11N_BA_STREAM_TIMEOUT:
7135 wlcm_process_ba_stream_timeout_request(msg);
7136 break;
7137 case WIFI_EVENT_11N_AGGR_CTRL:
7138 wlcm_d("AGGR_CTRL ignored for now");
7139 break;
7140 #endif /* CONFIG_11N */
7141 case WIFI_EVENT_STA_MAC_ADDR_CONFIG:
7142 if (msg->data != NULL)
7143 {
7144 (void)memcpy((void *)&wlan.sta_mac[0], (const void *)msg->data, MLAN_MAC_ADDR_LENGTH);
7145 #if !CONFIG_MEM_POOLS
7146 OSA_MemoryFree(msg->data);
7147 #else
7148 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
7149 #endif
7150 }
7151 break;
7152 case WIFI_EVENT_UAP_MAC_ADDR_CONFIG:
7153 if (msg->data != NULL)
7154 {
7155 (void)memcpy((void *)&wlan.uap_mac[0], (const void *)msg->data, MLAN_MAC_ADDR_LENGTH);
7156 #if !CONFIG_MEM_POOLS
7157 OSA_MemoryFree(msg->data);
7158 #else
7159 OSA_MemoryPoolFree(buf_32_MemoryPool, msg->data);
7160 #endif
7161 }
7162 break;
7163 #if CONFIG_BG_SCAN
7164 case WIFI_EVENT_BG_SCAN_STOPPED:
7165 wlcm_d("got event: BG scan stopped");
7166 wifi_process_bg_scan_stopped(msg);
7167 break;
7168 case WIFI_EVENT_BG_SCAN_REPORT:
7169 wlcm_d("got event: BG scan report");
7170 wlcm_process_bg_scan_report();
7171 break;
7172 #endif
7173 case WIFI_EVENT_MGMT_FRAME:
7174 wlcm_d("got event: management frame");
7175 wlcm_process_mgmt_frame(msg->data);
7176 next = wlan.sta_state;
7177 net_stack_buffer_free(msg->data);
7178 break;
7179 #if CONFIG_WPA_SUPP
7180 case WIFI_EVENT_REMAIN_ON_CHANNEL:
7181 wifi_process_remain_on_channel(msg);
7182 break;
7183 case WIFI_EVENT_MGMT_TX_STATUS:
7184 wifi_process_mgmt_tx_status(msg);
7185 break;
7186 #endif
7187 #if (CONFIG_11MC) || (CONFIG_11AZ)
7188 case WIFI_EVENT_FTM_COMPLETE:
7189 wlcm_d("got event: continue to ftm or stop");
7190 wlcm_process_ftm_complete_event();
7191 break;
7192 #if CONFIG_WLS_CSI_PROC
7193 case WIFI_EVENT_WLS_CSI:
7194 wlcm_d("got event: receive WLS csi data");
7195 wlcm_process_wls_csi_event(msg->data);
7196 break;
7197 #endif
7198 #endif
7199 case WIFI_EVENT_REGION_POWER_CFG:
7200 wlcm_process_region_power_cfg(msg);
7201 break;
7202 default:
7203 wlcm_w("got unknown message: %d", msg->event);
7204 break;
7205 }
7206
7207 return next;
7208 }
7209
is_uap_msg(struct wifi_message * msg)7210 static bool is_uap_msg(struct wifi_message *msg)
7211 {
7212 return (((msg->event >= CM_UAP_USER_REQUEST_START) && (msg->event < CM_WLAN_USER_REQUEST_DEINIT)) ||
7213 (msg->event <= WIFI_EVENT_UAP_LAST));
7214 }
7215
7216 /*
7217 * Main Thread: the WLAN Connection Manager event queue handler and state
7218 * machine.
7219 */
wlcmgr_task(void * data)7220 static void wlcmgr_task(void *data)
7221 {
7222 osa_status_t status;
7223 struct wifi_message msg;
7224 enum cm_sta_state next_sta_state;
7225 enum cm_uap_state next_uap_state;
7226
7227 (void)memset((void *)&msg, 0, sizeof(struct wifi_message));
7228
7229 /* Wait for all the data structures to be created */
7230 while (!wlan.running)
7231 {
7232 OSA_TimeDelay(500);
7233 }
7234
7235 (void)net_wlan_init();
7236
7237 while (true)
7238 {
7239 status = OSA_MsgQGet((osa_msgq_handle_t)wlan.events, &msg, osaWaitForever_c);
7240 if ((wlan.stop_request != 0U) && (msg.event == (uint16_t)CM_WLAN_USER_REQUEST_SHUTDOWN))
7241 {
7242 wlcm_d("Received shutdown request");
7243 wlan.status = WLCMGR_THREAD_STOPPED;
7244 while (true)
7245 {
7246 OSA_TimeDelay(60000);
7247 }
7248 }
7249
7250 if (status == KOSA_StatusSuccess)
7251 {
7252 #if !CONFIG_WIFI_PS_DEBUG
7253 if (msg.event != WIFI_EVENT_SLEEP && msg.event != WIFI_EVENT_IEEE_PS &&
7254 msg.event != WIFI_EVENT_DEEP_SLEEP && msg.event != WIFI_EVENT_IEEE_DEEP_SLEEP)
7255 {
7256 wlcm_d("got wifi message: %d %d %p", msg.event, msg.reason, msg.data);
7257 }
7258 #else
7259 wlcm_d("got wifi message: %d %d %p", msg.event, msg.reason, msg.data);
7260 #endif
7261
7262 if (is_uap_msg(&msg) != 0)
7263 {
7264 /* uAP related msg */
7265 next_uap_state = uap_state_machine(&msg);
7266 if (wlan.uap_state == next_uap_state)
7267 {
7268 continue;
7269 }
7270
7271 wlcm_d("SM uAP %s -> %s", dbg_uap_state_name(wlan.uap_state), dbg_uap_state_name(next_uap_state));
7272 wlan.uap_state = next_uap_state;
7273 }
7274 else if (msg.event == (uint16_t)CM_WLAN_USER_REQUEST_DEINIT)
7275 {
7276 wlcm_deinit((int)msg.data);
7277 }
7278 else
7279 {
7280 /* STA related msg */
7281 next_sta_state = handle_message(&msg);
7282 if (wlan.sta_state == next_sta_state)
7283 {
7284 continue;
7285 }
7286
7287 wlcm_d("SM STA %s -> %s", dbg_sta_state_name(wlan.sta_state), dbg_sta_state_name(next_sta_state));
7288 wlan.sta_state = next_sta_state;
7289 }
7290 }
7291 else
7292 {
7293 wlcm_d("SM queue recv Timed out ");
7294 }
7295 }
7296 }
7297
7298 #if CONFIG_WPS2
7299 /* WLAN Connection Manager scan results callback */
prov_wps_scan_results(unsigned int count)7300 static int prov_wps_scan_results(unsigned int count)
7301 {
7302 int i;
7303 int err;
7304
7305 if (count == 0)
7306 {
7307 OSA_SemaphorePost((osa_semaphore_handle_t)wlan_wps.wps_scan_done);
7308 return 0;
7309 }
7310
7311 for (i = 0; i < count; i++)
7312 {
7313 err = wlan_get_scan_result(i, &wlan_wps.wps_res);
7314 if (err != 0)
7315 {
7316 wlcm_e("Error: can't get scan res %d", i);
7317 continue;
7318 }
7319
7320 if ((wlan_wps.wps_res.wps_session == WPS_SESSION_PBC) || (wlan_wps.wps_res.wps_session == WPS_SESSION_PIN))
7321 break;
7322 }
7323
7324 OSA_SemaphorePost((osa_semaphore_handle_t)wlan_wps.wps_scan_done);
7325
7326 return 0;
7327 }
7328
wps_task(void * data)7329 static void wps_task(void *data)
7330 {
7331 osa_status_t status;
7332
7333 status = OSA_SemaphoreCreateBinary((osa_semaphore_handle_t)wlan_wps.wps_scan_done);
7334 if (status != KOSA_StatusSuccess)
7335 {
7336 wlcm_e("Failed to create WPS scan semaphore");
7337 }
7338
7339 while (1)
7340 {
7341 OSA_TimeDelay(500);
7342 if ((wlan_wps.wps_state == PROV_WPS_PBC_ENABLED) || (wlan_wps.wps_state == PROV_WPS_PIN_ENABLED))
7343 {
7344 int i = 5;
7345
7346 wlcm_d("WPS is enabled");
7347 if (is_uap_started())
7348 {
7349 wlan_wps.wps_state = PROV_WPS_STARTED;
7350 wps_conf.role = 2; //WPS_REGISTRAR
7351 wlan_set_prov_session(PROV_WPS_SESSION_ATTEMPT);
7352 wps_connect(wlan_wps.wps_cmd, wlan_wps.wps_pin, &wlan_wps.wps_res);
7353 }
7354 else
7355 {
7356 while (i)
7357 {
7358 if (wlan_scan(prov_wps_scan_results) != 0)
7359 {
7360 (void)PRINTF("Error: scan request failed, sta_state");
7361 #if CONFIG_WLCMGR_DEBUG
7362 (void)PRINTF("(%s)", dbg_sta_state_name(wlan.sta_state));
7363 #else
7364 (void)PRINTF("(%d)", wlan.sta_state);
7365 #endif
7366 (void)PRINTF(" is not idle/connected\r\n");
7367 (void)PRINTF("Wait or disconnect network\r\n");
7368 break;
7369 }
7370 OSA_SemaphoreWait((osa_semaphore_handle_t)wlan_wps.wps_scan_done, osaWaitForever_c);
7371 if ((wlan_wps.wps_res.wps_session == WPS_SESSION_PIN) ||
7372 (wlan_wps.wps_res.wps_session == WPS_SESSION_PBC))
7373 {
7374 wlcm_d("WPS Session from AP started");
7375 wlan_wps.wps_state = PROV_WPS_STARTED;
7376 wlan_set_prov_session(PROV_WPS_SESSION_ATTEMPT);
7377 wps_connect(wlan_wps.wps_cmd, wlan_wps.wps_pin, &wlan_wps.wps_res);
7378 break;
7379 }
7380 i--;
7381 }
7382 }
7383
7384 wlan_wps.wps_state = PROV_WPS_NONE;
7385 memset(&wlan_wps.wps_res, 0, sizeof(wlan_wps.wps_res));
7386 }
7387 }
7388 }
7389 #endif
7390 /*
7391 * WLAN API
7392 */
7393
send_user_request(enum user_request_type request,unsigned int data)7394 static int send_user_request(enum user_request_type request, unsigned int data)
7395 {
7396 struct wifi_message msg;
7397
7398 msg.event = (uint16_t)request;
7399 msg.reason = WIFI_EVENT_REASON_SUCCESS;
7400 msg.data = (void *)data;
7401
7402 if (OSA_MsgQPut((osa_msgq_handle_t)wlan.events, &msg) == KOSA_StatusSuccess)
7403 {
7404 return WM_SUCCESS;
7405 }
7406
7407 return -WM_FAIL;
7408 }
7409
copy_network(struct wlan_network * dst,struct wlan_network * src)7410 static void copy_network(struct wlan_network *dst, struct wlan_network *src)
7411 {
7412 (void)memcpy((void *)dst, (const void *)src, sizeof(struct wlan_network));
7413 /* Omit any information that was dynamically
7414 * learned from the network so that users can
7415 * see which parameters were actually
7416 * configured by the user.
7417 */
7418 if (!src->bssid_specific)
7419 {
7420 (void)memset(dst->bssid, 0, IEEEtypes_ADDRESS_SIZE);
7421 }
7422 if (!src->ssid_specific)
7423 {
7424 (void)memset(dst->ssid, 0, IEEEtypes_SSID_SIZE);
7425 }
7426 if (!src->channel_specific)
7427 {
7428 dst->channel = 0;
7429 }
7430 if (src->ip.ipv4.addr_type != 0U)
7431 {
7432 dst->ip.ipv4.address = 0;
7433 dst->ip.ipv4.gw = 0;
7434 dst->ip.ipv4.netmask = 0;
7435 dst->ip.ipv4.dns1 = 0;
7436 dst->ip.ipv4.dns2 = 0;
7437 }
7438 }
7439
wifi_wakeup_card_cb(osa_rw_lock_t * plock,unsigned int wait_time)7440 static int wifi_wakeup_card_cb(osa_rw_lock_t *plock, unsigned int wait_time)
7441 {
7442 osa_status_t status = OSA_SemaphoreWait((osa_semaphore_handle_t)plock->rw_lock, 0);
7443 if (status != KOSA_StatusSuccess)
7444 {
7445 wlan_wake_up_card();
7446 status = OSA_SemaphoreWait((osa_semaphore_handle_t)plock->rw_lock, wait_time);
7447 }
7448
7449 if (status != KOSA_StatusSuccess)
7450 {
7451 return -WM_FAIL;
7452 }
7453
7454 return WM_SUCCESS;
7455 }
7456
wlan_init(const uint8_t * fw_start_addr,const size_t size)7457 int wlan_init(const uint8_t *fw_start_addr, const size_t size)
7458 {
7459 int ret;
7460 #if (CONFIG_WMM_UAPSD) || (CONFIG_HOST_SLEEP)
7461 osa_status_t status;
7462 #endif
7463
7464 if (wlan.status != WLCMGR_INACTIVE)
7465 {
7466 return WM_SUCCESS;
7467 }
7468
7469 #if CONFIG_MEM_POOLS
7470 ret = mem_pool_init();
7471 if (ret != WM_SUCCESS)
7472 {
7473 wlcm_e("Failed to init Memory Pools");
7474 return ret;
7475 }
7476 #endif
7477
7478 #ifdef OVERRIDE_CALIBRATION_DATA
7479 wlan_set_cal_data(ext_cal_data, sizeof(ext_cal_data));
7480 #else
7481 #ifndef RW610
7482 wlan_set_cal_data(int_cal_data, sizeof(int_cal_data));
7483 #else
7484 wlan_set_cal_data(cal_data_rw610, sizeof(cal_data_rw610));
7485 #endif
7486 #endif
7487
7488 #if (CONFIG_HOST_PMK) || (CONFIG_WPS2)
7489 wm_mbedtls_lib_init();
7490 #endif /* (CONFIG_HOST_PMK) || (CONFIG_WPS2) */
7491
7492 ret = OSA_RWLockCreateWithCB(&sleep_rwlock, "sleep_mutex", "sleep_rwlock", wifi_wakeup_card_cb);
7493 if (ret != WM_SUCCESS)
7494 {
7495 wifi_e("Create sleep cmd lock failed");
7496 return ret;
7497 }
7498
7499 #if CONFIG_WMM_UAPSD
7500 status = OSA_SemaphoreCreateBinary((osa_semaphore_handle_t)uapsd_sem);
7501 if (status != KOSA_StatusSuccess)
7502 {
7503 wifi_e("Create uapsd sem failed");
7504 return ret;
7505 }
7506 OSA_SemaphorePost((osa_semaphore_handle_t)uapsd_sem);
7507 #endif
7508 #if CONFIG_HOST_SLEEP
7509 status = OSA_SemaphoreCreate((osa_semaphore_handle_t)wakelock, 0);
7510 if (status != KOSA_StatusSuccess)
7511 {
7512 wifi_e("Failed to create wake-lock semaphore");
7513 return ret;
7514 }
7515 #endif
7516
7517 ret = wifi_init(fw_start_addr, size);
7518 if (ret != 0)
7519 {
7520 wlcm_e("wifi_init failed. status code %d", ret);
7521 return ret;
7522 }
7523
7524 wlan.status = WLCMGR_INIT_DONE;
7525 wifi_mac_addr_t mac_addr;
7526 wifi_mac_addr_t mac_addr_uap;
7527 ret = wifi_get_device_mac_addr(&mac_addr);
7528
7529 if (ret != WM_SUCCESS)
7530 {
7531 wlcm_e("Failed to get sta mac address");
7532 return ret;
7533 }
7534
7535 ret = wifi_get_device_uap_mac_addr(&mac_addr_uap);
7536
7537 if (ret != WM_SUCCESS)
7538 {
7539 wlcm_e("Failed to get uap mac address");
7540 return ret;
7541 }
7542
7543 (void)memcpy((void *)&wlan.uap_mac[0], (const void *)mac_addr_uap.mac, MLAN_MAC_ADDR_LENGTH);
7544 (void)memcpy((void *)&wlan.sta_mac[0], (const void *)mac_addr.mac, MLAN_MAC_ADDR_LENGTH);
7545 (void)PRINTF("MAC Address: ");
7546 print_mac((const char *)&wlan.uap_mac);
7547 (void)PRINTF("\r\n");
7548 #if CONFIG_P2P
7549 (void)memcpy((void *)&wlan.wfd_mac[0], (const void *)mac_addr.mac, MLAN_MAC_ADDR_LENGTH);
7550 wlan.wfd_mac[0] |= (0x01 << 1);
7551 #endif
7552
7553 ret = wifi_get_device_firmware_version_ext(&wlan.fw_ver_ext);
7554 if (ret != WM_SUCCESS)
7555 {
7556 wlcm_e("Failed to get verext");
7557 return ret;
7558 }
7559 wlcm_d("WLAN FW ext_version: %s", wlan.fw_ver_ext.version_str);
7560
7561 #if CONFIG_WIFI_FW_DEBUG
7562 if (wlan.wlan_usb_init_cb != NULL)
7563 wlan.wlan_usb_init_cb();
7564 else
7565 wifi_d("USB init callback is not registered");
7566 #endif
7567 return ret;
7568 }
7569
wlan_deinit(int action)7570 void wlan_deinit(int action)
7571 {
7572 if (wlan.running != 0U)
7573 {
7574 (void)send_user_request(CM_WLAN_USER_REQUEST_DEINIT, (unsigned int)action);
7575 }
7576 else
7577 {
7578 wlcm_deinit(action);
7579 }
7580 #ifndef RW610
7581 OSA_RWLockDestroy(&sleep_rwlock);
7582 #endif
7583 }
7584
7585 #if CONFIG_WPS2
wlcm_wps_callback(enum wps_event event,void * data,uint16_t len)7586 static int wlcm_wps_callback(enum wps_event event, void *data, uint16_t len)
7587 {
7588 int ret = WM_SUCCESS;
7589 struct wlan_network *net = (struct wlan_network *)data;
7590
7591 wlcm_d("WPS EVENT = %d data = %p len=%d", event, data, len);
7592
7593 if (event == WPS_STARTED) {
7594 wifi_send_wps_cfg_cmd(1); /* Notify wifidriver that wps session has started */
7595 }
7596 else if (event == WPS_SESSION_SUCCESSFUL)
7597 {
7598 if (data == NULL)
7599 {
7600 wifi_send_wps_cfg_cmd(0); /* Notify wifidriver that wps session end */
7601 if (wps_conf.role != 2) /* if not WPS_REGISTRAR */
7602 {
7603 wlcm_e("Invalid data for WPS SESSION SUCCESSFUL");
7604 return -WM_FAIL;
7605 }
7606 }
7607 if (len == sizeof(struct wlan_network))
7608 {
7609 /* It's WPS SESSION */
7610 wifi_send_wps_cfg_cmd(0); /* Notify wifidriver that wps session end */
7611 ret = wlan_add_network(net);
7612
7613 if (ret != WM_SUCCESS)
7614 {
7615 wlcm_d("Adding network failed");
7616 return ret;
7617 }
7618 #if CONFIG_NCP_BRIDGE
7619 CONNECTION_EVENT(WLAN_REASON_WPS_SESSION_DONE, net);
7620 #endif
7621 ret = wlan_connect(net->name);
7622 if (ret != WM_SUCCESS)
7623 {
7624 wlcm_d("Connecting to network failed");
7625 return ret;
7626 }
7627 }
7628 else
7629 {
7630 /* It's ENTP SESSION */
7631 ret = wlan_wlcmgr_send_msg(WIFI_EVENT_PMK, WIFI_EVENT_REASON_SUCCESS, data);
7632 }
7633
7634 }
7635 else if (event == WPS_SESSION_TIMEOUT || event == WPS_SESSION_FAILED)
7636 {
7637 wifi_send_wps_cfg_cmd(0); /* Notify wifidriver that wps session end */
7638 ret =
7639 wlan_wlcmgr_send_msg(WIFI_EVENT_AUTHENTICATION, WIFI_EVENT_REASON_FAILURE, (void *)WPA2_ENTERPRISE_FAILED);
7640 }
7641
7642 return ret;
7643 }
7644 #endif
7645
assoc_timer_cb(osa_timer_arg_t arg)7646 static void assoc_timer_cb(osa_timer_arg_t arg)
7647 {
7648 wlan.assoc_paused = false;
7649 if (wlan.pending_assoc_request)
7650 {
7651 (void)send_user_request(CM_STA_USER_REQUEST_CONNECT, 0);
7652 }
7653 }
7654
7655 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
7656 #if CONFIG_WPA_SUPP
supp_status_timer_cb(osa_timer_arg_t arg)7657 static void supp_status_timer_cb(osa_timer_arg_t arg)
7658 {
7659 int ret;
7660
7661 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
7662 if (wlan.status_timeout == 60)
7663 #else
7664 if (wlan.status_timeout == 40)
7665 #endif
7666 {
7667 ret = wpa_supp_req_status(wlan.connect ? CONNECT : START);
7668
7669 if (ret != WM_SUCCESS)
7670 {
7671 (void)send_user_request(wlan.connect ? CM_STA_USER_REQUEST_DISCONNECT : CM_UAP_USER_REQUEST_STOP, 0);
7672 }
7673 }
7674
7675 wlan.status_timeout++;
7676 }
7677 #endif
7678 #endif
7679
7680 #if (CONFIG_11K) || (CONFIG_11V)
neighbor_req_timer_cb(osa_timer_arg_t arg)7681 static void neighbor_req_timer_cb(osa_timer_arg_t arg)
7682 {
7683 if (wlan.neighbor_req == true)
7684 {
7685 wlan.neighbor_req = false;
7686 (void)send_user_request(CM_STA_USER_REQUEST_SET_RSSI_THRESHOLD, 0);
7687 }
7688 }
7689 #endif
7690
7691 #if CONFIG_11R
7692 #if CONFIG_WPA_SUPP
ft_roam_timer_cb(osa_timer_arg_t arg)7693 static void ft_roam_timer_cb(osa_timer_arg_t arg)
7694 {
7695 wlan.roam_reassoc = false;
7696 }
7697 #endif
7698 #endif
7699
7700 #ifdef RW610
temperature_mon_cb(osa_timer_arg_t arg)7701 static void temperature_mon_cb(osa_timer_arg_t arg)
7702 {
7703 #if CONFIG_WIFI_RECOVERY
7704 if (wifi_recovery_enable || wifi_fw_is_hang())
7705 {
7706 struct wlan_message msg;
7707 (void)memset(&msg, 0U, sizeof(struct wlan_message));
7708 msg.data = NULL;
7709 msg.id = WIFI_RECOVERY_REQ;
7710 if (OSA_MsgQPut((osa_msgq_handle_t)mon_thread_events, &msg) != KOSA_StatusSuccess)
7711 {
7712 (void)PRINTF("Failed to send wifi recovery msg to queue\r\n");
7713 }
7714 return;
7715 }
7716 #endif
7717 /*
7718 * get CAU module temperature and write to firmware SMU in every 5s
7719 * can also read FW power status by REG PMU->WLAN_CTRL 0x4003_1068
7720 * bit[3:2] == 3 means FW is in sleep status
7721 */
7722 if ((mlan_adap != NULL) && (mlan_adap->ps_state == PS_STATE_AWAKE))
7723 {
7724 wifi_cau_temperature_write_to_firmware();
7725 }
7726 }
7727 #endif
7728
wlan_wait_wlmgr_ready()7729 static void wlan_wait_wlmgr_ready()
7730 {
7731 while (wlan.sta_state == CM_STA_INITIALIZING)
7732 {
7733 /* wait for wlmgr ready */
7734 OSA_TimeDelay(50);
7735 }
7736 }
7737
wlan_start(int (* cb)(enum wlan_event_reason reason,void * data))7738 int wlan_start(int (*cb)(enum wlan_event_reason reason, void *data))
7739 {
7740 #ifdef RW610
7741 static bool reset_mutex_init = 0;
7742 #endif
7743 int ret;
7744 osa_status_t status;
7745
7746 if (!((wlan.status == WLCMGR_INIT_DONE) || (wlan.status == WLCMGR_INACTIVE)))
7747 {
7748 wlcm_e("cannot start wlcmgr. unexpected status: %d", wlan.status);
7749 return WLAN_ERROR_STATE;
7750 }
7751
7752 if (cb == NULL)
7753 {
7754 return -WM_E_INVAL;
7755 }
7756
7757 if (wlan.running != 0U)
7758 {
7759 return WLAN_ERROR_STATE;
7760 }
7761
7762 wlan.sta_state = CM_STA_INITIALIZING;
7763
7764 wlan.sta_return_to = CM_STA_IDLE;
7765 wlan.uap_state = CM_UAP_INITIALIZING;
7766 wlan.uap_return_to = CM_UAP_INITIALIZING;
7767
7768 #if CONFIG_WIFI_STA_RECONNECT
7769 wlan.reassoc_control = true;
7770 #endif
7771 wlan.hidden_scan_on = false;
7772
7773 wlcm_process_init_params();
7774
7775 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_ROAMING)
7776 wlan.rssi_low_threshold = 70;
7777 #endif
7778
7779 #ifdef RW610
7780 #if (CONFIG_WIFI_BLE_COEX_APP) && (CONFIG_WIFI_BLE_COEX_APP == 1)
7781 wlan.wakeup_conditions = (unsigned int)WAKE_ON_UNICAST | (unsigned int)WAKE_ON_MAC_EVENT |
7782 (unsigned int)WAKE_ON_MULTICAST | (unsigned int)WAKE_ON_ARP_BROADCAST;
7783 #else
7784 wlan.wakeup_conditions = 0;
7785 #endif
7786 #else
7787 wlan.wakeup_conditions = (unsigned int)WAKE_ON_UNICAST | (unsigned int)WAKE_ON_MAC_EVENT |
7788 (unsigned int)WAKE_ON_MULTICAST | (unsigned int)WAKE_ON_ARP_BROADCAST;
7789 #endif
7790
7791 wlan.num_networks = 0;
7792 (void)memset(&wlan.networks[0], 0, sizeof(wlan.networks));
7793 (void)memset(&wlan.scan_chan_list, 0, sizeof(wifi_scan_chan_list_t));
7794 wlan.scan_count = 0;
7795 wlan.cb = cb;
7796 wlan.scan_cb = NULL;
7797 wlan.internal = 0;
7798
7799 #if CONFIG_WPA_SUPP
7800 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
7801 wlan.ca_cert_data = NULL;
7802 wlan.ca_cert_len = 0;
7803 wlan.client_cert_data = NULL;
7804 wlan.client_cert_len = 0;
7805 wlan.client_key_data = NULL;
7806 wlan.client_key_len = 0;
7807 #if CONFIG_WPA_SUPP_AP
7808 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
7809 wlan.dh_data = NULL;
7810 wlan.dh_len = 0;
7811 wlan.server_cert_data = NULL;
7812 wlan.server_cert_len = 0;
7813 wlan.server_key_data = NULL;
7814 wlan.server_key_len = 0;
7815 #endif
7816 #endif
7817 #endif
7818 #endif
7819
7820 status = OSA_MsgQCreate((osa_msgq_handle_t)wlan.events, MAX_EVENTS, sizeof(struct wifi_message));
7821 if (status != KOSA_StatusSuccess)
7822 {
7823 wlcm_e("unable to create event queue: %d", status);
7824 return -WM_FAIL;
7825 }
7826
7827 ret = wifi_register_event_queue((osa_msgq_handle_t)wlan.events);
7828
7829 if (ret != WM_SUCCESS)
7830 {
7831 wlcm_e("unable to register event queue");
7832 OSA_MsgQDestroy((osa_msgq_handle_t)wlan.events);
7833 return -WM_FAIL;
7834 }
7835
7836 status = OSA_TaskCreate((osa_task_handle_t)wlan.wlcmgr_task_Handle, OSA_TASK(wlcmgr_task), NULL);
7837 if (status != KOSA_StatusSuccess)
7838 {
7839 wlan.cb = NULL;
7840 (void)wifi_unregister_event_queue(&wlan.events);
7841 OSA_MsgQDestroy((osa_msgq_handle_t)wlan.events);
7842 return -WM_FAIL;
7843 }
7844
7845 #if ((CONFIG_11MC) || (CONFIG_11AZ)) && (CONFIG_WLS_CSI_PROC)
7846 status = OSA_SemaphoreCreateBinary((osa_semaphore_handle_t)wls_csi_sem) ;
7847 if (status != KOSA_StatusSuccess)
7848 {
7849 wlcm_e("unable to create wls csi lock: %d", status);
7850 return -WM_FAIL;
7851 }
7852 OSA_SemaphorePost((osa_semaphore_handle_t)wls_csi_sem);
7853 #endif
7854
7855 if (OSA_SemaphoreCreateBinary((osa_semaphore_handle_t)wlan.scan_lock) != KOSA_StatusSuccess)
7856 {
7857 (void)wifi_unregister_event_queue(&wlan.events);
7858 OSA_MsgQDestroy((osa_msgq_handle_t)wlan.events);
7859 OSA_TaskDestroy((osa_task_handle_t)wlan.wlcmgr_task_Handle);
7860 return -WM_FAIL;
7861 }
7862 OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
7863
7864 #ifdef RW610
7865 if (!reset_mutex_init)
7866 {
7867 status = OSA_MutexCreate((osa_mutex_handle_t)reset_lock);
7868 if (status != KOSA_StatusSuccess)
7869 {
7870 wlan.cb = NULL;
7871 wifi_unregister_event_queue(&wlan.events);
7872 OSA_MsgQDestroy((osa_msgq_handle_t)wlan.events);
7873 OSA_TaskDestroy((osa_task_handle_t)wlan.wlcmgr_task_Handle);
7874 OSA_SemaphoreDestroy((osa_semaphore_handle_t)wlan.scan_lock);
7875 return -WM_FAIL;
7876 }
7877 reset_mutex_init = 1;
7878 }
7879 if (!mon_thread_init)
7880 {
7881 status = OSA_MsgQCreate((osa_msgq_handle_t)mon_thread_events, MAX_EVENTS, sizeof(struct wlan_message));
7882 if (status != KOSA_StatusSuccess)
7883 {
7884 wlcm_e("unable to create event queue: %d", status);
7885 return -WM_FAIL;
7886 }
7887 #if ((defined(APP_LOWPOWER_ENABLED) && (APP_LOWPOWER_ENABLED == 1)) && \
7888 ((CONFIG_WIFI_BLE_COEX_APP) && (CONFIG_WIFI_BLE_COEX_APP == 1)))
7889 /* For coex app, only register wlan notify callback when APP_LOWPOWER_ENABLED == 1 */
7890 #if CONFIG_HOST_SLEEP
7891 #if CONFIG_POWER_MANAGER
7892 PM_RegisterNotify(kPM_NotifyGroup0, &wlan_notify);
7893 #endif
7894 #endif
7895 #endif
7896 /* Host sleep hanshake will be done in IDLE task and infinite
7897 * while loop is added to wait for hankshake complete to
7898 * prevent IDLE task from entering suspend state.
7899 * If mon_thread using same priority of IDLE task, then the
7900 * mon_thread task could not be scheduled as we did not
7901 * enabled time slice.
7902 */
7903 status = OSA_TaskCreate((osa_task_handle_t)wlcmgr_mon_task_Handle, OSA_TASK(wlcmgr_mon_task), NULL);
7904 if (status != KOSA_StatusSuccess)
7905 {
7906 wlan.cb = NULL;
7907 wifi_unregister_event_queue(&wlan.events);
7908 OSA_MsgQDestroy((osa_msgq_handle_t)wlan.events);
7909 OSA_TaskDestroy((osa_task_handle_t)wlan.wlcmgr_task_Handle);
7910 OSA_SemaphoreDestroy((osa_semaphore_handle_t)wlan.scan_lock);
7911 OSA_MutexDestroy((osa_mutex_handle_t)reset_lock);
7912 return -WM_FAIL;
7913 }
7914 mon_thread_init = 1;
7915 }
7916 wifi_cau_temperature_enable();
7917 status = OSA_TimerCreate((osa_timer_handle_t)temperature_mon_timer, TEMPERATURE_MON_TIMEOUT,
7918 &temperature_mon_cb, NULL, KOSA_TimerPeriodic, OSA_TIMER_AUTO_ACTIVATE);
7919 if (status != KOSA_StatusSuccess)
7920 {
7921 wlcm_e("Unable to create temperature monitor timer");
7922 }
7923 #endif
7924
7925 wlan.running = 1;
7926
7927 wlan.status = WLCMGR_ACTIVATED;
7928
7929 #if CONFIG_WPS2
7930 wlcm_d("WPS started");
7931 wps_start(&wps_conf);
7932
7933 status = OSA_TaskCreate((osa_task_handle_t)wlan_wps.wps_task_Handle, OSA_TASK(wps_task), NULL);
7934 if (status != KOSA_StatusSuccess)
7935 {
7936 wlan.cb = NULL;
7937 wifi_unregister_event_queue(&wlan.events);
7938 OSA_MsgQDestroy((osa_msgq_handle_t)wlan.events);
7939 OSA_TaskDestroy((osa_task_handle_t)wlan.wlcmgr_task_Handle);
7940 OSA_SemaphoreDestroy((osa_semaphore_handle_t)wlan.scan_lock);
7941 OSA_MutexDestroy((osa_mutex_handle_t)reset_lock);
7942 return -WM_FAIL;
7943 }
7944 #endif
7945
7946 #if CONFIG_CPU_LOADING
7947 cpu_loading.status = CPU_LOADING_STATUS_DEAD;
7948 cpu_loading.sampling_period = CPU_LOADING_PERIOD;
7949 #endif
7950
7951 status = OSA_TimerCreate((osa_timer_handle_t)wlan.assoc_timer, MSEC_TO_TICK(BAD_MIC_TIMEOUT), &assoc_timer_cb, NULL,
7952 KOSA_TimerOnce, OSA_TIMER_NO_ACTIVATE);
7953 if (status != KOSA_StatusSuccess)
7954 {
7955 wlcm_e("Unable to create unicast bad mic timer");
7956 return -WM_FAIL;
7957 }
7958
7959 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
7960 #if CONFIG_WPA_SUPP
7961 status = OSA_TimerCreate((osa_timer_handle_t)wlan.supp_status_timer, MSEC_TO_TICK(SUPP_STATUS_TIMEOUT),
7962 &supp_status_timer_cb, NULL, KOSA_TimerPeriodic, OSA_TIMER_NO_ACTIVATE);
7963 if (status != KOSA_StatusSuccess)
7964 {
7965 wlcm_e("Unable to create supp status timer");
7966 return -WM_FAIL;
7967 }
7968 #endif
7969 #endif
7970
7971 #if CONFIG_11K
7972
7973 memset(&wlan.nbr_rpt, 0x00, sizeof(wlan_rrm_neighbor_report_t));
7974 #endif
7975
7976 #if (CONFIG_11K) || (CONFIG_11V)
7977 status = OSA_TimerCreate((osa_timer_handle_t)wlan.neighbor_req_timer, MSEC_TO_TICK(NEIGHBOR_REQ_TIMEOUT),
7978 &neighbor_req_timer_cb, NULL, KOSA_TimerOnce, OSA_TIMER_NO_ACTIVATE);
7979 if (status != KOSA_StatusSuccess)
7980 {
7981 wlcm_e("Unable to create neighbor request timer");
7982 return ret;
7983 }
7984 #endif
7985
7986 #if CONFIG_11R
7987 #if CONFIG_WPA_SUPP
7988 status = OSA_TimerCreate((osa_timer_handle_t)wlan.ft_roam_timer, MSEC_TO_TICK(FT_ROAM_TIMEOUT),
7989 &ft_roam_timer_cb, NULL, KOSA_TimerOnce, OSA_TIMER_NO_ACTIVATE);
7990 if (status != KOSA_StatusSuccess)
7991 {
7992 wlcm_e("Unable to create ft roam timer");
7993 return -WM_FAIL;
7994 }
7995 #endif
7996 #endif
7997
7998 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
7999 #ifdef IR_OUTBAND_TRIGGER_GPIO
8000 gpio_pin_config_t out_config = {kGPIO_DigitalOutput, 1, kGPIO_NoIntmode};
8001
8002 #if defined(IOMUXC_GPIO_IR_OUTBAND_TRIGGER)
8003 IOMUXC_SetPinMux(IOMUXC_GPIO_IR_OUTBAND_TRIGGER, /* GPIO_AD_B0_10 is configured as GPIO1_IO10 */
8004 0U);
8005 #endif
8006 GPIO_PinInit(IR_OUTBAND_TRIGGER_GPIO, IR_OUTBAND_TRIGGER_GPIO_PIN, &out_config);
8007 #endif
8008
8009 #endif
8010
8011 wlan_wait_wlmgr_ready();
8012
8013 #if CONFIG_WIFI_SHELL
8014 #if CONFIG_WIFI_RF_TEST_MODE
8015 ret = wlan_test_mode_cli_init();
8016 if (ret != WM_SUCCESS)
8017 {
8018 PRINTF("Failed to initialize WLAN RF test mode CLIs\r\n");
8019 return 0;
8020 }
8021 #endif
8022 #if !(CONFIG_WIFI_RF_TEST_MODE) || (CONFIG_NXP_RW610)
8023 ret = wlan_basic_cli_init();
8024 if (ret != WM_SUCCESS)
8025 {
8026 PRINTF("Failed to initialize BASIC WLAN CLIs\r\n");
8027 return 0;
8028 }
8029 ret = wlan_cli_init();
8030 if (ret != WM_SUCCESS)
8031 {
8032 PRINTF("Failed to initialize WLAN CLIs\r\n");
8033 return 0;
8034 }
8035 #if CONFIG_SIGMA_AGENT
8036 ret = ping_cli_init();
8037 if (ret != WM_SUCCESS)
8038 {
8039 PRINTF("Failed to initialize PING CLI\r\n");
8040 return 0;
8041 }
8042 #endif
8043 ret = wlan_enhanced_cli_init();
8044 if (ret != WM_SUCCESS)
8045 {
8046 PRINTF("Failed to initialize WLAN Enhanced CLIs\r\n");
8047 return 0;
8048 }
8049 #if CONFIG_WPA_SUPP
8050 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
8051 ret = wpa_cli_init();
8052 if (ret != WM_SUCCESS)
8053 {
8054 PRINTF("Failed to initialize WPA SUPP CLIs\r\n");
8055 return 0;
8056 }
8057 #endif
8058 #endif
8059 #endif
8060 #endif
8061
8062 return WM_SUCCESS;
8063 }
8064
wlan_stop(void)8065 int wlan_stop(void)
8066 {
8067 osa_status_t status = KOSA_StatusIdle;
8068 int ret = WM_SUCCESS;
8069 #ifndef RW610
8070 int total_wait_time = 1000; /* millisecs */
8071 int check_interval = 200; /* millisecs */
8072 int num_iterations = total_wait_time / check_interval;
8073 #endif
8074 if (wlan.status != WLCMGR_ACTIVATED)
8075 {
8076 wlcm_e("cannot stop wlcmgr. unexpected status: %d", wlan.status);
8077 return WLAN_ERROR_STATE;
8078 }
8079
8080 if (!wlan.running)
8081 {
8082 wlcm_e("cannot stop wlcmgr. unexpected wlan.running: %d", wlan.running);
8083 return WLAN_ERROR_STATE;
8084 }
8085 #if OTP_CHANINFO
8086 wifi_free_fw_region_and_cfp_tables();
8087 #endif
8088
8089 #ifndef RW610
8090 wlan.running = 0;
8091 wlan.scan_cb = NULL;
8092
8093 #if CONFIG_WPA_SUPP
8094
8095 wifi_supp_deinit();
8096
8097 ret = wpa_supp_deinit();
8098 if (ret != 0)
8099 {
8100 wlcm_e("wpa_supp_deinit failed. status code %d", ret);
8101 return WLAN_ERROR_STATE;
8102 }
8103 #endif
8104
8105 /* We need to wait for scan_lock as wifi scan might have been
8106 * scheduled, so it must be completed before deleting cm_main_thread
8107 * here. Otherwise deadlock situation might arrive as both of them
8108 * share command_lock semaphore.
8109 */
8110 status = OSA_SemaphoreWait((osa_semaphore_handle_t)wlan.scan_lock, osaWaitForever_c);
8111 if (status != KOSA_StatusSuccess)
8112 {
8113 wlcm_w("failed to get scan lock: %d.", ret);
8114 return WLAN_ERROR_STATE;
8115 }
8116 #endif
8117 status = OSA_SemaphoreDestroy((osa_semaphore_handle_t)wlan.scan_lock);
8118 if (status != KOSA_StatusSuccess)
8119 {
8120 wlcm_w("failed to delete scan lock: %d.", ret);
8121 return WLAN_ERROR_STATE;
8122 }
8123 wlan.is_scan_lock = 0;
8124
8125 wlan.scan_cb = NULL;
8126
8127 status = OSA_TimerDestroy((osa_timer_handle_t)wlan.assoc_timer);
8128 if (status != KOSA_StatusSuccess)
8129 {
8130 wlcm_w("failed to delete assoc timer: %d.", ret);
8131 return WLAN_ERROR_STATE;
8132 }
8133 wlan.scan_cb = NULL;
8134 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
8135 #if CONFIG_WPA_SUPP
8136 status = OSA_TimerDestroy((osa_timer_handle_t)wlan.supp_status_timer);
8137 if (status != KOSA_StatusSuccess)
8138 {
8139 wlcm_w("failed to delete supp status timer: %d.", ret);
8140 return WLAN_ERROR_STATE;
8141 }
8142 #endif
8143 #endif
8144
8145 #if (CONFIG_11K) || (CONFIG_11V)
8146 status = OSA_TimerDestroy((osa_timer_handle_t)wlan.neighbor_req_timer);
8147 if (status != KOSA_StatusSuccess)
8148 {
8149 wlcm_w("failed to delete neighbor req timer: %d.", ret);
8150 return WLAN_ERROR_STATE;
8151 }
8152 #endif
8153
8154 #if CONFIG_11R
8155 #if CONFIG_WPA_SUPP
8156 status = OSA_TimerDestroy((osa_timer_handle_t)wlan.ft_roam_timer);
8157 if (status != KOSA_StatusSuccess)
8158 {
8159 wlcm_w("failed to delete ft roam timer: %d.", ret);
8160 return WLAN_ERROR_STATE;
8161 }
8162 #endif
8163 #endif
8164
8165 #ifdef RW610
8166 status = OSA_TimerDestroy((osa_timer_handle_t)temperature_mon_timer);
8167 if (status != KOSA_StatusSuccess)
8168 {
8169 wlcm_w("failed to delete temperature monitor timer: %d.", ret);
8170 return WLAN_ERROR_STATE;
8171 }
8172 #else
8173 /* We need to tell the AP that we're going away, however we've already
8174 * stopped the main thread so we can't do this by means of the state
8175 * machine. Unregister from the wifi interface and explicitly send a
8176 * deauth request and then proceed to tearing the main thread down. */
8177
8178 /* Set stop_request and wait for wlcmgr thread to acknowledge it */
8179 wlan.stop_request = (uint8_t) true;
8180
8181 wlcm_d("Sent wlcmgr shutdown request. Current State: %d", wlan.status);
8182
8183 (void)send_user_request(CM_WLAN_USER_REQUEST_SHUTDOWN, 0);
8184
8185 --num_iterations;
8186 while (wlan.status != WLCMGR_THREAD_STOPPED && num_iterations)
8187 {
8188 --num_iterations;
8189 OSA_TimeDelay((uint32_t)check_interval);
8190 }
8191
8192 if (wlan.status != WLCMGR_THREAD_STOPPED && !num_iterations)
8193 {
8194 wlcm_d("Timed out waiting for wlcmgr to stop\r\n");
8195 wlcm_d("Forcing halt for wlcmgr thread\r\n");
8196 /* Reinitiailize variable states */
8197 wlan.status = WLCMGR_THREAD_STOPPED;
8198 }
8199
8200 wlan.stop_request = (uint8_t) false;
8201 #endif
8202 if (wm_wifi.wlc_mgr_event_queue)
8203 {
8204 ret = wifi_unregister_event_queue(&wlan.events);
8205
8206 if (ret != WM_SUCCESS)
8207 {
8208 wlcm_w("failed to unregister wifi event queue: %d", ret);
8209 return WLAN_ERROR_STATE;
8210 }
8211 }
8212
8213 status = OSA_MsgQDestroy((osa_msgq_handle_t)wlan.events);
8214
8215 if (status != KOSA_StatusSuccess)
8216 {
8217 wlcm_w("failed to delete event queue: %d", ret);
8218 return WLAN_ERROR_STATE;
8219 }
8220
8221 #if CONFIG_HOST_SLEEP
8222 OSA_SemaphoreDestroy((osa_semaphore_handle_t)wakelock);
8223 #endif
8224 #if ((CONFIG_11MC) || (CONFIG_11AZ)) && (CONFIG_WLS_CSI_PROC)
8225 (void)OSA_SemaphoreDestroy((osa_semaphore_handle_t)wls_csi_sem);
8226 #endif
8227
8228 #ifndef RW610
8229 if (wlan.sta_state > CM_STA_ASSOCIATING)
8230 {
8231 (void)wifi_deauthenticate((uint8_t *)wlan.networks[wlan.cur_network_idx].bssid);
8232 wlan.sta_return_to = CM_STA_IDLE;
8233 }
8234 if (wlan.uap_state > CM_UAP_CONFIGURED)
8235 {
8236 (void)wifi_uap_stop();
8237 // (void)dhcp_server_stop();
8238 }
8239
8240 status = OSA_TaskDestroy((osa_task_handle_t)wlan.wlcmgr_task_Handle);
8241
8242 if (status != KOSA_StatusSuccess)
8243 {
8244 wlcm_w("failed to terminate thread: %d", ret);
8245 return WLAN_ERROR_STATE;
8246 }
8247
8248 (void)net_wlan_deinit();
8249
8250 wlan.status = WLCMGR_INIT_DONE;
8251 wlcm_d("WLCMGR thread deleted\n\r");
8252 #else
8253 wlan.running = 0;
8254 wlan.status = WLCMGR_INACTIVE;
8255 memset(&wlan, 0x00, sizeof(wlan));
8256
8257 wifi_deinit();
8258
8259 OSA_RWLockDestroy(&sleep_rwlock);
8260 #endif
8261
8262 #if CONFIG_WMM_UAPSD
8263 OSA_SemaphoreDestroy((osa_semaphore_handle_t)uapsd_sem);
8264 #endif
8265 return ret;
8266 }
8267
wlan_initialize_uap_network(struct wlan_network * net)8268 void wlan_initialize_uap_network(struct wlan_network *net)
8269 {
8270 (void)memset(net, 0, sizeof(struct wlan_network));
8271 /* Set profile name */
8272 (void)strcpy(net->name, "uap-network");
8273 /* Set channel selection to auto (0) */
8274 net->channel = 0;
8275 /* Set network type to uAP */
8276 net->type = WLAN_BSS_TYPE_UAP;
8277 /* Set network role to uAP */
8278 net->role = WLAN_BSS_ROLE_UAP;
8279 /* Specify address type as static assignment */
8280 net->ip.ipv4.addr_type = ADDR_TYPE_STATIC;
8281 }
8282
wlan_initialize_sta_network(struct wlan_network * net)8283 void wlan_initialize_sta_network(struct wlan_network *net)
8284 {
8285 (void)memset(net, 0, sizeof(struct wlan_network));
8286 /* Set profile name */
8287 (void)strcpy(net->name, "sta-network");
8288 /* Set channel selection to auto (0) */
8289 net->channel = 0;
8290 /* Set network type to sta */
8291 net->type = WLAN_BSS_TYPE_STA;
8292 /* Set network role to sta */
8293 net->role = WLAN_BSS_ROLE_STA;
8294 /* Specify address type as dynamic assignment */
8295 net->ip.ipv4.addr_type = ADDR_TYPE_DHCP;
8296 }
8297
isHexNumber(const char * str,const uint8_t len)8298 static bool isHexNumber(const char *str, const uint8_t len)
8299 {
8300 for (int i = 0; i < len; ++i)
8301 {
8302 if (('0' > str[i] || '9' < str[i]) && ('A' > str[i] || 'F' < str[i]) && ('a' > str[i] || 'f' < str[i]))
8303 {
8304 return false;
8305 }
8306 }
8307
8308 return true;
8309 }
8310
wlan_is_key_valid(struct wlan_network * network)8311 static bool wlan_is_key_valid(struct wlan_network *network)
8312 {
8313 enum wlan_security_type type = network->security.type;
8314 bool valid = true;
8315
8316 switch (type)
8317 {
8318 case WLAN_SECURITY_WPA:
8319 case WLAN_SECURITY_WPA2:
8320 case WLAN_SECURITY_WPA_WPA2_MIXED:
8321 #if CONFIG_11R
8322 case WLAN_SECURITY_WPA2_FT:
8323 #endif
8324 /* check the length of PSK phrase */
8325 if (network->security.psk_len < WLAN_PSK_MIN_LENGTH || network->security.psk_len >= WLAN_PSK_MAX_LENGTH)
8326 {
8327 wlcm_e(
8328 "Invalid passphrase length %d "
8329 "(expected ASCII characters: 8..63)",
8330 network->security.psk_len);
8331 return false;
8332 }
8333 if ((network->security.psk_len == WLAN_PSK_MAX_LENGTH - 1) &&
8334 (isHexNumber(network->security.psk, network->security.psk_len) == false))
8335 {
8336 wlcm_e(
8337 "Invalid hexadecimal digits psk"
8338 "(expected Hexadecimal digits: 64)");
8339 return false;
8340 }
8341 break;
8342 case WLAN_SECURITY_WPA2_WPA3_SAE_MIXED:
8343 /* check the length of PSK phrase */
8344 if (network->security.psk_len < WLAN_PSK_MIN_LENGTH || network->security.psk_len >= WLAN_PSK_MAX_LENGTH)
8345 {
8346 wlcm_e(
8347 "Invalid passphrase length %d "
8348 "(expected ASCII characters: 8..63)",
8349 network->security.psk_len);
8350 return false;
8351 }
8352 if ((network->security.psk_len == WLAN_PSK_MAX_LENGTH - 1) &&
8353 (isHexNumber(network->security.psk, network->security.psk_len) == false))
8354 {
8355 wlcm_e(
8356 "Invalid hexadecimal digits psk"
8357 "(expected Hexadecimal digits: 64)");
8358 return false;
8359 }
8360 case WLAN_SECURITY_WPA3_SAE:
8361 #if CONFIG_WPA_SUPP
8362 #if CONFIG_11R
8363 case WLAN_SECURITY_WPA3_FT_SAE:
8364 #endif
8365 #endif
8366 case WLAN_SECURITY_WPA3_SAE_EXT_KEY:
8367 if (network->security.password_len < WLAN_PASSWORD_MIN_LENGTH ||
8368 network->security.password_len > WLAN_PASSWORD_MAX_LENGTH)
8369 {
8370 wlcm_e("Invalid password length %d (expected 8..255)", network->security.password_len);
8371 return false;
8372 }
8373 break;
8374 case WLAN_SECURITY_NONE:
8375 case WLAN_SECURITY_WILDCARD:
8376 #if CONFIG_DRIVER_OWE
8377 case WLAN_SECURITY_OWE_ONLY:
8378 #endif
8379 #if CONFIG_WPA2_ENTP
8380 case WLAN_SECURITY_EAP_TLS:
8381 #elif CONFIG_WPA_SUPP
8382 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
8383 #if CONFIG_EAP_TLS
8384 case WLAN_SECURITY_EAP_TLS:
8385 case WLAN_SECURITY_EAP_TLS_SHA256:
8386 #if CONFIG_11R
8387 case WLAN_SECURITY_EAP_TLS_FT:
8388 case WLAN_SECURITY_EAP_TLS_FT_SHA384:
8389 #endif
8390 #endif
8391 #if CONFIG_EAP_TTLS
8392 case WLAN_SECURITY_EAP_TTLS:
8393 #if CONFIG_EAP_MSCHAPV2
8394 case WLAN_SECURITY_EAP_TTLS_MSCHAPV2:
8395 #endif
8396 #endif
8397 #if CONFIG_EAP_PEAP
8398 #if CONFIG_EAP_MSCHAPV2
8399 case WLAN_SECURITY_EAP_PEAP_MSCHAPV2:
8400 #endif
8401 #if CONFIG_EAP_TLS
8402 case WLAN_SECURITY_EAP_PEAP_TLS:
8403 #endif
8404 #if CONFIG_EAP_GTC
8405 case WLAN_SECURITY_EAP_PEAP_GTC:
8406 #endif
8407 #endif
8408 #if CONFIG_EAP_SIM
8409 case WLAN_SECURITY_EAP_SIM:
8410 #endif
8411 #if CONFIG_EAP_AKA
8412 case WLAN_SECURITY_EAP_AKA:
8413 #endif
8414 #if CONFIG_EAP_AKA_PRIME
8415 case WLAN_SECURITY_EAP_AKA_PRIME:
8416 #endif
8417 #if CONFIG_EAP_FAST
8418 #if CONFIG_EAP_MSCHAPV2
8419 case WLAN_SECURITY_EAP_FAST_MSCHAPV2:
8420 #endif
8421 #if CONFIG_EAP_GTC
8422 case WLAN_SECURITY_EAP_FAST_GTC:
8423 #endif
8424 #endif
8425 #endif
8426 #endif
8427 #if CONFIG_PEAP_MSCHAPV2
8428 case WLAN_SECURITY_EAP_PEAP_MSCHAPV2:
8429 #endif
8430 valid = true;
8431 break;
8432 case WLAN_SECURITY_WEP_OPEN:
8433 case WLAN_SECURITY_WEP_SHARED:
8434 valid = false;
8435 break;
8436 default:
8437
8438 valid = false;
8439 break;
8440 }
8441
8442 if (valid == false)
8443 {
8444 return false;
8445 }
8446 else
8447 {
8448 return true;
8449 }
8450 }
8451
8452 #if CONFIG_WPA_SUPP
8453 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
8454 #if CONFIG_EAP_TLS
wlan_is_eap_tls_security(enum wlan_security_type security)8455 static bool wlan_is_eap_tls_security(enum wlan_security_type security)
8456 {
8457 if ((security == WLAN_SECURITY_EAP_TLS) || (security == WLAN_SECURITY_EAP_TLS_SHA256)
8458 #if CONFIG_11R
8459 || (security == WLAN_SECURITY_EAP_TLS_FT) || (security == WLAN_SECURITY_EAP_TLS_FT_SHA384)
8460 #endif
8461 )
8462 return true;
8463 return false;
8464 }
8465 #endif
8466
8467 #if CONFIG_EAP_TTLS
wlan_is_eap_ttls_security(enum wlan_security_type security)8468 static bool wlan_is_eap_ttls_security(enum wlan_security_type security)
8469 {
8470 if (security == WLAN_SECURITY_EAP_TTLS)
8471 return true;
8472 #if CONFIG_EAP_MSCHAPV2
8473 if (security == WLAN_SECURITY_EAP_TTLS_MSCHAPV2)
8474 return true;
8475 #endif
8476
8477 return false;
8478 }
8479 #endif
8480
8481 #if CONFIG_EAP_PEAP
wlan_is_eap_peap_security(enum wlan_security_type security)8482 static bool wlan_is_eap_peap_security(enum wlan_security_type security)
8483 {
8484 #if CONFIG_EAP_MSCHAPV2
8485 if (security == WLAN_SECURITY_EAP_PEAP_MSCHAPV2)
8486 return true;
8487 #endif
8488 #if CONFIG_EAP_GTC
8489 if (security == WLAN_SECURITY_EAP_PEAP_GTC)
8490 return true;
8491 #endif
8492 #if CONFIG_EAP_TLS
8493 if (security == WLAN_SECURITY_EAP_PEAP_TLS)
8494 return true;
8495 #endif
8496 return false;
8497 }
8498 #endif
8499
wlan_is_eap_fast_security(enum wlan_security_type security)8500 static bool wlan_is_eap_fast_security(enum wlan_security_type security)
8501 {
8502 #if CONFIG_EAP_MSCHAPV2
8503 if (security == WLAN_SECURITY_EAP_FAST_MSCHAPV2)
8504 return true;
8505 #endif
8506 #if CONFIG_EAP_GTC
8507 if (security == WLAN_SECURITY_EAP_FAST_GTC)
8508 return true;
8509 #endif
8510 return false;
8511 }
8512
wlan_is_skip_cert_cfg(enum wlan_security_type security)8513 static bool wlan_is_skip_cert_cfg(enum wlan_security_type security)
8514 {
8515 #if CONFIG_EAP_MSCHAPV2
8516 if (security == WLAN_SECURITY_EAP_TTLS_MSCHAPV2)
8517 return true;
8518
8519 if (security == WLAN_SECURITY_EAP_PEAP_MSCHAPV2)
8520 return true;
8521 #endif
8522
8523 return false;
8524 }
8525
8526 #endif
8527 #endif
8528
wlan_key_mgmt_wpa_psk(int akm)8529 static int wlan_key_mgmt_wpa_psk(int akm)
8530 {
8531 int rakm = (WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_FT_PSK | WLAN_KEY_MGMT_PSK_SHA256);
8532
8533 if (akm == 0)
8534 {
8535 return 0;
8536 }
8537
8538 akm &= ~(WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_FT_PSK | WLAN_KEY_MGMT_PSK_SHA256);
8539
8540 return (!akm && rakm);
8541 }
8542
8543 #if CONFIG_11R
wlan_key_mgmt_ft_psk(int akm)8544 static int wlan_key_mgmt_ft_psk(int akm)
8545 {
8546 int rakm = WLAN_KEY_MGMT_FT_PSK;
8547
8548 if (akm == 0)
8549 {
8550 return 0;
8551 }
8552
8553 akm &= ~WLAN_KEY_MGMT_FT_PSK;
8554
8555 return (!akm && rakm);
8556 }
8557 #endif
8558
wlan_key_mgmt_sae(int akm)8559 static int wlan_key_mgmt_sae(int akm)
8560 {
8561 int rakm;
8562
8563 if (akm == 0)
8564 {
8565 return 0;
8566 }
8567
8568 rakm = (
8569 #if CONFIG_WPA_SUPP_DPP
8570 WLAN_KEY_MGMT_DPP |
8571 #endif
8572 WLAN_KEY_MGMT_SAE |
8573 WLAN_KEY_MGMT_SAE_EXT_KEY);
8574
8575 akm &= ~(
8576 #if CONFIG_WPA_SUPP_DPP
8577 WLAN_KEY_MGMT_DPP |
8578 #endif
8579 WLAN_KEY_MGMT_SAE |
8580 WLAN_KEY_MGMT_SAE_EXT_KEY);
8581
8582 return (!akm && rakm);
8583 }
8584
8585 #if CONFIG_WPA_SUPP
8586 #if CONFIG_11R
wlan_key_mgmt_ft_sae(int akm)8587 static int wlan_key_mgmt_ft_sae(int akm)
8588 {
8589 int rakm =~WLAN_KEY_MGMT_FT_SAE;
8590
8591 if (akm == 0)
8592 {
8593 return 0;
8594 }
8595
8596 akm &= ~WLAN_KEY_MGMT_FT_SAE;
8597
8598 return (!akm && rakm);
8599 }
8600 #endif
8601 #endif
8602
wlan_key_mgmt_wpa_psk_sae(int akm)8603 static int wlan_key_mgmt_wpa_psk_sae(int akm)
8604 {
8605 int rakm;
8606
8607 if (akm == 0)
8608 {
8609 return 0;
8610 }
8611
8612 rakm = (
8613 #if CONFIG_WPA_SUPP_DPP
8614 WLAN_KEY_MGMT_DPP |
8615 #endif
8616 WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_PSK_SHA256 | WLAN_KEY_MGMT_SAE);
8617
8618 akm &= ~(
8619 #if CONFIG_WPA_SUPP_DPP
8620 WLAN_KEY_MGMT_DPP |
8621 #endif
8622 WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_PSK_SHA256 | WLAN_KEY_MGMT_SAE);
8623
8624 return (!akm && rakm);
8625 }
8626
8627 #if CONFIG_DRIVER_OWE
wlan_key_mgmt_owe(int akm)8628 static int wlan_key_mgmt_owe(int akm)
8629 {
8630 int rakm = WLAN_KEY_MGMT_OWE;
8631
8632 if (akm == 0)
8633 {
8634 return 0;
8635 }
8636
8637 akm &= ~WLAN_KEY_MGMT_OWE;
8638
8639 return (!akm && rakm);
8640 }
8641 #endif
8642
8643 #if CONFIG_WPA_SUPP_DPP
wlan_key_mgmt_dpp(int akm)8644 static int wlan_key_mgmt_dpp(int akm)
8645 {
8646 int rakm = WLAN_KEY_MGMT_DPP;
8647
8648 if (akm == 0)
8649 {
8650 return 0;
8651 }
8652
8653 akm &= ~WLAN_KEY_MGMT_DPP;
8654
8655 return (!akm && rakm);
8656 }
8657 #endif
8658
wlan_add_network(struct wlan_network * network)8659 int wlan_add_network(struct wlan_network *network)
8660 {
8661 int pos = -1;
8662 int i;
8663 unsigned int len;
8664 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
8665 int ret = 0;
8666 #endif
8667 if (!wlan.running)
8668 {
8669 return WLAN_ERROR_STATE;
8670 }
8671
8672 #if CONFIG_WPA_SUPP
8673 struct netif *netif = net_get_sta_interface();
8674 #endif
8675
8676 if (network == NULL)
8677 {
8678 return -WM_E_INVAL;
8679 }
8680
8681 if ((network->channel > MAX_CHANNELS_BG) && ISSUPP_NO5G(mlan_adap->fw_cap_ext))
8682 {
8683 wlcm_e("Not support 5G, please set 2G channel");
8684 return -WM_E_INVAL;
8685 }
8686 if ((network->acs_band == 1) && ISSUPP_NO5G(mlan_adap->fw_cap_ext))
8687 {
8688 wlcm_e("Not support 5G, please not set acs_band 1");
8689 return -WM_E_INVAL;
8690 }
8691
8692 if (network->role == WLAN_BSS_ROLE_STA)
8693 {
8694 if (is_running() && !is_state(CM_STA_IDLE) && !is_state(CM_STA_ASSOCIATED) && !is_state(CM_STA_CONNECTED))
8695 {
8696 return WLAN_ERROR_STATE;
8697 }
8698 }
8699
8700 /* make sure that the network name length is acceptable */
8701 len = strlen(network->name);
8702 if (len < WLAN_NETWORK_NAME_MIN_LENGTH || len >= WLAN_NETWORK_NAME_MAX_LENGTH)
8703 {
8704 wlcm_e("name length is out of bounds");
8705 return -WM_E_INVAL;
8706 }
8707
8708 /* make sure that either the SSID or BSSID field is present */
8709 if (network->ssid[0] == '\0' && is_bssid_any(network->bssid))
8710 {
8711 wlcm_e("SSID or BSSID is required");
8712 return -WM_E_INVAL;
8713 }
8714
8715 if ((network->role == WLAN_BSS_ROLE_UAP) && (network->ip.ipv4.gw != network->ip.ipv4.address))
8716 {
8717 wlcm_e("IP address and Default gateway must be same for uAP");
8718 return -WM_E_INVAL;
8719 }
8720
8721 /* Always set PMF capable bt default */
8722 network->security.mfpc = 1;
8723
8724 if (((network->role == WLAN_BSS_ROLE_UAP) || (network->role == WLAN_BSS_ROLE_STA)) &&
8725 ((network->security.type == WLAN_SECURITY_WPA3_SAE)
8726 || (network->security.type == WLAN_SECURITY_WPA3_SAE_EXT_KEY)
8727 #if CONFIG_DRIVER_OWE
8728 || (network->security.type == WLAN_SECURITY_OWE_ONLY)
8729 #endif
8730 ))
8731 {
8732 network->security.mfpr = 1;
8733 }
8734
8735 #if CONFIG_WPA2_ENTP
8736 /* make sure that if in policy wireless connection is allowed
8737 * only with WPA2 Enterprise AP then add the network
8738 */
8739 if ((network->role == WLAN_BSS_ROLE_STA) &&
8740 ((network->security.type != WLAN_SECURITY_EAP_TLS) ||
8741 (network->security.type != WLAN_SECURITY_EAP_PEAP_MSCHAPV2)) &&
8742 wlan.allow_wpa2_enterprise_ap_only)
8743 {
8744 return -WM_E_INVAL;
8745 }
8746 #endif
8747
8748 #if CONFIG_WPA_SUPP
8749 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
8750 if ((is_ep_valid_security(network->security.type)) && ((network->security.wpa3_sb == 1U) || (network->security.wpa3_sb_192 == 1U)))
8751 {
8752 network->security.mfpr = 1;
8753 }
8754 #endif
8755 #endif
8756
8757 #if CONFIG_11R
8758 if ((network->role == WLAN_BSS_ROLE_STA) &&
8759 ((network->security.type == WLAN_SECURITY_WPA2_FT)
8760 #if CONFIG_WPA_SUPP
8761 || (network->security.type == WLAN_SECURITY_WPA3_FT_SAE)
8762 #endif
8763 ) && (network->channel != 0U))
8764 {
8765 wlcm_e("Specific channel not allowed in FT security");
8766 return -WM_E_INVAL;
8767 }
8768 #endif
8769
8770 if (!is_valid_security(network->security.type))
8771 {
8772 wlcm_e("Invalid security type is configured");
8773 return -WM_E_INVAL;
8774 }
8775
8776 if (network->security.key_mgmt == 0)
8777 {
8778 if (network->security.type == WLAN_SECURITY_NONE)
8779 {
8780 network->security.key_mgmt = WLAN_KEY_MGMT_NONE;
8781 }
8782 else if ((network->security.type == WLAN_SECURITY_WPA) || (network->security.type == WLAN_SECURITY_WPA2) || (network->security.type == WLAN_SECURITY_WPA_WPA2_MIXED))
8783 {
8784 network->security.key_mgmt = WLAN_KEY_MGMT_PSK;
8785 }
8786 else if (network->security.type == WLAN_SECURITY_WPA3_SAE)
8787 {
8788 network->security.key_mgmt = WLAN_KEY_MGMT_SAE;
8789 }
8790 else if (network->security.type == WLAN_SECURITY_WPA3_SAE_EXT_KEY)
8791 {
8792 network->security.key_mgmt = WLAN_KEY_MGMT_SAE_EXT_KEY;
8793 }
8794 #if CONFIG_DRIVER_OWE
8795 else if (network->security.type == WLAN_SECURITY_OWE_ONLY)
8796 {
8797 network->security.key_mgmt = WLAN_KEY_MGMT_OWE;
8798 }
8799 #endif
8800 #if CONFIG_11R
8801 else if (network->security.type == WLAN_SECURITY_WPA2_FT)
8802 {
8803 network->security.key_mgmt = WLAN_KEY_MGMT_FT_PSK;
8804 }
8805 #if CONFIG_WPA_SUPP
8806 else if (network->security.type == WLAN_SECURITY_WPA3_FT_SAE)
8807 {
8808 network->security.key_mgmt = WLAN_KEY_MGMT_FT_SAE;
8809 }
8810 #endif
8811 #endif
8812 else if (network->security.type == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED)
8813 {
8814 network->security.key_mgmt = WLAN_KEY_MGMT_PSK | WLAN_KEY_MGMT_SAE;
8815 }
8816 }
8817
8818 if ((network->role == WLAN_BSS_ROLE_UAP) || (network->role == WLAN_BSS_ROLE_STA))
8819 {
8820 if (network->role == WLAN_BSS_ROLE_STA)
8821 {
8822 if ((network->security.type == WLAN_SECURITY_WPA2) && (network->security.mfpc))
8823 {
8824 network->security.key_mgmt |= WLAN_KEY_MGMT_PSK_SHA256;
8825 }
8826 if ((network->security.type == WLAN_SECURITY_WPA_WPA2_MIXED) && (network->security.mfpr))
8827 {
8828 network->security.key_mgmt |= WLAN_KEY_MGMT_PSK_SHA256;
8829 }
8830 }
8831 if (network->role == WLAN_BSS_ROLE_UAP)
8832 {
8833 if ((network->security.type == WLAN_SECURITY_WPA2) && (network->security.mfpr))
8834 {
8835 network->security.key_mgmt |= WLAN_KEY_MGMT_PSK_SHA256;
8836 }
8837 }
8838 }
8839
8840 if (((network->role == WLAN_BSS_ROLE_UAP) || (network->role == WLAN_BSS_ROLE_STA)) &&
8841 ((((network->security.type == WLAN_SECURITY_WPA) || (network->security.type == WLAN_SECURITY_WPA2) || (network->security.type == WLAN_SECURITY_WPA_WPA2_MIXED)) &&
8842 (!wlan_key_mgmt_wpa_psk(network->security.key_mgmt)))
8843 #if CONFIG_11R
8844 || ((network->security.type == WLAN_SECURITY_WPA2_FT) && (!wlan_key_mgmt_ft_psk(network->security.key_mgmt)))
8845 #endif
8846 || ((network->security.type == WLAN_SECURITY_WPA3_SAE) && (!wlan_key_mgmt_sae(network->security.key_mgmt)))
8847 || ((network->security.type == WLAN_SECURITY_WPA3_SAE_EXT_KEY) && (!wlan_key_mgmt_sae(network->security.key_mgmt)))
8848 #if CONFIG_WPA_SUPP
8849 #if CONFIG_11R
8850 || ((network->security.type == WLAN_SECURITY_WPA3_FT_SAE) && (!wlan_key_mgmt_ft_sae(network->security.key_mgmt)))
8851 #endif
8852 #endif
8853 || ((network->security.type == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED) && (!wlan_key_mgmt_wpa_psk_sae(network->security.key_mgmt)))
8854 #if CONFIG_DRIVER_OWE
8855 || ((network->security.type == WLAN_SECURITY_OWE_ONLY) && (!wlan_key_mgmt_owe(network->security.key_mgmt)))
8856 #endif
8857 #if CONFIG_WPA_SUPP_DPP
8858 || ((network->security.type == WLAN_SECURITY_DPP) && (!wlan_key_mgmt_dpp(network->security.key_mgmt)))
8859 #endif
8860 ))
8861 {
8862 wlcm_e("Invalid security/key mgmt is configured");
8863 return -WM_E_INVAL;
8864 }
8865
8866 if (((network->role == WLAN_BSS_ROLE_UAP) || (network->role == WLAN_BSS_ROLE_STA)) &&
8867 (network->security.key_mgmt == WLAN_KEY_MGMT_PSK_SHA256) &&
8868 (!network->security.mfpc && !network->security.mfpr))
8869 {
8870 wlcm_e("MFP is not configured");
8871 return -WM_E_INVAL;
8872 }
8873
8874 if (((network->role == WLAN_BSS_ROLE_UAP) || (network->role == WLAN_BSS_ROLE_STA)) &&
8875 (network->security.type == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED) &&
8876 (!(network->security.mfpc && !network->security.mfpr)))
8877 {
8878 wlcm_e("MFP capable only is allowed");
8879 return -WM_E_INVAL;
8880 }
8881
8882 if (wlan_is_key_valid(network) == false)
8883 {
8884 wlcm_e("Invalid passphrase/password is configured");
8885 return -WM_E_INVAL;
8886 }
8887
8888 /* Make sure network type is set correctly if not
8889 * set correct values as per role*/
8890 if ((network->type == WLAN_BSS_TYPE_STA) || (network->type == WLAN_BSS_TYPE_ANY))
8891 {
8892 if (network->role == WLAN_BSS_ROLE_UAP)
8893 {
8894 network->type = WLAN_BSS_TYPE_UAP;
8895 #if CONFIG_WPA_SUPP
8896 netif = net_get_uap_interface();
8897 #endif
8898 }
8899 else if (network->role == WLAN_BSS_ROLE_STA)
8900 {
8901 network->type = WLAN_BSS_TYPE_STA;
8902 #if CONFIG_WPA_SUPP
8903 netif = net_get_sta_interface();
8904 #endif
8905 }
8906 else
8907 { /* Do Nothing */
8908 }
8909 }
8910
8911 if (network->role == WLAN_BSS_ROLE_UAP)
8912 {
8913 #if CONFIG_WIFI_CAPA
8914 if (network->channel != 14)
8915 {
8916 /* If no capability was configured, set capa up to 11ax by default */
8917 if (!network->wlan_capa)
8918 network->wlan_capa =
8919 #if CONFIG_11AX
8920 WIFI_SUPPORT_11AX |
8921 #endif
8922 #if CONFIG_11AC
8923 WIFI_SUPPORT_11AC |
8924 #endif
8925 WIFI_SUPPORT_11N | WIFI_SUPPORT_LEGACY;
8926 }
8927 else
8928 {
8929 network->wlan_capa = WIFI_SUPPORT_LEGACY;
8930 }
8931
8932 #if CONFIG_11AX
8933 if (network->wlan_capa & WIFI_SUPPORT_11AX)
8934 {
8935 network->dot11ax = 1;
8936 }
8937 #endif
8938 #if CONFIG_11AC
8939 if (network->wlan_capa & WIFI_SUPPORT_11AC)
8940 {
8941 network->dot11ac = 1;
8942 }
8943 #endif
8944 if (network->wlan_capa & WIFI_SUPPORT_11N)
8945 {
8946 network->dot11n = 1;
8947 }
8948 #else
8949 if (network->channel != 14)
8950 {
8951 #if CONFIG_11AX
8952 network->dot11ax = 1;
8953 #endif
8954 #if CONFIG_11AC
8955 network->dot11ac = 1;
8956 #endif
8957 network->dot11n = 1;
8958 }
8959 #endif
8960 }
8961
8962 #if CONFIG_WPA_SUPP
8963 #if CONFIG_WPA_SUPP_AP
8964 if (network->role == WLAN_BSS_ROLE_UAP)
8965 {
8966
8967 if (network->ht_capab == 0)
8968 {
8969 network->ht_capab = wifi_get_default_ht_capab();
8970 }
8971 #if CONFIG_11AC
8972 if (network->vht_capab == 0)
8973 {
8974 network->vht_capab = wifi_get_default_vht_capab();
8975 }
8976 if (network->vht_oper_chwidth == 0)
8977 {
8978 network->vht_oper_chwidth = 1;
8979 }
8980 #endif
8981 #if CONFIG_11AX
8982 if (network->he_oper_chwidth == 0)
8983 {
8984 network->he_oper_chwidth = 1;
8985 }
8986 #endif
8987 }
8988 #endif
8989 if (network->security.sae_groups == NULL)
8990 {
8991 network->security.sae_groups = wlan_string_dup("19");
8992 }
8993 #if CONFIG_DRIVER_OWE
8994 if (network->security.owe_groups == NULL)
8995 {
8996 network->security.owe_groups = wlan_string_dup("19");
8997 }
8998 #endif
8999 if (network->security.group_cipher == 0)
9000 {
9001 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9002 if (network->security.wpa3_sb_192 == 1U)
9003 {
9004 network->security.group_cipher = WLAN_CIPHER_GCMP_256;
9005 }
9006 else if (network->security.wpa3_sb == 1U)
9007 {
9008 network->security.group_cipher = WLAN_CIPHER_CCMP_256;
9009 }
9010 else
9011 #endif
9012 {
9013 network->security.group_cipher = WLAN_CIPHER_CCMP;
9014 }
9015 }
9016 else
9017 {
9018 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9019 if (network->security.wpa3_sb_192 == 1U)
9020 {
9021 if (network->security.group_cipher != WLAN_CIPHER_GCMP_256)
9022 {
9023 wlcm_e("Group cipher configuration not allowed");
9024 goto INVAL;
9025 }
9026 }
9027 else if (network->security.wpa3_sb == 1U)
9028 {
9029 if ((network->security.group_cipher != WLAN_CIPHER_GCMP_256) && (network->security.group_cipher != WLAN_CIPHER_CCMP_256) && (network->security.group_cipher != WLAN_CIPHER_GCMP) && (network->security.group_cipher != WLAN_CIPHER_CCMP))
9030 {
9031 wlcm_e("Group cipher configuration not allowed");
9032 goto INVAL;
9033 }
9034 }
9035 else
9036 #endif
9037 if (network->security.type != WLAN_SECURITY_NONE)
9038 {
9039 if ((network->security.group_cipher != WLAN_CIPHER_CCMP) && (network->security.group_cipher != WLAN_CIPHER_TKIP))
9040 {
9041 wlcm_e("Group cipher configuration not allowed");
9042 goto INVAL;
9043 }
9044 }
9045 else
9046 {
9047 wlcm_e("Group cipher configuration not allowed");
9048 goto INVAL;
9049 }
9050 }
9051
9052 if (network->security.pairwise_cipher == 0)
9053 {
9054 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9055 if (network->security.wpa3_sb_192 == 1U)
9056 {
9057 network->security.pairwise_cipher = WLAN_CIPHER_GCMP_256;
9058 }
9059 else if (network->security.wpa3_sb == 1U)
9060 {
9061 network->security.pairwise_cipher = WLAN_CIPHER_CCMP_256;
9062 }
9063 else
9064 #endif
9065 {
9066 network->security.pairwise_cipher = WLAN_CIPHER_CCMP;
9067 }
9068 }
9069 else
9070 {
9071 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9072 if (network->security.wpa3_sb_192 == 1U)
9073 {
9074 if (network->security.pairwise_cipher != WLAN_CIPHER_GCMP_256)
9075 {
9076 wlcm_e("Pairwise cipher configuration not allowed");
9077 goto INVAL;
9078 }
9079 }
9080 else if (network->security.wpa3_sb == 1U)
9081 {
9082 if ((network->security.pairwise_cipher != WLAN_CIPHER_GCMP_256) && (network->security.pairwise_cipher != WLAN_CIPHER_CCMP_256) && (network->security.pairwise_cipher != WLAN_CIPHER_GCMP) && (network->security.pairwise_cipher != WLAN_CIPHER_CCMP))
9083 {
9084 wlcm_e("Pairwise cipher configuration not allowed");
9085 goto INVAL;
9086 }
9087 }
9088 else
9089 #endif
9090 if (network->security.type != WLAN_SECURITY_NONE)
9091 {
9092 if ((network->security.pairwise_cipher != WLAN_CIPHER_CCMP) && (network->security.pairwise_cipher != WLAN_CIPHER_TKIP))
9093 {
9094 wlcm_e("Pairwise cipher configuration not allowed");
9095 goto INVAL;
9096 }
9097 }
9098 else
9099 {
9100 wlcm_e("Pairwise cipher configuration not allowed");
9101 goto INVAL;
9102 }
9103 }
9104
9105 if (network->security.group_mgmt_cipher == 0)
9106 {
9107 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9108 if (network->security.wpa3_sb_192 == 1U)
9109 {
9110 network->security.group_mgmt_cipher = WLAN_CIPHER_BIP_GMAC_256;
9111 }
9112 else if (network->security.wpa3_sb == 1U)
9113 {
9114 network->security.group_mgmt_cipher = WLAN_CIPHER_BIP_CMAC_256;
9115 }
9116 else
9117 #endif
9118 {
9119 network->security.group_mgmt_cipher = WLAN_CIPHER_AES_128_CMAC;
9120 }
9121 }
9122 else
9123 {
9124 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9125 if (network->security.wpa3_sb_192 == 1U)
9126 {
9127 if (network->security.group_mgmt_cipher != WLAN_CIPHER_BIP_GMAC_256)
9128 {
9129 wlcm_e("Group mgmt cipher configuration not allowed");
9130 goto INVAL;
9131 }
9132 }
9133 else if (network->security.wpa3_sb == 1U)
9134 {
9135 if ((network->security.group_mgmt_cipher != WLAN_CIPHER_BIP_GMAC_256) && (network->security.group_mgmt_cipher != WLAN_CIPHER_BIP_CMAC_256) && (network->security.group_mgmt_cipher != WLAN_CIPHER_BIP_GMAC_128) && (network->security.group_mgmt_cipher != WLAN_CIPHER_AES_128_CMAC))
9136 {
9137 wlcm_e("Group mgmt cipher configuration not allowed");
9138 goto INVAL;
9139 }
9140 }
9141 else
9142 #endif
9143 if (network->security.type != WLAN_SECURITY_NONE)
9144 {
9145 if (network->security.group_mgmt_cipher != WLAN_CIPHER_AES_128_CMAC)
9146 {
9147 wlcm_e("Group mgmt cipher configuration not allowed");
9148 goto INVAL;
9149 }
9150 }
9151 else
9152 {
9153 wlcm_e("Group mgmt cipher configuration not allowed");
9154 goto INVAL;
9155 }
9156 }
9157
9158 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9159 if (
9160 #if CONFIG_EAP_TLS
9161 (wlan_is_eap_tls_security(network->security.type)) ||
9162 #endif
9163 #if CONFIG_EAP_TTLS
9164 (wlan_is_eap_ttls_security(network->security.type)) ||
9165 #endif
9166 #if CONFIG_EAP_PEAP
9167 (wlan_is_eap_peap_security(network->security.type)) ||
9168 #endif
9169 #if CONFIG_EAP_FAST
9170 (wlan_is_eap_fast_security(network->security.type)) ||
9171 #endif
9172 false)
9173 {
9174 #if CONFIG_WPA_SUPP_AP
9175 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
9176 if (network->role == WLAN_BSS_ROLE_UAP)
9177 {
9178 /* Specify CA certificate */
9179 network->security.ca_cert_len =
9180 wlan_get_entp_cert_files(FILE_TYPE_ENTP_CA_CERT, &network->security.ca_cert_data);
9181 if (network->security.ca_cert_len == 0)
9182 {
9183 wlan_free_entp_cert_files();
9184 wlcm_e("CA cert is not configured");
9185 goto INVAL;
9186 }
9187
9188 /* Specify Server certificate */
9189 network->security.server_cert_len =
9190 wlan_get_entp_cert_files(FILE_TYPE_ENTP_SERVER_CERT, &network->security.server_cert_data);
9191 if (network->security.server_cert_len == 0)
9192 {
9193 wlan_free_entp_cert_files();
9194 #if CONFIG_WIFI_USB_FILE_ACCESS
9195 OSA_MemoryFree(network->security.ca_cert_data);
9196 #endif
9197 wlcm_e("Server cert is not configured");
9198 goto INVAL;
9199 }
9200 /* Specify Server key */
9201 network->security.server_key_len =
9202 wlan_get_entp_cert_files(FILE_TYPE_ENTP_SERVER_KEY, &network->security.server_key_data);
9203 if (network->security.server_key_len == 0)
9204 {
9205 wlan_free_entp_cert_files();
9206 #if CONFIG_WIFI_USB_FILE_ACCESS
9207 OSA_MemoryFree(network->security.ca_cert_data);
9208 OSA_MemoryFree(network->security.server_cert_data);
9209 #endif
9210 wlcm_e("Server key is not configured");
9211 goto INVAL;
9212 }
9213 /* Specify DH params */
9214 network->security.dh_len = wlan_get_entp_cert_files(FILE_TYPE_ENTP_DH_PARAMS, &network->security.dh_data);
9215 if (network->security.dh_len == 0)
9216 {
9217 wlan_free_entp_cert_files();
9218 #if CONFIG_WIFI_USB_FILE_ACCESS
9219 OSA_MemoryFree(network->security.ca_cert_data);
9220 OSA_MemoryFree(network->security.server_cert_data);
9221 OSA_MemoryFree(network->security.server_key_data);
9222 #endif
9223 wlcm_e("DH params are not configured");
9224 goto INVAL;
9225 }
9226
9227 #if CONFIG_EAP_FAST
9228 if (wlan_is_eap_fast_security(network->security.type))
9229 {
9230 if (strlen(network->security.pac_opaque_encr_key) != (PAC_OPAQUE_ENCR_KEY_MAX_LENGTH - 1))
9231 {
9232 wlcm_e("Invalid PAC Opaque Encryption key");
9233 goto INVAL;
9234 }
9235 if (strlen(network->security.a_id) != (A_ID_MAX_LENGTH - 1))
9236 {
9237 wlcm_e("Invalid authority identity(a_id)");
9238 goto INVAL;
9239 }
9240 }
9241 #endif
9242 }
9243 else
9244 #endif
9245 #endif
9246 {
9247 if (false == wlan_is_skip_cert_cfg(network->security.type))
9248 {
9249 /* Specify CA certificate */
9250 network->security.ca_cert_len =
9251 wlan_get_entp_cert_files(FILE_TYPE_ENTP_CA_CERT, &network->security.ca_cert_data);
9252 if (network->security.ca_cert_len == 0)
9253 {
9254 wlan_free_entp_cert_files();
9255 wlcm_e("CA cert is not configured");
9256 goto INVAL;
9257 }
9258
9259 /* Specify Client certificate */
9260 network->security.client_cert_len =
9261 wlan_get_entp_cert_files(FILE_TYPE_ENTP_CLIENT_CERT, &network->security.client_cert_data);
9262 if (network->security.client_cert_len == 0)
9263 {
9264 wlan_free_entp_cert_files();
9265 #if CONFIG_WIFI_USB_FILE_ACCESS
9266 OSA_MemoryFree(network->security.ca_cert_data);
9267 #endif
9268 wlcm_e("Client cert is not configured");
9269 goto INVAL;
9270 }
9271 /* Specify Client key */
9272 network->security.client_key_len =
9273 wlan_get_entp_cert_files(FILE_TYPE_ENTP_CLIENT_KEY, &network->security.client_key_data);
9274 if (network->security.client_key_len == 0)
9275 {
9276 wlan_free_entp_cert_files();
9277 #if CONFIG_WIFI_USB_FILE_ACCESS
9278 OSA_MemoryFree(network->security.ca_cert_data);
9279 OSA_MemoryFree(network->security.client_cert_data);
9280 #endif
9281 wlcm_e("Client key is not configured");
9282 goto INVAL;
9283 }
9284 }
9285 }
9286 #ifdef CONFIG_EAP_TTLS
9287 if (WLAN_SECURITY_EAP_TTLS == network->security.type)
9288 {
9289 if (network->role == WLAN_BSS_ROLE_STA)
9290 {
9291
9292 /* Specify CA certificate2 */
9293 network->security.ca_cert2_len =
9294 wlan_get_entp_cert_files(FILE_TYPE_ENTP_CA_CERT2, &network->security.ca_cert2_data);
9295 if (network->security.ca_cert2_len == 0)
9296 {
9297 wlan_free_entp_cert_files();
9298 #if CONFIG_WIFI_USB_FILE_ACCESS
9299 OSA_MemoryFree(network->security.ca_cert_data);
9300 OSA_MemoryFree(network->security.client_cert_data);
9301 OSA_MemoryFree(network->security.client_key_data);
9302 #endif
9303 wlcm_e("CA cert2 is not configured");
9304 goto INVAL;
9305 }
9306 /* Specify Client certificate2 */
9307 network->security.client_cert2_len =
9308 wlan_get_entp_cert_files(FILE_TYPE_ENTP_CLIENT_CERT, &network->security.client_cert2_data);
9309 if (network->security.client_cert2_len == 0)
9310 {
9311 wlan_free_entp_cert_files();
9312 #if CONFIG_WIFI_USB_FILE_ACCESS
9313 OSA_MemoryFree(network->security.ca_cert_data);
9314 OSA_MemoryFree(network->security.client_cert_data);
9315 OSA_MemoryFree(network->security.client_key_data);
9316 OSA_MemoryFree(network->security.ca_cert2_data);
9317 #endif
9318 wlcm_e("Client cert2 is not configured");
9319 goto INVAL;
9320 }
9321 /* Specify Client key2 */
9322 network->security.client_key2_len =
9323 wlan_get_entp_cert_files(FILE_TYPE_ENTP_CLIENT_KEY, &network->security.client_key2_data);
9324 if (network->security.client_key_len == 0)
9325 {
9326 wlan_free_entp_cert_files();
9327 #if CONFIG_WIFI_USB_FILE_ACCESS
9328 OSA_MemoryFree(network->security.ca_cert_data);
9329 OSA_MemoryFree(network->security.client_cert_data);
9330 OSA_MemoryFree(network->security.client_key_data);
9331 OSA_MemoryFree(network->security.ca_cert2_data);
9332 OSA_MemoryFree(network->security.client_cert2_data);
9333 #endif
9334 wlcm_e("Client key2 is not configured");
9335 goto INVAL;
9336 }
9337 }
9338 }
9339 #endif
9340 }
9341 #endif
9342 #endif
9343 /* Find a slot for the new network but check all existing networks in
9344 * case the new one has a duplicate name, which is not allowed. */
9345 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
9346 {
9347 if (wlan.networks[i].name[0] != '\0')
9348 {
9349 if (strlen(wlan.networks[i].name) == len && !strncmp(wlan.networks[i].name, network->name, len))
9350 {
9351 goto INVAL;
9352 }
9353 }
9354 else if (pos == -1)
9355 {
9356 pos = i;
9357 }
9358 else
9359 { /* Do Nothing */
9360 }
9361 }
9362
9363 if (pos < 0)
9364 {
9365 if (network->security.sae_groups)
9366 {
9367 OSA_MemoryFree(network->security.sae_groups);
9368 network->security.sae_groups = NULL;
9369 }
9370 #if CONFIG_DRIVER_OWE
9371 if (network->security.owe_groups)
9372 {
9373 OSA_MemoryFree(network->security.owe_groups);
9374 network->security.owe_groups = NULL;
9375 }
9376 #endif
9377 return -WM_E_NOMEM;
9378 }
9379
9380 wlan.networks[pos].dtim_period = network->dtim_period;
9381 wlan.networks[pos].acs_band = network->acs_band;
9382 /* save and set private fields */
9383 (void)memcpy((void *)&wlan.networks[pos], (const void *)network, sizeof(struct wlan_network));
9384 wlan.networks[pos].ssid_specific = (uint8_t)(network->ssid[0] != '\0');
9385 wlan.networks[pos].bssid_specific = (uint8_t)!is_bssid_any(network->bssid);
9386 wlan.networks[pos].channel_specific = (uint8_t)(network->channel != 0U);
9387 if (wlan.networks[pos].channel_specific == 1U)
9388 {
9389 #if CONFIG_5GHz_SUPPORT
9390 if (network->channel > MAX_CHANNELS_BG)
9391 {
9392 wlan.networks[pos].acs_band = 1;
9393 }
9394 else
9395 #endif
9396 {
9397 wlan.networks[pos].acs_band = 0;
9398 }
9399 }
9400
9401 if (network->security.type != WLAN_SECURITY_WILDCARD)
9402 {
9403 wlan.networks[pos].security_specific = 1;
9404 }
9405
9406 #if !CONFIG_WPA_SUPP
9407 if ((network->role == WLAN_BSS_ROLE_STA) &&
9408 (network->security.type != WLAN_SECURITY_NONE && network->security.type != WLAN_SECURITY_WEP_OPEN))
9409 {
9410 ret = wifi_send_clear_wpa_psk((int)network->role, network->ssid);
9411 if (ret != WM_SUCCESS)
9412 {
9413 return WLAN_ERROR_ACTION;
9414 }
9415 #if CONFIG_WLAN_BRIDGE
9416 if (network->bridge_ssid)
9417 {
9418 ret = wifi_send_clear_wpa_psk((int)network->role, network->bridge_ssid);
9419 if (ret != WM_SUCCESS)
9420 return WLAN_ERROR_ACTION;
9421 }
9422 #endif
9423 #if CONFIG_HOST_PMK
9424 if ((network->security.type != WLAN_SECURITY_OWE_ONLY) && (network->security.type != WLAN_SECURITY_WPA3_SAE))
9425 {
9426 ret = mrvl_generate_psk(network->ssid, strlen(network->ssid), network->security.psk,
9427 wlan.networks[pos].security.pmk);
9428
9429 if (ret == WM_SUCCESS)
9430 wlan.networks[pos].security.pmk_valid = true;
9431 }
9432
9433 #if CONFIG_WLAN_BRIDGE
9434 if (network->bridge_ssid)
9435 {
9436 ret = mrvl_generate_psk(network->bridge_ssid, strlen(network->bridge_ssid), network->security.bridge_psk,
9437 wlan.networks[pos].security.bridge_pmk);
9438
9439 if (ret == WM_SUCCESS)
9440 wlan.networks[pos].security.bridge_pmk_valid = true;
9441 }
9442 #endif
9443 #endif
9444 }
9445 #endif
9446 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
9447 #if CONFIG_WPA_SUPP
9448 #if CONFIG_WPA_SUPP_WPS
9449 if (!wlan.wps_session_attempt)
9450 {
9451 #endif
9452 ret = wpa_supp_add_network(netif, &wlan.networks[pos]);
9453 if (ret < 0)
9454 {
9455 wlan_remove_network(wlan.networks[pos].name);
9456 return -WM_E_NOMEM;
9457 }
9458 #if CONFIG_WPA_SUPP_WPS
9459 }
9460 #endif
9461 #endif
9462 #endif
9463 wlan.num_networks++;
9464 #if CONFIG_WLAN_FAST_PATH
9465 /* On station network addition,
9466 * flush the FP cache since the index changes */
9467 if (network->role == WLAN_BSS_ROLE_STA)
9468 {
9469 wlan.auth_cache_valid = false;
9470 wlan.fast_path_cache_valid = false;
9471 }
9472 #endif /* CONFIG_WLAN_FAST_PATH */
9473
9474 return WM_SUCCESS;
9475
9476 INVAL:
9477 if (network->security.sae_groups)
9478 {
9479 OSA_MemoryFree(network->security.sae_groups);
9480 network->security.sae_groups = NULL;
9481 }
9482 #if CONFIG_DRIVER_OWE
9483 if (network->security.owe_groups)
9484 {
9485 OSA_MemoryFree(network->security.owe_groups);
9486 network->security.owe_groups = NULL;
9487 }
9488 #endif
9489 return -WM_E_INVAL;
9490 }
9491
9492 #if CONFIG_WIFI_CAPA
wlan_check_11n_capa(unsigned int channel)9493 uint8_t wlan_check_11n_capa(unsigned int channel)
9494 {
9495 uint8_t enable_11n = false;
9496 uint16_t fw_bands = 0U;
9497
9498 wifi_get_fw_info(MLAN_BSS_TYPE_UAP, &fw_bands);
9499
9500 if (channel > 14 && (fw_bands & BAND_AN))
9501 {
9502 enable_11n = true;
9503 }
9504 else if (channel <= 14 && (fw_bands & BAND_GN))
9505 {
9506 enable_11n = true;
9507 }
9508 return enable_11n;
9509 }
9510
wlan_check_11ac_capa(unsigned int channel)9511 uint8_t wlan_check_11ac_capa(unsigned int channel)
9512 {
9513 uint8_t enable_11ac = false;
9514 uint16_t fw_bands = 0U;
9515
9516 wifi_get_fw_info(MLAN_BSS_TYPE_UAP, &fw_bands);
9517
9518 #if CONFIG_11AC
9519 if (channel > 14 && (fw_bands & BAND_AAC))
9520 {
9521 enable_11ac = true;
9522 }
9523 else if (channel <= 14 && (fw_bands & BAND_GAC))
9524 {
9525 enable_11ac = true;
9526 }
9527 #endif
9528 return enable_11ac;
9529 }
9530
wlan_check_11ax_capa(unsigned int channel)9531 uint8_t wlan_check_11ax_capa(unsigned int channel)
9532 {
9533 uint8_t enable_11ax = false;
9534 uint16_t fw_bands = 0U;
9535
9536 wifi_get_fw_info(MLAN_BSS_TYPE_UAP, &fw_bands);
9537
9538 #if CONFIG_11AX
9539 if (channel > 14 && (fw_bands & BAND_AAX))
9540 {
9541 enable_11ax = true;
9542 }
9543 else if (channel <= 14 && (fw_bands & BAND_GAX))
9544 {
9545 enable_11ax = true;
9546 }
9547 #endif
9548 return enable_11ax;
9549 }
9550 #endif
9551
wlan_remove_network(const char * name)9552 int wlan_remove_network(const char *name)
9553 {
9554 unsigned int len, i;
9555 #if CONFIG_WPA_SUPP
9556 struct netif *netif = net_get_sta_interface();
9557 #endif
9558
9559 if (!is_running())
9560 {
9561 return WLAN_ERROR_STATE;
9562 }
9563
9564 if (name == NULL)
9565 {
9566 return -WM_E_INVAL;
9567 }
9568
9569 len = strlen(name);
9570
9571 /* find the first network whose name matches and clear it out */
9572 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
9573 {
9574 if (wlan.networks[i].name[0] != '\0' && strlen(wlan.networks[i].name) == len &&
9575 !strncmp(wlan.networks[i].name, name, len))
9576 {
9577 if (false == wlan_in_reset)
9578 {
9579 if (wlan.running && wlan.cur_network_idx == i)
9580 {
9581 #if CONFIG_WLAN_FAST_PATH
9582 /* On station network removal,
9583 * flush the FP cache since the index changes */
9584 wlan.auth_cache_valid = false;
9585 wlan.fast_path_cache_valid = false;
9586 #endif /* CONFIG_WLAN_FAST_PATH */
9587 return WLAN_ERROR_STATE;
9588 }
9589 if (wlan.cur_uap_network_idx == i)
9590 {
9591 return WLAN_ERROR_STATE;
9592 }
9593 }
9594 #if CONFIG_WPA2_ENTP
9595 if (wlan.networks[i].security.tls_cert.ca_chain)
9596 {
9597 wm_mbedtls_free_cert(wlan.networks[i].security.tls_cert.ca_chain);
9598 }
9599 if (wlan.networks[i].security.tls_cert.own_cert)
9600 {
9601 wm_mbedtls_free_cert(wlan.networks[i].security.tls_cert.own_cert);
9602 }
9603 if (wlan.networks[i].security.tls_cert.own_key)
9604 {
9605 wm_mbedtls_free_key(wlan.networks[i].security.tls_cert.own_key);
9606 }
9607 #endif
9608 #if CONFIG_WPA_SUPP
9609 if (wlan.networks[i].role == WLAN_BSS_ROLE_STA)
9610 {
9611 netif = net_get_sta_interface();
9612 }
9613 else if (wlan.networks[i].role == WLAN_BSS_ROLE_UAP)
9614 {
9615 netif = net_get_uap_interface();
9616 }
9617 else
9618 {
9619 /* Do nothing */
9620 }
9621 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
9622 wpa_supp_remove_network(netif, &wlan.networks[i]);
9623 #endif
9624
9625 if (wlan.networks[i].security.sae_groups)
9626 {
9627 OSA_MemoryFree(wlan.networks[i].security.sae_groups);
9628 wlan.networks[i].security.sae_groups = NULL;
9629 }
9630 #if CONFIG_DRIVER_OWE
9631 if (wlan.networks[i].security.owe_groups)
9632 {
9633 OSA_MemoryFree(wlan.networks[i].security.owe_groups);
9634 wlan.networks[i].security.owe_groups = NULL;
9635 }
9636 #endif
9637 #if CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE
9638 #if CONFIG_WIFI_USB_FILE_ACCESS
9639 if (wlan.networks[i].role == WLAN_BSS_ROLE_STA)
9640 {
9641 if (wlan.networks[i].security.ca_cert_data)
9642 {
9643 OSA_MemoryFree(wlan.networks[i].security.ca_cert_data);
9644 }
9645 if (wlan.networks[i].security.client_cert_data)
9646 {
9647 OSA_MemoryFree(wlan.networks[i].security.client_cert_data);
9648 }
9649 if (wlan.networks[i].security.client_key_data)
9650 {
9651 OSA_MemoryFree(wlan.networks[i].security.client_key_data);
9652 }
9653 if (wlan.networks[i].security.ca_cert2_data)
9654 {
9655 OSA_MemoryFree(wlan.networks[i].security.ca_cert2_data);
9656 }
9657 if (wlan.networks[i].security.client_cert2_data)
9658 {
9659 OSA_MemoryFree(wlan.networks[i].security.client_cert2_data);
9660 }
9661 if (wlan.networks[i].security.client_key2_data)
9662 {
9663 OSA_MemoryFree(wlan.networks[i].security.client_key2_data);
9664 }
9665 }
9666 #if CONFIG_WPA_SUPP_AP
9667 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
9668 else if (wlan.networks[i].role == WLAN_BSS_ROLE_UAP)
9669 {
9670 if (wlan.networks[i].security.ca_cert_data)
9671 {
9672 OSA_MemoryFree(wlan.networks[i].security.ca_cert_data);
9673 }
9674 if (wlan.networks[i].security.server_cert_data)
9675 {
9676 OSA_MemoryFree(wlan.networks[i].security.server_cert_data);
9677 }
9678 if (wlan.networks[i].security.server_key_data)
9679 {
9680 OSA_MemoryFree(wlan.networks[i].security.server_key_data);
9681 }
9682 }
9683 #endif
9684 #endif
9685 #endif
9686 #endif
9687 #if CONFIG_WPA_SUPP_DPP
9688 if (wlan.networks[i].security.dpp_connector)
9689 {
9690 OSA_MemoryFree(wlan.networks[i].security.dpp_connector);
9691 }
9692 if (wlan.networks[i].security.dpp_c_sign_key)
9693 {
9694 OSA_MemoryFree(wlan.networks[i].security.dpp_c_sign_key);
9695 }
9696 if (wlan.networks[i].security.dpp_net_access_key)
9697 {
9698 OSA_MemoryFree(wlan.networks[i].security.dpp_net_access_key);
9699 }
9700 #endif
9701 #endif
9702 (void)memset(&wlan.networks[i], 0, sizeof(struct wlan_network));
9703 wlan.num_networks--;
9704 return WM_SUCCESS;
9705 }
9706 }
9707 /* network name wasn't found */
9708 return -WM_E_INVAL;
9709 }
9710
wlan_get_network_count(unsigned int * count)9711 int wlan_get_network_count(unsigned int *count)
9712 {
9713 if (count == NULL)
9714 {
9715 return -WM_E_INVAL;
9716 }
9717
9718 *count = wlan.num_networks;
9719 return WM_SUCCESS;
9720 }
9721
wlan_get_current_network(struct wlan_network * network)9722 int wlan_get_current_network(struct wlan_network *network)
9723 {
9724 short rssi;
9725 int snr;
9726
9727 if (network == NULL)
9728 {
9729 return -WM_E_INVAL;
9730 }
9731
9732 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED) || is_state(CM_STA_AUTHENTICATED)))
9733 {
9734 (void)memcpy((void *)network, (const void *)&wlan.networks[wlan.cur_network_idx], sizeof(struct wlan_network));
9735
9736 wlan_get_current_signal_strength(&rssi, &snr);
9737
9738 network->rssi = rssi;
9739
9740 return WM_SUCCESS;
9741 }
9742
9743 return WLAN_ERROR_STATE;
9744 }
9745
wlan_get_current_network_ssid(char * ssid)9746 int wlan_get_current_network_ssid(char *ssid)
9747 {
9748 if (ssid == NULL)
9749 {
9750 return -WM_E_INVAL;
9751 }
9752
9753 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED) || is_state(CM_STA_AUTHENTICATED)))
9754 {
9755 (void)memcpy((void *)ssid, (const void *)&wlan.networks[wlan.cur_network_idx].ssid, IEEEtypes_SSID_SIZE + 1);
9756
9757 return WM_SUCCESS;
9758 }
9759
9760 return WLAN_ERROR_STATE;
9761 }
9762
wlan_get_current_network_bssid(char * bssid)9763 int wlan_get_current_network_bssid(char *bssid)
9764 {
9765 if (bssid == NULL)
9766 {
9767 return -WM_E_INVAL;
9768 }
9769
9770 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
9771 struct netif *netif = net_get_sta_interface();
9772 struct wifi_iface_status status;
9773
9774 memset(&status, 0x0, sizeof(status));
9775 supplicant_status(net_if_get_device((void *)netif), &status);
9776 memcpy(bssid, status.bssid, MLAN_MAC_ADDR_LENGTH);
9777 return WM_SUCCESS;
9778 #else
9779 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED)))
9780 {
9781 (void)memcpy((void *)bssid, (const void *)&wlan.networks[wlan.cur_network_idx].bssid, IEEEtypes_ADDRESS_SIZE);
9782
9783 return WM_SUCCESS;
9784 }
9785
9786 return WLAN_ERROR_STATE;
9787 #endif
9788 }
9789
wlan_get_current_uap_network(struct wlan_network * network)9790 int wlan_get_current_uap_network(struct wlan_network *network)
9791 {
9792 if (network == NULL)
9793 {
9794 return -WM_E_INVAL;
9795 }
9796
9797 if (wlan.running && (is_uap_state(CM_UAP_IP_UP) || is_uap_state(CM_UAP_STARTED)))
9798 {
9799 (void)memcpy((void *)network, (const void *)&wlan.networks[wlan.cur_uap_network_idx],
9800 sizeof(struct wlan_network));
9801 return WM_SUCCESS;
9802 }
9803 return WLAN_ERROR_STATE;
9804 }
9805
wlan_get_current_uap_network_ssid(char * ssid)9806 int wlan_get_current_uap_network_ssid(char *ssid)
9807 {
9808 if (ssid == NULL)
9809 {
9810 return -WM_E_INVAL;
9811 }
9812
9813 if (wlan.running && (is_uap_state(CM_UAP_IP_UP) || is_uap_state(CM_UAP_STARTED)))
9814 {
9815 (void)memcpy((void *)ssid, (const void *)&wlan.networks[wlan.cur_uap_network_idx].ssid, IEEEtypes_SSID_SIZE + 1);
9816
9817 return WM_SUCCESS;
9818 }
9819
9820 return WLAN_ERROR_STATE;
9821 }
9822
9823 #if CONFIG_SCAN_WITH_RSSIFILTER
wlan_set_rssi_threshold(int rssithr)9824 int wlan_set_rssi_threshold(int rssithr)
9825 {
9826 if (rssithr)
9827 wlan.networks[wlan.cur_network_idx].rssi_threshold = (rssithr < 0 ? rssithr : 0);
9828
9829 return WM_SUCCESS;
9830 }
9831 #endif
9832
is_uap_started(void)9833 bool is_uap_started(void)
9834 {
9835 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
9836 int state = wifi_nxp_hapd_state();
9837
9838 return (state == HAPD_IFACE_ENABLED);
9839 #else
9840 return is_uap_state(CM_UAP_IP_UP);
9841 #endif
9842 }
9843
is_sta_connected(void)9844 bool is_sta_connected(void)
9845 {
9846 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
9847 int state = wifi_nxp_supp_state();
9848
9849 return (state == WPA_COMPLETED);
9850 #else
9851 return (wlan.sta_state == CM_STA_CONNECTED);
9852 #endif
9853 }
9854
is_sta_ipv4_connected(void)9855 bool is_sta_ipv4_connected(void)
9856 {
9857 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
9858 int ip = 0;
9859 net_get_if_ip_addr(&ip, net_get_sta_handle());
9860 return (ip == 0 ? false : true);
9861 #else
9862 return (wlan.sta_ipv4_state == CM_STA_CONNECTED);
9863 #endif
9864 }
9865
9866 #if CONFIG_IPV6
is_sta_ipv6_connected(void)9867 bool is_sta_ipv6_connected(void)
9868 {
9869 return (wlan.sta_ipv6_state == CM_STA_CONNECTED);
9870 }
9871 #endif
9872
wlan_get_network(unsigned int index,struct wlan_network * network)9873 int wlan_get_network(unsigned int index, struct wlan_network *network)
9874 {
9875 unsigned int i;
9876 int pos = -1;
9877
9878 if (network == NULL || index > ARRAY_SIZE(wlan.networks))
9879 {
9880 return -WM_E_INVAL;
9881 }
9882
9883 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
9884 {
9885 ++pos;
9886 if (wlan.networks[i].name[0] != '\0' && pos == (int)index)
9887 {
9888 copy_network(network, &wlan.networks[i]);
9889 return WM_SUCCESS;
9890 }
9891 }
9892
9893 return -WM_E_INVAL;
9894 }
9895
wlan_get_current_nf(void)9896 int wlan_get_current_nf(void)
9897 {
9898 return -g_data_nf_last;
9899 }
9900
wlan_get_current_signal_strength(short * rssi,int * snr)9901 int wlan_get_current_signal_strength(short *rssi, int *snr)
9902 {
9903 wifi_rssi_info_t rssi_info;
9904 (void)wifi_send_rssi_info_cmd(&rssi_info);
9905
9906 *snr = rssi_info.bcn_rssi_last - rssi_info.bcn_nf_last;
9907 *rssi = rssi_info.bcn_rssi_last;
9908 return WM_SUCCESS;
9909 }
9910
wlan_get_average_signal_strength(short * rssi,int * snr)9911 int wlan_get_average_signal_strength(short *rssi, int *snr)
9912 {
9913 wifi_rssi_info_t rssi_info;
9914 (void)wifi_send_rssi_info_cmd(&rssi_info);
9915
9916 *snr = rssi_info.bcn_snr_avg;
9917 *rssi = rssi_info.bcn_rssi_avg;
9918 return WM_SUCCESS;
9919 }
9920
wlan_get_current_rssi(short * rssi)9921 int wlan_get_current_rssi(short *rssi)
9922 {
9923 g_rssi = (uint8_t)(g_data_snr_last - g_data_nf_last);
9924 *rssi = (short)(g_rssi - 256U);
9925 return WM_SUCCESS;
9926 }
9927
wlan_get_network_byname(char * name,struct wlan_network * network)9928 int wlan_get_network_byname(char *name, struct wlan_network *network)
9929 {
9930 unsigned int i;
9931
9932 if (network == NULL || name == NULL)
9933 {
9934 return -WM_E_INVAL;
9935 }
9936
9937 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
9938 {
9939 if (wlan.networks[i].name[0] != '\0' && !strcmp(wlan.networks[i].name, name))
9940 {
9941 copy_network(network, &wlan.networks[i]);
9942 return WM_SUCCESS;
9943 }
9944 }
9945
9946 return -WM_E_INVAL;
9947 }
9948
wlan_set_network_ip_byname(char * name,struct wlan_ip_config * ip)9949 int wlan_set_network_ip_byname(char *name, struct wlan_ip_config *ip)
9950 {
9951 unsigned int i;
9952
9953 if (ip == NULL || name == NULL)
9954 {
9955 return -WM_E_INVAL;
9956 }
9957
9958 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
9959 {
9960 if (wlan.networks[i].name[0] != '\0' && !strcmp(wlan.networks[i].name, name))
9961 {
9962 memcpy(&(wlan.networks[i].ip), ip, sizeof(struct wlan_ip_config));
9963 return WM_SUCCESS;
9964 }
9965 }
9966
9967 return -WM_E_INVAL;
9968 }
9969
wlan_remove_all_network_profiles(void)9970 int wlan_remove_all_network_profiles(void)
9971 {
9972 unsigned int i;
9973 int ret;
9974
9975 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
9976 {
9977 if (wlan.networks[i].name[0] != '\0')
9978 {
9979 ret = wlan_remove_network(wlan.networks[i].name);
9980 if (ret != WM_SUCCESS)
9981 {
9982 return -WM_E_INVAL;
9983 }
9984 }
9985 }
9986
9987 return WM_SUCCESS;
9988 }
9989
wlan_disconnect(void)9990 int wlan_disconnect(void)
9991 {
9992 if (!wlan.running)
9993 {
9994 return WLAN_ERROR_STATE;
9995 }
9996
9997 #if CONFIG_HOST_SLEEP
9998 wakelock_get();
9999 #endif
10000
10001 (void)send_user_request(CM_STA_USER_REQUEST_DISCONNECT, 0);
10002
10003 #if CONFIG_ECSA
10004 /*Wait for sta to enter the disconnect state, and then send ECSA cmd*/
10005 OSA_TimeDelay(1000);
10006 wrapper_clear_media_connected_event();
10007 wlan_switch_to_nondfs_channel();
10008 #endif
10009
10010 return WM_SUCCESS;
10011 }
10012
wlan_connect(char * name)10013 int wlan_connect(char *name)
10014 {
10015 unsigned int len = name != NULL ? strlen(name) : 0U;
10016 int i = 0, ret;
10017
10018 if (!wlan.running)
10019 {
10020 return WLAN_ERROR_STATE;
10021 }
10022
10023 if (wlan.num_networks == 0U || len == 0U)
10024 {
10025 return -WM_E_INVAL;
10026 }
10027
10028 #if CONFIG_WPA_SUPP
10029 #if CONFIG_WPA_SUPP_WPS
10030 if (wlan.wps_session_attempt)
10031 {
10032 wlcm_d("WPS session is in progress");
10033 return WLAN_ERROR_STATE;
10034 }
10035 #endif
10036 #endif
10037
10038 wlan.roam_reassoc = false;
10039
10040 /* connect to a specific network */
10041 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
10042 {
10043 if (wlan.networks[i].name[0] != '\0' && strlen(wlan.networks[i].name) == len &&
10044 !strncmp(wlan.networks[i].name, name, len))
10045 {
10046 switch (wlan.networks[i].role)
10047 {
10048 case MLAN_BSS_ROLE_UAP:
10049 wlcm_e("Invalid bss role. Bss role is uap.");
10050 ret = WLAN_ERROR_PARAM;
10051 break;
10052 case MLAN_BSS_ROLE_ANY:
10053 wlcm_e("Invalid bss role. Bss role is any.");
10054 ret = WLAN_ERROR_PARAM;
10055 break;
10056 default:
10057 ret = WLAN_ERROR_NONE;
10058 break;
10059 }
10060
10061 if(ret != WLAN_ERROR_NONE)
10062 return ret;
10063
10064 wlcm_d("taking the scan lock (connect scan)");
10065 dbg_lock_info();
10066 ret = OSA_SemaphoreWait((osa_semaphore_handle_t)wlan.scan_lock, osaWaitForever_c);
10067 if (ret != WM_SUCCESS)
10068 {
10069 wlcm_e("failed to get scan lock: 0x%X", ret);
10070 return WLAN_ERROR_ACTION;
10071 }
10072 wlcm_d("got the scan lock (connect scan)");
10073 wlan.is_scan_lock = 1;
10074 /* Reset reassoc count as this is set to WLAN_RECONNECT_LIMIT
10075 * during disconnect */
10076 wlan.reassoc_count = 0;
10077
10078 return send_user_request(CM_STA_USER_REQUEST_CONNECT, i);
10079 }
10080 }
10081
10082 /* specified network was not found */
10083 return -WM_E_INVAL;
10084 }
10085
wlan_connect_opt(char * name,bool skip_dfs)10086 int wlan_connect_opt(char *name, bool skip_dfs)
10087 {
10088 int ret = 0;
10089
10090 mlan_adap->skip_dfs = false;
10091 if(skip_dfs)
10092 mlan_adap->skip_dfs = true;
10093
10094 ret = wlan_connect(name);
10095 if(ret != WM_SUCCESS)
10096 {
10097 mlan_adap->skip_dfs = false;
10098 }
10099
10100 return ret;
10101 }
10102
wlan_reassociate()10103 int wlan_reassociate()
10104 {
10105 int ret;
10106
10107 if (!wlan.running)
10108 {
10109 return WLAN_ERROR_STATE;
10110 }
10111
10112 if (wlan.num_networks == 0U)
10113 {
10114 return -WM_E_INVAL;
10115 }
10116
10117 if (!is_sta_connected())
10118 {
10119 wlcm_d("Error: sta connection is required before sending reassociate request");
10120 return WLAN_ERROR_STATE;
10121 }
10122
10123 #if CONFIG_WPA_SUPP
10124 #if CONFIG_WPA_SUPP_WPS
10125 if (wlan.wps_session_attempt)
10126 {
10127 wlcm_d("WPS session is in progress");
10128 return WLAN_ERROR_STATE;
10129 }
10130 #endif
10131 #endif
10132
10133 wlcm_d("taking the scan lock (reassociate scan)");
10134 dbg_lock_info();
10135 ret = OSA_SemaphoreWait((osa_semaphore_handle_t)wlan.scan_lock, osaWaitForever_c);
10136 if (ret != WM_SUCCESS)
10137 {
10138 wlcm_e("failed to get scan lock: 0x%X", ret);
10139 return WLAN_ERROR_ACTION;
10140 }
10141 wlcm_d("got the scan lock (reassociate scan)");
10142 wlan.is_scan_lock = 1;
10143
10144 wlan.roam_reassoc = true;
10145
10146 ret = send_user_request(CM_STA_USER_REQUEST_CONNECT, wlan.cur_network_idx);
10147 if (ret != WM_SUCCESS)
10148 {
10149 wlcm_d("Error: Reassociate failed");
10150 wlan.roam_reassoc = false;
10151 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan.scan_lock);
10152 wlan.is_scan_lock = 0;
10153 }
10154
10155 return ret;
10156 }
10157
wlan_start_network(const char * name)10158 int wlan_start_network(const char *name)
10159 {
10160 unsigned int i;
10161 unsigned int len;
10162
10163 if (name == NULL)
10164 {
10165 return -WM_E_INVAL;
10166 }
10167
10168 len = strlen(name);
10169 if (len == 0 || wlan.num_networks == 0U)
10170 {
10171 return -WM_E_INVAL;
10172 }
10173
10174 if (is_uap_started() != 0)
10175 {
10176 wlcm_e(
10177 "%s network cannot be started, "
10178 "as the uAP is already running",
10179 name);
10180 return WLAN_ERROR_STATE;
10181 }
10182
10183 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
10184 {
10185 if (wlan.networks[i].name[0] != '\0' && strlen(wlan.networks[i].name) == len &&
10186 !strncmp(wlan.networks[i].name, name, len) && (wlan.networks[i].role == WLAN_BSS_ROLE_UAP) &&
10187 wlan.networks[i].ssid_specific)
10188 {
10189 #if CONFIG_MULTI_CHAN
10190 /* when multi-channel is enabled, uap and sta can start on different channel */
10191 if (wifi_get_mc_policy() == 0)
10192 #endif
10193 {
10194 if ((wlan.networks[i].channel_specific) && (wlan.networks[i].channel != 0))
10195 {
10196 wlcm_w(
10197 "NOTE: uAP will automatically switch to"
10198 " the channel that station is on.");
10199 if(is_sta_connected())
10200 wlan.networks[i].channel = wlan.networks[wlan.cur_network_idx].channel;
10201 }
10202 }
10203 if (wlan.networks[i].role == WLAN_BSS_ROLE_UAP)
10204 {
10205 return send_user_request(CM_UAP_USER_REQUEST_START, i);
10206 }
10207 }
10208 }
10209
10210 /* specified network was not found */
10211 return -WM_E_INVAL;
10212 }
10213
wlan_stop_network(const char * name)10214 int wlan_stop_network(const char *name)
10215 {
10216 unsigned int i;
10217 unsigned int len;
10218
10219 if (name == NULL)
10220 {
10221 return -WM_E_INVAL;
10222 }
10223
10224 len = strlen(name);
10225 if (len == 0U || wlan.num_networks == 0U)
10226 {
10227 return -WM_E_INVAL;
10228 }
10229
10230 wlan_uap_scan_chan_list_set = false;
10231 /* Search for matching SSID
10232 * If found send stop request
10233 */
10234 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
10235 {
10236 if ((wlan.networks[i].name[0] == '\0') || (strlen(wlan.networks[i].name) != len) ||
10237 (strncmp(wlan.networks[i].name, name, len)) != 0)
10238 {
10239 continue;
10240 }
10241
10242 if (wlan.networks[i].role == WLAN_BSS_ROLE_UAP && wlan.networks[i].ssid_specific)
10243 {
10244 net_interface_down(net_get_uap_handle());
10245 return send_user_request(CM_UAP_USER_REQUEST_STOP, i);
10246 }
10247 } /* end of loop */
10248 /* specified network was not found */
10249 return -WM_E_INVAL;
10250 }
10251
10252 #if defined(RW610)
wlan_remove_all_networks(void)10253 int wlan_remove_all_networks(void)
10254 {
10255 void *intrfc_handle = NULL;
10256
10257 /* No need to remove net interfaces here, as they are added only once.
10258 * Moreover, removing and adding net interface will increase netif_num cumulatively,
10259 * which will mismatch with "ua2" during creating dhcpd.
10260 */
10261 wlan_in_reset = true;
10262 wlan_remove_all_network_profiles();
10263
10264 intrfc_handle = net_get_sta_handle();
10265 net_interface_down(intrfc_handle);
10266
10267 intrfc_handle = net_get_uap_handle();
10268 net_interface_down(intrfc_handle);
10269 /* wait for mgmt_event handled */
10270 OSA_TimeDelay(500);
10271 return WM_SUCCESS;
10272 }
10273
10274 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
wlan_enable_all_networks(void)10275 int wlan_enable_all_networks(void)
10276 {
10277 void *intrfc_handle = NULL;
10278
10279 intrfc_handle = net_get_sta_handle();
10280 net_interface_up(intrfc_handle);
10281
10282 intrfc_handle = net_get_uap_handle();
10283 net_interface_up(intrfc_handle);
10284 return WM_SUCCESS;
10285 }
10286 #endif
wlan_destroy_all_tasks(void)10287 void wlan_destroy_all_tasks(void)
10288 {
10289 OSA_LockSchedule();
10290
10291 /* Destroy cm_main thread */
10292 OSA_TaskDestroy((osa_task_handle_t)wlan.wlcmgr_task_Handle);
10293
10294 #if CONFIG_WPS2
10295 /* Destroy wps_main thread */
10296 OSA_TaskDestroy((osa_task_handle_t)wlan_wps.wps_task_Handle);
10297 OSA_SemaphoreDestroy((osa_semaphore_handle_t)wlan_wps.wps_scan_done);
10298 #endif
10299
10300 /* Destroy wifidriver thread */
10301 wifi_destroy_wifidriver_tasks();
10302
10303 OSA_UnlockSchedule();
10304 }
10305
wlan_imu_get_task_lock(void)10306 int wlan_imu_get_task_lock(void)
10307 {
10308 return wifi_imu_get_task_lock();
10309 }
10310
wlan_imu_put_task_lock(void)10311 int wlan_imu_put_task_lock(void)
10312 {
10313 return wifi_imu_put_task_lock();
10314 }
10315
wlan_reset(cli_reset_option ResetOption)10316 void wlan_reset(cli_reset_option ResetOption)
10317 {
10318 if (OSA_MutexLock((osa_mutex_handle_t)reset_lock, 0) != WM_SUCCESS)
10319 {
10320 PRINTF("already in process...\r\n");
10321 return;
10322 }
10323
10324 if (ResetOption == CLI_DISABLE_WIFI || ResetOption == CLI_RESET_WIFI)
10325 {
10326 PRINTF("--- Disable WiFi ---\r\n");
10327 if (wlan_is_started())
10328 {
10329 #if CONFIG_HOST_SLEEP
10330 #if CONFIG_POWER_MANAGER
10331 /* Reset host sleep state flag first */
10332 wlan_host_sleep_state = HOST_SLEEP_DISABLE;
10333 #endif
10334 #endif
10335 #if (CONFIG_WPA_SUPP) && (CONFIG_UAP_STA_MAC_ADDR_FILTER)
10336 wlan_set_sta_mac_filter(0, 0, NULL);
10337 #endif
10338 /*Disconnect form AP if station is associated with an AP.*/
10339 if (is_sta_connecting())
10340 {
10341 wlan_disconnect();
10342 while (!is_sta_idle())
10343 {
10344 OSA_TimeDelay(1000);
10345 }
10346 }
10347
10348 /*Stop current uAP if uAP is started.*/
10349 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
10350 if (is_uap_started())
10351 {
10352 send_user_request(CM_UAP_USER_REQUEST_STOP, 0);
10353 while(!is_uap_state(HAPD_IFACE_DISABLED))
10354 {
10355 OSA_TimeDelay(1000);
10356 }
10357 }
10358 #else
10359 if (wlan.uap_state > CM_UAP_CONFIGURED)
10360 {
10361 wlan_stop_network(wlan.networks[wlan.cur_uap_network_idx].name);
10362 while (wlan.uap_state != CM_UAP_INITIALIZING)
10363 {
10364 OSA_TimeDelay(1000);
10365 }
10366 }
10367 #endif
10368 #if CONFIG_CPU_LOADING
10369 if(cpu_loading.status != CPU_LOADING_STATUS_DEAD)
10370 wlan_cpu_loading_stop();
10371 while(cpu_loading.status != CPU_LOADING_STATUS_DEAD)
10372 {
10373 OSA_TimeDelay(50);
10374 }
10375 #endif
10376 /* Block TX data */
10377 wifi_set_tx_status(WIFI_DATA_BLOCK);
10378 /* Block RX data */
10379 wifi_set_rx_status(WIFI_DATA_BLOCK);
10380
10381 #if CONFIG_NCP_BRIDGE
10382 /* Stop uap provisioning if it started */
10383 if (uap_prov_deinit_cb)
10384 uap_prov_deinit_cb();
10385 #endif
10386 /* Stop and Remove all network interfaces */
10387 wlan_remove_all_networks();
10388
10389 (void)net_wlan_deinit();
10390
10391 wifi_scan_stop();
10392 mlan_adap->skip_dfs = false;
10393 if (!wifi_fw_is_hang())
10394 wifi_send_shutdown_cmd();
10395
10396 #if CONFIG_WPA_SUPP
10397 wifi_supp_deinit();
10398 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
10399 wpa_supp_deinit();
10400 #endif
10401 #endif
10402
10403 /* wait for imu task done */
10404 wlan_imu_get_task_lock();
10405 /* Destroy all tasks before touch the global vars */
10406 wlan_destroy_all_tasks();
10407 #if CONFIG_NCP_BRIDGE
10408 if (uap_prov_cleanup_cb)
10409 uap_prov_cleanup_cb();
10410 #endif
10411 #if CONFIG_WPS2
10412 wps_stop();
10413 #endif /* CONFIG_WPS2 */
10414
10415 #if CONFIG_WPA2_ENTP
10416 wlan_free_entp_cert_files();
10417 #endif
10418
10419 wlan_imu_put_task_lock();
10420 /* Clear wlcmgr */
10421 wlan_stop();
10422 }
10423 power_off_device(LOAD_WIFI_FIRMWARE);
10424 }
10425
10426 if (ResetOption == CLI_ENABLE_WIFI || ResetOption == CLI_RESET_WIFI)
10427 {
10428 PRINTF("--- Enable WiFi ---\r\n");
10429 if (!wlan_is_started())
10430 {
10431 PRINTF("Initialize WLAN Driver\r\n");
10432 /* Initialize WIFI Driver */
10433 if (WM_SUCCESS != (wlan_init(wlan_fw_bin, wlan_fw_bin_len)))
10434 {
10435 wlcm_e("wlan init failed\r\n");
10436 OSA_MutexUnlock((osa_mutex_handle_t)reset_lock);
10437 assert(0);
10438 return;
10439 }
10440
10441 if (WM_SUCCESS != (wlan_start(wlan_event_callback)))
10442 {
10443 wlcm_e("wlan start failed\r\n");
10444 OSA_MutexUnlock((osa_mutex_handle_t)reset_lock);
10445 return;
10446 }
10447
10448 /* update the netif hwaddr after reset */
10449 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
10450 wlan_set_mac_addr(&wlan.sta_mac[0]);
10451 wlan_enable_all_networks();
10452 #else
10453 net_wlan_set_mac_address(&wlan.sta_mac[0], &wlan.uap_mac[0]);
10454 #endif
10455 /* Unblock TX data */
10456 wifi_set_tx_status(WIFI_DATA_RUNNING);
10457 /* Unblock RX data */
10458 wifi_set_rx_status(WIFI_DATA_RUNNING);
10459 wifi_tx_block_cnt = 0;
10460 wifi_rx_block_cnt = 0;
10461 #if (CONFIG_WIFI_BLE_COEX_APP) && (CONFIG_WIFI_BLE_COEX_APP == 1)
10462 #if CONFIG_HOST_SLEEP
10463 #if CONFIG_POWER_MANAGER
10464 /* Re-enable host sleep for coex app */
10465 wlan_host_sleep_state = HOST_SLEEP_PERIODIC;
10466 #endif
10467 #endif
10468 #endif
10469 }
10470 }
10471
10472 OSA_MutexUnlock((osa_mutex_handle_t)reset_lock);
10473
10474 wlan_in_reset = false;
10475 PRINTF("--- Done ---\r\n");
10476 }
10477
wlcmgr_mon_task(void * data)10478 static void wlcmgr_mon_task(void * data)
10479 {
10480 #if CONFIG_HOST_SLEEP
10481 int ret = 0;
10482 #endif
10483 osa_status_t status;
10484 struct wlan_message msg;
10485
10486 #if CONFIG_POWER_MANAGER
10487 status = OSA_TimerCreate((osa_timer_handle_t)wake_timer, MSEC_TO_TICK(WAKE_TIMEOUT),
10488 &wake_timer_cb, NULL, KOSA_TimerOnce, OSA_TIMER_NO_ACTIVATE);
10489 if (status != KOSA_StatusSuccess)
10490 {
10491 wlcm_e("Unable to create wake timer");
10492 }
10493 #endif
10494 while (1)
10495 {
10496 status = OSA_MsgQGet((osa_msgq_handle_t)mon_thread_events, &msg, osaWaitForever_c);
10497 if (status == KOSA_StatusSuccess)
10498 {
10499 /*Elements of wlan is not avaliable during wlan reset, so wait ending of wlan reset*/
10500 while(wlan_in_reset)
10501 OSA_TimeDelay(10);
10502 #if CONFIG_HOST_SLEEP
10503 wlcm_d("got mon thread event: %d", msg.id);
10504 if (msg.id == HOST_SLEEP_HANDSHAKE)
10505 {
10506 ret = wlan_send_host_sleep_int(wlan.wakeup_conditions, MFALSE);
10507 if (ret != WM_SUCCESS)
10508 {
10509 is_hs_handshake_done = WLAN_HOSTSLEEP_FAIL;
10510 }
10511 }
10512 else if (msg.id == HOST_SLEEP_EXIT)
10513 {
10514 #if CONFIG_POWER_MANAGER
10515 if(!wlan_is_manual && wlan_host_sleep_state == HOST_SLEEP_PERIODIC)
10516 {
10517 wakelock_get();
10518 (void)OSA_TimerActivate((osa_timer_handle_t)wake_timer);
10519 }
10520 #endif
10521 wlan_cancel_host_sleep();
10522 /* Check fw status and write temperature to firmware after waking up */
10523 temperature_mon_cb(NULL);
10524 (void)OSA_TimerActivate((osa_timer_handle_t)temperature_mon_timer);
10525 }
10526 #endif
10527 #if CONFIG_WIFI_RECOVERY
10528 else if (msg.id == WIFI_RECOVERY_REQ)
10529 {
10530 wlan_reset(CLI_RESET_WIFI);
10531 wifi_recovery_cnt ++;
10532 }
10533 #endif
10534 }
10535 else
10536 {
10537 wlcm_e("Failed to get events from monitor task queue");
10538 }
10539 }
10540 }
10541 #endif // RW610
10542
10543 #if CONFIG_NCP_BRIDGE
wlan_stop_all_networks(void)10544 int wlan_stop_all_networks(void)
10545 {
10546 wifi_scan_stop();
10547
10548 net_interface_down(net_get_sta_handle());
10549 wlan_disconnect();
10550
10551 net_interface_down(net_get_uap_handle());
10552 send_user_request(CM_UAP_USER_REQUEST_STOP, 0);
10553
10554 return WM_SUCCESS;
10555 }
10556
wlan_register_uap_prov_deinit_cb(int (* cb)(void))10557 void wlan_register_uap_prov_deinit_cb(int (*cb)(void))
10558 {
10559 uap_prov_deinit_cb = cb;
10560 }
10561
wlan_register_uap_prov_cleanup_cb(void (* cb)(void))10562 void wlan_register_uap_prov_cleanup_cb(void (*cb)(void))
10563 {
10564 uap_prov_cleanup_cb = cb;
10565 }
10566 #endif
10567
wlan_get_scan_result(unsigned int index,struct wlan_scan_result * res)10568 int wlan_get_scan_result(unsigned int index, struct wlan_scan_result *res)
10569 {
10570 struct wifi_scan_result2 *desc;
10571
10572 if (res == NULL)
10573 {
10574 return -WM_E_INVAL;
10575 }
10576
10577 if (!is_running())
10578 {
10579 return WLAN_ERROR_STATE;
10580 }
10581
10582 if (wifi_get_scan_result(index, &desc) != 0)
10583 {
10584 return -WM_FAIL;
10585 }
10586
10587 (void)memset(res, 0, sizeof(struct wlan_scan_result));
10588
10589 (void)memcpy((void *)&res->bssid[0], (const void *)&desc->bssid[0], sizeof(res->bssid));
10590 (void)memcpy((void *)&res->ssid[0], (const void *)((char *)&desc->ssid[0]), (size_t)desc->ssid_len);
10591 res->ssid[desc->ssid_len] = (char)0;
10592 res->ssid_len = (size_t)desc->ssid_len;
10593 res->channel = desc->Channel;
10594 res->beacon_period = desc->beacon_period;
10595 res->dtim_period = desc->dtim_period;
10596
10597 if (!desc->is_ibss_bit_set)
10598 {
10599 res->role = WLAN_BSS_ROLE_STA;
10600 }
10601 res->dot11n = (uint8_t)desc->phtcap_ie_present;
10602 #if CONFIG_11AC
10603 res->dot11ac = (uint8_t)desc->pvhtcap_ie_present;
10604 #endif
10605 #if CONFIG_11AX
10606 res->dot11ax = (uint8_t)desc->phecap_ie_present;
10607 #endif
10608
10609 res->wmm = (uint8_t)desc->wmm_ie_present;
10610 #if (CONFIG_WPA_SUPP_WPS)
10611 if (desc->wps_IE_exist == true)
10612 {
10613 res->wps = desc->wps_IE_exist;
10614 res->wps_session = desc->wps_session;
10615 }
10616 #elif (CONFIG_WPS2)
10617 if (desc->wps_IE_exist == true)
10618 res->wps = desc->wps_IE_exist;
10619 res->wps_session = desc->wps_session;
10620 #endif
10621 if (desc->WPA_WPA2_WEP.wpa2_entp != 0U)
10622 {
10623 res->wpa2_entp = 1;
10624 }
10625 else if (desc->WPA_WPA2_WEP.wpa2_entp_sha256 != 0U)
10626 {
10627 res->wpa2_entp_sha256 = 1;
10628 }
10629 else if (desc->WPA_WPA2_WEP.wpa3_1x_sha256 != 0U)
10630 {
10631 res->wpa3_1x_sha256 = 1;
10632 }
10633 else if (desc->WPA_WPA2_WEP.wpa3_1x_sha384 != 0U)
10634 {
10635 res->wpa3_1x_sha384 = 1;
10636 }
10637 else
10638 {
10639 if (desc->WPA_WPA2_WEP.wpa != 0U)
10640 {
10641 res->wpa = 1;
10642 }
10643 if (desc->WPA_WPA2_WEP.wpa3_sae != 0U)
10644 {
10645 res->wpa3_sae = 1;
10646 }
10647 if (desc->WPA_WPA2_WEP.owe != 0U)
10648 {
10649 #if CONFIG_DRIVER_OWE
10650 res->owe = 1;
10651 #endif
10652 }
10653 if (desc->WPA_WPA2_WEP.wpa2 != 0U)
10654 {
10655 res->wpa2 = 1;
10656 }
10657 if (desc->WPA_WPA2_WEP.wpa2_sha256 != 0U)
10658 {
10659 res->wpa2_sha256 = 1;
10660 }
10661 if ((desc->WPA_WPA2_WEP.wepStatic != 0U) || (desc->WPA_WPA2_WEP.wepDynamic != 0U))
10662 {
10663 res->wep = 1;
10664 }
10665 }
10666 #if CONFIG_11R
10667 if (res->wpa2_entp != 0U)
10668 {
10669 res->ft_1x = (t_u8)desc->WPA_WPA2_WEP.ft_1x;
10670 }
10671 if (res->wpa2 != 0U)
10672 {
10673 res->ft_psk = (t_u8)desc->WPA_WPA2_WEP.ft_psk;
10674 }
10675 if (res->wpa3_sae != 0U)
10676 {
10677 res->ft_sae = (t_u8)desc->WPA_WPA2_WEP.ft_sae;
10678 }
10679 if (res->wpa3_1x_sha384 != 0U)
10680 {
10681 res->ft_1x_sha384 = (t_u8)desc->WPA_WPA2_WEP.ft_1x_sha384;
10682 }
10683 #endif
10684 res->rssi = desc->RSSI;
10685
10686 (void)memcpy((void *)&res->trans_bssid[0], (const void *)&desc->trans_bssid[0], sizeof(res->trans_bssid));
10687 (void)memcpy((void *)&res->trans_ssid[0], (const void *)((char *)&desc->trans_ssid[0]),
10688 (unsigned int)desc->trans_ssid_len);
10689 res->trans_ssid[desc->trans_ssid_len] = (char)0;
10690 res->trans_ssid_len = (unsigned int)desc->trans_ssid_len;
10691
10692 #if CONFIG_11K
10693 if (desc->neighbor_report_supported == true)
10694 {
10695 res->neighbor_report_supported = true;
10696 }
10697 else
10698 {
10699 res->neighbor_report_supported = false;
10700 }
10701 #endif
10702
10703 #if CONFIG_11V
10704 if (desc->bss_transition_supported == true)
10705 {
10706 res->bss_transition_supported = true;
10707 }
10708 else
10709 {
10710 res->bss_transition_supported = false;
10711 }
10712 #endif
10713
10714 res->ap_mfpc = desc->ap_mfpc;
10715 res->ap_mfpr = desc->ap_mfpr;
10716 res->ap_pwe = desc->ap_pwe;
10717
10718 return WM_SUCCESS;
10719 }
10720
wlan_set_cal_data(const uint8_t * cal_data,const unsigned int cal_data_size)10721 void wlan_set_cal_data(const uint8_t *cal_data, const unsigned int cal_data_size)
10722 {
10723 if (cal_data_size > 1)
10724 {
10725 wifi_set_cal_data(cal_data, cal_data_size);
10726 }
10727 }
10728
wlan_set_mac_addr(uint8_t * mac)10729 int wlan_set_mac_addr(uint8_t *mac)
10730 {
10731 uint8_t ap_mac[MLAN_MAC_ADDR_LENGTH];
10732
10733 if (is_uap_starting() || is_sta_connecting())
10734 {
10735 return -WM_FAIL;
10736 }
10737
10738 if (wlan.status == WLCMGR_INIT_DONE || wlan.status == WLCMGR_ACTIVATED)
10739 {
10740 (void)memcpy(ap_mac, mac, MLAN_MAC_ADDR_LENGTH);
10741 ap_mac[4] += 1;
10742
10743 net_wlan_set_mac_address((unsigned char *)mac, (unsigned char *)ap_mac);
10744
10745 _wifi_set_mac_addr(mac, MLAN_BSS_TYPE_STA);
10746
10747 _wifi_set_mac_addr(&ap_mac[0], MLAN_BSS_TYPE_UAP);
10748
10749 /* save the sta mac */
10750 (void)memcpy(&wlan.sta_mac[0], mac, MLAN_MAC_ADDR_LENGTH);
10751 /* save the uap mac */
10752 (void)memcpy(&wlan.uap_mac[0], &ap_mac[0], MLAN_MAC_ADDR_LENGTH);
10753 }
10754 else
10755 {
10756 wifi_set_mac_addr(mac);
10757 }
10758 #if CONFIG_WPS2
10759 (void)memcpy(wps_global.my_mac_addr, mac, MLAN_MAC_ADDR_LENGTH);
10760 (void)memcpy(wps_global.l2->my_mac_addr, mac, MLAN_MAC_ADDR_LENGTH);
10761 #endif
10762
10763 return WM_SUCCESS;
10764 }
10765
wlan_set_uap_mac_addr(uint8_t * mac)10766 int wlan_set_uap_mac_addr(uint8_t *mac)
10767 {
10768 /* Only suppoprt unicast mac */
10769 if (mac[0] & 0x01)
10770 {
10771 return -WM_FAIL;
10772 }
10773
10774 if (is_uap_starting())
10775 {
10776 return -WM_FAIL;
10777 }
10778
10779 if (memcmp(mac, &wlan.sta_mac[0], MLAN_MAC_ADDR_LENGTH) == 0)
10780 {
10781 return -WM_FAIL;
10782 }
10783
10784 if (wlan.status == WLCMGR_INIT_DONE || wlan.status == WLCMGR_ACTIVATED)
10785 {
10786 net_wlan_set_mac_address(NULL, (unsigned char *)mac);
10787
10788 _wifi_set_mac_addr(mac, MLAN_BSS_TYPE_UAP);
10789
10790 /* save the uap mac */
10791 (void)memcpy(&wlan.uap_mac[0], mac, MLAN_MAC_ADDR_LENGTH);
10792 }
10793 else
10794 {
10795 wifi_set_mac_addr(mac);
10796 }
10797
10798 return WM_SUCCESS;
10799 }
10800
wlan_set_sta_mac_addr(uint8_t * mac)10801 int wlan_set_sta_mac_addr(uint8_t *mac)
10802 {
10803 /* Only suppoprt unicast mac */
10804 if (mac[0] & 0x01)
10805 {
10806 return -WM_FAIL;
10807 }
10808
10809 if (is_sta_connecting())
10810 {
10811 return -WM_FAIL;
10812 }
10813
10814 if (memcmp(mac, &wlan.uap_mac[0], MLAN_MAC_ADDR_LENGTH) == 0)
10815 {
10816 return -WM_FAIL;
10817 }
10818
10819 if (wlan.status == WLCMGR_INIT_DONE || wlan.status == WLCMGR_ACTIVATED)
10820 {
10821 net_wlan_set_mac_address((unsigned char *)mac, NULL);
10822
10823 _wifi_set_mac_addr(mac, MLAN_BSS_TYPE_STA);
10824
10825 /* save the sta mac */
10826 (void)memcpy(&wlan.sta_mac[0], mac, MLAN_MAC_ADDR_LENGTH);
10827 }
10828 else
10829 {
10830 wifi_set_mac_addr(mac);
10831 }
10832
10833 return WM_SUCCESS;
10834 }
10835
wlan_scan(int (* cb)(unsigned int count))10836 int wlan_scan(int (*cb)(unsigned int count))
10837 {
10838 int ret;
10839
10840 wlan_scan_params_v2_t wlan_scan_param;
10841
10842 (void)memset(&wlan_scan_param, 0, sizeof(wlan_scan_params_v2_t));
10843
10844 wlan_scan_param.cb = cb;
10845
10846 ret = wlan_scan_with_opt(wlan_scan_param);
10847
10848 return ret;
10849 }
10850
wlan_pscan(int (* cb)(unsigned int count))10851 static int wlan_pscan(int (*cb)(unsigned int count))
10852 {
10853 struct wlan_network* network = NULL;
10854 wlan_scan_params_v2_t wlan_scan_param;
10855 int ret;
10856
10857 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED)))
10858 {
10859 network = &wlan.networks[wlan.cur_network_idx];
10860 }
10861
10862 if (network == NULL)
10863 {
10864 wlcm_e("cannot get network info");
10865 return -WM_FAIL;
10866 }
10867
10868 (void)memset(&wlan_scan_param, 0, sizeof(wlan_scan_params_v2_t));
10869
10870 wlan_scan_param.cb = cb;
10871
10872 (void)memcpy((void *)wlan_scan_param.bssid, (const void *)network->bssid, MLAN_MAC_ADDR_LENGTH);
10873
10874 (void)memcpy((void *)wlan_scan_param.ssid, (const void *)network->ssid, strlen(network->ssid));
10875
10876 wlan_scan_param.num_channels = 1;
10877
10878 wlan_scan_param.chan_list[0].chan_number = (t_u8)network->channel;
10879 wlan_scan_param.chan_list[0].scan_type = MLAN_SCAN_TYPE_PASSIVE;
10880 wlan_scan_param.chan_list[0].scan_time = 200;
10881
10882 ret = wlan_scan_with_opt(wlan_scan_param);
10883
10884 return ret;
10885 }
10886
wlan_scan_with_opt(wlan_scan_params_v2_t t_wlan_scan_param)10887 int wlan_scan_with_opt(wlan_scan_params_v2_t t_wlan_scan_param)
10888 {
10889 int ret;
10890 uint32_t chan_idx = 0;
10891 uint32_t t_idx = 0;
10892 wlan_scan_params_v2_t *wlan_scan_param = NULL;
10893
10894 if (t_wlan_scan_param.cb == NULL)
10895 {
10896 return -WM_E_INVAL;
10897 }
10898
10899 if (!is_running() || !is_scanning_allowed())
10900 {
10901 return WLAN_ERROR_STATE;
10902 }
10903
10904 #if !CONFIG_MEM_POOLS
10905 wlan_scan_param = (wlan_scan_params_v2_t *)OSA_MemoryAllocate(sizeof(wlan_scan_params_v2_t));
10906 #else
10907 wlan_scan_param = (wlan_scan_params_v2_t *)OSA_MemoryPoolAllocate(buf_128_MemoryPool);
10908 #endif
10909
10910 if (wlan_scan_param == NULL)
10911 {
10912 return -WM_E_NOMEM;
10913 }
10914
10915 (void)memcpy((void *)wlan_scan_param, (const void *)&t_wlan_scan_param, sizeof(wlan_scan_params_v2_t));
10916
10917 if (t_wlan_scan_param.num_channels > 0)
10918 {
10919 wlan_scan_param->num_channels = 0;
10920 (void)memset((void *)&wlan_scan_param->chan_list[0], 0x0, MAX_CHANNEL_LIST * sizeof(wifi_scan_channel_list_t));
10921 #if defined(RW610) && (CONFIG_ANT_DETECT)
10922 for (t_idx = 0; t_idx < ANT_DETECT_MAX_CHANNEL_LIST && t_wlan_scan_param.chan_list[t_idx].chan_number; t_idx++)
10923 #else
10924 for (t_idx = 0; t_idx < MAX_CHANNEL_LIST && t_wlan_scan_param.chan_list[t_idx].chan_number; t_idx++)
10925 #endif
10926 {
10927 if(!wlan_check_channel_by_region_table((mlan_private *)mlan_adap->priv[0], t_wlan_scan_param.chan_list[t_idx].chan_number))
10928 {
10929 continue;
10930 }
10931 (void)memcpy((void *)&wlan_scan_param->chan_list[chan_idx], (const void *)&t_wlan_scan_param.chan_list[t_idx], sizeof(wifi_scan_channel_list_t));
10932 chan_idx++;
10933 }
10934 wlan_scan_param->num_channels = chan_idx;
10935
10936 if (chan_idx == 0 && t_wlan_scan_param.num_channels > 0)
10937 {
10938 wlcm_e("no valid channel to scan");
10939 #if !CONFIG_MEM_POOLS
10940 OSA_MemoryFree(wlan_scan_param);
10941 #else
10942 OSA_MemoryPoolFree(buf_128_MemoryPool, wlan_scan_param);
10943 #endif
10944
10945 return -WM_E_INVAL;
10946 }
10947 }
10948
10949 wlcm_d("taking the scan lock (user scan)");
10950 dbg_lock_info();
10951 ret = OSA_SemaphoreWait((osa_semaphore_handle_t)wlan.scan_lock, osaWaitForever_c);
10952 if (ret != WM_SUCCESS)
10953 {
10954 wlcm_e("failed to get scan lock: 0x%X", ret);
10955 #if !CONFIG_MEM_POOLS
10956 OSA_MemoryFree(wlan_scan_param);
10957 #else
10958 OSA_MemoryPoolFree(buf_128_MemoryPool, wlan_scan_param);
10959 #endif
10960 return -WM_FAIL;
10961 }
10962 wlcm_d("got the scan lock (user scan)");
10963 wlan.is_scan_lock = 1;
10964
10965 ret = send_user_request(CM_STA_USER_REQUEST_SCAN, (unsigned int)wlan_scan_param);
10966
10967 if (ret != WM_SUCCESS)
10968 {
10969 #if !CONFIG_MEM_POOLS
10970 OSA_MemoryFree(wlan_scan_param);
10971 #else
10972 OSA_MemoryPoolFree(buf_128_MemoryPool, wlan_scan_param);
10973 #endif
10974 }
10975
10976 return ret;
10977 }
10978
wlan_get_connection_state(enum wlan_connection_state * state)10979 int wlan_get_connection_state(enum wlan_connection_state *state)
10980 {
10981 enum cm_sta_state cur;
10982
10983 if (state == NULL)
10984 {
10985 return -WM_E_INVAL;
10986 }
10987
10988 if (!is_running())
10989 {
10990 return WLAN_ERROR_STATE;
10991 }
10992
10993 if (is_user_scanning() != 0)
10994 {
10995 cur = wlan.sta_return_to;
10996 }
10997 else
10998 {
10999 cur = wlan.sta_state;
11000 }
11001
11002 switch (cur)
11003 {
11004 case CM_STA_IDLE:
11005 *state = WLAN_DISCONNECTED;
11006 break;
11007 case CM_STA_SCANNING:
11008 *state = WLAN_SCANNING;
11009 break;
11010 case CM_STA_ASSOCIATING:
11011 *state = WLAN_ASSOCIATING;
11012 break;
11013 case CM_STA_ASSOCIATED:
11014 *state = WLAN_ASSOCIATED;
11015 break;
11016 case CM_STA_AUTHENTICATED:
11017 *state = WLAN_AUTHENTICATED;
11018 break;
11019 case CM_STA_REQUESTING_ADDRESS:
11020 case CM_STA_OBTAINING_ADDRESS:
11021 *state = WLAN_CONNECTING;
11022 break;
11023 case CM_STA_CONNECTED:
11024 *state = WLAN_CONNECTED;
11025 break;
11026 default:
11027 *state = WLAN_DISCONNECTED;
11028 break;
11029 }
11030 return WM_SUCCESS;
11031 }
11032
wlan_get_ps_mode(enum wlan_ps_mode * ps_mode)11033 int wlan_get_ps_mode(enum wlan_ps_mode *ps_mode)
11034 {
11035 if (ps_mode == NULL)
11036 {
11037 return -WM_E_INVAL;
11038 }
11039
11040 *ps_mode = WLAN_ACTIVE;
11041
11042 if (wlan.cm_ieeeps_configured && wlan.cm_deepsleepps_configured)
11043 {
11044 if (is_state(CM_STA_CONNECTED))
11045 {
11046 *ps_mode = WLAN_IEEE;
11047 }
11048 else
11049 {
11050 *ps_mode = WLAN_DEEP_SLEEP;
11051 }
11052 }
11053 #if CONFIG_WNM_PS
11054 else if (wlan.cm_wnmps_configured && wlan.cm_deepsleepps_configured)
11055 {
11056 if (is_state(CM_STA_CONNECTED))
11057 {
11058 *ps_mode = WLAN_WNM;
11059 }
11060 else
11061 {
11062 *ps_mode = WLAN_DEEP_SLEEP;
11063 }
11064 }
11065 else if (wlan.cm_wnmps_configured)
11066 {
11067 *ps_mode = WLAN_WNM;
11068 }
11069 #endif
11070 else if (wlan.cm_deepsleepps_configured)
11071 {
11072 *ps_mode = WLAN_DEEP_SLEEP;
11073 }
11074 else if (wlan.cm_ieeeps_configured)
11075 {
11076 *ps_mode = WLAN_IEEE;
11077 }
11078 else
11079 { /* Do Nothing */
11080 }
11081
11082 return WM_SUCCESS;
11083 }
11084
wlan_get_uap_connection_state(enum wlan_connection_state * state)11085 int wlan_get_uap_connection_state(enum wlan_connection_state *state)
11086 {
11087 enum cm_uap_state cur;
11088
11089 if (state == NULL)
11090 {
11091 return -WM_E_INVAL;
11092 }
11093
11094 if (!is_running())
11095 {
11096 return WLAN_ERROR_STATE;
11097 }
11098
11099 cur = wlan.uap_state;
11100
11101 switch (cur)
11102 {
11103 case CM_UAP_INITIALIZING:
11104 case CM_UAP_CONFIGURED:
11105 *state = WLAN_UAP_STOPPED;
11106 break;
11107 case CM_UAP_STARTED:
11108 case CM_UAP_IP_UP:
11109 *state = WLAN_UAP_STARTED;
11110 break;
11111 default:
11112 *state = WLAN_UAP_STOPPED;
11113 break;
11114 }
11115 return WM_SUCCESS;
11116 }
11117
wlan_get_address(struct wlan_ip_config * addr)11118 int wlan_get_address(struct wlan_ip_config *addr)
11119 {
11120 void *if_handle = NULL;
11121 if (addr == NULL)
11122 {
11123 return -WM_E_INVAL;
11124 }
11125
11126 if (!is_running() || !is_state(CM_STA_CONNECTED))
11127 {
11128 return WLAN_ERROR_STATE;
11129 }
11130
11131 if_handle = net_get_mlan_handle();
11132 if (net_get_if_addr((struct net_ip_config *)addr, if_handle) != 0)
11133 {
11134 return -WM_FAIL;
11135 }
11136
11137 #if CONFIG_IPV6
11138 if (net_get_if_ipv6_addr((struct net_ip_config *)addr, if_handle) != 0)
11139 {
11140 return -WM_FAIL;
11141 }
11142 #endif
11143
11144 return WM_SUCCESS;
11145 }
11146
wlan_get_uap_address(struct wlan_ip_config * addr)11147 int wlan_get_uap_address(struct wlan_ip_config *addr)
11148 {
11149 void *if_handle = NULL;
11150 if (addr == NULL)
11151 {
11152 return -WM_E_INVAL;
11153 }
11154 if (!is_running() || !is_uap_state(CM_UAP_IP_UP))
11155 {
11156 return WLAN_ERROR_STATE;
11157 }
11158
11159 if_handle = net_get_uap_handle();
11160 if (net_get_if_addr((struct net_ip_config *)addr, if_handle) != 0)
11161 {
11162 return -WM_FAIL;
11163 }
11164 return WM_SUCCESS;
11165 }
11166
wlan_get_uap_channel(int * channel)11167 int wlan_get_uap_channel(int *channel)
11168 {
11169 if (channel != NULL)
11170 {
11171 *channel = 0;
11172 }
11173 else
11174 {
11175 return (int)(-WM_E_INVAL);
11176 }
11177
11178 return wifi_get_uap_channel(channel);
11179 }
11180
11181 #if CONFIG_P2P
wlan_get_wfd_address(struct wlan_ip_config * addr)11182 int wlan_get_wfd_address(struct wlan_ip_config *addr)
11183 {
11184 void *if_handle = NULL;
11185 if (addr == NULL)
11186 return -WM_E_INVAL;
11187 if (!is_running())
11188 return WLAN_ERROR_STATE;
11189
11190 if_handle = net_get_wfd_handle();
11191 if (net_get_if_addr((struct net_ip_config *)addr, if_handle))
11192 return -WM_FAIL;
11193 return WM_SUCCESS;
11194 }
11195 #endif
11196
wlan_get_mac_address(unsigned char * dest)11197 int wlan_get_mac_address(unsigned char *dest)
11198 {
11199 if (!dest)
11200 return -WM_E_INVAL;
11201 (void)memset(dest, 0, MLAN_MAC_ADDR_LENGTH);
11202 (void)memcpy(dest, &wlan.sta_mac[0], MLAN_MAC_ADDR_LENGTH);
11203 return WM_SUCCESS;
11204 }
11205
wlan_get_mac_address_uap(unsigned char * dest)11206 int wlan_get_mac_address_uap(unsigned char *dest)
11207 {
11208 if (!dest)
11209 return -WM_E_INVAL;
11210 (void)memset(dest, 0, MLAN_MAC_ADDR_LENGTH);
11211 (void)memcpy(dest, &wlan.uap_mac[0], MLAN_MAC_ADDR_LENGTH);
11212 return WM_SUCCESS;
11213 }
11214
11215 #if CONFIG_P2P
wlan_get_wfd_mac_address(unsigned char * dest)11216 int wlan_get_wfd_mac_address(unsigned char *dest)
11217 {
11218 if (dest == NULL)
11219 return -WM_E_INVAL;
11220 (void)memset((void *)dest, 0, MLAN_MAC_ADDR_LENGTH);
11221 (void)memcpy((void *)dest, (const void *)&wlan.wfd_mac[0], MLAN_MAC_ADDR_LENGTH);
11222 return WM_SUCCESS;
11223 }
11224 #endif
11225
wlan_wake_up_card(void)11226 void wlan_wake_up_card(void)
11227 {
11228 uint32_t resp;
11229
11230 wifi_wake_up_card(&resp);
11231 }
11232
wlan_set_ieeeps_cfg(struct wlan_ieeeps_config * ps_cfg)11233 int wlan_set_ieeeps_cfg(struct wlan_ieeeps_config *ps_cfg)
11234 {
11235 wlan_configure_null_pkt_interval(ps_cfg->ps_null_interval);
11236
11237 return send_user_request(CM_STA_USER_REQUEST_PS_ENTER, WLAN_IEEE);
11238 }
11239
wlan_configure_listen_interval(int listen_interval)11240 void wlan_configure_listen_interval(int listen_interval)
11241 {
11242 wifi_configure_listen_interval(listen_interval);
11243 }
11244
wlan_configure_delay_to_ps(unsigned int timeout_ms)11245 void wlan_configure_delay_to_ps(unsigned int timeout_ms)
11246 {
11247 wifi_configure_delay_to_ps(timeout_ms);
11248 }
11249
wlan_get_listen_interval()11250 unsigned short wlan_get_listen_interval()
11251 {
11252 return wifi_get_listen_interval();
11253 }
11254
wlan_get_delay_to_ps()11255 unsigned int wlan_get_delay_to_ps()
11256 {
11257 return wifi_get_delay_to_ps();
11258 }
11259
wlan_is_power_save_enabled()11260 bool wlan_is_power_save_enabled()
11261 {
11262 if (wlan.cm_ieeeps_configured
11263 #if CONFIG_WNM_PS
11264 || wlan.cm_wnmps_configured
11265 #endif
11266 || wlan.cm_deepsleepps_configured)
11267 {
11268 return true;
11269 }
11270
11271 return false;
11272 }
11273
wlan_configure_null_pkt_interval(int time_in_secs)11274 void wlan_configure_null_pkt_interval(int time_in_secs)
11275 {
11276 wifi_configure_null_pkt_interval((unsigned int)time_in_secs);
11277 }
11278
wlan_ieeeps_on(unsigned int wakeup_conditions)11279 int wlan_ieeeps_on(unsigned int wakeup_conditions)
11280 {
11281 enum wlan_connection_state state;
11282
11283 if ((!wlan.running) || (wlan_get_uap_connection_state(&state) != 0) || (state == WLAN_UAP_STARTED))
11284 {
11285 return -WM_FAIL;
11286 }
11287
11288 if (wlan.cm_ieeeps_configured
11289 #if CONFIG_WNM_PS
11290 || wlan.cm_wnmps_configured
11291 #endif
11292 )
11293 {
11294 #if CONFIG_WNM_PS
11295 if (wlan.cm_wnmps_configured == true)
11296 {
11297 wlcm_d("wnm ps already enabled: %d, ieee ps could not be enabled", wlan.cm_wnmps_configured);
11298 return -WM_FAIL;
11299 }
11300 else
11301 #endif
11302 {
11303 wlcm_d("ieee ps already enabled");
11304 }
11305
11306 CONNECTION_EVENT(WLAN_REASON_PS_ENTER, (void *)WLAN_IEEE);
11307 return WM_SUCCESS;
11308 }
11309
11310 return send_user_request(CM_STA_USER_REQUEST_PS_ENTER, WLAN_IEEE);
11311 }
11312
wlan_ieeeps_off(void)11313 int wlan_ieeeps_off(void)
11314 {
11315 if (wlan.cm_ieeeps_configured)
11316 {
11317 return send_user_request(CM_STA_USER_REQUEST_PS_EXIT, WLAN_IEEE);
11318 }
11319
11320 CONNECTION_EVENT(WLAN_REASON_PS_EXIT, (void *)WLAN_IEEE);
11321 return WM_SUCCESS;
11322 }
11323
11324 #if (CONFIG_WNM_PS)
wlan_wnmps_on(unsigned int wakeup_conditions,t_u16 wnm_sleep_time)11325 int wlan_wnmps_on(unsigned int wakeup_conditions, t_u16 wnm_sleep_time)
11326 {
11327 enum wlan_connection_state state;
11328
11329 if ((!wlan.running) || (wlan_get_uap_connection_state(&state) != 0) || (state == WLAN_UAP_STARTED))
11330 {
11331 return -WM_FAIL;
11332 }
11333
11334 if (wlan.cm_ieeeps_configured || wlan.cm_wnmps_configured)
11335 {
11336 if (wlan.cm_ieeeps_configured == true)
11337 {
11338 wlcm_d("ieee ps already enabled: %d, wnm ps could not be enabled", wlan.cm_ieeeps_configured);
11339 return -WM_FAIL;
11340 }
11341 else
11342 {
11343 wlcm_d("wnm ps already enabled");
11344 }
11345
11346 CONNECTION_EVENT(WLAN_REASON_PS_ENTER, (void *)WLAN_WNM);
11347 return WM_SUCCESS;
11348 }
11349
11350 wlan.wakeup_conditions = wakeup_conditions;
11351 wlan.wnm_sleep_time = wnm_sleep_time;
11352 return send_user_request(CM_STA_USER_REQUEST_PS_ENTER, WLAN_WNM);
11353 }
11354
wlan_wnmps_off()11355 int wlan_wnmps_off()
11356 {
11357 if (wlan.cm_wnmps_configured)
11358 {
11359 return send_user_request(CM_STA_USER_REQUEST_PS_EXIT, WLAN_WNM);
11360 }
11361
11362 CONNECTION_EVENT(WLAN_REASON_PS_EXIT, (void *)WLAN_WNM);
11363 return WM_SUCCESS;
11364 }
11365 #endif
11366
wlan_deepsleepps_on(void)11367 int wlan_deepsleepps_on(void)
11368 {
11369 enum wlan_connection_state state;
11370
11371 if ((!wlan.running) || (wlan_get_uap_connection_state(&state) != 0) || (state == WLAN_UAP_STARTED))
11372 {
11373 return -WM_FAIL;
11374 }
11375
11376 if (wlan.cm_deepsleepps_configured)
11377 {
11378 CONNECTION_EVENT(WLAN_REASON_PS_ENTER, (void *)WLAN_DEEP_SLEEP);
11379 return WM_SUCCESS;
11380 }
11381
11382 return send_user_request(CM_STA_USER_REQUEST_PS_ENTER, WLAN_DEEP_SLEEP);
11383 }
11384
wlan_deepsleepps_off(void)11385 int wlan_deepsleepps_off(void)
11386 {
11387 if (wlan.cm_deepsleepps_configured)
11388 {
11389 return send_user_request(CM_STA_USER_REQUEST_PS_EXIT, WLAN_DEEP_SLEEP);
11390 }
11391
11392 CONNECTION_EVENT(WLAN_REASON_PS_EXIT, (void *)WLAN_DEEP_SLEEP);
11393 return WM_SUCCESS;
11394 }
11395
11396 #if CONFIG_WPS2
wlan_start_wps_pbc()11397 int wlan_start_wps_pbc()
11398 {
11399 wlan_wps.wps_state = PROV_WPS_PBC_ENABLED;
11400 wlan_wps.wps_cmd = CMD_WPS_PBC;
11401 wlan_wps.wps_pin = 0;
11402
11403 return WM_SUCCESS;
11404 }
11405
wlan_wps_generate_pin(uint32_t * pin)11406 void wlan_wps_generate_pin(uint32_t *pin)
11407 {
11408 wps_generate_pin(pin);
11409 }
11410
wlan_start_wps_pin(uint32_t pin)11411 int wlan_start_wps_pin(uint32_t pin)
11412 {
11413 if (wps_validate_pin(pin) != WM_SUCCESS)
11414 {
11415 wlcm_d("WPS PIN validation failed for %d", pin);
11416 return -WM_FAIL;
11417 }
11418
11419 wlan_wps.wps_state = PROV_WPS_PIN_ENABLED;
11420 wlan_wps.wps_cmd = CMD_WPS_PIN;
11421 wlan_wps.wps_pin = pin;
11422
11423 return WM_SUCCESS;
11424 }
11425 #endif
11426
11427 #ifdef STREAM_2X2
wlan_set_current_ant(uint8_t tx_antenna,uint8_t rx_antenna)11428 int wlan_set_current_ant(uint8_t tx_antenna, uint8_t rx_antenna)
11429 {
11430 int rv = wifi_set_antenna(tx_antenna, rx_antenna);
11431 if (rv != WM_SUCCESS)
11432 {
11433 wlcm_e("Unable to set antenna");
11434 return WLAN_ERROR_STATE;
11435 }
11436
11437 return WM_SUCCESS;
11438 }
11439 #else
11440 #ifndef RW610
wlan_set_antcfg(uint32_t ant,uint16_t evaluate_time)11441 int wlan_set_antcfg(uint32_t ant, uint16_t evaluate_time)
11442 {
11443 int rv = wifi_set_antenna(ant, evaluate_time);
11444 if (rv != WM_SUCCESS)
11445 {
11446 wlcm_e("Unable to set antenna");
11447 return WLAN_ERROR_STATE;
11448 }
11449
11450 return WM_SUCCESS;
11451 }
11452
wlan_get_antcfg(uint32_t * ant,uint16_t * evaluate_time,uint16_t * current_antenna)11453 int wlan_get_antcfg(uint32_t *ant, uint16_t *evaluate_time, uint16_t *current_antenna)
11454 {
11455 int rv = wifi_get_antenna((unsigned int *)ant, evaluate_time, current_antenna);
11456 if (rv != WM_SUCCESS)
11457 {
11458 wlcm_e("Unable to get current antenna");
11459 return WLAN_ERROR_STATE;
11460 }
11461
11462 return WM_SUCCESS;
11463 }
11464 #else
wlan_set_antcfg(uint32_t ant,uint16_t evaluate_time,uint8_t evaluate_mode)11465 int wlan_set_antcfg(uint32_t ant, uint16_t evaluate_time, uint8_t evaluate_mode)
11466 {
11467 int rv = wifi_set_antenna(ant, evaluate_time, evaluate_mode);
11468 if (rv != WM_SUCCESS)
11469 {
11470 wlcm_e("Unable to set antenna");
11471 return WLAN_ERROR_STATE;
11472 }
11473
11474 return WM_SUCCESS;
11475 }
11476
wlan_get_antcfg(uint32_t * ant,uint16_t * evaluate_time,uint8_t * evaluate_mode,uint16_t * current_antenna)11477 int wlan_get_antcfg(uint32_t *ant, uint16_t *evaluate_time, uint8_t *evaluate_mode, uint16_t *current_antenna)
11478 {
11479 int rv = wifi_get_antenna((unsigned int *)ant, evaluate_time, evaluate_mode, current_antenna);
11480 if (rv != WM_SUCCESS)
11481 {
11482 wlcm_e("Unable to get current antenna");
11483 return WLAN_ERROR_STATE;
11484 }
11485
11486 return WM_SUCCESS;
11487 }
11488 #endif /*RW610*/
11489
11490 #endif
11491
wlan_wlcmgr_send_msg(enum wifi_event event,enum wifi_event_reason reason,void * data)11492 int wlan_wlcmgr_send_msg(enum wifi_event event, enum wifi_event_reason reason, void *data)
11493 {
11494 struct wifi_message msg;
11495
11496 msg.event = (uint16_t)event;
11497 msg.reason = reason;
11498 msg.data = (void *)data;
11499
11500 if (OSA_MsgQPut((osa_msgq_handle_t)wlan.events, &msg) == KOSA_StatusSuccess)
11501 {
11502 return WM_SUCCESS;
11503 }
11504
11505 return -WM_FAIL;
11506 }
11507
11508 /*
11509 This function validates input string for a valid WEP key, converts
11510 it to appropriate format
11511
11512 Returns positive integer equal to size of the output string
11513 for successful operation or -WM_FAIL in case of failure to convert. Note
11514 that the output string is not NULL terminated.
11515 */
load_wep_key(const uint8_t * input,uint8_t * output,uint8_t * output_len,const unsigned max_output_len)11516 int load_wep_key(const uint8_t *input, uint8_t *output, uint8_t *output_len, const unsigned max_output_len)
11517 {
11518 if (input == NULL || output == NULL)
11519 {
11520 return -WM_FAIL;
11521 }
11522
11523 unsigned len = *output_len;
11524
11525 /* fixme: add macros here after mlan integration */
11526 if (len == 10U || len == 26U)
11527 {
11528 /* Looks like this is an hexadecimal key */
11529 int ret = (int)wm_hex2bin(input, output, max_output_len);
11530 if (ret == 0)
11531 {
11532 return -WM_FAIL;
11533 }
11534
11535 len = len / 2U;
11536 }
11537 else if (len == 5U || len == 13U)
11538 {
11539 /* Looks like this is ASCII key */
11540 if (len > max_output_len)
11541 {
11542 return -WM_FAIL;
11543 }
11544
11545 (void)memcpy((void *)output, (const void *)input, len);
11546 }
11547 else
11548 {
11549 return -WM_FAIL;
11550 }
11551
11552 *output_len = (uint8_t)len;
11553
11554 return WM_SUCCESS;
11555 }
11556
get_split_scan_delay_ms(void)11557 int get_split_scan_delay_ms(void)
11558 {
11559 return g_wifi_scan_params.split_scan_delay;
11560 }
11561
wlan_get_firmware_version_ext(void)11562 char *wlan_get_firmware_version_ext(void)
11563 {
11564 return wlan.fw_ver_ext.version_str;
11565 }
11566
wlan_get_uap_supported_max_clients(void)11567 unsigned int wlan_get_uap_supported_max_clients(void)
11568 {
11569 return wlan.uap_supported_max_sta_num;
11570 }
11571
wlan_get_uap_max_clients(unsigned int * max_sta_num)11572 int wlan_get_uap_max_clients(unsigned int *max_sta_num)
11573 {
11574 return wifi_get_uap_max_clients(max_sta_num);
11575 }
11576
wlan_set_uap_max_clients(unsigned int max_sta_num)11577 int wlan_set_uap_max_clients(unsigned int max_sta_num)
11578 {
11579 int ret = -WM_FAIL;
11580
11581 if (is_uap_started() != 0)
11582 {
11583 wlcm_e(
11584 "Cannot set the max station number "
11585 "as the uAP is already running");
11586 return -WM_FAIL;
11587 }
11588 else if (max_sta_num > wlan.uap_supported_max_sta_num)
11589 {
11590 wlcm_e(
11591 "Maximum supported station number "
11592 "limit is = %d",
11593 wlan.uap_supported_max_sta_num);
11594 return -WM_FAIL;
11595 }
11596 else
11597 {
11598 ret = wifi_set_uap_max_clients(&max_sta_num);
11599
11600 if (ret != WM_SUCCESS)
11601 {
11602 return ret;
11603 }
11604
11605 #if CONFIG_WPA_SUPP
11606 #if CONFIG_WPA_SUPP_AP
11607 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
11608 struct netif *uap_netif = net_get_uap_interface();
11609
11610 wpa_supp_set_ap_max_num_sta(uap_netif, max_sta_num);
11611 #endif
11612 #endif
11613 #endif
11614 return ret;
11615 }
11616 }
11617
wlan_get_mgmt_ie(enum wlan_bss_type bss_type,IEEEtypes_ElementId_t index,void * buf,unsigned int * buf_len)11618 int wlan_get_mgmt_ie(enum wlan_bss_type bss_type, IEEEtypes_ElementId_t index, void *buf, unsigned int *buf_len)
11619 {
11620 return wifi_get_mgmt_ie((mlan_bss_type)bss_type, index, buf, buf_len);
11621 }
11622
wlan_set_mgmt_ie(enum wlan_bss_type bss_type,IEEEtypes_ElementId_t id,void * buf,unsigned int buf_len)11623 int wlan_set_mgmt_ie(enum wlan_bss_type bss_type, IEEEtypes_ElementId_t id, void *buf, unsigned int buf_len)
11624 {
11625 return wifi_set_mgmt_ie((mlan_bss_type)bss_type, id, buf, buf_len);
11626 }
11627
11628 #ifdef SD8801
wlan_get_ext_coex_stats(wlan_ext_coex_stats_t * ext_coex_stats)11629 int wlan_get_ext_coex_stats(wlan_ext_coex_stats_t *ext_coex_stats)
11630 {
11631 return wifi_get_ext_coex_stats(ext_coex_stats);
11632 }
11633
wlan_set_ext_coex_config(const wlan_ext_coex_config_t ext_coex_config)11634 int wlan_set_ext_coex_config(const wlan_ext_coex_config_t ext_coex_config)
11635 {
11636 return wifi_set_ext_coex_config(&ext_coex_config);
11637 }
11638 #endif
11639
wlan_clear_mgmt_ie(enum wlan_bss_type bss_type,IEEEtypes_ElementId_t index,int mgmt_bitmap_index)11640 int wlan_clear_mgmt_ie(enum wlan_bss_type bss_type, IEEEtypes_ElementId_t index, int mgmt_bitmap_index)
11641 {
11642 return wifi_clear_mgmt_ie((mlan_bss_type)bss_type, index, mgmt_bitmap_index);
11643 }
11644
wlan_set_txbfcap(unsigned int tx_bf_cap)11645 int wlan_set_txbfcap(unsigned int tx_bf_cap)
11646 {
11647 return wifi_set_txbfcap(tx_bf_cap);
11648 }
11649
wlan_set_htcapinfo(unsigned int htcapinfo)11650 int wlan_set_htcapinfo(unsigned int htcapinfo)
11651 {
11652 return wifi_set_htcapinfo(htcapinfo);
11653 }
11654
wlan_set_httxcfg(unsigned short httxcfg)11655 int wlan_set_httxcfg(unsigned short httxcfg)
11656 {
11657 return wifi_set_httxcfg(httxcfg);
11658 }
11659
wlan_set_txratecfg(wlan_ds_rate ds_rate,mlan_bss_type bss_type)11660 int wlan_set_txratecfg(wlan_ds_rate ds_rate, mlan_bss_type bss_type)
11661 {
11662 return wifi_set_txratecfg(ds_rate, bss_type);
11663 }
11664
wlan_get_txratecfg(wlan_ds_rate * ds_rate,mlan_bss_type bss_type)11665 int wlan_get_txratecfg(wlan_ds_rate *ds_rate, mlan_bss_type bss_type)
11666 {
11667 int ret;
11668
11669 ret = wifi_get_txratecfg(ds_rate, bss_type);
11670
11671 if (ret != WM_SUCCESS)
11672 {
11673 return ret;
11674 }
11675
11676 ret = wifi_get_data_rate(ds_rate, bss_type);
11677
11678 if (ret != WM_SUCCESS)
11679 {
11680 return ret;
11681 }
11682
11683 return WM_SUCCESS;
11684 }
11685
wlan_set_sta_tx_power(t_u32 power_level)11686 int wlan_set_sta_tx_power(t_u32 power_level)
11687 {
11688 return wifi_set_tx_power(power_level);
11689 }
11690
wlan_get_sta_tx_power(t_u32 * power_level)11691 int wlan_get_sta_tx_power(t_u32 *power_level)
11692 {
11693 return wifi_get_tx_power(power_level);
11694 }
11695
11696 #if CONFIG_COMPRESS_TX_PWTBL
wlan_set_region_power_cfg(const t_u8 * data,t_u16 len)11697 int wlan_set_region_power_cfg(const t_u8 *data, t_u16 len)
11698 {
11699 return wifi_set_region_power_cfg(data, len);
11700 }
11701 #endif
11702
wlan_set_chanlist_and_txpwrlimit(wlan_chanlist_t * chanlist,wlan_txpwrlimit_t * txpwrlimit)11703 int wlan_set_chanlist_and_txpwrlimit(wlan_chanlist_t *chanlist, wlan_txpwrlimit_t *txpwrlimit)
11704 {
11705 int ret = WM_SUCCESS;
11706
11707 ret = wlan_set_chanlist(chanlist);
11708 if (ret != WM_SUCCESS)
11709 {
11710 wlcm_e("Cannot set Channel List");
11711 return ret;
11712 }
11713
11714 ret = wlan_set_txpwrlimit(txpwrlimit);
11715 if (ret != WM_SUCCESS)
11716 {
11717 wlcm_e("Cannot set Tx Power");
11718 }
11719
11720 return ret;
11721 }
11722
wlan_set_chanlist(wlan_chanlist_t * chanlist)11723 int wlan_set_chanlist(wlan_chanlist_t *chanlist)
11724 {
11725 if (chanlist != NULL)
11726 {
11727 return wifi_set_chanlist(chanlist);
11728 }
11729
11730 return -WM_FAIL;
11731 }
11732
wlan_get_chanlist(wlan_chanlist_t * chanlist)11733 int wlan_get_chanlist(wlan_chanlist_t *chanlist)
11734 {
11735 if (chanlist != NULL)
11736 {
11737 return wifi_get_chanlist(chanlist);
11738 }
11739
11740 return -WM_FAIL;
11741 }
11742
wlan_set_txpwrlimit(wlan_txpwrlimit_t * txpwrlimit)11743 int wlan_set_txpwrlimit(wlan_txpwrlimit_t *txpwrlimit)
11744 {
11745 if (txpwrlimit != NULL)
11746 {
11747 return wifi_set_txpwrlimit(txpwrlimit);
11748 }
11749
11750 return -WM_FAIL;
11751 }
11752
wlan_get_txpwrlimit(wifi_SubBand_t subband,wifi_txpwrlimit_t * txpwrlimit)11753 int wlan_get_txpwrlimit(wifi_SubBand_t subband, wifi_txpwrlimit_t *txpwrlimit)
11754 {
11755 if (txpwrlimit != NULL)
11756 {
11757 (void)memset(txpwrlimit, 0x00, sizeof(wifi_txpwrlimit_t));
11758 return wifi_get_txpwrlimit(subband, txpwrlimit);
11759 }
11760
11761 return -WM_FAIL;
11762 }
11763
11764 #if WLAN_LOW_POWER_ENABLE
wlan_enable_low_pwr_mode()11765 int wlan_enable_low_pwr_mode()
11766 {
11767 if (wlan.status == WLCMGR_INACTIVE)
11768 {
11769 wifi_enable_low_pwr_mode();
11770 return WM_SUCCESS;
11771 }
11772 else
11773 return -WM_FAIL;
11774 }
11775 #endif
11776
wlan_set_reassoc_control(bool reassoc_control)11777 void wlan_set_reassoc_control(bool reassoc_control)
11778 {
11779 wlan.reassoc_control = reassoc_control;
11780 wlcm_d("Reassoc control %s", reassoc_control ? "enabled" : "disabled");
11781 }
11782
wlan_set_ed_mac_mode(wlan_ed_mac_ctrl_t wlan_ed_mac_ctrl)11783 int wlan_set_ed_mac_mode(wlan_ed_mac_ctrl_t wlan_ed_mac_ctrl)
11784 {
11785 return wifi_set_ed_mac_mode(&wlan_ed_mac_ctrl, MLAN_BSS_TYPE_STA);
11786 }
11787
wlan_get_ed_mac_mode(wlan_ed_mac_ctrl_t * wlan_ed_mac_ctrl)11788 int wlan_get_ed_mac_mode(wlan_ed_mac_ctrl_t *wlan_ed_mac_ctrl)
11789 {
11790 return wifi_get_ed_mac_mode(wlan_ed_mac_ctrl, MLAN_BSS_TYPE_STA);
11791 }
11792
wlan_set_uap_ed_mac_mode(wlan_ed_mac_ctrl_t wlan_ed_mac_ctrl)11793 int wlan_set_uap_ed_mac_mode(wlan_ed_mac_ctrl_t wlan_ed_mac_ctrl)
11794 {
11795 return wifi_set_ed_mac_mode(&wlan_ed_mac_ctrl, MLAN_BSS_TYPE_UAP);
11796 }
11797
wlan_get_uap_ed_mac_mode(wlan_ed_mac_ctrl_t * wlan_ed_mac_ctrl)11798 int wlan_get_uap_ed_mac_mode(wlan_ed_mac_ctrl_t *wlan_ed_mac_ctrl)
11799 {
11800 return wifi_get_ed_mac_mode(wlan_ed_mac_ctrl, MLAN_BSS_TYPE_UAP);
11801 }
11802
wlan_get_11d_enable_status(void)11803 bool wlan_get_11d_enable_status(void)
11804 {
11805 return wrapper_wlan_11d_support_is_enabled();
11806 }
11807
wlan_remain_on_channel(const enum wlan_bss_type bss_type,const bool status,const uint8_t channel,const uint32_t duration)11808 int wlan_remain_on_channel(const enum wlan_bss_type bss_type,
11809 const bool status,
11810 const uint8_t channel,
11811 const uint32_t duration)
11812 {
11813 wifi_remain_on_channel_t roc;
11814
11815 (void)memset(&roc, 0x00, sizeof(wifi_remain_on_channel_t));
11816
11817 roc.remove = (uint16_t)!status;
11818
11819 roc.channel = channel;
11820
11821 roc.remain_period = duration;
11822
11823 #if CONFIG_5GHz_SUPPORT
11824 if (channel > 14)
11825 {
11826 roc.bandcfg = 1;
11827 }
11828 #endif
11829
11830 return wifi_send_remain_on_channel_cmd((uint32_t)bss_type, &roc);
11831 }
11832
wlan_get_otp_user_data(uint8_t * buf,uint16_t len)11833 int wlan_get_otp_user_data(uint8_t *buf, uint16_t len)
11834 {
11835 if (buf == NULL)
11836 {
11837 return -WM_E_INVAL;
11838 }
11839
11840 return wifi_get_otp_user_data(buf, len);
11841 }
11842
11843 #if CONFIG_WIFI_GET_LOG
wlan_get_log(wlan_pkt_stats_t * stats)11844 int wlan_get_log(wlan_pkt_stats_t *stats)
11845 {
11846 if (!stats)
11847 return -WM_E_INVAL;
11848
11849 return wifi_get_log(stats, MLAN_BSS_TYPE_STA);
11850 }
11851
wlan_uap_get_log(wlan_pkt_stats_t * stats)11852 int wlan_uap_get_log(wlan_pkt_stats_t *stats)
11853 {
11854 if (!stats)
11855 return -WM_E_INVAL;
11856
11857 return wifi_get_log(stats, MLAN_BSS_TYPE_UAP);
11858 }
11859 #endif
11860
wlan_get_cal_data(wlan_cal_data_t * cal_data)11861 int wlan_get_cal_data(wlan_cal_data_t *cal_data)
11862 {
11863 if (cal_data == NULL)
11864 {
11865 return -WM_E_INVAL;
11866 }
11867
11868 return wifi_get_cal_data(cal_data);
11869 }
11870
11871 #if CONFIG_AUTO_RECONNECT
wlan_auto_reconnect_enable(wlan_auto_reconnect_config_t auto_reconnect_config)11872 int wlan_auto_reconnect_enable(wlan_auto_reconnect_config_t auto_reconnect_config)
11873 {
11874 if (is_sta_connected())
11875 {
11876 wlcm_e("Can not enable auto reconnect in connected state");
11877 return -WM_E_INVAL;
11878 }
11879
11880 return wifi_auto_reconnect_enable(auto_reconnect_config);
11881 }
11882
wlan_auto_reconnect_disable(void)11883 int wlan_auto_reconnect_disable(void)
11884 {
11885 return wifi_auto_reconnect_disable();
11886 }
11887
wlan_get_auto_reconnect_config(wlan_auto_reconnect_config_t * auto_reconnect_config)11888 int wlan_get_auto_reconnect_config(wlan_auto_reconnect_config_t *auto_reconnect_config)
11889 {
11890 if (auto_reconnect_config == NULL)
11891 {
11892 return -WM_E_INVAL;
11893 }
11894
11895 return wifi_get_auto_reconnect_config(auto_reconnect_config);
11896 }
11897 #endif
11898
wlan_get_tsf(uint32_t * tsf_high,uint32_t * tsf_low)11899 int wlan_get_tsf(uint32_t *tsf_high, uint32_t *tsf_low)
11900 {
11901 return wifi_get_tsf(tsf_high, tsf_low);
11902 }
11903
wlan_tcp_keep_alive(wlan_tcp_keep_alive_t * tcp_keep_alive)11904 int wlan_tcp_keep_alive(wlan_tcp_keep_alive_t *tcp_keep_alive)
11905 {
11906 int ret;
11907 unsigned int ipv4_addr;
11908
11909 ret = wlan_get_ipv4_addr(&ipv4_addr);
11910 if (ret != WM_SUCCESS)
11911 {
11912 wlcm_e("Cannot get IP");
11913 return -WM_FAIL;
11914 }
11915
11916 return wifi_tcp_keep_alive(tcp_keep_alive, wlan.sta_mac, ipv4_addr);
11917 }
11918
11919 #if CONFIG_NAT_KEEP_ALIVE
wlan_nat_keep_alive(wlan_nat_keep_alive_t * nat_keep_alive)11920 int wlan_nat_keep_alive(wlan_nat_keep_alive_t *nat_keep_alive)
11921 {
11922 int ret;
11923 unsigned int ipv4_addr;
11924 t_u16 src_port = 4500;
11925
11926 ret = wlan_get_ipv4_addr(&ipv4_addr);
11927 if (ret != WM_SUCCESS)
11928 {
11929 wlcm_e("Cannot get IP");
11930 return -WM_FAIL;
11931 }
11932
11933 return wifi_nat_keep_alive(nat_keep_alive, wlan.sta_mac, ipv4_addr, src_port);
11934 }
11935 #endif
11936
11937 #if CONFIG_CLOUD_KEEP_ALIVE
11938 /* Here the length of ip_packet for test is 40 */
11939 static t_u16 pkt_len_default = 40;
11940 /* ip packet content */
11941 static t_u8 packet_default[40] = {0x45, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0xff, 0x06, 0x00, 0x00, 0xc0, 0xa8,
11942 0x00, 0x7c, 0xc0, 0xa8, 0x00, 0x8a, 0xc0, 0x03, 0x22, 0xb7, 0xb0, 0xb6, 0x60, 0x9f,
11943 0x42, 0xdd, 0x9e, 0x1e, 0x50, 0x18, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00};
11944
wlan_save_cloud_keep_alive_params(wlan_cloud_keep_alive_t * cloud_keep_alive,t_u16 src_port,t_u16 dst_port,t_u32 seq_number,t_u32 ack_number,t_u8 enable)11945 int wlan_save_cloud_keep_alive_params(wlan_cloud_keep_alive_t *cloud_keep_alive,
11946 t_u16 src_port,
11947 t_u16 dst_port,
11948 t_u32 seq_number,
11949 t_u32 ack_number,
11950 t_u8 enable)
11951 {
11952 if (enable)
11953 {
11954 if (cloud_keep_alive == NULL)
11955 {
11956 return -WM_E_INVAL;
11957 }
11958
11959 if (!is_sta_connected())
11960 {
11961 wlcm_e("Can not start cloud keep alive in disconnected state");
11962 return -WM_E_INVAL;
11963 }
11964
11965 if (cloud_keep_alive->mkeep_alive_id >= MAX_KEEP_ALIVE_ID)
11966 {
11967 wlcm_e("Invalid keep alive id");
11968 return -WM_E_INVAL;
11969 }
11970
11971 /* Get source mac address */
11972 uint8_t sta_mac[MLAN_MAC_ADDR_LENGTH];
11973 if (wlan_get_mac_address(sta_mac))
11974 {
11975 wlcm_e("Unable to retrieve MAC address\r\n");
11976 }
11977 (void)memcpy(cloud_keep_alive->src_mac, sta_mac, MLAN_MAC_ADDR_LENGTH);
11978
11979 /* Get source ip */
11980 int ret = -WM_FAIL;
11981 ret = wlan_get_ipv4_addr(&cloud_keep_alive->src_ip);
11982 if (ret != WM_SUCCESS)
11983 {
11984 wlcm_e("Cannot get IP");
11985 }
11986 (void)memcpy(&cloud_keep_alive_param[cloud_keep_alive->mkeep_alive_id], cloud_keep_alive, sizeof(wlan_cloud_keep_alive_t));
11987 }
11988 else
11989 {
11990 int i;
11991
11992 for (i = 0; i < MAX_KEEP_ALIVE_ID; i++)
11993 {
11994 cloud_keep_alive = &cloud_keep_alive_param[i];
11995
11996 if (cloud_keep_alive && cloud_keep_alive->enable && (ntohs(dst_port) == cloud_keep_alive->dst_port))
11997 {
11998 /* Copy source port, destination port, sequece number, ack number, window size for keep alive.
11999 IP header checksum and TCP pesudo header checksum are calculated by WLAN FW */
12000 (void)memcpy(packet_default + 12, &cloud_keep_alive->src_ip, sizeof(cloud_keep_alive->src_ip));
12001 (void)memcpy(packet_default + 16, &cloud_keep_alive->dst_ip, sizeof(cloud_keep_alive->dst_ip));
12002 (void)memcpy(packet_default + 20, &src_port, sizeof(src_port));
12003 (void)memcpy(packet_default + 22, &dst_port, sizeof(dst_port));
12004 (void)memcpy(packet_default + 24, &seq_number, sizeof(seq_number));
12005 (void)memcpy(packet_default + 28, &ack_number, sizeof(ack_number));
12006
12007 cloud_keep_alive->pkt_len = pkt_len_default;
12008 (void)memcpy(cloud_keep_alive->packet, packet_default, cloud_keep_alive->pkt_len);
12009
12010 cloud_keep_alive->cached = MTRUE;
12011 }
12012 }
12013 }
12014
12015 return WM_SUCCESS;
12016 }
12017
wlan_cloud_keep_alive_enabled(t_u32 dst_ip,t_u16 dst_port)12018 int wlan_cloud_keep_alive_enabled(t_u32 dst_ip, t_u16 dst_port)
12019 {
12020 int i;
12021 wifi_cloud_keep_alive_t *cloud_keep_alive = NULL;
12022
12023 for (i = 0; i < MAX_KEEP_ALIVE_ID; i++)
12024 {
12025 cloud_keep_alive = &cloud_keep_alive_param[i];
12026 if (cloud_keep_alive && (cloud_keep_alive->dst_ip == dst_ip) && (cloud_keep_alive->dst_port == dst_port))
12027 {
12028 return 1;
12029 }
12030 }
12031
12032 return 0;
12033 }
12034
wlan_start_cloud_keep_alive(void)12035 int wlan_start_cloud_keep_alive(void)
12036 {
12037 int i;
12038 wifi_cloud_keep_alive_t *cloud_keep_alive = NULL;
12039
12040 for (i = 0; i < MAX_KEEP_ALIVE_ID; i++)
12041 {
12042 cloud_keep_alive = &cloud_keep_alive_param[i];
12043 if (cloud_keep_alive && cloud_keep_alive->cached && cloud_keep_alive->enable)
12044 {
12045 cloud_keep_alive->cached = MFALSE;
12046 wifi_cloud_keep_alive(cloud_keep_alive, MLAN_ACT_SET, NULL);
12047 }
12048 }
12049
12050 return WM_SUCCESS;
12051 }
12052
wlan_stop_cloud_keep_alive(wlan_cloud_keep_alive_t * cloud_keep_alive)12053 int wlan_stop_cloud_keep_alive(wlan_cloud_keep_alive_t *cloud_keep_alive)
12054 {
12055 t_u8 enable = MTRUE;
12056
12057 if (cloud_keep_alive == NULL)
12058 return -WM_E_INVAL;
12059
12060 wifi_cloud_keep_alive(cloud_keep_alive, MLAN_ACT_GET, &enable);
12061
12062 if (enable == MFALSE)
12063 {
12064 wlcm_e("Cloud keep alive is already stoped");
12065 return 0;
12066 }
12067 return wifi_cloud_keep_alive(cloud_keep_alive, MLAN_ACT_SET, NULL);
12068 }
12069 #endif
12070
wlan_get_beacon_period(void)12071 uint16_t wlan_get_beacon_period(void)
12072 {
12073 struct wlan_network* network = NULL;
12074
12075 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED)))
12076 {
12077 network = &wlan.networks[wlan.cur_network_idx];
12078 }
12079
12080 if (network == NULL)
12081 {
12082 wlcm_e("cannot get network info");
12083 return 0;
12084 }
12085
12086 return network->beacon_period;
12087 }
12088
12089 OSA_SEMAPHORE_HANDLE_DEFINE(wlan_dtim_sem);
12090
12091 static uint8_t dtim_period;
12092
pscan_cb(unsigned int count)12093 static int pscan_cb(unsigned int count)
12094 {
12095 struct wlan_scan_result res;
12096 unsigned int i;
12097 int err;
12098
12099 dtim_period = 0;
12100
12101 if (count == 0U)
12102 {
12103 (void)PRINTF("networks not found\r\n");
12104 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan_dtim_sem);
12105 return 0;
12106 }
12107
12108 for (i = 0; i < count; i++)
12109 {
12110 err = wlan_get_scan_result(i, &res);
12111 if (err != 0)
12112 {
12113 (void)PRINTF("Error: can't get scan res %d\r\n", i);
12114 continue;
12115 }
12116
12117 dtim_period = res.dtim_period;
12118 }
12119
12120 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan_dtim_sem);
12121
12122 return 0;
12123 }
12124
wlan_get_dtim_period(void)12125 uint8_t wlan_get_dtim_period(void)
12126 {
12127 osa_status_t status;
12128
12129 status = OSA_SemaphoreCreateBinary((osa_semaphore_handle_t)wlan_dtim_sem);
12130 if (status != KOSA_StatusSuccess)
12131 {
12132 return 0;
12133 }
12134
12135 if (wlan_pscan(pscan_cb) != 0)
12136 {
12137 (void)PRINTF("Error: scan request failed\r\n");
12138 (void)OSA_SemaphorePost((osa_semaphore_handle_t)wlan_dtim_sem);
12139 (void)OSA_SemaphoreDestroy((osa_semaphore_handle_t)wlan_dtim_sem);
12140 return 0;
12141 }
12142
12143 /* Wait till scan for DTIM is complete */
12144 /*TODO:This need to be handled in better way. */
12145 if (OSA_SemaphoreWait((osa_semaphore_handle_t)wlan_dtim_sem, 500) != KOSA_StatusSuccess)
12146 {
12147 wlcm_e("Do not call this API from wlan event handler\r\n");
12148 dtim_period = 0;
12149 }
12150 (void)OSA_SemaphoreDestroy((osa_semaphore_handle_t)wlan_dtim_sem);
12151
12152 return dtim_period;
12153 }
12154
wlan_get_data_rate(wlan_ds_rate * ds_rate,mlan_bss_type bss_type)12155 int wlan_get_data_rate(wlan_ds_rate *ds_rate, mlan_bss_type bss_type)
12156 {
12157 return wifi_get_data_rate(ds_rate, bss_type);
12158 }
12159
wlan_set_pmfcfg(uint8_t mfpc,uint8_t mfpr)12160 static int wlan_set_pmfcfg(uint8_t mfpc, uint8_t mfpr)
12161 {
12162 if (!mfpc && mfpr)
12163 {
12164 return -WM_FAIL;
12165 }
12166
12167 return wifi_set_pmfcfg(mfpc, mfpr);
12168 }
12169
wlan_get_pmfcfg(uint8_t * mfpc,uint8_t * mfpr)12170 int wlan_get_pmfcfg(uint8_t *mfpc, uint8_t *mfpr)
12171 {
12172 return wifi_get_pmfcfg(mfpc, mfpr);
12173 }
12174
wlan_uap_get_pmfcfg(uint8_t * mfpc,uint8_t * mfpr)12175 int wlan_uap_get_pmfcfg(uint8_t *mfpc, uint8_t *mfpr)
12176 {
12177 if (is_uap_started())
12178 {
12179 return wifi_uap_get_pmfcfg(mfpc, mfpr);
12180 }
12181 return -WM_FAIL;
12182 }
12183
12184 #if CONFIG_TBTT_OFFSET
wlan_get_tbtt_offset(wlan_tbtt_offset_t * tbtt_offset)12185 int wlan_get_tbtt_offset(wlan_tbtt_offset_t *tbtt_offset)
12186 {
12187 return wifi_get_tbtt_offset(tbtt_offset);
12188 }
12189 #endif
12190
wlan_set_packet_filters(wlan_flt_cfg_t * flt_cfg)12191 int wlan_set_packet_filters(wlan_flt_cfg_t *flt_cfg)
12192 {
12193 return wifi_set_packet_filters(flt_cfg);
12194 }
12195
wlan_set_auto_arp(void)12196 int wlan_set_auto_arp(void)
12197 {
12198 int ret;
12199 unsigned int ipv4_addr;
12200 wlan_flt_cfg_t flt_cfg;
12201
12202 ret = wlan_get_ipv4_addr(&ipv4_addr);
12203 if (ret != WM_SUCCESS)
12204 {
12205 wlcm_e("Cannot get IP");
12206 return -WM_FAIL;
12207 }
12208
12209 (void)memset(&flt_cfg, 0, sizeof(wlan_flt_cfg_t));
12210
12211 flt_cfg.criteria = CRITERIA_BROADCAST;
12212 flt_cfg.nentries = 1;
12213
12214 flt_cfg.mef_entry[0].mode = MEF_MODE_HOST_SLEEP; // MBIT(0);
12215 flt_cfg.mef_entry[0].action = MEF_AUTO_ARP;
12216
12217 flt_cfg.mef_entry[0].filter_num = 3;
12218
12219 flt_cfg.mef_entry[0].filter_item[0].type = TYPE_BYTE_EQ;
12220 flt_cfg.mef_entry[0].filter_item[0].repeat = 6;
12221 flt_cfg.mef_entry[0].filter_item[0].offset = 0;
12222 flt_cfg.mef_entry[0].filter_item[0].num_byte_seq = 1;
12223 flt_cfg.mef_entry[0].filter_item[0].byte_seq[0] = 0xff;
12224 flt_cfg.mef_entry[0].rpn[1] = RPN_TYPE_AND;
12225
12226 flt_cfg.mef_entry[0].filter_item[1].type = TYPE_BYTE_EQ;
12227 flt_cfg.mef_entry[0].filter_item[1].repeat = 1;
12228 flt_cfg.mef_entry[0].filter_item[1].offset = 20;
12229 flt_cfg.mef_entry[0].filter_item[1].num_byte_seq = 2;
12230 (void)memcpy((void *)flt_cfg.mef_entry[0].filter_item[1].byte_seq, (const void *)"\x08\x06", 2);
12231 flt_cfg.mef_entry[0].rpn[2] = RPN_TYPE_AND;
12232
12233 flt_cfg.mef_entry[0].filter_item[2].type = TYPE_BYTE_EQ;
12234 flt_cfg.mef_entry[0].filter_item[2].repeat = 1;
12235 flt_cfg.mef_entry[0].filter_item[2].offset = 46;
12236 flt_cfg.mef_entry[0].filter_item[2].num_byte_seq = 4;
12237 (void)memcpy((void *)flt_cfg.mef_entry[0].filter_item[2].byte_seq, (const void *)&ipv4_addr, 4);
12238
12239 return wifi_set_packet_filters(&flt_cfg);
12240 }
12241
12242 #if !CONFIG_WPA_SUPP
is_broadcast_ether_addr(const t_u8 * addr)12243 static inline bool is_broadcast_ether_addr(const t_u8 *addr)
12244 {
12245 return (*(const t_u16 *)(addr + 0) & *(const t_u16 *)(addr + 2) & *(const t_u16 *)(addr + 4)) == 0xffff;
12246 }
12247 #endif
12248
12249 /**
12250 * @brief is_wowlan_pattern_supported
12251 *
12252 * @param priv A pointer to moal_private
12253 * @param pat A pointer to wowlan pattern
12254 * @param byte_seq A pointer to byte_seq
12255 *
12256 * @return 1 -- support, 0 -- not support
12257 */
is_wowlan_pattern_supported(wifi_wowlan_pattern_t * pat,t_u8 * byte_seq)12258 static t_bool is_wowlan_pattern_supported(wifi_wowlan_pattern_t *pat, t_u8 *byte_seq)
12259 {
12260 int j, k, valid_byte_cnt = 0;
12261 t_bool dont_care_byte = false;
12262
12263 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++)
12264 {
12265 for (k = 0; k < 8; k++)
12266 {
12267 if (pat->mask[j] & 1 << k)
12268 {
12269 (void)memcpy((void *)(byte_seq + valid_byte_cnt), (const void *)&pat->pattern[j * 8 + k], 1);
12270 valid_byte_cnt++;
12271 if (dont_care_byte)
12272 return false;
12273 }
12274 else
12275 {
12276 if (valid_byte_cnt)
12277 dont_care_byte = true;
12278 }
12279
12280 if (valid_byte_cnt > MAX_NUM_BYTE_SEQ)
12281 return false;
12282 }
12283 }
12284
12285 byte_seq[MAX_NUM_BYTE_SEQ] = valid_byte_cnt;
12286
12287 return true;
12288 }
12289
wlan_wowlan_cfg_ptn_match(wlan_wowlan_ptn_cfg_t * ptn_cfg)12290 int wlan_wowlan_cfg_ptn_match(wlan_wowlan_ptn_cfg_t *ptn_cfg)
12291 {
12292 wlan_flt_cfg_t flt_cfg;
12293 wifi_mef_entry_t *mef_entry;
12294 t_u8 byte_seq[MAX_NUM_BYTE_SEQ + 1];
12295 const t_u8 ipv4_mc_mac[] = {0x33, 0x33};
12296 const t_u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
12297 int filt_num = 0, i = 0, ret = 0;
12298 t_bool first_pat = true;
12299 memset(&flt_cfg, 0, sizeof(flt_cfg));
12300 // mef_cfg.mef_act_type = MEF_ACT_WOWLAN;
12301 mef_entry = &flt_cfg.mef_entry[0];
12302
12303 mef_entry->mode = MEF_MODE_HOST_SLEEP;
12304 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
12305
12306 for (i = 0; i < ptn_cfg->n_patterns; i++)
12307 {
12308 memset(byte_seq, 0, sizeof(byte_seq));
12309 if (!is_wowlan_pattern_supported(&ptn_cfg->patterns[i], byte_seq))
12310 {
12311 PRINTM(MERROR, "Pattern not supported\n");
12312 ret = -EOPNOTSUPP;
12313 return ret;
12314 }
12315 if (!ptn_cfg->patterns[i].pkt_offset)
12316 {
12317 if (!(byte_seq[0] & 0x01) && (byte_seq[MAX_NUM_BYTE_SEQ] == 1))
12318 {
12319 flt_cfg.criteria |= CRITERIA_UNICAST;
12320 continue;
12321 }
12322 else if (is_broadcast_ether_addr(byte_seq))
12323 {
12324 flt_cfg.criteria |= CRITERIA_BROADCAST;
12325 continue;
12326 }
12327 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) && (byte_seq[MAX_NUM_BYTE_SEQ] == 2)) ||
12328 (!memcmp(byte_seq, ipv6_mc_mac, 3) && (byte_seq[MAX_NUM_BYTE_SEQ] == 3)))
12329 {
12330 flt_cfg.criteria |= CRITERIA_MULTICAST;
12331 continue;
12332 }
12333 }
12334
12335 // mef_entry->filter_item[filt_num].fill_flag =
12336 // (FILLING_TYPE | FILLING_REPEAT | FILLING_BYTE_SEQ |
12337 // FILLING_OFFSET);
12338 mef_entry->filter_item[filt_num].repeat = 1;
12339 mef_entry->filter_item[filt_num].offset = ptn_cfg->patterns[i].pkt_offset;
12340 (void)memcpy((void *)mef_entry->filter_item[filt_num].byte_seq, (const void *)byte_seq, MAX_NUM_BYTE_SEQ);
12341 mef_entry->filter_item[filt_num].num_byte_seq = byte_seq[MAX_NUM_BYTE_SEQ];
12342 mef_entry->filter_item[filt_num].type = TYPE_BYTE_EQ;
12343 if (first_pat)
12344 first_pat = false;
12345 else
12346 mef_entry->rpn[filt_num] = RPN_TYPE_OR;
12347
12348 filt_num++;
12349 }
12350 if (ptn_cfg->enable)
12351 {
12352 // (void)memset(&flt_cfg, 0, sizeof(wlan_flt_cfg_t));
12353
12354 flt_cfg.criteria = CRITERIA_UNICAST | CRITERIA_BROADCAST | CRITERIA_MULTICAST;
12355 flt_cfg.nentries = 1;
12356
12357 flt_cfg.mef_entry[0].mode = MEF_MODE_HOST_SLEEP;
12358 flt_cfg.mef_entry[0].action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
12359
12360 flt_cfg.mef_entry[0].filter_num = 2;
12361
12362 flt_cfg.mef_entry[0].filter_item[filt_num].type = TYPE_BYTE_EQ;
12363 flt_cfg.mef_entry[0].filter_item[filt_num].repeat = 16;
12364 flt_cfg.mef_entry[0].filter_item[filt_num].offset = 56;
12365 flt_cfg.mef_entry[0].filter_item[filt_num].num_byte_seq = MLAN_MAC_ADDR_LENGTH;
12366 (void)memcpy((void *)flt_cfg.mef_entry[0].filter_item[filt_num].byte_seq, (const void *)wlan.sta_mac,
12367 MLAN_MAC_ADDR_LENGTH);
12368 if (filt_num)
12369 flt_cfg.mef_entry[0].rpn[filt_num] = RPN_TYPE_OR;
12370 filt_num++;
12371 // flt_cfg.mef_entry.filter_item[1].fill_flag = (FILLING_TYPE | FILLING_REPEAT | FILLING_BYTE_SEQ |
12372 // FILLING_OFFSET);
12373 flt_cfg.mef_entry[0].filter_item[filt_num].type = TYPE_BYTE_EQ;
12374 flt_cfg.mef_entry[0].filter_item[filt_num].repeat = 16;
12375 flt_cfg.mef_entry[0].filter_item[filt_num].offset = 28;
12376 flt_cfg.mef_entry[0].filter_item[filt_num].num_byte_seq = MLAN_MAC_ADDR_LENGTH;
12377 (void)memcpy((void *)flt_cfg.mef_entry[0].filter_item[filt_num].byte_seq, (const void *)wlan.sta_mac,
12378 MLAN_MAC_ADDR_LENGTH);
12379 if (filt_num)
12380 flt_cfg.mef_entry[0].rpn[filt_num] = RPN_TYPE_OR;
12381 filt_num++;
12382 }
12383 flt_cfg.mef_entry[0].filter_num = filt_num;
12384 return wifi_set_packet_filters(&flt_cfg);
12385 }
12386
12387 #if CONFIG_AUTO_PING
wlan_set_auto_ping()12388 int wlan_set_auto_ping()
12389 {
12390 wlan_flt_cfg_t flt_cfg;
12391
12392 (void)memset(&flt_cfg, 0, sizeof(wlan_flt_cfg_t));
12393
12394 flt_cfg.criteria = (MBIT(0) | MBIT(1));
12395 flt_cfg.nentries = 1;
12396
12397 flt_cfg.mef_entry[0].mode = MBIT(0);
12398 flt_cfg.mef_entry[0].action = 0x20;
12399
12400 flt_cfg.mef_entry[0].filter_num = 2;
12401
12402 flt_cfg.mef_entry[0].filter_item[0].type = TYPE_BYTE_EQ;
12403 flt_cfg.mef_entry[0].filter_item[0].repeat = 1;
12404 flt_cfg.mef_entry[0].filter_item[0].offset = IPV4_PKT_OFFSET;
12405 flt_cfg.mef_entry[0].filter_item[0].num_byte_seq = 2;
12406 (void)memcpy((void *)flt_cfg.mef_entry[0].filter_item[0].byte_seq, (const void *)"\x08\x00", 2);
12407 flt_cfg.mef_entry[0].rpn[1] = RPN_TYPE_AND;
12408
12409 flt_cfg.mef_entry[0].filter_item[1].type = TYPE_DNUM_EQ;
12410 flt_cfg.mef_entry[0].filter_item[1].pattern = ICMP_OF_IP_PROTOCOL;
12411 flt_cfg.mef_entry[0].filter_item[1].offset = IP_PROTOCOL_OFFSET;
12412 flt_cfg.mef_entry[0].filter_item[1].num_bytes = 1;
12413
12414 return wifi_set_packet_filters(&flt_cfg);
12415 }
12416 #endif /* CONFIG_AUTO_PING */
12417
wlan_set_ipv6_ns_offload()12418 int wlan_set_ipv6_ns_offload()
12419 {
12420 wlan_flt_cfg_t flt_cfg;
12421
12422 (void)memset(&flt_cfg, 0, sizeof(wlan_flt_cfg_t));
12423
12424 flt_cfg.criteria = (MBIT(1) | MBIT(3));
12425 flt_cfg.nentries = 1;
12426
12427 flt_cfg.mef_entry[0].mode = MBIT(0);
12428 flt_cfg.mef_entry[0].action = 0x40;
12429
12430 flt_cfg.mef_entry[0].filter_num = 2;
12431
12432 flt_cfg.mef_entry[0].filter_item[0].type = TYPE_BYTE_EQ;
12433 flt_cfg.mef_entry[0].filter_item[0].repeat = 1;
12434 flt_cfg.mef_entry[0].filter_item[0].offset = 20;
12435 flt_cfg.mef_entry[0].filter_item[0].num_byte_seq = 2;
12436 (void)memcpy((void *)flt_cfg.mef_entry[0].filter_item[0].byte_seq, (const void *)"\x86\xdd", 2);
12437 flt_cfg.mef_entry[0].rpn[1] = RPN_TYPE_AND;
12438
12439 flt_cfg.mef_entry[0].filter_item[1].type = TYPE_BYTE_EQ;
12440 flt_cfg.mef_entry[0].filter_item[1].repeat = 1;
12441 flt_cfg.mef_entry[0].filter_item[1].offset = 62;
12442 flt_cfg.mef_entry[0].filter_item[1].num_byte_seq = 1;
12443 (void)memcpy((void *)flt_cfg.mef_entry[0].filter_item[1].byte_seq, (const void *)"\x87", 1);
12444
12445 return wifi_set_packet_filters(&flt_cfg);
12446 }
12447
wlan_get_current_bssid(uint8_t * bssid)12448 int wlan_get_current_bssid(uint8_t *bssid)
12449 {
12450 struct wlan_network* network = NULL;
12451
12452 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED)))
12453 {
12454 network = &wlan.networks[wlan.cur_network_idx];
12455 }
12456
12457 if (network == NULL)
12458 {
12459 wlcm_e("cannot get network info");
12460 return -WM_FAIL;
12461 }
12462 if (bssid != NULL)
12463 {
12464 (void)memcpy((void *)bssid, (const void *)network->bssid, IEEEtypes_ADDRESS_SIZE);
12465 return WM_SUCCESS;
12466 }
12467
12468 return -WM_FAIL;
12469 }
12470
wlan_get_current_channel(void)12471 uint8_t wlan_get_current_channel(void)
12472 {
12473 struct wlan_network* network = NULL;
12474
12475 if (wlan.running && (is_state(CM_STA_CONNECTED) || is_state(CM_STA_ASSOCIATED)))
12476 {
12477 network = &wlan.networks[wlan.cur_network_idx];
12478 }
12479
12480 if (network == NULL)
12481 {
12482 wlcm_e("cannot get network info");
12483 return 0;
12484 }
12485
12486 return (uint8_t)network->channel;
12487 }
12488
wlan_sta_ampdu_tx_enable(void)12489 void wlan_sta_ampdu_tx_enable(void)
12490 {
12491 wifi_sta_ampdu_tx_enable();
12492 }
12493
wlan_sta_ampdu_tx_disable(void)12494 void wlan_sta_ampdu_tx_disable(void)
12495 {
12496 wifi_sta_ampdu_tx_disable();
12497 }
12498
wlan_sta_ampdu_rx_enable(void)12499 void wlan_sta_ampdu_rx_enable(void)
12500 {
12501 wifi_sta_ampdu_rx_enable();
12502 }
12503
wlan_sta_ampdu_rx_disable(void)12504 void wlan_sta_ampdu_rx_disable(void)
12505 {
12506 wifi_sta_ampdu_rx_disable();
12507 }
12508
wlan_uap_ampdu_tx_enable(void)12509 void wlan_uap_ampdu_tx_enable(void)
12510 {
12511 wifi_uap_ampdu_tx_enable();
12512 }
12513
wlan_uap_ampdu_tx_disable(void)12514 void wlan_uap_ampdu_tx_disable(void)
12515 {
12516 wifi_uap_ampdu_tx_disable();
12517 }
12518
wlan_uap_ampdu_rx_enable(void)12519 void wlan_uap_ampdu_rx_enable(void)
12520 {
12521 wifi_uap_ampdu_rx_enable();
12522 }
12523
wlan_uap_ampdu_rx_disable(void)12524 void wlan_uap_ampdu_rx_disable(void)
12525 {
12526 wifi_uap_ampdu_rx_disable();
12527 }
12528
12529 #if CONFIG_WIFI_AMPDU_CTRL
wlan_sta_ampdu_tx_enable_per_tid(t_u8 tid)12530 void wlan_sta_ampdu_tx_enable_per_tid(t_u8 tid)
12531 {
12532 wifi_sta_ampdu_tx_enable_per_tid(tid);
12533 }
12534
wlan_sta_ampdu_rx_enable_per_tid(t_u8 tid)12535 void wlan_sta_ampdu_rx_enable_per_tid(t_u8 tid)
12536 {
12537 wifi_sta_ampdu_rx_enable_per_tid(tid);
12538 }
12539
wlan_uap_ampdu_tx_enable_per_tid(t_u8 tid)12540 void wlan_uap_ampdu_tx_enable_per_tid(t_u8 tid)
12541 {
12542 wifi_uap_ampdu_tx_enable_per_tid(tid);
12543 }
12544
wlan_uap_ampdu_rx_enable_per_tid(t_u8 tid)12545 void wlan_uap_ampdu_rx_enable_per_tid(t_u8 tid)
12546 {
12547 wifi_uap_ampdu_rx_enable_per_tid(tid);
12548 }
12549 #endif
12550
wlan_uap_set_scan_chan_list(wifi_scan_chan_list_t scan_chan_list)12551 void wlan_uap_set_scan_chan_list(wifi_scan_chan_list_t scan_chan_list)
12552 {
12553 wlan_uap_scan_chan_list_set = true;
12554 (void)memcpy((void *)&wlan.scan_chan_list, (const void *)&scan_chan_list, sizeof(wifi_scan_chan_list_t));
12555 }
12556
wlan_uap_set_beacon_period(const uint16_t beacon_period)12557 void wlan_uap_set_beacon_period(const uint16_t beacon_period)
12558 {
12559 #if CONFIG_WPA_SUPP
12560 #if CONFIG_WPA_SUPP_AP
12561 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12562 struct netif *netif = net_get_uap_interface();
12563
12564 wpa_supp_set_ap_beacon_int(netif, beacon_period);
12565 #endif
12566 #endif
12567 #endif
12568
12569 wifi_uap_set_beacon_period(beacon_period);
12570 }
12571
wlan_uap_set_bandwidth(const uint8_t bandwidth)12572 int wlan_uap_set_bandwidth(const uint8_t bandwidth)
12573 {
12574 #if CONFIG_WPA_SUPP
12575 #if CONFIG_WPA_SUPP_AP
12576 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12577 struct netif *netif = net_get_uap_interface();
12578
12579 wpa_supp_set_ap_bw(netif, bandwidth);
12580 #else
12581 return wifi_uap_set_bandwidth(bandwidth);
12582 #endif
12583 #endif
12584 #endif
12585
12586 return wifi_uap_set_bandwidth(bandwidth);
12587 }
12588
wlan_uap_get_bandwidth(uint8_t * bandwidth)12589 int wlan_uap_get_bandwidth(uint8_t *bandwidth)
12590 {
12591 *bandwidth = wifi_uap_get_bandwidth();
12592 if (*bandwidth == BANDWIDTH_20MHZ || *bandwidth == BANDWIDTH_40MHZ
12593 #if CONFIG_11AC
12594 || *bandwidth == BANDWIDTH_80MHZ
12595 #endif
12596 )
12597 {
12598 return WM_SUCCESS;
12599 }
12600 else
12601 {
12602 return -WM_FAIL;
12603 }
12604 }
12605
wlan_uap_set_hidden_ssid(const t_u8 hidden_ssid)12606 int wlan_uap_set_hidden_ssid(const t_u8 hidden_ssid)
12607 {
12608 if (hidden_ssid != 0 && hidden_ssid != 1 && hidden_ssid != 2)
12609 {
12610 return -WM_FAIL;
12611 }
12612
12613 if (is_uap_started())
12614 {
12615 (void)PRINTF("Pls set hidden_ssid before start uAP.\r\n");
12616 return -WM_FAIL;
12617 }
12618
12619 #if CONFIG_WPA_SUPP
12620 #if CONFIG_WPA_SUPP_AP
12621 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12622 struct netif *netif = net_get_uap_interface();
12623
12624 wpa_supp_set_ap_hidden_ssid(netif, hidden_ssid);
12625 #endif
12626 #endif
12627 #endif
12628
12629 wifi_uap_set_hidden_ssid(hidden_ssid);
12630
12631 return WM_SUCCESS;
12632 }
12633
wlan_uap_ctrl_deauth(const bool enable)12634 void wlan_uap_ctrl_deauth(const bool enable)
12635 {
12636 (void)wifi_uap_ctrl_deauth(enable);
12637 }
12638
wlan_uap_set_ecsa(void)12639 void wlan_uap_set_ecsa(void)
12640 {
12641 wifi_uap_set_ecsa();
12642 }
12643
wlan_uap_set_htcapinfo(const uint16_t ht_cap_info)12644 void wlan_uap_set_htcapinfo(const uint16_t ht_cap_info)
12645 {
12646 wifi_uap_set_htcapinfo(ht_cap_info);
12647 }
12648
wlan_uap_set_httxcfg(unsigned short httxcfg)12649 void wlan_uap_set_httxcfg(unsigned short httxcfg)
12650 {
12651 wifi_uap_set_httxcfg(httxcfg);
12652 }
12653
12654 #if CONFIG_WIFI_RTS_THRESHOLD
wlan_set_rts(int rts)12655 int wlan_set_rts(int rts)
12656 {
12657 return wifi_set_rts(rts, MLAN_BSS_TYPE_STA);
12658 }
12659
wlan_set_uap_rts(int rts)12660 int wlan_set_uap_rts(int rts)
12661 {
12662 return wifi_set_rts(rts, MLAN_BSS_TYPE_UAP);
12663 }
12664 #endif
12665
12666 #if CONFIG_WIFI_FRAG_THRESHOLD
wlan_set_frag(int frag)12667 int wlan_set_frag(int frag)
12668 {
12669 return wifi_set_frag(frag, MLAN_BSS_TYPE_STA);
12670 }
12671
wlan_set_uap_frag(int frag)12672 int wlan_set_uap_frag(int frag)
12673 {
12674 return wifi_set_frag(frag, MLAN_BSS_TYPE_UAP);
12675 }
12676 #endif
12677
12678 #if CONFIG_11K
_wlan_rrm_scan_cb(unsigned int count)12679 int _wlan_rrm_scan_cb(unsigned int count)
12680 {
12681 t_u16 i;
12682 t_u8 *rep_buf = NULL;
12683 t_u8 *buf_pos = NULL;
12684 /* The sufficient size is the length including reporting frame body */
12685 t_u16 suffi_len = 250U;
12686 t_u32 pos_last_indication = 0U;
12687 bool match_ap_found = false;
12688 int meas_report_len = 0;
12689
12690 /* process scan result */
12691 #if !CONFIG_MEM_POOLS
12692 rep_buf = (t_u8 *)OSA_MemoryAllocate(BEACON_REPORT_BUF_SIZE);
12693 #else
12694 rep_buf = (t_u8 *)OSA_MemoryPoolAllocate(buf_1536_MemoryPool);
12695 #endif
12696
12697 if (rep_buf == NULL)
12698 {
12699 PRINTM(MERROR, "Cannot allocate memory for report buffer");
12700 return -1;
12701 }
12702
12703 (void)memset(rep_buf, 0, BEACON_REPORT_BUF_SIZE);
12704 buf_pos = rep_buf;
12705 for (i = 0; i < count; i++)
12706 {
12707 if (wlan_rrm_matched_ap_found(&wlan.rrm_scan_cb_param.rep_data, &mlan_adap->pscan_table[i]))
12708 {
12709 wlan_add_rm_beacon_report(&wlan.rrm_scan_cb_param.rep_data, &mlan_adap->pscan_table[i], &buf_pos,
12710 BEACON_REPORT_BUF_SIZE - (buf_pos - rep_buf), &pos_last_indication);
12711 }
12712
12713 /* If current rep_buf is not enough and still have AP not added, just send the report */
12714 if ((buf_pos + suffi_len - rep_buf > BEACON_REPORT_BUF_SIZE) && (i < count - 1U) &&
12715 wlan_rrm_matched_ap_found(&wlan.rrm_scan_cb_param.rep_data, &mlan_adap->pscan_table[i + 1U]))
12716 {
12717 match_ap_found = 1;
12718 meas_report_len = buf_pos - rep_buf;
12719 /* send beacon report, not the last one */
12720 wlan_send_mgmt_rm_beacon_report(wlan.rrm_scan_cb_param.dialog_tok, wlan.sta_mac,
12721 wlan.rrm_scan_cb_param.dst_addr, rep_buf, (t_u32)meas_report_len,
12722 (bool)wlan.rrm_scan_cb_param.protect);
12723 /* Prepare for the next beacon report */
12724 (void)memset(rep_buf, 0, BEACON_REPORT_BUF_SIZE);
12725 buf_pos = rep_buf;
12726 }
12727
12728 /* Last AP in scan table, and matched AP found */
12729 if ((i == count - 1U) && (buf_pos > rep_buf))
12730 {
12731 match_ap_found = 1;
12732 /* Update last indication, the last one */
12733 if (wlan.rrm_scan_cb_param.rep_data.last_ind != 0U && pos_last_indication != 0U)
12734 {
12735 *(char *)pos_last_indication = (char)1U;
12736 }
12737 meas_report_len = buf_pos - rep_buf;
12738 /* send beacon report, the last one */
12739 wlan_send_mgmt_rm_beacon_report(wlan.rrm_scan_cb_param.dialog_tok, wlan.sta_mac,
12740 wlan.rrm_scan_cb_param.dst_addr, rep_buf, (t_u32)meas_report_len,
12741 (bool)wlan.rrm_scan_cb_param.protect);
12742 }
12743 }
12744
12745 /* If no matched AP found, no beacon report detail */
12746 if (!match_ap_found)
12747 {
12748 *buf_pos++ = (t_u8)MEASURE_REPORT;
12749 /* Tag length */
12750 *buf_pos++ = 3;
12751 *buf_pos++ = wlan.rrm_scan_cb_param.rep_data.token;
12752 *buf_pos++ = WLAN_RRM_REPORT_MODE_ACCEPT;
12753 *buf_pos++ = WLAN_RRM_MEASURE_TYPE_BEACON;
12754 meas_report_len = buf_pos - rep_buf;
12755 /* send beacon report */
12756 wlan_send_mgmt_rm_beacon_report(wlan.rrm_scan_cb_param.dialog_tok, wlan.sta_mac,
12757 wlan.rrm_scan_cb_param.dst_addr, rep_buf, (t_u32)meas_report_len,
12758 (bool)wlan.rrm_scan_cb_param.protect);
12759 }
12760 #if !CONFIG_MEM_POOLS
12761 OSA_MemoryFree(rep_buf);
12762 #else
12763 OSA_MemoryPoolFree(buf_1536_MemoryPool, rep_buf);
12764 #endif
12765
12766 return 0;
12767 }
12768
wlan_rrm_request_scan(wlan_scan_params_v2_t * wlan_scan_param,wlan_rrm_scan_cb_param * scan_cb_param)12769 void wlan_rrm_request_scan(wlan_scan_params_v2_t *wlan_scan_param, wlan_rrm_scan_cb_param *scan_cb_param)
12770 {
12771 char ssid[(MLAN_MAX_SSID_LENGTH + 1) * MRVDRV_MAX_SSID_LIST_LENGTH] = {0};
12772 uint8_t ssid_num = 0, ssid_off = 0;
12773 memcpy(ssid+ssid_off, wlan_scan_param->ssid[0], strlen(wlan_scan_param->ssid[0]));
12774 ssid_off += strlen(wlan_scan_param->ssid[0]);
12775 ssid[ssid_off] = '\0';
12776 ssid_off++;
12777 ssid_num++;
12778 #if CONFIG_COMBO_SCAN
12779 if (strlen(wlan_scan_param->ssid[1]))
12780 {
12781 memcpy(ssid+ssid_off, wlan_scan_param->ssid[1], strlen(wlan_scan_param->ssid[1]));
12782 ssid_off += strlen(wlan_scan_param->ssid[1]);
12783 ssid[ssid_off] = '\0';
12784 ssid_num++;
12785 }
12786 #endif
12787
12788 if (wlan_scan_param == NULL || scan_cb_param == NULL)
12789 {
12790 wlcm_d("ignoring scan request with NULL scan or cb params");
12791 return;
12792 }
12793 if (!is_scanning_allowed())
12794 {
12795 wlcm_d("ignoring scan request in invalid state");
12796 return;
12797 }
12798
12799 (void)memcpy(&wlan.rrm_scan_cb_param, scan_cb_param, sizeof(wlan_rrm_scan_cb_param));
12800
12801 #if CONFIG_SCAN_CHANNEL_GAP
12802 if (is_uap_started() || is_sta_connected())
12803 wlan_scan_param->scan_chan_gap = scan_channel_gap;
12804 else
12805 wlan_scan_param->scan_chan_gap = (t_u16)0U;
12806 #endif
12807
12808 int ret = wifi_send_scan_cmd((t_u8)BSS_ANY, wlan_scan_param->bssid,
12809 ssid, ssid_num,
12810 wlan_scan_param->num_channels, wlan_scan_param->chan_list, wlan_scan_param->num_probes,
12811 #if CONFIG_SCAN_WITH_RSSIFILTER
12812 wlan_scan_param->rssi_threshold,
12813 #endif
12814 #if CONFIG_SCAN_CHANNEL_GAP
12815 wlan_scan_param->scan_chan_gap,
12816 #endif
12817 false, false);
12818 if (ret == WM_SUCCESS)
12819 {
12820 wlan.scan_cb = (int (*)(unsigned int count))(wlan_scan_param->cb);
12821 wlan.sta_return_to = wlan.sta_state;
12822 wlan.sta_state = CM_STA_SCANNING_USER;
12823 }
12824 else
12825 {
12826 wlcm_e("wifi send scan cmd failed");
12827 }
12828 }
12829 #endif
12830
12831 #if CONFIG_11K_OFFLOAD
wlan_11k_cfg(int enable_11k)12832 int wlan_11k_cfg(int enable_11k)
12833 {
12834 return wifi_11k_cfg(enable_11k);
12835 }
12836
wlan_11k_neighbor_req(void)12837 int wlan_11k_neighbor_req(void)
12838 {
12839 return wifi_11k_neighbor_req();
12840 }
12841 #endif
12842
12843 #if CONFIG_SCAN_CHANNEL_GAP
wlan_set_scan_channel_gap(unsigned scan_chan_gap)12844 void wlan_set_scan_channel_gap(unsigned scan_chan_gap)
12845 {
12846 scan_channel_gap = (t_u16)scan_chan_gap;
12847 return;
12848 }
12849 #endif
12850
12851 #if CONFIG_11K
wlan_host_11k_cfg(int enable_11k)12852 int wlan_host_11k_cfg(int enable_11k)
12853 {
12854 #if CONFIG_WPA_SUPP
12855 wlan.enable_11k = enable_11k;
12856 return WM_SUCCESS;
12857 #else
12858 return wifi_host_11k_cfg(enable_11k);
12859 #endif
12860 }
12861
wlan_set_host_11k_status(int enable_11k)12862 int wlan_set_host_11k_status(int enable_11k)
12863 {
12864 if (enable_11k)
12865 wlan.enable_11k = true;
12866 else
12867 wlan.enable_11k = false;
12868
12869 return 0;
12870 }
12871
wlan_get_host_11k_status()12872 bool wlan_get_host_11k_status()
12873 {
12874 return wlan.enable_11k;
12875 }
12876
wlan_host_11k_neighbor_req(const char * ssid)12877 int wlan_host_11k_neighbor_req(const char *ssid)
12878 {
12879 int ret = -WM_FAIL;
12880 #if CONFIG_WPA_SUPP
12881 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12882 struct netif *netif = net_get_sta_interface();
12883 #endif
12884 #endif
12885
12886 if (!is_sta_connected())
12887 {
12888 wlcm_d("Error: sta connection is required before sending neighbor report req");
12889 return -WM_FAIL;
12890 }
12891
12892 #if CONFIG_WPA_SUPP
12893 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12894 ret = wpa_supp_send_neighbor_rep(netif, (char *)ssid, 0, 0);
12895 #endif
12896 #else
12897 ret = wifi_host_11k_neighbor_req(ssid);
12898 #endif
12899 if (ret == WM_SUCCESS)
12900 {
12901 wlan.neighbor_req = true;
12902 (void)OSA_TimerActivate((osa_timer_handle_t)wlan.neighbor_req_timer);
12903 }
12904 return ret;
12905 }
12906 #endif
12907
12908 #if CONFIG_11V
wlan_host_11v_bss_trans_query(t_u8 query_reason)12909 int wlan_host_11v_bss_trans_query(t_u8 query_reason)
12910 {
12911 #if CONFIG_WPA_SUPP
12912 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12913 struct netif *netif = net_get_sta_interface();
12914 #endif
12915 #else
12916 int ret = -WM_FAIL;
12917 #endif
12918
12919 if (!is_sta_connected())
12920 {
12921 wlcm_d("Error: sta connection is required before sending bss transition query");
12922 return -WM_FAIL;
12923 }
12924
12925 #if CONFIG_WPA_SUPP
12926 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12927 return wpa_supp_send_btm_query(netif, query_reason);
12928 #else
12929 return 0;
12930 #endif
12931 #else
12932 ret = wifi_host_11v_bss_trans_query(query_reason);
12933 if (ret == WM_SUCCESS)
12934 {
12935 wlan.neighbor_req = true;
12936 (void)OSA_TimerActivate((osa_timer_handle_t)wlan.neighbor_req_timer);
12937 }
12938 return ret;
12939 #endif
12940 }
12941 #endif
12942
12943 #if !CONFIG_WPA_SUPP
12944 #if CONFIG_DRIVER_MBO
wlan_host_mbo_cfg(int enable_mbo)12945 int wlan_host_mbo_cfg(int enable_mbo)
12946 {
12947 return wifi_host_mbo_cfg(enable_mbo);
12948 }
12949
wlan_mbo_peferch_cfg(t_u8 ch0,t_u8 pefer0,t_u8 ch1,t_u8 pefer1)12950 int wlan_mbo_peferch_cfg(t_u8 ch0, t_u8 pefer0, t_u8 ch1, t_u8 pefer1)
12951 {
12952 uint8_t ap_addr[IEEEtypes_ADDRESS_SIZE];
12953 if (is_sta_connected())
12954 {
12955 (void)wlan_get_current_bssid(ap_addr);
12956 return wifi_mbo_send_preferch_wnm(wlan.sta_mac, (t_u8 *)ap_addr, ch0, pefer0, ch1, pefer1);
12957 }
12958 else
12959 {
12960 return wifi_mbo_preferch_cfg(ch0, pefer0, ch1, pefer1);
12961 }
12962 }
12963 #endif
12964 #endif
12965
12966 #if (CONFIG_11MC) || (CONFIG_11AZ)
wlan_ftm_start_stop(const t_u16 action,const t_u8 loop_cnt,const t_u8 * mac,const t_u8 channel)12967 int wlan_ftm_start_stop(const t_u16 action, const t_u8 loop_cnt, const t_u8 *mac, const t_u8 channel)
12968 {
12969
12970 return wifi_ftm_start_stop(action, loop_cnt, mac, channel);
12971 }
12972
wlan_ftm_cfg(const t_u8 protocol,ranging_11az_cfg_t * ftm_ranging_cfg)12973 int wlan_ftm_cfg(const t_u8 protocol, ranging_11az_cfg_t *ftm_ranging_cfg)
12974 {
12975 return wifi_ftm_cfg(protocol, ftm_ranging_cfg);
12976 }
12977
wlan_ftm_11mc_cfg(ftm_11mc_nego_cfg_t * ftm_11mc_nego_cfg)12978 int wlan_ftm_11mc_cfg(ftm_11mc_nego_cfg_t *ftm_11mc_nego_cfg)
12979 {
12980 return wifi_ftm_11mc_cfg(ftm_11mc_nego_cfg);
12981 }
12982
wlan_ftm_location_cfg(location_cfg_info_t * ftm_location_cfg)12983 int wlan_ftm_location_cfg(location_cfg_info_t *ftm_location_cfg)
12984 {
12985 return wifi_ftm_location_cfg(ftm_location_cfg);
12986 }
12987
wlan_ftm_civic_cfg(location_civic_rep_t * ftm_civic_cfg)12988 int wlan_ftm_civic_cfg(location_civic_rep_t *ftm_civic_cfg)
12989 {
12990 return wifi_ftm_civic_cfg(ftm_civic_cfg);
12991 }
12992 #endif
12993
12994 #if CONFIG_WPA_SUPP
12995 #if (CONFIG_11AX && defined(CONFIG_MBO))
wlan_mbo_peferch_cfg(const char * non_pref_chan)12996 int wlan_mbo_peferch_cfg(const char *non_pref_chan)
12997 {
12998 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
12999 struct netif *netif = net_get_sta_interface();
13000
13001 return wpa_supp_mbo_update_non_pref_chan(netif, non_pref_chan);
13002 #else
13003 return 0;
13004 #endif
13005 }
13006
wlan_mbo_set_cell_capa(t_u8 cell_capa)13007 int wlan_mbo_set_cell_capa(t_u8 cell_capa)
13008 {
13009 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13010 struct netif *netif = net_get_sta_interface();
13011
13012 if (cell_capa != 1 && cell_capa != 2 && cell_capa != 3)
13013 {
13014 return -WM_E_PERM;
13015 }
13016
13017 return wpa_supp_mbo_set_cell_capa(netif, cell_capa);
13018 #else
13019 return 0;
13020 #endif
13021 }
13022
wlan_mbo_set_oce(t_u8 oce)13023 int wlan_mbo_set_oce(t_u8 oce)
13024 {
13025 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13026 struct netif *netif = net_get_sta_interface();
13027
13028 if (oce != 1 && oce != 2)
13029 {
13030 return -WM_E_PERM;
13031 }
13032
13033 return wpa_supp_mbo_set_oce(netif, oce);
13034 #else
13035 return 0;
13036 #endif
13037 }
13038 #endif
13039
wlan_set_okc(t_u8 okc)13040 int wlan_set_okc(t_u8 okc)
13041 {
13042 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13043 struct netif *netif = net_get_sta_interface();
13044
13045 if (okc != 0 && okc != 1)
13046 {
13047 return -WM_E_PERM;
13048 }
13049
13050 return wpa_supp_set_okc(netif, okc);
13051 #else
13052 return 0;
13053 #endif
13054 }
13055
wlan_pmksa_list(char * buf,size_t buflen)13056 int wlan_pmksa_list(char *buf, size_t buflen)
13057 {
13058 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13059 struct netif *netif = net_get_sta_interface();
13060
13061 return wpa_supp_pmksa_list(netif, buf, buflen);
13062 #else
13063 return 0;
13064 #endif
13065 }
13066
wlan_pmksa_flush()13067 int wlan_pmksa_flush()
13068 {
13069 struct netif *netif = net_get_sta_interface();
13070 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13071 return wpa_supp_pmksa_flush(netif);
13072 #else
13073 return supplicant_pmksa_flush(net_if_get_device((void *)netif));
13074 #endif
13075 }
13076
wlan_set_scan_interval(int scan_int)13077 int wlan_set_scan_interval(int scan_int)
13078 {
13079 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13080 struct netif *netif = net_get_sta_interface();
13081
13082 return wpa_supp_set_scan_interval(netif, scan_int);
13083 #else
13084 return 0;
13085 #endif
13086 }
13087 #endif
13088
13089 #if CONFIG_UAP_STA_MAC_ADDR_FILTER
wlan_set_sta_mac_filter(int filter_mode,int mac_count,unsigned char * mac_addr)13090 int wlan_set_sta_mac_filter(int filter_mode, int mac_count, unsigned char *mac_addr)
13091 {
13092 #if CONFIG_WPA_SUPP
13093 return wlan_host_set_sta_mac_filter(filter_mode, mac_count, mac_addr);
13094 #else
13095 return wifi_set_sta_mac_filter(filter_mode, mac_count, mac_addr);
13096 #endif
13097 }
13098 #endif
13099
13100 #if CONFIG_WPA2_ENTP
wlan_enable_wpa2_enterprise_ap_only()13101 void wlan_enable_wpa2_enterprise_ap_only()
13102 {
13103 wlan.allow_wpa2_enterprise_ap_only = true;
13104 wifi_scan_enable_wpa2_enterprise_ap_only();
13105 }
13106 #endif
13107
wlan_version_extended(void)13108 void wlan_version_extended(void)
13109 {
13110 #if SDK_DEBUGCONSOLE != DEBUGCONSOLE_DISABLE
13111 char *version_str;
13112
13113 version_str = wlan_get_firmware_version_ext();
13114
13115 (void)PRINTF("WLAN Driver Version : %s\r\n", WLAN_DRV_VERSION);
13116 (void)PRINTF("WLAN Firmware Version : %s\r\n", version_str);
13117 #endif
13118 }
13119
13120 #if CONFIG_WIFI_TX_PER_TRACK
wlan_set_tx_pert(struct wlan_tx_pert_info * tx_pert,mlan_bss_type bss_type)13121 void wlan_set_tx_pert(struct wlan_tx_pert_info *tx_pert, mlan_bss_type bss_type)
13122 {
13123 int ret = WM_SUCCESS;
13124
13125 ret = wifi_set_tx_pert((void *)tx_pert, bss_type);
13126 if (ret != WM_SUCCESS)
13127 (void)PRINTF("Failed to set tx per tracking.\r\n");
13128 return;
13129 }
13130 #endif
13131
13132 #if CONFIG_TX_RX_HISTOGRAM
wlan_set_txrx_histogram(struct wlan_txrx_histogram_info * txrx_histogram,t_u8 * data)13133 void wlan_set_txrx_histogram(struct wlan_txrx_histogram_info *txrx_histogram, t_u8 *data)
13134 {
13135 int ret = WM_SUCCESS;
13136
13137 wifi_set_txrx_histogram((void *)txrx_histogram, data);
13138 if (ret != WM_SUCCESS)
13139 (void)PRINTF("Failed to set txrx histogram config.\r\n");
13140 return;
13141 }
13142 #endif
13143
13144 #if CONFIG_ROAMING
wlan_set_roaming(const int enable,const uint8_t rssi_low_threshold)13145 int wlan_set_roaming(const int enable, const uint8_t rssi_low_threshold)
13146 {
13147 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13148 #if CONFIG_WPA_SUPP
13149 struct netif *netif = net_get_sta_interface();
13150 #endif
13151 #endif
13152
13153 wlan.roaming_enabled = enable;
13154 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
13155 #if CONFIG_WPA_SUPP
13156 wpa_supp_set_okc(netif, wlan.roaming_enabled == true ? 0 : 1);
13157 #endif
13158 #endif
13159 wlan.rssi_low_threshold = rssi_low_threshold;
13160
13161 return wifi_config_roaming(enable, &wlan.rssi_low_threshold);
13162 }
13163
wlan_get_roaming_status()13164 int wlan_get_roaming_status()
13165 {
13166 return wlan.roaming_enabled;
13167 }
13168
wlan_subscribe_rssi_low_event()13169 void wlan_subscribe_rssi_low_event()
13170 {
13171 if(wlan.roaming_enabled)
13172 {
13173 wifi_set_rssi_low_threshold(&wlan.rssi_low_threshold);
13174 }
13175 }
13176 #endif
13177
13178 #if CONFIG_WIFI_MEM_ACCESS
wlan_mem_access(uint16_t action,uint32_t addr,uint32_t * value)13179 int wlan_mem_access(uint16_t action, uint32_t addr, uint32_t *value)
13180 {
13181 return wifi_mem_access(action, addr, value);
13182 }
13183 #endif
13184
13185 #if CONFIG_WIFI_BOOT_SLEEP
wlan_boot_sleep(uint16_t action,uint16_t * enable)13186 int wlan_boot_sleep(uint16_t action, uint16_t *enable)
13187 {
13188
13189 if ((*enable != 0) && (*enable != 1))
13190 {
13191 return -WM_FAIL;
13192 }
13193
13194 return wifi_boot_sleep(action, enable);
13195 }
13196 #endif
13197
13198 #if CONFIG_RF_TEST_MODE
13199
wlan_set_rf_test_mode(void)13200 int wlan_set_rf_test_mode(void)
13201 {
13202 wlan_ieeeps_off();
13203 wlan_deepsleepps_off();
13204 return wifi_set_rf_test_mode();
13205 }
13206
wlan_unset_rf_test_mode(void)13207 int wlan_unset_rf_test_mode(void)
13208 {
13209 (void)wifi_unset_rf_test_mode();
13210 #if CONFIG_WIFI_AUTO_POWER_SAVE
13211 wlan_deepsleepps_on();
13212 wlan_ieeeps_on(wlan.wakeup_conditions);
13213 #endif
13214 return WM_SUCCESS;
13215 }
13216
wlan_set_rf_channel(const uint8_t channel)13217 int wlan_set_rf_channel(const uint8_t channel)
13218 {
13219 return wifi_set_rf_channel(channel);
13220 }
13221
wlan_set_rf_radio_mode(const uint8_t mode)13222 int wlan_set_rf_radio_mode(const uint8_t mode)
13223 {
13224 return wifi_set_rf_radio_mode(mode);
13225 }
13226
wlan_get_rf_channel(uint8_t * channel)13227 int wlan_get_rf_channel(uint8_t *channel)
13228 {
13229 if (channel != NULL)
13230 return wifi_get_rf_channel(channel);
13231
13232 return -WM_FAIL;
13233 }
13234
wlan_get_rf_radio_mode(uint8_t * mode)13235 int wlan_get_rf_radio_mode(uint8_t *mode)
13236 {
13237 if (mode)
13238 return wifi_get_rf_radio_mode(mode);
13239
13240 return -WM_FAIL;
13241 }
13242
wlan_set_rf_bandwidth(const uint8_t bandwidth)13243 int wlan_set_rf_bandwidth(const uint8_t bandwidth)
13244 {
13245 return wifi_set_rf_bandwidth(bandwidth);
13246 }
13247
wlan_set_rf_band(const uint8_t band)13248 int wlan_set_rf_band(const uint8_t band)
13249 {
13250 return wifi_set_rf_band(band);
13251 }
13252
wlan_get_rf_band(uint8_t * band)13253 int wlan_get_rf_band(uint8_t *band)
13254 {
13255 if (band != NULL)
13256 return wifi_get_rf_band(band);
13257
13258 return -WM_FAIL;
13259 }
13260
wlan_get_rf_bandwidth(uint8_t * bandwidth)13261 int wlan_get_rf_bandwidth(uint8_t *bandwidth)
13262 {
13263 if (bandwidth != NULL)
13264 return wifi_get_rf_bandwidth(bandwidth);
13265
13266 return -WM_FAIL;
13267 }
13268
wlan_get_rf_per(uint32_t * rx_tot_pkt_count,uint32_t * rx_mcast_bcast_count,uint32_t * rx_pkt_fcs_error)13269 int wlan_get_rf_per(uint32_t *rx_tot_pkt_count, uint32_t *rx_mcast_bcast_count, uint32_t *rx_pkt_fcs_error)
13270 {
13271 if ((rx_tot_pkt_count != NULL) && (rx_mcast_bcast_count != NULL) && (rx_pkt_fcs_error != NULL))
13272 return wifi_get_rf_per(rx_tot_pkt_count, rx_mcast_bcast_count, rx_pkt_fcs_error);
13273
13274 return -WM_FAIL;
13275 }
13276
wlan_set_rf_tx_cont_mode(const uint32_t enable_tx,const uint32_t cw_mode,const uint32_t payload_pattern,const uint32_t cs_mode,const uint32_t act_sub_ch,const uint32_t tx_rate)13277 int wlan_set_rf_tx_cont_mode(const uint32_t enable_tx,
13278 const uint32_t cw_mode,
13279 const uint32_t payload_pattern,
13280 const uint32_t cs_mode,
13281 const uint32_t act_sub_ch,
13282 const uint32_t tx_rate)
13283 {
13284 return wifi_set_rf_tx_cont_mode(enable_tx, cw_mode, payload_pattern, cs_mode, act_sub_ch, tx_rate);
13285 }
13286
wlan_set_rf_tx_antenna(const uint8_t antenna)13287 int wlan_set_rf_tx_antenna(const uint8_t antenna)
13288 {
13289 return wifi_set_rf_tx_antenna(antenna);
13290 }
13291
wlan_get_rf_tx_antenna(uint8_t * antenna)13292 int wlan_get_rf_tx_antenna(uint8_t *antenna)
13293 {
13294 if (antenna != NULL)
13295 return wifi_get_rf_tx_antenna(antenna);
13296
13297 return -WM_FAIL;
13298 }
13299
wlan_set_rf_rx_antenna(const uint8_t antenna)13300 int wlan_set_rf_rx_antenna(const uint8_t antenna)
13301 {
13302 return wifi_set_rf_rx_antenna(antenna);
13303 }
13304
wlan_get_rf_rx_antenna(uint8_t * antenna)13305 int wlan_get_rf_rx_antenna(uint8_t *antenna)
13306 {
13307 if (antenna != NULL)
13308 return wifi_get_rf_rx_antenna(antenna);
13309
13310 return -WM_FAIL;
13311 }
13312
wlan_set_rf_tx_power(const uint32_t power,const uint8_t mod,const uint8_t path_id)13313 int wlan_set_rf_tx_power(const uint32_t power, const uint8_t mod, const uint8_t path_id)
13314 {
13315 return wifi_set_rf_tx_power(power, mod, path_id);
13316 }
13317
wlan_cfg_rf_he_tb_tx(uint16_t enable,uint16_t qnum,uint16_t aid,uint16_t axq_mu_timer,int16_t tx_power)13318 int wlan_cfg_rf_he_tb_tx(uint16_t enable,uint16_t qnum,uint16_t aid,uint16_t axq_mu_timer,int16_t tx_power)
13319 {
13320 return wifi_cfg_rf_he_tb_tx(enable, qnum, aid,axq_mu_timer,tx_power);
13321 }
13322
wlan_rf_trigger_frame_cfg(uint32_t Enable_tx,uint32_t Standalone_hetb,uint8_t FRAME_CTRL_TYPE,uint8_t FRAME_CTRL_SUBTYPE,uint16_t FRAME_DURATION,uint64_t TriggerType,uint64_t UlLen,uint64_t MoreTF,uint64_t CSRequired,uint64_t UlBw,uint64_t LTFType,uint64_t LTFMode,uint64_t LTFSymbol,uint64_t UlSTBC,uint64_t LdpcESS,uint64_t ApTxPwr,uint64_t PreFecPadFct,uint64_t PeDisambig,uint64_t SpatialReuse,uint64_t Doppler,uint64_t HeSig2,uint32_t AID12,uint32_t RUAllocReg,uint32_t RUAlloc,uint32_t UlCodingType,uint32_t UlMCS,uint32_t UlDCM,uint32_t SSAlloc,uint8_t UlTargetRSSI,uint8_t MPDU_MU_SF,uint8_t TID_AL,uint8_t AC_PL,uint8_t Pref_AC)13323 int wlan_rf_trigger_frame_cfg(uint32_t Enable_tx,uint32_t Standalone_hetb,uint8_t FRAME_CTRL_TYPE,
13324 uint8_t FRAME_CTRL_SUBTYPE,uint16_t FRAME_DURATION,uint64_t TriggerType,
13325 uint64_t UlLen,uint64_t MoreTF,uint64_t CSRequired,uint64_t UlBw,
13326 uint64_t LTFType,uint64_t LTFMode,uint64_t LTFSymbol,uint64_t UlSTBC,
13327 uint64_t LdpcESS,uint64_t ApTxPwr,uint64_t PreFecPadFct,
13328 uint64_t PeDisambig,uint64_t SpatialReuse,uint64_t Doppler,
13329 uint64_t HeSig2,uint32_t AID12,uint32_t RUAllocReg,uint32_t RUAlloc,
13330 uint32_t UlCodingType,uint32_t UlMCS,uint32_t UlDCM,uint32_t SSAlloc,
13331 uint8_t UlTargetRSSI,uint8_t MPDU_MU_SF,uint8_t TID_AL,uint8_t AC_PL,
13332 uint8_t Pref_AC)
13333 {
13334 return wifi_rf_trigger_frame_cfg(Enable_tx,Standalone_hetb,FRAME_CTRL_TYPE,
13335 FRAME_CTRL_SUBTYPE,FRAME_DURATION,TriggerType,
13336 UlLen,MoreTF,CSRequired,UlBw,LTFType,LTFMode,
13337 LTFSymbol,UlSTBC,LdpcESS,ApTxPwr,PreFecPadFct,
13338 PeDisambig,SpatialReuse,Doppler,HeSig2,AID12,
13339 RUAllocReg,RUAlloc,UlCodingType,UlMCS,UlDCM,
13340 SSAlloc,UlTargetRSSI,MPDU_MU_SF,TID_AL,AC_PL,
13341 Pref_AC);
13342 }
13343
wlan_set_rf_tx_frame(const uint32_t enable,const uint32_t data_rate,const uint32_t frame_pattern,const uint32_t frame_length,const uint16_t adjust_burst_sifs,const uint32_t burst_sifs_in_us,const uint32_t short_preamble,const uint32_t act_sub_ch,const uint32_t short_gi,const uint32_t adv_coding,const uint32_t tx_bf,const uint32_t gf_mode,const uint32_t stbc,const uint8_t * bssid)13344 int wlan_set_rf_tx_frame(const uint32_t enable,
13345 const uint32_t data_rate,
13346 const uint32_t frame_pattern,
13347 const uint32_t frame_length,
13348 const uint16_t adjust_burst_sifs,
13349 const uint32_t burst_sifs_in_us,
13350 const uint32_t short_preamble,
13351 const uint32_t act_sub_ch,
13352 const uint32_t short_gi,
13353 const uint32_t adv_coding,
13354 const uint32_t tx_bf,
13355 const uint32_t gf_mode,
13356 const uint32_t stbc,
13357 const uint8_t *bssid)
13358 {
13359 return wifi_set_rf_tx_frame(enable, data_rate, frame_pattern, frame_length, adjust_burst_sifs, burst_sifs_in_us,
13360 short_preamble, act_sub_ch, short_gi, adv_coding, tx_bf, gf_mode, stbc, bssid);
13361 }
13362
wlan_set_rf_otp_mac_addr(uint8_t * mac)13363 int wlan_set_rf_otp_mac_addr(uint8_t *mac)
13364 {
13365 return wifi_set_rf_otp_mac_addr(mac);
13366 }
13367
wlan_get_rf_otp_mac_addr(uint8_t * mac)13368 int wlan_get_rf_otp_mac_addr(uint8_t *mac)
13369 {
13370 if (mac != NULL)
13371 return wifi_get_rf_otp_mac_addr(mac);
13372
13373 return -WM_FAIL;
13374 }
13375
wlan_set_rf_otp_cal_data(const uint8_t * cal_data,uint32_t cal_data_len)13376 int wlan_set_rf_otp_cal_data(const uint8_t *cal_data, uint32_t cal_data_len)
13377 {
13378 return wifi_set_rf_otp_cal_data(cal_data, cal_data_len);
13379 }
13380
wlan_get_rf_otp_cal_data(uint8_t * cal_data)13381 int wlan_get_rf_otp_cal_data(uint8_t *cal_data)
13382 {
13383 if (cal_data != NULL)
13384 return wifi_get_rf_otp_cal_data(cal_data);
13385
13386 return -WM_FAIL;
13387 }
13388 #endif
13389 #if CONFIG_WIFI_FW_DEBUG
wlan_register_fw_dump_cb(void (* wlan_usb_init_cb)(void),int (* wlan_usb_mount_cb)(),int (* wlan_usb_file_open_cb)(char * test_file_name),int (* wlan_usb_file_write_cb)(uint8_t * data,size_t data_len),int (* wlan_usb_file_close_cb)())13390 void wlan_register_fw_dump_cb(void (*wlan_usb_init_cb)(void),
13391 int (*wlan_usb_mount_cb)(),
13392 int (*wlan_usb_file_open_cb)(char *test_file_name),
13393 int (*wlan_usb_file_write_cb)(uint8_t *data, size_t data_len),
13394 int (*wlan_usb_file_close_cb)())
13395 {
13396 wlan.wlan_usb_init_cb = wlan_usb_init_cb;
13397 wifi_register_fw_dump_cb(wlan_usb_mount_cb, wlan_usb_file_open_cb, wlan_usb_file_write_cb, wlan_usb_file_close_cb);
13398 }
13399 #endif
13400
13401 #if CONFIG_WMM
wlan_wmm_tx_stats_dump(int bss_type)13402 void wlan_wmm_tx_stats_dump(int bss_type)
13403 {
13404 wifi_wmm_tx_stats_dump(bss_type);
13405 }
13406 #endif
13407
wlan_send_hostcmd(const void * cmd_buf,uint32_t cmd_buf_len,void * host_resp_buf,uint32_t resp_buf_len,uint32_t * reqd_resp_len)13408 int wlan_send_hostcmd(
13409 const void *cmd_buf, uint32_t cmd_buf_len, void *host_resp_buf, uint32_t resp_buf_len, uint32_t *reqd_resp_len)
13410 {
13411 if ((cmd_buf == NULL) || (host_resp_buf == NULL) || (reqd_resp_len == NULL))
13412 {
13413 return (int)WM_E_NOMEM;
13414 }
13415 if (!cmd_buf_len || !resp_buf_len)
13416 {
13417 return (int)WM_E_INVAL;
13418 }
13419
13420 return wifi_send_hostcmd(cmd_buf, cmd_buf_len, host_resp_buf, resp_buf_len, reqd_resp_len);
13421 }
13422
13423 #if CONFIG_11AX
wlan_enable_disable_htc(uint8_t option)13424 int wlan_enable_disable_htc(uint8_t option)
13425 {
13426 int ret = -WM_FAIL;
13427 uint8_t send_htc_set[] = {0x8b, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x24, 0x01, 0x01, 0x00, 0x00, 0x00};
13428 uint8_t debug_resp_buf[32] = {0};
13429 uint32_t reqd_len = 0;
13430
13431 send_htc_set[12] = option;
13432
13433 ret = wlan_send_hostcmd(send_htc_set, sizeof(send_htc_set) / sizeof(uint8_t), debug_resp_buf, sizeof(debug_resp_buf),
13434 &reqd_len);
13435
13436 return ret;
13437 }
13438
wlan_send_debug_htc(const uint8_t count,const uint8_t vht,const uint8_t he,const uint8_t rxNss,const uint8_t channelWidth,const uint8_t ulMuDisable,const uint8_t txNSTS,const uint8_t erSuDisable,const uint8_t dlResoundRecomm,const uint8_t ulMuDataDisable)13439 int wlan_send_debug_htc(const uint8_t count,
13440 const uint8_t vht,
13441 const uint8_t he,
13442 const uint8_t rxNss,
13443 const uint8_t channelWidth,
13444 const uint8_t ulMuDisable,
13445 const uint8_t txNSTS,
13446 const uint8_t erSuDisable,
13447 const uint8_t dlResoundRecomm,
13448 const uint8_t ulMuDataDisable)
13449 {
13450 int ret = -WM_FAIL;
13451 int i;
13452 uint8_t debug_cmd_buf[] = {0x8b, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x11, 0x01, 0x40, 0x01, 0x01, 0x00,
13453 0x02, 0x00, 0x00, 0x00, 0x00, 0x00};
13454
13455 uint8_t debug_resp_buf[32] = {0};
13456 uint32_t reqd_len = 0;
13457
13458 (void)memset(debug_resp_buf, 0, sizeof(debug_resp_buf));
13459
13460 debug_cmd_buf[12] = count;
13461 debug_cmd_buf[13] = vht;
13462 debug_cmd_buf[14] = he;
13463 debug_cmd_buf[15] = rxNss;
13464 debug_cmd_buf[16] = channelWidth;
13465 debug_cmd_buf[17] = ulMuDisable;
13466 debug_cmd_buf[18] = txNSTS;
13467 debug_cmd_buf[19] = erSuDisable;
13468 debug_cmd_buf[20] = dlResoundRecomm;
13469 debug_cmd_buf[21] = ulMuDataDisable;
13470
13471 ret = wlan_send_hostcmd(debug_cmd_buf, sizeof(debug_cmd_buf) / sizeof(uint8_t), debug_resp_buf, sizeof(debug_resp_buf),
13472 &reqd_len);
13473 if (ret == WM_SUCCESS)
13474 {
13475 (void)PRINTF("Hostcmd success, response is\r\n");
13476 for (i = 0; i < reqd_len; i++)
13477 (void)PRINTF("%x\t", debug_resp_buf[i]);
13478 }
13479 else
13480 {
13481 (void)PRINTF("Hostcmd failed error: %d", ret);
13482 }
13483 return ret;
13484 }
wlan_set_11ax_tx_omi(const t_u8 interface,const t_u16 tx_omi,const t_u8 tx_option,const t_u8 num_data_pkts)13485 int wlan_set_11ax_tx_omi(const t_u8 interface, const t_u16 tx_omi, const t_u8 tx_option, const t_u8 num_data_pkts)
13486 {
13487 if (interface == MLAN_BSS_TYPE_STA)
13488 {
13489
13490 if (num_data_pkts > 16)
13491 {
13492 (void)PRINTF("Minimum value of num_data_pkts should be 1 and maximum should be 16");
13493 return -WM_FAIL;
13494 }
13495
13496 if (is_sta_connected())
13497 {
13498 return wifi_set_11ax_tx_omi(MLAN_BSS_TYPE_STA, tx_omi, tx_option, num_data_pkts);
13499 }
13500 else
13501 {
13502 wifi_d("STA not connected");
13503 return -WM_FAIL;
13504 }
13505 }
13506 else if (interface == MLAN_BSS_TYPE_UAP)
13507 {
13508 if (is_uap_started())
13509 {
13510 return wifi_set_11ax_tx_omi(MLAN_BSS_TYPE_UAP, tx_omi, tx_option, num_data_pkts);
13511 }
13512 else
13513 {
13514 wifi_d("uAP not started");
13515 return -WM_FAIL;
13516 }
13517 }
13518 else
13519 {
13520 wifi_d("Interface not supported");
13521 return -WM_FAIL;
13522 }
13523 }
13524
wlan_set_11ax_tol_time(const t_u32 tol_time)13525 int wlan_set_11ax_tol_time(const t_u32 tol_time)
13526 {
13527 if (tol_time < 1 || tol_time > 3600)
13528 {
13529 wlcm_d("Error: invalid tolerance time value, range[[1..3600]].");
13530 return -WM_FAIL;
13531 ;
13532 }
13533
13534 if (is_sta_connecting())
13535 {
13536 wlcm_d("Pls set OBSS Tolerance Time value before connecting to AP.");
13537 return -WM_FAIL;
13538 }
13539
13540 return wifi_set_11ax_tol_time(tol_time);
13541 }
13542
wlan_set_11ax_rutxpowerlimit(const void * rutx_pwr_cfg,uint32_t rutx_pwr_cfg_len)13543 int wlan_set_11ax_rutxpowerlimit(const void *rutx_pwr_cfg, uint32_t rutx_pwr_cfg_len)
13544 {
13545 if (rutx_pwr_cfg != NULL)
13546 {
13547 return wifi_set_11ax_rutxpowerlimit(rutx_pwr_cfg, rutx_pwr_cfg_len);
13548 }
13549
13550 return -WM_FAIL;
13551 }
13552
wlan_set_11ax_rutxpowerlimit_legacy(const wifi_rutxpwrlimit_t * ru_pwr_cfg)13553 int wlan_set_11ax_rutxpowerlimit_legacy(const wifi_rutxpwrlimit_t *ru_pwr_cfg)
13554 {
13555 if (ru_pwr_cfg != NULL)
13556 {
13557 return wifi_set_11ax_rutxpowerlimit_legacy(ru_pwr_cfg);
13558 }
13559
13560 return -WM_FAIL;
13561 }
13562
wlan_get_11ax_rutxpowerlimit_legacy(wifi_rutxpwrlimit_t * ru_pwr_cfg)13563 int wlan_get_11ax_rutxpowerlimit_legacy(wifi_rutxpwrlimit_t *ru_pwr_cfg)
13564 {
13565 if (ru_pwr_cfg != NULL)
13566 {
13567 (void)memset(ru_pwr_cfg, 0x00, sizeof(wlan_rutxpwrlimit_t));
13568 return wifi_get_11ax_rutxpowerlimit_legacy(ru_pwr_cfg);
13569 }
13570
13571 return -WM_FAIL;
13572 }
13573
13574 /* cfg tables for 11axcfg and twt commands to FW */
13575 static uint8_t g_11ax_cfg_default[] = {
13576 /* band */
13577 0x03,
13578 /* HE cap */
13579 0xff, 0x00, // ID
13580 0x18, 0x00, // Length
13581 0x23, // he capability id
13582 0x03, 0x08, 0x00, 0x82, 0x00, 0x00, // HE MAC capability info
13583 0x40, 0x50, 0x42, 0x49, 0x0d, 0x00, 0x20, 0x1e, 0x17, 0x31, 0x00, // HE PHY capability info
13584 0xfd, 0xff, 0xfd, 0xff, // Tx Rx HE-MCS NSS support
13585 0x88, 0x1f, 0x00, 0x00
13586 };
13587
13588
wlan_set_11ax_cfg(wlan_11ax_config_t * ax_config)13589 int wlan_set_11ax_cfg(wlan_11ax_config_t *ax_config)
13590 {
13591 return wifi_set_11ax_cfg(ax_config);
13592 }
13593
wlan_get_11ax_cfg()13594 uint8_t * wlan_get_11ax_cfg()
13595 {
13596 return g_11ax_cfg_default;
13597 }
13598
13599 #if CONFIG_11AX_TWT
13600 static uint8_t g_btwt_cfg_default[] = {/* action */
13601 0x01, 0x00,
13602 /* sub_id */
13603 0x25, 0x01,
13604 /* btwt_cfg */
13605 0x40, 0x04, 0x63, 0x00, 0x70, 0x02, 0x0a, 0x05};
13606
wlan_set_btwt_cfg(const wlan_btwt_config_t * btwt_config)13607 int wlan_set_btwt_cfg(const wlan_btwt_config_t *btwt_config)
13608 {
13609 return wifi_set_btwt_cfg(btwt_config);
13610 }
13611
wlan_get_btwt_cfg()13612 uint8_t * wlan_get_btwt_cfg()
13613 {
13614 return g_btwt_cfg_default;
13615 }
13616
13617 static uint8_t g_twt_setup_cfg_default[] = {
13618 0x01, // implicit
13619 0x00, // unannounced
13620 0x00, // Non-Trigger
13621 0x00, // info enabled
13622 0x00, // indv TWT
13623 0x40, // wakeup dur
13624 0x00, // FID
13625 0x01, // FW not tweak
13626 0x0a, // exponent
13627 0x00, 0x02, // mantissa 200TU
13628 0x00, // REQ TWT
13629 0x00, // state
13630 0x3c, 0x00 //bcn miss=60s
13631 };
13632
13633 /* Below macros are defined as in FW under dot11ax_twt.c */
13634 #define TWT_EARLY_WAKEUP_ADJUSTMENT 1000 // us
13635 #define TWT_SLEEP_MIN (756 + TWT_EARLY_WAKEUP_ADJUSTMENT) // us
wlan_set_twt_setup_cfg(const wlan_twt_setup_config_t * twt_setup)13636 int wlan_set_twt_setup_cfg(const wlan_twt_setup_config_t *twt_setup)
13637 {
13638 if (((twt_setup->twt_mantissa << twt_setup->twt_exponent) - (twt_setup->twt_wakeup_duration * 256)) < TWT_SLEEP_MIN)
13639 {
13640 wlcm_e("TWT interval is : %u us", twt_setup->twt_mantissa << twt_setup->twt_exponent);
13641 wlcm_e("Wakeup duration (WD) value is : %u us", twt_setup->twt_wakeup_duration * 256);
13642 wlcm_e("Minimum sleep time (Interval - WD) should be greater than: %u us", TWT_SLEEP_MIN);
13643 return -WM_FAIL;
13644 }
13645 return wifi_set_twt_setup_cfg(twt_setup);
13646 }
13647
wlan_get_twt_setup_cfg()13648 uint8_t * wlan_get_twt_setup_cfg()
13649 {
13650 return g_twt_setup_cfg_default;
13651 }
13652
13653 static uint8_t g_twt_teardown_cfg_default[] = {0x00, 0x00, 0x00};
13654
wlan_set_twt_teardown_cfg(const wlan_twt_teardown_config_t * teardown_config)13655 int wlan_set_twt_teardown_cfg(const wlan_twt_teardown_config_t *teardown_config)
13656 {
13657 return wifi_set_twt_teardown_cfg(teardown_config);
13658 }
13659
wlan_get_twt_teardown_cfg()13660 uint8_t * wlan_get_twt_teardown_cfg()
13661 {
13662 return g_twt_teardown_cfg_default;
13663 }
13664
wlan_get_twt_report(wlan_twt_report_t * twt_report)13665 int wlan_get_twt_report(wlan_twt_report_t *twt_report)
13666 {
13667 return wifi_get_twt_report(twt_report);
13668 }
13669
wlan_twt_information(wlan_twt_information_t * twt_information)13670 int wlan_twt_information(wlan_twt_information_t *twt_information)
13671 {
13672 return wifi_twt_information(twt_information);
13673 }
13674 #endif /* CONFIG_11AX_TWT */
13675 #endif /* CONFIG_11AX */
13676
13677 #if CONFIG_WIFI_CLOCKSYNC
wlan_get_tsf_info(wlan_tsf_info_t * tsf_info)13678 int wlan_get_tsf_info(wlan_tsf_info_t *tsf_info)
13679 {
13680 return wifi_get_tsf_info(tsf_info);
13681 }
wlan_set_clocksync_cfg(const wlan_clock_sync_gpio_tsf_t * tsf_latch)13682 int wlan_set_clocksync_cfg(const wlan_clock_sync_gpio_tsf_t *tsf_latch)
13683 {
13684 return wifi_set_clocksync_cfg(tsf_latch, (mlan_bss_type)WLAN_BSS_TYPE_STA);
13685 }
13686 #endif /* CONFIG_WIFI_CLOCKSYNC */
13687
13688 #if CONFIG_WIFI_EU_CRYPTO
wlan_set_crypto_RC4_encrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * KeyIV,const t_u16 KeyIVLength,t_u8 * Data,t_u16 * DataLength)13689 int wlan_set_crypto_RC4_encrypt(
13690 const t_u8 *Key, const t_u16 KeyLength, const t_u8 *KeyIV, const t_u16 KeyIVLength, t_u8 *Data, t_u16 *DataLength)
13691 {
13692 t_u16 rc4_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13693 t_u16 rc4_keyiv_length = EU_CRYPTO_KEYIV_MAX_LENGTH;
13694 t_u16 rc4_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13695
13696 #if defined(SD8801)
13697 return -WM_E_PERM;
13698 #endif
13699
13700 if (!wlan_is_started())
13701 {
13702 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13703 return -WM_FAIL;
13704 }
13705
13706 if (KeyLength > rc4_key_length)
13707 return -WM_FAIL;
13708 if (KeyIVLength > rc4_keyiv_length)
13709 return -WM_FAIL;
13710 if (*DataLength > rc4_data_length)
13711 return -WM_FAIL;
13712 EU_Crypto Crypto_RC4_Param;
13713 Crypto_RC4_Param.KeyIVLength = KeyIVLength;
13714 memcpy(Crypto_RC4_Param.KeyIV, KeyIV, KeyIVLength);
13715 Crypto_RC4_Param.KeyLength = KeyLength;
13716 memcpy(Crypto_RC4_Param.Key, Key, KeyLength);
13717 Crypto_RC4_Param.DataLength = DataLength;
13718 Crypto_RC4_Param.Data = Data;
13719
13720 t_u16 EncDec = 1;
13721
13722 return wifi_set_eu_crypto(&Crypto_RC4_Param, CRYPTO_RC4, EncDec);
13723 }
13724
wlan_set_crypto_RC4_decrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * KeyIV,const t_u16 KeyIVLength,t_u8 * Data,t_u16 * DataLength)13725 int wlan_set_crypto_RC4_decrypt(
13726 const t_u8 *Key, const t_u16 KeyLength, const t_u8 *KeyIV, const t_u16 KeyIVLength, t_u8 *Data, t_u16 *DataLength)
13727 {
13728 t_u16 rc4_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13729 t_u16 rc4_keyiv_length = EU_CRYPTO_KEYIV_MAX_LENGTH;
13730 t_u16 rc4_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13731
13732 #if defined(SD8801)
13733 return -WM_E_PERM;
13734 #endif
13735
13736 if (!wlan_is_started())
13737 {
13738 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13739 return -WM_FAIL;
13740 }
13741
13742 if (KeyLength > rc4_key_length)
13743 return -WM_FAIL;
13744 if (KeyIVLength > rc4_keyiv_length)
13745 return -WM_FAIL;
13746 if (*DataLength > rc4_data_length)
13747 return -WM_FAIL;
13748 EU_Crypto Crypto_RC4_Param;
13749 Crypto_RC4_Param.KeyIVLength = KeyIVLength;
13750 memcpy(Crypto_RC4_Param.KeyIV, KeyIV, KeyIVLength);
13751 Crypto_RC4_Param.KeyLength = KeyLength;
13752 memcpy(Crypto_RC4_Param.Key, Key, KeyLength);
13753 Crypto_RC4_Param.DataLength = DataLength;
13754 Crypto_RC4_Param.Data = Data;
13755
13756 t_u16 EncDec = 0;
13757
13758 return wifi_set_eu_crypto(&Crypto_RC4_Param, CRYPTO_RC4, EncDec);
13759 }
13760
wlan_set_crypto_AES_ECB_encrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * KeyIV,const t_u16 KeyIVLength,t_u8 * Data,t_u16 * DataLength)13761 int wlan_set_crypto_AES_ECB_encrypt(
13762 const t_u8 *Key, const t_u16 KeyLength, const t_u8 *KeyIV, const t_u16 KeyIVLength, t_u8 *Data, t_u16 *DataLength)
13763 {
13764 t_u16 aes_ecb_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13765 t_u16 aes_ecb_keyiv_length = EU_CRYPTO_KEYIV_MAX_LENGTH;
13766 t_u16 aes_ecb_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13767
13768 #if defined(SD8801)
13769 return -WM_E_PERM;
13770 #endif
13771
13772 if (!wlan_is_started())
13773 {
13774 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13775 return -WM_FAIL;
13776 }
13777
13778 if (KeyLength > aes_ecb_key_length)
13779 return -WM_FAIL;
13780 if (KeyIVLength > aes_ecb_keyiv_length)
13781 return -WM_FAIL;
13782 if (*DataLength > aes_ecb_data_length)
13783 return -WM_FAIL;
13784 EU_Crypto Crypto_AES_ECB_Param;
13785 Crypto_AES_ECB_Param.KeyIVLength = KeyIVLength;
13786 memcpy(Crypto_AES_ECB_Param.KeyIV, KeyIV, KeyIVLength);
13787 Crypto_AES_ECB_Param.KeyLength = KeyLength;
13788 memcpy(Crypto_AES_ECB_Param.Key, Key, KeyLength);
13789 Crypto_AES_ECB_Param.DataLength = DataLength;
13790 Crypto_AES_ECB_Param.Data = Data;
13791
13792 t_u16 EncDec = 1;
13793
13794 return wifi_set_eu_crypto(&Crypto_AES_ECB_Param, CRYPTO_AES_ECB, EncDec);
13795 }
13796
wlan_set_crypto_AES_ECB_decrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * KeyIV,const t_u16 KeyIVLength,t_u8 * Data,t_u16 * DataLength)13797 int wlan_set_crypto_AES_ECB_decrypt(
13798 const t_u8 *Key, const t_u16 KeyLength, const t_u8 *KeyIV, const t_u16 KeyIVLength, t_u8 *Data, t_u16 *DataLength)
13799 {
13800 t_u16 aes_ecb_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13801 t_u16 aes_ecb_keyiv_length = EU_CRYPTO_KEYIV_MAX_LENGTH;
13802 t_u16 aes_ecb_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13803
13804 #if defined(SD8801)
13805 return -WM_E_PERM;
13806 #endif
13807
13808 if (!wlan_is_started())
13809 {
13810 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13811 return -WM_FAIL;
13812 }
13813
13814 if (KeyLength > aes_ecb_key_length)
13815 return -WM_FAIL;
13816 if (KeyIVLength > aes_ecb_keyiv_length)
13817 return -WM_FAIL;
13818 if (*DataLength > aes_ecb_data_length)
13819 return -WM_FAIL;
13820 EU_Crypto Crypto_AES_ECB_Param;
13821 Crypto_AES_ECB_Param.KeyIVLength = KeyIVLength;
13822 memcpy(Crypto_AES_ECB_Param.KeyIV, KeyIV, KeyIVLength);
13823 Crypto_AES_ECB_Param.KeyLength = KeyLength;
13824 memcpy(Crypto_AES_ECB_Param.Key, Key, KeyLength);
13825 Crypto_AES_ECB_Param.DataLength = DataLength;
13826 Crypto_AES_ECB_Param.Data = Data;
13827
13828 t_u16 EncDec = 0;
13829
13830 return wifi_set_eu_crypto(&Crypto_AES_ECB_Param, CRYPTO_AES_ECB, EncDec);
13831 }
13832
wlan_set_crypto_AES_WRAP_encrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * KeyIV,const t_u16 KeyIVLength,t_u8 * Data,t_u16 * DataLength)13833 int wlan_set_crypto_AES_WRAP_encrypt(
13834 const t_u8 *Key, const t_u16 KeyLength, const t_u8 *KeyIV, const t_u16 KeyIVLength, t_u8 *Data, t_u16 *DataLength)
13835 {
13836 t_u16 aes_wrap_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13837 t_u16 aes_wrap_keyiv_length = EU_CRYPTO_KEYIV_MAX_LENGTH;
13838 t_u16 aes_wrap_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13839
13840 #if defined(SD8801)
13841 return -WM_E_PERM;
13842 #endif
13843
13844 if (!wlan_is_started())
13845 {
13846 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13847 return -WM_FAIL;
13848 }
13849
13850 if (KeyLength > aes_wrap_key_length)
13851 return -WM_FAIL;
13852 if (KeyIVLength > aes_wrap_keyiv_length)
13853 return -WM_FAIL;
13854 if (*DataLength > aes_wrap_data_length)
13855 return -WM_FAIL;
13856
13857 EU_Crypto Crypto_AES_WRAP_Param;
13858 Crypto_AES_WRAP_Param.KeyIVLength = KeyIVLength;
13859 memcpy(Crypto_AES_WRAP_Param.KeyIV, KeyIV, KeyIVLength);
13860 Crypto_AES_WRAP_Param.KeyLength = KeyLength;
13861 memcpy(Crypto_AES_WRAP_Param.Key, Key, KeyLength);
13862 Crypto_AES_WRAP_Param.DataLength = DataLength;
13863 Crypto_AES_WRAP_Param.Data = Data;
13864
13865 t_u16 EncDec = 1;
13866
13867 return wifi_set_eu_crypto(&Crypto_AES_WRAP_Param, CRYPTO_AES_WRAP, EncDec);
13868 }
13869
wlan_set_crypto_AES_WRAP_decrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * KeyIV,const t_u16 KeyIVLength,t_u8 * Data,t_u16 * DataLength)13870 int wlan_set_crypto_AES_WRAP_decrypt(
13871 const t_u8 *Key, const t_u16 KeyLength, const t_u8 *KeyIV, const t_u16 KeyIVLength, t_u8 *Data, t_u16 *DataLength)
13872 {
13873 t_u16 aes_wrap_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13874 t_u16 aes_wrap_keyiv_length = EU_CRYPTO_KEYIV_MAX_LENGTH;
13875 t_u16 aes_wrap_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13876
13877 #if defined(SD8801)
13878 return -WM_E_PERM;
13879 #endif
13880
13881 if (!wlan_is_started())
13882 {
13883 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13884 return -WM_FAIL;
13885 }
13886
13887 if (KeyLength > aes_wrap_key_length)
13888 return -WM_FAIL;
13889 if (KeyIVLength > aes_wrap_keyiv_length)
13890 return -WM_FAIL;
13891 if (*DataLength > aes_wrap_data_length)
13892 return -WM_FAIL;
13893 EU_Crypto Crypto_AES_WRAP_Param;
13894 Crypto_AES_WRAP_Param.KeyIVLength = KeyIVLength;
13895 memcpy(Crypto_AES_WRAP_Param.KeyIV, KeyIV, KeyIVLength);
13896 Crypto_AES_WRAP_Param.KeyLength = KeyLength;
13897 memcpy(Crypto_AES_WRAP_Param.Key, Key, KeyLength);
13898 Crypto_AES_WRAP_Param.DataLength = DataLength;
13899 Crypto_AES_WRAP_Param.Data = Data;
13900
13901 t_u16 EncDec = 0;
13902
13903 return wifi_set_eu_crypto(&Crypto_AES_WRAP_Param, CRYPTO_AES_WRAP, EncDec);
13904 }
13905
wlan_set_crypto_AES_CCMP_encrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * AAD,const t_u16 AADLength,const t_u8 * Nonce,const t_u16 NonceLength,t_u8 * Data,t_u16 * DataLength)13906 int wlan_set_crypto_AES_CCMP_encrypt(const t_u8 *Key,
13907 const t_u16 KeyLength,
13908 const t_u8 *AAD,
13909 const t_u16 AADLength,
13910 const t_u8 *Nonce,
13911 const t_u16 NonceLength,
13912 t_u8 *Data,
13913 t_u16 *DataLength)
13914 {
13915 t_u16 aes_ccmp_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13916 t_u16 aes_ccmp_AAD_length = EU_CRYPTO_AAD_MAX_LENGTH;
13917 t_u16 aes_ccmp_Nonce_length = EU_CRYPTO_NONCE_MAX_LENGTH;
13918 t_u16 aes_ccmp_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13919
13920 #if defined(SD8801)
13921 return -WM_E_PERM;
13922 #endif
13923 #if defined(SD8978)
13924 if (KeyLength == aes_ccmp_key_length)
13925 {
13926 return -WM_E_PERM;
13927 }
13928 #endif
13929
13930 if (!wlan_is_started())
13931 {
13932 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13933 return -WM_FAIL;
13934 }
13935
13936 if (KeyLength > aes_ccmp_key_length)
13937 return -WM_FAIL;
13938 if (AADLength > aes_ccmp_AAD_length)
13939 return -WM_FAIL;
13940 if (NonceLength > aes_ccmp_Nonce_length)
13941 return -WM_FAIL;
13942 if (*DataLength > aes_ccmp_data_length)
13943 return -WM_FAIL;
13944 EU_Crypto Crypto_AES_CCMP_Param;
13945 Crypto_AES_CCMP_Param.AADLength = AADLength;
13946 memcpy(Crypto_AES_CCMP_Param.AAD, AAD, AADLength);
13947 Crypto_AES_CCMP_Param.NonceLength = NonceLength;
13948 memcpy(Crypto_AES_CCMP_Param.Nonce, Nonce, NonceLength);
13949 Crypto_AES_CCMP_Param.KeyLength = KeyLength;
13950 memcpy(Crypto_AES_CCMP_Param.Key, Key, KeyLength);
13951 Crypto_AES_CCMP_Param.DataLength = DataLength;
13952 Crypto_AES_CCMP_Param.Data = Data;
13953
13954 t_u16 EncDec = 1;
13955
13956 return wifi_set_eu_crypto(&Crypto_AES_CCMP_Param, CRYPTO_AES_CCMP, EncDec);
13957 }
13958
wlan_set_crypto_AES_CCMP_decrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * AAD,const t_u16 AADLength,const t_u8 * Nonce,const t_u16 NonceLength,t_u8 * Data,t_u16 * DataLength)13959 int wlan_set_crypto_AES_CCMP_decrypt(const t_u8 *Key,
13960 const t_u16 KeyLength,
13961 const t_u8 *AAD,
13962 const t_u16 AADLength,
13963 const t_u8 *Nonce,
13964 const t_u16 NonceLength,
13965 t_u8 *Data,
13966 t_u16 *DataLength)
13967 {
13968 t_u16 aes_ccmp_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
13969 t_u16 aes_ccmp_AAD_length = EU_CRYPTO_AAD_MAX_LENGTH;
13970 t_u16 aes_ccmp_Nonce_length = EU_CRYPTO_NONCE_MAX_LENGTH;
13971 t_u16 aes_ccmp_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
13972
13973 #if defined(SD8801)
13974 return -WM_E_PERM;
13975 #endif
13976
13977 #if defined(SD8978)
13978 if (KeyLength == aes_ccmp_key_length)
13979 {
13980 return -WM_E_PERM;
13981 }
13982 #endif
13983
13984 if (!wlan_is_started())
13985 {
13986 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
13987 return -WM_FAIL;
13988 }
13989
13990 if (KeyLength > aes_ccmp_key_length)
13991 return -WM_FAIL;
13992 if (AADLength > aes_ccmp_AAD_length)
13993 return -WM_FAIL;
13994 if (NonceLength > aes_ccmp_Nonce_length)
13995 return -WM_FAIL;
13996 if (*DataLength > aes_ccmp_data_length)
13997 return -WM_FAIL;
13998 EU_Crypto Crypto_AES_CCMP_Param;
13999 Crypto_AES_CCMP_Param.AADLength = AADLength;
14000 memcpy(Crypto_AES_CCMP_Param.AAD, AAD, AADLength);
14001 Crypto_AES_CCMP_Param.NonceLength = NonceLength;
14002 memcpy(Crypto_AES_CCMP_Param.Nonce, Nonce, NonceLength);
14003 Crypto_AES_CCMP_Param.KeyLength = KeyLength;
14004 memcpy(Crypto_AES_CCMP_Param.Key, Key, KeyLength);
14005 Crypto_AES_CCMP_Param.DataLength = DataLength;
14006 Crypto_AES_CCMP_Param.Data = Data;
14007
14008 t_u16 EncDec = 0;
14009
14010 return wifi_set_eu_crypto(&Crypto_AES_CCMP_Param, CRYPTO_AES_CCMP, EncDec);
14011 }
14012
wlan_set_crypto_AES_GCMP_encrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * AAD,const t_u16 AADLength,const t_u8 * Nonce,const t_u16 NonceLength,t_u8 * Data,t_u16 * DataLength)14013 int wlan_set_crypto_AES_GCMP_encrypt(const t_u8 *Key,
14014 const t_u16 KeyLength,
14015 const t_u8 *AAD,
14016 const t_u16 AADLength,
14017 const t_u8 *Nonce,
14018 const t_u16 NonceLength,
14019 t_u8 *Data,
14020 t_u16 *DataLength)
14021 {
14022 #if defined(SD8801) || defined(SD8978)
14023 return -WM_E_PERM;
14024 #else
14025 t_u16 aes_gcmp_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
14026 t_u16 aes_gcmp_AAD_length = EU_CRYPTO_AAD_MAX_LENGTH;
14027 t_u16 aes_gcmp_Nonce_length = EU_CRYPTO_NONCE_MAX_LENGTH;
14028 t_u16 aes_gcmp_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
14029
14030 if (!wlan_is_started())
14031 {
14032 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
14033 return -WM_FAIL;
14034 }
14035
14036 if (KeyLength > aes_gcmp_key_length)
14037 return -WM_FAIL;
14038 if (AADLength > aes_gcmp_AAD_length)
14039 return -WM_FAIL;
14040 if (NonceLength > aes_gcmp_Nonce_length)
14041 return -WM_FAIL;
14042 if (*DataLength > aes_gcmp_data_length)
14043 return -WM_FAIL;
14044 EU_Crypto Crypto_AES_GCMP_Param;
14045 Crypto_AES_GCMP_Param.AADLength = AADLength;
14046 memcpy(Crypto_AES_GCMP_Param.AAD, AAD, AADLength);
14047 Crypto_AES_GCMP_Param.NonceLength = NonceLength;
14048 memcpy(Crypto_AES_GCMP_Param.Nonce, Nonce, NonceLength);
14049 Crypto_AES_GCMP_Param.KeyLength = KeyLength;
14050 memcpy(Crypto_AES_GCMP_Param.Key, Key, KeyLength);
14051 Crypto_AES_GCMP_Param.DataLength = DataLength;
14052 Crypto_AES_GCMP_Param.Data = Data;
14053
14054 t_u16 EncDec = 1;
14055
14056 return wifi_set_eu_crypto(&Crypto_AES_GCMP_Param, CRYPTO_AES_GCMP, EncDec);
14057 #endif
14058 }
14059
wlan_set_crypto_AES_GCMP_decrypt(const t_u8 * Key,const t_u16 KeyLength,const t_u8 * AAD,const t_u16 AADLength,const t_u8 * Nonce,const t_u16 NonceLength,t_u8 * Data,t_u16 * DataLength)14060 int wlan_set_crypto_AES_GCMP_decrypt(const t_u8 *Key,
14061 const t_u16 KeyLength,
14062 const t_u8 *AAD,
14063 const t_u16 AADLength,
14064 const t_u8 *Nonce,
14065 const t_u16 NonceLength,
14066 t_u8 *Data,
14067 t_u16 *DataLength)
14068 {
14069 #if defined(SD8801) || defined(SD8978)
14070 return -WM_E_PERM;
14071 #else
14072 t_u16 aes_gcmp_key_length = EU_CRYPTO_KEY_MAX_LENGTH;
14073 t_u16 aes_gcmp_AAD_length = EU_CRYPTO_AAD_MAX_LENGTH;
14074 t_u16 aes_gcmp_Nonce_length = EU_CRYPTO_NONCE_MAX_LENGTH;
14075 t_u16 aes_gcmp_data_length = EU_CRYPTO_DATA_MAX_LENGTH;
14076
14077 if (!wlan_is_started())
14078 {
14079 (void)PRINTF("Must enable Wi-Fi firstly\r\n");
14080 return -WM_FAIL;
14081 }
14082
14083 if (KeyLength > aes_gcmp_key_length)
14084 return -WM_FAIL;
14085 if (AADLength > aes_gcmp_AAD_length)
14086 return -WM_FAIL;
14087 if (NonceLength > aes_gcmp_Nonce_length)
14088 return -WM_FAIL;
14089 if (*DataLength > aes_gcmp_data_length)
14090 return -WM_FAIL;
14091 EU_Crypto Crypto_AES_GCMP_Param;
14092 Crypto_AES_GCMP_Param.AADLength = AADLength;
14093 memcpy(Crypto_AES_GCMP_Param.AAD, AAD, AADLength);
14094 Crypto_AES_GCMP_Param.NonceLength = NonceLength;
14095 memcpy(Crypto_AES_GCMP_Param.Nonce, Nonce, NonceLength);
14096 Crypto_AES_GCMP_Param.KeyLength = KeyLength;
14097 memcpy(Crypto_AES_GCMP_Param.Key, Key, KeyLength);
14098 Crypto_AES_GCMP_Param.DataLength = DataLength;
14099 Crypto_AES_GCMP_Param.Data = Data;
14100
14101 t_u16 EncDec = 0;
14102
14103 return wifi_set_eu_crypto(&Crypto_AES_GCMP_Param, CRYPTO_AES_GCMP, EncDec);
14104 #endif
14105 }
14106 #endif /* CONFIG_WIFI_EU_CRYPTO */
14107
14108 #if CONFIG_HEAP_DEBUG
wlan_show_os_mem_stat()14109 void wlan_show_os_mem_stat()
14110 {
14111 wifi_show_os_mem_stat();
14112 }
14113 #endif
14114
14115 #if CONFIG_MULTI_CHAN
wlan_set_multi_chan_status(const int status)14116 int wlan_set_multi_chan_status(const int status)
14117 {
14118 return wifi_set_mc_policy(status);
14119 }
14120
wlan_get_multi_chan_status(int * status)14121 int wlan_get_multi_chan_status(int *status)
14122 {
14123 (*status) = wifi_get_mc_policy();
14124 return WM_SUCCESS;
14125 }
14126
wlan_set_drcs_cfg(const wlan_drcs_cfg_t * drcs_cfg,const int num)14127 int wlan_set_drcs_cfg(const wlan_drcs_cfg_t *drcs_cfg, const int num)
14128 {
14129 return wifi_set_mc_cfg_ext((wifi_drcs_cfg_t *)drcs_cfg, num);
14130 }
14131
wlan_get_drcs_cfg(wlan_drcs_cfg_t * drcs_cfg,int num)14132 int wlan_get_drcs_cfg(wlan_drcs_cfg_t *drcs_cfg, int num)
14133 {
14134 return wifi_get_mc_cfg_ext((wifi_drcs_cfg_t *)drcs_cfg, num);
14135 }
14136 #endif
14137
14138 #if CONFIG_WPS2
wlan_set_prov_session(int session)14139 void wlan_set_prov_session(int session)
14140 {
14141 prov_session_attempt = session;
14142 wps_conf.prov_session = session;
14143 }
14144
wlan_get_prov_session(void)14145 int wlan_get_prov_session(void)
14146 {
14147 return prov_session_attempt;
14148 }
14149 #endif
14150
14151 #if CONFIG_1AS
wlan_get_fw_timestamp(wlan_correlated_time_t * time)14152 int wlan_get_fw_timestamp(wlan_correlated_time_t *time)
14153 {
14154 return wifi_get_fw_timestamp((wifi_correlated_time_t *)time);
14155 }
14156
wlan_start_timing_measurement(int bss_type,t_u8 * peer_mac,uint8_t num_of_tm)14157 int wlan_start_timing_measurement(int bss_type, t_u8 *peer_mac, uint8_t num_of_tm)
14158 {
14159 return wifi_start_timing_measurement(bss_type, peer_mac, num_of_tm);
14160 }
14161
wlan_end_timing_measurement(wlan_dot1as_info_t * info)14162 void wlan_end_timing_measurement(wlan_dot1as_info_t *info)
14163 {
14164 /* Do nothing for now */
14165 }
14166
wlan_request_timing_measurement(int bss_type,t_u8 * peer_mac,t_u8 trigger)14167 void wlan_request_timing_measurement(int bss_type, t_u8 *peer_mac, t_u8 trigger)
14168 {
14169 wifi_request_timing_measurement(bss_type, peer_mac, trigger);
14170 }
14171
wlan_report_timing_measurement(wlan_dot1as_info_t * info)14172 void wlan_report_timing_measurement(wlan_dot1as_info_t *info)
14173 {
14174 /* Do nothing for now */
14175 }
14176 #endif
14177
14178 #if CONFIG_ECSA
14179
wlan_uap_set_ecsa_cfg(t_u8 block_tx,t_u8 oper_class,t_u8 channel,t_u8 switch_count,t_u8 band_width)14180 int wlan_uap_set_ecsa_cfg(t_u8 block_tx, t_u8 oper_class, t_u8 channel, t_u8 switch_count, t_u8 band_width)
14181 {
14182 t_u8 ecsa = MFALSE;
14183 int ret = 0;
14184
14185 ret = wlan_set_uap_ecsa_cfg(block_tx, oper_class, channel, switch_count, band_width, ecsa);
14186
14187 return ret;
14188 }
14189
14190 #endif
14191 #if CONFIG_11AX
14192 #if CONFIG_MMSF
wlan_set_mmsf(const t_u8 enable,const t_u8 Density,const t_u8 MMSF)14193 int wlan_set_mmsf(const t_u8 enable, const t_u8 Density, const t_u8 MMSF)
14194 {
14195 return wifi_mmsf_cfg(ACTION_SET, (t_u8 *)&enable, (t_u8 *)&Density, (t_u8 *)&MMSF);
14196 }
14197
wlan_get_mmsf(t_u8 * enable,t_u8 * Density,t_u8 * MMSF)14198 int wlan_get_mmsf(t_u8 *enable, t_u8 *Density, t_u8 *MMSF)
14199 {
14200 return wifi_mmsf_cfg(ACTION_GET, enable, Density, MMSF);
14201 }
14202 #endif
14203 #endif
14204
14205 #if CONFIG_WIFI_RECOVERY
wlan_recovery_test(void)14206 int wlan_recovery_test(void)
14207 {
14208 return wifi_recovery_test();
14209 }
14210 #endif
14211
14212 #if CONFIG_SUBSCRIBE_EVENT_SUPPORT
14213 /**
14214 * @brief This function subscribe event to firmware.
14215 *
14216 * @param sbitmap A pointer to specific event from user.
14217 * @param thresh_value A pointer to value from user.
14218 * @param freq A pointer to freq from user.
14219 *
14220 * @return MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE or WM_E_INVAL
14221 */
wlan_set_subscribe_event(unsigned int event_id,unsigned int thresh_value,unsigned int freq)14222 int wlan_set_subscribe_event(unsigned int event_id, unsigned int thresh_value, unsigned int freq)
14223 {
14224 int ret = WM_E_INVAL;
14225 switch (event_id)
14226 {
14227 case EVENT_SUB_RSSI_LOW:
14228 ret = wifi_set_threshold_rssi_low(mlan_adap->priv[0], thresh_value, freq);
14229 break;
14230 case EVENT_SUB_RSSI_HIGH:
14231 ret = wifi_set_threshold_rssi_high(mlan_adap->priv[0], thresh_value, freq);
14232 break;
14233 case EVENT_SUB_SNR_LOW:
14234 ret = wifi_set_threshold_snr_low(mlan_adap->priv[0], thresh_value, freq);
14235 break;
14236 case EVENT_SUB_SNR_HIGH:
14237 ret = wifi_set_threshold_snr_high(mlan_adap->priv[0], thresh_value, freq);
14238 break;
14239 case EVENT_SUB_MAX_FAIL:
14240 ret = wifi_set_threshold_max_fail(mlan_adap->priv[0], thresh_value, freq);
14241 break;
14242 case EVENT_SUB_BEACON_MISSED:
14243 ret = wifi_set_threshold_beacon_miss(mlan_adap->priv[0], thresh_value, freq);
14244 break;
14245 case EVENT_SUB_DATA_RSSI_LOW:
14246 ret = wifi_set_threshold_data_rssi_low(mlan_adap->priv[0], thresh_value, freq);
14247 break;
14248 case EVENT_SUB_DATA_RSSI_HIGH:
14249 ret = wifi_set_threshold_data_rssi_high(mlan_adap->priv[0], thresh_value, freq);
14250 break;
14251 case EVENT_SUB_DATA_SNR_LOW:
14252 ret = wifi_set_threshold_data_snr_low(mlan_adap->priv[0], thresh_value, freq);
14253 break;
14254 case EVENT_SUB_DATA_SNR_HIGH:
14255 ret = wifi_set_threshold_data_snr_high(mlan_adap->priv[0], thresh_value, freq);
14256 break;
14257 case EVENT_SUB_PRE_BEACON_LOST:
14258 ret = wifi_set_threshold_pre_beacon_lost(mlan_adap->priv[0], thresh_value, freq);
14259 break;
14260 default:
14261 ret = WM_E_INVAL;
14262 break;
14263 }
14264 return ret;
14265 }
14266
wlan_get_subscribe_event(wlan_ds_subscribe_evt * sub_evt)14267 int wlan_get_subscribe_event(wlan_ds_subscribe_evt *sub_evt)
14268 {
14269 int ret = WM_E_INVAL;
14270 mlan_ds_subscribe_evt msub_evt;
14271 memset(&msub_evt, 0, sizeof(msub_evt));
14272 ret = wifi_get_subscribe_event(mlan_adap->priv[0], &msub_evt);
14273 memcpy((t_u8 *)sub_evt, (t_u8 *)&msub_evt.evt_bitmap, sizeof(wlan_ds_subscribe_evt));
14274 return ret;
14275 }
14276
wlan_clear_subscribe_event(unsigned int event_id)14277 int wlan_clear_subscribe_event(unsigned int event_id)
14278 {
14279 /*bitmap parameter analyse*/
14280 int evt_bitmap = 0;
14281 switch (event_id)
14282 {
14283 case EVENT_SUB_RSSI_LOW:
14284 evt_bitmap = SUBSCRIBE_EVT_RSSI_LOW;
14285 break;
14286 case EVENT_SUB_RSSI_HIGH:
14287 evt_bitmap = SUBSCRIBE_EVT_RSSI_HIGH;
14288 break;
14289 case EVENT_SUB_SNR_LOW:
14290 evt_bitmap = SUBSCRIBE_EVT_SNR_LOW;
14291 break;
14292 case EVENT_SUB_SNR_HIGH:
14293 evt_bitmap = SUBSCRIBE_EVT_SNR_HIGH;
14294 break;
14295 case EVENT_SUB_MAX_FAIL:
14296 evt_bitmap = SUBSCRIBE_EVT_MAX_FAIL;
14297 break;
14298 case EVENT_SUB_BEACON_MISSED:
14299 evt_bitmap = SUBSCRIBE_EVT_BEACON_MISSED;
14300 break;
14301 case EVENT_SUB_DATA_RSSI_LOW:
14302 evt_bitmap = SUBSCRIBE_EVT_DATA_RSSI_LOW;
14303 break;
14304 case EVENT_SUB_DATA_RSSI_HIGH:
14305 evt_bitmap = SUBSCRIBE_EVT_DATA_RSSI_HIGH;
14306 break;
14307 case EVENT_SUB_DATA_SNR_LOW:
14308 evt_bitmap = SUBSCRIBE_EVT_DATA_SNR_LOW;
14309 break;
14310 case EVENT_SUB_DATA_SNR_HIGH:
14311 evt_bitmap = SUBSCRIBE_EVT_DATA_SNR_HIGH;
14312 break;
14313 case EVENT_SUB_LINK_QUALITY:
14314 evt_bitmap = SUBSCRIBE_EVT_LINK_QUALITY;
14315 break;
14316 case EVENT_SUB_PRE_BEACON_LOST:
14317 evt_bitmap = SUBSCRIBE_EVT_PRE_BEACON_LOST;
14318 break;
14319 default:
14320 return WM_E_INVAL;
14321 break;
14322 }
14323 return wifi_clear_subscribe_event(mlan_adap->priv[0], evt_bitmap);
14324 }
14325
wlan_set_threshold_link_quality(unsigned int event_id,unsigned int link_snr,unsigned int link_snr_freq,unsigned int link_rate,unsigned int link_rate_freq,unsigned int link_tx_latency,unsigned int link_tx_lantency_freq)14326 int wlan_set_threshold_link_quality(unsigned int event_id,
14327 unsigned int link_snr,
14328 unsigned int link_snr_freq,
14329 unsigned int link_rate,
14330 unsigned int link_rate_freq,
14331 unsigned int link_tx_latency,
14332 unsigned int link_tx_lantency_freq)
14333 {
14334 if (event_id == EVENT_SUB_LINK_QUALITY)
14335 return wifi_set_threshold_link_quality(mlan_adap->priv[0], link_snr, link_snr_freq, link_rate, link_rate_freq,
14336 link_tx_latency, link_tx_lantency_freq);
14337 return WM_E_INVAL;
14338 }
14339 #endif
14340
14341 #if CONFIG_WIFI_REG_ACCESS
wlan_reg_access(wifi_reg_t type,uint16_t action,uint32_t offset,uint32_t * value)14342 int wlan_reg_access(wifi_reg_t type, uint16_t action, uint32_t offset, uint32_t *value)
14343 {
14344 return wifi_reg_access(type, action, offset, value);
14345 }
14346 #endif
14347
14348 #if CONFIG_WMM_UAPSD
14349 static t_u8 uapsd_qos_info = WMM_UAPSD_QOS_INFO;
14350 static unsigned int uapsd_sleep_period = WMM_UAPSD_SLEEP_PERIOD;
wlan_wmm_uapsd_qosinfo(t_u8 * qos_info,t_u8 action)14351 int wlan_wmm_uapsd_qosinfo(t_u8 *qos_info, t_u8 action)
14352 {
14353 int ret = WM_SUCCESS;
14354
14355 ret = wifi_wmm_qos_cfg(qos_info, action);
14356 if (ret == WM_SUCCESS && action == ACTION_SET)
14357 uapsd_qos_info = *qos_info;
14358
14359 return ret;
14360 }
14361
wlan_set_wmm_uapsd(t_u8 uapsd_enable)14362 int wlan_set_wmm_uapsd(t_u8 uapsd_enable)
14363 {
14364 #if !CONFIG_WNM_PS
14365 unsigned int condition = 0;
14366 #endif
14367
14368 if (!is_uap_state(CM_UAP_INITIALIZING) || is_sta_connecting())
14369 {
14370 (void)PRINTF("Failed to enable/disable UAPSD, because uAP is up/STA is connecting\n");
14371 return -WM_FAIL;
14372 }
14373
14374 if (uapsd_enable)
14375 {
14376 (void)wifi_wmm_qos_cfg(&uapsd_qos_info, 1);
14377 (void)wifi_sleep_period(&uapsd_sleep_period, 1);
14378 #if !CONFIG_WNM_PS
14379 (void)wlan_ieeeps_on(condition);
14380 #endif
14381 }
14382 else
14383 {
14384 t_u8 qos_info = 0;
14385 unsigned int period = 0;
14386 (void)wifi_wmm_qos_cfg(&qos_info, 1);
14387 (void)wifi_sleep_period(&period, 1);
14388 (void)wlan_ieeeps_off();
14389 }
14390 return WM_SUCCESS;
14391 }
wlan_sleep_period(unsigned int * sleep_period,t_u8 action)14392 int wlan_sleep_period(unsigned int *sleep_period, t_u8 action)
14393 {
14394 int ret = WM_SUCCESS;
14395
14396 ret = wifi_sleep_period(sleep_period, action);
14397 if (ret == WM_SUCCESS && action == ACTION_SET)
14398 uapsd_sleep_period = *sleep_period;
14399
14400 return ret;
14401 }
14402
wlan_is_wmm_uapsd_enabled(void)14403 t_u8 wlan_is_wmm_uapsd_enabled(void)
14404 {
14405 return (mlan_adap ? mlan_adap->pps_uapsd_mode : false);
14406 }
14407 #endif
14408
14409 #if CONFIG_TX_AMPDU_PROT_MODE
wlan_tx_ampdu_prot_mode(tx_ampdu_prot_mode_para * prot_mode,t_u16 action)14410 int wlan_tx_ampdu_prot_mode(tx_ampdu_prot_mode_para *prot_mode, t_u16 action)
14411 {
14412 return wifi_tx_ampdu_prot_mode(prot_mode, action);
14413 }
14414 #endif
14415
14416 #if CONFIG_MEF_CFG
wlan_mef_set_auto_arp(t_u8 mef_action)14417 int wlan_mef_set_auto_arp(t_u8 mef_action)
14418 {
14419 int ret, index;
14420 unsigned int ipv4_addr[2];
14421 int ipv4_addr_num = 0;
14422 int filter_num = 0;
14423
14424 if(!is_sta_ipv4_connected() && !is_uap_started())
14425 {
14426 wlcm_e("No connection on STA and uAP is not activated.");
14427 wlcm_e("Should at least meet one condition.");
14428 return -WM_E_PERM;
14429 }
14430
14431 if (g_flt_cfg.nentries >= MAX_NUM_ENTRIES)
14432 {
14433 wlcm_e("Number of MEF entries(%d) exceeds limit(8)!", g_flt_cfg.nentries);
14434 return -WM_FAIL;
14435 }
14436
14437 (void)memset(ipv4_addr, 0x0, sizeof(ipv4_addr));
14438 if(is_sta_ipv4_connected() != 0)
14439 {
14440 ret = wlan_get_ipv4_addr(&ipv4_addr[0]);
14441 if (ret != WM_SUCCESS)
14442 {
14443 wlcm_e("Cannot get STA IP");
14444 return -WM_FAIL;
14445 }
14446 ipv4_addr_num++;
14447 }
14448 if(is_uap_started() != 0)
14449 {
14450 ret = wlan_get_uap_ipv4_addr(&ipv4_addr[1]);
14451 if (ret != WM_SUCCESS)
14452 {
14453 wlcm_e("Cannot get UAP IP");
14454 return -WM_FAIL;
14455 }
14456 ipv4_addr_num++;
14457 }
14458 index = g_flt_cfg.nentries;
14459 g_flt_cfg.criteria |= (CRITERIA_BROADCAST | CRITERIA_UNICAST);
14460 g_flt_cfg.nentries++;
14461
14462 g_flt_cfg.mef_entry[index].mode = MEF_MODE_HOST_SLEEP;
14463 g_flt_cfg.mef_entry[index].action = (MEF_AUTO_ARP | (mef_action & 0xF));
14464 g_flt_cfg.mef_entry[index].filter_num = 1;
14465 g_flt_cfg.mef_entry[index].filter_item[0].type = TYPE_BYTE_EQ;
14466 g_flt_cfg.mef_entry[index].filter_item[0].repeat = 1;
14467 g_flt_cfg.mef_entry[index].filter_item[0].offset = IPV4_PKT_OFFSET;
14468 g_flt_cfg.mef_entry[index].filter_item[0].num_byte_seq = 2;
14469 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[0].byte_seq, "\x08\x06", 2);
14470 g_flt_cfg.mef_entry[index].rpn[1] = RPN_TYPE_AND;
14471
14472 if(is_sta_ipv4_connected() != 0)
14473 {
14474 g_flt_cfg.mef_entry[index].filter_num++;
14475 filter_num = g_flt_cfg.mef_entry[index].filter_num;
14476 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].type = TYPE_BYTE_EQ;
14477 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].repeat = 1;
14478 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].offset = 46;
14479 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].num_byte_seq = 4;
14480 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].byte_seq,
14481 &ipv4_addr[0], 4); // STA IP address
14482 }
14483
14484 if(is_uap_started() != 0)
14485 {
14486 g_flt_cfg.mef_entry[index].filter_num++;
14487 filter_num = g_flt_cfg.mef_entry[index].filter_num;
14488 if(ipv4_addr_num == 2)
14489 g_flt_cfg.mef_entry[index].rpn[filter_num] = RPN_TYPE_OR;
14490 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].type = TYPE_BYTE_EQ;
14491 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].repeat = 1;
14492 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].offset = 46;
14493 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].num_byte_seq = 4;
14494 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].byte_seq,
14495 &ipv4_addr[1], 4); // UAP IP address
14496 }
14497
14498 return WM_SUCCESS;
14499 }
14500
wlan_mef_set_auto_ping(t_u8 mef_action)14501 int wlan_mef_set_auto_ping(t_u8 mef_action)
14502 {
14503 int ret, index;
14504 unsigned int ipv4_addr[2];
14505 int ipv4_addr_num = 0;
14506 int filter_num = 0;
14507
14508 if(!is_sta_ipv4_connected() && !is_uap_started())
14509 {
14510 wlcm_e("No connection on STA and uAP is not activated.");
14511 wlcm_e("Should at least meet one condition.");
14512 return -WM_E_PERM;
14513 }
14514
14515 if (g_flt_cfg.nentries >= MAX_NUM_ENTRIES)
14516 {
14517 wlcm_e("Number of MEF entries(%d) exceeds limit(8)!", g_flt_cfg.nentries);
14518 return -WM_FAIL;
14519 }
14520
14521 (void)memset(ipv4_addr, 0x0, sizeof(ipv4_addr));
14522 if(is_sta_ipv4_connected() != 0)
14523 {
14524 ret = wlan_get_ipv4_addr(&ipv4_addr[0]);
14525 if (ret != WM_SUCCESS)
14526 {
14527 wlcm_e("Cannot get STA IP");
14528 return -WM_FAIL;
14529 }
14530 ipv4_addr_num++;
14531 }
14532 if(is_uap_started() != 0)
14533 {
14534 ret = wlan_get_uap_ipv4_addr(&ipv4_addr[1]);
14535 if (ret != WM_SUCCESS)
14536 {
14537 wlcm_e("Cannot get UAP IP");
14538 return -WM_FAIL;
14539 }
14540 ipv4_addr_num++;
14541 }
14542 index = g_flt_cfg.nentries;
14543 g_flt_cfg.criteria |= (CRITERIA_BROADCAST | CRITERIA_UNICAST);
14544 g_flt_cfg.nentries++;
14545 g_flt_cfg.mef_entry[index].mode = MEF_MODE_HOST_SLEEP;
14546 g_flt_cfg.mef_entry[index].action = (MEF_AUTO_PING | (mef_action & 0xF));
14547 g_flt_cfg.mef_entry[index].filter_num = 2;
14548 g_flt_cfg.mef_entry[index].filter_item[0].type = TYPE_BYTE_EQ;
14549 g_flt_cfg.mef_entry[index].filter_item[0].repeat = 1;
14550 g_flt_cfg.mef_entry[index].filter_item[0].offset = IPV4_PKT_OFFSET;
14551 g_flt_cfg.mef_entry[index].filter_item[0].num_byte_seq = 2;
14552 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[0].byte_seq, "\x08\x00", 2);
14553 g_flt_cfg.mef_entry[index].rpn[1] = RPN_TYPE_AND;
14554
14555 g_flt_cfg.mef_entry[index].filter_item[1].type = TYPE_DNUM_EQ;
14556 g_flt_cfg.mef_entry[index].filter_item[1].pattern = ICMP_OF_IP_PROTOCOL;
14557 g_flt_cfg.mef_entry[index].filter_item[1].offset = IP_PROTOCOL_OFFSET;
14558 g_flt_cfg.mef_entry[index].filter_item[1].num_bytes = 1;
14559 g_flt_cfg.mef_entry[index].rpn[2] = RPN_TYPE_AND;
14560
14561 if(is_sta_ipv4_connected() != 0)
14562 {
14563 g_flt_cfg.mef_entry[index].filter_num++;
14564 filter_num = g_flt_cfg.mef_entry[index].filter_num;
14565 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].type = TYPE_BYTE_EQ;
14566 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].repeat = 1;
14567 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].offset = 38;
14568 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].num_byte_seq = 4;
14569 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].byte_seq,
14570 &ipv4_addr[0], 4); //STA IP address
14571 }
14572
14573 if(is_uap_started() != 0)
14574 {
14575 g_flt_cfg.mef_entry[index].filter_num++;
14576 filter_num = g_flt_cfg.mef_entry[index].filter_num;
14577 if(ipv4_addr_num == 2)
14578 g_flt_cfg.mef_entry[index].rpn[filter_num - 1] = RPN_TYPE_OR;
14579 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].type = TYPE_BYTE_EQ;
14580 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].repeat = 1;
14581 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].offset = 38;
14582 g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].num_byte_seq = 4;
14583 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[filter_num - 1].byte_seq,
14584 &ipv4_addr[1], 4); // UAP IP address
14585 }
14586
14587 return WM_SUCCESS;
14588 }
14589
wlan_set_ipv6_ns_mef(t_u8 mef_action)14590 int wlan_set_ipv6_ns_mef(t_u8 mef_action)
14591 {
14592 int index;
14593
14594 if (g_flt_cfg.nentries >= MAX_NUM_ENTRIES)
14595 {
14596 wlcm_e("Number of MEF entries(%d) exceeds limit(8)!", g_flt_cfg.nentries);
14597 return -WM_FAIL;
14598 }
14599
14600 index = g_flt_cfg.nentries;
14601 g_flt_cfg.criteria |= (CRITERIA_UNICAST | CRITERIA_MULTICAST);
14602 g_flt_cfg.nentries++;
14603 g_flt_cfg.mef_entry[index].mode = MEF_MODE_HOST_SLEEP;
14604 g_flt_cfg.mef_entry[index].action = (MEF_NS_RESP| (mef_action & 0xF));
14605 g_flt_cfg.mef_entry[index].filter_num = 2;
14606
14607 g_flt_cfg.mef_entry[index].filter_item[0].fill_flag = (FILLING_TYPE | FILLING_REPEAT | FILLING_OFFSET | FILLING_BYTE_SEQ);
14608 g_flt_cfg.mef_entry[index].filter_item[0].type = TYPE_BYTE_EQ;
14609 g_flt_cfg.mef_entry[index].filter_item[0].repeat = 1;
14610 g_flt_cfg.mef_entry[index].filter_item[0].offset = IPV4_PKT_OFFSET;
14611 g_flt_cfg.mef_entry[index].filter_item[0].num_byte_seq = 2;
14612 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[0].byte_seq, "\x86\xdd", 2);
14613 g_flt_cfg.mef_entry[index].rpn[1] = RPN_TYPE_AND;
14614
14615 g_flt_cfg.mef_entry[index].filter_item[1].fill_flag = (FILLING_TYPE | FILLING_REPEAT | FILLING_OFFSET | FILLING_BYTE_SEQ);
14616 g_flt_cfg.mef_entry[index].filter_item[1].type = TYPE_BYTE_EQ;
14617 g_flt_cfg.mef_entry[index].filter_item[1].repeat = 1;
14618 g_flt_cfg.mef_entry[index].filter_item[1].offset = 62;
14619 g_flt_cfg.mef_entry[index].filter_item[1].num_byte_seq = 1;
14620 (void)memcpy(g_flt_cfg.mef_entry[index].filter_item[1].byte_seq, "\x87", 1);
14621
14622 return WM_SUCCESS;
14623 }
14624
wlan_mef_set_multicast(t_u8 mef_action)14625 int wlan_mef_set_multicast(t_u8 mef_action)
14626 {
14627 t_u32 index = 0;
14628
14629 if (g_flt_cfg.nentries >= MAX_NUM_ENTRIES)
14630 {
14631 wlcm_e("Number of MEF entries(%d) exceeds limit(8)!", g_flt_cfg.nentries);
14632 return -WM_FAIL;
14633 }
14634 index = g_flt_cfg.nentries;
14635 g_flt_cfg.criteria |= (CRITERIA_MULTICAST | CRITERIA_UNICAST);
14636 g_flt_cfg.nentries++;
14637
14638 g_flt_cfg.mef_entry[index].mode = MEF_MODE_HOST_SLEEP;
14639 g_flt_cfg.mef_entry[index].action = mef_action;
14640 g_flt_cfg.mef_entry[index].filter_num = 2;
14641 g_flt_cfg.mef_entry[index].filter_item[0].type = TYPE_BIT_EQ;
14642 g_flt_cfg.mef_entry[index].filter_item[0].offset = 0;
14643 g_flt_cfg.mef_entry[index].filter_item[0].num_byte_seq = 1;
14644 g_flt_cfg.mef_entry[index].filter_item[0].byte_seq[0] = 0x01;
14645 g_flt_cfg.mef_entry[index].filter_item[0].num_mask_seq = 1;
14646 g_flt_cfg.mef_entry[index].filter_item[0].mask_seq[0] = 0x01;
14647 g_flt_cfg.mef_entry[index].rpn[1] = RPN_TYPE_OR;
14648
14649 g_flt_cfg.mef_entry[index].filter_item[1].type = TYPE_BIT_EQ;
14650 g_flt_cfg.mef_entry[index].filter_item[1].offset = 38;
14651 g_flt_cfg.mef_entry[index].filter_item[1].num_byte_seq = 1;
14652 g_flt_cfg.mef_entry[index].filter_item[1].byte_seq[0] = 0xE0;
14653 g_flt_cfg.mef_entry[index].filter_item[1].num_mask_seq = 1;
14654 g_flt_cfg.mef_entry[index].filter_item[1].mask_seq[0] = 0xF0;
14655
14656 return WM_SUCCESS;
14657 }
14658
wlan_config_mef(int type,t_u8 mef_action)14659 int wlan_config_mef(int type, t_u8 mef_action)
14660 {
14661 int ret = -WM_FAIL;
14662
14663 if (!wlan_is_started())
14664 {
14665 (void)PRINTF("MEF configure is not allowed when WIFI is disabled\r\n");
14666 return -WM_FAIL;
14667 }
14668
14669 switch (type)
14670 {
14671 case MEF_TYPE_DELETE:
14672 (void)memset(&g_flt_cfg, 0, sizeof(wlan_flt_cfg_t));
14673 ret = wifi_set_packet_filters(&g_flt_cfg);
14674 if(ret == WM_SUCCESS)
14675 (void)PRINTF("delete all MEF entries Successful\n\r");
14676 else
14677 (void)PRINTF("delete all MEF entries Failed\n\r");
14678 break;
14679 case MEF_TYPE_PING:
14680 ret = wlan_mef_set_auto_ping(mef_action);
14681 if (ret == WM_SUCCESS)
14682 (void)PRINTF("Add ping MEF entry successful\n\r");
14683 else
14684 (void)PRINTF("Add ping MEF entry Failed\n\r");
14685 break;
14686 case MEF_TYPE_ARP:
14687 ret = wlan_mef_set_auto_arp(mef_action);
14688 if (ret == WM_SUCCESS)
14689 {
14690 (void)PRINTF("Add ARP MEF entry successful\n\r");
14691 }
14692 else
14693 (void)PRINTF("Add ARP MEF entry Failed\n\r");
14694 break;
14695 case MEF_TYPE_MULTICAST:
14696 ret = wlan_mef_set_multicast(mef_action);
14697 if (ret == WM_SUCCESS)
14698 (void)PRINTF("Add multicast MEF entry successful\n\r");
14699 else
14700 (void)PRINTF("Add multicast MEF entry Failed\n\r");
14701 break;
14702 case MEF_TYPE_IPV6_NS:
14703 ret = wlan_set_ipv6_ns_mef(mef_action);
14704 if (ret == WM_SUCCESS)
14705 (void)PRINTF("Add ns MEF entry successful\n\r");
14706 else
14707 (void)PRINTF("Add ns MEF entry Failed\n\r");
14708 break;
14709 default:
14710 (void)PRINTF("Error: unknown MEF type:%d", type);
14711 break;
14712 }
14713
14714 return ret;
14715 }
14716 #endif
14717
14718 #if CONFIG_CSI
wlan_register_csi_user_callback(int (* csi_data_recv_callback)(void * buffer,size_t len))14719 int wlan_register_csi_user_callback(int (*csi_data_recv_callback)(void *buffer, size_t len))
14720 {
14721 return register_csi_user_callback(csi_data_recv_callback);
14722 }
14723
wlan_unregister_csi_user_callback(void)14724 int wlan_unregister_csi_user_callback(void)
14725 {
14726 return unregister_csi_user_callback();
14727 }
14728
wlan_csi_cfg(wlan_csi_config_params_t * csi_params)14729 int wlan_csi_cfg(wlan_csi_config_params_t *csi_params)
14730 {
14731 int ret = WM_SUCCESS;
14732
14733 if (csi_params->csi_enable == 1)
14734 {
14735 csi_local_buff_init();
14736 }
14737 else
14738 {
14739 ret = unregister_csi_user_callback();
14740 }
14741
14742 ret = wifi_csi_cfg(csi_params);
14743
14744 return ret;
14745 }
14746 #endif
14747
14748 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_11R) || (CONFIG_ROAMING)
wlan_set_rssi_low_threshold(uint8_t threshold)14749 void wlan_set_rssi_low_threshold(uint8_t threshold)
14750 {
14751 wlan.rssi_low_threshold = threshold;
14752
14753 if (is_sta_connected())
14754 {
14755 #if CONFIG_ROAMING
14756 if (wlan.roaming_enabled == true)
14757 {
14758 (void)wifi_config_roaming(true, &wlan.rssi_low_threshold);
14759 }
14760 else
14761 #endif
14762 {
14763 (void)wifi_set_rssi_low_threshold(&wlan.rssi_low_threshold);
14764 }
14765 }
14766 }
14767 #endif
14768
14769 #if CONFIG_WPA_SUPP
14770 #if CONFIG_WPA_SUPP_WPS
wlan_remove_wps_network(void)14771 static int wlan_remove_wps_network(void)
14772 {
14773 unsigned int len, i;
14774 int ret = -WM_E_INVAL;
14775 struct netif *netif = net_get_sta_interface();
14776
14777 ret = wpa_supp_cancel_scan(netif);
14778 /* find the first network whose name matches and clear it out */
14779 for (i = 0; i < ARRAY_SIZE(wlan.networks); i++)
14780 {
14781 if (wlan.networks[i].wps_network)
14782 ret = wpa_supp_remove_network(netif, &wlan.networks[i]);
14783 }
14784 return ret;
14785 }
14786
wlan_start_wps_pbc(void)14787 int wlan_start_wps_pbc(void)
14788 {
14789 int ret = -WM_FAIL;
14790 struct netif *netif = net_get_sta_interface();
14791
14792 if (wlan.wps_session_attempt)
14793 {
14794 wlcm_d("WPS session is already in progress");
14795 return ret;
14796 }
14797 wlan_remove_wps_network();
14798 ret = wpa_supp_start_wps_pbc(netif, 0);
14799
14800 if (ret == -2)
14801 {
14802 wlcm_e("WPS PBC overlap detected");
14803 }
14804 return ret;
14805 }
14806
wlan_wps_generate_pin(uint32_t * pin)14807 void wlan_wps_generate_pin(uint32_t *pin)
14808 {
14809 struct netif *netif = net_get_sta_interface();
14810
14811 wpa_supp_wps_generate_pin(netif, (unsigned int *)pin);
14812 }
14813
wlan_start_wps_pin(const char * pin)14814 int wlan_start_wps_pin(const char *pin)
14815 {
14816 struct netif *netif = net_get_sta_interface();
14817
14818 if (wlan.wps_session_attempt)
14819 {
14820 wlcm_d("WPS session is already in progress");
14821 return -WM_FAIL;
14822 }
14823
14824 if (wpa_supp_wps_pin_valid(netif, (const unsigned char *)pin) != WM_SUCCESS)
14825 {
14826 wlcm_d("WPS PIN validation failed for %s", pin);
14827 return -WM_FAIL;
14828 }
14829 wlan_remove_wps_network();
14830 return wpa_supp_start_wps_pin(netif, pin, 0);
14831 }
14832
wlan_wps_cancel(void)14833 int wlan_wps_cancel(void)
14834 {
14835 struct netif *netif = net_get_sta_interface();
14836
14837 if (wlan.wps_session_attempt == 0)
14838 {
14839 return WM_SUCCESS;
14840 }
14841
14842 return wpa_supp_cancel_wps(netif, 0);
14843 }
14844
14845 #if CONFIG_WPA_SUPP_AP
wlan_start_ap_wps_pbc(void)14846 int wlan_start_ap_wps_pbc(void)
14847 {
14848 struct netif *netif = net_get_uap_interface();
14849
14850 if (is_uap_started() == 0)
14851 {
14852 wlcm_e("Cannot Start WPS PBC as uAP is not running");
14853 return -WM_FAIL;
14854 }
14855
14856 return wpa_supp_start_wps_pbc(netif, 1);
14857 }
14858
wlan_start_ap_wps_pin(const char * pin)14859 int wlan_start_ap_wps_pin(const char *pin)
14860 {
14861 struct netif *netif = net_get_uap_interface();
14862
14863 if (is_uap_started() == 0)
14864 {
14865 wlcm_e("Cannot Start WPS PIN as uAP is not running");
14866 return -WM_FAIL;
14867 }
14868
14869 if (wpa_supp_wps_pin_valid(netif, (const unsigned char *)pin) != WM_SUCCESS)
14870 {
14871 wlcm_d("WPS PIN validation failed for %s", pin);
14872 return -WM_FAIL;
14873 }
14874
14875 return wpa_supp_start_wps_pin(netif, pin, 1);
14876 }
14877
wlan_wps_ap_cancel(void)14878 int wlan_wps_ap_cancel(void)
14879 {
14880 struct netif *netif = net_get_uap_interface();
14881
14882 return wpa_supp_cancel_wps(netif, 1);
14883 }
14884 #endif
14885 #endif
14886 #endif
14887
14888 #if (CONFIG_WPA2_ENTP) || (CONFIG_WPA_SUPP_CRYPTO_ENTERPRISE)
14889 #if CONFIG_WIFI_USB_FILE_ACCESS
wlan_entp_cert_cleanup()14890 static void wlan_entp_cert_cleanup()
14891 {
14892 if (wlan.ca_cert_data != NULL)
14893 {
14894 OSA_MemoryFree(wlan.ca_cert_data);
14895 }
14896 if (wlan.client_cert_data != NULL)
14897 {
14898 OSA_MemoryFree(wlan.client_cert_data);
14899 }
14900 if (wlan.client_key_data != NULL)
14901 {
14902 OSA_MemoryFree(wlan.client_key_data);
14903 }
14904 if (wlan.ca_cert2_data != NULL)
14905 {
14906 OSA_MemoryFree(wlan.ca_cert2_data);
14907 }
14908 if (wlan.client_cert2_data != NULL)
14909 {
14910 OSA_MemoryFree(wlan.client_cert2_data);
14911 }
14912 if (wlan.client_key2_data != NULL)
14913 {
14914 OSA_MemoryFree(wlan.client_key2_data);
14915 }
14916
14917 #if CONFIG_WPA_SUPP_AP
14918 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
14919 if (wlan.dh_data != NULL)
14920 {
14921 OSA_MemoryFree(wlan.dh_data);
14922 }
14923 if (wlan.server_cert_data != NULL)
14924 {
14925 OSA_MemoryFree(wlan.server_cert_data);
14926 }
14927 if (wlan.server_key_data != NULL)
14928 {
14929 OSA_MemoryFree(wlan.server_key_data);
14930 }
14931 #endif
14932 #endif
14933 }
14934
wlan_set_entp_cert_files(int cert_type,t_u8 * data,t_u32 data_len)14935 int wlan_set_entp_cert_files(int cert_type, t_u8 *data, t_u32 data_len)
14936 {
14937 if (cert_type == FILE_TYPE_ENTP_CA_CERT)
14938 {
14939 wlan.ca_cert_data = OSA_MemoryAllocate(data_len);
14940 if (!wlan.ca_cert_data)
14941 {
14942 wlan_entp_cert_cleanup();
14943 wlcm_e("CA Cert malloc failed");
14944 return -WM_FAIL;
14945 }
14946 memcpy(wlan.ca_cert_data, data, data_len);
14947 wlan.ca_cert_len = data_len;
14948 }
14949 else if (cert_type == FILE_TYPE_ENTP_CLIENT_CERT)
14950 {
14951 wlan.client_cert_data = OSA_MemoryAllocate(data_len);
14952 if (!wlan.client_cert_data)
14953 {
14954 wlan_entp_cert_cleanup();
14955 wlcm_e("Client Cert malloc failed");
14956 return -WM_FAIL;
14957 }
14958 memcpy(wlan.client_cert_data, data, data_len);
14959 wlan.client_cert_len = data_len;
14960 }
14961 else if (cert_type == FILE_TYPE_ENTP_CLIENT_KEY)
14962 {
14963 wlan.client_key_data = OSA_MemoryAllocate(data_len);
14964 if (!wlan.client_key_data)
14965 {
14966 wlan_entp_cert_cleanup();
14967 wlcm_e("Client Key malloc failed");
14968 return -WM_FAIL;
14969 }
14970 memcpy(wlan.client_key_data, data, data_len);
14971 wlan.client_key_len = data_len;
14972 }
14973 else if (cert_type == FILE_TYPE_ENTP_CA_CERT2)
14974 {
14975 wlan.ca_cert2_data = OSA_MemoryAllocate(data_len);
14976 if (!wlan.ca_cert2_data)
14977 {
14978 wlan_entp_cert_cleanup();
14979 wlcm_e("CA Cert2 malloc failed");
14980 return -WM_FAIL;
14981 }
14982 memcpy(wlan.ca_cert2_data, data, data_len);
14983 wlan.ca_cert2_len = data_len;
14984 }
14985 else if (cert_type == FILE_TYPE_ENTP_CLIENT_CERT2)
14986 {
14987 wlan.client_cert2_data = OSA_MemoryAllocate(data_len);
14988 if (!wlan.client_cert2_data)
14989 {
14990 wlan_entp_cert_cleanup();
14991 wlcm_e("Client Cert2 malloc failed");
14992 return -WM_FAIL;
14993 }
14994 memcpy(wlan.client_cert2_data, data, data_len);
14995 wlan.client_cert2_len = data_len;
14996 }
14997 else if (cert_type == FILE_TYPE_ENTP_CLIENT_KEY2)
14998 {
14999 wlan.client_key2_data = OSA_MemoryAllocate(data_len);
15000 if (!wlan.client_key2_data)
15001 {
15002 wlan_entp_cert_cleanup();
15003 wlcm_e("Client Key2 malloc failed");
15004 return -WM_FAIL;
15005 }
15006 memcpy(wlan.client_key2_data, data, data_len);
15007 wlan.client_key2_len = data_len;
15008 }
15009 #if CONFIG_WPA_SUPP_AP
15010 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
15011 else if (cert_type == FILE_TYPE_ENTP_DH_PARAMS)
15012 {
15013 wlan.dh_data = OSA_MemoryAllocate(data_len);
15014 if (!wlan.dh_data)
15015 {
15016 wlan_entp_cert_cleanup();
15017 wlcm_e("DH params malloc failed");
15018 return -WM_FAIL;
15019 }
15020 memcpy(wlan.dh_data, data, data_len);
15021 wlan.dh_len = data_len;
15022 }
15023 #endif
15024 #endif
15025 #if CONFIG_WPA_SUPP_AP
15026 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
15027 else if (cert_type == FILE_TYPE_ENTP_SERVER_CERT)
15028 {
15029 wlan.server_cert_data = OSA_MemoryAllocate(data_len);
15030 if (!wlan.server_cert_data)
15031 {
15032 wlan_entp_cert_cleanup();
15033 wlcm_e("Server Cert malloc failed");
15034 return -WM_FAIL;
15035 }
15036 memcpy(wlan.server_cert_data, data, data_len);
15037 wlan.server_cert_len = data_len;
15038 }
15039 else if (cert_type == FILE_TYPE_ENTP_SERVER_KEY)
15040 {
15041 wlan.server_key_data = OSA_MemoryAllocate(data_len);
15042 if (!wlan.server_key_data)
15043 {
15044 wlan_entp_cert_cleanup();
15045 wlcm_e("Server Key malloc failed");
15046 return -WM_FAIL;
15047 }
15048 memcpy(wlan.server_key_data, data, data_len);
15049 wlan.server_key_len = data_len;
15050 }
15051 #endif
15052 #endif
15053 #if CONFIG_WPA_SUPP_AP
15054 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
15055 else if (cert_type == FILE_TYPE_ENTP_SERVER_CERT)
15056 {
15057 wlan.server_cert_data = OSA_MemoryAllocate(data_len);
15058 if (!wlan.server_cert_data)
15059 {
15060 wlan_entp_cert_cleanup();
15061 wlcm_e("Server Cert malloc failed");
15062 return -WM_FAIL;
15063 }
15064 memcpy(wlan.server_cert_data, data, data_len);
15065 wlan.server_cert_len = data_len;
15066 }
15067 else if (cert_type == FILE_TYPE_ENTP_SERVER_KEY)
15068 {
15069 wlan.server_key_data = OSA_MemoryAllocate(data_len);
15070 if (!wlan.server_key_data)
15071 {
15072 wlan_entp_cert_cleanup();
15073 wlcm_e("Server Key malloc failed");
15074 return -WM_FAIL;
15075 }
15076 memcpy(wlan.server_key_data, data, data_len);
15077 wlan.server_key_len = data_len;
15078 }
15079 else if (cert_type == FILE_TYPE_ENTP_DH_PARAMS)
15080 {
15081 wlan.dh_data = OSA_MemoryAllocate(data_len);
15082 if (!wlan.dh_data)
15083 {
15084 wlan_entp_cert_cleanup();
15085 wlcm_e("DH params malloc failed");
15086 return -WM_FAIL;
15087 }
15088 memcpy(wlan.dh_data, data, data_len);
15089 wlan.dh_len = data_len;
15090 }
15091 #endif
15092 #endif
15093 else
15094 {
15095 wlcm_e("Invalid file type");
15096 return -WM_FAIL;
15097 }
15098
15099 return WM_SUCCESS;
15100 }
15101 #endif
15102
wlan_get_entp_cert_files(int cert_type,t_u8 ** data)15103 t_u32 wlan_get_entp_cert_files(int cert_type, t_u8 **data)
15104 {
15105 int len = 0;
15106 if (cert_type == FILE_TYPE_ENTP_CA_CERT)
15107 {
15108 *data = wlan.ca_cert_data;
15109 len = wlan.ca_cert_len;
15110 #if !CONFIG_WIFI_USB_FILE_ACCESS
15111 if (!wlan.ca_cert_data)
15112 {
15113 *data = (t_u8 *)ca_der;
15114 len = ca_der_len;
15115 }
15116 #endif
15117 wlan.ca_cert_data = NULL;
15118 }
15119 else if (cert_type == FILE_TYPE_ENTP_CLIENT_CERT)
15120 {
15121 *data = wlan.client_cert_data;
15122 len = wlan.client_cert_len;
15123 #if !CONFIG_WIFI_USB_FILE_ACCESS
15124 if (!wlan.client_cert_data)
15125 {
15126 *data = (t_u8 *)client_der;
15127 len = client_der_len;
15128 }
15129 #endif
15130 wlan.client_cert_data = NULL;
15131 }
15132 else if (cert_type == FILE_TYPE_ENTP_CLIENT_KEY)
15133 {
15134 *data = wlan.client_key_data;
15135 len = wlan.client_key_len;
15136 #if !CONFIG_WIFI_USB_FILE_ACCESS
15137 if (!wlan.client_key_data)
15138 {
15139 *data = (t_u8 *)client_key_der;
15140 len = client_key_der_len;
15141 }
15142 #endif
15143 wlan.client_key_data = NULL;
15144 }
15145 if (cert_type == FILE_TYPE_ENTP_CA_CERT2)
15146 {
15147 *data = wlan.ca_cert2_data;
15148 len = wlan.ca_cert2_len;
15149 #if !CONFIG_WIFI_USB_FILE_ACCESS
15150 if (!wlan.ca_cert2_data)
15151 {
15152 *data = (t_u8 *)ca_der;
15153 len = ca_der_len;
15154 }
15155 #endif
15156 wlan.ca_cert2_data = NULL;
15157 }
15158 else if (cert_type == FILE_TYPE_ENTP_CLIENT_CERT2)
15159 {
15160 *data = wlan.client_cert2_data;
15161 len = wlan.client_cert2_len;
15162 #if !CONFIG_WIFI_USB_FILE_ACCESS
15163 if (!wlan.client_cert2_data)
15164 {
15165 *data = (t_u8 *)client_der;
15166 len = client_der_len;
15167 }
15168 #endif
15169 wlan.client_cert2_data = NULL;
15170 }
15171 else if (cert_type == FILE_TYPE_ENTP_CLIENT_KEY2)
15172 {
15173 *data = wlan.client_key2_data;
15174 len = wlan.client_key2_len;
15175 #if !CONFIG_WIFI_USB_FILE_ACCESS
15176 if (!wlan.client_key2_data)
15177 {
15178 *data = (t_u8 *)client_key_der;
15179 len = client_key_der_len;
15180 }
15181 #endif
15182 wlan.client_key2_data = NULL;
15183 }
15184 #if CONFIG_WPA_SUPP_AP
15185 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
15186 else if (cert_type == FILE_TYPE_ENTP_DH_PARAMS)
15187 {
15188 *data = wlan.dh_data;
15189 len = wlan.dh_len;
15190 #if !CONFIG_WIFI_USB_FILE_ACCESS
15191 if (!wlan.dh_data)
15192 {
15193 *data = (t_u8 *)dh_der;
15194 len = dh_der_len;
15195 }
15196 #endif
15197 wlan.dh_data = NULL;
15198 }
15199 #endif
15200 #endif
15201 #if CONFIG_WPA_SUPP_AP
15202 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
15203 else if (cert_type == FILE_TYPE_ENTP_SERVER_CERT)
15204 {
15205 *data = wlan.server_cert_data;
15206 len = wlan.server_cert_len;
15207 #if !CONFIG_WIFI_USB_FILE_ACCESS
15208 if (!wlan.server_cert_data)
15209 {
15210 *data = (t_u8 *)server_der;
15211 len = server_der_len;
15212 }
15213 #endif
15214 wlan.server_cert_data = NULL;
15215 }
15216 else if (cert_type == FILE_TYPE_ENTP_SERVER_KEY)
15217 {
15218 *data = wlan.server_key_data;
15219 len = wlan.server_key_len;
15220 #if !CONFIG_WIFI_USB_FILE_ACCESS
15221 if (!wlan.server_key_data)
15222 {
15223 *data = (t_u8 *)server_key_der;
15224 len = server_key_der_len;
15225 }
15226 #endif
15227 wlan.server_key_data = NULL;
15228 }
15229 #endif
15230 #endif
15231
15232 return len;
15233 }
15234
wlan_free_entp_cert_files(void)15235 void wlan_free_entp_cert_files(void)
15236 {
15237 #if CONFIG_WIFI_USB_FILE_ACCESS
15238 if (wlan.ca_cert_data != NULL)
15239 {
15240 wlan.ca_cert_data = NULL;
15241 wlan.ca_cert_len = 0;
15242 }
15243 if (wlan.client_cert_data != NULL)
15244 {
15245 wlan.client_cert_data = NULL;
15246 wlan.client_cert_len = 0;
15247 }
15248 if (wlan.client_key_data != NULL)
15249 {
15250 wlan.client_key_data = NULL;
15251 wlan.client_key_len = 0;
15252 }
15253 if (wlan.ca_cert2_data != NULL)
15254 {
15255 wlan.ca_cert2_data = NULL;
15256 wlan.ca_cert2_len = 0;
15257 }
15258 if (wlan.client_cert2_data != NULL)
15259 {
15260 wlan.client_cert2_data = NULL;
15261 wlan.client_cert2_len = 0;
15262 }
15263 if (wlan.client_key2_data != NULL)
15264 {
15265 wlan.client_key2_data = NULL;
15266 wlan.client_key2_len = 0;
15267 }
15268 #if CONFIG_WPA_SUPP_AP
15269 #if CONFIG_WPA_SUPP_CRYPTO_AP_ENTERPRISE
15270 if (wlan.dh_data != NULL)
15271 {
15272 wlan.dh_data = NULL;
15273 wlan.dh_len = 0;
15274 }
15275 if (wlan.server_cert_data != NULL)
15276 {
15277 wlan.server_cert_data = NULL;
15278 wlan.server_cert_len = 0;
15279 }
15280 if (wlan.server_key_data != NULL)
15281 {
15282 wlan.server_key_data = NULL;
15283 wlan.server_key_len = 0;
15284 }
15285 #endif
15286 #endif
15287 #endif
15288 }
15289 #endif
15290
15291 #if CONFIG_NET_MONITOR
wlan_register_monitor_user_callback(int (* monitor_data_recv_callback)(void * buffer,t_u16 data_len))15292 void wlan_register_monitor_user_callback(int (*monitor_data_recv_callback)(void *buffer, t_u16 data_len))
15293 {
15294 register_monitor_user_callback(monitor_data_recv_callback);
15295 }
15296
wlan_deregister_net_monitor_user_callback()15297 void wlan_deregister_net_monitor_user_callback()
15298 {
15299 deregister_monitor_user_callback();
15300 }
15301
wlan_net_monitor_cfg(wlan_net_monitor_t * monitor)15302 int wlan_net_monitor_cfg(wlan_net_monitor_t *monitor)
15303 {
15304 bool flag = false;
15305
15306 if (is_sta_connected() || is_uap_started())
15307 {
15308 (void)PRINTF("down the uap and disconnet sta first\n\r");
15309 return WM_FAIL;
15310 }
15311
15312 flag = (1 == monitor->monitor_activity) ? true : false;
15313 set_monitor_flag(flag);
15314 return wifi_net_monitor_cfg(monitor);
15315 }
15316 #endif
15317
15318 #if CONFIG_TSP
wlan_get_tsp_cfg(t_u16 * enable,t_u32 * back_off,t_u32 * highThreshold,t_u32 * lowThreshold,t_u32 * dutycycstep,t_u32 * dutycycmin,int * highthrtemp,int * lowthrtemp,int * currCAUTemp,int * currRFUTemp)15319 int wlan_get_tsp_cfg(t_u16 *enable,
15320 t_u32 *back_off,
15321 t_u32 *highThreshold,
15322 t_u32 *lowThreshold,
15323 t_u32 *dutycycstep,
15324 t_u32 *dutycycmin,
15325 int *highthrtemp,
15326 int *lowthrtemp,
15327 int *currCAUTemp,
15328 int *currRFUTemp)
15329 {
15330 t_u16 action = 0;
15331
15332 return wifi_tsp_cfg(action, enable, back_off, highThreshold, lowThreshold, dutycycstep, dutycycmin, highthrtemp, lowthrtemp, currCAUTemp, currRFUTemp);
15333 }
wlan_set_tsp_cfg(t_u16 enable,t_u32 back_off,t_u32 highThreshold,t_u32 lowThreshold,t_u32 dutycycstep,t_u32 dutycycmin,int highthrtemp,int lowthrtemp)15334 int wlan_set_tsp_cfg(t_u16 enable,
15335 t_u32 back_off,
15336 t_u32 highThreshold,
15337 t_u32 lowThreshold,
15338 t_u32 dutycycstep,
15339 t_u32 dutycycmin,
15340 int highthrtemp,
15341 int lowthrtemp)
15342 {
15343 t_u16 action = 1;
15344
15345 return wifi_tsp_cfg(action, &enable, &back_off, &highThreshold, &lowThreshold, &dutycycstep, &dutycycmin, &highthrtemp, &lowthrtemp, NULL, NULL);
15346 }
15347 #endif
15348
15349 #if STA_SUPPORT
wlan_get_signal_info(wlan_rssi_info_t * signal)15350 int wlan_get_signal_info(wlan_rssi_info_t *signal)
15351 {
15352 return wifi_send_rssi_info_cmd(signal);
15353 }
15354 #endif
15355
15356 #if CONFIG_TURBO_MODE
wlan_get_turbo_mode(t_u8 * mode)15357 int wlan_get_turbo_mode(t_u8 *mode)
15358 {
15359 return wifi_get_turbo_mode(mode);
15360 }
15361
wlan_get_uap_turbo_mode(t_u8 * mode)15362 int wlan_get_uap_turbo_mode(t_u8 *mode)
15363 {
15364 return wifi_get_uap_turbo_mode(mode);
15365 }
15366
wlan_set_turbo_mode(t_u8 mode)15367 int wlan_set_turbo_mode(t_u8 mode)
15368 {
15369 return wifi_set_turbo_mode(mode);
15370 }
15371
wlan_set_uap_turbo_mode(t_u8 mode)15372 int wlan_set_uap_turbo_mode(t_u8 mode)
15373 {
15374 return wifi_set_uap_turbo_mode(mode);
15375 }
15376 #endif
15377
wlan_set_ps_cfg(t_u16 multiple_dtims,t_u16 bcn_miss_timeout,t_u16 local_listen_interval,t_u16 adhoc_wake_period,t_u16 mode,t_u16 delay_to_ps)15378 void wlan_set_ps_cfg(t_u16 multiple_dtims,
15379 t_u16 bcn_miss_timeout,
15380 t_u16 local_listen_interval,
15381 t_u16 adhoc_wake_period,
15382 t_u16 mode,
15383 t_u16 delay_to_ps)
15384 {
15385 wifi_set_ps_cfg(multiple_dtims, bcn_miss_timeout, local_listen_interval, adhoc_wake_period, mode, delay_to_ps);
15386 }
15387
15388 #if (CONFIG_IPS)
wlan_set_ips(int option)15389 int wlan_set_ips(int option)
15390 {
15391 return wifi_set_ips_config(MLAN_BSS_TYPE_STA, option);
15392 }
15393 #endif
15394
wlan_set_country_code(const char * alpha2)15395 int wlan_set_country_code(const char *alpha2)
15396 {
15397 int ret;
15398 t_u8 region_code_rw610;
15399 unsigned char country3 = 0x20;
15400 char country_code[COUNTRY_CODE_LEN] = {0};
15401 #ifndef RW610
15402 char region_code[COUNTRY_CODE_LEN] = {0};
15403 const char *wlan_region_code = NULL;
15404
15405 wlan_region_code = wlan_get_wlan_region_code();
15406
15407 region_code[0] = alpha2[0];
15408 region_code[1] = alpha2[1];
15409
15410 if (strstr(wlan_region_code, region_code) == NULL)
15411 {
15412 wlcm_d("Region %s is configured, re-config not allowed", wlan_region_code);
15413 return -WM_FAIL;
15414 }
15415 #endif
15416
15417 if ((alpha2[2] == 0x4f) || (alpha2[2] == 0x49) || (alpha2[2] == 0x58) || (alpha2[2] == 0x04))
15418 {
15419 country3 = alpha2[2];
15420 }
15421
15422 country_code[0] = alpha2[0];
15423 country_code[1] = alpha2[1];
15424 country_code[2] = country3;
15425
15426 ret = wlan_11d_region_2_code(mlan_adap, (t_u8 *)country_code, ®ion_code_rw610);
15427 if(ret != WM_SUCCESS)
15428 {
15429 wlcm_e("%s: Invalid country code.",country_code);
15430 return ret;
15431 }
15432
15433 #if CONFIG_WPA_SUPP
15434 #if CONFIG_WPA_SUPP_AP
15435 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
15436 struct netif *netif = net_get_uap_interface();
15437
15438 ret = wpa_supp_set_ap_country(netif, alpha2, country3);
15439 if (ret != WM_SUCCESS)
15440 {
15441 return -WM_FAIL;
15442 }
15443 #endif
15444 #endif
15445 #endif
15446 ret = wifi_set_country_code(country_code);
15447 if (ret != WM_SUCCESS)
15448 return ret;
15449
15450 #if defined(RW610) && (CONFIG_COMPRESS_TX_PWTBL)
15451 return wlan_set_rg_power_cfg(region_code_rw610);
15452 #else
15453 return ret;
15454 #endif
15455 }
15456
wlan_set_country_ie_ignore(uint8_t * ignore)15457 int wlan_set_country_ie_ignore(uint8_t *ignore)
15458 {
15459 return wifi_set_country_ie_ignore(ignore);
15460 }
15461
wlan_set_region_code(unsigned int region_code)15462 int wlan_set_region_code(unsigned int region_code)
15463 {
15464 char *country;
15465
15466 if ((region_code == 0x40) || (region_code == 0x41) || (region_code == 0xFE))
15467 {
15468 (void)PRINTF("Region code 0XFF is used for Japan to support channels of both 2.4GHz band and 5GHz band.\r\n");
15469 return -WM_FAIL;
15470 }
15471
15472 country = (char *)wlan_11d_code_2_region(mlan_adap, (unsigned char)region_code);
15473 return wlan_set_country_code(country);
15474 }
15475
wlan_get_region_code(unsigned int * region_code)15476 int wlan_get_region_code(unsigned int *region_code)
15477 {
15478 return wifi_get_region_code(region_code);
15479 }
15480
wlan_set_11d_state(int bss_type,int state)15481 int wlan_set_11d_state(int bss_type, int state)
15482 {
15483 #if CONFIG_WPA_SUPP_AP
15484 struct netif *netif;
15485 #endif
15486 if (bss_type == WLAN_BSS_TYPE_UAP)
15487 {
15488 #if CONFIG_WPA_SUPP_AP
15489 netif = net_get_uap_interface();
15490 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
15491 wpa_supp_set_ap_11d_state(netif, state);
15492 #endif
15493 #endif
15494
15495 return wlan_enable_uap_11d(state);
15496 }
15497 else
15498 {
15499 return wlan_enable_11d(state);
15500 }
15501 }
15502
15503 #if CONFIG_COEX_DUTY_CYCLE
wlan_single_ant_duty_cycle(t_u16 enable,t_u16 nbTime,t_u16 wlanTime)15504 int wlan_single_ant_duty_cycle(t_u16 enable, t_u16 nbTime, t_u16 wlanTime)
15505 {
15506 return wifi_single_ant_duty_cycle(enable, nbTime, wlanTime);
15507 }
15508
wlan_dual_ant_duty_cycle(t_u16 enable,t_u16 nbTime,t_u16 wlanTime,t_u16 wlanBlockTime)15509 int wlan_dual_ant_duty_cycle(t_u16 enable, t_u16 nbTime, t_u16 wlanTime, t_u16 wlanBlockTime)
15510 {
15511 return wifi_dual_ant_duty_cycle(enable, nbTime, wlanTime, wlanBlockTime);
15512 }
15513 #endif
15514
15515 #if CONFIG_EXTERNAL_COEX_PTA
wlan_external_coex_pta_cfg(ext_coex_pta_cfg coex_pta_config)15516 int wlan_external_coex_pta_cfg(ext_coex_pta_cfg coex_pta_config)
15517 {
15518 return wifi_external_coex_pta_cfg(coex_pta_config);
15519 }
15520 #endif
15521
15522 #if CONFIG_IMD3_CFG
wlan_imd3_cfg(t_u8 imd3_value)15523 int wlan_imd3_cfg(t_u8 imd3_value)
15524 {
15525 return wifi_imd3_cfg(imd3_value);
15526 }
15527 #endif
15528
15529 #if CONFIG_WPA_SUPP
15530 #if CONFIG_UAP_STA_MAC_ADDR_FILTER
wlan_host_set_sta_mac_filter(int filter_mode,int mac_count,unsigned char * mac_addr)15531 int wlan_host_set_sta_mac_filter(int filter_mode, int mac_count, unsigned char *mac_addr)
15532 {
15533 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
15534 int ret = 0;
15535 struct netif *uap_netif = net_get_uap_interface();
15536 ret = wpa_supp_set_mac_acl(uap_netif, filter_mode, mac_count, mac_addr);
15537 if (ret < 0)
15538 return -WM_FAIL;
15539 else
15540 #endif
15541 return WM_SUCCESS;
15542 }
15543 #endif
15544 #endif
15545
15546 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
wlan_set_indrst_cfg(const wlan_indrst_cfg_t * indrst_cfg)15547 int wlan_set_indrst_cfg(const wlan_indrst_cfg_t *indrst_cfg)
15548 {
15549 wlan.ir_mode = indrst_cfg->ir_mode;
15550
15551 return wifi_set_indrst_cfg(indrst_cfg, (mlan_bss_type)WLAN_BSS_TYPE_STA);
15552 }
15553
wlan_get_indrst_cfg(wlan_indrst_cfg_t * indrst_cfg)15554 int wlan_get_indrst_cfg(wlan_indrst_cfg_t *indrst_cfg)
15555 {
15556 return wifi_get_indrst_cfg(indrst_cfg, (mlan_bss_type)WLAN_BSS_TYPE_STA);
15557 }
15558
wlan_trigger_oob_ind_reset()15559 static int wlan_trigger_oob_ind_reset()
15560 {
15561 (void)wlan_ieeeps_off();
15562
15563 OSA_TimeDelay(1000);
15564
15565 (void)wlan_deepsleepps_off();
15566
15567 OSA_TimeDelay(1000);
15568
15569 #ifdef IR_OUTBAND_TRIGGER_GPIO
15570 GPIO_PinWrite(IR_OUTBAND_TRIGGER_GPIO, IR_OUTBAND_TRIGGER_GPIO_PIN, 0);
15571
15572 OSA_TimeDelay(10);
15573
15574 GPIO_PinWrite(IR_OUTBAND_TRIGGER_GPIO, IR_OUTBAND_TRIGGER_GPIO_PIN, 1);
15575 #endif
15576
15577 return wifi_trigger_oob_indrst();
15578 }
15579
wlan_independent_reset()15580 int wlan_independent_reset()
15581 {
15582 if (wlan.ir_mode == 1)
15583 {
15584 return wlan_trigger_oob_ind_reset();
15585 }
15586 else if (wlan.ir_mode == 2)
15587 {
15588 return wifi_test_independent_reset();
15589 }
15590
15591 return -WM_FAIL;
15592 }
15593 #endif
15594
15595 #if CONFIG_INACTIVITY_TIMEOUT_EXT
wlan_sta_inactivityto(wlan_inactivity_to_t * inac_to,t_u16 action)15596 int wlan_sta_inactivityto(wlan_inactivity_to_t *inac_to, t_u16 action)
15597 {
15598 return wifi_sta_inactivityto(inac_to, action);
15599 }
15600 #endif
15601
15602 #if CONFIG_CPU_LOADING
15603
wlan_cpu_loading_record_data(void)15604 static void wlan_cpu_loading_record_data(void)
15605 {
15606 memset(cpu_loading.cpu_loading_info, 0, cpu_loading.task_status_len);
15607
15608 char run_task_name[configMAX_TASK_NAME_LEN];
15609 char cpu_run_data[20];
15610 unsigned int value;
15611 int task_name_index = 0, task_time_index = 0, index = 0, task_index = 0;
15612
15613 OSA_GetRuntimeStats(cpu_loading.cpu_loading_info);
15614
15615 uint32_t len_data = strlen(cpu_loading.cpu_loading_info);
15616 do
15617 {
15618 memset(run_task_name, 0, strlen(run_task_name));
15619 /*Record task name*/
15620 do
15621 {
15622 if(cpu_loading.cpu_loading_info[index] == ' ' && cpu_loading.cpu_loading_info[index + 1] == ' ') // Complete name parsing
15623 break;
15624 else
15625 run_task_name[task_name_index++] = cpu_loading.cpu_loading_info[index++];
15626 }while(index < len_data);
15627
15628 do //Filter out padding spaces between task names and run time values.
15629 {
15630 if(cpu_loading.cpu_loading_info[index++] == '\t')
15631 break;
15632 } while (index < len_data);
15633
15634 /*Record task run time*/
15635 do
15636 {
15637 if(cpu_loading.cpu_loading_info[index] < '0' || cpu_loading.cpu_loading_info[index] > '9')
15638 break;
15639 cpu_run_data[task_time_index++] = cpu_loading.cpu_loading_info[index++];
15640 }while(index < len_data);
15641
15642 cpu_run_data[task_time_index] = '\0';
15643 get_uint(cpu_run_data, &value, strlen(cpu_run_data));
15644
15645 if(cpu_loading.index > 0)
15646 {
15647 for(int i = 0; i < cpu_loading.task_nums; i++) // To collect CPU loading info according to fixed task name sequence.
15648 {
15649 if(!strcmp(cpu_loading.task_name[i], run_task_name))
15650 {
15651 cpu_loading.data_pre[i] = cpu_loading.data_cur[i];
15652 cpu_loading.data_cur[i] = value;
15653 break;
15654 }
15655 }
15656 }
15657 else
15658 {
15659 memset(task_string_name[task_index],' ', configMAX_TASK_NAME_LEN);
15660 task_string_name[task_index][configMAX_TASK_NAME_LEN -1] = '\0';
15661
15662 memcpy(cpu_loading.task_name[task_index], run_task_name, strlen(run_task_name));
15663 memcpy(task_string_name[task_index], run_task_name, strlen(run_task_name));
15664 cpu_loading.data_pre[task_index] = value;
15665 cpu_loading.data_cur[task_index] = value;
15666 cpu_loading.first_data[task_index] = value;
15667
15668 cpu_loading.task_name[task_index][strlen(run_task_name)] = '\0';
15669 }
15670
15671 /*Filter percentage value*/
15672 do
15673 {
15674 if(cpu_loading.cpu_loading_info[index] == '\r' && cpu_loading.cpu_loading_info[index + 1] == '\n')
15675 {
15676 index += 2;
15677 break;
15678 }
15679
15680 index++;
15681 }while((index < len_data));
15682
15683 task_time_index = 0;
15684 task_name_index = 0;
15685 task_index ++;
15686
15687 }while (index < len_data);
15688
15689 cpu_loading.index ++;
15690 cpu_loading.sampling_loops --;
15691 }
15692
cpu_loading_task(osa_task_param_t arg)15693 static void cpu_loading_task(osa_task_param_t arg)
15694 {
15695 for(;;)
15696 {
15697 /* Wait till cpu loading timer time out. */
15698 (void)os_event_notify_get(OS_WAIT_FOREVER);
15699
15700 if(cpu_loading.sampling_loops == 0)
15701 {
15702 wlan_cpu_loading_stop();
15703 }
15704 else
15705 {
15706 wlan_cpu_loading_record_data();
15707 if(cpu_loading.index > 1)
15708 wlan_cpu_loading_info_display();
15709 }
15710 }
15711
15712 OSA_ThreadSelfComplete(NULL);
15713 }
15714
cpu_loading_cb(osa_timer_arg_t arg)15715 static void cpu_loading_cb(osa_timer_arg_t arg)
15716 {
15717 (void)os_event_notify_put(cpu_loading.cpu_loading_thread);
15718 }
15719
wlan_cpu_loading_start(uint32_t number,uint8_t period)15720 static int wlan_cpu_loading_start(uint32_t number, uint8_t period)
15721 {
15722 int ret;
15723 osa_status_t status;
15724
15725 if(cpu_loading.status == CPU_LOADING_STATUS_DEAD)
15726 {
15727 memset(&cpu_loading, 0, sizeof(cpu_loading));
15728 if(period == 0)
15729 cpu_loading.sampling_period = CPU_LOADING_PERIOD;
15730 else
15731 cpu_loading.sampling_period = period * (CPU_LOADING_PERIOD / 2);
15732
15733 status = OSA_TimerCreate((osa_timer_handle_t)cpu_loading.cpu_loading_timer, MSEC_TO_TICK(cpu_loading.sampling_period),
15734 &cpu_loading_cb, NULL, KOSA_TimerPeriodic, OSA_TIMER_NO_ACTIVATE);
15735 if (status != KOSA_StatusSuccess)
15736 {
15737 (void)PRINTF("Unable to create cpu loading timer.\r\n");
15738 return -WM_FAIL;
15739 }
15740
15741 status = OSA_TaskCreate((osa_task_handle_t)cpu_loading.cpu_loading_task_Handle, OSA_TASK(cpu_loading_task), NULL);
15742 if (status != KOSA_StatusSuccess)
15743 {
15744 (void)PRINTF("Unable to create cpu loading thread.\r\n");
15745 return -WM_FAIL;
15746 }
15747
15748 os_get_num_of_tasks(&cpu_loading.task_nums);
15749 cpu_loading.task_status_len = cpu_loading.task_nums * sizeof(TaskStatus_t);
15750 cpu_loading.cpu_loading_info = (char *)OSA_MemoryAllocate(cpu_loading.task_status_len);
15751 if (cpu_loading.cpu_loading_info == NULL)
15752 {
15753 (void)PRINTF("%s: Failed to alloc cpu loading info\r\n", __func__);
15754 return -WM_FAIL;
15755 }
15756
15757 cpu_loading.index = 0;
15758 if(number != 0)
15759 cpu_loading.sampling_loops = number;
15760 else
15761 cpu_loading.sampling_loops = CPU_LOADING_KEEPING;
15762
15763 cpu_loading.status = CPU_LOADING_STATUS_ONGOING;
15764
15765 memset(cpu_loading.data_cur, 0, sizeof(cpu_loading.data_cur));
15766 memset(cpu_loading.data_pre, 0, sizeof(cpu_loading.data_pre));
15767 (void)OSA_TimerActivate((osa_timer_handle_t)cpu_loading.cpu_loading_timer);
15768 return WM_SUCCESS;
15769 }
15770 else
15771 {
15772 wlcm_e("Unable to start cpu loading timer, pls stop the previous cpu loading test firstly.");
15773 return -WM_FAIL;
15774 }
15775 }
15776
wlan_cpu_loading(uint8_t start,uint32_t number,uint8_t period)15777 int wlan_cpu_loading(uint8_t start, uint32_t number, uint8_t period)
15778 {
15779 int ret;
15780 if(start == CPU_LOADING_ACTION_STOP)
15781 {
15782 if(cpu_loading.status == CPU_LOADING_STATUS_DEAD)
15783 {
15784 (void)PRINTF("Collecting CPU loading info has already ended.\r\n");
15785 return WM_SUCCESS;
15786 }
15787 else
15788 {
15789 cpu_loading.sampling_loops = 0;
15790 OSA_TimerChange((osa_timer_handle_t)cpu_loading.cpu_loading_timer, 100, 0); // Chages value of cpu loading timer to stop cpu loading test quickly.
15791 if(cpu_loading.status != CPU_LOADING_STATUS_DEAD)
15792 {
15793 OSA_TimeDelay(50);
15794 }
15795 return WM_SUCCESS;
15796 }
15797 }
15798 else
15799 {
15800 return wlan_cpu_loading_start(number, period);
15801 }
15802 }
15803
15804 #endif
15805
15806 #if CONFIG_AUTO_NULL_TX
wlan_auto_null_tx(wlan_auto_null_tx_t * auto_null_tx,mlan_bss_type bss_type)15807 int wlan_auto_null_tx(wlan_auto_null_tx_t *auto_null_tx, mlan_bss_type bss_type)
15808 {
15809 if (auto_null_tx == NULL)
15810 {
15811 return -WM_E_INVAL;
15812 }
15813
15814 return wifi_auto_null_tx(auto_null_tx, bss_type);
15815 }
15816 #endif
15817
15818 #ifdef RW610
wlan_get_temperature()15819 int32_t wlan_get_temperature()
15820 {
15821 return wifi_get_temperature();
15822 }
15823 #endif
15824
wlan_string_dup(const char * s)15825 char *wlan_string_dup(const char *s)
15826 {
15827 char *snew = (char *)OSA_MemoryAllocate(strlen(s) + 1);
15828 if (snew)
15829 (void)strcpy(snew, s);
15830 return snew;
15831 }
15832
wlan_get_board_type()15833 uint32_t wlan_get_board_type()
15834 {
15835 uint32_t board_type = 0xff;
15836
15837 #ifdef RW610
15838 board_type = wifi_get_board_type();
15839 #endif
15840
15841 return board_type;
15842 }
15843
15844 #if UAP_SUPPORT
wlan_uap_disconnect_sta(uint8_t * sta_addr)15845 int wlan_uap_disconnect_sta(uint8_t *sta_addr)
15846 {
15847 int ret = WM_SUCCESS;
15848 #if !CONFIG_WPA_SUPP
15849 t_u16 reason_code = WLAN_REASON_CODE_PREV_AUTH_NOT_VALID;
15850 #endif
15851 #if CONFIG_WPA_SUPP
15852 #if !CONFIG_WIFI_NM_WPA_SUPPLICANT
15853 struct netif *netif = net_get_uap_interface();
15854 ret = wpa_supp_deauth_sta(netif, sta_addr);
15855 #endif
15856 #else
15857 ret = wifi_sta_deauth(sta_addr, reason_code);
15858 #endif
15859
15860 if(ret != WM_SUCCESS)
15861 {
15862 (void)PRINTF("Error: Failed to disconnect sta.\r\n");
15863 }
15864
15865 return ret;
15866 }
15867
wlan_uap_set_sta_ageout_timer(uint32_t sta_ageout_time)15868 int wlan_uap_set_sta_ageout_timer(uint32_t sta_ageout_time)
15869 {
15870 int ret = WM_SUCCESS;
15871
15872 if (is_uap_started() != 0)
15873 {
15874 wlcm_e(
15875 "Cannot set the max inactivity duration for stations "
15876 "as the uAP is already running");
15877 return -WM_FAIL;
15878 }
15879
15880 ret = wifi_uap_sta_ageout_timer_getset(ACTION_SET, (uint32_t *)&sta_ageout_time);
15881 if (ret != WM_SUCCESS)
15882 {
15883 wlcm_e("Failed to set STA ageout timer");
15884 return ret;
15885 }
15886
15887 ret = wifi_uap_ps_sta_ageout_timer_getset(ACTION_SET, (uint32_t *)&sta_ageout_time);
15888 if (ret != WM_SUCCESS)
15889 {
15890 wlcm_e("Failed to set PS STA ageout timer");
15891 return ret;
15892 }
15893
15894 return ret;
15895 }
15896 #endif
15897
15898 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
wlan_supp_dpp_listen(int bss_type,int enable)15899 int wlan_supp_dpp_listen(int bss_type, int enable)
15900 {
15901 if (bss_type == WLAN_BSS_ROLE_STA)
15902 {
15903 if (enable)
15904 {
15905 wifi_set_rx_mgmt_indication(bss_type, WLAN_MGMT_ACTION);
15906 wlan_ieeeps_off();
15907 wlan_deepsleepps_off();
15908 }
15909 else
15910 {
15911 wlan_ieeeps_on(wlan.wakeup_conditions);
15912 wlan_deepsleepps_on();
15913 }
15914 }
15915 return 0;
15916 }
15917 #endif
15918