blob: 96d0d86526781f7d4ee456373a50acc6f9719011 [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 */
Wei Yongjun5570a912012-09-28 12:59:43 +0800694 le16_add_cpu(&chan_tlv_out->header.len,
695 sizeof(chan_tlv_out->chan_scan_param));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700696
697 /*
698 * The tlv buffer length is set to the number of bytes
699 * of the between the channel tlv pointer and the start
700 * of the tlv buffer. This compensates for any TLVs
701 * that were appended before the channel list.
702 */
703 scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
704 scan_cfg_out->tlv_buf);
705
706 /* Add the size of the channel tlv header and the data
707 length */
708 scan_cfg_out->tlv_buf_len +=
709 (sizeof(chan_tlv_out->header)
710 + le16_to_cpu(chan_tlv_out->header.len));
711
712 /* Increment the index to the channel tlv we are
713 constructing */
714 tlv_idx++;
715
716 /* Count the total scan time per command */
717 total_scan_time +=
718 le16_to_cpu(tmp_chan_list->max_scan_time);
719
720 done_early = false;
721
722 /* Stop the loop if the *current* channel is in the
723 1,6,11 set and we are not filtering on a BSSID
724 or SSID. */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700725 if (!filtered_scan &&
726 (tmp_chan_list->chan_number == 1 ||
727 tmp_chan_list->chan_number == 6 ||
728 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700729 done_early = true;
730
731 /* Increment the tmp pointer to the next channel to
732 be scanned */
733 tmp_chan_list++;
734
735 /* Stop the loop if the *next* channel is in the 1,6,11
736 set. This will cause it to be the only channel
737 scanned on the next interation */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700738 if (!filtered_scan &&
739 (tmp_chan_list->chan_number == 1 ||
740 tmp_chan_list->chan_number == 6 ||
741 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700742 done_early = true;
743 }
744
745 /* The total scan time should be less than scan command timeout
746 value */
747 if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530748 mwifiex_dbg(priv->adapter, ERROR,
749 "total scan time %dms\t"
750 "is over limit (%dms), scan skipped\n",
751 total_scan_time,
752 MWIFIEX_MAX_TOTAL_SCAN_TIME);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700753 ret = -1;
754 break;
755 }
756
Avinash Patil78dfca62013-07-30 17:18:56 -0700757 rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out,
758 radio_type);
759
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700760 priv->adapter->scan_channels = start_chan;
761
762 /* Send the scan command to the firmware with the specified
763 cfg */
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800764 if (priv->adapter->ext_scan)
765 cmd_no = HostCmd_CMD_802_11_SCAN_EXT;
766 else
767 cmd_no = HostCmd_CMD_802_11_SCAN;
768
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800769 ret = mwifiex_send_cmd(priv, cmd_no, HostCmd_ACT_GEN_SET,
770 0, scan_cfg_out, false);
Avinash Patil78dfca62013-07-30 17:18:56 -0700771
772 /* rate IE is updated per scan command but same starting
773 * pointer is used each time so that rate IE from earlier
774 * scan_cfg_out->buf is overwritten with new one.
775 */
776 scan_cfg_out->tlv_buf_len -=
777 sizeof(struct mwifiex_ie_types_header) + rates_size;
778
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700779 if (ret) {
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +0100780 mwifiex_cancel_pending_scan_cmd(adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700781 break;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700782 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700783 }
784
785 if (ret)
786 return -1;
787
788 return 0;
789}
790
791/*
792 * This function constructs a scan command configuration structure to use
793 * in scan commands.
794 *
795 * Application layer or other functions can invoke network scanning
796 * with a scan configuration supplied in a user scan configuration structure.
797 * This structure is used as the basis of one or many scan command configuration
798 * commands that are sent to the command processing module and eventually to the
799 * firmware.
800 *
801 * This function creates a scan command configuration structure based on the
802 * following user supplied parameters (if present):
803 * - SSID filter
804 * - BSSID filter
805 * - Number of Probes to be sent
806 * - Channel list
807 *
808 * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
809 * If the number of probes is not set, adapter default setting is used.
810 */
811static void
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700812mwifiex_config_scan(struct mwifiex_private *priv,
813 const struct mwifiex_user_scan_cfg *user_scan_in,
814 struct mwifiex_scan_cmd_config *scan_cfg_out,
815 struct mwifiex_ie_types_chan_list_param_set **chan_list_out,
816 struct mwifiex_chan_scan_param_set *scan_chan_list,
817 u8 *max_chan_per_scan, u8 *filtered_scan,
818 u8 *scan_current_only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700819{
820 struct mwifiex_adapter *adapter = priv->adapter;
821 struct mwifiex_ie_types_num_probes *num_probes_tlv;
Avinash Patilcb91be82014-09-12 20:08:54 +0530822 struct mwifiex_ie_types_scan_chan_gap *chan_gap_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700823 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800824 struct mwifiex_ie_types_bssid_list *bssid_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825 u8 *tlv_pos;
826 u32 num_probes;
827 u32 ssid_len;
828 u32 chan_idx;
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700829 u32 chan_num;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700830 u32 scan_type;
831 u16 scan_dur;
832 u8 channel;
833 u8 radio_type;
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800834 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700835 u8 ssid_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700836 struct mwifiex_ie_types_htcap *ht_cap;
Aniket Nagarnaik40d74122015-07-16 08:05:21 -0700837 struct mwifiex_ie_types_bss_mode *bss_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700838
839 /* The tlv_buf_len is calculated for each scan command. The TLVs added
840 in this routine will be preserved since the routine that sends the
841 command will append channelTLVs at *chan_list_out. The difference
842 between the *chan_list_out and the tlv_buf start will be used to
843 calculate the size of anything we add in this routine. */
844 scan_cfg_out->tlv_buf_len = 0;
845
846 /* Running tlv pointer. Assigned to chan_list_out at end of function
847 so later routines know where channels can be added to the command
848 buf */
849 tlv_pos = scan_cfg_out->tlv_buf;
850
851 /* Initialize the scan as un-filtered; the flag is later set to TRUE
852 below if a SSID or BSSID filter is sent in the command */
853 *filtered_scan = false;
854
855 /* Initialize the scan as not being only on the current channel. If
856 the channel list is customized, only contains one channel, and is
857 the active channel, this is set true and data flow is not halted. */
858 *scan_current_only = false;
859
860 if (user_scan_in) {
861
862 /* Default the ssid_filter flag to TRUE, set false under
863 certain wildcard conditions and qualified by the existence
864 of an SSID list before marking the scan as filtered */
865 ssid_filter = true;
866
867 /* Set the BSS type scan filter, use Adapter setting if
868 unset */
869 scan_cfg_out->bss_mode =
Andreas Fenkart2ccf7ce2016-03-10 09:44:07 +0100870 (u8)(user_scan_in->bss_mode ?: adapter->scan_mode);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871
872 /* Set the number of probes to send, use Adapter setting
873 if unset */
Andreas Fenkart2ccf7ce2016-03-10 09:44:07 +0100874 num_probes = user_scan_in->num_probes ?: adapter->scan_probes;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700875
876 /*
877 * Set the BSSID filter to the incoming configuration,
878 * if non-zero. If not set, it will remain disabled
879 * (all zeros).
880 */
881 memcpy(scan_cfg_out->specific_bssid,
882 user_scan_in->specific_bssid,
883 sizeof(scan_cfg_out->specific_bssid));
884
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800885 if (adapter->ext_scan &&
886 !is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
887 bssid_tlv =
888 (struct mwifiex_ie_types_bssid_list *)tlv_pos;
889 bssid_tlv->header.type = cpu_to_le16(TLV_TYPE_BSSID);
890 bssid_tlv->header.len = cpu_to_le16(ETH_ALEN);
891 memcpy(bssid_tlv->bssid, user_scan_in->specific_bssid,
892 ETH_ALEN);
893 tlv_pos += sizeof(struct mwifiex_ie_types_bssid_list);
894 }
895
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800896 for (i = 0; i < user_scan_in->num_ssids; i++) {
897 ssid_len = user_scan_in->ssid_list[i].ssid_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898
899 wildcard_ssid_tlv =
900 (struct mwifiex_ie_types_wildcard_ssid_params *)
901 tlv_pos;
902 wildcard_ssid_tlv->header.type =
903 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
904 wildcard_ssid_tlv->header.len = cpu_to_le16(
905 (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
906 max_ssid_length)));
Amitkumar Karwarfada10582011-11-09 21:36:21 -0800907
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800908 /*
909 * max_ssid_length = 0 tells firmware to perform
910 * specific scan for the SSID filled, whereas
911 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
912 * wildcard scan.
913 */
914 if (ssid_len)
915 wildcard_ssid_tlv->max_ssid_length = 0;
916 else
917 wildcard_ssid_tlv->max_ssid_length =
918 IEEE80211_MAX_SSID_LEN;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700919
Aniket Nagarnaik0c6303c2015-07-16 08:05:22 -0700920 if (!memcmp(user_scan_in->ssid_list[i].ssid,
921 "DIRECT-", 7))
922 wildcard_ssid_tlv->max_ssid_length = 0xfe;
923
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700924 memcpy(wildcard_ssid_tlv->ssid,
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800925 user_scan_in->ssid_list[i].ssid, ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700926
927 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
928 + le16_to_cpu(wildcard_ssid_tlv->header.len));
929
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530930 mwifiex_dbg(adapter, INFO,
931 "info: scan: ssid[%d]: %s, %d\n",
932 i, wildcard_ssid_tlv->ssid,
933 wildcard_ssid_tlv->max_ssid_length);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700934
935 /* Empty wildcard ssid with a maxlen will match many or
936 potentially all SSIDs (maxlen == 32), therefore do
937 not treat the scan as
938 filtered. */
939 if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
940 ssid_filter = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700941 }
942
943 /*
944 * The default number of channels sent in the command is low to
945 * ensure the response buffer from the firmware does not
946 * truncate scan results. That is not an issue with an SSID
947 * or BSSID filter applied to the scan results in the firmware.
948 */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700949 if ((i && ssid_filter) ||
Bing Zhao84f6a952012-08-27 20:32:54 -0700950 !is_zero_ether_addr(scan_cfg_out->specific_bssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700951 *filtered_scan = true;
Avinash Patil8eda10e2014-09-17 23:01:26 +0530952
953 if (user_scan_in->scan_chan_gap) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530954 mwifiex_dbg(adapter, INFO,
955 "info: scan: channel gap = %d\n",
956 user_scan_in->scan_chan_gap);
Avinash Patil8eda10e2014-09-17 23:01:26 +0530957 *max_chan_per_scan =
958 MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
959
960 chan_gap_tlv = (void *)tlv_pos;
961 chan_gap_tlv->header.type =
962 cpu_to_le16(TLV_TYPE_SCAN_CHANNEL_GAP);
963 chan_gap_tlv->header.len =
964 cpu_to_le16(sizeof(chan_gap_tlv->chan_gap));
965 chan_gap_tlv->chan_gap =
966 cpu_to_le16((user_scan_in->scan_chan_gap));
967 tlv_pos +=
968 sizeof(struct mwifiex_ie_types_scan_chan_gap);
969 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700970 } else {
971 scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
972 num_probes = adapter->scan_probes;
973 }
974
975 /*
976 * If a specific BSSID or SSID is used, the number of channels in the
977 * scan command will be increased to the absolute maximum.
978 */
979 if (*filtered_scan)
980 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
981 else
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700982 *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700983
Aniket Nagarnaik40d74122015-07-16 08:05:21 -0700984 if (adapter->ext_scan) {
985 bss_mode = (struct mwifiex_ie_types_bss_mode *)tlv_pos;
986 bss_mode->header.type = cpu_to_le16(TLV_TYPE_BSS_MODE);
987 bss_mode->header.len = cpu_to_le16(sizeof(bss_mode->bss_mode));
988 bss_mode->bss_mode = scan_cfg_out->bss_mode;
989 tlv_pos += sizeof(bss_mode->header) +
990 le16_to_cpu(bss_mode->header.len);
991 }
992
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993 /* If the input config or adapter has the number of Probes set,
994 add tlv */
995 if (num_probes) {
996
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530997 mwifiex_dbg(adapter, INFO,
998 "info: scan: num_probes = %d\n",
999 num_probes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001000
1001 num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
1002 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
1003 num_probes_tlv->header.len =
1004 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
1005 num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
1006
1007 tlv_pos += sizeof(num_probes_tlv->header) +
1008 le16_to_cpu(num_probes_tlv->header.len);
1009
1010 }
1011
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001012 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
1013 (priv->adapter->config_bands & BAND_GN ||
1014 priv->adapter->config_bands & BAND_AN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015 ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
1016 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
1017 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1018 ht_cap->header.len =
1019 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001020 radio_type =
1021 mwifiex_band_to_radio_type(priv->adapter->config_bands);
Amitkumar Karwar341b8802014-02-07 16:27:31 -08001022 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001023 tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
1024 }
1025
1026 /* Append vendor specific IE TLV */
1027 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
1028
1029 /*
1030 * Set the output for the channel TLV to the address in the tlv buffer
1031 * past any TLVs that were added in this function (SSID, num_probes).
1032 * Channel TLVs will be added past this for each scan command,
1033 * preserving the TLVs that were previously added.
1034 */
1035 *chan_list_out =
1036 (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
1037
1038 if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
1039
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301040 mwifiex_dbg(adapter, INFO,
1041 "info: Scan: Using supplied channel list\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042
1043 for (chan_idx = 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001044 chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX &&
1045 user_scan_in->chan_list[chan_idx].chan_number;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001046 chan_idx++) {
1047
1048 channel = user_scan_in->chan_list[chan_idx].chan_number;
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001049 scan_chan_list[chan_idx].chan_number = channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001050
1051 radio_type =
1052 user_scan_in->chan_list[chan_idx].radio_type;
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001053 scan_chan_list[chan_idx].radio_type = radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054
1055 scan_type = user_scan_in->chan_list[chan_idx].scan_type;
1056
1057 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001058 scan_chan_list[chan_idx].chan_scan_mode_bitmap
chunfan chen2375fa22015-08-05 06:09:42 -07001059 |= (MWIFIEX_PASSIVE_SCAN |
1060 MWIFIEX_HIDDEN_SSID_REPORT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001061 else
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001062 scan_chan_list[chan_idx].chan_scan_mode_bitmap
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001063 &= ~MWIFIEX_PASSIVE_SCAN;
1064
Amitkumar Karwar1b499cb2016-04-24 23:49:51 -07001065 scan_chan_list[chan_idx].chan_scan_mode_bitmap
1066 |= MWIFIEX_DISABLE_CHAN_FILT;
Amitkumar Karwarf3e1af32012-10-19 19:19:18 -07001067
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001068 if (user_scan_in->chan_list[chan_idx].scan_time) {
1069 scan_dur = (u16) user_scan_in->
1070 chan_list[chan_idx].scan_time;
1071 } else {
1072 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1073 scan_dur = adapter->passive_scan_time;
1074 else if (*filtered_scan)
1075 scan_dur = adapter->specific_scan_time;
1076 else
1077 scan_dur = adapter->active_scan_time;
1078 }
1079
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001080 scan_chan_list[chan_idx].min_scan_time =
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001081 cpu_to_le16(scan_dur);
Andreas Fenkart948ad6b2016-03-10 09:44:09 +01001082 scan_chan_list[chan_idx].max_scan_time =
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001083 cpu_to_le16(scan_dur);
1084 }
1085
1086 /* Check if we are only scanning the current channel */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001087 if ((chan_idx == 1) &&
1088 (user_scan_in->chan_list[0].chan_number ==
1089 priv->curr_bss_params.bss_descriptor.channel)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001090 *scan_current_only = true;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301091 mwifiex_dbg(adapter, INFO,
1092 "info: Scan: Scanning current channel only\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001093 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001094 chan_num = chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001095 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301096 mwifiex_dbg(adapter, INFO,
1097 "info: Scan: Creating full region channel list\n");
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001098 chan_num = mwifiex_scan_create_channel_list(priv, user_scan_in,
1099 scan_chan_list,
1100 *filtered_scan);
1101 }
1102
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103}
1104
1105/*
1106 * This function inspects the scan response buffer for pointers to
1107 * expected TLVs.
1108 *
1109 * TLVs can be included at the end of the scan response BSS information.
1110 *
1111 * Data in the buffer is parsed pointers to TLVs that can potentially
1112 * be passed back in the response.
1113 */
1114static void
1115mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
1116 struct mwifiex_ie_types_data *tlv,
1117 u32 tlv_buf_size, u32 req_tlv_type,
1118 struct mwifiex_ie_types_data **tlv_data)
1119{
1120 struct mwifiex_ie_types_data *current_tlv;
1121 u32 tlv_buf_left;
1122 u32 tlv_type;
1123 u32 tlv_len;
1124
1125 current_tlv = tlv;
1126 tlv_buf_left = tlv_buf_size;
1127 *tlv_data = NULL;
1128
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301129 mwifiex_dbg(adapter, INFO,
1130 "info: SCAN_RESP: tlv_buf_size = %d\n",
1131 tlv_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001132
1133 while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
1134
1135 tlv_type = le16_to_cpu(current_tlv->header.type);
1136 tlv_len = le16_to_cpu(current_tlv->header.len);
1137
1138 if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301139 mwifiex_dbg(adapter, ERROR,
1140 "SCAN_RESP: TLV buffer corrupt\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001141 break;
1142 }
1143
1144 if (req_tlv_type == tlv_type) {
1145 switch (tlv_type) {
1146 case TLV_TYPE_TSFTIMESTAMP:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301147 mwifiex_dbg(adapter, INFO,
1148 "info: SCAN_RESP: TSF\t"
1149 "timestamp TLV, len = %d\n",
1150 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001151 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001152 break;
1153 case TLV_TYPE_CHANNELBANDLIST:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301154 mwifiex_dbg(adapter, INFO,
1155 "info: SCAN_RESP: channel\t"
1156 "band list TLV, len = %d\n",
1157 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001158 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001159 break;
1160 default:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301161 mwifiex_dbg(adapter, ERROR,
1162 "SCAN_RESP: unhandled TLV = %d\n",
1163 tlv_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001164 /* Give up, this seems corrupted */
1165 return;
1166 }
1167 }
1168
1169 if (*tlv_data)
1170 break;
1171
1172
1173 tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
1174 current_tlv =
1175 (struct mwifiex_ie_types_data *) (current_tlv->data +
1176 tlv_len);
1177
1178 } /* while */
1179}
1180
1181/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001182 * This function parses provided beacon buffer and updates
1183 * respective fields in bss descriptor structure.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001184 */
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001185int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1186 struct mwifiex_bssdescriptor *bss_entry)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187{
1188 int ret = 0;
1189 u8 element_id;
1190 struct ieee_types_fh_param_set *fh_param_set;
1191 struct ieee_types_ds_param_set *ds_param_set;
1192 struct ieee_types_cf_param_set *cf_param_set;
1193 struct ieee_types_ibss_param_set *ibss_param_set;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001194 u8 *current_ptr;
1195 u8 *rate;
1196 u8 element_len;
1197 u16 total_ie_len;
1198 u8 bytes_to_copy;
1199 u8 rate_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001200 u8 found_data_rate_ie;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001201 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 struct ieee_types_vendor_specific *vendor_ie;
1203 const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
1204 const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
1205
1206 found_data_rate_ie = false;
1207 rate_size = 0;
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001208 current_ptr = bss_entry->beacon_buf;
1209 bytes_left = bss_entry->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001210
1211 /* Process variable IE */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001212 while (bytes_left >= 2) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001213 element_id = *current_ptr;
1214 element_len = *(current_ptr + 1);
1215 total_ie_len = element_len + sizeof(struct ieee_types_header);
1216
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001217 if (bytes_left < total_ie_len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301218 mwifiex_dbg(adapter, ERROR,
1219 "err: InterpretIE: in processing\t"
1220 "IE, bytes left < IE length\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001221 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001222 }
1223 switch (element_id) {
1224 case WLAN_EID_SSID:
1225 bss_entry->ssid.ssid_len = element_len;
1226 memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
1227 element_len);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301228 mwifiex_dbg(adapter, INFO,
1229 "info: InterpretIE: ssid: %-32s\n",
1230 bss_entry->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001231 break;
1232
1233 case WLAN_EID_SUPP_RATES:
1234 memcpy(bss_entry->data_rates, current_ptr + 2,
1235 element_len);
1236 memcpy(bss_entry->supported_rates, current_ptr + 2,
1237 element_len);
1238 rate_size = element_len;
1239 found_data_rate_ie = true;
1240 break;
1241
1242 case WLAN_EID_FH_PARAMS:
1243 fh_param_set =
1244 (struct ieee_types_fh_param_set *) current_ptr;
1245 memcpy(&bss_entry->phy_param_set.fh_param_set,
1246 fh_param_set,
1247 sizeof(struct ieee_types_fh_param_set));
1248 break;
1249
1250 case WLAN_EID_DS_PARAMS:
1251 ds_param_set =
1252 (struct ieee_types_ds_param_set *) current_ptr;
1253
1254 bss_entry->channel = ds_param_set->current_chan;
1255
1256 memcpy(&bss_entry->phy_param_set.ds_param_set,
1257 ds_param_set,
1258 sizeof(struct ieee_types_ds_param_set));
1259 break;
1260
1261 case WLAN_EID_CF_PARAMS:
1262 cf_param_set =
1263 (struct ieee_types_cf_param_set *) current_ptr;
1264 memcpy(&bss_entry->ss_param_set.cf_param_set,
1265 cf_param_set,
1266 sizeof(struct ieee_types_cf_param_set));
1267 break;
1268
1269 case WLAN_EID_IBSS_PARAMS:
1270 ibss_param_set =
1271 (struct ieee_types_ibss_param_set *)
1272 current_ptr;
1273 memcpy(&bss_entry->ss_param_set.ibss_param_set,
1274 ibss_param_set,
1275 sizeof(struct ieee_types_ibss_param_set));
1276 break;
1277
1278 case WLAN_EID_ERP_INFO:
1279 bss_entry->erp_flags = *(current_ptr + 2);
1280 break;
1281
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -07001282 case WLAN_EID_PWR_CONSTRAINT:
1283 bss_entry->local_constraint = *(current_ptr + 2);
1284 bss_entry->sensed_11h = true;
1285 break;
1286
1287 case WLAN_EID_CHANNEL_SWITCH:
1288 bss_entry->chan_sw_ie_present = true;
1289 case WLAN_EID_PWR_CAPABILITY:
1290 case WLAN_EID_TPC_REPORT:
1291 case WLAN_EID_QUIET:
1292 bss_entry->sensed_11h = true;
1293 break;
1294
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001295 case WLAN_EID_EXT_SUPP_RATES:
1296 /*
1297 * Only process extended supported rate
1298 * if data rate is already found.
1299 * Data rate IE should come before
1300 * extended supported rate IE
1301 */
1302 if (found_data_rate_ie) {
1303 if ((element_len + rate_size) >
1304 MWIFIEX_SUPPORTED_RATES)
1305 bytes_to_copy =
1306 (MWIFIEX_SUPPORTED_RATES -
1307 rate_size);
1308 else
1309 bytes_to_copy = element_len;
1310
1311 rate = (u8 *) bss_entry->data_rates;
1312 rate += rate_size;
1313 memcpy(rate, current_ptr + 2, bytes_to_copy);
1314
1315 rate = (u8 *) bss_entry->supported_rates;
1316 rate += rate_size;
1317 memcpy(rate, current_ptr + 2, bytes_to_copy);
1318 }
1319 break;
1320
1321 case WLAN_EID_VENDOR_SPECIFIC:
1322 vendor_ie = (struct ieee_types_vendor_specific *)
1323 current_ptr;
1324
1325 if (!memcmp
1326 (vendor_ie->vend_hdr.oui, wpa_oui,
1327 sizeof(wpa_oui))) {
1328 bss_entry->bcn_wpa_ie =
1329 (struct ieee_types_vendor_specific *)
1330 current_ptr;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001331 bss_entry->wpa_offset = (u16)
1332 (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001333 } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui,
1334 sizeof(wmm_oui))) {
1335 if (total_ie_len ==
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001336 sizeof(struct ieee_types_wmm_parameter) ||
1337 total_ie_len ==
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001338 sizeof(struct ieee_types_wmm_info))
1339 /*
1340 * Only accept and copy the WMM IE if
1341 * it matches the size expected for the
1342 * WMM Info IE or the WMM Parameter IE.
1343 */
1344 memcpy((u8 *) &bss_entry->wmm_ie,
1345 current_ptr, total_ie_len);
1346 }
1347 break;
1348 case WLAN_EID_RSN:
1349 bss_entry->bcn_rsn_ie =
1350 (struct ieee_types_generic *) current_ptr;
1351 bss_entry->rsn_offset = (u16) (current_ptr -
1352 bss_entry->beacon_buf);
1353 break;
1354 case WLAN_EID_BSS_AC_ACCESS_DELAY:
1355 bss_entry->bcn_wapi_ie =
1356 (struct ieee_types_generic *) current_ptr;
1357 bss_entry->wapi_offset = (u16) (current_ptr -
1358 bss_entry->beacon_buf);
1359 break;
1360 case WLAN_EID_HT_CAPABILITY:
1361 bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
1362 (current_ptr +
1363 sizeof(struct ieee_types_header));
1364 bss_entry->ht_cap_offset = (u16) (current_ptr +
1365 sizeof(struct ieee_types_header) -
1366 bss_entry->beacon_buf);
1367 break;
Johannes Berg074d46d2012-03-15 19:45:16 +01001368 case WLAN_EID_HT_OPERATION:
1369 bss_entry->bcn_ht_oper =
1370 (struct ieee80211_ht_operation *)(current_ptr +
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001371 sizeof(struct ieee_types_header));
1372 bss_entry->ht_info_offset = (u16) (current_ptr +
1373 sizeof(struct ieee_types_header) -
1374 bss_entry->beacon_buf);
1375 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001376 case WLAN_EID_VHT_CAPABILITY:
1377 bss_entry->disable_11ac = false;
1378 bss_entry->bcn_vht_cap =
1379 (void *)(current_ptr +
1380 sizeof(struct ieee_types_header));
1381 bss_entry->vht_cap_offset =
1382 (u16)((u8 *)bss_entry->bcn_vht_cap -
1383 bss_entry->beacon_buf);
1384 break;
1385 case WLAN_EID_VHT_OPERATION:
1386 bss_entry->bcn_vht_oper =
1387 (void *)(current_ptr +
1388 sizeof(struct ieee_types_header));
1389 bss_entry->vht_info_offset =
1390 (u16)((u8 *)bss_entry->bcn_vht_oper -
1391 bss_entry->beacon_buf);
1392 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001393 case WLAN_EID_BSS_COEX_2040:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001394 bss_entry->bcn_bss_co_2040 = current_ptr;
1395 bss_entry->bss_co_2040_offset =
1396 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001397 break;
1398 case WLAN_EID_EXT_CAPABILITY:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001399 bss_entry->bcn_ext_cap = current_ptr;
1400 bss_entry->ext_cap_offset =
1401 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001402 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001403 case WLAN_EID_OPMODE_NOTIF:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001404 bss_entry->oper_mode = (void *)current_ptr;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001405 bss_entry->oper_mode_offset =
1406 (u16)((u8 *)bss_entry->oper_mode -
1407 bss_entry->beacon_buf);
1408 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001409 default:
1410 break;
1411 }
1412
1413 current_ptr += element_len + 2;
1414
1415 /* Need to account for IE ID and IE Len */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001416 bytes_left -= (element_len + 2);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001417
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001418 } /* while (bytes_left > 2) */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001419 return ret;
1420}
1421
1422/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001423 * This function converts radio type scan parameter to a band configuration
1424 * to be used in join command.
1425 */
1426static u8
1427mwifiex_radio_type_to_band(u8 radio_type)
1428{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001429 switch (radio_type) {
1430 case HostCmd_SCAN_RADIO_TYPE_A:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001431 return BAND_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001432 case HostCmd_SCAN_RADIO_TYPE_BG:
1433 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001434 return BAND_G;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001435 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001436}
1437
1438/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001439 * This is an internal function used to start a scan based on an input
1440 * configuration.
1441 *
1442 * This uses the input user scan configuration information when provided in
1443 * order to send the appropriate scan commands to firmware to populate or
1444 * update the internal driver scan table.
1445 */
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001446int mwifiex_scan_networks(struct mwifiex_private *priv,
1447 const struct mwifiex_user_scan_cfg *user_scan_in)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001448{
Bing Zhaoc2476332012-10-05 20:21:40 -07001449 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001450 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001451 struct cmd_ctrl_node *cmd_node;
1452 union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001453 struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001454 struct mwifiex_chan_scan_param_set *scan_chan_list;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001455 u8 filtered_scan;
1456 u8 scan_current_chan_only;
1457 u8 max_chan_per_scan;
1458 unsigned long flags;
1459
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001460 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301461 mwifiex_dbg(adapter, WARN,
1462 "cmd: Scan already in process...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001463 return -EBUSY;
1464 }
1465
1466 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301467 mwifiex_dbg(adapter, WARN,
1468 "cmd: Scan is blocked during association...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001469 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001470 }
1471
Amitkumar Karware00483f2015-01-07 03:57:39 -08001472 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301473 mwifiex_dbg(adapter, ERROR,
1474 "Ignore scan. Card removed or firmware in bad state\n");
Amitkumar Karware00483f2015-01-07 03:57:39 -08001475 return -EFAULT;
1476 }
1477
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001478 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1479 adapter->scan_processing = true;
1480 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1481
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001482 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
Joe Perches0d2e7a52013-02-03 17:28:14 +00001483 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001484 if (!scan_cfg_out) {
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001485 ret = -ENOMEM;
1486 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001487 }
1488
Joe Perches0d2e7a52013-02-03 17:28:14 +00001489 scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
1490 sizeof(struct mwifiex_chan_scan_param_set),
1491 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001492 if (!scan_chan_list) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001493 kfree(scan_cfg_out);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001494 ret = -ENOMEM;
1495 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001496 }
1497
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001498 mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config,
1499 &chan_list_out, scan_chan_list, &max_chan_per_scan,
1500 &filtered_scan, &scan_current_chan_only);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001501
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001502 ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
1503 &scan_cfg_out->config, chan_list_out,
1504 scan_chan_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001505
1506 /* Get scan command from scan_pending_q and put to cmd_pending_q */
1507 if (!ret) {
1508 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1509 if (!list_empty(&adapter->scan_pending_q)) {
1510 cmd_node = list_first_entry(&adapter->scan_pending_q,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001511 struct cmd_ctrl_node, list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001512 list_del(&cmd_node->list);
1513 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001514 flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001515 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1516 true);
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001517 queue_work(adapter->workqueue, &adapter->main_work);
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001518
1519 /* Perform internal scan synchronously */
Bing Zhao21de9792013-04-01 12:44:45 -07001520 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301521 mwifiex_dbg(adapter, INFO,
1522 "wait internal scan\n");
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001523 mwifiex_wait_queue_complete(adapter, cmd_node);
Bing Zhao21de9792013-04-01 12:44:45 -07001524 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001525 } else {
1526 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1527 flags);
1528 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001529 }
1530
1531 kfree(scan_cfg_out);
1532 kfree(scan_chan_list);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001533done:
1534 if (ret) {
1535 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1536 adapter->scan_processing = false;
1537 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1538 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001539 return ret;
1540}
1541
1542/*
1543 * This function prepares a scan command to be sent to the firmware.
1544 *
1545 * This uses the scan command configuration sent to the command processing
1546 * module in command preparation stage to configure a scan command structure
1547 * to send to firmware.
1548 *
1549 * The fixed fields specifying the BSS type and BSSID filters as well as a
1550 * variable number/length of TLVs are sent in the command to firmware.
1551 *
1552 * Preparation also includes -
1553 * - Setting command ID, and proper size
1554 * - Ensuring correct endian-ness
1555 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001556int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1557 struct mwifiex_scan_cmd_config *scan_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001558{
1559 struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001560
1561 /* Set fixed field variables in scan command */
1562 scan_cmd->bss_mode = scan_cfg->bss_mode;
1563 memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
1564 sizeof(scan_cmd->bssid));
1565 memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
1566
1567 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
1568
1569 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
1570 cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
1571 + sizeof(scan_cmd->bssid)
1572 + scan_cfg->tlv_buf_len + S_DS_GEN));
1573
1574 return 0;
1575}
1576
1577/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001578 * This function checks compatibility of requested network with current
1579 * driver settings.
1580 */
1581int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1582 struct mwifiex_bssdescriptor *bss_desc)
1583{
1584 int ret = -1;
1585
1586 if (!bss_desc)
1587 return -1;
1588
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -07001589 if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
1590 (u16) bss_desc->channel, 0))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001591 switch (priv->bss_mode) {
1592 case NL80211_IFTYPE_STATION:
1593 case NL80211_IFTYPE_ADHOC:
1594 ret = mwifiex_is_network_compatible(priv, bss_desc,
1595 priv->bss_mode);
1596 if (ret)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301597 mwifiex_dbg(priv->adapter, ERROR,
1598 "Incompatible network settings\n");
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001599 break;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001600 default:
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001601 ret = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001602 }
1603 }
1604
1605 return ret;
1606}
1607
chunfan chen2375fa22015-08-05 06:09:42 -07001608/* This function checks if SSID string contains all zeroes or length is zero */
1609static bool mwifiex_is_hidden_ssid(struct cfg80211_ssid *ssid)
1610{
1611 int idx;
1612
1613 for (idx = 0; idx < ssid->ssid_len; idx++) {
1614 if (ssid->ssid[idx])
1615 return false;
1616 }
1617
1618 return true;
1619}
1620
1621/* This function checks if any hidden SSID found in passive scan channels
1622 * and save those channels for specific SSID active scan
1623 */
1624static int mwifiex_save_hidden_ssid_channels(struct mwifiex_private *priv,
1625 struct cfg80211_bss *bss)
1626{
1627 struct mwifiex_bssdescriptor *bss_desc;
1628 int ret;
1629 int chid;
1630
1631 /* Allocate and fill new bss descriptor */
1632 bss_desc = kzalloc(sizeof(*bss_desc), GFP_KERNEL);
1633 if (!bss_desc)
1634 return -ENOMEM;
1635
1636 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
1637 if (ret)
1638 goto done;
1639
1640 if (mwifiex_is_hidden_ssid(&bss_desc->ssid)) {
1641 mwifiex_dbg(priv->adapter, INFO, "found hidden SSID\n");
1642 for (chid = 0 ; chid < MWIFIEX_USER_SCAN_CHAN_MAX; chid++) {
1643 if (priv->hidden_chan[chid].chan_number ==
1644 bss->channel->hw_value)
1645 break;
1646
1647 if (!priv->hidden_chan[chid].chan_number) {
1648 priv->hidden_chan[chid].chan_number =
1649 bss->channel->hw_value;
1650 priv->hidden_chan[chid].radio_type =
1651 bss->channel->band;
1652 priv->hidden_chan[chid].scan_type =
1653 MWIFIEX_SCAN_TYPE_ACTIVE;
1654 break;
1655 }
1656 }
1657 }
1658
1659done:
1660 kfree(bss_desc);
1661 return 0;
1662}
1663
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001664static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1665 struct cfg80211_bss *bss)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001666{
Jesper Juhldb652e42011-11-06 22:58:31 +01001667 struct mwifiex_bssdescriptor *bss_desc;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001668 int ret;
1669 unsigned long flags;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001670
1671 /* Allocate and fill new bss descriptor */
Joe Perches0d2e7a52013-02-03 17:28:14 +00001672 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
1673 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001674 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07001675
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001676 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001677 if (ret)
1678 goto done;
1679
1680 ret = mwifiex_check_network_compatibility(priv, bss_desc);
1681 if (ret)
1682 goto done;
1683
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001684 spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001685 /* Make a copy of current BSSID descriptor */
1686 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001687 sizeof(priv->curr_bss_params.bss_descriptor));
Bing Zhaod837a2a2013-04-12 10:34:17 -07001688
1689 /* The contents of beacon_ie will be copied to its own buffer
1690 * in mwifiex_save_curr_bcn()
1691 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001692 mwifiex_save_curr_bcn(priv);
1693 spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
1694
1695done:
Bing Zhaod837a2a2013-04-12 10:34:17 -07001696 /* beacon_ie buffer was allocated in function
1697 * mwifiex_fill_new_bss_desc(). Free it now.
1698 */
1699 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001700 kfree(bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001701 return 0;
1702}
1703
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001704static int
1705mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info,
1706 u32 *bytes_left, u64 fw_tsf, u8 *radio_type,
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001707 bool ext_scan, s32 rssi_val)
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001708{
1709 struct mwifiex_adapter *adapter = priv->adapter;
1710 struct mwifiex_chan_freq_power *cfp;
1711 struct cfg80211_bss *bss;
1712 u8 bssid[ETH_ALEN];
1713 s32 rssi;
1714 const u8 *ie_buf;
1715 size_t ie_len;
1716 u16 channel = 0;
1717 u16 beacon_size = 0;
1718 u32 curr_bcn_bytes;
1719 u32 freq;
1720 u16 beacon_period;
1721 u16 cap_info_bitmap;
1722 u8 *current_ptr;
1723 u64 timestamp;
1724 struct mwifiex_fixed_bcn_param *bcn_param;
1725 struct mwifiex_bss_priv *bss_priv;
1726
1727 if (*bytes_left >= sizeof(beacon_size)) {
1728 /* Extract & convert beacon size from command buffer */
Amitkumar Karwar798ea8e2014-11-25 06:43:03 -08001729 beacon_size = le16_to_cpu(*(__le16 *)(*bss_info));
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001730 *bytes_left -= sizeof(beacon_size);
1731 *bss_info += sizeof(beacon_size);
1732 }
1733
1734 if (!beacon_size || beacon_size > *bytes_left) {
1735 *bss_info += *bytes_left;
1736 *bytes_left = 0;
1737 return -EFAULT;
1738 }
1739
1740 /* Initialize the current working beacon pointer for this BSS
1741 * iteration
1742 */
1743 current_ptr = *bss_info;
1744
1745 /* Advance the return beacon pointer past the current beacon */
1746 *bss_info += beacon_size;
1747 *bytes_left -= beacon_size;
1748
1749 curr_bcn_bytes = beacon_size;
1750
1751 /* First 5 fields are bssid, RSSI(for legacy scan only),
1752 * time stamp, beacon interval, and capability information
1753 */
1754 if (curr_bcn_bytes < ETH_ALEN + sizeof(u8) +
1755 sizeof(struct mwifiex_fixed_bcn_param)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301756 mwifiex_dbg(adapter, ERROR,
1757 "InterpretIE: not enough bytes left\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001758 return -EFAULT;
1759 }
1760
1761 memcpy(bssid, current_ptr, ETH_ALEN);
1762 current_ptr += ETH_ALEN;
1763 curr_bcn_bytes -= ETH_ALEN;
1764
1765 if (!ext_scan) {
Joe Perches45d18c52014-03-24 13:15:39 -07001766 rssi = (s32) *current_ptr;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001767 rssi = (-rssi) * 100; /* Convert dBm to mBm */
1768 current_ptr += sizeof(u8);
1769 curr_bcn_bytes -= sizeof(u8);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301770 mwifiex_dbg(adapter, INFO,
1771 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001772 } else {
1773 rssi = rssi_val;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001774 }
1775
1776 bcn_param = (struct mwifiex_fixed_bcn_param *)current_ptr;
1777 current_ptr += sizeof(*bcn_param);
1778 curr_bcn_bytes -= sizeof(*bcn_param);
1779
1780 timestamp = le64_to_cpu(bcn_param->timestamp);
1781 beacon_period = le16_to_cpu(bcn_param->beacon_period);
1782
1783 cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301784 mwifiex_dbg(adapter, INFO,
1785 "info: InterpretIE: capabilities=0x%X\n",
1786 cap_info_bitmap);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001787
1788 /* Rest of the current buffer are IE's */
1789 ie_buf = current_ptr;
1790 ie_len = curr_bcn_bytes;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301791 mwifiex_dbg(adapter, INFO,
1792 "info: InterpretIE: IELength for this AP = %d\n",
1793 curr_bcn_bytes);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001794
1795 while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) {
1796 u8 element_id, element_len;
1797
1798 element_id = *current_ptr;
1799 element_len = *(current_ptr + 1);
1800 if (curr_bcn_bytes < element_len +
1801 sizeof(struct ieee_types_header)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301802 mwifiex_dbg(adapter, ERROR,
1803 "%s: bytes left < IE length\n", __func__);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001804 return -EFAULT;
1805 }
1806 if (element_id == WLAN_EID_DS_PARAMS) {
1807 channel = *(current_ptr +
1808 sizeof(struct ieee_types_header));
1809 break;
1810 }
1811
1812 current_ptr += element_len + sizeof(struct ieee_types_header);
1813 curr_bcn_bytes -= element_len +
1814 sizeof(struct ieee_types_header);
1815 }
1816
1817 if (channel) {
1818 struct ieee80211_channel *chan;
1819 u8 band;
1820
1821 /* Skip entry if on csa closed channel */
1822 if (channel == priv->csa_chan) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301823 mwifiex_dbg(adapter, WARN,
1824 "Dropping entry on csa closed channel\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001825 return 0;
1826 }
1827
1828 band = BAND_G;
1829 if (radio_type)
1830 band = mwifiex_radio_type_to_band(*radio_type &
1831 (BIT(0) | BIT(1)));
1832
1833 cfp = mwifiex_get_cfp(priv, band, channel, 0);
1834
1835 freq = cfp ? cfp->freq : 0;
1836
Avinash Patil4facc342015-01-28 15:42:00 +05301837 chan = ieee80211_get_channel(priv->wdev.wiphy, freq);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001838
1839 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Avinash Patil4facc342015-01-28 15:42:00 +05301840 bss = cfg80211_inform_bss(priv->wdev.wiphy,
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02001841 chan, CFG80211_BSS_FTYPE_UNKNOWN,
1842 bssid, timestamp,
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001843 cap_info_bitmap, beacon_period,
1844 ie_buf, ie_len, rssi, GFP_KERNEL);
Xinming Hu02421dd32015-09-18 06:32:07 -07001845 if (bss) {
1846 bss_priv = (struct mwifiex_bss_priv *)bss->priv;
1847 bss_priv->band = band;
1848 bss_priv->fw_tsf = fw_tsf;
1849 if (priv->media_connected &&
1850 !memcmp(bssid, priv->curr_bss_params.
1851 bss_descriptor.mac_address,
1852 ETH_ALEN))
1853 mwifiex_update_curr_bss_params(priv,
1854 bss);
1855 cfg80211_put_bss(priv->wdev.wiphy, bss);
1856 }
chunfan chen2375fa22015-08-05 06:09:42 -07001857
1858 if ((chan->flags & IEEE80211_CHAN_RADAR) ||
1859 (chan->flags & IEEE80211_CHAN_NO_IR)) {
1860 mwifiex_dbg(adapter, INFO,
1861 "radar or passive channel %d\n",
1862 channel);
1863 mwifiex_save_hidden_ssid_channels(priv, bss);
1864 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001865 }
1866 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301867 mwifiex_dbg(adapter, WARN, "missing BSS channel IE\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001868 }
1869
1870 return 0;
1871}
1872
Avinash Patil21445042014-05-27 21:39:32 -07001873static void mwifiex_complete_scan(struct mwifiex_private *priv)
1874{
1875 struct mwifiex_adapter *adapter = priv->adapter;
1876
Avinash Patilbf354432014-10-31 16:08:26 +05301877 adapter->survey_idx = 0;
Avinash Patil21445042014-05-27 21:39:32 -07001878 if (adapter->curr_cmd->wait_q_enabled) {
1879 adapter->cmd_wait_q.status = 0;
1880 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301881 mwifiex_dbg(adapter, INFO,
1882 "complete internal scan\n");
Avinash Patil21445042014-05-27 21:39:32 -07001883 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1884 }
1885 }
1886}
1887
chunfan chen2375fa22015-08-05 06:09:42 -07001888/* This function checks if any hidden SSID found in passive scan channels
1889 * and do specific SSID active scan for those channels
1890 */
1891static int
1892mwifiex_active_scan_req_for_passive_chan(struct mwifiex_private *priv)
1893{
1894 int ret;
1895 struct mwifiex_adapter *adapter = priv->adapter;
1896 u8 id = 0;
1897 struct mwifiex_user_scan_cfg *user_scan_cfg;
1898
Aniket Nagarnaik17e524b2015-09-18 06:32:09 -07001899 if (adapter->active_scan_triggered || !priv->scan_request) {
chunfan chen2375fa22015-08-05 06:09:42 -07001900 adapter->active_scan_triggered = false;
1901 return 0;
1902 }
1903
1904 if (!priv->hidden_chan[0].chan_number) {
1905 mwifiex_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n");
1906 return 0;
1907 }
1908 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1909
1910 if (!user_scan_cfg)
1911 return -ENOMEM;
1912
1913 memset(user_scan_cfg, 0, sizeof(*user_scan_cfg));
1914
1915 for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) {
1916 if (!priv->hidden_chan[id].chan_number)
1917 break;
1918 memcpy(&user_scan_cfg->chan_list[id],
1919 &priv->hidden_chan[id],
1920 sizeof(struct mwifiex_user_scan_chan));
1921 }
1922
1923 adapter->active_scan_triggered = true;
1924 user_scan_cfg->num_ssids = priv->scan_request->n_ssids;
1925 user_scan_cfg->ssid_list = priv->scan_request->ssids;
1926
1927 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1928 kfree(user_scan_cfg);
1929
1930 memset(&priv->hidden_chan, 0, sizeof(priv->hidden_chan));
1931
1932 if (ret) {
1933 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1934 return ret;
1935 }
1936
1937 return 0;
1938}
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001939static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1940{
1941 struct mwifiex_adapter *adapter = priv->adapter;
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +01001942 struct cmd_ctrl_node *cmd_node;
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001943 unsigned long flags;
1944
1945 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1946 if (list_empty(&adapter->scan_pending_q)) {
1947 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +01001948
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001949 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1950 adapter->scan_processing = false;
1951 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1952
chunfan chen2375fa22015-08-05 06:09:42 -07001953 mwifiex_active_scan_req_for_passive_chan(priv);
1954
Avinash Patil21445042014-05-27 21:39:32 -07001955 if (!adapter->ext_scan)
1956 mwifiex_complete_scan(priv);
1957
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001958 if (priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301959 mwifiex_dbg(adapter, INFO,
1960 "info: notifying scan done\n");
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001961 cfg80211_scan_done(priv->scan_request, 0);
1962 priv->scan_request = NULL;
Amitkumar Karwar09e672a2016-06-27 14:16:28 +05301963 priv->scan_aborting = false;
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001964 } else {
1965 priv->scan_aborting = false;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301966 mwifiex_dbg(adapter, INFO,
1967 "info: scan already aborted\n");
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001968 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05301969 } else if ((priv->scan_aborting && !priv->scan_request) ||
1970 priv->scan_block) {
Amitkumar Karward8d91252014-09-12 20:08:58 +05301971 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1972
Andreas Fenkartc70ca8c2016-03-10 09:44:10 +01001973 mwifiex_cancel_pending_scan_cmd(adapter);
1974
Amitkumar Karward8d91252014-09-12 20:08:58 +05301975 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1976 adapter->scan_processing = false;
1977 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1978
chunfan chen2375fa22015-08-05 06:09:42 -07001979 if (!adapter->active_scan_triggered) {
1980 if (priv->scan_request) {
1981 mwifiex_dbg(adapter, INFO,
1982 "info: aborting scan\n");
1983 cfg80211_scan_done(priv->scan_request, 1);
1984 priv->scan_request = NULL;
Amitkumar Karwar09e672a2016-06-27 14:16:28 +05301985 priv->scan_aborting = false;
chunfan chen2375fa22015-08-05 06:09:42 -07001986 } else {
1987 priv->scan_aborting = false;
1988 mwifiex_dbg(adapter, INFO,
1989 "info: scan already aborted\n");
1990 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05301991 }
1992 } else {
1993 /* Get scan command from scan_pending_q and put to
1994 * cmd_pending_q
1995 */
1996 cmd_node = list_first_entry(&adapter->scan_pending_q,
1997 struct cmd_ctrl_node, list);
1998 list_del(&cmd_node->list);
1999 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2000 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002001 }
2002
2003 return;
2004}
2005
Xinming Hua9c790b2016-06-16 18:52:22 +05302006void mwifiex_cancel_scan(struct mwifiex_adapter *adapter)
2007{
2008 struct mwifiex_private *priv;
2009 unsigned long cmd_flags;
2010 int i;
2011
2012 mwifiex_cancel_pending_scan_cmd(adapter);
2013
2014 if (adapter->scan_processing) {
2015 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
2016 adapter->scan_processing = false;
2017 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
2018 for (i = 0; i < adapter->priv_num; i++) {
2019 priv = adapter->priv[i];
2020 if (!priv)
2021 continue;
2022 if (priv->scan_request) {
2023 mwifiex_dbg(adapter, INFO,
2024 "info: aborting scan\n");
2025 cfg80211_scan_done(priv->scan_request, 1);
2026 priv->scan_request = NULL;
Amitkumar Karwar09e672a2016-06-27 14:16:28 +05302027 priv->scan_aborting = false;
Xinming Hua9c790b2016-06-16 18:52:22 +05302028 }
2029 }
2030 }
2031}
2032
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002033/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002034 * This function handles the command response of scan.
2035 *
2036 * The response buffer for the scan command has the following
2037 * memory layout:
2038 *
2039 * .-------------------------------------------------------------.
2040 * | Header (4 * sizeof(t_u16)): Standard command response hdr |
2041 * .-------------------------------------------------------------.
2042 * | BufSize (t_u16) : sizeof the BSS Description data |
2043 * .-------------------------------------------------------------.
2044 * | NumOfSet (t_u8) : Number of BSS Descs returned |
2045 * .-------------------------------------------------------------.
2046 * | BSSDescription data (variable, size given in BufSize) |
2047 * .-------------------------------------------------------------.
2048 * | TLV data (variable, size calculated using Header->Size, |
2049 * | BufSize and sizeof the fixed fields above) |
2050 * .-------------------------------------------------------------.
2051 */
2052int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002053 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002054{
2055 int ret = 0;
2056 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002057 struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002058 struct mwifiex_ie_types_data *tlv_data;
2059 struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
2060 u8 *bss_info;
2061 u32 scan_resp_size;
2062 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002063 u32 idx;
2064 u32 tlv_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002065 struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
2066 struct chan_band_param_set *chan_band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002067 u8 is_bgscan_resp;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002068 __le64 fw_tsf = 0;
2069 u8 *radio_type;
chunfan chen7d7f07d2016-01-13 01:26:54 -08002070 struct cfg80211_wowlan_nd_match *pmatch;
2071 struct cfg80211_sched_scan_request *nd_config = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002072
2073 is_bgscan_resp = (le16_to_cpu(resp->command)
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002074 == HostCmd_CMD_802_11_BG_SCAN_QUERY);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002075 if (is_bgscan_resp)
2076 scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
2077 else
2078 scan_rsp = &resp->params.scan_resp;
2079
2080
Bing Zhao67a50032011-07-13 18:38:34 -07002081 if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302082 mwifiex_dbg(adapter, ERROR,
2083 "SCAN_RESP: too many AP returned (%d)\n",
2084 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002085 ret = -1;
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002086 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002087 }
2088
Amitkumar Karwarb8876642013-06-18 16:36:58 -07002089 /* Check csa channel expiry before parsing scan response */
2090 mwifiex_11h_get_csa_closed_channel(priv);
2091
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002092 bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302093 mwifiex_dbg(adapter, INFO,
2094 "info: SCAN_RESP: bss_descript_size %d\n",
2095 bytes_left);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002096
2097 scan_resp_size = le16_to_cpu(resp->size);
2098
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302099 mwifiex_dbg(adapter, INFO,
2100 "info: SCAN_RESP: returned %d APs before parsing\n",
2101 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002102
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002103 bss_info = scan_rsp->bss_desc_and_tlv_buffer;
2104
2105 /*
2106 * The size of the TLV buffer is equal to the entire command response
2107 * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
2108 * BSS Descriptions (bss_descript_size as bytesLef) and the command
2109 * response header (S_DS_GEN)
2110 */
2111 tlv_buf_size = scan_resp_size - (bytes_left
2112 + sizeof(scan_rsp->bss_descript_size)
2113 + sizeof(scan_rsp->number_of_sets)
2114 + S_DS_GEN);
2115
2116 tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
2117 bss_desc_and_tlv_buffer +
2118 bytes_left);
2119
2120 /* Search the TLV buffer space in the scan response for any valid
2121 TLVs */
2122 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2123 TLV_TYPE_TSFTIMESTAMP,
2124 (struct mwifiex_ie_types_data **)
2125 &tsf_tlv);
2126
2127 /* Search the TLV buffer space in the scan response for any valid
2128 TLVs */
2129 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2130 TLV_TYPE_CHANNELBANDLIST,
2131 (struct mwifiex_ie_types_data **)
2132 &chan_band_tlv);
2133
chunfan chen7d7f07d2016-01-13 01:26:54 -08002134#ifdef CONFIG_PM
2135 if (priv->wdev.wiphy->wowlan_config)
2136 nd_config = priv->wdev.wiphy->wowlan_config->nd_config;
2137#endif
2138
2139 if (nd_config) {
2140 adapter->nd_info =
2141 kzalloc(sizeof(struct cfg80211_wowlan_nd_match) +
2142 sizeof(struct cfg80211_wowlan_nd_match *) *
2143 scan_rsp->number_of_sets, GFP_ATOMIC);
2144
2145 if (adapter->nd_info)
2146 adapter->nd_info->n_matches = scan_rsp->number_of_sets;
2147 }
2148
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002149 for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002150 /*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002151 * If the TSF TLV was appended to the scan results, save this
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002152 * entry's TSF value in the fw_tsf field. It is the firmware's
2153 * TSF value at the time the beacon or probe response was
2154 * received.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002155 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002156 if (tsf_tlv)
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002157 memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
2158 sizeof(fw_tsf));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002159
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002160 if (chan_band_tlv) {
2161 chan_band = &chan_band_tlv->chan_band_param[idx];
2162 radio_type = &chan_band->radio_type;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002163 } else {
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002164 radio_type = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002165 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002166
chunfan chen7d7f07d2016-01-13 01:26:54 -08002167 if (chan_band_tlv && adapter->nd_info) {
2168 adapter->nd_info->matches[idx] =
2169 kzalloc(sizeof(*pmatch) +
2170 sizeof(u32), GFP_ATOMIC);
2171
2172 pmatch = adapter->nd_info->matches[idx];
2173
Dan Carpenterefdf0e32016-02-02 13:00:05 +03002174 if (pmatch) {
chunfan chen7d7f07d2016-01-13 01:26:54 -08002175 memset(pmatch, 0, sizeof(*pmatch));
2176 if (chan_band_tlv) {
2177 pmatch->n_channels = 1;
2178 pmatch->channels[0] =
2179 chan_band->chan_number;
2180 }
2181 }
2182 }
2183
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002184 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2185 &bytes_left,
2186 le64_to_cpu(fw_tsf),
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002187 radio_type, false, 0);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002188 if (ret)
2189 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002190 }
2191
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002192check_next_scan:
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002193 mwifiex_check_next_scan_command(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002194 return ret;
2195}
2196
2197/*
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002198 * This function prepares an extended scan command to be sent to the firmware
2199 *
2200 * This uses the scan command configuration sent to the command processing
2201 * module in command preparation stage to configure a extended scan command
2202 * structure to send to firmware.
2203 */
2204int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
2205 struct host_cmd_ds_command *cmd,
2206 void *data_buf)
2207{
2208 struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan;
2209 struct mwifiex_scan_cmd_config *scan_cfg = data_buf;
2210
2211 memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
2212
2213 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT);
2214
2215 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
2216 cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved)
2217 + scan_cfg->tlv_buf_len + S_DS_GEN));
2218
2219 return 0;
2220}
2221
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002222/* This function prepares an background scan config command to be sent
2223 * to the firmware
2224 */
2225int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv,
2226 struct host_cmd_ds_command *cmd,
2227 void *data_buf)
2228{
2229 struct host_cmd_ds_802_11_bg_scan_config *bgscan_config =
2230 &cmd->params.bg_scan_config;
2231 struct mwifiex_bg_scan_cfg *bgscan_cfg_in = data_buf;
2232 u8 *tlv_pos = bgscan_config->tlv;
2233 u8 num_probes;
2234 u32 ssid_len, chan_idx, scan_type, scan_dur, chan_num;
2235 int i;
2236 struct mwifiex_ie_types_num_probes *num_probes_tlv;
2237 struct mwifiex_ie_types_repeat_count *repeat_count_tlv;
Ganapathi Bhatfdcab082016-01-13 01:26:56 -08002238 struct mwifiex_ie_types_min_rssi_threshold *rssi_threshold_tlv;
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002239 struct mwifiex_ie_types_bgscan_start_later *start_later_tlv;
2240 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
2241 struct mwifiex_ie_types_chan_list_param_set *chan_list_tlv;
2242 struct mwifiex_chan_scan_param_set *temp_chan;
2243
2244 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_CONFIG);
2245 cmd->size = cpu_to_le16(sizeof(*bgscan_config) + S_DS_GEN);
2246
2247 bgscan_config->action = cpu_to_le16(bgscan_cfg_in->action);
2248 bgscan_config->enable = bgscan_cfg_in->enable;
2249 bgscan_config->bss_type = bgscan_cfg_in->bss_type;
2250 bgscan_config->scan_interval =
2251 cpu_to_le32(bgscan_cfg_in->scan_interval);
2252 bgscan_config->report_condition =
2253 cpu_to_le32(bgscan_cfg_in->report_condition);
2254
2255 /* stop sched scan */
2256 if (!bgscan_config->enable)
2257 return 0;
2258
2259 bgscan_config->chan_per_scan = bgscan_cfg_in->chan_per_scan;
2260
2261 num_probes = (bgscan_cfg_in->num_probes ? bgscan_cfg_in->
2262 num_probes : priv->adapter->scan_probes);
2263
2264 if (num_probes) {
2265 num_probes_tlv = (struct mwifiex_ie_types_num_probes *)tlv_pos;
2266 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
2267 num_probes_tlv->header.len =
2268 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
2269 num_probes_tlv->num_probes = cpu_to_le16((u16)num_probes);
2270
2271 tlv_pos += sizeof(num_probes_tlv->header) +
2272 le16_to_cpu(num_probes_tlv->header.len);
2273 }
2274
2275 if (bgscan_cfg_in->repeat_count) {
2276 repeat_count_tlv =
2277 (struct mwifiex_ie_types_repeat_count *)tlv_pos;
2278 repeat_count_tlv->header.type =
2279 cpu_to_le16(TLV_TYPE_REPEAT_COUNT);
2280 repeat_count_tlv->header.len =
2281 cpu_to_le16(sizeof(repeat_count_tlv->repeat_count));
2282 repeat_count_tlv->repeat_count =
2283 cpu_to_le16(bgscan_cfg_in->repeat_count);
2284
2285 tlv_pos += sizeof(repeat_count_tlv->header) +
2286 le16_to_cpu(repeat_count_tlv->header.len);
2287 }
2288
Ganapathi Bhatfdcab082016-01-13 01:26:56 -08002289 if (bgscan_cfg_in->rssi_threshold) {
2290 rssi_threshold_tlv =
2291 (struct mwifiex_ie_types_min_rssi_threshold *)tlv_pos;
2292 rssi_threshold_tlv->header.type =
2293 cpu_to_le16(TLV_TYPE_RSSI_LOW);
2294 rssi_threshold_tlv->header.len =
2295 cpu_to_le16(sizeof(rssi_threshold_tlv->rssi_threshold));
2296 rssi_threshold_tlv->rssi_threshold =
2297 cpu_to_le16(bgscan_cfg_in->rssi_threshold);
2298
2299 tlv_pos += sizeof(rssi_threshold_tlv->header) +
2300 le16_to_cpu(rssi_threshold_tlv->header.len);
2301 }
2302
Xinming Hu0c9b7f22016-01-13 01:26:52 -08002303 for (i = 0; i < bgscan_cfg_in->num_ssids; i++) {
2304 ssid_len = bgscan_cfg_in->ssid_list[i].ssid.ssid_len;
2305
2306 wildcard_ssid_tlv =
2307 (struct mwifiex_ie_types_wildcard_ssid_params *)tlv_pos;
2308 wildcard_ssid_tlv->header.type =
2309 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
2310 wildcard_ssid_tlv->header.len = cpu_to_le16(
2311 (u16)(ssid_len + sizeof(wildcard_ssid_tlv->
2312 max_ssid_length)));
2313
2314 /* max_ssid_length = 0 tells firmware to perform
2315 * specific scan for the SSID filled, whereas
2316 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
2317 * wildcard scan.
2318 */
2319 if (ssid_len)
2320 wildcard_ssid_tlv->max_ssid_length = 0;
2321 else
2322 wildcard_ssid_tlv->max_ssid_length =
2323 IEEE80211_MAX_SSID_LEN;
2324
2325 memcpy(wildcard_ssid_tlv->ssid,
2326 bgscan_cfg_in->ssid_list[i].ssid.ssid, ssid_len);
2327
2328 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
2329 + le16_to_cpu(wildcard_ssid_tlv->header.len));
2330 }
2331
2332 chan_list_tlv = (struct mwifiex_ie_types_chan_list_param_set *)tlv_pos;
2333
2334 if (bgscan_cfg_in->chan_list[0].chan_number) {
2335 dev_dbg(priv->adapter->dev, "info: bgscan: Using supplied channel list\n");
2336
2337 chan_list_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
2338
2339 for (chan_idx = 0;
2340 chan_idx < MWIFIEX_BG_SCAN_CHAN_MAX &&
2341 bgscan_cfg_in->chan_list[chan_idx].chan_number;
2342 chan_idx++) {
2343 temp_chan = chan_list_tlv->chan_scan_param + chan_idx;
2344
2345 /* Increment the TLV header length by size appended */
2346 le16_add_cpu(&chan_list_tlv->header.len,
2347 sizeof(chan_list_tlv->chan_scan_param));
2348
2349 temp_chan->chan_number =
2350 bgscan_cfg_in->chan_list[chan_idx].chan_number;
2351 temp_chan->radio_type =
2352 bgscan_cfg_in->chan_list[chan_idx].radio_type;
2353
2354 scan_type =
2355 bgscan_cfg_in->chan_list[chan_idx].scan_type;
2356
2357 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
2358 temp_chan->chan_scan_mode_bitmap
2359 |= MWIFIEX_PASSIVE_SCAN;
2360 else
2361 temp_chan->chan_scan_mode_bitmap
2362 &= ~MWIFIEX_PASSIVE_SCAN;
2363
2364 if (bgscan_cfg_in->chan_list[chan_idx].scan_time) {
2365 scan_dur = (u16)bgscan_cfg_in->
2366 chan_list[chan_idx].scan_time;
2367 } else {
2368 scan_dur = (scan_type ==
2369 MWIFIEX_SCAN_TYPE_PASSIVE) ?
2370 priv->adapter->passive_scan_time :
2371 priv->adapter->specific_scan_time;
2372 }
2373
2374 temp_chan->min_scan_time = cpu_to_le16(scan_dur);
2375 temp_chan->max_scan_time = cpu_to_le16(scan_dur);
2376 }
2377 } else {
2378 dev_dbg(priv->adapter->dev,
2379 "info: bgscan: Creating full region channel list\n");
2380 chan_num =
2381 mwifiex_bgscan_create_channel_list(priv, bgscan_cfg_in,
2382 chan_list_tlv->
2383 chan_scan_param);
2384 le16_add_cpu(&chan_list_tlv->header.len,
2385 chan_num *
2386 sizeof(chan_list_tlv->chan_scan_param[0]));
2387 }
2388
2389 tlv_pos += (sizeof(chan_list_tlv->header)
2390 + le16_to_cpu(chan_list_tlv->header.len));
2391
2392 if (bgscan_cfg_in->start_later) {
2393 start_later_tlv =
2394 (struct mwifiex_ie_types_bgscan_start_later *)tlv_pos;
2395 start_later_tlv->header.type =
2396 cpu_to_le16(TLV_TYPE_BGSCAN_START_LATER);
2397 start_later_tlv->header.len =
2398 cpu_to_le16(sizeof(start_later_tlv->start_later));
2399 start_later_tlv->start_later =
2400 cpu_to_le16(bgscan_cfg_in->start_later);
2401
2402 tlv_pos += sizeof(start_later_tlv->header) +
2403 le16_to_cpu(start_later_tlv->header.len);
2404 }
2405
2406 /* Append vendor specific IE TLV */
2407 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_BGSCAN, &tlv_pos);
2408
2409 le16_add_cpu(&cmd->size, tlv_pos - bgscan_config->tlv);
2410
2411 return 0;
2412}
2413
2414int mwifiex_stop_bg_scan(struct mwifiex_private *priv)
2415{
2416 struct mwifiex_bg_scan_cfg *bgscan_cfg;
2417
2418 if (!priv->sched_scanning) {
2419 dev_dbg(priv->adapter->dev, "bgscan already stopped!\n");
2420 return 0;
2421 }
2422
2423 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
2424 if (!bgscan_cfg)
2425 return -ENOMEM;
2426
2427 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
2428 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
2429 bgscan_cfg->enable = false;
2430
2431 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
2432 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
2433 kfree(bgscan_cfg);
2434 return -EFAULT;
2435 }
2436
2437 kfree(bgscan_cfg);
2438 priv->sched_scanning = false;
2439
2440 return 0;
2441}
2442
Avinash Patilbf354432014-10-31 16:08:26 +05302443static void
2444mwifiex_update_chan_statistics(struct mwifiex_private *priv,
2445 struct mwifiex_ietypes_chanstats *tlv_stat)
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002446{
Avinash Patil3223db22014-09-12 20:08:48 +05302447 struct mwifiex_adapter *adapter = priv->adapter;
Avinash Patilbf354432014-10-31 16:08:26 +05302448 u8 i, num_chan;
2449 struct mwifiex_fw_chan_stats *fw_chan_stats;
2450 struct mwifiex_chan_stats chan_stats;
2451
2452 fw_chan_stats = (void *)((u8 *)tlv_stat +
2453 sizeof(struct mwifiex_ie_types_header));
2454 num_chan = le16_to_cpu(tlv_stat->header.len) /
2455 sizeof(struct mwifiex_chan_stats);
2456
2457 for (i = 0 ; i < num_chan; i++) {
2458 chan_stats.chan_num = fw_chan_stats->chan_num;
2459 chan_stats.bandcfg = fw_chan_stats->bandcfg;
2460 chan_stats.flags = fw_chan_stats->flags;
2461 chan_stats.noise = fw_chan_stats->noise;
2462 chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss);
2463 chan_stats.cca_scan_dur =
2464 le16_to_cpu(fw_chan_stats->cca_scan_dur);
2465 chan_stats.cca_busy_dur =
2466 le16_to_cpu(fw_chan_stats->cca_busy_dur);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302467 mwifiex_dbg(adapter, INFO,
2468 "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n",
2469 chan_stats.chan_num,
2470 chan_stats.noise,
2471 chan_stats.total_bss,
2472 chan_stats.cca_scan_dur,
2473 chan_stats.cca_busy_dur);
Avinash Patilbf354432014-10-31 16:08:26 +05302474 memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats,
2475 sizeof(struct mwifiex_chan_stats));
2476 fw_chan_stats++;
2477 }
2478}
2479
2480/* This function handles the command response of extended scan */
2481int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
2482 struct host_cmd_ds_command *resp)
2483{
2484 struct mwifiex_adapter *adapter = priv->adapter;
2485 struct host_cmd_ds_802_11_scan_ext *ext_scan_resp;
2486 struct mwifiex_ie_types_header *tlv;
2487 struct mwifiex_ietypes_chanstats *tlv_stat;
2488 u16 buf_left, type, len;
2489
Avinash Patil3223db22014-09-12 20:08:48 +05302490 struct host_cmd_ds_command *cmd_ptr;
2491 struct cmd_ctrl_node *cmd_node;
2492 unsigned long cmd_flags, scan_flags;
2493 bool complete_scan = false;
2494
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302495 mwifiex_dbg(adapter, INFO, "info: EXT scan returns successfully\n");
Avinash Patil21445042014-05-27 21:39:32 -07002496
Avinash Patilbf354432014-10-31 16:08:26 +05302497 ext_scan_resp = &resp->params.ext_scan;
2498
2499 tlv = (void *)ext_scan_resp->tlv_buffer;
2500 buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN
2501 - 1);
2502
2503 while (buf_left >= sizeof(struct mwifiex_ie_types_header)) {
2504 type = le16_to_cpu(tlv->type);
2505 len = le16_to_cpu(tlv->len);
2506
2507 if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302508 mwifiex_dbg(adapter, ERROR,
2509 "error processing scan response TLVs");
Avinash Patilbf354432014-10-31 16:08:26 +05302510 break;
2511 }
2512
2513 switch (type) {
2514 case TLV_TYPE_CHANNEL_STATS:
2515 tlv_stat = (void *)tlv;
2516 mwifiex_update_chan_statistics(priv, tlv_stat);
2517 break;
2518 default:
2519 break;
2520 }
2521
2522 buf_left -= len + sizeof(struct mwifiex_ie_types_header);
2523 tlv = (void *)((u8 *)tlv + len +
2524 sizeof(struct mwifiex_ie_types_header));
2525 }
2526
Avinash Patil3223db22014-09-12 20:08:48 +05302527 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
2528 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
2529 if (list_empty(&adapter->scan_pending_q)) {
2530 complete_scan = true;
2531 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
2532 cmd_ptr = (void *)cmd_node->cmd_skb->data;
2533 if (le16_to_cpu(cmd_ptr->command) ==
2534 HostCmd_CMD_802_11_SCAN_EXT) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302535 mwifiex_dbg(adapter, INFO,
2536 "Scan pending in command pending list");
Avinash Patil3223db22014-09-12 20:08:48 +05302537 complete_scan = false;
2538 break;
2539 }
2540 }
2541 }
2542 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags);
2543 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags);
2544
2545 if (complete_scan)
2546 mwifiex_complete_scan(priv);
Avinash Patil21445042014-05-27 21:39:32 -07002547
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002548 return 0;
2549}
2550
2551/* This function This function handles the event extended scan report. It
2552 * parses extended scan results and informs to cfg80211 stack.
2553 */
2554int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
2555 void *buf)
2556{
2557 int ret = 0;
2558 struct mwifiex_adapter *adapter = priv->adapter;
2559 u8 *bss_info;
2560 u32 bytes_left, bytes_left_for_tlv, idx;
2561 u16 type, len;
2562 struct mwifiex_ie_types_data *tlv;
2563 struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv;
2564 struct mwifiex_ie_types_bss_scan_info *scan_info_tlv;
2565 u8 *radio_type;
2566 u64 fw_tsf = 0;
2567 s32 rssi = 0;
2568 struct mwifiex_event_scan_result *event_scan = buf;
2569 u8 num_of_set = event_scan->num_of_set;
2570 u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
2571 u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
2572
2573 if (num_of_set > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302574 mwifiex_dbg(adapter, ERROR,
2575 "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
2576 num_of_set);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002577 ret = -1;
2578 goto check_next_scan;
2579 }
2580
2581 bytes_left = scan_resp_size;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302582 mwifiex_dbg(adapter, INFO,
2583 "EXT_SCAN: size %d, returned %d APs...",
2584 scan_resp_size, num_of_set);
Zhaoyang Liu868093a2015-05-12 00:48:19 +05302585 mwifiex_dbg_dump(adapter, CMD_D, "EXT_SCAN buffer:", buf,
2586 scan_resp_size +
2587 sizeof(struct mwifiex_event_scan_result));
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002588
2589 tlv = (struct mwifiex_ie_types_data *)scan_resp;
2590
2591 for (idx = 0; idx < num_of_set && bytes_left; idx++) {
2592 type = le16_to_cpu(tlv->header.type);
2593 len = le16_to_cpu(tlv->header.len);
2594 if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302595 mwifiex_dbg(adapter, ERROR,
2596 "EXT_SCAN: Error bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002597 break;
2598 }
2599 scan_rsp_tlv = NULL;
2600 scan_info_tlv = NULL;
2601 bytes_left_for_tlv = bytes_left;
2602
2603 /* BSS response TLV with beacon or probe response buffer
2604 * at the initial position of each descriptor
2605 */
2606 if (type != TLV_TYPE_BSS_SCAN_RSP)
2607 break;
2608
2609 bss_info = (u8 *)tlv;
2610 scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv;
2611 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2612 bytes_left_for_tlv -=
2613 (len + sizeof(struct mwifiex_ie_types_header));
2614
2615 while (bytes_left_for_tlv >=
2616 sizeof(struct mwifiex_ie_types_header) &&
2617 le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) {
2618 type = le16_to_cpu(tlv->header.type);
2619 len = le16_to_cpu(tlv->header.len);
2620 if (bytes_left_for_tlv <
2621 sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302622 mwifiex_dbg(adapter, ERROR,
2623 "EXT_SCAN: Error in processing TLV,\t"
2624 "bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002625 scan_rsp_tlv = NULL;
2626 bytes_left_for_tlv = 0;
2627 continue;
2628 }
2629 switch (type) {
2630 case TLV_TYPE_BSS_SCAN_INFO:
2631 scan_info_tlv =
2632 (struct mwifiex_ie_types_bss_scan_info *)tlv;
2633 if (len !=
2634 sizeof(struct mwifiex_ie_types_bss_scan_info) -
2635 sizeof(struct mwifiex_ie_types_header)) {
2636 bytes_left_for_tlv = 0;
2637 continue;
2638 }
2639 break;
2640 default:
2641 break;
2642 }
2643 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2644 bytes_left -=
2645 (len + sizeof(struct mwifiex_ie_types_header));
2646 bytes_left_for_tlv -=
2647 (len + sizeof(struct mwifiex_ie_types_header));
2648 }
2649
2650 if (!scan_rsp_tlv)
2651 break;
2652
2653 /* Advance pointer to the beacon buffer length and
2654 * update the bytes count so that the function
2655 * wlan_interpret_bss_desc_with_ie() can handle the
2656 * scan buffer withut any change
2657 */
2658 bss_info += sizeof(u16);
2659 bytes_left -= sizeof(u16);
2660
2661 if (scan_info_tlv) {
2662 rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi));
2663 rssi *= 100; /* Convert dBm to mBm */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302664 mwifiex_dbg(adapter, INFO,
2665 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002666 fw_tsf = le64_to_cpu(scan_info_tlv->tsf);
2667 radio_type = &scan_info_tlv->radio_type;
2668 } else {
2669 radio_type = NULL;
2670 }
2671 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2672 &bytes_left, fw_tsf,
2673 radio_type, true, rssi);
2674 if (ret)
2675 goto check_next_scan;
2676 }
2677
2678check_next_scan:
2679 if (!event_scan->more_event)
2680 mwifiex_check_next_scan_command(priv);
2681
2682 return ret;
2683}
2684
2685/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002686 * This function prepares command for background scan query.
2687 *
2688 * Preparation includes -
2689 * - Setting command ID and proper size
2690 * - Setting background scan flush parameter
2691 * - Ensuring correct endian-ness
2692 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002693int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002694{
2695 struct host_cmd_ds_802_11_bg_scan_query *bg_query =
2696 &cmd->params.bg_scan_query;
2697
2698 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
2699 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
2700 + S_DS_GEN);
2701
2702 bg_query->flush = 1;
2703
2704 return 0;
2705}
2706
2707/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002708 * This function inserts scan command node to the scan pending queue.
2709 */
2710void
2711mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
2712 struct cmd_ctrl_node *cmd_node)
2713{
2714 struct mwifiex_adapter *adapter = priv->adapter;
2715 unsigned long flags;
2716
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002717 cmd_node->wait_q_enabled = true;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002718 cmd_node->condition = &adapter->scan_wait_q_woken;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002719 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
2720 list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
2721 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2722}
2723
2724/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002725 * This function sends a scan command for all available channels to the
2726 * firmware, filtered on a specific SSID.
2727 */
2728static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002729 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002730{
2731 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhaodcd5c792012-10-19 19:01:59 -07002732 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002733 struct mwifiex_user_scan_cfg *scan_cfg;
2734
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002735 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302736 mwifiex_dbg(adapter, WARN,
2737 "cmd: Scan already in process...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002738 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002739 }
2740
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002741 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302742 mwifiex_dbg(adapter, WARN,
2743 "cmd: Scan is blocked during association...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002744 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002745 }
2746
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002747 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002748 if (!scan_cfg)
Christoph Fritzb53575e2011-05-08 22:50:09 +02002749 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002750
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08002751 scan_cfg->ssid_list = req_ssid;
2752 scan_cfg->num_ssids = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002753
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002754 ret = mwifiex_scan_networks(priv, scan_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002755
2756 kfree(scan_cfg);
2757 return ret;
2758}
2759
2760/*
2761 * Sends IOCTL request to start a scan.
2762 *
2763 * This function allocates the IOCTL request buffer, fills it
2764 * with requisite parameters and calls the IOCTL handler.
2765 *
2766 * Scan command can be issued for both normal scan and specific SSID
2767 * scan, depending upon whether an SSID is provided or not.
2768 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002769int mwifiex_request_scan(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002770 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002771{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002772 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002773
2774 if (down_interruptible(&priv->async_sem)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302775 mwifiex_dbg(priv->adapter, ERROR,
2776 "%s: acquire semaphore fail\n",
2777 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002778 return -1;
2779 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002780
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002781 priv->adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002782
2783 if (req_ssid && req_ssid->ssid_len != 0)
2784 /* Specific SSID scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002785 ret = mwifiex_scan_specific_ssid(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002786 else
2787 /* Normal scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002788 ret = mwifiex_scan_networks(priv, NULL);
2789
Amitkumar Karwarb0e70c22012-10-19 19:19:17 -07002790 up(&priv->async_sem);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002791
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002792 return ret;
2793}
2794
2795/*
2796 * This function appends the vendor specific IE TLV to a buffer.
2797 */
2798int
2799mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
2800 u16 vsie_mask, u8 **buffer)
2801{
2802 int id, ret_len = 0;
2803 struct mwifiex_ie_types_vendor_param_set *vs_param_set;
2804
2805 if (!buffer)
2806 return 0;
2807 if (!(*buffer))
2808 return 0;
2809
2810 /*
2811 * Traverse through the saved vendor specific IE array and append
2812 * the selected(scan/assoc/adhoc) IE as TLV to the command
2813 */
2814 for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
2815 if (priv->vs_ie[id].mask & vsie_mask) {
2816 vs_param_set =
2817 (struct mwifiex_ie_types_vendor_param_set *)
2818 *buffer;
2819 vs_param_set->header.type =
2820 cpu_to_le16(TLV_TYPE_PASSTHROUGH);
2821 vs_param_set->header.len =
2822 cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
2823 & 0x00FF) + 2);
2824 memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
2825 le16_to_cpu(vs_param_set->header.len));
2826 *buffer += le16_to_cpu(vs_param_set->header.len) +
2827 sizeof(struct mwifiex_ie_types_header);
2828 ret_len += le16_to_cpu(vs_param_set->header.len) +
2829 sizeof(struct mwifiex_ie_types_header);
2830 }
2831 }
2832 return ret_len;
2833}
2834
2835/*
2836 * This function saves a beacon buffer of the current BSS descriptor.
2837 *
2838 * The current beacon buffer is saved so that it can be restored in the
2839 * following cases that makes the beacon buffer not to contain the current
2840 * ssid's beacon buffer.
2841 * - The current ssid was not found somehow in the last scan.
2842 * - The current ssid was the last entry of the scan table and overloaded.
2843 */
2844void
2845mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2846{
2847 struct mwifiex_bssdescriptor *curr_bss =
2848 &priv->curr_bss_params.bss_descriptor;
2849
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002850 if (!curr_bss->beacon_buf_size)
2851 return;
2852
2853 /* allocate beacon buffer at 1st time; or if it's size has changed */
2854 if (!priv->curr_bcn_buf ||
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002855 priv->curr_bcn_size != curr_bss->beacon_buf_size) {
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002856 priv->curr_bcn_size = curr_bss->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002857
2858 kfree(priv->curr_bcn_buf);
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07002859 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002860 GFP_ATOMIC);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002861 if (!priv->curr_bcn_buf)
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002862 return;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002863 }
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002864
2865 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002866 curr_bss->beacon_buf_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302867 mwifiex_dbg(priv->adapter, INFO,
2868 "info: current beacon saved %d\n",
2869 priv->curr_bcn_size);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002870
2871 curr_bss->beacon_buf = priv->curr_bcn_buf;
2872
2873 /* adjust the pointers in the current BSS descriptor */
2874 if (curr_bss->bcn_wpa_ie)
2875 curr_bss->bcn_wpa_ie =
2876 (struct ieee_types_vendor_specific *)
2877 (curr_bss->beacon_buf +
2878 curr_bss->wpa_offset);
2879
2880 if (curr_bss->bcn_rsn_ie)
2881 curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
2882 (curr_bss->beacon_buf +
2883 curr_bss->rsn_offset);
2884
2885 if (curr_bss->bcn_ht_cap)
2886 curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
2887 (curr_bss->beacon_buf +
2888 curr_bss->ht_cap_offset);
2889
Johannes Berg074d46d2012-03-15 19:45:16 +01002890 if (curr_bss->bcn_ht_oper)
2891 curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002892 (curr_bss->beacon_buf +
2893 curr_bss->ht_info_offset);
2894
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002895 if (curr_bss->bcn_vht_cap)
Amitkumar Karward5124642014-03-04 18:43:14 -08002896 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2897 curr_bss->vht_cap_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002898
2899 if (curr_bss->bcn_vht_oper)
Amitkumar Karward5124642014-03-04 18:43:14 -08002900 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2901 curr_bss->vht_info_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002902
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002903 if (curr_bss->bcn_bss_co_2040)
2904 curr_bss->bcn_bss_co_2040 =
Joe Perches2c208892012-06-04 12:44:17 +00002905 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002906
2907 if (curr_bss->bcn_ext_cap)
Joe Perches2c208892012-06-04 12:44:17 +00002908 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2909 curr_bss->ext_cap_offset;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002910
2911 if (curr_bss->oper_mode)
2912 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2913 curr_bss->oper_mode_offset);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002914}
2915
2916/*
2917 * This function frees the current BSS descriptor beacon buffer.
2918 */
2919void
2920mwifiex_free_curr_bcn(struct mwifiex_private *priv)
2921{
2922 kfree(priv->curr_bcn_buf);
2923 priv->curr_bcn_buf = NULL;
2924}