1 /** @file mlan_api.c
2  *
3  *  @brief This file provides more APIs for mlan.
4  *
5  *  Copyright 2008-2024 NXP
6  *
7  *  SPDX-License-Identifier: BSD-3-Clause
8  *
9  */
10 
11 #include <stdio.h>
12 #include <mlan_api.h>
13 #if CONFIG_COMBO_SCAN
14 #include <string.h>
15 #endif
16 /* Additional WMSDK header files */
17 #include <wmerrno.h>
18 #include <osa.h>
19 
20 #include <wifi.h>
21 
22 #if defined(RW610)
23 #include "wifi-imu.h"
24 #else
25 #include "wifi-sdio.h"
26 #endif
27 #include "wifi-internal.h"
28 
29 #if CONFIG_DRIVER_MBO
30 #include "mlan_mbo.h"
31 #endif
32 
33 /* Always keep this include at the end of all include files */
34 #include <mlan_remap_mem_operations.h>
35 
36 #if (CONFIG_11MC) || (CONFIG_11AZ)
37 #if CONFIG_WLS_CSI_PROC
38 #include <wls_param_defines.h>
39 #include <wls_api.h>
40 #include <wls_structure_defs.h>
41 #include <range_kalman.h>
42 #endif
43 #endif
44 
45 static const char driver_version_format[] = "SD878x-%s-%s-WM";
46 static const char driver_version[]        = "702.1.0";
47 
48 static unsigned int mgmt_ie_index_bitmap = 0x0000000F;
49 
50 #if (CONFIG_11MC) || (CONFIG_11AZ)
51 ftm_start_param ftm_param;
52 #if CONFIG_WLS_CSI_PROC
53 #define NL_MAX_PAYLOAD (3 * 1024)
54 unsigned int csi_res_array[8];
55 uint32_t wls_data[WLS_CSI_DATA_LEN_DW];
56 range_kalman_state range_input_str = {0};
57 #define RANGE_DRIVE_VAR       1e-5f // in meter/(s^2)
58 #define RANGE_MEASUREMENT_VAR 4e-2f // in meter^2
59 #define RANGE_RATE_INIT       1e-3f // in (meter/s)^2
60 #define CSI_TSF_LEN           6 * sizeof(uint32_t)
61 #define FFT_INBUFFER_LEN_DW   (MAX_RX * MAX_TX + NUM_PROC_BUF) * (MAX_IFFT_SIZE_CSI)
62 uint32_t fftInBuffer_t[FFT_INBUFFER_LEN_DW];
63 #endif
64 #endif
65 
66 /* This were static functions in mlan file */
67 mlan_status wlan_cmd_802_11_deauthenticate(IN pmlan_private pmpriv, IN HostCmd_DS_COMMAND *cmd, IN t_void *pdata_buf);
68 mlan_status wlan_cmd_reg_access(IN HostCmd_DS_COMMAND *cmd, IN t_u16 cmd_action, IN t_void *pdata_buf);
69 mlan_status wlan_cmd_mem_access(IN HostCmd_DS_COMMAND *cmd, IN t_u16 cmd_action, IN t_void *pdata_buf);
70 #if CONFIG_WLAN_BRIDGE
71 mlan_status wlan_cmd_bridge_mode(IN HostCmd_DS_COMMAND *cmd, IN t_u16 cmd_action, IN t_void *pdata_buf);
72 #endif
73 mlan_status wlan_cmd_auto_reconnect(IN HostCmd_DS_COMMAND *cmd, IN t_u16 cmd_action, IN t_void *pdata_buf);
74 mlan_status wlan_misc_ioctl_region(IN pmlan_adapter pmadapter, IN pmlan_ioctl_req pioctl_req);
75 #if CONFIG_11K_OFFLOAD
76 mlan_status wlan_cmd_11k_neighbor_req(mlan_private *pmpriv, HostCmd_DS_COMMAND *pcmd);
77 #endif
78 
79 int wifi_set_mac_multicast_addr(const char *mlist, t_u32 num_of_addr);
80 int wifi_send_disable_supplicant(int mode);
81 int wifi_send_rf_channel_cmd(wifi_rf_channel_t *rf_channel);
82 int wifi_get_set_rf_tx_power(t_u16 cmd_action, wifi_tx_power_t *tx_power);
83 
84 #ifdef RW610
wifi_send_shutdown_cmd()85 int wifi_send_shutdown_cmd()
86 {
87     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
88 
89     wifi_get_command_lock();
90 
91     cmd->command = HostCmd_CMD_FUNC_SHUTDOWN;
92     cmd->size    = S_DS_GEN;
93     cmd->seq_num = 0x0;
94     cmd->result  = 0x0;
95 
96     wifi_wait_for_cmdresp(NULL);
97     return WM_SUCCESS;
98 }
99 #endif
wifi_deauthenticate(uint8_t * bssid)100 int wifi_deauthenticate(uint8_t *bssid)
101 {
102     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
103 
104     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
105 
106     if (pmpriv->media_connected == MFALSE)
107     {
108         return WM_SUCCESS;
109     }
110 
111     (void)wifi_get_command_lock();
112 
113     /* fixme: check if this static selection is ok */
114 #if CONFIG_P2P
115     cmd->seq_num = (0x01) << 13;
116 #else
117     cmd->seq_num                      = 0x0;
118 #endif
119     cmd->result = 0x0;
120 
121     (void)wlan_cmd_802_11_deauthenticate((mlan_private *)mlan_adap->priv[0], cmd, bssid);
122     (void)wifi_wait_for_cmdresp(NULL);
123 
124     return WM_SUCCESS;
125 }
126 
127 #if CONFIG_WPA_SUPP
128 #define REASON_CODE_PEER_STA_LEAVING 36
wifi_nxp_deauthenticate(unsigned int bss_type,const uint8_t * bssid,uint16_t reason_code)129 int wifi_nxp_deauthenticate(unsigned int bss_type, const uint8_t *bssid, uint16_t reason_code)
130 {
131     mlan_private *pmpriv                      = (mlan_private *)mlan_adap->priv[bss_type];
132     HostCmd_DS_COMMAND *cmd                   = wifi_get_command_buffer();
133     HostCmd_DS_802_11_DEAUTHENTICATE *pdeauth = &cmd->params.deauth;
134 
135     pmpriv->curr_bss_params.host_mlme = 0;
136     pmpriv->auth_flag                 = 0;
137     pmpriv->auth_alg                  = 0xFFFF;
138 
139     if (pmpriv->media_connected == MFALSE)
140     {
141         return WM_SUCCESS;
142     }
143 
144     (void)wifi_get_command_lock();
145 
146     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
147     cmd->size    = wlan_cpu_to_le16(sizeof(HostCmd_DS_802_11_DEAUTHENTICATE) + S_DS_GEN);
148     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
149     cmd->result  = 0x0;
150 
151     /* Set AP MAC address */ (void)memcpy((void *)pdeauth->mac_addr, (const void *)bssid, (size_t)MLAN_MAC_ADDR_LENGTH);
152 
153     wifi_d("Deauth: %02x:%02x:%02x:%02x:%02x:%02x", pdeauth->mac_addr[0], pdeauth->mac_addr[1], pdeauth->mac_addr[2],
154            pdeauth->mac_addr[3], pdeauth->mac_addr[4], pdeauth->mac_addr[5]);
155 
156     if (pmpriv->adapter->state_11h.recvd_chanswann_event)
157     { /** Reason code 36 = Requested from peer station as it is leaving the BSS */
158         pdeauth->reason_code = wlan_cpu_to_le16(REASON_CODE_PEER_STA_LEAVING);
159     }
160     else
161     {
162         pdeauth->reason_code = wlan_cpu_to_le16(reason_code);
163     }
164     (void)wifi_wait_for_cmdresp(NULL);
165 
166     return WM_SUCCESS;
167 }
168 #endif
169 
wifi_get_eeprom_data(uint32_t offset,uint32_t byte_count,uint8_t * buf)170 int wifi_get_eeprom_data(uint32_t offset, uint32_t byte_count, uint8_t *buf)
171 {
172     mlan_ds_read_eeprom eeprom_rd;
173     eeprom_rd.offset     = offset;
174     eeprom_rd.byte_count = byte_count;
175 
176     (void)wifi_get_command_lock();
177     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
178 
179     cmd->command = HostCmd_CMD_802_11_EEPROM_ACCESS;
180     cmd->seq_num = 0x0;
181     cmd->result  = 0x0;
182 
183     (void)wlan_cmd_reg_access(cmd, HostCmd_ACT_GEN_GET, &eeprom_rd);
184     (void)wifi_wait_for_cmdresp(buf);
185     return wm_wifi.cmd_resp_status;
186 }
187 
wifi_reg_access(wifi_reg_t reg_type,uint16_t action,uint32_t offset,uint32_t * value)188 int wifi_reg_access(wifi_reg_t reg_type, uint16_t action, uint32_t offset, uint32_t *value)
189 {
190     mlan_ds_reg_rw reg_rw;
191     reg_rw.offset = offset;
192     reg_rw.value  = *value;
193     uint16_t hostcmd;
194     int ret = WM_SUCCESS;
195     switch (reg_type)
196     {
197         case REG_MAC:
198             hostcmd = HostCmd_CMD_MAC_REG_ACCESS;
199             break;
200         case REG_BBP:
201             hostcmd = HostCmd_CMD_BBP_REG_ACCESS;
202             break;
203         case REG_RF:
204             hostcmd = HostCmd_CMD_RF_REG_ACCESS;
205             break;
206         case REG_CAU:
207             hostcmd = HostCmd_CMD_CAU_REG_ACCESS;
208             break;
209         default:
210             wifi_e("Incorrect register type");
211             ret = -WM_FAIL;
212             break;
213     }
214 
215     if (ret != WM_SUCCESS)
216     {
217         return ret;
218     }
219 
220     (void)wifi_get_command_lock();
221     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
222 
223     cmd->command = hostcmd;
224     cmd->seq_num = 0x0;
225     cmd->result  = 0x0;
226 
227     (void)wlan_cmd_reg_access(cmd, action, &reg_rw);
228     (void)wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? value : NULL);
229     return wm_wifi.cmd_resp_status;
230 }
231 
wifi_mem_access(uint16_t action,uint32_t addr,uint32_t * value)232 int wifi_mem_access(uint16_t action, uint32_t addr, uint32_t *value)
233 {
234     mlan_ds_mem_rw mem_rw;
235     mem_rw.addr  = addr;
236     mem_rw.value = *value;
237 
238     (void)wifi_get_command_lock();
239     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
240 
241     cmd->command = HostCmd_CMD_MEM_ACCESS;
242     cmd->seq_num = 0x0;
243     cmd->result  = 0x0;
244 
245     (void)wlan_cmd_mem_access(cmd, action, &mem_rw);
246 
247     (void)wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? value : NULL);
248     return wm_wifi.cmd_resp_status;
249 }
250 
251 #if CONFIG_WIFI_BOOT_SLEEP
wifi_boot_sleep(uint16_t action,uint16_t * enable)252 int wifi_boot_sleep(uint16_t action, uint16_t *enable)
253 {
254     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
255 
256     (void)wifi_get_command_lock();
257     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
258 
259     cmd->command = HostCmd_CMD_BOOT_SLEEP;
260     cmd->seq_num = 0x0;
261     cmd->result  = 0x0;
262 
263     (void)wlan_cmd_boot_sleep(pmpriv, cmd, action, enable);
264 
265     (void)wifi_wait_for_cmdresp(enable);
266     return wm_wifi.cmd_resp_status;
267 }
268 #endif
269 
270 #if CONFIG_AUTO_RECONNECT
wifi_auto_reconnect(uint16_t action,wifi_auto_reconnect_config_t * auto_reconnect_config)271 static int wifi_auto_reconnect(uint16_t action, wifi_auto_reconnect_config_t *auto_reconnect_config)
272 {
273     mlan_ds_auto_reconnect auto_reconnect;
274 
275     (void)memset(&auto_reconnect, 0x00, sizeof(mlan_ds_auto_reconnect));
276 
277     if (auto_reconnect_config)
278     {
279         auto_reconnect.reconnect_counter  = auto_reconnect_config->reconnect_counter;
280         auto_reconnect.reconnect_interval = auto_reconnect_config->reconnect_interval;
281         auto_reconnect.flags              = auto_reconnect_config->flags;
282     }
283 
284     wifi_get_command_lock();
285     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
286 
287     cmd->command = HostCmd_CMD_AUTO_RECONNECT;
288     cmd->seq_num = 0x0;
289     cmd->result  = 0x0;
290 
291     wlan_cmd_auto_reconnect(cmd, action, &auto_reconnect);
292 
293     wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? auto_reconnect_config : NULL);
294 
295     return wm_wifi.cmd_resp_status;
296 }
297 
wifi_auto_reconnect_enable(wifi_auto_reconnect_config_t auto_reconnect_config)298 int wifi_auto_reconnect_enable(wifi_auto_reconnect_config_t auto_reconnect_config)
299 {
300     return wifi_auto_reconnect(HostCmd_ACT_GEN_SET, &auto_reconnect_config);
301 }
302 
wifi_auto_reconnect_disable(void)303 int wifi_auto_reconnect_disable(void)
304 {
305     return wifi_auto_reconnect(HostCmd_ACT_GEN_SET, NULL);
306 }
307 
wifi_get_auto_reconnect_config(wifi_auto_reconnect_config_t * auto_reconnect_config)308 int wifi_get_auto_reconnect_config(wifi_auto_reconnect_config_t *auto_reconnect_config)
309 {
310     return wifi_auto_reconnect(HostCmd_ACT_GEN_GET, auto_reconnect_config);
311 }
312 #endif
313 
wifi_get_tsf(uint32_t * tsf_high,uint32_t * tsf_low)314 int wifi_get_tsf(uint32_t *tsf_high, uint32_t *tsf_low)
315 {
316     t_u64 tsf = 0x00;
317 
318     (void)wifi_get_command_lock();
319     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
320 
321     (void)memset(cmd, 0, sizeof(HostCmd_DS_COMMAND));
322 
323     cmd->seq_num = 0x0;
324     cmd->result  = 0x0;
325 
326     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_GET_TSF,
327                                               HostCmd_ACT_GEN_GET, 0, NULL, NULL, cmd);
328     if (rv != MLAN_STATUS_SUCCESS)
329     {
330         return -WM_FAIL;
331     }
332 
333     (void)wifi_wait_for_cmdresp(&tsf);
334 
335     *tsf_high = tsf >> 32;
336     *tsf_low  = (t_u32)tsf;
337 
338     return wm_wifi.cmd_resp_status;
339 }
340 
341 #if CONFIG_WLAN_BRIDGE
wifi_bridge_mode(uint16_t action,uint8_t * enable,wifi_bridge_cfg_t * bridgecfg)342 static int wifi_bridge_mode(uint16_t action, uint8_t *enable, wifi_bridge_cfg_t *bridgecfg)
343 {
344     mlan_bridge_mode bridge_mode;
345     bridge_mode.enable = *enable;
346 
347     t_u8 *tlv                                       = NULL;
348     MrvlIEtypes_BridgeParamSet_t *bridge_params     = NULL;
349     MrvlIEtypes_AutoLinkParamSet_t *autolink_params = NULL;
350     MrvlIEtypes_SsIdParamSet_t *ssid                = NULL;
351     MrvlIEtypes_Passphrase_t *pass                  = NULL;
352 
353     wifi_get_command_lock();
354     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
355 
356     cmd->command = HostCmd_CMD_BRIDGE_MODE;
357     cmd->seq_num = 0x0;
358     cmd->result  = 0x0;
359 
360     wlan_cmd_bridge_mode(cmd, action, &bridge_mode);
361 
362     if (action == HostCmd_ACT_GEN_GET)
363         goto done;
364 
365     if (bridgecfg == NULL)
366         goto done;
367 
368     tlv = (t_u8 *)cmd + sizeof(HostCmd_BRIDGE_MODE) + S_DS_GEN;
369 
370     bridge_params = (MrvlIEtypes_BridgeParamSet_t *)tlv;
371 
372     bridge_params->header.type = wlan_cpu_to_le16(TLV_TYPE_BRIDGE_PARAM);
373     bridge_params->header.len  = 4 * sizeof(MrvlIEtypesHeader_t) + bridgecfg->ex_ap_ssid_len +
374                                 bridgecfg->ex_ap_pass_len + bridgecfg->bridge_ssid_len + bridgecfg->bridge_pass_len;
375     tlv = (t_u8 *)bridge_params;
376 
377     ssid              = (MrvlIEtypes_SsIdParamSet_t *)(tlv + sizeof(MrvlIEtypesHeader_t));
378     ssid->header.type = wlan_cpu_to_le16(TLV_TYPE_SSID);
379     ssid->header.len  = bridgecfg->ex_ap_ssid_len;
380     (void)memcpy((void *)ssid->ssid, (const void *)bridgecfg->ex_ap_ssid, bridgecfg->ex_ap_ssid_len);
381     tlv = (t_u8 *)ssid;
382 
383     pass              = (MrvlIEtypes_Passphrase_t *)(tlv + sizeof(MrvlIEtypesHeader_t) + ssid->header.len);
384     pass->header.type = wlan_cpu_to_le16(TLV_TYPE_PASSPHRASE);
385     pass->header.len  = bridgecfg->ex_ap_pass_len;
386     (void)memcpy((void *)pass->passphrase, (const void *)bridgecfg->ex_ap_pass, bridgecfg->ex_ap_pass_len);
387 
388     tlv = (t_u8 *)pass;
389 
390     ssid              = (MrvlIEtypes_SsIdParamSet_t *)(tlv + sizeof(MrvlIEtypesHeader_t) + pass->header.len);
391     ssid->header.type = wlan_cpu_to_le16(TLV_TYPE_SSID);
392     ssid->header.len  = bridgecfg->bridge_ssid_len;
393     (void)memcpy((void *)ssid->ssid, (const void *)bridgecfg->bridge_ssid, bridgecfg->bridge_ssid_len);
394 
395     tlv = (t_u8 *)ssid;
396 
397     pass              = (MrvlIEtypes_Passphrase_t *)(tlv + sizeof(MrvlIEtypesHeader_t) + ssid->header.len);
398     pass->header.type = wlan_cpu_to_le16(TLV_TYPE_PASSPHRASE);
399     pass->header.len  = bridgecfg->bridge_pass_len;
400     (void)memcpy((void *)pass->passphrase, (const void *)bridgecfg->bridge_pass, bridgecfg->bridge_pass_len);
401 
402     cmd->size += bridge_params->header.len + sizeof(MrvlIEtypesHeader_t);
403 
404     /*prepare autolink info*/
405     tlv             = (t_u8 *)pass;
406     autolink_params = (MrvlIEtypes_AutoLinkParamSet_t *)(tlv + sizeof(MrvlIEtypesHeader_t) + pass->header.len);
407     autolink_params->header.type          = wlan_cpu_to_le16(TLV_TYPE_AUTOLINK_PARAM);
408     autolink_params->header.len           = sizeof(MrvlIEtypes_AutoLinkParamSet_t) - sizeof(MrvlIEtypesHeader_t);
409     autolink_params->scan_timer_interval  = wlan_cpu_to_le32(bridgecfg->autolink.scan_timer_interval);
410     autolink_params->scan_timer_condition = bridgecfg->autolink.scan_timer_condition;
411     autolink_params->scan_channel_list    = bridgecfg->autolink.scan_channel_list;
412     cmd->size += autolink_params->header.len + sizeof(MrvlIEtypesHeader_t);
413 
414 done:
415 
416     wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? bridgecfg : NULL);
417 
418     return wm_wifi.cmd_resp_status;
419 }
420 
wifi_enable_bridge_mode(wifi_bridge_cfg_t * cfg)421 int wifi_enable_bridge_mode(wifi_bridge_cfg_t *cfg)
422 {
423     uint8_t enable = 0x01;
424 
425     if (cfg->auto_link)
426     {
427         enable |= 1 << ENABLE_AUTOLINK_BIT;
428     }
429     if (cfg->hidden_ssid)
430     {
431         enable |= 1 << HIDDEN_SSID_BIT;
432     }
433 
434     return wifi_bridge_mode(HostCmd_ACT_GEN_SET, &enable, cfg);
435 }
436 
wifi_disable_bridge_mode()437 int wifi_disable_bridge_mode()
438 {
439     uint8_t disable = 0x00;
440     return wifi_bridge_mode(HostCmd_ACT_GEN_SET, &disable, NULL);
441 }
442 
wifi_get_bridge_mode_config(wifi_bridge_cfg_t * cfg)443 int wifi_get_bridge_mode_config(wifi_bridge_cfg_t *cfg)
444 {
445     uint8_t config = 0x00;
446     return wifi_bridge_mode(HostCmd_ACT_GEN_GET, &config, cfg);
447 }
448 
wifi_config_bridge_tx_buf(uint16_t buf_size)449 int wifi_config_bridge_tx_buf(uint16_t buf_size)
450 {
451     wifi_get_command_lock();
452     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
453 
454     cmd->command = HostCmd_CMD_RECONFIGURE_TX_BUFF;
455     cmd->seq_num = 0x0;
456     cmd->result  = 0x0;
457 
458     wlan_cmd_recfg_tx_buf((mlan_private *)mlan_adap->priv[0], cmd, HostCmd_ACT_GEN_SET, &buf_size);
459 
460     wifi_wait_for_cmdresp(NULL);
461     return wm_wifi.cmd_resp_status;
462 }
463 #endif
464 
wifi_send_rssi_info_cmd(wifi_rssi_info_t * rssi_info)465 int wifi_send_rssi_info_cmd(wifi_rssi_info_t *rssi_info)
466 {
467     (void)wifi_get_command_lock();
468     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
469 
470     cmd->seq_num = 0x0;
471     cmd->result  = 0x0;
472 
473     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_RSSI_INFO,
474                                               HostCmd_ACT_GEN_GET, 0, NULL, NULL, cmd);
475     if (rv != MLAN_STATUS_SUCCESS)
476     {
477         return -WM_FAIL;
478     }
479 
480     (void)wifi_wait_for_cmdresp(rssi_info);
481     return wm_wifi.cmd_resp_status;
482 }
483 
wifi_send_rf_channel_cmd(wifi_rf_channel_t * rf_channel)484 int wifi_send_rf_channel_cmd(wifi_rf_channel_t *rf_channel)
485 {
486     (void)wifi_get_command_lock();
487     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
488 
489     cmd->seq_num = 0x0;
490     cmd->result  = 0x0;
491 
492     /*
493       SET operation is not supported according to spec. So we are
494       sending NULL as one param below.
495     */
496     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_RF_CHANNEL,
497                                               HostCmd_ACT_GEN_GET, 0, NULL, NULL, cmd);
498     if (rv != MLAN_STATUS_SUCCESS)
499     {
500         return -WM_FAIL;
501     }
502 
503     (void)wifi_wait_for_cmdresp(rf_channel);
504     return wm_wifi.cmd_resp_status;
505 }
506 
wifi_send_remain_on_channel_cmd(unsigned int bss_type,wifi_remain_on_channel_t * remain_on_channel)507 int wifi_send_remain_on_channel_cmd(unsigned int bss_type, wifi_remain_on_channel_t *remain_on_channel)
508 {
509     (void)wifi_get_command_lock();
510     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
511 
512     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, bss_type);
513     cmd->result  = 0x0;
514     /*save remain on channel bss index*/
515     mlan_adap->remain_bss_index = mlan_adap->priv[bss_type]->bss_index;
516     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[bss_type], HostCmd_CMD_802_11_REMAIN_ON_CHANNEL,
517                                               HostCmd_ACT_GEN_SET, 0, NULL, remain_on_channel, cmd);
518     if (rv != MLAN_STATUS_SUCCESS)
519     {
520         return -WM_FAIL;
521     }
522 
523     (void)wifi_wait_for_cmdresp(NULL);
524     return wm_wifi.cmd_resp_status;
525 }
526 
527 /* power_level is not used when cmd_action is GET */
wifi_get_set_rf_tx_power(t_u16 cmd_action,wifi_tx_power_t * tx_power)528 int wifi_get_set_rf_tx_power(t_u16 cmd_action, wifi_tx_power_t *tx_power)
529 {
530     (void)wifi_get_command_lock();
531     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
532 
533     cmd->seq_num   = 0x0;
534     cmd->result    = 0x0;
535     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_RF_TX_POWER,
536                                               cmd_action, 0, NULL, &tx_power->current_level, cmd);
537     if (rv != MLAN_STATUS_SUCCESS)
538     {
539         return -WM_FAIL;
540     }
541 
542     (void)wifi_wait_for_cmdresp(cmd_action == HostCmd_ACT_GEN_GET ? tx_power : NULL);
543     return wm_wifi.cmd_resp_status;
544 }
545 
wifi_get_data_rate(wifi_ds_rate * ds_rate,mlan_bss_type bss_type)546 int wifi_get_data_rate(wifi_ds_rate *ds_rate, mlan_bss_type bss_type)
547 {
548     (void)wifi_get_command_lock();
549     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
550 
551     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
552     cmd->result  = 0x0;
553 
554     mlan_status rv = MLAN_STATUS_SUCCESS;
555     if (bss_type == MLAN_BSS_TYPE_UAP)
556     {
557         if (is_uap_started())
558             rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[1], HostCmd_CMD_802_11_TX_RATE_QUERY, 0, 0,
559                                           NULL, NULL, cmd);
560         else
561             wifi_e("uap isn't up\n\r");
562     }
563     else if (bss_type == MLAN_BSS_TYPE_STA)
564     {
565         if (is_sta_connected())
566             rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_TX_RATE_QUERY, 0, 0,
567                                           NULL, NULL, cmd);
568         else
569             wifi_e("sta connection required before setting tx rate\n\r");
570     }
571 
572     if (rv != MLAN_STATUS_SUCCESS)
573     {
574         wifi_put_command_lock();
575         return -WM_FAIL;
576     }
577 
578     (void)wifi_wait_for_cmdresp(ds_rate);
579     return wm_wifi.cmd_resp_status;
580 }
581 
wifi_set_pmfcfg(t_u8 mfpc,t_u8 mfpr)582 int wifi_set_pmfcfg(t_u8 mfpc, t_u8 mfpr)
583 {
584     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
585 
586     pmpriv->pmfcfg.mfpc = mfpc;
587     pmpriv->pmfcfg.mfpr = mfpr;
588 
589     return WM_SUCCESS;
590 }
591 
wifi_get_pmfcfg(t_u8 * mfpc,t_u8 * mfpr)592 int wifi_get_pmfcfg(t_u8 *mfpc, t_u8 *mfpr)
593 {
594     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
595 
596     *mfpc = pmpriv->pmfcfg.mfpc;
597     *mfpr = pmpriv->pmfcfg.mfpr;
598 
599     return WM_SUCCESS;
600 }
601 
wifi_uap_get_pmfcfg(t_u8 * mfpc,t_u8 * mfpr)602 int wifi_uap_get_pmfcfg(t_u8 *mfpc, t_u8 *mfpr)
603 {
604     return wifi_uap_pmf_getset(HostCmd_ACT_GEN_GET, mfpc, mfpr);
605 }
606 
wifi_set_packet_filters(wifi_flt_cfg_t * flt_cfg)607 int wifi_set_packet_filters(wifi_flt_cfg_t *flt_cfg)
608 {
609     (void)wifi_get_command_lock();
610     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
611     HostCmd_DS_MEF_CFG *mef_hdr;
612     mef_entry_header *entry_hdr;
613     t_u8 *buf = (t_u8 *)cmd, *filter_buf = NULL;
614     t_u32 buf_len;
615     int i, j;
616     mef_op op;
617     t_u32 dnum;
618 
619     (void)memset(cmd, 0, sizeof(HostCmd_DS_COMMAND));
620 
621     cmd->seq_num = 0x0;
622     cmd->result  = 0x0;
623 
624     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_MEF_CFG);
625     buf_len      = S_DS_GEN;
626 
627     /** Fill HostCmd_DS_MEF_CFG */
628     mef_hdr           = (HostCmd_DS_MEF_CFG *)(void *)(buf + buf_len);
629     mef_hdr->criteria = wlan_cpu_to_le32(flt_cfg->criteria);
630     mef_hdr->nentries = wlan_cpu_to_le16(flt_cfg->nentries);
631     buf_len += sizeof(HostCmd_DS_MEF_CFG);
632 
633     for (i = 0; i < flt_cfg->nentries; i++)
634     {
635         /** Fill entry header data */
636         entry_hdr         = (mef_entry_header *)(buf + buf_len);
637         entry_hdr->mode   = flt_cfg->mef_entry[i].mode;
638         entry_hdr->action = flt_cfg->mef_entry[i].action;
639         buf_len += sizeof(mef_entry_header);
640         for (j = 0; j < flt_cfg->mef_entry[i].filter_num; j++)
641         {
642             if (flt_cfg->mef_entry[i].filter_item[j].type == TYPE_DNUM_EQ)
643             {
644                 /* Format of decimal num:
645                  * |   5 bytes  |    5 bytes    |    5 bytes    |        1 byte         |
646                  * |   pattern  |     offset    |  num of bytes |  type (TYPE_DNUM_EQ)  |
647                  */
648                 filter_buf = (t_u8 *)(buf + buf_len);
649 
650                 /* push pattern */
651                 op.operand_type = OPERAND_DNUM;
652                 dnum            = flt_cfg->mef_entry[i].filter_item[j].pattern;
653                 (void)memcpy(filter_buf, &dnum, sizeof(dnum));
654                 (void)memcpy(filter_buf + sizeof(dnum), &(op.operand_type), 1);
655                 buf_len += sizeof(dnum) + 1;
656                 filter_buf = (t_u8 *)(buf + buf_len);
657 
658                 /* push offset */
659                 op.operand_type = OPERAND_DNUM;
660                 dnum            = flt_cfg->mef_entry[i].filter_item[j].offset;
661                 (void)memcpy(filter_buf, &dnum, sizeof(dnum));
662                 (void)memcpy(filter_buf + sizeof(dnum), &(op.operand_type), 1);
663                 buf_len += sizeof(dnum) + 1;
664                 filter_buf = (t_u8 *)(buf + buf_len);
665 
666                 /* push num of bytes */
667                 op.operand_type = OPERAND_DNUM;
668                 dnum            = flt_cfg->mef_entry[i].filter_item[j].num_bytes;
669                 (void)memcpy(filter_buf, &dnum, sizeof(dnum));
670                 (void)memcpy(filter_buf + sizeof(dnum), &(op.operand_type), 1);
671                 buf_len += sizeof(dnum) + 1;
672                 filter_buf = (t_u8 *)(buf + buf_len);
673 
674                 /* push type */
675                 op.operand_type = TYPE_DNUM_EQ;
676                 (void)memcpy(filter_buf, &(op.operand_type), 1);
677                 buf_len += 1;
678                 filter_buf = (t_u8 *)(buf + buf_len);
679             }
680             else if (flt_cfg->mef_entry[i].filter_item[j].type == TYPE_BYTE_EQ)
681             {
682                 /* Format of byte seq:
683                  * |   5 bytes  |      val      |    5 bytes    |        1 byte         |
684                  * |   repeat   |   bytes seq   |    offset     |  type (TYPE_BYTE_EQ)  |
685                  */
686                 filter_buf = (t_u8 *)(buf + buf_len);
687 
688                 /* push repeat */
689                 op.operand_type = OPERAND_DNUM;
690                 dnum            = flt_cfg->mef_entry[i].filter_item[j].repeat;
691                 (void)memcpy(filter_buf, &dnum, sizeof(dnum));
692                 (void)memcpy(filter_buf + sizeof(dnum), &(op.operand_type), 1);
693                 buf_len += sizeof(dnum) + 1;
694                 filter_buf = (t_u8 *)(buf + buf_len);
695 
696                 /* push bytes seq */
697                 op.operand_type = OPERAND_BYTE_SEQ;
698                 (void)memcpy(filter_buf, flt_cfg->mef_entry[i].filter_item[j].byte_seq,
699                              flt_cfg->mef_entry[i].filter_item[j].num_byte_seq);
700                 (void)memcpy(filter_buf + flt_cfg->mef_entry[i].filter_item[j].num_byte_seq,
701                              &(flt_cfg->mef_entry[i].filter_item[j].num_byte_seq), 1);
702                 (void)memcpy(filter_buf + flt_cfg->mef_entry[i].filter_item[j].num_byte_seq + 1, &(op.operand_type), 1);
703                 buf_len += flt_cfg->mef_entry[i].filter_item[j].num_byte_seq + 2;
704                 filter_buf = (t_u8 *)(buf + buf_len);
705 
706                 /* push offset */
707                 op.operand_type = OPERAND_DNUM;
708                 dnum            = flt_cfg->mef_entry[i].filter_item[j].offset;
709                 (void)memcpy(filter_buf, &dnum, sizeof(dnum));
710                 (void)memcpy(filter_buf + sizeof(dnum), &(op.operand_type), 1);
711                 buf_len += sizeof(dnum) + 1;
712                 filter_buf = (t_u8 *)(buf + buf_len);
713 
714                 /* push type */
715                 op.operand_type = TYPE_BYTE_EQ;
716                 (void)memcpy(filter_buf, &(op.operand_type), 1);
717                 buf_len += 1;
718                 filter_buf = (t_u8 *)(buf + buf_len);
719             }
720             else if (flt_cfg->mef_entry[i].filter_item[j].type == TYPE_BIT_EQ)
721             {
722                 /* Format of bit seq:
723                  * |   val      |    5 bytes    |      val      |        1 byte         |
724                  * | bytes seq  |    offset     |    mask seq   |  type (TYPE_BIT_EQ)   |
725                  */
726                 filter_buf = (t_u8 *)(buf + buf_len);
727 
728                 /* push bytes seq */
729                 op.operand_type = OPERAND_BYTE_SEQ;
730                 (void)memcpy(filter_buf, flt_cfg->mef_entry[i].filter_item[j].byte_seq,
731                              flt_cfg->mef_entry[i].filter_item[j].num_byte_seq);
732                 (void)memcpy(filter_buf + flt_cfg->mef_entry[i].filter_item[j].num_byte_seq,
733                              &(flt_cfg->mef_entry[i].filter_item[j].num_byte_seq), 1);
734                 (void)memcpy(filter_buf + flt_cfg->mef_entry[i].filter_item[j].num_byte_seq + 1, &(op.operand_type), 1);
735                 buf_len += flt_cfg->mef_entry[i].filter_item[j].num_byte_seq + 2;
736                 filter_buf = (t_u8 *)(buf + buf_len);
737 
738                 /* push offset */
739                 op.operand_type = OPERAND_DNUM;
740                 dnum            = flt_cfg->mef_entry[i].filter_item[j].offset;
741                 (void)memcpy(filter_buf, &dnum, sizeof(dnum));
742                 (void)memcpy(filter_buf + sizeof(dnum), &(op.operand_type), 1);
743                 buf_len += sizeof(dnum) + 1;
744                 filter_buf = (t_u8 *)(buf + buf_len);
745 
746                 /* push mask seq */
747                 op.operand_type = OPERAND_BYTE_SEQ;
748                 (void)memcpy(filter_buf, flt_cfg->mef_entry[i].filter_item[j].mask_seq,
749                              flt_cfg->mef_entry[i].filter_item[j].num_mask_seq);
750                 (void)memcpy(filter_buf + flt_cfg->mef_entry[i].filter_item[j].num_mask_seq,
751                              &(flt_cfg->mef_entry[i].filter_item[j].num_mask_seq), 1);
752                 (void)memcpy(filter_buf + flt_cfg->mef_entry[i].filter_item[j].num_mask_seq + 1, &(op.operand_type), 1);
753                 buf_len += flt_cfg->mef_entry[i].filter_item[j].num_mask_seq + 2;
754                 filter_buf = (t_u8 *)(buf + buf_len);
755 
756                 /* push type */
757                 op.operand_type = TYPE_BIT_EQ;
758                 (void)memcpy(filter_buf, &(op.operand_type), 1);
759                 buf_len += 1;
760                 filter_buf = (t_u8 *)(buf + buf_len);
761             }
762             else
763                 goto done;
764             if (j != 0)
765             {
766                 filter_buf      = (t_u8 *)(buf + buf_len);
767                 op.operand_type = flt_cfg->mef_entry[i].rpn[j];
768                 (void)memcpy(filter_buf, &(op.operand_type), 1);
769                 buf_len += 1;
770                 filter_buf = (t_u8 *)(buf + buf_len);
771             }
772         }
773         if (filter_buf != NULL)
774             entry_hdr->len = (t_u32)filter_buf - (t_u32)entry_hdr - sizeof(mef_entry_header);
775     }
776 
777     cmd->size = wlan_cpu_to_le16(buf_len);
778 done:
779     (void)wifi_wait_for_cmdresp(NULL);
780 
781     return wm_wifi.cmd_resp_status;
782 }
783 
784 #define FLTR_BUF_IP_OFFSET 24
785 
wifi_set_auto_arp(t_u32 * ipv4_addr)786 int wifi_set_auto_arp(t_u32 *ipv4_addr)
787 {
788     wifi_get_command_lock();
789     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
790     HostCmd_DS_MEF_CFG *mef_hdr;
791     t_u8 *buf = (t_u8 *)cmd, *filter = NULL;
792     t_u32 buf_len;
793     t_u8 fltr_buf[] = {0x01, 0x10, 0x21, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x02, 0x02,
794                        0x14, 0x00, 0x00, 0x00, 0x01, 0x41, 0x01, 0x00, 0x00, 0x00, 0x01, 0xc0, 0xa8,
795                        0x01, 0x6d, 0x04, 0x02, 0x2e, 0x00, 0x00, 0x00, 0x01, 0x41, 0x44};
796 
797     (void)memset(cmd, 0, sizeof(HostCmd_DS_COMMAND));
798 
799     cmd->seq_num = 0x0;
800     cmd->result  = 0x0;
801 
802     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_MEF_CFG);
803     buf_len      = S_DS_GEN;
804 
805     /** Fill HostCmd_DS_MEF_CFG*/
806     mef_hdr           = (HostCmd_DS_MEF_CFG *)(buf + buf_len);
807     mef_hdr->criteria = wlan_cpu_to_le32(MBIT(0) | MBIT(1) | MBIT(3));
808     mef_hdr->nentries = wlan_cpu_to_le16(1);
809     buf_len += sizeof(HostCmd_DS_MEF_CFG);
810 
811     filter = buf + buf_len;
812     (void)memcpy((void *)filter, (const void *)fltr_buf, sizeof(fltr_buf));
813     (void)memcpy((void *)&filter[FLTR_BUF_IP_OFFSET], (const void *)ipv4_addr, sizeof(t_u32));
814     buf_len += sizeof(fltr_buf);
815 
816     cmd->size = wlan_cpu_to_le16(buf_len);
817     wifi_wait_for_cmdresp(NULL);
818 
819     return wm_wifi.cmd_resp_status;
820 }
821 
wifi_tcp_keep_alive(wifi_tcp_keep_alive_t * keep_alive,t_u8 * src_mac,t_u32 src_ip)822 int wifi_tcp_keep_alive(wifi_tcp_keep_alive_t *keep_alive, t_u8 *src_mac, t_u32 src_ip)
823 {
824     wifi_get_command_lock();
825     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
826     t_u16 cmd_action        = HostCmd_ACT_GEN_SET;
827 
828     HostCmd_DS_AUTO_TX *auto_tx_cmd = (HostCmd_DS_AUTO_TX *)((t_u8 *)cmd + S_DS_GEN);
829     t_u8 *pos                       = (t_u8 *)auto_tx_cmd + sizeof(auto_tx_cmd->action);
830     t_u16 len                       = 0;
831 
832     MrvlIEtypes_Cloud_Keep_Alive_t *keep_alive_tlv = MNULL;
833     MrvlIEtypes_Keep_Alive_Ctrl_t *ctrl_tlv        = MNULL;
834     MrvlIEtypes_Keep_Alive_Pkt_t *pkt_tlv          = MNULL;
835     t_u8 eth_ip[]                                  = {0x08, 0x00};
836     t_u8 ip_packet[67] = {0x45, 0x00, 0x00, 0x43, 0x8c, 0x9e, 0x00, 0x00, 0xff, 0x06, 0xac, 0xbf, 0xc0, 0xa8,
837                           0x00, 0x7c, 0xc0, 0xa8, 0x00, 0x8a, 0xc0, 0x03, 0x22, 0xb7, 0xb0, 0xb6, 0x60, 0x9f,
838                           0x42, 0xdd, 0x9e, 0x1e, 0x50, 0x18, 0x80, 0x00, 0xd0, 0x88, 0x00, 0x00, 0x74, 0x68,
839                           0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x6b, 0x65, 0x65, 0x70, 0x20, 0x61,
840                           0x6c, 0x69, 0x76, 0x65, 0x20, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74};
841 #if 0
842 	t_u8 ip_packet2[41] = {0x45, 0x00, 0x00, 0x29, 0x76, 0x51, 0x40, 0x00, 0x80, 0x06, 0xf2, 0x4c, 0xc0, 0xa8, 0x01, 0x0a, 0xc0, 0xa8, 0x01, 0x0c, 0xfb, 0xd8, 0x01, 0xbd, 0x76, 0xe3, 0x34, 0x62, 0x06, 0x80, 0x8b, 0x62, 0x50, 0x10, 0x01, 0x00, 0xe1, 0xe4, 0x00, 0x00, 0x00};
843 #endif
844     t_u16 pkt_len = 67;
845 
846     if (keep_alive->reset)
847         cmd_action = HostCmd_ACT_GEN_RESET;
848 
849     cmd->command        = wlan_cpu_to_le16(HostCmd_CMD_AUTO_TX);
850     cmd->size           = S_DS_GEN + sizeof(HostCmd_DS_AUTO_TX);
851     auto_tx_cmd->action = wlan_cpu_to_le16(cmd_action);
852 
853     keep_alive_tlv = (MrvlIEtypes_Cloud_Keep_Alive_t *)pos;
854 
855     keep_alive_tlv->header.type   = wlan_cpu_to_le16(TLV_TYPE_CLOUD_KEEP_ALIVE);
856     keep_alive_tlv->keep_alive_id = 1; // keep_alive->mkeep_alive_id;
857     keep_alive_tlv->enable        = keep_alive->enable;
858     len                           = len + sizeof(keep_alive_tlv->keep_alive_id) + sizeof(keep_alive_tlv->enable);
859     pos                           = pos + len + sizeof(MrvlIEtypesHeader_t);
860     if (cmd_action == HostCmd_ACT_GEN_SET)
861     {
862         if (keep_alive->enable)
863         {
864             ctrl_tlv              = (MrvlIEtypes_Keep_Alive_Ctrl_t *)pos;
865             ctrl_tlv->header.type = wlan_cpu_to_le16(TLV_TYPE_KEEP_ALIVE_CTRL);
866             ctrl_tlv->header.len =
867                 wlan_cpu_to_le16(sizeof(MrvlIEtypes_Keep_Alive_Ctrl_t) - sizeof(MrvlIEtypesHeader_t));
868             ctrl_tlv->snd_interval   = wlan_cpu_to_le32(keep_alive->timeout);
869             ctrl_tlv->retry_interval = wlan_cpu_to_le16(keep_alive->interval);
870             ctrl_tlv->retry_count    = wlan_cpu_to_le16(keep_alive->max_keep_alives);
871             len                      = len + sizeof(MrvlIEtypes_Keep_Alive_Ctrl_t);
872 
873             pos                  = pos + sizeof(MrvlIEtypes_Keep_Alive_Ctrl_t);
874             pkt_tlv              = (MrvlIEtypes_Keep_Alive_Pkt_t *)pos;
875             pkt_tlv->header.type = wlan_cpu_to_le16(TLV_TYPE_KEEP_ALIVE_PKT);
876             (void)memcpy((void *)pkt_tlv->eth_header.dest_addr, (const void *)keep_alive->dst_mac,
877                          MLAN_MAC_ADDR_LENGTH);
878             (void)memcpy((void *)pkt_tlv->eth_header.src_addr, (const void *)src_mac, MLAN_MAC_ADDR_LENGTH);
879             (void)memcpy((void *)((t_u8 *)&pkt_tlv->eth_header.h803_len), (const void *)eth_ip, sizeof(t_u16));
880             (void)memcpy((void *)(ip_packet + 12), (const void *)&src_ip, sizeof(t_u32));
881             (void)memcpy((void *)(ip_packet + 16), (const void *)&keep_alive->dst_ip, sizeof(t_u32));
882             (void)memcpy((void *)pkt_tlv->ip_packet, (const void *)ip_packet, pkt_len);
883             pkt_tlv->header.len = wlan_cpu_to_le16(sizeof(Eth803Hdr_t) + pkt_len);
884             len                 = len + sizeof(MrvlIEtypesHeader_t) + sizeof(Eth803Hdr_t) + pkt_len;
885         }
886         else
887         {
888             pkt_tlv              = (MrvlIEtypes_Keep_Alive_Pkt_t *)pos;
889             pkt_tlv->header.type = wlan_cpu_to_le16(TLV_TYPE_KEEP_ALIVE_PKT);
890             pkt_tlv->header.len  = 0;
891             len                  = len + sizeof(MrvlIEtypesHeader_t);
892         }
893     }
894     if (cmd_action == HostCmd_ACT_GEN_RESET)
895     {
896         pkt_tlv              = (MrvlIEtypes_Keep_Alive_Pkt_t *)pos;
897         pkt_tlv->header.type = wlan_cpu_to_le16(TLV_TYPE_KEEP_ALIVE_PKT);
898         pkt_tlv->header.len  = 0;
899         len                  = len + sizeof(MrvlIEtypesHeader_t);
900     }
901     keep_alive_tlv->header.len = wlan_cpu_to_le16(len);
902 
903     cmd->size = cmd->size + len + sizeof(MrvlIEtypesHeader_t);
904     cmd->size = wlan_cpu_to_le16(cmd->size);
905 
906     cmd->seq_num = 0x00;
907     cmd->result  = 0x00;
908 
909     wifi_wait_for_cmdresp(NULL);
910 
911     return wm_wifi.cmd_resp_status;
912 }
913 
914 #if CONFIG_CLOUD_KEEP_ALIVE
wifi_cloud_keep_alive(wifi_cloud_keep_alive_t * keep_alive,t_u16 action,t_u8 * enable)915 int wifi_cloud_keep_alive(wifi_cloud_keep_alive_t *keep_alive, t_u16 action, t_u8 *enable)
916 {
917     wifi_get_command_lock();
918     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
919     t_u16 cmd_action;
920     HostCmd_DS_AUTO_TX *auto_tx_cmd                = (HostCmd_DS_AUTO_TX *)((t_u8 *)cmd + S_DS_GEN);
921     t_u8 *pos                                      = (t_u8 *)auto_tx_cmd + sizeof(auto_tx_cmd->action);
922     t_u16 len                                      = 0;
923     MrvlIEtypes_Cloud_Keep_Alive_t *keep_alive_tlv = MNULL;
924 
925     if (keep_alive == NULL)
926         return -WM_E_INVAL;
927 
928     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
929     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_STA);
930     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_AUTO_TX);
931     cmd->size    = S_DS_GEN + sizeof(HostCmd_DS_AUTO_TX);
932 
933     if ((action == MLAN_ACT_GET) && (enable != NULL))
934     {
935         cmd_action = HostCmd_ACT_GEN_GET;
936     }
937     else if ((action == MLAN_ACT_SET) && !keep_alive->reset)
938     {
939         cmd_action = HostCmd_ACT_GEN_SET;
940     }
941     else if ((action == MLAN_ACT_SET) && keep_alive->reset)
942     {
943         cmd_action = HostCmd_ACT_GEN_RESET;
944     }
945     else
946     {
947         return -WM_E_INVAL;
948     }
949     auto_tx_cmd->action = wlan_cpu_to_le16(cmd_action);
950 
951     keep_alive_tlv = (MrvlIEtypes_Cloud_Keep_Alive_t *)pos;
952 
953     keep_alive_tlv->header.type   = wlan_cpu_to_le16(TLV_TYPE_CLOUD_KEEP_ALIVE);
954     keep_alive_tlv->keep_alive_id = keep_alive->mkeep_alive_id;
955     if (cmd_action == HostCmd_ACT_GEN_GET)
956     {
957         keep_alive_tlv->enable     = MFALSE;
958         len                        = len + sizeof(keep_alive_tlv->keep_alive_id) + sizeof(keep_alive_tlv->enable);
959         keep_alive_tlv->header.len = wlan_cpu_to_le16(len);
960 
961         cmd->size = cmd->size + len + sizeof(MrvlIEtypesHeader_t);
962         cmd->size = wlan_cpu_to_le16(cmd->size);
963     }
964     else if (cmd_action == HostCmd_ACT_GEN_SET)
965     {
966         if (keep_alive->enable)
967         {
968             MrvlIEtypes_Keep_Alive_Ctrl_t *ctrl_tlv = MNULL;
969             MrvlIEtypes_Keep_Alive_Pkt_t *pkt_tlv   = MNULL;
970             t_u8 eth_ip[]                           = {0x08, 0x00};
971 
972             keep_alive_tlv->enable = keep_alive->enable;
973             len                    = len + sizeof(keep_alive_tlv->keep_alive_id) + sizeof(keep_alive_tlv->enable);
974             pos                    = pos + len + sizeof(MrvlIEtypesHeader_t);
975             ctrl_tlv               = (MrvlIEtypes_Keep_Alive_Ctrl_t *)pos;
976             ctrl_tlv->header.type  = wlan_cpu_to_le16(TLV_TYPE_KEEP_ALIVE_CTRL);
977             ctrl_tlv->header.len =
978                 wlan_cpu_to_le16(sizeof(MrvlIEtypes_Keep_Alive_Ctrl_t) - sizeof(MrvlIEtypesHeader_t));
979             ctrl_tlv->snd_interval   = wlan_cpu_to_le32(keep_alive->send_interval);
980             ctrl_tlv->retry_interval = wlan_cpu_to_le16(keep_alive->retry_interval);
981             ctrl_tlv->retry_count    = wlan_cpu_to_le16(keep_alive->retry_count);
982             len                      = len + sizeof(MrvlIEtypes_Keep_Alive_Ctrl_t);
983 
984             pos                  = pos + sizeof(MrvlIEtypes_Keep_Alive_Ctrl_t);
985             pkt_tlv              = (MrvlIEtypes_Keep_Alive_Pkt_t *)pos;
986             pkt_tlv->header.type = wlan_cpu_to_le16(TLV_TYPE_KEEP_ALIVE_PKT);
987             (void)memcpy(pkt_tlv->eth_header.dest_addr, keep_alive->dst_mac, MLAN_MAC_ADDR_LENGTH);
988             (void)memcpy(pkt_tlv->eth_header.src_addr, keep_alive->src_mac, MLAN_MAC_ADDR_LENGTH);
989             (void)memcpy((t_u8 *)&pkt_tlv->eth_header.h803_len, eth_ip, sizeof(t_u16));
990             (void)memcpy(pkt_tlv->ip_packet, keep_alive->packet, keep_alive->pkt_len);
991             pkt_tlv->header.len        = wlan_cpu_to_le16(sizeof(Eth803Hdr_t) + keep_alive->pkt_len);
992             len                        = len + sizeof(MrvlIEtypesHeader_t) + sizeof(Eth803Hdr_t) + keep_alive->pkt_len;
993             keep_alive_tlv->header.len = wlan_cpu_to_le16(len);
994 
995             cmd->size = cmd->size + len + sizeof(MrvlIEtypesHeader_t);
996             cmd->size = wlan_cpu_to_le16(cmd->size);
997         }
998         else
999         {
1000             keep_alive_tlv->enable     = MFALSE;
1001             len                        = len + sizeof(keep_alive_tlv->keep_alive_id) + sizeof(keep_alive_tlv->enable);
1002             keep_alive_tlv->header.len = wlan_cpu_to_le16(len);
1003 
1004             cmd->size = cmd->size + len + sizeof(MrvlIEtypesHeader_t);
1005             cmd->size = wlan_cpu_to_le16(cmd->size);
1006         }
1007     }
1008     else if (cmd_action == HostCmd_ACT_GEN_RESET)
1009     {
1010         keep_alive_tlv->enable     = MFALSE;
1011         len                        = len + sizeof(keep_alive_tlv->keep_alive_id) + sizeof(keep_alive_tlv->enable);
1012         keep_alive_tlv->header.len = wlan_cpu_to_le16(len);
1013 
1014         cmd->size = cmd->size + len + sizeof(MrvlIEtypesHeader_t);
1015         cmd->size = wlan_cpu_to_le16(cmd->size);
1016     }
1017 
1018     cmd->result = 0x00;
1019     if (cmd_action == HostCmd_ACT_GEN_GET)
1020     {
1021         wifi_wait_for_cmdresp((void *)enable);
1022     }
1023     else
1024     {
1025         wifi_wait_for_cmdresp(NULL);
1026     }
1027 
1028     return wm_wifi.cmd_resp_status;
1029 }
1030 #endif
1031 
1032 #if CONFIG_RF_TEST_MODE
1033 #ifdef RW610
1034 /* 802.11n/a/g/b data rate IDs */
1035 #define DATARATE_1M  0x0001
1036 #define DATARATE_2M  0x0002
1037 #define DATARATE5_5M 0x0003
1038 #define DATARATE_11M 0x0004
1039 #define RESERVED_1   0x0005
1040 
1041 #define DATARATE_6M  0x0006
1042 #define DATARATE_9M  0x0007
1043 #define DATARATE_12M 0x0008
1044 #define DATARATE_18M 0x0009
1045 #define DATARATE_24M 0x000A
1046 #define DATARATE_36M 0x000B
1047 #define DATARATE_48M 0x000C
1048 #define DATARATE_54M 0x000D
1049 #define RESERVED_2   0x000E
1050 
1051 #define HT_MCS0 0x000F
1052 #define HT_MCS1 0x0010
1053 #define HT_MCS2 0x0011
1054 #define HT_MCS3 0x0012
1055 #define HT_MCS4 0x0013
1056 #define HT_MCS5 0x0014
1057 #define HT_MCS6 0x0015
1058 #define HT_MCS7 0x0016
1059 
1060 /* 802.11ac VHT MCS rates ID */
1061 #define VHT_SS1_MCS0 0x1100
1062 #define VHT_SS1_MCS1 0x1101
1063 #define VHT_SS1_MCS2 0x1102
1064 #define VHT_SS1_MCS3 0x1103
1065 #define VHT_SS1_MCS4 0x1104
1066 #define VHT_SS1_MCS5 0x1105
1067 #define VHT_SS1_MCS6 0x1106
1068 #define VHT_SS1_MCS7 0x1107
1069 #define VHT_SS1_MCS8 0x1108
1070 
1071 /* 802.11ax HE MCS rates ID */
1072 #define HE_SS1_MCS0 0x2100
1073 #define HE_SS1_MCS1 0x2101
1074 #define HE_SS1_MCS2 0x2102
1075 #define HE_SS1_MCS3 0x2103
1076 #define HE_SS1_MCS4 0x2104
1077 #define HE_SS1_MCS5 0x2105
1078 #define HE_SS1_MCS6 0x2106
1079 #define HE_SS1_MCS7 0x2107
1080 #define HE_SS1_MCS8 0x2108
1081 #define HE_SS1_MCS9 0x2109
1082 
1083 static uint32_t tx_data_rate_ids[] = {
1084     /* 802.11n/a/g/b data rate IDs */
1085     DATARATE_1M, DATARATE_2M, DATARATE5_5M, DATARATE_11M, RESERVED_1, DATARATE_6M, DATARATE_9M, DATARATE_12M,
1086     DATARATE_18M, DATARATE_24M, DATARATE_36M, DATARATE_48M, DATARATE_54M, RESERVED_2, HT_MCS0, HT_MCS1, HT_MCS2,
1087     HT_MCS3, HT_MCS4, HT_MCS5, HT_MCS6, HT_MCS7,
1088     /* 802.11ac VHT MCS rates id */
1089     VHT_SS1_MCS0, VHT_SS1_MCS1, VHT_SS1_MCS2, VHT_SS1_MCS3, VHT_SS1_MCS4, VHT_SS1_MCS5, VHT_SS1_MCS6, VHT_SS1_MCS7,
1090     VHT_SS1_MCS8,
1091     /* 802.11ax HE MCS rates ID */
1092     HE_SS1_MCS0, HE_SS1_MCS1, HE_SS1_MCS2, HE_SS1_MCS3, HE_SS1_MCS4, HE_SS1_MCS5, HE_SS1_MCS6, HE_SS1_MCS7, HE_SS1_MCS8,
1093     HE_SS1_MCS9};
1094 #endif
1095 
1096 static uint8_t band_set       = 0;
1097 static uint8_t bandwidth_set  = 0;
1098 static uint8_t tx_antenna_set = 0;
1099 static uint8_t rx_antenna_set = 0;
1100 
wifi_get_set_rf_test_generic(t_u16 cmd_action,wifi_mfg_cmd_generic_cfg_t * wifi_mfg_cmd_generic_cfg)1101 int wifi_get_set_rf_test_generic(t_u16 cmd_action, wifi_mfg_cmd_generic_cfg_t *wifi_mfg_cmd_generic_cfg)
1102 {
1103     wifi_get_command_lock();
1104     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1105     mlan_ds_misc_cfg misc;
1106     cmd->seq_num = 0x0;
1107     cmd->result  = 0x0;
1108 
1109     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
1110     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MFG_COMMAND, cmd_action,
1111                                               0, NULL, wifi_mfg_cmd_generic_cfg, cmd);
1112     if (rv != MLAN_STATUS_SUCCESS)
1113         return -WM_FAIL;
1114 
1115     wifi_wait_for_cmdresp(&misc);
1116     memcpy(wifi_mfg_cmd_generic_cfg, (wifi_mfg_cmd_generic_cfg_t *)&misc.param.mfg_generic_cfg,
1117            sizeof(wifi_mfg_cmd_generic_cfg_t));
1118     return wm_wifi.cmd_resp_status;
1119 }
1120 
wifi_get_set_rf_test_tx_frame(t_u16 cmd_action,wifi_mfg_cmd_tx_frame_t * wifi_mfg_cmd_tx_frame,wifi_mfg_cmd_generic_cfg_t * wifi_mfg_cmd_generic_cfg)1121 int wifi_get_set_rf_test_tx_frame(t_u16 cmd_action,
1122                                   wifi_mfg_cmd_tx_frame_t *wifi_mfg_cmd_tx_frame,
1123                                   wifi_mfg_cmd_generic_cfg_t *wifi_mfg_cmd_generic_cfg)
1124 {
1125     wifi_get_command_lock();
1126     mlan_ds_misc_cfg misc;
1127     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1128 
1129     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
1130     cmd->seq_num   = 0x0;
1131     cmd->result    = 0x0;
1132     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MFG_COMMAND, cmd_action,
1133                                               0, NULL, wifi_mfg_cmd_tx_frame, cmd);
1134     if (rv != MLAN_STATUS_SUCCESS)
1135         return -WM_FAIL;
1136 
1137     wifi_wait_for_cmdresp(&misc);
1138     memcpy(wifi_mfg_cmd_generic_cfg, (wifi_mfg_cmd_generic_cfg_t *)&misc.param.mfg_generic_cfg,
1139            sizeof(wifi_mfg_cmd_generic_cfg_t));
1140     return wm_wifi.cmd_resp_status;
1141 }
1142 
wifi_get_set_rf_trigger_frame_cfg(t_u16 cmd_action,wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr_t * wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr,wifi_mfg_cmd_generic_cfg_t * wifi_mfg_cmd_generic_cfg)1143 int wifi_get_set_rf_trigger_frame_cfg(t_u16 cmd_action,
1144                                       wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr_t *wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr,
1145                                       wifi_mfg_cmd_generic_cfg_t *wifi_mfg_cmd_generic_cfg)
1146 {
1147     wifi_get_command_lock();
1148     mlan_ds_misc_cfg misc;
1149     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1150 
1151     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
1152     cmd->seq_num   = 0x0;
1153     cmd->result    = 0x0;
1154     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MFG_COMMAND, cmd_action,
1155                                               0, NULL, wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr, cmd);
1156     if (rv != MLAN_STATUS_SUCCESS)
1157         return -WM_FAIL;
1158 
1159     wifi_wait_for_cmdresp(&misc);
1160     memcpy(wifi_mfg_cmd_generic_cfg, (wifi_mfg_cmd_generic_cfg_t *)&misc.param.mfg_generic_cfg,
1161            sizeof(wifi_mfg_cmd_generic_cfg_t));
1162     return wm_wifi.cmd_resp_status;
1163 }
1164 
wifi_get_set_rf_he_tb_tx(t_u16 cmd_action,wifi_mfg_cmd_he_tb_tx_t * wifi_mfg_cmd_he_tb_tx,wifi_mfg_cmd_generic_cfg_t * wifi_mfg_cmd_generic_cfg)1165 int wifi_get_set_rf_he_tb_tx(t_u16 cmd_action,
1166                              wifi_mfg_cmd_he_tb_tx_t *wifi_mfg_cmd_he_tb_tx,
1167                              wifi_mfg_cmd_generic_cfg_t *wifi_mfg_cmd_generic_cfg)
1168 {
1169     wifi_get_command_lock();
1170     mlan_ds_misc_cfg misc;
1171     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1172 
1173     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
1174     cmd->seq_num   = 0x0;
1175     cmd->result    = 0x0;
1176     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MFG_COMMAND, cmd_action,
1177                                               0, NULL, wifi_mfg_cmd_he_tb_tx, cmd);
1178     if (rv != MLAN_STATUS_SUCCESS)
1179         return -WM_FAIL;
1180 
1181     wifi_wait_for_cmdresp(&misc);
1182     memcpy(wifi_mfg_cmd_generic_cfg, (wifi_mfg_cmd_generic_cfg_t *)&misc.param.mfg_generic_cfg,
1183            sizeof(wifi_mfg_cmd_generic_cfg_t));
1184     return wm_wifi.cmd_resp_status;
1185 }
1186 
wifi_get_set_rf_otp_mac_addr(t_u16 cmd_action,wifi_mfg_cmd_otp_mac_addr_rd_wr_t * wifi_mfg_cmd_otp_mac_addr_rd_wr)1187 int wifi_get_set_rf_otp_mac_addr(t_u16 cmd_action, wifi_mfg_cmd_otp_mac_addr_rd_wr_t *wifi_mfg_cmd_otp_mac_addr_rd_wr)
1188 {
1189     wifi_get_command_lock();
1190     mlan_ds_misc_cfg misc;
1191     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1192 
1193     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
1194     cmd->seq_num   = 0x0;
1195     cmd->result    = 0x0;
1196     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MFG_COMMAND, cmd_action,
1197                                               0, NULL, wifi_mfg_cmd_otp_mac_addr_rd_wr, cmd);
1198     if (rv != MLAN_STATUS_SUCCESS)
1199         return -WM_FAIL;
1200 
1201     wifi_wait_for_cmdresp(&misc);
1202     memcpy(wifi_mfg_cmd_otp_mac_addr_rd_wr, (wifi_mfg_cmd_otp_mac_addr_rd_wr_t *)&misc.param.mfg_otp_mac_addr_rd_wr,
1203            sizeof(wifi_mfg_cmd_otp_mac_addr_rd_wr_t));
1204     return wm_wifi.cmd_resp_status;
1205 }
1206 
wifi_get_set_rf_otp_cal_data(t_u16 cmd_action,wifi_mfg_cmd_otp_cal_data_rd_wr_t * wifi_mfg_cmd_otp_cal_data_rd_wr)1207 int wifi_get_set_rf_otp_cal_data(t_u16 cmd_action, wifi_mfg_cmd_otp_cal_data_rd_wr_t *wifi_mfg_cmd_otp_cal_data_rd_wr)
1208 {
1209     wifi_get_command_lock();
1210     mlan_ds_misc_cfg *misc  = NULL;
1211     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1212 
1213     misc = (mlan_ds_misc_cfg *)OSA_MemoryAllocate(sizeof(mlan_ds_misc_cfg));
1214     (void)memset(misc, 0x00, sizeof(mlan_ds_misc_cfg));
1215     cmd->seq_num   = 0x0;
1216     cmd->result    = 0x0;
1217     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MFG_COMMAND, cmd_action,
1218                                               0, NULL, wifi_mfg_cmd_otp_cal_data_rd_wr, cmd);
1219     if (rv != MLAN_STATUS_SUCCESS)
1220     {
1221         (void)OSA_MemoryFree(misc);
1222         return -WM_FAIL;
1223     }
1224 
1225     wifi_wait_for_cmdresp(misc);
1226     memcpy(wifi_mfg_cmd_otp_cal_data_rd_wr, (wifi_mfg_cmd_otp_cal_data_rd_wr_t *)&(misc->param.mfg_otp_cal_data_rd_wr),
1227            sizeof(wifi_mfg_cmd_otp_cal_data_rd_wr_t));
1228     (void)OSA_MemoryFree(misc);
1229     return wm_wifi.cmd_resp_status;
1230 }
1231 
wifi_get_set_rf_test_tx_cont(t_u16 cmd_action,wifi_mfg_cmd_tx_cont_t * wifi_mfg_cmd_tx_cont,wifi_mfg_cmd_generic_cfg_t * wifi_mfg_cmd_generic_cfg)1232 int wifi_get_set_rf_test_tx_cont(t_u16 cmd_action,
1233                                  wifi_mfg_cmd_tx_cont_t *wifi_mfg_cmd_tx_cont,
1234                                  wifi_mfg_cmd_generic_cfg_t *wifi_mfg_cmd_generic_cfg)
1235 {
1236     wifi_get_command_lock();
1237     mlan_ds_misc_cfg misc;
1238     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
1239 
1240     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
1241     cmd->seq_num   = 0x0;
1242     cmd->result    = 0x0;
1243     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MFG_COMMAND, cmd_action,
1244                                               0, NULL, wifi_mfg_cmd_tx_cont, cmd);
1245     if (rv != MLAN_STATUS_SUCCESS)
1246         return -WM_FAIL;
1247 
1248     wifi_wait_for_cmdresp(&misc);
1249     memcpy(wifi_mfg_cmd_generic_cfg, (wifi_mfg_cmd_generic_cfg_t *)&misc.param.mfg_generic_cfg,
1250            sizeof(wifi_mfg_cmd_generic_cfg_t));
1251     return wm_wifi.cmd_resp_status;
1252 }
1253 
wifi_set_rf_test_mode(void)1254 int wifi_set_rf_test_mode(void)
1255 {
1256     int ret;
1257     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1258 
1259     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1260 
1261     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_SET_TEST_MODE;
1262     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1263 
1264     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1265     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1266     {
1267         return WM_SUCCESS;
1268     }
1269 
1270     wifi_e("wifi set rf test mode fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1271     return -WM_FAIL;
1272 }
1273 
wifi_unset_rf_test_mode(void)1274 int wifi_unset_rf_test_mode(void)
1275 {
1276     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1277 
1278     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1279 
1280     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_UNSET_TEST_MODE;
1281     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1282 
1283     (void)wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1284 
1285     return WM_SUCCESS;
1286 }
1287 
wifi_set_rf_channel(const uint8_t channel)1288 int wifi_set_rf_channel(const uint8_t channel)
1289 {
1290     int ret;
1291 
1292     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1293 
1294     /* To align with mxdriver, skip channel valid check for rf test mode */
1295 #if 0
1296     /* Check if Channel is allowed as per WWSM */
1297     if (!wlan_is_channel_valid(channel))
1298         return -WM_FAIL;
1299 #endif
1300 
1301     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1302 
1303     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RF_CHAN;
1304     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1305 
1306     wifi_mfg_cmd_generic_cfg.data1 = channel;
1307 
1308     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1309 
1310     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1311     {
1312         return WM_SUCCESS;
1313     }
1314 
1315     wifi_e("wifi set rf channel fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1316     return -WM_FAIL;
1317 }
1318 
wifi_set_rf_radio_mode(const uint8_t mode)1319 int wifi_set_rf_radio_mode(const uint8_t mode)
1320 {
1321     int ret;
1322 
1323     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1324 
1325     /* Check if radio mode is valid */
1326     if (!wlan_is_radio_mode_valid(mode))
1327     {
1328         return -WM_FAIL;
1329     }
1330 
1331     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1332 
1333     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RADIO_MODE_CFG;
1334     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1335     wifi_mfg_cmd_generic_cfg.data1   = mode;
1336 
1337     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1338     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1339     {
1340         return WM_SUCCESS;
1341     }
1342 
1343     wifi_e("wifi set radio mode fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1344     return -WM_FAIL;
1345 }
1346 
wifi_get_rf_channel(uint8_t * channel)1347 int wifi_get_rf_channel(uint8_t *channel)
1348 {
1349     int ret;
1350 
1351     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1352 
1353     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1354 
1355     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RF_CHAN;
1356     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_GET;
1357 
1358     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_generic_cfg);
1359 
1360     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1361     {
1362         *channel = wifi_mfg_cmd_generic_cfg.data1;
1363         return WM_SUCCESS;
1364     }
1365 
1366     wifi_e("wifi get rf channel fail, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1367     return -WM_FAIL;
1368 }
1369 
wifi_get_rf_radio_mode(uint8_t * mode)1370 int wifi_get_rf_radio_mode(uint8_t *mode)
1371 {
1372     int ret;
1373 
1374     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1375 
1376     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1377 
1378     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RADIO_MODE_CFG;
1379     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_GET;
1380 
1381     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_generic_cfg);
1382 
1383     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1384     {
1385         *mode = wifi_mfg_cmd_generic_cfg.data1;
1386         return WM_SUCCESS;
1387     }
1388 
1389     wifi_e("wifi get rf radio fail, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1390     return -WM_FAIL;
1391 }
1392 
wifi_set_rf_band(const uint8_t band)1393 int wifi_set_rf_band(const uint8_t band)
1394 {
1395     int ret;
1396 
1397     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1398 
1399     if (band != 0U
1400 #if CONFIG_5GHz_SUPPORT
1401         && band != 1U
1402 #endif
1403     )
1404         return -WM_FAIL;
1405 
1406 #if CONFIG_5GHz_SUPPORT
1407     if ((band == 1) && ISSUPP_NO5G(mlan_adap->fw_cap_ext))
1408     {
1409         wifi_e("Not support 5G, please set 2G band");
1410         return -WM_FAIL;
1411     }
1412 #endif
1413 
1414     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1415 
1416     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RF_BAND_AG;
1417     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1418 
1419     wifi_mfg_cmd_generic_cfg.data1 = band;
1420 
1421     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1422 
1423     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1424     {
1425         band_set = 1;
1426         return WM_SUCCESS;
1427     }
1428 
1429     wifi_e("Wifi set rf band fails, error code: 0x%x", wifi_mfg_cmd_generic_cfg.error);
1430     return -WM_FAIL;
1431 }
1432 
wifi_get_rf_band(uint8_t * band)1433 int wifi_get_rf_band(uint8_t *band)
1434 {
1435     int ret;
1436 
1437     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1438 
1439     if (!band_set)
1440     {
1441         wifi_e("RF Band not set");
1442         return -WM_FAIL;
1443     }
1444 
1445     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1446 
1447     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RF_BAND_AG;
1448     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_GET;
1449 
1450     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_generic_cfg);
1451     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1452     {
1453         *band = wifi_mfg_cmd_generic_cfg.data1;
1454         return WM_SUCCESS;
1455     }
1456 
1457     wifi_e("Wifi get rf band fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1458     return -WM_FAIL;
1459 }
1460 
wifi_set_rf_bandwidth(const uint8_t bandwidth)1461 int wifi_set_rf_bandwidth(const uint8_t bandwidth)
1462 {
1463     int ret;
1464 
1465     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1466 
1467     if ((bandwidth != 0U)
1468 #if CONFIG_5GHz_SUPPORT
1469         && (bandwidth != 1U)
1470 #endif
1471 #if CONFIG_11AC
1472         && (bandwidth != 4U)
1473 #endif
1474     )
1475     {
1476         return -WM_FAIL;
1477     }
1478 
1479     if ((bandwidth != 0) && ISSUPP_NO5G(mlan_adap->fw_cap_ext))
1480     {
1481         wifi_e("Not support 5G, please set 2G bandwidth");
1482         return -WM_FAIL;
1483     }
1484 
1485     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1486 
1487     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RF_CHANNELBW;
1488     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1489 
1490     wifi_mfg_cmd_generic_cfg.data1 = bandwidth;
1491 
1492     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1493     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1494     {
1495         bandwidth_set = 1;
1496         return WM_SUCCESS;
1497     }
1498 
1499     wifi_e("Wifi set rf bandwidth fails, error code: 0x%x", wifi_mfg_cmd_generic_cfg.error);
1500     return -WM_FAIL;
1501 }
1502 
wifi_get_rf_bandwidth(uint8_t * bandwidth)1503 int wifi_get_rf_bandwidth(uint8_t *bandwidth)
1504 {
1505     int ret;
1506 
1507     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1508 
1509     if (!bandwidth_set)
1510     {
1511         wifi_e("Bandwidth not set");
1512         return -WM_FAIL;
1513     }
1514 
1515     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1516 
1517     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RF_CHANNELBW;
1518     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_GET;
1519 
1520     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_generic_cfg);
1521     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1522     {
1523         *bandwidth = wifi_mfg_cmd_generic_cfg.data1;
1524         return WM_SUCCESS;
1525     }
1526 
1527     wifi_e("Wifi get rf bandwidth fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1528     return -WM_FAIL;
1529 }
1530 
wifi_get_rf_per(uint32_t * rx_tot_pkt_count,uint32_t * rx_mcast_bcast_count,uint32_t * rx_pkt_fcs_error)1531 int wifi_get_rf_per(uint32_t *rx_tot_pkt_count, uint32_t *rx_mcast_bcast_count, uint32_t *rx_pkt_fcs_error)
1532 {
1533     int ret;
1534 
1535     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1536 
1537     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1538 
1539     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_CLR_RX_ERR;
1540     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_GET;
1541 
1542     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_generic_cfg);
1543     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1544     {
1545         *rx_tot_pkt_count     = wifi_mfg_cmd_generic_cfg.data1;
1546         *rx_mcast_bcast_count = wifi_mfg_cmd_generic_cfg.data2;
1547         *rx_pkt_fcs_error     = wifi_mfg_cmd_generic_cfg.data3;
1548         return WM_SUCCESS;
1549     }
1550 
1551     wifi_e("Wifi get rf per fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1552     return -WM_FAIL;
1553 }
1554 
wifi_set_rf_tx_cont_mode(const uint32_t enable_tx,const uint32_t cw_mode,const uint32_t payload_pattern,const uint32_t cs_mode,const uint32_t act_sub_ch,const uint32_t tx_rate)1555 int wifi_set_rf_tx_cont_mode(const uint32_t enable_tx,
1556                              const uint32_t cw_mode,
1557                              const uint32_t payload_pattern,
1558                              const uint32_t cs_mode,
1559                              const uint32_t act_sub_ch,
1560                              const uint32_t tx_rate)
1561 {
1562     wifi_mfg_cmd_tx_cont_t wifi_mfg_cmd_tx_cont;
1563     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1564     int ret;
1565 
1566     if ((enable_tx > 1U) || (cw_mode > 1U) || (cs_mode > 1U) || (act_sub_ch == 2U || act_sub_ch > 3U))
1567         return -WM_FAIL;
1568 
1569     (void)memset(&wifi_mfg_cmd_tx_cont, 0x00, sizeof(wifi_mfg_cmd_tx_cont_t));
1570     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1571 
1572     wifi_mfg_cmd_tx_cont.mfg_cmd = MFG_CMD_TX_CONT;
1573     wifi_mfg_cmd_tx_cont.action  = HostCmd_ACT_GEN_SET;
1574 
1575     wifi_mfg_cmd_tx_cont.enable_tx       = enable_tx;
1576     wifi_mfg_cmd_tx_cont.cw_mode         = cw_mode;
1577     wifi_mfg_cmd_tx_cont.payload_pattern = payload_pattern;
1578     wifi_mfg_cmd_tx_cont.cs_mode         = cs_mode;
1579     wifi_mfg_cmd_tx_cont.act_sub_ch      = act_sub_ch;
1580     wifi_mfg_cmd_tx_cont.tx_rate         = tx_rate;
1581 
1582     ret = wifi_get_set_rf_test_tx_cont(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_tx_cont, &wifi_mfg_cmd_generic_cfg);
1583     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1584     {
1585         return WM_SUCCESS;
1586     }
1587 
1588     wifi_e("Wifi set rf tx cont mode fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1589     return -WM_FAIL;
1590 }
1591 
wifi_set_rf_tx_antenna(const uint8_t antenna)1592 int wifi_set_rf_tx_antenna(const uint8_t antenna)
1593 {
1594     int ret;
1595 
1596     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1597 
1598     if (antenna != 1U && antenna != 2U)
1599         return -WM_FAIL;
1600 
1601     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1602 
1603     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_TX_ANT;
1604     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1605 
1606     wifi_mfg_cmd_generic_cfg.data1 = antenna;
1607 
1608     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1609     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1610     {
1611         tx_antenna_set = 1;
1612         return WM_SUCCESS;
1613     }
1614 
1615     wifi_e("Wifi set rf tx antenna fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1616     return -WM_FAIL;
1617 }
1618 
wifi_get_rf_tx_antenna(uint8_t * antenna)1619 int wifi_get_rf_tx_antenna(uint8_t *antenna)
1620 {
1621     int ret;
1622 
1623     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1624 
1625     if (!tx_antenna_set)
1626     {
1627         wifi_e("Tx Antenna not set");
1628         return -WM_FAIL;
1629     }
1630 
1631     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1632 
1633     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_TX_ANT;
1634     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_GET;
1635 
1636     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_generic_cfg);
1637     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1638     {
1639         *antenna = wifi_mfg_cmd_generic_cfg.data1;
1640         return WM_SUCCESS;
1641     }
1642 
1643     wifi_e("Wifi get rf tx antenna fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1644     return -WM_FAIL;
1645     ;
1646 }
1647 
wifi_set_rf_rx_antenna(const uint8_t antenna)1648 int wifi_set_rf_rx_antenna(const uint8_t antenna)
1649 {
1650     int ret;
1651 
1652     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1653 
1654     if (antenna != 1U && antenna != 2U)
1655         return -WM_FAIL;
1656 
1657     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1658 
1659     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RX_ANT;
1660     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1661 
1662     wifi_mfg_cmd_generic_cfg.data1 = antenna;
1663 
1664     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1665     if (ret == WM_SUCCESS && wifi_mfg_cmd_generic_cfg.error == 0)
1666     {
1667         rx_antenna_set = 1;
1668         return WM_SUCCESS;
1669     }
1670 
1671     wifi_e("Wifi get rf tx antenna fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1672     return -WM_FAIL;
1673 }
1674 
wifi_get_rf_rx_antenna(uint8_t * antenna)1675 int wifi_get_rf_rx_antenna(uint8_t *antenna)
1676 {
1677     int ret;
1678 
1679     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1680 
1681     if (!rx_antenna_set)
1682     {
1683         wifi_e("Rx antenna not set");
1684         return -WM_FAIL;
1685     }
1686 
1687     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1688 
1689     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RX_ANT;
1690     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_GET;
1691 
1692     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_generic_cfg);
1693 
1694     if (ret == WM_SUCCESS)
1695         *antenna = wifi_mfg_cmd_generic_cfg.data1;
1696 
1697     return ret;
1698 }
1699 
wifi_set_rf_tx_power(const uint32_t power,const uint8_t mod,const uint8_t path_id)1700 int wifi_set_rf_tx_power(const uint32_t power, const uint8_t mod, const uint8_t path_id)
1701 {
1702     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1703     int ret;
1704 
1705     if (mod != 0U && mod != 1U && mod != 2U)
1706         return -WM_FAIL;
1707 
1708     if (path_id != 0U && path_id != 1U && path_id != 2U)
1709         return -WM_FAIL;
1710 
1711     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1712 
1713     wifi_mfg_cmd_generic_cfg.mfg_cmd = MFG_CMD_RFPWR;
1714     wifi_mfg_cmd_generic_cfg.action  = HostCmd_ACT_GEN_SET;
1715 #ifdef SD9177
1716     /* Firecrest firmware expects value * 16 */
1717     wifi_mfg_cmd_generic_cfg.data1 = power * 16;
1718 #else
1719     wifi_mfg_cmd_generic_cfg.data1 = power;
1720 #endif
1721     wifi_mfg_cmd_generic_cfg.data2 = mod;
1722     wifi_mfg_cmd_generic_cfg.data3 = path_id;
1723 
1724     ret = wifi_get_set_rf_test_generic(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_generic_cfg);
1725     if (ret == WM_SUCCESS)
1726     {
1727         return WM_SUCCESS;
1728     }
1729 
1730     wifi_e("Wifi set rf tx power fails, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1731     return -WM_FAIL;
1732 }
1733 
1734 #ifdef RW610
wifi_check_data_rate_id(const uint32_t data_rate)1735 static int wifi_check_data_rate_id(const uint32_t data_rate)
1736 {
1737     uint8_t i;
1738     for (i = 0; i < sizeof(tx_data_rate_ids) / sizeof(tx_data_rate_ids[0]); i++)
1739     {
1740         if (data_rate == tx_data_rate_ids[i])
1741         {
1742             return WM_SUCCESS;
1743         }
1744     }
1745     return -WM_FAIL;
1746 }
1747 #endif
1748 
wifi_set_rf_tx_frame(const uint32_t enable,const uint32_t data_rate,const uint32_t frame_pattern,const uint32_t frame_length,const uint16_t adjust_burst_sifs,const uint32_t burst_sifs_in_us,const uint32_t short_preamble,const uint32_t act_sub_ch,const uint32_t short_gi,const uint32_t adv_coding,const uint32_t tx_bf,const uint32_t gf_mode,const uint32_t stbc,const uint8_t * bssid)1749 int wifi_set_rf_tx_frame(const uint32_t enable,
1750                          const uint32_t data_rate,
1751                          const uint32_t frame_pattern,
1752                          const uint32_t frame_length,
1753                          const uint16_t adjust_burst_sifs,
1754                          const uint32_t burst_sifs_in_us,
1755                          const uint32_t short_preamble,
1756                          const uint32_t act_sub_ch,
1757                          const uint32_t short_gi,
1758                          const uint32_t adv_coding,
1759                          const uint32_t tx_bf,
1760                          const uint32_t gf_mode,
1761                          const uint32_t stbc,
1762                          const uint8_t *bssid)
1763 {
1764     wifi_mfg_cmd_tx_frame_t wifi_mfg_cmd_tx_frame;
1765     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1766     int ret;
1767 
1768     if (enable > 1U || frame_length < 1U || frame_length > 0x400U || burst_sifs_in_us > 255U || short_preamble > 1U ||
1769         act_sub_ch == 2U || act_sub_ch > 3U || short_gi > 1U || adv_coding > 1U || tx_bf > 1U || gf_mode > 1U ||
1770         stbc > 1U)
1771         return -WM_FAIL;
1772 
1773     (void)memset(&wifi_mfg_cmd_tx_frame, 0x00, sizeof(wifi_mfg_cmd_tx_frame_t));
1774     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1775 #ifdef RW610
1776     ret = wifi_check_data_rate_id(data_rate);
1777     if ((enable == 1U) && (ret != WM_SUCCESS))
1778     {
1779         wifi_e("The configured data rate ID is illegal. data_rate_id: 0x%x\r\n", data_rate);
1780         return ret;
1781     }
1782 #endif
1783 
1784     wifi_mfg_cmd_tx_frame.mfg_cmd = MFG_CMD_TX_FRAME;
1785     wifi_mfg_cmd_tx_frame.action  = HostCmd_ACT_GEN_SET;
1786 
1787     wifi_mfg_cmd_tx_frame.enable    = enable;
1788     wifi_mfg_cmd_tx_frame.data_rate = data_rate;
1789 #ifdef RW610
1790     /* on fw side, data rate id of 802.11n/a/g/b start from 0, the data rate id need reduce 1 */
1791     if (data_rate <= HT_MCS7)
1792     {
1793         wifi_mfg_cmd_tx_frame.data_rate--;
1794     }
1795 #endif
1796 
1797     wifi_mfg_cmd_tx_frame.frame_pattern = frame_pattern;
1798     wifi_mfg_cmd_tx_frame.frame_length  = frame_length;
1799     (void)memcpy((void *)wifi_mfg_cmd_tx_frame.bssid, (const void *)bssid, MLAN_MAC_ADDR_LENGTH);
1800     wifi_mfg_cmd_tx_frame.adjust_burst_sifs = adjust_burst_sifs;
1801     wifi_mfg_cmd_tx_frame.burst_sifs_in_us  = burst_sifs_in_us;
1802     wifi_mfg_cmd_tx_frame.short_preamble    = short_preamble;
1803     wifi_mfg_cmd_tx_frame.act_sub_ch        = act_sub_ch;
1804     wifi_mfg_cmd_tx_frame.short_gi          = short_gi;
1805     wifi_mfg_cmd_tx_frame.adv_coding        = adv_coding;
1806     wifi_mfg_cmd_tx_frame.tx_bf             = tx_bf;
1807     wifi_mfg_cmd_tx_frame.gf_mode           = gf_mode;
1808     wifi_mfg_cmd_tx_frame.stbc              = stbc;
1809 
1810     ret = wifi_get_set_rf_test_tx_frame(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_tx_frame, &wifi_mfg_cmd_generic_cfg);
1811     if (WM_SUCCESS == ret && wifi_mfg_cmd_generic_cfg.error == 0)
1812     {
1813         return WM_SUCCESS;
1814     }
1815 
1816     wifi_e("wifi set rf tx frame fail, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1817     return -WM_FAIL;
1818 }
1819 
wifi_rf_trigger_frame_cfg(uint32_t Enable_tx,uint32_t Standalone_hetb,uint8_t FRAME_CTRL_TYPE,uint8_t FRAME_CTRL_SUBTYPE,uint16_t FRAME_DURATION,uint64_t TriggerType,uint64_t UlLen,uint64_t MoreTF,uint64_t CSRequired,uint64_t UlBw,uint64_t LTFType,uint64_t LTFMode,uint64_t LTFSymbol,uint64_t UlSTBC,uint64_t LdpcESS,uint64_t ApTxPwr,uint64_t PreFecPadFct,uint64_t PeDisambig,uint64_t SpatialReuse,uint64_t Doppler,uint64_t HeSig2,uint32_t AID12,uint32_t RUAllocReg,uint32_t RUAlloc,uint32_t UlCodingType,uint32_t UlMCS,uint32_t UlDCM,uint32_t SSAlloc,uint8_t UlTargetRSSI,uint8_t MPDU_MU_SF,uint8_t TID_AL,uint8_t AC_PL,uint8_t Pref_AC)1820 int wifi_rf_trigger_frame_cfg(uint32_t Enable_tx,
1821                               uint32_t Standalone_hetb,
1822                               uint8_t FRAME_CTRL_TYPE,
1823                               uint8_t FRAME_CTRL_SUBTYPE,
1824                               uint16_t FRAME_DURATION,
1825                               uint64_t TriggerType,
1826                               uint64_t UlLen,
1827                               uint64_t MoreTF,
1828                               uint64_t CSRequired,
1829                               uint64_t UlBw,
1830                               uint64_t LTFType,
1831                               uint64_t LTFMode,
1832                               uint64_t LTFSymbol,
1833                               uint64_t UlSTBC,
1834                               uint64_t LdpcESS,
1835                               uint64_t ApTxPwr,
1836                               uint64_t PreFecPadFct,
1837                               uint64_t PeDisambig,
1838                               uint64_t SpatialReuse,
1839                               uint64_t Doppler,
1840                               uint64_t HeSig2,
1841                               uint32_t AID12,
1842                               uint32_t RUAllocReg,
1843                               uint32_t RUAlloc,
1844                               uint32_t UlCodingType,
1845                               uint32_t UlMCS,
1846                               uint32_t UlDCM,
1847                               uint32_t SSAlloc,
1848                               uint8_t UlTargetRSSI,
1849                               uint8_t MPDU_MU_SF,
1850                               uint8_t TID_AL,
1851                               uint8_t AC_PL,
1852                               uint8_t Pref_AC)
1853 {
1854     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr_t wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr;
1855     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1856     int ret;
1857 
1858     (void)memset(&wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr, 0x00, sizeof(wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr_t));
1859     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1860     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.mfg_cmd = MFG_CMD_CONFIG_TRIGGER_FRAME;
1861     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.action  = HostCmd_ACT_GEN_SET;
1862 
1863     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.enable_tx       = Enable_tx;
1864     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.standalone_hetb = Standalone_hetb;
1865     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.frmCtl.type     = FRAME_CTRL_TYPE;
1866     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.frmCtl.sub_type = FRAME_CTRL_SUBTYPE;
1867     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.duration        = FRAME_DURATION;
1868 
1869     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.trigger_type    = TriggerType;
1870     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ul_len          = UlLen;
1871     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.more_tf         = MoreTF;
1872     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.cs_required     = CSRequired;
1873     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ul_bw           = UlBw;
1874     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ltf_type        = LTFType;
1875     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ltf_mode        = LTFMode;
1876     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ltf_symbol      = LTFSymbol;
1877     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ul_stbc         = UlSTBC;
1878     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ldpc_ess        = LdpcESS;
1879     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.ap_tx_pwr       = ApTxPwr;
1880     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.pre_fec_pad_fct = PreFecPadFct;
1881     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.pe_disambig     = PeDisambig;
1882     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.spatial_reuse   = SpatialReuse;
1883     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.doppler         = Doppler;
1884     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_common_field.he_sig2         = HeSig2;
1885 
1886     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.aid12          = AID12;
1887     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.ru_alloc_reg   = RUAllocReg;
1888     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.ru_alloc       = RUAlloc;
1889     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.ul_coding_type = UlCodingType;
1890     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.ul_mcs         = UlMCS;
1891     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.ul_dcm         = UlDCM;
1892     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.ss_alloc       = SSAlloc;
1893     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.trig_user_info_field.ul_target_rssi = UlTargetRSSI;
1894 
1895     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.basic_trig_user_info.mpdu_mu_sf = MPDU_MU_SF;
1896     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.basic_trig_user_info.tid_al     = TID_AL;
1897     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.basic_trig_user_info.ac_pl      = AC_PL;
1898     wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr.basic_trig_user_info.pref_ac    = Pref_AC;
1899 
1900     ret = wifi_get_set_rf_trigger_frame_cfg(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_IEEEtypes_CtlBasicTrigHdr,
1901                                             &wifi_mfg_cmd_generic_cfg);
1902     if (WM_SUCCESS == ret && wifi_mfg_cmd_generic_cfg.error == 0)
1903     {
1904         return WM_SUCCESS;
1905     }
1906 
1907     wifi_e("wifi set rf tx frame fail, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1908     return -WM_FAIL;
1909 }
1910 
wifi_cfg_rf_he_tb_tx(uint16_t enable,uint16_t qnum,uint16_t aid,uint16_t axq_mu_timer,int16_t tx_power)1911 int wifi_cfg_rf_he_tb_tx(uint16_t enable, uint16_t qnum, uint16_t aid, uint16_t axq_mu_timer, int16_t tx_power)
1912 {
1913     wifi_mfg_cmd_he_tb_tx_t wifi_mfg_cmd_he_tb_tx;
1914 
1915     wifi_mfg_cmd_generic_cfg_t wifi_mfg_cmd_generic_cfg;
1916     int ret;
1917 
1918     (void)memset(&wifi_mfg_cmd_he_tb_tx, 0x00, sizeof(wifi_mfg_cmd_he_tb_tx_t));
1919     (void)memset(&wifi_mfg_cmd_generic_cfg, 0x00, sizeof(wifi_mfg_cmd_generic_cfg_t));
1920     wifi_mfg_cmd_he_tb_tx.mfg_cmd = MFG_CMD_CONFIG_MAC_HE_TB_TX;
1921     wifi_mfg_cmd_he_tb_tx.action  = HostCmd_ACT_GEN_SET;
1922 
1923     wifi_mfg_cmd_he_tb_tx.enable       = enable;
1924     wifi_mfg_cmd_he_tb_tx.qnum         = qnum;
1925     wifi_mfg_cmd_he_tb_tx.aid          = aid;
1926     wifi_mfg_cmd_he_tb_tx.axq_mu_timer = axq_mu_timer;
1927     wifi_mfg_cmd_he_tb_tx.tx_power     = tx_power;
1928 
1929     ret = wifi_get_set_rf_he_tb_tx(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_he_tb_tx, &wifi_mfg_cmd_generic_cfg);
1930     if (WM_SUCCESS == ret && wifi_mfg_cmd_generic_cfg.error == 0)
1931     {
1932         return WM_SUCCESS;
1933     }
1934 
1935     wifi_e("wifi set rf tx frame fail, error code: 0x%x\r\n", wifi_mfg_cmd_generic_cfg.error);
1936     return -WM_FAIL;
1937 }
1938 
wifi_set_rf_otp_mac_addr(uint8_t * mac)1939 int wifi_set_rf_otp_mac_addr(uint8_t *mac)
1940 {
1941     int ret;
1942 
1943     wifi_mfg_cmd_otp_mac_addr_rd_wr_t wifi_mfg_cmd_otp_mac_addr_rd_wr;
1944 
1945     (void)memset(&wifi_mfg_cmd_otp_mac_addr_rd_wr, 0x00, sizeof(wifi_mfg_cmd_otp_mac_addr_rd_wr_t));
1946 
1947     wifi_mfg_cmd_otp_mac_addr_rd_wr.mfg_cmd = MFG_CMD_OTP_MAC_ADD;
1948     wifi_mfg_cmd_otp_mac_addr_rd_wr.action  = HostCmd_ACT_GEN_SET;
1949     (void)memcpy((void *)wifi_mfg_cmd_otp_mac_addr_rd_wr.mac_addr, (const void *)mac, MLAN_MAC_ADDR_LENGTH);
1950 
1951     ret = wifi_get_set_rf_otp_mac_addr(HostCmd_ACT_GEN_SET, &wifi_mfg_cmd_otp_mac_addr_rd_wr);
1952     if (ret == WM_SUCCESS && wifi_mfg_cmd_otp_mac_addr_rd_wr.error == 0)
1953     {
1954         return WM_SUCCESS;
1955     }
1956 
1957     wifi_e("wifi set otp mac address fails, error code: 0x%x\r\n", wifi_mfg_cmd_otp_mac_addr_rd_wr.error);
1958     return -WM_FAIL;
1959 }
1960 
wifi_get_rf_otp_mac_addr(uint8_t * mac)1961 int wifi_get_rf_otp_mac_addr(uint8_t *mac)
1962 {
1963     int ret;
1964 
1965     wifi_mfg_cmd_otp_mac_addr_rd_wr_t wifi_mfg_cmd_otp_mac_addr_rd_wr;
1966 
1967     (void)memset(&wifi_mfg_cmd_otp_mac_addr_rd_wr, 0x00, sizeof(wifi_mfg_cmd_otp_mac_addr_rd_wr_t));
1968 
1969     wifi_mfg_cmd_otp_mac_addr_rd_wr.mfg_cmd = MFG_CMD_OTP_MAC_ADD;
1970     wifi_mfg_cmd_otp_mac_addr_rd_wr.action  = HostCmd_ACT_GEN_GET;
1971 
1972     ret = wifi_get_set_rf_otp_mac_addr(HostCmd_ACT_GEN_GET, &wifi_mfg_cmd_otp_mac_addr_rd_wr);
1973     if (ret == WM_SUCCESS && wifi_mfg_cmd_otp_mac_addr_rd_wr.error == 0)
1974     {
1975         (void)memcpy((void *)mac, (const void *)wifi_mfg_cmd_otp_mac_addr_rd_wr.mac_addr, MLAN_MAC_ADDR_LENGTH);
1976         return WM_SUCCESS;
1977     }
1978 
1979     wifi_e("wifi get otp mac address fails, error code: 0x%x\r\n", wifi_mfg_cmd_otp_mac_addr_rd_wr.error);
1980     return -WM_FAIL;
1981 }
1982 
wifi_set_rf_otp_cal_data(const uint8_t * cal_data,uint32_t cal_data_len)1983 int wifi_set_rf_otp_cal_data(const uint8_t *cal_data, uint32_t cal_data_len)
1984 {
1985     int ret;
1986 
1987     wifi_mfg_cmd_otp_cal_data_rd_wr_t *wifi_mfg_cmd_otp_cal_data_rd_wr = NULL;
1988 
1989     wifi_mfg_cmd_otp_cal_data_rd_wr =
1990         (wifi_mfg_cmd_otp_cal_data_rd_wr_t *)OSA_MemoryAllocate(sizeof(wifi_mfg_cmd_otp_cal_data_rd_wr_t));
1991     (void)memset(wifi_mfg_cmd_otp_cal_data_rd_wr, 0x00, sizeof(wifi_mfg_cmd_otp_cal_data_rd_wr_t));
1992 
1993     wifi_mfg_cmd_otp_cal_data_rd_wr->mfg_cmd      = MFG_CMD_OTP_CAL_DATA;
1994     wifi_mfg_cmd_otp_cal_data_rd_wr->action       = HostCmd_ACT_GEN_SET;
1995     wifi_mfg_cmd_otp_cal_data_rd_wr->cal_data_len = cal_data_len;
1996     (void)memcpy((void *)wifi_mfg_cmd_otp_cal_data_rd_wr->cal_data, (const void *)cal_data, cal_data_len);
1997 
1998     ret = wifi_get_set_rf_otp_cal_data(HostCmd_ACT_GEN_SET, wifi_mfg_cmd_otp_cal_data_rd_wr);
1999     if (ret == WM_SUCCESS && wifi_mfg_cmd_otp_cal_data_rd_wr->error == 0)
2000     {
2001         ret = WM_SUCCESS;
2002     }
2003     else
2004     {
2005         wifi_e("wifi set cal data fails, error code: 0x%x\r\n", wifi_mfg_cmd_otp_cal_data_rd_wr->error);
2006         ret = -WM_FAIL;
2007     }
2008 
2009     (void)OSA_MemoryFree(wifi_mfg_cmd_otp_cal_data_rd_wr);
2010     return ret;
2011 }
2012 
wifi_get_rf_otp_cal_data(uint8_t * cal_data)2013 int wifi_get_rf_otp_cal_data(uint8_t *cal_data)
2014 {
2015     int ret;
2016     uint32_t cal_data_status = 0;
2017 
2018     wifi_mfg_cmd_otp_cal_data_rd_wr_t *wifi_mfg_cmd_otp_cal_data_rd_wr = NULL;
2019 
2020     wifi_mfg_cmd_otp_cal_data_rd_wr =
2021         (wifi_mfg_cmd_otp_cal_data_rd_wr_t *)OSA_MemoryAllocate(sizeof(wifi_mfg_cmd_otp_cal_data_rd_wr_t));
2022     (void)memset(wifi_mfg_cmd_otp_cal_data_rd_wr, 0x00, sizeof(wifi_mfg_cmd_otp_cal_data_rd_wr_t));
2023 
2024     wifi_mfg_cmd_otp_cal_data_rd_wr->mfg_cmd = MFG_CMD_OTP_CAL_DATA;
2025     wifi_mfg_cmd_otp_cal_data_rd_wr->action  = HostCmd_ACT_GEN_GET;
2026 
2027     ret = wifi_get_set_rf_otp_cal_data(HostCmd_ACT_GEN_GET, wifi_mfg_cmd_otp_cal_data_rd_wr);
2028     if (ret == WM_SUCCESS && wifi_mfg_cmd_otp_cal_data_rd_wr->error == 0)
2029     {
2030         cal_data_status = wifi_mfg_cmd_otp_cal_data_rd_wr->cal_data_status;
2031         if (cal_data_status == 1)
2032         {
2033             (void)memcpy((void *)cal_data, (const void *)wifi_mfg_cmd_otp_cal_data_rd_wr->cal_data,
2034                          wifi_mfg_cmd_otp_cal_data_rd_wr->cal_data_len);
2035             ret = WM_SUCCESS;
2036         }
2037         else
2038         {
2039             ret = -WM_FAIL;
2040         }
2041     }
2042     else
2043     {
2044         wifi_e("wifi get otp cal data fails, error code: 0x%x\r\n", wifi_mfg_cmd_otp_cal_data_rd_wr->error);
2045         ret = -WM_FAIL;
2046     }
2047 
2048     (void)OSA_MemoryFree(wifi_mfg_cmd_otp_cal_data_rd_wr);
2049 
2050     return ret;
2051 }
2052 #endif
2053 
2054 /*
2055  * fixme: Currently, we support only single SSID based scan. We can extend
2056  * this to a list of multiple SSIDs. The mlan API supports this.
2057  */
wifi_send_scan_cmd(t_u8 bss_mode,const t_u8 * specific_bssid,const char * ssid,uint8_t ssid_num,const t_u8 num_channels,const wifi_scan_channel_list_t * chan_list,const t_u8 num_probes,const t_s16 rssi_threshold,const t_u16 scan_chan_gap,const bool keep_previous_scan,const bool active_scan_triggered)2058 int wifi_send_scan_cmd(t_u8 bss_mode,
2059                        const t_u8 *specific_bssid,
2060                        const char *ssid,
2061                        uint8_t ssid_num,
2062                        const t_u8 num_channels,
2063                        const wifi_scan_channel_list_t *chan_list,
2064                        const t_u8 num_probes,
2065 #if CONFIG_SCAN_WITH_RSSIFILTER
2066                        const t_s16 rssi_threshold,
2067 #endif
2068 #if CONFIG_SCAN_CHANNEL_GAP
2069                        const t_u16 scan_chan_gap,
2070 #endif
2071                        const bool keep_previous_scan,
2072                        const bool active_scan_triggered)
2073 {
2074     int ssid_len  = 0;
2075     char const *tmp_ssid = ssid;
2076     t_u8 i;
2077 #if CONFIG_COMBO_SCAN
2078     const char wildcard_ssid[] = "*";
2079 #endif
2080     mlan_adap->active_scan_triggered = MFALSE;
2081 
2082 #if CONFIG_WPA_SUPP
2083     if (mlan_adap->wpa_supp_scan_triggered == MTRUE)
2084     {
2085         return -WM_E_BUSY;
2086     }
2087 
2088     mlan_adap->wpa_supp_scan_triggered = wm_wifi.wpa_supp_scan;
2089     wm_wifi.wpa_supp_scan              = MFALSE;
2090 #endif
2091     if (ssid_num > MRVDRV_MAX_SSID_LIST_LENGTH)
2092          return -WM_E_INVAL;
2093     tmp_ssid = ssid;
2094     for (i = 0; i < ssid_num; i++)
2095     {
2096         ssid_len = strlen(tmp_ssid);
2097         tmp_ssid += ssid_len;
2098         tmp_ssid++;
2099         if (ssid_len > MLAN_MAX_SSID_LENGTH)
2100         {
2101 #if CONFIG_WPA_SUPP
2102             mlan_adap->wpa_supp_scan_triggered = MFALSE;
2103 #endif
2104             return -WM_E_INVAL;
2105         }
2106     }
2107 
2108 #if !CONFIG_MEM_POOLS
2109     wlan_user_scan_cfg *user_scan_cfg = (wlan_user_scan_cfg *)OSA_MemoryAllocate(sizeof(wlan_user_scan_cfg));
2110 #else
2111     wlan_user_scan_cfg *user_scan_cfg = (wlan_user_scan_cfg *)OSA_MemoryPoolAllocate(buf_512_MemoryPool);
2112 #endif
2113     if (user_scan_cfg == MNULL)
2114     {
2115 #if CONFIG_WPA_SUPP
2116         mlan_adap->wpa_supp_scan_triggered = MFALSE;
2117 #endif
2118         return -WM_E_NOMEM;
2119     }
2120 
2121     (void)memset(user_scan_cfg, 0x00, sizeof(wlan_user_scan_cfg));
2122 
2123     user_scan_cfg->bss_mode           = bss_mode;
2124     user_scan_cfg->keep_previous_scan = keep_previous_scan;
2125 
2126 #if CONFIG_SCAN_WITH_RSSIFILTER
2127     user_scan_cfg->rssi_threshold = rssi_threshold;
2128 #endif
2129 
2130     if (num_probes > 0U && num_probes <= MAX_PROBES)
2131     {
2132         user_scan_cfg->num_probes = num_probes;
2133     }
2134 
2135     if (specific_bssid != NULL)
2136     {
2137         (void)memcpy((void *)user_scan_cfg->specific_bssid, (const void *)specific_bssid, MLAN_MAC_ADDR_LENGTH);
2138     }
2139 
2140     tmp_ssid = ssid;
2141     for (i = 0; i < ssid_num; i++)
2142     {
2143         ssid_len = strlen(tmp_ssid);
2144         (void)memcpy((void *)user_scan_cfg->ssid_list[i].ssid, (const void *)tmp_ssid, ssid_len);
2145         tmp_ssid += ssid_len;
2146         tmp_ssid++;
2147     }
2148 
2149 #if CONFIG_COMBO_SCAN
2150     for (i = 0; (i < MRVDRV_MAX_SSID_LIST_LENGTH) && (*user_scan_cfg->ssid_list[i].ssid); i++)
2151     {
2152         if (!strncmp(wildcard_ssid, (char *)(user_scan_cfg->ssid_list[i].ssid), strlen(wildcard_ssid)))
2153         {
2154             (void)memset(user_scan_cfg->ssid_list[i].ssid, 0x00, sizeof(user_scan_cfg->ssid_list[i].ssid));
2155             user_scan_cfg->ssid_list[i].max_len = 40;
2156         }
2157     }
2158 #endif
2159 
2160     if ((chan_list != MNULL) && (chan_list[0].radio_type & BAND_SPECIFIED))
2161     {
2162         user_scan_cfg->chan_list[0].radio_type = chan_list[0].radio_type;
2163     }
2164     else if (num_channels > 0U && num_channels <= WLAN_USER_SCAN_CHAN_MAX && chan_list != MNULL)
2165     {
2166         for (i = 0; i < num_channels; i++)
2167         {
2168             /** Channel Number to scan */
2169             user_scan_cfg->chan_list[i].chan_number = chan_list[i].chan_number;
2170             /** Radio type: 'B/G' Band = 0, 'A' Band = 1 */
2171             /* fixme: B/G is hardcoded here. Ask the caller first to
2172                send the radio type and then change here */
2173             if (chan_list[i].chan_number > 14U)
2174             {
2175                 user_scan_cfg->chan_list[i].radio_type = 1;
2176             }
2177             /** Scan type: Active = 1, Passive = 2 */
2178             /* fixme: Active is hardcoded here. Ask the caller first to
2179                send the  type and then change here */
2180             user_scan_cfg->chan_list[i].scan_type = chan_list[i].scan_type;
2181             /** Scan duration in milliseconds; if 0 default used */
2182             user_scan_cfg->chan_list[i].scan_time = chan_list[i].scan_time;
2183         }
2184     }
2185 
2186     if (active_scan_triggered)
2187     {
2188         mlan_adap->active_scan_triggered = MTRUE;
2189     }
2190 #if CONFIG_SCAN_CHANNEL_GAP
2191     user_scan_cfg->scan_chan_gap = scan_chan_gap;
2192 #endif
2193     if (wm_wifi.g_user_scan_cfg != NULL)
2194     {
2195 #if !CONFIG_MEM_POOLS
2196         OSA_MemoryFree((void *)user_scan_cfg);
2197 #else
2198         OSA_MemoryPoolFree(buf_512_MemoryPool, user_scan_cfg);
2199 #endif
2200 
2201 #if CONFIG_WPA_SUPP
2202         mlan_adap->wpa_supp_scan_triggered = MFALSE;
2203         return -WM_E_BUSY;
2204 #else
2205         return -WM_E_BUSY;
2206 #endif
2207     }
2208 
2209     wm_wifi.g_user_scan_cfg = user_scan_cfg;
2210     (void)OSA_TaskNotifyPost(wm_wifi.wifi_scan_task_Handle);
2211 
2212     return WM_SUCCESS;
2213 }
2214 
2215 #if CONFIG_WPA_SUPP
wifi_send_sched_scan_cmd(nxp_wifi_trigger_sched_scan_t * params)2216 int wifi_send_sched_scan_cmd(nxp_wifi_trigger_sched_scan_t *params)
2217 {
2218     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2219     int ret, i;
2220 
2221     memset(&pmpriv->scan_cfg, 0, sizeof(pmpriv->scan_cfg));
2222 
2223     if (params->num_ssids != 0U)
2224     {
2225         for (i = 0; i < params->num_ssids; i++)
2226         {
2227             memcpy((void *)pmpriv->scan_cfg.ssid_list[i].ssid, (const void *)params->scan_ssids[i].ssid,
2228                    (size_t)params->scan_ssids[i].ssid_len);
2229             pmpriv->scan_cfg.ssid_list[i].max_len = 0;
2230         }
2231     }
2232     else
2233     {
2234         pmpriv->scan_cfg.ssid_list[0].max_len = 0xff;
2235     }
2236 
2237     for (i = 0; params->num_chans; i++)
2238     {
2239         pmpriv->scan_cfg.chan_list[i].chan_number = params->chan_list[i];
2240 
2241         pmpriv->scan_cfg.chan_list[i].scan_type = MLAN_SCAN_TYPE_ACTIVE;
2242 
2243         if (pmpriv->scan_cfg.chan_list[i].chan_number > 14)
2244         {
2245             pmpriv->scan_cfg.chan_list[i].radio_type = HostCmd_SCAN_RADIO_TYPE_A;
2246         }
2247         else
2248         {
2249             pmpriv->scan_cfg.chan_list[i].radio_type = HostCmd_SCAN_RADIO_TYPE_BG;
2250         }
2251     }
2252 
2253     if (pmpriv->probe_req_index != -1)
2254     {
2255         ret = wifi_clear_mgmt_ie2(MLAN_BSS_TYPE_STA, pmpriv->probe_req_index);
2256 
2257         if (ret != WM_SUCCESS)
2258         {
2259             wifi_e("Clear probe req IE failed");
2260             return -WM_FAIL;
2261         }
2262         pmpriv->probe_req_index = -1;
2263     }
2264 
2265     if (params->extra_ies.ie_len)
2266     {
2267         pmpriv->probe_req_index = wifi_set_mgmt_ie2(MLAN_BSS_TYPE_STA, MGMT_MASK_PROBE_REQ,
2268                                                     (void *)params->extra_ies.ie, params->extra_ies.ie_len);
2269 
2270         if (pmpriv->probe_req_index == -1)
2271         {
2272             wifi_e("Set probe req IE failed");
2273             return -WM_FAIL;
2274         }
2275     }
2276 
2277     pmpriv->scan_cfg.report_condition = params->report_condition;
2278     pmpriv->scan_cfg.rssi_threshold   = params->filter_rssi;
2279     pmpriv->scan_cfg.repeat_count     = params->repeat_count;
2280     pmpriv->scan_cfg.scan_interval    = params->scan_interval;
2281     pmpriv->scan_cfg.chan_per_scan    = params->chan_per_scan;
2282     pmpriv->scan_cfg.num_probes       = 2;
2283 
2284     pmpriv->scan_cfg.bss_type = MLAN_BSS_MODE_INFRA;
2285     pmpriv->scan_cfg.action   = BG_SCAN_ACT_SET;
2286     pmpriv->scan_cfg.enable   = MTRUE;
2287 
2288     ret = wifi_request_bgscan(pmpriv);
2289     if (ret)
2290     {
2291         wifi_d("Failed to request bgscan");
2292         return -WM_FAIL;
2293     }
2294 
2295     pmpriv->sched_scanning   = MTRUE;
2296     pmpriv->bg_scan_start    = MTRUE;
2297     pmpriv->bg_scan_reported = MFALSE;
2298 
2299     return ret;
2300 }
2301 
wifi_send_stop_sched_scan_cmd(void)2302 int wifi_send_stop_sched_scan_cmd(void)
2303 {
2304     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2305 
2306     pmpriv->sched_scanning   = MFALSE;
2307     pmpriv->bg_scan_start    = MFALSE;
2308     pmpriv->bg_scan_reported = MFALSE;
2309 
2310     memset(&pmpriv->scan_cfg, 0, sizeof(pmpriv->scan_cfg));
2311 
2312     pmpriv->scan_cfg.action = BG_SCAN_ACT_SET;
2313     pmpriv->scan_cfg.enable = MFALSE;
2314     int ret                 = wifi_request_bgscan(pmpriv);
2315     if (ret)
2316     {
2317         wifi_d("Failed to request bgscan");
2318     }
2319 
2320     return ret;
2321 }
2322 #endif
2323 
wifi_send_key_material_cmd(int bss_index,mlan_ds_sec_cfg * sec)2324 static int wifi_send_key_material_cmd(int bss_index, mlan_ds_sec_cfg *sec)
2325 {
2326     /* fixme: check if this needs to go on heap */
2327     mlan_ioctl_req req;
2328     mlan_status rv = MLAN_STATUS_SUCCESS;
2329 
2330     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
2331     req.pbuf      = (t_u8 *)sec;
2332     req.buf_len   = sizeof(mlan_ds_sec_cfg);
2333     req.bss_index = bss_index;
2334     req.req_id    = MLAN_IOCTL_SEC_CFG;
2335     req.action    = MLAN_ACT_SET;
2336 
2337     if (bss_index != 0)
2338     {
2339         rv = wlan_ops_uap_ioctl(mlan_adap, &req);
2340     }
2341     else
2342     {
2343         rv = wlan_ops_sta_ioctl(mlan_adap, &req);
2344     }
2345 
2346     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
2347     {
2348         return -WM_FAIL;
2349     }
2350 
2351     return WM_SUCCESS;
2352 }
2353 
wifi_set_key(int bss_index,bool is_pairwise,const uint8_t key_index,const uint8_t * key,unsigned key_len,const uint8_t * seq,unsigned seq_len,const uint8_t * mac_addr,unsigned int flags)2354 int wifi_set_key(int bss_index,
2355                  bool is_pairwise,
2356                  const uint8_t key_index,
2357                  const uint8_t *key,
2358                  unsigned key_len,
2359                  const uint8_t *seq,
2360                  unsigned seq_len,
2361                  const uint8_t *mac_addr,
2362                  unsigned int flags)
2363 {
2364     /* fixme: check if this needs to go on heap */
2365     mlan_ds_sec_cfg sec;
2366     int ret           = WM_SUCCESS;
2367     t_u8 bcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2368 #if CONFIG_GTK_REKEY_OFFLOAD
2369     mlan_private *pmpriv        = (mlan_private *)mlan_adap->priv[bss_index];
2370     t_u8 zero_kek[MLAN_KEK_LEN] = {0};
2371 #endif
2372 
2373     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2374     sec.sub_command = MLAN_OID_SEC_CFG_ENCRYPT_KEY;
2375 
2376     if (key_len > MAX_WEP_KEY_SIZE)
2377     {
2378         if (seq && seq_len)
2379         {
2380             memcpy(sec.param.encrypt_key.pn, seq, seq_len);
2381             sec.param.encrypt_key.key_flags |= KEY_FLAG_RX_SEQ_VALID;
2382         }
2383 
2384         if (mac_addr)
2385         {
2386             if (is_pairwise)
2387             {
2388                 sec.param.encrypt_key.key_flags |= KEY_FLAG_SET_TX_KEY;
2389             }
2390             else
2391             {
2392                 sec.param.encrypt_key.key_flags |= KEY_FLAG_GROUP_KEY;
2393             }
2394             (void)memcpy((void *)sec.param.encrypt_key.mac_addr, (const void *)mac_addr, MLAN_MAC_ADDR_LENGTH);
2395         }
2396         else
2397         {
2398             memcpy(sec.param.encrypt_key.mac_addr, bcast_addr, MLAN_MAC_ADDR_LENGTH);
2399             sec.param.encrypt_key.key_flags |= KEY_FLAG_GROUP_KEY;
2400         }
2401         sec.param.encrypt_key.key_index = key_index;
2402 
2403         if (flags)
2404         {
2405             sec.param.encrypt_key.key_flags |= flags;
2406         }
2407     }
2408     else
2409     {
2410         sec.param.encrypt_key.key_index          = MLAN_KEY_INDEX_DEFAULT;
2411         sec.param.encrypt_key.is_current_wep_key = MTRUE;
2412     }
2413 
2414     sec.param.encrypt_key.key_len = key_len;
2415     (void)memcpy((void *)sec.param.encrypt_key.key_material, (const void *)key, key_len);
2416 
2417     ret = wifi_send_key_material_cmd(bss_index, &sec);
2418 
2419 #if CONFIG_GTK_REKEY_OFFLOAD
2420 
2421     if ((ret == WM_SUCCESS) && (is_pairwise == false))
2422     {
2423         if (memcmp(pmpriv->gtk_rekey.kek, zero_kek, sizeof(zero_kek)) != 0)
2424         {
2425             mlan_status status = MLAN_STATUS_SUCCESS;
2426             ret = wlan_prepare_cmd(pmpriv, HostCmd_CMD_CONFIG_GTK_REKEY_OFFLOAD_CFG, HostCmd_ACT_GEN_SET, 0, MNULL,
2427                                    &pmpriv->gtk_rekey);
2428             if (status)
2429             {
2430                 PRINTM(MINFO, "Error sending message to FW\n");
2431                 ret = -WM_FAIL;
2432             }
2433             (void)__memset(pmpriv->adapter, &pmpriv->gtk_rekey, 0, sizeof(mlan_ds_misc_gtk_rekey_data));
2434         }
2435     }
2436 #endif
2437 
2438     return ret;
2439 }
2440 
wifi_set_rekey_info(int bss_index,const t_u8 * kek,size_t kek_len,const t_u8 * kck,size_t kck_len,const t_u8 * replay_ctr)2441 int wifi_set_rekey_info(
2442     int bss_index, const t_u8 *kek, size_t kek_len, const t_u8 *kck, size_t kck_len, const t_u8 *replay_ctr)
2443 {
2444 #if CONFIG_GTK_REKEY_OFFLOAD
2445     mlan_ds_misc_cfg misc;
2446     mlan_ioctl_req req;
2447     mlan_status rv = MLAN_STATUS_SUCCESS;
2448 
2449     (void)memset(&misc, 0x00, sizeof(mlan_ds_misc_cfg));
2450 
2451     misc.sub_command = MLAN_OID_MISC_CONFIG_GTK_REKEY_OFFLOAD;
2452 
2453     (void)memcpy(misc.param.gtk_rekey.kek, kek, MLAN_KEK_LEN);
2454     (void)memcpy(misc.param.gtk_rekey.kck, kck, MLAN_KCK_LEN);
2455     (void)memcpy(misc.param.gtk_rekey.replay_ctr, replay_ctr, MLAN_REPLAY_CTR_LEN);
2456 
2457     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
2458     req.pbuf      = (t_u8 *)&misc;
2459     req.buf_len   = sizeof(mlan_ds_misc_cfg);
2460     req.bss_index = bss_index;
2461     req.req_id    = MLAN_IOCTL_MISC_CFG;
2462     req.action    = MLAN_ACT_SET;
2463 
2464     if (bss_index != 0)
2465     {
2466         rv = wlan_ops_uap_ioctl(mlan_adap, &req);
2467     }
2468     else
2469     {
2470         rv = wlan_ops_sta_ioctl(mlan_adap, &req);
2471     }
2472 
2473     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
2474     {
2475         return -WM_FAIL;
2476     }
2477 
2478     return WM_SUCCESS;
2479 #else
2480     return WM_SUCCESS;
2481 #endif
2482 }
2483 
wifi_set_igtk_key(int bss_index,const uint8_t * pn,const uint16_t key_index,const uint8_t * key,unsigned key_len)2484 int wifi_set_igtk_key(int bss_index, const uint8_t *pn, const uint16_t key_index, const uint8_t *key, unsigned key_len)
2485 {
2486     /* fixme: check if this needs to go on heap */
2487     mlan_ds_sec_cfg sec;
2488 
2489     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2490     sec.sub_command = MLAN_OID_SEC_CFG_ENCRYPT_KEY;
2491 
2492     sec.param.encrypt_key.key_flags = KEY_FLAG_AES_MCAST_IGTK;
2493     sec.param.encrypt_key.key_index = key_index;
2494 
2495     (void)memcpy((void *)sec.param.encrypt_key.pn, (const void *)pn, SEQ_MAX_SIZE);
2496     sec.param.encrypt_key.key_len = key_len;
2497     (void)memcpy((void *)sec.param.encrypt_key.key_material, (const void *)key, key_len);
2498 
2499     return wifi_send_key_material_cmd(bss_index, &sec);
2500 }
2501 
wifi_remove_key(int bss_index,bool is_pairwise,const uint8_t key_index,const uint8_t * mac_addr)2502 int wifi_remove_key(int bss_index, bool is_pairwise, const uint8_t key_index, const uint8_t *mac_addr)
2503 {
2504     /* fixme: check if this needs to go on heap */
2505     mlan_ds_sec_cfg sec;
2506 
2507     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2508     sec.sub_command = MLAN_OID_SEC_CFG_ENCRYPT_KEY;
2509 
2510     if (key_index == KEY_INDEX_CLEAR_ALL)
2511     {
2512         sec.param.encrypt_key.key_disable = MTRUE;
2513     }
2514     else
2515     {
2516         sec.param.encrypt_key.key_remove = MTRUE;
2517         sec.param.encrypt_key.key_index  = key_index;
2518     }
2519 
2520     sec.param.encrypt_key.key_len   = MLAN_MAX_KEY_LENGTH;
2521     sec.param.encrypt_key.key_flags = KEY_FLAG_REMOVE_KEY;
2522 
2523     if (mac_addr)
2524     {
2525         (void)memcpy((void *)sec.param.encrypt_key.mac_addr, (const void *)mac_addr, MLAN_MAC_ADDR_LENGTH);
2526     }
2527 
2528     return wifi_send_key_material_cmd(bss_index, &sec);
2529 }
2530 
2531 #ifdef STREAM_2X2
wifi_send_11n_cfg_cmd(t_u16 action,uint16_t httxcfg)2532 static int wifi_send_11n_cfg_cmd(t_u16 action, uint16_t httxcfg)
2533 {
2534     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2535     mlan_ds_11n_tx_cfg dot11n_tx_cfg;
2536 
2537     (void)memset(&dot11n_tx_cfg, 0x00, sizeof(mlan_ds_11n_tx_cfg));
2538 
2539     dot11n_tx_cfg.httxcap = httxcfg;
2540 
2541     if (action != HostCmd_ACT_GEN_GET && action != HostCmd_ACT_GEN_SET)
2542         return -WM_FAIL;
2543 
2544     wifi_get_command_lock();
2545     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
2546 
2547     cmd->seq_num = 0x0;
2548     cmd->result  = 0x0;
2549 
2550     mlan_status rv = wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_11N_CFG, action, 0, NULL, &dot11n_tx_cfg, cmd);
2551     if (rv != MLAN_STATUS_SUCCESS)
2552         return -WM_FAIL;
2553 
2554     return wifi_wait_for_cmdresp(NULL);
2555 }
2556 
wifi_send_11ac_cfg_cmd(t_u16 action,uint32_t vhtcap,uint16_t tx_mcs_map,uint16_t rx_mcs_map)2557 static int wifi_send_11ac_cfg_cmd(t_u16 action, uint32_t vhtcap, uint16_t tx_mcs_map, uint16_t rx_mcs_map)
2558 {
2559     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2560     mlan_ds_11ac_vht_cfg dot11ac_cfg;
2561 
2562     (void)memset(&dot11ac_cfg, 0x00, sizeof(mlan_ds_11ac_vht_cfg));
2563 
2564     dot11ac_cfg.band         = 2;
2565     dot11ac_cfg.txrx         = 1;
2566     dot11ac_cfg.vht_cap_info = vhtcap;
2567     dot11ac_cfg.vht_tx_mcs   = tx_mcs_map;
2568     dot11ac_cfg.vht_rx_mcs   = rx_mcs_map;
2569 
2570     if (action != HostCmd_ACT_GEN_GET && action != HostCmd_ACT_GEN_SET)
2571         return -WM_FAIL;
2572 
2573     wifi_get_command_lock();
2574     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
2575 
2576     cmd->seq_num = 0x0;
2577     cmd->result  = 0x0;
2578 
2579     mlan_status rv = wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_11AC_CFG, action, 0, NULL, &dot11ac_cfg, cmd);
2580     if (rv != MLAN_STATUS_SUCCESS)
2581         return -WM_FAIL;
2582 
2583     return wifi_wait_for_cmdresp(NULL);
2584 }
2585 
2586 #endif
2587 
2588 #ifdef STREAM_2X2
wifi_send_rf_antenna_cmd(t_u16 action,uint8_t tx_antenna,uint8_t rx_antenna)2589 static int wifi_send_rf_antenna_cmd(t_u16 action, uint8_t tx_antenna, uint8_t rx_antenna)
2590 {
2591     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2592     mlan_ds_ant_cfg ant_cfg;
2593 
2594     (void)memset(&ant_cfg, 0x00, sizeof(mlan_ds_ant_cfg));
2595 
2596     ant_cfg.tx_antenna = tx_antenna;
2597     ant_cfg.rx_antenna = rx_antenna;
2598 
2599     if (action != HostCmd_ACT_GEN_GET && action != HostCmd_ACT_GEN_SET)
2600         return -WM_FAIL;
2601 
2602     wifi_get_command_lock();
2603     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
2604 
2605     cmd->seq_num = 0x0;
2606     cmd->result  = 0x0;
2607 
2608     mlan_status rv = wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_RF_ANTENNA, action, 0, NULL, &ant_cfg, cmd);
2609     if (rv != MLAN_STATUS_SUCCESS)
2610         return -WM_FAIL;
2611 
2612     return wifi_wait_for_cmdresp(/*action == HostCmd_ACT_GEN_GET ? ant_mode : */ NULL);
2613 }
2614 
2615 #else
2616 
wifi_send_rf_antenna_cmd(t_u16 action,wifi_antcfg_t * wifi_antcfg)2617 static int wifi_send_rf_antenna_cmd(t_u16 action, wifi_antcfg_t *wifi_antcfg)
2618 {
2619     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2620     mlan_ds_ant_cfg_1x1 ant_cfg_1x1;
2621 
2622     (void)memset(&ant_cfg_1x1, 0x00, sizeof(mlan_ds_ant_cfg_1x1));
2623 
2624     ant_cfg_1x1.antenna       = (t_u32) * (wifi_antcfg->ant_mode);
2625     ant_cfg_1x1.evaluate_time = (t_u16) * (wifi_antcfg->evaluate_time);
2626 #ifdef RW610
2627     ant_cfg_1x1.evaluate_mode = (t_u8) * (wifi_antcfg->evaluate_mode);
2628 #endif
2629 
2630     if (action != HostCmd_ACT_GEN_GET && action != HostCmd_ACT_GEN_SET)
2631     {
2632         return -WM_FAIL;
2633     }
2634 
2635     (void)wifi_get_command_lock();
2636     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
2637 
2638     (void)memset(cmd, 0x00, S_DS_GEN + sizeof(HostCmd_DS_802_11_RF_ANTENNA));
2639 
2640     cmd->seq_num = 0x0;
2641     cmd->result  = 0x0;
2642 
2643     mlan_status rv =
2644         wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_RF_ANTENNA, action, 0, NULL, &ant_cfg_1x1, cmd);
2645     if (rv != MLAN_STATUS_SUCCESS)
2646     {
2647         (void)wifi_put_command_lock();
2648         return -WM_FAIL;
2649     }
2650 
2651     (void)wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? wifi_antcfg : NULL);
2652 
2653     return wm_wifi.cmd_resp_status;
2654 }
2655 
2656 #ifndef RW610
wifi_get_antenna(t_u32 * ant_mode,t_u16 * evaluate_time,t_u16 * current_antenna)2657 int wifi_get_antenna(t_u32 *ant_mode, t_u16 *evaluate_time, t_u16 *current_antenna)
2658 #else
2659 int wifi_get_antenna(t_u32 *ant_mode, t_u16 *evaluate_time, t_u8 *evaluate_mode, t_u16 *current_antenna)
2660 #endif
2661 {
2662     if (ant_mode == MNULL)
2663     {
2664         return -WM_E_INVAL;
2665     }
2666 
2667     wifi_antcfg_t antenna_cfg;
2668     antenna_cfg.ant_mode        = ant_mode;
2669     antenna_cfg.evaluate_time   = evaluate_time;
2670 #ifdef RW610
2671     antenna_cfg.evaluate_mode   = evaluate_mode;
2672 #endif
2673     antenna_cfg.current_antenna = current_antenna;
2674 
2675     int rv = wifi_send_rf_antenna_cmd(HostCmd_ACT_GEN_GET, &antenna_cfg);
2676     if (rv != WM_SUCCESS || wm_wifi.cmd_resp_status != WM_SUCCESS)
2677     {
2678         return -WM_FAIL;
2679     }
2680 
2681     return WM_SUCCESS;
2682 }
2683 #endif
2684 
2685 #ifdef STREAM_2X2
wifi_set_11n_cfg(uint16_t httxcfg)2686 int wifi_set_11n_cfg(uint16_t httxcfg)
2687 {
2688     return wifi_send_11n_cfg_cmd(HostCmd_ACT_GEN_SET, httxcfg);
2689 }
2690 
wifi_set_11ac_cfg(uint32_t vhtcap,uint16_t tx_mcs_map,uint16_t rx_mcs_map)2691 int wifi_set_11ac_cfg(uint32_t vhtcap, uint16_t tx_mcs_map, uint16_t rx_mcs_map)
2692 {
2693     return wifi_send_11ac_cfg_cmd(HostCmd_ACT_GEN_SET, vhtcap, tx_mcs_map, rx_mcs_map);
2694 }
2695 
2696 #endif
2697 
2698 #ifdef STREAM_2X2
wifi_set_antenna(t_u8 tx_antenna,t_u8 rx_antenna)2699 int wifi_set_antenna(t_u8 tx_antenna, t_u8 rx_antenna)
2700 {
2701     return wifi_send_rf_antenna_cmd(HostCmd_ACT_GEN_SET, tx_antenna, rx_antenna);
2702 }
2703 #else
2704 #ifndef RW610
wifi_set_antenna(t_u32 ant_mode,t_u16 evaluate_time)2705 int wifi_set_antenna(t_u32 ant_mode, t_u16 evaluate_time)
2706 {
2707     wifi_antcfg_t antenna_cfg;
2708     antenna_cfg.ant_mode      = &ant_mode;
2709     antenna_cfg.evaluate_time = &evaluate_time;
2710 
2711     return wifi_send_rf_antenna_cmd(HostCmd_ACT_GEN_SET, &antenna_cfg);
2712 }
2713 #else
wifi_set_antenna(t_u32 ant_mode,t_u16 evaluate_time,t_u8 evaluate_mode)2714 int wifi_set_antenna(t_u32 ant_mode, t_u16 evaluate_time, t_u8 evaluate_mode)
2715 {
2716     wifi_antcfg_t antenna_cfg;
2717     antenna_cfg.ant_mode      = &ant_mode;
2718     antenna_cfg.evaluate_time = &evaluate_time;
2719     antenna_cfg.evaluate_mode = &evaluate_mode;
2720 
2721     return wifi_send_rf_antenna_cmd(HostCmd_ACT_GEN_SET, &antenna_cfg);
2722 }
2723 #endif /*RW610*/
2724 #endif
2725 
2726 #if CONFIG_WIFI_GET_LOG
wifi_send_get_log_cmd(wlan_pkt_stats_t * stats,mlan_bss_type bss_type)2727 static int wifi_send_get_log_cmd(wlan_pkt_stats_t *stats, mlan_bss_type bss_type)
2728 {
2729     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
2730 
2731     wifi_get_command_lock();
2732     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
2733 
2734     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
2735     cmd->result  = 0x0;
2736 
2737     mlan_status rv =
2738         wlan_ops_sta_prepare_cmd(pmpriv, HostCmd_CMD_802_11_GET_LOG, HostCmd_ACT_GEN_GET, 0, NULL, NULL, cmd);
2739     if (rv != MLAN_STATUS_SUCCESS)
2740         return -WM_FAIL;
2741 
2742     return wifi_wait_for_cmdresp(stats);
2743 }
2744 
wifi_get_log(wlan_pkt_stats_t * stats,mlan_bss_type bss_type)2745 int wifi_get_log(wlan_pkt_stats_t *stats, mlan_bss_type bss_type)
2746 
2747 {
2748     int rv = wifi_send_get_log_cmd(stats, bss_type);
2749     if (rv != WM_SUCCESS || wm_wifi.cmd_resp_status != WM_SUCCESS)
2750         return -WM_FAIL;
2751 
2752     return WM_SUCCESS;
2753 }
2754 #endif
2755 
wifi_send_cmd_802_11_supplicant_pmk(int mode,mlan_ds_sec_cfg * sec,mlan_act_ioctl action)2756 static int wifi_send_cmd_802_11_supplicant_pmk(int mode, mlan_ds_sec_cfg *sec, mlan_act_ioctl action)
2757 {
2758     /* fixme: check if this needs to go on heap */
2759     mlan_ioctl_req req;
2760 
2761     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
2762     req.pbuf      = (t_u8 *)sec;
2763     req.buf_len   = sizeof(mlan_ds_sec_cfg);
2764     req.bss_index = 0;
2765     req.req_id    = MLAN_IOCTL_SEC_CFG;
2766     req.action    = action;
2767 
2768     mlan_status rv = wlan_ops_sta_ioctl(mlan_adap, &req);
2769     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
2770     {
2771         return -WM_FAIL;
2772     }
2773 
2774     return WM_SUCCESS;
2775 }
2776 
wifi_send_add_wpa_pmk(int mode,char * ssid,char * bssid,char * pmk,unsigned int len)2777 int wifi_send_add_wpa_pmk(int mode, char *ssid, char *bssid, char *pmk, unsigned int len)
2778 {
2779     if (ssid == MNULL || (len != MLAN_MAX_KEY_LENGTH))
2780     {
2781         return -WM_E_INVAL;
2782     }
2783 
2784     mlan_ds_sec_cfg sec;
2785 
2786     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2787     sec.sub_command = MLAN_OID_SEC_CFG_PASSPHRASE;
2788 
2789     /* SSID */
2790     int ssid_len = strlen(ssid);
2791     if (ssid_len > MLAN_MAX_SSID_LENGTH)
2792     {
2793         return -WM_E_INVAL;
2794     }
2795 
2796     mlan_ds_passphrase *pp = &sec.param.passphrase;
2797     pp->ssid.ssid_len      = ssid_len;
2798     (void)memcpy((void *)pp->ssid.ssid, (const void *)ssid, ssid_len);
2799 
2800     /* MAC */
2801     if (bssid != NULL)
2802     {
2803         (void)memcpy((void *)pp->bssid, (const void *)bssid, MLAN_MAC_ADDR_LENGTH);
2804     }
2805 
2806     /* PMK */
2807     pp->psk_type = MLAN_PSK_PMK;
2808     (void)memcpy((void *)pp->psk.pmk.pmk, (const void *)pmk, len);
2809 
2810     return wifi_send_cmd_802_11_supplicant_pmk(mode, &sec, MLAN_ACT_SET);
2811 }
2812 
2813 /* fixme: This function has not been tested because of known issue in
2814    calling function. The calling function has been disabled for that */
wifi_send_get_wpa_pmk(int mode,char * ssid)2815 int wifi_send_get_wpa_pmk(int mode, char *ssid)
2816 {
2817     if (ssid == MNULL)
2818     {
2819         return -WM_E_INVAL;
2820     }
2821 
2822     mlan_ds_sec_cfg sec;
2823 
2824     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2825     sec.sub_command = MLAN_OID_SEC_CFG_PASSPHRASE;
2826 
2827     /* SSID */
2828     int ssid_len = strlen(ssid);
2829     if (ssid_len > MLAN_MAX_SSID_LENGTH)
2830     {
2831         return -WM_E_INVAL;
2832     }
2833 
2834     mlan_ds_passphrase *pp = &sec.param.passphrase;
2835     pp->ssid.ssid_len      = ssid_len;
2836     (void)memcpy((void *)pp->ssid.ssid, (const void *)ssid, ssid_len);
2837 
2838     /* Zero MAC */
2839 
2840     pp->psk_type = MLAN_PSK_QUERY;
2841 
2842     return wifi_send_cmd_802_11_supplicant_pmk(mode, &sec, MLAN_ACT_GET);
2843 }
2844 
2845 /*
2846 Note:
2847 Passphrase can be between 8 to 63 if it is ASCII and 64 if its PSK
2848 hexstring
2849 */
wifi_send_add_wpa_psk(int mode,char * ssid,char * passphrase,unsigned int len)2850 int wifi_send_add_wpa_psk(int mode, char *ssid, char *passphrase, unsigned int len)
2851 {
2852     if (ssid == MNULL || ((len < MLAN_MIN_PASSPHRASE_LENGTH) || (len > MLAN_MAX_PASSPHRASE_LENGTH)))
2853     {
2854         return -WM_E_INVAL;
2855     }
2856 
2857     mlan_ds_sec_cfg sec;
2858 
2859     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2860     sec.sub_command = MLAN_OID_SEC_CFG_PASSPHRASE;
2861 
2862     /* SSID */
2863     int ssid_len = strlen(ssid);
2864     if (ssid_len > MLAN_MAX_SSID_LENGTH)
2865     {
2866         return -WM_E_INVAL;
2867     }
2868 
2869     mlan_ds_passphrase *pp = &sec.param.passphrase;
2870     pp->ssid.ssid_len      = ssid_len;
2871     (void)memcpy((void *)pp->ssid.ssid, (const void *)ssid, ssid_len);
2872 
2873     /* Zero MAC */
2874 
2875     /* Passphrase */
2876     pp->psk_type                      = MLAN_PSK_PASSPHRASE;
2877     pp->psk.passphrase.passphrase_len = len;
2878     (void)memcpy((void *)pp->psk.passphrase.passphrase, (const void *)passphrase, len);
2879 
2880     return wifi_send_cmd_802_11_supplicant_pmk(mode, &sec, MLAN_ACT_SET);
2881 }
2882 
2883 /*
2884 Note:
2885 Password can be between 1 to 255 if it is ASCII
2886 */
wifi_send_add_wpa3_password(int mode,char * ssid,char * password,unsigned int len)2887 int wifi_send_add_wpa3_password(int mode, char *ssid, char *password, unsigned int len)
2888 {
2889     if (ssid == MNULL || ((len < MLAN_MIN_PASSWORD_LENGTH) || (len > MLAN_MAX_PASSWORD_LENGTH)))
2890     {
2891         return -WM_E_INVAL;
2892     }
2893 
2894     mlan_ds_sec_cfg sec;
2895 
2896     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2897     sec.sub_command = MLAN_OID_SEC_CFG_PASSWORD;
2898 
2899     /* SSID */
2900     int ssid_len = strlen(ssid);
2901     if (ssid_len > MLAN_MAX_SSID_LENGTH)
2902     {
2903         return -WM_E_INVAL;
2904     }
2905 
2906     mlan_ds_passphrase *pp = &sec.param.passphrase;
2907     pp->ssid.ssid_len      = ssid_len;
2908     (void)memcpy((void *)pp->ssid.ssid, (const void *)ssid, ssid_len);
2909 
2910     /* Zero MAC */
2911 
2912     /* Passphrase */
2913     pp->psk_type              = MLAN_PSK_PASSWORD;
2914     pp->password.password_len = len;
2915     (void)memcpy((void *)pp->password.password, (const void *)password, len);
2916 
2917     return wifi_send_cmd_802_11_supplicant_pmk(mode, &sec, MLAN_ACT_SET);
2918 }
2919 
wifi_send_clear_wpa_psk(int mode,const char * ssid)2920 int wifi_send_clear_wpa_psk(int mode, const char *ssid)
2921 {
2922     if (ssid == MNULL)
2923     {
2924         return -WM_E_INVAL;
2925     }
2926 
2927     mlan_ds_sec_cfg sec;
2928 
2929     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2930     sec.sub_command = MLAN_OID_SEC_CFG_PASSPHRASE;
2931 
2932     /* SSID */
2933     int ssid_len = strlen(ssid);
2934     if (ssid_len > MLAN_MAX_SSID_LENGTH)
2935     {
2936         return -WM_E_INVAL;
2937     }
2938 
2939     sec.param.passphrase.ssid.ssid_len = ssid_len;
2940     (void)strcpy((char *)sec.param.passphrase.ssid.ssid, ssid);
2941 
2942     /* Zero MAC */
2943 
2944     sec.param.passphrase.psk_type = MLAN_PSK_CLEAR;
2945     return wifi_send_cmd_802_11_supplicant_pmk(mode, &sec, MLAN_ACT_SET);
2946 }
2947 
wifi_send_enable_supplicant(int mode,const char * ssid)2948 int wifi_send_enable_supplicant(int mode, const char *ssid)
2949 {
2950     if (ssid == MNULL)
2951     {
2952         return -WM_E_INVAL;
2953     }
2954 
2955     mlan_ds_sec_cfg sec;
2956 
2957     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2958     sec.sub_command = MLAN_OID_SEC_CFG_PASSPHRASE;
2959 
2960     /* SSID */
2961     int ssid_len = strlen(ssid);
2962     if (ssid_len > MLAN_MAX_SSID_LENGTH)
2963     {
2964         return -WM_E_INVAL;
2965     }
2966 
2967     sec.param.passphrase.ssid.ssid_len = ssid_len;
2968     (void)strcpy((char *)sec.param.passphrase.ssid.ssid, ssid);
2969 
2970     /* Zero MAC */
2971 
2972     sec.param.passphrase.psk_type = MLAN_PSK_PASSPHRASE;
2973     return wifi_send_cmd_802_11_supplicant_pmk(mode, &sec, MLAN_ACT_SET);
2974 }
2975 
wifi_send_disable_supplicant(int mode)2976 int wifi_send_disable_supplicant(int mode)
2977 {
2978     mlan_ds_sec_cfg sec;
2979 
2980     (void)memset(&sec, 0x00, sizeof(mlan_ds_sec_cfg));
2981     sec.sub_command = MLAN_OID_SEC_CFG_PASSPHRASE;
2982 
2983     sec.param.passphrase.psk_type = MLAN_PSK_CLEAR;
2984 
2985     return wifi_send_cmd_802_11_supplicant_pmk(mode, &sec, MLAN_ACT_SET);
2986 }
2987 
wifi_set_mac_multicast_addr(const char * mlist,t_u32 num_of_addr)2988 int wifi_set_mac_multicast_addr(const char *mlist, t_u32 num_of_addr)
2989 {
2990     if (mlist == MNULL)
2991     {
2992         return -WM_E_INVAL;
2993     }
2994     if (num_of_addr > MLAN_MAX_MULTICAST_LIST_SIZE)
2995     {
2996         return -WM_E_INVAL;
2997     }
2998 
2999     mlan_multicast_list *mcast_list = (mlan_multicast_list *)OSA_MemoryAllocate(sizeof(mlan_multicast_list));
3000     if(mcast_list == NULL)
3001     {
3002         return -WM_FAIL;
3003     }
3004 
3005     (void)memset(mcast_list, 0x0, sizeof(mlan_multicast_list));
3006     (void)memcpy(mcast_list->mac_list, (const void *)mlist, num_of_addr * MLAN_MAC_ADDR_LENGTH);
3007     mcast_list->num_multicast_addr = num_of_addr;
3008     (void)wifi_get_command_lock();
3009     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
3010 
3011     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_MAC_MULTICAST_ADR,
3012                                               HostCmd_ACT_GEN_SET, 0, NULL, mcast_list, cmd);
3013 
3014     if (rv != MLAN_STATUS_SUCCESS)
3015     {
3016         OSA_MemoryFree(mcast_list);
3017         return -WM_FAIL;
3018     }
3019     (void)wifi_wait_for_cmdresp(NULL);
3020     OSA_MemoryFree(mcast_list);
3021 
3022     return WM_SUCCESS;
3023 }
3024 
wifi_get_otp_user_data(uint8_t * buf,uint16_t len)3025 int wifi_get_otp_user_data(uint8_t *buf, uint16_t len)
3026 {
3027     (void)wifi_get_command_lock();
3028     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
3029     mlan_ds_misc_otp_user_data pdata;
3030 
3031     if (buf == MNULL)
3032     {
3033         return -WM_E_INVAL;
3034     }
3035 
3036     cmd->seq_num           = 0x0;
3037     cmd->result            = 0x0;
3038     pdata.user_data_length = len > MAX_OTP_USER_DATA_LEN ? MAX_OTP_USER_DATA_LEN : len;
3039 
3040     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_OTP_READ_USER_DATA,
3041                                               HostCmd_ACT_GEN_GET, 0, NULL, &pdata, cmd);
3042     if (rv != MLAN_STATUS_SUCCESS)
3043     {
3044         return -WM_FAIL;
3045     }
3046 
3047     (void)wifi_wait_for_cmdresp(buf);
3048     return wm_wifi.cmd_resp_status;
3049 }
3050 
wifi_get_cal_data(wifi_cal_data_t * cal_data)3051 int wifi_get_cal_data(wifi_cal_data_t *cal_data)
3052 {
3053     uint32_t size = S_DS_GEN + sizeof(HostCmd_DS_802_11_CFG_DATA) - 1U;
3054 
3055     (void)wifi_get_command_lock();
3056     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
3057 
3058     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_CFG_DATA);
3059 
3060     HostCmd_DS_802_11_CFG_DATA *cfg_data_cmd = (HostCmd_DS_802_11_CFG_DATA *)((uint32_t)cmd + S_DS_GEN);
3061 
3062     cfg_data_cmd->action   = HostCmd_ACT_GEN_GET;
3063     cfg_data_cmd->type     = 0x02;
3064     cfg_data_cmd->data_len = 0x00;
3065 
3066     cmd->size    = size;
3067     cmd->seq_num = 0x00;
3068     cmd->result  = 0x00;
3069 
3070     (void)wifi_wait_for_cmdresp(cal_data);
3071 
3072     return wm_wifi.cmd_resp_status;
3073 }
3074 
3075 #if CONFIG_11AX
wifi_request_get_fw_info(mlan_private * priv,mlan_fw_info * fw_info)3076 void wifi_request_get_fw_info(mlan_private *priv, mlan_fw_info *fw_info)
3077 {
3078     (void)memset(fw_info, 0x0, sizeof(mlan_fw_info));
3079 
3080     fw_info->fw_ver = mlan_adap->fw_release_number;
3081     (void)memcpy(fw_info->mac_addr, priv->curr_addr, MLAN_MAC_ADDR_LENGTH);
3082     fw_info->fw_bands           = mlan_adap->fw_bands;
3083     fw_info->hw_dev_mcs_support = mlan_adap->hw_dev_mcs_support;
3084 
3085     fw_info->hw_2g_hecap_len = mlan_adap->hw_2g_hecap_len;
3086 
3087     (void)memcpy(fw_info->hw_2g_he_cap, mlan_adap->hw_2g_he_cap, mlan_adap->hw_2g_hecap_len);
3088 
3089     fw_info->hw_hecap_len = mlan_adap->hw_hecap_len;
3090 
3091     (void)memcpy(fw_info->hw_he_cap, mlan_adap->hw_he_cap, mlan_adap->hw_hecap_len);
3092 }
3093 #endif
3094 
3095 #if CONFIG_WIFI_CAPA
wifi_get_fw_info(mlan_bss_type type,t_u16 * fw_bands)3096 void wifi_get_fw_info(mlan_bss_type type, t_u16 *fw_bands)
3097 {
3098     mlan_fw_info fw_info;
3099 
3100     (void)memset(&fw_info, 0x0, sizeof(mlan_fw_info));
3101     fw_info.fw_ver = mlan_adap->fw_release_number;
3102     (void)memcpy(fw_info.mac_addr, mlan_adap->priv[type]->curr_addr, MLAN_MAC_ADDR_LENGTH);
3103     fw_info.fw_bands           = mlan_adap->fw_bands;
3104     fw_info.hw_dev_mcs_support = mlan_adap->hw_dev_mcs_support;
3105 
3106     *fw_bands = fw_info.fw_bands;
3107 }
3108 #endif
3109 
wifi_get_firmware_version_ext(wifi_fw_version_ext_t * version_ext)3110 int wifi_get_firmware_version_ext(wifi_fw_version_ext_t *version_ext)
3111 {
3112     if (version_ext == MNULL)
3113     {
3114         return -WM_E_INVAL;
3115     }
3116 
3117     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
3118     mlan_status rv       = wifi_prepare_and_send_cmd(pmpriv, HostCmd_CMD_VERSION_EXT, HostCmd_ACT_GEN_GET, 0, NULL,
3119                                                      &version_ext->version_str_sel, MLAN_BSS_TYPE_STA, version_ext);
3120     return (rv == MLAN_STATUS_SUCCESS ? WM_SUCCESS : -WM_FAIL);
3121 }
3122 
wifi_get_firmware_version(wifi_fw_version_t * ver)3123 int wifi_get_firmware_version(wifi_fw_version_t *ver)
3124 {
3125     if (ver == MNULL)
3126     {
3127         return -WM_E_INVAL;
3128     }
3129 
3130     union
3131     {
3132         uint32_t l;
3133         uint8_t c[4];
3134     } u_ver;
3135     char fw_ver[32];
3136 
3137     u_ver.l = mlan_adap->fw_release_number;
3138     (void)sprintf(fw_ver, "%u.%u.%u.p%u", u_ver.c[2], u_ver.c[1], u_ver.c[0], u_ver.c[3]);
3139 
3140     (void)snprintf(ver->version_str, MLAN_MAX_VER_STR_LEN, driver_version_format, fw_ver, driver_version);
3141 
3142     return WM_SUCCESS;
3143 }
3144 
3145 /* Region: US(US) or Canada(CA) or Singapore(SG) 2.4 GHz */
3146 static wifi_sub_band_set_t subband_US_CA_SG_2_4_GHz[] = {{1, 11, 20}};
3147 
3148 /* Region: Europe(EU), Australia(AU), Republic of Korea(KR),
3149 China(CN) 2.4 GHz */
3150 static wifi_sub_band_set_t subband_EU_AU_KR_CN_2_4GHz[] = {{1, 13, 20}};
3151 
3152 /* Region: Japan(JP) 2.4 GHz */
3153 static wifi_sub_band_set_t subband_JP_2_4GHz[] = {
3154     {1, 14, 20},
3155 };
3156 
3157 /* Region: World Wide Safe Mode(WWSM) 2.4 GHz */
3158 static wifi_sub_band_set_t subband_WWSM_2_4GHz[] = {
3159     {1, 14, 22},
3160 };
3161 
3162 /* Region: Constrained 2.4 Ghz */
3163 static wifi_sub_band_set_t subband_CS_2_4GHz[] = {{1, 9, 20}, {10, 2, 10}};
3164 
3165 #if CONFIG_5GHz_SUPPORT
3166 
3167 #if (CONFIG_UNII4_BAND_SUPPORT)
3168 /* Region: US(US) 5 GHz */
3169 wifi_sub_band_set_t subband_US_5_GHz[] = {{36, 8, 20}, {100, 11, 20}, {149, 8, 20}};
3170 
3171 /* Region: France(FR) or Singapore(SG) 5 GHz */
3172 wifi_sub_band_set_t subband_SG_FR_5_GHz[] = {{36, 8, 20}, {100, 11, 20}, {149, 5, 20}};
3173 #else
3174 /* Region: US(US) or France(FR) or Singapore(SG) 5 GHz */
3175 static wifi_sub_band_set_t subband_US_SG_FR_5_GHz[] = {{36, 8, 20}, {100, 11, 20}, {149, 5, 20}};
3176 #endif
3177 
3178 /* Region: Canada(CA) 5 GHz */
3179 static wifi_sub_band_set_t subband_CA_5_GHz[] = {{36, 8, 20}, {100, 5, 20}, {132, 3, 20}, {149, 5, 20}};
3180 
3181 /* Region: Region: Europe(EU), Australia(AU), Republic of Korea(KR)
3182  * 5 GHz */
3183 static wifi_sub_band_set_t subband_EU_AU_KR_5_GHz[] = {
3184     {36, 8, 20},
3185     {100, 11, 20},
3186     {149, 5, 20},
3187 };
3188 
3189 /* Region: Japan(JP) 5 GHz */
3190 static wifi_sub_band_set_t subband_JP_5_GHz[] = {
3191     {8, 3, 23},
3192     {36, 8, 23},
3193     {100, 11, 23},
3194 };
3195 
3196 /* Region: China(CN) 5 Ghz */
3197 static wifi_sub_band_set_t subband_CN_5_GHz[] = {
3198     {36, 4, 23},
3199     {52, 4, 23},
3200     {149, 5, 33},
3201 };
3202 
3203 /* Region: World Wide Safe Mode(WWSM) 5 GHz */
3204 static wifi_sub_band_set_t subband_WWSM_5_GHz[] = {{36, 8, 22}, {100, 11, 22}, {149, 5, 22}};
3205 
3206 #endif /* CONFIG_5GHz_SUPPORT */
3207 
wifi_get_region_code(t_u32 * region_code)3208 int wifi_get_region_code(t_u32 *region_code)
3209 {
3210     *region_code = mlan_adap->region_code;
3211     return WM_SUCCESS;
3212 }
3213 
wifi_set_region_code(t_u32 region_code)3214 int wifi_set_region_code(t_u32 region_code)
3215 {
3216     mlan_ds_misc_cfg misc = {
3217         .param.region_code = region_code,
3218     };
3219 
3220     if ((misc.param.region_code == 0x41) || (misc.param.region_code == 0xFE))
3221     {
3222         (void)PRINTF("Region code 0XFF is used for Japan to support channels of both 2.4GHz band and 5GHz band.\r\n");
3223         (void)PRINTF("Region code 0X40 is used for Japan to support channels of 5GHz band.\r\n");
3224         return -WM_FAIL;
3225     }
3226 
3227     mlan_ioctl_req req = {
3228         .bss_index = 0,
3229         .pbuf      = (t_u8 *)&misc,
3230         .action    = MLAN_ACT_SET,
3231     };
3232 
3233     mlan_status mrv = wlan_misc_ioctl_region(mlan_adap, &req);
3234     if (mrv != MLAN_STATUS_SUCCESS)
3235     {
3236         wifi_w("Unable to set region code");
3237         return -WM_FAIL;
3238     }
3239 
3240     return WM_SUCCESS;
3241 }
3242 
wifi_enable_11d_support()3243 int wifi_enable_11d_support()
3244 {
3245     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
3246 
3247     wrapper_wlan_11d_enable(ENABLE_11D);
3248 
3249     wlan_11d_support_APIs(pmpriv);
3250 
3251     return wlan_enable_11d_support(pmpriv);
3252 }
3253 
wifi_enable_uap_11d_support()3254 int wifi_enable_uap_11d_support()
3255 {
3256     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[1];
3257 
3258     wrapper_wlan_uap_11d_enable(ENABLE_11D);
3259 
3260     wlan_11d_support_APIs(pmpriv);
3261 
3262     /* set callback for setting domain params when uap start */
3263     wifi_uap_enable_11d_support();
3264 
3265     return wlan_enable_11d_support(pmpriv);
3266 }
3267 
wifi_disable_11d_support()3268 int wifi_disable_11d_support()
3269 {
3270     mlan_adap->priv[0]->state_11d.user_enable_11d_support = DISABLE_11D;
3271     wrapper_wlan_11d_enable(DISABLE_11D);
3272 
3273     return WM_SUCCESS;
3274 }
3275 
wifi_disable_uap_11d_support()3276 int wifi_disable_uap_11d_support()
3277 {
3278     mlan_adap->priv[1]->state_11d.user_enable_11d_support = DISABLE_11D;
3279     wrapper_wlan_uap_11d_enable(DISABLE_11D);
3280 
3281     wm_wifi.enable_11d_support   = false;
3282     wm_wifi.uap_support_11d_apis = MNULL;
3283     return WM_SUCCESS;
3284 }
3285 
wifi_enable_11d_support_APIs(void)3286 int wifi_enable_11d_support_APIs(void)
3287 {
3288     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
3289 
3290     return wlan_11d_support_APIs(pmpriv);
3291 }
3292 
get_sub_band_from_region_code(int region_code,t_u8 * nr_sb)3293 wifi_sub_band_set_t *get_sub_band_from_region_code(int region_code, t_u8 *nr_sb)
3294 {
3295     *nr_sb                        = 1;
3296     wifi_sub_band_set_t *ret_band = NULL;
3297 
3298     switch (region_code)
3299     {
3300         case 0x10:
3301         case 0x20:
3302             ret_band = subband_US_CA_SG_2_4_GHz;
3303             break;
3304         case 0x30:
3305         case 0x32:
3306         case 0x50:
3307             ret_band = subband_EU_AU_KR_CN_2_4GHz;
3308             break;
3309         case 0xFF:
3310             ret_band = subband_JP_2_4GHz;
3311             break;
3312         case 0x00:
3313             ret_band = subband_WWSM_2_4GHz;
3314             break;
3315         default:
3316             *nr_sb   = 2;
3317             ret_band = subband_CS_2_4GHz;
3318             break;
3319     }
3320     return ret_band;
3321 }
3322 
3323 #if CONFIG_5GHz_SUPPORT
get_sub_band_from_region_code_5ghz(int region_code,t_u8 * nr_sb)3324 wifi_sub_band_set_t *get_sub_band_from_region_code_5ghz(int region_code, t_u8 *nr_sb)
3325 {
3326     *nr_sb                        = 1;
3327     wifi_sub_band_set_t *ret_band = NULL;
3328 
3329     switch (region_code)
3330     {
3331         case 0x10:
3332 #if (CONFIG_UNII4_BAND_SUPPORT)
3333             *nr_sb = 3;
3334             return subband_US_5_GHz;
3335 #endif
3336         case 0x32:
3337             *nr_sb = 3;
3338 #if (CONFIG_UNII4_BAND_SUPPORT)
3339             ret_band = subband_SG_FR_5_GHz;
3340 #else
3341             ret_band = subband_US_SG_FR_5_GHz;
3342 #endif
3343             break;
3344         case 0x20:
3345             *nr_sb   = 4;
3346             ret_band = subband_CA_5_GHz;
3347             break;
3348         case 0x30:
3349             *nr_sb   = 3;
3350             ret_band = subband_EU_AU_KR_5_GHz;
3351             break;
3352         case 0x40:
3353         case 0xFF:
3354             *nr_sb   = 3;
3355             ret_band = subband_JP_5_GHz;
3356             break;
3357         case 0x50:
3358             *nr_sb   = 3;
3359             ret_band = subband_CN_5_GHz;
3360             break;
3361         case 0x00:
3362             *nr_sb   = 3;
3363             ret_band = subband_WWSM_5_GHz;
3364             break;
3365         default:
3366             *nr_sb = 3;
3367 #if (CONFIG_UNII4_BAND_SUPPORT)
3368             ret_band = subband_US_5_GHz;
3369 #else
3370             ret_band = subband_US_SG_FR_5_GHz;
3371 #endif
3372             break;
3373     }
3374     return ret_band;
3375 }
3376 #endif /* CONFIG_5GHz_SUPPORT */
3377 
wifi_11d_is_channel_allowed(int channel)3378 bool wifi_11d_is_channel_allowed(int channel)
3379 {
3380     t_u8 i, j;
3381     t_u8 k;
3382     t_u8 nr_sb = 0;
3383 
3384     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
3385 
3386     wifi_sub_band_set_t *sub_band = NULL;
3387 
3388     if (channel > 14)
3389     {
3390 #if CONFIG_5GHz_SUPPORT
3391         sub_band = get_sub_band_from_region_code_5ghz(pmpriv->adapter->region_code, &nr_sb);
3392 #else
3393         wifi_w("5 GHz support is not enabled");
3394 
3395         return false;
3396 #endif /* CONFIG_5GHz_SUPPORT */
3397     }
3398     else
3399     {
3400         sub_band = get_sub_band_from_region_code(pmpriv->adapter->region_code, &nr_sb);
3401     }
3402 
3403     for (i = 0; i < nr_sb; i++)
3404     {
3405         j = sub_band[i].first_chan;
3406 
3407         for (k = 0; k < sub_band[i].no_of_chan; k++)
3408         {
3409             if (j == channel)
3410             {
3411                 return true;
3412             }
3413 
3414             if (channel > 14)
3415             {
3416                 j += 4;
3417             }
3418             else
3419             {
3420                 j++;
3421             }
3422         }
3423     }
3424 
3425     /*For channel 144*/
3426     if (144 == channel)
3427     {
3428         return wlan_check_channel_by_region_table(pmpriv, channel);
3429     }
3430 
3431     return false;
3432 }
3433 
wifi_enable_ecsa_support(void)3434 int wifi_enable_ecsa_support(void)
3435 {
3436     return wrapper_wlan_ecsa_enable();
3437 }
3438 
wifi_is_ecsa_enabled(void)3439 bool wifi_is_ecsa_enabled(void)
3440 {
3441     return mlan_adap->ecsa_enable;
3442 }
3443 
get_free_mgmt_ie_index(unsigned int * mgmt_ie_index)3444 static int get_free_mgmt_ie_index(unsigned int *mgmt_ie_index)
3445 {
3446     unsigned int idx;
3447 
3448     for (idx = 0; idx < 32; idx++)
3449     {
3450         if ((mgmt_ie_index_bitmap & MBIT((t_u32)idx)) == 0U)
3451         {
3452             *mgmt_ie_index = idx;
3453             return WM_SUCCESS;
3454         }
3455     }
3456     return -WM_FAIL;
3457 }
3458 
set_ie_index(unsigned int index)3459 static void set_ie_index(unsigned int index)
3460 {
3461     mgmt_ie_index_bitmap |= (MBIT(index));
3462 }
3463 
clear_ie_index(unsigned int index)3464 static void clear_ie_index(unsigned int index)
3465 {
3466     mgmt_ie_index_bitmap &= ~(MBIT(index));
3467 }
3468 
3469 #ifdef SD8801
wifi_config_ext_coex(int action,const wifi_ext_coex_config_t * ext_coex_config,wifi_ext_coex_stats_t * ext_coex_stats)3470 static int wifi_config_ext_coex(int action,
3471                                 const wifi_ext_coex_config_t *ext_coex_config,
3472                                 wifi_ext_coex_stats_t *ext_coex_stats)
3473 {
3474     int ret;
3475     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
3476 
3477     (void)wifi_get_command_lock();
3478 
3479     cmd->command                                           = HostCmd_CMD_ROBUST_COEX;
3480     cmd->size                                              = sizeof(HostCmd_DS_ExtBLECoex_Config_t) + S_DS_GEN;
3481     cmd->seq_num                                           = 0;
3482     cmd->result                                            = 0;
3483     cmd->params.ext_ble_coex_cfg.action                    = action;
3484     cmd->params.ext_ble_coex_cfg.reserved                  = 0;
3485     cmd->params.ext_ble_coex_cfg.coex_cfg_data.header.type = TLV_TYPE_EXT_BLE_COEX_CFG;
3486     cmd->params.ext_ble_coex_cfg.coex_cfg_data.header.len =
3487         sizeof(MrvlIETypes_ExtBLECoex_Config_t) - sizeof(MrvlIEtypesHeader_t);
3488 
3489     if (action == HostCmd_ACT_GEN_SET)
3490     {
3491         cmd->params.ext_ble_coex_cfg.coex_cfg_data.Enabled         = ext_coex_config->Enabled;
3492         cmd->params.ext_ble_coex_cfg.coex_cfg_data.IgnorePriority  = ext_coex_config->IgnorePriority;
3493         cmd->params.ext_ble_coex_cfg.coex_cfg_data.DefaultPriority = ext_coex_config->DefaultPriority;
3494         cmd->params.ext_ble_coex_cfg.coex_cfg_data.EXT_RADIO_REQ_ip_gpio_num =
3495             ext_coex_config->EXT_RADIO_REQ_ip_gpio_num;
3496         cmd->params.ext_ble_coex_cfg.coex_cfg_data.EXT_RADIO_REQ_ip_gpio_polarity =
3497             ext_coex_config->EXT_RADIO_REQ_ip_gpio_polarity;
3498         cmd->params.ext_ble_coex_cfg.coex_cfg_data.EXT_RADIO_PRI_ip_gpio_num =
3499             ext_coex_config->EXT_RADIO_PRI_ip_gpio_num;
3500         cmd->params.ext_ble_coex_cfg.coex_cfg_data.EXT_RADIO_PRI_ip_gpio_polarity =
3501             ext_coex_config->EXT_RADIO_PRI_ip_gpio_polarity;
3502         cmd->params.ext_ble_coex_cfg.coex_cfg_data.WLAN_GRANT_op_gpio_num = ext_coex_config->WLAN_GRANT_op_gpio_num;
3503         cmd->params.ext_ble_coex_cfg.coex_cfg_data.WLAN_GRANT_op_gpio_polarity =
3504             ext_coex_config->WLAN_GRANT_op_gpio_polarity;
3505         cmd->params.ext_ble_coex_cfg.coex_cfg_data.reserved_1 = ext_coex_config->reserved_1;
3506         cmd->params.ext_ble_coex_cfg.coex_cfg_data.reserved_2 = ext_coex_config->reserved_2;
3507     }
3508     ret = wifi_wait_for_cmdresp(ext_coex_stats);
3509     return ret;
3510 }
3511 #endif
3512 
ie_index_is_set(unsigned int index)3513 static bool ie_index_is_set(unsigned int index)
3514 {
3515     return (mgmt_ie_index_bitmap & (MBIT(index))) ? MTRUE : MFALSE;
3516 }
3517 
reset_ie_index()3518 void reset_ie_index()
3519 {
3520     mgmt_ie_index_bitmap = 0x0000000F;
3521 }
3522 
wifi_config_mgmt_ie(mlan_bss_type bss_type,t_u16 action,IEEEtypes_ElementId_t index,void * buffer,unsigned int * ie_len,int mgmt_bitmap_index)3523 static int wifi_config_mgmt_ie(mlan_bss_type bss_type,
3524                                t_u16 action,
3525                                IEEEtypes_ElementId_t index,
3526                                void *buffer,
3527                                unsigned int *ie_len,
3528                                int mgmt_bitmap_index)
3529 {
3530     uint8_t *buf, *pos;
3531     IEEEtypes_Header_t *ptlv_header = NULL;
3532     uint16_t buf_len                = 0;
3533     tlvbuf_custom_ie *tlv           = NULL;
3534     custom_ie *ie_ptr               = NULL;
3535     unsigned int mgmt_ie_index      = -1;
3536     int total_len =
3537         sizeof(tlvbuf_custom_ie) + 2U * (sizeof(custom_ie) - MAX_IE_SIZE) + sizeof(IEEEtypes_Header_t) + *ie_len;
3538     int ret = WM_SUCCESS;
3539 
3540 #if !CONFIG_MEM_POOLS
3541     buf = (uint8_t *)OSA_MemoryAllocate(total_len);
3542 #else
3543     buf = OSA_MemoryPoolAllocate(buf_512_MemoryPool);
3544 #endif
3545     if (buf == MNULL)
3546     {
3547         wifi_e("Cannot allocate memory");
3548         return -WM_FAIL;
3549     }
3550 
3551     (void)memset(buf, 0, total_len);
3552 
3553     tlv       = (tlvbuf_custom_ie *)(void *)buf;
3554     tlv->type = MRVL_MGMT_IE_LIST_TLV_ID;
3555 
3556     /* Locate headers */
3557     ie_ptr = (custom_ie *)(tlv->ie_data);
3558     /* Set TLV fields */
3559     buf_len = sizeof(tlvbuf_custom_ie);
3560 
3561     if (action == HostCmd_ACT_GEN_SET)
3562     {
3563         if (*ie_len == 0U)
3564         {
3565             /*
3566                MGMT_WPA_IE = MGMT_VENDOR_SPECIFIC_221
3567                MGMT_WPS_IE = MGMT_VENDOR_SPECIFIC_221
3568                */
3569 
3570             if (!ie_index_is_set(mgmt_bitmap_index))
3571             {
3572 #if !CONFIG_MEM_POOLS
3573                 OSA_MemoryFree(buf);
3574 #else
3575                 OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3576 #endif
3577                 return -WM_FAIL;
3578             }
3579 
3580             ie_ptr->mgmt_subtype_mask = MGMT_MASK_CLEAR;
3581             ie_ptr->ie_length         = 0;
3582             ie_ptr->ie_index          = (t_u16)mgmt_bitmap_index;
3583 
3584             tlv->length = sizeof(custom_ie) - MAX_IE_SIZE;
3585             buf_len += tlv->length;
3586             clear_ie_index(mgmt_bitmap_index);
3587         }
3588         else
3589         {
3590             ret = get_free_mgmt_ie_index(&mgmt_ie_index);
3591 
3592             if (WM_SUCCESS != ret)
3593             {
3594 #if !CONFIG_MEM_POOLS
3595                 OSA_MemoryFree(buf);
3596 #else
3597                 OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3598 #endif
3599                 return -WM_FAIL;
3600             }
3601 
3602             pos         = ie_ptr->ie_buffer;
3603             ptlv_header = (IEEEtypes_Header_t *)(void *)pos;
3604             pos += sizeof(IEEEtypes_Header_t);
3605 
3606             ptlv_header->element_id = (IEEEtypes_ElementId_e)index;
3607             ptlv_header->len        = *ie_len;
3608             if (bss_type == MLAN_BSS_TYPE_UAP)
3609             {
3610                 ie_ptr->mgmt_subtype_mask =
3611                     MGMT_MASK_BEACON | MGMT_MASK_PROBE_RESP | MGMT_MASK_ASSOC_RESP | MGMT_MASK_REASSOC_RESP;
3612             }
3613             else if (bss_type == MLAN_BSS_TYPE_STA)
3614             {
3615                 ie_ptr->mgmt_subtype_mask = MGMT_MASK_PROBE_REQ | MGMT_MASK_ASSOC_REQ | MGMT_MASK_REASSOC_REQ;
3616             }
3617             else
3618             { /* Do Nothing */
3619             }
3620 
3621             tlv->length       = sizeof(custom_ie) + sizeof(IEEEtypes_Header_t) + *ie_len - MAX_IE_SIZE;
3622             ie_ptr->ie_length = sizeof(IEEEtypes_Header_t) + *ie_len;
3623             ie_ptr->ie_index  = mgmt_ie_index;
3624 
3625             buf_len += tlv->length;
3626 
3627             (void)memcpy((void *)pos, (const void *)buffer, *ie_len);
3628         }
3629     }
3630     else if (action == HostCmd_ACT_GEN_GET)
3631     {
3632         /* Get WPS IE */
3633         tlv->length = 0;
3634     }
3635     else
3636     { /* Do Nothing */
3637     }
3638 
3639     mlan_status rv = wrapper_wlan_cmd_mgmt_ie(bss_type, buf, buf_len, action);
3640 
3641     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
3642     {
3643 #if !CONFIG_MEM_POOLS
3644         OSA_MemoryFree(buf);
3645 #else
3646         OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3647 #endif
3648         return -WM_FAIL;
3649     }
3650 
3651     if (action == HostCmd_ACT_GEN_GET)
3652     {
3653         if (wm_wifi.cmd_resp_status != 0)
3654         {
3655             wifi_w("Unable to get mgmt ie buffer");
3656 #if !CONFIG_MEM_POOLS
3657             OSA_MemoryFree(buf);
3658 #else
3659             OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3660 #endif
3661             return wm_wifi.cmd_resp_status;
3662         }
3663         ie_ptr = (custom_ie *)(void *)(buf);
3664         (void)memcpy((void *)buffer, (const void *)ie_ptr->ie_buffer, ie_ptr->ie_length);
3665         *ie_len = ie_ptr->ie_length;
3666     }
3667 #if !CONFIG_MEM_POOLS
3668     OSA_MemoryFree(buf);
3669 #else
3670     OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3671 #endif
3672 
3673     if ((action == HostCmd_ACT_GEN_SET) && *ie_len)
3674     {
3675         set_ie_index(mgmt_ie_index);
3676         return mgmt_ie_index;
3677     }
3678     else
3679     {
3680         return WM_SUCCESS;
3681     }
3682 }
3683 
wifi_get_mgmt_ie(mlan_bss_type bss_type,IEEEtypes_ElementId_t index,void * buf,unsigned int * buf_len)3684 int wifi_get_mgmt_ie(mlan_bss_type bss_type, IEEEtypes_ElementId_t index, void *buf, unsigned int *buf_len)
3685 {
3686     return wifi_config_mgmt_ie(bss_type, HostCmd_ACT_GEN_GET, index, buf, buf_len, 0);
3687 }
3688 
wifi_set_mgmt_ie(mlan_bss_type bss_type,IEEEtypes_ElementId_t id,void * buf,unsigned int buf_len)3689 int wifi_set_mgmt_ie(mlan_bss_type bss_type, IEEEtypes_ElementId_t id, void *buf, unsigned int buf_len)
3690 {
3691     unsigned int data_len = buf_len;
3692 
3693     return wifi_config_mgmt_ie(bss_type, HostCmd_ACT_GEN_SET, id, buf, &data_len, 0);
3694 }
3695 
wifi_clear_mgmt_ie(mlan_bss_type bss_type,IEEEtypes_ElementId_t index,int mgmt_bitmap_index)3696 int wifi_clear_mgmt_ie(mlan_bss_type bss_type, IEEEtypes_ElementId_t index, int mgmt_bitmap_index)
3697 {
3698     unsigned int data_len = 0;
3699     return wifi_config_mgmt_ie(bss_type, HostCmd_ACT_GEN_SET, index, NULL, &data_len, mgmt_bitmap_index);
3700 }
3701 
wifi_config_mgmt_ie2(mlan_bss_type bss_type,t_u16 action,t_u16 mask,void * buffer,unsigned int * ie_len,int mgmt_bitmap_index)3702 static int wifi_config_mgmt_ie2(
3703     mlan_bss_type bss_type, t_u16 action, t_u16 mask, void *buffer, unsigned int *ie_len, int mgmt_bitmap_index)
3704 {
3705     uint8_t *buf;
3706     uint16_t buf_len           = 0;
3707     tlvbuf_custom_ie *tlv      = NULL;
3708     custom_ie *ie_ptr          = NULL;
3709     unsigned int mgmt_ie_index = -1;
3710     int total_len              = sizeof(tlvbuf_custom_ie) + (sizeof(custom_ie) - MAX_IE_SIZE) + *ie_len;
3711     int ret                    = WM_SUCCESS;
3712 
3713 #if !CONFIG_MEM_POOLS
3714     buf = (uint8_t *)OSA_MemoryAllocate(total_len);
3715 #else
3716     buf = OSA_MemoryPoolAllocate(buf_512_MemoryPool);
3717 #endif
3718     if (buf == MNULL)
3719     {
3720         wifi_e("Cannot allocate memory");
3721         return -WM_FAIL;
3722     }
3723 
3724     (void)memset(buf, 0, total_len);
3725 
3726     tlv       = (tlvbuf_custom_ie *)(void *)buf;
3727     tlv->type = MRVL_MGMT_IE_LIST_TLV_ID;
3728 
3729     /* Locate headers */
3730     ie_ptr = (custom_ie *)(tlv->ie_data);
3731     /* Set TLV fields */
3732     buf_len = sizeof(tlvbuf_custom_ie);
3733 
3734     if (action == HostCmd_ACT_GEN_SET)
3735     {
3736         if (*ie_len == 0U)
3737         {
3738             /*
3739                MGMT_WPA_IE = MGMT_VENDOR_SPECIFIC_221
3740                MGMT_WPS_IE = MGMT_VENDOR_SPECIFIC_221
3741                */
3742 
3743             if (!ie_index_is_set(mgmt_bitmap_index))
3744             {
3745 #if !CONFIG_MEM_POOLS
3746                 OSA_MemoryFree(buf);
3747 #else
3748                 OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3749 #endif
3750                 return -WM_FAIL;
3751             }
3752 
3753             ie_ptr->mgmt_subtype_mask = MGMT_MASK_CLEAR;
3754             ie_ptr->ie_length         = 0;
3755             ie_ptr->ie_index          = (t_u16)mgmt_bitmap_index;
3756 
3757             tlv->length = sizeof(custom_ie) - MAX_IE_SIZE;
3758             buf_len += tlv->length;
3759             clear_ie_index(mgmt_bitmap_index);
3760         }
3761         else
3762         {
3763             ret = get_free_mgmt_ie_index(&mgmt_ie_index);
3764 
3765             if (WM_SUCCESS != ret)
3766             {
3767 #if !CONFIG_MEM_POOLS
3768                 OSA_MemoryFree(buf);
3769 #else
3770                 OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3771 #endif
3772                 return -WM_FAIL;
3773             }
3774 
3775             tlv->length      = (sizeof(custom_ie) - MAX_IE_SIZE) + *ie_len;
3776             ie_ptr->ie_index = mgmt_ie_index;
3777 
3778             ie_ptr->mgmt_subtype_mask = mask;
3779 
3780             ie_ptr->ie_length = *ie_len;
3781 
3782             buf_len += tlv->length;
3783 
3784             (void)memcpy((void *)&ie_ptr->ie_buffer, (const void *)buffer, *ie_len);
3785         }
3786     }
3787     else if (action == HostCmd_ACT_GEN_GET)
3788     {
3789         /* Get WPS IE */
3790         tlv->length = 0;
3791     }
3792     else
3793     { /* Do Nothing */
3794     }
3795 
3796     mlan_status rv = wrapper_wlan_cmd_mgmt_ie(bss_type, buf, buf_len, action);
3797 
3798     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
3799     {
3800 #if !CONFIG_MEM_POOLS
3801         OSA_MemoryFree(buf);
3802 #else
3803         OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3804 #endif
3805         return -WM_FAIL;
3806     }
3807 
3808     if (action == HostCmd_ACT_GEN_GET)
3809     {
3810         if (wm_wifi.cmd_resp_status != 0)
3811         {
3812             wifi_w("Unable to get mgmt ie buffer");
3813 #if !CONFIG_MEM_POOLS
3814             OSA_MemoryFree(buf);
3815 #else
3816             OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3817 #endif
3818             return wm_wifi.cmd_resp_status;
3819         }
3820         ie_ptr = (custom_ie *)(void *)(buf);
3821         (void)memcpy((void *)buffer, (const void *)ie_ptr->ie_buffer, ie_ptr->ie_length);
3822         *ie_len = ie_ptr->ie_length;
3823     }
3824 
3825 #if !CONFIG_MEM_POOLS
3826     OSA_MemoryFree(buf);
3827 #else
3828     OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
3829 #endif
3830 
3831     if ((action == HostCmd_ACT_GEN_SET) && *ie_len)
3832     {
3833         set_ie_index(mgmt_ie_index);
3834         return mgmt_ie_index;
3835     }
3836     else
3837     {
3838         return WM_SUCCESS;
3839     }
3840 }
3841 
wifi_get_mgmt_ie2(mlan_bss_type bss_type,void * buf,unsigned int * buf_len)3842 int wifi_get_mgmt_ie2(mlan_bss_type bss_type, void *buf, unsigned int *buf_len)
3843 {
3844     return wifi_config_mgmt_ie2(bss_type, HostCmd_ACT_GEN_GET, 0, buf, buf_len, 0);
3845 }
3846 
wifi_set_mgmt_ie2(mlan_bss_type bss_type,unsigned short mask,void * buf,unsigned int buf_len)3847 int wifi_set_mgmt_ie2(mlan_bss_type bss_type, unsigned short mask, void *buf, unsigned int buf_len)
3848 {
3849     unsigned int data_len = buf_len;
3850 
3851     return wifi_config_mgmt_ie2(bss_type, HostCmd_ACT_GEN_SET, mask, buf, &data_len, 0);
3852 }
3853 
wifi_clear_mgmt_ie2(mlan_bss_type bss_type,int mgmt_bitmap_index)3854 int wifi_clear_mgmt_ie2(mlan_bss_type bss_type, int mgmt_bitmap_index)
3855 {
3856     unsigned int data_len = 0;
3857 
3858     return wifi_config_mgmt_ie2(bss_type, HostCmd_ACT_GEN_SET, 0, NULL, &data_len, mgmt_bitmap_index);
3859 }
3860 
3861 #ifdef SD8801
wifi_get_ext_coex_stats(wifi_ext_coex_stats_t * ext_coex_stats)3862 int wifi_get_ext_coex_stats(wifi_ext_coex_stats_t *ext_coex_stats)
3863 {
3864     if (ext_coex_stats == NULL)
3865     {
3866         wifi_e("Invalid structure passed");
3867         return -WM_FAIL;
3868     }
3869 
3870     return wifi_config_ext_coex(HostCmd_ACT_GEN_GET, NULL, ext_coex_stats);
3871 }
3872 
wifi_set_ext_coex_config(const wifi_ext_coex_config_t * ext_coex_config)3873 int wifi_set_ext_coex_config(const wifi_ext_coex_config_t *ext_coex_config)
3874 {
3875     if (ext_coex_config == NULL)
3876     {
3877         wifi_e("Invalid structure passed");
3878         return -WM_FAIL;
3879     }
3880 
3881     return wifi_config_ext_coex(HostCmd_ACT_GEN_SET, ext_coex_config, NULL);
3882 }
3883 #endif
3884 
3885 #if CONFIG_WPA_SUPP
wifi_set_custom_ie(custom_ie * beacon_ies_data,custom_ie * beacon_wps_ies_data,custom_ie * proberesp_ies_data,custom_ie * assocresp_ies_data)3886 int wifi_set_custom_ie(custom_ie *beacon_ies_data,
3887                        custom_ie *beacon_wps_ies_data,
3888                        custom_ie *proberesp_ies_data,
3889                        custom_ie *assocresp_ies_data)
3890 {
3891     mlan_ds_misc_custom_ie *pcustom_ie = NULL;
3892     t_u8 *pos                          = NULL;
3893     t_u16 len                          = 0;
3894     mlan_status status                 = MLAN_STATUS_SUCCESS;
3895     t_u32 remain_len                   = 0;
3896     HostCmd_DS_COMMAND *cmd            = NULL;
3897 
3898     ENTER();
3899 
3900     pcustom_ie = OSA_MemoryAllocate(sizeof(mlan_ds_misc_custom_ie));
3901     if (!pcustom_ie)
3902     {
3903         PRINTM(MERROR, "Fail to allocate custome_ie\n");
3904         status = MLAN_STATUS_FAILURE;
3905         goto done;
3906     }
3907 
3908     pcustom_ie->type = TLV_TYPE_MGMT_IE;
3909 
3910     pos        = (t_u8 *)pcustom_ie->ie_data_list;
3911     remain_len = sizeof(pcustom_ie->ie_data_list);
3912     if (beacon_ies_data)
3913     {
3914         len = sizeof(*beacon_ies_data) - MAX_IE_SIZE + beacon_ies_data->ie_length;
3915         memcpy(pos, beacon_ies_data, len);
3916         pos += len;
3917         remain_len -= len;
3918         pcustom_ie->len += len;
3919     }
3920 
3921     if (beacon_wps_ies_data)
3922     {
3923         len = sizeof(*beacon_wps_ies_data) - MAX_IE_SIZE + beacon_wps_ies_data->ie_length;
3924         memcpy(pos, beacon_wps_ies_data, len);
3925         pos += len;
3926         remain_len -= len;
3927         pcustom_ie->len += len;
3928     }
3929 
3930     if (proberesp_ies_data)
3931     {
3932         len = sizeof(*proberesp_ies_data) - MAX_IE_SIZE + proberesp_ies_data->ie_length;
3933         memcpy(pos, proberesp_ies_data, len);
3934         pos += len;
3935         remain_len -= len;
3936         pcustom_ie->len += len;
3937     }
3938 
3939     if (assocresp_ies_data)
3940     {
3941         len = sizeof(*assocresp_ies_data) - MAX_IE_SIZE + assocresp_ies_data->ie_length;
3942         memcpy(pos, assocresp_ies_data, len);
3943         pos += len;
3944         remain_len -= len;
3945         pcustom_ie->len += len;
3946     }
3947 
3948     (void)wifi_get_command_lock();
3949 
3950     cmd = wifi_get_command_buffer();
3951 
3952     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
3953 
3954     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, MLAN_BSS_TYPE_UAP);
3955 
3956     cmd->result = 0x0;
3957 
3958     status = wlan_ops_uap_prepare_cmd((mlan_private *)mlan_adap->priv[1], HOST_CMD_APCMD_SYS_CONFIGURE,
3959                                       HostCmd_ACT_GEN_SET, 0, NULL, (void *)pcustom_ie, cmd);
3960 
3961     (void)wifi_wait_for_cmdresp(NULL);
3962 
3963     OSA_MemoryFree(pcustom_ie);
3964 
3965 done:
3966     LEAVE();
3967     return status;
3968 }
3969 
wifi_get_scan_table(mlan_private * pmpriv,mlan_scan_resp * pscan_resp)3970 void wifi_get_scan_table(mlan_private *pmpriv, mlan_scan_resp *pscan_resp)
3971 {
3972     mlan_adapter *pmadapter = pmpriv->adapter;
3973 
3974     pscan_resp->pscan_table       = (t_u8 *)pmadapter->pscan_table;
3975     pscan_resp->num_in_scan_table = pmadapter->num_in_scan_table;
3976     pscan_resp->age_in_secs       = pmadapter->age_in_secs;
3977 #if CONFIG_SCAN_CHANNEL_GAP
3978     pscan_resp->pchan_stats       = (t_u8 *)pmadapter->pchan_stats;
3979     pscan_resp->num_in_chan_stats = pmadapter->num_in_chan_stats;
3980 #endif
3981 }
3982 #endif
3983 
wifi_set_chanlist(wifi_chanlist_t * chanlist)3984 int wifi_set_chanlist(wifi_chanlist_t *chanlist)
3985 {
3986     mlan_status ret;
3987     t_u8 i         = 0;
3988     t_u8 cfp_no_bg = 0;
3989 #if CONFIG_5GHz_SUPPORT
3990     t_u8 cfp_no_a = 0;
3991 #endif
3992     mlan_adapter *pmadapter = mlan_adap->priv[0]->adapter;
3993 
3994 #ifdef OTP_CHANINFO
3995     if ((pmadapter->otp_region == MNULL) || (pmadapter->otp_region->force_reg == 0U))
3996     {
3997 #endif
3998         /*
3999          * Validate if the channels provided in the channel list
4000          * are valid channels according to World Wide Safe Mode.
4001          */
4002         for (i = 0; i < chanlist->num_chans; i++)
4003         {
4004             if (!wlan_is_channel_and_freq_valid(pmadapter, chanlist->chan_info[i].chan_num,
4005                                                 chanlist->chan_info[i].chan_freq))
4006             {
4007                 wifi_e("Invalid channel %d\r\n", chanlist->chan_info[i].chan_num);
4008                 return -WM_FAIL;
4009             }
4010         }
4011 
4012         /* Configure Custom CFP Tables */
4013 #if CONFIG_5GHz_SUPPORT
4014         ret = wlan_set_custom_cfp_table(chanlist, &cfp_no_bg, &cfp_no_a);
4015 #else
4016     ret = wlan_set_custom_cfp_table(chanlist, &cfp_no_bg);
4017 #endif
4018         if (ret != MLAN_STATUS_SUCCESS)
4019         {
4020             wifi_e("Failed to set Custom CFP Table");
4021             return -WM_FAIL;
4022         }
4023 
4024         /* Set Region Table */
4025 #if CONFIG_5GHz_SUPPORT
4026         wlan_set_custom_regiontable((mlan_private *)mlan_adap->priv[0], cfp_no_bg, cfp_no_a);
4027 #else
4028     wlan_set_custom_regiontable((mlan_private *)mlan_adap->priv[0], cfp_no_bg);
4029 #endif
4030 #ifdef OTP_CHANINFO
4031     }
4032 #endif
4033 
4034     return WM_SUCCESS;
4035 }
4036 
wifi_get_chanlist(wifi_chanlist_t * chanlist)4037 int wifi_get_chanlist(wifi_chanlist_t *chanlist)
4038 {
4039     mlan_adapter *pmadapter      = mlan_adap->priv[0]->adapter;
4040     region_chan_t *pchan_region  = MNULL;
4041     const chan_freq_power_t *cfp = MNULL;
4042     t_u32 region_idx             = 0;
4043     t_u32 next_chan              = 0;
4044     chanlist->num_chans          = 0;
4045 
4046     for (region_idx = 0; region_idx < NELEMENTS(pmadapter->region_channel); region_idx++)
4047     {
4048         if (!pmadapter->region_channel[region_idx].valid)
4049         {
4050             continue;
4051         }
4052 
4053         pchan_region = &pmadapter->region_channel[region_idx];
4054 
4055         for (next_chan = 0; next_chan < pchan_region->num_cfp; next_chan++)
4056         {
4057             cfp = pchan_region->pcfp + next_chan;
4058             if (cfp == MNULL)
4059             {
4060                 wifi_e("No cfp configured");
4061                 return -WM_FAIL;
4062             }
4063 
4064             if ((cfp->dynamic.flags & NXP_CHANNEL_DISABLED) != 0U)
4065             {
4066                 continue;
4067             }
4068 
4069             chanlist->chan_info[chanlist->num_chans].chan_num                     = cfp->channel;
4070             chanlist->chan_info[chanlist->num_chans].chan_freq                    = cfp->freq;
4071             chanlist->chan_info[chanlist->num_chans].passive_scan_or_radar_detect = cfp->passive_scan_or_radar_detect;
4072             chanlist->num_chans++;
4073 
4074             if (chanlist->num_chans >= NELEMENTS(chanlist->chan_info))
4075             {
4076                 break;
4077             }
4078         }
4079     }
4080 
4081     return WM_SUCCESS;
4082 }
4083 
wifi_get_active_channel_list(t_u8 * chan_list,t_u8 * num_chans,t_u16 acs_band)4084 void wifi_get_active_channel_list(t_u8 *chan_list, t_u8 *num_chans, t_u16 acs_band)
4085 {
4086     if (chan_list != MNULL && num_chans != MNULL)
4087     {
4088         wlan_get_active_channel_list((mlan_private *)mlan_adap->priv[1], chan_list, num_chans, acs_band);
4089     }
4090 }
4091 
wifi_set_txpwrlimit(wifi_txpwrlimit_t * txpwrlimit)4092 int wifi_set_txpwrlimit(wifi_txpwrlimit_t *txpwrlimit)
4093 {
4094     t_u8 i;
4095     int ret;
4096     HostCmd_DS_COMMAND *cmd                = wifi_get_command_buffer();
4097     t_u8 *pByte                            = NULL;
4098     MrvlIETypes_ChanTRPCConfig_t *trpc_tlv = NULL;
4099 
4100     (void)wifi_get_command_lock();
4101 
4102     cmd->command = HostCmd_CMD_CHANNEL_TRPC_CONFIG;
4103     cmd->seq_num = 0x0;
4104     cmd->result  = 0x0;
4105     cmd->size    = S_DS_GEN + 2U * sizeof(t_u16) +
4106                 txpwrlimit->num_chans * (sizeof(MrvlIEtypesHeader_t) + sizeof(MrvlChannelDesc_t)) +
4107                 (txpwrlimit->num_chans * txpwrlimit->txpwrlimit_config->num_mod_grps * sizeof(MrvlChanTrpcEntry_t));
4108 
4109     HostCmd_DS_CHAN_TRPC_CONFIG *txpwrlimit_config = (HostCmd_DS_CHAN_TRPC_CONFIG *)(void *)((uint8_t *)cmd + S_DS_GEN);
4110 
4111     txpwrlimit_config->action   = HostCmd_ACT_GEN_SET;
4112     txpwrlimit_config->reserved = txpwrlimit->subband;
4113 
4114     pByte = (t_u8 *)txpwrlimit_config->tlv_buffer;
4115 
4116     for (i = 0; i < txpwrlimit->num_chans; i++)
4117     {
4118         trpc_tlv              = (MrvlIETypes_ChanTRPCConfig_t *)(void *)pByte;
4119         trpc_tlv->header.type = TLV_TYPE_CHANNEL_TRPC_CONFIG;
4120         trpc_tlv->header.len =
4121             sizeof(MrvlChannelDesc_t) + txpwrlimit->txpwrlimit_config->num_mod_grps * sizeof(MrvlChanTrpcEntry_t);
4122         trpc_tlv->start_freq = txpwrlimit->txpwrlimit_config[i].chan_desc.start_freq;
4123         trpc_tlv->width      = txpwrlimit->txpwrlimit_config[i].chan_desc.chan_width;
4124         trpc_tlv->chan_num   = txpwrlimit->txpwrlimit_config[i].chan_desc.chan_num;
4125         (void)memcpy((void *)trpc_tlv->mod_group, (const void *)txpwrlimit->txpwrlimit_config[i].txpwrlimit_entry,
4126                      txpwrlimit->txpwrlimit_config->num_mod_grps * sizeof(MrvlChanTrpcEntry_t));
4127         pByte += trpc_tlv->header.len + sizeof(trpc_tlv->header);
4128     }
4129     ret = wifi_wait_for_cmdresp(NULL);
4130     return ret;
4131 }
4132 
wifi_get_txpwrlimit(wifi_SubBand_t subband,wifi_txpwrlimit_t * txpwrlimit)4133 int wifi_get_txpwrlimit(wifi_SubBand_t subband, wifi_txpwrlimit_t *txpwrlimit)
4134 {
4135     int ret;
4136 
4137     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4138 
4139     (void)wifi_get_command_lock();
4140 
4141     cmd->command = HostCmd_CMD_CHANNEL_TRPC_CONFIG;
4142     cmd->seq_num = 0x0;
4143     cmd->result  = 0x0;
4144     cmd->size    = S_DS_GEN + 2U * sizeof(t_u16);
4145 
4146     HostCmd_DS_CHAN_TRPC_CONFIG *txpwrlimit_config = (HostCmd_DS_CHAN_TRPC_CONFIG *)(void *)((uint8_t *)cmd + S_DS_GEN);
4147 
4148     txpwrlimit_config->action   = HostCmd_ACT_GEN_GET;
4149     txpwrlimit_config->reserved = subband;
4150 
4151     ret = wifi_wait_for_cmdresp(txpwrlimit);
4152     return ret;
4153 }
4154 
4155 #if CONFIG_WIFI_RTS_THRESHOLD
wifi_set_rts(int rts,mlan_bss_type bss_type)4156 int wifi_set_rts(int rts, mlan_bss_type bss_type)
4157 {
4158     mlan_ioctl_req req;
4159     mlan_ds_snmp_mib *mib = NULL;
4160     mlan_status ret       = MLAN_STATUS_FAILURE;
4161     wifi_sta_list_t *sl   = NULL;
4162 
4163     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
4164 
4165     /* Allocate an IOCTL request buffer */
4166 #if !CONFIG_MEM_POOLS
4167     mib = OSA_MemoryAllocate(sizeof(mlan_ds_snmp_mib));
4168 #else
4169     mib = OSA_MemoryPoolAllocate(buf_128_MemoryPool);
4170 #endif
4171 
4172     if (mib == NULL)
4173         return -WM_FAIL;
4174 
4175     /* Fill request buffer */
4176     mib->sub_command = MLAN_OID_SNMP_MIB_RTS_THRESHOLD;
4177     req.pbuf         = (t_u8 *)mib;
4178     req.buf_len      = sizeof(mlan_ds_snmp_mib);
4179     req.req_id       = MLAN_IOCTL_SNMP_MIB;
4180     req.action       = MLAN_ACT_SET;
4181     req.bss_index    = bss_type;
4182 
4183     if (req.action == MLAN_ACT_SET)
4184     {
4185         if (rts < MLAN_RTS_MIN_VALUE || rts > MLAN_RTS_MAX_VALUE)
4186         {
4187 #if !CONFIG_MEM_POOLS
4188             OSA_MemoryFree(mib);
4189 #else
4190             OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4191 #endif
4192             return -WM_FAIL;
4193         }
4194         mib->param.rts_threshold = rts;
4195     }
4196 
4197     if (bss_type == MLAN_BSS_TYPE_UAP)
4198     {
4199         if (!is_uap_started())
4200         {
4201             wifi_e("uap isn't up\n\r");
4202 #if !CONFIG_MEM_POOLS
4203             OSA_MemoryFree(mib);
4204 #else
4205             OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4206 #endif
4207             return -WM_FAIL;
4208         }
4209         wifi_uap_bss_sta_list(&sl);
4210         if (!sl)
4211         {
4212             wifi_e("Failed to get sta list\n\r");
4213 #if !CONFIG_MEM_POOLS
4214             OSA_MemoryFree(mib);
4215 #else
4216             OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4217 #endif
4218             return -WM_FAIL;
4219         }
4220         if (sl->count >= 1)
4221             ret = wlan_ops_sta_ioctl(mlan_adap, &req);
4222         else
4223             wifi_e("uap required sta to connect before setting rts threshold\n\r");
4224     }
4225     else if (bss_type == MLAN_BSS_TYPE_STA)
4226     {
4227         if (is_sta_connected())
4228             ret = wlan_ops_sta_ioctl(mlan_adap, &req);
4229         else
4230             wifi_e("sta connection required before setting rts threshold\n\r");
4231     }
4232 
4233     if (ret != MLAN_STATUS_SUCCESS && ret != MLAN_STATUS_PENDING)
4234     {
4235 #if !CONFIG_MEM_POOLS
4236         OSA_MemoryFree(mib);
4237 #else
4238         OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4239 #endif
4240         return -WM_FAIL;
4241     }
4242 
4243 #if !CONFIG_MEM_POOLS
4244     OSA_MemoryFree(mib);
4245 #else
4246     OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4247 #endif
4248 
4249     return WM_SUCCESS;
4250 }
4251 #endif
4252 
4253 #if CONFIG_WIFI_FRAG_THRESHOLD
wifi_set_frag(int frag,mlan_bss_type bss_type)4254 int wifi_set_frag(int frag, mlan_bss_type bss_type)
4255 {
4256     mlan_ioctl_req req;
4257     mlan_ds_snmp_mib *mib = NULL;
4258     mlan_status ret       = MLAN_STATUS_FAILURE;
4259     wifi_sta_list_t *sl   = NULL;
4260 
4261     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
4262 
4263     /* Allocate an IOCTL request buffer */
4264 #if !CONFIG_MEM_POOLS
4265     mib = OSA_MemoryAllocate(sizeof(mlan_ds_snmp_mib));
4266 #else
4267     mib = OSA_MemoryPoolAllocate(buf_128_MemoryPool);
4268 #endif
4269 
4270     if (mib == NULL)
4271         return -WM_FAIL;
4272 
4273     /* Fill request buffer */
4274     mib->sub_command = MLAN_OID_SNMP_MIB_FRAG_THRESHOLD;
4275     req.pbuf         = (t_u8 *)mib;
4276     req.buf_len      = sizeof(mlan_ds_snmp_mib);
4277     req.req_id       = MLAN_IOCTL_SNMP_MIB;
4278     req.action       = MLAN_ACT_SET;
4279     req.bss_index    = bss_type;
4280 
4281     if (req.action == MLAN_ACT_SET)
4282     {
4283         if (frag < MLAN_FRAG_MIN_VALUE || frag > MLAN_FRAG_MAX_VALUE)
4284         {
4285 #if !CONFIG_MEM_POOLS
4286             OSA_MemoryFree(mib);
4287 #else
4288             OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4289 #endif
4290             return -WM_FAIL;
4291         }
4292         mib->param.frag_threshold = frag;
4293     }
4294 
4295     if (bss_type == MLAN_BSS_TYPE_UAP)
4296     {
4297         if (!is_uap_started())
4298         {
4299             wifi_e("uap isn't up\n\r");
4300 #if !CONFIG_MEM_POOLS
4301             OSA_MemoryFree(mib);
4302 #else
4303             OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4304 #endif
4305             return -WM_FAIL;
4306         }
4307         wifi_uap_bss_sta_list(&sl);
4308         if (!sl)
4309         {
4310             wifi_e("Failed to get sta list\n\r");
4311 #if !CONFIG_MEM_POOLS
4312             OSA_MemoryFree(mib);
4313 #else
4314             OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4315 #endif
4316             return -WM_FAIL;
4317         }
4318 
4319         if (sl->count >= 1)
4320             ret = wlan_ops_sta_ioctl(mlan_adap, &req);
4321         else
4322             wifi_e("uap required sta to connect before setting fragment threshold\n\r");
4323     }
4324     else if (bss_type == MLAN_BSS_TYPE_STA)
4325     {
4326         if (is_sta_connected())
4327             ret = wlan_ops_sta_ioctl(mlan_adap, &req);
4328         else
4329             wifi_e("sta connection required before setting fragment threshold\n\r");
4330     }
4331 
4332     if (ret != MLAN_STATUS_SUCCESS && ret != MLAN_STATUS_PENDING)
4333     {
4334 #if !CONFIG_MEM_POOLS
4335         OSA_MemoryFree(mib);
4336 #else
4337         OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4338 #endif
4339         return -WM_FAIL;
4340     }
4341 #if !CONFIG_MEM_POOLS
4342     OSA_MemoryFree(mib);
4343 #else
4344     OSA_MemoryPoolFree(buf_128_MemoryPool, mib);
4345 #endif
4346     return WM_SUCCESS;
4347 }
4348 #endif
4349 
wifi_set_curr_bss_channel(uint8_t channel)4350 void wifi_set_curr_bss_channel(uint8_t channel)
4351 {
4352     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
4353 
4354     pmpriv->curr_bss_params.bss_descriptor.channel = channel;
4355 }
4356 
4357 #if CONFIG_11K_OFFLOAD
wifi_11k_cfg(int enable_11k)4358 int wifi_11k_cfg(int enable_11k)
4359 {
4360     mlan_ioctl_req req;
4361     mlan_ds_11k_cfg *pcfg_11k = NULL;
4362     mlan_status ret           = MLAN_STATUS_SUCCESS;
4363 
4364     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
4365 
4366     /* Allocate an IOCTL request buffer */
4367 #if !CONFIG_MEM_POOLS
4368     pcfg_11k = OSA_MemoryAllocate(sizeof(mlan_ds_11k_cfg));
4369 #else
4370     pcfg_11k = OSA_MemoryPoolAllocate(buf_128_MemoryPool);
4371 #endif
4372 
4373     if (pcfg_11k == NULL)
4374     {
4375         ret = MLAN_STATUS_FAILURE;
4376         return ret;
4377     }
4378 
4379     /* Fill request buffer */
4380     pcfg_11k->sub_command = MLAN_OID_11K_CFG_ENABLE;
4381     req.pbuf              = (t_u8 *)pcfg_11k;
4382     req.buf_len           = sizeof(mlan_ds_11k_cfg);
4383     req.req_id            = MLAN_IOCTL_11K_CFG;
4384     req.action            = MLAN_ACT_SET;
4385 
4386     if (enable_11k != 0 && enable_11k != 1)
4387     {
4388         ret = MLAN_STATUS_FAILURE;
4389 #if !CONFIG_MEM_POOLS
4390         OSA_MemoryFree(pcfg_11k);
4391 #else
4392         OSA_MemoryPoolFree(buf_128_MemoryPool, pcfg_11k);
4393 #endif
4394         return ret;
4395     }
4396 
4397     pcfg_11k->param.enable_11k = enable_11k;
4398 
4399     if (!is_sta_connected())
4400     {
4401         ret = wlan_ops_sta_ioctl(mlan_adap, &req);
4402         if (ret != MLAN_STATUS_SUCCESS && ret != MLAN_STATUS_PENDING)
4403         {
4404 #if !CONFIG_MEM_POOLS
4405             OSA_MemoryFree(pcfg_11k);
4406 #else
4407             OSA_MemoryPoolFree(buf_128_MemoryPool, pcfg_11k);
4408 #endif
4409             return -WM_FAIL;
4410         }
4411     }
4412     else
4413         wifi_e("sta disconnection is required before enable/disable 11k\r\n");
4414 
4415 #if !CONFIG_MEM_POOLS
4416     OSA_MemoryFree(pcfg_11k);
4417 #else
4418     OSA_MemoryPoolFree(buf_128_MemoryPool, pcfg_11k);
4419 #endif
4420 
4421     return WM_SUCCESS;
4422 }
4423 
wifi_11k_neighbor_req()4424 int wifi_11k_neighbor_req()
4425 {
4426     if (!is_sta_connected())
4427     {
4428         wifi_e("sta connection is required before sending neighbor report req\r\n");
4429         return -WM_FAIL;
4430     }
4431 
4432     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4433 
4434     wifi_get_command_lock();
4435 
4436     cmd->seq_num = 0x0;
4437     cmd->result  = 0x0;
4438 
4439     wlan_cmd_11k_neighbor_req((mlan_private *)mlan_adap->priv[0], cmd);
4440 
4441     wifi_wait_for_cmdresp(NULL);
4442 
4443     return WM_SUCCESS;
4444 }
4445 #endif
4446 
4447 #if CONFIG_11K
wifi_host_11k_cfg(int enable_11k)4448 int wifi_host_11k_cfg(int enable_11k)
4449 {
4450     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
4451 #if !CONFIG_WPA_SUPP
4452     IEEEtypes_RrmElement_t rrmCap;
4453 #endif
4454     int ret = (int)MLAN_STATUS_SUCCESS;
4455 
4456 #if CONFIG_11K_OFFLOAD
4457     /* Check if fw base 11k is enabled */
4458     if (enable_11k == 1 && pmpriv->enable_11k == (t_u8)1U)
4459     {
4460         return -WM_E_PERM;
4461     }
4462 #endif
4463     if (enable_11k == (int)pmpriv->enable_host_11k)
4464     {
4465         return (int)MLAN_STATUS_SUCCESS;
4466     }
4467 
4468 #if !CONFIG_WPA_SUPP
4469     if (enable_11k == 1)
4470     {
4471         if (pmpriv->rrm_mgmt_bitmap_index != -1)
4472         {
4473             ret = wifi_clear_mgmt_ie(MLAN_BSS_TYPE_STA, MGMT_RRM_ENABLED_CAP, pmpriv->rrm_mgmt_bitmap_index);
4474 
4475             pmpriv->rrm_mgmt_bitmap_index = -1;
4476         }
4477         rrmCap.element_id = (t_u8)MGMT_RRM_ENABLED_CAP;
4478         rrmCap.len        = (t_u8)sizeof(IEEEtypes_RrmEnabledCapabilities_t);
4479         wlan_dot11k_formatRrmCapabilities(&(rrmCap.RrmEnabledCapabilities), 100);
4480 
4481         /* Append the passed data to the end of
4482          * the genIeBuffer */
4483         __memcpy(pmpriv->adapter, pmpriv->assoc_req_buf, &rrmCap, sizeof(IEEEtypes_RrmElement_t));
4484 
4485         /* Increment the stored buffer length by
4486          * the size passed */
4487         pmpriv->assoc_req_size = sizeof(IEEEtypes_RrmElement_t);
4488     }
4489     else
4490     {
4491         pmpriv->assoc_req_size = 0;
4492     }
4493 #endif
4494 
4495     pmpriv->enable_host_11k = (t_u8)enable_11k;
4496 
4497     return ret;
4498 }
4499 
wifi_host_11k_neighbor_req(const char * ssid)4500 int wifi_host_11k_neighbor_req(const char *ssid)
4501 {
4502     if (wlan_strlen((t_s8 *)ssid) > IEEEtypes_SSID_SIZE)
4503     {
4504         return -WM_FAIL;
4505     }
4506     else
4507     {
4508         return wlan_send_mgmt_rm_neighbor_request(mlan_adap->priv[0], (t_u8 *)ssid, (t_u8)wlan_strlen((t_s8 *)ssid));
4509     }
4510 }
4511 #endif
4512 
4513 #if CONFIG_11V
wifi_host_11v_bss_trans_query(t_u8 query_reason)4514 int wifi_host_11v_bss_trans_query(t_u8 query_reason)
4515 {
4516     return wlan_send_mgmt_bss_trans_query(mlan_adap->priv[0], query_reason);
4517 }
4518 #endif
4519 
4520 #if CONFIG_DRIVER_MBO
wifi_host_mbo_cfg(int enable_mbo)4521 int wifi_host_mbo_cfg(int enable_mbo)
4522 {
4523     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
4524     IEEEtypes_VendorSpecific_t mboie;
4525     int ret = (int)MLAN_STATUS_SUCCESS;
4526     t_u8 *pos;
4527     int meas_vend_hdr_len = 0;
4528 
4529     if ((t_u8)enable_mbo == pmpriv->enable_mbo)
4530     {
4531         /* Do nothing */
4532         return (int)MLAN_STATUS_SUCCESS;
4533     }
4534 
4535     if (enable_mbo != 0)
4536     {
4537         mboie.vend_hdr.element_id = (IEEEtypes_ElementId_e)MGMT_MBO_IE;
4538         pos                       = mboie.vend_hdr.oui;
4539         pos                       = wlan_add_mbo_oui(pos);
4540         pos                       = wlan_add_mbo_oui_type(pos);
4541         pos                       = wlan_add_mbo_cellular_cap(pos);
4542         meas_vend_hdr_len         = pos - mboie.vend_hdr.oui;
4543         mboie.vend_hdr.len        = (t_u8)meas_vend_hdr_len;
4544         pmpriv->mbo_mgmt_bitmap_index =
4545             wifi_set_mgmt_ie(MLAN_BSS_TYPE_STA, MGMT_MBO_IE, (void *)&(mboie.vend_hdr.oui), mboie.vend_hdr.len);
4546     }
4547     else
4548     {
4549         ret = wifi_clear_mgmt_ie(MLAN_BSS_TYPE_STA, MGMT_MBO_IE, pmpriv->mbo_mgmt_bitmap_index);
4550     }
4551     pmpriv->enable_mbo = (t_u8)enable_mbo;
4552 
4553     return ret;
4554 }
4555 
wifi_mbo_preferch_cfg(t_u8 ch0,t_u8 pefer0,t_u8 ch1,t_u8 pefer1)4556 int wifi_mbo_preferch_cfg(t_u8 ch0, t_u8 pefer0, t_u8 ch1, t_u8 pefer1)
4557 {
4558     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
4559     IEEEtypes_VendorSpecific_t mboie;
4560     int ret = (int)MLAN_STATUS_SUCCESS;
4561     t_u8 *pos;
4562     int meas_vend_hdr_len = 0;
4563 
4564     if (0U == pmpriv->enable_mbo)
4565     {
4566         wifi_e("Please enable MBO first!");
4567         return (int)MLAN_STATUS_FAILURE;
4568     }
4569 
4570     if (pmpriv->enable_mbo != 0U)
4571     {
4572         /* remove MBO OCE IE in case there is already a MBO OCE IE. */
4573         ret                       = wifi_clear_mgmt_ie(MLAN_BSS_TYPE_STA, MGMT_MBO_IE, pmpriv->mbo_mgmt_bitmap_index);
4574         mboie.vend_hdr.element_id = (IEEEtypes_ElementId_e)MGMT_MBO_IE;
4575         pos                       = mboie.vend_hdr.oui;
4576         pos                       = wlan_add_mbo_oui(pos);
4577         pos                       = wlan_add_mbo_oui_type(pos);
4578         pos                       = wlan_add_mbo_cellular_cap(pos);
4579         pos                       = wlan_add_mbo_prefer_ch(pos, ch0, pefer0, ch1, pefer1);
4580         meas_vend_hdr_len         = pos - mboie.vend_hdr.oui;
4581         mboie.vend_hdr.len        = (t_u8)meas_vend_hdr_len;
4582         pmpriv->mbo_mgmt_bitmap_index =
4583             wifi_set_mgmt_ie(MLAN_BSS_TYPE_STA, MGMT_MBO_IE, (void *)&(mboie.vend_hdr.oui), mboie.vend_hdr.len);
4584     }
4585 
4586     return ret;
4587 }
4588 
wifi_mbo_send_preferch_wnm(t_u8 * src_addr,t_u8 * target_bssid,t_u8 ch0,t_u8 pefer0,t_u8 ch1,t_u8 pefer1)4589 int wifi_mbo_send_preferch_wnm(t_u8 *src_addr, t_u8 *target_bssid, t_u8 ch0, t_u8 pefer0, t_u8 ch1, t_u8 pefer1)
4590 {
4591     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
4592     int ret              = MLAN_STATUS_SUCCESS;
4593     t_u8 *buf, *pos, *pos_len1, *pos_len2;
4594     t_u8 global_oper_class_0 = 0, global_oper_class_1 = 0, num = 0, i;
4595 
4596     if (0 == pmpriv->enable_mbo)
4597     {
4598         wifi_e("Please enable MBO first!\r\n");
4599         return MLAN_STATUS_FAILURE;
4600     }
4601 
4602     if (pmpriv->enable_mbo)
4603     {
4604 #if !CONFIG_MEM_POOLS
4605         buf = OSA_MemoryAllocate(sizeof(IEEEtypes_VendorSpecific_t));
4606 #else
4607         buf = OSA_MemoryPoolAllocate(buf_512_MemoryPool);
4608 #endif
4609         pos = buf;
4610 
4611         /* No non-preferred channels */
4612         if (!ch0 && !pefer0 && !ch1 && !pefer1)
4613         {
4614             *pos = MGMT_MBO_IE;
4615             pos++;
4616             *pos = 4;
4617             pos++;
4618             pos = wlan_add_mbo_oui(pos);
4619             pos = wlan_add_mbo_attr_id(pos);
4620         }
4621         else
4622         {
4623             wlan_get_curr_oper_class(pmpriv, ch0, BW_20MHZ, &global_oper_class_0);
4624             wlan_get_curr_oper_class(pmpriv, ch1, BW_20MHZ, &global_oper_class_1);
4625             if (global_oper_class_0 != global_oper_class_1 || pefer0 != pefer1)
4626                 num = 2;
4627             else
4628                 num = 1;
4629 
4630             for (i = 0; i < num; i++)
4631             {
4632                 *pos = MGMT_MBO_IE;
4633                 pos++;
4634                 if (i == 0)
4635                     pos_len1 = pos;
4636                 else
4637                     pos_len2 = pos;
4638                 pos++;
4639                 pos = wlan_add_mbo_oui(pos);
4640                 pos = wlan_add_mbo_attr_id(pos);
4641                 if (num == 1)
4642                 {
4643                     pos[0] = global_oper_class_0;
4644                     pos[1] = ch0;
4645                     pos[2] = ch1;
4646                     pos[3] = pefer0;
4647                     pos += 4;
4648                 }
4649                 else
4650                 {
4651                     if (i == 0)
4652                     {
4653                         pos[0] = global_oper_class_0;
4654                         pos[1] = ch0;
4655                         pos[2] = pefer0;
4656                     }
4657                     else
4658                     {
4659                         pos[0] = global_oper_class_1;
4660                         pos[1] = ch1;
4661                         pos[2] = pefer1;
4662                     }
4663                     pos += 3;
4664                 }
4665 
4666                 /* Reason code */
4667                 *pos = 0;
4668                 pos++;
4669 
4670                 if (i == 0)
4671                     *pos_len1 = pos - (pos_len1 + 1);
4672                 else
4673                     *pos_len2 = pos - (pos_len2 + 1);
4674             }
4675         }
4676         wlan_send_mgmt_wnm_notification(src_addr, target_bssid, target_bssid, buf, pos - buf, false);
4677     }
4678 #if !CONFIG_MEM_POOLS
4679     OSA_MemoryFree(buf);
4680 #else
4681     OSA_MemoryPoolFree(buf_512_MemoryPool, buf);
4682 #endif
4683 
4684     return ret;
4685 }
4686 #endif
4687 
4688 #ifdef OTP_CHANINFO
wifi_get_fw_region_and_cfp_tables(void)4689 int wifi_get_fw_region_and_cfp_tables(void)
4690 {
4691     int ret;
4692 
4693     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4694 
4695     (void)wifi_get_command_lock();
4696 
4697     cmd->command = HostCmd_CMD_CHAN_REGION_CFG;
4698     cmd->seq_num = 0x0;
4699     cmd->result  = 0x0;
4700     cmd->size    = S_DS_GEN + sizeof(HostCmd_DS_CHAN_REGION_CFG);
4701 
4702     HostCmd_DS_CHAN_REGION_CFG *chan_region_cfg = (HostCmd_DS_CHAN_REGION_CFG *)(void *)((uint8_t *)cmd + S_DS_GEN);
4703 
4704     chan_region_cfg->action = HostCmd_ACT_GEN_GET;
4705 
4706     ret = wifi_wait_for_cmdresp(NULL);
4707     return ret;
4708 }
4709 
wifi_free_fw_region_and_cfp_tables(void)4710 void wifi_free_fw_region_and_cfp_tables(void)
4711 {
4712     mlan_adapter *pmadapter = mlan_adap->priv[0]->adapter;
4713     wlan_free_fw_cfp_tables(pmadapter);
4714 }
4715 #endif
4716 
wifi_set_ed_mac_mode(wifi_ed_mac_ctrl_t * wifi_ed_mac_ctrl,int bss_type)4717 int wifi_set_ed_mac_mode(wifi_ed_mac_ctrl_t *wifi_ed_mac_ctrl, int bss_type)
4718 {
4719     int ret;
4720 
4721     if (wifi_ed_mac_ctrl == MNULL)
4722     {
4723         return -WM_FAIL;
4724     }
4725 
4726     mlan_private *pmpriv    = (mlan_private *)mlan_adap->priv[bss_type];
4727     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4728 
4729     (void)wifi_get_command_lock();
4730 
4731     cmd->command = HostCmd_CMD_ED_MAC_MODE;
4732     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
4733     cmd->result  = 0x0;
4734     cmd->size    = S_DS_GEN + sizeof(HostCmd_CONFIG_ED_MAC_MODE);
4735 
4736     HostCmd_CONFIG_ED_MAC_MODE *ed_mac_mode = (HostCmd_CONFIG_ED_MAC_MODE *)(void *)((uint8_t *)cmd + S_DS_GEN);
4737 
4738     ed_mac_mode->ed_ctrl_2g   = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_ctrl_2g);
4739     ed_mac_mode->ed_offset_2g = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_offset_2g);
4740 #if CONFIG_5GHz_SUPPORT
4741     ed_mac_mode->ed_ctrl_5g   = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_ctrl_5g);
4742     ed_mac_mode->ed_offset_5g = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_offset_5g);
4743 #if defined(SD9177)
4744     ed_mac_mode->ed_bitmap_txq_lock = 0x1e00ff;
4745 #else
4746     ed_mac_mode->ed_bitmap_txq_lock = 0xff;
4747 #endif
4748 #endif
4749 
4750     pmpriv->ed_mac_mode.ed_ctrl_2g   = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_ctrl_2g);
4751     pmpriv->ed_mac_mode.ed_offset_2g = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_offset_2g);
4752 #if CONFIG_5GHz_SUPPORT
4753     pmpriv->ed_mac_mode.ed_ctrl_5g   = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_ctrl_5g);
4754     pmpriv->ed_mac_mode.ed_offset_5g = wlan_cpu_to_le16(wifi_ed_mac_ctrl->ed_offset_5g);
4755 #endif
4756 
4757     ret = wifi_wait_for_cmdresp(NULL);
4758     return ret;
4759 }
4760 
wifi_get_ed_mac_mode(wifi_ed_mac_ctrl_t * wifi_ed_mac_ctrl,int bss_type)4761 int wifi_get_ed_mac_mode(wifi_ed_mac_ctrl_t *wifi_ed_mac_ctrl, int bss_type)
4762 {
4763     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[bss_type];
4764 
4765     if (wifi_ed_mac_ctrl == MNULL)
4766     {
4767         return -WM_FAIL;
4768     }
4769 
4770     (void)memset(wifi_ed_mac_ctrl, 0x00, sizeof(wifi_ed_mac_ctrl_t));
4771 
4772     wifi_ed_mac_ctrl->ed_ctrl_2g   = wlan_cpu_to_le16(pmpriv->ed_mac_mode.ed_ctrl_2g);
4773     wifi_ed_mac_ctrl->ed_offset_2g = wlan_cpu_to_le16(pmpriv->ed_mac_mode.ed_offset_2g);
4774 #if CONFIG_5GHz_SUPPORT
4775     wifi_ed_mac_ctrl->ed_ctrl_5g   = wlan_cpu_to_le16(pmpriv->ed_mac_mode.ed_ctrl_5g);
4776     wifi_ed_mac_ctrl->ed_offset_5g = wlan_cpu_to_le16(pmpriv->ed_mac_mode.ed_offset_5g);
4777 #endif
4778 
4779     return WM_SUCCESS;
4780 }
4781 
4782 #ifndef IEEEtypes_SSID_SIZE
4783 #define IEEEtypes_SSID_SIZE 32
4784 #endif /* IEEEtypes_SSID_SIZE */
4785 #define MRVL_SSID_TLV_ID          0x0000
4786 #define MRVL_BEACON_PERIOD_TLV_ID (PROPRIETARY_TLV_BASE_ID + 0x2cU)
4787 #define TLV_TYPE_SMCADDRRANGE     (PROPRIETARY_TLV_BASE_ID + 0xccU)
4788 #define TLV_TYPE_SMCFRAMEFILTER   (PROPRIETARY_TLV_BASE_ID + 0xd1U)
4789 
wifi_set_smart_mode_cfg(char * ssid,int beacon_period,wifi_chan_list_param_set_t * chan_list,uint8_t * smc_start_addr,uint8_t * smc_end_addr,uint16_t filter_type,int smc_frame_filter_len,uint8_t * smc_frame_filter,int custom_ie_len,uint8_t * custom_ie)4790 int wifi_set_smart_mode_cfg(char *ssid,
4791                             int beacon_period,
4792                             wifi_chan_list_param_set_t *chan_list,
4793                             uint8_t *smc_start_addr,
4794                             uint8_t *smc_end_addr,
4795                             uint16_t filter_type,
4796                             int smc_frame_filter_len,
4797                             uint8_t *smc_frame_filter,
4798                             int custom_ie_len,
4799                             uint8_t *custom_ie)
4800 {
4801     unsigned int ssid_len                              = 0, i;
4802     uint32_t size                                      = S_DS_GEN + sizeof(HostCmd_DS_SYS_CONFIG) - 1U;
4803     MrvlIEtypes_SsIdParamSet_t *tlv_ssid               = NULL;
4804     MrvlIEtypes_beacon_period_t *tlv_beacon_period     = NULL;
4805     MrvlIEtypes_ChanListParamSet_t *tlv_chan_list      = NULL;
4806     MrvlIEtypes_Data_t *tlv_custom_ie                  = NULL;
4807     MrvlIETypes_SmcAddrRange_t *tlv_smc_addr_range     = NULL;
4808     MrvlIETypes_SmcFrameFilter_t *tlv_smc_frame_filter = NULL;
4809 
4810     (void)wifi_get_command_lock();
4811     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4812 
4813     cmd->command                          = wlan_cpu_to_le16(HOST_CMD_SMART_MODE_CFG);
4814     HostCmd_DS_SYS_CONFIG *sys_config_cmd = (HostCmd_DS_SYS_CONFIG *)((uint32_t)cmd + S_DS_GEN);
4815     sys_config_cmd->action                = HostCmd_ACT_GEN_SET;
4816     uint8_t *tlv                          = (uint8_t *)sys_config_cmd->tlv_buffer;
4817 
4818     ssid_len = strlen(ssid);
4819     if (ssid_len > IEEEtypes_SSID_SIZE || custom_ie_len > 255)
4820     {
4821         return -WM_E_INVAL;
4822     };
4823 
4824     tlv_ssid              = (MrvlIEtypes_SsIdParamSet_t *)(void *)sys_config_cmd->tlv_buffer;
4825     tlv_ssid->header.type = MRVL_SSID_TLV_ID;
4826     tlv_ssid->header.len  = strlen(ssid);
4827     (void)memcpy((void *)tlv_ssid->ssid, (const void *)ssid, strlen(ssid));
4828     size += sizeof(tlv_ssid->header) + tlv_ssid->header.len;
4829     tlv += sizeof(tlv_ssid->header) + tlv_ssid->header.len;
4830     tlv_beacon_period                = (MrvlIEtypes_beacon_period_t *)(void *)tlv;
4831     tlv_beacon_period->header.type   = MRVL_BEACON_PERIOD_TLV_ID;
4832     tlv_beacon_period->header.len    = sizeof(uint16_t);
4833     tlv_beacon_period->beacon_period = beacon_period;
4834 
4835     size += sizeof(tlv_beacon_period->header) + tlv_beacon_period->header.len;
4836     tlv += sizeof(tlv_beacon_period->header) + tlv_beacon_period->header.len;
4837 
4838     tlv_chan_list              = (MrvlIEtypes_ChanListParamSet_t *)(void *)tlv;
4839     tlv_chan_list->header.type = TLV_TYPE_CHANLIST;
4840     tlv_chan_list->header.len  = chan_list->no_of_channels * sizeof(ChanScanParamSet_t);
4841 
4842     for (i = 0; i < chan_list->no_of_channels; i++)
4843     {
4844         tlv_chan_list->chan_scan_param[i].chan_number   = chan_list->chan_scan_param[i].chan_number;
4845         tlv_chan_list->chan_scan_param[i].min_scan_time = chan_list->chan_scan_param[i].min_scan_time;
4846         tlv_chan_list->chan_scan_param[i].max_scan_time = chan_list->chan_scan_param[i].max_scan_time;
4847     }
4848 
4849     size += sizeof(tlv_chan_list->header) + tlv_chan_list->header.len;
4850     tlv += sizeof(tlv_chan_list->header) + tlv_chan_list->header.len;
4851 
4852     if (custom_ie != MNULL && custom_ie_len > 0)
4853     {
4854         tlv_custom_ie              = (MrvlIEtypes_Data_t *)(void *)tlv;
4855         tlv_custom_ie->header.type = TLV_TYPE_PASSTHROUGH;
4856         tlv_custom_ie->header.len  = custom_ie_len;
4857         (void)memcpy((void *)tlv_custom_ie->data, (const void *)custom_ie, custom_ie_len);
4858 
4859         size += sizeof(tlv_custom_ie->header) + tlv_custom_ie->header.len;
4860         tlv += sizeof(tlv_custom_ie->header) + tlv_custom_ie->header.len;
4861     }
4862 
4863     if (smc_start_addr != MNULL && smc_end_addr != MNULL)
4864     {
4865         tlv_smc_addr_range              = (MrvlIETypes_SmcAddrRange_t *)(void *)tlv;
4866         tlv_smc_addr_range->header.type = TLV_TYPE_SMCADDRRANGE;
4867         tlv_smc_addr_range->header.len  = 2U * MLAN_MAC_ADDR_LENGTH + sizeof(uint16_t);
4868 
4869         (void)memcpy((void *)tlv_smc_addr_range->smcstartAddr, (const void *)smc_start_addr, MLAN_MAC_ADDR_LENGTH);
4870         (void)memcpy((void *)tlv_smc_addr_range->smcendAddr, (const void *)smc_end_addr, MLAN_MAC_ADDR_LENGTH);
4871 
4872         tlv_smc_addr_range->filter_type = filter_type;
4873 
4874         size += sizeof(tlv_smc_addr_range->header) + tlv_smc_addr_range->header.len;
4875         tlv += sizeof(tlv_smc_addr_range->header) + tlv_smc_addr_range->header.len;
4876     }
4877 
4878     tlv_smc_frame_filter              = (MrvlIETypes_SmcFrameFilter_t *)(void *)tlv;
4879     tlv_smc_frame_filter->header.type = TLV_TYPE_SMCFRAMEFILTER;
4880     tlv_smc_frame_filter->header.len  = smc_frame_filter_len;
4881     (void)memcpy((void *)tlv_smc_frame_filter->frame_filter, (const void *)smc_frame_filter, smc_frame_filter_len);
4882 
4883     size += sizeof(tlv_smc_frame_filter->header) + tlv_smc_frame_filter->header.len;
4884     tlv += sizeof(tlv_smc_frame_filter->header) + tlv_smc_frame_filter->header.len;
4885 
4886     cmd->size    = size;
4887     cmd->seq_num = 0x00;
4888     cmd->result  = 0x00;
4889 
4890     (void)wifi_wait_for_cmdresp(NULL);
4891 
4892     return WM_SUCCESS;
4893 }
4894 
wifi_get_smart_mode_cfg(void)4895 int wifi_get_smart_mode_cfg(void)
4896 {
4897     uint32_t size = S_DS_GEN + sizeof(HostCmd_DS_SYS_CONFIG) - 1U;
4898 
4899     (void)wifi_get_command_lock();
4900     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4901 
4902     cmd->command                          = wlan_cpu_to_le16(HOST_CMD_SMART_MODE_CFG);
4903     HostCmd_DS_SYS_CONFIG *sys_config_cmd = (HostCmd_DS_SYS_CONFIG *)((uint32_t)cmd + S_DS_GEN);
4904     sys_config_cmd->action                = HostCmd_ACT_GEN_GET;
4905 
4906     cmd->size    = size;
4907     cmd->seq_num = 0x00;
4908     cmd->result  = 0x00;
4909 
4910     (void)wifi_wait_for_cmdresp(NULL);
4911     return WM_SUCCESS;
4912 }
4913 
wifi_start_smart_mode(void)4914 int wifi_start_smart_mode(void)
4915 {
4916     uint32_t size = S_DS_GEN + sizeof(HostCmd_DS_SYS_CONFIG) - 1U;
4917 
4918     (void)wifi_get_command_lock();
4919     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4920 
4921     cmd->command                          = wlan_cpu_to_le16(HOST_CMD_SMART_MODE_CFG);
4922     HostCmd_DS_SYS_CONFIG *sys_config_cmd = (HostCmd_DS_SYS_CONFIG *)((uint32_t)cmd + S_DS_GEN);
4923     sys_config_cmd->action                = HostCmd_ACT_GEN_START;
4924 
4925     cmd->size    = size;
4926     cmd->seq_num = 0x00;
4927     cmd->result  = 0x00;
4928 
4929     (void)wifi_wait_for_cmdresp(NULL);
4930     return WM_SUCCESS;
4931 }
4932 
wifi_stop_smart_mode(void)4933 int wifi_stop_smart_mode(void)
4934 {
4935     uint32_t size = S_DS_GEN + sizeof(HostCmd_DS_SYS_CONFIG) - 1U;
4936 
4937     (void)wifi_get_command_lock();
4938     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
4939 
4940     cmd->command                          = wlan_cpu_to_le16(HOST_CMD_SMART_MODE_CFG);
4941     HostCmd_DS_SYS_CONFIG *sys_config_cmd = (HostCmd_DS_SYS_CONFIG *)((uint32_t)cmd + S_DS_GEN);
4942     sys_config_cmd->action                = HostCmd_ACT_GEN_STOP;
4943 
4944     cmd->size    = size;
4945     cmd->seq_num = 0x00;
4946     cmd->result  = 0x00;
4947 
4948     (void)wifi_wait_for_cmdresp(NULL);
4949 
4950     return WM_SUCCESS;
4951 }
4952 
4953 #if CONFIG_BG_SCAN
wifi_get_band(mlan_private * pmpriv,int * band)4954 void wifi_get_band(mlan_private *pmpriv, int *band)
4955 {
4956     int support_band = 0;
4957 
4958     if (pmpriv->config_bands & (BAND_B | BAND_G | BAND_GN))
4959         support_band |= WIFI_FREQUENCY_BAND_2GHZ;
4960 #if CONFIG_5GHz_SUPPORT
4961     if (pmpriv->config_bands & (BAND_A | BAND_AN))
4962         support_band |= WIFI_FREQUENCY_BAND_5GHZ;
4963 #endif
4964     *band = support_band;
4965     if (support_band == WIFI_FREQUENCY_ALL_BAND)
4966         *band = WIFI_FREQUENCY_BAND_AUTO;
4967 }
4968 
wifi_get_bgscan_results(mlan_private * pmpriv)4969 int wifi_get_bgscan_results(mlan_private *pmpriv)
4970 {
4971     mlan_adapter *pmadapter = pmpriv->adapter;
4972     int ret                 = 0;
4973 #if CONFIG_WPA_SUPP
4974     BSSDescriptor_t *bss_entry = NULL;
4975     int i;
4976 #endif
4977 
4978     ENTER();
4979 
4980 #if CONFIG_WPA_SUPP
4981     pmadapter->wpa_supp_scan_triggered = MTRUE;
4982     for (i = 0; i < pmadapter->num_in_scan_table; i++)
4983     {
4984         bss_entry = &pmadapter->pscan_table[i];
4985         if (bss_entry && bss_entry->ies != NULL)
4986         {
4987             OSA_MemoryFree(bss_entry->ies);
4988         }
4989     }
4990 #endif
4991 
4992     memset(pmadapter->pscan_table, 0x00, sizeof(BSSDescriptor_t) * MRVDRV_MAX_BSSID_LIST);
4993     pmadapter->num_in_scan_table = 0;
4994     ret                          = wifi_request_bgscan_query(pmpriv);
4995     pmadapter->bgscan_reported   = MFALSE;
4996     LEAVE();
4997     return ret;
4998 }
4999 
wifi_send_scan_query(void)5000 int wifi_send_scan_query(void)
5001 {
5002     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
5003     int ret              = 0;
5004 
5005     ENTER();
5006     ret = wifi_get_bgscan_results(pmpriv);
5007     if (ret)
5008     {
5009         PRINTM(MERROR, "Failed to get scan results\n");
5010         goto done;
5011     }
5012 done:
5013     /* config rssi low threshold again */
5014     pmpriv->rssi_low = DEFAULT_RSSI_LOW_THRESHOLD;
5015     LEAVE();
5016     return ret;
5017 }
5018 #endif
5019 
wifi_send_hostcmd(const void * cmd_buf,uint32_t cmd_buf_len,void * resp_buf,uint32_t resp_buf_len,uint32_t * reqd_resp_len)5020 int wifi_send_hostcmd(
5021     const void *cmd_buf, uint32_t cmd_buf_len, void *resp_buf, uint32_t resp_buf_len, uint32_t *reqd_resp_len)
5022 {
5023     uint32_t ret = WM_SUCCESS;
5024     /* Store IN & OUT params to be used by driver to update internaally*/
5025     /* These variables are updated from reponse handlers */
5026     wm_wifi.hostcmd_cfg.resp_buf      = resp_buf;
5027     wm_wifi.hostcmd_cfg.resp_buf_len  = resp_buf_len;
5028     wm_wifi.hostcmd_cfg.reqd_resp_len = reqd_resp_len;
5029 
5030     /* Check if command is larger than the command size that can be handled by firmware */
5031     if (cmd_buf_len > WIFI_FW_CMDBUF_SIZE)
5032     {
5033         *reqd_resp_len = 0;
5034         return WM_E_INBIG;
5035     }
5036     else if (cmd_buf_len < WIFI_HOST_CMD_FIXED_HEADER_LEN)
5037     /* Check if command is smaller than the minimum command size needed, which is WIFI_HOST_CMD_FIXED_HEADER_LEN */
5038     {
5039         *reqd_resp_len = 0;
5040         return WM_E_INSMALL;
5041     }
5042     else
5043     {
5044         /* Do Nothing */
5045     }
5046     (void)wifi_get_command_lock();
5047     /* Copy command buffer to driver command buffer */
5048     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5049     (void)memcpy((void *)cmd, (const void *)cmd_buf, cmd_buf_len);
5050 
5051     /* Set global variable to say that this command is from user invocation */
5052     wm_wifi.hostcmd_cfg.is_hostcmd = true;
5053     (void)wifi_wait_for_cmdresp(&wm_wifi.hostcmd_cfg);
5054 
5055     if (*reqd_resp_len > resp_buf_len)
5056     {
5057         ret = WM_E_OUTBIG;
5058     }
5059     /*Response fail check not checked here, as thats caller's responsibility */
5060     return ret;
5061 }
5062 
5063 #if CONFIG_WIFI_EU_CRYPTO
wifi_set_eu_crypto(EU_Crypto * Crypto_Data,enum _crypto_algorithm Algorithm,t_u16 EncDec)5064 int wifi_set_eu_crypto(EU_Crypto *Crypto_Data, enum _crypto_algorithm Algorithm, t_u16 EncDec)
5065 {
5066     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5067     t_u16 cmd_size;
5068     t_u16 *DataLength = Crypto_Data->DataLength;
5069 
5070     wifi_get_command_lock();
5071 
5072     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
5073     cmd->command = HostCmd_CMD_EU_CRYPTO;
5074     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, MLAN_BSS_ROLE_STA);
5075 
5076     switch (Algorithm)
5077     {
5078         case CRYPTO_RC4:
5079         case CRYPTO_AES_ECB:
5080         case CRYPTO_AES_WRAP:
5081         {
5082             cmd_size                        = sizeof(HostCmd_DS_EU_CRYPTO) - 1 + 8 /*cmd header */;
5083             cmd->params.eu_crypto.Algorithm = Algorithm;
5084             cmd->params.eu_crypto.KeyLength = Crypto_Data->KeyLength;
5085             memcpy(cmd->params.eu_crypto.Key, Crypto_Data->Key, Crypto_Data->KeyLength);
5086             cmd->params.eu_crypto.KeyIVLength = Crypto_Data->KeyIVLength;
5087             memcpy(cmd->params.eu_crypto.KeyIV, Crypto_Data->KeyIV, Crypto_Data->KeyIVLength);
5088             cmd->params.eu_crypto.DataLength = *DataLength;
5089             memcpy(cmd->params.eu_crypto.Data, Crypto_Data->Data, *DataLength);
5090             cmd_size += cmd->params.eu_crypto.DataLength;
5091             cmd->params.eu_crypto.EncDec   = EncDec;
5092             cmd->params.eu_crypto.DataType = 0x0111;
5093             break;
5094         }
5095         case CRYPTO_AES_CCMP:
5096         case CRYPTO_AES_GCMP:
5097         {
5098             cmd_size                            = sizeof(HostCmd_DS_EU_AES_CRYPTO) - 1 + 8 /* cmd header */;
5099             cmd->params.eu_aes_crypto.Algorithm = Algorithm;
5100             cmd->params.eu_aes_crypto.KeyLength = Crypto_Data->KeyLength;
5101             memcpy(cmd->params.eu_aes_crypto.Key, Crypto_Data->Key, Crypto_Data->KeyLength);
5102             cmd->params.eu_aes_crypto.NonceLength = Crypto_Data->NonceLength;
5103             memcpy(cmd->params.eu_aes_crypto.Nonce, Crypto_Data->Nonce, Crypto_Data->NonceLength);
5104             cmd->params.eu_aes_crypto.AADLength = Crypto_Data->AADLength;
5105             memcpy(cmd->params.eu_aes_crypto.AAD, Crypto_Data->AAD, Crypto_Data->AADLength);
5106             cmd->params.eu_aes_crypto.DataLength = *DataLength;
5107             memcpy(cmd->params.eu_aes_crypto.Data, Crypto_Data->Data, *DataLength);
5108             cmd_size += cmd->params.eu_aes_crypto.DataLength;
5109             cmd->params.eu_aes_crypto.EncDec   = EncDec;
5110             cmd->params.eu_aes_crypto.DataType = 0x0111;
5111             break;
5112         }
5113         default:
5114             return -WM_FAIL;
5115     }
5116     cmd->size = cmd_size;
5117 
5118     return wifi_wait_for_cmdresp(Crypto_Data);
5119 }
5120 #endif
5121 
wifi_set_rx_mgmt_indication(unsigned int bss_type,unsigned int mgmt_subtype_mask)5122 int wifi_set_rx_mgmt_indication(unsigned int bss_type, unsigned int mgmt_subtype_mask)
5123 {
5124     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[bss_type];
5125 
5126     mlan_ds_rx_mgmt_indication rx_mgmt_indication;
5127 
5128     memset(&rx_mgmt_indication, 0x00, sizeof(mlan_ds_rx_mgmt_indication));
5129 
5130     rx_mgmt_indication.mgmt_subtype_mask = mgmt_subtype_mask;
5131 
5132     wifi_get_command_lock();
5133     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5134 
5135     cmd->command = HostCmd_CMD_RX_MGMT_IND;
5136 #if CONFIG_P2P
5137     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, MLAN_BSS_TYPE_WIFIDIRECT);
5138 #else
5139     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0U /* seq_num */, 0U /* bss_num */, bss_type);
5140 #endif /* CONFIG_P2P */
5141     cmd->result = 0x0;
5142 
5143     wlan_cmd_rx_mgmt_indication(pmpriv, cmd, HostCmd_ACT_GEN_SET, &rx_mgmt_indication);
5144 
5145     wifi_wait_for_cmdresp(NULL);
5146 
5147     return wm_wifi.cmd_resp_status;
5148 }
5149 
5150 #if CONFIG_WPS2
5151 /* enable/disable WPS session */
wifi_send_wps_cfg_cmd(int option)5152 int wifi_send_wps_cfg_cmd(int option)
5153 {
5154     mlan_ioctl_req req;
5155     mlan_ds_wps_cfg pwps;
5156 
5157     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
5158     (void)memset(&pwps, 0x00, sizeof(mlan_ds_wps_cfg));
5159     pwps.sub_command = MLAN_OID_WPS_CFG_SESSION;
5160     if (option)
5161         pwps.param.wps_session = MLAN_WPS_CFG_SESSION_START;
5162     else
5163         pwps.param.wps_session = MLAN_WPS_CFG_SESSION_END;
5164     req.pbuf      = (t_u8 *)&pwps;
5165     req.buf_len   = sizeof(mlan_ds_wps_cfg);
5166     req.bss_index = 0;
5167     req.req_id    = MLAN_IOCTL_WPS_CFG;
5168     req.action    = MLAN_ACT_SET;
5169 
5170     mlan_status rv = wlan_ops_sta_ioctl(mlan_adap, &req);
5171     if (rv != MLAN_STATUS_SUCCESS && rv != MLAN_STATUS_PENDING)
5172     {
5173         return -WM_FAIL;
5174     }
5175 
5176     return WM_SUCCESS;
5177 }
5178 #endif /* CONFIG_WPS2 */
5179 
wifi_PrepDefaultMgtMsg(t_u8 sub_type,mlan_802_11_mac_addr * DestAddr,mlan_802_11_mac_addr * SrcAddr,mlan_802_11_mac_addr * Bssid,t_u16 pkt_len)5180 wlan_mgmt_pkt *wifi_PrepDefaultMgtMsg(t_u8 sub_type,
5181                                       mlan_802_11_mac_addr *DestAddr,
5182                                       mlan_802_11_mac_addr *SrcAddr,
5183                                       mlan_802_11_mac_addr *Bssid,
5184                                       t_u16 pkt_len)
5185 {
5186     wlan_mgmt_pkt *pmgmt_pkt_hdr    = MNULL;
5187     IEEEtypes_FrameCtl_t *mgmt_fc_p = MNULL;
5188     t_u8 *pBuf                      = MNULL;
5189 
5190 #if !CONFIG_MEM_POOLS
5191     pBuf = OSA_MemoryAllocate(pkt_len);
5192 #else
5193     pBuf         = OSA_MemoryPoolAllocate(buf_1536_MemoryPool);
5194 #endif
5195 
5196     if (pBuf == MNULL)
5197     {
5198         return MNULL;
5199     }
5200 
5201     pmgmt_pkt_hdr = (wlan_mgmt_pkt *)(void *)pBuf;
5202     /* 802.11 header */
5203     mgmt_fc_p           = (IEEEtypes_FrameCtl_t *)(void *)&pmgmt_pkt_hdr->wlan_header.frm_ctl;
5204     mgmt_fc_p->sub_type = sub_type;
5205     mgmt_fc_p->type     = (t_u8)IEEE_TYPE_MANAGEMENT;
5206     (void)memcpy(pmgmt_pkt_hdr->wlan_header.addr1, DestAddr, MLAN_MAC_ADDR_LENGTH);
5207     (void)memcpy(pmgmt_pkt_hdr->wlan_header.addr2, SrcAddr, MLAN_MAC_ADDR_LENGTH);
5208     (void)memcpy(pmgmt_pkt_hdr->wlan_header.addr3, Bssid, MLAN_MAC_ADDR_LENGTH);
5209 
5210     return pmgmt_pkt_hdr;
5211 }
5212 
5213 #if CONFIG_ECSA
5214 wifi_ecsa_status_control ecsa_status_control = {false, 0};
5215 
set_ecsa_block_tx_time(t_u8 switch_count)5216 void set_ecsa_block_tx_time(t_u8 switch_count)
5217 {
5218     ecsa_status_control.block_time = switch_count;
5219 }
5220 
get_ecsa_block_tx_time()5221 t_u8 get_ecsa_block_tx_time()
5222 {
5223     return ecsa_status_control.block_time;
5224 }
5225 
set_ecsa_block_tx_flag(bool block_tx)5226 void set_ecsa_block_tx_flag(bool block_tx)
5227 {
5228     ecsa_status_control.required = block_tx;
5229 }
5230 
get_ecsa_block_tx_flag()5231 bool get_ecsa_block_tx_flag()
5232 {
5233     return ecsa_status_control.required;
5234 }
5235 
wifi_put_ecsa_sem()5236 void wifi_put_ecsa_sem()
5237 {
5238     OSA_SemaphorePost((osa_semaphore_handle_t)ecsa_status_control.ecsa_sem);
5239 }
5240 
wlan_get_nonglobal_operclass_by_bw_channel(t_u8 bandwidth,t_u8 channel,t_u8 * oper_class)5241 int wlan_get_nonglobal_operclass_by_bw_channel(t_u8 bandwidth, t_u8 channel, t_u8 *oper_class)
5242 {
5243     int ret = 0;
5244     mlan_ioctl_req req;
5245     mlan_ds_misc_cfg *misc = NULL;
5246     mlan_status status     = MLAN_STATUS_SUCCESS;
5247 
5248     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
5249 
5250 #if !CONFIG_MEM_POOLS
5251     misc = OSA_MemoryAllocate(sizeof(mlan_ds_misc_cfg));
5252 #else
5253     misc                            = OSA_MemoryPoolAllocate(buf_512_MemoryPool);
5254 #endif
5255 
5256     if (misc == NULL)
5257     {
5258         return -WM_FAIL;
5259     }
5260 
5261     req.bss_index                      = MLAN_BSS_ROLE_UAP;
5262     req.pbuf                           = (t_u8 *)misc;
5263     misc->sub_command                  = MLAN_OID_MISC_OPER_CLASS;
5264     req.req_id                         = MLAN_IOCTL_MISC_CFG;
5265     req.action                         = MLAN_ACT_GET;
5266     misc->param.bw_chan_oper.bandwidth = bandwidth;
5267     misc->param.bw_chan_oper.channel   = channel;
5268 
5269     status = wlan_ops_uap_ioctl(mlan_adap, &req);
5270     if (status != MLAN_STATUS_SUCCESS)
5271     {
5272         wifi_e("Failed to get operclass");
5273 #if !CONFIG_MEM_POOLS
5274         OSA_MemoryFree(misc);
5275 #else
5276         OSA_MemoryPoolFree(buf_512_MemoryPool, misc);
5277 #endif
5278         return -WM_FAIL;
5279     }
5280     *oper_class = misc->param.bw_chan_oper.oper_class;
5281 
5282 #if !CONFIG_MEM_POOLS
5283     OSA_MemoryFree(misc);
5284 #else
5285     OSA_MemoryPoolFree(buf_512_MemoryPool, misc);
5286 #endif
5287 
5288     return ret;
5289 }
5290 
wifi_set_ecsa_cfg(t_u8 block_tx,t_u8 oper_class,t_u8 channel,t_u8 switch_count,t_u8 band_width,t_u8 ecsa)5291 int wifi_set_ecsa_cfg(t_u8 block_tx, t_u8 oper_class, t_u8 channel, t_u8 switch_count, t_u8 band_width, t_u8 ecsa)
5292 {
5293     IEEEtypes_ExtChanSwitchAnn_t *ext_chan_switch = NULL;
5294     IEEEtypes_ChanSwitchAnn_t *chan_switch        = NULL;
5295     custom_ie *pcust_chansw_ie                    = NULL;
5296     t_u32 usr_dot_11n_dev_cap                     = 0;
5297     mlan_private *pmpriv                          = (mlan_private *)mlan_adap->priv[1];
5298     BSSDescriptor_t *pbss_desc;
5299     pbss_desc           = &pmpriv->curr_bss_params.bss_descriptor;
5300     t_u8 new_oper_class = oper_class;
5301     t_u8 bw;
5302     int ret = MLAN_STATUS_SUCCESS;
5303 #if (CONFIG_11AC)
5304     t_u8 center_freq_idx                       = 0;
5305     IEEEtypes_Header_t *pChanSwWrap_ie         = NULL;
5306     IEEEtypes_WideBWChanSwitch_t *pbwchansw_ie = NULL;
5307     IEEEtypes_VhtTpcEnvelope_t *pvhttpcEnv_ie  = NULL;
5308 #endif
5309     uint8_t *buf               = NULL;
5310     tlvbuf_custom_ie *tlv      = NULL;
5311     unsigned int mgmt_ie_index = -1;
5312     int total_len = sizeof(tlvbuf_custom_ie) + (sizeof(custom_ie) - MAX_IE_SIZE) + sizeof(IEEEtypes_ChanSwitchAnn_t) +
5313                     sizeof(IEEEtypes_ExtChanSwitchAnn_t);
5314 #if (CONFIG_11AC)
5315     total_len += sizeof(IEEEtypes_WideBWChanSwitch_t) + sizeof(IEEEtypes_VhtTpcEnvelope_t) + sizeof(IEEEtypes_Header_t);
5316 #endif
5317     uint16_t buf_len = 0;
5318 
5319 #if !CONFIG_MEM_POOLS
5320     buf = (uint8_t *)OSA_MemoryAllocate(total_len);
5321 #else
5322     buf = OSA_MemoryPoolAllocate(buf_1024_MemoryPool);
5323 #endif
5324     if (!buf)
5325     {
5326         wifi_e("ECSA allocate memory failed \r\n");
5327         return -WM_FAIL;
5328     }
5329 
5330     (void)memset(buf, 0, total_len);
5331     tlv       = (tlvbuf_custom_ie *)buf;
5332     tlv->type = MRVL_MGMT_IE_LIST_TLV_ID;
5333 
5334     ret = get_free_mgmt_ie_index(&mgmt_ie_index);
5335     if (WM_SUCCESS != ret)
5336     {
5337 #if !CONFIG_MEM_POOLS
5338         OSA_MemoryFree(buf);
5339 #else
5340         OSA_MemoryPoolFree(buf_1024_MemoryPool, buf);
5341 #endif
5342         return -WM_FAIL;
5343     }
5344 
5345     pcust_chansw_ie                    = (custom_ie *)(tlv->ie_data);
5346     pcust_chansw_ie->ie_index          = mgmt_ie_index;
5347     pcust_chansw_ie->ie_length         = sizeof(IEEEtypes_ChanSwitchAnn_t);
5348     pcust_chansw_ie->mgmt_subtype_mask = MGMT_MASK_BEACON | MGMT_MASK_PROBE_RESP; /*Add IE for
5349                                                                  BEACON/probe resp*/
5350     chan_switch                    = (IEEEtypes_ChanSwitchAnn_t *)pcust_chansw_ie->ie_buffer;
5351     chan_switch->element_id        = CHANNEL_SWITCH_ANN;
5352     chan_switch->len               = 3;
5353     chan_switch->chan_switch_mode  = block_tx;
5354     chan_switch->new_channel_num   = channel;
5355     chan_switch->chan_switch_count = switch_count;
5356     DBG_HEXDUMP(MCMD_D, "CSA IE", (t_u8 *)pcust_chansw_ie->ie_buffer, pcust_chansw_ie->ie_length);
5357 
5358 #if CONFIG_5GHz_SUPPORT
5359     if (pbss_desc->bss_band & BAND_A)
5360         usr_dot_11n_dev_cap = mlan_adap->usr_dot_11n_dev_cap_a;
5361     else
5362 #endif
5363         usr_dot_11n_dev_cap = mlan_adap->usr_dot_11n_dev_cap_bg;
5364 
5365     if (!ISSUPP_CHANWIDTH40(usr_dot_11n_dev_cap))
5366     {
5367         band_width = 0;
5368     }
5369 
5370     switch (band_width)
5371     {
5372         case CHANNEL_BW_40MHZ_ABOVE:
5373         case CHANNEL_BW_40MHZ_BELOW:
5374             bw = 40;
5375             break;
5376 #if (CONFIG_11AC)
5377         case CHANNEL_BW_80MHZ:
5378             bw = 80;
5379             break;
5380         case CHANNEL_BW_160MHZ:
5381             bw = 160;
5382             break;
5383 #endif
5384         default:
5385             bw = 20;
5386             break;
5387     }
5388 
5389     if (!new_oper_class && ecsa)
5390         wlan_get_nonglobal_operclass_by_bw_channel(bw, channel, &new_oper_class);
5391 
5392     if (new_oper_class)
5393     {
5394         pcust_chansw_ie->ie_length += sizeof(IEEEtypes_ExtChanSwitchAnn_t);
5395         ext_chan_switch =
5396             (IEEEtypes_ExtChanSwitchAnn_t *)(pcust_chansw_ie->ie_buffer + sizeof(IEEEtypes_ChanSwitchAnn_t));
5397         ext_chan_switch->element_id        = EXTEND_CHANNEL_SWITCH_ANN;
5398         ext_chan_switch->len               = 4;
5399         ext_chan_switch->chan_switch_mode  = block_tx;
5400         ext_chan_switch->new_oper_class    = new_oper_class;
5401         ext_chan_switch->new_channel_num   = channel;
5402         ext_chan_switch->chan_switch_count = switch_count;
5403         DBG_HEXDUMP(MCMD_D, "ECSA IE", (t_u8 *)(pcust_chansw_ie->ie_buffer + sizeof(IEEEtypes_ChanSwitchAnn_t)),
5404                     pcust_chansw_ie->ie_length - sizeof(IEEEtypes_ChanSwitchAnn_t));
5405     }
5406 
5407 #if (CONFIG_11AC)
5408     /* bandwidth 40/80/160 should set channel switch wrapper ie for 11ac 5G
5409      * channel*/
5410     if (band_width && channel > 14)
5411     {
5412         pChanSwWrap_ie             = (IEEEtypes_Header_t *)(pcust_chansw_ie->ie_buffer + pcust_chansw_ie->ie_length);
5413         pChanSwWrap_ie->element_id = EXT_POWER_CONSTR;
5414         pChanSwWrap_ie->len        = sizeof(IEEEtypes_WideBWChanSwitch_t);
5415 
5416         pbwchansw_ie = (IEEEtypes_WideBWChanSwitch_t *)((t_u8 *)pChanSwWrap_ie + sizeof(IEEEtypes_Header_t));
5417         pbwchansw_ie->ieee_hdr.element_id = BW_CHANNEL_SWITCH;
5418         pbwchansw_ie->ieee_hdr.len        = sizeof(IEEEtypes_WideBWChanSwitch_t) - sizeof(IEEEtypes_Header_t);
5419 
5420         center_freq_idx = wlan_get_center_freq_idx((mlan_private *)mlan_adap->priv[1], BAND_AAC, channel, band_width);
5421         if (band_width == CHANNEL_BW_40MHZ_ABOVE || band_width == CHANNEL_BW_40MHZ_BELOW)
5422         {
5423             pbwchansw_ie->new_channel_width        = 0;
5424             pbwchansw_ie->new_channel_center_freq0 = center_freq_idx;
5425         }
5426         else if (band_width == CHANNEL_BW_80MHZ)
5427         {
5428             pbwchansw_ie->new_channel_width        = 1;
5429             pbwchansw_ie->new_channel_center_freq0 = center_freq_idx - 4;
5430             pbwchansw_ie->new_channel_center_freq1 = center_freq_idx + 4;
5431         }
5432         else if (band_width == CHANNEL_BW_160MHZ)
5433         {
5434             pbwchansw_ie->new_channel_width        = 2;
5435             pbwchansw_ie->new_channel_center_freq0 = center_freq_idx - 8;
5436             pbwchansw_ie->new_channel_center_freq1 = center_freq_idx + 8;
5437         }
5438         else
5439             wifi_e("Invalid bandwidth.Support value 1/3/4/5 for 40+/40-/80/160MHZ\n");
5440 
5441         /*prepare the VHT Transmit Power Envelope IE*/
5442         pvhttpcEnv_ie = (IEEEtypes_VhtTpcEnvelope_t *)((t_u8 *)pChanSwWrap_ie + sizeof(IEEEtypes_Header_t) +
5443                                                        sizeof(IEEEtypes_WideBWChanSwitch_t));
5444         pvhttpcEnv_ie->ieee_hdr.element_id = VHT_TX_POWER_ENV;
5445         pvhttpcEnv_ie->ieee_hdr.len        = sizeof(IEEEtypes_VhtTpcEnvelope_t) - sizeof(IEEEtypes_Header_t);
5446         /* Local Max TX Power Count= 3,
5447          * Local TX Power Unit Inter=EIP(0) */
5448         pvhttpcEnv_ie->tpc_info                     = 3;
5449         pvhttpcEnv_ie->local_max_tp_20mhz           = 0xff;
5450         pvhttpcEnv_ie->local_max_tp_40mhz           = 0xff;
5451         pvhttpcEnv_ie->local_max_tp_80mhz           = 0xff;
5452         pvhttpcEnv_ie->local_max_tp_160mhz_80_80mhz = 0xff;
5453         pChanSwWrap_ie->len += sizeof(IEEEtypes_VhtTpcEnvelope_t);
5454         pcust_chansw_ie->ie_length += pChanSwWrap_ie->len + sizeof(IEEEtypes_Header_t);
5455         DBG_HEXDUMP(MCMD_D, "Channel switch wrapper IE", (t_u8 *)pChanSwWrap_ie,
5456                     pChanSwWrap_ie->len + sizeof(IEEEtypes_Header_t));
5457     }
5458 #endif
5459     tlv->length = sizeof(custom_ie) + pcust_chansw_ie->ie_length - MAX_IE_SIZE;
5460 
5461     buf_len = pcust_chansw_ie->ie_length + sizeof(tlvbuf_custom_ie) + sizeof(custom_ie) - MAX_IE_SIZE;
5462 
5463     ret = wrapper_wlan_cmd_mgmt_ie(MLAN_BSS_TYPE_UAP, buf, buf_len, HostCmd_ACT_GEN_SET);
5464     if (ret != MLAN_STATUS_SUCCESS && ret != MLAN_STATUS_PENDING)
5465     {
5466         wifi_e("Failed to set ECSA IE");
5467 #if !CONFIG_MEM_POOLS
5468         OSA_MemoryFree(buf);
5469 #else
5470         OSA_MemoryPoolFree(buf_1024_MemoryPool, buf);
5471 #endif
5472         return -WM_FAIL;
5473     }
5474     set_ie_index(mgmt_ie_index);
5475 
5476     OSA_SemaphoreWait((osa_semaphore_handle_t)ecsa_status_control.ecsa_sem, (switch_count + 2) * wm_wifi.beacon_period);
5477     set_ecsa_block_tx_flag(false);
5478 
5479     if (!ie_index_is_set(mgmt_ie_index))
5480     {
5481 #if !CONFIG_MEM_POOLS
5482         OSA_MemoryFree(buf);
5483 #else
5484         OSA_MemoryPoolFree(buf_1024_MemoryPool, buf);
5485 #endif
5486         return -WM_FAIL;
5487     }
5488 
5489     /*Clear ECSA ie*/
5490     (void)memset(buf, 0, total_len);
5491     tlv         = (tlvbuf_custom_ie *)buf;
5492     tlv->type   = MRVL_MGMT_IE_LIST_TLV_ID;
5493     tlv->length = sizeof(custom_ie) - MAX_IE_SIZE;
5494 
5495     pcust_chansw_ie->mgmt_subtype_mask = MGMT_MASK_CLEAR;
5496     pcust_chansw_ie->ie_length         = 0;
5497     pcust_chansw_ie->ie_index          = mgmt_ie_index;
5498     buf_len                            = sizeof(tlvbuf_custom_ie) + tlv->length;
5499 
5500     ret = wrapper_wlan_cmd_mgmt_ie(MLAN_BSS_TYPE_UAP, buf, buf_len, HostCmd_ACT_GEN_SET);
5501     if (ret != MLAN_STATUS_SUCCESS && ret != MLAN_STATUS_PENDING)
5502     {
5503         wifi_e("Failed to clear ECSA IE");
5504 #if !CONFIG_MEM_POOLS
5505         OSA_MemoryFree(buf);
5506 #else
5507         OSA_MemoryPoolFree(buf_1024_MemoryPool, buf);
5508 #endif
5509         return -WM_FAIL;
5510     }
5511     clear_ie_index(mgmt_ie_index);
5512 
5513 #if !CONFIG_MEM_POOLS
5514     OSA_MemoryFree(buf);
5515 #else
5516     OSA_MemoryPoolFree(buf_1024_MemoryPool, buf);
5517 #endif
5518 
5519     return WM_SUCCESS;
5520 }
5521 
wifi_set_action_ecsa_cfg(t_u8 block_tx,t_u8 oper_class,t_u8 channel,t_u8 switch_count)5522 int wifi_set_action_ecsa_cfg(t_u8 block_tx, t_u8 oper_class, t_u8 channel, t_u8 switch_count)
5523 {
5524     mlan_status ret  = MLAN_STATUS_SUCCESS;
5525     mlan_ds_bss *bss = NULL;
5526     mlan_ioctl_req req;
5527 
5528     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
5529 
5530 #if !CONFIG_MEM_POOLS
5531     bss = OSA_MemoryAllocate(sizeof(mlan_ds_bss));
5532 #else
5533     bss = OSA_MemoryPoolAllocate(buf_1024_MemoryPool);
5534 #endif
5535 
5536     if (bss == NULL)
5537     {
5538         return -WM_FAIL;
5539     }
5540 
5541     req.bss_index                           = MLAN_BSS_ROLE_UAP;
5542     req.pbuf                                = (t_u8 *)bss;
5543     bss->sub_command                        = MLAN_OID_ACTION_CHAN_SWITCH;
5544     req.req_id                              = MLAN_IOCTL_BSS;
5545     req.action                              = MLAN_ACT_SET;
5546     bss->param.chanswitch.chan_switch_mode  = block_tx;
5547     bss->param.chanswitch.new_channel_num   = channel;
5548     bss->param.chanswitch.chan_switch_count = switch_count;
5549     bss->param.chanswitch.new_oper_class    = oper_class;
5550 
5551     ret = wlan_ops_uap_ioctl(mlan_adap, &req);
5552 
5553     if (ret != MLAN_STATUS_SUCCESS && ret != MLAN_STATUS_PENDING)
5554     {
5555         wifi_e("Failed to set ECSA IE");
5556 #if !CONFIG_MEM_POOLS
5557         OSA_MemoryFree(bss);
5558 #else
5559         OSA_MemoryPoolFree(buf_1024_MemoryPool, bss);
5560 #endif
5561         return -WM_FAIL;
5562     }
5563 #if !CONFIG_MEM_POOLS
5564     OSA_MemoryFree(bss);
5565 #else
5566     OSA_MemoryPoolFree(buf_1024_MemoryPool, bss);
5567 #endif
5568 
5569     return WM_SUCCESS;
5570 }
5571 
5572 #endif
5573 
5574 #define SUBTYPE_AUTH          11
5575 #define AUTH_REQUEST_BUF_SIZE 512
5576 
5577 #if CONFIG_WPA_SUPP
5578 
5579 #if CONFIG_11R
wifi_same_ess_ft()5580 bool wifi_same_ess_ft()
5581 {
5582     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
5583 
5584     return pmpriv->auth_alg == MLAN_AUTH_MODE_FT ? true : false;
5585 }
5586 #endif
5587 
wifi_nxp_set_default_scan_ies(const u8 * ies,size_t ies_len)5588 int wifi_nxp_set_default_scan_ies(const u8 *ies, size_t ies_len)
5589 {
5590     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
5591 
5592     if (ies && ies_len < sizeof(pmpriv->default_scan_ies))
5593     {
5594         pmpriv->default_scan_ies_len = ies_len;
5595         memcpy(pmpriv->default_scan_ies, ies, ies_len);
5596     }
5597 
5598     return WM_SUCCESS;
5599 }
5600 
5601 #define HEADER_SIZE 8
5602 // frmctl + durationid + addr1 + addr2 + addr3 + seqctl + addr4
5603 #define MGMT_HEADER_LEN (2 + 2 + 6 + 6 + 6 + 2 + 6)
5604 // 6   = auth_alg + auth_transaction +auth_status
5605 #define AUTH_BODY_LEN 6
5606 
wlan_send_mgmt_auth_request(mlan_private * pmpriv,const t_u8 channel,const t_u8 auth_alg,const t_u8 * auth_seq_num,const t_u8 * status_code,const t_u8 * dest,const t_u8 * sae_data,const t_u16 sae_data_len)5607 static int wlan_send_mgmt_auth_request(mlan_private *pmpriv,
5608                                        const t_u8 channel,
5609                                        const t_u8 auth_alg,
5610                                        const t_u8 *auth_seq_num,
5611                                        const t_u8 *status_code,
5612                                        const t_u8 *dest,
5613                                        const t_u8 *sae_data,
5614                                        const t_u16 sae_data_len)
5615 {
5616     mlan_adapter *pmadapter      = pmpriv->adapter;
5617     t_u16 pkt_len                = 0;
5618     mlan_802_11_mac_addr *da     = MNULL;
5619     mlan_802_11_mac_addr *sa     = MNULL;
5620     wlan_mgmt_pkt *pmgmt_pkt_hdr = MNULL;
5621     t_u8 *pos                    = MNULL;
5622     int meas_pkt_len             = 0;
5623     t_s32 i                      = -1;
5624     BSSDescriptor_t *pbss_desc   = MNULL;
5625     WLAN_802_11_RATES rates = {0x00};
5626     t_u32 rates_size;
5627     t_u8 addr[]                  = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
5628     t_u8 baserates[] = {0x82, 0x84, 0x8b, 0x96, 0x8c, 0x98, 0xb0};
5629 
5630     if (pmpriv->bss_index != (t_u8)MLAN_BSS_ROLE_STA)
5631     {
5632         wifi_d("invalid interface %d for sending auth request", pmpriv->bss_index);
5633         return (int)MLAN_STATUS_FAILURE;
5634     }
5635 
5636     da = (mlan_802_11_mac_addr *)(void *)dest;
5637     sa = (mlan_802_11_mac_addr *)(void *)(&pmpriv->curr_addr[0]);
5638 
5639     i = wlan_find_bssid_in_list(pmpriv, dest, MLAN_BSS_MODE_AUTO);
5640     if (i >= 0)
5641     {
5642         pbss_desc = &pmadapter->pscan_table[i];
5643         if (wlan_setup_rates_from_bssdesc(pmpriv, pbss_desc, rates, &rates_size) != MLAN_STATUS_SUCCESS)
5644         {
5645             wifi_d("Not support the rates");
5646             return (int)MLAN_STATUS_FAILURE;
5647         }
5648         t_u8 *prate = (t_u8 *)&(pbss_desc->supported_rates);
5649         t_u8 rateIndex = 0xff;
5650 
5651         for (int j = 0; j < rates_size; j++)
5652         {
5653             if (prate[j] >= 0x82)
5654             {
5655                 for (int k = 0; k < sizeof(baserates); k++)
5656                 {
5657                     if (prate[j] == baserates[k] && k < rateIndex)
5658                     rateIndex = k;
5659                 }
5660             }
5661         }
5662         pmpriv->pkt_tx_ctrl |= 1 << 15;
5663         switch (baserates[rateIndex])
5664         {
5665         case 0x82:
5666             pmpriv->pkt_tx_ctrl |= 0 << 16;
5667             break;
5668         case 0x84:
5669             pmpriv->pkt_tx_ctrl |= 1 << 16;
5670             break;
5671         case 0x8b:
5672             pmpriv->pkt_tx_ctrl |= 2 << 16;
5673             break;
5674         case 0x96:
5675             pmpriv->pkt_tx_ctrl |= 3 << 16;
5676             break;
5677         case 0x8c:
5678             pmpriv->pkt_tx_ctrl |= 5 << 16;
5679             break;
5680         case 0x98:
5681             pmpriv->pkt_tx_ctrl |= 7 << 16;
5682             break;
5683         case 0xb0:
5684             pmpriv->pkt_tx_ctrl |= 9 << 16;
5685             break;
5686         default:
5687             pmpriv->pkt_tx_ctrl = 0;
5688             wifi_d("Not support the base rates");
5689             break;
5690         }
5691     }
5692     if (pmadapter->cmd_tx_data == 1U)
5693     {
5694         (void)wifi_get_command_lock();
5695         HostCmd_DS_COMMAND *cmd           = wifi_get_command_buffer();
5696         mlan_ds_misc_tx_frame tx_frame    = {0};
5697         wlan_802_11_header *pwlan_pkt_hdr = MNULL;
5698         IEEEtypes_FrameCtl_t *mgmt_fc_p   = MNULL;
5699         t_u8 *pBuf                        = &tx_frame.tx_buf[0];
5700         t_u32 pkt_type;
5701 
5702         pkt_len = MGMT_HEADER_LEN + AUTH_BODY_LEN;
5703 
5704         memset(cmd, 0x00, pkt_len);
5705 
5706         pkt_type   = MRVL_PKT_TYPE_MGMT_FRAME;
5707 
5708         /* Add pkt_type and tx_control */
5709         memcpy(pBuf, &pkt_type, sizeof(pkt_type));
5710         memcpy(pBuf + sizeof(pkt_type), &(pmpriv->pkt_tx_ctrl), sizeof(pmpriv->pkt_tx_ctrl));
5711 
5712         pwlan_pkt_hdr = (wlan_802_11_header *)(void *)(pBuf + HEADER_SIZE + sizeof(pkt_len));
5713         /* 802.11 header */
5714         mgmt_fc_p           = (IEEEtypes_FrameCtl_t *)(void *)&pwlan_pkt_hdr->frm_ctl;
5715         mgmt_fc_p->sub_type = SUBTYPE_AUTH;
5716         mgmt_fc_p->type     = (t_u8)IEEE_TYPE_MANAGEMENT;
5717         (void)memcpy(pwlan_pkt_hdr->addr1, da, MLAN_MAC_ADDR_LENGTH);
5718         (void)memcpy(pwlan_pkt_hdr->addr2, sa, MLAN_MAC_ADDR_LENGTH);
5719         (void)memcpy(pwlan_pkt_hdr->addr3, da, MLAN_MAC_ADDR_LENGTH);
5720 
5721         (void)memcpy(pwlan_pkt_hdr->addr4, addr, MLAN_MAC_ADDR_LENGTH);
5722 
5723         /* 802.11 management body */
5724         pos    = (t_u8 *)pwlan_pkt_hdr + sizeof(wlan_802_11_header);
5725         pos[0] = auth_alg;
5726         pos[1] = 0;
5727         pos[2] = auth_seq_num[0];
5728         pos[3] = auth_seq_num[1];
5729         pos[4] = status_code[0];
5730         pos[5] = status_code[1];
5731 
5732         pos += 6;
5733 
5734         if ((sae_data != NULL) && (sae_data_len > 0))
5735         {
5736             memcpy(pos, sae_data, sae_data_len);
5737             pos += sae_data_len;
5738         }
5739 
5740         meas_pkt_len = pos - (t_u8 *)pwlan_pkt_hdr;
5741         pkt_len      = (t_u16)meas_pkt_len;
5742 
5743         /*Add packet len*/
5744         pkt_len = wlan_cpu_to_le16(pkt_len);
5745         memcpy(pBuf + HEADER_SIZE, &pkt_len, sizeof(pkt_len));
5746 
5747         tx_frame.bandcfg.chanBand = channel > 14 ? BAND_5GHZ : BAND_2GHZ;
5748         tx_frame.channel          = channel;
5749         tx_frame.data_len         = HEADER_SIZE + pkt_len + 2 * sizeof(pkt_len);
5750         tx_frame.buf_type         = MLAN_BUF_TYPE_RAW_DATA;
5751         tx_frame.priority         = 7;
5752 
5753         cmd->seq_num = 0x0;
5754         cmd->result  = 0x0;
5755 
5756         mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_TX_FRAME,
5757                                                   HostCmd_ACT_GEN_SET, 0, NULL, &tx_frame, cmd);
5758         if (rv != MLAN_STATUS_SUCCESS)
5759         {
5760             return -WM_FAIL;
5761         }
5762 
5763         (void)wifi_wait_for_cmdresp(NULL);
5764         return wm_wifi.cmd_resp_status;
5765     }
5766     else
5767     {
5768         pmgmt_pkt_hdr = wifi_PrepDefaultMgtMsg(SUBTYPE_AUTH, da, sa, da, sizeof(wlan_mgmt_pkt) + AUTH_REQUEST_BUF_SIZE);
5769         if (pmgmt_pkt_hdr == MNULL)
5770         {
5771             wifi_e("No memory for auth request");
5772             return (int)MLAN_STATUS_FAILURE;
5773         }
5774 
5775         (void)memcpy(pmgmt_pkt_hdr->wlan_header.addr4, addr, MLAN_MAC_ADDR_LENGTH);
5776 
5777         /* 802.11 management body */
5778         pos    = (t_u8 *)pmgmt_pkt_hdr + sizeof(wlan_mgmt_pkt);
5779         pos[0] = auth_alg;
5780         pos[1] = 0;
5781         pos[2] = auth_seq_num[0];
5782         pos[3] = auth_seq_num[1];
5783         pos[4] = status_code[0];
5784         pos[5] = status_code[1];
5785 
5786         pos += 6;
5787 
5788         if ((sae_data != NULL) && (sae_data_len > 0))
5789         {
5790             memcpy(pos, sae_data, sae_data_len);
5791             pos += sae_data_len;
5792         }
5793 
5794         meas_pkt_len           = pos - (t_u8 *)pmgmt_pkt_hdr;
5795         pkt_len                = (t_u16)meas_pkt_len;
5796         pmgmt_pkt_hdr->frm_len = pkt_len - (t_u16)sizeof(pmgmt_pkt_hdr->frm_len);
5797 
5798         (void)wifi_inject_frame(WLAN_BSS_TYPE_STA, (t_u8 *)pmgmt_pkt_hdr, pkt_len);
5799 
5800 #if !CONFIG_MEM_POOLS
5801         OSA_MemoryFree(pmgmt_pkt_hdr);
5802 #else
5803         OSA_MemoryPoolFree(buf_1536_MemoryPool, pmgmt_pkt_hdr);
5804 #endif
5805     }
5806 
5807     pmpriv->pkt_tx_ctrl = 0;
5808     return (int)MLAN_STATUS_SUCCESS;
5809 }
5810 
wifi_send_mgmt_auth_request(const t_u8 channel,const t_u8 auth_alg,const t_u8 * auth_seq_num,const t_u8 * status_code,const t_u8 * dest,const t_u8 * sae_data,const t_u16 sae_data_len)5811 int wifi_send_mgmt_auth_request(const t_u8 channel,
5812                                 const t_u8 auth_alg,
5813                                 const t_u8 *auth_seq_num,
5814                                 const t_u8 *status_code,
5815                                 const t_u8 *dest,
5816                                 const t_u8 *sae_data,
5817                                 const t_u16 sae_data_len)
5818 {
5819     mlan_private *pmpriv = (mlan_private *)mlan_adap->priv[0];
5820     int ret;
5821 
5822     if ((pmpriv->auth_alg != WLAN_AUTH_SAE) && (pmpriv->auth_flag & HOST_MLME_AUTH_PENDING))
5823     {
5824         wifi_d("pending auth on going");
5825         return -WM_FAIL;
5826     }
5827 
5828 #if CONFIG_11R
5829     if (auth_alg == MLAN_AUTH_MODE_FT)
5830     {
5831         pmpriv->ft_roam = MTRUE;
5832     }
5833 #endif
5834 
5835     if (pmpriv->auth_flag == 0)
5836     {
5837         wifi_set_rx_mgmt_indication(MLAN_BSS_TYPE_STA, WIFI_MGMT_AUTH | WIFI_MGMT_DEAUTH | WIFI_MGMT_DIASSOC);
5838 
5839         wifi_remain_on_channel(true, channel, 2400);
5840     }
5841 
5842     pmpriv->curr_bss_params.host_mlme = 1;
5843     pmpriv->auth_flag                 = HOST_MLME_AUTH_PENDING;
5844     pmpriv->auth_alg                  = wlan_cpu_to_le16(auth_alg);
5845 
5846     ret =
5847         wlan_send_mgmt_auth_request(pmpriv, channel, auth_alg, auth_seq_num, status_code, dest, sae_data, sae_data_len);
5848 
5849     if (ret != WM_SUCCESS)
5850     {
5851         wifi_set_rx_mgmt_indication(MLAN_BSS_TYPE_STA, 0);
5852         wifi_remain_on_channel(false, 0, 0);
5853 
5854         pmpriv->curr_bss_params.host_mlme = 0;
5855         pmpriv->auth_flag                 = 0;
5856         pmpriv->auth_alg                  = 0xFFFF;
5857 #if CONFIG_11R
5858         pmpriv->ft_roam = MFALSE;
5859 #endif
5860     }
5861     return ret;
5862 }
5863 #endif
5864 
5865 #if CONFIG_WMM_UAPSD
wifi_set_wmm_qos_cfg(t_u8 qos_cfg)5866 int wifi_set_wmm_qos_cfg(t_u8 qos_cfg)
5867 {
5868     mlan_status ret = MLAN_STATUS_SUCCESS;
5869     mlan_ioctl_req req;
5870     mlan_ds_wmm_cfg cfg;
5871 
5872     (void)memset(&req, 0x00, sizeof(mlan_ioctl_req));
5873     (void)memset(&cfg, 0x00, sizeof(mlan_ds_wmm_cfg));
5874     cfg.sub_command   = MLAN_OID_WMM_CFG_QOS;
5875     cfg.param.qos_cfg = qos_cfg;
5876     req.pbuf          = (t_u8 *)&cfg;
5877     req.buf_len       = sizeof(mlan_ds_wmm_cfg);
5878     req.req_id        = MLAN_IOCTL_WMM_CFG;
5879     req.action        = MLAN_ACT_SET;
5880 
5881     ret = wlan_ops_sta_ioctl(mlan_adap, &req);
5882     return ret;
5883 }
5884 
wifi_set_sleep_period(uint16_t sleep_period)5885 void wifi_set_sleep_period(uint16_t sleep_period)
5886 {
5887     wifi_get_command_lock();
5888     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5889     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
5890     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, MLAN_BSS_TYPE_STA);
5891     cmd->result  = 0x0;
5892     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_SLEEP_PERIOD, HostCmd_ACT_GEN_SET,
5893                              0, NULL, &sleep_period, cmd);
5894     wifi_wait_for_cmdresp(NULL);
5895 }
5896 #endif
5897 
5898 #if CONFIG_11AX
5899 #if CONFIG_MMSF
wifi_mmsf_cfg(const t_u16 action,t_u8 * enable,t_u8 * Density,t_u8 * MMSF)5900 int wifi_mmsf_cfg(const t_u16 action, t_u8 *enable, t_u8 *Density, t_u8 *MMSF)
5901 {
5902     wifi_get_command_lock();
5903     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5904     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
5905 
5906     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_DBGS_CFG);
5907     cmd->size    = S_DS_GEN;
5908 
5909     HostCmd_DS_MMSF_CFG *MMSF_CFG = (HostCmd_DS_MMSF_CFG *)&cmd->params.mmsf_cfg;
5910     MMSF_CFG->action              = wlan_cpu_to_le16(action);
5911     MMSF_CFG->sub_id              = wlan_cpu_to_le16(MLAN_11AX_DEBUG_MMSF_SUBID);
5912 
5913     (void)memcpy(&MMSF_CFG->enableMMSF, enable, sizeof(MMSF_CFG->enableMMSF));
5914     (void)memcpy(&MMSF_CFG->ampduDensity, Density, sizeof(MMSF_CFG->ampduDensity));
5915     (void)memcpy(&MMSF_CFG->ampduMMSF, MMSF, sizeof(MMSF_CFG->ampduMMSF));
5916 
5917     cmd->size += sizeof(HostCmd_DS_MMSF_CFG);
5918     cmd->size = wlan_cpu_to_le16(cmd->size);
5919 
5920     if (action == ACTION_SET)
5921     {
5922         return wifi_wait_for_cmdresp(NULL);
5923     }
5924     else
5925     {
5926         wifi_mmsf_cfg_t mmsf_cfg_resp;
5927         mmsf_cfg_resp.enable  = enable;
5928         mmsf_cfg_resp.Density = Density;
5929         mmsf_cfg_resp.MMSF    = MMSF;
5930         return wifi_wait_for_cmdresp(&mmsf_cfg_resp);
5931     }
5932 }
5933 #endif
5934 #endif
5935 
5936 #if CONFIG_WIFI_RECOVERY
wifi_recovery_test(void)5937 int wifi_recovery_test(void)
5938 {
5939     wifi_get_command_lock();
5940     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5941     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
5942 
5943     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_DBGS_CFG);
5944     cmd->size    = S_DS_GEN;
5945     //HostCmd_DS_TMRC_CFG tmrc_cfg;
5946 
5947     HostCmd_DS_TMRC_CFG *tmrc_cfg = (HostCmd_DS_TMRC_CFG *)&cmd->params.tmrc_cfg;
5948     tmrc_cfg->action              = wlan_cpu_to_le16(HostCmd_ACT_GEN_GET);
5949     tmrc_cfg->sub_id              = wlan_cpu_to_le16(MLAN_RECOVERY_TEST_SUBID);
5950 
5951     cmd->size += sizeof(HostCmd_DS_TMRC_CFG);
5952     cmd->size = wlan_cpu_to_le16(cmd->size);
5953 
5954     return wifi_wait_for_cmdresp(NULL);
5955 }
5956 #endif
5957 
5958 #if CONFIG_TX_AMPDU_PROT_MODE
wifi_tx_ampdu_prot_mode(tx_ampdu_prot_mode_para * prot_mode,t_u16 action)5959 int wifi_tx_ampdu_prot_mode(tx_ampdu_prot_mode_para *prot_mode, t_u16 action)
5960 {
5961     wifi_get_command_lock();
5962     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5963 
5964     cmd->seq_num = 0x00;
5965     cmd->result  = 0x0;
5966 
5967     wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_TX_AMPDU_PROT_MODE, action, 0, NULL,
5968                              prot_mode, cmd);
5969 
5970     return wifi_wait_for_cmdresp(action == HostCmd_ACT_GEN_GET ? prot_mode : NULL);
5971 }
5972 #endif
5973 
5974 #if CONFIG_CSI
wifi_csi_cfg(wifi_csi_config_params_t * csi_params)5975 int wifi_csi_cfg(wifi_csi_config_params_t *csi_params)
5976 {
5977     t_u16 action = CSI_CMD_DISABLE;
5978 
5979     action = csi_params->csi_enable;
5980     if (action != CSI_CMD_ENABLE && action != CSI_CMD_DISABLE)
5981         return -WM_FAIL;
5982 
5983     wifi_get_command_lock();
5984     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
5985 
5986     if (csi_params->bss_type == BSS_TYPE_UAP)
5987         cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, BSS_TYPE_UAP);
5988     else
5989         cmd->seq_num = 0x0;
5990     cmd->result = 0x0;
5991 
5992     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_CSI,
5993                                               csi_params->csi_enable, 0, NULL, csi_params, cmd);
5994     if (rv != MLAN_STATUS_SUCCESS)
5995     {
5996         wifi_put_command_lock();
5997         return -WM_FAIL;
5998     }
5999 
6000     return wifi_wait_for_cmdresp(NULL);
6001 }
6002 #endif
6003 
6004 #if (CONFIG_IPS)
6005 /* enable/disable config for IPS */
wifi_set_ips_config(mlan_bss_type interface,int option)6006 int wifi_set_ips_config(mlan_bss_type interface, int option)
6007 {
6008     wifi_get_command_lock();
6009     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6010     t_u16 cmd_size;
6011 
6012     if ((option != 0) && (option != 1))
6013         return -WM_FAIL;
6014 
6015     cmd_size = sizeof(HostCmd_DS_IPS_CONFIG) + S_DS_GEN /* cmd header */;
6016     (void)memset(cmd, 0x00, cmd_size);
6017     cmd->command = HostCmd_CMD_IPS_CONFIG;
6018     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, interface);
6019     cmd->size    = cmd_size;
6020 
6021     cmd->params.ips_config.enable = option;
6022 
6023     return wifi_wait_for_cmdresp(NULL);
6024 }
6025 #endif
6026 
6027 #if CONFIG_NET_MONITOR
wifi_net_monitor_cfg(wifi_net_monitor_t * monitor)6028 int wifi_net_monitor_cfg(wifi_net_monitor_t *monitor)
6029 {
6030     t_u16 action = HostCmd_ACT_GEN_SET;
6031 
6032     action = monitor->action;
6033 
6034     if (action != HostCmd_ACT_GEN_GET && action != HostCmd_ACT_GEN_SET)
6035         return -WM_FAIL;
6036 
6037     wifi_get_command_lock();
6038     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6039 
6040     cmd->seq_num = 0x0;
6041     cmd->result  = 0x0;
6042 
6043     mlan_status rv = wlan_ops_sta_prepare_cmd((mlan_private *)mlan_adap->priv[0], HostCmd_CMD_802_11_NET_MONITOR,
6044                                               monitor->action, 0, NULL, monitor, cmd);
6045     if (rv != MLAN_STATUS_SUCCESS)
6046         return -WM_FAIL;
6047 
6048     return wifi_wait_for_cmdresp(NULL);
6049 }
6050 #endif
6051 
6052 #if CONFIG_TSP
wifi_tsp_cfg(const t_u16 action,t_u16 * enable,t_u32 * back_off,t_u32 * highThreshold,t_u32 * lowThreshold,t_u32 * dutycycstep,t_u32 * dutycycmin,int * highthrtemp,int * lowthrtemp,int * currCAUTemp,int * currRFUTemp)6053 int wifi_tsp_cfg(const t_u16 action,
6054                  t_u16 *enable,
6055                  t_u32 *back_off,
6056                  t_u32 *highThreshold,
6057                  t_u32 *lowThreshold,
6058                  t_u32 *dutycycstep,
6059                  t_u32 *dutycycmin,
6060                  int *highthrtemp,
6061                  int *lowthrtemp,
6062                  int *currCAUTemp,
6063                  int *currRFUTemp)
6064 {
6065     wifi_get_command_lock();
6066     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6067     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6068     HostCmd_DS_TSP_CFG *tsp_cfg = &cmd->params.tsp_cfg;
6069 
6070     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_TSP_CFG);
6071     cmd->size    = sizeof(HostCmd_DS_TSP_CFG) + S_DS_GEN;
6072 
6073     (void)memcpy(&tsp_cfg->thermalPowerMgmtenable, enable, sizeof(t_u16));
6074     (void)memcpy(&tsp_cfg->powerMgmtBackoff, back_off, sizeof(t_u32));
6075     (void)memcpy(&tsp_cfg->highPwrBOThrshld, highThreshold, sizeof(t_u32));
6076     (void)memcpy(&tsp_cfg->lowPwrBOThrshld, lowThreshold, sizeof(t_u32));
6077     (void)memcpy(&tsp_cfg->dutycycstep, dutycycstep, sizeof(t_u32));
6078     (void)memcpy(&tsp_cfg->dutycycmin, dutycycmin, sizeof(t_u32));
6079     (void)memcpy(&tsp_cfg->highthrtemp, highthrtemp, sizeof(t_s32));
6080     (void)memcpy(&tsp_cfg->lowthrtemp, lowthrtemp, sizeof(t_s32));
6081 
6082     tsp_cfg->action                 = wlan_cpu_to_le16(action);
6083     tsp_cfg->thermalPowerMgmtenable = wlan_cpu_to_le16(tsp_cfg->thermalPowerMgmtenable);
6084     tsp_cfg->powerMgmtBackoff       = wlan_cpu_to_le16(tsp_cfg->powerMgmtBackoff);
6085     tsp_cfg->highPwrBOThrshld       = wlan_cpu_to_le16(tsp_cfg->highPwrBOThrshld);
6086     tsp_cfg->lowPwrBOThrshld        = wlan_cpu_to_le16(tsp_cfg->lowPwrBOThrshld);
6087     tsp_cfg->dutycycstep            = wlan_cpu_to_le16(tsp_cfg->dutycycstep);
6088     tsp_cfg->dutycycmin             = wlan_cpu_to_le16(tsp_cfg->dutycycmin);
6089     tsp_cfg->highthrtemp            = wlan_cpu_to_le16(tsp_cfg->highthrtemp);
6090     tsp_cfg->lowthrtemp             = wlan_cpu_to_le16(tsp_cfg->lowthrtemp);
6091 
6092     cmd->size = wlan_cpu_to_le16(cmd->size);
6093 
6094     if (action == MLAN_ACT_SET)
6095         return wifi_wait_for_cmdresp(NULL);
6096     else
6097     {
6098         TSP_CFG tsp_get_cfg;
6099         tsp_get_cfg.thermalPowerMgmtenable = enable;
6100         tsp_get_cfg.powerMgmtBackoff       = back_off;
6101         tsp_get_cfg.highPwrBOThrshld       = highThreshold;
6102         tsp_get_cfg.lowPwrBOThrshld        = lowThreshold;
6103         tsp_get_cfg.dutycycstep            = dutycycstep;
6104         tsp_get_cfg.dutycycmin             = dutycycmin;
6105         tsp_get_cfg.highthrtemp            = highthrtemp;
6106         tsp_get_cfg.lowthrtemp             = lowthrtemp;
6107         tsp_get_cfg.currCAUTemp            = currCAUTemp;
6108         tsp_get_cfg.currRFUTemp            = currRFUTemp;
6109 
6110         return wifi_wait_for_cmdresp(&tsp_get_cfg);
6111     }
6112 }
6113 #endif
6114 
6115 #if CONFIG_TURBO_MODE
wifi_get_turbo_mode(t_u8 * mode)6116 int wifi_get_turbo_mode(t_u8 *mode)
6117 {
6118     return wlan_get_set_turbo_mode(ACTION_GET, mode, MLAN_BSS_TYPE_STA);
6119 }
6120 
wifi_get_uap_turbo_mode(t_u8 * mode)6121 int wifi_get_uap_turbo_mode(t_u8 *mode)
6122 {
6123     return wlan_get_set_turbo_mode(ACTION_GET, mode, MLAN_BSS_TYPE_UAP);
6124 }
6125 
wifi_set_turbo_mode(t_u8 mode)6126 int wifi_set_turbo_mode(t_u8 mode)
6127 {
6128     return wlan_get_set_turbo_mode(ACTION_SET, &mode, MLAN_BSS_TYPE_STA);
6129 }
6130 
wifi_set_uap_turbo_mode(t_u8 mode)6131 int wifi_set_uap_turbo_mode(t_u8 mode)
6132 {
6133     return wlan_get_set_turbo_mode(ACTION_SET, &mode, MLAN_BSS_TYPE_UAP);
6134 }
6135 
wlan_get_set_turbo_mode(t_u16 action,t_u8 * mode,mlan_bss_type bss_type)6136 int wlan_get_set_turbo_mode(t_u16 action, t_u8 *mode, mlan_bss_type bss_type)
6137 {
6138     wifi_get_command_lock();
6139     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6140     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6141 
6142     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
6143     cmd->size    = S_DS_GEN;
6144     cmd->seq_num = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
6145 
6146     uint8_t *tlv = (uint8_t *)((uint8_t *)cmd + S_DS_GEN);
6147 
6148     turbo_mode_para *turbo_ptr = (turbo_mode_para *)tlv;
6149     turbo_ptr->action          = action;
6150     turbo_ptr->oid             = OID_WMM_TURBO_MODE;
6151     turbo_ptr->size            = 0x1;
6152     if (action == ACTION_SET)
6153         (void)memcpy(&turbo_ptr->mode, mode, sizeof(t_u8));
6154 
6155     cmd->size += sizeof(turbo_mode_para);
6156     cmd->size = wlan_cpu_to_le16(cmd->size);
6157 
6158     if (action == ACTION_GET)
6159         return wifi_wait_for_cmdresp(mode);
6160     else
6161         return wifi_wait_for_cmdresp(NULL);
6162 }
6163 #endif
6164 
6165 #if (CONFIG_11MC) || (CONFIG_11AZ)
wifi_ftm_start_stop(const t_u16 action,const t_u8 loop_cnt,const t_u8 * mac,const t_u8 channel)6166 int wifi_ftm_start_stop(const t_u16 action, const t_u8 loop_cnt, const t_u8 *mac, const t_u8 channel)
6167 {
6168     if (action == FTM_ACTION_START)
6169     {
6170         ftm_param.channel = channel;
6171         (void)memcpy(ftm_param.peer_mac, mac, MLAN_MAC_ADDR_LENGTH);
6172         ftm_param.loop_cnt = loop_cnt;
6173         ftm_param.status   = (ftm_param.loop_cnt == 0) ? 1 : 0;
6174         return wifi_ftm_start(FTM_ACTION_START, mac, channel);
6175     }
6176     else
6177     {
6178         ftm_param.loop_cnt = 0;
6179         ftm_param.status   = 0;
6180         return wifi_ftm_stop(FTM_ACTION_STOP, ftm_param.peer_mac, ftm_param.channel);
6181     }
6182 }
6183 
wifi_ftm_start(const t_u16 action,const t_u8 * mac,const t_u8 channel)6184 int wifi_ftm_start(const t_u16 action, const t_u8 *mac, const t_u8 channel)
6185 {
6186     if (!is_sta_connected())
6187     {
6188         PRINTF("Cannot Start FTM, STA not associated !\r\n");
6189         return -WM_FAIL;
6190     }
6191     wifi_get_command_lock();
6192     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6193 
6194     cmd->command                             = wlan_cpu_to_le16(HostCmd_CMD_FTM_SESSION_CTRL);
6195     cmd->size                                = S_DS_GEN + sizeof(HostCmd_FTM_SESSION_CTRL);
6196     cmd->size                                = wlan_cpu_to_le16(cmd->size);
6197     cmd->params.ftm_session_ctrl.action      = wlan_cpu_to_le16(action);
6198     cmd->params.ftm_session_ctrl.for_ranging = wlan_cpu_to_le16(FOR_RANGING);
6199     (void)memcpy(cmd->params.ftm_session_ctrl.peer_mac, mac, MLAN_MAC_ADDR_LENGTH);
6200     cmd->params.ftm_session_ctrl.chan = wlan_cpu_to_le16(channel);
6201 
6202     dump_hex(cmd, cmd->size);
6203     return wifi_wait_for_cmdresp(NULL);
6204 }
6205 
wifi_ftm_stop(const t_u16 action,const t_u8 * mac,const t_u8 channel)6206 int wifi_ftm_stop(const t_u16 action, const t_u8 *mac, const t_u8 channel)
6207 {
6208     wifi_get_command_lock();
6209     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6210 
6211     cmd->command                             = wlan_cpu_to_le16(HostCmd_CMD_FTM_SESSION_CTRL);
6212     cmd->size                                = S_DS_GEN + sizeof(HostCmd_FTM_SESSION_CTRL);
6213     cmd->size                                = wlan_cpu_to_le16(cmd->size);
6214     cmd->params.ftm_session_ctrl.action      = wlan_cpu_to_le16(action);
6215     cmd->params.ftm_session_ctrl.for_ranging = wlan_cpu_to_le16(FOR_RANGING);
6216     (void)memcpy(cmd->params.ftm_session_ctrl.peer_mac, mac, MLAN_MAC_ADDR_LENGTH);
6217     cmd->params.ftm_session_ctrl.chan = wlan_cpu_to_le16(channel);
6218 
6219     return wifi_wait_for_cmdresp(NULL);
6220 }
6221 
wifi_ftm_11mc_cfg(ftm_11mc_nego_cfg_t * ftm_11mc_nego_cfg)6222 int wifi_ftm_11mc_cfg(ftm_11mc_nego_cfg_t *ftm_11mc_nego_cfg)
6223 {
6224     wifi_get_command_lock();
6225     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6226 
6227     cmd->command                       = wlan_cpu_to_le16(HostCmd_CMD_FTM_SESSION_CFG);
6228     cmd->size                          = wlan_cpu_to_le16(S_DS_GEN);
6229     cmd->params.ftm_session_cfg.action = MLAN_ACT_SET;
6230 
6231     wlan_dot11mc_ftm_cfg(cmd, ftm_11mc_nego_cfg);
6232 
6233     return wifi_wait_for_cmdresp(NULL);
6234 }
6235 
wifi_ftm_location_cfg(location_cfg_info_t * ftm_location_cfg)6236 int wifi_ftm_location_cfg(location_cfg_info_t *ftm_location_cfg)
6237 {
6238     wlan_location_ftm_cfg(ftm_location_cfg);
6239 }
6240 
wifi_ftm_civic_cfg(location_civic_rep_t * ftm_civic_cfg)6241 int wifi_ftm_civic_cfg(location_civic_rep_t *ftm_civic_cfg)
6242 {
6243     wlan_civic_ftm_cfg(ftm_civic_cfg);
6244 }
6245 
wifi_ftm_cfg(const t_u8 protocol,ranging_11az_cfg_t * ftm_ranging_cfg)6246 int wifi_ftm_cfg(const t_u8 protocol, ranging_11az_cfg_t *ftm_ranging_cfg)
6247 {
6248     wifi_get_command_lock();
6249     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6250 
6251     cmd->command                       = wlan_cpu_to_le16(HostCmd_CMD_FTM_SESSION_CFG);
6252     cmd->size                          = wlan_cpu_to_le16(S_DS_GEN);
6253     cmd->params.ftm_session_cfg.action = MLAN_ACT_SET;
6254 
6255     HostCmd_FTM_SESSION_CFG ftm_session_cfg;
6256     dot11az_ftm_cfg_t *cfg_11az                       = (dot11az_ftm_cfg_t *)&ftm_session_cfg.tlv.cfg_11az;
6257     cfg_11az->range_tlv.val.format_bw                 = ftm_ranging_cfg->format_bw;
6258     cfg_11az->range_tlv.val.max_i2r_sts_upto80        = ftm_ranging_cfg->max_i2r_sts_upto80;
6259     cfg_11az->range_tlv.val.max_r2i_sts_upto80        = ftm_ranging_cfg->max_r2i_sts_upto80;
6260     cfg_11az->range_tlv.val.az_measurement_freq       = ftm_ranging_cfg->az_measurement_freq;
6261     cfg_11az->range_tlv.val.az_number_of_measurements = ftm_ranging_cfg->az_number_of_measurements;
6262     cfg_11az->range_tlv.val.i2r_lmr_feedback          = ftm_ranging_cfg->i2r_lmr_feedback;
6263     cfg_11az->range_tlv.val.civic_req                 = ftm_ranging_cfg->civic_req;
6264     cfg_11az->range_tlv.val.lci_req                   = ftm_ranging_cfg->lci_req;
6265     wlan_dto11az_ranging_cfg(cmd, protocol, &ftm_session_cfg);
6266 
6267     return wifi_wait_for_cmdresp(NULL);
6268 }
6269 
wifi_process_wlc_ftm_event()6270 int wifi_process_wlc_ftm_event()
6271 {
6272     int ret = -WM_FAIL;
6273     if (ftm_param.loop_cnt > 0)
6274         ftm_param.loop_cnt--;
6275     if (ftm_param.loop_cnt > 0 || (ftm_param.status))
6276         ret = wifi_ftm_start(FTM_ACTION_START, ftm_param.peer_mac, ftm_param.channel);
6277     // else
6278     //    ret = wifi_ftm_stop(FTM_ACTION_STOP, ftm_param.peer_mac, ftm_param.channel);
6279 
6280     return ret;
6281 }
6282 
6283 #if CONFIG_WLS_CSI_PROC
6284 
mlanwls_update_distance_to_gui(int distance,unsigned int tsf)6285 static int mlanwls_update_distance_to_gui(int distance, unsigned int tsf)
6286 {
6287     int distance_m, distance_cm;
6288     unsigned int time_ms = tsf / 1000;
6289     float distance_flt   = 1.0f * distance / (1 << 8); // in meters
6290     float distance_kalman;
6291 
6292     if (range_input_str.time == 0)
6293     {
6294         range_kalman_init(&range_input_str, distance_flt, time_ms, RANGE_DRIVE_VAR, RANGE_MEASUREMENT_VAR,
6295                           RANGE_RATE_INIT);
6296         range_input_str.time = 1;
6297     }
6298     else
6299     {
6300         range_input_str.range_measurement = distance_flt;
6301         range_input_str.time              = time_ms;
6302         range_kalman(&range_input_str);
6303     }
6304     distance_kalman = range_input_str.last_range;
6305 
6306     distance_cm = (int)(distance_kalman * 100);
6307     distance_m  = distance_cm / 100;
6308     distance_cm -= distance_m * 100;
6309 
6310     wifi_d("Measured Distance: %f m; Kalman Distance: %f m [%d ms]\r\n", (double)distance_flt, (double)distance_kalman,
6311            time_ms);
6312 
6313     return 0;
6314 }
6315 
send_csi_ack(unsigned int * resArray)6316 static int send_csi_ack(unsigned int *resArray)
6317 {
6318     int ret;
6319     wifi_get_command_lock();
6320     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6321     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6322     HostCmd_WLS_CSI_ACK *phostcmd = (HostCmd_WLS_CSI_ACK *)&cmd->params.wls_csi_ack;
6323 
6324     cmd->command     = wlan_cpu_to_le16(HostCmd_CMD_DBGS_CFG);
6325     cmd->size        = S_DS_GEN + sizeof(HostCmd_WLS_CSI_ACK) + 8;
6326     phostcmd->action = 0;
6327     phostcmd->sub_id = 0x333;
6328     phostcmd->ack    = 1;
6329 
6330     phostcmd->phase_roll       = resArray[0];
6331     phostcmd->firstpath_delay  = resArray[1];
6332     phostcmd->fft_size_pointer = resArray[2];
6333     phostcmd->csi_tsf          = resArray[3];
6334 
6335     cmd->size += CSI_TSF_LEN;
6336     cmd->size = wlan_cpu_to_le16(cmd->size);
6337 
6338     ret = wifi_wait_for_cmdresp(NULL);
6339 
6340     return ret;
6341 }
6342 
proc_csi_event(void * event,unsigned int * resArray)6343 static void proc_csi_event(void *event, unsigned int *resArray)
6344 {
6345     uint8_t *csiBuffer = (uint8_t *)(event);
6346     hal_wls_packet_params_t packetparams;
6347     hal_wls_processing_input_params_t inputVals;
6348     unsigned int tsf = ((unsigned int *)csiBuffer)[3];
6349     int distance     = ((unsigned int *)csiBuffer)[19];
6350 
6351     if (distance >= 0)
6352         mlanwls_update_distance_to_gui(distance, tsf);
6353 
6354     inputVals.enableCsi              = 1;                  // turn on CSI processing
6355     inputVals.enableAoA              = AOA_DEFAULT;        // turn on AoA (req. enableCsi==1)
6356     inputVals.nTx                    = 3;                  // limit # tx streams to process
6357     inputVals.nRx                    = 3;                  // limit # rx to process
6358     inputVals.selCal                 = 0;                  // choose cal values
6359     inputVals.dumpMul                = 0;                  // dump extra peaks in AoA
6360     inputVals.enableAntCycling       = 0;                  // enable antenna cycling
6361     inputVals.dumpRawAngle           = 0;                  // Dump Raw Angle
6362     inputVals.useToaMin              = TOA_MIN_DEFAULT;    // 1: use min combining, 0: power combining;
6363     inputVals.useSubspace            = SUBSPACE_DEFAULT;   // 1: use subspace algo; 0: no;
6364     inputVals.useFindAngleDelayPeaks = ENABLE_DELAY_PEAKS; // use this algorithm for AoA
6365 
6366     resArray[0] = 0xffffffff;
6367     resArray[1] = 0xffffffff;
6368     resArray[2] = 0xffffffff;
6369     resArray[3] = 0xffffffff;
6370 
6371     wls_process_csi((unsigned int *)csiBuffer, (unsigned int *)fftInBuffer_t, &packetparams, &inputVals, resArray);
6372     // record TSF
6373     resArray[3] = tsf;
6374 
6375     wifi_d("EVENT: MLAN_CSI Processing results: %d | %d (%x), TSF[%x]\r\n", resArray[0], resArray[1], resArray[2], tsf);
6376 
6377     return;
6378 }
6379 
wifi_process_wls_csi_event(void * p_data)6380 int wifi_process_wls_csi_event(void *p_data)
6381 {
6382     int ret;
6383 
6384     proc_csi_event(((t_u8 *)p_data + sizeof(csi_event_t)), csi_res_array);
6385     // wifi_put_wls_csi_sem(); // After processing CSI raw data, release csi sem for next CSI event.
6386     ret = send_csi_ack(csi_res_array);
6387     return ret;
6388 }
6389 
6390 #endif
6391 
6392 #endif
6393 
6394 #if CONFIG_COEX_DUTY_CYCLE
wifi_single_ant_duty_cycle(t_u16 enable,t_u16 nbTime,t_u16 wlanTime)6395 int wifi_single_ant_duty_cycle(t_u16 enable, t_u16 nbTime, t_u16 wlanTime)
6396 {
6397     wifi_get_command_lock();
6398     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6399     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6400 
6401     cmd->command                               = wlan_cpu_to_le16(HostCmd_CMD_ROBUST_COEX);
6402     cmd->size                                  = sizeof(HostCmd_SIGNLE_ANT_DUTY_CYCLE) + S_DS_GEN;
6403     cmd->seq_num                               = 0x0;
6404     cmd->result                                = 0x00;
6405     cmd->params.single_ant_duty_cycle.action   = HostCmd_ACT_GEN_SET;
6406     cmd->params.single_ant_duty_cycle.reserved = 0;
6407     cmd->params.single_ant_duty_cycle.single_ant_cfg_data.header.type = TLV_TYPE_COEX_DUTY_CYCLE;
6408 
6409     if (enable)
6410     {
6411         cmd->params.single_ant_duty_cycle.single_ant_cfg_data.header.len =
6412             sizeof(MrvlIETypes_SingleAntDutyCycle_Config_t) - 4;
6413         cmd->params.single_ant_duty_cycle.single_ant_cfg_data.enabled  = 0x0002;
6414         cmd->params.single_ant_duty_cycle.single_ant_cfg_data.nbTime   = nbTime;
6415         cmd->params.single_ant_duty_cycle.single_ant_cfg_data.wlanTime = wlanTime;
6416     }
6417     else
6418     {
6419         cmd->params.single_ant_duty_cycle.single_ant_cfg_data.header.len = sizeof(t_u16);
6420         cmd->params.single_ant_duty_cycle.single_ant_cfg_data.enabled    = 0x0004;
6421     }
6422 
6423     wifi_wait_for_cmdresp(NULL);
6424 
6425     return wm_wifi.cmd_resp_status;
6426 }
6427 
wifi_dual_ant_duty_cycle(t_u16 enable,t_u16 nbTime,t_u16 wlanTime,t_u16 wlanBlockTime)6428 int wifi_dual_ant_duty_cycle(t_u16 enable, t_u16 nbTime, t_u16 wlanTime, t_u16 wlanBlockTime)
6429 {
6430     wifi_get_command_lock();
6431     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6432     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6433 
6434     cmd->command                                                  = wlan_cpu_to_le16(HostCmd_CMD_ROBUST_COEX);
6435     cmd->size                                                     = sizeof(HostCmd_DUAL_ANT_DUTY_CYCLE) + S_DS_GEN;
6436     cmd->seq_num                                                  = 0x0;
6437     cmd->result                                                   = 0x00;
6438     cmd->params.dual_ant_duty_cycle.action                        = HostCmd_ACT_GEN_SET;
6439     cmd->params.dual_ant_duty_cycle.reserved                      = 0;
6440     cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.header.type = TLV_TYPE_COEX_DUTY_CYCLE;
6441 
6442     if (enable)
6443     {
6444         cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.header.len =
6445             sizeof(MrvlIETypes_DualAntDutyCycle_Config_t) - 4;
6446         cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.enabled       = 0x0002;
6447         cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.nbTime        = nbTime;
6448         cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.wlanTime      = wlanTime;
6449         cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.wlanBlockTime = wlanBlockTime;
6450     }
6451     else
6452     {
6453         cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.header.len = sizeof(t_u16);
6454         cmd->params.dual_ant_duty_cycle.dual_ant_cfg_data.enabled    = 0x0004;
6455     }
6456 
6457     wifi_wait_for_cmdresp(NULL);
6458 
6459     return wm_wifi.cmd_resp_status;
6460 }
6461 #endif
6462 
6463 #if CONFIG_EXTERNAL_COEX_PTA
6464 
wifi_external_coex_pta_cfg(ext_coex_pta_cfg coex_pta_config)6465 int wifi_external_coex_pta_cfg(ext_coex_pta_cfg coex_pta_config)
6466 {
6467     wifi_get_command_lock();
6468     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6469     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6470 
6471     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_ROBUST_COEX);
6472     cmd->size    = wlan_cpu_to_le16(sizeof(HostCmd_EXTERNAL_COEX_PTA) + S_DS_GEN);
6473     cmd->seq_num = 0x0;
6474     cmd->result  = 0x00;
6475 
6476     HostCmd_EXTERNAL_COEX_PTA *external_coex_pta = (HostCmd_EXTERNAL_COEX_PTA *)&cmd->params.external_coex_pta;
6477     external_coex_pta->action                    = wlan_cpu_to_le16(ACTION_SET);
6478     external_coex_pta->reserved                  = 0x00;
6479 
6480     MrvlIETypes_ExternalCoexPta_Config_t *coex_pta_cfg_data =
6481         (MrvlIETypes_ExternalCoexPta_Config_t *)&external_coex_pta->coex_pta_cfg_data;
6482 
6483     coex_pta_cfg_data->param.tlv_type = wlan_cpu_to_le16(TLV_TYPE_ROBUST_COEX);
6484     coex_pta_cfg_data->param.tlv_length =
6485         wlan_cpu_to_le16(sizeof(MrvlIETypes_ExternalCoexPta_Config_t) - sizeof(MrvlIETypes_Coex_params_t));
6486 
6487     coex_pta_cfg_data->enabled                = wlan_cpu_to_le16(coex_pta_config.enabled);
6488     coex_pta_cfg_data->ext_WifiBtArb          = wlan_cpu_to_le16(coex_pta_config.ext_WifiBtArb);
6489     coex_pta_cfg_data->polGrantPin            = wlan_cpu_to_le16(coex_pta_config.polGrantPin);
6490     coex_pta_cfg_data->enable_PriPtaInt       = wlan_cpu_to_le16(coex_pta_config.enable_PriPtaInt);
6491     coex_pta_cfg_data->enable_StatusFromPta   = wlan_cpu_to_le16(coex_pta_config.enable_StatusFromPta);
6492     coex_pta_cfg_data->setPriSampTiming       = wlan_cpu_to_le16(coex_pta_config.setPriSampTiming);
6493     coex_pta_cfg_data->setStateInfoSampTiming = wlan_cpu_to_le16(coex_pta_config.setStateInfoSampTiming);
6494     coex_pta_cfg_data->extRadioTrafficPrio    = wlan_cpu_to_le16(coex_pta_config.extRadioTrafficPrio);
6495     coex_pta_cfg_data->extCoexHwIntWci2       = wlan_cpu_to_le16(coex_pta_config.extCoexHwIntWci2);
6496 
6497     wifi_wait_for_cmdresp(NULL);
6498 
6499     return wm_wifi.cmd_resp_status;
6500 }
6501 #endif
6502 
6503 #if CONFIG_IMD3_CFG
wifi_imd3_cfg(t_u8 imd3_value)6504 int wifi_imd3_cfg(t_u8 imd3_value)
6505 {
6506     wifi_get_command_lock();
6507     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6508     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6509 
6510     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_ROBUST_COEX);
6511     cmd->size    = wlan_cpu_to_le16(sizeof(HostCmd_IMD3_CFG) + S_DS_GEN);
6512     cmd->seq_num = 0x0;
6513     cmd->result  = 0x00;
6514 
6515     HostCmd_IMD3_CFG *imd3_cfg = (HostCmd_IMD3_CFG *)&cmd->params.imd3_cfg;
6516     imd3_cfg->action           = wlan_cpu_to_le16(ACTION_SET);
6517     imd3_cfg->reserved         = 0x00;
6518 
6519     MrvlIETypes_IMD_Config_t *imd_cfg = (MrvlIETypes_IMD_Config_t *)&imd3_cfg->imd_cfg;
6520 
6521     imd_cfg->param.tlv_type   = wlan_cpu_to_le16(TLV_TYPE_IMD_VALIDATION);
6522     imd_cfg->param.tlv_length = wlan_cpu_to_le16(sizeof(MrvlIETypes_IMD_Config_t) - sizeof(MrvlIETypes_Coex_params_t));
6523 
6524     imd_cfg->rbc_mode    = 0x00;
6525     imd_cfg->reserved    = wlan_cpu_to_le16(imd3_value);
6526     imd_cfg->DynamicMode = 0x0000;
6527 
6528     wifi_wait_for_cmdresp(NULL);
6529 
6530     return wm_wifi.cmd_resp_status;
6531 }
6532 #endif
6533 
6534 #if CONFIG_INACTIVITY_TIMEOUT_EXT
wifi_sta_inactivityto(wifi_inactivity_to_t * inac_to,t_u16 cmd_action)6535 int wifi_sta_inactivityto(wifi_inactivity_to_t *inac_to, t_u16 cmd_action)
6536 {
6537     wifi_get_command_lock();
6538     HostCmd_DS_COMMAND *cmd = wifi_get_command_buffer();
6539     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6540     HostCmd_DS_INACTIVITY_TIMEOUT_EXT *inac_to_ext = (HostCmd_DS_INACTIVITY_TIMEOUT_EXT *)&cmd->params.inactivity_to;
6541 
6542     cmd->command = wlan_cpu_to_le16(HostCmd_CMD_INACTIVITY_TIMEOUT_EXT);
6543     cmd->size    = wlan_cpu_to_le16(sizeof(HostCmd_DS_INACTIVITY_TIMEOUT_EXT) + S_DS_GEN);
6544     cmd->seq_num = 0x0;
6545     cmd->result  = 0x00;
6546 
6547     inac_to_ext->action = wlan_cpu_to_le16(cmd_action);
6548     if (cmd_action == HostCmd_ACT_GEN_SET)
6549     {
6550         inac_to_ext->timeout_unit     = wlan_cpu_to_le16((t_u16)inac_to->timeout_unit);
6551         inac_to_ext->unicast_timeout  = wlan_cpu_to_le16((t_u16)inac_to->unicast_timeout);
6552         inac_to_ext->mcast_timeout    = wlan_cpu_to_le16((t_u16)inac_to->mcast_timeout);
6553         inac_to_ext->ps_entry_timeout = wlan_cpu_to_le16((t_u16)inac_to->ps_entry_timeout);
6554         inac_to_ext->ps_cmd_timeout   = wlan_cpu_to_le16((t_u16)inac_to->ps_cmd_timeout);
6555         wifi_wait_for_cmdresp(NULL);
6556     }
6557     else
6558     {
6559         wifi_wait_for_cmdresp(inac_to);
6560     }
6561 
6562     return wm_wifi.cmd_resp_status;
6563 }
6564 #endif
6565 
6566 #if CONFIG_AUTO_NULL_TX
wifi_auto_null_tx(wifi_auto_null_tx_t * auto_null_tx,mlan_bss_type bss_type)6567 int wifi_auto_null_tx(wifi_auto_null_tx_t *auto_null_tx, mlan_bss_type bss_type)
6568 {
6569     wifi_get_command_lock();
6570     HostCmd_DS_COMMAND *cmd         = wifi_get_command_buffer();
6571     HostCmd_DS_AUTO_TX *auto_tx_cmd = (HostCmd_DS_AUTO_TX *)((t_u8 *)cmd + S_DS_GEN);
6572 
6573     if (auto_null_tx == NULL)
6574         return -WM_E_INVAL;
6575 
6576     (void)memset(cmd, 0x00, sizeof(HostCmd_DS_COMMAND));
6577     cmd->seq_num        = HostCmd_SET_SEQ_NO_BSS_INFO(0 /* seq_num */, 0 /* bss_num */, bss_type);
6578     cmd->command        = wlan_cpu_to_le16(HostCmd_CMD_AUTO_TX);
6579     cmd->size           = S_DS_GEN + sizeof(HostCmd_DS_AUTO_TX);
6580     auto_tx_cmd->action = wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
6581 
6582     if (auto_null_tx->start)
6583     {
6584         MrvlIEtypes_Auto_Null_Tx_t *auto_null_tx_tlv =
6585             (MrvlIEtypes_Auto_Null_Tx_t *)((t_u8 *)auto_tx_cmd + sizeof(auto_tx_cmd->action));
6586         auto_null_tx_tlv->header.type = wlan_cpu_to_le16(TLV_TYPE_AUTO_TX);
6587         auto_null_tx_tlv->header.len =
6588             wlan_cpu_to_le16(sizeof(MrvlIEtypes_Auto_Null_Tx_t) - sizeof(MrvlIEtypesHeader_t));
6589         auto_null_tx_tlv->interval = auto_null_tx->interval;
6590         auto_null_tx_tlv->priority = auto_null_tx->priority;
6591         /* Packet index, set to 0 for auto null tx */
6592         auto_null_tx_tlv->index = 0;
6593         /* getTodToAForPkts, set to 0 for auto null tx */
6594         auto_null_tx_tlv->getTodToAForPkts = 0;
6595         auto_null_tx_tlv->frame_len        = sizeof(auto_null_tx_tlv->dest_mac_addr) +
6596                                       sizeof(auto_null_tx_tlv->dest_mac_addr) +
6597                                       sizeof(auto_null_tx_tlv->frame_body_len);
6598 
6599         (void)memcpy((void *)auto_null_tx_tlv->dest_mac_addr, (const void *)auto_null_tx->dst_mac,
6600                      MLAN_MAC_ADDR_LENGTH);
6601         (void)memcpy((void *)auto_null_tx_tlv->src_mac_addr, (const void *)auto_null_tx->src_mac, MLAN_MAC_ADDR_LENGTH);
6602         /* fram body length, '0x00,0x00' for auto null tx */
6603         auto_null_tx_tlv->frame_body_len = 0;
6604         cmd->size                        = cmd->size + sizeof(MrvlIEtypes_Auto_Null_Tx_t);
6605         cmd->size                        = wlan_cpu_to_le16(cmd->size);
6606     }
6607 
6608     cmd->result = 0x00;
6609 
6610     wifi_wait_for_cmdresp(NULL);
6611 
6612     return wm_wifi.cmd_resp_status;
6613 }
6614 #endif
6615