blob: 5847863a2d6bec573956ff88c42a16c3495333b3 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: scan ioctl and command handling
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "11n.h"
26#include "cfg80211.h"
27
28/* The maximum number of channels the firmware can scan per command */
29#define MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN 14
30
Amitkumar Karwar658f37b2012-06-06 21:12:42 -070031#define MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD 4
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032
33/* Memory needed to store a max sized Channel List TLV for a firmware scan */
34#define CHAN_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_header) \
35 + (MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN \
36 *sizeof(struct mwifiex_chan_scan_param_set)))
37
38/* Memory needed to store supported rate */
39#define RATE_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_rates_param_set) \
40 + HOSTCMD_SUPPORTED_RATES)
41
42/* Memory needed to store a max number/size WildCard SSID TLV for a firmware
43 scan */
44#define WILDCARD_SSID_TLV_MAX_SIZE \
45 (MWIFIEX_MAX_SSID_LIST_LENGTH * \
46 (sizeof(struct mwifiex_ie_types_wildcard_ssid_params) \
47 + IEEE80211_MAX_SSID_LEN))
48
49/* Maximum memory needed for a mwifiex_scan_cmd_config with all TLVs at max */
50#define MAX_SCAN_CFG_ALLOC (sizeof(struct mwifiex_scan_cmd_config) \
51 + sizeof(struct mwifiex_ie_types_num_probes) \
52 + sizeof(struct mwifiex_ie_types_htcap) \
53 + CHAN_TLV_MAX_SIZE \
54 + RATE_TLV_MAX_SIZE \
55 + WILDCARD_SSID_TLV_MAX_SIZE)
56
57
58union mwifiex_scan_cmd_config_tlv {
59 /* Scan configuration (variable length) */
60 struct mwifiex_scan_cmd_config config;
61 /* Max allocated block */
62 u8 config_alloc_buf[MAX_SCAN_CFG_ALLOC];
63};
64
65enum cipher_suite {
66 CIPHER_SUITE_TKIP,
67 CIPHER_SUITE_CCMP,
68 CIPHER_SUITE_MAX
69};
70static u8 mwifiex_wpa_oui[CIPHER_SUITE_MAX][4] = {
71 { 0x00, 0x50, 0xf2, 0x02 }, /* TKIP */
72 { 0x00, 0x50, 0xf2, 0x04 }, /* AES */
73};
74static u8 mwifiex_rsn_oui[CIPHER_SUITE_MAX][4] = {
75 { 0x00, 0x0f, 0xac, 0x02 }, /* TKIP */
76 { 0x00, 0x0f, 0xac, 0x04 }, /* AES */
77};
78
79/*
80 * This function parses a given IE for a given OUI.
81 *
82 * This is used to parse a WPA/RSN IE to find if it has
83 * a given oui in PTK.
84 */
85static u8
86mwifiex_search_oui_in_ie(struct ie_body *iebody, u8 *oui)
87{
88 u8 count;
89
90 count = iebody->ptk_cnt[0];
91
92 /* There could be multiple OUIs for PTK hence
93 1) Take the length.
94 2) Check all the OUIs for AES.
95 3) If one of them is AES then pass success. */
96 while (count) {
97 if (!memcmp(iebody->ptk_body, oui, sizeof(iebody->ptk_body)))
98 return MWIFIEX_OUI_PRESENT;
99
100 --count;
101 if (count)
102 iebody = (struct ie_body *) ((u8 *) iebody +
103 sizeof(iebody->ptk_body));
104 }
105
106 pr_debug("info: %s: OUI is not found in PTK\n", __func__);
107 return MWIFIEX_OUI_NOT_PRESENT;
108}
109
110/*
111 * This function checks if a given OUI is present in a RSN IE.
112 *
113 * The function first checks if a RSN IE is present or not in the
114 * BSS descriptor. It tries to locate the OUI only if such an IE is
115 * present.
116 */
117static u8
118mwifiex_is_rsn_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
119{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700120 u8 *oui;
121 struct ie_body *iebody;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700122 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
123
124 if (((bss_desc->bcn_rsn_ie) && ((*(bss_desc->bcn_rsn_ie)).
125 ieee_hdr.element_id == WLAN_EID_RSN))) {
126 iebody = (struct ie_body *)
127 (((u8 *) bss_desc->bcn_rsn_ie->data) +
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700128 RSN_GTK_OUI_OFFSET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700129 oui = &mwifiex_rsn_oui[cipher][0];
130 ret = mwifiex_search_oui_in_ie(iebody, oui);
131 if (ret)
132 return ret;
133 }
134 return ret;
135}
136
137/*
138 * This function checks if a given OUI is present in a WPA IE.
139 *
140 * The function first checks if a WPA IE is present or not in the
141 * BSS descriptor. It tries to locate the OUI only if such an IE is
142 * present.
143 */
144static u8
145mwifiex_is_wpa_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
146{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700147 u8 *oui;
148 struct ie_body *iebody;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700149 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
150
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700151 if (((bss_desc->bcn_wpa_ie) &&
152 ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id ==
Arend van Spriel04b23122012-10-12 12:28:14 +0200153 WLAN_EID_VENDOR_SPECIFIC))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700154 iebody = (struct ie_body *) bss_desc->bcn_wpa_ie->data;
155 oui = &mwifiex_wpa_oui[cipher][0];
156 ret = mwifiex_search_oui_in_ie(iebody, oui);
157 if (ret)
158 return ret;
159 }
160 return ret;
161}
162
163/*
164 * This function compares two SSIDs and checks if they match.
165 */
166s32
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800167mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700168{
169 if (!ssid1 || !ssid2 || (ssid1->ssid_len != ssid2->ssid_len))
170 return -1;
171 return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssid_len);
172}
173
174/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700175 * This function checks if wapi is enabled in driver and scanned network is
176 * compatible with it.
177 */
178static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700179mwifiex_is_bss_wapi(struct mwifiex_private *priv,
180 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700181{
182 if (priv->sec_info.wapi_enabled &&
183 (bss_desc->bcn_wapi_ie &&
184 ((*(bss_desc->bcn_wapi_ie)).ieee_hdr.element_id ==
185 WLAN_EID_BSS_AC_ACCESS_DELAY))) {
186 return true;
187 }
188 return false;
189}
190
191/*
192 * This function checks if driver is configured with no security mode and
193 * scanned network is compatible with it.
194 */
195static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700196mwifiex_is_bss_no_sec(struct mwifiex_private *priv,
197 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700198{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800199 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
200 !priv->sec_info.wpa2_enabled && ((!bss_desc->bcn_wpa_ie) ||
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201 ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id !=
Arend van Spriel04b23122012-10-12 12:28:14 +0200202 WLAN_EID_VENDOR_SPECIFIC)) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700203 ((!bss_desc->bcn_rsn_ie) ||
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700204 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id !=
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700205 WLAN_EID_RSN)) &&
206 !priv->sec_info.encryption_mode && !bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700207 return true;
208 }
209 return false;
210}
211
212/*
213 * This function checks if static WEP is enabled in driver and scanned network
214 * is compatible with it.
215 */
216static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700217mwifiex_is_bss_static_wep(struct mwifiex_private *priv,
218 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700219{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800220 if (priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
221 !priv->sec_info.wpa2_enabled && bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700222 return true;
223 }
224 return false;
225}
226
227/*
228 * This function checks if wpa is enabled in driver and scanned network is
229 * compatible with it.
230 */
231static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700232mwifiex_is_bss_wpa(struct mwifiex_private *priv,
233 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700234{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800235 if (!priv->sec_info.wep_enabled && priv->sec_info.wpa_enabled &&
236 !priv->sec_info.wpa2_enabled && ((bss_desc->bcn_wpa_ie) &&
Arend van Spriel04b23122012-10-12 12:28:14 +0200237 ((*(bss_desc->bcn_wpa_ie)).
238 vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239 /*
240 * Privacy bit may NOT be set in some APs like
241 * LinkSys WRT54G && bss_desc->privacy
242 */
243 ) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530244 mwifiex_dbg(priv->adapter, INFO,
245 "info: %s: WPA:\t"
246 "wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s\t"
247 "EncMode=%#x privacy=%#x\n", __func__,
248 (bss_desc->bcn_wpa_ie) ?
249 (*bss_desc->bcn_wpa_ie).
250 vend_hdr.element_id : 0,
251 (bss_desc->bcn_rsn_ie) ?
252 (*bss_desc->bcn_rsn_ie).
253 ieee_hdr.element_id : 0,
254 (priv->sec_info.wep_enabled) ? "e" : "d",
255 (priv->sec_info.wpa_enabled) ? "e" : "d",
256 (priv->sec_info.wpa2_enabled) ? "e" : "d",
257 priv->sec_info.encryption_mode,
258 bss_desc->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700259 return true;
260 }
261 return false;
262}
263
264/*
265 * This function checks if wpa2 is enabled in driver and scanned network is
266 * compatible with it.
267 */
268static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700269mwifiex_is_bss_wpa2(struct mwifiex_private *priv,
270 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700271{
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700272 if (!priv->sec_info.wep_enabled &&
273 !priv->sec_info.wpa_enabled &&
274 priv->sec_info.wpa2_enabled &&
275 ((bss_desc->bcn_rsn_ie) &&
276 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id == WLAN_EID_RSN))) {
277 /*
278 * Privacy bit may NOT be set in some APs like
279 * LinkSys WRT54G && bss_desc->privacy
280 */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530281 mwifiex_dbg(priv->adapter, INFO,
282 "info: %s: WPA2:\t"
283 "wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s\t"
284 "EncMode=%#x privacy=%#x\n", __func__,
285 (bss_desc->bcn_wpa_ie) ?
286 (*bss_desc->bcn_wpa_ie).
287 vend_hdr.element_id : 0,
288 (bss_desc->bcn_rsn_ie) ?
289 (*bss_desc->bcn_rsn_ie).
290 ieee_hdr.element_id : 0,
291 (priv->sec_info.wep_enabled) ? "e" : "d",
292 (priv->sec_info.wpa_enabled) ? "e" : "d",
293 (priv->sec_info.wpa2_enabled) ? "e" : "d",
294 priv->sec_info.encryption_mode,
295 bss_desc->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700296 return true;
297 }
298 return false;
299}
300
301/*
302 * This function checks if adhoc AES is enabled in driver and scanned network is
303 * compatible with it.
304 */
305static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700306mwifiex_is_bss_adhoc_aes(struct mwifiex_private *priv,
307 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700308{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800309 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700310 !priv->sec_info.wpa2_enabled &&
311 ((!bss_desc->bcn_wpa_ie) ||
Arend van Spriel04b23122012-10-12 12:28:14 +0200312 ((*(bss_desc->bcn_wpa_ie)).
313 vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700314 ((!bss_desc->bcn_rsn_ie) ||
315 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
316 !priv->sec_info.encryption_mode && bss_desc->privacy) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700317 return true;
318 }
319 return false;
320}
321
322/*
323 * This function checks if dynamic WEP is enabled in driver and scanned network
324 * is compatible with it.
325 */
326static bool
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700327mwifiex_is_bss_dynamic_wep(struct mwifiex_private *priv,
328 struct mwifiex_bssdescriptor *bss_desc)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329{
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800330 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700331 !priv->sec_info.wpa2_enabled &&
332 ((!bss_desc->bcn_wpa_ie) ||
Arend van Spriel04b23122012-10-12 12:28:14 +0200333 ((*(bss_desc->bcn_wpa_ie)).
334 vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700335 ((!bss_desc->bcn_rsn_ie) ||
336 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
337 priv->sec_info.encryption_mode && bss_desc->privacy) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530338 mwifiex_dbg(priv->adapter, INFO,
339 "info: %s: dynamic\t"
340 "WEP: wpa_ie=%#x wpa2_ie=%#x\t"
341 "EncMode=%#x privacy=%#x\n",
342 __func__,
343 (bss_desc->bcn_wpa_ie) ?
344 (*bss_desc->bcn_wpa_ie).
345 vend_hdr.element_id : 0,
346 (bss_desc->bcn_rsn_ie) ?
347 (*bss_desc->bcn_rsn_ie).
348 ieee_hdr.element_id : 0,
349 priv->sec_info.encryption_mode,
350 bss_desc->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700351 return true;
352 }
353 return false;
354}
355
356/*
357 * This function checks if a scanned network is compatible with the driver
358 * settings.
359 *
360 * WEP WPA WPA2 ad-hoc encrypt Network
361 * enabled enabled enabled AES mode Privacy WPA WPA2 Compatible
362 * 0 0 0 0 NONE 0 0 0 yes No security
363 * 0 1 0 0 x 1x 1 x yes WPA (disable
364 * HT if no AES)
365 * 0 0 1 0 x 1x x 1 yes WPA2 (disable
366 * HT if no AES)
367 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
368 * 1 0 0 0 NONE 1 0 0 yes Static WEP
369 * (disable HT)
370 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
371 *
372 * Compatibility is not matched while roaming, except for mode.
373 */
374static s32
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700375mwifiex_is_network_compatible(struct mwifiex_private *priv,
376 struct mwifiex_bssdescriptor *bss_desc, u32 mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700377{
378 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700379
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700380 bss_desc->disable_11n = false;
381
382 /* Don't check for compatibility if roaming */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700383 if (priv->media_connected &&
384 (priv->bss_mode == NL80211_IFTYPE_STATION) &&
385 (bss_desc->bss_mode == NL80211_IFTYPE_STATION))
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700386 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700387
388 if (priv->wps.session_enable) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530389 mwifiex_dbg(adapter, IOCTL,
390 "info: return success directly in WPS period\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700391 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700392 }
393
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700394 if (bss_desc->chan_sw_ie_present) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530395 mwifiex_dbg(adapter, INFO,
396 "Don't connect to AP with WLAN_EID_CHANNEL_SWITCH\n");
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700397 return -1;
398 }
399
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700400 if (mwifiex_is_bss_wapi(priv, bss_desc)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530401 mwifiex_dbg(adapter, INFO,
402 "info: return success for WAPI AP\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700403 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404 }
405
406 if (bss_desc->bss_mode == mode) {
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700407 if (mwifiex_is_bss_no_sec(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700408 /* No security */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700409 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700410 } else if (mwifiex_is_bss_static_wep(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700411 /* Static WEP enabled */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530412 mwifiex_dbg(adapter, INFO,
413 "info: Disable 11n in WEP mode.\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700414 bss_desc->disable_11n = true;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700415 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700416 } else if (mwifiex_is_bss_wpa(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700417 /* WPA enabled */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700418 if (((priv->adapter->config_bands & BAND_GN ||
419 priv->adapter->config_bands & BAND_AN) &&
420 bss_desc->bcn_ht_cap) &&
421 !mwifiex_is_wpa_oui_present(bss_desc,
422 CIPHER_SUITE_CCMP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700423
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700424 if (mwifiex_is_wpa_oui_present
425 (bss_desc, CIPHER_SUITE_TKIP)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530426 mwifiex_dbg(adapter, INFO,
427 "info: Disable 11n if AES\t"
428 "is not supported by AP\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700429 bss_desc->disable_11n = true;
430 } else {
431 return -1;
432 }
433 }
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700434 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700435 } else if (mwifiex_is_bss_wpa2(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700436 /* WPA2 enabled */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700437 if (((priv->adapter->config_bands & BAND_GN ||
438 priv->adapter->config_bands & BAND_AN) &&
439 bss_desc->bcn_ht_cap) &&
440 !mwifiex_is_rsn_oui_present(bss_desc,
441 CIPHER_SUITE_CCMP)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700442
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700443 if (mwifiex_is_rsn_oui_present
444 (bss_desc, CIPHER_SUITE_TKIP)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530445 mwifiex_dbg(adapter, INFO,
446 "info: Disable 11n if AES\t"
447 "is not supported by AP\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448 bss_desc->disable_11n = true;
449 } else {
450 return -1;
451 }
452 }
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700453 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700454 } else if (mwifiex_is_bss_adhoc_aes(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700455 /* Ad-hoc AES enabled */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700456 return 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700457 } else if (mwifiex_is_bss_dynamic_wep(priv, bss_desc)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700458 /* Dynamic WEP enabled */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700459 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700460 }
461
462 /* Security doesn't match */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530463 mwifiex_dbg(adapter, ERROR,
464 "info: %s: failed: wpa_ie=%#x wpa2_ie=%#x WEP=%s\t"
465 "WPA=%s WPA2=%s EncMode=%#x privacy=%#x\n",
466 __func__,
467 (bss_desc->bcn_wpa_ie) ?
468 (*bss_desc->bcn_wpa_ie).vend_hdr.element_id : 0,
469 (bss_desc->bcn_rsn_ie) ?
470 (*bss_desc->bcn_rsn_ie).ieee_hdr.element_id : 0,
471 (priv->sec_info.wep_enabled) ? "e" : "d",
472 (priv->sec_info.wpa_enabled) ? "e" : "d",
473 (priv->sec_info.wpa2_enabled) ? "e" : "d",
474 priv->sec_info.encryption_mode, bss_desc->privacy);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475 return -1;
476 }
477
478 /* Mode doesn't match */
479 return -1;
480}
481
482/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700483 * This function creates a channel list for the driver to scan, based
484 * on region/band information.
485 *
486 * This routine is used for any scan that is not provided with a
487 * specific channel list to scan.
488 */
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700489static int
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700490mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700491 const struct mwifiex_user_scan_cfg
492 *user_scan_in,
493 struct mwifiex_chan_scan_param_set
494 *scan_chan_list,
495 u8 filtered_scan)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700496{
497 enum ieee80211_band band;
498 struct ieee80211_supported_band *sband;
499 struct ieee80211_channel *ch;
500 struct mwifiex_adapter *adapter = priv->adapter;
501 int chan_idx = 0, i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700502
503 for (band = 0; (band < IEEE80211_NUM_BANDS) ; band++) {
504
Avinash Patil4facc342015-01-28 15:42:00 +0530505 if (!priv->wdev.wiphy->bands[band])
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700506 continue;
507
Avinash Patil4facc342015-01-28 15:42:00 +0530508 sband = priv->wdev.wiphy->bands[band];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700509
Amitkumar Karward06b7b92011-09-21 21:43:22 -0700510 for (i = 0; (i < sband->n_channels) ; i++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700511 ch = &sband->channels[i];
512 if (ch->flags & IEEE80211_CHAN_DISABLED)
513 continue;
514 scan_chan_list[chan_idx].radio_type = band;
Amitkumar Karwar186630c2011-12-15 21:00:37 -0800515
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700516 if (user_scan_in &&
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700517 user_scan_in->chan_list[0].scan_time)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 scan_chan_list[chan_idx].max_scan_time =
519 cpu_to_le16((u16) user_scan_in->
520 chan_list[0].scan_time);
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200521 else if (ch->flags & IEEE80211_CHAN_NO_IR)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700522 scan_chan_list[chan_idx].max_scan_time =
523 cpu_to_le16(adapter->passive_scan_time);
524 else
525 scan_chan_list[chan_idx].max_scan_time =
526 cpu_to_le16(adapter->active_scan_time);
Amitkumar Karwar186630c2011-12-15 21:00:37 -0800527
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200528 if (ch->flags & IEEE80211_CHAN_NO_IR)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700529 scan_chan_list[chan_idx].chan_scan_mode_bitmap
chunfan chen2375fa22015-08-05 06:09:42 -0700530 |= (MWIFIEX_PASSIVE_SCAN |
531 MWIFIEX_HIDDEN_SSID_REPORT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700532 else
533 scan_chan_list[chan_idx].chan_scan_mode_bitmap
534 &= ~MWIFIEX_PASSIVE_SCAN;
535 scan_chan_list[chan_idx].chan_number =
536 (u32) ch->hw_value;
537 if (filtered_scan) {
538 scan_chan_list[chan_idx].max_scan_time =
539 cpu_to_le16(adapter->specific_scan_time);
540 scan_chan_list[chan_idx].chan_scan_mode_bitmap
541 |= MWIFIEX_DISABLE_CHAN_FILT;
542 }
Amitkumar Karward06b7b92011-09-21 21:43:22 -0700543 chan_idx++;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700544 }
545
546 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700547 return chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548}
549
Avinash Patil78dfca62013-07-30 17:18:56 -0700550/* This function appends rate TLV to scan config command. */
551static int
552mwifiex_append_rate_tlv(struct mwifiex_private *priv,
553 struct mwifiex_scan_cmd_config *scan_cfg_out,
554 u8 radio)
555{
556 struct mwifiex_ie_types_rates_param_set *rates_tlv;
557 u8 rates[MWIFIEX_SUPPORTED_RATES], *tlv_pos;
558 u32 rates_size;
559
560 memset(rates, 0, sizeof(rates));
561
562 tlv_pos = (u8 *)scan_cfg_out->tlv_buf + scan_cfg_out->tlv_buf_len;
563
564 if (priv->scan_request)
565 rates_size = mwifiex_get_rates_from_cfg80211(priv, rates,
566 radio);
567 else
568 rates_size = mwifiex_get_supported_rates(priv, rates);
569
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530570 mwifiex_dbg(priv->adapter, CMD,
571 "info: SCAN_CMD: Rates size = %d\n",
Avinash Patil78dfca62013-07-30 17:18:56 -0700572 rates_size);
573 rates_tlv = (struct mwifiex_ie_types_rates_param_set *)tlv_pos;
574 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
575 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
576 memcpy(rates_tlv->rates, rates, rates_size);
577 scan_cfg_out->tlv_buf_len += sizeof(rates_tlv->header) + rates_size;
578
579 return rates_size;
580}
581
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582/*
583 * This function constructs and sends multiple scan config commands to
584 * the firmware.
585 *
586 * Previous routines in the code flow have created a scan command configuration
587 * with any requested TLVs. This function splits the channel TLV into maximum
588 * channels supported per scan lists and sends the portion of the channel TLV,
589 * along with the other TLVs, to the firmware.
590 */
591static int
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700592mwifiex_scan_channel_list(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700593 u32 max_chan_per_scan, u8 filtered_scan,
594 struct mwifiex_scan_cmd_config *scan_cfg_out,
595 struct mwifiex_ie_types_chan_list_param_set
596 *chan_tlv_out,
597 struct mwifiex_chan_scan_param_set *scan_chan_list)
598{
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700599 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700600 int ret = 0;
601 struct mwifiex_chan_scan_param_set *tmp_chan_list;
602 struct mwifiex_chan_scan_param_set *start_chan;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700603 struct cmd_ctrl_node *cmd_node, *tmp_node;
604 unsigned long flags;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800605 u32 tlv_idx, rates_size, cmd_no;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700606 u32 total_scan_time;
607 u32 done_early;
Avinash Patil78dfca62013-07-30 17:18:56 -0700608 u8 radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700609
610 if (!scan_cfg_out || !chan_tlv_out || !scan_chan_list) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530611 mwifiex_dbg(priv->adapter, ERROR,
612 "info: Scan: Null detect: %p, %p, %p\n",
613 scan_cfg_out, chan_tlv_out, scan_chan_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700614 return -1;
615 }
616
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700617 /* Check csa channel expiry before preparing scan list */
618 mwifiex_11h_get_csa_closed_channel(priv);
619
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700620 chan_tlv_out->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
621
622 /* Set the temp channel struct pointer to the start of the desired
623 list */
624 tmp_chan_list = scan_chan_list;
625
626 /* Loop through the desired channel list, sending a new firmware scan
627 commands for each max_chan_per_scan channels (or for 1,6,11
628 individually if configured accordingly) */
629 while (tmp_chan_list->chan_number) {
630
631 tlv_idx = 0;
632 total_scan_time = 0;
Avinash Patil78dfca62013-07-30 17:18:56 -0700633 radio_type = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700634 chan_tlv_out->header.len = 0;
635 start_chan = tmp_chan_list;
636 done_early = false;
637
638 /*
639 * Construct the Channel TLV for the scan command. Continue to
640 * insert channel TLVs until:
641 * - the tlv_idx hits the maximum configured per scan command
642 * - the next channel to insert is 0 (end of desired channel
643 * list)
644 * - done_early is set (controlling individual scanning of
645 * 1,6,11)
646 */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700647 while (tlv_idx < max_chan_per_scan &&
648 tmp_chan_list->chan_number && !done_early) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700650 if (tmp_chan_list->chan_number == priv->csa_chan) {
651 tmp_chan_list++;
652 continue;
653 }
654
Avinash Patil78dfca62013-07-30 17:18:56 -0700655 radio_type = tmp_chan_list->radio_type;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530656 mwifiex_dbg(priv->adapter, INFO,
657 "info: Scan: Chan(%3d), Radio(%d),\t"
658 "Mode(%d, %d), Dur(%d)\n",
659 tmp_chan_list->chan_number,
660 tmp_chan_list->radio_type,
661 tmp_chan_list->chan_scan_mode_bitmap
662 & MWIFIEX_PASSIVE_SCAN,
663 (tmp_chan_list->chan_scan_mode_bitmap
664 & MWIFIEX_DISABLE_CHAN_FILT) >> 1,
665 le16_to_cpu(tmp_chan_list->max_scan_time));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700666
667 /* Copy the current channel TLV to the command being
668 prepared */
669 memcpy(chan_tlv_out->chan_scan_param + tlv_idx,
670 tmp_chan_list,
671 sizeof(chan_tlv_out->chan_scan_param));
672
673 /* Increment the TLV header length by the size
674 appended */
Wei Yongjun5570a912012-09-28 12:59:43 +0800675 le16_add_cpu(&chan_tlv_out->header.len,
676 sizeof(chan_tlv_out->chan_scan_param));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700677
678 /*
679 * The tlv buffer length is set to the number of bytes
680 * of the between the channel tlv pointer and the start
681 * of the tlv buffer. This compensates for any TLVs
682 * that were appended before the channel list.
683 */
684 scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
685 scan_cfg_out->tlv_buf);
686
687 /* Add the size of the channel tlv header and the data
688 length */
689 scan_cfg_out->tlv_buf_len +=
690 (sizeof(chan_tlv_out->header)
691 + le16_to_cpu(chan_tlv_out->header.len));
692
693 /* Increment the index to the channel tlv we are
694 constructing */
695 tlv_idx++;
696
697 /* Count the total scan time per command */
698 total_scan_time +=
699 le16_to_cpu(tmp_chan_list->max_scan_time);
700
701 done_early = false;
702
703 /* Stop the loop if the *current* channel is in the
704 1,6,11 set and we are not filtering on a BSSID
705 or SSID. */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700706 if (!filtered_scan &&
707 (tmp_chan_list->chan_number == 1 ||
708 tmp_chan_list->chan_number == 6 ||
709 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700710 done_early = true;
711
712 /* Increment the tmp pointer to the next channel to
713 be scanned */
714 tmp_chan_list++;
715
716 /* Stop the loop if the *next* channel is in the 1,6,11
717 set. This will cause it to be the only channel
718 scanned on the next interation */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700719 if (!filtered_scan &&
720 (tmp_chan_list->chan_number == 1 ||
721 tmp_chan_list->chan_number == 6 ||
722 tmp_chan_list->chan_number == 11))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700723 done_early = true;
724 }
725
726 /* The total scan time should be less than scan command timeout
727 value */
728 if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530729 mwifiex_dbg(priv->adapter, ERROR,
730 "total scan time %dms\t"
731 "is over limit (%dms), scan skipped\n",
732 total_scan_time,
733 MWIFIEX_MAX_TOTAL_SCAN_TIME);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700734 ret = -1;
735 break;
736 }
737
Avinash Patil78dfca62013-07-30 17:18:56 -0700738 rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out,
739 radio_type);
740
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700741 priv->adapter->scan_channels = start_chan;
742
743 /* Send the scan command to the firmware with the specified
744 cfg */
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800745 if (priv->adapter->ext_scan)
746 cmd_no = HostCmd_CMD_802_11_SCAN_EXT;
747 else
748 cmd_no = HostCmd_CMD_802_11_SCAN;
749
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800750 ret = mwifiex_send_cmd(priv, cmd_no, HostCmd_ACT_GEN_SET,
751 0, scan_cfg_out, false);
Avinash Patil78dfca62013-07-30 17:18:56 -0700752
753 /* rate IE is updated per scan command but same starting
754 * pointer is used each time so that rate IE from earlier
755 * scan_cfg_out->buf is overwritten with new one.
756 */
757 scan_cfg_out->tlv_buf_len -=
758 sizeof(struct mwifiex_ie_types_header) + rates_size;
759
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700760 if (ret) {
761 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
762 list_for_each_entry_safe(cmd_node, tmp_node,
763 &adapter->scan_pending_q,
764 list) {
765 list_del(&cmd_node->list);
766 cmd_node->wait_q_enabled = false;
767 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
768 }
769 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
770 flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700771 break;
Amitkumar Karwar1845bd32014-03-20 19:50:06 -0700772 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700773 }
774
775 if (ret)
776 return -1;
777
778 return 0;
779}
780
781/*
782 * This function constructs a scan command configuration structure to use
783 * in scan commands.
784 *
785 * Application layer or other functions can invoke network scanning
786 * with a scan configuration supplied in a user scan configuration structure.
787 * This structure is used as the basis of one or many scan command configuration
788 * commands that are sent to the command processing module and eventually to the
789 * firmware.
790 *
791 * This function creates a scan command configuration structure based on the
792 * following user supplied parameters (if present):
793 * - SSID filter
794 * - BSSID filter
795 * - Number of Probes to be sent
796 * - Channel list
797 *
798 * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
799 * If the number of probes is not set, adapter default setting is used.
800 */
801static void
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700802mwifiex_config_scan(struct mwifiex_private *priv,
803 const struct mwifiex_user_scan_cfg *user_scan_in,
804 struct mwifiex_scan_cmd_config *scan_cfg_out,
805 struct mwifiex_ie_types_chan_list_param_set **chan_list_out,
806 struct mwifiex_chan_scan_param_set *scan_chan_list,
807 u8 *max_chan_per_scan, u8 *filtered_scan,
808 u8 *scan_current_only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700809{
810 struct mwifiex_adapter *adapter = priv->adapter;
811 struct mwifiex_ie_types_num_probes *num_probes_tlv;
Avinash Patilcb91be82014-09-12 20:08:54 +0530812 struct mwifiex_ie_types_scan_chan_gap *chan_gap_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700813 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800814 struct mwifiex_ie_types_bssid_list *bssid_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700815 u8 *tlv_pos;
816 u32 num_probes;
817 u32 ssid_len;
818 u32 chan_idx;
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700819 u32 chan_num;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700820 u32 scan_type;
821 u16 scan_dur;
822 u8 channel;
823 u8 radio_type;
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800824 int i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825 u8 ssid_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700826 struct mwifiex_ie_types_htcap *ht_cap;
Aniket Nagarnaik40d74122015-07-16 08:05:21 -0700827 struct mwifiex_ie_types_bss_mode *bss_mode;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700828
829 /* The tlv_buf_len is calculated for each scan command. The TLVs added
830 in this routine will be preserved since the routine that sends the
831 command will append channelTLVs at *chan_list_out. The difference
832 between the *chan_list_out and the tlv_buf start will be used to
833 calculate the size of anything we add in this routine. */
834 scan_cfg_out->tlv_buf_len = 0;
835
836 /* Running tlv pointer. Assigned to chan_list_out at end of function
837 so later routines know where channels can be added to the command
838 buf */
839 tlv_pos = scan_cfg_out->tlv_buf;
840
841 /* Initialize the scan as un-filtered; the flag is later set to TRUE
842 below if a SSID or BSSID filter is sent in the command */
843 *filtered_scan = false;
844
845 /* Initialize the scan as not being only on the current channel. If
846 the channel list is customized, only contains one channel, and is
847 the active channel, this is set true and data flow is not halted. */
848 *scan_current_only = false;
849
850 if (user_scan_in) {
851
852 /* Default the ssid_filter flag to TRUE, set false under
853 certain wildcard conditions and qualified by the existence
854 of an SSID list before marking the scan as filtered */
855 ssid_filter = true;
856
857 /* Set the BSS type scan filter, use Adapter setting if
858 unset */
859 scan_cfg_out->bss_mode =
860 (user_scan_in->bss_mode ? (u8) user_scan_in->
861 bss_mode : (u8) adapter->scan_mode);
862
863 /* Set the number of probes to send, use Adapter setting
864 if unset */
865 num_probes =
866 (user_scan_in->num_probes ? user_scan_in->
867 num_probes : adapter->scan_probes);
868
869 /*
870 * Set the BSSID filter to the incoming configuration,
871 * if non-zero. If not set, it will remain disabled
872 * (all zeros).
873 */
874 memcpy(scan_cfg_out->specific_bssid,
875 user_scan_in->specific_bssid,
876 sizeof(scan_cfg_out->specific_bssid));
877
Amitkumar Karwar21f58d202014-02-11 18:39:56 -0800878 if (adapter->ext_scan &&
879 !is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
880 bssid_tlv =
881 (struct mwifiex_ie_types_bssid_list *)tlv_pos;
882 bssid_tlv->header.type = cpu_to_le16(TLV_TYPE_BSSID);
883 bssid_tlv->header.len = cpu_to_le16(ETH_ALEN);
884 memcpy(bssid_tlv->bssid, user_scan_in->specific_bssid,
885 ETH_ALEN);
886 tlv_pos += sizeof(struct mwifiex_ie_types_bssid_list);
887 }
888
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800889 for (i = 0; i < user_scan_in->num_ssids; i++) {
890 ssid_len = user_scan_in->ssid_list[i].ssid_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700891
892 wildcard_ssid_tlv =
893 (struct mwifiex_ie_types_wildcard_ssid_params *)
894 tlv_pos;
895 wildcard_ssid_tlv->header.type =
896 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
897 wildcard_ssid_tlv->header.len = cpu_to_le16(
898 (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
899 max_ssid_length)));
Amitkumar Karwarfada1052011-11-09 21:36:21 -0800900
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800901 /*
902 * max_ssid_length = 0 tells firmware to perform
903 * specific scan for the SSID filled, whereas
904 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
905 * wildcard scan.
906 */
907 if (ssid_len)
908 wildcard_ssid_tlv->max_ssid_length = 0;
909 else
910 wildcard_ssid_tlv->max_ssid_length =
911 IEEE80211_MAX_SSID_LEN;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700912
Aniket Nagarnaik0c6303c2015-07-16 08:05:22 -0700913 if (!memcmp(user_scan_in->ssid_list[i].ssid,
914 "DIRECT-", 7))
915 wildcard_ssid_tlv->max_ssid_length = 0xfe;
916
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700917 memcpy(wildcard_ssid_tlv->ssid,
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -0800918 user_scan_in->ssid_list[i].ssid, ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700919
920 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
921 + le16_to_cpu(wildcard_ssid_tlv->header.len));
922
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530923 mwifiex_dbg(adapter, INFO,
924 "info: scan: ssid[%d]: %s, %d\n",
925 i, wildcard_ssid_tlv->ssid,
926 wildcard_ssid_tlv->max_ssid_length);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700927
928 /* Empty wildcard ssid with a maxlen will match many or
929 potentially all SSIDs (maxlen == 32), therefore do
930 not treat the scan as
931 filtered. */
932 if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
933 ssid_filter = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700934 }
935
936 /*
937 * The default number of channels sent in the command is low to
938 * ensure the response buffer from the firmware does not
939 * truncate scan results. That is not an issue with an SSID
940 * or BSSID filter applied to the scan results in the firmware.
941 */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -0700942 if ((i && ssid_filter) ||
Bing Zhao84f6a952012-08-27 20:32:54 -0700943 !is_zero_ether_addr(scan_cfg_out->specific_bssid))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700944 *filtered_scan = true;
Avinash Patil8eda10e2014-09-17 23:01:26 +0530945
946 if (user_scan_in->scan_chan_gap) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530947 mwifiex_dbg(adapter, INFO,
948 "info: scan: channel gap = %d\n",
949 user_scan_in->scan_chan_gap);
Avinash Patil8eda10e2014-09-17 23:01:26 +0530950 *max_chan_per_scan =
951 MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
952
953 chan_gap_tlv = (void *)tlv_pos;
954 chan_gap_tlv->header.type =
955 cpu_to_le16(TLV_TYPE_SCAN_CHANNEL_GAP);
956 chan_gap_tlv->header.len =
957 cpu_to_le16(sizeof(chan_gap_tlv->chan_gap));
958 chan_gap_tlv->chan_gap =
959 cpu_to_le16((user_scan_in->scan_chan_gap));
960 tlv_pos +=
961 sizeof(struct mwifiex_ie_types_scan_chan_gap);
962 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700963 } else {
964 scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
965 num_probes = adapter->scan_probes;
966 }
967
968 /*
969 * If a specific BSSID or SSID is used, the number of channels in the
970 * scan command will be increased to the absolute maximum.
971 */
972 if (*filtered_scan)
973 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
974 else
Amitkumar Karwar658f37b2012-06-06 21:12:42 -0700975 *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700976
Aniket Nagarnaik40d74122015-07-16 08:05:21 -0700977 if (adapter->ext_scan) {
978 bss_mode = (struct mwifiex_ie_types_bss_mode *)tlv_pos;
979 bss_mode->header.type = cpu_to_le16(TLV_TYPE_BSS_MODE);
980 bss_mode->header.len = cpu_to_le16(sizeof(bss_mode->bss_mode));
981 bss_mode->bss_mode = scan_cfg_out->bss_mode;
982 tlv_pos += sizeof(bss_mode->header) +
983 le16_to_cpu(bss_mode->header.len);
984 }
985
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700986 /* If the input config or adapter has the number of Probes set,
987 add tlv */
988 if (num_probes) {
989
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530990 mwifiex_dbg(adapter, INFO,
991 "info: scan: num_probes = %d\n",
992 num_probes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993
994 num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
995 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
996 num_probes_tlv->header.len =
997 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
998 num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
999
1000 tlv_pos += sizeof(num_probes_tlv->header) +
1001 le16_to_cpu(num_probes_tlv->header.len);
1002
1003 }
1004
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001005 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
1006 (priv->adapter->config_bands & BAND_GN ||
1007 priv->adapter->config_bands & BAND_AN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001008 ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
1009 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
1010 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1011 ht_cap->header.len =
1012 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
Amitkumar Karwara46b7b52011-04-27 19:13:12 -07001013 radio_type =
1014 mwifiex_band_to_radio_type(priv->adapter->config_bands);
Amitkumar Karwar341b8802014-02-07 16:27:31 -08001015 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016 tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
1017 }
1018
1019 /* Append vendor specific IE TLV */
1020 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
1021
1022 /*
1023 * Set the output for the channel TLV to the address in the tlv buffer
1024 * past any TLVs that were added in this function (SSID, num_probes).
1025 * Channel TLVs will be added past this for each scan command,
1026 * preserving the TLVs that were previously added.
1027 */
1028 *chan_list_out =
1029 (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
1030
1031 if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
1032
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301033 mwifiex_dbg(adapter, INFO,
1034 "info: Scan: Using supplied channel list\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035
1036 for (chan_idx = 0;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001037 chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX &&
1038 user_scan_in->chan_list[chan_idx].chan_number;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039 chan_idx++) {
1040
1041 channel = user_scan_in->chan_list[chan_idx].chan_number;
1042 (scan_chan_list + chan_idx)->chan_number = channel;
1043
1044 radio_type =
1045 user_scan_in->chan_list[chan_idx].radio_type;
1046 (scan_chan_list + chan_idx)->radio_type = radio_type;
1047
1048 scan_type = user_scan_in->chan_list[chan_idx].scan_type;
1049
1050 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1051 (scan_chan_list +
1052 chan_idx)->chan_scan_mode_bitmap
chunfan chen2375fa22015-08-05 06:09:42 -07001053 |= (MWIFIEX_PASSIVE_SCAN |
1054 MWIFIEX_HIDDEN_SSID_REPORT);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001055 else
1056 (scan_chan_list +
1057 chan_idx)->chan_scan_mode_bitmap
1058 &= ~MWIFIEX_PASSIVE_SCAN;
1059
Amitkumar Karwarf3e1af32012-10-19 19:19:18 -07001060 if (*filtered_scan)
1061 (scan_chan_list +
1062 chan_idx)->chan_scan_mode_bitmap
1063 |= MWIFIEX_DISABLE_CHAN_FILT;
1064
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001065 if (user_scan_in->chan_list[chan_idx].scan_time) {
1066 scan_dur = (u16) user_scan_in->
1067 chan_list[chan_idx].scan_time;
1068 } else {
1069 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1070 scan_dur = adapter->passive_scan_time;
1071 else if (*filtered_scan)
1072 scan_dur = adapter->specific_scan_time;
1073 else
1074 scan_dur = adapter->active_scan_time;
1075 }
1076
1077 (scan_chan_list + chan_idx)->min_scan_time =
1078 cpu_to_le16(scan_dur);
1079 (scan_chan_list + chan_idx)->max_scan_time =
1080 cpu_to_le16(scan_dur);
1081 }
1082
1083 /* Check if we are only scanning the current channel */
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001084 if ((chan_idx == 1) &&
1085 (user_scan_in->chan_list[0].chan_number ==
1086 priv->curr_bss_params.bss_descriptor.channel)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001087 *scan_current_only = true;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301088 mwifiex_dbg(adapter, INFO,
1089 "info: Scan: Scanning current channel only\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001090 }
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001091 chan_num = chan_idx;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001092 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301093 mwifiex_dbg(adapter, INFO,
1094 "info: Scan: Creating full region channel list\n");
Amitkumar Karwar658f37b2012-06-06 21:12:42 -07001095 chan_num = mwifiex_scan_create_channel_list(priv, user_scan_in,
1096 scan_chan_list,
1097 *filtered_scan);
1098 }
1099
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001100}
1101
1102/*
1103 * This function inspects the scan response buffer for pointers to
1104 * expected TLVs.
1105 *
1106 * TLVs can be included at the end of the scan response BSS information.
1107 *
1108 * Data in the buffer is parsed pointers to TLVs that can potentially
1109 * be passed back in the response.
1110 */
1111static void
1112mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
1113 struct mwifiex_ie_types_data *tlv,
1114 u32 tlv_buf_size, u32 req_tlv_type,
1115 struct mwifiex_ie_types_data **tlv_data)
1116{
1117 struct mwifiex_ie_types_data *current_tlv;
1118 u32 tlv_buf_left;
1119 u32 tlv_type;
1120 u32 tlv_len;
1121
1122 current_tlv = tlv;
1123 tlv_buf_left = tlv_buf_size;
1124 *tlv_data = NULL;
1125
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301126 mwifiex_dbg(adapter, INFO,
1127 "info: SCAN_RESP: tlv_buf_size = %d\n",
1128 tlv_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001129
1130 while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
1131
1132 tlv_type = le16_to_cpu(current_tlv->header.type);
1133 tlv_len = le16_to_cpu(current_tlv->header.len);
1134
1135 if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301136 mwifiex_dbg(adapter, ERROR,
1137 "SCAN_RESP: TLV buffer corrupt\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001138 break;
1139 }
1140
1141 if (req_tlv_type == tlv_type) {
1142 switch (tlv_type) {
1143 case TLV_TYPE_TSFTIMESTAMP:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301144 mwifiex_dbg(adapter, INFO,
1145 "info: SCAN_RESP: TSF\t"
1146 "timestamp TLV, len = %d\n",
1147 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001148 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149 break;
1150 case TLV_TYPE_CHANNELBANDLIST:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301151 mwifiex_dbg(adapter, INFO,
1152 "info: SCAN_RESP: channel\t"
1153 "band list TLV, len = %d\n",
1154 tlv_len);
Joe Perches2c208892012-06-04 12:44:17 +00001155 *tlv_data = current_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001156 break;
1157 default:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301158 mwifiex_dbg(adapter, ERROR,
1159 "SCAN_RESP: unhandled TLV = %d\n",
1160 tlv_type);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161 /* Give up, this seems corrupted */
1162 return;
1163 }
1164 }
1165
1166 if (*tlv_data)
1167 break;
1168
1169
1170 tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
1171 current_tlv =
1172 (struct mwifiex_ie_types_data *) (current_tlv->data +
1173 tlv_len);
1174
1175 } /* while */
1176}
1177
1178/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001179 * This function parses provided beacon buffer and updates
1180 * respective fields in bss descriptor structure.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001181 */
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001182int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1183 struct mwifiex_bssdescriptor *bss_entry)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001184{
1185 int ret = 0;
1186 u8 element_id;
1187 struct ieee_types_fh_param_set *fh_param_set;
1188 struct ieee_types_ds_param_set *ds_param_set;
1189 struct ieee_types_cf_param_set *cf_param_set;
1190 struct ieee_types_ibss_param_set *ibss_param_set;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001191 u8 *current_ptr;
1192 u8 *rate;
1193 u8 element_len;
1194 u16 total_ie_len;
1195 u8 bytes_to_copy;
1196 u8 rate_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197 u8 found_data_rate_ie;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001198 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199 struct ieee_types_vendor_specific *vendor_ie;
1200 const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
1201 const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
1202
1203 found_data_rate_ie = false;
1204 rate_size = 0;
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001205 current_ptr = bss_entry->beacon_buf;
1206 bytes_left = bss_entry->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207
1208 /* Process variable IE */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001209 while (bytes_left >= 2) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001210 element_id = *current_ptr;
1211 element_len = *(current_ptr + 1);
1212 total_ie_len = element_len + sizeof(struct ieee_types_header);
1213
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001214 if (bytes_left < total_ie_len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301215 mwifiex_dbg(adapter, ERROR,
1216 "err: InterpretIE: in processing\t"
1217 "IE, bytes left < IE length\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001218 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001219 }
1220 switch (element_id) {
1221 case WLAN_EID_SSID:
1222 bss_entry->ssid.ssid_len = element_len;
1223 memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
1224 element_len);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301225 mwifiex_dbg(adapter, INFO,
1226 "info: InterpretIE: ssid: %-32s\n",
1227 bss_entry->ssid.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001228 break;
1229
1230 case WLAN_EID_SUPP_RATES:
1231 memcpy(bss_entry->data_rates, current_ptr + 2,
1232 element_len);
1233 memcpy(bss_entry->supported_rates, current_ptr + 2,
1234 element_len);
1235 rate_size = element_len;
1236 found_data_rate_ie = true;
1237 break;
1238
1239 case WLAN_EID_FH_PARAMS:
1240 fh_param_set =
1241 (struct ieee_types_fh_param_set *) current_ptr;
1242 memcpy(&bss_entry->phy_param_set.fh_param_set,
1243 fh_param_set,
1244 sizeof(struct ieee_types_fh_param_set));
1245 break;
1246
1247 case WLAN_EID_DS_PARAMS:
1248 ds_param_set =
1249 (struct ieee_types_ds_param_set *) current_ptr;
1250
1251 bss_entry->channel = ds_param_set->current_chan;
1252
1253 memcpy(&bss_entry->phy_param_set.ds_param_set,
1254 ds_param_set,
1255 sizeof(struct ieee_types_ds_param_set));
1256 break;
1257
1258 case WLAN_EID_CF_PARAMS:
1259 cf_param_set =
1260 (struct ieee_types_cf_param_set *) current_ptr;
1261 memcpy(&bss_entry->ss_param_set.cf_param_set,
1262 cf_param_set,
1263 sizeof(struct ieee_types_cf_param_set));
1264 break;
1265
1266 case WLAN_EID_IBSS_PARAMS:
1267 ibss_param_set =
1268 (struct ieee_types_ibss_param_set *)
1269 current_ptr;
1270 memcpy(&bss_entry->ss_param_set.ibss_param_set,
1271 ibss_param_set,
1272 sizeof(struct ieee_types_ibss_param_set));
1273 break;
1274
1275 case WLAN_EID_ERP_INFO:
1276 bss_entry->erp_flags = *(current_ptr + 2);
1277 break;
1278
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -07001279 case WLAN_EID_PWR_CONSTRAINT:
1280 bss_entry->local_constraint = *(current_ptr + 2);
1281 bss_entry->sensed_11h = true;
1282 break;
1283
1284 case WLAN_EID_CHANNEL_SWITCH:
1285 bss_entry->chan_sw_ie_present = true;
1286 case WLAN_EID_PWR_CAPABILITY:
1287 case WLAN_EID_TPC_REPORT:
1288 case WLAN_EID_QUIET:
1289 bss_entry->sensed_11h = true;
1290 break;
1291
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001292 case WLAN_EID_EXT_SUPP_RATES:
1293 /*
1294 * Only process extended supported rate
1295 * if data rate is already found.
1296 * Data rate IE should come before
1297 * extended supported rate IE
1298 */
1299 if (found_data_rate_ie) {
1300 if ((element_len + rate_size) >
1301 MWIFIEX_SUPPORTED_RATES)
1302 bytes_to_copy =
1303 (MWIFIEX_SUPPORTED_RATES -
1304 rate_size);
1305 else
1306 bytes_to_copy = element_len;
1307
1308 rate = (u8 *) bss_entry->data_rates;
1309 rate += rate_size;
1310 memcpy(rate, current_ptr + 2, bytes_to_copy);
1311
1312 rate = (u8 *) bss_entry->supported_rates;
1313 rate += rate_size;
1314 memcpy(rate, current_ptr + 2, bytes_to_copy);
1315 }
1316 break;
1317
1318 case WLAN_EID_VENDOR_SPECIFIC:
1319 vendor_ie = (struct ieee_types_vendor_specific *)
1320 current_ptr;
1321
1322 if (!memcmp
1323 (vendor_ie->vend_hdr.oui, wpa_oui,
1324 sizeof(wpa_oui))) {
1325 bss_entry->bcn_wpa_ie =
1326 (struct ieee_types_vendor_specific *)
1327 current_ptr;
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001328 bss_entry->wpa_offset = (u16)
1329 (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001330 } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui,
1331 sizeof(wmm_oui))) {
1332 if (total_ie_len ==
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001333 sizeof(struct ieee_types_wmm_parameter) ||
1334 total_ie_len ==
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001335 sizeof(struct ieee_types_wmm_info))
1336 /*
1337 * Only accept and copy the WMM IE if
1338 * it matches the size expected for the
1339 * WMM Info IE or the WMM Parameter IE.
1340 */
1341 memcpy((u8 *) &bss_entry->wmm_ie,
1342 current_ptr, total_ie_len);
1343 }
1344 break;
1345 case WLAN_EID_RSN:
1346 bss_entry->bcn_rsn_ie =
1347 (struct ieee_types_generic *) current_ptr;
1348 bss_entry->rsn_offset = (u16) (current_ptr -
1349 bss_entry->beacon_buf);
1350 break;
1351 case WLAN_EID_BSS_AC_ACCESS_DELAY:
1352 bss_entry->bcn_wapi_ie =
1353 (struct ieee_types_generic *) current_ptr;
1354 bss_entry->wapi_offset = (u16) (current_ptr -
1355 bss_entry->beacon_buf);
1356 break;
1357 case WLAN_EID_HT_CAPABILITY:
1358 bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
1359 (current_ptr +
1360 sizeof(struct ieee_types_header));
1361 bss_entry->ht_cap_offset = (u16) (current_ptr +
1362 sizeof(struct ieee_types_header) -
1363 bss_entry->beacon_buf);
1364 break;
Johannes Berg074d46d2012-03-15 19:45:16 +01001365 case WLAN_EID_HT_OPERATION:
1366 bss_entry->bcn_ht_oper =
1367 (struct ieee80211_ht_operation *)(current_ptr +
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001368 sizeof(struct ieee_types_header));
1369 bss_entry->ht_info_offset = (u16) (current_ptr +
1370 sizeof(struct ieee_types_header) -
1371 bss_entry->beacon_buf);
1372 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001373 case WLAN_EID_VHT_CAPABILITY:
1374 bss_entry->disable_11ac = false;
1375 bss_entry->bcn_vht_cap =
1376 (void *)(current_ptr +
1377 sizeof(struct ieee_types_header));
1378 bss_entry->vht_cap_offset =
1379 (u16)((u8 *)bss_entry->bcn_vht_cap -
1380 bss_entry->beacon_buf);
1381 break;
1382 case WLAN_EID_VHT_OPERATION:
1383 bss_entry->bcn_vht_oper =
1384 (void *)(current_ptr +
1385 sizeof(struct ieee_types_header));
1386 bss_entry->vht_info_offset =
1387 (u16)((u8 *)bss_entry->bcn_vht_oper -
1388 bss_entry->beacon_buf);
1389 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001390 case WLAN_EID_BSS_COEX_2040:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001391 bss_entry->bcn_bss_co_2040 = current_ptr;
1392 bss_entry->bss_co_2040_offset =
1393 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001394 break;
1395 case WLAN_EID_EXT_CAPABILITY:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001396 bss_entry->bcn_ext_cap = current_ptr;
1397 bss_entry->ext_cap_offset =
1398 (u16) (current_ptr - bss_entry->beacon_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001399 break;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001400 case WLAN_EID_OPMODE_NOTIF:
Amitkumar Karwarcf831ff2014-04-16 22:01:53 -07001401 bss_entry->oper_mode = (void *)current_ptr;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001402 bss_entry->oper_mode_offset =
1403 (u16)((u8 *)bss_entry->oper_mode -
1404 bss_entry->beacon_buf);
1405 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001406 default:
1407 break;
1408 }
1409
1410 current_ptr += element_len + 2;
1411
1412 /* Need to account for IE ID and IE Len */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001413 bytes_left -= (element_len + 2);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001414
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001415 } /* while (bytes_left > 2) */
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001416 return ret;
1417}
1418
1419/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420 * This function converts radio type scan parameter to a band configuration
1421 * to be used in join command.
1422 */
1423static u8
1424mwifiex_radio_type_to_band(u8 radio_type)
1425{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001426 switch (radio_type) {
1427 case HostCmd_SCAN_RADIO_TYPE_A:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001428 return BAND_A;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001429 case HostCmd_SCAN_RADIO_TYPE_BG:
1430 default:
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001431 return BAND_G;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001432 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001433}
1434
1435/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001436 * This is an internal function used to start a scan based on an input
1437 * configuration.
1438 *
1439 * This uses the input user scan configuration information when provided in
1440 * order to send the appropriate scan commands to firmware to populate or
1441 * update the internal driver scan table.
1442 */
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001443int mwifiex_scan_networks(struct mwifiex_private *priv,
1444 const struct mwifiex_user_scan_cfg *user_scan_in)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001445{
Bing Zhaoc2476332012-10-05 20:21:40 -07001446 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001447 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001448 struct cmd_ctrl_node *cmd_node;
1449 union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001450 struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001451 struct mwifiex_chan_scan_param_set *scan_chan_list;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001452 u8 filtered_scan;
1453 u8 scan_current_chan_only;
1454 u8 max_chan_per_scan;
1455 unsigned long flags;
1456
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001457 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301458 mwifiex_dbg(adapter, WARN,
1459 "cmd: Scan already in process...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001460 return -EBUSY;
1461 }
1462
1463 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301464 mwifiex_dbg(adapter, WARN,
1465 "cmd: Scan is blocked during association...\n");
Bing Zhaoc2476332012-10-05 20:21:40 -07001466 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001467 }
1468
Amitkumar Karware00483f2015-01-07 03:57:39 -08001469 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301470 mwifiex_dbg(adapter, ERROR,
1471 "Ignore scan. Card removed or firmware in bad state\n");
Amitkumar Karware00483f2015-01-07 03:57:39 -08001472 return -EFAULT;
1473 }
1474
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001475 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1476 adapter->scan_processing = true;
1477 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1478
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001479 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
Joe Perches0d2e7a52013-02-03 17:28:14 +00001480 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001481 if (!scan_cfg_out) {
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001482 ret = -ENOMEM;
1483 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001484 }
1485
Joe Perches0d2e7a52013-02-03 17:28:14 +00001486 scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
1487 sizeof(struct mwifiex_chan_scan_param_set),
1488 GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001489 if (!scan_chan_list) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001490 kfree(scan_cfg_out);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001491 ret = -ENOMEM;
1492 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001493 }
1494
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001495 mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config,
1496 &chan_list_out, scan_chan_list, &max_chan_per_scan,
1497 &filtered_scan, &scan_current_chan_only);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001498
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001499 ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
1500 &scan_cfg_out->config, chan_list_out,
1501 scan_chan_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001502
1503 /* Get scan command from scan_pending_q and put to cmd_pending_q */
1504 if (!ret) {
1505 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1506 if (!list_empty(&adapter->scan_pending_q)) {
1507 cmd_node = list_first_entry(&adapter->scan_pending_q,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001508 struct cmd_ctrl_node, list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001509 list_del(&cmd_node->list);
1510 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001511 flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001512 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1513 true);
Amitkumar Karwar1a1fb972012-06-27 19:57:56 -07001514 queue_work(adapter->workqueue, &adapter->main_work);
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001515
1516 /* Perform internal scan synchronously */
Bing Zhao21de9792013-04-01 12:44:45 -07001517 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301518 mwifiex_dbg(adapter, INFO,
1519 "wait internal scan\n");
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -07001520 mwifiex_wait_queue_complete(adapter, cmd_node);
Bing Zhao21de9792013-04-01 12:44:45 -07001521 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001522 } else {
1523 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1524 flags);
1525 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001526 }
1527
1528 kfree(scan_cfg_out);
1529 kfree(scan_chan_list);
Amitkumar Karwar061f2e62012-10-05 20:21:41 -07001530done:
1531 if (ret) {
1532 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1533 adapter->scan_processing = false;
1534 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1535 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001536 return ret;
1537}
1538
1539/*
1540 * This function prepares a scan command to be sent to the firmware.
1541 *
1542 * This uses the scan command configuration sent to the command processing
1543 * module in command preparation stage to configure a scan command structure
1544 * to send to firmware.
1545 *
1546 * The fixed fields specifying the BSS type and BSSID filters as well as a
1547 * variable number/length of TLVs are sent in the command to firmware.
1548 *
1549 * Preparation also includes -
1550 * - Setting command ID, and proper size
1551 * - Ensuring correct endian-ness
1552 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001553int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1554 struct mwifiex_scan_cmd_config *scan_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001555{
1556 struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001557
1558 /* Set fixed field variables in scan command */
1559 scan_cmd->bss_mode = scan_cfg->bss_mode;
1560 memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
1561 sizeof(scan_cmd->bssid));
1562 memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
1563
1564 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
1565
1566 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
1567 cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
1568 + sizeof(scan_cmd->bssid)
1569 + scan_cfg->tlv_buf_len + S_DS_GEN));
1570
1571 return 0;
1572}
1573
1574/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001575 * This function checks compatibility of requested network with current
1576 * driver settings.
1577 */
1578int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1579 struct mwifiex_bssdescriptor *bss_desc)
1580{
1581 int ret = -1;
1582
1583 if (!bss_desc)
1584 return -1;
1585
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -07001586 if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
1587 (u16) bss_desc->channel, 0))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001588 switch (priv->bss_mode) {
1589 case NL80211_IFTYPE_STATION:
1590 case NL80211_IFTYPE_ADHOC:
1591 ret = mwifiex_is_network_compatible(priv, bss_desc,
1592 priv->bss_mode);
1593 if (ret)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301594 mwifiex_dbg(priv->adapter, ERROR,
1595 "Incompatible network settings\n");
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001596 break;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001597 default:
Fengguang Wu2f9279b2012-08-07 10:26:53 +08001598 ret = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001599 }
1600 }
1601
1602 return ret;
1603}
1604
chunfan chen2375fa22015-08-05 06:09:42 -07001605/* This function checks if SSID string contains all zeroes or length is zero */
1606static bool mwifiex_is_hidden_ssid(struct cfg80211_ssid *ssid)
1607{
1608 int idx;
1609
1610 for (idx = 0; idx < ssid->ssid_len; idx++) {
1611 if (ssid->ssid[idx])
1612 return false;
1613 }
1614
1615 return true;
1616}
1617
1618/* This function checks if any hidden SSID found in passive scan channels
1619 * and save those channels for specific SSID active scan
1620 */
1621static int mwifiex_save_hidden_ssid_channels(struct mwifiex_private *priv,
1622 struct cfg80211_bss *bss)
1623{
1624 struct mwifiex_bssdescriptor *bss_desc;
1625 int ret;
1626 int chid;
1627
1628 /* Allocate and fill new bss descriptor */
1629 bss_desc = kzalloc(sizeof(*bss_desc), GFP_KERNEL);
1630 if (!bss_desc)
1631 return -ENOMEM;
1632
1633 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
1634 if (ret)
1635 goto done;
1636
1637 if (mwifiex_is_hidden_ssid(&bss_desc->ssid)) {
1638 mwifiex_dbg(priv->adapter, INFO, "found hidden SSID\n");
1639 for (chid = 0 ; chid < MWIFIEX_USER_SCAN_CHAN_MAX; chid++) {
1640 if (priv->hidden_chan[chid].chan_number ==
1641 bss->channel->hw_value)
1642 break;
1643
1644 if (!priv->hidden_chan[chid].chan_number) {
1645 priv->hidden_chan[chid].chan_number =
1646 bss->channel->hw_value;
1647 priv->hidden_chan[chid].radio_type =
1648 bss->channel->band;
1649 priv->hidden_chan[chid].scan_type =
1650 MWIFIEX_SCAN_TYPE_ACTIVE;
1651 break;
1652 }
1653 }
1654 }
1655
1656done:
1657 kfree(bss_desc);
1658 return 0;
1659}
1660
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001661static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1662 struct cfg80211_bss *bss)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001663{
Jesper Juhldb652e42011-11-06 22:58:31 +01001664 struct mwifiex_bssdescriptor *bss_desc;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001665 int ret;
1666 unsigned long flags;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001667
1668 /* Allocate and fill new bss descriptor */
Joe Perches0d2e7a52013-02-03 17:28:14 +00001669 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
1670 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001671 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07001672
Amitkumar Karwar9558a402012-04-16 21:36:51 -07001673 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001674 if (ret)
1675 goto done;
1676
1677 ret = mwifiex_check_network_compatibility(priv, bss_desc);
1678 if (ret)
1679 goto done;
1680
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001681 spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001682 /* Make a copy of current BSSID descriptor */
1683 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07001684 sizeof(priv->curr_bss_params.bss_descriptor));
Bing Zhaod837a2a2013-04-12 10:34:17 -07001685
1686 /* The contents of beacon_ie will be copied to its own buffer
1687 * in mwifiex_save_curr_bcn()
1688 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001689 mwifiex_save_curr_bcn(priv);
1690 spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
1691
1692done:
Bing Zhaod837a2a2013-04-12 10:34:17 -07001693 /* beacon_ie buffer was allocated in function
1694 * mwifiex_fill_new_bss_desc(). Free it now.
1695 */
1696 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001697 kfree(bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001698 return 0;
1699}
1700
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001701static int
1702mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info,
1703 u32 *bytes_left, u64 fw_tsf, u8 *radio_type,
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001704 bool ext_scan, s32 rssi_val)
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001705{
1706 struct mwifiex_adapter *adapter = priv->adapter;
1707 struct mwifiex_chan_freq_power *cfp;
1708 struct cfg80211_bss *bss;
1709 u8 bssid[ETH_ALEN];
1710 s32 rssi;
1711 const u8 *ie_buf;
1712 size_t ie_len;
1713 u16 channel = 0;
1714 u16 beacon_size = 0;
1715 u32 curr_bcn_bytes;
1716 u32 freq;
1717 u16 beacon_period;
1718 u16 cap_info_bitmap;
1719 u8 *current_ptr;
1720 u64 timestamp;
1721 struct mwifiex_fixed_bcn_param *bcn_param;
1722 struct mwifiex_bss_priv *bss_priv;
1723
1724 if (*bytes_left >= sizeof(beacon_size)) {
1725 /* Extract & convert beacon size from command buffer */
Amitkumar Karwar798ea8e2014-11-25 06:43:03 -08001726 beacon_size = le16_to_cpu(*(__le16 *)(*bss_info));
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001727 *bytes_left -= sizeof(beacon_size);
1728 *bss_info += sizeof(beacon_size);
1729 }
1730
1731 if (!beacon_size || beacon_size > *bytes_left) {
1732 *bss_info += *bytes_left;
1733 *bytes_left = 0;
1734 return -EFAULT;
1735 }
1736
1737 /* Initialize the current working beacon pointer for this BSS
1738 * iteration
1739 */
1740 current_ptr = *bss_info;
1741
1742 /* Advance the return beacon pointer past the current beacon */
1743 *bss_info += beacon_size;
1744 *bytes_left -= beacon_size;
1745
1746 curr_bcn_bytes = beacon_size;
1747
1748 /* First 5 fields are bssid, RSSI(for legacy scan only),
1749 * time stamp, beacon interval, and capability information
1750 */
1751 if (curr_bcn_bytes < ETH_ALEN + sizeof(u8) +
1752 sizeof(struct mwifiex_fixed_bcn_param)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301753 mwifiex_dbg(adapter, ERROR,
1754 "InterpretIE: not enough bytes left\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001755 return -EFAULT;
1756 }
1757
1758 memcpy(bssid, current_ptr, ETH_ALEN);
1759 current_ptr += ETH_ALEN;
1760 curr_bcn_bytes -= ETH_ALEN;
1761
1762 if (!ext_scan) {
Joe Perches45d18c52014-03-24 13:15:39 -07001763 rssi = (s32) *current_ptr;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001764 rssi = (-rssi) * 100; /* Convert dBm to mBm */
1765 current_ptr += sizeof(u8);
1766 curr_bcn_bytes -= sizeof(u8);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301767 mwifiex_dbg(adapter, INFO,
1768 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001769 } else {
1770 rssi = rssi_val;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001771 }
1772
1773 bcn_param = (struct mwifiex_fixed_bcn_param *)current_ptr;
1774 current_ptr += sizeof(*bcn_param);
1775 curr_bcn_bytes -= sizeof(*bcn_param);
1776
1777 timestamp = le64_to_cpu(bcn_param->timestamp);
1778 beacon_period = le16_to_cpu(bcn_param->beacon_period);
1779
1780 cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301781 mwifiex_dbg(adapter, INFO,
1782 "info: InterpretIE: capabilities=0x%X\n",
1783 cap_info_bitmap);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001784
1785 /* Rest of the current buffer are IE's */
1786 ie_buf = current_ptr;
1787 ie_len = curr_bcn_bytes;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301788 mwifiex_dbg(adapter, INFO,
1789 "info: InterpretIE: IELength for this AP = %d\n",
1790 curr_bcn_bytes);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001791
1792 while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) {
1793 u8 element_id, element_len;
1794
1795 element_id = *current_ptr;
1796 element_len = *(current_ptr + 1);
1797 if (curr_bcn_bytes < element_len +
1798 sizeof(struct ieee_types_header)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301799 mwifiex_dbg(adapter, ERROR,
1800 "%s: bytes left < IE length\n", __func__);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001801 return -EFAULT;
1802 }
1803 if (element_id == WLAN_EID_DS_PARAMS) {
1804 channel = *(current_ptr +
1805 sizeof(struct ieee_types_header));
1806 break;
1807 }
1808
1809 current_ptr += element_len + sizeof(struct ieee_types_header);
1810 curr_bcn_bytes -= element_len +
1811 sizeof(struct ieee_types_header);
1812 }
1813
1814 if (channel) {
1815 struct ieee80211_channel *chan;
1816 u8 band;
1817
1818 /* Skip entry if on csa closed channel */
1819 if (channel == priv->csa_chan) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301820 mwifiex_dbg(adapter, WARN,
1821 "Dropping entry on csa closed channel\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001822 return 0;
1823 }
1824
1825 band = BAND_G;
1826 if (radio_type)
1827 band = mwifiex_radio_type_to_band(*radio_type &
1828 (BIT(0) | BIT(1)));
1829
1830 cfp = mwifiex_get_cfp(priv, band, channel, 0);
1831
1832 freq = cfp ? cfp->freq : 0;
1833
Avinash Patil4facc342015-01-28 15:42:00 +05301834 chan = ieee80211_get_channel(priv->wdev.wiphy, freq);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001835
1836 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Avinash Patil4facc342015-01-28 15:42:00 +05301837 bss = cfg80211_inform_bss(priv->wdev.wiphy,
Johannes Berg5bc8c1f2014-08-12 21:01:28 +02001838 chan, CFG80211_BSS_FTYPE_UNKNOWN,
1839 bssid, timestamp,
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001840 cap_info_bitmap, beacon_period,
1841 ie_buf, ie_len, rssi, GFP_KERNEL);
1842 bss_priv = (struct mwifiex_bss_priv *)bss->priv;
1843 bss_priv->band = band;
1844 bss_priv->fw_tsf = fw_tsf;
1845 if (priv->media_connected &&
1846 !memcmp(bssid, priv->curr_bss_params.bss_descriptor
1847 .mac_address, ETH_ALEN))
1848 mwifiex_update_curr_bss_params(priv, bss);
Avinash Patil4facc342015-01-28 15:42:00 +05301849 cfg80211_put_bss(priv->wdev.wiphy, bss);
chunfan chen2375fa22015-08-05 06:09:42 -07001850
1851 if ((chan->flags & IEEE80211_CHAN_RADAR) ||
1852 (chan->flags & IEEE80211_CHAN_NO_IR)) {
1853 mwifiex_dbg(adapter, INFO,
1854 "radar or passive channel %d\n",
1855 channel);
1856 mwifiex_save_hidden_ssid_channels(priv, bss);
1857 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001858 }
1859 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301860 mwifiex_dbg(adapter, WARN, "missing BSS channel IE\n");
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08001861 }
1862
1863 return 0;
1864}
1865
Avinash Patil21445042014-05-27 21:39:32 -07001866static void mwifiex_complete_scan(struct mwifiex_private *priv)
1867{
1868 struct mwifiex_adapter *adapter = priv->adapter;
1869
Avinash Patilbf354432014-10-31 16:08:26 +05301870 adapter->survey_idx = 0;
Avinash Patil21445042014-05-27 21:39:32 -07001871 if (adapter->curr_cmd->wait_q_enabled) {
1872 adapter->cmd_wait_q.status = 0;
1873 if (!priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301874 mwifiex_dbg(adapter, INFO,
1875 "complete internal scan\n");
Avinash Patil21445042014-05-27 21:39:32 -07001876 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1877 }
1878 }
1879}
1880
chunfan chen2375fa22015-08-05 06:09:42 -07001881/* This function checks if any hidden SSID found in passive scan channels
1882 * and do specific SSID active scan for those channels
1883 */
1884static int
1885mwifiex_active_scan_req_for_passive_chan(struct mwifiex_private *priv)
1886{
1887 int ret;
1888 struct mwifiex_adapter *adapter = priv->adapter;
1889 u8 id = 0;
1890 struct mwifiex_user_scan_cfg *user_scan_cfg;
1891
1892 if (adapter->active_scan_triggered) {
1893 adapter->active_scan_triggered = false;
1894 return 0;
1895 }
1896
1897 if (!priv->hidden_chan[0].chan_number) {
1898 mwifiex_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n");
1899 return 0;
1900 }
1901 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1902
1903 if (!user_scan_cfg)
1904 return -ENOMEM;
1905
1906 memset(user_scan_cfg, 0, sizeof(*user_scan_cfg));
1907
1908 for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) {
1909 if (!priv->hidden_chan[id].chan_number)
1910 break;
1911 memcpy(&user_scan_cfg->chan_list[id],
1912 &priv->hidden_chan[id],
1913 sizeof(struct mwifiex_user_scan_chan));
1914 }
1915
1916 adapter->active_scan_triggered = true;
1917 user_scan_cfg->num_ssids = priv->scan_request->n_ssids;
1918 user_scan_cfg->ssid_list = priv->scan_request->ssids;
1919
1920 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1921 kfree(user_scan_cfg);
1922
1923 memset(&priv->hidden_chan, 0, sizeof(priv->hidden_chan));
1924
1925 if (ret) {
1926 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1927 return ret;
1928 }
1929
1930 return 0;
1931}
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001932static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1933{
1934 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karward8d91252014-09-12 20:08:58 +05301935 struct cmd_ctrl_node *cmd_node, *tmp_node;
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001936 unsigned long flags;
1937
1938 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1939 if (list_empty(&adapter->scan_pending_q)) {
1940 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1941 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1942 adapter->scan_processing = false;
1943 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1944
chunfan chen2375fa22015-08-05 06:09:42 -07001945 mwifiex_active_scan_req_for_passive_chan(priv);
1946
Avinash Patil21445042014-05-27 21:39:32 -07001947 if (!adapter->ext_scan)
1948 mwifiex_complete_scan(priv);
1949
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001950 if (priv->scan_request) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301951 mwifiex_dbg(adapter, INFO,
1952 "info: notifying scan done\n");
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001953 cfg80211_scan_done(priv->scan_request, 0);
1954 priv->scan_request = NULL;
1955 } else {
1956 priv->scan_aborting = false;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301957 mwifiex_dbg(adapter, INFO,
1958 "info: scan already aborted\n");
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001959 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05301960 } else if ((priv->scan_aborting && !priv->scan_request) ||
1961 priv->scan_block) {
1962 list_for_each_entry_safe(cmd_node, tmp_node,
1963 &adapter->scan_pending_q, list) {
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001964 list_del(&cmd_node->list);
Amitkumar Karward8d91252014-09-12 20:08:58 +05301965 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001966 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05301967 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1968
1969 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1970 adapter->scan_processing = false;
1971 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1972
chunfan chen2375fa22015-08-05 06:09:42 -07001973 if (!adapter->active_scan_triggered) {
1974 if (priv->scan_request) {
1975 mwifiex_dbg(adapter, INFO,
1976 "info: aborting scan\n");
1977 cfg80211_scan_done(priv->scan_request, 1);
1978 priv->scan_request = NULL;
1979 } else {
1980 priv->scan_aborting = false;
1981 mwifiex_dbg(adapter, INFO,
1982 "info: scan already aborted\n");
1983 }
Amitkumar Karward8d91252014-09-12 20:08:58 +05301984 }
1985 } else {
1986 /* Get scan command from scan_pending_q and put to
1987 * cmd_pending_q
1988 */
1989 cmd_node = list_first_entry(&adapter->scan_pending_q,
1990 struct cmd_ctrl_node, list);
1991 list_del(&cmd_node->list);
1992 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1993 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
Amitkumar Karward44b5c22014-02-07 16:23:36 -08001994 }
1995
1996 return;
1997}
1998
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07001999/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002000 * This function handles the command response of scan.
2001 *
2002 * The response buffer for the scan command has the following
2003 * memory layout:
2004 *
2005 * .-------------------------------------------------------------.
2006 * | Header (4 * sizeof(t_u16)): Standard command response hdr |
2007 * .-------------------------------------------------------------.
2008 * | BufSize (t_u16) : sizeof the BSS Description data |
2009 * .-------------------------------------------------------------.
2010 * | NumOfSet (t_u8) : Number of BSS Descs returned |
2011 * .-------------------------------------------------------------.
2012 * | BSSDescription data (variable, size given in BufSize) |
2013 * .-------------------------------------------------------------.
2014 * | TLV data (variable, size calculated using Header->Size, |
2015 * | BufSize and sizeof the fixed fields above) |
2016 * .-------------------------------------------------------------.
2017 */
2018int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002019 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002020{
2021 int ret = 0;
2022 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002023 struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002024 struct mwifiex_ie_types_data *tlv_data;
2025 struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
2026 u8 *bss_info;
2027 u32 scan_resp_size;
2028 u32 bytes_left;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002029 u32 idx;
2030 u32 tlv_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002031 struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
2032 struct chan_band_param_set *chan_band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002033 u8 is_bgscan_resp;
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002034 __le64 fw_tsf = 0;
2035 u8 *radio_type;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002036
2037 is_bgscan_resp = (le16_to_cpu(resp->command)
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002038 == HostCmd_CMD_802_11_BG_SCAN_QUERY);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002039 if (is_bgscan_resp)
2040 scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
2041 else
2042 scan_rsp = &resp->params.scan_resp;
2043
2044
Bing Zhao67a50032011-07-13 18:38:34 -07002045 if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302046 mwifiex_dbg(adapter, ERROR,
2047 "SCAN_RESP: too many AP returned (%d)\n",
2048 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002049 ret = -1;
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002050 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002051 }
2052
Amitkumar Karwarb8876642013-06-18 16:36:58 -07002053 /* Check csa channel expiry before parsing scan response */
2054 mwifiex_11h_get_csa_closed_channel(priv);
2055
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002056 bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302057 mwifiex_dbg(adapter, INFO,
2058 "info: SCAN_RESP: bss_descript_size %d\n",
2059 bytes_left);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002060
2061 scan_resp_size = le16_to_cpu(resp->size);
2062
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302063 mwifiex_dbg(adapter, INFO,
2064 "info: SCAN_RESP: returned %d APs before parsing\n",
2065 scan_rsp->number_of_sets);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002066
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002067 bss_info = scan_rsp->bss_desc_and_tlv_buffer;
2068
2069 /*
2070 * The size of the TLV buffer is equal to the entire command response
2071 * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
2072 * BSS Descriptions (bss_descript_size as bytesLef) and the command
2073 * response header (S_DS_GEN)
2074 */
2075 tlv_buf_size = scan_resp_size - (bytes_left
2076 + sizeof(scan_rsp->bss_descript_size)
2077 + sizeof(scan_rsp->number_of_sets)
2078 + S_DS_GEN);
2079
2080 tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
2081 bss_desc_and_tlv_buffer +
2082 bytes_left);
2083
2084 /* Search the TLV buffer space in the scan response for any valid
2085 TLVs */
2086 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2087 TLV_TYPE_TSFTIMESTAMP,
2088 (struct mwifiex_ie_types_data **)
2089 &tsf_tlv);
2090
2091 /* Search the TLV buffer space in the scan response for any valid
2092 TLVs */
2093 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2094 TLV_TYPE_CHANNELBANDLIST,
2095 (struct mwifiex_ie_types_data **)
2096 &chan_band_tlv);
2097
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002098 for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002099 /*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002100 * If the TSF TLV was appended to the scan results, save this
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002101 * entry's TSF value in the fw_tsf field. It is the firmware's
2102 * TSF value at the time the beacon or probe response was
2103 * received.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002104 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002105 if (tsf_tlv)
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -07002106 memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
2107 sizeof(fw_tsf));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002108
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002109 if (chan_band_tlv) {
2110 chan_band = &chan_band_tlv->chan_band_param[idx];
2111 radio_type = &chan_band->radio_type;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002112 } else {
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002113 radio_type = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002114 }
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002115
2116 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2117 &bytes_left,
2118 le64_to_cpu(fw_tsf),
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002119 radio_type, false, 0);
Amitkumar Karwar3b4d5c62014-02-07 16:23:35 -08002120 if (ret)
2121 goto check_next_scan;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002122 }
2123
Bing Zhao8a7d7cb2013-01-29 14:38:02 -08002124check_next_scan:
Amitkumar Karward44b5c22014-02-07 16:23:36 -08002125 mwifiex_check_next_scan_command(priv);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002126 return ret;
2127}
2128
2129/*
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002130 * This function prepares an extended scan command to be sent to the firmware
2131 *
2132 * This uses the scan command configuration sent to the command processing
2133 * module in command preparation stage to configure a extended scan command
2134 * structure to send to firmware.
2135 */
2136int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
2137 struct host_cmd_ds_command *cmd,
2138 void *data_buf)
2139{
2140 struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan;
2141 struct mwifiex_scan_cmd_config *scan_cfg = data_buf;
2142
2143 memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
2144
2145 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT);
2146
2147 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
2148 cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved)
2149 + scan_cfg->tlv_buf_len + S_DS_GEN));
2150
2151 return 0;
2152}
2153
Avinash Patilbf354432014-10-31 16:08:26 +05302154static void
2155mwifiex_update_chan_statistics(struct mwifiex_private *priv,
2156 struct mwifiex_ietypes_chanstats *tlv_stat)
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002157{
Avinash Patil3223db22014-09-12 20:08:48 +05302158 struct mwifiex_adapter *adapter = priv->adapter;
Avinash Patilbf354432014-10-31 16:08:26 +05302159 u8 i, num_chan;
2160 struct mwifiex_fw_chan_stats *fw_chan_stats;
2161 struct mwifiex_chan_stats chan_stats;
2162
2163 fw_chan_stats = (void *)((u8 *)tlv_stat +
2164 sizeof(struct mwifiex_ie_types_header));
2165 num_chan = le16_to_cpu(tlv_stat->header.len) /
2166 sizeof(struct mwifiex_chan_stats);
2167
2168 for (i = 0 ; i < num_chan; i++) {
2169 chan_stats.chan_num = fw_chan_stats->chan_num;
2170 chan_stats.bandcfg = fw_chan_stats->bandcfg;
2171 chan_stats.flags = fw_chan_stats->flags;
2172 chan_stats.noise = fw_chan_stats->noise;
2173 chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss);
2174 chan_stats.cca_scan_dur =
2175 le16_to_cpu(fw_chan_stats->cca_scan_dur);
2176 chan_stats.cca_busy_dur =
2177 le16_to_cpu(fw_chan_stats->cca_busy_dur);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302178 mwifiex_dbg(adapter, INFO,
2179 "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n",
2180 chan_stats.chan_num,
2181 chan_stats.noise,
2182 chan_stats.total_bss,
2183 chan_stats.cca_scan_dur,
2184 chan_stats.cca_busy_dur);
Avinash Patilbf354432014-10-31 16:08:26 +05302185 memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats,
2186 sizeof(struct mwifiex_chan_stats));
2187 fw_chan_stats++;
2188 }
2189}
2190
2191/* This function handles the command response of extended scan */
2192int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
2193 struct host_cmd_ds_command *resp)
2194{
2195 struct mwifiex_adapter *adapter = priv->adapter;
2196 struct host_cmd_ds_802_11_scan_ext *ext_scan_resp;
2197 struct mwifiex_ie_types_header *tlv;
2198 struct mwifiex_ietypes_chanstats *tlv_stat;
2199 u16 buf_left, type, len;
2200
Avinash Patil3223db22014-09-12 20:08:48 +05302201 struct host_cmd_ds_command *cmd_ptr;
2202 struct cmd_ctrl_node *cmd_node;
2203 unsigned long cmd_flags, scan_flags;
2204 bool complete_scan = false;
2205
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302206 mwifiex_dbg(adapter, INFO, "info: EXT scan returns successfully\n");
Avinash Patil21445042014-05-27 21:39:32 -07002207
Avinash Patilbf354432014-10-31 16:08:26 +05302208 ext_scan_resp = &resp->params.ext_scan;
2209
2210 tlv = (void *)ext_scan_resp->tlv_buffer;
2211 buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN
2212 - 1);
2213
2214 while (buf_left >= sizeof(struct mwifiex_ie_types_header)) {
2215 type = le16_to_cpu(tlv->type);
2216 len = le16_to_cpu(tlv->len);
2217
2218 if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302219 mwifiex_dbg(adapter, ERROR,
2220 "error processing scan response TLVs");
Avinash Patilbf354432014-10-31 16:08:26 +05302221 break;
2222 }
2223
2224 switch (type) {
2225 case TLV_TYPE_CHANNEL_STATS:
2226 tlv_stat = (void *)tlv;
2227 mwifiex_update_chan_statistics(priv, tlv_stat);
2228 break;
2229 default:
2230 break;
2231 }
2232
2233 buf_left -= len + sizeof(struct mwifiex_ie_types_header);
2234 tlv = (void *)((u8 *)tlv + len +
2235 sizeof(struct mwifiex_ie_types_header));
2236 }
2237
Avinash Patil3223db22014-09-12 20:08:48 +05302238 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
2239 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
2240 if (list_empty(&adapter->scan_pending_q)) {
2241 complete_scan = true;
2242 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
2243 cmd_ptr = (void *)cmd_node->cmd_skb->data;
2244 if (le16_to_cpu(cmd_ptr->command) ==
2245 HostCmd_CMD_802_11_SCAN_EXT) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302246 mwifiex_dbg(adapter, INFO,
2247 "Scan pending in command pending list");
Avinash Patil3223db22014-09-12 20:08:48 +05302248 complete_scan = false;
2249 break;
2250 }
2251 }
2252 }
2253 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags);
2254 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags);
2255
2256 if (complete_scan)
2257 mwifiex_complete_scan(priv);
Avinash Patil21445042014-05-27 21:39:32 -07002258
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002259 return 0;
2260}
2261
2262/* This function This function handles the event extended scan report. It
2263 * parses extended scan results and informs to cfg80211 stack.
2264 */
2265int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
2266 void *buf)
2267{
2268 int ret = 0;
2269 struct mwifiex_adapter *adapter = priv->adapter;
2270 u8 *bss_info;
2271 u32 bytes_left, bytes_left_for_tlv, idx;
2272 u16 type, len;
2273 struct mwifiex_ie_types_data *tlv;
2274 struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv;
2275 struct mwifiex_ie_types_bss_scan_info *scan_info_tlv;
2276 u8 *radio_type;
2277 u64 fw_tsf = 0;
2278 s32 rssi = 0;
2279 struct mwifiex_event_scan_result *event_scan = buf;
2280 u8 num_of_set = event_scan->num_of_set;
2281 u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
2282 u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
2283
2284 if (num_of_set > MWIFIEX_MAX_AP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302285 mwifiex_dbg(adapter, ERROR,
2286 "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
2287 num_of_set);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002288 ret = -1;
2289 goto check_next_scan;
2290 }
2291
2292 bytes_left = scan_resp_size;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302293 mwifiex_dbg(adapter, INFO,
2294 "EXT_SCAN: size %d, returned %d APs...",
2295 scan_resp_size, num_of_set);
Zhaoyang Liu868093a2015-05-12 00:48:19 +05302296 mwifiex_dbg_dump(adapter, CMD_D, "EXT_SCAN buffer:", buf,
2297 scan_resp_size +
2298 sizeof(struct mwifiex_event_scan_result));
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002299
2300 tlv = (struct mwifiex_ie_types_data *)scan_resp;
2301
2302 for (idx = 0; idx < num_of_set && bytes_left; idx++) {
2303 type = le16_to_cpu(tlv->header.type);
2304 len = le16_to_cpu(tlv->header.len);
2305 if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302306 mwifiex_dbg(adapter, ERROR,
2307 "EXT_SCAN: Error bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002308 break;
2309 }
2310 scan_rsp_tlv = NULL;
2311 scan_info_tlv = NULL;
2312 bytes_left_for_tlv = bytes_left;
2313
2314 /* BSS response TLV with beacon or probe response buffer
2315 * at the initial position of each descriptor
2316 */
2317 if (type != TLV_TYPE_BSS_SCAN_RSP)
2318 break;
2319
2320 bss_info = (u8 *)tlv;
2321 scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv;
2322 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2323 bytes_left_for_tlv -=
2324 (len + sizeof(struct mwifiex_ie_types_header));
2325
2326 while (bytes_left_for_tlv >=
2327 sizeof(struct mwifiex_ie_types_header) &&
2328 le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) {
2329 type = le16_to_cpu(tlv->header.type);
2330 len = le16_to_cpu(tlv->header.len);
2331 if (bytes_left_for_tlv <
2332 sizeof(struct mwifiex_ie_types_header) + len) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302333 mwifiex_dbg(adapter, ERROR,
2334 "EXT_SCAN: Error in processing TLV,\t"
2335 "bytes left < TLV length\n");
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002336 scan_rsp_tlv = NULL;
2337 bytes_left_for_tlv = 0;
2338 continue;
2339 }
2340 switch (type) {
2341 case TLV_TYPE_BSS_SCAN_INFO:
2342 scan_info_tlv =
2343 (struct mwifiex_ie_types_bss_scan_info *)tlv;
2344 if (len !=
2345 sizeof(struct mwifiex_ie_types_bss_scan_info) -
2346 sizeof(struct mwifiex_ie_types_header)) {
2347 bytes_left_for_tlv = 0;
2348 continue;
2349 }
2350 break;
2351 default:
2352 break;
2353 }
2354 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2355 bytes_left -=
2356 (len + sizeof(struct mwifiex_ie_types_header));
2357 bytes_left_for_tlv -=
2358 (len + sizeof(struct mwifiex_ie_types_header));
2359 }
2360
2361 if (!scan_rsp_tlv)
2362 break;
2363
2364 /* Advance pointer to the beacon buffer length and
2365 * update the bytes count so that the function
2366 * wlan_interpret_bss_desc_with_ie() can handle the
2367 * scan buffer withut any change
2368 */
2369 bss_info += sizeof(u16);
2370 bytes_left -= sizeof(u16);
2371
2372 if (scan_info_tlv) {
2373 rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi));
2374 rssi *= 100; /* Convert dBm to mBm */
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302375 mwifiex_dbg(adapter, INFO,
2376 "info: InterpretIE: RSSI=%d\n", rssi);
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002377 fw_tsf = le64_to_cpu(scan_info_tlv->tsf);
2378 radio_type = &scan_info_tlv->radio_type;
2379 } else {
2380 radio_type = NULL;
2381 }
2382 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2383 &bytes_left, fw_tsf,
2384 radio_type, true, rssi);
2385 if (ret)
2386 goto check_next_scan;
2387 }
2388
2389check_next_scan:
2390 if (!event_scan->more_event)
2391 mwifiex_check_next_scan_command(priv);
2392
2393 return ret;
2394}
2395
2396/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002397 * This function prepares command for background scan query.
2398 *
2399 * Preparation includes -
2400 * - Setting command ID and proper size
2401 * - Setting background scan flush parameter
2402 * - Ensuring correct endian-ness
2403 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002404int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002405{
2406 struct host_cmd_ds_802_11_bg_scan_query *bg_query =
2407 &cmd->params.bg_scan_query;
2408
2409 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
2410 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
2411 + S_DS_GEN);
2412
2413 bg_query->flush = 1;
2414
2415 return 0;
2416}
2417
2418/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002419 * This function inserts scan command node to the scan pending queue.
2420 */
2421void
2422mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
2423 struct cmd_ctrl_node *cmd_node)
2424{
2425 struct mwifiex_adapter *adapter = priv->adapter;
2426 unsigned long flags;
2427
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002428 cmd_node->wait_q_enabled = true;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002429 cmd_node->condition = &adapter->scan_wait_q_woken;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002430 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
2431 list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
2432 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2433}
2434
2435/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002436 * This function sends a scan command for all available channels to the
2437 * firmware, filtered on a specific SSID.
2438 */
2439static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002440 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002441{
2442 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhaodcd5c792012-10-19 19:01:59 -07002443 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002444 struct mwifiex_user_scan_cfg *scan_cfg;
2445
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002446 if (adapter->scan_processing) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302447 mwifiex_dbg(adapter, WARN,
2448 "cmd: Scan already in process...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002449 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002450 }
2451
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002452 if (priv->scan_block) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302453 mwifiex_dbg(adapter, WARN,
2454 "cmd: Scan is blocked during association...\n");
Bing Zhaodcd5c792012-10-19 19:01:59 -07002455 return -EBUSY;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002456 }
2457
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002458 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002459 if (!scan_cfg)
Christoph Fritzb53575e2011-05-08 22:50:09 +02002460 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002461
Amitkumar Karwarbe0b2812012-02-27 22:04:15 -08002462 scan_cfg->ssid_list = req_ssid;
2463 scan_cfg->num_ssids = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002464
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002465 ret = mwifiex_scan_networks(priv, scan_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002466
2467 kfree(scan_cfg);
2468 return ret;
2469}
2470
2471/*
2472 * Sends IOCTL request to start a scan.
2473 *
2474 * This function allocates the IOCTL request buffer, fills it
2475 * with requisite parameters and calls the IOCTL handler.
2476 *
2477 * Scan command can be issued for both normal scan and specific SSID
2478 * scan, depending upon whether an SSID is provided or not.
2479 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002480int mwifiex_request_scan(struct mwifiex_private *priv,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -08002481 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002482{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002483 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002484
2485 if (down_interruptible(&priv->async_sem)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302486 mwifiex_dbg(priv->adapter, ERROR,
2487 "%s: acquire semaphore fail\n",
2488 __func__);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002489 return -1;
2490 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002491
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -07002492 priv->adapter->scan_wait_q_woken = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002493
2494 if (req_ssid && req_ssid->ssid_len != 0)
2495 /* Specific SSID scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002496 ret = mwifiex_scan_specific_ssid(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002497 else
2498 /* Normal scan */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002499 ret = mwifiex_scan_networks(priv, NULL);
2500
Amitkumar Karwarb0e70c22012-10-19 19:19:17 -07002501 up(&priv->async_sem);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07002502
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002503 return ret;
2504}
2505
2506/*
2507 * This function appends the vendor specific IE TLV to a buffer.
2508 */
2509int
2510mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
2511 u16 vsie_mask, u8 **buffer)
2512{
2513 int id, ret_len = 0;
2514 struct mwifiex_ie_types_vendor_param_set *vs_param_set;
2515
2516 if (!buffer)
2517 return 0;
2518 if (!(*buffer))
2519 return 0;
2520
2521 /*
2522 * Traverse through the saved vendor specific IE array and append
2523 * the selected(scan/assoc/adhoc) IE as TLV to the command
2524 */
2525 for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
2526 if (priv->vs_ie[id].mask & vsie_mask) {
2527 vs_param_set =
2528 (struct mwifiex_ie_types_vendor_param_set *)
2529 *buffer;
2530 vs_param_set->header.type =
2531 cpu_to_le16(TLV_TYPE_PASSTHROUGH);
2532 vs_param_set->header.len =
2533 cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
2534 & 0x00FF) + 2);
2535 memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
2536 le16_to_cpu(vs_param_set->header.len));
2537 *buffer += le16_to_cpu(vs_param_set->header.len) +
2538 sizeof(struct mwifiex_ie_types_header);
2539 ret_len += le16_to_cpu(vs_param_set->header.len) +
2540 sizeof(struct mwifiex_ie_types_header);
2541 }
2542 }
2543 return ret_len;
2544}
2545
2546/*
2547 * This function saves a beacon buffer of the current BSS descriptor.
2548 *
2549 * The current beacon buffer is saved so that it can be restored in the
2550 * following cases that makes the beacon buffer not to contain the current
2551 * ssid's beacon buffer.
2552 * - The current ssid was not found somehow in the last scan.
2553 * - The current ssid was the last entry of the scan table and overloaded.
2554 */
2555void
2556mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2557{
2558 struct mwifiex_bssdescriptor *curr_bss =
2559 &priv->curr_bss_params.bss_descriptor;
2560
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002561 if (!curr_bss->beacon_buf_size)
2562 return;
2563
2564 /* allocate beacon buffer at 1st time; or if it's size has changed */
2565 if (!priv->curr_bcn_buf ||
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002566 priv->curr_bcn_size != curr_bss->beacon_buf_size) {
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002567 priv->curr_bcn_size = curr_bss->beacon_buf_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002568
2569 kfree(priv->curr_bcn_buf);
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -07002570 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002571 GFP_ATOMIC);
Joe Perches0d2e7a52013-02-03 17:28:14 +00002572 if (!priv->curr_bcn_buf)
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002573 return;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002574 }
Amitkumar Karwar030fe792011-04-27 19:13:13 -07002575
2576 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
Yogesh Ashok Powarcff23ce2012-03-13 19:22:38 -07002577 curr_bss->beacon_buf_size);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302578 mwifiex_dbg(priv->adapter, INFO,
2579 "info: current beacon saved %d\n",
2580 priv->curr_bcn_size);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002581
2582 curr_bss->beacon_buf = priv->curr_bcn_buf;
2583
2584 /* adjust the pointers in the current BSS descriptor */
2585 if (curr_bss->bcn_wpa_ie)
2586 curr_bss->bcn_wpa_ie =
2587 (struct ieee_types_vendor_specific *)
2588 (curr_bss->beacon_buf +
2589 curr_bss->wpa_offset);
2590
2591 if (curr_bss->bcn_rsn_ie)
2592 curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
2593 (curr_bss->beacon_buf +
2594 curr_bss->rsn_offset);
2595
2596 if (curr_bss->bcn_ht_cap)
2597 curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
2598 (curr_bss->beacon_buf +
2599 curr_bss->ht_cap_offset);
2600
Johannes Berg074d46d2012-03-15 19:45:16 +01002601 if (curr_bss->bcn_ht_oper)
2602 curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002603 (curr_bss->beacon_buf +
2604 curr_bss->ht_info_offset);
2605
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002606 if (curr_bss->bcn_vht_cap)
Amitkumar Karward5124642014-03-04 18:43:14 -08002607 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2608 curr_bss->vht_cap_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002609
2610 if (curr_bss->bcn_vht_oper)
Amitkumar Karward5124642014-03-04 18:43:14 -08002611 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2612 curr_bss->vht_info_offset);
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002613
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002614 if (curr_bss->bcn_bss_co_2040)
2615 curr_bss->bcn_bss_co_2040 =
Joe Perches2c208892012-06-04 12:44:17 +00002616 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -07002617
2618 if (curr_bss->bcn_ext_cap)
Joe Perches2c208892012-06-04 12:44:17 +00002619 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2620 curr_bss->ext_cap_offset;
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002621
2622 if (curr_bss->oper_mode)
2623 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2624 curr_bss->oper_mode_offset);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002625}
2626
2627/*
2628 * This function frees the current BSS descriptor beacon buffer.
2629 */
2630void
2631mwifiex_free_curr_bcn(struct mwifiex_private *priv)
2632{
2633 kfree(priv->curr_bcn_buf);
2634 priv->curr_bcn_buf = NULL;
2635}