Merge branch 'wl12xx-next' into for-linville
[deliverable/linux.git] / drivers / net / wireless / mwifiex / sta_ioctl.c
1 /*
2 * Marvell Wireless LAN device driver: functions for station ioctl
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
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.
13 *
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.
18 */
19
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"
28
29 /*
30 * Copies the multicast address list from device to driver.
31 *
32 * This function does not validate the destination memory for
33 * size, and the calling function must ensure enough memory is
34 * available.
35 */
36 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
37 struct net_device *dev)
38 {
39 int i = 0;
40 struct netdev_hw_addr *ha;
41
42 netdev_for_each_mc_addr(ha, dev)
43 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
44
45 return i;
46 }
47
48 /*
49 * Wait queue completion handler.
50 *
51 * This function waits on a cmd wait queue. It also cancels the pending
52 * request after waking up, in case of errors.
53 */
54 int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
55 {
56 bool cancel_flag = false;
57 int status = adapter->cmd_wait_q.status;
58
59 dev_dbg(adapter->dev, "cmd pending\n");
60 atomic_inc(&adapter->cmd_pending);
61
62 /* Status pending, wake up main process */
63 queue_work(adapter->workqueue, &adapter->main_work);
64
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;
70
71 if (cancel_flag) {
72 mwifiex_cancel_pending_ioctl(adapter);
73 dev_dbg(adapter->dev, "cmd cancel\n");
74 }
75 adapter->cmd_wait_q.status = 0;
76
77 return status;
78 }
79
80 /*
81 * This function prepares the correct firmware command and
82 * issues it to set the multicast list.
83 *
84 * This function can be used to enable promiscuous mode, or enable all
85 * multicast packets, or to enable selective multicast.
86 */
87 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
88 struct mwifiex_multicast_list *mcast_list)
89 {
90 int ret = 0;
91 u16 old_pkt_filter;
92
93 old_pkt_filter = priv->curr_pkt_filter;
94
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);
128 }
129 }
130 }
131 }
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);
139 }
140
141 return ret;
142 }
143
144 /*
145 * This function fills bss descriptor structure using provided
146 * information.
147 */
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)
153 {
154 int ret;
155
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;
167 }
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;
172
173 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
174 ie_buf, ie_len);
175
176 return ret;
177 }
178
179 /*
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.
183 */
184 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
185 struct mwifiex_802_11_ssid *req_ssid)
186 {
187 int ret;
188 struct mwifiex_adapter *adapter = priv->adapter;
189 struct mwifiex_bssdescriptor *bss_desc = NULL;
190 u8 *beacon_ie = NULL;
191
192 priv->scan_block = false;
193
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;
201 }
202
203 beacon_ie = kmemdup(bss->information_elements,
204 bss->len_beacon_ies, GFP_KERNEL);
205 if (!beacon_ie) {
206 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
207 return -ENOMEM;
208 }
209
210 ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
211 beacon_ie, bss->len_beacon_ies,
212 bss->beacon_interval,
213 bss->capability, bss_desc);
214 if (ret)
215 goto done;
216 }
217
218 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
219 /* Infra mode */
220 ret = mwifiex_deauthenticate(priv, NULL);
221 if (ret)
222 goto done;
223
224 ret = mwifiex_check_network_compatibility(priv, bss_desc);
225 if (ret)
226 goto done;
227
228 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
229 "associating...\n");
230
231 if (!netif_queue_stopped(priv->netdev))
232 netif_stop_queue(priv->netdev);
233
234 /* Clear any past association response stored for
235 * application retrieval */
236 priv->assoc_rsp_size = 0;
237 ret = mwifiex_associate(priv, bss_desc);
238 if (bss)
239 cfg80211_put_bss(bss);
240 } else {
241 /* Adhoc mode */
242 /* If the requested SSID matches current SSID, return */
243 if (bss_desc && bss_desc->ssid.ssid_len &&
244 (!mwifiex_ssid_cmp
245 (&priv->curr_bss_params.bss_descriptor.ssid,
246 &bss_desc->ssid))) {
247 kfree(bss_desc);
248 kfree(beacon_ie);
249 return 0;
250 }
251
252 /* Exit Adhoc mode first */
253 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
254 ret = mwifiex_deauthenticate(priv, NULL);
255 if (ret)
256 goto done;
257
258 priv->adhoc_is_link_sensed = false;
259
260 ret = mwifiex_check_network_compatibility(priv, bss_desc);
261
262 if (!netif_queue_stopped(priv->netdev))
263 netif_stop_queue(priv->netdev);
264
265 if (!ret) {
266 dev_dbg(adapter->dev, "info: network found in scan"
267 " list. Joining...\n");
268 ret = mwifiex_adhoc_join(priv, bss_desc);
269 if (bss)
270 cfg80211_put_bss(bss);
271 } else {
272 dev_dbg(adapter->dev, "info: Network not found in "
273 "the list, creating adhoc with ssid = %s\n",
274 req_ssid->ssid);
275 ret = mwifiex_adhoc_start(priv, req_ssid);
276 }
277 }
278
279 done:
280 kfree(bss_desc);
281 kfree(beacon_ie);
282 return ret;
283 }
284
285 /*
286 * IOCTL request handler to set host sleep configuration.
287 *
288 * This function prepares the correct firmware command and
289 * issues it.
290 */
291 int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
292 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
293
294 {
295 struct mwifiex_adapter *adapter = priv->adapter;
296 int status = 0;
297 u32 prev_cond = 0;
298
299 if (!hs_cfg)
300 return -ENOMEM;
301
302 switch (action) {
303 case HostCmd_ACT_GEN_SET:
304 if (adapter->pps_uapsd_mode) {
305 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
306 " is blocked in UAPSD/PPS mode\n");
307 status = -1;
308 break;
309 }
310 if (hs_cfg->is_invoke_hostcmd) {
311 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
312 if (!adapter->is_hs_configured)
313 /* Already cancelled */
314 break;
315 /* Save previous condition */
316 prev_cond = le32_to_cpu(adapter->hs_cfg
317 .conditions);
318 adapter->hs_cfg.conditions =
319 cpu_to_le32(hs_cfg->conditions);
320 } else if (hs_cfg->conditions) {
321 adapter->hs_cfg.conditions =
322 cpu_to_le32(hs_cfg->conditions);
323 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
324 if (hs_cfg->gap)
325 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
326 } else if (adapter->hs_cfg.conditions ==
327 cpu_to_le32(
328 HOST_SLEEP_CFG_CANCEL)) {
329 /* Return failure if no parameters for HS
330 enable */
331 status = -1;
332 break;
333 }
334 if (cmd_type == MWIFIEX_SYNC_CMD)
335 status = mwifiex_send_cmd_sync(priv,
336 HostCmd_CMD_802_11_HS_CFG_ENH,
337 HostCmd_ACT_GEN_SET, 0,
338 &adapter->hs_cfg);
339 else
340 status = mwifiex_send_cmd_async(priv,
341 HostCmd_CMD_802_11_HS_CFG_ENH,
342 HostCmd_ACT_GEN_SET, 0,
343 &adapter->hs_cfg);
344 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
345 /* Restore previous condition */
346 adapter->hs_cfg.conditions =
347 cpu_to_le32(prev_cond);
348 } else {
349 adapter->hs_cfg.conditions =
350 cpu_to_le32(hs_cfg->conditions);
351 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
352 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
353 }
354 break;
355 case HostCmd_ACT_GEN_GET:
356 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
357 hs_cfg->gpio = adapter->hs_cfg.gpio;
358 hs_cfg->gap = adapter->hs_cfg.gap;
359 break;
360 default:
361 status = -1;
362 break;
363 }
364
365 return status;
366 }
367
368 /*
369 * Sends IOCTL request to cancel the existing Host Sleep configuration.
370 *
371 * This function allocates the IOCTL request buffer, fills it
372 * with requisite parameters and calls the IOCTL handler.
373 */
374 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
375 {
376 struct mwifiex_ds_hs_cfg hscfg;
377
378 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
379 hscfg.is_invoke_hostcmd = true;
380
381 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
382 cmd_type, &hscfg);
383 }
384 EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
385
386 /*
387 * Sends IOCTL request to cancel the existing Host Sleep configuration.
388 *
389 * This function allocates the IOCTL request buffer, fills it
390 * with requisite parameters and calls the IOCTL handler.
391 */
392 int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
393 {
394 struct mwifiex_ds_hs_cfg hscfg;
395
396 if (adapter->hs_activated) {
397 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
398 return true;
399 }
400
401 adapter->hs_activate_wait_q_woken = false;
402
403 memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
404 hscfg.is_invoke_hostcmd = true;
405
406 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
407 MWIFIEX_BSS_ROLE_STA),
408 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
409 &hscfg)) {
410 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
411 return false;
412 }
413
414 wait_event_interruptible(adapter->hs_activate_wait_q,
415 adapter->hs_activate_wait_q_woken);
416
417 return true;
418 }
419 EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
420
421 /*
422 * IOCTL request handler to get BSS information.
423 *
424 * This function collates the information from different driver structures
425 * to send to the user.
426 */
427 int mwifiex_get_bss_info(struct mwifiex_private *priv,
428 struct mwifiex_bss_info *info)
429 {
430 struct mwifiex_adapter *adapter = priv->adapter;
431 struct mwifiex_bssdescriptor *bss_desc;
432
433 if (!info)
434 return -1;
435
436 bss_desc = &priv->curr_bss_params.bss_descriptor;
437
438 info->bss_mode = priv->bss_mode;
439
440 memcpy(&info->ssid, &bss_desc->ssid,
441 sizeof(struct mwifiex_802_11_ssid));
442
443 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
444
445 info->bss_chan = bss_desc->channel;
446
447 info->region_code = adapter->region_code;
448
449 info->media_connected = priv->media_connected;
450
451 info->max_power_level = priv->max_tx_power_level;
452 info->min_power_level = priv->min_tx_power_level;
453
454 info->adhoc_state = priv->adhoc_state;
455
456 info->bcn_nf_last = priv->bcn_nf_last;
457
458 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
459 info->wep_status = true;
460 else
461 info->wep_status = false;
462
463 info->is_hs_configured = adapter->is_hs_configured;
464 info->is_deep_sleep = adapter->is_deep_sleep;
465
466 return 0;
467 }
468
469 /*
470 * The function sets band configurations.
471 *
472 * it performs extra checks to make sure the Ad-Hoc
473 * band and channel are compatible. Otherwise it returns an error.
474 *
475 */
476 int mwifiex_set_radio_band_cfg(struct mwifiex_private *priv,
477 struct mwifiex_ds_band_cfg *radio_cfg)
478 {
479 struct mwifiex_adapter *adapter = priv->adapter;
480 u8 infra_band, adhoc_band;
481 u32 adhoc_channel;
482
483 infra_band = (u8) radio_cfg->config_bands;
484 adhoc_band = (u8) radio_cfg->adhoc_start_band;
485 adhoc_channel = radio_cfg->adhoc_channel;
486
487 /* SET Infra band */
488 if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
489 return -1;
490
491 adapter->config_bands = infra_band;
492
493 /* SET Ad-hoc Band */
494 if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
495 return -1;
496
497 if (adhoc_band)
498 adapter->adhoc_start_band = adhoc_band;
499 adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
500 /*
501 * If no adhoc_channel is supplied verify if the existing adhoc
502 * channel compiles with new adhoc_band
503 */
504 if (!adhoc_channel) {
505 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
506 (priv, adapter->adhoc_start_band,
507 priv->adhoc_channel)) {
508 /* Pass back the default channel */
509 radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
510 if ((adapter->adhoc_start_band & BAND_A)
511 || (adapter->adhoc_start_band & BAND_AN))
512 radio_cfg->adhoc_channel =
513 DEFAULT_AD_HOC_CHANNEL_A;
514 }
515 } else { /* Retrurn error if adhoc_band and
516 adhoc_channel combination is invalid */
517 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
518 (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
519 return -1;
520 priv->adhoc_channel = (u8) adhoc_channel;
521 }
522 if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
523 adapter->adhoc_11n_enabled = true;
524 else
525 adapter->adhoc_11n_enabled = false;
526
527 return 0;
528 }
529
530 /*
531 * The function disables auto deep sleep mode.
532 */
533 int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
534 {
535 struct mwifiex_ds_auto_ds auto_ds;
536
537 auto_ds.auto_ds = DEEP_SLEEP_OFF;
538
539 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
540 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
541 }
542 EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
543
544 /*
545 * IOCTL request handler to set/get active channel.
546 *
547 * This function performs validity checking on channel/frequency
548 * compatibility and returns failure if not valid.
549 */
550 int mwifiex_bss_set_channel(struct mwifiex_private *priv,
551 struct mwifiex_chan_freq_power *chan)
552 {
553 struct mwifiex_adapter *adapter = priv->adapter;
554 struct mwifiex_chan_freq_power *cfp = NULL;
555
556 if (!chan)
557 return -1;
558
559 if (!chan->channel && !chan->freq)
560 return -1;
561 if (adapter->adhoc_start_band & BAND_AN)
562 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
563 else if (adapter->adhoc_start_band & BAND_A)
564 adapter->adhoc_start_band = BAND_G | BAND_B;
565 if (chan->channel) {
566 if (chan->channel <= MAX_CHANNEL_BAND_BG)
567 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
568 (priv, 0, (u16) chan->channel);
569 if (!cfp) {
570 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
571 (priv, BAND_A, (u16) chan->channel);
572 if (cfp) {
573 if (adapter->adhoc_11n_enabled)
574 adapter->adhoc_start_band = BAND_A
575 | BAND_AN;
576 else
577 adapter->adhoc_start_band = BAND_A;
578 }
579 }
580 } else {
581 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
582 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
583 priv, 0, chan->freq);
584 if (!cfp) {
585 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
586 (priv, BAND_A, chan->freq);
587 if (cfp) {
588 if (adapter->adhoc_11n_enabled)
589 adapter->adhoc_start_band = BAND_A
590 | BAND_AN;
591 else
592 adapter->adhoc_start_band = BAND_A;
593 }
594 }
595 }
596 if (!cfp || !cfp->channel) {
597 dev_err(adapter->dev, "invalid channel/freq\n");
598 return -1;
599 }
600 priv->adhoc_channel = (u8) cfp->channel;
601 chan->channel = cfp->channel;
602 chan->freq = cfp->freq;
603
604 return 0;
605 }
606
607 /*
608 * IOCTL request handler to set/get Ad-Hoc channel.
609 *
610 * This function prepares the correct firmware command and
611 * issues it to set or get the ad-hoc channel.
612 */
613 static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
614 u16 action, u16 *channel)
615 {
616 if (action == HostCmd_ACT_GEN_GET) {
617 if (!priv->media_connected) {
618 *channel = priv->adhoc_channel;
619 return 0;
620 }
621 } else {
622 priv->adhoc_channel = (u8) *channel;
623 }
624
625 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
626 action, 0, channel);
627 }
628
629 /*
630 * IOCTL request handler to change Ad-Hoc channel.
631 *
632 * This function allocates the IOCTL request buffer, fills it
633 * with requisite parameters and calls the IOCTL handler.
634 *
635 * The function follows the following steps to perform the change -
636 * - Get current IBSS information
637 * - Get current channel
638 * - If no change is required, return
639 * - If not connected, change channel and return
640 * - If connected,
641 * - Disconnect
642 * - Change channel
643 * - Perform specific SSID scan with same SSID
644 * - Start/Join the IBSS
645 */
646 int
647 mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
648 {
649 int ret;
650 struct mwifiex_bss_info bss_info;
651 struct mwifiex_ssid_bssid ssid_bssid;
652 u16 curr_chan = 0;
653 struct cfg80211_bss *bss = NULL;
654 struct ieee80211_channel *chan;
655
656 memset(&bss_info, 0, sizeof(bss_info));
657
658 /* Get BSS information */
659 if (mwifiex_get_bss_info(priv, &bss_info))
660 return -1;
661
662 /* Get current channel */
663 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
664 &curr_chan);
665
666 if (curr_chan == channel) {
667 ret = 0;
668 goto done;
669 }
670 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
671 curr_chan, channel);
672
673 if (!bss_info.media_connected) {
674 ret = 0;
675 goto done;
676 }
677
678 /* Do disonnect */
679 memset(&ssid_bssid, 0, ETH_ALEN);
680 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
681
682 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
683 (u16 *) &channel);
684
685 /* Do specific SSID scanning */
686 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
687 ret = -1;
688 goto done;
689 }
690
691 chan = __ieee80211_get_channel(priv->wdev->wiphy,
692 ieee80211_channel_to_frequency(channel,
693 priv->curr_bss_params.band));
694
695 /* Find the BSS we want using available scan results */
696 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
697 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
698 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
699 if (!bss)
700 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
701 bss_info.bssid);
702
703 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
704 done:
705 return ret;
706 }
707
708 /*
709 * IOCTL request handler to get rate.
710 *
711 * This function prepares the correct firmware command and
712 * issues it to get the current rate if it is connected,
713 * otherwise, the function returns the lowest supported rate
714 * for the band.
715 */
716 static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
717 struct mwifiex_rate_cfg *rate_cfg)
718 {
719 struct mwifiex_adapter *adapter = priv->adapter;
720
721 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
722 if (!priv->media_connected) {
723 switch (adapter->config_bands) {
724 case BAND_B:
725 /* Return the lowest supported rate for B band */
726 rate_cfg->rate = supported_rates_b[0] & 0x7f;
727 break;
728 case BAND_G:
729 case BAND_G | BAND_GN:
730 /* Return the lowest supported rate for G band */
731 rate_cfg->rate = supported_rates_g[0] & 0x7f;
732 break;
733 case BAND_B | BAND_G:
734 case BAND_A | BAND_B | BAND_G:
735 case BAND_A | BAND_B:
736 case BAND_A | BAND_B | BAND_G | BAND_AN | BAND_GN:
737 case BAND_B | BAND_G | BAND_GN:
738 /* Return the lowest supported rate for BG band */
739 rate_cfg->rate = supported_rates_bg[0] & 0x7f;
740 break;
741 case BAND_A:
742 case BAND_A | BAND_G:
743 case BAND_A | BAND_G | BAND_AN | BAND_GN:
744 case BAND_A | BAND_AN:
745 /* Return the lowest supported rate for A band */
746 rate_cfg->rate = supported_rates_a[0] & 0x7f;
747 break;
748 case BAND_GN:
749 /* Return the lowest supported rate for N band */
750 rate_cfg->rate = supported_rates_n[0] & 0x7f;
751 break;
752 default:
753 dev_warn(adapter->dev, "invalid band %#x\n",
754 adapter->config_bands);
755 break;
756 }
757 } else {
758 return mwifiex_send_cmd_sync(priv,
759 HostCmd_CMD_802_11_TX_RATE_QUERY,
760 HostCmd_ACT_GEN_GET, 0, NULL);
761 }
762
763 return 0;
764 }
765
766 /*
767 * IOCTL request handler to set rate.
768 *
769 * This function prepares the correct firmware command and
770 * issues it to set the current rate.
771 *
772 * The function also performs validation checking on the supplied value.
773 */
774 static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
775 struct mwifiex_rate_cfg *rate_cfg)
776 {
777 u8 rates[MWIFIEX_SUPPORTED_RATES];
778 u8 *rate;
779 int rate_index, ret;
780 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
781 u32 i;
782 struct mwifiex_adapter *adapter = priv->adapter;
783
784 if (rate_cfg->is_rate_auto) {
785 memset(bitmap_rates, 0, sizeof(bitmap_rates));
786 /* Support all HR/DSSS rates */
787 bitmap_rates[0] = 0x000F;
788 /* Support all OFDM rates */
789 bitmap_rates[1] = 0x00FF;
790 /* Support all HT-MCSs rate */
791 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
792 bitmap_rates[i + 2] = 0xFFFF;
793 bitmap_rates[9] = 0x3FFF;
794 } else {
795 memset(rates, 0, sizeof(rates));
796 mwifiex_get_active_data_rates(priv, rates);
797 rate = rates;
798 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
799 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
800 rate[i], rate_cfg->rate);
801 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
802 break;
803 }
804 if (!rate[i] || (i == MWIFIEX_SUPPORTED_RATES)) {
805 dev_err(adapter->dev, "fixed data rate %#x is out "
806 "of range\n", rate_cfg->rate);
807 return -1;
808 }
809 memset(bitmap_rates, 0, sizeof(bitmap_rates));
810
811 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
812
813 /* Only allow b/g rates to be set */
814 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
815 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
816 bitmap_rates[0] = 1 << rate_index;
817 } else {
818 rate_index -= 1; /* There is a 0x00 in the table */
819 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
820 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
821 bitmap_rates[1] = 1 << (rate_index -
822 MWIFIEX_RATE_INDEX_OFDM0);
823 }
824 }
825
826 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
827 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
828
829 return ret;
830 }
831
832 /*
833 * IOCTL request handler to set/get rate.
834 *
835 * This function can be used to set/get either the rate value or the
836 * rate index.
837 */
838 static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
839 struct mwifiex_rate_cfg *rate_cfg)
840 {
841 int status;
842
843 if (!rate_cfg)
844 return -1;
845
846 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
847 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
848 else
849 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
850
851 return status;
852 }
853
854 /*
855 * Sends IOCTL request to get the data rate.
856 *
857 * This function allocates the IOCTL request buffer, fills it
858 * with requisite parameters and calls the IOCTL handler.
859 */
860 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
861 struct mwifiex_rate_cfg *rate)
862 {
863 int ret;
864
865 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
866 rate->action = HostCmd_ACT_GEN_GET;
867 ret = mwifiex_rate_ioctl_cfg(priv, rate);
868
869 if (!ret) {
870 if (rate && rate->is_rate_auto)
871 rate->rate = mwifiex_index_to_data_rate(priv->tx_rate,
872 priv->tx_htinfo);
873 else if (rate)
874 rate->rate = priv->data_rate;
875 } else {
876 ret = -1;
877 }
878
879 return ret;
880 }
881
882 /*
883 * IOCTL request handler to set tx power configuration.
884 *
885 * This function prepares the correct firmware command and
886 * issues it.
887 *
888 * For non-auto power mode, all the following power groups are set -
889 * - Modulation class HR/DSSS
890 * - Modulation class OFDM
891 * - Modulation class HTBW20
892 * - Modulation class HTBW40
893 */
894 int mwifiex_set_tx_power(struct mwifiex_private *priv,
895 struct mwifiex_power_cfg *power_cfg)
896 {
897 int ret;
898 struct host_cmd_ds_txpwr_cfg *txp_cfg;
899 struct mwifiex_types_power_group *pg_tlv;
900 struct mwifiex_power_group *pg;
901 u8 *buf;
902 u16 dbm = 0;
903
904 if (!power_cfg->is_power_auto) {
905 dbm = (u16) power_cfg->power_level;
906 if ((dbm < priv->min_tx_power_level) ||
907 (dbm > priv->max_tx_power_level)) {
908 dev_err(priv->adapter->dev, "txpower value %d dBm"
909 " is out of range (%d dBm-%d dBm)\n",
910 dbm, priv->min_tx_power_level,
911 priv->max_tx_power_level);
912 return -1;
913 }
914 }
915 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
916 if (!buf) {
917 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
918 __func__);
919 return -ENOMEM;
920 }
921
922 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
923 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
924 if (!power_cfg->is_power_auto) {
925 txp_cfg->mode = cpu_to_le32(1);
926 pg_tlv = (struct mwifiex_types_power_group *) (buf +
927 sizeof(struct host_cmd_ds_txpwr_cfg));
928 pg_tlv->type = TLV_TYPE_POWER_GROUP;
929 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
930 pg = (struct mwifiex_power_group *) (buf +
931 sizeof(struct host_cmd_ds_txpwr_cfg) +
932 sizeof(struct mwifiex_types_power_group));
933 /* Power group for modulation class HR/DSSS */
934 pg->first_rate_code = 0x00;
935 pg->last_rate_code = 0x03;
936 pg->modulation_class = MOD_CLASS_HR_DSSS;
937 pg->power_step = 0;
938 pg->power_min = (s8) dbm;
939 pg->power_max = (s8) dbm;
940 pg++;
941 /* Power group for modulation class OFDM */
942 pg->first_rate_code = 0x00;
943 pg->last_rate_code = 0x07;
944 pg->modulation_class = MOD_CLASS_OFDM;
945 pg->power_step = 0;
946 pg->power_min = (s8) dbm;
947 pg->power_max = (s8) dbm;
948 pg++;
949 /* Power group for modulation class HTBW20 */
950 pg->first_rate_code = 0x00;
951 pg->last_rate_code = 0x20;
952 pg->modulation_class = MOD_CLASS_HT;
953 pg->power_step = 0;
954 pg->power_min = (s8) dbm;
955 pg->power_max = (s8) dbm;
956 pg->ht_bandwidth = HT_BW_20;
957 pg++;
958 /* Power group for modulation class HTBW40 */
959 pg->first_rate_code = 0x00;
960 pg->last_rate_code = 0x20;
961 pg->modulation_class = MOD_CLASS_HT;
962 pg->power_step = 0;
963 pg->power_min = (s8) dbm;
964 pg->power_max = (s8) dbm;
965 pg->ht_bandwidth = HT_BW_40;
966 }
967 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
968 HostCmd_ACT_GEN_SET, 0, buf);
969
970 kfree(buf);
971 return ret;
972 }
973
974 /*
975 * IOCTL request handler to get power save mode.
976 *
977 * This function prepares the correct firmware command and
978 * issues it.
979 */
980 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
981 {
982 int ret;
983 struct mwifiex_adapter *adapter = priv->adapter;
984 u16 sub_cmd;
985
986 if (*ps_mode)
987 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
988 else
989 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
990 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
991 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
992 sub_cmd, BITMAP_STA_PS, NULL);
993 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
994 ret = mwifiex_send_cmd_async(priv,
995 HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
996 0, NULL);
997
998 return ret;
999 }
1000
1001 /*
1002 * IOCTL request handler to set/reset WPA IE.
1003 *
1004 * The supplied WPA IE is treated as a opaque buffer. Only the first field
1005 * is checked to determine WPA version. If buffer length is zero, the existing
1006 * WPA IE is reset.
1007 */
1008 static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
1009 u8 *ie_data_ptr, u16 ie_len)
1010 {
1011 if (ie_len) {
1012 if (ie_len > sizeof(priv->wpa_ie)) {
1013 dev_err(priv->adapter->dev,
1014 "failed to copy WPA IE, too big\n");
1015 return -1;
1016 }
1017 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
1018 priv->wpa_ie_len = (u8) ie_len;
1019 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
1020 priv->wpa_ie_len, priv->wpa_ie[0]);
1021
1022 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
1023 priv->sec_info.wpa_enabled = true;
1024 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
1025 priv->sec_info.wpa2_enabled = true;
1026 } else {
1027 priv->sec_info.wpa_enabled = false;
1028 priv->sec_info.wpa2_enabled = false;
1029 }
1030 } else {
1031 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
1032 priv->wpa_ie_len = 0;
1033 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
1034 priv->wpa_ie_len, priv->wpa_ie[0]);
1035 priv->sec_info.wpa_enabled = false;
1036 priv->sec_info.wpa2_enabled = false;
1037 }
1038
1039 return 0;
1040 }
1041
1042 /*
1043 * IOCTL request handler to set/reset WAPI IE.
1044 *
1045 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
1046 * is checked to internally enable WAPI. If buffer length is zero, the existing
1047 * WAPI IE is reset.
1048 */
1049 static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
1050 u8 *ie_data_ptr, u16 ie_len)
1051 {
1052 if (ie_len) {
1053 if (ie_len > sizeof(priv->wapi_ie)) {
1054 dev_dbg(priv->adapter->dev,
1055 "info: failed to copy WAPI IE, too big\n");
1056 return -1;
1057 }
1058 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
1059 priv->wapi_ie_len = ie_len;
1060 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
1061 priv->wapi_ie_len, priv->wapi_ie[0]);
1062
1063 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
1064 priv->sec_info.wapi_enabled = true;
1065 } else {
1066 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
1067 priv->wapi_ie_len = ie_len;
1068 dev_dbg(priv->adapter->dev,
1069 "info: Reset wapi_ie_len=%d IE=%#x\n",
1070 priv->wapi_ie_len, priv->wapi_ie[0]);
1071 priv->sec_info.wapi_enabled = false;
1072 }
1073 return 0;
1074 }
1075
1076 /*
1077 * IOCTL request handler to set WAPI key.
1078 *
1079 * This function prepares the correct firmware command and
1080 * issues it.
1081 */
1082 static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
1083 struct mwifiex_ds_encrypt_key *encrypt_key)
1084 {
1085
1086 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1087 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1088 encrypt_key);
1089 }
1090
1091 /*
1092 * IOCTL request handler to set WEP network key.
1093 *
1094 * This function prepares the correct firmware command and
1095 * issues it, after validation checks.
1096 */
1097 static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
1098 struct mwifiex_ds_encrypt_key *encrypt_key)
1099 {
1100 int ret;
1101 struct mwifiex_wep_key *wep_key;
1102 int index;
1103
1104 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1105 priv->wep_key_curr_index = 0;
1106 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1107 index = encrypt_key->key_index;
1108 if (encrypt_key->key_disable) {
1109 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
1110 } else if (!encrypt_key->key_len) {
1111 /* Copy the required key as the current key */
1112 wep_key = &priv->wep_key[index];
1113 if (!wep_key->key_length) {
1114 dev_err(priv->adapter->dev,
1115 "key not set, so cannot enable it\n");
1116 return -1;
1117 }
1118 priv->wep_key_curr_index = (u16) index;
1119 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1120 } else {
1121 wep_key = &priv->wep_key[index];
1122 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1123 /* Copy the key in the driver */
1124 memcpy(wep_key->key_material,
1125 encrypt_key->key_material,
1126 encrypt_key->key_len);
1127 wep_key->key_index = index;
1128 wep_key->key_length = encrypt_key->key_len;
1129 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1130 }
1131 if (wep_key->key_length) {
1132 /* Send request to firmware */
1133 ret = mwifiex_send_cmd_async(priv,
1134 HostCmd_CMD_802_11_KEY_MATERIAL,
1135 HostCmd_ACT_GEN_SET, 0, NULL);
1136 if (ret)
1137 return ret;
1138 }
1139 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
1140 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1141 else
1142 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1143
1144 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1145 HostCmd_ACT_GEN_SET, 0,
1146 &priv->curr_pkt_filter);
1147
1148 return ret;
1149 }
1150
1151 /*
1152 * IOCTL request handler to set WPA key.
1153 *
1154 * This function prepares the correct firmware command and
1155 * issues it, after validation checks.
1156 *
1157 * Current driver only supports key length of up to 32 bytes.
1158 *
1159 * This function can also be used to disable a currently set key.
1160 */
1161 static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
1162 struct mwifiex_ds_encrypt_key *encrypt_key)
1163 {
1164 int ret;
1165 u8 remove_key = false;
1166 struct host_cmd_ds_802_11_key_material *ibss_key;
1167
1168 /* Current driver only supports key length of up to 32 bytes */
1169 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
1170 dev_err(priv->adapter->dev, "key length too long\n");
1171 return -1;
1172 }
1173
1174 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
1175 /*
1176 * IBSS/WPA-None uses only one key (Group) for both receiving
1177 * and sending unicast and multicast packets.
1178 */
1179 /* Send the key as PTK to firmware */
1180 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1181 ret = mwifiex_send_cmd_async(priv,
1182 HostCmd_CMD_802_11_KEY_MATERIAL,
1183 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1184 encrypt_key);
1185 if (ret)
1186 return ret;
1187
1188 ibss_key = &priv->aes_key;
1189 memset(ibss_key, 0,
1190 sizeof(struct host_cmd_ds_802_11_key_material));
1191 /* Copy the key in the driver */
1192 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1193 encrypt_key->key_len);
1194 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1195 sizeof(ibss_key->key_param_set.key_len));
1196 ibss_key->key_param_set.key_type_id
1197 = cpu_to_le16(KEY_TYPE_ID_TKIP);
1198 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
1199
1200 /* Send the key as GTK to firmware */
1201 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1202 }
1203
1204 if (!encrypt_key->key_index)
1205 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1206
1207 if (remove_key)
1208 ret = mwifiex_send_cmd_sync(priv,
1209 HostCmd_CMD_802_11_KEY_MATERIAL,
1210 HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
1211 encrypt_key);
1212 else
1213 ret = mwifiex_send_cmd_sync(priv,
1214 HostCmd_CMD_802_11_KEY_MATERIAL,
1215 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1216 encrypt_key);
1217
1218 return ret;
1219 }
1220
1221 /*
1222 * IOCTL request handler to set/get network keys.
1223 *
1224 * This is a generic key handling function which supports WEP, WPA
1225 * and WAPI.
1226 */
1227 static int
1228 mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
1229 struct mwifiex_ds_encrypt_key *encrypt_key)
1230 {
1231 int status;
1232
1233 if (encrypt_key->is_wapi_key)
1234 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
1235 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
1236 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
1237 else
1238 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
1239 return status;
1240 }
1241
1242 /*
1243 * This function returns the driver version.
1244 */
1245 int
1246 mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1247 int max_len)
1248 {
1249 union {
1250 u32 l;
1251 u8 c[4];
1252 } ver;
1253 char fw_ver[32];
1254
1255 ver.l = adapter->fw_release_number;
1256 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1257
1258 snprintf(version, max_len, driver_version, fw_ver);
1259
1260 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1261
1262 return 0;
1263 }
1264
1265 /*
1266 * Sends IOCTL request to get signal information.
1267 *
1268 * This function allocates the IOCTL request buffer, fills it
1269 * with requisite parameters and calls the IOCTL handler.
1270 */
1271 int mwifiex_get_signal_info(struct mwifiex_private *priv,
1272 struct mwifiex_ds_get_signal *signal)
1273 {
1274 int status;
1275
1276 signal->selector = ALL_RSSI_INFO_MASK;
1277
1278 /* Signal info can be obtained only if connected */
1279 if (!priv->media_connected) {
1280 dev_dbg(priv->adapter->dev,
1281 "info: Can not get signal in disconnected state\n");
1282 return -1;
1283 }
1284
1285 status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
1286 HostCmd_ACT_GEN_GET, 0, signal);
1287
1288 if (!status) {
1289 if (signal->selector & BCN_RSSI_AVG_MASK)
1290 priv->qual_level = signal->bcn_rssi_avg;
1291 if (signal->selector & BCN_NF_AVG_MASK)
1292 priv->qual_noise = signal->bcn_nf_avg;
1293 }
1294
1295 return status;
1296 }
1297
1298 /*
1299 * Sends IOCTL request to set encoding parameters.
1300 *
1301 * This function allocates the IOCTL request buffer, fills it
1302 * with requisite parameters and calls the IOCTL handler.
1303 */
1304 int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1305 int key_len, u8 key_index, int disable)
1306 {
1307 struct mwifiex_ds_encrypt_key encrypt_key;
1308
1309 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1310 encrypt_key.key_len = key_len;
1311 if (!disable) {
1312 encrypt_key.key_index = key_index;
1313 if (key_len)
1314 memcpy(encrypt_key.key_material, key, key_len);
1315 } else {
1316 encrypt_key.key_disable = true;
1317 }
1318
1319 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
1320 }
1321
1322 /*
1323 * Sends IOCTL request to get extended version.
1324 *
1325 * This function allocates the IOCTL request buffer, fills it
1326 * with requisite parameters and calls the IOCTL handler.
1327 */
1328 int
1329 mwifiex_get_ver_ext(struct mwifiex_private *priv)
1330 {
1331 struct mwifiex_ver_ext ver_ext;
1332
1333 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
1334 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1335 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1336 return -1;
1337
1338 return 0;
1339 }
1340
1341 /*
1342 * Sends IOCTL request to get statistics information.
1343 *
1344 * This function allocates the IOCTL request buffer, fills it
1345 * with requisite parameters and calls the IOCTL handler.
1346 */
1347 int
1348 mwifiex_get_stats_info(struct mwifiex_private *priv,
1349 struct mwifiex_ds_get_stats *log)
1350 {
1351 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
1352 HostCmd_ACT_GEN_GET, 0, log);
1353 }
1354
1355 /*
1356 * IOCTL request handler to read/write register.
1357 *
1358 * This function prepares the correct firmware command and
1359 * issues it.
1360 *
1361 * Access to the following registers are supported -
1362 * - MAC
1363 * - BBP
1364 * - RF
1365 * - PMIC
1366 * - CAU
1367 */
1368 static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
1369 struct mwifiex_ds_reg_rw *reg_rw,
1370 u16 action)
1371 {
1372 u16 cmd_no;
1373
1374 switch (le32_to_cpu(reg_rw->type)) {
1375 case MWIFIEX_REG_MAC:
1376 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1377 break;
1378 case MWIFIEX_REG_BBP:
1379 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1380 break;
1381 case MWIFIEX_REG_RF:
1382 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1383 break;
1384 case MWIFIEX_REG_PMIC:
1385 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1386 break;
1387 case MWIFIEX_REG_CAU:
1388 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1389 break;
1390 default:
1391 return -1;
1392 }
1393
1394 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
1395
1396 }
1397
1398 /*
1399 * Sends IOCTL request to write to a register.
1400 *
1401 * This function allocates the IOCTL request buffer, fills it
1402 * with requisite parameters and calls the IOCTL handler.
1403 */
1404 int
1405 mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1406 u32 reg_offset, u32 reg_value)
1407 {
1408 struct mwifiex_ds_reg_rw reg_rw;
1409
1410 reg_rw.type = cpu_to_le32(reg_type);
1411 reg_rw.offset = cpu_to_le32(reg_offset);
1412 reg_rw.value = cpu_to_le32(reg_value);
1413
1414 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
1415 }
1416
1417 /*
1418 * Sends IOCTL request to read from a register.
1419 *
1420 * This function allocates the IOCTL request buffer, fills it
1421 * with requisite parameters and calls the IOCTL handler.
1422 */
1423 int
1424 mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1425 u32 reg_offset, u32 *value)
1426 {
1427 int ret;
1428 struct mwifiex_ds_reg_rw reg_rw;
1429
1430 reg_rw.type = cpu_to_le32(reg_type);
1431 reg_rw.offset = cpu_to_le32(reg_offset);
1432 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
1433
1434 if (ret)
1435 goto done;
1436
1437 *value = le32_to_cpu(reg_rw.value);
1438
1439 done:
1440 return ret;
1441 }
1442
1443 /*
1444 * Sends IOCTL request to read from EEPROM.
1445 *
1446 * This function allocates the IOCTL request buffer, fills it
1447 * with requisite parameters and calls the IOCTL handler.
1448 */
1449 int
1450 mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1451 u8 *value)
1452 {
1453 int ret;
1454 struct mwifiex_ds_read_eeprom rd_eeprom;
1455
1456 rd_eeprom.offset = cpu_to_le16((u16) offset);
1457 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
1458
1459 /* Send request to firmware */
1460 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1461 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
1462
1463 if (!ret)
1464 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
1465 return ret;
1466 }
1467
1468 /*
1469 * This function sets a generic IE. In addition to generic IE, it can
1470 * also handle WPA, WPA2 and WAPI IEs.
1471 */
1472 static int
1473 mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1474 u16 ie_len)
1475 {
1476 int ret = 0;
1477 struct ieee_types_vendor_header *pvendor_ie;
1478 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1479 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1480
1481 /* If the passed length is zero, reset the buffer */
1482 if (!ie_len) {
1483 priv->gen_ie_buf_len = 0;
1484 priv->wps.session_enable = false;
1485
1486 return 0;
1487 } else if (!ie_data_ptr) {
1488 return -1;
1489 }
1490 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1491 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1492 if (((pvendor_ie->element_id == WLAN_EID_WPA)
1493 && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
1494 || (pvendor_ie->element_id == WLAN_EID_RSN)) {
1495
1496 /* IE is a WPA/WPA2 IE so call set_wpa function */
1497 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1498 priv->wps.session_enable = false;
1499
1500 return ret;
1501 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1502 /* IE is a WAPI IE so call set_wapi function */
1503 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1504
1505 return ret;
1506 }
1507 /*
1508 * Verify that the passed length is not larger than the
1509 * available space remaining in the buffer
1510 */
1511 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1512
1513 /* Test to see if it is a WPS IE, if so, enable
1514 * wps session flag
1515 */
1516 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1517 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
1518 && (!memcmp(pvendor_ie->oui, wps_oui,
1519 sizeof(wps_oui)))) {
1520 priv->wps.session_enable = true;
1521 dev_dbg(priv->adapter->dev,
1522 "info: WPS Session Enabled.\n");
1523 }
1524
1525 /* Append the passed data to the end of the
1526 genIeBuffer */
1527 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1528 ie_len);
1529 /* Increment the stored buffer length by the
1530 size passed */
1531 priv->gen_ie_buf_len += ie_len;
1532 } else {
1533 /* Passed data does not fit in the remaining
1534 buffer space */
1535 ret = -1;
1536 }
1537
1538 /* Return 0, or -1 for error case */
1539 return ret;
1540 }
1541
1542 /*
1543 * IOCTL request handler to set/get generic IE.
1544 *
1545 * In addition to various generic IEs, this function can also be
1546 * used to set the ARP filter.
1547 */
1548 static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1549 struct mwifiex_ds_misc_gen_ie *gen_ie,
1550 u16 action)
1551 {
1552 struct mwifiex_adapter *adapter = priv->adapter;
1553
1554 switch (gen_ie->type) {
1555 case MWIFIEX_IE_TYPE_GEN_IE:
1556 if (action == HostCmd_ACT_GEN_GET) {
1557 gen_ie->len = priv->wpa_ie_len;
1558 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1559 } else {
1560 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1561 (u16) gen_ie->len);
1562 }
1563 break;
1564 case MWIFIEX_IE_TYPE_ARP_FILTER:
1565 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1566 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1567 adapter->arp_filter_size = 0;
1568 dev_err(adapter->dev, "invalid ARP filter size\n");
1569 return -1;
1570 } else {
1571 memcpy(adapter->arp_filter, gen_ie->ie_data,
1572 gen_ie->len);
1573 adapter->arp_filter_size = gen_ie->len;
1574 }
1575 break;
1576 default:
1577 dev_err(adapter->dev, "invalid IE type\n");
1578 return -1;
1579 }
1580 return 0;
1581 }
1582
1583 /*
1584 * Sends IOCTL request to set a generic IE.
1585 *
1586 * This function allocates the IOCTL request buffer, fills it
1587 * with requisite parameters and calls the IOCTL handler.
1588 */
1589 int
1590 mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1591 {
1592 struct mwifiex_ds_misc_gen_ie gen_ie;
1593
1594 if (ie_len > IEEE_MAX_IE_SIZE)
1595 return -EFAULT;
1596
1597 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1598 gen_ie.len = ie_len;
1599 memcpy(gen_ie.ie_data, ie, ie_len);
1600 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
1601 return -EFAULT;
1602
1603 return 0;
1604 }
This page took 0.064298 seconds and 6 git commands to generate.