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.
29 static int disconnect_on_suspend = 1;
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
39 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
40 struct net_device *dev)
43 struct netdev_hw_addr *ha;
45 netdev_for_each_mc_addr(ha, dev)
46 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
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)
60 struct cmd_ctrl_node *cmd_queued;
62 if (!adapter->cmd_queued)
65 cmd_queued = adapter->cmd_queued;
66 adapter->cmd_queued = NULL;
68 dev_dbg(adapter->dev, "cmd pending\n");
69 atomic_inc(&adapter->cmd_pending);
71 /* Wait for completion */
72 status = wait_event_interruptible(adapter->cmd_wait_q.wait,
73 *(cmd_queued->condition));
75 dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status);
79 status = adapter->cmd_wait_q.status;
80 adapter->cmd_wait_q.status = 0;
86 * This function prepares the correct firmware command and
87 * issues it to set the multicast list.
89 * This function can be used to enable promiscuous mode, or enable all
90 * multicast packets, or to enable selective multicast.
92 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
93 struct mwifiex_multicast_list *mcast_list)
98 old_pkt_filter = priv->curr_pkt_filter;
100 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
101 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
102 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
103 priv->curr_pkt_filter &=
104 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
107 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
108 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
109 dev_dbg(priv->adapter->dev,
110 "info: Enabling All Multicast!\n");
111 priv->curr_pkt_filter |=
112 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
114 priv->curr_pkt_filter &=
115 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
116 if (mcast_list->num_multicast_addr) {
117 dev_dbg(priv->adapter->dev,
118 "info: Set multicast list=%d\n",
119 mcast_list->num_multicast_addr);
120 /* Set multicast addresses to firmware */
121 if (old_pkt_filter == priv->curr_pkt_filter) {
122 /* Send request to firmware */
123 ret = mwifiex_send_cmd_async(priv,
124 HostCmd_CMD_MAC_MULTICAST_ADR,
125 HostCmd_ACT_GEN_SET, 0,
128 /* Send request to firmware */
129 ret = mwifiex_send_cmd_async(priv,
130 HostCmd_CMD_MAC_MULTICAST_ADR,
131 HostCmd_ACT_GEN_SET, 0,
137 dev_dbg(priv->adapter->dev,
138 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
139 old_pkt_filter, priv->curr_pkt_filter);
140 if (old_pkt_filter != priv->curr_pkt_filter) {
141 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
143 0, &priv->curr_pkt_filter);
150 * This function fills bss descriptor structure using provided
153 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
154 struct cfg80211_bss *bss,
155 struct mwifiex_bssdescriptor *bss_desc,
156 u8 *beacon_ie, size_t beacon_ie_len)
158 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
160 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
161 bss_desc->rssi = bss->signal;
162 bss_desc->beacon_buf = beacon_ie;
163 bss_desc->beacon_buf_size = beacon_ie_len;
164 bss_desc->beacon_period = bss->beacon_interval;
165 bss_desc->cap_info_bitmap = bss->capability;
166 bss_desc->bss_band = bss_priv->band;
167 bss_desc->fw_tsf = bss_priv->fw_tsf;
168 bss_desc->timestamp = bss->tsf;
169 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
170 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
171 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
173 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
175 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
176 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
178 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
180 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
183 static int mwifiex_process_country_ie(struct mwifiex_private *priv,
184 struct cfg80211_bss *bss)
186 u8 *country_ie, country_ie_len;
187 struct mwifiex_802_11d_domain_reg *domain_info =
188 &priv->adapter->domain_reg;
190 country_ie = (u8 *)ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
195 country_ie_len = country_ie[1];
196 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
199 domain_info->country_code[0] = country_ie[2];
200 domain_info->country_code[1] = country_ie[3];
201 domain_info->country_code[2] = ' ';
203 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
205 domain_info->no_of_triplet =
206 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
208 memcpy((u8 *)domain_info->triplet,
209 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
211 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
212 HostCmd_ACT_GEN_SET, 0, NULL)) {
213 wiphy_err(priv->wdev->wiphy,
214 "11D: setting domain info in FW\n");
222 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
223 * In both Ad-Hoc and infra mode, an deauthentication is performed
226 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
227 struct cfg80211_ssid *req_ssid)
230 struct mwifiex_adapter *adapter = priv->adapter;
231 struct mwifiex_bssdescriptor *bss_desc = NULL;
232 u8 *beacon_ie = NULL;
233 size_t beacon_ie_len;
235 priv->scan_block = false;
238 mwifiex_process_country_ie(priv, bss);
240 /* Allocate and fill new bss descriptor */
241 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
244 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
248 beacon_ie_len = bss->len_information_elements;
249 beacon_ie = kmemdup(bss->information_elements, beacon_ie_len,
256 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc, beacon_ie,
262 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
264 ret = mwifiex_deauthenticate(priv, NULL);
268 ret = mwifiex_check_network_compatibility(priv, bss_desc);
272 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
275 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
276 if (netif_carrier_ok(priv->netdev))
277 netif_carrier_off(priv->netdev);
279 /* Clear any past association response stored for
280 * application retrieval */
281 priv->assoc_rsp_size = 0;
282 ret = mwifiex_associate(priv, bss_desc);
284 /* If auth type is auto and association fails using open mode,
285 * try to connect using shared mode */
286 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
287 priv->sec_info.is_authtype_auto &&
288 priv->sec_info.wep_enabled) {
289 priv->sec_info.authentication_mode =
290 NL80211_AUTHTYPE_SHARED_KEY;
291 ret = mwifiex_associate(priv, bss_desc);
295 cfg80211_put_bss(bss);
298 /* If the requested SSID matches current SSID, return */
299 if (bss_desc && bss_desc->ssid.ssid_len &&
300 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
301 ssid, &bss_desc->ssid))) {
306 /* Exit Adhoc mode first */
307 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
308 ret = mwifiex_deauthenticate(priv, NULL);
312 priv->adhoc_is_link_sensed = false;
314 ret = mwifiex_check_network_compatibility(priv, bss_desc);
316 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
317 if (netif_carrier_ok(priv->netdev))
318 netif_carrier_off(priv->netdev);
321 dev_dbg(adapter->dev, "info: network found in scan"
322 " list. Joining...\n");
323 ret = mwifiex_adhoc_join(priv, bss_desc);
325 cfg80211_put_bss(bss);
327 dev_dbg(adapter->dev, "info: Network not found in "
328 "the list, creating adhoc with ssid = %s\n",
330 ret = mwifiex_adhoc_start(priv, req_ssid);
341 * IOCTL request handler to set host sleep configuration.
343 * This function prepares the correct firmware command and
346 static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
347 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
350 struct mwifiex_adapter *adapter = priv->adapter;
358 case HostCmd_ACT_GEN_SET:
359 if (adapter->pps_uapsd_mode) {
360 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
361 " is blocked in UAPSD/PPS mode\n");
365 if (hs_cfg->is_invoke_hostcmd) {
366 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
367 if (!adapter->is_hs_configured)
368 /* Already cancelled */
370 /* Save previous condition */
371 prev_cond = le32_to_cpu(adapter->hs_cfg
373 adapter->hs_cfg.conditions =
374 cpu_to_le32(hs_cfg->conditions);
375 } else if (hs_cfg->conditions) {
376 adapter->hs_cfg.conditions =
377 cpu_to_le32(hs_cfg->conditions);
378 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
380 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
381 } else if (adapter->hs_cfg.conditions
382 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
383 /* Return failure if no parameters for HS
388 if (cmd_type == MWIFIEX_SYNC_CMD)
389 status = mwifiex_send_cmd_sync(priv,
390 HostCmd_CMD_802_11_HS_CFG_ENH,
391 HostCmd_ACT_GEN_SET, 0,
394 status = mwifiex_send_cmd_async(priv,
395 HostCmd_CMD_802_11_HS_CFG_ENH,
396 HostCmd_ACT_GEN_SET, 0,
398 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
399 /* Restore previous condition */
400 adapter->hs_cfg.conditions =
401 cpu_to_le32(prev_cond);
403 adapter->hs_cfg.conditions =
404 cpu_to_le32(hs_cfg->conditions);
405 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
406 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
409 case HostCmd_ACT_GEN_GET:
410 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
411 hs_cfg->gpio = adapter->hs_cfg.gpio;
412 hs_cfg->gap = adapter->hs_cfg.gap;
423 * Sends IOCTL request to cancel the existing Host Sleep configuration.
425 * This function allocates the IOCTL request buffer, fills it
426 * with requisite parameters and calls the IOCTL handler.
428 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
430 struct mwifiex_ds_hs_cfg hscfg;
432 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
433 hscfg.is_invoke_hostcmd = true;
435 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
438 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
441 * Sends IOCTL request to cancel the existing Host Sleep configuration.
443 * This function allocates the IOCTL request buffer, fills it
444 * with requisite parameters and calls the IOCTL handler.
446 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
448 struct mwifiex_ds_hs_cfg hscfg;
449 struct mwifiex_private *priv;
452 if (disconnect_on_suspend) {
453 for (i = 0; i < adapter->priv_num; i++) {
454 priv = adapter->priv[i];
455 if (priv && priv->media_connected)
456 mwifiex_deauthenticate(priv, NULL);
460 if (adapter->hs_activated) {
461 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
465 adapter->hs_activate_wait_q_woken = false;
467 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
468 hscfg.is_invoke_hostcmd = true;
470 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
471 MWIFIEX_BSS_ROLE_STA),
472 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
474 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
478 if (wait_event_interruptible(adapter->hs_activate_wait_q,
479 adapter->hs_activate_wait_q_woken)) {
480 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
486 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
489 * IOCTL request handler to get BSS information.
491 * This function collates the information from different driver structures
492 * to send to the user.
494 int mwifiex_get_bss_info(struct mwifiex_private *priv,
495 struct mwifiex_bss_info *info)
497 struct mwifiex_adapter *adapter = priv->adapter;
498 struct mwifiex_bssdescriptor *bss_desc;
503 bss_desc = &priv->curr_bss_params.bss_descriptor;
505 info->bss_mode = priv->bss_mode;
507 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
509 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
511 info->bss_chan = bss_desc->channel;
513 memcpy(info->country_code, priv->country_code,
514 IEEE80211_COUNTRY_STRING_LEN);
516 info->media_connected = priv->media_connected;
518 info->max_power_level = priv->max_tx_power_level;
519 info->min_power_level = priv->min_tx_power_level;
521 info->adhoc_state = priv->adhoc_state;
523 info->bcn_nf_last = priv->bcn_nf_last;
525 if (priv->sec_info.wep_enabled)
526 info->wep_status = true;
528 info->wep_status = false;
530 info->is_hs_configured = adapter->is_hs_configured;
531 info->is_deep_sleep = adapter->is_deep_sleep;
537 * The function disables auto deep sleep mode.
539 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
541 struct mwifiex_ds_auto_ds auto_ds;
543 auto_ds.auto_ds = DEEP_SLEEP_OFF;
545 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
546 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
548 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
551 * IOCTL request handler to set/get active channel.
553 * This function performs validity checking on channel/frequency
554 * compatibility and returns failure if not valid.
556 int mwifiex_bss_set_channel(struct mwifiex_private *priv,
557 struct mwifiex_chan_freq_power *chan)
559 struct mwifiex_adapter *adapter = priv->adapter;
560 struct mwifiex_chan_freq_power *cfp = NULL;
565 if (!chan->channel && !chan->freq)
567 if (adapter->adhoc_start_band & BAND_AN)
568 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
569 else if (adapter->adhoc_start_band & BAND_A)
570 adapter->adhoc_start_band = BAND_G | BAND_B;
572 if (chan->channel <= MAX_CHANNEL_BAND_BG)
573 cfp = mwifiex_get_cfp(priv, 0, (u16) chan->channel, 0);
575 cfp = mwifiex_get_cfp(priv, BAND_A,
576 (u16) chan->channel, 0);
578 if (adapter->adhoc_11n_enabled)
579 adapter->adhoc_start_band = BAND_A
582 adapter->adhoc_start_band = BAND_A;
586 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
587 cfp = mwifiex_get_cfp(priv, 0, 0, chan->freq);
589 cfp = mwifiex_get_cfp(priv, BAND_A, 0, chan->freq);
591 if (adapter->adhoc_11n_enabled)
592 adapter->adhoc_start_band = BAND_A
595 adapter->adhoc_start_band = BAND_A;
599 if (!cfp || !cfp->channel) {
600 dev_err(adapter->dev, "invalid channel/freq\n");
603 priv->adhoc_channel = (u8) cfp->channel;
604 chan->channel = cfp->channel;
605 chan->freq = cfp->freq;
611 * IOCTL request handler to set/get Ad-Hoc channel.
613 * This function prepares the correct firmware command and
614 * issues it to set or get the ad-hoc channel.
616 static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
617 u16 action, u16 *channel)
619 if (action == HostCmd_ACT_GEN_GET) {
620 if (!priv->media_connected) {
621 *channel = priv->adhoc_channel;
625 priv->adhoc_channel = (u8) *channel;
628 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
633 * IOCTL request handler to change Ad-Hoc channel.
635 * This function allocates the IOCTL request buffer, fills it
636 * with requisite parameters and calls the IOCTL handler.
638 * The function follows the following steps to perform the change -
639 * - Get current IBSS information
640 * - Get current channel
641 * - If no change is required, return
642 * - If not connected, change channel and return
646 * - Perform specific SSID scan with same SSID
647 * - Start/Join the IBSS
650 mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, u16 channel)
653 struct mwifiex_bss_info bss_info;
654 struct mwifiex_ssid_bssid ssid_bssid;
656 struct cfg80211_bss *bss = NULL;
657 struct ieee80211_channel *chan;
658 enum ieee80211_band band;
660 memset(&bss_info, 0, sizeof(bss_info));
662 /* Get BSS information */
663 if (mwifiex_get_bss_info(priv, &bss_info))
666 /* Get current channel */
667 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
670 if (curr_chan == channel) {
674 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
677 if (!bss_info.media_connected) {
683 memset(&ssid_bssid, 0, ETH_ALEN);
684 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
686 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
689 /* Do specific SSID scanning */
690 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
695 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
696 chan = __ieee80211_get_channel(priv->wdev->wiphy,
697 ieee80211_channel_to_frequency(channel,
700 /* Find the BSS we want using available scan results */
701 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
702 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
703 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
705 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
708 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
714 * IOCTL request handler to get rate.
716 * This function prepares the correct firmware command and
717 * issues it to get the current rate if it is connected,
718 * otherwise, the function returns the lowest supported rate
721 static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
722 struct mwifiex_rate_cfg *rate_cfg)
724 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
725 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
726 HostCmd_ACT_GEN_GET, 0, NULL);
730 * IOCTL request handler to set rate.
732 * This function prepares the correct firmware command and
733 * issues it to set the current rate.
735 * The function also performs validation checking on the supplied value.
737 static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
738 struct mwifiex_rate_cfg *rate_cfg)
740 u8 rates[MWIFIEX_SUPPORTED_RATES];
743 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
745 struct mwifiex_adapter *adapter = priv->adapter;
747 if (rate_cfg->is_rate_auto) {
748 memset(bitmap_rates, 0, sizeof(bitmap_rates));
749 /* Support all HR/DSSS rates */
750 bitmap_rates[0] = 0x000F;
751 /* Support all OFDM rates */
752 bitmap_rates[1] = 0x00FF;
753 /* Support all HT-MCSs rate */
754 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
755 bitmap_rates[i + 2] = 0xFFFF;
756 bitmap_rates[9] = 0x3FFF;
758 memset(rates, 0, sizeof(rates));
759 mwifiex_get_active_data_rates(priv, rates);
761 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
762 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
763 rate[i], rate_cfg->rate);
764 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
767 if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
768 dev_err(adapter->dev, "fixed data rate %#x is out "
769 "of range\n", rate_cfg->rate);
772 memset(bitmap_rates, 0, sizeof(bitmap_rates));
774 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
776 /* Only allow b/g rates to be set */
777 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
778 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
779 bitmap_rates[0] = 1 << rate_index;
781 rate_index -= 1; /* There is a 0x00 in the table */
782 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
783 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
784 bitmap_rates[1] = 1 << (rate_index -
785 MWIFIEX_RATE_INDEX_OFDM0);
789 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
790 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
796 * IOCTL request handler to set/get rate.
798 * This function can be used to set/get either the rate value or the
801 static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
802 struct mwifiex_rate_cfg *rate_cfg)
809 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
810 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
812 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
818 * Sends IOCTL request to get the data rate.
820 * This function allocates the IOCTL request buffer, fills it
821 * with requisite parameters and calls the IOCTL handler.
823 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
824 struct mwifiex_rate_cfg *rate)
828 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
829 rate->action = HostCmd_ACT_GEN_GET;
830 ret = mwifiex_rate_ioctl_cfg(priv, rate);
833 if (rate->is_rate_auto)
834 rate->rate = mwifiex_index_to_data_rate(priv,
839 rate->rate = priv->data_rate;
848 * IOCTL request handler to set tx power configuration.
850 * This function prepares the correct firmware command and
853 * For non-auto power mode, all the following power groups are set -
854 * - Modulation class HR/DSSS
855 * - Modulation class OFDM
856 * - Modulation class HTBW20
857 * - Modulation class HTBW40
859 int mwifiex_set_tx_power(struct mwifiex_private *priv,
860 struct mwifiex_power_cfg *power_cfg)
863 struct host_cmd_ds_txpwr_cfg *txp_cfg;
864 struct mwifiex_types_power_group *pg_tlv;
865 struct mwifiex_power_group *pg;
869 if (!power_cfg->is_power_auto) {
870 dbm = (u16) power_cfg->power_level;
871 if ((dbm < priv->min_tx_power_level) ||
872 (dbm > priv->max_tx_power_level)) {
873 dev_err(priv->adapter->dev, "txpower value %d dBm"
874 " is out of range (%d dBm-%d dBm)\n",
875 dbm, priv->min_tx_power_level,
876 priv->max_tx_power_level);
880 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
882 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
887 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
888 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
889 if (!power_cfg->is_power_auto) {
890 txp_cfg->mode = cpu_to_le32(1);
891 pg_tlv = (struct mwifiex_types_power_group *)
892 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
893 pg_tlv->type = TLV_TYPE_POWER_GROUP;
894 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
895 pg = (struct mwifiex_power_group *)
896 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
897 + sizeof(struct mwifiex_types_power_group));
898 /* Power group for modulation class HR/DSSS */
899 pg->first_rate_code = 0x00;
900 pg->last_rate_code = 0x03;
901 pg->modulation_class = MOD_CLASS_HR_DSSS;
903 pg->power_min = (s8) dbm;
904 pg->power_max = (s8) dbm;
906 /* Power group for modulation class OFDM */
907 pg->first_rate_code = 0x00;
908 pg->last_rate_code = 0x07;
909 pg->modulation_class = MOD_CLASS_OFDM;
911 pg->power_min = (s8) dbm;
912 pg->power_max = (s8) dbm;
914 /* Power group for modulation class HTBW20 */
915 pg->first_rate_code = 0x00;
916 pg->last_rate_code = 0x20;
917 pg->modulation_class = MOD_CLASS_HT;
919 pg->power_min = (s8) dbm;
920 pg->power_max = (s8) dbm;
921 pg->ht_bandwidth = HT_BW_20;
923 /* Power group for modulation class HTBW40 */
924 pg->first_rate_code = 0x00;
925 pg->last_rate_code = 0x20;
926 pg->modulation_class = MOD_CLASS_HT;
928 pg->power_min = (s8) dbm;
929 pg->power_max = (s8) dbm;
930 pg->ht_bandwidth = HT_BW_40;
932 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
933 HostCmd_ACT_GEN_SET, 0, buf);
940 * IOCTL request handler to get power save mode.
942 * This function prepares the correct firmware command and
945 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
948 struct mwifiex_adapter *adapter = priv->adapter;
952 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
954 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
955 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
956 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
957 sub_cmd, BITMAP_STA_PS, NULL);
958 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
959 ret = mwifiex_send_cmd_async(priv,
960 HostCmd_CMD_802_11_PS_MODE_ENH,
967 * IOCTL request handler to set/reset WPA IE.
969 * The supplied WPA IE is treated as a opaque buffer. Only the first field
970 * is checked to determine WPA version. If buffer length is zero, the existing
973 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
974 u8 *ie_data_ptr, u16 ie_len)
977 if (ie_len > sizeof(priv->wpa_ie)) {
978 dev_err(priv->adapter->dev,
979 "failed to copy WPA IE, too big\n");
982 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
983 priv->wpa_ie_len = (u8) ie_len;
984 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
985 priv->wpa_ie_len, priv->wpa_ie[0]);
987 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
988 priv->sec_info.wpa_enabled = true;
989 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
990 priv->sec_info.wpa2_enabled = true;
992 priv->sec_info.wpa_enabled = false;
993 priv->sec_info.wpa2_enabled = false;
996 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
997 priv->wpa_ie_len = 0;
998 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
999 priv->wpa_ie_len, priv->wpa_ie[0]);
1000 priv->sec_info.wpa_enabled = false;
1001 priv->sec_info.wpa2_enabled = false;
1008 * IOCTL request handler to set/reset WAPI IE.
1010 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
1011 * is checked to internally enable WAPI. If buffer length is zero, the existing
1014 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
1015 u8 *ie_data_ptr, u16 ie_len)
1018 if (ie_len > sizeof(priv->wapi_ie)) {
1019 dev_dbg(priv->adapter->dev,
1020 "info: failed to copy WAPI IE, too big\n");
1023 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
1024 priv->wapi_ie_len = ie_len;
1025 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
1026 priv->wapi_ie_len, priv->wapi_ie[0]);
1028 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
1029 priv->sec_info.wapi_enabled = true;
1031 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
1032 priv->wapi_ie_len = ie_len;
1033 dev_dbg(priv->adapter->dev,
1034 "info: Reset wapi_ie_len=%d IE=%#x\n",
1035 priv->wapi_ie_len, priv->wapi_ie[0]);
1036 priv->sec_info.wapi_enabled = false;
1042 * IOCTL request handler to set/reset WPS IE.
1044 * The supplied WPS IE is treated as a opaque buffer. Only the first field
1045 * is checked to internally enable WPS. If buffer length is zero, the existing
1048 static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
1049 u8 *ie_data_ptr, u16 ie_len)
1052 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
1055 if (ie_len > sizeof(priv->wps_ie)) {
1056 dev_dbg(priv->adapter->dev,
1057 "info: failed to copy WPS IE, too big\n");
1058 kfree(priv->wps_ie);
1061 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
1062 priv->wps_ie_len = ie_len;
1063 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
1064 priv->wps_ie_len, priv->wps_ie[0]);
1066 kfree(priv->wps_ie);
1067 priv->wps_ie_len = ie_len;
1068 dev_dbg(priv->adapter->dev,
1069 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
1075 * IOCTL request handler to set WAPI key.
1077 * This function prepares the correct firmware command and
1080 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
1081 struct mwifiex_ds_encrypt_key *encrypt_key)
1084 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1085 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1090 * IOCTL request handler to set WEP network key.
1092 * This function prepares the correct firmware command and
1093 * issues it, after validation checks.
1095 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
1096 struct mwifiex_ds_encrypt_key *encrypt_key)
1099 struct mwifiex_wep_key *wep_key;
1102 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1103 priv->wep_key_curr_index = 0;
1104 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1105 index = encrypt_key->key_index;
1106 if (encrypt_key->key_disable) {
1107 priv->sec_info.wep_enabled = 0;
1108 } else if (!encrypt_key->key_len) {
1109 /* Copy the required key as the current key */
1110 wep_key = &priv->wep_key[index];
1111 if (!wep_key->key_length) {
1112 dev_err(priv->adapter->dev,
1113 "key not set, so cannot enable it\n");
1116 priv->wep_key_curr_index = (u16) index;
1117 priv->sec_info.wep_enabled = 1;
1119 wep_key = &priv->wep_key[index];
1120 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1121 /* Copy the key in the driver */
1122 memcpy(wep_key->key_material,
1123 encrypt_key->key_material,
1124 encrypt_key->key_len);
1125 wep_key->key_index = index;
1126 wep_key->key_length = encrypt_key->key_len;
1127 priv->sec_info.wep_enabled = 1;
1129 if (wep_key->key_length) {
1130 /* Send request to firmware */
1131 ret = mwifiex_send_cmd_async(priv,
1132 HostCmd_CMD_802_11_KEY_MATERIAL,
1133 HostCmd_ACT_GEN_SET, 0, NULL);
1137 if (priv->sec_info.wep_enabled)
1138 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1140 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1142 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1143 HostCmd_ACT_GEN_SET, 0,
1144 &priv->curr_pkt_filter);
1150 * IOCTL request handler to set WPA key.
1152 * This function prepares the correct firmware command and
1153 * issues it, after validation checks.
1155 * Current driver only supports key length of up to 32 bytes.
1157 * This function can also be used to disable a currently set key.
1159 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
1160 struct mwifiex_ds_encrypt_key *encrypt_key)
1163 u8 remove_key = false;
1164 struct host_cmd_ds_802_11_key_material *ibss_key;
1166 /* Current driver only supports key length of up to 32 bytes */
1167 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
1168 dev_err(priv->adapter->dev, "key length too long\n");
1172 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1174 * IBSS/WPA-None uses only one key (Group) for both receiving
1175 * and sending unicast and multicast packets.
1177 /* Send the key as PTK to firmware */
1178 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1179 ret = mwifiex_send_cmd_async(priv,
1180 HostCmd_CMD_802_11_KEY_MATERIAL,
1181 HostCmd_ACT_GEN_SET,
1182 KEY_INFO_ENABLED, encrypt_key);
1186 ibss_key = &priv->aes_key;
1188 sizeof(struct host_cmd_ds_802_11_key_material));
1189 /* Copy the key in the driver */
1190 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1191 encrypt_key->key_len);
1192 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1193 sizeof(ibss_key->key_param_set.key_len));
1194 ibss_key->key_param_set.key_type_id
1195 = cpu_to_le16(KEY_TYPE_ID_TKIP);
1196 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
1198 /* Send the key as GTK to firmware */
1199 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1202 if (!encrypt_key->key_index)
1203 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1206 ret = mwifiex_send_cmd_sync(priv,
1207 HostCmd_CMD_802_11_KEY_MATERIAL,
1208 HostCmd_ACT_GEN_SET,
1209 !KEY_INFO_ENABLED, encrypt_key);
1211 ret = mwifiex_send_cmd_sync(priv,
1212 HostCmd_CMD_802_11_KEY_MATERIAL,
1213 HostCmd_ACT_GEN_SET,
1214 KEY_INFO_ENABLED, encrypt_key);
1220 * IOCTL request handler to set/get network keys.
1222 * This is a generic key handling function which supports WEP, WPA
1226 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
1227 struct mwifiex_ds_encrypt_key *encrypt_key)
1231 if (encrypt_key->is_wapi_key)
1232 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
1233 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
1234 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
1236 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
1241 * This function returns the driver version.
1244 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1253 ver.l = adapter->fw_release_number;
1254 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1256 snprintf(version, max_len, driver_version, fw_ver);
1258 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1264 * Sends IOCTL request to set encoding parameters.
1266 * This function allocates the IOCTL request buffer, fills it
1267 * with requisite parameters and calls the IOCTL handler.
1269 int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1270 int key_len, u8 key_index, int disable)
1272 struct mwifiex_ds_encrypt_key encrypt_key;
1274 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1275 encrypt_key.key_len = key_len;
1277 encrypt_key.key_index = key_index;
1279 memcpy(encrypt_key.key_material, key, key_len);
1281 encrypt_key.key_disable = true;
1284 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1288 * Sends IOCTL request to get extended version.
1290 * This function allocates the IOCTL request buffer, fills it
1291 * with requisite parameters and calls the IOCTL handler.
1294 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1296 struct mwifiex_ver_ext ver_ext;
1298 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1299 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1300 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1307 * Sends IOCTL request to get statistics information.
1309 * This function allocates the IOCTL request buffer, fills it
1310 * with requisite parameters and calls the IOCTL handler.
1313 mwifiex_get_stats_info(struct mwifiex_private *priv,
1314 struct mwifiex_ds_get_stats *log)
1316 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1317 HostCmd_ACT_GEN_GET, 0, log);
1321 * IOCTL request handler to read/write register.
1323 * This function prepares the correct firmware command and
1326 * Access to the following registers are supported -
1333 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1334 struct mwifiex_ds_reg_rw *reg_rw,
1339 switch (le32_to_cpu(reg_rw->type)) {
1340 case MWIFIEX_REG_MAC:
1341 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1343 case MWIFIEX_REG_BBP:
1344 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1346 case MWIFIEX_REG_RF:
1347 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1349 case MWIFIEX_REG_PMIC:
1350 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1352 case MWIFIEX_REG_CAU:
1353 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1359 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1364 * Sends IOCTL request to write to a register.
1366 * This function allocates the IOCTL request buffer, fills it
1367 * with requisite parameters and calls the IOCTL handler.
1370 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1371 u32 reg_offset, u32 reg_value)
1373 struct mwifiex_ds_reg_rw reg_rw;
1375 reg_rw.type = cpu_to_le32(reg_type);
1376 reg_rw.offset = cpu_to_le32(reg_offset);
1377 reg_rw.value = cpu_to_le32(reg_value);
1379 return mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET);
1383 * Sends IOCTL request to read from a register.
1385 * This function allocates the IOCTL request buffer, fills it
1386 * with requisite parameters and calls the IOCTL handler.
1389 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1390 u32 reg_offset, u32 *value)
1393 struct mwifiex_ds_reg_rw reg_rw;
1395 reg_rw.type = cpu_to_le32(reg_type);
1396 reg_rw.offset = cpu_to_le32(reg_offset);
1397 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET);
1402 *value = le32_to_cpu(reg_rw.value);
1409 * Sends IOCTL request to read from EEPROM.
1411 * This function allocates the IOCTL request buffer, fills it
1412 * with requisite parameters and calls the IOCTL handler.
1415 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1419 struct mwifiex_ds_read_eeprom rd_eeprom;
1421 rd_eeprom.offset = cpu_to_le16((u16) offset);
1422 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1424 /* Send request to firmware */
1425 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1426 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1429 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1434 * This function sets a generic IE. In addition to generic IE, it can
1435 * also handle WPA, WPA2 and WAPI IEs.
1438 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1442 struct ieee_types_vendor_header *pvendor_ie;
1443 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1444 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1446 /* If the passed length is zero, reset the buffer */
1448 priv->gen_ie_buf_len = 0;
1449 priv->wps.session_enable = false;
1452 } else if (!ie_data_ptr) {
1455 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1456 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1457 if (((pvendor_ie->element_id == WLAN_EID_WPA) &&
1458 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1459 (pvendor_ie->element_id == WLAN_EID_RSN)) {
1461 /* IE is a WPA/WPA2 IE so call set_wpa function */
1462 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1463 priv->wps.session_enable = false;
1466 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1467 /* IE is a WAPI IE so call set_wapi function */
1468 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1473 * Verify that the passed length is not larger than the
1474 * available space remaining in the buffer
1476 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1478 /* Test to see if it is a WPS IE, if so, enable
1481 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1482 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1483 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
1484 priv->wps.session_enable = true;
1485 dev_dbg(priv->adapter->dev,
1486 "info: WPS Session Enabled.\n");
1487 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
1490 /* Append the passed data to the end of the
1492 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1494 /* Increment the stored buffer length by the
1496 priv->gen_ie_buf_len += ie_len;
1498 /* Passed data does not fit in the remaining
1503 /* Return 0, or -1 for error case */
1508 * IOCTL request handler to set/get generic IE.
1510 * In addition to various generic IEs, this function can also be
1511 * used to set the ARP filter.
1513 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1514 struct mwifiex_ds_misc_gen_ie *gen_ie,
1517 struct mwifiex_adapter *adapter = priv->adapter;
1519 switch (gen_ie->type) {
1520 case MWIFIEX_IE_TYPE_GEN_IE:
1521 if (action == HostCmd_ACT_GEN_GET) {
1522 gen_ie->len = priv->wpa_ie_len;
1523 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1525 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1529 case MWIFIEX_IE_TYPE_ARP_FILTER:
1530 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1531 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1532 adapter->arp_filter_size = 0;
1533 dev_err(adapter->dev, "invalid ARP filter size\n");
1536 memcpy(adapter->arp_filter, gen_ie->ie_data,
1538 adapter->arp_filter_size = gen_ie->len;
1542 dev_err(adapter->dev, "invalid IE type\n");
1549 * Sends IOCTL request to set a generic IE.
1551 * This function allocates the IOCTL request buffer, fills it
1552 * with requisite parameters and calls the IOCTL handler.
1555 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1557 struct mwifiex_ds_misc_gen_ie gen_ie;
1559 if (ie_len > IEEE_MAX_IE_SIZE)
1562 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1563 gen_ie.len = ie_len;
1564 memcpy(gen_ie.ie_data, ie, ie_len);
1565 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))