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