2 * Marvell Wireless LAN device driver: scan ioctl and command handling
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
28 /* The maximum number of channels the firmware can scan per command */
29 #define MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN 14
31 #define MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD 4
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)))
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)
42 /* Memory needed to store a max number/size WildCard SSID TLV for a firmware
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))
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) \
55 + WILDCARD_SSID_TLV_MAX_SIZE)
58 union 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];
70 static u8 mwifiex_wpa_oui[CIPHER_SUITE_MAX][4] = {
71 { 0x00, 0x50, 0xf2, 0x02 }, /* TKIP */
72 { 0x00, 0x50, 0xf2, 0x04 }, /* AES */
74 static u8 mwifiex_rsn_oui[CIPHER_SUITE_MAX][4] = {
75 { 0x00, 0x0f, 0xac, 0x02 }, /* TKIP */
76 { 0x00, 0x0f, 0xac, 0x04 }, /* AES */
80 * This function parses a given IE for a given OUI.
82 * This is used to parse a WPA/RSN IE to find if it has
86 mwifiex_search_oui_in_ie(struct ie_body *iebody, u8 *oui)
90 count = iebody->ptk_cnt[0];
92 /* There could be multiple OUIs for PTK hence
94 2) Check all the OUIs for AES.
95 3) If one of them is AES then pass success. */
97 if (!memcmp(iebody->ptk_body, oui, sizeof(iebody->ptk_body)))
98 return MWIFIEX_OUI_PRESENT;
102 iebody = (struct ie_body *) ((u8 *) iebody +
103 sizeof(iebody->ptk_body));
106 pr_debug("info: %s: OUI is not found in PTK\n", __func__);
107 return MWIFIEX_OUI_NOT_PRESENT;
111 * This function checks if a given OUI is present in a RSN IE.
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
118 mwifiex_is_rsn_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
121 struct ie_body *iebody;
122 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
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) +
129 oui = &mwifiex_rsn_oui[cipher][0];
130 ret = mwifiex_search_oui_in_ie(iebody, oui);
138 * This function checks if a given OUI is present in a WPA IE.
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
145 mwifiex_is_wpa_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher)
148 struct ie_body *iebody;
149 u8 ret = MWIFIEX_OUI_NOT_PRESENT;
151 if (((bss_desc->bcn_wpa_ie) &&
152 ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id ==
153 WLAN_EID_VENDOR_SPECIFIC))) {
154 iebody = (struct ie_body *)((u8 *)bss_desc->bcn_wpa_ie->data +
156 oui = &mwifiex_wpa_oui[cipher][0];
157 ret = mwifiex_search_oui_in_ie(iebody, oui);
165 * This function compares two SSIDs and checks if they match.
168 mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2)
170 if (!ssid1 || !ssid2 || (ssid1->ssid_len != ssid2->ssid_len))
172 return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssid_len);
176 * This function checks if wapi is enabled in driver and scanned network is
177 * compatible with it.
180 mwifiex_is_bss_wapi(struct mwifiex_private *priv,
181 struct mwifiex_bssdescriptor *bss_desc)
183 if (priv->sec_info.wapi_enabled &&
184 (bss_desc->bcn_wapi_ie &&
185 ((*(bss_desc->bcn_wapi_ie)).ieee_hdr.element_id ==
186 WLAN_EID_BSS_AC_ACCESS_DELAY))) {
193 * This function checks if driver is configured with no security mode and
194 * scanned network is compatible with it.
197 mwifiex_is_bss_no_sec(struct mwifiex_private *priv,
198 struct mwifiex_bssdescriptor *bss_desc)
200 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
201 !priv->sec_info.wpa2_enabled && ((!bss_desc->bcn_wpa_ie) ||
202 ((*(bss_desc->bcn_wpa_ie)).vend_hdr.element_id !=
203 WLAN_EID_VENDOR_SPECIFIC)) &&
204 ((!bss_desc->bcn_rsn_ie) ||
205 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id !=
207 !priv->sec_info.encryption_mode && !bss_desc->privacy) {
214 * This function checks if static WEP is enabled in driver and scanned network
215 * is compatible with it.
218 mwifiex_is_bss_static_wep(struct mwifiex_private *priv,
219 struct mwifiex_bssdescriptor *bss_desc)
221 if (priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
222 !priv->sec_info.wpa2_enabled && bss_desc->privacy) {
229 * This function checks if wpa is enabled in driver and scanned network is
230 * compatible with it.
233 mwifiex_is_bss_wpa(struct mwifiex_private *priv,
234 struct mwifiex_bssdescriptor *bss_desc)
236 if (!priv->sec_info.wep_enabled && priv->sec_info.wpa_enabled &&
237 !priv->sec_info.wpa2_enabled && ((bss_desc->bcn_wpa_ie) &&
238 ((*(bss_desc->bcn_wpa_ie)).
239 vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC))
241 * Privacy bit may NOT be set in some APs like
242 * LinkSys WRT54G && bss_desc->privacy
245 mwifiex_dbg(priv->adapter, INFO,
247 "wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s\t"
248 "EncMode=%#x privacy=%#x\n", __func__,
249 (bss_desc->bcn_wpa_ie) ?
250 (*bss_desc->bcn_wpa_ie).
251 vend_hdr.element_id : 0,
252 (bss_desc->bcn_rsn_ie) ?
253 (*bss_desc->bcn_rsn_ie).
254 ieee_hdr.element_id : 0,
255 (priv->sec_info.wep_enabled) ? "e" : "d",
256 (priv->sec_info.wpa_enabled) ? "e" : "d",
257 (priv->sec_info.wpa2_enabled) ? "e" : "d",
258 priv->sec_info.encryption_mode,
266 * This function checks if wpa2 is enabled in driver and scanned network is
267 * compatible with it.
270 mwifiex_is_bss_wpa2(struct mwifiex_private *priv,
271 struct mwifiex_bssdescriptor *bss_desc)
273 if (!priv->sec_info.wep_enabled &&
274 !priv->sec_info.wpa_enabled &&
275 priv->sec_info.wpa2_enabled &&
276 ((bss_desc->bcn_rsn_ie) &&
277 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id == WLAN_EID_RSN))) {
279 * Privacy bit may NOT be set in some APs like
280 * LinkSys WRT54G && bss_desc->privacy
282 mwifiex_dbg(priv->adapter, INFO,
284 "wpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s\t"
285 "EncMode=%#x privacy=%#x\n", __func__,
286 (bss_desc->bcn_wpa_ie) ?
287 (*bss_desc->bcn_wpa_ie).
288 vend_hdr.element_id : 0,
289 (bss_desc->bcn_rsn_ie) ?
290 (*bss_desc->bcn_rsn_ie).
291 ieee_hdr.element_id : 0,
292 (priv->sec_info.wep_enabled) ? "e" : "d",
293 (priv->sec_info.wpa_enabled) ? "e" : "d",
294 (priv->sec_info.wpa2_enabled) ? "e" : "d",
295 priv->sec_info.encryption_mode,
303 * This function checks if adhoc AES is enabled in driver and scanned network is
304 * compatible with it.
307 mwifiex_is_bss_adhoc_aes(struct mwifiex_private *priv,
308 struct mwifiex_bssdescriptor *bss_desc)
310 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
311 !priv->sec_info.wpa2_enabled &&
312 ((!bss_desc->bcn_wpa_ie) ||
313 ((*(bss_desc->bcn_wpa_ie)).
314 vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
315 ((!bss_desc->bcn_rsn_ie) ||
316 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
317 !priv->sec_info.encryption_mode && bss_desc->privacy) {
324 * This function checks if dynamic WEP is enabled in driver and scanned network
325 * is compatible with it.
328 mwifiex_is_bss_dynamic_wep(struct mwifiex_private *priv,
329 struct mwifiex_bssdescriptor *bss_desc)
331 if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled &&
332 !priv->sec_info.wpa2_enabled &&
333 ((!bss_desc->bcn_wpa_ie) ||
334 ((*(bss_desc->bcn_wpa_ie)).
335 vend_hdr.element_id != WLAN_EID_VENDOR_SPECIFIC)) &&
336 ((!bss_desc->bcn_rsn_ie) ||
337 ((*(bss_desc->bcn_rsn_ie)).ieee_hdr.element_id != WLAN_EID_RSN)) &&
338 priv->sec_info.encryption_mode && bss_desc->privacy) {
339 mwifiex_dbg(priv->adapter, INFO,
340 "info: %s: dynamic\t"
341 "WEP: wpa_ie=%#x wpa2_ie=%#x\t"
342 "EncMode=%#x privacy=%#x\n",
344 (bss_desc->bcn_wpa_ie) ?
345 (*bss_desc->bcn_wpa_ie).
346 vend_hdr.element_id : 0,
347 (bss_desc->bcn_rsn_ie) ?
348 (*bss_desc->bcn_rsn_ie).
349 ieee_hdr.element_id : 0,
350 priv->sec_info.encryption_mode,
358 * This function checks if a scanned network is compatible with the driver
361 * WEP WPA WPA2 ad-hoc encrypt Network
362 * enabled enabled enabled AES mode Privacy WPA WPA2 Compatible
363 * 0 0 0 0 NONE 0 0 0 yes No security
364 * 0 1 0 0 x 1x 1 x yes WPA (disable
366 * 0 0 1 0 x 1x x 1 yes WPA2 (disable
368 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
369 * 1 0 0 0 NONE 1 0 0 yes Static WEP
371 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
373 * Compatibility is not matched while roaming, except for mode.
376 mwifiex_is_network_compatible(struct mwifiex_private *priv,
377 struct mwifiex_bssdescriptor *bss_desc, u32 mode)
379 struct mwifiex_adapter *adapter = priv->adapter;
381 bss_desc->disable_11n = false;
383 /* Don't check for compatibility if roaming */
384 if (priv->media_connected &&
385 (priv->bss_mode == NL80211_IFTYPE_STATION) &&
386 (bss_desc->bss_mode == NL80211_IFTYPE_STATION))
389 if (priv->wps.session_enable) {
390 mwifiex_dbg(adapter, IOCTL,
391 "info: return success directly in WPS period\n");
395 if (bss_desc->chan_sw_ie_present) {
396 mwifiex_dbg(adapter, INFO,
397 "Don't connect to AP with WLAN_EID_CHANNEL_SWITCH\n");
401 if (mwifiex_is_bss_wapi(priv, bss_desc)) {
402 mwifiex_dbg(adapter, INFO,
403 "info: return success for WAPI AP\n");
407 if (bss_desc->bss_mode == mode) {
408 if (mwifiex_is_bss_no_sec(priv, bss_desc)) {
411 } else if (mwifiex_is_bss_static_wep(priv, bss_desc)) {
412 /* Static WEP enabled */
413 mwifiex_dbg(adapter, INFO,
414 "info: Disable 11n in WEP mode.\n");
415 bss_desc->disable_11n = true;
417 } else if (mwifiex_is_bss_wpa(priv, bss_desc)) {
419 if (((priv->adapter->config_bands & BAND_GN ||
420 priv->adapter->config_bands & BAND_AN) &&
421 bss_desc->bcn_ht_cap) &&
422 !mwifiex_is_wpa_oui_present(bss_desc,
423 CIPHER_SUITE_CCMP)) {
425 if (mwifiex_is_wpa_oui_present
426 (bss_desc, CIPHER_SUITE_TKIP)) {
427 mwifiex_dbg(adapter, INFO,
428 "info: Disable 11n if AES\t"
429 "is not supported by AP\n");
430 bss_desc->disable_11n = true;
436 } else if (mwifiex_is_bss_wpa2(priv, bss_desc)) {
438 if (((priv->adapter->config_bands & BAND_GN ||
439 priv->adapter->config_bands & BAND_AN) &&
440 bss_desc->bcn_ht_cap) &&
441 !mwifiex_is_rsn_oui_present(bss_desc,
442 CIPHER_SUITE_CCMP)) {
444 if (mwifiex_is_rsn_oui_present
445 (bss_desc, CIPHER_SUITE_TKIP)) {
446 mwifiex_dbg(adapter, INFO,
447 "info: Disable 11n if AES\t"
448 "is not supported by AP\n");
449 bss_desc->disable_11n = true;
455 } else if (mwifiex_is_bss_adhoc_aes(priv, bss_desc)) {
456 /* Ad-hoc AES enabled */
458 } else if (mwifiex_is_bss_dynamic_wep(priv, bss_desc)) {
459 /* Dynamic WEP enabled */
463 /* Security doesn't match */
464 mwifiex_dbg(adapter, ERROR,
465 "info: %s: failed: wpa_ie=%#x wpa2_ie=%#x WEP=%s\t"
466 "WPA=%s WPA2=%s EncMode=%#x privacy=%#x\n",
468 (bss_desc->bcn_wpa_ie) ?
469 (*bss_desc->bcn_wpa_ie).vend_hdr.element_id : 0,
470 (bss_desc->bcn_rsn_ie) ?
471 (*bss_desc->bcn_rsn_ie).ieee_hdr.element_id : 0,
472 (priv->sec_info.wep_enabled) ? "e" : "d",
473 (priv->sec_info.wpa_enabled) ? "e" : "d",
474 (priv->sec_info.wpa2_enabled) ? "e" : "d",
475 priv->sec_info.encryption_mode, bss_desc->privacy);
479 /* Mode doesn't match */
484 * This function creates a channel list for the driver to scan, based
485 * on region/band information.
487 * This routine is used for any scan that is not provided with a
488 * specific channel list to scan.
491 mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
492 const struct mwifiex_user_scan_cfg
494 struct mwifiex_chan_scan_param_set
498 enum ieee80211_band band;
499 struct ieee80211_supported_band *sband;
500 struct ieee80211_channel *ch;
501 struct mwifiex_adapter *adapter = priv->adapter;
504 for (band = 0; (band < IEEE80211_NUM_BANDS) ; band++) {
506 if (!priv->wdev.wiphy->bands[band])
509 sband = priv->wdev.wiphy->bands[band];
511 for (i = 0; (i < sband->n_channels) ; i++) {
512 ch = &sband->channels[i];
513 if (ch->flags & IEEE80211_CHAN_DISABLED)
515 scan_chan_list[chan_idx].radio_type = band;
518 user_scan_in->chan_list[0].scan_time)
519 scan_chan_list[chan_idx].max_scan_time =
520 cpu_to_le16((u16) user_scan_in->
521 chan_list[0].scan_time);
522 else if (ch->flags & IEEE80211_CHAN_NO_IR)
523 scan_chan_list[chan_idx].max_scan_time =
524 cpu_to_le16(adapter->passive_scan_time);
526 scan_chan_list[chan_idx].max_scan_time =
527 cpu_to_le16(adapter->active_scan_time);
529 if (ch->flags & IEEE80211_CHAN_NO_IR)
530 scan_chan_list[chan_idx].chan_scan_mode_bitmap
531 |= (MWIFIEX_PASSIVE_SCAN |
532 MWIFIEX_HIDDEN_SSID_REPORT);
534 scan_chan_list[chan_idx].chan_scan_mode_bitmap
535 &= ~MWIFIEX_PASSIVE_SCAN;
536 scan_chan_list[chan_idx].chan_number =
539 scan_chan_list[chan_idx].max_scan_time =
540 cpu_to_le16(adapter->specific_scan_time);
541 scan_chan_list[chan_idx].chan_scan_mode_bitmap
542 |= MWIFIEX_DISABLE_CHAN_FILT;
551 /* This function appends rate TLV to scan config command. */
553 mwifiex_append_rate_tlv(struct mwifiex_private *priv,
554 struct mwifiex_scan_cmd_config *scan_cfg_out,
557 struct mwifiex_ie_types_rates_param_set *rates_tlv;
558 u8 rates[MWIFIEX_SUPPORTED_RATES], *tlv_pos;
561 memset(rates, 0, sizeof(rates));
563 tlv_pos = (u8 *)scan_cfg_out->tlv_buf + scan_cfg_out->tlv_buf_len;
565 if (priv->scan_request)
566 rates_size = mwifiex_get_rates_from_cfg80211(priv, rates,
569 rates_size = mwifiex_get_supported_rates(priv, rates);
571 mwifiex_dbg(priv->adapter, CMD,
572 "info: SCAN_CMD: Rates size = %d\n",
574 rates_tlv = (struct mwifiex_ie_types_rates_param_set *)tlv_pos;
575 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES);
576 rates_tlv->header.len = cpu_to_le16((u16) rates_size);
577 memcpy(rates_tlv->rates, rates, rates_size);
578 scan_cfg_out->tlv_buf_len += sizeof(rates_tlv->header) + rates_size;
584 * This function constructs and sends multiple scan config commands to
587 * Previous routines in the code flow have created a scan command configuration
588 * with any requested TLVs. This function splits the channel TLV into maximum
589 * channels supported per scan lists and sends the portion of the channel TLV,
590 * along with the other TLVs, to the firmware.
593 mwifiex_scan_channel_list(struct mwifiex_private *priv,
594 u32 max_chan_per_scan, u8 filtered_scan,
595 struct mwifiex_scan_cmd_config *scan_cfg_out,
596 struct mwifiex_ie_types_chan_list_param_set
598 struct mwifiex_chan_scan_param_set *scan_chan_list)
600 struct mwifiex_adapter *adapter = priv->adapter;
602 struct mwifiex_chan_scan_param_set *tmp_chan_list;
603 struct mwifiex_chan_scan_param_set *start_chan;
604 struct cmd_ctrl_node *cmd_node, *tmp_node;
606 u32 tlv_idx, rates_size, cmd_no;
611 if (!scan_cfg_out || !chan_tlv_out || !scan_chan_list) {
612 mwifiex_dbg(priv->adapter, ERROR,
613 "info: Scan: Null detect: %p, %p, %p\n",
614 scan_cfg_out, chan_tlv_out, scan_chan_list);
618 /* Check csa channel expiry before preparing scan list */
619 mwifiex_11h_get_csa_closed_channel(priv);
621 chan_tlv_out->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
623 /* Set the temp channel struct pointer to the start of the desired
625 tmp_chan_list = scan_chan_list;
627 /* Loop through the desired channel list, sending a new firmware scan
628 commands for each max_chan_per_scan channels (or for 1,6,11
629 individually if configured accordingly) */
630 while (tmp_chan_list->chan_number) {
635 chan_tlv_out->header.len = 0;
636 start_chan = tmp_chan_list;
640 * Construct the Channel TLV for the scan command. Continue to
641 * insert channel TLVs until:
642 * - the tlv_idx hits the maximum configured per scan command
643 * - the next channel to insert is 0 (end of desired channel
645 * - done_early is set (controlling individual scanning of
648 while (tlv_idx < max_chan_per_scan &&
649 tmp_chan_list->chan_number && !done_early) {
651 if (tmp_chan_list->chan_number == priv->csa_chan) {
656 radio_type = tmp_chan_list->radio_type;
657 mwifiex_dbg(priv->adapter, INFO,
658 "info: Scan: Chan(%3d), Radio(%d),\t"
659 "Mode(%d, %d), Dur(%d)\n",
660 tmp_chan_list->chan_number,
661 tmp_chan_list->radio_type,
662 tmp_chan_list->chan_scan_mode_bitmap
663 & MWIFIEX_PASSIVE_SCAN,
664 (tmp_chan_list->chan_scan_mode_bitmap
665 & MWIFIEX_DISABLE_CHAN_FILT) >> 1,
666 le16_to_cpu(tmp_chan_list->max_scan_time));
668 /* Copy the current channel TLV to the command being
670 memcpy(chan_tlv_out->chan_scan_param + tlv_idx,
672 sizeof(chan_tlv_out->chan_scan_param));
674 /* Increment the TLV header length by the size
676 le16_add_cpu(&chan_tlv_out->header.len,
677 sizeof(chan_tlv_out->chan_scan_param));
680 * The tlv buffer length is set to the number of bytes
681 * of the between the channel tlv pointer and the start
682 * of the tlv buffer. This compensates for any TLVs
683 * that were appended before the channel list.
685 scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out -
686 scan_cfg_out->tlv_buf);
688 /* Add the size of the channel tlv header and the data
690 scan_cfg_out->tlv_buf_len +=
691 (sizeof(chan_tlv_out->header)
692 + le16_to_cpu(chan_tlv_out->header.len));
694 /* Increment the index to the channel tlv we are
698 /* Count the total scan time per command */
700 le16_to_cpu(tmp_chan_list->max_scan_time);
704 /* Stop the loop if the *current* channel is in the
705 1,6,11 set and we are not filtering on a BSSID
707 if (!filtered_scan &&
708 (tmp_chan_list->chan_number == 1 ||
709 tmp_chan_list->chan_number == 6 ||
710 tmp_chan_list->chan_number == 11))
713 /* Increment the tmp pointer to the next channel to
717 /* Stop the loop if the *next* channel is in the 1,6,11
718 set. This will cause it to be the only channel
719 scanned on the next interation */
720 if (!filtered_scan &&
721 (tmp_chan_list->chan_number == 1 ||
722 tmp_chan_list->chan_number == 6 ||
723 tmp_chan_list->chan_number == 11))
727 /* The total scan time should be less than scan command timeout
729 if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) {
730 mwifiex_dbg(priv->adapter, ERROR,
731 "total scan time %dms\t"
732 "is over limit (%dms), scan skipped\n",
734 MWIFIEX_MAX_TOTAL_SCAN_TIME);
739 rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out,
742 priv->adapter->scan_channels = start_chan;
744 /* Send the scan command to the firmware with the specified
746 if (priv->adapter->ext_scan)
747 cmd_no = HostCmd_CMD_802_11_SCAN_EXT;
749 cmd_no = HostCmd_CMD_802_11_SCAN;
751 ret = mwifiex_send_cmd(priv, cmd_no, HostCmd_ACT_GEN_SET,
752 0, scan_cfg_out, false);
754 /* rate IE is updated per scan command but same starting
755 * pointer is used each time so that rate IE from earlier
756 * scan_cfg_out->buf is overwritten with new one.
758 scan_cfg_out->tlv_buf_len -=
759 sizeof(struct mwifiex_ie_types_header) + rates_size;
762 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
763 list_for_each_entry_safe(cmd_node, tmp_node,
764 &adapter->scan_pending_q,
766 list_del(&cmd_node->list);
767 cmd_node->wait_q_enabled = false;
768 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
770 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
783 * This function constructs a scan command configuration structure to use
786 * Application layer or other functions can invoke network scanning
787 * with a scan configuration supplied in a user scan configuration structure.
788 * This structure is used as the basis of one or many scan command configuration
789 * commands that are sent to the command processing module and eventually to the
792 * This function creates a scan command configuration structure based on the
793 * following user supplied parameters (if present):
796 * - Number of Probes to be sent
799 * If the SSID or BSSID filter is not present, the filter is disabled/cleared.
800 * If the number of probes is not set, adapter default setting is used.
803 mwifiex_config_scan(struct mwifiex_private *priv,
804 const struct mwifiex_user_scan_cfg *user_scan_in,
805 struct mwifiex_scan_cmd_config *scan_cfg_out,
806 struct mwifiex_ie_types_chan_list_param_set **chan_list_out,
807 struct mwifiex_chan_scan_param_set *scan_chan_list,
808 u8 *max_chan_per_scan, u8 *filtered_scan,
809 u8 *scan_current_only)
811 struct mwifiex_adapter *adapter = priv->adapter;
812 struct mwifiex_ie_types_num_probes *num_probes_tlv;
813 struct mwifiex_ie_types_scan_chan_gap *chan_gap_tlv;
814 struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv;
815 struct mwifiex_ie_types_bssid_list *bssid_tlv;
827 struct mwifiex_ie_types_htcap *ht_cap;
828 struct mwifiex_ie_types_bss_mode *bss_mode;
830 /* The tlv_buf_len is calculated for each scan command. The TLVs added
831 in this routine will be preserved since the routine that sends the
832 command will append channelTLVs at *chan_list_out. The difference
833 between the *chan_list_out and the tlv_buf start will be used to
834 calculate the size of anything we add in this routine. */
835 scan_cfg_out->tlv_buf_len = 0;
837 /* Running tlv pointer. Assigned to chan_list_out at end of function
838 so later routines know where channels can be added to the command
840 tlv_pos = scan_cfg_out->tlv_buf;
842 /* Initialize the scan as un-filtered; the flag is later set to TRUE
843 below if a SSID or BSSID filter is sent in the command */
844 *filtered_scan = false;
846 /* Initialize the scan as not being only on the current channel. If
847 the channel list is customized, only contains one channel, and is
848 the active channel, this is set true and data flow is not halted. */
849 *scan_current_only = false;
853 /* Default the ssid_filter flag to TRUE, set false under
854 certain wildcard conditions and qualified by the existence
855 of an SSID list before marking the scan as filtered */
858 /* Set the BSS type scan filter, use Adapter setting if
860 scan_cfg_out->bss_mode =
861 (user_scan_in->bss_mode ? (u8) user_scan_in->
862 bss_mode : (u8) adapter->scan_mode);
864 /* Set the number of probes to send, use Adapter setting
867 (user_scan_in->num_probes ? user_scan_in->
868 num_probes : adapter->scan_probes);
871 * Set the BSSID filter to the incoming configuration,
872 * if non-zero. If not set, it will remain disabled
875 memcpy(scan_cfg_out->specific_bssid,
876 user_scan_in->specific_bssid,
877 sizeof(scan_cfg_out->specific_bssid));
879 if (adapter->ext_scan &&
880 !is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
882 (struct mwifiex_ie_types_bssid_list *)tlv_pos;
883 bssid_tlv->header.type = cpu_to_le16(TLV_TYPE_BSSID);
884 bssid_tlv->header.len = cpu_to_le16(ETH_ALEN);
885 memcpy(bssid_tlv->bssid, user_scan_in->specific_bssid,
887 tlv_pos += sizeof(struct mwifiex_ie_types_bssid_list);
890 for (i = 0; i < user_scan_in->num_ssids; i++) {
891 ssid_len = user_scan_in->ssid_list[i].ssid_len;
894 (struct mwifiex_ie_types_wildcard_ssid_params *)
896 wildcard_ssid_tlv->header.type =
897 cpu_to_le16(TLV_TYPE_WILDCARDSSID);
898 wildcard_ssid_tlv->header.len = cpu_to_le16(
899 (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
903 * max_ssid_length = 0 tells firmware to perform
904 * specific scan for the SSID filled, whereas
905 * max_ssid_length = IEEE80211_MAX_SSID_LEN is for
909 wildcard_ssid_tlv->max_ssid_length = 0;
911 wildcard_ssid_tlv->max_ssid_length =
912 IEEE80211_MAX_SSID_LEN;
914 if (!memcmp(user_scan_in->ssid_list[i].ssid,
916 wildcard_ssid_tlv->max_ssid_length = 0xfe;
918 memcpy(wildcard_ssid_tlv->ssid,
919 user_scan_in->ssid_list[i].ssid, ssid_len);
921 tlv_pos += (sizeof(wildcard_ssid_tlv->header)
922 + le16_to_cpu(wildcard_ssid_tlv->header.len));
924 mwifiex_dbg(adapter, INFO,
925 "info: scan: ssid[%d]: %s, %d\n",
926 i, wildcard_ssid_tlv->ssid,
927 wildcard_ssid_tlv->max_ssid_length);
929 /* Empty wildcard ssid with a maxlen will match many or
930 potentially all SSIDs (maxlen == 32), therefore do
931 not treat the scan as
933 if (!ssid_len && wildcard_ssid_tlv->max_ssid_length)
938 * The default number of channels sent in the command is low to
939 * ensure the response buffer from the firmware does not
940 * truncate scan results. That is not an issue with an SSID
941 * or BSSID filter applied to the scan results in the firmware.
943 if ((i && ssid_filter) ||
944 !is_zero_ether_addr(scan_cfg_out->specific_bssid))
945 *filtered_scan = true;
947 if (user_scan_in->scan_chan_gap) {
948 mwifiex_dbg(adapter, INFO,
949 "info: scan: channel gap = %d\n",
950 user_scan_in->scan_chan_gap);
952 MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
954 chan_gap_tlv = (void *)tlv_pos;
955 chan_gap_tlv->header.type =
956 cpu_to_le16(TLV_TYPE_SCAN_CHANNEL_GAP);
957 chan_gap_tlv->header.len =
958 cpu_to_le16(sizeof(chan_gap_tlv->chan_gap));
959 chan_gap_tlv->chan_gap =
960 cpu_to_le16((user_scan_in->scan_chan_gap));
962 sizeof(struct mwifiex_ie_types_scan_chan_gap);
965 scan_cfg_out->bss_mode = (u8) adapter->scan_mode;
966 num_probes = adapter->scan_probes;
970 * If a specific BSSID or SSID is used, the number of channels in the
971 * scan command will be increased to the absolute maximum.
974 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
976 *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
978 if (adapter->ext_scan) {
979 bss_mode = (struct mwifiex_ie_types_bss_mode *)tlv_pos;
980 bss_mode->header.type = cpu_to_le16(TLV_TYPE_BSS_MODE);
981 bss_mode->header.len = cpu_to_le16(sizeof(bss_mode->bss_mode));
982 bss_mode->bss_mode = scan_cfg_out->bss_mode;
983 tlv_pos += sizeof(bss_mode->header) +
984 le16_to_cpu(bss_mode->header.len);
987 /* If the input config or adapter has the number of Probes set,
991 mwifiex_dbg(adapter, INFO,
992 "info: scan: num_probes = %d\n",
995 num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos;
996 num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES);
997 num_probes_tlv->header.len =
998 cpu_to_le16(sizeof(num_probes_tlv->num_probes));
999 num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes);
1001 tlv_pos += sizeof(num_probes_tlv->header) +
1002 le16_to_cpu(num_probes_tlv->header.len);
1006 if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) &&
1007 (priv->adapter->config_bands & BAND_GN ||
1008 priv->adapter->config_bands & BAND_AN)) {
1009 ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos;
1010 memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap));
1011 ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1012 ht_cap->header.len =
1013 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
1015 mwifiex_band_to_radio_type(priv->adapter->config_bands);
1016 mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap);
1017 tlv_pos += sizeof(struct mwifiex_ie_types_htcap);
1020 /* Append vendor specific IE TLV */
1021 mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos);
1024 * Set the output for the channel TLV to the address in the tlv buffer
1025 * past any TLVs that were added in this function (SSID, num_probes).
1026 * Channel TLVs will be added past this for each scan command,
1027 * preserving the TLVs that were previously added.
1030 (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos;
1032 if (user_scan_in && user_scan_in->chan_list[0].chan_number) {
1034 mwifiex_dbg(adapter, INFO,
1035 "info: Scan: Using supplied channel list\n");
1038 chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX &&
1039 user_scan_in->chan_list[chan_idx].chan_number;
1042 channel = user_scan_in->chan_list[chan_idx].chan_number;
1043 (scan_chan_list + chan_idx)->chan_number = channel;
1046 user_scan_in->chan_list[chan_idx].radio_type;
1047 (scan_chan_list + chan_idx)->radio_type = radio_type;
1049 scan_type = user_scan_in->chan_list[chan_idx].scan_type;
1051 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1053 chan_idx)->chan_scan_mode_bitmap
1054 |= (MWIFIEX_PASSIVE_SCAN |
1055 MWIFIEX_HIDDEN_SSID_REPORT);
1058 chan_idx)->chan_scan_mode_bitmap
1059 &= ~MWIFIEX_PASSIVE_SCAN;
1063 chan_idx)->chan_scan_mode_bitmap
1064 |= MWIFIEX_DISABLE_CHAN_FILT;
1066 if (user_scan_in->chan_list[chan_idx].scan_time) {
1067 scan_dur = (u16) user_scan_in->
1068 chan_list[chan_idx].scan_time;
1070 if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE)
1071 scan_dur = adapter->passive_scan_time;
1072 else if (*filtered_scan)
1073 scan_dur = adapter->specific_scan_time;
1075 scan_dur = adapter->active_scan_time;
1078 (scan_chan_list + chan_idx)->min_scan_time =
1079 cpu_to_le16(scan_dur);
1080 (scan_chan_list + chan_idx)->max_scan_time =
1081 cpu_to_le16(scan_dur);
1084 /* Check if we are only scanning the current channel */
1085 if ((chan_idx == 1) &&
1086 (user_scan_in->chan_list[0].chan_number ==
1087 priv->curr_bss_params.bss_descriptor.channel)) {
1088 *scan_current_only = true;
1089 mwifiex_dbg(adapter, INFO,
1090 "info: Scan: Scanning current channel only\n");
1092 chan_num = chan_idx;
1094 mwifiex_dbg(adapter, INFO,
1095 "info: Scan: Creating full region channel list\n");
1096 chan_num = mwifiex_scan_create_channel_list(priv, user_scan_in,
1104 * This function inspects the scan response buffer for pointers to
1107 * TLVs can be included at the end of the scan response BSS information.
1109 * Data in the buffer is parsed pointers to TLVs that can potentially
1110 * be passed back in the response.
1113 mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
1114 struct mwifiex_ie_types_data *tlv,
1115 u32 tlv_buf_size, u32 req_tlv_type,
1116 struct mwifiex_ie_types_data **tlv_data)
1118 struct mwifiex_ie_types_data *current_tlv;
1124 tlv_buf_left = tlv_buf_size;
1127 mwifiex_dbg(adapter, INFO,
1128 "info: SCAN_RESP: tlv_buf_size = %d\n",
1131 while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) {
1133 tlv_type = le16_to_cpu(current_tlv->header.type);
1134 tlv_len = le16_to_cpu(current_tlv->header.len);
1136 if (sizeof(tlv->header) + tlv_len > tlv_buf_left) {
1137 mwifiex_dbg(adapter, ERROR,
1138 "SCAN_RESP: TLV buffer corrupt\n");
1142 if (req_tlv_type == tlv_type) {
1144 case TLV_TYPE_TSFTIMESTAMP:
1145 mwifiex_dbg(adapter, INFO,
1146 "info: SCAN_RESP: TSF\t"
1147 "timestamp TLV, len = %d\n",
1149 *tlv_data = current_tlv;
1151 case TLV_TYPE_CHANNELBANDLIST:
1152 mwifiex_dbg(adapter, INFO,
1153 "info: SCAN_RESP: channel\t"
1154 "band list TLV, len = %d\n",
1156 *tlv_data = current_tlv;
1159 mwifiex_dbg(adapter, ERROR,
1160 "SCAN_RESP: unhandled TLV = %d\n",
1162 /* Give up, this seems corrupted */
1171 tlv_buf_left -= (sizeof(tlv->header) + tlv_len);
1173 (struct mwifiex_ie_types_data *) (current_tlv->data +
1180 * This function parses provided beacon buffer and updates
1181 * respective fields in bss descriptor structure.
1183 int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1184 struct mwifiex_bssdescriptor *bss_entry)
1188 struct ieee_types_fh_param_set *fh_param_set;
1189 struct ieee_types_ds_param_set *ds_param_set;
1190 struct ieee_types_cf_param_set *cf_param_set;
1191 struct ieee_types_ibss_param_set *ibss_param_set;
1198 u8 found_data_rate_ie;
1200 struct ieee_types_vendor_specific *vendor_ie;
1201 const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 };
1202 const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 };
1204 found_data_rate_ie = false;
1206 current_ptr = bss_entry->beacon_buf;
1207 bytes_left = bss_entry->beacon_buf_size;
1209 /* Process variable IE */
1210 while (bytes_left >= 2) {
1211 element_id = *current_ptr;
1212 element_len = *(current_ptr + 1);
1213 total_ie_len = element_len + sizeof(struct ieee_types_header);
1215 if (bytes_left < total_ie_len) {
1216 mwifiex_dbg(adapter, ERROR,
1217 "err: InterpretIE: in processing\t"
1218 "IE, bytes left < IE length\n");
1221 switch (element_id) {
1223 if (element_len > IEEE80211_MAX_SSID_LEN)
1225 bss_entry->ssid.ssid_len = element_len;
1226 memcpy(bss_entry->ssid.ssid, (current_ptr + 2),
1228 mwifiex_dbg(adapter, INFO,
1229 "info: InterpretIE: ssid: %-32s\n",
1230 bss_entry->ssid.ssid);
1233 case WLAN_EID_SUPP_RATES:
1234 if (element_len > MWIFIEX_SUPPORTED_RATES)
1236 memcpy(bss_entry->data_rates, current_ptr + 2,
1238 memcpy(bss_entry->supported_rates, current_ptr + 2,
1240 rate_size = element_len;
1241 found_data_rate_ie = true;
1244 case WLAN_EID_FH_PARAMS:
1245 if (element_len + 2 < sizeof(*fh_param_set))
1248 (struct ieee_types_fh_param_set *) current_ptr;
1249 memcpy(&bss_entry->phy_param_set.fh_param_set,
1251 sizeof(struct ieee_types_fh_param_set));
1254 case WLAN_EID_DS_PARAMS:
1255 if (element_len + 2 < sizeof(*ds_param_set))
1258 (struct ieee_types_ds_param_set *) current_ptr;
1260 bss_entry->channel = ds_param_set->current_chan;
1262 memcpy(&bss_entry->phy_param_set.ds_param_set,
1264 sizeof(struct ieee_types_ds_param_set));
1267 case WLAN_EID_CF_PARAMS:
1268 if (element_len + 2 < sizeof(*cf_param_set))
1271 (struct ieee_types_cf_param_set *) current_ptr;
1272 memcpy(&bss_entry->ss_param_set.cf_param_set,
1274 sizeof(struct ieee_types_cf_param_set));
1277 case WLAN_EID_IBSS_PARAMS:
1278 if (element_len + 2 < sizeof(*ibss_param_set))
1281 (struct ieee_types_ibss_param_set *)
1283 memcpy(&bss_entry->ss_param_set.ibss_param_set,
1285 sizeof(struct ieee_types_ibss_param_set));
1288 case WLAN_EID_ERP_INFO:
1291 bss_entry->erp_flags = *(current_ptr + 2);
1294 case WLAN_EID_PWR_CONSTRAINT:
1297 bss_entry->local_constraint = *(current_ptr + 2);
1298 bss_entry->sensed_11h = true;
1301 case WLAN_EID_CHANNEL_SWITCH:
1302 bss_entry->chan_sw_ie_present = true;
1303 case WLAN_EID_PWR_CAPABILITY:
1304 case WLAN_EID_TPC_REPORT:
1305 case WLAN_EID_QUIET:
1306 bss_entry->sensed_11h = true;
1309 case WLAN_EID_EXT_SUPP_RATES:
1311 * Only process extended supported rate
1312 * if data rate is already found.
1313 * Data rate IE should come before
1314 * extended supported rate IE
1316 if (found_data_rate_ie) {
1317 if ((element_len + rate_size) >
1318 MWIFIEX_SUPPORTED_RATES)
1320 (MWIFIEX_SUPPORTED_RATES -
1323 bytes_to_copy = element_len;
1325 rate = (u8 *) bss_entry->data_rates;
1327 memcpy(rate, current_ptr + 2, bytes_to_copy);
1329 rate = (u8 *) bss_entry->supported_rates;
1331 memcpy(rate, current_ptr + 2, bytes_to_copy);
1335 case WLAN_EID_VENDOR_SPECIFIC:
1336 vendor_ie = (struct ieee_types_vendor_specific *)
1339 /* 802.11 requires at least 3-byte OUI. */
1340 if (element_len < sizeof(vendor_ie->vend_hdr.oui.oui))
1343 /* Not long enough for a match? Skip it. */
1344 if (element_len < sizeof(wpa_oui))
1347 if (!memcmp(&vendor_ie->vend_hdr.oui, wpa_oui,
1349 bss_entry->bcn_wpa_ie =
1350 (struct ieee_types_vendor_specific *)
1352 bss_entry->wpa_offset = (u16)
1353 (current_ptr - bss_entry->beacon_buf);
1354 } else if (!memcmp(&vendor_ie->vend_hdr.oui, wmm_oui,
1357 sizeof(struct ieee_types_wmm_parameter) ||
1359 sizeof(struct ieee_types_wmm_info))
1361 * Only accept and copy the WMM IE if
1362 * it matches the size expected for the
1363 * WMM Info IE or the WMM Parameter IE.
1365 memcpy((u8 *) &bss_entry->wmm_ie,
1366 current_ptr, total_ie_len);
1370 bss_entry->bcn_rsn_ie =
1371 (struct ieee_types_generic *) current_ptr;
1372 bss_entry->rsn_offset = (u16) (current_ptr -
1373 bss_entry->beacon_buf);
1375 case WLAN_EID_BSS_AC_ACCESS_DELAY:
1376 bss_entry->bcn_wapi_ie =
1377 (struct ieee_types_generic *) current_ptr;
1378 bss_entry->wapi_offset = (u16) (current_ptr -
1379 bss_entry->beacon_buf);
1381 case WLAN_EID_HT_CAPABILITY:
1382 bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *)
1384 sizeof(struct ieee_types_header));
1385 bss_entry->ht_cap_offset = (u16) (current_ptr +
1386 sizeof(struct ieee_types_header) -
1387 bss_entry->beacon_buf);
1389 case WLAN_EID_HT_OPERATION:
1390 bss_entry->bcn_ht_oper =
1391 (struct ieee80211_ht_operation *)(current_ptr +
1392 sizeof(struct ieee_types_header));
1393 bss_entry->ht_info_offset = (u16) (current_ptr +
1394 sizeof(struct ieee_types_header) -
1395 bss_entry->beacon_buf);
1397 case WLAN_EID_VHT_CAPABILITY:
1398 bss_entry->disable_11ac = false;
1399 bss_entry->bcn_vht_cap =
1400 (void *)(current_ptr +
1401 sizeof(struct ieee_types_header));
1402 bss_entry->vht_cap_offset =
1403 (u16)((u8 *)bss_entry->bcn_vht_cap -
1404 bss_entry->beacon_buf);
1406 case WLAN_EID_VHT_OPERATION:
1407 bss_entry->bcn_vht_oper =
1408 (void *)(current_ptr +
1409 sizeof(struct ieee_types_header));
1410 bss_entry->vht_info_offset =
1411 (u16)((u8 *)bss_entry->bcn_vht_oper -
1412 bss_entry->beacon_buf);
1414 case WLAN_EID_BSS_COEX_2040:
1415 bss_entry->bcn_bss_co_2040 = current_ptr;
1416 bss_entry->bss_co_2040_offset =
1417 (u16) (current_ptr - bss_entry->beacon_buf);
1419 case WLAN_EID_EXT_CAPABILITY:
1420 bss_entry->bcn_ext_cap = current_ptr;
1421 bss_entry->ext_cap_offset =
1422 (u16) (current_ptr - bss_entry->beacon_buf);
1424 case WLAN_EID_OPMODE_NOTIF:
1425 bss_entry->oper_mode = (void *)current_ptr;
1426 bss_entry->oper_mode_offset =
1427 (u16)((u8 *)bss_entry->oper_mode -
1428 bss_entry->beacon_buf);
1434 current_ptr += element_len + 2;
1436 /* Need to account for IE ID and IE Len */
1437 bytes_left -= (element_len + 2);
1439 } /* while (bytes_left > 2) */
1444 * This function converts radio type scan parameter to a band configuration
1445 * to be used in join command.
1448 mwifiex_radio_type_to_band(u8 radio_type)
1450 switch (radio_type) {
1451 case HostCmd_SCAN_RADIO_TYPE_A:
1453 case HostCmd_SCAN_RADIO_TYPE_BG:
1460 * This is an internal function used to start a scan based on an input
1463 * This uses the input user scan configuration information when provided in
1464 * order to send the appropriate scan commands to firmware to populate or
1465 * update the internal driver scan table.
1467 int mwifiex_scan_networks(struct mwifiex_private *priv,
1468 const struct mwifiex_user_scan_cfg *user_scan_in)
1471 struct mwifiex_adapter *adapter = priv->adapter;
1472 struct cmd_ctrl_node *cmd_node;
1473 union mwifiex_scan_cmd_config_tlv *scan_cfg_out;
1474 struct mwifiex_ie_types_chan_list_param_set *chan_list_out;
1475 struct mwifiex_chan_scan_param_set *scan_chan_list;
1477 u8 scan_current_chan_only;
1478 u8 max_chan_per_scan;
1479 unsigned long flags;
1481 if (adapter->scan_processing) {
1482 mwifiex_dbg(adapter, WARN,
1483 "cmd: Scan already in process...\n");
1487 if (priv->scan_block) {
1488 mwifiex_dbg(adapter, WARN,
1489 "cmd: Scan is blocked during association...\n");
1493 if (adapter->surprise_removed || adapter->is_cmd_timedout) {
1494 mwifiex_dbg(adapter, ERROR,
1495 "Ignore scan. Card removed or firmware in bad state\n");
1499 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1500 adapter->scan_processing = true;
1501 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1503 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
1505 if (!scan_cfg_out) {
1510 scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX,
1511 sizeof(struct mwifiex_chan_scan_param_set),
1513 if (!scan_chan_list) {
1514 kfree(scan_cfg_out);
1519 mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config,
1520 &chan_list_out, scan_chan_list, &max_chan_per_scan,
1521 &filtered_scan, &scan_current_chan_only);
1523 ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan,
1524 &scan_cfg_out->config, chan_list_out,
1527 /* Get scan command from scan_pending_q and put to cmd_pending_q */
1529 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1530 if (!list_empty(&adapter->scan_pending_q)) {
1531 cmd_node = list_first_entry(&adapter->scan_pending_q,
1532 struct cmd_ctrl_node, list);
1533 list_del(&cmd_node->list);
1534 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1536 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1538 queue_work(adapter->workqueue, &adapter->main_work);
1540 /* Perform internal scan synchronously */
1541 if (!priv->scan_request) {
1542 mwifiex_dbg(adapter, INFO,
1543 "wait internal scan\n");
1544 mwifiex_wait_queue_complete(adapter, cmd_node);
1547 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1552 kfree(scan_cfg_out);
1553 kfree(scan_chan_list);
1556 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1557 adapter->scan_processing = false;
1558 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1564 * This function prepares a scan command to be sent to the firmware.
1566 * This uses the scan command configuration sent to the command processing
1567 * module in command preparation stage to configure a scan command structure
1568 * to send to firmware.
1570 * The fixed fields specifying the BSS type and BSSID filters as well as a
1571 * variable number/length of TLVs are sent in the command to firmware.
1573 * Preparation also includes -
1574 * - Setting command ID, and proper size
1575 * - Ensuring correct endian-ness
1577 int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
1578 struct mwifiex_scan_cmd_config *scan_cfg)
1580 struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan;
1582 /* Set fixed field variables in scan command */
1583 scan_cmd->bss_mode = scan_cfg->bss_mode;
1584 memcpy(scan_cmd->bssid, scan_cfg->specific_bssid,
1585 sizeof(scan_cmd->bssid));
1586 memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
1588 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN);
1590 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
1591 cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode)
1592 + sizeof(scan_cmd->bssid)
1593 + scan_cfg->tlv_buf_len + S_DS_GEN));
1599 * This function checks compatibility of requested network with current
1602 int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1603 struct mwifiex_bssdescriptor *bss_desc)
1610 if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
1611 (u16) bss_desc->channel, 0))) {
1612 switch (priv->bss_mode) {
1613 case NL80211_IFTYPE_STATION:
1614 case NL80211_IFTYPE_ADHOC:
1615 ret = mwifiex_is_network_compatible(priv, bss_desc,
1618 mwifiex_dbg(priv->adapter, ERROR,
1619 "Incompatible network settings\n");
1629 /* This function checks if SSID string contains all zeroes or length is zero */
1630 static bool mwifiex_is_hidden_ssid(struct cfg80211_ssid *ssid)
1634 for (idx = 0; idx < ssid->ssid_len; idx++) {
1635 if (ssid->ssid[idx])
1642 /* This function checks if any hidden SSID found in passive scan channels
1643 * and save those channels for specific SSID active scan
1645 static int mwifiex_save_hidden_ssid_channels(struct mwifiex_private *priv,
1646 struct cfg80211_bss *bss)
1648 struct mwifiex_bssdescriptor *bss_desc;
1652 /* Allocate and fill new bss descriptor */
1653 bss_desc = kzalloc(sizeof(*bss_desc), GFP_KERNEL);
1657 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
1661 if (mwifiex_is_hidden_ssid(&bss_desc->ssid)) {
1662 mwifiex_dbg(priv->adapter, INFO, "found hidden SSID\n");
1663 for (chid = 0 ; chid < MWIFIEX_USER_SCAN_CHAN_MAX; chid++) {
1664 if (priv->hidden_chan[chid].chan_number ==
1665 bss->channel->hw_value)
1668 if (!priv->hidden_chan[chid].chan_number) {
1669 priv->hidden_chan[chid].chan_number =
1670 bss->channel->hw_value;
1671 priv->hidden_chan[chid].radio_type =
1673 priv->hidden_chan[chid].scan_type =
1674 MWIFIEX_SCAN_TYPE_ACTIVE;
1685 static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
1686 struct cfg80211_bss *bss)
1688 struct mwifiex_bssdescriptor *bss_desc;
1690 unsigned long flags;
1692 /* Allocate and fill new bss descriptor */
1693 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL);
1697 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
1701 ret = mwifiex_check_network_compatibility(priv, bss_desc);
1705 spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags);
1706 /* Make a copy of current BSSID descriptor */
1707 memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc,
1708 sizeof(priv->curr_bss_params.bss_descriptor));
1710 /* The contents of beacon_ie will be copied to its own buffer
1711 * in mwifiex_save_curr_bcn()
1713 mwifiex_save_curr_bcn(priv);
1714 spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags);
1717 /* beacon_ie buffer was allocated in function
1718 * mwifiex_fill_new_bss_desc(). Free it now.
1720 kfree(bss_desc->beacon_buf);
1726 mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info,
1727 u32 *bytes_left, u64 fw_tsf, u8 *radio_type,
1728 bool ext_scan, s32 rssi_val)
1730 struct mwifiex_adapter *adapter = priv->adapter;
1731 struct mwifiex_chan_freq_power *cfp;
1732 struct cfg80211_bss *bss;
1738 u16 beacon_size = 0;
1742 u16 cap_info_bitmap;
1745 struct mwifiex_fixed_bcn_param *bcn_param;
1746 struct mwifiex_bss_priv *bss_priv;
1748 if (*bytes_left >= sizeof(beacon_size)) {
1749 /* Extract & convert beacon size from command buffer */
1750 beacon_size = le16_to_cpu(*(__le16 *)(*bss_info));
1751 *bytes_left -= sizeof(beacon_size);
1752 *bss_info += sizeof(beacon_size);
1755 if (!beacon_size || beacon_size > *bytes_left) {
1756 *bss_info += *bytes_left;
1761 /* Initialize the current working beacon pointer for this BSS
1764 current_ptr = *bss_info;
1766 /* Advance the return beacon pointer past the current beacon */
1767 *bss_info += beacon_size;
1768 *bytes_left -= beacon_size;
1770 curr_bcn_bytes = beacon_size;
1772 /* First 5 fields are bssid, RSSI(for legacy scan only),
1773 * time stamp, beacon interval, and capability information
1775 if (curr_bcn_bytes < ETH_ALEN + sizeof(u8) +
1776 sizeof(struct mwifiex_fixed_bcn_param)) {
1777 mwifiex_dbg(adapter, ERROR,
1778 "InterpretIE: not enough bytes left\n");
1782 memcpy(bssid, current_ptr, ETH_ALEN);
1783 current_ptr += ETH_ALEN;
1784 curr_bcn_bytes -= ETH_ALEN;
1787 rssi = (s32) *current_ptr;
1788 rssi = (-rssi) * 100; /* Convert dBm to mBm */
1789 current_ptr += sizeof(u8);
1790 curr_bcn_bytes -= sizeof(u8);
1791 mwifiex_dbg(adapter, INFO,
1792 "info: InterpretIE: RSSI=%d\n", rssi);
1797 bcn_param = (struct mwifiex_fixed_bcn_param *)current_ptr;
1798 current_ptr += sizeof(*bcn_param);
1799 curr_bcn_bytes -= sizeof(*bcn_param);
1801 timestamp = le64_to_cpu(bcn_param->timestamp);
1802 beacon_period = le16_to_cpu(bcn_param->beacon_period);
1804 cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
1805 mwifiex_dbg(adapter, INFO,
1806 "info: InterpretIE: capabilities=0x%X\n",
1809 /* Rest of the current buffer are IE's */
1810 ie_buf = current_ptr;
1811 ie_len = curr_bcn_bytes;
1812 mwifiex_dbg(adapter, INFO,
1813 "info: InterpretIE: IELength for this AP = %d\n",
1816 while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) {
1817 u8 element_id, element_len;
1819 element_id = *current_ptr;
1820 element_len = *(current_ptr + 1);
1821 if (curr_bcn_bytes < element_len +
1822 sizeof(struct ieee_types_header)) {
1823 mwifiex_dbg(adapter, ERROR,
1824 "%s: bytes left < IE length\n", __func__);
1827 if (element_id == WLAN_EID_DS_PARAMS) {
1828 channel = *(current_ptr +
1829 sizeof(struct ieee_types_header));
1833 current_ptr += element_len + sizeof(struct ieee_types_header);
1834 curr_bcn_bytes -= element_len +
1835 sizeof(struct ieee_types_header);
1839 struct ieee80211_channel *chan;
1842 /* Skip entry if on csa closed channel */
1843 if (channel == priv->csa_chan) {
1844 mwifiex_dbg(adapter, WARN,
1845 "Dropping entry on csa closed channel\n");
1851 band = mwifiex_radio_type_to_band(*radio_type &
1854 cfp = mwifiex_get_cfp(priv, band, channel, 0);
1856 freq = cfp ? cfp->freq : 0;
1858 chan = ieee80211_get_channel(priv->wdev.wiphy, freq);
1860 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
1861 bss = cfg80211_inform_bss(priv->wdev.wiphy,
1862 chan, CFG80211_BSS_FTYPE_UNKNOWN,
1864 cap_info_bitmap, beacon_period,
1865 ie_buf, ie_len, rssi, GFP_ATOMIC);
1867 bss_priv = (struct mwifiex_bss_priv *)bss->priv;
1868 bss_priv->band = band;
1869 bss_priv->fw_tsf = fw_tsf;
1870 if (priv->media_connected &&
1871 !memcmp(bssid, priv->curr_bss_params.
1872 bss_descriptor.mac_address,
1874 mwifiex_update_curr_bss_params(priv,
1877 if ((chan->flags & IEEE80211_CHAN_RADAR) ||
1878 (chan->flags & IEEE80211_CHAN_NO_IR)) {
1879 mwifiex_dbg(adapter, INFO,
1880 "radar or passive channel %d\n",
1882 mwifiex_save_hidden_ssid_channels(priv,
1886 cfg80211_put_bss(priv->wdev.wiphy, bss);
1890 mwifiex_dbg(adapter, WARN, "missing BSS channel IE\n");
1896 static void mwifiex_complete_scan(struct mwifiex_private *priv)
1898 struct mwifiex_adapter *adapter = priv->adapter;
1900 adapter->survey_idx = 0;
1901 if (adapter->curr_cmd->wait_q_enabled) {
1902 adapter->cmd_wait_q.status = 0;
1903 if (!priv->scan_request) {
1904 mwifiex_dbg(adapter, INFO,
1905 "complete internal scan\n");
1906 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1911 /* This function checks if any hidden SSID found in passive scan channels
1912 * and do specific SSID active scan for those channels
1915 mwifiex_active_scan_req_for_passive_chan(struct mwifiex_private *priv)
1918 struct mwifiex_adapter *adapter = priv->adapter;
1920 struct mwifiex_user_scan_cfg *user_scan_cfg;
1922 if (adapter->active_scan_triggered || !priv->scan_request) {
1923 adapter->active_scan_triggered = false;
1927 if (!priv->hidden_chan[0].chan_number) {
1928 mwifiex_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n");
1931 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1936 memset(user_scan_cfg, 0, sizeof(*user_scan_cfg));
1938 for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) {
1939 if (!priv->hidden_chan[id].chan_number)
1941 memcpy(&user_scan_cfg->chan_list[id],
1942 &priv->hidden_chan[id],
1943 sizeof(struct mwifiex_user_scan_chan));
1946 adapter->active_scan_triggered = true;
1947 user_scan_cfg->num_ssids = priv->scan_request->n_ssids;
1948 user_scan_cfg->ssid_list = priv->scan_request->ssids;
1950 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1951 kfree(user_scan_cfg);
1953 memset(&priv->hidden_chan, 0, sizeof(priv->hidden_chan));
1956 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1962 static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1964 struct mwifiex_adapter *adapter = priv->adapter;
1965 struct cmd_ctrl_node *cmd_node, *tmp_node;
1966 unsigned long flags;
1968 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1969 if (list_empty(&adapter->scan_pending_q)) {
1970 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1971 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1972 adapter->scan_processing = false;
1973 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1975 mwifiex_active_scan_req_for_passive_chan(priv);
1977 if (!adapter->ext_scan)
1978 mwifiex_complete_scan(priv);
1980 if (priv->scan_request) {
1981 mwifiex_dbg(adapter, INFO,
1982 "info: notifying scan done\n");
1983 cfg80211_scan_done(priv->scan_request, 0);
1984 priv->scan_request = NULL;
1986 priv->scan_aborting = false;
1987 mwifiex_dbg(adapter, INFO,
1988 "info: scan already aborted\n");
1990 } else if ((priv->scan_aborting && !priv->scan_request) ||
1992 list_for_each_entry_safe(cmd_node, tmp_node,
1993 &adapter->scan_pending_q, list) {
1994 list_del(&cmd_node->list);
1995 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
1997 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1999 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
2000 adapter->scan_processing = false;
2001 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
2003 if (!adapter->active_scan_triggered) {
2004 if (priv->scan_request) {
2005 mwifiex_dbg(adapter, INFO,
2006 "info: aborting scan\n");
2007 cfg80211_scan_done(priv->scan_request, 1);
2008 priv->scan_request = NULL;
2010 priv->scan_aborting = false;
2011 mwifiex_dbg(adapter, INFO,
2012 "info: scan already aborted\n");
2016 /* Get scan command from scan_pending_q and put to
2019 cmd_node = list_first_entry(&adapter->scan_pending_q,
2020 struct cmd_ctrl_node, list);
2021 list_del(&cmd_node->list);
2022 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2023 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
2030 * This function handles the command response of scan.
2032 * The response buffer for the scan command has the following
2035 * .-------------------------------------------------------------.
2036 * | Header (4 * sizeof(t_u16)): Standard command response hdr |
2037 * .-------------------------------------------------------------.
2038 * | BufSize (t_u16) : sizeof the BSS Description data |
2039 * .-------------------------------------------------------------.
2040 * | NumOfSet (t_u8) : Number of BSS Descs returned |
2041 * .-------------------------------------------------------------.
2042 * | BSSDescription data (variable, size given in BufSize) |
2043 * .-------------------------------------------------------------.
2044 * | TLV data (variable, size calculated using Header->Size, |
2045 * | BufSize and sizeof the fixed fields above) |
2046 * .-------------------------------------------------------------.
2048 int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
2049 struct host_cmd_ds_command *resp)
2052 struct mwifiex_adapter *adapter = priv->adapter;
2053 struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
2054 struct mwifiex_ie_types_data *tlv_data;
2055 struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
2061 struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
2062 struct chan_band_param_set *chan_band;
2067 is_bgscan_resp = (le16_to_cpu(resp->command)
2068 == HostCmd_CMD_802_11_BG_SCAN_QUERY);
2070 scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
2072 scan_rsp = &resp->params.scan_resp;
2075 if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
2076 mwifiex_dbg(adapter, ERROR,
2077 "SCAN_RESP: too many AP returned (%d)\n",
2078 scan_rsp->number_of_sets);
2080 goto check_next_scan;
2083 /* Check csa channel expiry before parsing scan response */
2084 mwifiex_11h_get_csa_closed_channel(priv);
2086 bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
2087 mwifiex_dbg(adapter, INFO,
2088 "info: SCAN_RESP: bss_descript_size %d\n",
2091 scan_resp_size = le16_to_cpu(resp->size);
2093 mwifiex_dbg(adapter, INFO,
2094 "info: SCAN_RESP: returned %d APs before parsing\n",
2095 scan_rsp->number_of_sets);
2097 bss_info = scan_rsp->bss_desc_and_tlv_buffer;
2100 * The size of the TLV buffer is equal to the entire command response
2101 * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
2102 * BSS Descriptions (bss_descript_size as bytesLef) and the command
2103 * response header (S_DS_GEN)
2105 tlv_buf_size = scan_resp_size - (bytes_left
2106 + sizeof(scan_rsp->bss_descript_size)
2107 + sizeof(scan_rsp->number_of_sets)
2110 tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
2111 bss_desc_and_tlv_buffer +
2114 /* Search the TLV buffer space in the scan response for any valid
2116 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2117 TLV_TYPE_TSFTIMESTAMP,
2118 (struct mwifiex_ie_types_data **)
2121 /* Search the TLV buffer space in the scan response for any valid
2123 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2124 TLV_TYPE_CHANNELBANDLIST,
2125 (struct mwifiex_ie_types_data **)
2128 for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
2130 * If the TSF TLV was appended to the scan results, save this
2131 * entry's TSF value in the fw_tsf field. It is the firmware's
2132 * TSF value at the time the beacon or probe response was
2136 memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
2139 if (chan_band_tlv) {
2140 chan_band = &chan_band_tlv->chan_band_param[idx];
2141 radio_type = &chan_band->radio_type;
2146 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2148 le64_to_cpu(fw_tsf),
2149 radio_type, false, 0);
2151 goto check_next_scan;
2155 mwifiex_check_next_scan_command(priv);
2160 * This function prepares an extended scan command to be sent to the firmware
2162 * This uses the scan command configuration sent to the command processing
2163 * module in command preparation stage to configure a extended scan command
2164 * structure to send to firmware.
2166 int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
2167 struct host_cmd_ds_command *cmd,
2170 struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan;
2171 struct mwifiex_scan_cmd_config *scan_cfg = data_buf;
2173 memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
2175 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT);
2177 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
2178 cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved)
2179 + scan_cfg->tlv_buf_len + S_DS_GEN));
2185 mwifiex_update_chan_statistics(struct mwifiex_private *priv,
2186 struct mwifiex_ietypes_chanstats *tlv_stat)
2188 struct mwifiex_adapter *adapter = priv->adapter;
2190 struct mwifiex_fw_chan_stats *fw_chan_stats;
2191 struct mwifiex_chan_stats chan_stats;
2193 fw_chan_stats = (void *)((u8 *)tlv_stat +
2194 sizeof(struct mwifiex_ie_types_header));
2195 num_chan = le16_to_cpu(tlv_stat->header.len) /
2196 sizeof(struct mwifiex_chan_stats);
2198 for (i = 0 ; i < num_chan; i++) {
2199 if (adapter->survey_idx >= adapter->num_in_chan_stats) {
2200 mwifiex_dbg(adapter, WARN,
2201 "FW reported too many channel results (max %d)\n",
2202 adapter->num_in_chan_stats);
2205 chan_stats.chan_num = fw_chan_stats->chan_num;
2206 chan_stats.bandcfg = fw_chan_stats->bandcfg;
2207 chan_stats.flags = fw_chan_stats->flags;
2208 chan_stats.noise = fw_chan_stats->noise;
2209 chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss);
2210 chan_stats.cca_scan_dur =
2211 le16_to_cpu(fw_chan_stats->cca_scan_dur);
2212 chan_stats.cca_busy_dur =
2213 le16_to_cpu(fw_chan_stats->cca_busy_dur);
2214 mwifiex_dbg(adapter, INFO,
2215 "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n",
2216 chan_stats.chan_num,
2218 chan_stats.total_bss,
2219 chan_stats.cca_scan_dur,
2220 chan_stats.cca_busy_dur);
2221 memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats,
2222 sizeof(struct mwifiex_chan_stats));
2227 /* This function handles the command response of extended scan */
2228 int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
2229 struct host_cmd_ds_command *resp)
2231 struct mwifiex_adapter *adapter = priv->adapter;
2232 struct host_cmd_ds_802_11_scan_ext *ext_scan_resp;
2233 struct mwifiex_ie_types_header *tlv;
2234 struct mwifiex_ietypes_chanstats *tlv_stat;
2235 u16 buf_left, type, len;
2237 struct host_cmd_ds_command *cmd_ptr;
2238 struct cmd_ctrl_node *cmd_node;
2239 unsigned long cmd_flags, scan_flags;
2240 bool complete_scan = false;
2242 mwifiex_dbg(adapter, INFO, "info: EXT scan returns successfully\n");
2244 ext_scan_resp = &resp->params.ext_scan;
2246 tlv = (void *)ext_scan_resp->tlv_buffer;
2247 buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN
2250 while (buf_left >= sizeof(struct mwifiex_ie_types_header)) {
2251 type = le16_to_cpu(tlv->type);
2252 len = le16_to_cpu(tlv->len);
2254 if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) {
2255 mwifiex_dbg(adapter, ERROR,
2256 "error processing scan response TLVs");
2261 case TLV_TYPE_CHANNEL_STATS:
2262 tlv_stat = (void *)tlv;
2263 mwifiex_update_chan_statistics(priv, tlv_stat);
2269 buf_left -= len + sizeof(struct mwifiex_ie_types_header);
2270 tlv = (void *)((u8 *)tlv + len +
2271 sizeof(struct mwifiex_ie_types_header));
2274 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
2275 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
2276 if (list_empty(&adapter->scan_pending_q)) {
2277 complete_scan = true;
2278 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
2279 cmd_ptr = (void *)cmd_node->cmd_skb->data;
2280 if (le16_to_cpu(cmd_ptr->command) ==
2281 HostCmd_CMD_802_11_SCAN_EXT) {
2282 mwifiex_dbg(adapter, INFO,
2283 "Scan pending in command pending list");
2284 complete_scan = false;
2289 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags);
2290 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags);
2293 mwifiex_complete_scan(priv);
2298 /* This function This function handles the event extended scan report. It
2299 * parses extended scan results and informs to cfg80211 stack.
2301 int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
2305 struct mwifiex_adapter *adapter = priv->adapter;
2307 u32 bytes_left, bytes_left_for_tlv, idx;
2309 struct mwifiex_ie_types_data *tlv;
2310 struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv;
2311 struct mwifiex_ie_types_bss_scan_info *scan_info_tlv;
2315 struct mwifiex_event_scan_result *event_scan = buf;
2316 u8 num_of_set = event_scan->num_of_set;
2317 u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
2318 u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
2320 if (num_of_set > MWIFIEX_MAX_AP) {
2321 mwifiex_dbg(adapter, ERROR,
2322 "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
2325 goto check_next_scan;
2328 bytes_left = scan_resp_size;
2329 mwifiex_dbg(adapter, INFO,
2330 "EXT_SCAN: size %d, returned %d APs...",
2331 scan_resp_size, num_of_set);
2332 mwifiex_dbg_dump(adapter, CMD_D, "EXT_SCAN buffer:", buf,
2334 sizeof(struct mwifiex_event_scan_result));
2336 tlv = (struct mwifiex_ie_types_data *)scan_resp;
2338 for (idx = 0; idx < num_of_set && bytes_left; idx++) {
2339 type = le16_to_cpu(tlv->header.type);
2340 len = le16_to_cpu(tlv->header.len);
2341 if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) {
2342 mwifiex_dbg(adapter, ERROR,
2343 "EXT_SCAN: Error bytes left < TLV length\n");
2346 scan_rsp_tlv = NULL;
2347 scan_info_tlv = NULL;
2348 bytes_left_for_tlv = bytes_left;
2350 /* BSS response TLV with beacon or probe response buffer
2351 * at the initial position of each descriptor
2353 if (type != TLV_TYPE_BSS_SCAN_RSP)
2356 bss_info = (u8 *)tlv;
2357 scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv;
2358 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2359 bytes_left_for_tlv -=
2360 (len + sizeof(struct mwifiex_ie_types_header));
2362 while (bytes_left_for_tlv >=
2363 sizeof(struct mwifiex_ie_types_header) &&
2364 le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) {
2365 type = le16_to_cpu(tlv->header.type);
2366 len = le16_to_cpu(tlv->header.len);
2367 if (bytes_left_for_tlv <
2368 sizeof(struct mwifiex_ie_types_header) + len) {
2369 mwifiex_dbg(adapter, ERROR,
2370 "EXT_SCAN: Error in processing TLV,\t"
2371 "bytes left < TLV length\n");
2372 scan_rsp_tlv = NULL;
2373 bytes_left_for_tlv = 0;
2377 case TLV_TYPE_BSS_SCAN_INFO:
2379 (struct mwifiex_ie_types_bss_scan_info *)tlv;
2381 sizeof(struct mwifiex_ie_types_bss_scan_info) -
2382 sizeof(struct mwifiex_ie_types_header)) {
2383 bytes_left_for_tlv = 0;
2390 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2392 (len + sizeof(struct mwifiex_ie_types_header));
2393 bytes_left_for_tlv -=
2394 (len + sizeof(struct mwifiex_ie_types_header));
2400 /* Advance pointer to the beacon buffer length and
2401 * update the bytes count so that the function
2402 * wlan_interpret_bss_desc_with_ie() can handle the
2403 * scan buffer withut any change
2405 bss_info += sizeof(u16);
2406 bytes_left -= sizeof(u16);
2408 if (scan_info_tlv) {
2409 rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi));
2410 rssi *= 100; /* Convert dBm to mBm */
2411 mwifiex_dbg(adapter, INFO,
2412 "info: InterpretIE: RSSI=%d\n", rssi);
2413 fw_tsf = le64_to_cpu(scan_info_tlv->tsf);
2414 radio_type = &scan_info_tlv->radio_type;
2418 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2419 &bytes_left, fw_tsf,
2420 radio_type, true, rssi);
2422 goto check_next_scan;
2426 if (!event_scan->more_event)
2427 mwifiex_check_next_scan_command(priv);
2433 * This function prepares command for background scan query.
2435 * Preparation includes -
2436 * - Setting command ID and proper size
2437 * - Setting background scan flush parameter
2438 * - Ensuring correct endian-ness
2440 int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
2442 struct host_cmd_ds_802_11_bg_scan_query *bg_query =
2443 &cmd->params.bg_scan_query;
2445 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
2446 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
2449 bg_query->flush = 1;
2455 * This function inserts scan command node to the scan pending queue.
2458 mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
2459 struct cmd_ctrl_node *cmd_node)
2461 struct mwifiex_adapter *adapter = priv->adapter;
2462 unsigned long flags;
2464 cmd_node->wait_q_enabled = true;
2465 cmd_node->condition = &adapter->scan_wait_q_woken;
2466 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
2467 list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
2468 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2472 * This function sends a scan command for all available channels to the
2473 * firmware, filtered on a specific SSID.
2475 static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
2476 struct cfg80211_ssid *req_ssid)
2478 struct mwifiex_adapter *adapter = priv->adapter;
2480 struct mwifiex_user_scan_cfg *scan_cfg;
2482 if (adapter->scan_processing) {
2483 mwifiex_dbg(adapter, WARN,
2484 "cmd: Scan already in process...\n");
2488 if (priv->scan_block) {
2489 mwifiex_dbg(adapter, WARN,
2490 "cmd: Scan is blocked during association...\n");
2494 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
2498 scan_cfg->ssid_list = req_ssid;
2499 scan_cfg->num_ssids = 1;
2501 ret = mwifiex_scan_networks(priv, scan_cfg);
2508 * Sends IOCTL request to start a scan.
2510 * This function allocates the IOCTL request buffer, fills it
2511 * with requisite parameters and calls the IOCTL handler.
2513 * Scan command can be issued for both normal scan and specific SSID
2514 * scan, depending upon whether an SSID is provided or not.
2516 int mwifiex_request_scan(struct mwifiex_private *priv,
2517 struct cfg80211_ssid *req_ssid)
2521 if (down_interruptible(&priv->async_sem)) {
2522 mwifiex_dbg(priv->adapter, ERROR,
2523 "%s: acquire semaphore fail\n",
2528 priv->adapter->scan_wait_q_woken = false;
2530 if (req_ssid && req_ssid->ssid_len != 0)
2531 /* Specific SSID scan */
2532 ret = mwifiex_scan_specific_ssid(priv, req_ssid);
2535 ret = mwifiex_scan_networks(priv, NULL);
2537 up(&priv->async_sem);
2543 * This function appends the vendor specific IE TLV to a buffer.
2546 mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
2547 u16 vsie_mask, u8 **buffer)
2549 int id, ret_len = 0;
2550 struct mwifiex_ie_types_vendor_param_set *vs_param_set;
2558 * Traverse through the saved vendor specific IE array and append
2559 * the selected(scan/assoc/adhoc) IE as TLV to the command
2561 for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
2562 if (priv->vs_ie[id].mask & vsie_mask) {
2564 (struct mwifiex_ie_types_vendor_param_set *)
2566 vs_param_set->header.type =
2567 cpu_to_le16(TLV_TYPE_PASSTHROUGH);
2568 vs_param_set->header.len =
2569 cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
2571 if (le16_to_cpu(vs_param_set->header.len) >
2572 MWIFIEX_MAX_VSIE_LEN) {
2573 mwifiex_dbg(priv->adapter, ERROR,
2574 "Invalid param length!\n");
2578 memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
2579 le16_to_cpu(vs_param_set->header.len));
2580 *buffer += le16_to_cpu(vs_param_set->header.len) +
2581 sizeof(struct mwifiex_ie_types_header);
2582 ret_len += le16_to_cpu(vs_param_set->header.len) +
2583 sizeof(struct mwifiex_ie_types_header);
2590 * This function saves a beacon buffer of the current BSS descriptor.
2592 * The current beacon buffer is saved so that it can be restored in the
2593 * following cases that makes the beacon buffer not to contain the current
2594 * ssid's beacon buffer.
2595 * - The current ssid was not found somehow in the last scan.
2596 * - The current ssid was the last entry of the scan table and overloaded.
2599 mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2601 struct mwifiex_bssdescriptor *curr_bss =
2602 &priv->curr_bss_params.bss_descriptor;
2604 if (!curr_bss->beacon_buf_size)
2607 /* allocate beacon buffer at 1st time; or if it's size has changed */
2608 if (!priv->curr_bcn_buf ||
2609 priv->curr_bcn_size != curr_bss->beacon_buf_size) {
2610 priv->curr_bcn_size = curr_bss->beacon_buf_size;
2612 kfree(priv->curr_bcn_buf);
2613 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
2615 if (!priv->curr_bcn_buf)
2619 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
2620 curr_bss->beacon_buf_size);
2621 mwifiex_dbg(priv->adapter, INFO,
2622 "info: current beacon saved %d\n",
2623 priv->curr_bcn_size);
2625 curr_bss->beacon_buf = priv->curr_bcn_buf;
2627 /* adjust the pointers in the current BSS descriptor */
2628 if (curr_bss->bcn_wpa_ie)
2629 curr_bss->bcn_wpa_ie =
2630 (struct ieee_types_vendor_specific *)
2631 (curr_bss->beacon_buf +
2632 curr_bss->wpa_offset);
2634 if (curr_bss->bcn_rsn_ie)
2635 curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
2636 (curr_bss->beacon_buf +
2637 curr_bss->rsn_offset);
2639 if (curr_bss->bcn_ht_cap)
2640 curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
2641 (curr_bss->beacon_buf +
2642 curr_bss->ht_cap_offset);
2644 if (curr_bss->bcn_ht_oper)
2645 curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
2646 (curr_bss->beacon_buf +
2647 curr_bss->ht_info_offset);
2649 if (curr_bss->bcn_vht_cap)
2650 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2651 curr_bss->vht_cap_offset);
2653 if (curr_bss->bcn_vht_oper)
2654 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2655 curr_bss->vht_info_offset);
2657 if (curr_bss->bcn_bss_co_2040)
2658 curr_bss->bcn_bss_co_2040 =
2659 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
2661 if (curr_bss->bcn_ext_cap)
2662 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2663 curr_bss->ext_cap_offset;
2665 if (curr_bss->oper_mode)
2666 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2667 curr_bss->oper_mode_offset);
2671 * This function frees the current BSS descriptor beacon buffer.
2674 mwifiex_free_curr_bcn(struct mwifiex_private *priv)
2676 kfree(priv->curr_bcn_buf);
2677 priv->curr_bcn_buf = NULL;