Om Prakash Tripathi | 7e3f45d | 2016-12-28 16:58:54 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all |
| 7 | * copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 16 | * PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * DOC: Defines scan utility functions |
| 21 | */ |
Om Prakash Tripathi | 22f95dc | 2016-12-19 10:45:59 +0530 | [diff] [blame] | 22 | |
Abhishek Singh | 4caf1a9 | 2017-02-21 15:01:08 +0530 | [diff] [blame] | 23 | #include <wlan_cmn.h> |
Om Prakash Tripathi | 22f95dc | 2016-12-19 10:45:59 +0530 | [diff] [blame] | 24 | #include <wlan_scan_ucfg_api.h> |
| 25 | #include <wlan_scan_utils_api.h> |
| 26 | #include <../../core/src/wlan_scan_cache_db.h> |
| 27 | #include <../../core/src/wlan_scan_main.h> |
| 28 | |
| 29 | const char* |
| 30 | util_scan_get_ev_type_name(enum scan_event_type type) |
| 31 | { |
| 32 | static const char * const event_name[] = { |
| 33 | [SCAN_EVENT_TYPE_STARTED] = "STARTED", |
| 34 | [SCAN_EVENT_TYPE_COMPLETED] = "COMPLETED", |
| 35 | [SCAN_EVENT_TYPE_BSS_CHANNEL] = "HOME_CHANNEL", |
| 36 | [SCAN_EVENT_TYPE_FOREIGN_CHANNEL] = "FOREIGN_CHANNEL", |
| 37 | [SCAN_EVENT_TYPE_DEQUEUED] = "DEQUEUED", |
| 38 | [SCAN_EVENT_TYPE_PREEMPTED] = "PREEMPTED", |
| 39 | [SCAN_EVENT_TYPE_START_FAILED] = "START_FAILED", |
| 40 | [SCAN_EVENT_TYPE_RESTARTED] = "RESTARTED", |
| 41 | [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_EXIT] = "FOREIGN_CHANNEL_EXIT", |
| 42 | [SCAN_EVENT_TYPE_SUSPENDED] = "SUSPENDED", |
| 43 | [SCAN_EVENT_TYPE_RESUMED] = "RESUMED", |
| 44 | [SCAN_EVENT_TYPE_NLO_COMPLETE] = "NLO_COMPLETE", |
Abhishek Singh | 8c6e82d | 2017-03-03 21:57:29 +0530 | [diff] [blame] | 45 | [SCAN_EVENT_TYPE_NLO_MATCH] = "NLO_MATCH", |
Om Prakash Tripathi | 22f95dc | 2016-12-19 10:45:59 +0530 | [diff] [blame] | 46 | [SCAN_EVENT_TYPE_INVALID] = "INVALID", |
| 47 | [SCAN_EVENT_TYPE_GPIO_TIMEOUT] = "GPIO_TIMEOUT", |
| 48 | [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_START] = |
| 49 | "RADIO_MEASUREMENT_START", |
| 50 | [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_END] = |
| 51 | "RADIO_MEASUREMENT_END", |
| 52 | [SCAN_EVENT_TYPE_BSSID_MATCH] = "BSSID_MATCH", |
| 53 | [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_GET_NF] = |
| 54 | "FOREIGN_CHANNEL_GET_NF", |
| 55 | }; |
| 56 | |
Abhishek Singh | 483d914 | 2017-03-06 13:28:13 +0530 | [diff] [blame] | 57 | if (type >= SCAN_EVENT_TYPE_MAX) |
Om Prakash Tripathi | 22f95dc | 2016-12-19 10:45:59 +0530 | [diff] [blame] | 58 | return "UNKNOWN"; |
Om Prakash Tripathi | 22f95dc | 2016-12-19 10:45:59 +0530 | [diff] [blame] | 59 | |
| 60 | return event_name[type]; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | const char* |
| 65 | util_scan_get_ev_reason_name(enum scan_completion_reason reason) |
| 66 | { |
| 67 | static const char * const reason_name[] = { |
| 68 | [SCAN_REASON_NONE] = "NONE", |
| 69 | [SCAN_REASON_COMPLETED] = "COMPLETED", |
| 70 | [SCAN_REASON_CANCELLED] = "CANCELLED", |
| 71 | [SCAN_REASON_PREEMPTED] = "PREEMPTED", |
| 72 | [SCAN_REASON_TIMEDOUT] = "TIMEDOUT", |
| 73 | [SCAN_REASON_INTERNAL_FAILURE] = "INTERNAL_FAILURE", |
| 74 | [SCAN_REASON_SUSPENDED] = "SUSPENDED", |
| 75 | [SCAN_REASON_RUN_FAILED] = "RUN_FAILED", |
| 76 | [SCAN_REASON_TERMINATION_FUNCTION] = "TERMINATION_FUNCTION", |
| 77 | [SCAN_REASON_MAX_OFFCHAN_RETRIES] = "MAX_OFFCHAN_RETRIES", |
| 78 | }; |
| 79 | |
Abhishek Singh | 483d914 | 2017-03-06 13:28:13 +0530 | [diff] [blame] | 80 | if (reason >= SCAN_REASON_MAX) |
Om Prakash Tripathi | 22f95dc | 2016-12-19 10:45:59 +0530 | [diff] [blame] | 81 | return "UNKNOWN"; |
Om Prakash Tripathi | 22f95dc | 2016-12-19 10:45:59 +0530 | [diff] [blame] | 82 | |
| 83 | return reason_name[reason]; |
| 84 | } |
| 85 | |
| 86 | qdf_time_t |
| 87 | util_get_last_scan_time(struct wlan_objmgr_vdev *vdev) |
| 88 | { |
| 89 | uint8_t pdev_id; |
| 90 | struct wlan_scan_obj *scan_obj; |
| 91 | |
| 92 | if (!vdev) { |
| 93 | scm_warn("null vdev"); |
| 94 | QDF_ASSERT(0); |
| 95 | return 0; |
| 96 | } |
| 97 | pdev_id = wlan_scan_vdev_get_pdev_id(vdev); |
| 98 | scan_obj = wlan_vdev_get_scan_obj(vdev); |
| 99 | |
| 100 | return scan_obj->pdev_info[pdev_id].last_scan_time; |
| 101 | } |
Abhishek Singh | 4caf1a9 | 2017-02-21 15:01:08 +0530 | [diff] [blame] | 102 | |
| 103 | static enum wlan_band scm_chan_to_band(uint32_t chan) |
| 104 | { |
| 105 | if (WLAN_CHAN_IS_2GHZ(chan)) |
| 106 | return WLAN_BAND_2_4_GHZ; |
| 107 | |
| 108 | return WLAN_BAND_5_GHZ; |
| 109 | } |
| 110 | |
Abhishek Singh | d4e600f | 2017-02-21 15:16:28 +0530 | [diff] [blame] | 111 | bool util_is_scan_entry_match( |
| 112 | struct scan_cache_entry *entry1, |
| 113 | struct scan_cache_entry *entry2) |
| 114 | { |
| 115 | |
| 116 | if (entry1->cap_info.wlan_caps.ess != |
| 117 | entry1->cap_info.wlan_caps.ess) |
| 118 | return false; |
| 119 | |
| 120 | if (entry1->cap_info.wlan_caps.ess && |
| 121 | !qdf_mem_cmp(entry1->bssid.bytes, |
| 122 | entry1->bssid.bytes, QDF_MAC_ADDR_SIZE) && |
| 123 | scm_chan_to_band( |
| 124 | entry1->channel.chan_idx) == |
| 125 | scm_chan_to_band(entry2->channel.chan_idx)) { |
| 126 | /* Check for BSS */ |
| 127 | if (util_is_ssid_match( |
| 128 | &entry1->ssid, &entry2->ssid)) |
| 129 | return true; |
| 130 | } else if (entry1->cap_info.wlan_caps.ibss && |
| 131 | (entry1->channel.chan_idx == |
| 132 | entry2->channel.chan_idx)) { |
| 133 | /* |
| 134 | * Same channel cannot have same SSID for |
| 135 | * different IBSS, so no need to check BSSID |
| 136 | */ |
| 137 | if (util_is_ssid_match( |
| 138 | &entry1->ssid, &entry2->ssid)) |
| 139 | return true; |
| 140 | } else if (!entry1->cap_info.wlan_caps.ibss && |
| 141 | !entry1->cap_info.wlan_caps.ess && |
| 142 | !qdf_mem_cmp(entry1->bssid.bytes, |
| 143 | entry1->bssid.bytes, QDF_MAC_ADDR_SIZE)) { |
| 144 | /* In case of P2P devices, ess and ibss will be set to zero */ |
| 145 | return true; |
| 146 | } |
| 147 | |
| 148 | return false; |
| 149 | } |
| 150 | |
Abhishek Singh | 4caf1a9 | 2017-02-21 15:01:08 +0530 | [diff] [blame] | 151 | static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates) |
| 152 | { |
| 153 | static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108}; |
| 154 | bool pureg = false; |
| 155 | uint8_t i, j; |
| 156 | |
| 157 | for (i = 0; i < nrates; i++) { |
| 158 | for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) { |
| 159 | if (WLAN_RV(rates[i]) == g_rates[j]) { |
| 160 | pureg = true; |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | if (pureg) |
| 165 | break; |
| 166 | } |
| 167 | |
| 168 | return pureg; |
| 169 | } |
| 170 | static enum wlan_phymode |
| 171 | util_scan_get_phymode_5g(struct scan_cache_entry *scan_params) |
| 172 | { |
| 173 | enum wlan_phymode phymode = WLAN_PHYMODE_AUTO; |
| 174 | uint16_t ht_cap = 0; |
| 175 | struct htcap_cmn_ie *htcap; |
| 176 | struct wlan_ie_htinfo_cmn *htinfo; |
| 177 | struct wlan_ie_vhtop *vhtop; |
| 178 | |
| 179 | htcap = (struct htcap_cmn_ie *) |
| 180 | util_scan_entry_htcap(scan_params); |
| 181 | htinfo = (struct wlan_ie_htinfo_cmn *) |
| 182 | util_scan_entry_htinfo(scan_params); |
| 183 | vhtop = (struct wlan_ie_vhtop *) |
| 184 | util_scan_entry_vhtop(scan_params); |
| 185 | |
| 186 | if (!(htcap && htinfo)) |
| 187 | return WLAN_PHYMODE_11A; |
| 188 | |
| 189 | if (htcap) |
| 190 | ht_cap = le16toh(htcap->hc_cap); |
| 191 | |
| 192 | if (util_scan_entry_vhtcap(scan_params) && vhtop) { |
| 193 | switch (vhtop->vht_op_chwidth) { |
| 194 | case WLAN_VHTOP_CHWIDTH_2040: |
| 195 | if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && |
| 196 | (htinfo->hi_extchoff == |
| 197 | WLAN_HTINFO_EXTOFFSET_ABOVE)) |
| 198 | phymode = WLAN_PHYMODE_11AC_VHT40PLUS; |
| 199 | else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && |
| 200 | (htinfo->hi_extchoff == |
| 201 | WLAN_HTINFO_EXTOFFSET_BELOW)) |
| 202 | phymode = WLAN_PHYMODE_11AC_VHT40MINUS; |
| 203 | else |
| 204 | phymode = WLAN_PHYMODE_11AC_VHT20; |
| 205 | break; |
| 206 | case WLAN_VHTOP_CHWIDTH_80: |
| 207 | if (WLAN_IS_REVSIG_VHT80_80(vhtop)) |
| 208 | phymode = WLAN_PHYMODE_11AC_VHT80_80; |
| 209 | else if (WLAN_IS_REVSIG_VHT160(vhtop)) |
| 210 | phymode = WLAN_PHYMODE_11AC_VHT160; |
| 211 | else |
| 212 | phymode = WLAN_PHYMODE_11AC_VHT80; |
| 213 | break; |
| 214 | case WLAN_VHTOP_CHWIDTH_160: |
| 215 | phymode = WLAN_PHYMODE_11AC_VHT160; |
| 216 | break; |
| 217 | case WLAN_VHTOP_CHWIDTH_80_80: |
| 218 | phymode = WLAN_PHYMODE_11AC_VHT80_80; |
| 219 | break; |
| 220 | default: |
| 221 | scm_err("bad channel: %d", |
| 222 | vhtop->vht_op_chwidth); |
| 223 | break; |
| 224 | } |
| 225 | } else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && |
| 226 | (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE)) |
| 227 | phymode = WLAN_PHYMODE_11NA_HT40PLUS; |
| 228 | else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && |
| 229 | (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW)) |
| 230 | phymode = WLAN_PHYMODE_11NA_HT40MINUS; |
| 231 | else |
| 232 | phymode = WLAN_PHYMODE_11NA_HT20; |
| 233 | |
| 234 | return phymode; |
| 235 | } |
| 236 | |
| 237 | static enum wlan_phymode |
| 238 | util_scan_get_phymode_2g(struct scan_cache_entry *scan_params) |
| 239 | { |
| 240 | enum wlan_phymode phymode = WLAN_PHYMODE_AUTO; |
| 241 | uint16_t ht_cap = 0; |
| 242 | struct htcap_cmn_ie *htcap; |
| 243 | struct wlan_ie_htinfo_cmn *htinfo; |
| 244 | struct wlan_ie_vhtop *vhtop; |
| 245 | |
| 246 | htcap = (struct htcap_cmn_ie *) |
| 247 | util_scan_entry_htcap(scan_params); |
| 248 | htinfo = (struct wlan_ie_htinfo_cmn *) |
| 249 | util_scan_entry_htinfo(scan_params); |
| 250 | vhtop = (struct wlan_ie_vhtop *) |
| 251 | util_scan_entry_vhtop(scan_params); |
| 252 | |
| 253 | if (htcap) |
| 254 | ht_cap = le16toh(htcap->hc_cap); |
| 255 | |
| 256 | if (htcap && htinfo) { |
| 257 | if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && |
| 258 | (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE)) |
| 259 | phymode = WLAN_PHYMODE_11NG_HT40PLUS; |
| 260 | else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) && |
| 261 | (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW)) |
| 262 | phymode = WLAN_PHYMODE_11NG_HT40MINUS; |
| 263 | else |
| 264 | phymode = WLAN_PHYMODE_11NG_HT20; |
| 265 | } else if (util_scan_entry_xrates(scan_params)) { |
| 266 | /* only 11G stations will have more than 8 rates */ |
| 267 | phymode = WLAN_PHYMODE_11G; |
| 268 | } else { |
| 269 | /* Some mischievous g-only APs do not set extended rates */ |
| 270 | if (util_scan_entry_rates(scan_params)) { |
| 271 | if (util_is_pureg_rate(&scan_params->ie_list.rates[2], |
| 272 | scan_params->ie_list.rates[1])) |
| 273 | phymode = WLAN_PHYMODE_11G; |
| 274 | else |
| 275 | phymode = WLAN_PHYMODE_11B; |
| 276 | } else { |
| 277 | phymode = WLAN_PHYMODE_11B; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | return phymode; |
| 282 | } |
| 283 | |
| 284 | static QDF_STATUS |
| 285 | util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params, |
| 286 | struct ie_header *sub_ie, qdf_size_t sub_ie_len) |
| 287 | { |
| 288 | /* Walk through to check nothing is malformed */ |
| 289 | while (sub_ie_len >= sizeof(struct ie_header)) { |
| 290 | /* At least one more header is present */ |
| 291 | sub_ie_len -= sizeof(struct ie_header); |
| 292 | |
| 293 | if (sub_ie->ie_len == 0) { |
| 294 | sub_ie += 1; |
| 295 | continue; |
| 296 | } |
| 297 | if (sub_ie_len < sub_ie->ie_len) { |
| 298 | scm_err("Incomplete corrupted IE:%x", |
| 299 | WLAN_ELEMID_CHAN_SWITCH_WRAP); |
| 300 | return QDF_STATUS_E_INVAL; |
| 301 | } |
| 302 | switch (sub_ie->ie_id) { |
| 303 | case WLAN_ELEMID_COUNTRY: |
| 304 | scan_params->ie_list.country = (uint8_t *)sub_ie; |
| 305 | break; |
| 306 | case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH: |
| 307 | scan_params->ie_list.widebw = (uint8_t *)sub_ie; |
| 308 | break; |
| 309 | case WLAN_ELEMID_VHT_TX_PWR_ENVLP: |
| 310 | scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie; |
| 311 | break; |
| 312 | } |
| 313 | /* Consume sub info element */ |
| 314 | sub_ie_len -= sub_ie->ie_len; |
| 315 | /* go to next Sub IE */ |
| 316 | sub_ie = (struct ie_header *) |
| 317 | (((uint8_t *) sub_ie) + |
| 318 | sizeof(struct ie_header) + sub_ie->ie_len); |
| 319 | } |
| 320 | |
| 321 | return QDF_STATUS_SUCCESS; |
| 322 | } |
| 323 | |
| 324 | static bool |
| 325 | util_scan_is_hidden_ssid(struct ie_ssid *ssid) |
| 326 | { |
| 327 | uint8_t i; |
| 328 | |
| 329 | /* |
| 330 | * We flag this as Hidden SSID if the Length is 0 |
| 331 | * of the SSID only contains 0's |
| 332 | */ |
| 333 | if (!ssid || !ssid->ssid_len) |
| 334 | return true; |
| 335 | |
| 336 | for (i = 0; i < ssid->ssid_len; i++) |
| 337 | if (ssid->ssid[i] != 0) |
| 338 | return false; |
| 339 | |
| 340 | /* All 0's */ |
| 341 | return true; |
| 342 | } |
| 343 | |
| 344 | static void |
| 345 | util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params, |
| 346 | struct ie_header *ie) |
| 347 | { |
| 348 | |
| 349 | if (scan_params->ie_list.vendor == NULL) |
| 350 | scan_params->ie_list.vendor = (uint8_t *)ie; |
| 351 | |
| 352 | if (is_wpa_oui((uint8_t *)ie)) { |
| 353 | scan_params->ie_list.wpa = (uint8_t *)ie; |
| 354 | } else if (is_wps_oui((uint8_t *)ie)) { |
| 355 | scan_params->ie_list.wps = (uint8_t *)ie; |
| 356 | /* WCN IE should be a subset of WPS IE */ |
| 357 | if (is_wcn_oui((uint8_t *)ie)) |
| 358 | scan_params->ie_list.wcn = (uint8_t *)ie; |
| 359 | } else if (is_wme_param((uint8_t *)ie)) { |
| 360 | scan_params->ie_list.wmeparam = (uint8_t *)ie; |
| 361 | } else if (is_wme_info((uint8_t *)ie)) { |
| 362 | scan_params->ie_list.wmeinfo = (uint8_t *)ie; |
| 363 | } else if (is_atheros_oui((uint8_t *)ie)) { |
| 364 | scan_params->ie_list.athcaps = (uint8_t *)ie; |
| 365 | } else if (is_atheros_extcap_oui((uint8_t *)ie)) { |
| 366 | scan_params->ie_list.athextcaps = (uint8_t *)ie; |
| 367 | } else if (is_sfa_oui((uint8_t *)ie)) { |
| 368 | scan_params->ie_list.sfa = (uint8_t *)ie; |
| 369 | } else if (is_p2p_oui((uint8_t *)ie)) { |
| 370 | scan_params->ie_list.p2p = (uint8_t *)ie; |
| 371 | } else if (is_qca_whc_oui((uint8_t *)ie, |
| 372 | QCA_OUI_WHC_AP_INFO_SUBTYPE)) { |
| 373 | scan_params->ie_list.sonadv = (uint8_t *)ie; |
| 374 | } else if (is_ht_cap((uint8_t *)ie)) { |
| 375 | /* we only care if there isn't already an HT IE (ANA) */ |
| 376 | if (scan_params->ie_list.htcap == NULL) |
| 377 | scan_params->ie_list.htcap = |
| 378 | (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie); |
| 379 | } else if (is_ht_info((uint8_t *)ie)) { |
| 380 | /* we only care if there isn't already an HT IE (ANA) */ |
| 381 | if (scan_params->ie_list.htinfo == NULL) |
| 382 | scan_params->ie_list.htinfo = |
| 383 | (uint8_t *)&(((struct wlan_vendor_ie_htinfo *) |
| 384 | ie)->hi_ie); |
| 385 | } else if (is_interop_vht((uint8_t *)ie) && |
| 386 | !(scan_params->ie_list.vhtop)) { |
| 387 | /* location where Interop Vht Cap IE and VHT OP IE Present */ |
| 388 | scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) + 7); |
| 389 | scan_params->ie_list.vhtop = (((uint8_t *)(ie)) + 21); |
| 390 | } else if (is_bwnss_oui((uint8_t *)ie)) { |
| 391 | /* |
| 392 | * Bandwidth-NSS map has sub-type & version. |
| 393 | * hence copy data just after version byte |
| 394 | */ |
| 395 | scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8); |
Abhishek Singh | e5f3f0f | 2017-03-07 18:20:44 +0530 | [diff] [blame] | 396 | } else if (is_he_cap_oui(((uint8_t *)(ie))) && |
| 397 | !(scan_params->ie_list.hecap)) { |
| 398 | scan_params->ie_list.hecap = (uint8_t *)ie; |
| 399 | } else if (is_he_op_oui(((uint8_t *)(ie))) && |
| 400 | !(scan_params->ie_list.heop)) { |
| 401 | scan_params->ie_list.heop = (uint8_t *)ie; |
Abhishek Singh | 4caf1a9 | 2017-02-21 15:01:08 +0530 | [diff] [blame] | 402 | } |
Abhishek Singh | e5f3f0f | 2017-03-07 18:20:44 +0530 | [diff] [blame] | 403 | |
Abhishek Singh | 4caf1a9 | 2017-02-21 15:01:08 +0530 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static QDF_STATUS |
| 407 | util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params) |
| 408 | { |
| 409 | struct ie_header *ie, *sub_ie; |
| 410 | uint32_t ie_len, sub_ie_len; |
| 411 | QDF_STATUS status; |
| 412 | |
| 413 | ie_len = util_scan_entry_ie_len(scan_params); |
| 414 | ie = (struct ie_header *) |
| 415 | util_scan_entry_ie_data(scan_params); |
| 416 | |
| 417 | while (ie_len >= sizeof(struct ie_header)) { |
| 418 | ie_len -= sizeof(struct ie_header); |
| 419 | |
| 420 | if (!ie->ie_len) { |
| 421 | ie += 1; |
| 422 | continue; |
| 423 | } |
| 424 | |
| 425 | if (ie_len < ie->ie_len) { |
| 426 | scm_err("Incomplete corrupted IE:%x", |
| 427 | ie->ie_id); |
| 428 | return QDF_STATUS_E_INVAL; |
| 429 | } |
| 430 | |
| 431 | switch (ie->ie_id) { |
| 432 | case WLAN_ELEMID_SSID: |
| 433 | scan_params->ie_list.ssid = (uint8_t *)ie; |
| 434 | break; |
| 435 | case WLAN_ELEMID_RATES: |
| 436 | scan_params->ie_list.rates = (uint8_t *)ie; |
| 437 | break; |
| 438 | case WLAN_ELEMID_DSPARMS: |
| 439 | scan_params->channel.chan_idx = |
| 440 | ((struct ds_ie *)ie)->cur_chan; |
| 441 | break; |
| 442 | case WLAN_ELEMID_TIM: |
| 443 | scan_params->ie_list.tim = (uint8_t *)ie; |
| 444 | scan_params->dtim_period = |
| 445 | ((struct wlan_tim_ie *)ie)->tim_period; |
| 446 | break; |
| 447 | case WLAN_ELEMID_COUNTRY: |
| 448 | scan_params->ie_list.country = (uint8_t *)ie; |
| 449 | break; |
| 450 | case WLAN_ELEMID_QBSS_LOAD: |
| 451 | scan_params->ie_list.qbssload = (uint8_t *)ie; |
| 452 | break; |
| 453 | case WLAN_ELEMID_CHANSWITCHANN: |
| 454 | scan_params->ie_list.csa = (uint8_t *)ie; |
| 455 | break; |
| 456 | case WLAN_ELEMID_IBSSDFS: |
| 457 | scan_params->ie_list.ibssdfs = (uint8_t *)ie; |
| 458 | break; |
| 459 | case WLAN_ELEMID_QUIET: |
| 460 | scan_params->ie_list.quiet = (uint8_t *)ie; |
| 461 | break; |
| 462 | case WLAN_ELEMID_ERP: |
| 463 | scan_params->erp = ((struct erp_ie *)ie)->value; |
| 464 | break; |
| 465 | case WLAN_ELEMID_HTCAP_ANA: |
| 466 | scan_params->ie_list.htcap = |
| 467 | (uint8_t *)&(((struct htcap_ie *)ie)->ie); |
| 468 | break; |
| 469 | case WLAN_ELEMID_RSN: |
| 470 | scan_params->ie_list.rsn = (uint8_t *)ie; |
| 471 | break; |
| 472 | case WLAN_ELEMID_XRATES: |
| 473 | scan_params->ie_list.xrates = (uint8_t *)ie; |
| 474 | break; |
| 475 | case WLAN_ELEMID_EXTCHANSWITCHANN: |
| 476 | scan_params->ie_list.xcsa = (uint8_t *)ie; |
| 477 | break; |
| 478 | case WLAN_ELEMID_SECCHANOFFSET: |
| 479 | scan_params->ie_list.secchanoff = (uint8_t *)ie; |
| 480 | break; |
| 481 | case WLAN_ELEMID_HTINFO_ANA: |
| 482 | scan_params->ie_list.htinfo = |
| 483 | (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie); |
| 484 | scan_params->channel.chan_idx = |
| 485 | ((struct wlan_ie_htinfo_cmn *) |
| 486 | (scan_params->ie_list.htinfo))->hi_ctrlchannel; |
| 487 | break; |
| 488 | case WLAN_ELEMID_WAPI: |
| 489 | scan_params->ie_list.wapi = (uint8_t *)ie; |
| 490 | break; |
| 491 | case WLAN_ELEMID_XCAPS: |
| 492 | scan_params->ie_list.extcaps = (uint8_t *)ie; |
| 493 | break; |
| 494 | case WLAN_ELEMID_VHTCAP: |
| 495 | scan_params->ie_list.vhtcap = (uint8_t *)ie; |
| 496 | break; |
| 497 | case WLAN_ELEMID_VHTOP: |
| 498 | scan_params->ie_list.vhtop = (uint8_t *)ie; |
| 499 | break; |
| 500 | case WLAN_ELEMID_OP_MODE_NOTIFY: |
| 501 | scan_params->ie_list.opmode = (uint8_t *)ie; |
| 502 | break; |
| 503 | case WLAN_ELEMID_MOBILITY_DOMAIN: |
| 504 | scan_params->ie_list.mdie = (uint8_t *)ie; |
| 505 | break; |
| 506 | case WLAN_ELEMID_VENDOR: |
| 507 | util_scan_parse_vendor_ie(scan_params, |
| 508 | ie); |
| 509 | break; |
| 510 | case WLAN_ELEMID_CHAN_SWITCH_WRAP: |
| 511 | scan_params->ie_list.cswrp = (uint8_t *)ie; |
| 512 | /* Go to next sub IE */ |
| 513 | sub_ie = (struct ie_header *) |
| 514 | (((uint8_t *)ie) + sizeof(struct ie_header)); |
| 515 | sub_ie_len = ie->ie_len; |
| 516 | status = |
| 517 | util_scan_parse_chan_switch_wrapper_ie( |
| 518 | scan_params, sub_ie, sub_ie_len); |
| 519 | if (QDF_IS_STATUS_ERROR(status)) { |
| 520 | scm_err("failed to parse chan_switch_wrapper_ie"); |
| 521 | return status; |
| 522 | } |
| 523 | break; |
| 524 | default: |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | /* Consume info element */ |
| 529 | ie_len -= ie->ie_len; |
| 530 | /* Go to next IE */ |
| 531 | ie = (struct ie_header *) |
| 532 | (((uint8_t *) ie) + |
| 533 | sizeof(struct ie_header) + |
| 534 | ie->ie_len); |
| 535 | } |
| 536 | |
| 537 | return QDF_STATUS_SUCCESS; |
| 538 | } |
| 539 | |
| 540 | struct scan_cache_entry * |
| 541 | util_scan_unpack_beacon_frame(uint8_t *frame, |
| 542 | qdf_size_t frame_len, uint32_t frm_subtype, |
| 543 | struct mgmt_rx_event_params *rx_param) |
| 544 | { |
| 545 | struct wlan_frame_hdr *hdr; |
| 546 | struct wlan_bcn_frame *bcn; |
| 547 | QDF_STATUS status; |
| 548 | struct ie_ssid *ssid; |
| 549 | struct scan_cache_entry *scan_entry = NULL; |
| 550 | |
| 551 | scan_entry = qdf_mem_malloc(sizeof(*scan_entry)); |
| 552 | if (!scan_entry) { |
| 553 | scm_err("failed to allocate memory for scan_entry"); |
| 554 | return NULL; |
| 555 | } |
| 556 | scan_entry->raw_frame.ptr = |
| 557 | qdf_mem_malloc(frame_len); |
| 558 | if (!scan_entry->raw_frame.ptr) { |
| 559 | scm_err("failed to allocate memory for frame"); |
| 560 | qdf_mem_free(scan_entry); |
| 561 | return NULL; |
| 562 | } |
| 563 | |
| 564 | bcn = (struct wlan_bcn_frame *) |
| 565 | (frame + sizeof(*hdr)); |
| 566 | hdr = (struct wlan_frame_hdr *)frame; |
| 567 | |
| 568 | scan_entry->frm_subtype = frm_subtype; |
| 569 | qdf_mem_copy(scan_entry->bssid.bytes, |
| 570 | hdr->i_addr3, QDF_MAC_ADDR_SIZE); |
| 571 | /* Scr addr */ |
| 572 | qdf_mem_copy(scan_entry->mac_addr.bytes, |
| 573 | hdr->i_addr2, QDF_MAC_ADDR_SIZE); |
| 574 | scan_entry->seq_num = |
| 575 | (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT); |
| 576 | |
| 577 | scan_entry->rssi_raw = rx_param->rssi; |
Om Prakash Tripathi | cdcbb39 | 2017-04-18 18:51:20 +0530 | [diff] [blame^] | 578 | scan_entry->avg_rssi = WLAN_RSSI_DUMMY_MARKER; |
Abhishek Singh | 4caf1a9 | 2017-02-21 15:01:08 +0530 | [diff] [blame] | 579 | scan_entry->tsf_delta = rx_param->tsf_delta; |
| 580 | |
| 581 | /* store jiffies */ |
| 582 | scan_entry->rrm_parent_tsf = (u_int32_t) qdf_system_ticks(); |
| 583 | |
| 584 | scan_entry->bcn_int = le16toh(bcn->beacon_interval); |
| 585 | |
| 586 | /* |
| 587 | * In case if the beacon dosnt have |
| 588 | * valid beacon interval falback to def |
| 589 | */ |
| 590 | if (!scan_entry->bcn_int) |
| 591 | scan_entry->bcn_int = 100; |
| 592 | scan_entry->cap_info.value = le16toh(bcn->capability.value); |
| 593 | qdf_mem_copy(scan_entry->tsf_info.data, |
| 594 | bcn->timestamp, 8); |
| 595 | scan_entry->erp = ERP_NON_ERP_PRESENT; |
| 596 | |
Om Prakash Tripathi | cdcbb39 | 2017-04-18 18:51:20 +0530 | [diff] [blame^] | 597 | scan_entry->scan_entry_time = |
| 598 | qdf_mc_timer_get_system_time(); |
Abhishek Singh | 4caf1a9 | 2017-02-21 15:01:08 +0530 | [diff] [blame] | 599 | |
| 600 | scan_entry->raw_frame.len = frame_len; |
| 601 | qdf_mem_copy(scan_entry->raw_frame.ptr, |
| 602 | frame, frame_len); |
| 603 | status = util_scan_populate_bcn_ie_list(scan_entry); |
| 604 | if (QDF_IS_STATUS_ERROR(status)) { |
| 605 | scm_err("failed to parse beacon IE"); |
| 606 | qdf_mem_free(scan_entry->raw_frame.ptr); |
| 607 | qdf_mem_free(scan_entry); |
| 608 | return NULL; |
| 609 | } |
| 610 | |
| 611 | if (!scan_entry->ie_list.rates) { |
| 612 | qdf_mem_free(scan_entry->raw_frame.ptr); |
| 613 | qdf_mem_free(scan_entry); |
| 614 | return NULL; |
| 615 | } |
| 616 | |
| 617 | ssid = (struct ie_ssid *) |
| 618 | scan_entry->ie_list.ssid; |
| 619 | |
| 620 | if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) { |
| 621 | qdf_mem_free(scan_entry->raw_frame.ptr); |
| 622 | qdf_mem_free(scan_entry); |
| 623 | return NULL; |
| 624 | } |
| 625 | |
| 626 | if (scan_entry->ie_list.p2p) |
| 627 | scan_entry->is_p2p = true; |
| 628 | |
| 629 | /* If no channel info is present in beacon use meta channel */ |
| 630 | if (!scan_entry->channel.chan_idx) { |
| 631 | scan_entry->channel.chan_idx = |
| 632 | rx_param->channel; |
| 633 | } else if (rx_param->channel != |
| 634 | scan_entry->channel.chan_idx) { |
| 635 | scan_entry->channel_mismatch = true; |
| 636 | } |
| 637 | |
| 638 | if (util_scan_is_hidden_ssid(ssid)) { |
| 639 | scan_entry->ie_list.ssid = NULL; |
| 640 | } else { |
| 641 | qdf_mem_copy(scan_entry->ssid.ssid, |
| 642 | ssid->ssid, WLAN_SSID_MAX_LEN); |
| 643 | scan_entry->ssid.length = ssid->ssid_len; |
| 644 | scan_entry->hidden_ssid_timestamp = |
| 645 | scan_entry->scan_entry_time; |
| 646 | } |
| 647 | |
| 648 | if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx)) |
| 649 | scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry); |
| 650 | else |
| 651 | scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry); |
| 652 | |
| 653 | /* TODO calculate channel struct */ |
| 654 | return scan_entry; |
| 655 | } |