]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
mwifiex: fix unbalanced locking in mwifiex_process_country_ie()
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / marvell / mwifiex / sta_ioctl.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: functions for station ioctl
3 *
65da33f5 4 * Copyright (C) 2011-2014, Marvell International Ltd.
5e6e3a92
BZ
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
ef0a68a8 29static int disconnect_on_suspend;
22c22d27
AK
30module_param(disconnect_on_suspend, int, 0644);
31
5e6e3a92
BZ
32/*
33 * Copies the multicast address list from device to driver.
34 *
35 * This function does not validate the destination memory for
36 * size, and the calling function must ensure enough memory is
37 * available.
38 */
600f5d90
AK
39int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
40 struct net_device *dev)
5e6e3a92
BZ
41{
42 int i = 0;
43 struct netdev_hw_addr *ha;
44
45 netdev_for_each_mc_addr(ha, dev)
46 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
47
48 return i;
49}
50
5e6e3a92
BZ
51/*
52 * Wait queue completion handler.
53 *
600f5d90
AK
54 * This function waits on a cmd wait queue. It also cancels the pending
55 * request after waking up, in case of errors.
5e6e3a92 56 */
00d7ea11
AK
57int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
58 struct cmd_ctrl_node *cmd_queued)
5e6e3a92 59{
b7097eb7 60 int status;
b015dbc0 61
600f5d90 62 /* Wait for completion */
f8d2b920
AK
63 status = wait_event_interruptible_timeout(adapter->cmd_wait_q.wait,
64 *(cmd_queued->condition),
65 (12 * HZ));
66 if (status <= 0) {
4e0ff946
DT
67 if (status == 0)
68 status = -ETIMEDOUT;
c5bc15fc
AF
69 mwifiex_dbg(adapter, ERROR, "cmd_wait_q terminated: %d\n",
70 status);
3d026d09 71 mwifiex_cancel_all_pending_cmd(adapter);
9c969d8c 72 return status;
5e6e3a92 73 }
b7097eb7
AK
74
75 status = adapter->cmd_wait_q.status;
600f5d90 76 adapter->cmd_wait_q.status = 0;
5e6e3a92 77
5e6e3a92
BZ
78 return status;
79}
80
81/*
5e6e3a92
BZ
82 * This function prepares the correct firmware command and
83 * issues it to set the multicast list.
84 *
85 * This function can be used to enable promiscuous mode, or enable all
86 * multicast packets, or to enable selective multicast.
87 */
600f5d90
AK
88int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
89 struct mwifiex_multicast_list *mcast_list)
5e6e3a92
BZ
90{
91 int ret = 0;
92 u16 old_pkt_filter;
93
94 old_pkt_filter = priv->curr_pkt_filter;
5e6e3a92
BZ
95
96 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
acebe8c1
ZL
97 mwifiex_dbg(priv->adapter, INFO,
98 "info: Enable Promiscuous mode\n");
5e6e3a92
BZ
99 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
100 priv->curr_pkt_filter &=
101 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
102 } else {
103 /* Multicast */
104 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
ccd384b1 105 if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
acebe8c1
ZL
106 mwifiex_dbg(priv->adapter, INFO,
107 "info: Enabling All Multicast!\n");
5e6e3a92
BZ
108 priv->curr_pkt_filter |=
109 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
110 } else {
111 priv->curr_pkt_filter &=
112 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
acebe8c1
ZL
113 mwifiex_dbg(priv->adapter, INFO,
114 "info: Set multicast list=%d\n",
115 mcast_list->num_multicast_addr);
6390d885 116 /* Send multicast addresses to firmware */
fa0ecbb9
BZ
117 ret = mwifiex_send_cmd(priv,
118 HostCmd_CMD_MAC_MULTICAST_ADR,
119 HostCmd_ACT_GEN_SET, 0,
120 mcast_list, false);
5e6e3a92
BZ
121 }
122 }
acebe8c1
ZL
123 mwifiex_dbg(priv->adapter, INFO,
124 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
125 old_pkt_filter, priv->curr_pkt_filter);
5e6e3a92 126 if (old_pkt_filter != priv->curr_pkt_filter) {
fa0ecbb9
BZ
127 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
128 HostCmd_ACT_GEN_SET,
129 0, &priv->curr_pkt_filter, false);
5e6e3a92
BZ
130 }
131
132 return ret;
133}
134
7c6fa2a8
AK
135/*
136 * This function fills bss descriptor structure using provided
137 * information.
d837a2ae
BZ
138 * beacon_ie buffer is allocated in this function. It is caller's
139 * responsibility to free the memory.
7c6fa2a8
AK
140 */
141int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
9558a407 142 struct cfg80211_bss *bss,
7c6fa2a8
AK
143 struct mwifiex_bssdescriptor *bss_desc)
144{
9558a407 145 u8 *beacon_ie;
403e1673 146 size_t beacon_ie_len;
b5abcf02 147 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
9caf0364 148 const struct cfg80211_bss_ies *ies;
bcc920e8 149 int ret;
9caf0364
JB
150
151 rcu_read_lock();
152 ies = rcu_dereference(bss->ies);
9caf0364
JB
153 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
154 beacon_ie_len = ies->len;
8cef2c9d 155 bss_desc->timestamp = ies->tsf;
9caf0364 156 rcu_read_unlock();
7c6fa2a8 157
9558a407 158 if (!beacon_ie) {
acebe8c1
ZL
159 mwifiex_dbg(priv->adapter, ERROR,
160 " failed to alloc beacon_ie\n");
9558a407
AK
161 return -ENOMEM;
162 }
163
164 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
165 bss_desc->rssi = bss->signal;
d837a2ae 166 /* The caller of this function will free beacon_ie */
9558a407 167 bss_desc->beacon_buf = beacon_ie;
904f137d 168 bss_desc->beacon_buf_size = beacon_ie_len;
9558a407
AK
169 bss_desc->beacon_period = bss->beacon_interval;
170 bss_desc->cap_info_bitmap = bss->capability;
b5abcf02
AK
171 bss_desc->bss_band = bss_priv->band;
172 bss_desc->fw_tsf = bss_priv->fw_tsf;
7c6fa2a8 173 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
acebe8c1
ZL
174 mwifiex_dbg(priv->adapter, INFO,
175 "info: InterpretIE: AP WEP enabled\n");
7c6fa2a8
AK
176 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
177 } else {
178 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
179 }
180 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
181 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
182 else
183 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
184
c43933e6
BZ
185 /* Disable 11ac by default. Enable it only where there
186 * exist VHT_CAP IE in AP beacon
187 */
188 bss_desc->disable_11ac = true;
189
2a7305c8
AK
190 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
191 bss_desc->sensed_11h = true;
192
bcc920e8
AK
193 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
194 if (ret)
195 return ret;
196
197 /* Update HT40 capability based on current channel information */
198 if (bss_desc->bcn_ht_oper && bss_desc->bcn_ht_cap) {
199 u8 ht_param = bss_desc->bcn_ht_oper->ht_param;
200 u8 radio = mwifiex_band_to_radio_type(bss_desc->bss_band);
201 struct ieee80211_supported_band *sband =
202 priv->wdev.wiphy->bands[radio];
203 int freq = ieee80211_channel_to_frequency(bss_desc->channel,
204 radio);
205 struct ieee80211_channel *chan =
206 ieee80211_get_channel(priv->adapter->wiphy, freq);
207
208 switch (ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
209 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
210 if (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) {
211 sband->ht_cap.cap &=
212 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
213 sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
214 } else {
215 sband->ht_cap.cap |=
216 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
217 IEEE80211_HT_CAP_SGI_40;
218 }
219 break;
220 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
221 if (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) {
222 sband->ht_cap.cap &=
223 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
224 sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
225 } else {
226 sband->ht_cap.cap |=
227 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
228 IEEE80211_HT_CAP_SGI_40;
229 }
230 break;
231 }
232 }
233
234 return 0;
7c6fa2a8
AK
235}
236
b58df446
BZ
237void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv)
238{
239 if (priv->adapter->dt_node) {
240 char txpwr[] = {"marvell,00_txpwrlimit"};
241
242 memcpy(&txpwr[8], priv->adapter->country_code, 2);
243 mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
244 }
245}
246
e89e2da2
AK
247static int mwifiex_process_country_ie(struct mwifiex_private *priv,
248 struct cfg80211_bss *bss)
249{
9caf0364
JB
250 const u8 *country_ie;
251 u8 country_ie_len;
e89e2da2
AK
252 struct mwifiex_802_11d_domain_reg *domain_info =
253 &priv->adapter->domain_reg;
254
9caf0364
JB
255 rcu_read_lock();
256 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
257 if (!country_ie) {
258 rcu_read_unlock();
e89e2da2 259 return 0;
9caf0364 260 }
e89e2da2
AK
261
262 country_ie_len = country_ie[1];
9caf0364
JB
263 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
264 rcu_read_unlock();
e89e2da2 265 return 0;
9caf0364 266 }
e89e2da2 267
dd4a9ac0
BZ
268 if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
269 rcu_read_unlock();
acebe8c1
ZL
270 mwifiex_dbg(priv->adapter, INFO,
271 "11D: skip setting domain info in FW\n");
dd4a9ac0
BZ
272 return 0;
273 }
8384e788
WH
274
275 if (country_ie_len >
276 (IEEE80211_COUNTRY_STRING_LEN + MWIFIEX_MAX_TRIPLET_802_11D)) {
7cd74622 277 rcu_read_unlock();
8384e788
WH
278 mwifiex_dbg(priv->adapter, ERROR,
279 "11D: country_ie_len overflow!, deauth AP\n");
280 return -EINVAL;
281 }
dd4a9ac0
BZ
282 memcpy(priv->adapter->country_code, &country_ie[2], 2);
283
e89e2da2
AK
284 domain_info->country_code[0] = country_ie[2];
285 domain_info->country_code[1] = country_ie[3];
286 domain_info->country_code[2] = ' ';
287
288 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
289
290 domain_info->no_of_triplet =
291 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
292
293 memcpy((u8 *)domain_info->triplet,
294 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
295
9caf0364
JB
296 rcu_read_unlock();
297
fa0ecbb9
BZ
298 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
299 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
acebe8c1
ZL
300 mwifiex_dbg(priv->adapter, ERROR,
301 "11D: setting domain info in FW fail\n");
e89e2da2
AK
302 return -1;
303 }
304
b58df446 305 mwifiex_dnld_txpwr_table(priv);
82efa16a 306
e89e2da2
AK
307 return 0;
308}
309
5e6e3a92 310/*
5e6e3a92
BZ
311 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
312 * In both Ad-Hoc and infra mode, an deauthentication is performed
313 * first.
314 */
7c6fa2a8 315int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
b9be5f39 316 struct cfg80211_ssid *req_ssid)
5e6e3a92 317{
270e58e8 318 int ret;
5e6e3a92 319 struct mwifiex_adapter *adapter = priv->adapter;
7c6fa2a8 320 struct mwifiex_bssdescriptor *bss_desc = NULL;
5e6e3a92
BZ
321
322 priv->scan_block = false;
7c6fa2a8
AK
323
324 if (bss) {
8384e788
WH
325 if (adapter->region_code == 0x00 &&
326 mwifiex_process_country_ie(priv, bss))
327 return -EINVAL;
e89e2da2 328
7c6fa2a8
AK
329 /* Allocate and fill new bss descriptor */
330 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
0d2e7a5c
JP
331 GFP_KERNEL);
332 if (!bss_desc)
7c6fa2a8 333 return -ENOMEM;
5982b47a 334
9558a407 335 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
7c6fa2a8
AK
336 if (ret)
337 goto done;
338 }
5e6e3a92 339
6621fe18
SP
340 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
341 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
f2bbb077
AK
342 u8 config_bands;
343
f2bbb077
AK
344 if (!bss_desc)
345 return -1;
d7b9c520 346
f2bbb077 347 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
a659c430 348 HostCmd_SCAN_RADIO_TYPE_BG) {
f25b1431 349 config_bands = BAND_B | BAND_G | BAND_GN;
a659c430
XH
350 } else {
351 config_bands = BAND_A | BAND_AN;
352 if (adapter->fw_bands & BAND_AAC)
353 config_bands |= BAND_AAC;
354 }
d7b9c520 355
f2bbb077
AK
356 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
357 adapter->config_bands = config_bands;
d7b9c520 358
7c6fa2a8
AK
359 ret = mwifiex_check_network_compatibility(priv, bss_desc);
360 if (ret)
361 goto done;
5e6e3a92 362
b887664d
AK
363 if (mwifiex_11h_get_csa_closed_channel(priv) ==
364 (u8)bss_desc->channel) {
acebe8c1
ZL
365 mwifiex_dbg(adapter, ERROR,
366 "Attempt to reconnect on csa closed chan(%d)\n",
367 bss_desc->channel);
a6139b62 368 ret = -1;
b887664d
AK
369 goto done;
370 }
371
acebe8c1
ZL
372 mwifiex_dbg(adapter, INFO,
373 "info: SSID found in scan list ...\t"
374 "associating...\n");
7c6fa2a8 375
47411a06 376 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
b7097eb7
AK
377 if (netif_carrier_ok(priv->netdev))
378 netif_carrier_off(priv->netdev);
5e6e3a92
BZ
379
380 /* Clear any past association response stored for
381 * application retrieval */
382 priv->assoc_rsp_size = 0;
7c6fa2a8 383 ret = mwifiex_associate(priv, bss_desc);
a0f6d6ca
AK
384
385 /* If auth type is auto and association fails using open mode,
386 * try to connect using shared mode */
387 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
388 priv->sec_info.is_authtype_auto &&
389 priv->sec_info.wep_enabled) {
390 priv->sec_info.authentication_mode =
391 NL80211_AUTHTYPE_SHARED_KEY;
392 ret = mwifiex_associate(priv, bss_desc);
393 }
394
7c6fa2a8 395 if (bss)
5b112d3d 396 cfg80211_put_bss(priv->adapter->wiphy, bss);
5e6e3a92
BZ
397 } else {
398 /* Adhoc mode */
399 /* If the requested SSID matches current SSID, return */
7c6fa2a8 400 if (bss_desc && bss_desc->ssid.ssid_len &&
500f747c
YAP
401 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
402 ssid, &bss_desc->ssid))) {
517543fd
UR
403 ret = 0;
404 goto done;
7c6fa2a8 405 }
5e6e3a92 406
5e6e3a92
BZ
407 priv->adhoc_is_link_sensed = false;
408
7c6fa2a8
AK
409 ret = mwifiex_check_network_compatibility(priv, bss_desc);
410
47411a06 411 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
b7097eb7
AK
412 if (netif_carrier_ok(priv->netdev))
413 netif_carrier_off(priv->netdev);
7c6fa2a8
AK
414
415 if (!ret) {
acebe8c1
ZL
416 mwifiex_dbg(adapter, INFO,
417 "info: network found in scan\t"
418 " list. Joining...\n");
7c6fa2a8
AK
419 ret = mwifiex_adhoc_join(priv, bss_desc);
420 if (bss)
5b112d3d 421 cfg80211_put_bss(priv->adapter->wiphy, bss);
636c4598 422 } else {
acebe8c1
ZL
423 mwifiex_dbg(adapter, INFO,
424 "info: Network not found in\t"
425 "the list, creating adhoc with ssid = %s\n",
426 req_ssid->ssid);
7c6fa2a8 427 ret = mwifiex_adhoc_start(priv, req_ssid);
5e6e3a92
BZ
428 }
429 }
430
7c6fa2a8 431done:
d837a2ae
BZ
432 /* beacon_ie buffer was allocated in function
433 * mwifiex_fill_new_bss_desc(). Free it now.
434 */
435 if (bss_desc)
436 kfree(bss_desc->beacon_buf);
7c6fa2a8 437 kfree(bss_desc);
4699fc3f
GB
438
439 if (ret < 0)
440 priv->attempted_bss_desc = NULL;
441
5e6e3a92
BZ
442 return ret;
443}
444
5e6e3a92
BZ
445/*
446 * IOCTL request handler to set host sleep configuration.
447 *
448 * This function prepares the correct firmware command and
449 * issues it.
450 */
937a5045
XH
451int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
452 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
600f5d90 453
5e6e3a92
BZ
454{
455 struct mwifiex_adapter *adapter = priv->adapter;
456 int status = 0;
457 u32 prev_cond = 0;
458
600f5d90
AK
459 if (!hs_cfg)
460 return -ENOMEM;
461
5e6e3a92
BZ
462 switch (action) {
463 case HostCmd_ACT_GEN_SET:
464 if (adapter->pps_uapsd_mode) {
acebe8c1
ZL
465 mwifiex_dbg(adapter, INFO,
466 "info: Host Sleep IOCTL\t"
467 "is blocked in UAPSD/PPS mode\n");
5e6e3a92
BZ
468 status = -1;
469 break;
470 }
471 if (hs_cfg->is_invoke_hostcmd) {
cc0b5a64 472 if (hs_cfg->conditions == HS_CFG_CANCEL) {
5e6e3a92
BZ
473 if (!adapter->is_hs_configured)
474 /* Already cancelled */
475 break;
476 /* Save previous condition */
477 prev_cond = le32_to_cpu(adapter->hs_cfg
478 .conditions);
479 adapter->hs_cfg.conditions =
480 cpu_to_le32(hs_cfg->conditions);
481 } else if (hs_cfg->conditions) {
482 adapter->hs_cfg.conditions =
483 cpu_to_le32(hs_cfg->conditions);
484 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
485 if (hs_cfg->gap)
486 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
cc0b5a64
AK
487 } else if (adapter->hs_cfg.conditions ==
488 cpu_to_le32(HS_CFG_CANCEL)) {
5e6e3a92
BZ
489 /* Return failure if no parameters for HS
490 enable */
491 status = -1;
492 break;
493 }
fa0ecbb9
BZ
494
495 status = mwifiex_send_cmd(priv,
496 HostCmd_CMD_802_11_HS_CFG_ENH,
497 HostCmd_ACT_GEN_SET, 0,
498 &adapter->hs_cfg,
499 cmd_type == MWIFIEX_SYNC_CMD);
500
cc0b5a64 501 if (hs_cfg->conditions == HS_CFG_CANCEL)
5e6e3a92
BZ
502 /* Restore previous condition */
503 adapter->hs_cfg.conditions =
504 cpu_to_le32(prev_cond);
505 } else {
506 adapter->hs_cfg.conditions =
500f747c 507 cpu_to_le32(hs_cfg->conditions);
5e6e3a92
BZ
508 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
509 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
510 }
511 break;
512 case HostCmd_ACT_GEN_GET:
513 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
514 hs_cfg->gpio = adapter->hs_cfg.gpio;
515 hs_cfg->gap = adapter->hs_cfg.gap;
516 break;
517 default:
518 status = -1;
519 break;
520 }
521
522 return status;
523}
524
5e6e3a92
BZ
525/*
526 * Sends IOCTL request to cancel the existing Host Sleep configuration.
527 *
528 * This function allocates the IOCTL request buffer, fills it
529 * with requisite parameters and calls the IOCTL handler.
530 */
600f5d90 531int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
5e6e3a92 532{
5e6e3a92
BZ
533 struct mwifiex_ds_hs_cfg hscfg;
534
cc0b5a64 535 hscfg.conditions = HS_CFG_CANCEL;
5e6e3a92 536 hscfg.is_invoke_hostcmd = true;
5e6e3a92 537
636c4598
YAP
538 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
539 cmd_type, &hscfg);
5e6e3a92
BZ
540}
541EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
542
543/*
544 * Sends IOCTL request to cancel the existing Host Sleep configuration.
545 *
546 * This function allocates the IOCTL request buffer, fills it
547 * with requisite parameters and calls the IOCTL handler.
548 */
549int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
550{
551 struct mwifiex_ds_hs_cfg hscfg;
22c22d27
AK
552 struct mwifiex_private *priv;
553 int i;
554
555 if (disconnect_on_suspend) {
556 for (i = 0; i < adapter->priv_num; i++) {
557 priv = adapter->priv[i];
558 if (priv)
559 mwifiex_deauthenticate(priv, NULL);
560 }
561 }
5e6e3a92 562
0c9b7f22 563 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
7d7f07d8 564
0c9b7f22 565 if (priv && priv->sched_scanning) {
7d7f07d8 566#ifdef CONFIG_PM
a5c92f0b
WNH
567 if (priv->wdev.wiphy->wowlan_config &&
568 !priv->wdev.wiphy->wowlan_config->nd_config) {
7d7f07d8 569#endif
570 mwifiex_dbg(adapter, CMD, "aborting bgscan!\n");
571 mwifiex_stop_bg_scan(priv);
b34939b9 572 cfg80211_sched_scan_stopped(priv->wdev.wiphy, 0);
7d7f07d8 573#ifdef CONFIG_PM
574 }
575#endif
0c9b7f22
XH
576 }
577
5e6e3a92 578 if (adapter->hs_activated) {
acebe8c1
ZL
579 mwifiex_dbg(adapter, CMD,
580 "cmd: HS Already activated\n");
5e6e3a92
BZ
581 return true;
582 }
583
5e6e3a92
BZ
584 adapter->hs_activate_wait_q_woken = false;
585
6a162200 586 memset(&hscfg, 0, sizeof(hscfg));
5e6e3a92
BZ
587 hscfg.is_invoke_hostcmd = true;
588
c0dbba66
AK
589 adapter->hs_enabling = true;
590 mwifiex_cancel_all_pending_cmd(adapter);
591
5e6e3a92 592 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
500f747c 593 MWIFIEX_BSS_ROLE_STA),
600f5d90
AK
594 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
595 &hscfg)) {
acebe8c1
ZL
596 mwifiex_dbg(adapter, ERROR,
597 "IOCTL request HS enable failed\n");
5e6e3a92
BZ
598 return false;
599 }
600
52250cbe
AK
601 if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
602 adapter->hs_activate_wait_q_woken,
603 (10 * HZ)) <= 0) {
acebe8c1
ZL
604 mwifiex_dbg(adapter, ERROR,
605 "hs_activate_wait_q terminated\n");
9c969d8c
BZ
606 return false;
607 }
5e6e3a92
BZ
608
609 return true;
610}
611EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
612
b6e32028
WJS
613int mwifiex_set_led(struct mwifiex_adapter *adapter, int on)
614{
615 struct mwifiex_private *priv;
616 struct mwifiex_led_param ledcfg;
617
618 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
619 if (!priv->is_edge_gateway)
620 return -ENODEV;
621
622 memset(&ledcfg, 0, sizeof(struct mwifiex_led_param));
623 ledcfg.on = cpu_to_le16(on);
624
625 return mwifiex_send_cmd(priv,
626 HostCmd_CMD_802_11_LED_CONTROL,
627 HostCmd_ACT_GEN_SET, 0,
628 &ledcfg, true);
629}
630
5e6e3a92
BZ
631/*
632 * IOCTL request handler to get BSS information.
633 *
634 * This function collates the information from different driver structures
635 * to send to the user.
636 */
637int mwifiex_get_bss_info(struct mwifiex_private *priv,
638 struct mwifiex_bss_info *info)
639{
640 struct mwifiex_adapter *adapter = priv->adapter;
641 struct mwifiex_bssdescriptor *bss_desc;
5e6e3a92
BZ
642
643 if (!info)
644 return -1;
645
5e6e3a92
BZ
646 bss_desc = &priv->curr_bss_params.bss_descriptor;
647
5e6e3a92
BZ
648 info->bss_mode = priv->bss_mode;
649
b9be5f39 650 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
5e6e3a92 651
5e6e3a92
BZ
652 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
653
5e6e3a92
BZ
654 info->bss_chan = bss_desc->channel;
655
67fdf39e 656 memcpy(info->country_code, adapter->country_code,
5e218b7a 657 IEEE80211_COUNTRY_STRING_LEN);
5e6e3a92 658
5e6e3a92
BZ
659 info->media_connected = priv->media_connected;
660
5e6e3a92
BZ
661 info->max_power_level = priv->max_tx_power_level;
662 info->min_power_level = priv->min_tx_power_level;
663
5e6e3a92
BZ
664 info->adhoc_state = priv->adhoc_state;
665
5e6e3a92
BZ
666 info->bcn_nf_last = priv->bcn_nf_last;
667
5eb02e44 668 if (priv->sec_info.wep_enabled)
5e6e3a92
BZ
669 info->wep_status = true;
670 else
671 info->wep_status = false;
672
673 info->is_hs_configured = adapter->is_hs_configured;
674 info->is_deep_sleep = adapter->is_deep_sleep;
675
676 return 0;
677}
678
a0490936
AK
679/*
680 * The function disables auto deep sleep mode.
681 */
682int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
683{
9557d9f2
BN
684 struct mwifiex_ds_auto_ds auto_ds = {
685 .auto_ds = DEEP_SLEEP_OFF,
686 };
a0490936 687
fa0ecbb9
BZ
688 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
689 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
a0490936
AK
690}
691EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
692
5e6e3a92
BZ
693/*
694 * Sends IOCTL request to get the data rate.
695 *
696 * This function allocates the IOCTL request buffer, fills it
697 * with requisite parameters and calls the IOCTL handler.
698 */
006606c0 699int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
5e6e3a92 700{
270e58e8 701 int ret;
5e6e3a92 702
fa0ecbb9
BZ
703 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
704 HostCmd_ACT_GEN_GET, 0, NULL, true);
5e6e3a92 705
5e6e3a92 706 if (!ret) {
006606c0
AK
707 if (priv->is_data_rate_auto)
708 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
709 priv->tx_htinfo);
49753128 710 else
006606c0 711 *rate = priv->data_rate;
5e6e3a92
BZ
712 }
713
5e6e3a92
BZ
714 return ret;
715}
716
717/*
718 * IOCTL request handler to set tx power configuration.
719 *
720 * This function prepares the correct firmware command and
721 * issues it.
722 *
723 * For non-auto power mode, all the following power groups are set -
724 * - Modulation class HR/DSSS
725 * - Modulation class OFDM
726 * - Modulation class HTBW20
727 * - Modulation class HTBW40
728 */
600f5d90
AK
729int mwifiex_set_tx_power(struct mwifiex_private *priv,
730 struct mwifiex_power_cfg *power_cfg)
5e6e3a92 731{
270e58e8
YAP
732 int ret;
733 struct host_cmd_ds_txpwr_cfg *txp_cfg;
734 struct mwifiex_types_power_group *pg_tlv;
735 struct mwifiex_power_group *pg;
736 u8 *buf;
5e6e3a92
BZ
737 u16 dbm = 0;
738
739 if (!power_cfg->is_power_auto) {
740 dbm = (u16) power_cfg->power_level;
741 if ((dbm < priv->min_tx_power_level) ||
742 (dbm > priv->max_tx_power_level)) {
acebe8c1
ZL
743 mwifiex_dbg(priv->adapter, ERROR,
744 "txpower value %d dBm\t"
745 "is out of range (%d dBm-%d dBm)\n",
746 dbm, priv->min_tx_power_level,
747 priv->max_tx_power_level);
5e6e3a92
BZ
748 return -1;
749 }
750 }
751 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
0d2e7a5c 752 if (!buf)
b53575ec 753 return -ENOMEM;
5e6e3a92
BZ
754
755 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
756 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
757 if (!power_cfg->is_power_auto) {
916a4dd3
AB
758 u16 dbm_min = power_cfg->is_power_fixed ?
759 dbm : priv->min_tx_power_level;
760
5e6e3a92 761 txp_cfg->mode = cpu_to_le32(1);
500f747c
YAP
762 pg_tlv = (struct mwifiex_types_power_group *)
763 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
930fd35c
AK
764 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
765 pg_tlv->length =
766 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
500f747c
YAP
767 pg = (struct mwifiex_power_group *)
768 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
769 + sizeof(struct mwifiex_types_power_group));
5e6e3a92
BZ
770 /* Power group for modulation class HR/DSSS */
771 pg->first_rate_code = 0x00;
772 pg->last_rate_code = 0x03;
773 pg->modulation_class = MOD_CLASS_HR_DSSS;
774 pg->power_step = 0;
916a4dd3 775 pg->power_min = (s8) dbm_min;
5e6e3a92
BZ
776 pg->power_max = (s8) dbm;
777 pg++;
778 /* Power group for modulation class OFDM */
779 pg->first_rate_code = 0x00;
780 pg->last_rate_code = 0x07;
781 pg->modulation_class = MOD_CLASS_OFDM;
782 pg->power_step = 0;
916a4dd3 783 pg->power_min = (s8) dbm_min;
5e6e3a92
BZ
784 pg->power_max = (s8) dbm;
785 pg++;
786 /* Power group for modulation class HTBW20 */
787 pg->first_rate_code = 0x00;
788 pg->last_rate_code = 0x20;
789 pg->modulation_class = MOD_CLASS_HT;
790 pg->power_step = 0;
916a4dd3 791 pg->power_min = (s8) dbm_min;
5e6e3a92
BZ
792 pg->power_max = (s8) dbm;
793 pg->ht_bandwidth = HT_BW_20;
794 pg++;
795 /* Power group for modulation class HTBW40 */
796 pg->first_rate_code = 0x00;
797 pg->last_rate_code = 0x20;
798 pg->modulation_class = MOD_CLASS_HT;
799 pg->power_step = 0;
916a4dd3 800 pg->power_min = (s8) dbm_min;
5e6e3a92
BZ
801 pg->power_max = (s8) dbm;
802 pg->ht_bandwidth = HT_BW_40;
803 }
fa0ecbb9
BZ
804 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
805 HostCmd_ACT_GEN_SET, 0, buf, true);
5e6e3a92 806
600f5d90 807 kfree(buf);
5e6e3a92
BZ
808 return ret;
809}
810
811/*
812 * IOCTL request handler to get power save mode.
813 *
814 * This function prepares the correct firmware command and
815 * issues it.
816 */
600f5d90 817int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
5e6e3a92 818{
270e58e8 819 int ret;
5e6e3a92
BZ
820 struct mwifiex_adapter *adapter = priv->adapter;
821 u16 sub_cmd;
822
600f5d90
AK
823 if (*ps_mode)
824 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
825 else
826 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
827 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
fa0ecbb9
BZ
828 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
829 sub_cmd, BITMAP_STA_PS, NULL, true);
600f5d90 830 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
fa0ecbb9
BZ
831 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
832 GET_PS, 0, NULL, false);
5e6e3a92
BZ
833
834 return ret;
835}
836
837/*
838 * IOCTL request handler to set/reset WPA IE.
839 *
840 * The supplied WPA IE is treated as a opaque buffer. Only the first field
841 * is checked to determine WPA version. If buffer length is zero, the existing
842 * WPA IE is reset.
843 */
9ddb378b
XH
844static int mwifiex_set_wpa_ie(struct mwifiex_private *priv,
845 u8 *ie_data_ptr, u16 ie_len)
5e6e3a92
BZ
846{
847 if (ie_len) {
848 if (ie_len > sizeof(priv->wpa_ie)) {
acebe8c1
ZL
849 mwifiex_dbg(priv->adapter, ERROR,
850 "failed to copy WPA IE, too big\n");
5e6e3a92
BZ
851 return -1;
852 }
853 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
1d8f5c13 854 priv->wpa_ie_len = ie_len;
acebe8c1
ZL
855 mwifiex_dbg(priv->adapter, CMD,
856 "cmd: Set Wpa_ie_len=%d IE=%#x\n",
857 priv->wpa_ie_len, priv->wpa_ie[0]);
5e6e3a92 858
04b2312a 859 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
5e6e3a92
BZ
860 priv->sec_info.wpa_enabled = true;
861 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
862 priv->sec_info.wpa2_enabled = true;
863 } else {
864 priv->sec_info.wpa_enabled = false;
865 priv->sec_info.wpa2_enabled = false;
866 }
867 } else {
868 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
869 priv->wpa_ie_len = 0;
acebe8c1
ZL
870 mwifiex_dbg(priv->adapter, INFO,
871 "info: reset wpa_ie_len=%d IE=%#x\n",
872 priv->wpa_ie_len, priv->wpa_ie[0]);
5e6e3a92
BZ
873 priv->sec_info.wpa_enabled = false;
874 priv->sec_info.wpa2_enabled = false;
875 }
876
877 return 0;
878}
879
880/*
881 * IOCTL request handler to set/reset WAPI IE.
882 *
883 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
884 * is checked to internally enable WAPI. If buffer length is zero, the existing
885 * WAPI IE is reset.
886 */
887static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
888 u8 *ie_data_ptr, u16 ie_len)
889{
890 if (ie_len) {
891 if (ie_len > sizeof(priv->wapi_ie)) {
acebe8c1
ZL
892 mwifiex_dbg(priv->adapter, ERROR,
893 "info: failed to copy WAPI IE, too big\n");
5e6e3a92
BZ
894 return -1;
895 }
896 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
897 priv->wapi_ie_len = ie_len;
acebe8c1
ZL
898 mwifiex_dbg(priv->adapter, CMD,
899 "cmd: Set wapi_ie_len=%d IE=%#x\n",
900 priv->wapi_ie_len, priv->wapi_ie[0]);
5e6e3a92
BZ
901
902 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
903 priv->sec_info.wapi_enabled = true;
904 } else {
905 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
906 priv->wapi_ie_len = ie_len;
acebe8c1
ZL
907 mwifiex_dbg(priv->adapter, INFO,
908 "info: Reset wapi_ie_len=%d IE=%#x\n",
909 priv->wapi_ie_len, priv->wapi_ie[0]);
5e6e3a92
BZ
910 priv->sec_info.wapi_enabled = false;
911 }
912 return 0;
913}
914
13d7ba78
AP
915/*
916 * IOCTL request handler to set/reset WPS IE.
917 *
918 * The supplied WPS IE is treated as a opaque buffer. Only the first field
919 * is checked to internally enable WPS. If buffer length is zero, the existing
920 * WPS IE is reset.
921 */
922static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
923 u8 *ie_data_ptr, u16 ie_len)
924{
925 if (ie_len) {
8795ca61 926 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
acebe8c1
ZL
927 mwifiex_dbg(priv->adapter, ERROR,
928 "info: failed to copy WPS IE, too big\n");
13d7ba78
AP
929 return -1;
930 }
8795ca61
AP
931
932 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
933 if (!priv->wps_ie)
934 return -ENOMEM;
935
13d7ba78
AP
936 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
937 priv->wps_ie_len = ie_len;
acebe8c1
ZL
938 mwifiex_dbg(priv->adapter, CMD,
939 "cmd: Set wps_ie_len=%d IE=%#x\n",
940 priv->wps_ie_len, priv->wps_ie[0]);
13d7ba78
AP
941 } else {
942 kfree(priv->wps_ie);
943 priv->wps_ie_len = ie_len;
acebe8c1
ZL
944 mwifiex_dbg(priv->adapter, INFO,
945 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
13d7ba78
AP
946 }
947 return 0;
948}
949
5e6e3a92
BZ
950/*
951 * IOCTL request handler to set WAPI key.
952 *
953 * This function prepares the correct firmware command and
954 * issues it.
955 */
600f5d90 956static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
5e6e3a92
BZ
957 struct mwifiex_ds_encrypt_key *encrypt_key)
958{
5e6e3a92 959
fa0ecbb9
BZ
960 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
961 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
962 encrypt_key, true);
5e6e3a92
BZ
963}
964
5e6e3a92
BZ
965/*
966 * IOCTL request handler to set WEP network key.
967 *
968 * This function prepares the correct firmware command and
969 * issues it, after validation checks.
970 */
600f5d90 971static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
5e6e3a92
BZ
972 struct mwifiex_ds_encrypt_key *encrypt_key)
973{
e57f1734 974 struct mwifiex_adapter *adapter = priv->adapter;
270e58e8
YAP
975 int ret;
976 struct mwifiex_wep_key *wep_key;
5e6e3a92
BZ
977 int index;
978
979 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
980 priv->wep_key_curr_index = 0;
981 wep_key = &priv->wep_key[priv->wep_key_curr_index];
982 index = encrypt_key->key_index;
983 if (encrypt_key->key_disable) {
5eb02e44 984 priv->sec_info.wep_enabled = 0;
5e6e3a92
BZ
985 } else if (!encrypt_key->key_len) {
986 /* Copy the required key as the current key */
987 wep_key = &priv->wep_key[index];
988 if (!wep_key->key_length) {
acebe8c1
ZL
989 mwifiex_dbg(adapter, ERROR,
990 "key not set, so cannot enable it\n");
5e6e3a92
BZ
991 return -1;
992 }
e57f1734 993
4b9fede5 994 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2) {
e57f1734
AP
995 memcpy(encrypt_key->key_material,
996 wep_key->key_material, wep_key->key_length);
997 encrypt_key->key_len = wep_key->key_length;
998 }
999
5e6e3a92 1000 priv->wep_key_curr_index = (u16) index;
5eb02e44 1001 priv->sec_info.wep_enabled = 1;
5e6e3a92
BZ
1002 } else {
1003 wep_key = &priv->wep_key[index];
5e6e3a92
BZ
1004 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1005 /* Copy the key in the driver */
1006 memcpy(wep_key->key_material,
1007 encrypt_key->key_material,
1008 encrypt_key->key_len);
1009 wep_key->key_index = index;
1010 wep_key->key_length = encrypt_key->key_len;
5eb02e44 1011 priv->sec_info.wep_enabled = 1;
5e6e3a92
BZ
1012 }
1013 if (wep_key->key_length) {
e57f1734
AP
1014 void *enc_key;
1015
2ab87d5d 1016 if (encrypt_key->key_disable) {
e57f1734
AP
1017 memset(&priv->wep_key[index], 0,
1018 sizeof(struct mwifiex_wep_key));
97276c10
DC
1019 goto done;
1020 }
e57f1734 1021
4b9fede5 1022 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
e57f1734
AP
1023 enc_key = encrypt_key;
1024 else
1025 enc_key = NULL;
1026
5e6e3a92 1027 /* Send request to firmware */
fa0ecbb9
BZ
1028 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1029 HostCmd_ACT_GEN_SET, 0, enc_key, false);
5e6e3a92
BZ
1030 if (ret)
1031 return ret;
1032 }
e57f1734 1033
2ab87d5d 1034done:
5eb02e44 1035 if (priv->sec_info.wep_enabled)
5e6e3a92
BZ
1036 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1037 else
1038 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1039
fa0ecbb9
BZ
1040 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
1041 HostCmd_ACT_GEN_SET, 0,
1042 &priv->curr_pkt_filter, true);
5e6e3a92
BZ
1043
1044 return ret;
1045}
1046
1047/*
1048 * IOCTL request handler to set WPA key.
1049 *
1050 * This function prepares the correct firmware command and
1051 * issues it, after validation checks.
1052 *
1053 * Current driver only supports key length of up to 32 bytes.
1054 *
1055 * This function can also be used to disable a currently set key.
1056 */
600f5d90 1057static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
5e6e3a92
BZ
1058 struct mwifiex_ds_encrypt_key *encrypt_key)
1059{
270e58e8 1060 int ret;
5e6e3a92
BZ
1061 u8 remove_key = false;
1062 struct host_cmd_ds_802_11_key_material *ibss_key;
1063
1064 /* Current driver only supports key length of up to 32 bytes */
a3731658 1065 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
acebe8c1
ZL
1066 mwifiex_dbg(priv->adapter, ERROR,
1067 "key length too long\n");
5e6e3a92
BZ
1068 return -1;
1069 }
1070
eecd8250 1071 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
1072 /*
1073 * IBSS/WPA-None uses only one key (Group) for both receiving
1074 * and sending unicast and multicast packets.
1075 */
1076 /* Send the key as PTK to firmware */
1077 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
fa0ecbb9
BZ
1078 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1079 HostCmd_ACT_GEN_SET,
1080 KEY_INFO_ENABLED, encrypt_key, false);
5e6e3a92
BZ
1081 if (ret)
1082 return ret;
1083
1084 ibss_key = &priv->aes_key;
1085 memset(ibss_key, 0,
1086 sizeof(struct host_cmd_ds_802_11_key_material));
1087 /* Copy the key in the driver */
1088 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1089 encrypt_key->key_len);
1090 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1091 sizeof(ibss_key->key_param_set.key_len));
1092 ibss_key->key_param_set.key_type_id
1093 = cpu_to_le16(KEY_TYPE_ID_TKIP);
6a35a0ac 1094 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
5e6e3a92
BZ
1095
1096 /* Send the key as GTK to firmware */
1097 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1098 }
1099
1100 if (!encrypt_key->key_index)
1101 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1102
1103 if (remove_key)
fa0ecbb9
BZ
1104 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1105 HostCmd_ACT_GEN_SET,
1106 !KEY_INFO_ENABLED, encrypt_key, true);
5e6e3a92 1107 else
fa0ecbb9
BZ
1108 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1109 HostCmd_ACT_GEN_SET,
1110 KEY_INFO_ENABLED, encrypt_key, true);
5e6e3a92
BZ
1111
1112 return ret;
1113}
1114
1115/*
1116 * IOCTL request handler to set/get network keys.
1117 *
1118 * This is a generic key handling function which supports WEP, WPA
1119 * and WAPI.
1120 */
1121static int
1122mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
5e6e3a92
BZ
1123 struct mwifiex_ds_encrypt_key *encrypt_key)
1124{
270e58e8 1125 int status;
5e6e3a92
BZ
1126
1127 if (encrypt_key->is_wapi_key)
600f5d90 1128 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
5e6e3a92 1129 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
600f5d90 1130 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
5e6e3a92 1131 else
600f5d90 1132 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
5e6e3a92
BZ
1133 return status;
1134}
1135
1136/*
1137 * This function returns the driver version.
1138 */
1139int
1140mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1141 int max_len)
1142{
1143 union {
0d4b5c7c 1144 __le32 l;
5e6e3a92
BZ
1145 u8 c[4];
1146 } ver;
1147 char fw_ver[32];
1148
0d4b5c7c 1149 ver.l = cpu_to_le32(adapter->fw_release_number);
5e6e3a92
BZ
1150 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1151
1152 snprintf(version, max_len, driver_version, fw_ver);
1153
acebe8c1 1154 mwifiex_dbg(adapter, MSG, "info: MWIFIEX VERSION: %s\n", version);
5e6e3a92
BZ
1155
1156 return 0;
1157}
1158
5e6e3a92
BZ
1159/*
1160 * Sends IOCTL request to set encoding parameters.
1161 *
1162 * This function allocates the IOCTL request buffer, fills it
1163 * with requisite parameters and calls the IOCTL handler.
1164 */
53b11231
YL
1165int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1166 const u8 *key, int key_len, u8 key_index,
1167 const u8 *mac_addr, int disable)
5e6e3a92 1168{
5e6e3a92 1169 struct mwifiex_ds_encrypt_key encrypt_key;
5e6e3a92 1170
6a162200 1171 memset(&encrypt_key, 0, sizeof(encrypt_key));
5e6e3a92 1172 encrypt_key.key_len = key_len;
e57f1734 1173 encrypt_key.key_index = key_index;
53b11231
YL
1174
1175 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1176 encrypt_key.is_igtk_key = true;
1177
5e6e3a92 1178 if (!disable) {
5e6e3a92
BZ
1179 if (key_len)
1180 memcpy(encrypt_key.key_material, key, key_len);
e57f1734
AP
1181 else
1182 encrypt_key.is_current_wep_key = true;
1183
75edd2c6
AP
1184 if (mac_addr)
1185 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
e57f1734 1186 if (kp && kp->seq && kp->seq_len) {
53b11231 1187 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
e57f1734
AP
1188 encrypt_key.pn_len = kp->seq_len;
1189 encrypt_key.is_rx_seq_valid = true;
1190 }
5e6e3a92
BZ
1191 } else {
1192 encrypt_key.key_disable = true;
75edd2c6
AP
1193 if (mac_addr)
1194 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
5e6e3a92
BZ
1195 }
1196
636c4598 1197 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
5e6e3a92
BZ
1198}
1199
1200/*
1201 * Sends IOCTL request to get extended version.
1202 *
1203 * This function allocates the IOCTL request buffer, fills it
1204 * with requisite parameters and calls the IOCTL handler.
1205 */
1206int
17934b6a 1207mwifiex_get_ver_ext(struct mwifiex_private *priv, u32 version_str_sel)
5e6e3a92
BZ
1208{
1209 struct mwifiex_ver_ext ver_ext;
5e6e3a92 1210
ba852018 1211 memset(&ver_ext, 0, sizeof(ver_ext));
17934b6a 1212 ver_ext.version_str_sel = version_str_sel;
fa0ecbb9
BZ
1213 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1214 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
636c4598 1215 return -1;
5e6e3a92 1216
636c4598 1217 return 0;
5e6e3a92
BZ
1218}
1219
7feb4c48
SP
1220int
1221mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1222 struct ieee80211_channel *chan,
7feb4c48
SP
1223 unsigned int duration)
1224{
1225 struct host_cmd_ds_remain_on_chan roc_cfg;
1226 u8 sc;
1227
1228 memset(&roc_cfg, 0, sizeof(roc_cfg));
1229 roc_cfg.action = cpu_to_le16(action);
1230 if (action == HostCmd_ACT_GEN_SET) {
1231 roc_cfg.band_cfg = chan->band;
42d97a59 1232 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
7feb4c48
SP
1233 roc_cfg.band_cfg |= (sc << 2);
1234
1235 roc_cfg.channel =
1236 ieee80211_frequency_to_channel(chan->center_freq);
1237 roc_cfg.duration = cpu_to_le32(duration);
1238 }
fa0ecbb9
BZ
1239 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1240 action, 0, &roc_cfg, true)) {
acebe8c1
ZL
1241 mwifiex_dbg(priv->adapter, ERROR,
1242 "failed to remain on channel\n");
7feb4c48
SP
1243 return -1;
1244 }
1245
1246 return roc_cfg.status;
1247}
1248
5e6e3a92
BZ
1249/*
1250 * Sends IOCTL request to get statistics information.
1251 *
1252 * This function allocates the IOCTL request buffer, fills it
1253 * with requisite parameters and calls the IOCTL handler.
1254 */
1255int
1256mwifiex_get_stats_info(struct mwifiex_private *priv,
1257 struct mwifiex_ds_get_stats *log)
1258{
fa0ecbb9
BZ
1259 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1260 HostCmd_ACT_GEN_GET, 0, log, true);
5e6e3a92
BZ
1261}
1262
1263/*
1264 * IOCTL request handler to read/write register.
1265 *
1266 * This function prepares the correct firmware command and
1267 * issues it.
1268 *
1269 * Access to the following registers are supported -
1270 * - MAC
1271 * - BBP
1272 * - RF
1273 * - PMIC
1274 * - CAU
1275 */
1276static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
5e6e3a92
BZ
1277 struct mwifiex_ds_reg_rw *reg_rw,
1278 u16 action)
1279{
5e6e3a92
BZ
1280 u16 cmd_no;
1281
8cfb8600 1282 switch (reg_rw->type) {
5e6e3a92
BZ
1283 case MWIFIEX_REG_MAC:
1284 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1285 break;
1286 case MWIFIEX_REG_BBP:
1287 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1288 break;
1289 case MWIFIEX_REG_RF:
1290 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1291 break;
1292 case MWIFIEX_REG_PMIC:
1293 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1294 break;
1295 case MWIFIEX_REG_CAU:
1296 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1297 break;
1298 default:
1299 return -1;
1300 }
1301
fa0ecbb9 1302 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
5e6e3a92
BZ
1303}
1304
1305/*
1306 * Sends IOCTL request to write to a register.
1307 *
1308 * This function allocates the IOCTL request buffer, fills it
1309 * with requisite parameters and calls the IOCTL handler.
1310 */
1311int
1312mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1313 u32 reg_offset, u32 reg_value)
1314{
5e6e3a92
BZ
1315 struct mwifiex_ds_reg_rw reg_rw;
1316
8cfb8600
PM
1317 reg_rw.type = reg_type;
1318 reg_rw.offset = reg_offset;
1319 reg_rw.value = reg_value;
5e6e3a92 1320
636c4598 1321 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
5e6e3a92
BZ
1322}
1323
1324/*
1325 * Sends IOCTL request to read from a register.
1326 *
1327 * This function allocates the IOCTL request buffer, fills it
1328 * with requisite parameters and calls the IOCTL handler.
1329 */
1330int
1331mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1332 u32 reg_offset, u32 *value)
1333{
270e58e8 1334 int ret;
5e6e3a92
BZ
1335 struct mwifiex_ds_reg_rw reg_rw;
1336
8cfb8600
PM
1337 reg_rw.type = reg_type;
1338 reg_rw.offset = reg_offset;
600f5d90 1339 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
5e6e3a92 1340
5e6e3a92
BZ
1341 if (ret)
1342 goto done;
1343
8cfb8600 1344 *value = reg_rw.value;
5e6e3a92
BZ
1345
1346done:
5e6e3a92
BZ
1347 return ret;
1348}
1349
1350/*
1351 * Sends IOCTL request to read from EEPROM.
1352 *
1353 * This function allocates the IOCTL request buffer, fills it
1354 * with requisite parameters and calls the IOCTL handler.
1355 */
1356int
1357mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1358 u8 *value)
1359{
270e58e8 1360 int ret;
5e6e3a92
BZ
1361 struct mwifiex_ds_read_eeprom rd_eeprom;
1362
8cfb8600
PM
1363 rd_eeprom.offset = offset;
1364 rd_eeprom.byte_count = bytes;
5e6e3a92 1365
600f5d90 1366 /* Send request to firmware */
fa0ecbb9
BZ
1367 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1368 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
5e6e3a92 1369
600f5d90 1370 if (!ret)
8cfb8600
PM
1371 memcpy(value, rd_eeprom.value, min((u16)MAX_EEPROM_DATA,
1372 rd_eeprom.byte_count));
5e6e3a92
BZ
1373 return ret;
1374}
1375
1376/*
1377 * This function sets a generic IE. In addition to generic IE, it can
1378 * also handle WPA, WPA2 and WAPI IEs.
1379 */
1380static int
1381mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1382 u16 ie_len)
1383{
5e6e3a92
BZ
1384 struct ieee_types_vendor_header *pvendor_ie;
1385 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1386 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
9ddb378b 1387 u16 unparsed_len = ie_len, cur_ie_len;
5e6e3a92
BZ
1388
1389 /* If the passed length is zero, reset the buffer */
1390 if (!ie_len) {
1391 priv->gen_ie_buf_len = 0;
1392 priv->wps.session_enable = false;
5e6e3a92 1393 return 0;
9ddb378b
XH
1394 } else if (!ie_data_ptr ||
1395 ie_len <= sizeof(struct ieee_types_header)) {
5e6e3a92
BZ
1396 return -1;
1397 }
1398 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
5e6e3a92 1399
84a38fb3 1400 while (pvendor_ie) {
9ddb378b
XH
1401 cur_ie_len = pvendor_ie->len + sizeof(struct ieee_types_header);
1402
1403 if (pvendor_ie->element_id == WLAN_EID_RSN) {
1404 /* IE is a WPA/WPA2 IE so call set_wpa function */
1405 mwifiex_set_wpa_ie(priv, (u8 *)pvendor_ie, cur_ie_len);
1406 priv->wps.session_enable = false;
1407 goto next_ie;
1408 }
1409
1410 if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1411 /* IE is a WAPI IE so call set_wapi function */
1412 mwifiex_set_wapi_ie(priv, (u8 *)pvendor_ie,
1413 cur_ie_len);
1414 goto next_ie;
1415 }
1416
84a38fb3 1417 if (pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) {
9ddb378b
XH
1418 /* Test to see if it is a WPA IE, if not, then
1419 * it is a gen IE
84a38fb3 1420 */
cb7d1e11 1421 if (!memcmp(&pvendor_ie->oui, wpa_oui,
84a38fb3 1422 sizeof(wpa_oui))) {
9ddb378b
XH
1423 /* IE is a WPA/WPA2 IE so call set_wpa function
1424 */
1425 mwifiex_set_wpa_ie(priv, (u8 *)pvendor_ie,
1426 cur_ie_len);
1427 priv->wps.session_enable = false;
1428 goto next_ie;
84a38fb3 1429 }
5e6e3a92 1430
cb7d1e11 1431 if (!memcmp(&pvendor_ie->oui, wps_oui,
84a38fb3 1432 sizeof(wps_oui))) {
9ddb378b
XH
1433 /* Test to see if it is a WPS IE,
1434 * if so, enable wps session flag
1435 */
84a38fb3 1436 priv->wps.session_enable = true;
1437 mwifiex_dbg(priv->adapter, MSG,
9ddb378b
XH
1438 "WPS Session Enabled.\n");
1439 mwifiex_set_wps_ie(priv, (u8 *)pvendor_ie,
1440 cur_ie_len);
1441 goto next_ie;
84a38fb3 1442 }
1443 }
1444
9ddb378b 1445 /* Saved in gen_ie, such as P2P IE.etc.*/
84a38fb3 1446
9ddb378b
XH
1447 /* Verify that the passed length is not larger than the
1448 * available space remaining in the buffer
1449 */
1450 if (cur_ie_len <
1451 (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1452 /* Append the passed data to the end
1453 * of the genIeBuffer
1454 */
1455 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len,
1456 (u8 *)pvendor_ie, cur_ie_len);
1457 /* Increment the stored buffer length by the
1458 * size passed
1459 */
1460 priv->gen_ie_buf_len += cur_ie_len;
84a38fb3 1461 }
1462
9ddb378b
XH
1463next_ie:
1464 unparsed_len -= cur_ie_len;
84a38fb3 1465
1466 if (unparsed_len <= sizeof(struct ieee_types_header))
1467 pvendor_ie = NULL;
1468 else
1469 pvendor_ie = (struct ieee_types_vendor_header *)
9ddb378b 1470 (((u8 *)pvendor_ie) + cur_ie_len);
5e6e3a92 1471 }
84a38fb3 1472
9ddb378b 1473 return 0;
5e6e3a92
BZ
1474}
1475
1476/*
1477 * IOCTL request handler to set/get generic IE.
1478 *
1479 * In addition to various generic IEs, this function can also be
1480 * used to set the ARP filter.
1481 */
1482static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1483 struct mwifiex_ds_misc_gen_ie *gen_ie,
1484 u16 action)
1485{
1486 struct mwifiex_adapter *adapter = priv->adapter;
1487
1488 switch (gen_ie->type) {
1489 case MWIFIEX_IE_TYPE_GEN_IE:
1490 if (action == HostCmd_ACT_GEN_GET) {
1491 gen_ie->len = priv->wpa_ie_len;
1492 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1493 } else {
1494 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1495 (u16) gen_ie->len);
1496 }
1497 break;
1498 case MWIFIEX_IE_TYPE_ARP_FILTER:
1499 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1500 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1501 adapter->arp_filter_size = 0;
acebe8c1
ZL
1502 mwifiex_dbg(adapter, ERROR,
1503 "invalid ARP filter size\n");
5e6e3a92
BZ
1504 return -1;
1505 } else {
1506 memcpy(adapter->arp_filter, gen_ie->ie_data,
500f747c 1507 gen_ie->len);
5e6e3a92
BZ
1508 adapter->arp_filter_size = gen_ie->len;
1509 }
1510 break;
1511 default:
acebe8c1 1512 mwifiex_dbg(adapter, ERROR, "invalid IE type\n");
5e6e3a92
BZ
1513 return -1;
1514 }
1515 return 0;
1516}
1517
1518/*
1519 * Sends IOCTL request to set a generic IE.
1520 *
1521 * This function allocates the IOCTL request buffer, fills it
1522 * with requisite parameters and calls the IOCTL handler.
1523 */
1524int
4b5800fe 1525mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
5e6e3a92
BZ
1526{
1527 struct mwifiex_ds_misc_gen_ie gen_ie;
5e6e3a92 1528
67a50035 1529 if (ie_len > IEEE_MAX_IE_SIZE)
5e6e3a92
BZ
1530 return -EFAULT;
1531
1532 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1533 gen_ie.len = ie_len;
1534 memcpy(gen_ie.ie_data, ie, ie_len);
636c4598 1535 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
5e6e3a92
BZ
1536 return -EFAULT;
1537
1538 return 0;
1539}
8de00f1b 1540
1541/* This function get Host Sleep wake up reason.
1542 *
1543 */
1544int mwifiex_get_wakeup_reason(struct mwifiex_private *priv, u16 action,
1545 int cmd_type,
1546 struct mwifiex_ds_wakeup_reason *wakeup_reason)
1547{
1548 int status = 0;
1549
1550 status = mwifiex_send_cmd(priv, HostCmd_CMD_HS_WAKEUP_REASON,
1551 HostCmd_ACT_GEN_GET, 0, wakeup_reason,
1552 cmd_type == MWIFIEX_SYNC_CMD);
1553
1554 return status;
1555}