blob: 2f86bb63f3c08085a9735fc8d19a11c33ce8bbac [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: scan ioctl and command handling
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
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 "11n.h"
26#include "cfg80211.h"
27
28/* The maximum number of channels the firmware can scan per command */
29#define MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN 14
30
Amitkumar Karwar658f37b2012-06-06 21:12:42 -070031#define MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD 4
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032
33/* Memory needed to store a max sized Channel List TLV for a firmware scan */
34#define CHAN_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_header) \
35 + (MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN \
36 *sizeof(struct mwifiex_chan_scan_param_set)))
37
38/* Memory needed to store supported rate */
39#define RATE_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_rates_param_set) \
40 + HOSTCMD_SUPPORTED_RATES)
41
42/* Memory needed to store a max number/size WildCard SSID TLV for a firmware
43 scan */
44#define WILDCARD_SSID_TLV_MAX_SIZE \
45 (MWIFIEX_MAX_SSID_LIST_LENGTH * \
46 (sizeof(struct mwifiex_ie_types_wildcard_ssid_params) \
47 + IEEE80211_MAX_SSID_LEN))
48
49/* Maximum memory needed for a mwifiex_scan_cmd_config with all TLVs at max */
50#define MAX_SCAN_CFG_ALLOC (sizeof(struct mwifiex_scan_cmd_config) \
51 + sizeof(struct mwifiex_ie_types_num_probes) \
52 + sizeof(struct mwifiex_ie_types_htcap) \
53 + CHAN_TLV_MAX_SIZE \
54 + RATE_TLV_MAX_SIZE \
55 + WILDCARD_SSID_TLV_MAX_SIZE)
56
57
58union mwifiex_scan_cmd_config_tlv {
59 /* Scan configuration (variable length) */
60 struct mwifiex_scan_cmd_config config;
61 /* Max allocated block */
62 u8 config_alloc_buf[MAX_SCAN_CFG_ALLOC];
63};
64
65enum cipher_suite {
66 CIPHER_SUITE_TKIP,
67 CIPHER_SUITE_CCMP,
68 CIPHER_SUITE_MAX
69};
70static u8 mwifiex_wpa_oui[CIPHER_SUITE_MAX][4] = {
71 { 0x00, 0x50, 0xf2, 0x02 }, /* TKIP */
72 { 0x00, 0x50, 0xf2, 0x04 }, /* AES */
73};
74static u8 mwifiex_rsn_oui[CIPHER_SUITE_MAX][4] = {
75 { 0x00, 0x0f, 0xac, 0x02 }, /* TKIP */
76 { 0x00, 0x0f, 0xac, 0x04 }, /* AES */
77};
78
79/*
80 * This function parses a given IE for a given OUI.
81 *
82 * This is used to parse a WPA/RSN IE to find if it has
83 * a given oui in PTK.
84 */
85static u8
86mwifiex_search_oui_in_ie(struct ie_body *iebody, u8 *oui)
87{
88 u8 count;
89
90 count = iebody->ptk_cnt[0];
91
92 /* There could be multiple OUIs for PTK hence
93 1) Take the length.
94 2) Check all the OUIs for AES.
95 3) If one of them is AES then pass success. */
96 while (count) {
97 if (!memcmp(iebody->ptk_body, oui, sizeof(iebody->ptk_body)))
98 return MWIFIEX_OUI_PRESENT;
99
100 --count;
101 if (count)
102 iebody = (struct ie_body *) ((u8 *) iebody +
103 sizeof(iebody->ptk_body));
104 }
105
106 pr_debug("info: %s: OUI is not found in PTK\n", __func__);
107 return MWIFIEX_OUI_NOT_PRESENT;
108}
109
110/*
111 * This function checks if a given OUI is present in a RSN IE.
112 *
113 * The function first checks if a RSN IE is present or not in the
114 * BSS descriptor. It tries to locate the OUI only if such an IE is
115 * present.
116 */
117static u8
118mwifiex_is_rsn_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
119{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700120 u8 *oui;
121 struct ie_body *iebody;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700122 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
123
124 if (((bss_desc->bcn_rsn_ie) && ((*(bss_desc->bcn_rsn_ie)).
125 ieee_hdr.element_id == WLAN_EID_RSN))) {
126 iebody = (struct ie_body *)
127 (((u8 *) bss_desc->bcn_rsn_ie->data) +
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700128 RSN_GTK_OUI_OFFSET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700129 oui = &mwifiex_rsn_oui[cipher][0];
130 ret = mwifiex_search_oui_in_ie(iebody, oui);
131 if (ret)
132 return ret;
133 }
134 return ret;
135}
136
137/*
138 * This function checks if a given OUI is present in a WPA IE.
139 *
140 * The function first checks if a WPA IE is present or not in the
141 * BSS descriptor. It tries to locate the OUI only if such an IE is
142 * present.
143 */
144static u8
145mwifiex_is_wpa_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
146{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700147 u8 *oui;
148 struct ie_body *iebody;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700149 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
150
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700151 if (((bss_desc->bcn_wpa_ie) &&
152 ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id ==
Arend van Spriel04b23122012-10-12 12:28:14 +0200153 WLAN_EID_VENDOR_SPECIFIC))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700154 iebody = (struct ie_body *) bss_desc->bcn_wpa_ie->data;
155 oui = &mwifiex_wpa_oui[cipher][0];
156 ret = mwifiex_search_oui_in_ie(iebody, oui);
157 if (ret)
158 return ret;
159 }
160 return ret;
161}
162
163/*
164 * This function compares two SSIDs and checks if they match.
165 */
166s32
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800167mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700168{
169 if (!ssid1 || !ssid2 || (ssid1->ssid_len != ssid2->ssid_len))
170 return -1;
171 return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssid_len);
172}
173
174/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700175 * This function checks if wapi is enabled in driver and scanned network is
176 * compatible with it.
177 */
178static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700179mwifiex_is_bss_wapi(struct mwifiex_private *priv,
180 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700181{
182 if (priv->sec_info.wapi_enabled &&
183 (bss_desc->bcn_wapi_ie &&
184 ((*(bss_desc->bcn_wapi_ie)).ieee_hdr.element_id ==
185 WLAN_EID_BSS_AC_ACCESS_DELAY))) {
186 return true;
187 }
188 return false;
189}
190
191/*
192 * This function checks if driver is configured with no security mode and
193 * scanned network is compatible with it.
194 */
195static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700196mwifiex_is_bss_no_sec(struct mwifiex_private *priv,
197 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700198{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800199 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
200 !priv->sec_info.wpa2_enabled && ((!bss_desc->bcn_wpa_ie) ||
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201 ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id !=
Arend van Spriel04b23122012-10-12 12:28:14 +0200202 WLAN_EID_VENDOR_SPECIFIC)) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700203 ((!bss_desc->bcn_rsn_ie) ||
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700204 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id !=
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700205 WLAN_EID_RSN)) &&
206 !priv->sec_info.encryption_mode && !bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700207 return true;
208 }
209 return false;
210}
211
212/*
213 * This function checks if static WEP is enabled in driver and scanned network
214 * is compatible with it.
215 */
216static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700217mwifiex_is_bss_static_wep(struct mwifiex_private *priv,
218 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700219{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800220 if (priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
221 !priv->sec_info.wpa2_enabled && bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700222 return true;
223 }
224 return false;
225}
226
227/*
228 * This function checks if wpa is enabled in driver and scanned network is
229 * compatible with it.
230 */
231static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700232mwifiex_is_bss_wpa(struct mwifiex_private *priv,
233 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700234{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800235 if (!priv->sec_info.wep_enabled && priv->sec_info.wpa_enabled &&
236 !priv->sec_info.wpa2_enabled && ((bss_desc->bcn_wpa_ie) &&
Arend van Spriel04b23122012-10-12 12:28:14 +0200237 ((*(bss_desc->bcn_wpa_ie)).
238 vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239 /*
240 * Privacy bit may NOT be set in some APs like
241 * LinkSys WRT54G && bss_desc->privacy
242 */
243 ) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700244 dev_dbg(priv->adapter->dev, "info: %s: WPA:"
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700245 " wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700246 "EncMode=%#x privacy=%#x\n", __func__,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700247 (bss_desc->bcn_wpa_ie) ?
248 (*(bss_desc->bcn_wpa_ie)).
249 vend_hdr.element_id : 0,
250 (bss_desc->bcn_rsn_ie) ?
251 (*(bss_desc->bcn_rsn_ie)).
252 ieee_hdr.element_id : 0,
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800253 (priv->sec_info.wep_enabled) ? "e" : "d",
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700254 (priv->sec_info.wpa_enabled) ? "e" : "d",
255 (priv->sec_info.wpa2_enabled) ? "e" : "d",
256 priv->sec_info.encryption_mode,
257 bss_desc->privacy);
258 return true;
259 }
260 return false;
261}
262
263/*
264 * This function checks if wpa2 is enabled in driver and scanned network is
265 * compatible with it.
266 */
267static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700268mwifiex_is_bss_wpa2(struct mwifiex_private *priv,
269 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270{
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700271 if (!priv->sec_info.wep_enabled &&
272 !priv->sec_info.wpa_enabled &&
273 priv->sec_info.wpa2_enabled &&
274 ((bss_desc->bcn_rsn_ie) &&
275 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id == WLAN_EID_RSN))) {
276 /*
277 * Privacy bit may NOT be set in some APs like
278 * LinkSys WRT54G && bss_desc->privacy
279 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700280 dev_dbg(priv->adapter->dev, "info: %s: WPA2: "
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700281 " wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700282 "EncMode=%#x privacy=%#x\n", __func__,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700283 (bss_desc->bcn_wpa_ie) ?
284 (*(bss_desc->bcn_wpa_ie)).
285 vend_hdr.element_id : 0,
286 (bss_desc->bcn_rsn_ie) ?
287 (*(bss_desc->bcn_rsn_ie)).
288 ieee_hdr.element_id : 0,
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800289 (priv->sec_info.wep_enabled) ? "e" : "d",
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700290 (priv->sec_info.wpa_enabled) ? "e" : "d",
291 (priv->sec_info.wpa2_enabled) ? "e" : "d",
292 priv->sec_info.encryption_mode,
293 bss_desc->privacy);
294 return true;
295 }
296 return false;
297}
298
299/*
300 * This function checks if adhoc AES is enabled in driver and scanned network is
301 * compatible with it.
302 */
303static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700304mwifiex_is_bss_adhoc_aes(struct mwifiex_private *priv,
305 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700306{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800307 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700308 !priv->sec_info.wpa2_enabled &&
309 ((!bss_desc->bcn_wpa_ie) ||
Arend van Spriel04b23122012-10-12 12:28:14 +0200310 ((*(bss_desc->bcn_wpa_ie)).
311 vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700312 ((!bss_desc->bcn_rsn_ie) ||
313 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
314 !priv->sec_info.encryption_mode && bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700315 return true;
316 }
317 return false;
318}
319
320/*
321 * This function checks if dynamic WEP is enabled in driver and scanned network
322 * is compatible with it.
323 */
324static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700325mwifiex_is_bss_dynamic_wep(struct mwifiex_private *priv,
326 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700327{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800328 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700329 !priv->sec_info.wpa2_enabled &&
330 ((!bss_desc->bcn_wpa_ie) ||
Arend van Spriel04b23122012-10-12 12:28:14 +0200331 ((*(bss_desc->bcn_wpa_ie)).
332 vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700333 ((!bss_desc->bcn_rsn_ie) ||
334 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
335 priv->sec_info.encryption_mode && bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336 dev_dbg(priv->adapter->dev, "info: %s: dynamic "
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700337 "WEP: wpa_ie=%#x wpa2_ie=%#x "
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700338 "EncMode=%#x privacy=%#x\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700339 __func__,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700340 (bss_desc->bcn_wpa_ie) ?
341 (*(bss_desc->bcn_wpa_ie)).
342 vend_hdr.element_id : 0,
343 (bss_desc->bcn_rsn_ie) ?
344 (*(bss_desc->bcn_rsn_ie)).
345 ieee_hdr.element_id : 0,
346 priv->sec_info.encryption_mode,
347 bss_desc->privacy);
348 return true;
349 }
350 return false;
351}
352
353/*
354 * This function checks if a scanned network is compatible with the driver
355 * settings.
356 *
357 * WEP WPA WPA2 ad-hoc encrypt Network
358 * enabled enabled enabled AES mode Privacy WPA WPA2 Compatible
359 * 0 0 0 0 NONE 0 0 0 yes No security
360 * 0 1 0 0 x 1x 1 x yes WPA (disable
361 * HT if no AES)
362 * 0 0 1 0 x 1x x 1 yes WPA2 (disable
363 * HT if no AES)
364 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
365 * 1 0 0 0 NONE 1 0 0 yes Static WEP
366 * (disable HT)
367 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
368 *
369 * Compatibility is not matched while roaming, except for mode.
370 */
371static s32
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700372mwifiex_is_network_compatible(struct mwifiex_private *priv,
373 struct mwifiex_bssdescriptor *bss_desc, u32 mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700374{
375 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700377 bss_desc->disable_11n = false;
378
379 /* Don't check for compatibility if roaming */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700380 if (priv->media_connected &&
381 (priv->bss_mode == NL80211_IFTYPE_STATION) &&
382 (bss_desc->bss_mode == NL80211_IFTYPE_STATION))
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700383 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700384
385 if (priv->wps.session_enable) {
386 dev_dbg(adapter->dev,
387 "info: return success directly in WPS period\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700388 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700389 }
390
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700391 if (bss_desc->chan_sw_ie_present) {
392 dev_err(adapter->dev,
393 "Don't connect to AP with WLAN_EID_CHANNEL_SWITCH\n");
394 return -1;
395 }
396
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700397 if (mwifiex_is_bss_wapi(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398 dev_dbg(adapter->dev, "info: return success for WAPI AP\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700399 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700400 }
401
402 if (bss_desc->bss_mode == mode) {
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700403 if (mwifiex_is_bss_no_sec(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404 /* No security */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700405 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700406 } else if (mwifiex_is_bss_static_wep(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700407 /* Static WEP enabled */
408 dev_dbg(adapter->dev, "info: Disable 11n in WEP mode.\n");
409 bss_desc->disable_11n = true;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700410 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700411 } else if (mwifiex_is_bss_wpa(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700412 /* WPA enabled */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700413 if (((priv->adapter->config_bands & BAND_GN ||
414 priv->adapter->config_bands & BAND_AN) &&
415 bss_desc->bcn_ht_cap) &&
416 !mwifiex_is_wpa_oui_present(bss_desc,
417 CIPHER_SUITE_CCMP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700418
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700419 if (mwifiex_is_wpa_oui_present
420 (bss_desc, CIPHER_SUITE_TKIP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700421 dev_dbg(adapter->dev,
422 "info: Disable 11n if AES "
423 "is not supported by AP\n");
424 bss_desc->disable_11n = true;
425 } else {
426 return -1;
427 }
428 }
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700429 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700430 } else if (mwifiex_is_bss_wpa2(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700431 /* WPA2 enabled */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700432 if (((priv->adapter->config_bands & BAND_GN ||
433 priv->adapter->config_bands & BAND_AN) &&
434 bss_desc->bcn_ht_cap) &&
435 !mwifiex_is_rsn_oui_present(bss_desc,
436 CIPHER_SUITE_CCMP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700437
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700438 if (mwifiex_is_rsn_oui_present
439 (bss_desc, CIPHER_SUITE_TKIP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700440 dev_dbg(adapter->dev,
441 "info: Disable 11n if AES "
442 "is not supported by AP\n");
443 bss_desc->disable_11n = true;
444 } else {
445 return -1;
446 }
447 }
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700448 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700449 } else if (mwifiex_is_bss_adhoc_aes(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700450 /* Ad-hoc AES enabled */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700451 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700452 } else if (mwifiex_is_bss_dynamic_wep(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700453 /* Dynamic WEP enabled */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700454 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700455 }
456
457 /* Security doesn't match */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700458 dev_dbg(adapter->dev,
459 "info: %s: failed: wpa_ie=%#x wpa2_ie=%#x WEP=%s "
460 "WPA=%s WPA2=%s EncMode=%#x privacy=%#x\n", __func__,
461 (bss_desc->bcn_wpa_ie) ?
462 (*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id : 0,
463 (bss_desc->bcn_rsn_ie) ?
464 (*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id : 0,
465 (priv->sec_info.wep_enabled) ? "e" : "d",
466 (priv->sec_info.wpa_enabled) ? "e" : "d",
467 (priv->sec_info.wpa2_enabled) ? "e" : "d",
468 priv->sec_info.encryption_mode, bss_desc->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 return -1;
470 }
471
472 /* Mode doesn't match */
473 return -1;
474}
475
476/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700477 * This function creates a channel list for the driver to scan, based
478 * on region/band information.
479 *
480 * This routine is used for any scan that is not provided with a
481 * specific channel list to scan.
482 */
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700483static int
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700484mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700485 const struct mwifiex_user_scan_cfg
486 *user_scan_in,
487 struct mwifiex_chan_scan_param_set
488 *scan_chan_list,
489 u8 filtered_scan)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700490{
491 enum ieee80211_band band;
492 struct ieee80211_supported_band *sband;
493 struct ieee80211_channel *ch;
494 struct mwifiex_adapter *adapter = priv->adapter;
495 int chan_idx = 0, i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700496
497 for (band = 0; (band < IEEE80211_NUM_BANDS) ; band++) {
498
499 if (!priv->wdev->wiphy->bands[band])
500 continue;
501
502 sband = priv->wdev->wiphy->bands[band];
503
Amitkumar Karward06b7b92011-09-21 21:43:22 -0700504 for (i = 0; (i < sband->n_channels) ; i++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 ch = &sband->channels[i];
506 if (ch->flags & IEEE80211_CHAN_DISABLED)
507 continue;
508 scan_chan_list[chan_idx].radio_type = band;
Amitkumar Karwar186630c2011-12-15 21:00:37 -0800509
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510 if (user_scan_in &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700511 user_scan_in->chan_list[0].scan_time)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700512 scan_chan_list[chan_idx].max_scan_time =
513 cpu_to_le16((u16) user_scan_in->
514 chan_list[0].scan_time);
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200515 else if (ch->flags & IEEE80211_CHAN_NO_IR)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700516 scan_chan_list[chan_idx].max_scan_time =
517 cpu_to_le16(adapter->passive_scan_time);
518 else
519 scan_chan_list[chan_idx].max_scan_time =
520 cpu_to_le16(adapter->active_scan_time);
Amitkumar Karwar186630c2011-12-15 21:00:37 -0800521
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200522 if (ch->flags & IEEE80211_CHAN_NO_IR)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523 scan_chan_list[chan_idx].chan_scan_mode_bitmap
524 |= MWIFIEX_PASSIVE_SCAN;
525 else
526 scan_chan_list[chan_idx].chan_scan_mode_bitmap
527 &= ~MWIFIEX_PASSIVE_SCAN;
528 scan_chan_list[chan_idx].chan_number =
529 (u32) ch->hw_value;
530 if (filtered_scan) {
531 scan_chan_list[chan_idx].max_scan_time =
532 cpu_to_le16(adapter->specific_scan_time);
533 scan_chan_list[chan_idx].chan_scan_mode_bitmap
534 |= MWIFIEX_DISABLE_CHAN_FILT;
535 }
Amitkumar Karward06b7b92011-09-21 21:43:22 -0700536 chan_idx++;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537 }
538
539 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700540 return chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700541}
542
Avinash Patil78dfca62013-07-30 17:18:56 -0700543/* This function appends rate TLV to scan config command. */
544static int
545mwifiex_append_rate_tlv(struct mwifiex_private *priv,
546 struct mwifiex_scan_cmd_config *scan_cfg_out,
547 u8 radio)
548{
549 struct mwifiex_ie_types_rates_param_set *rates_tlv;
550 u8 rates[MWIFIEX_SUPPORTED_RATES], *tlv_pos;
551 u32 rates_size;
552
553 memset(rates, 0, sizeof(rates));
554
555 tlv_pos = (u8 *)scan_cfg_out->tlv_buf + scan_cfg_out->tlv_buf_len;
556
557 if (priv->scan_request)
558 rates_size = mwifiex_get_rates_from_cfg80211(priv, rates,
559 radio);
560 else
561 rates_size = mwifiex_get_supported_rates(priv, rates);
562
563 dev_dbg(priv->adapter->dev, "info: SCAN_CMD: Rates size = %d\n",
564 rates_size);
565 rates_tlv = (struct mwifiex_ie_types_rates_param_set *)tlv_pos;
566 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
567 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
568 memcpy(rates_tlv->rates, rates, rates_size);
569 scan_cfg_out->tlv_buf_len += sizeof(rates_tlv->header) + rates_size;
570
571 return rates_size;
572}
573
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700574/*
575 * This function constructs and sends multiple scan config commands to
576 * the firmware.
577 *
578 * Previous routines in the code flow have created a scan command configuration
579 * with any requested TLVs. This function splits the channel TLV into maximum
580 * channels supported per scan lists and sends the portion of the channel TLV,
581 * along with the other TLVs, to the firmware.
582 */
583static int
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700584mwifiex_scan_channel_list(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700585 u32 max_chan_per_scan, u8 filtered_scan,
586 struct mwifiex_scan_cmd_config *scan_cfg_out,
587 struct mwifiex_ie_types_chan_list_param_set
588 *chan_tlv_out,
589 struct mwifiex_chan_scan_param_set *scan_chan_list)
590{
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700591 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700592 int ret = 0;
593 struct mwifiex_chan_scan_param_set *tmp_chan_list;
594 struct mwifiex_chan_scan_param_set *start_chan;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700595 struct cmd_ctrl_node *cmd_node, *tmp_node;
596 unsigned long flags;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800597 u32 tlv_idx, rates_size, cmd_no;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700598 u32 total_scan_time;
599 u32 done_early;
Avinash Patil78dfca62013-07-30 17:18:56 -0700600 u8 radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700601
602 if (!scan_cfg_out || !chan_tlv_out || !scan_chan_list) {
603 dev_dbg(priv->adapter->dev,
604 "info: Scan: Null detect: %p, %p, %p\n",
605 scan_cfg_out, chan_tlv_out, scan_chan_list);
606 return -1;
607 }
608
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700609 /* Check csa channel expiry before preparing scan list */
610 mwifiex_11h_get_csa_closed_channel(priv);
611
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612 chan_tlv_out->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
613
614 /* Set the temp channel struct pointer to the start of the desired
615 list */
616 tmp_chan_list = scan_chan_list;
617
618 /* Loop through the desired channel list, sending a new firmware scan
619 commands for each max_chan_per_scan channels (or for 1,6,11
620 individually if configured accordingly) */
621 while (tmp_chan_list->chan_number) {
622
623 tlv_idx = 0;
624 total_scan_time = 0;
Avinash Patil78dfca62013-07-30 17:18:56 -0700625 radio_type = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700626 chan_tlv_out->header.len = 0;
627 start_chan = tmp_chan_list;
628 done_early = false;
629
630 /*
631 * Construct the Channel TLV for the scan command. Continue to
632 * insert channel TLVs until:
633 * - the tlv_idx hits the maximum configured per scan command
634 * - the next channel to insert is 0 (end of desired channel
635 * list)
636 * - done_early is set (controlling individual scanning of
637 * 1,6,11)
638 */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700639 while (tlv_idx < max_chan_per_scan &&
640 tmp_chan_list->chan_number && !done_early) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700641
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700642 if (tmp_chan_list->chan_number == priv->csa_chan) {
643 tmp_chan_list++;
644 continue;
645 }
646
Avinash Patil78dfca62013-07-30 17:18:56 -0700647 radio_type = tmp_chan_list->radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700648 dev_dbg(priv->adapter->dev,
649 "info: Scan: Chan(%3d), Radio(%d),"
650 " Mode(%d, %d), Dur(%d)\n",
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700651 tmp_chan_list->chan_number,
652 tmp_chan_list->radio_type,
653 tmp_chan_list->chan_scan_mode_bitmap
654 & MWIFIEX_PASSIVE_SCAN,
655 (tmp_chan_list->chan_scan_mode_bitmap
656 & MWIFIEX_DISABLE_CHAN_FILT) >> 1,
657 le16_to_cpu(tmp_chan_list->max_scan_time));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700658
659 /* Copy the current channel TLV to the command being
660 prepared */
661 memcpy(chan_tlv_out->chan_scan_param + tlv_idx,
662 tmp_chan_list,
663 sizeof(chan_tlv_out->chan_scan_param));
664
665 /* Increment the TLV header length by the size
666 appended */
Wei Yongjun5570a912012-09-28 12:59:43 +0800667 le16_add_cpu(&chan_tlv_out->header.len,
668 sizeof(chan_tlv_out->chan_scan_param));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700669
670 /*
671 * The tlv buffer length is set to the number of bytes
672 * of the between the channel tlv pointer and the start
673 * of the tlv buffer. This compensates for any TLVs
674 * that were appended before the channel list.
675 */
676 scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
677 scan_cfg_out->tlv_buf);
678
679 /* Add the size of the channel tlv header and the data
680 length */
681 scan_cfg_out->tlv_buf_len +=
682 (sizeof(chan_tlv_out->header)
683 + le16_to_cpu(chan_tlv_out->header.len));
684
685 /* Increment the index to the channel tlv we are
686 constructing */
687 tlv_idx++;
688
689 /* Count the total scan time per command */
690 total_scan_time +=
691 le16_to_cpu(tmp_chan_list->max_scan_time);
692
693 done_early = false;
694
695 /* Stop the loop if the *current* channel is in the
696 1,6,11 set and we are not filtering on a BSSID
697 or SSID. */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700698 if (!filtered_scan &&
699 (tmp_chan_list->chan_number == 1 ||
700 tmp_chan_list->chan_number == 6 ||
701 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700702 done_early = true;
703
704 /* Increment the tmp pointer to the next channel to
705 be scanned */
706 tmp_chan_list++;
707
708 /* Stop the loop if the *next* channel is in the 1,6,11
709 set. This will cause it to be the only channel
710 scanned on the next interation */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700711 if (!filtered_scan &&
712 (tmp_chan_list->chan_number == 1 ||
713 tmp_chan_list->chan_number == 6 ||
714 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700715 done_early = true;
716 }
717
718 /* The total scan time should be less than scan command timeout
719 value */
720 if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
721 dev_err(priv->adapter->dev, "total scan time %dms"
722 " is over limit (%dms), scan skipped\n",
723 total_scan_time, MWIFIEX_MAX_TOTAL_SCAN_TIME);
724 ret = -1;
725 break;
726 }
727
Avinash Patil78dfca62013-07-30 17:18:56 -0700728 rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out,
729 radio_type);
730
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700731 priv->adapter->scan_channels = start_chan;
732
733 /* Send the scan command to the firmware with the specified
734 cfg */
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800735 if (priv->adapter->ext_scan)
736 cmd_no = HostCmd_CMD_802_11_SCAN_EXT;
737 else
738 cmd_no = HostCmd_CMD_802_11_SCAN;
739
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800740 ret = mwifiex_send_cmd(priv, cmd_no, HostCmd_ACT_GEN_SET,
741 0, scan_cfg_out, false);
Avinash Patil78dfca62013-07-30 17:18:56 -0700742
743 /* rate IE is updated per scan command but same starting
744 * pointer is used each time so that rate IE from earlier
745 * scan_cfg_out->buf is overwritten with new one.
746 */
747 scan_cfg_out->tlv_buf_len -=
748 sizeof(struct mwifiex_ie_types_header) + rates_size;
749
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700750 if (ret) {
751 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
752 list_for_each_entry_safe(cmd_node, tmp_node,
753 &adapter->scan_pending_q,
754 list) {
755 list_del(&cmd_node->list);
756 cmd_node->wait_q_enabled = false;
757 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
758 }
759 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
760 flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700761 break;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700762 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700763 }
764
765 if (ret)
766 return -1;
767
768 return 0;
769}
770
771/*
772 * This function constructs a scan command configuration structure to use
773 * in scan commands.
774 *
775 * Application layer or other functions can invoke network scanning
776 * with a scan configuration supplied in a user scan configuration structure.
777 * This structure is used as the basis of one or many scan command configuration
778 * commands that are sent to the command processing module and eventually to the
779 * firmware.
780 *
781 * This function creates a scan command configuration structure based on the
782 * following user supplied parameters (if present):
783 * - SSID filter
784 * - BSSID filter
785 * - Number of Probes to be sent
786 * - Channel list
787 *
788 * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
789 * If the number of probes is not set, adapter default setting is used.
790 */
791static void
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700792mwifiex_config_scan(struct mwifiex_private *priv,
793 const struct mwifiex_user_scan_cfg *user_scan_in,
794 struct mwifiex_scan_cmd_config *scan_cfg_out,
795 struct mwifiex_ie_types_chan_list_param_set **chan_list_out,
796 struct mwifiex_chan_scan_param_set *scan_chan_list,
797 u8 *max_chan_per_scan, u8 *filtered_scan,
798 u8 *scan_current_only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700799{
800 struct mwifiex_adapter *adapter = priv->adapter;
801 struct mwifiex_ie_types_num_probes *num_probes_tlv;
Avinash Patilcb91be82014-09-12 20:08:54 +0530802 struct mwifiex_ie_types_scan_chan_gap *chan_gap_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700803 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800804 struct mwifiex_ie_types_bssid_list *bssid_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700805 u8 *tlv_pos;
806 u32 num_probes;
807 u32 ssid_len;
808 u32 chan_idx;
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700809 u32 chan_num;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700810 u32 scan_type;
811 u16 scan_dur;
812 u8 channel;
813 u8 radio_type;
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800814 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700815 u8 ssid_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700816 struct mwifiex_ie_types_htcap *ht_cap;
817
818 /* The tlv_buf_len is calculated for each scan command. The TLVs added
819 in this routine will be preserved since the routine that sends the
820 command will append channelTLVs at *chan_list_out. The difference
821 between the *chan_list_out and the tlv_buf start will be used to
822 calculate the size of anything we add in this routine. */
823 scan_cfg_out->tlv_buf_len = 0;
824
825 /* Running tlv pointer. Assigned to chan_list_out at end of function
826 so later routines know where channels can be added to the command
827 buf */
828 tlv_pos = scan_cfg_out->tlv_buf;
829
830 /* Initialize the scan as un-filtered; the flag is later set to TRUE
831 below if a SSID or BSSID filter is sent in the command */
832 *filtered_scan = false;
833
834 /* Initialize the scan as not being only on the current channel. If
835 the channel list is customized, only contains one channel, and is
836 the active channel, this is set true and data flow is not halted. */
837 *scan_current_only = false;
838
839 if (user_scan_in) {
840
841 /* Default the ssid_filter flag to TRUE, set false under
842 certain wildcard conditions and qualified by the existence
843 of an SSID list before marking the scan as filtered */
844 ssid_filter = true;
845
846 /* Set the BSS type scan filter, use Adapter setting if
847 unset */
848 scan_cfg_out->bss_mode =
849 (user_scan_in->bss_mode ? (u8) user_scan_in->
850 bss_mode : (u8) adapter->scan_mode);
851
852 /* Set the number of probes to send, use Adapter setting
853 if unset */
854 num_probes =
855 (user_scan_in->num_probes ? user_scan_in->
856 num_probes : adapter->scan_probes);
857
858 /*
859 * Set the BSSID filter to the incoming configuration,
860 * if non-zero. If not set, it will remain disabled
861 * (all zeros).
862 */
863 memcpy(scan_cfg_out->specific_bssid,
864 user_scan_in->specific_bssid,
865 sizeof(scan_cfg_out->specific_bssid));
866
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800867 if (adapter->ext_scan &&
868 !is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
869 bssid_tlv =
870 (struct mwifiex_ie_types_bssid_list *)tlv_pos;
871 bssid_tlv->header.type = cpu_to_le16(TLV_TYPE_BSSID);
872 bssid_tlv->header.len = cpu_to_le16(ETH_ALEN);
873 memcpy(bssid_tlv->bssid, user_scan_in->specific_bssid,
874 ETH_ALEN);
875 tlv_pos += sizeof(struct mwifiex_ie_types_bssid_list);
876 }
877
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800878 for (i = 0; i < user_scan_in->num_ssids; i++) {
879 ssid_len = user_scan_in->ssid_list[i].ssid_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700880
881 wildcard_ssid_tlv =
882 (struct mwifiex_ie_types_wildcard_ssid_params *)
883 tlv_pos;
884 wildcard_ssid_tlv->header.type =
885 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
886 wildcard_ssid_tlv->header.len = cpu_to_le16(
887 (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
888 max_ssid_length)));
Amitkumar Karwarfada10582011-11-09 21:36:21 -0800889
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800890 /*
891 * max_ssid_length = 0 tells firmware to perform
892 * specific scan for the SSID filled, whereas
893 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
894 * wildcard scan.
895 */
896 if (ssid_len)
897 wildcard_ssid_tlv->max_ssid_length = 0;
898 else
899 wildcard_ssid_tlv->max_ssid_length =
900 IEEE80211_MAX_SSID_LEN;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700901
902 memcpy(wildcard_ssid_tlv->ssid,
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800903 user_scan_in->ssid_list[i].ssid, ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700904
905 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
906 + le16_to_cpu(wildcard_ssid_tlv->header.len));
907
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800908 dev_dbg(adapter->dev, "info: scan: ssid[%d]: %s, %d\n",
909 i, wildcard_ssid_tlv->ssid,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700910 wildcard_ssid_tlv->max_ssid_length);
911
912 /* Empty wildcard ssid with a maxlen will match many or
913 potentially all SSIDs (maxlen == 32), therefore do
914 not treat the scan as
915 filtered. */
916 if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
917 ssid_filter = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700918 }
919
920 /*
921 * The default number of channels sent in the command is low to
922 * ensure the response buffer from the firmware does not
923 * truncate scan results. That is not an issue with an SSID
924 * or BSSID filter applied to the scan results in the firmware.
925 */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700926 if ((i && ssid_filter) ||
Bing Zhao84f6a952012-08-27 20:32:54 -0700927 !is_zero_ether_addr(scan_cfg_out->specific_bssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700928 *filtered_scan = true;
929 } else {
930 scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
931 num_probes = adapter->scan_probes;
932 }
933
934 /*
935 * If a specific BSSID or SSID is used, the number of channels in the
936 * scan command will be increased to the absolute maximum.
937 */
938 if (*filtered_scan)
939 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
940 else
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700941 *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700942
Avinash Patilcb91be82014-09-12 20:08:54 +0530943 if (user_scan_in->scan_chan_gap) {
944 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
945 dev_dbg(adapter->dev, "info: scan: channel gap = %d\n",
946 user_scan_in->scan_chan_gap);
947
948 chan_gap_tlv = (void *)tlv_pos;
949 chan_gap_tlv->header.type =
950 cpu_to_le16(TLV_TYPE_SCAN_CHANNEL_GAP);
951 chan_gap_tlv->header.len =
952 cpu_to_le16(sizeof(chan_gap_tlv->chan_gap));
953 chan_gap_tlv->chan_gap =
954 cpu_to_le16((user_scan_in->scan_chan_gap));
955
956 tlv_pos += sizeof(struct mwifiex_ie_types_scan_chan_gap);
957 }
958
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700959 /* If the input config or adapter has the number of Probes set,
960 add tlv */
961 if (num_probes) {
962
963 dev_dbg(adapter->dev, "info: scan: num_probes = %d\n",
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700964 num_probes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700965
966 num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
967 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
968 num_probes_tlv->header.len =
969 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
970 num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
971
972 tlv_pos += sizeof(num_probes_tlv->header) +
973 le16_to_cpu(num_probes_tlv->header.len);
974
975 }
976
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700977 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
978 (priv->adapter->config_bands & BAND_GN ||
979 priv->adapter->config_bands & BAND_AN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700980 ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
981 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
982 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
983 ht_cap->header.len =
984 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
Amitkumar Karwara46b7b52011-04-27 19:13:12 -0700985 radio_type =
986 mwifiex_band_to_radio_type(priv->adapter->config_bands);
Amitkumar Karwar341b8802014-02-07 16:27:31 -0800987 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700988 tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
989 }
990
991 /* Append vendor specific IE TLV */
992 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
993
994 /*
995 * Set the output for the channel TLV to the address in the tlv buffer
996 * past any TLVs that were added in this function (SSID, num_probes).
997 * Channel TLVs will be added past this for each scan command,
998 * preserving the TLVs that were previously added.
999 */
1000 *chan_list_out =
1001 (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
1002
1003 if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
1004
1005 dev_dbg(adapter->dev, "info: Scan: Using supplied channel list\n");
1006
1007 for (chan_idx = 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001008 chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX &&
1009 user_scan_in->chan_list[chan_idx].chan_number;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001010 chan_idx++) {
1011
1012 channel = user_scan_in->chan_list[chan_idx].chan_number;
1013 (scan_chan_list + chan_idx)->chan_number = channel;
1014
1015 radio_type =
1016 user_scan_in->chan_list[chan_idx].radio_type;
1017 (scan_chan_list + chan_idx)->radio_type = radio_type;
1018
1019 scan_type = user_scan_in->chan_list[chan_idx].scan_type;
1020
1021 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1022 (scan_chan_list +
1023 chan_idx)->chan_scan_mode_bitmap
1024 |= MWIFIEX_PASSIVE_SCAN;
1025 else
1026 (scan_chan_list +
1027 chan_idx)->chan_scan_mode_bitmap
1028 &= ~MWIFIEX_PASSIVE_SCAN;
1029
Amitkumar Karwarf3e1af32012-10-19 19:19:18 -07001030 if (*filtered_scan)
1031 (scan_chan_list +
1032 chan_idx)->chan_scan_mode_bitmap
1033 |= MWIFIEX_DISABLE_CHAN_FILT;
1034
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035 if (user_scan_in->chan_list[chan_idx].scan_time) {
1036 scan_dur = (u16) user_scan_in->
1037 chan_list[chan_idx].scan_time;
1038 } else {
1039 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1040 scan_dur = adapter->passive_scan_time;
1041 else if (*filtered_scan)
1042 scan_dur = adapter->specific_scan_time;
1043 else
1044 scan_dur = adapter->active_scan_time;
1045 }
1046
1047 (scan_chan_list + chan_idx)->min_scan_time =
1048 cpu_to_le16(scan_dur);
1049 (scan_chan_list + chan_idx)->max_scan_time =
1050 cpu_to_le16(scan_dur);
1051 }
1052
1053 /* Check if we are only scanning the current channel */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001054 if ((chan_idx == 1) &&
1055 (user_scan_in->chan_list[0].chan_number ==
1056 priv->curr_bss_params.bss_descriptor.channel)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001057 *scan_current_only = true;
1058 dev_dbg(adapter->dev,
1059 "info: Scan: Scanning current channel only\n");
1060 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001061 chan_num = chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001062 } else {
1063 dev_dbg(adapter->dev,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001064 "info: Scan: Creating full region channel list\n");
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001065 chan_num = mwifiex_scan_create_channel_list(priv, user_scan_in,
1066 scan_chan_list,
1067 *filtered_scan);
1068 }
1069
1070 /*
1071 * In associated state we will reduce the number of channels scanned per
Amitkumar Karwarb5413e62014-04-14 15:32:52 -07001072 * scan command to 1 to avoid any traffic delay/loss.
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001073 */
Amitkumar Karwarb5413e62014-04-14 15:32:52 -07001074 if (priv->media_connected)
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001075 *max_chan_per_scan = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001076}
1077
1078/*
1079 * This function inspects the scan response buffer for pointers to
1080 * expected TLVs.
1081 *
1082 * TLVs can be included at the end of the scan response BSS information.
1083 *
1084 * Data in the buffer is parsed pointers to TLVs that can potentially
1085 * be passed back in the response.
1086 */
1087static void
1088mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
1089 struct mwifiex_ie_types_data *tlv,
1090 u32 tlv_buf_size, u32 req_tlv_type,
1091 struct mwifiex_ie_types_data **tlv_data)
1092{
1093 struct mwifiex_ie_types_data *current_tlv;
1094 u32 tlv_buf_left;
1095 u32 tlv_type;
1096 u32 tlv_len;
1097
1098 current_tlv = tlv;
1099 tlv_buf_left = tlv_buf_size;
1100 *tlv_data = NULL;
1101
1102 dev_dbg(adapter->dev, "info: SCAN_RESP: tlv_buf_size = %d\n",
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001103 tlv_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001104
1105 while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
1106
1107 tlv_type = le16_to_cpu(current_tlv->header.type);
1108 tlv_len = le16_to_cpu(current_tlv->header.len);
1109
1110 if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
1111 dev_err(adapter->dev, "SCAN_RESP: TLV buffer corrupt\n");
1112 break;
1113 }
1114
1115 if (req_tlv_type == tlv_type) {
1116 switch (tlv_type) {
1117 case TLV_TYPE_TSFTIMESTAMP:
1118 dev_dbg(adapter->dev, "info: SCAN_RESP: TSF "
1119 "timestamp TLV, len = %d\n", tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001120 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001121 break;
1122 case TLV_TYPE_CHANNELBANDLIST:
1123 dev_dbg(adapter->dev, "info: SCAN_RESP: channel"
1124 " band list TLV, len = %d\n", tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001125 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001126 break;
1127 default:
1128 dev_err(adapter->dev,
1129 "SCAN_RESP: unhandled TLV = %d\n",
1130 tlv_type);
1131 /* Give up, this seems corrupted */
1132 return;
1133 }
1134 }
1135
1136 if (*tlv_data)
1137 break;
1138
1139
1140 tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
1141 current_tlv =
1142 (struct mwifiex_ie_types_data *) (current_tlv->data +
1143 tlv_len);
1144
1145 } /* while */
1146}
1147
1148/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001149 * This function parses provided beacon buffer and updates
1150 * respective fields in bss descriptor structure.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001151 */
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001152int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1153 struct mwifiex_bssdescriptor *bss_entry)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001154{
1155 int ret = 0;
1156 u8 element_id;
1157 struct ieee_types_fh_param_set *fh_param_set;
1158 struct ieee_types_ds_param_set *ds_param_set;
1159 struct ieee_types_cf_param_set *cf_param_set;
1160 struct ieee_types_ibss_param_set *ibss_param_set;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161 u8 *current_ptr;
1162 u8 *rate;
1163 u8 element_len;
1164 u16 total_ie_len;
1165 u8 bytes_to_copy;
1166 u8 rate_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001167 u8 found_data_rate_ie;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001168 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001169 struct ieee_types_vendor_specific *vendor_ie;
1170 const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
1171 const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
1172
1173 found_data_rate_ie = false;
1174 rate_size = 0;
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001175 current_ptr = bss_entry->beacon_buf;
1176 bytes_left = bss_entry->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177
1178 /* Process variable IE */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001179 while (bytes_left >= 2) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001180 element_id = *current_ptr;
1181 element_len = *(current_ptr + 1);
1182 total_ie_len = element_len + sizeof(struct ieee_types_header);
1183
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001184 if (bytes_left < total_ie_len) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001185 dev_err(adapter->dev, "err: InterpretIE: in processing"
1186 " IE, bytes left < IE length\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001187 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001188 }
1189 switch (element_id) {
1190 case WLAN_EID_SSID:
1191 bss_entry->ssid.ssid_len = element_len;
1192 memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
1193 element_len);
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001194 dev_dbg(adapter->dev,
1195 "info: InterpretIE: ssid: %-32s\n",
1196 bss_entry->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197 break;
1198
1199 case WLAN_EID_SUPP_RATES:
1200 memcpy(bss_entry->data_rates, current_ptr + 2,
1201 element_len);
1202 memcpy(bss_entry->supported_rates, current_ptr + 2,
1203 element_len);
1204 rate_size = element_len;
1205 found_data_rate_ie = true;
1206 break;
1207
1208 case WLAN_EID_FH_PARAMS:
1209 fh_param_set =
1210 (struct ieee_types_fh_param_set *) current_ptr;
1211 memcpy(&bss_entry->phy_param_set.fh_param_set,
1212 fh_param_set,
1213 sizeof(struct ieee_types_fh_param_set));
1214 break;
1215
1216 case WLAN_EID_DS_PARAMS:
1217 ds_param_set =
1218 (struct ieee_types_ds_param_set *) current_ptr;
1219
1220 bss_entry->channel = ds_param_set->current_chan;
1221
1222 memcpy(&bss_entry->phy_param_set.ds_param_set,
1223 ds_param_set,
1224 sizeof(struct ieee_types_ds_param_set));
1225 break;
1226
1227 case WLAN_EID_CF_PARAMS:
1228 cf_param_set =
1229 (struct ieee_types_cf_param_set *) current_ptr;
1230 memcpy(&bss_entry->ss_param_set.cf_param_set,
1231 cf_param_set,
1232 sizeof(struct ieee_types_cf_param_set));
1233 break;
1234
1235 case WLAN_EID_IBSS_PARAMS:
1236 ibss_param_set =
1237 (struct ieee_types_ibss_param_set *)
1238 current_ptr;
1239 memcpy(&bss_entry->ss_param_set.ibss_param_set,
1240 ibss_param_set,
1241 sizeof(struct ieee_types_ibss_param_set));
1242 break;
1243
1244 case WLAN_EID_ERP_INFO:
1245 bss_entry->erp_flags = *(current_ptr + 2);
1246 break;
1247
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -07001248 case WLAN_EID_PWR_CONSTRAINT:
1249 bss_entry->local_constraint = *(current_ptr + 2);
1250 bss_entry->sensed_11h = true;
1251 break;
1252
1253 case WLAN_EID_CHANNEL_SWITCH:
1254 bss_entry->chan_sw_ie_present = true;
1255 case WLAN_EID_PWR_CAPABILITY:
1256 case WLAN_EID_TPC_REPORT:
1257 case WLAN_EID_QUIET:
1258 bss_entry->sensed_11h = true;
1259 break;
1260
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261 case WLAN_EID_EXT_SUPP_RATES:
1262 /*
1263 * Only process extended supported rate
1264 * if data rate is already found.
1265 * Data rate IE should come before
1266 * extended supported rate IE
1267 */
1268 if (found_data_rate_ie) {
1269 if ((element_len + rate_size) >
1270 MWIFIEX_SUPPORTED_RATES)
1271 bytes_to_copy =
1272 (MWIFIEX_SUPPORTED_RATES -
1273 rate_size);
1274 else
1275 bytes_to_copy = element_len;
1276
1277 rate = (u8 *) bss_entry->data_rates;
1278 rate += rate_size;
1279 memcpy(rate, current_ptr + 2, bytes_to_copy);
1280
1281 rate = (u8 *) bss_entry->supported_rates;
1282 rate += rate_size;
1283 memcpy(rate, current_ptr + 2, bytes_to_copy);
1284 }
1285 break;
1286
1287 case WLAN_EID_VENDOR_SPECIFIC:
1288 vendor_ie = (struct ieee_types_vendor_specific *)
1289 current_ptr;
1290
1291 if (!memcmp
1292 (vendor_ie->vend_hdr.oui, wpa_oui,
1293 sizeof(wpa_oui))) {
1294 bss_entry->bcn_wpa_ie =
1295 (struct ieee_types_vendor_specific *)
1296 current_ptr;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001297 bss_entry->wpa_offset = (u16)
1298 (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001299 } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui,
1300 sizeof(wmm_oui))) {
1301 if (total_ie_len ==
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001302 sizeof(struct ieee_types_wmm_parameter) ||
1303 total_ie_len ==
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001304 sizeof(struct ieee_types_wmm_info))
1305 /*
1306 * Only accept and copy the WMM IE if
1307 * it matches the size expected for the
1308 * WMM Info IE or the WMM Parameter IE.
1309 */
1310 memcpy((u8 *) &bss_entry->wmm_ie,
1311 current_ptr, total_ie_len);
1312 }
1313 break;
1314 case WLAN_EID_RSN:
1315 bss_entry->bcn_rsn_ie =
1316 (struct ieee_types_generic *) current_ptr;
1317 bss_entry->rsn_offset = (u16) (current_ptr -
1318 bss_entry->beacon_buf);
1319 break;
1320 case WLAN_EID_BSS_AC_ACCESS_DELAY:
1321 bss_entry->bcn_wapi_ie =
1322 (struct ieee_types_generic *) current_ptr;
1323 bss_entry->wapi_offset = (u16) (current_ptr -
1324 bss_entry->beacon_buf);
1325 break;
1326 case WLAN_EID_HT_CAPABILITY:
1327 bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
1328 (current_ptr +
1329 sizeof(struct ieee_types_header));
1330 bss_entry->ht_cap_offset = (u16) (current_ptr +
1331 sizeof(struct ieee_types_header) -
1332 bss_entry->beacon_buf);
1333 break;
Johannes Berg074d46d2012-03-15 19:45:16 +01001334 case WLAN_EID_HT_OPERATION:
1335 bss_entry->bcn_ht_oper =
1336 (struct ieee80211_ht_operation *)(current_ptr +
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001337 sizeof(struct ieee_types_header));
1338 bss_entry->ht_info_offset = (u16) (current_ptr +
1339 sizeof(struct ieee_types_header) -
1340 bss_entry->beacon_buf);
1341 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001342 case WLAN_EID_VHT_CAPABILITY:
1343 bss_entry->disable_11ac = false;
1344 bss_entry->bcn_vht_cap =
1345 (void *)(current_ptr +
1346 sizeof(struct ieee_types_header));
1347 bss_entry->vht_cap_offset =
1348 (u16)((u8 *)bss_entry->bcn_vht_cap -
1349 bss_entry->beacon_buf);
1350 break;
1351 case WLAN_EID_VHT_OPERATION:
1352 bss_entry->bcn_vht_oper =
1353 (void *)(current_ptr +
1354 sizeof(struct ieee_types_header));
1355 bss_entry->vht_info_offset =
1356 (u16)((u8 *)bss_entry->bcn_vht_oper -
1357 bss_entry->beacon_buf);
1358 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001359 case WLAN_EID_BSS_COEX_2040:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001360 bss_entry->bcn_bss_co_2040 = current_ptr;
1361 bss_entry->bss_co_2040_offset =
1362 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001363 break;
1364 case WLAN_EID_EXT_CAPABILITY:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001365 bss_entry->bcn_ext_cap = current_ptr;
1366 bss_entry->ext_cap_offset =
1367 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001368 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001369 case WLAN_EID_OPMODE_NOTIF:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001370 bss_entry->oper_mode = (void *)current_ptr;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001371 bss_entry->oper_mode_offset =
1372 (u16)((u8 *)bss_entry->oper_mode -
1373 bss_entry->beacon_buf);
1374 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001375 default:
1376 break;
1377 }
1378
1379 current_ptr += element_len + 2;
1380
1381 /* Need to account for IE ID and IE Len */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001382 bytes_left -= (element_len + 2);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001383
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001384 } /* while (bytes_left > 2) */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001385 return ret;
1386}
1387
1388/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001389 * This function converts radio type scan parameter to a band configuration
1390 * to be used in join command.
1391 */
1392static u8
1393mwifiex_radio_type_to_band(u8 radio_type)
1394{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001395 switch (radio_type) {
1396 case HostCmd_SCAN_RADIO_TYPE_A:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001397 return BAND_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001398 case HostCmd_SCAN_RADIO_TYPE_BG:
1399 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001400 return BAND_G;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001401 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001402}
1403
1404/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001405 * This is an internal function used to start a scan based on an input
1406 * configuration.
1407 *
1408 * This uses the input user scan configuration information when provided in
1409 * order to send the appropriate scan commands to firmware to populate or
1410 * update the internal driver scan table.
1411 */
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001412int mwifiex_scan_networks(struct mwifiex_private *priv,
1413 const struct mwifiex_user_scan_cfg *user_scan_in)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001414{
Bing Zhaoc2476332012-10-05 20:21:40 -07001415 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001416 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001417 struct cmd_ctrl_node *cmd_node;
1418 union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001419 struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420 struct mwifiex_chan_scan_param_set *scan_chan_list;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001421 u8 filtered_scan;
1422 u8 scan_current_chan_only;
1423 u8 max_chan_per_scan;
1424 unsigned long flags;
1425
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001426 if (adapter->scan_processing) {
Bing Zhaoc2476332012-10-05 20:21:40 -07001427 dev_err(adapter->dev, "cmd: Scan already in process...\n");
1428 return -EBUSY;
1429 }
1430
1431 if (priv->scan_block) {
1432 dev_err(adapter->dev,
1433 "cmd: Scan is blocked during association...\n");
1434 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001435 }
1436
1437 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1438 adapter->scan_processing = true;
1439 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1440
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001441 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
Joe Perches0d2e7a52013-02-03 17:28:14 +00001442 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001443 if (!scan_cfg_out) {
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001444 ret = -ENOMEM;
1445 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001446 }
1447
Joe Perches0d2e7a52013-02-03 17:28:14 +00001448 scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
1449 sizeof(struct mwifiex_chan_scan_param_set),
1450 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001451 if (!scan_chan_list) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001452 kfree(scan_cfg_out);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001453 ret = -ENOMEM;
1454 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001455 }
1456
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001457 mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config,
1458 &chan_list_out, scan_chan_list, &max_chan_per_scan,
1459 &filtered_scan, &scan_current_chan_only);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001460
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001461 ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
1462 &scan_cfg_out->config, chan_list_out,
1463 scan_chan_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001464
1465 /* Get scan command from scan_pending_q and put to cmd_pending_q */
1466 if (!ret) {
1467 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1468 if (!list_empty(&adapter->scan_pending_q)) {
1469 cmd_node = list_first_entry(&adapter->scan_pending_q,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001470 struct cmd_ctrl_node, list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001471 list_del(&cmd_node->list);
1472 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001473 flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001474 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1475 true);
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001476 queue_work(adapter->workqueue, &adapter->main_work);
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001477
1478 /* Perform internal scan synchronously */
Bing Zhao21de9792013-04-01 12:44:45 -07001479 if (!priv->scan_request) {
1480 dev_dbg(adapter->dev, "wait internal scan\n");
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001481 mwifiex_wait_queue_complete(adapter, cmd_node);
Bing Zhao21de9792013-04-01 12:44:45 -07001482 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001483 } else {
1484 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1485 flags);
1486 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001487 }
1488
1489 kfree(scan_cfg_out);
1490 kfree(scan_chan_list);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001491done:
1492 if (ret) {
1493 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1494 adapter->scan_processing = false;
1495 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1496 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001497 return ret;
1498}
1499
1500/*
1501 * This function prepares a scan command to be sent to the firmware.
1502 *
1503 * This uses the scan command configuration sent to the command processing
1504 * module in command preparation stage to configure a scan command structure
1505 * to send to firmware.
1506 *
1507 * The fixed fields specifying the BSS type and BSSID filters as well as a
1508 * variable number/length of TLVs are sent in the command to firmware.
1509 *
1510 * Preparation also includes -
1511 * - Setting command ID, and proper size
1512 * - Ensuring correct endian-ness
1513 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001514int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1515 struct mwifiex_scan_cmd_config *scan_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001516{
1517 struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001518
1519 /* Set fixed field variables in scan command */
1520 scan_cmd->bss_mode = scan_cfg->bss_mode;
1521 memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
1522 sizeof(scan_cmd->bssid));
1523 memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
1524
1525 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
1526
1527 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
1528 cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
1529 + sizeof(scan_cmd->bssid)
1530 + scan_cfg->tlv_buf_len + S_DS_GEN));
1531
1532 return 0;
1533}
1534
1535/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001536 * This function checks compatibility of requested network with current
1537 * driver settings.
1538 */
1539int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1540 struct mwifiex_bssdescriptor *bss_desc)
1541{
1542 int ret = -1;
1543
1544 if (!bss_desc)
1545 return -1;
1546
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -07001547 if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
1548 (u16) bss_desc->channel, 0))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001549 switch (priv->bss_mode) {
1550 case NL80211_IFTYPE_STATION:
1551 case NL80211_IFTYPE_ADHOC:
1552 ret = mwifiex_is_network_compatible(priv, bss_desc,
1553 priv->bss_mode);
1554 if (ret)
Amitkumar Karwar069758842012-10-05 20:21:42 -07001555 dev_err(priv->adapter->dev,
1556 "Incompatible network settings\n");
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001557 break;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001558 default:
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001559 ret = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001560 }
1561 }
1562
1563 return ret;
1564}
1565
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001566static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1567 struct cfg80211_bss *bss)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001568{
Jesper Juhldb652e42011-11-06 22:58:31 +01001569 struct mwifiex_bssdescriptor *bss_desc;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001570 int ret;
1571 unsigned long flags;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001572
1573 /* Allocate and fill new bss descriptor */
Joe Perches0d2e7a52013-02-03 17:28:14 +00001574 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
1575 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001576 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07001577
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001578 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001579 if (ret)
1580 goto done;
1581
1582 ret = mwifiex_check_network_compatibility(priv, bss_desc);
1583 if (ret)
1584 goto done;
1585
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001586 spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001587 /* Make a copy of current BSSID descriptor */
1588 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001589 sizeof(priv->curr_bss_params.bss_descriptor));
Bing Zhaod837a2a2013-04-12 10:34:17 -07001590
1591 /* The contents of beacon_ie will be copied to its own buffer
1592 * in mwifiex_save_curr_bcn()
1593 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001594 mwifiex_save_curr_bcn(priv);
1595 spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
1596
1597done:
Bing Zhaod837a2a2013-04-12 10:34:17 -07001598 /* beacon_ie buffer was allocated in function
1599 * mwifiex_fill_new_bss_desc(). Free it now.
1600 */
1601 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001602 kfree(bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001603 return 0;
1604}
1605
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001606static int
1607mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info,
1608 u32 *bytes_left, u64 fw_tsf, u8 *radio_type,
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001609 bool ext_scan, s32 rssi_val)
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001610{
1611 struct mwifiex_adapter *adapter = priv->adapter;
1612 struct mwifiex_chan_freq_power *cfp;
1613 struct cfg80211_bss *bss;
1614 u8 bssid[ETH_ALEN];
1615 s32 rssi;
1616 const u8 *ie_buf;
1617 size_t ie_len;
1618 u16 channel = 0;
1619 u16 beacon_size = 0;
1620 u32 curr_bcn_bytes;
1621 u32 freq;
1622 u16 beacon_period;
1623 u16 cap_info_bitmap;
1624 u8 *current_ptr;
1625 u64 timestamp;
1626 struct mwifiex_fixed_bcn_param *bcn_param;
1627 struct mwifiex_bss_priv *bss_priv;
1628
1629 if (*bytes_left >= sizeof(beacon_size)) {
1630 /* Extract & convert beacon size from command buffer */
1631 memcpy(&beacon_size, *bss_info, sizeof(beacon_size));
1632 *bytes_left -= sizeof(beacon_size);
1633 *bss_info += sizeof(beacon_size);
1634 }
1635
1636 if (!beacon_size || beacon_size > *bytes_left) {
1637 *bss_info += *bytes_left;
1638 *bytes_left = 0;
1639 return -EFAULT;
1640 }
1641
1642 /* Initialize the current working beacon pointer for this BSS
1643 * iteration
1644 */
1645 current_ptr = *bss_info;
1646
1647 /* Advance the return beacon pointer past the current beacon */
1648 *bss_info += beacon_size;
1649 *bytes_left -= beacon_size;
1650
1651 curr_bcn_bytes = beacon_size;
1652
1653 /* First 5 fields are bssid, RSSI(for legacy scan only),
1654 * time stamp, beacon interval, and capability information
1655 */
1656 if (curr_bcn_bytes < ETH_ALEN + sizeof(u8) +
1657 sizeof(struct mwifiex_fixed_bcn_param)) {
1658 dev_err(adapter->dev, "InterpretIE: not enough bytes left\n");
1659 return -EFAULT;
1660 }
1661
1662 memcpy(bssid, current_ptr, ETH_ALEN);
1663 current_ptr += ETH_ALEN;
1664 curr_bcn_bytes -= ETH_ALEN;
1665
1666 if (!ext_scan) {
Joe Perches45d18c52014-03-24 13:15:39 -07001667 rssi = (s32) *current_ptr;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001668 rssi = (-rssi) * 100; /* Convert dBm to mBm */
1669 current_ptr += sizeof(u8);
1670 curr_bcn_bytes -= sizeof(u8);
1671 dev_dbg(adapter->dev, "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001672 } else {
1673 rssi = rssi_val;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001674 }
1675
1676 bcn_param = (struct mwifiex_fixed_bcn_param *)current_ptr;
1677 current_ptr += sizeof(*bcn_param);
1678 curr_bcn_bytes -= sizeof(*bcn_param);
1679
1680 timestamp = le64_to_cpu(bcn_param->timestamp);
1681 beacon_period = le16_to_cpu(bcn_param->beacon_period);
1682
1683 cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
1684 dev_dbg(adapter->dev, "info: InterpretIE: capabilities=0x%X\n",
1685 cap_info_bitmap);
1686
1687 /* Rest of the current buffer are IE's */
1688 ie_buf = current_ptr;
1689 ie_len = curr_bcn_bytes;
1690 dev_dbg(adapter->dev, "info: InterpretIE: IELength for this AP = %d\n",
1691 curr_bcn_bytes);
1692
1693 while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) {
1694 u8 element_id, element_len;
1695
1696 element_id = *current_ptr;
1697 element_len = *(current_ptr + 1);
1698 if (curr_bcn_bytes < element_len +
1699 sizeof(struct ieee_types_header)) {
1700 dev_err(adapter->dev,
1701 "%s: bytes left < IE length\n", __func__);
1702 return -EFAULT;
1703 }
1704 if (element_id == WLAN_EID_DS_PARAMS) {
1705 channel = *(current_ptr +
1706 sizeof(struct ieee_types_header));
1707 break;
1708 }
1709
1710 current_ptr += element_len + sizeof(struct ieee_types_header);
1711 curr_bcn_bytes -= element_len +
1712 sizeof(struct ieee_types_header);
1713 }
1714
1715 if (channel) {
1716 struct ieee80211_channel *chan;
1717 u8 band;
1718
1719 /* Skip entry if on csa closed channel */
1720 if (channel == priv->csa_chan) {
1721 dev_dbg(adapter->dev,
1722 "Dropping entry on csa closed channel\n");
1723 return 0;
1724 }
1725
1726 band = BAND_G;
1727 if (radio_type)
1728 band = mwifiex_radio_type_to_band(*radio_type &
1729 (BIT(0) | BIT(1)));
1730
1731 cfp = mwifiex_get_cfp(priv, band, channel, 0);
1732
1733 freq = cfp ? cfp->freq : 0;
1734
1735 chan = ieee80211_get_channel(priv->wdev->wiphy, freq);
1736
1737 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
1738 bss = cfg80211_inform_bss(priv->wdev->wiphy,
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02001739 chan, CFG80211_BSS_FTYPE_UNKNOWN,
1740 bssid, timestamp,
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001741 cap_info_bitmap, beacon_period,
1742 ie_buf, ie_len, rssi, GFP_KERNEL);
1743 bss_priv = (struct mwifiex_bss_priv *)bss->priv;
1744 bss_priv->band = band;
1745 bss_priv->fw_tsf = fw_tsf;
1746 if (priv->media_connected &&
1747 !memcmp(bssid, priv->curr_bss_params.bss_descriptor
1748 .mac_address, ETH_ALEN))
1749 mwifiex_update_curr_bss_params(priv, bss);
1750 cfg80211_put_bss(priv->wdev->wiphy, bss);
1751 }
1752 } else {
1753 dev_dbg(adapter->dev, "missing BSS channel IE\n");
1754 }
1755
1756 return 0;
1757}
1758
Avinash Patil21445042014-05-27 21:39:32 -07001759static void mwifiex_complete_scan(struct mwifiex_private *priv)
1760{
1761 struct mwifiex_adapter *adapter = priv->adapter;
1762
1763 if (adapter->curr_cmd->wait_q_enabled) {
1764 adapter->cmd_wait_q.status = 0;
1765 if (!priv->scan_request) {
1766 dev_dbg(adapter->dev, "complete internal scan\n");
1767 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1768 }
1769 }
1770}
1771
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001772static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1773{
1774 struct mwifiex_adapter *adapter = priv->adapter;
1775 struct cmd_ctrl_node *cmd_node;
1776 unsigned long flags;
1777
1778 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1779 if (list_empty(&adapter->scan_pending_q)) {
1780 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1781 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1782 adapter->scan_processing = false;
1783 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1784
Avinash Patil21445042014-05-27 21:39:32 -07001785 if (!adapter->ext_scan)
1786 mwifiex_complete_scan(priv);
1787
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001788 if (priv->report_scan_result)
1789 priv->report_scan_result = false;
1790
1791 if (priv->scan_request) {
1792 dev_dbg(adapter->dev, "info: notifying scan done\n");
1793 cfg80211_scan_done(priv->scan_request, 0);
1794 priv->scan_request = NULL;
1795 } else {
1796 priv->scan_aborting = false;
1797 dev_dbg(adapter->dev, "info: scan already aborted\n");
1798 }
1799 } else {
1800 if ((priv->scan_aborting && !priv->scan_request) ||
1801 priv->scan_block) {
1802 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1803 flags);
1804 adapter->scan_delay_cnt = MWIFIEX_MAX_SCAN_DELAY_CNT;
1805 mod_timer(&priv->scan_delay_timer, jiffies);
1806 dev_dbg(priv->adapter->dev,
1807 "info: %s: triggerring scan abort\n", __func__);
1808 } else if (!mwifiex_wmm_lists_empty(adapter) &&
1809 (priv->scan_request && (priv->scan_request->flags &
1810 NL80211_SCAN_FLAG_LOW_PRIORITY))) {
1811 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1812 flags);
1813 adapter->scan_delay_cnt = 1;
1814 mod_timer(&priv->scan_delay_timer, jiffies +
1815 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
1816 dev_dbg(priv->adapter->dev,
1817 "info: %s: deferring scan\n", __func__);
1818 } else {
1819 /* Get scan command from scan_pending_q and put to
1820 * cmd_pending_q
1821 */
1822 cmd_node = list_first_entry(&adapter->scan_pending_q,
1823 struct cmd_ctrl_node, list);
1824 list_del(&cmd_node->list);
1825 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1826 flags);
1827 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1828 true);
1829 }
1830 }
1831
1832 return;
1833}
1834
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001835/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001836 * This function handles the command response of scan.
1837 *
1838 * The response buffer for the scan command has the following
1839 * memory layout:
1840 *
1841 * .-------------------------------------------------------------.
1842 * | Header (4 * sizeof(t_u16)): Standard command response hdr |
1843 * .-------------------------------------------------------------.
1844 * | BufSize (t_u16) : sizeof the BSS Description data |
1845 * .-------------------------------------------------------------.
1846 * | NumOfSet (t_u8) : Number of BSS Descs returned |
1847 * .-------------------------------------------------------------.
1848 * | BSSDescription data (variable, size given in BufSize) |
1849 * .-------------------------------------------------------------.
1850 * | TLV data (variable, size calculated using Header->Size, |
1851 * | BufSize and sizeof the fixed fields above) |
1852 * .-------------------------------------------------------------.
1853 */
1854int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001855 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001856{
1857 int ret = 0;
1858 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001859 struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001860 struct mwifiex_ie_types_data *tlv_data;
1861 struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
1862 u8 *bss_info;
1863 u32 scan_resp_size;
1864 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001865 u32 idx;
1866 u32 tlv_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001867 struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
1868 struct chan_band_param_set *chan_band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001869 u8 is_bgscan_resp;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001870 __le64 fw_tsf = 0;
1871 u8 *radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001872
1873 is_bgscan_resp = (le16_to_cpu(resp->command)
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001874 == HostCmd_CMD_802_11_BG_SCAN_QUERY);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001875 if (is_bgscan_resp)
1876 scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
1877 else
1878 scan_rsp = &resp->params.scan_resp;
1879
1880
Bing Zhao67a50032011-07-13 18:38:34 -07001881 if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001882 dev_err(adapter->dev, "SCAN_RESP: too many AP returned (%d)\n",
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001883 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001884 ret = -1;
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08001885 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001886 }
1887
Amitkumar Karwarb8876642013-06-18 16:36:58 -07001888 /* Check csa channel expiry before parsing scan response */
1889 mwifiex_11h_get_csa_closed_channel(priv);
1890
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001891 bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
1892 dev_dbg(adapter->dev, "info: SCAN_RESP: bss_descript_size %d\n",
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001893 bytes_left);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001894
1895 scan_resp_size = le16_to_cpu(resp->size);
1896
1897 dev_dbg(adapter->dev,
1898 "info: SCAN_RESP: returned %d APs before parsing\n",
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001899 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001900
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001901 bss_info = scan_rsp->bss_desc_and_tlv_buffer;
1902
1903 /*
1904 * The size of the TLV buffer is equal to the entire command response
1905 * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
1906 * BSS Descriptions (bss_descript_size as bytesLef) and the command
1907 * response header (S_DS_GEN)
1908 */
1909 tlv_buf_size = scan_resp_size - (bytes_left
1910 + sizeof(scan_rsp->bss_descript_size)
1911 + sizeof(scan_rsp->number_of_sets)
1912 + S_DS_GEN);
1913
1914 tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
1915 bss_desc_and_tlv_buffer +
1916 bytes_left);
1917
1918 /* Search the TLV buffer space in the scan response for any valid
1919 TLVs */
1920 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
1921 TLV_TYPE_TSFTIMESTAMP,
1922 (struct mwifiex_ie_types_data **)
1923 &tsf_tlv);
1924
1925 /* Search the TLV buffer space in the scan response for any valid
1926 TLVs */
1927 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
1928 TLV_TYPE_CHANNELBANDLIST,
1929 (struct mwifiex_ie_types_data **)
1930 &chan_band_tlv);
1931
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001932 for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001933 /*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001934 * If the TSF TLV was appended to the scan results, save this
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001935 * entry's TSF value in the fw_tsf field. It is the firmware's
1936 * TSF value at the time the beacon or probe response was
1937 * received.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001938 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001939 if (tsf_tlv)
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07001940 memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
1941 sizeof(fw_tsf));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001942
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001943 if (chan_band_tlv) {
1944 chan_band = &chan_band_tlv->chan_band_param[idx];
1945 radio_type = &chan_band->radio_type;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001946 } else {
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001947 radio_type = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001948 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001949
1950 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
1951 &bytes_left,
1952 le64_to_cpu(fw_tsf),
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001953 radio_type, false, 0);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001954 if (ret)
1955 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001956 }
1957
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08001958check_next_scan:
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001959 mwifiex_check_next_scan_command(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001960 return ret;
1961}
1962
1963/*
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001964 * This function prepares an extended scan command to be sent to the firmware
1965 *
1966 * This uses the scan command configuration sent to the command processing
1967 * module in command preparation stage to configure a extended scan command
1968 * structure to send to firmware.
1969 */
1970int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
1971 struct host_cmd_ds_command *cmd,
1972 void *data_buf)
1973{
1974 struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan;
1975 struct mwifiex_scan_cmd_config *scan_cfg = data_buf;
1976
1977 memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
1978
1979 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT);
1980
1981 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
1982 cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved)
1983 + scan_cfg->tlv_buf_len + S_DS_GEN));
1984
1985 return 0;
1986}
1987
1988/* This function handles the command response of extended scan */
1989int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv)
1990{
Avinash Patil3223db22014-09-12 20:08:48 +05301991 struct mwifiex_adapter *adapter = priv->adapter;
1992 struct host_cmd_ds_command *cmd_ptr;
1993 struct cmd_ctrl_node *cmd_node;
1994 unsigned long cmd_flags, scan_flags;
1995 bool complete_scan = false;
1996
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001997 dev_dbg(priv->adapter->dev, "info: EXT scan returns successfully\n");
Avinash Patil21445042014-05-27 21:39:32 -07001998
Avinash Patil3223db22014-09-12 20:08:48 +05301999 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
2000 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
2001 if (list_empty(&adapter->scan_pending_q)) {
2002 complete_scan = true;
2003 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
2004 cmd_ptr = (void *)cmd_node->cmd_skb->data;
2005 if (le16_to_cpu(cmd_ptr->command) ==
2006 HostCmd_CMD_802_11_SCAN_EXT) {
2007 dev_dbg(priv->adapter->dev,
2008 "Scan pending in command pending list");
2009 complete_scan = false;
2010 break;
2011 }
2012 }
2013 }
2014 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags);
2015 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags);
2016
2017 if (complete_scan)
2018 mwifiex_complete_scan(priv);
Avinash Patil21445042014-05-27 21:39:32 -07002019
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002020 return 0;
2021}
2022
2023/* This function This function handles the event extended scan report. It
2024 * parses extended scan results and informs to cfg80211 stack.
2025 */
2026int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
2027 void *buf)
2028{
2029 int ret = 0;
2030 struct mwifiex_adapter *adapter = priv->adapter;
2031 u8 *bss_info;
2032 u32 bytes_left, bytes_left_for_tlv, idx;
2033 u16 type, len;
2034 struct mwifiex_ie_types_data *tlv;
2035 struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv;
2036 struct mwifiex_ie_types_bss_scan_info *scan_info_tlv;
2037 u8 *radio_type;
2038 u64 fw_tsf = 0;
2039 s32 rssi = 0;
2040 struct mwifiex_event_scan_result *event_scan = buf;
2041 u8 num_of_set = event_scan->num_of_set;
2042 u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
2043 u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
2044
2045 if (num_of_set > MWIFIEX_MAX_AP) {
2046 dev_err(adapter->dev,
2047 "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
2048 num_of_set);
2049 ret = -1;
2050 goto check_next_scan;
2051 }
2052
2053 bytes_left = scan_resp_size;
2054 dev_dbg(adapter->dev,
2055 "EXT_SCAN: size %d, returned %d APs...",
2056 scan_resp_size, num_of_set);
2057
2058 tlv = (struct mwifiex_ie_types_data *)scan_resp;
2059
2060 for (idx = 0; idx < num_of_set && bytes_left; idx++) {
2061 type = le16_to_cpu(tlv->header.type);
2062 len = le16_to_cpu(tlv->header.len);
2063 if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) {
2064 dev_err(adapter->dev, "EXT_SCAN: Error bytes left < TLV length\n");
2065 break;
2066 }
2067 scan_rsp_tlv = NULL;
2068 scan_info_tlv = NULL;
2069 bytes_left_for_tlv = bytes_left;
2070
2071 /* BSS response TLV with beacon or probe response buffer
2072 * at the initial position of each descriptor
2073 */
2074 if (type != TLV_TYPE_BSS_SCAN_RSP)
2075 break;
2076
2077 bss_info = (u8 *)tlv;
2078 scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv;
2079 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2080 bytes_left_for_tlv -=
2081 (len + sizeof(struct mwifiex_ie_types_header));
2082
2083 while (bytes_left_for_tlv >=
2084 sizeof(struct mwifiex_ie_types_header) &&
2085 le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) {
2086 type = le16_to_cpu(tlv->header.type);
2087 len = le16_to_cpu(tlv->header.len);
2088 if (bytes_left_for_tlv <
2089 sizeof(struct mwifiex_ie_types_header) + len) {
2090 dev_err(adapter->dev,
2091 "EXT_SCAN: Error in processing TLV, bytes left < TLV length\n");
2092 scan_rsp_tlv = NULL;
2093 bytes_left_for_tlv = 0;
2094 continue;
2095 }
2096 switch (type) {
2097 case TLV_TYPE_BSS_SCAN_INFO:
2098 scan_info_tlv =
2099 (struct mwifiex_ie_types_bss_scan_info *)tlv;
2100 if (len !=
2101 sizeof(struct mwifiex_ie_types_bss_scan_info) -
2102 sizeof(struct mwifiex_ie_types_header)) {
2103 bytes_left_for_tlv = 0;
2104 continue;
2105 }
2106 break;
2107 default:
2108 break;
2109 }
2110 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2111 bytes_left -=
2112 (len + sizeof(struct mwifiex_ie_types_header));
2113 bytes_left_for_tlv -=
2114 (len + sizeof(struct mwifiex_ie_types_header));
2115 }
2116
2117 if (!scan_rsp_tlv)
2118 break;
2119
2120 /* Advance pointer to the beacon buffer length and
2121 * update the bytes count so that the function
2122 * wlan_interpret_bss_desc_with_ie() can handle the
2123 * scan buffer withut any change
2124 */
2125 bss_info += sizeof(u16);
2126 bytes_left -= sizeof(u16);
2127
2128 if (scan_info_tlv) {
2129 rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi));
2130 rssi *= 100; /* Convert dBm to mBm */
2131 dev_dbg(adapter->dev,
2132 "info: InterpretIE: RSSI=%d\n", rssi);
2133 fw_tsf = le64_to_cpu(scan_info_tlv->tsf);
2134 radio_type = &scan_info_tlv->radio_type;
2135 } else {
2136 radio_type = NULL;
2137 }
2138 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2139 &bytes_left, fw_tsf,
2140 radio_type, true, rssi);
2141 if (ret)
2142 goto check_next_scan;
2143 }
2144
2145check_next_scan:
2146 if (!event_scan->more_event)
2147 mwifiex_check_next_scan_command(priv);
2148
2149 return ret;
2150}
2151
2152/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002153 * This function prepares command for background scan query.
2154 *
2155 * Preparation includes -
2156 * - Setting command ID and proper size
2157 * - Setting background scan flush parameter
2158 * - Ensuring correct endian-ness
2159 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002160int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002161{
2162 struct host_cmd_ds_802_11_bg_scan_query *bg_query =
2163 &cmd->params.bg_scan_query;
2164
2165 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
2166 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
2167 + S_DS_GEN);
2168
2169 bg_query->flush = 1;
2170
2171 return 0;
2172}
2173
2174/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002175 * This function inserts scan command node to the scan pending queue.
2176 */
2177void
2178mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
2179 struct cmd_ctrl_node *cmd_node)
2180{
2181 struct mwifiex_adapter *adapter = priv->adapter;
2182 unsigned long flags;
2183
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002184 cmd_node->wait_q_enabled = true;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002185 cmd_node->condition = &adapter->scan_wait_q_woken;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002186 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
2187 list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
2188 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2189}
2190
2191/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002192 * This function sends a scan command for all available channels to the
2193 * firmware, filtered on a specific SSID.
2194 */
2195static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002196 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002197{
2198 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhaodcd5c792012-10-19 19:01:59 -07002199 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002200 struct mwifiex_user_scan_cfg *scan_cfg;
2201
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002202 if (adapter->scan_processing) {
Bing Zhaodcd5c792012-10-19 19:01:59 -07002203 dev_err(adapter->dev, "cmd: Scan already in process...\n");
2204 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002205 }
2206
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002207 if (priv->scan_block) {
Bing Zhaodcd5c792012-10-19 19:01:59 -07002208 dev_err(adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002209 "cmd: Scan is blocked during association...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002210 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002211 }
2212
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002213 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002214 if (!scan_cfg)
Christoph Fritzb53575e2011-05-08 22:50:09 +02002215 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002216
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08002217 scan_cfg->ssid_list = req_ssid;
2218 scan_cfg->num_ssids = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002219
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002220 ret = mwifiex_scan_networks(priv, scan_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002221
2222 kfree(scan_cfg);
2223 return ret;
2224}
2225
2226/*
2227 * Sends IOCTL request to start a scan.
2228 *
2229 * This function allocates the IOCTL request buffer, fills it
2230 * with requisite parameters and calls the IOCTL handler.
2231 *
2232 * Scan command can be issued for both normal scan and specific SSID
2233 * scan, depending upon whether an SSID is provided or not.
2234 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002235int mwifiex_request_scan(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002236 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002237{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002238 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002239
2240 if (down_interruptible(&priv->async_sem)) {
2241 dev_err(priv->adapter->dev, "%s: acquire semaphore\n",
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002242 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002243 return -1;
2244 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002245
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002246 priv->adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002247
2248 if (req_ssid && req_ssid->ssid_len != 0)
2249 /* Specific SSID scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002250 ret = mwifiex_scan_specific_ssid(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002251 else
2252 /* Normal scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002253 ret = mwifiex_scan_networks(priv, NULL);
2254
Amitkumar Karwarb0e70c22012-10-19 19:19:17 -07002255 up(&priv->async_sem);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002256
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002257 return ret;
2258}
2259
2260/*
2261 * This function appends the vendor specific IE TLV to a buffer.
2262 */
2263int
2264mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
2265 u16 vsie_mask, u8 **buffer)
2266{
2267 int id, ret_len = 0;
2268 struct mwifiex_ie_types_vendor_param_set *vs_param_set;
2269
2270 if (!buffer)
2271 return 0;
2272 if (!(*buffer))
2273 return 0;
2274
2275 /*
2276 * Traverse through the saved vendor specific IE array and append
2277 * the selected(scan/assoc/adhoc) IE as TLV to the command
2278 */
2279 for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
2280 if (priv->vs_ie[id].mask & vsie_mask) {
2281 vs_param_set =
2282 (struct mwifiex_ie_types_vendor_param_set *)
2283 *buffer;
2284 vs_param_set->header.type =
2285 cpu_to_le16(TLV_TYPE_PASSTHROUGH);
2286 vs_param_set->header.len =
2287 cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
2288 & 0x00FF) + 2);
2289 memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
2290 le16_to_cpu(vs_param_set->header.len));
2291 *buffer += le16_to_cpu(vs_param_set->header.len) +
2292 sizeof(struct mwifiex_ie_types_header);
2293 ret_len += le16_to_cpu(vs_param_set->header.len) +
2294 sizeof(struct mwifiex_ie_types_header);
2295 }
2296 }
2297 return ret_len;
2298}
2299
2300/*
2301 * This function saves a beacon buffer of the current BSS descriptor.
2302 *
2303 * The current beacon buffer is saved so that it can be restored in the
2304 * following cases that makes the beacon buffer not to contain the current
2305 * ssid's beacon buffer.
2306 * - The current ssid was not found somehow in the last scan.
2307 * - The current ssid was the last entry of the scan table and overloaded.
2308 */
2309void
2310mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2311{
2312 struct mwifiex_bssdescriptor *curr_bss =
2313 &priv->curr_bss_params.bss_descriptor;
2314
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002315 if (!curr_bss->beacon_buf_size)
2316 return;
2317
2318 /* allocate beacon buffer at 1st time; or if it's size has changed */
2319 if (!priv->curr_bcn_buf ||
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002320 priv->curr_bcn_size != curr_bss->beacon_buf_size) {
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002321 priv->curr_bcn_size = curr_bss->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002322
2323 kfree(priv->curr_bcn_buf);
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07002324 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002325 GFP_ATOMIC);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002326 if (!priv->curr_bcn_buf)
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002327 return;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002328 }
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002329
2330 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002331 curr_bss->beacon_buf_size);
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002332 dev_dbg(priv->adapter->dev, "info: current beacon saved %d\n",
2333 priv->curr_bcn_size);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002334
2335 curr_bss->beacon_buf = priv->curr_bcn_buf;
2336
2337 /* adjust the pointers in the current BSS descriptor */
2338 if (curr_bss->bcn_wpa_ie)
2339 curr_bss->bcn_wpa_ie =
2340 (struct ieee_types_vendor_specific *)
2341 (curr_bss->beacon_buf +
2342 curr_bss->wpa_offset);
2343
2344 if (curr_bss->bcn_rsn_ie)
2345 curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
2346 (curr_bss->beacon_buf +
2347 curr_bss->rsn_offset);
2348
2349 if (curr_bss->bcn_ht_cap)
2350 curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
2351 (curr_bss->beacon_buf +
2352 curr_bss->ht_cap_offset);
2353
Johannes Berg074d46d2012-03-15 19:45:16 +01002354 if (curr_bss->bcn_ht_oper)
2355 curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002356 (curr_bss->beacon_buf +
2357 curr_bss->ht_info_offset);
2358
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002359 if (curr_bss->bcn_vht_cap)
Amitkumar Karward5124642014-03-04 18:43:14 -08002360 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2361 curr_bss->vht_cap_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002362
2363 if (curr_bss->bcn_vht_oper)
Amitkumar Karward5124642014-03-04 18:43:14 -08002364 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2365 curr_bss->vht_info_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002366
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002367 if (curr_bss->bcn_bss_co_2040)
2368 curr_bss->bcn_bss_co_2040 =
Joe Perches2c208892012-06-04 12:44:17 +00002369 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002370
2371 if (curr_bss->bcn_ext_cap)
Joe Perches2c208892012-06-04 12:44:17 +00002372 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2373 curr_bss->ext_cap_offset;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002374
2375 if (curr_bss->oper_mode)
2376 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2377 curr_bss->oper_mode_offset);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002378}
2379
2380/*
2381 * This function frees the current BSS descriptor beacon buffer.
2382 */
2383void
2384mwifiex_free_curr_bcn(struct mwifiex_private *priv)
2385{
2386 kfree(priv->curr_bcn_buf);
2387 priv->curr_bcn_buf = NULL;
2388}