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