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