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