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