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