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)
159 size_t beacon_ie_len;
160 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
161 const struct cfg80211_bss_ies *ies;
164 ies = rcu_dereference(bss->ies);
165 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
166 beacon_ie_len = ies->len;
167 bss_desc->timestamp = ies->tsf;
171 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
175 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
176 bss_desc->rssi = bss->signal;
177 bss_desc->beacon_buf = beacon_ie;
178 bss_desc->beacon_buf_size = beacon_ie_len;
179 bss_desc->beacon_period = bss->beacon_interval;
180 bss_desc->cap_info_bitmap = bss->capability;
181 bss_desc->bss_band = bss_priv->band;
182 bss_desc->fw_tsf = bss_priv->fw_tsf;
183 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
184 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
185 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
187 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
189 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
190 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
192 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
194 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
200 static int mwifiex_process_country_ie(struct mwifiex_private *priv,
201 struct cfg80211_bss *bss)
203 const u8 *country_ie;
205 struct mwifiex_802_11d_domain_reg *domain_info =
206 &priv->adapter->domain_reg;
209 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
215 country_ie_len = country_ie[1];
216 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
221 domain_info->country_code[0] = country_ie[2];
222 domain_info->country_code[1] = country_ie[3];
223 domain_info->country_code[2] = ' ';
225 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
227 domain_info->no_of_triplet =
228 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
230 memcpy((u8 *)domain_info->triplet,
231 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
235 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
236 HostCmd_ACT_GEN_SET, 0, NULL)) {
237 wiphy_err(priv->adapter->wiphy,
238 "11D: setting domain info in FW\n");
246 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
247 * In both Ad-Hoc and infra mode, an deauthentication is performed
250 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
251 struct cfg80211_ssid *req_ssid)
254 struct mwifiex_adapter *adapter = priv->adapter;
255 struct mwifiex_bssdescriptor *bss_desc = NULL;
257 priv->scan_block = false;
260 mwifiex_process_country_ie(priv, bss);
262 /* Allocate and fill new bss descriptor */
263 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
268 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
273 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
275 ret = mwifiex_deauthenticate(priv, NULL);
282 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
283 == HostCmd_SCAN_RADIO_TYPE_BG)
284 config_bands = BAND_B | BAND_G | BAND_GN |
287 config_bands = BAND_A | BAND_AN | BAND_AAC;
289 if (!((config_bands | adapter->fw_bands) &
291 adapter->config_bands = config_bands;
294 ret = mwifiex_check_network_compatibility(priv, bss_desc);
298 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
301 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
302 if (netif_carrier_ok(priv->netdev))
303 netif_carrier_off(priv->netdev);
305 /* Clear any past association response stored for
306 * application retrieval */
307 priv->assoc_rsp_size = 0;
308 ret = mwifiex_associate(priv, bss_desc);
310 /* If auth type is auto and association fails using open mode,
311 * try to connect using shared mode */
312 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
313 priv->sec_info.is_authtype_auto &&
314 priv->sec_info.wep_enabled) {
315 priv->sec_info.authentication_mode =
316 NL80211_AUTHTYPE_SHARED_KEY;
317 ret = mwifiex_associate(priv, bss_desc);
321 cfg80211_put_bss(priv->adapter->wiphy, bss);
324 /* If the requested SSID matches current SSID, return */
325 if (bss_desc && bss_desc->ssid.ssid_len &&
326 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
327 ssid, &bss_desc->ssid))) {
332 /* Exit Adhoc mode first */
333 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
334 ret = mwifiex_deauthenticate(priv, NULL);
338 priv->adhoc_is_link_sensed = false;
340 ret = mwifiex_check_network_compatibility(priv, bss_desc);
342 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
343 if (netif_carrier_ok(priv->netdev))
344 netif_carrier_off(priv->netdev);
347 dev_dbg(adapter->dev, "info: network found in scan"
348 " list. Joining...\n");
349 ret = mwifiex_adhoc_join(priv, bss_desc);
351 cfg80211_put_bss(priv->adapter->wiphy, bss);
353 dev_dbg(adapter->dev, "info: Network not found in "
354 "the list, creating adhoc with ssid = %s\n",
356 ret = mwifiex_adhoc_start(priv, req_ssid);
366 * IOCTL request handler to set host sleep configuration.
368 * This function prepares the correct firmware command and
371 static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
372 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
375 struct mwifiex_adapter *adapter = priv->adapter;
383 case HostCmd_ACT_GEN_SET:
384 if (adapter->pps_uapsd_mode) {
385 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
386 " is blocked in UAPSD/PPS mode\n");
390 if (hs_cfg->is_invoke_hostcmd) {
391 if (hs_cfg->conditions == HS_CFG_CANCEL) {
392 if (!adapter->is_hs_configured)
393 /* Already cancelled */
395 /* Save previous condition */
396 prev_cond = le32_to_cpu(adapter->hs_cfg
398 adapter->hs_cfg.conditions =
399 cpu_to_le32(hs_cfg->conditions);
400 } else if (hs_cfg->conditions) {
401 adapter->hs_cfg.conditions =
402 cpu_to_le32(hs_cfg->conditions);
403 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
405 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
406 } else if (adapter->hs_cfg.conditions ==
407 cpu_to_le32(HS_CFG_CANCEL)) {
408 /* Return failure if no parameters for HS
413 if (cmd_type == MWIFIEX_SYNC_CMD)
414 status = mwifiex_send_cmd_sync(priv,
415 HostCmd_CMD_802_11_HS_CFG_ENH,
416 HostCmd_ACT_GEN_SET, 0,
419 status = mwifiex_send_cmd_async(priv,
420 HostCmd_CMD_802_11_HS_CFG_ENH,
421 HostCmd_ACT_GEN_SET, 0,
423 if (hs_cfg->conditions == HS_CFG_CANCEL)
424 /* Restore previous condition */
425 adapter->hs_cfg.conditions =
426 cpu_to_le32(prev_cond);
428 adapter->hs_cfg.conditions =
429 cpu_to_le32(hs_cfg->conditions);
430 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
431 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
434 case HostCmd_ACT_GEN_GET:
435 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
436 hs_cfg->gpio = adapter->hs_cfg.gpio;
437 hs_cfg->gap = adapter->hs_cfg.gap;
448 * Sends IOCTL request to cancel the existing Host Sleep configuration.
450 * This function allocates the IOCTL request buffer, fills it
451 * with requisite parameters and calls the IOCTL handler.
453 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
455 struct mwifiex_ds_hs_cfg hscfg;
457 hscfg.conditions = HS_CFG_CANCEL;
458 hscfg.is_invoke_hostcmd = true;
460 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
463 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
466 * Sends IOCTL request to cancel the existing Host Sleep configuration.
468 * This function allocates the IOCTL request buffer, fills it
469 * with requisite parameters and calls the IOCTL handler.
471 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
473 struct mwifiex_ds_hs_cfg hscfg;
474 struct mwifiex_private *priv;
477 if (disconnect_on_suspend) {
478 for (i = 0; i < adapter->priv_num; i++) {
479 priv = adapter->priv[i];
481 mwifiex_deauthenticate(priv, NULL);
485 if (adapter->hs_activated) {
486 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
490 adapter->hs_activate_wait_q_woken = false;
492 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
493 hscfg.is_invoke_hostcmd = true;
495 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
496 MWIFIEX_BSS_ROLE_STA),
497 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
499 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
503 if (wait_event_interruptible(adapter->hs_activate_wait_q,
504 adapter->hs_activate_wait_q_woken)) {
505 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
511 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
514 * IOCTL request handler to get BSS information.
516 * This function collates the information from different driver structures
517 * to send to the user.
519 int mwifiex_get_bss_info(struct mwifiex_private *priv,
520 struct mwifiex_bss_info *info)
522 struct mwifiex_adapter *adapter = priv->adapter;
523 struct mwifiex_bssdescriptor *bss_desc;
528 bss_desc = &priv->curr_bss_params.bss_descriptor;
530 info->bss_mode = priv->bss_mode;
532 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
534 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
536 info->bss_chan = bss_desc->channel;
538 memcpy(info->country_code, adapter->country_code,
539 IEEE80211_COUNTRY_STRING_LEN);
541 info->media_connected = priv->media_connected;
543 info->max_power_level = priv->max_tx_power_level;
544 info->min_power_level = priv->min_tx_power_level;
546 info->adhoc_state = priv->adhoc_state;
548 info->bcn_nf_last = priv->bcn_nf_last;
550 if (priv->sec_info.wep_enabled)
551 info->wep_status = true;
553 info->wep_status = false;
555 info->is_hs_configured = adapter->is_hs_configured;
556 info->is_deep_sleep = adapter->is_deep_sleep;
562 * The function disables auto deep sleep mode.
564 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
566 struct mwifiex_ds_auto_ds auto_ds;
568 auto_ds.auto_ds = DEEP_SLEEP_OFF;
570 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
571 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
573 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
576 * Sends IOCTL request to get the data rate.
578 * This function allocates the IOCTL request buffer, fills it
579 * with requisite parameters and calls the IOCTL handler.
581 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
585 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
586 HostCmd_ACT_GEN_GET, 0, NULL);
589 if (priv->is_data_rate_auto)
590 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
593 *rate = priv->data_rate;
600 * IOCTL request handler to set tx power configuration.
602 * This function prepares the correct firmware command and
605 * For non-auto power mode, all the following power groups are set -
606 * - Modulation class HR/DSSS
607 * - Modulation class OFDM
608 * - Modulation class HTBW20
609 * - Modulation class HTBW40
611 int mwifiex_set_tx_power(struct mwifiex_private *priv,
612 struct mwifiex_power_cfg *power_cfg)
615 struct host_cmd_ds_txpwr_cfg *txp_cfg;
616 struct mwifiex_types_power_group *pg_tlv;
617 struct mwifiex_power_group *pg;
621 if (!power_cfg->is_power_auto) {
622 dbm = (u16) power_cfg->power_level;
623 if ((dbm < priv->min_tx_power_level) ||
624 (dbm > priv->max_tx_power_level)) {
625 dev_err(priv->adapter->dev, "txpower value %d dBm"
626 " is out of range (%d dBm-%d dBm)\n",
627 dbm, priv->min_tx_power_level,
628 priv->max_tx_power_level);
632 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
636 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
637 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
638 if (!power_cfg->is_power_auto) {
639 txp_cfg->mode = cpu_to_le32(1);
640 pg_tlv = (struct mwifiex_types_power_group *)
641 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
642 pg_tlv->type = TLV_TYPE_POWER_GROUP;
643 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
644 pg = (struct mwifiex_power_group *)
645 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
646 + sizeof(struct mwifiex_types_power_group));
647 /* Power group for modulation class HR/DSSS */
648 pg->first_rate_code = 0x00;
649 pg->last_rate_code = 0x03;
650 pg->modulation_class = MOD_CLASS_HR_DSSS;
652 pg->power_min = (s8) dbm;
653 pg->power_max = (s8) dbm;
655 /* Power group for modulation class OFDM */
656 pg->first_rate_code = 0x00;
657 pg->last_rate_code = 0x07;
658 pg->modulation_class = MOD_CLASS_OFDM;
660 pg->power_min = (s8) dbm;
661 pg->power_max = (s8) dbm;
663 /* Power group for modulation class HTBW20 */
664 pg->first_rate_code = 0x00;
665 pg->last_rate_code = 0x20;
666 pg->modulation_class = MOD_CLASS_HT;
668 pg->power_min = (s8) dbm;
669 pg->power_max = (s8) dbm;
670 pg->ht_bandwidth = HT_BW_20;
672 /* Power group for modulation class HTBW40 */
673 pg->first_rate_code = 0x00;
674 pg->last_rate_code = 0x20;
675 pg->modulation_class = MOD_CLASS_HT;
677 pg->power_min = (s8) dbm;
678 pg->power_max = (s8) dbm;
679 pg->ht_bandwidth = HT_BW_40;
681 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
682 HostCmd_ACT_GEN_SET, 0, buf);
689 * IOCTL request handler to get power save mode.
691 * This function prepares the correct firmware command and
694 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
697 struct mwifiex_adapter *adapter = priv->adapter;
701 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
703 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
704 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
705 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
706 sub_cmd, BITMAP_STA_PS, NULL);
707 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
708 ret = mwifiex_send_cmd_async(priv,
709 HostCmd_CMD_802_11_PS_MODE_ENH,
716 * IOCTL request handler to set/reset WPA IE.
718 * The supplied WPA IE is treated as a opaque buffer. Only the first field
719 * is checked to determine WPA version. If buffer length is zero, the existing
722 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
723 u8 *ie_data_ptr, u16 ie_len)
726 if (ie_len > sizeof(priv->wpa_ie)) {
727 dev_err(priv->adapter->dev,
728 "failed to copy WPA IE, too big\n");
731 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
732 priv->wpa_ie_len = (u8) ie_len;
733 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
734 priv->wpa_ie_len, priv->wpa_ie[0]);
736 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
737 priv->sec_info.wpa_enabled = true;
738 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
739 priv->sec_info.wpa2_enabled = true;
741 priv->sec_info.wpa_enabled = false;
742 priv->sec_info.wpa2_enabled = false;
745 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
746 priv->wpa_ie_len = 0;
747 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
748 priv->wpa_ie_len, priv->wpa_ie[0]);
749 priv->sec_info.wpa_enabled = false;
750 priv->sec_info.wpa2_enabled = false;
757 * IOCTL request handler to set/reset WAPI IE.
759 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
760 * is checked to internally enable WAPI. If buffer length is zero, the existing
763 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
764 u8 *ie_data_ptr, u16 ie_len)
767 if (ie_len > sizeof(priv->wapi_ie)) {
768 dev_dbg(priv->adapter->dev,
769 "info: failed to copy WAPI IE, too big\n");
772 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
773 priv->wapi_ie_len = ie_len;
774 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
775 priv->wapi_ie_len, priv->wapi_ie[0]);
777 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
778 priv->sec_info.wapi_enabled = true;
780 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
781 priv->wapi_ie_len = ie_len;
782 dev_dbg(priv->adapter->dev,
783 "info: Reset wapi_ie_len=%d IE=%#x\n",
784 priv->wapi_ie_len, priv->wapi_ie[0]);
785 priv->sec_info.wapi_enabled = false;
791 * IOCTL request handler to set/reset WPS IE.
793 * The supplied WPS IE is treated as a opaque buffer. Only the first field
794 * is checked to internally enable WPS. If buffer length is zero, the existing
797 static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
798 u8 *ie_data_ptr, u16 ie_len)
801 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
804 if (ie_len > sizeof(priv->wps_ie)) {
805 dev_dbg(priv->adapter->dev,
806 "info: failed to copy WPS IE, too big\n");
810 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
811 priv->wps_ie_len = ie_len;
812 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
813 priv->wps_ie_len, priv->wps_ie[0]);
816 priv->wps_ie_len = ie_len;
817 dev_dbg(priv->adapter->dev,
818 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
824 * IOCTL request handler to set WAPI key.
826 * This function prepares the correct firmware command and
829 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
830 struct mwifiex_ds_encrypt_key *encrypt_key)
833 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
834 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
839 * IOCTL request handler to set WEP network key.
841 * This function prepares the correct firmware command and
842 * issues it, after validation checks.
844 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
845 struct mwifiex_ds_encrypt_key *encrypt_key)
848 struct mwifiex_wep_key *wep_key;
851 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
852 priv->wep_key_curr_index = 0;
853 wep_key = &priv->wep_key[priv->wep_key_curr_index];
854 index = encrypt_key->key_index;
855 if (encrypt_key->key_disable) {
856 priv->sec_info.wep_enabled = 0;
857 } else if (!encrypt_key->key_len) {
858 /* Copy the required key as the current key */
859 wep_key = &priv->wep_key[index];
860 if (!wep_key->key_length) {
861 dev_err(priv->adapter->dev,
862 "key not set, so cannot enable it\n");
865 priv->wep_key_curr_index = (u16) index;
866 priv->sec_info.wep_enabled = 1;
868 wep_key = &priv->wep_key[index];
869 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
870 /* Copy the key in the driver */
871 memcpy(wep_key->key_material,
872 encrypt_key->key_material,
873 encrypt_key->key_len);
874 wep_key->key_index = index;
875 wep_key->key_length = encrypt_key->key_len;
876 priv->sec_info.wep_enabled = 1;
878 if (wep_key->key_length) {
879 /* Send request to firmware */
880 ret = mwifiex_send_cmd_async(priv,
881 HostCmd_CMD_802_11_KEY_MATERIAL,
882 HostCmd_ACT_GEN_SET, 0, NULL);
886 if (priv->sec_info.wep_enabled)
887 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
889 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
891 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
892 HostCmd_ACT_GEN_SET, 0,
893 &priv->curr_pkt_filter);
899 * IOCTL request handler to set WPA key.
901 * This function prepares the correct firmware command and
902 * issues it, after validation checks.
904 * Current driver only supports key length of up to 32 bytes.
906 * This function can also be used to disable a currently set key.
908 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
909 struct mwifiex_ds_encrypt_key *encrypt_key)
912 u8 remove_key = false;
913 struct host_cmd_ds_802_11_key_material *ibss_key;
915 /* Current driver only supports key length of up to 32 bytes */
916 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
917 dev_err(priv->adapter->dev, "key length too long\n");
921 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
923 * IBSS/WPA-None uses only one key (Group) for both receiving
924 * and sending unicast and multicast packets.
926 /* Send the key as PTK to firmware */
927 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
928 ret = mwifiex_send_cmd_async(priv,
929 HostCmd_CMD_802_11_KEY_MATERIAL,
931 KEY_INFO_ENABLED, encrypt_key);
935 ibss_key = &priv->aes_key;
937 sizeof(struct host_cmd_ds_802_11_key_material));
938 /* Copy the key in the driver */
939 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
940 encrypt_key->key_len);
941 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
942 sizeof(ibss_key->key_param_set.key_len));
943 ibss_key->key_param_set.key_type_id
944 = cpu_to_le16(KEY_TYPE_ID_TKIP);
945 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
947 /* Send the key as GTK to firmware */
948 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
951 if (!encrypt_key->key_index)
952 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
955 ret = mwifiex_send_cmd_sync(priv,
956 HostCmd_CMD_802_11_KEY_MATERIAL,
958 !KEY_INFO_ENABLED, encrypt_key);
960 ret = mwifiex_send_cmd_sync(priv,
961 HostCmd_CMD_802_11_KEY_MATERIAL,
963 KEY_INFO_ENABLED, encrypt_key);
969 * IOCTL request handler to set/get network keys.
971 * This is a generic key handling function which supports WEP, WPA
975 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
976 struct mwifiex_ds_encrypt_key *encrypt_key)
980 if (encrypt_key->is_wapi_key)
981 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
982 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
983 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
985 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
990 * This function returns the driver version.
993 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1002 ver.l = adapter->fw_release_number;
1003 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1005 snprintf(version, max_len, driver_version, fw_ver);
1007 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1013 * Sends IOCTL request to set encoding parameters.
1015 * This function allocates the IOCTL request buffer, fills it
1016 * with requisite parameters and calls the IOCTL handler.
1018 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1019 const u8 *key, int key_len, u8 key_index,
1020 const u8 *mac_addr, int disable)
1022 struct mwifiex_ds_encrypt_key encrypt_key;
1024 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1025 encrypt_key.key_len = key_len;
1027 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1028 encrypt_key.is_igtk_key = true;
1031 encrypt_key.key_index = key_index;
1033 memcpy(encrypt_key.key_material, key, key_len);
1035 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1036 if (kp && kp->seq && kp->seq_len)
1037 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
1039 encrypt_key.key_disable = true;
1041 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1044 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1048 * Sends IOCTL request to get extended version.
1050 * This function allocates the IOCTL request buffer, fills it
1051 * with requisite parameters and calls the IOCTL handler.
1054 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1056 struct mwifiex_ver_ext ver_ext;
1058 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1059 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1060 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1067 mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1068 struct ieee80211_channel *chan,
1069 unsigned int duration)
1071 struct host_cmd_ds_remain_on_chan roc_cfg;
1074 memset(&roc_cfg, 0, sizeof(roc_cfg));
1075 roc_cfg.action = cpu_to_le16(action);
1076 if (action == HostCmd_ACT_GEN_SET) {
1077 roc_cfg.band_cfg = chan->band;
1078 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
1079 roc_cfg.band_cfg |= (sc << 2);
1082 ieee80211_frequency_to_channel(chan->center_freq);
1083 roc_cfg.duration = cpu_to_le32(duration);
1085 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1086 action, 0, &roc_cfg)) {
1087 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1091 return roc_cfg.status;
1095 mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1097 if (GET_BSS_ROLE(priv) == bss_role) {
1098 dev_dbg(priv->adapter->dev,
1099 "info: already in the desired role.\n");
1103 mwifiex_free_priv(priv);
1104 mwifiex_init_priv(priv);
1106 priv->bss_role = bss_role;
1108 case MWIFIEX_BSS_ROLE_UAP:
1109 priv->bss_mode = NL80211_IFTYPE_AP;
1111 case MWIFIEX_BSS_ROLE_STA:
1112 case MWIFIEX_BSS_ROLE_ANY:
1114 priv->bss_mode = NL80211_IFTYPE_STATION;
1118 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1119 HostCmd_ACT_GEN_SET, 0, NULL);
1121 return mwifiex_sta_init_cmd(priv, false);
1125 * Sends IOCTL request to get statistics information.
1127 * This function allocates the IOCTL request buffer, fills it
1128 * with requisite parameters and calls the IOCTL handler.
1131 mwifiex_get_stats_info(struct mwifiex_private *priv,
1132 struct mwifiex_ds_get_stats *log)
1134 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1135 HostCmd_ACT_GEN_GET, 0, log);
1139 * IOCTL request handler to read/write register.
1141 * This function prepares the correct firmware command and
1144 * Access to the following registers are supported -
1151 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1152 struct mwifiex_ds_reg_rw *reg_rw,
1157 switch (le32_to_cpu(reg_rw->type)) {
1158 case MWIFIEX_REG_MAC:
1159 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1161 case MWIFIEX_REG_BBP:
1162 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1164 case MWIFIEX_REG_RF:
1165 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1167 case MWIFIEX_REG_PMIC:
1168 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1170 case MWIFIEX_REG_CAU:
1171 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1177 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1182 * Sends IOCTL request to write to a register.
1184 * This function allocates the IOCTL request buffer, fills it
1185 * with requisite parameters and calls the IOCTL handler.
1188 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1189 u32 reg_offset, u32 reg_value)
1191 struct mwifiex_ds_reg_rw reg_rw;
1193 reg_rw.type = cpu_to_le32(reg_type);
1194 reg_rw.offset = cpu_to_le32(reg_offset);
1195 reg_rw.value = cpu_to_le32(reg_value);
1197 return mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET);
1201 * Sends IOCTL request to read from a register.
1203 * This function allocates the IOCTL request buffer, fills it
1204 * with requisite parameters and calls the IOCTL handler.
1207 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1208 u32 reg_offset, u32 *value)
1211 struct mwifiex_ds_reg_rw reg_rw;
1213 reg_rw.type = cpu_to_le32(reg_type);
1214 reg_rw.offset = cpu_to_le32(reg_offset);
1215 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET);
1220 *value = le32_to_cpu(reg_rw.value);
1227 * Sends IOCTL request to read from EEPROM.
1229 * This function allocates the IOCTL request buffer, fills it
1230 * with requisite parameters and calls the IOCTL handler.
1233 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1237 struct mwifiex_ds_read_eeprom rd_eeprom;
1239 rd_eeprom.offset = cpu_to_le16((u16) offset);
1240 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1242 /* Send request to firmware */
1243 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1244 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1247 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1252 * This function sets a generic IE. In addition to generic IE, it can
1253 * also handle WPA, WPA2 and WAPI IEs.
1256 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1260 struct ieee_types_vendor_header *pvendor_ie;
1261 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1262 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1264 /* If the passed length is zero, reset the buffer */
1266 priv->gen_ie_buf_len = 0;
1267 priv->wps.session_enable = false;
1270 } else if (!ie_data_ptr) {
1273 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1274 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1275 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1276 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1277 (pvendor_ie->element_id == WLAN_EID_RSN)) {
1279 /* IE is a WPA/WPA2 IE so call set_wpa function */
1280 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1281 priv->wps.session_enable = false;
1284 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1285 /* IE is a WAPI IE so call set_wapi function */
1286 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1291 * Verify that the passed length is not larger than the
1292 * available space remaining in the buffer
1294 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1296 /* Test to see if it is a WPS IE, if so, enable
1299 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1300 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1301 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
1302 priv->wps.session_enable = true;
1303 dev_dbg(priv->adapter->dev,
1304 "info: WPS Session Enabled.\n");
1305 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
1308 /* Append the passed data to the end of the
1310 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1312 /* Increment the stored buffer length by the
1314 priv->gen_ie_buf_len += ie_len;
1316 /* Passed data does not fit in the remaining
1321 /* Return 0, or -1 for error case */
1326 * IOCTL request handler to set/get generic IE.
1328 * In addition to various generic IEs, this function can also be
1329 * used to set the ARP filter.
1331 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1332 struct mwifiex_ds_misc_gen_ie *gen_ie,
1335 struct mwifiex_adapter *adapter = priv->adapter;
1337 switch (gen_ie->type) {
1338 case MWIFIEX_IE_TYPE_GEN_IE:
1339 if (action == HostCmd_ACT_GEN_GET) {
1340 gen_ie->len = priv->wpa_ie_len;
1341 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1343 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1347 case MWIFIEX_IE_TYPE_ARP_FILTER:
1348 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1349 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1350 adapter->arp_filter_size = 0;
1351 dev_err(adapter->dev, "invalid ARP filter size\n");
1354 memcpy(adapter->arp_filter, gen_ie->ie_data,
1356 adapter->arp_filter_size = gen_ie->len;
1360 dev_err(adapter->dev, "invalid IE type\n");
1367 * Sends IOCTL request to set a generic IE.
1369 * This function allocates the IOCTL request buffer, fills it
1370 * with requisite parameters and calls the IOCTL handler.
1373 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1375 struct mwifiex_ds_misc_gen_ie gen_ie;
1377 if (ie_len > IEEE_MAX_IE_SIZE)
1380 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1381 gen_ie.len = ie_len;
1382 memcpy(gen_ie.ie_data, ie, ie_len);
1383 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))