mwifiex: remove unneeded NULL check
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / mwifiex / sta_ioctl.c
blob1df5ef6b4953bc51b25c59c0e94183077daf5cd5
1 /*
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.
20 #include "decl.h"
21 #include "ioctl.h"
22 #include "util.h"
23 #include "fw.h"
24 #include "main.h"
25 #include "wmm.h"
26 #include "11n.h"
27 #include "cfg80211.h"
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
34 * available.
36 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
37 struct net_device *dev)
39 int i = 0;
40 struct netdev_hw_addr *ha;
42 netdev_for_each_mc_addr(ha, dev)
43 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
45 return i;
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;
59 dev_dbg(adapter->dev, "cmd pending\n");
60 atomic_inc(&adapter->cmd_pending);
62 /* Status pending, wake up main process */
63 queue_work(adapter->workqueue, &adapter->main_work);
65 /* Wait for completion */
66 wait_event_interruptible(adapter->cmd_wait_q.wait,
67 adapter->cmd_wait_q.condition);
68 if (!adapter->cmd_wait_q.condition)
69 cancel_flag = true;
71 if (cancel_flag) {
72 mwifiex_cancel_pending_ioctl(adapter);
73 dev_dbg(adapter->dev, "cmd cancel\n");
75 adapter->cmd_wait_q.status = 0;
77 return status;
81 * This function prepares the correct firmware command and
82 * issues it to set the multicast list.
84 * This function can be used to enable promiscuous mode, or enable all
85 * multicast packets, or to enable selective multicast.
87 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
88 struct mwifiex_multicast_list *mcast_list)
90 int ret = 0;
91 u16 old_pkt_filter;
93 old_pkt_filter = priv->curr_pkt_filter;
95 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
96 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
97 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
98 priv->curr_pkt_filter &=
99 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
100 } else {
101 /* Multicast */
102 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
103 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
104 dev_dbg(priv->adapter->dev,
105 "info: Enabling All Multicast!\n");
106 priv->curr_pkt_filter |=
107 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
108 } else {
109 priv->curr_pkt_filter &=
110 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
111 if (mcast_list->num_multicast_addr) {
112 dev_dbg(priv->adapter->dev,
113 "info: Set multicast list=%d\n",
114 mcast_list->num_multicast_addr);
115 /* Set multicast addresses to firmware */
116 if (old_pkt_filter == priv->curr_pkt_filter) {
117 /* Send request to firmware */
118 ret = mwifiex_send_cmd_async(priv,
119 HostCmd_CMD_MAC_MULTICAST_ADR,
120 HostCmd_ACT_GEN_SET, 0,
121 mcast_list);
122 } else {
123 /* Send request to firmware */
124 ret = mwifiex_send_cmd_async(priv,
125 HostCmd_CMD_MAC_MULTICAST_ADR,
126 HostCmd_ACT_GEN_SET, 0,
127 mcast_list);
132 dev_dbg(priv->adapter->dev,
133 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
134 old_pkt_filter, priv->curr_pkt_filter);
135 if (old_pkt_filter != priv->curr_pkt_filter) {
136 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
137 HostCmd_ACT_GEN_SET,
138 0, &priv->curr_pkt_filter);
141 return ret;
145 * This function fills bss descriptor structure using provided
146 * information.
148 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
149 u8 *bssid, s32 rssi, u8 *ie_buf,
150 size_t ie_len, u16 beacon_period,
151 u16 cap_info_bitmap,
152 struct mwifiex_bssdescriptor *bss_desc)
154 int ret;
156 memcpy(bss_desc->mac_address, bssid, ETH_ALEN);
157 bss_desc->rssi = rssi;
158 bss_desc->beacon_buf = ie_buf;
159 bss_desc->beacon_buf_size = ie_len;
160 bss_desc->beacon_period = beacon_period;
161 bss_desc->cap_info_bitmap = cap_info_bitmap;
162 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
163 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
164 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
165 } else {
166 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
168 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
169 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
170 else
171 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
173 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
174 ie_buf, ie_len);
176 return ret;
180 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
181 * In both Ad-Hoc and infra mode, an deauthentication is performed
182 * first.
184 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
185 struct mwifiex_802_11_ssid *req_ssid)
187 int ret;
188 struct mwifiex_adapter *adapter = priv->adapter;
189 struct mwifiex_bssdescriptor *bss_desc = NULL;
190 u8 *beacon_ie = NULL;
192 priv->scan_block = false;
194 if (bss) {
195 /* Allocate and fill new bss descriptor */
196 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
197 GFP_KERNEL);
198 if (!bss_desc) {
199 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
200 return -ENOMEM;
203 beacon_ie = kmemdup(bss->information_elements,
204 bss->len_beacon_ies, GFP_KERNEL);
205 if (!beacon_ie) {
206 kfree(bss_desc);
207 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
208 return -ENOMEM;
211 ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
212 beacon_ie, bss->len_beacon_ies,
213 bss->beacon_interval,
214 bss->capability, bss_desc);
215 if (ret)
216 goto done;
219 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
220 /* Infra mode */
221 ret = mwifiex_deauthenticate(priv, NULL);
222 if (ret)
223 goto done;
225 ret = mwifiex_check_network_compatibility(priv, bss_desc);
226 if (ret)
227 goto done;
229 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
230 "associating...\n");
232 if (!netif_queue_stopped(priv->netdev))
233 netif_stop_queue(priv->netdev);
235 /* Clear any past association response stored for
236 * application retrieval */
237 priv->assoc_rsp_size = 0;
238 ret = mwifiex_associate(priv, bss_desc);
239 if (bss)
240 cfg80211_put_bss(bss);
241 } else {
242 /* Adhoc mode */
243 /* If the requested SSID matches current SSID, return */
244 if (bss_desc && bss_desc->ssid.ssid_len &&
245 (!mwifiex_ssid_cmp
246 (&priv->curr_bss_params.bss_descriptor.ssid,
247 &bss_desc->ssid))) {
248 kfree(bss_desc);
249 kfree(beacon_ie);
250 return 0;
253 /* Exit Adhoc mode first */
254 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
255 ret = mwifiex_deauthenticate(priv, NULL);
256 if (ret)
257 goto done;
259 priv->adhoc_is_link_sensed = false;
261 ret = mwifiex_check_network_compatibility(priv, bss_desc);
263 if (!netif_queue_stopped(priv->netdev))
264 netif_stop_queue(priv->netdev);
266 if (!ret) {
267 dev_dbg(adapter->dev, "info: network found in scan"
268 " list. Joining...\n");
269 ret = mwifiex_adhoc_join(priv, bss_desc);
270 if (bss)
271 cfg80211_put_bss(bss);
272 } else {
273 dev_dbg(adapter->dev, "info: Network not found in "
274 "the list, creating adhoc with ssid = %s\n",
275 req_ssid->ssid);
276 ret = mwifiex_adhoc_start(priv, req_ssid);
280 done:
281 kfree(bss_desc);
282 kfree(beacon_ie);
283 return ret;
287 * IOCTL request handler to set host sleep configuration.
289 * This function prepares the correct firmware command and
290 * issues it.
292 int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
293 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
296 struct mwifiex_adapter *adapter = priv->adapter;
297 int status = 0;
298 u32 prev_cond = 0;
300 if (!hs_cfg)
301 return -ENOMEM;
303 switch (action) {
304 case HostCmd_ACT_GEN_SET:
305 if (adapter->pps_uapsd_mode) {
306 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
307 " is blocked in UAPSD/PPS mode\n");
308 status = -1;
309 break;
311 if (hs_cfg->is_invoke_hostcmd) {
312 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
313 if (!adapter->is_hs_configured)
314 /* Already cancelled */
315 break;
316 /* Save previous condition */
317 prev_cond = le32_to_cpu(adapter->hs_cfg
318 .conditions);
319 adapter->hs_cfg.conditions =
320 cpu_to_le32(hs_cfg->conditions);
321 } else if (hs_cfg->conditions) {
322 adapter->hs_cfg.conditions =
323 cpu_to_le32(hs_cfg->conditions);
324 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
325 if (hs_cfg->gap)
326 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
327 } else if (adapter->hs_cfg.conditions ==
328 cpu_to_le32(
329 HOST_SLEEP_CFG_CANCEL)) {
330 /* Return failure if no parameters for HS
331 enable */
332 status = -1;
333 break;
335 if (cmd_type == MWIFIEX_SYNC_CMD)
336 status = mwifiex_send_cmd_sync(priv,
337 HostCmd_CMD_802_11_HS_CFG_ENH,
338 HostCmd_ACT_GEN_SET, 0,
339 &adapter->hs_cfg);
340 else
341 status = mwifiex_send_cmd_async(priv,
342 HostCmd_CMD_802_11_HS_CFG_ENH,
343 HostCmd_ACT_GEN_SET, 0,
344 &adapter->hs_cfg);
345 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
346 /* Restore previous condition */
347 adapter->hs_cfg.conditions =
348 cpu_to_le32(prev_cond);
349 } else {
350 adapter->hs_cfg.conditions =
351 cpu_to_le32(hs_cfg->conditions);
352 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
353 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
355 break;
356 case HostCmd_ACT_GEN_GET:
357 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
358 hs_cfg->gpio = adapter->hs_cfg.gpio;
359 hs_cfg->gap = adapter->hs_cfg.gap;
360 break;
361 default:
362 status = -1;
363 break;
366 return status;
370 * Sends IOCTL request to cancel the existing Host Sleep configuration.
372 * This function allocates the IOCTL request buffer, fills it
373 * with requisite parameters and calls the IOCTL handler.
375 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
377 struct mwifiex_ds_hs_cfg hscfg;
379 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
380 hscfg.is_invoke_hostcmd = true;
382 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
383 cmd_type, &hscfg);
385 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
388 * Sends IOCTL request to cancel the existing Host Sleep configuration.
390 * This function allocates the IOCTL request buffer, fills it
391 * with requisite parameters and calls the IOCTL handler.
393 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
395 struct mwifiex_ds_hs_cfg hscfg;
397 if (adapter->hs_activated) {
398 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
399 return true;
402 adapter->hs_activate_wait_q_woken = false;
404 memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
405 hscfg.is_invoke_hostcmd = true;
407 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
408 MWIFIEX_BSS_ROLE_STA),
409 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
410 &hscfg)) {
411 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
412 return false;
415 wait_event_interruptible(adapter->hs_activate_wait_q,
416 adapter->hs_activate_wait_q_woken);
418 return true;
420 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
423 * IOCTL request handler to get BSS information.
425 * This function collates the information from different driver structures
426 * to send to the user.
428 int mwifiex_get_bss_info(struct mwifiex_private *priv,
429 struct mwifiex_bss_info *info)
431 struct mwifiex_adapter *adapter = priv->adapter;
432 struct mwifiex_bssdescriptor *bss_desc;
434 if (!info)
435 return -1;
437 bss_desc = &priv->curr_bss_params.bss_descriptor;
439 info->bss_mode = priv->bss_mode;
441 memcpy(&info->ssid, &bss_desc->ssid,
442 sizeof(struct mwifiex_802_11_ssid));
444 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
446 info->bss_chan = bss_desc->channel;
448 info->region_code = adapter->region_code;
450 info->media_connected = priv->media_connected;
452 info->max_power_level = priv->max_tx_power_level;
453 info->min_power_level = priv->min_tx_power_level;
455 info->adhoc_state = priv->adhoc_state;
457 info->bcn_nf_last = priv->bcn_nf_last;
459 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
460 info->wep_status = true;
461 else
462 info->wep_status = false;
464 info->is_hs_configured = adapter->is_hs_configured;
465 info->is_deep_sleep = adapter->is_deep_sleep;
467 return 0;
471 * The function sets band configurations.
473 * it performs extra checks to make sure the Ad-Hoc
474 * band and channel are compatible. Otherwise it returns an error.
477 int mwifiex_set_radio_band_cfg(struct mwifiex_private *priv,
478 struct mwifiex_ds_band_cfg *radio_cfg)
480 struct mwifiex_adapter *adapter = priv->adapter;
481 u8 infra_band, adhoc_band;
482 u32 adhoc_channel;
484 infra_band = (u8) radio_cfg->config_bands;
485 adhoc_band = (u8) radio_cfg->adhoc_start_band;
486 adhoc_channel = radio_cfg->adhoc_channel;
488 /* SET Infra band */
489 if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
490 return -1;
492 adapter->config_bands = infra_band;
494 /* SET Ad-hoc Band */
495 if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
496 return -1;
498 if (adhoc_band)
499 adapter->adhoc_start_band = adhoc_band;
500 adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
502 * If no adhoc_channel is supplied verify if the existing adhoc
503 * channel compiles with new adhoc_band
505 if (!adhoc_channel) {
506 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
507 (priv, adapter->adhoc_start_band,
508 priv->adhoc_channel)) {
509 /* Pass back the default channel */
510 radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
511 if ((adapter->adhoc_start_band & BAND_A)
512 || (adapter->adhoc_start_band & BAND_AN))
513 radio_cfg->adhoc_channel =
514 DEFAULT_AD_HOC_CHANNEL_A;
516 } else { /* Retrurn error if adhoc_band and
517 adhoc_channel combination is invalid */
518 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
519 (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
520 return -1;
521 priv->adhoc_channel = (u8) adhoc_channel;
523 if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
524 adapter->adhoc_11n_enabled = true;
525 else
526 adapter->adhoc_11n_enabled = false;
528 return 0;
532 * The function disables auto deep sleep mode.
534 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
536 struct mwifiex_ds_auto_ds auto_ds;
538 auto_ds.auto_ds = DEEP_SLEEP_OFF;
540 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
541 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
543 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
546 * IOCTL request handler to set/get active channel.
548 * This function performs validity checking on channel/frequency
549 * compatibility and returns failure if not valid.
551 int mwifiex_bss_set_channel(struct mwifiex_private *priv,
552 struct mwifiex_chan_freq_power *chan)
554 struct mwifiex_adapter *adapter = priv->adapter;
555 struct mwifiex_chan_freq_power *cfp = NULL;
557 if (!chan)
558 return -1;
560 if (!chan->channel && !chan->freq)
561 return -1;
562 if (adapter->adhoc_start_band & BAND_AN)
563 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
564 else if (adapter->adhoc_start_band & BAND_A)
565 adapter->adhoc_start_band = BAND_G | BAND_B;
566 if (chan->channel) {
567 if (chan->channel <= MAX_CHANNEL_BAND_BG)
568 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
569 (priv, 0, (u16) chan->channel);
570 if (!cfp) {
571 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
572 (priv, BAND_A, (u16) chan->channel);
573 if (cfp) {
574 if (adapter->adhoc_11n_enabled)
575 adapter->adhoc_start_band = BAND_A
576 | BAND_AN;
577 else
578 adapter->adhoc_start_band = BAND_A;
581 } else {
582 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
583 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
584 priv, 0, chan->freq);
585 if (!cfp) {
586 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
587 (priv, BAND_A, chan->freq);
588 if (cfp) {
589 if (adapter->adhoc_11n_enabled)
590 adapter->adhoc_start_band = BAND_A
591 | BAND_AN;
592 else
593 adapter->adhoc_start_band = BAND_A;
597 if (!cfp || !cfp->channel) {
598 dev_err(adapter->dev, "invalid channel/freq\n");
599 return -1;
601 priv->adhoc_channel = (u8) cfp->channel;
602 chan->channel = cfp->channel;
603 chan->freq = cfp->freq;
605 return 0;
609 * IOCTL request handler to set/get Ad-Hoc channel.
611 * This function prepares the correct firmware command and
612 * issues it to set or get the ad-hoc channel.
614 static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
615 u16 action, u16 *channel)
617 if (action == HostCmd_ACT_GEN_GET) {
618 if (!priv->media_connected) {
619 *channel = priv->adhoc_channel;
620 return 0;
622 } else {
623 priv->adhoc_channel = (u8) *channel;
626 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
627 action, 0, channel);
631 * IOCTL request handler to change Ad-Hoc channel.
633 * This function allocates the IOCTL request buffer, fills it
634 * with requisite parameters and calls the IOCTL handler.
636 * The function follows the following steps to perform the change -
637 * - Get current IBSS information
638 * - Get current channel
639 * - If no change is required, return
640 * - If not connected, change channel and return
641 * - If connected,
642 * - Disconnect
643 * - Change channel
644 * - Perform specific SSID scan with same SSID
645 * - Start/Join the IBSS
648 mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
650 int ret;
651 struct mwifiex_bss_info bss_info;
652 struct mwifiex_ssid_bssid ssid_bssid;
653 u16 curr_chan = 0;
654 struct cfg80211_bss *bss = NULL;
655 struct ieee80211_channel *chan;
657 memset(&bss_info, 0, sizeof(bss_info));
659 /* Get BSS information */
660 if (mwifiex_get_bss_info(priv, &bss_info))
661 return -1;
663 /* Get current channel */
664 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
665 &curr_chan);
667 if (curr_chan == channel) {
668 ret = 0;
669 goto done;
671 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
672 curr_chan, channel);
674 if (!bss_info.media_connected) {
675 ret = 0;
676 goto done;
679 /* Do disonnect */
680 memset(&ssid_bssid, 0, ETH_ALEN);
681 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
683 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
684 (u16 *) &channel);
686 /* Do specific SSID scanning */
687 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
688 ret = -1;
689 goto done;
692 chan = __ieee80211_get_channel(priv->wdev->wiphy,
693 ieee80211_channel_to_frequency(channel,
694 priv->curr_bss_params.band));
696 /* Find the BSS we want using available scan results */
697 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
698 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
699 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
700 if (!bss)
701 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
702 bss_info.bssid);
704 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
705 done:
706 return ret;
710 * IOCTL request handler to get rate.
712 * This function prepares the correct firmware command and
713 * issues it to get the current rate if it is connected,
714 * otherwise, the function returns the lowest supported rate
715 * for the band.
717 static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
718 struct mwifiex_rate_cfg *rate_cfg)
720 struct mwifiex_adapter *adapter = priv->adapter;
722 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
723 if (!priv->media_connected) {
724 switch (adapter->config_bands) {
725 case BAND_B:
726 /* Return the lowest supported rate for B band */
727 rate_cfg->rate = supported_rates_b[0] & 0x7f;
728 break;
729 case BAND_G:
730 case BAND_G | BAND_GN:
731 /* Return the lowest supported rate for G band */
732 rate_cfg->rate = supported_rates_g[0] & 0x7f;
733 break;
734 case BAND_B | BAND_G:
735 case BAND_A | BAND_B | BAND_G:
736 case BAND_A | BAND_B:
737 case BAND_A | BAND_B | BAND_G | BAND_AN | BAND_GN:
738 case BAND_B | BAND_G | BAND_GN:
739 /* Return the lowest supported rate for BG band */
740 rate_cfg->rate = supported_rates_bg[0] & 0x7f;
741 break;
742 case BAND_A:
743 case BAND_A | BAND_G:
744 case BAND_A | BAND_G | BAND_AN | BAND_GN:
745 case BAND_A | BAND_AN:
746 /* Return the lowest supported rate for A band */
747 rate_cfg->rate = supported_rates_a[0] & 0x7f;
748 break;
749 case BAND_GN:
750 /* Return the lowest supported rate for N band */
751 rate_cfg->rate = supported_rates_n[0] & 0x7f;
752 break;
753 default:
754 dev_warn(adapter->dev, "invalid band %#x\n",
755 adapter->config_bands);
756 break;
758 } else {
759 return mwifiex_send_cmd_sync(priv,
760 HostCmd_CMD_802_11_TX_RATE_QUERY,
761 HostCmd_ACT_GEN_GET, 0, NULL);
764 return 0;
768 * IOCTL request handler to set rate.
770 * This function prepares the correct firmware command and
771 * issues it to set the current rate.
773 * The function also performs validation checking on the supplied value.
775 static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
776 struct mwifiex_rate_cfg *rate_cfg)
778 u8 rates[MWIFIEX_SUPPORTED_RATES];
779 u8 *rate;
780 int rate_index, ret;
781 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
782 u32 i;
783 struct mwifiex_adapter *adapter = priv->adapter;
785 if (rate_cfg->is_rate_auto) {
786 memset(bitmap_rates, 0, sizeof(bitmap_rates));
787 /* Support all HR/DSSS rates */
788 bitmap_rates[0] = 0x000F;
789 /* Support all OFDM rates */
790 bitmap_rates[1] = 0x00FF;
791 /* Support all HT-MCSs rate */
792 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
793 bitmap_rates[i + 2] = 0xFFFF;
794 bitmap_rates[9] = 0x3FFF;
795 } else {
796 memset(rates, 0, sizeof(rates));
797 mwifiex_get_active_data_rates(priv, rates);
798 rate = rates;
799 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
800 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
801 rate[i], rate_cfg->rate);
802 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
803 break;
805 if (!rate[i] || (i == MWIFIEX_SUPPORTED_RATES)) {
806 dev_err(adapter->dev, "fixed data rate %#x is out "
807 "of range\n", rate_cfg->rate);
808 return -1;
810 memset(bitmap_rates, 0, sizeof(bitmap_rates));
812 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
814 /* Only allow b/g rates to be set */
815 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
816 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
817 bitmap_rates[0] = 1 << rate_index;
818 } else {
819 rate_index -= 1; /* There is a 0x00 in the table */
820 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
821 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
822 bitmap_rates[1] = 1 << (rate_index -
823 MWIFIEX_RATE_INDEX_OFDM0);
827 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
828 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
830 return ret;
834 * IOCTL request handler to set/get rate.
836 * This function can be used to set/get either the rate value or the
837 * rate index.
839 static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
840 struct mwifiex_rate_cfg *rate_cfg)
842 int status;
844 if (!rate_cfg)
845 return -1;
847 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
848 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
849 else
850 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
852 return status;
856 * Sends IOCTL request to get the data rate.
858 * This function allocates the IOCTL request buffer, fills it
859 * with requisite parameters and calls the IOCTL handler.
861 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
862 struct mwifiex_rate_cfg *rate)
864 int ret;
866 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
867 rate->action = HostCmd_ACT_GEN_GET;
868 ret = mwifiex_rate_ioctl_cfg(priv, rate);
870 if (!ret) {
871 if (rate->is_rate_auto)
872 rate->rate = mwifiex_index_to_data_rate(priv->tx_rate,
873 priv->tx_htinfo);
874 else
875 rate->rate = priv->data_rate;
876 } else {
877 ret = -1;
880 return ret;
884 * IOCTL request handler to set tx power configuration.
886 * This function prepares the correct firmware command and
887 * issues it.
889 * For non-auto power mode, all the following power groups are set -
890 * - Modulation class HR/DSSS
891 * - Modulation class OFDM
892 * - Modulation class HTBW20
893 * - Modulation class HTBW40
895 int mwifiex_set_tx_power(struct mwifiex_private *priv,
896 struct mwifiex_power_cfg *power_cfg)
898 int ret;
899 struct host_cmd_ds_txpwr_cfg *txp_cfg;
900 struct mwifiex_types_power_group *pg_tlv;
901 struct mwifiex_power_group *pg;
902 u8 *buf;
903 u16 dbm = 0;
905 if (!power_cfg->is_power_auto) {
906 dbm = (u16) power_cfg->power_level;
907 if ((dbm < priv->min_tx_power_level) ||
908 (dbm > priv->max_tx_power_level)) {
909 dev_err(priv->adapter->dev, "txpower value %d dBm"
910 " is out of range (%d dBm-%d dBm)\n",
911 dbm, priv->min_tx_power_level,
912 priv->max_tx_power_level);
913 return -1;
916 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
917 if (!buf) {
918 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
919 __func__);
920 return -ENOMEM;
923 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
924 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
925 if (!power_cfg->is_power_auto) {
926 txp_cfg->mode = cpu_to_le32(1);
927 pg_tlv = (struct mwifiex_types_power_group *) (buf +
928 sizeof(struct host_cmd_ds_txpwr_cfg));
929 pg_tlv->type = TLV_TYPE_POWER_GROUP;
930 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
931 pg = (struct mwifiex_power_group *) (buf +
932 sizeof(struct host_cmd_ds_txpwr_cfg) +
933 sizeof(struct mwifiex_types_power_group));
934 /* Power group for modulation class HR/DSSS */
935 pg->first_rate_code = 0x00;
936 pg->last_rate_code = 0x03;
937 pg->modulation_class = MOD_CLASS_HR_DSSS;
938 pg->power_step = 0;
939 pg->power_min = (s8) dbm;
940 pg->power_max = (s8) dbm;
941 pg++;
942 /* Power group for modulation class OFDM */
943 pg->first_rate_code = 0x00;
944 pg->last_rate_code = 0x07;
945 pg->modulation_class = MOD_CLASS_OFDM;
946 pg->power_step = 0;
947 pg->power_min = (s8) dbm;
948 pg->power_max = (s8) dbm;
949 pg++;
950 /* Power group for modulation class HTBW20 */
951 pg->first_rate_code = 0x00;
952 pg->last_rate_code = 0x20;
953 pg->modulation_class = MOD_CLASS_HT;
954 pg->power_step = 0;
955 pg->power_min = (s8) dbm;
956 pg->power_max = (s8) dbm;
957 pg->ht_bandwidth = HT_BW_20;
958 pg++;
959 /* Power group for modulation class HTBW40 */
960 pg->first_rate_code = 0x00;
961 pg->last_rate_code = 0x20;
962 pg->modulation_class = MOD_CLASS_HT;
963 pg->power_step = 0;
964 pg->power_min = (s8) dbm;
965 pg->power_max = (s8) dbm;
966 pg->ht_bandwidth = HT_BW_40;
968 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
969 HostCmd_ACT_GEN_SET, 0, buf);
971 kfree(buf);
972 return ret;
976 * IOCTL request handler to get power save mode.
978 * This function prepares the correct firmware command and
979 * issues it.
981 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
983 int ret;
984 struct mwifiex_adapter *adapter = priv->adapter;
985 u16 sub_cmd;
987 if (*ps_mode)
988 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
989 else
990 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
991 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
992 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
993 sub_cmd, BITMAP_STA_PS, NULL);
994 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
995 ret = mwifiex_send_cmd_async(priv,
996 HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
997 0, NULL);
999 return ret;
1003 * IOCTL request handler to set/reset WPA IE.
1005 * The supplied WPA IE is treated as a opaque buffer. Only the first field
1006 * is checked to determine WPA version. If buffer length is zero, the existing
1007 * WPA IE is reset.
1009 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
1010 u8 *ie_data_ptr, u16 ie_len)
1012 if (ie_len) {
1013 if (ie_len > sizeof(priv->wpa_ie)) {
1014 dev_err(priv->adapter->dev,
1015 "failed to copy WPA IE, too big\n");
1016 return -1;
1018 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
1019 priv->wpa_ie_len = (u8) ie_len;
1020 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
1021 priv->wpa_ie_len, priv->wpa_ie[0]);
1023 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
1024 priv->sec_info.wpa_enabled = true;
1025 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
1026 priv->sec_info.wpa2_enabled = true;
1027 } else {
1028 priv->sec_info.wpa_enabled = false;
1029 priv->sec_info.wpa2_enabled = false;
1031 } else {
1032 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
1033 priv->wpa_ie_len = 0;
1034 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
1035 priv->wpa_ie_len, priv->wpa_ie[0]);
1036 priv->sec_info.wpa_enabled = false;
1037 priv->sec_info.wpa2_enabled = false;
1040 return 0;
1044 * IOCTL request handler to set/reset WAPI IE.
1046 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
1047 * is checked to internally enable WAPI. If buffer length is zero, the existing
1048 * WAPI IE is reset.
1050 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
1051 u8 *ie_data_ptr, u16 ie_len)
1053 if (ie_len) {
1054 if (ie_len > sizeof(priv->wapi_ie)) {
1055 dev_dbg(priv->adapter->dev,
1056 "info: failed to copy WAPI IE, too big\n");
1057 return -1;
1059 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
1060 priv->wapi_ie_len = ie_len;
1061 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
1062 priv->wapi_ie_len, priv->wapi_ie[0]);
1064 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
1065 priv->sec_info.wapi_enabled = true;
1066 } else {
1067 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
1068 priv->wapi_ie_len = ie_len;
1069 dev_dbg(priv->adapter->dev,
1070 "info: Reset wapi_ie_len=%d IE=%#x\n",
1071 priv->wapi_ie_len, priv->wapi_ie[0]);
1072 priv->sec_info.wapi_enabled = false;
1074 return 0;
1078 * IOCTL request handler to set WAPI key.
1080 * This function prepares the correct firmware command and
1081 * issues it.
1083 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
1084 struct mwifiex_ds_encrypt_key *encrypt_key)
1087 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1088 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1089 encrypt_key);
1093 * IOCTL request handler to set WEP network key.
1095 * This function prepares the correct firmware command and
1096 * issues it, after validation checks.
1098 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
1099 struct mwifiex_ds_encrypt_key *encrypt_key)
1101 int ret;
1102 struct mwifiex_wep_key *wep_key;
1103 int index;
1105 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1106 priv->wep_key_curr_index = 0;
1107 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1108 index = encrypt_key->key_index;
1109 if (encrypt_key->key_disable) {
1110 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
1111 } else if (!encrypt_key->key_len) {
1112 /* Copy the required key as the current key */
1113 wep_key = &priv->wep_key[index];
1114 if (!wep_key->key_length) {
1115 dev_err(priv->adapter->dev,
1116 "key not set, so cannot enable it\n");
1117 return -1;
1119 priv->wep_key_curr_index = (u16) index;
1120 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1121 } else {
1122 wep_key = &priv->wep_key[index];
1123 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1124 /* Copy the key in the driver */
1125 memcpy(wep_key->key_material,
1126 encrypt_key->key_material,
1127 encrypt_key->key_len);
1128 wep_key->key_index = index;
1129 wep_key->key_length = encrypt_key->key_len;
1130 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1132 if (wep_key->key_length) {
1133 /* Send request to firmware */
1134 ret = mwifiex_send_cmd_async(priv,
1135 HostCmd_CMD_802_11_KEY_MATERIAL,
1136 HostCmd_ACT_GEN_SET, 0, NULL);
1137 if (ret)
1138 return ret;
1140 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
1141 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1142 else
1143 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1145 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1146 HostCmd_ACT_GEN_SET, 0,
1147 &priv->curr_pkt_filter);
1149 return ret;
1153 * IOCTL request handler to set WPA key.
1155 * This function prepares the correct firmware command and
1156 * issues it, after validation checks.
1158 * Current driver only supports key length of up to 32 bytes.
1160 * This function can also be used to disable a currently set key.
1162 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
1163 struct mwifiex_ds_encrypt_key *encrypt_key)
1165 int ret;
1166 u8 remove_key = false;
1167 struct host_cmd_ds_802_11_key_material *ibss_key;
1169 /* Current driver only supports key length of up to 32 bytes */
1170 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
1171 dev_err(priv->adapter->dev, "key length too long\n");
1172 return -1;
1175 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1177 * IBSS/WPA-None uses only one key (Group) for both receiving
1178 * and sending unicast and multicast packets.
1180 /* Send the key as PTK to firmware */
1181 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1182 ret = mwifiex_send_cmd_async(priv,
1183 HostCmd_CMD_802_11_KEY_MATERIAL,
1184 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1185 encrypt_key);
1186 if (ret)
1187 return ret;
1189 ibss_key = &priv->aes_key;
1190 memset(ibss_key, 0,
1191 sizeof(struct host_cmd_ds_802_11_key_material));
1192 /* Copy the key in the driver */
1193 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1194 encrypt_key->key_len);
1195 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1196 sizeof(ibss_key->key_param_set.key_len));
1197 ibss_key->key_param_set.key_type_id
1198 = cpu_to_le16(KEY_TYPE_ID_TKIP);
1199 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
1201 /* Send the key as GTK to firmware */
1202 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1205 if (!encrypt_key->key_index)
1206 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1208 if (remove_key)
1209 ret = mwifiex_send_cmd_sync(priv,
1210 HostCmd_CMD_802_11_KEY_MATERIAL,
1211 HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
1212 encrypt_key);
1213 else
1214 ret = mwifiex_send_cmd_sync(priv,
1215 HostCmd_CMD_802_11_KEY_MATERIAL,
1216 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1217 encrypt_key);
1219 return ret;
1223 * IOCTL request handler to set/get network keys.
1225 * This is a generic key handling function which supports WEP, WPA
1226 * and WAPI.
1228 static int
1229 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
1230 struct mwifiex_ds_encrypt_key *encrypt_key)
1232 int status;
1234 if (encrypt_key->is_wapi_key)
1235 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
1236 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
1237 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
1238 else
1239 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
1240 return status;
1244 * This function returns the driver version.
1247 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1248 int max_len)
1250 union {
1251 u32 l;
1252 u8 c[4];
1253 } ver;
1254 char fw_ver[32];
1256 ver.l = adapter->fw_release_number;
1257 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1259 snprintf(version, max_len, driver_version, fw_ver);
1261 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1263 return 0;
1267 * Sends IOCTL request to get signal information.
1269 * This function allocates the IOCTL request buffer, fills it
1270 * with requisite parameters and calls the IOCTL handler.
1272 int mwifiex_get_signal_info(struct mwifiex_private *priv,
1273 struct mwifiex_ds_get_signal *signal)
1275 int status;
1277 signal->selector = ALL_RSSI_INFO_MASK;
1279 /* Signal info can be obtained only if connected */
1280 if (!priv->media_connected) {
1281 dev_dbg(priv->adapter->dev,
1282 "info: Can not get signal in disconnected state\n");
1283 return -1;
1286 status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
1287 HostCmd_ACT_GEN_GET, 0, signal);
1289 if (!status) {
1290 if (signal->selector & BCN_RSSI_AVG_MASK)
1291 priv->qual_level = signal->bcn_rssi_avg;
1292 if (signal->selector & BCN_NF_AVG_MASK)
1293 priv->qual_noise = signal->bcn_nf_avg;
1296 return status;
1300 * Sends IOCTL request to set encoding parameters.
1302 * This function allocates the IOCTL request buffer, fills it
1303 * with requisite parameters and calls the IOCTL handler.
1305 int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1306 int key_len, u8 key_index, int disable)
1308 struct mwifiex_ds_encrypt_key encrypt_key;
1310 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1311 encrypt_key.key_len = key_len;
1312 if (!disable) {
1313 encrypt_key.key_index = key_index;
1314 if (key_len)
1315 memcpy(encrypt_key.key_material, key, key_len);
1316 } else {
1317 encrypt_key.key_disable = true;
1320 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1324 * Sends IOCTL request to get extended version.
1326 * This function allocates the IOCTL request buffer, fills it
1327 * with requisite parameters and calls the IOCTL handler.
1330 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1332 struct mwifiex_ver_ext ver_ext;
1334 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1335 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1336 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1337 return -1;
1339 return 0;
1343 * Sends IOCTL request to get statistics information.
1345 * This function allocates the IOCTL request buffer, fills it
1346 * with requisite parameters and calls the IOCTL handler.
1349 mwifiex_get_stats_info(struct mwifiex_private *priv,
1350 struct mwifiex_ds_get_stats *log)
1352 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1353 HostCmd_ACT_GEN_GET, 0, log);
1357 * IOCTL request handler to read/write register.
1359 * This function prepares the correct firmware command and
1360 * issues it.
1362 * Access to the following registers are supported -
1363 * - MAC
1364 * - BBP
1365 * - RF
1366 * - PMIC
1367 * - CAU
1369 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1370 struct mwifiex_ds_reg_rw *reg_rw,
1371 u16 action)
1373 u16 cmd_no;
1375 switch (le32_to_cpu(reg_rw->type)) {
1376 case MWIFIEX_REG_MAC:
1377 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1378 break;
1379 case MWIFIEX_REG_BBP:
1380 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1381 break;
1382 case MWIFIEX_REG_RF:
1383 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1384 break;
1385 case MWIFIEX_REG_PMIC:
1386 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1387 break;
1388 case MWIFIEX_REG_CAU:
1389 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1390 break;
1391 default:
1392 return -1;
1395 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1400 * Sends IOCTL request to write to a register.
1402 * This function allocates the IOCTL request buffer, fills it
1403 * with requisite parameters and calls the IOCTL handler.
1406 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1407 u32 reg_offset, u32 reg_value)
1409 struct mwifiex_ds_reg_rw reg_rw;
1411 reg_rw.type = cpu_to_le32(reg_type);
1412 reg_rw.offset = cpu_to_le32(reg_offset);
1413 reg_rw.value = cpu_to_le32(reg_value);
1415 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
1419 * Sends IOCTL request to read from a register.
1421 * This function allocates the IOCTL request buffer, fills it
1422 * with requisite parameters and calls the IOCTL handler.
1425 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1426 u32 reg_offset, u32 *value)
1428 int ret;
1429 struct mwifiex_ds_reg_rw reg_rw;
1431 reg_rw.type = cpu_to_le32(reg_type);
1432 reg_rw.offset = cpu_to_le32(reg_offset);
1433 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
1435 if (ret)
1436 goto done;
1438 *value = le32_to_cpu(reg_rw.value);
1440 done:
1441 return ret;
1445 * Sends IOCTL request to read from EEPROM.
1447 * This function allocates the IOCTL request buffer, fills it
1448 * with requisite parameters and calls the IOCTL handler.
1451 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1452 u8 *value)
1454 int ret;
1455 struct mwifiex_ds_read_eeprom rd_eeprom;
1457 rd_eeprom.offset = cpu_to_le16((u16) offset);
1458 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1460 /* Send request to firmware */
1461 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1462 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1464 if (!ret)
1465 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1466 return ret;
1470 * This function sets a generic IE. In addition to generic IE, it can
1471 * also handle WPA, WPA2 and WAPI IEs.
1473 static int
1474 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1475 u16 ie_len)
1477 int ret = 0;
1478 struct ieee_types_vendor_header *pvendor_ie;
1479 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1480 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1482 /* If the passed length is zero, reset the buffer */
1483 if (!ie_len) {
1484 priv->gen_ie_buf_len = 0;
1485 priv->wps.session_enable = false;
1487 return 0;
1488 } else if (!ie_data_ptr) {
1489 return -1;
1491 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1492 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1493 if (((pvendor_ie->element_id == WLAN_EID_WPA)
1494 && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
1495 || (pvendor_ie->element_id == WLAN_EID_RSN)) {
1497 /* IE is a WPA/WPA2 IE so call set_wpa function */
1498 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1499 priv->wps.session_enable = false;
1501 return ret;
1502 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1503 /* IE is a WAPI IE so call set_wapi function */
1504 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1506 return ret;
1509 * Verify that the passed length is not larger than the
1510 * available space remaining in the buffer
1512 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1514 /* Test to see if it is a WPS IE, if so, enable
1515 * wps session flag
1517 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1518 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
1519 && (!memcmp(pvendor_ie->oui, wps_oui,
1520 sizeof(wps_oui)))) {
1521 priv->wps.session_enable = true;
1522 dev_dbg(priv->adapter->dev,
1523 "info: WPS Session Enabled.\n");
1526 /* Append the passed data to the end of the
1527 genIeBuffer */
1528 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1529 ie_len);
1530 /* Increment the stored buffer length by the
1531 size passed */
1532 priv->gen_ie_buf_len += ie_len;
1533 } else {
1534 /* Passed data does not fit in the remaining
1535 buffer space */
1536 ret = -1;
1539 /* Return 0, or -1 for error case */
1540 return ret;
1544 * IOCTL request handler to set/get generic IE.
1546 * In addition to various generic IEs, this function can also be
1547 * used to set the ARP filter.
1549 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1550 struct mwifiex_ds_misc_gen_ie *gen_ie,
1551 u16 action)
1553 struct mwifiex_adapter *adapter = priv->adapter;
1555 switch (gen_ie->type) {
1556 case MWIFIEX_IE_TYPE_GEN_IE:
1557 if (action == HostCmd_ACT_GEN_GET) {
1558 gen_ie->len = priv->wpa_ie_len;
1559 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1560 } else {
1561 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1562 (u16) gen_ie->len);
1564 break;
1565 case MWIFIEX_IE_TYPE_ARP_FILTER:
1566 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1567 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1568 adapter->arp_filter_size = 0;
1569 dev_err(adapter->dev, "invalid ARP filter size\n");
1570 return -1;
1571 } else {
1572 memcpy(adapter->arp_filter, gen_ie->ie_data,
1573 gen_ie->len);
1574 adapter->arp_filter_size = gen_ie->len;
1576 break;
1577 default:
1578 dev_err(adapter->dev, "invalid IE type\n");
1579 return -1;
1581 return 0;
1585 * Sends IOCTL request to set a generic IE.
1587 * This function allocates the IOCTL request buffer, fills it
1588 * with requisite parameters and calls the IOCTL handler.
1591 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1593 struct mwifiex_ds_misc_gen_ie gen_ie;
1595 if (ie_len > IEEE_MAX_IE_SIZE)
1596 return -EFAULT;
1598 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1599 gen_ie.len = ie_len;
1600 memcpy(gen_ie.ie_data, ie, ie_len);
1601 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
1602 return -EFAULT;
1604 return 0;