gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / wireless / marvell / mwifiex / sta_ioctl.c
blob653f9e094256e5b0029c0b126a66328595546d20
1 /*
2 * NXP Wireless LAN device driver: functions for station ioctl
4 * Copyright 2011-2020 NXP
6 * This software file (the "File") is distributed by NXP
7 * under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
20 #include "decl.h"
21 #include "ioctl.h"
22 #include "util.h"
23 #include "fw.h"
24 #include "main.h"
25 #include "wmm.h"
26 #include "11n.h"
27 #include "cfg80211.h"
29 static int disconnect_on_suspend;
30 module_param(disconnect_on_suspend, int, 0644);
33 * Copies the multicast address list from device to driver.
35 * This function does not validate the destination memory for
36 * size, and the calling function must ensure enough memory is
37 * available.
39 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
40 struct net_device *dev)
42 int i = 0;
43 struct netdev_hw_addr *ha;
45 netdev_for_each_mc_addr(ha, dev)
46 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
48 return i;
52 * Wait queue completion handler.
54 * This function waits on a cmd wait queue. It also cancels the pending
55 * request after waking up, in case of errors.
57 int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
58 struct cmd_ctrl_node *cmd_queued)
60 int status;
62 /* Wait for completion */
63 status = wait_event_interruptible_timeout(adapter->cmd_wait_q.wait,
64 *(cmd_queued->condition),
65 (12 * HZ));
66 if (status <= 0) {
67 if (status == 0)
68 status = -ETIMEDOUT;
69 mwifiex_dbg(adapter, ERROR, "cmd_wait_q terminated: %d\n",
70 status);
71 mwifiex_cancel_all_pending_cmd(adapter);
72 return status;
75 status = adapter->cmd_wait_q.status;
76 adapter->cmd_wait_q.status = 0;
78 return status;
82 * This function prepares the correct firmware command and
83 * issues it to set the multicast list.
85 * This function can be used to enable promiscuous mode, or enable all
86 * multicast packets, or to enable selective multicast.
88 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
89 struct mwifiex_multicast_list *mcast_list)
91 int ret = 0;
92 u16 old_pkt_filter;
94 old_pkt_filter = priv->curr_pkt_filter;
96 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
97 mwifiex_dbg(priv->adapter, INFO,
98 "info: Enable Promiscuous mode\n");
99 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
100 priv->curr_pkt_filter &=
101 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
102 } else {
103 /* Multicast */
104 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
105 if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
106 mwifiex_dbg(priv->adapter, INFO,
107 "info: Enabling All Multicast!\n");
108 priv->curr_pkt_filter |=
109 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
110 } else {
111 priv->curr_pkt_filter &=
112 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
113 mwifiex_dbg(priv->adapter, INFO,
114 "info: Set multicast list=%d\n",
115 mcast_list->num_multicast_addr);
116 /* Send multicast addresses to firmware */
117 ret = mwifiex_send_cmd(priv,
118 HostCmd_CMD_MAC_MULTICAST_ADR,
119 HostCmd_ACT_GEN_SET, 0,
120 mcast_list, false);
123 mwifiex_dbg(priv->adapter, INFO,
124 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
125 old_pkt_filter, priv->curr_pkt_filter);
126 if (old_pkt_filter != priv->curr_pkt_filter) {
127 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
128 HostCmd_ACT_GEN_SET,
129 0, &priv->curr_pkt_filter, false);
132 return ret;
136 * This function fills bss descriptor structure using provided
137 * information.
138 * beacon_ie buffer is allocated in this function. It is caller's
139 * responsibility to free the memory.
141 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
142 struct cfg80211_bss *bss,
143 struct mwifiex_bssdescriptor *bss_desc)
145 u8 *beacon_ie;
146 size_t beacon_ie_len;
147 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
148 const struct cfg80211_bss_ies *ies;
150 rcu_read_lock();
151 ies = rcu_dereference(bss->ies);
152 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
153 beacon_ie_len = ies->len;
154 bss_desc->timestamp = ies->tsf;
155 rcu_read_unlock();
157 if (!beacon_ie) {
158 mwifiex_dbg(priv->adapter, ERROR,
159 " failed to alloc beacon_ie\n");
160 return -ENOMEM;
163 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
164 bss_desc->rssi = bss->signal;
165 /* The caller of this function will free beacon_ie */
166 bss_desc->beacon_buf = beacon_ie;
167 bss_desc->beacon_buf_size = beacon_ie_len;
168 bss_desc->beacon_period = bss->beacon_interval;
169 bss_desc->cap_info_bitmap = bss->capability;
170 bss_desc->bss_band = bss_priv->band;
171 bss_desc->fw_tsf = bss_priv->fw_tsf;
172 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
173 mwifiex_dbg(priv->adapter, INFO,
174 "info: InterpretIE: AP WEP enabled\n");
175 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
176 } else {
177 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
179 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
180 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
181 else
182 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
184 /* Disable 11ac by default. Enable it only where there
185 * exist VHT_CAP IE in AP beacon
187 bss_desc->disable_11ac = true;
189 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
190 bss_desc->sensed_11h = true;
192 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
195 void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv)
197 if (priv->adapter->dt_node) {
198 char txpwr[] = {"marvell,00_txpwrlimit"};
200 memcpy(&txpwr[8], priv->adapter->country_code, 2);
201 mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
205 static int mwifiex_process_country_ie(struct mwifiex_private *priv,
206 struct cfg80211_bss *bss)
208 const u8 *country_ie;
209 u8 country_ie_len;
210 struct mwifiex_802_11d_domain_reg *domain_info =
211 &priv->adapter->domain_reg;
213 rcu_read_lock();
214 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
215 if (!country_ie) {
216 rcu_read_unlock();
217 return 0;
220 country_ie_len = country_ie[1];
221 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
222 rcu_read_unlock();
223 return 0;
226 if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
227 rcu_read_unlock();
228 mwifiex_dbg(priv->adapter, INFO,
229 "11D: skip setting domain info in FW\n");
230 return 0;
233 if (country_ie_len >
234 (IEEE80211_COUNTRY_STRING_LEN + MWIFIEX_MAX_TRIPLET_802_11D)) {
235 rcu_read_unlock();
236 mwifiex_dbg(priv->adapter, ERROR,
237 "11D: country_ie_len overflow!, deauth AP\n");
238 return -EINVAL;
241 memcpy(priv->adapter->country_code, &country_ie[2], 2);
243 domain_info->country_code[0] = country_ie[2];
244 domain_info->country_code[1] = country_ie[3];
245 domain_info->country_code[2] = ' ';
247 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
249 domain_info->no_of_triplet =
250 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
252 memcpy((u8 *)domain_info->triplet,
253 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
255 rcu_read_unlock();
257 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
258 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
259 mwifiex_dbg(priv->adapter, ERROR,
260 "11D: setting domain info in FW fail\n");
261 return -1;
264 mwifiex_dnld_txpwr_table(priv);
266 return 0;
270 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
271 * In both Ad-Hoc and infra mode, an deauthentication is performed
272 * first.
274 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
275 struct cfg80211_ssid *req_ssid)
277 int ret;
278 struct mwifiex_adapter *adapter = priv->adapter;
279 struct mwifiex_bssdescriptor *bss_desc = NULL;
281 priv->scan_block = false;
283 if (bss) {
284 if (adapter->region_code == 0x00 &&
285 mwifiex_process_country_ie(priv, bss))
286 return -EINVAL;
288 /* Allocate and fill new bss descriptor */
289 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
290 GFP_KERNEL);
291 if (!bss_desc)
292 return -ENOMEM;
294 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
295 if (ret)
296 goto done;
299 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
300 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
301 u8 config_bands;
303 if (!bss_desc)
304 return -1;
306 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
307 HostCmd_SCAN_RADIO_TYPE_BG) {
308 config_bands = BAND_B | BAND_G | BAND_GN;
309 } else {
310 config_bands = BAND_A | BAND_AN;
311 if (adapter->fw_bands & BAND_AAC)
312 config_bands |= BAND_AAC;
315 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
316 adapter->config_bands = config_bands;
318 ret = mwifiex_check_network_compatibility(priv, bss_desc);
319 if (ret)
320 goto done;
322 if (mwifiex_11h_get_csa_closed_channel(priv) ==
323 (u8)bss_desc->channel) {
324 mwifiex_dbg(adapter, ERROR,
325 "Attempt to reconnect on csa closed chan(%d)\n",
326 bss_desc->channel);
327 ret = -1;
328 goto done;
331 mwifiex_dbg(adapter, INFO,
332 "info: SSID found in scan list ...\t"
333 "associating...\n");
335 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
336 if (netif_carrier_ok(priv->netdev))
337 netif_carrier_off(priv->netdev);
339 /* Clear any past association response stored for
340 * application retrieval */
341 priv->assoc_rsp_size = 0;
342 ret = mwifiex_associate(priv, bss_desc);
344 /* If auth type is auto and association fails using open mode,
345 * try to connect using shared mode */
346 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
347 priv->sec_info.is_authtype_auto &&
348 priv->sec_info.wep_enabled) {
349 priv->sec_info.authentication_mode =
350 NL80211_AUTHTYPE_SHARED_KEY;
351 ret = mwifiex_associate(priv, bss_desc);
354 if (bss)
355 cfg80211_put_bss(priv->adapter->wiphy, bss);
356 } else {
357 /* Adhoc mode */
358 /* If the requested SSID matches current SSID, return */
359 if (bss_desc && bss_desc->ssid.ssid_len &&
360 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
361 ssid, &bss_desc->ssid))) {
362 ret = 0;
363 goto done;
366 priv->adhoc_is_link_sensed = false;
368 ret = mwifiex_check_network_compatibility(priv, bss_desc);
370 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
371 if (netif_carrier_ok(priv->netdev))
372 netif_carrier_off(priv->netdev);
374 if (!ret) {
375 mwifiex_dbg(adapter, INFO,
376 "info: network found in scan\t"
377 " list. Joining...\n");
378 ret = mwifiex_adhoc_join(priv, bss_desc);
379 if (bss)
380 cfg80211_put_bss(priv->adapter->wiphy, bss);
381 } else {
382 mwifiex_dbg(adapter, INFO,
383 "info: Network not found in\t"
384 "the list, creating adhoc with ssid = %s\n",
385 req_ssid->ssid);
386 ret = mwifiex_adhoc_start(priv, req_ssid);
390 done:
391 /* beacon_ie buffer was allocated in function
392 * mwifiex_fill_new_bss_desc(). Free it now.
394 if (bss_desc)
395 kfree(bss_desc->beacon_buf);
396 kfree(bss_desc);
398 if (ret < 0)
399 priv->attempted_bss_desc = NULL;
401 return ret;
405 * IOCTL request handler to set host sleep configuration.
407 * This function prepares the correct firmware command and
408 * issues it.
410 int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
411 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
414 struct mwifiex_adapter *adapter = priv->adapter;
415 int status = 0;
416 u32 prev_cond = 0;
418 if (!hs_cfg)
419 return -ENOMEM;
421 switch (action) {
422 case HostCmd_ACT_GEN_SET:
423 if (adapter->pps_uapsd_mode) {
424 mwifiex_dbg(adapter, INFO,
425 "info: Host Sleep IOCTL\t"
426 "is blocked in UAPSD/PPS mode\n");
427 status = -1;
428 break;
430 if (hs_cfg->is_invoke_hostcmd) {
431 if (hs_cfg->conditions == HS_CFG_CANCEL) {
432 if (!test_bit(MWIFIEX_IS_HS_CONFIGURED,
433 &adapter->work_flags))
434 /* Already cancelled */
435 break;
436 /* Save previous condition */
437 prev_cond = le32_to_cpu(adapter->hs_cfg
438 .conditions);
439 adapter->hs_cfg.conditions =
440 cpu_to_le32(hs_cfg->conditions);
441 } else if (hs_cfg->conditions) {
442 adapter->hs_cfg.conditions =
443 cpu_to_le32(hs_cfg->conditions);
444 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
445 if (hs_cfg->gap)
446 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
447 } else if (adapter->hs_cfg.conditions ==
448 cpu_to_le32(HS_CFG_CANCEL)) {
449 /* Return failure if no parameters for HS
450 enable */
451 status = -1;
452 break;
455 status = mwifiex_send_cmd(priv,
456 HostCmd_CMD_802_11_HS_CFG_ENH,
457 HostCmd_ACT_GEN_SET, 0,
458 &adapter->hs_cfg,
459 cmd_type == MWIFIEX_SYNC_CMD);
461 if (hs_cfg->conditions == HS_CFG_CANCEL)
462 /* Restore previous condition */
463 adapter->hs_cfg.conditions =
464 cpu_to_le32(prev_cond);
465 } else {
466 adapter->hs_cfg.conditions =
467 cpu_to_le32(hs_cfg->conditions);
468 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
469 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
471 break;
472 case HostCmd_ACT_GEN_GET:
473 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
474 hs_cfg->gpio = adapter->hs_cfg.gpio;
475 hs_cfg->gap = adapter->hs_cfg.gap;
476 break;
477 default:
478 status = -1;
479 break;
482 return status;
486 * Sends IOCTL request to cancel the existing Host Sleep configuration.
488 * This function allocates the IOCTL request buffer, fills it
489 * with requisite parameters and calls the IOCTL handler.
491 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
493 struct mwifiex_ds_hs_cfg hscfg;
495 hscfg.conditions = HS_CFG_CANCEL;
496 hscfg.is_invoke_hostcmd = true;
498 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
499 cmd_type, &hscfg);
501 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
504 * Sends IOCTL request to cancel the existing Host Sleep configuration.
506 * This function allocates the IOCTL request buffer, fills it
507 * with requisite parameters and calls the IOCTL handler.
509 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
511 struct mwifiex_ds_hs_cfg hscfg;
512 struct mwifiex_private *priv;
513 int i;
515 if (disconnect_on_suspend) {
516 for (i = 0; i < adapter->priv_num; i++) {
517 priv = adapter->priv[i];
518 if (priv)
519 mwifiex_deauthenticate(priv, NULL);
523 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
525 if (priv && priv->sched_scanning) {
526 #ifdef CONFIG_PM
527 if (priv->wdev.wiphy->wowlan_config &&
528 !priv->wdev.wiphy->wowlan_config->nd_config) {
529 #endif
530 mwifiex_dbg(adapter, CMD, "aborting bgscan!\n");
531 mwifiex_stop_bg_scan(priv);
532 cfg80211_sched_scan_stopped(priv->wdev.wiphy, 0);
533 #ifdef CONFIG_PM
535 #endif
538 if (adapter->hs_activated) {
539 mwifiex_dbg(adapter, CMD,
540 "cmd: HS Already activated\n");
541 return true;
544 adapter->hs_activate_wait_q_woken = false;
546 memset(&hscfg, 0, sizeof(hscfg));
547 hscfg.is_invoke_hostcmd = true;
549 set_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
550 mwifiex_cancel_all_pending_cmd(adapter);
552 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
553 MWIFIEX_BSS_ROLE_STA),
554 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
555 &hscfg)) {
556 mwifiex_dbg(adapter, ERROR,
557 "IOCTL request HS enable failed\n");
558 return false;
561 if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
562 adapter->hs_activate_wait_q_woken,
563 (10 * HZ)) <= 0) {
564 mwifiex_dbg(adapter, ERROR,
565 "hs_activate_wait_q terminated\n");
566 return false;
569 return true;
571 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
574 * IOCTL request handler to get BSS information.
576 * This function collates the information from different driver structures
577 * to send to the user.
579 int mwifiex_get_bss_info(struct mwifiex_private *priv,
580 struct mwifiex_bss_info *info)
582 struct mwifiex_adapter *adapter = priv->adapter;
583 struct mwifiex_bssdescriptor *bss_desc;
585 if (!info)
586 return -1;
588 bss_desc = &priv->curr_bss_params.bss_descriptor;
590 info->bss_mode = priv->bss_mode;
592 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
594 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
596 info->bss_chan = bss_desc->channel;
598 memcpy(info->country_code, adapter->country_code,
599 IEEE80211_COUNTRY_STRING_LEN);
601 info->media_connected = priv->media_connected;
603 info->max_power_level = priv->max_tx_power_level;
604 info->min_power_level = priv->min_tx_power_level;
606 info->adhoc_state = priv->adhoc_state;
608 info->bcn_nf_last = priv->bcn_nf_last;
610 if (priv->sec_info.wep_enabled)
611 info->wep_status = true;
612 else
613 info->wep_status = false;
615 info->is_hs_configured = test_bit(MWIFIEX_IS_HS_CONFIGURED,
616 &adapter->work_flags);
617 info->is_deep_sleep = adapter->is_deep_sleep;
619 return 0;
623 * The function disables auto deep sleep mode.
625 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
627 struct mwifiex_ds_auto_ds auto_ds = {
628 .auto_ds = DEEP_SLEEP_OFF,
631 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
632 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
634 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
637 * Sends IOCTL request to get the data rate.
639 * This function allocates the IOCTL request buffer, fills it
640 * with requisite parameters and calls the IOCTL handler.
642 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
644 int ret;
646 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
647 HostCmd_ACT_GEN_GET, 0, NULL, true);
649 if (!ret) {
650 if (priv->is_data_rate_auto)
651 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
652 priv->tx_htinfo);
653 else
654 *rate = priv->data_rate;
657 return ret;
661 * IOCTL request handler to set tx power configuration.
663 * This function prepares the correct firmware command and
664 * issues it.
666 * For non-auto power mode, all the following power groups are set -
667 * - Modulation class HR/DSSS
668 * - Modulation class OFDM
669 * - Modulation class HTBW20
670 * - Modulation class HTBW40
672 int mwifiex_set_tx_power(struct mwifiex_private *priv,
673 struct mwifiex_power_cfg *power_cfg)
675 int ret;
676 struct host_cmd_ds_txpwr_cfg *txp_cfg;
677 struct mwifiex_types_power_group *pg_tlv;
678 struct mwifiex_power_group *pg;
679 u8 *buf;
680 u16 dbm = 0;
682 if (!power_cfg->is_power_auto) {
683 dbm = (u16) power_cfg->power_level;
684 if ((dbm < priv->min_tx_power_level) ||
685 (dbm > priv->max_tx_power_level)) {
686 mwifiex_dbg(priv->adapter, ERROR,
687 "txpower value %d dBm\t"
688 "is out of range (%d dBm-%d dBm)\n",
689 dbm, priv->min_tx_power_level,
690 priv->max_tx_power_level);
691 return -1;
694 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
695 if (!buf)
696 return -ENOMEM;
698 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
699 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
700 if (!power_cfg->is_power_auto) {
701 u16 dbm_min = power_cfg->is_power_fixed ?
702 dbm : priv->min_tx_power_level;
704 txp_cfg->mode = cpu_to_le32(1);
705 pg_tlv = (struct mwifiex_types_power_group *)
706 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
707 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
708 pg_tlv->length =
709 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
710 pg = (struct mwifiex_power_group *)
711 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
712 + sizeof(struct mwifiex_types_power_group));
713 /* Power group for modulation class HR/DSSS */
714 pg->first_rate_code = 0x00;
715 pg->last_rate_code = 0x03;
716 pg->modulation_class = MOD_CLASS_HR_DSSS;
717 pg->power_step = 0;
718 pg->power_min = (s8) dbm_min;
719 pg->power_max = (s8) dbm;
720 pg++;
721 /* Power group for modulation class OFDM */
722 pg->first_rate_code = 0x00;
723 pg->last_rate_code = 0x07;
724 pg->modulation_class = MOD_CLASS_OFDM;
725 pg->power_step = 0;
726 pg->power_min = (s8) dbm_min;
727 pg->power_max = (s8) dbm;
728 pg++;
729 /* Power group for modulation class HTBW20 */
730 pg->first_rate_code = 0x00;
731 pg->last_rate_code = 0x20;
732 pg->modulation_class = MOD_CLASS_HT;
733 pg->power_step = 0;
734 pg->power_min = (s8) dbm_min;
735 pg->power_max = (s8) dbm;
736 pg->ht_bandwidth = HT_BW_20;
737 pg++;
738 /* Power group for modulation class HTBW40 */
739 pg->first_rate_code = 0x00;
740 pg->last_rate_code = 0x20;
741 pg->modulation_class = MOD_CLASS_HT;
742 pg->power_step = 0;
743 pg->power_min = (s8) dbm_min;
744 pg->power_max = (s8) dbm;
745 pg->ht_bandwidth = HT_BW_40;
747 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
748 HostCmd_ACT_GEN_SET, 0, buf, true);
750 kfree(buf);
751 return ret;
755 * IOCTL request handler to get power save mode.
757 * This function prepares the correct firmware command and
758 * issues it.
760 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
762 int ret;
763 struct mwifiex_adapter *adapter = priv->adapter;
764 u16 sub_cmd;
766 if (*ps_mode)
767 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
768 else
769 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
770 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
771 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
772 sub_cmd, BITMAP_STA_PS, NULL, true);
773 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
774 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
775 GET_PS, 0, NULL, false);
777 return ret;
781 * IOCTL request handler to set/reset WPA IE.
783 * The supplied WPA IE is treated as a opaque buffer. Only the first field
784 * is checked to determine WPA version. If buffer length is zero, the existing
785 * WPA IE is reset.
787 static int mwifiex_set_wpa_ie(struct mwifiex_private *priv,
788 u8 *ie_data_ptr, u16 ie_len)
790 if (ie_len) {
791 if (ie_len > sizeof(priv->wpa_ie)) {
792 mwifiex_dbg(priv->adapter, ERROR,
793 "failed to copy WPA IE, too big\n");
794 return -1;
796 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
797 priv->wpa_ie_len = ie_len;
798 mwifiex_dbg(priv->adapter, CMD,
799 "cmd: Set Wpa_ie_len=%d IE=%#x\n",
800 priv->wpa_ie_len, priv->wpa_ie[0]);
802 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
803 priv->sec_info.wpa_enabled = true;
804 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
805 priv->sec_info.wpa2_enabled = true;
806 } else {
807 priv->sec_info.wpa_enabled = false;
808 priv->sec_info.wpa2_enabled = false;
810 } else {
811 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
812 priv->wpa_ie_len = 0;
813 mwifiex_dbg(priv->adapter, INFO,
814 "info: reset wpa_ie_len=%d IE=%#x\n",
815 priv->wpa_ie_len, priv->wpa_ie[0]);
816 priv->sec_info.wpa_enabled = false;
817 priv->sec_info.wpa2_enabled = false;
820 return 0;
824 * IOCTL request handler to set/reset WAPI IE.
826 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
827 * is checked to internally enable WAPI. If buffer length is zero, the existing
828 * WAPI IE is reset.
830 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
831 u8 *ie_data_ptr, u16 ie_len)
833 if (ie_len) {
834 if (ie_len > sizeof(priv->wapi_ie)) {
835 mwifiex_dbg(priv->adapter, ERROR,
836 "info: failed to copy WAPI IE, too big\n");
837 return -1;
839 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
840 priv->wapi_ie_len = ie_len;
841 mwifiex_dbg(priv->adapter, CMD,
842 "cmd: Set wapi_ie_len=%d IE=%#x\n",
843 priv->wapi_ie_len, priv->wapi_ie[0]);
845 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
846 priv->sec_info.wapi_enabled = true;
847 } else {
848 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
849 priv->wapi_ie_len = ie_len;
850 mwifiex_dbg(priv->adapter, INFO,
851 "info: Reset wapi_ie_len=%d IE=%#x\n",
852 priv->wapi_ie_len, priv->wapi_ie[0]);
853 priv->sec_info.wapi_enabled = false;
855 return 0;
859 * IOCTL request handler to set/reset WPS IE.
861 * The supplied WPS IE is treated as a opaque buffer. Only the first field
862 * is checked to internally enable WPS. If buffer length is zero, the existing
863 * WPS IE is reset.
865 static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
866 u8 *ie_data_ptr, u16 ie_len)
868 if (ie_len) {
869 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
870 mwifiex_dbg(priv->adapter, ERROR,
871 "info: failed to copy WPS IE, too big\n");
872 return -1;
875 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
876 if (!priv->wps_ie)
877 return -ENOMEM;
879 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
880 priv->wps_ie_len = ie_len;
881 mwifiex_dbg(priv->adapter, CMD,
882 "cmd: Set wps_ie_len=%d IE=%#x\n",
883 priv->wps_ie_len, priv->wps_ie[0]);
884 } else {
885 kfree(priv->wps_ie);
886 priv->wps_ie_len = ie_len;
887 mwifiex_dbg(priv->adapter, INFO,
888 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
890 return 0;
894 * IOCTL request handler to set WAPI key.
896 * This function prepares the correct firmware command and
897 * issues it.
899 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
900 struct mwifiex_ds_encrypt_key *encrypt_key)
903 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
904 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
905 encrypt_key, true);
909 * IOCTL request handler to set WEP network key.
911 * This function prepares the correct firmware command and
912 * issues it, after validation checks.
914 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
915 struct mwifiex_ds_encrypt_key *encrypt_key)
917 struct mwifiex_adapter *adapter = priv->adapter;
918 int ret;
919 struct mwifiex_wep_key *wep_key;
920 int index;
922 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
923 priv->wep_key_curr_index = 0;
924 wep_key = &priv->wep_key[priv->wep_key_curr_index];
925 index = encrypt_key->key_index;
926 if (encrypt_key->key_disable) {
927 priv->sec_info.wep_enabled = 0;
928 } else if (!encrypt_key->key_len) {
929 /* Copy the required key as the current key */
930 wep_key = &priv->wep_key[index];
931 if (!wep_key->key_length) {
932 mwifiex_dbg(adapter, ERROR,
933 "key not set, so cannot enable it\n");
934 return -1;
937 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2) {
938 memcpy(encrypt_key->key_material,
939 wep_key->key_material, wep_key->key_length);
940 encrypt_key->key_len = wep_key->key_length;
943 priv->wep_key_curr_index = (u16) index;
944 priv->sec_info.wep_enabled = 1;
945 } else {
946 wep_key = &priv->wep_key[index];
947 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
948 /* Copy the key in the driver */
949 memcpy(wep_key->key_material,
950 encrypt_key->key_material,
951 encrypt_key->key_len);
952 wep_key->key_index = index;
953 wep_key->key_length = encrypt_key->key_len;
954 priv->sec_info.wep_enabled = 1;
956 if (wep_key->key_length) {
957 void *enc_key;
959 if (encrypt_key->key_disable) {
960 memset(&priv->wep_key[index], 0,
961 sizeof(struct mwifiex_wep_key));
962 goto done;
965 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
966 enc_key = encrypt_key;
967 else
968 enc_key = NULL;
970 /* Send request to firmware */
971 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
972 HostCmd_ACT_GEN_SET, 0, enc_key, false);
973 if (ret)
974 return ret;
977 done:
978 if (priv->sec_info.wep_enabled)
979 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
980 else
981 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
983 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
984 HostCmd_ACT_GEN_SET, 0,
985 &priv->curr_pkt_filter, true);
987 return ret;
991 * IOCTL request handler to set WPA key.
993 * This function prepares the correct firmware command and
994 * issues it, after validation checks.
996 * Current driver only supports key length of up to 32 bytes.
998 * This function can also be used to disable a currently set key.
1000 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
1001 struct mwifiex_ds_encrypt_key *encrypt_key)
1003 int ret;
1004 u8 remove_key = false;
1005 struct host_cmd_ds_802_11_key_material *ibss_key;
1007 /* Current driver only supports key length of up to 32 bytes */
1008 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
1009 mwifiex_dbg(priv->adapter, ERROR,
1010 "key length too long\n");
1011 return -1;
1014 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1016 * IBSS/WPA-None uses only one key (Group) for both receiving
1017 * and sending unicast and multicast packets.
1019 /* Send the key as PTK to firmware */
1020 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1021 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1022 HostCmd_ACT_GEN_SET,
1023 KEY_INFO_ENABLED, encrypt_key, false);
1024 if (ret)
1025 return ret;
1027 ibss_key = &priv->aes_key;
1028 memset(ibss_key, 0,
1029 sizeof(struct host_cmd_ds_802_11_key_material));
1030 /* Copy the key in the driver */
1031 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1032 encrypt_key->key_len);
1033 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1034 sizeof(ibss_key->key_param_set.key_len));
1035 ibss_key->key_param_set.key_type_id
1036 = cpu_to_le16(KEY_TYPE_ID_TKIP);
1037 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
1039 /* Send the key as GTK to firmware */
1040 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1043 if (!encrypt_key->key_index)
1044 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1046 if (remove_key)
1047 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1048 HostCmd_ACT_GEN_SET,
1049 !KEY_INFO_ENABLED, encrypt_key, true);
1050 else
1051 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1052 HostCmd_ACT_GEN_SET,
1053 KEY_INFO_ENABLED, encrypt_key, true);
1055 return ret;
1059 * IOCTL request handler to set/get network keys.
1061 * This is a generic key handling function which supports WEP, WPA
1062 * and WAPI.
1064 static int
1065 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
1066 struct mwifiex_ds_encrypt_key *encrypt_key)
1068 int status;
1070 if (encrypt_key->is_wapi_key)
1071 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
1072 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
1073 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
1074 else
1075 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
1076 return status;
1080 * This function returns the driver version.
1083 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1084 int max_len)
1086 union {
1087 __le32 l;
1088 u8 c[4];
1089 } ver;
1090 char fw_ver[32];
1092 ver.l = cpu_to_le32(adapter->fw_release_number);
1093 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1095 snprintf(version, max_len, driver_version, fw_ver);
1097 mwifiex_dbg(adapter, MSG, "info: MWIFIEX VERSION: %s\n", version);
1099 return 0;
1103 * Sends IOCTL request to set encoding parameters.
1105 * This function allocates the IOCTL request buffer, fills it
1106 * with requisite parameters and calls the IOCTL handler.
1108 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1109 const u8 *key, int key_len, u8 key_index,
1110 const u8 *mac_addr, int disable)
1112 struct mwifiex_ds_encrypt_key encrypt_key;
1114 memset(&encrypt_key, 0, sizeof(encrypt_key));
1115 encrypt_key.key_len = key_len;
1116 encrypt_key.key_index = key_index;
1118 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1119 encrypt_key.is_igtk_key = true;
1121 if (!disable) {
1122 if (key_len)
1123 memcpy(encrypt_key.key_material, key, key_len);
1124 else
1125 encrypt_key.is_current_wep_key = true;
1127 if (mac_addr)
1128 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1129 if (kp && kp->seq && kp->seq_len) {
1130 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
1131 encrypt_key.pn_len = kp->seq_len;
1132 encrypt_key.is_rx_seq_valid = true;
1134 } else {
1135 encrypt_key.key_disable = true;
1136 if (mac_addr)
1137 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1140 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1144 * Sends IOCTL request to get extended version.
1146 * This function allocates the IOCTL request buffer, fills it
1147 * with requisite parameters and calls the IOCTL handler.
1150 mwifiex_get_ver_ext(struct mwifiex_private *priv, u32 version_str_sel)
1152 struct mwifiex_ver_ext ver_ext;
1154 memset(&ver_ext, 0, sizeof(ver_ext));
1155 ver_ext.version_str_sel = version_str_sel;
1156 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1157 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
1158 return -1;
1160 return 0;
1164 mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1165 struct ieee80211_channel *chan,
1166 unsigned int duration)
1168 struct host_cmd_ds_remain_on_chan roc_cfg;
1169 u8 sc;
1171 memset(&roc_cfg, 0, sizeof(roc_cfg));
1172 roc_cfg.action = cpu_to_le16(action);
1173 if (action == HostCmd_ACT_GEN_SET) {
1174 roc_cfg.band_cfg = chan->band;
1175 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
1176 roc_cfg.band_cfg |= (sc << 2);
1178 roc_cfg.channel =
1179 ieee80211_frequency_to_channel(chan->center_freq);
1180 roc_cfg.duration = cpu_to_le32(duration);
1182 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1183 action, 0, &roc_cfg, true)) {
1184 mwifiex_dbg(priv->adapter, ERROR,
1185 "failed to remain on channel\n");
1186 return -1;
1189 return roc_cfg.status;
1193 * Sends IOCTL request to get statistics information.
1195 * This function allocates the IOCTL request buffer, fills it
1196 * with requisite parameters and calls the IOCTL handler.
1199 mwifiex_get_stats_info(struct mwifiex_private *priv,
1200 struct mwifiex_ds_get_stats *log)
1202 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1203 HostCmd_ACT_GEN_GET, 0, log, true);
1207 * IOCTL request handler to read/write register.
1209 * This function prepares the correct firmware command and
1210 * issues it.
1212 * Access to the following registers are supported -
1213 * - MAC
1214 * - BBP
1215 * - RF
1216 * - PMIC
1217 * - CAU
1219 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1220 struct mwifiex_ds_reg_rw *reg_rw,
1221 u16 action)
1223 u16 cmd_no;
1225 switch (reg_rw->type) {
1226 case MWIFIEX_REG_MAC:
1227 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1228 break;
1229 case MWIFIEX_REG_BBP:
1230 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1231 break;
1232 case MWIFIEX_REG_RF:
1233 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1234 break;
1235 case MWIFIEX_REG_PMIC:
1236 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1237 break;
1238 case MWIFIEX_REG_CAU:
1239 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1240 break;
1241 default:
1242 return -1;
1245 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
1249 * Sends IOCTL request to write to a register.
1251 * This function allocates the IOCTL request buffer, fills it
1252 * with requisite parameters and calls the IOCTL handler.
1255 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1256 u32 reg_offset, u32 reg_value)
1258 struct mwifiex_ds_reg_rw reg_rw;
1260 reg_rw.type = reg_type;
1261 reg_rw.offset = reg_offset;
1262 reg_rw.value = reg_value;
1264 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
1268 * Sends IOCTL request to read from a register.
1270 * This function allocates the IOCTL request buffer, fills it
1271 * with requisite parameters and calls the IOCTL handler.
1274 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1275 u32 reg_offset, u32 *value)
1277 int ret;
1278 struct mwifiex_ds_reg_rw reg_rw;
1280 reg_rw.type = reg_type;
1281 reg_rw.offset = reg_offset;
1282 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
1284 if (ret)
1285 goto done;
1287 *value = reg_rw.value;
1289 done:
1290 return ret;
1294 * Sends IOCTL request to read from EEPROM.
1296 * This function allocates the IOCTL request buffer, fills it
1297 * with requisite parameters and calls the IOCTL handler.
1300 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1301 u8 *value)
1303 int ret;
1304 struct mwifiex_ds_read_eeprom rd_eeprom;
1306 rd_eeprom.offset = offset;
1307 rd_eeprom.byte_count = bytes;
1309 /* Send request to firmware */
1310 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1311 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
1313 if (!ret)
1314 memcpy(value, rd_eeprom.value, min((u16)MAX_EEPROM_DATA,
1315 rd_eeprom.byte_count));
1316 return ret;
1320 * This function sets a generic IE. In addition to generic IE, it can
1321 * also handle WPA, WPA2 and WAPI IEs.
1323 static int
1324 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1325 u16 ie_len)
1327 struct ieee_types_vendor_header *pvendor_ie;
1328 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1329 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1330 u16 unparsed_len = ie_len, cur_ie_len;
1332 /* If the passed length is zero, reset the buffer */
1333 if (!ie_len) {
1334 priv->gen_ie_buf_len = 0;
1335 priv->wps.session_enable = false;
1336 return 0;
1337 } else if (!ie_data_ptr ||
1338 ie_len <= sizeof(struct ieee_types_header)) {
1339 return -1;
1341 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1343 while (pvendor_ie) {
1344 cur_ie_len = pvendor_ie->len + sizeof(struct ieee_types_header);
1346 if (pvendor_ie->element_id == WLAN_EID_RSN) {
1347 /* IE is a WPA/WPA2 IE so call set_wpa function */
1348 mwifiex_set_wpa_ie(priv, (u8 *)pvendor_ie, cur_ie_len);
1349 priv->wps.session_enable = false;
1350 goto next_ie;
1353 if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1354 /* IE is a WAPI IE so call set_wapi function */
1355 mwifiex_set_wapi_ie(priv, (u8 *)pvendor_ie,
1356 cur_ie_len);
1357 goto next_ie;
1360 if (pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) {
1361 /* Test to see if it is a WPA IE, if not, then
1362 * it is a gen IE
1364 if (!memcmp(&pvendor_ie->oui, wpa_oui,
1365 sizeof(wpa_oui))) {
1366 /* IE is a WPA/WPA2 IE so call set_wpa function
1368 mwifiex_set_wpa_ie(priv, (u8 *)pvendor_ie,
1369 cur_ie_len);
1370 priv->wps.session_enable = false;
1371 goto next_ie;
1374 if (!memcmp(&pvendor_ie->oui, wps_oui,
1375 sizeof(wps_oui))) {
1376 /* Test to see if it is a WPS IE,
1377 * if so, enable wps session flag
1379 priv->wps.session_enable = true;
1380 mwifiex_dbg(priv->adapter, MSG,
1381 "WPS Session Enabled.\n");
1382 mwifiex_set_wps_ie(priv, (u8 *)pvendor_ie,
1383 cur_ie_len);
1384 goto next_ie;
1388 /* Saved in gen_ie, such as P2P IE.etc.*/
1390 /* Verify that the passed length is not larger than the
1391 * available space remaining in the buffer
1393 if (cur_ie_len <
1394 (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1395 /* Append the passed data to the end
1396 * of the genIeBuffer
1398 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len,
1399 (u8 *)pvendor_ie, cur_ie_len);
1400 /* Increment the stored buffer length by the
1401 * size passed
1403 priv->gen_ie_buf_len += cur_ie_len;
1406 next_ie:
1407 unparsed_len -= cur_ie_len;
1409 if (unparsed_len <= sizeof(struct ieee_types_header))
1410 pvendor_ie = NULL;
1411 else
1412 pvendor_ie = (struct ieee_types_vendor_header *)
1413 (((u8 *)pvendor_ie) + cur_ie_len);
1416 return 0;
1420 * IOCTL request handler to set/get generic IE.
1422 * In addition to various generic IEs, this function can also be
1423 * used to set the ARP filter.
1425 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1426 struct mwifiex_ds_misc_gen_ie *gen_ie,
1427 u16 action)
1429 struct mwifiex_adapter *adapter = priv->adapter;
1431 switch (gen_ie->type) {
1432 case MWIFIEX_IE_TYPE_GEN_IE:
1433 if (action == HostCmd_ACT_GEN_GET) {
1434 gen_ie->len = priv->wpa_ie_len;
1435 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1436 } else {
1437 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1438 (u16) gen_ie->len);
1440 break;
1441 case MWIFIEX_IE_TYPE_ARP_FILTER:
1442 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1443 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1444 adapter->arp_filter_size = 0;
1445 mwifiex_dbg(adapter, ERROR,
1446 "invalid ARP filter size\n");
1447 return -1;
1448 } else {
1449 memcpy(adapter->arp_filter, gen_ie->ie_data,
1450 gen_ie->len);
1451 adapter->arp_filter_size = gen_ie->len;
1453 break;
1454 default:
1455 mwifiex_dbg(adapter, ERROR, "invalid IE type\n");
1456 return -1;
1458 return 0;
1462 * Sends IOCTL request to set a generic IE.
1464 * This function allocates the IOCTL request buffer, fills it
1465 * with requisite parameters and calls the IOCTL handler.
1468 mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
1470 struct mwifiex_ds_misc_gen_ie gen_ie;
1472 if (ie_len > IEEE_MAX_IE_SIZE)
1473 return -EFAULT;
1475 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1476 gen_ie.len = ie_len;
1477 memcpy(gen_ie.ie_data, ie, ie_len);
1478 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
1479 return -EFAULT;
1481 return 0;
1484 /* This function get Host Sleep wake up reason.
1487 int mwifiex_get_wakeup_reason(struct mwifiex_private *priv, u16 action,
1488 int cmd_type,
1489 struct mwifiex_ds_wakeup_reason *wakeup_reason)
1491 int status = 0;
1493 status = mwifiex_send_cmd(priv, HostCmd_CMD_HS_WAKEUP_REASON,
1494 HostCmd_ACT_GEN_GET, 0, wakeup_reason,
1495 cmd_type == MWIFIEX_SYNC_CMD);
1497 return status;
1500 int mwifiex_get_chan_info(struct mwifiex_private *priv,
1501 struct mwifiex_channel_band *channel_band)
1503 int status = 0;
1505 status = mwifiex_send_cmd(priv, HostCmd_CMD_STA_CONFIGURE,
1506 HostCmd_ACT_GEN_GET, 0, channel_band,
1507 MWIFIEX_SYNC_CMD);
1509 return status;