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 dev_dbg(adapter
->dev
, "cmd pending\n");
63 atomic_inc(&adapter
->cmd_pending
);
65 /* Wait for completion */
66 status
= wait_event_interruptible(adapter
->cmd_wait_q
.wait
,
67 *(cmd_queued
->condition
));
69 dev_err(adapter
->dev
, "cmd_wait_q terminated: %d\n", status
);
73 status
= adapter
->cmd_wait_q
.status
;
74 adapter
->cmd_wait_q
.status
= 0;
80 * This function prepares the correct firmware command and
81 * issues it to set the multicast list.
83 * This function can be used to enable promiscuous mode, or enable all
84 * multicast packets, or to enable selective multicast.
86 int mwifiex_request_set_multicast_list(struct mwifiex_private
*priv
,
87 struct mwifiex_multicast_list
*mcast_list
)
92 old_pkt_filter
= priv
->curr_pkt_filter
;
94 if (mcast_list
->mode
== MWIFIEX_PROMISC_MODE
) {
95 dev_dbg(priv
->adapter
->dev
, "info: Enable Promiscuous mode\n");
96 priv
->curr_pkt_filter
|= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE
;
97 priv
->curr_pkt_filter
&=
98 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
101 priv
->curr_pkt_filter
&= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE
;
102 if (mcast_list
->mode
== MWIFIEX_MULTICAST_MODE
) {
103 dev_dbg(priv
->adapter
->dev
,
104 "info: Enabling All Multicast!\n");
105 priv
->curr_pkt_filter
|=
106 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
108 priv
->curr_pkt_filter
&=
109 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
110 if (mcast_list
->num_multicast_addr
) {
111 dev_dbg(priv
->adapter
->dev
,
112 "info: Set multicast list=%d\n",
113 mcast_list
->num_multicast_addr
);
114 /* Set multicast addresses to firmware */
115 if (old_pkt_filter
== priv
->curr_pkt_filter
) {
116 /* Send request to firmware */
117 ret
= mwifiex_send_cmd_async(priv
,
118 HostCmd_CMD_MAC_MULTICAST_ADR
,
119 HostCmd_ACT_GEN_SET
, 0,
122 /* Send request to firmware */
123 ret
= mwifiex_send_cmd_async(priv
,
124 HostCmd_CMD_MAC_MULTICAST_ADR
,
125 HostCmd_ACT_GEN_SET
, 0,
131 dev_dbg(priv
->adapter
->dev
,
132 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
133 old_pkt_filter
, priv
->curr_pkt_filter
);
134 if (old_pkt_filter
!= priv
->curr_pkt_filter
) {
135 ret
= mwifiex_send_cmd_async(priv
, HostCmd_CMD_MAC_CONTROL
,
137 0, &priv
->curr_pkt_filter
);
144 * This function fills bss descriptor structure using provided
147 int mwifiex_fill_new_bss_desc(struct mwifiex_private
*priv
,
148 struct cfg80211_bss
*bss
,
149 struct mwifiex_bssdescriptor
*bss_desc
)
153 size_t beacon_ie_len
;
154 struct mwifiex_bss_priv
*bss_priv
= (void *)bss
->priv
;
155 const struct cfg80211_bss_ies
*ies
;
158 ies
= rcu_dereference(bss
->ies
);
159 beacon_ie
= kmemdup(ies
->data
, ies
->len
, GFP_ATOMIC
);
160 beacon_ie_len
= ies
->len
;
161 bss_desc
->timestamp
= ies
->tsf
;
165 dev_err(priv
->adapter
->dev
, " failed to alloc beacon_ie\n");
169 memcpy(bss_desc
->mac_address
, bss
->bssid
, ETH_ALEN
);
170 bss_desc
->rssi
= bss
->signal
;
171 bss_desc
->beacon_buf
= beacon_ie
;
172 bss_desc
->beacon_buf_size
= beacon_ie_len
;
173 bss_desc
->beacon_period
= bss
->beacon_interval
;
174 bss_desc
->cap_info_bitmap
= bss
->capability
;
175 bss_desc
->bss_band
= bss_priv
->band
;
176 bss_desc
->fw_tsf
= bss_priv
->fw_tsf
;
177 if (bss_desc
->cap_info_bitmap
& WLAN_CAPABILITY_PRIVACY
) {
178 dev_dbg(priv
->adapter
->dev
, "info: InterpretIE: AP WEP enabled\n");
179 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_8021X_WEP
;
181 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL
;
183 if (bss_desc
->cap_info_bitmap
& WLAN_CAPABILITY_IBSS
)
184 bss_desc
->bss_mode
= NL80211_IFTYPE_ADHOC
;
186 bss_desc
->bss_mode
= NL80211_IFTYPE_STATION
;
188 ret
= mwifiex_update_bss_desc_with_ie(priv
->adapter
, bss_desc
);
194 static int mwifiex_process_country_ie(struct mwifiex_private
*priv
,
195 struct cfg80211_bss
*bss
)
197 const u8
*country_ie
;
199 struct mwifiex_802_11d_domain_reg
*domain_info
=
200 &priv
->adapter
->domain_reg
;
203 country_ie
= ieee80211_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
209 country_ie_len
= country_ie
[1];
210 if (country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
) {
215 domain_info
->country_code
[0] = country_ie
[2];
216 domain_info
->country_code
[1] = country_ie
[3];
217 domain_info
->country_code
[2] = ' ';
219 country_ie_len
-= IEEE80211_COUNTRY_STRING_LEN
;
221 domain_info
->no_of_triplet
=
222 country_ie_len
/ sizeof(struct ieee80211_country_ie_triplet
);
224 memcpy((u8
*)domain_info
->triplet
,
225 &country_ie
[2] + IEEE80211_COUNTRY_STRING_LEN
, country_ie_len
);
229 if (mwifiex_send_cmd_async(priv
, HostCmd_CMD_802_11D_DOMAIN_INFO
,
230 HostCmd_ACT_GEN_SET
, 0, NULL
)) {
231 wiphy_err(priv
->adapter
->wiphy
,
232 "11D: setting domain info in FW\n");
240 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
241 * In both Ad-Hoc and infra mode, an deauthentication is performed
244 int mwifiex_bss_start(struct mwifiex_private
*priv
, struct cfg80211_bss
*bss
,
245 struct cfg80211_ssid
*req_ssid
)
248 struct mwifiex_adapter
*adapter
= priv
->adapter
;
249 struct mwifiex_bssdescriptor
*bss_desc
= NULL
;
251 priv
->scan_block
= false;
254 mwifiex_process_country_ie(priv
, bss
);
256 /* Allocate and fill new bss descriptor */
257 bss_desc
= kzalloc(sizeof(struct mwifiex_bssdescriptor
),
262 ret
= mwifiex_fill_new_bss_desc(priv
, bss
, bss_desc
);
267 if (priv
->bss_mode
== NL80211_IFTYPE_STATION
) {
269 ret
= mwifiex_deauthenticate(priv
, NULL
);
276 if (mwifiex_band_to_radio_type((u8
) bss_desc
->bss_band
)
277 == HostCmd_SCAN_RADIO_TYPE_BG
)
278 config_bands
= BAND_B
| BAND_G
| BAND_GN
|
281 config_bands
= BAND_A
| BAND_AN
| BAND_AAC
;
283 if (!((config_bands
| adapter
->fw_bands
) &
285 adapter
->config_bands
= config_bands
;
288 ret
= mwifiex_check_network_compatibility(priv
, bss_desc
);
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
);
360 * IOCTL request handler to set host sleep configuration.
362 * This function prepares the correct firmware command and
365 static int mwifiex_set_hs_params(struct mwifiex_private
*priv
, u16 action
,
366 int cmd_type
, struct mwifiex_ds_hs_cfg
*hs_cfg
)
369 struct mwifiex_adapter
*adapter
= priv
->adapter
;
377 case HostCmd_ACT_GEN_SET
:
378 if (adapter
->pps_uapsd_mode
) {
379 dev_dbg(adapter
->dev
, "info: Host Sleep IOCTL"
380 " is blocked in UAPSD/PPS mode\n");
384 if (hs_cfg
->is_invoke_hostcmd
) {
385 if (hs_cfg
->conditions
== HOST_SLEEP_CFG_CANCEL
) {
386 if (!adapter
->is_hs_configured
)
387 /* Already cancelled */
389 /* Save previous condition */
390 prev_cond
= le32_to_cpu(adapter
->hs_cfg
392 adapter
->hs_cfg
.conditions
=
393 cpu_to_le32(hs_cfg
->conditions
);
394 } else if (hs_cfg
->conditions
) {
395 adapter
->hs_cfg
.conditions
=
396 cpu_to_le32(hs_cfg
->conditions
);
397 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
399 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
400 } else if (adapter
->hs_cfg
.conditions
401 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL
)) {
402 /* Return failure if no parameters for HS
407 if (cmd_type
== MWIFIEX_SYNC_CMD
)
408 status
= mwifiex_send_cmd_sync(priv
,
409 HostCmd_CMD_802_11_HS_CFG_ENH
,
410 HostCmd_ACT_GEN_SET
, 0,
413 status
= mwifiex_send_cmd_async(priv
,
414 HostCmd_CMD_802_11_HS_CFG_ENH
,
415 HostCmd_ACT_GEN_SET
, 0,
417 if (hs_cfg
->conditions
== HOST_SLEEP_CFG_CANCEL
)
418 /* Restore previous condition */
419 adapter
->hs_cfg
.conditions
=
420 cpu_to_le32(prev_cond
);
422 adapter
->hs_cfg
.conditions
=
423 cpu_to_le32(hs_cfg
->conditions
);
424 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
425 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
428 case HostCmd_ACT_GEN_GET
:
429 hs_cfg
->conditions
= le32_to_cpu(adapter
->hs_cfg
.conditions
);
430 hs_cfg
->gpio
= adapter
->hs_cfg
.gpio
;
431 hs_cfg
->gap
= adapter
->hs_cfg
.gap
;
442 * Sends IOCTL request to cancel the existing Host Sleep configuration.
444 * This function allocates the IOCTL request buffer, fills it
445 * with requisite parameters and calls the IOCTL handler.
447 int mwifiex_cancel_hs(struct mwifiex_private
*priv
, int cmd_type
)
449 struct mwifiex_ds_hs_cfg hscfg
;
451 hscfg
.conditions
= HOST_SLEEP_CFG_CANCEL
;
452 hscfg
.is_invoke_hostcmd
= true;
454 return mwifiex_set_hs_params(priv
, HostCmd_ACT_GEN_SET
,
457 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs
);
460 * Sends IOCTL request to cancel the existing Host Sleep configuration.
462 * This function allocates the IOCTL request buffer, fills it
463 * with requisite parameters and calls the IOCTL handler.
465 int mwifiex_enable_hs(struct mwifiex_adapter
*adapter
)
467 struct mwifiex_ds_hs_cfg hscfg
;
468 struct mwifiex_private
*priv
;
471 if (disconnect_on_suspend
) {
472 for (i
= 0; i
< adapter
->priv_num
; i
++) {
473 priv
= adapter
->priv
[i
];
475 mwifiex_deauthenticate(priv
, NULL
);
479 if (adapter
->hs_activated
) {
480 dev_dbg(adapter
->dev
, "cmd: HS Already activated\n");
484 adapter
->hs_activate_wait_q_woken
= false;
486 memset(&hscfg
, 0, sizeof(struct mwifiex_ds_hs_cfg
));
487 hscfg
.is_invoke_hostcmd
= true;
489 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter
,
490 MWIFIEX_BSS_ROLE_STA
),
491 HostCmd_ACT_GEN_SET
, MWIFIEX_SYNC_CMD
,
493 dev_err(adapter
->dev
, "IOCTL request HS enable failed\n");
497 if (wait_event_interruptible(adapter
->hs_activate_wait_q
,
498 adapter
->hs_activate_wait_q_woken
)) {
499 dev_err(adapter
->dev
, "hs_activate_wait_q terminated\n");
505 EXPORT_SYMBOL_GPL(mwifiex_enable_hs
);
508 * IOCTL request handler to get BSS information.
510 * This function collates the information from different driver structures
511 * to send to the user.
513 int mwifiex_get_bss_info(struct mwifiex_private
*priv
,
514 struct mwifiex_bss_info
*info
)
516 struct mwifiex_adapter
*adapter
= priv
->adapter
;
517 struct mwifiex_bssdescriptor
*bss_desc
;
522 bss_desc
= &priv
->curr_bss_params
.bss_descriptor
;
524 info
->bss_mode
= priv
->bss_mode
;
526 memcpy(&info
->ssid
, &bss_desc
->ssid
, sizeof(struct cfg80211_ssid
));
528 memcpy(&info
->bssid
, &bss_desc
->mac_address
, ETH_ALEN
);
530 info
->bss_chan
= bss_desc
->channel
;
532 memcpy(info
->country_code
, adapter
->country_code
,
533 IEEE80211_COUNTRY_STRING_LEN
);
535 info
->media_connected
= priv
->media_connected
;
537 info
->max_power_level
= priv
->max_tx_power_level
;
538 info
->min_power_level
= priv
->min_tx_power_level
;
540 info
->adhoc_state
= priv
->adhoc_state
;
542 info
->bcn_nf_last
= priv
->bcn_nf_last
;
544 if (priv
->sec_info
.wep_enabled
)
545 info
->wep_status
= true;
547 info
->wep_status
= false;
549 info
->is_hs_configured
= adapter
->is_hs_configured
;
550 info
->is_deep_sleep
= adapter
->is_deep_sleep
;
556 * The function disables auto deep sleep mode.
558 int mwifiex_disable_auto_ds(struct mwifiex_private
*priv
)
560 struct mwifiex_ds_auto_ds auto_ds
;
562 auto_ds
.auto_ds
= DEEP_SLEEP_OFF
;
564 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
565 DIS_AUTO_PS
, BITMAP_AUTO_DS
, &auto_ds
);
567 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds
);
570 * Sends IOCTL request to get the data rate.
572 * This function allocates the IOCTL request buffer, fills it
573 * with requisite parameters and calls the IOCTL handler.
575 int mwifiex_drv_get_data_rate(struct mwifiex_private
*priv
, u32
*rate
)
579 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_TX_RATE_QUERY
,
580 HostCmd_ACT_GEN_GET
, 0, NULL
);
583 if (priv
->is_data_rate_auto
)
584 *rate
= mwifiex_index_to_data_rate(priv
, priv
->tx_rate
,
587 *rate
= priv
->data_rate
;
594 * IOCTL request handler to set tx power configuration.
596 * This function prepares the correct firmware command and
599 * For non-auto power mode, all the following power groups are set -
600 * - Modulation class HR/DSSS
601 * - Modulation class OFDM
602 * - Modulation class HTBW20
603 * - Modulation class HTBW40
605 int mwifiex_set_tx_power(struct mwifiex_private
*priv
,
606 struct mwifiex_power_cfg
*power_cfg
)
609 struct host_cmd_ds_txpwr_cfg
*txp_cfg
;
610 struct mwifiex_types_power_group
*pg_tlv
;
611 struct mwifiex_power_group
*pg
;
615 if (!power_cfg
->is_power_auto
) {
616 dbm
= (u16
) power_cfg
->power_level
;
617 if ((dbm
< priv
->min_tx_power_level
) ||
618 (dbm
> priv
->max_tx_power_level
)) {
619 dev_err(priv
->adapter
->dev
, "txpower value %d dBm"
620 " is out of range (%d dBm-%d dBm)\n",
621 dbm
, priv
->min_tx_power_level
,
622 priv
->max_tx_power_level
);
626 buf
= kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER
, GFP_KERNEL
);
630 txp_cfg
= (struct host_cmd_ds_txpwr_cfg
*) buf
;
631 txp_cfg
->action
= cpu_to_le16(HostCmd_ACT_GEN_SET
);
632 if (!power_cfg
->is_power_auto
) {
633 txp_cfg
->mode
= cpu_to_le32(1);
634 pg_tlv
= (struct mwifiex_types_power_group
*)
635 (buf
+ sizeof(struct host_cmd_ds_txpwr_cfg
));
636 pg_tlv
->type
= TLV_TYPE_POWER_GROUP
;
637 pg_tlv
->length
= 4 * sizeof(struct mwifiex_power_group
);
638 pg
= (struct mwifiex_power_group
*)
639 (buf
+ sizeof(struct host_cmd_ds_txpwr_cfg
)
640 + sizeof(struct mwifiex_types_power_group
));
641 /* Power group for modulation class HR/DSSS */
642 pg
->first_rate_code
= 0x00;
643 pg
->last_rate_code
= 0x03;
644 pg
->modulation_class
= MOD_CLASS_HR_DSSS
;
646 pg
->power_min
= (s8
) dbm
;
647 pg
->power_max
= (s8
) dbm
;
649 /* Power group for modulation class OFDM */
650 pg
->first_rate_code
= 0x00;
651 pg
->last_rate_code
= 0x07;
652 pg
->modulation_class
= MOD_CLASS_OFDM
;
654 pg
->power_min
= (s8
) dbm
;
655 pg
->power_max
= (s8
) dbm
;
657 /* Power group for modulation class HTBW20 */
658 pg
->first_rate_code
= 0x00;
659 pg
->last_rate_code
= 0x20;
660 pg
->modulation_class
= MOD_CLASS_HT
;
662 pg
->power_min
= (s8
) dbm
;
663 pg
->power_max
= (s8
) dbm
;
664 pg
->ht_bandwidth
= HT_BW_20
;
666 /* Power group for modulation class HTBW40 */
667 pg
->first_rate_code
= 0x00;
668 pg
->last_rate_code
= 0x20;
669 pg
->modulation_class
= MOD_CLASS_HT
;
671 pg
->power_min
= (s8
) dbm
;
672 pg
->power_max
= (s8
) dbm
;
673 pg
->ht_bandwidth
= HT_BW_40
;
675 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_TXPWR_CFG
,
676 HostCmd_ACT_GEN_SET
, 0, buf
);
683 * IOCTL request handler to get power save mode.
685 * This function prepares the correct firmware command and
688 int mwifiex_drv_set_power(struct mwifiex_private
*priv
, u32
*ps_mode
)
691 struct mwifiex_adapter
*adapter
= priv
->adapter
;
695 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
697 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
698 sub_cmd
= (*ps_mode
) ? EN_AUTO_PS
: DIS_AUTO_PS
;
699 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
700 sub_cmd
, BITMAP_STA_PS
, NULL
);
701 if ((!ret
) && (sub_cmd
== DIS_AUTO_PS
))
702 ret
= mwifiex_send_cmd_async(priv
,
703 HostCmd_CMD_802_11_PS_MODE_ENH
,
710 * IOCTL request handler to set/reset WPA IE.
712 * The supplied WPA IE is treated as a opaque buffer. Only the first field
713 * is checked to determine WPA version. If buffer length is zero, the existing
716 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private
*priv
,
717 u8
*ie_data_ptr
, u16 ie_len
)
720 if (ie_len
> sizeof(priv
->wpa_ie
)) {
721 dev_err(priv
->adapter
->dev
,
722 "failed to copy WPA IE, too big\n");
725 memcpy(priv
->wpa_ie
, ie_data_ptr
, ie_len
);
726 priv
->wpa_ie_len
= (u8
) ie_len
;
727 dev_dbg(priv
->adapter
->dev
, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
728 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
730 if (priv
->wpa_ie
[0] == WLAN_EID_VENDOR_SPECIFIC
) {
731 priv
->sec_info
.wpa_enabled
= true;
732 } else if (priv
->wpa_ie
[0] == WLAN_EID_RSN
) {
733 priv
->sec_info
.wpa2_enabled
= true;
735 priv
->sec_info
.wpa_enabled
= false;
736 priv
->sec_info
.wpa2_enabled
= false;
739 memset(priv
->wpa_ie
, 0, sizeof(priv
->wpa_ie
));
740 priv
->wpa_ie_len
= 0;
741 dev_dbg(priv
->adapter
->dev
, "info: reset wpa_ie_len=%d IE=%#x\n",
742 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
743 priv
->sec_info
.wpa_enabled
= false;
744 priv
->sec_info
.wpa2_enabled
= false;
751 * IOCTL request handler to set/reset WAPI IE.
753 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
754 * is checked to internally enable WAPI. If buffer length is zero, the existing
757 static int mwifiex_set_wapi_ie(struct mwifiex_private
*priv
,
758 u8
*ie_data_ptr
, u16 ie_len
)
761 if (ie_len
> sizeof(priv
->wapi_ie
)) {
762 dev_dbg(priv
->adapter
->dev
,
763 "info: failed to copy WAPI IE, too big\n");
766 memcpy(priv
->wapi_ie
, ie_data_ptr
, ie_len
);
767 priv
->wapi_ie_len
= ie_len
;
768 dev_dbg(priv
->adapter
->dev
, "cmd: Set wapi_ie_len=%d IE=%#x\n",
769 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
771 if (priv
->wapi_ie
[0] == WLAN_EID_BSS_AC_ACCESS_DELAY
)
772 priv
->sec_info
.wapi_enabled
= true;
774 memset(priv
->wapi_ie
, 0, sizeof(priv
->wapi_ie
));
775 priv
->wapi_ie_len
= ie_len
;
776 dev_dbg(priv
->adapter
->dev
,
777 "info: Reset wapi_ie_len=%d IE=%#x\n",
778 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
779 priv
->sec_info
.wapi_enabled
= false;
785 * IOCTL request handler to set/reset WPS IE.
787 * The supplied WPS IE is treated as a opaque buffer. Only the first field
788 * is checked to internally enable WPS. If buffer length is zero, the existing
791 static int mwifiex_set_wps_ie(struct mwifiex_private
*priv
,
792 u8
*ie_data_ptr
, u16 ie_len
)
795 priv
->wps_ie
= kzalloc(MWIFIEX_MAX_VSIE_LEN
, GFP_KERNEL
);
798 if (ie_len
> sizeof(priv
->wps_ie
)) {
799 dev_dbg(priv
->adapter
->dev
,
800 "info: failed to copy WPS IE, too big\n");
804 memcpy(priv
->wps_ie
, ie_data_ptr
, ie_len
);
805 priv
->wps_ie_len
= ie_len
;
806 dev_dbg(priv
->adapter
->dev
, "cmd: Set wps_ie_len=%d IE=%#x\n",
807 priv
->wps_ie_len
, priv
->wps_ie
[0]);
810 priv
->wps_ie_len
= ie_len
;
811 dev_dbg(priv
->adapter
->dev
,
812 "info: Reset wps_ie_len=%d\n", priv
->wps_ie_len
);
818 * IOCTL request handler to set WAPI key.
820 * This function prepares the correct firmware command and
823 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private
*priv
,
824 struct mwifiex_ds_encrypt_key
*encrypt_key
)
827 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_KEY_MATERIAL
,
828 HostCmd_ACT_GEN_SET
, KEY_INFO_ENABLED
,
833 * IOCTL request handler to set WEP network key.
835 * This function prepares the correct firmware command and
836 * issues it, after validation checks.
838 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private
*priv
,
839 struct mwifiex_ds_encrypt_key
*encrypt_key
)
842 struct mwifiex_wep_key
*wep_key
;
845 if (priv
->wep_key_curr_index
>= NUM_WEP_KEYS
)
846 priv
->wep_key_curr_index
= 0;
847 wep_key
= &priv
->wep_key
[priv
->wep_key_curr_index
];
848 index
= encrypt_key
->key_index
;
849 if (encrypt_key
->key_disable
) {
850 priv
->sec_info
.wep_enabled
= 0;
851 } else if (!encrypt_key
->key_len
) {
852 /* Copy the required key as the current key */
853 wep_key
= &priv
->wep_key
[index
];
854 if (!wep_key
->key_length
) {
855 dev_err(priv
->adapter
->dev
,
856 "key not set, so cannot enable it\n");
859 priv
->wep_key_curr_index
= (u16
) index
;
860 priv
->sec_info
.wep_enabled
= 1;
862 wep_key
= &priv
->wep_key
[index
];
863 memset(wep_key
, 0, sizeof(struct mwifiex_wep_key
));
864 /* Copy the key in the driver */
865 memcpy(wep_key
->key_material
,
866 encrypt_key
->key_material
,
867 encrypt_key
->key_len
);
868 wep_key
->key_index
= index
;
869 wep_key
->key_length
= encrypt_key
->key_len
;
870 priv
->sec_info
.wep_enabled
= 1;
872 if (wep_key
->key_length
) {
873 /* Send request to firmware */
874 ret
= mwifiex_send_cmd_async(priv
,
875 HostCmd_CMD_802_11_KEY_MATERIAL
,
876 HostCmd_ACT_GEN_SET
, 0, NULL
);
880 if (priv
->sec_info
.wep_enabled
)
881 priv
->curr_pkt_filter
|= HostCmd_ACT_MAC_WEP_ENABLE
;
883 priv
->curr_pkt_filter
&= ~HostCmd_ACT_MAC_WEP_ENABLE
;
885 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_MAC_CONTROL
,
886 HostCmd_ACT_GEN_SET
, 0,
887 &priv
->curr_pkt_filter
);
893 * IOCTL request handler to set WPA key.
895 * This function prepares the correct firmware command and
896 * issues it, after validation checks.
898 * Current driver only supports key length of up to 32 bytes.
900 * This function can also be used to disable a currently set key.
902 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private
*priv
,
903 struct mwifiex_ds_encrypt_key
*encrypt_key
)
906 u8 remove_key
= false;
907 struct host_cmd_ds_802_11_key_material
*ibss_key
;
909 /* Current driver only supports key length of up to 32 bytes */
910 if (encrypt_key
->key_len
> WLAN_MAX_KEY_LEN
) {
911 dev_err(priv
->adapter
->dev
, "key length too long\n");
915 if (priv
->bss_mode
== NL80211_IFTYPE_ADHOC
) {
917 * IBSS/WPA-None uses only one key (Group) for both receiving
918 * and sending unicast and multicast packets.
920 /* Send the key as PTK to firmware */
921 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
922 ret
= mwifiex_send_cmd_async(priv
,
923 HostCmd_CMD_802_11_KEY_MATERIAL
,
925 KEY_INFO_ENABLED
, encrypt_key
);
929 ibss_key
= &priv
->aes_key
;
931 sizeof(struct host_cmd_ds_802_11_key_material
));
932 /* Copy the key in the driver */
933 memcpy(ibss_key
->key_param_set
.key
, encrypt_key
->key_material
,
934 encrypt_key
->key_len
);
935 memcpy(&ibss_key
->key_param_set
.key_len
, &encrypt_key
->key_len
,
936 sizeof(ibss_key
->key_param_set
.key_len
));
937 ibss_key
->key_param_set
.key_type_id
938 = cpu_to_le16(KEY_TYPE_ID_TKIP
);
939 ibss_key
->key_param_set
.key_info
= cpu_to_le16(KEY_ENABLED
);
941 /* Send the key as GTK to firmware */
942 encrypt_key
->key_index
= ~MWIFIEX_KEY_INDEX_UNICAST
;
945 if (!encrypt_key
->key_index
)
946 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
949 ret
= mwifiex_send_cmd_sync(priv
,
950 HostCmd_CMD_802_11_KEY_MATERIAL
,
952 !KEY_INFO_ENABLED
, encrypt_key
);
954 ret
= mwifiex_send_cmd_sync(priv
,
955 HostCmd_CMD_802_11_KEY_MATERIAL
,
957 KEY_INFO_ENABLED
, encrypt_key
);
963 * IOCTL request handler to set/get network keys.
965 * This is a generic key handling function which supports WEP, WPA
969 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private
*priv
,
970 struct mwifiex_ds_encrypt_key
*encrypt_key
)
974 if (encrypt_key
->is_wapi_key
)
975 status
= mwifiex_sec_ioctl_set_wapi_key(priv
, encrypt_key
);
976 else if (encrypt_key
->key_len
> WLAN_KEY_LEN_WEP104
)
977 status
= mwifiex_sec_ioctl_set_wpa_key(priv
, encrypt_key
);
979 status
= mwifiex_sec_ioctl_set_wep_key(priv
, encrypt_key
);
984 * This function returns the driver version.
987 mwifiex_drv_get_driver_version(struct mwifiex_adapter
*adapter
, char *version
,
996 ver
.l
= adapter
->fw_release_number
;
997 sprintf(fw_ver
, "%u.%u.%u.p%u", ver
.c
[2], ver
.c
[1], ver
.c
[0], ver
.c
[3]);
999 snprintf(version
, max_len
, driver_version
, fw_ver
);
1001 dev_dbg(adapter
->dev
, "info: MWIFIEX VERSION: %s\n", version
);
1007 * Sends IOCTL request to set encoding parameters.
1009 * This function allocates the IOCTL request buffer, fills it
1010 * with requisite parameters and calls the IOCTL handler.
1012 int mwifiex_set_encode(struct mwifiex_private
*priv
, struct key_params
*kp
,
1013 const u8
*key
, int key_len
, u8 key_index
,
1014 const u8
*mac_addr
, int disable
)
1016 struct mwifiex_ds_encrypt_key encrypt_key
;
1018 memset(&encrypt_key
, 0, sizeof(struct mwifiex_ds_encrypt_key
));
1019 encrypt_key
.key_len
= key_len
;
1021 if (kp
&& kp
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
1022 encrypt_key
.is_igtk_key
= true;
1025 encrypt_key
.key_index
= key_index
;
1027 memcpy(encrypt_key
.key_material
, key
, key_len
);
1029 memcpy(encrypt_key
.mac_addr
, mac_addr
, ETH_ALEN
);
1030 if (kp
&& kp
->seq
&& kp
->seq_len
)
1031 memcpy(encrypt_key
.pn
, kp
->seq
, kp
->seq_len
);
1033 encrypt_key
.key_disable
= true;
1035 memcpy(encrypt_key
.mac_addr
, mac_addr
, ETH_ALEN
);
1038 return mwifiex_sec_ioctl_encrypt_key(priv
, &encrypt_key
);
1042 * Sends IOCTL request to get extended version.
1044 * This function allocates the IOCTL request buffer, fills it
1045 * with requisite parameters and calls the IOCTL handler.
1048 mwifiex_get_ver_ext(struct mwifiex_private
*priv
)
1050 struct mwifiex_ver_ext ver_ext
;
1052 memset(&ver_ext
, 0, sizeof(struct host_cmd_ds_version_ext
));
1053 if (mwifiex_send_cmd_sync(priv
, HostCmd_CMD_VERSION_EXT
,
1054 HostCmd_ACT_GEN_GET
, 0, &ver_ext
))
1061 mwifiex_remain_on_chan_cfg(struct mwifiex_private
*priv
, u16 action
,
1062 struct ieee80211_channel
*chan
,
1063 unsigned int duration
)
1065 struct host_cmd_ds_remain_on_chan roc_cfg
;
1068 memset(&roc_cfg
, 0, sizeof(roc_cfg
));
1069 roc_cfg
.action
= cpu_to_le16(action
);
1070 if (action
== HostCmd_ACT_GEN_SET
) {
1071 roc_cfg
.band_cfg
= chan
->band
;
1072 sc
= mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT
);
1073 roc_cfg
.band_cfg
|= (sc
<< 2);
1076 ieee80211_frequency_to_channel(chan
->center_freq
);
1077 roc_cfg
.duration
= cpu_to_le32(duration
);
1079 if (mwifiex_send_cmd_sync(priv
, HostCmd_CMD_REMAIN_ON_CHAN
,
1080 action
, 0, &roc_cfg
)) {
1081 dev_err(priv
->adapter
->dev
, "failed to remain on channel\n");
1085 return roc_cfg
.status
;
1089 mwifiex_set_bss_role(struct mwifiex_private
*priv
, u8 bss_role
)
1091 if (GET_BSS_ROLE(priv
) == bss_role
) {
1092 dev_dbg(priv
->adapter
->dev
,
1093 "info: already in the desired role.\n");
1097 mwifiex_free_priv(priv
);
1098 mwifiex_init_priv(priv
);
1100 priv
->bss_role
= bss_role
;
1102 case MWIFIEX_BSS_ROLE_UAP
:
1103 priv
->bss_mode
= NL80211_IFTYPE_AP
;
1105 case MWIFIEX_BSS_ROLE_STA
:
1106 case MWIFIEX_BSS_ROLE_ANY
:
1108 priv
->bss_mode
= NL80211_IFTYPE_STATION
;
1112 mwifiex_send_cmd_sync(priv
, HostCmd_CMD_SET_BSS_MODE
,
1113 HostCmd_ACT_GEN_SET
, 0, NULL
);
1115 return mwifiex_sta_init_cmd(priv
, false);
1119 * Sends IOCTL request to get statistics information.
1121 * This function allocates the IOCTL request buffer, fills it
1122 * with requisite parameters and calls the IOCTL handler.
1125 mwifiex_get_stats_info(struct mwifiex_private
*priv
,
1126 struct mwifiex_ds_get_stats
*log
)
1128 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_GET_LOG
,
1129 HostCmd_ACT_GEN_GET
, 0, log
);
1133 * IOCTL request handler to read/write register.
1135 * This function prepares the correct firmware command and
1138 * Access to the following registers are supported -
1145 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private
*priv
,
1146 struct mwifiex_ds_reg_rw
*reg_rw
,
1151 switch (le32_to_cpu(reg_rw
->type
)) {
1152 case MWIFIEX_REG_MAC
:
1153 cmd_no
= HostCmd_CMD_MAC_REG_ACCESS
;
1155 case MWIFIEX_REG_BBP
:
1156 cmd_no
= HostCmd_CMD_BBP_REG_ACCESS
;
1158 case MWIFIEX_REG_RF
:
1159 cmd_no
= HostCmd_CMD_RF_REG_ACCESS
;
1161 case MWIFIEX_REG_PMIC
:
1162 cmd_no
= HostCmd_CMD_PMIC_REG_ACCESS
;
1164 case MWIFIEX_REG_CAU
:
1165 cmd_no
= HostCmd_CMD_CAU_REG_ACCESS
;
1171 return mwifiex_send_cmd_sync(priv
, cmd_no
, action
, 0, reg_rw
);
1176 * Sends IOCTL request to write to a register.
1178 * This function allocates the IOCTL request buffer, fills it
1179 * with requisite parameters and calls the IOCTL handler.
1182 mwifiex_reg_write(struct mwifiex_private
*priv
, u32 reg_type
,
1183 u32 reg_offset
, u32 reg_value
)
1185 struct mwifiex_ds_reg_rw reg_rw
;
1187 reg_rw
.type
= cpu_to_le32(reg_type
);
1188 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1189 reg_rw
.value
= cpu_to_le32(reg_value
);
1191 return mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_SET
);
1195 * Sends IOCTL request to read from a register.
1197 * This function allocates the IOCTL request buffer, fills it
1198 * with requisite parameters and calls the IOCTL handler.
1201 mwifiex_reg_read(struct mwifiex_private
*priv
, u32 reg_type
,
1202 u32 reg_offset
, u32
*value
)
1205 struct mwifiex_ds_reg_rw reg_rw
;
1207 reg_rw
.type
= cpu_to_le32(reg_type
);
1208 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1209 ret
= mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_GET
);
1214 *value
= le32_to_cpu(reg_rw
.value
);
1221 * Sends IOCTL request to read from EEPROM.
1223 * This function allocates the IOCTL request buffer, fills it
1224 * with requisite parameters and calls the IOCTL handler.
1227 mwifiex_eeprom_read(struct mwifiex_private
*priv
, u16 offset
, u16 bytes
,
1231 struct mwifiex_ds_read_eeprom rd_eeprom
;
1233 rd_eeprom
.offset
= cpu_to_le16((u16
) offset
);
1234 rd_eeprom
.byte_count
= cpu_to_le16((u16
) bytes
);
1236 /* Send request to firmware */
1237 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_EEPROM_ACCESS
,
1238 HostCmd_ACT_GEN_GET
, 0, &rd_eeprom
);
1241 memcpy(value
, rd_eeprom
.value
, MAX_EEPROM_DATA
);
1246 * This function sets a generic IE. In addition to generic IE, it can
1247 * also handle WPA, WPA2 and WAPI IEs.
1250 mwifiex_set_gen_ie_helper(struct mwifiex_private
*priv
, u8
*ie_data_ptr
,
1254 struct ieee_types_vendor_header
*pvendor_ie
;
1255 const u8 wpa_oui
[] = { 0x00, 0x50, 0xf2, 0x01 };
1256 const u8 wps_oui
[] = { 0x00, 0x50, 0xf2, 0x04 };
1258 /* If the passed length is zero, reset the buffer */
1260 priv
->gen_ie_buf_len
= 0;
1261 priv
->wps
.session_enable
= false;
1264 } else if (!ie_data_ptr
) {
1267 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1268 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1269 if (((pvendor_ie
->element_id
== WLAN_EID_VENDOR_SPECIFIC
) &&
1270 (!memcmp(pvendor_ie
->oui
, wpa_oui
, sizeof(wpa_oui
)))) ||
1271 (pvendor_ie
->element_id
== WLAN_EID_RSN
)) {
1273 /* IE is a WPA/WPA2 IE so call set_wpa function */
1274 ret
= mwifiex_set_wpa_ie_helper(priv
, ie_data_ptr
, ie_len
);
1275 priv
->wps
.session_enable
= false;
1278 } else if (pvendor_ie
->element_id
== WLAN_EID_BSS_AC_ACCESS_DELAY
) {
1279 /* IE is a WAPI IE so call set_wapi function */
1280 ret
= mwifiex_set_wapi_ie(priv
, ie_data_ptr
, ie_len
);
1285 * Verify that the passed length is not larger than the
1286 * available space remaining in the buffer
1288 if (ie_len
< (sizeof(priv
->gen_ie_buf
) - priv
->gen_ie_buf_len
)) {
1290 /* Test to see if it is a WPS IE, if so, enable
1293 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1294 if ((pvendor_ie
->element_id
== WLAN_EID_VENDOR_SPECIFIC
) &&
1295 (!memcmp(pvendor_ie
->oui
, wps_oui
, sizeof(wps_oui
)))) {
1296 priv
->wps
.session_enable
= true;
1297 dev_dbg(priv
->adapter
->dev
,
1298 "info: WPS Session Enabled.\n");
1299 ret
= mwifiex_set_wps_ie(priv
, ie_data_ptr
, ie_len
);
1302 /* Append the passed data to the end of the
1304 memcpy(priv
->gen_ie_buf
+ priv
->gen_ie_buf_len
, ie_data_ptr
,
1306 /* Increment the stored buffer length by the
1308 priv
->gen_ie_buf_len
+= ie_len
;
1310 /* Passed data does not fit in the remaining
1315 /* Return 0, or -1 for error case */
1320 * IOCTL request handler to set/get generic IE.
1322 * In addition to various generic IEs, this function can also be
1323 * used to set the ARP filter.
1325 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private
*priv
,
1326 struct mwifiex_ds_misc_gen_ie
*gen_ie
,
1329 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1331 switch (gen_ie
->type
) {
1332 case MWIFIEX_IE_TYPE_GEN_IE
:
1333 if (action
== HostCmd_ACT_GEN_GET
) {
1334 gen_ie
->len
= priv
->wpa_ie_len
;
1335 memcpy(gen_ie
->ie_data
, priv
->wpa_ie
, gen_ie
->len
);
1337 mwifiex_set_gen_ie_helper(priv
, gen_ie
->ie_data
,
1341 case MWIFIEX_IE_TYPE_ARP_FILTER
:
1342 memset(adapter
->arp_filter
, 0, sizeof(adapter
->arp_filter
));
1343 if (gen_ie
->len
> ARP_FILTER_MAX_BUF_SIZE
) {
1344 adapter
->arp_filter_size
= 0;
1345 dev_err(adapter
->dev
, "invalid ARP filter size\n");
1348 memcpy(adapter
->arp_filter
, gen_ie
->ie_data
,
1350 adapter
->arp_filter_size
= gen_ie
->len
;
1354 dev_err(adapter
->dev
, "invalid IE type\n");
1361 * Sends IOCTL request to set a generic IE.
1363 * This function allocates the IOCTL request buffer, fills it
1364 * with requisite parameters and calls the IOCTL handler.
1367 mwifiex_set_gen_ie(struct mwifiex_private
*priv
, u8
*ie
, int ie_len
)
1369 struct mwifiex_ds_misc_gen_ie gen_ie
;
1371 if (ie_len
> IEEE_MAX_IE_SIZE
)
1374 gen_ie
.type
= MWIFIEX_IE_TYPE_GEN_IE
;
1375 gen_ie
.len
= ie_len
;
1376 memcpy(gen_ie
.ie_data
, ie
, ie_len
);
1377 if (mwifiex_misc_ioctl_gen_ie(priv
, &gen_ie
, HostCmd_ACT_GEN_SET
))