blob: 3edc92fad319ab21c4e1dd04aa9d65a0235e4c4c [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 Drake6390d882013-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
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700181 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
182 bss_desc->sensed_11h = true;
183
Bing Zhaod837a2a2013-04-12 10:34:17 -0700184 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700185}
186
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700187static int mwifiex_process_country_ie(struct mwifiex_private *priv,
188 struct cfg80211_bss *bss)
189{
Johannes Berg9caf0362012-11-29 01:25:20 +0100190 const u8 *country_ie;
191 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700192 struct mwifiex_802_11d_domain_reg *domain_info =
193 &priv->adapter->domain_reg;
194
Johannes Berg9caf0362012-11-29 01:25:20 +0100195 rcu_read_lock();
196 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
197 if (!country_ie) {
198 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700199 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100200 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700201
202 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100203 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
204 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700205 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100206 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700207
Bing Zhaodd4a9ac2013-12-13 18:32:59 -0800208 if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
209 rcu_read_unlock();
210 wiphy_dbg(priv->wdev->wiphy,
211 "11D: skip setting domain info in FW\n");
212 return 0;
213 }
214 memcpy(priv->adapter->country_code, &country_ie[2], 2);
215
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700216 domain_info->country_code[0] = country_ie[2];
217 domain_info->country_code[1] = country_ie[3];
218 domain_info->country_code[2] = ' ';
219
220 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
221
222 domain_info->no_of_triplet =
223 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
224
225 memcpy((u8 *)domain_info->triplet,
226 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
227
Johannes Berg9caf0362012-11-29 01:25:20 +0100228 rcu_read_unlock();
229
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700230 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
231 HostCmd_ACT_GEN_SET, 0, NULL)) {
232 wiphy_err(priv->adapter->wiphy,
233 "11D: setting domain info in FW\n");
234 return -1;
235 }
236
Bing Zhao82efa162013-12-13 18:33:02 -0800237 if (priv->adapter->dt_node) {
238 char txpwr[] = {"marvell,00_txpwrlimit"};
239
240 memcpy(&txpwr[8], priv->adapter->country_code, 2);
241 mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
242 }
243
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700244 return 0;
245}
246
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700247/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700248 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
249 * In both Ad-Hoc and infra mode, an deauthentication is performed
250 * first.
251 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700252int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800253 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700254{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700255 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700256 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700257 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258
259 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700260
261 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700262 mwifiex_process_country_ie(priv, bss);
263
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700264 /* Allocate and fill new bss descriptor */
265 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000266 GFP_KERNEL);
267 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700268 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700269
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700270 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700271 if (ret)
272 goto done;
273 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274
Stone Piao6621fe12013-07-29 16:32:39 -0700275 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
276 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700277 u8 config_bands;
278
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700279 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700281 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700282
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700283 if (!bss_desc)
284 return -1;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800285
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700286 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
287 HostCmd_SCAN_RADIO_TYPE_BG)
288 config_bands = BAND_B | BAND_G | BAND_GN | BAND_GAC;
289 else
290 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800291
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700292 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
293 adapter->config_bands = config_bands;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800294
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700295 ret = mwifiex_check_network_compatibility(priv, bss_desc);
296 if (ret)
297 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700298
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700299 if (mwifiex_11h_get_csa_closed_channel(priv) ==
300 (u8)bss_desc->channel) {
301 dev_err(adapter->dev,
302 "Attempt to reconnect on csa closed chan(%d)\n",
303 bss_desc->channel);
304 goto done;
305 }
306
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700307 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
308 "associating...\n");
309
Avinash Patil47411a02012-11-01 18:44:16 -0700310 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800311 if (netif_carrier_ok(priv->netdev))
312 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700313
314 /* Clear any past association response stored for
315 * application retrieval */
316 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700317 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800318
319 /* If auth type is auto and association fails using open mode,
320 * try to connect using shared mode */
321 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
322 priv->sec_info.is_authtype_auto &&
323 priv->sec_info.wep_enabled) {
324 priv->sec_info.authentication_mode =
325 NL80211_AUTHTYPE_SHARED_KEY;
326 ret = mwifiex_associate(priv, bss_desc);
327 }
328
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700329 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100330 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 } else {
332 /* Adhoc mode */
333 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700334 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700335 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
336 ssid, &bss_desc->ssid))) {
Ujjal Roy517543f2013-11-21 11:08:56 -0800337 ret = 0;
338 goto done;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700339 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700340
341 /* Exit Adhoc mode first */
342 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700343 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700344 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700345 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700346
347 priv->adhoc_is_link_sensed = false;
348
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700349 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700350
Avinash Patil47411a02012-11-01 18:44:16 -0700351 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800352 if (netif_carrier_ok(priv->netdev))
353 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700354
355 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700356 dev_dbg(adapter->dev, "info: network found in scan"
357 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700358 ret = mwifiex_adhoc_join(priv, bss_desc);
359 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100360 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700361 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 dev_dbg(adapter->dev, "info: Network not found in "
363 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700364 req_ssid->ssid);
365 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700366 }
367 }
368
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700369done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700370 /* beacon_ie buffer was allocated in function
371 * mwifiex_fill_new_bss_desc(). Free it now.
372 */
373 if (bss_desc)
374 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700375 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 return ret;
377}
378
379/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700380 * IOCTL request handler to set host sleep configuration.
381 *
382 * This function prepares the correct firmware command and
383 * issues it.
384 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700385static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
386 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700387
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700388{
389 struct mwifiex_adapter *adapter = priv->adapter;
390 int status = 0;
391 u32 prev_cond = 0;
392
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700393 if (!hs_cfg)
394 return -ENOMEM;
395
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700396 switch (action) {
397 case HostCmd_ACT_GEN_SET:
398 if (adapter->pps_uapsd_mode) {
399 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
400 " is blocked in UAPSD/PPS mode\n");
401 status = -1;
402 break;
403 }
404 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800405 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700406 if (!adapter->is_hs_configured)
407 /* Already cancelled */
408 break;
409 /* Save previous condition */
410 prev_cond = le32_to_cpu(adapter->hs_cfg
411 .conditions);
412 adapter->hs_cfg.conditions =
413 cpu_to_le32(hs_cfg->conditions);
414 } else if (hs_cfg->conditions) {
415 adapter->hs_cfg.conditions =
416 cpu_to_le32(hs_cfg->conditions);
417 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
418 if (hs_cfg->gap)
419 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800420 } else if (adapter->hs_cfg.conditions ==
421 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700422 /* Return failure if no parameters for HS
423 enable */
424 status = -1;
425 break;
426 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700427 if (cmd_type == MWIFIEX_SYNC_CMD)
428 status = mwifiex_send_cmd_sync(priv,
429 HostCmd_CMD_802_11_HS_CFG_ENH,
430 HostCmd_ACT_GEN_SET, 0,
431 &adapter->hs_cfg);
432 else
433 status = mwifiex_send_cmd_async(priv,
434 HostCmd_CMD_802_11_HS_CFG_ENH,
435 HostCmd_ACT_GEN_SET, 0,
436 &adapter->hs_cfg);
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800437 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700438 /* Restore previous condition */
439 adapter->hs_cfg.conditions =
440 cpu_to_le32(prev_cond);
441 } else {
442 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700443 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700444 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
445 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
446 }
447 break;
448 case HostCmd_ACT_GEN_GET:
449 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
450 hs_cfg->gpio = adapter->hs_cfg.gpio;
451 hs_cfg->gap = adapter->hs_cfg.gap;
452 break;
453 default:
454 status = -1;
455 break;
456 }
457
458 return status;
459}
460
461/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700462 * Sends IOCTL request to cancel the existing Host Sleep configuration.
463 *
464 * This function allocates the IOCTL request buffer, fills it
465 * with requisite parameters and calls the IOCTL handler.
466 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700467int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700468{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 struct mwifiex_ds_hs_cfg hscfg;
470
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800471 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700472 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700474 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
475 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476}
477EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
478
479/*
480 * Sends IOCTL request to cancel the existing Host Sleep configuration.
481 *
482 * This function allocates the IOCTL request buffer, fills it
483 * with requisite parameters and calls the IOCTL handler.
484 */
485int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
486{
487 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700488 struct mwifiex_private *priv;
489 int i;
490
491 if (disconnect_on_suspend) {
492 for (i = 0; i < adapter->priv_num; i++) {
493 priv = adapter->priv[i];
494 if (priv)
495 mwifiex_deauthenticate(priv, NULL);
496 }
497 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700498
499 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900500 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700501 return true;
502 }
503
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700504 adapter->hs_activate_wait_q_woken = false;
505
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700506 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700507 hscfg.is_invoke_hostcmd = true;
508
509 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700510 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700511 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
512 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700513 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
514 return false;
515 }
516
Bing Zhao9c969d82013-01-02 16:07:35 -0800517 if (wait_event_interruptible(adapter->hs_activate_wait_q,
518 adapter->hs_activate_wait_q_woken)) {
519 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
520 return false;
521 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700522
523 return true;
524}
525EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
526
527/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700528 * IOCTL request handler to get BSS information.
529 *
530 * This function collates the information from different driver structures
531 * to send to the user.
532 */
533int mwifiex_get_bss_info(struct mwifiex_private *priv,
534 struct mwifiex_bss_info *info)
535{
536 struct mwifiex_adapter *adapter = priv->adapter;
537 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700538
539 if (!info)
540 return -1;
541
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700542 bss_desc = &priv->curr_bss_params.bss_descriptor;
543
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700544 info->bss_mode = priv->bss_mode;
545
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800546 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700547
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
549
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700550 info->bss_chan = bss_desc->channel;
551
Avinash Patil67fdf392012-05-08 18:30:17 -0700552 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700553 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700554
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555 info->media_connected = priv->media_connected;
556
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700557 info->max_power_level = priv->max_tx_power_level;
558 info->min_power_level = priv->min_tx_power_level;
559
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700560 info->adhoc_state = priv->adhoc_state;
561
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562 info->bcn_nf_last = priv->bcn_nf_last;
563
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800564 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 info->wep_status = true;
566 else
567 info->wep_status = false;
568
569 info->is_hs_configured = adapter->is_hs_configured;
570 info->is_deep_sleep = adapter->is_deep_sleep;
571
572 return 0;
573}
574
575/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700576 * The function disables auto deep sleep mode.
577 */
578int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
579{
580 struct mwifiex_ds_auto_ds auto_ds;
581
582 auto_ds.auto_ds = DEEP_SLEEP_OFF;
583
584 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
585 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
586}
587EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
588
589/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590 * Sends IOCTL request to get the data rate.
591 *
592 * This function allocates the IOCTL request buffer, fills it
593 * with requisite parameters and calls the IOCTL handler.
594 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700595int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700597 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700598
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700599 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
600 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700601
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700603 if (priv->is_data_rate_auto)
604 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
605 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300606 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700607 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608 }
609
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700610 return ret;
611}
612
613/*
614 * IOCTL request handler to set tx power configuration.
615 *
616 * This function prepares the correct firmware command and
617 * issues it.
618 *
619 * For non-auto power mode, all the following power groups are set -
620 * - Modulation class HR/DSSS
621 * - Modulation class OFDM
622 * - Modulation class HTBW20
623 * - Modulation class HTBW40
624 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700625int mwifiex_set_tx_power(struct mwifiex_private *priv,
626 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700627{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700628 int ret;
629 struct host_cmd_ds_txpwr_cfg *txp_cfg;
630 struct mwifiex_types_power_group *pg_tlv;
631 struct mwifiex_power_group *pg;
632 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633 u16 dbm = 0;
634
635 if (!power_cfg->is_power_auto) {
636 dbm = (u16) power_cfg->power_level;
637 if ((dbm < priv->min_tx_power_level) ||
638 (dbm > priv->max_tx_power_level)) {
639 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700640 " is out of range (%d dBm-%d dBm)\n",
641 dbm, priv->min_tx_power_level,
642 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700643 return -1;
644 }
645 }
646 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000647 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200648 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649
650 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
651 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
652 if (!power_cfg->is_power_auto) {
653 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700654 pg_tlv = (struct mwifiex_types_power_group *)
655 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700656 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
657 pg_tlv->length =
658 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700659 pg = (struct mwifiex_power_group *)
660 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
661 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700662 /* Power group for modulation class HR/DSSS */
663 pg->first_rate_code = 0x00;
664 pg->last_rate_code = 0x03;
665 pg->modulation_class = MOD_CLASS_HR_DSSS;
666 pg->power_step = 0;
667 pg->power_min = (s8) dbm;
668 pg->power_max = (s8) dbm;
669 pg++;
670 /* Power group for modulation class OFDM */
671 pg->first_rate_code = 0x00;
672 pg->last_rate_code = 0x07;
673 pg->modulation_class = MOD_CLASS_OFDM;
674 pg->power_step = 0;
675 pg->power_min = (s8) dbm;
676 pg->power_max = (s8) dbm;
677 pg++;
678 /* Power group for modulation class HTBW20 */
679 pg->first_rate_code = 0x00;
680 pg->last_rate_code = 0x20;
681 pg->modulation_class = MOD_CLASS_HT;
682 pg->power_step = 0;
683 pg->power_min = (s8) dbm;
684 pg->power_max = (s8) dbm;
685 pg->ht_bandwidth = HT_BW_20;
686 pg++;
687 /* Power group for modulation class HTBW40 */
688 pg->first_rate_code = 0x00;
689 pg->last_rate_code = 0x20;
690 pg->modulation_class = MOD_CLASS_HT;
691 pg->power_step = 0;
692 pg->power_min = (s8) dbm;
693 pg->power_max = (s8) dbm;
694 pg->ht_bandwidth = HT_BW_40;
695 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700696 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
697 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700698
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700699 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700700 return ret;
701}
702
703/*
704 * IOCTL request handler to get power save mode.
705 *
706 * This function prepares the correct firmware command and
707 * issues it.
708 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700709int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700710{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700711 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700712 struct mwifiex_adapter *adapter = priv->adapter;
713 u16 sub_cmd;
714
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700715 if (*ps_mode)
716 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
717 else
718 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
719 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
720 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
721 sub_cmd, BITMAP_STA_PS, NULL);
722 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
723 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700724 HostCmd_CMD_802_11_PS_MODE_ENH,
725 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726
727 return ret;
728}
729
730/*
731 * IOCTL request handler to set/reset WPA IE.
732 *
733 * The supplied WPA IE is treated as a opaque buffer. Only the first field
734 * is checked to determine WPA version. If buffer length is zero, the existing
735 * WPA IE is reset.
736 */
737static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
738 u8 *ie_data_ptr, u16 ie_len)
739{
740 if (ie_len) {
741 if (ie_len > sizeof(priv->wpa_ie)) {
742 dev_err(priv->adapter->dev,
743 "failed to copy WPA IE, too big\n");
744 return -1;
745 }
746 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
747 priv->wpa_ie_len = (u8) ie_len;
748 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700749 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700750
Arend van Spriel04b23122012-10-12 12:28:14 +0200751 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700752 priv->sec_info.wpa_enabled = true;
753 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
754 priv->sec_info.wpa2_enabled = true;
755 } else {
756 priv->sec_info.wpa_enabled = false;
757 priv->sec_info.wpa2_enabled = false;
758 }
759 } else {
760 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
761 priv->wpa_ie_len = 0;
762 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
763 priv->wpa_ie_len, priv->wpa_ie[0]);
764 priv->sec_info.wpa_enabled = false;
765 priv->sec_info.wpa2_enabled = false;
766 }
767
768 return 0;
769}
770
771/*
772 * IOCTL request handler to set/reset WAPI IE.
773 *
774 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
775 * is checked to internally enable WAPI. If buffer length is zero, the existing
776 * WAPI IE is reset.
777 */
778static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
779 u8 *ie_data_ptr, u16 ie_len)
780{
781 if (ie_len) {
782 if (ie_len > sizeof(priv->wapi_ie)) {
783 dev_dbg(priv->adapter->dev,
784 "info: failed to copy WAPI IE, too big\n");
785 return -1;
786 }
787 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
788 priv->wapi_ie_len = ie_len;
789 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700790 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700791
792 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
793 priv->sec_info.wapi_enabled = true;
794 } else {
795 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
796 priv->wapi_ie_len = ie_len;
797 dev_dbg(priv->adapter->dev,
798 "info: Reset wapi_ie_len=%d IE=%#x\n",
799 priv->wapi_ie_len, priv->wapi_ie[0]);
800 priv->sec_info.wapi_enabled = false;
801 }
802 return 0;
803}
804
805/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700806 * IOCTL request handler to set/reset WPS IE.
807 *
808 * The supplied WPS IE is treated as a opaque buffer. Only the first field
809 * is checked to internally enable WPS. If buffer length is zero, the existing
810 * WPS IE is reset.
811 */
812static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
813 u8 *ie_data_ptr, u16 ie_len)
814{
815 if (ie_len) {
Avinash Patil8795ca62013-07-22 19:17:46 -0700816 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
817 dev_dbg(priv->adapter->dev,
818 "info: failed to copy WPS IE, too big\n");
819 return -1;
820 }
821
Avinash Patil13d7ba782012-04-09 20:06:56 -0700822 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
823 if (!priv->wps_ie)
824 return -ENOMEM;
Avinash Patil8795ca62013-07-22 19:17:46 -0700825
Avinash Patil13d7ba782012-04-09 20:06:56 -0700826 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
827 priv->wps_ie_len = ie_len;
828 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
829 priv->wps_ie_len, priv->wps_ie[0]);
830 } else {
831 kfree(priv->wps_ie);
832 priv->wps_ie_len = ie_len;
833 dev_dbg(priv->adapter->dev,
834 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
835 }
836 return 0;
837}
838
839/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700840 * IOCTL request handler to set WAPI key.
841 *
842 * This function prepares the correct firmware command and
843 * issues it.
844 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700845static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700846 struct mwifiex_ds_encrypt_key *encrypt_key)
847{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700849 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700850 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
851 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700852}
853
854/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700855 * IOCTL request handler to set WEP network key.
856 *
857 * This function prepares the correct firmware command and
858 * issues it, after validation checks.
859 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700860static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 struct mwifiex_ds_encrypt_key *encrypt_key)
862{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700863 int ret;
864 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700865 int index;
866
867 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
868 priv->wep_key_curr_index = 0;
869 wep_key = &priv->wep_key[priv->wep_key_curr_index];
870 index = encrypt_key->key_index;
871 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800872 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700873 } else if (!encrypt_key->key_len) {
874 /* Copy the required key as the current key */
875 wep_key = &priv->wep_key[index];
876 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700877 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878 "key not set, so cannot enable it\n");
879 return -1;
880 }
881 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800882 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700883 } else {
884 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
886 /* Copy the key in the driver */
887 memcpy(wep_key->key_material,
888 encrypt_key->key_material,
889 encrypt_key->key_len);
890 wep_key->key_index = index;
891 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800892 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700893 }
894 if (wep_key->key_length) {
895 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700896 ret = mwifiex_send_cmd_async(priv,
897 HostCmd_CMD_802_11_KEY_MATERIAL,
898 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700899 if (ret)
900 return ret;
901 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800902 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700903 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
904 else
905 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
906
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700907 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
908 HostCmd_ACT_GEN_SET, 0,
909 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700910
911 return ret;
912}
913
914/*
915 * IOCTL request handler to set WPA key.
916 *
917 * This function prepares the correct firmware command and
918 * issues it, after validation checks.
919 *
920 * Current driver only supports key length of up to 32 bytes.
921 *
922 * This function can also be used to disable a currently set key.
923 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700924static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700925 struct mwifiex_ds_encrypt_key *encrypt_key)
926{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700927 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700928 u8 remove_key = false;
929 struct host_cmd_ds_802_11_key_material *ibss_key;
930
931 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700932 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700933 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700934 return -1;
935 }
936
Bing Zhaoeecd8252011-03-28 17:55:41 -0700937 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700938 /*
939 * IBSS/WPA-None uses only one key (Group) for both receiving
940 * and sending unicast and multicast packets.
941 */
942 /* Send the key as PTK to firmware */
943 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700944 ret = mwifiex_send_cmd_async(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 if (ret)
949 return ret;
950
951 ibss_key = &priv->aes_key;
952 memset(ibss_key, 0,
953 sizeof(struct host_cmd_ds_802_11_key_material));
954 /* Copy the key in the driver */
955 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
956 encrypt_key->key_len);
957 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
958 sizeof(ibss_key->key_param_set.key_len));
959 ibss_key->key_param_set.key_type_id
960 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700961 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700962
963 /* Send the key as GTK to firmware */
964 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
965 }
966
967 if (!encrypt_key->key_index)
968 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
969
970 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700971 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700972 HostCmd_CMD_802_11_KEY_MATERIAL,
973 HostCmd_ACT_GEN_SET,
974 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700975 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700976 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700977 HostCmd_CMD_802_11_KEY_MATERIAL,
978 HostCmd_ACT_GEN_SET,
979 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700980
981 return ret;
982}
983
984/*
985 * IOCTL request handler to set/get network keys.
986 *
987 * This is a generic key handling function which supports WEP, WPA
988 * and WAPI.
989 */
990static int
991mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700992 struct mwifiex_ds_encrypt_key *encrypt_key)
993{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700994 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700995
996 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700997 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700998 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700999 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001000 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001001 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001002 return status;
1003}
1004
1005/*
1006 * This function returns the driver version.
1007 */
1008int
1009mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1010 int max_len)
1011{
1012 union {
1013 u32 l;
1014 u8 c[4];
1015 } ver;
1016 char fw_ver[32];
1017
1018 ver.l = adapter->fw_release_number;
1019 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1020
1021 snprintf(version, max_len, driver_version, fw_ver);
1022
1023 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1024
1025 return 0;
1026}
1027
1028/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001029 * Sends IOCTL request to set encoding parameters.
1030 *
1031 * This function allocates the IOCTL request buffer, fills it
1032 * with requisite parameters and calls the IOCTL handler.
1033 */
Ying Luo53b11232012-08-03 18:06:13 -07001034int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1035 const u8 *key, int key_len, u8 key_index,
1036 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001037{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001040 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1041 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001042
1043 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1044 encrypt_key.is_igtk_key = true;
1045
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001046 if (!disable) {
1047 encrypt_key.key_index = key_index;
1048 if (key_len)
1049 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001050 if (mac_addr)
1051 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001052 if (kp && kp->seq && kp->seq_len)
1053 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054 } else {
1055 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001056 if (mac_addr)
1057 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058 }
1059
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001060 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001061}
1062
1063/*
1064 * Sends IOCTL request to get extended version.
1065 *
1066 * This function allocates the IOCTL request buffer, fills it
1067 * with requisite parameters and calls the IOCTL handler.
1068 */
1069int
1070mwifiex_get_ver_ext(struct mwifiex_private *priv)
1071{
1072 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001073
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001074 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001075 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001076 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001077 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001078
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001079 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001080}
1081
Stone Piao7feb4c42012-09-25 20:23:36 -07001082int
1083mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1084 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001085 unsigned int duration)
1086{
1087 struct host_cmd_ds_remain_on_chan roc_cfg;
1088 u8 sc;
1089
1090 memset(&roc_cfg, 0, sizeof(roc_cfg));
1091 roc_cfg.action = cpu_to_le16(action);
1092 if (action == HostCmd_ACT_GEN_SET) {
1093 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001094 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001095 roc_cfg.band_cfg |= (sc << 2);
1096
1097 roc_cfg.channel =
1098 ieee80211_frequency_to_channel(chan->center_freq);
1099 roc_cfg.duration = cpu_to_le32(duration);
1100 }
1101 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1102 action, 0, &roc_cfg)) {
1103 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1104 return -1;
1105 }
1106
1107 return roc_cfg.status;
1108}
1109
Stone Piao9197ab92012-09-25 20:23:42 -07001110int
1111mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1112{
1113 if (GET_BSS_ROLE(priv) == bss_role) {
1114 dev_dbg(priv->adapter->dev,
1115 "info: already in the desired role.\n");
1116 return 0;
1117 }
1118
1119 mwifiex_free_priv(priv);
1120 mwifiex_init_priv(priv);
1121
1122 priv->bss_role = bss_role;
1123 switch (bss_role) {
1124 case MWIFIEX_BSS_ROLE_UAP:
1125 priv->bss_mode = NL80211_IFTYPE_AP;
1126 break;
1127 case MWIFIEX_BSS_ROLE_STA:
1128 case MWIFIEX_BSS_ROLE_ANY:
1129 default:
1130 priv->bss_mode = NL80211_IFTYPE_STATION;
1131 break;
1132 }
1133
1134 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1135 HostCmd_ACT_GEN_SET, 0, NULL);
1136
1137 return mwifiex_sta_init_cmd(priv, false);
1138}
1139
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001140/*
1141 * Sends IOCTL request to get statistics information.
1142 *
1143 * This function allocates the IOCTL request buffer, fills it
1144 * with requisite parameters and calls the IOCTL handler.
1145 */
1146int
1147mwifiex_get_stats_info(struct mwifiex_private *priv,
1148 struct mwifiex_ds_get_stats *log)
1149{
Bing Zhao67a50032011-07-13 18:38:34 -07001150 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001151 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001152}
1153
1154/*
1155 * IOCTL request handler to read/write register.
1156 *
1157 * This function prepares the correct firmware command and
1158 * issues it.
1159 *
1160 * Access to the following registers are supported -
1161 * - MAC
1162 * - BBP
1163 * - RF
1164 * - PMIC
1165 * - CAU
1166 */
1167static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001168 struct mwifiex_ds_reg_rw *reg_rw,
1169 u16 action)
1170{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001171 u16 cmd_no;
1172
1173 switch (le32_to_cpu(reg_rw->type)) {
1174 case MWIFIEX_REG_MAC:
1175 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1176 break;
1177 case MWIFIEX_REG_BBP:
1178 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1179 break;
1180 case MWIFIEX_REG_RF:
1181 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1182 break;
1183 case MWIFIEX_REG_PMIC:
1184 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1185 break;
1186 case MWIFIEX_REG_CAU:
1187 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1188 break;
1189 default:
1190 return -1;
1191 }
1192
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001193 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001194
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001195}
1196
1197/*
1198 * Sends IOCTL request to write to a register.
1199 *
1200 * This function allocates the IOCTL request buffer, fills it
1201 * with requisite parameters and calls the IOCTL handler.
1202 */
1203int
1204mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1205 u32 reg_offset, u32 reg_value)
1206{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207 struct mwifiex_ds_reg_rw reg_rw;
1208
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001209 reg_rw.type = cpu_to_le32(reg_type);
1210 reg_rw.offset = cpu_to_le32(reg_offset);
1211 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001212
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001213 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001214}
1215
1216/*
1217 * Sends IOCTL request to read from a register.
1218 *
1219 * This function allocates the IOCTL request buffer, fills it
1220 * with requisite parameters and calls the IOCTL handler.
1221 */
1222int
1223mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1224 u32 reg_offset, u32 *value)
1225{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001226 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001227 struct mwifiex_ds_reg_rw reg_rw;
1228
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001229 reg_rw.type = cpu_to_le32(reg_type);
1230 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001231 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001233 if (ret)
1234 goto done;
1235
1236 *value = le32_to_cpu(reg_rw.value);
1237
1238done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239 return ret;
1240}
1241
1242/*
1243 * Sends IOCTL request to read from EEPROM.
1244 *
1245 * This function allocates the IOCTL request buffer, fills it
1246 * with requisite parameters and calls the IOCTL handler.
1247 */
1248int
1249mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1250 u8 *value)
1251{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001252 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001253 struct mwifiex_ds_read_eeprom rd_eeprom;
1254
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255 rd_eeprom.offset = cpu_to_le16((u16) offset);
1256 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001258 /* Send request to firmware */
1259 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1260 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001262 if (!ret)
1263 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001264 return ret;
1265}
1266
1267/*
1268 * This function sets a generic IE. In addition to generic IE, it can
1269 * also handle WPA, WPA2 and WAPI IEs.
1270 */
1271static int
1272mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1273 u16 ie_len)
1274{
1275 int ret = 0;
1276 struct ieee_types_vendor_header *pvendor_ie;
1277 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1278 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1279
1280 /* If the passed length is zero, reset the buffer */
1281 if (!ie_len) {
1282 priv->gen_ie_buf_len = 0;
1283 priv->wps.session_enable = false;
1284
1285 return 0;
1286 } else if (!ie_data_ptr) {
1287 return -1;
1288 }
1289 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1290 /* 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 +02001291 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001292 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1293 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001294
1295 /* IE is a WPA/WPA2 IE so call set_wpa function */
1296 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1297 priv->wps.session_enable = false;
1298
1299 return ret;
1300 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1301 /* IE is a WAPI IE so call set_wapi function */
1302 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1303
1304 return ret;
1305 }
1306 /*
1307 * Verify that the passed length is not larger than the
1308 * available space remaining in the buffer
1309 */
1310 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1311
1312 /* Test to see if it is a WPS IE, if so, enable
1313 * wps session flag
1314 */
1315 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001316 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1317 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001318 priv->wps.session_enable = true;
1319 dev_dbg(priv->adapter->dev,
1320 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001321 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001322 }
1323
1324 /* Append the passed data to the end of the
1325 genIeBuffer */
1326 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001327 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001328 /* Increment the stored buffer length by the
1329 size passed */
1330 priv->gen_ie_buf_len += ie_len;
1331 } else {
1332 /* Passed data does not fit in the remaining
1333 buffer space */
1334 ret = -1;
1335 }
1336
1337 /* Return 0, or -1 for error case */
1338 return ret;
1339}
1340
1341/*
1342 * IOCTL request handler to set/get generic IE.
1343 *
1344 * In addition to various generic IEs, this function can also be
1345 * used to set the ARP filter.
1346 */
1347static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1348 struct mwifiex_ds_misc_gen_ie *gen_ie,
1349 u16 action)
1350{
1351 struct mwifiex_adapter *adapter = priv->adapter;
1352
1353 switch (gen_ie->type) {
1354 case MWIFIEX_IE_TYPE_GEN_IE:
1355 if (action == HostCmd_ACT_GEN_GET) {
1356 gen_ie->len = priv->wpa_ie_len;
1357 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1358 } else {
1359 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1360 (u16) gen_ie->len);
1361 }
1362 break;
1363 case MWIFIEX_IE_TYPE_ARP_FILTER:
1364 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1365 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1366 adapter->arp_filter_size = 0;
1367 dev_err(adapter->dev, "invalid ARP filter size\n");
1368 return -1;
1369 } else {
1370 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001371 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001372 adapter->arp_filter_size = gen_ie->len;
1373 }
1374 break;
1375 default:
1376 dev_err(adapter->dev, "invalid IE type\n");
1377 return -1;
1378 }
1379 return 0;
1380}
1381
1382/*
1383 * Sends IOCTL request to set a generic IE.
1384 *
1385 * This function allocates the IOCTL request buffer, fills it
1386 * with requisite parameters and calls the IOCTL handler.
1387 */
1388int
1389mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1390{
1391 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001392
Bing Zhao67a50032011-07-13 18:38:34 -07001393 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001394 return -EFAULT;
1395
1396 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1397 gen_ie.len = ie_len;
1398 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001399 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001400 return -EFAULT;
1401
1402 return 0;
1403}