blob: 11d57185a090d7e0ffe8ed51c97cc85ef144b830 [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
Andreas Fenkart679b6872016-03-10 09:44:08 +010079static void
80_dbg_security_flags(int log_level, const char *func, const char *desc,
81 struct mwifiex_private *priv,
82 struct mwifiex_bssdescriptor *bss_desc)
83{
84 _mwifiex_dbg(priv->adapter, log_level,
85 "info: %s: %s:\twpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s\tEncMode=%#x privacy=%#x\n",
86 func, desc,
87 bss_desc->bcn_wpa_ie ?
88 bss_desc->bcn_wpa_ie->vend_hdr.element_id : 0,
89 bss_desc->bcn_rsn_ie ?
90 bss_desc->bcn_rsn_ie->ieee_hdr.element_id : 0,
91 priv->sec_info.wep_enabled ? "e" : "d",
92 priv->sec_info.wpa_enabled ? "e" : "d",
93 priv->sec_info.wpa2_enabled ? "e" : "d",
94 priv->sec_info.encryption_mode,
95 bss_desc->privacy);
96}
97#define dbg_security_flags(mask, desc, priv, bss_desc) \
98 _dbg_security_flags(MWIFIEX_DBG_##mask, desc, __func__, priv, bss_desc)
99
Andreas Fenkart38329562016-03-10 09:44:06 +0100100static bool
101has_ieee_hdr(struct ieee_types_generic *ie, u8 key)
102{
103 return (ie && ie->ieee_hdr.element_id == key);
104}
105
106static bool
107has_vendor_hdr(struct ieee_types_vendor_specific *ie, u8 key)
108{
109 return (ie && ie->vend_hdr.element_id == key);
110}
111
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700112/*
113 * This function parses a given IE for a given OUI.
114 *
115 * This is used to parse a WPA/RSN IE to find if it has
116 * a given oui in PTK.
117 */
118static u8
119mwifiex_search_oui_in_ie(struct ie_body *iebody, u8 *oui)
120{
121 u8 count;
122
123 count = iebody->ptk_cnt[0];
124
125 /* There could be multiple OUIs for PTK hence
126 1) Take the length.
127 2) Check all the OUIs for AES.
128 3) If one of them is AES then pass success. */
129 while (count) {
130 if (!memcmp(iebody->ptk_body, oui, sizeof(iebody->ptk_body)))
131 return MWIFIEX_OUI_PRESENT;
132
133 --count;
134 if (count)
135 iebody = (struct ie_body *) ((u8 *) iebody +
136 sizeof(iebody->ptk_body));
137 }
138
139 pr_debug("info: %s: OUI is not found in PTK\n", __func__);
140 return MWIFIEX_OUI_NOT_PRESENT;
141}
142
143/*
144 * This function checks if a given OUI is present in a RSN IE.
145 *
146 * The function first checks if a RSN IE is present or not in the
147 * BSS descriptor. It tries to locate the OUI only if such an IE is
148 * present.
149 */
150static u8
151mwifiex_is_rsn_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
152{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700153 u8 *oui;
154 struct ie_body *iebody;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700155 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
156
Andreas Fenkart38329562016-03-10 09:44:06 +0100157 if (has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700158 iebody = (struct ie_body *)
159 (((u8 *) bss_desc->bcn_rsn_ie->data) +
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700160 RSN_GTK_OUI_OFFSET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700161 oui = &mwifiex_rsn_oui[cipher][0];
162 ret = mwifiex_search_oui_in_ie(iebody, oui);
163 if (ret)
164 return ret;
165 }
166 return ret;
167}
168
169/*
170 * This function checks if a given OUI is present in a WPA IE.
171 *
172 * The function first checks if a WPA IE is present or not in the
173 * BSS descriptor. It tries to locate the OUI only if such an IE is
174 * present.
175 */
176static u8
177mwifiex_is_wpa_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
178{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700179 u8 *oui;
180 struct ie_body *iebody;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700181 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
182
Andreas Fenkart38329562016-03-10 09:44:06 +0100183 if (has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700184 iebody = (struct ie_body *) bss_desc->bcn_wpa_ie->data;
185 oui = &mwifiex_wpa_oui[cipher][0];
186 ret = mwifiex_search_oui_in_ie(iebody, oui);
187 if (ret)
188 return ret;
189 }
190 return ret;
191}
192
193/*
194 * This function compares two SSIDs and checks if they match.
195 */
196s32
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800197mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700198{
199 if (!ssid1 || !ssid2 || (ssid1->ssid_len != ssid2->ssid_len))
200 return -1;
201 return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssid_len);
202}
203
204/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700205 * This function checks if wapi is enabled in driver and scanned network is
206 * compatible with it.
207 */
208static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700209mwifiex_is_bss_wapi(struct mwifiex_private *priv,
210 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700211{
212 if (priv->sec_info.wapi_enabled &&
Andreas Fenkart38329562016-03-10 09:44:06 +0100213 has_ieee_hdr(bss_desc->bcn_wapi_ie, WLAN_EID_BSS_AC_ACCESS_DELAY))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700214 return true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700215 return false;
216}
217
218/*
219 * This function checks if driver is configured with no security mode and
220 * scanned network is compatible with it.
221 */
222static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700223mwifiex_is_bss_no_sec(struct mwifiex_private *priv,
224 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700225{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800226 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Andreas Fenkart0a233c92016-03-10 09:44:05 +0100227 !priv->sec_info.wpa2_enabled &&
Andreas Fenkart38329562016-03-10 09:44:06 +0100228 !has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC) &&
229 !has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700230 !priv->sec_info.encryption_mode && !bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700231 return true;
232 }
233 return false;
234}
235
236/*
237 * This function checks if static WEP is enabled in driver and scanned network
238 * is compatible with it.
239 */
240static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700241mwifiex_is_bss_static_wep(struct mwifiex_private *priv,
242 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700243{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800244 if (priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
245 !priv->sec_info.wpa2_enabled && bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700246 return true;
247 }
248 return false;
249}
250
251/*
252 * This function checks if wpa is enabled in driver and scanned network is
253 * compatible with it.
254 */
255static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700256mwifiex_is_bss_wpa(struct mwifiex_private *priv,
257 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800259 if (!priv->sec_info.wep_enabled && priv->sec_info.wpa_enabled &&
Andreas Fenkart0a233c92016-03-10 09:44:05 +0100260 !priv->sec_info.wpa2_enabled &&
Andreas Fenkart38329562016-03-10 09:44:06 +0100261 has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700262 /*
263 * Privacy bit may NOT be set in some APs like
264 * LinkSys WRT54G && bss_desc->privacy
265 */
266 ) {
Andreas Fenkart679b6872016-03-10 09:44:08 +0100267 dbg_security_flags(INFO, "WPA", priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700268 return true;
269 }
270 return false;
271}
272
273/*
274 * This function checks if wpa2 is enabled in driver and scanned network is
275 * compatible with it.
276 */
277static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700278mwifiex_is_bss_wpa2(struct mwifiex_private *priv,
279 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280{
Andreas Fenkart0a233c92016-03-10 09:44:05 +0100281 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700282 priv->sec_info.wpa2_enabled &&
Andreas Fenkart38329562016-03-10 09:44:06 +0100283 has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN)) {
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700284 /*
285 * Privacy bit may NOT be set in some APs like
286 * LinkSys WRT54G && bss_desc->privacy
287 */
Andreas Fenkart679b6872016-03-10 09:44:08 +0100288 dbg_security_flags(INFO, "WAP2", priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700289 return true;
290 }
291 return false;
292}
293
294/*
295 * This function checks if adhoc AES is enabled in driver and scanned network is
296 * compatible with it.
297 */
298static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700299mwifiex_is_bss_adhoc_aes(struct mwifiex_private *priv,
300 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700301{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800302 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700303 !priv->sec_info.wpa2_enabled &&
Andreas Fenkart38329562016-03-10 09:44:06 +0100304 !has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC) &&
305 !has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700306 !priv->sec_info.encryption_mode && bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700307 return true;
308 }
309 return false;
310}
311
312/*
313 * This function checks if dynamic WEP is enabled in driver and scanned network
314 * is compatible with it.
315 */
316static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700317mwifiex_is_bss_dynamic_wep(struct mwifiex_private *priv,
318 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700319{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800320 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700321 !priv->sec_info.wpa2_enabled &&
Andreas Fenkart38329562016-03-10 09:44:06 +0100322 !has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC) &&
323 !has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700324 priv->sec_info.encryption_mode && bss_desc->privacy) {
Andreas Fenkart679b6872016-03-10 09:44:08 +0100325 dbg_security_flags(INFO, "dynamic", priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700326 return true;
327 }
328 return false;
329}
330
331/*
332 * This function checks if a scanned network is compatible with the driver
333 * settings.
334 *
335 * WEP WPA WPA2 ad-hoc encrypt Network
336 * enabled enabled enabled AES mode Privacy WPA WPA2 Compatible
337 * 0 0 0 0 NONE 0 0 0 yes No security
338 * 0 1 0 0 x 1x 1 x yes WPA (disable
339 * HT if no AES)
340 * 0 0 1 0 x 1x x 1 yes WPA2 (disable
341 * HT if no AES)
342 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
343 * 1 0 0 0 NONE 1 0 0 yes Static WEP
344 * (disable HT)
345 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
346 *
347 * Compatibility is not matched while roaming, except for mode.
348 */
349static s32
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700350mwifiex_is_network_compatible(struct mwifiex_private *priv,
351 struct mwifiex_bssdescriptor *bss_desc, u32 mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700352{
353 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700354
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355 bss_desc->disable_11n = false;
356
357 /* Don't check for compatibility if roaming */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700358 if (priv->media_connected &&
359 (priv->bss_mode == NL80211_IFTYPE_STATION) &&
360 (bss_desc->bss_mode == NL80211_IFTYPE_STATION))
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700361 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362
363 if (priv->wps.session_enable) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530364 mwifiex_dbg(adapter, IOCTL,
365 "info: return success directly in WPS period\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700366 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700367 }
368
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700369 if (bss_desc->chan_sw_ie_present) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530370 mwifiex_dbg(adapter, INFO,
371 "Don't connect to AP with WLAN_EID_CHANNEL_SWITCH\n");
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700372 return -1;
373 }
374
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700375 if (mwifiex_is_bss_wapi(priv, bss_desc)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530376 mwifiex_dbg(adapter, INFO,
377 "info: return success for WAPI AP\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700378 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700379 }
380
381 if (bss_desc->bss_mode == mode) {
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700382 if (mwifiex_is_bss_no_sec(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700383 /* No security */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700384 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700385 } else if (mwifiex_is_bss_static_wep(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700386 /* Static WEP enabled */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530387 mwifiex_dbg(adapter, INFO,
388 "info: Disable 11n in WEP mode.\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700389 bss_desc->disable_11n = true;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700390 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700391 } else if (mwifiex_is_bss_wpa(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700392 /* WPA enabled */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700393 if (((priv->adapter->config_bands & BAND_GN ||
394 priv->adapter->config_bands & BAND_AN) &&
395 bss_desc->bcn_ht_cap) &&
396 !mwifiex_is_wpa_oui_present(bss_desc,
397 CIPHER_SUITE_CCMP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700399 if (mwifiex_is_wpa_oui_present
400 (bss_desc, CIPHER_SUITE_TKIP)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530401 mwifiex_dbg(adapter, INFO,
402 "info: Disable 11n if AES\t"
403 "is not supported by AP\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404 bss_desc->disable_11n = true;
405 } else {
406 return -1;
407 }
408 }
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700409 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700410 } else if (mwifiex_is_bss_wpa2(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700411 /* WPA2 enabled */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700412 if (((priv->adapter->config_bands & BAND_GN ||
413 priv->adapter->config_bands & BAND_AN) &&
414 bss_desc->bcn_ht_cap) &&
415 !mwifiex_is_rsn_oui_present(bss_desc,
416 CIPHER_SUITE_CCMP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700417
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700418 if (mwifiex_is_rsn_oui_present
419 (bss_desc, CIPHER_SUITE_TKIP)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530420 mwifiex_dbg(adapter, INFO,
421 "info: Disable 11n if AES\t"
422 "is not supported by AP\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700423 bss_desc->disable_11n = true;
424 } else {
425 return -1;
426 }
427 }
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700428 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700429 } else if (mwifiex_is_bss_adhoc_aes(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700430 /* Ad-hoc AES enabled */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700431 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700432 } else if (mwifiex_is_bss_dynamic_wep(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700433 /* Dynamic WEP enabled */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700434 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700435 }
436
437 /* Security doesn't match */
Andreas Fenkart679b6872016-03-10 09:44:08 +0100438 dbg_security_flags(ERROR, "failed", priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700439 return -1;
440 }
441
442 /* Mode doesn't match */
443 return -1;
444}
445
446/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700447 * This function creates a channel list for the driver to scan, based
448 * on region/band information.
449 *
450 * This routine is used for any scan that is not provided with a
451 * specific channel list to scan.
452 */
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700453static int
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700454mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700455 const struct mwifiex_user_scan_cfg
456 *user_scan_in,
457 struct mwifiex_chan_scan_param_set
458 *scan_chan_list,
459 u8 filtered_scan)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700460{
Johannes Berg57fbcce2016-04-12 15:56:15 +0200461 enum nl80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700462 struct ieee80211_supported_band *sband;
463 struct ieee80211_channel *ch;
464 struct mwifiex_adapter *adapter = priv->adapter;
465 int chan_idx = 0, i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700466
Johannes Berg57fbcce2016-04-12 15:56:15 +0200467 for (band = 0; (band < NUM_NL80211_BANDS) ; band++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700468
Avinash Patil4facc342015-01-28 15:42:00 +0530469 if (!priv->wdev.wiphy->bands[band])
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470 continue;
471
Avinash Patil4facc342015-01-28 15:42:00 +0530472 sband = priv->wdev.wiphy->bands[band];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473
Amitkumar Karward06b7b92011-09-21 21:43:22 -0700474 for (i = 0; (i < sband->n_channels) ; i++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475 ch = &sband->channels[i];
476 if (ch->flags & IEEE80211_CHAN_DISABLED)
477 continue;
478 scan_chan_list[chan_idx].radio_type = band;
Amitkumar Karwar186630c2011-12-15 21:00:37 -0800479
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700480 if (user_scan_in &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700481 user_scan_in->chan_list[0].scan_time)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700482 scan_chan_list[chan_idx].max_scan_time =
483 cpu_to_le16((u16) user_scan_in->
484 chan_list[0].scan_time);
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200485 else if (ch->flags & IEEE80211_CHAN_NO_IR)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700486 scan_chan_list[chan_idx].max_scan_time =
487 cpu_to_le16(adapter->passive_scan_time);
488 else
489 scan_chan_list[chan_idx].max_scan_time =
490 cpu_to_le16(adapter->active_scan_time);
Amitkumar Karwar186630c2011-12-15 21:00:37 -0800491
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200492 if (ch->flags & IEEE80211_CHAN_NO_IR)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700493 scan_chan_list[chan_idx].chan_scan_mode_bitmap
chunfan chen2375fa22015-08-05 06:09:42 -0700494 |= (MWIFIEX_PASSIVE_SCAN |
495 MWIFIEX_HIDDEN_SSID_REPORT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700496 else
497 scan_chan_list[chan_idx].chan_scan_mode_bitmap
498 &= ~MWIFIEX_PASSIVE_SCAN;
499 scan_chan_list[chan_idx].chan_number =
500 (u32) ch->hw_value;
501 if (filtered_scan) {
502 scan_chan_list[chan_idx].max_scan_time =
503 cpu_to_le16(adapter->specific_scan_time);
504 scan_chan_list[chan_idx].chan_scan_mode_bitmap
505 |= MWIFIEX_DISABLE_CHAN_FILT;
506 }
Amitkumar Karward06b7b92011-09-21 21:43:22 -0700507 chan_idx++;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700508 }
509
510 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700511 return chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700512}
513
Xinming Hu0c9b7f22016-01-13 01:26:52 -0800514/* This function creates a channel list tlv for bgscan config, based
515 * on region/band information.
516 */
517static int
518mwifiex_bgscan_create_channel_list(struct mwifiex_private *priv,
519 const struct mwifiex_bg_scan_cfg
520 *bgscan_cfg_in,
521 struct mwifiex_chan_scan_param_set
522 *scan_chan_list)
523{
Johannes Berg57fbcce2016-04-12 15:56:15 +0200524 enum nl80211_band band;
Xinming Hu0c9b7f22016-01-13 01:26:52 -0800525 struct ieee80211_supported_band *sband;
526 struct ieee80211_channel *ch;
527 struct mwifiex_adapter *adapter = priv->adapter;
528 int chan_idx = 0, i;
529
Johannes Berg57fbcce2016-04-12 15:56:15 +0200530 for (band = 0; (band < NUM_NL80211_BANDS); band++) {
Xinming Hu0c9b7f22016-01-13 01:26:52 -0800531 if (!priv->wdev.wiphy->bands[band])
532 continue;
533
534 sband = priv->wdev.wiphy->bands[band];
535
536 for (i = 0; (i < sband->n_channels) ; i++) {
537 ch = &sband->channels[i];
538 if (ch->flags & IEEE80211_CHAN_DISABLED)
539 continue;
540 scan_chan_list[chan_idx].radio_type = band;
541
542 if (bgscan_cfg_in->chan_list[0].scan_time)
543 scan_chan_list[chan_idx].max_scan_time =
544 cpu_to_le16((u16)bgscan_cfg_in->
545 chan_list[0].scan_time);
546 else if (ch->flags & IEEE80211_CHAN_NO_IR)
547 scan_chan_list[chan_idx].max_scan_time =
548 cpu_to_le16(adapter->passive_scan_time);
549 else
550 scan_chan_list[chan_idx].max_scan_time =
551 cpu_to_le16(adapter->
552 specific_scan_time);
553
554 if (ch->flags & IEEE80211_CHAN_NO_IR)
555 scan_chan_list[chan_idx].chan_scan_mode_bitmap
556 |= MWIFIEX_PASSIVE_SCAN;
557 else
558 scan_chan_list[chan_idx].chan_scan_mode_bitmap
559 &= ~MWIFIEX_PASSIVE_SCAN;
560
561 scan_chan_list[chan_idx].chan_number =
562 (u32)ch->hw_value;
563 chan_idx++;
564 }
565 }
566 return chan_idx;
567}
568
Avinash Patil78dfca62013-07-30 17:18:56 -0700569/* This function appends rate TLV to scan config command. */
570static int
571mwifiex_append_rate_tlv(struct mwifiex_private *priv,
572 struct mwifiex_scan_cmd_config *scan_cfg_out,
573 u8 radio)
574{
575 struct mwifiex_ie_types_rates_param_set *rates_tlv;
576 u8 rates[MWIFIEX_SUPPORTED_RATES], *tlv_pos;
577 u32 rates_size;
578
579 memset(rates, 0, sizeof(rates));
580
581 tlv_pos = (u8 *)scan_cfg_out->tlv_buf + scan_cfg_out->tlv_buf_len;
582
583 if (priv->scan_request)
584 rates_size = mwifiex_get_rates_from_cfg80211(priv, rates,
585 radio);
586 else
587 rates_size = mwifiex_get_supported_rates(priv, rates);
588
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530589 mwifiex_dbg(priv->adapter, CMD,
590 "info: SCAN_CMD: Rates size = %d\n",
Avinash Patil78dfca62013-07-30 17:18:56 -0700591 rates_size);
592 rates_tlv = (struct mwifiex_ie_types_rates_param_set *)tlv_pos;
593 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
594 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
595 memcpy(rates_tlv->rates, rates, rates_size);
596 scan_cfg_out->tlv_buf_len += sizeof(rates_tlv->header) + rates_size;
597
598 return rates_size;
599}
600
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700601/*
602 * This function constructs and sends multiple scan config commands to
603 * the firmware.
604 *
605 * Previous routines in the code flow have created a scan command configuration
606 * with any requested TLVs. This function splits the channel TLV into maximum
607 * channels supported per scan lists and sends the portion of the channel TLV,
608 * along with the other TLVs, to the firmware.
609 */
610static int
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700611mwifiex_scan_channel_list(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612 u32 max_chan_per_scan, u8 filtered_scan,
613 struct mwifiex_scan_cmd_config *scan_cfg_out,
614 struct mwifiex_ie_types_chan_list_param_set
615 *chan_tlv_out,
616 struct mwifiex_chan_scan_param_set *scan_chan_list)
617{
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700618 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619 int ret = 0;
620 struct mwifiex_chan_scan_param_set *tmp_chan_list;
621 struct mwifiex_chan_scan_param_set *start_chan;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700622 struct cmd_ctrl_node *cmd_node, *tmp_node;
623 unsigned long flags;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800624 u32 tlv_idx, rates_size, cmd_no;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700625 u32 total_scan_time;
626 u32 done_early;
Avinash Patil78dfca62013-07-30 17:18:56 -0700627 u8 radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700628
629 if (!scan_cfg_out || !chan_tlv_out || !scan_chan_list) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530630 mwifiex_dbg(priv->adapter, ERROR,
631 "info: Scan: Null detect: %p, %p, %p\n",
632 scan_cfg_out, chan_tlv_out, scan_chan_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633 return -1;
634 }
635
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700636 /* Check csa channel expiry before preparing scan list */
637 mwifiex_11h_get_csa_closed_channel(priv);
638
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700639 chan_tlv_out->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
640
641 /* Set the temp channel struct pointer to the start of the desired
642 list */
643 tmp_chan_list = scan_chan_list;
644
645 /* Loop through the desired channel list, sending a new firmware scan
646 commands for each max_chan_per_scan channels (or for 1,6,11
647 individually if configured accordingly) */
648 while (tmp_chan_list->chan_number) {
649
650 tlv_idx = 0;
651 total_scan_time = 0;
Avinash Patil78dfca62013-07-30 17:18:56 -0700652 radio_type = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700653 chan_tlv_out->header.len = 0;
654 start_chan = tmp_chan_list;
655 done_early = false;
656
657 /*
658 * Construct the Channel TLV for the scan command. Continue to
659 * insert channel TLVs until:
660 * - the tlv_idx hits the maximum configured per scan command
661 * - the next channel to insert is 0 (end of desired channel
662 * list)
663 * - done_early is set (controlling individual scanning of
664 * 1,6,11)
665 */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700666 while (tlv_idx < max_chan_per_scan &&
667 tmp_chan_list->chan_number && !done_early) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700668
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700669 if (tmp_chan_list->chan_number == priv->csa_chan) {
670 tmp_chan_list++;
671 continue;
672 }
673
Avinash Patil78dfca62013-07-30 17:18:56 -0700674 radio_type = tmp_chan_list->radio_type;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530675 mwifiex_dbg(priv->adapter, INFO,
676 "info: Scan: Chan(%3d), Radio(%d),\t"
677 "Mode(%d, %d), Dur(%d)\n",
678 tmp_chan_list->chan_number,
679 tmp_chan_list->radio_type,
680 tmp_chan_list->chan_scan_mode_bitmap
681 & MWIFIEX_PASSIVE_SCAN,
682 (tmp_chan_list->chan_scan_mode_bitmap
683 & MWIFIEX_DISABLE_CHAN_FILT) >> 1,
684 le16_to_cpu(tmp_chan_list->max_scan_time));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700685
686 /* Copy the current channel TLV to the command being
687 prepared */
688 memcpy(chan_tlv_out->chan_scan_param + tlv_idx,
689 tmp_chan_list,
690 sizeof(chan_tlv_out->chan_scan_param));
691
692 /* Increment the TLV header length by the size
693 appended */
Wei Yongjun5570a912012-09-28 12:59:43 +0800694 le16_add_cpu(&chan_tlv_out->header.len,
695 sizeof(chan_tlv_out->chan_scan_param));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700696
697 /*
698 * The tlv buffer length is set to the number of bytes
699 * of the between the channel tlv pointer and the start
700 * of the tlv buffer. This compensates for any TLVs
701 * that were appended before the channel list.
702 */
703 scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
704 scan_cfg_out->tlv_buf);
705
706 /* Add the size of the channel tlv header and the data
707 length */
708 scan_cfg_out->tlv_buf_len +=
709 (sizeof(chan_tlv_out->header)
710 + le16_to_cpu(chan_tlv_out->header.len));
711
712 /* Increment the index to the channel tlv we are
713 constructing */
714 tlv_idx++;
715
716 /* Count the total scan time per command */
717 total_scan_time +=
718 le16_to_cpu(tmp_chan_list->max_scan_time);
719
720 done_early = false;
721
722 /* Stop the loop if the *current* channel is in the
723 1,6,11 set and we are not filtering on a BSSID
724 or SSID. */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700725 if (!filtered_scan &&
726 (tmp_chan_list->chan_number == 1 ||
727 tmp_chan_list->chan_number == 6 ||
728 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700729 done_early = true;
730
731 /* Increment the tmp pointer to the next channel to
732 be scanned */
733 tmp_chan_list++;
734
735 /* Stop the loop if the *next* channel is in the 1,6,11
736 set. This will cause it to be the only channel
737 scanned on the next interation */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700738 if (!filtered_scan &&
739 (tmp_chan_list->chan_number == 1 ||
740 tmp_chan_list->chan_number == 6 ||
741 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700742 done_early = true;
743 }
744
745 /* The total scan time should be less than scan command timeout
746 value */
747 if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530748 mwifiex_dbg(priv->adapter, ERROR,
749 "total scan time %dms\t"
750 "is over limit (%dms), scan skipped\n",
751 total_scan_time,
752 MWIFIEX_MAX_TOTAL_SCAN_TIME);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700753 ret = -1;
754 break;
755 }
756
Avinash Patil78dfca62013-07-30 17:18:56 -0700757 rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out,
758 radio_type);
759
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700760 priv->adapter->scan_channels = start_chan;
761
762 /* Send the scan command to the firmware with the specified
763 cfg */
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800764 if (priv->adapter->ext_scan)
765 cmd_no = HostCmd_CMD_802_11_SCAN_EXT;
766 else
767 cmd_no = HostCmd_CMD_802_11_SCAN;
768
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800769 ret = mwifiex_send_cmd(priv, cmd_no, HostCmd_ACT_GEN_SET,
770 0, scan_cfg_out, false);
Avinash Patil78dfca62013-07-30 17:18:56 -0700771
772 /* rate IE is updated per scan command but same starting
773 * pointer is used each time so that rate IE from earlier
774 * scan_cfg_out->buf is overwritten with new one.
775 */
776 scan_cfg_out->tlv_buf_len -=
777 sizeof(struct mwifiex_ie_types_header) + rates_size;
778
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700779 if (ret) {
780 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
781 list_for_each_entry_safe(cmd_node, tmp_node,
782 &adapter->scan_pending_q,
783 list) {
784 list_del(&cmd_node->list);
785 cmd_node->wait_q_enabled = false;
786 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
787 }
788 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
789 flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700790 break;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700791 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700792 }
793
794 if (ret)
795 return -1;
796
797 return 0;
798}
799
800/*
801 * This function constructs a scan command configuration structure to use
802 * in scan commands.
803 *
804 * Application layer or other functions can invoke network scanning
805 * with a scan configuration supplied in a user scan configuration structure.
806 * This structure is used as the basis of one or many scan command configuration
807 * commands that are sent to the command processing module and eventually to the
808 * firmware.
809 *
810 * This function creates a scan command configuration structure based on the
811 * following user supplied parameters (if present):
812 * - SSID filter
813 * - BSSID filter
814 * - Number of Probes to be sent
815 * - Channel list
816 *
817 * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
818 * If the number of probes is not set, adapter default setting is used.
819 */
820static void
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700821mwifiex_config_scan(struct mwifiex_private *priv,
822 const struct mwifiex_user_scan_cfg *user_scan_in,
823 struct mwifiex_scan_cmd_config *scan_cfg_out,
824 struct mwifiex_ie_types_chan_list_param_set **chan_list_out,
825 struct mwifiex_chan_scan_param_set *scan_chan_list,
826 u8 *max_chan_per_scan, u8 *filtered_scan,
827 u8 *scan_current_only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700828{
829 struct mwifiex_adapter *adapter = priv->adapter;
830 struct mwifiex_ie_types_num_probes *num_probes_tlv;
Avinash Patilcb91be82014-09-12 20:08:54 +0530831 struct mwifiex_ie_types_scan_chan_gap *chan_gap_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700832 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800833 struct mwifiex_ie_types_bssid_list *bssid_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700834 u8 *tlv_pos;
835 u32 num_probes;
836 u32 ssid_len;
837 u32 chan_idx;
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700838 u32 chan_num;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700839 u32 scan_type;
840 u16 scan_dur;
841 u8 channel;
842 u8 radio_type;
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800843 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700844 u8 ssid_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700845 struct mwifiex_ie_types_htcap *ht_cap;
Aniket Nagarnaik40d74122015-07-16 08:05:21 -0700846 struct mwifiex_ie_types_bss_mode *bss_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700847
848 /* The tlv_buf_len is calculated for each scan command. The TLVs added
849 in this routine will be preserved since the routine that sends the
850 command will append channelTLVs at *chan_list_out. The difference
851 between the *chan_list_out and the tlv_buf start will be used to
852 calculate the size of anything we add in this routine. */
853 scan_cfg_out->tlv_buf_len = 0;
854
855 /* Running tlv pointer. Assigned to chan_list_out at end of function
856 so later routines know where channels can be added to the command
857 buf */
858 tlv_pos = scan_cfg_out->tlv_buf;
859
860 /* Initialize the scan as un-filtered; the flag is later set to TRUE
861 below if a SSID or BSSID filter is sent in the command */
862 *filtered_scan = false;
863
864 /* Initialize the scan as not being only on the current channel. If
865 the channel list is customized, only contains one channel, and is
866 the active channel, this is set true and data flow is not halted. */
867 *scan_current_only = false;
868
869 if (user_scan_in) {
870
871 /* Default the ssid_filter flag to TRUE, set false under
872 certain wildcard conditions and qualified by the existence
873 of an SSID list before marking the scan as filtered */
874 ssid_filter = true;
875
876 /* Set the BSS type scan filter, use Adapter setting if
877 unset */
878 scan_cfg_out->bss_mode =
Andreas Fenkart2ccf7ce2016-03-10 09:44:07 +0100879 (u8)(user_scan_in->bss_mode ?: adapter->scan_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700880
881 /* Set the number of probes to send, use Adapter setting
882 if unset */
Andreas Fenkart2ccf7ce2016-03-10 09:44:07 +0100883 num_probes = user_scan_in->num_probes ?: adapter->scan_probes;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700884
885 /*
886 * Set the BSSID filter to the incoming configuration,
887 * if non-zero. If not set, it will remain disabled
888 * (all zeros).
889 */
890 memcpy(scan_cfg_out->specific_bssid,
891 user_scan_in->specific_bssid,
892 sizeof(scan_cfg_out->specific_bssid));
893
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800894 if (adapter->ext_scan &&
895 !is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
896 bssid_tlv =
897 (struct mwifiex_ie_types_bssid_list *)tlv_pos;
898 bssid_tlv->header.type = cpu_to_le16(TLV_TYPE_BSSID);
899 bssid_tlv->header.len = cpu_to_le16(ETH_ALEN);
900 memcpy(bssid_tlv->bssid, user_scan_in->specific_bssid,
901 ETH_ALEN);
902 tlv_pos += sizeof(struct mwifiex_ie_types_bssid_list);
903 }
904
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800905 for (i = 0; i < user_scan_in->num_ssids; i++) {
906 ssid_len = user_scan_in->ssid_list[i].ssid_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700907
908 wildcard_ssid_tlv =
909 (struct mwifiex_ie_types_wildcard_ssid_params *)
910 tlv_pos;
911 wildcard_ssid_tlv->header.type =
912 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
913 wildcard_ssid_tlv->header.len = cpu_to_le16(
914 (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
915 max_ssid_length)));
Amitkumar Karwarfada1052011-11-09 21:36:21 -0800916
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800917 /*
918 * max_ssid_length = 0 tells firmware to perform
919 * specific scan for the SSID filled, whereas
920 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
921 * wildcard scan.
922 */
923 if (ssid_len)
924 wildcard_ssid_tlv->max_ssid_length = 0;
925 else
926 wildcard_ssid_tlv->max_ssid_length =
927 IEEE80211_MAX_SSID_LEN;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700928
Aniket Nagarnaik0c6303c2015-07-16 08:05:22 -0700929 if (!memcmp(user_scan_in->ssid_list[i].ssid,
930 "DIRECT-", 7))
931 wildcard_ssid_tlv->max_ssid_length = 0xfe;
932
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700933 memcpy(wildcard_ssid_tlv->ssid,
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800934 user_scan_in->ssid_list[i].ssid, ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700935
936 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
937 + le16_to_cpu(wildcard_ssid_tlv->header.len));
938
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530939 mwifiex_dbg(adapter, INFO,
940 "info: scan: ssid[%d]: %s, %d\n",
941 i, wildcard_ssid_tlv->ssid,
942 wildcard_ssid_tlv->max_ssid_length);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700943
944 /* Empty wildcard ssid with a maxlen will match many or
945 potentially all SSIDs (maxlen == 32), therefore do
946 not treat the scan as
947 filtered. */
948 if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
949 ssid_filter = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700950 }
951
952 /*
953 * The default number of channels sent in the command is low to
954 * ensure the response buffer from the firmware does not
955 * truncate scan results. That is not an issue with an SSID
956 * or BSSID filter applied to the scan results in the firmware.
957 */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700958 if ((i && ssid_filter) ||
Bing Zhao84f6a952012-08-27 20:32:54 -0700959 !is_zero_ether_addr(scan_cfg_out->specific_bssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700960 *filtered_scan = true;
Avinash Patil8eda10e2014-09-17 23:01:26 +0530961
962 if (user_scan_in->scan_chan_gap) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530963 mwifiex_dbg(adapter, INFO,
964 "info: scan: channel gap = %d\n",
965 user_scan_in->scan_chan_gap);
Avinash Patil8eda10e2014-09-17 23:01:26 +0530966 *max_chan_per_scan =
967 MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
968
969 chan_gap_tlv = (void *)tlv_pos;
970 chan_gap_tlv->header.type =
971 cpu_to_le16(TLV_TYPE_SCAN_CHANNEL_GAP);
972 chan_gap_tlv->header.len =
973 cpu_to_le16(sizeof(chan_gap_tlv->chan_gap));
974 chan_gap_tlv->chan_gap =
975 cpu_to_le16((user_scan_in->scan_chan_gap));
976 tlv_pos +=
977 sizeof(struct mwifiex_ie_types_scan_chan_gap);
978 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700979 } else {
980 scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
981 num_probes = adapter->scan_probes;
982 }
983
984 /*
985 * If a specific BSSID or SSID is used, the number of channels in the
986 * scan command will be increased to the absolute maximum.
987 */
988 if (*filtered_scan)
989 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
990 else
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700991 *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700992
Aniket Nagarnaik40d74122015-07-16 08:05:21 -0700993 if (adapter->ext_scan) {
994 bss_mode = (struct mwifiex_ie_types_bss_mode *)tlv_pos;
995 bss_mode->header.type = cpu_to_le16(TLV_TYPE_BSS_MODE);
996 bss_mode->header.len = cpu_to_le16(sizeof(bss_mode->bss_mode));
997 bss_mode->bss_mode = scan_cfg_out->bss_mode;
998 tlv_pos += sizeof(bss_mode->header) +
999 le16_to_cpu(bss_mode->header.len);
1000 }
1001
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001002 /* If the input config or adapter has the number of Probes set,
1003 add tlv */
1004 if (num_probes) {
1005
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301006 mwifiex_dbg(adapter, INFO,
1007 "info: scan: num_probes = %d\n",
1008 num_probes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001009
1010 num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
1011 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
1012 num_probes_tlv->header.len =
1013 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
1014 num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
1015
1016 tlv_pos += sizeof(num_probes_tlv->header) +
1017 le16_to_cpu(num_probes_tlv->header.len);
1018
1019 }
1020
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001021 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
1022 (priv->adapter->config_bands & BAND_GN ||
1023 priv->adapter->config_bands & BAND_AN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001024 ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
1025 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
1026 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1027 ht_cap->header.len =
1028 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001029 radio_type =
1030 mwifiex_band_to_radio_type(priv->adapter->config_bands);
Amitkumar Karwar341b8802014-02-07 16:27:31 -08001031 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001032 tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
1033 }
1034
1035 /* Append vendor specific IE TLV */
1036 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
1037
1038 /*
1039 * Set the output for the channel TLV to the address in the tlv buffer
1040 * past any TLVs that were added in this function (SSID, num_probes).
1041 * Channel TLVs will be added past this for each scan command,
1042 * preserving the TLVs that were previously added.
1043 */
1044 *chan_list_out =
1045 (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
1046
1047 if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
1048
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301049 mwifiex_dbg(adapter, INFO,
1050 "info: Scan: Using supplied channel list\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001051
1052 for (chan_idx = 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001053 chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX &&
1054 user_scan_in->chan_list[chan_idx].chan_number;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001055 chan_idx++) {
1056
1057 channel = user_scan_in->chan_list[chan_idx].chan_number;
1058 (scan_chan_list + chan_idx)->chan_number = channel;
1059
1060 radio_type =
1061 user_scan_in->chan_list[chan_idx].radio_type;
1062 (scan_chan_list + chan_idx)->radio_type = radio_type;
1063
1064 scan_type = user_scan_in->chan_list[chan_idx].scan_type;
1065
1066 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1067 (scan_chan_list +
1068 chan_idx)->chan_scan_mode_bitmap
chunfan chen2375fa22015-08-05 06:09:42 -07001069 |= (MWIFIEX_PASSIVE_SCAN |
1070 MWIFIEX_HIDDEN_SSID_REPORT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001071 else
1072 (scan_chan_list +
1073 chan_idx)->chan_scan_mode_bitmap
1074 &= ~MWIFIEX_PASSIVE_SCAN;
1075
Amitkumar Karwarf3e1af32012-10-19 19:19:18 -07001076 if (*filtered_scan)
1077 (scan_chan_list +
1078 chan_idx)->chan_scan_mode_bitmap
1079 |= MWIFIEX_DISABLE_CHAN_FILT;
1080
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001081 if (user_scan_in->chan_list[chan_idx].scan_time) {
1082 scan_dur = (u16) user_scan_in->
1083 chan_list[chan_idx].scan_time;
1084 } else {
1085 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1086 scan_dur = adapter->passive_scan_time;
1087 else if (*filtered_scan)
1088 scan_dur = adapter->specific_scan_time;
1089 else
1090 scan_dur = adapter->active_scan_time;
1091 }
1092
1093 (scan_chan_list + chan_idx)->min_scan_time =
1094 cpu_to_le16(scan_dur);
1095 (scan_chan_list + chan_idx)->max_scan_time =
1096 cpu_to_le16(scan_dur);
1097 }
1098
1099 /* Check if we are only scanning the current channel */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001100 if ((chan_idx == 1) &&
1101 (user_scan_in->chan_list[0].chan_number ==
1102 priv->curr_bss_params.bss_descriptor.channel)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103 *scan_current_only = true;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301104 mwifiex_dbg(adapter, INFO,
1105 "info: Scan: Scanning current channel only\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001107 chan_num = chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001108 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301109 mwifiex_dbg(adapter, INFO,
1110 "info: Scan: Creating full region channel list\n");
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001111 chan_num = mwifiex_scan_create_channel_list(priv, user_scan_in,
1112 scan_chan_list,
1113 *filtered_scan);
1114 }
1115
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001116}
1117
1118/*
1119 * This function inspects the scan response buffer for pointers to
1120 * expected TLVs.
1121 *
1122 * TLVs can be included at the end of the scan response BSS information.
1123 *
1124 * Data in the buffer is parsed pointers to TLVs that can potentially
1125 * be passed back in the response.
1126 */
1127static void
1128mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
1129 struct mwifiex_ie_types_data *tlv,
1130 u32 tlv_buf_size, u32 req_tlv_type,
1131 struct mwifiex_ie_types_data **tlv_data)
1132{
1133 struct mwifiex_ie_types_data *current_tlv;
1134 u32 tlv_buf_left;
1135 u32 tlv_type;
1136 u32 tlv_len;
1137
1138 current_tlv = tlv;
1139 tlv_buf_left = tlv_buf_size;
1140 *tlv_data = NULL;
1141
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301142 mwifiex_dbg(adapter, INFO,
1143 "info: SCAN_RESP: tlv_buf_size = %d\n",
1144 tlv_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001145
1146 while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
1147
1148 tlv_type = le16_to_cpu(current_tlv->header.type);
1149 tlv_len = le16_to_cpu(current_tlv->header.len);
1150
1151 if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301152 mwifiex_dbg(adapter, ERROR,
1153 "SCAN_RESP: TLV buffer corrupt\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001154 break;
1155 }
1156
1157 if (req_tlv_type == tlv_type) {
1158 switch (tlv_type) {
1159 case TLV_TYPE_TSFTIMESTAMP:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301160 mwifiex_dbg(adapter, INFO,
1161 "info: SCAN_RESP: TSF\t"
1162 "timestamp TLV, len = %d\n",
1163 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001164 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001165 break;
1166 case TLV_TYPE_CHANNELBANDLIST:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301167 mwifiex_dbg(adapter, INFO,
1168 "info: SCAN_RESP: channel\t"
1169 "band list TLV, len = %d\n",
1170 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001171 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001172 break;
1173 default:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301174 mwifiex_dbg(adapter, ERROR,
1175 "SCAN_RESP: unhandled TLV = %d\n",
1176 tlv_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177 /* Give up, this seems corrupted */
1178 return;
1179 }
1180 }
1181
1182 if (*tlv_data)
1183 break;
1184
1185
1186 tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
1187 current_tlv =
1188 (struct mwifiex_ie_types_data *) (current_tlv->data +
1189 tlv_len);
1190
1191 } /* while */
1192}
1193
1194/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001195 * This function parses provided beacon buffer and updates
1196 * respective fields in bss descriptor structure.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197 */
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001198int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1199 struct mwifiex_bssdescriptor *bss_entry)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001200{
1201 int ret = 0;
1202 u8 element_id;
1203 struct ieee_types_fh_param_set *fh_param_set;
1204 struct ieee_types_ds_param_set *ds_param_set;
1205 struct ieee_types_cf_param_set *cf_param_set;
1206 struct ieee_types_ibss_param_set *ibss_param_set;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207 u8 *current_ptr;
1208 u8 *rate;
1209 u8 element_len;
1210 u16 total_ie_len;
1211 u8 bytes_to_copy;
1212 u8 rate_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001213 u8 found_data_rate_ie;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001214 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001215 struct ieee_types_vendor_specific *vendor_ie;
1216 const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
1217 const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
1218
1219 found_data_rate_ie = false;
1220 rate_size = 0;
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001221 current_ptr = bss_entry->beacon_buf;
1222 bytes_left = bss_entry->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001223
1224 /* Process variable IE */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001225 while (bytes_left >= 2) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001226 element_id = *current_ptr;
1227 element_len = *(current_ptr + 1);
1228 total_ie_len = element_len + sizeof(struct ieee_types_header);
1229
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001230 if (bytes_left < total_ie_len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301231 mwifiex_dbg(adapter, ERROR,
1232 "err: InterpretIE: in processing\t"
1233 "IE, bytes left < IE length\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001234 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001235 }
1236 switch (element_id) {
1237 case WLAN_EID_SSID:
1238 bss_entry->ssid.ssid_len = element_len;
1239 memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
1240 element_len);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301241 mwifiex_dbg(adapter, INFO,
1242 "info: InterpretIE: ssid: %-32s\n",
1243 bss_entry->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001244 break;
1245
1246 case WLAN_EID_SUPP_RATES:
1247 memcpy(bss_entry->data_rates, current_ptr + 2,
1248 element_len);
1249 memcpy(bss_entry->supported_rates, current_ptr + 2,
1250 element_len);
1251 rate_size = element_len;
1252 found_data_rate_ie = true;
1253 break;
1254
1255 case WLAN_EID_FH_PARAMS:
1256 fh_param_set =
1257 (struct ieee_types_fh_param_set *) current_ptr;
1258 memcpy(&bss_entry->phy_param_set.fh_param_set,
1259 fh_param_set,
1260 sizeof(struct ieee_types_fh_param_set));
1261 break;
1262
1263 case WLAN_EID_DS_PARAMS:
1264 ds_param_set =
1265 (struct ieee_types_ds_param_set *) current_ptr;
1266
1267 bss_entry->channel = ds_param_set->current_chan;
1268
1269 memcpy(&bss_entry->phy_param_set.ds_param_set,
1270 ds_param_set,
1271 sizeof(struct ieee_types_ds_param_set));
1272 break;
1273
1274 case WLAN_EID_CF_PARAMS:
1275 cf_param_set =
1276 (struct ieee_types_cf_param_set *) current_ptr;
1277 memcpy(&bss_entry->ss_param_set.cf_param_set,
1278 cf_param_set,
1279 sizeof(struct ieee_types_cf_param_set));
1280 break;
1281
1282 case WLAN_EID_IBSS_PARAMS:
1283 ibss_param_set =
1284 (struct ieee_types_ibss_param_set *)
1285 current_ptr;
1286 memcpy(&bss_entry->ss_param_set.ibss_param_set,
1287 ibss_param_set,
1288 sizeof(struct ieee_types_ibss_param_set));
1289 break;
1290
1291 case WLAN_EID_ERP_INFO:
1292 bss_entry->erp_flags = *(current_ptr + 2);
1293 break;
1294
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -07001295 case WLAN_EID_PWR_CONSTRAINT:
1296 bss_entry->local_constraint = *(current_ptr + 2);
1297 bss_entry->sensed_11h = true;
1298 break;
1299
1300 case WLAN_EID_CHANNEL_SWITCH:
1301 bss_entry->chan_sw_ie_present = true;
1302 case WLAN_EID_PWR_CAPABILITY:
1303 case WLAN_EID_TPC_REPORT:
1304 case WLAN_EID_QUIET:
1305 bss_entry->sensed_11h = true;
1306 break;
1307
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001308 case WLAN_EID_EXT_SUPP_RATES:
1309 /*
1310 * Only process extended supported rate
1311 * if data rate is already found.
1312 * Data rate IE should come before
1313 * extended supported rate IE
1314 */
1315 if (found_data_rate_ie) {
1316 if ((element_len + rate_size) >
1317 MWIFIEX_SUPPORTED_RATES)
1318 bytes_to_copy =
1319 (MWIFIEX_SUPPORTED_RATES -
1320 rate_size);
1321 else
1322 bytes_to_copy = element_len;
1323
1324 rate = (u8 *) bss_entry->data_rates;
1325 rate += rate_size;
1326 memcpy(rate, current_ptr + 2, bytes_to_copy);
1327
1328 rate = (u8 *) bss_entry->supported_rates;
1329 rate += rate_size;
1330 memcpy(rate, current_ptr + 2, bytes_to_copy);
1331 }
1332 break;
1333
1334 case WLAN_EID_VENDOR_SPECIFIC:
1335 vendor_ie = (struct ieee_types_vendor_specific *)
1336 current_ptr;
1337
1338 if (!memcmp
1339 (vendor_ie->vend_hdr.oui, wpa_oui,
1340 sizeof(wpa_oui))) {
1341 bss_entry->bcn_wpa_ie =
1342 (struct ieee_types_vendor_specific *)
1343 current_ptr;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001344 bss_entry->wpa_offset = (u16)
1345 (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001346 } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui,
1347 sizeof(wmm_oui))) {
1348 if (total_ie_len ==
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001349 sizeof(struct ieee_types_wmm_parameter) ||
1350 total_ie_len ==
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001351 sizeof(struct ieee_types_wmm_info))
1352 /*
1353 * Only accept and copy the WMM IE if
1354 * it matches the size expected for the
1355 * WMM Info IE or the WMM Parameter IE.
1356 */
1357 memcpy((u8 *) &bss_entry->wmm_ie,
1358 current_ptr, total_ie_len);
1359 }
1360 break;
1361 case WLAN_EID_RSN:
1362 bss_entry->bcn_rsn_ie =
1363 (struct ieee_types_generic *) current_ptr;
1364 bss_entry->rsn_offset = (u16) (current_ptr -
1365 bss_entry->beacon_buf);
1366 break;
1367 case WLAN_EID_BSS_AC_ACCESS_DELAY:
1368 bss_entry->bcn_wapi_ie =
1369 (struct ieee_types_generic *) current_ptr;
1370 bss_entry->wapi_offset = (u16) (current_ptr -
1371 bss_entry->beacon_buf);
1372 break;
1373 case WLAN_EID_HT_CAPABILITY:
1374 bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
1375 (current_ptr +
1376 sizeof(struct ieee_types_header));
1377 bss_entry->ht_cap_offset = (u16) (current_ptr +
1378 sizeof(struct ieee_types_header) -
1379 bss_entry->beacon_buf);
1380 break;
Johannes Berg074d46d2012-03-15 19:45:16 +01001381 case WLAN_EID_HT_OPERATION:
1382 bss_entry->bcn_ht_oper =
1383 (struct ieee80211_ht_operation *)(current_ptr +
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001384 sizeof(struct ieee_types_header));
1385 bss_entry->ht_info_offset = (u16) (current_ptr +
1386 sizeof(struct ieee_types_header) -
1387 bss_entry->beacon_buf);
1388 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001389 case WLAN_EID_VHT_CAPABILITY:
1390 bss_entry->disable_11ac = false;
1391 bss_entry->bcn_vht_cap =
1392 (void *)(current_ptr +
1393 sizeof(struct ieee_types_header));
1394 bss_entry->vht_cap_offset =
1395 (u16)((u8 *)bss_entry->bcn_vht_cap -
1396 bss_entry->beacon_buf);
1397 break;
1398 case WLAN_EID_VHT_OPERATION:
1399 bss_entry->bcn_vht_oper =
1400 (void *)(current_ptr +
1401 sizeof(struct ieee_types_header));
1402 bss_entry->vht_info_offset =
1403 (u16)((u8 *)bss_entry->bcn_vht_oper -
1404 bss_entry->beacon_buf);
1405 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001406 case WLAN_EID_BSS_COEX_2040:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001407 bss_entry->bcn_bss_co_2040 = current_ptr;
1408 bss_entry->bss_co_2040_offset =
1409 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001410 break;
1411 case WLAN_EID_EXT_CAPABILITY:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001412 bss_entry->bcn_ext_cap = current_ptr;
1413 bss_entry->ext_cap_offset =
1414 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001415 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001416 case WLAN_EID_OPMODE_NOTIF:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001417 bss_entry->oper_mode = (void *)current_ptr;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001418 bss_entry->oper_mode_offset =
1419 (u16)((u8 *)bss_entry->oper_mode -
1420 bss_entry->beacon_buf);
1421 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001422 default:
1423 break;
1424 }
1425
1426 current_ptr += element_len + 2;
1427
1428 /* Need to account for IE ID and IE Len */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001429 bytes_left -= (element_len + 2);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001430
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001431 } /* while (bytes_left > 2) */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001432 return ret;
1433}
1434
1435/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001436 * This function converts radio type scan parameter to a band configuration
1437 * to be used in join command.
1438 */
1439static u8
1440mwifiex_radio_type_to_band(u8 radio_type)
1441{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001442 switch (radio_type) {
1443 case HostCmd_SCAN_RADIO_TYPE_A:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001444 return BAND_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001445 case HostCmd_SCAN_RADIO_TYPE_BG:
1446 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001447 return BAND_G;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001448 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001449}
1450
1451/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001452 * This is an internal function used to start a scan based on an input
1453 * configuration.
1454 *
1455 * This uses the input user scan configuration information when provided in
1456 * order to send the appropriate scan commands to firmware to populate or
1457 * update the internal driver scan table.
1458 */
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001459int mwifiex_scan_networks(struct mwifiex_private *priv,
1460 const struct mwifiex_user_scan_cfg *user_scan_in)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001461{
Bing Zhaoc2476332012-10-05 20:21:40 -07001462 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001463 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001464 struct cmd_ctrl_node *cmd_node;
1465 union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001466 struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001467 struct mwifiex_chan_scan_param_set *scan_chan_list;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001468 u8 filtered_scan;
1469 u8 scan_current_chan_only;
1470 u8 max_chan_per_scan;
1471 unsigned long flags;
1472
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001473 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301474 mwifiex_dbg(adapter, WARN,
1475 "cmd: Scan already in process...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001476 return -EBUSY;
1477 }
1478
1479 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301480 mwifiex_dbg(adapter, WARN,
1481 "cmd: Scan is blocked during association...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001482 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001483 }
1484
Amitkumar Karware00483f2015-01-07 03:57:39 -08001485 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301486 mwifiex_dbg(adapter, ERROR,
1487 "Ignore scan. Card removed or firmware in bad state\n");
Amitkumar Karware00483f2015-01-07 03:57:39 -08001488 return -EFAULT;
1489 }
1490
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001491 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1492 adapter->scan_processing = true;
1493 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1494
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001495 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
Joe Perches0d2e7a52013-02-03 17:28:14 +00001496 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001497 if (!scan_cfg_out) {
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001498 ret = -ENOMEM;
1499 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001500 }
1501
Joe Perches0d2e7a52013-02-03 17:28:14 +00001502 scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
1503 sizeof(struct mwifiex_chan_scan_param_set),
1504 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001505 if (!scan_chan_list) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001506 kfree(scan_cfg_out);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001507 ret = -ENOMEM;
1508 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001509 }
1510
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001511 mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config,
1512 &chan_list_out, scan_chan_list, &max_chan_per_scan,
1513 &filtered_scan, &scan_current_chan_only);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001514
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001515 ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
1516 &scan_cfg_out->config, chan_list_out,
1517 scan_chan_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001518
1519 /* Get scan command from scan_pending_q and put to cmd_pending_q */
1520 if (!ret) {
1521 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1522 if (!list_empty(&adapter->scan_pending_q)) {
1523 cmd_node = list_first_entry(&adapter->scan_pending_q,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001524 struct cmd_ctrl_node, list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001525 list_del(&cmd_node->list);
1526 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001527 flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001528 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1529 true);
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001530 queue_work(adapter->workqueue, &adapter->main_work);
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001531
1532 /* Perform internal scan synchronously */
Bing Zhao21de9792013-04-01 12:44:45 -07001533 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301534 mwifiex_dbg(adapter, INFO,
1535 "wait internal scan\n");
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001536 mwifiex_wait_queue_complete(adapter, cmd_node);
Bing Zhao21de9792013-04-01 12:44:45 -07001537 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001538 } else {
1539 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1540 flags);
1541 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001542 }
1543
1544 kfree(scan_cfg_out);
1545 kfree(scan_chan_list);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001546done:
1547 if (ret) {
1548 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1549 adapter->scan_processing = false;
1550 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1551 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001552 return ret;
1553}
1554
1555/*
1556 * This function prepares a scan command to be sent to the firmware.
1557 *
1558 * This uses the scan command configuration sent to the command processing
1559 * module in command preparation stage to configure a scan command structure
1560 * to send to firmware.
1561 *
1562 * The fixed fields specifying the BSS type and BSSID filters as well as a
1563 * variable number/length of TLVs are sent in the command to firmware.
1564 *
1565 * Preparation also includes -
1566 * - Setting command ID, and proper size
1567 * - Ensuring correct endian-ness
1568 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001569int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1570 struct mwifiex_scan_cmd_config *scan_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001571{
1572 struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001573
1574 /* Set fixed field variables in scan command */
1575 scan_cmd->bss_mode = scan_cfg->bss_mode;
1576 memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
1577 sizeof(scan_cmd->bssid));
1578 memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
1579
1580 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
1581
1582 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
1583 cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
1584 + sizeof(scan_cmd->bssid)
1585 + scan_cfg->tlv_buf_len + S_DS_GEN));
1586
1587 return 0;
1588}
1589
1590/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001591 * This function checks compatibility of requested network with current
1592 * driver settings.
1593 */
1594int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1595 struct mwifiex_bssdescriptor *bss_desc)
1596{
1597 int ret = -1;
1598
1599 if (!bss_desc)
1600 return -1;
1601
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -07001602 if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
1603 (u16) bss_desc->channel, 0))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001604 switch (priv->bss_mode) {
1605 case NL80211_IFTYPE_STATION:
1606 case NL80211_IFTYPE_ADHOC:
1607 ret = mwifiex_is_network_compatible(priv, bss_desc,
1608 priv->bss_mode);
1609 if (ret)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301610 mwifiex_dbg(priv->adapter, ERROR,
1611 "Incompatible network settings\n");
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001612 break;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001613 default:
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001614 ret = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001615 }
1616 }
1617
1618 return ret;
1619}
1620
chunfan chen2375fa22015-08-05 06:09:42 -07001621/* This function checks if SSID string contains all zeroes or length is zero */
1622static bool mwifiex_is_hidden_ssid(struct cfg80211_ssid *ssid)
1623{
1624 int idx;
1625
1626 for (idx = 0; idx < ssid->ssid_len; idx++) {
1627 if (ssid->ssid[idx])
1628 return false;
1629 }
1630
1631 return true;
1632}
1633
1634/* This function checks if any hidden SSID found in passive scan channels
1635 * and save those channels for specific SSID active scan
1636 */
1637static int mwifiex_save_hidden_ssid_channels(struct mwifiex_private *priv,
1638 struct cfg80211_bss *bss)
1639{
1640 struct mwifiex_bssdescriptor *bss_desc;
1641 int ret;
1642 int chid;
1643
1644 /* Allocate and fill new bss descriptor */
1645 bss_desc = kzalloc(sizeof(*bss_desc), GFP_KERNEL);
1646 if (!bss_desc)
1647 return -ENOMEM;
1648
1649 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
1650 if (ret)
1651 goto done;
1652
1653 if (mwifiex_is_hidden_ssid(&bss_desc->ssid)) {
1654 mwifiex_dbg(priv->adapter, INFO, "found hidden SSID\n");
1655 for (chid = 0 ; chid < MWIFIEX_USER_SCAN_CHAN_MAX; chid++) {
1656 if (priv->hidden_chan[chid].chan_number ==
1657 bss->channel->hw_value)
1658 break;
1659
1660 if (!priv->hidden_chan[chid].chan_number) {
1661 priv->hidden_chan[chid].chan_number =
1662 bss->channel->hw_value;
1663 priv->hidden_chan[chid].radio_type =
1664 bss->channel->band;
1665 priv->hidden_chan[chid].scan_type =
1666 MWIFIEX_SCAN_TYPE_ACTIVE;
1667 break;
1668 }
1669 }
1670 }
1671
1672done:
1673 kfree(bss_desc);
1674 return 0;
1675}
1676
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001677static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1678 struct cfg80211_bss *bss)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001679{
Jesper Juhldb652e42011-11-06 22:58:31 +01001680 struct mwifiex_bssdescriptor *bss_desc;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001681 int ret;
1682 unsigned long flags;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001683
1684 /* Allocate and fill new bss descriptor */
Joe Perches0d2e7a52013-02-03 17:28:14 +00001685 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
1686 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001687 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07001688
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001689 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001690 if (ret)
1691 goto done;
1692
1693 ret = mwifiex_check_network_compatibility(priv, bss_desc);
1694 if (ret)
1695 goto done;
1696
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001697 spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001698 /* Make a copy of current BSSID descriptor */
1699 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001700 sizeof(priv->curr_bss_params.bss_descriptor));
Bing Zhaod837a2a2013-04-12 10:34:17 -07001701
1702 /* The contents of beacon_ie will be copied to its own buffer
1703 * in mwifiex_save_curr_bcn()
1704 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001705 mwifiex_save_curr_bcn(priv);
1706 spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
1707
1708done:
Bing Zhaod837a2a2013-04-12 10:34:17 -07001709 /* beacon_ie buffer was allocated in function
1710 * mwifiex_fill_new_bss_desc(). Free it now.
1711 */
1712 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001713 kfree(bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001714 return 0;
1715}
1716
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001717static int
1718mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info,
1719 u32 *bytes_left, u64 fw_tsf, u8 *radio_type,
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001720 bool ext_scan, s32 rssi_val)
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001721{
1722 struct mwifiex_adapter *adapter = priv->adapter;
1723 struct mwifiex_chan_freq_power *cfp;
1724 struct cfg80211_bss *bss;
1725 u8 bssid[ETH_ALEN];
1726 s32 rssi;
1727 const u8 *ie_buf;
1728 size_t ie_len;
1729 u16 channel = 0;
1730 u16 beacon_size = 0;
1731 u32 curr_bcn_bytes;
1732 u32 freq;
1733 u16 beacon_period;
1734 u16 cap_info_bitmap;
1735 u8 *current_ptr;
1736 u64 timestamp;
1737 struct mwifiex_fixed_bcn_param *bcn_param;
1738 struct mwifiex_bss_priv *bss_priv;
1739
1740 if (*bytes_left >= sizeof(beacon_size)) {
1741 /* Extract & convert beacon size from command buffer */
Amitkumar Karwar798ea8e2014-11-25 06:43:03 -08001742 beacon_size = le16_to_cpu(*(__le16 *)(*bss_info));
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001743 *bytes_left -= sizeof(beacon_size);
1744 *bss_info += sizeof(beacon_size);
1745 }
1746
1747 if (!beacon_size || beacon_size > *bytes_left) {
1748 *bss_info += *bytes_left;
1749 *bytes_left = 0;
1750 return -EFAULT;
1751 }
1752
1753 /* Initialize the current working beacon pointer for this BSS
1754 * iteration
1755 */
1756 current_ptr = *bss_info;
1757
1758 /* Advance the return beacon pointer past the current beacon */
1759 *bss_info += beacon_size;
1760 *bytes_left -= beacon_size;
1761
1762 curr_bcn_bytes = beacon_size;
1763
1764 /* First 5 fields are bssid, RSSI(for legacy scan only),
1765 * time stamp, beacon interval, and capability information
1766 */
1767 if (curr_bcn_bytes < ETH_ALEN + sizeof(u8) +
1768 sizeof(struct mwifiex_fixed_bcn_param)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301769 mwifiex_dbg(adapter, ERROR,
1770 "InterpretIE: not enough bytes left\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001771 return -EFAULT;
1772 }
1773
1774 memcpy(bssid, current_ptr, ETH_ALEN);
1775 current_ptr += ETH_ALEN;
1776 curr_bcn_bytes -= ETH_ALEN;
1777
1778 if (!ext_scan) {
Joe Perches45d18c52014-03-24 13:15:39 -07001779 rssi = (s32) *current_ptr;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001780 rssi = (-rssi) * 100; /* Convert dBm to mBm */
1781 current_ptr += sizeof(u8);
1782 curr_bcn_bytes -= sizeof(u8);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301783 mwifiex_dbg(adapter, INFO,
1784 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001785 } else {
1786 rssi = rssi_val;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001787 }
1788
1789 bcn_param = (struct mwifiex_fixed_bcn_param *)current_ptr;
1790 current_ptr += sizeof(*bcn_param);
1791 curr_bcn_bytes -= sizeof(*bcn_param);
1792
1793 timestamp = le64_to_cpu(bcn_param->timestamp);
1794 beacon_period = le16_to_cpu(bcn_param->beacon_period);
1795
1796 cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301797 mwifiex_dbg(adapter, INFO,
1798 "info: InterpretIE: capabilities=0x%X\n",
1799 cap_info_bitmap);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001800
1801 /* Rest of the current buffer are IE's */
1802 ie_buf = current_ptr;
1803 ie_len = curr_bcn_bytes;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301804 mwifiex_dbg(adapter, INFO,
1805 "info: InterpretIE: IELength for this AP = %d\n",
1806 curr_bcn_bytes);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001807
1808 while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) {
1809 u8 element_id, element_len;
1810
1811 element_id = *current_ptr;
1812 element_len = *(current_ptr + 1);
1813 if (curr_bcn_bytes < element_len +
1814 sizeof(struct ieee_types_header)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301815 mwifiex_dbg(adapter, ERROR,
1816 "%s: bytes left < IE length\n", __func__);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001817 return -EFAULT;
1818 }
1819 if (element_id == WLAN_EID_DS_PARAMS) {
1820 channel = *(current_ptr +
1821 sizeof(struct ieee_types_header));
1822 break;
1823 }
1824
1825 current_ptr += element_len + sizeof(struct ieee_types_header);
1826 curr_bcn_bytes -= element_len +
1827 sizeof(struct ieee_types_header);
1828 }
1829
1830 if (channel) {
1831 struct ieee80211_channel *chan;
1832 u8 band;
1833
1834 /* Skip entry if on csa closed channel */
1835 if (channel == priv->csa_chan) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301836 mwifiex_dbg(adapter, WARN,
1837 "Dropping entry on csa closed channel\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001838 return 0;
1839 }
1840
1841 band = BAND_G;
1842 if (radio_type)
1843 band = mwifiex_radio_type_to_band(*radio_type &
1844 (BIT(0) | BIT(1)));
1845
1846 cfp = mwifiex_get_cfp(priv, band, channel, 0);
1847
1848 freq = cfp ? cfp->freq : 0;
1849
Avinash Patil4facc342015-01-28 15:42:00 +05301850 chan = ieee80211_get_channel(priv->wdev.wiphy, freq);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001851
1852 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Avinash Patil4facc342015-01-28 15:42:00 +05301853 bss = cfg80211_inform_bss(priv->wdev.wiphy,
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02001854 chan, CFG80211_BSS_FTYPE_UNKNOWN,
1855 bssid, timestamp,
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001856 cap_info_bitmap, beacon_period,
1857 ie_buf, ie_len, rssi, GFP_KERNEL);
Xinming Hu02421dd32015-09-18 06:32:07 -07001858 if (bss) {
1859 bss_priv = (struct mwifiex_bss_priv *)bss->priv;
1860 bss_priv->band = band;
1861 bss_priv->fw_tsf = fw_tsf;
1862 if (priv->media_connected &&
1863 !memcmp(bssid, priv->curr_bss_params.
1864 bss_descriptor.mac_address,
1865 ETH_ALEN))
1866 mwifiex_update_curr_bss_params(priv,
1867 bss);
1868 cfg80211_put_bss(priv->wdev.wiphy, bss);
1869 }
chunfan chen2375fa22015-08-05 06:09:42 -07001870
1871 if ((chan->flags & IEEE80211_CHAN_RADAR) ||
1872 (chan->flags & IEEE80211_CHAN_NO_IR)) {
1873 mwifiex_dbg(adapter, INFO,
1874 "radar or passive channel %d\n",
1875 channel);
1876 mwifiex_save_hidden_ssid_channels(priv, bss);
1877 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001878 }
1879 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301880 mwifiex_dbg(adapter, WARN, "missing BSS channel IE\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001881 }
1882
1883 return 0;
1884}
1885
Avinash Patil21445042014-05-27 21:39:32 -07001886static void mwifiex_complete_scan(struct mwifiex_private *priv)
1887{
1888 struct mwifiex_adapter *adapter = priv->adapter;
1889
Avinash Patilbf354432014-10-31 16:08:26 +05301890 adapter->survey_idx = 0;
Avinash Patil21445042014-05-27 21:39:32 -07001891 if (adapter->curr_cmd->wait_q_enabled) {
1892 adapter->cmd_wait_q.status = 0;
1893 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301894 mwifiex_dbg(adapter, INFO,
1895 "complete internal scan\n");
Avinash Patil21445042014-05-27 21:39:32 -07001896 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1897 }
1898 }
1899}
1900
chunfan chen2375fa22015-08-05 06:09:42 -07001901/* This function checks if any hidden SSID found in passive scan channels
1902 * and do specific SSID active scan for those channels
1903 */
1904static int
1905mwifiex_active_scan_req_for_passive_chan(struct mwifiex_private *priv)
1906{
1907 int ret;
1908 struct mwifiex_adapter *adapter = priv->adapter;
1909 u8 id = 0;
1910 struct mwifiex_user_scan_cfg *user_scan_cfg;
1911
Aniket Nagarnaik17e524b2015-09-18 06:32:09 -07001912 if (adapter->active_scan_triggered || !priv->scan_request) {
chunfan chen2375fa22015-08-05 06:09:42 -07001913 adapter->active_scan_triggered = false;
1914 return 0;
1915 }
1916
1917 if (!priv->hidden_chan[0].chan_number) {
1918 mwifiex_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n");
1919 return 0;
1920 }
1921 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1922
1923 if (!user_scan_cfg)
1924 return -ENOMEM;
1925
1926 memset(user_scan_cfg, 0, sizeof(*user_scan_cfg));
1927
1928 for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) {
1929 if (!priv->hidden_chan[id].chan_number)
1930 break;
1931 memcpy(&user_scan_cfg->chan_list[id],
1932 &priv->hidden_chan[id],
1933 sizeof(struct mwifiex_user_scan_chan));
1934 }
1935
1936 adapter->active_scan_triggered = true;
1937 user_scan_cfg->num_ssids = priv->scan_request->n_ssids;
1938 user_scan_cfg->ssid_list = priv->scan_request->ssids;
1939
1940 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1941 kfree(user_scan_cfg);
1942
1943 memset(&priv->hidden_chan, 0, sizeof(priv->hidden_chan));
1944
1945 if (ret) {
1946 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1947 return ret;
1948 }
1949
1950 return 0;
1951}
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001952static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1953{
1954 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karward8d91252014-09-12 20:08:58 +05301955 struct cmd_ctrl_node *cmd_node, *tmp_node;
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001956 unsigned long flags;
1957
1958 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1959 if (list_empty(&adapter->scan_pending_q)) {
1960 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1961 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1962 adapter->scan_processing = false;
1963 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1964
chunfan chen2375fa22015-08-05 06:09:42 -07001965 mwifiex_active_scan_req_for_passive_chan(priv);
1966
Avinash Patil21445042014-05-27 21:39:32 -07001967 if (!adapter->ext_scan)
1968 mwifiex_complete_scan(priv);
1969
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001970 if (priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301971 mwifiex_dbg(adapter, INFO,
1972 "info: notifying scan done\n");
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001973 cfg80211_scan_done(priv->scan_request, 0);
1974 priv->scan_request = NULL;
1975 } else {
1976 priv->scan_aborting = false;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301977 mwifiex_dbg(adapter, INFO,
1978 "info: scan already aborted\n");
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001979 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05301980 } else if ((priv->scan_aborting && !priv->scan_request) ||
1981 priv->scan_block) {
1982 list_for_each_entry_safe(cmd_node, tmp_node,
1983 &adapter->scan_pending_q, list) {
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001984 list_del(&cmd_node->list);
Amitkumar Karward8d91252014-09-12 20:08:58 +05301985 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001986 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05301987 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1988
1989 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1990 adapter->scan_processing = false;
1991 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1992
chunfan chen2375fa22015-08-05 06:09:42 -07001993 if (!adapter->active_scan_triggered) {
1994 if (priv->scan_request) {
1995 mwifiex_dbg(adapter, INFO,
1996 "info: aborting scan\n");
1997 cfg80211_scan_done(priv->scan_request, 1);
1998 priv->scan_request = NULL;
1999 } else {
2000 priv->scan_aborting = false;
2001 mwifiex_dbg(adapter, INFO,
2002 "info: scan already aborted\n");
2003 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05302004 }
2005 } else {
2006 /* Get scan command from scan_pending_q and put to
2007 * cmd_pending_q
2008 */
2009 cmd_node = list_first_entry(&adapter->scan_pending_q,
2010 struct cmd_ctrl_node, list);
2011 list_del(&cmd_node->list);
2012 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2013 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002014 }
2015
2016 return;
2017}
2018
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002019/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002020 * This function handles the command response of scan.
2021 *
2022 * The response buffer for the scan command has the following
2023 * memory layout:
2024 *
2025 * .-------------------------------------------------------------.
2026 * | Header (4 * sizeof(t_u16)): Standard command response hdr |
2027 * .-------------------------------------------------------------.
2028 * | BufSize (t_u16) : sizeof the BSS Description data |
2029 * .-------------------------------------------------------------.
2030 * | NumOfSet (t_u8) : Number of BSS Descs returned |
2031 * .-------------------------------------------------------------.
2032 * | BSSDescription data (variable, size given in BufSize) |
2033 * .-------------------------------------------------------------.
2034 * | TLV data (variable, size calculated using Header->Size, |
2035 * | BufSize and sizeof the fixed fields above) |
2036 * .-------------------------------------------------------------.
2037 */
2038int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002039 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002040{
2041 int ret = 0;
2042 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002043 struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002044 struct mwifiex_ie_types_data *tlv_data;
2045 struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
2046 u8 *bss_info;
2047 u32 scan_resp_size;
2048 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002049 u32 idx;
2050 u32 tlv_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002051 struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
2052 struct chan_band_param_set *chan_band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002053 u8 is_bgscan_resp;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002054 __le64 fw_tsf = 0;
2055 u8 *radio_type;
chunfan chen7d7f07d2016-01-13 01:26:54 -08002056 struct cfg80211_wowlan_nd_match *pmatch;
2057 struct cfg80211_sched_scan_request *nd_config = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002058
2059 is_bgscan_resp = (le16_to_cpu(resp->command)
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002060 == HostCmd_CMD_802_11_BG_SCAN_QUERY);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002061 if (is_bgscan_resp)
2062 scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
2063 else
2064 scan_rsp = &resp->params.scan_resp;
2065
2066
Bing Zhao67a50032011-07-13 18:38:34 -07002067 if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302068 mwifiex_dbg(adapter, ERROR,
2069 "SCAN_RESP: too many AP returned (%d)\n",
2070 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002071 ret = -1;
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002072 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002073 }
2074
Amitkumar Karwarb8876642013-06-18 16:36:58 -07002075 /* Check csa channel expiry before parsing scan response */
2076 mwifiex_11h_get_csa_closed_channel(priv);
2077
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002078 bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302079 mwifiex_dbg(adapter, INFO,
2080 "info: SCAN_RESP: bss_descript_size %d\n",
2081 bytes_left);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002082
2083 scan_resp_size = le16_to_cpu(resp->size);
2084
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302085 mwifiex_dbg(adapter, INFO,
2086 "info: SCAN_RESP: returned %d APs before parsing\n",
2087 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002088
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002089 bss_info = scan_rsp->bss_desc_and_tlv_buffer;
2090
2091 /*
2092 * The size of the TLV buffer is equal to the entire command response
2093 * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
2094 * BSS Descriptions (bss_descript_size as bytesLef) and the command
2095 * response header (S_DS_GEN)
2096 */
2097 tlv_buf_size = scan_resp_size - (bytes_left
2098 + sizeof(scan_rsp->bss_descript_size)
2099 + sizeof(scan_rsp->number_of_sets)
2100 + S_DS_GEN);
2101
2102 tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
2103 bss_desc_and_tlv_buffer +
2104 bytes_left);
2105
2106 /* Search the TLV buffer space in the scan response for any valid
2107 TLVs */
2108 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2109 TLV_TYPE_TSFTIMESTAMP,
2110 (struct mwifiex_ie_types_data **)
2111 &tsf_tlv);
2112
2113 /* Search the TLV buffer space in the scan response for any valid
2114 TLVs */
2115 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2116 TLV_TYPE_CHANNELBANDLIST,
2117 (struct mwifiex_ie_types_data **)
2118 &chan_band_tlv);
2119
chunfan chen7d7f07d2016-01-13 01:26:54 -08002120#ifdef CONFIG_PM
2121 if (priv->wdev.wiphy->wowlan_config)
2122 nd_config = priv->wdev.wiphy->wowlan_config->nd_config;
2123#endif
2124
2125 if (nd_config) {
2126 adapter->nd_info =
2127 kzalloc(sizeof(struct cfg80211_wowlan_nd_match) +
2128 sizeof(struct cfg80211_wowlan_nd_match *) *
2129 scan_rsp->number_of_sets, GFP_ATOMIC);
2130
2131 if (adapter->nd_info)
2132 adapter->nd_info->n_matches = scan_rsp->number_of_sets;
2133 }
2134
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002135 for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002136 /*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002137 * If the TSF TLV was appended to the scan results, save this
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002138 * entry's TSF value in the fw_tsf field. It is the firmware's
2139 * TSF value at the time the beacon or probe response was
2140 * received.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002141 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002142 if (tsf_tlv)
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002143 memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
2144 sizeof(fw_tsf));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002145
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002146 if (chan_band_tlv) {
2147 chan_band = &chan_band_tlv->chan_band_param[idx];
2148 radio_type = &chan_band->radio_type;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002149 } else {
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002150 radio_type = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002151 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002152
chunfan chen7d7f07d2016-01-13 01:26:54 -08002153 if (chan_band_tlv && adapter->nd_info) {
2154 adapter->nd_info->matches[idx] =
2155 kzalloc(sizeof(*pmatch) +
2156 sizeof(u32), GFP_ATOMIC);
2157
2158 pmatch = adapter->nd_info->matches[idx];
2159
Dan Carpenterefdf0e32016-02-02 13:00:05 +03002160 if (pmatch) {
chunfan chen7d7f07d2016-01-13 01:26:54 -08002161 memset(pmatch, 0, sizeof(*pmatch));
2162 if (chan_band_tlv) {
2163 pmatch->n_channels = 1;
2164 pmatch->channels[0] =
2165 chan_band->chan_number;
2166 }
2167 }
2168 }
2169
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002170 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2171 &bytes_left,
2172 le64_to_cpu(fw_tsf),
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002173 radio_type, false, 0);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002174 if (ret)
2175 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002176 }
2177
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002178check_next_scan:
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002179 mwifiex_check_next_scan_command(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002180 return ret;
2181}
2182
2183/*
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002184 * This function prepares an extended scan command to be sent to the firmware
2185 *
2186 * This uses the scan command configuration sent to the command processing
2187 * module in command preparation stage to configure a extended scan command
2188 * structure to send to firmware.
2189 */
2190int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
2191 struct host_cmd_ds_command *cmd,
2192 void *data_buf)
2193{
2194 struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan;
2195 struct mwifiex_scan_cmd_config *scan_cfg = data_buf;
2196
2197 memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
2198
2199 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT);
2200
2201 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
2202 cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved)
2203 + scan_cfg->tlv_buf_len + S_DS_GEN));
2204
2205 return 0;
2206}
2207
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002208/* This function prepares an background scan config command to be sent
2209 * to the firmware
2210 */
2211int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv,
2212 struct host_cmd_ds_command *cmd,
2213 void *data_buf)
2214{
2215 struct host_cmd_ds_802_11_bg_scan_config *bgscan_config =
2216 &cmd->params.bg_scan_config;
2217 struct mwifiex_bg_scan_cfg *bgscan_cfg_in = data_buf;
2218 u8 *tlv_pos = bgscan_config->tlv;
2219 u8 num_probes;
2220 u32 ssid_len, chan_idx, scan_type, scan_dur, chan_num;
2221 int i;
2222 struct mwifiex_ie_types_num_probes *num_probes_tlv;
2223 struct mwifiex_ie_types_repeat_count *repeat_count_tlv;
Ganapathi Bhatfdcab082016-01-13 01:26:56 -08002224 struct mwifiex_ie_types_min_rssi_threshold *rssi_threshold_tlv;
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002225 struct mwifiex_ie_types_bgscan_start_later *start_later_tlv;
2226 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
2227 struct mwifiex_ie_types_chan_list_param_set *chan_list_tlv;
2228 struct mwifiex_chan_scan_param_set *temp_chan;
2229
2230 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_CONFIG);
2231 cmd->size = cpu_to_le16(sizeof(*bgscan_config) + S_DS_GEN);
2232
2233 bgscan_config->action = cpu_to_le16(bgscan_cfg_in->action);
2234 bgscan_config->enable = bgscan_cfg_in->enable;
2235 bgscan_config->bss_type = bgscan_cfg_in->bss_type;
2236 bgscan_config->scan_interval =
2237 cpu_to_le32(bgscan_cfg_in->scan_interval);
2238 bgscan_config->report_condition =
2239 cpu_to_le32(bgscan_cfg_in->report_condition);
2240
2241 /* stop sched scan */
2242 if (!bgscan_config->enable)
2243 return 0;
2244
2245 bgscan_config->chan_per_scan = bgscan_cfg_in->chan_per_scan;
2246
2247 num_probes = (bgscan_cfg_in->num_probes ? bgscan_cfg_in->
2248 num_probes : priv->adapter->scan_probes);
2249
2250 if (num_probes) {
2251 num_probes_tlv = (struct mwifiex_ie_types_num_probes *)tlv_pos;
2252 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
2253 num_probes_tlv->header.len =
2254 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
2255 num_probes_tlv->num_probes = cpu_to_le16((u16)num_probes);
2256
2257 tlv_pos += sizeof(num_probes_tlv->header) +
2258 le16_to_cpu(num_probes_tlv->header.len);
2259 }
2260
2261 if (bgscan_cfg_in->repeat_count) {
2262 repeat_count_tlv =
2263 (struct mwifiex_ie_types_repeat_count *)tlv_pos;
2264 repeat_count_tlv->header.type =
2265 cpu_to_le16(TLV_TYPE_REPEAT_COUNT);
2266 repeat_count_tlv->header.len =
2267 cpu_to_le16(sizeof(repeat_count_tlv->repeat_count));
2268 repeat_count_tlv->repeat_count =
2269 cpu_to_le16(bgscan_cfg_in->repeat_count);
2270
2271 tlv_pos += sizeof(repeat_count_tlv->header) +
2272 le16_to_cpu(repeat_count_tlv->header.len);
2273 }
2274
Ganapathi Bhatfdcab082016-01-13 01:26:56 -08002275 if (bgscan_cfg_in->rssi_threshold) {
2276 rssi_threshold_tlv =
2277 (struct mwifiex_ie_types_min_rssi_threshold *)tlv_pos;
2278 rssi_threshold_tlv->header.type =
2279 cpu_to_le16(TLV_TYPE_RSSI_LOW);
2280 rssi_threshold_tlv->header.len =
2281 cpu_to_le16(sizeof(rssi_threshold_tlv->rssi_threshold));
2282 rssi_threshold_tlv->rssi_threshold =
2283 cpu_to_le16(bgscan_cfg_in->rssi_threshold);
2284
2285 tlv_pos += sizeof(rssi_threshold_tlv->header) +
2286 le16_to_cpu(rssi_threshold_tlv->header.len);
2287 }
2288
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002289 for (i = 0; i < bgscan_cfg_in->num_ssids; i++) {
2290 ssid_len = bgscan_cfg_in->ssid_list[i].ssid.ssid_len;
2291
2292 wildcard_ssid_tlv =
2293 (struct mwifiex_ie_types_wildcard_ssid_params *)tlv_pos;
2294 wildcard_ssid_tlv->header.type =
2295 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
2296 wildcard_ssid_tlv->header.len = cpu_to_le16(
2297 (u16)(ssid_len + sizeof(wildcard_ssid_tlv->
2298 max_ssid_length)));
2299
2300 /* max_ssid_length = 0 tells firmware to perform
2301 * specific scan for the SSID filled, whereas
2302 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
2303 * wildcard scan.
2304 */
2305 if (ssid_len)
2306 wildcard_ssid_tlv->max_ssid_length = 0;
2307 else
2308 wildcard_ssid_tlv->max_ssid_length =
2309 IEEE80211_MAX_SSID_LEN;
2310
2311 memcpy(wildcard_ssid_tlv->ssid,
2312 bgscan_cfg_in->ssid_list[i].ssid.ssid, ssid_len);
2313
2314 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
2315 + le16_to_cpu(wildcard_ssid_tlv->header.len));
2316 }
2317
2318 chan_list_tlv = (struct mwifiex_ie_types_chan_list_param_set *)tlv_pos;
2319
2320 if (bgscan_cfg_in->chan_list[0].chan_number) {
2321 dev_dbg(priv->adapter->dev, "info: bgscan: Using supplied channel list\n");
2322
2323 chan_list_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
2324
2325 for (chan_idx = 0;
2326 chan_idx < MWIFIEX_BG_SCAN_CHAN_MAX &&
2327 bgscan_cfg_in->chan_list[chan_idx].chan_number;
2328 chan_idx++) {
2329 temp_chan = chan_list_tlv->chan_scan_param + chan_idx;
2330
2331 /* Increment the TLV header length by size appended */
2332 le16_add_cpu(&chan_list_tlv->header.len,
2333 sizeof(chan_list_tlv->chan_scan_param));
2334
2335 temp_chan->chan_number =
2336 bgscan_cfg_in->chan_list[chan_idx].chan_number;
2337 temp_chan->radio_type =
2338 bgscan_cfg_in->chan_list[chan_idx].radio_type;
2339
2340 scan_type =
2341 bgscan_cfg_in->chan_list[chan_idx].scan_type;
2342
2343 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
2344 temp_chan->chan_scan_mode_bitmap
2345 |= MWIFIEX_PASSIVE_SCAN;
2346 else
2347 temp_chan->chan_scan_mode_bitmap
2348 &= ~MWIFIEX_PASSIVE_SCAN;
2349
2350 if (bgscan_cfg_in->chan_list[chan_idx].scan_time) {
2351 scan_dur = (u16)bgscan_cfg_in->
2352 chan_list[chan_idx].scan_time;
2353 } else {
2354 scan_dur = (scan_type ==
2355 MWIFIEX_SCAN_TYPE_PASSIVE) ?
2356 priv->adapter->passive_scan_time :
2357 priv->adapter->specific_scan_time;
2358 }
2359
2360 temp_chan->min_scan_time = cpu_to_le16(scan_dur);
2361 temp_chan->max_scan_time = cpu_to_le16(scan_dur);
2362 }
2363 } else {
2364 dev_dbg(priv->adapter->dev,
2365 "info: bgscan: Creating full region channel list\n");
2366 chan_num =
2367 mwifiex_bgscan_create_channel_list(priv, bgscan_cfg_in,
2368 chan_list_tlv->
2369 chan_scan_param);
2370 le16_add_cpu(&chan_list_tlv->header.len,
2371 chan_num *
2372 sizeof(chan_list_tlv->chan_scan_param[0]));
2373 }
2374
2375 tlv_pos += (sizeof(chan_list_tlv->header)
2376 + le16_to_cpu(chan_list_tlv->header.len));
2377
2378 if (bgscan_cfg_in->start_later) {
2379 start_later_tlv =
2380 (struct mwifiex_ie_types_bgscan_start_later *)tlv_pos;
2381 start_later_tlv->header.type =
2382 cpu_to_le16(TLV_TYPE_BGSCAN_START_LATER);
2383 start_later_tlv->header.len =
2384 cpu_to_le16(sizeof(start_later_tlv->start_later));
2385 start_later_tlv->start_later =
2386 cpu_to_le16(bgscan_cfg_in->start_later);
2387
2388 tlv_pos += sizeof(start_later_tlv->header) +
2389 le16_to_cpu(start_later_tlv->header.len);
2390 }
2391
2392 /* Append vendor specific IE TLV */
2393 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_BGSCAN, &tlv_pos);
2394
2395 le16_add_cpu(&cmd->size, tlv_pos - bgscan_config->tlv);
2396
2397 return 0;
2398}
2399
2400int mwifiex_stop_bg_scan(struct mwifiex_private *priv)
2401{
2402 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2403
2404 if (!priv->sched_scanning) {
2405 dev_dbg(priv->adapter->dev, "bgscan already stopped!\n");
2406 return 0;
2407 }
2408
2409 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2410 if (!bgscan_cfg)
2411 return -ENOMEM;
2412
2413 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2414 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2415 bgscan_cfg->enable = false;
2416
2417 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2418 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2419 kfree(bgscan_cfg);
2420 return -EFAULT;
2421 }
2422
2423 kfree(bgscan_cfg);
2424 priv->sched_scanning = false;
2425
2426 return 0;
2427}
2428
Avinash Patilbf354432014-10-31 16:08:26 +05302429static void
2430mwifiex_update_chan_statistics(struct mwifiex_private *priv,
2431 struct mwifiex_ietypes_chanstats *tlv_stat)
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002432{
Avinash Patil3223db22014-09-12 20:08:48 +05302433 struct mwifiex_adapter *adapter = priv->adapter;
Avinash Patilbf354432014-10-31 16:08:26 +05302434 u8 i, num_chan;
2435 struct mwifiex_fw_chan_stats *fw_chan_stats;
2436 struct mwifiex_chan_stats chan_stats;
2437
2438 fw_chan_stats = (void *)((u8 *)tlv_stat +
2439 sizeof(struct mwifiex_ie_types_header));
2440 num_chan = le16_to_cpu(tlv_stat->header.len) /
2441 sizeof(struct mwifiex_chan_stats);
2442
2443 for (i = 0 ; i < num_chan; i++) {
2444 chan_stats.chan_num = fw_chan_stats->chan_num;
2445 chan_stats.bandcfg = fw_chan_stats->bandcfg;
2446 chan_stats.flags = fw_chan_stats->flags;
2447 chan_stats.noise = fw_chan_stats->noise;
2448 chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss);
2449 chan_stats.cca_scan_dur =
2450 le16_to_cpu(fw_chan_stats->cca_scan_dur);
2451 chan_stats.cca_busy_dur =
2452 le16_to_cpu(fw_chan_stats->cca_busy_dur);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302453 mwifiex_dbg(adapter, INFO,
2454 "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n",
2455 chan_stats.chan_num,
2456 chan_stats.noise,
2457 chan_stats.total_bss,
2458 chan_stats.cca_scan_dur,
2459 chan_stats.cca_busy_dur);
Avinash Patilbf354432014-10-31 16:08:26 +05302460 memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats,
2461 sizeof(struct mwifiex_chan_stats));
2462 fw_chan_stats++;
2463 }
2464}
2465
2466/* This function handles the command response of extended scan */
2467int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
2468 struct host_cmd_ds_command *resp)
2469{
2470 struct mwifiex_adapter *adapter = priv->adapter;
2471 struct host_cmd_ds_802_11_scan_ext *ext_scan_resp;
2472 struct mwifiex_ie_types_header *tlv;
2473 struct mwifiex_ietypes_chanstats *tlv_stat;
2474 u16 buf_left, type, len;
2475
Avinash Patil3223db22014-09-12 20:08:48 +05302476 struct host_cmd_ds_command *cmd_ptr;
2477 struct cmd_ctrl_node *cmd_node;
2478 unsigned long cmd_flags, scan_flags;
2479 bool complete_scan = false;
2480
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302481 mwifiex_dbg(adapter, INFO, "info: EXT scan returns successfully\n");
Avinash Patil21445042014-05-27 21:39:32 -07002482
Avinash Patilbf354432014-10-31 16:08:26 +05302483 ext_scan_resp = &resp->params.ext_scan;
2484
2485 tlv = (void *)ext_scan_resp->tlv_buffer;
2486 buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN
2487 - 1);
2488
2489 while (buf_left >= sizeof(struct mwifiex_ie_types_header)) {
2490 type = le16_to_cpu(tlv->type);
2491 len = le16_to_cpu(tlv->len);
2492
2493 if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302494 mwifiex_dbg(adapter, ERROR,
2495 "error processing scan response TLVs");
Avinash Patilbf354432014-10-31 16:08:26 +05302496 break;
2497 }
2498
2499 switch (type) {
2500 case TLV_TYPE_CHANNEL_STATS:
2501 tlv_stat = (void *)tlv;
2502 mwifiex_update_chan_statistics(priv, tlv_stat);
2503 break;
2504 default:
2505 break;
2506 }
2507
2508 buf_left -= len + sizeof(struct mwifiex_ie_types_header);
2509 tlv = (void *)((u8 *)tlv + len +
2510 sizeof(struct mwifiex_ie_types_header));
2511 }
2512
Avinash Patil3223db22014-09-12 20:08:48 +05302513 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
2514 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
2515 if (list_empty(&adapter->scan_pending_q)) {
2516 complete_scan = true;
2517 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
2518 cmd_ptr = (void *)cmd_node->cmd_skb->data;
2519 if (le16_to_cpu(cmd_ptr->command) ==
2520 HostCmd_CMD_802_11_SCAN_EXT) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302521 mwifiex_dbg(adapter, INFO,
2522 "Scan pending in command pending list");
Avinash Patil3223db22014-09-12 20:08:48 +05302523 complete_scan = false;
2524 break;
2525 }
2526 }
2527 }
2528 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags);
2529 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags);
2530
2531 if (complete_scan)
2532 mwifiex_complete_scan(priv);
Avinash Patil21445042014-05-27 21:39:32 -07002533
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002534 return 0;
2535}
2536
2537/* This function This function handles the event extended scan report. It
2538 * parses extended scan results and informs to cfg80211 stack.
2539 */
2540int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
2541 void *buf)
2542{
2543 int ret = 0;
2544 struct mwifiex_adapter *adapter = priv->adapter;
2545 u8 *bss_info;
2546 u32 bytes_left, bytes_left_for_tlv, idx;
2547 u16 type, len;
2548 struct mwifiex_ie_types_data *tlv;
2549 struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv;
2550 struct mwifiex_ie_types_bss_scan_info *scan_info_tlv;
2551 u8 *radio_type;
2552 u64 fw_tsf = 0;
2553 s32 rssi = 0;
2554 struct mwifiex_event_scan_result *event_scan = buf;
2555 u8 num_of_set = event_scan->num_of_set;
2556 u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
2557 u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
2558
2559 if (num_of_set > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302560 mwifiex_dbg(adapter, ERROR,
2561 "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
2562 num_of_set);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002563 ret = -1;
2564 goto check_next_scan;
2565 }
2566
2567 bytes_left = scan_resp_size;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302568 mwifiex_dbg(adapter, INFO,
2569 "EXT_SCAN: size %d, returned %d APs...",
2570 scan_resp_size, num_of_set);
Zhaoyang Liu868093a2015-05-12 00:48:19 +05302571 mwifiex_dbg_dump(adapter, CMD_D, "EXT_SCAN buffer:", buf,
2572 scan_resp_size +
2573 sizeof(struct mwifiex_event_scan_result));
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002574
2575 tlv = (struct mwifiex_ie_types_data *)scan_resp;
2576
2577 for (idx = 0; idx < num_of_set && bytes_left; idx++) {
2578 type = le16_to_cpu(tlv->header.type);
2579 len = le16_to_cpu(tlv->header.len);
2580 if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302581 mwifiex_dbg(adapter, ERROR,
2582 "EXT_SCAN: Error bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002583 break;
2584 }
2585 scan_rsp_tlv = NULL;
2586 scan_info_tlv = NULL;
2587 bytes_left_for_tlv = bytes_left;
2588
2589 /* BSS response TLV with beacon or probe response buffer
2590 * at the initial position of each descriptor
2591 */
2592 if (type != TLV_TYPE_BSS_SCAN_RSP)
2593 break;
2594
2595 bss_info = (u8 *)tlv;
2596 scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv;
2597 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2598 bytes_left_for_tlv -=
2599 (len + sizeof(struct mwifiex_ie_types_header));
2600
2601 while (bytes_left_for_tlv >=
2602 sizeof(struct mwifiex_ie_types_header) &&
2603 le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) {
2604 type = le16_to_cpu(tlv->header.type);
2605 len = le16_to_cpu(tlv->header.len);
2606 if (bytes_left_for_tlv <
2607 sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302608 mwifiex_dbg(adapter, ERROR,
2609 "EXT_SCAN: Error in processing TLV,\t"
2610 "bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002611 scan_rsp_tlv = NULL;
2612 bytes_left_for_tlv = 0;
2613 continue;
2614 }
2615 switch (type) {
2616 case TLV_TYPE_BSS_SCAN_INFO:
2617 scan_info_tlv =
2618 (struct mwifiex_ie_types_bss_scan_info *)tlv;
2619 if (len !=
2620 sizeof(struct mwifiex_ie_types_bss_scan_info) -
2621 sizeof(struct mwifiex_ie_types_header)) {
2622 bytes_left_for_tlv = 0;
2623 continue;
2624 }
2625 break;
2626 default:
2627 break;
2628 }
2629 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2630 bytes_left -=
2631 (len + sizeof(struct mwifiex_ie_types_header));
2632 bytes_left_for_tlv -=
2633 (len + sizeof(struct mwifiex_ie_types_header));
2634 }
2635
2636 if (!scan_rsp_tlv)
2637 break;
2638
2639 /* Advance pointer to the beacon buffer length and
2640 * update the bytes count so that the function
2641 * wlan_interpret_bss_desc_with_ie() can handle the
2642 * scan buffer withut any change
2643 */
2644 bss_info += sizeof(u16);
2645 bytes_left -= sizeof(u16);
2646
2647 if (scan_info_tlv) {
2648 rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi));
2649 rssi *= 100; /* Convert dBm to mBm */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302650 mwifiex_dbg(adapter, INFO,
2651 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002652 fw_tsf = le64_to_cpu(scan_info_tlv->tsf);
2653 radio_type = &scan_info_tlv->radio_type;
2654 } else {
2655 radio_type = NULL;
2656 }
2657 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2658 &bytes_left, fw_tsf,
2659 radio_type, true, rssi);
2660 if (ret)
2661 goto check_next_scan;
2662 }
2663
2664check_next_scan:
2665 if (!event_scan->more_event)
2666 mwifiex_check_next_scan_command(priv);
2667
2668 return ret;
2669}
2670
2671/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002672 * This function prepares command for background scan query.
2673 *
2674 * Preparation includes -
2675 * - Setting command ID and proper size
2676 * - Setting background scan flush parameter
2677 * - Ensuring correct endian-ness
2678 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002679int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002680{
2681 struct host_cmd_ds_802_11_bg_scan_query *bg_query =
2682 &cmd->params.bg_scan_query;
2683
2684 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
2685 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
2686 + S_DS_GEN);
2687
2688 bg_query->flush = 1;
2689
2690 return 0;
2691}
2692
2693/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002694 * This function inserts scan command node to the scan pending queue.
2695 */
2696void
2697mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
2698 struct cmd_ctrl_node *cmd_node)
2699{
2700 struct mwifiex_adapter *adapter = priv->adapter;
2701 unsigned long flags;
2702
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002703 cmd_node->wait_q_enabled = true;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002704 cmd_node->condition = &adapter->scan_wait_q_woken;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002705 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
2706 list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
2707 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2708}
2709
2710/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002711 * This function sends a scan command for all available channels to the
2712 * firmware, filtered on a specific SSID.
2713 */
2714static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002715 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002716{
2717 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhaodcd5c792012-10-19 19:01:59 -07002718 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002719 struct mwifiex_user_scan_cfg *scan_cfg;
2720
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002721 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302722 mwifiex_dbg(adapter, WARN,
2723 "cmd: Scan already in process...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002724 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002725 }
2726
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002727 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302728 mwifiex_dbg(adapter, WARN,
2729 "cmd: Scan is blocked during association...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002730 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002731 }
2732
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002733 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002734 if (!scan_cfg)
Christoph Fritzb53575e2011-05-08 22:50:09 +02002735 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002736
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08002737 scan_cfg->ssid_list = req_ssid;
2738 scan_cfg->num_ssids = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002739
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002740 ret = mwifiex_scan_networks(priv, scan_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002741
2742 kfree(scan_cfg);
2743 return ret;
2744}
2745
2746/*
2747 * Sends IOCTL request to start a scan.
2748 *
2749 * This function allocates the IOCTL request buffer, fills it
2750 * with requisite parameters and calls the IOCTL handler.
2751 *
2752 * Scan command can be issued for both normal scan and specific SSID
2753 * scan, depending upon whether an SSID is provided or not.
2754 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002755int mwifiex_request_scan(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002756 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002757{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002758 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002759
2760 if (down_interruptible(&priv->async_sem)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302761 mwifiex_dbg(priv->adapter, ERROR,
2762 "%s: acquire semaphore fail\n",
2763 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002764 return -1;
2765 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002766
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002767 priv->adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002768
2769 if (req_ssid && req_ssid->ssid_len != 0)
2770 /* Specific SSID scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002771 ret = mwifiex_scan_specific_ssid(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002772 else
2773 /* Normal scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002774 ret = mwifiex_scan_networks(priv, NULL);
2775
Amitkumar Karwarb0e70c22012-10-19 19:19:17 -07002776 up(&priv->async_sem);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002777
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002778 return ret;
2779}
2780
2781/*
2782 * This function appends the vendor specific IE TLV to a buffer.
2783 */
2784int
2785mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
2786 u16 vsie_mask, u8 **buffer)
2787{
2788 int id, ret_len = 0;
2789 struct mwifiex_ie_types_vendor_param_set *vs_param_set;
2790
2791 if (!buffer)
2792 return 0;
2793 if (!(*buffer))
2794 return 0;
2795
2796 /*
2797 * Traverse through the saved vendor specific IE array and append
2798 * the selected(scan/assoc/adhoc) IE as TLV to the command
2799 */
2800 for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
2801 if (priv->vs_ie[id].mask & vsie_mask) {
2802 vs_param_set =
2803 (struct mwifiex_ie_types_vendor_param_set *)
2804 *buffer;
2805 vs_param_set->header.type =
2806 cpu_to_le16(TLV_TYPE_PASSTHROUGH);
2807 vs_param_set->header.len =
2808 cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
2809 & 0x00FF) + 2);
2810 memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
2811 le16_to_cpu(vs_param_set->header.len));
2812 *buffer += le16_to_cpu(vs_param_set->header.len) +
2813 sizeof(struct mwifiex_ie_types_header);
2814 ret_len += le16_to_cpu(vs_param_set->header.len) +
2815 sizeof(struct mwifiex_ie_types_header);
2816 }
2817 }
2818 return ret_len;
2819}
2820
2821/*
2822 * This function saves a beacon buffer of the current BSS descriptor.
2823 *
2824 * The current beacon buffer is saved so that it can be restored in the
2825 * following cases that makes the beacon buffer not to contain the current
2826 * ssid's beacon buffer.
2827 * - The current ssid was not found somehow in the last scan.
2828 * - The current ssid was the last entry of the scan table and overloaded.
2829 */
2830void
2831mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2832{
2833 struct mwifiex_bssdescriptor *curr_bss =
2834 &priv->curr_bss_params.bss_descriptor;
2835
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002836 if (!curr_bss->beacon_buf_size)
2837 return;
2838
2839 /* allocate beacon buffer at 1st time; or if it's size has changed */
2840 if (!priv->curr_bcn_buf ||
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002841 priv->curr_bcn_size != curr_bss->beacon_buf_size) {
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002842 priv->curr_bcn_size = curr_bss->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002843
2844 kfree(priv->curr_bcn_buf);
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07002845 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002846 GFP_ATOMIC);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002847 if (!priv->curr_bcn_buf)
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002848 return;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002849 }
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002850
2851 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002852 curr_bss->beacon_buf_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302853 mwifiex_dbg(priv->adapter, INFO,
2854 "info: current beacon saved %d\n",
2855 priv->curr_bcn_size);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002856
2857 curr_bss->beacon_buf = priv->curr_bcn_buf;
2858
2859 /* adjust the pointers in the current BSS descriptor */
2860 if (curr_bss->bcn_wpa_ie)
2861 curr_bss->bcn_wpa_ie =
2862 (struct ieee_types_vendor_specific *)
2863 (curr_bss->beacon_buf +
2864 curr_bss->wpa_offset);
2865
2866 if (curr_bss->bcn_rsn_ie)
2867 curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
2868 (curr_bss->beacon_buf +
2869 curr_bss->rsn_offset);
2870
2871 if (curr_bss->bcn_ht_cap)
2872 curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
2873 (curr_bss->beacon_buf +
2874 curr_bss->ht_cap_offset);
2875
Johannes Berg074d46d2012-03-15 19:45:16 +01002876 if (curr_bss->bcn_ht_oper)
2877 curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002878 (curr_bss->beacon_buf +
2879 curr_bss->ht_info_offset);
2880
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002881 if (curr_bss->bcn_vht_cap)
Amitkumar Karward5124642014-03-04 18:43:14 -08002882 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2883 curr_bss->vht_cap_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002884
2885 if (curr_bss->bcn_vht_oper)
Amitkumar Karward5124642014-03-04 18:43:14 -08002886 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2887 curr_bss->vht_info_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002888
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002889 if (curr_bss->bcn_bss_co_2040)
2890 curr_bss->bcn_bss_co_2040 =
Joe Perches2c208892012-06-04 12:44:17 +00002891 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002892
2893 if (curr_bss->bcn_ext_cap)
Joe Perches2c208892012-06-04 12:44:17 +00002894 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2895 curr_bss->ext_cap_offset;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002896
2897 if (curr_bss->oper_mode)
2898 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2899 curr_bss->oper_mode_offset);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002900}
2901
2902/*
2903 * This function frees the current BSS descriptor beacon buffer.
2904 */
2905void
2906mwifiex_free_curr_bcn(struct mwifiex_private *priv)
2907{
2908 kfree(priv->curr_bcn_buf);
2909 priv->curr_bcn_buf = NULL;
2910}