blob: 8c943b6ebf4512034eb17349a9bb320c8f66cb4e [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
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
Amitkumar Karwar22c22d22012-09-20 20:23:17 -070029static int disconnect_on_suspend = 1;
30module_param(disconnect_on_suspend, int, 0644);
31
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032/*
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 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070039int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
40 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070041{
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/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052 * Wait queue completion handler.
53 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070054 * This function waits on a cmd wait queue. It also cancels the pending
55 * request after waking up, in case of errors.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056 */
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -070057int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
58 struct cmd_ctrl_node *cmd_queued)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059{
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080060 int status;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080061
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070062 dev_dbg(adapter->dev, "cmd pending\n");
63 atomic_inc(&adapter->cmd_pending);
64
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070065 /* Wait for completion */
Bing Zhao9c969d82013-01-02 16:07:35 -080066 status = wait_event_interruptible(adapter->cmd_wait_q.wait,
67 *(cmd_queued->condition));
68 if (status) {
69 dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status);
70 return status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080072
73 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070074 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070075
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076 return status;
77}
78
79/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070080 * This function prepares the correct firmware command and
81 * issues it to set the multicast list.
82 *
83 * This function can be used to enable promiscuous mode, or enable all
84 * multicast packets, or to enable selective multicast.
85 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070086int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
87 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070088{
89 int ret = 0;
90 u16 old_pkt_filter;
91
92 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093
94 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
95 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
96 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
97 priv->curr_pkt_filter &=
98 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
99 } else {
100 /* Multicast */
101 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
102 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
103 dev_dbg(priv->adapter->dev,
104 "info: Enabling All Multicast!\n");
105 priv->curr_pkt_filter |=
106 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
107 } else {
108 priv->curr_pkt_filter &=
109 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
110 if (mcast_list->num_multicast_addr) {
111 dev_dbg(priv->adapter->dev,
112 "info: Set multicast list=%d\n",
113 mcast_list->num_multicast_addr);
114 /* Set multicast addresses to firmware */
115 if (old_pkt_filter == priv->curr_pkt_filter) {
116 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700117 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700118 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700119 HostCmd_ACT_GEN_SET, 0,
120 mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121 } else {
122 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700123 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700125 HostCmd_ACT_GEN_SET, 0,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126 mcast_list);
127 }
128 }
129 }
130 }
131 dev_dbg(priv->adapter->dev,
132 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
133 old_pkt_filter, priv->curr_pkt_filter);
134 if (old_pkt_filter != priv->curr_pkt_filter) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700135 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
136 HostCmd_ACT_GEN_SET,
137 0, &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700138 }
139
140 return ret;
141}
142
143/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700144 * This function fills bss descriptor structure using provided
145 * information.
146 */
147int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700148 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700149 struct mwifiex_bssdescriptor *bss_desc)
150{
151 int ret;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700152 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500153 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700154 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100155 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700156
Johannes Berg9caf0362012-11-29 01:25:20 +0100157 rcu_read_lock();
158 ies = rcu_dereference(bss->ies);
Johannes Berg9caf0362012-11-29 01:25:20 +0100159 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
160 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100161 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100162 rcu_read_unlock();
163
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700164 if (!beacon_ie) {
165 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
166 return -ENOMEM;
167 }
168
169 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
170 bss_desc->rssi = bss->signal;
171 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100172 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700173 bss_desc->beacon_period = bss->beacon_interval;
174 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700175 bss_desc->bss_band = bss_priv->band;
176 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700177 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
178 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
179 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
180 } else {
181 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
182 }
183 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
184 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
185 else
186 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
187
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700188 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700189
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700190 kfree(beacon_ie);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700191 return ret;
192}
193
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700194static int mwifiex_process_country_ie(struct mwifiex_private *priv,
195 struct cfg80211_bss *bss)
196{
Johannes Berg9caf0362012-11-29 01:25:20 +0100197 const u8 *country_ie;
198 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700199 struct mwifiex_802_11d_domain_reg *domain_info =
200 &priv->adapter->domain_reg;
201
Johannes Berg9caf0362012-11-29 01:25:20 +0100202 rcu_read_lock();
203 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
204 if (!country_ie) {
205 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700206 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100207 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700208
209 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100210 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
211 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700212 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100213 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700214
215 domain_info->country_code[0] = country_ie[2];
216 domain_info->country_code[1] = country_ie[3];
217 domain_info->country_code[2] = ' ';
218
219 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
220
221 domain_info->no_of_triplet =
222 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
223
224 memcpy((u8 *)domain_info->triplet,
225 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
226
Johannes Berg9caf0362012-11-29 01:25:20 +0100227 rcu_read_unlock();
228
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700229 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
230 HostCmd_ACT_GEN_SET, 0, NULL)) {
231 wiphy_err(priv->adapter->wiphy,
232 "11D: setting domain info in FW\n");
233 return -1;
234 }
235
236 return 0;
237}
238
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700239/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700240 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
241 * In both Ad-Hoc and infra mode, an deauthentication is performed
242 * first.
243 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700244int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800245 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700246{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700247 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700248 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700249 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700250
251 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700252
253 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700254 mwifiex_process_country_ie(priv, bss);
255
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700256 /* Allocate and fill new bss descriptor */
257 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000258 GFP_KERNEL);
259 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700260 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700261
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700262 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700263 if (ret)
264 goto done;
265 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700266
Bing Zhaoeecd8252011-03-28 17:55:41 -0700267 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700268 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700269 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700271 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700272
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800273 if (bss_desc) {
274 u8 config_bands = 0;
275
276 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
277 == HostCmd_SCAN_RADIO_TYPE_BG)
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800278 config_bands = BAND_B | BAND_G | BAND_GN |
279 BAND_GAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800280 else
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800281 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800282
283 if (!((config_bands | adapter->fw_bands) &
284 ~adapter->fw_bands))
285 adapter->config_bands = config_bands;
286 }
287
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700288 ret = mwifiex_check_network_compatibility(priv, bss_desc);
289 if (ret)
290 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700291
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700292 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
293 "associating...\n");
294
Avinash Patil47411a02012-11-01 18:44:16 -0700295 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800296 if (netif_carrier_ok(priv->netdev))
297 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700298
299 /* Clear any past association response stored for
300 * application retrieval */
301 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700302 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800303
304 /* If auth type is auto and association fails using open mode,
305 * try to connect using shared mode */
306 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
307 priv->sec_info.is_authtype_auto &&
308 priv->sec_info.wep_enabled) {
309 priv->sec_info.authentication_mode =
310 NL80211_AUTHTYPE_SHARED_KEY;
311 ret = mwifiex_associate(priv, bss_desc);
312 }
313
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700314 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100315 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700316 } else {
317 /* Adhoc mode */
318 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700319 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700320 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
321 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700322 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700323 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700324 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700325
326 /* Exit Adhoc mode first */
327 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700328 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700330 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331
332 priv->adhoc_is_link_sensed = false;
333
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700334 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700335
Avinash Patil47411a02012-11-01 18:44:16 -0700336 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800337 if (netif_carrier_ok(priv->netdev))
338 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700339
340 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700341 dev_dbg(adapter->dev, "info: network found in scan"
342 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700343 ret = mwifiex_adhoc_join(priv, bss_desc);
344 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100345 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700346 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347 dev_dbg(adapter->dev, "info: Network not found in "
348 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700349 req_ssid->ssid);
350 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700351 }
352 }
353
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700354done:
355 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700356 return ret;
357}
358
359/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700360 * IOCTL request handler to set host sleep configuration.
361 *
362 * This function prepares the correct firmware command and
363 * issues it.
364 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700365static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
366 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700367
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368{
369 struct mwifiex_adapter *adapter = priv->adapter;
370 int status = 0;
371 u32 prev_cond = 0;
372
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700373 if (!hs_cfg)
374 return -ENOMEM;
375
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 switch (action) {
377 case HostCmd_ACT_GEN_SET:
378 if (adapter->pps_uapsd_mode) {
379 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
380 " is blocked in UAPSD/PPS mode\n");
381 status = -1;
382 break;
383 }
384 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800385 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700386 if (!adapter->is_hs_configured)
387 /* Already cancelled */
388 break;
389 /* Save previous condition */
390 prev_cond = le32_to_cpu(adapter->hs_cfg
391 .conditions);
392 adapter->hs_cfg.conditions =
393 cpu_to_le32(hs_cfg->conditions);
394 } else if (hs_cfg->conditions) {
395 adapter->hs_cfg.conditions =
396 cpu_to_le32(hs_cfg->conditions);
397 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
398 if (hs_cfg->gap)
399 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800400 } else if (adapter->hs_cfg.conditions ==
401 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700402 /* Return failure if no parameters for HS
403 enable */
404 status = -1;
405 break;
406 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700407 if (cmd_type == MWIFIEX_SYNC_CMD)
408 status = mwifiex_send_cmd_sync(priv,
409 HostCmd_CMD_802_11_HS_CFG_ENH,
410 HostCmd_ACT_GEN_SET, 0,
411 &adapter->hs_cfg);
412 else
413 status = mwifiex_send_cmd_async(priv,
414 HostCmd_CMD_802_11_HS_CFG_ENH,
415 HostCmd_ACT_GEN_SET, 0,
416 &adapter->hs_cfg);
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800417 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700418 /* Restore previous condition */
419 adapter->hs_cfg.conditions =
420 cpu_to_le32(prev_cond);
421 } else {
422 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700423 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700424 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
425 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
426 }
427 break;
428 case HostCmd_ACT_GEN_GET:
429 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
430 hs_cfg->gpio = adapter->hs_cfg.gpio;
431 hs_cfg->gap = adapter->hs_cfg.gap;
432 break;
433 default:
434 status = -1;
435 break;
436 }
437
438 return status;
439}
440
441/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700442 * Sends IOCTL request to cancel the existing Host Sleep configuration.
443 *
444 * This function allocates the IOCTL request buffer, fills it
445 * with requisite parameters and calls the IOCTL handler.
446 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700447int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700449 struct mwifiex_ds_hs_cfg hscfg;
450
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800451 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700452 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700453
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700454 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
455 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700456}
457EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
458
459/*
460 * Sends IOCTL request to cancel the existing Host Sleep configuration.
461 *
462 * This function allocates the IOCTL request buffer, fills it
463 * with requisite parameters and calls the IOCTL handler.
464 */
465int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
466{
467 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700468 struct mwifiex_private *priv;
469 int i;
470
471 if (disconnect_on_suspend) {
472 for (i = 0; i < adapter->priv_num; i++) {
473 priv = adapter->priv[i];
474 if (priv)
475 mwifiex_deauthenticate(priv, NULL);
476 }
477 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700478
479 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900480 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700481 return true;
482 }
483
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700484 adapter->hs_activate_wait_q_woken = false;
485
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700486 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700487 hscfg.is_invoke_hostcmd = true;
488
489 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700490 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700491 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
492 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700493 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
494 return false;
495 }
496
Bing Zhao9c969d82013-01-02 16:07:35 -0800497 if (wait_event_interruptible(adapter->hs_activate_wait_q,
498 adapter->hs_activate_wait_q_woken)) {
499 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
500 return false;
501 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700502
503 return true;
504}
505EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
506
507/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700508 * IOCTL request handler to get BSS information.
509 *
510 * This function collates the information from different driver structures
511 * to send to the user.
512 */
513int mwifiex_get_bss_info(struct mwifiex_private *priv,
514 struct mwifiex_bss_info *info)
515{
516 struct mwifiex_adapter *adapter = priv->adapter;
517 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518
519 if (!info)
520 return -1;
521
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700522 bss_desc = &priv->curr_bss_params.bss_descriptor;
523
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700524 info->bss_mode = priv->bss_mode;
525
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800526 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700527
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700528 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
529
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700530 info->bss_chan = bss_desc->channel;
531
Avinash Patil67fdf392012-05-08 18:30:17 -0700532 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700533 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700534
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535 info->media_connected = priv->media_connected;
536
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537 info->max_power_level = priv->max_tx_power_level;
538 info->min_power_level = priv->min_tx_power_level;
539
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700540 info->adhoc_state = priv->adhoc_state;
541
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700542 info->bcn_nf_last = priv->bcn_nf_last;
543
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800544 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700545 info->wep_status = true;
546 else
547 info->wep_status = false;
548
549 info->is_hs_configured = adapter->is_hs_configured;
550 info->is_deep_sleep = adapter->is_deep_sleep;
551
552 return 0;
553}
554
555/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700556 * The function disables auto deep sleep mode.
557 */
558int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
559{
560 struct mwifiex_ds_auto_ds auto_ds;
561
562 auto_ds.auto_ds = DEEP_SLEEP_OFF;
563
564 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
565 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
566}
567EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
568
569/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700570 * Sends IOCTL request to get the data rate.
571 *
572 * This function allocates the IOCTL request buffer, fills it
573 * with requisite parameters and calls the IOCTL handler.
574 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700575int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700576{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700577 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700578
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700579 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
580 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700581
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700583 if (priv->is_data_rate_auto)
584 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
585 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300586 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700587 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588 }
589
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590 return ret;
591}
592
593/*
594 * IOCTL request handler to set tx power configuration.
595 *
596 * This function prepares the correct firmware command and
597 * issues it.
598 *
599 * For non-auto power mode, all the following power groups are set -
600 * - Modulation class HR/DSSS
601 * - Modulation class OFDM
602 * - Modulation class HTBW20
603 * - Modulation class HTBW40
604 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700605int mwifiex_set_tx_power(struct mwifiex_private *priv,
606 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700607{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700608 int ret;
609 struct host_cmd_ds_txpwr_cfg *txp_cfg;
610 struct mwifiex_types_power_group *pg_tlv;
611 struct mwifiex_power_group *pg;
612 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700613 u16 dbm = 0;
614
615 if (!power_cfg->is_power_auto) {
616 dbm = (u16) power_cfg->power_level;
617 if ((dbm < priv->min_tx_power_level) ||
618 (dbm > priv->max_tx_power_level)) {
619 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700620 " is out of range (%d dBm-%d dBm)\n",
621 dbm, priv->min_tx_power_level,
622 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700623 return -1;
624 }
625 }
626 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000627 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200628 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700629
630 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
631 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
632 if (!power_cfg->is_power_auto) {
633 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700634 pg_tlv = (struct mwifiex_types_power_group *)
635 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700636 pg_tlv->type = TLV_TYPE_POWER_GROUP;
637 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700638 pg = (struct mwifiex_power_group *)
639 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
640 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700641 /* Power group for modulation class HR/DSSS */
642 pg->first_rate_code = 0x00;
643 pg->last_rate_code = 0x03;
644 pg->modulation_class = MOD_CLASS_HR_DSSS;
645 pg->power_step = 0;
646 pg->power_min = (s8) dbm;
647 pg->power_max = (s8) dbm;
648 pg++;
649 /* Power group for modulation class OFDM */
650 pg->first_rate_code = 0x00;
651 pg->last_rate_code = 0x07;
652 pg->modulation_class = MOD_CLASS_OFDM;
653 pg->power_step = 0;
654 pg->power_min = (s8) dbm;
655 pg->power_max = (s8) dbm;
656 pg++;
657 /* Power group for modulation class HTBW20 */
658 pg->first_rate_code = 0x00;
659 pg->last_rate_code = 0x20;
660 pg->modulation_class = MOD_CLASS_HT;
661 pg->power_step = 0;
662 pg->power_min = (s8) dbm;
663 pg->power_max = (s8) dbm;
664 pg->ht_bandwidth = HT_BW_20;
665 pg++;
666 /* Power group for modulation class HTBW40 */
667 pg->first_rate_code = 0x00;
668 pg->last_rate_code = 0x20;
669 pg->modulation_class = MOD_CLASS_HT;
670 pg->power_step = 0;
671 pg->power_min = (s8) dbm;
672 pg->power_max = (s8) dbm;
673 pg->ht_bandwidth = HT_BW_40;
674 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700675 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
676 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700677
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700678 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700679 return ret;
680}
681
682/*
683 * IOCTL request handler to get power save mode.
684 *
685 * This function prepares the correct firmware command and
686 * issues it.
687 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700688int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700689{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700690 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700691 struct mwifiex_adapter *adapter = priv->adapter;
692 u16 sub_cmd;
693
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700694 if (*ps_mode)
695 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
696 else
697 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
698 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
699 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
700 sub_cmd, BITMAP_STA_PS, NULL);
701 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
702 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700703 HostCmd_CMD_802_11_PS_MODE_ENH,
704 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700705
706 return ret;
707}
708
709/*
710 * IOCTL request handler to set/reset WPA IE.
711 *
712 * The supplied WPA IE is treated as a opaque buffer. Only the first field
713 * is checked to determine WPA version. If buffer length is zero, the existing
714 * WPA IE is reset.
715 */
716static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
717 u8 *ie_data_ptr, u16 ie_len)
718{
719 if (ie_len) {
720 if (ie_len > sizeof(priv->wpa_ie)) {
721 dev_err(priv->adapter->dev,
722 "failed to copy WPA IE, too big\n");
723 return -1;
724 }
725 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
726 priv->wpa_ie_len = (u8) ie_len;
727 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700728 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700729
Arend van Spriel04b23122012-10-12 12:28:14 +0200730 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700731 priv->sec_info.wpa_enabled = true;
732 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
733 priv->sec_info.wpa2_enabled = true;
734 } else {
735 priv->sec_info.wpa_enabled = false;
736 priv->sec_info.wpa2_enabled = false;
737 }
738 } else {
739 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
740 priv->wpa_ie_len = 0;
741 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
742 priv->wpa_ie_len, priv->wpa_ie[0]);
743 priv->sec_info.wpa_enabled = false;
744 priv->sec_info.wpa2_enabled = false;
745 }
746
747 return 0;
748}
749
750/*
751 * IOCTL request handler to set/reset WAPI IE.
752 *
753 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
754 * is checked to internally enable WAPI. If buffer length is zero, the existing
755 * WAPI IE is reset.
756 */
757static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
758 u8 *ie_data_ptr, u16 ie_len)
759{
760 if (ie_len) {
761 if (ie_len > sizeof(priv->wapi_ie)) {
762 dev_dbg(priv->adapter->dev,
763 "info: failed to copy WAPI IE, too big\n");
764 return -1;
765 }
766 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
767 priv->wapi_ie_len = ie_len;
768 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700769 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700770
771 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
772 priv->sec_info.wapi_enabled = true;
773 } else {
774 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
775 priv->wapi_ie_len = ie_len;
776 dev_dbg(priv->adapter->dev,
777 "info: Reset wapi_ie_len=%d IE=%#x\n",
778 priv->wapi_ie_len, priv->wapi_ie[0]);
779 priv->sec_info.wapi_enabled = false;
780 }
781 return 0;
782}
783
784/*
Avinash Patil13d7ba72012-04-09 20:06:56 -0700785 * IOCTL request handler to set/reset WPS IE.
786 *
787 * The supplied WPS IE is treated as a opaque buffer. Only the first field
788 * is checked to internally enable WPS. If buffer length is zero, the existing
789 * WPS IE is reset.
790 */
791static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
792 u8 *ie_data_ptr, u16 ie_len)
793{
794 if (ie_len) {
795 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
796 if (!priv->wps_ie)
797 return -ENOMEM;
798 if (ie_len > sizeof(priv->wps_ie)) {
799 dev_dbg(priv->adapter->dev,
800 "info: failed to copy WPS IE, too big\n");
801 kfree(priv->wps_ie);
802 return -1;
803 }
804 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
805 priv->wps_ie_len = ie_len;
806 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
807 priv->wps_ie_len, priv->wps_ie[0]);
808 } else {
809 kfree(priv->wps_ie);
810 priv->wps_ie_len = ie_len;
811 dev_dbg(priv->adapter->dev,
812 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
813 }
814 return 0;
815}
816
817/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700818 * IOCTL request handler to set WAPI key.
819 *
820 * This function prepares the correct firmware command and
821 * issues it.
822 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700823static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700824 struct mwifiex_ds_encrypt_key *encrypt_key)
825{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700826
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700827 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700828 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
829 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700830}
831
832/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700833 * IOCTL request handler to set WEP network key.
834 *
835 * This function prepares the correct firmware command and
836 * issues it, after validation checks.
837 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700838static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700839 struct mwifiex_ds_encrypt_key *encrypt_key)
840{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700841 int ret;
842 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700843 int index;
844
845 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
846 priv->wep_key_curr_index = 0;
847 wep_key = &priv->wep_key[priv->wep_key_curr_index];
848 index = encrypt_key->key_index;
849 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800850 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700851 } else if (!encrypt_key->key_len) {
852 /* Copy the required key as the current key */
853 wep_key = &priv->wep_key[index];
854 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700855 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700856 "key not set, so cannot enable it\n");
857 return -1;
858 }
859 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800860 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 } else {
862 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700863 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
864 /* Copy the key in the driver */
865 memcpy(wep_key->key_material,
866 encrypt_key->key_material,
867 encrypt_key->key_len);
868 wep_key->key_index = index;
869 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800870 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871 }
872 if (wep_key->key_length) {
873 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700874 ret = mwifiex_send_cmd_async(priv,
875 HostCmd_CMD_802_11_KEY_MATERIAL,
876 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700877 if (ret)
878 return ret;
879 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800880 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700881 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
882 else
883 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
884
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700885 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
886 HostCmd_ACT_GEN_SET, 0,
887 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700888
889 return ret;
890}
891
892/*
893 * IOCTL request handler to set WPA key.
894 *
895 * This function prepares the correct firmware command and
896 * issues it, after validation checks.
897 *
898 * Current driver only supports key length of up to 32 bytes.
899 *
900 * This function can also be used to disable a currently set key.
901 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700902static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700903 struct mwifiex_ds_encrypt_key *encrypt_key)
904{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700905 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700906 u8 remove_key = false;
907 struct host_cmd_ds_802_11_key_material *ibss_key;
908
909 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700910 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700911 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700912 return -1;
913 }
914
Bing Zhaoeecd8252011-03-28 17:55:41 -0700915 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700916 /*
917 * IBSS/WPA-None uses only one key (Group) for both receiving
918 * and sending unicast and multicast packets.
919 */
920 /* Send the key as PTK to firmware */
921 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700922 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700923 HostCmd_CMD_802_11_KEY_MATERIAL,
924 HostCmd_ACT_GEN_SET,
925 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700926 if (ret)
927 return ret;
928
929 ibss_key = &priv->aes_key;
930 memset(ibss_key, 0,
931 sizeof(struct host_cmd_ds_802_11_key_material));
932 /* Copy the key in the driver */
933 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
934 encrypt_key->key_len);
935 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
936 sizeof(ibss_key->key_param_set.key_len));
937 ibss_key->key_param_set.key_type_id
938 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700939 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700940
941 /* Send the key as GTK to firmware */
942 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
943 }
944
945 if (!encrypt_key->key_index)
946 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
947
948 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700949 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700950 HostCmd_CMD_802_11_KEY_MATERIAL,
951 HostCmd_ACT_GEN_SET,
952 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700953 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700954 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700955 HostCmd_CMD_802_11_KEY_MATERIAL,
956 HostCmd_ACT_GEN_SET,
957 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700958
959 return ret;
960}
961
962/*
963 * IOCTL request handler to set/get network keys.
964 *
965 * This is a generic key handling function which supports WEP, WPA
966 * and WAPI.
967 */
968static int
969mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700970 struct mwifiex_ds_encrypt_key *encrypt_key)
971{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700972 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700973
974 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700975 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700976 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700977 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700978 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700979 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700980 return status;
981}
982
983/*
984 * This function returns the driver version.
985 */
986int
987mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
988 int max_len)
989{
990 union {
991 u32 l;
992 u8 c[4];
993 } ver;
994 char fw_ver[32];
995
996 ver.l = adapter->fw_release_number;
997 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
998
999 snprintf(version, max_len, driver_version, fw_ver);
1000
1001 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1002
1003 return 0;
1004}
1005
1006/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001007 * Sends IOCTL request to set encoding parameters.
1008 *
1009 * This function allocates the IOCTL request buffer, fills it
1010 * with requisite parameters and calls the IOCTL handler.
1011 */
Ying Luo53b11232012-08-03 18:06:13 -07001012int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1013 const u8 *key, int key_len, u8 key_index,
1014 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001017
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001018 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1019 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001020
1021 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1022 encrypt_key.is_igtk_key = true;
1023
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001024 if (!disable) {
1025 encrypt_key.key_index = key_index;
1026 if (key_len)
1027 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001028 if (mac_addr)
1029 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001030 if (kp && kp->seq && kp->seq_len)
1031 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001032 } else {
1033 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001034 if (mac_addr)
1035 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001036 }
1037
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001038 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039}
1040
1041/*
1042 * Sends IOCTL request to get extended version.
1043 *
1044 * This function allocates the IOCTL request buffer, fills it
1045 * with requisite parameters and calls the IOCTL handler.
1046 */
1047int
1048mwifiex_get_ver_ext(struct mwifiex_private *priv)
1049{
1050 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001051
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001052 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001053 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001054 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001055 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001056
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001057 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058}
1059
Stone Piao7feb4c42012-09-25 20:23:36 -07001060int
1061mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1062 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001063 unsigned int duration)
1064{
1065 struct host_cmd_ds_remain_on_chan roc_cfg;
1066 u8 sc;
1067
1068 memset(&roc_cfg, 0, sizeof(roc_cfg));
1069 roc_cfg.action = cpu_to_le16(action);
1070 if (action == HostCmd_ACT_GEN_SET) {
1071 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001072 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001073 roc_cfg.band_cfg |= (sc << 2);
1074
1075 roc_cfg.channel =
1076 ieee80211_frequency_to_channel(chan->center_freq);
1077 roc_cfg.duration = cpu_to_le32(duration);
1078 }
1079 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1080 action, 0, &roc_cfg)) {
1081 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1082 return -1;
1083 }
1084
1085 return roc_cfg.status;
1086}
1087
Stone Piao9197ab92012-09-25 20:23:42 -07001088int
1089mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1090{
1091 if (GET_BSS_ROLE(priv) == bss_role) {
1092 dev_dbg(priv->adapter->dev,
1093 "info: already in the desired role.\n");
1094 return 0;
1095 }
1096
1097 mwifiex_free_priv(priv);
1098 mwifiex_init_priv(priv);
1099
1100 priv->bss_role = bss_role;
1101 switch (bss_role) {
1102 case MWIFIEX_BSS_ROLE_UAP:
1103 priv->bss_mode = NL80211_IFTYPE_AP;
1104 break;
1105 case MWIFIEX_BSS_ROLE_STA:
1106 case MWIFIEX_BSS_ROLE_ANY:
1107 default:
1108 priv->bss_mode = NL80211_IFTYPE_STATION;
1109 break;
1110 }
1111
1112 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1113 HostCmd_ACT_GEN_SET, 0, NULL);
1114
1115 return mwifiex_sta_init_cmd(priv, false);
1116}
1117
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001118/*
1119 * Sends IOCTL request to get statistics information.
1120 *
1121 * This function allocates the IOCTL request buffer, fills it
1122 * with requisite parameters and calls the IOCTL handler.
1123 */
1124int
1125mwifiex_get_stats_info(struct mwifiex_private *priv,
1126 struct mwifiex_ds_get_stats *log)
1127{
Bing Zhao67a50032011-07-13 18:38:34 -07001128 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001129 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001130}
1131
1132/*
1133 * IOCTL request handler to read/write register.
1134 *
1135 * This function prepares the correct firmware command and
1136 * issues it.
1137 *
1138 * Access to the following registers are supported -
1139 * - MAC
1140 * - BBP
1141 * - RF
1142 * - PMIC
1143 * - CAU
1144 */
1145static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001146 struct mwifiex_ds_reg_rw *reg_rw,
1147 u16 action)
1148{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149 u16 cmd_no;
1150
1151 switch (le32_to_cpu(reg_rw->type)) {
1152 case MWIFIEX_REG_MAC:
1153 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1154 break;
1155 case MWIFIEX_REG_BBP:
1156 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1157 break;
1158 case MWIFIEX_REG_RF:
1159 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1160 break;
1161 case MWIFIEX_REG_PMIC:
1162 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1163 break;
1164 case MWIFIEX_REG_CAU:
1165 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1166 break;
1167 default:
1168 return -1;
1169 }
1170
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001171 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001172
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001173}
1174
1175/*
1176 * Sends IOCTL request to write to a register.
1177 *
1178 * This function allocates the IOCTL request buffer, fills it
1179 * with requisite parameters and calls the IOCTL handler.
1180 */
1181int
1182mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1183 u32 reg_offset, u32 reg_value)
1184{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001185 struct mwifiex_ds_reg_rw reg_rw;
1186
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187 reg_rw.type = cpu_to_le32(reg_type);
1188 reg_rw.offset = cpu_to_le32(reg_offset);
1189 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001190
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001191 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001192}
1193
1194/*
1195 * Sends IOCTL request to read from a register.
1196 *
1197 * This function allocates the IOCTL request buffer, fills it
1198 * with requisite parameters and calls the IOCTL handler.
1199 */
1200int
1201mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1202 u32 reg_offset, u32 *value)
1203{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001204 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001205 struct mwifiex_ds_reg_rw reg_rw;
1206
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207 reg_rw.type = cpu_to_le32(reg_type);
1208 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001209 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001210
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001211 if (ret)
1212 goto done;
1213
1214 *value = le32_to_cpu(reg_rw.value);
1215
1216done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001217 return ret;
1218}
1219
1220/*
1221 * Sends IOCTL request to read from EEPROM.
1222 *
1223 * This function allocates the IOCTL request buffer, fills it
1224 * with requisite parameters and calls the IOCTL handler.
1225 */
1226int
1227mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1228 u8 *value)
1229{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001230 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001231 struct mwifiex_ds_read_eeprom rd_eeprom;
1232
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001233 rd_eeprom.offset = cpu_to_le16((u16) offset);
1234 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001235
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001236 /* Send request to firmware */
1237 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1238 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001240 if (!ret)
1241 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001242 return ret;
1243}
1244
1245/*
1246 * This function sets a generic IE. In addition to generic IE, it can
1247 * also handle WPA, WPA2 and WAPI IEs.
1248 */
1249static int
1250mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1251 u16 ie_len)
1252{
1253 int ret = 0;
1254 struct ieee_types_vendor_header *pvendor_ie;
1255 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1256 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1257
1258 /* If the passed length is zero, reset the buffer */
1259 if (!ie_len) {
1260 priv->gen_ie_buf_len = 0;
1261 priv->wps.session_enable = false;
1262
1263 return 0;
1264 } else if (!ie_data_ptr) {
1265 return -1;
1266 }
1267 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1268 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
Arend van Spriel04b23122012-10-12 12:28:14 +02001269 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001270 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1271 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001272
1273 /* IE is a WPA/WPA2 IE so call set_wpa function */
1274 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1275 priv->wps.session_enable = false;
1276
1277 return ret;
1278 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1279 /* IE is a WAPI IE so call set_wapi function */
1280 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1281
1282 return ret;
1283 }
1284 /*
1285 * Verify that the passed length is not larger than the
1286 * available space remaining in the buffer
1287 */
1288 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1289
1290 /* Test to see if it is a WPS IE, if so, enable
1291 * wps session flag
1292 */
1293 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001294 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1295 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001296 priv->wps.session_enable = true;
1297 dev_dbg(priv->adapter->dev,
1298 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba72012-04-09 20:06:56 -07001299 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001300 }
1301
1302 /* Append the passed data to the end of the
1303 genIeBuffer */
1304 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001305 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001306 /* Increment the stored buffer length by the
1307 size passed */
1308 priv->gen_ie_buf_len += ie_len;
1309 } else {
1310 /* Passed data does not fit in the remaining
1311 buffer space */
1312 ret = -1;
1313 }
1314
1315 /* Return 0, or -1 for error case */
1316 return ret;
1317}
1318
1319/*
1320 * IOCTL request handler to set/get generic IE.
1321 *
1322 * In addition to various generic IEs, this function can also be
1323 * used to set the ARP filter.
1324 */
1325static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1326 struct mwifiex_ds_misc_gen_ie *gen_ie,
1327 u16 action)
1328{
1329 struct mwifiex_adapter *adapter = priv->adapter;
1330
1331 switch (gen_ie->type) {
1332 case MWIFIEX_IE_TYPE_GEN_IE:
1333 if (action == HostCmd_ACT_GEN_GET) {
1334 gen_ie->len = priv->wpa_ie_len;
1335 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1336 } else {
1337 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1338 (u16) gen_ie->len);
1339 }
1340 break;
1341 case MWIFIEX_IE_TYPE_ARP_FILTER:
1342 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1343 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1344 adapter->arp_filter_size = 0;
1345 dev_err(adapter->dev, "invalid ARP filter size\n");
1346 return -1;
1347 } else {
1348 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001349 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001350 adapter->arp_filter_size = gen_ie->len;
1351 }
1352 break;
1353 default:
1354 dev_err(adapter->dev, "invalid IE type\n");
1355 return -1;
1356 }
1357 return 0;
1358}
1359
1360/*
1361 * Sends IOCTL request to set a generic IE.
1362 *
1363 * This function allocates the IOCTL request buffer, fills it
1364 * with requisite parameters and calls the IOCTL handler.
1365 */
1366int
1367mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1368{
1369 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001370
Bing Zhao67a50032011-07-13 18:38:34 -07001371 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001372 return -EFAULT;
1373
1374 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1375 gen_ie.len = ie_len;
1376 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001377 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001378 return -EFAULT;
1379
1380 return 0;
1381}