blob: f542bb8ccbc8d4ce6859e8fff1e45784183f8fbb [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 Karwar600f5d92011-04-13 17:27:06 -070057int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070058{
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080059 int status;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080060 struct cmd_ctrl_node *cmd_queued;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070061
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080062 if (!adapter->cmd_queued)
63 return 0;
64
65 cmd_queued = adapter->cmd_queued;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -070066 adapter->cmd_queued = NULL;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080067
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070068 dev_dbg(adapter->dev, "cmd pending\n");
69 atomic_inc(&adapter->cmd_pending);
70
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070071 /* Wait for completion */
Bing Zhao9c969d82013-01-02 16:07:35 -080072 status = wait_event_interruptible(adapter->cmd_wait_q.wait,
73 *(cmd_queued->condition));
74 if (status) {
75 dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status);
76 return status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080078
79 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070080 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070081
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082 return status;
83}
84
85/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070086 * This function prepares the correct firmware command and
87 * issues it to set the multicast list.
88 *
89 * This function can be used to enable promiscuous mode, or enable all
90 * multicast packets, or to enable selective multicast.
91 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070092int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
93 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070094{
95 int ret = 0;
96 u16 old_pkt_filter;
97
98 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070099
100 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
101 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
102 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
103 priv->curr_pkt_filter &=
104 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
105 } else {
106 /* Multicast */
107 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
108 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
109 dev_dbg(priv->adapter->dev,
110 "info: Enabling All Multicast!\n");
111 priv->curr_pkt_filter |=
112 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
113 } else {
114 priv->curr_pkt_filter &=
115 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
116 if (mcast_list->num_multicast_addr) {
117 dev_dbg(priv->adapter->dev,
118 "info: Set multicast list=%d\n",
119 mcast_list->num_multicast_addr);
120 /* Set multicast addresses to firmware */
121 if (old_pkt_filter == priv->curr_pkt_filter) {
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,
126 mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700127 } else {
128 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700129 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700131 HostCmd_ACT_GEN_SET, 0,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700132 mcast_list);
133 }
134 }
135 }
136 }
137 dev_dbg(priv->adapter->dev,
138 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
139 old_pkt_filter, priv->curr_pkt_filter);
140 if (old_pkt_filter != priv->curr_pkt_filter) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700141 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
142 HostCmd_ACT_GEN_SET,
143 0, &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700144 }
145
146 return ret;
147}
148
149/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700150 * This function fills bss descriptor structure using provided
151 * information.
152 */
153int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700154 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700155 struct mwifiex_bssdescriptor *bss_desc)
156{
157 int ret;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700158 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500159 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700160 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100161 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700162
Johannes Berg9caf0362012-11-29 01:25:20 +0100163 rcu_read_lock();
164 ies = rcu_dereference(bss->ies);
165 if (WARN_ON(!ies)) {
166 /* should never happen */
167 rcu_read_unlock();
168 return -EINVAL;
169 }
170 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
171 beacon_ie_len = ies->len;
172 rcu_read_unlock();
173
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700174 if (!beacon_ie) {
175 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
176 return -ENOMEM;
177 }
178
179 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
180 bss_desc->rssi = bss->signal;
181 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100182 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700183 bss_desc->beacon_period = bss->beacon_interval;
184 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700185 bss_desc->bss_band = bss_priv->band;
186 bss_desc->fw_tsf = bss_priv->fw_tsf;
187 bss_desc->timestamp = bss->tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700188 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
189 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
190 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
191 } else {
192 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
193 }
194 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
195 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
196 else
197 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
198
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700199 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700200
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700201 kfree(beacon_ie);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700202 return ret;
203}
204
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700205static int mwifiex_process_country_ie(struct mwifiex_private *priv,
206 struct cfg80211_bss *bss)
207{
Johannes Berg9caf0362012-11-29 01:25:20 +0100208 const u8 *country_ie;
209 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700210 struct mwifiex_802_11d_domain_reg *domain_info =
211 &priv->adapter->domain_reg;
212
Johannes Berg9caf0362012-11-29 01:25:20 +0100213 rcu_read_lock();
214 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
215 if (!country_ie) {
216 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700217 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100218 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700219
220 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100221 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
222 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700223 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100224 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700225
226 domain_info->country_code[0] = country_ie[2];
227 domain_info->country_code[1] = country_ie[3];
228 domain_info->country_code[2] = ' ';
229
230 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
231
232 domain_info->no_of_triplet =
233 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
234
235 memcpy((u8 *)domain_info->triplet,
236 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
237
Johannes Berg9caf0362012-11-29 01:25:20 +0100238 rcu_read_unlock();
239
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700240 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
241 HostCmd_ACT_GEN_SET, 0, NULL)) {
242 wiphy_err(priv->adapter->wiphy,
243 "11D: setting domain info in FW\n");
244 return -1;
245 }
246
247 return 0;
248}
249
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700250/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700251 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
252 * In both Ad-Hoc and infra mode, an deauthentication is performed
253 * first.
254 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700255int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800256 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700257{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700258 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700259 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700260 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700261
262 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700263
264 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700265 mwifiex_process_country_ie(priv, bss);
266
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700267 /* Allocate and fill new bss descriptor */
268 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
269 GFP_KERNEL);
270 if (!bss_desc) {
271 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
272 return -ENOMEM;
273 }
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700274
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700275 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700276 if (ret)
277 goto done;
278 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700279
Bing Zhaoeecd8252011-03-28 17:55:41 -0700280 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700281 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700282 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700283 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700284 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700285
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800286 if (bss_desc) {
287 u8 config_bands = 0;
288
289 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
290 == HostCmd_SCAN_RADIO_TYPE_BG)
291 config_bands = BAND_B | BAND_G | BAND_GN;
292 else
293 config_bands = BAND_A | BAND_AN;
294
295 if (!((config_bands | adapter->fw_bands) &
296 ~adapter->fw_bands))
297 adapter->config_bands = config_bands;
298 }
299
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700300 ret = mwifiex_check_network_compatibility(priv, bss_desc);
301 if (ret)
302 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700303
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700304 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
305 "associating...\n");
306
Avinash Patil47411a02012-11-01 18:44:16 -0700307 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800308 if (netif_carrier_ok(priv->netdev))
309 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700310
311 /* Clear any past association response stored for
312 * application retrieval */
313 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700314 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800315
316 /* If auth type is auto and association fails using open mode,
317 * try to connect using shared mode */
318 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
319 priv->sec_info.is_authtype_auto &&
320 priv->sec_info.wep_enabled) {
321 priv->sec_info.authentication_mode =
322 NL80211_AUTHTYPE_SHARED_KEY;
323 ret = mwifiex_associate(priv, bss_desc);
324 }
325
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700326 if (bss)
327 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700328 } else {
329 /* Adhoc mode */
330 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700331 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700332 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
333 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700334 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700335 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700336 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337
338 /* Exit Adhoc mode first */
339 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700340 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700341 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700342 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700343
344 priv->adhoc_is_link_sensed = false;
345
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700346 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347
Avinash Patil47411a02012-11-01 18:44:16 -0700348 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800349 if (netif_carrier_ok(priv->netdev))
350 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700351
352 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353 dev_dbg(adapter->dev, "info: network found in scan"
354 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700355 ret = mwifiex_adhoc_join(priv, bss_desc);
356 if (bss)
357 cfg80211_put_bss(bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700358 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700359 dev_dbg(adapter->dev, "info: Network not found in "
360 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700361 req_ssid->ssid);
362 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700363 }
364 }
365
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700366done:
367 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368 return ret;
369}
370
371/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700372 * IOCTL request handler to set host sleep configuration.
373 *
374 * This function prepares the correct firmware command and
375 * issues it.
376 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700377static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
378 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700379
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700380{
381 struct mwifiex_adapter *adapter = priv->adapter;
382 int status = 0;
383 u32 prev_cond = 0;
384
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700385 if (!hs_cfg)
386 return -ENOMEM;
387
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700388 switch (action) {
389 case HostCmd_ACT_GEN_SET:
390 if (adapter->pps_uapsd_mode) {
391 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
392 " is blocked in UAPSD/PPS mode\n");
393 status = -1;
394 break;
395 }
396 if (hs_cfg->is_invoke_hostcmd) {
397 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
398 if (!adapter->is_hs_configured)
399 /* Already cancelled */
400 break;
401 /* Save previous condition */
402 prev_cond = le32_to_cpu(adapter->hs_cfg
403 .conditions);
404 adapter->hs_cfg.conditions =
405 cpu_to_le32(hs_cfg->conditions);
406 } else if (hs_cfg->conditions) {
407 adapter->hs_cfg.conditions =
408 cpu_to_le32(hs_cfg->conditions);
409 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
410 if (hs_cfg->gap)
411 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700412 } else if (adapter->hs_cfg.conditions
413 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700414 /* Return failure if no parameters for HS
415 enable */
416 status = -1;
417 break;
418 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700419 if (cmd_type == MWIFIEX_SYNC_CMD)
420 status = mwifiex_send_cmd_sync(priv,
421 HostCmd_CMD_802_11_HS_CFG_ENH,
422 HostCmd_ACT_GEN_SET, 0,
423 &adapter->hs_cfg);
424 else
425 status = mwifiex_send_cmd_async(priv,
426 HostCmd_CMD_802_11_HS_CFG_ENH,
427 HostCmd_ACT_GEN_SET, 0,
428 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700429 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
430 /* Restore previous condition */
431 adapter->hs_cfg.conditions =
432 cpu_to_le32(prev_cond);
433 } else {
434 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700435 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700436 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
437 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
438 }
439 break;
440 case HostCmd_ACT_GEN_GET:
441 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
442 hs_cfg->gpio = adapter->hs_cfg.gpio;
443 hs_cfg->gap = adapter->hs_cfg.gap;
444 break;
445 default:
446 status = -1;
447 break;
448 }
449
450 return status;
451}
452
453/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700454 * Sends IOCTL request to cancel the existing Host Sleep configuration.
455 *
456 * This function allocates the IOCTL request buffer, fills it
457 * with requisite parameters and calls the IOCTL handler.
458 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700459int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700460{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700461 struct mwifiex_ds_hs_cfg hscfg;
462
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
464 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700465
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700466 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
467 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700468}
469EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
470
471/*
472 * Sends IOCTL request to cancel the existing Host Sleep configuration.
473 *
474 * This function allocates the IOCTL request buffer, fills it
475 * with requisite parameters and calls the IOCTL handler.
476 */
477int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
478{
479 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700480 struct mwifiex_private *priv;
481 int i;
482
483 if (disconnect_on_suspend) {
484 for (i = 0; i < adapter->priv_num; i++) {
485 priv = adapter->priv[i];
486 if (priv)
487 mwifiex_deauthenticate(priv, NULL);
488 }
489 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700490
491 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900492 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700493 return true;
494 }
495
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700496 adapter->hs_activate_wait_q_woken = false;
497
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700498 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700499 hscfg.is_invoke_hostcmd = true;
500
501 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700502 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700503 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
504 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
506 return false;
507 }
508
Bing Zhao9c969d82013-01-02 16:07:35 -0800509 if (wait_event_interruptible(adapter->hs_activate_wait_q,
510 adapter->hs_activate_wait_q_woken)) {
511 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
512 return false;
513 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514
515 return true;
516}
517EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
518
519/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700520 * IOCTL request handler to get BSS information.
521 *
522 * This function collates the information from different driver structures
523 * to send to the user.
524 */
525int mwifiex_get_bss_info(struct mwifiex_private *priv,
526 struct mwifiex_bss_info *info)
527{
528 struct mwifiex_adapter *adapter = priv->adapter;
529 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700530
531 if (!info)
532 return -1;
533
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700534 bss_desc = &priv->curr_bss_params.bss_descriptor;
535
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700536 info->bss_mode = priv->bss_mode;
537
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800538 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700539
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700540 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
541
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700542 info->bss_chan = bss_desc->channel;
543
Avinash Patil67fdf392012-05-08 18:30:17 -0700544 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700545 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700546
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700547 info->media_connected = priv->media_connected;
548
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549 info->max_power_level = priv->max_tx_power_level;
550 info->min_power_level = priv->min_tx_power_level;
551
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700552 info->adhoc_state = priv->adhoc_state;
553
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700554 info->bcn_nf_last = priv->bcn_nf_last;
555
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800556 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700557 info->wep_status = true;
558 else
559 info->wep_status = false;
560
561 info->is_hs_configured = adapter->is_hs_configured;
562 info->is_deep_sleep = adapter->is_deep_sleep;
563
564 return 0;
565}
566
567/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700568 * The function disables auto deep sleep mode.
569 */
570int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
571{
572 struct mwifiex_ds_auto_ds auto_ds;
573
574 auto_ds.auto_ds = DEEP_SLEEP_OFF;
575
576 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
577 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
578}
579EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
580
581/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582 * Sends IOCTL request to get the data rate.
583 *
584 * This function allocates the IOCTL request buffer, fills it
585 * with requisite parameters and calls the IOCTL handler.
586 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700587int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700589 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700591 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
592 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700593
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700595 if (priv->is_data_rate_auto)
596 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
597 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300598 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700599 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700600 }
601
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602 return ret;
603}
604
605/*
606 * IOCTL request handler to set tx power configuration.
607 *
608 * This function prepares the correct firmware command and
609 * issues it.
610 *
611 * For non-auto power mode, all the following power groups are set -
612 * - Modulation class HR/DSSS
613 * - Modulation class OFDM
614 * - Modulation class HTBW20
615 * - Modulation class HTBW40
616 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700617int mwifiex_set_tx_power(struct mwifiex_private *priv,
618 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700620 int ret;
621 struct host_cmd_ds_txpwr_cfg *txp_cfg;
622 struct mwifiex_types_power_group *pg_tlv;
623 struct mwifiex_power_group *pg;
624 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700625 u16 dbm = 0;
626
627 if (!power_cfg->is_power_auto) {
628 dbm = (u16) power_cfg->power_level;
629 if ((dbm < priv->min_tx_power_level) ||
630 (dbm > priv->max_tx_power_level)) {
631 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700632 " is out of range (%d dBm-%d dBm)\n",
633 dbm, priv->min_tx_power_level,
634 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700635 return -1;
636 }
637 }
638 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
639 if (!buf) {
640 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700641 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200642 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700643 }
644
645 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
646 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
647 if (!power_cfg->is_power_auto) {
648 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700649 pg_tlv = (struct mwifiex_types_power_group *)
650 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700651 pg_tlv->type = TLV_TYPE_POWER_GROUP;
652 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700653 pg = (struct mwifiex_power_group *)
654 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
655 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700656 /* Power group for modulation class HR/DSSS */
657 pg->first_rate_code = 0x00;
658 pg->last_rate_code = 0x03;
659 pg->modulation_class = MOD_CLASS_HR_DSSS;
660 pg->power_step = 0;
661 pg->power_min = (s8) dbm;
662 pg->power_max = (s8) dbm;
663 pg++;
664 /* Power group for modulation class OFDM */
665 pg->first_rate_code = 0x00;
666 pg->last_rate_code = 0x07;
667 pg->modulation_class = MOD_CLASS_OFDM;
668 pg->power_step = 0;
669 pg->power_min = (s8) dbm;
670 pg->power_max = (s8) dbm;
671 pg++;
672 /* Power group for modulation class HTBW20 */
673 pg->first_rate_code = 0x00;
674 pg->last_rate_code = 0x20;
675 pg->modulation_class = MOD_CLASS_HT;
676 pg->power_step = 0;
677 pg->power_min = (s8) dbm;
678 pg->power_max = (s8) dbm;
679 pg->ht_bandwidth = HT_BW_20;
680 pg++;
681 /* Power group for modulation class HTBW40 */
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_40;
689 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700690 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
691 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700692
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700693 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700694 return ret;
695}
696
697/*
698 * IOCTL request handler to get power save mode.
699 *
700 * This function prepares the correct firmware command and
701 * issues it.
702 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700703int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700704{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700705 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700706 struct mwifiex_adapter *adapter = priv->adapter;
707 u16 sub_cmd;
708
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700709 if (*ps_mode)
710 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
711 else
712 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
713 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
714 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
715 sub_cmd, BITMAP_STA_PS, NULL);
716 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
717 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700718 HostCmd_CMD_802_11_PS_MODE_ENH,
719 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700720
721 return ret;
722}
723
724/*
725 * IOCTL request handler to set/reset WPA IE.
726 *
727 * The supplied WPA IE is treated as a opaque buffer. Only the first field
728 * is checked to determine WPA version. If buffer length is zero, the existing
729 * WPA IE is reset.
730 */
731static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
732 u8 *ie_data_ptr, u16 ie_len)
733{
734 if (ie_len) {
735 if (ie_len > sizeof(priv->wpa_ie)) {
736 dev_err(priv->adapter->dev,
737 "failed to copy WPA IE, too big\n");
738 return -1;
739 }
740 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
741 priv->wpa_ie_len = (u8) ie_len;
742 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700743 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700744
Arend van Spriel04b23122012-10-12 12:28:14 +0200745 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700746 priv->sec_info.wpa_enabled = true;
747 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
748 priv->sec_info.wpa2_enabled = true;
749 } else {
750 priv->sec_info.wpa_enabled = false;
751 priv->sec_info.wpa2_enabled = false;
752 }
753 } else {
754 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
755 priv->wpa_ie_len = 0;
756 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
757 priv->wpa_ie_len, priv->wpa_ie[0]);
758 priv->sec_info.wpa_enabled = false;
759 priv->sec_info.wpa2_enabled = false;
760 }
761
762 return 0;
763}
764
765/*
766 * IOCTL request handler to set/reset WAPI IE.
767 *
768 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
769 * is checked to internally enable WAPI. If buffer length is zero, the existing
770 * WAPI IE is reset.
771 */
772static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
773 u8 *ie_data_ptr, u16 ie_len)
774{
775 if (ie_len) {
776 if (ie_len > sizeof(priv->wapi_ie)) {
777 dev_dbg(priv->adapter->dev,
778 "info: failed to copy WAPI IE, too big\n");
779 return -1;
780 }
781 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
782 priv->wapi_ie_len = ie_len;
783 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700784 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700785
786 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
787 priv->sec_info.wapi_enabled = true;
788 } else {
789 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
790 priv->wapi_ie_len = ie_len;
791 dev_dbg(priv->adapter->dev,
792 "info: Reset wapi_ie_len=%d IE=%#x\n",
793 priv->wapi_ie_len, priv->wapi_ie[0]);
794 priv->sec_info.wapi_enabled = false;
795 }
796 return 0;
797}
798
799/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700800 * IOCTL request handler to set/reset WPS IE.
801 *
802 * The supplied WPS IE is treated as a opaque buffer. Only the first field
803 * is checked to internally enable WPS. If buffer length is zero, the existing
804 * WPS IE is reset.
805 */
806static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
807 u8 *ie_data_ptr, u16 ie_len)
808{
809 if (ie_len) {
810 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
811 if (!priv->wps_ie)
812 return -ENOMEM;
813 if (ie_len > sizeof(priv->wps_ie)) {
814 dev_dbg(priv->adapter->dev,
815 "info: failed to copy WPS IE, too big\n");
816 kfree(priv->wps_ie);
817 return -1;
818 }
819 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
820 priv->wps_ie_len = ie_len;
821 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
822 priv->wps_ie_len, priv->wps_ie[0]);
823 } else {
824 kfree(priv->wps_ie);
825 priv->wps_ie_len = ie_len;
826 dev_dbg(priv->adapter->dev,
827 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
828 }
829 return 0;
830}
831
832/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700833 * IOCTL request handler to set WAPI key.
834 *
835 * This function prepares the correct firmware command and
836 * issues it.
837 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700838static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700839 struct mwifiex_ds_encrypt_key *encrypt_key)
840{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700841
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700842 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700843 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
844 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700845}
846
847/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848 * IOCTL request handler to set WEP network key.
849 *
850 * This function prepares the correct firmware command and
851 * issues it, after validation checks.
852 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700853static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700854 struct mwifiex_ds_encrypt_key *encrypt_key)
855{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700856 int ret;
857 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700858 int index;
859
860 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
861 priv->wep_key_curr_index = 0;
862 wep_key = &priv->wep_key[priv->wep_key_curr_index];
863 index = encrypt_key->key_index;
864 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800865 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700866 } else if (!encrypt_key->key_len) {
867 /* Copy the required key as the current key */
868 wep_key = &priv->wep_key[index];
869 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700870 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871 "key not set, so cannot enable it\n");
872 return -1;
873 }
874 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800875 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700876 } else {
877 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
879 /* Copy the key in the driver */
880 memcpy(wep_key->key_material,
881 encrypt_key->key_material,
882 encrypt_key->key_len);
883 wep_key->key_index = index;
884 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800885 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700886 }
887 if (wep_key->key_length) {
888 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700889 ret = mwifiex_send_cmd_async(priv,
890 HostCmd_CMD_802_11_KEY_MATERIAL,
891 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700892 if (ret)
893 return ret;
894 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800895 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700896 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
897 else
898 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
899
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700900 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
901 HostCmd_ACT_GEN_SET, 0,
902 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700903
904 return ret;
905}
906
907/*
908 * IOCTL request handler to set WPA key.
909 *
910 * This function prepares the correct firmware command and
911 * issues it, after validation checks.
912 *
913 * Current driver only supports key length of up to 32 bytes.
914 *
915 * This function can also be used to disable a currently set key.
916 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700917static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700918 struct mwifiex_ds_encrypt_key *encrypt_key)
919{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700920 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700921 u8 remove_key = false;
922 struct host_cmd_ds_802_11_key_material *ibss_key;
923
924 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700925 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700926 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700927 return -1;
928 }
929
Bing Zhaoeecd8252011-03-28 17:55:41 -0700930 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700931 /*
932 * IBSS/WPA-None uses only one key (Group) for both receiving
933 * and sending unicast and multicast packets.
934 */
935 /* Send the key as PTK to firmware */
936 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700937 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700938 HostCmd_CMD_802_11_KEY_MATERIAL,
939 HostCmd_ACT_GEN_SET,
940 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700941 if (ret)
942 return ret;
943
944 ibss_key = &priv->aes_key;
945 memset(ibss_key, 0,
946 sizeof(struct host_cmd_ds_802_11_key_material));
947 /* Copy the key in the driver */
948 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
949 encrypt_key->key_len);
950 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
951 sizeof(ibss_key->key_param_set.key_len));
952 ibss_key->key_param_set.key_type_id
953 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700954 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700955
956 /* Send the key as GTK to firmware */
957 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
958 }
959
960 if (!encrypt_key->key_index)
961 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
962
963 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700964 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700965 HostCmd_CMD_802_11_KEY_MATERIAL,
966 HostCmd_ACT_GEN_SET,
967 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700968 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700969 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700970 HostCmd_CMD_802_11_KEY_MATERIAL,
971 HostCmd_ACT_GEN_SET,
972 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700973
974 return ret;
975}
976
977/*
978 * IOCTL request handler to set/get network keys.
979 *
980 * This is a generic key handling function which supports WEP, WPA
981 * and WAPI.
982 */
983static int
984mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700985 struct mwifiex_ds_encrypt_key *encrypt_key)
986{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700987 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700988
989 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700990 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700991 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700992 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700994 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700995 return status;
996}
997
998/*
999 * This function returns the driver version.
1000 */
1001int
1002mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1003 int max_len)
1004{
1005 union {
1006 u32 l;
1007 u8 c[4];
1008 } ver;
1009 char fw_ver[32];
1010
1011 ver.l = adapter->fw_release_number;
1012 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1013
1014 snprintf(version, max_len, driver_version, fw_ver);
1015
1016 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1017
1018 return 0;
1019}
1020
1021/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022 * Sends IOCTL request to set encoding parameters.
1023 *
1024 * This function allocates the IOCTL request buffer, fills it
1025 * with requisite parameters and calls the IOCTL handler.
1026 */
Ying Luo53b11232012-08-03 18:06:13 -07001027int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1028 const u8 *key, int key_len, u8 key_index,
1029 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001030{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001031 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001032
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001033 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1034 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001035
1036 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1037 encrypt_key.is_igtk_key = true;
1038
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039 if (!disable) {
1040 encrypt_key.key_index = key_index;
1041 if (key_len)
1042 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001043 if (mac_addr)
1044 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001045 if (kp && kp->seq && kp->seq_len)
1046 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001047 } else {
1048 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001049 if (mac_addr)
1050 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001051 }
1052
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001053 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054}
1055
1056/*
1057 * Sends IOCTL request to get extended version.
1058 *
1059 * This function allocates the IOCTL request buffer, fills it
1060 * with requisite parameters and calls the IOCTL handler.
1061 */
1062int
1063mwifiex_get_ver_ext(struct mwifiex_private *priv)
1064{
1065 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001066
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001067 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001068 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001069 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001070 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001071
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001072 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001073}
1074
Stone Piao7feb4c42012-09-25 20:23:36 -07001075int
1076mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1077 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001078 unsigned int duration)
1079{
1080 struct host_cmd_ds_remain_on_chan roc_cfg;
1081 u8 sc;
1082
1083 memset(&roc_cfg, 0, sizeof(roc_cfg));
1084 roc_cfg.action = cpu_to_le16(action);
1085 if (action == HostCmd_ACT_GEN_SET) {
1086 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001087 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001088 roc_cfg.band_cfg |= (sc << 2);
1089
1090 roc_cfg.channel =
1091 ieee80211_frequency_to_channel(chan->center_freq);
1092 roc_cfg.duration = cpu_to_le32(duration);
1093 }
1094 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1095 action, 0, &roc_cfg)) {
1096 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1097 return -1;
1098 }
1099
1100 return roc_cfg.status;
1101}
1102
Stone Piao9197ab92012-09-25 20:23:42 -07001103int
1104mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1105{
1106 if (GET_BSS_ROLE(priv) == bss_role) {
1107 dev_dbg(priv->adapter->dev,
1108 "info: already in the desired role.\n");
1109 return 0;
1110 }
1111
1112 mwifiex_free_priv(priv);
1113 mwifiex_init_priv(priv);
1114
1115 priv->bss_role = bss_role;
1116 switch (bss_role) {
1117 case MWIFIEX_BSS_ROLE_UAP:
1118 priv->bss_mode = NL80211_IFTYPE_AP;
1119 break;
1120 case MWIFIEX_BSS_ROLE_STA:
1121 case MWIFIEX_BSS_ROLE_ANY:
1122 default:
1123 priv->bss_mode = NL80211_IFTYPE_STATION;
1124 break;
1125 }
1126
1127 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1128 HostCmd_ACT_GEN_SET, 0, NULL);
1129
1130 return mwifiex_sta_init_cmd(priv, false);
1131}
1132
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001133/*
1134 * Sends IOCTL request to get statistics information.
1135 *
1136 * This function allocates the IOCTL request buffer, fills it
1137 * with requisite parameters and calls the IOCTL handler.
1138 */
1139int
1140mwifiex_get_stats_info(struct mwifiex_private *priv,
1141 struct mwifiex_ds_get_stats *log)
1142{
Bing Zhao67a50032011-07-13 18:38:34 -07001143 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001144 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001145}
1146
1147/*
1148 * IOCTL request handler to read/write register.
1149 *
1150 * This function prepares the correct firmware command and
1151 * issues it.
1152 *
1153 * Access to the following registers are supported -
1154 * - MAC
1155 * - BBP
1156 * - RF
1157 * - PMIC
1158 * - CAU
1159 */
1160static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161 struct mwifiex_ds_reg_rw *reg_rw,
1162 u16 action)
1163{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001164 u16 cmd_no;
1165
1166 switch (le32_to_cpu(reg_rw->type)) {
1167 case MWIFIEX_REG_MAC:
1168 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1169 break;
1170 case MWIFIEX_REG_BBP:
1171 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1172 break;
1173 case MWIFIEX_REG_RF:
1174 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1175 break;
1176 case MWIFIEX_REG_PMIC:
1177 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1178 break;
1179 case MWIFIEX_REG_CAU:
1180 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1181 break;
1182 default:
1183 return -1;
1184 }
1185
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001186 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001188}
1189
1190/*
1191 * Sends IOCTL request to write to a register.
1192 *
1193 * This function allocates the IOCTL request buffer, fills it
1194 * with requisite parameters and calls the IOCTL handler.
1195 */
1196int
1197mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1198 u32 reg_offset, u32 reg_value)
1199{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001200 struct mwifiex_ds_reg_rw reg_rw;
1201
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 reg_rw.type = cpu_to_le32(reg_type);
1203 reg_rw.offset = cpu_to_le32(reg_offset);
1204 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001205
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001206 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207}
1208
1209/*
1210 * Sends IOCTL request to read from a register.
1211 *
1212 * This function allocates the IOCTL request buffer, fills it
1213 * with requisite parameters and calls the IOCTL handler.
1214 */
1215int
1216mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1217 u32 reg_offset, u32 *value)
1218{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001219 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001220 struct mwifiex_ds_reg_rw reg_rw;
1221
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001222 reg_rw.type = cpu_to_le32(reg_type);
1223 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001224 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001225
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001226 if (ret)
1227 goto done;
1228
1229 *value = le32_to_cpu(reg_rw.value);
1230
1231done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232 return ret;
1233}
1234
1235/*
1236 * Sends IOCTL request to read from EEPROM.
1237 *
1238 * This function allocates the IOCTL request buffer, fills it
1239 * with requisite parameters and calls the IOCTL handler.
1240 */
1241int
1242mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1243 u8 *value)
1244{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001245 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001246 struct mwifiex_ds_read_eeprom rd_eeprom;
1247
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001248 rd_eeprom.offset = cpu_to_le16((u16) offset);
1249 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001250
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001251 /* Send request to firmware */
1252 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1253 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001254
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001255 if (!ret)
1256 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 return ret;
1258}
1259
1260/*
1261 * This function sets a generic IE. In addition to generic IE, it can
1262 * also handle WPA, WPA2 and WAPI IEs.
1263 */
1264static int
1265mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1266 u16 ie_len)
1267{
1268 int ret = 0;
1269 struct ieee_types_vendor_header *pvendor_ie;
1270 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1271 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1272
1273 /* If the passed length is zero, reset the buffer */
1274 if (!ie_len) {
1275 priv->gen_ie_buf_len = 0;
1276 priv->wps.session_enable = false;
1277
1278 return 0;
1279 } else if (!ie_data_ptr) {
1280 return -1;
1281 }
1282 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1283 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
Arend van Spriel04b23122012-10-12 12:28:14 +02001284 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001285 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1286 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001287
1288 /* IE is a WPA/WPA2 IE so call set_wpa function */
1289 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1290 priv->wps.session_enable = false;
1291
1292 return ret;
1293 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1294 /* IE is a WAPI IE so call set_wapi function */
1295 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1296
1297 return ret;
1298 }
1299 /*
1300 * Verify that the passed length is not larger than the
1301 * available space remaining in the buffer
1302 */
1303 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1304
1305 /* Test to see if it is a WPS IE, if so, enable
1306 * wps session flag
1307 */
1308 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001309 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1310 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001311 priv->wps.session_enable = true;
1312 dev_dbg(priv->adapter->dev,
1313 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001314 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001315 }
1316
1317 /* Append the passed data to the end of the
1318 genIeBuffer */
1319 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001320 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001321 /* Increment the stored buffer length by the
1322 size passed */
1323 priv->gen_ie_buf_len += ie_len;
1324 } else {
1325 /* Passed data does not fit in the remaining
1326 buffer space */
1327 ret = -1;
1328 }
1329
1330 /* Return 0, or -1 for error case */
1331 return ret;
1332}
1333
1334/*
1335 * IOCTL request handler to set/get generic IE.
1336 *
1337 * In addition to various generic IEs, this function can also be
1338 * used to set the ARP filter.
1339 */
1340static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1341 struct mwifiex_ds_misc_gen_ie *gen_ie,
1342 u16 action)
1343{
1344 struct mwifiex_adapter *adapter = priv->adapter;
1345
1346 switch (gen_ie->type) {
1347 case MWIFIEX_IE_TYPE_GEN_IE:
1348 if (action == HostCmd_ACT_GEN_GET) {
1349 gen_ie->len = priv->wpa_ie_len;
1350 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1351 } else {
1352 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1353 (u16) gen_ie->len);
1354 }
1355 break;
1356 case MWIFIEX_IE_TYPE_ARP_FILTER:
1357 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1358 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1359 adapter->arp_filter_size = 0;
1360 dev_err(adapter->dev, "invalid ARP filter size\n");
1361 return -1;
1362 } else {
1363 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001364 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001365 adapter->arp_filter_size = gen_ie->len;
1366 }
1367 break;
1368 default:
1369 dev_err(adapter->dev, "invalid IE type\n");
1370 return -1;
1371 }
1372 return 0;
1373}
1374
1375/*
1376 * Sends IOCTL request to set a generic IE.
1377 *
1378 * This function allocates the IOCTL request buffer, fills it
1379 * with requisite parameters and calls the IOCTL handler.
1380 */
1381int
1382mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1383{
1384 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001385
Bing Zhao67a50032011-07-13 18:38:34 -07001386 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001387 return -EFAULT;
1388
1389 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1390 gen_ie.len = ie_len;
1391 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001392 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001393 return -EFAULT;
1394
1395 return 0;
1396}