blob: 7ce72e93260d5f2581df29d8a717e79a13e07e6e [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);
Johannes Berg9caf0362012-11-29 01:25:20 +0100165 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
166 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100167 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100168 rcu_read_unlock();
169
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700170 if (!beacon_ie) {
171 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
172 return -ENOMEM;
173 }
174
175 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
176 bss_desc->rssi = bss->signal;
177 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100178 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700179 bss_desc->beacon_period = bss->beacon_interval;
180 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700181 bss_desc->bss_band = bss_priv->band;
182 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700183 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
184 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
185 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
186 } else {
187 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
188 }
189 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
190 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
191 else
192 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
193
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700194 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700195
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700196 kfree(beacon_ie);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700197 return ret;
198}
199
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700200static int mwifiex_process_country_ie(struct mwifiex_private *priv,
201 struct cfg80211_bss *bss)
202{
Johannes Berg9caf0362012-11-29 01:25:20 +0100203 const u8 *country_ie;
204 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700205 struct mwifiex_802_11d_domain_reg *domain_info =
206 &priv->adapter->domain_reg;
207
Johannes Berg9caf0362012-11-29 01:25:20 +0100208 rcu_read_lock();
209 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
210 if (!country_ie) {
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 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100216 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
217 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700218 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100219 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700220
221 domain_info->country_code[0] = country_ie[2];
222 domain_info->country_code[1] = country_ie[3];
223 domain_info->country_code[2] = ' ';
224
225 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
226
227 domain_info->no_of_triplet =
228 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
229
230 memcpy((u8 *)domain_info->triplet,
231 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
232
Johannes Berg9caf0362012-11-29 01:25:20 +0100233 rcu_read_unlock();
234
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700235 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
236 HostCmd_ACT_GEN_SET, 0, NULL)) {
237 wiphy_err(priv->adapter->wiphy,
238 "11D: setting domain info in FW\n");
239 return -1;
240 }
241
242 return 0;
243}
244
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700245/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700246 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
247 * In both Ad-Hoc and infra mode, an deauthentication is performed
248 * first.
249 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700250int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800251 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700252{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700253 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700254 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700255 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700256
257 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700258
259 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700260 mwifiex_process_country_ie(priv, bss);
261
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700262 /* Allocate and fill new bss descriptor */
263 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
264 GFP_KERNEL);
265 if (!bss_desc) {
266 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
267 return -ENOMEM;
268 }
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700269
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700270 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700271 if (ret)
272 goto done;
273 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274
Bing Zhaoeecd8252011-03-28 17:55:41 -0700275 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700277 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700278 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700279 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800281 if (bss_desc) {
282 u8 config_bands = 0;
283
284 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
285 == HostCmd_SCAN_RADIO_TYPE_BG)
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800286 config_bands = BAND_B | BAND_G | BAND_GN |
287 BAND_GAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800288 else
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800289 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800290
291 if (!((config_bands | adapter->fw_bands) &
292 ~adapter->fw_bands))
293 adapter->config_bands = config_bands;
294 }
295
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700296 ret = mwifiex_check_network_compatibility(priv, bss_desc);
297 if (ret)
298 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700299
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700300 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
301 "associating...\n");
302
Avinash Patil47411a02012-11-01 18:44:16 -0700303 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800304 if (netif_carrier_ok(priv->netdev))
305 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700306
307 /* Clear any past association response stored for
308 * application retrieval */
309 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700310 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800311
312 /* If auth type is auto and association fails using open mode,
313 * try to connect using shared mode */
314 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
315 priv->sec_info.is_authtype_auto &&
316 priv->sec_info.wep_enabled) {
317 priv->sec_info.authentication_mode =
318 NL80211_AUTHTYPE_SHARED_KEY;
319 ret = mwifiex_associate(priv, bss_desc);
320 }
321
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700322 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100323 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700324 } else {
325 /* Adhoc mode */
326 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700327 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700328 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
329 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700330 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700332 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700333
334 /* Exit Adhoc mode first */
335 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700336 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700338 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700339
340 priv->adhoc_is_link_sensed = false;
341
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700342 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700343
Avinash Patil47411a02012-11-01 18:44:16 -0700344 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800345 if (netif_carrier_ok(priv->netdev))
346 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700347
348 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700349 dev_dbg(adapter->dev, "info: network found in scan"
350 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700351 ret = mwifiex_adhoc_join(priv, bss_desc);
352 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100353 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700354 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355 dev_dbg(adapter->dev, "info: Network not found in "
356 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700357 req_ssid->ssid);
358 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700359 }
360 }
361
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700362done:
363 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700364 return ret;
365}
366
367/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368 * IOCTL request handler to set host sleep configuration.
369 *
370 * This function prepares the correct firmware command and
371 * issues it.
372 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700373static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
374 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700375
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376{
377 struct mwifiex_adapter *adapter = priv->adapter;
378 int status = 0;
379 u32 prev_cond = 0;
380
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700381 if (!hs_cfg)
382 return -ENOMEM;
383
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700384 switch (action) {
385 case HostCmd_ACT_GEN_SET:
386 if (adapter->pps_uapsd_mode) {
387 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
388 " is blocked in UAPSD/PPS mode\n");
389 status = -1;
390 break;
391 }
392 if (hs_cfg->is_invoke_hostcmd) {
393 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
394 if (!adapter->is_hs_configured)
395 /* Already cancelled */
396 break;
397 /* Save previous condition */
398 prev_cond = le32_to_cpu(adapter->hs_cfg
399 .conditions);
400 adapter->hs_cfg.conditions =
401 cpu_to_le32(hs_cfg->conditions);
402 } else if (hs_cfg->conditions) {
403 adapter->hs_cfg.conditions =
404 cpu_to_le32(hs_cfg->conditions);
405 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
406 if (hs_cfg->gap)
407 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700408 } else if (adapter->hs_cfg.conditions
409 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700410 /* Return failure if no parameters for HS
411 enable */
412 status = -1;
413 break;
414 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700415 if (cmd_type == MWIFIEX_SYNC_CMD)
416 status = mwifiex_send_cmd_sync(priv,
417 HostCmd_CMD_802_11_HS_CFG_ENH,
418 HostCmd_ACT_GEN_SET, 0,
419 &adapter->hs_cfg);
420 else
421 status = mwifiex_send_cmd_async(priv,
422 HostCmd_CMD_802_11_HS_CFG_ENH,
423 HostCmd_ACT_GEN_SET, 0,
424 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700425 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
426 /* Restore previous condition */
427 adapter->hs_cfg.conditions =
428 cpu_to_le32(prev_cond);
429 } else {
430 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700431 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700432 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
433 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
434 }
435 break;
436 case HostCmd_ACT_GEN_GET:
437 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
438 hs_cfg->gpio = adapter->hs_cfg.gpio;
439 hs_cfg->gap = adapter->hs_cfg.gap;
440 break;
441 default:
442 status = -1;
443 break;
444 }
445
446 return status;
447}
448
449/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700450 * Sends IOCTL request to cancel the existing Host Sleep configuration.
451 *
452 * This function allocates the IOCTL request buffer, fills it
453 * with requisite parameters and calls the IOCTL handler.
454 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700455int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700456{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700457 struct mwifiex_ds_hs_cfg hscfg;
458
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700459 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
460 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700461
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700462 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
463 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700464}
465EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
466
467/*
468 * Sends IOCTL request to cancel the existing Host Sleep configuration.
469 *
470 * This function allocates the IOCTL request buffer, fills it
471 * with requisite parameters and calls the IOCTL handler.
472 */
473int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
474{
475 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700476 struct mwifiex_private *priv;
477 int i;
478
479 if (disconnect_on_suspend) {
480 for (i = 0; i < adapter->priv_num; i++) {
481 priv = adapter->priv[i];
482 if (priv)
483 mwifiex_deauthenticate(priv, NULL);
484 }
485 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700486
487 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900488 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700489 return true;
490 }
491
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700492 adapter->hs_activate_wait_q_woken = false;
493
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700494 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700495 hscfg.is_invoke_hostcmd = true;
496
497 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700498 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700499 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
500 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700501 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
502 return false;
503 }
504
Bing Zhao9c969d82013-01-02 16:07:35 -0800505 if (wait_event_interruptible(adapter->hs_activate_wait_q,
506 adapter->hs_activate_wait_q_woken)) {
507 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
508 return false;
509 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510
511 return true;
512}
513EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
514
515/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700516 * IOCTL request handler to get BSS information.
517 *
518 * This function collates the information from different driver structures
519 * to send to the user.
520 */
521int mwifiex_get_bss_info(struct mwifiex_private *priv,
522 struct mwifiex_bss_info *info)
523{
524 struct mwifiex_adapter *adapter = priv->adapter;
525 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700526
527 if (!info)
528 return -1;
529
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700530 bss_desc = &priv->curr_bss_params.bss_descriptor;
531
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700532 info->bss_mode = priv->bss_mode;
533
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800534 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700536 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
537
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700538 info->bss_chan = bss_desc->channel;
539
Avinash Patil67fdf392012-05-08 18:30:17 -0700540 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700541 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700542
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543 info->media_connected = priv->media_connected;
544
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700545 info->max_power_level = priv->max_tx_power_level;
546 info->min_power_level = priv->min_tx_power_level;
547
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 info->adhoc_state = priv->adhoc_state;
549
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700550 info->bcn_nf_last = priv->bcn_nf_last;
551
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800552 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553 info->wep_status = true;
554 else
555 info->wep_status = false;
556
557 info->is_hs_configured = adapter->is_hs_configured;
558 info->is_deep_sleep = adapter->is_deep_sleep;
559
560 return 0;
561}
562
563/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700564 * The function disables auto deep sleep mode.
565 */
566int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
567{
568 struct mwifiex_ds_auto_ds auto_ds;
569
570 auto_ds.auto_ds = DEEP_SLEEP_OFF;
571
572 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
573 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
574}
575EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
576
577/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700578 * Sends IOCTL request to get the data rate.
579 *
580 * This function allocates the IOCTL request buffer, fills it
581 * with requisite parameters and calls the IOCTL handler.
582 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700583int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700584{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700585 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700586
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700587 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
588 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700589
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700591 if (priv->is_data_rate_auto)
592 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
593 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300594 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700595 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 }
597
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700598 return ret;
599}
600
601/*
602 * IOCTL request handler to set tx power configuration.
603 *
604 * This function prepares the correct firmware command and
605 * issues it.
606 *
607 * For non-auto power mode, all the following power groups are set -
608 * - Modulation class HR/DSSS
609 * - Modulation class OFDM
610 * - Modulation class HTBW20
611 * - Modulation class HTBW40
612 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700613int mwifiex_set_tx_power(struct mwifiex_private *priv,
614 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700615{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700616 int ret;
617 struct host_cmd_ds_txpwr_cfg *txp_cfg;
618 struct mwifiex_types_power_group *pg_tlv;
619 struct mwifiex_power_group *pg;
620 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621 u16 dbm = 0;
622
623 if (!power_cfg->is_power_auto) {
624 dbm = (u16) power_cfg->power_level;
625 if ((dbm < priv->min_tx_power_level) ||
626 (dbm > priv->max_tx_power_level)) {
627 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700628 " is out of range (%d dBm-%d dBm)\n",
629 dbm, priv->min_tx_power_level,
630 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700631 return -1;
632 }
633 }
634 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
635 if (!buf) {
636 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700637 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200638 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700639 }
640
641 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
642 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
643 if (!power_cfg->is_power_auto) {
644 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700645 pg_tlv = (struct mwifiex_types_power_group *)
646 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700647 pg_tlv->type = TLV_TYPE_POWER_GROUP;
648 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700649 pg = (struct mwifiex_power_group *)
650 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
651 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700652 /* Power group for modulation class HR/DSSS */
653 pg->first_rate_code = 0x00;
654 pg->last_rate_code = 0x03;
655 pg->modulation_class = MOD_CLASS_HR_DSSS;
656 pg->power_step = 0;
657 pg->power_min = (s8) dbm;
658 pg->power_max = (s8) dbm;
659 pg++;
660 /* Power group for modulation class OFDM */
661 pg->first_rate_code = 0x00;
662 pg->last_rate_code = 0x07;
663 pg->modulation_class = MOD_CLASS_OFDM;
664 pg->power_step = 0;
665 pg->power_min = (s8) dbm;
666 pg->power_max = (s8) dbm;
667 pg++;
668 /* Power group for modulation class HTBW20 */
669 pg->first_rate_code = 0x00;
670 pg->last_rate_code = 0x20;
671 pg->modulation_class = MOD_CLASS_HT;
672 pg->power_step = 0;
673 pg->power_min = (s8) dbm;
674 pg->power_max = (s8) dbm;
675 pg->ht_bandwidth = HT_BW_20;
676 pg++;
677 /* Power group for modulation class HTBW40 */
678 pg->first_rate_code = 0x00;
679 pg->last_rate_code = 0x20;
680 pg->modulation_class = MOD_CLASS_HT;
681 pg->power_step = 0;
682 pg->power_min = (s8) dbm;
683 pg->power_max = (s8) dbm;
684 pg->ht_bandwidth = HT_BW_40;
685 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700686 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
687 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700688
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700689 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700690 return ret;
691}
692
693/*
694 * IOCTL request handler to get power save mode.
695 *
696 * This function prepares the correct firmware command and
697 * issues it.
698 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700699int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700700{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700701 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700702 struct mwifiex_adapter *adapter = priv->adapter;
703 u16 sub_cmd;
704
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700705 if (*ps_mode)
706 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
707 else
708 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
709 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
710 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
711 sub_cmd, BITMAP_STA_PS, NULL);
712 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
713 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700714 HostCmd_CMD_802_11_PS_MODE_ENH,
715 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700716
717 return ret;
718}
719
720/*
721 * IOCTL request handler to set/reset WPA IE.
722 *
723 * The supplied WPA IE is treated as a opaque buffer. Only the first field
724 * is checked to determine WPA version. If buffer length is zero, the existing
725 * WPA IE is reset.
726 */
727static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
728 u8 *ie_data_ptr, u16 ie_len)
729{
730 if (ie_len) {
731 if (ie_len > sizeof(priv->wpa_ie)) {
732 dev_err(priv->adapter->dev,
733 "failed to copy WPA IE, too big\n");
734 return -1;
735 }
736 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
737 priv->wpa_ie_len = (u8) ie_len;
738 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700739 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700740
Arend van Spriel04b23122012-10-12 12:28:14 +0200741 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700742 priv->sec_info.wpa_enabled = true;
743 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
744 priv->sec_info.wpa2_enabled = true;
745 } else {
746 priv->sec_info.wpa_enabled = false;
747 priv->sec_info.wpa2_enabled = false;
748 }
749 } else {
750 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
751 priv->wpa_ie_len = 0;
752 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
753 priv->wpa_ie_len, priv->wpa_ie[0]);
754 priv->sec_info.wpa_enabled = false;
755 priv->sec_info.wpa2_enabled = false;
756 }
757
758 return 0;
759}
760
761/*
762 * IOCTL request handler to set/reset WAPI IE.
763 *
764 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
765 * is checked to internally enable WAPI. If buffer length is zero, the existing
766 * WAPI IE is reset.
767 */
768static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
769 u8 *ie_data_ptr, u16 ie_len)
770{
771 if (ie_len) {
772 if (ie_len > sizeof(priv->wapi_ie)) {
773 dev_dbg(priv->adapter->dev,
774 "info: failed to copy WAPI IE, too big\n");
775 return -1;
776 }
777 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
778 priv->wapi_ie_len = ie_len;
779 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700780 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700781
782 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
783 priv->sec_info.wapi_enabled = true;
784 } else {
785 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
786 priv->wapi_ie_len = ie_len;
787 dev_dbg(priv->adapter->dev,
788 "info: Reset wapi_ie_len=%d IE=%#x\n",
789 priv->wapi_ie_len, priv->wapi_ie[0]);
790 priv->sec_info.wapi_enabled = false;
791 }
792 return 0;
793}
794
795/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700796 * IOCTL request handler to set/reset WPS IE.
797 *
798 * The supplied WPS IE is treated as a opaque buffer. Only the first field
799 * is checked to internally enable WPS. If buffer length is zero, the existing
800 * WPS IE is reset.
801 */
802static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
803 u8 *ie_data_ptr, u16 ie_len)
804{
805 if (ie_len) {
806 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
807 if (!priv->wps_ie)
808 return -ENOMEM;
809 if (ie_len > sizeof(priv->wps_ie)) {
810 dev_dbg(priv->adapter->dev,
811 "info: failed to copy WPS IE, too big\n");
812 kfree(priv->wps_ie);
813 return -1;
814 }
815 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
816 priv->wps_ie_len = ie_len;
817 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
818 priv->wps_ie_len, priv->wps_ie[0]);
819 } else {
820 kfree(priv->wps_ie);
821 priv->wps_ie_len = ie_len;
822 dev_dbg(priv->adapter->dev,
823 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
824 }
825 return 0;
826}
827
828/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700829 * IOCTL request handler to set WAPI key.
830 *
831 * This function prepares the correct firmware command and
832 * issues it.
833 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700834static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700835 struct mwifiex_ds_encrypt_key *encrypt_key)
836{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700837
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700838 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700839 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
840 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700841}
842
843/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700844 * IOCTL request handler to set WEP network key.
845 *
846 * This function prepares the correct firmware command and
847 * issues it, after validation checks.
848 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700849static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700850 struct mwifiex_ds_encrypt_key *encrypt_key)
851{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700852 int ret;
853 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700854 int index;
855
856 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
857 priv->wep_key_curr_index = 0;
858 wep_key = &priv->wep_key[priv->wep_key_curr_index];
859 index = encrypt_key->key_index;
860 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800861 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700862 } else if (!encrypt_key->key_len) {
863 /* Copy the required key as the current key */
864 wep_key = &priv->wep_key[index];
865 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700866 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867 "key not set, so cannot enable it\n");
868 return -1;
869 }
870 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800871 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872 } else {
873 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
875 /* Copy the key in the driver */
876 memcpy(wep_key->key_material,
877 encrypt_key->key_material,
878 encrypt_key->key_len);
879 wep_key->key_index = index;
880 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800881 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700882 }
883 if (wep_key->key_length) {
884 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700885 ret = mwifiex_send_cmd_async(priv,
886 HostCmd_CMD_802_11_KEY_MATERIAL,
887 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700888 if (ret)
889 return ret;
890 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800891 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700892 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
893 else
894 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
895
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700896 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
897 HostCmd_ACT_GEN_SET, 0,
898 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700899
900 return ret;
901}
902
903/*
904 * IOCTL request handler to set WPA key.
905 *
906 * This function prepares the correct firmware command and
907 * issues it, after validation checks.
908 *
909 * Current driver only supports key length of up to 32 bytes.
910 *
911 * This function can also be used to disable a currently set key.
912 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700913static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700914 struct mwifiex_ds_encrypt_key *encrypt_key)
915{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700916 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700917 u8 remove_key = false;
918 struct host_cmd_ds_802_11_key_material *ibss_key;
919
920 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700921 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700922 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700923 return -1;
924 }
925
Bing Zhaoeecd8252011-03-28 17:55:41 -0700926 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700927 /*
928 * IBSS/WPA-None uses only one key (Group) for both receiving
929 * and sending unicast and multicast packets.
930 */
931 /* Send the key as PTK to firmware */
932 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700933 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700934 HostCmd_CMD_802_11_KEY_MATERIAL,
935 HostCmd_ACT_GEN_SET,
936 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700937 if (ret)
938 return ret;
939
940 ibss_key = &priv->aes_key;
941 memset(ibss_key, 0,
942 sizeof(struct host_cmd_ds_802_11_key_material));
943 /* Copy the key in the driver */
944 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
945 encrypt_key->key_len);
946 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
947 sizeof(ibss_key->key_param_set.key_len));
948 ibss_key->key_param_set.key_type_id
949 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700950 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700951
952 /* Send the key as GTK to firmware */
953 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
954 }
955
956 if (!encrypt_key->key_index)
957 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
958
959 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700960 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700961 HostCmd_CMD_802_11_KEY_MATERIAL,
962 HostCmd_ACT_GEN_SET,
963 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700964 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700965 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700966 HostCmd_CMD_802_11_KEY_MATERIAL,
967 HostCmd_ACT_GEN_SET,
968 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700969
970 return ret;
971}
972
973/*
974 * IOCTL request handler to set/get network keys.
975 *
976 * This is a generic key handling function which supports WEP, WPA
977 * and WAPI.
978 */
979static int
980mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700981 struct mwifiex_ds_encrypt_key *encrypt_key)
982{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700983 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700984
985 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700986 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700987 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700988 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700989 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700990 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700991 return status;
992}
993
994/*
995 * This function returns the driver version.
996 */
997int
998mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
999 int max_len)
1000{
1001 union {
1002 u32 l;
1003 u8 c[4];
1004 } ver;
1005 char fw_ver[32];
1006
1007 ver.l = adapter->fw_release_number;
1008 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1009
1010 snprintf(version, max_len, driver_version, fw_ver);
1011
1012 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1013
1014 return 0;
1015}
1016
1017/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001018 * Sends IOCTL request to set encoding parameters.
1019 *
1020 * This function allocates the IOCTL request buffer, fills it
1021 * with requisite parameters and calls the IOCTL handler.
1022 */
Ying Luo53b11232012-08-03 18:06:13 -07001023int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1024 const u8 *key, int key_len, u8 key_index,
1025 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001026{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001027 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001028
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001029 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1030 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001031
1032 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1033 encrypt_key.is_igtk_key = true;
1034
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035 if (!disable) {
1036 encrypt_key.key_index = key_index;
1037 if (key_len)
1038 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001039 if (mac_addr)
1040 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001041 if (kp && kp->seq && kp->seq_len)
1042 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001043 } else {
1044 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001045 if (mac_addr)
1046 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001047 }
1048
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001049 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001050}
1051
1052/*
1053 * Sends IOCTL request to get extended version.
1054 *
1055 * This function allocates the IOCTL request buffer, fills it
1056 * with requisite parameters and calls the IOCTL handler.
1057 */
1058int
1059mwifiex_get_ver_ext(struct mwifiex_private *priv)
1060{
1061 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001062
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001063 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001064 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001065 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001066 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001067
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001068 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001069}
1070
Stone Piao7feb4c42012-09-25 20:23:36 -07001071int
1072mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1073 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001074 unsigned int duration)
1075{
1076 struct host_cmd_ds_remain_on_chan roc_cfg;
1077 u8 sc;
1078
1079 memset(&roc_cfg, 0, sizeof(roc_cfg));
1080 roc_cfg.action = cpu_to_le16(action);
1081 if (action == HostCmd_ACT_GEN_SET) {
1082 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001083 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001084 roc_cfg.band_cfg |= (sc << 2);
1085
1086 roc_cfg.channel =
1087 ieee80211_frequency_to_channel(chan->center_freq);
1088 roc_cfg.duration = cpu_to_le32(duration);
1089 }
1090 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1091 action, 0, &roc_cfg)) {
1092 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1093 return -1;
1094 }
1095
1096 return roc_cfg.status;
1097}
1098
Stone Piao9197ab92012-09-25 20:23:42 -07001099int
1100mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1101{
1102 if (GET_BSS_ROLE(priv) == bss_role) {
1103 dev_dbg(priv->adapter->dev,
1104 "info: already in the desired role.\n");
1105 return 0;
1106 }
1107
1108 mwifiex_free_priv(priv);
1109 mwifiex_init_priv(priv);
1110
1111 priv->bss_role = bss_role;
1112 switch (bss_role) {
1113 case MWIFIEX_BSS_ROLE_UAP:
1114 priv->bss_mode = NL80211_IFTYPE_AP;
1115 break;
1116 case MWIFIEX_BSS_ROLE_STA:
1117 case MWIFIEX_BSS_ROLE_ANY:
1118 default:
1119 priv->bss_mode = NL80211_IFTYPE_STATION;
1120 break;
1121 }
1122
1123 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1124 HostCmd_ACT_GEN_SET, 0, NULL);
1125
1126 return mwifiex_sta_init_cmd(priv, false);
1127}
1128
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001129/*
1130 * Sends IOCTL request to get statistics information.
1131 *
1132 * This function allocates the IOCTL request buffer, fills it
1133 * with requisite parameters and calls the IOCTL handler.
1134 */
1135int
1136mwifiex_get_stats_info(struct mwifiex_private *priv,
1137 struct mwifiex_ds_get_stats *log)
1138{
Bing Zhao67a50032011-07-13 18:38:34 -07001139 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001140 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001141}
1142
1143/*
1144 * IOCTL request handler to read/write register.
1145 *
1146 * This function prepares the correct firmware command and
1147 * issues it.
1148 *
1149 * Access to the following registers are supported -
1150 * - MAC
1151 * - BBP
1152 * - RF
1153 * - PMIC
1154 * - CAU
1155 */
1156static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001157 struct mwifiex_ds_reg_rw *reg_rw,
1158 u16 action)
1159{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001160 u16 cmd_no;
1161
1162 switch (le32_to_cpu(reg_rw->type)) {
1163 case MWIFIEX_REG_MAC:
1164 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1165 break;
1166 case MWIFIEX_REG_BBP:
1167 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1168 break;
1169 case MWIFIEX_REG_RF:
1170 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1171 break;
1172 case MWIFIEX_REG_PMIC:
1173 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1174 break;
1175 case MWIFIEX_REG_CAU:
1176 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1177 break;
1178 default:
1179 return -1;
1180 }
1181
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001182 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001183
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001184}
1185
1186/*
1187 * Sends IOCTL request to write to a register.
1188 *
1189 * This function allocates the IOCTL request buffer, fills it
1190 * with requisite parameters and calls the IOCTL handler.
1191 */
1192int
1193mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1194 u32 reg_offset, u32 reg_value)
1195{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196 struct mwifiex_ds_reg_rw reg_rw;
1197
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001198 reg_rw.type = cpu_to_le32(reg_type);
1199 reg_rw.offset = cpu_to_le32(reg_offset);
1200 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001201
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001202 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001203}
1204
1205/*
1206 * Sends IOCTL request to read from a register.
1207 *
1208 * This function allocates the IOCTL request buffer, fills it
1209 * with requisite parameters and calls the IOCTL handler.
1210 */
1211int
1212mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1213 u32 reg_offset, u32 *value)
1214{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001215 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001216 struct mwifiex_ds_reg_rw reg_rw;
1217
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001218 reg_rw.type = cpu_to_le32(reg_type);
1219 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001220 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001221
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001222 if (ret)
1223 goto done;
1224
1225 *value = le32_to_cpu(reg_rw.value);
1226
1227done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001228 return ret;
1229}
1230
1231/*
1232 * Sends IOCTL request to read from EEPROM.
1233 *
1234 * This function allocates the IOCTL request buffer, fills it
1235 * with requisite parameters and calls the IOCTL handler.
1236 */
1237int
1238mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1239 u8 *value)
1240{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001241 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001242 struct mwifiex_ds_read_eeprom rd_eeprom;
1243
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001244 rd_eeprom.offset = cpu_to_le16((u16) offset);
1245 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001246
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001247 /* Send request to firmware */
1248 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1249 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001250
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001251 if (!ret)
1252 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001253 return ret;
1254}
1255
1256/*
1257 * This function sets a generic IE. In addition to generic IE, it can
1258 * also handle WPA, WPA2 and WAPI IEs.
1259 */
1260static int
1261mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1262 u16 ie_len)
1263{
1264 int ret = 0;
1265 struct ieee_types_vendor_header *pvendor_ie;
1266 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1267 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1268
1269 /* If the passed length is zero, reset the buffer */
1270 if (!ie_len) {
1271 priv->gen_ie_buf_len = 0;
1272 priv->wps.session_enable = false;
1273
1274 return 0;
1275 } else if (!ie_data_ptr) {
1276 return -1;
1277 }
1278 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1279 /* 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 +02001280 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001281 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1282 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001283
1284 /* IE is a WPA/WPA2 IE so call set_wpa function */
1285 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1286 priv->wps.session_enable = false;
1287
1288 return ret;
1289 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1290 /* IE is a WAPI IE so call set_wapi function */
1291 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1292
1293 return ret;
1294 }
1295 /*
1296 * Verify that the passed length is not larger than the
1297 * available space remaining in the buffer
1298 */
1299 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1300
1301 /* Test to see if it is a WPS IE, if so, enable
1302 * wps session flag
1303 */
1304 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001305 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1306 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001307 priv->wps.session_enable = true;
1308 dev_dbg(priv->adapter->dev,
1309 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001310 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001311 }
1312
1313 /* Append the passed data to the end of the
1314 genIeBuffer */
1315 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001316 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001317 /* Increment the stored buffer length by the
1318 size passed */
1319 priv->gen_ie_buf_len += ie_len;
1320 } else {
1321 /* Passed data does not fit in the remaining
1322 buffer space */
1323 ret = -1;
1324 }
1325
1326 /* Return 0, or -1 for error case */
1327 return ret;
1328}
1329
1330/*
1331 * IOCTL request handler to set/get generic IE.
1332 *
1333 * In addition to various generic IEs, this function can also be
1334 * used to set the ARP filter.
1335 */
1336static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1337 struct mwifiex_ds_misc_gen_ie *gen_ie,
1338 u16 action)
1339{
1340 struct mwifiex_adapter *adapter = priv->adapter;
1341
1342 switch (gen_ie->type) {
1343 case MWIFIEX_IE_TYPE_GEN_IE:
1344 if (action == HostCmd_ACT_GEN_GET) {
1345 gen_ie->len = priv->wpa_ie_len;
1346 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1347 } else {
1348 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1349 (u16) gen_ie->len);
1350 }
1351 break;
1352 case MWIFIEX_IE_TYPE_ARP_FILTER:
1353 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1354 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1355 adapter->arp_filter_size = 0;
1356 dev_err(adapter->dev, "invalid ARP filter size\n");
1357 return -1;
1358 } else {
1359 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001360 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001361 adapter->arp_filter_size = gen_ie->len;
1362 }
1363 break;
1364 default:
1365 dev_err(adapter->dev, "invalid IE type\n");
1366 return -1;
1367 }
1368 return 0;
1369}
1370
1371/*
1372 * Sends IOCTL request to set a generic IE.
1373 *
1374 * This function allocates the IOCTL request buffer, fills it
1375 * with requisite parameters and calls the IOCTL handler.
1376 */
1377int
1378mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1379{
1380 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001381
Bing Zhao67a50032011-07-13 18:38:34 -07001382 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001383 return -EFAULT;
1384
1385 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1386 gen_ie.len = ie_len;
1387 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001388 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001389 return -EFAULT;
1390
1391 return 0;
1392}