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.
30 * Copies the multicast address list from device to driver.
32 * This function does not validate the destination memory for
33 * size, and the calling function must ensure enough memory is
36 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list
*mlist
,
37 struct net_device
*dev
)
40 struct netdev_hw_addr
*ha
;
42 netdev_for_each_mc_addr(ha
, dev
)
43 memcpy(&mlist
->mac_list
[i
++], ha
->addr
, ETH_ALEN
);
49 * Wait queue completion handler.
51 * This function waits on a cmd wait queue. It also cancels the pending
52 * request after waking up, in case of errors.
54 int mwifiex_wait_queue_complete(struct mwifiex_adapter
*adapter
)
56 bool cancel_flag
= false;
57 int status
= adapter
->cmd_wait_q
.status
;
58 struct cmd_ctrl_node
*cmd_queued
= adapter
->cmd_queued
;
60 adapter
->cmd_queued
= NULL
;
61 dev_dbg(adapter
->dev
, "cmd pending\n");
62 atomic_inc(&adapter
->cmd_pending
);
64 /* Status pending, wake up main process */
65 queue_work(adapter
->workqueue
, &adapter
->main_work
);
67 /* Wait for completion */
68 wait_event_interruptible(adapter
->cmd_wait_q
.wait
,
69 *(cmd_queued
->condition
));
70 if (!*(cmd_queued
->condition
))
74 mwifiex_cancel_pending_ioctl(adapter
);
75 dev_dbg(adapter
->dev
, "cmd cancel\n");
77 adapter
->cmd_wait_q
.status
= 0;
83 * This function prepares the correct firmware command and
84 * issues it to set the multicast list.
86 * This function can be used to enable promiscuous mode, or enable all
87 * multicast packets, or to enable selective multicast.
89 int mwifiex_request_set_multicast_list(struct mwifiex_private
*priv
,
90 struct mwifiex_multicast_list
*mcast_list
)
95 old_pkt_filter
= priv
->curr_pkt_filter
;
97 if (mcast_list
->mode
== MWIFIEX_PROMISC_MODE
) {
98 dev_dbg(priv
->adapter
->dev
, "info: Enable Promiscuous mode\n");
99 priv
->curr_pkt_filter
|= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE
;
100 priv
->curr_pkt_filter
&=
101 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
104 priv
->curr_pkt_filter
&= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE
;
105 if (mcast_list
->mode
== MWIFIEX_MULTICAST_MODE
) {
106 dev_dbg(priv
->adapter
->dev
,
107 "info: Enabling All Multicast!\n");
108 priv
->curr_pkt_filter
|=
109 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
111 priv
->curr_pkt_filter
&=
112 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE
;
113 if (mcast_list
->num_multicast_addr
) {
114 dev_dbg(priv
->adapter
->dev
,
115 "info: Set multicast list=%d\n",
116 mcast_list
->num_multicast_addr
);
117 /* Set multicast addresses to firmware */
118 if (old_pkt_filter
== priv
->curr_pkt_filter
) {
119 /* Send request to firmware */
120 ret
= mwifiex_send_cmd_async(priv
,
121 HostCmd_CMD_MAC_MULTICAST_ADR
,
122 HostCmd_ACT_GEN_SET
, 0,
125 /* Send request to firmware */
126 ret
= mwifiex_send_cmd_async(priv
,
127 HostCmd_CMD_MAC_MULTICAST_ADR
,
128 HostCmd_ACT_GEN_SET
, 0,
134 dev_dbg(priv
->adapter
->dev
,
135 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
136 old_pkt_filter
, priv
->curr_pkt_filter
);
137 if (old_pkt_filter
!= priv
->curr_pkt_filter
) {
138 ret
= mwifiex_send_cmd_async(priv
, HostCmd_CMD_MAC_CONTROL
,
140 0, &priv
->curr_pkt_filter
);
147 * This function fills bss descriptor structure using provided
150 int mwifiex_fill_new_bss_desc(struct mwifiex_private
*priv
,
151 u8
*bssid
, s32 rssi
, u8
*ie_buf
,
152 size_t ie_len
, u16 beacon_period
,
153 u16 cap_info_bitmap
, u8 band
,
154 struct mwifiex_bssdescriptor
*bss_desc
)
158 memcpy(bss_desc
->mac_address
, bssid
, ETH_ALEN
);
159 bss_desc
->rssi
= rssi
;
160 bss_desc
->beacon_buf
= ie_buf
;
161 bss_desc
->beacon_buf_size
= ie_len
;
162 bss_desc
->beacon_period
= beacon_period
;
163 bss_desc
->cap_info_bitmap
= cap_info_bitmap
;
164 bss_desc
->bss_band
= band
;
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 ret
= mwifiex_update_bss_desc_with_ie(priv
->adapter
, bss_desc
,
183 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
184 * In both Ad-Hoc and infra mode, an deauthentication is performed
187 int mwifiex_bss_start(struct mwifiex_private
*priv
, struct cfg80211_bss
*bss
,
188 struct mwifiex_802_11_ssid
*req_ssid
)
191 struct mwifiex_adapter
*adapter
= priv
->adapter
;
192 struct mwifiex_bssdescriptor
*bss_desc
= NULL
;
193 u8
*beacon_ie
= NULL
;
195 priv
->scan_block
= false;
198 /* Allocate and fill new bss descriptor */
199 bss_desc
= kzalloc(sizeof(struct mwifiex_bssdescriptor
),
202 dev_err(priv
->adapter
->dev
, " failed to alloc bss_desc\n");
206 beacon_ie
= kmemdup(bss
->information_elements
,
207 bss
->len_beacon_ies
, GFP_KERNEL
);
210 dev_err(priv
->adapter
->dev
, " failed to alloc beacon_ie\n");
214 ret
= mwifiex_fill_new_bss_desc(priv
, bss
->bssid
, bss
->signal
,
215 beacon_ie
, bss
->len_beacon_ies
,
216 bss
->beacon_interval
,
218 *(u8
*)bss
->priv
, bss_desc
);
223 if (priv
->bss_mode
== NL80211_IFTYPE_STATION
) {
225 ret
= mwifiex_deauthenticate(priv
, NULL
);
229 ret
= mwifiex_check_network_compatibility(priv
, bss_desc
);
233 dev_dbg(adapter
->dev
, "info: SSID found in scan list ... "
236 if (!netif_queue_stopped(priv
->netdev
))
237 netif_stop_queue(priv
->netdev
);
239 /* Clear any past association response stored for
240 * application retrieval */
241 priv
->assoc_rsp_size
= 0;
242 ret
= mwifiex_associate(priv
, bss_desc
);
244 cfg80211_put_bss(bss
);
247 /* If the requested SSID matches current SSID, return */
248 if (bss_desc
&& bss_desc
->ssid
.ssid_len
&&
250 (&priv
->curr_bss_params
.bss_descriptor
.ssid
,
257 /* Exit Adhoc mode first */
258 dev_dbg(adapter
->dev
, "info: Sending Adhoc Stop\n");
259 ret
= mwifiex_deauthenticate(priv
, NULL
);
263 priv
->adhoc_is_link_sensed
= false;
265 ret
= mwifiex_check_network_compatibility(priv
, bss_desc
);
267 if (!netif_queue_stopped(priv
->netdev
))
268 netif_stop_queue(priv
->netdev
);
271 dev_dbg(adapter
->dev
, "info: network found in scan"
272 " list. Joining...\n");
273 ret
= mwifiex_adhoc_join(priv
, bss_desc
);
275 cfg80211_put_bss(bss
);
277 dev_dbg(adapter
->dev
, "info: Network not found in "
278 "the list, creating adhoc with ssid = %s\n",
280 ret
= mwifiex_adhoc_start(priv
, req_ssid
);
291 * IOCTL request handler to set host sleep configuration.
293 * This function prepares the correct firmware command and
296 static int mwifiex_set_hs_params(struct mwifiex_private
*priv
, u16 action
,
297 int cmd_type
, struct mwifiex_ds_hs_cfg
*hs_cfg
)
300 struct mwifiex_adapter
*adapter
= priv
->adapter
;
308 case HostCmd_ACT_GEN_SET
:
309 if (adapter
->pps_uapsd_mode
) {
310 dev_dbg(adapter
->dev
, "info: Host Sleep IOCTL"
311 " is blocked in UAPSD/PPS mode\n");
315 if (hs_cfg
->is_invoke_hostcmd
) {
316 if (hs_cfg
->conditions
== HOST_SLEEP_CFG_CANCEL
) {
317 if (!adapter
->is_hs_configured
)
318 /* Already cancelled */
320 /* Save previous condition */
321 prev_cond
= le32_to_cpu(adapter
->hs_cfg
323 adapter
->hs_cfg
.conditions
=
324 cpu_to_le32(hs_cfg
->conditions
);
325 } else if (hs_cfg
->conditions
) {
326 adapter
->hs_cfg
.conditions
=
327 cpu_to_le32(hs_cfg
->conditions
);
328 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
330 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
331 } else if (adapter
->hs_cfg
.conditions
==
333 HOST_SLEEP_CFG_CANCEL
)) {
334 /* Return failure if no parameters for HS
339 if (cmd_type
== MWIFIEX_SYNC_CMD
)
340 status
= mwifiex_send_cmd_sync(priv
,
341 HostCmd_CMD_802_11_HS_CFG_ENH
,
342 HostCmd_ACT_GEN_SET
, 0,
345 status
= mwifiex_send_cmd_async(priv
,
346 HostCmd_CMD_802_11_HS_CFG_ENH
,
347 HostCmd_ACT_GEN_SET
, 0,
349 if (hs_cfg
->conditions
== HOST_SLEEP_CFG_CANCEL
)
350 /* Restore previous condition */
351 adapter
->hs_cfg
.conditions
=
352 cpu_to_le32(prev_cond
);
354 adapter
->hs_cfg
.conditions
=
355 cpu_to_le32(hs_cfg
->conditions
);
356 adapter
->hs_cfg
.gpio
= (u8
)hs_cfg
->gpio
;
357 adapter
->hs_cfg
.gap
= (u8
)hs_cfg
->gap
;
360 case HostCmd_ACT_GEN_GET
:
361 hs_cfg
->conditions
= le32_to_cpu(adapter
->hs_cfg
.conditions
);
362 hs_cfg
->gpio
= adapter
->hs_cfg
.gpio
;
363 hs_cfg
->gap
= adapter
->hs_cfg
.gap
;
374 * Sends IOCTL request to cancel the existing Host Sleep configuration.
376 * This function allocates the IOCTL request buffer, fills it
377 * with requisite parameters and calls the IOCTL handler.
379 int mwifiex_cancel_hs(struct mwifiex_private
*priv
, int cmd_type
)
381 struct mwifiex_ds_hs_cfg hscfg
;
383 hscfg
.conditions
= HOST_SLEEP_CFG_CANCEL
;
384 hscfg
.is_invoke_hostcmd
= true;
386 return mwifiex_set_hs_params(priv
, HostCmd_ACT_GEN_SET
,
389 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs
);
392 * Sends IOCTL request to cancel the existing Host Sleep configuration.
394 * This function allocates the IOCTL request buffer, fills it
395 * with requisite parameters and calls the IOCTL handler.
397 int mwifiex_enable_hs(struct mwifiex_adapter
*adapter
)
399 struct mwifiex_ds_hs_cfg hscfg
;
401 if (adapter
->hs_activated
) {
402 dev_dbg(adapter
->dev
, "cmd: HS Already actived\n");
406 adapter
->hs_activate_wait_q_woken
= false;
408 memset(&hscfg
, 0, sizeof(struct mwifiex_hs_config_param
));
409 hscfg
.is_invoke_hostcmd
= true;
411 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter
,
412 MWIFIEX_BSS_ROLE_STA
),
413 HostCmd_ACT_GEN_SET
, MWIFIEX_SYNC_CMD
,
415 dev_err(adapter
->dev
, "IOCTL request HS enable failed\n");
419 wait_event_interruptible(adapter
->hs_activate_wait_q
,
420 adapter
->hs_activate_wait_q_woken
);
424 EXPORT_SYMBOL_GPL(mwifiex_enable_hs
);
427 * IOCTL request handler to get BSS information.
429 * This function collates the information from different driver structures
430 * to send to the user.
432 int mwifiex_get_bss_info(struct mwifiex_private
*priv
,
433 struct mwifiex_bss_info
*info
)
435 struct mwifiex_adapter
*adapter
= priv
->adapter
;
436 struct mwifiex_bssdescriptor
*bss_desc
;
441 bss_desc
= &priv
->curr_bss_params
.bss_descriptor
;
443 info
->bss_mode
= priv
->bss_mode
;
445 memcpy(&info
->ssid
, &bss_desc
->ssid
,
446 sizeof(struct mwifiex_802_11_ssid
));
448 memcpy(&info
->bssid
, &bss_desc
->mac_address
, ETH_ALEN
);
450 info
->bss_chan
= bss_desc
->channel
;
452 info
->region_code
= adapter
->region_code
;
454 info
->media_connected
= priv
->media_connected
;
456 info
->max_power_level
= priv
->max_tx_power_level
;
457 info
->min_power_level
= priv
->min_tx_power_level
;
459 info
->adhoc_state
= priv
->adhoc_state
;
461 info
->bcn_nf_last
= priv
->bcn_nf_last
;
463 if (priv
->sec_info
.wep_status
== MWIFIEX_802_11_WEP_ENABLED
)
464 info
->wep_status
= true;
466 info
->wep_status
= false;
468 info
->is_hs_configured
= adapter
->is_hs_configured
;
469 info
->is_deep_sleep
= adapter
->is_deep_sleep
;
475 * The function sets band configurations.
477 * it performs extra checks to make sure the Ad-Hoc
478 * band and channel are compatible. Otherwise it returns an error.
481 int mwifiex_set_radio_band_cfg(struct mwifiex_private
*priv
,
482 struct mwifiex_ds_band_cfg
*radio_cfg
)
484 struct mwifiex_adapter
*adapter
= priv
->adapter
;
485 u8 infra_band
, adhoc_band
;
488 infra_band
= (u8
) radio_cfg
->config_bands
;
489 adhoc_band
= (u8
) radio_cfg
->adhoc_start_band
;
490 adhoc_channel
= radio_cfg
->adhoc_channel
;
493 if ((infra_band
| adapter
->fw_bands
) & ~adapter
->fw_bands
)
496 adapter
->config_bands
= infra_band
;
498 /* SET Ad-hoc Band */
499 if ((adhoc_band
| adapter
->fw_bands
) & ~adapter
->fw_bands
)
503 adapter
->adhoc_start_band
= adhoc_band
;
504 adapter
->chan_offset
= (u8
) radio_cfg
->sec_chan_offset
;
506 * If no adhoc_channel is supplied verify if the existing adhoc
507 * channel compiles with new adhoc_band
509 if (!adhoc_channel
) {
510 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
511 (priv
, adapter
->adhoc_start_band
,
512 priv
->adhoc_channel
)) {
513 /* Pass back the default channel */
514 radio_cfg
->adhoc_channel
= DEFAULT_AD_HOC_CHANNEL
;
515 if ((adapter
->adhoc_start_band
& BAND_A
)
516 || (adapter
->adhoc_start_band
& BAND_AN
))
517 radio_cfg
->adhoc_channel
=
518 DEFAULT_AD_HOC_CHANNEL_A
;
520 } else { /* Retrurn error if adhoc_band and
521 adhoc_channel combination is invalid */
522 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
523 (priv
, adapter
->adhoc_start_band
, (u16
) adhoc_channel
))
525 priv
->adhoc_channel
= (u8
) adhoc_channel
;
527 if ((adhoc_band
& BAND_GN
) || (adhoc_band
& BAND_AN
))
528 adapter
->adhoc_11n_enabled
= true;
530 adapter
->adhoc_11n_enabled
= false;
536 * The function disables auto deep sleep mode.
538 int mwifiex_disable_auto_ds(struct mwifiex_private
*priv
)
540 struct mwifiex_ds_auto_ds auto_ds
;
542 auto_ds
.auto_ds
= DEEP_SLEEP_OFF
;
544 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
545 DIS_AUTO_PS
, BITMAP_AUTO_DS
, &auto_ds
);
547 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds
);
550 * IOCTL request handler to set/get active channel.
552 * This function performs validity checking on channel/frequency
553 * compatibility and returns failure if not valid.
555 int mwifiex_bss_set_channel(struct mwifiex_private
*priv
,
556 struct mwifiex_chan_freq_power
*chan
)
558 struct mwifiex_adapter
*adapter
= priv
->adapter
;
559 struct mwifiex_chan_freq_power
*cfp
= NULL
;
564 if (!chan
->channel
&& !chan
->freq
)
566 if (adapter
->adhoc_start_band
& BAND_AN
)
567 adapter
->adhoc_start_band
= BAND_G
| BAND_B
| BAND_GN
;
568 else if (adapter
->adhoc_start_band
& BAND_A
)
569 adapter
->adhoc_start_band
= BAND_G
| BAND_B
;
571 if (chan
->channel
<= MAX_CHANNEL_BAND_BG
)
572 cfp
= mwifiex_get_cfp_by_band_and_channel_from_cfg80211
573 (priv
, 0, (u16
) chan
->channel
);
575 cfp
= mwifiex_get_cfp_by_band_and_channel_from_cfg80211
576 (priv
, BAND_A
, (u16
) chan
->channel
);
578 if (adapter
->adhoc_11n_enabled
)
579 adapter
->adhoc_start_band
= BAND_A
582 adapter
->adhoc_start_band
= BAND_A
;
586 if (chan
->freq
<= MAX_FREQUENCY_BAND_BG
)
587 cfp
= mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
588 priv
, 0, chan
->freq
);
590 cfp
= mwifiex_get_cfp_by_band_and_freq_from_cfg80211
591 (priv
, BAND_A
, chan
->freq
);
593 if (adapter
->adhoc_11n_enabled
)
594 adapter
->adhoc_start_band
= BAND_A
597 adapter
->adhoc_start_band
= BAND_A
;
601 if (!cfp
|| !cfp
->channel
) {
602 dev_err(adapter
->dev
, "invalid channel/freq\n");
605 priv
->adhoc_channel
= (u8
) cfp
->channel
;
606 chan
->channel
= cfp
->channel
;
607 chan
->freq
= cfp
->freq
;
613 * IOCTL request handler to set/get Ad-Hoc channel.
615 * This function prepares the correct firmware command and
616 * issues it to set or get the ad-hoc channel.
618 static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private
*priv
,
619 u16 action
, u16
*channel
)
621 if (action
== HostCmd_ACT_GEN_GET
) {
622 if (!priv
->media_connected
) {
623 *channel
= priv
->adhoc_channel
;
627 priv
->adhoc_channel
= (u8
) *channel
;
630 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_RF_CHANNEL
,
635 * IOCTL request handler to change Ad-Hoc channel.
637 * This function allocates the IOCTL request buffer, fills it
638 * with requisite parameters and calls the IOCTL handler.
640 * The function follows the following steps to perform the change -
641 * - Get current IBSS information
642 * - Get current channel
643 * - If no change is required, return
644 * - If not connected, change channel and return
648 * - Perform specific SSID scan with same SSID
649 * - Start/Join the IBSS
652 mwifiex_drv_change_adhoc_chan(struct mwifiex_private
*priv
, int channel
)
655 struct mwifiex_bss_info bss_info
;
656 struct mwifiex_ssid_bssid ssid_bssid
;
658 struct cfg80211_bss
*bss
= NULL
;
659 struct ieee80211_channel
*chan
;
660 enum ieee80211_band band
;
662 memset(&bss_info
, 0, sizeof(bss_info
));
664 /* Get BSS information */
665 if (mwifiex_get_bss_info(priv
, &bss_info
))
668 /* Get current channel */
669 ret
= mwifiex_bss_ioctl_ibss_channel(priv
, HostCmd_ACT_GEN_GET
,
672 if (curr_chan
== channel
) {
676 dev_dbg(priv
->adapter
->dev
, "cmd: updating channel from %d to %d\n",
679 if (!bss_info
.media_connected
) {
685 memset(&ssid_bssid
, 0, ETH_ALEN
);
686 ret
= mwifiex_deauthenticate(priv
, ssid_bssid
.bssid
);
688 ret
= mwifiex_bss_ioctl_ibss_channel(priv
, HostCmd_ACT_GEN_SET
,
691 /* Do specific SSID scanning */
692 if (mwifiex_request_scan(priv
, &bss_info
.ssid
)) {
697 band
= mwifiex_band_to_radio_type(priv
->curr_bss_params
.band
);
698 chan
= __ieee80211_get_channel(priv
->wdev
->wiphy
,
699 ieee80211_channel_to_frequency(channel
, band
));
701 /* Find the BSS we want using available scan results */
702 bss
= cfg80211_get_bss(priv
->wdev
->wiphy
, chan
, bss_info
.bssid
,
703 bss_info
.ssid
.ssid
, bss_info
.ssid
.ssid_len
,
704 WLAN_CAPABILITY_ESS
, WLAN_CAPABILITY_ESS
);
706 wiphy_warn(priv
->wdev
->wiphy
, "assoc: bss %pM not in scan results\n",
709 ret
= mwifiex_bss_start(priv
, bss
, &bss_info
.ssid
);
715 * IOCTL request handler to get rate.
717 * This function prepares the correct firmware command and
718 * issues it to get the current rate if it is connected,
719 * otherwise, the function returns the lowest supported rate
722 static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private
*priv
,
723 struct mwifiex_rate_cfg
*rate_cfg
)
725 rate_cfg
->is_rate_auto
= priv
->is_data_rate_auto
;
726 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_TX_RATE_QUERY
,
727 HostCmd_ACT_GEN_GET
, 0, NULL
);
731 * IOCTL request handler to set rate.
733 * This function prepares the correct firmware command and
734 * issues it to set the current rate.
736 * The function also performs validation checking on the supplied value.
738 static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private
*priv
,
739 struct mwifiex_rate_cfg
*rate_cfg
)
741 u8 rates
[MWIFIEX_SUPPORTED_RATES
];
744 u16 bitmap_rates
[MAX_BITMAP_RATES_SIZE
];
746 struct mwifiex_adapter
*adapter
= priv
->adapter
;
748 if (rate_cfg
->is_rate_auto
) {
749 memset(bitmap_rates
, 0, sizeof(bitmap_rates
));
750 /* Support all HR/DSSS rates */
751 bitmap_rates
[0] = 0x000F;
752 /* Support all OFDM rates */
753 bitmap_rates
[1] = 0x00FF;
754 /* Support all HT-MCSs rate */
755 for (i
= 0; i
< ARRAY_SIZE(priv
->bitmap_rates
) - 3; i
++)
756 bitmap_rates
[i
+ 2] = 0xFFFF;
757 bitmap_rates
[9] = 0x3FFF;
759 memset(rates
, 0, sizeof(rates
));
760 mwifiex_get_active_data_rates(priv
, rates
);
762 for (i
= 0; (rate
[i
] && i
< MWIFIEX_SUPPORTED_RATES
); i
++) {
763 dev_dbg(adapter
->dev
, "info: rate=%#x wanted=%#x\n",
764 rate
[i
], rate_cfg
->rate
);
765 if ((rate
[i
] & 0x7f) == (rate_cfg
->rate
& 0x7f))
768 if ((i
== MWIFIEX_SUPPORTED_RATES
) || !rate
[i
]) {
769 dev_err(adapter
->dev
, "fixed data rate %#x is out "
770 "of range\n", rate_cfg
->rate
);
773 memset(bitmap_rates
, 0, sizeof(bitmap_rates
));
775 rate_index
= mwifiex_data_rate_to_index(rate_cfg
->rate
);
777 /* Only allow b/g rates to be set */
778 if (rate_index
>= MWIFIEX_RATE_INDEX_HRDSSS0
&&
779 rate_index
<= MWIFIEX_RATE_INDEX_HRDSSS3
) {
780 bitmap_rates
[0] = 1 << rate_index
;
782 rate_index
-= 1; /* There is a 0x00 in the table */
783 if (rate_index
>= MWIFIEX_RATE_INDEX_OFDM0
&&
784 rate_index
<= MWIFIEX_RATE_INDEX_OFDM7
)
785 bitmap_rates
[1] = 1 << (rate_index
-
786 MWIFIEX_RATE_INDEX_OFDM0
);
790 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_TX_RATE_CFG
,
791 HostCmd_ACT_GEN_SET
, 0, bitmap_rates
);
797 * IOCTL request handler to set/get rate.
799 * This function can be used to set/get either the rate value or the
802 static int mwifiex_rate_ioctl_cfg(struct mwifiex_private
*priv
,
803 struct mwifiex_rate_cfg
*rate_cfg
)
810 if (rate_cfg
->action
== HostCmd_ACT_GEN_GET
)
811 status
= mwifiex_rate_ioctl_get_rate_value(priv
, rate_cfg
);
813 status
= mwifiex_rate_ioctl_set_rate_value(priv
, rate_cfg
);
819 * Sends IOCTL request to get the data rate.
821 * This function allocates the IOCTL request buffer, fills it
822 * with requisite parameters and calls the IOCTL handler.
824 int mwifiex_drv_get_data_rate(struct mwifiex_private
*priv
,
825 struct mwifiex_rate_cfg
*rate
)
829 memset(rate
, 0, sizeof(struct mwifiex_rate_cfg
));
830 rate
->action
= HostCmd_ACT_GEN_GET
;
831 ret
= mwifiex_rate_ioctl_cfg(priv
, rate
);
834 if (rate
->is_rate_auto
)
835 rate
->rate
= mwifiex_index_to_data_rate(priv
->tx_rate
,
838 rate
->rate
= priv
->data_rate
;
847 * IOCTL request handler to set tx power configuration.
849 * This function prepares the correct firmware command and
852 * For non-auto power mode, all the following power groups are set -
853 * - Modulation class HR/DSSS
854 * - Modulation class OFDM
855 * - Modulation class HTBW20
856 * - Modulation class HTBW40
858 int mwifiex_set_tx_power(struct mwifiex_private
*priv
,
859 struct mwifiex_power_cfg
*power_cfg
)
862 struct host_cmd_ds_txpwr_cfg
*txp_cfg
;
863 struct mwifiex_types_power_group
*pg_tlv
;
864 struct mwifiex_power_group
*pg
;
868 if (!power_cfg
->is_power_auto
) {
869 dbm
= (u16
) power_cfg
->power_level
;
870 if ((dbm
< priv
->min_tx_power_level
) ||
871 (dbm
> priv
->max_tx_power_level
)) {
872 dev_err(priv
->adapter
->dev
, "txpower value %d dBm"
873 " is out of range (%d dBm-%d dBm)\n",
874 dbm
, priv
->min_tx_power_level
,
875 priv
->max_tx_power_level
);
879 buf
= kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER
, GFP_KERNEL
);
881 dev_err(priv
->adapter
->dev
, "%s: failed to alloc cmd buffer\n",
886 txp_cfg
= (struct host_cmd_ds_txpwr_cfg
*) buf
;
887 txp_cfg
->action
= cpu_to_le16(HostCmd_ACT_GEN_SET
);
888 if (!power_cfg
->is_power_auto
) {
889 txp_cfg
->mode
= cpu_to_le32(1);
890 pg_tlv
= (struct mwifiex_types_power_group
*) (buf
+
891 sizeof(struct host_cmd_ds_txpwr_cfg
));
892 pg_tlv
->type
= TLV_TYPE_POWER_GROUP
;
893 pg_tlv
->length
= 4 * sizeof(struct mwifiex_power_group
);
894 pg
= (struct mwifiex_power_group
*) (buf
+
895 sizeof(struct host_cmd_ds_txpwr_cfg
) +
896 sizeof(struct mwifiex_types_power_group
));
897 /* Power group for modulation class HR/DSSS */
898 pg
->first_rate_code
= 0x00;
899 pg
->last_rate_code
= 0x03;
900 pg
->modulation_class
= MOD_CLASS_HR_DSSS
;
902 pg
->power_min
= (s8
) dbm
;
903 pg
->power_max
= (s8
) dbm
;
905 /* Power group for modulation class OFDM */
906 pg
->first_rate_code
= 0x00;
907 pg
->last_rate_code
= 0x07;
908 pg
->modulation_class
= MOD_CLASS_OFDM
;
910 pg
->power_min
= (s8
) dbm
;
911 pg
->power_max
= (s8
) dbm
;
913 /* Power group for modulation class HTBW20 */
914 pg
->first_rate_code
= 0x00;
915 pg
->last_rate_code
= 0x20;
916 pg
->modulation_class
= MOD_CLASS_HT
;
918 pg
->power_min
= (s8
) dbm
;
919 pg
->power_max
= (s8
) dbm
;
920 pg
->ht_bandwidth
= HT_BW_20
;
922 /* Power group for modulation class HTBW40 */
923 pg
->first_rate_code
= 0x00;
924 pg
->last_rate_code
= 0x20;
925 pg
->modulation_class
= MOD_CLASS_HT
;
927 pg
->power_min
= (s8
) dbm
;
928 pg
->power_max
= (s8
) dbm
;
929 pg
->ht_bandwidth
= HT_BW_40
;
931 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_TXPWR_CFG
,
932 HostCmd_ACT_GEN_SET
, 0, buf
);
939 * IOCTL request handler to get power save mode.
941 * This function prepares the correct firmware command and
944 int mwifiex_drv_set_power(struct mwifiex_private
*priv
, u32
*ps_mode
)
947 struct mwifiex_adapter
*adapter
= priv
->adapter
;
951 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_PSP
;
953 adapter
->ps_mode
= MWIFIEX_802_11_POWER_MODE_CAM
;
954 sub_cmd
= (*ps_mode
) ? EN_AUTO_PS
: DIS_AUTO_PS
;
955 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_PS_MODE_ENH
,
956 sub_cmd
, BITMAP_STA_PS
, NULL
);
957 if ((!ret
) && (sub_cmd
== DIS_AUTO_PS
))
958 ret
= mwifiex_send_cmd_async(priv
,
959 HostCmd_CMD_802_11_PS_MODE_ENH
, GET_PS
,
966 * IOCTL request handler to set/reset WPA IE.
968 * The supplied WPA IE is treated as a opaque buffer. Only the first field
969 * is checked to determine WPA version. If buffer length is zero, the existing
972 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private
*priv
,
973 u8
*ie_data_ptr
, u16 ie_len
)
976 if (ie_len
> sizeof(priv
->wpa_ie
)) {
977 dev_err(priv
->adapter
->dev
,
978 "failed to copy WPA IE, too big\n");
981 memcpy(priv
->wpa_ie
, ie_data_ptr
, ie_len
);
982 priv
->wpa_ie_len
= (u8
) ie_len
;
983 dev_dbg(priv
->adapter
->dev
, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
984 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
986 if (priv
->wpa_ie
[0] == WLAN_EID_WPA
) {
987 priv
->sec_info
.wpa_enabled
= true;
988 } else if (priv
->wpa_ie
[0] == WLAN_EID_RSN
) {
989 priv
->sec_info
.wpa2_enabled
= true;
991 priv
->sec_info
.wpa_enabled
= false;
992 priv
->sec_info
.wpa2_enabled
= false;
995 memset(priv
->wpa_ie
, 0, sizeof(priv
->wpa_ie
));
996 priv
->wpa_ie_len
= 0;
997 dev_dbg(priv
->adapter
->dev
, "info: reset wpa_ie_len=%d IE=%#x\n",
998 priv
->wpa_ie_len
, priv
->wpa_ie
[0]);
999 priv
->sec_info
.wpa_enabled
= false;
1000 priv
->sec_info
.wpa2_enabled
= false;
1007 * IOCTL request handler to set/reset WAPI IE.
1009 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
1010 * is checked to internally enable WAPI. If buffer length is zero, the existing
1013 static int mwifiex_set_wapi_ie(struct mwifiex_private
*priv
,
1014 u8
*ie_data_ptr
, u16 ie_len
)
1017 if (ie_len
> sizeof(priv
->wapi_ie
)) {
1018 dev_dbg(priv
->adapter
->dev
,
1019 "info: failed to copy WAPI IE, too big\n");
1022 memcpy(priv
->wapi_ie
, ie_data_ptr
, ie_len
);
1023 priv
->wapi_ie_len
= ie_len
;
1024 dev_dbg(priv
->adapter
->dev
, "cmd: Set wapi_ie_len=%d IE=%#x\n",
1025 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
1027 if (priv
->wapi_ie
[0] == WLAN_EID_BSS_AC_ACCESS_DELAY
)
1028 priv
->sec_info
.wapi_enabled
= true;
1030 memset(priv
->wapi_ie
, 0, sizeof(priv
->wapi_ie
));
1031 priv
->wapi_ie_len
= ie_len
;
1032 dev_dbg(priv
->adapter
->dev
,
1033 "info: Reset wapi_ie_len=%d IE=%#x\n",
1034 priv
->wapi_ie_len
, priv
->wapi_ie
[0]);
1035 priv
->sec_info
.wapi_enabled
= false;
1041 * IOCTL request handler to set WAPI key.
1043 * This function prepares the correct firmware command and
1046 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private
*priv
,
1047 struct mwifiex_ds_encrypt_key
*encrypt_key
)
1050 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_KEY_MATERIAL
,
1051 HostCmd_ACT_GEN_SET
, KEY_INFO_ENABLED
,
1056 * IOCTL request handler to set WEP network key.
1058 * This function prepares the correct firmware command and
1059 * issues it, after validation checks.
1061 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private
*priv
,
1062 struct mwifiex_ds_encrypt_key
*encrypt_key
)
1065 struct mwifiex_wep_key
*wep_key
;
1068 if (priv
->wep_key_curr_index
>= NUM_WEP_KEYS
)
1069 priv
->wep_key_curr_index
= 0;
1070 wep_key
= &priv
->wep_key
[priv
->wep_key_curr_index
];
1071 index
= encrypt_key
->key_index
;
1072 if (encrypt_key
->key_disable
) {
1073 priv
->sec_info
.wep_status
= MWIFIEX_802_11_WEP_DISABLED
;
1074 } else if (!encrypt_key
->key_len
) {
1075 /* Copy the required key as the current key */
1076 wep_key
= &priv
->wep_key
[index
];
1077 if (!wep_key
->key_length
) {
1078 dev_err(priv
->adapter
->dev
,
1079 "key not set, so cannot enable it\n");
1082 priv
->wep_key_curr_index
= (u16
) index
;
1083 priv
->sec_info
.wep_status
= MWIFIEX_802_11_WEP_ENABLED
;
1085 wep_key
= &priv
->wep_key
[index
];
1086 memset(wep_key
, 0, sizeof(struct mwifiex_wep_key
));
1087 /* Copy the key in the driver */
1088 memcpy(wep_key
->key_material
,
1089 encrypt_key
->key_material
,
1090 encrypt_key
->key_len
);
1091 wep_key
->key_index
= index
;
1092 wep_key
->key_length
= encrypt_key
->key_len
;
1093 priv
->sec_info
.wep_status
= MWIFIEX_802_11_WEP_ENABLED
;
1095 if (wep_key
->key_length
) {
1096 /* Send request to firmware */
1097 ret
= mwifiex_send_cmd_async(priv
,
1098 HostCmd_CMD_802_11_KEY_MATERIAL
,
1099 HostCmd_ACT_GEN_SET
, 0, NULL
);
1103 if (priv
->sec_info
.wep_status
== MWIFIEX_802_11_WEP_ENABLED
)
1104 priv
->curr_pkt_filter
|= HostCmd_ACT_MAC_WEP_ENABLE
;
1106 priv
->curr_pkt_filter
&= ~HostCmd_ACT_MAC_WEP_ENABLE
;
1108 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_MAC_CONTROL
,
1109 HostCmd_ACT_GEN_SET
, 0,
1110 &priv
->curr_pkt_filter
);
1116 * IOCTL request handler to set WPA key.
1118 * This function prepares the correct firmware command and
1119 * issues it, after validation checks.
1121 * Current driver only supports key length of up to 32 bytes.
1123 * This function can also be used to disable a currently set key.
1125 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private
*priv
,
1126 struct mwifiex_ds_encrypt_key
*encrypt_key
)
1129 u8 remove_key
= false;
1130 struct host_cmd_ds_802_11_key_material
*ibss_key
;
1132 /* Current driver only supports key length of up to 32 bytes */
1133 if (encrypt_key
->key_len
> WLAN_MAX_KEY_LEN
) {
1134 dev_err(priv
->adapter
->dev
, "key length too long\n");
1138 if (priv
->bss_mode
== NL80211_IFTYPE_ADHOC
) {
1140 * IBSS/WPA-None uses only one key (Group) for both receiving
1141 * and sending unicast and multicast packets.
1143 /* Send the key as PTK to firmware */
1144 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
1145 ret
= mwifiex_send_cmd_async(priv
,
1146 HostCmd_CMD_802_11_KEY_MATERIAL
,
1147 HostCmd_ACT_GEN_SET
, KEY_INFO_ENABLED
,
1152 ibss_key
= &priv
->aes_key
;
1154 sizeof(struct host_cmd_ds_802_11_key_material
));
1155 /* Copy the key in the driver */
1156 memcpy(ibss_key
->key_param_set
.key
, encrypt_key
->key_material
,
1157 encrypt_key
->key_len
);
1158 memcpy(&ibss_key
->key_param_set
.key_len
, &encrypt_key
->key_len
,
1159 sizeof(ibss_key
->key_param_set
.key_len
));
1160 ibss_key
->key_param_set
.key_type_id
1161 = cpu_to_le16(KEY_TYPE_ID_TKIP
);
1162 ibss_key
->key_param_set
.key_info
= cpu_to_le16(KEY_ENABLED
);
1164 /* Send the key as GTK to firmware */
1165 encrypt_key
->key_index
= ~MWIFIEX_KEY_INDEX_UNICAST
;
1168 if (!encrypt_key
->key_index
)
1169 encrypt_key
->key_index
= MWIFIEX_KEY_INDEX_UNICAST
;
1172 ret
= mwifiex_send_cmd_sync(priv
,
1173 HostCmd_CMD_802_11_KEY_MATERIAL
,
1174 HostCmd_ACT_GEN_SET
, !(KEY_INFO_ENABLED
),
1177 ret
= mwifiex_send_cmd_sync(priv
,
1178 HostCmd_CMD_802_11_KEY_MATERIAL
,
1179 HostCmd_ACT_GEN_SET
, KEY_INFO_ENABLED
,
1186 * IOCTL request handler to set/get network keys.
1188 * This is a generic key handling function which supports WEP, WPA
1192 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private
*priv
,
1193 struct mwifiex_ds_encrypt_key
*encrypt_key
)
1197 if (encrypt_key
->is_wapi_key
)
1198 status
= mwifiex_sec_ioctl_set_wapi_key(priv
, encrypt_key
);
1199 else if (encrypt_key
->key_len
> WLAN_KEY_LEN_WEP104
)
1200 status
= mwifiex_sec_ioctl_set_wpa_key(priv
, encrypt_key
);
1202 status
= mwifiex_sec_ioctl_set_wep_key(priv
, encrypt_key
);
1207 * This function returns the driver version.
1210 mwifiex_drv_get_driver_version(struct mwifiex_adapter
*adapter
, char *version
,
1219 ver
.l
= adapter
->fw_release_number
;
1220 sprintf(fw_ver
, "%u.%u.%u.p%u", ver
.c
[2], ver
.c
[1], ver
.c
[0], ver
.c
[3]);
1222 snprintf(version
, max_len
, driver_version
, fw_ver
);
1224 dev_dbg(adapter
->dev
, "info: MWIFIEX VERSION: %s\n", version
);
1230 * Sends IOCTL request to get signal information.
1232 * This function allocates the IOCTL request buffer, fills it
1233 * with requisite parameters and calls the IOCTL handler.
1235 int mwifiex_get_signal_info(struct mwifiex_private
*priv
,
1236 struct mwifiex_ds_get_signal
*signal
)
1240 signal
->selector
= ALL_RSSI_INFO_MASK
;
1242 /* Signal info can be obtained only if connected */
1243 if (!priv
->media_connected
) {
1244 dev_dbg(priv
->adapter
->dev
,
1245 "info: Can not get signal in disconnected state\n");
1249 status
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_RSSI_INFO
,
1250 HostCmd_ACT_GEN_GET
, 0, signal
);
1253 if (signal
->selector
& BCN_RSSI_AVG_MASK
)
1254 priv
->qual_level
= signal
->bcn_rssi_avg
;
1255 if (signal
->selector
& BCN_NF_AVG_MASK
)
1256 priv
->qual_noise
= signal
->bcn_nf_avg
;
1263 * Sends IOCTL request to set encoding parameters.
1265 * This function allocates the IOCTL request buffer, fills it
1266 * with requisite parameters and calls the IOCTL handler.
1268 int mwifiex_set_encode(struct mwifiex_private
*priv
, const u8
*key
,
1269 int key_len
, u8 key_index
, int disable
)
1271 struct mwifiex_ds_encrypt_key encrypt_key
;
1273 memset(&encrypt_key
, 0, sizeof(struct mwifiex_ds_encrypt_key
));
1274 encrypt_key
.key_len
= key_len
;
1276 encrypt_key
.key_index
= key_index
;
1278 memcpy(encrypt_key
.key_material
, key
, key_len
);
1280 encrypt_key
.key_disable
= true;
1283 return mwifiex_sec_ioctl_encrypt_key(priv
, &encrypt_key
);
1287 * Sends IOCTL request to get extended version.
1289 * This function allocates the IOCTL request buffer, fills it
1290 * with requisite parameters and calls the IOCTL handler.
1293 mwifiex_get_ver_ext(struct mwifiex_private
*priv
)
1295 struct mwifiex_ver_ext ver_ext
;
1297 memset(&ver_ext
, 0, sizeof(struct host_cmd_ds_version_ext
));
1298 if (mwifiex_send_cmd_sync(priv
, HostCmd_CMD_VERSION_EXT
,
1299 HostCmd_ACT_GEN_GET
, 0, &ver_ext
))
1306 * Sends IOCTL request to get statistics information.
1308 * This function allocates the IOCTL request buffer, fills it
1309 * with requisite parameters and calls the IOCTL handler.
1312 mwifiex_get_stats_info(struct mwifiex_private
*priv
,
1313 struct mwifiex_ds_get_stats
*log
)
1315 return mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_GET_LOG
,
1316 HostCmd_ACT_GEN_GET
, 0, log
);
1320 * IOCTL request handler to read/write register.
1322 * This function prepares the correct firmware command and
1325 * Access to the following registers are supported -
1332 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private
*priv
,
1333 struct mwifiex_ds_reg_rw
*reg_rw
,
1338 switch (le32_to_cpu(reg_rw
->type
)) {
1339 case MWIFIEX_REG_MAC
:
1340 cmd_no
= HostCmd_CMD_MAC_REG_ACCESS
;
1342 case MWIFIEX_REG_BBP
:
1343 cmd_no
= HostCmd_CMD_BBP_REG_ACCESS
;
1345 case MWIFIEX_REG_RF
:
1346 cmd_no
= HostCmd_CMD_RF_REG_ACCESS
;
1348 case MWIFIEX_REG_PMIC
:
1349 cmd_no
= HostCmd_CMD_PMIC_REG_ACCESS
;
1351 case MWIFIEX_REG_CAU
:
1352 cmd_no
= HostCmd_CMD_CAU_REG_ACCESS
;
1358 return mwifiex_send_cmd_sync(priv
, cmd_no
, action
, 0, reg_rw
);
1363 * Sends IOCTL request to write to a register.
1365 * This function allocates the IOCTL request buffer, fills it
1366 * with requisite parameters and calls the IOCTL handler.
1369 mwifiex_reg_write(struct mwifiex_private
*priv
, u32 reg_type
,
1370 u32 reg_offset
, u32 reg_value
)
1372 struct mwifiex_ds_reg_rw reg_rw
;
1374 reg_rw
.type
= cpu_to_le32(reg_type
);
1375 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1376 reg_rw
.value
= cpu_to_le32(reg_value
);
1378 return mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_SET
);
1382 * Sends IOCTL request to read from a register.
1384 * This function allocates the IOCTL request buffer, fills it
1385 * with requisite parameters and calls the IOCTL handler.
1388 mwifiex_reg_read(struct mwifiex_private
*priv
, u32 reg_type
,
1389 u32 reg_offset
, u32
*value
)
1392 struct mwifiex_ds_reg_rw reg_rw
;
1394 reg_rw
.type
= cpu_to_le32(reg_type
);
1395 reg_rw
.offset
= cpu_to_le32(reg_offset
);
1396 ret
= mwifiex_reg_mem_ioctl_reg_rw(priv
, ®_rw
, HostCmd_ACT_GEN_GET
);
1401 *value
= le32_to_cpu(reg_rw
.value
);
1408 * Sends IOCTL request to read from EEPROM.
1410 * This function allocates the IOCTL request buffer, fills it
1411 * with requisite parameters and calls the IOCTL handler.
1414 mwifiex_eeprom_read(struct mwifiex_private
*priv
, u16 offset
, u16 bytes
,
1418 struct mwifiex_ds_read_eeprom rd_eeprom
;
1420 rd_eeprom
.offset
= cpu_to_le16((u16
) offset
);
1421 rd_eeprom
.byte_count
= cpu_to_le16((u16
) bytes
);
1423 /* Send request to firmware */
1424 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_EEPROM_ACCESS
,
1425 HostCmd_ACT_GEN_GET
, 0, &rd_eeprom
);
1428 memcpy(value
, rd_eeprom
.value
, MAX_EEPROM_DATA
);
1433 * This function sets a generic IE. In addition to generic IE, it can
1434 * also handle WPA, WPA2 and WAPI IEs.
1437 mwifiex_set_gen_ie_helper(struct mwifiex_private
*priv
, u8
*ie_data_ptr
,
1441 struct ieee_types_vendor_header
*pvendor_ie
;
1442 const u8 wpa_oui
[] = { 0x00, 0x50, 0xf2, 0x01 };
1443 const u8 wps_oui
[] = { 0x00, 0x50, 0xf2, 0x04 };
1445 /* If the passed length is zero, reset the buffer */
1447 priv
->gen_ie_buf_len
= 0;
1448 priv
->wps
.session_enable
= false;
1451 } else if (!ie_data_ptr
) {
1454 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1455 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1456 if (((pvendor_ie
->element_id
== WLAN_EID_WPA
)
1457 && (!memcmp(pvendor_ie
->oui
, wpa_oui
, sizeof(wpa_oui
))))
1458 || (pvendor_ie
->element_id
== WLAN_EID_RSN
)) {
1460 /* IE is a WPA/WPA2 IE so call set_wpa function */
1461 ret
= mwifiex_set_wpa_ie_helper(priv
, ie_data_ptr
, ie_len
);
1462 priv
->wps
.session_enable
= false;
1465 } else if (pvendor_ie
->element_id
== WLAN_EID_BSS_AC_ACCESS_DELAY
) {
1466 /* IE is a WAPI IE so call set_wapi function */
1467 ret
= mwifiex_set_wapi_ie(priv
, ie_data_ptr
, ie_len
);
1472 * Verify that the passed length is not larger than the
1473 * available space remaining in the buffer
1475 if (ie_len
< (sizeof(priv
->gen_ie_buf
) - priv
->gen_ie_buf_len
)) {
1477 /* Test to see if it is a WPS IE, if so, enable
1480 pvendor_ie
= (struct ieee_types_vendor_header
*) ie_data_ptr
;
1481 if ((pvendor_ie
->element_id
== WLAN_EID_VENDOR_SPECIFIC
)
1482 && (!memcmp(pvendor_ie
->oui
, wps_oui
,
1483 sizeof(wps_oui
)))) {
1484 priv
->wps
.session_enable
= true;
1485 dev_dbg(priv
->adapter
->dev
,
1486 "info: WPS Session Enabled.\n");
1489 /* Append the passed data to the end of the
1491 memcpy(priv
->gen_ie_buf
+ priv
->gen_ie_buf_len
, ie_data_ptr
,
1493 /* Increment the stored buffer length by the
1495 priv
->gen_ie_buf_len
+= ie_len
;
1497 /* Passed data does not fit in the remaining
1502 /* Return 0, or -1 for error case */
1507 * IOCTL request handler to set/get generic IE.
1509 * In addition to various generic IEs, this function can also be
1510 * used to set the ARP filter.
1512 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private
*priv
,
1513 struct mwifiex_ds_misc_gen_ie
*gen_ie
,
1516 struct mwifiex_adapter
*adapter
= priv
->adapter
;
1518 switch (gen_ie
->type
) {
1519 case MWIFIEX_IE_TYPE_GEN_IE
:
1520 if (action
== HostCmd_ACT_GEN_GET
) {
1521 gen_ie
->len
= priv
->wpa_ie_len
;
1522 memcpy(gen_ie
->ie_data
, priv
->wpa_ie
, gen_ie
->len
);
1524 mwifiex_set_gen_ie_helper(priv
, gen_ie
->ie_data
,
1528 case MWIFIEX_IE_TYPE_ARP_FILTER
:
1529 memset(adapter
->arp_filter
, 0, sizeof(adapter
->arp_filter
));
1530 if (gen_ie
->len
> ARP_FILTER_MAX_BUF_SIZE
) {
1531 adapter
->arp_filter_size
= 0;
1532 dev_err(adapter
->dev
, "invalid ARP filter size\n");
1535 memcpy(adapter
->arp_filter
, gen_ie
->ie_data
,
1537 adapter
->arp_filter_size
= gen_ie
->len
;
1541 dev_err(adapter
->dev
, "invalid IE type\n");
1548 * Sends IOCTL request to set a generic IE.
1550 * This function allocates the IOCTL request buffer, fills it
1551 * with requisite parameters and calls the IOCTL handler.
1554 mwifiex_set_gen_ie(struct mwifiex_private
*priv
, u8
*ie
, int ie_len
)
1556 struct mwifiex_ds_misc_gen_ie gen_ie
;
1558 if (ie_len
> IEEE_MAX_IE_SIZE
)
1561 gen_ie
.type
= MWIFIEX_IE_TYPE_GEN_IE
;
1562 gen_ie
.len
= ie_len
;
1563 memcpy(gen_ie
.ie_data
, ie
, ie_len
);
1564 if (mwifiex_misc_ioctl_gen_ie(priv
, &gen_ie
, HostCmd_ACT_GEN_SET
))