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 nl80211_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 < NUM_NL80211_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_KERNEL);
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,
1876 cfg80211_put_bss(priv->wdev.wiphy, bss);
1879 if ((chan->flags & IEEE80211_CHAN_RADAR) ||
1880 (chan->flags & IEEE80211_CHAN_NO_IR)) {
1881 mwifiex_dbg(adapter, INFO,
1882 "radar or passive channel %d\n",
1884 mwifiex_save_hidden_ssid_channels(priv, bss);
1888 mwifiex_dbg(adapter, WARN, "missing BSS channel IE\n");
1894 static void mwifiex_complete_scan(struct mwifiex_private *priv)
1896 struct mwifiex_adapter *adapter = priv->adapter;
1898 adapter->survey_idx = 0;
1899 if (adapter->curr_cmd->wait_q_enabled) {
1900 adapter->cmd_wait_q.status = 0;
1901 if (!priv->scan_request) {
1902 mwifiex_dbg(adapter, INFO,
1903 "complete internal scan\n");
1904 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1909 /* This function checks if any hidden SSID found in passive scan channels
1910 * and do specific SSID active scan for those channels
1913 mwifiex_active_scan_req_for_passive_chan(struct mwifiex_private *priv)
1916 struct mwifiex_adapter *adapter = priv->adapter;
1918 struct mwifiex_user_scan_cfg *user_scan_cfg;
1920 if (adapter->active_scan_triggered || !priv->scan_request) {
1921 adapter->active_scan_triggered = false;
1925 if (!priv->hidden_chan[0].chan_number) {
1926 mwifiex_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n");
1929 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
1934 memset(user_scan_cfg, 0, sizeof(*user_scan_cfg));
1936 for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) {
1937 if (!priv->hidden_chan[id].chan_number)
1939 memcpy(&user_scan_cfg->chan_list[id],
1940 &priv->hidden_chan[id],
1941 sizeof(struct mwifiex_user_scan_chan));
1944 adapter->active_scan_triggered = true;
1945 user_scan_cfg->num_ssids = priv->scan_request->n_ssids;
1946 user_scan_cfg->ssid_list = priv->scan_request->ssids;
1948 ret = mwifiex_scan_networks(priv, user_scan_cfg);
1949 kfree(user_scan_cfg);
1951 memset(&priv->hidden_chan, 0, sizeof(priv->hidden_chan));
1954 dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
1960 static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1962 struct mwifiex_adapter *adapter = priv->adapter;
1963 struct cmd_ctrl_node *cmd_node, *tmp_node;
1964 unsigned long flags;
1966 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
1967 if (list_empty(&adapter->scan_pending_q)) {
1968 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1969 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1970 adapter->scan_processing = false;
1971 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1973 mwifiex_active_scan_req_for_passive_chan(priv);
1975 if (!adapter->ext_scan)
1976 mwifiex_complete_scan(priv);
1978 if (priv->scan_request) {
1979 mwifiex_dbg(adapter, INFO,
1980 "info: notifying scan done\n");
1981 cfg80211_scan_done(priv->scan_request, 0);
1982 priv->scan_request = NULL;
1984 priv->scan_aborting = false;
1985 mwifiex_dbg(adapter, INFO,
1986 "info: scan already aborted\n");
1988 } else if ((priv->scan_aborting && !priv->scan_request) ||
1990 list_for_each_entry_safe(cmd_node, tmp_node,
1991 &adapter->scan_pending_q, list) {
1992 list_del(&cmd_node->list);
1993 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
1995 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
1997 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
1998 adapter->scan_processing = false;
1999 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
2001 if (!adapter->active_scan_triggered) {
2002 if (priv->scan_request) {
2003 mwifiex_dbg(adapter, INFO,
2004 "info: aborting scan\n");
2005 cfg80211_scan_done(priv->scan_request, 1);
2006 priv->scan_request = NULL;
2008 priv->scan_aborting = false;
2009 mwifiex_dbg(adapter, INFO,
2010 "info: scan already aborted\n");
2014 /* Get scan command from scan_pending_q and put to
2017 cmd_node = list_first_entry(&adapter->scan_pending_q,
2018 struct cmd_ctrl_node, list);
2019 list_del(&cmd_node->list);
2020 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2021 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
2028 * This function handles the command response of scan.
2030 * The response buffer for the scan command has the following
2033 * .-------------------------------------------------------------.
2034 * | Header (4 * sizeof(t_u16)): Standard command response hdr |
2035 * .-------------------------------------------------------------.
2036 * | BufSize (t_u16) : sizeof the BSS Description data |
2037 * .-------------------------------------------------------------.
2038 * | NumOfSet (t_u8) : Number of BSS Descs returned |
2039 * .-------------------------------------------------------------.
2040 * | BSSDescription data (variable, size given in BufSize) |
2041 * .-------------------------------------------------------------.
2042 * | TLV data (variable, size calculated using Header->Size, |
2043 * | BufSize and sizeof the fixed fields above) |
2044 * .-------------------------------------------------------------.
2046 int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
2047 struct host_cmd_ds_command *resp)
2050 struct mwifiex_adapter *adapter = priv->adapter;
2051 struct host_cmd_ds_802_11_scan_rsp *scan_rsp;
2052 struct mwifiex_ie_types_data *tlv_data;
2053 struct mwifiex_ie_types_tsf_timestamp *tsf_tlv;
2059 struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;
2060 struct chan_band_param_set *chan_band;
2065 is_bgscan_resp = (le16_to_cpu(resp->command)
2066 == HostCmd_CMD_802_11_BG_SCAN_QUERY);
2068 scan_rsp = &resp->params.bg_scan_query_resp.scan_resp;
2070 scan_rsp = &resp->params.scan_resp;
2073 if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) {
2074 mwifiex_dbg(adapter, ERROR,
2075 "SCAN_RESP: too many AP returned (%d)\n",
2076 scan_rsp->number_of_sets);
2078 goto check_next_scan;
2081 /* Check csa channel expiry before parsing scan response */
2082 mwifiex_11h_get_csa_closed_channel(priv);
2084 bytes_left = le16_to_cpu(scan_rsp->bss_descript_size);
2085 mwifiex_dbg(adapter, INFO,
2086 "info: SCAN_RESP: bss_descript_size %d\n",
2089 scan_resp_size = le16_to_cpu(resp->size);
2091 mwifiex_dbg(adapter, INFO,
2092 "info: SCAN_RESP: returned %d APs before parsing\n",
2093 scan_rsp->number_of_sets);
2095 bss_info = scan_rsp->bss_desc_and_tlv_buffer;
2098 * The size of the TLV buffer is equal to the entire command response
2099 * size (scan_resp_size) minus the fixed fields (sizeof()'s), the
2100 * BSS Descriptions (bss_descript_size as bytesLef) and the command
2101 * response header (S_DS_GEN)
2103 tlv_buf_size = scan_resp_size - (bytes_left
2104 + sizeof(scan_rsp->bss_descript_size)
2105 + sizeof(scan_rsp->number_of_sets)
2108 tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp->
2109 bss_desc_and_tlv_buffer +
2112 /* Search the TLV buffer space in the scan response for any valid
2114 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2115 TLV_TYPE_TSFTIMESTAMP,
2116 (struct mwifiex_ie_types_data **)
2119 /* Search the TLV buffer space in the scan response for any valid
2121 mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size,
2122 TLV_TYPE_CHANNELBANDLIST,
2123 (struct mwifiex_ie_types_data **)
2126 for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) {
2128 * If the TSF TLV was appended to the scan results, save this
2129 * entry's TSF value in the fw_tsf field. It is the firmware's
2130 * TSF value at the time the beacon or probe response was
2134 memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
2137 if (chan_band_tlv) {
2138 chan_band = &chan_band_tlv->chan_band_param[idx];
2139 radio_type = &chan_band->radio_type;
2144 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2146 le64_to_cpu(fw_tsf),
2147 radio_type, false, 0);
2149 goto check_next_scan;
2153 mwifiex_check_next_scan_command(priv);
2158 * This function prepares an extended scan command to be sent to the firmware
2160 * This uses the scan command configuration sent to the command processing
2161 * module in command preparation stage to configure a extended scan command
2162 * structure to send to firmware.
2164 int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
2165 struct host_cmd_ds_command *cmd,
2168 struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan;
2169 struct mwifiex_scan_cmd_config *scan_cfg = data_buf;
2171 memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len);
2173 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT);
2175 /* Size is equal to the sizeof(fixed portions) + the TLV len + header */
2176 cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved)
2177 + scan_cfg->tlv_buf_len + S_DS_GEN));
2183 mwifiex_update_chan_statistics(struct mwifiex_private *priv,
2184 struct mwifiex_ietypes_chanstats *tlv_stat)
2186 struct mwifiex_adapter *adapter = priv->adapter;
2188 struct mwifiex_fw_chan_stats *fw_chan_stats;
2189 struct mwifiex_chan_stats chan_stats;
2191 fw_chan_stats = (void *)((u8 *)tlv_stat +
2192 sizeof(struct mwifiex_ie_types_header));
2193 num_chan = le16_to_cpu(tlv_stat->header.len) /
2194 sizeof(struct mwifiex_chan_stats);
2196 for (i = 0 ; i < num_chan; i++) {
2197 if (adapter->survey_idx >= adapter->num_in_chan_stats) {
2198 mwifiex_dbg(adapter, WARN,
2199 "FW reported too many channel results (max %d)\n",
2200 adapter->num_in_chan_stats);
2203 chan_stats.chan_num = fw_chan_stats->chan_num;
2204 chan_stats.bandcfg = fw_chan_stats->bandcfg;
2205 chan_stats.flags = fw_chan_stats->flags;
2206 chan_stats.noise = fw_chan_stats->noise;
2207 chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss);
2208 chan_stats.cca_scan_dur =
2209 le16_to_cpu(fw_chan_stats->cca_scan_dur);
2210 chan_stats.cca_busy_dur =
2211 le16_to_cpu(fw_chan_stats->cca_busy_dur);
2212 mwifiex_dbg(adapter, INFO,
2213 "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n",
2214 chan_stats.chan_num,
2216 chan_stats.total_bss,
2217 chan_stats.cca_scan_dur,
2218 chan_stats.cca_busy_dur);
2219 memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats,
2220 sizeof(struct mwifiex_chan_stats));
2225 /* This function handles the command response of extended scan */
2226 int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
2227 struct host_cmd_ds_command *resp)
2229 struct mwifiex_adapter *adapter = priv->adapter;
2230 struct host_cmd_ds_802_11_scan_ext *ext_scan_resp;
2231 struct mwifiex_ie_types_header *tlv;
2232 struct mwifiex_ietypes_chanstats *tlv_stat;
2233 u16 buf_left, type, len;
2235 struct host_cmd_ds_command *cmd_ptr;
2236 struct cmd_ctrl_node *cmd_node;
2237 unsigned long cmd_flags, scan_flags;
2238 bool complete_scan = false;
2240 mwifiex_dbg(adapter, INFO, "info: EXT scan returns successfully\n");
2242 ext_scan_resp = &resp->params.ext_scan;
2244 tlv = (void *)ext_scan_resp->tlv_buffer;
2245 buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN
2248 while (buf_left >= sizeof(struct mwifiex_ie_types_header)) {
2249 type = le16_to_cpu(tlv->type);
2250 len = le16_to_cpu(tlv->len);
2252 if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) {
2253 mwifiex_dbg(adapter, ERROR,
2254 "error processing scan response TLVs");
2259 case TLV_TYPE_CHANNEL_STATS:
2260 tlv_stat = (void *)tlv;
2261 mwifiex_update_chan_statistics(priv, tlv_stat);
2267 buf_left -= len + sizeof(struct mwifiex_ie_types_header);
2268 tlv = (void *)((u8 *)tlv + len +
2269 sizeof(struct mwifiex_ie_types_header));
2272 spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags);
2273 spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags);
2274 if (list_empty(&adapter->scan_pending_q)) {
2275 complete_scan = true;
2276 list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) {
2277 cmd_ptr = (void *)cmd_node->cmd_skb->data;
2278 if (le16_to_cpu(cmd_ptr->command) ==
2279 HostCmd_CMD_802_11_SCAN_EXT) {
2280 mwifiex_dbg(adapter, INFO,
2281 "Scan pending in command pending list");
2282 complete_scan = false;
2287 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags);
2288 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags);
2291 mwifiex_complete_scan(priv);
2296 /* This function This function handles the event extended scan report. It
2297 * parses extended scan results and informs to cfg80211 stack.
2299 int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
2303 struct mwifiex_adapter *adapter = priv->adapter;
2305 u32 bytes_left, bytes_left_for_tlv, idx;
2307 struct mwifiex_ie_types_data *tlv;
2308 struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv;
2309 struct mwifiex_ie_types_bss_scan_info *scan_info_tlv;
2313 struct mwifiex_event_scan_result *event_scan = buf;
2314 u8 num_of_set = event_scan->num_of_set;
2315 u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
2316 u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
2318 if (num_of_set > MWIFIEX_MAX_AP) {
2319 mwifiex_dbg(adapter, ERROR,
2320 "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
2323 goto check_next_scan;
2326 bytes_left = scan_resp_size;
2327 mwifiex_dbg(adapter, INFO,
2328 "EXT_SCAN: size %d, returned %d APs...",
2329 scan_resp_size, num_of_set);
2330 mwifiex_dbg_dump(adapter, CMD_D, "EXT_SCAN buffer:", buf,
2332 sizeof(struct mwifiex_event_scan_result));
2334 tlv = (struct mwifiex_ie_types_data *)scan_resp;
2336 for (idx = 0; idx < num_of_set && bytes_left; idx++) {
2337 type = le16_to_cpu(tlv->header.type);
2338 len = le16_to_cpu(tlv->header.len);
2339 if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) {
2340 mwifiex_dbg(adapter, ERROR,
2341 "EXT_SCAN: Error bytes left < TLV length\n");
2344 scan_rsp_tlv = NULL;
2345 scan_info_tlv = NULL;
2346 bytes_left_for_tlv = bytes_left;
2348 /* BSS response TLV with beacon or probe response buffer
2349 * at the initial position of each descriptor
2351 if (type != TLV_TYPE_BSS_SCAN_RSP)
2354 bss_info = (u8 *)tlv;
2355 scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv;
2356 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2357 bytes_left_for_tlv -=
2358 (len + sizeof(struct mwifiex_ie_types_header));
2360 while (bytes_left_for_tlv >=
2361 sizeof(struct mwifiex_ie_types_header) &&
2362 le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) {
2363 type = le16_to_cpu(tlv->header.type);
2364 len = le16_to_cpu(tlv->header.len);
2365 if (bytes_left_for_tlv <
2366 sizeof(struct mwifiex_ie_types_header) + len) {
2367 mwifiex_dbg(adapter, ERROR,
2368 "EXT_SCAN: Error in processing TLV,\t"
2369 "bytes left < TLV length\n");
2370 scan_rsp_tlv = NULL;
2371 bytes_left_for_tlv = 0;
2375 case TLV_TYPE_BSS_SCAN_INFO:
2377 (struct mwifiex_ie_types_bss_scan_info *)tlv;
2379 sizeof(struct mwifiex_ie_types_bss_scan_info) -
2380 sizeof(struct mwifiex_ie_types_header)) {
2381 bytes_left_for_tlv = 0;
2388 tlv = (struct mwifiex_ie_types_data *)(tlv->data + len);
2390 (len + sizeof(struct mwifiex_ie_types_header));
2391 bytes_left_for_tlv -=
2392 (len + sizeof(struct mwifiex_ie_types_header));
2398 /* Advance pointer to the beacon buffer length and
2399 * update the bytes count so that the function
2400 * wlan_interpret_bss_desc_with_ie() can handle the
2401 * scan buffer withut any change
2403 bss_info += sizeof(u16);
2404 bytes_left -= sizeof(u16);
2406 if (scan_info_tlv) {
2407 rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi));
2408 rssi *= 100; /* Convert dBm to mBm */
2409 mwifiex_dbg(adapter, INFO,
2410 "info: InterpretIE: RSSI=%d\n", rssi);
2411 fw_tsf = le64_to_cpu(scan_info_tlv->tsf);
2412 radio_type = &scan_info_tlv->radio_type;
2416 ret = mwifiex_parse_single_response_buf(priv, &bss_info,
2417 &bytes_left, fw_tsf,
2418 radio_type, true, rssi);
2420 goto check_next_scan;
2424 if (!event_scan->more_event)
2425 mwifiex_check_next_scan_command(priv);
2431 * This function prepares command for background scan query.
2433 * Preparation includes -
2434 * - Setting command ID and proper size
2435 * - Setting background scan flush parameter
2436 * - Ensuring correct endian-ness
2438 int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd)
2440 struct host_cmd_ds_802_11_bg_scan_query *bg_query =
2441 &cmd->params.bg_scan_query;
2443 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY);
2444 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query)
2447 bg_query->flush = 1;
2453 * This function inserts scan command node to the scan pending queue.
2456 mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
2457 struct cmd_ctrl_node *cmd_node)
2459 struct mwifiex_adapter *adapter = priv->adapter;
2460 unsigned long flags;
2462 cmd_node->wait_q_enabled = true;
2463 cmd_node->condition = &adapter->scan_wait_q_woken;
2464 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
2465 list_add_tail(&cmd_node->list, &adapter->scan_pending_q);
2466 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
2470 * This function sends a scan command for all available channels to the
2471 * firmware, filtered on a specific SSID.
2473 static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv,
2474 struct cfg80211_ssid *req_ssid)
2476 struct mwifiex_adapter *adapter = priv->adapter;
2478 struct mwifiex_user_scan_cfg *scan_cfg;
2480 if (adapter->scan_processing) {
2481 mwifiex_dbg(adapter, WARN,
2482 "cmd: Scan already in process...\n");
2486 if (priv->scan_block) {
2487 mwifiex_dbg(adapter, WARN,
2488 "cmd: Scan is blocked during association...\n");
2492 scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL);
2496 scan_cfg->ssid_list = req_ssid;
2497 scan_cfg->num_ssids = 1;
2499 ret = mwifiex_scan_networks(priv, scan_cfg);
2506 * Sends IOCTL request to start a scan.
2508 * This function allocates the IOCTL request buffer, fills it
2509 * with requisite parameters and calls the IOCTL handler.
2511 * Scan command can be issued for both normal scan and specific SSID
2512 * scan, depending upon whether an SSID is provided or not.
2514 int mwifiex_request_scan(struct mwifiex_private *priv,
2515 struct cfg80211_ssid *req_ssid)
2519 if (down_interruptible(&priv->async_sem)) {
2520 mwifiex_dbg(priv->adapter, ERROR,
2521 "%s: acquire semaphore fail\n",
2526 priv->adapter->scan_wait_q_woken = false;
2528 if (req_ssid && req_ssid->ssid_len != 0)
2529 /* Specific SSID scan */
2530 ret = mwifiex_scan_specific_ssid(priv, req_ssid);
2533 ret = mwifiex_scan_networks(priv, NULL);
2535 up(&priv->async_sem);
2541 * This function appends the vendor specific IE TLV to a buffer.
2544 mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv,
2545 u16 vsie_mask, u8 **buffer)
2547 int id, ret_len = 0;
2548 struct mwifiex_ie_types_vendor_param_set *vs_param_set;
2556 * Traverse through the saved vendor specific IE array and append
2557 * the selected(scan/assoc/adhoc) IE as TLV to the command
2559 for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) {
2560 if (priv->vs_ie[id].mask & vsie_mask) {
2562 (struct mwifiex_ie_types_vendor_param_set *)
2564 vs_param_set->header.type =
2565 cpu_to_le16(TLV_TYPE_PASSTHROUGH);
2566 vs_param_set->header.len =
2567 cpu_to_le16((((u16) priv->vs_ie[id].ie[1])
2569 memcpy(vs_param_set->ie, priv->vs_ie[id].ie,
2570 le16_to_cpu(vs_param_set->header.len));
2571 *buffer += le16_to_cpu(vs_param_set->header.len) +
2572 sizeof(struct mwifiex_ie_types_header);
2573 ret_len += le16_to_cpu(vs_param_set->header.len) +
2574 sizeof(struct mwifiex_ie_types_header);
2581 * This function saves a beacon buffer of the current BSS descriptor.
2583 * The current beacon buffer is saved so that it can be restored in the
2584 * following cases that makes the beacon buffer not to contain the current
2585 * ssid's beacon buffer.
2586 * - The current ssid was not found somehow in the last scan.
2587 * - The current ssid was the last entry of the scan table and overloaded.
2590 mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2592 struct mwifiex_bssdescriptor *curr_bss =
2593 &priv->curr_bss_params.bss_descriptor;
2595 if (!curr_bss->beacon_buf_size)
2598 /* allocate beacon buffer at 1st time; or if it's size has changed */
2599 if (!priv->curr_bcn_buf ||
2600 priv->curr_bcn_size != curr_bss->beacon_buf_size) {
2601 priv->curr_bcn_size = curr_bss->beacon_buf_size;
2603 kfree(priv->curr_bcn_buf);
2604 priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size,
2606 if (!priv->curr_bcn_buf)
2610 memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf,
2611 curr_bss->beacon_buf_size);
2612 mwifiex_dbg(priv->adapter, INFO,
2613 "info: current beacon saved %d\n",
2614 priv->curr_bcn_size);
2616 curr_bss->beacon_buf = priv->curr_bcn_buf;
2618 /* adjust the pointers in the current BSS descriptor */
2619 if (curr_bss->bcn_wpa_ie)
2620 curr_bss->bcn_wpa_ie =
2621 (struct ieee_types_vendor_specific *)
2622 (curr_bss->beacon_buf +
2623 curr_bss->wpa_offset);
2625 if (curr_bss->bcn_rsn_ie)
2626 curr_bss->bcn_rsn_ie = (struct ieee_types_generic *)
2627 (curr_bss->beacon_buf +
2628 curr_bss->rsn_offset);
2630 if (curr_bss->bcn_ht_cap)
2631 curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *)
2632 (curr_bss->beacon_buf +
2633 curr_bss->ht_cap_offset);
2635 if (curr_bss->bcn_ht_oper)
2636 curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *)
2637 (curr_bss->beacon_buf +
2638 curr_bss->ht_info_offset);
2640 if (curr_bss->bcn_vht_cap)
2641 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2642 curr_bss->vht_cap_offset);
2644 if (curr_bss->bcn_vht_oper)
2645 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2646 curr_bss->vht_info_offset);
2648 if (curr_bss->bcn_bss_co_2040)
2649 curr_bss->bcn_bss_co_2040 =
2650 (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset);
2652 if (curr_bss->bcn_ext_cap)
2653 curr_bss->bcn_ext_cap = curr_bss->beacon_buf +
2654 curr_bss->ext_cap_offset;
2656 if (curr_bss->oper_mode)
2657 curr_bss->oper_mode = (void *)(curr_bss->beacon_buf +
2658 curr_bss->oper_mode_offset);
2662 * This function frees the current BSS descriptor beacon buffer.
2665 mwifiex_free_curr_bcn(struct mwifiex_private *priv)
2667 kfree(priv->curr_bcn_buf);
2668 priv->curr_bcn_buf = NULL;