blob: 1a8a19dbd635df7b6b012533605cdde724c0d000 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: functions for station ioctl
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27#include "cfg80211.h"
28
Amitkumar Karwar22c22d22012-09-20 20:23:17 -070029static int disconnect_on_suspend = 1;
30module_param(disconnect_on_suspend, int, 0644);
31
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032/*
33 * Copies the multicast address list from device to driver.
34 *
35 * This function does not validate the destination memory for
36 * size, and the calling function must ensure enough memory is
37 * available.
38 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070039int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
40 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070041{
42 int i = 0;
43 struct netdev_hw_addr *ha;
44
45 netdev_for_each_mc_addr(ha, dev)
46 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
47
48 return i;
49}
50
51/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052 * Wait queue completion handler.
53 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070054 * This function waits on a cmd wait queue. It also cancels the pending
55 * request after waking up, in case of errors.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056 */
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -070057int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
58 struct cmd_ctrl_node *cmd_queued)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059{
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080060 int status;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080061
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070062 /* Wait for completion */
Bing Zhao9c969d82013-01-02 16:07:35 -080063 status = wait_event_interruptible(adapter->cmd_wait_q.wait,
64 *(cmd_queued->condition));
65 if (status) {
66 dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status);
67 return status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070068 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080069
70 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070071 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070072
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073 return status;
74}
75
76/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077 * This function prepares the correct firmware command and
78 * issues it to set the multicast list.
79 *
80 * This function can be used to enable promiscuous mode, or enable all
81 * multicast packets, or to enable selective multicast.
82 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070083int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
84 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070085{
86 int ret = 0;
87 u16 old_pkt_filter;
88
89 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070090
91 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
92 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
93 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
94 priv->curr_pkt_filter &=
95 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
96 } else {
97 /* Multicast */
98 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
Daniel Drakeccd384b2013-05-08 15:37:19 -040099 if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700100 dev_dbg(priv->adapter->dev,
101 "info: Enabling All Multicast!\n");
102 priv->curr_pkt_filter |=
103 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
104 } else {
105 priv->curr_pkt_filter &=
106 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
107 if (mcast_list->num_multicast_addr) {
108 dev_dbg(priv->adapter->dev,
109 "info: Set multicast list=%d\n",
110 mcast_list->num_multicast_addr);
Daniel Drakeccd384b2013-05-08 15:37:19 -0400111 /* Send multicast addresses to firmware */
112 ret = mwifiex_send_cmd_async(priv,
113 HostCmd_CMD_MAC_MULTICAST_ADR,
114 HostCmd_ACT_GEN_SET, 0,
115 mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116 }
117 }
118 }
119 dev_dbg(priv->adapter->dev,
120 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
121 old_pkt_filter, priv->curr_pkt_filter);
122 if (old_pkt_filter != priv->curr_pkt_filter) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700123 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
124 HostCmd_ACT_GEN_SET,
125 0, &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126 }
127
128 return ret;
129}
130
131/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700132 * This function fills bss descriptor structure using provided
133 * information.
Bing Zhaod837a2a2013-04-12 10:34:17 -0700134 * beacon_ie buffer is allocated in this function. It is caller's
135 * responsibility to free the memory.
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700136 */
137int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700138 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700139 struct mwifiex_bssdescriptor *bss_desc)
140{
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700141 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500142 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700143 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100144 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700145
Johannes Berg9caf0362012-11-29 01:25:20 +0100146 rcu_read_lock();
147 ies = rcu_dereference(bss->ies);
Johannes Berg9caf0362012-11-29 01:25:20 +0100148 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
149 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100150 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100151 rcu_read_unlock();
152
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700153 if (!beacon_ie) {
154 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
155 return -ENOMEM;
156 }
157
158 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
159 bss_desc->rssi = bss->signal;
Bing Zhaod837a2a2013-04-12 10:34:17 -0700160 /* The caller of this function will free beacon_ie */
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700161 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100162 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700163 bss_desc->beacon_period = bss->beacon_interval;
164 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700165 bss_desc->bss_band = bss_priv->band;
166 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700167 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
168 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
169 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
170 } else {
171 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
172 }
173 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
174 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
175 else
176 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
177
Bing Zhaoc43933e2013-04-12 10:34:18 -0700178 /* Disable 11ac by default. Enable it only where there
179 * exist VHT_CAP IE in AP beacon
180 */
181 bss_desc->disable_11ac = true;
182
Bing Zhaod837a2a2013-04-12 10:34:17 -0700183 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700184}
185
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700186static int mwifiex_process_country_ie(struct mwifiex_private *priv,
187 struct cfg80211_bss *bss)
188{
Johannes Berg9caf0362012-11-29 01:25:20 +0100189 const u8 *country_ie;
190 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700191 struct mwifiex_802_11d_domain_reg *domain_info =
192 &priv->adapter->domain_reg;
193
Johannes Berg9caf0362012-11-29 01:25:20 +0100194 rcu_read_lock();
195 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
196 if (!country_ie) {
197 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700198 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100199 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700200
201 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100202 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
203 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700204 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100205 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700206
207 domain_info->country_code[0] = country_ie[2];
208 domain_info->country_code[1] = country_ie[3];
209 domain_info->country_code[2] = ' ';
210
211 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
212
213 domain_info->no_of_triplet =
214 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
215
216 memcpy((u8 *)domain_info->triplet,
217 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
218
Johannes Berg9caf0362012-11-29 01:25:20 +0100219 rcu_read_unlock();
220
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700221 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
222 HostCmd_ACT_GEN_SET, 0, NULL)) {
223 wiphy_err(priv->adapter->wiphy,
224 "11D: setting domain info in FW\n");
225 return -1;
226 }
227
228 return 0;
229}
230
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700231/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700232 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
233 * In both Ad-Hoc and infra mode, an deauthentication is performed
234 * first.
235 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700236int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800237 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700238{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700239 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700240 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700241 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700242
243 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700244
245 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700246 mwifiex_process_country_ie(priv, bss);
247
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700248 /* Allocate and fill new bss descriptor */
249 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000250 GFP_KERNEL);
251 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700252 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700253
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700254 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700255 if (ret)
256 goto done;
257 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258
Bing Zhaoeecd8252011-03-28 17:55:41 -0700259 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700260 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700261 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700262 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700263 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700264
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800265 if (bss_desc) {
266 u8 config_bands = 0;
267
268 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
269 == HostCmd_SCAN_RADIO_TYPE_BG)
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800270 config_bands = BAND_B | BAND_G | BAND_GN |
271 BAND_GAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800272 else
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800273 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800274
275 if (!((config_bands | adapter->fw_bands) &
276 ~adapter->fw_bands))
277 adapter->config_bands = config_bands;
278 }
279
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700280 ret = mwifiex_check_network_compatibility(priv, bss_desc);
281 if (ret)
282 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700283
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700284 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
285 "associating...\n");
286
Avinash Patil47411a02012-11-01 18:44:16 -0700287 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800288 if (netif_carrier_ok(priv->netdev))
289 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700290
291 /* Clear any past association response stored for
292 * application retrieval */
293 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700294 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800295
296 /* If auth type is auto and association fails using open mode,
297 * try to connect using shared mode */
298 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
299 priv->sec_info.is_authtype_auto &&
300 priv->sec_info.wep_enabled) {
301 priv->sec_info.authentication_mode =
302 NL80211_AUTHTYPE_SHARED_KEY;
303 ret = mwifiex_associate(priv, bss_desc);
304 }
305
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700306 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100307 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700308 } else {
309 /* Adhoc mode */
310 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700311 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700312 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
313 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700314 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700315 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700316 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700317
318 /* Exit Adhoc mode first */
319 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700320 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700321 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700322 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700323
324 priv->adhoc_is_link_sensed = false;
325
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700326 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700327
Avinash Patil47411a02012-11-01 18:44:16 -0700328 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800329 if (netif_carrier_ok(priv->netdev))
330 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700331
332 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700333 dev_dbg(adapter->dev, "info: network found in scan"
334 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700335 ret = mwifiex_adhoc_join(priv, bss_desc);
336 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100337 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700338 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700339 dev_dbg(adapter->dev, "info: Network not found in "
340 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700341 req_ssid->ssid);
342 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700343 }
344 }
345
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700346done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700347 /* beacon_ie buffer was allocated in function
348 * mwifiex_fill_new_bss_desc(). Free it now.
349 */
350 if (bss_desc)
351 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700352 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353 return ret;
354}
355
356/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700357 * IOCTL request handler to set host sleep configuration.
358 *
359 * This function prepares the correct firmware command and
360 * issues it.
361 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700362static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
363 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700364
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700365{
366 struct mwifiex_adapter *adapter = priv->adapter;
367 int status = 0;
368 u32 prev_cond = 0;
369
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700370 if (!hs_cfg)
371 return -ENOMEM;
372
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700373 switch (action) {
374 case HostCmd_ACT_GEN_SET:
375 if (adapter->pps_uapsd_mode) {
376 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
377 " is blocked in UAPSD/PPS mode\n");
378 status = -1;
379 break;
380 }
381 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800382 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700383 if (!adapter->is_hs_configured)
384 /* Already cancelled */
385 break;
386 /* Save previous condition */
387 prev_cond = le32_to_cpu(adapter->hs_cfg
388 .conditions);
389 adapter->hs_cfg.conditions =
390 cpu_to_le32(hs_cfg->conditions);
391 } else if (hs_cfg->conditions) {
392 adapter->hs_cfg.conditions =
393 cpu_to_le32(hs_cfg->conditions);
394 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
395 if (hs_cfg->gap)
396 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800397 } else if (adapter->hs_cfg.conditions ==
398 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700399 /* Return failure if no parameters for HS
400 enable */
401 status = -1;
402 break;
403 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700404 if (cmd_type == MWIFIEX_SYNC_CMD)
405 status = mwifiex_send_cmd_sync(priv,
406 HostCmd_CMD_802_11_HS_CFG_ENH,
407 HostCmd_ACT_GEN_SET, 0,
408 &adapter->hs_cfg);
409 else
410 status = mwifiex_send_cmd_async(priv,
411 HostCmd_CMD_802_11_HS_CFG_ENH,
412 HostCmd_ACT_GEN_SET, 0,
413 &adapter->hs_cfg);
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800414 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700415 /* Restore previous condition */
416 adapter->hs_cfg.conditions =
417 cpu_to_le32(prev_cond);
418 } else {
419 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700420 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700421 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
422 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
423 }
424 break;
425 case HostCmd_ACT_GEN_GET:
426 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
427 hs_cfg->gpio = adapter->hs_cfg.gpio;
428 hs_cfg->gap = adapter->hs_cfg.gap;
429 break;
430 default:
431 status = -1;
432 break;
433 }
434
435 return status;
436}
437
438/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700439 * Sends IOCTL request to cancel the existing Host Sleep configuration.
440 *
441 * This function allocates the IOCTL request buffer, fills it
442 * with requisite parameters and calls the IOCTL handler.
443 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700444int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700445{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700446 struct mwifiex_ds_hs_cfg hscfg;
447
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800448 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700449 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700450
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700451 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
452 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700453}
454EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
455
456/*
457 * Sends IOCTL request to cancel the existing Host Sleep configuration.
458 *
459 * This function allocates the IOCTL request buffer, fills it
460 * with requisite parameters and calls the IOCTL handler.
461 */
462int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
463{
464 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700465 struct mwifiex_private *priv;
466 int i;
467
468 if (disconnect_on_suspend) {
469 for (i = 0; i < adapter->priv_num; i++) {
470 priv = adapter->priv[i];
471 if (priv)
472 mwifiex_deauthenticate(priv, NULL);
473 }
474 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475
476 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900477 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700478 return true;
479 }
480
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700481 adapter->hs_activate_wait_q_woken = false;
482
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700483 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700484 hscfg.is_invoke_hostcmd = true;
485
486 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700487 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700488 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
489 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700490 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
491 return false;
492 }
493
Bing Zhao9c969d82013-01-02 16:07:35 -0800494 if (wait_event_interruptible(adapter->hs_activate_wait_q,
495 adapter->hs_activate_wait_q_woken)) {
496 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
497 return false;
498 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700499
500 return true;
501}
502EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
503
504/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 * IOCTL request handler to get BSS information.
506 *
507 * This function collates the information from different driver structures
508 * to send to the user.
509 */
510int mwifiex_get_bss_info(struct mwifiex_private *priv,
511 struct mwifiex_bss_info *info)
512{
513 struct mwifiex_adapter *adapter = priv->adapter;
514 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700515
516 if (!info)
517 return -1;
518
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700519 bss_desc = &priv->curr_bss_params.bss_descriptor;
520
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700521 info->bss_mode = priv->bss_mode;
522
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800523 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700524
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700525 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
526
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700527 info->bss_chan = bss_desc->channel;
528
Avinash Patil67fdf392012-05-08 18:30:17 -0700529 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700530 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700531
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700532 info->media_connected = priv->media_connected;
533
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700534 info->max_power_level = priv->max_tx_power_level;
535 info->min_power_level = priv->min_tx_power_level;
536
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537 info->adhoc_state = priv->adhoc_state;
538
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700539 info->bcn_nf_last = priv->bcn_nf_last;
540
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800541 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700542 info->wep_status = true;
543 else
544 info->wep_status = false;
545
546 info->is_hs_configured = adapter->is_hs_configured;
547 info->is_deep_sleep = adapter->is_deep_sleep;
548
549 return 0;
550}
551
552/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700553 * The function disables auto deep sleep mode.
554 */
555int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
556{
557 struct mwifiex_ds_auto_ds auto_ds;
558
559 auto_ds.auto_ds = DEEP_SLEEP_OFF;
560
561 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
562 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
563}
564EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
565
566/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567 * Sends IOCTL request to get the data rate.
568 *
569 * This function allocates the IOCTL request buffer, fills it
570 * with requisite parameters and calls the IOCTL handler.
571 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700572int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700573{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700574 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700575
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700576 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
577 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700578
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700579 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700580 if (priv->is_data_rate_auto)
581 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
582 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300583 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700584 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700585 }
586
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700587 return ret;
588}
589
590/*
591 * IOCTL request handler to set tx power configuration.
592 *
593 * This function prepares the correct firmware command and
594 * issues it.
595 *
596 * For non-auto power mode, all the following power groups are set -
597 * - Modulation class HR/DSSS
598 * - Modulation class OFDM
599 * - Modulation class HTBW20
600 * - Modulation class HTBW40
601 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700602int mwifiex_set_tx_power(struct mwifiex_private *priv,
603 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700604{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700605 int ret;
606 struct host_cmd_ds_txpwr_cfg *txp_cfg;
607 struct mwifiex_types_power_group *pg_tlv;
608 struct mwifiex_power_group *pg;
609 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700610 u16 dbm = 0;
611
612 if (!power_cfg->is_power_auto) {
613 dbm = (u16) power_cfg->power_level;
614 if ((dbm < priv->min_tx_power_level) ||
615 (dbm > priv->max_tx_power_level)) {
616 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700617 " is out of range (%d dBm-%d dBm)\n",
618 dbm, priv->min_tx_power_level,
619 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700620 return -1;
621 }
622 }
623 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000624 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200625 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700626
627 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
628 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
629 if (!power_cfg->is_power_auto) {
630 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700631 pg_tlv = (struct mwifiex_types_power_group *)
632 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633 pg_tlv->type = TLV_TYPE_POWER_GROUP;
634 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700635 pg = (struct mwifiex_power_group *)
636 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
637 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700638 /* Power group for modulation class HR/DSSS */
639 pg->first_rate_code = 0x00;
640 pg->last_rate_code = 0x03;
641 pg->modulation_class = MOD_CLASS_HR_DSSS;
642 pg->power_step = 0;
643 pg->power_min = (s8) dbm;
644 pg->power_max = (s8) dbm;
645 pg++;
646 /* Power group for modulation class OFDM */
647 pg->first_rate_code = 0x00;
648 pg->last_rate_code = 0x07;
649 pg->modulation_class = MOD_CLASS_OFDM;
650 pg->power_step = 0;
651 pg->power_min = (s8) dbm;
652 pg->power_max = (s8) dbm;
653 pg++;
654 /* Power group for modulation class HTBW20 */
655 pg->first_rate_code = 0x00;
656 pg->last_rate_code = 0x20;
657 pg->modulation_class = MOD_CLASS_HT;
658 pg->power_step = 0;
659 pg->power_min = (s8) dbm;
660 pg->power_max = (s8) dbm;
661 pg->ht_bandwidth = HT_BW_20;
662 pg++;
663 /* Power group for modulation class HTBW40 */
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_40;
671 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700672 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
673 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700674
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700675 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700676 return ret;
677}
678
679/*
680 * IOCTL request handler to get power save mode.
681 *
682 * This function prepares the correct firmware command and
683 * issues it.
684 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700685int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700686{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700687 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700688 struct mwifiex_adapter *adapter = priv->adapter;
689 u16 sub_cmd;
690
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700691 if (*ps_mode)
692 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
693 else
694 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
695 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
696 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
697 sub_cmd, BITMAP_STA_PS, NULL);
698 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
699 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700700 HostCmd_CMD_802_11_PS_MODE_ENH,
701 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700702
703 return ret;
704}
705
706/*
707 * IOCTL request handler to set/reset WPA IE.
708 *
709 * The supplied WPA IE is treated as a opaque buffer. Only the first field
710 * is checked to determine WPA version. If buffer length is zero, the existing
711 * WPA IE is reset.
712 */
713static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
714 u8 *ie_data_ptr, u16 ie_len)
715{
716 if (ie_len) {
717 if (ie_len > sizeof(priv->wpa_ie)) {
718 dev_err(priv->adapter->dev,
719 "failed to copy WPA IE, too big\n");
720 return -1;
721 }
722 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
723 priv->wpa_ie_len = (u8) ie_len;
724 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700725 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726
Arend van Spriel04b23122012-10-12 12:28:14 +0200727 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700728 priv->sec_info.wpa_enabled = true;
729 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
730 priv->sec_info.wpa2_enabled = true;
731 } else {
732 priv->sec_info.wpa_enabled = false;
733 priv->sec_info.wpa2_enabled = false;
734 }
735 } else {
736 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
737 priv->wpa_ie_len = 0;
738 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
739 priv->wpa_ie_len, priv->wpa_ie[0]);
740 priv->sec_info.wpa_enabled = false;
741 priv->sec_info.wpa2_enabled = false;
742 }
743
744 return 0;
745}
746
747/*
748 * IOCTL request handler to set/reset WAPI IE.
749 *
750 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
751 * is checked to internally enable WAPI. If buffer length is zero, the existing
752 * WAPI IE is reset.
753 */
754static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
755 u8 *ie_data_ptr, u16 ie_len)
756{
757 if (ie_len) {
758 if (ie_len > sizeof(priv->wapi_ie)) {
759 dev_dbg(priv->adapter->dev,
760 "info: failed to copy WAPI IE, too big\n");
761 return -1;
762 }
763 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
764 priv->wapi_ie_len = ie_len;
765 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700766 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700767
768 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
769 priv->sec_info.wapi_enabled = true;
770 } else {
771 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
772 priv->wapi_ie_len = ie_len;
773 dev_dbg(priv->adapter->dev,
774 "info: Reset wapi_ie_len=%d IE=%#x\n",
775 priv->wapi_ie_len, priv->wapi_ie[0]);
776 priv->sec_info.wapi_enabled = false;
777 }
778 return 0;
779}
780
781/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700782 * IOCTL request handler to set/reset WPS IE.
783 *
784 * The supplied WPS IE is treated as a opaque buffer. Only the first field
785 * is checked to internally enable WPS. If buffer length is zero, the existing
786 * WPS IE is reset.
787 */
788static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
789 u8 *ie_data_ptr, u16 ie_len)
790{
791 if (ie_len) {
792 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
793 if (!priv->wps_ie)
794 return -ENOMEM;
795 if (ie_len > sizeof(priv->wps_ie)) {
796 dev_dbg(priv->adapter->dev,
797 "info: failed to copy WPS IE, too big\n");
798 kfree(priv->wps_ie);
799 return -1;
800 }
801 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
802 priv->wps_ie_len = ie_len;
803 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
804 priv->wps_ie_len, priv->wps_ie[0]);
805 } else {
806 kfree(priv->wps_ie);
807 priv->wps_ie_len = ie_len;
808 dev_dbg(priv->adapter->dev,
809 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
810 }
811 return 0;
812}
813
814/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700815 * IOCTL request handler to set WAPI key.
816 *
817 * This function prepares the correct firmware command and
818 * issues it.
819 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700820static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700821 struct mwifiex_ds_encrypt_key *encrypt_key)
822{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700823
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700824 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700825 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
826 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700827}
828
829/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700830 * IOCTL request handler to set WEP network key.
831 *
832 * This function prepares the correct firmware command and
833 * issues it, after validation checks.
834 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700835static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700836 struct mwifiex_ds_encrypt_key *encrypt_key)
837{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700838 int ret;
839 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700840 int index;
841
842 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
843 priv->wep_key_curr_index = 0;
844 wep_key = &priv->wep_key[priv->wep_key_curr_index];
845 index = encrypt_key->key_index;
846 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800847 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848 } else if (!encrypt_key->key_len) {
849 /* Copy the required key as the current key */
850 wep_key = &priv->wep_key[index];
851 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700852 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700853 "key not set, so cannot enable it\n");
854 return -1;
855 }
856 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800857 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700858 } else {
859 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700860 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
861 /* Copy the key in the driver */
862 memcpy(wep_key->key_material,
863 encrypt_key->key_material,
864 encrypt_key->key_len);
865 wep_key->key_index = index;
866 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800867 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700868 }
869 if (wep_key->key_length) {
870 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700871 ret = mwifiex_send_cmd_async(priv,
872 HostCmd_CMD_802_11_KEY_MATERIAL,
873 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874 if (ret)
875 return ret;
876 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800877 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
879 else
880 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
881
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700882 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
883 HostCmd_ACT_GEN_SET, 0,
884 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885
886 return ret;
887}
888
889/*
890 * IOCTL request handler to set WPA key.
891 *
892 * This function prepares the correct firmware command and
893 * issues it, after validation checks.
894 *
895 * Current driver only supports key length of up to 32 bytes.
896 *
897 * This function can also be used to disable a currently set key.
898 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700899static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700900 struct mwifiex_ds_encrypt_key *encrypt_key)
901{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700902 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700903 u8 remove_key = false;
904 struct host_cmd_ds_802_11_key_material *ibss_key;
905
906 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700907 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700908 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700909 return -1;
910 }
911
Bing Zhaoeecd8252011-03-28 17:55:41 -0700912 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700913 /*
914 * IBSS/WPA-None uses only one key (Group) for both receiving
915 * and sending unicast and multicast packets.
916 */
917 /* Send the key as PTK to firmware */
918 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700919 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700920 HostCmd_CMD_802_11_KEY_MATERIAL,
921 HostCmd_ACT_GEN_SET,
922 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700923 if (ret)
924 return ret;
925
926 ibss_key = &priv->aes_key;
927 memset(ibss_key, 0,
928 sizeof(struct host_cmd_ds_802_11_key_material));
929 /* Copy the key in the driver */
930 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
931 encrypt_key->key_len);
932 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
933 sizeof(ibss_key->key_param_set.key_len));
934 ibss_key->key_param_set.key_type_id
935 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700936 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700937
938 /* Send the key as GTK to firmware */
939 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
940 }
941
942 if (!encrypt_key->key_index)
943 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
944
945 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700946 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700947 HostCmd_CMD_802_11_KEY_MATERIAL,
948 HostCmd_ACT_GEN_SET,
949 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700950 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700951 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700952 HostCmd_CMD_802_11_KEY_MATERIAL,
953 HostCmd_ACT_GEN_SET,
954 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700955
956 return ret;
957}
958
959/*
960 * IOCTL request handler to set/get network keys.
961 *
962 * This is a generic key handling function which supports WEP, WPA
963 * and WAPI.
964 */
965static int
966mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700967 struct mwifiex_ds_encrypt_key *encrypt_key)
968{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700969 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700970
971 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700972 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700973 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700974 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700975 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700976 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700977 return status;
978}
979
980/*
981 * This function returns the driver version.
982 */
983int
984mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
985 int max_len)
986{
987 union {
988 u32 l;
989 u8 c[4];
990 } ver;
991 char fw_ver[32];
992
993 ver.l = adapter->fw_release_number;
994 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
995
996 snprintf(version, max_len, driver_version, fw_ver);
997
998 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
999
1000 return 0;
1001}
1002
1003/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001004 * Sends IOCTL request to set encoding parameters.
1005 *
1006 * This function allocates the IOCTL request buffer, fills it
1007 * with requisite parameters and calls the IOCTL handler.
1008 */
Ying Luo53b11232012-08-03 18:06:13 -07001009int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1010 const u8 *key, int key_len, u8 key_index,
1011 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001012{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001013 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001014
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1016 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001017
1018 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1019 encrypt_key.is_igtk_key = true;
1020
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001021 if (!disable) {
1022 encrypt_key.key_index = key_index;
1023 if (key_len)
1024 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001025 if (mac_addr)
1026 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001027 if (kp && kp->seq && kp->seq_len)
1028 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001029 } else {
1030 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001031 if (mac_addr)
1032 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001033 }
1034
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001035 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001036}
1037
1038/*
1039 * Sends IOCTL request to get extended version.
1040 *
1041 * This function allocates the IOCTL request buffer, fills it
1042 * with requisite parameters and calls the IOCTL handler.
1043 */
1044int
1045mwifiex_get_ver_ext(struct mwifiex_private *priv)
1046{
1047 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001048
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001049 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001050 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001051 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001052 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001053
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001054 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001055}
1056
Stone Piao7feb4c42012-09-25 20:23:36 -07001057int
1058mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1059 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001060 unsigned int duration)
1061{
1062 struct host_cmd_ds_remain_on_chan roc_cfg;
1063 u8 sc;
1064
1065 memset(&roc_cfg, 0, sizeof(roc_cfg));
1066 roc_cfg.action = cpu_to_le16(action);
1067 if (action == HostCmd_ACT_GEN_SET) {
1068 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001069 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001070 roc_cfg.band_cfg |= (sc << 2);
1071
1072 roc_cfg.channel =
1073 ieee80211_frequency_to_channel(chan->center_freq);
1074 roc_cfg.duration = cpu_to_le32(duration);
1075 }
1076 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1077 action, 0, &roc_cfg)) {
1078 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1079 return -1;
1080 }
1081
1082 return roc_cfg.status;
1083}
1084
Stone Piao9197ab92012-09-25 20:23:42 -07001085int
1086mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1087{
1088 if (GET_BSS_ROLE(priv) == bss_role) {
1089 dev_dbg(priv->adapter->dev,
1090 "info: already in the desired role.\n");
1091 return 0;
1092 }
1093
1094 mwifiex_free_priv(priv);
1095 mwifiex_init_priv(priv);
1096
1097 priv->bss_role = bss_role;
1098 switch (bss_role) {
1099 case MWIFIEX_BSS_ROLE_UAP:
1100 priv->bss_mode = NL80211_IFTYPE_AP;
1101 break;
1102 case MWIFIEX_BSS_ROLE_STA:
1103 case MWIFIEX_BSS_ROLE_ANY:
1104 default:
1105 priv->bss_mode = NL80211_IFTYPE_STATION;
1106 break;
1107 }
1108
1109 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1110 HostCmd_ACT_GEN_SET, 0, NULL);
1111
1112 return mwifiex_sta_init_cmd(priv, false);
1113}
1114
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001115/*
1116 * Sends IOCTL request to get statistics information.
1117 *
1118 * This function allocates the IOCTL request buffer, fills it
1119 * with requisite parameters and calls the IOCTL handler.
1120 */
1121int
1122mwifiex_get_stats_info(struct mwifiex_private *priv,
1123 struct mwifiex_ds_get_stats *log)
1124{
Bing Zhao67a50032011-07-13 18:38:34 -07001125 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001126 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001127}
1128
1129/*
1130 * IOCTL request handler to read/write register.
1131 *
1132 * This function prepares the correct firmware command and
1133 * issues it.
1134 *
1135 * Access to the following registers are supported -
1136 * - MAC
1137 * - BBP
1138 * - RF
1139 * - PMIC
1140 * - CAU
1141 */
1142static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001143 struct mwifiex_ds_reg_rw *reg_rw,
1144 u16 action)
1145{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001146 u16 cmd_no;
1147
1148 switch (le32_to_cpu(reg_rw->type)) {
1149 case MWIFIEX_REG_MAC:
1150 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1151 break;
1152 case MWIFIEX_REG_BBP:
1153 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1154 break;
1155 case MWIFIEX_REG_RF:
1156 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1157 break;
1158 case MWIFIEX_REG_PMIC:
1159 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1160 break;
1161 case MWIFIEX_REG_CAU:
1162 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1163 break;
1164 default:
1165 return -1;
1166 }
1167
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001168 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001169
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001170}
1171
1172/*
1173 * Sends IOCTL request to write to a register.
1174 *
1175 * This function allocates the IOCTL request buffer, fills it
1176 * with requisite parameters and calls the IOCTL handler.
1177 */
1178int
1179mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1180 u32 reg_offset, u32 reg_value)
1181{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001182 struct mwifiex_ds_reg_rw reg_rw;
1183
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001184 reg_rw.type = cpu_to_le32(reg_type);
1185 reg_rw.offset = cpu_to_le32(reg_offset);
1186 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001188 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001189}
1190
1191/*
1192 * Sends IOCTL request to read from a register.
1193 *
1194 * This function allocates the IOCTL request buffer, fills it
1195 * with requisite parameters and calls the IOCTL handler.
1196 */
1197int
1198mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1199 u32 reg_offset, u32 *value)
1200{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001201 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 struct mwifiex_ds_reg_rw reg_rw;
1203
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001204 reg_rw.type = cpu_to_le32(reg_type);
1205 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001206 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001208 if (ret)
1209 goto done;
1210
1211 *value = le32_to_cpu(reg_rw.value);
1212
1213done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001214 return ret;
1215}
1216
1217/*
1218 * Sends IOCTL request to read from EEPROM.
1219 *
1220 * This function allocates the IOCTL request buffer, fills it
1221 * with requisite parameters and calls the IOCTL handler.
1222 */
1223int
1224mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1225 u8 *value)
1226{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001227 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001228 struct mwifiex_ds_read_eeprom rd_eeprom;
1229
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001230 rd_eeprom.offset = cpu_to_le16((u16) offset);
1231 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001233 /* Send request to firmware */
1234 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1235 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001236
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001237 if (!ret)
1238 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239 return ret;
1240}
1241
1242/*
1243 * This function sets a generic IE. In addition to generic IE, it can
1244 * also handle WPA, WPA2 and WAPI IEs.
1245 */
1246static int
1247mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1248 u16 ie_len)
1249{
1250 int ret = 0;
1251 struct ieee_types_vendor_header *pvendor_ie;
1252 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1253 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1254
1255 /* If the passed length is zero, reset the buffer */
1256 if (!ie_len) {
1257 priv->gen_ie_buf_len = 0;
1258 priv->wps.session_enable = false;
1259
1260 return 0;
1261 } else if (!ie_data_ptr) {
1262 return -1;
1263 }
1264 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1265 /* 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 +02001266 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001267 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1268 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001269
1270 /* IE is a WPA/WPA2 IE so call set_wpa function */
1271 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1272 priv->wps.session_enable = false;
1273
1274 return ret;
1275 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1276 /* IE is a WAPI IE so call set_wapi function */
1277 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1278
1279 return ret;
1280 }
1281 /*
1282 * Verify that the passed length is not larger than the
1283 * available space remaining in the buffer
1284 */
1285 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1286
1287 /* Test to see if it is a WPS IE, if so, enable
1288 * wps session flag
1289 */
1290 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001291 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1292 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001293 priv->wps.session_enable = true;
1294 dev_dbg(priv->adapter->dev,
1295 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001296 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001297 }
1298
1299 /* Append the passed data to the end of the
1300 genIeBuffer */
1301 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001302 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001303 /* Increment the stored buffer length by the
1304 size passed */
1305 priv->gen_ie_buf_len += ie_len;
1306 } else {
1307 /* Passed data does not fit in the remaining
1308 buffer space */
1309 ret = -1;
1310 }
1311
1312 /* Return 0, or -1 for error case */
1313 return ret;
1314}
1315
1316/*
1317 * IOCTL request handler to set/get generic IE.
1318 *
1319 * In addition to various generic IEs, this function can also be
1320 * used to set the ARP filter.
1321 */
1322static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1323 struct mwifiex_ds_misc_gen_ie *gen_ie,
1324 u16 action)
1325{
1326 struct mwifiex_adapter *adapter = priv->adapter;
1327
1328 switch (gen_ie->type) {
1329 case MWIFIEX_IE_TYPE_GEN_IE:
1330 if (action == HostCmd_ACT_GEN_GET) {
1331 gen_ie->len = priv->wpa_ie_len;
1332 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1333 } else {
1334 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1335 (u16) gen_ie->len);
1336 }
1337 break;
1338 case MWIFIEX_IE_TYPE_ARP_FILTER:
1339 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1340 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1341 adapter->arp_filter_size = 0;
1342 dev_err(adapter->dev, "invalid ARP filter size\n");
1343 return -1;
1344 } else {
1345 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001346 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001347 adapter->arp_filter_size = gen_ie->len;
1348 }
1349 break;
1350 default:
1351 dev_err(adapter->dev, "invalid IE type\n");
1352 return -1;
1353 }
1354 return 0;
1355}
1356
1357/*
1358 * Sends IOCTL request to set a generic IE.
1359 *
1360 * This function allocates the IOCTL request buffer, fills it
1361 * with requisite parameters and calls the IOCTL handler.
1362 */
1363int
1364mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1365{
1366 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001367
Bing Zhao67a50032011-07-13 18:38:34 -07001368 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001369 return -EFAULT;
1370
1371 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1372 gen_ie.len = ie_len;
1373 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001374 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001375 return -EFAULT;
1376
1377 return 0;
1378}