blob: 690c785a18ffd7ff90bba84c7e570565c409da3d [file] [log] [blame]
Om Prakash Tripathi7e3f45d2016-12-28 16:58:54 +05301/*
Bala Venkatesh7a5bee02019-01-07 16:09:03 +05302 * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
Om Prakash Tripathi7e3f45d2016-12-28 16:58:54 +05303 *
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 Tripathi22f95dc2016-12-19 10:45:59 +053022
Abhishek Singh4caf1a92017-02-21 15:01:08 +053023#include <wlan_cmn.h>
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053024#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>
Shashikala Prabhu48ecda82018-04-13 01:13:30 +053028#include <wlan_reg_services_api.h>
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053029
Sandeep Puligilla54d8b642018-07-06 17:35:26 -070030#define MAX_IE_LEN 1024
31
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053032const char*
33util_scan_get_ev_type_name(enum scan_event_type type)
34{
35 static const char * const event_name[] = {
36 [SCAN_EVENT_TYPE_STARTED] = "STARTED",
37 [SCAN_EVENT_TYPE_COMPLETED] = "COMPLETED",
38 [SCAN_EVENT_TYPE_BSS_CHANNEL] = "HOME_CHANNEL",
39 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL] = "FOREIGN_CHANNEL",
40 [SCAN_EVENT_TYPE_DEQUEUED] = "DEQUEUED",
41 [SCAN_EVENT_TYPE_PREEMPTED] = "PREEMPTED",
42 [SCAN_EVENT_TYPE_START_FAILED] = "START_FAILED",
43 [SCAN_EVENT_TYPE_RESTARTED] = "RESTARTED",
44 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_EXIT] = "FOREIGN_CHANNEL_EXIT",
45 [SCAN_EVENT_TYPE_SUSPENDED] = "SUSPENDED",
46 [SCAN_EVENT_TYPE_RESUMED] = "RESUMED",
47 [SCAN_EVENT_TYPE_NLO_COMPLETE] = "NLO_COMPLETE",
Abhishek Singh8c6e82d2017-03-03 21:57:29 +053048 [SCAN_EVENT_TYPE_NLO_MATCH] = "NLO_MATCH",
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053049 [SCAN_EVENT_TYPE_INVALID] = "INVALID",
50 [SCAN_EVENT_TYPE_GPIO_TIMEOUT] = "GPIO_TIMEOUT",
51 [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_START] =
52 "RADIO_MEASUREMENT_START",
53 [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_END] =
54 "RADIO_MEASUREMENT_END",
55 [SCAN_EVENT_TYPE_BSSID_MATCH] = "BSSID_MATCH",
56 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_GET_NF] =
57 "FOREIGN_CHANNEL_GET_NF",
58 };
59
Abhishek Singh483d9142017-03-06 13:28:13 +053060 if (type >= SCAN_EVENT_TYPE_MAX)
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053061 return "UNKNOWN";
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053062
63 return event_name[type];
64}
65
66
67const char*
68util_scan_get_ev_reason_name(enum scan_completion_reason reason)
69{
70 static const char * const reason_name[] = {
71 [SCAN_REASON_NONE] = "NONE",
72 [SCAN_REASON_COMPLETED] = "COMPLETED",
73 [SCAN_REASON_CANCELLED] = "CANCELLED",
74 [SCAN_REASON_PREEMPTED] = "PREEMPTED",
75 [SCAN_REASON_TIMEDOUT] = "TIMEDOUT",
76 [SCAN_REASON_INTERNAL_FAILURE] = "INTERNAL_FAILURE",
77 [SCAN_REASON_SUSPENDED] = "SUSPENDED",
78 [SCAN_REASON_RUN_FAILED] = "RUN_FAILED",
79 [SCAN_REASON_TERMINATION_FUNCTION] = "TERMINATION_FUNCTION",
80 [SCAN_REASON_MAX_OFFCHAN_RETRIES] = "MAX_OFFCHAN_RETRIES",
Abhijit Pradhan0f0e27b2018-10-08 10:48:00 +053081 [SCAN_REASON_DFS_VIOLATION] = "DFS_NOL_VIOLATION",
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053082 };
83
Abhishek Singh483d9142017-03-06 13:28:13 +053084 if (reason >= SCAN_REASON_MAX)
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053085 return "UNKNOWN";
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053086
87 return reason_name[reason];
88}
89
90qdf_time_t
91util_get_last_scan_time(struct wlan_objmgr_vdev *vdev)
92{
93 uint8_t pdev_id;
94 struct wlan_scan_obj *scan_obj;
95
96 if (!vdev) {
97 scm_warn("null vdev");
98 QDF_ASSERT(0);
99 return 0;
100 }
101 pdev_id = wlan_scan_vdev_get_pdev_id(vdev);
102 scan_obj = wlan_vdev_get_scan_obj(vdev);
103
Om Prakash Tripathi510a27c2019-03-01 11:53:18 +0530104 if (scan_obj)
105 return scan_obj->pdev_info[pdev_id].last_scan_time;
106 else
107 return 0;
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +0530108}
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530109
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530110enum wlan_band util_scan_scm_chan_to_band(uint32_t chan)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530111{
112 if (WLAN_CHAN_IS_2GHZ(chan))
113 return WLAN_BAND_2_4_GHZ;
114
115 return WLAN_BAND_5_GHZ;
116}
117
Shashikala Prabhu48ecda82018-04-13 01:13:30 +0530118enum wlan_band util_scan_scm_freq_to_band(uint16_t freq)
119{
120 if (WLAN_REG_IS_24GHZ_CH_FREQ(freq))
121 return WLAN_BAND_2_4_GHZ;
122
123 return WLAN_BAND_5_GHZ;
124}
125
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530126bool util_is_scan_entry_match(
127 struct scan_cache_entry *entry1,
128 struct scan_cache_entry *entry2)
129{
130
131 if (entry1->cap_info.wlan_caps.ess !=
wadesong49ae4cb2018-01-22 15:03:12 +0800132 entry2->cap_info.wlan_caps.ess)
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530133 return false;
134
135 if (entry1->cap_info.wlan_caps.ess &&
136 !qdf_mem_cmp(entry1->bssid.bytes,
Yeshwanth Sriram Guntukadca006c2018-11-16 17:58:08 +0530137 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530138 /* Check for BSS */
Yeshwanth Sriram Guntuka294ce112018-10-23 16:49:19 +0530139 if (util_is_ssid_match(&entry1->ssid, &entry2->ssid) ||
Yeshwanth Sriram Guntukadca006c2018-11-16 17:58:08 +0530140 util_scan_is_null_ssid(&entry1->ssid) ||
141 util_scan_is_null_ssid(&entry2->ssid))
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530142 return true;
143 } else if (entry1->cap_info.wlan_caps.ibss &&
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +0530144 (entry1->channel.chan_freq ==
145 entry2->channel.chan_freq)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530146 /*
147 * Same channel cannot have same SSID for
148 * different IBSS, so no need to check BSSID
149 */
150 if (util_is_ssid_match(
151 &entry1->ssid, &entry2->ssid))
152 return true;
153 } else if (!entry1->cap_info.wlan_caps.ibss &&
154 !entry1->cap_info.wlan_caps.ess &&
155 !qdf_mem_cmp(entry1->bssid.bytes,
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530156 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530157 /* In case of P2P devices, ess and ibss will be set to zero */
158 return true;
159 }
160
161 return false;
162}
163
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530164static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates)
165{
166 static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108};
167 bool pureg = false;
168 uint8_t i, j;
169
170 for (i = 0; i < nrates; i++) {
171 for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) {
172 if (WLAN_RV(rates[i]) == g_rates[j]) {
173 pureg = true;
174 break;
175 }
176 }
177 if (pureg)
178 break;
179 }
180
181 return pureg;
182}
Abhishek Ambure986f5c92019-10-21 14:52:59 +0530183
184#ifdef CONFIG_BAND_6GHZ
185static enum wlan_phymode
186util_scan_get_phymode_6g(struct scan_cache_entry *scan_params)
187{
188 uint8_t len;
189 struct he_oper_6g_param *he_6g_params;
190 uint32_t he_oper_params;
191 enum wlan_phymode phymode = WLAN_PHYMODE_11AXA_HE20;
192 uint8_t *he_ops;
193
194 he_ops = util_scan_entry_heop(scan_params);
195 if (!util_scan_entry_hecap(scan_params) || !he_ops)
196 return phymode;
197
198 len = he_ops[1];
199 he_ops += 2;
200
201 /* Length less than fixed params length */
202 if (len < 7)
203 return phymode;
204
205 /* element id extension */
206 he_ops++;
207 len--;
208
209 he_oper_params = LE_READ_4(he_ops);
210 if (!(he_oper_params & WLAN_HEOP_6GHZ_INFO_PRESENT_MASK))
211 return phymode;
212
213 /* fixed params */
214 he_ops += 6;
215 len -= 6;
216
217 if (!len)
218 return phymode;
219
220 /* vht oper params */
221 if (he_oper_params & WLAN_HEOP_VHTOP_PRESENT_MASK) {
222 if (len < 3)
223 return phymode;
224 he_ops += 3;
225 len -= 3;
226 }
227
228 if (!len)
229 return phymode;
230
231 if (he_oper_params & WLAN_HEOP_CO_LOCATED_BSS_MASK) {
232 he_ops += 1;
233 len -= 1;
234 }
235
236 if (len < sizeof(*he_6g_params))
237 return phymode;
238
239 he_6g_params = (struct he_oper_6g_param *)he_ops;
240
241 switch (he_6g_params->width) {
242 case WLAN_HE_6GHZ_CHWIDTH_20:
243 phymode = WLAN_PHYMODE_11AXA_HE20;
244 break;
245 case WLAN_HE_6GHZ_CHWIDTH_40:
246 phymode = WLAN_PHYMODE_11AXA_HE40;
247 break;
248 case WLAN_HE_6GHZ_CHWIDTH_80:
249 phymode = WLAN_PHYMODE_11AXA_HE80;
250 break;
251 case WLAN_HE_6GHZ_CHWIDTH_160_80_80:
252 if (WLAN_IS_HE80_80(he_6g_params))
253 phymode = WLAN_PHYMODE_11AXA_HE80_80;
254 else if (WLAN_IS_HE160(he_6g_params))
255 phymode = WLAN_PHYMODE_11AXA_HE160;
256 else
257 phymode = WLAN_PHYMODE_11AXA_HE80;
258 break;
259 default:
260 scm_err("Invalid he_6g_params width: %d", he_6g_params->width);
261 phymode = WLAN_PHYMODE_11AXA_HE20;
262 break;
263 }
264
265 return phymode;
266}
267#else
268static inline enum wlan_phymode
269util_scan_get_phymode_6g(struct scan_cache_entry *scan_params)
270{
271 return WLAN_PHYMODE_AUTO;
272}
273#endif
274
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530275static enum wlan_phymode
276util_scan_get_phymode_5g(struct scan_cache_entry *scan_params)
277{
278 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
279 uint16_t ht_cap = 0;
280 struct htcap_cmn_ie *htcap;
281 struct wlan_ie_htinfo_cmn *htinfo;
282 struct wlan_ie_vhtop *vhtop;
283
284 htcap = (struct htcap_cmn_ie *)
285 util_scan_entry_htcap(scan_params);
286 htinfo = (struct wlan_ie_htinfo_cmn *)
287 util_scan_entry_htinfo(scan_params);
288 vhtop = (struct wlan_ie_vhtop *)
289 util_scan_entry_vhtop(scan_params);
290
291 if (!(htcap && htinfo))
292 return WLAN_PHYMODE_11A;
293
294 if (htcap)
295 ht_cap = le16toh(htcap->hc_cap);
296
Abhishek Ambure986f5c92019-10-21 14:52:59 +0530297 if (ht_cap & WLAN_HTCAP_C_CHWIDTH40)
298 phymode = WLAN_PHYMODE_11NA_HT40;
299 else
300 phymode = WLAN_PHYMODE_11NA_HT20;
301
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530302 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
303 switch (vhtop->vht_op_chwidth) {
304 case WLAN_VHTOP_CHWIDTH_2040:
Abhishek Singhf3f97972019-09-18 12:13:46 +0530305 if (ht_cap & WLAN_HTCAP_C_CHWIDTH40)
306 phymode = WLAN_PHYMODE_11AC_VHT40;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530307 else
308 phymode = WLAN_PHYMODE_11AC_VHT20;
309 break;
310 case WLAN_VHTOP_CHWIDTH_80:
311 if (WLAN_IS_REVSIG_VHT80_80(vhtop))
312 phymode = WLAN_PHYMODE_11AC_VHT80_80;
313 else if (WLAN_IS_REVSIG_VHT160(vhtop))
314 phymode = WLAN_PHYMODE_11AC_VHT160;
315 else
316 phymode = WLAN_PHYMODE_11AC_VHT80;
317 break;
318 case WLAN_VHTOP_CHWIDTH_160:
319 phymode = WLAN_PHYMODE_11AC_VHT160;
320 break;
321 case WLAN_VHTOP_CHWIDTH_80_80:
322 phymode = WLAN_PHYMODE_11AC_VHT80_80;
323 break;
324 default:
325 scm_err("bad channel: %d",
326 vhtop->vht_op_chwidth);
Abhishek Singhf3f97972019-09-18 12:13:46 +0530327 phymode = WLAN_PHYMODE_11AC_VHT20;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530328 break;
329 }
Abhishek Ambure986f5c92019-10-21 14:52:59 +0530330 }
331
332 if (!util_scan_entry_hecap(scan_params))
333 return phymode;
334
335 /* for 5Ghz Check for HE, only if VHT cap and HE cap are present */
336 if (!IS_WLAN_PHYMODE_VHT(phymode))
337 return phymode;
338
339 switch (phymode) {
340 case WLAN_PHYMODE_11AC_VHT20:
341 phymode = WLAN_PHYMODE_11AXA_HE20;
342 break;
343 case WLAN_PHYMODE_11AC_VHT40:
344 phymode = WLAN_PHYMODE_11AXA_HE40;
345 break;
346 case WLAN_PHYMODE_11AC_VHT80:
347 phymode = WLAN_PHYMODE_11AXA_HE80;
348 break;
349 case WLAN_PHYMODE_11AC_VHT160:
350 phymode = WLAN_PHYMODE_11AXA_HE160;
351 break;
352 case WLAN_PHYMODE_11AC_VHT80_80:
353 phymode = WLAN_PHYMODE_11AXA_HE80_80;
354 break;
355 default:
356 phymode = WLAN_PHYMODE_11AXA_HE20;
357 break;
Abhishek Singhf3f97972019-09-18 12:13:46 +0530358 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530359
360 return phymode;
361}
362
363static enum wlan_phymode
364util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
365{
366 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
367 uint16_t ht_cap = 0;
368 struct htcap_cmn_ie *htcap;
369 struct wlan_ie_htinfo_cmn *htinfo;
370 struct wlan_ie_vhtop *vhtop;
371
372 htcap = (struct htcap_cmn_ie *)
373 util_scan_entry_htcap(scan_params);
374 htinfo = (struct wlan_ie_htinfo_cmn *)
375 util_scan_entry_htinfo(scan_params);
376 vhtop = (struct wlan_ie_vhtop *)
377 util_scan_entry_vhtop(scan_params);
378
379 if (htcap)
380 ht_cap = le16toh(htcap->hc_cap);
381
382 if (htcap && htinfo) {
383 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
384 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
385 phymode = WLAN_PHYMODE_11NG_HT40PLUS;
386 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
387 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
388 phymode = WLAN_PHYMODE_11NG_HT40MINUS;
389 else
390 phymode = WLAN_PHYMODE_11NG_HT20;
391 } else if (util_scan_entry_xrates(scan_params)) {
392 /* only 11G stations will have more than 8 rates */
393 phymode = WLAN_PHYMODE_11G;
394 } else {
395 /* Some mischievous g-only APs do not set extended rates */
396 if (util_scan_entry_rates(scan_params)) {
397 if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
398 scan_params->ie_list.rates[1]))
399 phymode = WLAN_PHYMODE_11G;
400 else
401 phymode = WLAN_PHYMODE_11B;
402 } else {
403 phymode = WLAN_PHYMODE_11B;
404 }
405 }
406
Abhishek Ambure986f5c92019-10-21 14:52:59 +0530407 /* Check for VHT only if HT cap is present */
408 if (!IS_WLAN_PHYMODE_HT(phymode))
409 return phymode;
410
Abhishek Singhf3f97972019-09-18 12:13:46 +0530411 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
412 switch (vhtop->vht_op_chwidth) {
413 case WLAN_VHTOP_CHWIDTH_2040:
414 if (phymode == WLAN_PHYMODE_11NG_HT40PLUS)
415 phymode = WLAN_PHYMODE_11AC_VHT40PLUS_2G;
416 else if (phymode == WLAN_PHYMODE_11NG_HT40MINUS)
417 phymode = WLAN_PHYMODE_11AC_VHT40MINUS_2G;
418 else
419 phymode = WLAN_PHYMODE_11AC_VHT20_2G;
420
421 break;
422 default:
423 scm_info("bad vht_op_chwidth: %d",
424 vhtop->vht_op_chwidth);
425 phymode = WLAN_PHYMODE_11AC_VHT20_2G;
426 break;
427 }
428 }
429
Abhishek Ambure986f5c92019-10-21 14:52:59 +0530430 if (!util_scan_entry_hecap(scan_params))
431 return phymode;
432
433 if (phymode == WLAN_PHYMODE_11AC_VHT40PLUS_2G ||
434 phymode == WLAN_PHYMODE_11NG_HT40PLUS)
435 phymode = WLAN_PHYMODE_11AXG_HE40PLUS;
436 else if (phymode == WLAN_PHYMODE_11AC_VHT40MINUS_2G ||
437 phymode == WLAN_PHYMODE_11NG_HT40MINUS)
438 phymode = WLAN_PHYMODE_11AXG_HE40MINUS;
439 else
440 phymode = WLAN_PHYMODE_11AXG_HE20;
441
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530442 return phymode;
443}
444
Abhishek Ambure986f5c92019-10-21 14:52:59 +0530445static enum wlan_phymode
446util_scan_get_phymode(struct scan_cache_entry *scan_params)
447{
448 if (WLAN_REG_IS_24GHZ_CH_FREQ(scan_params->channel.chan_freq))
449 return util_scan_get_phymode_2g(scan_params);
450 else if (WLAN_REG_IS_6GHZ_CHAN_FREQ(scan_params->channel.chan_freq))
451 return util_scan_get_phymode_6g(scan_params);
452 else
453 return util_scan_get_phymode_5g(scan_params);
454}
455
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530456static QDF_STATUS
457util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
458 struct ie_header *sub_ie, qdf_size_t sub_ie_len)
459{
460 /* Walk through to check nothing is malformed */
461 while (sub_ie_len >= sizeof(struct ie_header)) {
462 /* At least one more header is present */
463 sub_ie_len -= sizeof(struct ie_header);
464
465 if (sub_ie->ie_len == 0) {
466 sub_ie += 1;
467 continue;
468 }
469 if (sub_ie_len < sub_ie->ie_len) {
470 scm_err("Incomplete corrupted IE:%x",
471 WLAN_ELEMID_CHAN_SWITCH_WRAP);
472 return QDF_STATUS_E_INVAL;
473 }
474 switch (sub_ie->ie_id) {
475 case WLAN_ELEMID_COUNTRY:
476 scan_params->ie_list.country = (uint8_t *)sub_ie;
477 break;
478 case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
479 scan_params->ie_list.widebw = (uint8_t *)sub_ie;
480 break;
481 case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
482 scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
483 break;
484 }
485 /* Consume sub info element */
486 sub_ie_len -= sub_ie->ie_len;
487 /* go to next Sub IE */
488 sub_ie = (struct ie_header *)
489 (((uint8_t *) sub_ie) +
490 sizeof(struct ie_header) + sub_ie->ie_len);
491 }
492
493 return QDF_STATUS_SUCCESS;
494}
495
Om Prakash Tripathi1d1525d2017-09-08 13:59:34 +0530496bool
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530497util_scan_is_hidden_ssid(struct ie_ssid *ssid)
498{
499 uint8_t i;
500
501 /*
502 * We flag this as Hidden SSID if the Length is 0
503 * of the SSID only contains 0's
504 */
505 if (!ssid || !ssid->ssid_len)
506 return true;
507
508 for (i = 0; i < ssid->ssid_len; i++)
509 if (ssid->ssid[i] != 0)
510 return false;
511
512 /* All 0's */
513 return true;
514}
515
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530516static QDF_STATUS
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530517util_scan_parse_extn_ie(struct scan_cache_entry *scan_params,
518 struct ie_header *ie)
519{
520 struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie;
521
522 switch (extn_ie->ie_extn_id) {
Hariharan Basuthkar738320e2018-11-26 11:19:19 +0530523 case WLAN_EXTN_ELEMID_MAX_CHAN_SWITCH_TIME:
524 scan_params->ie_list.mcst = (uint8_t *)ie;
525 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530526 case WLAN_EXTN_ELEMID_SRP:
Gyanranjan Hazarikab5d426d2017-08-22 21:45:07 -0700527 scan_params->ie_list.srp = (uint8_t *)ie;
528 break;
529 case WLAN_EXTN_ELEMID_HECAP:
530 scan_params->ie_list.hecap = (uint8_t *)ie;
531 break;
532 case WLAN_EXTN_ELEMID_HEOP:
533 scan_params->ie_list.heop = (uint8_t *)ie;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530534 break;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530535 case WLAN_EXTN_ELEMID_ESP:
536 scan_params->ie_list.esp = (uint8_t *)ie;
537 break;
Rhythm Patwaa6ba9ee2018-05-23 19:29:57 -0700538 case WLAN_EXTN_ELEMID_MUEDCA:
539 scan_params->ie_list.muedca = (uint8_t *)ie;
540 break;
Rhythm Patwa7232cb12019-09-23 22:09:00 -0700541 case WLAN_EXTN_ELEMID_HE_6G_CAP:
542 scan_params->ie_list.hecap_6g = (uint8_t *)ie;
543 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530544 default:
545 break;
546 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530547 return QDF_STATUS_SUCCESS;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530548}
549
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530550static QDF_STATUS
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530551util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
552 struct ie_header *ie)
553{
Jeff Johnson82eb2122019-03-20 12:16:13 -0700554 if (!scan_params->ie_list.vendor)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530555 scan_params->ie_list.vendor = (uint8_t *)ie;
556
557 if (is_wpa_oui((uint8_t *)ie)) {
558 scan_params->ie_list.wpa = (uint8_t *)ie;
559 } else if (is_wps_oui((uint8_t *)ie)) {
560 scan_params->ie_list.wps = (uint8_t *)ie;
561 /* WCN IE should be a subset of WPS IE */
562 if (is_wcn_oui((uint8_t *)ie))
563 scan_params->ie_list.wcn = (uint8_t *)ie;
564 } else if (is_wme_param((uint8_t *)ie)) {
565 scan_params->ie_list.wmeparam = (uint8_t *)ie;
566 } else if (is_wme_info((uint8_t *)ie)) {
567 scan_params->ie_list.wmeinfo = (uint8_t *)ie;
568 } else if (is_atheros_oui((uint8_t *)ie)) {
569 scan_params->ie_list.athcaps = (uint8_t *)ie;
570 } else if (is_atheros_extcap_oui((uint8_t *)ie)) {
571 scan_params->ie_list.athextcaps = (uint8_t *)ie;
572 } else if (is_sfa_oui((uint8_t *)ie)) {
573 scan_params->ie_list.sfa = (uint8_t *)ie;
574 } else if (is_p2p_oui((uint8_t *)ie)) {
575 scan_params->ie_list.p2p = (uint8_t *)ie;
Bharat Bhushan Chakravarty145d3932017-03-20 12:52:16 -0700576 } else if (is_qca_son_oui((uint8_t *)ie,
577 QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530578 scan_params->ie_list.sonadv = (uint8_t *)ie;
579 } else if (is_ht_cap((uint8_t *)ie)) {
580 /* we only care if there isn't already an HT IE (ANA) */
Jeff Johnson82eb2122019-03-20 12:16:13 -0700581 if (!scan_params->ie_list.htcap) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530582 if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN +
583 sizeof(struct htcap_cmn_ie)))
584 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530585 scan_params->ie_list.htcap =
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530586 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
587 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530588 } else if (is_ht_info((uint8_t *)ie)) {
589 /* we only care if there isn't already an HT IE (ANA) */
Jeff Johnson82eb2122019-03-20 12:16:13 -0700590 if (!scan_params->ie_list.htinfo) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530591 if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN +
592 sizeof(struct wlan_ie_htinfo_cmn))
593 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530594 scan_params->ie_list.htinfo =
595 (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
596 ie)->hi_ie);
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530597 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530598 } else if (is_interop_vht((uint8_t *)ie) &&
Min Liub2183122019-05-17 13:29:00 +0800599 !(scan_params->ie_list.vhtcap)) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530600 uint8_t *vendor_ie = (uint8_t *)(ie);
601
602 if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
603 sizeof(struct wlan_ie_vhtcaps)) -
604 sizeof(struct ie_header)))
605 return QDF_STATUS_E_INVAL;
606 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET;
607 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) -
608 sizeof(struct ie_header))
609 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530610 /* location where Interop Vht Cap IE and VHT OP IE Present */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530611 scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) +
612 WLAN_VENDOR_VHTCAP_IE_OFFSET);
613 if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
614 sizeof(struct wlan_ie_vhtcaps)) -
Min Liub2183122019-05-17 13:29:00 +0800615 sizeof(struct ie_header))) {
616 if (ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET +
617 sizeof(struct wlan_ie_vhtop)) -
618 sizeof(struct ie_header)))
619 return QDF_STATUS_E_INVAL;
620 vendor_ie = ((uint8_t *)(ie)) +
621 WLAN_VENDOR_VHTOP_IE_OFFSET;
622 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) -
623 sizeof(struct ie_header)))
624 return QDF_STATUS_E_INVAL;
625 scan_params->ie_list.vhtop = (((uint8_t *)(ie)) +
626 WLAN_VENDOR_VHTOP_IE_OFFSET);
627 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530628 } else if (is_bwnss_oui((uint8_t *)ie)) {
629 /*
630 * Bandwidth-NSS map has sub-type & version.
631 * hence copy data just after version byte
632 */
633 scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
Abhishek Singh7b599032017-11-10 14:42:31 +0530634 } else if (is_mbo_oce_oui((uint8_t *)ie)) {
635 scan_params->ie_list.mbo_oce = (uint8_t *)ie;
Rathees kumar Chinannanb8f2d082018-07-04 15:51:51 +0530636 } else if (is_extender_oui((uint8_t *)ie)) {
637 scan_params->ie_list.extender = (uint8_t *)ie;
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +0530638 } else if (is_adaptive_11r_oui((uint8_t *)ie)) {
639 if ((ie->ie_len < OUI_LENGTH) ||
640 (ie->ie_len > MAX_ADAPTIVE_11R_IE_LEN))
641 return QDF_STATUS_E_INVAL;
642
643 scan_params->ie_list.adaptive_11r = (uint8_t *)ie +
644 sizeof(struct ie_header);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530645 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530646 return QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530647}
648
649static QDF_STATUS
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +0530650util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params,
651 uint8_t *chan_idx)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530652{
653 struct ie_header *ie, *sub_ie;
654 uint32_t ie_len, sub_ie_len;
655 QDF_STATUS status;
656
657 ie_len = util_scan_entry_ie_len(scan_params);
658 ie = (struct ie_header *)
659 util_scan_entry_ie_data(scan_params);
660
661 while (ie_len >= sizeof(struct ie_header)) {
662 ie_len -= sizeof(struct ie_header);
663
664 if (!ie->ie_len) {
665 ie += 1;
666 continue;
667 }
668
669 if (ie_len < ie->ie_len) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +0530670 scm_debug("Incomplete corrupted IE:%x",
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530671 ie->ie_id);
672 return QDF_STATUS_E_INVAL;
673 }
674
675 switch (ie->ie_id) {
676 case WLAN_ELEMID_SSID:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530677 if (ie->ie_len > (sizeof(struct ie_ssid) -
678 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530679 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530680 scan_params->ie_list.ssid = (uint8_t *)ie;
681 break;
682 case WLAN_ELEMID_RATES:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530683 if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530684 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530685 scan_params->ie_list.rates = (uint8_t *)ie;
686 break;
687 case WLAN_ELEMID_DSPARMS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530688 if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN)
689 return QDF_STATUS_E_INVAL;
Abhishek Singhc05285d2018-01-12 15:19:32 +0530690 scan_params->ie_list.ds_param = (uint8_t *)ie;
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +0530691 *chan_idx =
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530692 ((struct ds_ie *)ie)->cur_chan;
693 break;
694 case WLAN_ELEMID_TIM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530695 if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530696 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530697 scan_params->ie_list.tim = (uint8_t *)ie;
698 scan_params->dtim_period =
699 ((struct wlan_tim_ie *)ie)->tim_period;
700 break;
701 case WLAN_ELEMID_COUNTRY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530702 if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530703 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530704 scan_params->ie_list.country = (uint8_t *)ie;
705 break;
706 case WLAN_ELEMID_QBSS_LOAD:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530707 if (ie->ie_len != sizeof(struct qbss_load_ie) -
Jingxiang Gec5f0bd12018-06-13 18:00:02 +0800708 sizeof(struct ie_header)) {
709 /*
710 * Expected QBSS IE length is 5Bytes; For some
711 * old cisco AP, QBSS IE length is 4Bytes, which
712 * doesn't match with latest spec, So ignore
713 * QBSS IE in such case.
714 */
715 break;
716 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530717 scan_params->ie_list.qbssload = (uint8_t *)ie;
718 break;
719 case WLAN_ELEMID_CHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530720 if (ie->ie_len != WLAN_CSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530721 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530722 scan_params->ie_list.csa = (uint8_t *)ie;
723 break;
724 case WLAN_ELEMID_IBSSDFS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530725 if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530726 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530727 scan_params->ie_list.ibssdfs = (uint8_t *)ie;
728 break;
729 case WLAN_ELEMID_QUIET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530730 if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530731 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530732 scan_params->ie_list.quiet = (uint8_t *)ie;
733 break;
734 case WLAN_ELEMID_ERP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530735 if (ie->ie_len != (sizeof(struct erp_ie) -
736 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530737 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530738 scan_params->erp = ((struct erp_ie *)ie)->value;
739 break;
740 case WLAN_ELEMID_HTCAP_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530741 if (ie->ie_len != sizeof(struct htcap_cmn_ie))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530742 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530743 scan_params->ie_list.htcap =
744 (uint8_t *)&(((struct htcap_ie *)ie)->ie);
745 break;
746 case WLAN_ELEMID_RSN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530747 if (ie->ie_len < WLAN_RSN_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530748 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530749 scan_params->ie_list.rsn = (uint8_t *)ie;
750 break;
751 case WLAN_ELEMID_XRATES:
752 scan_params->ie_list.xrates = (uint8_t *)ie;
753 break;
754 case WLAN_ELEMID_EXTCHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530755 if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530756 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530757 scan_params->ie_list.xcsa = (uint8_t *)ie;
758 break;
759 case WLAN_ELEMID_SECCHANOFFSET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530760 if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530761 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530762 scan_params->ie_list.secchanoff = (uint8_t *)ie;
763 break;
764 case WLAN_ELEMID_HTINFO_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530765 if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530766 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530767 scan_params->ie_list.htinfo =
768 (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +0530769 *chan_idx =
770 ((struct wlan_ie_htinfo_cmn *)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530771 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
772 break;
773 case WLAN_ELEMID_WAPI:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530774 if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530775 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530776 scan_params->ie_list.wapi = (uint8_t *)ie;
777 break;
778 case WLAN_ELEMID_XCAPS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530779 if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530780 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530781 scan_params->ie_list.extcaps = (uint8_t *)ie;
782 break;
783 case WLAN_ELEMID_VHTCAP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530784 if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) -
785 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530786 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530787 scan_params->ie_list.vhtcap = (uint8_t *)ie;
788 break;
789 case WLAN_ELEMID_VHTOP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530790 if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) -
791 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530792 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530793 scan_params->ie_list.vhtop = (uint8_t *)ie;
794 break;
795 case WLAN_ELEMID_OP_MODE_NOTIFY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530796 if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530797 goto err;
wadesongd58eaf42018-05-23 11:30:02 +0800798 scan_params->ie_list.opmode = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530799 break;
800 case WLAN_ELEMID_MOBILITY_DOMAIN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530801 if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530802 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530803 scan_params->ie_list.mdie = (uint8_t *)ie;
804 break;
805 case WLAN_ELEMID_VENDOR:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530806 status = util_scan_parse_vendor_ie(scan_params,
807 ie);
808 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530809 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530810 break;
811 case WLAN_ELEMID_CHAN_SWITCH_WRAP:
812 scan_params->ie_list.cswrp = (uint8_t *)ie;
813 /* Go to next sub IE */
814 sub_ie = (struct ie_header *)
815 (((uint8_t *)ie) + sizeof(struct ie_header));
816 sub_ie_len = ie->ie_len;
817 status =
818 util_scan_parse_chan_switch_wrapper_ie(
819 scan_params, sub_ie, sub_ie_len);
820 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530821 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530822 }
823 break;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530824 case WLAN_ELEMID_FILS_INDICATION:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530825 if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530826 goto err;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530827 scan_params->ie_list.fils_indication = (uint8_t *)ie;
828 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530829 case WLAN_ELEMID_EXTN_ELEM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530830 status = util_scan_parse_extn_ie(scan_params, ie);
831 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530832 goto err_status;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530833 break;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530834 default:
835 break;
836 }
837
838 /* Consume info element */
839 ie_len -= ie->ie_len;
840 /* Go to next IE */
841 ie = (struct ie_header *)
842 (((uint8_t *) ie) +
843 sizeof(struct ie_header) +
844 ie->ie_len);
845 }
846
847 return QDF_STATUS_SUCCESS;
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530848
849err:
850 status = QDF_STATUS_E_INVAL;
851err_status:
852 scm_debug("failed to parse IE - id: %d, len: %d",
853 ie->ie_id, ie->ie_len);
854
855 return status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530856}
857
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530858/**
859 * util_scan_update_esp_data: update ESP params from beacon/probe response
860 * @esp_information: pointer to wlan_esp_information
861 * @scan_entry: new received entry
862 *
863 * The Estimated Service Parameters element is
864 * used by a AP to provide information to another STA which
865 * can then use the information as input to an algorithm to
866 * generate an estimate of throughput between the two STAs.
867 * The ESP Information List field contains from 1 to 4 ESP
868 * Information fields(each field 24 bits), each corresponding
869 * to an access category for which estimated service parameters
870 * information is provided.
871 *
872 * Return: None
873 */
874static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information,
875 struct scan_cache_entry *scan_entry)
876{
877
878 uint8_t *data;
879 int i = 0;
Sathyanarayanan0a000622017-10-10 17:17:28 +0530880 uint64_t total_elements;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530881 struct wlan_esp_info *esp_info;
882 struct wlan_esp_ie *esp_ie;
883
884 esp_ie = (struct wlan_esp_ie *)
885 util_scan_entry_esp_info(scan_entry);
886
887 total_elements = esp_ie->esp_len;
888 data = (uint8_t *)esp_ie + 3;
889 do_div(total_elements, ESP_INFORMATION_LIST_LENGTH);
890
891 if (total_elements > MAX_ESP_INFORMATION_FIELD) {
892 scm_err("No of Air time fractions are greater than supported");
893 return;
894 }
895
896 for (i = 0; i < total_elements; i++) {
897 esp_info = (struct wlan_esp_info *)data;
898 if (esp_info->access_category == ESP_AC_BK) {
899 qdf_mem_copy(&esp_information->esp_info_AC_BK,
900 data, 3);
901 data = data + ESP_INFORMATION_LIST_LENGTH;
902 continue;
903 }
904 if (esp_info->access_category == ESP_AC_BE) {
905 qdf_mem_copy(&esp_information->esp_info_AC_BE,
906 data, 3);
907 data = data + ESP_INFORMATION_LIST_LENGTH;
908 continue;
909 }
910 if (esp_info->access_category == ESP_AC_VI) {
911 qdf_mem_copy(&esp_information->esp_info_AC_VI,
912 data, 3);
913 data = data + ESP_INFORMATION_LIST_LENGTH;
914 continue;
915 }
916 if (esp_info->access_category == ESP_AC_VO) {
917 qdf_mem_copy(&esp_information->esp_info_AC_VO,
918 data, 3);
919 data = data + ESP_INFORMATION_LIST_LENGTH;
920 break;
921 }
922 }
923}
924
925/**
926 * util_scan_scm_update_bss_with_esp_dataa: calculate estimated air time
927 * fraction
928 * @scan_entry: new received entry
929 *
930 * This function process all Access category ESP params and provide
931 * best effort air time fraction.
932 * If best effort is not available, it will choose VI, VO and BK in sequence
933 *
934 */
935static void util_scan_scm_update_bss_with_esp_data(
936 struct scan_cache_entry *scan_entry)
937{
938 uint8_t air_time_fraction = 0;
939 struct wlan_esp_ie esp_information;
940
941 if (!scan_entry->ie_list.esp)
942 return;
943
944 util_scan_update_esp_data(&esp_information, scan_entry);
945
946 /*
947 * If the ESP metric is transmitting multiple airtime fractions, then
948 * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is
949 * the first one available
950 */
951 if (esp_information.esp_info_AC_BE.access_category
952 == ESP_AC_BE)
953 air_time_fraction =
954 esp_information.esp_info_AC_BE.
955 estimated_air_fraction;
956 else if (esp_information.esp_info_AC_VI.access_category
957 == ESP_AC_VI)
958 air_time_fraction =
959 esp_information.esp_info_AC_VI.
960 estimated_air_fraction;
961 else if (esp_information.esp_info_AC_VO.access_category
962 == ESP_AC_VO)
963 air_time_fraction =
964 esp_information.esp_info_AC_VO.
965 estimated_air_fraction;
966 else if (esp_information.esp_info_AC_BK.access_category
967 == ESP_AC_BK)
968 air_time_fraction =
969 esp_information.esp_info_AC_BK.
970 estimated_air_fraction;
971 scan_entry->air_time_fraction = air_time_fraction;
972}
973
974/**
975 * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP
976 * @scan_entry: new received entry
977 *
978 * Return: number of nss advertised by AP
979 */
980static int util_scan_scm_calc_nss_supported_by_ap(
981 struct scan_cache_entry *scan_params)
982{
983 struct htcap_cmn_ie *htcap;
984 struct wlan_ie_vhtcaps *vhtcaps;
985 uint8_t rx_mcs_map;
986
987 htcap = (struct htcap_cmn_ie *)
988 util_scan_entry_htcap(scan_params);
989 vhtcaps = (struct wlan_ie_vhtcaps *)
990 util_scan_entry_vhtcap(scan_params);
991 if (vhtcaps) {
992 rx_mcs_map = vhtcaps->rx_mcs_map;
993 if ((rx_mcs_map & 0xC0) != 0xC0)
994 return 4;
995
996 if ((rx_mcs_map & 0x30) != 0x30)
997 return 3;
998
999 if ((rx_mcs_map & 0x0C) != 0x0C)
1000 return 2;
1001 } else if (htcap) {
1002 if (htcap->mcsset[3])
1003 return 4;
1004
1005 if (htcap->mcsset[2])
1006 return 3;
1007
1008 if (htcap->mcsset[1])
1009 return 2;
1010
1011 }
1012 return 1;
1013}
1014
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +05301015#ifdef WLAN_DFS_CHAN_HIDDEN_SSID
1016QDF_STATUS
1017util_scan_add_hidden_ssid(struct wlan_objmgr_pdev *pdev, qdf_nbuf_t bcnbuf)
1018{
1019 struct wlan_frame_hdr *hdr;
1020 struct wlan_bcn_frame *bcn;
1021 struct wlan_scan_obj *scan_obj;
1022 struct wlan_ssid *conf_ssid;
1023 struct ie_header *ie;
1024 uint32_t frame_len = qdf_nbuf_len(bcnbuf);
1025 uint16_t bcn_ie_offset, ssid_ie_start_offset, ssid_ie_end_offset;
1026 uint16_t tmplen, ie_length;
1027 uint8_t *pbeacon, *tmp;
1028 bool set_ssid_flag = false;
1029 struct ie_ssid *ssid;
1030 uint8_t pdev_id;
1031
1032 if (!pdev) {
1033 scm_warn("pdev: 0x%pK is NULL", pdev);
1034 return QDF_STATUS_E_NULL_VALUE;
1035 }
1036 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1037 scan_obj = wlan_pdev_get_scan_obj(pdev);
Om Prakash Tripathi510a27c2019-03-01 11:53:18 +05301038 if (!scan_obj) {
1039 scm_warn("null scan_obj");
1040 return QDF_STATUS_E_NULL_VALUE;
1041 }
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +05301042
1043 conf_ssid = &scan_obj->pdev_info[pdev_id].conf_ssid;
1044
1045 hdr = (struct wlan_frame_hdr *)qdf_nbuf_data(bcnbuf);
1046
1047 /* received bssid does not match configured bssid */
1048 if (qdf_mem_cmp(hdr->i_addr3, scan_obj->pdev_info[pdev_id].conf_bssid,
1049 QDF_MAC_ADDR_SIZE) ||
1050 conf_ssid->length == 0) {
1051 return QDF_STATUS_SUCCESS;
1052 }
1053
1054 bcn = (struct wlan_bcn_frame *)(qdf_nbuf_data(bcnbuf) + sizeof(*hdr));
1055 pbeacon = (uint8_t *)bcn;
1056
1057 ie = (struct ie_header *)(pbeacon +
1058 offsetof(struct wlan_bcn_frame, ie));
1059
1060 bcn_ie_offset = offsetof(struct wlan_bcn_frame, ie);
1061 ie_length = (uint16_t)(frame_len - sizeof(*hdr) -
1062 bcn_ie_offset);
1063
1064 while (ie_length >= sizeof(struct ie_header)) {
1065 ie_length -= sizeof(struct ie_header);
1066
1067 bcn_ie_offset += sizeof(struct ie_header);
1068
1069 if (ie_length < ie->ie_len) {
1070 scm_debug("Incomplete corrupted IE:%x", ie->ie_id);
1071 return QDF_STATUS_E_INVAL;
1072 }
1073 if (ie->ie_id == WLAN_ELEMID_SSID) {
1074 if (ie->ie_len > (sizeof(struct ie_ssid) -
1075 sizeof(struct ie_header))) {
1076 return QDF_STATUS_E_INVAL;
1077 }
1078 ssid = (struct ie_ssid *)ie;
1079 if (util_scan_is_hidden_ssid(ssid)) {
1080 set_ssid_flag = true;
1081 ssid_ie_start_offset = bcn_ie_offset -
1082 sizeof(struct ie_header);
1083 ssid_ie_end_offset = bcn_ie_offset +
1084 ie->ie_len;
1085 }
1086 }
1087 if (ie->ie_len == 0) {
1088 ie += 1; /* next IE */
1089 continue;
1090 }
1091 if (ie->ie_id == WLAN_ELEMID_VENDOR &&
1092 is_wps_oui((uint8_t *)ie)) {
1093 set_ssid_flag = false;
1094 break;
1095 }
1096 /* Consume info element */
1097 ie_length -= ie->ie_len;
1098 /* Go to next IE */
1099 ie = (struct ie_header *)(((uint8_t *)ie) +
1100 sizeof(struct ie_header) +
1101 ie->ie_len);
1102 }
1103
1104 if (set_ssid_flag) {
1105 /* Hidden SSID if the Length is 0 */
1106 if (!ssid->ssid_len) {
1107 /* increase the taillength by length of ssid */
1108 if (qdf_nbuf_put_tail(bcnbuf,
1109 conf_ssid->length) == NULL) {
1110 scm_debug("No enough tailroom");
1111 return QDF_STATUS_E_NOMEM;
1112 }
1113 /* length of the buffer to be copied */
1114 tmplen = frame_len -
1115 sizeof(*hdr) - ssid_ie_end_offset;
1116 /*
1117 * tmp memory to copy the beacon info
1118 * after ssid ie.
1119 */
1120 tmp = qdf_mem_malloc(tmplen * sizeof(u_int8_t));
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +05301121 if (!tmp)
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +05301122 return QDF_STATUS_E_NOMEM;
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +05301123
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +05301124 /* Copy beacon data after ssid ie to tmp */
1125 qdf_nbuf_copy_bits(bcnbuf, (sizeof(*hdr) +
1126 ssid_ie_end_offset), tmplen, tmp);
1127 /* Add ssid length */
1128 *(pbeacon + (ssid_ie_start_offset + 1))
1129 = conf_ssid->length;
1130 /* Insert the SSID string */
1131 qdf_mem_copy((pbeacon + ssid_ie_end_offset),
1132 conf_ssid->ssid, conf_ssid->length);
1133 /* Copy rest of the beacon data */
1134 qdf_mem_copy((pbeacon + ssid_ie_end_offset +
1135 conf_ssid->length), tmp, tmplen);
1136 qdf_mem_free(tmp);
1137
1138 /* Hidden ssid with all 0's */
1139 } else if (ssid->ssid_len == conf_ssid->length) {
1140 /* Insert the SSID string */
1141 qdf_mem_copy((pbeacon + ssid_ie_start_offset +
1142 sizeof(struct ie_header)),
1143 conf_ssid->ssid, conf_ssid->length);
1144 } else {
1145 scm_debug("mismatch in hidden ssid length");
1146 return QDF_STATUS_E_INVAL;
1147 }
1148 }
1149 return QDF_STATUS_SUCCESS;
1150}
1151#endif /* WLAN_DFS_CHAN_HIDDEN_SSID */
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +05301152
1153#ifdef WLAN_ADAPTIVE_11R
1154/**
1155 * scm_fill_adaptive_11r_cap() - Check if the AP supports adaptive 11r
1156 * @scan_entry: Pointer to the scan entry
1157 *
1158 * Return: true if adaptive 11r is advertised else false
1159 */
1160static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
1161{
1162 uint8_t *ie;
1163 uint8_t data;
1164 bool adaptive_11r;
1165
1166 ie = util_scan_entry_adaptive_11r(scan_entry);
1167 if (!ie)
1168 return;
1169
1170 data = *(ie + OUI_LENGTH);
1171 adaptive_11r = (data & 0x1) ? true : false;
1172
1173 scan_entry->adaptive_11r_ap = adaptive_11r;
1174}
1175#else
1176static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
1177{
1178 scan_entry->adaptive_11r_ap = false;
1179}
1180#endif
1181
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001182static QDF_STATUS
1183util_scan_gen_scan_entry(struct wlan_objmgr_pdev *pdev,
1184 uint8_t *frame, qdf_size_t frame_len,
1185 uint32_t frm_subtype,
1186 struct mgmt_rx_event_params *rx_param,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001187 struct scan_mbssid_info *mbssid_info,
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001188 qdf_list_t *scan_list)
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301189{
1190 struct wlan_frame_hdr *hdr;
1191 struct wlan_bcn_frame *bcn;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001192 QDF_STATUS status = QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301193 struct ie_ssid *ssid;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001194 struct scan_cache_entry *scan_entry;
Abhishek Singh7b599032017-11-10 14:42:31 +05301195 struct qbss_load_ie *qbss_load;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001196 struct scan_cache_node *scan_node;
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +05301197 uint8_t i, chan_idx = 0;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001198
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301199 scan_entry = qdf_mem_malloc_atomic(sizeof(*scan_entry));
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301200 if (!scan_entry) {
1201 scm_err("failed to allocate memory for scan_entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001202 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301203 }
1204 scan_entry->raw_frame.ptr =
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301205 qdf_mem_malloc_atomic(frame_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301206 if (!scan_entry->raw_frame.ptr) {
1207 scm_err("failed to allocate memory for frame");
1208 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001209 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301210 }
1211
1212 bcn = (struct wlan_bcn_frame *)
1213 (frame + sizeof(*hdr));
1214 hdr = (struct wlan_frame_hdr *)frame;
1215
gaurank kathpalia26f98332018-01-29 18:09:06 +05301216 /* update timestamp in nanoseconds needed by kernel layers */
Arif Hussain6fcc7902018-03-22 12:33:12 -07001217 scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns();
gaurank kathpalia26f98332018-01-29 18:09:06 +05301218
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301219 scan_entry->frm_subtype = frm_subtype;
1220 qdf_mem_copy(scan_entry->bssid.bytes,
1221 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1222 /* Scr addr */
1223 qdf_mem_copy(scan_entry->mac_addr.bytes,
1224 hdr->i_addr2, QDF_MAC_ADDR_SIZE);
1225 scan_entry->seq_num =
1226 (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
1227
Shashikala Prabhua477ec22019-10-22 09:41:10 +05301228 scan_entry->snr = rx_param->snr;
1229 scan_entry->avg_snr = WLAN_SNR_IN(scan_entry->snr);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301230 scan_entry->rssi_raw = rx_param->rssi;
Om Prakash Tripathi6af738b2017-08-22 15:46:38 +05301231 scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301232 scan_entry->tsf_delta = rx_param->tsf_delta;
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +05301233 scan_entry->pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301234
gaurank kathpalia26f98332018-01-29 18:09:06 +05301235 /* Copy per chain rssi to scan entry */
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301236 qdf_mem_copy(scan_entry->per_chain_rssi, rx_param->rssi_ctl,
gaurank kathpalia26f98332018-01-29 18:09:06 +05301237 WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
1238
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301239 if (!wlan_psoc_nif_fw_ext_cap_get(wlan_pdev_get_psoc(pdev),
1240 WLAN_SOC_CEXT_HW_DB2DBM)) {
1241 for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++) {
1242 if (scan_entry->per_chain_rssi[i] !=
1243 WLAN_INVALID_PER_CHAIN_SNR)
1244 scan_entry->per_chain_rssi[i] +=
1245 WLAN_NOISE_FLOOR_DBM_DEFAULT;
1246 else
1247 scan_entry->per_chain_rssi[i] =
1248 WLAN_INVALID_PER_CHAIN_RSSI;
1249 }
1250 }
1251
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301252 /* store jiffies */
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001253 scan_entry->rrm_parent_tsf = (uint32_t)qdf_system_ticks();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301254
1255 scan_entry->bcn_int = le16toh(bcn->beacon_interval);
1256
1257 /*
1258 * In case if the beacon dosnt have
1259 * valid beacon interval falback to def
1260 */
1261 if (!scan_entry->bcn_int)
1262 scan_entry->bcn_int = 100;
1263 scan_entry->cap_info.value = le16toh(bcn->capability.value);
1264 qdf_mem_copy(scan_entry->tsf_info.data,
1265 bcn->timestamp, 8);
1266 scan_entry->erp = ERP_NON_ERP_PRESENT;
1267
Om Prakash Tripathicdcbb392017-04-18 18:51:20 +05301268 scan_entry->scan_entry_time =
1269 qdf_mc_timer_get_system_time();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301270
1271 scan_entry->raw_frame.len = frame_len;
1272 qdf_mem_copy(scan_entry->raw_frame.ptr,
1273 frame, frame_len);
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +05301274 status = util_scan_populate_bcn_ie_list(scan_entry, &chan_idx);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301275 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +05301276 scm_debug("failed to parse beacon IE");
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301277 qdf_mem_free(scan_entry->raw_frame.ptr);
1278 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001279 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301280 }
1281
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301282 ssid = (struct ie_ssid *)
1283 scan_entry->ie_list.ssid;
1284
1285 if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
1286 qdf_mem_free(scan_entry->raw_frame.ptr);
1287 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001288 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301289 }
1290
1291 if (scan_entry->ie_list.p2p)
1292 scan_entry->is_p2p = true;
1293
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +05301294 if (chan_idx) {
1295 uint8_t band_mask = BIT(wlan_reg_freq_to_band(
1296 rx_param->chan_freq));
1297
1298 scan_entry->channel.chan_freq =
1299 wlan_reg_chan_band_to_freq(
1300 pdev, chan_idx,
1301 band_mask);
1302 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301303 /* If no channel info is present in beacon use meta channel */
Ashish Kumar Dhanotiya75ccbd42019-08-29 19:17:44 +05301304 if (!scan_entry->channel.chan_freq) {
1305 scan_entry->channel.chan_freq = rx_param->chan_freq;
1306 } else if (rx_param->chan_freq !=
1307 scan_entry->channel.chan_freq) {
1308 if (!wlan_reg_is_49ghz_freq(scan_entry->channel.chan_freq))
Shashikala Prabhu7edbb052018-04-12 09:55:25 +05301309 scan_entry->channel_mismatch = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301310 }
1311
1312 if (util_scan_is_hidden_ssid(ssid)) {
1313 scan_entry->ie_list.ssid = NULL;
Abhishek Singh7062efa2019-03-05 15:37:07 +05301314 scan_entry->is_hidden_ssid = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301315 } else {
1316 qdf_mem_copy(scan_entry->ssid.ssid,
Harprit Chhabadaab6c10d2018-10-31 10:52:34 -07001317 ssid->ssid, ssid->ssid_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301318 scan_entry->ssid.length = ssid->ssid_len;
1319 scan_entry->hidden_ssid_timestamp =
1320 scan_entry->scan_entry_time;
1321 }
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001322 qdf_mem_copy(&scan_entry->mbssid_info, mbssid_info,
1323 sizeof(scan_entry->mbssid_info));
Abhishek Ambure986f5c92019-10-21 14:52:59 +05301324
1325 scan_entry->phy_mode = util_scan_get_phymode(scan_entry);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301326
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301327 scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry);
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +05301328 scm_fill_adaptive_11r_cap(scan_entry);
1329
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301330 util_scan_scm_update_bss_with_esp_data(scan_entry);
Abhishek Singh7b599032017-11-10 14:42:31 +05301331 qbss_load = (struct qbss_load_ie *)
1332 util_scan_entry_qbssload(scan_entry);
1333 if (qbss_load)
1334 scan_entry->qbss_chan_load = qbss_load->qbss_chan_load;
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301335
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301336 scan_node = qdf_mem_malloc_atomic(sizeof(*scan_node));
Sandeep Puligillac6764592017-12-05 21:01:52 -08001337 if (!scan_node) {
Om Prakash Tripathi52402552018-02-21 16:31:49 +05301338 qdf_mem_free(scan_entry->raw_frame.ptr);
Sandeep Puligillac6764592017-12-05 21:01:52 -08001339 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001340 return QDF_STATUS_E_FAILURE;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001341 }
1342
1343 scan_node->entry = scan_entry;
1344 qdf_list_insert_front(scan_list, &scan_node->node);
1345
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001346 return status;
1347}
1348
1349/**
1350 * util_scan_find_ie() - find information element
1351 * @eid: element id
1352 * @ies: pointer consisting of IEs
1353 * @len: IE length
1354 *
1355 * Return: NULL if the element ID is not found or
1356 * a pointer to the first byte of the requested
1357 * element
1358 */
1359static uint8_t *util_scan_find_ie(uint8_t eid, uint8_t *ies,
1360 int32_t len)
1361{
1362 while (len >= 2 && len >= ies[1] + 2) {
1363 if (ies[0] == eid)
1364 return ies;
1365 len -= ies[1] + 2;
1366 ies += ies[1] + 2;
1367 }
1368
1369 return NULL;
1370}
1371
1372#ifdef WLAN_FEATURE_MBSSID
1373static void util_gen_new_bssid(uint8_t *bssid, uint8_t max_bssid,
1374 uint8_t mbssid_index,
1375 uint8_t *new_bssid_addr)
1376{
1377 uint64_t bssid_tmp = 0, new_bssid = 0;
1378 uint64_t lsb_n;
1379 int i;
1380
1381 for (i = 0; i < QDF_MAC_ADDR_SIZE; i++)
1382 bssid_tmp = bssid_tmp << 8 | bssid[i];
1383
1384 lsb_n = bssid_tmp & ((1 << max_bssid) - 1);
1385 new_bssid = bssid_tmp;
1386 new_bssid &= ~((1 << max_bssid) - 1);
Gurumoorthi Gnanasambandhanf069fcc2019-10-17 17:33:22 +05301387 new_bssid |= qdf_do_div((lsb_n + mbssid_index), (1 << max_bssid));
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001388
1389 for (i = QDF_MAC_ADDR_SIZE - 1; i >= 0; i--) {
1390 new_bssid_addr[i] = new_bssid & 0xff;
1391 new_bssid = new_bssid >> 8;
1392 }
1393}
1394
1395static uint32_t util_gen_new_ie(uint8_t *ie, uint32_t ielen,
1396 uint8_t *subelement,
1397 size_t subie_len, uint8_t *new_ie)
1398{
1399 uint8_t *pos, *tmp;
1400 const uint8_t *tmp_old, *tmp_new;
1401 uint8_t *sub_copy;
1402
1403 /* copy subelement as we need to change its content to
1404 * mark an ie after it is processed.
1405 */
1406 sub_copy = qdf_mem_malloc(subie_len);
1407 if (!sub_copy)
1408 return 0;
1409 qdf_mem_copy(sub_copy, subelement, subie_len);
1410
1411 pos = &new_ie[0];
1412
1413 /* new ssid */
1414 tmp_new = util_scan_find_ie(WLAN_ELEMID_SSID, sub_copy, subie_len);
1415 if (tmp_new) {
1416 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1417 pos += (tmp_new[1] + 2);
1418 }
1419
1420 /* go through IEs in ie (skip SSID) and subelement,
1421 * merge them into new_ie
1422 */
1423 tmp_old = util_scan_find_ie(WLAN_ELEMID_SSID, ie, ielen);
1424 tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie;
1425
1426 while (tmp_old + tmp_old[1] + 2 - ie <= ielen) {
1427 if (tmp_old[0] == 0) {
1428 tmp_old++;
1429 continue;
1430 }
1431
1432 tmp = (uint8_t *)util_scan_find_ie(tmp_old[0], sub_copy,
1433 subie_len);
1434 if (!tmp) {
1435 /* ie in old ie but not in subelement */
1436 if (tmp_old[0] != WLAN_ELEMID_MULTIPLE_BSSID) {
1437 qdf_mem_copy(pos, tmp_old, tmp_old[1] + 2);
1438 pos += tmp_old[1] + 2;
1439 }
1440 } else {
1441 /* ie in transmitting ie also in subelement,
1442 * copy from subelement and flag the ie in subelement
1443 * as copied (by setting eid field to 0xff). For
1444 * vendor ie, compare OUI + type + subType to
1445 * determine if they are the same ie.
1446 */
1447 if (tmp_old[0] == WLAN_ELEMID_VENDOR) {
1448 if (!qdf_mem_cmp(tmp_old + 2, tmp + 2, 5)) {
1449 /* same vendor ie, copy from
1450 * subelement
1451 */
1452 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1453 pos += tmp[1] + 2;
1454 tmp[0] = 0xff;
1455 } else {
1456 qdf_mem_copy(pos, tmp_old,
1457 tmp_old[1] + 2);
1458 pos += tmp_old[1] + 2;
1459 }
1460 } else {
1461 /* copy ie from subelement into new ie */
1462 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1463 pos += tmp[1] + 2;
1464 tmp[0] = 0xff;
1465 }
1466 }
1467
1468 if (tmp_old + tmp_old[1] + 2 - ie == ielen)
1469 break;
1470
1471 tmp_old += tmp_old[1] + 2;
1472 }
1473
1474 /* go through subelement again to check if there is any ie not
1475 * copied to new ie, skip ssid, capability, bssid-index ie
1476 */
1477 tmp_new = sub_copy;
1478 while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
1479 if (!(tmp_new[0] == WLAN_ELEMID_NONTX_BSSID_CAP ||
1480 tmp_new[0] == WLAN_ELEMID_SSID ||
1481 tmp_new[0] == WLAN_ELEMID_MULTI_BSSID_IDX ||
1482 tmp_new[0] == 0xff)) {
1483 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1484 pos += tmp_new[1] + 2;
1485 }
1486 if (tmp_new + tmp_new[1] + 2 - sub_copy == subie_len)
1487 break;
1488 tmp_new += tmp_new[1] + 2;
1489 }
1490
1491 qdf_mem_free(sub_copy);
1492 return pos - new_ie;
1493}
1494
1495static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1496 uint8_t *frame, qdf_size_t frame_len,
1497 uint32_t frm_subtype,
1498 struct mgmt_rx_event_params *rx_param,
1499 qdf_list_t *scan_list)
1500{
1501 struct wlan_bcn_frame *bcn;
1502 struct wlan_frame_hdr *hdr;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001503 struct scan_mbssid_info mbssid_info;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001504 QDF_STATUS status;
1505 uint8_t *pos, *subelement, *mbssid_end_pos;
1506 uint8_t *tmp, *mbssid_index_ie;
1507 uint32_t subie_len, new_ie_len;
1508 uint8_t new_bssid[QDF_MAC_ADDR_SIZE], bssid[QDF_MAC_ADDR_SIZE];
1509 uint8_t *new_ie;
1510 uint8_t *ie, *new_frame = NULL;
1511 uint64_t ielen, new_frame_len;
1512
1513 hdr = (struct wlan_frame_hdr *)frame;
1514 bcn = (struct wlan_bcn_frame *)(frame + sizeof(struct wlan_frame_hdr));
1515 ie = (uint8_t *)&bcn->ie;
1516 ielen = (uint16_t)(frame_len -
1517 sizeof(struct wlan_frame_hdr) -
1518 offsetof(struct wlan_bcn_frame, ie));
1519 qdf_mem_copy(bssid, hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1520
1521 if (!util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, ie, ielen))
1522 return QDF_STATUS_E_FAILURE;
1523
1524 pos = ie;
1525
1526 new_ie = qdf_mem_malloc(MAX_IE_LEN);
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +05301527 if (!new_ie)
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001528 return QDF_STATUS_E_NOMEM;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001529
1530 while (pos < ie + ielen + 2) {
1531 tmp = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, pos,
1532 ielen - (pos - ie));
1533 if (!tmp)
1534 break;
1535
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001536 mbssid_info.profile_count = 1 << tmp[2];
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001537 mbssid_end_pos = tmp + tmp[1] + 2;
1538 /* Skip Element ID, Len, MaxBSSID Indicator */
1539 if (tmp[1] < 4)
1540 break;
1541 for (subelement = tmp + 3; subelement < mbssid_end_pos - 1;
1542 subelement += 2 + subelement[1]) {
1543 subie_len = subelement[1];
1544 if (mbssid_end_pos - subelement < 2 + subie_len)
1545 break;
1546 if (subelement[0] != 0 || subelement[1] < 4) {
1547 /* not a valid BSS profile */
1548 continue;
1549 }
1550
1551 if (subelement[2] != WLAN_ELEMID_NONTX_BSSID_CAP ||
1552 subelement[3] != 2) {
1553 /* The first element within the Nontransmitted
1554 * BSSID Profile is not the Nontransmitted
1555 * BSSID Capability element.
1556 */
1557 continue;
1558 }
1559
1560 /* found a Nontransmitted BSSID Profile */
1561 mbssid_index_ie =
1562 util_scan_find_ie(WLAN_ELEMID_MULTI_BSSID_IDX,
1563 subelement + 2, subie_len);
1564 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 ||
1565 mbssid_index_ie[2] == 0) {
1566 /* No valid Multiple BSSID-Index element */
1567 continue;
1568 }
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001569 qdf_mem_copy(&mbssid_info.trans_bssid, bssid,
1570 QDF_MAC_ADDR_SIZE);
1571 mbssid_info.profile_num = mbssid_index_ie[2];
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001572 util_gen_new_bssid(bssid, tmp[2], mbssid_index_ie[2],
1573 new_bssid);
1574 new_ie_len = util_gen_new_ie(ie, ielen, subelement + 2,
1575 subie_len, new_ie);
1576 if (!new_ie_len)
1577 continue;
1578
1579 new_frame_len = frame_len - ielen + new_ie_len;
1580 new_frame = qdf_mem_malloc(new_frame_len);
1581 if (!new_frame) {
1582 qdf_mem_free(new_ie);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001583 return QDF_STATUS_E_NOMEM;
1584 }
1585
1586 /*
1587 * Copy the header(24byte), timestamp(8 byte),
1588 * beaconinterval(2byte) and capability(2byte)
1589 */
1590 qdf_mem_copy(new_frame, frame, 36);
1591 /* Copy the new ie generated from MBSSID profile*/
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001592 hdr = (struct wlan_frame_hdr *)new_frame;
1593 qdf_mem_copy(hdr->i_addr2, new_bssid,
1594 QDF_MAC_ADDR_SIZE);
1595 qdf_mem_copy(hdr->i_addr3, new_bssid,
1596 QDF_MAC_ADDR_SIZE);
1597 /* Copy the new ie generated from MBSSID profile*/
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001598 qdf_mem_copy(new_frame +
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001599 offsetof(struct wlan_bcn_frame, ie) +
1600 sizeof(struct wlan_frame_hdr),
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001601 new_ie, new_ie_len);
1602 status = util_scan_gen_scan_entry(pdev, new_frame,
1603 new_frame_len,
1604 frm_subtype,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001605 rx_param,
1606 &mbssid_info,
1607 scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001608 if (QDF_IS_STATUS_ERROR(status)) {
1609 qdf_mem_free(new_frame);
1610 scm_err("failed to generate a scan entry");
1611 break;
1612 }
1613 /* scan entry makes its own copy so free the frame*/
1614 qdf_mem_free(new_frame);
1615 }
1616
1617 pos = mbssid_end_pos;
1618 }
1619 qdf_mem_free(new_ie);
1620
1621 return QDF_STATUS_SUCCESS;
1622}
1623#else
1624static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1625 uint8_t *frame, qdf_size_t frame_len,
1626 uint32_t frm_subtype,
1627 struct mgmt_rx_event_params *rx_param,
1628 qdf_list_t *scan_list)
1629{
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001630 return QDF_STATUS_SUCCESS;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001631}
1632#endif
1633
1634static QDF_STATUS
1635util_scan_parse_beacon_frame(struct wlan_objmgr_pdev *pdev,
1636 uint8_t *frame,
1637 qdf_size_t frame_len,
1638 uint32_t frm_subtype,
1639 struct mgmt_rx_event_params *rx_param,
1640 qdf_list_t *scan_list)
1641{
1642 struct wlan_bcn_frame *bcn;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001643 struct wlan_frame_hdr *hdr;
1644 uint8_t *mbssid_ie = NULL;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001645 uint32_t ie_len = 0;
1646 QDF_STATUS status;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001647 struct scan_mbssid_info mbssid_info = { 0 };
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001648
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001649 hdr = (struct wlan_frame_hdr *)frame;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001650 bcn = (struct wlan_bcn_frame *)
1651 (frame + sizeof(struct wlan_frame_hdr));
1652 ie_len = (uint16_t)(frame_len -
1653 sizeof(struct wlan_frame_hdr) -
1654 offsetof(struct wlan_bcn_frame, ie));
1655
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001656 mbssid_ie = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID,
1657 (uint8_t *)&bcn->ie, ie_len);
1658 if (mbssid_ie) {
1659 qdf_mem_copy(&mbssid_info.trans_bssid,
1660 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1661 mbssid_info.profile_count = 1 << mbssid_ie[2];
1662 }
1663
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001664 status = util_scan_gen_scan_entry(pdev, frame, frame_len,
1665 frm_subtype, rx_param,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001666 &mbssid_info,
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001667 scan_list);
1668
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001669 /*
1670 * IF MBSSID IE is present in the beacon then
1671 * scan component will create a new entry for
1672 * each BSSID found in the MBSSID
1673 */
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001674 if (mbssid_ie)
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301675 status = util_scan_parse_mbssid(pdev, frame, frame_len,
1676 frm_subtype, rx_param,
1677 scan_list);
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001678
Om Prakash Tripathi0e3c5412019-04-08 15:01:34 +05301679 if (QDF_IS_STATUS_ERROR(status))
1680 scm_debug_rl("Failed to create a scan entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001681
1682 return status;
1683}
1684
1685qdf_list_t *
1686util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame,
1687 qdf_size_t frame_len, uint32_t frm_subtype,
1688 struct mgmt_rx_event_params *rx_param)
1689{
1690 qdf_list_t *scan_list;
1691 QDF_STATUS status;
1692
1693 scan_list = qdf_mem_malloc_atomic(sizeof(*scan_list));
1694 if (!scan_list) {
1695 scm_err("failed to allocate scan_list");
1696 return NULL;
1697 }
1698 qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE);
1699
1700 status = util_scan_parse_beacon_frame(pdev, frame, frame_len,
1701 frm_subtype, rx_param,
1702 scan_list);
1703 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301704 ucfg_scan_purge_results(scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001705 return NULL;
1706 }
1707
Sandeep Puligillac6764592017-12-05 21:01:52 -08001708 return scan_list;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301709}
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301710
1711QDF_STATUS
1712util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev,
1713 struct scan_cache_entry *scan_entry)
1714{
1715
1716 if (!pdev || !scan_entry) {
Jeff Johnson878533e2017-09-18 10:07:54 -07001717 scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry);
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301718 return QDF_STATUS_E_INVAL;
1719 }
1720
1721 return scm_update_scan_mlme_info(pdev, scan_entry);
1722}
Sandeep Puligillaf57464c2017-11-16 23:31:52 -08001723
1724bool util_is_scan_completed(struct scan_event *event, bool *success)
1725{
1726 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) ||
1727 (event->type == SCAN_EVENT_TYPE_DEQUEUED) ||
1728 (event->type == SCAN_EVENT_TYPE_START_FAILED)) {
1729 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
1730 (event->reason == SCAN_REASON_COMPLETED))
1731 *success = true;
1732 else
1733 *success = false;
1734
1735 return true;
1736 }
1737
1738 *success = false;
1739 return false;
1740}
1741