Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: scan ioctl and command handling |
| 3 | * |
Xinming Hu | 65da33f | 2014-06-19 21:38:57 -0700 | [diff] [blame] | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include "decl.h" |
| 21 | #include "ioctl.h" |
| 22 | #include "util.h" |
| 23 | #include "fw.h" |
| 24 | #include "main.h" |
| 25 | #include "11n.h" |
| 26 | #include "cfg80211.h" |
| 27 | |
| 28 | /* The maximum number of channels the firmware can scan per command */ |
| 29 | #define MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN 14 |
| 30 | |
Amitkumar Karwar | 658f37b | 2012-06-06 21:12:42 -0700 | [diff] [blame] | 31 | #define MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD 4 |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 32 | |
| 33 | /* Memory needed to store a max sized Channel List TLV for a firmware scan */ |
| 34 | #define CHAN_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_header) \ |
| 35 | + (MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN \ |
| 36 | *sizeof(struct mwifiex_chan_scan_param_set))) |
| 37 | |
| 38 | /* Memory needed to store supported rate */ |
| 39 | #define RATE_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_rates_param_set) \ |
| 40 | + HOSTCMD_SUPPORTED_RATES) |
| 41 | |
| 42 | /* Memory needed to store a max number/size WildCard SSID TLV for a firmware |
| 43 | scan */ |
| 44 | #define WILDCARD_SSID_TLV_MAX_SIZE \ |
| 45 | (MWIFIEX_MAX_SSID_LIST_LENGTH * \ |
| 46 | (sizeof(struct mwifiex_ie_types_wildcard_ssid_params) \ |
| 47 | + IEEE80211_MAX_SSID_LEN)) |
| 48 | |
| 49 | /* Maximum memory needed for a mwifiex_scan_cmd_config with all TLVs at max */ |
| 50 | #define MAX_SCAN_CFG_ALLOC (sizeof(struct mwifiex_scan_cmd_config) \ |
| 51 | + sizeof(struct mwifiex_ie_types_num_probes) \ |
| 52 | + sizeof(struct mwifiex_ie_types_htcap) \ |
| 53 | + CHAN_TLV_MAX_SIZE \ |
| 54 | + RATE_TLV_MAX_SIZE \ |
| 55 | + WILDCARD_SSID_TLV_MAX_SIZE) |
| 56 | |
| 57 | |
| 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]; |
| 63 | }; |
| 64 | |
| 65 | enum cipher_suite { |
| 66 | CIPHER_SUITE_TKIP, |
| 67 | CIPHER_SUITE_CCMP, |
| 68 | CIPHER_SUITE_MAX |
| 69 | }; |
| 70 | static u8 mwifiex_wpa_oui[CIPHER_SUITE_MAX][4] = { |
| 71 | { 0x00, 0x50, 0xf2, 0x02 }, /* TKIP */ |
| 72 | { 0x00, 0x50, 0xf2, 0x04 }, /* AES */ |
| 73 | }; |
| 74 | static u8 mwifiex_rsn_oui[CIPHER_SUITE_MAX][4] = { |
| 75 | { 0x00, 0x0f, 0xac, 0x02 }, /* TKIP */ |
| 76 | { 0x00, 0x0f, 0xac, 0x04 }, /* AES */ |
| 77 | }; |
| 78 | |
Andreas Fenkart | 679b687 | 2016-03-10 09:44:08 +0100 | [diff] [blame] | 79 | static void |
| 80 | _dbg_security_flags(int log_level, const char *func, const char *desc, |
| 81 | struct mwifiex_private *priv, |
| 82 | struct mwifiex_bssdescriptor *bss_desc) |
| 83 | { |
| 84 | _mwifiex_dbg(priv->adapter, log_level, |
| 85 | "info: %s: %s:\twpa_ie=%#x wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s\tEncMode=%#x privacy=%#x\n", |
| 86 | func, desc, |
| 87 | bss_desc->bcn_wpa_ie ? |
| 88 | bss_desc->bcn_wpa_ie->vend_hdr.element_id : 0, |
| 89 | bss_desc->bcn_rsn_ie ? |
| 90 | bss_desc->bcn_rsn_ie->ieee_hdr.element_id : 0, |
| 91 | priv->sec_info.wep_enabled ? "e" : "d", |
| 92 | priv->sec_info.wpa_enabled ? "e" : "d", |
| 93 | priv->sec_info.wpa2_enabled ? "e" : "d", |
| 94 | priv->sec_info.encryption_mode, |
| 95 | bss_desc->privacy); |
| 96 | } |
| 97 | #define dbg_security_flags(mask, desc, priv, bss_desc) \ |
| 98 | _dbg_security_flags(MWIFIEX_DBG_##mask, desc, __func__, priv, bss_desc) |
| 99 | |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 100 | static bool |
| 101 | has_ieee_hdr(struct ieee_types_generic *ie, u8 key) |
| 102 | { |
| 103 | return (ie && ie->ieee_hdr.element_id == key); |
| 104 | } |
| 105 | |
| 106 | static bool |
| 107 | has_vendor_hdr(struct ieee_types_vendor_specific *ie, u8 key) |
| 108 | { |
| 109 | return (ie && ie->vend_hdr.element_id == key); |
| 110 | } |
| 111 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 112 | /* |
| 113 | * This function parses a given IE for a given OUI. |
| 114 | * |
| 115 | * This is used to parse a WPA/RSN IE to find if it has |
| 116 | * a given oui in PTK. |
| 117 | */ |
| 118 | static u8 |
| 119 | mwifiex_search_oui_in_ie(struct ie_body *iebody, u8 *oui) |
| 120 | { |
| 121 | u8 count; |
| 122 | |
| 123 | count = iebody->ptk_cnt[0]; |
| 124 | |
| 125 | /* There could be multiple OUIs for PTK hence |
| 126 | 1) Take the length. |
| 127 | 2) Check all the OUIs for AES. |
| 128 | 3) If one of them is AES then pass success. */ |
| 129 | while (count) { |
| 130 | if (!memcmp(iebody->ptk_body, oui, sizeof(iebody->ptk_body))) |
| 131 | return MWIFIEX_OUI_PRESENT; |
| 132 | |
| 133 | --count; |
| 134 | if (count) |
| 135 | iebody = (struct ie_body *) ((u8 *) iebody + |
| 136 | sizeof(iebody->ptk_body)); |
| 137 | } |
| 138 | |
| 139 | pr_debug("info: %s: OUI is not found in PTK\n", __func__); |
| 140 | return MWIFIEX_OUI_NOT_PRESENT; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * This function checks if a given OUI is present in a RSN IE. |
| 145 | * |
| 146 | * The function first checks if a RSN IE is present or not in the |
| 147 | * BSS descriptor. It tries to locate the OUI only if such an IE is |
| 148 | * present. |
| 149 | */ |
| 150 | static u8 |
| 151 | mwifiex_is_rsn_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher) |
| 152 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 153 | u8 *oui; |
| 154 | struct ie_body *iebody; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 155 | u8 ret = MWIFIEX_OUI_NOT_PRESENT; |
| 156 | |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 157 | if (has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 158 | iebody = (struct ie_body *) |
| 159 | (((u8 *) bss_desc->bcn_rsn_ie->data) + |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 160 | RSN_GTK_OUI_OFFSET); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 161 | oui = &mwifiex_rsn_oui[cipher][0]; |
| 162 | ret = mwifiex_search_oui_in_ie(iebody, oui); |
| 163 | if (ret) |
| 164 | return ret; |
| 165 | } |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * This function checks if a given OUI is present in a WPA IE. |
| 171 | * |
| 172 | * The function first checks if a WPA IE is present or not in the |
| 173 | * BSS descriptor. It tries to locate the OUI only if such an IE is |
| 174 | * present. |
| 175 | */ |
| 176 | static u8 |
| 177 | mwifiex_is_wpa_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher) |
| 178 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 179 | u8 *oui; |
| 180 | struct ie_body *iebody; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 181 | u8 ret = MWIFIEX_OUI_NOT_PRESENT; |
| 182 | |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 183 | if (has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 184 | iebody = (struct ie_body *) bss_desc->bcn_wpa_ie->data; |
| 185 | oui = &mwifiex_wpa_oui[cipher][0]; |
| 186 | ret = mwifiex_search_oui_in_ie(iebody, oui); |
| 187 | if (ret) |
| 188 | return ret; |
| 189 | } |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * This function compares two SSIDs and checks if they match. |
| 195 | */ |
| 196 | s32 |
Amitkumar Karwar | b9be5f3 | 2012-02-27 22:04:14 -0800 | [diff] [blame] | 197 | mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 198 | { |
| 199 | if (!ssid1 || !ssid2 || (ssid1->ssid_len != ssid2->ssid_len)) |
| 200 | return -1; |
| 201 | return memcmp(ssid1->ssid, ssid2->ssid, ssid1->ssid_len); |
| 202 | } |
| 203 | |
| 204 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 205 | * This function checks if wapi is enabled in driver and scanned network is |
| 206 | * compatible with it. |
| 207 | */ |
| 208 | static bool |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 209 | mwifiex_is_bss_wapi(struct mwifiex_private *priv, |
| 210 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 211 | { |
| 212 | if (priv->sec_info.wapi_enabled && |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 213 | has_ieee_hdr(bss_desc->bcn_wapi_ie, WLAN_EID_BSS_AC_ACCESS_DELAY)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 214 | return true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 215 | return false; |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * This function checks if driver is configured with no security mode and |
| 220 | * scanned network is compatible with it. |
| 221 | */ |
| 222 | static bool |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 223 | mwifiex_is_bss_no_sec(struct mwifiex_private *priv, |
| 224 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 225 | { |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame] | 226 | if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled && |
Andreas Fenkart | 0a233c9 | 2016-03-10 09:44:05 +0100 | [diff] [blame] | 227 | !priv->sec_info.wpa2_enabled && |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 228 | !has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC) && |
| 229 | !has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN) && |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 230 | !priv->sec_info.encryption_mode && !bss_desc->privacy) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 231 | return true; |
| 232 | } |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * This function checks if static WEP is enabled in driver and scanned network |
| 238 | * is compatible with it. |
| 239 | */ |
| 240 | static bool |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 241 | mwifiex_is_bss_static_wep(struct mwifiex_private *priv, |
| 242 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 243 | { |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame] | 244 | if (priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled && |
| 245 | !priv->sec_info.wpa2_enabled && bss_desc->privacy) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 246 | return true; |
| 247 | } |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * This function checks if wpa is enabled in driver and scanned network is |
| 253 | * compatible with it. |
| 254 | */ |
| 255 | static bool |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 256 | mwifiex_is_bss_wpa(struct mwifiex_private *priv, |
| 257 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 258 | { |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame] | 259 | if (!priv->sec_info.wep_enabled && priv->sec_info.wpa_enabled && |
Andreas Fenkart | 0a233c9 | 2016-03-10 09:44:05 +0100 | [diff] [blame] | 260 | !priv->sec_info.wpa2_enabled && |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 261 | has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 262 | /* |
| 263 | * Privacy bit may NOT be set in some APs like |
| 264 | * LinkSys WRT54G && bss_desc->privacy |
| 265 | */ |
| 266 | ) { |
Andreas Fenkart | 679b687 | 2016-03-10 09:44:08 +0100 | [diff] [blame] | 267 | dbg_security_flags(INFO, "WPA", priv, bss_desc); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 268 | return true; |
| 269 | } |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * This function checks if wpa2 is enabled in driver and scanned network is |
| 275 | * compatible with it. |
| 276 | */ |
| 277 | static bool |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 278 | mwifiex_is_bss_wpa2(struct mwifiex_private *priv, |
| 279 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 280 | { |
Andreas Fenkart | 0a233c9 | 2016-03-10 09:44:05 +0100 | [diff] [blame] | 281 | if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled && |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 282 | priv->sec_info.wpa2_enabled && |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 283 | has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN)) { |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 284 | /* |
| 285 | * Privacy bit may NOT be set in some APs like |
| 286 | * LinkSys WRT54G && bss_desc->privacy |
| 287 | */ |
Andreas Fenkart | 679b687 | 2016-03-10 09:44:08 +0100 | [diff] [blame] | 288 | dbg_security_flags(INFO, "WAP2", priv, bss_desc); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | return false; |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * This function checks if adhoc AES is enabled in driver and scanned network is |
| 296 | * compatible with it. |
| 297 | */ |
| 298 | static bool |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 299 | mwifiex_is_bss_adhoc_aes(struct mwifiex_private *priv, |
| 300 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 301 | { |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame] | 302 | if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled && |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 303 | !priv->sec_info.wpa2_enabled && |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 304 | !has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC) && |
| 305 | !has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN) && |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 306 | !priv->sec_info.encryption_mode && bss_desc->privacy) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 307 | return true; |
| 308 | } |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * This function checks if dynamic WEP is enabled in driver and scanned network |
| 314 | * is compatible with it. |
| 315 | */ |
| 316 | static bool |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 317 | mwifiex_is_bss_dynamic_wep(struct mwifiex_private *priv, |
| 318 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 319 | { |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame] | 320 | if (!priv->sec_info.wep_enabled && !priv->sec_info.wpa_enabled && |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 321 | !priv->sec_info.wpa2_enabled && |
Andreas Fenkart | 3832956 | 2016-03-10 09:44:06 +0100 | [diff] [blame] | 322 | !has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC) && |
| 323 | !has_ieee_hdr(bss_desc->bcn_rsn_ie, WLAN_EID_RSN) && |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 324 | priv->sec_info.encryption_mode && bss_desc->privacy) { |
Andreas Fenkart | 679b687 | 2016-03-10 09:44:08 +0100 | [diff] [blame] | 325 | dbg_security_flags(INFO, "dynamic", priv, bss_desc); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 326 | return true; |
| 327 | } |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * This function checks if a scanned network is compatible with the driver |
| 333 | * settings. |
| 334 | * |
| 335 | * WEP WPA WPA2 ad-hoc encrypt Network |
| 336 | * enabled enabled enabled AES mode Privacy WPA WPA2 Compatible |
| 337 | * 0 0 0 0 NONE 0 0 0 yes No security |
| 338 | * 0 1 0 0 x 1x 1 x yes WPA (disable |
| 339 | * HT if no AES) |
| 340 | * 0 0 1 0 x 1x x 1 yes WPA2 (disable |
| 341 | * HT if no AES) |
| 342 | * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES |
| 343 | * 1 0 0 0 NONE 1 0 0 yes Static WEP |
| 344 | * (disable HT) |
| 345 | * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP |
| 346 | * |
| 347 | * Compatibility is not matched while roaming, except for mode. |
| 348 | */ |
| 349 | static s32 |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 350 | mwifiex_is_network_compatible(struct mwifiex_private *priv, |
| 351 | struct mwifiex_bssdescriptor *bss_desc, u32 mode) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 352 | { |
| 353 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 354 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 355 | bss_desc->disable_11n = false; |
| 356 | |
| 357 | /* Don't check for compatibility if roaming */ |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 358 | if (priv->media_connected && |
| 359 | (priv->bss_mode == NL80211_IFTYPE_STATION) && |
| 360 | (bss_desc->bss_mode == NL80211_IFTYPE_STATION)) |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 361 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 362 | |
| 363 | if (priv->wps.session_enable) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 364 | mwifiex_dbg(adapter, IOCTL, |
| 365 | "info: return success directly in WPS period\n"); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 366 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Amitkumar Karwar | 2a7305c | 2013-06-19 08:49:05 -0700 | [diff] [blame] | 369 | if (bss_desc->chan_sw_ie_present) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 370 | mwifiex_dbg(adapter, INFO, |
| 371 | "Don't connect to AP with WLAN_EID_CHANNEL_SWITCH\n"); |
Amitkumar Karwar | 2a7305c | 2013-06-19 08:49:05 -0700 | [diff] [blame] | 372 | return -1; |
| 373 | } |
| 374 | |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 375 | if (mwifiex_is_bss_wapi(priv, bss_desc)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 376 | mwifiex_dbg(adapter, INFO, |
| 377 | "info: return success for WAPI AP\n"); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 378 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | if (bss_desc->bss_mode == mode) { |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 382 | if (mwifiex_is_bss_no_sec(priv, bss_desc)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 383 | /* No security */ |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 384 | return 0; |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 385 | } else if (mwifiex_is_bss_static_wep(priv, bss_desc)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 386 | /* Static WEP enabled */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 387 | mwifiex_dbg(adapter, INFO, |
| 388 | "info: Disable 11n in WEP mode.\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 389 | bss_desc->disable_11n = true; |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 390 | return 0; |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 391 | } else if (mwifiex_is_bss_wpa(priv, bss_desc)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 392 | /* WPA enabled */ |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 393 | if (((priv->adapter->config_bands & BAND_GN || |
| 394 | priv->adapter->config_bands & BAND_AN) && |
| 395 | bss_desc->bcn_ht_cap) && |
| 396 | !mwifiex_is_wpa_oui_present(bss_desc, |
| 397 | CIPHER_SUITE_CCMP)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 398 | |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 399 | if (mwifiex_is_wpa_oui_present |
| 400 | (bss_desc, CIPHER_SUITE_TKIP)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 401 | mwifiex_dbg(adapter, INFO, |
| 402 | "info: Disable 11n if AES\t" |
| 403 | "is not supported by AP\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 404 | bss_desc->disable_11n = true; |
| 405 | } else { |
| 406 | return -1; |
| 407 | } |
| 408 | } |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 409 | return 0; |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 410 | } else if (mwifiex_is_bss_wpa2(priv, bss_desc)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 411 | /* WPA2 enabled */ |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 412 | if (((priv->adapter->config_bands & BAND_GN || |
| 413 | priv->adapter->config_bands & BAND_AN) && |
| 414 | bss_desc->bcn_ht_cap) && |
| 415 | !mwifiex_is_rsn_oui_present(bss_desc, |
| 416 | CIPHER_SUITE_CCMP)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 417 | |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 418 | if (mwifiex_is_rsn_oui_present |
| 419 | (bss_desc, CIPHER_SUITE_TKIP)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 420 | mwifiex_dbg(adapter, INFO, |
| 421 | "info: Disable 11n if AES\t" |
| 422 | "is not supported by AP\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 423 | bss_desc->disable_11n = true; |
| 424 | } else { |
| 425 | return -1; |
| 426 | } |
| 427 | } |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 428 | return 0; |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 429 | } else if (mwifiex_is_bss_adhoc_aes(priv, bss_desc)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 430 | /* Ad-hoc AES enabled */ |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 431 | return 0; |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 432 | } else if (mwifiex_is_bss_dynamic_wep(priv, bss_desc)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 433 | /* Dynamic WEP enabled */ |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 434 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* Security doesn't match */ |
Andreas Fenkart | 679b687 | 2016-03-10 09:44:08 +0100 | [diff] [blame] | 438 | dbg_security_flags(ERROR, "failed", priv, bss_desc); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 439 | return -1; |
| 440 | } |
| 441 | |
| 442 | /* Mode doesn't match */ |
| 443 | return -1; |
| 444 | } |
| 445 | |
| 446 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 447 | * This function creates a channel list for the driver to scan, based |
| 448 | * on region/band information. |
| 449 | * |
| 450 | * This routine is used for any scan that is not provided with a |
| 451 | * specific channel list to scan. |
| 452 | */ |
Amitkumar Karwar | 658f37b | 2012-06-06 21:12:42 -0700 | [diff] [blame] | 453 | static int |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 454 | mwifiex_scan_create_channel_list(struct mwifiex_private *priv, |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 455 | const struct mwifiex_user_scan_cfg |
| 456 | *user_scan_in, |
| 457 | struct mwifiex_chan_scan_param_set |
| 458 | *scan_chan_list, |
| 459 | u8 filtered_scan) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 460 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 461 | enum nl80211_band band; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 462 | struct ieee80211_supported_band *sband; |
| 463 | struct ieee80211_channel *ch; |
| 464 | struct mwifiex_adapter *adapter = priv->adapter; |
| 465 | int chan_idx = 0, i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 466 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 467 | for (band = 0; (band < NUM_NL80211_BANDS) ; band++) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 468 | |
Avinash Patil | 4facc34 | 2015-01-28 15:42:00 +0530 | [diff] [blame] | 469 | if (!priv->wdev.wiphy->bands[band]) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 470 | continue; |
| 471 | |
Avinash Patil | 4facc34 | 2015-01-28 15:42:00 +0530 | [diff] [blame] | 472 | sband = priv->wdev.wiphy->bands[band]; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 473 | |
Amitkumar Karwar | d06b7b9 | 2011-09-21 21:43:22 -0700 | [diff] [blame] | 474 | for (i = 0; (i < sband->n_channels) ; i++) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 475 | ch = &sband->channels[i]; |
| 476 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 477 | continue; |
| 478 | scan_chan_list[chan_idx].radio_type = band; |
Amitkumar Karwar | 186630c | 2011-12-15 21:00:37 -0800 | [diff] [blame] | 479 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 480 | if (user_scan_in && |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 481 | user_scan_in->chan_list[0].scan_time) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 482 | scan_chan_list[chan_idx].max_scan_time = |
| 483 | cpu_to_le16((u16) user_scan_in-> |
| 484 | chan_list[0].scan_time); |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 485 | else if (ch->flags & IEEE80211_CHAN_NO_IR) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 486 | scan_chan_list[chan_idx].max_scan_time = |
| 487 | cpu_to_le16(adapter->passive_scan_time); |
| 488 | else |
| 489 | scan_chan_list[chan_idx].max_scan_time = |
| 490 | cpu_to_le16(adapter->active_scan_time); |
Amitkumar Karwar | 186630c | 2011-12-15 21:00:37 -0800 | [diff] [blame] | 491 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 492 | if (ch->flags & IEEE80211_CHAN_NO_IR) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 493 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 494 | |= (MWIFIEX_PASSIVE_SCAN | |
| 495 | MWIFIEX_HIDDEN_SSID_REPORT); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 496 | else |
| 497 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
| 498 | &= ~MWIFIEX_PASSIVE_SCAN; |
| 499 | scan_chan_list[chan_idx].chan_number = |
| 500 | (u32) ch->hw_value; |
Amitkumar Karwar | 1b499cb | 2016-04-24 23:49:51 -0700 | [diff] [blame] | 501 | |
| 502 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
| 503 | |= MWIFIEX_DISABLE_CHAN_FILT; |
| 504 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 505 | if (filtered_scan) { |
| 506 | scan_chan_list[chan_idx].max_scan_time = |
| 507 | cpu_to_le16(adapter->specific_scan_time); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 508 | } |
Amitkumar Karwar | d06b7b9 | 2011-09-21 21:43:22 -0700 | [diff] [blame] | 509 | chan_idx++; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | } |
Amitkumar Karwar | 658f37b | 2012-06-06 21:12:42 -0700 | [diff] [blame] | 513 | return chan_idx; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 516 | /* This function creates a channel list tlv for bgscan config, based |
| 517 | * on region/band information. |
| 518 | */ |
| 519 | static int |
| 520 | mwifiex_bgscan_create_channel_list(struct mwifiex_private *priv, |
| 521 | const struct mwifiex_bg_scan_cfg |
| 522 | *bgscan_cfg_in, |
| 523 | struct mwifiex_chan_scan_param_set |
| 524 | *scan_chan_list) |
| 525 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 526 | enum nl80211_band band; |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 527 | struct ieee80211_supported_band *sband; |
| 528 | struct ieee80211_channel *ch; |
| 529 | struct mwifiex_adapter *adapter = priv->adapter; |
| 530 | int chan_idx = 0, i; |
| 531 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 532 | for (band = 0; (band < NUM_NL80211_BANDS); band++) { |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 533 | if (!priv->wdev.wiphy->bands[band]) |
| 534 | continue; |
| 535 | |
| 536 | sband = priv->wdev.wiphy->bands[band]; |
| 537 | |
| 538 | for (i = 0; (i < sband->n_channels) ; i++) { |
| 539 | ch = &sband->channels[i]; |
| 540 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 541 | continue; |
| 542 | scan_chan_list[chan_idx].radio_type = band; |
| 543 | |
| 544 | if (bgscan_cfg_in->chan_list[0].scan_time) |
| 545 | scan_chan_list[chan_idx].max_scan_time = |
| 546 | cpu_to_le16((u16)bgscan_cfg_in-> |
| 547 | chan_list[0].scan_time); |
| 548 | else if (ch->flags & IEEE80211_CHAN_NO_IR) |
| 549 | scan_chan_list[chan_idx].max_scan_time = |
| 550 | cpu_to_le16(adapter->passive_scan_time); |
| 551 | else |
| 552 | scan_chan_list[chan_idx].max_scan_time = |
| 553 | cpu_to_le16(adapter-> |
| 554 | specific_scan_time); |
| 555 | |
| 556 | if (ch->flags & IEEE80211_CHAN_NO_IR) |
| 557 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
| 558 | |= MWIFIEX_PASSIVE_SCAN; |
| 559 | else |
| 560 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
| 561 | &= ~MWIFIEX_PASSIVE_SCAN; |
| 562 | |
| 563 | scan_chan_list[chan_idx].chan_number = |
| 564 | (u32)ch->hw_value; |
| 565 | chan_idx++; |
| 566 | } |
| 567 | } |
| 568 | return chan_idx; |
| 569 | } |
| 570 | |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 571 | /* This function appends rate TLV to scan config command. */ |
| 572 | static int |
| 573 | mwifiex_append_rate_tlv(struct mwifiex_private *priv, |
| 574 | struct mwifiex_scan_cmd_config *scan_cfg_out, |
| 575 | u8 radio) |
| 576 | { |
| 577 | struct mwifiex_ie_types_rates_param_set *rates_tlv; |
| 578 | u8 rates[MWIFIEX_SUPPORTED_RATES], *tlv_pos; |
| 579 | u32 rates_size; |
| 580 | |
| 581 | memset(rates, 0, sizeof(rates)); |
| 582 | |
| 583 | tlv_pos = (u8 *)scan_cfg_out->tlv_buf + scan_cfg_out->tlv_buf_len; |
| 584 | |
| 585 | if (priv->scan_request) |
| 586 | rates_size = mwifiex_get_rates_from_cfg80211(priv, rates, |
| 587 | radio); |
| 588 | else |
| 589 | rates_size = mwifiex_get_supported_rates(priv, rates); |
| 590 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 591 | mwifiex_dbg(priv->adapter, CMD, |
| 592 | "info: SCAN_CMD: Rates size = %d\n", |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 593 | rates_size); |
| 594 | rates_tlv = (struct mwifiex_ie_types_rates_param_set *)tlv_pos; |
| 595 | rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES); |
| 596 | rates_tlv->header.len = cpu_to_le16((u16) rates_size); |
| 597 | memcpy(rates_tlv->rates, rates, rates_size); |
| 598 | scan_cfg_out->tlv_buf_len += sizeof(rates_tlv->header) + rates_size; |
| 599 | |
| 600 | return rates_size; |
| 601 | } |
| 602 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 603 | /* |
| 604 | * This function constructs and sends multiple scan config commands to |
| 605 | * the firmware. |
| 606 | * |
| 607 | * Previous routines in the code flow have created a scan command configuration |
| 608 | * with any requested TLVs. This function splits the channel TLV into maximum |
| 609 | * channels supported per scan lists and sends the portion of the channel TLV, |
| 610 | * along with the other TLVs, to the firmware. |
| 611 | */ |
| 612 | static int |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 613 | mwifiex_scan_channel_list(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 614 | u32 max_chan_per_scan, u8 filtered_scan, |
| 615 | struct mwifiex_scan_cmd_config *scan_cfg_out, |
| 616 | struct mwifiex_ie_types_chan_list_param_set |
| 617 | *chan_tlv_out, |
| 618 | struct mwifiex_chan_scan_param_set *scan_chan_list) |
| 619 | { |
Amitkumar Karwar | 1845bd3 | 2014-03-20 19:50:06 -0700 | [diff] [blame] | 620 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 621 | int ret = 0; |
| 622 | struct mwifiex_chan_scan_param_set *tmp_chan_list; |
| 623 | struct mwifiex_chan_scan_param_set *start_chan; |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 624 | u32 tlv_idx, rates_size, cmd_no; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 625 | u32 total_scan_time; |
| 626 | u32 done_early; |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 627 | u8 radio_type; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 628 | |
| 629 | if (!scan_cfg_out || !chan_tlv_out || !scan_chan_list) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 630 | mwifiex_dbg(priv->adapter, ERROR, |
| 631 | "info: Scan: Null detect: %p, %p, %p\n", |
| 632 | scan_cfg_out, chan_tlv_out, scan_chan_list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 633 | return -1; |
| 634 | } |
| 635 | |
Amitkumar Karwar | b887664 | 2013-06-18 16:36:58 -0700 | [diff] [blame] | 636 | /* Check csa channel expiry before preparing scan list */ |
| 637 | mwifiex_11h_get_csa_closed_channel(priv); |
| 638 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 639 | chan_tlv_out->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 640 | |
| 641 | /* Set the temp channel struct pointer to the start of the desired |
| 642 | list */ |
| 643 | tmp_chan_list = scan_chan_list; |
| 644 | |
| 645 | /* Loop through the desired channel list, sending a new firmware scan |
| 646 | commands for each max_chan_per_scan channels (or for 1,6,11 |
| 647 | individually if configured accordingly) */ |
| 648 | while (tmp_chan_list->chan_number) { |
| 649 | |
| 650 | tlv_idx = 0; |
| 651 | total_scan_time = 0; |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 652 | radio_type = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 653 | chan_tlv_out->header.len = 0; |
| 654 | start_chan = tmp_chan_list; |
| 655 | done_early = false; |
| 656 | |
| 657 | /* |
| 658 | * Construct the Channel TLV for the scan command. Continue to |
| 659 | * insert channel TLVs until: |
| 660 | * - the tlv_idx hits the maximum configured per scan command |
| 661 | * - the next channel to insert is 0 (end of desired channel |
| 662 | * list) |
| 663 | * - done_early is set (controlling individual scanning of |
| 664 | * 1,6,11) |
| 665 | */ |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 666 | while (tlv_idx < max_chan_per_scan && |
| 667 | tmp_chan_list->chan_number && !done_early) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 668 | |
Amitkumar Karwar | b887664 | 2013-06-18 16:36:58 -0700 | [diff] [blame] | 669 | if (tmp_chan_list->chan_number == priv->csa_chan) { |
| 670 | tmp_chan_list++; |
| 671 | continue; |
| 672 | } |
| 673 | |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 674 | radio_type = tmp_chan_list->radio_type; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 675 | mwifiex_dbg(priv->adapter, INFO, |
| 676 | "info: Scan: Chan(%3d), Radio(%d),\t" |
| 677 | "Mode(%d, %d), Dur(%d)\n", |
| 678 | tmp_chan_list->chan_number, |
| 679 | tmp_chan_list->radio_type, |
| 680 | tmp_chan_list->chan_scan_mode_bitmap |
| 681 | & MWIFIEX_PASSIVE_SCAN, |
| 682 | (tmp_chan_list->chan_scan_mode_bitmap |
| 683 | & MWIFIEX_DISABLE_CHAN_FILT) >> 1, |
| 684 | le16_to_cpu(tmp_chan_list->max_scan_time)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 685 | |
| 686 | /* Copy the current channel TLV to the command being |
| 687 | prepared */ |
| 688 | memcpy(chan_tlv_out->chan_scan_param + tlv_idx, |
| 689 | tmp_chan_list, |
| 690 | sizeof(chan_tlv_out->chan_scan_param)); |
| 691 | |
| 692 | /* Increment the TLV header length by the size |
| 693 | appended */ |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 694 | le16_unaligned_add_cpu(&chan_tlv_out->header.len, |
| 695 | sizeof( |
| 696 | chan_tlv_out->chan_scan_param)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | * The tlv buffer length is set to the number of bytes |
| 700 | * of the between the channel tlv pointer and the start |
| 701 | * of the tlv buffer. This compensates for any TLVs |
| 702 | * that were appended before the channel list. |
| 703 | */ |
| 704 | scan_cfg_out->tlv_buf_len = (u32) ((u8 *) chan_tlv_out - |
| 705 | scan_cfg_out->tlv_buf); |
| 706 | |
| 707 | /* Add the size of the channel tlv header and the data |
| 708 | length */ |
| 709 | scan_cfg_out->tlv_buf_len += |
| 710 | (sizeof(chan_tlv_out->header) |
| 711 | + le16_to_cpu(chan_tlv_out->header.len)); |
| 712 | |
| 713 | /* Increment the index to the channel tlv we are |
| 714 | constructing */ |
| 715 | tlv_idx++; |
| 716 | |
| 717 | /* Count the total scan time per command */ |
| 718 | total_scan_time += |
| 719 | le16_to_cpu(tmp_chan_list->max_scan_time); |
| 720 | |
| 721 | done_early = false; |
| 722 | |
| 723 | /* Stop the loop if the *current* channel is in the |
| 724 | 1,6,11 set and we are not filtering on a BSSID |
| 725 | or SSID. */ |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 726 | if (!filtered_scan && |
| 727 | (tmp_chan_list->chan_number == 1 || |
| 728 | tmp_chan_list->chan_number == 6 || |
| 729 | tmp_chan_list->chan_number == 11)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 730 | done_early = true; |
| 731 | |
| 732 | /* Increment the tmp pointer to the next channel to |
| 733 | be scanned */ |
| 734 | tmp_chan_list++; |
| 735 | |
| 736 | /* Stop the loop if the *next* channel is in the 1,6,11 |
| 737 | set. This will cause it to be the only channel |
| 738 | scanned on the next interation */ |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 739 | if (!filtered_scan && |
| 740 | (tmp_chan_list->chan_number == 1 || |
| 741 | tmp_chan_list->chan_number == 6 || |
| 742 | tmp_chan_list->chan_number == 11)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 743 | done_early = true; |
| 744 | } |
| 745 | |
| 746 | /* The total scan time should be less than scan command timeout |
| 747 | value */ |
| 748 | if (total_scan_time > MWIFIEX_MAX_TOTAL_SCAN_TIME) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 749 | mwifiex_dbg(priv->adapter, ERROR, |
| 750 | "total scan time %dms\t" |
| 751 | "is over limit (%dms), scan skipped\n", |
| 752 | total_scan_time, |
| 753 | MWIFIEX_MAX_TOTAL_SCAN_TIME); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 754 | ret = -1; |
| 755 | break; |
| 756 | } |
| 757 | |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 758 | rates_size = mwifiex_append_rate_tlv(priv, scan_cfg_out, |
| 759 | radio_type); |
| 760 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 761 | priv->adapter->scan_channels = start_chan; |
| 762 | |
| 763 | /* Send the scan command to the firmware with the specified |
| 764 | cfg */ |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 765 | if (priv->adapter->ext_scan) |
| 766 | cmd_no = HostCmd_CMD_802_11_SCAN_EXT; |
| 767 | else |
| 768 | cmd_no = HostCmd_CMD_802_11_SCAN; |
| 769 | |
Bing Zhao | fa0ecbb | 2014-02-27 19:35:12 -0800 | [diff] [blame] | 770 | ret = mwifiex_send_cmd(priv, cmd_no, HostCmd_ACT_GEN_SET, |
| 771 | 0, scan_cfg_out, false); |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 772 | |
| 773 | /* rate IE is updated per scan command but same starting |
| 774 | * pointer is used each time so that rate IE from earlier |
| 775 | * scan_cfg_out->buf is overwritten with new one. |
| 776 | */ |
| 777 | scan_cfg_out->tlv_buf_len -= |
| 778 | sizeof(struct mwifiex_ie_types_header) + rates_size; |
| 779 | |
Amitkumar Karwar | 1845bd3 | 2014-03-20 19:50:06 -0700 | [diff] [blame] | 780 | if (ret) { |
Andreas Fenkart | c70ca8c | 2016-03-10 09:44:10 +0100 | [diff] [blame] | 781 | mwifiex_cancel_pending_scan_cmd(adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 782 | break; |
Amitkumar Karwar | 1845bd3 | 2014-03-20 19:50:06 -0700 | [diff] [blame] | 783 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | if (ret) |
| 787 | return -1; |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * This function constructs a scan command configuration structure to use |
| 794 | * in scan commands. |
| 795 | * |
| 796 | * Application layer or other functions can invoke network scanning |
| 797 | * with a scan configuration supplied in a user scan configuration structure. |
| 798 | * This structure is used as the basis of one or many scan command configuration |
| 799 | * commands that are sent to the command processing module and eventually to the |
| 800 | * firmware. |
| 801 | * |
| 802 | * This function creates a scan command configuration structure based on the |
| 803 | * following user supplied parameters (if present): |
| 804 | * - SSID filter |
| 805 | * - BSSID filter |
| 806 | * - Number of Probes to be sent |
| 807 | * - Channel list |
| 808 | * |
| 809 | * If the SSID or BSSID filter is not present, the filter is disabled/cleared. |
| 810 | * If the number of probes is not set, adapter default setting is used. |
| 811 | */ |
| 812 | static void |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 813 | mwifiex_config_scan(struct mwifiex_private *priv, |
| 814 | const struct mwifiex_user_scan_cfg *user_scan_in, |
| 815 | struct mwifiex_scan_cmd_config *scan_cfg_out, |
| 816 | struct mwifiex_ie_types_chan_list_param_set **chan_list_out, |
| 817 | struct mwifiex_chan_scan_param_set *scan_chan_list, |
| 818 | u8 *max_chan_per_scan, u8 *filtered_scan, |
| 819 | u8 *scan_current_only) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 820 | { |
| 821 | struct mwifiex_adapter *adapter = priv->adapter; |
| 822 | struct mwifiex_ie_types_num_probes *num_probes_tlv; |
Avinash Patil | cb91be8 | 2014-09-12 20:08:54 +0530 | [diff] [blame] | 823 | struct mwifiex_ie_types_scan_chan_gap *chan_gap_tlv; |
Ganapathi Bhat | c2a8f0f | 2016-07-25 21:21:07 +0530 | [diff] [blame] | 824 | struct mwifiex_ie_types_random_mac *random_mac_tlv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 825 | struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv; |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 826 | struct mwifiex_ie_types_bssid_list *bssid_tlv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 827 | u8 *tlv_pos; |
| 828 | u32 num_probes; |
| 829 | u32 ssid_len; |
| 830 | u32 chan_idx; |
| 831 | u32 scan_type; |
| 832 | u16 scan_dur; |
| 833 | u8 channel; |
| 834 | u8 radio_type; |
Amitkumar Karwar | be0b281 | 2012-02-27 22:04:15 -0800 | [diff] [blame] | 835 | int i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 836 | u8 ssid_filter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 837 | struct mwifiex_ie_types_htcap *ht_cap; |
Aniket Nagarnaik | 40d7412 | 2015-07-16 08:05:21 -0700 | [diff] [blame] | 838 | struct mwifiex_ie_types_bss_mode *bss_mode; |
Ganapathi Bhat | c2a8f0f | 2016-07-25 21:21:07 +0530 | [diff] [blame] | 839 | const u8 zero_mac[6] = {0, 0, 0, 0, 0, 0}; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 840 | |
| 841 | /* The tlv_buf_len is calculated for each scan command. The TLVs added |
| 842 | in this routine will be preserved since the routine that sends the |
| 843 | command will append channelTLVs at *chan_list_out. The difference |
| 844 | between the *chan_list_out and the tlv_buf start will be used to |
| 845 | calculate the size of anything we add in this routine. */ |
| 846 | scan_cfg_out->tlv_buf_len = 0; |
| 847 | |
| 848 | /* Running tlv pointer. Assigned to chan_list_out at end of function |
| 849 | so later routines know where channels can be added to the command |
| 850 | buf */ |
| 851 | tlv_pos = scan_cfg_out->tlv_buf; |
| 852 | |
| 853 | /* Initialize the scan as un-filtered; the flag is later set to TRUE |
| 854 | below if a SSID or BSSID filter is sent in the command */ |
| 855 | *filtered_scan = false; |
| 856 | |
| 857 | /* Initialize the scan as not being only on the current channel. If |
| 858 | the channel list is customized, only contains one channel, and is |
| 859 | the active channel, this is set true and data flow is not halted. */ |
| 860 | *scan_current_only = false; |
| 861 | |
| 862 | if (user_scan_in) { |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 863 | u8 tmpaddr[ETH_ALEN]; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 864 | |
| 865 | /* Default the ssid_filter flag to TRUE, set false under |
| 866 | certain wildcard conditions and qualified by the existence |
| 867 | of an SSID list before marking the scan as filtered */ |
| 868 | ssid_filter = true; |
| 869 | |
| 870 | /* Set the BSS type scan filter, use Adapter setting if |
| 871 | unset */ |
| 872 | scan_cfg_out->bss_mode = |
Andreas Fenkart | 2ccf7ce | 2016-03-10 09:44:07 +0100 | [diff] [blame] | 873 | (u8)(user_scan_in->bss_mode ?: adapter->scan_mode); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 874 | |
| 875 | /* Set the number of probes to send, use Adapter setting |
| 876 | if unset */ |
Andreas Fenkart | 2ccf7ce | 2016-03-10 09:44:07 +0100 | [diff] [blame] | 877 | num_probes = user_scan_in->num_probes ?: adapter->scan_probes; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 878 | |
| 879 | /* |
| 880 | * Set the BSSID filter to the incoming configuration, |
| 881 | * if non-zero. If not set, it will remain disabled |
| 882 | * (all zeros). |
| 883 | */ |
| 884 | memcpy(scan_cfg_out->specific_bssid, |
| 885 | user_scan_in->specific_bssid, |
| 886 | sizeof(scan_cfg_out->specific_bssid)); |
| 887 | |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 888 | memcpy(tmpaddr, scan_cfg_out->specific_bssid, ETH_ALEN); |
| 889 | |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 890 | if (adapter->ext_scan && |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 891 | !is_zero_ether_addr(tmpaddr)) { |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 892 | bssid_tlv = |
| 893 | (struct mwifiex_ie_types_bssid_list *)tlv_pos; |
| 894 | bssid_tlv->header.type = cpu_to_le16(TLV_TYPE_BSSID); |
| 895 | bssid_tlv->header.len = cpu_to_le16(ETH_ALEN); |
| 896 | memcpy(bssid_tlv->bssid, user_scan_in->specific_bssid, |
| 897 | ETH_ALEN); |
| 898 | tlv_pos += sizeof(struct mwifiex_ie_types_bssid_list); |
| 899 | } |
| 900 | |
Amitkumar Karwar | be0b281 | 2012-02-27 22:04:15 -0800 | [diff] [blame] | 901 | for (i = 0; i < user_scan_in->num_ssids; i++) { |
| 902 | ssid_len = user_scan_in->ssid_list[i].ssid_len; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 903 | |
| 904 | wildcard_ssid_tlv = |
| 905 | (struct mwifiex_ie_types_wildcard_ssid_params *) |
| 906 | tlv_pos; |
| 907 | wildcard_ssid_tlv->header.type = |
| 908 | cpu_to_le16(TLV_TYPE_WILDCARDSSID); |
| 909 | wildcard_ssid_tlv->header.len = cpu_to_le16( |
| 910 | (u16) (ssid_len + sizeof(wildcard_ssid_tlv-> |
| 911 | max_ssid_length))); |
Amitkumar Karwar | fada1058 | 2011-11-09 21:36:21 -0800 | [diff] [blame] | 912 | |
Amitkumar Karwar | be0b281 | 2012-02-27 22:04:15 -0800 | [diff] [blame] | 913 | /* |
| 914 | * max_ssid_length = 0 tells firmware to perform |
| 915 | * specific scan for the SSID filled, whereas |
| 916 | * max_ssid_length = IEEE80211_MAX_SSID_LEN is for |
| 917 | * wildcard scan. |
| 918 | */ |
| 919 | if (ssid_len) |
| 920 | wildcard_ssid_tlv->max_ssid_length = 0; |
| 921 | else |
| 922 | wildcard_ssid_tlv->max_ssid_length = |
| 923 | IEEE80211_MAX_SSID_LEN; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 924 | |
Aniket Nagarnaik | 0c6303c | 2015-07-16 08:05:22 -0700 | [diff] [blame] | 925 | if (!memcmp(user_scan_in->ssid_list[i].ssid, |
| 926 | "DIRECT-", 7)) |
| 927 | wildcard_ssid_tlv->max_ssid_length = 0xfe; |
| 928 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 929 | memcpy(wildcard_ssid_tlv->ssid, |
Amitkumar Karwar | be0b281 | 2012-02-27 22:04:15 -0800 | [diff] [blame] | 930 | user_scan_in->ssid_list[i].ssid, ssid_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 931 | |
| 932 | tlv_pos += (sizeof(wildcard_ssid_tlv->header) |
| 933 | + le16_to_cpu(wildcard_ssid_tlv->header.len)); |
| 934 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 935 | mwifiex_dbg(adapter, INFO, |
| 936 | "info: scan: ssid[%d]: %s, %d\n", |
| 937 | i, wildcard_ssid_tlv->ssid, |
| 938 | wildcard_ssid_tlv->max_ssid_length); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 939 | |
| 940 | /* Empty wildcard ssid with a maxlen will match many or |
| 941 | potentially all SSIDs (maxlen == 32), therefore do |
| 942 | not treat the scan as |
| 943 | filtered. */ |
| 944 | if (!ssid_len && wildcard_ssid_tlv->max_ssid_length) |
| 945 | ssid_filter = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /* |
| 949 | * The default number of channels sent in the command is low to |
| 950 | * ensure the response buffer from the firmware does not |
| 951 | * truncate scan results. That is not an issue with an SSID |
| 952 | * or BSSID filter applied to the scan results in the firmware. |
| 953 | */ |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 954 | memcpy(tmpaddr, scan_cfg_out->specific_bssid, ETH_ALEN); |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 955 | if ((i && ssid_filter) || |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 956 | !is_zero_ether_addr(tmpaddr)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 957 | *filtered_scan = true; |
Avinash Patil | 8eda10e | 2014-09-17 23:01:26 +0530 | [diff] [blame] | 958 | |
| 959 | if (user_scan_in->scan_chan_gap) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 960 | mwifiex_dbg(adapter, INFO, |
| 961 | "info: scan: channel gap = %d\n", |
| 962 | user_scan_in->scan_chan_gap); |
Avinash Patil | 8eda10e | 2014-09-17 23:01:26 +0530 | [diff] [blame] | 963 | *max_chan_per_scan = |
| 964 | MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN; |
| 965 | |
| 966 | chan_gap_tlv = (void *)tlv_pos; |
| 967 | chan_gap_tlv->header.type = |
| 968 | cpu_to_le16(TLV_TYPE_SCAN_CHANNEL_GAP); |
| 969 | chan_gap_tlv->header.len = |
| 970 | cpu_to_le16(sizeof(chan_gap_tlv->chan_gap)); |
| 971 | chan_gap_tlv->chan_gap = |
| 972 | cpu_to_le16((user_scan_in->scan_chan_gap)); |
| 973 | tlv_pos += |
| 974 | sizeof(struct mwifiex_ie_types_scan_chan_gap); |
| 975 | } |
Ganapathi Bhat | c2a8f0f | 2016-07-25 21:21:07 +0530 | [diff] [blame] | 976 | |
| 977 | if (!ether_addr_equal(user_scan_in->random_mac, zero_mac)) { |
| 978 | random_mac_tlv = (void *)tlv_pos; |
| 979 | random_mac_tlv->header.type = |
| 980 | cpu_to_le16(TLV_TYPE_RANDOM_MAC); |
| 981 | random_mac_tlv->header.len = |
| 982 | cpu_to_le16(sizeof(random_mac_tlv->mac)); |
| 983 | ether_addr_copy(random_mac_tlv->mac, |
| 984 | user_scan_in->random_mac); |
| 985 | tlv_pos += |
| 986 | sizeof(struct mwifiex_ie_types_random_mac); |
| 987 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 988 | } else { |
| 989 | scan_cfg_out->bss_mode = (u8) adapter->scan_mode; |
| 990 | num_probes = adapter->scan_probes; |
| 991 | } |
| 992 | |
| 993 | /* |
| 994 | * If a specific BSSID or SSID is used, the number of channels in the |
| 995 | * scan command will be increased to the absolute maximum. |
| 996 | */ |
| 997 | if (*filtered_scan) |
| 998 | *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN; |
| 999 | else |
Amitkumar Karwar | 658f37b | 2012-06-06 21:12:42 -0700 | [diff] [blame] | 1000 | *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1001 | |
Aniket Nagarnaik | 40d7412 | 2015-07-16 08:05:21 -0700 | [diff] [blame] | 1002 | if (adapter->ext_scan) { |
| 1003 | bss_mode = (struct mwifiex_ie_types_bss_mode *)tlv_pos; |
| 1004 | bss_mode->header.type = cpu_to_le16(TLV_TYPE_BSS_MODE); |
| 1005 | bss_mode->header.len = cpu_to_le16(sizeof(bss_mode->bss_mode)); |
| 1006 | bss_mode->bss_mode = scan_cfg_out->bss_mode; |
| 1007 | tlv_pos += sizeof(bss_mode->header) + |
| 1008 | le16_to_cpu(bss_mode->header.len); |
| 1009 | } |
| 1010 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1011 | /* If the input config or adapter has the number of Probes set, |
| 1012 | add tlv */ |
| 1013 | if (num_probes) { |
| 1014 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1015 | mwifiex_dbg(adapter, INFO, |
| 1016 | "info: scan: num_probes = %d\n", |
| 1017 | num_probes); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1018 | |
| 1019 | num_probes_tlv = (struct mwifiex_ie_types_num_probes *) tlv_pos; |
| 1020 | num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES); |
| 1021 | num_probes_tlv->header.len = |
| 1022 | cpu_to_le16(sizeof(num_probes_tlv->num_probes)); |
| 1023 | num_probes_tlv->num_probes = cpu_to_le16((u16) num_probes); |
| 1024 | |
| 1025 | tlv_pos += sizeof(num_probes_tlv->header) + |
| 1026 | le16_to_cpu(num_probes_tlv->header.len); |
| 1027 | |
| 1028 | } |
| 1029 | |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1030 | if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) && |
| 1031 | (priv->adapter->config_bands & BAND_GN || |
| 1032 | priv->adapter->config_bands & BAND_AN)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1033 | ht_cap = (struct mwifiex_ie_types_htcap *) tlv_pos; |
| 1034 | memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap)); |
| 1035 | ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY); |
| 1036 | ht_cap->header.len = |
| 1037 | cpu_to_le16(sizeof(struct ieee80211_ht_cap)); |
Amitkumar Karwar | a46b7b5 | 2011-04-27 19:13:12 -0700 | [diff] [blame] | 1038 | radio_type = |
| 1039 | mwifiex_band_to_radio_type(priv->adapter->config_bands); |
Amitkumar Karwar | 341b880 | 2014-02-07 16:27:31 -0800 | [diff] [blame] | 1040 | mwifiex_fill_cap_info(priv, radio_type, &ht_cap->ht_cap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1041 | tlv_pos += sizeof(struct mwifiex_ie_types_htcap); |
| 1042 | } |
| 1043 | |
| 1044 | /* Append vendor specific IE TLV */ |
| 1045 | mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_SCAN, &tlv_pos); |
| 1046 | |
| 1047 | /* |
| 1048 | * Set the output for the channel TLV to the address in the tlv buffer |
| 1049 | * past any TLVs that were added in this function (SSID, num_probes). |
| 1050 | * Channel TLVs will be added past this for each scan command, |
| 1051 | * preserving the TLVs that were previously added. |
| 1052 | */ |
| 1053 | *chan_list_out = |
| 1054 | (struct mwifiex_ie_types_chan_list_param_set *) tlv_pos; |
| 1055 | |
| 1056 | if (user_scan_in && user_scan_in->chan_list[0].chan_number) { |
| 1057 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1058 | mwifiex_dbg(adapter, INFO, |
| 1059 | "info: Scan: Using supplied channel list\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1060 | |
| 1061 | for (chan_idx = 0; |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1062 | chan_idx < MWIFIEX_USER_SCAN_CHAN_MAX && |
| 1063 | user_scan_in->chan_list[chan_idx].chan_number; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1064 | chan_idx++) { |
| 1065 | |
| 1066 | channel = user_scan_in->chan_list[chan_idx].chan_number; |
Andreas Fenkart | 948ad6b | 2016-03-10 09:44:09 +0100 | [diff] [blame] | 1067 | scan_chan_list[chan_idx].chan_number = channel; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1068 | |
| 1069 | radio_type = |
| 1070 | user_scan_in->chan_list[chan_idx].radio_type; |
Andreas Fenkart | 948ad6b | 2016-03-10 09:44:09 +0100 | [diff] [blame] | 1071 | scan_chan_list[chan_idx].radio_type = radio_type; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1072 | |
| 1073 | scan_type = user_scan_in->chan_list[chan_idx].scan_type; |
| 1074 | |
| 1075 | if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE) |
Andreas Fenkart | 948ad6b | 2016-03-10 09:44:09 +0100 | [diff] [blame] | 1076 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1077 | |= (MWIFIEX_PASSIVE_SCAN | |
| 1078 | MWIFIEX_HIDDEN_SSID_REPORT); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1079 | else |
Andreas Fenkart | 948ad6b | 2016-03-10 09:44:09 +0100 | [diff] [blame] | 1080 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1081 | &= ~MWIFIEX_PASSIVE_SCAN; |
| 1082 | |
Amitkumar Karwar | 1b499cb | 2016-04-24 23:49:51 -0700 | [diff] [blame] | 1083 | scan_chan_list[chan_idx].chan_scan_mode_bitmap |
| 1084 | |= MWIFIEX_DISABLE_CHAN_FILT; |
Amitkumar Karwar | f3e1af3 | 2012-10-19 19:19:18 -0700 | [diff] [blame] | 1085 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1086 | if (user_scan_in->chan_list[chan_idx].scan_time) { |
| 1087 | scan_dur = (u16) user_scan_in-> |
| 1088 | chan_list[chan_idx].scan_time; |
| 1089 | } else { |
| 1090 | if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE) |
| 1091 | scan_dur = adapter->passive_scan_time; |
| 1092 | else if (*filtered_scan) |
| 1093 | scan_dur = adapter->specific_scan_time; |
| 1094 | else |
| 1095 | scan_dur = adapter->active_scan_time; |
| 1096 | } |
| 1097 | |
Andreas Fenkart | 948ad6b | 2016-03-10 09:44:09 +0100 | [diff] [blame] | 1098 | scan_chan_list[chan_idx].min_scan_time = |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1099 | cpu_to_le16(scan_dur); |
Andreas Fenkart | 948ad6b | 2016-03-10 09:44:09 +0100 | [diff] [blame] | 1100 | scan_chan_list[chan_idx].max_scan_time = |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1101 | cpu_to_le16(scan_dur); |
| 1102 | } |
| 1103 | |
| 1104 | /* Check if we are only scanning the current channel */ |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1105 | if ((chan_idx == 1) && |
| 1106 | (user_scan_in->chan_list[0].chan_number == |
| 1107 | priv->curr_bss_params.bss_descriptor.channel)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1108 | *scan_current_only = true; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1109 | mwifiex_dbg(adapter, INFO, |
| 1110 | "info: Scan: Scanning current channel only\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1111 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1112 | } else { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1113 | mwifiex_dbg(adapter, INFO, |
| 1114 | "info: Scan: Creating full region channel list\n"); |
Kirtika Ruchandani | 8ac9134 | 2016-11-23 17:24:54 -0800 | [diff] [blame] | 1115 | mwifiex_scan_create_channel_list(priv, user_scan_in, |
| 1116 | scan_chan_list, |
| 1117 | *filtered_scan); |
Amitkumar Karwar | 658f37b | 2012-06-06 21:12:42 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * This function inspects the scan response buffer for pointers to |
| 1124 | * expected TLVs. |
| 1125 | * |
| 1126 | * TLVs can be included at the end of the scan response BSS information. |
| 1127 | * |
| 1128 | * Data in the buffer is parsed pointers to TLVs that can potentially |
| 1129 | * be passed back in the response. |
| 1130 | */ |
| 1131 | static void |
| 1132 | mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter, |
| 1133 | struct mwifiex_ie_types_data *tlv, |
| 1134 | u32 tlv_buf_size, u32 req_tlv_type, |
| 1135 | struct mwifiex_ie_types_data **tlv_data) |
| 1136 | { |
| 1137 | struct mwifiex_ie_types_data *current_tlv; |
| 1138 | u32 tlv_buf_left; |
| 1139 | u32 tlv_type; |
| 1140 | u32 tlv_len; |
| 1141 | |
| 1142 | current_tlv = tlv; |
| 1143 | tlv_buf_left = tlv_buf_size; |
| 1144 | *tlv_data = NULL; |
| 1145 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1146 | mwifiex_dbg(adapter, INFO, |
| 1147 | "info: SCAN_RESP: tlv_buf_size = %d\n", |
| 1148 | tlv_buf_size); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1149 | |
| 1150 | while (tlv_buf_left >= sizeof(struct mwifiex_ie_types_header)) { |
| 1151 | |
| 1152 | tlv_type = le16_to_cpu(current_tlv->header.type); |
| 1153 | tlv_len = le16_to_cpu(current_tlv->header.len); |
| 1154 | |
| 1155 | if (sizeof(tlv->header) + tlv_len > tlv_buf_left) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1156 | mwifiex_dbg(adapter, ERROR, |
| 1157 | "SCAN_RESP: TLV buffer corrupt\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1158 | break; |
| 1159 | } |
| 1160 | |
| 1161 | if (req_tlv_type == tlv_type) { |
| 1162 | switch (tlv_type) { |
| 1163 | case TLV_TYPE_TSFTIMESTAMP: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1164 | mwifiex_dbg(adapter, INFO, |
| 1165 | "info: SCAN_RESP: TSF\t" |
| 1166 | "timestamp TLV, len = %d\n", |
| 1167 | tlv_len); |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1168 | *tlv_data = current_tlv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1169 | break; |
| 1170 | case TLV_TYPE_CHANNELBANDLIST: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1171 | mwifiex_dbg(adapter, INFO, |
| 1172 | "info: SCAN_RESP: channel\t" |
| 1173 | "band list TLV, len = %d\n", |
| 1174 | tlv_len); |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1175 | *tlv_data = current_tlv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1176 | break; |
| 1177 | default: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1178 | mwifiex_dbg(adapter, ERROR, |
| 1179 | "SCAN_RESP: unhandled TLV = %d\n", |
| 1180 | tlv_type); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1181 | /* Give up, this seems corrupted */ |
| 1182 | return; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | if (*tlv_data) |
| 1187 | break; |
| 1188 | |
| 1189 | |
| 1190 | tlv_buf_left -= (sizeof(tlv->header) + tlv_len); |
| 1191 | current_tlv = |
| 1192 | (struct mwifiex_ie_types_data *) (current_tlv->data + |
| 1193 | tlv_len); |
| 1194 | |
| 1195 | } /* while */ |
| 1196 | } |
| 1197 | |
| 1198 | /* |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1199 | * This function parses provided beacon buffer and updates |
| 1200 | * respective fields in bss descriptor structure. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1201 | */ |
Amitkumar Karwar | 9558a40 | 2012-04-16 21:36:51 -0700 | [diff] [blame] | 1202 | int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter, |
| 1203 | struct mwifiex_bssdescriptor *bss_entry) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1204 | { |
| 1205 | int ret = 0; |
| 1206 | u8 element_id; |
| 1207 | struct ieee_types_fh_param_set *fh_param_set; |
| 1208 | struct ieee_types_ds_param_set *ds_param_set; |
| 1209 | struct ieee_types_cf_param_set *cf_param_set; |
| 1210 | struct ieee_types_ibss_param_set *ibss_param_set; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1211 | u8 *current_ptr; |
| 1212 | u8 *rate; |
| 1213 | u8 element_len; |
| 1214 | u16 total_ie_len; |
| 1215 | u8 bytes_to_copy; |
| 1216 | u8 rate_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1217 | u8 found_data_rate_ie; |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1218 | u32 bytes_left; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1219 | struct ieee_types_vendor_specific *vendor_ie; |
| 1220 | const u8 wpa_oui[4] = { 0x00, 0x50, 0xf2, 0x01 }; |
| 1221 | const u8 wmm_oui[4] = { 0x00, 0x50, 0xf2, 0x02 }; |
| 1222 | |
| 1223 | found_data_rate_ie = false; |
| 1224 | rate_size = 0; |
Amitkumar Karwar | 9558a40 | 2012-04-16 21:36:51 -0700 | [diff] [blame] | 1225 | current_ptr = bss_entry->beacon_buf; |
| 1226 | bytes_left = bss_entry->beacon_buf_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1227 | |
| 1228 | /* Process variable IE */ |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1229 | while (bytes_left >= 2) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1230 | element_id = *current_ptr; |
| 1231 | element_len = *(current_ptr + 1); |
| 1232 | total_ie_len = element_len + sizeof(struct ieee_types_header); |
| 1233 | |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1234 | if (bytes_left < total_ie_len) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1235 | mwifiex_dbg(adapter, ERROR, |
| 1236 | "err: InterpretIE: in processing\t" |
| 1237 | "IE, bytes left < IE length\n"); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1238 | return -1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1239 | } |
| 1240 | switch (element_id) { |
| 1241 | case WLAN_EID_SSID: |
| 1242 | bss_entry->ssid.ssid_len = element_len; |
| 1243 | memcpy(bss_entry->ssid.ssid, (current_ptr + 2), |
| 1244 | element_len); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1245 | mwifiex_dbg(adapter, INFO, |
| 1246 | "info: InterpretIE: ssid: %-32s\n", |
| 1247 | bss_entry->ssid.ssid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1248 | break; |
| 1249 | |
| 1250 | case WLAN_EID_SUPP_RATES: |
| 1251 | memcpy(bss_entry->data_rates, current_ptr + 2, |
| 1252 | element_len); |
| 1253 | memcpy(bss_entry->supported_rates, current_ptr + 2, |
| 1254 | element_len); |
| 1255 | rate_size = element_len; |
| 1256 | found_data_rate_ie = true; |
| 1257 | break; |
| 1258 | |
| 1259 | case WLAN_EID_FH_PARAMS: |
| 1260 | fh_param_set = |
| 1261 | (struct ieee_types_fh_param_set *) current_ptr; |
| 1262 | memcpy(&bss_entry->phy_param_set.fh_param_set, |
| 1263 | fh_param_set, |
| 1264 | sizeof(struct ieee_types_fh_param_set)); |
| 1265 | break; |
| 1266 | |
| 1267 | case WLAN_EID_DS_PARAMS: |
| 1268 | ds_param_set = |
| 1269 | (struct ieee_types_ds_param_set *) current_ptr; |
| 1270 | |
| 1271 | bss_entry->channel = ds_param_set->current_chan; |
| 1272 | |
| 1273 | memcpy(&bss_entry->phy_param_set.ds_param_set, |
| 1274 | ds_param_set, |
| 1275 | sizeof(struct ieee_types_ds_param_set)); |
| 1276 | break; |
| 1277 | |
| 1278 | case WLAN_EID_CF_PARAMS: |
| 1279 | cf_param_set = |
| 1280 | (struct ieee_types_cf_param_set *) current_ptr; |
| 1281 | memcpy(&bss_entry->ss_param_set.cf_param_set, |
| 1282 | cf_param_set, |
| 1283 | sizeof(struct ieee_types_cf_param_set)); |
| 1284 | break; |
| 1285 | |
| 1286 | case WLAN_EID_IBSS_PARAMS: |
| 1287 | ibss_param_set = |
| 1288 | (struct ieee_types_ibss_param_set *) |
| 1289 | current_ptr; |
| 1290 | memcpy(&bss_entry->ss_param_set.ibss_param_set, |
| 1291 | ibss_param_set, |
| 1292 | sizeof(struct ieee_types_ibss_param_set)); |
| 1293 | break; |
| 1294 | |
| 1295 | case WLAN_EID_ERP_INFO: |
| 1296 | bss_entry->erp_flags = *(current_ptr + 2); |
| 1297 | break; |
| 1298 | |
Amitkumar Karwar | 2a7305c | 2013-06-19 08:49:05 -0700 | [diff] [blame] | 1299 | case WLAN_EID_PWR_CONSTRAINT: |
| 1300 | bss_entry->local_constraint = *(current_ptr + 2); |
| 1301 | bss_entry->sensed_11h = true; |
| 1302 | break; |
| 1303 | |
| 1304 | case WLAN_EID_CHANNEL_SWITCH: |
| 1305 | bss_entry->chan_sw_ie_present = true; |
| 1306 | case WLAN_EID_PWR_CAPABILITY: |
| 1307 | case WLAN_EID_TPC_REPORT: |
| 1308 | case WLAN_EID_QUIET: |
| 1309 | bss_entry->sensed_11h = true; |
| 1310 | break; |
| 1311 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1312 | case WLAN_EID_EXT_SUPP_RATES: |
| 1313 | /* |
| 1314 | * Only process extended supported rate |
| 1315 | * if data rate is already found. |
| 1316 | * Data rate IE should come before |
| 1317 | * extended supported rate IE |
| 1318 | */ |
| 1319 | if (found_data_rate_ie) { |
| 1320 | if ((element_len + rate_size) > |
| 1321 | MWIFIEX_SUPPORTED_RATES) |
| 1322 | bytes_to_copy = |
| 1323 | (MWIFIEX_SUPPORTED_RATES - |
| 1324 | rate_size); |
| 1325 | else |
| 1326 | bytes_to_copy = element_len; |
| 1327 | |
| 1328 | rate = (u8 *) bss_entry->data_rates; |
| 1329 | rate += rate_size; |
| 1330 | memcpy(rate, current_ptr + 2, bytes_to_copy); |
| 1331 | |
| 1332 | rate = (u8 *) bss_entry->supported_rates; |
| 1333 | rate += rate_size; |
| 1334 | memcpy(rate, current_ptr + 2, bytes_to_copy); |
| 1335 | } |
| 1336 | break; |
| 1337 | |
| 1338 | case WLAN_EID_VENDOR_SPECIFIC: |
| 1339 | vendor_ie = (struct ieee_types_vendor_specific *) |
| 1340 | current_ptr; |
| 1341 | |
| 1342 | if (!memcmp |
| 1343 | (vendor_ie->vend_hdr.oui, wpa_oui, |
| 1344 | sizeof(wpa_oui))) { |
| 1345 | bss_entry->bcn_wpa_ie = |
| 1346 | (struct ieee_types_vendor_specific *) |
| 1347 | current_ptr; |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1348 | bss_entry->wpa_offset = (u16) |
| 1349 | (current_ptr - bss_entry->beacon_buf); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1350 | } else if (!memcmp(vendor_ie->vend_hdr.oui, wmm_oui, |
| 1351 | sizeof(wmm_oui))) { |
| 1352 | if (total_ie_len == |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1353 | sizeof(struct ieee_types_wmm_parameter) || |
| 1354 | total_ie_len == |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1355 | sizeof(struct ieee_types_wmm_info)) |
| 1356 | /* |
| 1357 | * Only accept and copy the WMM IE if |
| 1358 | * it matches the size expected for the |
| 1359 | * WMM Info IE or the WMM Parameter IE. |
| 1360 | */ |
| 1361 | memcpy((u8 *) &bss_entry->wmm_ie, |
| 1362 | current_ptr, total_ie_len); |
| 1363 | } |
| 1364 | break; |
| 1365 | case WLAN_EID_RSN: |
| 1366 | bss_entry->bcn_rsn_ie = |
| 1367 | (struct ieee_types_generic *) current_ptr; |
| 1368 | bss_entry->rsn_offset = (u16) (current_ptr - |
| 1369 | bss_entry->beacon_buf); |
| 1370 | break; |
| 1371 | case WLAN_EID_BSS_AC_ACCESS_DELAY: |
| 1372 | bss_entry->bcn_wapi_ie = |
| 1373 | (struct ieee_types_generic *) current_ptr; |
| 1374 | bss_entry->wapi_offset = (u16) (current_ptr - |
| 1375 | bss_entry->beacon_buf); |
| 1376 | break; |
| 1377 | case WLAN_EID_HT_CAPABILITY: |
| 1378 | bss_entry->bcn_ht_cap = (struct ieee80211_ht_cap *) |
| 1379 | (current_ptr + |
| 1380 | sizeof(struct ieee_types_header)); |
| 1381 | bss_entry->ht_cap_offset = (u16) (current_ptr + |
| 1382 | sizeof(struct ieee_types_header) - |
| 1383 | bss_entry->beacon_buf); |
| 1384 | break; |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 1385 | case WLAN_EID_HT_OPERATION: |
| 1386 | bss_entry->bcn_ht_oper = |
| 1387 | (struct ieee80211_ht_operation *)(current_ptr + |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1388 | sizeof(struct ieee_types_header)); |
| 1389 | bss_entry->ht_info_offset = (u16) (current_ptr + |
| 1390 | sizeof(struct ieee_types_header) - |
| 1391 | bss_entry->beacon_buf); |
| 1392 | break; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 1393 | case WLAN_EID_VHT_CAPABILITY: |
| 1394 | bss_entry->disable_11ac = false; |
| 1395 | bss_entry->bcn_vht_cap = |
| 1396 | (void *)(current_ptr + |
| 1397 | sizeof(struct ieee_types_header)); |
| 1398 | bss_entry->vht_cap_offset = |
| 1399 | (u16)((u8 *)bss_entry->bcn_vht_cap - |
| 1400 | bss_entry->beacon_buf); |
| 1401 | break; |
| 1402 | case WLAN_EID_VHT_OPERATION: |
| 1403 | bss_entry->bcn_vht_oper = |
| 1404 | (void *)(current_ptr + |
| 1405 | sizeof(struct ieee_types_header)); |
| 1406 | bss_entry->vht_info_offset = |
| 1407 | (u16)((u8 *)bss_entry->bcn_vht_oper - |
| 1408 | bss_entry->beacon_buf); |
| 1409 | break; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1410 | case WLAN_EID_BSS_COEX_2040: |
Amitkumar Karwar | cf831ff | 2014-04-16 22:01:53 -0700 | [diff] [blame] | 1411 | bss_entry->bcn_bss_co_2040 = current_ptr; |
| 1412 | bss_entry->bss_co_2040_offset = |
| 1413 | (u16) (current_ptr - bss_entry->beacon_buf); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1414 | break; |
| 1415 | case WLAN_EID_EXT_CAPABILITY: |
Amitkumar Karwar | cf831ff | 2014-04-16 22:01:53 -0700 | [diff] [blame] | 1416 | bss_entry->bcn_ext_cap = current_ptr; |
| 1417 | bss_entry->ext_cap_offset = |
| 1418 | (u16) (current_ptr - bss_entry->beacon_buf); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1419 | break; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 1420 | case WLAN_EID_OPMODE_NOTIF: |
Amitkumar Karwar | cf831ff | 2014-04-16 22:01:53 -0700 | [diff] [blame] | 1421 | bss_entry->oper_mode = (void *)current_ptr; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 1422 | bss_entry->oper_mode_offset = |
| 1423 | (u16)((u8 *)bss_entry->oper_mode - |
| 1424 | bss_entry->beacon_buf); |
| 1425 | break; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1426 | default: |
| 1427 | break; |
| 1428 | } |
| 1429 | |
| 1430 | current_ptr += element_len + 2; |
| 1431 | |
| 1432 | /* Need to account for IE ID and IE Len */ |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1433 | bytes_left -= (element_len + 2); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1434 | |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1435 | } /* while (bytes_left > 2) */ |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1436 | return ret; |
| 1437 | } |
| 1438 | |
| 1439 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1440 | * This function converts radio type scan parameter to a band configuration |
| 1441 | * to be used in join command. |
| 1442 | */ |
| 1443 | static u8 |
| 1444 | mwifiex_radio_type_to_band(u8 radio_type) |
| 1445 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1446 | switch (radio_type) { |
| 1447 | case HostCmd_SCAN_RADIO_TYPE_A: |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1448 | return BAND_A; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1449 | case HostCmd_SCAN_RADIO_TYPE_BG: |
| 1450 | default: |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1451 | return BAND_G; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1452 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1456 | * This is an internal function used to start a scan based on an input |
| 1457 | * configuration. |
| 1458 | * |
| 1459 | * This uses the input user scan configuration information when provided in |
| 1460 | * order to send the appropriate scan commands to firmware to populate or |
| 1461 | * update the internal driver scan table. |
| 1462 | */ |
Amitkumar Karwar | 1a1fb97 | 2012-06-27 19:57:56 -0700 | [diff] [blame] | 1463 | int mwifiex_scan_networks(struct mwifiex_private *priv, |
| 1464 | const struct mwifiex_user_scan_cfg *user_scan_in) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1465 | { |
Bing Zhao | c247633 | 2012-10-05 20:21:40 -0700 | [diff] [blame] | 1466 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1467 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1468 | struct cmd_ctrl_node *cmd_node; |
| 1469 | union mwifiex_scan_cmd_config_tlv *scan_cfg_out; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1470 | struct mwifiex_ie_types_chan_list_param_set *chan_list_out; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1471 | struct mwifiex_chan_scan_param_set *scan_chan_list; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1472 | u8 filtered_scan; |
| 1473 | u8 scan_current_chan_only; |
| 1474 | u8 max_chan_per_scan; |
| 1475 | unsigned long flags; |
| 1476 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1477 | if (adapter->scan_processing) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1478 | mwifiex_dbg(adapter, WARN, |
| 1479 | "cmd: Scan already in process...\n"); |
Bing Zhao | c247633 | 2012-10-05 20:21:40 -0700 | [diff] [blame] | 1480 | return -EBUSY; |
| 1481 | } |
| 1482 | |
| 1483 | if (priv->scan_block) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1484 | mwifiex_dbg(adapter, WARN, |
| 1485 | "cmd: Scan is blocked during association...\n"); |
Bing Zhao | c247633 | 2012-10-05 20:21:40 -0700 | [diff] [blame] | 1486 | return -EBUSY; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Amitkumar Karwar | e00483f | 2015-01-07 03:57:39 -0800 | [diff] [blame] | 1489 | if (adapter->surprise_removed || adapter->is_cmd_timedout) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1490 | mwifiex_dbg(adapter, ERROR, |
| 1491 | "Ignore scan. Card removed or firmware in bad state\n"); |
Amitkumar Karwar | e00483f | 2015-01-07 03:57:39 -0800 | [diff] [blame] | 1492 | return -EFAULT; |
| 1493 | } |
| 1494 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1495 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 1496 | adapter->scan_processing = true; |
| 1497 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 1498 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1499 | scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv), |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 1500 | GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1501 | if (!scan_cfg_out) { |
Amitkumar Karwar | 061f2e6 | 2012-10-05 20:21:41 -0700 | [diff] [blame] | 1502 | ret = -ENOMEM; |
| 1503 | goto done; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 1506 | scan_chan_list = kcalloc(MWIFIEX_USER_SCAN_CHAN_MAX, |
| 1507 | sizeof(struct mwifiex_chan_scan_param_set), |
| 1508 | GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1509 | if (!scan_chan_list) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1510 | kfree(scan_cfg_out); |
Amitkumar Karwar | 061f2e6 | 2012-10-05 20:21:41 -0700 | [diff] [blame] | 1511 | ret = -ENOMEM; |
| 1512 | goto done; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1515 | mwifiex_config_scan(priv, user_scan_in, &scan_cfg_out->config, |
| 1516 | &chan_list_out, scan_chan_list, &max_chan_per_scan, |
| 1517 | &filtered_scan, &scan_current_chan_only); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1518 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1519 | ret = mwifiex_scan_channel_list(priv, max_chan_per_scan, filtered_scan, |
| 1520 | &scan_cfg_out->config, chan_list_out, |
| 1521 | scan_chan_list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1522 | |
| 1523 | /* Get scan command from scan_pending_q and put to cmd_pending_q */ |
| 1524 | if (!ret) { |
| 1525 | spin_lock_irqsave(&adapter->scan_pending_q_lock, flags); |
| 1526 | if (!list_empty(&adapter->scan_pending_q)) { |
| 1527 | cmd_node = list_first_entry(&adapter->scan_pending_q, |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1528 | struct cmd_ctrl_node, list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1529 | list_del(&cmd_node->list); |
| 1530 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1531 | flags); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1532 | mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, |
| 1533 | true); |
Amitkumar Karwar | 1a1fb97 | 2012-06-27 19:57:56 -0700 | [diff] [blame] | 1534 | queue_work(adapter->workqueue, &adapter->main_work); |
Amitkumar Karwar | 00d7ea1 | 2013-03-15 18:47:05 -0700 | [diff] [blame] | 1535 | |
| 1536 | /* Perform internal scan synchronously */ |
Bing Zhao | 21de979 | 2013-04-01 12:44:45 -0700 | [diff] [blame] | 1537 | if (!priv->scan_request) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1538 | mwifiex_dbg(adapter, INFO, |
| 1539 | "wait internal scan\n"); |
Amitkumar Karwar | 00d7ea1 | 2013-03-15 18:47:05 -0700 | [diff] [blame] | 1540 | mwifiex_wait_queue_complete(adapter, cmd_node); |
Bing Zhao | 21de979 | 2013-04-01 12:44:45 -0700 | [diff] [blame] | 1541 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1542 | } else { |
| 1543 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, |
| 1544 | flags); |
| 1545 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | kfree(scan_cfg_out); |
| 1549 | kfree(scan_chan_list); |
Amitkumar Karwar | 061f2e6 | 2012-10-05 20:21:41 -0700 | [diff] [blame] | 1550 | done: |
| 1551 | if (ret) { |
| 1552 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 1553 | adapter->scan_processing = false; |
| 1554 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 1555 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1556 | return ret; |
| 1557 | } |
| 1558 | |
| 1559 | /* |
| 1560 | * This function prepares a scan command to be sent to the firmware. |
| 1561 | * |
| 1562 | * This uses the scan command configuration sent to the command processing |
| 1563 | * module in command preparation stage to configure a scan command structure |
| 1564 | * to send to firmware. |
| 1565 | * |
| 1566 | * The fixed fields specifying the BSS type and BSSID filters as well as a |
| 1567 | * variable number/length of TLVs are sent in the command to firmware. |
| 1568 | * |
| 1569 | * Preparation also includes - |
| 1570 | * - Setting command ID, and proper size |
| 1571 | * - Ensuring correct endian-ness |
| 1572 | */ |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 1573 | int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd, |
| 1574 | struct mwifiex_scan_cmd_config *scan_cfg) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1575 | { |
| 1576 | struct host_cmd_ds_802_11_scan *scan_cmd = &cmd->params.scan; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1577 | |
| 1578 | /* Set fixed field variables in scan command */ |
| 1579 | scan_cmd->bss_mode = scan_cfg->bss_mode; |
| 1580 | memcpy(scan_cmd->bssid, scan_cfg->specific_bssid, |
| 1581 | sizeof(scan_cmd->bssid)); |
| 1582 | memcpy(scan_cmd->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len); |
| 1583 | |
| 1584 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN); |
| 1585 | |
| 1586 | /* Size is equal to the sizeof(fixed portions) + the TLV len + header */ |
| 1587 | cmd->size = cpu_to_le16((u16) (sizeof(scan_cmd->bss_mode) |
| 1588 | + sizeof(scan_cmd->bssid) |
| 1589 | + scan_cfg->tlv_buf_len + S_DS_GEN)); |
| 1590 | |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | /* |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1595 | * This function checks compatibility of requested network with current |
| 1596 | * driver settings. |
| 1597 | */ |
| 1598 | int mwifiex_check_network_compatibility(struct mwifiex_private *priv, |
| 1599 | struct mwifiex_bssdescriptor *bss_desc) |
| 1600 | { |
| 1601 | int ret = -1; |
| 1602 | |
| 1603 | if (!bss_desc) |
| 1604 | return -1; |
| 1605 | |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 1606 | if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band, |
| 1607 | (u16) bss_desc->channel, 0))) { |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1608 | switch (priv->bss_mode) { |
| 1609 | case NL80211_IFTYPE_STATION: |
| 1610 | case NL80211_IFTYPE_ADHOC: |
| 1611 | ret = mwifiex_is_network_compatible(priv, bss_desc, |
| 1612 | priv->bss_mode); |
| 1613 | if (ret) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1614 | mwifiex_dbg(priv->adapter, ERROR, |
| 1615 | "Incompatible network settings\n"); |
Fengguang Wu | 2f9279b | 2012-08-07 10:26:53 +0800 | [diff] [blame] | 1616 | break; |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1617 | default: |
Fengguang Wu | 2f9279b | 2012-08-07 10:26:53 +0800 | [diff] [blame] | 1618 | ret = 0; |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | return ret; |
| 1623 | } |
| 1624 | |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1625 | /* This function checks if SSID string contains all zeroes or length is zero */ |
| 1626 | static bool mwifiex_is_hidden_ssid(struct cfg80211_ssid *ssid) |
| 1627 | { |
| 1628 | int idx; |
| 1629 | |
| 1630 | for (idx = 0; idx < ssid->ssid_len; idx++) { |
| 1631 | if (ssid->ssid[idx]) |
| 1632 | return false; |
| 1633 | } |
| 1634 | |
| 1635 | return true; |
| 1636 | } |
| 1637 | |
| 1638 | /* This function checks if any hidden SSID found in passive scan channels |
| 1639 | * and save those channels for specific SSID active scan |
| 1640 | */ |
| 1641 | static int mwifiex_save_hidden_ssid_channels(struct mwifiex_private *priv, |
| 1642 | struct cfg80211_bss *bss) |
| 1643 | { |
| 1644 | struct mwifiex_bssdescriptor *bss_desc; |
| 1645 | int ret; |
| 1646 | int chid; |
| 1647 | |
| 1648 | /* Allocate and fill new bss descriptor */ |
| 1649 | bss_desc = kzalloc(sizeof(*bss_desc), GFP_KERNEL); |
| 1650 | if (!bss_desc) |
| 1651 | return -ENOMEM; |
| 1652 | |
| 1653 | ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc); |
| 1654 | if (ret) |
| 1655 | goto done; |
| 1656 | |
| 1657 | if (mwifiex_is_hidden_ssid(&bss_desc->ssid)) { |
| 1658 | mwifiex_dbg(priv->adapter, INFO, "found hidden SSID\n"); |
| 1659 | for (chid = 0 ; chid < MWIFIEX_USER_SCAN_CHAN_MAX; chid++) { |
| 1660 | if (priv->hidden_chan[chid].chan_number == |
| 1661 | bss->channel->hw_value) |
| 1662 | break; |
| 1663 | |
| 1664 | if (!priv->hidden_chan[chid].chan_number) { |
| 1665 | priv->hidden_chan[chid].chan_number = |
| 1666 | bss->channel->hw_value; |
| 1667 | priv->hidden_chan[chid].radio_type = |
| 1668 | bss->channel->band; |
| 1669 | priv->hidden_chan[chid].scan_type = |
| 1670 | MWIFIEX_SCAN_TYPE_ACTIVE; |
| 1671 | break; |
| 1672 | } |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | done: |
Ricky Liang | 5ff2622 | 2016-11-09 11:37:28 +0800 | [diff] [blame] | 1677 | /* beacon_ie buffer was allocated in function |
| 1678 | * mwifiex_fill_new_bss_desc(). Free it now. |
| 1679 | */ |
| 1680 | kfree(bss_desc->beacon_buf); |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1681 | kfree(bss_desc); |
| 1682 | return 0; |
| 1683 | } |
| 1684 | |
Amitkumar Karwar | 9558a40 | 2012-04-16 21:36:51 -0700 | [diff] [blame] | 1685 | static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv, |
| 1686 | struct cfg80211_bss *bss) |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1687 | { |
Jesper Juhl | db652e4 | 2011-11-06 22:58:31 +0100 | [diff] [blame] | 1688 | struct mwifiex_bssdescriptor *bss_desc; |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1689 | int ret; |
| 1690 | unsigned long flags; |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1691 | |
| 1692 | /* Allocate and fill new bss descriptor */ |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 1693 | bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), GFP_KERNEL); |
| 1694 | if (!bss_desc) |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1695 | return -ENOMEM; |
Yogesh Ashok Powar | 5982b47 | 2011-08-29 13:21:10 -0700 | [diff] [blame] | 1696 | |
Amitkumar Karwar | 9558a40 | 2012-04-16 21:36:51 -0700 | [diff] [blame] | 1697 | ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1698 | if (ret) |
| 1699 | goto done; |
| 1700 | |
| 1701 | ret = mwifiex_check_network_compatibility(priv, bss_desc); |
| 1702 | if (ret) |
| 1703 | goto done; |
| 1704 | |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1705 | spin_lock_irqsave(&priv->curr_bcn_buf_lock, flags); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1706 | /* Make a copy of current BSSID descriptor */ |
| 1707 | memcpy(&priv->curr_bss_params.bss_descriptor, bss_desc, |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 1708 | sizeof(priv->curr_bss_params.bss_descriptor)); |
Bing Zhao | d837a2a | 2013-04-12 10:34:17 -0700 | [diff] [blame] | 1709 | |
| 1710 | /* The contents of beacon_ie will be copied to its own buffer |
| 1711 | * in mwifiex_save_curr_bcn() |
| 1712 | */ |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1713 | mwifiex_save_curr_bcn(priv); |
| 1714 | spin_unlock_irqrestore(&priv->curr_bcn_buf_lock, flags); |
| 1715 | |
| 1716 | done: |
Bing Zhao | d837a2a | 2013-04-12 10:34:17 -0700 | [diff] [blame] | 1717 | /* beacon_ie buffer was allocated in function |
| 1718 | * mwifiex_fill_new_bss_desc(). Free it now. |
| 1719 | */ |
| 1720 | kfree(bss_desc->beacon_buf); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1721 | kfree(bss_desc); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 1722 | return 0; |
| 1723 | } |
| 1724 | |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1725 | static int |
| 1726 | mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info, |
| 1727 | u32 *bytes_left, u64 fw_tsf, u8 *radio_type, |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 1728 | bool ext_scan, s32 rssi_val) |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1729 | { |
| 1730 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1731 | struct mwifiex_chan_freq_power *cfp; |
| 1732 | struct cfg80211_bss *bss; |
| 1733 | u8 bssid[ETH_ALEN]; |
| 1734 | s32 rssi; |
| 1735 | const u8 *ie_buf; |
| 1736 | size_t ie_len; |
| 1737 | u16 channel = 0; |
| 1738 | u16 beacon_size = 0; |
| 1739 | u32 curr_bcn_bytes; |
| 1740 | u32 freq; |
| 1741 | u16 beacon_period; |
| 1742 | u16 cap_info_bitmap; |
| 1743 | u8 *current_ptr; |
| 1744 | u64 timestamp; |
| 1745 | struct mwifiex_fixed_bcn_param *bcn_param; |
| 1746 | struct mwifiex_bss_priv *bss_priv; |
| 1747 | |
| 1748 | if (*bytes_left >= sizeof(beacon_size)) { |
| 1749 | /* Extract & convert beacon size from command buffer */ |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 1750 | beacon_size = get_unaligned_le16((*bss_info)); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1751 | *bytes_left -= sizeof(beacon_size); |
| 1752 | *bss_info += sizeof(beacon_size); |
| 1753 | } |
| 1754 | |
| 1755 | if (!beacon_size || beacon_size > *bytes_left) { |
| 1756 | *bss_info += *bytes_left; |
| 1757 | *bytes_left = 0; |
| 1758 | return -EFAULT; |
| 1759 | } |
| 1760 | |
| 1761 | /* Initialize the current working beacon pointer for this BSS |
| 1762 | * iteration |
| 1763 | */ |
| 1764 | current_ptr = *bss_info; |
| 1765 | |
| 1766 | /* Advance the return beacon pointer past the current beacon */ |
| 1767 | *bss_info += beacon_size; |
| 1768 | *bytes_left -= beacon_size; |
| 1769 | |
| 1770 | curr_bcn_bytes = beacon_size; |
| 1771 | |
| 1772 | /* First 5 fields are bssid, RSSI(for legacy scan only), |
| 1773 | * time stamp, beacon interval, and capability information |
| 1774 | */ |
| 1775 | if (curr_bcn_bytes < ETH_ALEN + sizeof(u8) + |
| 1776 | sizeof(struct mwifiex_fixed_bcn_param)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1777 | mwifiex_dbg(adapter, ERROR, |
| 1778 | "InterpretIE: not enough bytes left\n"); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1779 | return -EFAULT; |
| 1780 | } |
| 1781 | |
| 1782 | memcpy(bssid, current_ptr, ETH_ALEN); |
| 1783 | current_ptr += ETH_ALEN; |
| 1784 | curr_bcn_bytes -= ETH_ALEN; |
| 1785 | |
| 1786 | if (!ext_scan) { |
Joe Perches | 45d18c5 | 2014-03-24 13:15:39 -0700 | [diff] [blame] | 1787 | rssi = (s32) *current_ptr; |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1788 | rssi = (-rssi) * 100; /* Convert dBm to mBm */ |
| 1789 | current_ptr += sizeof(u8); |
| 1790 | curr_bcn_bytes -= sizeof(u8); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1791 | mwifiex_dbg(adapter, INFO, |
| 1792 | "info: InterpretIE: RSSI=%d\n", rssi); |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 1793 | } else { |
| 1794 | rssi = rssi_val; |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | bcn_param = (struct mwifiex_fixed_bcn_param *)current_ptr; |
| 1798 | current_ptr += sizeof(*bcn_param); |
| 1799 | curr_bcn_bytes -= sizeof(*bcn_param); |
| 1800 | |
| 1801 | timestamp = le64_to_cpu(bcn_param->timestamp); |
| 1802 | beacon_period = le16_to_cpu(bcn_param->beacon_period); |
| 1803 | |
| 1804 | cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1805 | mwifiex_dbg(adapter, INFO, |
| 1806 | "info: InterpretIE: capabilities=0x%X\n", |
| 1807 | cap_info_bitmap); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1808 | |
| 1809 | /* Rest of the current buffer are IE's */ |
| 1810 | ie_buf = current_ptr; |
| 1811 | ie_len = curr_bcn_bytes; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1812 | mwifiex_dbg(adapter, INFO, |
| 1813 | "info: InterpretIE: IELength for this AP = %d\n", |
| 1814 | curr_bcn_bytes); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1815 | |
| 1816 | while (curr_bcn_bytes >= sizeof(struct ieee_types_header)) { |
| 1817 | u8 element_id, element_len; |
| 1818 | |
| 1819 | element_id = *current_ptr; |
| 1820 | element_len = *(current_ptr + 1); |
| 1821 | if (curr_bcn_bytes < element_len + |
| 1822 | sizeof(struct ieee_types_header)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1823 | mwifiex_dbg(adapter, ERROR, |
| 1824 | "%s: bytes left < IE length\n", __func__); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1825 | return -EFAULT; |
| 1826 | } |
| 1827 | if (element_id == WLAN_EID_DS_PARAMS) { |
| 1828 | channel = *(current_ptr + |
| 1829 | sizeof(struct ieee_types_header)); |
| 1830 | break; |
| 1831 | } |
| 1832 | |
| 1833 | current_ptr += element_len + sizeof(struct ieee_types_header); |
| 1834 | curr_bcn_bytes -= element_len + |
| 1835 | sizeof(struct ieee_types_header); |
| 1836 | } |
| 1837 | |
| 1838 | if (channel) { |
| 1839 | struct ieee80211_channel *chan; |
| 1840 | u8 band; |
| 1841 | |
| 1842 | /* Skip entry if on csa closed channel */ |
| 1843 | if (channel == priv->csa_chan) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1844 | mwifiex_dbg(adapter, WARN, |
| 1845 | "Dropping entry on csa closed channel\n"); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1846 | return 0; |
| 1847 | } |
| 1848 | |
| 1849 | band = BAND_G; |
| 1850 | if (radio_type) |
| 1851 | band = mwifiex_radio_type_to_band(*radio_type & |
| 1852 | (BIT(0) | BIT(1))); |
| 1853 | |
| 1854 | cfp = mwifiex_get_cfp(priv, band, channel, 0); |
| 1855 | |
| 1856 | freq = cfp ? cfp->freq : 0; |
| 1857 | |
Avinash Patil | 4facc34 | 2015-01-28 15:42:00 +0530 | [diff] [blame] | 1858 | chan = ieee80211_get_channel(priv->wdev.wiphy, freq); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1859 | |
| 1860 | if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) { |
Avinash Patil | 4facc34 | 2015-01-28 15:42:00 +0530 | [diff] [blame] | 1861 | bss = cfg80211_inform_bss(priv->wdev.wiphy, |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 1862 | chan, CFG80211_BSS_FTYPE_UNKNOWN, |
| 1863 | bssid, timestamp, |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1864 | cap_info_bitmap, beacon_period, |
| 1865 | ie_buf, ie_len, rssi, GFP_KERNEL); |
Xinming Hu | 02421dd3 | 2015-09-18 06:32:07 -0700 | [diff] [blame] | 1866 | if (bss) { |
| 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, |
| 1873 | ETH_ALEN)) |
| 1874 | mwifiex_update_curr_bss_params(priv, |
| 1875 | bss); |
| 1876 | cfg80211_put_bss(priv->wdev.wiphy, bss); |
| 1877 | } |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1878 | |
| 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", |
| 1883 | channel); |
| 1884 | mwifiex_save_hidden_ssid_channels(priv, bss); |
| 1885 | } |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1886 | } |
| 1887 | } else { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1888 | mwifiex_dbg(adapter, WARN, "missing BSS channel IE\n"); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | |
Avinash Patil | 2144504 | 2014-05-27 21:39:32 -0700 | [diff] [blame] | 1894 | static void mwifiex_complete_scan(struct mwifiex_private *priv) |
| 1895 | { |
| 1896 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1897 | |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 1898 | adapter->survey_idx = 0; |
Avinash Patil | 2144504 | 2014-05-27 21:39:32 -0700 | [diff] [blame] | 1899 | if (adapter->curr_cmd->wait_q_enabled) { |
| 1900 | adapter->cmd_wait_q.status = 0; |
| 1901 | if (!priv->scan_request) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1902 | mwifiex_dbg(adapter, INFO, |
| 1903 | "complete internal scan\n"); |
Avinash Patil | 2144504 | 2014-05-27 21:39:32 -0700 | [diff] [blame] | 1904 | mwifiex_complete_cmd(adapter, adapter->curr_cmd); |
| 1905 | } |
| 1906 | } |
| 1907 | } |
| 1908 | |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1909 | /* This function checks if any hidden SSID found in passive scan channels |
| 1910 | * and do specific SSID active scan for those channels |
| 1911 | */ |
| 1912 | static int |
| 1913 | mwifiex_active_scan_req_for_passive_chan(struct mwifiex_private *priv) |
| 1914 | { |
| 1915 | int ret; |
| 1916 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1917 | u8 id = 0; |
| 1918 | struct mwifiex_user_scan_cfg *user_scan_cfg; |
| 1919 | |
Amitkumar Karwar | 16d25da | 2016-06-27 14:16:29 +0530 | [diff] [blame] | 1920 | if (adapter->active_scan_triggered || !priv->scan_request || |
| 1921 | priv->scan_aborting) { |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1922 | adapter->active_scan_triggered = false; |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
| 1926 | if (!priv->hidden_chan[0].chan_number) { |
| 1927 | mwifiex_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n"); |
| 1928 | return 0; |
| 1929 | } |
| 1930 | user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL); |
| 1931 | |
| 1932 | if (!user_scan_cfg) |
| 1933 | return -ENOMEM; |
| 1934 | |
| 1935 | memset(user_scan_cfg, 0, sizeof(*user_scan_cfg)); |
| 1936 | |
| 1937 | for (id = 0; id < MWIFIEX_USER_SCAN_CHAN_MAX; id++) { |
| 1938 | if (!priv->hidden_chan[id].chan_number) |
| 1939 | break; |
| 1940 | memcpy(&user_scan_cfg->chan_list[id], |
| 1941 | &priv->hidden_chan[id], |
| 1942 | sizeof(struct mwifiex_user_scan_chan)); |
| 1943 | } |
| 1944 | |
| 1945 | adapter->active_scan_triggered = true; |
Ganapathi Bhat | c2a8f0f | 2016-07-25 21:21:07 +0530 | [diff] [blame] | 1946 | ether_addr_copy(user_scan_cfg->random_mac, priv->random_mac); |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1947 | user_scan_cfg->num_ssids = priv->scan_request->n_ssids; |
| 1948 | user_scan_cfg->ssid_list = priv->scan_request->ssids; |
| 1949 | |
| 1950 | ret = mwifiex_scan_networks(priv, user_scan_cfg); |
| 1951 | kfree(user_scan_cfg); |
| 1952 | |
| 1953 | memset(&priv->hidden_chan, 0, sizeof(priv->hidden_chan)); |
| 1954 | |
| 1955 | if (ret) { |
| 1956 | dev_err(priv->adapter->dev, "scan failed: %d\n", ret); |
| 1957 | return ret; |
| 1958 | } |
| 1959 | |
| 1960 | return 0; |
| 1961 | } |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 1962 | static void mwifiex_check_next_scan_command(struct mwifiex_private *priv) |
| 1963 | { |
| 1964 | struct mwifiex_adapter *adapter = priv->adapter; |
Andreas Fenkart | c70ca8c | 2016-03-10 09:44:10 +0100 | [diff] [blame] | 1965 | struct cmd_ctrl_node *cmd_node; |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 1966 | unsigned long flags; |
| 1967 | |
| 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); |
Andreas Fenkart | c70ca8c | 2016-03-10 09:44:10 +0100 | [diff] [blame] | 1971 | |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 1972 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 1973 | adapter->scan_processing = false; |
| 1974 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 1975 | |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 1976 | mwifiex_active_scan_req_for_passive_chan(priv); |
| 1977 | |
Avinash Patil | 2144504 | 2014-05-27 21:39:32 -0700 | [diff] [blame] | 1978 | if (!adapter->ext_scan) |
| 1979 | mwifiex_complete_scan(priv); |
| 1980 | |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 1981 | if (priv->scan_request) { |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 1982 | struct cfg80211_scan_info info = { |
| 1983 | .aborted = false, |
| 1984 | }; |
| 1985 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1986 | mwifiex_dbg(adapter, INFO, |
| 1987 | "info: notifying scan done\n"); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 1988 | cfg80211_scan_done(priv->scan_request, &info); |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 1989 | priv->scan_request = NULL; |
Amitkumar Karwar | 09e672a | 2016-06-27 14:16:28 +0530 | [diff] [blame] | 1990 | priv->scan_aborting = false; |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 1991 | } else { |
| 1992 | priv->scan_aborting = false; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1993 | mwifiex_dbg(adapter, INFO, |
| 1994 | "info: scan already aborted\n"); |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 1995 | } |
Amitkumar Karwar | d8d9125 | 2014-09-12 20:08:58 +0530 | [diff] [blame] | 1996 | } else if ((priv->scan_aborting && !priv->scan_request) || |
| 1997 | priv->scan_block) { |
Amitkumar Karwar | d8d9125 | 2014-09-12 20:08:58 +0530 | [diff] [blame] | 1998 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); |
| 1999 | |
Andreas Fenkart | c70ca8c | 2016-03-10 09:44:10 +0100 | [diff] [blame] | 2000 | mwifiex_cancel_pending_scan_cmd(adapter); |
| 2001 | |
Amitkumar Karwar | d8d9125 | 2014-09-12 20:08:58 +0530 | [diff] [blame] | 2002 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags); |
| 2003 | adapter->scan_processing = false; |
| 2004 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); |
| 2005 | |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 2006 | if (!adapter->active_scan_triggered) { |
| 2007 | if (priv->scan_request) { |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 2008 | struct cfg80211_scan_info info = { |
| 2009 | .aborted = true, |
| 2010 | }; |
| 2011 | |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 2012 | mwifiex_dbg(adapter, INFO, |
| 2013 | "info: aborting scan\n"); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 2014 | cfg80211_scan_done(priv->scan_request, &info); |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 2015 | priv->scan_request = NULL; |
Amitkumar Karwar | 09e672a | 2016-06-27 14:16:28 +0530 | [diff] [blame] | 2016 | priv->scan_aborting = false; |
chunfan chen | 2375fa2 | 2015-08-05 06:09:42 -0700 | [diff] [blame] | 2017 | } else { |
| 2018 | priv->scan_aborting = false; |
| 2019 | mwifiex_dbg(adapter, INFO, |
| 2020 | "info: scan already aborted\n"); |
| 2021 | } |
Amitkumar Karwar | d8d9125 | 2014-09-12 20:08:58 +0530 | [diff] [blame] | 2022 | } |
| 2023 | } else { |
| 2024 | /* Get scan command from scan_pending_q and put to |
| 2025 | * cmd_pending_q |
| 2026 | */ |
| 2027 | cmd_node = list_first_entry(&adapter->scan_pending_q, |
| 2028 | struct cmd_ctrl_node, list); |
| 2029 | list_del(&cmd_node->list); |
| 2030 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); |
| 2031 | mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true); |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | return; |
| 2035 | } |
| 2036 | |
Xinming Hu | a9c790b | 2016-06-16 18:52:22 +0530 | [diff] [blame] | 2037 | void mwifiex_cancel_scan(struct mwifiex_adapter *adapter) |
| 2038 | { |
| 2039 | struct mwifiex_private *priv; |
| 2040 | unsigned long cmd_flags; |
| 2041 | int i; |
| 2042 | |
| 2043 | mwifiex_cancel_pending_scan_cmd(adapter); |
| 2044 | |
| 2045 | if (adapter->scan_processing) { |
| 2046 | spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags); |
| 2047 | adapter->scan_processing = false; |
| 2048 | spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags); |
| 2049 | for (i = 0; i < adapter->priv_num; i++) { |
| 2050 | priv = adapter->priv[i]; |
| 2051 | if (!priv) |
| 2052 | continue; |
| 2053 | if (priv->scan_request) { |
David S. Miller | 88b3ec5 | 2016-07-14 16:27:42 -0700 | [diff] [blame] | 2054 | struct cfg80211_scan_info info = { |
| 2055 | .aborted = true, |
| 2056 | }; |
| 2057 | |
Xinming Hu | a9c790b | 2016-06-16 18:52:22 +0530 | [diff] [blame] | 2058 | mwifiex_dbg(adapter, INFO, |
| 2059 | "info: aborting scan\n"); |
David S. Miller | 88b3ec5 | 2016-07-14 16:27:42 -0700 | [diff] [blame] | 2060 | cfg80211_scan_done(priv->scan_request, &info); |
Xinming Hu | a9c790b | 2016-06-16 18:52:22 +0530 | [diff] [blame] | 2061 | priv->scan_request = NULL; |
Amitkumar Karwar | 09e672a | 2016-06-27 14:16:28 +0530 | [diff] [blame] | 2062 | priv->scan_aborting = false; |
Xinming Hu | a9c790b | 2016-06-16 18:52:22 +0530 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | } |
| 2066 | } |
| 2067 | |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2068 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2069 | * This function handles the command response of scan. |
| 2070 | * |
| 2071 | * The response buffer for the scan command has the following |
| 2072 | * memory layout: |
| 2073 | * |
| 2074 | * .-------------------------------------------------------------. |
| 2075 | * | Header (4 * sizeof(t_u16)): Standard command response hdr | |
| 2076 | * .-------------------------------------------------------------. |
| 2077 | * | BufSize (t_u16) : sizeof the BSS Description data | |
| 2078 | * .-------------------------------------------------------------. |
| 2079 | * | NumOfSet (t_u8) : Number of BSS Descs returned | |
| 2080 | * .-------------------------------------------------------------. |
| 2081 | * | BSSDescription data (variable, size given in BufSize) | |
| 2082 | * .-------------------------------------------------------------. |
| 2083 | * | TLV data (variable, size calculated using Header->Size, | |
| 2084 | * | BufSize and sizeof the fixed fields above) | |
| 2085 | * .-------------------------------------------------------------. |
| 2086 | */ |
| 2087 | int mwifiex_ret_802_11_scan(struct mwifiex_private *priv, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2088 | struct host_cmd_ds_command *resp) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2089 | { |
| 2090 | int ret = 0; |
| 2091 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 2092 | struct host_cmd_ds_802_11_scan_rsp *scan_rsp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2093 | struct mwifiex_ie_types_data *tlv_data; |
| 2094 | struct mwifiex_ie_types_tsf_timestamp *tsf_tlv; |
| 2095 | u8 *bss_info; |
| 2096 | u32 scan_resp_size; |
| 2097 | u32 bytes_left; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2098 | u32 idx; |
| 2099 | u32 tlv_buf_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2100 | struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv; |
| 2101 | struct chan_band_param_set *chan_band; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2102 | u8 is_bgscan_resp; |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 2103 | __le64 fw_tsf = 0; |
| 2104 | u8 *radio_type; |
chunfan chen | 7d7f07d | 2016-01-13 01:26:54 -0800 | [diff] [blame] | 2105 | struct cfg80211_wowlan_nd_match *pmatch; |
| 2106 | struct cfg80211_sched_scan_request *nd_config = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2107 | |
| 2108 | is_bgscan_resp = (le16_to_cpu(resp->command) |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 2109 | == HostCmd_CMD_802_11_BG_SCAN_QUERY); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2110 | if (is_bgscan_resp) |
| 2111 | scan_rsp = &resp->params.bg_scan_query_resp.scan_resp; |
| 2112 | else |
| 2113 | scan_rsp = &resp->params.scan_resp; |
| 2114 | |
| 2115 | |
Bing Zhao | 67a5003 | 2011-07-13 18:38:34 -0700 | [diff] [blame] | 2116 | if (scan_rsp->number_of_sets > MWIFIEX_MAX_AP) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2117 | mwifiex_dbg(adapter, ERROR, |
| 2118 | "SCAN_RESP: too many AP returned (%d)\n", |
| 2119 | scan_rsp->number_of_sets); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2120 | ret = -1; |
Bing Zhao | 8a7d7cb | 2013-01-29 14:38:02 -0800 | [diff] [blame] | 2121 | goto check_next_scan; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
Amitkumar Karwar | b887664 | 2013-06-18 16:36:58 -0700 | [diff] [blame] | 2124 | /* Check csa channel expiry before parsing scan response */ |
| 2125 | mwifiex_11h_get_csa_closed_channel(priv); |
| 2126 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2127 | bytes_left = le16_to_cpu(scan_rsp->bss_descript_size); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2128 | mwifiex_dbg(adapter, INFO, |
| 2129 | "info: SCAN_RESP: bss_descript_size %d\n", |
| 2130 | bytes_left); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2131 | |
| 2132 | scan_resp_size = le16_to_cpu(resp->size); |
| 2133 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2134 | mwifiex_dbg(adapter, INFO, |
| 2135 | "info: SCAN_RESP: returned %d APs before parsing\n", |
| 2136 | scan_rsp->number_of_sets); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2137 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2138 | bss_info = scan_rsp->bss_desc_and_tlv_buffer; |
| 2139 | |
| 2140 | /* |
| 2141 | * The size of the TLV buffer is equal to the entire command response |
| 2142 | * size (scan_resp_size) minus the fixed fields (sizeof()'s), the |
| 2143 | * BSS Descriptions (bss_descript_size as bytesLef) and the command |
| 2144 | * response header (S_DS_GEN) |
| 2145 | */ |
| 2146 | tlv_buf_size = scan_resp_size - (bytes_left |
| 2147 | + sizeof(scan_rsp->bss_descript_size) |
| 2148 | + sizeof(scan_rsp->number_of_sets) |
| 2149 | + S_DS_GEN); |
| 2150 | |
| 2151 | tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp-> |
| 2152 | bss_desc_and_tlv_buffer + |
| 2153 | bytes_left); |
| 2154 | |
| 2155 | /* Search the TLV buffer space in the scan response for any valid |
| 2156 | TLVs */ |
| 2157 | mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size, |
| 2158 | TLV_TYPE_TSFTIMESTAMP, |
| 2159 | (struct mwifiex_ie_types_data **) |
| 2160 | &tsf_tlv); |
| 2161 | |
| 2162 | /* Search the TLV buffer space in the scan response for any valid |
| 2163 | TLVs */ |
| 2164 | mwifiex_ret_802_11_scan_get_tlv_ptrs(adapter, tlv_data, tlv_buf_size, |
| 2165 | TLV_TYPE_CHANNELBANDLIST, |
| 2166 | (struct mwifiex_ie_types_data **) |
| 2167 | &chan_band_tlv); |
| 2168 | |
chunfan chen | 7d7f07d | 2016-01-13 01:26:54 -0800 | [diff] [blame] | 2169 | #ifdef CONFIG_PM |
| 2170 | if (priv->wdev.wiphy->wowlan_config) |
| 2171 | nd_config = priv->wdev.wiphy->wowlan_config->nd_config; |
| 2172 | #endif |
| 2173 | |
| 2174 | if (nd_config) { |
| 2175 | adapter->nd_info = |
| 2176 | kzalloc(sizeof(struct cfg80211_wowlan_nd_match) + |
| 2177 | sizeof(struct cfg80211_wowlan_nd_match *) * |
| 2178 | scan_rsp->number_of_sets, GFP_ATOMIC); |
| 2179 | |
| 2180 | if (adapter->nd_info) |
| 2181 | adapter->nd_info->n_matches = scan_rsp->number_of_sets; |
| 2182 | } |
| 2183 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2184 | for (idx = 0; idx < scan_rsp->number_of_sets && bytes_left; idx++) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2185 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2186 | * If the TSF TLV was appended to the scan results, save this |
Amitkumar Karwar | b5abcf0 | 2012-04-16 21:36:52 -0700 | [diff] [blame] | 2187 | * entry's TSF value in the fw_tsf field. It is the firmware's |
| 2188 | * TSF value at the time the beacon or probe response was |
| 2189 | * received. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2190 | */ |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2191 | if (tsf_tlv) |
Amitkumar Karwar | b5abcf0 | 2012-04-16 21:36:52 -0700 | [diff] [blame] | 2192 | memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE], |
| 2193 | sizeof(fw_tsf)); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2194 | |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 2195 | if (chan_band_tlv) { |
| 2196 | chan_band = &chan_band_tlv->chan_band_param[idx]; |
| 2197 | radio_type = &chan_band->radio_type; |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2198 | } else { |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 2199 | radio_type = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2200 | } |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 2201 | |
chunfan chen | 7d7f07d | 2016-01-13 01:26:54 -0800 | [diff] [blame] | 2202 | if (chan_band_tlv && adapter->nd_info) { |
| 2203 | adapter->nd_info->matches[idx] = |
Christophe Jaillet | b711657 | 2016-08-31 13:50:59 +0200 | [diff] [blame] | 2204 | kzalloc(sizeof(*pmatch) + sizeof(u32), |
| 2205 | GFP_ATOMIC); |
chunfan chen | 7d7f07d | 2016-01-13 01:26:54 -0800 | [diff] [blame] | 2206 | |
| 2207 | pmatch = adapter->nd_info->matches[idx]; |
| 2208 | |
Dan Carpenter | efdf0e3 | 2016-02-02 13:00:05 +0300 | [diff] [blame] | 2209 | if (pmatch) { |
Christophe Jaillet | b711657 | 2016-08-31 13:50:59 +0200 | [diff] [blame] | 2210 | pmatch->n_channels = 1; |
| 2211 | pmatch->channels[0] = chan_band->chan_number; |
chunfan chen | 7d7f07d | 2016-01-13 01:26:54 -0800 | [diff] [blame] | 2212 | } |
| 2213 | } |
| 2214 | |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 2215 | ret = mwifiex_parse_single_response_buf(priv, &bss_info, |
| 2216 | &bytes_left, |
| 2217 | le64_to_cpu(fw_tsf), |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2218 | radio_type, false, 0); |
Amitkumar Karwar | 3b4d5c6 | 2014-02-07 16:23:35 -0800 | [diff] [blame] | 2219 | if (ret) |
| 2220 | goto check_next_scan; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
Bing Zhao | 8a7d7cb | 2013-01-29 14:38:02 -0800 | [diff] [blame] | 2223 | check_next_scan: |
Amitkumar Karwar | d44b5c2 | 2014-02-07 16:23:36 -0800 | [diff] [blame] | 2224 | mwifiex_check_next_scan_command(priv); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2225 | return ret; |
| 2226 | } |
| 2227 | |
| 2228 | /* |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2229 | * This function prepares an extended scan command to be sent to the firmware |
| 2230 | * |
| 2231 | * This uses the scan command configuration sent to the command processing |
| 2232 | * module in command preparation stage to configure a extended scan command |
| 2233 | * structure to send to firmware. |
| 2234 | */ |
| 2235 | int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv, |
| 2236 | struct host_cmd_ds_command *cmd, |
| 2237 | void *data_buf) |
| 2238 | { |
| 2239 | struct host_cmd_ds_802_11_scan_ext *ext_scan = &cmd->params.ext_scan; |
| 2240 | struct mwifiex_scan_cmd_config *scan_cfg = data_buf; |
| 2241 | |
| 2242 | memcpy(ext_scan->tlv_buffer, scan_cfg->tlv_buf, scan_cfg->tlv_buf_len); |
| 2243 | |
| 2244 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SCAN_EXT); |
| 2245 | |
| 2246 | /* Size is equal to the sizeof(fixed portions) + the TLV len + header */ |
| 2247 | cmd->size = cpu_to_le16((u16)(sizeof(ext_scan->reserved) |
| 2248 | + scan_cfg->tlv_buf_len + S_DS_GEN)); |
| 2249 | |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 2253 | /* This function prepares an background scan config command to be sent |
| 2254 | * to the firmware |
| 2255 | */ |
| 2256 | int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv, |
| 2257 | struct host_cmd_ds_command *cmd, |
| 2258 | void *data_buf) |
| 2259 | { |
| 2260 | struct host_cmd_ds_802_11_bg_scan_config *bgscan_config = |
| 2261 | &cmd->params.bg_scan_config; |
| 2262 | struct mwifiex_bg_scan_cfg *bgscan_cfg_in = data_buf; |
| 2263 | u8 *tlv_pos = bgscan_config->tlv; |
| 2264 | u8 num_probes; |
| 2265 | u32 ssid_len, chan_idx, scan_type, scan_dur, chan_num; |
| 2266 | int i; |
| 2267 | struct mwifiex_ie_types_num_probes *num_probes_tlv; |
| 2268 | struct mwifiex_ie_types_repeat_count *repeat_count_tlv; |
Ganapathi Bhat | fdcab08 | 2016-01-13 01:26:56 -0800 | [diff] [blame] | 2269 | struct mwifiex_ie_types_min_rssi_threshold *rssi_threshold_tlv; |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 2270 | struct mwifiex_ie_types_bgscan_start_later *start_later_tlv; |
| 2271 | struct mwifiex_ie_types_wildcard_ssid_params *wildcard_ssid_tlv; |
| 2272 | struct mwifiex_ie_types_chan_list_param_set *chan_list_tlv; |
| 2273 | struct mwifiex_chan_scan_param_set *temp_chan; |
| 2274 | |
| 2275 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_CONFIG); |
| 2276 | cmd->size = cpu_to_le16(sizeof(*bgscan_config) + S_DS_GEN); |
| 2277 | |
| 2278 | bgscan_config->action = cpu_to_le16(bgscan_cfg_in->action); |
| 2279 | bgscan_config->enable = bgscan_cfg_in->enable; |
| 2280 | bgscan_config->bss_type = bgscan_cfg_in->bss_type; |
| 2281 | bgscan_config->scan_interval = |
| 2282 | cpu_to_le32(bgscan_cfg_in->scan_interval); |
| 2283 | bgscan_config->report_condition = |
| 2284 | cpu_to_le32(bgscan_cfg_in->report_condition); |
| 2285 | |
| 2286 | /* stop sched scan */ |
| 2287 | if (!bgscan_config->enable) |
| 2288 | return 0; |
| 2289 | |
| 2290 | bgscan_config->chan_per_scan = bgscan_cfg_in->chan_per_scan; |
| 2291 | |
| 2292 | num_probes = (bgscan_cfg_in->num_probes ? bgscan_cfg_in-> |
| 2293 | num_probes : priv->adapter->scan_probes); |
| 2294 | |
| 2295 | if (num_probes) { |
| 2296 | num_probes_tlv = (struct mwifiex_ie_types_num_probes *)tlv_pos; |
| 2297 | num_probes_tlv->header.type = cpu_to_le16(TLV_TYPE_NUMPROBES); |
| 2298 | num_probes_tlv->header.len = |
| 2299 | cpu_to_le16(sizeof(num_probes_tlv->num_probes)); |
| 2300 | num_probes_tlv->num_probes = cpu_to_le16((u16)num_probes); |
| 2301 | |
| 2302 | tlv_pos += sizeof(num_probes_tlv->header) + |
| 2303 | le16_to_cpu(num_probes_tlv->header.len); |
| 2304 | } |
| 2305 | |
| 2306 | if (bgscan_cfg_in->repeat_count) { |
| 2307 | repeat_count_tlv = |
| 2308 | (struct mwifiex_ie_types_repeat_count *)tlv_pos; |
| 2309 | repeat_count_tlv->header.type = |
| 2310 | cpu_to_le16(TLV_TYPE_REPEAT_COUNT); |
| 2311 | repeat_count_tlv->header.len = |
| 2312 | cpu_to_le16(sizeof(repeat_count_tlv->repeat_count)); |
| 2313 | repeat_count_tlv->repeat_count = |
| 2314 | cpu_to_le16(bgscan_cfg_in->repeat_count); |
| 2315 | |
| 2316 | tlv_pos += sizeof(repeat_count_tlv->header) + |
| 2317 | le16_to_cpu(repeat_count_tlv->header.len); |
| 2318 | } |
| 2319 | |
Ganapathi Bhat | fdcab08 | 2016-01-13 01:26:56 -0800 | [diff] [blame] | 2320 | if (bgscan_cfg_in->rssi_threshold) { |
| 2321 | rssi_threshold_tlv = |
| 2322 | (struct mwifiex_ie_types_min_rssi_threshold *)tlv_pos; |
| 2323 | rssi_threshold_tlv->header.type = |
| 2324 | cpu_to_le16(TLV_TYPE_RSSI_LOW); |
| 2325 | rssi_threshold_tlv->header.len = |
| 2326 | cpu_to_le16(sizeof(rssi_threshold_tlv->rssi_threshold)); |
| 2327 | rssi_threshold_tlv->rssi_threshold = |
| 2328 | cpu_to_le16(bgscan_cfg_in->rssi_threshold); |
| 2329 | |
| 2330 | tlv_pos += sizeof(rssi_threshold_tlv->header) + |
| 2331 | le16_to_cpu(rssi_threshold_tlv->header.len); |
| 2332 | } |
| 2333 | |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 2334 | for (i = 0; i < bgscan_cfg_in->num_ssids; i++) { |
| 2335 | ssid_len = bgscan_cfg_in->ssid_list[i].ssid.ssid_len; |
| 2336 | |
| 2337 | wildcard_ssid_tlv = |
| 2338 | (struct mwifiex_ie_types_wildcard_ssid_params *)tlv_pos; |
| 2339 | wildcard_ssid_tlv->header.type = |
| 2340 | cpu_to_le16(TLV_TYPE_WILDCARDSSID); |
| 2341 | wildcard_ssid_tlv->header.len = cpu_to_le16( |
| 2342 | (u16)(ssid_len + sizeof(wildcard_ssid_tlv-> |
| 2343 | max_ssid_length))); |
| 2344 | |
| 2345 | /* max_ssid_length = 0 tells firmware to perform |
| 2346 | * specific scan for the SSID filled, whereas |
| 2347 | * max_ssid_length = IEEE80211_MAX_SSID_LEN is for |
| 2348 | * wildcard scan. |
| 2349 | */ |
| 2350 | if (ssid_len) |
| 2351 | wildcard_ssid_tlv->max_ssid_length = 0; |
| 2352 | else |
| 2353 | wildcard_ssid_tlv->max_ssid_length = |
| 2354 | IEEE80211_MAX_SSID_LEN; |
| 2355 | |
| 2356 | memcpy(wildcard_ssid_tlv->ssid, |
| 2357 | bgscan_cfg_in->ssid_list[i].ssid.ssid, ssid_len); |
| 2358 | |
| 2359 | tlv_pos += (sizeof(wildcard_ssid_tlv->header) |
| 2360 | + le16_to_cpu(wildcard_ssid_tlv->header.len)); |
| 2361 | } |
| 2362 | |
| 2363 | chan_list_tlv = (struct mwifiex_ie_types_chan_list_param_set *)tlv_pos; |
| 2364 | |
| 2365 | if (bgscan_cfg_in->chan_list[0].chan_number) { |
| 2366 | dev_dbg(priv->adapter->dev, "info: bgscan: Using supplied channel list\n"); |
| 2367 | |
| 2368 | chan_list_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 2369 | |
| 2370 | for (chan_idx = 0; |
| 2371 | chan_idx < MWIFIEX_BG_SCAN_CHAN_MAX && |
| 2372 | bgscan_cfg_in->chan_list[chan_idx].chan_number; |
| 2373 | chan_idx++) { |
| 2374 | temp_chan = chan_list_tlv->chan_scan_param + chan_idx; |
| 2375 | |
| 2376 | /* Increment the TLV header length by size appended */ |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 2377 | le16_unaligned_add_cpu(&chan_list_tlv->header.len, |
| 2378 | sizeof( |
| 2379 | chan_list_tlv->chan_scan_param)); |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 2380 | |
| 2381 | temp_chan->chan_number = |
| 2382 | bgscan_cfg_in->chan_list[chan_idx].chan_number; |
| 2383 | temp_chan->radio_type = |
| 2384 | bgscan_cfg_in->chan_list[chan_idx].radio_type; |
| 2385 | |
| 2386 | scan_type = |
| 2387 | bgscan_cfg_in->chan_list[chan_idx].scan_type; |
| 2388 | |
| 2389 | if (scan_type == MWIFIEX_SCAN_TYPE_PASSIVE) |
| 2390 | temp_chan->chan_scan_mode_bitmap |
| 2391 | |= MWIFIEX_PASSIVE_SCAN; |
| 2392 | else |
| 2393 | temp_chan->chan_scan_mode_bitmap |
| 2394 | &= ~MWIFIEX_PASSIVE_SCAN; |
| 2395 | |
| 2396 | if (bgscan_cfg_in->chan_list[chan_idx].scan_time) { |
| 2397 | scan_dur = (u16)bgscan_cfg_in-> |
| 2398 | chan_list[chan_idx].scan_time; |
| 2399 | } else { |
| 2400 | scan_dur = (scan_type == |
| 2401 | MWIFIEX_SCAN_TYPE_PASSIVE) ? |
| 2402 | priv->adapter->passive_scan_time : |
| 2403 | priv->adapter->specific_scan_time; |
| 2404 | } |
| 2405 | |
| 2406 | temp_chan->min_scan_time = cpu_to_le16(scan_dur); |
| 2407 | temp_chan->max_scan_time = cpu_to_le16(scan_dur); |
| 2408 | } |
| 2409 | } else { |
| 2410 | dev_dbg(priv->adapter->dev, |
| 2411 | "info: bgscan: Creating full region channel list\n"); |
| 2412 | chan_num = |
| 2413 | mwifiex_bgscan_create_channel_list(priv, bgscan_cfg_in, |
| 2414 | chan_list_tlv-> |
| 2415 | chan_scan_param); |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 2416 | le16_unaligned_add_cpu(&chan_list_tlv->header.len, |
| 2417 | chan_num * |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 2418 | sizeof(chan_list_tlv->chan_scan_param[0])); |
| 2419 | } |
| 2420 | |
| 2421 | tlv_pos += (sizeof(chan_list_tlv->header) |
| 2422 | + le16_to_cpu(chan_list_tlv->header.len)); |
| 2423 | |
| 2424 | if (bgscan_cfg_in->start_later) { |
| 2425 | start_later_tlv = |
| 2426 | (struct mwifiex_ie_types_bgscan_start_later *)tlv_pos; |
| 2427 | start_later_tlv->header.type = |
| 2428 | cpu_to_le16(TLV_TYPE_BGSCAN_START_LATER); |
| 2429 | start_later_tlv->header.len = |
| 2430 | cpu_to_le16(sizeof(start_later_tlv->start_later)); |
| 2431 | start_later_tlv->start_later = |
| 2432 | cpu_to_le16(bgscan_cfg_in->start_later); |
| 2433 | |
| 2434 | tlv_pos += sizeof(start_later_tlv->header) + |
| 2435 | le16_to_cpu(start_later_tlv->header.len); |
| 2436 | } |
| 2437 | |
| 2438 | /* Append vendor specific IE TLV */ |
| 2439 | mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_BGSCAN, &tlv_pos); |
| 2440 | |
Daniel Mentz | 5653c64 | 2017-03-09 14:06:16 +0530 | [diff] [blame^] | 2441 | le16_unaligned_add_cpu(&cmd->size, tlv_pos - bgscan_config->tlv); |
Xinming Hu | 0c9b7f2 | 2016-01-13 01:26:52 -0800 | [diff] [blame] | 2442 | |
| 2443 | return 0; |
| 2444 | } |
| 2445 | |
| 2446 | int mwifiex_stop_bg_scan(struct mwifiex_private *priv) |
| 2447 | { |
| 2448 | struct mwifiex_bg_scan_cfg *bgscan_cfg; |
| 2449 | |
| 2450 | if (!priv->sched_scanning) { |
| 2451 | dev_dbg(priv->adapter->dev, "bgscan already stopped!\n"); |
| 2452 | return 0; |
| 2453 | } |
| 2454 | |
| 2455 | bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL); |
| 2456 | if (!bgscan_cfg) |
| 2457 | return -ENOMEM; |
| 2458 | |
| 2459 | bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA; |
| 2460 | bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET; |
| 2461 | bgscan_cfg->enable = false; |
| 2462 | |
| 2463 | if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG, |
| 2464 | HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) { |
| 2465 | kfree(bgscan_cfg); |
| 2466 | return -EFAULT; |
| 2467 | } |
| 2468 | |
| 2469 | kfree(bgscan_cfg); |
| 2470 | priv->sched_scanning = false; |
| 2471 | |
| 2472 | return 0; |
| 2473 | } |
| 2474 | |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 2475 | static void |
| 2476 | mwifiex_update_chan_statistics(struct mwifiex_private *priv, |
| 2477 | struct mwifiex_ietypes_chanstats *tlv_stat) |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2478 | { |
Avinash Patil | 3223db2 | 2014-09-12 20:08:48 +0530 | [diff] [blame] | 2479 | struct mwifiex_adapter *adapter = priv->adapter; |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 2480 | u8 i, num_chan; |
| 2481 | struct mwifiex_fw_chan_stats *fw_chan_stats; |
| 2482 | struct mwifiex_chan_stats chan_stats; |
| 2483 | |
| 2484 | fw_chan_stats = (void *)((u8 *)tlv_stat + |
| 2485 | sizeof(struct mwifiex_ie_types_header)); |
| 2486 | num_chan = le16_to_cpu(tlv_stat->header.len) / |
| 2487 | sizeof(struct mwifiex_chan_stats); |
| 2488 | |
| 2489 | for (i = 0 ; i < num_chan; i++) { |
| 2490 | chan_stats.chan_num = fw_chan_stats->chan_num; |
| 2491 | chan_stats.bandcfg = fw_chan_stats->bandcfg; |
| 2492 | chan_stats.flags = fw_chan_stats->flags; |
| 2493 | chan_stats.noise = fw_chan_stats->noise; |
| 2494 | chan_stats.total_bss = le16_to_cpu(fw_chan_stats->total_bss); |
| 2495 | chan_stats.cca_scan_dur = |
| 2496 | le16_to_cpu(fw_chan_stats->cca_scan_dur); |
| 2497 | chan_stats.cca_busy_dur = |
| 2498 | le16_to_cpu(fw_chan_stats->cca_busy_dur); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2499 | mwifiex_dbg(adapter, INFO, |
| 2500 | "chan=%d, noise=%d, total_network=%d scan_duration=%d, busy_duration=%d\n", |
| 2501 | chan_stats.chan_num, |
| 2502 | chan_stats.noise, |
| 2503 | chan_stats.total_bss, |
| 2504 | chan_stats.cca_scan_dur, |
| 2505 | chan_stats.cca_busy_dur); |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 2506 | memcpy(&adapter->chan_stats[adapter->survey_idx++], &chan_stats, |
| 2507 | sizeof(struct mwifiex_chan_stats)); |
| 2508 | fw_chan_stats++; |
| 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | /* This function handles the command response of extended scan */ |
| 2513 | int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv, |
| 2514 | struct host_cmd_ds_command *resp) |
| 2515 | { |
| 2516 | struct mwifiex_adapter *adapter = priv->adapter; |
| 2517 | struct host_cmd_ds_802_11_scan_ext *ext_scan_resp; |
| 2518 | struct mwifiex_ie_types_header *tlv; |
| 2519 | struct mwifiex_ietypes_chanstats *tlv_stat; |
| 2520 | u16 buf_left, type, len; |
| 2521 | |
Avinash Patil | 3223db2 | 2014-09-12 20:08:48 +0530 | [diff] [blame] | 2522 | struct host_cmd_ds_command *cmd_ptr; |
| 2523 | struct cmd_ctrl_node *cmd_node; |
| 2524 | unsigned long cmd_flags, scan_flags; |
| 2525 | bool complete_scan = false; |
| 2526 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2527 | mwifiex_dbg(adapter, INFO, "info: EXT scan returns successfully\n"); |
Avinash Patil | 2144504 | 2014-05-27 21:39:32 -0700 | [diff] [blame] | 2528 | |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 2529 | ext_scan_resp = &resp->params.ext_scan; |
| 2530 | |
| 2531 | tlv = (void *)ext_scan_resp->tlv_buffer; |
| 2532 | buf_left = le16_to_cpu(resp->size) - (sizeof(*ext_scan_resp) + S_DS_GEN |
| 2533 | - 1); |
| 2534 | |
| 2535 | while (buf_left >= sizeof(struct mwifiex_ie_types_header)) { |
| 2536 | type = le16_to_cpu(tlv->type); |
| 2537 | len = le16_to_cpu(tlv->len); |
| 2538 | |
| 2539 | if (buf_left < (sizeof(struct mwifiex_ie_types_header) + len)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2540 | mwifiex_dbg(adapter, ERROR, |
| 2541 | "error processing scan response TLVs"); |
Avinash Patil | bf35443 | 2014-10-31 16:08:26 +0530 | [diff] [blame] | 2542 | break; |
| 2543 | } |
| 2544 | |
| 2545 | switch (type) { |
| 2546 | case TLV_TYPE_CHANNEL_STATS: |
| 2547 | tlv_stat = (void *)tlv; |
| 2548 | mwifiex_update_chan_statistics(priv, tlv_stat); |
| 2549 | break; |
| 2550 | default: |
| 2551 | break; |
| 2552 | } |
| 2553 | |
| 2554 | buf_left -= len + sizeof(struct mwifiex_ie_types_header); |
| 2555 | tlv = (void *)((u8 *)tlv + len + |
| 2556 | sizeof(struct mwifiex_ie_types_header)); |
| 2557 | } |
| 2558 | |
Avinash Patil | 3223db2 | 2014-09-12 20:08:48 +0530 | [diff] [blame] | 2559 | spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_flags); |
| 2560 | spin_lock_irqsave(&adapter->scan_pending_q_lock, scan_flags); |
| 2561 | if (list_empty(&adapter->scan_pending_q)) { |
| 2562 | complete_scan = true; |
| 2563 | list_for_each_entry(cmd_node, &adapter->cmd_pending_q, list) { |
| 2564 | cmd_ptr = (void *)cmd_node->cmd_skb->data; |
| 2565 | if (le16_to_cpu(cmd_ptr->command) == |
| 2566 | HostCmd_CMD_802_11_SCAN_EXT) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2567 | mwifiex_dbg(adapter, INFO, |
| 2568 | "Scan pending in command pending list"); |
Avinash Patil | 3223db2 | 2014-09-12 20:08:48 +0530 | [diff] [blame] | 2569 | complete_scan = false; |
| 2570 | break; |
| 2571 | } |
| 2572 | } |
| 2573 | } |
| 2574 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, scan_flags); |
| 2575 | spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, cmd_flags); |
| 2576 | |
| 2577 | if (complete_scan) |
| 2578 | mwifiex_complete_scan(priv); |
Avinash Patil | 2144504 | 2014-05-27 21:39:32 -0700 | [diff] [blame] | 2579 | |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2580 | return 0; |
| 2581 | } |
| 2582 | |
| 2583 | /* This function This function handles the event extended scan report. It |
| 2584 | * parses extended scan results and informs to cfg80211 stack. |
| 2585 | */ |
| 2586 | int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv, |
| 2587 | void *buf) |
| 2588 | { |
| 2589 | int ret = 0; |
| 2590 | struct mwifiex_adapter *adapter = priv->adapter; |
| 2591 | u8 *bss_info; |
| 2592 | u32 bytes_left, bytes_left_for_tlv, idx; |
| 2593 | u16 type, len; |
| 2594 | struct mwifiex_ie_types_data *tlv; |
| 2595 | struct mwifiex_ie_types_bss_scan_rsp *scan_rsp_tlv; |
| 2596 | struct mwifiex_ie_types_bss_scan_info *scan_info_tlv; |
| 2597 | u8 *radio_type; |
| 2598 | u64 fw_tsf = 0; |
| 2599 | s32 rssi = 0; |
| 2600 | struct mwifiex_event_scan_result *event_scan = buf; |
| 2601 | u8 num_of_set = event_scan->num_of_set; |
| 2602 | u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result); |
| 2603 | u16 scan_resp_size = le16_to_cpu(event_scan->buf_size); |
| 2604 | |
| 2605 | if (num_of_set > MWIFIEX_MAX_AP) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2606 | mwifiex_dbg(adapter, ERROR, |
| 2607 | "EXT_SCAN: Invalid number of AP returned (%d)!!\n", |
| 2608 | num_of_set); |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2609 | ret = -1; |
| 2610 | goto check_next_scan; |
| 2611 | } |
| 2612 | |
| 2613 | bytes_left = scan_resp_size; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2614 | mwifiex_dbg(adapter, INFO, |
| 2615 | "EXT_SCAN: size %d, returned %d APs...", |
| 2616 | scan_resp_size, num_of_set); |
Zhaoyang Liu | 868093a | 2015-05-12 00:48:19 +0530 | [diff] [blame] | 2617 | mwifiex_dbg_dump(adapter, CMD_D, "EXT_SCAN buffer:", buf, |
| 2618 | scan_resp_size + |
| 2619 | sizeof(struct mwifiex_event_scan_result)); |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2620 | |
| 2621 | tlv = (struct mwifiex_ie_types_data *)scan_resp; |
| 2622 | |
| 2623 | for (idx = 0; idx < num_of_set && bytes_left; idx++) { |
| 2624 | type = le16_to_cpu(tlv->header.type); |
| 2625 | len = le16_to_cpu(tlv->header.len); |
| 2626 | if (bytes_left < sizeof(struct mwifiex_ie_types_header) + len) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2627 | mwifiex_dbg(adapter, ERROR, |
| 2628 | "EXT_SCAN: Error bytes left < TLV length\n"); |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2629 | break; |
| 2630 | } |
| 2631 | scan_rsp_tlv = NULL; |
| 2632 | scan_info_tlv = NULL; |
| 2633 | bytes_left_for_tlv = bytes_left; |
| 2634 | |
| 2635 | /* BSS response TLV with beacon or probe response buffer |
| 2636 | * at the initial position of each descriptor |
| 2637 | */ |
| 2638 | if (type != TLV_TYPE_BSS_SCAN_RSP) |
| 2639 | break; |
| 2640 | |
| 2641 | bss_info = (u8 *)tlv; |
| 2642 | scan_rsp_tlv = (struct mwifiex_ie_types_bss_scan_rsp *)tlv; |
| 2643 | tlv = (struct mwifiex_ie_types_data *)(tlv->data + len); |
| 2644 | bytes_left_for_tlv -= |
| 2645 | (len + sizeof(struct mwifiex_ie_types_header)); |
| 2646 | |
| 2647 | while (bytes_left_for_tlv >= |
| 2648 | sizeof(struct mwifiex_ie_types_header) && |
| 2649 | le16_to_cpu(tlv->header.type) != TLV_TYPE_BSS_SCAN_RSP) { |
| 2650 | type = le16_to_cpu(tlv->header.type); |
| 2651 | len = le16_to_cpu(tlv->header.len); |
| 2652 | if (bytes_left_for_tlv < |
| 2653 | sizeof(struct mwifiex_ie_types_header) + len) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2654 | mwifiex_dbg(adapter, ERROR, |
| 2655 | "EXT_SCAN: Error in processing TLV,\t" |
| 2656 | "bytes left < TLV length\n"); |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2657 | scan_rsp_tlv = NULL; |
| 2658 | bytes_left_for_tlv = 0; |
| 2659 | continue; |
| 2660 | } |
| 2661 | switch (type) { |
| 2662 | case TLV_TYPE_BSS_SCAN_INFO: |
| 2663 | scan_info_tlv = |
| 2664 | (struct mwifiex_ie_types_bss_scan_info *)tlv; |
| 2665 | if (len != |
| 2666 | sizeof(struct mwifiex_ie_types_bss_scan_info) - |
| 2667 | sizeof(struct mwifiex_ie_types_header)) { |
| 2668 | bytes_left_for_tlv = 0; |
| 2669 | continue; |
| 2670 | } |
| 2671 | break; |
| 2672 | default: |
| 2673 | break; |
| 2674 | } |
| 2675 | tlv = (struct mwifiex_ie_types_data *)(tlv->data + len); |
| 2676 | bytes_left -= |
| 2677 | (len + sizeof(struct mwifiex_ie_types_header)); |
| 2678 | bytes_left_for_tlv -= |
| 2679 | (len + sizeof(struct mwifiex_ie_types_header)); |
| 2680 | } |
| 2681 | |
| 2682 | if (!scan_rsp_tlv) |
| 2683 | break; |
| 2684 | |
| 2685 | /* Advance pointer to the beacon buffer length and |
| 2686 | * update the bytes count so that the function |
| 2687 | * wlan_interpret_bss_desc_with_ie() can handle the |
| 2688 | * scan buffer withut any change |
| 2689 | */ |
| 2690 | bss_info += sizeof(u16); |
| 2691 | bytes_left -= sizeof(u16); |
| 2692 | |
| 2693 | if (scan_info_tlv) { |
| 2694 | rssi = (s32)(s16)(le16_to_cpu(scan_info_tlv->rssi)); |
| 2695 | rssi *= 100; /* Convert dBm to mBm */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2696 | mwifiex_dbg(adapter, INFO, |
| 2697 | "info: InterpretIE: RSSI=%d\n", rssi); |
Amitkumar Karwar | 21f58d20 | 2014-02-11 18:39:56 -0800 | [diff] [blame] | 2698 | fw_tsf = le64_to_cpu(scan_info_tlv->tsf); |
| 2699 | radio_type = &scan_info_tlv->radio_type; |
| 2700 | } else { |
| 2701 | radio_type = NULL; |
| 2702 | } |
| 2703 | ret = mwifiex_parse_single_response_buf(priv, &bss_info, |
| 2704 | &bytes_left, fw_tsf, |
| 2705 | radio_type, true, rssi); |
| 2706 | if (ret) |
| 2707 | goto check_next_scan; |
| 2708 | } |
| 2709 | |
| 2710 | check_next_scan: |
| 2711 | if (!event_scan->more_event) |
| 2712 | mwifiex_check_next_scan_command(priv); |
| 2713 | |
| 2714 | return ret; |
| 2715 | } |
| 2716 | |
| 2717 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2718 | * This function prepares command for background scan query. |
| 2719 | * |
| 2720 | * Preparation includes - |
| 2721 | * - Setting command ID and proper size |
| 2722 | * - Setting background scan flush parameter |
| 2723 | * - Ensuring correct endian-ness |
| 2724 | */ |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 2725 | int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2726 | { |
| 2727 | struct host_cmd_ds_802_11_bg_scan_query *bg_query = |
| 2728 | &cmd->params.bg_scan_query; |
| 2729 | |
| 2730 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_BG_SCAN_QUERY); |
| 2731 | cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_bg_scan_query) |
| 2732 | + S_DS_GEN); |
| 2733 | |
| 2734 | bg_query->flush = 1; |
| 2735 | |
| 2736 | return 0; |
| 2737 | } |
| 2738 | |
| 2739 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2740 | * This function inserts scan command node to the scan pending queue. |
| 2741 | */ |
| 2742 | void |
| 2743 | mwifiex_queue_scan_cmd(struct mwifiex_private *priv, |
| 2744 | struct cmd_ctrl_node *cmd_node) |
| 2745 | { |
| 2746 | struct mwifiex_adapter *adapter = priv->adapter; |
| 2747 | unsigned long flags; |
| 2748 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2749 | cmd_node->wait_q_enabled = true; |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 2750 | cmd_node->condition = &adapter->scan_wait_q_woken; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2751 | spin_lock_irqsave(&adapter->scan_pending_q_lock, flags); |
| 2752 | list_add_tail(&cmd_node->list, &adapter->scan_pending_q); |
| 2753 | spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); |
| 2754 | } |
| 2755 | |
| 2756 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2757 | * This function sends a scan command for all available channels to the |
| 2758 | * firmware, filtered on a specific SSID. |
| 2759 | */ |
| 2760 | static int mwifiex_scan_specific_ssid(struct mwifiex_private *priv, |
Amitkumar Karwar | b9be5f3 | 2012-02-27 22:04:14 -0800 | [diff] [blame] | 2761 | struct cfg80211_ssid *req_ssid) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2762 | { |
| 2763 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | dcd5c79 | 2012-10-19 19:01:59 -0700 | [diff] [blame] | 2764 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2765 | struct mwifiex_user_scan_cfg *scan_cfg; |
| 2766 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2767 | if (adapter->scan_processing) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2768 | mwifiex_dbg(adapter, WARN, |
| 2769 | "cmd: Scan already in process...\n"); |
Bing Zhao | dcd5c79 | 2012-10-19 19:01:59 -0700 | [diff] [blame] | 2770 | return -EBUSY; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2773 | if (priv->scan_block) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2774 | mwifiex_dbg(adapter, WARN, |
| 2775 | "cmd: Scan is blocked during association...\n"); |
Bing Zhao | dcd5c79 | 2012-10-19 19:01:59 -0700 | [diff] [blame] | 2776 | return -EBUSY; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2779 | scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg), GFP_KERNEL); |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 2780 | if (!scan_cfg) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 2781 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2782 | |
Ganapathi Bhat | c2a8f0f | 2016-07-25 21:21:07 +0530 | [diff] [blame] | 2783 | ether_addr_copy(scan_cfg->random_mac, priv->random_mac); |
Amitkumar Karwar | be0b281 | 2012-02-27 22:04:15 -0800 | [diff] [blame] | 2784 | scan_cfg->ssid_list = req_ssid; |
| 2785 | scan_cfg->num_ssids = 1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2786 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2787 | ret = mwifiex_scan_networks(priv, scan_cfg); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2788 | |
| 2789 | kfree(scan_cfg); |
| 2790 | return ret; |
| 2791 | } |
| 2792 | |
| 2793 | /* |
| 2794 | * Sends IOCTL request to start a scan. |
| 2795 | * |
| 2796 | * This function allocates the IOCTL request buffer, fills it |
| 2797 | * with requisite parameters and calls the IOCTL handler. |
| 2798 | * |
| 2799 | * Scan command can be issued for both normal scan and specific SSID |
| 2800 | * scan, depending upon whether an SSID is provided or not. |
| 2801 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2802 | int mwifiex_request_scan(struct mwifiex_private *priv, |
Amitkumar Karwar | b9be5f3 | 2012-02-27 22:04:14 -0800 | [diff] [blame] | 2803 | struct cfg80211_ssid *req_ssid) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2804 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 2805 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2806 | |
| 2807 | if (down_interruptible(&priv->async_sem)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2808 | mwifiex_dbg(priv->adapter, ERROR, |
| 2809 | "%s: acquire semaphore fail\n", |
| 2810 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2811 | return -1; |
| 2812 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2813 | |
Amitkumar Karwar | efaaa8b | 2011-10-12 20:28:06 -0700 | [diff] [blame] | 2814 | priv->adapter->scan_wait_q_woken = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2815 | |
| 2816 | if (req_ssid && req_ssid->ssid_len != 0) |
| 2817 | /* Specific SSID scan */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2818 | ret = mwifiex_scan_specific_ssid(priv, req_ssid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2819 | else |
| 2820 | /* Normal scan */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2821 | ret = mwifiex_scan_networks(priv, NULL); |
| 2822 | |
Amitkumar Karwar | b0e70c2 | 2012-10-19 19:19:17 -0700 | [diff] [blame] | 2823 | up(&priv->async_sem); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 2824 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2825 | return ret; |
| 2826 | } |
| 2827 | |
| 2828 | /* |
| 2829 | * This function appends the vendor specific IE TLV to a buffer. |
| 2830 | */ |
| 2831 | int |
| 2832 | mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv, |
| 2833 | u16 vsie_mask, u8 **buffer) |
| 2834 | { |
| 2835 | int id, ret_len = 0; |
| 2836 | struct mwifiex_ie_types_vendor_param_set *vs_param_set; |
| 2837 | |
| 2838 | if (!buffer) |
| 2839 | return 0; |
| 2840 | if (!(*buffer)) |
| 2841 | return 0; |
| 2842 | |
| 2843 | /* |
| 2844 | * Traverse through the saved vendor specific IE array and append |
| 2845 | * the selected(scan/assoc/adhoc) IE as TLV to the command |
| 2846 | */ |
| 2847 | for (id = 0; id < MWIFIEX_MAX_VSIE_NUM; id++) { |
| 2848 | if (priv->vs_ie[id].mask & vsie_mask) { |
| 2849 | vs_param_set = |
| 2850 | (struct mwifiex_ie_types_vendor_param_set *) |
| 2851 | *buffer; |
| 2852 | vs_param_set->header.type = |
| 2853 | cpu_to_le16(TLV_TYPE_PASSTHROUGH); |
| 2854 | vs_param_set->header.len = |
| 2855 | cpu_to_le16((((u16) priv->vs_ie[id].ie[1]) |
| 2856 | & 0x00FF) + 2); |
| 2857 | memcpy(vs_param_set->ie, priv->vs_ie[id].ie, |
| 2858 | le16_to_cpu(vs_param_set->header.len)); |
| 2859 | *buffer += le16_to_cpu(vs_param_set->header.len) + |
| 2860 | sizeof(struct mwifiex_ie_types_header); |
| 2861 | ret_len += le16_to_cpu(vs_param_set->header.len) + |
| 2862 | sizeof(struct mwifiex_ie_types_header); |
| 2863 | } |
| 2864 | } |
| 2865 | return ret_len; |
| 2866 | } |
| 2867 | |
| 2868 | /* |
| 2869 | * This function saves a beacon buffer of the current BSS descriptor. |
| 2870 | * |
| 2871 | * The current beacon buffer is saved so that it can be restored in the |
| 2872 | * following cases that makes the beacon buffer not to contain the current |
| 2873 | * ssid's beacon buffer. |
| 2874 | * - The current ssid was not found somehow in the last scan. |
| 2875 | * - The current ssid was the last entry of the scan table and overloaded. |
| 2876 | */ |
| 2877 | void |
| 2878 | mwifiex_save_curr_bcn(struct mwifiex_private *priv) |
| 2879 | { |
| 2880 | struct mwifiex_bssdescriptor *curr_bss = |
| 2881 | &priv->curr_bss_params.bss_descriptor; |
| 2882 | |
Amitkumar Karwar | 030fe79 | 2011-04-27 19:13:13 -0700 | [diff] [blame] | 2883 | if (!curr_bss->beacon_buf_size) |
| 2884 | return; |
| 2885 | |
| 2886 | /* allocate beacon buffer at 1st time; or if it's size has changed */ |
| 2887 | if (!priv->curr_bcn_buf || |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 2888 | priv->curr_bcn_size != curr_bss->beacon_buf_size) { |
Amitkumar Karwar | 030fe79 | 2011-04-27 19:13:13 -0700 | [diff] [blame] | 2889 | priv->curr_bcn_size = curr_bss->beacon_buf_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2890 | |
| 2891 | kfree(priv->curr_bcn_buf); |
Yogesh Ashok Powar | 5982b47 | 2011-08-29 13:21:10 -0700 | [diff] [blame] | 2892 | priv->curr_bcn_buf = kmalloc(curr_bss->beacon_buf_size, |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 2893 | GFP_ATOMIC); |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 2894 | if (!priv->curr_bcn_buf) |
Amitkumar Karwar | 030fe79 | 2011-04-27 19:13:13 -0700 | [diff] [blame] | 2895 | return; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2896 | } |
Amitkumar Karwar | 030fe79 | 2011-04-27 19:13:13 -0700 | [diff] [blame] | 2897 | |
| 2898 | memcpy(priv->curr_bcn_buf, curr_bss->beacon_buf, |
Yogesh Ashok Powar | cff23ce | 2012-03-13 19:22:38 -0700 | [diff] [blame] | 2899 | curr_bss->beacon_buf_size); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2900 | mwifiex_dbg(priv->adapter, INFO, |
| 2901 | "info: current beacon saved %d\n", |
| 2902 | priv->curr_bcn_size); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2903 | |
| 2904 | curr_bss->beacon_buf = priv->curr_bcn_buf; |
| 2905 | |
| 2906 | /* adjust the pointers in the current BSS descriptor */ |
| 2907 | if (curr_bss->bcn_wpa_ie) |
| 2908 | curr_bss->bcn_wpa_ie = |
| 2909 | (struct ieee_types_vendor_specific *) |
| 2910 | (curr_bss->beacon_buf + |
| 2911 | curr_bss->wpa_offset); |
| 2912 | |
| 2913 | if (curr_bss->bcn_rsn_ie) |
| 2914 | curr_bss->bcn_rsn_ie = (struct ieee_types_generic *) |
| 2915 | (curr_bss->beacon_buf + |
| 2916 | curr_bss->rsn_offset); |
| 2917 | |
| 2918 | if (curr_bss->bcn_ht_cap) |
| 2919 | curr_bss->bcn_ht_cap = (struct ieee80211_ht_cap *) |
| 2920 | (curr_bss->beacon_buf + |
| 2921 | curr_bss->ht_cap_offset); |
| 2922 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 2923 | if (curr_bss->bcn_ht_oper) |
| 2924 | curr_bss->bcn_ht_oper = (struct ieee80211_ht_operation *) |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2925 | (curr_bss->beacon_buf + |
| 2926 | curr_bss->ht_info_offset); |
| 2927 | |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 2928 | if (curr_bss->bcn_vht_cap) |
Amitkumar Karwar | d512464 | 2014-03-04 18:43:14 -0800 | [diff] [blame] | 2929 | curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf + |
| 2930 | curr_bss->vht_cap_offset); |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 2931 | |
| 2932 | if (curr_bss->bcn_vht_oper) |
Amitkumar Karwar | d512464 | 2014-03-04 18:43:14 -0800 | [diff] [blame] | 2933 | curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf + |
| 2934 | curr_bss->vht_info_offset); |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 2935 | |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2936 | if (curr_bss->bcn_bss_co_2040) |
| 2937 | curr_bss->bcn_bss_co_2040 = |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 2938 | (curr_bss->beacon_buf + curr_bss->bss_co_2040_offset); |
Amitkumar Karwar | 7c6fa2a | 2011-08-10 18:53:57 -0700 | [diff] [blame] | 2939 | |
| 2940 | if (curr_bss->bcn_ext_cap) |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 2941 | curr_bss->bcn_ext_cap = curr_bss->beacon_buf + |
| 2942 | curr_bss->ext_cap_offset; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 2943 | |
| 2944 | if (curr_bss->oper_mode) |
| 2945 | curr_bss->oper_mode = (void *)(curr_bss->beacon_buf + |
| 2946 | curr_bss->oper_mode_offset); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | /* |
| 2950 | * This function frees the current BSS descriptor beacon buffer. |
| 2951 | */ |
| 2952 | void |
| 2953 | mwifiex_free_curr_bcn(struct mwifiex_private *priv) |
| 2954 | { |
| 2955 | kfree(priv->curr_bcn_buf); |
| 2956 | priv->curr_bcn_buf = NULL; |
| 2957 | } |