2 * Marvell Wireless LAN device driver: functions for station ioctl
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. 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.
30 * Copies the multicast address list from device to driver.
32 * This function does not validate the destination memory for
33 * size, and the calling function must ensure enough memory is
36 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
37 struct net_device *dev)
40 struct netdev_hw_addr *ha;
42 netdev_for_each_mc_addr(ha, dev)
43 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
49 * Wait queue completion handler.
51 * This function waits on a cmd wait queue. It also cancels the pending
52 * request after waking up, in case of errors.
54 int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
56 bool cancel_flag = false;
57 int status = adapter->cmd_wait_q.status;
59 dev_dbg(adapter->dev, "cmd pending\n");
60 atomic_inc(&adapter->cmd_pending);
62 /* Status pending, wake up main process */
63 queue_work(adapter->workqueue, &adapter->main_work);
65 /* Wait for completion */
66 wait_event_interruptible(adapter->cmd_wait_q.wait,
67 adapter->cmd_wait_q.condition);
68 if (!adapter->cmd_wait_q.condition)
72 mwifiex_cancel_pending_ioctl(adapter);
73 dev_dbg(adapter->dev, "cmd cancel\n");
75 adapter->cmd_wait_q.status = 0;
81 * This function prepares the correct firmware command and
82 * issues it to set the multicast list.
84 * This function can be used to enable promiscuous mode, or enable all
85 * multicast packets, or to enable selective multicast.
87 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
88 struct mwifiex_multicast_list *mcast_list)
93 old_pkt_filter = priv->curr_pkt_filter;
95 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
96 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
97 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
98 priv->curr_pkt_filter &=
99 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
102 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
103 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
104 dev_dbg(priv->adapter->dev,
105 "info: Enabling All Multicast!\n");
106 priv->curr_pkt_filter |=
107 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
109 priv->curr_pkt_filter &=
110 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
111 if (mcast_list->num_multicast_addr) {
112 dev_dbg(priv->adapter->dev,
113 "info: Set multicast list=%d\n",
114 mcast_list->num_multicast_addr);
115 /* Set multicast addresses to firmware */
116 if (old_pkt_filter == priv->curr_pkt_filter) {
117 /* Send request to firmware */
118 ret = mwifiex_send_cmd_async(priv,
119 HostCmd_CMD_MAC_MULTICAST_ADR,
120 HostCmd_ACT_GEN_SET, 0,
123 /* Send request to firmware */
124 ret = mwifiex_send_cmd_async(priv,
125 HostCmd_CMD_MAC_MULTICAST_ADR,
126 HostCmd_ACT_GEN_SET, 0,
132 dev_dbg(priv->adapter->dev,
133 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
134 old_pkt_filter, priv->curr_pkt_filter);
135 if (old_pkt_filter != priv->curr_pkt_filter) {
136 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
138 0, &priv->curr_pkt_filter);
145 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
146 * In both Ad-Hoc and infra mode, an deauthentication is performed
149 int mwifiex_bss_start(struct mwifiex_private *priv,
150 struct mwifiex_ssid_bssid *ssid_bssid)
153 struct mwifiex_adapter *adapter = priv->adapter;
156 priv->scan_block = false;
160 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
162 ret = mwifiex_deauthenticate(priv, NULL);
166 /* Search for the requested SSID in the scan table */
167 if (ssid_bssid->ssid.ssid_len)
168 i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid,
169 NULL, NL80211_IFTYPE_STATION);
171 i = mwifiex_find_bssid_in_list(priv,
172 (u8 *) &ssid_bssid->bssid,
173 NL80211_IFTYPE_STATION);
177 dev_dbg(adapter->dev,
178 "info: SSID found in scan list ... associating...\n");
180 /* Clear any past association response stored for
181 * application retrieval */
182 priv->assoc_rsp_size = 0;
183 ret = mwifiex_associate(priv, &adapter->scan_table[i]);
188 /* If the requested SSID matches current SSID, return */
189 if (ssid_bssid->ssid.ssid_len &&
191 (&priv->curr_bss_params.bss_descriptor.ssid,
195 /* Exit Adhoc mode first */
196 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
197 ret = mwifiex_deauthenticate(priv, NULL);
201 priv->adhoc_is_link_sensed = false;
203 /* Search for the requested network in the scan table */
204 if (ssid_bssid->ssid.ssid_len)
205 i = mwifiex_find_ssid_in_list(priv,
206 &ssid_bssid->ssid, NULL,
207 NL80211_IFTYPE_ADHOC);
209 i = mwifiex_find_bssid_in_list(priv,
210 (u8 *)&ssid_bssid->bssid,
211 NL80211_IFTYPE_ADHOC);
214 dev_dbg(adapter->dev, "info: network found in scan"
215 " list. Joining...\n");
216 ret = mwifiex_adhoc_join(priv, &adapter->scan_table[i]);
219 } else { /* i >= 0 */
220 dev_dbg(adapter->dev, "info: Network not found in "
221 "the list, creating adhoc with ssid = %s\n",
222 ssid_bssid->ssid.ssid);
223 ret = mwifiex_adhoc_start(priv, &ssid_bssid->ssid);
233 * IOCTL request handler to set host sleep configuration.
235 * This function prepares the correct firmware command and
238 int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
239 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
242 struct mwifiex_adapter *adapter = priv->adapter;
250 case HostCmd_ACT_GEN_SET:
251 if (adapter->pps_uapsd_mode) {
252 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
253 " is blocked in UAPSD/PPS mode\n");
257 if (hs_cfg->is_invoke_hostcmd) {
258 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
259 if (!adapter->is_hs_configured)
260 /* Already cancelled */
262 /* Save previous condition */
263 prev_cond = le32_to_cpu(adapter->hs_cfg
265 adapter->hs_cfg.conditions =
266 cpu_to_le32(hs_cfg->conditions);
267 } else if (hs_cfg->conditions) {
268 adapter->hs_cfg.conditions =
269 cpu_to_le32(hs_cfg->conditions);
270 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
272 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
273 } else if (adapter->hs_cfg.conditions ==
275 HOST_SLEEP_CFG_CANCEL)) {
276 /* Return failure if no parameters for HS
281 if (cmd_type == MWIFIEX_SYNC_CMD)
282 status = mwifiex_send_cmd_sync(priv,
283 HostCmd_CMD_802_11_HS_CFG_ENH,
284 HostCmd_ACT_GEN_SET, 0,
287 status = mwifiex_send_cmd_async(priv,
288 HostCmd_CMD_802_11_HS_CFG_ENH,
289 HostCmd_ACT_GEN_SET, 0,
291 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
292 /* Restore previous condition */
293 adapter->hs_cfg.conditions =
294 cpu_to_le32(prev_cond);
296 adapter->hs_cfg.conditions =
297 cpu_to_le32(hs_cfg->conditions);
298 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
299 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
302 case HostCmd_ACT_GEN_GET:
303 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
304 hs_cfg->gpio = adapter->hs_cfg.gpio;
305 hs_cfg->gap = adapter->hs_cfg.gap;
316 * Sends IOCTL request to cancel the existing Host Sleep configuration.
318 * This function allocates the IOCTL request buffer, fills it
319 * with requisite parameters and calls the IOCTL handler.
321 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
324 struct mwifiex_ds_hs_cfg hscfg;
326 /* Cancel Host Sleep */
327 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
328 hscfg.is_invoke_hostcmd = true;
329 ret = mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
334 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
337 * Sends IOCTL request to cancel the existing Host Sleep configuration.
339 * This function allocates the IOCTL request buffer, fills it
340 * with requisite parameters and calls the IOCTL handler.
342 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
344 struct mwifiex_ds_hs_cfg hscfg;
346 if (adapter->hs_activated) {
347 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
351 /* Enable Host Sleep */
352 adapter->hs_activate_wait_q_woken = false;
354 memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
355 hscfg.is_invoke_hostcmd = true;
357 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
358 MWIFIEX_BSS_ROLE_STA),
359 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
361 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
365 wait_event_interruptible(adapter->hs_activate_wait_q,
366 adapter->hs_activate_wait_q_woken);
370 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
373 * IOCTL request handler to get BSS information.
375 * This function collates the information from different driver structures
376 * to send to the user.
378 int mwifiex_get_bss_info(struct mwifiex_private *priv,
379 struct mwifiex_bss_info *info)
381 struct mwifiex_adapter *adapter = priv->adapter;
382 struct mwifiex_bssdescriptor *bss_desc;
388 /* Get current BSS info */
389 bss_desc = &priv->curr_bss_params.bss_descriptor;
392 info->bss_mode = priv->bss_mode;
395 memcpy(&info->ssid, &bss_desc->ssid,
396 sizeof(struct mwifiex_802_11_ssid));
399 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
402 info->bss_chan = bss_desc->channel;
405 info->region_code = adapter->region_code;
407 /* Scan table index if connected */
408 info->scan_table_idx = 0;
409 if (priv->media_connected) {
411 mwifiex_find_ssid_in_list(priv, &bss_desc->ssid,
412 bss_desc->mac_address,
415 info->scan_table_idx = tbl_idx;
418 /* Connection status */
419 info->media_connected = priv->media_connected;
421 /* Tx power information */
422 info->max_power_level = priv->max_tx_power_level;
423 info->min_power_level = priv->min_tx_power_level;
426 info->adhoc_state = priv->adhoc_state;
429 info->bcn_nf_last = priv->bcn_nf_last;
432 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
433 info->wep_status = true;
435 info->wep_status = false;
437 info->is_hs_configured = adapter->is_hs_configured;
438 info->is_deep_sleep = adapter->is_deep_sleep;
444 * The function sets band configurations.
446 * it performs extra checks to make sure the Ad-Hoc
447 * band and channel are compatible. Otherwise it returns an error.
450 int mwifiex_set_radio_band_cfg(struct mwifiex_private *priv,
451 struct mwifiex_ds_band_cfg *radio_cfg)
453 struct mwifiex_adapter *adapter = priv->adapter;
456 u32 adhoc_channel = 0;
458 infra_band = (u8) radio_cfg->config_bands;
459 adhoc_band = (u8) radio_cfg->adhoc_start_band;
460 adhoc_channel = radio_cfg->adhoc_channel;
463 if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
466 adapter->config_bands = infra_band;
468 /* SET Ad-hoc Band */
469 if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
473 adapter->adhoc_start_band = adhoc_band;
474 adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
476 * If no adhoc_channel is supplied verify if the existing adhoc
477 * channel compiles with new adhoc_band
479 if (!adhoc_channel) {
480 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
481 (priv, adapter->adhoc_start_band,
482 priv->adhoc_channel)) {
483 /* Pass back the default channel */
484 radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
485 if ((adapter->adhoc_start_band & BAND_A)
486 || (adapter->adhoc_start_band & BAND_AN))
487 radio_cfg->adhoc_channel =
488 DEFAULT_AD_HOC_CHANNEL_A;
490 } else { /* Retrurn error if adhoc_band and
491 adhoc_channel combination is invalid */
492 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
493 (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
495 priv->adhoc_channel = (u8) adhoc_channel;
497 if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
498 adapter->adhoc_11n_enabled = true;
500 adapter->adhoc_11n_enabled = false;
506 * IOCTL request handler to set/get active channel.
508 * This function performs validity checking on channel/frequency
509 * compatibility and returns failure if not valid.
511 int mwifiex_bss_set_channel(struct mwifiex_private *priv,
512 struct mwifiex_chan_freq_power *chan)
514 struct mwifiex_adapter *adapter = priv->adapter;
515 struct mwifiex_chan_freq_power *cfp = NULL;
520 if (!chan->channel && !chan->freq)
522 if (adapter->adhoc_start_band & BAND_AN)
523 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
524 else if (adapter->adhoc_start_band & BAND_A)
525 adapter->adhoc_start_band = BAND_G | BAND_B;
527 if (chan->channel <= MAX_CHANNEL_BAND_BG)
528 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
529 (priv, 0, (u16) chan->channel);
531 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
532 (priv, BAND_A, (u16) chan->channel);
534 if (adapter->adhoc_11n_enabled)
535 adapter->adhoc_start_band = BAND_A
538 adapter->adhoc_start_band = BAND_A;
542 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
543 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
544 priv, 0, chan->freq);
546 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
547 (priv, BAND_A, chan->freq);
549 if (adapter->adhoc_11n_enabled)
550 adapter->adhoc_start_band = BAND_A
553 adapter->adhoc_start_band = BAND_A;
557 if (!cfp || !cfp->channel) {
558 dev_err(adapter->dev, "invalid channel/freq\n");
561 priv->adhoc_channel = (u8) cfp->channel;
562 chan->channel = cfp->channel;
563 chan->freq = cfp->freq;
569 * IOCTL request handler to set/get Ad-Hoc channel.
571 * This function prepares the correct firmware command and
572 * issues it to set or get the ad-hoc channel.
574 static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
575 u16 action, u16 *channel)
579 if (action == HostCmd_ACT_GEN_GET) {
580 if (!priv->media_connected) {
581 *channel = priv->adhoc_channel;
585 priv->adhoc_channel = (u8) *channel;
588 /* Send request to firmware */
589 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
596 * IOCTL request handler to find a particular BSS.
598 * The BSS can be searched with either a BSSID or a SSID. If none of
599 * these are provided, just the best BSS (best RSSI) is returned.
601 int mwifiex_bss_ioctl_find_bss(struct mwifiex_private *priv,
602 struct mwifiex_ssid_bssid *ssid_bssid)
604 struct mwifiex_adapter *adapter = priv->adapter;
606 struct mwifiex_bssdescriptor *bss_desc;
607 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
611 if (memcmp(ssid_bssid->bssid, zero_mac, sizeof(zero_mac))) {
612 i = mwifiex_find_bssid_in_list(priv,
613 (u8 *) ssid_bssid->bssid,
616 memcpy(mac, ssid_bssid->bssid, sizeof(mac));
617 dev_err(adapter->dev, "cannot find bssid %pM\n", mac);
620 bss_desc = &adapter->scan_table[i];
621 memcpy(&ssid_bssid->ssid, &bss_desc->ssid,
622 sizeof(struct mwifiex_802_11_ssid));
623 } else if (ssid_bssid->ssid.ssid_len) {
624 i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid, NULL,
627 dev_err(adapter->dev, "cannot find ssid %s\n",
628 ssid_bssid->ssid.ssid);
631 bss_desc = &adapter->scan_table[i];
632 memcpy(ssid_bssid->bssid, bss_desc->mac_address, ETH_ALEN);
634 ret = mwifiex_find_best_network(priv, ssid_bssid);
641 * IOCTL request handler to change Ad-Hoc channel.
643 * This function allocates the IOCTL request buffer, fills it
644 * with requisite parameters and calls the IOCTL handler.
646 * The function follows the following steps to perform the change -
647 * - Get current IBSS information
648 * - Get current channel
649 * - If no change is required, return
650 * - If not connected, change channel and return
654 * - Perform specific SSID scan with same SSID
655 * - Start/Join the IBSS
658 mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
661 struct mwifiex_bss_info bss_info;
662 struct mwifiex_ssid_bssid ssid_bssid;
665 memset(&bss_info, 0, sizeof(bss_info));
667 /* Get BSS information */
668 if (mwifiex_get_bss_info(priv, &bss_info))
671 /* Get current channel */
672 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
675 if (curr_chan == channel) {
679 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
682 if (!bss_info.media_connected) {
688 memset(&ssid_bssid, 0, ETH_ALEN);
689 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
691 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
694 /* Do specific SSID scanning */
695 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
699 /* Start/Join Adhoc network */
700 memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid));
701 memcpy(&ssid_bssid.ssid, &bss_info.ssid,
702 sizeof(struct mwifiex_802_11_ssid));
704 ret = mwifiex_bss_start(priv, &ssid_bssid);
710 * IOCTL request handler to get rate.
712 * This function prepares the correct firmware command and
713 * issues it to get the current rate if it is connected,
714 * otherwise, the function returns the lowest supported rate
717 static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
718 struct mwifiex_rate_cfg *rate_cfg)
720 struct mwifiex_adapter *adapter = priv->adapter;
723 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
724 if (!priv->media_connected) {
725 switch (adapter->config_bands) {
727 /* Return the lowest supported rate for B band */
728 rate_cfg->rate = supported_rates_b[0] & 0x7f;
731 case BAND_G | BAND_GN:
732 /* Return the lowest supported rate for G band */
733 rate_cfg->rate = supported_rates_g[0] & 0x7f;
735 case BAND_B | BAND_G:
736 case BAND_A | BAND_B | BAND_G:
737 case BAND_A | BAND_B:
738 case BAND_A | BAND_B | BAND_G | BAND_AN | BAND_GN:
739 case BAND_B | BAND_G | BAND_GN:
740 /* Return the lowest supported rate for BG band */
741 rate_cfg->rate = supported_rates_bg[0] & 0x7f;
744 case BAND_A | BAND_G:
745 case BAND_A | BAND_G | BAND_AN | BAND_GN:
746 case BAND_A | BAND_AN:
747 /* Return the lowest supported rate for A band */
748 rate_cfg->rate = supported_rates_a[0] & 0x7f;
751 /* Return the lowest supported rate for N band */
752 rate_cfg->rate = supported_rates_n[0] & 0x7f;
755 dev_warn(adapter->dev, "invalid band %#x\n",
756 adapter->config_bands);
760 /* Send request to firmware */
761 ret = mwifiex_send_cmd_sync(priv,
762 HostCmd_CMD_802_11_TX_RATE_QUERY,
763 HostCmd_ACT_GEN_GET, 0, NULL);
770 * IOCTL request handler to set rate.
772 * This function prepares the correct firmware command and
773 * issues it to set the current rate.
775 * The function also performs validation checking on the supplied value.
777 static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
778 struct mwifiex_rate_cfg *rate_cfg)
780 u8 rates[MWIFIEX_SUPPORTED_RATES];
783 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
786 struct mwifiex_adapter *adapter = priv->adapter;
788 if (rate_cfg->is_rate_auto) {
789 memset(bitmap_rates, 0, sizeof(bitmap_rates));
790 /* Support all HR/DSSS rates */
791 bitmap_rates[0] = 0x000F;
792 /* Support all OFDM rates */
793 bitmap_rates[1] = 0x00FF;
794 /* Support all HT-MCSs rate */
795 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
796 bitmap_rates[i + 2] = 0xFFFF;
797 bitmap_rates[9] = 0x3FFF;
799 memset(rates, 0, sizeof(rates));
800 mwifiex_get_active_data_rates(priv, rates);
802 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
803 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
804 rate[i], rate_cfg->rate);
805 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
808 if (!rate[i] || (i == MWIFIEX_SUPPORTED_RATES)) {
809 dev_err(adapter->dev, "fixed data rate %#x is out "
810 "of range\n", rate_cfg->rate);
813 memset(bitmap_rates, 0, sizeof(bitmap_rates));
815 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
817 /* Only allow b/g rates to be set */
818 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
819 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
820 bitmap_rates[0] = 1 << rate_index;
822 rate_index -= 1; /* There is a 0x00 in the table */
823 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
824 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
825 bitmap_rates[1] = 1 << (rate_index -
826 MWIFIEX_RATE_INDEX_OFDM0);
830 /* Send request to firmware */
831 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
832 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
838 * IOCTL request handler to set/get rate.
840 * This function can be used to set/get either the rate value or the
843 static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
844 struct mwifiex_rate_cfg *rate_cfg)
851 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
852 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
854 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
860 * Sends IOCTL request to get the data rate.
862 * This function allocates the IOCTL request buffer, fills it
863 * with requisite parameters and calls the IOCTL handler.
865 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
866 struct mwifiex_rate_cfg *rate)
870 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
871 rate->action = HostCmd_ACT_GEN_GET;
872 ret = mwifiex_rate_ioctl_cfg(priv, rate);
875 if (rate && rate->is_rate_auto)
876 rate->rate = mwifiex_index_to_data_rate(priv->tx_rate,
879 rate->rate = priv->data_rate;
888 * IOCTL request handler to set tx power configuration.
890 * This function prepares the correct firmware command and
893 * For non-auto power mode, all the following power groups are set -
894 * - Modulation class HR/DSSS
895 * - Modulation class OFDM
896 * - Modulation class HTBW20
897 * - Modulation class HTBW40
899 int mwifiex_set_tx_power(struct mwifiex_private *priv,
900 struct mwifiex_power_cfg *power_cfg)
903 struct host_cmd_ds_txpwr_cfg *txp_cfg = NULL;
904 struct mwifiex_types_power_group *pg_tlv = NULL;
905 struct mwifiex_power_group *pg = NULL;
909 if (!power_cfg->is_power_auto) {
910 dbm = (u16) power_cfg->power_level;
911 if ((dbm < priv->min_tx_power_level) ||
912 (dbm > priv->max_tx_power_level)) {
913 dev_err(priv->adapter->dev, "txpower value %d dBm"
914 " is out of range (%d dBm-%d dBm)\n",
915 dbm, priv->min_tx_power_level,
916 priv->max_tx_power_level);
920 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
922 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
927 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
928 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
929 if (!power_cfg->is_power_auto) {
930 txp_cfg->mode = cpu_to_le32(1);
931 pg_tlv = (struct mwifiex_types_power_group *) (buf +
932 sizeof(struct host_cmd_ds_txpwr_cfg));
933 pg_tlv->type = TLV_TYPE_POWER_GROUP;
934 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
935 pg = (struct mwifiex_power_group *) (buf +
936 sizeof(struct host_cmd_ds_txpwr_cfg) +
937 sizeof(struct mwifiex_types_power_group));
938 /* Power group for modulation class HR/DSSS */
939 pg->first_rate_code = 0x00;
940 pg->last_rate_code = 0x03;
941 pg->modulation_class = MOD_CLASS_HR_DSSS;
943 pg->power_min = (s8) dbm;
944 pg->power_max = (s8) dbm;
946 /* Power group for modulation class OFDM */
947 pg->first_rate_code = 0x00;
948 pg->last_rate_code = 0x07;
949 pg->modulation_class = MOD_CLASS_OFDM;
951 pg->power_min = (s8) dbm;
952 pg->power_max = (s8) dbm;
954 /* Power group for modulation class HTBW20 */
955 pg->first_rate_code = 0x00;
956 pg->last_rate_code = 0x20;
957 pg->modulation_class = MOD_CLASS_HT;
959 pg->power_min = (s8) dbm;
960 pg->power_max = (s8) dbm;
961 pg->ht_bandwidth = HT_BW_20;
963 /* Power group for modulation class HTBW40 */
964 pg->first_rate_code = 0x00;
965 pg->last_rate_code = 0x20;
966 pg->modulation_class = MOD_CLASS_HT;
968 pg->power_min = (s8) dbm;
969 pg->power_max = (s8) dbm;
970 pg->ht_bandwidth = HT_BW_40;
972 /* Send request to firmware */
973 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
974 HostCmd_ACT_GEN_SET, 0, buf);
981 * IOCTL request handler to get power save mode.
983 * This function prepares the correct firmware command and
986 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
989 struct mwifiex_adapter *adapter = priv->adapter;
993 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
995 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
996 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
997 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
998 sub_cmd, BITMAP_STA_PS, NULL);
999 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
1000 ret = mwifiex_send_cmd_async(priv,
1001 HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
1008 * IOCTL request handler to set/reset WPA IE.
1010 * The supplied WPA IE is treated as a opaque buffer. Only the first field
1011 * is checked to determine WPA version. If buffer length is zero, the existing
1014 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
1015 u8 *ie_data_ptr, u16 ie_len)
1018 if (ie_len > sizeof(priv->wpa_ie)) {
1019 dev_err(priv->adapter->dev,
1020 "failed to copy WPA IE, too big\n");
1023 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
1024 priv->wpa_ie_len = (u8) ie_len;
1025 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
1026 priv->wpa_ie_len, priv->wpa_ie[0]);
1028 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
1029 priv->sec_info.wpa_enabled = true;
1030 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
1031 priv->sec_info.wpa2_enabled = true;
1033 priv->sec_info.wpa_enabled = false;
1034 priv->sec_info.wpa2_enabled = false;
1037 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
1038 priv->wpa_ie_len = 0;
1039 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
1040 priv->wpa_ie_len, priv->wpa_ie[0]);
1041 priv->sec_info.wpa_enabled = false;
1042 priv->sec_info.wpa2_enabled = false;
1049 * IOCTL request handler to set/reset WAPI IE.
1051 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
1052 * is checked to internally enable WAPI. If buffer length is zero, the existing
1055 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
1056 u8 *ie_data_ptr, u16 ie_len)
1059 if (ie_len > sizeof(priv->wapi_ie)) {
1060 dev_dbg(priv->adapter->dev,
1061 "info: failed to copy WAPI IE, too big\n");
1064 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
1065 priv->wapi_ie_len = ie_len;
1066 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
1067 priv->wapi_ie_len, priv->wapi_ie[0]);
1069 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
1070 priv->sec_info.wapi_enabled = true;
1072 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
1073 priv->wapi_ie_len = ie_len;
1074 dev_dbg(priv->adapter->dev,
1075 "info: Reset wapi_ie_len=%d IE=%#x\n",
1076 priv->wapi_ie_len, priv->wapi_ie[0]);
1077 priv->sec_info.wapi_enabled = false;
1083 * IOCTL request handler to set WAPI key.
1085 * This function prepares the correct firmware command and
1088 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
1089 struct mwifiex_ds_encrypt_key *encrypt_key)
1093 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1094 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1101 * IOCTL request handler to set WEP network key.
1103 * This function prepares the correct firmware command and
1104 * issues it, after validation checks.
1106 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
1107 struct mwifiex_ds_encrypt_key *encrypt_key)
1110 struct mwifiex_wep_key *wep_key = NULL;
1113 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1114 priv->wep_key_curr_index = 0;
1115 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1116 index = encrypt_key->key_index;
1117 if (encrypt_key->key_disable) {
1118 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
1119 } else if (!encrypt_key->key_len) {
1120 /* Copy the required key as the current key */
1121 wep_key = &priv->wep_key[index];
1122 if (!wep_key->key_length) {
1123 dev_err(priv->adapter->dev,
1124 "key not set, so cannot enable it\n");
1127 priv->wep_key_curr_index = (u16) index;
1128 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1130 wep_key = &priv->wep_key[index];
1132 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1133 /* Copy the key in the driver */
1134 memcpy(wep_key->key_material,
1135 encrypt_key->key_material,
1136 encrypt_key->key_len);
1137 wep_key->key_index = index;
1138 wep_key->key_length = encrypt_key->key_len;
1139 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1141 if (wep_key->key_length) {
1142 /* Send request to firmware */
1143 ret = mwifiex_send_cmd_async(priv,
1144 HostCmd_CMD_802_11_KEY_MATERIAL,
1145 HostCmd_ACT_GEN_SET, 0, NULL);
1149 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
1150 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1152 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1154 /* Send request to firmware */
1155 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1156 HostCmd_ACT_GEN_SET, 0,
1157 &priv->curr_pkt_filter);
1163 * IOCTL request handler to set WPA key.
1165 * This function prepares the correct firmware command and
1166 * issues it, after validation checks.
1168 * Current driver only supports key length of up to 32 bytes.
1170 * This function can also be used to disable a currently set key.
1172 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
1173 struct mwifiex_ds_encrypt_key *encrypt_key)
1176 u8 remove_key = false;
1177 struct host_cmd_ds_802_11_key_material *ibss_key;
1179 /* Current driver only supports key length of up to 32 bytes */
1180 if (encrypt_key->key_len > MWIFIEX_MAX_KEY_LENGTH) {
1181 dev_err(priv->adapter->dev, "key length too long\n");
1185 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1187 * IBSS/WPA-None uses only one key (Group) for both receiving
1188 * and sending unicast and multicast packets.
1190 /* Send the key as PTK to firmware */
1191 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1192 ret = mwifiex_send_cmd_async(priv,
1193 HostCmd_CMD_802_11_KEY_MATERIAL,
1194 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1199 ibss_key = &priv->aes_key;
1201 sizeof(struct host_cmd_ds_802_11_key_material));
1202 /* Copy the key in the driver */
1203 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1204 encrypt_key->key_len);
1205 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1206 sizeof(ibss_key->key_param_set.key_len));
1207 ibss_key->key_param_set.key_type_id
1208 = cpu_to_le16(KEY_TYPE_ID_TKIP);
1209 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
1211 /* Send the key as GTK to firmware */
1212 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1215 if (!encrypt_key->key_index)
1216 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1219 /* Send request to firmware */
1220 ret = mwifiex_send_cmd_sync(priv,
1221 HostCmd_CMD_802_11_KEY_MATERIAL,
1222 HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
1225 /* Send request to firmware */
1226 ret = mwifiex_send_cmd_sync(priv,
1227 HostCmd_CMD_802_11_KEY_MATERIAL,
1228 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1235 * IOCTL request handler to set/get network keys.
1237 * This is a generic key handling function which supports WEP, WPA
1241 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
1242 struct mwifiex_ds_encrypt_key *encrypt_key)
1246 if (encrypt_key->is_wapi_key)
1247 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
1248 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
1249 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
1251 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
1256 * This function returns the driver version.
1259 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1268 ver.l = adapter->fw_release_number;
1269 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1271 snprintf(version, max_len, driver_version, fw_ver);
1273 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1279 * Sends IOCTL request to get signal information.
1281 * This function allocates the IOCTL request buffer, fills it
1282 * with requisite parameters and calls the IOCTL handler.
1284 int mwifiex_get_signal_info(struct mwifiex_private *priv,
1285 struct mwifiex_ds_get_signal *signal)
1287 struct mwifiex_ds_get_signal info;
1290 memset(&info, 0, sizeof(struct mwifiex_ds_get_signal));
1291 info.selector = ALL_RSSI_INFO_MASK;
1293 /* Signal info can be obtained only if connected */
1294 if (!priv->media_connected) {
1295 dev_dbg(priv->adapter->dev,
1296 "info: Can not get signal in disconnected state\n");
1300 /* Send request to firmware */
1301 status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
1302 HostCmd_ACT_GEN_GET, 0, signal);
1306 memcpy(signal, &info,
1307 sizeof(struct mwifiex_ds_get_signal));
1308 if (info.selector & BCN_RSSI_AVG_MASK)
1309 priv->w_stats.qual.level = info.bcn_rssi_avg;
1310 if (info.selector & BCN_NF_AVG_MASK)
1311 priv->w_stats.qual.noise = info.bcn_nf_avg;
1318 * Sends IOCTL request to set encoding parameters.
1320 * This function allocates the IOCTL request buffer, fills it
1321 * with requisite parameters and calls the IOCTL handler.
1323 int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1324 int key_len, u8 key_index, int disable)
1326 struct mwifiex_ds_encrypt_key encrypt_key;
1329 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1330 encrypt_key.key_len = key_len;
1332 encrypt_key.key_index = key_index;
1334 memcpy(encrypt_key.key_material, key, key_len);
1336 encrypt_key.key_disable = true;
1339 ret = mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1345 * Sends IOCTL request to get extended version.
1347 * This function allocates the IOCTL request buffer, fills it
1348 * with requisite parameters and calls the IOCTL handler.
1351 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1353 struct mwifiex_ver_ext ver_ext;
1356 /* get fw version */
1357 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1358 /* Send request to firmware */
1359 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1360 HostCmd_ACT_GEN_GET, 0, &ver_ext);
1369 * Sends IOCTL request to get statistics information.
1371 * This function allocates the IOCTL request buffer, fills it
1372 * with requisite parameters and calls the IOCTL handler.
1375 mwifiex_get_stats_info(struct mwifiex_private *priv,
1376 struct mwifiex_ds_get_stats *log)
1379 struct mwifiex_ds_get_stats get_log;
1381 memset(&get_log, 0, sizeof(struct mwifiex_ds_get_stats));
1382 /* Send request to firmware */
1383 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1384 HostCmd_ACT_GEN_GET, 0, &get_log);
1388 memcpy(log, &get_log, sizeof(struct
1389 mwifiex_ds_get_stats));
1390 priv->w_stats.discard.fragment = get_log.fcs_error;
1391 priv->w_stats.discard.retries = get_log.retry;
1392 priv->w_stats.discard.misc = get_log.ack_failure;
1399 * IOCTL request handler to read/write register.
1401 * This function prepares the correct firmware command and
1404 * Access to the following registers are supported -
1411 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1412 struct mwifiex_ds_reg_rw *reg_rw,
1418 switch (le32_to_cpu(reg_rw->type)) {
1419 case MWIFIEX_REG_MAC:
1420 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1422 case MWIFIEX_REG_BBP:
1423 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1425 case MWIFIEX_REG_RF:
1426 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1428 case MWIFIEX_REG_PMIC:
1429 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1431 case MWIFIEX_REG_CAU:
1432 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1438 /* Send request to firmware */
1439 ret = mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1445 * Sends IOCTL request to write to a register.
1447 * This function allocates the IOCTL request buffer, fills it
1448 * with requisite parameters and calls the IOCTL handler.
1451 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1452 u32 reg_offset, u32 reg_value)
1455 struct mwifiex_ds_reg_rw reg_rw;
1457 reg_rw.type = cpu_to_le32(reg_type);
1458 reg_rw.offset = cpu_to_le32(reg_offset);
1459 reg_rw.value = cpu_to_le32(reg_value);
1460 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET);
1466 * Sends IOCTL request to read from a register.
1468 * This function allocates the IOCTL request buffer, fills it
1469 * with requisite parameters and calls the IOCTL handler.
1472 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1473 u32 reg_offset, u32 *value)
1476 struct mwifiex_ds_reg_rw reg_rw;
1478 reg_rw.type = cpu_to_le32(reg_type);
1479 reg_rw.offset = cpu_to_le32(reg_offset);
1480 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET);
1485 *value = le32_to_cpu(reg_rw.value);
1492 * Sends IOCTL request to read from EEPROM.
1494 * This function allocates the IOCTL request buffer, fills it
1495 * with requisite parameters and calls the IOCTL handler.
1498 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1502 struct mwifiex_ds_read_eeprom rd_eeprom;
1504 rd_eeprom.offset = cpu_to_le16((u16) offset);
1505 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1507 /* Send request to firmware */
1508 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1509 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1512 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1517 * This function sets a generic IE. In addition to generic IE, it can
1518 * also handle WPA, WPA2 and WAPI IEs.
1521 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1525 struct ieee_types_vendor_header *pvendor_ie;
1526 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1527 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1529 /* If the passed length is zero, reset the buffer */
1531 priv->gen_ie_buf_len = 0;
1532 priv->wps.session_enable = false;
1535 } else if (!ie_data_ptr) {
1538 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1539 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1540 if (((pvendor_ie->element_id == WLAN_EID_WPA)
1541 && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
1542 || (pvendor_ie->element_id == WLAN_EID_RSN)) {
1544 /* IE is a WPA/WPA2 IE so call set_wpa function */
1545 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1546 priv->wps.session_enable = false;
1549 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1550 /* IE is a WAPI IE so call set_wapi function */
1551 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1556 * Verify that the passed length is not larger than the
1557 * available space remaining in the buffer
1559 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1561 /* Test to see if it is a WPS IE, if so, enable
1564 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1565 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
1566 && (!memcmp(pvendor_ie->oui, wps_oui,
1567 sizeof(wps_oui)))) {
1568 priv->wps.session_enable = true;
1569 dev_dbg(priv->adapter->dev,
1570 "info: WPS Session Enabled.\n");
1573 /* Append the passed data to the end of the
1575 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1577 /* Increment the stored buffer length by the
1579 priv->gen_ie_buf_len += ie_len;
1581 /* Passed data does not fit in the remaining
1586 /* Return 0, or -1 for error case */
1591 * IOCTL request handler to set/get generic IE.
1593 * In addition to various generic IEs, this function can also be
1594 * used to set the ARP filter.
1596 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1597 struct mwifiex_ds_misc_gen_ie *gen_ie,
1600 struct mwifiex_adapter *adapter = priv->adapter;
1602 switch (gen_ie->type) {
1603 case MWIFIEX_IE_TYPE_GEN_IE:
1604 if (action == HostCmd_ACT_GEN_GET) {
1605 gen_ie->len = priv->wpa_ie_len;
1606 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1608 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1612 case MWIFIEX_IE_TYPE_ARP_FILTER:
1613 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1614 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1615 adapter->arp_filter_size = 0;
1616 dev_err(adapter->dev, "invalid ARP filter size\n");
1619 memcpy(adapter->arp_filter, gen_ie->ie_data,
1621 adapter->arp_filter_size = gen_ie->len;
1625 dev_err(adapter->dev, "invalid IE type\n");
1632 * Sends IOCTL request to set a generic IE.
1634 * This function allocates the IOCTL request buffer, fills it
1635 * with requisite parameters and calls the IOCTL handler.
1638 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1640 struct mwifiex_ds_misc_gen_ie gen_ie;
1643 if (ie_len > IW_CUSTOM_MAX)
1646 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1647 gen_ie.len = ie_len;
1648 memcpy(gen_ie.ie_data, ie, ie_len);
1649 status = mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET);