blob: 19df92b6668d20f036d6717ba99d6bbdb2f6603d [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;
Amitkumar Karwar1b499cb2016-04-24 23:49:51 -0700501
502 scan_chan_list[chan_idx].chan_scan_mode_bitmap
503 |= MWIFIEX_DISABLE_CHAN_FILT;
504
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 if (filtered_scan) {
506 scan_chan_list[chan_idx].max_scan_time =
507 cpu_to_le16(adapter->specific_scan_time);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700508 }
Amitkumar Karward06b7b92011-09-21 21:43:22 -0700509 chan_idx++;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510 }
511
512 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700513 return chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514}
515
Xinming Hu0c9b7f22016-01-13 01:26:52 -0800516/* This function creates a channel list tlv for bgscan config, based
517 * on region/band information.
518 */
519static int
520mwifiex_bgscan_create_channel_list(struct mwifiex_private *priv,
521 const struct mwifiex_bg_scan_cfg
522 *bgscan_cfg_in,
523 struct mwifiex_chan_scan_param_set
524 *scan_chan_list)
525{
Johannes Berg57fbcce2016-04-12 15:56:15 +0200526 enum nl80211_band band;
Xinming Hu0c9b7f22016-01-13 01:26:52 -0800527 struct ieee80211_supported_band *sband;
528 struct ieee80211_channel *ch;
529 struct mwifiex_adapter *adapter = priv->adapter;
530 int chan_idx = 0, i;
531
Johannes Berg57fbcce2016-04-12 15:56:15 +0200532 for (band = 0; (band < NUM_NL80211_BANDS); band++) {
Xinming Hu0c9b7f22016-01-13 01:26:52 -0800533 if (!priv->wdev.wiphy->bands[band])
534 continue;
535
536 sband = priv->wdev.wiphy->bands[band];
537
538 for (i = 0; (i < sband->n_channels) ; i++) {
539 ch = &sband->channels[i];
540 if (ch->flags & IEEE80211_CHAN_DISABLED)
541 continue;
542 scan_chan_list[chan_idx].radio_type = band;
543
544 if (bgscan_cfg_in->chan_list[0].scan_time)
545 scan_chan_list[chan_idx].max_scan_time =
546 cpu_to_le16((u16)bgscan_cfg_in->
547 chan_list[0].scan_time);
548 else if (ch->flags & IEEE80211_CHAN_NO_IR)
549 scan_chan_list[chan_idx].max_scan_time =
550 cpu_to_le16(adapter->passive_scan_time);
551 else
552 scan_chan_list[chan_idx].max_scan_time =
553 cpu_to_le16(adapter->
554 specific_scan_time);
555
556 if (ch->flags & IEEE80211_CHAN_NO_IR)
557 scan_chan_list[chan_idx].chan_scan_mode_bitmap
558 |= MWIFIEX_PASSIVE_SCAN;
559 else
560 scan_chan_list[chan_idx].chan_scan_mode_bitmap
561 &= ~MWIFIEX_PASSIVE_SCAN;
562
563 scan_chan_list[chan_idx].chan_number =
564 (u32)ch->hw_value;
565 chan_idx++;
566 }
567 }
568 return chan_idx;
569}
570
Avinash Patil78dfca62013-07-30 17:18:56 -0700571/* This function appends rate TLV to scan config command. */
572static int
573mwifiex_append_rate_tlv(struct mwifiex_private *priv,
574 struct mwifiex_scan_cmd_config *scan_cfg_out,
575 u8 radio)
576{
577 struct mwifiex_ie_types_rates_param_set *rates_tlv;
578 u8 rates[MWIFIEX_SUPPORTED_RATES], *tlv_pos;
579 u32 rates_size;
580
581 memset(rates, 0, sizeof(rates));
582
583 tlv_pos = (u8 *)scan_cfg_out->tlv_buf + scan_cfg_out->tlv_buf_len;
584
585 if (priv->scan_request)
586 rates_size = mwifiex_get_rates_from_cfg80211(priv, rates,
587 radio);
588 else
589 rates_size = mwifiex_get_supported_rates(priv, rates);
590
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530591 mwifiex_dbg(priv->adapter, CMD,
592 "info: SCAN_CMD: Rates size = %d\n",
Avinash Patil78dfca62013-07-30 17:18:56 -0700593 rates_size);
594 rates_tlv = (struct mwifiex_ie_types_rates_param_set *)tlv_pos;
595 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
596 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
597 memcpy(rates_tlv->rates, rates, rates_size);
598 scan_cfg_out->tlv_buf_len += sizeof(rates_tlv->header) + rates_size;
599
600 return rates_size;
601}
602
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603/*
604 * This function constructs and sends multiple scan config commands to
605 * the firmware.
606 *
607 * Previous routines in the code flow have created a scan command configuration
608 * with any requested TLVs. This function splits the channel TLV into maximum
609 * channels supported per scan lists and sends the portion of the channel TLV,
610 * along with the other TLVs, to the firmware.
611 */
612static int
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700613mwifiex_scan_channel_list(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700614 u32 max_chan_per_scan, u8 filtered_scan,
615 struct mwifiex_scan_cmd_config *scan_cfg_out,
616 struct mwifiex_ie_types_chan_list_param_set
617 *chan_tlv_out,
618 struct mwifiex_chan_scan_param_set *scan_chan_list)
619{
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700620 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621 int ret = 0;
622 struct mwifiex_chan_scan_param_set *tmp_chan_list;
623 struct mwifiex_chan_scan_param_set *start_chan;
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 */
Daniel Mentz5653c642017-03-09 14:06:16 +0530694 le16_unaligned_add_cpu(&chan_tlv_out->header.len,
695 sizeof(
696 chan_tlv_out->chan_scan_param));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700697
698 /*
699 * The tlv buffer length is set to the number of bytes
700 * of the between the channel tlv pointer and the start
701 * of the tlv buffer. This compensates for any TLVs
702 * that were appended before the channel list.
703 */
704 scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
705 scan_cfg_out->tlv_buf);
706
707 /* Add the size of the channel tlv header and the data
708 length */
709 scan_cfg_out->tlv_buf_len +=
710 (sizeof(chan_tlv_out->header)
711 + le16_to_cpu(chan_tlv_out->header.len));
712
713 /* Increment the index to the channel tlv we are
714 constructing */
715 tlv_idx++;
716
717 /* Count the total scan time per command */
718 total_scan_time +=
719 le16_to_cpu(tmp_chan_list->max_scan_time);
720
721 done_early = false;
722
723 /* Stop the loop if the *current* channel is in the
724 1,6,11 set and we are not filtering on a BSSID
725 or SSID. */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700726 if (!filtered_scan &&
727 (tmp_chan_list->chan_number == 1 ||
728 tmp_chan_list->chan_number == 6 ||
729 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700730 done_early = true;
731
732 /* Increment the tmp pointer to the next channel to
733 be scanned */
734 tmp_chan_list++;
735
736 /* Stop the loop if the *next* channel is in the 1,6,11
737 set. This will cause it to be the only channel
738 scanned on the next interation */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700739 if (!filtered_scan &&
740 (tmp_chan_list->chan_number == 1 ||
741 tmp_chan_list->chan_number == 6 ||
742 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700743 done_early = true;
744 }
745
746 /* The total scan time should be less than scan command timeout
747 value */
748 if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530749 mwifiex_dbg(priv->adapter, ERROR,
750 "total scan time %dms\t"
751 "is over limit (%dms), scan skipped\n",
752 total_scan_time,
753 MWIFIEX_MAX_TOTAL_SCAN_TIME);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700754 ret = -1;
755 break;
756 }
757
Avinash Patil78dfca62013-07-30 17:18:56 -0700758 rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out,
759 radio_type);
760
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700761 priv->adapter->scan_channels = start_chan;
762
763 /* Send the scan command to the firmware with the specified
764 cfg */
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800765 if (priv->adapter->ext_scan)
766 cmd_no = HostCmd_CMD_802_11_SCAN_EXT;
767 else
768 cmd_no = HostCmd_CMD_802_11_SCAN;
769
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800770 ret = mwifiex_send_cmd(priv, cmd_no, HostCmd_ACT_GEN_SET,
771 0, scan_cfg_out, false);
Avinash Patil78dfca62013-07-30 17:18:56 -0700772
773 /* rate IE is updated per scan command but same starting
774 * pointer is used each time so that rate IE from earlier
775 * scan_cfg_out->buf is overwritten with new one.
776 */
777 scan_cfg_out->tlv_buf_len -=
778 sizeof(struct mwifiex_ie_types_header) + rates_size;
779
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700780 if (ret) {
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +0100781 mwifiex_cancel_pending_scan_cmd(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700782 break;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700783 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700784 }
785
786 if (ret)
787 return -1;
788
789 return 0;
790}
791
792/*
793 * This function constructs a scan command configuration structure to use
794 * in scan commands.
795 *
796 * Application layer or other functions can invoke network scanning
797 * with a scan configuration supplied in a user scan configuration structure.
798 * This structure is used as the basis of one or many scan command configuration
799 * commands that are sent to the command processing module and eventually to the
800 * firmware.
801 *
802 * This function creates a scan command configuration structure based on the
803 * following user supplied parameters (if present):
804 * - SSID filter
805 * - BSSID filter
806 * - Number of Probes to be sent
807 * - Channel list
808 *
809 * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
810 * If the number of probes is not set, adapter default setting is used.
811 */
812static void
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700813mwifiex_config_scan(struct mwifiex_private *priv,
814 const struct mwifiex_user_scan_cfg *user_scan_in,
815 struct mwifiex_scan_cmd_config *scan_cfg_out,
816 struct mwifiex_ie_types_chan_list_param_set **chan_list_out,
817 struct mwifiex_chan_scan_param_set *scan_chan_list,
818 u8 *max_chan_per_scan, u8 *filtered_scan,
819 u8 *scan_current_only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700820{
821 struct mwifiex_adapter *adapter = priv->adapter;
822 struct mwifiex_ie_types_num_probes *num_probes_tlv;
Avinash Patilcb91be82014-09-12 20:08:54 +0530823 struct mwifiex_ie_types_scan_chan_gap *chan_gap_tlv;
Ganapathi Bhatc2a8f0f2016-07-25 21:21:07 +0530824 struct mwifiex_ie_types_random_mac *random_mac_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800826 struct mwifiex_ie_types_bssid_list *bssid_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700827 u8 *tlv_pos;
828 u32 num_probes;
829 u32 ssid_len;
830 u32 chan_idx;
831 u32 scan_type;
832 u16 scan_dur;
833 u8 channel;
834 u8 radio_type;
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800835 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700836 u8 ssid_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700837 struct mwifiex_ie_types_htcap *ht_cap;
Aniket Nagarnaik40d74122015-07-16 08:05:21 -0700838 struct mwifiex_ie_types_bss_mode *bss_mode;
Ganapathi Bhatc2a8f0f2016-07-25 21:21:07 +0530839 const u8 zero_mac[6] = {0, 0, 0, 0, 0, 0};
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700840
841 /* The tlv_buf_len is calculated for each scan command. The TLVs added
842 in this routine will be preserved since the routine that sends the
843 command will append channelTLVs at *chan_list_out. The difference
844 between the *chan_list_out and the tlv_buf start will be used to
845 calculate the size of anything we add in this routine. */
846 scan_cfg_out->tlv_buf_len = 0;
847
848 /* Running tlv pointer. Assigned to chan_list_out at end of function
849 so later routines know where channels can be added to the command
850 buf */
851 tlv_pos = scan_cfg_out->tlv_buf;
852
853 /* Initialize the scan as un-filtered; the flag is later set to TRUE
854 below if a SSID or BSSID filter is sent in the command */
855 *filtered_scan = false;
856
857 /* Initialize the scan as not being only on the current channel. If
858 the channel list is customized, only contains one channel, and is
859 the active channel, this is set true and data flow is not halted. */
860 *scan_current_only = false;
861
862 if (user_scan_in) {
Daniel Mentz5653c642017-03-09 14:06:16 +0530863 u8 tmpaddr[ETH_ALEN];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700864
865 /* Default the ssid_filter flag to TRUE, set false under
866 certain wildcard conditions and qualified by the existence
867 of an SSID list before marking the scan as filtered */
868 ssid_filter = true;
869
870 /* Set the BSS type scan filter, use Adapter setting if
871 unset */
872 scan_cfg_out->bss_mode =
Andreas Fenkart2ccf7ce2016-03-10 09:44:07 +0100873 (u8)(user_scan_in->bss_mode ?: adapter->scan_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874
875 /* Set the number of probes to send, use Adapter setting
876 if unset */
Andreas Fenkart2ccf7ce2016-03-10 09:44:07 +0100877 num_probes = user_scan_in->num_probes ?: adapter->scan_probes;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878
879 /*
880 * Set the BSSID filter to the incoming configuration,
881 * if non-zero. If not set, it will remain disabled
882 * (all zeros).
883 */
884 memcpy(scan_cfg_out->specific_bssid,
885 user_scan_in->specific_bssid,
886 sizeof(scan_cfg_out->specific_bssid));
887
Daniel Mentz5653c642017-03-09 14:06:16 +0530888 memcpy(tmpaddr, scan_cfg_out->specific_bssid, ETH_ALEN);
889
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800890 if (adapter->ext_scan &&
Daniel Mentz5653c642017-03-09 14:06:16 +0530891 !is_zero_ether_addr(tmpaddr)) {
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800892 bssid_tlv =
893 (struct mwifiex_ie_types_bssid_list *)tlv_pos;
894 bssid_tlv->header.type = cpu_to_le16(TLV_TYPE_BSSID);
895 bssid_tlv->header.len = cpu_to_le16(ETH_ALEN);
896 memcpy(bssid_tlv->bssid, user_scan_in->specific_bssid,
897 ETH_ALEN);
898 tlv_pos += sizeof(struct mwifiex_ie_types_bssid_list);
899 }
900
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800901 for (i = 0; i < user_scan_in->num_ssids; i++) {
902 ssid_len = user_scan_in->ssid_list[i].ssid_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700903
904 wildcard_ssid_tlv =
905 (struct mwifiex_ie_types_wildcard_ssid_params *)
906 tlv_pos;
907 wildcard_ssid_tlv->header.type =
908 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
909 wildcard_ssid_tlv->header.len = cpu_to_le16(
910 (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
911 max_ssid_length)));
Amitkumar Karwarfada10582011-11-09 21:36:21 -0800912
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800913 /*
914 * max_ssid_length = 0 tells firmware to perform
915 * specific scan for the SSID filled, whereas
916 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
917 * wildcard scan.
918 */
919 if (ssid_len)
920 wildcard_ssid_tlv->max_ssid_length = 0;
921 else
922 wildcard_ssid_tlv->max_ssid_length =
923 IEEE80211_MAX_SSID_LEN;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700924
Aniket Nagarnaik0c6303c2015-07-16 08:05:22 -0700925 if (!memcmp(user_scan_in->ssid_list[i].ssid,
926 "DIRECT-", 7))
927 wildcard_ssid_tlv->max_ssid_length = 0xfe;
928
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700929 memcpy(wildcard_ssid_tlv->ssid,
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800930 user_scan_in->ssid_list[i].ssid, ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700931
932 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
933 + le16_to_cpu(wildcard_ssid_tlv->header.len));
934
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530935 mwifiex_dbg(adapter, INFO,
936 "info: scan: ssid[%d]: %s, %d\n",
937 i, wildcard_ssid_tlv->ssid,
938 wildcard_ssid_tlv->max_ssid_length);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700939
940 /* Empty wildcard ssid with a maxlen will match many or
941 potentially all SSIDs (maxlen == 32), therefore do
942 not treat the scan as
943 filtered. */
944 if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
945 ssid_filter = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700946 }
947
948 /*
949 * The default number of channels sent in the command is low to
950 * ensure the response buffer from the firmware does not
951 * truncate scan results. That is not an issue with an SSID
952 * or BSSID filter applied to the scan results in the firmware.
953 */
Daniel Mentz5653c642017-03-09 14:06:16 +0530954 memcpy(tmpaddr, scan_cfg_out->specific_bssid, ETH_ALEN);
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700955 if ((i && ssid_filter) ||
Daniel Mentz5653c642017-03-09 14:06:16 +0530956 !is_zero_ether_addr(tmpaddr))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700957 *filtered_scan = true;
Avinash Patil8eda10e2014-09-17 23:01:26 +0530958
959 if (user_scan_in->scan_chan_gap) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530960 mwifiex_dbg(adapter, INFO,
961 "info: scan: channel gap = %d\n",
962 user_scan_in->scan_chan_gap);
Avinash Patil8eda10e2014-09-17 23:01:26 +0530963 *max_chan_per_scan =
964 MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
965
966 chan_gap_tlv = (void *)tlv_pos;
967 chan_gap_tlv->header.type =
968 cpu_to_le16(TLV_TYPE_SCAN_CHANNEL_GAP);
969 chan_gap_tlv->header.len =
970 cpu_to_le16(sizeof(chan_gap_tlv->chan_gap));
971 chan_gap_tlv->chan_gap =
972 cpu_to_le16((user_scan_in->scan_chan_gap));
973 tlv_pos +=
974 sizeof(struct mwifiex_ie_types_scan_chan_gap);
975 }
Ganapathi Bhatc2a8f0f2016-07-25 21:21:07 +0530976
977 if (!ether_addr_equal(user_scan_in->random_mac, zero_mac)) {
978 random_mac_tlv = (void *)tlv_pos;
979 random_mac_tlv->header.type =
980 cpu_to_le16(TLV_TYPE_RANDOM_MAC);
981 random_mac_tlv->header.len =
982 cpu_to_le16(sizeof(random_mac_tlv->mac));
983 ether_addr_copy(random_mac_tlv->mac,
984 user_scan_in->random_mac);
985 tlv_pos +=
986 sizeof(struct mwifiex_ie_types_random_mac);
987 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700988 } else {
989 scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
990 num_probes = adapter->scan_probes;
991 }
992
993 /*
994 * If a specific BSSID or SSID is used, the number of channels in the
995 * scan command will be increased to the absolute maximum.
996 */
Amitkumar Karwar0a5cc492017-03-16 16:16:11 +0530997 if (*filtered_scan) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700998 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
Amitkumar Karwar0a5cc492017-03-16 16:16:11 +0530999 } else {
1000 if (!priv->media_connected)
1001 *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
1002 else
1003 *max_chan_per_scan =
1004 MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD / 2;
1005 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001006
Aniket Nagarnaik40d74122015-07-16 08:05:21 -07001007 if (adapter->ext_scan) {
1008 bss_mode = (struct mwifiex_ie_types_bss_mode *)tlv_pos;
1009 bss_mode->header.type = cpu_to_le16(TLV_TYPE_BSS_MODE);
1010 bss_mode->header.len = cpu_to_le16(sizeof(bss_mode->bss_mode));
1011 bss_mode->bss_mode = scan_cfg_out->bss_mode;
1012 tlv_pos += sizeof(bss_mode->header) +
1013 le16_to_cpu(bss_mode->header.len);
1014 }
1015
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016 /* If the input config or adapter has the number of Probes set,
1017 add tlv */
1018 if (num_probes) {
1019
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301020 mwifiex_dbg(adapter, INFO,
1021 "info: scan: num_probes = %d\n",
1022 num_probes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001023
1024 num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
1025 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
1026 num_probes_tlv->header.len =
1027 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
1028 num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
1029
1030 tlv_pos += sizeof(num_probes_tlv->header) +
1031 le16_to_cpu(num_probes_tlv->header.len);
1032
1033 }
1034
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001035 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
1036 (priv->adapter->config_bands & BAND_GN ||
1037 priv->adapter->config_bands & BAND_AN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
1039 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
1040 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1041 ht_cap->header.len =
1042 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001043 radio_type =
1044 mwifiex_band_to_radio_type(priv->adapter->config_bands);
Amitkumar Karwar341b8802014-02-07 16:27:31 -08001045 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001046 tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
1047 }
1048
1049 /* Append vendor specific IE TLV */
1050 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
1051
1052 /*
1053 * Set the output for the channel TLV to the address in the tlv buffer
1054 * past any TLVs that were added in this function (SSID, num_probes).
1055 * Channel TLVs will be added past this for each scan command,
1056 * preserving the TLVs that were previously added.
1057 */
1058 *chan_list_out =
1059 (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
1060
1061 if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
1062
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301063 mwifiex_dbg(adapter, INFO,
1064 "info: Scan: Using supplied channel list\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001065
1066 for (chan_idx = 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001067 chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX &&
1068 user_scan_in->chan_list[chan_idx].chan_number;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001069 chan_idx++) {
1070
1071 channel = user_scan_in->chan_list[chan_idx].chan_number;
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001072 scan_chan_list[chan_idx].chan_number = channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001073
1074 radio_type =
1075 user_scan_in->chan_list[chan_idx].radio_type;
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001076 scan_chan_list[chan_idx].radio_type = radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001077
1078 scan_type = user_scan_in->chan_list[chan_idx].scan_type;
1079
1080 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001081 scan_chan_list[chan_idx].chan_scan_mode_bitmap
chunfan chen2375fa22015-08-05 06:09:42 -07001082 |= (MWIFIEX_PASSIVE_SCAN |
1083 MWIFIEX_HIDDEN_SSID_REPORT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001084 else
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001085 scan_chan_list[chan_idx].chan_scan_mode_bitmap
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001086 &= ~MWIFIEX_PASSIVE_SCAN;
1087
Amitkumar Karwar1b499cb2016-04-24 23:49:51 -07001088 scan_chan_list[chan_idx].chan_scan_mode_bitmap
1089 |= MWIFIEX_DISABLE_CHAN_FILT;
Amitkumar Karwarf3e1af32012-10-19 19:19:18 -07001090
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001091 if (user_scan_in->chan_list[chan_idx].scan_time) {
1092 scan_dur = (u16) user_scan_in->
1093 chan_list[chan_idx].scan_time;
1094 } else {
1095 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1096 scan_dur = adapter->passive_scan_time;
1097 else if (*filtered_scan)
1098 scan_dur = adapter->specific_scan_time;
1099 else
1100 scan_dur = adapter->active_scan_time;
1101 }
1102
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001103 scan_chan_list[chan_idx].min_scan_time =
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001104 cpu_to_le16(scan_dur);
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001105 scan_chan_list[chan_idx].max_scan_time =
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106 cpu_to_le16(scan_dur);
1107 }
1108
1109 /* Check if we are only scanning the current channel */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001110 if ((chan_idx == 1) &&
1111 (user_scan_in->chan_list[0].chan_number ==
1112 priv->curr_bss_params.bss_descriptor.channel)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001113 *scan_current_only = true;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301114 mwifiex_dbg(adapter, INFO,
1115 "info: Scan: Scanning current channel only\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001116 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001117 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301118 mwifiex_dbg(adapter, INFO,
1119 "info: Scan: Creating full region channel list\n");
Kirtika Ruchandani8ac91342016-11-23 17:24:54 -08001120 mwifiex_scan_create_channel_list(priv, user_scan_in,
1121 scan_chan_list,
1122 *filtered_scan);
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001123 }
1124
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001125}
1126
1127/*
1128 * This function inspects the scan response buffer for pointers to
1129 * expected TLVs.
1130 *
1131 * TLVs can be included at the end of the scan response BSS information.
1132 *
1133 * Data in the buffer is parsed pointers to TLVs that can potentially
1134 * be passed back in the response.
1135 */
1136static void
1137mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
1138 struct mwifiex_ie_types_data *tlv,
1139 u32 tlv_buf_size, u32 req_tlv_type,
1140 struct mwifiex_ie_types_data **tlv_data)
1141{
1142 struct mwifiex_ie_types_data *current_tlv;
1143 u32 tlv_buf_left;
1144 u32 tlv_type;
1145 u32 tlv_len;
1146
1147 current_tlv = tlv;
1148 tlv_buf_left = tlv_buf_size;
1149 *tlv_data = NULL;
1150
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301151 mwifiex_dbg(adapter, INFO,
1152 "info: SCAN_RESP: tlv_buf_size = %d\n",
1153 tlv_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001154
1155 while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
1156
1157 tlv_type = le16_to_cpu(current_tlv->header.type);
1158 tlv_len = le16_to_cpu(current_tlv->header.len);
1159
1160 if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301161 mwifiex_dbg(adapter, ERROR,
1162 "SCAN_RESP: TLV buffer corrupt\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001163 break;
1164 }
1165
1166 if (req_tlv_type == tlv_type) {
1167 switch (tlv_type) {
1168 case TLV_TYPE_TSFTIMESTAMP:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301169 mwifiex_dbg(adapter, INFO,
1170 "info: SCAN_RESP: TSF\t"
1171 "timestamp TLV, len = %d\n",
1172 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001173 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001174 break;
1175 case TLV_TYPE_CHANNELBANDLIST:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301176 mwifiex_dbg(adapter, INFO,
1177 "info: SCAN_RESP: channel\t"
1178 "band list TLV, len = %d\n",
1179 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001180 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001181 break;
1182 default:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301183 mwifiex_dbg(adapter, ERROR,
1184 "SCAN_RESP: unhandled TLV = %d\n",
1185 tlv_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001186 /* Give up, this seems corrupted */
1187 return;
1188 }
1189 }
1190
1191 if (*tlv_data)
1192 break;
1193
1194
1195 tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
1196 current_tlv =
1197 (struct mwifiex_ie_types_data *) (current_tlv->data +
1198 tlv_len);
1199
1200 } /* while */
1201}
1202
1203/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001204 * This function parses provided beacon buffer and updates
1205 * respective fields in bss descriptor structure.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001206 */
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001207int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1208 struct mwifiex_bssdescriptor *bss_entry)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001209{
1210 int ret = 0;
1211 u8 element_id;
1212 struct ieee_types_fh_param_set *fh_param_set;
1213 struct ieee_types_ds_param_set *ds_param_set;
1214 struct ieee_types_cf_param_set *cf_param_set;
1215 struct ieee_types_ibss_param_set *ibss_param_set;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001216 u8 *current_ptr;
1217 u8 *rate;
1218 u8 element_len;
1219 u16 total_ie_len;
1220 u8 bytes_to_copy;
1221 u8 rate_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001222 u8 found_data_rate_ie;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001223 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001224 struct ieee_types_vendor_specific *vendor_ie;
1225 const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
1226 const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
1227
1228 found_data_rate_ie = false;
1229 rate_size = 0;
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001230 current_ptr = bss_entry->beacon_buf;
1231 bytes_left = bss_entry->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232
1233 /* Process variable IE */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001234 while (bytes_left >= 2) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001235 element_id = *current_ptr;
1236 element_len = *(current_ptr + 1);
1237 total_ie_len = element_len + sizeof(struct ieee_types_header);
1238
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001239 if (bytes_left < total_ie_len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301240 mwifiex_dbg(adapter, ERROR,
1241 "err: InterpretIE: in processing\t"
1242 "IE, bytes left < IE length\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001243 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001244 }
1245 switch (element_id) {
1246 case WLAN_EID_SSID:
1247 bss_entry->ssid.ssid_len = element_len;
1248 memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
1249 element_len);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301250 mwifiex_dbg(adapter, INFO,
1251 "info: InterpretIE: ssid: %-32s\n",
1252 bss_entry->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001253 break;
1254
1255 case WLAN_EID_SUPP_RATES:
1256 memcpy(bss_entry->data_rates, current_ptr + 2,
1257 element_len);
1258 memcpy(bss_entry->supported_rates, current_ptr + 2,
1259 element_len);
1260 rate_size = element_len;
1261 found_data_rate_ie = true;
1262 break;
1263
1264 case WLAN_EID_FH_PARAMS:
1265 fh_param_set =
1266 (struct ieee_types_fh_param_set *) current_ptr;
1267 memcpy(&bss_entry->phy_param_set.fh_param_set,
1268 fh_param_set,
1269 sizeof(struct ieee_types_fh_param_set));
1270 break;
1271
1272 case WLAN_EID_DS_PARAMS:
1273 ds_param_set =
1274 (struct ieee_types_ds_param_set *) current_ptr;
1275
1276 bss_entry->channel = ds_param_set->current_chan;
1277
1278 memcpy(&bss_entry->phy_param_set.ds_param_set,
1279 ds_param_set,
1280 sizeof(struct ieee_types_ds_param_set));
1281 break;
1282
1283 case WLAN_EID_CF_PARAMS:
1284 cf_param_set =
1285 (struct ieee_types_cf_param_set *) current_ptr;
1286 memcpy(&bss_entry->ss_param_set.cf_param_set,
1287 cf_param_set,
1288 sizeof(struct ieee_types_cf_param_set));
1289 break;
1290
1291 case WLAN_EID_IBSS_PARAMS:
1292 ibss_param_set =
1293 (struct ieee_types_ibss_param_set *)
1294 current_ptr;
1295 memcpy(&bss_entry->ss_param_set.ibss_param_set,
1296 ibss_param_set,
1297 sizeof(struct ieee_types_ibss_param_set));
1298 break;
1299
1300 case WLAN_EID_ERP_INFO:
1301 bss_entry->erp_flags = *(current_ptr + 2);
1302 break;
1303
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -07001304 case WLAN_EID_PWR_CONSTRAINT:
1305 bss_entry->local_constraint = *(current_ptr + 2);
1306 bss_entry->sensed_11h = true;
1307 break;
1308
1309 case WLAN_EID_CHANNEL_SWITCH:
1310 bss_entry->chan_sw_ie_present = true;
Gustavo A. R. Silva666cc432018-05-25 16:38:54 -05001311 /* fall through */
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -07001312 case WLAN_EID_PWR_CAPABILITY:
1313 case WLAN_EID_TPC_REPORT:
1314 case WLAN_EID_QUIET:
1315 bss_entry->sensed_11h = true;
1316 break;
1317
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001318 case WLAN_EID_EXT_SUPP_RATES:
1319 /*
1320 * Only process extended supported rate
1321 * if data rate is already found.
1322 * Data rate IE should come before
1323 * extended supported rate IE
1324 */
1325 if (found_data_rate_ie) {
1326 if ((element_len + rate_size) >
1327 MWIFIEX_SUPPORTED_RATES)
1328 bytes_to_copy =
1329 (MWIFIEX_SUPPORTED_RATES -
1330 rate_size);
1331 else
1332 bytes_to_copy = element_len;
1333
1334 rate = (u8 *) bss_entry->data_rates;
1335 rate += rate_size;
1336 memcpy(rate, current_ptr + 2, bytes_to_copy);
1337
1338 rate = (u8 *) bss_entry->supported_rates;
1339 rate += rate_size;
1340 memcpy(rate, current_ptr + 2, bytes_to_copy);
1341 }
1342 break;
1343
1344 case WLAN_EID_VENDOR_SPECIFIC:
1345 vendor_ie = (struct ieee_types_vendor_specific *)
1346 current_ptr;
1347
1348 if (!memcmp
1349 (vendor_ie->vend_hdr.oui, wpa_oui,
1350 sizeof(wpa_oui))) {
1351 bss_entry->bcn_wpa_ie =
1352 (struct ieee_types_vendor_specific *)
1353 current_ptr;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001354 bss_entry->wpa_offset = (u16)
1355 (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001356 } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui,
1357 sizeof(wmm_oui))) {
1358 if (total_ie_len ==
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001359 sizeof(struct ieee_types_wmm_parameter) ||
1360 total_ie_len ==
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001361 sizeof(struct ieee_types_wmm_info))
1362 /*
1363 * Only accept and copy the WMM IE if
1364 * it matches the size expected for the
1365 * WMM Info IE or the WMM Parameter IE.
1366 */
1367 memcpy((u8 *) &bss_entry->wmm_ie,
1368 current_ptr, total_ie_len);
1369 }
1370 break;
1371 case WLAN_EID_RSN:
1372 bss_entry->bcn_rsn_ie =
1373 (struct ieee_types_generic *) current_ptr;
1374 bss_entry->rsn_offset = (u16) (current_ptr -
1375 bss_entry->beacon_buf);
1376 break;
1377 case WLAN_EID_BSS_AC_ACCESS_DELAY:
1378 bss_entry->bcn_wapi_ie =
1379 (struct ieee_types_generic *) current_ptr;
1380 bss_entry->wapi_offset = (u16) (current_ptr -
1381 bss_entry->beacon_buf);
1382 break;
1383 case WLAN_EID_HT_CAPABILITY:
1384 bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
1385 (current_ptr +
1386 sizeof(struct ieee_types_header));
1387 bss_entry->ht_cap_offset = (u16) (current_ptr +
1388 sizeof(struct ieee_types_header) -
1389 bss_entry->beacon_buf);
1390 break;
Johannes Berg074d46d2012-03-15 19:45:16 +01001391 case WLAN_EID_HT_OPERATION:
1392 bss_entry->bcn_ht_oper =
1393 (struct ieee80211_ht_operation *)(current_ptr +
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001394 sizeof(struct ieee_types_header));
1395 bss_entry->ht_info_offset = (u16) (current_ptr +
1396 sizeof(struct ieee_types_header) -
1397 bss_entry->beacon_buf);
1398 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001399 case WLAN_EID_VHT_CAPABILITY:
1400 bss_entry->disable_11ac = false;
1401 bss_entry->bcn_vht_cap =
1402 (void *)(current_ptr +
1403 sizeof(struct ieee_types_header));
1404 bss_entry->vht_cap_offset =
1405 (u16)((u8 *)bss_entry->bcn_vht_cap -
1406 bss_entry->beacon_buf);
1407 break;
1408 case WLAN_EID_VHT_OPERATION:
1409 bss_entry->bcn_vht_oper =
1410 (void *)(current_ptr +
1411 sizeof(struct ieee_types_header));
1412 bss_entry->vht_info_offset =
1413 (u16)((u8 *)bss_entry->bcn_vht_oper -
1414 bss_entry->beacon_buf);
1415 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001416 case WLAN_EID_BSS_COEX_2040:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001417 bss_entry->bcn_bss_co_2040 = current_ptr;
1418 bss_entry->bss_co_2040_offset =
1419 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420 break;
1421 case WLAN_EID_EXT_CAPABILITY:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001422 bss_entry->bcn_ext_cap = current_ptr;
1423 bss_entry->ext_cap_offset =
1424 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001425 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001426 case WLAN_EID_OPMODE_NOTIF:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001427 bss_entry->oper_mode = (void *)current_ptr;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001428 bss_entry->oper_mode_offset =
1429 (u16)((u8 *)bss_entry->oper_mode -
1430 bss_entry->beacon_buf);
1431 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001432 default:
1433 break;
1434 }
1435
1436 current_ptr += element_len + 2;
1437
1438 /* Need to account for IE ID and IE Len */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001439 bytes_left -= (element_len + 2);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001440
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001441 } /* while (bytes_left > 2) */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001442 return ret;
1443}
1444
1445/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001446 * This function converts radio type scan parameter to a band configuration
1447 * to be used in join command.
1448 */
1449static u8
1450mwifiex_radio_type_to_band(u8 radio_type)
1451{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001452 switch (radio_type) {
1453 case HostCmd_SCAN_RADIO_TYPE_A:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001454 return BAND_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001455 case HostCmd_SCAN_RADIO_TYPE_BG:
1456 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001457 return BAND_G;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001458 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001459}
1460
1461/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001462 * This is an internal function used to start a scan based on an input
1463 * configuration.
1464 *
1465 * This uses the input user scan configuration information when provided in
1466 * order to send the appropriate scan commands to firmware to populate or
1467 * update the internal driver scan table.
1468 */
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001469int mwifiex_scan_networks(struct mwifiex_private *priv,
1470 const struct mwifiex_user_scan_cfg *user_scan_in)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001471{
Bing Zhaoc2476332012-10-05 20:21:40 -07001472 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001473 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001474 struct cmd_ctrl_node *cmd_node;
1475 union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001476 struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001477 struct mwifiex_chan_scan_param_set *scan_chan_list;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001478 u8 filtered_scan;
1479 u8 scan_current_chan_only;
1480 u8 max_chan_per_scan;
1481 unsigned long flags;
1482
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001483 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301484 mwifiex_dbg(adapter, WARN,
1485 "cmd: Scan already in process...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001486 return -EBUSY;
1487 }
1488
1489 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301490 mwifiex_dbg(adapter, WARN,
1491 "cmd: Scan is blocked during association...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001492 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001493 }
1494
Amitkumar Karware00483f2015-01-07 03:57:39 -08001495 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301496 mwifiex_dbg(adapter, ERROR,
1497 "Ignore scan. Card removed or firmware in bad state\n");
Amitkumar Karware00483f2015-01-07 03:57:39 -08001498 return -EFAULT;
1499 }
1500
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001501 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1502 adapter->scan_processing = true;
1503 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1504
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001505 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
Joe Perches0d2e7a52013-02-03 17:28:14 +00001506 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001507 if (!scan_cfg_out) {
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001508 ret = -ENOMEM;
1509 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001510 }
1511
Joe Perches0d2e7a52013-02-03 17:28:14 +00001512 scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
1513 sizeof(struct mwifiex_chan_scan_param_set),
1514 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001515 if (!scan_chan_list) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001516 kfree(scan_cfg_out);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001517 ret = -ENOMEM;
1518 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001519 }
1520
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001521 mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config,
1522 &chan_list_out, scan_chan_list, &max_chan_per_scan,
1523 &filtered_scan, &scan_current_chan_only);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001524
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001525 ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
1526 &scan_cfg_out->config, chan_list_out,
1527 scan_chan_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001528
1529 /* Get scan command from scan_pending_q and put to cmd_pending_q */
1530 if (!ret) {
1531 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1532 if (!list_empty(&adapter->scan_pending_q)) {
1533 cmd_node = list_first_entry(&adapter->scan_pending_q,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001534 struct cmd_ctrl_node, list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001535 list_del(&cmd_node->list);
1536 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001537 flags);
Brian Norris463df472017-07-24 18:13:29 -07001538 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node);
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001539 queue_work(adapter->workqueue, &adapter->main_work);
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001540
1541 /* Perform internal scan synchronously */
Bing Zhao21de9792013-04-01 12:44:45 -07001542 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301543 mwifiex_dbg(adapter, INFO,
1544 "wait internal scan\n");
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001545 mwifiex_wait_queue_complete(adapter, cmd_node);
Bing Zhao21de9792013-04-01 12:44:45 -07001546 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001547 } else {
1548 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1549 flags);
1550 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001551 }
1552
1553 kfree(scan_cfg_out);
1554 kfree(scan_chan_list);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001555done:
1556 if (ret) {
1557 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1558 adapter->scan_processing = false;
1559 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1560 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001561 return ret;
1562}
1563
1564/*
1565 * This function prepares a scan command to be sent to the firmware.
1566 *
1567 * This uses the scan command configuration sent to the command processing
1568 * module in command preparation stage to configure a scan command structure
1569 * to send to firmware.
1570 *
1571 * The fixed fields specifying the BSS type and BSSID filters as well as a
1572 * variable number/length of TLVs are sent in the command to firmware.
1573 *
1574 * Preparation also includes -
1575 * - Setting command ID, and proper size
1576 * - Ensuring correct endian-ness
1577 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001578int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1579 struct mwifiex_scan_cmd_config *scan_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001580{
1581 struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001582
1583 /* Set fixed field variables in scan command */
1584 scan_cmd->bss_mode = scan_cfg->bss_mode;
1585 memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
1586 sizeof(scan_cmd->bssid));
1587 memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
1588
1589 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
1590
1591 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
1592 cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
1593 + sizeof(scan_cmd->bssid)
1594 + scan_cfg->tlv_buf_len + S_DS_GEN));
1595
1596 return 0;
1597}
1598
1599/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001600 * This function checks compatibility of requested network with current
1601 * driver settings.
1602 */
1603int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1604 struct mwifiex_bssdescriptor *bss_desc)
1605{
1606 int ret = -1;
1607
1608 if (!bss_desc)
1609 return -1;
1610
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -07001611 if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
1612 (u16) bss_desc->channel, 0))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001613 switch (priv->bss_mode) {
1614 case NL80211_IFTYPE_STATION:
1615 case NL80211_IFTYPE_ADHOC:
1616 ret = mwifiex_is_network_compatible(priv, bss_desc,
1617 priv->bss_mode);
1618 if (ret)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301619 mwifiex_dbg(priv->adapter, ERROR,
1620 "Incompatible network settings\n");
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001621 break;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001622 default:
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001623 ret = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001624 }
1625 }
1626
1627 return ret;
1628}
1629
chunfan chen2375fa22015-08-05 06:09:42 -07001630/* This function checks if SSID string contains all zeroes or length is zero */
1631static bool mwifiex_is_hidden_ssid(struct cfg80211_ssid *ssid)
1632{
1633 int idx;
1634
1635 for (idx = 0; idx < ssid->ssid_len; idx++) {
1636 if (ssid->ssid[idx])
1637 return false;
1638 }
1639
1640 return true;
1641}
1642
1643/* This function checks if any hidden SSID found in passive scan channels
1644 * and save those channels for specific SSID active scan
1645 */
1646static int mwifiex_save_hidden_ssid_channels(struct mwifiex_private *priv,
1647 struct cfg80211_bss *bss)
1648{
1649 struct mwifiex_bssdescriptor *bss_desc;
1650 int ret;
1651 int chid;
1652
1653 /* Allocate and fill new bss descriptor */
1654 bss_desc = kzalloc(sizeof(*bss_desc), GFP_KERNEL);
1655 if (!bss_desc)
1656 return -ENOMEM;
1657
1658 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
1659 if (ret)
1660 goto done;
1661
1662 if (mwifiex_is_hidden_ssid(&bss_desc->ssid)) {
1663 mwifiex_dbg(priv->adapter, INFO, "found hidden SSID\n");
1664 for (chid = 0 ; chid < MWIFIEX_USER_SCAN_CHAN_MAX; chid++) {
1665 if (priv->hidden_chan[chid].chan_number ==
1666 bss->channel->hw_value)
1667 break;
1668
1669 if (!priv->hidden_chan[chid].chan_number) {
1670 priv->hidden_chan[chid].chan_number =
1671 bss->channel->hw_value;
1672 priv->hidden_chan[chid].radio_type =
1673 bss->channel->band;
1674 priv->hidden_chan[chid].scan_type =
1675 MWIFIEX_SCAN_TYPE_ACTIVE;
1676 break;
1677 }
1678 }
1679 }
1680
1681done:
Ricky Liang5ff26222016-11-09 11:37:28 +08001682 /* beacon_ie buffer was allocated in function
1683 * mwifiex_fill_new_bss_desc(). Free it now.
1684 */
1685 kfree(bss_desc->beacon_buf);
chunfan chen2375fa22015-08-05 06:09:42 -07001686 kfree(bss_desc);
1687 return 0;
1688}
1689
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001690static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1691 struct cfg80211_bss *bss)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001692{
Jesper Juhldb652e42011-11-06 22:58:31 +01001693 struct mwifiex_bssdescriptor *bss_desc;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001694 int ret;
1695 unsigned long flags;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001696
1697 /* Allocate and fill new bss descriptor */
Joe Perches0d2e7a52013-02-03 17:28:14 +00001698 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
1699 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001700 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07001701
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001702 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001703 if (ret)
1704 goto done;
1705
1706 ret = mwifiex_check_network_compatibility(priv, bss_desc);
1707 if (ret)
1708 goto done;
1709
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001710 spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001711 /* Make a copy of current BSSID descriptor */
1712 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001713 sizeof(priv->curr_bss_params.bss_descriptor));
Bing Zhaod837a2a2013-04-12 10:34:17 -07001714
1715 /* The contents of beacon_ie will be copied to its own buffer
1716 * in mwifiex_save_curr_bcn()
1717 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001718 mwifiex_save_curr_bcn(priv);
1719 spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
1720
1721done:
Bing Zhaod837a2a2013-04-12 10:34:17 -07001722 /* beacon_ie buffer was allocated in function
1723 * mwifiex_fill_new_bss_desc(). Free it now.
1724 */
1725 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001726 kfree(bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001727 return 0;
1728}
1729
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001730static int
1731mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info,
1732 u32 *bytes_left, u64 fw_tsf, u8 *radio_type,
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001733 bool ext_scan, s32 rssi_val)
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001734{
1735 struct mwifiex_adapter *adapter = priv->adapter;
1736 struct mwifiex_chan_freq_power *cfp;
1737 struct cfg80211_bss *bss;
1738 u8 bssid[ETH_ALEN];
1739 s32 rssi;
1740 const u8 *ie_buf;
1741 size_t ie_len;
1742 u16 channel = 0;
1743 u16 beacon_size = 0;
1744 u32 curr_bcn_bytes;
1745 u32 freq;
1746 u16 beacon_period;
1747 u16 cap_info_bitmap;
1748 u8 *current_ptr;
1749 u64 timestamp;
1750 struct mwifiex_fixed_bcn_param *bcn_param;
1751 struct mwifiex_bss_priv *bss_priv;
1752
1753 if (*bytes_left >= sizeof(beacon_size)) {
1754 /* Extract & convert beacon size from command buffer */
Daniel Mentz5653c642017-03-09 14:06:16 +05301755 beacon_size = get_unaligned_le16((*bss_info));
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001756 *bytes_left -= sizeof(beacon_size);
1757 *bss_info += sizeof(beacon_size);
1758 }
1759
1760 if (!beacon_size || beacon_size > *bytes_left) {
1761 *bss_info += *bytes_left;
1762 *bytes_left = 0;
1763 return -EFAULT;
1764 }
1765
1766 /* Initialize the current working beacon pointer for this BSS
1767 * iteration
1768 */
1769 current_ptr = *bss_info;
1770
1771 /* Advance the return beacon pointer past the current beacon */
1772 *bss_info += beacon_size;
1773 *bytes_left -= beacon_size;
1774
1775 curr_bcn_bytes = beacon_size;
1776
1777 /* First 5 fields are bssid, RSSI(for legacy scan only),
1778 * time stamp, beacon interval, and capability information
1779 */
1780 if (curr_bcn_bytes < ETH_ALEN + sizeof(u8) +
1781 sizeof(struct mwifiex_fixed_bcn_param)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301782 mwifiex_dbg(adapter, ERROR,
1783 "InterpretIE: not enough bytes left\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001784 return -EFAULT;
1785 }
1786
1787 memcpy(bssid, current_ptr, ETH_ALEN);
1788 current_ptr += ETH_ALEN;
1789 curr_bcn_bytes -= ETH_ALEN;
1790
1791 if (!ext_scan) {
Joe Perches45d18c52014-03-24 13:15:39 -07001792 rssi = (s32) *current_ptr;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001793 rssi = (-rssi) * 100; /* Convert dBm to mBm */
1794 current_ptr += sizeof(u8);
1795 curr_bcn_bytes -= sizeof(u8);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301796 mwifiex_dbg(adapter, INFO,
1797 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001798 } else {
1799 rssi = rssi_val;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001800 }
1801
1802 bcn_param = (struct mwifiex_fixed_bcn_param *)current_ptr;
1803 current_ptr += sizeof(*bcn_param);
1804 curr_bcn_bytes -= sizeof(*bcn_param);
1805
1806 timestamp = le64_to_cpu(bcn_param->timestamp);
1807 beacon_period = le16_to_cpu(bcn_param->beacon_period);
1808
1809 cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301810 mwifiex_dbg(adapter, INFO,
1811 "info: InterpretIE: capabilities=0x%X\n",
1812 cap_info_bitmap);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001813
1814 /* Rest of the current buffer are IE's */
1815 ie_buf = current_ptr;
1816 ie_len = curr_bcn_bytes;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301817 mwifiex_dbg(adapter, INFO,
1818 "info: InterpretIE: IELength for this AP = %d\n",
1819 curr_bcn_bytes);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001820
1821 while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) {
1822 u8 element_id, element_len;
1823
1824 element_id = *current_ptr;
1825 element_len = *(current_ptr + 1);
1826 if (curr_bcn_bytes < element_len +
1827 sizeof(struct ieee_types_header)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301828 mwifiex_dbg(adapter, ERROR,
1829 "%s: bytes left < IE length\n", __func__);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001830 return -EFAULT;
1831 }
1832 if (element_id == WLAN_EID_DS_PARAMS) {
1833 channel = *(current_ptr +
1834 sizeof(struct ieee_types_header));
1835 break;
1836 }
1837
1838 current_ptr += element_len + sizeof(struct ieee_types_header);
1839 curr_bcn_bytes -= element_len +
1840 sizeof(struct ieee_types_header);
1841 }
1842
1843 if (channel) {
1844 struct ieee80211_channel *chan;
1845 u8 band;
1846
1847 /* Skip entry if on csa closed channel */
1848 if (channel == priv->csa_chan) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301849 mwifiex_dbg(adapter, WARN,
1850 "Dropping entry on csa closed channel\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001851 return 0;
1852 }
1853
1854 band = BAND_G;
1855 if (radio_type)
1856 band = mwifiex_radio_type_to_band(*radio_type &
1857 (BIT(0) | BIT(1)));
1858
1859 cfp = mwifiex_get_cfp(priv, band, channel, 0);
1860
1861 freq = cfp ? cfp->freq : 0;
1862
Avinash Patil4facc342015-01-28 15:42:00 +05301863 chan = ieee80211_get_channel(priv->wdev.wiphy, freq);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001864
1865 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Avinash Patil4facc342015-01-28 15:42:00 +05301866 bss = cfg80211_inform_bss(priv->wdev.wiphy,
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02001867 chan, CFG80211_BSS_FTYPE_UNKNOWN,
1868 bssid, timestamp,
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001869 cap_info_bitmap, beacon_period,
1870 ie_buf, ie_len, rssi, GFP_KERNEL);
Xinming Hu02421dd32015-09-18 06:32:07 -07001871 if (bss) {
1872 bss_priv = (struct mwifiex_bss_priv *)bss->priv;
1873 bss_priv->band = band;
1874 bss_priv->fw_tsf = fw_tsf;
1875 if (priv->media_connected &&
1876 !memcmp(bssid, priv->curr_bss_params.
1877 bss_descriptor.mac_address,
1878 ETH_ALEN))
1879 mwifiex_update_curr_bss_params(priv,
1880 bss);
1881 cfg80211_put_bss(priv->wdev.wiphy, bss);
1882 }
chunfan chen2375fa22015-08-05 06:09:42 -07001883
1884 if ((chan->flags & IEEE80211_CHAN_RADAR) ||
1885 (chan->flags & IEEE80211_CHAN_NO_IR)) {
1886 mwifiex_dbg(adapter, INFO,
1887 "radar or passive channel %d\n",
1888 channel);
1889 mwifiex_save_hidden_ssid_channels(priv, bss);
1890 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001891 }
1892 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301893 mwifiex_dbg(adapter, WARN, "missing BSS channel IE\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001894 }
1895
1896 return 0;
1897}
1898
Avinash Patil21445042014-05-27 21:39:32 -07001899static void mwifiex_complete_scan(struct mwifiex_private *priv)
1900{
1901 struct mwifiex_adapter *adapter = priv->adapter;
1902
Avinash Patilbf354432014-10-31 16:08:26 +05301903 adapter->survey_idx = 0;
Avinash Patil21445042014-05-27 21:39:32 -07001904 if (adapter->curr_cmd->wait_q_enabled) {
1905 adapter->cmd_wait_q.status = 0;
1906 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301907 mwifiex_dbg(adapter, INFO,
1908 "complete internal scan\n");
Avinash Patil21445042014-05-27 21:39:32 -07001909 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1910 }
1911 }
1912}
1913
chunfan chen2375fa22015-08-05 06:09:42 -07001914/* This function checks if any hidden SSID found in passive scan channels
1915 * and do specific SSID active scan for those channels
1916 */
1917static int
1918mwifiex_active_scan_req_for_passive_chan(struct mwifiex_private *priv)
1919{
1920 int ret;
1921 struct mwifiex_adapter *adapter = priv->adapter;
1922 u8 id = 0;
1923 struct mwifiex_user_scan_cfg *user_scan_cfg;
1924
Amitkumar Karwar16d25da2016-06-27 14:16:29 +05301925 if (adapter->active_scan_triggered || !priv->scan_request ||
1926 priv->scan_aborting) {
chunfan chen2375fa22015-08-05 06:09:42 -07001927 adapter->active_scan_triggered = false;
1928 return 0;
1929 }
1930
1931 if (!priv->hidden_chan[0].chan_number) {
1932 mwifiex_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n");
1933 return 0;
1934 }
1935 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1936
1937 if (!user_scan_cfg)
1938 return -ENOMEM;
1939
chunfan chen2375fa22015-08-05 06:09:42 -07001940 for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) {
1941 if (!priv->hidden_chan[id].chan_number)
1942 break;
1943 memcpy(&user_scan_cfg->chan_list[id],
1944 &priv->hidden_chan[id],
1945 sizeof(struct mwifiex_user_scan_chan));
1946 }
1947
1948 adapter->active_scan_triggered = true;
Ganapathi Bhat89001c12017-08-10 18:11:26 +05301949 if (priv->scan_request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
Ganapathi Bhate251a882017-09-18 12:25:02 +05301950 ether_addr_copy(user_scan_cfg->random_mac,
1951 priv->scan_request->mac_addr);
chunfan chen2375fa22015-08-05 06:09:42 -07001952 user_scan_cfg->num_ssids = priv->scan_request->n_ssids;
1953 user_scan_cfg->ssid_list = priv->scan_request->ssids;
1954
1955 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1956 kfree(user_scan_cfg);
1957
1958 memset(&priv->hidden_chan, 0, sizeof(priv->hidden_chan));
1959
1960 if (ret) {
1961 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1962 return ret;
1963 }
1964
1965 return 0;
1966}
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001967static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1968{
1969 struct mwifiex_adapter *adapter = priv->adapter;
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +01001970 struct cmd_ctrl_node *cmd_node;
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001971 unsigned long flags;
1972
1973 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1974 if (list_empty(&adapter->scan_pending_q)) {
1975 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +01001976
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001977 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1978 adapter->scan_processing = false;
1979 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1980
chunfan chen2375fa22015-08-05 06:09:42 -07001981 mwifiex_active_scan_req_for_passive_chan(priv);
1982
Avinash Patil21445042014-05-27 21:39:32 -07001983 if (!adapter->ext_scan)
1984 mwifiex_complete_scan(priv);
1985
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001986 if (priv->scan_request) {
Avraham Stern1d762502016-07-05 17:10:13 +03001987 struct cfg80211_scan_info info = {
1988 .aborted = false,
1989 };
1990
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301991 mwifiex_dbg(adapter, INFO,
1992 "info: notifying scan done\n");
Avraham Stern1d762502016-07-05 17:10:13 +03001993 cfg80211_scan_done(priv->scan_request, &info);
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001994 priv->scan_request = NULL;
Amitkumar Karwar09e672a2016-06-27 14:16:28 +05301995 priv->scan_aborting = false;
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001996 } else {
1997 priv->scan_aborting = false;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301998 mwifiex_dbg(adapter, INFO,
1999 "info: scan already aborted\n");
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002000 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05302001 } else if ((priv->scan_aborting && !priv->scan_request) ||
2002 priv->scan_block) {
Amitkumar Karward8d91252014-09-12 20:08:58 +05302003 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2004
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +01002005 mwifiex_cancel_pending_scan_cmd(adapter);
2006
Amitkumar Karward8d91252014-09-12 20:08:58 +05302007 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
2008 adapter->scan_processing = false;
2009 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
2010
chunfan chen2375fa22015-08-05 06:09:42 -07002011 if (!adapter->active_scan_triggered) {
2012 if (priv->scan_request) {
Avraham Stern1d762502016-07-05 17:10:13 +03002013 struct cfg80211_scan_info info = {
2014 .aborted = true,
2015 };
2016
chunfan chen2375fa22015-08-05 06:09:42 -07002017 mwifiex_dbg(adapter, INFO,
2018 "info: aborting scan\n");
Avraham Stern1d762502016-07-05 17:10:13 +03002019 cfg80211_scan_done(priv->scan_request, &info);
chunfan chen2375fa22015-08-05 06:09:42 -07002020 priv->scan_request = NULL;
Amitkumar Karwar09e672a2016-06-27 14:16:28 +05302021 priv->scan_aborting = false;
chunfan chen2375fa22015-08-05 06:09:42 -07002022 } else {
2023 priv->scan_aborting = false;
2024 mwifiex_dbg(adapter, INFO,
2025 "info: scan already aborted\n");
2026 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05302027 }
2028 } else {
2029 /* Get scan command from scan_pending_q and put to
2030 * cmd_pending_q
2031 */
2032 cmd_node = list_first_entry(&adapter->scan_pending_q,
2033 struct cmd_ctrl_node, list);
2034 list_del(&cmd_node->list);
2035 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
Brian Norris463df472017-07-24 18:13:29 -07002036 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node);
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002037 }
2038
2039 return;
2040}
2041
Xinming Hua9c790b2016-06-16 18:52:22 +05302042void mwifiex_cancel_scan(struct mwifiex_adapter *adapter)
2043{
2044 struct mwifiex_private *priv;
2045 unsigned long cmd_flags;
2046 int i;
2047
2048 mwifiex_cancel_pending_scan_cmd(adapter);
2049
2050 if (adapter->scan_processing) {
2051 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
2052 adapter->scan_processing = false;
2053 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
2054 for (i = 0; i < adapter->priv_num; i++) {
2055 priv = adapter->priv[i];
2056 if (!priv)
2057 continue;
2058 if (priv->scan_request) {
David S. Miller88b3ec52016-07-14 16:27:42 -07002059 struct cfg80211_scan_info info = {
2060 .aborted = true,
2061 };
2062
Xinming Hua9c790b2016-06-16 18:52:22 +05302063 mwifiex_dbg(adapter, INFO,
2064 "info: aborting scan\n");
David S. Miller88b3ec52016-07-14 16:27:42 -07002065 cfg80211_scan_done(priv->scan_request, &info);
Xinming Hua9c790b2016-06-16 18:52:22 +05302066 priv->scan_request = NULL;
Amitkumar Karwar09e672a2016-06-27 14:16:28 +05302067 priv->scan_aborting = false;
Xinming Hua9c790b2016-06-16 18:52:22 +05302068 }
2069 }
2070 }
2071}
2072
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002073/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002074 * This function handles the command response of scan.
2075 *
2076 * The response buffer for the scan command has the following
2077 * memory layout:
2078 *
2079 * .-------------------------------------------------------------.
2080 * | Header (4 * sizeof(t_u16)): Standard command response hdr |
2081 * .-------------------------------------------------------------.
2082 * | BufSize (t_u16) : sizeof the BSS Description data |
2083 * .-------------------------------------------------------------.
2084 * | NumOfSet (t_u8) : Number of BSS Descs returned |
2085 * .-------------------------------------------------------------.
2086 * | BSSDescription data (variable, size given in BufSize) |
2087 * .-------------------------------------------------------------.
2088 * | TLV data (variable, size calculated using Header->Size, |
2089 * | BufSize and sizeof the fixed fields above) |
2090 * .-------------------------------------------------------------.
2091 */
2092int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002093 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002094{
2095 int ret = 0;
2096 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002097 struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002098 struct mwifiex_ie_types_data *tlv_data;
2099 struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
2100 u8 *bss_info;
2101 u32 scan_resp_size;
2102 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002103 u32 idx;
2104 u32 tlv_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002105 struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
2106 struct chan_band_param_set *chan_band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002107 u8 is_bgscan_resp;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002108 __le64 fw_tsf = 0;
2109 u8 *radio_type;
chunfan chen7d7f07d2016-01-13 01:26:54 -08002110 struct cfg80211_wowlan_nd_match *pmatch;
2111 struct cfg80211_sched_scan_request *nd_config = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002112
2113 is_bgscan_resp = (le16_to_cpu(resp->command)
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002114 == HostCmd_CMD_802_11_BG_SCAN_QUERY);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002115 if (is_bgscan_resp)
2116 scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
2117 else
2118 scan_rsp = &resp->params.scan_resp;
2119
2120
Bing Zhao67a50032011-07-13 18:38:34 -07002121 if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302122 mwifiex_dbg(adapter, ERROR,
2123 "SCAN_RESP: too many AP returned (%d)\n",
2124 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002125 ret = -1;
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002126 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002127 }
2128
Amitkumar Karwarb8876642013-06-18 16:36:58 -07002129 /* Check csa channel expiry before parsing scan response */
2130 mwifiex_11h_get_csa_closed_channel(priv);
2131
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002132 bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302133 mwifiex_dbg(adapter, INFO,
2134 "info: SCAN_RESP: bss_descript_size %d\n",
2135 bytes_left);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002136
2137 scan_resp_size = le16_to_cpu(resp->size);
2138
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302139 mwifiex_dbg(adapter, INFO,
2140 "info: SCAN_RESP: returned %d APs before parsing\n",
2141 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002142
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002143 bss_info = scan_rsp->bss_desc_and_tlv_buffer;
2144
2145 /*
2146 * The size of the TLV buffer is equal to the entire command response
2147 * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
2148 * BSS Descriptions (bss_descript_size as bytesLef) and the command
2149 * response header (S_DS_GEN)
2150 */
2151 tlv_buf_size = scan_resp_size - (bytes_left
2152 + sizeof(scan_rsp->bss_descript_size)
2153 + sizeof(scan_rsp->number_of_sets)
2154 + S_DS_GEN);
2155
2156 tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
2157 bss_desc_and_tlv_buffer +
2158 bytes_left);
2159
2160 /* Search the TLV buffer space in the scan response for any valid
2161 TLVs */
2162 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2163 TLV_TYPE_TSFTIMESTAMP,
2164 (struct mwifiex_ie_types_data **)
2165 &tsf_tlv);
2166
2167 /* Search the TLV buffer space in the scan response for any valid
2168 TLVs */
2169 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2170 TLV_TYPE_CHANNELBANDLIST,
2171 (struct mwifiex_ie_types_data **)
2172 &chan_band_tlv);
2173
chunfan chen7d7f07d2016-01-13 01:26:54 -08002174#ifdef CONFIG_PM
2175 if (priv->wdev.wiphy->wowlan_config)
2176 nd_config = priv->wdev.wiphy->wowlan_config->nd_config;
2177#endif
2178
2179 if (nd_config) {
2180 adapter->nd_info =
2181 kzalloc(sizeof(struct cfg80211_wowlan_nd_match) +
2182 sizeof(struct cfg80211_wowlan_nd_match *) *
2183 scan_rsp->number_of_sets, GFP_ATOMIC);
2184
2185 if (adapter->nd_info)
2186 adapter->nd_info->n_matches = scan_rsp->number_of_sets;
2187 }
2188
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002189 for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002190 /*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002191 * If the TSF TLV was appended to the scan results, save this
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002192 * entry's TSF value in the fw_tsf field. It is the firmware's
2193 * TSF value at the time the beacon or probe response was
2194 * received.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002195 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002196 if (tsf_tlv)
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002197 memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
2198 sizeof(fw_tsf));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002199
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002200 if (chan_band_tlv) {
2201 chan_band = &chan_band_tlv->chan_band_param[idx];
2202 radio_type = &chan_band->radio_type;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002203 } else {
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002204 radio_type = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002205 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002206
chunfan chen7d7f07d2016-01-13 01:26:54 -08002207 if (chan_band_tlv && adapter->nd_info) {
2208 adapter->nd_info->matches[idx] =
Christophe Jailletb7116572016-08-31 13:50:59 +02002209 kzalloc(sizeof(*pmatch) + sizeof(u32),
2210 GFP_ATOMIC);
chunfan chen7d7f07d2016-01-13 01:26:54 -08002211
2212 pmatch = adapter->nd_info->matches[idx];
2213
Dan Carpenterefdf0e32016-02-02 13:00:05 +03002214 if (pmatch) {
Christophe Jailletb7116572016-08-31 13:50:59 +02002215 pmatch->n_channels = 1;
2216 pmatch->channels[0] = chan_band->chan_number;
chunfan chen7d7f07d2016-01-13 01:26:54 -08002217 }
2218 }
2219
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002220 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2221 &bytes_left,
2222 le64_to_cpu(fw_tsf),
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002223 radio_type, false, 0);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002224 if (ret)
2225 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002226 }
2227
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002228check_next_scan:
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002229 mwifiex_check_next_scan_command(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002230 return ret;
2231}
2232
2233/*
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002234 * This function prepares an extended scan command to be sent to the firmware
2235 *
2236 * This uses the scan command configuration sent to the command processing
2237 * module in command preparation stage to configure a extended scan command
2238 * structure to send to firmware.
2239 */
2240int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
2241 struct host_cmd_ds_command *cmd,
2242 void *data_buf)
2243{
2244 struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan;
2245 struct mwifiex_scan_cmd_config *scan_cfg = data_buf;
2246
2247 memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
2248
2249 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT);
2250
2251 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
2252 cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved)
2253 + scan_cfg->tlv_buf_len + S_DS_GEN));
2254
2255 return 0;
2256}
2257
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002258/* This function prepares an background scan config command to be sent
2259 * to the firmware
2260 */
2261int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv,
2262 struct host_cmd_ds_command *cmd,
2263 void *data_buf)
2264{
2265 struct host_cmd_ds_802_11_bg_scan_config *bgscan_config =
2266 &cmd->params.bg_scan_config;
2267 struct mwifiex_bg_scan_cfg *bgscan_cfg_in = data_buf;
2268 u8 *tlv_pos = bgscan_config->tlv;
2269 u8 num_probes;
2270 u32 ssid_len, chan_idx, scan_type, scan_dur, chan_num;
2271 int i;
2272 struct mwifiex_ie_types_num_probes *num_probes_tlv;
2273 struct mwifiex_ie_types_repeat_count *repeat_count_tlv;
Ganapathi Bhatfdcab082016-01-13 01:26:56 -08002274 struct mwifiex_ie_types_min_rssi_threshold *rssi_threshold_tlv;
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002275 struct mwifiex_ie_types_bgscan_start_later *start_later_tlv;
2276 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
2277 struct mwifiex_ie_types_chan_list_param_set *chan_list_tlv;
2278 struct mwifiex_chan_scan_param_set *temp_chan;
2279
2280 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_CONFIG);
2281 cmd->size = cpu_to_le16(sizeof(*bgscan_config) + S_DS_GEN);
2282
2283 bgscan_config->action = cpu_to_le16(bgscan_cfg_in->action);
2284 bgscan_config->enable = bgscan_cfg_in->enable;
2285 bgscan_config->bss_type = bgscan_cfg_in->bss_type;
2286 bgscan_config->scan_interval =
2287 cpu_to_le32(bgscan_cfg_in->scan_interval);
2288 bgscan_config->report_condition =
2289 cpu_to_le32(bgscan_cfg_in->report_condition);
2290
2291 /* stop sched scan */
2292 if (!bgscan_config->enable)
2293 return 0;
2294
2295 bgscan_config->chan_per_scan = bgscan_cfg_in->chan_per_scan;
2296
2297 num_probes = (bgscan_cfg_in->num_probes ? bgscan_cfg_in->
2298 num_probes : priv->adapter->scan_probes);
2299
2300 if (num_probes) {
2301 num_probes_tlv = (struct mwifiex_ie_types_num_probes *)tlv_pos;
2302 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
2303 num_probes_tlv->header.len =
2304 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
2305 num_probes_tlv->num_probes = cpu_to_le16((u16)num_probes);
2306
2307 tlv_pos += sizeof(num_probes_tlv->header) +
2308 le16_to_cpu(num_probes_tlv->header.len);
2309 }
2310
2311 if (bgscan_cfg_in->repeat_count) {
2312 repeat_count_tlv =
2313 (struct mwifiex_ie_types_repeat_count *)tlv_pos;
2314 repeat_count_tlv->header.type =
2315 cpu_to_le16(TLV_TYPE_REPEAT_COUNT);
2316 repeat_count_tlv->header.len =
2317 cpu_to_le16(sizeof(repeat_count_tlv->repeat_count));
2318 repeat_count_tlv->repeat_count =
2319 cpu_to_le16(bgscan_cfg_in->repeat_count);
2320
2321 tlv_pos += sizeof(repeat_count_tlv->header) +
2322 le16_to_cpu(repeat_count_tlv->header.len);
2323 }
2324
Ganapathi Bhatfdcab082016-01-13 01:26:56 -08002325 if (bgscan_cfg_in->rssi_threshold) {
2326 rssi_threshold_tlv =
2327 (struct mwifiex_ie_types_min_rssi_threshold *)tlv_pos;
2328 rssi_threshold_tlv->header.type =
2329 cpu_to_le16(TLV_TYPE_RSSI_LOW);
2330 rssi_threshold_tlv->header.len =
2331 cpu_to_le16(sizeof(rssi_threshold_tlv->rssi_threshold));
2332 rssi_threshold_tlv->rssi_threshold =
2333 cpu_to_le16(bgscan_cfg_in->rssi_threshold);
2334
2335 tlv_pos += sizeof(rssi_threshold_tlv->header) +
2336 le16_to_cpu(rssi_threshold_tlv->header.len);
2337 }
2338
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002339 for (i = 0; i < bgscan_cfg_in->num_ssids; i++) {
2340 ssid_len = bgscan_cfg_in->ssid_list[i].ssid.ssid_len;
2341
2342 wildcard_ssid_tlv =
2343 (struct mwifiex_ie_types_wildcard_ssid_params *)tlv_pos;
2344 wildcard_ssid_tlv->header.type =
2345 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
2346 wildcard_ssid_tlv->header.len = cpu_to_le16(
2347 (u16)(ssid_len + sizeof(wildcard_ssid_tlv->
2348 max_ssid_length)));
2349
2350 /* max_ssid_length = 0 tells firmware to perform
2351 * specific scan for the SSID filled, whereas
2352 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
2353 * wildcard scan.
2354 */
2355 if (ssid_len)
2356 wildcard_ssid_tlv->max_ssid_length = 0;
2357 else
2358 wildcard_ssid_tlv->max_ssid_length =
2359 IEEE80211_MAX_SSID_LEN;
2360
2361 memcpy(wildcard_ssid_tlv->ssid,
2362 bgscan_cfg_in->ssid_list[i].ssid.ssid, ssid_len);
2363
2364 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
2365 + le16_to_cpu(wildcard_ssid_tlv->header.len));
2366 }
2367
2368 chan_list_tlv = (struct mwifiex_ie_types_chan_list_param_set *)tlv_pos;
2369
2370 if (bgscan_cfg_in->chan_list[0].chan_number) {
2371 dev_dbg(priv->adapter->dev, "info: bgscan: Using supplied channel list\n");
2372
2373 chan_list_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
2374
2375 for (chan_idx = 0;
2376 chan_idx < MWIFIEX_BG_SCAN_CHAN_MAX &&
2377 bgscan_cfg_in->chan_list[chan_idx].chan_number;
2378 chan_idx++) {
2379 temp_chan = chan_list_tlv->chan_scan_param + chan_idx;
2380
2381 /* Increment the TLV header length by size appended */
Daniel Mentz5653c642017-03-09 14:06:16 +05302382 le16_unaligned_add_cpu(&chan_list_tlv->header.len,
2383 sizeof(
2384 chan_list_tlv->chan_scan_param));
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002385
2386 temp_chan->chan_number =
2387 bgscan_cfg_in->chan_list[chan_idx].chan_number;
2388 temp_chan->radio_type =
2389 bgscan_cfg_in->chan_list[chan_idx].radio_type;
2390
2391 scan_type =
2392 bgscan_cfg_in->chan_list[chan_idx].scan_type;
2393
2394 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
2395 temp_chan->chan_scan_mode_bitmap
2396 |= MWIFIEX_PASSIVE_SCAN;
2397 else
2398 temp_chan->chan_scan_mode_bitmap
2399 &= ~MWIFIEX_PASSIVE_SCAN;
2400
2401 if (bgscan_cfg_in->chan_list[chan_idx].scan_time) {
2402 scan_dur = (u16)bgscan_cfg_in->
2403 chan_list[chan_idx].scan_time;
2404 } else {
2405 scan_dur = (scan_type ==
2406 MWIFIEX_SCAN_TYPE_PASSIVE) ?
2407 priv->adapter->passive_scan_time :
2408 priv->adapter->specific_scan_time;
2409 }
2410
2411 temp_chan->min_scan_time = cpu_to_le16(scan_dur);
2412 temp_chan->max_scan_time = cpu_to_le16(scan_dur);
2413 }
2414 } else {
2415 dev_dbg(priv->adapter->dev,
2416 "info: bgscan: Creating full region channel list\n");
2417 chan_num =
2418 mwifiex_bgscan_create_channel_list(priv, bgscan_cfg_in,
2419 chan_list_tlv->
2420 chan_scan_param);
Daniel Mentz5653c642017-03-09 14:06:16 +05302421 le16_unaligned_add_cpu(&chan_list_tlv->header.len,
2422 chan_num *
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002423 sizeof(chan_list_tlv->chan_scan_param[0]));
2424 }
2425
2426 tlv_pos += (sizeof(chan_list_tlv->header)
2427 + le16_to_cpu(chan_list_tlv->header.len));
2428
2429 if (bgscan_cfg_in->start_later) {
2430 start_later_tlv =
2431 (struct mwifiex_ie_types_bgscan_start_later *)tlv_pos;
2432 start_later_tlv->header.type =
2433 cpu_to_le16(TLV_TYPE_BGSCAN_START_LATER);
2434 start_later_tlv->header.len =
2435 cpu_to_le16(sizeof(start_later_tlv->start_later));
2436 start_later_tlv->start_later =
2437 cpu_to_le16(bgscan_cfg_in->start_later);
2438
2439 tlv_pos += sizeof(start_later_tlv->header) +
2440 le16_to_cpu(start_later_tlv->header.len);
2441 }
2442
2443 /* Append vendor specific IE TLV */
2444 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_BGSCAN, &tlv_pos);
2445
Daniel Mentz5653c642017-03-09 14:06:16 +05302446 le16_unaligned_add_cpu(&cmd->size, tlv_pos - bgscan_config->tlv);
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002447
2448 return 0;
2449}
2450
2451int mwifiex_stop_bg_scan(struct mwifiex_private *priv)
2452{
2453 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2454
2455 if (!priv->sched_scanning) {
2456 dev_dbg(priv->adapter->dev, "bgscan already stopped!\n");
2457 return 0;
2458 }
2459
2460 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2461 if (!bgscan_cfg)
2462 return -ENOMEM;
2463
2464 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2465 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2466 bgscan_cfg->enable = false;
2467
2468 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2469 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2470 kfree(bgscan_cfg);
2471 return -EFAULT;
2472 }
2473
2474 kfree(bgscan_cfg);
2475 priv->sched_scanning = false;
2476
2477 return 0;
2478}
2479
Avinash Patilbf354432014-10-31 16:08:26 +05302480static void
2481mwifiex_update_chan_statistics(struct mwifiex_private *priv,
2482 struct mwifiex_ietypes_chanstats *tlv_stat)
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002483{
Avinash Patil3223db22014-09-12 20:08:48 +05302484 struct mwifiex_adapter *adapter = priv->adapter;
Avinash Patilbf354432014-10-31 16:08:26 +05302485 u8 i, num_chan;
2486 struct mwifiex_fw_chan_stats *fw_chan_stats;
2487 struct mwifiex_chan_stats chan_stats;
2488
2489 fw_chan_stats = (void *)((u8 *)tlv_stat +
2490 sizeof(struct mwifiex_ie_types_header));
2491 num_chan = le16_to_cpu(tlv_stat->header.len) /
2492 sizeof(struct mwifiex_chan_stats);
2493
2494 for (i = 0 ; i < num_chan; i++) {
Brian Norris4b5dde22017-06-29 18:23:54 -07002495 if (adapter->survey_idx >= adapter->num_in_chan_stats) {
2496 mwifiex_dbg(adapter, WARN,
2497 "FW reported too many channel results (max %d)\n",
2498 adapter->num_in_chan_stats);
2499 return;
2500 }
Avinash Patilbf354432014-10-31 16:08:26 +05302501 chan_stats.chan_num = fw_chan_stats->chan_num;
2502 chan_stats.bandcfg = fw_chan_stats->bandcfg;
2503 chan_stats.flags = fw_chan_stats->flags;
2504 chan_stats.noise = fw_chan_stats->noise;
2505 chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss);
2506 chan_stats.cca_scan_dur =
2507 le16_to_cpu(fw_chan_stats->cca_scan_dur);
2508 chan_stats.cca_busy_dur =
2509 le16_to_cpu(fw_chan_stats->cca_busy_dur);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302510 mwifiex_dbg(adapter, INFO,
2511 "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n",
2512 chan_stats.chan_num,
2513 chan_stats.noise,
2514 chan_stats.total_bss,
2515 chan_stats.cca_scan_dur,
2516 chan_stats.cca_busy_dur);
Avinash Patilbf354432014-10-31 16:08:26 +05302517 memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats,
2518 sizeof(struct mwifiex_chan_stats));
2519 fw_chan_stats++;
2520 }
2521}
2522
2523/* This function handles the command response of extended scan */
2524int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
2525 struct host_cmd_ds_command *resp)
2526{
2527 struct mwifiex_adapter *adapter = priv->adapter;
2528 struct host_cmd_ds_802_11_scan_ext *ext_scan_resp;
2529 struct mwifiex_ie_types_header *tlv;
2530 struct mwifiex_ietypes_chanstats *tlv_stat;
2531 u16 buf_left, type, len;
2532
Avinash Patil3223db22014-09-12 20:08:48 +05302533 struct host_cmd_ds_command *cmd_ptr;
2534 struct cmd_ctrl_node *cmd_node;
2535 unsigned long cmd_flags, scan_flags;
2536 bool complete_scan = false;
2537
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302538 mwifiex_dbg(adapter, INFO, "info: EXT scan returns successfully\n");
Avinash Patil21445042014-05-27 21:39:32 -07002539
Avinash Patilbf354432014-10-31 16:08:26 +05302540 ext_scan_resp = &resp->params.ext_scan;
2541
2542 tlv = (void *)ext_scan_resp->tlv_buffer;
2543 buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN
2544 - 1);
2545
2546 while (buf_left >= sizeof(struct mwifiex_ie_types_header)) {
2547 type = le16_to_cpu(tlv->type);
2548 len = le16_to_cpu(tlv->len);
2549
2550 if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302551 mwifiex_dbg(adapter, ERROR,
2552 "error processing scan response TLVs");
Avinash Patilbf354432014-10-31 16:08:26 +05302553 break;
2554 }
2555
2556 switch (type) {
2557 case TLV_TYPE_CHANNEL_STATS:
2558 tlv_stat = (void *)tlv;
2559 mwifiex_update_chan_statistics(priv, tlv_stat);
2560 break;
2561 default:
2562 break;
2563 }
2564
2565 buf_left -= len + sizeof(struct mwifiex_ie_types_header);
2566 tlv = (void *)((u8 *)tlv + len +
2567 sizeof(struct mwifiex_ie_types_header));
2568 }
2569
Avinash Patil3223db22014-09-12 20:08:48 +05302570 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
2571 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
2572 if (list_empty(&adapter->scan_pending_q)) {
2573 complete_scan = true;
2574 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
2575 cmd_ptr = (void *)cmd_node->cmd_skb->data;
2576 if (le16_to_cpu(cmd_ptr->command) ==
2577 HostCmd_CMD_802_11_SCAN_EXT) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302578 mwifiex_dbg(adapter, INFO,
2579 "Scan pending in command pending list");
Avinash Patil3223db22014-09-12 20:08:48 +05302580 complete_scan = false;
2581 break;
2582 }
2583 }
2584 }
2585 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags);
2586 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags);
2587
2588 if (complete_scan)
2589 mwifiex_complete_scan(priv);
Avinash Patil21445042014-05-27 21:39:32 -07002590
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002591 return 0;
2592}
2593
2594/* This function This function handles the event extended scan report. It
2595 * parses extended scan results and informs to cfg80211 stack.
2596 */
2597int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
2598 void *buf)
2599{
2600 int ret = 0;
2601 struct mwifiex_adapter *adapter = priv->adapter;
2602 u8 *bss_info;
2603 u32 bytes_left, bytes_left_for_tlv, idx;
2604 u16 type, len;
2605 struct mwifiex_ie_types_data *tlv;
2606 struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv;
2607 struct mwifiex_ie_types_bss_scan_info *scan_info_tlv;
2608 u8 *radio_type;
2609 u64 fw_tsf = 0;
2610 s32 rssi = 0;
2611 struct mwifiex_event_scan_result *event_scan = buf;
2612 u8 num_of_set = event_scan->num_of_set;
2613 u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
2614 u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
2615
2616 if (num_of_set > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302617 mwifiex_dbg(adapter, ERROR,
2618 "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
2619 num_of_set);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002620 ret = -1;
2621 goto check_next_scan;
2622 }
2623
2624 bytes_left = scan_resp_size;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302625 mwifiex_dbg(adapter, INFO,
2626 "EXT_SCAN: size %d, returned %d APs...",
2627 scan_resp_size, num_of_set);
Zhaoyang Liu868093a2015-05-12 00:48:19 +05302628 mwifiex_dbg_dump(adapter, CMD_D, "EXT_SCAN buffer:", buf,
2629 scan_resp_size +
2630 sizeof(struct mwifiex_event_scan_result));
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002631
2632 tlv = (struct mwifiex_ie_types_data *)scan_resp;
2633
2634 for (idx = 0; idx < num_of_set && bytes_left; idx++) {
2635 type = le16_to_cpu(tlv->header.type);
2636 len = le16_to_cpu(tlv->header.len);
2637 if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302638 mwifiex_dbg(adapter, ERROR,
2639 "EXT_SCAN: Error bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002640 break;
2641 }
2642 scan_rsp_tlv = NULL;
2643 scan_info_tlv = NULL;
2644 bytes_left_for_tlv = bytes_left;
2645
2646 /* BSS response TLV with beacon or probe response buffer
2647 * at the initial position of each descriptor
2648 */
2649 if (type != TLV_TYPE_BSS_SCAN_RSP)
2650 break;
2651
2652 bss_info = (u8 *)tlv;
2653 scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv;
2654 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2655 bytes_left_for_tlv -=
2656 (len + sizeof(struct mwifiex_ie_types_header));
2657
2658 while (bytes_left_for_tlv >=
2659 sizeof(struct mwifiex_ie_types_header) &&
2660 le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) {
2661 type = le16_to_cpu(tlv->header.type);
2662 len = le16_to_cpu(tlv->header.len);
2663 if (bytes_left_for_tlv <
2664 sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302665 mwifiex_dbg(adapter, ERROR,
2666 "EXT_SCAN: Error in processing TLV,\t"
2667 "bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002668 scan_rsp_tlv = NULL;
2669 bytes_left_for_tlv = 0;
2670 continue;
2671 }
2672 switch (type) {
2673 case TLV_TYPE_BSS_SCAN_INFO:
2674 scan_info_tlv =
2675 (struct mwifiex_ie_types_bss_scan_info *)tlv;
2676 if (len !=
2677 sizeof(struct mwifiex_ie_types_bss_scan_info) -
2678 sizeof(struct mwifiex_ie_types_header)) {
2679 bytes_left_for_tlv = 0;
2680 continue;
2681 }
2682 break;
2683 default:
2684 break;
2685 }
2686 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2687 bytes_left -=
2688 (len + sizeof(struct mwifiex_ie_types_header));
2689 bytes_left_for_tlv -=
2690 (len + sizeof(struct mwifiex_ie_types_header));
2691 }
2692
2693 if (!scan_rsp_tlv)
2694 break;
2695
2696 /* Advance pointer to the beacon buffer length and
2697 * update the bytes count so that the function
2698 * wlan_interpret_bss_desc_with_ie() can handle the
2699 * scan buffer withut any change
2700 */
2701 bss_info += sizeof(u16);
2702 bytes_left -= sizeof(u16);
2703
2704 if (scan_info_tlv) {
2705 rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi));
2706 rssi *= 100; /* Convert dBm to mBm */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302707 mwifiex_dbg(adapter, INFO,
2708 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002709 fw_tsf = le64_to_cpu(scan_info_tlv->tsf);
2710 radio_type = &scan_info_tlv->radio_type;
2711 } else {
2712 radio_type = NULL;
2713 }
2714 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2715 &bytes_left, fw_tsf,
2716 radio_type, true, rssi);
2717 if (ret)
2718 goto check_next_scan;
2719 }
2720
2721check_next_scan:
2722 if (!event_scan->more_event)
2723 mwifiex_check_next_scan_command(priv);
2724
2725 return ret;
2726}
2727
2728/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002729 * This function prepares command for background scan query.
2730 *
2731 * Preparation includes -
2732 * - Setting command ID and proper size
2733 * - Setting background scan flush parameter
2734 * - Ensuring correct endian-ness
2735 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002736int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002737{
2738 struct host_cmd_ds_802_11_bg_scan_query *bg_query =
2739 &cmd->params.bg_scan_query;
2740
2741 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
2742 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
2743 + S_DS_GEN);
2744
2745 bg_query->flush = 1;
2746
2747 return 0;
2748}
2749
2750/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002751 * This function inserts scan command node to the scan pending queue.
2752 */
2753void
2754mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
2755 struct cmd_ctrl_node *cmd_node)
2756{
2757 struct mwifiex_adapter *adapter = priv->adapter;
2758 unsigned long flags;
2759
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002760 cmd_node->wait_q_enabled = true;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002761 cmd_node->condition = &adapter->scan_wait_q_woken;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002762 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
2763 list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
2764 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2765}
2766
2767/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002768 * This function sends a scan command for all available channels to the
2769 * firmware, filtered on a specific SSID.
2770 */
2771static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002772 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002773{
2774 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhaodcd5c792012-10-19 19:01:59 -07002775 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002776 struct mwifiex_user_scan_cfg *scan_cfg;
2777
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002778 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302779 mwifiex_dbg(adapter, WARN,
2780 "cmd: Scan already in process...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002781 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002782 }
2783
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002784 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302785 mwifiex_dbg(adapter, WARN,
2786 "cmd: Scan is blocked during association...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002787 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002788 }
2789
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002790 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002791 if (!scan_cfg)
Christoph Fritzb53575e2011-05-08 22:50:09 +02002792 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002793
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08002794 scan_cfg->ssid_list = req_ssid;
2795 scan_cfg->num_ssids = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002796
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002797 ret = mwifiex_scan_networks(priv, scan_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002798
2799 kfree(scan_cfg);
2800 return ret;
2801}
2802
2803/*
2804 * Sends IOCTL request to start a scan.
2805 *
2806 * This function allocates the IOCTL request buffer, fills it
2807 * with requisite parameters and calls the IOCTL handler.
2808 *
2809 * Scan command can be issued for both normal scan and specific SSID
2810 * scan, depending upon whether an SSID is provided or not.
2811 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002812int mwifiex_request_scan(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002813 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002814{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002815 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002816
Binoy Jayan1abf9ae2017-06-08 15:33:03 +05302817 if (mutex_lock_interruptible(&priv->async_mutex)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302818 mwifiex_dbg(priv->adapter, ERROR,
2819 "%s: acquire semaphore fail\n",
2820 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002821 return -1;
2822 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002823
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002824 priv->adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002825
2826 if (req_ssid && req_ssid->ssid_len != 0)
2827 /* Specific SSID scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002828 ret = mwifiex_scan_specific_ssid(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002829 else
2830 /* Normal scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002831 ret = mwifiex_scan_networks(priv, NULL);
2832
Binoy Jayan1abf9ae2017-06-08 15:33:03 +05302833 mutex_unlock(&priv->async_mutex);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002834
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002835 return ret;
2836}
2837
2838/*
2839 * This function appends the vendor specific IE TLV to a buffer.
2840 */
2841int
2842mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
2843 u16 vsie_mask, u8 **buffer)
2844{
2845 int id, ret_len = 0;
2846 struct mwifiex_ie_types_vendor_param_set *vs_param_set;
2847
2848 if (!buffer)
2849 return 0;
2850 if (!(*buffer))
2851 return 0;
2852
2853 /*
2854 * Traverse through the saved vendor specific IE array and append
2855 * the selected(scan/assoc/adhoc) IE as TLV to the command
2856 */
2857 for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
2858 if (priv->vs_ie[id].mask & vsie_mask) {
2859 vs_param_set =
2860 (struct mwifiex_ie_types_vendor_param_set *)
2861 *buffer;
2862 vs_param_set->header.type =
2863 cpu_to_le16(TLV_TYPE_PASSTHROUGH);
2864 vs_param_set->header.len =
2865 cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
2866 & 0x00FF) + 2);
2867 memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
2868 le16_to_cpu(vs_param_set->header.len));
2869 *buffer += le16_to_cpu(vs_param_set->header.len) +
2870 sizeof(struct mwifiex_ie_types_header);
2871 ret_len += le16_to_cpu(vs_param_set->header.len) +
2872 sizeof(struct mwifiex_ie_types_header);
2873 }
2874 }
2875 return ret_len;
2876}
2877
2878/*
2879 * This function saves a beacon buffer of the current BSS descriptor.
2880 *
2881 * The current beacon buffer is saved so that it can be restored in the
2882 * following cases that makes the beacon buffer not to contain the current
2883 * ssid's beacon buffer.
2884 * - The current ssid was not found somehow in the last scan.
2885 * - The current ssid was the last entry of the scan table and overloaded.
2886 */
2887void
2888mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2889{
2890 struct mwifiex_bssdescriptor *curr_bss =
2891 &priv->curr_bss_params.bss_descriptor;
2892
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002893 if (!curr_bss->beacon_buf_size)
2894 return;
2895
2896 /* allocate beacon buffer at 1st time; or if it's size has changed */
2897 if (!priv->curr_bcn_buf ||
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002898 priv->curr_bcn_size != curr_bss->beacon_buf_size) {
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002899 priv->curr_bcn_size = curr_bss->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002900
2901 kfree(priv->curr_bcn_buf);
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07002902 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002903 GFP_ATOMIC);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002904 if (!priv->curr_bcn_buf)
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002905 return;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002906 }
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002907
2908 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002909 curr_bss->beacon_buf_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302910 mwifiex_dbg(priv->adapter, INFO,
2911 "info: current beacon saved %d\n",
2912 priv->curr_bcn_size);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002913
2914 curr_bss->beacon_buf = priv->curr_bcn_buf;
2915
2916 /* adjust the pointers in the current BSS descriptor */
2917 if (curr_bss->bcn_wpa_ie)
2918 curr_bss->bcn_wpa_ie =
2919 (struct ieee_types_vendor_specific *)
2920 (curr_bss->beacon_buf +
2921 curr_bss->wpa_offset);
2922
2923 if (curr_bss->bcn_rsn_ie)
2924 curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
2925 (curr_bss->beacon_buf +
2926 curr_bss->rsn_offset);
2927
2928 if (curr_bss->bcn_ht_cap)
2929 curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
2930 (curr_bss->beacon_buf +
2931 curr_bss->ht_cap_offset);
2932
Johannes Berg074d46d2012-03-15 19:45:16 +01002933 if (curr_bss->bcn_ht_oper)
2934 curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002935 (curr_bss->beacon_buf +
2936 curr_bss->ht_info_offset);
2937
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002938 if (curr_bss->bcn_vht_cap)
Amitkumar Karward5124642014-03-04 18:43:14 -08002939 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2940 curr_bss->vht_cap_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002941
2942 if (curr_bss->bcn_vht_oper)
Amitkumar Karward5124642014-03-04 18:43:14 -08002943 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2944 curr_bss->vht_info_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002945
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002946 if (curr_bss->bcn_bss_co_2040)
2947 curr_bss->bcn_bss_co_2040 =
Joe Perches2c208892012-06-04 12:44:17 +00002948 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002949
2950 if (curr_bss->bcn_ext_cap)
Joe Perches2c208892012-06-04 12:44:17 +00002951 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2952 curr_bss->ext_cap_offset;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002953
2954 if (curr_bss->oper_mode)
2955 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2956 curr_bss->oper_mode_offset);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002957}
2958
2959/*
2960 * This function frees the current BSS descriptor beacon buffer.
2961 */
2962void
2963mwifiex_free_curr_bcn(struct mwifiex_private *priv)
2964{
2965 kfree(priv->curr_bcn_buf);
2966 priv->curr_bcn_buf = NULL;
2967}