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)
163 size_t beacon_ie_len;
164 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
165 const struct cfg80211_bss_ies *ies;
168 ies = rcu_dereference(bss->ies);
170 /* should never happen */
174 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
175 beacon_ie_len = ies->len;
179 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
183 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
184 bss_desc->rssi = bss->signal;
185 bss_desc->beacon_buf = beacon_ie;
186 bss_desc->beacon_buf_size = beacon_ie_len;
187 bss_desc->beacon_period = bss->beacon_interval;
188 bss_desc->cap_info_bitmap = bss->capability;
189 bss_desc->bss_band = bss_priv->band;
190 bss_desc->fw_tsf = bss_priv->fw_tsf;
191 bss_desc->timestamp = bss->tsf;
192 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
193 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
194 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
196 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
198 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
199 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
201 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
203 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
209 static int mwifiex_process_country_ie(struct mwifiex_private *priv,
210 struct cfg80211_bss *bss)
212 const u8 *country_ie;
214 struct mwifiex_802_11d_domain_reg *domain_info =
215 &priv->adapter->domain_reg;
218 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
224 country_ie_len = country_ie[1];
225 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
230 domain_info->country_code[0] = country_ie[2];
231 domain_info->country_code[1] = country_ie[3];
232 domain_info->country_code[2] = ' ';
234 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
236 domain_info->no_of_triplet =
237 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
239 memcpy((u8 *)domain_info->triplet,
240 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
244 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
245 HostCmd_ACT_GEN_SET, 0, NULL)) {
246 wiphy_err(priv->adapter->wiphy,
247 "11D: setting domain info in FW\n");
255 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
256 * In both Ad-Hoc and infra mode, an deauthentication is performed
259 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
260 struct cfg80211_ssid *req_ssid)
263 struct mwifiex_adapter *adapter = priv->adapter;
264 struct mwifiex_bssdescriptor *bss_desc = NULL;
266 priv->scan_block = false;
269 mwifiex_process_country_ie(priv, bss);
271 /* Allocate and fill new bss descriptor */
272 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
275 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
279 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
284 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
286 ret = mwifiex_deauthenticate(priv, NULL);
290 ret = mwifiex_check_network_compatibility(priv, bss_desc);
294 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
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 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
339 if (netif_carrier_ok(priv->netdev))
340 netif_carrier_off(priv->netdev);
343 dev_dbg(adapter->dev, "info: network found in scan"
344 " list. Joining...\n");
345 ret = mwifiex_adhoc_join(priv, bss_desc);
347 cfg80211_put_bss(bss);
349 dev_dbg(adapter->dev, "info: Network not found in "
350 "the list, creating adhoc with ssid = %s\n",
352 ret = mwifiex_adhoc_start(priv, req_ssid);
362 * IOCTL request handler to set host sleep configuration.
364 * This function prepares the correct firmware command and
367 static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
368 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
371 struct mwifiex_adapter *adapter = priv->adapter;
379 case HostCmd_ACT_GEN_SET:
380 if (adapter->pps_uapsd_mode) {
381 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
382 " is blocked in UAPSD/PPS mode\n");
386 if (hs_cfg->is_invoke_hostcmd) {
387 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
388 if (!adapter->is_hs_configured)
389 /* Already cancelled */
391 /* Save previous condition */
392 prev_cond = le32_to_cpu(adapter->hs_cfg
394 adapter->hs_cfg.conditions =
395 cpu_to_le32(hs_cfg->conditions);
396 } else if (hs_cfg->conditions) {
397 adapter->hs_cfg.conditions =
398 cpu_to_le32(hs_cfg->conditions);
399 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
401 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
402 } else if (adapter->hs_cfg.conditions
403 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
404 /* Return failure if no parameters for HS
409 if (cmd_type == MWIFIEX_SYNC_CMD)
410 status = mwifiex_send_cmd_sync(priv,
411 HostCmd_CMD_802_11_HS_CFG_ENH,
412 HostCmd_ACT_GEN_SET, 0,
415 status = mwifiex_send_cmd_async(priv,
416 HostCmd_CMD_802_11_HS_CFG_ENH,
417 HostCmd_ACT_GEN_SET, 0,
419 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
420 /* Restore previous condition */
421 adapter->hs_cfg.conditions =
422 cpu_to_le32(prev_cond);
424 adapter->hs_cfg.conditions =
425 cpu_to_le32(hs_cfg->conditions);
426 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
427 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
430 case HostCmd_ACT_GEN_GET:
431 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
432 hs_cfg->gpio = adapter->hs_cfg.gpio;
433 hs_cfg->gap = adapter->hs_cfg.gap;
444 * Sends IOCTL request to cancel the existing Host Sleep configuration.
446 * This function allocates the IOCTL request buffer, fills it
447 * with requisite parameters and calls the IOCTL handler.
449 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
451 struct mwifiex_ds_hs_cfg hscfg;
453 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
454 hscfg.is_invoke_hostcmd = true;
456 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
459 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
462 * Sends IOCTL request to cancel the existing Host Sleep configuration.
464 * This function allocates the IOCTL request buffer, fills it
465 * with requisite parameters and calls the IOCTL handler.
467 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
469 struct mwifiex_ds_hs_cfg hscfg;
470 struct mwifiex_private *priv;
473 if (disconnect_on_suspend) {
474 for (i = 0; i < adapter->priv_num; i++) {
475 priv = adapter->priv[i];
477 mwifiex_deauthenticate(priv, NULL);
481 if (adapter->hs_activated) {
482 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
486 adapter->hs_activate_wait_q_woken = false;
488 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
489 hscfg.is_invoke_hostcmd = true;
491 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
492 MWIFIEX_BSS_ROLE_STA),
493 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
495 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
499 wait_event_interruptible(adapter->hs_activate_wait_q,
500 adapter->hs_activate_wait_q_woken);
504 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
507 * IOCTL request handler to get BSS information.
509 * This function collates the information from different driver structures
510 * to send to the user.
512 int mwifiex_get_bss_info(struct mwifiex_private *priv,
513 struct mwifiex_bss_info *info)
515 struct mwifiex_adapter *adapter = priv->adapter;
516 struct mwifiex_bssdescriptor *bss_desc;
521 bss_desc = &priv->curr_bss_params.bss_descriptor;
523 info->bss_mode = priv->bss_mode;
525 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
527 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
529 info->bss_chan = bss_desc->channel;
531 memcpy(info->country_code, adapter->country_code,
532 IEEE80211_COUNTRY_STRING_LEN);
534 info->media_connected = priv->media_connected;
536 info->max_power_level = priv->max_tx_power_level;
537 info->min_power_level = priv->min_tx_power_level;
539 info->adhoc_state = priv->adhoc_state;
541 info->bcn_nf_last = priv->bcn_nf_last;
543 if (priv->sec_info.wep_enabled)
544 info->wep_status = true;
546 info->wep_status = false;
548 info->is_hs_configured = adapter->is_hs_configured;
549 info->is_deep_sleep = adapter->is_deep_sleep;
555 * The function disables auto deep sleep mode.
557 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
559 struct mwifiex_ds_auto_ds auto_ds;
561 auto_ds.auto_ds = DEEP_SLEEP_OFF;
563 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
564 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
566 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
569 * Sends IOCTL request to get the data rate.
571 * This function allocates the IOCTL request buffer, fills it
572 * with requisite parameters and calls the IOCTL handler.
574 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
578 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
579 HostCmd_ACT_GEN_GET, 0, NULL);
582 if (priv->is_data_rate_auto)
583 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
586 *rate = priv->data_rate;
593 * IOCTL request handler to set tx power configuration.
595 * This function prepares the correct firmware command and
598 * For non-auto power mode, all the following power groups are set -
599 * - Modulation class HR/DSSS
600 * - Modulation class OFDM
601 * - Modulation class HTBW20
602 * - Modulation class HTBW40
604 int mwifiex_set_tx_power(struct mwifiex_private *priv,
605 struct mwifiex_power_cfg *power_cfg)
608 struct host_cmd_ds_txpwr_cfg *txp_cfg;
609 struct mwifiex_types_power_group *pg_tlv;
610 struct mwifiex_power_group *pg;
614 if (!power_cfg->is_power_auto) {
615 dbm = (u16) power_cfg->power_level;
616 if ((dbm < priv->min_tx_power_level) ||
617 (dbm > priv->max_tx_power_level)) {
618 dev_err(priv->adapter->dev, "txpower value %d dBm"
619 " is out of range (%d dBm-%d dBm)\n",
620 dbm, priv->min_tx_power_level,
621 priv->max_tx_power_level);
625 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
627 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
632 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
633 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
634 if (!power_cfg->is_power_auto) {
635 txp_cfg->mode = cpu_to_le32(1);
636 pg_tlv = (struct mwifiex_types_power_group *)
637 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
638 pg_tlv->type = TLV_TYPE_POWER_GROUP;
639 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
640 pg = (struct mwifiex_power_group *)
641 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
642 + sizeof(struct mwifiex_types_power_group));
643 /* Power group for modulation class HR/DSSS */
644 pg->first_rate_code = 0x00;
645 pg->last_rate_code = 0x03;
646 pg->modulation_class = MOD_CLASS_HR_DSSS;
648 pg->power_min = (s8) dbm;
649 pg->power_max = (s8) dbm;
651 /* Power group for modulation class OFDM */
652 pg->first_rate_code = 0x00;
653 pg->last_rate_code = 0x07;
654 pg->modulation_class = MOD_CLASS_OFDM;
656 pg->power_min = (s8) dbm;
657 pg->power_max = (s8) dbm;
659 /* Power group for modulation class HTBW20 */
660 pg->first_rate_code = 0x00;
661 pg->last_rate_code = 0x20;
662 pg->modulation_class = MOD_CLASS_HT;
664 pg->power_min = (s8) dbm;
665 pg->power_max = (s8) dbm;
666 pg->ht_bandwidth = HT_BW_20;
668 /* Power group for modulation class HTBW40 */
669 pg->first_rate_code = 0x00;
670 pg->last_rate_code = 0x20;
671 pg->modulation_class = MOD_CLASS_HT;
673 pg->power_min = (s8) dbm;
674 pg->power_max = (s8) dbm;
675 pg->ht_bandwidth = HT_BW_40;
677 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
678 HostCmd_ACT_GEN_SET, 0, buf);
685 * IOCTL request handler to get power save mode.
687 * This function prepares the correct firmware command and
690 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
693 struct mwifiex_adapter *adapter = priv->adapter;
697 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
699 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
700 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
701 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
702 sub_cmd, BITMAP_STA_PS, NULL);
703 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
704 ret = mwifiex_send_cmd_async(priv,
705 HostCmd_CMD_802_11_PS_MODE_ENH,
712 * IOCTL request handler to set/reset WPA IE.
714 * The supplied WPA IE is treated as a opaque buffer. Only the first field
715 * is checked to determine WPA version. If buffer length is zero, the existing
718 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
719 u8 *ie_data_ptr, u16 ie_len)
722 if (ie_len > sizeof(priv->wpa_ie)) {
723 dev_err(priv->adapter->dev,
724 "failed to copy WPA IE, too big\n");
727 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
728 priv->wpa_ie_len = (u8) ie_len;
729 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
730 priv->wpa_ie_len, priv->wpa_ie[0]);
732 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
733 priv->sec_info.wpa_enabled = true;
734 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
735 priv->sec_info.wpa2_enabled = true;
737 priv->sec_info.wpa_enabled = false;
738 priv->sec_info.wpa2_enabled = false;
741 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
742 priv->wpa_ie_len = 0;
743 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
744 priv->wpa_ie_len, priv->wpa_ie[0]);
745 priv->sec_info.wpa_enabled = false;
746 priv->sec_info.wpa2_enabled = false;
753 * IOCTL request handler to set/reset WAPI IE.
755 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
756 * is checked to internally enable WAPI. If buffer length is zero, the existing
759 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
760 u8 *ie_data_ptr, u16 ie_len)
763 if (ie_len > sizeof(priv->wapi_ie)) {
764 dev_dbg(priv->adapter->dev,
765 "info: failed to copy WAPI IE, too big\n");
768 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
769 priv->wapi_ie_len = ie_len;
770 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
771 priv->wapi_ie_len, priv->wapi_ie[0]);
773 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
774 priv->sec_info.wapi_enabled = true;
776 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
777 priv->wapi_ie_len = ie_len;
778 dev_dbg(priv->adapter->dev,
779 "info: Reset wapi_ie_len=%d IE=%#x\n",
780 priv->wapi_ie_len, priv->wapi_ie[0]);
781 priv->sec_info.wapi_enabled = false;
787 * IOCTL request handler to set/reset WPS IE.
789 * The supplied WPS IE is treated as a opaque buffer. Only the first field
790 * is checked to internally enable WPS. If buffer length is zero, the existing
793 static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
794 u8 *ie_data_ptr, u16 ie_len)
797 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
800 if (ie_len > sizeof(priv->wps_ie)) {
801 dev_dbg(priv->adapter->dev,
802 "info: failed to copy WPS IE, too big\n");
806 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
807 priv->wps_ie_len = ie_len;
808 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
809 priv->wps_ie_len, priv->wps_ie[0]);
812 priv->wps_ie_len = ie_len;
813 dev_dbg(priv->adapter->dev,
814 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
820 * IOCTL request handler to set WAPI key.
822 * This function prepares the correct firmware command and
825 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
826 struct mwifiex_ds_encrypt_key *encrypt_key)
829 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
830 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
835 * IOCTL request handler to set WEP network key.
837 * This function prepares the correct firmware command and
838 * issues it, after validation checks.
840 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
841 struct mwifiex_ds_encrypt_key *encrypt_key)
844 struct mwifiex_wep_key *wep_key;
847 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
848 priv->wep_key_curr_index = 0;
849 wep_key = &priv->wep_key[priv->wep_key_curr_index];
850 index = encrypt_key->key_index;
851 if (encrypt_key->key_disable) {
852 priv->sec_info.wep_enabled = 0;
853 } else if (!encrypt_key->key_len) {
854 /* Copy the required key as the current key */
855 wep_key = &priv->wep_key[index];
856 if (!wep_key->key_length) {
857 dev_err(priv->adapter->dev,
858 "key not set, so cannot enable it\n");
861 priv->wep_key_curr_index = (u16) index;
862 priv->sec_info.wep_enabled = 1;
864 wep_key = &priv->wep_key[index];
865 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
866 /* Copy the key in the driver */
867 memcpy(wep_key->key_material,
868 encrypt_key->key_material,
869 encrypt_key->key_len);
870 wep_key->key_index = index;
871 wep_key->key_length = encrypt_key->key_len;
872 priv->sec_info.wep_enabled = 1;
874 if (wep_key->key_length) {
875 /* Send request to firmware */
876 ret = mwifiex_send_cmd_async(priv,
877 HostCmd_CMD_802_11_KEY_MATERIAL,
878 HostCmd_ACT_GEN_SET, 0, NULL);
882 if (priv->sec_info.wep_enabled)
883 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
885 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
887 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
888 HostCmd_ACT_GEN_SET, 0,
889 &priv->curr_pkt_filter);
895 * IOCTL request handler to set WPA key.
897 * This function prepares the correct firmware command and
898 * issues it, after validation checks.
900 * Current driver only supports key length of up to 32 bytes.
902 * This function can also be used to disable a currently set key.
904 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
905 struct mwifiex_ds_encrypt_key *encrypt_key)
908 u8 remove_key = false;
909 struct host_cmd_ds_802_11_key_material *ibss_key;
911 /* Current driver only supports key length of up to 32 bytes */
912 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
913 dev_err(priv->adapter->dev, "key length too long\n");
917 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
919 * IBSS/WPA-None uses only one key (Group) for both receiving
920 * and sending unicast and multicast packets.
922 /* Send the key as PTK to firmware */
923 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
924 ret = mwifiex_send_cmd_async(priv,
925 HostCmd_CMD_802_11_KEY_MATERIAL,
927 KEY_INFO_ENABLED, encrypt_key);
931 ibss_key = &priv->aes_key;
933 sizeof(struct host_cmd_ds_802_11_key_material));
934 /* Copy the key in the driver */
935 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
936 encrypt_key->key_len);
937 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
938 sizeof(ibss_key->key_param_set.key_len));
939 ibss_key->key_param_set.key_type_id
940 = cpu_to_le16(KEY_TYPE_ID_TKIP);
941 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
943 /* Send the key as GTK to firmware */
944 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
947 if (!encrypt_key->key_index)
948 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
951 ret = mwifiex_send_cmd_sync(priv,
952 HostCmd_CMD_802_11_KEY_MATERIAL,
954 !KEY_INFO_ENABLED, encrypt_key);
956 ret = mwifiex_send_cmd_sync(priv,
957 HostCmd_CMD_802_11_KEY_MATERIAL,
959 KEY_INFO_ENABLED, encrypt_key);
965 * IOCTL request handler to set/get network keys.
967 * This is a generic key handling function which supports WEP, WPA
971 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
972 struct mwifiex_ds_encrypt_key *encrypt_key)
976 if (encrypt_key->is_wapi_key)
977 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
978 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
979 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
981 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
986 * This function returns the driver version.
989 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
998 ver.l = adapter->fw_release_number;
999 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1001 snprintf(version, max_len, driver_version, fw_ver);
1003 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1009 * Sends IOCTL request to set encoding parameters.
1011 * This function allocates the IOCTL request buffer, fills it
1012 * with requisite parameters and calls the IOCTL handler.
1014 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1015 const u8 *key, int key_len, u8 key_index,
1016 const u8 *mac_addr, int disable)
1018 struct mwifiex_ds_encrypt_key encrypt_key;
1020 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1021 encrypt_key.key_len = key_len;
1023 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1024 encrypt_key.is_igtk_key = true;
1027 encrypt_key.key_index = key_index;
1029 memcpy(encrypt_key.key_material, key, key_len);
1031 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1032 if (kp && kp->seq && kp->seq_len)
1033 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
1035 encrypt_key.key_disable = true;
1037 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1040 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1044 * Sends IOCTL request to get extended version.
1046 * This function allocates the IOCTL request buffer, fills it
1047 * with requisite parameters and calls the IOCTL handler.
1050 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1052 struct mwifiex_ver_ext ver_ext;
1054 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1055 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1056 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1063 mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1064 struct ieee80211_channel *chan,
1065 unsigned int duration)
1067 struct host_cmd_ds_remain_on_chan roc_cfg;
1070 memset(&roc_cfg, 0, sizeof(roc_cfg));
1071 roc_cfg.action = cpu_to_le16(action);
1072 if (action == HostCmd_ACT_GEN_SET) {
1073 roc_cfg.band_cfg = chan->band;
1074 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
1075 roc_cfg.band_cfg |= (sc << 2);
1078 ieee80211_frequency_to_channel(chan->center_freq);
1079 roc_cfg.duration = cpu_to_le32(duration);
1081 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1082 action, 0, &roc_cfg)) {
1083 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1087 return roc_cfg.status;
1091 mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1093 if (GET_BSS_ROLE(priv) == bss_role) {
1094 dev_dbg(priv->adapter->dev,
1095 "info: already in the desired role.\n");
1099 mwifiex_free_priv(priv);
1100 mwifiex_init_priv(priv);
1102 priv->bss_role = bss_role;
1104 case MWIFIEX_BSS_ROLE_UAP:
1105 priv->bss_mode = NL80211_IFTYPE_AP;
1107 case MWIFIEX_BSS_ROLE_STA:
1108 case MWIFIEX_BSS_ROLE_ANY:
1110 priv->bss_mode = NL80211_IFTYPE_STATION;
1114 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1115 HostCmd_ACT_GEN_SET, 0, NULL);
1117 return mwifiex_sta_init_cmd(priv, false);
1121 * Sends IOCTL request to get statistics information.
1123 * This function allocates the IOCTL request buffer, fills it
1124 * with requisite parameters and calls the IOCTL handler.
1127 mwifiex_get_stats_info(struct mwifiex_private *priv,
1128 struct mwifiex_ds_get_stats *log)
1130 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1131 HostCmd_ACT_GEN_GET, 0, log);
1135 * IOCTL request handler to read/write register.
1137 * This function prepares the correct firmware command and
1140 * Access to the following registers are supported -
1147 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1148 struct mwifiex_ds_reg_rw *reg_rw,
1153 switch (le32_to_cpu(reg_rw->type)) {
1154 case MWIFIEX_REG_MAC:
1155 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1157 case MWIFIEX_REG_BBP:
1158 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1160 case MWIFIEX_REG_RF:
1161 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1163 case MWIFIEX_REG_PMIC:
1164 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1166 case MWIFIEX_REG_CAU:
1167 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1173 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1178 * Sends IOCTL request to write to a register.
1180 * This function allocates the IOCTL request buffer, fills it
1181 * with requisite parameters and calls the IOCTL handler.
1184 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1185 u32 reg_offset, u32 reg_value)
1187 struct mwifiex_ds_reg_rw reg_rw;
1189 reg_rw.type = cpu_to_le32(reg_type);
1190 reg_rw.offset = cpu_to_le32(reg_offset);
1191 reg_rw.value = cpu_to_le32(reg_value);
1193 return mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET);
1197 * Sends IOCTL request to read from a register.
1199 * This function allocates the IOCTL request buffer, fills it
1200 * with requisite parameters and calls the IOCTL handler.
1203 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1204 u32 reg_offset, u32 *value)
1207 struct mwifiex_ds_reg_rw reg_rw;
1209 reg_rw.type = cpu_to_le32(reg_type);
1210 reg_rw.offset = cpu_to_le32(reg_offset);
1211 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET);
1216 *value = le32_to_cpu(reg_rw.value);
1223 * Sends IOCTL request to read from EEPROM.
1225 * This function allocates the IOCTL request buffer, fills it
1226 * with requisite parameters and calls the IOCTL handler.
1229 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1233 struct mwifiex_ds_read_eeprom rd_eeprom;
1235 rd_eeprom.offset = cpu_to_le16((u16) offset);
1236 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1238 /* Send request to firmware */
1239 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1240 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1243 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1248 * This function sets a generic IE. In addition to generic IE, it can
1249 * also handle WPA, WPA2 and WAPI IEs.
1252 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1256 struct ieee_types_vendor_header *pvendor_ie;
1257 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1258 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1260 /* If the passed length is zero, reset the buffer */
1262 priv->gen_ie_buf_len = 0;
1263 priv->wps.session_enable = false;
1266 } else if (!ie_data_ptr) {
1269 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1270 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1271 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1272 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1273 (pvendor_ie->element_id == WLAN_EID_RSN)) {
1275 /* IE is a WPA/WPA2 IE so call set_wpa function */
1276 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1277 priv->wps.session_enable = false;
1280 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1281 /* IE is a WAPI IE so call set_wapi function */
1282 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1287 * Verify that the passed length is not larger than the
1288 * available space remaining in the buffer
1290 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1292 /* Test to see if it is a WPS IE, if so, enable
1295 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1296 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1297 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
1298 priv->wps.session_enable = true;
1299 dev_dbg(priv->adapter->dev,
1300 "info: WPS Session Enabled.\n");
1301 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
1304 /* Append the passed data to the end of the
1306 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1308 /* Increment the stored buffer length by the
1310 priv->gen_ie_buf_len += ie_len;
1312 /* Passed data does not fit in the remaining
1317 /* Return 0, or -1 for error case */
1322 * IOCTL request handler to set/get generic IE.
1324 * In addition to various generic IEs, this function can also be
1325 * used to set the ARP filter.
1327 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1328 struct mwifiex_ds_misc_gen_ie *gen_ie,
1331 struct mwifiex_adapter *adapter = priv->adapter;
1333 switch (gen_ie->type) {
1334 case MWIFIEX_IE_TYPE_GEN_IE:
1335 if (action == HostCmd_ACT_GEN_GET) {
1336 gen_ie->len = priv->wpa_ie_len;
1337 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1339 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1343 case MWIFIEX_IE_TYPE_ARP_FILTER:
1344 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1345 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1346 adapter->arp_filter_size = 0;
1347 dev_err(adapter->dev, "invalid ARP filter size\n");
1350 memcpy(adapter->arp_filter, gen_ie->ie_data,
1352 adapter->arp_filter_size = gen_ie->len;
1356 dev_err(adapter->dev, "invalid IE type\n");
1363 * Sends IOCTL request to set a generic IE.
1365 * This function allocates the IOCTL request buffer, fills it
1366 * with requisite parameters and calls the IOCTL handler.
1369 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1371 struct mwifiex_ds_misc_gen_ie gen_ie;
1373 if (ie_len > IEEE_MAX_IE_SIZE)
1376 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1377 gen_ie.len = ie_len;
1378 memcpy(gen_ie.ie_data, ie, ie_len);
1379 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))