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)
59 bool cancel_flag = false;
61 struct cmd_ctrl_node *cmd_queued;
63 if (!adapter->cmd_queued)
66 cmd_queued = adapter->cmd_queued;
67 adapter->cmd_queued = NULL;
69 dev_dbg(adapter->dev, "cmd pending\n");
70 atomic_inc(&adapter->cmd_pending);
72 /* Wait for completion */
73 wait_event_interruptible(adapter->cmd_wait_q.wait,
74 *(cmd_queued->condition));
75 if (!*(cmd_queued->condition))
79 mwifiex_cancel_pending_ioctl(adapter);
80 dev_dbg(adapter->dev, "cmd cancel\n");
83 status = adapter->cmd_wait_q.status;
84 adapter->cmd_wait_q.status = 0;
90 * This function prepares the correct firmware command and
91 * issues it to set the multicast list.
93 * This function can be used to enable promiscuous mode, or enable all
94 * multicast packets, or to enable selective multicast.
96 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
97 struct mwifiex_multicast_list *mcast_list)
102 old_pkt_filter = priv->curr_pkt_filter;
104 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
105 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
106 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
107 priv->curr_pkt_filter &=
108 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
111 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
112 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
113 dev_dbg(priv->adapter->dev,
114 "info: Enabling All Multicast!\n");
115 priv->curr_pkt_filter |=
116 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
118 priv->curr_pkt_filter &=
119 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
120 if (mcast_list->num_multicast_addr) {
121 dev_dbg(priv->adapter->dev,
122 "info: Set multicast list=%d\n",
123 mcast_list->num_multicast_addr);
124 /* Set multicast addresses to firmware */
125 if (old_pkt_filter == priv->curr_pkt_filter) {
126 /* Send request to firmware */
127 ret = mwifiex_send_cmd_async(priv,
128 HostCmd_CMD_MAC_MULTICAST_ADR,
129 HostCmd_ACT_GEN_SET, 0,
132 /* Send request to firmware */
133 ret = mwifiex_send_cmd_async(priv,
134 HostCmd_CMD_MAC_MULTICAST_ADR,
135 HostCmd_ACT_GEN_SET, 0,
141 dev_dbg(priv->adapter->dev,
142 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
143 old_pkt_filter, priv->curr_pkt_filter);
144 if (old_pkt_filter != priv->curr_pkt_filter) {
145 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
147 0, &priv->curr_pkt_filter);
154 * This function fills bss descriptor structure using provided
157 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
158 struct cfg80211_bss *bss,
159 struct mwifiex_bssdescriptor *bss_desc)
161 int ret, beacon_ie_len;
163 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
164 const struct cfg80211_bss_ies *ies;
167 ies = rcu_dereference(bss->ies);
169 /* should never happen */
173 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
174 beacon_ie_len = ies->len;
178 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
182 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
183 bss_desc->rssi = bss->signal;
184 bss_desc->beacon_buf = beacon_ie;
185 bss_desc->beacon_buf_size = beacon_ie_len;
186 bss_desc->beacon_period = bss->beacon_interval;
187 bss_desc->cap_info_bitmap = bss->capability;
188 bss_desc->bss_band = bss_priv->band;
189 bss_desc->fw_tsf = bss_priv->fw_tsf;
190 bss_desc->timestamp = bss->tsf;
191 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
192 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
193 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
195 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
197 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
198 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
200 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
202 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
208 static int mwifiex_process_country_ie(struct mwifiex_private *priv,
209 struct cfg80211_bss *bss)
211 const u8 *country_ie;
213 struct mwifiex_802_11d_domain_reg *domain_info =
214 &priv->adapter->domain_reg;
217 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
223 country_ie_len = country_ie[1];
224 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
229 domain_info->country_code[0] = country_ie[2];
230 domain_info->country_code[1] = country_ie[3];
231 domain_info->country_code[2] = ' ';
233 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
235 domain_info->no_of_triplet =
236 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
238 memcpy((u8 *)domain_info->triplet,
239 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
243 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
244 HostCmd_ACT_GEN_SET, 0, NULL)) {
245 wiphy_err(priv->adapter->wiphy,
246 "11D: setting domain info in FW\n");
254 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
255 * In both Ad-Hoc and infra mode, an deauthentication is performed
258 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
259 struct cfg80211_ssid *req_ssid)
262 struct mwifiex_adapter *adapter = priv->adapter;
263 struct mwifiex_bssdescriptor *bss_desc = NULL;
265 priv->scan_block = false;
268 mwifiex_process_country_ie(priv, bss);
270 /* Allocate and fill new bss descriptor */
271 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
274 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
278 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
283 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
285 ret = mwifiex_deauthenticate(priv, NULL);
289 ret = mwifiex_check_network_compatibility(priv, bss_desc);
293 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
296 if (!netif_queue_stopped(priv->netdev))
297 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
298 if (netif_carrier_ok(priv->netdev))
299 netif_carrier_off(priv->netdev);
301 /* Clear any past association response stored for
302 * application retrieval */
303 priv->assoc_rsp_size = 0;
304 ret = mwifiex_associate(priv, bss_desc);
306 /* If auth type is auto and association fails using open mode,
307 * try to connect using shared mode */
308 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
309 priv->sec_info.is_authtype_auto &&
310 priv->sec_info.wep_enabled) {
311 priv->sec_info.authentication_mode =
312 NL80211_AUTHTYPE_SHARED_KEY;
313 ret = mwifiex_associate(priv, bss_desc);
317 cfg80211_put_bss(bss);
320 /* If the requested SSID matches current SSID, return */
321 if (bss_desc && bss_desc->ssid.ssid_len &&
322 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
323 ssid, &bss_desc->ssid))) {
328 /* Exit Adhoc mode first */
329 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
330 ret = mwifiex_deauthenticate(priv, NULL);
334 priv->adhoc_is_link_sensed = false;
336 ret = mwifiex_check_network_compatibility(priv, bss_desc);
338 if (!netif_queue_stopped(priv->netdev))
339 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
340 if (netif_carrier_ok(priv->netdev))
341 netif_carrier_off(priv->netdev);
344 dev_dbg(adapter->dev, "info: network found in scan"
345 " list. Joining...\n");
346 ret = mwifiex_adhoc_join(priv, bss_desc);
348 cfg80211_put_bss(bss);
350 dev_dbg(adapter->dev, "info: Network not found in "
351 "the list, creating adhoc with ssid = %s\n",
353 ret = mwifiex_adhoc_start(priv, req_ssid);
363 * IOCTL request handler to set host sleep configuration.
365 * This function prepares the correct firmware command and
368 static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
369 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
372 struct mwifiex_adapter *adapter = priv->adapter;
380 case HostCmd_ACT_GEN_SET:
381 if (adapter->pps_uapsd_mode) {
382 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
383 " is blocked in UAPSD/PPS mode\n");
387 if (hs_cfg->is_invoke_hostcmd) {
388 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
389 if (!adapter->is_hs_configured)
390 /* Already cancelled */
392 /* Save previous condition */
393 prev_cond = le32_to_cpu(adapter->hs_cfg
395 adapter->hs_cfg.conditions =
396 cpu_to_le32(hs_cfg->conditions);
397 } else if (hs_cfg->conditions) {
398 adapter->hs_cfg.conditions =
399 cpu_to_le32(hs_cfg->conditions);
400 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
402 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
403 } else if (adapter->hs_cfg.conditions
404 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
405 /* Return failure if no parameters for HS
410 if (cmd_type == MWIFIEX_SYNC_CMD)
411 status = mwifiex_send_cmd_sync(priv,
412 HostCmd_CMD_802_11_HS_CFG_ENH,
413 HostCmd_ACT_GEN_SET, 0,
416 status = mwifiex_send_cmd_async(priv,
417 HostCmd_CMD_802_11_HS_CFG_ENH,
418 HostCmd_ACT_GEN_SET, 0,
420 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
421 /* Restore previous condition */
422 adapter->hs_cfg.conditions =
423 cpu_to_le32(prev_cond);
425 adapter->hs_cfg.conditions =
426 cpu_to_le32(hs_cfg->conditions);
427 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
428 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
431 case HostCmd_ACT_GEN_GET:
432 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
433 hs_cfg->gpio = adapter->hs_cfg.gpio;
434 hs_cfg->gap = adapter->hs_cfg.gap;
445 * Sends IOCTL request to cancel the existing Host Sleep configuration.
447 * This function allocates the IOCTL request buffer, fills it
448 * with requisite parameters and calls the IOCTL handler.
450 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
452 struct mwifiex_ds_hs_cfg hscfg;
454 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
455 hscfg.is_invoke_hostcmd = true;
457 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
460 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
463 * Sends IOCTL request to cancel the existing Host Sleep configuration.
465 * This function allocates the IOCTL request buffer, fills it
466 * with requisite parameters and calls the IOCTL handler.
468 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
470 struct mwifiex_ds_hs_cfg hscfg;
471 struct mwifiex_private *priv;
474 if (disconnect_on_suspend) {
475 for (i = 0; i < adapter->priv_num; i++) {
476 priv = adapter->priv[i];
478 mwifiex_deauthenticate(priv, NULL);
482 if (adapter->hs_activated) {
483 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
487 adapter->hs_activate_wait_q_woken = false;
489 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
490 hscfg.is_invoke_hostcmd = true;
492 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
493 MWIFIEX_BSS_ROLE_STA),
494 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
496 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
500 wait_event_interruptible(adapter->hs_activate_wait_q,
501 adapter->hs_activate_wait_q_woken);
505 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
508 * IOCTL request handler to get BSS information.
510 * This function collates the information from different driver structures
511 * to send to the user.
513 int mwifiex_get_bss_info(struct mwifiex_private *priv,
514 struct mwifiex_bss_info *info)
516 struct mwifiex_adapter *adapter = priv->adapter;
517 struct mwifiex_bssdescriptor *bss_desc;
522 bss_desc = &priv->curr_bss_params.bss_descriptor;
524 info->bss_mode = priv->bss_mode;
526 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
528 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
530 info->bss_chan = bss_desc->channel;
532 memcpy(info->country_code, adapter->country_code,
533 IEEE80211_COUNTRY_STRING_LEN);
535 info->media_connected = priv->media_connected;
537 info->max_power_level = priv->max_tx_power_level;
538 info->min_power_level = priv->min_tx_power_level;
540 info->adhoc_state = priv->adhoc_state;
542 info->bcn_nf_last = priv->bcn_nf_last;
544 if (priv->sec_info.wep_enabled)
545 info->wep_status = true;
547 info->wep_status = false;
549 info->is_hs_configured = adapter->is_hs_configured;
550 info->is_deep_sleep = adapter->is_deep_sleep;
556 * The function disables auto deep sleep mode.
558 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
560 struct mwifiex_ds_auto_ds auto_ds;
562 auto_ds.auto_ds = DEEP_SLEEP_OFF;
564 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
565 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
567 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
570 * Sends IOCTL request to get the data rate.
572 * This function allocates the IOCTL request buffer, fills it
573 * with requisite parameters and calls the IOCTL handler.
575 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
579 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
580 HostCmd_ACT_GEN_GET, 0, NULL);
583 if (priv->is_data_rate_auto)
584 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
587 *rate = priv->data_rate;
594 * IOCTL request handler to set tx power configuration.
596 * This function prepares the correct firmware command and
599 * For non-auto power mode, all the following power groups are set -
600 * - Modulation class HR/DSSS
601 * - Modulation class OFDM
602 * - Modulation class HTBW20
603 * - Modulation class HTBW40
605 int mwifiex_set_tx_power(struct mwifiex_private *priv,
606 struct mwifiex_power_cfg *power_cfg)
609 struct host_cmd_ds_txpwr_cfg *txp_cfg;
610 struct mwifiex_types_power_group *pg_tlv;
611 struct mwifiex_power_group *pg;
615 if (!power_cfg->is_power_auto) {
616 dbm = (u16) power_cfg->power_level;
617 if ((dbm < priv->min_tx_power_level) ||
618 (dbm > priv->max_tx_power_level)) {
619 dev_err(priv->adapter->dev, "txpower value %d dBm"
620 " is out of range (%d dBm-%d dBm)\n",
621 dbm, priv->min_tx_power_level,
622 priv->max_tx_power_level);
626 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
628 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
633 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
634 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
635 if (!power_cfg->is_power_auto) {
636 txp_cfg->mode = cpu_to_le32(1);
637 pg_tlv = (struct mwifiex_types_power_group *)
638 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
639 pg_tlv->type = TLV_TYPE_POWER_GROUP;
640 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
641 pg = (struct mwifiex_power_group *)
642 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
643 + sizeof(struct mwifiex_types_power_group));
644 /* Power group for modulation class HR/DSSS */
645 pg->first_rate_code = 0x00;
646 pg->last_rate_code = 0x03;
647 pg->modulation_class = MOD_CLASS_HR_DSSS;
649 pg->power_min = (s8) dbm;
650 pg->power_max = (s8) dbm;
652 /* Power group for modulation class OFDM */
653 pg->first_rate_code = 0x00;
654 pg->last_rate_code = 0x07;
655 pg->modulation_class = MOD_CLASS_OFDM;
657 pg->power_min = (s8) dbm;
658 pg->power_max = (s8) dbm;
660 /* Power group for modulation class HTBW20 */
661 pg->first_rate_code = 0x00;
662 pg->last_rate_code = 0x20;
663 pg->modulation_class = MOD_CLASS_HT;
665 pg->power_min = (s8) dbm;
666 pg->power_max = (s8) dbm;
667 pg->ht_bandwidth = HT_BW_20;
669 /* Power group for modulation class HTBW40 */
670 pg->first_rate_code = 0x00;
671 pg->last_rate_code = 0x20;
672 pg->modulation_class = MOD_CLASS_HT;
674 pg->power_min = (s8) dbm;
675 pg->power_max = (s8) dbm;
676 pg->ht_bandwidth = HT_BW_40;
678 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
679 HostCmd_ACT_GEN_SET, 0, buf);
686 * IOCTL request handler to get power save mode.
688 * This function prepares the correct firmware command and
691 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
694 struct mwifiex_adapter *adapter = priv->adapter;
698 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
700 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
701 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
702 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
703 sub_cmd, BITMAP_STA_PS, NULL);
704 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
705 ret = mwifiex_send_cmd_async(priv,
706 HostCmd_CMD_802_11_PS_MODE_ENH,
713 * IOCTL request handler to set/reset WPA IE.
715 * The supplied WPA IE is treated as a opaque buffer. Only the first field
716 * is checked to determine WPA version. If buffer length is zero, the existing
719 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
720 u8 *ie_data_ptr, u16 ie_len)
723 if (ie_len > sizeof(priv->wpa_ie)) {
724 dev_err(priv->adapter->dev,
725 "failed to copy WPA IE, too big\n");
728 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
729 priv->wpa_ie_len = (u8) ie_len;
730 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
731 priv->wpa_ie_len, priv->wpa_ie[0]);
733 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
734 priv->sec_info.wpa_enabled = true;
735 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
736 priv->sec_info.wpa2_enabled = true;
738 priv->sec_info.wpa_enabled = false;
739 priv->sec_info.wpa2_enabled = false;
742 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
743 priv->wpa_ie_len = 0;
744 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
745 priv->wpa_ie_len, priv->wpa_ie[0]);
746 priv->sec_info.wpa_enabled = false;
747 priv->sec_info.wpa2_enabled = false;
754 * IOCTL request handler to set/reset WAPI IE.
756 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
757 * is checked to internally enable WAPI. If buffer length is zero, the existing
760 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
761 u8 *ie_data_ptr, u16 ie_len)
764 if (ie_len > sizeof(priv->wapi_ie)) {
765 dev_dbg(priv->adapter->dev,
766 "info: failed to copy WAPI IE, too big\n");
769 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
770 priv->wapi_ie_len = ie_len;
771 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
772 priv->wapi_ie_len, priv->wapi_ie[0]);
774 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
775 priv->sec_info.wapi_enabled = true;
777 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
778 priv->wapi_ie_len = ie_len;
779 dev_dbg(priv->adapter->dev,
780 "info: Reset wapi_ie_len=%d IE=%#x\n",
781 priv->wapi_ie_len, priv->wapi_ie[0]);
782 priv->sec_info.wapi_enabled = false;
788 * IOCTL request handler to set/reset WPS IE.
790 * The supplied WPS IE is treated as a opaque buffer. Only the first field
791 * is checked to internally enable WPS. If buffer length is zero, the existing
794 static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
795 u8 *ie_data_ptr, u16 ie_len)
798 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
801 if (ie_len > sizeof(priv->wps_ie)) {
802 dev_dbg(priv->adapter->dev,
803 "info: failed to copy WPS IE, too big\n");
807 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
808 priv->wps_ie_len = ie_len;
809 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
810 priv->wps_ie_len, priv->wps_ie[0]);
813 priv->wps_ie_len = ie_len;
814 dev_dbg(priv->adapter->dev,
815 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
821 * IOCTL request handler to set WAPI key.
823 * This function prepares the correct firmware command and
826 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
827 struct mwifiex_ds_encrypt_key *encrypt_key)
830 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
831 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
836 * IOCTL request handler to set WEP network key.
838 * This function prepares the correct firmware command and
839 * issues it, after validation checks.
841 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
842 struct mwifiex_ds_encrypt_key *encrypt_key)
845 struct mwifiex_wep_key *wep_key;
848 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
849 priv->wep_key_curr_index = 0;
850 wep_key = &priv->wep_key[priv->wep_key_curr_index];
851 index = encrypt_key->key_index;
852 if (encrypt_key->key_disable) {
853 priv->sec_info.wep_enabled = 0;
854 } else if (!encrypt_key->key_len) {
855 /* Copy the required key as the current key */
856 wep_key = &priv->wep_key[index];
857 if (!wep_key->key_length) {
858 dev_err(priv->adapter->dev,
859 "key not set, so cannot enable it\n");
862 priv->wep_key_curr_index = (u16) index;
863 priv->sec_info.wep_enabled = 1;
865 wep_key = &priv->wep_key[index];
866 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
867 /* Copy the key in the driver */
868 memcpy(wep_key->key_material,
869 encrypt_key->key_material,
870 encrypt_key->key_len);
871 wep_key->key_index = index;
872 wep_key->key_length = encrypt_key->key_len;
873 priv->sec_info.wep_enabled = 1;
875 if (wep_key->key_length) {
876 /* Send request to firmware */
877 ret = mwifiex_send_cmd_async(priv,
878 HostCmd_CMD_802_11_KEY_MATERIAL,
879 HostCmd_ACT_GEN_SET, 0, NULL);
883 if (priv->sec_info.wep_enabled)
884 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
886 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
888 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
889 HostCmd_ACT_GEN_SET, 0,
890 &priv->curr_pkt_filter);
896 * IOCTL request handler to set WPA key.
898 * This function prepares the correct firmware command and
899 * issues it, after validation checks.
901 * Current driver only supports key length of up to 32 bytes.
903 * This function can also be used to disable a currently set key.
905 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
906 struct mwifiex_ds_encrypt_key *encrypt_key)
909 u8 remove_key = false;
910 struct host_cmd_ds_802_11_key_material *ibss_key;
912 /* Current driver only supports key length of up to 32 bytes */
913 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
914 dev_err(priv->adapter->dev, "key length too long\n");
918 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
920 * IBSS/WPA-None uses only one key (Group) for both receiving
921 * and sending unicast and multicast packets.
923 /* Send the key as PTK to firmware */
924 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
925 ret = mwifiex_send_cmd_async(priv,
926 HostCmd_CMD_802_11_KEY_MATERIAL,
928 KEY_INFO_ENABLED, encrypt_key);
932 ibss_key = &priv->aes_key;
934 sizeof(struct host_cmd_ds_802_11_key_material));
935 /* Copy the key in the driver */
936 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
937 encrypt_key->key_len);
938 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
939 sizeof(ibss_key->key_param_set.key_len));
940 ibss_key->key_param_set.key_type_id
941 = cpu_to_le16(KEY_TYPE_ID_TKIP);
942 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
944 /* Send the key as GTK to firmware */
945 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
948 if (!encrypt_key->key_index)
949 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
952 ret = mwifiex_send_cmd_sync(priv,
953 HostCmd_CMD_802_11_KEY_MATERIAL,
955 !KEY_INFO_ENABLED, encrypt_key);
957 ret = mwifiex_send_cmd_sync(priv,
958 HostCmd_CMD_802_11_KEY_MATERIAL,
960 KEY_INFO_ENABLED, encrypt_key);
966 * IOCTL request handler to set/get network keys.
968 * This is a generic key handling function which supports WEP, WPA
972 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
973 struct mwifiex_ds_encrypt_key *encrypt_key)
977 if (encrypt_key->is_wapi_key)
978 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
979 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
980 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
982 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
987 * This function returns the driver version.
990 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
999 ver.l = adapter->fw_release_number;
1000 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1002 snprintf(version, max_len, driver_version, fw_ver);
1004 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1010 * Sends IOCTL request to set encoding parameters.
1012 * This function allocates the IOCTL request buffer, fills it
1013 * with requisite parameters and calls the IOCTL handler.
1015 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1016 const u8 *key, int key_len, u8 key_index,
1017 const u8 *mac_addr, int disable)
1019 struct mwifiex_ds_encrypt_key encrypt_key;
1021 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1022 encrypt_key.key_len = key_len;
1024 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1025 encrypt_key.is_igtk_key = true;
1028 encrypt_key.key_index = key_index;
1030 memcpy(encrypt_key.key_material, key, key_len);
1032 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1033 if (kp && kp->seq && kp->seq_len)
1034 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
1036 encrypt_key.key_disable = true;
1038 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1041 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1045 * Sends IOCTL request to get extended version.
1047 * This function allocates the IOCTL request buffer, fills it
1048 * with requisite parameters and calls the IOCTL handler.
1051 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1053 struct mwifiex_ver_ext ver_ext;
1055 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1056 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1057 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1064 mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1065 struct ieee80211_channel *chan,
1066 unsigned int duration)
1068 struct host_cmd_ds_remain_on_chan roc_cfg;
1071 memset(&roc_cfg, 0, sizeof(roc_cfg));
1072 roc_cfg.action = cpu_to_le16(action);
1073 if (action == HostCmd_ACT_GEN_SET) {
1074 roc_cfg.band_cfg = chan->band;
1075 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
1076 roc_cfg.band_cfg |= (sc << 2);
1079 ieee80211_frequency_to_channel(chan->center_freq);
1080 roc_cfg.duration = cpu_to_le32(duration);
1082 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1083 action, 0, &roc_cfg)) {
1084 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1088 return roc_cfg.status;
1092 mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1094 if (GET_BSS_ROLE(priv) == bss_role) {
1095 dev_dbg(priv->adapter->dev,
1096 "info: already in the desired role.\n");
1100 mwifiex_free_priv(priv);
1101 mwifiex_init_priv(priv);
1103 priv->bss_role = bss_role;
1105 case MWIFIEX_BSS_ROLE_UAP:
1106 priv->bss_mode = NL80211_IFTYPE_AP;
1108 case MWIFIEX_BSS_ROLE_STA:
1109 case MWIFIEX_BSS_ROLE_ANY:
1111 priv->bss_mode = NL80211_IFTYPE_STATION;
1115 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1116 HostCmd_ACT_GEN_SET, 0, NULL);
1118 return mwifiex_sta_init_cmd(priv, false);
1122 * Sends IOCTL request to get statistics information.
1124 * This function allocates the IOCTL request buffer, fills it
1125 * with requisite parameters and calls the IOCTL handler.
1128 mwifiex_get_stats_info(struct mwifiex_private *priv,
1129 struct mwifiex_ds_get_stats *log)
1131 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1132 HostCmd_ACT_GEN_GET, 0, log);
1136 * IOCTL request handler to read/write register.
1138 * This function prepares the correct firmware command and
1141 * Access to the following registers are supported -
1148 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1149 struct mwifiex_ds_reg_rw *reg_rw,
1154 switch (le32_to_cpu(reg_rw->type)) {
1155 case MWIFIEX_REG_MAC:
1156 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1158 case MWIFIEX_REG_BBP:
1159 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1161 case MWIFIEX_REG_RF:
1162 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1164 case MWIFIEX_REG_PMIC:
1165 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1167 case MWIFIEX_REG_CAU:
1168 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1174 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1179 * Sends IOCTL request to write to a register.
1181 * This function allocates the IOCTL request buffer, fills it
1182 * with requisite parameters and calls the IOCTL handler.
1185 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1186 u32 reg_offset, u32 reg_value)
1188 struct mwifiex_ds_reg_rw reg_rw;
1190 reg_rw.type = cpu_to_le32(reg_type);
1191 reg_rw.offset = cpu_to_le32(reg_offset);
1192 reg_rw.value = cpu_to_le32(reg_value);
1194 return mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET);
1198 * Sends IOCTL request to read from a register.
1200 * This function allocates the IOCTL request buffer, fills it
1201 * with requisite parameters and calls the IOCTL handler.
1204 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1205 u32 reg_offset, u32 *value)
1208 struct mwifiex_ds_reg_rw reg_rw;
1210 reg_rw.type = cpu_to_le32(reg_type);
1211 reg_rw.offset = cpu_to_le32(reg_offset);
1212 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET);
1217 *value = le32_to_cpu(reg_rw.value);
1224 * Sends IOCTL request to read from EEPROM.
1226 * This function allocates the IOCTL request buffer, fills it
1227 * with requisite parameters and calls the IOCTL handler.
1230 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1234 struct mwifiex_ds_read_eeprom rd_eeprom;
1236 rd_eeprom.offset = cpu_to_le16((u16) offset);
1237 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1239 /* Send request to firmware */
1240 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1241 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1244 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1249 * This function sets a generic IE. In addition to generic IE, it can
1250 * also handle WPA, WPA2 and WAPI IEs.
1253 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1257 struct ieee_types_vendor_header *pvendor_ie;
1258 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1259 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1261 /* If the passed length is zero, reset the buffer */
1263 priv->gen_ie_buf_len = 0;
1264 priv->wps.session_enable = false;
1267 } else if (!ie_data_ptr) {
1270 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1271 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1272 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1273 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1274 (pvendor_ie->element_id == WLAN_EID_RSN)) {
1276 /* IE is a WPA/WPA2 IE so call set_wpa function */
1277 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1278 priv->wps.session_enable = false;
1281 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1282 /* IE is a WAPI IE so call set_wapi function */
1283 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1288 * Verify that the passed length is not larger than the
1289 * available space remaining in the buffer
1291 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1293 /* Test to see if it is a WPS IE, if so, enable
1296 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1297 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1298 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
1299 priv->wps.session_enable = true;
1300 dev_dbg(priv->adapter->dev,
1301 "info: WPS Session Enabled.\n");
1302 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
1305 /* Append the passed data to the end of the
1307 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1309 /* Increment the stored buffer length by the
1311 priv->gen_ie_buf_len += ie_len;
1313 /* Passed data does not fit in the remaining
1318 /* Return 0, or -1 for error case */
1323 * IOCTL request handler to set/get generic IE.
1325 * In addition to various generic IEs, this function can also be
1326 * used to set the ARP filter.
1328 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1329 struct mwifiex_ds_misc_gen_ie *gen_ie,
1332 struct mwifiex_adapter *adapter = priv->adapter;
1334 switch (gen_ie->type) {
1335 case MWIFIEX_IE_TYPE_GEN_IE:
1336 if (action == HostCmd_ACT_GEN_GET) {
1337 gen_ie->len = priv->wpa_ie_len;
1338 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1340 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1344 case MWIFIEX_IE_TYPE_ARP_FILTER:
1345 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1346 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1347 adapter->arp_filter_size = 0;
1348 dev_err(adapter->dev, "invalid ARP filter size\n");
1351 memcpy(adapter->arp_filter, gen_ie->ie_data,
1353 adapter->arp_filter_size = gen_ie->len;
1357 dev_err(adapter->dev, "invalid IE type\n");
1364 * Sends IOCTL request to set a generic IE.
1366 * This function allocates the IOCTL request buffer, fills it
1367 * with requisite parameters and calls the IOCTL handler.
1370 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1372 struct mwifiex_ds_misc_gen_ie gen_ie;
1374 if (ie_len > IEEE_MAX_IE_SIZE)
1377 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1378 gen_ie.len = ie_len;
1379 memcpy(gen_ie.ie_data, ie, ie_len);
1380 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))