blob: 0a9f59c5ab5afca5bc327a691e632964d2597abc [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;
Daniel Drake9e65b302013-06-14 15:24:24 -0400107 dev_dbg(priv->adapter->dev,
108 "info: Set multicast list=%d\n",
109 mcast_list->num_multicast_addr);
110 /* Send multicast addresses to firmware */
111 ret = mwifiex_send_cmd_async(priv,
112 HostCmd_CMD_MAC_MULTICAST_ADR,
113 HostCmd_ACT_GEN_SET, 0,
114 mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700115 }
116 }
117 dev_dbg(priv->adapter->dev,
118 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
119 old_pkt_filter, priv->curr_pkt_filter);
120 if (old_pkt_filter != priv->curr_pkt_filter) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700121 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
122 HostCmd_ACT_GEN_SET,
123 0, &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124 }
125
126 return ret;
127}
128
129/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700130 * This function fills bss descriptor structure using provided
131 * information.
Bing Zhaod837a2a2013-04-12 10:34:17 -0700132 * beacon_ie buffer is allocated in this function. It is caller's
133 * responsibility to free the memory.
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700134 */
135int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700136 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700137 struct mwifiex_bssdescriptor *bss_desc)
138{
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700139 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500140 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700141 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100142 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700143
Johannes Berg9caf0362012-11-29 01:25:20 +0100144 rcu_read_lock();
145 ies = rcu_dereference(bss->ies);
Johannes Berg9caf0362012-11-29 01:25:20 +0100146 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
147 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100148 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100149 rcu_read_unlock();
150
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700151 if (!beacon_ie) {
152 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
153 return -ENOMEM;
154 }
155
156 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
157 bss_desc->rssi = bss->signal;
Bing Zhaod837a2a2013-04-12 10:34:17 -0700158 /* The caller of this function will free beacon_ie */
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700159 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100160 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700161 bss_desc->beacon_period = bss->beacon_interval;
162 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700163 bss_desc->bss_band = bss_priv->band;
164 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700165 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
166 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
167 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
168 } else {
169 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
170 }
171 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
172 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
173 else
174 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
175
Bing Zhaoc43933e2013-04-12 10:34:18 -0700176 /* Disable 11ac by default. Enable it only where there
177 * exist VHT_CAP IE in AP beacon
178 */
179 bss_desc->disable_11ac = true;
180
Bing Zhaod837a2a2013-04-12 10:34:17 -0700181 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700182}
183
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700184static int mwifiex_process_country_ie(struct mwifiex_private *priv,
185 struct cfg80211_bss *bss)
186{
Johannes Berg9caf0362012-11-29 01:25:20 +0100187 const u8 *country_ie;
188 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700189 struct mwifiex_802_11d_domain_reg *domain_info =
190 &priv->adapter->domain_reg;
191
Johannes Berg9caf0362012-11-29 01:25:20 +0100192 rcu_read_lock();
193 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
194 if (!country_ie) {
195 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700196 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100197 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700198
199 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100200 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
201 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700202 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100203 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700204
205 domain_info->country_code[0] = country_ie[2];
206 domain_info->country_code[1] = country_ie[3];
207 domain_info->country_code[2] = ' ';
208
209 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
210
211 domain_info->no_of_triplet =
212 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
213
214 memcpy((u8 *)domain_info->triplet,
215 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
216
Johannes Berg9caf0362012-11-29 01:25:20 +0100217 rcu_read_unlock();
218
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700219 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
220 HostCmd_ACT_GEN_SET, 0, NULL)) {
221 wiphy_err(priv->adapter->wiphy,
222 "11D: setting domain info in FW\n");
223 return -1;
224 }
225
226 return 0;
227}
228
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700229/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700230 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
231 * In both Ad-Hoc and infra mode, an deauthentication is performed
232 * first.
233 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700234int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800235 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700236{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700237 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700238 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700239 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700240
241 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700242
243 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700244 mwifiex_process_country_ie(priv, bss);
245
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700246 /* Allocate and fill new bss descriptor */
247 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000248 GFP_KERNEL);
249 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700250 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700251
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700252 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700253 if (ret)
254 goto done;
255 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700256
Bing Zhaoeecd8252011-03-28 17:55:41 -0700257 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700259 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700260 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700261 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700262
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800263 if (bss_desc) {
264 u8 config_bands = 0;
265
266 if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band)
267 == HostCmd_SCAN_RADIO_TYPE_BG)
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800268 config_bands = BAND_B | BAND_G | BAND_GN |
269 BAND_GAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800270 else
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -0800271 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800272
273 if (!((config_bands | adapter->fw_bands) &
274 ~adapter->fw_bands))
275 adapter->config_bands = config_bands;
276 }
277
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700278 ret = mwifiex_check_network_compatibility(priv, bss_desc);
279 if (ret)
280 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700281
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700282 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
283 "associating...\n");
284
Avinash Patil47411a02012-11-01 18:44:16 -0700285 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800286 if (netif_carrier_ok(priv->netdev))
287 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700288
289 /* Clear any past association response stored for
290 * application retrieval */
291 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700292 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800293
294 /* If auth type is auto and association fails using open mode,
295 * try to connect using shared mode */
296 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
297 priv->sec_info.is_authtype_auto &&
298 priv->sec_info.wep_enabled) {
299 priv->sec_info.authentication_mode =
300 NL80211_AUTHTYPE_SHARED_KEY;
301 ret = mwifiex_associate(priv, bss_desc);
302 }
303
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700304 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100305 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700306 } else {
307 /* Adhoc mode */
308 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700309 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700310 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
311 ssid, &bss_desc->ssid))) {
Ujjal Roy4798e3b2013-11-21 11:08:56 -0800312 ret = 0;
313 goto done;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700314 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700315
316 /* Exit Adhoc mode first */
317 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700318 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700319 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700320 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700321
322 priv->adhoc_is_link_sensed = false;
323
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700324 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700325
Avinash Patil47411a02012-11-01 18:44:16 -0700326 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800327 if (netif_carrier_ok(priv->netdev))
328 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700329
330 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 dev_dbg(adapter->dev, "info: network found in scan"
332 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700333 ret = mwifiex_adhoc_join(priv, bss_desc);
334 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100335 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700336 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337 dev_dbg(adapter->dev, "info: Network not found in "
338 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700339 req_ssid->ssid);
340 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700341 }
342 }
343
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700344done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700345 /* beacon_ie buffer was allocated in function
346 * mwifiex_fill_new_bss_desc(). Free it now.
347 */
348 if (bss_desc)
349 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700350 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700351 return ret;
352}
353
354/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355 * IOCTL request handler to set host sleep configuration.
356 *
357 * This function prepares the correct firmware command and
358 * issues it.
359 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700360static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
361 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700362
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700363{
364 struct mwifiex_adapter *adapter = priv->adapter;
365 int status = 0;
366 u32 prev_cond = 0;
367
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700368 if (!hs_cfg)
369 return -ENOMEM;
370
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371 switch (action) {
372 case HostCmd_ACT_GEN_SET:
373 if (adapter->pps_uapsd_mode) {
374 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
375 " is blocked in UAPSD/PPS mode\n");
376 status = -1;
377 break;
378 }
379 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800380 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700381 if (!adapter->is_hs_configured)
382 /* Already cancelled */
383 break;
384 /* Save previous condition */
385 prev_cond = le32_to_cpu(adapter->hs_cfg
386 .conditions);
387 adapter->hs_cfg.conditions =
388 cpu_to_le32(hs_cfg->conditions);
389 } else if (hs_cfg->conditions) {
390 adapter->hs_cfg.conditions =
391 cpu_to_le32(hs_cfg->conditions);
392 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
393 if (hs_cfg->gap)
394 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800395 } else if (adapter->hs_cfg.conditions ==
396 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700397 /* Return failure if no parameters for HS
398 enable */
399 status = -1;
400 break;
401 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700402 if (cmd_type == MWIFIEX_SYNC_CMD)
403 status = mwifiex_send_cmd_sync(priv,
404 HostCmd_CMD_802_11_HS_CFG_ENH,
405 HostCmd_ACT_GEN_SET, 0,
406 &adapter->hs_cfg);
407 else
408 status = mwifiex_send_cmd_async(priv,
409 HostCmd_CMD_802_11_HS_CFG_ENH,
410 HostCmd_ACT_GEN_SET, 0,
411 &adapter->hs_cfg);
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800412 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700413 /* Restore previous condition */
414 adapter->hs_cfg.conditions =
415 cpu_to_le32(prev_cond);
416 } else {
417 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700418 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700419 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
420 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
421 }
422 break;
423 case HostCmd_ACT_GEN_GET:
424 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
425 hs_cfg->gpio = adapter->hs_cfg.gpio;
426 hs_cfg->gap = adapter->hs_cfg.gap;
427 break;
428 default:
429 status = -1;
430 break;
431 }
432
433 return status;
434}
435
436/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700437 * Sends IOCTL request to cancel the existing Host Sleep configuration.
438 *
439 * This function allocates the IOCTL request buffer, fills it
440 * with requisite parameters and calls the IOCTL handler.
441 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700442int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700443{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700444 struct mwifiex_ds_hs_cfg hscfg;
445
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800446 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700447 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700449 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
450 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700451}
452EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
453
454/*
455 * Sends IOCTL request to cancel the existing Host Sleep configuration.
456 *
457 * This function allocates the IOCTL request buffer, fills it
458 * with requisite parameters and calls the IOCTL handler.
459 */
460int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
461{
462 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700463 struct mwifiex_private *priv;
464 int i;
465
466 if (disconnect_on_suspend) {
467 for (i = 0; i < adapter->priv_num; i++) {
468 priv = adapter->priv[i];
469 if (priv)
470 mwifiex_deauthenticate(priv, NULL);
471 }
472 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473
474 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900475 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476 return true;
477 }
478
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700479 adapter->hs_activate_wait_q_woken = false;
480
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700481 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700482 hscfg.is_invoke_hostcmd = true;
483
484 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700485 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700486 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
487 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700488 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
489 return false;
490 }
491
Bing Zhao9c969d82013-01-02 16:07:35 -0800492 if (wait_event_interruptible(adapter->hs_activate_wait_q,
493 adapter->hs_activate_wait_q_woken)) {
494 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
495 return false;
496 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700497
498 return true;
499}
500EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
501
502/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700503 * IOCTL request handler to get BSS information.
504 *
505 * This function collates the information from different driver structures
506 * to send to the user.
507 */
508int mwifiex_get_bss_info(struct mwifiex_private *priv,
509 struct mwifiex_bss_info *info)
510{
511 struct mwifiex_adapter *adapter = priv->adapter;
512 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700513
514 if (!info)
515 return -1;
516
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700517 bss_desc = &priv->curr_bss_params.bss_descriptor;
518
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700519 info->bss_mode = priv->bss_mode;
520
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800521 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700522
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
524
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700525 info->bss_chan = bss_desc->channel;
526
Avinash Patil67fdf392012-05-08 18:30:17 -0700527 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700528 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700529
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700530 info->media_connected = priv->media_connected;
531
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700532 info->max_power_level = priv->max_tx_power_level;
533 info->min_power_level = priv->min_tx_power_level;
534
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535 info->adhoc_state = priv->adhoc_state;
536
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537 info->bcn_nf_last = priv->bcn_nf_last;
538
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800539 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700540 info->wep_status = true;
541 else
542 info->wep_status = false;
543
544 info->is_hs_configured = adapter->is_hs_configured;
545 info->is_deep_sleep = adapter->is_deep_sleep;
546
547 return 0;
548}
549
550/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700551 * The function disables auto deep sleep mode.
552 */
553int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
554{
555 struct mwifiex_ds_auto_ds auto_ds;
556
557 auto_ds.auto_ds = DEEP_SLEEP_OFF;
558
559 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
560 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
561}
562EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
563
564/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 * Sends IOCTL request to get the data rate.
566 *
567 * This function allocates the IOCTL request buffer, fills it
568 * with requisite parameters and calls the IOCTL handler.
569 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700570int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700571{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700572 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700573
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700574 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
575 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700576
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700577 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700578 if (priv->is_data_rate_auto)
579 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
580 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300581 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700582 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700583 }
584
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700585 return ret;
586}
587
588/*
589 * IOCTL request handler to set tx power configuration.
590 *
591 * This function prepares the correct firmware command and
592 * issues it.
593 *
594 * For non-auto power mode, all the following power groups are set -
595 * - Modulation class HR/DSSS
596 * - Modulation class OFDM
597 * - Modulation class HTBW20
598 * - Modulation class HTBW40
599 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700600int mwifiex_set_tx_power(struct mwifiex_private *priv,
601 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700603 int ret;
604 struct host_cmd_ds_txpwr_cfg *txp_cfg;
605 struct mwifiex_types_power_group *pg_tlv;
606 struct mwifiex_power_group *pg;
607 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608 u16 dbm = 0;
609
610 if (!power_cfg->is_power_auto) {
611 dbm = (u16) power_cfg->power_level;
612 if ((dbm < priv->min_tx_power_level) ||
613 (dbm > priv->max_tx_power_level)) {
614 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700615 " is out of range (%d dBm-%d dBm)\n",
616 dbm, priv->min_tx_power_level,
617 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700618 return -1;
619 }
620 }
621 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000622 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200623 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700624
625 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
626 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
627 if (!power_cfg->is_power_auto) {
628 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700629 pg_tlv = (struct mwifiex_types_power_group *)
630 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700631 pg_tlv->type = TLV_TYPE_POWER_GROUP;
632 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700633 pg = (struct mwifiex_power_group *)
634 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
635 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700636 /* Power group for modulation class HR/DSSS */
637 pg->first_rate_code = 0x00;
638 pg->last_rate_code = 0x03;
639 pg->modulation_class = MOD_CLASS_HR_DSSS;
640 pg->power_step = 0;
641 pg->power_min = (s8) dbm;
642 pg->power_max = (s8) dbm;
643 pg++;
644 /* Power group for modulation class OFDM */
645 pg->first_rate_code = 0x00;
646 pg->last_rate_code = 0x07;
647 pg->modulation_class = MOD_CLASS_OFDM;
648 pg->power_step = 0;
649 pg->power_min = (s8) dbm;
650 pg->power_max = (s8) dbm;
651 pg++;
652 /* Power group for modulation class HTBW20 */
653 pg->first_rate_code = 0x00;
654 pg->last_rate_code = 0x20;
655 pg->modulation_class = MOD_CLASS_HT;
656 pg->power_step = 0;
657 pg->power_min = (s8) dbm;
658 pg->power_max = (s8) dbm;
659 pg->ht_bandwidth = HT_BW_20;
660 pg++;
661 /* Power group for modulation class HTBW40 */
662 pg->first_rate_code = 0x00;
663 pg->last_rate_code = 0x20;
664 pg->modulation_class = MOD_CLASS_HT;
665 pg->power_step = 0;
666 pg->power_min = (s8) dbm;
667 pg->power_max = (s8) dbm;
668 pg->ht_bandwidth = HT_BW_40;
669 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700670 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
671 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700672
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700673 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700674 return ret;
675}
676
677/*
678 * IOCTL request handler to get power save mode.
679 *
680 * This function prepares the correct firmware command and
681 * issues it.
682 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700683int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700684{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700685 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700686 struct mwifiex_adapter *adapter = priv->adapter;
687 u16 sub_cmd;
688
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700689 if (*ps_mode)
690 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
691 else
692 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
693 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
694 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
695 sub_cmd, BITMAP_STA_PS, NULL);
696 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
697 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700698 HostCmd_CMD_802_11_PS_MODE_ENH,
699 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700700
701 return ret;
702}
703
704/*
705 * IOCTL request handler to set/reset WPA IE.
706 *
707 * The supplied WPA IE is treated as a opaque buffer. Only the first field
708 * is checked to determine WPA version. If buffer length is zero, the existing
709 * WPA IE is reset.
710 */
711static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
712 u8 *ie_data_ptr, u16 ie_len)
713{
714 if (ie_len) {
715 if (ie_len > sizeof(priv->wpa_ie)) {
716 dev_err(priv->adapter->dev,
717 "failed to copy WPA IE, too big\n");
718 return -1;
719 }
720 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
721 priv->wpa_ie_len = (u8) ie_len;
722 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700723 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700724
Arend van Spriel04b23122012-10-12 12:28:14 +0200725 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726 priv->sec_info.wpa_enabled = true;
727 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
728 priv->sec_info.wpa2_enabled = true;
729 } else {
730 priv->sec_info.wpa_enabled = false;
731 priv->sec_info.wpa2_enabled = false;
732 }
733 } else {
734 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
735 priv->wpa_ie_len = 0;
736 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
737 priv->wpa_ie_len, priv->wpa_ie[0]);
738 priv->sec_info.wpa_enabled = false;
739 priv->sec_info.wpa2_enabled = false;
740 }
741
742 return 0;
743}
744
745/*
746 * IOCTL request handler to set/reset WAPI IE.
747 *
748 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
749 * is checked to internally enable WAPI. If buffer length is zero, the existing
750 * WAPI IE is reset.
751 */
752static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
753 u8 *ie_data_ptr, u16 ie_len)
754{
755 if (ie_len) {
756 if (ie_len > sizeof(priv->wapi_ie)) {
757 dev_dbg(priv->adapter->dev,
758 "info: failed to copy WAPI IE, too big\n");
759 return -1;
760 }
761 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
762 priv->wapi_ie_len = ie_len;
763 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700764 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700765
766 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
767 priv->sec_info.wapi_enabled = true;
768 } else {
769 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
770 priv->wapi_ie_len = ie_len;
771 dev_dbg(priv->adapter->dev,
772 "info: Reset wapi_ie_len=%d IE=%#x\n",
773 priv->wapi_ie_len, priv->wapi_ie[0]);
774 priv->sec_info.wapi_enabled = false;
775 }
776 return 0;
777}
778
779/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700780 * IOCTL request handler to set/reset WPS IE.
781 *
782 * The supplied WPS IE is treated as a opaque buffer. Only the first field
783 * is checked to internally enable WPS. If buffer length is zero, the existing
784 * WPS IE is reset.
785 */
786static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
787 u8 *ie_data_ptr, u16 ie_len)
788{
789 if (ie_len) {
790 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
791 if (!priv->wps_ie)
792 return -ENOMEM;
793 if (ie_len > sizeof(priv->wps_ie)) {
794 dev_dbg(priv->adapter->dev,
795 "info: failed to copy WPS IE, too big\n");
796 kfree(priv->wps_ie);
797 return -1;
798 }
799 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
800 priv->wps_ie_len = ie_len;
801 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
802 priv->wps_ie_len, priv->wps_ie[0]);
803 } else {
804 kfree(priv->wps_ie);
805 priv->wps_ie_len = ie_len;
806 dev_dbg(priv->adapter->dev,
807 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
808 }
809 return 0;
810}
811
812/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700813 * IOCTL request handler to set WAPI key.
814 *
815 * This function prepares the correct firmware command and
816 * issues it.
817 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700818static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700819 struct mwifiex_ds_encrypt_key *encrypt_key)
820{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700821
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700822 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700823 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
824 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825}
826
827/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700828 * IOCTL request handler to set WEP network key.
829 *
830 * This function prepares the correct firmware command and
831 * issues it, after validation checks.
832 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700833static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700834 struct mwifiex_ds_encrypt_key *encrypt_key)
835{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700836 int ret;
837 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700838 int index;
839
840 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
841 priv->wep_key_curr_index = 0;
842 wep_key = &priv->wep_key[priv->wep_key_curr_index];
843 index = encrypt_key->key_index;
844 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800845 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700846 } else if (!encrypt_key->key_len) {
847 /* Copy the required key as the current key */
848 wep_key = &priv->wep_key[index];
849 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700850 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700851 "key not set, so cannot enable it\n");
852 return -1;
853 }
854 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800855 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700856 } else {
857 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700858 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
859 /* Copy the key in the driver */
860 memcpy(wep_key->key_material,
861 encrypt_key->key_material,
862 encrypt_key->key_len);
863 wep_key->key_index = index;
864 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800865 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700866 }
867 if (wep_key->key_length) {
868 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700869 ret = mwifiex_send_cmd_async(priv,
870 HostCmd_CMD_802_11_KEY_MATERIAL,
871 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872 if (ret)
873 return ret;
874 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800875 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700876 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
877 else
878 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
879
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700880 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
881 HostCmd_ACT_GEN_SET, 0,
882 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700883
884 return ret;
885}
886
887/*
888 * IOCTL request handler to set WPA key.
889 *
890 * This function prepares the correct firmware command and
891 * issues it, after validation checks.
892 *
893 * Current driver only supports key length of up to 32 bytes.
894 *
895 * This function can also be used to disable a currently set key.
896 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700897static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898 struct mwifiex_ds_encrypt_key *encrypt_key)
899{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700900 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700901 u8 remove_key = false;
902 struct host_cmd_ds_802_11_key_material *ibss_key;
903
904 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700905 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700906 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700907 return -1;
908 }
909
Bing Zhaoeecd8252011-03-28 17:55:41 -0700910 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700911 /*
912 * IBSS/WPA-None uses only one key (Group) for both receiving
913 * and sending unicast and multicast packets.
914 */
915 /* Send the key as PTK to firmware */
916 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700917 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700918 HostCmd_CMD_802_11_KEY_MATERIAL,
919 HostCmd_ACT_GEN_SET,
920 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700921 if (ret)
922 return ret;
923
924 ibss_key = &priv->aes_key;
925 memset(ibss_key, 0,
926 sizeof(struct host_cmd_ds_802_11_key_material));
927 /* Copy the key in the driver */
928 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
929 encrypt_key->key_len);
930 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
931 sizeof(ibss_key->key_param_set.key_len));
932 ibss_key->key_param_set.key_type_id
933 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700934 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700935
936 /* Send the key as GTK to firmware */
937 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
938 }
939
940 if (!encrypt_key->key_index)
941 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
942
943 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700944 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700945 HostCmd_CMD_802_11_KEY_MATERIAL,
946 HostCmd_ACT_GEN_SET,
947 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700948 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700949 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700950 HostCmd_CMD_802_11_KEY_MATERIAL,
951 HostCmd_ACT_GEN_SET,
952 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700953
954 return ret;
955}
956
957/*
958 * IOCTL request handler to set/get network keys.
959 *
960 * This is a generic key handling function which supports WEP, WPA
961 * and WAPI.
962 */
963static int
964mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700965 struct mwifiex_ds_encrypt_key *encrypt_key)
966{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700967 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700968
969 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700970 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700971 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700972 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700973 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700974 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700975 return status;
976}
977
978/*
979 * This function returns the driver version.
980 */
981int
982mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
983 int max_len)
984{
985 union {
986 u32 l;
987 u8 c[4];
988 } ver;
989 char fw_ver[32];
990
991 ver.l = adapter->fw_release_number;
992 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
993
994 snprintf(version, max_len, driver_version, fw_ver);
995
996 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
997
998 return 0;
999}
1000
1001/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001002 * Sends IOCTL request to set encoding parameters.
1003 *
1004 * This function allocates the IOCTL request buffer, fills it
1005 * with requisite parameters and calls the IOCTL handler.
1006 */
Ying Luo53b11232012-08-03 18:06:13 -07001007int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1008 const u8 *key, int key_len, u8 key_index,
1009 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001010{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001011 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001012
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001013 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1014 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001015
1016 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1017 encrypt_key.is_igtk_key = true;
1018
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001019 if (!disable) {
1020 encrypt_key.key_index = key_index;
1021 if (key_len)
1022 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001023 if (mac_addr)
1024 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001025 if (kp && kp->seq && kp->seq_len)
1026 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001027 } else {
1028 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001029 if (mac_addr)
1030 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001031 }
1032
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001033 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001034}
1035
1036/*
1037 * Sends IOCTL request to get extended version.
1038 *
1039 * This function allocates the IOCTL request buffer, fills it
1040 * with requisite parameters and calls the IOCTL handler.
1041 */
1042int
1043mwifiex_get_ver_ext(struct mwifiex_private *priv)
1044{
1045 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001046
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001047 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001048 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001049 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001050 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001051
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001052 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001053}
1054
Stone Piao7feb4c42012-09-25 20:23:36 -07001055int
1056mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1057 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001058 unsigned int duration)
1059{
1060 struct host_cmd_ds_remain_on_chan roc_cfg;
1061 u8 sc;
1062
1063 memset(&roc_cfg, 0, sizeof(roc_cfg));
1064 roc_cfg.action = cpu_to_le16(action);
1065 if (action == HostCmd_ACT_GEN_SET) {
1066 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001067 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001068 roc_cfg.band_cfg |= (sc << 2);
1069
1070 roc_cfg.channel =
1071 ieee80211_frequency_to_channel(chan->center_freq);
1072 roc_cfg.duration = cpu_to_le32(duration);
1073 }
1074 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1075 action, 0, &roc_cfg)) {
1076 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1077 return -1;
1078 }
1079
1080 return roc_cfg.status;
1081}
1082
Stone Piao9197ab92012-09-25 20:23:42 -07001083int
1084mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1085{
1086 if (GET_BSS_ROLE(priv) == bss_role) {
1087 dev_dbg(priv->adapter->dev,
1088 "info: already in the desired role.\n");
1089 return 0;
1090 }
1091
1092 mwifiex_free_priv(priv);
1093 mwifiex_init_priv(priv);
1094
1095 priv->bss_role = bss_role;
1096 switch (bss_role) {
1097 case MWIFIEX_BSS_ROLE_UAP:
1098 priv->bss_mode = NL80211_IFTYPE_AP;
1099 break;
1100 case MWIFIEX_BSS_ROLE_STA:
1101 case MWIFIEX_BSS_ROLE_ANY:
1102 default:
1103 priv->bss_mode = NL80211_IFTYPE_STATION;
1104 break;
1105 }
1106
1107 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1108 HostCmd_ACT_GEN_SET, 0, NULL);
1109
1110 return mwifiex_sta_init_cmd(priv, false);
1111}
1112
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001113/*
1114 * Sends IOCTL request to get statistics information.
1115 *
1116 * This function allocates the IOCTL request buffer, fills it
1117 * with requisite parameters and calls the IOCTL handler.
1118 */
1119int
1120mwifiex_get_stats_info(struct mwifiex_private *priv,
1121 struct mwifiex_ds_get_stats *log)
1122{
Bing Zhao67a50032011-07-13 18:38:34 -07001123 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001124 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001125}
1126
1127/*
1128 * IOCTL request handler to read/write register.
1129 *
1130 * This function prepares the correct firmware command and
1131 * issues it.
1132 *
1133 * Access to the following registers are supported -
1134 * - MAC
1135 * - BBP
1136 * - RF
1137 * - PMIC
1138 * - CAU
1139 */
1140static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001141 struct mwifiex_ds_reg_rw *reg_rw,
1142 u16 action)
1143{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001144 u16 cmd_no;
1145
1146 switch (le32_to_cpu(reg_rw->type)) {
1147 case MWIFIEX_REG_MAC:
1148 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1149 break;
1150 case MWIFIEX_REG_BBP:
1151 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1152 break;
1153 case MWIFIEX_REG_RF:
1154 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1155 break;
1156 case MWIFIEX_REG_PMIC:
1157 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1158 break;
1159 case MWIFIEX_REG_CAU:
1160 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1161 break;
1162 default:
1163 return -1;
1164 }
1165
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001166 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001167
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001168}
1169
1170/*
1171 * Sends IOCTL request to write to a register.
1172 *
1173 * This function allocates the IOCTL request buffer, fills it
1174 * with requisite parameters and calls the IOCTL handler.
1175 */
1176int
1177mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1178 u32 reg_offset, u32 reg_value)
1179{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001180 struct mwifiex_ds_reg_rw reg_rw;
1181
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001182 reg_rw.type = cpu_to_le32(reg_type);
1183 reg_rw.offset = cpu_to_le32(reg_offset);
1184 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001185
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001186 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187}
1188
1189/*
1190 * Sends IOCTL request to read from a register.
1191 *
1192 * This function allocates the IOCTL request buffer, fills it
1193 * with requisite parameters and calls the IOCTL handler.
1194 */
1195int
1196mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1197 u32 reg_offset, u32 *value)
1198{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001199 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001200 struct mwifiex_ds_reg_rw reg_rw;
1201
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 reg_rw.type = cpu_to_le32(reg_type);
1203 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001204 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001205
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001206 if (ret)
1207 goto done;
1208
1209 *value = le32_to_cpu(reg_rw.value);
1210
1211done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001212 return ret;
1213}
1214
1215/*
1216 * Sends IOCTL request to read from EEPROM.
1217 *
1218 * This function allocates the IOCTL request buffer, fills it
1219 * with requisite parameters and calls the IOCTL handler.
1220 */
1221int
1222mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1223 u8 *value)
1224{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001225 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001226 struct mwifiex_ds_read_eeprom rd_eeprom;
1227
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001228 rd_eeprom.offset = cpu_to_le16((u16) offset);
1229 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001230
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001231 /* Send request to firmware */
1232 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1233 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001234
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001235 if (!ret)
1236 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001237 return ret;
1238}
1239
1240/*
1241 * This function sets a generic IE. In addition to generic IE, it can
1242 * also handle WPA, WPA2 and WAPI IEs.
1243 */
1244static int
1245mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1246 u16 ie_len)
1247{
1248 int ret = 0;
1249 struct ieee_types_vendor_header *pvendor_ie;
1250 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1251 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1252
1253 /* If the passed length is zero, reset the buffer */
1254 if (!ie_len) {
1255 priv->gen_ie_buf_len = 0;
1256 priv->wps.session_enable = false;
1257
1258 return 0;
1259 } else if (!ie_data_ptr) {
1260 return -1;
1261 }
1262 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1263 /* 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 +02001264 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001265 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1266 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001267
1268 /* IE is a WPA/WPA2 IE so call set_wpa function */
1269 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1270 priv->wps.session_enable = false;
1271
1272 return ret;
1273 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1274 /* IE is a WAPI IE so call set_wapi function */
1275 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1276
1277 return ret;
1278 }
1279 /*
1280 * Verify that the passed length is not larger than the
1281 * available space remaining in the buffer
1282 */
1283 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1284
1285 /* Test to see if it is a WPS IE, if so, enable
1286 * wps session flag
1287 */
1288 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001289 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1290 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001291 priv->wps.session_enable = true;
1292 dev_dbg(priv->adapter->dev,
1293 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001294 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001295 }
1296
1297 /* Append the passed data to the end of the
1298 genIeBuffer */
1299 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001300 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001301 /* Increment the stored buffer length by the
1302 size passed */
1303 priv->gen_ie_buf_len += ie_len;
1304 } else {
1305 /* Passed data does not fit in the remaining
1306 buffer space */
1307 ret = -1;
1308 }
1309
1310 /* Return 0, or -1 for error case */
1311 return ret;
1312}
1313
1314/*
1315 * IOCTL request handler to set/get generic IE.
1316 *
1317 * In addition to various generic IEs, this function can also be
1318 * used to set the ARP filter.
1319 */
1320static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1321 struct mwifiex_ds_misc_gen_ie *gen_ie,
1322 u16 action)
1323{
1324 struct mwifiex_adapter *adapter = priv->adapter;
1325
1326 switch (gen_ie->type) {
1327 case MWIFIEX_IE_TYPE_GEN_IE:
1328 if (action == HostCmd_ACT_GEN_GET) {
1329 gen_ie->len = priv->wpa_ie_len;
1330 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1331 } else {
1332 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1333 (u16) gen_ie->len);
1334 }
1335 break;
1336 case MWIFIEX_IE_TYPE_ARP_FILTER:
1337 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1338 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1339 adapter->arp_filter_size = 0;
1340 dev_err(adapter->dev, "invalid ARP filter size\n");
1341 return -1;
1342 } else {
1343 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001344 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001345 adapter->arp_filter_size = gen_ie->len;
1346 }
1347 break;
1348 default:
1349 dev_err(adapter->dev, "invalid IE type\n");
1350 return -1;
1351 }
1352 return 0;
1353}
1354
1355/*
1356 * Sends IOCTL request to set a generic IE.
1357 *
1358 * This function allocates the IOCTL request buffer, fills it
1359 * with requisite parameters and calls the IOCTL handler.
1360 */
1361int
1362mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1363{
1364 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001365
Bing Zhao67a50032011-07-13 18:38:34 -07001366 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001367 return -EFAULT;
1368
1369 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1370 gen_ie.len = ie_len;
1371 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001372 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001373 return -EFAULT;
1374
1375 return 0;
1376}