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
,
58 struct cmd_ctrl_node
*cmd_queued
)
62 /* Wait for completion */
63 status
= wait_event_interruptible(adapter
->cmd_wait_q
.wait
,
64 *(cmd_queued
->condition
));
66 dev_err(adapter
->dev
, "cmd_wait_q terminated: %d\n", status
);
70 status
= adapter
->cmd_wait_q
.status
;
71 adapter
->cmd_wait_q
.status
= 0;
77 * This function prepares the correct firmware command and
78 * issues it to set the multicast list.
80 * This function can be used to enable promiscuous mode, or enable all
81 * multicast packets, or to enable selective multicast.
83 int mwifiex_request_set_multicast_list(struct mwifiex_private
*priv
,
84 struct mwifiex_multicast_list
*mcast_list
)
89 old_pkt_filter
= priv
->curr_pkt_filter
;
91 if (mcast_list
->mode
== MWIFIEX_PROMISC_MODE
) {
92 dev_dbg(priv
->adapter
->dev
, "info: Enable Promiscuous mode\n");
93 priv
->curr_pkt_filter
|= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE
;
94 priv
->curr_pkt_filter
&=
95 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
98 priv
->curr_pkt_filter
&= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE
;
99 if (mcast_list
->mode
== MWIFIEX_ALL_MULTI_MODE
) {
100 dev_dbg(priv
->adapter
->dev
,
101 "info: Enabling All Multicast!\n");
102 priv
->curr_pkt_filter
|=
103 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
105 priv
->curr_pkt_filter
&=
106 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
107 dev_dbg(priv
->adapter
->dev
,
108 "info: Set multicast list=%d\n",
109 mcast_list
->num_multicast_addr
);
110 /* Send multicast addresses to firmware */
111 ret
= mwifiex_send_cmd_async(priv
,
112 HostCmd_CMD_MAC_MULTICAST_ADR
,
113 HostCmd_ACT_GEN_SET
, 0,
117 dev_dbg(priv
->adapter
->dev
,
118 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
119 old_pkt_filter
, priv
->curr_pkt_filter
);
120 if (old_pkt_filter
!= priv
->curr_pkt_filter
) {
121 ret
= mwifiex_send_cmd_async(priv
, HostCmd_CMD_MAC_CONTROL
,
123 0, &priv
->curr_pkt_filter
);
130 * This function fills bss descriptor structure using provided
132 * beacon_ie buffer is allocated in this function. It is caller's
133 * responsibility to free the memory.
135 int mwifiex_fill_new_bss_desc(struct mwifiex_private
*priv
,
136 struct cfg80211_bss
*bss
,
137 struct mwifiex_bssdescriptor
*bss_desc
)
140 size_t beacon_ie_len
;
141 struct mwifiex_bss_priv
*bss_priv
= (void *)bss
->priv
;
142 const struct cfg80211_bss_ies
*ies
;
145 ies
= rcu_dereference(bss
->ies
);
146 beacon_ie
= kmemdup(ies
->data
, ies
->len
, GFP_ATOMIC
);
147 beacon_ie_len
= ies
->len
;
148 bss_desc
->timestamp
= ies
->tsf
;
152 dev_err(priv
->adapter
->dev
, " failed to alloc beacon_ie\n");
156 memcpy(bss_desc
->mac_address
, bss
->bssid
, ETH_ALEN
);
157 bss_desc
->rssi
= bss
->signal
;
158 /* The caller of this function will free beacon_ie */
159 bss_desc
->beacon_buf
= beacon_ie
;
160 bss_desc
->beacon_buf_size
= beacon_ie_len
;
161 bss_desc
->beacon_period
= bss
->beacon_interval
;
162 bss_desc
->cap_info_bitmap
= bss
->capability
;
163 bss_desc
->bss_band
= bss_priv
->band
;
164 bss_desc
->fw_tsf
= bss_priv
->fw_tsf
;
165 if (bss_desc
->cap_info_bitmap
& WLAN_CAPABILITY_PRIVACY
) {
166 dev_dbg(priv
->adapter
->dev
, "info: InterpretIE: AP WEP enabled\n");
167 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_8021X_WEP
;
169 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL
;
171 if (bss_desc
->cap_info_bitmap
& WLAN_CAPABILITY_IBSS
)
172 bss_desc
->bss_mode
= NL80211_IFTYPE_ADHOC
;
174 bss_desc
->bss_mode
= NL80211_IFTYPE_STATION
;
176 /* Disable 11ac by default. Enable it only where there
177 * exist VHT_CAP IE in AP beacon
179 bss_desc
->disable_11ac
= true;
181 if (bss_desc
->cap_info_bitmap
& WLAN_CAPABILITY_SPECTRUM_MGMT
)
182 bss_desc
->sensed_11h
= true;
184 return mwifiex_update_bss_desc_with_ie(priv
->adapter
, bss_desc
);
187 static int mwifiex_process_country_ie(struct mwifiex_private
*priv
,
188 struct cfg80211_bss
*bss
)
190 const u8
*country_ie
;
192 struct mwifiex_802_11d_domain_reg
*domain_info
=
193 &priv
->adapter
->domain_reg
;
196 country_ie
= ieee80211_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
202 country_ie_len
= country_ie
[1];
203 if (country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
) {
208 domain_info
->country_code
[0] = country_ie
[2];
209 domain_info
->country_code
[1] = country_ie
[3];
210 domain_info
->country_code
[2] = ' ';
212 country_ie_len
-= IEEE80211_COUNTRY_STRING_LEN
;
214 domain_info
->no_of_triplet
=
215 country_ie_len
/ sizeof(struct ieee80211_country_ie_triplet
);
217 memcpy((u8
*)domain_info
->triplet
,
218 &country_ie
[2] + IEEE80211_COUNTRY_STRING_LEN
, country_ie_len
);
222 if (mwifiex_send_cmd_async(priv
, HostCmd_CMD_802_11D_DOMAIN_INFO
,
223 HostCmd_ACT_GEN_SET
, 0, NULL
)) {
224 wiphy_err(priv
->adapter
->wiphy
,
225 "11D: setting domain info in FW\n");
233 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
234 * In both Ad-Hoc and infra mode, an deauthentication is performed
237 int mwifiex_bss_start(struct mwifiex_private
*priv
, struct cfg80211_bss
*bss
,
238 struct cfg80211_ssid
*req_ssid
)
241 struct mwifiex_adapter
*adapter
= priv
->adapter
;
242 struct mwifiex_bssdescriptor
*bss_desc
= NULL
;
244 priv
->scan_block
= false;
247 mwifiex_process_country_ie(priv
, bss
);
249 /* Allocate and fill new bss descriptor */
250 bss_desc
= kzalloc(sizeof(struct mwifiex_bssdescriptor
),
255 ret
= mwifiex_fill_new_bss_desc(priv
, bss
, bss_desc
);
260 if (priv
->bss_mode
== NL80211_IFTYPE_STATION
) {
264 ret
= mwifiex_deauthenticate(priv
, NULL
);
271 if (mwifiex_band_to_radio_type(bss_desc
->bss_band
) ==
272 HostCmd_SCAN_RADIO_TYPE_BG
)
273 config_bands
= BAND_B
| BAND_G
| BAND_GN
| BAND_GAC
;
275 config_bands
= BAND_A
| BAND_AN
| BAND_AAC
;
277 if (!((config_bands
| adapter
->fw_bands
) & ~adapter
->fw_bands
))
278 adapter
->config_bands
= config_bands
;
280 ret
= mwifiex_check_network_compatibility(priv
, bss_desc
);
284 if (mwifiex_11h_get_csa_closed_channel(priv
) ==
285 (u8
)bss_desc
->channel
) {
286 dev_err(adapter
->dev
,
287 "Attempt to reconnect on csa closed chan(%d)\n",
292 dev_dbg(adapter
->dev
, "info: SSID found in scan list ... "
295 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
296 if (netif_carrier_ok(priv
->netdev
))
297 netif_carrier_off(priv
->netdev
);
299 /* Clear any past association response stored for
300 * application retrieval */
301 priv
->assoc_rsp_size
= 0;
302 ret
= mwifiex_associate(priv
, bss_desc
);
304 /* If auth type is auto and association fails using open mode,
305 * try to connect using shared mode */
306 if (ret
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
&&
307 priv
->sec_info
.is_authtype_auto
&&
308 priv
->sec_info
.wep_enabled
) {
309 priv
->sec_info
.authentication_mode
=
310 NL80211_AUTHTYPE_SHARED_KEY
;
311 ret
= mwifiex_associate(priv
, bss_desc
);
315 cfg80211_put_bss(priv
->adapter
->wiphy
, bss
);
318 /* If the requested SSID matches current SSID, return */
319 if (bss_desc
&& bss_desc
->ssid
.ssid_len
&&
320 (!mwifiex_ssid_cmp(&priv
->curr_bss_params
.bss_descriptor
.
321 ssid
, &bss_desc
->ssid
))) {
326 /* Exit Adhoc mode first */
327 dev_dbg(adapter
->dev
, "info: Sending Adhoc Stop\n");
328 ret
= mwifiex_deauthenticate(priv
, NULL
);
332 priv
->adhoc_is_link_sensed
= false;
334 ret
= mwifiex_check_network_compatibility(priv
, bss_desc
);
336 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
337 if (netif_carrier_ok(priv
->netdev
))
338 netif_carrier_off(priv
->netdev
);
341 dev_dbg(adapter
->dev
, "info: network found in scan"
342 " list. Joining...\n");
343 ret
= mwifiex_adhoc_join(priv
, bss_desc
);
345 cfg80211_put_bss(priv
->adapter
->wiphy
, bss
);
347 dev_dbg(adapter
->dev
, "info: Network not found in "
348 "the list, creating adhoc with ssid = %s\n",
350 ret
= mwifiex_adhoc_start(priv
, req_ssid
);
355 /* beacon_ie buffer was allocated in function
356 * mwifiex_fill_new_bss_desc(). Free it now.
359 kfree(bss_desc
->beacon_buf
);
365 * IOCTL request handler to set host sleep configuration.
367 * This function prepares the correct firmware command and
370 static int mwifiex_set_hs_params(struct mwifiex_private
*priv
, u16 action
,
371 int cmd_type
, struct mwifiex_ds_hs_cfg
*hs_cfg
)
374 struct mwifiex_adapter
*adapter
= priv
->adapter
;
382 case HostCmd_ACT_GEN_SET
:
383 if (adapter
->pps_uapsd_mode
) {
384 dev_dbg(adapter
->dev
, "info: Host Sleep IOCTL"
385 " is blocked in UAPSD/PPS mode\n");
389 if (hs_cfg
->is_invoke_hostcmd
) {
390 if (hs_cfg
->conditions
== HS_CFG_CANCEL
) {
391 if (!adapter
->is_hs_configured
)
392 /* Already cancelled */
394 /* Save previous condition */
395 prev_cond
= le32_to_cpu(adapter
->hs_cfg
397 adapter
->hs_cfg
.conditions
=
398 cpu_to_le32(hs_cfg
->conditions
);
399 } else if (hs_cfg
->conditions
) {
400 adapter
->hs_cfg
.conditions
=
401 cpu_to_le32(hs_cfg
->conditions
);
402 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
404 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
405 } else if (adapter
->hs_cfg
.conditions
==
406 cpu_to_le32(HS_CFG_CANCEL
)) {
407 /* Return failure if no parameters for HS
412 if (cmd_type
== MWIFIEX_SYNC_CMD
)
413 status
= mwifiex_send_cmd_sync(priv
,
414 HostCmd_CMD_802_11_HS_CFG_ENH
,
415 HostCmd_ACT_GEN_SET
, 0,
418 status
= mwifiex_send_cmd_async(priv
,
419 HostCmd_CMD_802_11_HS_CFG_ENH
,
420 HostCmd_ACT_GEN_SET
, 0,
422 if (hs_cfg
->conditions
== HS_CFG_CANCEL
)
423 /* Restore previous condition */
424 adapter
->hs_cfg
.conditions
=
425 cpu_to_le32(prev_cond
);
427 adapter
->hs_cfg
.conditions
=
428 cpu_to_le32(hs_cfg
->conditions
);
429 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
430 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
433 case HostCmd_ACT_GEN_GET
:
434 hs_cfg
->conditions
= le32_to_cpu(adapter
->hs_cfg
.conditions
);
435 hs_cfg
->gpio
= adapter
->hs_cfg
.gpio
;
436 hs_cfg
->gap
= adapter
->hs_cfg
.gap
;
447 * Sends IOCTL request to cancel the existing Host Sleep configuration.
449 * This function allocates the IOCTL request buffer, fills it
450 * with requisite parameters and calls the IOCTL handler.
452 int mwifiex_cancel_hs(struct mwifiex_private
*priv
, int cmd_type
)
454 struct mwifiex_ds_hs_cfg hscfg
;
456 hscfg
.conditions
= HS_CFG_CANCEL
;
457 hscfg
.is_invoke_hostcmd
= true;
459 return mwifiex_set_hs_params(priv
, HostCmd_ACT_GEN_SET
,
462 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs
);
465 * Sends IOCTL request to cancel the existing Host Sleep configuration.
467 * This function allocates the IOCTL request buffer, fills it
468 * with requisite parameters and calls the IOCTL handler.
470 int mwifiex_enable_hs(struct mwifiex_adapter
*adapter
)
472 struct mwifiex_ds_hs_cfg hscfg
;
473 struct mwifiex_private
*priv
;
476 if (disconnect_on_suspend
) {
477 for (i
= 0; i
< adapter
->priv_num
; i
++) {
478 priv
= adapter
->priv
[i
];
480 mwifiex_deauthenticate(priv
, NULL
);
484 if (adapter
->hs_activated
) {
485 dev_dbg(adapter
->dev
, "cmd: HS Already activated\n");
489 adapter
->hs_activate_wait_q_woken
= false;
491 memset(&hscfg
, 0, sizeof(struct mwifiex_ds_hs_cfg
));
492 hscfg
.is_invoke_hostcmd
= true;
494 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter
,
495 MWIFIEX_BSS_ROLE_STA
),
496 HostCmd_ACT_GEN_SET
, MWIFIEX_SYNC_CMD
,
498 dev_err(adapter
->dev
, "IOCTL request HS enable failed\n");
502 if (wait_event_interruptible(adapter
->hs_activate_wait_q
,
503 adapter
->hs_activate_wait_q_woken
)) {
504 dev_err(adapter
->dev
, "hs_activate_wait_q terminated\n");
510 EXPORT_SYMBOL_GPL(mwifiex_enable_hs
);
513 * IOCTL request handler to get BSS information.
515 * This function collates the information from different driver structures
516 * to send to the user.
518 int mwifiex_get_bss_info(struct mwifiex_private
*priv
,
519 struct mwifiex_bss_info
*info
)
521 struct mwifiex_adapter
*adapter
= priv
->adapter
;
522 struct mwifiex_bssdescriptor
*bss_desc
;
527 bss_desc
= &priv
->curr_bss_params
.bss_descriptor
;
529 info
->bss_mode
= priv
->bss_mode
;
531 memcpy(&info
->ssid
, &bss_desc
->ssid
, sizeof(struct cfg80211_ssid
));
533 memcpy(&info
->bssid
, &bss_desc
->mac_address
, ETH_ALEN
);
535 info
->bss_chan
= bss_desc
->channel
;
537 memcpy(info
->country_code
, adapter
->country_code
,
538 IEEE80211_COUNTRY_STRING_LEN
);
540 info
->media_connected
= priv
->media_connected
;
542 info
->max_power_level
= priv
->max_tx_power_level
;
543 info
->min_power_level
= priv
->min_tx_power_level
;
545 info
->adhoc_state
= priv
->adhoc_state
;
547 info
->bcn_nf_last
= priv
->bcn_nf_last
;
549 if (priv
->sec_info
.wep_enabled
)
550 info
->wep_status
= true;
552 info
->wep_status
= false;
554 info
->is_hs_configured
= adapter
->is_hs_configured
;
555 info
->is_deep_sleep
= adapter
->is_deep_sleep
;
561 * The function disables auto deep sleep mode.
563 int mwifiex_disable_auto_ds(struct mwifiex_private
*priv
)
565 struct mwifiex_ds_auto_ds auto_ds
;
567 auto_ds
.auto_ds
= DEEP_SLEEP_OFF
;
569 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
570 DIS_AUTO_PS
, BITMAP_AUTO_DS
, &auto_ds
);
572 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds
);
575 * Sends IOCTL request to get the data rate.
577 * This function allocates the IOCTL request buffer, fills it
578 * with requisite parameters and calls the IOCTL handler.
580 int mwifiex_drv_get_data_rate(struct mwifiex_private
*priv
, u32
*rate
)
584 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_TX_RATE_QUERY
,
585 HostCmd_ACT_GEN_GET
, 0, NULL
);
588 if (priv
->is_data_rate_auto
)
589 *rate
= mwifiex_index_to_data_rate(priv
, priv
->tx_rate
,
592 *rate
= priv
->data_rate
;
599 * IOCTL request handler to set tx power configuration.
601 * This function prepares the correct firmware command and
604 * For non-auto power mode, all the following power groups are set -
605 * - Modulation class HR/DSSS
606 * - Modulation class OFDM
607 * - Modulation class HTBW20
608 * - Modulation class HTBW40
610 int mwifiex_set_tx_power(struct mwifiex_private
*priv
,
611 struct mwifiex_power_cfg
*power_cfg
)
614 struct host_cmd_ds_txpwr_cfg
*txp_cfg
;
615 struct mwifiex_types_power_group
*pg_tlv
;
616 struct mwifiex_power_group
*pg
;
620 if (!power_cfg
->is_power_auto
) {
621 dbm
= (u16
) power_cfg
->power_level
;
622 if ((dbm
< priv
->min_tx_power_level
) ||
623 (dbm
> priv
->max_tx_power_level
)) {
624 dev_err(priv
->adapter
->dev
, "txpower value %d dBm"
625 " is out of range (%d dBm-%d dBm)\n",
626 dbm
, priv
->min_tx_power_level
,
627 priv
->max_tx_power_level
);
631 buf
= kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER
, GFP_KERNEL
);
635 txp_cfg
= (struct host_cmd_ds_txpwr_cfg
*) buf
;
636 txp_cfg
->action
= cpu_to_le16(HostCmd_ACT_GEN_SET
);
637 if (!power_cfg
->is_power_auto
) {
638 txp_cfg
->mode
= cpu_to_le32(1);
639 pg_tlv
= (struct mwifiex_types_power_group
*)
640 (buf
+ sizeof(struct host_cmd_ds_txpwr_cfg
));
641 pg_tlv
->type
= TLV_TYPE_POWER_GROUP
;
642 pg_tlv
->length
= 4 * sizeof(struct mwifiex_power_group
);
643 pg
= (struct mwifiex_power_group
*)
644 (buf
+ sizeof(struct host_cmd_ds_txpwr_cfg
)
645 + sizeof(struct mwifiex_types_power_group
));
646 /* Power group for modulation class HR/DSSS */
647 pg
->first_rate_code
= 0x00;
648 pg
->last_rate_code
= 0x03;
649 pg
->modulation_class
= MOD_CLASS_HR_DSSS
;
651 pg
->power_min
= (s8
) dbm
;
652 pg
->power_max
= (s8
) dbm
;
654 /* Power group for modulation class OFDM */
655 pg
->first_rate_code
= 0x00;
656 pg
->last_rate_code
= 0x07;
657 pg
->modulation_class
= MOD_CLASS_OFDM
;
659 pg
->power_min
= (s8
) dbm
;
660 pg
->power_max
= (s8
) dbm
;
662 /* Power group for modulation class HTBW20 */
663 pg
->first_rate_code
= 0x00;
664 pg
->last_rate_code
= 0x20;
665 pg
->modulation_class
= MOD_CLASS_HT
;
667 pg
->power_min
= (s8
) dbm
;
668 pg
->power_max
= (s8
) dbm
;
669 pg
->ht_bandwidth
= HT_BW_20
;
671 /* Power group for modulation class HTBW40 */
672 pg
->first_rate_code
= 0x00;
673 pg
->last_rate_code
= 0x20;
674 pg
->modulation_class
= MOD_CLASS_HT
;
676 pg
->power_min
= (s8
) dbm
;
677 pg
->power_max
= (s8
) dbm
;
678 pg
->ht_bandwidth
= HT_BW_40
;
680 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_TXPWR_CFG
,
681 HostCmd_ACT_GEN_SET
, 0, buf
);
688 * IOCTL request handler to get power save mode.
690 * This function prepares the correct firmware command and
693 int mwifiex_drv_set_power(struct mwifiex_private
*priv
, u32
*ps_mode
)
696 struct mwifiex_adapter
*adapter
= priv
->adapter
;
700 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
702 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
703 sub_cmd
= (*ps_mode
) ? EN_AUTO_PS
: DIS_AUTO_PS
;
704 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
705 sub_cmd
, BITMAP_STA_PS
, NULL
);
706 if ((!ret
) && (sub_cmd
== DIS_AUTO_PS
))
707 ret
= mwifiex_send_cmd_async(priv
,
708 HostCmd_CMD_802_11_PS_MODE_ENH
,
715 * IOCTL request handler to set/reset WPA IE.
717 * The supplied WPA IE is treated as a opaque buffer. Only the first field
718 * is checked to determine WPA version. If buffer length is zero, the existing
721 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private
*priv
,
722 u8
*ie_data_ptr
, u16 ie_len
)
725 if (ie_len
> sizeof(priv
->wpa_ie
)) {
726 dev_err(priv
->adapter
->dev
,
727 "failed to copy WPA IE, too big\n");
730 memcpy(priv
->wpa_ie
, ie_data_ptr
, ie_len
);
731 priv
->wpa_ie_len
= (u8
) ie_len
;
732 dev_dbg(priv
->adapter
->dev
, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
733 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
735 if (priv
->wpa_ie
[0] == WLAN_EID_VENDOR_SPECIFIC
) {
736 priv
->sec_info
.wpa_enabled
= true;
737 } else if (priv
->wpa_ie
[0] == WLAN_EID_RSN
) {
738 priv
->sec_info
.wpa2_enabled
= true;
740 priv
->sec_info
.wpa_enabled
= false;
741 priv
->sec_info
.wpa2_enabled
= false;
744 memset(priv
->wpa_ie
, 0, sizeof(priv
->wpa_ie
));
745 priv
->wpa_ie_len
= 0;
746 dev_dbg(priv
->adapter
->dev
, "info: reset wpa_ie_len=%d IE=%#x\n",
747 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
748 priv
->sec_info
.wpa_enabled
= false;
749 priv
->sec_info
.wpa2_enabled
= false;
756 * IOCTL request handler to set/reset WAPI IE.
758 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
759 * is checked to internally enable WAPI. If buffer length is zero, the existing
762 static int mwifiex_set_wapi_ie(struct mwifiex_private
*priv
,
763 u8
*ie_data_ptr
, u16 ie_len
)
766 if (ie_len
> sizeof(priv
->wapi_ie
)) {
767 dev_dbg(priv
->adapter
->dev
,
768 "info: failed to copy WAPI IE, too big\n");
771 memcpy(priv
->wapi_ie
, ie_data_ptr
, ie_len
);
772 priv
->wapi_ie_len
= ie_len
;
773 dev_dbg(priv
->adapter
->dev
, "cmd: Set wapi_ie_len=%d IE=%#x\n",
774 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
776 if (priv
->wapi_ie
[0] == WLAN_EID_BSS_AC_ACCESS_DELAY
)
777 priv
->sec_info
.wapi_enabled
= true;
779 memset(priv
->wapi_ie
, 0, sizeof(priv
->wapi_ie
));
780 priv
->wapi_ie_len
= ie_len
;
781 dev_dbg(priv
->adapter
->dev
,
782 "info: Reset wapi_ie_len=%d IE=%#x\n",
783 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
784 priv
->sec_info
.wapi_enabled
= false;
790 * IOCTL request handler to set/reset WPS IE.
792 * The supplied WPS IE is treated as a opaque buffer. Only the first field
793 * is checked to internally enable WPS. If buffer length is zero, the existing
796 static int mwifiex_set_wps_ie(struct mwifiex_private
*priv
,
797 u8
*ie_data_ptr
, u16 ie_len
)
800 priv
->wps_ie
= kzalloc(MWIFIEX_MAX_VSIE_LEN
, GFP_KERNEL
);
803 if (ie_len
> sizeof(priv
->wps_ie
)) {
804 dev_dbg(priv
->adapter
->dev
,
805 "info: failed to copy WPS IE, too big\n");
809 memcpy(priv
->wps_ie
, ie_data_ptr
, ie_len
);
810 priv
->wps_ie_len
= ie_len
;
811 dev_dbg(priv
->adapter
->dev
, "cmd: Set wps_ie_len=%d IE=%#x\n",
812 priv
->wps_ie_len
, priv
->wps_ie
[0]);
815 priv
->wps_ie_len
= ie_len
;
816 dev_dbg(priv
->adapter
->dev
,
817 "info: Reset wps_ie_len=%d\n", priv
->wps_ie_len
);
823 * IOCTL request handler to set WAPI key.
825 * This function prepares the correct firmware command and
828 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private
*priv
,
829 struct mwifiex_ds_encrypt_key
*encrypt_key
)
832 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_KEY_MATERIAL
,
833 HostCmd_ACT_GEN_SET
, KEY_INFO_ENABLED
,
838 * IOCTL request handler to set WEP network key.
840 * This function prepares the correct firmware command and
841 * issues it, after validation checks.
843 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private
*priv
,
844 struct mwifiex_ds_encrypt_key
*encrypt_key
)
847 struct mwifiex_wep_key
*wep_key
;
850 if (priv
->wep_key_curr_index
>= NUM_WEP_KEYS
)
851 priv
->wep_key_curr_index
= 0;
852 wep_key
= &priv
->wep_key
[priv
->wep_key_curr_index
];
853 index
= encrypt_key
->key_index
;
854 if (encrypt_key
->key_disable
) {
855 priv
->sec_info
.wep_enabled
= 0;
856 } else if (!encrypt_key
->key_len
) {
857 /* Copy the required key as the current key */
858 wep_key
= &priv
->wep_key
[index
];
859 if (!wep_key
->key_length
) {
860 dev_err(priv
->adapter
->dev
,
861 "key not set, so cannot enable it\n");
864 priv
->wep_key_curr_index
= (u16
) index
;
865 priv
->sec_info
.wep_enabled
= 1;
867 wep_key
= &priv
->wep_key
[index
];
868 memset(wep_key
, 0, sizeof(struct mwifiex_wep_key
));
869 /* Copy the key in the driver */
870 memcpy(wep_key
->key_material
,
871 encrypt_key
->key_material
,
872 encrypt_key
->key_len
);
873 wep_key
->key_index
= index
;
874 wep_key
->key_length
= encrypt_key
->key_len
;
875 priv
->sec_info
.wep_enabled
= 1;
877 if (wep_key
->key_length
) {
878 /* Send request to firmware */
879 ret
= mwifiex_send_cmd_async(priv
,
880 HostCmd_CMD_802_11_KEY_MATERIAL
,
881 HostCmd_ACT_GEN_SET
, 0, NULL
);
885 if (priv
->sec_info
.wep_enabled
)
886 priv
->curr_pkt_filter
|= HostCmd_ACT_MAC_WEP_ENABLE
;
888 priv
->curr_pkt_filter
&= ~HostCmd_ACT_MAC_WEP_ENABLE
;
890 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_MAC_CONTROL
,
891 HostCmd_ACT_GEN_SET
, 0,
892 &priv
->curr_pkt_filter
);
898 * IOCTL request handler to set WPA key.
900 * This function prepares the correct firmware command and
901 * issues it, after validation checks.
903 * Current driver only supports key length of up to 32 bytes.
905 * This function can also be used to disable a currently set key.
907 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private
*priv
,
908 struct mwifiex_ds_encrypt_key
*encrypt_key
)
911 u8 remove_key
= false;
912 struct host_cmd_ds_802_11_key_material
*ibss_key
;
914 /* Current driver only supports key length of up to 32 bytes */
915 if (encrypt_key
->key_len
> WLAN_MAX_KEY_LEN
) {
916 dev_err(priv
->adapter
->dev
, "key length too long\n");
920 if (priv
->bss_mode
== NL80211_IFTYPE_ADHOC
) {
922 * IBSS/WPA-None uses only one key (Group) for both receiving
923 * and sending unicast and multicast packets.
925 /* Send the key as PTK to firmware */
926 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
927 ret
= mwifiex_send_cmd_async(priv
,
928 HostCmd_CMD_802_11_KEY_MATERIAL
,
930 KEY_INFO_ENABLED
, encrypt_key
);
934 ibss_key
= &priv
->aes_key
;
936 sizeof(struct host_cmd_ds_802_11_key_material
));
937 /* Copy the key in the driver */
938 memcpy(ibss_key
->key_param_set
.key
, encrypt_key
->key_material
,
939 encrypt_key
->key_len
);
940 memcpy(&ibss_key
->key_param_set
.key_len
, &encrypt_key
->key_len
,
941 sizeof(ibss_key
->key_param_set
.key_len
));
942 ibss_key
->key_param_set
.key_type_id
943 = cpu_to_le16(KEY_TYPE_ID_TKIP
);
944 ibss_key
->key_param_set
.key_info
= cpu_to_le16(KEY_ENABLED
);
946 /* Send the key as GTK to firmware */
947 encrypt_key
->key_index
= ~MWIFIEX_KEY_INDEX_UNICAST
;
950 if (!encrypt_key
->key_index
)
951 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
954 ret
= mwifiex_send_cmd_sync(priv
,
955 HostCmd_CMD_802_11_KEY_MATERIAL
,
957 !KEY_INFO_ENABLED
, encrypt_key
);
959 ret
= mwifiex_send_cmd_sync(priv
,
960 HostCmd_CMD_802_11_KEY_MATERIAL
,
962 KEY_INFO_ENABLED
, encrypt_key
);
968 * IOCTL request handler to set/get network keys.
970 * This is a generic key handling function which supports WEP, WPA
974 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private
*priv
,
975 struct mwifiex_ds_encrypt_key
*encrypt_key
)
979 if (encrypt_key
->is_wapi_key
)
980 status
= mwifiex_sec_ioctl_set_wapi_key(priv
, encrypt_key
);
981 else if (encrypt_key
->key_len
> WLAN_KEY_LEN_WEP104
)
982 status
= mwifiex_sec_ioctl_set_wpa_key(priv
, encrypt_key
);
984 status
= mwifiex_sec_ioctl_set_wep_key(priv
, encrypt_key
);
989 * This function returns the driver version.
992 mwifiex_drv_get_driver_version(struct mwifiex_adapter
*adapter
, char *version
,
1001 ver
.l
= adapter
->fw_release_number
;
1002 sprintf(fw_ver
, "%u.%u.%u.p%u", ver
.c
[2], ver
.c
[1], ver
.c
[0], ver
.c
[3]);
1004 snprintf(version
, max_len
, driver_version
, fw_ver
);
1006 dev_dbg(adapter
->dev
, "info: MWIFIEX VERSION: %s\n", version
);
1012 * Sends IOCTL request to set encoding parameters.
1014 * This function allocates the IOCTL request buffer, fills it
1015 * with requisite parameters and calls the IOCTL handler.
1017 int mwifiex_set_encode(struct mwifiex_private
*priv
, struct key_params
*kp
,
1018 const u8
*key
, int key_len
, u8 key_index
,
1019 const u8
*mac_addr
, int disable
)
1021 struct mwifiex_ds_encrypt_key encrypt_key
;
1023 memset(&encrypt_key
, 0, sizeof(struct mwifiex_ds_encrypt_key
));
1024 encrypt_key
.key_len
= key_len
;
1026 if (kp
&& kp
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
1027 encrypt_key
.is_igtk_key
= true;
1030 encrypt_key
.key_index
= key_index
;
1032 memcpy(encrypt_key
.key_material
, key
, key_len
);
1034 memcpy(encrypt_key
.mac_addr
, mac_addr
, ETH_ALEN
);
1035 if (kp
&& kp
->seq
&& kp
->seq_len
)
1036 memcpy(encrypt_key
.pn
, kp
->seq
, kp
->seq_len
);
1038 encrypt_key
.key_disable
= true;
1040 memcpy(encrypt_key
.mac_addr
, mac_addr
, ETH_ALEN
);
1043 return mwifiex_sec_ioctl_encrypt_key(priv
, &encrypt_key
);
1047 * Sends IOCTL request to get extended version.
1049 * This function allocates the IOCTL request buffer, fills it
1050 * with requisite parameters and calls the IOCTL handler.
1053 mwifiex_get_ver_ext(struct mwifiex_private
*priv
)
1055 struct mwifiex_ver_ext ver_ext
;
1057 memset(&ver_ext
, 0, sizeof(struct host_cmd_ds_version_ext
));
1058 if (mwifiex_send_cmd_sync(priv
, HostCmd_CMD_VERSION_EXT
,
1059 HostCmd_ACT_GEN_GET
, 0, &ver_ext
))
1066 mwifiex_remain_on_chan_cfg(struct mwifiex_private
*priv
, u16 action
,
1067 struct ieee80211_channel
*chan
,
1068 unsigned int duration
)
1070 struct host_cmd_ds_remain_on_chan roc_cfg
;
1073 memset(&roc_cfg
, 0, sizeof(roc_cfg
));
1074 roc_cfg
.action
= cpu_to_le16(action
);
1075 if (action
== HostCmd_ACT_GEN_SET
) {
1076 roc_cfg
.band_cfg
= chan
->band
;
1077 sc
= mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT
);
1078 roc_cfg
.band_cfg
|= (sc
<< 2);
1081 ieee80211_frequency_to_channel(chan
->center_freq
);
1082 roc_cfg
.duration
= cpu_to_le32(duration
);
1084 if (mwifiex_send_cmd_sync(priv
, HostCmd_CMD_REMAIN_ON_CHAN
,
1085 action
, 0, &roc_cfg
)) {
1086 dev_err(priv
->adapter
->dev
, "failed to remain on channel\n");
1090 return roc_cfg
.status
;
1094 mwifiex_set_bss_role(struct mwifiex_private
*priv
, u8 bss_role
)
1096 if (GET_BSS_ROLE(priv
) == bss_role
) {
1097 dev_dbg(priv
->adapter
->dev
,
1098 "info: already in the desired role.\n");
1102 mwifiex_free_priv(priv
);
1103 mwifiex_init_priv(priv
);
1105 priv
->bss_role
= bss_role
;
1107 case MWIFIEX_BSS_ROLE_UAP
:
1108 priv
->bss_mode
= NL80211_IFTYPE_AP
;
1110 case MWIFIEX_BSS_ROLE_STA
:
1111 case MWIFIEX_BSS_ROLE_ANY
:
1113 priv
->bss_mode
= NL80211_IFTYPE_STATION
;
1117 mwifiex_send_cmd_sync(priv
, HostCmd_CMD_SET_BSS_MODE
,
1118 HostCmd_ACT_GEN_SET
, 0, NULL
);
1120 return mwifiex_sta_init_cmd(priv
, false);
1124 * Sends IOCTL request to get statistics information.
1126 * This function allocates the IOCTL request buffer, fills it
1127 * with requisite parameters and calls the IOCTL handler.
1130 mwifiex_get_stats_info(struct mwifiex_private
*priv
,
1131 struct mwifiex_ds_get_stats
*log
)
1133 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_GET_LOG
,
1134 HostCmd_ACT_GEN_GET
, 0, log
);
1138 * IOCTL request handler to read/write register.
1140 * This function prepares the correct firmware command and
1143 * Access to the following registers are supported -
1150 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private
*priv
,
1151 struct mwifiex_ds_reg_rw
*reg_rw
,
1156 switch (le32_to_cpu(reg_rw
->type
)) {
1157 case MWIFIEX_REG_MAC
:
1158 cmd_no
= HostCmd_CMD_MAC_REG_ACCESS
;
1160 case MWIFIEX_REG_BBP
:
1161 cmd_no
= HostCmd_CMD_BBP_REG_ACCESS
;
1163 case MWIFIEX_REG_RF
:
1164 cmd_no
= HostCmd_CMD_RF_REG_ACCESS
;
1166 case MWIFIEX_REG_PMIC
:
1167 cmd_no
= HostCmd_CMD_PMIC_REG_ACCESS
;
1169 case MWIFIEX_REG_CAU
:
1170 cmd_no
= HostCmd_CMD_CAU_REG_ACCESS
;
1176 return mwifiex_send_cmd_sync(priv
, cmd_no
, action
, 0, reg_rw
);
1181 * Sends IOCTL request to write to a register.
1183 * This function allocates the IOCTL request buffer, fills it
1184 * with requisite parameters and calls the IOCTL handler.
1187 mwifiex_reg_write(struct mwifiex_private
*priv
, u32 reg_type
,
1188 u32 reg_offset
, u32 reg_value
)
1190 struct mwifiex_ds_reg_rw reg_rw
;
1192 reg_rw
.type
= cpu_to_le32(reg_type
);
1193 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1194 reg_rw
.value
= cpu_to_le32(reg_value
);
1196 return mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_SET
);
1200 * Sends IOCTL request to read from a register.
1202 * This function allocates the IOCTL request buffer, fills it
1203 * with requisite parameters and calls the IOCTL handler.
1206 mwifiex_reg_read(struct mwifiex_private
*priv
, u32 reg_type
,
1207 u32 reg_offset
, u32
*value
)
1210 struct mwifiex_ds_reg_rw reg_rw
;
1212 reg_rw
.type
= cpu_to_le32(reg_type
);
1213 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1214 ret
= mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_GET
);
1219 *value
= le32_to_cpu(reg_rw
.value
);
1226 * Sends IOCTL request to read from EEPROM.
1228 * This function allocates the IOCTL request buffer, fills it
1229 * with requisite parameters and calls the IOCTL handler.
1232 mwifiex_eeprom_read(struct mwifiex_private
*priv
, u16 offset
, u16 bytes
,
1236 struct mwifiex_ds_read_eeprom rd_eeprom
;
1238 rd_eeprom
.offset
= cpu_to_le16((u16
) offset
);
1239 rd_eeprom
.byte_count
= cpu_to_le16((u16
) bytes
);
1241 /* Send request to firmware */
1242 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_EEPROM_ACCESS
,
1243 HostCmd_ACT_GEN_GET
, 0, &rd_eeprom
);
1246 memcpy(value
, rd_eeprom
.value
, MAX_EEPROM_DATA
);
1251 * This function sets a generic IE. In addition to generic IE, it can
1252 * also handle WPA, WPA2 and WAPI IEs.
1255 mwifiex_set_gen_ie_helper(struct mwifiex_private
*priv
, u8
*ie_data_ptr
,
1259 struct ieee_types_vendor_header
*pvendor_ie
;
1260 const u8 wpa_oui
[] = { 0x00, 0x50, 0xf2, 0x01 };
1261 const u8 wps_oui
[] = { 0x00, 0x50, 0xf2, 0x04 };
1263 /* If the passed length is zero, reset the buffer */
1265 priv
->gen_ie_buf_len
= 0;
1266 priv
->wps
.session_enable
= false;
1269 } else if (!ie_data_ptr
) {
1272 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1273 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1274 if (((pvendor_ie
->element_id
== WLAN_EID_VENDOR_SPECIFIC
) &&
1275 (!memcmp(pvendor_ie
->oui
, wpa_oui
, sizeof(wpa_oui
)))) ||
1276 (pvendor_ie
->element_id
== WLAN_EID_RSN
)) {
1278 /* IE is a WPA/WPA2 IE so call set_wpa function */
1279 ret
= mwifiex_set_wpa_ie_helper(priv
, ie_data_ptr
, ie_len
);
1280 priv
->wps
.session_enable
= false;
1283 } else if (pvendor_ie
->element_id
== WLAN_EID_BSS_AC_ACCESS_DELAY
) {
1284 /* IE is a WAPI IE so call set_wapi function */
1285 ret
= mwifiex_set_wapi_ie(priv
, ie_data_ptr
, ie_len
);
1290 * Verify that the passed length is not larger than the
1291 * available space remaining in the buffer
1293 if (ie_len
< (sizeof(priv
->gen_ie_buf
) - priv
->gen_ie_buf_len
)) {
1295 /* Test to see if it is a WPS IE, if so, enable
1298 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1299 if ((pvendor_ie
->element_id
== WLAN_EID_VENDOR_SPECIFIC
) &&
1300 (!memcmp(pvendor_ie
->oui
, wps_oui
, sizeof(wps_oui
)))) {
1301 priv
->wps
.session_enable
= true;
1302 dev_dbg(priv
->adapter
->dev
,
1303 "info: WPS Session Enabled.\n");
1304 ret
= mwifiex_set_wps_ie(priv
, ie_data_ptr
, ie_len
);
1307 /* Append the passed data to the end of the
1309 memcpy(priv
->gen_ie_buf
+ priv
->gen_ie_buf_len
, ie_data_ptr
,
1311 /* Increment the stored buffer length by the
1313 priv
->gen_ie_buf_len
+= ie_len
;
1315 /* Passed data does not fit in the remaining
1320 /* Return 0, or -1 for error case */
1325 * IOCTL request handler to set/get generic IE.
1327 * In addition to various generic IEs, this function can also be
1328 * used to set the ARP filter.
1330 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private
*priv
,
1331 struct mwifiex_ds_misc_gen_ie
*gen_ie
,
1334 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1336 switch (gen_ie
->type
) {
1337 case MWIFIEX_IE_TYPE_GEN_IE
:
1338 if (action
== HostCmd_ACT_GEN_GET
) {
1339 gen_ie
->len
= priv
->wpa_ie_len
;
1340 memcpy(gen_ie
->ie_data
, priv
->wpa_ie
, gen_ie
->len
);
1342 mwifiex_set_gen_ie_helper(priv
, gen_ie
->ie_data
,
1346 case MWIFIEX_IE_TYPE_ARP_FILTER
:
1347 memset(adapter
->arp_filter
, 0, sizeof(adapter
->arp_filter
));
1348 if (gen_ie
->len
> ARP_FILTER_MAX_BUF_SIZE
) {
1349 adapter
->arp_filter_size
= 0;
1350 dev_err(adapter
->dev
, "invalid ARP filter size\n");
1353 memcpy(adapter
->arp_filter
, gen_ie
->ie_data
,
1355 adapter
->arp_filter_size
= gen_ie
->len
;
1359 dev_err(adapter
->dev
, "invalid IE type\n");
1366 * Sends IOCTL request to set a generic IE.
1368 * This function allocates the IOCTL request buffer, fills it
1369 * with requisite parameters and calls the IOCTL handler.
1372 mwifiex_set_gen_ie(struct mwifiex_private
*priv
, u8
*ie
, int ie_len
)
1374 struct mwifiex_ds_misc_gen_ie gen_ie
;
1376 if (ie_len
> IEEE_MAX_IE_SIZE
)
1379 gen_ie
.type
= MWIFIEX_IE_TYPE_GEN_IE
;
1380 gen_ie
.len
= ie_len
;
1381 memcpy(gen_ie
.ie_data
, ie
, ie_len
);
1382 if (mwifiex_misc_ioctl_gen_ie(priv
, &gen_ie
, HostCmd_ACT_GEN_SET
))