1 /** @file mlan_glue.c
2  *
3  *  @brief This file acts as a glue between legacy wlan code and mlan based wlan
4  *  code
5  *
6  *  Copyright 2008-2024 NXP
7  *
8  *  SPDX-License-Identifier: BSD-3-Clause
9  *
10  */
11 #include <mlan_api.h>
12 
13 /* Additional WMSDK header files */
14 #include <wmerrno.h>
15 #include <osa.h>
16 #include <wifi_events.h>
17 #include <wifi-debug.h>
18 
19 #include <wifi.h>
20 #include "wifi-internal.h"
21 #if defined(RW610)
22 #include "wifi-imu.h"
23 #include "fsl_ocotp.h"
24 #else
25 #include "wifi-sdio.h"
26 #endif
27 
28 #if CONFIG_WPA_SUPP
29 #include "wifi_nxp.h"
30 #endif
31 
32 /* Always keep this include at the end of all include files */
33 #include <mlan_remap_mem_operations.h>
34 
35 #if CONFIG_WIFI_FW_DEBUG
36 #define FW_DEBUG_INFO_SIZE 400
37 #endif
38 #define RUTXCMD_RESP_BUFF_SIZE 1024
39 
40 static const uint8_t wpa2_akmp_oui[4] = {0x00, 0x0f, 0xac, 0x01};
41 #ifdef WLAN_LOW_POWER_ENABLE
42 bool low_power_mode;
43 #endif
44 bool cal_data_valid = 0;
45 static uint8_t *cal_data;
46 static uint32_t cal_data_len;
47 
48 bool mac_addr_valid;
49 static uint8_t *mac_addr;
50 #if CONFIG_WIFI_TX_BUFF
51 #if CONFIG_AMSDU_IN_AMPDU
52 uint16_t tx_buf_size = MLAN_TX_DATA_BUF_SIZE_4K;
53 #else
54 uint16_t tx_buf_size = MLAN_TX_DATA_BUF_SIZE_2K;
55 #endif
56 #endif
57 #ifdef RW610
58 extern t_u32 last_resp_rcvd;
59 #endif
60 
61 extern uint8_t dev_mac_addr[MLAN_MAC_ADDR_LENGTH];
62 extern uint8_t dev_mac_addr_uap[MLAN_MAC_ADDR_LENGTH];
63 
64 #if (CONFIG_11MC) || (CONFIG_11AZ)
65 extern ftm_start_param ftm_param;
66 static char ftm_address[255] = CIVIC_ADDRESS;
67 #if CONFIG_WLS_CSI_PROC
68 extern uint8_t wls_data[WLS_CSI_DATA_LEN];
69 #endif
70 #endif
71 
72 #if CONFIG_WPA2_ENTP
73 bool scan_enable_wpa2_enterprise_ap_only;
74 #endif
75 
76 #if CONFIG_11K
77 typedef MLAN_PACK_START struct _Event_Gen_t
78 {
79     /** Event ID */
80     uint16_t event_id;
81     /** BSS index number for multiple BSS support */
82     uint8_t bss_index;
83     /** BSS type */
84     uint8_t bss_type;
85     /** No of bytes in packet including this field */
86     uint16_t length;
87     /** tlv */
88     uint8_t tlv[1];
89 } MLAN_PACK_END Event_Gen_t;
90 #endif
91 
92 /*
93  *  fixme: This entry is not present in mlan_fw.h. It is likely possible
94  *  that this code is no-op in the firmware. Keeping it as it is for
95  *  maintaining backward compatibility. Can be removed later.
96  */
97 #define host_CMD_802_11_AUTHENTICATE 0x0011
98 
99 /* Following is allocated in mlan_register */
100 mlan_adapter *mlan_adap;
101 
102 static mlan_device mlan_dev;
103 
104 uint8_t g_rssi;
105 int16_t g_bcn_nf_last;
106 
107 /* fixme: This global variable is needed
108  *  to save the correct event since SLP_CFRM command
109  *  returns incorrect bitmap. This will be  further investigated
110  *  and if possile global variable will be removed.*/
111 static t_u16 ps_event;
112 
113 #if CONFIG_NET_MONITOR
114 /* record status */
115 bool g_monitor_status = false;
116 
117 /* monitor recv data user callback */
118 int (*net_monitor_callback)(void *buffer, t_u16 data_len) = NULL;
119 #endif
120 
121 int mlan_subsys_init(void);
122 int mlan_subsys_deinit(void);
123 
124 void wifi_get_mac_address_from_cmdresp(const HostCmd_DS_COMMAND *resp, uint8_t *get_mac_addr);
125 void wifi_get_value1_from_cmdresp(const HostCmd_DS_COMMAND *resp, uint32_t *dev_value1);
126 void wifi_get_firmware_ver_ext_from_cmdresp(const HostCmd_DS_COMMAND *resp, uint8_t *fw_ver_ext);
127 int wifi_set_tx_power_ext(uint32_t len, uint32_t *power_data);
128 int wifi_send_bss_ioctl(mlan_ds_bss *bss);
129 
130 void wifi_prepare_get_fw_ver_ext_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number, int version_str_sel);
131 void wifi_prepare_get_value1(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
132 void wifi_prepare_enable_amsdu_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
133 void wifi_prepare_get_mac_addr_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
134 void wifi_prepare_get_hw_spec_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
135 void wifi_prepare_set_mac_addr_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
136 void wifi_prepare_set_cal_data_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
137 void wifi_prepare_reconfigure_tx_buf_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
138 void wlan_prepare_mac_control_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
139 
140 #ifdef OTP_CHANINFO
141 void wifi_prepare_get_channel_region_cfg_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number);
142 #endif
143 
144 void wrapper_wlan_cmd_11n_cfg(HostCmd_DS_COMMAND *cmd);
145 void wrapper_deliver_amsdu_subframe(pmlan_buffer amsdu_pmbuf, t_u8 *data, t_u16 pkt_len);
146 int wrapper_wlan_set_regiontable(t_u8 region, t_u16 band);
147 int wrapper_wlan_handle_rx_packet(t_u16 datalen, RxPD *rxpd, void *p, void *payload);
148 int wrapper_get_wpa_ie_in_assoc(uint8_t *wpa_ie);
149 
150 int wrapper_wlan_handle_amsdu_rx_packet(const t_u8 *rcvdata, const t_u16 datalen);
151 
152 void wlan_process_hang(uint8_t fw_reload);
153 
154 #if CONFIG_11N
155 /*
156  * The command event received from the firmware (e.g. EVENT_ADDBA) cannot
157  * be processed immediately. We need to do it the WLC manager context. For
158  * that we will save the buffer lest some other event destroy it. WLC
159  * manager will be notified of this event.
160  *
161  * Returns NULL if buffer allocation failed.
162  */
wifi_11n_save_request(Event_Ext_t * evt)163 static void *wifi_11n_save_request(Event_Ext_t *evt)
164 {
165 #if !CONFIG_MEM_POOLS
166     void *dot11n_eventbuf = OSA_MemoryAllocate(evt->length);
167 #else
168     void *dot11n_eventbuf                     = OSA_MemoryPoolAllocate(buf_256_MemoryPool);
169 #endif
170 
171     if (dot11n_eventbuf == MNULL)
172     {
173         wifi_w("11n eventbuf alloc failed %d", evt->length);
174         return NULL;
175     }
176 
177     (void)memcpy((void *)dot11n_eventbuf, (const void *)evt, evt->length);
178     return dot11n_eventbuf;
179 }
180 #endif /* CONFIG_11N */
181 
182 #if CONFIG_11K_OFFLOAD
183 /** Event body : 11K NLIST */
184 typedef PACK_START struct _nlist_entry_tlv
185 {
186     /** Header */
187     MrvlIEtypesHeader_t header;
188     t_u8 bssid[6];
189     t_u8 bssid_info[4];
190     t_u8 reg_class;
191     t_u8 chan;
192     t_u8 phy_type;
193 } PACK_END nlist_entry_tlv;
194 
wifi_find_in_channels(t_u8 * channels,t_u8 entry_num,t_u8 chan)195 static bool wifi_find_in_channels(t_u8 *channels, t_u8 entry_num, t_u8 chan)
196 {
197     t_u8 i;
198     for (i = 0; i < entry_num; i++)
199     {
200         if (channels[i] == chan)
201         {
202             return true;
203         }
204     }
205     return false;
206 }
207 
wifi_11k_save_request(Event_Gen_t * evt)208 static void *wifi_11k_save_request(Event_Gen_t *evt)
209 {
210     int tlv_buf_left = 0;
211     size_t buf_used  = 0;
212     MrvlIEtypesHeader_t *tlv;
213     nlist_entry_tlv *nlist = MNULL;
214     t_u8 entry_num         = 0;
215     t_u16 tlv_type, tlv_len;
216     t_u8 *buffer = (t_u8 *)evt + sizeof(Event_Gen_t) - 1;
217 #if !CONFIG_MEM_POOLS
218     wlan_nlist_report_param *pnlist_rep_param =
219         (wlan_nlist_report_param *)OSA_MemoryAllocate(sizeof(wlan_nlist_report_param));
220 #else
221     wlan_nlist_report_param *pnlist_rep_param = (wlan_nlist_report_param *)OSA_MemoryPoolAllocate(buf_128_MemoryPool);
222 #endif
223 
224     wifi_d("Neighbor report event");
225 #if CONFIG_WIFI_EXTRA_DEBUG
226     dump_hex(evt, evt->length + sizeof(Event_Gen_t));
227 #endif
228     if (pnlist_rep_param == MNULL)
229     {
230         wifi_e("11k nlist report param buffer alloc failed %d", sizeof(wlan_nlist_report_param));
231         return MNULL;
232     }
233 
234     (void)memset(pnlist_rep_param, 0, sizeof(wlan_nlist_report_param));
235     tlv_buf_left = (int)evt->length;
236     tlv_buf_left = wlan_le16_to_cpu(tlv_buf_left);
237     if (tlv_buf_left < (int)sizeof(MrvlIEtypesHeader_t))
238     {
239 #if !CONFIG_MEM_POOLS
240         OSA_MemoryFree((void *)pnlist_rep_param);
241 #else
242         OSA_MemoryPoolFree(buf_128_MemoryPool, pnlist_rep_param);
243 #endif
244         return MNULL;
245     }
246     wifi_d("neighbor AP list tlv len: %d", tlv_buf_left);
247     tlv = (MrvlIEtypesHeader_t *)(void *)buffer;
248     while (tlv_buf_left >= (int)sizeof(MrvlIEtypesHeader_t))
249     {
250         tlv_type = wlan_le16_to_cpu(tlv->type);
251         tlv_len  = wlan_le16_to_cpu(tlv->len);
252         if ((sizeof(MrvlIEtypesHeader_t) + tlv_len) > (unsigned int)tlv_buf_left)
253         {
254             wifi_d("wrong tlv: tlvLen=%d, tlvBufLeft=%d", tlv_len, tlv_buf_left);
255             break;
256         }
257         switch (tlv_type)
258         {
259             case MRVL_NEIGHBOR_REPORT_TLV_ID:
260                 nlist = (nlist_entry_tlv *)(void *)tlv;
261                 wifi_d("Neighbor entry %d:", entry_num);
262                 wifi_d("BSSID: %02x:%02x:%02x:%02x:%02x:%02x ", nlist->bssid[0], nlist->bssid[1], nlist->bssid[2],
263                        nlist->bssid[3], nlist->bssid[4], nlist->bssid[5]);
264                 wifi_d("BSSID Info: %02x:%02x:%02x:%02x ", nlist->bssid_info[0], nlist->bssid_info[1],
265                        nlist->bssid_info[2], nlist->bssid_info[3]);
266                 wifi_d("reg class: %d, chan: %d, phy: %d ", nlist->reg_class, nlist->chan, nlist->phy_type);
267                 if (tlv_len > (sizeof(nlist_entry_tlv) - sizeof(MrvlIEtypesHeader_t)))
268                 {
269                     wifi_d("sub IE:");
270 #if CONFIG_WIFI_EXTRA_DEBUG
271                     dump_hex((t_u8 *)tlv + sizeof(nlist_entry_tlv),
272                              tlv_len - sizeof(nlist_entry_tlv) + sizeof(MrvlIEtypesHeader_t));
273 #endif
274                 }
275                 wifi_d("channel = %d", nlist->chan);
276                 if (!wifi_find_in_channels(pnlist_rep_param->channels, entry_num, nlist->chan))
277                 {
278                     pnlist_rep_param->channels[entry_num] = nlist->chan;
279                     entry_num++;
280                 }
281                 break;
282             default:
283                 wifi_d("unknown tlv: %d", tlv_type);
284                 break;
285         }
286         buf_used = sizeof(MrvlIEtypesHeader_t) + (size_t)tlv_len;
287         tlv_buf_left -= (int)(buf_used);
288         tlv = (MrvlIEtypesHeader_t *)(void *)((t_u8 *)tlv + tlv_len + sizeof(MrvlIEtypesHeader_t));
289     }
290 
291     if (entry_num > (t_u8)0U)
292     {
293         pnlist_rep_param->nlist_mode   = WLAN_NLIST_11K;
294         pnlist_rep_param->num_channels = entry_num;
295         return pnlist_rep_param;
296     }
297     else
298     {
299 #if !CONFIG_MEM_POOLS
300         OSA_MemoryFree((void *)pnlist_rep_param);
301 #else
302         OSA_MemoryPoolFree(buf_128_MemoryPool, pnlist_rep_param);
303 #endif
304         return MNULL;
305     }
306 }
307 #endif /* CONFIG_11K_OFFLOAD */
308 
wrapper_deliver_amsdu_subframe(pmlan_buffer amsdu_pmbuf,t_u8 * data,t_u16 pkt_len)309 void wrapper_deliver_amsdu_subframe(pmlan_buffer amsdu_pmbuf, t_u8 *data, t_u16 pkt_len)
310 {
311     RxPD *prx_pd = (RxPD *)(void *)amsdu_pmbuf->pbuf;
312     w_pkt_d("[amsdu] [push]: BSS Type: %d L: %d", prx_pd->bss_type, pkt_len);
313     wm_wifi.amsdu_data_input_callback(prx_pd->bss_type, data, pkt_len);
314 }
315 
wrapper_moal_recv_packet(IN t_void * pmoal_handle,IN pmlan_buffer pmbuf)316 static mlan_status wrapper_moal_recv_packet(IN t_void *pmoal_handle, IN pmlan_buffer pmbuf)
317 {
318     RxPD *prx_pd = (RxPD *)(void *)(pmbuf->pbuf + pmbuf->data_offset);
319     if (pmbuf->data_offset != 0U)
320     {
321         wifi_e("pmbuf->data_offset != 0 (%d)?", pmbuf->data_offset);
322         while (true)
323         {
324             ;
325         }
326     }
327 
328     w_pkt_d("[push] %p + %d:  DELV: %p L: %d", pmbuf->pbuf, pmbuf->data_offset, pmbuf->lwip_pbuf, pmbuf->data_len);
329 
330     wm_wifi.deliver_packet_above_callback((void *)prx_pd, prx_pd->bss_type, pmbuf->lwip_pbuf);
331 
332 #if !(CONFIG_TX_RX_ZERO_COPY) && !(FSL_USDHC_ENABLE_SCATTER_GATHER_TRANSFER)
333     /* Free RxPD */
334 #if !CONFIG_MEM_POOLS
335     OSA_MemoryFree(pmbuf->pbuf);
336     OSA_MemoryFree(pmbuf);
337 #else
338     OSA_MemoryPoolFree(buf_128_MemoryPool, pmbuf->pbuf);
339     OSA_MemoryPoolFree(buf_128_MemoryPool, pmbuf);
340 #endif
341 
342 #endif
343     return MLAN_STATUS_SUCCESS;
344 }
345 
346 /**
347  *  @brief Copy memory from one area to another
348  *
349  *  @param pmoal Pointer to the MOAL context
350  *  @param pdest    Pointer to the dest memory
351  *  @param psrc     Pointer to the src memory
352  *  @param num      Number of bytes to move
353  *  @param dest_size size of dest memory.
354  *
355  *  @return         Pointer to the dest memory
356  */
wrapper_moal_memcpy_ext(t_void * pmoal,t_void * pdest,const t_void * psrc,t_u32 num,t_u32 dest_size)357 t_void *wrapper_moal_memcpy_ext(t_void *pmoal, t_void *pdest, const t_void *psrc, t_u32 num, t_u32 dest_size)
358 {
359     t_void *p = pdest;
360     if (pdest && psrc && num && dest_size)
361         p = memcpy(pdest, psrc, MIN(num, dest_size));
362 
363     return p;
364 }
365 
366 /** moal_init_timer*/
wrapper_moal_init_timer(IN t_void * pmoal_handle,OUT t_void * ptimer,IN t_void (* callback)(osa_timer_arg_t arg),IN t_void * pcontext)367 static mlan_status wrapper_moal_init_timer(IN t_void *pmoal_handle,
368                                            OUT t_void *ptimer,
369                                            IN t_void (*callback)(osa_timer_arg_t arg),
370                                            IN t_void *pcontext)
371 {
372     w_tmr_d("Creating timer");
373 
374     /*
375      * As can be seen from the arguments to our function, we do not
376      * have a timer period parameter. Nor do we have a parameter to
377      * specify whether the user wants a periodic or a one-shot
378      * timer. We have to wait for these paramters till the next call to
379      * wrapper_moal_start_timer.
380      *
381      * But a timer object cannot be created in
382      * wrapper_moal_start_timer. Because the timer handle is passed by
383      * value.
384      *
385      * Considering all this we will need to create the timer object in the
386      * current function. We will provide a dummy time here one and
387      * change in later. One assumption from the current observation is
388      * that only one shot timers are created. So we will assume this
389      * and raise assert in *timer_start if this is not the case.
390      */
391 #define DUMMY_TIME_PARAM 10
392 
393     osa_status_t status = OSA_TimerCreate((osa_timer_handle_t)ptimer, MSEC_TO_TICK(DUMMY_TIME_PARAM), callback, pcontext,
394                                           KOSA_TimerOnce, OSA_TIMER_NO_ACTIVATE);
395     if (status != KOSA_StatusSuccess)
396     {
397         w_tmr_e("Unable to create timer");
398         return MLAN_STATUS_FAILURE;
399     }
400 
401     return MLAN_STATUS_SUCCESS;
402 }
403 
404 /** moal_start_timer*/
wrapper_moal_start_timer(IN t_void * pmoal_handle,IN t_void * ptimer,IN bool periodic,IN t_u32 msec)405 static mlan_status wrapper_moal_start_timer(IN t_void *pmoal_handle, IN t_void *ptimer, IN bool periodic, IN t_u32 msec)
406 {
407     w_tmr_d("Starting timer: %p for %d mS", ptimer, msec);
408 
409     if (periodic == MTRUE)
410     {
411         /* Check note in wrapper_moal_init_timer for details */
412         w_tmr_w("Periodic is not supported temporarily");
413         while (true)
414         {
415             ;
416         }
417         // wmpanic();
418     }
419 
420     osa_status_t status = OSA_TimerChange((osa_timer_handle_t)ptimer, msec, 0);
421     if (status != KOSA_StatusSuccess)
422     {
423         w_tmr_e("Unable to change period in timer");
424         return MLAN_STATUS_FAILURE;
425     }
426 
427     status = OSA_TimerActivate((osa_timer_handle_t)ptimer);
428     if (status != KOSA_StatusSuccess)
429     {
430         w_tmr_e("Unable to start timer");
431         return MLAN_STATUS_FAILURE;
432     }
433 
434     return MLAN_STATUS_SUCCESS;
435 }
436 
437 /** moal_reset_timer*/
wrapper_moal_reset_timer(IN t_void * pmoal_handle,IN t_void * ptimer)438 static mlan_status wrapper_moal_reset_timer(IN t_void *pmoal_handle, IN t_void *ptimer)
439 {
440     w_tmr_d("Resetting timer: %p", ptimer);
441 
442     int rv = OSA_TimerReset((osa_timer_handle_t)ptimer);
443     if (rv != WM_SUCCESS)
444     {
445         w_tmr_e("Unable to reset timer.");
446         return MLAN_STATUS_FAILURE;
447     }
448 
449     return MLAN_STATUS_SUCCESS;
450 }
451 
452 /** moal_stop_timer*/
wrapper_moal_stop_timer(IN t_void * pmoal_handle,IN t_void * ptimer)453 static mlan_status wrapper_moal_stop_timer(IN t_void *pmoal_handle, IN t_void *ptimer)
454 {
455     w_tmr_d("Stopping timer: %p", ptimer);
456 
457     int rv = OSA_TimerDeactivate((osa_timer_handle_t)ptimer);
458     if (rv != WM_SUCCESS)
459     {
460         w_tmr_e("Unable to stop timer.");
461         return MLAN_STATUS_FAILURE;
462     }
463 
464     return MLAN_STATUS_SUCCESS;
465 }
466 
467 /** moal_free_timer */
wrapper_moal_free_timer(IN t_void * pmoal_handle,IN t_void * ptimer)468 static mlan_status wrapper_moal_free_timer(IN t_void *pmoal_handle, IN t_void *ptimer)
469 {
470     w_tmr_d("Deleting timer: %p", *((uint32_t *)ptimer));
471 
472     int rv = OSA_TimerDestroy((osa_timer_handle_t)ptimer);
473     if (rv != WM_SUCCESS)
474     {
475         w_tmr_e("Unable to delete timer.");
476         return MLAN_STATUS_FAILURE;
477     }
478 
479     return MLAN_STATUS_SUCCESS;
480 }
481 
wrapper_moal_init_lock(IN t_void * pmoal_handle,OUT t_void * plock)482 static mlan_status wrapper_moal_init_lock(IN t_void *pmoal_handle, OUT t_void *plock)
483 {
484 #ifdef DEBUG_DEVELOPMENT
485     wmprintf("%s: Locks not needed for now\n\r", __func__);
486 #endif /* DEBUG_DEVELOPMENT */
487     return MLAN_STATUS_SUCCESS;
488 }
489 
490 /** moal_free_lock */
wrapper_moal_free_lock(IN t_void * pmoal_handle,IN t_void * plock)491 static mlan_status wrapper_moal_free_lock(IN t_void *pmoal_handle, IN t_void *plock)
492 {
493 #ifdef DEBUG_DEVELOPMENT
494     wmprintf("%s: Locks not needed for now\n\r", __func__);
495 #endif /* DEBUG_DEVELOPMENT */
496     return MLAN_STATUS_SUCCESS;
497 }
498 
499 /** moal_spin_lock */
wrapper_moal_spin_lock(IN t_void * pmoal_handle,IN t_void * plock)500 static mlan_status wrapper_moal_spin_lock(IN t_void *pmoal_handle, IN t_void *plock)
501 {
502 #ifdef DEBUG_DEVELOPMENT
503     wmprintf("%s: Locks not needed for now\n\r", __func__);
504 #endif /* DEBUG_DEVELOPMENT */
505     return MLAN_STATUS_SUCCESS;
506 }
507 
508 /** moal_spin_unlock */
wrapper_moal_spin_unlock(IN t_void * pmoal_handle,IN t_void * plock)509 static mlan_status wrapper_moal_spin_unlock(IN t_void *pmoal_handle, IN t_void *plock)
510 {
511 #ifdef DEBUG_DEVELOPMENT
512     wmprintf("%s: Locks not needed for now\n\r", __func__);
513 #endif /* DEBUG_DEVELOPMENT */
514     return MLAN_STATUS_SUCCESS;
515 }
516 
517 #if CONFIG_WMM
518 /* os_semaphore_t equals (t_void *)(*pplock) */
wrapper_moal_init_semaphore(IN t_void * pmoal_handle,IN const char * name,OUT t_void * plock)519 static mlan_status wrapper_moal_init_semaphore(IN t_void *pmoal_handle, IN const char *name, OUT t_void *plock)
520 {
521     //    if (*((os_semaphore_t *)pplock) != MNULL)
522     //        return MLAN_STATUS_SUCCESS;
523 
524     if (OSA_SemaphoreCreateBinary((osa_semaphore_handle_t)plock) != KOSA_StatusSuccess)
525         return MLAN_STATUS_FAILURE;
526 
527     OSA_SemaphorePost((osa_semaphore_handle_t)plock);
528     return MLAN_STATUS_SUCCESS;
529 }
530 
wrapper_moal_free_semaphore(IN t_void * pmoal_handle,IN t_void * plock)531 static mlan_status wrapper_moal_free_semaphore(IN t_void *pmoal_handle, IN t_void *plock)
532 {
533     //    if (*((os_semaphore_t *)pplock) == MNULL)
534     //        return MLAN_STATUS_SUCCESS;
535 
536     if (OSA_SemaphoreDestroy((osa_semaphore_handle_t)plock) != KOSA_StatusSuccess)
537         return MLAN_STATUS_FAILURE;
538 
539     return MLAN_STATUS_SUCCESS;
540 }
541 
wrapper_moal_semaphore_get(IN t_void * pmoal_handle,IN t_void * plock)542 static mlan_status wrapper_moal_semaphore_get(IN t_void *pmoal_handle, IN t_void *plock)
543 {
544     if (OSA_SemaphoreWait((osa_semaphore_handle_t)plock, 60000) != KOSA_StatusSuccess)
545     {
546         assert(0);
547         return MLAN_STATUS_FAILURE;
548     }
549 
550     return MLAN_STATUS_SUCCESS;
551 }
552 
wrapper_moal_semaphore_put(IN t_void * pmoal_handle,IN t_void * plock)553 static mlan_status wrapper_moal_semaphore_put(IN t_void *pmoal_handle, IN t_void *plock)
554 {
555     if (OSA_SemaphorePost((osa_semaphore_handle_t)plock) != KOSA_StatusSuccess)
556         return MLAN_STATUS_FAILURE;
557 
558     return MLAN_STATUS_SUCCESS;
559 }
560 #endif
561 
562 /** woal_callbacks */
563 static mlan_callbacks woal_callbacks = {
564     .moal_malloc      = wrapper_moal_malloc,
565     .moal_mfree       = wrapper_moal_mfree,
566     .moal_recv_packet = wrapper_moal_recv_packet,
567     .moal_memcpy_ext  = wrapper_moal_memcpy_ext,
568     .moal_init_timer  = wrapper_moal_init_timer,
569     .moal_free_timer  = wrapper_moal_free_timer,
570     .moal_start_timer = wrapper_moal_start_timer,
571     .moal_reset_timer = wrapper_moal_reset_timer,
572     .moal_stop_timer  = wrapper_moal_stop_timer,
573     .moal_init_lock   = wrapper_moal_init_lock,
574     .moal_free_lock   = wrapper_moal_free_lock,
575     .moal_spin_lock   = wrapper_moal_spin_lock,
576     .moal_spin_unlock = wrapper_moal_spin_unlock,
577 #if CONFIG_WMM
578     .moal_init_semaphore = wrapper_moal_init_semaphore,
579     .moal_free_semaphore = wrapper_moal_free_semaphore,
580     .moal_semaphore_get  = wrapper_moal_semaphore_get,
581     .moal_semaphore_put  = wrapper_moal_semaphore_put,
582 #endif
583 };
584 
mlan_subsys_init(void)585 int mlan_subsys_init(void)
586 {
587     (void)memcpy((void *)&mlan_dev.callbacks, (const void *)&woal_callbacks, sizeof(mlan_callbacks));
588 
589     /* The mlinux driver has an array of these which is dynamically allocated
590      * in function woal_update_drv_tbl (moal_main.c). We have only one.
591      */
592     /** BSS type */
593     mlan_dev.bss_attr[0].bss_type = MLAN_BSS_TYPE_STA;
594     /** Data frame type: Ethernet II, 802.11, etc. */
595     mlan_dev.bss_attr[0].frame_type = MLAN_DATA_FRAME_TYPE_ETH_II;
596     /** The BSS is active (non-0) or not (0). */
597     mlan_dev.bss_attr[0].active = MTRUE;
598     /** BSS Priority */
599     mlan_dev.bss_attr[0].bss_priority = 0;
600     /** BSS number */
601     mlan_dev.bss_attr[0].bss_num = 0;
602     /* 11d initialization */
603     /* mlan_dev.cfg_11d = 0; */
604 
605     mlan_dev.bss_attr[1].bss_type = MLAN_BSS_TYPE_UAP;
606     /** Data frame type: Ethernet II, 802.11, etc. */
607     mlan_dev.bss_attr[1].frame_type = MLAN_DATA_FRAME_TYPE_ETH_II;
608     /** The BSS is active (non-0) or not (0). */
609     mlan_dev.bss_attr[1].active = MTRUE;
610     /** BSS Priority */
611     mlan_dev.bss_attr[1].bss_priority = 0;
612     /** BSS number */
613     mlan_dev.bss_attr[1].bss_num = 0;
614 
615     /* fixme: check return value above status */
616     (void)mlan_register(&mlan_dev, (t_void **)&mlan_adap);
617 
618     (void)mlan_init_fw(mlan_adap);
619     /* wlan_init_adapter(mlan_adap); */
620 
621     return WM_SUCCESS;
622 }
623 
mlan_subsys_deinit(void)624 int mlan_subsys_deinit(void)
625 {
626     wlan_clear_scan_bss();
627     (void)mlan_unregister(mlan_adap);
628     mlan_adap = MNULL;
629 
630     return WM_SUCCESS;
631 }
632 
633 #ifdef DEBUG_11N_AGGR
wifi_get_amsdu_status()634 int wifi_get_amsdu_status()
635 {
636     wifi_get_command_lock();
637 
638     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
639 
640     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
641 
642     cmd->seq_num = 0x0;
643     cmd->result  = 0x0;
644 
645     wlan_cmd_amsdu_aggr_ctrl((mlan_private *)mlan_adap->priv[0], cmd, HostCmd_ACT_GEN_GET, NULL);
646 
647     wmprintf("Waiting for cmdresp\n\r");
648     wifi_wait_for_cmdresp(NULL);
649     wmprintf("DONE\n\r");
650 
651     mlan_ds_11n_tx_cfg txcfg;
652     (void)memset(&txcfg, 0x00, sizeof(mlan_ds_11n_tx_cfg));
653 
654     wifi_get_command_lock();
655     wlan_cmd_11n_cfg((mlan_private *)mlan_adap->priv[0], cmd, HostCmd_ACT_GEN_GET, &txcfg);
656 
657     wmprintf("Waiting for cmdresp\n\r");
658     wifi_wait_for_cmdresp(NULL);
659     wmprintf("DONE\n\r");
660 
661     return 0;
662 }
663 #endif /* DEBUG_11N_AGGR */
664 
665 #if CONFIG_11N
666 /* Note: The saved_event_buff is allocated by the cmd resp/event handler
667    thread. We need to free it in this function */
wrapper_wlan_cmd_11n_addba_rspgen(void * saved_event_buff)668 int wrapper_wlan_cmd_11n_addba_rspgen(void *saved_event_buff)
669 {
670     Event_Ext_t *evt = (Event_Ext_t *)saved_event_buff;
671 
672     (void)wifi_get_command_lock();
673 
674     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
675 
676     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
677 
678     if (evt->bss_type == BSS_TYPE_STA)
679     {
680         cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, BSS_TYPE_STA);
681         (void)wlan_cmd_11n_addba_rspgen((mlan_private *)mlan_adap->priv[evt->bss_type], cmd, &evt->reason_code);
682     }
683     else if (evt->bss_type == BSS_TYPE_UAP)
684     {
685         cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, BSS_TYPE_UAP);
686 
687         (void)wlan_cmd_11n_uap_addba_rspgen((mlan_private *)mlan_adap->priv[evt->bss_type], cmd, &evt->reason_code);
688     }
689     else
690     { /* Do Nothing */
691     }
692 
693 #ifdef DEBUG_11N_AGGR
694     wmprintf("ADDBA response\n\r");
695     dump_addba_req_rsp_packet(cmd);
696     wmprintf("Waiting for cmd resp\n\r");
697 #endif /* DEBUG_11N_AGGR */
698 
699 #if !CONFIG_MEM_POOLS
700     OSA_MemoryFree(saved_event_buff);
701 #else
702     OSA_MemoryPoolFree(buf_256_MemoryPool, saved_event_buff);
703 #endif
704 
705     (void)wifi_wait_for_cmdresp(NULL);
706 
707     return 0;
708 }
709 
wrapper_wlan_cmd_11n_ba_stream_timeout(void * saved_event_buff)710 int wrapper_wlan_cmd_11n_ba_stream_timeout(void *saved_event_buff)
711 {
712     Event_Ext_t *evt = (Event_Ext_t *)saved_event_buff;
713 
714     wlan_11n_ba_stream_timeout(mlan_adap->priv[evt->bss_type], (HostCmd_DS_11N_BATIMEOUT *)(void *)&evt->reason_code);
715 
716 #if !CONFIG_MEM_POOLS
717     OSA_MemoryFree(saved_event_buff);
718 #else
719     OSA_MemoryPoolFree(buf_256_MemoryPool, saved_event_buff);
720 #endif
721 
722     return 0;
723 }
724 
wrapper_wlan_cmd_11n_delba_rspgen(void * saved_event_buff)725 int wrapper_wlan_cmd_11n_delba_rspgen(void *saved_event_buff)
726 {
727     Event_Ext_t *evt = (Event_Ext_t *)saved_event_buff;
728 
729     wlan_11n_delete_bastream((mlan_private *)mlan_adap->priv[evt->bss_type], (t_u8 *)&evt->reason_code);
730 
731 #if !CONFIG_MEM_POOLS
732     OSA_MemoryFree(saved_event_buff);
733 #else
734     OSA_MemoryPoolFree(buf_256_MemoryPool, saved_event_buff);
735 #endif
736 
737     return 0;
738 }
739 
wrapper_wlan_update_uap_rxrate_info(RxPD * rxpd)740 void wrapper_wlan_update_uap_rxrate_info(RxPD *rxpd)
741 {
742     pmlan_private priv = mlan_adap->priv[1];
743 
744     priv->rxpd_rate = rxpd->rx_rate;
745 #ifdef SD8801
746     priv->rxpd_htinfo = rxpd->ht_info;
747 #else
748     priv->rxpd_rate_info = rxpd->rate_info;
749 #endif
750 }
751 
wlan_is_ampdu_allowed(mlan_private * priv,TxBAStreamTbl * ptx_tbl,int tid)752 static t_u8 wlan_is_ampdu_allowed(mlan_private *priv, TxBAStreamTbl *ptx_tbl, int tid)
753 {
754     if (priv->port_ctrl_mode == MTRUE)
755     {
756         if (priv->port_open == MFALSE)
757             return MFALSE;
758     }
759 
760     if (!ptx_tbl->ampdu_stat[tid] && ptx_tbl->ampdu_supported[tid] && (ptx_tbl->txpkt_cnt >= ptx_tbl->txba_thresh))
761         return MTRUE;
762     else
763         return MFALSE;
764 }
765 
wrapper_wlan_uap_ampdu_enable(uint8_t * addr,t_u8 tid)766 int wrapper_wlan_uap_ampdu_enable(uint8_t *addr
767 #if CONFIG_WMM
768                                   ,
769                                   t_u8 tid
770 #endif
771 )
772 {
773     int ret;
774     TxBAStreamTbl *ptx_tbl;
775     mlan_private *pmpriv_uap = mlan_adap->priv[1];
776 
777     if (!(pmpriv_uap->is_11n_enabled))
778         return MLAN_STATUS_SUCCESS;
779 
780     wlan_request_ralist_lock(pmpriv_uap);
781     wlan_11n_update_txbastream_tbl_tx_cnt(pmpriv_uap, addr);
782     if ((ptx_tbl = wlan_11n_get_txbastream_tbl(pmpriv_uap, addr)))
783     {
784         if (wlan_is_ampdu_allowed(pmpriv_uap, ptx_tbl,
785 #if CONFIG_WMM
786                                   tid
787 #else
788                                   0
789 #endif
790                                  ))
791         {
792             ptx_tbl->ba_status = BA_STREAM_SETUP_INPROGRESS;
793             wlan_release_ralist_lock(pmpriv_uap);
794             ret = wlan_send_addba(pmpriv_uap,
795 #if CONFIG_WMM
796                                   tid,
797 #else
798                                   0,
799 #endif
800                                   addr);
801             if (ret != 0)
802             {
803                 wifi_d("uap failed to send addba req");
804                 return MLAN_STATUS_FAILURE;
805             }
806         }
807         else
808             wlan_release_ralist_lock(pmpriv_uap);
809     }
810     else
811         wlan_release_ralist_lock(pmpriv_uap);
812     return MLAN_STATUS_SUCCESS;
813 }
814 
do_wlan_ret_11n_addba_resp(HostCmd_DS_COMMAND * resp)815 static mlan_status do_wlan_ret_11n_addba_resp(HostCmd_DS_COMMAND *resp)
816 {
817     mlan_status rv = MLAN_STATUS_SUCCESS;
818 #ifdef DEBUG_11N_AGGR
819     wmprintf("ADDBA response result\n\r");
820     dump_addba_req_rsp_packet(resp);
821 #endif /* DEBUG_11N_AGGR */
822 
823     if (resp->result != HostCmd_RESULT_OK)
824     {
825         wifi_d("Failed: ADDBA RESULT: %d", resp->result);
826         return MLAN_STATUS_FAILURE;
827     }
828 
829     int bss_type = HostCmd_GET_BSS_TYPE(resp->seq_num);
830 
831     if (bss_type == BSS_TYPE_STA)
832     {
833         mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
834         rv                   = wlan_ret_11n_addba_resp(pmpriv, resp);
835     }
836 #ifdef DEBUG_11N_AGGR
837     wmprintf("ADDBA RESP RESP: %d\n\r", resp->result);
838 #endif /* DEBUG_11N_AGGR */
839     if (bss_type == BSS_TYPE_UAP)
840     {
841         mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[1];
842         rv                   = wlan_ret_11n_addba_resp(pmpriv, resp);
843     }
844 
845     return rv;
846 }
847 
do_wlan_ret_11n_addba_req(mlan_private * priv,HostCmd_DS_COMMAND * resp)848 static mlan_status do_wlan_ret_11n_addba_req(mlan_private *priv, HostCmd_DS_COMMAND *resp)
849 {
850     t_u8 tid;
851     HostCmd_DS_11N_ADDBA_RSP *padd_ba_rsp = (HostCmd_DS_11N_ADDBA_RSP *)&resp->params.add_ba_rsp;
852     padd_ba_rsp->status_code              = wlan_le16_to_cpu(padd_ba_rsp->status_code);
853     TxBAStreamTbl *ptx_ba_tbl;
854 
855     padd_ba_rsp->block_ack_param_set = wlan_le16_to_cpu(padd_ba_rsp->block_ack_param_set);
856     padd_ba_rsp->block_ack_tmo       = wlan_le16_to_cpu(padd_ba_rsp->block_ack_tmo);
857     padd_ba_rsp->ssn                 = (wlan_le16_to_cpu(padd_ba_rsp->ssn)) & SSN_MASK;
858     padd_ba_rsp->status_code         = wlan_le16_to_cpu(padd_ba_rsp->status_code);
859 
860     tid = (padd_ba_rsp->block_ack_param_set & BLOCKACKPARAM_TID_MASK) >> BLOCKACKPARAM_TID_POS;
861 
862     if (padd_ba_rsp->status_code == BA_RESULT_SUCCESS)
863     {
864         wlan_request_ralist_lock(priv);
865         if ((ptx_ba_tbl = wlan_11n_get_txbastream_tbl(priv, padd_ba_rsp->peer_mac_addr)))
866         {
867             wlan_11n_update_txbastream_tbl_ampdu_stat(priv, padd_ba_rsp->peer_mac_addr, MTRUE, tid);
868 
869             PRINTM(MCMND, "ADDBA REQ: %02x:%02x:%02x:%02x:%02x:%02x tid=%d ssn=%d win_size=%d,amsdu=%d\n",
870                    padd_ba_rsp->peer_mac_addr[0], padd_ba_rsp->peer_mac_addr[1], padd_ba_rsp->peer_mac_addr[2],
871                    padd_ba_rsp->peer_mac_addr[3], padd_ba_rsp->peer_mac_addr[4], padd_ba_rsp->peer_mac_addr[5], tid,
872                    padd_ba_rsp->ssn,
873                    ((padd_ba_rsp->block_ack_param_set & BLOCKACKPARAM_WINSIZE_MASK) >> BLOCKACKPARAM_WINSIZE_POS),
874                    padd_ba_rsp->block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK);
875 
876             ptx_ba_tbl->ba_status = BA_STREAM_SETUP_COMPLETE;
877 
878             if ((padd_ba_rsp->block_ack_param_set & BLOCKACKPARAM_AMSDU_SUPP_MASK) && priv->add_ba_param.tx_amsdu)
879                 ptx_ba_tbl->amsdu = MTRUE;
880             else
881                 ptx_ba_tbl->amsdu = MFALSE;
882             wlan_release_ralist_lock(priv);
883         }
884         else
885         {
886             wlan_release_ralist_lock(priv);
887             PRINTM(MERROR, "BA stream not created\n");
888         }
889     }
890     else
891     {
892         if (padd_ba_rsp->add_rsp_result != BA_RESULT_TIMEOUT)
893         {
894             wlan_request_ralist_lock(priv);
895             if ((ptx_ba_tbl = wlan_11n_get_txbastream_tbl(priv, padd_ba_rsp->peer_mac_addr)))
896             {
897                 wlan_11n_update_txbastream_tbl_ampdu_stat(priv, padd_ba_rsp->peer_mac_addr, MFALSE, tid);
898                 ptx_ba_tbl->ampdu_supported[tid] = MFALSE;
899             }
900             wlan_release_ralist_lock(priv);
901         }
902         else
903         {
904             wlan_request_ralist_lock(priv);
905             if ((ptx_ba_tbl = wlan_11n_get_txbastream_tbl(priv, padd_ba_rsp->peer_mac_addr)))
906             {
907                 /* Clear txpkt_cnt to avoid collision between our STA and our uAP */
908                 ptx_ba_tbl->txpkt_cnt = 0;
909             }
910             wlan_release_ralist_lock(priv);
911         }
912         wifi_d("Failed: ADDBA req: %d", padd_ba_rsp->add_rsp_result);
913     }
914 
915     return MLAN_STATUS_SUCCESS;
916 }
917 
do_wlan_ret_11n_delba(mlan_private * priv,HostCmd_DS_COMMAND * resp)918 static mlan_status do_wlan_ret_11n_delba(mlan_private *priv, HostCmd_DS_COMMAND *resp)
919 {
920     HostCmd_DS_11N_DELBA *pdel_ba = (HostCmd_DS_11N_DELBA *)&resp->params.del_ba;
921     int tid;
922 
923     pdel_ba->del_ba_param_set = wlan_le16_to_cpu(pdel_ba->del_ba_param_set);
924     tid                       = pdel_ba->del_ba_param_set >> DELBA_TID_POS;
925 
926     if (pdel_ba->del_result == BA_RESULT_SUCCESS)
927     {
928         mlan_11n_update_bastream_tbl(priv, tid, pdel_ba->peer_mac_addr, TYPE_DELBA_SENT,
929                                      INITIATOR_BIT(pdel_ba->del_ba_param_set));
930     }
931     else
932     {
933         wifi_d("Failed: DELBA: %d", pdel_ba->del_result);
934     }
935 
936     return MLAN_STATUS_SUCCESS;
937 }
938 
939 // Only Enable AMPDU for station interface
wrapper_wlan_sta_ampdu_enable(t_u8 tid)940 int wrapper_wlan_sta_ampdu_enable(
941 #if CONFIG_WMM
942     t_u8 tid
943 #endif
944 )
945 {
946     int ret;
947     mlan_private *pmpriv               = (mlan_private *)mlan_adap->priv[0];
948     t_u8 cur_mac[MLAN_MAC_ADDR_LENGTH] = {0};
949     TxBAStreamTbl *ptx_tbl             = NULL;
950 
951     wlan_request_ralist_lock(pmpriv);
952     if (pmpriv->media_connected == MTRUE)
953     {
954         (void)memcpy(cur_mac, pmpriv->curr_bss_params.bss_descriptor.mac_address, MLAN_MAC_ADDR_LENGTH);
955         ptx_tbl = wlan_11n_get_txbastream_tbl(pmpriv, cur_mac);
956         if (!ptx_tbl)
957         {
958             wlan_11n_create_txbastream_tbl(pmpriv, cur_mac, BA_STREAM_NOT_SETUP);
959 
960             ptx_tbl              = wlan_11n_get_txbastream_tbl(pmpriv, cur_mac);
961             ptx_tbl->txba_thresh = 1;
962 
963             if (pmpriv->curr_bss_params.bss_descriptor.pht_cap)
964             {
965                 wlan_11n_update_txbastream_tbl_ampdu_supported(pmpriv, cur_mac, MTRUE);
966             }
967             else
968             {
969                 wlan_release_ralist_lock(pmpriv);
970                 return MLAN_STATUS_SUCCESS;
971             }
972         }
973     }
974     else
975     {
976         wifi_d("sta not connected: failed to send addba req");
977         wlan_release_ralist_lock(pmpriv);
978         return MLAN_STATUS_FAILURE;
979     }
980 
981     wlan_11n_update_txbastream_tbl_tx_cnt(pmpriv, cur_mac);
982 
983     if (wlan_is_ampdu_allowed(pmpriv, ptx_tbl,
984 #if CONFIG_WMM
985                               tid
986 #else
987                               0
988 #endif
989                               ))
990     {
991         ptx_tbl->ba_status = BA_STREAM_SETUP_INPROGRESS;
992         wlan_release_ralist_lock(pmpriv);
993         ret = wlan_send_addba(pmpriv,
994 #if CONFIG_WMM
995                               tid,
996 #else
997                               0,
998 #endif
999                               (t_u8 *)cur_mac);
1000         if (ret != 0)
1001         {
1002             wifi_d("sta: failed to send addba req");
1003             return MLAN_STATUS_FAILURE;
1004         }
1005     }
1006     else
1007         wlan_release_ralist_lock(pmpriv);
1008 
1009     return MLAN_STATUS_SUCCESS;
1010 }
1011 #endif /* CONFIG_11N */
1012 
wrapper_wlan_11d_enable(t_u32 state)1013 int wrapper_wlan_11d_enable(t_u32 state)
1014 {
1015     t_u32 enable_11d = state;
1016 
1017     wifi_get_command_lock();
1018     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1019     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
1020 
1021     cmd->seq_num = 0x00;
1022     cmd->result  = 0x0;
1023 
1024     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_SNMP_MIB, HostCmd_ACT_GEN_SET,
1025                              Dot11D_i, NULL, &enable_11d, cmd);
1026 
1027     return wifi_wait_for_cmdresp(NULL);
1028 }
1029 
wrapper_wlan_uap_11d_enable(t_u32 state)1030 int wrapper_wlan_uap_11d_enable(t_u32 state)
1031 {
1032     t_u32 enable_11d = state;
1033 
1034     wifi_get_command_lock();
1035     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1036     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
1037 
1038     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_UAP);
1039     cmd->result  = 0x0;
1040 
1041     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_SNMP_MIB, HostCmd_ACT_GEN_SET,
1042                              Dot11D_i, NULL, &enable_11d, cmd);
1043 
1044     return wifi_wait_for_cmdresp(NULL);
1045 }
1046 
wifi_11h_enable(void)1047 int wifi_11h_enable(void)
1048 {
1049     t_u32 enable_11h = (t_u32)ENABLE_11H;
1050 
1051     (void)wifi_get_command_lock();
1052     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1053     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
1054 
1055     cmd->seq_num = 0x0;
1056     cmd->result  = 0x0;
1057 
1058     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_SNMP_MIB, HostCmd_ACT_GEN_SET,
1059                                    (t_u32)Dot11H_i, NULL, &enable_11h, cmd);
1060 
1061     return wifi_wait_for_cmdresp(NULL);
1062 }
1063 
wrapper_wlan_ecsa_enable(void)1064 int wrapper_wlan_ecsa_enable(void)
1065 {
1066     bool ecsa_enable = MTRUE;
1067 
1068     if ((mlan_adap->fw_cap_info & FW_CAPINFO_ECSA) == 0U)
1069     {
1070         return -WM_FAIL;
1071     }
1072 
1073     mlan_adap->ecsa_enable = MTRUE;
1074 
1075     (void)wifi_get_command_lock();
1076     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1077     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
1078 
1079     cmd->seq_num = 0x0;
1080     cmd->result  = 0x0;
1081 
1082     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_SNMP_MIB, HostCmd_ACT_GEN_SET,
1083                                    (t_u32)ECSAEnable_i, NULL, &ecsa_enable, cmd);
1084 
1085     return wifi_wait_for_cmdresp(NULL);
1086 }
1087 
wrapper_wlan_cmd_get_hw_spec(void)1088 int wrapper_wlan_cmd_get_hw_spec(void)
1089 {
1090     (void)wifi_get_command_lock();
1091     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1092     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
1093     cmd->seq_num = 0x0;
1094     cmd->result  = 0x0;
1095     (void)wlan_cmd_get_hw_spec((mlan_private *)mlan_adap->priv[0], cmd);
1096     (void)wifi_wait_for_cmdresp(NULL);
1097     return 0;
1098 }
1099 
wrapper_wlan_cmd_mgmt_ie(int bss_type,void * buffer,unsigned int len,t_u16 action)1100 mlan_status wrapper_wlan_cmd_mgmt_ie(int bss_type, void *buffer, unsigned int len, t_u16 action)
1101 {
1102     void *pdata_buf = NULL;
1103     HostCmd_DS_MGMT_IE_LIST_CFG ds_mgmt_ie_list_cfg;
1104     mlan_status status = MLAN_STATUS_SUCCESS;
1105 
1106     (void)wifi_get_command_lock();
1107 
1108     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1109     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
1110 #if CONFIG_P2P
1111     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, MLAN_BSS_TYPE_WIFIDIRECT);
1112 #else
1113     cmd->seq_num       = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, bss_type);
1114 #endif
1115     cmd->result = 0x0;
1116 
1117     (void)memset(&ds_mgmt_ie_list_cfg, 0x00, sizeof(HostCmd_DS_MGMT_IE_LIST_CFG));
1118 
1119     (void)memcpy((void *)&ds_mgmt_ie_list_cfg, (const void *)buffer, len);
1120 
1121     pdata_buf = &ds_mgmt_ie_list_cfg;
1122 
1123     if (bss_type == MLAN_BSS_TYPE_UAP)
1124         status = wlan_ops_uap_prepare_cmd((mlan_private *)mlan_adap->priv[1], HOST_CMD_APCMD_SYS_CONFIGURE, action, 0,
1125                                           NULL, pdata_buf, cmd);
1126     else
1127         status = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MGMT_IE_LIST, action, 0, NULL,
1128                                           pdata_buf, cmd);
1129 
1130     (void)wifi_wait_for_cmdresp(buffer);
1131     return status;
1132 }
1133 
wrapper_wlan_handle_rx_packet(t_u16 datalen,RxPD * rxpd,void * p,void * payload)1134 int wrapper_wlan_handle_rx_packet(t_u16 datalen, RxPD *rxpd, void *p, void *payload)
1135 {
1136     w_pkt_d("[recv]                  : %p T: %d L: %d", p, rxpd->rx_pkt_type, rxpd->rx_pkt_length);
1137 
1138 #if !(CONFIG_TX_RX_ZERO_COPY) && !(FSL_USDHC_ENABLE_SCATTER_GATHER_TRANSFER)
1139     /* fixme: Check if mlan buffer can be allocated from standard mlan
1140        function */
1141 #if !CONFIG_MEM_POOLS
1142     pmlan_buffer pmbuf = OSA_MemoryAllocate(sizeof(mlan_buffer));
1143 #else
1144     pmlan_buffer pmbuf = OSA_MemoryPoolAllocate(buf_128_MemoryPool);
1145 #endif
1146 
1147     if (pmbuf == MNULL)
1148     {
1149         /* No mlan_buffer available. Drop this packet */
1150         /* fixme: Need to note this event. */
1151         wifi_w("No memory available. Have to drop packet.");
1152         return -WM_FAIL;
1153     }
1154 #else
1155     pmlan_buffer pmbuf = (pmlan_buffer)((t_u8 *)rxpd - INTF_HEADER_LEN - sizeof(mlan_buffer));
1156 #endif
1157     /** Buffer descriptor, e.g. skb in Linux */
1158     /* Note: We are storing payload member here. We need to unwind
1159        pointer when passing pbuf to lwip */
1160     pmbuf->pdesc = payload;
1161 
1162     /* Store it for later retrivval. mlan stack does not know about this */
1163     pmbuf->lwip_pbuf = p;
1164 
1165     /* fixme: check that no data is accessed after this pointer
1166       Note: Important: mlan requires RxPD in number of places. We
1167     already have duplicated the ethernet packet in the pbuf. We cannot
1168     afford to duplicate the entire SDIO buffer and reduplicate the
1169     ethernet part of it into pbuf which the lwip requires. So, we will
1170     duplicate only the RxPD for ourselves. We will have to change all
1171     the code which assumes that there is ethernet packet after RxPD */
1172     /** Pointer to buffer */
1173     /* fixme: CHK this*/
1174 #if !(CONFIG_TX_RX_ZERO_COPY) && !(FSL_USDHC_ENABLE_SCATTER_GATHER_TRANSFER)
1175 #if !CONFIG_MEM_POOLS
1176     pmbuf->pbuf = (t_u8 *)OSA_MemoryAllocate(sizeof(RxPD));
1177 #else
1178     pmbuf->pbuf        = OSA_MemoryPoolAllocate(buf_128_MemoryPool);
1179 #endif
1180     if (pmbuf->pbuf == MNULL)
1181     {
1182         /* No buffer available. Drop this packet */
1183         /* fixme: Need to note this event. */
1184 #if !CONFIG_MEM_POOLS
1185         OSA_MemoryFree(pmbuf);
1186 #else
1187         OSA_MemoryPoolFree(buf_128_MemoryPool, pmbuf);
1188 #endif
1189         wifi_w("No memory available. Have to drop packet.");
1190         return -WM_FAIL;
1191     }
1192     (void)memcpy((void *)pmbuf->pbuf, (const void *)rxpd, sizeof(RxPD));
1193 #else
1194     pmbuf->pbuf        = (t_u8 *)rxpd;
1195 #endif
1196     /** Offset to data */
1197     /* This should ideally be INTF_HEADER_LEN. But we not be storing
1198        initial INTF_HEADER_LEN bytes. We will store RxPD directly */
1199     /* fixme: CHK this*/
1200     pmbuf->data_offset = 0;
1201 
1202     /** Data length */
1203     /* fixme: CHK this*/
1204     pmbuf->data_len = datalen;
1205     /** Buffer type: data, cmd, event etc. */
1206     pmbuf->buf_type = MLAN_BUF_TYPE_DATA;
1207     /** Fields below are valid for data packet only */
1208     /** QoS priority */
1209     /* t_u32 priority; */
1210     /** Time stamp when packet is received (seconds) */
1211     /* t_u32 in_ts_sec; */
1212     /** Time stamp when packet is received (micro seconds) */
1213     /* t_u32 in_ts_usec; */
1214     /** Time stamp when packet is processed (seconds) */
1215     /* t_u32 out_ts_sec; */
1216     /** Time stamp when packet is processed (micro seconds) */
1217     /* t_u32 out_ts_usec; */
1218 
1219     /** Fields below are valid for MLAN module only */
1220     /** Pointer to parent mlan_buffer */
1221     /* struct _mlan_buffer *pparent; */
1222     /** Use count for this buffer */
1223     /* t_u32 use_count; */
1224 
1225     mlan_status rv = wlan_handle_rx_packet(mlan_adap, pmbuf);
1226     if (rv != MLAN_STATUS_SUCCESS)
1227     {
1228         /* mlan did not accept this packet for some reason. Some
1229            probable reasons are - duplicate packet - packet outside
1230            the current 11n aggregation window.
1231 
1232            We need to free allocated structures.
1233         */
1234 #if !(CONFIG_TX_RX_ZERO_COPY) && !(FSL_USDHC_ENABLE_SCATTER_GATHER_TRANSFER)
1235 #if !CONFIG_MEM_POOLS
1236         OSA_MemoryFree(pmbuf->pbuf);
1237         OSA_MemoryFree(pmbuf);
1238 #else
1239         OSA_MemoryPoolFree(buf_128_MemoryPool, pmbuf->pbuf);
1240         OSA_MemoryPoolFree(buf_128_MemoryPool, pmbuf);
1241 #endif
1242 #endif
1243         return -WM_FAIL;
1244     }
1245 
1246     return WM_SUCCESS;
1247 }
1248 
1249 /* fixme: This AMSDU special handling needs to be redesigned. We could
1250    create a copy of the SDIO packet buffer for _every_ packet AMSDU and
1251    non-AMSDU. We could then use RAW_PBUF allocation to allocate pbufs
1252    during final step of packet delivery to lwip stack.
1253 
1254    Note: This is not AMSDU inside AMPDU. This is a pure AMSDU.
1255    Note: We will not be duplicating the AMSDU packet from the SDIO
1256    buffer. So, we have to ensure that there are no race
1257    conditions. i.e. the SDIO buffer is not overwritten in the background.
1258 */
wrapper_wlan_handle_amsdu_rx_packet(const t_u8 * rcvdata,const t_u16 datalen)1259 int wrapper_wlan_handle_amsdu_rx_packet(const t_u8 *rcvdata, const t_u16 datalen)
1260 {
1261     w_pkt_d("[amsdu] [recv]       : L: %d", datalen);
1262 
1263     RxPD *rxpd = (RxPD *)(void *)((t_u8 *)rcvdata + INTF_HEADER_LEN);
1264 
1265     /* fixme: Check if mlan buffer can be allocated from standard mlan
1266        function */
1267 #if !CONFIG_MEM_POOLS
1268     pmlan_buffer pmbuf = OSA_MemoryAllocate(sizeof(mlan_buffer));
1269 #else
1270     pmlan_buffer pmbuf = OSA_MemoryPoolAllocate(buf_128_MemoryPool);
1271 #endif
1272 
1273     if (pmbuf == MNULL)
1274     {
1275         /* No mlan_buffer available. Drop this packet */
1276         /* fixme: Need to note this event. */
1277         w_pkt_e("[amsdu] No memory available. Have to drop packet");
1278         return -WM_FAIL;
1279     }
1280     (void)memset(pmbuf, 0x00, sizeof(mlan_buffer));
1281 
1282     /** Buffer descriptor, e.g. skb in Linux */
1283     /* Note: We are storing payload member here. We need to unwind
1284        pointer when passing pbuf to lwip */
1285     pmbuf->pdesc = ((t_u8 *)rcvdata + INTF_HEADER_LEN + rxpd->rx_pkt_offset);
1286 
1287     /* Store it for later retrivval. mlan stack does not know about this */
1288     pmbuf->lwip_pbuf = NULL;
1289 
1290     /* Since this is an AMSDU packet we have the entire SDIO buffer
1291        with us. So we do not need to duplicate RxPD
1292     */
1293     pmbuf->pbuf = (t_u8 *)rxpd;
1294     /** Offset to data */
1295     pmbuf->data_offset = 0;
1296 
1297     /** Data length */
1298     /* fixme: CHK this*/
1299     pmbuf->data_len = datalen;
1300     /** Buffer type: data, cmd, event etc. */
1301     pmbuf->buf_type = MLAN_BUF_TYPE_DATA;
1302     /** Fields below are valid for data packet only */
1303     /** QoS priority */
1304     /* t_u32 priority; */
1305     /** Time stamp when packet is received (seconds) */
1306     /* t_u32 in_ts_sec; */
1307     /** Time stamp when packet is received (micro seconds) */
1308     /* t_u32 in_ts_usec; */
1309     /** Time stamp when packet is processed (seconds) */
1310     /* t_u32 out_ts_sec; */
1311     /** Time stamp when packet is processed (micro seconds) */
1312     /* t_u32 out_ts_usec; */
1313 
1314     /** Fields below are valid for MLAN module only */
1315     /** Pointer to parent mlan_buffer */
1316     /* struct _mlan_buffer *pparent; */
1317     /** Use count for this buffer */
1318     /* t_u32 use_count; */
1319 
1320     if (rxpd->bss_type == (t_u8)MLAN_BSS_ROLE_STA)
1321     {
1322         (void)wlan_handle_rx_packet(mlan_adap, pmbuf);
1323     }
1324     else
1325     {
1326         pmlan_private priv = wlan_get_priv(mlan_adap, MLAN_BSS_ROLE_UAP);
1327         pmbuf->data_len    = rxpd->rx_pkt_length;
1328         pmbuf->data_offset += rxpd->rx_pkt_offset;
1329         (void)wlan_11n_deaggregate_pkt(priv, pmbuf);
1330     }
1331     /* if (rv != MLAN_STATUS_SUCCESS) { */
1332     /*
1333       We need to free allocated structures. In case of AMSDU this pmbuf
1334       is not freed inside mlan
1335     */
1336 #if !CONFIG_MEM_POOLS
1337     OSA_MemoryFree(pmbuf);
1338 #else
1339     OSA_MemoryPoolFree(buf_128_MemoryPool, pmbuf);
1340 #endif
1341 
1342     /* return -WM_FAIL; */
1343     /* } */
1344 
1345     return WM_SUCCESS;
1346 }
1347 
1348 #if CONFIG_NET_MONITOR
register_monitor_user_callback(int (* monitor_cb)(void * frame,t_u16 len))1349 void register_monitor_user_callback(int (*monitor_cb)(void *frame, t_u16 len))
1350 {
1351     net_monitor_callback = monitor_cb;
1352 }
1353 
deregister_monitor_user_callback()1354 void deregister_monitor_user_callback()
1355 {
1356     net_monitor_callback = NULL;
1357 }
1358 
set_monitor_flag(bool flag)1359 void set_monitor_flag(bool flag)
1360 {
1361     g_monitor_status = flag;
1362 }
1363 
get_monitor_flag()1364 bool get_monitor_flag()
1365 {
1366     return g_monitor_status;
1367 }
1368 
user_recv_monitor_data(const t_u8 * rcvdata)1369 void user_recv_monitor_data(const t_u8 *rcvdata)
1370 {
1371     t_s8 rssi              = 0;
1372     t_u16 datalen          = 0;
1373     t_u8 *net_monitor_data = NULL;
1374     RxPD *rxpd             = (RxPD *)((t_u8 *)rcvdata + INTF_HEADER_LEN);
1375     t_u16 inimupkt_len     = *(t_u16 *)rcvdata;
1376 
1377     datalen = rxpd->rx_pkt_length + sizeof(t_s8);
1378     rssi    = rxpd->snr - rxpd->nf;
1379 
1380     if ((rxpd->rx_pkt_length + rxpd->rx_pkt_offset + INTF_HEADER_LEN) != inimupkt_len)
1381     {
1382         wifi_w("rx_pkt_length + rx_pkt_offset + INTF_HEADER_LEN is not equal to inimupkt_len \n\r");
1383         wifi_w("Invalid data, discard \n\r");
1384         wifi_w("rx_pkt_length :%d \n\r", rxpd->rx_pkt_length);
1385         wifi_w("rx_pkt_offset :%d \n\r", rxpd->rx_pkt_offset);
1386         wifi_w("inimupkt_len  :%d \n\r", inimupkt_len);
1387         return;
1388     }
1389 
1390     if (net_monitor_callback != NULL)
1391     {
1392         net_monitor_data = OSA_MemoryAllocate(datalen);
1393 
1394         if (!net_monitor_data)
1395         {
1396             wifi_w("No mem. Cannot process net monitor data");
1397             return;
1398         }
1399 
1400         memcpy(net_monitor_data, &rssi, sizeof(t_s8));
1401         memcpy(net_monitor_data + sizeof(t_s8), ((t_u8 *)rcvdata + INTF_HEADER_LEN + rxpd->rx_pkt_offset),
1402                rxpd->rx_pkt_length);
1403 
1404         net_monitor_callback((void *)net_monitor_data, datalen);
1405 
1406         OSA_MemoryFree(net_monitor_data);
1407     }
1408 
1409     return;
1410 }
1411 #endif
wrapper_wlan_cmd_11n_cfg(HostCmd_DS_COMMAND * cmd)1412 void wrapper_wlan_cmd_11n_cfg(HostCmd_DS_COMMAND *cmd)
1413 {
1414     mlan_ds_11n_tx_cfg txcfg = {/** HTTxCap */
1415                                 .httxcap = DOT11N_CFG_ENABLE_GREENFIELD_XMIT | DOT11N_CFG_ENABLE_SHORT_GI_20MHZ |
1416                                            DOT11N_CFG_ENABLE_SHORT_GI_40MHZ,
1417                                 /** HTTxInfo */
1418                                 .httxinfo = DOT11N_CFG_ENABLE_RIFS,
1419                                 /** Band selection */
1420                                 .misc_cfg = BAND_SELECT_BOTH};
1421 
1422     (void)wlan_cmd_11n_cfg((mlan_private *)mlan_adap->priv[0], cmd, HostCmd_ACT_GEN_SET, &txcfg);
1423 }
1424 
1425 /*
1426   fixme: Following three functions will not be needed when
1427   wlan_11h_handle_event_chanswann is used to handle the relevant event */
set_event_chanswann(void)1428 void set_event_chanswann(void)
1429 {
1430     mlan_adap->state_11h.recvd_chanswann_event = MTRUE;
1431 }
1432 
clear_event_chanswann(void)1433 void clear_event_chanswann(void)
1434 {
1435     mlan_adap->state_11h.recvd_chanswann_event = MFALSE;
1436 }
1437 
wrapper_wlan_11d_clear_parsedtable(void)1438 void wrapper_wlan_11d_clear_parsedtable(void)
1439 {
1440     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
1441     (void)wlan_11d_clear_parsedtable(pmpriv);
1442 }
1443 
1444 /*
1445   This was added to solve the radar DFS issue. The function
1446   wlan_11h_radar_detect_required() checks for this and sets the scan to
1447   active if media is connected. The temporary problem with our current port
1448   of mlan is that after a deauth is sent after channel switch event from
1449   the AP, the media connected event is still MTRUE. Hence, during scan the
1450   old channel of the AP is marked as active scan which is not a correct way
1451   of scanning on that channel (since radar interference is detected on
1452   it). So, for now we clear this bit manually to avoid active scan on the
1453   old channel. This bit will be set again at the next association completion.
1454 
1455   fixme: Check this later.
1456  */
wrapper_clear_media_connected_event(void)1457 void wrapper_clear_media_connected_event(void)
1458 {
1459     mlan_private *pmpriv    = (mlan_private *)mlan_adap->priv[0];
1460     pmpriv->media_connected = MFALSE;
1461 }
1462 
wifi_prepare_and_send_cmd(IN mlan_private * pmpriv,IN t_u16 cmd_no,IN t_u16 cmd_action,IN t_u32 cmd_oid,IN t_void * pioctl_buf,IN t_void * pdata_buf,mlan_bss_type bss_type,void * priv)1463 mlan_status wifi_prepare_and_send_cmd(IN mlan_private *pmpriv,
1464                                       IN t_u16 cmd_no,
1465                                       IN t_u16 cmd_action,
1466                                       IN t_u32 cmd_oid,
1467                                       IN t_void *pioctl_buf,
1468                                       IN t_void *pdata_buf,
1469                                       mlan_bss_type bss_type,
1470                                       void *priv)
1471 {
1472     pmlan_ioctl_req pioctl_req = (mlan_ioctl_req *)pioctl_buf;
1473     mlan_status rv             = MLAN_STATUS_SUCCESS;
1474 
1475     (void)wifi_get_command_lock();
1476     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1477 
1478     if (pioctl_req != NULL)
1479     {
1480         if (pioctl_req->bss_index == 1U)
1481         {
1482             bss_type = MLAN_BSS_TYPE_UAP;
1483         }
1484     }
1485 
1486 #if CONFIG_P2P
1487     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, MLAN_BSS_TYPE_WIFIDIRECT);
1488 #else
1489     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, (t_u8)bss_type);
1490 #endif /* CONFIG_P2P */
1491     cmd->result = 0x0;
1492 
1493     if (bss_type == MLAN_BSS_TYPE_UAP)
1494     {
1495         rv = wlan_ops_uap_prepare_cmd(pmpriv, cmd_no, cmd_action, cmd_oid, pioctl_buf, pdata_buf, cmd);
1496     }
1497     else
1498     {
1499         rv = wlan_ops_sta_prepare_cmd(pmpriv, cmd_no, cmd_action, cmd_oid, pioctl_buf, pdata_buf, cmd);
1500     }
1501 
1502     if (rv != MLAN_STATUS_SUCCESS)
1503     {
1504         wifi_d("Failed to prepare cmd.");
1505         wm_wifi.cmd_resp_priv = NULL;
1506         (void)wifi_put_command_lock();
1507         return rv;
1508     }
1509 
1510     (void)wifi_wait_for_cmdresp(priv);
1511     return MLAN_STATUS_SUCCESS;
1512 }
1513 
wmsdk_is_11N_enabled(void)1514 bool wmsdk_is_11N_enabled(void)
1515 {
1516 #if CONFIG_11N
1517     return true;
1518 #else
1519     return false;
1520 #endif /* CONFIG_11N */
1521 }
1522 
wifi_send_bss_ioctl(mlan_ds_bss * bss)1523 /* static */ int wifi_send_bss_ioctl(mlan_ds_bss *bss)
1524 {
1525     /* fixme: check if this needs to go on heap */
1526     mlan_ioctl_req req;
1527 
1528     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
1529     req.pbuf      = (t_u8 *)bss;
1530     req.buf_len   = sizeof(mlan_ds_bss);
1531     req.bss_index = 0;
1532     req.req_id    = MLAN_IOCTL_BSS;
1533 
1534     mlan_status rv = wlan_ops_sta_ioctl(mlan_adap, &req);
1535     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
1536     {
1537         return -WM_FAIL;
1538     }
1539 
1540     return WM_SUCCESS;
1541 }
1542 
wrapper_get_wpa_ie_in_assoc(uint8_t * wpa_ie)1543 int wrapper_get_wpa_ie_in_assoc(uint8_t *wpa_ie)
1544 {
1545     mlan_private *priv = (mlan_private *)mlan_adap->priv[0];
1546 
1547     /* Reset all state variables */
1548     (void)memcpy((void *)wpa_ie, (const void *)&priv->wpa_ie, sizeof(priv->wpa_ie));
1549 
1550     return (int)priv->wpa_ie_len;
1551 }
1552 
wifi_send_11n_cfg_ioctl(mlan_act_ioctl action,mlan_ds_11n_cfg * ds_11n_cfg)1553 static int wifi_send_11n_cfg_ioctl(mlan_act_ioctl action, mlan_ds_11n_cfg *ds_11n_cfg)
1554 {
1555     /* fixme: check if this needs to go on heap */
1556     mlan_ioctl_req req;
1557 
1558     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
1559     req.pbuf      = (t_u8 *)ds_11n_cfg;
1560     req.buf_len   = sizeof(mlan_ds_11n_cfg);
1561     req.bss_index = 0;
1562     req.req_id    = MLAN_IOCTL_11N_CFG;
1563     req.action    = action;
1564 
1565     mlan_status rv = wlan_ops_sta_ioctl(mlan_adap, &req);
1566     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
1567     {
1568         return -WM_FAIL;
1569     }
1570 
1571     return WM_SUCCESS;
1572 }
1573 
wifi_send_uap_11n_cfg_ioctl(mlan_act_ioctl action,mlan_ds_11n_cfg * ds_11n_cfg)1574 static int wifi_send_uap_11n_cfg_ioctl(mlan_act_ioctl action, mlan_ds_11n_cfg *ds_11n_cfg)
1575 {
1576     /* fixme: check if this needs to go on heap */
1577     mlan_ioctl_req req;
1578 
1579     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
1580     req.pbuf      = (t_u8 *)ds_11n_cfg;
1581     req.buf_len   = sizeof(mlan_ds_11n_cfg);
1582     req.bss_index = 1;
1583     req.req_id    = MLAN_IOCTL_11N_CFG;
1584     req.action    = action;
1585 
1586     mlan_status rv = wlan_ops_sta_ioctl(mlan_adap, &req);
1587     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
1588     {
1589         return -WM_FAIL;
1590     }
1591 
1592     return WM_SUCCESS;
1593 }
1594 
wifi_set_txbfcap(unsigned int tx_bf_cap)1595 int wifi_set_txbfcap(unsigned int tx_bf_cap)
1596 {
1597     mlan_ds_11n_cfg ds_11n_cfg;
1598 
1599     (void)memset(&ds_11n_cfg, 0x00, sizeof(mlan_ds_11n_cfg));
1600 
1601     ds_11n_cfg.sub_command     = MLAN_OID_11N_CFG_TX_BF_CAP;
1602     ds_11n_cfg.param.tx_bf_cap = tx_bf_cap;
1603 
1604     return wifi_send_11n_cfg_ioctl(MLAN_ACT_SET, &ds_11n_cfg);
1605 }
1606 
wifi_set_htcapinfo(unsigned int htcapinfo)1607 int wifi_set_htcapinfo(unsigned int htcapinfo)
1608 {
1609     mlan_ds_11n_cfg ds_11n_cfg;
1610 
1611     (void)memset(&ds_11n_cfg, 0x00, sizeof(mlan_ds_11n_cfg));
1612 
1613     ds_11n_cfg.sub_command           = MLAN_OID_11N_HTCAP_CFG;
1614     ds_11n_cfg.param.htcap_cfg.htcap = htcapinfo;
1615 #if CONFIG_5GHz_SUPPORT
1616     ds_11n_cfg.param.htcap_cfg.misc_cfg = BAND_SELECT_BOTH;
1617 #else
1618     ds_11n_cfg.param.htcap_cfg.misc_cfg = BAND_SELECT_BG;
1619 #endif
1620 
1621     return wifi_send_11n_cfg_ioctl(MLAN_ACT_SET, &ds_11n_cfg);
1622 }
1623 
wifi_set_httxcfg(unsigned short httxcfg)1624 int wifi_set_httxcfg(unsigned short httxcfg)
1625 {
1626     mlan_ds_11n_cfg ds_11n_cfg;
1627 
1628     (void)memset(&ds_11n_cfg, 0x00, sizeof(mlan_ds_11n_cfg));
1629 
1630     ds_11n_cfg.sub_command          = MLAN_OID_11N_CFG_TX;
1631     ds_11n_cfg.param.tx_cfg.httxcap = httxcfg;
1632 #if CONFIG_5GHz_SUPPORT
1633     ds_11n_cfg.param.tx_cfg.misc_cfg = BAND_SELECT_BOTH;
1634 #else
1635     ds_11n_cfg.param.tx_cfg.misc_cfg    = BAND_SELECT_BG;
1636 #endif
1637 
1638     return wifi_send_11n_cfg_ioctl(MLAN_ACT_SET, &ds_11n_cfg);
1639 }
1640 
wifi_uap_set_httxcfg_int(unsigned short httxcfg)1641 int wifi_uap_set_httxcfg_int(unsigned short httxcfg)
1642 {
1643     mlan_ds_11n_cfg ds_11n_cfg;
1644 
1645     (void)memset(&ds_11n_cfg, 0x00, sizeof(mlan_ds_11n_cfg));
1646 
1647     ds_11n_cfg.sub_command          = MLAN_OID_11N_CFG_TX;
1648     ds_11n_cfg.param.tx_cfg.httxcap = httxcfg;
1649 #if CONFIG_5GHz_SUPPORT
1650     ds_11n_cfg.param.tx_cfg.misc_cfg = BAND_SELECT_BOTH;
1651 #else
1652     ds_11n_cfg.param.tx_cfg.misc_cfg    = BAND_SELECT_BG;
1653 #endif
1654 
1655     return wifi_send_uap_11n_cfg_ioctl(MLAN_ACT_SET, &ds_11n_cfg);
1656 }
1657 
wifi_send_tx_power_cfg_ioctl(mlan_act_ioctl action,mlan_ds_power_cfg * ds_power_cfg)1658 static int wifi_send_tx_power_cfg_ioctl(mlan_act_ioctl action, mlan_ds_power_cfg *ds_power_cfg)
1659 {
1660     /* fixme: check if this needs to go on heap */
1661     mlan_ioctl_req req;
1662 
1663     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
1664     req.pbuf      = (t_u8 *)ds_power_cfg;
1665     req.buf_len   = sizeof(mlan_ds_power_cfg);
1666     req.bss_index = 0;
1667     req.req_id    = MLAN_IOCTL_POWER_CFG;
1668     req.action    = action;
1669 
1670     mlan_status rv = wlan_ops_sta_ioctl(mlan_adap, &req);
1671     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
1672     {
1673         return -WM_FAIL;
1674     }
1675 
1676     return WM_SUCCESS;
1677 }
1678 
wifi_set_tx_power(t_u32 power_level)1679 int wifi_set_tx_power(t_u32 power_level)
1680 {
1681     mlan_ds_power_cfg ds_power_cfg;
1682 
1683     (void)memset(&ds_power_cfg, 0x00, sizeof(mlan_ds_power_cfg));
1684 
1685     ds_power_cfg.sub_command                   = MLAN_OID_POWER_CFG;
1686     ds_power_cfg.param.power_cfg.is_power_auto = MFALSE;
1687     ds_power_cfg.param.power_cfg.power_level   = power_level;
1688 
1689     return wifi_send_tx_power_cfg_ioctl(MLAN_ACT_SET, &ds_power_cfg);
1690 }
1691 
wifi_set_tx_power_ext(uint32_t len,uint32_t * power_data)1692 int wifi_set_tx_power_ext(uint32_t len, uint32_t *power_data)
1693 {
1694     mlan_ds_power_cfg ds_power_cfg;
1695 
1696     (void)memset(&ds_power_cfg, 0x00, sizeof(mlan_ds_power_cfg));
1697 
1698     ds_power_cfg.sub_command         = MLAN_OID_POWER_CFG_EXT;
1699     ds_power_cfg.param.power_ext.len = len;
1700     (void)memcpy((void *)ds_power_cfg.param.power_ext.power_data, (const void *)power_data, len);
1701 
1702     return wifi_send_tx_power_cfg_ioctl(MLAN_ACT_SET, &ds_power_cfg);
1703 }
1704 
wifi_get_tx_power(t_u32 * power_level)1705 int wifi_get_tx_power(t_u32 *power_level)
1706 {
1707     int ret;
1708     mlan_ds_power_cfg ds_power_cfg;
1709     mlan_ioctl_req ioctl_req_pwr_cfg;
1710     (void)memset(&ds_power_cfg, 0x00, sizeof(mlan_ds_power_cfg));
1711     (void)memset(&ioctl_req_pwr_cfg, 0x00, sizeof(mlan_ioctl_req));
1712 
1713     ds_power_cfg.sub_command                   = MLAN_OID_POWER_CFG;
1714     ds_power_cfg.param.power_cfg.is_power_auto = MFALSE;
1715     wm_wifi.cmd_resp_ioctl                     = &ioctl_req_pwr_cfg;
1716     ioctl_req_pwr_cfg.pbuf                     = (t_u8 *)(&ds_power_cfg);
1717     ioctl_req_pwr_cfg.buf_len                  = sizeof(mlan_ds_power_cfg);
1718     ret                                        = wifi_send_tx_power_cfg_ioctl(MLAN_ACT_GET, &ds_power_cfg);
1719     wm_wifi.cmd_resp_ioctl                     = NULL;
1720 
1721     if (ret == WM_SUCCESS)
1722     {
1723         *power_level = ds_power_cfg.param.power_cfg.power_level;
1724     }
1725     return ret;
1726 }
1727 
wifi_send_tx_rate_cfg_ioctl(mlan_act_ioctl action,mlan_ds_rate * ds_rate_cfg,mlan_bss_type bss_type)1728 static int wifi_send_tx_rate_cfg_ioctl(mlan_act_ioctl action, mlan_ds_rate *ds_rate_cfg, mlan_bss_type bss_type)
1729 {
1730     /* fixme: check if this needs to go on heap */
1731     mlan_ioctl_req req;
1732 
1733     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
1734     req.pbuf      = (t_u8 *)ds_rate_cfg;
1735     req.buf_len   = sizeof(mlan_ds_rate);
1736     req.bss_index = bss_type;
1737     req.req_id    = MLAN_IOCTL_RATE;
1738     req.action    = action;
1739 
1740     mlan_status rv = MLAN_STATUS_SUCCESS;
1741     if (bss_type == MLAN_BSS_TYPE_UAP)
1742     {
1743         if (!is_uap_started())
1744         {
1745             wifi_e("uap isn't up\n\r");
1746             return -WM_FAIL;
1747         }
1748         rv = wlan_ops_uap_ioctl(mlan_adap, &req);
1749     }
1750     else if (bss_type == MLAN_BSS_TYPE_STA)
1751     {
1752         if (is_sta_connected())
1753         {
1754             rv = wlan_ops_sta_ioctl(mlan_adap, &req);
1755         }
1756         else
1757         {
1758             wifi_e("sta connection required before setting tx rate\n\r");
1759         }
1760     }
1761 
1762     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
1763     {
1764         return -WM_FAIL;
1765     }
1766 
1767     return WM_SUCCESS;
1768 }
1769 
wifi_set_txratecfg(wifi_ds_rate ds_rate,mlan_bss_type bss_type)1770 int wifi_set_txratecfg(wifi_ds_rate ds_rate, mlan_bss_type bss_type)
1771 {
1772     mlan_ds_rate ds_rate_cfg;
1773 
1774     if (ds_rate.sub_command != WIFI_DS_RATE_CFG)
1775     {
1776         return -WM_FAIL;
1777     }
1778 
1779     (void)memset(&ds_rate_cfg, 0x00, sizeof(mlan_ds_rate));
1780 #if CONFIG_AUTO_NULL_TX
1781     ds_rate_cfg.auto_null_fixrate_enable = 0xff;
1782 #endif
1783 
1784     ds_rate_cfg.sub_command = MLAN_OID_RATE_CFG;
1785     if (ds_rate.param.rate_cfg.rate_format == MLAN_RATE_FORMAT_AUTO)
1786     {
1787         ds_rate_cfg.param.rate_cfg.is_rate_auto = MTRUE;
1788     }
1789     else
1790     {
1791 #if CONFIG_AUTO_NULL_TX
1792         ds_rate_cfg.auto_null_fixrate_enable = ds_rate.auto_null_fixrate_enable;
1793 #endif
1794         ds_rate_cfg.param.rate_cfg.is_rate_auto = MFALSE;
1795         ds_rate_cfg.param.rate_cfg.rate_type    = MLAN_RATE_INDEX;
1796         ds_rate_cfg.param.rate_cfg.rate         = ds_rate.param.rate_cfg.rate_index;
1797         ds_rate_cfg.param.rate_cfg.rate_format  = ds_rate.param.rate_cfg.rate_format;
1798 #ifdef SD8801
1799         if (ds_rate.param.rate_cfg.rate_format == MLAN_RATE_FORMAT_HT)
1800             ds_rate_cfg.param.rate_cfg.rate += MLAN_RATE_INDEX_MCS0;
1801 #endif
1802 #if CONFIG_11AC
1803         if (ds_rate.param.rate_cfg.rate_format == MLAN_RATE_FORMAT_VHT
1804 #if CONFIG_11AX
1805             || ds_rate.param.rate_cfg.rate_format == MLAN_RATE_FORMAT_HE
1806 #endif
1807         )
1808             ds_rate_cfg.param.rate_cfg.nss = ds_rate.param.rate_cfg.nss;
1809 #endif
1810         if (ds_rate.param.rate_cfg.rate_setting != 0xffff)
1811             ds_rate_cfg.param.rate_cfg.rate_setting = ds_rate.param.rate_cfg.rate_setting & ~0x0C00;
1812         else
1813             ds_rate_cfg.param.rate_cfg.rate_setting = ds_rate.param.rate_cfg.rate_setting;
1814     }
1815     return wifi_send_tx_rate_cfg_ioctl(MLAN_ACT_SET, &ds_rate_cfg, bss_type);
1816 }
1817 
wifi_get_txratecfg(wifi_ds_rate * ds_rate,mlan_bss_type bss_type)1818 int wifi_get_txratecfg(wifi_ds_rate *ds_rate, mlan_bss_type bss_type)
1819 {
1820     int ret;
1821 
1822     mlan_ds_rate ds_rate_cfg;
1823 
1824     if (ds_rate->sub_command != WIFI_DS_RATE_CFG)
1825     {
1826         return -WM_FAIL;
1827     }
1828 
1829     (void)memset(&ds_rate_cfg, 0x00, sizeof(mlan_ds_rate));
1830 
1831     ds_rate_cfg.sub_command = MLAN_OID_RATE_CFG;
1832 
1833     wm_wifi.cmd_resp_ioctl = ds_rate;
1834 
1835     ret = wifi_send_tx_rate_cfg_ioctl(MLAN_ACT_GET, &ds_rate_cfg, bss_type);
1836 
1837     wm_wifi.cmd_resp_ioctl = NULL;
1838 
1839     return ret;
1840 }
1841 
wrapper_wlan_11d_support_is_enabled(void)1842 bool wrapper_wlan_11d_support_is_enabled(void)
1843 {
1844     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
1845 
1846     return wlan_11d_support_is_enabled(pmpriv);
1847 }
1848 
1849 /*
1850  * fixme: This function is temporarily present till the mlan transition is complete.
1851  */
wrapper_wifi_assoc(const unsigned char * bssid,int wlan_security,bool is_wpa_tkip,unsigned int owe_trans_mode,bool is_ft)1852 int wrapper_wifi_assoc(
1853     const unsigned char *bssid, int wlan_security, bool is_wpa_tkip, unsigned int owe_trans_mode, bool is_ft)
1854 {
1855 #if !CONFIG_11R
1856     (void)is_ft;
1857 #endif
1858     mlan_private *priv = (mlan_private *)mlan_adap->priv[0];
1859     t_u8 country_code[COUNTRY_CODE_LEN];
1860     /* BSSDescriptor_t *bssDesc = OSA_MemoryAllocate(sizeof(BSSDescriptor_t)); */
1861     /* if (!bssDesc) */
1862     /* 	return -WM_FAIL; */
1863     int idx = wlan_find_bssid_in_list(priv, (const unsigned char *)bssid, MLAN_BSS_MODE_NEGATIVE);
1864     if (idx == -1)
1865     {
1866         wifi_w("Could not find BSSID in mlan scan list");
1867         return -WM_FAIL;
1868     }
1869 
1870     /* Reset all state variables */
1871     (void)memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
1872     priv->wpa_ie_len                   = 0;
1873     priv->sec_info.wpa2_enabled        = false;
1874     priv->sec_info.wapi_enabled        = false;
1875     priv->sec_info.ewpa_enabled        = false;
1876     priv->sec_info.wpa_enabled         = false;
1877     priv->sec_info.authentication_mode = MLAN_AUTH_MODE_AUTO;
1878 
1879 #if CONFIG_11K
1880     if (priv->assoc_req_size != 0U)
1881     {
1882         /* Append the passed data to the end of
1883          * the genIeBuffer */
1884         __memcpy(priv->adapter, priv->gen_ie_buf, priv->assoc_req_buf, priv->assoc_req_size);
1885 
1886         /* Increment the stored buffer length by
1887          * the size passed */
1888         priv->gen_ie_buf_len = priv->assoc_req_size;
1889     }
1890 #endif
1891 
1892 #if CONFIG_11R
1893     priv->sec_info.is_ft = is_ft;
1894     if (is_ft)
1895     {
1896         priv->sec_info.authentication_mode = MLAN_AUTH_MODE_FT;
1897     }
1898 #endif
1899 
1900     BSSDescriptor_t *d = &mlan_adap->pscan_table[idx];
1901     /* fixme: This code is quite hacky and is present only because
1902      * security part is yet not fully integrated into mlan. This will
1903      * not be necessary after the integration is complete.
1904      */
1905 #if CONFIG_WPA2_ENTP
1906     if (d->prsn_ie && (wlan_security == WLAN_SECURITY_EAP_TLS || wlan_security == WLAN_SECURITY_EAP_PEAP_MSCHAPV2))
1907     {
1908         priv->sec_info.wpa2_enabled = true;
1909         if (d->rsn_ie_buff_len <= sizeof(priv->wpa_ie))
1910         {
1911             (void)memcpy(priv->wpa_ie, d->rsn_ie_buff, d->rsn_ie_buff_len);
1912             priv->wpa_ie_len = d->rsn_ie_buff_len;
1913         }
1914         else
1915         {
1916             wifi_e("Failed to copy RSN IE");
1917             return -WM_FAIL;
1918         }
1919     }
1920     else
1921 #endif
1922         if ((d->pwpa_ie != MNULL) && (d->prsn_ie != MNULL) && (wlan_security == WLAN_SECURITY_WPA_WPA2_MIXED))
1923     {
1924         priv->sec_info.is_wpa_tkip  = is_wpa_tkip;
1925         priv->sec_info.wpa2_enabled = true;
1926         if (d->rsn_ie_buff_len <= sizeof(priv->wpa_ie))
1927         {
1928             (void)memcpy((void *)priv->wpa_ie, (const void *)d->rsn_ie_buff, d->rsn_ie_buff_len);
1929             priv->wpa_ie_len = (t_u8)d->rsn_ie_buff_len;
1930         }
1931         else
1932         {
1933             wifi_e("Failed to copy RSN IE");
1934             return -WM_FAIL;
1935         }
1936     }
1937     else if ((d->pwpa_ie != MNULL) &&
1938              (wlan_security == WLAN_SECURITY_WPA || wlan_security == WLAN_SECURITY_WPA_WPA2_MIXED))
1939     {
1940         priv->sec_info.is_wpa_tkip = is_wpa_tkip;
1941         priv->sec_info.wpa_enabled = true;
1942         if (d->wpa_ie_buff_len <= sizeof(priv->wpa_ie))
1943         {
1944             (void)memcpy((void *)priv->wpa_ie, (const void *)d->wpa_ie_buff, d->wpa_ie_buff_len);
1945             priv->wpa_ie_len = (t_u8)d->wpa_ie_buff_len;
1946         }
1947         else
1948         {
1949             wifi_e("Failed to copy WPA IE");
1950             return -WM_FAIL;
1951         }
1952     }
1953     else if ((d->prsn_ie != MNULL) &&
1954 #if CONFIG_11R
1955              (!is_ft) &&
1956 #endif
1957              (wlan_security == WLAN_SECURITY_WPA2 || wlan_security == WLAN_SECURITY_WPA_WPA2_MIXED ||
1958 #if CONFIG_DRIVER_OWE
1959               owe_trans_mode == OWE_TRANS_MODE_OWE || wlan_security == WLAN_SECURITY_OWE_ONLY ||
1960 #endif
1961               wlan_security == WLAN_SECURITY_WPA3_SAE || wlan_security == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED))
1962     {
1963         if (wlan_security == WLAN_SECURITY_WPA2 || wlan_security == WLAN_SECURITY_WPA_WPA2_MIXED)
1964 
1965         {
1966             priv->sec_info.authentication_mode = MLAN_AUTH_MODE_OPEN;
1967         }
1968         priv->sec_info.is_wpa_tkip  = is_wpa_tkip;
1969         priv->sec_info.wpa2_enabled = true;
1970         if (d->rsn_ie_buff_len <= sizeof(priv->wpa_ie))
1971         {
1972             (void)memcpy((void *)priv->wpa_ie, (const void *)d->rsn_ie_buff, d->rsn_ie_buff_len);
1973             priv->wpa_ie_len = (t_u8)d->rsn_ie_buff_len;
1974         }
1975         else
1976         {
1977             wifi_e("Failed to copy RSN IE.");
1978             return -WM_FAIL;
1979         }
1980 #if CONFIG_11R
1981         if ((!is_ft) && (wlan_security == WLAN_SECURITY_WPA2 || wlan_security == WLAN_SECURITY_WPA3_SAE ||
1982                          wlan_security == WLAN_SECURITY_WPA2_WPA3_SAE_MIXED))
1983         {
1984             if (d->md_ie_buff_len <= sizeof(priv->md_ie))
1985             {
1986                 (void)memcpy((void *)priv->md_ie, (const void *)d->md_ie_buff, (size_t)d->md_ie_buff_len);
1987                 priv->md_ie_len = d->md_ie_buff_len;
1988             }
1989         }
1990 #endif
1991         /* In case of WPA3 SAE-PSK mixed mode AP, RSN IE processing sets the SAE AKM,
1992          * but if the configured security is WPA2 PSK then AKM must be of PSK
1993          * hence update the AKM to WPA2 PSK and reset the PMF capabilities
1994          */
1995     }
1996     else
1997     { /* Do Nothing */
1998     }
1999 
2000     if ((MNULL != d) && (*d->country_info.country_code) && (d->country_info.len > COUNTRY_CODE_LEN) &&
2001         (!priv->adapter->country_ie_ignore))
2002     {
2003         country_code[0] = d->country_info.country_code[0];
2004         country_code[1] = d->country_info.country_code[1];
2005         country_code[2] = ' ';
2006 
2007         wlan_set_country_code((const char *)country_code);
2008     }
2009 
2010     /* The original assoc cmd handling function of mlan sends
2011        additional two commands to the firmware; both
2012        HostCmd_CMD_802_11D_DOMAIN_INFO. In the current wmsdk wifi
2013        driver design we have only one command buffer. Thus, we cannot
2014        new cmd while the current cmd is being sent. We will change the
2015        default flow a little and send the 801.11D domain info commands
2016        first and skip that step later */
2017     if (wlan_11d_support_is_enabled(priv) && !mlan_adap->country_ie_ignore)
2018     {
2019         if (priv->support_11d != NULL)
2020         {
2021             if (priv->support_11d->wlan_11d_create_dnld_countryinfo_p(priv, BAND_B) != MLAN_STATUS_SUCCESS)
2022             {
2023                 PRINTM(MERROR, "Dnld_countryinfo_11d failed\n");
2024                 return -WM_FAIL;
2025             }
2026 
2027 #if CONFIG_5GHz_SUPPORT
2028             if (priv->support_11d->wlan_11d_create_dnld_countryinfo_p(priv, BAND_A) != MLAN_STATUS_SUCCESS)
2029             {
2030                 PRINTM(MERROR, "Dnld_countryinfo_11d failed\n");
2031                 return -WM_FAIL;
2032             }
2033 #endif
2034 
2035             if (priv->support_11d->wlan_11d_parse_dnld_countryinfo_p(priv, d) != MLAN_STATUS_SUCCESS)
2036             {
2037                 return -WM_FAIL;
2038             }
2039         }
2040     }
2041     /* fixme: check if this needs to go on heap */
2042     mlan_ds_bss bss;
2043     (void)memset(&bss, 0x00, sizeof(mlan_ds_bss));
2044     bss.sub_command          = MLAN_OID_BSS_START;
2045     bss.param.ssid_bssid.idx = (t_u32)idx + 1UL; /* + 1 req. by mlan */
2046     return wifi_send_bss_ioctl(&bss);
2047 }
2048 
2049 #if CONFIG_WPA_SUPP
wlan_set_wpa_ie_helper(mlan_private * priv,t_u8 * ie_data_ptr,t_u16 ie_len)2050 static mlan_status wlan_set_wpa_ie_helper(mlan_private *priv, t_u8 *ie_data_ptr, t_u16 ie_len)
2051 {
2052     ENTER();
2053 
2054     if (ie_len)
2055     {
2056         if (ie_len > sizeof(priv->wpa_ie))
2057         {
2058             PRINTM(MERROR, "failed to copy, WPA IE is too big\n");
2059             LEAVE();
2060             return MLAN_STATUS_FAILURE;
2061         }
2062         __memcpy(priv->adapter, priv->wpa_ie, ie_data_ptr, ie_len);
2063         priv->wpa_ie_len = (t_u8)ie_len;
2064         PRINTM(MIOCTL, "Set Wpa_ie_len=%d IE=%#x\n", priv->wpa_ie_len, priv->wpa_ie[0]);
2065         DBG_HEXDUMP(MCMD_D, "Wpa_ie", priv->wpa_ie, priv->wpa_ie_len);
2066         if (priv->wpa_ie[0] == WPA_IE)
2067         {
2068             priv->sec_info.wpa_enabled = MTRUE;
2069         }
2070         else if (priv->wpa_ie[0] == RSN_IE)
2071         {
2072             priv->sec_info.wpa2_enabled = MTRUE;
2073         }
2074         else
2075         {
2076             priv->sec_info.wpa_enabled  = MFALSE;
2077             priv->sec_info.wpa2_enabled = MFALSE;
2078         }
2079     }
2080     else
2081     {
2082         __memset(priv->adapter, priv->wpa_ie, 0, sizeof(priv->wpa_ie));
2083         priv->wpa_ie_len = 0;
2084         PRINTM(MINFO, "Reset Wpa_ie_len=%d IE=%#x\n", priv->wpa_ie_len, priv->wpa_ie[0]);
2085         priv->sec_info.wpa_enabled  = MFALSE;
2086         priv->sec_info.wpa2_enabled = MFALSE;
2087     }
2088 
2089     LEAVE();
2090     return MLAN_STATUS_SUCCESS;
2091 }
2092 
wlan_set_gen_ie_helper(mlan_private * priv,t_u8 * ie_data_ptr,t_u16 ie_len)2093 static mlan_status wlan_set_gen_ie_helper(mlan_private *priv, t_u8 *ie_data_ptr, t_u16 ie_len)
2094 {
2095     mlan_status ret = MLAN_STATUS_SUCCESS;
2096     IEEEtypes_VendorHeader_t *pvendor_ie;
2097     const t_u8 wpa_oui[] = {0x00, 0x50, 0xf2, 0x01};
2098 #if CONFIG_WPA_SUPP_WPS
2099     const t_u8 wps_oui[] = {0x00, 0x50, 0xf2, 0x04};
2100 #endif
2101 #if CONFIG_WPA_SUPP_WPS
2102     const t_u8 wpse_oui[] = {0x00, 0x50, 0xf2, 0x10};
2103 #endif
2104 #ifdef ENABLE_HOTSPOT
2105     const t_u8 osen_oui[] = {0x50, 0x6f, 0x9a, 0x12};
2106 #endif
2107     t_u8 i = 0, temp[12] = {0};
2108 
2109     ENTER();
2110 
2111     /* If the passed length is zero, reset the buffer */
2112     if (!ie_len)
2113     {
2114         priv->gen_ie_buf_len = 0;
2115 #if CONFIG_WPA_SUPP_WPS
2116         priv->wps.session_enable = MFALSE;
2117 #endif
2118         wlan_set_wpa_ie_helper(priv, MNULL, 0);
2119 #ifdef WAPI
2120         wlan_set_wapi_ie(priv, MNULL, 0);
2121 #endif
2122 #ifdef ENABLE_HOTSPOT
2123         wlan_set_osen_ie(priv, MNULL, 0);
2124 #endif
2125     }
2126     else if (!ie_data_ptr)
2127     {
2128         /* MNULL check */
2129         ret = MLAN_STATUS_FAILURE;
2130     }
2131     else
2132     {
2133         pvendor_ie = (IEEEtypes_VendorHeader_t *)ie_data_ptr;
2134         if (pvendor_ie->element_id == EXT_CAPABILITY)
2135         {
2136             __memcpy(priv->adapter, temp, &priv->ext_cap, sizeof(priv->ext_cap));
2137             for (i = 0; i < MIN(sizeof(priv->ext_cap), pvendor_ie->len); i++)
2138                 temp[i] |= ie_data_ptr[2 + i];
2139             __memcpy(priv->adapter, &priv->ext_cap, temp, sizeof(priv->ext_cap));
2140         }
2141         else
2142             /* Test to see if it is a WPA IE, if not, then it is a
2143                gen IE*/
2144             if (((pvendor_ie->element_id == WPA_IE) &&
2145                  (!__memcmp(priv->adapter, pvendor_ie->oui, wpa_oui, sizeof(pvendor_ie->oui))) &&
2146                  (pvendor_ie->oui_type == wpa_oui[3U])) ||
2147                 (pvendor_ie->element_id == RSN_IE))
2148             {
2149                 /* IE is a WPA/WPA2 IE so call set_wpa function */
2150                 ret = wlan_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
2151 #if CONFIG_WPA_SUPP_WPS
2152                 priv->wps.session_enable = MFALSE;
2153 #endif /* CONFIG_WPA_SUPP_WPS */
2154             }
2155             else
2156 #ifdef WAPI
2157                 if (pvendor_ie->element_id == WAPI_IE)
2158             {
2159                 /* IE is a WAPI IE so call set_wapi function */
2160                 ret = wlan_set_wapi_ie(priv, ie_data_ptr, ie_len);
2161             }
2162             else
2163 #endif /* WAPI */
2164 #ifdef ENABLE_HOTSPOT
2165                 if ((pvendor_ie->element_id == VENDOR_SPECIFIC_221) &&
2166                     (!__memcmp(priv->adapter, pvendor_ie->oui, osen_oui, sizeof(pvendor_ie->oui))) &&
2167                     (pvendor_ie->oui_type == osen_oui[3U]))
2168             {
2169                 /* IE is a OSEN IE so call set_osen function */
2170                 ret = wlan_set_osen_ie(priv, ie_data_ptr, ie_len);
2171             }
2172             else
2173 #endif
2174 #if CONFIG_WPA_SUPP_WPS
2175                 if (pvendor_ie->element_id == VENDOR_SPECIFIC_221 &&
2176                     (!__memcmp(priv->adapter, pvendor_ie->oui, wps_oui, sizeof(pvendor_ie->oui))) &&
2177                     (pvendor_ie->oui_type == wps_oui[3U]))
2178             {
2179                 /*
2180                  * Discard first two byte (Element ID and Length)
2181                  * because they are not needed in the case of setting
2182                  * WPS_IE
2183                  */
2184                 if (pvendor_ie->len > 4)
2185                 {
2186                     __memcpy(priv->adapter, (t_u8 *)&priv->wps.wps_ie, ie_data_ptr, ie_len);
2187 
2188                     HEXDUMP("wps_ie", (t_u8 *)&priv->wps.wps_ie, priv->wps.wps_ie.vend_hdr.len + 2);
2189                 }
2190                 else
2191                 {
2192                     /* Only wps oui exist, reset driver wps buffer
2193                      */
2194                     __memset(priv->adapter, (t_u8 *)&priv->wps.wps_ie, 0x00, sizeof(priv->wps.wps_ie));
2195                     PRINTM(MINFO, "wps_ie cleared\n");
2196                 }
2197             }
2198             else
2199 #endif
2200             {
2201                 /*
2202                  * Verify that the passed length is not larger than
2203                  * the available space remaining in the buffer
2204                  */
2205                 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len))
2206                 {
2207 #if CONFIG_WPA_SUPP_WPS
2208                     /* Test to see if it is a WPS IE, if so, enable
2209                      * wps session flag */
2210                     pvendor_ie = (IEEEtypes_VendorHeader_t *)ie_data_ptr;
2211                     if ((pvendor_ie->element_id == WPS_IE) &&
2212                         (!__memcmp(priv->adapter, pvendor_ie->oui, wps_oui, sizeof(pvendor_ie->oui))) &&
2213                         (pvendor_ie->oui_type == wps_oui[3U]))
2214                     {
2215                         priv->wps.session_enable = MTRUE;
2216                         PRINTM(MINFO, "WPS Session Enabled.\n");
2217                     }
2218 #endif
2219 
2220 #if CONFIG_WPA_SUPP_WPS
2221                     /* Test to see if it is a WPSE IE, if so,
2222                      * enable wps session flag */
2223                     pvendor_ie = (IEEEtypes_VendorHeader_t *)ie_data_ptr;
2224                     if ((pvendor_ie->element_id == WPS_IE) &&
2225                         (!__memcmp(priv->adapter, pvendor_ie->oui, wpse_oui, sizeof(pvendor_ie->oui))) &&
2226                         (pvendor_ie->oui_type == wpse_oui[3U]))
2227                     {
2228                         priv->wps.session_enable = MTRUE;
2229                         PRINTM(MINFO, "WPSE Session Enabled.\n");
2230                     }
2231 #endif
2232                     /* Append the passed data to the end of
2233                      * the genIeBuffer */
2234                     __memcpy(priv->adapter, priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr, ie_len);
2235 
2236                     /* Increment the stored buffer length by
2237                      * the size passed */
2238                     priv->gen_ie_buf_len += ie_len;
2239                 }
2240                 else
2241                 {
2242                     /* Passed data does not fit in the
2243                      * remaining buffer space */
2244                     ret = MLAN_STATUS_FAILURE;
2245                 }
2246             }
2247     }
2248 
2249     /* Return MLAN_STATUS_SUCCESS, or MLAN_STATUS_FAILURE for error case */
2250     LEAVE();
2251     return ret;
2252 }
2253 
wifi_set_ies_cfg(mlan_private * priv,t_u8 * ie,int ie_len)2254 static int wifi_set_ies_cfg(mlan_private *priv, t_u8 *ie, int ie_len)
2255 {
2256     int bytes_left     = ie_len;
2257     t_u8 *pcurrent_ptr = ie;
2258     int total_ie_len;
2259     t_u8 element_len;
2260     int ret = WM_SUCCESS;
2261     IEEEtypes_ElementId_e element_id;
2262 #if CONFIG_WPA_SUPP_WPS
2263     IEEEtypes_VendorSpecific_t *pvendor_ie;
2264     t_u8 wps_oui[] = {0x00, 0x50, 0xf2, 0x04};
2265 #endif
2266 #ifdef HOST_CCX
2267     t_u8 ccx_oui[] = {0x00, 0x40, 0x96, 0x03};
2268 #endif /* HOST_CCX */
2269 #ifdef ENABLE_HOTSPOT
2270     t_u8 hs20_oui[] = {0x50, 0x6f, 0x9a, 0x10};
2271 #endif /* ENABLE_HOTSPOT */
2272 
2273 #ifdef EASYMESH
2274     t_u8 multiap_oui[] = {0x50, 0x6f, 0x9a, 0x1b};
2275     t_u8 multiap_flag  = 0;
2276 #endif
2277 
2278     while (bytes_left >= 2)
2279     {
2280         element_id   = (IEEEtypes_ElementId_e)(*((t_u8 *)pcurrent_ptr));
2281         element_len  = *((t_u8 *)pcurrent_ptr + 1);
2282         total_ie_len = element_len + sizeof(IEEEtypes_Header_t);
2283         if (bytes_left < total_ie_len)
2284         {
2285             PRINTM(MERROR, "InterpretIE: Error in processing IE, bytes left < IE length\n");
2286             bytes_left = 0;
2287             continue;
2288         }
2289         switch (element_id)
2290         {
2291             case RSN_IE:
2292                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2293                 {
2294                     PRINTM(MERROR, "Fail to set RSN IE\n");
2295                     ret = -WM_FAIL;
2296                     goto done;
2297                 }
2298                 PRINTM(MIOCTL, "Set RSN IE\n");
2299                 break;
2300             case VENDOR_SPECIFIC_221:
2301 #if CONFIG_WPA_SUPP_WPS
2302                 pvendor_ie = (IEEEtypes_VendorSpecific_t *)pcurrent_ptr;
2303                 if (!memcmp(pvendor_ie->vend_hdr.oui, wps_oui, sizeof(pvendor_ie->vend_hdr.oui)) &&
2304                     (pvendor_ie->vend_hdr.oui_type == wps_oui[3]))
2305                 {
2306                     wifi_d("Enable WPS session\r\n");
2307                     priv->wps.session_enable = MTRUE;
2308                 }
2309 #endif
2310 
2311 #ifdef EASYMESH
2312                 if (!memcmp(pvendor_ie->vend_hdr.oui, multiap_oui, sizeof(pvendor_ie->vend_hdr.oui)) &&
2313                     (pvendor_ie->vend_hdr.oui_type == multiap_oui[3]))
2314                 {
2315                     multiap_flag = pvendor_ie->data[0];
2316                     if (MLAN_STATUS_SUCCESS != woal_multi_ap_cfg(priv, wait_option, multiap_flag))
2317                     {
2318                         PRINTM(MERROR, "%s: failed to configure multi ap\n", __func__);
2319                         ret = -WM_FAIL;
2320                         goto done;
2321                     }
2322                 }
2323 #endif
2324 
2325 #ifdef HOST_CCX
2326                 if (!memcmp(pvendor_ie->vend_hdr.oui, ccx_oui, sizeof(ccx_oui)))
2327                 {
2328                     PRINTM(MIOCTL, "CCX is enabled for this bss\n");
2329                     priv->is_ccx = 1;
2330                 }
2331 #endif
2332 #ifdef ENABLE_HOTSPOT
2333                 if (!memcmp(pvendor_ie->vend_hdr.oui, hs20_oui, sizeof(pvendor_ie->vend_hdr.oui)) &&
2334                     (pvendor_ie->vend_hdr.oui_type == hs20_oui[3]))
2335                 {
2336                     PRINTM(MIOCTL, "Hotspot2.0 is enabled for this bss\n");
2337                     if (MLAN_STATUS_SUCCESS !=
2338                         woal_set_hotspotcfg(priv, wait_option, (HOTSPOT_BY_SUPPLICANT | HOTSPOT_ENABLED)))
2339                     {
2340                         PRINTM(MERROR, "Fail to enable hotspot 2.0\n");
2341                         ret = -WM_FAIL;
2342                         goto done;
2343                     }
2344                 }
2345 #endif
2346                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2347                 {
2348                     PRINTM(MERROR, "Fail to Set VENDOR SPECIFIC IE\n");
2349                     ret = -WM_FAIL;
2350                     goto done;
2351                 }
2352 #if CONFIG_WPA_SUPP_WPS
2353                 wifi_d("Set VENDOR SPECIFIC IE, OUI: %02x:%02x:%02x:%02x\r\n", pvendor_ie->vend_hdr.oui[0],
2354                        pvendor_ie->vend_hdr.oui[1], pvendor_ie->vend_hdr.oui[2], pvendor_ie->vend_hdr.oui_type);
2355 #endif
2356                 break;
2357 #if CONFIG_11R
2358             case MOBILITY_DOMAIN:
2359                 (void)memcpy((void *)priv->md_ie, (const void *)pcurrent_ptr, (size_t)total_ie_len);
2360                 priv->md_ie_len = (size_t)total_ie_len;
2361                 wifi_d("Set MD IE\r\n");
2362                 break;
2363             case FAST_BSS_TRANSITION:
2364                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2365                 {
2366                     wifi_d(
2367                         "Fail to set"
2368                         "FAST_BSS_TRANSITION IE\r\n");
2369                     ret = -WM_FAIL;
2370                     goto done;
2371                 }
2372                 wifi_d("Set FAST_BSS_TRANSITION IE\r\n");
2373                 priv->sec_info.is_ft = true;
2374                 break;
2375             case RIC:
2376                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2377                 {
2378                     wifi_d(
2379                         "Fail to set"
2380                         "RESOURCE INFORMATION CONTAINER IE\r\n");
2381                     ret = -WM_FAIL;
2382                     goto done;
2383                 }
2384                 wifi_d("Set RESOURCE INFORMATION CONTAINER IE\r\n");
2385                 break;
2386 #endif
2387             case EXT_CAPABILITY:
2388                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2389                 {
2390                     PRINTM(MERROR, "Fail to set Extended Capabilites IE\n");
2391                     ret = -WM_FAIL;
2392                     goto done;
2393                 }
2394                 wifi_d("Set Extended Capabilities IE\n");
2395                 break;
2396 #if CONFIG_HOST_MLME
2397             case EXTENSION:
2398                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2399                 {
2400                     PRINTM(MERROR, "Fail to set Extension IE\n");
2401                     ret = -WM_FAIL;
2402                     goto done;
2403                 }
2404                 PRINTM(MIOCTL, "Set Extension IE\n");
2405                 break;
2406             case FRAGMENT:
2407                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2408                 {
2409                     PRINTM(MERROR, "Fail to set Fragmented IE\n");
2410                     ret = -WM_FAIL;
2411                     goto done;
2412                 }
2413                 PRINTM(MIOCTL, "Set Fragmented IE\n");
2414                 break;
2415 #endif
2416             default:
2417                 if (MLAN_STATUS_SUCCESS != wlan_set_gen_ie_helper(priv, pcurrent_ptr, total_ie_len))
2418                 {
2419                     PRINTM(MERROR, "Fail to set GEN IE\n");
2420                     ret = -WM_FAIL;
2421                     goto done;
2422                 }
2423                 PRINTM(MIOCTL, "Set GEN IE\n");
2424                 break;
2425         }
2426         pcurrent_ptr += element_len + 2;
2427         /* Need to account for IE ID and IE Len */
2428         bytes_left -= (element_len + 2);
2429     }
2430 done:
2431     return ret;
2432 }
2433 
wifi_set_scan_ies(void * ie,size_t ie_len)2434 int wifi_set_scan_ies(void *ie, size_t ie_len)
2435 {
2436     mlan_private *priv = (mlan_private *)mlan_adap->priv[0];
2437     int ret            = -WM_FAIL;
2438 #if (CONFIG_WPA_SUPP) && (CONFIG_WPA_SUPP_WPS)
2439     priv->wps.session_enable = MFALSE;
2440 #endif
2441 
2442     /* Reset the generic IE buffer */
2443     priv->gen_ie_buf_len = 0;
2444 
2445     ret = wifi_set_ies_cfg(priv, (t_u8 *)ie, ie_len);
2446 
2447     if (ret != MLAN_STATUS_SUCCESS)
2448     {
2449         wifi_w("Could not set the IEs");
2450         return (int)-WM_FAIL;
2451     }
2452 
2453     return WM_SUCCESS;
2454 }
2455 
2456 #if CONFIG_WPA_SUPP
2457 #if CONFIG_WPA_SUPP_WPS
wifi_assocreq_wps_ie_cfg(mlan_private * priv)2458 static int wifi_assocreq_wps_ie_cfg(mlan_private *priv)
2459 {
2460     int ret       = WM_SUCCESS;
2461     int wpsie_len = 0;
2462     u8 *wps_buf   = NULL;
2463     wpsie_len     = sizeof(IEEEtypes_Header_t) + priv->wps.wps_ie.vend_hdr.len;
2464     wps_buf       = (t_u8 *)OSA_MemoryAllocate(wpsie_len);
2465     (void)memset(wps_buf, 0, wpsie_len);
2466     (void)__memcpy(priv->adapter, wps_buf, (t_u8 *)&priv->wps.wps_ie, wpsie_len);
2467     priv->wps.wps_mgmt_bitmap_index =
2468         wifi_set_mgmt_ie2(priv->bss_type, MGMT_MASK_ASSOC_REQ | MGMT_MASK_REASSOC_REQ, (void *)wps_buf, wpsie_len);
2469     if (-WM_FAIL != priv->wps.wps_mgmt_bitmap_index)
2470         ret = WM_SUCCESS;
2471     else
2472         ret = -WM_FAIL;
2473     OSA_MemoryFree(wps_buf);
2474     return ret;
2475 }
2476 #endif
2477 #endif
2478 
wifi_nxp_send_assoc(nxp_wifi_assoc_info_t * assoc_info)2479 int wifi_nxp_send_assoc(nxp_wifi_assoc_info_t *assoc_info)
2480 {
2481     int ret                    = -WM_FAIL;
2482     const unsigned char *bssid = (const unsigned char *)&assoc_info->bssid;
2483 
2484     mlan_private *priv = (mlan_private *)mlan_adap->priv[0];
2485     t_u8 country_code[COUNTRY_CODE_LEN];
2486 
2487     if (priv->auth_alg == WLAN_AUTH_SAE)
2488     {
2489         priv->auth_flag = HOST_MLME_AUTH_DONE;
2490     }
2491 
2492     wifi_remain_on_channel(false, 0, 0);
2493 
2494     if (priv->auth_flag && !(priv->auth_flag & HOST_MLME_AUTH_DONE))
2495     {
2496         return -WM_FAIL;
2497     }
2498 
2499     int idx = wlan_find_bssid_in_list(priv, (const unsigned char *)bssid, MLAN_BSS_MODE_NEGATIVE);
2500     if (idx == -1)
2501     {
2502         wifi_w("Could not find BSSID in mlan scan list");
2503         return ret;
2504     }
2505 
2506     BSSDescriptor_t *d = &mlan_adap->pscan_table[idx];
2507 
2508 #if CONFIG_HOST_MLME
2509     priv->curr_bss_params.host_mlme = 1;
2510 #endif
2511 
2512     __memcpy(priv->adapter, &priv->curr_bss_params.prev_bssid, assoc_info->prev_bssid, MLAN_MAC_ADDR_LENGTH);
2513 
2514     /* Reset all state variables */
2515     (void)memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie));
2516     priv->wpa_ie_len                   = 0;
2517     priv->sec_info.wpa2_enabled        = MFALSE;
2518     priv->sec_info.wapi_enabled        = MFALSE;
2519     priv->sec_info.ewpa_enabled        = MFALSE;
2520     priv->sec_info.wpa_enabled         = MFALSE;
2521     priv->sec_info.authentication_mode = MLAN_AUTH_MODE_AUTO;
2522 
2523     priv->sec_info.is_wpa_tkip = MFALSE;
2524 #if CONFIG_11R
2525     priv->sec_info.is_ft = MFALSE;
2526     priv->md_ie_len      = 0;
2527 #endif
2528 
2529     /* Reset the generic IE buffer */
2530     priv->gen_ie_buf_len = 0;
2531 
2532 #if CONFIG_WPA_SUPP_WPS
2533     priv->wps.session_enable = MFALSE;
2534 #endif
2535 
2536     ret = wifi_set_ies_cfg(priv, (t_u8 *)assoc_info->wpa_ie.ie, assoc_info->wpa_ie.ie_len);
2537 
2538     if (ret != WM_SUCCESS)
2539     {
2540         wifi_w("Could not set the IEs");
2541         return -WM_FAIL;
2542     }
2543 #if CONFIG_WPA_SUPP
2544 #if CONFIG_WPA_SUPP_WPS
2545     if (priv->wps.wps_mgmt_bitmap_index != -1)
2546     {
2547         ret = wifi_clear_mgmt_ie2(priv->bss_type, priv->wps.wps_mgmt_bitmap_index);
2548         if (ret != WM_SUCCESS)
2549         {
2550             wifi_e("Clear Assoc req IE failed");
2551             return -WM_FAIL;
2552         }
2553         priv->wps.wps_mgmt_bitmap_index = -1;
2554     }
2555     else if (priv->wps.session_enable == MTRUE)
2556     {
2557         ret = wifi_assocreq_wps_ie_cfg(priv);
2558         if (ret != WM_SUCCESS)
2559         {
2560             wifi_w("add WPS_IE to assocreq fail");
2561             return -WM_FAIL;
2562         }
2563     }
2564 #endif
2565 #endif
2566 
2567     (void)wifi_set_rx_mgmt_indication(MLAN_BSS_TYPE_STA, WIFI_MGMT_DEAUTH | WIFI_MGMT_DIASSOC | WIFI_MGMT_ACTION);
2568 
2569 #if CONFIG_11R
2570     if (priv->sec_info.is_ft)
2571     {
2572         priv->sec_info.authentication_mode = MLAN_AUTH_MODE_FT;
2573 #if CONFIG_GTK_REKEY_OFFLOAD
2574         (void)__memset(pmadapter, &priv->gtk_rekey, 0, sizeof(priv->gtk_rekey));
2575 #endif
2576     }
2577 #endif
2578 
2579     if ((MNULL != d) && (*d->country_info.country_code) && (d->country_info.len > COUNTRY_CODE_LEN) &&
2580         (!priv->adapter->country_ie_ignore))
2581     {
2582         country_code[0] = d->country_info.country_code[0];
2583         country_code[1] = d->country_info.country_code[1];
2584         country_code[2] = ' ';
2585 
2586         wlan_set_country_code((const char *)country_code);
2587     }
2588 
2589     /* The original assoc cmd handling function of mlan sends
2590        additional two commands to the firmware; both
2591        HostCmd_CMD_802_11D_DOMAIN_INFO. In the current wmsdk wifi
2592        driver design we have only one command buffer. Thus, we cannot
2593        new cmd while the current cmd is being sent. We will change the
2594        default flow a little and send the 801.11D domain info commands
2595        first and skip that step later */
2596     if (wlan_11d_support_is_enabled(priv) && !mlan_adap->country_ie_ignore)
2597     {
2598         if (priv->support_11d != NULL)
2599         {
2600             if (priv->support_11d->wlan_11d_create_dnld_countryinfo_p(priv, BAND_B) != MLAN_STATUS_SUCCESS)
2601             {
2602                 PRINTM(MERROR, "Dnld_countryinfo_11d failed\n");
2603                 return -WM_FAIL;
2604             }
2605 
2606 #if CONFIG_5GHz_SUPPORT
2607             if (priv->support_11d->wlan_11d_create_dnld_countryinfo_p(priv, BAND_A) != MLAN_STATUS_SUCCESS)
2608             {
2609                 PRINTM(MERROR, "Dnld_countryinfo_11d failed\n");
2610                 return -WM_FAIL;
2611             }
2612 #endif
2613 
2614             if (priv->support_11d->wlan_11d_parse_dnld_countryinfo_p(priv, d) != MLAN_STATUS_SUCCESS)
2615             {
2616                 return -WM_FAIL;
2617             }
2618         }
2619     }
2620     /* fixme: check if this needs to go on heap */
2621     mlan_ds_bss bss;
2622     (void)memset(&bss, 0x00, sizeof(mlan_ds_bss));
2623     bss.sub_command          = MLAN_OID_BSS_START;
2624     bss.param.ssid_bssid.idx = (t_u32)idx + 1UL; /* + 1 req. by mlan */
2625     return wifi_send_bss_ioctl(&bss);
2626 }
2627 
2628 #define MAX_NUM_CHANNEL_2G  (14)
2629 #if CONFIG_5GHz_SUPPORT
2630 #define MAX_NUM_CHANNEL_5G  (28)
2631 #endif
2632 
2633 static struct wifi_nxp_event_get_wiphy wiphy;
2634 
wifi_nxp_get_wiphy(const unsigned int bss_type)2635 int wifi_nxp_get_wiphy(const unsigned int bss_type)
2636 {
2637     int status = -WM_FAIL;
2638 #if CONFIG_11AX
2639     t_u8 bandwidth = wifi_uap_get_bandwidth();
2640 #endif
2641 
2642     wiphy.sband[0].wifi_nxp_n_channels = MAX_NUM_CHANNEL_2G;
2643 
2644     wifi_setup_channel_info(&wiphy.sband[0].channels, wiphy.sband[0].wifi_nxp_n_channels,
2645                             BAND_2GHZ);
2646 
2647     wiphy.sband[0].wifi_nxp_n_bitrates = 12;
2648 
2649     wiphy.sband[0].bitrates[0].wifi_nxp_bitrate = 10;
2650     wiphy.sband[0].bitrates[1].wifi_nxp_bitrate = 20;
2651     wiphy.sband[0].bitrates[2].wifi_nxp_bitrate = 55;
2652     wiphy.sband[0].bitrates[3].wifi_nxp_bitrate = 110;
2653     wiphy.sband[0].bitrates[4].wifi_nxp_bitrate = 60;
2654     wiphy.sband[0].bitrates[5].wifi_nxp_bitrate = 90;
2655     wiphy.sband[0].bitrates[6].wifi_nxp_bitrate = 120;
2656     wiphy.sband[0].bitrates[7].wifi_nxp_bitrate = 180;
2657     wiphy.sband[0].bitrates[8].wifi_nxp_bitrate = 240;
2658     wiphy.sband[0].bitrates[9].wifi_nxp_bitrate = 360;
2659     wiphy.sband[0].bitrates[10].wifi_nxp_bitrate = 480;
2660     wiphy.sband[0].bitrates[11].wifi_nxp_bitrate = 540;
2661 
2662     wiphy.sband[0].ht_cap.wifi_nxp_ht_supported = 1;
2663 
2664     status = wifi_setup_ht_cap(&wiphy.sband[0].ht_cap.wifi_nxp_cap, (t_u8 *)(&wiphy.sband[0].ht_cap.mcs),
2665                                &wiphy.sband[0].ht_cap.wifi_nxp_ampdu_factor, 0);
2666     if (status != WM_SUCCESS)
2667     {
2668         wifi_e("%s: wifi nxp set 2G infra ht cap failed", __func__);
2669         return -WM_FAIL;
2670     }
2671 
2672 #if CONFIG_11AC
2673     wiphy.sband[0].vht_cap.wifi_nxp_vht_supported = 1;
2674 
2675     status = wifi_setup_vht_cap((t_u32 *)&wiphy.sband[0].vht_cap.wifi_nxp_cap,
2676                                 (t_u8 *)(&wiphy.sband[0].vht_cap.vht_mcs), 0);
2677     if (status != WM_SUCCESS)
2678     {
2679         wifi_e("%s: wifi nxp set 2G infra vht cap failed", __func__);
2680         return -WM_FAIL;
2681     }
2682 #endif
2683 
2684 #if CONFIG_11AX
2685     status = wifi_setup_he_cap((nxp_wifi_he_capabilities *)&wiphy.sband[0].he_cap, 0);
2686     if (status != WM_SUCCESS)
2687     {
2688         wifi_e("%s: wifi nxp set 2G infra he cap failed", __func__);
2689         return -WM_FAIL;
2690     }
2691 
2692     if (bandwidth == BANDWIDTH_20MHZ)
2693     {
2694         wiphy.sband[0].he_cap.phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] = 0;
2695     }
2696 #endif
2697 
2698     wiphy.sband[0].band = 0;
2699 
2700 #if CONFIG_5GHz_SUPPORT
2701     if (!ISSUPP_NO5G(mlan_adap->fw_cap_ext))
2702     {
2703         wiphy.sband[1].wifi_nxp_n_channels = MAX_NUM_CHANNEL_5G;
2704 
2705         wifi_setup_channel_info(&wiphy.sband[1].channels, wiphy.sband[1].wifi_nxp_n_channels,
2706                             BAND_5GHZ);
2707 
2708         wiphy.sband[1].wifi_nxp_n_bitrates = 8;
2709 
2710         wiphy.sband[1].bitrates[0].wifi_nxp_bitrate = 60;
2711         wiphy.sband[1].bitrates[1].wifi_nxp_bitrate = 90;
2712         wiphy.sband[1].bitrates[2].wifi_nxp_bitrate = 120;
2713         wiphy.sband[1].bitrates[3].wifi_nxp_bitrate = 180;
2714         wiphy.sband[1].bitrates[4].wifi_nxp_bitrate = 240;
2715         wiphy.sband[1].bitrates[5].wifi_nxp_bitrate = 360;
2716         wiphy.sband[1].bitrates[6].wifi_nxp_bitrate = 480;
2717         wiphy.sband[1].bitrates[7].wifi_nxp_bitrate = 540;
2718 
2719         wiphy.sband[1].ht_cap.wifi_nxp_ht_supported = 1;
2720 
2721         status = wifi_setup_ht_cap(&wiphy.sband[1].ht_cap.wifi_nxp_cap, (t_u8 *)(&wiphy.sband[1].ht_cap.mcs),
2722                 &wiphy.sband[1].ht_cap.wifi_nxp_ampdu_factor, 1);
2723         if (status != WM_SUCCESS)
2724         {
2725             wifi_e("%s: wifi nxp set 2G infra ht cap failed", __func__);
2726             return -WM_FAIL;
2727         }
2728 
2729 #if CONFIG_11AC
2730         wiphy.sband[1].vht_cap.wifi_nxp_vht_supported = 1;
2731 
2732         status = wifi_setup_vht_cap((t_u32 *)&wiphy.sband[1].vht_cap.wifi_nxp_cap,
2733                 (t_u8 *)(&wiphy.sband[1].vht_cap.vht_mcs), 1);
2734         if (status != WM_SUCCESS)
2735         {
2736             wifi_e("%s: wifi nxp set 2G infra vht cap failed", __func__);
2737             return -WM_FAIL;
2738         }
2739 #endif
2740 
2741 #if CONFIG_11AX
2742         status = wifi_setup_he_cap((nxp_wifi_he_capabilities *)&wiphy.sband[1].he_cap, 1);
2743         if (status != WM_SUCCESS)
2744         {
2745             wifi_e("%s: wifi nxp set 2G infra he cap failed", __func__);
2746             return -WM_FAIL;
2747         }
2748 
2749         if (bandwidth == BANDWIDTH_20MHZ)
2750         {
2751             wiphy.sband[1].he_cap.phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] = 0;
2752         }
2753 #endif
2754 
2755         wiphy.sband[1].band = 1;
2756 
2757         if (status != WM_SUCCESS)
2758         {
2759             wifi_e("%s: wifi nxp set 5G infra ht cap failed", __func__);
2760             return -WM_FAIL;
2761         }
2762     }
2763 #endif
2764 
2765     if (wm_wifi.supp_if_callbk_fns->get_wiphy_callbk_fn)
2766     {
2767         if (bss_type == BSS_TYPE_STA)
2768         {
2769             wm_wifi.supp_if_callbk_fns->get_wiphy_callbk_fn(wm_wifi.if_priv, &wiphy, sizeof(wiphy));
2770         }
2771 #if CONFIG_WPA_SUPP_AP
2772         else if (bss_type == BSS_TYPE_UAP)
2773         {
2774             wm_wifi.supp_if_callbk_fns->get_wiphy_callbk_fn(wm_wifi.hapd_if_priv, &wiphy, sizeof(wiphy));
2775         }
2776 #endif
2777     }
2778 
2779     return WM_SUCCESS;
2780 }
2781 
wifi_nxp_get_conn_info(uint16_t * beacon_interval,uint8_t * dtim_period,bool * twt_capable)2782 int wifi_nxp_get_conn_info(uint16_t *beacon_interval, uint8_t *dtim_period, bool *twt_capable)
2783 {
2784     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2785 
2786     *beacon_interval = pmpriv->curr_bss_params.bss_descriptor.beacon_period;
2787     *dtim_period = pmpriv->curr_bss_params.bss_descriptor.dtim_period;
2788 #if CONFIG_11AX_TWT
2789     *twt_capable = wlan_check_ap_11ax_twt_supported(&(pmpriv->curr_bss_params.bss_descriptor)) ? true : false;
2790 #else
2791     *twt_capable = false;
2792 #endif
2793 
2794     return WM_SUCCESS;
2795 }
2796 #endif
2797 
compute_rssi_values(HostCmd_DS_802_11_RSSI_INFO_RSP * prssi_info_rsp,wifi_rssi_info_t * rssi_info)2798 static void compute_rssi_values(HostCmd_DS_802_11_RSSI_INFO_RSP *prssi_info_rsp, wifi_rssi_info_t *rssi_info)
2799 {
2800     g_rssi        = prssi_info_rsp->bcn_rssi_last;
2801     g_bcn_nf_last = prssi_info_rsp->bcn_nf_last;
2802 
2803     rssi_info->bcn_rssi_last  = prssi_info_rsp->bcn_rssi_last;
2804     rssi_info->bcn_rssi_avg   = prssi_info_rsp->bcn_rssi_avg;
2805     rssi_info->data_rssi_last = prssi_info_rsp->data_rssi_last;
2806     rssi_info->data_rssi_avg  = prssi_info_rsp->data_rssi_avg;
2807 
2808     rssi_info->bcn_snr_last  = CAL_SNR(prssi_info_rsp->bcn_rssi_last, prssi_info_rsp->bcn_nf_last);
2809     rssi_info->bcn_snr_avg   = CAL_SNR(prssi_info_rsp->bcn_rssi_avg, prssi_info_rsp->bcn_nf_avg);
2810     rssi_info->data_snr_last = CAL_SNR(prssi_info_rsp->data_rssi_last, prssi_info_rsp->data_nf_last);
2811     rssi_info->data_snr_avg  = CAL_SNR(prssi_info_rsp->data_rssi_avg, prssi_info_rsp->data_nf_avg);
2812 
2813     rssi_info->bcn_nf_last  = prssi_info_rsp->bcn_nf_last;
2814     rssi_info->bcn_nf_avg   = prssi_info_rsp->bcn_nf_avg;
2815     rssi_info->data_nf_last = prssi_info_rsp->data_nf_last;
2816     rssi_info->data_nf_avg  = prssi_info_rsp->data_nf_avg;
2817 }
2818 /* Function of copy hostcmd response to buffers set in wm_wifi structure */
wifi_set_hostcmd_resp(const HostCmd_DS_COMMAND * resp)2819 static void wifi_set_hostcmd_resp(const HostCmd_DS_COMMAND *resp)
2820 {
2821     if (wm_wifi.cmd_resp_priv == MNULL)
2822     {
2823         return;
2824     }
2825     /* reset is_hostcmd to 0, so that other commands can be processed */
2826     wm_wifi.hostcmd_cfg.is_hostcmd = false;
2827 
2828     hostcmd_cfg_t *hcmd_cfg = (hostcmd_cfg_t *)wm_wifi.cmd_resp_priv;
2829 
2830     *hcmd_cfg->reqd_resp_len = resp->size;
2831     /* Copy if response buffer is suffcient to hold response data */
2832     if (hcmd_cfg->resp_buf_len >= resp->size)
2833     {
2834         (void)memcpy((void *)hcmd_cfg->resp_buf, (const void *)resp, resp->size);
2835     }
2836     /* Initialize user pointer to NULL*/
2837     wm_wifi.cmd_resp_priv = NULL;
2838 }
2839 
load_bss_list(const HostCmd_DS_STA_LIST * sta_list)2840 static void load_bss_list(const HostCmd_DS_STA_LIST *sta_list)
2841 {
2842     if (wm_wifi.cmd_resp_priv == MNULL)
2843     {
2844         return;
2845     }
2846 
2847     /* Initialize user pointer */
2848     *(wifi_sta_list_t **)wm_wifi.cmd_resp_priv = NULL;
2849 
2850     t_u16 c = sta_list->sta_count;
2851     if (c > MAX_NUM_CLIENTS)
2852     {
2853         wifi_w("Too many clients: %d", c);
2854         return;
2855     }
2856 
2857 #if !CONFIG_MEM_POOLS
2858     wifi_sta_list_t *sl = OSA_MemoryAllocate(sizeof(wifi_sta_list_t) + c * sizeof(wifi_sta_info_t));
2859 #else
2860     wifi_sta_list_t *sl                 = OSA_MemoryPoolAllocate(buf_256_MemoryPool);
2861 #endif
2862 
2863     if (sl == MNULL)
2864     {
2865         return;
2866     }
2867 
2868     sl->count            = c;
2869     wifi_sta_info_t *sta = (wifi_sta_info_t *)(void *)(((t_u8 *)&sl->count) + sizeof(int));
2870 
2871     int i;
2872     MrvlIEtypes_sta_info_t *si = (MrvlIEtypes_sta_info_t *)(((t_u8 *)&sta_list->sta_count) + sizeof(t_u16));
2873     for (i = 0; i < c && i < MAX_NUM_CLIENTS; i++)
2874     {
2875         if ((si->rssi & 0x80) != 0)
2876         {
2877             // coverity[overrun-local:SUPPRESS]
2878             sta[i].rssi = -(256 - si->rssi);
2879         }
2880         else
2881         {
2882             sta[i].rssi = si->rssi;
2883         }
2884 
2885         (void)memcpy(sta[i].mac, si->mac_address, MLAN_MAC_ADDR_LENGTH);
2886         sta[i].power_mgmt_status = si->power_mfg_status;
2887         si = (MrvlIEtypes_sta_info_t *)((t_u8 *)si + (si->header.len + sizeof(MrvlIEtypesHeader_t)));
2888 
2889         wifi_d("RSSI: 0x%x %d dbm", sta[i].rssi, sta[i].rssi);
2890     }
2891 
2892     /* Note: Caller needs to free this */
2893     *(wifi_sta_list_t **)wm_wifi.cmd_resp_priv = sl;
2894 
2895     wm_wifi.cmd_resp_status = WM_SUCCESS;
2896     wm_wifi.cmd_resp_priv   = NULL;
2897 }
2898 
load_ver_ext(HostCmd_DS_COMMAND * resp)2899 static void load_ver_ext(HostCmd_DS_COMMAND *resp)
2900 {
2901     if (wm_wifi.cmd_resp_priv == MNULL)
2902     {
2903         return;
2904     }
2905 
2906     HostCmd_DS_VERSION_EXT *ver_ext     = &resp->params.verext;
2907     wifi_fw_version_ext_t *user_ver_ext = (wifi_fw_version_ext_t *)wm_wifi.cmd_resp_priv;
2908 
2909     (void)memcpy((void *)user_ver_ext->version_str, (const void *)ver_ext->version_str, resp->size - 10U);
2910 
2911     wm_wifi.cmd_resp_status = WM_SUCCESS;
2912     wm_wifi.cmd_resp_priv   = NULL;
2913 }
2914 
wifi_process_cmd_response(HostCmd_DS_COMMAND * resp)2915 int wifi_process_cmd_response(HostCmd_DS_COMMAND *resp)
2916 {
2917     mlan_private *pmpriv          = (mlan_private *)mlan_adap->priv[0];
2918     mlan_status rv                = MLAN_STATUS_SUCCESS;
2919     enum wifi_event_reason result = WIFI_EVENT_REASON_FAILURE;
2920     t_u8 *sta_addr;
2921 
2922     t_u16 command = (resp->command & HostCmd_CMD_ID_MASK);
2923 #ifdef RW610
2924     last_resp_rcvd = command;
2925 #endif
2926 
2927 #if !CONFIG_WIFI_PS_DEBUG
2928     if ((resp->command & 0x0fffU) != HostCmd_CMD_802_11_PS_MODE_ENH)
2929     {
2930         wcmdr_d("CMD_RESP - : 0x%x, result %d, len %d, seqno 0x%x", resp->command, resp->result, resp->size,
2931                 resp->seq_num);
2932     }
2933 #else
2934     wcmdr_d("CMD_RESP - : 0x%x, result %d, len %d, seqno 0x%x", resp->command, resp->result, resp->size, resp->seq_num);
2935 #endif
2936 
2937 #if CONFIG_FW_VDLL
2938     mlan_adap->vdll_in_progress = MFALSE;
2939 #endif
2940 
2941     mlan_bss_type bss_type = (mlan_bss_type)HostCmd_GET_BSS_TYPE(resp->seq_num);
2942 
2943     if (bss_type == MLAN_BSS_TYPE_UAP)
2944     {
2945         pmpriv = (mlan_private *)mlan_adap->priv[1];
2946     }
2947     else
2948     {
2949         pmpriv = (mlan_private *)mlan_adap->priv[0];
2950     }
2951 
2952     if (mlan_adap->ps_state == PS_STATE_SLEEP)
2953     {
2954         OSA_RWLockWriteUnlock(&sleep_rwlock);
2955         mlan_adap->ps_state = PS_STATE_AWAKE;
2956     }
2957 
2958     /* Check if the command is a user issued host command */
2959     if (wm_wifi.hostcmd_cfg.is_hostcmd == true)
2960     {
2961         wifi_set_hostcmd_resp(resp);
2962         rv = MLAN_STATUS_SUCCESS;
2963     }
2964     else
2965     {
2966         switch (command)
2967         {
2968             case HOST_CMD_SMART_MODE_CFG:
2969             {
2970 #if CONFIG_WIFI_EXTRA_DEBUG
2971                 HostCmd_DS_SYS_CONFIG *sys_config_cmd = (HostCmd_DS_SYS_CONFIG *)&resp->params.sys_config;
2972 
2973                 if (sys_config_cmd->action == HostCmd_ACT_GEN_GET)
2974                     dump_hex(resp, resp->size);
2975 #endif
2976             }
2977             break;
2978             case HOST_CMD_APCMD_BSS_STOP:
2979             {
2980                 if (resp->result == HostCmd_RESULT_OK)
2981                 {
2982                     pmpriv->uap_bss_started = MFALSE;
2983                     bss_type                = (mlan_bss_type)HostCmd_GET_BSS_TYPE(resp->seq_num);
2984                     if ((bss_type == MLAN_BSS_TYPE_UAP)
2985 #if CONFIG_P2P
2986                         || (bss_type == MLAN_BSS_TYPE_WIFIDIRECT)
2987 #endif /* CONFIG_P2P*/
2988                     )
2989                     {
2990                         wm_wifi.cmd_resp_status = WM_SUCCESS;
2991                         wlan_clean_txrx(pmpriv);
2992                         (void)wifi_event_completion(WIFI_EVENT_UAP_STOPPED, WIFI_EVENT_REASON_SUCCESS, NULL);
2993                     }
2994                 }
2995                 else
2996                 {
2997                     wm_wifi.cmd_resp_status = -WM_FAIL;
2998                 }
2999             }
3000             break;
3001             case HostCMD_APCMD_ACS_SCAN:
3002 #ifdef SD8801
3003             case HostCmd_MMH_ACS_CFG:
3004 #endif
3005             {
3006 #if CONFIG_WPA_SUPP
3007 #ifdef SD8801
3008                 HostCmd_DS_ACS_CONFIG *acs_scan = (HostCmd_DS_ACS_CONFIG *)&resp->params.acs_scan;
3009 #else
3010                 HostCMD_DS_APCMD_ACS_SCAN *acs_scan = (HostCMD_DS_APCMD_ACS_SCAN *)&resp->params.acs_scan;
3011 #endif
3012 #endif
3013                 if (resp->result == HostCmd_RESULT_OK)
3014                 {
3015                     bss_type = (mlan_bss_type)HostCmd_GET_BSS_TYPE(resp->seq_num);
3016                     if ((bss_type == MLAN_BSS_TYPE_UAP)
3017 #if CONFIG_P2P
3018                         || (bss_type == MLAN_BSS_TYPE_WIFIDIRECT)
3019 #endif /* CONFIG_P2P*/
3020                     )
3021                     {
3022 #if CONFIG_WPA_SUPP
3023                         nxp_wifi_acs_params acs_params;
3024                         wm_wifi.cmd_resp_status = WM_SUCCESS;
3025 #ifndef SD8801
3026                         wifi_d("ACS scan done: bandcfg=%x, channel=%d\r\n", acs_scan->bandcfg, acs_scan->chan);
3027 #else
3028                         wifi_d("ACS scan done: bandcfg=0, channel=%d\r\n", acs_scan->chan);
3029 #endif
3030 
3031                         memset(&acs_params, 0, sizeof(nxp_wifi_acs_params));
3032 
3033 #if defined(SD8801) || defined(RW610)
3034 #ifdef SD8801
3035                         acs_params.pri_freq = channel_to_frequency(acs_scan->chan, 0);
3036                         acs_params.hw_mode  = 1;
3037 #else
3038                         acs_params.pri_freq = channel_to_frequency(acs_scan->chan, acs_scan->bandcfg.chanBand);
3039                         acs_params.hw_mode  = acs_scan->bandcfg.chanBand == 0 ? 1 : 2;
3040 #endif
3041                         acs_params.ch_width = 20;
3042 #else
3043                         t_u8 chan_offset;
3044                         acs_params.pri_freq = channel_to_frequency(acs_scan->chan, acs_scan->bandcfg.chanBand);
3045 
3046                         chan_offset = wifi_get_sec_channel_offset(acs_scan->chan);
3047                         if (chan_offset == SEC_CHAN_ABOVE)
3048                         {
3049                             acs_params.sec_freq = acs_params.pri_freq + 20;
3050                         }
3051                         else if (chan_offset == SEC_CHAN_BELOW)
3052                         {
3053                             acs_params.sec_freq = acs_params.pri_freq - 20;
3054                         }
3055                         else
3056                         {
3057                             acs_params.sec_freq = acs_params.pri_freq;
3058                         }
3059 
3060 #if CONFIG_5GHz_SUPPORT
3061                         if (acs_scan->chan > MAX_CHANNELS_BG)
3062                         {
3063 #if CONFIG_11AC
3064                             if (wm_wifi.bandwidth == BANDWIDTH_80MHZ)
3065                             {
3066                                 acs_params.ch_width = 80;
3067                             }
3068 #endif
3069                         }
3070 #endif
3071                         if (wm_wifi.bandwidth == BANDWIDTH_40MHZ)
3072                         {
3073                             acs_params.ch_width = 40;
3074                         }
3075                         else
3076                         {
3077                             acs_params.sec_freq = 0;
3078                             acs_params.ch_width = 20;
3079                         }
3080                         acs_params.hw_mode = acs_scan->bandcfg.chanBand == 0 ? 1 : 2;
3081 #endif
3082                         if (wm_wifi.supp_if_callbk_fns->acs_channel_sel_callbk_fn)
3083                         {
3084                             wm_wifi.supp_if_callbk_fns->acs_channel_sel_callbk_fn(wm_wifi.hapd_if_priv, &acs_params);
3085                         }
3086 #endif
3087                     }
3088                 }
3089                 else
3090                 {
3091                     wm_wifi.cmd_resp_status = -WM_FAIL;
3092                 }
3093             }
3094             break;
3095             case HOST_CMD_APCMD_BSS_START:
3096             {
3097                 if (resp->result == HostCmd_RESULT_OK)
3098                 {
3099                     bss_type = (mlan_bss_type)HostCmd_GET_BSS_TYPE(resp->seq_num);
3100                     if ((bss_type == MLAN_BSS_TYPE_UAP)
3101 #if CONFIG_P2P
3102                         || (bss_type == MLAN_BSS_TYPE_WIFIDIRECT)
3103 #endif /* CONFIG_P2P*/
3104                     )
3105                     {
3106 #if CONFIG_WMM_UAPSD
3107                         /* disable uapsd for uAP */
3108                         mlan_adap->pps_uapsd_mode = MFALSE;
3109                         mlan_adap->tx_lock_flag   = MFALSE;
3110 #endif
3111                         wm_wifi.cmd_resp_status = WM_SUCCESS;
3112                         (void)wifi_event_completion(WIFI_EVENT_UAP_STARTED, WIFI_EVENT_REASON_SUCCESS, NULL);
3113                     }
3114                 }
3115                 else
3116                 {
3117                     wm_wifi.cmd_resp_status = -WM_FAIL;
3118                 }
3119             }
3120             break;
3121             case HOST_CMD_APCMD_STA_LIST:
3122             {
3123                 if (resp->result == HostCmd_RESULT_OK)
3124                 {
3125                     const HostCmd_DS_STA_LIST *sta_list = &resp->params.sta_list;
3126                     load_bss_list(sta_list);
3127                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3128                 }
3129                 else
3130                 {
3131                     wm_wifi.cmd_resp_status = -WM_FAIL;
3132                 }
3133             }
3134             break;
3135             case HostCmd_CMD_802_11_TX_RATE_QUERY:
3136             {
3137                 if (resp->result == HostCmd_RESULT_OK)
3138                 {
3139                     int bss_type = HostCmd_GET_BSS_TYPE(resp->seq_num);
3140                     if (bss_type == MLAN_BSS_TYPE_UAP)
3141                         pmpriv = (mlan_private *)mlan_adap->priv[1];
3142                     if (wm_wifi.cmd_resp_priv != NULL)
3143                     {
3144                         wifi_ds_rate *ds_rate = (wifi_ds_rate *)wm_wifi.cmd_resp_priv;
3145                         rv                    = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, ds_rate);
3146                         if (rv != MLAN_STATUS_SUCCESS)
3147                         {
3148                             wm_wifi.cmd_resp_status = -WM_FAIL;
3149                         }
3150                         else
3151                         {
3152                             wm_wifi.cmd_resp_status = WM_SUCCESS;
3153                         }
3154                     }
3155                 }
3156                 else
3157                 {
3158                     wm_wifi.cmd_resp_status = -WM_FAIL;
3159                 }
3160             }
3161             break;
3162             case HostCmd_CMD_TBTT_OFFSET:
3163             {
3164                 HostCmd_DS_TBTT_OFFSET *tbtt_offset;
3165                 tbtt_offset = (HostCmd_DS_TBTT_OFFSET *)&resp->params.tbtt_offset;
3166                 if (resp->result == HostCmd_RESULT_OK)
3167                 {
3168                     if (tbtt_offset->action == HostCmd_ACT_GEN_GET)
3169                     {
3170                         if (wm_wifi.cmd_resp_priv != NULL)
3171                         {
3172                             wifi_tbtt_offset_t *tbtt_offset_t = (wifi_tbtt_offset_t *)wm_wifi.cmd_resp_priv;
3173 
3174                             tbtt_offset_t->min_tbtt_offset = tbtt_offset->min_tbtt_offset;
3175                             tbtt_offset_t->max_tbtt_offset = tbtt_offset->max_tbtt_offset;
3176                             tbtt_offset_t->avg_tbtt_offset = tbtt_offset->avg_tbtt_offset;
3177                         }
3178                     }
3179                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3180                 }
3181                 else
3182                 {
3183                     wm_wifi.cmd_resp_status = -WM_FAIL;
3184                 }
3185             }
3186             break;
3187             case HostCmd_CMD_MEF_CFG:
3188             {
3189                 if (resp->result == HostCmd_RESULT_OK)
3190                 {
3191                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3192                 }
3193                 else
3194                 {
3195                     wm_wifi.cmd_resp_status = -WM_FAIL;
3196                 }
3197             }
3198             break;
3199             case HostCmd_CMD_802_11_RF_TX_POWER:
3200             {
3201                 const HostCmd_DS_802_11_RF_TX_POWER *txp = &resp->params.txp;
3202                 if (txp->action == HostCmd_ACT_GEN_GET)
3203                 {
3204                     if (wm_wifi.cmd_resp_priv != NULL)
3205                     {
3206                         wifi_tx_power_t *tx_p = (wifi_tx_power_t *)wm_wifi.cmd_resp_priv;
3207                         tx_p->current_level   = txp->current_level;
3208                         tx_p->max_power       = txp->max_power;
3209                         tx_p->min_power       = txp->min_power;
3210                     }
3211                 }
3212                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3213             }
3214             break;
3215             case HostCmd_CMD_802_11D_DOMAIN_INFO:
3216             {
3217                 HostCmd_DS_802_11D_DOMAIN_INFO *domain_info =
3218                     (HostCmd_DS_802_11D_DOMAIN_INFO *)&resp->params.domain_info;
3219                 if (resp->result == HostCmd_RESULT_OK)
3220                 {
3221                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3222                 }
3223                 else if (domain_info->action == HostCmd_ACT_SPC_SET)
3224                 {
3225                     /*FW not supported yet, always set command response status success for action code
3226                      * HostCmd_ACT_SPC_SET*/
3227                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3228                 }
3229                 else
3230                 {
3231                     wm_wifi.cmd_resp_status = -WM_FAIL;
3232                 }
3233             }
3234             break;
3235             case HostCmd_CMD_GET_HW_SPEC:
3236                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
3237                 if (rv != MLAN_STATUS_SUCCESS)
3238                 {
3239                     return -WM_FAIL;
3240                 }
3241 
3242                 (void)wifi_event_completion(WIFI_EVENT_GET_HW_SPEC, WIFI_EVENT_REASON_SUCCESS, NULL);
3243                 break;
3244 #if CONFIG_11K_OFFLOAD
3245             case HostCmd_CMD_OFFLOAD_FEATURE_CONTROL:
3246                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
3247                 if (rv != MLAN_STATUS_SUCCESS)
3248                 {
3249                     wm_wifi.cmd_resp_status = -WM_FAIL;
3250                     return -WM_FAIL;
3251                 }
3252                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3253                 break;
3254 #endif
3255             case HostCmd_CMD_802_11_SCAN:
3256                 if (resp->result != HostCmd_RESULT_OK)
3257                 {
3258                     if (resp->result == HostCmd_RESULT_BUSY)
3259                     {
3260                         wifi_w("ED MAC: Scan temporary aborted, due to noisy environment");
3261                     }
3262                     else
3263                     {
3264                         wifi_w("Scan temporary failure");
3265                     }
3266                     /*
3267                      * Abort the split scan. The firmware has returned
3268                      * scan failure.
3269                      */
3270                     wlan_abort_split_scan();
3271                     wifi_user_scan_config_cleanup();
3272 
3273                     (void)wifi_event_completion(WIFI_EVENT_SCAN_RESULT, WIFI_EVENT_REASON_FAILURE, NULL);
3274                     break;
3275                 }
3276 
3277                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
3278                 if (rv != MLAN_STATUS_SUCCESS)
3279                 {
3280                     wifi_user_scan_config_cleanup();
3281                     return -WM_FAIL;
3282                 }
3283 
3284                 if (is_split_scan_complete())
3285                 {
3286                     wifi_d("Split scan complete");
3287                     wifi_user_scan_config_cleanup();
3288 
3289                     (void)wifi_event_completion(WIFI_EVENT_SCAN_RESULT, WIFI_EVENT_REASON_SUCCESS, NULL);
3290                 }
3291                 break;
3292 #if CONFIG_EXT_SCAN_SUPPORT
3293             case HostCmd_CMD_802_11_SCAN_EXT:
3294                 if (resp->result != 0)
3295                 {
3296                     wifi_w("Scan temporary failure");
3297                     /*
3298                      * Abort the split scan. The firmware has returned
3299                      * scan failure.
3300                      */
3301                     wlan_abort_split_scan();
3302                     wifi_user_scan_config_cleanup();
3303 
3304                     (void)wifi_event_completion(WIFI_EVENT_SCAN_RESULT, WIFI_EVENT_REASON_FAILURE, NULL);
3305                 }
3306                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
3307                 if (rv != MLAN_STATUS_SUCCESS)
3308                 {
3309                     return -WM_FAIL;
3310                 }
3311                 break;
3312 #endif
3313             case HostCmd_CMD_802_11_DEAUTHENTICATE:
3314                 (void)wlan_ret_802_11_deauthenticate(pmpriv, resp, NULL);
3315                 (void)wifi_event_completion(WIFI_EVENT_DEAUTHENTICATION, WIFI_EVENT_REASON_SUCCESS, NULL);
3316                 break;
3317             case HostCmd_CMD_802_11_HS_CFG_ENH:
3318 #if CONFIG_HOST_SLEEP
3319                 wifi_process_hs_cfg_resp((t_u8 *)resp);
3320 #endif
3321                 break;
3322             case HostCmd_CMD_802_11_PS_MODE_ENH:
3323             {
3324 #if !CONFIG_MEM_POOLS
3325                 t_u16 *ps_action_p = (t_u16 *)OSA_MemoryAllocate(sizeof(t_u16));
3326 #else
3327                 t_u16 *ps_action_p = (t_u16 *)OSA_MemoryPoolAllocate(buf_32_MemoryPool);
3328 #endif
3329                 if (ps_action_p != NULL)
3330                 {
3331                     result = wifi_process_ps_enh_response((t_u8 *)resp, &ps_event, ps_action_p);
3332 
3333                     if (ps_event != (t_u16)WIFI_EVENT_PS_INVALID)
3334                     {
3335 #if CONFIG_WNM_PS
3336                         if (ps_event == WIFI_EVENT_WNM_PS)
3337                         {
3338                             if (wifi_event_completion((enum wifi_event)ps_event, result,
3339                                                       (void *)((t_u32)ps_action_p)) != WM_SUCCESS)
3340                             {
3341 #if !CONFIG_MEM_POOLS
3342                                 OSA_MemoryFree((void *)ps_action_p);
3343 #else
3344                                 OSA_MemoryPoolFree(buf_32_MemoryPool, ps_action_p);
3345 #endif
3346                             }
3347                         }
3348                         else
3349 #endif
3350                         {
3351                             if (wifi_event_completion((enum wifi_event)ps_event, result, (void *)ps_action_p) !=
3352                                 WM_SUCCESS)
3353                             {
3354 #if !CONFIG_MEM_POOLS
3355                                 OSA_MemoryFree((void *)ps_action_p);
3356 #else
3357                                 OSA_MemoryPoolFree(buf_32_MemoryPool, ps_action_p);
3358 #endif
3359                             }
3360                             else
3361                             {
3362                                 /*do nothing*/
3363                             }
3364                         }
3365                     }
3366                     else
3367                     {
3368 #if !CONFIG_MEM_POOLS
3369                         OSA_MemoryFree((void *)ps_action_p);
3370 #else
3371                         OSA_MemoryPoolFree(buf_32_MemoryPool, ps_action_p);
3372 #endif
3373                     }
3374                 }
3375             }
3376             break;
3377 #if 0
3378             case HostCmd_CMD_SUPPLICANT_PMK:
3379                 (void)wifi_event_completion(WIFI_EVENT_SUPPLICANT_PMK,
3380                         WIFI_EVENT_REASON_SUCCESS,
3381                         resp);
3382                 break;
3383 #endif
3384 #if CONFIG_WMM_UAPSD
3385             case HostCmd_CMD_802_11_SLEEP_PERIOD:
3386                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_priv);
3387                 if (rv != MLAN_STATUS_SUCCESS)
3388                     return -WM_FAIL;
3389                 break;
3390 #endif
3391             case HostCmd_CMD_802_11_RF_CHANNEL:
3392             {
3393                 const HostCmd_DS_802_11_RF_CHANNEL *ch = &resp->params.rf_channel;
3394                 if (ch->action == HostCmd_ACT_GEN_GET)
3395                 {
3396                     if (wm_wifi.cmd_resp_priv != NULL)
3397                     {
3398                         wifi_rf_channel_t *rf_c = (wifi_rf_channel_t *)wm_wifi.cmd_resp_priv;
3399                         rf_c->current_channel   = ch->current_channel;
3400                         rf_c->rf_type           = ch->rf_type;
3401                     }
3402                 }
3403                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3404                 /* Is this required */
3405                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
3406             }
3407             break;
3408 #ifdef SD8801
3409             case HostCmd_CMD_ROBUST_COEX:
3410             {
3411                 const HostCmd_DS_ExtBLECoex_Config_t *coex = &resp->params.ext_ble_coex_cfg;
3412                 if (coex->action == HostCmd_ACT_GEN_GET)
3413                 {
3414                     if (wm_wifi.cmd_resp_priv != NULL)
3415                     {
3416                         wifi_ext_coex_stats_t *stats = (wifi_ext_coex_stats_t *)wm_wifi.cmd_resp_priv;
3417                         stats->ext_radio_req_count   = coex->coex_cfg_data.EXT_RADIO_REQ_count;
3418                         stats->ext_radio_pri_count   = coex->coex_cfg_data.EXT_RADIO_PRI_count;
3419                         stats->wlan_grant_count      = coex->coex_cfg_data.WLAN_GRANT_count;
3420                     }
3421                 }
3422                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3423             }
3424             break;
3425 #endif
3426 #if CONFIG_11N
3427             case HostCmd_CMD_11N_CFG:
3428                 rv = wlan_ret_11n_cfg(pmpriv, resp, NULL);
3429                 break;
3430             case HostCmd_CMD_11N_ADDBA_REQ:
3431                 (void)do_wlan_ret_11n_addba_req(pmpriv, resp);
3432                 break;
3433             case HostCmd_CMD_11N_DELBA:
3434                 (void)do_wlan_ret_11n_delba(pmpriv, resp);
3435                 break;
3436             case HostCmd_CMD_11N_ADDBA_RSP:
3437                 (void)do_wlan_ret_11n_addba_resp(resp);
3438                 break;
3439 #if CONFIG_AMSDU_IN_AMPDU
3440             case HostCmd_CMD_AMSDU_AGGR_CTRL:
3441                 rv = wlan_ret_amsdu_aggr_ctrl(pmpriv, resp, NULL);
3442                 break;
3443 #endif
3444 #endif /* CONFIG_11N */
3445             case HostCmd_CMD_MAC_MULTICAST_ADR:
3446                 break;
3447             case HostCmd_CMD_802_11_ASSOCIATE:
3448             {
3449                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
3450 #if !CONFIG_WPA_SUPP
3451                 if (rv != MLAN_STATUS_SUCCESS)
3452                 {
3453                     (void)wifi_event_completion(WIFI_EVENT_ASSOCIATION, WIFI_EVENT_REASON_FAILURE, NULL);
3454                     return -WM_FAIL;
3455                 }
3456 #endif
3457 
3458 #if CONFIG_WPA_SUPP
3459                 nxp_wifi_assoc_event_mlme_t *assoc_resp = &wm_wifi.assoc_resp;
3460                 memset(assoc_resp, 0, sizeof(nxp_wifi_assoc_event_mlme_t));
3461 
3462                 IEEEtypes_AssocRsp_t *passoc_rsp1 = (IEEEtypes_AssocRsp_t *)(void *)&resp->params;
3463 
3464                 IEEEtypes_AssocRsp_t *passoc_rsp =
3465                     (IEEEtypes_AssocRsp_t *)((t_u8 *)(&resp->params) + sizeof(IEEEtypes_MgmtHdr_t));
3466 
3467 #if CONFIG_11R
3468                 pmpriv->ft_roam = MFALSE;
3469 #endif
3470                 assoc_resp->frame.frame_len = resp->size - S_DS_GEN;
3471                 if (assoc_resp->frame.frame_len > (int)sizeof(assoc_resp->frame.frame))
3472                 {
3473                     wifi_e("Assocate response payload length (%d) overs the max length(%d), dropping it",
3474                            assoc_resp->frame.frame_len, sizeof(assoc_resp->frame.frame));
3475                     assoc_resp->frame.frame_len = 0;
3476                     result                      = WIFI_EVENT_REASON_FAILURE;
3477                     goto assoc_resp_ret;
3478                 }
3479                 // coverity[overrun-buffer-arg:SUPPRESS]
3480                 memcpy(assoc_resp->frame.frame, passoc_rsp1, assoc_resp->frame.frame_len);
3481 
3482                 if (pmpriv->assoc_req_size && (pmpriv->assoc_req_size <= (int)sizeof(assoc_resp->req_ie)))
3483                 {
3484                     assoc_resp->req_ie_len = pmpriv->assoc_req_size;
3485                     // coverity[overrun-buffer-arg:SUPPRESS]
3486                     memcpy(assoc_resp->req_ie, pmpriv->assoc_req_buf, assoc_resp->req_ie_len);
3487                 }
3488                 if (wm_wifi.supp_if_callbk_fns->assoc_resp_callbk_fn)
3489                 {
3490                     pmpriv->auth_flag = 0;
3491 
3492                     wm_wifi.supp_if_callbk_fns->assoc_resp_callbk_fn(wm_wifi.if_priv, assoc_resp,
3493                                                                      sizeof(nxp_wifi_assoc_event_mlme_t));
3494                 }
3495 #else
3496                 IEEEtypes_AssocRsp_t *passoc_rsp = (IEEEtypes_AssocRsp_t *)(void *)&resp->params;
3497 #endif
3498                 if (passoc_rsp->status_code == 0U)
3499                 {
3500                     result = WIFI_EVENT_REASON_SUCCESS;
3501                 }
3502                 else
3503                 {
3504 #if CONFIG_WIFI_EXTRA_DEBUG
3505                     wifi_w("Assoc failed: Status: %d\n\r", passoc_rsp->status_code);
3506                     wifi_show_assoc_fail_reason(passoc_rsp->status_code);
3507 #endif
3508                     /* Since we have failed assoc attempt clear this */
3509                     pmpriv->media_connected = MFALSE;
3510                 }
3511                 /** Clear BSS blacklist if association is successful */
3512                 if (result == WIFI_EVENT_REASON_SUCCESS)
3513                 {
3514                     (void)memset(&pmpriv->adapter->blacklist_bss.bssids, 0x0,
3515                                  sizeof(pmpriv->adapter->blacklist_bss.bssids));
3516                     pmpriv->adapter->blacklist_bss.num_bssid = 0;
3517                 }
3518 #if CONFIG_WPA_SUPP
3519             assoc_resp_ret:
3520 #endif
3521                 (void)wifi_event_completion(WIFI_EVENT_ASSOCIATION, result, NULL);
3522             }
3523             break;
3524             case HostCmd_CMD_802_11_MAC_ADDRESS:
3525             {
3526                 HostCmd_DS_802_11_MAC_ADDRESS *pmac_addr = &resp->params.mac_addr;
3527                 int ret                                  = -WM_FAIL;
3528 #if !CONFIG_MEM_POOLS
3529                 sta_addr = OSA_MemoryAllocate(MLAN_MAC_ADDR_LENGTH);
3530 #else
3531                 sta_addr                         = OSA_MemoryPoolAllocate(buf_32_MemoryPool);
3532 #endif
3533                 if (sta_addr == MNULL)
3534                 {
3535                     wifi_w("No mem. Cannot process MAC address command");
3536                     break;
3537                 }
3538                 (void)memcpy((void *)sta_addr, (const void *)((uint8_t *)&pmac_addr->mac_addr), MLAN_MAC_ADDR_LENGTH);
3539                 if (bss_type == MLAN_BSS_TYPE_STA)
3540                 {
3541                     (void)memcpy(dev_mac_addr, sta_addr, MLAN_MAC_ADDR_LENGTH);
3542                     ret = wifi_event_completion(WIFI_EVENT_STA_MAC_ADDR_CONFIG, WIFI_EVENT_REASON_SUCCESS, sta_addr);
3543                 }
3544                 else if (bss_type == MLAN_BSS_TYPE_UAP)
3545                 {
3546                     (void)memcpy(dev_mac_addr_uap, sta_addr, MLAN_MAC_ADDR_LENGTH);
3547                     ret = wifi_event_completion(WIFI_EVENT_UAP_MAC_ADDR_CONFIG, WIFI_EVENT_REASON_SUCCESS, sta_addr);
3548                 }
3549 
3550                 if (ret != WM_SUCCESS)
3551                 {
3552                     /* If fail to send message on queue, free allocated memory ! */
3553 #if !CONFIG_MEM_POOLS
3554                     OSA_MemoryFree((void *)sta_addr);
3555 #else
3556                     OSA_MemoryPoolFree(buf_32_MemoryPool, sta_addr);
3557 #endif
3558                 }
3559             }
3560             break;
3561             case HostCmd_CMD_802_11_KEY_MATERIAL:
3562                 break;
3563             case HostCmd_CMD_MAC_REG_ACCESS:
3564             {
3565                 HostCmd_DS_MAC_REG_ACCESS *reg;
3566                 reg = (HostCmd_DS_MAC_REG_ACCESS *)&resp->params.mac_reg;
3567                 if (reg->action == HostCmd_ACT_GEN_GET)
3568                 {
3569                     if (wm_wifi.cmd_resp_priv != NULL)
3570                     {
3571                         uint32_t *mac_reg = (uint32_t *)wm_wifi.cmd_resp_priv;
3572                         *mac_reg          = reg->value;
3573                     }
3574                 }
3575                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3576             }
3577             break;
3578             case HostCmd_CMD_BBP_REG_ACCESS:
3579             {
3580                 HostCmd_DS_BBP_REG_ACCESS *reg;
3581                 reg = (HostCmd_DS_BBP_REG_ACCESS *)&resp->params.bbp_reg;
3582                 if (reg->action == HostCmd_ACT_GEN_GET)
3583                 {
3584                     if (wm_wifi.cmd_resp_priv != NULL)
3585                     {
3586                         uint32_t *bbp_reg = (uint32_t *)wm_wifi.cmd_resp_priv;
3587                         *bbp_reg          = reg->value;
3588                     }
3589                 }
3590                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3591             }
3592             break;
3593             case HostCmd_CMD_RF_REG_ACCESS:
3594             {
3595                 HostCmd_DS_RF_REG_ACCESS *reg;
3596                 reg = (HostCmd_DS_RF_REG_ACCESS *)&resp->params.rf_reg;
3597                 if (reg->action == HostCmd_ACT_GEN_GET)
3598                 {
3599                     if (wm_wifi.cmd_resp_priv != NULL)
3600                     {
3601                         uint32_t *rf_reg = (uint32_t *)wm_wifi.cmd_resp_priv;
3602                         *rf_reg          = reg->value;
3603                     }
3604                 }
3605                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3606             }
3607             break;
3608             case HostCmd_CMD_CAU_REG_ACCESS:
3609             {
3610                 HostCmd_DS_RF_REG_ACCESS *reg;
3611                 reg = (HostCmd_DS_RF_REG_ACCESS *)&resp->params.rf_reg;
3612                 if (reg->action == HostCmd_ACT_GEN_GET)
3613                 {
3614                     if (wm_wifi.cmd_resp_priv != NULL)
3615                     {
3616                         uint32_t *cau_reg = (uint32_t *)wm_wifi.cmd_resp_priv;
3617                         *cau_reg          = reg->value;
3618                     }
3619                 }
3620                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3621             }
3622             break;
3623             case HostCmd_CMD_802_11_EEPROM_ACCESS:
3624             {
3625                 HostCmd_DS_802_11_EEPROM_ACCESS *eeprom;
3626                 eeprom = (HostCmd_DS_802_11_EEPROM_ACCESS *)&resp->params.eeprom;
3627                 if (wm_wifi.cmd_resp_priv != NULL)
3628                 {
3629                     uint8_t *buf = (uint8_t *)wm_wifi.cmd_resp_priv;
3630                     (void)memcpy((void *)buf, (const void *)&eeprom->value, eeprom->byte_count);
3631                 }
3632                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3633             }
3634             break;
3635             case HostCmd_CMD_MEM_ACCESS:
3636             {
3637                 HostCmd_DS_MEM_ACCESS *mem;
3638                 mem = (HostCmd_DS_MEM_ACCESS *)&resp->params.mem;
3639                 if (mem->action == HostCmd_ACT_GEN_GET)
3640                 {
3641                     if (wm_wifi.cmd_resp_priv != NULL)
3642                     {
3643                         uint32_t *mem_value = (uint32_t *)wm_wifi.cmd_resp_priv;
3644                         *mem_value          = mem->value;
3645                     }
3646                 }
3647                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3648             }
3649             break;
3650             case HostCmd_CMD_MGMT_IE_LIST:
3651             {
3652                 HostCmd_DS_MGMT_IE_LIST_CFG *ie_list_cfg;
3653                 ie_list_cfg = (HostCmd_DS_MGMT_IE_LIST_CFG *)&resp->params.mgmt_ie_list;
3654                 if (wm_wifi.cmd_resp_priv != NULL)
3655                 {
3656                     uint8_t *buf = (uint8_t *)wm_wifi.cmd_resp_priv;
3657                     (void)memcpy((void *)buf, (const void *)(&ie_list_cfg->ds_mgmt_ie.ie_data_list[0]),
3658                                  ie_list_cfg->ds_mgmt_ie.len);
3659                 }
3660                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3661             }
3662             break;
3663             case HostCmd_CMD_VERSION_EXT:
3664                 load_ver_ext(resp);
3665                 break;
3666             case HostCmd_CMD_802_11_RF_ANTENNA:
3667             {
3668 #ifndef STREAM_2X2
3669                 HostCmd_DS_802_11_RF_ANTENNA *rf_antenna_ctrl;
3670                 rf_antenna_ctrl = (HostCmd_DS_802_11_RF_ANTENNA *)&resp->params.antenna;
3671                 if (resp->result == HostCmd_RESULT_OK)
3672                 {
3673                     if (rf_antenna_ctrl->action == HostCmd_ACT_GET_BOTH)
3674                     {
3675                         if (wm_wifi.cmd_resp_priv != NULL)
3676                         {
3677                             wifi_antcfg_t *antcfg      = (wifi_antcfg_t *)wm_wifi.cmd_resp_priv;
3678                             *(antcfg->ant_mode)        = rf_antenna_ctrl->antenna_mode;
3679                             *(antcfg->evaluate_time)   = rf_antenna_ctrl->evaluate_time;
3680                             *(antcfg->current_antenna) = rf_antenna_ctrl->current_antenna;
3681 #ifdef RW610
3682                             *(antcfg->evaluate_mode) = rf_antenna_ctrl->evaluate_mode;
3683 #endif
3684                         }
3685                     }
3686                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3687                 }
3688                 else
3689                 {
3690                     wm_wifi.cmd_resp_status = -WM_FAIL;
3691                 }
3692 #endif
3693             }
3694             break;
3695             case HostCmd_CMD_CW_MODE_CTRL:
3696             {
3697                 HostCmd_DS_CW_MODE_CTRL *cw_mode_ctrl;
3698                 cw_mode_ctrl = (HostCmd_DS_CW_MODE_CTRL *)&resp->params.cwmode;
3699                 if (resp->result == HostCmd_RESULT_OK)
3700                 {
3701                     if (cw_mode_ctrl->action == HostCmd_ACT_GEN_GET)
3702                     {
3703                         if (wm_wifi.cmd_resp_priv != NULL)
3704                         {
3705                             wifi_cw_mode_ctrl_t *cwmode_ctrl = (wifi_cw_mode_ctrl_t *)wm_wifi.cmd_resp_priv;
3706                             cwmode_ctrl->mode                = cw_mode_ctrl->mode;
3707                             cwmode_ctrl->channel             = cw_mode_ctrl->channel;
3708                             cwmode_ctrl->chanInfo            = cw_mode_ctrl->chanInfo;
3709                             cwmode_ctrl->txPower             = wlan_cpu_to_le16(cw_mode_ctrl->txPower);
3710                             cwmode_ctrl->rateInfo            = wlan_cpu_to_le32(cw_mode_ctrl->rateInfo);
3711                             cwmode_ctrl->pktLength           = wlan_cpu_to_le16(cw_mode_ctrl->pktLength);
3712                         }
3713                     }
3714                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3715                 }
3716                 else
3717                 {
3718                     wm_wifi.cmd_resp_status = -WM_FAIL;
3719                 }
3720             }
3721             break;
3722             case HostCmd_CMD_RSSI_INFO:
3723             {
3724                 HostCmd_DS_802_11_RSSI_INFO_RSP *prssi_info_rsp =
3725                     (HostCmd_DS_802_11_RSSI_INFO_RSP *)(void *)&resp->params;
3726                 if (wm_wifi.cmd_resp_priv != NULL)
3727                 {
3728                     wifi_rssi_info_t *rssi_info = (wifi_rssi_info_t *)wm_wifi.cmd_resp_priv;
3729                     compute_rssi_values(prssi_info_rsp, rssi_info);
3730                 }
3731                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3732             }
3733             break;
3734             case HostCmd_CMD_802_11_NET_MONITOR:
3735                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3736                 break;
3737             case HOST_CMD_APCMD_SYS_CONFIGURE:
3738                 wifi_uap_handle_cmd_resp(resp);
3739                 break;
3740             case HostCmd_CMD_TXPWR_CFG:
3741                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_ioctl);
3742                 if (rv != MLAN_STATUS_SUCCESS)
3743                 {
3744                     return -WM_FAIL;
3745                 }
3746                 break;
3747             case HostCmd_CMD_TX_RATE_CFG:
3748             {
3749                 const HostCmd_DS_TX_RATE_CFG *tx_rate_cfg = &resp->params.tx_rate_cfg;
3750                 if (resp->result == HostCmd_RESULT_OK)
3751                 {
3752                     if (tx_rate_cfg->action == HostCmd_ACT_GEN_GET)
3753                     {
3754                         if (wm_wifi.cmd_resp_ioctl != NULL)
3755                         {
3756                             wifi_ds_rate *ds_rate = (wifi_ds_rate *)wm_wifi.cmd_resp_ioctl;
3757                             rv                    = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, ds_rate);
3758                             if (rv != MLAN_STATUS_SUCCESS)
3759                             {
3760                                 wm_wifi.cmd_resp_status = -WM_FAIL;
3761                             }
3762                             else
3763                             {
3764                                 wm_wifi.cmd_resp_status = WM_SUCCESS;
3765                             }
3766                         }
3767                     }
3768                 }
3769                 else
3770                 {
3771                     wm_wifi.cmd_resp_status = -WM_FAIL;
3772                 }
3773             }
3774             break;
3775             case HostCmd_CMD_802_11_SNMP_MIB:
3776 #if CONFIG_TURBO_MODE
3777                 if (resp->result == HostCmd_RESULT_OK)
3778                 {
3779                     t_u8 *turbo_mode           = (t_u8 *)wm_wifi.cmd_resp_priv;
3780                     t_u8 *tlv                  = (t_u8 *)((t_u8 *)resp + S_DS_GEN);
3781                     turbo_mode_para *turbo_ptr = (turbo_mode_para *)tlv;
3782                     if (turbo_ptr->action == ACTION_GET)
3783                     {
3784                         (void)memcpy(turbo_mode, &turbo_ptr->mode, sizeof(t_u8));
3785                     }
3786                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3787                 }
3788                 else
3789                 {
3790                     wm_wifi.cmd_resp_status = -WM_FAIL;
3791                 }
3792 #endif
3793                 rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
3794                 if (rv != MLAN_STATUS_SUCCESS)
3795                 {
3796                     return -WM_FAIL;
3797                 }
3798                 break;
3799             case HostCmd_CMD_OTP_READ_USER_DATA:
3800             {
3801                 const HostCmd_DS_OTP_USER_DATA *user_data = &resp->params.otp_user_data;
3802                 if (resp->result == HostCmd_RESULT_OK)
3803                 {
3804                     if (user_data->action == HostCmd_ACT_GEN_GET)
3805                     {
3806                         if (wm_wifi.cmd_resp_priv != NULL)
3807                         {
3808                             uint8_t *buf = (uint8_t *)wm_wifi.cmd_resp_priv;
3809                             (void)memcpy((void *)buf, (const void *)user_data->user_data, user_data->user_data_length);
3810                         }
3811                     }
3812                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3813                 }
3814                 else
3815                 {
3816                     wm_wifi.cmd_resp_status = -WM_FAIL;
3817                 }
3818             }
3819             break;
3820             case HostCmd_CMD_CFG_DATA:
3821             {
3822                 const HostCmd_DS_802_11_CFG_DATA *cfg_data = &resp->params.cfg_data;
3823                 if (resp->result == HostCmd_RESULT_OK)
3824                 {
3825                     if (cfg_data->action == HostCmd_ACT_GEN_GET)
3826                     {
3827                         if (wm_wifi.cmd_resp_priv != NULL)
3828                         {
3829                             wifi_cal_data_t *cal_data_cfg = (wifi_cal_data_t *)wm_wifi.cmd_resp_priv;
3830 #if !CONFIG_MEM_POOLS
3831                             cal_data_cfg->data = (uint8_t *)OSA_MemoryAllocate(cfg_data->data_len);
3832 #else
3833                             cal_data_cfg->data = (uint8_t *)OSA_MemoryPoolAllocate(buf_2048_MemoryPool);
3834 #endif
3835                             if (cal_data_cfg->data == MNULL)
3836                             {
3837                                 wifi_w(
3838                                     "No mem. Cannot"
3839                                     "process CAL DATA command");
3840                                 break;
3841                             }
3842                             cal_data_cfg->data_len = cfg_data->data_len;
3843 
3844                             (void)memcpy((void *)cal_data_cfg->data, (const void *)cfg_data->data, cfg_data->data_len);
3845                         }
3846                     }
3847                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3848                 }
3849                 else
3850                 {
3851                     wm_wifi.cmd_resp_status = -WM_FAIL;
3852                 }
3853             }
3854             break;
3855             case HostCmd_CMD_AUTO_RECONNECT:
3856             {
3857                 const HostCmd_DS_AUTO_RECONNECT *auto_reconn = &resp->params.auto_reconnect;
3858                 if (resp->result == HostCmd_RESULT_OK)
3859                 {
3860                     if (auto_reconn->action == HostCmd_ACT_GEN_GET)
3861                     {
3862                         if (wm_wifi.cmd_resp_priv != NULL)
3863                         {
3864                             wifi_auto_reconnect_config_t *auto_reconnect_config =
3865                                 (wifi_auto_reconnect_config_t *)wm_wifi.cmd_resp_priv;
3866 
3867                             auto_reconnect_config->reconnect_counter  = auto_reconn->reconnect_counter;
3868                             auto_reconnect_config->reconnect_interval = auto_reconn->reconnect_interval;
3869                             auto_reconnect_config->flags              = auto_reconn->flags;
3870                         }
3871                     }
3872                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3873                 }
3874                 else
3875                 {
3876                     wm_wifi.cmd_resp_status = -WM_FAIL;
3877                 }
3878             }
3879             break;
3880             case HostCmd_CMD_HS_WAKEUP_REASON:
3881             {
3882                 const HostCmd_DS_HS_WAKEUP_REASON *hs_wakeup_reason = &resp->params.hs_wakeup_reason;
3883                 if (resp->result == HostCmd_RESULT_OK)
3884                 {
3885                     if (wm_wifi.cmd_resp_priv != NULL)
3886                     {
3887                         t_u16 *wakeup_reason = (t_u16 *)wm_wifi.cmd_resp_priv;
3888                         *wakeup_reason       = hs_wakeup_reason->wakeup_reason;
3889                     }
3890 
3891                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3892                 }
3893                 else
3894                 {
3895                     wm_wifi.cmd_resp_status = -WM_FAIL;
3896                 }
3897             }
3898             break;
3899             case HostCmd_CMD_RX_MGMT_IND:
3900             {
3901                 if (resp->result == HostCmd_RESULT_OK)
3902                 {
3903                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3904                 }
3905                 else
3906                 {
3907                     wm_wifi.cmd_resp_status = -WM_FAIL;
3908                 }
3909             }
3910             break;
3911             case HostCmd_CMD_CHANNEL_TRPC_CONFIG:
3912             {
3913                 HostCmd_DS_CHAN_TRPC_CONFIG *chan_trpc_cfg = &resp->params.chan_trpc_cfg;
3914                 if (resp->result == HostCmd_RESULT_OK)
3915                 {
3916                     if (chan_trpc_cfg->action == HostCmd_ACT_GEN_GET)
3917                     {
3918                         if (wm_wifi.cmd_resp_priv != NULL)
3919                         {
3920                             t_u8 i;
3921                             t_u8 mod_num = 0;
3922                             t_u8 *pByte  = NULL;
3923                             t_u16 left_len;
3924                             MrvlIETypes_ChanTRPCConfig_t *trpc_tlv = NULL;
3925                             MrvlIEtypes_Data_t *pTlvHdr;
3926                             wifi_txpwrlimit_t *txpwrlimit = (wifi_txpwrlimit_t *)wm_wifi.cmd_resp_priv;
3927 
3928                             txpwrlimit->subband = (wifi_SubBand_t)chan_trpc_cfg->reserved;
3929 
3930                             pByte    = (t_u8 *)chan_trpc_cfg + 4;
3931                             left_len = resp->size - (t_u16)S_DS_GEN - 4U;
3932                             while (left_len >= sizeof(pTlvHdr->header))
3933                             {
3934                                 pTlvHdr             = (MrvlIEtypes_Data_t *)(void *)pByte;
3935                                 pTlvHdr->header.len = wlan_le16_to_cpu(pTlvHdr->header.len);
3936 
3937                                 switch (wlan_le16_to_cpu(pTlvHdr->header.type))
3938                                 {
3939                                     case TLV_TYPE_CHAN_TRPC_CONFIG:
3940                                         trpc_tlv = (MrvlIETypes_ChanTRPCConfig_t *)(void *)pTlvHdr;
3941 #if !CONFIG_11AC
3942                                         /*
3943                                          * For 2.4 GHz band, we do not support HT40 Modulation Groups.
3944                                          * Limit the number of mod groups to 7.
3945                                          */
3946                                         if (!txpwrlimit->subband)
3947                                         {
3948                                             mod_num = 7;
3949                                         }
3950                                         else
3951                                         {
3952 #endif /* CONFIG_11AC */
3953                                             mod_num =
3954                                                 ((t_u8)pTlvHdr->header.len - 4U) / ((t_u8)sizeof(mod_group_setting));
3955 #if !CONFIG_11AC
3956                                         }
3957 #endif /* CONFIG_11AC */
3958                                         txpwrlimit->txpwrlimit_config[txpwrlimit->num_chans].num_mod_grps = mod_num;
3959                                         txpwrlimit->txpwrlimit_config[txpwrlimit->num_chans].chan_desc.start_freq =
3960                                             trpc_tlv->start_freq;
3961                                         txpwrlimit->txpwrlimit_config[txpwrlimit->num_chans].chan_desc.chan_width =
3962                                             trpc_tlv->width;
3963                                         txpwrlimit->txpwrlimit_config[txpwrlimit->num_chans].chan_desc.chan_num =
3964                                             trpc_tlv->chan_num;
3965                                         for (i = 0; i < mod_num; i++)
3966                                         {
3967                                             // coverity[overrun-local:SUPPRESS]
3968                                             txpwrlimit->txpwrlimit_config[txpwrlimit->num_chans]
3969                                                 .txpwrlimit_entry[i]
3970                                                 .mod_group = trpc_tlv->mod_group[i].mod_group;
3971                                             txpwrlimit->txpwrlimit_config[txpwrlimit->num_chans]
3972                                                 .txpwrlimit_entry[i]
3973                                                 .tx_power = trpc_tlv->mod_group[i].power;
3974                                         }
3975                                         txpwrlimit->num_chans++;
3976                                         break;
3977                                     default:
3978                                         PRINTM(MINFO, "Unexpected host cmd response \n");
3979                                         break;
3980                                 }
3981                                 left_len -= (pTlvHdr->header.len + (t_u16)sizeof(pTlvHdr->header));
3982                                 pByte += (t_u8)pTlvHdr->header.len + (t_u8)sizeof(pTlvHdr->header);
3983                             }
3984                         }
3985                     }
3986                     wm_wifi.cmd_resp_status = WM_SUCCESS;
3987                 }
3988                 else
3989                 {
3990                     wm_wifi.cmd_resp_status = -WM_FAIL;
3991                 }
3992             }
3993             break;
3994             case HostCmd_CMD_802_11_GET_LOG:
3995             {
3996                 const HostCmd_DS_802_11_GET_LOG *get_log = &resp->params.get_log;
3997                 if (resp->result == HostCmd_RESULT_OK)
3998                 {
3999                     if (wm_wifi.cmd_resp_priv != NULL)
4000                     {
4001                         uint8_t *buf = (uint8_t *)wm_wifi.cmd_resp_priv;
4002                         (void)memcpy((void *)buf, (const void *)get_log, sizeof(HostCmd_DS_802_11_GET_LOG));
4003                     }
4004                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4005                 }
4006                 else
4007                 {
4008                     wm_wifi.cmd_resp_status = -WM_FAIL;
4009                 }
4010             }
4011             break;
4012 #if CONFIG_WLAN_BRIDGE
4013             case HostCmd_CMD_BRIDGE_MODE:
4014             {
4015                 const HostCmd_BRIDGE_MODE *bridge_mode = &resp->params.bridge_mode;
4016                 if (resp->result == HostCmd_RESULT_OK)
4017                 {
4018                     if (bridge_mode->action == HostCmd_ACT_GEN_GET)
4019                     {
4020                         if (wm_wifi.cmd_resp_priv)
4021                         {
4022                             wifi_bridge_cfg_t *bridgecfg             = (wifi_bridge_cfg_t *)wm_wifi.cmd_resp_priv;
4023                             t_u8 *tlv                                = NULL;
4024                             MrvlIEtypes_SsIdParamSet_t *ssid         = NULL;
4025                             MrvlIEtypes_Passphrase_t *pass           = NULL;
4026                             MrvlIEtypes_AutoLinkParamSet_t *autolink = NULL;
4027                             HostCmd_DS_GEN *hostcmd                  = NULL;
4028 
4029                             (void)memset(bridgecfg, 0x00, sizeof(wifi_bridge_cfg_t));
4030 
4031                             tlv               = (t_u8 *)resp + sizeof(HostCmd_BRIDGE_MODE) + S_DS_GEN;
4032                             hostcmd           = (HostCmd_DS_GEN *)resp;
4033                             bridgecfg->enable = bridge_mode->enable;
4034 
4035                             ssid = (MrvlIEtypes_SsIdParamSet_t *)(tlv + sizeof(MrvlIEtypesHeader_t));
4036 
4037                             bridgecfg->ex_ap_ssid_len = wlan_cpu_to_le16(ssid->header.len);
4038                             (void)memcpy((void *)bridgecfg->ex_ap_ssid, (const void *)ssid->ssid,
4039                                          bridgecfg->ex_ap_ssid_len);
4040 
4041                             tlv = (t_u8 *)ssid;
4042 
4043                             pass = (MrvlIEtypes_Passphrase_t *)(tlv + sizeof(MrvlIEtypesHeader_t) + ssid->header.len);
4044 
4045                             bridgecfg->ex_ap_pass_len = wlan_cpu_to_le16(pass->header.len);
4046                             (void)memcpy((void *)bridgecfg->ex_ap_pass, (const void *)pass->passphrase,
4047                                          bridgecfg->ex_ap_pass_len);
4048 
4049                             tlv = (t_u8 *)pass;
4050 
4051                             ssid = (MrvlIEtypes_SsIdParamSet_t *)(tlv + sizeof(MrvlIEtypesHeader_t) + pass->header.len);
4052 
4053                             bridgecfg->bridge_ssid_len = wlan_cpu_to_le16(ssid->header.len);
4054                             (void)memcpy((void *)bridgecfg->bridge_ssid, (const void *)ssid->ssid,
4055                                          bridgecfg->bridge_ssid_len);
4056 
4057                             tlv = (t_u8 *)ssid;
4058 
4059                             pass = (MrvlIEtypes_Passphrase_t *)(tlv + sizeof(MrvlIEtypesHeader_t) + ssid->header.len);
4060                             bridgecfg->bridge_pass_len = wlan_cpu_to_le16(pass->header.len);
4061                             (void)memcpy((void *)bridgecfg->bridge_pass, (const void *)pass->passphrase,
4062                                          bridgecfg->bridge_pass_len);
4063 
4064                             tlv = (t_u8 *)pass;
4065 
4066                             autolink = (MrvlIEtypes_AutoLinkParamSet_t *)(tlv + sizeof(MrvlIEtypesHeader_t) +
4067                                                                           pass->header.len);
4068                             if (hostcmd->size > ((char *)autolink - (char *)resp))
4069                             {
4070                                 (void)memcpy((void *)&bridgecfg->autolink,
4071                                              (const void *)(((char *)autolink) + sizeof(MrvlIEtypesHeader_t)),
4072                                              autolink->header.len);
4073                             }
4074                         }
4075                     }
4076                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4077                 }
4078                 else
4079                 {
4080                     wm_wifi.cmd_resp_status = -WM_FAIL;
4081                 }
4082             }
4083             break;
4084 #endif
4085             case HostCmd_CMD_RECONFIGURE_TX_BUFF:
4086                 if (resp->result == HostCmd_RESULT_OK)
4087                 {
4088                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4089                 }
4090                 else
4091                 {
4092                     wm_wifi.cmd_resp_status = -WM_FAIL;
4093                 }
4094                 break;
4095             case HostCmd_CMD_PMF_PARAMS:
4096             {
4097                 const HostCmd_DS_PMF_PARAMS *get_pmf_params = &resp->params.pmf_params;
4098                 if ((resp->result == HostCmd_RESULT_OK) && (get_pmf_params->action == HostCmd_ACT_GEN_GET))
4099                 {
4100                     if (wm_wifi.cmd_resp_priv != NULL)
4101                     {
4102                         wifi_pmf_params_t *wifi_pmf_params = (wifi_pmf_params_t *)wm_wifi.cmd_resp_priv;
4103 
4104                         wifi_pmf_params->mfpc = get_pmf_params->params.mfpc;
4105                         wifi_pmf_params->mfpr = get_pmf_params->params.mfpr;
4106                     }
4107                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4108                 }
4109                 else
4110                 {
4111                     wm_wifi.cmd_resp_status = -WM_FAIL;
4112                 }
4113             }
4114             break;
4115 #if CONFIG_RF_TEST_MODE
4116             case HostCmd_CMD_MFG_COMMAND:
4117             {
4118                 if ((resp->result == HostCmd_RESULT_OK) && wm_wifi.cmd_resp_priv)
4119                 {
4120                     rv = wlan_ret_mfg(pmpriv, resp, wm_wifi.cmd_resp_priv);
4121                     if (rv == MLAN_STATUS_SUCCESS)
4122                     {
4123                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4124                     }
4125                     else
4126                     {
4127                         wm_wifi.cmd_resp_status = -WM_FAIL;
4128                     }
4129                 }
4130                 else
4131                 {
4132                     wm_wifi.cmd_resp_status = -WM_FAIL;
4133                 }
4134             }
4135             break;
4136 #endif
4137             case HostCmd_CMD_GET_TSF:
4138             {
4139                 const HostCmd_DS_TSF *tsf_pointer = (HostCmd_DS_TSF *)&resp->params.tsf_cfg;
4140                 if (resp->result == HostCmd_RESULT_OK)
4141                 {
4142                     if (wm_wifi.cmd_resp_priv != NULL)
4143                     {
4144                         t_u64 *tsf = (t_u64 *)(wm_wifi.cmd_resp_priv);
4145 
4146                         *tsf = tsf_pointer->tsf;
4147 
4148                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4149                     }
4150                     else
4151                     {
4152                         wm_wifi.cmd_resp_status = -WM_FAIL;
4153                     }
4154                 }
4155                 else
4156                 {
4157                     wm_wifi.cmd_resp_status = -WM_FAIL;
4158                 }
4159             }
4160             break;
4161             case HostCmd_CMD_BOOT_SLEEP:
4162             {
4163                 const HostCmd_DS_BOOT_SLEEP *boot_sleep_pointer = (HostCmd_DS_BOOT_SLEEP *)&resp->params.tsf_cfg;
4164                 if (resp->result == HostCmd_RESULT_OK)
4165                 {
4166                     if (wm_wifi.cmd_resp_priv != NULL)
4167                     {
4168                         t_u16 *enable = (t_u16 *)(wm_wifi.cmd_resp_priv);
4169 
4170                         *enable = boot_sleep_pointer->enable;
4171 
4172                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4173                     }
4174                     else
4175                     {
4176                         wm_wifi.cmd_resp_status = -WM_FAIL;
4177                     }
4178                 }
4179                 else
4180                 {
4181                     wm_wifi.cmd_resp_status = -WM_FAIL;
4182                 }
4183             }
4184             break;
4185 #if CONFIG_WIFI_CLOCKSYNC
4186             case HostCmd_GPIO_TSF_LATCH_PARAM_CONFIG:
4187             {
4188                 if (resp->result == HostCmd_RESULT_OK)
4189                 {
4190                     rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_ioctl);
4191                     if (rv != MLAN_STATUS_SUCCESS)
4192                     {
4193                         wm_wifi.cmd_resp_status = -WM_FAIL;
4194                     }
4195                     else
4196                     {
4197                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4198                     }
4199                 }
4200                 else
4201                     wm_wifi.cmd_resp_status = -WM_FAIL;
4202             }
4203             break;
4204 #endif
4205             case HostCmd_CMD_AUTO_TX:
4206             {
4207                 if (resp->result == HostCmd_RESULT_OK)
4208                 {
4209 #if CONFIG_CLOUD_KEEP_ALIVE
4210                     const HostCmd_DS_AUTO_TX *auto_tx              = (HostCmd_DS_AUTO_TX *)&resp->params.auto_tx;
4211                     MrvlIEtypes_Cloud_Keep_Alive_t *keep_alive_tlv = MNULL;
4212                     t_u8 *enable;
4213                     MrvlIEtypesHeader_t *header = (MrvlIEtypesHeader_t *)auto_tx->tlv_buffer;
4214                     header->type                = wlan_le16_to_cpu(header->type);
4215 
4216                     if ((auto_tx->action == HostCmd_ACT_GEN_GET) && (header->type == TLV_TYPE_CLOUD_KEEP_ALIVE) &&
4217                         (wm_wifi.cmd_resp_priv != NULL))
4218                     {
4219                         keep_alive_tlv        = (MrvlIEtypes_Cloud_Keep_Alive_t *)auto_tx->tlv_buffer;
4220                         enable                = (t_u8 *)wm_wifi.cmd_resp_priv;
4221                         *enable               = keep_alive_tlv->enable;
4222                         wm_wifi.cmd_resp_priv = NULL;
4223                     }
4224 #endif
4225                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4226                 }
4227                 else
4228                 {
4229                     wm_wifi.cmd_resp_status = -WM_FAIL;
4230                 }
4231             }
4232             break;
4233 #ifdef OTP_CHANINFO
4234             case HostCmd_CMD_CHAN_REGION_CFG:
4235             {
4236                 if (resp->result == HostCmd_RESULT_OK)
4237                 {
4238                     rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
4239                     if (rv != MLAN_STATUS_SUCCESS)
4240                     {
4241                         wm_wifi.cmd_resp_status = -WM_FAIL;
4242                     }
4243                     else
4244                     {
4245                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4246                     }
4247                 }
4248                 else
4249                 {
4250                     wm_wifi.cmd_resp_status = -WM_FAIL;
4251                 }
4252             }
4253             break;
4254 #endif
4255 #if CONFIG_11AX
4256             case HostCmd_CMD_11AX_CFG:
4257             {
4258                 if (resp->result == HostCmd_RESULT_OK)
4259                 {
4260                     if (wm_wifi.cmd_resp_priv != NULL)
4261                     {
4262                         mlan_ds_11ax_he_cfg *cfg = (mlan_ds_11ax_he_cfg *)wm_wifi.cmd_resp_priv;
4263                         rv                       = wlan_ret_11ax_cfg(pmpriv, resp, cfg);
4264                         if (rv != MLAN_STATUS_SUCCESS)
4265                             wm_wifi.cmd_resp_status = -WM_FAIL;
4266                         else
4267                             wm_wifi.cmd_resp_status = WM_SUCCESS;
4268                     }
4269                 }
4270                 else
4271                 {
4272                     rv                      = MLAN_STATUS_FAILURE;
4273                     wm_wifi.cmd_resp_status = -WM_FAIL;
4274                 }
4275             }
4276             break;
4277 #if CONFIG_11AX_TWT
4278             case HostCmd_CMD_TWT_CFG:
4279             {
4280                 if (resp->result == HostCmd_RESULT_OK)
4281                 {
4282                     if (wm_wifi.cmd_resp_priv != NULL)
4283                     {
4284                         if (resp->params.twtcfg.sub_id == MLAN_11AX_TWT_SETUP_SUBID)
4285                         {
4286                             mlan_ds_twt_setup *cfg = (mlan_ds_twt_setup *)wm_wifi.cmd_resp_priv;
4287                             (void)memcpy(cfg, &resp->params.twtcfg.param.twt_setup, sizeof(mlan_ds_twt_setup));
4288                         }
4289                         else if (resp->params.twtcfg.sub_id == MLAN_11AX_TWT_REPORT_SUBID)
4290                         {
4291                             mlan_ds_twt_report *cfg = (mlan_ds_twt_report *)wm_wifi.cmd_resp_priv;
4292                             (void)memcpy(cfg, &resp->params.twtcfg.param.twt_report, sizeof(mlan_ds_twt_report));
4293                         }
4294                     }
4295                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4296                 }
4297                 else
4298                 {
4299                     rv                      = MLAN_STATUS_FAILURE;
4300                     wm_wifi.cmd_resp_status = -WM_FAIL;
4301                 }
4302             }
4303             break;
4304 #endif /* CONFIG_11AX_TWT */
4305             case HostCmd_CMD_11AX_CMD:
4306             {
4307                 if (resp->result == HostCmd_RESULT_OK)
4308                 {
4309                     rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_ioctl);
4310                     if (rv != MLAN_STATUS_SUCCESS)
4311                         wm_wifi.cmd_resp_status = -WM_FAIL;
4312                     else
4313                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4314                 }
4315                 else
4316                 {
4317                     rv                      = MLAN_STATUS_FAILURE;
4318                     wm_wifi.cmd_resp_status = -WM_FAIL;
4319                 }
4320             }
4321             break;
4322 #if CONFIG_MMSF
4323             case HostCmd_CMD_DBGS_CFG:
4324             {
4325                 if (resp->result == HostCmd_RESULT_OK)
4326                 {
4327                     if (wm_wifi.cmd_resp_priv != NULL)
4328                     {
4329                         wifi_mmsf_cfg_t *mmsf_cfg     = (wifi_mmsf_cfg_t *)wm_wifi.cmd_resp_priv;
4330                         HostCmd_DS_MMSF_CFG *MMSF_CFG = (HostCmd_DS_MMSF_CFG *)&resp->params.mmsf_cfg;
4331                         if (MMSF_CFG->action == HostCmd_ACT_GEN_GET)
4332                         {
4333                             (void)memcpy(mmsf_cfg->enable, &MMSF_CFG->enableMMSF, sizeof(MMSF_CFG->enableMMSF));
4334                             (void)memcpy(mmsf_cfg->Density, &MMSF_CFG->ampduDensity, sizeof(MMSF_CFG->ampduDensity));
4335                             (void)memcpy(mmsf_cfg->MMSF, &MMSF_CFG->ampduMMSF, sizeof(MMSF_CFG->ampduMMSF));
4336                         }
4337                     }
4338                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4339                 }
4340                 else
4341                 {
4342                     wm_wifi.cmd_resp_status = -WM_FAIL;
4343                 }
4344             }
4345 #endif
4346 #endif
4347 #if (CONFIG_WIFI_TX_PER_TRACK) || (CONFIG_TX_RX_HISTOGRAM)
4348             case HostCmd_CMD_TX_RX_PKT_STATS:
4349             {
4350                 if (resp->result == HostCmd_RESULT_OK)
4351                 {
4352 #if CONFIG_TX_RX_HISTOGRAM
4353                     const HostCmd_DS_TX_RX_HISTOGRAM *txrx_histogram = &resp->params.histogram;
4354                     if (txrx_histogram->action != HostCmd_ACT_SET_TX_PER_TRACKING)
4355                     {
4356                         t_u16 cmdsize   = wlan_le16_to_cpu(resp->size);
4357                         t_u16 length    = 0;
4358                         t_u16 data_size = 0;
4359                         t_u8 *pos       = NULL;
4360 
4361                         if (wm_wifi.cmd_resp_priv != NULL)
4362                         {
4363                             t_u8 *tx_rx_histogram_data = wm_wifi.cmd_resp_priv;
4364                             (void)memcpy(&data_size, tx_rx_histogram_data, sizeof(data_size));
4365                             length = cmdsize - S_DS_GEN - sizeof(HostCmd_DS_TX_RX_HISTOGRAM);
4366 
4367                             if (length > 0 && (data_size >= length + sizeof(length)))
4368                             {
4369                                 (void)memcpy(tx_rx_histogram_data, (t_u8 *)&length, sizeof(length));
4370                                 pos = (t_u8 *)resp + S_DS_GEN + sizeof(HostCmd_DS_TX_RX_HISTOGRAM);
4371                                 (void)memcpy(tx_rx_histogram_data + sizeof(length), pos, length);
4372                             }
4373                             else
4374                             {
4375                                 wifi_w("TX RX histogram data error\n");
4376                             }
4377                         }
4378                     }
4379 #endif
4380                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4381                 }
4382                 else
4383                 {
4384                     wm_wifi.cmd_resp_status = -WM_FAIL;
4385                 }
4386             }
4387             break;
4388 #endif
4389 #if CONFIG_BG_SCAN
4390             case HostCmd_CMD_802_11_BG_SCAN_CONFIG:
4391             {
4392                 HostCmd_DS_802_11_BG_SCAN_CONFIG *bg_scan = &resp->params.bg_scan_config;
4393                 /* TODO: command response handler for GET command */
4394                 if (resp->result == HostCmd_RESULT_OK)
4395                 {
4396                     if (bg_scan->enable)
4397                         pmpriv->roaming_configured = MTRUE;
4398                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4399                 }
4400                 else
4401                     wm_wifi.cmd_resp_status = -WM_FAIL;
4402             }
4403             break;
4404             case HostCmd_CMD_802_11_BG_SCAN_QUERY:
4405             {
4406                 if (resp->result == HostCmd_RESULT_OK)
4407                 {
4408                     rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, NULL);
4409                     if (rv != MLAN_STATUS_SUCCESS)
4410                         wm_wifi.cmd_resp_status = -WM_FAIL;
4411                     else
4412                     {
4413                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4414                         wifi_d("BG scan query complete");
4415 
4416                         (void)wifi_event_completion(WIFI_EVENT_SCAN_RESULT, WIFI_EVENT_REASON_SUCCESS, NULL);
4417                     }
4418                 }
4419                 else
4420                     wm_wifi.cmd_resp_status = -WM_FAIL;
4421             }
4422             break;
4423 #endif
4424             case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
4425             {
4426                 if (resp->result == HostCmd_RESULT_OK)
4427                 {
4428                     rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_priv);
4429                     if (rv != MLAN_STATUS_SUCCESS)
4430                         wm_wifi.cmd_resp_status = -WM_FAIL;
4431                     else
4432                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4433                 }
4434                 else
4435                     wm_wifi.cmd_resp_status = -WM_FAIL;
4436             }
4437             break;
4438 #if CONFIG_WIFI_EU_CRYPTO
4439             case HostCmd_CMD_EU_CRYPTO:
4440             {
4441                 if (resp->result == HostCmd_RESULT_OK)
4442                 {
4443                     if (wm_wifi.cmd_resp_priv != NULL)
4444                     {
4445                         EU_Crypto *EU_Data = (EU_Crypto *)wm_wifi.cmd_resp_priv;
4446                         HostCmd_DS_EU_AES_CRYPTO *cmd_aes_ccmp =
4447                             (HostCmd_DS_EU_AES_CRYPTO *)&resp->params.eu_aes_crypto;
4448                         HostCmd_DS_EU_CRYPTO *cmd_eu_crypto = (HostCmd_DS_EU_CRYPTO *)&resp->params.eu_crypto;
4449                         if (cmd_eu_crypto->Algorithm == CRYPTO_RC4 || cmd_eu_crypto->Algorithm == CRYPTO_AES_ECB ||
4450                             cmd_eu_crypto->Algorithm == CRYPTO_AES_WRAP)
4451                         {
4452                             memcpy(EU_Data->DataLength, &cmd_eu_crypto->DataLength, sizeof(t_u16) / sizeof(t_u8));
4453                             memcpy(EU_Data->Data, cmd_eu_crypto->Data, cmd_eu_crypto->DataLength);
4454                         }
4455                         else if (cmd_aes_ccmp->Algorithm == CRYPTO_AES_CCMP ||
4456                                  cmd_aes_ccmp->Algorithm == CRYPTO_AES_GCMP)
4457                         {
4458                             memcpy(EU_Data->DataLength, &cmd_aes_ccmp->DataLength, sizeof(t_u16) / sizeof(t_u8));
4459                             memcpy(EU_Data->Data, cmd_aes_ccmp->Data, cmd_aes_ccmp->DataLength);
4460                         }
4461                     }
4462                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4463                 }
4464                 else
4465                 {
4466                     rv                      = MLAN_STATUS_FAILURE;
4467                     wm_wifi.cmd_resp_status = -WM_FAIL;
4468                 }
4469             }
4470             break;
4471 #endif
4472 #if CONFIG_MULTI_CHAN
4473             case HostCmd_CMD_MULTI_CHAN_CONFIG:
4474             case HostCmd_CMD_MULTI_CHAN_POLICY:
4475             case HostCmd_CMD_DRCS_CONFIG:
4476                 if (resp->result == HostCmd_RESULT_OK)
4477                 {
4478                     wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_ioctl);
4479                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4480                 }
4481                 else
4482                 {
4483                     rv                      = MLAN_STATUS_FAILURE;
4484                     wm_wifi.cmd_resp_status = -WM_FAIL;
4485                 }
4486                 break;
4487 #endif
4488 #if CONFIG_1AS
4489             case HostCmd_CMD_HOST_CLOCK_CFG:
4490                 if (resp->result == HostCmd_RESULT_OK)
4491                 {
4492                     wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_ioctl);
4493                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4494                 }
4495                 else
4496                 {
4497                     rv                      = MLAN_STATUS_FAILURE;
4498                     wm_wifi.cmd_resp_status = -WM_FAIL;
4499                 }
4500                 break;
4501 #endif
4502 #if CONFIG_WPA_SUPP
4503             case HostCmd_CMD_802_11_REMAIN_ON_CHANNEL:
4504             {
4505                 const HostCmd_DS_REMAIN_ON_CHANNEL *remain_channel = &resp->params.remain_on_chan;
4506 #if !CONFIG_MEM_POOLS
4507                 t_u8 *cancel_channel = (t_u8 *)OSA_MemoryAllocate(sizeof(t_u8));
4508 #else
4509                 t_u8 *cancel_channel = (t_u8 *)OSA_MemoryPoolAllocate(buf_32_MemoryPool);
4510 #endif
4511                 if (cancel_channel != NULL)
4512                 {
4513                     *cancel_channel              = remain_channel->action == HostCmd_ACT_GEN_REMOVE ? MTRUE : MFALSE;
4514                     mlan_adap->remain_on_channel = remain_channel->action == HostCmd_ACT_GEN_REMOVE ? MFALSE : MTRUE;
4515                     if (*cancel_channel)
4516                     {
4517                         if (wifi_event_completion(WIFI_EVENT_REMAIN_ON_CHANNEL, WIFI_EVENT_REASON_SUCCESS,
4518                                                   (void *)cancel_channel) != WM_SUCCESS)
4519                         {
4520 #if !CONFIG_MEM_POOLS
4521                             OSA_MemoryFree(cancel_channel);
4522 #else
4523                             OSA_MemoryPoolFree(buf_32_MemoryPool, cancel_channel);
4524 #endif
4525                             cancel_channel = NULL;
4526                         }
4527                     }
4528                     else
4529                     {
4530                         if (wifi_event_completion(WIFI_EVENT_REMAIN_ON_CHANNEL, WIFI_EVENT_REASON_SUCCESS,
4531                                                   (void *)cancel_channel) != WM_SUCCESS)
4532                         {
4533 #if !CONFIG_MEM_POOLS
4534                             OSA_MemoryFree(cancel_channel);
4535 #else
4536                             OSA_MemoryPoolFree(buf_32_MemoryPool, cancel_channel);
4537 #endif
4538                             cancel_channel = NULL;
4539                         }
4540                     }
4541                 }
4542             }
4543             break;
4544 #endif
4545 
4546 #if CONFIG_RX_ABORT_CFG
4547             case HostCmd_CMD_RX_ABORT_CFG:
4548             {
4549                 HostCmd_DS_RX_ABORT_CFG *cfg;
4550                 cfg = (HostCmd_DS_RX_ABORT_CFG *)&resp->params.rx_abort_cfg;
4551                 if (resp->result == HostCmd_RESULT_OK)
4552                 {
4553                     if (cfg->action == HostCmd_ACT_GEN_GET)
4554                     {
4555                         if (wm_wifi.cmd_resp_priv != NULL)
4556                         {
4557                             rx_abort_cfg_t *rx_abort_cfg = (rx_abort_cfg_t *)wm_wifi.cmd_resp_priv;
4558                             rx_abort_cfg->enable         = cfg->enable;
4559                             rx_abort_cfg->rssi_threshold = (int)cfg->rssi_threshold;
4560                             if (rx_abort_cfg->rssi_threshold > 0x7f)
4561                             {
4562                                 rx_abort_cfg->rssi_threshold = -(256 - rx_abort_cfg->rssi_threshold);
4563                             }
4564                         }
4565                     }
4566                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4567                 }
4568                 else
4569                     wm_wifi.cmd_resp_status = -WM_FAIL;
4570             }
4571             break;
4572 #endif
4573 #if CONFIG_RX_ABORT_CFG_EXT
4574             case HostCmd_CMD_RX_ABORT_CFG_EXT:
4575             {
4576                 HostCmd_DS_RX_ABORT_CFG_EXT *cfg;
4577                 cfg = (HostCmd_DS_RX_ABORT_CFG_EXT *)&resp->params.rx_abort_cfg_ext;
4578                 if (resp->result == HostCmd_RESULT_OK)
4579                 {
4580                     if (cfg->action == HostCmd_ACT_GEN_GET)
4581                     {
4582                         if (wm_wifi.cmd_resp_priv != NULL)
4583                         {
4584                             rx_abort_cfg_ext_t *rx_abort_cfg_ext   = (rx_abort_cfg_ext_t *)wm_wifi.cmd_resp_priv;
4585                             rx_abort_cfg_ext->enable               = cfg->enable;
4586                             rx_abort_cfg_ext->rssi_margin          = (int)cfg->rssi_margin;
4587                             rx_abort_cfg_ext->ceil_rssi_threshold  = (int)cfg->ceil_rssi_threshold;
4588                             rx_abort_cfg_ext->floor_rssi_threshold = (int)cfg->floor_rssi_threshold;
4589                             rx_abort_cfg_ext->current_dynamic_rssi_threshold = (int)cfg->current_dynamic_rssi_threshold;
4590                             rx_abort_cfg_ext->rssi_default_config            = (int)cfg->rssi_default_config;
4591                             rx_abort_cfg_ext->edmac_enable                   = (int)cfg->edmac_enable;
4592                         }
4593                     }
4594                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4595                 }
4596                 else
4597                     wm_wifi.cmd_resp_status = -WM_FAIL;
4598             }
4599             break;
4600 #endif
4601 #if CONFIG_CCK_DESENSE_CFG
4602             case HostCmd_CMD_CCK_DESENSE_CFG:
4603             {
4604                 HostCmd_DS_CCK_DESENSE_CFG *cfg_cmd;
4605                 cfg_cmd = (HostCmd_DS_CCK_DESENSE_CFG *)&resp->params.cck_desense_cfg;
4606                 if (resp->result == HostCmd_RESULT_OK)
4607                 {
4608                     if (cfg_cmd->action == HostCmd_ACT_GEN_GET)
4609                     {
4610                         if (wm_wifi.cmd_resp_priv != NULL)
4611                         {
4612                             cck_desense_cfg_t *cck_desense_cfg = (cck_desense_cfg_t *)wm_wifi.cmd_resp_priv;
4613                             cck_desense_cfg->mode              = wlan_le16_to_cpu(cfg_cmd->mode);
4614                             cck_desense_cfg->margin            = (int)cfg_cmd->margin;
4615                             if (cck_desense_cfg->margin > 0x7f)
4616                             {
4617                                 cck_desense_cfg->margin = -(256 - cck_desense_cfg->margin);
4618                             }
4619                             cck_desense_cfg->ceil_thresh = (int)cfg_cmd->ceil_thresh;
4620                             if (cck_desense_cfg->ceil_thresh > 0x7f)
4621                             {
4622                                 cck_desense_cfg->ceil_thresh = -(256 - cck_desense_cfg->ceil_thresh);
4623                             }
4624                             cck_desense_cfg->num_on_intervals  = (int)cfg_cmd->num_on_intervals;
4625                             cck_desense_cfg->num_off_intervals = (int)cfg_cmd->num_off_intervals;
4626                         }
4627                     }
4628                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4629                 }
4630                 else
4631                     wm_wifi.cmd_resp_status = -WM_FAIL;
4632             }
4633             break;
4634 #endif
4635 
4636 #if CONFIG_TX_AMPDU_PROT_MODE
4637             case HostCmd_CMD_TX_AMPDU_PROT_MODE:
4638                 if (resp->result == HostCmd_RESULT_OK)
4639                 {
4640                     const HostCmd_DS_CMD_TX_AMPDU_PROT_MODE *data = &resp->params.tx_ampdu_prot_mode;
4641                     if (data->action == HostCmd_ACT_GEN_GET)
4642                     {
4643                         if (wm_wifi.cmd_resp_priv != NULL)
4644                         {
4645                             tx_ampdu_prot_mode_para *prot_mode = (tx_ampdu_prot_mode_para *)wm_wifi.cmd_resp_priv;
4646                             prot_mode->mode                    = data->mode;
4647                         }
4648                     }
4649                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4650                 }
4651                 else
4652                     wm_wifi.cmd_resp_status = -WM_FAIL;
4653                 break;
4654 #endif
4655 #if CONFIG_TSP
4656             case HostCmd_CMD_TSP_CFG:
4657                 if (resp->result == HostCmd_RESULT_OK)
4658                 {
4659                     TSP_CFG *tsp_get_cfg     = (TSP_CFG *)wm_wifi.cmd_resp_priv;
4660                     HostCmd_DS_TSP_CFG *data = &resp->params.tsp_cfg;
4661                     if (data->action == HostCmd_ACT_GEN_GET)
4662                     {
4663                         *(tsp_get_cfg->thermalPowerMgmtenable) = data->thermalPowerMgmtenable;
4664                         *(tsp_get_cfg->powerMgmtBackoff)       = data->powerMgmtBackoff;
4665                         *(tsp_get_cfg->lowPwrBOThrshld)        = data->lowPwrBOThrshld;
4666                         *(tsp_get_cfg->highPwrBOThrshld)       = data->highPwrBOThrshld;
4667                         *(tsp_get_cfg->dutycycstep)            = data->dutycycstep;
4668                         *(tsp_get_cfg->dutycycmin)             = data->dutycycmin;
4669                         *(tsp_get_cfg->highthrtemp)            = data->highthrtemp;
4670                         *(tsp_get_cfg->lowthrtemp)             = data->lowthrtemp;
4671                         *(tsp_get_cfg->currCAUTemp)            = data->currCAUTemp;
4672                         *(tsp_get_cfg->currRFUTemp)            = data->currRFUTemp;
4673                     }
4674                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4675                 }
4676                 else
4677                     wm_wifi.cmd_resp_status = -WM_FAIL;
4678                 break;
4679 #endif
4680 #if (CONFIG_11MC) || (CONFIG_11AZ)
4681             case HostCmd_CMD_FTM_SESSION_CFG:
4682                 if (resp->result == HostCmd_RESULT_OK)
4683                 {
4684                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4685                     wifi_ftm_process_cfg_resp(resp);
4686                 }
4687                 else
4688                     wm_wifi.cmd_resp_status = -WM_FAIL;
4689                 break;
4690             case HostCmd_CMD_FTM_SESSION_CTRL:
4691                 if (resp->result == HostCmd_RESULT_OK)
4692                 {
4693                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4694                     wifi_ftm_process_ctrl_resp(resp);
4695                 }
4696                 else
4697                     wm_wifi.cmd_resp_status = -WM_FAIL;
4698                 break;
4699 #endif
4700 #if (CONFIG_COEX_DUTY_CYCLE) || (CONFIG_EXTERNAL_COEX_PTA) || (CONFIG_IMD3_CFG)
4701             case HostCmd_CMD_ROBUST_COEX:
4702                 if (resp->result == HostCmd_RESULT_OK)
4703                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4704                 else
4705                     wm_wifi.cmd_resp_status = -WM_FAIL;
4706                 break;
4707 #endif
4708 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
4709             case HostCmd_CMD_INDEPENDENT_RESET_CFG:
4710             {
4711                 if (resp->result == HostCmd_RESULT_OK)
4712                 {
4713                     rv = wlan_ops_sta_process_cmdresp(pmpriv, command, resp, wm_wifi.cmd_resp_ioctl);
4714                     if (rv != MLAN_STATUS_SUCCESS)
4715                     {
4716                         wm_wifi.cmd_resp_status = -WM_FAIL;
4717                     }
4718                     else
4719                     {
4720                         wm_wifi.cmd_resp_status = WM_SUCCESS;
4721                     }
4722                 }
4723                 else
4724                     wm_wifi.cmd_resp_status = -WM_FAIL;
4725             }
4726             break;
4727 #endif
4728 #if CONFIG_INACTIVITY_TIMEOUT_EXT
4729             case HostCmd_CMD_INACTIVITY_TIMEOUT_EXT:
4730                 if (resp->result == HostCmd_RESULT_OK)
4731                 {
4732                     const HostCmd_DS_INACTIVITY_TIMEOUT_EXT *data = &resp->params.inactivity_to;
4733                     if (data->action == HostCmd_ACT_GEN_GET)
4734                     {
4735                         if (wm_wifi.cmd_resp_priv != NULL)
4736                         {
4737                             wifi_inactivity_to_t *inac_to = (wifi_inactivity_to_t *)wm_wifi.cmd_resp_priv;
4738                             inac_to->timeout_unit         = data->timeout_unit;
4739                             inac_to->unicast_timeout      = data->unicast_timeout;
4740                             inac_to->mcast_timeout        = data->mcast_timeout;
4741                             inac_to->ps_entry_timeout     = data->ps_entry_timeout;
4742                             inac_to->ps_cmd_timeout       = data->ps_cmd_timeout;
4743                         }
4744                     }
4745                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4746                 }
4747                 else
4748                     wm_wifi.cmd_resp_status = -WM_FAIL;
4749                 break;
4750 #endif
4751             case HostCmd_CMD_802_11_TX_FRAME:
4752             {
4753                 if (resp->result == HostCmd_RESULT_OK)
4754                 {
4755                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4756                 }
4757                 else
4758                 {
4759                     wm_wifi.cmd_resp_status = -WM_FAIL;
4760                 }
4761             }
4762             break;
4763             case HostCmd_CMD_ADD_NEW_STATION:
4764                 if (resp->result == HostCmd_RESULT_OK)
4765                 {
4766                     wm_wifi.cmd_resp_status = WM_SUCCESS;
4767                 }
4768                 else
4769                 {
4770                     wm_wifi.cmd_resp_status = -WM_FAIL;
4771                 }
4772                 break;
4773 
4774             default:
4775                 /* fixme: Currently handled by the legacy code. Change this
4776                    handling later. Also check the default return value then*/
4777                 break;
4778         }
4779     }
4780 
4781     if (rv != MLAN_STATUS_SUCCESS)
4782     {
4783         return -WM_FAIL;
4784     }
4785 
4786     return WM_SUCCESS;
4787 }
4788 
4789 #if (CONFIG_UAP_AMPDU_TX) || (CONFIG_UAP_AMPDU_RX)
4790 /**
4791  *  @brief This function will search for the specific ie
4792  *
4793  *
4794  *  @param priv    A pointer to mlan_private
4795  *  @param ie_buf  A pointer to ie_buf
4796  *  @param ie_len  total ie length
4797  *  @param id      ie's id
4798  *
4799  *  @return	       ie's poiner or MNULL
4800  */
wlan_get_specific_ie(pmlan_private priv,t_u8 * ie_buf,t_u8 ie_len,IEEEtypes_ElementId_e id,t_u8 ext_id)4801 t_u8 *wlan_get_specific_ie(pmlan_private priv, t_u8 *ie_buf, t_u8 ie_len, IEEEtypes_ElementId_e id, t_u8 ext_id)
4802 {
4803     t_u8 bytes_left    = ie_len;
4804     t_u8 *pcurrent_ptr = ie_buf;
4805     t_u8 total_ie_len;
4806     t_u8 *ie_ptr = MNULL;
4807     IEEEtypes_ElementId_e element_id;
4808     t_u8 element_len;
4809 #if CONFIG_11AX
4810     t_u8 element_eid;
4811 #endif
4812     ENTER();
4813 
4814     DBG_HEXDUMP(MCMD_D, "ie", ie_buf, ie_len);
4815     while (bytes_left >= 2U)
4816     {
4817         element_id  = (IEEEtypes_ElementId_e)(*((t_u8 *)pcurrent_ptr));
4818         element_len = *((t_u8 *)pcurrent_ptr + 1);
4819 #if CONFIG_11AX
4820         element_eid = *((t_u8 *)pcurrent_ptr + 2);
4821 #endif
4822         total_ie_len = element_len + (t_u8)sizeof(IEEEtypes_Header_t);
4823         if (bytes_left < total_ie_len)
4824         {
4825             PRINTM(MERROR,
4826                    "InterpretIE: Error in processing IE, "
4827                    "bytes left < IE length\n");
4828             break;
4829         }
4830         if ((
4831 #if CONFIG_11AX
4832                 (ext_id == 0U) &&
4833 #endif
4834                 element_id == id)
4835 #if CONFIG_11AX
4836             || (id == EXTENSION && element_id == id && ext_id == element_eid)
4837 #endif
4838         )
4839         {
4840 #if CONFIG_11AX
4841             PRINTM(MCMND, "Find IE: id=%d ext_id=%d\n", id, ext_id);
4842 #else
4843             PRINTM(MCMND, "Find IE: id=%d\n", id);
4844 #endif
4845             DBG_HEXDUMP(MCMND, "IE", pcurrent_ptr, total_ie_len);
4846             ie_ptr = pcurrent_ptr;
4847             break;
4848         }
4849         pcurrent_ptr += element_len + 2U;
4850         /* Need to account for IE ID and IE Len */
4851         bytes_left -= (element_len + 2U);
4852     }
4853 
4854     LEAVE();
4855 
4856     return ie_ptr;
4857 }
4858 
4859 /**
4860  *  @brief This function will search for the specific ie
4861  *
4862  *
4863  *  @param priv    A pointer to mlan_private
4864  *  @param pevent  A pointer to event buf
4865  *  @param sta_ptr A pointer to sta_node
4866  *
4867  *  @return	       N/A
4868  */
wrapper_wlan_check_sta_capability(pmlan_private priv,Event_Ext_t * pevent,sta_node * sta_ptr)4869 static void wrapper_wlan_check_sta_capability(pmlan_private priv, Event_Ext_t *pevent, sta_node *sta_ptr)
4870 {
4871     t_u16 tlv_type, tlv_len;
4872     t_u16 frame_control, frame_sub_type = 0;
4873     t_u8 *assoc_req_ie = MNULL;
4874     t_u8 ie_len = 0, assoc_ie_len = 0;
4875     IEEEtypes_HTCap_t *pht_cap = MNULL;
4876 #if CONFIG_11AC
4877     IEEEtypes_VHTCap_t *pvht_cap = MNULL;
4878 #endif
4879 #if CONFIG_11AX
4880     IEEEtypes_Extension_t *phe_cap = MNULL;
4881 #endif
4882     int tlv_buf_left         = (int)pevent->length - (int)INTF_HEADER_LEN - (int)ASSOC_EVENT_FIX_SIZE;
4883     MrvlIEtypesHeader_t *tlv = (MrvlIEtypesHeader_t *)(void *)((char *)pevent + INTF_HEADER_LEN + ASSOC_EVENT_FIX_SIZE);
4884     MrvlIETypes_MgmtFrameSet_t *mgmt_tlv = MNULL;
4885 
4886     ENTER();
4887     while (tlv_buf_left >= (int)sizeof(MrvlIEtypesHeader_t))
4888     {
4889         tlv_type = wlan_le16_to_cpu(tlv->type);
4890         tlv_len  = wlan_le16_to_cpu(tlv->len);
4891         if ((sizeof(MrvlIEtypesHeader_t) + tlv_len) > (unsigned int)tlv_buf_left)
4892         {
4893             PRINTM(MERROR, "wrong tlv: tlvLen=%d, tlvBufLeft=%d\n", tlv_len, tlv_buf_left);
4894             break;
4895         }
4896         if (tlv_type == TLV_TYPE_UAP_MGMT_FRAME)
4897         {
4898             mgmt_tlv = (MrvlIETypes_MgmtFrameSet_t *)(void *)tlv;
4899             (void)memcpy((void *)&frame_control, (const void *)((t_u8 *)&(mgmt_tlv->frame_control)),
4900                          sizeof(frame_control));
4901             frame_sub_type = IEEE80211_GET_FC_MGMT_FRAME_SUBTYPE(frame_control);
4902             if ((mgmt_tlv->frame_control.type == 0U) &&
4903                 ((frame_sub_type == SUBTYPE_ASSOC_REQUEST) || (frame_sub_type == SUBTYPE_REASSOC_REQUEST)))
4904             {
4905                 if (frame_sub_type == SUBTYPE_ASSOC_REQUEST)
4906                 {
4907                     assoc_ie_len = (t_u8)sizeof(IEEEtypes_AssocRqst_t);
4908                 }
4909                 else if (frame_sub_type == SUBTYPE_REASSOC_REQUEST)
4910                 {
4911                     assoc_ie_len = (t_u8)sizeof(IEEEtypes_ReAssocRqst_t);
4912                 }
4913                 else
4914                 { /* Do Nothing */
4915                 }
4916 
4917                 ie_len       = (t_u8)tlv_len - (t_u8)sizeof(IEEEtypes_FrameCtl_t) - assoc_ie_len;
4918                 assoc_req_ie = (t_u8 *)tlv + sizeof(MrvlIETypes_MgmtFrameSet_t) + assoc_ie_len;
4919                 pht_cap =
4920                     (IEEEtypes_HTCap_t *)(void *)wlan_get_specific_ie(priv, assoc_req_ie, ie_len, HT_CAPABILITY, 0);
4921 
4922                 if (pht_cap != NULL)
4923                 {
4924                     PRINTM(MCMND, "STA supports 11n\n");
4925                     sta_ptr->is_11n_enabled = MTRUE;
4926                     if (GETHT_MAXAMSDU(pht_cap->ht_cap.ht_cap_info) != 0U)
4927                     {
4928                         sta_ptr->max_amsdu = MLAN_TX_DATA_BUF_SIZE_8K;
4929                     }
4930                     else
4931                     {
4932                         sta_ptr->max_amsdu = MLAN_TX_DATA_BUF_SIZE_4K;
4933                     }
4934                 }
4935                 else
4936                 {
4937                     PRINTM(MCMND,
4938                            "STA doesn't "
4939                            "support 11n\n");
4940                 }
4941 #if CONFIG_11AC
4942                 pvht_cap =
4943                     (IEEEtypes_VHTCap_t *)(void *)wlan_get_specific_ie(priv, assoc_req_ie, ie_len, VHT_CAPABILITY, 0);
4944                 if ((pvht_cap != MNULL) && (priv->is_11ac_enabled == MTRUE))
4945                 {
4946                     PRINTM(MCMND, "STA supports 11ac\n");
4947                     sta_ptr->is_11ac_enabled = MTRUE;
4948                     if (GET_VHTCAP_MAXMPDULEN(wlan_le32_to_cpu(pvht_cap->vht_cap.vht_cap_info)) == 2U)
4949                     {
4950                         sta_ptr->max_amsdu = MLAN_TX_DATA_BUF_SIZE_12K;
4951                     }
4952                     else if (GET_VHTCAP_MAXMPDULEN(wlan_le32_to_cpu(pvht_cap->vht_cap.vht_cap_info)) == 1U)
4953                     {
4954                         sta_ptr->max_amsdu = MLAN_TX_DATA_BUF_SIZE_8K;
4955                     }
4956                     else
4957                     {
4958                         sta_ptr->max_amsdu = MLAN_TX_DATA_BUF_SIZE_4K;
4959                     }
4960                 }
4961                 else
4962                 {
4963                     PRINTM(MCMND, "STA doesn't support 11ac\n");
4964                 }
4965 #endif
4966 #if CONFIG_11AX
4967                 phe_cap =
4968                     (IEEEtypes_Extension_t *)wlan_get_specific_ie(priv, assoc_req_ie, ie_len, EXTENSION, HE_CAPABILITY);
4969                 if (phe_cap && (priv->is_11ax_enabled == MTRUE))
4970                 {
4971                     PRINTM(MCMND, "STA supports 11ax\n");
4972                     sta_ptr->is_11ax_enabled = MTRUE;
4973                     (void)memcpy((void *)((t_u8 *)&sta_ptr->he_cap), (const void *)phe_cap,
4974                                  phe_cap->ieee_hdr.len + sizeof(IEEEtypes_Header_t));
4975                     sta_ptr->he_cap.ieee_hdr.len =
4976                         MIN(phe_cap->ieee_hdr.len, sizeof(IEEEtypes_HECap_t) - sizeof(IEEEtypes_Header_t));
4977                 }
4978                 else
4979                     PRINTM(MCMND, "STA doesn't support 11ax\n");
4980 #endif
4981                 break;
4982             }
4983         }
4984         tlv_buf_left -= (int)sizeof(MrvlIEtypesHeader_t) + (int)tlv_len;
4985         tlv = (MrvlIEtypesHeader_t *)(void *)((t_u8 *)tlv + tlv_len + sizeof(MrvlIEtypesHeader_t));
4986     }
4987     LEAVE();
4988 
4989     return;
4990 }
4991 
4992 /** Fixed size of bss start event */
4993 #define BSS_START_EVENT_FIX_SIZE 12U
4994 
4995 /**
4996  *  @brief This function will search for the specific ie
4997  *
4998  *
4999  *  @param priv    A pointer to mlan_private
5000  *  @param pevent  A pointer to event buf
5001  *
5002  *  @return           N/A
5003  */
wrapper_wlan_check_uap_capability(pmlan_private priv,Event_Ext_t * pevent)5004 static void wrapper_wlan_check_uap_capability(pmlan_private priv, Event_Ext_t *pevent)
5005 {
5006     t_u16 tlv_type, tlv_len;
5007     int tlv_buf_left = (int)pevent->length - (int)INTF_HEADER_LEN - (int)BSS_START_EVENT_FIX_SIZE;
5008     MrvlIEtypesHeader_t *tlv =
5009         (MrvlIEtypesHeader_t *)(void *)((char *)pevent + INTF_HEADER_LEN + BSS_START_EVENT_FIX_SIZE);
5010 #if CONFIG_11AX
5011     MrvlIEtypes_He_cap_t *pext_tlv = MNULL;
5012 #endif
5013     priv->wmm_enabled    = MFALSE;
5014     priv->pkt_fwd        = 0U;
5015     priv->is_11n_enabled = MFALSE;
5016 #if CONFIG_11AC
5017     priv->is_11ac_enabled = MFALSE;
5018 #endif
5019 #if CONFIG_11AX
5020     priv->is_11ax_enabled = MFALSE;
5021 #endif
5022     ENTER();
5023 
5024     while (tlv_buf_left >= (int)sizeof(MrvlIEtypesHeader_t))
5025     {
5026         tlv_type = wlan_le16_to_cpu(tlv->type);
5027         tlv_len  = wlan_le16_to_cpu(tlv->len);
5028         if ((sizeof(MrvlIEtypesHeader_t) + tlv_len) > (unsigned int)tlv_buf_left)
5029         {
5030             PRINTM(MERROR, "wrong tlv: tlvLen=%d, tlvBufLeft=%d\n", tlv_len, tlv_buf_left);
5031             break;
5032         }
5033         if (tlv_type == (t_u16)HT_CAPABILITY)
5034         {
5035             DBG_HEXDUMP(MCMD_D, "HT_CAP tlv", tlv, tlv_len + sizeof(MrvlIEtypesHeader_t));
5036             priv->is_11n_enabled = MTRUE;
5037         }
5038 #if CONFIG_11AC
5039         if (tlv_type == (t_u16)VHT_CAPABILITY)
5040         {
5041             DBG_HEXDUMP(MCMD_D, "VHT_CAP tlv", tlv, tlv_len + sizeof(MrvlIEtypesHeader_t));
5042             priv->is_11ac_enabled = MTRUE;
5043         }
5044 #endif
5045 #if CONFIG_11AX
5046         if (tlv_type == EXTENSION)
5047         {
5048             pext_tlv = (MrvlIEtypes_He_cap_t *)tlv;
5049             if (pext_tlv->ext_id == HE_CAPABILITY)
5050             {
5051                 DBG_HEXDUMP(MCMD_D, "HE_CAP tlv", tlv, tlv_len + sizeof(MrvlIEtypesHeader_t));
5052                 priv->is_11ax_enabled = MTRUE;
5053             }
5054         }
5055 #endif
5056         if (tlv_type == (t_u16)TLV_TYPE_UAP_PKT_FWD_CTL)
5057         {
5058             DBG_HEXDUMP(MCMD_D, "pkt_fwd tlv", tlv, tlv_len + sizeof(MrvlIEtypesHeader_t));
5059             priv->pkt_fwd = *((t_u8 *)tlv + sizeof(MrvlIEtypesHeader_t));
5060             PRINTM(MCMND, "pkt_fwd FW: 0x%x\n", priv->pkt_fwd);
5061             if ((priv->pkt_fwd & PKT_FWD_FW_BIT) != 0U)
5062             {
5063                 priv->pkt_fwd = 0U;
5064             }
5065             else
5066             {
5067                 priv->pkt_fwd |= PKT_FWD_ENABLE_BIT;
5068             }
5069             PRINTM(MCMND, "pkt_fwd DRV: 0x%x\n", priv->pkt_fwd);
5070         }
5071         tlv_buf_left -= (int)sizeof(MrvlIEtypesHeader_t) + (int)tlv_len;
5072         tlv = (MrvlIEtypesHeader_t *)(void *)((t_u8 *)tlv + tlv_len + sizeof(MrvlIEtypesHeader_t));
5073     }
5074     LEAVE();
5075 }
5076 #endif /* CONFIG_UAP_AMPDU_TX || CONFIG_UAP_AMPDU_RX */
5077 
5078 #if (CONFIG_WNM_PS)
wlan_update_wnm_ps_status(wnm_ps_result * wnm_ps_result)5079 void wlan_update_wnm_ps_status(wnm_ps_result *wnm_ps_result)
5080 {
5081     if ((wnm_ps_result->action == 0) && (wnm_ps_result->result == 0))
5082     {
5083         /* Do nothing */
5084     }
5085     else if ((wnm_ps_result->action == 1) && (wnm_ps_result->result == 0))
5086     {
5087         ((mlan_private *)mlan_adap->priv[0])->wnm_set = false;
5088     }
5089     else if ((wnm_ps_result->action == 0) && (wnm_ps_result->result == 1))
5090     {
5091         ((mlan_private *)mlan_adap->priv[0])->wnm_set = false;
5092     }
5093     else if ((wnm_ps_result->action == 1) && (wnm_ps_result->result == 1))
5094     {
5095         /* Do nothing */
5096     }
5097     else
5098     {
5099         /* Do nothing */
5100     }
5101 }
5102 #endif
5103 
5104 #if CONFIG_WMM
wifi_wmm_queue_lock(mlan_private * priv,t_u8 ac)5105 static inline void wifi_wmm_queue_lock(mlan_private *priv, t_u8 ac)
5106 {
5107     priv->adapter->callbacks.moal_semaphore_get(priv->adapter->pmoal_handle, &priv->wmm.tid_tbl_ptr[ac].ra_list.plock);
5108 }
5109 
wifi_wmm_queue_unlock(mlan_private * priv,t_u8 ac)5110 static inline void wifi_wmm_queue_unlock(mlan_private *priv, t_u8 ac)
5111 {
5112     priv->adapter->callbacks.moal_semaphore_put(priv->adapter->pmoal_handle, &priv->wmm.tid_tbl_ptr[ac].ra_list.plock);
5113 }
5114 
wifi_wmm_trigger_tx(t_u8 tx_pause)5115 static inline void wifi_wmm_trigger_tx(t_u8 tx_pause)
5116 {
5117     if (tx_pause == MFALSE)
5118     {
5119         send_wifi_driver_tx_data_event(MLAN_BSS_TYPE_STA);
5120     }
5121 }
5122 
5123 /*
5124  *  update sta tx pause status
5125  *  trigger tx handler if this is an unpause event
5126  */
wifi_sta_handle_event_data_pause(mlan_private * priv,MrvlIEtypes_tx_pause_t * tx_pause_tlv)5127 static void wifi_sta_handle_event_data_pause(mlan_private *priv, MrvlIEtypes_tx_pause_t *tx_pause_tlv)
5128 {
5129     int i;
5130     t_u8 *bssid                         = MNULL;
5131     raListTbl *ra_list                  = MNULL;
5132     t_u8 zero_mac[MLAN_MAC_ADDR_LENGTH] = {0};
5133 
5134     if (!priv->media_connected)
5135         return;
5136 
5137     bssid = priv->curr_bss_params.bss_descriptor.mac_address;
5138     if (!__memcmp(mlan_adap, bssid, zero_mac, MLAN_MAC_ADDR_LENGTH))
5139         return;
5140 
5141     if (!__memcmp(mlan_adap, bssid, tx_pause_tlv->peermac, MLAN_MAC_ADDR_LENGTH))
5142     {
5143         priv->tx_pause = (tx_pause_tlv->tx_pause) ? MTRUE : MFALSE;
5144 
5145         /* update ralists for finding alternative buffer when queue full */
5146         for (i = 0; i < MAX_AC_QUEUES; i++)
5147         {
5148             wifi_wmm_queue_lock(priv, i);
5149 
5150             ra_list = wlan_wmm_get_ralist_node(priv, i, tx_pause_tlv->peermac);
5151             if (ra_list == MNULL)
5152             {
5153                 wifi_wmm_queue_unlock(priv, i);
5154                 continue;
5155             }
5156 
5157             ra_list->tx_pause = priv->tx_pause;
5158 
5159             wifi_wmm_queue_unlock(priv, i);
5160         }
5161     }
5162 
5163     wifi_wmm_trigger_tx(tx_pause_tlv->tx_pause);
5164 }
5165 
5166 /*
5167  *  update uap tx pause status
5168  *  for self address, update the whole priv interface status
5169  *  for other addresses, update corresponding ralist status
5170  *  trigger tx handler if this is an unpause event
5171  */
wifi_uap_handle_event_data_pause(mlan_private * priv_uap,MrvlIEtypes_tx_pause_t * tx_pause_tlv)5172 static void wifi_uap_handle_event_data_pause(mlan_private *priv_uap, MrvlIEtypes_tx_pause_t *tx_pause_tlv)
5173 {
5174     int i;
5175     raListTbl *ra_list = MNULL;
5176 
5177     if (!memcmp(priv_uap->curr_addr, tx_pause_tlv->peermac, MLAN_MAC_ADDR_LENGTH))
5178     {
5179         priv_uap->tx_pause = (tx_pause_tlv->tx_pause) ? MTRUE : MFALSE;
5180     }
5181     else
5182     {
5183         for (i = 0; i < MAX_AC_QUEUES; i++)
5184         {
5185             wifi_wmm_queue_lock(priv_uap, i);
5186 
5187             ra_list = wlan_wmm_get_ralist_node(priv_uap, i, tx_pause_tlv->peermac);
5188             if (ra_list == MNULL)
5189             {
5190                 wifi_wmm_queue_unlock(priv_uap, i);
5191                 continue;
5192             }
5193 
5194             ra_list->tx_pause = (tx_pause_tlv->tx_pause) ? MTRUE : MFALSE;
5195 
5196             wifi_wmm_queue_unlock(priv_uap, i);
5197         }
5198     }
5199 
5200     wifi_wmm_trigger_tx(tx_pause_tlv->tx_pause);
5201 }
5202 
wifi_handle_event_data_pause(void * data)5203 void wifi_handle_event_data_pause(void *data)
5204 {
5205     mlan_private *priv     = mlan_adap->priv[0];
5206     mlan_private *priv_uap = mlan_adap->priv[1];
5207     /* Event_Ext_t shares the same header but from reason_code, payload differs with tx_pause cmd */
5208     Event_Ext_t *evt = (Event_Ext_t *)data;
5209     t_u16 tlv_type, tlv_len;
5210     int tlv_buf_left         = evt->length - MLAN_FIELD_OFFSET(Event_Ext_t, reason_code);
5211     MrvlIEtypesHeader_t *tlv = (MrvlIEtypesHeader_t *)&evt->reason_code;
5212 
5213     /* set tx pause */
5214     while (tlv_buf_left >= (int)sizeof(MrvlIEtypesHeader_t))
5215     {
5216         tlv_type = wlan_le16_to_cpu(tlv->type);
5217         tlv_len  = wlan_le16_to_cpu(tlv->len);
5218 
5219         if ((sizeof(MrvlIEtypesHeader_t) + tlv_len) > (unsigned int)tlv_buf_left)
5220         {
5221             wifi_e("wrong tlv: tlvLen=%d, tlvBufLeft=%d", tlv_len, tlv_buf_left);
5222             break;
5223         }
5224 
5225         if (tlv_type == TLV_TYPE_TX_PAUSE)
5226         {
5227             if (evt->bss_type == MLAN_BSS_TYPE_STA)
5228             {
5229                 wifi_sta_handle_event_data_pause(priv, (MrvlIEtypes_tx_pause_t *)tlv);
5230             }
5231             else if (evt->bss_type == MLAN_BSS_TYPE_UAP)
5232             {
5233                 wifi_uap_handle_event_data_pause(priv_uap, (MrvlIEtypes_tx_pause_t *)tlv);
5234             }
5235             else
5236             {
5237                 wifi_w("Not support bss_type %d", evt->bss_type);
5238             }
5239         }
5240 
5241         /* iterate */
5242         tlv_buf_left -= (sizeof(MrvlIEtypesHeader_t) + tlv_len);
5243         tlv = (MrvlIEtypesHeader_t *)((t_u8 *)tlv + tlv_len + sizeof(MrvlIEtypesHeader_t));
5244     }
5245 }
5246 #endif
5247 
wifi_handle_event_tx_status_report(Event_Ext_t * evt)5248 static void wifi_handle_event_tx_status_report(Event_Ext_t *evt)
5249 {
5250 #if CONFIG_WPA_SUPP
5251     tx_status_event *tx_status = MNULL;
5252     unsigned int bss_type      = (unsigned int)evt->bss_type;
5253 
5254     tx_status = (tx_status_event *)(void *)&evt->reason_code;
5255 
5256     if (tx_status->packet_type == 0xe5)
5257     {
5258         if (tx_status->status == 0U)
5259         {
5260             (void)wifi_event_completion(WIFI_EVENT_MGMT_TX_STATUS, WIFI_EVENT_REASON_SUCCESS, (void *)bss_type);
5261         }
5262         return;
5263     }
5264 #endif
5265 
5266 #if CONFIG_1AS
5267     mlan_private *pmpriv = mlan_adap->priv[evt->bss_type];
5268 
5269     /* tx status event includes dot1as info */
5270     if (evt->length >= sizeof(tx_status_event) + MLAN_FIELD_OFFSET(Event_Ext_t, reason_code))
5271     {
5272         tx_status = (tx_status_event *)(void *)&evt->reason_code;
5273         if (tx_status->status == 0U)
5274         {
5275             pmpriv->dot1as_info.tm_num++;
5276             pmpriv->dot1as_info.dialog_token++;
5277             pmpriv->dot1as_info.prev_dialog_token++;
5278             pmpriv->dot1as_info.t1          = (t_u32)wlan_le32_to_cpu(tx_status->t1_tstamp);
5279             pmpriv->dot1as_info.t4          = (t_u32)wlan_le32_to_cpu(tx_status->t1_tstamp);
5280             pmpriv->dot1as_info.egress_time = wlan_le64_to_cpu(tx_status->egress_time);
5281             pmpriv->dot1as_info.t1_err      = (t_u8)tx_status->t1_error;
5282             pmpriv->dot1as_info.t4_err      = (t_u8)tx_status->t4_error;
5283 
5284             if (pmpriv->dot1as_info.tm_num >= pmpriv->dot1as_info.max_tm_num)
5285             {
5286                 wifi_end_timing_measurement((int)pmpriv->bss_index);
5287             }
5288             else if (wlan_send_timing_measurement_frame(pmpriv) != MLAN_STATUS_SUCCESS)
5289             {
5290                 wifi_e("wifi_handle_event_tx_status_report send next tm frame fail");
5291                 wifi_end_timing_measurement((int)pmpriv->bss_index);
5292             }
5293             else
5294             {
5295                 /* Do nothing */
5296             }
5297         }
5298         else
5299         {
5300             wifi_e("wifi_handle_event_tx_status_report send curr tm frame fail");
5301             wifi_end_timing_measurement((int)pmpriv->bss_index);
5302         }
5303     }
5304 #endif
5305 }
5306 
5307 #define REASON_CODE_BSS_BLOCKED 0x21
wifi_handle_blocked_sta_report(Event_Ext_t * evt)5308 static void wifi_handle_blocked_sta_report(Event_Ext_t *evt)
5309 {
5310     mlan_adapter *pmadapter = mlan_adap;
5311     t_u16 reason_code       = 0;
5312     int idx                 = 0;
5313 
5314     reason_code = evt->reason_code;
5315     if (reason_code == REASON_CODE_BSS_BLOCKED)
5316     {
5317         if (pmadapter->blacklist_bss.num_bssid == MLAN_MAX_BSS_NUM)
5318         {
5319             wifi_e("BSSID blacklist is full!");
5320             return;
5321         }
5322         idx = pmadapter->blacklist_bss.num_bssid;
5323         memcpy(pmadapter->blacklist_bss.bssids[idx], evt->src_mac_addr, MLAN_MAC_ADDR_LENGTH);
5324         pmadapter->blacklist_bss.num_bssid++;
5325         (void)PRINTF("Added BSSID ");
5326         print_mac((const char *)evt->src_mac_addr);
5327         (void)PRINTF("to blacklist\r\n");
5328     }
5329     else
5330         wifi_w("Unknown reason code! Ignore the event");
5331 }
5332 
5333 /* fixme: duplicated from legacy. needs to be cleaned up later */
5334 #define IEEEtypes_REASON_UNSPEC                     1U
5335 #define IEEEtypes_REASON_PRIOR_AUTH_INVALID         2U
5336 #define IEEEtypes_REASON_DEAUTH_LEAVING             3
5337 #define IEEEtypes_REASON_DISASSOC_DUE_TO_INACTIVITY 4U
5338 #define AP_DEAUTH_REASON_MAC_ADDR_BLOCKED           6U
5339 
5340 #if CONFIG_WIFI_TX_PER_TRACK
5341 #define OFFSET_SEQNUM 8
wifi_tx_pert_report(void * pbuf)5342 static void wifi_tx_pert_report(void *pbuf)
5343 {
5344     (void)PRINTF("current PER is %d%%\r\n", wlan_le16_to_cpu(*(t_u16 *)((t_u8 *)pbuf + 8)));
5345     (void)PRINTF("User configure:\r\n");
5346     (void)PRINTF("       tx_pert_check_period : %d sec\r\n", mlan_adap->tx_pert.tx_pert_check_peroid);
5347     (void)PRINTF("       tx_pert_check_ratio  : %d%%\r\n", mlan_adap->tx_pert.tx_pert_check_ratio);
5348     (void)PRINTF("       tx_pert_check_num    : %d\r\n", mlan_adap->tx_pert.tx_pert_check_num);
5349     return;
5350 }
5351 #endif
5352 
5353 #if CONFIG_BG_SCAN
wifi_request_bgscan(mlan_private * pmpriv)5354 int wifi_request_bgscan(mlan_private *pmpriv)
5355 {
5356     wifi_get_command_lock();
5357     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5358     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
5359     cmd->seq_num = 0;
5360     cmd->result  = 0x0;
5361     wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_BG_SCAN_CONFIG, HostCmd_ACT_GEN_SET, 0, NULL, &pmpriv->scan_cfg,
5362                              cmd);
5363     wifi_wait_for_cmdresp(NULL);
5364     return wm_wifi.cmd_resp_status;
5365 }
5366 #endif
5367 
wifi_set_rssi_low_threshold(uint8_t * low_rssi)5368 int wifi_set_rssi_low_threshold(uint8_t *low_rssi)
5369 {
5370 #if (CONFIG_11K) || (CONFIG_11V) || (CONFIG_ROAMING)
5371     mlan_private *pmpriv = mlan_adap->priv[0];
5372     mlan_ds_subscribe_evt subscribe_evt;
5373 
5374     wifi_get_command_lock();
5375     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5376     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
5377     cmd->seq_num                = 0;
5378     cmd->result                 = 0x0;
5379     subscribe_evt.evt_action    = SUBSCRIBE_EVT_ACT_BITWISE_SET;
5380     subscribe_evt.evt_bitmap    = SUBSCRIBE_EVT_RSSI_LOW;
5381     subscribe_evt.low_rssi      = *low_rssi;
5382     subscribe_evt.low_rssi_freq = 0;
5383     wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT, HostCmd_ACT_GEN_SET, 0, NULL, &subscribe_evt,
5384                              cmd);
5385     wifi_wait_for_cmdresp(NULL);
5386 
5387     return wm_wifi.cmd_resp_status;
5388 #else
5389     return 0;
5390 #endif
5391 }
5392 
5393 #if CONFIG_BG_SCAN
wifi_request_bgscan_query(mlan_private * pmpriv)5394 int wifi_request_bgscan_query(mlan_private *pmpriv)
5395 {
5396     wifi_get_command_lock();
5397     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5398     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
5399     cmd->seq_num = 0;
5400     cmd->result  = 0x0;
5401     wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_BG_SCAN_QUERY, HostCmd_ACT_GEN_GET, 0, NULL, NULL, cmd);
5402     wifi_wait_for_cmdresp(NULL);
5403     return wm_wifi.cmd_resp_status;
5404 }
5405 
wifi_config_bgscan_and_rssi(const char * ssid)5406 int wifi_config_bgscan_and_rssi(const char *ssid)
5407 {
5408     mlan_private *pmpriv = mlan_adap->priv[0];
5409     int band             = 0;
5410     int ret              = -WM_FAIL;
5411 
5412     ENTER();
5413 
5414     if (pmpriv->roaming_enabled == MFALSE)
5415     {
5416         wifi_d("Roaming is disabled");
5417         goto done;
5418     }
5419 
5420     memset(&pmpriv->scan_cfg, 0, sizeof(pmpriv->scan_cfg));
5421 
5422     if (wm_wifi.g_user_scan_cfg != NULL)
5423     {
5424         pmpriv->scan_cfg.start_later = MTRUE;
5425     }
5426 
5427     /* Fill scan config field for bg scan */
5428     strncpy((char *)pmpriv->scan_cfg.ssid_list[0].ssid, (char *)ssid, MLAN_MAX_SSID_LENGTH);
5429     pmpriv->scan_cfg.ssid_list[0].ssid[MLAN_MAX_SSID_LENGTH] = '\0';
5430     pmpriv->scan_cfg.ssid_list[0].max_len                    = 0x00;
5431     pmpriv->scan_cfg.report_condition                        = BG_SCAN_SSID_RSSI_MATCH | BG_SCAN_WAIT_ALL_CHAN_DONE;
5432     pmpriv->scan_cfg.rssi_threshold                          = pmpriv->rssi_low;
5433     pmpriv->scan_cfg.repeat_count                            = DEF_REPEAT_COUNT;
5434     pmpriv->scan_cfg.scan_interval                           = MIN_BGSCAN_INTERVAL;
5435     pmpriv->scan_cfg.chan_per_scan                           = WLAN_USER_SCAN_CHAN_MAX;
5436     pmpriv->scan_cfg.num_probes                              = 2;
5437 #if CONFIG_SCAN_CHANNEL_GAP
5438     pmpriv->scan_cfg.scan_chan_gap = SCAN_CHANNEL_GAP_VALUE;
5439 #endif
5440 
5441     wifi_get_band(pmpriv, &band);
5442     switch (band)
5443     {
5444         case WIFI_FREQUENCY_BAND_2GHZ:
5445             pmpriv->scan_cfg.chan_list[0].radio_type = 0 | BAND_SPECIFIED;
5446             break;
5447         case WIFI_FREQUENCY_BAND_5GHZ:
5448             pmpriv->scan_cfg.chan_list[0].radio_type = 1 | BAND_SPECIFIED;
5449             break;
5450         default:
5451             PRINTM(MINFO, "Unexpected freq band \n");
5452             break;
5453     }
5454     pmpriv->scan_cfg.bss_type = MLAN_BSS_MODE_INFRA;
5455     pmpriv->scan_cfg.action   = BG_SCAN_ACT_SET;
5456     pmpriv->scan_cfg.enable   = MTRUE;
5457     ret                       = wifi_request_bgscan(pmpriv);
5458     if (ret)
5459     {
5460         wifi_d("Failed to request bgscan");
5461     }
5462 
5463 done:
5464     LEAVE();
5465 
5466     return ret;
5467 }
5468 
wifi_stop_bgscan()5469 mlan_status wifi_stop_bgscan()
5470 {
5471     mlan_private *pmpriv = mlan_adap->priv[0];
5472     mlan_status ret      = MLAN_STATUS_SUCCESS;
5473 
5474     memset(&pmpriv->scan_cfg, 0, sizeof(pmpriv->scan_cfg));
5475     pmpriv->scan_cfg.bss_type = MLAN_BSS_MODE_INFRA;
5476     pmpriv->scan_cfg.action   = BG_SCAN_ACT_SET;
5477     pmpriv->scan_cfg.enable   = MFALSE;
5478     ret                       = (mlan_status)wifi_request_bgscan(pmpriv);
5479     if (ret)
5480         PRINTM(MERROR, "Failed to stop bgscan\n");
5481     return ret;
5482 }
5483 #endif
5484 
wifi_handle_fw_event(struct bus_message * msg)5485 int wifi_handle_fw_event(struct bus_message *msg)
5486 {
5487     mlan_private *pmpriv     = (mlan_private *)mlan_adap->priv[0];
5488     mlan_private *pmpriv_uap = (mlan_private *)mlan_adap->priv[1];
5489 #if CONFIG_WMM_UAPSD
5490     t_u8 tx_lock_flag_org = 0;
5491 #endif
5492 #if CONFIG_EXT_SCAN_SUPPORT
5493     mlan_status rv = MLAN_STATUS_SUCCESS;
5494 #endif
5495 
5496 #if CONFIG_WPA_SUPP
5497     struct wifi_nxp_ctx_rtos *wifi_if_ctx_rtos = (struct wifi_nxp_ctx_rtos *)wm_wifi.if_priv;
5498 #endif
5499 
5500     Event_Ext_t *evt = ((Event_Ext_t *)msg->data);
5501     t_u8 *sta_addr = NULL, *event_sta_addr = NULL;
5502     wifi_ecsa_info *pecsa_info = NULL;
5503     wifi_uap_client_disassoc_t *disassoc_resp;
5504 #if CONFIG_WLAN_BRIDGE
5505     Event_AutoLink_SW_Node_t *pnewNode = NULL;
5506     char *pinfo                        = NULL;
5507 #endif
5508 
5509 #if (CONFIG_UAP_AMPDU_TX) || (CONFIG_UAP_AMPDU_RX)
5510     sta_node *sta_node_ptr;
5511 #endif /* CONFIG_UAP_AMPDU_TX || CONFIG_UAP_AMPDU_RX */
5512 #if CONFIG_EXT_SCAN_SUPPORT
5513     mlan_event_scan_result *pext_scan_result;
5514 #endif
5515     if (evt == NULL)
5516     {
5517         wevt_d("No mem allocated for msg.data");
5518         return -WM_FAIL;
5519     }
5520 
5521 #if !CONFIG_WIFI_PS_DEBUG
5522     if ((evt->event_id != EVENT_PS_SLEEP) && (evt->event_id != EVENT_PS_AWAKE))
5523     {
5524         wevt_d("EVENT - : 0x%x Len : %d Reason: %d", evt->event_id, evt->length, evt->reason_code);
5525     }
5526 #else
5527     wevt_d("EVENT - : 0x%x Len : %d Reason: %d", evt->event_id, evt->length, evt->reason_code);
5528 #endif
5529 
5530     if ((evt->event_id != EVENT_PS_AWAKE) && (mlan_adap->ps_state == PS_STATE_SLEEP))
5531     {
5532         OSA_RWLockWriteUnlock(&sleep_rwlock);
5533         pmpriv->adapter->ps_state = PS_STATE_AWAKE;
5534     }
5535 
5536     switch (evt->event_id)
5537     {
5538         case EVENT_LINK_LOST:
5539             (void)wifi_event_completion(WIFI_EVENT_LINK_LOSS, WIFI_EVENT_REASON_FAILURE,
5540                                         (void *)IEEEtypes_REASON_DEAUTH_LEAVING);
5541 #if CONFIG_WPA_SUPP
5542             wifi_if_ctx_rtos->associated = MFALSE;
5543 
5544             wpa_supp_handle_link_lost(pmpriv);
5545 #endif
5546             wlan_handle_disconnect_event(pmpriv);
5547             break;
5548         case EVENT_DEAUTHENTICATED:
5549 #if CONFIG_WPA_SUPP
5550             wifi_if_ctx_rtos->associated = MFALSE;
5551 #endif
5552             if (evt->reason_code == 0U)
5553             {
5554                 (void)wifi_event_completion(WIFI_EVENT_LINK_LOSS, WIFI_EVENT_REASON_FAILURE,
5555                                             (void *)IEEEtypes_REASON_DEAUTH_LEAVING);
5556             }
5557             else
5558             {
5559                 (void)wifi_event_completion(WIFI_EVENT_AUTHENTICATION, WIFI_EVENT_REASON_FAILURE,
5560                                             (void *)&evt->reason_code);
5561             }
5562             wlan_handle_disconnect_event(pmpriv);
5563             break;
5564         case EVENT_DISASSOCIATED:
5565 #if CONFIG_WPA_SUPP
5566             wifi_if_ctx_rtos->associated = MFALSE;
5567 #endif
5568 
5569 #if !CONFIG_WPA_SUPP
5570             (void)wifi_event_completion(WIFI_EVENT_DISASSOCIATION, WIFI_EVENT_REASON_FAILURE,
5571                                         (void *)IEEEtypes_REASON_DEAUTH_LEAVING);
5572 #else
5573             (void)wifi_event_completion(WIFI_EVENT_DISASSOCIATION, WIFI_EVENT_REASON_SUCCESS,
5574                                         (void *)&evt->reason_code);
5575 #endif
5576             wlan_handle_disconnect_event(pmpriv);
5577             break;
5578         case EVENT_PORT_RELEASE:
5579             /* Open the port */
5580             if (pmpriv->port_ctrl_mode == MTRUE)
5581             {
5582                 PRINTM(MINFO, "PORT_REL: port_status = OPEN\n");
5583                 pmpriv->port_open = MTRUE;
5584             }
5585 #if !CONFIG_WPA_SUPP
5586             (void)wifi_event_completion(WIFI_EVENT_AUTHENTICATION, WIFI_EVENT_REASON_SUCCESS, NULL);
5587 #endif
5588             break;
5589         case EVENT_PS_SLEEP:
5590 #if CONFIG_WIFI_PS_DEBUG
5591             wevt_d("_");
5592 #endif
5593             if (mlan_adap->ps_state != PS_STATE_PRE_SLEEP)
5594             {
5595                 mlan_adap->ps_state = PS_STATE_PRE_SLEEP;
5596 #if CONFIG_HOST_SLEEP
5597                 wakelock_get();
5598 #endif
5599                 if (split_scan_in_progress == false)
5600                 {
5601                     /* When received EVENT_PS_SLEEP, firstly send msg to wifi_powersave task
5602                      * with lowest priority, then send msg to wlcmgr task. This will let all
5603                      * TX data transmitted, then continue the 0xe4 cmd handshake */
5604                     struct wifi_message ps_msg;
5605                     ps_msg.reason = WIFI_EVENT_REASON_SUCCESS;
5606                     ps_msg.event  = WIFI_EVENT_SLEEP;
5607                     OSA_MsgQPut((osa_msgq_handle_t)wm_wifi.powersave_queue, &ps_msg);
5608                 }
5609                 else
5610                 {
5611                     /** Do Nothing */
5612                 }
5613             }
5614             else
5615             {
5616                 /* Unexpected PS SLEEP event */
5617                 wevt_w("Receive PS SLEEP event when presleep: %d", mlan_adap->ps_state);
5618             }
5619             break;
5620         case EVENT_PS_AWAKE:
5621 #if CONFIG_WIFI_PS_DEBUG
5622             wevt_d("|");
5623 #endif
5624 #if CONFIG_WMM_UAPSD
5625             if (!pmpriv->adapter->pps_uapsd_mode && pmpriv->media_connected && pmpriv->adapter->sleep_period.period)
5626             {
5627                 pmpriv->adapter->pps_uapsd_mode = MTRUE;
5628                 PRINTM(MEVENT, "PPS/UAPSD mode activated\n");
5629             }
5630 
5631             tx_lock_flag_org = pmpriv->adapter->tx_lock_flag;
5632 
5633             if (pmpriv->adapter->pps_uapsd_mode)
5634             {
5635                 OSA_SemaphorePost((osa_semaphore_handle_t)uapsd_sem);
5636                 /* For the continous 0xA event handling case, wifi_driver_tx task
5637                  * is not allowed to send packets until the last 0xA is processed */
5638                 pmpriv->adapter->tx_lock_flag = MTRUE;
5639                 /* As the wifi_driver task has priority of 3, so sleep 1ms to yield to the CMD sending task */
5640                 OSA_TimeDelay(1);
5641             }
5642 
5643             /* If original tx_lock_flag is false, we don't change the tx_lock_flag to
5644              * false again, to avoid sending two last packets to FW in one sleep period */
5645             if (tx_lock_flag_org == MTRUE)
5646             {
5647                 pmpriv->adapter->tx_lock_flag = MFALSE;
5648             }
5649 
5650             if (pmpriv->adapter->pps_uapsd_mode && pmpriv->media_connected && pmpriv->adapter->gen_null_pkt &&
5651                 wifi_check_no_packet_indication(pmpriv))
5652             {
5653                 /* wifi_driver_tx task process the null packet sending */
5654                 send_wifi_driver_tx_null_data_event(MLAN_BSS_TYPE_STA);
5655             }
5656 #endif
5657             if (mlan_adap->ps_state == PS_STATE_SLEEP)
5658             {
5659                 OSA_RWLockWriteUnlock(&sleep_rwlock);
5660                 mlan_adap->ps_state = PS_STATE_AWAKE;
5661             }
5662             else if (mlan_adap->ps_state == PS_STATE_PRE_SLEEP)
5663             {
5664                 /* If driver did not send out sleep confirm in the expected time,
5665                    FW would take it as timeout, switch to awake and send out PS AWAKE event */
5666                 wevt_w("Receive PS AWAKE event when presleep: %d", mlan_adap->ps_state);
5667                 OSA_RWLockWriteUnlock(&sleep_rwlock);
5668                 mlan_adap->ps_state = PS_STATE_AWAKE;
5669             }
5670             else
5671             {
5672                 /*Do Nothing*/
5673             }
5674             break;
5675 #if (CONFIG_WNM_PS)
5676         case EVENT_WNM_PS:
5677         {
5678 #if !CONFIG_MEM_POOLS
5679             t_u16 *wnm_action_p = (t_u16 *)OSA_MemoryAllocate(sizeof(t_u16));
5680 #else
5681             t_u16 *wnm_action_p = (t_u16 *)OSA_MemoryPoolAllocate(buf_32_MemoryPool);
5682 #endif
5683             if (!wnm_action_p)
5684             {
5685                 wifi_w("No mem. Cannot process wnm ps event");
5686                 break;
5687             }
5688 
5689             *wnm_action_p = evt->reason_code;
5690             wlan_update_wnm_ps_status((wnm_ps_result *)wnm_action_p);
5691             if (wifi_event_completion(WIFI_EVENT_WNM_PS, WIFI_EVENT_REASON_SUCCESS,
5692                                        (void *)((t_u32)wnm_action_p)) != WM_SUCCESS)
5693             {
5694                 /* If fail to send message on queue, free allocated memory ! */
5695 #if !CONFIG_MEM_POOLS
5696                 OSA_MemoryFree((void *)wnm_action_p);
5697 #else
5698                 OSA_MemoryPoolFree(buf_32_MemoryPool, wnm_action_p);
5699 #endif
5700             }
5701         }
5702         break;
5703 #endif
5704         case EVENT_MIC_ERR_MULTICAST:
5705             (void)wifi_event_completion(WIFI_EVENT_ERR_MULTICAST, WIFI_EVENT_REASON_SUCCESS, NULL);
5706             break;
5707         case EVENT_MIC_ERR_UNICAST:
5708             (void)wifi_event_completion(WIFI_EVENT_ERR_UNICAST, WIFI_EVENT_REASON_SUCCESS, NULL);
5709             break;
5710 #if CONFIG_BG_SCAN
5711         case EVENT_BG_SCAN_REPORT:
5712             pmpriv->adapter->bgscan_reported = MTRUE;
5713             pmpriv->roaming_configured       = MFALSE;
5714             (void)wifi_event_completion(WIFI_EVENT_BG_SCAN_REPORT, WIFI_EVENT_REASON_SUCCESS, NULL);
5715             break;
5716         case EVENT_BG_SCAN_STOPPED:
5717             pmpriv->roaming_configured = MFALSE;
5718             (void)wifi_event_completion(WIFI_EVENT_BG_SCAN_STOPPED, WIFI_EVENT_REASON_SUCCESS, NULL);
5719             break;
5720 #endif
5721 #if CONFIG_P2P
5722         case EVENT_WIFIDIRECT_GENERIC_EVENT:
5723         case EVENT_WIFIDIRECT_SERVICE_DISCOVERY:
5724             wifi_d("EVENT: WIFIDIRECT event 0x%x\r\n", evt->event_id);
5725             wifi_wfd_event(true, false, &evt->event_id);
5726             break;
5727 #endif
5728 #if CONFIG_HOST_SLEEP
5729         case EVENT_HS_ACT_REQ:
5730             (void)wifi_event_completion(WIFI_EVENT_HS_CONFIG, WIFI_EVENT_REASON_SUCCESS, NULL);
5731             break;
5732 #endif
5733 #if CONFIG_11K_OFFLOAD
5734         case EVENT_NLIST_REPORT:
5735         {
5736             void *saved_event_buff = wifi_11k_save_request((Event_Gen_t *)(void *)((t_u8 *)evt + 4));
5737             if (saved_event_buff != NULL)
5738             {
5739                 if (wifi_event_completion(WIFI_EVENT_NLIST_REPORT, WIFI_EVENT_REASON_SUCCESS, saved_event_buff) !=
5740                     WM_SUCCESS)
5741                 {
5742                     /* If fail to send message on queue, free allocated memory ! */
5743 #if !CONFIG_MEM_POOLS
5744                     OSA_MemoryFree((void *)saved_event_buff);
5745 #else
5746                     OSA_MemoryPoolFree(buf_256_MemoryPool, saved_event_buff);
5747 #endif
5748                 }
5749             }
5750 
5751             /* If allocation failed ignore this event quietly ! */
5752         }
5753         break;
5754 #endif
5755 #ifdef SD9177
5756         case EVENT_IMD3_CAL_START:
5757             wifi_d("got event: IMD3 cal started");
5758             break;
5759         case EVENT_IMD3_CAL_END:
5760             wifi_d("got event: IMD3 cal stopped");
5761             break;
5762 #endif
5763         case EVENT_RSSI_LOW:
5764 #if CONFIG_WIFI_NM_WPA_SUPPLICANT
5765 #if !CONFIG_MEM_POOLS
5766             t_s16 *curr_rssi = (t_s16 *)OSA_MemoryAllocate(sizeof(t_s16));
5767 #else
5768             t_s16 *curr_rssi = (t_s16 *)OSA_MemoryPoolAllocate(buf_32_MemoryPool);
5769 #endif
5770             if (curr_rssi == MNULL)
5771             {
5772                 wifi_w("No mem. Failed to alloc memory for EVENT_RSSI_LOW");
5773                 break;
5774             }
5775             *curr_rssi = (t_s16)evt->reason_code;
5776             if(wifi_event_completion(WIFI_EVENT_RSSI_LOW,
5777                                      WIFI_EVENT_REASON_SUCCESS,
5778                                      (void *)curr_rssi) != WM_SUCCESS)
5779             {
5780 #if !CONFIG_MEM_POOLS
5781                 OSA_MemoryFree((void *)curr_rssi);
5782 #else
5783                 OSA_MemoryPoolFree(buf_32_MemoryPool, curr_rssi);
5784 #endif
5785             }
5786 #else
5787             (void)wifi_event_completion(WIFI_EVENT_RSSI_LOW, WIFI_EVENT_REASON_SUCCESS, NULL);
5788 #endif
5789             break;
5790 #if CONFIG_SUBSCRIBE_EVENT_SUPPORT
5791         case EVENT_RSSI_HIGH:
5792             (void)wifi_event_completion(WIFI_EVENT_RSSI_HIGH, WIFI_EVENT_REASON_SUCCESS, NULL);
5793             break;
5794         case EVENT_SNR_LOW:
5795             (void)wifi_event_completion(WIFI_EVENT_SNR_LOW, WIFI_EVENT_REASON_SUCCESS, NULL);
5796             break;
5797         case EVENT_SNR_HIGH:
5798             (void)wifi_event_completion(WIFI_EVENT_SNR_HIGH, WIFI_EVENT_REASON_SUCCESS, NULL);
5799             break;
5800         case EVENT_MAX_FAIL:
5801             (void)wifi_event_completion(WIFI_EVENT_MAX_FAIL, WIFI_EVENT_REASON_SUCCESS, NULL);
5802             break;
5803         case EVENT_DATA_RSSI_LOW:
5804             (void)wifi_event_completion(WIFI_EVENT_DATA_RSSI_LOW, WIFI_EVENT_REASON_SUCCESS, NULL);
5805             break;
5806         case EVENT_DATA_RSSI_HIGH:
5807             (void)wifi_event_completion(WIFI_EVENT_DATA_RSSI_HIGH, WIFI_EVENT_REASON_SUCCESS, NULL);
5808             break;
5809         case EVENT_DATA_SNR_LOW:
5810             (void)wifi_event_completion(WIFI_EVENT_DATA_SNR_LOW, WIFI_EVENT_REASON_SUCCESS, NULL);
5811             break;
5812         case EVENT_DATA_SNR_HIGH:
5813             (void)wifi_event_completion(WIFI_EVENT_DATA_SNR_HIGH, WIFI_EVENT_REASON_SUCCESS, NULL);
5814             break;
5815         case EVENT_LINK_QUALITY:
5816             (void)wifi_event_completion(WIFI_EVENT_FW_LINK_QUALITY, WIFI_EVENT_REASON_SUCCESS, NULL);
5817             break;
5818         case EVENT_PRE_BEACON_LOST:
5819             (void)wifi_event_completion(WIFI_EVENT_FW_PRE_BCN_LOST, WIFI_EVENT_REASON_SUCCESS, NULL);
5820             break;
5821 #endif
5822 #if CONFIG_11N
5823         case EVENT_ADDBA:
5824         {
5825             void *saved_event_buff = wifi_11n_save_request(evt);
5826             if (saved_event_buff != NULL)
5827             {
5828                 if (wifi_event_completion(WIFI_EVENT_11N_ADDBA, WIFI_EVENT_REASON_SUCCESS, saved_event_buff) !=
5829                     WM_SUCCESS)
5830                 {
5831                     /* If fail to send message on queue, free allocated memory ! */
5832 #if !CONFIG_MEM_POOLS
5833                     OSA_MemoryFree((void *)saved_event_buff);
5834 #else
5835                     OSA_MemoryPoolFree(buf_256_MemoryPool, saved_event_buff);
5836 #endif
5837                 }
5838             }
5839             /* If allocation failed ignore this event quietly ! */
5840         }
5841         break;
5842         case EVENT_DELBA:
5843         {
5844             wlan_11n_delete_bastream((mlan_private *)mlan_adap->priv[evt->bss_type], (t_u8 *)&evt->reason_code);
5845         }
5846         break;
5847         case EVENT_BA_STREAM_TIMEOUT:
5848         {
5849             void *saved_event_buff = wifi_11n_save_request(evt);
5850             if (saved_event_buff != NULL)
5851             {
5852                 if (wifi_event_completion(WIFI_EVENT_11N_BA_STREAM_TIMEOUT, WIFI_EVENT_REASON_SUCCESS,
5853                                           saved_event_buff) != WM_SUCCESS)
5854                 {
5855                     /* If fail to send message on queue, free allocated memory ! */
5856 #if !CONFIG_MEM_POOLS
5857                     OSA_MemoryFree((void *)saved_event_buff);
5858 #else
5859                     OSA_MemoryPoolFree(buf_256_MemoryPool, saved_event_buff);
5860 #endif
5861                 }
5862             }
5863             /* If allocation failed ignore this event quietly ! */
5864         }
5865         break;
5866         case EVENT_AMSDU_AGGR_CTRL:
5867             /*
5868              * Currently this event buffer isn't being used. Enable
5869              * this when required.
5870              */
5871             /* wifi_11n_save_request(evt); */
5872             (void)wifi_event_completion(WIFI_EVENT_11N_AGGR_CTRL, WIFI_EVENT_REASON_SUCCESS, NULL);
5873             break;
5874 #endif /* CONFIG_11N */
5875         case EVENT_CHANNEL_SWITCH_ANN:
5876             (void)wifi_event_completion(WIFI_EVENT_CHAN_SWITCH_ANN, WIFI_EVENT_REASON_SUCCESS, NULL);
5877             break;
5878         case EVENT_CHANNEL_SWITCH:
5879         {
5880 #if !CONFIG_MEM_POOLS
5881             pecsa_info = OSA_MemoryAllocate(sizeof(wifi_ecsa_info));
5882 #else
5883             pecsa_info = OSA_MemoryPoolAllocate(buf_32_MemoryPool);
5884 #endif
5885             if (!pecsa_info)
5886             {
5887                 wifi_w("No mem. Cannot process new channel from channel switch");
5888                 break;
5889             }
5890 
5891             MrvlIEtypes_channel_band_t *tlv = (MrvlIEtypes_channel_band_t *)&evt->reason_code;
5892 
5893             pecsa_info->bss_type    = evt->bss_type;
5894             pecsa_info->band_config = tlv->band_config;
5895             pecsa_info->channel     = tlv->channel;
5896 
5897             if (wifi_event_completion(WIFI_EVENT_CHAN_SWITCH, WIFI_EVENT_REASON_SUCCESS, pecsa_info) != WM_SUCCESS)
5898             {
5899                 /* If fail to send message on queue, free allocated memory ! */
5900 #if !CONFIG_MEM_POOLS
5901                 OSA_MemoryFree((void *)pecsa_info);
5902 #else
5903                 OSA_MemoryPoolFree(buf_32_MemoryPool, pecsa_info);
5904 #endif
5905             }
5906         }
5907         break;
5908         case EVENT_MICRO_AP_STA_ASSOC:
5909         {
5910             /*
5911              * Alloc memory to store the STA mac id. This will be
5912              * passed to event receiver thread. Freeing this is
5913              * responsibility of the receiving thread.
5914              */
5915 #if !CONFIG_MEM_POOLS
5916             sta_addr = OSA_MemoryAllocate(MLAN_MAC_ADDR_LENGTH);
5917 #else
5918             sta_addr = OSA_MemoryPoolAllocate(buf_32_MemoryPool);
5919 #endif
5920             if (sta_addr == MNULL)
5921             {
5922                 wifi_w("No mem. Cannot process MAC address from assoc");
5923                 break;
5924             }
5925 
5926             event_sta_addr = (t_u8 *)&evt->src_mac_addr;
5927             (void)memcpy((void *)sta_addr, (const void *)event_sta_addr, MLAN_MAC_ADDR_LENGTH);
5928 
5929 #if (CONFIG_UAP_AMPDU_TX) || (CONFIG_UAP_AMPDU_RX)
5930             wlan_request_ralist_lock(mlan_adap->priv[1]);
5931             /* Clear corresponding tx/rx table if necessary */
5932             if (wlan_11n_get_txbastream_tbl((mlan_private *)mlan_adap->priv[1], sta_addr))
5933                 wlan_11n_delete_txbastream_tbl_entry((mlan_private *)mlan_adap->priv[1], sta_addr);
5934 
5935             wlan_cleanup_reorder_tbl((mlan_private *)mlan_adap->priv[1], sta_addr);
5936 #if CONFIG_WMM
5937             wlan_ralist_del_enh(mlan_adap->priv[1], sta_addr);
5938 #endif
5939             /* txbastream table also is used as connected STAs data base */
5940             wlan_11n_create_txbastream_tbl((mlan_private *)mlan_adap->priv[1], sta_addr, BA_STREAM_NOT_SETUP);
5941             wlan_11n_update_txbastream_tbl_tx_thresh((mlan_private *)mlan_adap->priv[1], sta_addr, 3);
5942 
5943 #if !CONFIG_MEM_POOLS
5944             sta_node_ptr = OSA_MemoryAllocate(sizeof(sta_node));
5945 #else
5946             sta_node_ptr = OSA_MemoryPoolAllocate(buf_256_MemoryPool);
5947 #endif
5948             if (sta_node_ptr == MNULL)
5949             {
5950                 wifi_w("No mem. Cannot check station type");
5951                 wlan_release_ralist_lock(mlan_adap->priv[1]);
5952 #if !CONFIG_MEM_POOLS
5953                 OSA_MemoryFree(sta_addr);
5954 #else
5955                 OSA_MemoryPoolFree(buf_32_MemoryPool, sta_addr);
5956 #endif
5957                 break;
5958             }
5959             memset(sta_node_ptr, 0x00, sizeof(sta_node));
5960 
5961             wrapper_wlan_check_sta_capability((mlan_private *)mlan_adap->priv[1], msg->data, sta_node_ptr);
5962 
5963             if (sta_node_ptr->is_11n_enabled)
5964             {
5965                 wlan_11n_update_txbastream_tbl_ampdu_supported((mlan_private *)mlan_adap->priv[1], sta_addr, MTRUE);
5966             }
5967 
5968             wlan_release_ralist_lock(mlan_adap->priv[1]);
5969 
5970 #if !CONFIG_MEM_POOLS
5971             OSA_MemoryFree(sta_node_ptr);
5972 #else
5973             OSA_MemoryPoolFree(buf_256_MemoryPool, sta_node_ptr);
5974 #endif
5975 
5976 #endif /* CONFIG_UAP_AMPDU_TX || CONFIG_UAP_AMPDU_RX */
5977 
5978 #if CONFIG_WMM
5979             wlan_ralist_add_enh(mlan_adap->priv[1], sta_addr);
5980 #endif
5981 
5982             if (wifi_event_completion(WIFI_EVENT_UAP_CLIENT_ASSOC, WIFI_EVENT_REASON_SUCCESS, sta_addr) != WM_SUCCESS)
5983             {
5984                 /* If fail to send message on queue, free allocated memory ! */
5985 #if !CONFIG_MEM_POOLS
5986                 OSA_MemoryFree((void *)sta_addr);
5987 #else
5988                 OSA_MemoryPoolFree(buf_32_MemoryPool, sta_addr);
5989 #endif
5990             }
5991         }
5992         break;
5993         case EVENT_MICRO_AP_RSN_CONNECT:
5994         {
5995             /*
5996              * Alloc memory to store the STA mac id. This will be
5997              * passed to event receiver thread. Freeing this is
5998              * responsibility of the receiving thread.
5999              */
6000 #if !CONFIG_MEM_POOLS
6001             sta_addr = OSA_MemoryAllocate(MLAN_MAC_ADDR_LENGTH);
6002 #else
6003             sta_addr = OSA_MemoryPoolAllocate(buf_32_MemoryPool);
6004 #endif
6005             if (sta_addr == MNULL)
6006             {
6007                 wifi_w("No mem. Cannot process MAC address from conn");
6008                 break;
6009             }
6010 
6011             event_sta_addr = (t_u8 *)&evt->src_mac_addr;
6012             (void)memcpy((void *)sta_addr, (const void *)event_sta_addr, MLAN_MAC_ADDR_LENGTH);
6013             if (wifi_event_completion(WIFI_EVENT_UAP_CLIENT_CONN, WIFI_EVENT_REASON_SUCCESS, sta_addr) != WM_SUCCESS)
6014             {
6015                 /* If fail to send message on queue, free allocated memory ! */
6016 #if !CONFIG_MEM_POOLS
6017                 OSA_MemoryFree((void *)sta_addr);
6018 #else
6019                 OSA_MemoryPoolFree(buf_32_MemoryPool, sta_addr);
6020 #endif
6021             }
6022         }
6023         break;
6024         case EVENT_MICRO_AP_STA_DEAUTH:
6025             /*
6026              * Alloc memory to store the STA mac id. This will be
6027              * passed to event receiver thread. Freeing this is
6028              * responsibility of the receiving thread.
6029              */
6030 #if !CONFIG_MEM_POOLS
6031             disassoc_resp = OSA_MemoryAllocate(sizeof(wifi_uap_client_disassoc_t));
6032 #else
6033             disassoc_resp = OSA_MemoryPoolAllocate(buf_32_MemoryPool);
6034 #endif
6035             if (disassoc_resp == MNULL)
6036             {
6037                 wifi_w("No mem. Cannot add mac and reason code for deauth event to app");
6038                 break;
6039             }
6040             sta_addr                   = disassoc_resp->sta_addr;
6041             disassoc_resp->reason_code = (int)evt->reason_code;
6042 
6043             event_sta_addr = (t_u8 *)&evt->src_mac_addr;
6044             (void)memcpy((void *)sta_addr, (const void *)event_sta_addr, MLAN_MAC_ADDR_LENGTH);
6045 
6046 #if (CONFIG_UAP_AMPDU_TX) || (CONFIG_UAP_AMPDU_RX)
6047             if (pmpriv_uap->is_11n_enabled)
6048             {
6049                 wlan_cleanup_reorder_tbl(pmpriv_uap, sta_addr);
6050                 wlan_request_ralist_lock(pmpriv_uap);
6051                 wlan_11n_delete_txbastream_tbl_entry(pmpriv_uap, sta_addr);
6052                 wlan_release_ralist_lock(pmpriv_uap);
6053             }
6054 #endif /* CONFIG_UAP_AMPDU_TX || CONFIG_UAP_AMPDU_RX */
6055 
6056             wlan_delete_station_entry(pmpriv_uap, sta_addr);
6057 
6058 #ifdef CONFIG_WPA_SUPP_AP
6059             /* BIT 14 indicate deauth is initiated by FW */
6060             if (disassoc_resp->reason_code & MBIT(14))
6061             {
6062                 if (disassoc_resp->reason_code & MBIT(1))
6063                 {
6064                     t_u16 reason_code = IEEEtypes_REASON_DISASSOC_DUE_TO_INACTIVITY;
6065                     wifi_nxp_uap_disconnect(pmpriv_uap, reason_code, sta_addr);
6066                 }
6067                 else
6068                 {
6069                     wifi_nxp_uap_disconnect(pmpriv_uap, 0, sta_addr);
6070                 }
6071             }
6072 #endif
6073 
6074             if (wifi_event_completion(WIFI_EVENT_UAP_CLIENT_DEAUTH, WIFI_EVENT_REASON_SUCCESS, disassoc_resp) !=
6075                 WM_SUCCESS)
6076             {
6077                 /* If fail to send message on queue, free allocated memory ! */
6078 #if !CONFIG_MEM_POOLS
6079                 OSA_MemoryFree((void *)disassoc_resp);
6080 #else
6081                 OSA_MemoryPoolFree(buf_32_MemoryPool, disassoc_resp);
6082 #endif
6083             }
6084 #if CONFIG_WMM
6085             wlan_ralist_del_enh(mlan_adap->priv[1], evt->src_mac_addr);
6086 #endif
6087             if (evt->reason_code == AP_DEAUTH_REASON_MAC_ADDR_BLOCKED)
6088             {
6089                 wevt_d("EVENT: Blacklist sta %02x:%02x:%02x:%02x:%02x:%02x: try to join the network \r\n",
6090                        evt->src_mac_addr[0], evt->src_mac_addr[1], evt->src_mac_addr[2], evt->src_mac_addr[3],
6091                        evt->src_mac_addr[4], evt->src_mac_addr[5]);
6092             }
6093             break;
6094         case EVENT_MICRO_AP_BSS_START:
6095             wifi_d("uAP start event received");
6096             /*
6097              * wmsdk: statement copied from
6098              * mlan_uap_cmdevent.c. Necessary for other uAP functions.
6099              */
6100 #if (CONFIG_UAP_AMPDU_TX) || (CONFIG_UAP_AMPDU_RX)
6101             wrapper_wlan_check_uap_capability((mlan_private *)mlan_adap->priv[1], msg->data);
6102 #endif /* CONFIG_UAP_AMPDU_TX || CONFIG_UAP_AMPDU_RX */
6103             pmpriv_uap->uap_bss_started = MTRUE;
6104             /* set uap mac addr */
6105             (void)memcpy((void *)pmpriv_uap->curr_addr, (const void *)evt->src_mac_addr, (size_t)MLAN_MAC_ADDR_LENGTH);
6106             break;
6107         case EVENT_MICRO_AP_BSS_ACTIVE:
6108             PRINTM(MEVENT, "EVENT: MICRO_AP_BSS_ACTIVE\n");
6109             pmpriv_uap->media_connected = MTRUE;
6110             break;
6111         case EVENT_MICRO_AP_BSS_IDLE:
6112             PRINTM(MEVENT, "EVENT: MICRO_AP_BSS_IDLE\n");
6113             pmpriv_uap->media_connected = MFALSE;
6114             wlan_clean_txrx(pmpriv_uap);
6115             wlan_delete_station_list(pmpriv_uap);
6116             break;
6117 #if CONFIG_WMM
6118         case EVENT_TX_DATA_PAUSE:
6119             wifi_handle_event_data_pause(evt);
6120             break;
6121 #endif
6122 #if CONFIG_WIFI_TX_PER_TRACK
6123         case EVENT_PER_STATUS_REPORT:
6124             PRINTM(MEVENT, "EVENT: PER_STATUS_REPORT\n");
6125             wifi_tx_pert_report((void *)evt);
6126             break;
6127 #endif
6128         case EVENT_TX_STATUS_REPORT:
6129             wifi_handle_event_tx_status_report(evt);
6130             break;
6131         case EVENT_BLOCKEDSTA_AUTH_REPORT:
6132             wifi_handle_blocked_sta_report(evt);
6133             break;
6134 #if CONFIG_WLAN_BRIDGE
6135         case EVENT_AUTO_LINK_SWITCH_NEW_NODE:
6136             pnewNode = (Event_AutoLink_SW_Node_t *)msg->data;
6137             pinfo    = OSA_MemoryAllocate(pnewNode->length);
6138             if (!pinfo)
6139             {
6140                 wifi_w("No mem. Cannot process auto link switch network info");
6141                 break;
6142             }
6143             (void)memcpy((void *)pinfo, (const void *)pnewNode, pnewNode->length);
6144             if (wifi_event_completion(WIFI_EVENT_AUTOLINK_NETWORK_SWITCHED, WIFI_EVENT_REASON_SUCCESS, pinfo) !=
6145                 WM_SUCCESS)
6146             {
6147                 /* If fail to send message on queue, free allocated memory ! */
6148                 OSA_MemoryFree((void *)pinfo);
6149             }
6150             break;
6151 #endif
6152 #if CONFIG_EXT_SCAN_SUPPORT
6153         case EVENT_EXT_SCAN_REPORT:
6154             pext_scan_result = (mlan_event_scan_result *)((t_u8 *)msg->data + 4);
6155 
6156             rv = wlan_handle_event_ext_scan_report(pmpriv, (t_u8 *)pext_scan_result);
6157 
6158             if (rv != MLAN_STATUS_SUCCESS)
6159             {
6160                 wifi_user_scan_config_cleanup();
6161                 return -WM_FAIL;
6162             }
6163             if (is_split_scan_complete() && !pext_scan_result->more_event)
6164             {
6165                 wifi_d("Split scan complete");
6166                 wifi_user_scan_config_cleanup();
6167                 wifi_event_completion(WIFI_EVENT_SCAN_RESULT, WIFI_EVENT_REASON_SUCCESS, NULL);
6168             }
6169             break;
6170 #endif
6171 #if CONFIG_WIFI_FW_DEBUG
6172         case EVENT_FW_DEBUG_INFO:
6173         {
6174 #if !CONFIG_MEM_POOLS
6175             t_u8 *debug = (t_u8 *)OSA_MemoryAllocate(FW_DEBUG_INFO_SIZE);
6176 #else
6177             t_u8 *debug = (t_u8 *)OSA_MemoryPoolAllocate(buf_512_MemoryPool);
6178 #endif
6179             if (!debug)
6180             {
6181                 wifi_w("No mem. Cannot print debug event");
6182                 break;
6183             }
6184 
6185             (void)memcpy((void *)debug, (const void *)((uint8_t *)&evt->reason_code), evt->length - 8);
6186             (void)PRINTF("EVENT: FW Debug Info %s\r\n", debug);
6187 #if !CONFIG_MEM_POOLS
6188             OSA_MemoryFree((void *)debug);
6189 #else
6190             OSA_MemoryPoolFree(buf_512_MemoryPool, debug);
6191 #endif
6192         }
6193         break;
6194 #endif
6195 #if (CONFIG_CSI) || (((CONFIG_11AZ) || (CONFIG_11MC)))
6196         case EVENT_CSI:
6197         {
6198             PRINTM(MEVENT, "EVENT: EVENT_CSI\n");
6199 #if CONFIG_CSI
6200             csi_deliver_data_to_user();
6201 #endif
6202 #if (CONFIG_11AZ) || (CONFIG_11MC)
6203 #if CONFIG_WLS_CSI_PROC
6204             // wifi_get_wls_csi_sem(); // Get wls csi sem to prevent CSI event raw data from being overwritten before
6205             //  processing.
6206             memcpy(wls_data, (t_u8 *)msg->data, WLS_CSI_DATA_LEN);
6207             wifi_event_completion(WIFI_EVENT_WLS_CSI, WIFI_EVENT_REASON_SUCCESS, wls_data);
6208 #endif
6209 #endif
6210         }
6211         break;
6212 #endif
6213         case EVENT_MEF_HOST_WAKEUP:
6214             wifi_d("Host recevied host wake-up event from firmware");
6215             break;
6216 #if CONFIG_RSN_REPLAY_DETECTION
6217         case EVENT_RESET_PN_ON_REKEY:
6218             PRINTM(MEVENT, "EVENT: RESET PN ON REKEY\n");
6219             wlan_reset_pn_on_rekey(pmpriv, (t_u8 *)(msg->data) + 8);
6220             break;
6221 #endif
6222 #if CONFIG_MULTI_CHAN
6223         case EVENT_MULTI_CHAN_INFO:
6224             break;
6225 #endif
6226 #if CONFIG_WPA_SUPP
6227         case EVENT_ASSOC_REQ_IE:
6228 #if CONFIG_AUTO_RECONNECT
6229             if (pmpriv->media_connected == MTRUE)
6230             {
6231                 wifi_event_completion(WIFI_EVENT_ASSOCIATION_NOTIFY, WIFI_EVENT_REASON_SUCCESS, NULL);
6232             }
6233 #endif
6234             pmpriv->assoc_req_size = evt->length - 8;
6235             (void)memcpy((void *)pmpriv->assoc_req_buf, (const void *)((uint8_t *)&evt->reason_code),
6236                          pmpriv->assoc_req_size);
6237             break;
6238 #endif
6239 #if CONFIG_5GHz_SUPPORT
6240         case EVENT_RADAR_DETECTED:
6241             wevt_d("EVENT:RADAR_DETECTED -> detect_count=%d, reg_domain=%d, det_type=%d(%s)\n",
6242                    wlan_le32_to_cpu(((Event_Radar_Detected_Info *)msg->data)->detect_count),
6243                    ((Event_Radar_Detected_Info *)msg->data)->reg_domain,
6244                    ((Event_Radar_Detected_Info *)msg->data)->main_det_type,
6245                    (((Event_Radar_Detected_Info *)msg->data)->main_det_type == 2) ? "PRI" :
6246                    (((Event_Radar_Detected_Info *)msg->data)->main_det_type == 1) ? "PW" :
6247                                                                                     "");
6248 
6249             break;
6250 #endif
6251 #if CONFIG_CLOUD_KEEP_ALIVE
6252         case EVENT_CLOUD_KEEP_ALIVE_RETRY_FAIL:
6253             wevt_d("EVENT: EVENT_CLOUD_KEEP_ALIVE_RETRY_FAIL received\n\r");
6254             break;
6255 #endif
6256 #if (CONFIG_11MC) || (CONFIG_11AZ)
6257         case EVENT_WLS_FTM_COMPLETE:
6258             wifi_ftm_process_event(msg->data);
6259             break;
6260 #endif
6261         case EVENT_ACCESS_BY_HOST:
6262             break;
6263 #if CONFIG_WMM
6264         case EVENT_REMAIN_ON_CHANNEL_EXPIRED:
6265             mlan_adap->remain_on_channel = MFALSE;
6266             /* Restore tx after remain on channel expired */
6267             wifi_set_tx_status(WIFI_DATA_RUNNING);
6268 
6269             send_wifi_driver_tx_data_event(MLAN_BSS_TYPE_STA);
6270             send_wifi_driver_tx_data_event(MLAN_BSS_TYPE_UAP);
6271             break;
6272 #endif
6273         default:
6274             wifi_d("Event 0x%x not implemented", evt->event_id);
6275             break;
6276     }
6277 
6278     return WM_SUCCESS;
6279 }
6280 
process_rsn_ie(t_u8 * rsn_ie,_Cipher_t * mcstCipher,_Cipher_t * ucstCipher,t_u8 * ap_mfpc,t_u8 * ap_mfpr,_SecurityMode_t * WPA_WPA2_WEP)6281 static void process_rsn_ie(t_u8 *rsn_ie,
6282                            _Cipher_t *mcstCipher,
6283                            _Cipher_t *ucstCipher,
6284                            t_u8 *ap_mfpc,
6285                            t_u8 *ap_mfpr,
6286                            _SecurityMode_t *WPA_WPA2_WEP)
6287 {
6288     t_u8 *temp;
6289     t_u16 count;
6290     t_u16 group_cipher_count    = 0;
6291     t_u16 pairwise_cipher_count = 0;
6292     t_u16 akm_suite_count       = 0;
6293     t_u16 rsn_cap               = 0;
6294     t_u8 wpa2_oui01[4]          = {0x00, 0x0f, 0xac, 0x01};
6295     t_u8 wpa2_oui02[4]          = {0x00, 0x0f, 0xac, 0x02};
6296     t_u8 wpa2_oui04[4]          = {0x00, 0x0f, 0xac, 0x04};
6297     t_u8 wpa2_oui05[4]          = {0x00, 0x0f, 0xac, 0x05};
6298     t_u8 wpa2_oui06[4]          = {0x00, 0x0f, 0xac, 0x06};
6299 
6300     t_u8 wpa3_oui08[4] = {0x00, 0x0f, 0xac, 0x08};
6301     t_u8 wpa3_oui0b[4] = {0x00, 0x0f, 0xac, 0x0b};
6302     t_u8 wpa3_oui0c[4] = {0x00, 0x0f, 0xac, 0x0c};
6303 #if CONFIG_DRIVER_OWE
6304     t_u8 wpa3_oui12[4] = {0x00, 0x0f, 0xac, 0x12};
6305 #endif
6306 #if CONFIG_11R
6307     t_u8 rsn_ft_1x_oui[4]  = {0x00, 0x0f, 0xac, 0x03};
6308     t_u8 rsn_ft_psk_oui[4] = {0x00, 0x0f, 0xac, 0x04};
6309     t_u8 rsn_ft_sae_oui[4] = {0x00, 0x0f, 0xac, 0x09};
6310     t_u8 wpa3_oui0d[4]     = {0x00, 0x0f, 0xac, 0x0d};
6311 #endif
6312 
6313     ENTER();
6314 
6315     if (rsn_ie == MNULL)
6316     {
6317         goto done;
6318     }
6319     else
6320     {
6321         /* Do nothing */
6322     }
6323 
6324     if (rsn_ie[0] != (t_u8)RSN_IE)
6325     {
6326         goto done;
6327     }
6328     else
6329     {
6330         /* Do nothing */
6331     }
6332     /*  2 bytes header + 2 bytes version + 4 bytes group_cipher_suite +
6333      *  2 bytes pairwise_cipher_count + pairwise_cipher_count *
6334      * PAIRWISE_CIPHER_SUITE_LEN (4) + 2 bytes akm_suite_count +
6335      * akm_suite_count * AKM_SUITE_LEN (4)
6336      */
6337     count              = *(t_u16 *)(void *)(rsn_ie + 2);
6338     count              = wlan_le16_to_cpu(count);
6339     group_cipher_count = count;
6340     temp               = (t_u8 *)(rsn_ie + 2 + sizeof(t_u16));
6341 
6342     while (count > 0U)
6343     {
6344         if (!memcmp(temp, (const void *)wpa2_oui04, sizeof(wpa2_oui04)))
6345         {
6346             mcstCipher->ccmp = true;
6347         }
6348         else if (!memcmp(temp, (const void *)wpa2_oui02, sizeof(wpa2_oui02)))
6349         {
6350             mcstCipher->tkip = true;
6351         }
6352         else if (!memcmp(temp, (const void *)wpa2_oui05, sizeof(wpa2_oui05)))
6353         {
6354             mcstCipher->wep104 = true;
6355         }
6356         else if (!memcmp(temp, (const void *)wpa2_oui01, sizeof(wpa2_oui01)))
6357         {
6358             mcstCipher->wep40 = true;
6359         }
6360         else
6361         { /* Do nothing */
6362         }
6363         count--;
6364         temp += 4;
6365     }
6366 
6367     count                 = *(t_u16 *)(void *)(rsn_ie + 2 + sizeof(t_u16) + (int)group_cipher_count * 4);
6368     count                 = wlan_le16_to_cpu(count);
6369     pairwise_cipher_count = count;
6370 
6371     temp = (t_u8 *)(rsn_ie + 2 + sizeof(t_u16) + (int)group_cipher_count * 4 + (int)sizeof(t_u16));
6372 
6373     while (count > 0U)
6374     {
6375         if (!memcmp(temp, (const void *)wpa2_oui04, sizeof(wpa2_oui04)))
6376         {
6377             ucstCipher->ccmp = true;
6378         }
6379         else if (!memcmp(temp, (const void *)wpa2_oui02, sizeof(wpa2_oui02)))
6380         {
6381             ucstCipher->tkip = true;
6382         }
6383         else
6384         { /* Do Nothing */
6385         }
6386         count--;
6387         temp += 4;
6388     }
6389 
6390     count           = *(t_u16 *)(void *)(rsn_ie + 2 + sizeof(t_u16) + (int)group_cipher_count * 4 + (int)sizeof(t_u16) +
6391                                (int)pairwise_cipher_count * 4);
6392     count           = wlan_le16_to_cpu(count);
6393     akm_suite_count = count;
6394 
6395     temp = (t_u8 *)(rsn_ie + 2 + sizeof(t_u16) + (int)group_cipher_count * 4 + (int)sizeof(t_u16) +
6396                     (int)pairwise_cipher_count * 4 + (int)sizeof(t_u16));
6397 
6398     while (count > 0U)
6399     {
6400         if (memcmp(temp, wpa3_oui08, sizeof(wpa3_oui08)) == 0)
6401         {
6402             WPA_WPA2_WEP->wpa3_sae = 1;
6403         }
6404         else if (memcmp(temp, wpa3_oui0b, sizeof(wpa3_oui0b)) == 0)
6405         {
6406             WPA_WPA2_WEP->wpa3_1x_sha256 = 1;
6407         }
6408         else if (memcmp(temp, wpa3_oui0c, sizeof(wpa3_oui0c)) == 0)
6409         {
6410             WPA_WPA2_WEP->wpa3_1x_sha384 = 1;
6411         }
6412 #if CONFIG_DRIVER_OWE
6413         else if (memcmp(temp, wpa3_oui12, sizeof(wpa3_oui12)) == 0)
6414         {
6415             WPA_WPA2_WEP->owe = 1;
6416         }
6417 #endif
6418         else if (memcmp(temp, wpa2_oui01, sizeof(wpa2_oui01)) == 0)
6419         {
6420             WPA_WPA2_WEP->wpa2_entp = 1;
6421         }
6422         else if (memcmp(temp, wpa2_oui02, sizeof(wpa2_oui02)) == 0)
6423         {
6424             WPA_WPA2_WEP->wpa2 = 1;
6425         }
6426         else if (memcmp(temp, wpa2_oui05, sizeof(wpa2_oui05)) == 0)
6427         {
6428             WPA_WPA2_WEP->wpa2_entp_sha256 = 1;
6429         }
6430         else if (memcmp(temp, wpa2_oui06, sizeof(wpa2_oui06)) == 0)
6431         {
6432             WPA_WPA2_WEP->wpa2_sha256 = 1;
6433         }
6434 
6435 #if CONFIG_11R
6436         else if (memcmp(temp, rsn_ft_1x_oui, sizeof(rsn_ft_1x_oui)) == 0)
6437         {
6438             WPA_WPA2_WEP->ft_1x = 1;
6439             WPA_WPA2_WEP->wpa2  = 1;
6440         }
6441         else if (memcmp(temp, wpa3_oui0d, sizeof(wpa3_oui0d)) == 0)
6442         {
6443             WPA_WPA2_WEP->ft_1x_sha384 = 1;
6444         }
6445         else if (memcmp(temp, rsn_ft_psk_oui, sizeof(rsn_ft_psk_oui)) == 0)
6446         {
6447             WPA_WPA2_WEP->ft_psk = 1;
6448             WPA_WPA2_WEP->wpa2   = 1;
6449         }
6450         else if (memcmp(temp, rsn_ft_sae_oui, sizeof(rsn_ft_sae_oui)) == 0)
6451         {
6452             WPA_WPA2_WEP->ft_sae   = 1;
6453             WPA_WPA2_WEP->wpa3_sae = 1;
6454         }
6455 #endif
6456         else
6457         { /* Do Nothing */
6458         }
6459         temp += 4;
6460         count--;
6461     }
6462 
6463     rsn_cap = *(t_u16 *)(void *)(rsn_ie + 2 + sizeof(t_u16) + 4 * (int)sizeof(t_u8) + (int)sizeof(t_u16) +
6464                                  (int)pairwise_cipher_count * 4 + (int)sizeof(t_u16) + (int)akm_suite_count * 4);
6465     rsn_cap = (t_u16)wlan_le16_to_cpu(rsn_cap);
6466 
6467     *ap_mfpc = ((rsn_cap & (0x1 << MFPC_BIT)) == (0x1 << MFPC_BIT));
6468     *ap_mfpr = ((rsn_cap & (0x1 << MFPR_BIT)) == (0x1 << MFPR_BIT));
6469 done:
6470     LEAVE();
6471 }
6472 
process_wpa_ie(t_u8 * wpa_ie,_Cipher_t * mcstCipher,_Cipher_t * ucstCipher,t_u8 * ap_mfpc,t_u8 * ap_mfpr,_SecurityMode_t * WPA_WPA2_WEP)6473 static void process_wpa_ie(t_u8 *wpa_ie,
6474                            _Cipher_t *mcstCipher,
6475                            _Cipher_t *ucstCipher,
6476                            t_u8 *ap_mfpc,
6477                            t_u8 *ap_mfpr,
6478                            _SecurityMode_t *WPA_WPA2_WEP)
6479 {
6480     t_u16 wpa_ie_len;
6481     t_u8 *temp;
6482     t_u8 *ptr;
6483     t_u8 *wpa_ie_len_ptr;
6484     t_u8 *pairwise_cipher_count_ptr;
6485     t_u16 count;
6486     t_u16 group_cipher_count    = 0;
6487     t_u16 pairwise_cipher_count = 0;
6488     t_u8 wpa_oui01[4]           = {0x00, 0x50, 0xf2, 0x01};
6489     t_u8 wpa_oui02[4]           = {0x00, 0x50, 0xf2, 0x02};
6490     t_u8 wpa_oui04[4]           = {0x00, 0x50, 0xf2, 0x04};
6491     t_u8 wpa_oui05[4]           = {0x00, 0x50, 0xf2, 0x05};
6492 
6493     ENTER();
6494 
6495     if (wpa_ie == MNULL)
6496     {
6497         goto done;
6498     }
6499     else
6500     {
6501         /* Do nothing */
6502     }
6503 
6504     if (wpa_ie[0] != (t_u8)WPA_IE)
6505     {
6506         goto done;
6507     }
6508     else
6509     {
6510         /* Do nothing */
6511     }
6512     /*  2 bytes header + 4 bytes oui + 2 bytes version + 4 bytes group_cipher_suite +
6513      *  2 bytes pairwise_cipher_count + pairwise_cipher_count *
6514      * PAIRWISE_CIPHER_SUITE_LEN (4) + 2 bytes akm_suite_count +
6515      * akm_suite_count * AKM_SUITE_LEN (4)
6516      */
6517     ptr            = (t_u8 *)(wpa_ie + 1);
6518     wpa_ie_len_ptr = ptr;
6519 
6520     wpa_ie_len = wlan_le16_to_cpu(*(t_u16 *)ptr);
6521 
6522     count              = *(t_u16 *)(void *)(wpa_ie + 2 + 4);
6523     count              = wlan_le16_to_cpu(count);
6524     group_cipher_count = count;
6525     temp               = (t_u8 *)(wpa_ie + 2 + 4 + sizeof(t_u16));
6526 
6527     while (count > 0U)
6528     {
6529         if (!memcmp(temp, (const void *)wpa_oui04, sizeof(wpa_oui04)))
6530         {
6531             mcstCipher->ccmp = true;
6532         }
6533         else if (!memcmp(temp, (const void *)wpa_oui02, sizeof(wpa_oui02)))
6534         {
6535             mcstCipher->tkip = true;
6536         }
6537         else if (!memcmp(temp, (const void *)wpa_oui05, sizeof(wpa_oui05)))
6538         {
6539             mcstCipher->wep104 = true;
6540         }
6541         else if (!memcmp(temp, (const void *)wpa_oui01, sizeof(wpa_oui01)))
6542         {
6543             mcstCipher->wep40 = true;
6544         }
6545         else
6546         { /* Do nothing */
6547         }
6548         count--;
6549         temp += 4;
6550     }
6551 
6552     ptr                       = (t_u8 *)(wpa_ie + 2 + 4 + sizeof(t_u16) + (int)group_cipher_count * 4);
6553     pairwise_cipher_count_ptr = ptr;
6554 
6555     count                 = *(t_u16 *)(void *)ptr;
6556     count                 = wlan_le16_to_cpu(count);
6557     pairwise_cipher_count = count;
6558     temp                  = (t_u8 *)(wpa_ie + 2 + 4 + sizeof(t_u16) + (int)group_cipher_count * 4 + (int)sizeof(t_u16));
6559 
6560     while (count > 0U)
6561     {
6562         if (!memcmp(temp, (const void *)wpa_oui04, sizeof(wpa_oui04)))
6563         {
6564             ucstCipher->ccmp = true;
6565         }
6566         else if (!memcmp(temp, (const void *)wpa_oui02, sizeof(wpa_oui02)))
6567         {
6568             ucstCipher->tkip = true;
6569         }
6570         else
6571         { /* Do Nothing */
6572         }
6573         count--;
6574         temp += 4;
6575     }
6576 
6577     if (pairwise_cipher_count == 2)
6578     {
6579         ptr           = wpa_ie_len_ptr;
6580         *(t_u16 *)ptr = wlan_cpu_to_le16(wpa_ie_len - 4);
6581         ptr           = pairwise_cipher_count_ptr;
6582         *(t_u16 *)ptr = wlan_cpu_to_le16(1);
6583         temp          = (t_u8 *)(wpa_ie + 2 + 4 + sizeof(t_u16) + (int)group_cipher_count * 4 + (int)sizeof(t_u16));
6584 
6585         if (!memcmp((temp + 4), (const void *)wpa_oui04, sizeof(wpa_oui04)))
6586         {
6587             memmove(temp, (temp + 4), (4 + sizeof(t_u16) + 4));
6588         }
6589         else
6590         {
6591             /* 2 bytes header + 4 bytes oui + 2 bytes version + 4 bytes group_cipher_suite +
6592              *  2 bytes pairwise_cipher_count + pairwise_cipher_1 (4) +
6593              *  pairwise_cipher_2 (4) + 2 bytes akm_suite_count +
6594              *  akm_suite_count * AKM_SUITE_LEN (4)
6595              *
6596              *  Here move memory of 4bytes(pairwise_cipher_2) if the cipher type is not wpa_oui04,
6597              *  dest = (temp + 4) and src = (temp + 8),
6598              *  this memmove will keep akm data intact */
6599             memmove((temp + 4), (temp + 8), (sizeof(t_u16) + 4));
6600         }
6601     }
6602 done:
6603     LEAVE();
6604 }
6605 
wrapper_bssdesc_first_set(int bss_index,uint8_t * BssId,bool * is_ibss_bit_set,int * ssid_len,uint8_t * ssid,uint8_t * Channel,uint8_t * RSSI,uint16_t * beacon_period,uint16_t * dtim_period,_SecurityMode_t * WPA_WPA2_WEP,_Cipher_t * wpa_mcstCipher,_Cipher_t * wpa_ucstCipher,_Cipher_t * rsn_mcstCipher,_Cipher_t * rsn_ucstCipher,t_u8 * ap_mfpc,t_u8 * ap_mfpr,t_u8 * ap_pwe)6606 int wrapper_bssdesc_first_set(int bss_index,
6607                               uint8_t *BssId,
6608                               bool *is_ibss_bit_set,
6609                               int *ssid_len,
6610                               uint8_t *ssid,
6611                               uint8_t *Channel,
6612                               uint8_t *RSSI,
6613                               uint16_t *beacon_period,
6614                               uint16_t *dtim_period,
6615                               _SecurityMode_t *WPA_WPA2_WEP,
6616                               _Cipher_t *wpa_mcstCipher,
6617                               _Cipher_t *wpa_ucstCipher,
6618                               _Cipher_t *rsn_mcstCipher,
6619                               _Cipher_t *rsn_ucstCipher,
6620                               t_u8 *ap_mfpc,
6621                               t_u8 *ap_mfpr,
6622                               t_u8 *ap_pwe)
6623 {
6624     uint8_t i = WLAN_SUPPORTED_RATES;
6625     if (bss_index >= (int)mlan_adap->num_in_scan_table)
6626     {
6627         wifi_w("Unable to find given entry %d in BSS table", bss_index);
6628         return -WM_FAIL;
6629     }
6630 
6631     /* TODO
6632      * Removed : const BSSDescriptor_t *d = &mlan_adap->pscan_table[bss_index]; */
6633     BSSDescriptor_t *d = &mlan_adap->pscan_table[bss_index];
6634 
6635     (void)memcpy((void *)BssId, (const void *)d->mac_address, MLAN_MAC_ADDR_LENGTH);
6636 
6637     if (d->cap_info.ibss != 0U)
6638     {
6639         *is_ibss_bit_set = true;
6640     }
6641     else
6642     {
6643         *is_ibss_bit_set = false;
6644     }
6645 
6646     if (d->ssid.ssid_len <= MLAN_MAX_SSID_LENGTH)
6647     {
6648         *ssid_len = (int)d->ssid.ssid_len;
6649         (void)memcpy((void *)ssid, (const void *)d->ssid.ssid, d->ssid.ssid_len);
6650     }
6651 
6652     *Channel = d->channel; /*!< Channel associated to the BSSID */
6653 
6654     *RSSI = (uint8_t)d->rssi;
6655     /* uint8_t RSSI; */ /*!< Received signal strength */
6656     *beacon_period = d->beacon_period;
6657     *dtim_period   = d->dtim_period;
6658 
6659     if (d->pwpa_ie != MNULL || d->prsn_ie != MNULL)
6660     {
6661         if (d->pwpa_ie != MNULL)
6662         {
6663             WPA_WPA2_WEP->wpa = 1;
6664 
6665             process_wpa_ie(d->wpa_ie_buff, wpa_mcstCipher, wpa_ucstCipher, ap_mfpc, ap_mfpr, WPA_WPA2_WEP);
6666         }
6667 
6668         if (d->prsn_ie != MNULL)
6669         {
6670             process_rsn_ie(d->rsn_ie_buff, rsn_mcstCipher, rsn_ucstCipher, ap_mfpc, ap_mfpr, WPA_WPA2_WEP);
6671         }
6672     }
6673     else
6674     {
6675         /* Check if WEP */
6676         if (d->cap_info.privacy != 0U)
6677         {
6678             WPA_WPA2_WEP->wepStatic = 1;
6679         }
6680     }
6681 
6682     if ((d->prsnx_ie != MNULL) && (d->prsnx_ie->data[0] & (0x1 << SAE_H2E_BIT)))
6683     {
6684         *ap_pwe = 2;
6685         for (i = WLAN_SUPPORTED_RATES; i > 0; i--)
6686         {
6687             if (d->data_rates[i-1] == 0xFB)
6688             {
6689                 *ap_pwe = 1;
6690                 break;
6691             }
6692         }
6693     }
6694     else
6695     {
6696         *ap_pwe = 0;
6697     }
6698 
6699     return WM_SUCCESS;
6700 }
6701 
wrapper_bssdesc_second_set(int bss_index,bool * phtcap_ie_present,bool * phtinfo_ie_present,bool * pvhtcap_ie_present,bool * phecap_ie_present,bool * wmm_ie_present,uint16_t * band,bool * wps_IE_exist,uint16_t * wps_session,bool * wpa2_entp_IE_exist,uint16_t * mdid,bool * neighbor_report_supported,bool * bss_transition_supported,uint8_t * trans_mode,uint8_t * trans_bssid,int * trans_ssid_len,uint8_t * trans_ssid,bool * mbo_assoc_disallowed)6702 int wrapper_bssdesc_second_set(int bss_index,
6703                                bool *phtcap_ie_present,
6704                                bool *phtinfo_ie_present,
6705 #if CONFIG_11AC
6706                                bool *pvhtcap_ie_present,
6707 #endif
6708 #if CONFIG_11AX
6709                                bool *phecap_ie_present,
6710 #endif
6711                                bool *wmm_ie_present,
6712                                uint16_t *band,
6713                                bool *wps_IE_exist,
6714                                uint16_t *wps_session,
6715                                bool *wpa2_entp_IE_exist,
6716 #if CONFIG_11R
6717                                uint16_t *mdid,
6718 #endif
6719 #if CONFIG_11K
6720                                bool *neighbor_report_supported,
6721 #endif
6722 #if CONFIG_11V
6723                                bool *bss_transition_supported,
6724 #endif
6725                                uint8_t *trans_mode,
6726                                uint8_t *trans_bssid,
6727                                int *trans_ssid_len,
6728                                uint8_t *trans_ssid
6729 #if CONFIG_DRIVER_MBO
6730                                ,
6731                                bool *mbo_assoc_disallowed
6732 #endif
6733 )
6734 {
6735     if (bss_index >= mlan_adap->num_in_scan_table)
6736     {
6737         wifi_w("Unable to find given entry %d in BSS table", bss_index);
6738         return -WM_FAIL;
6739     }
6740     const BSSDescriptor_t *d = &mlan_adap->pscan_table[bss_index];
6741 #if CONFIG_11R
6742     IEEEtypes_MobilityDomain_t *pmd_ie;
6743 #endif
6744 
6745     if (d->pht_cap != NULL)
6746     {
6747         *phtcap_ie_present = true;
6748     }
6749     else
6750     {
6751         *phtcap_ie_present = false;
6752     }
6753 
6754     if (d->pht_info != NULL)
6755     {
6756         *phtinfo_ie_present = true;
6757     }
6758     else
6759     {
6760         *phtinfo_ie_present = false;
6761     }
6762 #if CONFIG_11AC
6763     if (d->pvht_cap != NULL)
6764     {
6765         *pvhtcap_ie_present = true;
6766     }
6767     else
6768     {
6769         *pvhtcap_ie_present = false;
6770     }
6771 #endif
6772 #if CONFIG_11AX
6773     if (d->phe_cap != NULL)
6774     {
6775         *phecap_ie_present = true;
6776     }
6777     else
6778     {
6779         *phecap_ie_present = false;
6780     }
6781 #endif
6782     if (d->wmm_ie.vend_hdr.element_id == WMM_IE)
6783     {
6784         *wmm_ie_present = true;
6785     }
6786     else
6787     {
6788         *wmm_ie_present = false;
6789     }
6790 
6791 #if CONFIG_DRIVER_MBO
6792     *mbo_assoc_disallowed = d->mbo_assoc_disallowed;
6793 #endif
6794 
6795     *band = d->bss_band;
6796 
6797     if (wps_IE_exist != NULL)
6798     {
6799         *wps_IE_exist = d->wps_IE_exist;
6800     }
6801     if (wps_session != NULL)
6802     {
6803         *wps_session = d->wps_session;
6804     }
6805 
6806     if (wpa2_entp_IE_exist != NULL)
6807     {
6808         *wpa2_entp_IE_exist = d->wpa2_entp_IE_exist;
6809     }
6810 
6811 #if CONFIG_11R
6812     if (mdid != NULL)
6813     {
6814         pmd_ie = (IEEEtypes_MobilityDomain_t *)d->md_ie_buff;
6815         *mdid  = pmd_ie->mdid;
6816     }
6817 #endif
6818 #if CONFIG_11K
6819     if (neighbor_report_supported != NULL)
6820     {
6821         *neighbor_report_supported = (bool)d->rm_cap_saved.RrmEnabledCapabilities.NborRpt;
6822     }
6823 #endif
6824 #if CONFIG_11V
6825     if (bss_transition_supported != NULL)
6826     {
6827         *bss_transition_supported = (bool)d->ext_cap_saved.ext_cap.BSS_Transition;
6828     }
6829 #endif
6830 
6831 #if CONFIG_DRIVER_OWE
6832     *trans_mode = d->owe_transition_mode;
6833 #endif
6834     (void)memcpy((void *)trans_bssid, (const void *)d->trans_mac_address, MLAN_MAC_ADDR_LENGTH);
6835 
6836     if (d->trans_ssid.ssid_len <= MLAN_MAX_SSID_LENGTH)
6837     {
6838         *trans_ssid_len = (int)d->trans_ssid.ssid_len;
6839         (void)memcpy((void *)trans_ssid, (const void *)d->trans_ssid.ssid, d->trans_ssid.ssid_len);
6840     }
6841 
6842     return WM_SUCCESS;
6843 }
6844 
wifi_get_scan_result_count(unsigned * count)6845 int wifi_get_scan_result_count(unsigned *count)
6846 {
6847     if (count == MNULL)
6848     {
6849         return -WM_E_INVAL;
6850     }
6851 
6852     *count = mlan_adap->num_in_scan_table;
6853     return WM_SUCCESS;
6854 }
6855 
wrapper_wlan_set_regiontable(t_u8 region,t_u16 band)6856 int wrapper_wlan_set_regiontable(t_u8 region, t_u16 band)
6857 {
6858     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
6859     mlan_status rv       = wlan_set_regiontable(pmpriv, region, band);
6860     if (rv != MLAN_STATUS_SUCCESS)
6861     {
6862         return -WM_FAIL;
6863     }
6864 
6865     return WM_SUCCESS;
6866 }
6867 
wlan_get_regulatory_domain(uint8_t chan_freq,int * cfp_no)6868 const chan_freq_power_t  *wlan_get_regulatory_domain(uint8_t chan_freq, int *cfp_no)
6869 {
6870     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
6871     const chan_freq_power_t *cfp;
6872     uint16_t region_code = pmpriv->adapter->region_code;
6873 
6874     if (chan_freq == 0)
6875     {
6876         cfp = wlan_get_region_cfp_table(pmpriv->adapter, region_code, (BAND_G | BAND_B | BAND_GN), cfp_no);
6877     }
6878 #ifdef CONFIG_5GHz_SUPPORT
6879     else
6880     {
6881         cfp = wlan_get_region_cfp_table(pmpriv->adapter, region_code, BAND_A, cfp_no);
6882     }
6883 #endif
6884 
6885     return cfp;
6886 }
6887 
6888 /*
6889  * This function is supposed to be called after scan is complete.
6890  */
wifi_scan_process_results(void)6891 void wifi_scan_process_results(void)
6892 {
6893     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
6894     /*
6895      * This function is normally supposed to be called from inside
6896      * mlan_scan.c during parsing of scanning results. But we do not
6897      * have async. cmd send functionality in the current design. So, we
6898      * have moved this outside.
6899      */
6900     wlan_scan_process_results(pmpriv);
6901 }
6902 
6903 #if CONFIG_WPA2_ENTP
wifi_scan_enable_wpa2_enterprise_ap_only()6904 void wifi_scan_enable_wpa2_enterprise_ap_only()
6905 {
6906     scan_enable_wpa2_enterprise_ap_only = true;
6907 }
6908 
wifi_get_scan_enable_wpa2_enterprise_ap_only()6909 bool wifi_get_scan_enable_wpa2_enterprise_ap_only()
6910 {
6911     return scan_enable_wpa2_enterprise_ap_only;
6912 }
6913 #endif
6914 
check_for_wpa2_entp_ie(bool * wpa2_entp_IE_exist,const void * element_data,unsigned element_len)6915 bool check_for_wpa2_entp_ie(bool *wpa2_entp_IE_exist, const void *element_data, unsigned element_len)
6916 {
6917     uint8_t wpa2_ent_IE[4];
6918     uint16_t len;
6919 
6920     (void)memcpy((void *)&len, (const void *)element_data, sizeof(len));
6921 
6922     if (len * 4U >= element_len)
6923     {
6924         return false;
6925     }
6926 
6927     (void)memcpy((void *)&wpa2_ent_IE, (const void *)((const char *)element_data + len * 4U + 2U * sizeof(len)), 4U);
6928 
6929     if (!memcmp(wpa2_ent_IE, wpa2_akmp_oui, sizeof(wpa2_akmp_oui)))
6930     {
6931         /* WPA2 Enterprise IE is present in probe response. */
6932         wifi_d("WPA2 Enterprise AKMP IE :: %x:%x:%x:%x\r\n", wpa2_ent_IE[0], wpa2_ent_IE[1], wpa2_ent_IE[2],
6933                wpa2_ent_IE[3]);
6934 
6935         *wpa2_entp_IE_exist = true;
6936 
6937         return true;
6938     }
6939 
6940     return false;
6941 }
6942 
6943 /*
6944  * The below wifi authenticate code, data structures and macros seems to be
6945  * completely absent from mlan. Our current code, including the wlc manager
6946  * currently depends on this command and its response (though it may be a
6947  * no-op).
6948  *
6949  * fixme: remove this later when appropriate.
6950  */
6951 #define host_CMD_802_11_AUTHENTICATE 0x0011
6952 #define AUTH_OPEN_SYSTEM             0
6953 
6954 typedef PACK_START struct host_802_11Authenticate_t
6955 {
6956     uint8_t MacAddr[MLAN_MAC_ADDR_LENGTH];
6957     uint8_t AuthType;
6958     uint16_t TimeOut;
6959     uint8_t Reserved[2];
6960 } PACK_END host_802_11Authenticate_t;
6961 
wifi_get_value1_from_cmdresp(const HostCmd_DS_COMMAND * resp,uint32_t * dev_value1)6962 void wifi_get_value1_from_cmdresp(const HostCmd_DS_COMMAND *resp, uint32_t *dev_value1)
6963 {
6964     if (resp->params.mac_reg.offset == wlan_cpu_to_le16((t_u16)WLAN_VALUE1))
6965     {
6966         *dev_value1 = resp->params.mac_reg.value;
6967     }
6968 }
6969 
6970 /*
6971  * fixme: This function will be present till mlan integration is complete
6972  */
wifi_get_mac_address_from_cmdresp(const HostCmd_DS_COMMAND * resp,uint8_t * get_mac_addr)6973 void wifi_get_mac_address_from_cmdresp(const HostCmd_DS_COMMAND *resp, uint8_t *get_mac_addr)
6974 {
6975     (void)memcpy((void *)get_mac_addr, (const void *)&resp->params.mac_addr.mac_addr, MLAN_MAC_ADDR_LENGTH);
6976 }
6977 
wifi_get_firmware_ver_ext_from_cmdresp(const HostCmd_DS_COMMAND * resp,uint8_t * fw_ver_ext)6978 void wifi_get_firmware_ver_ext_from_cmdresp(const HostCmd_DS_COMMAND *resp, uint8_t *fw_ver_ext)
6979 {
6980     uint8_t comma = 0x2C, space = 0x20;
6981 #ifdef RW610
6982     uint8_t ver_str_len = resp->size - WIFI_HOST_CMD_FIXED_HEADER_LEN - sizeof(resp->params.verext.version_str_sel);
6983 #endif
6984 
6985     if (!resp->params.verext.version_str_sel)
6986     {
6987         /* TODO: Below change is added to change 8978 firmware name to IW416.
6988          * This change is temporary and can be removed once firmware changes are in place */
6989         if (strstr((const char *)&resp->params.verext.version_str, "w8978o") != NULL)
6990         {
6991             (void)memcpy((void *)fw_ver_ext, (const void *)"IW416", 6);
6992             (void)memcpy((void *)(fw_ver_ext + strlen((const char *)fw_ver_ext)),
6993                          (const void *)&resp->params.verext.version_str[6],
6994                          strlen((const char *)(&resp->params.verext.version_str)) - strlen((const char *)fw_ver_ext));
6995         }
6996         else
6997         {
6998             (void)memcpy((void *)fw_ver_ext, (const void *)&resp->params.verext.version_str,
6999 #ifdef RW610
7000                          ver_str_len
7001 #else
7002                          strlen((const char *)(&resp->params.verext.version_str))
7003 #endif
7004             );
7005         }
7006     }
7007     else if (resp->params.verext.version_str_sel == 3U && strlen((const char *)(&resp->params.verext.version_str)))
7008     {
7009         (void)memcpy((void *)(fw_ver_ext + strlen((const char *)fw_ver_ext)), (const void *)&comma, 1);
7010         (void)memcpy((void *)(fw_ver_ext + strlen((const char *)fw_ver_ext)), (const void *)&space, 1);
7011         (void)memcpy((void *)(fw_ver_ext + strlen((const char *)fw_ver_ext)),
7012                      (const void *)&resp->params.verext.version_str,
7013 #ifdef RW610
7014                      ver_str_len
7015 #else
7016                      strlen((const char *)(&resp->params.verext.version_str))
7017 #endif
7018         );
7019     }
7020     else if (resp->params.verext.version_str_sel == 4U && strlen((const char *)(&resp->params.verext.version_str)))
7021     {
7022         (void)memcpy((void *)(fw_ver_ext + strlen((const char *)fw_ver_ext)), (const void *)&comma, 1);
7023         (void)memcpy((void *)(fw_ver_ext + strlen((const char *)fw_ver_ext)), (const void *)&space, 1);
7024         (void)memcpy((void *)(fw_ver_ext + strlen((const char *)fw_ver_ext)),
7025                      (const void *)&resp->params.verext.version_str,
7026 #ifdef RW610
7027                      ver_str_len
7028 #else
7029                      strlen((const char *)(&resp->params.verext.version_str))
7030 #endif
7031         );
7032     }
7033     else
7034     { /* Do Nothing */
7035     }
7036 }
7037 
wifi_prepare_set_cal_data_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7038 void wifi_prepare_set_cal_data_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7039 {
7040     cmd->command = HostCmd_CMD_CFG_DATA;
7041     cmd->size    = (t_u16)sizeof(HostCmd_DS_802_11_CFG_DATA) + (t_u16)S_DS_GEN + (t_u16)cal_data_len - (t_u16)1;
7042     cmd->seq_num = seq_number;
7043     cmd->result  = 0;
7044     cmd->params.cfg_data.action   = HostCmd_ACT_GEN_SET;
7045     cmd->params.cfg_data.type     = 0x02;
7046     cmd->params.cfg_data.data_len = cal_data_len;
7047     (void)memcpy((void *)cmd->params.cfg_data.data, (const void *)cal_data, cal_data_len);
7048 }
7049 
7050 #ifdef OTP_CHANINFO
wifi_prepare_get_channel_region_cfg_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7051 void wifi_prepare_get_channel_region_cfg_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7052 {
7053     cmd->command               = HostCmd_CMD_CHAN_REGION_CFG;
7054     cmd->size                  = sizeof(HostCmd_DS_CHAN_REGION_CFG) + S_DS_GEN;
7055     cmd->seq_num               = seq_number;
7056     cmd->result                = 0;
7057     cmd->params.reg_cfg.action = HostCmd_ACT_GEN_GET;
7058 }
7059 #endif
7060 
7061 #if CONFIG_COMPRESS_TX_PWTBL
wifi_set_region_power_cfg(const t_u8 * data,t_u16 len)7062 int wifi_set_region_power_cfg(const t_u8 *data, t_u16 len)
7063 {
7064     wifi_get_command_lock();
7065     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7066 
7067     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7068     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, 0 /* bss_type */);
7069     cmd->result  = 0x0;
7070     cmd->size    = len + S_DS_GEN;
7071 
7072     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_REGION_POWER_CFG, HostCmd_ACT_GEN_SET, 0,
7073                              NULL, (void *)data, cmd);
7074     wifi_wait_for_cmdresp(NULL);
7075     return WM_SUCCESS;
7076 }
7077 #endif
7078 
wifi_prepare_get_hw_spec_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7079 void wifi_prepare_get_hw_spec_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7080 {
7081     cmd->command = HostCmd_CMD_GET_HW_SPEC;
7082     cmd->size    = sizeof(HostCmd_DS_GET_HW_SPEC) + S_DS_GEN;
7083     cmd->seq_num = seq_number;
7084     cmd->result  = 0;
7085 }
7086 
wifi_prepare_reconfigure_tx_buf_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7087 void wifi_prepare_reconfigure_tx_buf_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7088 {
7089     cmd->command = HostCmd_CMD_RECONFIGURE_TX_BUFF;
7090     /* TODO: Replace hardcoded size with logical implementation */
7091     cmd->size                    = 16;
7092     cmd->seq_num                 = seq_number;
7093     cmd->result                  = 0;
7094     cmd->params.tx_buf.action    = HostCmd_ACT_GEN_SET;
7095     cmd->params.tx_buf.buff_size = 2048;
7096 }
7097 
7098 /*
7099  * fixme: This function will be present till mlan integration is complete
7100  */
wifi_prepare_get_mac_addr_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7101 void wifi_prepare_get_mac_addr_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7102 {
7103     cmd->command                = HostCmd_CMD_802_11_MAC_ADDRESS;
7104     cmd->size                   = sizeof(HostCmd_DS_802_11_MAC_ADDRESS) + S_DS_GEN;
7105     cmd->seq_num                = seq_number;
7106     cmd->result                 = 0;
7107     cmd->params.mac_addr.action = HostCmd_ACT_GEN_GET;
7108 }
7109 
wifi_prepare_get_fw_ver_ext_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number,int version_str_sel)7110 void wifi_prepare_get_fw_ver_ext_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number, int version_str_sel)
7111 {
7112     cmd->command                       = HostCmd_CMD_VERSION_EXT;
7113     cmd->size                          = sizeof(HostCmd_DS_VERSION_EXT) + S_DS_GEN;
7114     cmd->seq_num                       = seq_number;
7115     cmd->result                        = 0;
7116     cmd->params.verext.version_str_sel = version_str_sel;
7117 }
7118 
wifi_prepare_get_value1(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7119 void wifi_prepare_get_value1(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7120 {
7121     cmd->command               = HostCmd_CMD_MAC_REG_ACCESS;
7122     cmd->command               = wlan_cpu_to_le16(cmd->command);
7123     cmd->size                  = wlan_cpu_to_le16(sizeof(HostCmd_DS_MAC_REG_ACCESS) + S_DS_GEN);
7124     cmd->seq_num               = 0x0;
7125     cmd->result                = 0x0;
7126     cmd->params.mac_reg.action = wlan_cpu_to_le16(HostCmd_ACT_GEN_GET);
7127     cmd->params.mac_reg.offset = wlan_cpu_to_le16((t_u16)WLAN_VALUE1);
7128     cmd->params.mac_reg.value  = 0x0;
7129 }
7130 
wifi_prepare_set_mac_addr_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7131 void wifi_prepare_set_mac_addr_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7132 {
7133     cmd->command                = HostCmd_CMD_802_11_MAC_ADDRESS;
7134     cmd->size                   = sizeof(HostCmd_DS_802_11_MAC_ADDRESS) + S_DS_GEN;
7135     cmd->seq_num                = seq_number;
7136     cmd->result                 = 0;
7137     cmd->params.mac_addr.action = HostCmd_ACT_GEN_SET;
7138     (void)memcpy((void *)cmd->params.mac_addr.mac_addr, (const void *)mac_addr, MLAN_MAC_ADDR_LENGTH);
7139 }
7140 
7141 #if CONFIG_EXTERNAL_BLE_COEX
wifi_prepare_set_coex_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7142 void wifi_prepare_set_coex_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7143 {
7144     cmd->command                                               = HostCmd_CMD_ROBUST_COEX;
7145     cmd->size                                                  = sizeof(MrvlIETypes_ExtBLECoex_Config_t) + S_DS_GEN;
7146     cmd->seq_num                                               = seq_number;
7147     cmd->result                                                = 0;
7148     cmd->params.ext_ble_coex_cfg.action                        = HostCmd_ACT_GEN_SET;
7149     cmd->params.ext_ble_coex_cfg.reserved                      = 0;
7150     cmd->params.ext_ble_coex_cfg.IEParam.type                  = TLV_TYPE_EXT_BLE_COEX_CFG;
7151     cmd->params.ext_ble_coex_cfg.IEParam.len                   = sizeof(MrvlIETypes_ExtBLECoex_Config_t) - 8;
7152     cmd->params.ext_ble_coex_cfg.Enabled                       = 1;
7153     cmd->params.ext_ble_coex_cfg.IgnorePriority                = 0;
7154     cmd->params.ext_ble_coex_cfg.DefaultPriority               = 0;
7155     cmd->params.ext_ble_coex_cfg.BLE_EIP_Input_GPIO_num        = 0;
7156     cmd->params.ext_ble_coex_cfg.BLE_EIP_Input_GPIO_polarity   = 1;
7157     cmd->params.ext_ble_coex_cfg.BLE_Pri_Input_GPIO_num        = 1;
7158     cmd->params.ext_ble_coex_cfg.BLE_Pri_Input_GPIO_polarity   = 1;
7159     cmd->params.ext_ble_coex_cfg.WLAN_EIP_Output_GPIO_num      = 10;
7160     cmd->params.ext_ble_coex_cfg.WLAN_EIP_Output_GPIO_polarity = 1;
7161     cmd->params.ext_ble_coex_cfg.WLAN_Time                     = 200;
7162     cmd->params.ext_ble_coex_cfg.BT_Time                       = 255;
7163 }
7164 #endif
7165 
7166 #if CONFIG_WIFI_TX_BUFF
wifi_prepare_set_tx_buf_size(HostCmd_DS_COMMAND * cmd,int seq_number)7167 void wifi_prepare_set_tx_buf_size(HostCmd_DS_COMMAND *cmd, int seq_number)
7168 {
7169     cmd->command                 = HostCmd_CMD_RECONFIGURE_TX_BUFF;
7170     cmd->size                    = sizeof(HostCmd_DS_TXBUF_CFG) + S_DS_GEN;
7171     cmd->seq_num                 = seq_number;
7172     cmd->result                  = 0;
7173     cmd->params.tx_buf.action    = HostCmd_ACT_GEN_SET;
7174     cmd->params.tx_buf.buff_size = tx_buf_size;
7175 }
7176 #endif
7177 
wifi_prepare_enable_amsdu_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7178 void wifi_prepare_enable_amsdu_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7179 {
7180     cmd->command                              = HostCmd_CMD_AMSDU_AGGR_CTRL;
7181     cmd->size                                 = sizeof(HostCmd_DS_AMSDU_AGGR_CTRL) + S_DS_GEN;
7182     cmd->seq_num                              = seq_number;
7183     cmd->result                               = 0;
7184     cmd->params.amsdu_aggr_ctrl.action        = HostCmd_ACT_GEN_SET;
7185     cmd->params.amsdu_aggr_ctrl.enable        = 0x1;
7186     cmd->params.amsdu_aggr_ctrl.curr_buf_size = 0x0;
7187 }
7188 
7189 #ifdef WLAN_LOW_POWER_ENABLE
wifi_prepare_low_power_mode_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7190 void wifi_prepare_low_power_mode_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7191 {
7192     cmd->command = HostCmd_CMD_LOW_POWER_MODE;
7193     cmd->size    = sizeof(HostCmd_CONFIG_LOW_PWR_MODE) + S_DS_GEN;
7194     cmd->seq_num = seq_number;
7195     cmd->result  = 0;
7196 
7197     cmd->params.low_pwr_mode_cfg.enable = 1;
7198 
7199     return;
7200 }
7201 #endif
7202 
wlan_prepare_mac_control_cmd(HostCmd_DS_COMMAND * cmd,t_u16 seq_number)7203 void wlan_prepare_mac_control_cmd(HostCmd_DS_COMMAND *cmd, t_u16 seq_number)
7204 {
7205     cmd->command = HostCmd_CMD_MAC_CONTROL;
7206     cmd->size    = sizeof(HostCmd_DS_MAC_CONTROL) + S_DS_GEN;
7207     cmd->seq_num = seq_number;
7208     cmd->result  = 0;
7209 
7210     cmd->params.mac_ctrl.action =
7211 #if CONFIG_11AC
7212         HostCmd_ACT_MAC_STATIC_DYNAMIC_BW_ENABLE |
7213 #endif
7214         HostCmd_ACT_MAC_RTS_CTS_ENABLE | HostCmd_ACT_MAC_RX_ON | HostCmd_ACT_MAC_TX_ON |
7215         HostCmd_ACT_MAC_ETHERNETII_ENABLE;
7216 
7217     return;
7218 }
7219 
wifi_set_cal_data(const uint8_t * cdata,const unsigned int clen)7220 void wifi_set_cal_data(const uint8_t *cdata, const unsigned int clen)
7221 {
7222     cal_data       = (uint8_t *)cdata;
7223     cal_data_len   = (unsigned int)clen;
7224     cal_data_valid = true;
7225 }
7226 
wifi_set_mac_addr(uint8_t * mac)7227 void wifi_set_mac_addr(uint8_t *mac)
7228 {
7229     mac_addr       = mac;
7230     mac_addr_valid = true;
7231 }
7232 
_wifi_set_mac_addr(const uint8_t * mac,mlan_bss_type bss_type)7233 void _wifi_set_mac_addr(const uint8_t *mac, mlan_bss_type bss_type)
7234 {
7235     (void)wifi_get_command_lock();
7236     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7237     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7238     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, bss_type);
7239 
7240     cmd->result = 0x0;
7241     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_MAC_ADDRESS,
7242                                    HostCmd_ACT_GEN_SET, 0, NULL, (uint8_t *)mac, cmd);
7243     (void)wifi_wait_for_cmdresp(NULL);
7244     /* Also need to update priv->curr_addr, as rx reorder will check mac address using priv->curr_addr */
7245     if (bss_type == MLAN_BSS_TYPE_STA)
7246     {
7247         (void)memcpy(&mlan_adap->priv[0]->curr_addr[0], &mac[0], MLAN_MAC_ADDR_LENGTH);
7248 #if CONFIG_WPA_SUPP
7249         if (wm_wifi.supp_if_callbk_fns->mac_changed_callbk_fn)
7250         {
7251             wm_wifi.supp_if_callbk_fns->mac_changed_callbk_fn(wm_wifi.if_priv);
7252         }
7253 #endif
7254     }
7255     else if (bss_type == MLAN_BSS_TYPE_UAP)
7256     {
7257         (void)memcpy(&mlan_adap->priv[1]->curr_addr[0], &mac[0], MLAN_MAC_ADDR_LENGTH);
7258 #if CONFIG_WPA_SUPP_AP
7259         if (wm_wifi.supp_if_callbk_fns->mac_changed_callbk_fn)
7260         {
7261             wm_wifi.supp_if_callbk_fns->mac_changed_callbk_fn(wm_wifi.hapd_if_priv);
7262         }
7263 #endif
7264     }
7265 }
7266 
7267 #if CONFIG_WMM_UAPSD
7268 /**
7269  *  @brief This function checks if there is no packet indication.
7270  *
7271  *  @param priv    A pointer to mlan_private structure
7272  *
7273  *  @return        true or false
7274  */
wifi_check_no_packet_indication(mlan_private * priv)7275 t_u8 wifi_check_no_packet_indication(mlan_private *priv)
7276 {
7277     if ((wifi_wmm_get_packet_cnt() == 0) && priv->wmm_qosinfo && priv->curr_bss_params.wmm_uapsd_enabled)
7278         return true;
7279     else
7280         return false;
7281 }
7282 
7283 /**
7284  *  @brief This function checks if we need to send last packet indication.
7285  *
7286  *  @param priv    A pointer to mlan_private structure
7287  *
7288  *  @return        true or false
7289  */
wifi_check_last_packet_indication(mlan_private * priv)7290 t_u8 wifi_check_last_packet_indication(mlan_private *priv)
7291 {
7292     if ((wifi_wmm_get_packet_cnt() == 1) && priv->wmm_qosinfo && priv->curr_bss_params.wmm_uapsd_enabled)
7293         return true;
7294     else
7295         return false;
7296 }
7297 
wifi_wmm_qos_cfg(t_u8 * qos_cfg,t_u8 action)7298 int wifi_wmm_qos_cfg(t_u8 *qos_cfg, t_u8 action)
7299 {
7300     mlan_status ret = MLAN_STATUS_SUCCESS;
7301     mlan_ioctl_req req;
7302     mlan_ds_wmm_cfg cfg;
7303 
7304     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
7305     (void)memset(&cfg, 0x00, sizeof(mlan_ds_wmm_cfg));
7306     cfg.sub_command = MLAN_OID_WMM_CFG_QOS;
7307     if (action == HostCmd_ACT_GEN_SET)
7308         cfg.param.qos_cfg = *qos_cfg;
7309     req.pbuf    = (t_u8 *)&cfg;
7310     req.buf_len = sizeof(mlan_ds_wmm_cfg);
7311     req.req_id  = MLAN_IOCTL_WMM_CFG;
7312 
7313     if (action == HostCmd_ACT_GEN_SET)
7314         req.action = MLAN_ACT_SET;
7315     else if (action == HostCmd_ACT_GEN_GET)
7316         req.action = MLAN_ACT_GET;
7317     ret = wlan_ops_sta_ioctl(mlan_adap, &req);
7318 
7319     if (action == HostCmd_ACT_GEN_GET)
7320         *qos_cfg = cfg.param.qos_cfg;
7321     return ret;
7322 }
7323 
wifi_sleep_period(unsigned int * sleep_period,int action)7324 int wifi_sleep_period(unsigned int *sleep_period, int action)
7325 {
7326     int ret = WM_SUCCESS;
7327     wifi_get_command_lock();
7328     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7329     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7330     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, MLAN_BSS_TYPE_STA);
7331     cmd->result  = 0x0;
7332     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_SLEEP_PERIOD, action, 0, NULL,
7333                              sleep_period, cmd);
7334     if (action == HostCmd_ACT_GEN_SET)
7335         ret = wifi_wait_for_cmdresp(NULL);
7336     else if (action == HostCmd_ACT_GEN_GET)
7337     {
7338         mlan_ds_pm_cfg pm_cfg;
7339         mlan_ioctl_req pioctl_buf;
7340         pioctl_buf.pbuf = (t_u8 *)&pm_cfg;
7341         memset((t_u8 *)&pioctl_buf, 0, sizeof(pioctl_buf));
7342         memset((t_u8 *)&pm_cfg, 0, sizeof(pm_cfg));
7343         ret           = wifi_wait_for_cmdresp(&pioctl_buf);
7344         pm_cfg        = *(mlan_ds_pm_cfg *)pioctl_buf.pbuf;
7345         *sleep_period = pm_cfg.param.sleep_period;
7346     }
7347     return ret;
7348 }
7349 #endif
7350 
7351 #if CONFIG_WIFI_TX_BUFF
wifi_calibrate_tx_buf_size(uint16_t buf_size)7352 bool wifi_calibrate_tx_buf_size(uint16_t buf_size)
7353 {
7354     uint16_t pre_tx_buf_size = tx_buf_size;
7355     tx_buf_size              = MLAN_TX_DATA_BUF_SIZE_2K;
7356 
7357 #if defined(RW610)
7358     if (buf_size >= MLAN_TX_DATA_BUF_SIZE_4K)
7359         tx_buf_size = MLAN_TX_DATA_BUF_SIZE_4K;
7360     _wlan_return_all_tx_buf(kIMU_LinkCpu1Cpu3);
7361 #else
7362     if (buf_size >= MLAN_TX_DATA_BUF_SIZE_8K)
7363         tx_buf_size = MLAN_TX_DATA_BUF_SIZE_8K;
7364     else if (buf_size >= MLAN_TX_DATA_BUF_SIZE_4K)
7365         tx_buf_size = MLAN_TX_DATA_BUF_SIZE_4K;
7366 #endif
7367 
7368     return (tx_buf_size != pre_tx_buf_size) ? true : false;
7369 }
7370 
wifi_recfg_tx_buf_size(uint16_t buf_size)7371 void wifi_recfg_tx_buf_size(uint16_t buf_size)
7372 {
7373     tx_buf_size = buf_size;
7374 }
7375 
_wifi_recfg_tx_buf_size(uint16_t buf_size,mlan_bss_type bss_type)7376 void _wifi_recfg_tx_buf_size(uint16_t buf_size, mlan_bss_type bss_type)
7377 {
7378     if (!wifi_calibrate_tx_buf_size(buf_size))
7379         return;
7380 
7381     wifi_get_command_lock();
7382 
7383     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7384 
7385     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7386     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
7387     cmd->result  = 0x0;
7388 
7389     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_RECONFIGURE_TX_BUFF, HostCmd_ACT_GEN_SET,
7390                              0, NULL, &tx_buf_size, cmd);
7391     wifi_wait_for_cmdresp(NULL);
7392 }
7393 
7394 #endif
7395 
7396 #if CONFIG_WIFI_TX_PER_TRACK
wifi_set_tx_pert(void * cfg,mlan_bss_type bss_type)7397 int wifi_set_tx_pert(void *cfg, mlan_bss_type bss_type)
7398 {
7399     tx_pert_info *tx_pert = (tx_pert_info *)cfg;
7400 
7401     wifi_get_command_lock();
7402     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7403     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7404     /* Store tx per tracking config in driver */
7405     (void)memcpy((t_u8 *)&(mlan_adap->tx_pert), tx_pert, sizeof(tx_pert_info));
7406     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
7407     cmd->result  = 0x0;
7408     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_TX_RX_PKT_STATS,
7409                              HostCmd_ACT_SET_TX_PER_TRACKING, 0, NULL, tx_pert, cmd);
7410     wifi_wait_for_cmdresp(NULL);
7411     return wm_wifi.cmd_resp_status;
7412 }
7413 #endif
7414 
7415 #if CONFIG_TX_RX_HISTOGRAM
wifi_set_txrx_histogram(void * cfg,t_u8 * data)7416 int wifi_set_txrx_histogram(void *cfg, t_u8 *data)
7417 {
7418     txrx_histogram_info *txrx_histogram    = (txrx_histogram_info *)cfg;
7419     txrx_histogram_info txrx_histogram_cmd = {0};
7420 
7421     txrx_histogram_cmd.enable = txrx_histogram->enable;
7422     txrx_histogram_cmd.action = txrx_histogram->action;
7423 
7424     if (txrx_histogram_cmd.enable == GET_TX_RX_HISTOGRAM)
7425     {
7426         txrx_histogram_cmd.enable = ENABLE_TX_RX_HISTOGRAM;
7427     }
7428     else
7429     {
7430         txrx_histogram_cmd.action = 0;
7431     }
7432 
7433     wifi_get_command_lock();
7434     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7435     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7436 
7437     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_TX_RX_PKT_STATS, HostCmd_ACT_GEN_GET, 0,
7438                              NULL, &txrx_histogram_cmd, cmd);
7439     wifi_wait_for_cmdresp(data);
7440     return wm_wifi.cmd_resp_status;
7441 }
7442 #endif
7443 
7444 #if CONFIG_RX_ABORT_CFG
wifi_set_get_rx_abort_cfg(void * cfg,t_u16 action)7445 int wifi_set_get_rx_abort_cfg(void *cfg, t_u16 action)
7446 {
7447     wifi_get_command_lock();
7448     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7449     cmd->seq_num            = 0x0;
7450     cmd->result             = 0x0;
7451     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_RX_ABORT_CFG, action, 0, NULL, cfg, cmd);
7452     wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? cfg : NULL);
7453     return wm_wifi.cmd_resp_status;
7454 }
7455 #endif
7456 
7457 #if CONFIG_RX_ABORT_CFG_EXT
wifi_set_get_rx_abort_cfg_ext(void * cfg,t_u16 action)7458 int wifi_set_get_rx_abort_cfg_ext(void *cfg, t_u16 action)
7459 {
7460     wifi_get_command_lock();
7461     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7462     (void)memset(cmd, 0, sizeof(HostCmd_DS_COMMAND));
7463     cmd->seq_num = 0x0;
7464     cmd->result  = 0x0;
7465     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_RX_ABORT_CFG_EXT, action, 0, NULL, cfg,
7466                              cmd);
7467     wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? cfg : NULL);
7468     return wm_wifi.cmd_resp_status;
7469 }
7470 #endif
7471 
7472 #if CONFIG_CCK_DESENSE_CFG
wifi_set_get_cck_desense_cfg(void * cfg,t_u16 action)7473 int wifi_set_get_cck_desense_cfg(void *cfg, t_u16 action)
7474 {
7475     wifi_get_command_lock();
7476     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7477     cmd->seq_num            = 0x0;
7478     cmd->result             = 0x0;
7479     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_CCK_DESENSE_CFG, action, 0, NULL, cfg,
7480                              cmd);
7481     wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? cfg : NULL);
7482     return wm_wifi.cmd_resp_status;
7483 }
7484 #endif
7485 
7486 #ifdef WLAN_LOW_POWER_ENABLE
wifi_enable_low_pwr_mode()7487 void wifi_enable_low_pwr_mode()
7488 {
7489     low_power_mode = true;
7490 }
7491 #endif
7492 
7493 #if CONFIG_ROAMING
wifi_config_roaming(const int enable,uint8_t * rssi_low)7494 int wifi_config_roaming(const int enable, uint8_t *rssi_low)
7495 {
7496     mlan_private *pmpriv = mlan_adap->priv[0];
7497     int ret              = WM_SUCCESS;
7498 
7499     if (enable)
7500     {
7501         pmpriv->roaming_enabled = MTRUE;
7502         pmpriv->rssi_low        = *rssi_low;
7503         ret                     = wifi_set_rssi_low_threshold(rssi_low);
7504         if (ret != WM_SUCCESS)
7505         {
7506             wifi_e("Failed to config rssi threshold for roaming");
7507             return -WM_FAIL;
7508         }
7509     }
7510     else
7511     {
7512         if (pmpriv->roaming_enabled)
7513         {
7514             pmpriv->roaming_enabled = MFALSE;
7515             pmpriv->rssi_low        = 0;
7516             wifi_stop_bgscan();
7517         }
7518     }
7519     return ret;
7520 }
7521 #endif
7522 
7523 #if CONFIG_11AX
wifi_set_11ax_tx_omi(const mlan_bss_type bss_type,const t_u16 tx_omi,const t_u8 tx_option,const t_u8 num_data_pkts)7524 int wifi_set_11ax_tx_omi(const mlan_bss_type bss_type,
7525                          const t_u16 tx_omi,
7526                          const t_u8 tx_option,
7527                          const t_u8 num_data_pkts)
7528 {
7529     mlan_ioctl_req req;
7530 
7531     mlan_ds_11ax_cmd_cfg cfg;
7532 
7533     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
7534     (void)memset(&cfg, 0x00, sizeof(mlan_ds_11ax_cmd_cfg));
7535 
7536     req.req_id  = MLAN_IOCTL_11AX_CFG;
7537     req.action  = MLAN_ACT_SET;
7538     req.pbuf    = (t_u8 *)&cfg;
7539     req.buf_len = sizeof(mlan_ds_11ax_cmd_cfg);
7540 
7541     cfg.sub_command                   = MLAN_OID_11AX_CMD_CFG;
7542     cfg.sub_id                        = MLAN_11AXCMD_TXOMI_SUBID;
7543     cfg.param.txomi_cfg.omi           = tx_omi;
7544     cfg.param.txomi_cfg.tx_option     = tx_option;
7545     cfg.param.txomi_cfg.num_data_pkts = num_data_pkts;
7546 
7547     mlan_status rv;
7548 
7549     if (bss_type == MLAN_BSS_TYPE_UAP)
7550     {
7551         req.bss_index = (t_u32)MLAN_BSS_TYPE_UAP;
7552         rv            = wlan_ops_uap_ioctl(mlan_adap, &req);
7553     }
7554     else
7555     {
7556         req.bss_index = (t_u32)MLAN_BSS_TYPE_STA;
7557         rv            = wlan_ops_sta_ioctl(mlan_adap, &req);
7558     }
7559 
7560     wm_wifi.cmd_resp_ioctl = NULL;
7561 
7562     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
7563     {
7564         return -WM_FAIL;
7565     }
7566 
7567     return WM_SUCCESS;
7568 }
7569 
wifi_set_11ax_tol_time(const t_u32 tol_time)7570 int wifi_set_11ax_tol_time(const t_u32 tol_time)
7571 {
7572     mlan_ioctl_req req;
7573 
7574     mlan_ds_11ax_cmd_cfg cfg;
7575 
7576     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
7577     (void)memset(&cfg, 0x00, sizeof(mlan_ds_11ax_cmd_cfg));
7578 
7579     req.req_id  = MLAN_IOCTL_11AX_CFG;
7580     req.action  = MLAN_ACT_SET;
7581     req.pbuf    = (t_u8 *)&cfg;
7582     req.buf_len = sizeof(mlan_ds_11ax_cmd_cfg);
7583 
7584     cfg.sub_command                = MLAN_OID_11AX_CMD_CFG;
7585     cfg.sub_id                     = MLAN_11AXCMD_OBSS_TOLTIME_SUBID;
7586     cfg.param.toltime_cfg.tol_time = tol_time;
7587 
7588     mlan_status rv = wlan_ops_sta_ioctl(mlan_adap, &req);
7589 
7590     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
7591         return MLAN_STATUS_FAILURE;
7592 
7593     return MLAN_STATUS_SUCCESS;
7594 }
7595 
wifi_set_11ax_rutxpowerlimit(const void * rutx_pwr_cfg,uint32_t rutx_pwr_cfg_len)7596 int wifi_set_11ax_rutxpowerlimit(const void *rutx_pwr_cfg, uint32_t rutx_pwr_cfg_len)
7597 {
7598     int ret;
7599     uint32_t reqd_len = 0;
7600 #if !CONFIG_MEM_POOLS
7601     void *rutxcmd_resp_buff = OSA_MemoryAllocate(RUTXCMD_RESP_BUFF_SIZE);
7602 #else
7603     void *rutxcmd_resp_buff = OSA_MemoryPoolAllocate(buf_1024_MemoryPool);
7604 #endif
7605 
7606     if (rutxcmd_resp_buff == NULL)
7607     {
7608         return -WM_FAIL;
7609     }
7610 
7611     ret = wlan_send_hostcmd(rutx_pwr_cfg, rutx_pwr_cfg_len / sizeof(uint8_t), rutxcmd_resp_buff, RUTXCMD_RESP_BUFF_SIZE,
7612                             &reqd_len);
7613 
7614     if (ret != WM_SUCCESS)
7615     {
7616         wifi_d("RUTXcmd failed error: %d", ret);
7617     }
7618 
7619     if (rutxcmd_resp_buff != NULL)
7620     {
7621 #if !CONFIG_MEM_POOLS
7622         OSA_MemoryFree(rutxcmd_resp_buff);
7623 #else
7624         OSA_MemoryPoolFree(buf_1024_MemoryPool, rutxcmd_resp_buff);
7625 #endif
7626 
7627         return ret;
7628     }
7629 
7630     return WM_SUCCESS;
7631 }
7632 
wifi_set_11ax_rutxpowerlimit_legacy(const wifi_rutxpwrlimit_t * ru_pwr_cfg)7633 int wifi_set_11ax_rutxpowerlimit_legacy(const wifi_rutxpwrlimit_t *ru_pwr_cfg)
7634 {
7635     t_u8 i;
7636     int ret;
7637     HostCmd_DS_COMMAND *cmd                    = wifi_get_command_buffer();
7638     t_u8 *pByte                                = NULL;
7639     mlan_ds_11ax_chanlrupwrcft_cmd *chrupc_tlv = NULL;
7640 
7641     (void)wifi_get_command_lock();
7642 
7643     cmd->command = HostCmd_CMD_11AX_CMD;
7644     cmd->seq_num = 0x0;
7645     cmd->result  = 0x0;
7646     cmd->size    = sizeof(HostCmd_DS_11AX_CMD_CFG) + S_DS_GEN +
7647                 ru_pwr_cfg->num_chans * (sizeof(wifi_rupwrlimit_config_t) + sizeof(MrvlIEtypesHeader_t));
7648 
7649     HostCmd_DS_11AX_CMD_CFG *axcmd = &cmd->params.axcmd;
7650 
7651     axcmd->action = wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
7652     axcmd->sub_id = wlan_cpu_to_le16(MLAN_11AXCMD_RUPOWER_SUBID);
7653 
7654     pByte = (t_u8 *)axcmd->val;
7655     for (i = 0; i < ru_pwr_cfg->num_chans; i++)
7656     {
7657         t_u8 j;
7658         chrupc_tlv                               = (mlan_ds_11ax_chanlrupwrcft_cmd *)(void *)pByte;
7659         chrupc_tlv->type                         = TLV_TYPE_CHANNEL_RU_PWR_CONFIG;
7660         chrupc_tlv->len                          = sizeof(wifi_rupwrlimit_config_t);
7661         chrupc_tlv->rupwrlimit_config.start_freq = ru_pwr_cfg->rupwrlimit_config[i].start_freq;
7662         chrupc_tlv->rupwrlimit_config.width      = ru_pwr_cfg->rupwrlimit_config[i].width;
7663         chrupc_tlv->rupwrlimit_config.chan_num   = ru_pwr_cfg->rupwrlimit_config[i].chan_num;
7664         for (j = 0; j < MAX_RU_COUNT; j++)
7665         {
7666             chrupc_tlv->rupwrlimit_config.ruPower[j] = (t_s8)ru_pwr_cfg->rupwrlimit_config[i].ruPower[j];
7667         }
7668         pByte += chrupc_tlv->len + sizeof(MrvlIEtypesHeader_t);
7669     }
7670     ret = wifi_wait_for_cmdresp(NULL);
7671     return ret;
7672 }
7673 
wifi_get_11ax_rutxpowerlimit_legacy(wifi_rutxpwrlimit_t * ru_pwr_cfg)7674 int wifi_get_11ax_rutxpowerlimit_legacy(wifi_rutxpwrlimit_t *ru_pwr_cfg)
7675 {
7676     int ret;
7677 
7678     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7679 
7680     (void)wifi_get_command_lock();
7681 
7682     cmd->command = HostCmd_CMD_11AX_CMD;
7683     cmd->seq_num = 0x0;
7684     cmd->result  = 0x0;
7685     cmd->size    = S_DS_GEN + 2U * sizeof(t_u16);
7686 
7687     HostCmd_DS_11AX_CMD_CFG *rutxpwrlimit_config = (HostCmd_DS_11AX_CMD_CFG *)(void *)((uint8_t *)cmd + S_DS_GEN);
7688 
7689     rutxpwrlimit_config->action = HostCmd_ACT_GEN_GET;
7690 
7691     rutxpwrlimit_config->sub_id = MLAN_11AXCMD_RUPOWER_SUBID;
7692 
7693     ret = wifi_wait_for_cmdresp(ru_pwr_cfg);
7694 
7695     return ret;
7696 }
7697 
wifi_set_11ax_cfg(wifi_11ax_config_t * ax_config)7698 int wifi_set_11ax_cfg(wifi_11ax_config_t *ax_config)
7699 {
7700     /* alloc cmd and wait for response in prepare cmd, no need to deal with cmd outside */
7701     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_11AX_CFG, HostCmd_ACT_GEN_SET, 0, NULL,
7702                              ax_config, NULL);
7703     return WM_SUCCESS;
7704 }
7705 
7706 #if CONFIG_11AX_TWT
wifi_set_btwt_cfg(const wifi_btwt_config_t * btwt_config)7707 int wifi_set_btwt_cfg(const wifi_btwt_config_t *btwt_config)
7708 {
7709     wifi_get_command_lock();
7710     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7711 
7712     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7713     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_STA);
7714     cmd->result  = 0x0;
7715     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_DBGS_CFG);
7716     cmd->size    = sizeof(wifi_btwt_config_t) + S_DS_GEN;
7717     (void)memcpy(&cmd->params, btwt_config, sizeof(wifi_btwt_config_t));
7718 
7719     wifi_wait_for_cmdresp(NULL);
7720     return WM_SUCCESS;
7721 }
7722 
wifi_set_twt_setup_cfg(const wifi_twt_setup_config_t * twt_setup)7723 int wifi_set_twt_setup_cfg(const wifi_twt_setup_config_t *twt_setup)
7724 {
7725     wifi_get_command_lock();
7726     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7727     mlan_ds_twtcfg twt_cfg  = {0};
7728     MrvlIEtypes_He_cap_t *hw_he_cap;
7729     MrvlIEtypes_He_cap_t *hw_2g_he_cap;
7730     int ret = 0;
7731 
7732     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7733     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_STA);
7734     cmd->result  = 0x0;
7735 
7736     twt_cfg.sub_id = MLAN_11AX_TWT_SETUP_SUBID;
7737     (void)memcpy(&twt_cfg.param.twt_setup, twt_setup, sizeof(twt_cfg.param.twt_setup));
7738 
7739     /* block BTWT setup command if firmware does not support BTWT */
7740     if (twt_cfg.param.twt_setup.negotiation_type == 3)
7741     {
7742         hw_he_cap    = (MrvlIEtypes_He_cap_t *)&mlan_adap->hw_he_cap[0];
7743         hw_2g_he_cap = (MrvlIEtypes_He_cap_t *)&mlan_adap->hw_2g_he_cap[0];
7744         /* BTWT support bit 20 */
7745         if ((hw_he_cap->he_mac_cap[2] & MBIT(4)) == 0 && (hw_2g_he_cap->he_mac_cap[2] & MBIT(4)) == 0)
7746         {
7747             wifi_put_command_lock();
7748             wifi_e("Firmware does not support Broadcast TWT, please use support BTWT version");
7749             return -WM_FAIL;
7750         }
7751     }
7752 
7753     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_TWT_CFG, HostCmd_ACT_GEN_SET, 0, NULL,
7754                              &twt_cfg, cmd);
7755     ret = wifi_wait_for_cmdresp(&twt_cfg.param.twt_setup);
7756     if (ret == WM_SUCCESS)
7757     {
7758         if (wm_wifi.cmd_resp_status != WM_SUCCESS)
7759         {
7760             wifi_e("TWT setup error. State code=%d", twt_cfg.param.twt_setup.twt_setup_state);
7761         }
7762         else
7763         {
7764             (void)PRINTF("TWT setup success. Flow id: %d, use this in future TWT operation.\r\n", twt_cfg.param.twt_setup.flow_identifier);
7765         }
7766     }
7767     return WM_SUCCESS;
7768 }
7769 
wifi_set_twt_teardown_cfg(const wifi_twt_teardown_config_t * teardown_config)7770 int wifi_set_twt_teardown_cfg(const wifi_twt_teardown_config_t *teardown_config)
7771 {
7772     wifi_get_command_lock();
7773     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7774     mlan_ds_twtcfg twt_cfg  = {0};
7775 
7776     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7777     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_STA);
7778     cmd->result  = 0x0;
7779 
7780     twt_cfg.sub_id = MLAN_11AX_TWT_TEARDOWN_SUBID;
7781     (void)memcpy(&twt_cfg.param.twt_teardown, teardown_config, sizeof(twt_cfg.param.twt_teardown));
7782 
7783     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_TWT_CFG, HostCmd_ACT_GEN_SET, 0, NULL,
7784                              &twt_cfg, cmd);
7785     wifi_wait_for_cmdresp(NULL);
7786     return WM_SUCCESS;
7787 }
7788 
wifi_get_twt_report(wifi_twt_report_t * twt_report)7789 int wifi_get_twt_report(wifi_twt_report_t *twt_report)
7790 {
7791     wifi_get_command_lock();
7792     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7793     mlan_ds_twtcfg twt_cfg  = {0};
7794 
7795     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7796     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_STA);
7797     cmd->result  = 0x0;
7798 
7799     twt_cfg.sub_id = MLAN_11AX_TWT_REPORT_SUBID;
7800 
7801     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_TWT_CFG, HostCmd_ACT_GEN_GET, 0, NULL,
7802                              &twt_cfg, cmd);
7803     wifi_wait_for_cmdresp(twt_report);
7804     return WM_SUCCESS;
7805 }
7806 
wifi_twt_information(wifi_twt_information_t * twt_information)7807 int wifi_twt_information(wifi_twt_information_t *twt_information)
7808 {
7809     wifi_get_command_lock();
7810     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
7811     mlan_ds_twtcfg twt_cfg  = {0};
7812     int ret                 = 0;
7813 
7814     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7815     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_STA);
7816     cmd->result  = 0x0;
7817 
7818     twt_cfg.sub_id = MLAN_11AX_TWT_INFORMATION_SUBID;
7819     (void)memcpy(&twt_cfg.param.twt_information, twt_information, sizeof(twt_cfg.param.twt_information));
7820 
7821     /* TWT Flow Identifier. Range: [0-7]. */
7822     if (twt_cfg.param.twt_information.flow_identifier > 7)
7823     {
7824         wifi_put_command_lock();
7825         wifi_e("Invalid TWT flow id");
7826         return -WM_FAIL;
7827     }
7828 
7829     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_TWT_CFG, HostCmd_ACT_GEN_SET, 0, NULL,
7830                              &twt_cfg, cmd);
7831     ret = wifi_wait_for_cmdresp(NULL);
7832     if (ret == WM_SUCCESS)
7833     {
7834         if (wm_wifi.cmd_resp_status != WM_SUCCESS)
7835         {
7836             wifi_e("TWT information error");
7837         }
7838     }
7839 
7840     return WM_SUCCESS;
7841 }
7842 #endif /* CONFIG_11AX_TWT */
7843 #endif
7844 
7845 #if CONFIG_WIFI_CLOCKSYNC
wifi_set_clocksync_cfg(const wifi_clock_sync_gpio_tsf_t * tsf_latch,mlan_bss_type bss_type)7846 int wifi_set_clocksync_cfg(const wifi_clock_sync_gpio_tsf_t *tsf_latch, mlan_bss_type bss_type)
7847 {
7848     int ret;
7849     mlan_ds_misc_cfg misc;
7850     mlan_ioctl_req req;
7851     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
7852     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
7853 
7854     (void)memcpy((void *)&misc.param.gpio_tsf_latch_config, (const void *)tsf_latch,
7855                  sizeof(misc.param.gpio_tsf_latch_config));
7856 
7857     misc.sub_command       = (t_u32)MLAN_OID_MISC_GPIO_TSF_LATCH;
7858     wm_wifi.cmd_resp_ioctl = &req;
7859     req.pbuf               = (t_u8 *)&misc;
7860     req.buf_len            = sizeof(mlan_ds_misc_cfg);
7861     req.req_id             = (t_u32)MLAN_IOCTL_MISC_CFG;
7862     req.action             = MLAN_ACT_SET;
7863 
7864     if (bss_type == MLAN_BSS_TYPE_UAP)
7865     {
7866         req.bss_index = (t_u32)MLAN_BSS_TYPE_UAP;
7867         ret           = (int)wlan_ops_uap_ioctl(mlan_adap, &req);
7868     }
7869     else
7870     {
7871         req.bss_index = (t_u32)MLAN_BSS_TYPE_STA;
7872         ret           = (int)wlan_ops_sta_ioctl(mlan_adap, &req);
7873     }
7874 
7875     wm_wifi.cmd_resp_ioctl = NULL;
7876     return ret;
7877 }
7878 
wifi_get_tsf_info(wifi_tsf_info_t * tsf_info)7879 int wifi_get_tsf_info(wifi_tsf_info_t *tsf_info)
7880 {
7881     int ret;
7882     mlan_ds_misc_cfg misc;
7883     mlan_ioctl_req req;
7884     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
7885     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
7886 
7887     (void)memcpy((void *)&misc.param.tsf_info, (void *)tsf_info, sizeof(misc.param.tsf_info));
7888 
7889     misc.sub_command       = (t_u32)MLAN_OID_MISC_GET_TSF_INFO;
7890     wm_wifi.cmd_resp_ioctl = &req;
7891     req.pbuf               = (t_u8 *)&misc;
7892     req.buf_len            = sizeof(mlan_ds_misc_cfg);
7893     req.bss_index          = 0;
7894     req.req_id             = (t_u32)MLAN_IOCTL_MISC_CFG;
7895     req.action             = MLAN_ACT_GET;
7896 
7897     ret                    = (int)wlan_ops_sta_ioctl(mlan_adap, &req);
7898     wm_wifi.cmd_resp_ioctl = NULL;
7899 
7900     if (ret == WM_SUCCESS)
7901     {
7902         (void)memcpy((void *)tsf_info, (void *)&misc.param.tsf_info, sizeof(mlan_ds_tsf_info));
7903     }
7904     return ret;
7905 }
7906 #endif /* CONFIG_WIFI_CLOCKSYNC */
7907 
7908 #if CONFIG_WMM
wifi_wmm_tx_stats_dump_ralist(mlan_list_head * ra_list_head)7909 static void wifi_wmm_tx_stats_dump_ralist(mlan_list_head *ra_list_head)
7910 {
7911     raListTbl *ra_list = MNULL;
7912 
7913     ra_list = (raListTbl *)util_peek_list(mlan_adap->pmoal_handle, ra_list_head, MNULL, MNULL);
7914     while (ra_list && ra_list != (raListTbl *)ra_list_head)
7915     {
7916         wifi_w("    [%02X:XX:XX:XX:%02X:%02X] drop_cnt[%d] total_pkts[%d]", ra_list->ra[0], ra_list->ra[4],
7917                ra_list->ra[5], ra_list->drop_count, ra_list->total_pkts);
7918 
7919         ra_list = ra_list->pnext;
7920     }
7921 }
7922 
wifi_wmm_tx_stats_dump(int bss_type)7923 void wifi_wmm_tx_stats_dump(int bss_type)
7924 {
7925     int i;
7926     mlan_private *priv = MNULL;
7927 
7928     if (bss_type == MLAN_BSS_TYPE_STA)
7929         priv = mlan_adap->priv[0];
7930     else if (bss_type == MLAN_BSS_TYPE_UAP)
7931         priv = mlan_adap->priv[1];
7932     else
7933         return;
7934 
7935     for (i = 0; i < MAX_AC_QUEUES; i++)
7936     {
7937         wifi_w("Dump priv[%d] ac_queue[%d]", bss_type, i);
7938         wifi_wmm_tx_stats_dump_ralist(&priv->wmm.tid_tbl_ptr[i].ra_list);
7939     }
7940 
7941     wifi_w("Dump priv[%d] driver_error_cnt:", bss_type);
7942     wifi_w("    tx_no_media[%hu]", priv->driver_error_cnt.tx_no_media);
7943     wifi_w("    tx_err_mem[%hu]", priv->driver_error_cnt.tx_err_mem);
7944     wifi_w("    tx_wmm_retried_drop[%hu]", priv->driver_error_cnt.tx_wmm_retried_drop);
7945     wifi_w("    tx_wmm_pause_drop[%hu]", priv->driver_error_cnt.tx_wmm_pause_drop);
7946     wifi_w("    tx_wmm_pause_replaced[%hu]", priv->driver_error_cnt.tx_wmm_pause_replaced);
7947     wifi_w("    rx_reorder_drop[%hu]", priv->driver_error_cnt.rx_reorder_drop);
7948 
7949     int free_cnt_real   = 0;
7950     mlan_linked_list *p = MNULL;
7951 
7952     mlan_adap->callbacks.moal_semaphore_get(mlan_adap->pmoal_handle, &mlan_adap->outbuf_pool.free_list.plock);
7953 
7954     p = util_peek_list(mlan_adap->pmoal_handle, &mlan_adap->outbuf_pool.free_list, MNULL, MNULL);
7955     while (p && p != (mlan_linked_list *)&mlan_adap->outbuf_pool.free_list)
7956     {
7957         free_cnt_real++;
7958         p = p->pnext;
7959     }
7960 
7961     mlan_adap->callbacks.moal_semaphore_put(mlan_adap->pmoal_handle, &mlan_adap->outbuf_pool.free_list.plock);
7962     wifi_w("TX buffer pool: free_cnt[%d] real_free_cnt[%d]", mlan_adap->outbuf_pool.free_cnt, free_cnt_real);
7963 
7964 #if CONFIG_WMM_DEBUG
7965     for (i = 0; i < MAX_AC_QUEUES; i++)
7966     {
7967         wifi_w("Dump priv[%d] ac_queue[%d] history ra", bss_type, i);
7968         wifi_wmm_tx_stats_dump_ralist(&priv->wmm.hist_ra[i]);
7969     }
7970 #endif
7971 }
7972 #endif
7973 
7974 #if CONFIG_MULTI_CHAN
wifi_set_mc_cfg(uint32_t channel_time)7975 int wifi_set_mc_cfg(uint32_t channel_time)
7976 {
7977     (void)wifi_get_command_lock();
7978     HostCmd_DS_COMMAND *cmd               = wifi_get_command_buffer();
7979     mlan_ds_multi_chan_cfg multi_chan_cfg = {0};
7980 
7981     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
7982     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, 0U /* bss_type */);
7983     cmd->result  = 0x0;
7984 
7985     multi_chan_cfg.channel_time  = channel_time;
7986     multi_chan_cfg.buffer_weight = 1;
7987 
7988     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MULTI_CHAN_CONFIG,
7989                                    HostCmd_ACT_GEN_SET, 0, NULL, &multi_chan_cfg, cmd);
7990     (void)wifi_wait_for_cmdresp(NULL);
7991     return wm_wifi.cmd_resp_status;
7992 }
7993 
wifi_get_mc_cfg(uint32_t * channel_time)7994 int wifi_get_mc_cfg(uint32_t *channel_time)
7995 {
7996     (void)wifi_get_command_lock();
7997     HostCmd_DS_COMMAND *cmd    = wifi_get_command_buffer();
7998     mlan_ioctl_req ioctl_req   = {0};
7999     mlan_ds_misc_cfg ioctl_cfg = {0};
8000 
8001     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
8002     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, 0U /* bss_type */);
8003     cmd->result  = 0x0;
8004 
8005     wm_wifi.cmd_resp_ioctl = &ioctl_req;
8006     ioctl_req.pbuf         = (t_u8 *)&ioctl_cfg;
8007     ioctl_req.buf_len      = sizeof(ioctl_cfg);
8008 
8009     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MULTI_CHAN_CONFIG,
8010                                    HostCmd_ACT_GEN_GET, 0, NULL, &ioctl_cfg.param.multi_chan_cfg, cmd);
8011     (void)wifi_wait_for_cmdresp(NULL);
8012     wm_wifi.cmd_resp_ioctl = NULL;
8013     (*channel_time)        = ioctl_cfg.param.multi_chan_cfg.channel_time;
8014     return wm_wifi.cmd_resp_status;
8015 }
8016 
wifi_set_mc_policy(const int status)8017 int wifi_set_mc_policy(const int status)
8018 {
8019     (void)wifi_get_command_lock();
8020     HostCmd_DS_COMMAND *cmd    = wifi_get_command_buffer();
8021     t_u16 mc_policy            = (t_u16)status;
8022     mlan_ioctl_req ioctl_req   = {0};
8023     mlan_ds_misc_cfg ioctl_cfg = {0};
8024 
8025     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
8026     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, 0U /* bss_type */);
8027     cmd->result  = 0x0;
8028 
8029     wm_wifi.cmd_resp_ioctl            = &ioctl_req;
8030     ioctl_req.action                  = (mlan_act_ioctl)HostCmd_ACT_GEN_SET;
8031     ioctl_req.pbuf                    = (t_u8 *)&ioctl_cfg;
8032     ioctl_req.buf_len                 = sizeof(ioctl_cfg);
8033     ioctl_cfg.param.multi_chan_policy = mc_policy;
8034     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MULTI_CHAN_POLICY,
8035                                    HostCmd_ACT_GEN_SET, 0, NULL, &mc_policy, cmd);
8036     (void)wifi_wait_for_cmdresp(NULL);
8037     wm_wifi.cmd_resp_ioctl = NULL;
8038     return wm_wifi.cmd_resp_status;
8039 }
8040 
wifi_get_mc_policy(void)8041 int wifi_get_mc_policy(void)
8042 {
8043     return (int)mlan_adap->mc_policy;
8044 }
8045 
wifi_set_mc_cfg_ext(const wifi_drcs_cfg_t * drcs,const int num)8046 int wifi_set_mc_cfg_ext(const wifi_drcs_cfg_t *drcs, const int num)
8047 {
8048     (void)wifi_get_command_lock();
8049     HostCmd_DS_COMMAND *cmd      = wifi_get_command_buffer();
8050     mlan_ds_drcs_cfg drcs_cfg[2] = {0};
8051 
8052     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
8053     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, 0U /* bss_type */);
8054     cmd->result  = 0x0;
8055 
8056     /* struct align is different */
8057     (void)memcpy(&drcs_cfg[0], drcs, sizeof(mlan_ds_drcs_cfg));
8058     if (num == 2)
8059     {
8060         (void)memcpy(&drcs_cfg[1], drcs + 1, sizeof(mlan_ds_drcs_cfg));
8061     }
8062 
8063     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_DRCS_CONFIG, HostCmd_ACT_GEN_SET, 0,
8064                                    NULL, &drcs_cfg, cmd);
8065     (void)wifi_wait_for_cmdresp(NULL);
8066     return wm_wifi.cmd_resp_status;
8067 }
8068 
wifi_get_mc_cfg_ext(wifi_drcs_cfg_t * drcs,int num)8069 int wifi_get_mc_cfg_ext(wifi_drcs_cfg_t *drcs, int num)
8070 {
8071     (void)wifi_get_command_lock();
8072     HostCmd_DS_COMMAND *cmd    = wifi_get_command_buffer();
8073     mlan_ioctl_req ioctl_req   = {0};
8074     mlan_ds_misc_cfg ioctl_cfg = {0};
8075 
8076     if (num != 2)
8077     {
8078         wifi_e("drcs should get 2 drcs config");
8079         (void)wifi_put_command_lock();
8080         return -WM_FAIL;
8081     }
8082 
8083     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
8084     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, 0U /* bss_type */);
8085     cmd->result  = 0x0;
8086 
8087     wm_wifi.cmd_resp_ioctl = &ioctl_req;
8088     ioctl_req.pbuf         = (t_u8 *)&ioctl_cfg;
8089     ioctl_req.buf_len      = sizeof(ioctl_cfg);
8090 
8091     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_DRCS_CONFIG, HostCmd_ACT_GEN_GET, 0,
8092                                    NULL, &ioctl_cfg.param.drcs_cfg[0], cmd);
8093     (void)wifi_wait_for_cmdresp(NULL);
8094     wm_wifi.cmd_resp_ioctl = NULL;
8095 
8096     /* struct align is different */
8097     (void)memcpy(drcs, &ioctl_cfg.param.drcs_cfg[0], sizeof(mlan_ds_drcs_cfg));
8098     (void)memcpy(drcs + 1, &ioctl_cfg.param.drcs_cfg[1], sizeof(mlan_ds_drcs_cfg));
8099     return wm_wifi.cmd_resp_status;
8100 }
8101 #endif
8102 
8103 #if CONFIG_1AS
wifi_get_fw_timestamp(wifi_correlated_time_t * time)8104 int wifi_get_fw_timestamp(wifi_correlated_time_t *time)
8105 {
8106     (void)wifi_get_command_lock();
8107     HostCmd_DS_COMMAND *cmd        = wifi_get_command_buffer();
8108     mlan_ioctl_req ioctl_req       = {0};
8109     mlan_ds_misc_cfg ioctl_cfg     = {0};
8110     mlan_ds_host_clock *host_clock = &ioctl_cfg.param.host_clock;
8111 
8112     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
8113     cmd->seq_num =
8114         HostCmd_SET_SEQ_NO_BSS_INFO((t_u16)0U /* seq_num */, (t_u16)0U /* bss_num */, (t_u16)0U /* bss_type */);
8115     cmd->result = 0x0;
8116 
8117     wm_wifi.cmd_resp_ioctl = &ioctl_req;
8118     ioctl_req.pbuf         = (t_u8 *)&ioctl_cfg;
8119     ioctl_req.buf_len      = sizeof(ioctl_cfg);
8120     /* host time in nano secs */
8121     host_clock->time = ((t_u64)os_get_timestamp() * 1000U);
8122 
8123     (void)wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_HOST_CLOCK_CFG, HostCmd_ACT_GEN_GET,
8124                                    0, NULL, host_clock, cmd);
8125     (void)wifi_wait_for_cmdresp(NULL);
8126     wm_wifi.cmd_resp_ioctl = NULL;
8127 
8128     (void)memcpy((void *)time, (const void *)host_clock, sizeof(wifi_correlated_time_t));
8129     return wm_wifi.cmd_resp_status;
8130 }
8131 
wifi_request_timing_measurement(int bss_type,t_u8 * peer_mac,t_u8 trigger)8132 void wifi_request_timing_measurement(int bss_type, t_u8 *peer_mac, t_u8 trigger)
8133 {
8134     mlan_private *pmpriv = mlan_adap->priv[bss_type];
8135 
8136     wlan_send_timing_measurement_req_frame(pmpriv, peer_mac, trigger);
8137 }
8138 
wifi_end_timing_measurement(int bss_type)8139 void wifi_end_timing_measurement(int bss_type)
8140 {
8141     mlan_private *pmpriv     = mlan_adap->priv[bss_type];
8142     wifi_dot1as_info_t *info = &pmpriv->dot1as_info;
8143 
8144     info->status = DOT1AS_TM_STATUS_COMPLETE;
8145 
8146     (void)PRINTF("Xmit timing measurement finish, peer " MACSTR ", tm number %d, t1[%u] t4[%u]\r\n",
8147                  MAC2STR(info->peer_addr), info->tm_num, info->t1, info->t4);
8148     wlan_end_timing_measurement((wlan_dot1as_info_t *)info);
8149 }
8150 
wifi_start_timing_measurement(int bss_type,t_u8 * peer_mac,uint8_t num_of_tm)8151 int wifi_start_timing_measurement(int bss_type, t_u8 *peer_mac, uint8_t num_of_tm)
8152 {
8153     mlan_status ret;
8154     mlan_private *pmpriv = mlan_adap->priv[bss_type];
8155 
8156     assert(peer_mac != MNULL);
8157 
8158     if (pmpriv->dot1as_info.status == (t_u8)DOT1AS_TM_STATUS_INPROGRESS)
8159     {
8160         wifi_e("wlan_start_timing_measurement abort previous tm procedure, peer " MACSTR,
8161                MAC2STR(pmpriv->dot1as_info.peer_addr));
8162         wifi_end_timing_measurement(bss_type);
8163         return -WM_FAIL;
8164     }
8165 
8166     (void)memset(&pmpriv->dot1as_info, 0x00, sizeof(wifi_dot1as_info_t));
8167     (void)memcpy(&pmpriv->dot1as_info.peer_addr[0], peer_mac, MLAN_MAC_ADDR_LENGTH);
8168     pmpriv->dot1as_info.role              = DOT1AS_TM_ROLE_TRANSMITTER;
8169     pmpriv->dot1as_info.max_tm_num        = num_of_tm;
8170     pmpriv->dot1as_info.dialog_token      = 1;
8171     pmpriv->dot1as_info.prev_dialog_token = 0;
8172     pmpriv->dot1as_info.status            = DOT1AS_TM_STATUS_INPROGRESS;
8173 
8174     ret = wlan_send_timing_measurement_frame(pmpriv);
8175     if (ret != MLAN_STATUS_SUCCESS)
8176     {
8177         wifi_e("wlan_start_timing_measurement fail on send tm frame");
8178         wifi_end_timing_measurement(bss_type);
8179         return -WM_FAIL;
8180     }
8181     return WM_SUCCESS;
8182 }
8183 #endif
8184 
8185 #if CONFIG_SUBSCRIBE_EVENT_SUPPORT
8186 /**
8187  *  @brief This function submit the subscribe event command to firmware.
8188  *
8189  *  @param priv       A pointer to mlan_private structure.
8190  *  @sub_evt          subscribe event to submit.
8191  *
8192  *  @return           MLAN_STATUS_SUCCESS, WM_E_INVAL or MLAN_STATUS_FAILURE
8193  */
wifi_subscribe_event_submit(mlan_private * pmpriv,mlan_ds_subscribe_evt * sub_evt)8194 int wifi_subscribe_event_submit(mlan_private *pmpriv, mlan_ds_subscribe_evt *sub_evt)
8195 {
8196     wifi_get_command_lock();
8197     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
8198     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
8199     cmd->command = HostCmd_CMD_802_11_SUBSCRIBE_EVENT;
8200     cmd->seq_num = 0;
8201     cmd->result  = 0x0;
8202 
8203     if (sub_evt->evt_action != HostCmd_ACT_GEN_GET)
8204     {
8205         wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT, HostCmd_ACT_GEN_SET, 0, NULL, sub_evt,
8206                                  cmd);
8207         wifi_wait_for_cmdresp(NULL);
8208     }
8209     else if (sub_evt->evt_action == HostCmd_ACT_GEN_GET)
8210     {
8211         wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT, HostCmd_ACT_GEN_GET, 0, NULL, NULL, cmd);
8212         wifi_wait_for_cmdresp(sub_evt);
8213     }
8214     else
8215         return WM_E_INVAL;
8216 
8217     return wm_wifi.cmd_resp_status;
8218 }
8219 
8220 /**
8221  *  @brief This function get all subscribe event from firmware.
8222  *
8223  *  @param priv       A pointer to mlan_private structure.
8224  *  @sub_evt          subscribe event to submit.
8225  *
8226  *  @return           MLAN_STATUS_SUCCESS, WM_E_INVAL or MLAN_STATUS_FAILURE
8227  */
wifi_get_subscribe_event(mlan_private * pmpriv,mlan_ds_subscribe_evt * sub_evt)8228 int wifi_get_subscribe_event(mlan_private *pmpriv, mlan_ds_subscribe_evt *sub_evt)
8229 {
8230     if (!sub_evt)
8231         return WM_E_INVAL;
8232     if (!pmpriv)
8233         pmpriv = mlan_adap->priv[0];
8234     sub_evt->evt_action = HostCmd_ACT_GEN_GET;
8235     return wifi_subscribe_event_submit(pmpriv, sub_evt);
8236 }
8237 
8238 /**
8239  *  @brief This function disable the specific subscribe event.
8240  *
8241  *  @param priv       A pointer to mlan_private structure.
8242  *  @sbitmap          the specific subscribe event will be disabled.
8243  *
8244  *  @return           MLAN_STATUS_SUCCESS, WM_E_INVAL or MLAN_STATUS_FAILURE
8245  */
wifi_clear_subscribe_event(mlan_private * pmpriv,int evt_bitmap)8246 int wifi_clear_subscribe_event(mlan_private *pmpriv, int evt_bitmap)
8247 {
8248     mlan_ds_subscribe_evt sub_evt;
8249     if (!pmpriv)
8250         pmpriv = mlan_adap->priv[0];
8251     memset((t_u8 *)&sub_evt, 0, sizeof(sub_evt));
8252     sub_evt.evt_action = SUBSCRIBE_EVT_ACT_BITWISE_CLR;
8253     sub_evt.evt_bitmap = evt_bitmap;
8254     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8255 }
8256 
wifi_set_threshold_rssi_low(mlan_private * pmpriv,unsigned int rssi_low,unsigned int freq)8257 int wifi_set_threshold_rssi_low(mlan_private *pmpriv, unsigned int rssi_low, unsigned int freq)
8258 {
8259     if (!pmpriv)
8260         return WM_E_INVAL;
8261     mlan_ds_subscribe_evt sub_evt;
8262     sub_evt.evt_action    = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8263     sub_evt.evt_bitmap    = SUBSCRIBE_EVT_RSSI_LOW;
8264     sub_evt.low_rssi      = rssi_low;
8265     sub_evt.low_rssi_freq = freq;
8266     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8267 }
wifi_set_threshold_rssi_high(mlan_private * pmpriv,unsigned int rssi_high,unsigned int freq)8268 int wifi_set_threshold_rssi_high(mlan_private *pmpriv, unsigned int rssi_high, unsigned int freq)
8269 {
8270     if (!pmpriv)
8271         return WM_E_INVAL;
8272     mlan_ds_subscribe_evt sub_evt;
8273     sub_evt.evt_action     = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8274     sub_evt.evt_bitmap     = SUBSCRIBE_EVT_RSSI_HIGH;
8275     sub_evt.high_rssi      = rssi_high;
8276     sub_evt.high_rssi_freq = freq;
8277     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8278 }
wifi_set_threshold_snr_low(mlan_private * pmpriv,unsigned int snr_low,unsigned int freq)8279 int wifi_set_threshold_snr_low(mlan_private *pmpriv, unsigned int snr_low, unsigned int freq)
8280 {
8281     if (!pmpriv)
8282         return WM_E_INVAL;
8283     mlan_ds_subscribe_evt sub_evt;
8284     sub_evt.evt_action   = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8285     sub_evt.evt_bitmap   = SUBSCRIBE_EVT_SNR_LOW;
8286     sub_evt.low_snr      = snr_low;
8287     sub_evt.low_snr_freq = freq;
8288     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8289 }
8290 
wifi_set_threshold_snr_high(mlan_private * pmpriv,unsigned int snr_high,unsigned int freq)8291 int wifi_set_threshold_snr_high(mlan_private *pmpriv, unsigned int snr_high, unsigned int freq)
8292 {
8293     if (!pmpriv)
8294         return WM_E_INVAL;
8295     mlan_ds_subscribe_evt sub_evt;
8296     sub_evt.evt_action    = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8297     sub_evt.evt_bitmap    = SUBSCRIBE_EVT_SNR_HIGH;
8298     sub_evt.high_snr      = snr_high;
8299     sub_evt.high_snr_freq = freq;
8300     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8301 }
wifi_set_threshold_max_fail(mlan_private * pmpriv,unsigned int max_fail,unsigned int freq)8302 int wifi_set_threshold_max_fail(mlan_private *pmpriv, unsigned int max_fail, unsigned int freq)
8303 {
8304     if (!pmpriv)
8305         return WM_E_INVAL;
8306     mlan_ds_subscribe_evt sub_evt;
8307     sub_evt.evt_action         = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8308     sub_evt.evt_bitmap         = SUBSCRIBE_EVT_MAX_FAIL;
8309     sub_evt.failure_count      = max_fail;
8310     sub_evt.failure_count_freq = freq;
8311     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8312 }
8313 
wifi_set_threshold_beacon_miss(mlan_private * pmpriv,unsigned int beacon_miss,unsigned int freq)8314 int wifi_set_threshold_beacon_miss(mlan_private *pmpriv, unsigned int beacon_miss, unsigned int freq)
8315 {
8316     if (!pmpriv)
8317         return WM_E_INVAL;
8318     mlan_ds_subscribe_evt sub_evt;
8319     sub_evt.evt_action       = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8320     sub_evt.evt_bitmap       = SUBSCRIBE_EVT_BEACON_MISSED;
8321     sub_evt.beacon_miss      = beacon_miss;
8322     sub_evt.beacon_miss_freq = freq;
8323     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8324 }
8325 
wifi_set_threshold_data_rssi_low(mlan_private * pmpriv,unsigned int data_rssi_low,unsigned int freq)8326 int wifi_set_threshold_data_rssi_low(mlan_private *pmpriv, unsigned int data_rssi_low, unsigned int freq)
8327 {
8328     if (!pmpriv)
8329         return WM_E_INVAL;
8330     mlan_ds_subscribe_evt sub_evt;
8331     sub_evt.evt_action         = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8332     sub_evt.evt_bitmap         = SUBSCRIBE_EVT_DATA_RSSI_LOW;
8333     sub_evt.data_low_rssi      = data_rssi_low;
8334     sub_evt.data_low_rssi_freq = freq;
8335     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8336 }
8337 
wifi_set_threshold_data_rssi_high(mlan_private * pmpriv,unsigned int data_rssi_high,unsigned int freq)8338 int wifi_set_threshold_data_rssi_high(mlan_private *pmpriv, unsigned int data_rssi_high, unsigned int freq)
8339 {
8340     if (!pmpriv)
8341         return WM_E_INVAL;
8342     mlan_ds_subscribe_evt sub_evt;
8343     sub_evt.evt_action          = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8344     sub_evt.evt_bitmap          = SUBSCRIBE_EVT_DATA_RSSI_HIGH;
8345     sub_evt.data_high_rssi      = data_rssi_high;
8346     sub_evt.data_high_rssi_freq = freq;
8347     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8348 }
8349 
wifi_set_threshold_data_snr_low(mlan_private * pmpriv,unsigned int data_snr_low,unsigned int freq)8350 int wifi_set_threshold_data_snr_low(mlan_private *pmpriv, unsigned int data_snr_low, unsigned int freq)
8351 {
8352     if (!pmpriv)
8353         return WM_E_INVAL;
8354     mlan_ds_subscribe_evt sub_evt;
8355     sub_evt.evt_action        = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8356     sub_evt.evt_bitmap        = SUBSCRIBE_EVT_DATA_SNR_LOW;
8357     sub_evt.data_low_snr      = data_snr_low;
8358     sub_evt.data_low_snr_freq = freq;
8359     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8360 }
8361 
wifi_set_threshold_data_snr_high(mlan_private * pmpriv,unsigned int data_snr_high,unsigned int freq)8362 int wifi_set_threshold_data_snr_high(mlan_private *pmpriv, unsigned int data_snr_high, unsigned int freq)
8363 {
8364     if (!pmpriv)
8365         return WM_E_INVAL;
8366     mlan_ds_subscribe_evt sub_evt;
8367     sub_evt.evt_action         = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8368     sub_evt.evt_bitmap         = SUBSCRIBE_EVT_DATA_SNR_HIGH;
8369     sub_evt.data_high_snr      = data_snr_high;
8370     sub_evt.data_high_snr_freq = freq;
8371     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8372 }
8373 
wifi_set_threshold_link_quality(mlan_private * pmpriv,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)8374 int wifi_set_threshold_link_quality(mlan_private *pmpriv,
8375                                     unsigned int link_snr,
8376                                     unsigned int link_snr_freq,
8377                                     unsigned int link_rate,
8378                                     unsigned int link_rate_freq,
8379                                     unsigned int link_tx_latency,
8380                                     unsigned int link_tx_lantency_freq)
8381 {
8382     mlan_ds_subscribe_evt sub_evt;
8383     sub_evt.evt_action            = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8384     sub_evt.evt_bitmap            = SUBSCRIBE_EVT_LINK_QUALITY;
8385     sub_evt.link_snr              = link_snr;
8386     sub_evt.link_snr_freq         = link_snr_freq;
8387     sub_evt.link_rate             = link_rate;
8388     sub_evt.link_rate_freq        = link_rate_freq;
8389     sub_evt.link_tx_latency       = link_tx_latency;
8390     sub_evt.link_tx_lantency_freq = link_tx_lantency_freq;
8391     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8392 }
8393 
wifi_set_threshold_pre_beacon_lost(mlan_private * pmpriv,unsigned int pre_beacon_lost,unsigned int freq)8394 int wifi_set_threshold_pre_beacon_lost(mlan_private *pmpriv, unsigned int pre_beacon_lost, unsigned int freq)
8395 {
8396     if (!pmpriv)
8397         return WM_E_INVAL;
8398     mlan_ds_subscribe_evt sub_evt;
8399     sub_evt.evt_action      = SUBSCRIBE_EVT_ACT_BITWISE_SET;
8400     sub_evt.evt_bitmap      = SUBSCRIBE_EVT_PRE_BEACON_LOST;
8401     sub_evt.pre_beacon_miss = pre_beacon_lost;
8402     return wifi_subscribe_event_submit(pmpriv, &sub_evt);
8403 }
8404 #endif
8405 
8406 #if CONFIG_11MC
8407 static location_cfg_info_t g_ftm_location_cfg;
8408 static location_civic_rep_t g_ftm_civic_cfg;
8409 
wlan_civic_ftm_cfg(location_civic_rep_t * ftm_civic_cfg)8410 void wlan_civic_ftm_cfg(location_civic_rep_t *ftm_civic_cfg)
8411 {
8412     g_ftm_civic_cfg.civic_location_type = ftm_civic_cfg->civic_location_type;
8413     g_ftm_civic_cfg.civic_address_type  = ftm_civic_cfg->civic_address_type;
8414     g_ftm_civic_cfg.civic_req           = ftm_civic_cfg->civic_req;
8415     g_ftm_civic_cfg.country_code        = ftm_civic_cfg->country_code;
8416 }
8417 
wlan_location_ftm_cfg(location_cfg_info_t * ftm_location_cfg)8418 void wlan_location_ftm_cfg(location_cfg_info_t *ftm_location_cfg)
8419 {
8420     g_ftm_location_cfg.lat_unc   = ftm_location_cfg->lat_unc;
8421     g_ftm_location_cfg.long_unc  = ftm_location_cfg->long_unc;
8422     g_ftm_location_cfg.alt_unc   = ftm_location_cfg->alt_unc;
8423     g_ftm_location_cfg.lci_req   = ftm_location_cfg->lci_req;
8424     g_ftm_location_cfg.longitude = ftm_location_cfg->longitude;
8425     g_ftm_location_cfg.latitude  = ftm_location_cfg->latitude;
8426     g_ftm_location_cfg.altitude  = ftm_location_cfg->altitude;
8427 }
8428 
wlan_dot11mc_ftm_cfg(void * p_buf,ftm_11mc_nego_cfg_t * ftm_11mc_nego_cfg)8429 void wlan_dot11mc_ftm_cfg(void *p_buf, ftm_11mc_nego_cfg_t *ftm_11mc_nego_cfg)
8430 {
8431     HostCmd_DS_COMMAND *cmd     = (HostCmd_DS_COMMAND *)p_buf;
8432     dot11mc_ftm_cfg_t *cfg_11mc = (dot11mc_ftm_cfg_t *)&cmd->params.ftm_session_cfg.tlv.cfg_11mc;
8433 
8434     cfg_11mc->sess_tlv.type                = wlan_cpu_to_le16(FTM_SESSION_CFG_INITATOR_TLV_ID);
8435     cfg_11mc->sess_tlv.len                 = wlan_cpu_to_le16(sizeof(ftm_session_cfg_t) + sizeof(t_u16));
8436     cfg_11mc->sess_tlv.val.burst_exponent  = ftm_11mc_nego_cfg->burst_exponent;
8437     cfg_11mc->sess_tlv.val.burst_duration  = ftm_11mc_nego_cfg->burst_duration;
8438     cfg_11mc->sess_tlv.val.min_delta_FTM   = ftm_11mc_nego_cfg->min_delta_FTM;
8439     cfg_11mc->sess_tlv.val.is_ASAP         = ftm_11mc_nego_cfg->is_ASAP;
8440     cfg_11mc->sess_tlv.val.per_burst_FTM   = ftm_11mc_nego_cfg->per_burst_FTM;
8441     cfg_11mc->sess_tlv.val.channel_spacing = ftm_11mc_nego_cfg->channel_spacing;
8442     cfg_11mc->sess_tlv.val.burst_period    = wlan_cpu_to_le16(ftm_11mc_nego_cfg->burst_period);
8443     cfg_11mc->sess_tlv.civic_req           = g_ftm_civic_cfg.civic_req;
8444     cfg_11mc->sess_tlv.lci_req             = g_ftm_location_cfg.lci_req;
8445     cmd->size += sizeof(ftm_session_cfg_tlv_t);
8446 
8447     if (cfg_11mc->sess_tlv.lci_req)
8448     {
8449         cfg_11mc->lci_tlv.type          = wlan_cpu_to_le16(FTM_SESSION_CFG_LCI_TLV_ID);
8450         cfg_11mc->lci_tlv.len           = wlan_cpu_to_le16(sizeof(lci_cfg_t));
8451         cfg_11mc->lci_tlv.val.altitude  = g_ftm_location_cfg.altitude;
8452         cfg_11mc->lci_tlv.val.alt_unc   = g_ftm_location_cfg.alt_unc;
8453         cfg_11mc->lci_tlv.val.latitude  = g_ftm_location_cfg.latitude;
8454         cfg_11mc->lci_tlv.val.lat_unc   = g_ftm_location_cfg.lat_unc;
8455         cfg_11mc->lci_tlv.val.longitude = g_ftm_location_cfg.longitude;
8456         cfg_11mc->lci_tlv.val.long_unc  = g_ftm_location_cfg.long_unc;
8457         cfg_11mc->lci_tlv.val.z_info    = Z_INFO;
8458         cmd->size += sizeof(lci_tlv_t);
8459     }
8460 
8461     if (cfg_11mc->sess_tlv.civic_req)
8462     {
8463         cfg_11mc->civic_tlv.type                     = wlan_cpu_to_le16(FTM_SESSION_CFG_LOCATION_CIVIC_TLV_ID);
8464         cfg_11mc->civic_tlv.len                      = wlan_cpu_to_le16(sizeof(civic_loc_cfg_t) -
8465                                                                         sizeof(cfg_11mc->civic_tlv.val.civic_address) + strlen(ftm_address));
8466         cfg_11mc->civic_tlv.val.civic_address_type   = g_ftm_civic_cfg.civic_address_type;
8467         cfg_11mc->civic_tlv.val.civic_location_type  = g_ftm_civic_cfg.civic_location_type;
8468         cfg_11mc->civic_tlv.val.country_code         = wlan_cpu_to_le16(g_ftm_civic_cfg.country_code);
8469         cfg_11mc->civic_tlv.val.civic_address_length = strlen(ftm_address);
8470         (void)memcpy(cfg_11mc->civic_tlv.val.civic_address, ftm_address, strlen(ftm_address));
8471         cmd->size += (cfg_11mc->civic_tlv.len + sizeof(t_u32)) + sizeof(t_u16);
8472     }
8473 
8474     cmd->size = wlan_cpu_to_le16(cmd->size);
8475 }
8476 #endif
8477 
8478 #if CONFIG_11AZ
wlan_dto11az_ranging_cfg(void * p_buf,const t_u8 protocl,HostCmd_FTM_SESSION_CFG * ftm_session_cfg)8479 void wlan_dto11az_ranging_cfg(void *p_buf, const t_u8 protocl, HostCmd_FTM_SESSION_CFG *ftm_session_cfg)
8480 {
8481     HostCmd_DS_COMMAND *cmd        = (HostCmd_DS_COMMAND *)p_buf;
8482     dot11az_ftm_cfg_t *cfg_11az    = (dot11az_ftm_cfg_t *)&cmd->params.ftm_session_cfg.tlv.cfg_11az;
8483     dot11az_ftm_cfg_t *in_cfg_11az = &ftm_session_cfg->tlv.cfg_11az;
8484     cfg_11az->range_tlv.len        = wlan_cpu_to_le16(sizeof(ranging_cfg_t));
8485 
8486     if (protocl == PROTO_DOT11AZ_TB)
8487         cfg_11az->range_tlv.type = wlan_cpu_to_le16(FTM_TB_RANGING_CFG_TLV_ID);
8488     else
8489         cfg_11az->range_tlv.type = wlan_cpu_to_le16(FTM_NTB_RANGING_CFG_TLV_ID);
8490 
8491     cfg_11az->range_tlv.val.format_bw                 = in_cfg_11az->range_tlv.val.format_bw;
8492     cfg_11az->range_tlv.val.max_i2r_sts_upto80        = in_cfg_11az->range_tlv.val.max_i2r_sts_upto80;
8493     cfg_11az->range_tlv.val.max_r2i_sts_upto80        = in_cfg_11az->range_tlv.val.max_r2i_sts_upto80;
8494     cfg_11az->range_tlv.val.az_measurement_freq       = in_cfg_11az->range_tlv.val.az_measurement_freq;
8495     cfg_11az->range_tlv.val.az_number_of_measurements = in_cfg_11az->range_tlv.val.az_number_of_measurements;
8496     cfg_11az->range_tlv.val.i2r_lmr_feedback          = in_cfg_11az->range_tlv.val.i2r_lmr_feedback;
8497 
8498     cfg_11az->range_tlv.val.civic_req = in_cfg_11az->range_tlv.val.civic_req;
8499     cfg_11az->range_tlv.val.lci_req   = in_cfg_11az->range_tlv.val.lci_req;
8500 
8501     cmd->size += (sizeof(dot11az_ftm_cfg_t));
8502 }
8503 #endif
8504 
8505 #if (CONFIG_11MC) || (CONFIG_11AZ)
wifi_ftm_process_cfg_resp(void * resp_buff)8506 void wifi_ftm_process_cfg_resp(void *resp_buff)
8507 {
8508     HostCmd_DS_COMMAND *resp = (HostCmd_DS_COMMAND *)resp_buff;
8509 
8510     if ((wlan_cpu_to_le16(resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.type) == FTM_NTB_RANGING_CFG_TLV_ID) ||
8511         (wlan_cpu_to_le16(resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.type) == FTM_TB_RANGING_CFG_TLV_ID))
8512     {
8513         if (resp->params.ftm_session_cfg.action == MLAN_ACT_SET)
8514             wifi_d("\n\nSet Ranging Parameters: \r\n");
8515         else
8516             wifi_d("\n\nGet Ranging Parameters: \r\n");
8517         wifi_d("---------------------------------\r\n");
8518         wifi_d("format_bw:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.val.format_bw);
8519         wifi_d("az_measurement_freq:%d \r\n",
8520                resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.val.az_measurement_freq);
8521         wifi_d("az_number_of_measurements:%d \r\n",
8522                resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.val.az_number_of_measurements);
8523         wifi_d("max_i2r_sts_upto80:%d \r\n",
8524                resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.val.max_i2r_sts_upto80);
8525         wifi_d("max_r2i_sts_upto80:%d \r\n",
8526                resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.val.max_r2i_sts_upto80);
8527         wifi_d("i2r_lmr_feedback:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11az.range_tlv.val.i2r_lmr_feedback);
8528     }
8529     else if (wlan_cpu_to_le16(resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.type) ==
8530              FTM_SESSION_CFG_INITATOR_TLV_ID)
8531     {
8532         if (resp->params.ftm_session_cfg.action == BG_SCAN_ACT_SET)
8533             wifi_d("\n\nSet dot11mc ftm session config: \r\n");
8534         else
8535             wifi_d("\n\nGet dot11mc ftm session config: \r\n");
8536 
8537         wifi_d("---------------------------------\r\n");
8538         wifi_d("burst_exponent:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.val.burst_exponent);
8539         wifi_d("burst_duration:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.val.burst_duration);
8540         wifi_d("min_delta_FTM:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.val.min_delta_FTM);
8541         wifi_d("is_ASAP:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.val.is_ASAP);
8542         wifi_d("per_burst_FTM:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.val.per_burst_FTM);
8543         wifi_d("channel_spacing:%d \r\n", resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.val.channel_spacing);
8544         wifi_d("burst_period:%d \n\n", resp->params.ftm_session_cfg.tlv.cfg_11mc.sess_tlv.val.burst_period);
8545     }
8546     else
8547         wifi_d("Invaild TLV return code \r\n");
8548 }
8549 
wifi_ftm_process_ctrl_resp(void * resp_buff)8550 void wifi_ftm_process_ctrl_resp(void *resp_buff)
8551 {
8552     HostCmd_DS_COMMAND *resp = (HostCmd_DS_COMMAND *)resp_buff;
8553 
8554     if (resp->result == HostCmd_RESULT_OK)
8555     {
8556         if (resp->params.ftm_session_ctrl.action == FTM_ACTION_START)
8557         {
8558             wifi_d("[INFO] FTM Session Control Started on %d channel with Peer %02X:%02X:%02X:%02X:%02X:%02X \r\n",
8559                    resp->params.ftm_session_ctrl.chan, resp->params.ftm_session_ctrl.peer_mac[0],
8560                    resp->params.ftm_session_ctrl.peer_mac[1], resp->params.ftm_session_ctrl.peer_mac[2],
8561                    resp->params.ftm_session_ctrl.peer_mac[3], resp->params.ftm_session_ctrl.peer_mac[4],
8562                    resp->params.ftm_session_ctrl.peer_mac[5]);
8563         }
8564         else if (resp->params.ftm_session_ctrl.action == FTM_ACTION_STOP)
8565             wifi_d("[INFO] FTM Session Stopped\r\n");
8566         else
8567             wifi_d("[ERROR] Hostcmd action not supported\r\n");
8568     }
8569     else
8570     {
8571         wifi_d("[ERROR] Hostcmd failed: ReturnCode=%#04x, Result=%#04x\n", wlan_cpu_to_le16(resp->command),
8572                wlan_cpu_to_le16(resp->result));
8573     }
8574 }
8575 
wifi_ftm_process_event(void * p_data)8576 void wifi_ftm_process_event(void *p_data)
8577 {
8578     wls_event_t *ftm_event = (wls_event_t *)p_data;
8579     double distance        = 0.0;
8580 
8581     wevt_d("[INFO] EventID: 0x%x SubeventID:%d \r\n", ftm_event->event_id, ftm_event->sub_event_id);
8582 
8583     switch (ftm_event->sub_event_id)
8584     {
8585         case WLS_SUB_EVENT_FTM_COMPLETE:
8586             PRINTF("\n\nFTM Session Complete:\r\n");
8587             PRINTF("=====================\r\n");
8588             PRINTF("Average RTT: %d ns\r\n", ftm_event->e.ftm_complete.avg_rtt);
8589             PRINTF("Average Clockoffset:%d ns\r\n", ftm_event->e.ftm_complete.avg_clk_offset);
8590             distance = ((ftm_event->e.ftm_complete.avg_clk_offset / 2) * (0.0003));
8591             PRINTF("Distance: %.6f meters\r\n\n", distance);
8592             wlan_wlcmgr_send_msg(WIFI_EVENT_FTM_COMPLETE, WIFI_EVENT_REASON_SUCCESS, NULL);
8593             break;
8594         case WLS_SUB_EVENT_RADIO_RECEIVED:
8595             wifi_d("WLS_SUB_EVENT_RADIO_RECEIVED\n");
8596             break;
8597         case WLS_SUB_EVENT_RADIO_RPT_RECEIVED:
8598             wifi_d("WLS_SUB_EVENT_RADIO_RPT_RECEIVED\n");
8599             break;
8600         case WLS_SUB_EVENT_ANQP_RESP_RECEIVED:
8601             wifi_d("WLS_SUB_EVENT_ANQP_RESP_RECEIVED\n");
8602             break;
8603         default:
8604             wifi_d("[ERROR] Unknown sub event\n");
8605             break;
8606     }
8607 }
8608 #endif
8609 
8610 #ifdef RW610
wifi_get_board_type()8611 uint32_t wifi_get_board_type()
8612 {
8613     status_t status;
8614     static uint32_t wifi_rw610_package_type = 0xFFFFFFFF;
8615 
8616     if (0xFFFFFFFF == wifi_rw610_package_type)
8617     {
8618         OCOTP_OtpInit();
8619         status = OCOTP_ReadPackage(&wifi_rw610_package_type);
8620         if (status != kStatus_Success)
8621         {
8622             /*If status error, use BGA as default type*/
8623             wifi_rw610_package_type = RW610_PACKAGE_TYPE_BGA;
8624         }
8625         OCOTP_OtpDeinit();
8626     }
8627 
8628     return wifi_rw610_package_type;
8629 }
8630 #endif
8631 
8632 #ifdef RW610
wifi_cau_temperature_enable()8633 void wifi_cau_temperature_enable()
8634 {
8635     t_u32 val;
8636 
8637     val = WIFI_REG32(WLAN_CAU_ENABLE_ADDR);
8638     val &= ~(0xC);
8639     val |= (2 << 2);
8640     WIFI_WRITE_REG32(WLAN_CAU_ENABLE_ADDR, val);
8641     OSA_TimeDelay(1);
8642 }
8643 
wifi_get_temperature(void)8644 int32_t wifi_get_temperature(void)
8645 {
8646     int32_t val                   = 0;
8647     uint32_t reg_val              = 0;
8648     uint32_t temp_Cau_Raw_Reading = 0;
8649     uint32_t board_type           = 0;
8650 
8651     reg_val              = WIFI_REG32(WLAN_CAU_TEMPERATURE_ADDR);
8652     temp_Cau_Raw_Reading = ((reg_val & 0XFFC00) >> 10);
8653     board_type           = wifi_get_board_type();
8654 
8655     switch (board_type)
8656     {
8657         case RW610_PACKAGE_TYPE_QFN:
8658             val = (((((int32_t)(temp_Cau_Raw_Reading)) * 484260) - 220040600) / 1000000);
8659             break;
8660 
8661         case RW610_PACKAGE_TYPE_CSP:
8662             val = (((((int32_t)(temp_Cau_Raw_Reading)) * 480560) - 220707000) / 1000000);
8663             break;
8664 
8665         case RW610_PACKAGE_TYPE_BGA:
8666             val = (((((int32_t)(temp_Cau_Raw_Reading)) * 480561) - 220707400) / 1000000);
8667             break;
8668 
8669         default:
8670             PRINTF("Unknown board type, use BGA temperature \r\n");
8671             val = (((((int32_t)(temp_Cau_Raw_Reading)) * 480561) - 220707400) / 1000000);
8672             break;
8673     }
8674 
8675     return val;
8676 }
8677 
wifi_cau_temperature_write_to_firmware()8678 int wifi_cau_temperature_write_to_firmware()
8679 {
8680     int32_t val = 0;
8681 
8682     val = wifi_get_temperature();
8683     WIFI_WRITE_REG32(WLAN_CAU_TEMPERATURE_FW_ADDR, val);
8684     return val;
8685 }
8686 #endif
8687 
8688 #if (CONFIG_WIFI_IND_RESET) && (CONFIG_WIFI_IND_DNLD)
wifi_set_indrst_cfg(const wifi_indrst_cfg_t * indrst_cfg,mlan_bss_type bss_type)8689 int wifi_set_indrst_cfg(const wifi_indrst_cfg_t *indrst_cfg, mlan_bss_type bss_type)
8690 {
8691     int ret;
8692     mlan_ds_misc_cfg misc;
8693     mlan_ioctl_req req;
8694 
8695     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
8696     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
8697 
8698     misc.param.ind_rst_cfg.ir_mode  = indrst_cfg->ir_mode;
8699     misc.param.ind_rst_cfg.gpio_pin = indrst_cfg->gpio_pin;
8700 
8701     misc.sub_command       = (t_u32)MLAN_OID_MISC_IND_RST_CFG;
8702     wm_wifi.cmd_resp_ioctl = &req;
8703     req.pbuf               = (t_u8 *)&misc;
8704     req.buf_len            = sizeof(mlan_ds_misc_cfg);
8705     req.req_id             = (t_u32)MLAN_IOCTL_MISC_CFG;
8706     req.action             = MLAN_ACT_SET;
8707 
8708     if (bss_type == MLAN_BSS_TYPE_UAP)
8709     {
8710         req.bss_index = (t_u32)MLAN_BSS_TYPE_UAP;
8711         ret           = (int)wlan_ops_uap_ioctl(mlan_adap, &req);
8712     }
8713     else
8714     {
8715         req.bss_index = (t_u32)MLAN_BSS_TYPE_STA;
8716         ret           = (int)wlan_ops_sta_ioctl(mlan_adap, &req);
8717     }
8718 
8719     wm_wifi.cmd_resp_ioctl = NULL;
8720     return ret;
8721 }
8722 
wifi_get_indrst_cfg(wifi_indrst_cfg_t * indrst_cfg,mlan_bss_type bss_type)8723 int wifi_get_indrst_cfg(wifi_indrst_cfg_t *indrst_cfg, mlan_bss_type bss_type)
8724 {
8725     int ret;
8726     mlan_ds_misc_cfg misc;
8727     mlan_ioctl_req req;
8728     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
8729     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
8730 
8731     misc.sub_command = (t_u32)MLAN_OID_MISC_IND_RST_CFG;
8732 
8733     wm_wifi.cmd_resp_ioctl = &req;
8734     req.pbuf               = (t_u8 *)&misc;
8735     req.buf_len            = sizeof(mlan_ds_misc_cfg);
8736     req.req_id             = (t_u32)MLAN_IOCTL_MISC_CFG;
8737     req.action             = MLAN_ACT_GET;
8738 
8739     ret                    = (int)wlan_ops_sta_ioctl(mlan_adap, &req);
8740     wm_wifi.cmd_resp_ioctl = NULL;
8741 
8742     if (ret == WM_SUCCESS)
8743     {
8744         indrst_cfg->ir_mode  = misc.param.ind_rst_cfg.ir_mode;
8745         indrst_cfg->gpio_pin = misc.param.ind_rst_cfg.gpio_pin;
8746     }
8747     return ret;
8748 }
8749 
wifi_test_independent_reset()8750 int wifi_test_independent_reset()
8751 {
8752     wifi_get_command_lock();
8753     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
8754 
8755     HostCmd_DS_IND_RST ind;
8756     /** Action */
8757     ind.action = 0;
8758     /** CMD_SUBID */
8759     ind.sub_id = 0x117;
8760     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
8761     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_STA);
8762     cmd->result  = 0x0;
8763     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_DBGS_CFG);
8764     cmd->size    = sizeof(HostCmd_DS_IND_RST) + S_DS_GEN;
8765     (void)memcpy(&cmd->params.ind_rst, &ind, sizeof(HostCmd_DS_IND_RST));
8766 
8767     wifi_wait_for_cmdresp(NULL);
8768     return WM_SUCCESS;
8769 }
8770 
wifi_trigger_oob_indrst()8771 int wifi_trigger_oob_indrst()
8772 {
8773     wlan_process_hang(FW_RELOAD_NO_EMULATION);
8774 
8775     return WM_SUCCESS;
8776 }
8777 
8778 #endif
8779