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 if (mcast_list
->num_multicast_addr
) {
108 dev_dbg(priv
->adapter
->dev
,
109 "info: Set multicast list=%d\n",
110 mcast_list
->num_multicast_addr
);
111 /* Send multicast addresses to firmware */
112 ret
= mwifiex_send_cmd_async(priv
,
113 HostCmd_CMD_MAC_MULTICAST_ADR
,
114 HostCmd_ACT_GEN_SET
, 0,
119 dev_dbg(priv
->adapter
->dev
,
120 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
121 old_pkt_filter
, priv
->curr_pkt_filter
);
122 if (old_pkt_filter
!= priv
->curr_pkt_filter
) {
123 ret
= mwifiex_send_cmd_async(priv
, HostCmd_CMD_MAC_CONTROL
,
125 0, &priv
->curr_pkt_filter
);
132 * This function fills bss descriptor structure using provided
134 * beacon_ie buffer is allocated in this function. It is caller's
135 * responsibility to free the memory.
137 int mwifiex_fill_new_bss_desc(struct mwifiex_private
*priv
,
138 struct cfg80211_bss
*bss
,
139 struct mwifiex_bssdescriptor
*bss_desc
)
142 size_t beacon_ie_len
;
143 struct mwifiex_bss_priv
*bss_priv
= (void *)bss
->priv
;
144 const struct cfg80211_bss_ies
*ies
;
147 ies
= rcu_dereference(bss
->ies
);
148 beacon_ie
= kmemdup(ies
->data
, ies
->len
, GFP_ATOMIC
);
149 beacon_ie_len
= ies
->len
;
150 bss_desc
->timestamp
= ies
->tsf
;
154 dev_err(priv
->adapter
->dev
, " failed to alloc beacon_ie\n");
158 memcpy(bss_desc
->mac_address
, bss
->bssid
, ETH_ALEN
);
159 bss_desc
->rssi
= bss
->signal
;
160 /* The caller of this function will free beacon_ie */
161 bss_desc
->beacon_buf
= beacon_ie
;
162 bss_desc
->beacon_buf_size
= beacon_ie_len
;
163 bss_desc
->beacon_period
= bss
->beacon_interval
;
164 bss_desc
->cap_info_bitmap
= bss
->capability
;
165 bss_desc
->bss_band
= bss_priv
->band
;
166 bss_desc
->fw_tsf
= bss_priv
->fw_tsf
;
167 if (bss_desc
->cap_info_bitmap
& WLAN_CAPABILITY_PRIVACY
) {
168 dev_dbg(priv
->adapter
->dev
, "info: InterpretIE: AP WEP enabled\n");
169 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_8021X_WEP
;
171 bss_desc
->privacy
= MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL
;
173 if (bss_desc
->cap_info_bitmap
& WLAN_CAPABILITY_IBSS
)
174 bss_desc
->bss_mode
= NL80211_IFTYPE_ADHOC
;
176 bss_desc
->bss_mode
= NL80211_IFTYPE_STATION
;
178 /* Disable 11ac by default. Enable it only where there
179 * exist VHT_CAP IE in AP beacon
181 bss_desc
->disable_11ac
= true;
183 return mwifiex_update_bss_desc_with_ie(priv
->adapter
, bss_desc
);
186 static int mwifiex_process_country_ie(struct mwifiex_private
*priv
,
187 struct cfg80211_bss
*bss
)
189 const u8
*country_ie
;
191 struct mwifiex_802_11d_domain_reg
*domain_info
=
192 &priv
->adapter
->domain_reg
;
195 country_ie
= ieee80211_bss_get_ie(bss
, WLAN_EID_COUNTRY
);
201 country_ie_len
= country_ie
[1];
202 if (country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
) {
207 domain_info
->country_code
[0] = country_ie
[2];
208 domain_info
->country_code
[1] = country_ie
[3];
209 domain_info
->country_code
[2] = ' ';
211 country_ie_len
-= IEEE80211_COUNTRY_STRING_LEN
;
213 domain_info
->no_of_triplet
=
214 country_ie_len
/ sizeof(struct ieee80211_country_ie_triplet
);
216 memcpy((u8
*)domain_info
->triplet
,
217 &country_ie
[2] + IEEE80211_COUNTRY_STRING_LEN
, country_ie_len
);
221 if (mwifiex_send_cmd_async(priv
, HostCmd_CMD_802_11D_DOMAIN_INFO
,
222 HostCmd_ACT_GEN_SET
, 0, NULL
)) {
223 wiphy_err(priv
->adapter
->wiphy
,
224 "11D: setting domain info in FW\n");
232 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
233 * In both Ad-Hoc and infra mode, an deauthentication is performed
236 int mwifiex_bss_start(struct mwifiex_private
*priv
, struct cfg80211_bss
*bss
,
237 struct cfg80211_ssid
*req_ssid
)
240 struct mwifiex_adapter
*adapter
= priv
->adapter
;
241 struct mwifiex_bssdescriptor
*bss_desc
= NULL
;
243 priv
->scan_block
= false;
246 mwifiex_process_country_ie(priv
, bss
);
248 /* Allocate and fill new bss descriptor */
249 bss_desc
= kzalloc(sizeof(struct mwifiex_bssdescriptor
),
254 ret
= mwifiex_fill_new_bss_desc(priv
, bss
, bss_desc
);
259 if (priv
->bss_mode
== NL80211_IFTYPE_STATION
) {
261 ret
= mwifiex_deauthenticate(priv
, NULL
);
268 if (mwifiex_band_to_radio_type((u8
) bss_desc
->bss_band
)
269 == HostCmd_SCAN_RADIO_TYPE_BG
)
270 config_bands
= BAND_B
| BAND_G
| BAND_GN
|
273 config_bands
= BAND_A
| BAND_AN
| BAND_AAC
;
275 if (!((config_bands
| adapter
->fw_bands
) &
277 adapter
->config_bands
= config_bands
;
280 ret
= mwifiex_check_network_compatibility(priv
, bss_desc
);
284 dev_dbg(adapter
->dev
, "info: SSID found in scan list ... "
287 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
288 if (netif_carrier_ok(priv
->netdev
))
289 netif_carrier_off(priv
->netdev
);
291 /* Clear any past association response stored for
292 * application retrieval */
293 priv
->assoc_rsp_size
= 0;
294 ret
= mwifiex_associate(priv
, bss_desc
);
296 /* If auth type is auto and association fails using open mode,
297 * try to connect using shared mode */
298 if (ret
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
&&
299 priv
->sec_info
.is_authtype_auto
&&
300 priv
->sec_info
.wep_enabled
) {
301 priv
->sec_info
.authentication_mode
=
302 NL80211_AUTHTYPE_SHARED_KEY
;
303 ret
= mwifiex_associate(priv
, bss_desc
);
307 cfg80211_put_bss(priv
->adapter
->wiphy
, bss
);
310 /* If the requested SSID matches current SSID, return */
311 if (bss_desc
&& bss_desc
->ssid
.ssid_len
&&
312 (!mwifiex_ssid_cmp(&priv
->curr_bss_params
.bss_descriptor
.
313 ssid
, &bss_desc
->ssid
))) {
318 /* Exit Adhoc mode first */
319 dev_dbg(adapter
->dev
, "info: Sending Adhoc Stop\n");
320 ret
= mwifiex_deauthenticate(priv
, NULL
);
324 priv
->adhoc_is_link_sensed
= false;
326 ret
= mwifiex_check_network_compatibility(priv
, bss_desc
);
328 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
329 if (netif_carrier_ok(priv
->netdev
))
330 netif_carrier_off(priv
->netdev
);
333 dev_dbg(adapter
->dev
, "info: network found in scan"
334 " list. Joining...\n");
335 ret
= mwifiex_adhoc_join(priv
, bss_desc
);
337 cfg80211_put_bss(priv
->adapter
->wiphy
, bss
);
339 dev_dbg(adapter
->dev
, "info: Network not found in "
340 "the list, creating adhoc with ssid = %s\n",
342 ret
= mwifiex_adhoc_start(priv
, req_ssid
);
347 /* beacon_ie buffer was allocated in function
348 * mwifiex_fill_new_bss_desc(). Free it now.
351 kfree(bss_desc
->beacon_buf
);
357 * IOCTL request handler to set host sleep configuration.
359 * This function prepares the correct firmware command and
362 static int mwifiex_set_hs_params(struct mwifiex_private
*priv
, u16 action
,
363 int cmd_type
, struct mwifiex_ds_hs_cfg
*hs_cfg
)
366 struct mwifiex_adapter
*adapter
= priv
->adapter
;
374 case HostCmd_ACT_GEN_SET
:
375 if (adapter
->pps_uapsd_mode
) {
376 dev_dbg(adapter
->dev
, "info: Host Sleep IOCTL"
377 " is blocked in UAPSD/PPS mode\n");
381 if (hs_cfg
->is_invoke_hostcmd
) {
382 if (hs_cfg
->conditions
== HS_CFG_CANCEL
) {
383 if (!adapter
->is_hs_configured
)
384 /* Already cancelled */
386 /* Save previous condition */
387 prev_cond
= le32_to_cpu(adapter
->hs_cfg
389 adapter
->hs_cfg
.conditions
=
390 cpu_to_le32(hs_cfg
->conditions
);
391 } else if (hs_cfg
->conditions
) {
392 adapter
->hs_cfg
.conditions
=
393 cpu_to_le32(hs_cfg
->conditions
);
394 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
396 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
397 } else if (adapter
->hs_cfg
.conditions
==
398 cpu_to_le32(HS_CFG_CANCEL
)) {
399 /* Return failure if no parameters for HS
404 if (cmd_type
== MWIFIEX_SYNC_CMD
)
405 status
= mwifiex_send_cmd_sync(priv
,
406 HostCmd_CMD_802_11_HS_CFG_ENH
,
407 HostCmd_ACT_GEN_SET
, 0,
410 status
= mwifiex_send_cmd_async(priv
,
411 HostCmd_CMD_802_11_HS_CFG_ENH
,
412 HostCmd_ACT_GEN_SET
, 0,
414 if (hs_cfg
->conditions
== HS_CFG_CANCEL
)
415 /* Restore previous condition */
416 adapter
->hs_cfg
.conditions
=
417 cpu_to_le32(prev_cond
);
419 adapter
->hs_cfg
.conditions
=
420 cpu_to_le32(hs_cfg
->conditions
);
421 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
422 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
425 case HostCmd_ACT_GEN_GET
:
426 hs_cfg
->conditions
= le32_to_cpu(adapter
->hs_cfg
.conditions
);
427 hs_cfg
->gpio
= adapter
->hs_cfg
.gpio
;
428 hs_cfg
->gap
= adapter
->hs_cfg
.gap
;
439 * Sends IOCTL request to cancel the existing Host Sleep configuration.
441 * This function allocates the IOCTL request buffer, fills it
442 * with requisite parameters and calls the IOCTL handler.
444 int mwifiex_cancel_hs(struct mwifiex_private
*priv
, int cmd_type
)
446 struct mwifiex_ds_hs_cfg hscfg
;
448 hscfg
.conditions
= HS_CFG_CANCEL
;
449 hscfg
.is_invoke_hostcmd
= true;
451 return mwifiex_set_hs_params(priv
, HostCmd_ACT_GEN_SET
,
454 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs
);
457 * Sends IOCTL request to cancel the existing Host Sleep configuration.
459 * This function allocates the IOCTL request buffer, fills it
460 * with requisite parameters and calls the IOCTL handler.
462 int mwifiex_enable_hs(struct mwifiex_adapter
*adapter
)
464 struct mwifiex_ds_hs_cfg hscfg
;
465 struct mwifiex_private
*priv
;
468 if (disconnect_on_suspend
) {
469 for (i
= 0; i
< adapter
->priv_num
; i
++) {
470 priv
= adapter
->priv
[i
];
472 mwifiex_deauthenticate(priv
, NULL
);
476 if (adapter
->hs_activated
) {
477 dev_dbg(adapter
->dev
, "cmd: HS Already activated\n");
481 adapter
->hs_activate_wait_q_woken
= false;
483 memset(&hscfg
, 0, sizeof(struct mwifiex_ds_hs_cfg
));
484 hscfg
.is_invoke_hostcmd
= true;
486 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter
,
487 MWIFIEX_BSS_ROLE_STA
),
488 HostCmd_ACT_GEN_SET
, MWIFIEX_SYNC_CMD
,
490 dev_err(adapter
->dev
, "IOCTL request HS enable failed\n");
494 if (wait_event_interruptible(adapter
->hs_activate_wait_q
,
495 adapter
->hs_activate_wait_q_woken
)) {
496 dev_err(adapter
->dev
, "hs_activate_wait_q terminated\n");
502 EXPORT_SYMBOL_GPL(mwifiex_enable_hs
);
505 * IOCTL request handler to get BSS information.
507 * This function collates the information from different driver structures
508 * to send to the user.
510 int mwifiex_get_bss_info(struct mwifiex_private
*priv
,
511 struct mwifiex_bss_info
*info
)
513 struct mwifiex_adapter
*adapter
= priv
->adapter
;
514 struct mwifiex_bssdescriptor
*bss_desc
;
519 bss_desc
= &priv
->curr_bss_params
.bss_descriptor
;
521 info
->bss_mode
= priv
->bss_mode
;
523 memcpy(&info
->ssid
, &bss_desc
->ssid
, sizeof(struct cfg80211_ssid
));
525 memcpy(&info
->bssid
, &bss_desc
->mac_address
, ETH_ALEN
);
527 info
->bss_chan
= bss_desc
->channel
;
529 memcpy(info
->country_code
, adapter
->country_code
,
530 IEEE80211_COUNTRY_STRING_LEN
);
532 info
->media_connected
= priv
->media_connected
;
534 info
->max_power_level
= priv
->max_tx_power_level
;
535 info
->min_power_level
= priv
->min_tx_power_level
;
537 info
->adhoc_state
= priv
->adhoc_state
;
539 info
->bcn_nf_last
= priv
->bcn_nf_last
;
541 if (priv
->sec_info
.wep_enabled
)
542 info
->wep_status
= true;
544 info
->wep_status
= false;
546 info
->is_hs_configured
= adapter
->is_hs_configured
;
547 info
->is_deep_sleep
= adapter
->is_deep_sleep
;
553 * The function disables auto deep sleep mode.
555 int mwifiex_disable_auto_ds(struct mwifiex_private
*priv
)
557 struct mwifiex_ds_auto_ds auto_ds
;
559 auto_ds
.auto_ds
= DEEP_SLEEP_OFF
;
561 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
562 DIS_AUTO_PS
, BITMAP_AUTO_DS
, &auto_ds
);
564 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds
);
567 * Sends IOCTL request to get the data rate.
569 * This function allocates the IOCTL request buffer, fills it
570 * with requisite parameters and calls the IOCTL handler.
572 int mwifiex_drv_get_data_rate(struct mwifiex_private
*priv
, u32
*rate
)
576 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_TX_RATE_QUERY
,
577 HostCmd_ACT_GEN_GET
, 0, NULL
);
580 if (priv
->is_data_rate_auto
)
581 *rate
= mwifiex_index_to_data_rate(priv
, priv
->tx_rate
,
584 *rate
= priv
->data_rate
;
591 * IOCTL request handler to set tx power configuration.
593 * This function prepares the correct firmware command and
596 * For non-auto power mode, all the following power groups are set -
597 * - Modulation class HR/DSSS
598 * - Modulation class OFDM
599 * - Modulation class HTBW20
600 * - Modulation class HTBW40
602 int mwifiex_set_tx_power(struct mwifiex_private
*priv
,
603 struct mwifiex_power_cfg
*power_cfg
)
606 struct host_cmd_ds_txpwr_cfg
*txp_cfg
;
607 struct mwifiex_types_power_group
*pg_tlv
;
608 struct mwifiex_power_group
*pg
;
612 if (!power_cfg
->is_power_auto
) {
613 dbm
= (u16
) power_cfg
->power_level
;
614 if ((dbm
< priv
->min_tx_power_level
) ||
615 (dbm
> priv
->max_tx_power_level
)) {
616 dev_err(priv
->adapter
->dev
, "txpower value %d dBm"
617 " is out of range (%d dBm-%d dBm)\n",
618 dbm
, priv
->min_tx_power_level
,
619 priv
->max_tx_power_level
);
623 buf
= kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER
, GFP_KERNEL
);
627 txp_cfg
= (struct host_cmd_ds_txpwr_cfg
*) buf
;
628 txp_cfg
->action
= cpu_to_le16(HostCmd_ACT_GEN_SET
);
629 if (!power_cfg
->is_power_auto
) {
630 txp_cfg
->mode
= cpu_to_le32(1);
631 pg_tlv
= (struct mwifiex_types_power_group
*)
632 (buf
+ sizeof(struct host_cmd_ds_txpwr_cfg
));
633 pg_tlv
->type
= TLV_TYPE_POWER_GROUP
;
634 pg_tlv
->length
= 4 * sizeof(struct mwifiex_power_group
);
635 pg
= (struct mwifiex_power_group
*)
636 (buf
+ sizeof(struct host_cmd_ds_txpwr_cfg
)
637 + sizeof(struct mwifiex_types_power_group
));
638 /* Power group for modulation class HR/DSSS */
639 pg
->first_rate_code
= 0x00;
640 pg
->last_rate_code
= 0x03;
641 pg
->modulation_class
= MOD_CLASS_HR_DSSS
;
643 pg
->power_min
= (s8
) dbm
;
644 pg
->power_max
= (s8
) dbm
;
646 /* Power group for modulation class OFDM */
647 pg
->first_rate_code
= 0x00;
648 pg
->last_rate_code
= 0x07;
649 pg
->modulation_class
= MOD_CLASS_OFDM
;
651 pg
->power_min
= (s8
) dbm
;
652 pg
->power_max
= (s8
) dbm
;
654 /* Power group for modulation class HTBW20 */
655 pg
->first_rate_code
= 0x00;
656 pg
->last_rate_code
= 0x20;
657 pg
->modulation_class
= MOD_CLASS_HT
;
659 pg
->power_min
= (s8
) dbm
;
660 pg
->power_max
= (s8
) dbm
;
661 pg
->ht_bandwidth
= HT_BW_20
;
663 /* Power group for modulation class HTBW40 */
664 pg
->first_rate_code
= 0x00;
665 pg
->last_rate_code
= 0x20;
666 pg
->modulation_class
= MOD_CLASS_HT
;
668 pg
->power_min
= (s8
) dbm
;
669 pg
->power_max
= (s8
) dbm
;
670 pg
->ht_bandwidth
= HT_BW_40
;
672 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_TXPWR_CFG
,
673 HostCmd_ACT_GEN_SET
, 0, buf
);
680 * IOCTL request handler to get power save mode.
682 * This function prepares the correct firmware command and
685 int mwifiex_drv_set_power(struct mwifiex_private
*priv
, u32
*ps_mode
)
688 struct mwifiex_adapter
*adapter
= priv
->adapter
;
692 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
694 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
695 sub_cmd
= (*ps_mode
) ? EN_AUTO_PS
: DIS_AUTO_PS
;
696 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
697 sub_cmd
, BITMAP_STA_PS
, NULL
);
698 if ((!ret
) && (sub_cmd
== DIS_AUTO_PS
))
699 ret
= mwifiex_send_cmd_async(priv
,
700 HostCmd_CMD_802_11_PS_MODE_ENH
,
707 * IOCTL request handler to set/reset WPA IE.
709 * The supplied WPA IE is treated as a opaque buffer. Only the first field
710 * is checked to determine WPA version. If buffer length is zero, the existing
713 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private
*priv
,
714 u8
*ie_data_ptr
, u16 ie_len
)
717 if (ie_len
> sizeof(priv
->wpa_ie
)) {
718 dev_err(priv
->adapter
->dev
,
719 "failed to copy WPA IE, too big\n");
722 memcpy(priv
->wpa_ie
, ie_data_ptr
, ie_len
);
723 priv
->wpa_ie_len
= (u8
) ie_len
;
724 dev_dbg(priv
->adapter
->dev
, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
725 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
727 if (priv
->wpa_ie
[0] == WLAN_EID_VENDOR_SPECIFIC
) {
728 priv
->sec_info
.wpa_enabled
= true;
729 } else if (priv
->wpa_ie
[0] == WLAN_EID_RSN
) {
730 priv
->sec_info
.wpa2_enabled
= true;
732 priv
->sec_info
.wpa_enabled
= false;
733 priv
->sec_info
.wpa2_enabled
= false;
736 memset(priv
->wpa_ie
, 0, sizeof(priv
->wpa_ie
));
737 priv
->wpa_ie_len
= 0;
738 dev_dbg(priv
->adapter
->dev
, "info: reset wpa_ie_len=%d IE=%#x\n",
739 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
740 priv
->sec_info
.wpa_enabled
= false;
741 priv
->sec_info
.wpa2_enabled
= false;
748 * IOCTL request handler to set/reset WAPI IE.
750 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
751 * is checked to internally enable WAPI. If buffer length is zero, the existing
754 static int mwifiex_set_wapi_ie(struct mwifiex_private
*priv
,
755 u8
*ie_data_ptr
, u16 ie_len
)
758 if (ie_len
> sizeof(priv
->wapi_ie
)) {
759 dev_dbg(priv
->adapter
->dev
,
760 "info: failed to copy WAPI IE, too big\n");
763 memcpy(priv
->wapi_ie
, ie_data_ptr
, ie_len
);
764 priv
->wapi_ie_len
= ie_len
;
765 dev_dbg(priv
->adapter
->dev
, "cmd: Set wapi_ie_len=%d IE=%#x\n",
766 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
768 if (priv
->wapi_ie
[0] == WLAN_EID_BSS_AC_ACCESS_DELAY
)
769 priv
->sec_info
.wapi_enabled
= true;
771 memset(priv
->wapi_ie
, 0, sizeof(priv
->wapi_ie
));
772 priv
->wapi_ie_len
= ie_len
;
773 dev_dbg(priv
->adapter
->dev
,
774 "info: Reset wapi_ie_len=%d IE=%#x\n",
775 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
776 priv
->sec_info
.wapi_enabled
= false;
782 * IOCTL request handler to set/reset WPS IE.
784 * The supplied WPS IE is treated as a opaque buffer. Only the first field
785 * is checked to internally enable WPS. If buffer length is zero, the existing
788 static int mwifiex_set_wps_ie(struct mwifiex_private
*priv
,
789 u8
*ie_data_ptr
, u16 ie_len
)
792 priv
->wps_ie
= kzalloc(MWIFIEX_MAX_VSIE_LEN
, GFP_KERNEL
);
795 if (ie_len
> sizeof(priv
->wps_ie
)) {
796 dev_dbg(priv
->adapter
->dev
,
797 "info: failed to copy WPS IE, too big\n");
801 memcpy(priv
->wps_ie
, ie_data_ptr
, ie_len
);
802 priv
->wps_ie_len
= ie_len
;
803 dev_dbg(priv
->adapter
->dev
, "cmd: Set wps_ie_len=%d IE=%#x\n",
804 priv
->wps_ie_len
, priv
->wps_ie
[0]);
807 priv
->wps_ie_len
= ie_len
;
808 dev_dbg(priv
->adapter
->dev
,
809 "info: Reset wps_ie_len=%d\n", priv
->wps_ie_len
);
815 * IOCTL request handler to set WAPI key.
817 * This function prepares the correct firmware command and
820 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private
*priv
,
821 struct mwifiex_ds_encrypt_key
*encrypt_key
)
824 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_KEY_MATERIAL
,
825 HostCmd_ACT_GEN_SET
, KEY_INFO_ENABLED
,
830 * IOCTL request handler to set WEP network key.
832 * This function prepares the correct firmware command and
833 * issues it, after validation checks.
835 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private
*priv
,
836 struct mwifiex_ds_encrypt_key
*encrypt_key
)
839 struct mwifiex_wep_key
*wep_key
;
842 if (priv
->wep_key_curr_index
>= NUM_WEP_KEYS
)
843 priv
->wep_key_curr_index
= 0;
844 wep_key
= &priv
->wep_key
[priv
->wep_key_curr_index
];
845 index
= encrypt_key
->key_index
;
846 if (encrypt_key
->key_disable
) {
847 priv
->sec_info
.wep_enabled
= 0;
848 } else if (!encrypt_key
->key_len
) {
849 /* Copy the required key as the current key */
850 wep_key
= &priv
->wep_key
[index
];
851 if (!wep_key
->key_length
) {
852 dev_err(priv
->adapter
->dev
,
853 "key not set, so cannot enable it\n");
856 priv
->wep_key_curr_index
= (u16
) index
;
857 priv
->sec_info
.wep_enabled
= 1;
859 wep_key
= &priv
->wep_key
[index
];
860 memset(wep_key
, 0, sizeof(struct mwifiex_wep_key
));
861 /* Copy the key in the driver */
862 memcpy(wep_key
->key_material
,
863 encrypt_key
->key_material
,
864 encrypt_key
->key_len
);
865 wep_key
->key_index
= index
;
866 wep_key
->key_length
= encrypt_key
->key_len
;
867 priv
->sec_info
.wep_enabled
= 1;
869 if (wep_key
->key_length
) {
870 /* Send request to firmware */
871 ret
= mwifiex_send_cmd_async(priv
,
872 HostCmd_CMD_802_11_KEY_MATERIAL
,
873 HostCmd_ACT_GEN_SET
, 0, NULL
);
877 if (priv
->sec_info
.wep_enabled
)
878 priv
->curr_pkt_filter
|= HostCmd_ACT_MAC_WEP_ENABLE
;
880 priv
->curr_pkt_filter
&= ~HostCmd_ACT_MAC_WEP_ENABLE
;
882 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_MAC_CONTROL
,
883 HostCmd_ACT_GEN_SET
, 0,
884 &priv
->curr_pkt_filter
);
890 * IOCTL request handler to set WPA key.
892 * This function prepares the correct firmware command and
893 * issues it, after validation checks.
895 * Current driver only supports key length of up to 32 bytes.
897 * This function can also be used to disable a currently set key.
899 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private
*priv
,
900 struct mwifiex_ds_encrypt_key
*encrypt_key
)
903 u8 remove_key
= false;
904 struct host_cmd_ds_802_11_key_material
*ibss_key
;
906 /* Current driver only supports key length of up to 32 bytes */
907 if (encrypt_key
->key_len
> WLAN_MAX_KEY_LEN
) {
908 dev_err(priv
->adapter
->dev
, "key length too long\n");
912 if (priv
->bss_mode
== NL80211_IFTYPE_ADHOC
) {
914 * IBSS/WPA-None uses only one key (Group) for both receiving
915 * and sending unicast and multicast packets.
917 /* Send the key as PTK to firmware */
918 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
919 ret
= mwifiex_send_cmd_async(priv
,
920 HostCmd_CMD_802_11_KEY_MATERIAL
,
922 KEY_INFO_ENABLED
, encrypt_key
);
926 ibss_key
= &priv
->aes_key
;
928 sizeof(struct host_cmd_ds_802_11_key_material
));
929 /* Copy the key in the driver */
930 memcpy(ibss_key
->key_param_set
.key
, encrypt_key
->key_material
,
931 encrypt_key
->key_len
);
932 memcpy(&ibss_key
->key_param_set
.key_len
, &encrypt_key
->key_len
,
933 sizeof(ibss_key
->key_param_set
.key_len
));
934 ibss_key
->key_param_set
.key_type_id
935 = cpu_to_le16(KEY_TYPE_ID_TKIP
);
936 ibss_key
->key_param_set
.key_info
= cpu_to_le16(KEY_ENABLED
);
938 /* Send the key as GTK to firmware */
939 encrypt_key
->key_index
= ~MWIFIEX_KEY_INDEX_UNICAST
;
942 if (!encrypt_key
->key_index
)
943 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
946 ret
= mwifiex_send_cmd_sync(priv
,
947 HostCmd_CMD_802_11_KEY_MATERIAL
,
949 !KEY_INFO_ENABLED
, encrypt_key
);
951 ret
= mwifiex_send_cmd_sync(priv
,
952 HostCmd_CMD_802_11_KEY_MATERIAL
,
954 KEY_INFO_ENABLED
, encrypt_key
);
960 * IOCTL request handler to set/get network keys.
962 * This is a generic key handling function which supports WEP, WPA
966 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private
*priv
,
967 struct mwifiex_ds_encrypt_key
*encrypt_key
)
971 if (encrypt_key
->is_wapi_key
)
972 status
= mwifiex_sec_ioctl_set_wapi_key(priv
, encrypt_key
);
973 else if (encrypt_key
->key_len
> WLAN_KEY_LEN_WEP104
)
974 status
= mwifiex_sec_ioctl_set_wpa_key(priv
, encrypt_key
);
976 status
= mwifiex_sec_ioctl_set_wep_key(priv
, encrypt_key
);
981 * This function returns the driver version.
984 mwifiex_drv_get_driver_version(struct mwifiex_adapter
*adapter
, char *version
,
993 ver
.l
= adapter
->fw_release_number
;
994 sprintf(fw_ver
, "%u.%u.%u.p%u", ver
.c
[2], ver
.c
[1], ver
.c
[0], ver
.c
[3]);
996 snprintf(version
, max_len
, driver_version
, fw_ver
);
998 dev_dbg(adapter
->dev
, "info: MWIFIEX VERSION: %s\n", version
);
1004 * Sends IOCTL request to set encoding parameters.
1006 * This function allocates the IOCTL request buffer, fills it
1007 * with requisite parameters and calls the IOCTL handler.
1009 int mwifiex_set_encode(struct mwifiex_private
*priv
, struct key_params
*kp
,
1010 const u8
*key
, int key_len
, u8 key_index
,
1011 const u8
*mac_addr
, int disable
)
1013 struct mwifiex_ds_encrypt_key encrypt_key
;
1015 memset(&encrypt_key
, 0, sizeof(struct mwifiex_ds_encrypt_key
));
1016 encrypt_key
.key_len
= key_len
;
1018 if (kp
&& kp
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
1019 encrypt_key
.is_igtk_key
= true;
1022 encrypt_key
.key_index
= key_index
;
1024 memcpy(encrypt_key
.key_material
, key
, key_len
);
1026 memcpy(encrypt_key
.mac_addr
, mac_addr
, ETH_ALEN
);
1027 if (kp
&& kp
->seq
&& kp
->seq_len
)
1028 memcpy(encrypt_key
.pn
, kp
->seq
, kp
->seq_len
);
1030 encrypt_key
.key_disable
= true;
1032 memcpy(encrypt_key
.mac_addr
, mac_addr
, ETH_ALEN
);
1035 return mwifiex_sec_ioctl_encrypt_key(priv
, &encrypt_key
);
1039 * Sends IOCTL request to get extended version.
1041 * This function allocates the IOCTL request buffer, fills it
1042 * with requisite parameters and calls the IOCTL handler.
1045 mwifiex_get_ver_ext(struct mwifiex_private
*priv
)
1047 struct mwifiex_ver_ext ver_ext
;
1049 memset(&ver_ext
, 0, sizeof(struct host_cmd_ds_version_ext
));
1050 if (mwifiex_send_cmd_sync(priv
, HostCmd_CMD_VERSION_EXT
,
1051 HostCmd_ACT_GEN_GET
, 0, &ver_ext
))
1058 mwifiex_remain_on_chan_cfg(struct mwifiex_private
*priv
, u16 action
,
1059 struct ieee80211_channel
*chan
,
1060 unsigned int duration
)
1062 struct host_cmd_ds_remain_on_chan roc_cfg
;
1065 memset(&roc_cfg
, 0, sizeof(roc_cfg
));
1066 roc_cfg
.action
= cpu_to_le16(action
);
1067 if (action
== HostCmd_ACT_GEN_SET
) {
1068 roc_cfg
.band_cfg
= chan
->band
;
1069 sc
= mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT
);
1070 roc_cfg
.band_cfg
|= (sc
<< 2);
1073 ieee80211_frequency_to_channel(chan
->center_freq
);
1074 roc_cfg
.duration
= cpu_to_le32(duration
);
1076 if (mwifiex_send_cmd_sync(priv
, HostCmd_CMD_REMAIN_ON_CHAN
,
1077 action
, 0, &roc_cfg
)) {
1078 dev_err(priv
->adapter
->dev
, "failed to remain on channel\n");
1082 return roc_cfg
.status
;
1086 mwifiex_set_bss_role(struct mwifiex_private
*priv
, u8 bss_role
)
1088 if (GET_BSS_ROLE(priv
) == bss_role
) {
1089 dev_dbg(priv
->adapter
->dev
,
1090 "info: already in the desired role.\n");
1094 mwifiex_free_priv(priv
);
1095 mwifiex_init_priv(priv
);
1097 priv
->bss_role
= bss_role
;
1099 case MWIFIEX_BSS_ROLE_UAP
:
1100 priv
->bss_mode
= NL80211_IFTYPE_AP
;
1102 case MWIFIEX_BSS_ROLE_STA
:
1103 case MWIFIEX_BSS_ROLE_ANY
:
1105 priv
->bss_mode
= NL80211_IFTYPE_STATION
;
1109 mwifiex_send_cmd_sync(priv
, HostCmd_CMD_SET_BSS_MODE
,
1110 HostCmd_ACT_GEN_SET
, 0, NULL
);
1112 return mwifiex_sta_init_cmd(priv
, false);
1116 * Sends IOCTL request to get statistics information.
1118 * This function allocates the IOCTL request buffer, fills it
1119 * with requisite parameters and calls the IOCTL handler.
1122 mwifiex_get_stats_info(struct mwifiex_private
*priv
,
1123 struct mwifiex_ds_get_stats
*log
)
1125 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_GET_LOG
,
1126 HostCmd_ACT_GEN_GET
, 0, log
);
1130 * IOCTL request handler to read/write register.
1132 * This function prepares the correct firmware command and
1135 * Access to the following registers are supported -
1142 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private
*priv
,
1143 struct mwifiex_ds_reg_rw
*reg_rw
,
1148 switch (le32_to_cpu(reg_rw
->type
)) {
1149 case MWIFIEX_REG_MAC
:
1150 cmd_no
= HostCmd_CMD_MAC_REG_ACCESS
;
1152 case MWIFIEX_REG_BBP
:
1153 cmd_no
= HostCmd_CMD_BBP_REG_ACCESS
;
1155 case MWIFIEX_REG_RF
:
1156 cmd_no
= HostCmd_CMD_RF_REG_ACCESS
;
1158 case MWIFIEX_REG_PMIC
:
1159 cmd_no
= HostCmd_CMD_PMIC_REG_ACCESS
;
1161 case MWIFIEX_REG_CAU
:
1162 cmd_no
= HostCmd_CMD_CAU_REG_ACCESS
;
1168 return mwifiex_send_cmd_sync(priv
, cmd_no
, action
, 0, reg_rw
);
1173 * Sends IOCTL request to write to a register.
1175 * This function allocates the IOCTL request buffer, fills it
1176 * with requisite parameters and calls the IOCTL handler.
1179 mwifiex_reg_write(struct mwifiex_private
*priv
, u32 reg_type
,
1180 u32 reg_offset
, u32 reg_value
)
1182 struct mwifiex_ds_reg_rw reg_rw
;
1184 reg_rw
.type
= cpu_to_le32(reg_type
);
1185 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1186 reg_rw
.value
= cpu_to_le32(reg_value
);
1188 return mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_SET
);
1192 * Sends IOCTL request to read from a register.
1194 * This function allocates the IOCTL request buffer, fills it
1195 * with requisite parameters and calls the IOCTL handler.
1198 mwifiex_reg_read(struct mwifiex_private
*priv
, u32 reg_type
,
1199 u32 reg_offset
, u32
*value
)
1202 struct mwifiex_ds_reg_rw reg_rw
;
1204 reg_rw
.type
= cpu_to_le32(reg_type
);
1205 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1206 ret
= mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_GET
);
1211 *value
= le32_to_cpu(reg_rw
.value
);
1218 * Sends IOCTL request to read from EEPROM.
1220 * This function allocates the IOCTL request buffer, fills it
1221 * with requisite parameters and calls the IOCTL handler.
1224 mwifiex_eeprom_read(struct mwifiex_private
*priv
, u16 offset
, u16 bytes
,
1228 struct mwifiex_ds_read_eeprom rd_eeprom
;
1230 rd_eeprom
.offset
= cpu_to_le16((u16
) offset
);
1231 rd_eeprom
.byte_count
= cpu_to_le16((u16
) bytes
);
1233 /* Send request to firmware */
1234 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_EEPROM_ACCESS
,
1235 HostCmd_ACT_GEN_GET
, 0, &rd_eeprom
);
1238 memcpy(value
, rd_eeprom
.value
, MAX_EEPROM_DATA
);
1243 * This function sets a generic IE. In addition to generic IE, it can
1244 * also handle WPA, WPA2 and WAPI IEs.
1247 mwifiex_set_gen_ie_helper(struct mwifiex_private
*priv
, u8
*ie_data_ptr
,
1251 struct ieee_types_vendor_header
*pvendor_ie
;
1252 const u8 wpa_oui
[] = { 0x00, 0x50, 0xf2, 0x01 };
1253 const u8 wps_oui
[] = { 0x00, 0x50, 0xf2, 0x04 };
1255 /* If the passed length is zero, reset the buffer */
1257 priv
->gen_ie_buf_len
= 0;
1258 priv
->wps
.session_enable
= false;
1261 } else if (!ie_data_ptr
) {
1264 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1265 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1266 if (((pvendor_ie
->element_id
== WLAN_EID_VENDOR_SPECIFIC
) &&
1267 (!memcmp(pvendor_ie
->oui
, wpa_oui
, sizeof(wpa_oui
)))) ||
1268 (pvendor_ie
->element_id
== WLAN_EID_RSN
)) {
1270 /* IE is a WPA/WPA2 IE so call set_wpa function */
1271 ret
= mwifiex_set_wpa_ie_helper(priv
, ie_data_ptr
, ie_len
);
1272 priv
->wps
.session_enable
= false;
1275 } else if (pvendor_ie
->element_id
== WLAN_EID_BSS_AC_ACCESS_DELAY
) {
1276 /* IE is a WAPI IE so call set_wapi function */
1277 ret
= mwifiex_set_wapi_ie(priv
, ie_data_ptr
, ie_len
);
1282 * Verify that the passed length is not larger than the
1283 * available space remaining in the buffer
1285 if (ie_len
< (sizeof(priv
->gen_ie_buf
) - priv
->gen_ie_buf_len
)) {
1287 /* Test to see if it is a WPS IE, if so, enable
1290 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1291 if ((pvendor_ie
->element_id
== WLAN_EID_VENDOR_SPECIFIC
) &&
1292 (!memcmp(pvendor_ie
->oui
, wps_oui
, sizeof(wps_oui
)))) {
1293 priv
->wps
.session_enable
= true;
1294 dev_dbg(priv
->adapter
->dev
,
1295 "info: WPS Session Enabled.\n");
1296 ret
= mwifiex_set_wps_ie(priv
, ie_data_ptr
, ie_len
);
1299 /* Append the passed data to the end of the
1301 memcpy(priv
->gen_ie_buf
+ priv
->gen_ie_buf_len
, ie_data_ptr
,
1303 /* Increment the stored buffer length by the
1305 priv
->gen_ie_buf_len
+= ie_len
;
1307 /* Passed data does not fit in the remaining
1312 /* Return 0, or -1 for error case */
1317 * IOCTL request handler to set/get generic IE.
1319 * In addition to various generic IEs, this function can also be
1320 * used to set the ARP filter.
1322 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private
*priv
,
1323 struct mwifiex_ds_misc_gen_ie
*gen_ie
,
1326 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1328 switch (gen_ie
->type
) {
1329 case MWIFIEX_IE_TYPE_GEN_IE
:
1330 if (action
== HostCmd_ACT_GEN_GET
) {
1331 gen_ie
->len
= priv
->wpa_ie_len
;
1332 memcpy(gen_ie
->ie_data
, priv
->wpa_ie
, gen_ie
->len
);
1334 mwifiex_set_gen_ie_helper(priv
, gen_ie
->ie_data
,
1338 case MWIFIEX_IE_TYPE_ARP_FILTER
:
1339 memset(adapter
->arp_filter
, 0, sizeof(adapter
->arp_filter
));
1340 if (gen_ie
->len
> ARP_FILTER_MAX_BUF_SIZE
) {
1341 adapter
->arp_filter_size
= 0;
1342 dev_err(adapter
->dev
, "invalid ARP filter size\n");
1345 memcpy(adapter
->arp_filter
, gen_ie
->ie_data
,
1347 adapter
->arp_filter_size
= gen_ie
->len
;
1351 dev_err(adapter
->dev
, "invalid IE type\n");
1358 * Sends IOCTL request to set a generic IE.
1360 * This function allocates the IOCTL request buffer, fills it
1361 * with requisite parameters and calls the IOCTL handler.
1364 mwifiex_set_gen_ie(struct mwifiex_private
*priv
, u8
*ie
, int ie_len
)
1366 struct mwifiex_ds_misc_gen_ie gen_ie
;
1368 if (ie_len
> IEEE_MAX_IE_SIZE
)
1371 gen_ie
.type
= MWIFIEX_IE_TYPE_GEN_IE
;
1372 gen_ie
.len
= ie_len
;
1373 memcpy(gen_ie
.ie_data
, ie
, ie_len
);
1374 if (mwifiex_misc_ioctl_gen_ie(priv
, &gen_ie
, HostCmd_ACT_GEN_SET
))