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 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
165 beacon_ie = kmemdup(bss->information_elements, bss->len_beacon_ies,
168 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
172 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
173 bss_desc->rssi = bss->signal;
174 bss_desc->beacon_buf = beacon_ie;
175 bss_desc->beacon_buf_size = bss->len_beacon_ies;
176 bss_desc->beacon_period = bss->beacon_interval;
177 bss_desc->cap_info_bitmap = bss->capability;
178 bss_desc->bss_band = bss_priv->band;
179 bss_desc->fw_tsf = bss_priv->fw_tsf;
180 bss_desc->timestamp = bss->tsf;
181 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
182 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
183 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
185 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
187 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
188 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
190 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
192 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
198 static int mwifiex_process_country_ie(struct mwifiex_private *priv,
199 struct cfg80211_bss *bss)
201 u8 *country_ie, country_ie_len;
202 struct mwifiex_802_11d_domain_reg *domain_info =
203 &priv->adapter->domain_reg;
205 country_ie = (u8 *)ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
210 country_ie_len = country_ie[1];
211 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
214 domain_info->country_code[0] = country_ie[2];
215 domain_info->country_code[1] = country_ie[3];
216 domain_info->country_code[2] = ' ';
218 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
220 domain_info->no_of_triplet =
221 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
223 memcpy((u8 *)domain_info->triplet,
224 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
226 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
227 HostCmd_ACT_GEN_SET, 0, NULL)) {
228 wiphy_err(priv->adapter->wiphy,
229 "11D: setting domain info in FW\n");
237 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
238 * In both Ad-Hoc and infra mode, an deauthentication is performed
241 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
242 struct cfg80211_ssid *req_ssid)
245 struct mwifiex_adapter *adapter = priv->adapter;
246 struct mwifiex_bssdescriptor *bss_desc = NULL;
248 priv->scan_block = false;
251 mwifiex_process_country_ie(priv, bss);
253 /* Allocate and fill new bss descriptor */
254 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
257 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
261 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
266 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
268 ret = mwifiex_deauthenticate(priv, NULL);
272 ret = mwifiex_check_network_compatibility(priv, bss_desc);
276 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
279 if (!netif_queue_stopped(priv->netdev))
280 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
281 if (netif_carrier_ok(priv->netdev))
282 netif_carrier_off(priv->netdev);
284 /* Clear any past association response stored for
285 * application retrieval */
286 priv->assoc_rsp_size = 0;
287 ret = mwifiex_associate(priv, bss_desc);
289 /* If auth type is auto and association fails using open mode,
290 * try to connect using shared mode */
291 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
292 priv->sec_info.is_authtype_auto &&
293 priv->sec_info.wep_enabled) {
294 priv->sec_info.authentication_mode =
295 NL80211_AUTHTYPE_SHARED_KEY;
296 ret = mwifiex_associate(priv, bss_desc);
300 cfg80211_put_bss(bss);
303 /* If the requested SSID matches current SSID, return */
304 if (bss_desc && bss_desc->ssid.ssid_len &&
305 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
306 ssid, &bss_desc->ssid))) {
311 /* Exit Adhoc mode first */
312 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
313 ret = mwifiex_deauthenticate(priv, NULL);
317 priv->adhoc_is_link_sensed = false;
319 ret = mwifiex_check_network_compatibility(priv, bss_desc);
321 if (!netif_queue_stopped(priv->netdev))
322 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
323 if (netif_carrier_ok(priv->netdev))
324 netif_carrier_off(priv->netdev);
327 dev_dbg(adapter->dev, "info: network found in scan"
328 " list. Joining...\n");
329 ret = mwifiex_adhoc_join(priv, bss_desc);
331 cfg80211_put_bss(bss);
333 dev_dbg(adapter->dev, "info: Network not found in "
334 "the list, creating adhoc with ssid = %s\n",
336 ret = mwifiex_adhoc_start(priv, req_ssid);
346 * IOCTL request handler to set host sleep configuration.
348 * This function prepares the correct firmware command and
351 static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
352 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
355 struct mwifiex_adapter *adapter = priv->adapter;
363 case HostCmd_ACT_GEN_SET:
364 if (adapter->pps_uapsd_mode) {
365 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
366 " is blocked in UAPSD/PPS mode\n");
370 if (hs_cfg->is_invoke_hostcmd) {
371 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
372 if (!adapter->is_hs_configured)
373 /* Already cancelled */
375 /* Save previous condition */
376 prev_cond = le32_to_cpu(adapter->hs_cfg
378 adapter->hs_cfg.conditions =
379 cpu_to_le32(hs_cfg->conditions);
380 } else if (hs_cfg->conditions) {
381 adapter->hs_cfg.conditions =
382 cpu_to_le32(hs_cfg->conditions);
383 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
385 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
386 } else if (adapter->hs_cfg.conditions
387 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
388 /* Return failure if no parameters for HS
393 if (cmd_type == MWIFIEX_SYNC_CMD)
394 status = mwifiex_send_cmd_sync(priv,
395 HostCmd_CMD_802_11_HS_CFG_ENH,
396 HostCmd_ACT_GEN_SET, 0,
399 status = mwifiex_send_cmd_async(priv,
400 HostCmd_CMD_802_11_HS_CFG_ENH,
401 HostCmd_ACT_GEN_SET, 0,
403 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
404 /* Restore previous condition */
405 adapter->hs_cfg.conditions =
406 cpu_to_le32(prev_cond);
408 adapter->hs_cfg.conditions =
409 cpu_to_le32(hs_cfg->conditions);
410 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
411 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
414 case HostCmd_ACT_GEN_GET:
415 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
416 hs_cfg->gpio = adapter->hs_cfg.gpio;
417 hs_cfg->gap = adapter->hs_cfg.gap;
428 * Sends IOCTL request to cancel the existing Host Sleep configuration.
430 * This function allocates the IOCTL request buffer, fills it
431 * with requisite parameters and calls the IOCTL handler.
433 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
435 struct mwifiex_ds_hs_cfg hscfg;
437 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
438 hscfg.is_invoke_hostcmd = true;
440 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
443 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
446 * Sends IOCTL request to cancel the existing Host Sleep configuration.
448 * This function allocates the IOCTL request buffer, fills it
449 * with requisite parameters and calls the IOCTL handler.
451 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
453 struct mwifiex_ds_hs_cfg hscfg;
454 struct mwifiex_private *priv;
457 if (disconnect_on_suspend) {
458 for (i = 0; i < adapter->priv_num; i++) {
459 priv = adapter->priv[i];
461 mwifiex_deauthenticate(priv, NULL);
465 if (adapter->hs_activated) {
466 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
470 adapter->hs_activate_wait_q_woken = false;
472 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
473 hscfg.is_invoke_hostcmd = true;
475 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
476 MWIFIEX_BSS_ROLE_STA),
477 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
479 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
483 wait_event_interruptible(adapter->hs_activate_wait_q,
484 adapter->hs_activate_wait_q_woken);
488 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
491 * IOCTL request handler to get BSS information.
493 * This function collates the information from different driver structures
494 * to send to the user.
496 int mwifiex_get_bss_info(struct mwifiex_private *priv,
497 struct mwifiex_bss_info *info)
499 struct mwifiex_adapter *adapter = priv->adapter;
500 struct mwifiex_bssdescriptor *bss_desc;
505 bss_desc = &priv->curr_bss_params.bss_descriptor;
507 info->bss_mode = priv->bss_mode;
509 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
511 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
513 info->bss_chan = bss_desc->channel;
515 memcpy(info->country_code, adapter->country_code,
516 IEEE80211_COUNTRY_STRING_LEN);
518 info->media_connected = priv->media_connected;
520 info->max_power_level = priv->max_tx_power_level;
521 info->min_power_level = priv->min_tx_power_level;
523 info->adhoc_state = priv->adhoc_state;
525 info->bcn_nf_last = priv->bcn_nf_last;
527 if (priv->sec_info.wep_enabled)
528 info->wep_status = true;
530 info->wep_status = false;
532 info->is_hs_configured = adapter->is_hs_configured;
533 info->is_deep_sleep = adapter->is_deep_sleep;
539 * The function disables auto deep sleep mode.
541 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
543 struct mwifiex_ds_auto_ds auto_ds;
545 auto_ds.auto_ds = DEEP_SLEEP_OFF;
547 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
548 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
550 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
553 * Sends IOCTL request to get the data rate.
555 * This function allocates the IOCTL request buffer, fills it
556 * with requisite parameters and calls the IOCTL handler.
558 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
562 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
563 HostCmd_ACT_GEN_GET, 0, NULL);
566 if (priv->is_data_rate_auto)
567 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
570 *rate = priv->data_rate;
577 * IOCTL request handler to set tx power configuration.
579 * This function prepares the correct firmware command and
582 * For non-auto power mode, all the following power groups are set -
583 * - Modulation class HR/DSSS
584 * - Modulation class OFDM
585 * - Modulation class HTBW20
586 * - Modulation class HTBW40
588 int mwifiex_set_tx_power(struct mwifiex_private *priv,
589 struct mwifiex_power_cfg *power_cfg)
592 struct host_cmd_ds_txpwr_cfg *txp_cfg;
593 struct mwifiex_types_power_group *pg_tlv;
594 struct mwifiex_power_group *pg;
598 if (!power_cfg->is_power_auto) {
599 dbm = (u16) power_cfg->power_level;
600 if ((dbm < priv->min_tx_power_level) ||
601 (dbm > priv->max_tx_power_level)) {
602 dev_err(priv->adapter->dev, "txpower value %d dBm"
603 " is out of range (%d dBm-%d dBm)\n",
604 dbm, priv->min_tx_power_level,
605 priv->max_tx_power_level);
609 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
611 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
616 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
617 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
618 if (!power_cfg->is_power_auto) {
619 txp_cfg->mode = cpu_to_le32(1);
620 pg_tlv = (struct mwifiex_types_power_group *)
621 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
622 pg_tlv->type = TLV_TYPE_POWER_GROUP;
623 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
624 pg = (struct mwifiex_power_group *)
625 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
626 + sizeof(struct mwifiex_types_power_group));
627 /* Power group for modulation class HR/DSSS */
628 pg->first_rate_code = 0x00;
629 pg->last_rate_code = 0x03;
630 pg->modulation_class = MOD_CLASS_HR_DSSS;
632 pg->power_min = (s8) dbm;
633 pg->power_max = (s8) dbm;
635 /* Power group for modulation class OFDM */
636 pg->first_rate_code = 0x00;
637 pg->last_rate_code = 0x07;
638 pg->modulation_class = MOD_CLASS_OFDM;
640 pg->power_min = (s8) dbm;
641 pg->power_max = (s8) dbm;
643 /* Power group for modulation class HTBW20 */
644 pg->first_rate_code = 0x00;
645 pg->last_rate_code = 0x20;
646 pg->modulation_class = MOD_CLASS_HT;
648 pg->power_min = (s8) dbm;
649 pg->power_max = (s8) dbm;
650 pg->ht_bandwidth = HT_BW_20;
652 /* Power group for modulation class HTBW40 */
653 pg->first_rate_code = 0x00;
654 pg->last_rate_code = 0x20;
655 pg->modulation_class = MOD_CLASS_HT;
657 pg->power_min = (s8) dbm;
658 pg->power_max = (s8) dbm;
659 pg->ht_bandwidth = HT_BW_40;
661 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
662 HostCmd_ACT_GEN_SET, 0, buf);
669 * IOCTL request handler to get power save mode.
671 * This function prepares the correct firmware command and
674 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
677 struct mwifiex_adapter *adapter = priv->adapter;
681 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
683 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
684 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
685 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
686 sub_cmd, BITMAP_STA_PS, NULL);
687 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
688 ret = mwifiex_send_cmd_async(priv,
689 HostCmd_CMD_802_11_PS_MODE_ENH,
696 * IOCTL request handler to set/reset WPA IE.
698 * The supplied WPA IE is treated as a opaque buffer. Only the first field
699 * is checked to determine WPA version. If buffer length is zero, the existing
702 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
703 u8 *ie_data_ptr, u16 ie_len)
706 if (ie_len > sizeof(priv->wpa_ie)) {
707 dev_err(priv->adapter->dev,
708 "failed to copy WPA IE, too big\n");
711 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
712 priv->wpa_ie_len = (u8) ie_len;
713 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
714 priv->wpa_ie_len, priv->wpa_ie[0]);
716 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
717 priv->sec_info.wpa_enabled = true;
718 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
719 priv->sec_info.wpa2_enabled = true;
721 priv->sec_info.wpa_enabled = false;
722 priv->sec_info.wpa2_enabled = false;
725 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
726 priv->wpa_ie_len = 0;
727 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
728 priv->wpa_ie_len, priv->wpa_ie[0]);
729 priv->sec_info.wpa_enabled = false;
730 priv->sec_info.wpa2_enabled = false;
737 * IOCTL request handler to set/reset WAPI IE.
739 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
740 * is checked to internally enable WAPI. If buffer length is zero, the existing
743 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
744 u8 *ie_data_ptr, u16 ie_len)
747 if (ie_len > sizeof(priv->wapi_ie)) {
748 dev_dbg(priv->adapter->dev,
749 "info: failed to copy WAPI IE, too big\n");
752 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
753 priv->wapi_ie_len = ie_len;
754 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
755 priv->wapi_ie_len, priv->wapi_ie[0]);
757 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
758 priv->sec_info.wapi_enabled = true;
760 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
761 priv->wapi_ie_len = ie_len;
762 dev_dbg(priv->adapter->dev,
763 "info: Reset wapi_ie_len=%d IE=%#x\n",
764 priv->wapi_ie_len, priv->wapi_ie[0]);
765 priv->sec_info.wapi_enabled = false;
771 * IOCTL request handler to set/reset WPS IE.
773 * The supplied WPS IE is treated as a opaque buffer. Only the first field
774 * is checked to internally enable WPS. If buffer length is zero, the existing
777 static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
778 u8 *ie_data_ptr, u16 ie_len)
781 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
784 if (ie_len > sizeof(priv->wps_ie)) {
785 dev_dbg(priv->adapter->dev,
786 "info: failed to copy WPS IE, too big\n");
790 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
791 priv->wps_ie_len = ie_len;
792 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
793 priv->wps_ie_len, priv->wps_ie[0]);
796 priv->wps_ie_len = ie_len;
797 dev_dbg(priv->adapter->dev,
798 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
804 * IOCTL request handler to set WAPI key.
806 * This function prepares the correct firmware command and
809 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
810 struct mwifiex_ds_encrypt_key *encrypt_key)
813 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
814 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
819 * IOCTL request handler to set WEP network key.
821 * This function prepares the correct firmware command and
822 * issues it, after validation checks.
824 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
825 struct mwifiex_ds_encrypt_key *encrypt_key)
828 struct mwifiex_wep_key *wep_key;
831 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
832 priv->wep_key_curr_index = 0;
833 wep_key = &priv->wep_key[priv->wep_key_curr_index];
834 index = encrypt_key->key_index;
835 if (encrypt_key->key_disable) {
836 priv->sec_info.wep_enabled = 0;
837 } else if (!encrypt_key->key_len) {
838 /* Copy the required key as the current key */
839 wep_key = &priv->wep_key[index];
840 if (!wep_key->key_length) {
841 dev_err(priv->adapter->dev,
842 "key not set, so cannot enable it\n");
845 priv->wep_key_curr_index = (u16) index;
846 priv->sec_info.wep_enabled = 1;
848 wep_key = &priv->wep_key[index];
849 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
850 /* Copy the key in the driver */
851 memcpy(wep_key->key_material,
852 encrypt_key->key_material,
853 encrypt_key->key_len);
854 wep_key->key_index = index;
855 wep_key->key_length = encrypt_key->key_len;
856 priv->sec_info.wep_enabled = 1;
858 if (wep_key->key_length) {
859 /* Send request to firmware */
860 ret = mwifiex_send_cmd_async(priv,
861 HostCmd_CMD_802_11_KEY_MATERIAL,
862 HostCmd_ACT_GEN_SET, 0, NULL);
866 if (priv->sec_info.wep_enabled)
867 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
869 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
871 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
872 HostCmd_ACT_GEN_SET, 0,
873 &priv->curr_pkt_filter);
879 * IOCTL request handler to set WPA key.
881 * This function prepares the correct firmware command and
882 * issues it, after validation checks.
884 * Current driver only supports key length of up to 32 bytes.
886 * This function can also be used to disable a currently set key.
888 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
889 struct mwifiex_ds_encrypt_key *encrypt_key)
892 u8 remove_key = false;
893 struct host_cmd_ds_802_11_key_material *ibss_key;
895 /* Current driver only supports key length of up to 32 bytes */
896 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
897 dev_err(priv->adapter->dev, "key length too long\n");
901 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
903 * IBSS/WPA-None uses only one key (Group) for both receiving
904 * and sending unicast and multicast packets.
906 /* Send the key as PTK to firmware */
907 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
908 ret = mwifiex_send_cmd_async(priv,
909 HostCmd_CMD_802_11_KEY_MATERIAL,
911 KEY_INFO_ENABLED, encrypt_key);
915 ibss_key = &priv->aes_key;
917 sizeof(struct host_cmd_ds_802_11_key_material));
918 /* Copy the key in the driver */
919 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
920 encrypt_key->key_len);
921 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
922 sizeof(ibss_key->key_param_set.key_len));
923 ibss_key->key_param_set.key_type_id
924 = cpu_to_le16(KEY_TYPE_ID_TKIP);
925 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
927 /* Send the key as GTK to firmware */
928 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
931 if (!encrypt_key->key_index)
932 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
935 ret = mwifiex_send_cmd_sync(priv,
936 HostCmd_CMD_802_11_KEY_MATERIAL,
938 !KEY_INFO_ENABLED, encrypt_key);
940 ret = mwifiex_send_cmd_sync(priv,
941 HostCmd_CMD_802_11_KEY_MATERIAL,
943 KEY_INFO_ENABLED, encrypt_key);
949 * IOCTL request handler to set/get network keys.
951 * This is a generic key handling function which supports WEP, WPA
955 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
956 struct mwifiex_ds_encrypt_key *encrypt_key)
960 if (encrypt_key->is_wapi_key)
961 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
962 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
963 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
965 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
970 * This function returns the driver version.
973 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
982 ver.l = adapter->fw_release_number;
983 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
985 snprintf(version, max_len, driver_version, fw_ver);
987 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
993 * Sends IOCTL request to set encoding parameters.
995 * This function allocates the IOCTL request buffer, fills it
996 * with requisite parameters and calls the IOCTL handler.
998 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
999 const u8 *key, int key_len, u8 key_index,
1000 const u8 *mac_addr, int disable)
1002 struct mwifiex_ds_encrypt_key encrypt_key;
1004 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1005 encrypt_key.key_len = key_len;
1007 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1008 encrypt_key.is_igtk_key = true;
1011 encrypt_key.key_index = key_index;
1013 memcpy(encrypt_key.key_material, key, key_len);
1015 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1016 if (kp && kp->seq && kp->seq_len)
1017 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
1019 encrypt_key.key_disable = true;
1021 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
1024 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1028 * Sends IOCTL request to get extended version.
1030 * This function allocates the IOCTL request buffer, fills it
1031 * with requisite parameters and calls the IOCTL handler.
1034 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1036 struct mwifiex_ver_ext ver_ext;
1038 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1039 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1040 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1047 mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1048 struct ieee80211_channel *chan,
1049 enum nl80211_channel_type *ct,
1050 unsigned int duration)
1052 struct host_cmd_ds_remain_on_chan roc_cfg;
1055 memset(&roc_cfg, 0, sizeof(roc_cfg));
1056 roc_cfg.action = cpu_to_le16(action);
1057 if (action == HostCmd_ACT_GEN_SET) {
1058 roc_cfg.band_cfg = chan->band;
1059 sc = mwifiex_chan_type_to_sec_chan_offset(*ct);
1060 roc_cfg.band_cfg |= (sc << 2);
1063 ieee80211_frequency_to_channel(chan->center_freq);
1064 roc_cfg.duration = cpu_to_le32(duration);
1066 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1067 action, 0, &roc_cfg)) {
1068 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1072 return roc_cfg.status;
1076 mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1078 if (GET_BSS_ROLE(priv) == bss_role) {
1079 dev_dbg(priv->adapter->dev,
1080 "info: already in the desired role.\n");
1084 mwifiex_free_priv(priv);
1085 mwifiex_init_priv(priv);
1087 priv->bss_role = bss_role;
1089 case MWIFIEX_BSS_ROLE_UAP:
1090 priv->bss_mode = NL80211_IFTYPE_AP;
1092 case MWIFIEX_BSS_ROLE_STA:
1093 case MWIFIEX_BSS_ROLE_ANY:
1095 priv->bss_mode = NL80211_IFTYPE_STATION;
1099 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1100 HostCmd_ACT_GEN_SET, 0, NULL);
1102 return mwifiex_sta_init_cmd(priv, false);
1106 * Sends IOCTL request to get statistics information.
1108 * This function allocates the IOCTL request buffer, fills it
1109 * with requisite parameters and calls the IOCTL handler.
1112 mwifiex_get_stats_info(struct mwifiex_private *priv,
1113 struct mwifiex_ds_get_stats *log)
1115 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1116 HostCmd_ACT_GEN_GET, 0, log);
1120 * IOCTL request handler to read/write register.
1122 * This function prepares the correct firmware command and
1125 * Access to the following registers are supported -
1132 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1133 struct mwifiex_ds_reg_rw *reg_rw,
1138 switch (le32_to_cpu(reg_rw->type)) {
1139 case MWIFIEX_REG_MAC:
1140 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1142 case MWIFIEX_REG_BBP:
1143 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1145 case MWIFIEX_REG_RF:
1146 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1148 case MWIFIEX_REG_PMIC:
1149 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1151 case MWIFIEX_REG_CAU:
1152 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1158 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1163 * Sends IOCTL request to write to a register.
1165 * This function allocates the IOCTL request buffer, fills it
1166 * with requisite parameters and calls the IOCTL handler.
1169 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1170 u32 reg_offset, u32 reg_value)
1172 struct mwifiex_ds_reg_rw reg_rw;
1174 reg_rw.type = cpu_to_le32(reg_type);
1175 reg_rw.offset = cpu_to_le32(reg_offset);
1176 reg_rw.value = cpu_to_le32(reg_value);
1178 return mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET);
1182 * Sends IOCTL request to read from a register.
1184 * This function allocates the IOCTL request buffer, fills it
1185 * with requisite parameters and calls the IOCTL handler.
1188 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1189 u32 reg_offset, u32 *value)
1192 struct mwifiex_ds_reg_rw reg_rw;
1194 reg_rw.type = cpu_to_le32(reg_type);
1195 reg_rw.offset = cpu_to_le32(reg_offset);
1196 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET);
1201 *value = le32_to_cpu(reg_rw.value);
1208 * Sends IOCTL request to read from EEPROM.
1210 * This function allocates the IOCTL request buffer, fills it
1211 * with requisite parameters and calls the IOCTL handler.
1214 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1218 struct mwifiex_ds_read_eeprom rd_eeprom;
1220 rd_eeprom.offset = cpu_to_le16((u16) offset);
1221 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1223 /* Send request to firmware */
1224 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1225 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1228 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1233 * This function sets a generic IE. In addition to generic IE, it can
1234 * also handle WPA, WPA2 and WAPI IEs.
1237 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1241 struct ieee_types_vendor_header *pvendor_ie;
1242 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1243 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1245 /* If the passed length is zero, reset the buffer */
1247 priv->gen_ie_buf_len = 0;
1248 priv->wps.session_enable = false;
1251 } else if (!ie_data_ptr) {
1254 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1255 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1256 if (((pvendor_ie->element_id == WLAN_EID_WPA) &&
1257 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1258 (pvendor_ie->element_id == WLAN_EID_RSN)) {
1260 /* IE is a WPA/WPA2 IE so call set_wpa function */
1261 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1262 priv->wps.session_enable = false;
1265 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1266 /* IE is a WAPI IE so call set_wapi function */
1267 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1272 * Verify that the passed length is not larger than the
1273 * available space remaining in the buffer
1275 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1277 /* Test to see if it is a WPS IE, if so, enable
1280 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1281 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1282 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
1283 priv->wps.session_enable = true;
1284 dev_dbg(priv->adapter->dev,
1285 "info: WPS Session Enabled.\n");
1286 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
1289 /* Append the passed data to the end of the
1291 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1293 /* Increment the stored buffer length by the
1295 priv->gen_ie_buf_len += ie_len;
1297 /* Passed data does not fit in the remaining
1302 /* Return 0, or -1 for error case */
1307 * IOCTL request handler to set/get generic IE.
1309 * In addition to various generic IEs, this function can also be
1310 * used to set the ARP filter.
1312 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1313 struct mwifiex_ds_misc_gen_ie *gen_ie,
1316 struct mwifiex_adapter *adapter = priv->adapter;
1318 switch (gen_ie->type) {
1319 case MWIFIEX_IE_TYPE_GEN_IE:
1320 if (action == HostCmd_ACT_GEN_GET) {
1321 gen_ie->len = priv->wpa_ie_len;
1322 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1324 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1328 case MWIFIEX_IE_TYPE_ARP_FILTER:
1329 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1330 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1331 adapter->arp_filter_size = 0;
1332 dev_err(adapter->dev, "invalid ARP filter size\n");
1335 memcpy(adapter->arp_filter, gen_ie->ie_data,
1337 adapter->arp_filter_size = gen_ie->len;
1341 dev_err(adapter->dev, "invalid IE type\n");
1348 * Sends IOCTL request to set a generic IE.
1350 * This function allocates the IOCTL request buffer, fills it
1351 * with requisite parameters and calls the IOCTL handler.
1354 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1356 struct mwifiex_ds_misc_gen_ie gen_ie;
1358 if (ie_len > IEEE_MAX_IE_SIZE)
1361 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1362 gen_ie.len = ie_len;
1363 memcpy(gen_ie.ie_data, ie, ie_len);
1364 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))