blob: 76d31deb7b1b820270af361de0e8ed110b105dd9 [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),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000264 GFP_KERNEL);
265 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700266 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700267
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700268 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700269 if (ret)
270 goto done;
271 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700272
Bing Zhaoeecd8252011-03-28 17:55:41 -0700273 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700275 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700277 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700278
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800279 if (bss_desc) {
280 u8 config_bands = 0;
281
282 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
283 == HostCmd_SCAN_RADIO_TYPE_BG)
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800284 config_bands = BAND_B | BAND_G | BAND_GN |
285 BAND_GAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800286 else
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800287 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800288
289 if (!((config_bands | adapter->fw_bands) &
290 ~adapter->fw_bands))
291 adapter->config_bands = config_bands;
292 }
293
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700294 ret = mwifiex_check_network_compatibility(priv, bss_desc);
295 if (ret)
296 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700297
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700298 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
299 "associating...\n");
300
Avinash Patil47411a02012-11-01 18:44:16 -0700301 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800302 if (netif_carrier_ok(priv->netdev))
303 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700304
305 /* Clear any past association response stored for
306 * application retrieval */
307 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700308 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800309
310 /* If auth type is auto and association fails using open mode,
311 * try to connect using shared mode */
312 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
313 priv->sec_info.is_authtype_auto &&
314 priv->sec_info.wep_enabled) {
315 priv->sec_info.authentication_mode =
316 NL80211_AUTHTYPE_SHARED_KEY;
317 ret = mwifiex_associate(priv, bss_desc);
318 }
319
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700320 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100321 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700322 } else {
323 /* Adhoc mode */
324 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700325 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700326 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
327 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700328 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700330 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331
332 /* Exit Adhoc mode first */
333 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700334 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700335 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700336 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337
338 priv->adhoc_is_link_sensed = false;
339
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700340 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700341
Avinash Patil47411a02012-11-01 18:44:16 -0700342 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800343 if (netif_carrier_ok(priv->netdev))
344 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700345
346 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347 dev_dbg(adapter->dev, "info: network found in scan"
348 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700349 ret = mwifiex_adhoc_join(priv, bss_desc);
350 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100351 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700352 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353 dev_dbg(adapter->dev, "info: Network not found in "
354 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700355 req_ssid->ssid);
356 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700357 }
358 }
359
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700360done:
361 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 return ret;
363}
364
365/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700366 * IOCTL request handler to set host sleep configuration.
367 *
368 * This function prepares the correct firmware command and
369 * issues it.
370 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700371static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
372 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700373
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700374{
375 struct mwifiex_adapter *adapter = priv->adapter;
376 int status = 0;
377 u32 prev_cond = 0;
378
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700379 if (!hs_cfg)
380 return -ENOMEM;
381
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700382 switch (action) {
383 case HostCmd_ACT_GEN_SET:
384 if (adapter->pps_uapsd_mode) {
385 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
386 " is blocked in UAPSD/PPS mode\n");
387 status = -1;
388 break;
389 }
390 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800391 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700392 if (!adapter->is_hs_configured)
393 /* Already cancelled */
394 break;
395 /* Save previous condition */
396 prev_cond = le32_to_cpu(adapter->hs_cfg
397 .conditions);
398 adapter->hs_cfg.conditions =
399 cpu_to_le32(hs_cfg->conditions);
400 } else if (hs_cfg->conditions) {
401 adapter->hs_cfg.conditions =
402 cpu_to_le32(hs_cfg->conditions);
403 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
404 if (hs_cfg->gap)
405 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800406 } else if (adapter->hs_cfg.conditions ==
407 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700408 /* Return failure if no parameters for HS
409 enable */
410 status = -1;
411 break;
412 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700413 if (cmd_type == MWIFIEX_SYNC_CMD)
414 status = mwifiex_send_cmd_sync(priv,
415 HostCmd_CMD_802_11_HS_CFG_ENH,
416 HostCmd_ACT_GEN_SET, 0,
417 &adapter->hs_cfg);
418 else
419 status = mwifiex_send_cmd_async(priv,
420 HostCmd_CMD_802_11_HS_CFG_ENH,
421 HostCmd_ACT_GEN_SET, 0,
422 &adapter->hs_cfg);
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800423 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700424 /* Restore previous condition */
425 adapter->hs_cfg.conditions =
426 cpu_to_le32(prev_cond);
427 } else {
428 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700429 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700430 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
431 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
432 }
433 break;
434 case HostCmd_ACT_GEN_GET:
435 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
436 hs_cfg->gpio = adapter->hs_cfg.gpio;
437 hs_cfg->gap = adapter->hs_cfg.gap;
438 break;
439 default:
440 status = -1;
441 break;
442 }
443
444 return status;
445}
446
447/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448 * Sends IOCTL request to cancel the existing Host Sleep configuration.
449 *
450 * This function allocates the IOCTL request buffer, fills it
451 * with requisite parameters and calls the IOCTL handler.
452 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700453int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700454{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700455 struct mwifiex_ds_hs_cfg hscfg;
456
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800457 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700458 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700459
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700460 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
461 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700462}
463EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
464
465/*
466 * Sends IOCTL request to cancel the existing Host Sleep configuration.
467 *
468 * This function allocates the IOCTL request buffer, fills it
469 * with requisite parameters and calls the IOCTL handler.
470 */
471int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
472{
473 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700474 struct mwifiex_private *priv;
475 int i;
476
477 if (disconnect_on_suspend) {
478 for (i = 0; i < adapter->priv_num; i++) {
479 priv = adapter->priv[i];
480 if (priv)
481 mwifiex_deauthenticate(priv, NULL);
482 }
483 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700484
485 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900486 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700487 return true;
488 }
489
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700490 adapter->hs_activate_wait_q_woken = false;
491
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700492 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700493 hscfg.is_invoke_hostcmd = true;
494
495 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700496 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700497 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
498 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700499 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
500 return false;
501 }
502
Bing Zhao9c969d82013-01-02 16:07:35 -0800503 if (wait_event_interruptible(adapter->hs_activate_wait_q,
504 adapter->hs_activate_wait_q_woken)) {
505 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
506 return false;
507 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700508
509 return true;
510}
511EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
512
513/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514 * IOCTL request handler to get BSS information.
515 *
516 * This function collates the information from different driver structures
517 * to send to the user.
518 */
519int mwifiex_get_bss_info(struct mwifiex_private *priv,
520 struct mwifiex_bss_info *info)
521{
522 struct mwifiex_adapter *adapter = priv->adapter;
523 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700524
525 if (!info)
526 return -1;
527
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700528 bss_desc = &priv->curr_bss_params.bss_descriptor;
529
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700530 info->bss_mode = priv->bss_mode;
531
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800532 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700533
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700534 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
535
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700536 info->bss_chan = bss_desc->channel;
537
Avinash Patil67fdf392012-05-08 18:30:17 -0700538 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700539 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700540
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700541 info->media_connected = priv->media_connected;
542
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543 info->max_power_level = priv->max_tx_power_level;
544 info->min_power_level = priv->min_tx_power_level;
545
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700546 info->adhoc_state = priv->adhoc_state;
547
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 info->bcn_nf_last = priv->bcn_nf_last;
549
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800550 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700551 info->wep_status = true;
552 else
553 info->wep_status = false;
554
555 info->is_hs_configured = adapter->is_hs_configured;
556 info->is_deep_sleep = adapter->is_deep_sleep;
557
558 return 0;
559}
560
561/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700562 * The function disables auto deep sleep mode.
563 */
564int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
565{
566 struct mwifiex_ds_auto_ds auto_ds;
567
568 auto_ds.auto_ds = DEEP_SLEEP_OFF;
569
570 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
571 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
572}
573EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
574
575/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700576 * Sends IOCTL request to get the data rate.
577 *
578 * This function allocates the IOCTL request buffer, fills it
579 * with requisite parameters and calls the IOCTL handler.
580 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700581int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700583 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700584
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700585 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
586 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700587
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700589 if (priv->is_data_rate_auto)
590 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
591 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300592 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700593 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594 }
595
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 return ret;
597}
598
599/*
600 * IOCTL request handler to set tx power configuration.
601 *
602 * This function prepares the correct firmware command and
603 * issues it.
604 *
605 * For non-auto power mode, all the following power groups are set -
606 * - Modulation class HR/DSSS
607 * - Modulation class OFDM
608 * - Modulation class HTBW20
609 * - Modulation class HTBW40
610 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700611int mwifiex_set_tx_power(struct mwifiex_private *priv,
612 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700613{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700614 int ret;
615 struct host_cmd_ds_txpwr_cfg *txp_cfg;
616 struct mwifiex_types_power_group *pg_tlv;
617 struct mwifiex_power_group *pg;
618 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619 u16 dbm = 0;
620
621 if (!power_cfg->is_power_auto) {
622 dbm = (u16) power_cfg->power_level;
623 if ((dbm < priv->min_tx_power_level) ||
624 (dbm > priv->max_tx_power_level)) {
625 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700626 " is out of range (%d dBm-%d dBm)\n",
627 dbm, priv->min_tx_power_level,
628 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700629 return -1;
630 }
631 }
632 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000633 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200634 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700635
636 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
637 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
638 if (!power_cfg->is_power_auto) {
639 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700640 pg_tlv = (struct mwifiex_types_power_group *)
641 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700642 pg_tlv->type = TLV_TYPE_POWER_GROUP;
643 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700644 pg = (struct mwifiex_power_group *)
645 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
646 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700647 /* Power group for modulation class HR/DSSS */
648 pg->first_rate_code = 0x00;
649 pg->last_rate_code = 0x03;
650 pg->modulation_class = MOD_CLASS_HR_DSSS;
651 pg->power_step = 0;
652 pg->power_min = (s8) dbm;
653 pg->power_max = (s8) dbm;
654 pg++;
655 /* Power group for modulation class OFDM */
656 pg->first_rate_code = 0x00;
657 pg->last_rate_code = 0x07;
658 pg->modulation_class = MOD_CLASS_OFDM;
659 pg->power_step = 0;
660 pg->power_min = (s8) dbm;
661 pg->power_max = (s8) dbm;
662 pg++;
663 /* Power group for modulation class HTBW20 */
664 pg->first_rate_code = 0x00;
665 pg->last_rate_code = 0x20;
666 pg->modulation_class = MOD_CLASS_HT;
667 pg->power_step = 0;
668 pg->power_min = (s8) dbm;
669 pg->power_max = (s8) dbm;
670 pg->ht_bandwidth = HT_BW_20;
671 pg++;
672 /* Power group for modulation class HTBW40 */
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_40;
680 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700681 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
682 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700683
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700684 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700685 return ret;
686}
687
688/*
689 * IOCTL request handler to get power save mode.
690 *
691 * This function prepares the correct firmware command and
692 * issues it.
693 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700694int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700695{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700696 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700697 struct mwifiex_adapter *adapter = priv->adapter;
698 u16 sub_cmd;
699
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700700 if (*ps_mode)
701 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
702 else
703 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
704 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
705 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
706 sub_cmd, BITMAP_STA_PS, NULL);
707 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
708 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700709 HostCmd_CMD_802_11_PS_MODE_ENH,
710 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700711
712 return ret;
713}
714
715/*
716 * IOCTL request handler to set/reset WPA IE.
717 *
718 * The supplied WPA IE is treated as a opaque buffer. Only the first field
719 * is checked to determine WPA version. If buffer length is zero, the existing
720 * WPA IE is reset.
721 */
722static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
723 u8 *ie_data_ptr, u16 ie_len)
724{
725 if (ie_len) {
726 if (ie_len > sizeof(priv->wpa_ie)) {
727 dev_err(priv->adapter->dev,
728 "failed to copy WPA IE, too big\n");
729 return -1;
730 }
731 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
732 priv->wpa_ie_len = (u8) ie_len;
733 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700734 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700735
Arend van Spriel04b23122012-10-12 12:28:14 +0200736 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700737 priv->sec_info.wpa_enabled = true;
738 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
739 priv->sec_info.wpa2_enabled = true;
740 } else {
741 priv->sec_info.wpa_enabled = false;
742 priv->sec_info.wpa2_enabled = false;
743 }
744 } else {
745 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
746 priv->wpa_ie_len = 0;
747 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
748 priv->wpa_ie_len, priv->wpa_ie[0]);
749 priv->sec_info.wpa_enabled = false;
750 priv->sec_info.wpa2_enabled = false;
751 }
752
753 return 0;
754}
755
756/*
757 * IOCTL request handler to set/reset WAPI IE.
758 *
759 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
760 * is checked to internally enable WAPI. If buffer length is zero, the existing
761 * WAPI IE is reset.
762 */
763static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
764 u8 *ie_data_ptr, u16 ie_len)
765{
766 if (ie_len) {
767 if (ie_len > sizeof(priv->wapi_ie)) {
768 dev_dbg(priv->adapter->dev,
769 "info: failed to copy WAPI IE, too big\n");
770 return -1;
771 }
772 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
773 priv->wapi_ie_len = ie_len;
774 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700775 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700776
777 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
778 priv->sec_info.wapi_enabled = true;
779 } else {
780 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
781 priv->wapi_ie_len = ie_len;
782 dev_dbg(priv->adapter->dev,
783 "info: Reset wapi_ie_len=%d IE=%#x\n",
784 priv->wapi_ie_len, priv->wapi_ie[0]);
785 priv->sec_info.wapi_enabled = false;
786 }
787 return 0;
788}
789
790/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700791 * IOCTL request handler to set/reset WPS IE.
792 *
793 * The supplied WPS IE is treated as a opaque buffer. Only the first field
794 * is checked to internally enable WPS. If buffer length is zero, the existing
795 * WPS IE is reset.
796 */
797static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
798 u8 *ie_data_ptr, u16 ie_len)
799{
800 if (ie_len) {
801 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
802 if (!priv->wps_ie)
803 return -ENOMEM;
804 if (ie_len > sizeof(priv->wps_ie)) {
805 dev_dbg(priv->adapter->dev,
806 "info: failed to copy WPS IE, too big\n");
807 kfree(priv->wps_ie);
808 return -1;
809 }
810 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
811 priv->wps_ie_len = ie_len;
812 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
813 priv->wps_ie_len, priv->wps_ie[0]);
814 } else {
815 kfree(priv->wps_ie);
816 priv->wps_ie_len = ie_len;
817 dev_dbg(priv->adapter->dev,
818 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
819 }
820 return 0;
821}
822
823/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700824 * IOCTL request handler to set WAPI key.
825 *
826 * This function prepares the correct firmware command and
827 * issues it.
828 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700829static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700830 struct mwifiex_ds_encrypt_key *encrypt_key)
831{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700832
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700833 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700834 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
835 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700836}
837
838/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700839 * IOCTL request handler to set WEP network key.
840 *
841 * This function prepares the correct firmware command and
842 * issues it, after validation checks.
843 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700844static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700845 struct mwifiex_ds_encrypt_key *encrypt_key)
846{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700847 int ret;
848 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700849 int index;
850
851 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
852 priv->wep_key_curr_index = 0;
853 wep_key = &priv->wep_key[priv->wep_key_curr_index];
854 index = encrypt_key->key_index;
855 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800856 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700857 } else if (!encrypt_key->key_len) {
858 /* Copy the required key as the current key */
859 wep_key = &priv->wep_key[index];
860 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700861 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700862 "key not set, so cannot enable it\n");
863 return -1;
864 }
865 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800866 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867 } else {
868 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700869 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
870 /* Copy the key in the driver */
871 memcpy(wep_key->key_material,
872 encrypt_key->key_material,
873 encrypt_key->key_len);
874 wep_key->key_index = index;
875 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800876 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700877 }
878 if (wep_key->key_length) {
879 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700880 ret = mwifiex_send_cmd_async(priv,
881 HostCmd_CMD_802_11_KEY_MATERIAL,
882 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700883 if (ret)
884 return ret;
885 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800886 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700887 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
888 else
889 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
890
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700891 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
892 HostCmd_ACT_GEN_SET, 0,
893 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700894
895 return ret;
896}
897
898/*
899 * IOCTL request handler to set WPA key.
900 *
901 * This function prepares the correct firmware command and
902 * issues it, after validation checks.
903 *
904 * Current driver only supports key length of up to 32 bytes.
905 *
906 * This function can also be used to disable a currently set key.
907 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700908static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700909 struct mwifiex_ds_encrypt_key *encrypt_key)
910{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700911 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700912 u8 remove_key = false;
913 struct host_cmd_ds_802_11_key_material *ibss_key;
914
915 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700916 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700917 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700918 return -1;
919 }
920
Bing Zhaoeecd8252011-03-28 17:55:41 -0700921 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700922 /*
923 * IBSS/WPA-None uses only one key (Group) for both receiving
924 * and sending unicast and multicast packets.
925 */
926 /* Send the key as PTK to firmware */
927 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700928 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700929 HostCmd_CMD_802_11_KEY_MATERIAL,
930 HostCmd_ACT_GEN_SET,
931 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700932 if (ret)
933 return ret;
934
935 ibss_key = &priv->aes_key;
936 memset(ibss_key, 0,
937 sizeof(struct host_cmd_ds_802_11_key_material));
938 /* Copy the key in the driver */
939 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
940 encrypt_key->key_len);
941 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
942 sizeof(ibss_key->key_param_set.key_len));
943 ibss_key->key_param_set.key_type_id
944 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700945 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700946
947 /* Send the key as GTK to firmware */
948 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
949 }
950
951 if (!encrypt_key->key_index)
952 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
953
954 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700955 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700956 HostCmd_CMD_802_11_KEY_MATERIAL,
957 HostCmd_ACT_GEN_SET,
958 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700959 else
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
965 return ret;
966}
967
968/*
969 * IOCTL request handler to set/get network keys.
970 *
971 * This is a generic key handling function which supports WEP, WPA
972 * and WAPI.
973 */
974static int
975mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700976 struct mwifiex_ds_encrypt_key *encrypt_key)
977{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700978 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700979
980 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700981 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700982 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700983 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700984 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700985 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700986 return status;
987}
988
989/*
990 * This function returns the driver version.
991 */
992int
993mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
994 int max_len)
995{
996 union {
997 u32 l;
998 u8 c[4];
999 } ver;
1000 char fw_ver[32];
1001
1002 ver.l = adapter->fw_release_number;
1003 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1004
1005 snprintf(version, max_len, driver_version, fw_ver);
1006
1007 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1008
1009 return 0;
1010}
1011
1012/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001013 * Sends IOCTL request to set encoding parameters.
1014 *
1015 * This function allocates the IOCTL request buffer, fills it
1016 * with requisite parameters and calls the IOCTL handler.
1017 */
Ying Luo53b11232012-08-03 18:06:13 -07001018int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1019 const u8 *key, int key_len, u8 key_index,
1020 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001021{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001023
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001024 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1025 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001026
1027 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1028 encrypt_key.is_igtk_key = true;
1029
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001030 if (!disable) {
1031 encrypt_key.key_index = key_index;
1032 if (key_len)
1033 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001034 if (mac_addr)
1035 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001036 if (kp && kp->seq && kp->seq_len)
1037 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 } else {
1039 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001040 if (mac_addr)
1041 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042 }
1043
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001044 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001045}
1046
1047/*
1048 * Sends IOCTL request to get extended version.
1049 *
1050 * This function allocates the IOCTL request buffer, fills it
1051 * with requisite parameters and calls the IOCTL handler.
1052 */
1053int
1054mwifiex_get_ver_ext(struct mwifiex_private *priv)
1055{
1056 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001057
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001059 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001060 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001061 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001062
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001063 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001064}
1065
Stone Piao7feb4c42012-09-25 20:23:36 -07001066int
1067mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1068 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001069 unsigned int duration)
1070{
1071 struct host_cmd_ds_remain_on_chan roc_cfg;
1072 u8 sc;
1073
1074 memset(&roc_cfg, 0, sizeof(roc_cfg));
1075 roc_cfg.action = cpu_to_le16(action);
1076 if (action == HostCmd_ACT_GEN_SET) {
1077 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001078 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001079 roc_cfg.band_cfg |= (sc << 2);
1080
1081 roc_cfg.channel =
1082 ieee80211_frequency_to_channel(chan->center_freq);
1083 roc_cfg.duration = cpu_to_le32(duration);
1084 }
1085 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1086 action, 0, &roc_cfg)) {
1087 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1088 return -1;
1089 }
1090
1091 return roc_cfg.status;
1092}
1093
Stone Piao9197ab92012-09-25 20:23:42 -07001094int
1095mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1096{
1097 if (GET_BSS_ROLE(priv) == bss_role) {
1098 dev_dbg(priv->adapter->dev,
1099 "info: already in the desired role.\n");
1100 return 0;
1101 }
1102
1103 mwifiex_free_priv(priv);
1104 mwifiex_init_priv(priv);
1105
1106 priv->bss_role = bss_role;
1107 switch (bss_role) {
1108 case MWIFIEX_BSS_ROLE_UAP:
1109 priv->bss_mode = NL80211_IFTYPE_AP;
1110 break;
1111 case MWIFIEX_BSS_ROLE_STA:
1112 case MWIFIEX_BSS_ROLE_ANY:
1113 default:
1114 priv->bss_mode = NL80211_IFTYPE_STATION;
1115 break;
1116 }
1117
1118 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1119 HostCmd_ACT_GEN_SET, 0, NULL);
1120
1121 return mwifiex_sta_init_cmd(priv, false);
1122}
1123
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001124/*
1125 * Sends IOCTL request to get statistics information.
1126 *
1127 * This function allocates the IOCTL request buffer, fills it
1128 * with requisite parameters and calls the IOCTL handler.
1129 */
1130int
1131mwifiex_get_stats_info(struct mwifiex_private *priv,
1132 struct mwifiex_ds_get_stats *log)
1133{
Bing Zhao67a50032011-07-13 18:38:34 -07001134 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001135 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001136}
1137
1138/*
1139 * IOCTL request handler to read/write register.
1140 *
1141 * This function prepares the correct firmware command and
1142 * issues it.
1143 *
1144 * Access to the following registers are supported -
1145 * - MAC
1146 * - BBP
1147 * - RF
1148 * - PMIC
1149 * - CAU
1150 */
1151static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001152 struct mwifiex_ds_reg_rw *reg_rw,
1153 u16 action)
1154{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001155 u16 cmd_no;
1156
1157 switch (le32_to_cpu(reg_rw->type)) {
1158 case MWIFIEX_REG_MAC:
1159 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1160 break;
1161 case MWIFIEX_REG_BBP:
1162 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1163 break;
1164 case MWIFIEX_REG_RF:
1165 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1166 break;
1167 case MWIFIEX_REG_PMIC:
1168 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1169 break;
1170 case MWIFIEX_REG_CAU:
1171 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1172 break;
1173 default:
1174 return -1;
1175 }
1176
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001177 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001178
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001179}
1180
1181/*
1182 * Sends IOCTL request to write to a register.
1183 *
1184 * This function allocates the IOCTL request buffer, fills it
1185 * with requisite parameters and calls the IOCTL handler.
1186 */
1187int
1188mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1189 u32 reg_offset, u32 reg_value)
1190{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001191 struct mwifiex_ds_reg_rw reg_rw;
1192
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001193 reg_rw.type = cpu_to_le32(reg_type);
1194 reg_rw.offset = cpu_to_le32(reg_offset);
1195 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001197 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001198}
1199
1200/*
1201 * Sends IOCTL request to read from a register.
1202 *
1203 * This function allocates the IOCTL request buffer, fills it
1204 * with requisite parameters and calls the IOCTL handler.
1205 */
1206int
1207mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1208 u32 reg_offset, u32 *value)
1209{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001210 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001211 struct mwifiex_ds_reg_rw reg_rw;
1212
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001213 reg_rw.type = cpu_to_le32(reg_type);
1214 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001215 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001216
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001217 if (ret)
1218 goto done;
1219
1220 *value = le32_to_cpu(reg_rw.value);
1221
1222done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001223 return ret;
1224}
1225
1226/*
1227 * Sends IOCTL request to read from EEPROM.
1228 *
1229 * This function allocates the IOCTL request buffer, fills it
1230 * with requisite parameters and calls the IOCTL handler.
1231 */
1232int
1233mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1234 u8 *value)
1235{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001236 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001237 struct mwifiex_ds_read_eeprom rd_eeprom;
1238
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239 rd_eeprom.offset = cpu_to_le16((u16) offset);
1240 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001241
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001242 /* Send request to firmware */
1243 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1244 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001245
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001246 if (!ret)
1247 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001248 return ret;
1249}
1250
1251/*
1252 * This function sets a generic IE. In addition to generic IE, it can
1253 * also handle WPA, WPA2 and WAPI IEs.
1254 */
1255static int
1256mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1257 u16 ie_len)
1258{
1259 int ret = 0;
1260 struct ieee_types_vendor_header *pvendor_ie;
1261 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1262 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1263
1264 /* If the passed length is zero, reset the buffer */
1265 if (!ie_len) {
1266 priv->gen_ie_buf_len = 0;
1267 priv->wps.session_enable = false;
1268
1269 return 0;
1270 } else if (!ie_data_ptr) {
1271 return -1;
1272 }
1273 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1274 /* 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 +02001275 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001276 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1277 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001278
1279 /* IE is a WPA/WPA2 IE so call set_wpa function */
1280 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1281 priv->wps.session_enable = false;
1282
1283 return ret;
1284 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1285 /* IE is a WAPI IE so call set_wapi function */
1286 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1287
1288 return ret;
1289 }
1290 /*
1291 * Verify that the passed length is not larger than the
1292 * available space remaining in the buffer
1293 */
1294 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1295
1296 /* Test to see if it is a WPS IE, if so, enable
1297 * wps session flag
1298 */
1299 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001300 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1301 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001302 priv->wps.session_enable = true;
1303 dev_dbg(priv->adapter->dev,
1304 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001305 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001306 }
1307
1308 /* Append the passed data to the end of the
1309 genIeBuffer */
1310 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001311 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001312 /* Increment the stored buffer length by the
1313 size passed */
1314 priv->gen_ie_buf_len += ie_len;
1315 } else {
1316 /* Passed data does not fit in the remaining
1317 buffer space */
1318 ret = -1;
1319 }
1320
1321 /* Return 0, or -1 for error case */
1322 return ret;
1323}
1324
1325/*
1326 * IOCTL request handler to set/get generic IE.
1327 *
1328 * In addition to various generic IEs, this function can also be
1329 * used to set the ARP filter.
1330 */
1331static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1332 struct mwifiex_ds_misc_gen_ie *gen_ie,
1333 u16 action)
1334{
1335 struct mwifiex_adapter *adapter = priv->adapter;
1336
1337 switch (gen_ie->type) {
1338 case MWIFIEX_IE_TYPE_GEN_IE:
1339 if (action == HostCmd_ACT_GEN_GET) {
1340 gen_ie->len = priv->wpa_ie_len;
1341 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1342 } else {
1343 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1344 (u16) gen_ie->len);
1345 }
1346 break;
1347 case MWIFIEX_IE_TYPE_ARP_FILTER:
1348 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1349 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1350 adapter->arp_filter_size = 0;
1351 dev_err(adapter->dev, "invalid ARP filter size\n");
1352 return -1;
1353 } else {
1354 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001355 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001356 adapter->arp_filter_size = gen_ie->len;
1357 }
1358 break;
1359 default:
1360 dev_err(adapter->dev, "invalid IE type\n");
1361 return -1;
1362 }
1363 return 0;
1364}
1365
1366/*
1367 * Sends IOCTL request to set a generic IE.
1368 *
1369 * This function allocates the IOCTL request buffer, fills it
1370 * with requisite parameters and calls the IOCTL handler.
1371 */
1372int
1373mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1374{
1375 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001376
Bing Zhao67a50032011-07-13 18:38:34 -07001377 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001378 return -EFAULT;
1379
1380 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1381 gen_ie.len = ie_len;
1382 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001383 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001384 return -EFAULT;
1385
1386 return 0;
1387}