blob: fbeec7590e1ca1c503957b11fc16eb09827a5b8d [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 &&
144 (entry1->channel.chan_idx ==
145 entry2->channel.chan_idx)) {
146 /*
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}
183static enum wlan_phymode
184util_scan_get_phymode_5g(struct scan_cache_entry *scan_params)
185{
186 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
187 uint16_t ht_cap = 0;
188 struct htcap_cmn_ie *htcap;
189 struct wlan_ie_htinfo_cmn *htinfo;
190 struct wlan_ie_vhtop *vhtop;
191
192 htcap = (struct htcap_cmn_ie *)
193 util_scan_entry_htcap(scan_params);
194 htinfo = (struct wlan_ie_htinfo_cmn *)
195 util_scan_entry_htinfo(scan_params);
196 vhtop = (struct wlan_ie_vhtop *)
197 util_scan_entry_vhtop(scan_params);
198
199 if (!(htcap && htinfo))
200 return WLAN_PHYMODE_11A;
201
202 if (htcap)
203 ht_cap = le16toh(htcap->hc_cap);
204
205 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
206 switch (vhtop->vht_op_chwidth) {
207 case WLAN_VHTOP_CHWIDTH_2040:
Abhishek Singhf3f97972019-09-18 12:13:46 +0530208 if (ht_cap & WLAN_HTCAP_C_CHWIDTH40)
209 phymode = WLAN_PHYMODE_11AC_VHT40;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530210 else
211 phymode = WLAN_PHYMODE_11AC_VHT20;
212 break;
213 case WLAN_VHTOP_CHWIDTH_80:
214 if (WLAN_IS_REVSIG_VHT80_80(vhtop))
215 phymode = WLAN_PHYMODE_11AC_VHT80_80;
216 else if (WLAN_IS_REVSIG_VHT160(vhtop))
217 phymode = WLAN_PHYMODE_11AC_VHT160;
218 else
219 phymode = WLAN_PHYMODE_11AC_VHT80;
220 break;
221 case WLAN_VHTOP_CHWIDTH_160:
222 phymode = WLAN_PHYMODE_11AC_VHT160;
223 break;
224 case WLAN_VHTOP_CHWIDTH_80_80:
225 phymode = WLAN_PHYMODE_11AC_VHT80_80;
226 break;
227 default:
228 scm_err("bad channel: %d",
229 vhtop->vht_op_chwidth);
Abhishek Singhf3f97972019-09-18 12:13:46 +0530230 phymode = WLAN_PHYMODE_11AC_VHT20;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530231 break;
232 }
Abhishek Singhf3f97972019-09-18 12:13:46 +0530233 } else if (ht_cap & WLAN_HTCAP_C_CHWIDTH40) {
234 phymode = WLAN_PHYMODE_11NA_HT40;
235 } else {
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530236 phymode = WLAN_PHYMODE_11NA_HT20;
Abhishek Singhf3f97972019-09-18 12:13:46 +0530237 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530238
239 return phymode;
240}
241
242static enum wlan_phymode
243util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
244{
245 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
246 uint16_t ht_cap = 0;
247 struct htcap_cmn_ie *htcap;
248 struct wlan_ie_htinfo_cmn *htinfo;
249 struct wlan_ie_vhtop *vhtop;
250
251 htcap = (struct htcap_cmn_ie *)
252 util_scan_entry_htcap(scan_params);
253 htinfo = (struct wlan_ie_htinfo_cmn *)
254 util_scan_entry_htinfo(scan_params);
255 vhtop = (struct wlan_ie_vhtop *)
256 util_scan_entry_vhtop(scan_params);
257
258 if (htcap)
259 ht_cap = le16toh(htcap->hc_cap);
260
261 if (htcap && htinfo) {
262 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
263 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
264 phymode = WLAN_PHYMODE_11NG_HT40PLUS;
265 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
266 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
267 phymode = WLAN_PHYMODE_11NG_HT40MINUS;
268 else
269 phymode = WLAN_PHYMODE_11NG_HT20;
270 } else if (util_scan_entry_xrates(scan_params)) {
271 /* only 11G stations will have more than 8 rates */
272 phymode = WLAN_PHYMODE_11G;
273 } else {
274 /* Some mischievous g-only APs do not set extended rates */
275 if (util_scan_entry_rates(scan_params)) {
276 if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
277 scan_params->ie_list.rates[1]))
278 phymode = WLAN_PHYMODE_11G;
279 else
280 phymode = WLAN_PHYMODE_11B;
281 } else {
282 phymode = WLAN_PHYMODE_11B;
283 }
284 }
285
Abhishek Singhf3f97972019-09-18 12:13:46 +0530286 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
287 switch (vhtop->vht_op_chwidth) {
288 case WLAN_VHTOP_CHWIDTH_2040:
289 if (phymode == WLAN_PHYMODE_11NG_HT40PLUS)
290 phymode = WLAN_PHYMODE_11AC_VHT40PLUS_2G;
291 else if (phymode == WLAN_PHYMODE_11NG_HT40MINUS)
292 phymode = WLAN_PHYMODE_11AC_VHT40MINUS_2G;
293 else
294 phymode = WLAN_PHYMODE_11AC_VHT20_2G;
295
296 break;
297 default:
298 scm_info("bad vht_op_chwidth: %d",
299 vhtop->vht_op_chwidth);
300 phymode = WLAN_PHYMODE_11AC_VHT20_2G;
301 break;
302 }
303 }
304
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530305 return phymode;
306}
307
308static QDF_STATUS
309util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
310 struct ie_header *sub_ie, qdf_size_t sub_ie_len)
311{
312 /* Walk through to check nothing is malformed */
313 while (sub_ie_len >= sizeof(struct ie_header)) {
314 /* At least one more header is present */
315 sub_ie_len -= sizeof(struct ie_header);
316
317 if (sub_ie->ie_len == 0) {
318 sub_ie += 1;
319 continue;
320 }
321 if (sub_ie_len < sub_ie->ie_len) {
322 scm_err("Incomplete corrupted IE:%x",
323 WLAN_ELEMID_CHAN_SWITCH_WRAP);
324 return QDF_STATUS_E_INVAL;
325 }
326 switch (sub_ie->ie_id) {
327 case WLAN_ELEMID_COUNTRY:
328 scan_params->ie_list.country = (uint8_t *)sub_ie;
329 break;
330 case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
331 scan_params->ie_list.widebw = (uint8_t *)sub_ie;
332 break;
333 case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
334 scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
335 break;
336 }
337 /* Consume sub info element */
338 sub_ie_len -= sub_ie->ie_len;
339 /* go to next Sub IE */
340 sub_ie = (struct ie_header *)
341 (((uint8_t *) sub_ie) +
342 sizeof(struct ie_header) + sub_ie->ie_len);
343 }
344
345 return QDF_STATUS_SUCCESS;
346}
347
Om Prakash Tripathi1d1525d2017-09-08 13:59:34 +0530348bool
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530349util_scan_is_hidden_ssid(struct ie_ssid *ssid)
350{
351 uint8_t i;
352
353 /*
354 * We flag this as Hidden SSID if the Length is 0
355 * of the SSID only contains 0's
356 */
357 if (!ssid || !ssid->ssid_len)
358 return true;
359
360 for (i = 0; i < ssid->ssid_len; i++)
361 if (ssid->ssid[i] != 0)
362 return false;
363
364 /* All 0's */
365 return true;
366}
367
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530368static QDF_STATUS
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530369util_scan_parse_extn_ie(struct scan_cache_entry *scan_params,
370 struct ie_header *ie)
371{
372 struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie;
373
374 switch (extn_ie->ie_extn_id) {
Hariharan Basuthkar738320e2018-11-26 11:19:19 +0530375 case WLAN_EXTN_ELEMID_MAX_CHAN_SWITCH_TIME:
376 scan_params->ie_list.mcst = (uint8_t *)ie;
377 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530378 case WLAN_EXTN_ELEMID_SRP:
Gyanranjan Hazarikab5d426d2017-08-22 21:45:07 -0700379 scan_params->ie_list.srp = (uint8_t *)ie;
380 break;
381 case WLAN_EXTN_ELEMID_HECAP:
382 scan_params->ie_list.hecap = (uint8_t *)ie;
383 break;
384 case WLAN_EXTN_ELEMID_HEOP:
385 scan_params->ie_list.heop = (uint8_t *)ie;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530386 break;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530387 case WLAN_EXTN_ELEMID_ESP:
388 scan_params->ie_list.esp = (uint8_t *)ie;
389 break;
Rhythm Patwaa6ba9ee2018-05-23 19:29:57 -0700390 case WLAN_EXTN_ELEMID_MUEDCA:
391 scan_params->ie_list.muedca = (uint8_t *)ie;
392 break;
Rhythm Patwa7232cb12019-09-23 22:09:00 -0700393 case WLAN_EXTN_ELEMID_HE_6G_CAP:
394 scan_params->ie_list.hecap_6g = (uint8_t *)ie;
395 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530396 default:
397 break;
398 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530399 return QDF_STATUS_SUCCESS;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530400}
401
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530402static QDF_STATUS
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530403util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
404 struct ie_header *ie)
405{
Jeff Johnson82eb2122019-03-20 12:16:13 -0700406 if (!scan_params->ie_list.vendor)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530407 scan_params->ie_list.vendor = (uint8_t *)ie;
408
409 if (is_wpa_oui((uint8_t *)ie)) {
410 scan_params->ie_list.wpa = (uint8_t *)ie;
411 } else if (is_wps_oui((uint8_t *)ie)) {
412 scan_params->ie_list.wps = (uint8_t *)ie;
413 /* WCN IE should be a subset of WPS IE */
414 if (is_wcn_oui((uint8_t *)ie))
415 scan_params->ie_list.wcn = (uint8_t *)ie;
416 } else if (is_wme_param((uint8_t *)ie)) {
417 scan_params->ie_list.wmeparam = (uint8_t *)ie;
418 } else if (is_wme_info((uint8_t *)ie)) {
419 scan_params->ie_list.wmeinfo = (uint8_t *)ie;
420 } else if (is_atheros_oui((uint8_t *)ie)) {
421 scan_params->ie_list.athcaps = (uint8_t *)ie;
422 } else if (is_atheros_extcap_oui((uint8_t *)ie)) {
423 scan_params->ie_list.athextcaps = (uint8_t *)ie;
424 } else if (is_sfa_oui((uint8_t *)ie)) {
425 scan_params->ie_list.sfa = (uint8_t *)ie;
426 } else if (is_p2p_oui((uint8_t *)ie)) {
427 scan_params->ie_list.p2p = (uint8_t *)ie;
Bharat Bhushan Chakravarty145d3932017-03-20 12:52:16 -0700428 } else if (is_qca_son_oui((uint8_t *)ie,
429 QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530430 scan_params->ie_list.sonadv = (uint8_t *)ie;
431 } else if (is_ht_cap((uint8_t *)ie)) {
432 /* we only care if there isn't already an HT IE (ANA) */
Jeff Johnson82eb2122019-03-20 12:16:13 -0700433 if (!scan_params->ie_list.htcap) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530434 if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN +
435 sizeof(struct htcap_cmn_ie)))
436 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530437 scan_params->ie_list.htcap =
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530438 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
439 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530440 } else if (is_ht_info((uint8_t *)ie)) {
441 /* we only care if there isn't already an HT IE (ANA) */
Jeff Johnson82eb2122019-03-20 12:16:13 -0700442 if (!scan_params->ie_list.htinfo) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530443 if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN +
444 sizeof(struct wlan_ie_htinfo_cmn))
445 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530446 scan_params->ie_list.htinfo =
447 (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
448 ie)->hi_ie);
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530449 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530450 } else if (is_interop_vht((uint8_t *)ie) &&
Min Liub2183122019-05-17 13:29:00 +0800451 !(scan_params->ie_list.vhtcap)) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530452 uint8_t *vendor_ie = (uint8_t *)(ie);
453
454 if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
455 sizeof(struct wlan_ie_vhtcaps)) -
456 sizeof(struct ie_header)))
457 return QDF_STATUS_E_INVAL;
458 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET;
459 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) -
460 sizeof(struct ie_header))
461 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530462 /* location where Interop Vht Cap IE and VHT OP IE Present */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530463 scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) +
464 WLAN_VENDOR_VHTCAP_IE_OFFSET);
465 if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
466 sizeof(struct wlan_ie_vhtcaps)) -
Min Liub2183122019-05-17 13:29:00 +0800467 sizeof(struct ie_header))) {
468 if (ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET +
469 sizeof(struct wlan_ie_vhtop)) -
470 sizeof(struct ie_header)))
471 return QDF_STATUS_E_INVAL;
472 vendor_ie = ((uint8_t *)(ie)) +
473 WLAN_VENDOR_VHTOP_IE_OFFSET;
474 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) -
475 sizeof(struct ie_header)))
476 return QDF_STATUS_E_INVAL;
477 scan_params->ie_list.vhtop = (((uint8_t *)(ie)) +
478 WLAN_VENDOR_VHTOP_IE_OFFSET);
479 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530480 } else if (is_bwnss_oui((uint8_t *)ie)) {
481 /*
482 * Bandwidth-NSS map has sub-type & version.
483 * hence copy data just after version byte
484 */
485 scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
Abhishek Singh7b599032017-11-10 14:42:31 +0530486 } else if (is_mbo_oce_oui((uint8_t *)ie)) {
487 scan_params->ie_list.mbo_oce = (uint8_t *)ie;
Rathees kumar Chinannanb8f2d082018-07-04 15:51:51 +0530488 } else if (is_extender_oui((uint8_t *)ie)) {
489 scan_params->ie_list.extender = (uint8_t *)ie;
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +0530490 } else if (is_adaptive_11r_oui((uint8_t *)ie)) {
491 if ((ie->ie_len < OUI_LENGTH) ||
492 (ie->ie_len > MAX_ADAPTIVE_11R_IE_LEN))
493 return QDF_STATUS_E_INVAL;
494
495 scan_params->ie_list.adaptive_11r = (uint8_t *)ie +
496 sizeof(struct ie_header);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530497 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530498 return QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530499}
500
501static QDF_STATUS
502util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params)
503{
504 struct ie_header *ie, *sub_ie;
505 uint32_t ie_len, sub_ie_len;
506 QDF_STATUS status;
507
508 ie_len = util_scan_entry_ie_len(scan_params);
509 ie = (struct ie_header *)
510 util_scan_entry_ie_data(scan_params);
511
512 while (ie_len >= sizeof(struct ie_header)) {
513 ie_len -= sizeof(struct ie_header);
514
515 if (!ie->ie_len) {
516 ie += 1;
517 continue;
518 }
519
520 if (ie_len < ie->ie_len) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +0530521 scm_debug("Incomplete corrupted IE:%x",
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530522 ie->ie_id);
523 return QDF_STATUS_E_INVAL;
524 }
525
526 switch (ie->ie_id) {
527 case WLAN_ELEMID_SSID:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530528 if (ie->ie_len > (sizeof(struct ie_ssid) -
529 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530530 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530531 scan_params->ie_list.ssid = (uint8_t *)ie;
532 break;
533 case WLAN_ELEMID_RATES:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530534 if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530535 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530536 scan_params->ie_list.rates = (uint8_t *)ie;
537 break;
538 case WLAN_ELEMID_DSPARMS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530539 if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN)
540 return QDF_STATUS_E_INVAL;
Abhishek Singhc05285d2018-01-12 15:19:32 +0530541 scan_params->ie_list.ds_param = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530542 scan_params->channel.chan_idx =
543 ((struct ds_ie *)ie)->cur_chan;
544 break;
545 case WLAN_ELEMID_TIM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530546 if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530547 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530548 scan_params->ie_list.tim = (uint8_t *)ie;
549 scan_params->dtim_period =
550 ((struct wlan_tim_ie *)ie)->tim_period;
551 break;
552 case WLAN_ELEMID_COUNTRY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530553 if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530554 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530555 scan_params->ie_list.country = (uint8_t *)ie;
556 break;
557 case WLAN_ELEMID_QBSS_LOAD:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530558 if (ie->ie_len != sizeof(struct qbss_load_ie) -
Jingxiang Gec5f0bd12018-06-13 18:00:02 +0800559 sizeof(struct ie_header)) {
560 /*
561 * Expected QBSS IE length is 5Bytes; For some
562 * old cisco AP, QBSS IE length is 4Bytes, which
563 * doesn't match with latest spec, So ignore
564 * QBSS IE in such case.
565 */
566 break;
567 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530568 scan_params->ie_list.qbssload = (uint8_t *)ie;
569 break;
570 case WLAN_ELEMID_CHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530571 if (ie->ie_len != WLAN_CSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530572 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530573 scan_params->ie_list.csa = (uint8_t *)ie;
574 break;
575 case WLAN_ELEMID_IBSSDFS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530576 if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530577 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530578 scan_params->ie_list.ibssdfs = (uint8_t *)ie;
579 break;
580 case WLAN_ELEMID_QUIET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530581 if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530582 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530583 scan_params->ie_list.quiet = (uint8_t *)ie;
584 break;
585 case WLAN_ELEMID_ERP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530586 if (ie->ie_len != (sizeof(struct erp_ie) -
587 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530588 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530589 scan_params->erp = ((struct erp_ie *)ie)->value;
590 break;
591 case WLAN_ELEMID_HTCAP_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530592 if (ie->ie_len != sizeof(struct htcap_cmn_ie))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530593 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530594 scan_params->ie_list.htcap =
595 (uint8_t *)&(((struct htcap_ie *)ie)->ie);
596 break;
597 case WLAN_ELEMID_RSN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530598 if (ie->ie_len < WLAN_RSN_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530599 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530600 scan_params->ie_list.rsn = (uint8_t *)ie;
601 break;
602 case WLAN_ELEMID_XRATES:
603 scan_params->ie_list.xrates = (uint8_t *)ie;
604 break;
605 case WLAN_ELEMID_EXTCHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530606 if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530607 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530608 scan_params->ie_list.xcsa = (uint8_t *)ie;
609 break;
610 case WLAN_ELEMID_SECCHANOFFSET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530611 if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530612 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530613 scan_params->ie_list.secchanoff = (uint8_t *)ie;
614 break;
615 case WLAN_ELEMID_HTINFO_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530616 if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530617 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530618 scan_params->ie_list.htinfo =
619 (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
620 scan_params->channel.chan_idx =
621 ((struct wlan_ie_htinfo_cmn *)
622 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
623 break;
624 case WLAN_ELEMID_WAPI:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530625 if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530626 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530627 scan_params->ie_list.wapi = (uint8_t *)ie;
628 break;
629 case WLAN_ELEMID_XCAPS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530630 if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530631 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530632 scan_params->ie_list.extcaps = (uint8_t *)ie;
633 break;
634 case WLAN_ELEMID_VHTCAP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530635 if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) -
636 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530637 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530638 scan_params->ie_list.vhtcap = (uint8_t *)ie;
639 break;
640 case WLAN_ELEMID_VHTOP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530641 if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) -
642 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530643 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530644 scan_params->ie_list.vhtop = (uint8_t *)ie;
645 break;
646 case WLAN_ELEMID_OP_MODE_NOTIFY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530647 if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530648 goto err;
wadesongd58eaf42018-05-23 11:30:02 +0800649 scan_params->ie_list.opmode = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530650 break;
651 case WLAN_ELEMID_MOBILITY_DOMAIN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530652 if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530653 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530654 scan_params->ie_list.mdie = (uint8_t *)ie;
655 break;
656 case WLAN_ELEMID_VENDOR:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530657 status = util_scan_parse_vendor_ie(scan_params,
658 ie);
659 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530660 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530661 break;
662 case WLAN_ELEMID_CHAN_SWITCH_WRAP:
663 scan_params->ie_list.cswrp = (uint8_t *)ie;
664 /* Go to next sub IE */
665 sub_ie = (struct ie_header *)
666 (((uint8_t *)ie) + sizeof(struct ie_header));
667 sub_ie_len = ie->ie_len;
668 status =
669 util_scan_parse_chan_switch_wrapper_ie(
670 scan_params, sub_ie, sub_ie_len);
671 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530672 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530673 }
674 break;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530675 case WLAN_ELEMID_FILS_INDICATION:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530676 if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530677 goto err;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530678 scan_params->ie_list.fils_indication = (uint8_t *)ie;
679 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530680 case WLAN_ELEMID_EXTN_ELEM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530681 status = util_scan_parse_extn_ie(scan_params, ie);
682 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530683 goto err_status;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530684 break;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530685 default:
686 break;
687 }
688
689 /* Consume info element */
690 ie_len -= ie->ie_len;
691 /* Go to next IE */
692 ie = (struct ie_header *)
693 (((uint8_t *) ie) +
694 sizeof(struct ie_header) +
695 ie->ie_len);
696 }
697
698 return QDF_STATUS_SUCCESS;
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530699
700err:
701 status = QDF_STATUS_E_INVAL;
702err_status:
703 scm_debug("failed to parse IE - id: %d, len: %d",
704 ie->ie_id, ie->ie_len);
705
706 return status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530707}
708
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530709/**
710 * util_scan_update_esp_data: update ESP params from beacon/probe response
711 * @esp_information: pointer to wlan_esp_information
712 * @scan_entry: new received entry
713 *
714 * The Estimated Service Parameters element is
715 * used by a AP to provide information to another STA which
716 * can then use the information as input to an algorithm to
717 * generate an estimate of throughput between the two STAs.
718 * The ESP Information List field contains from 1 to 4 ESP
719 * Information fields(each field 24 bits), each corresponding
720 * to an access category for which estimated service parameters
721 * information is provided.
722 *
723 * Return: None
724 */
725static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information,
726 struct scan_cache_entry *scan_entry)
727{
728
729 uint8_t *data;
730 int i = 0;
Sathyanarayanan0a000622017-10-10 17:17:28 +0530731 uint64_t total_elements;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530732 struct wlan_esp_info *esp_info;
733 struct wlan_esp_ie *esp_ie;
734
735 esp_ie = (struct wlan_esp_ie *)
736 util_scan_entry_esp_info(scan_entry);
737
738 total_elements = esp_ie->esp_len;
739 data = (uint8_t *)esp_ie + 3;
740 do_div(total_elements, ESP_INFORMATION_LIST_LENGTH);
741
742 if (total_elements > MAX_ESP_INFORMATION_FIELD) {
743 scm_err("No of Air time fractions are greater than supported");
744 return;
745 }
746
747 for (i = 0; i < total_elements; i++) {
748 esp_info = (struct wlan_esp_info *)data;
749 if (esp_info->access_category == ESP_AC_BK) {
750 qdf_mem_copy(&esp_information->esp_info_AC_BK,
751 data, 3);
752 data = data + ESP_INFORMATION_LIST_LENGTH;
753 continue;
754 }
755 if (esp_info->access_category == ESP_AC_BE) {
756 qdf_mem_copy(&esp_information->esp_info_AC_BE,
757 data, 3);
758 data = data + ESP_INFORMATION_LIST_LENGTH;
759 continue;
760 }
761 if (esp_info->access_category == ESP_AC_VI) {
762 qdf_mem_copy(&esp_information->esp_info_AC_VI,
763 data, 3);
764 data = data + ESP_INFORMATION_LIST_LENGTH;
765 continue;
766 }
767 if (esp_info->access_category == ESP_AC_VO) {
768 qdf_mem_copy(&esp_information->esp_info_AC_VO,
769 data, 3);
770 data = data + ESP_INFORMATION_LIST_LENGTH;
771 break;
772 }
773 }
774}
775
776/**
777 * util_scan_scm_update_bss_with_esp_dataa: calculate estimated air time
778 * fraction
779 * @scan_entry: new received entry
780 *
781 * This function process all Access category ESP params and provide
782 * best effort air time fraction.
783 * If best effort is not available, it will choose VI, VO and BK in sequence
784 *
785 */
786static void util_scan_scm_update_bss_with_esp_data(
787 struct scan_cache_entry *scan_entry)
788{
789 uint8_t air_time_fraction = 0;
790 struct wlan_esp_ie esp_information;
791
792 if (!scan_entry->ie_list.esp)
793 return;
794
795 util_scan_update_esp_data(&esp_information, scan_entry);
796
797 /*
798 * If the ESP metric is transmitting multiple airtime fractions, then
799 * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is
800 * the first one available
801 */
802 if (esp_information.esp_info_AC_BE.access_category
803 == ESP_AC_BE)
804 air_time_fraction =
805 esp_information.esp_info_AC_BE.
806 estimated_air_fraction;
807 else if (esp_information.esp_info_AC_VI.access_category
808 == ESP_AC_VI)
809 air_time_fraction =
810 esp_information.esp_info_AC_VI.
811 estimated_air_fraction;
812 else if (esp_information.esp_info_AC_VO.access_category
813 == ESP_AC_VO)
814 air_time_fraction =
815 esp_information.esp_info_AC_VO.
816 estimated_air_fraction;
817 else if (esp_information.esp_info_AC_BK.access_category
818 == ESP_AC_BK)
819 air_time_fraction =
820 esp_information.esp_info_AC_BK.
821 estimated_air_fraction;
822 scan_entry->air_time_fraction = air_time_fraction;
823}
824
825/**
826 * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP
827 * @scan_entry: new received entry
828 *
829 * Return: number of nss advertised by AP
830 */
831static int util_scan_scm_calc_nss_supported_by_ap(
832 struct scan_cache_entry *scan_params)
833{
834 struct htcap_cmn_ie *htcap;
835 struct wlan_ie_vhtcaps *vhtcaps;
836 uint8_t rx_mcs_map;
837
838 htcap = (struct htcap_cmn_ie *)
839 util_scan_entry_htcap(scan_params);
840 vhtcaps = (struct wlan_ie_vhtcaps *)
841 util_scan_entry_vhtcap(scan_params);
842 if (vhtcaps) {
843 rx_mcs_map = vhtcaps->rx_mcs_map;
844 if ((rx_mcs_map & 0xC0) != 0xC0)
845 return 4;
846
847 if ((rx_mcs_map & 0x30) != 0x30)
848 return 3;
849
850 if ((rx_mcs_map & 0x0C) != 0x0C)
851 return 2;
852 } else if (htcap) {
853 if (htcap->mcsset[3])
854 return 4;
855
856 if (htcap->mcsset[2])
857 return 3;
858
859 if (htcap->mcsset[1])
860 return 2;
861
862 }
863 return 1;
864}
865
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530866#ifdef WLAN_DFS_CHAN_HIDDEN_SSID
867QDF_STATUS
868util_scan_add_hidden_ssid(struct wlan_objmgr_pdev *pdev, qdf_nbuf_t bcnbuf)
869{
870 struct wlan_frame_hdr *hdr;
871 struct wlan_bcn_frame *bcn;
872 struct wlan_scan_obj *scan_obj;
873 struct wlan_ssid *conf_ssid;
874 struct ie_header *ie;
875 uint32_t frame_len = qdf_nbuf_len(bcnbuf);
876 uint16_t bcn_ie_offset, ssid_ie_start_offset, ssid_ie_end_offset;
877 uint16_t tmplen, ie_length;
878 uint8_t *pbeacon, *tmp;
879 bool set_ssid_flag = false;
880 struct ie_ssid *ssid;
881 uint8_t pdev_id;
882
883 if (!pdev) {
884 scm_warn("pdev: 0x%pK is NULL", pdev);
885 return QDF_STATUS_E_NULL_VALUE;
886 }
887 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
888 scan_obj = wlan_pdev_get_scan_obj(pdev);
Om Prakash Tripathi510a27c2019-03-01 11:53:18 +0530889 if (!scan_obj) {
890 scm_warn("null scan_obj");
891 return QDF_STATUS_E_NULL_VALUE;
892 }
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530893
894 conf_ssid = &scan_obj->pdev_info[pdev_id].conf_ssid;
895
896 hdr = (struct wlan_frame_hdr *)qdf_nbuf_data(bcnbuf);
897
898 /* received bssid does not match configured bssid */
899 if (qdf_mem_cmp(hdr->i_addr3, scan_obj->pdev_info[pdev_id].conf_bssid,
900 QDF_MAC_ADDR_SIZE) ||
901 conf_ssid->length == 0) {
902 return QDF_STATUS_SUCCESS;
903 }
904
905 bcn = (struct wlan_bcn_frame *)(qdf_nbuf_data(bcnbuf) + sizeof(*hdr));
906 pbeacon = (uint8_t *)bcn;
907
908 ie = (struct ie_header *)(pbeacon +
909 offsetof(struct wlan_bcn_frame, ie));
910
911 bcn_ie_offset = offsetof(struct wlan_bcn_frame, ie);
912 ie_length = (uint16_t)(frame_len - sizeof(*hdr) -
913 bcn_ie_offset);
914
915 while (ie_length >= sizeof(struct ie_header)) {
916 ie_length -= sizeof(struct ie_header);
917
918 bcn_ie_offset += sizeof(struct ie_header);
919
920 if (ie_length < ie->ie_len) {
921 scm_debug("Incomplete corrupted IE:%x", ie->ie_id);
922 return QDF_STATUS_E_INVAL;
923 }
924 if (ie->ie_id == WLAN_ELEMID_SSID) {
925 if (ie->ie_len > (sizeof(struct ie_ssid) -
926 sizeof(struct ie_header))) {
927 return QDF_STATUS_E_INVAL;
928 }
929 ssid = (struct ie_ssid *)ie;
930 if (util_scan_is_hidden_ssid(ssid)) {
931 set_ssid_flag = true;
932 ssid_ie_start_offset = bcn_ie_offset -
933 sizeof(struct ie_header);
934 ssid_ie_end_offset = bcn_ie_offset +
935 ie->ie_len;
936 }
937 }
938 if (ie->ie_len == 0) {
939 ie += 1; /* next IE */
940 continue;
941 }
942 if (ie->ie_id == WLAN_ELEMID_VENDOR &&
943 is_wps_oui((uint8_t *)ie)) {
944 set_ssid_flag = false;
945 break;
946 }
947 /* Consume info element */
948 ie_length -= ie->ie_len;
949 /* Go to next IE */
950 ie = (struct ie_header *)(((uint8_t *)ie) +
951 sizeof(struct ie_header) +
952 ie->ie_len);
953 }
954
955 if (set_ssid_flag) {
956 /* Hidden SSID if the Length is 0 */
957 if (!ssid->ssid_len) {
958 /* increase the taillength by length of ssid */
959 if (qdf_nbuf_put_tail(bcnbuf,
960 conf_ssid->length) == NULL) {
961 scm_debug("No enough tailroom");
962 return QDF_STATUS_E_NOMEM;
963 }
964 /* length of the buffer to be copied */
965 tmplen = frame_len -
966 sizeof(*hdr) - ssid_ie_end_offset;
967 /*
968 * tmp memory to copy the beacon info
969 * after ssid ie.
970 */
971 tmp = qdf_mem_malloc(tmplen * sizeof(u_int8_t));
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +0530972 if (!tmp)
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530973 return QDF_STATUS_E_NOMEM;
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +0530974
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530975 /* Copy beacon data after ssid ie to tmp */
976 qdf_nbuf_copy_bits(bcnbuf, (sizeof(*hdr) +
977 ssid_ie_end_offset), tmplen, tmp);
978 /* Add ssid length */
979 *(pbeacon + (ssid_ie_start_offset + 1))
980 = conf_ssid->length;
981 /* Insert the SSID string */
982 qdf_mem_copy((pbeacon + ssid_ie_end_offset),
983 conf_ssid->ssid, conf_ssid->length);
984 /* Copy rest of the beacon data */
985 qdf_mem_copy((pbeacon + ssid_ie_end_offset +
986 conf_ssid->length), tmp, tmplen);
987 qdf_mem_free(tmp);
988
989 /* Hidden ssid with all 0's */
990 } else if (ssid->ssid_len == conf_ssid->length) {
991 /* Insert the SSID string */
992 qdf_mem_copy((pbeacon + ssid_ie_start_offset +
993 sizeof(struct ie_header)),
994 conf_ssid->ssid, conf_ssid->length);
995 } else {
996 scm_debug("mismatch in hidden ssid length");
997 return QDF_STATUS_E_INVAL;
998 }
999 }
1000 return QDF_STATUS_SUCCESS;
1001}
1002#endif /* WLAN_DFS_CHAN_HIDDEN_SSID */
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +05301003
1004#ifdef WLAN_ADAPTIVE_11R
1005/**
1006 * scm_fill_adaptive_11r_cap() - Check if the AP supports adaptive 11r
1007 * @scan_entry: Pointer to the scan entry
1008 *
1009 * Return: true if adaptive 11r is advertised else false
1010 */
1011static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
1012{
1013 uint8_t *ie;
1014 uint8_t data;
1015 bool adaptive_11r;
1016
1017 ie = util_scan_entry_adaptive_11r(scan_entry);
1018 if (!ie)
1019 return;
1020
1021 data = *(ie + OUI_LENGTH);
1022 adaptive_11r = (data & 0x1) ? true : false;
1023
1024 scan_entry->adaptive_11r_ap = adaptive_11r;
1025}
1026#else
1027static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
1028{
1029 scan_entry->adaptive_11r_ap = false;
1030}
1031#endif
1032
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001033static QDF_STATUS
1034util_scan_gen_scan_entry(struct wlan_objmgr_pdev *pdev,
1035 uint8_t *frame, qdf_size_t frame_len,
1036 uint32_t frm_subtype,
1037 struct mgmt_rx_event_params *rx_param,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001038 struct scan_mbssid_info *mbssid_info,
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001039 qdf_list_t *scan_list)
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301040{
1041 struct wlan_frame_hdr *hdr;
1042 struct wlan_bcn_frame *bcn;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001043 QDF_STATUS status = QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301044 struct ie_ssid *ssid;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001045 struct scan_cache_entry *scan_entry;
Abhishek Singh7b599032017-11-10 14:42:31 +05301046 struct qbss_load_ie *qbss_load;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001047 struct scan_cache_node *scan_node;
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301048 uint8_t i;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001049
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301050 scan_entry = qdf_mem_malloc_atomic(sizeof(*scan_entry));
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301051 if (!scan_entry) {
1052 scm_err("failed to allocate memory for scan_entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001053 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301054 }
1055 scan_entry->raw_frame.ptr =
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301056 qdf_mem_malloc_atomic(frame_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301057 if (!scan_entry->raw_frame.ptr) {
1058 scm_err("failed to allocate memory for frame");
1059 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001060 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301061 }
1062
1063 bcn = (struct wlan_bcn_frame *)
1064 (frame + sizeof(*hdr));
1065 hdr = (struct wlan_frame_hdr *)frame;
1066
gaurank kathpalia26f98332018-01-29 18:09:06 +05301067 /* update timestamp in nanoseconds needed by kernel layers */
Arif Hussain6fcc7902018-03-22 12:33:12 -07001068 scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns();
gaurank kathpalia26f98332018-01-29 18:09:06 +05301069
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301070 scan_entry->frm_subtype = frm_subtype;
1071 qdf_mem_copy(scan_entry->bssid.bytes,
1072 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1073 /* Scr addr */
1074 qdf_mem_copy(scan_entry->mac_addr.bytes,
1075 hdr->i_addr2, QDF_MAC_ADDR_SIZE);
1076 scan_entry->seq_num =
1077 (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
1078
1079 scan_entry->rssi_raw = rx_param->rssi;
Om Prakash Tripathi6af738b2017-08-22 15:46:38 +05301080 scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301081 scan_entry->tsf_delta = rx_param->tsf_delta;
1082
gaurank kathpalia26f98332018-01-29 18:09:06 +05301083 /* Copy per chain rssi to scan entry */
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301084 qdf_mem_copy(scan_entry->per_chain_rssi, rx_param->rssi_ctl,
gaurank kathpalia26f98332018-01-29 18:09:06 +05301085 WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
1086
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301087 if (!wlan_psoc_nif_fw_ext_cap_get(wlan_pdev_get_psoc(pdev),
1088 WLAN_SOC_CEXT_HW_DB2DBM)) {
1089 for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++) {
1090 if (scan_entry->per_chain_rssi[i] !=
1091 WLAN_INVALID_PER_CHAIN_SNR)
1092 scan_entry->per_chain_rssi[i] +=
1093 WLAN_NOISE_FLOOR_DBM_DEFAULT;
1094 else
1095 scan_entry->per_chain_rssi[i] =
1096 WLAN_INVALID_PER_CHAIN_RSSI;
1097 }
1098 }
1099
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301100 /* store jiffies */
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001101 scan_entry->rrm_parent_tsf = (uint32_t)qdf_system_ticks();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301102
1103 scan_entry->bcn_int = le16toh(bcn->beacon_interval);
1104
1105 /*
1106 * In case if the beacon dosnt have
1107 * valid beacon interval falback to def
1108 */
1109 if (!scan_entry->bcn_int)
1110 scan_entry->bcn_int = 100;
1111 scan_entry->cap_info.value = le16toh(bcn->capability.value);
1112 qdf_mem_copy(scan_entry->tsf_info.data,
1113 bcn->timestamp, 8);
1114 scan_entry->erp = ERP_NON_ERP_PRESENT;
1115
Om Prakash Tripathicdcbb392017-04-18 18:51:20 +05301116 scan_entry->scan_entry_time =
1117 qdf_mc_timer_get_system_time();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301118
1119 scan_entry->raw_frame.len = frame_len;
1120 qdf_mem_copy(scan_entry->raw_frame.ptr,
1121 frame, frame_len);
1122 status = util_scan_populate_bcn_ie_list(scan_entry);
1123 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +05301124 scm_debug("failed to parse beacon IE");
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301125 qdf_mem_free(scan_entry->raw_frame.ptr);
1126 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001127 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301128 }
1129
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301130 ssid = (struct ie_ssid *)
1131 scan_entry->ie_list.ssid;
1132
1133 if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
1134 qdf_mem_free(scan_entry->raw_frame.ptr);
1135 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001136 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301137 }
1138
1139 if (scan_entry->ie_list.p2p)
1140 scan_entry->is_p2p = true;
1141
1142 /* If no channel info is present in beacon use meta channel */
1143 if (!scan_entry->channel.chan_idx) {
1144 scan_entry->channel.chan_idx =
1145 rx_param->channel;
1146 } else if (rx_param->channel !=
1147 scan_entry->channel.chan_idx) {
Shashikala Prabhu7edbb052018-04-12 09:55:25 +05301148 if (!wlan_reg_chan_is_49ghz(pdev, scan_entry->channel.chan_idx))
1149 scan_entry->channel_mismatch = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301150 }
1151
1152 if (util_scan_is_hidden_ssid(ssid)) {
1153 scan_entry->ie_list.ssid = NULL;
Abhishek Singh7062efa2019-03-05 15:37:07 +05301154 scan_entry->is_hidden_ssid = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301155 } else {
1156 qdf_mem_copy(scan_entry->ssid.ssid,
Harprit Chhabadaab6c10d2018-10-31 10:52:34 -07001157 ssid->ssid, ssid->ssid_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301158 scan_entry->ssid.length = ssid->ssid_len;
1159 scan_entry->hidden_ssid_timestamp =
1160 scan_entry->scan_entry_time;
1161 }
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001162 qdf_mem_copy(&scan_entry->mbssid_info, mbssid_info,
1163 sizeof(scan_entry->mbssid_info));
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301164 if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx))
1165 scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry);
1166 else
1167 scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry);
1168
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301169 scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry);
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +05301170 scm_fill_adaptive_11r_cap(scan_entry);
1171
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301172 util_scan_scm_update_bss_with_esp_data(scan_entry);
Abhishek Singh7b599032017-11-10 14:42:31 +05301173 qbss_load = (struct qbss_load_ie *)
1174 util_scan_entry_qbssload(scan_entry);
1175 if (qbss_load)
1176 scan_entry->qbss_chan_load = qbss_load->qbss_chan_load;
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301177
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301178 scan_node = qdf_mem_malloc_atomic(sizeof(*scan_node));
Sandeep Puligillac6764592017-12-05 21:01:52 -08001179 if (!scan_node) {
Om Prakash Tripathi52402552018-02-21 16:31:49 +05301180 qdf_mem_free(scan_entry->raw_frame.ptr);
Sandeep Puligillac6764592017-12-05 21:01:52 -08001181 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001182 return QDF_STATUS_E_FAILURE;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001183 }
1184
1185 scan_node->entry = scan_entry;
1186 qdf_list_insert_front(scan_list, &scan_node->node);
1187
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001188 return status;
1189}
1190
1191/**
1192 * util_scan_find_ie() - find information element
1193 * @eid: element id
1194 * @ies: pointer consisting of IEs
1195 * @len: IE length
1196 *
1197 * Return: NULL if the element ID is not found or
1198 * a pointer to the first byte of the requested
1199 * element
1200 */
1201static uint8_t *util_scan_find_ie(uint8_t eid, uint8_t *ies,
1202 int32_t len)
1203{
1204 while (len >= 2 && len >= ies[1] + 2) {
1205 if (ies[0] == eid)
1206 return ies;
1207 len -= ies[1] + 2;
1208 ies += ies[1] + 2;
1209 }
1210
1211 return NULL;
1212}
1213
1214#ifdef WLAN_FEATURE_MBSSID
1215static void util_gen_new_bssid(uint8_t *bssid, uint8_t max_bssid,
1216 uint8_t mbssid_index,
1217 uint8_t *new_bssid_addr)
1218{
1219 uint64_t bssid_tmp = 0, new_bssid = 0;
1220 uint64_t lsb_n;
1221 int i;
1222
1223 for (i = 0; i < QDF_MAC_ADDR_SIZE; i++)
1224 bssid_tmp = bssid_tmp << 8 | bssid[i];
1225
1226 lsb_n = bssid_tmp & ((1 << max_bssid) - 1);
1227 new_bssid = bssid_tmp;
1228 new_bssid &= ~((1 << max_bssid) - 1);
1229 new_bssid |= (lsb_n + mbssid_index) % (1 << max_bssid);
1230
1231 for (i = QDF_MAC_ADDR_SIZE - 1; i >= 0; i--) {
1232 new_bssid_addr[i] = new_bssid & 0xff;
1233 new_bssid = new_bssid >> 8;
1234 }
1235}
1236
1237static uint32_t util_gen_new_ie(uint8_t *ie, uint32_t ielen,
1238 uint8_t *subelement,
1239 size_t subie_len, uint8_t *new_ie)
1240{
1241 uint8_t *pos, *tmp;
1242 const uint8_t *tmp_old, *tmp_new;
1243 uint8_t *sub_copy;
1244
1245 /* copy subelement as we need to change its content to
1246 * mark an ie after it is processed.
1247 */
1248 sub_copy = qdf_mem_malloc(subie_len);
1249 if (!sub_copy)
1250 return 0;
1251 qdf_mem_copy(sub_copy, subelement, subie_len);
1252
1253 pos = &new_ie[0];
1254
1255 /* new ssid */
1256 tmp_new = util_scan_find_ie(WLAN_ELEMID_SSID, sub_copy, subie_len);
1257 if (tmp_new) {
1258 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1259 pos += (tmp_new[1] + 2);
1260 }
1261
1262 /* go through IEs in ie (skip SSID) and subelement,
1263 * merge them into new_ie
1264 */
1265 tmp_old = util_scan_find_ie(WLAN_ELEMID_SSID, ie, ielen);
1266 tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie;
1267
1268 while (tmp_old + tmp_old[1] + 2 - ie <= ielen) {
1269 if (tmp_old[0] == 0) {
1270 tmp_old++;
1271 continue;
1272 }
1273
1274 tmp = (uint8_t *)util_scan_find_ie(tmp_old[0], sub_copy,
1275 subie_len);
1276 if (!tmp) {
1277 /* ie in old ie but not in subelement */
1278 if (tmp_old[0] != WLAN_ELEMID_MULTIPLE_BSSID) {
1279 qdf_mem_copy(pos, tmp_old, tmp_old[1] + 2);
1280 pos += tmp_old[1] + 2;
1281 }
1282 } else {
1283 /* ie in transmitting ie also in subelement,
1284 * copy from subelement and flag the ie in subelement
1285 * as copied (by setting eid field to 0xff). For
1286 * vendor ie, compare OUI + type + subType to
1287 * determine if they are the same ie.
1288 */
1289 if (tmp_old[0] == WLAN_ELEMID_VENDOR) {
1290 if (!qdf_mem_cmp(tmp_old + 2, tmp + 2, 5)) {
1291 /* same vendor ie, copy from
1292 * subelement
1293 */
1294 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1295 pos += tmp[1] + 2;
1296 tmp[0] = 0xff;
1297 } else {
1298 qdf_mem_copy(pos, tmp_old,
1299 tmp_old[1] + 2);
1300 pos += tmp_old[1] + 2;
1301 }
1302 } else {
1303 /* copy ie from subelement into new ie */
1304 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1305 pos += tmp[1] + 2;
1306 tmp[0] = 0xff;
1307 }
1308 }
1309
1310 if (tmp_old + tmp_old[1] + 2 - ie == ielen)
1311 break;
1312
1313 tmp_old += tmp_old[1] + 2;
1314 }
1315
1316 /* go through subelement again to check if there is any ie not
1317 * copied to new ie, skip ssid, capability, bssid-index ie
1318 */
1319 tmp_new = sub_copy;
1320 while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
1321 if (!(tmp_new[0] == WLAN_ELEMID_NONTX_BSSID_CAP ||
1322 tmp_new[0] == WLAN_ELEMID_SSID ||
1323 tmp_new[0] == WLAN_ELEMID_MULTI_BSSID_IDX ||
1324 tmp_new[0] == 0xff)) {
1325 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1326 pos += tmp_new[1] + 2;
1327 }
1328 if (tmp_new + tmp_new[1] + 2 - sub_copy == subie_len)
1329 break;
1330 tmp_new += tmp_new[1] + 2;
1331 }
1332
1333 qdf_mem_free(sub_copy);
1334 return pos - new_ie;
1335}
1336
1337static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1338 uint8_t *frame, qdf_size_t frame_len,
1339 uint32_t frm_subtype,
1340 struct mgmt_rx_event_params *rx_param,
1341 qdf_list_t *scan_list)
1342{
1343 struct wlan_bcn_frame *bcn;
1344 struct wlan_frame_hdr *hdr;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001345 struct scan_mbssid_info mbssid_info;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001346 QDF_STATUS status;
1347 uint8_t *pos, *subelement, *mbssid_end_pos;
1348 uint8_t *tmp, *mbssid_index_ie;
1349 uint32_t subie_len, new_ie_len;
1350 uint8_t new_bssid[QDF_MAC_ADDR_SIZE], bssid[QDF_MAC_ADDR_SIZE];
1351 uint8_t *new_ie;
1352 uint8_t *ie, *new_frame = NULL;
1353 uint64_t ielen, new_frame_len;
1354
1355 hdr = (struct wlan_frame_hdr *)frame;
1356 bcn = (struct wlan_bcn_frame *)(frame + sizeof(struct wlan_frame_hdr));
1357 ie = (uint8_t *)&bcn->ie;
1358 ielen = (uint16_t)(frame_len -
1359 sizeof(struct wlan_frame_hdr) -
1360 offsetof(struct wlan_bcn_frame, ie));
1361 qdf_mem_copy(bssid, hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1362
1363 if (!util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, ie, ielen))
1364 return QDF_STATUS_E_FAILURE;
1365
1366 pos = ie;
1367
1368 new_ie = qdf_mem_malloc(MAX_IE_LEN);
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +05301369 if (!new_ie)
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001370 return QDF_STATUS_E_NOMEM;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001371
1372 while (pos < ie + ielen + 2) {
1373 tmp = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, pos,
1374 ielen - (pos - ie));
1375 if (!tmp)
1376 break;
1377
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001378 mbssid_info.profile_count = 1 << tmp[2];
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001379 mbssid_end_pos = tmp + tmp[1] + 2;
1380 /* Skip Element ID, Len, MaxBSSID Indicator */
1381 if (tmp[1] < 4)
1382 break;
1383 for (subelement = tmp + 3; subelement < mbssid_end_pos - 1;
1384 subelement += 2 + subelement[1]) {
1385 subie_len = subelement[1];
1386 if (mbssid_end_pos - subelement < 2 + subie_len)
1387 break;
1388 if (subelement[0] != 0 || subelement[1] < 4) {
1389 /* not a valid BSS profile */
1390 continue;
1391 }
1392
1393 if (subelement[2] != WLAN_ELEMID_NONTX_BSSID_CAP ||
1394 subelement[3] != 2) {
1395 /* The first element within the Nontransmitted
1396 * BSSID Profile is not the Nontransmitted
1397 * BSSID Capability element.
1398 */
1399 continue;
1400 }
1401
1402 /* found a Nontransmitted BSSID Profile */
1403 mbssid_index_ie =
1404 util_scan_find_ie(WLAN_ELEMID_MULTI_BSSID_IDX,
1405 subelement + 2, subie_len);
1406 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 ||
1407 mbssid_index_ie[2] == 0) {
1408 /* No valid Multiple BSSID-Index element */
1409 continue;
1410 }
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001411 qdf_mem_copy(&mbssid_info.trans_bssid, bssid,
1412 QDF_MAC_ADDR_SIZE);
1413 mbssid_info.profile_num = mbssid_index_ie[2];
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001414 util_gen_new_bssid(bssid, tmp[2], mbssid_index_ie[2],
1415 new_bssid);
1416 new_ie_len = util_gen_new_ie(ie, ielen, subelement + 2,
1417 subie_len, new_ie);
1418 if (!new_ie_len)
1419 continue;
1420
1421 new_frame_len = frame_len - ielen + new_ie_len;
1422 new_frame = qdf_mem_malloc(new_frame_len);
1423 if (!new_frame) {
1424 qdf_mem_free(new_ie);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001425 return QDF_STATUS_E_NOMEM;
1426 }
1427
1428 /*
1429 * Copy the header(24byte), timestamp(8 byte),
1430 * beaconinterval(2byte) and capability(2byte)
1431 */
1432 qdf_mem_copy(new_frame, frame, 36);
1433 /* Copy the new ie generated from MBSSID profile*/
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001434 hdr = (struct wlan_frame_hdr *)new_frame;
1435 qdf_mem_copy(hdr->i_addr2, new_bssid,
1436 QDF_MAC_ADDR_SIZE);
1437 qdf_mem_copy(hdr->i_addr3, new_bssid,
1438 QDF_MAC_ADDR_SIZE);
1439 /* Copy the new ie generated from MBSSID profile*/
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001440 qdf_mem_copy(new_frame +
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001441 offsetof(struct wlan_bcn_frame, ie) +
1442 sizeof(struct wlan_frame_hdr),
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001443 new_ie, new_ie_len);
1444 status = util_scan_gen_scan_entry(pdev, new_frame,
1445 new_frame_len,
1446 frm_subtype,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001447 rx_param,
1448 &mbssid_info,
1449 scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001450 if (QDF_IS_STATUS_ERROR(status)) {
1451 qdf_mem_free(new_frame);
1452 scm_err("failed to generate a scan entry");
1453 break;
1454 }
1455 /* scan entry makes its own copy so free the frame*/
1456 qdf_mem_free(new_frame);
1457 }
1458
1459 pos = mbssid_end_pos;
1460 }
1461 qdf_mem_free(new_ie);
1462
1463 return QDF_STATUS_SUCCESS;
1464}
1465#else
1466static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1467 uint8_t *frame, qdf_size_t frame_len,
1468 uint32_t frm_subtype,
1469 struct mgmt_rx_event_params *rx_param,
1470 qdf_list_t *scan_list)
1471{
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001472 return QDF_STATUS_SUCCESS;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001473}
1474#endif
1475
1476static QDF_STATUS
1477util_scan_parse_beacon_frame(struct wlan_objmgr_pdev *pdev,
1478 uint8_t *frame,
1479 qdf_size_t frame_len,
1480 uint32_t frm_subtype,
1481 struct mgmt_rx_event_params *rx_param,
1482 qdf_list_t *scan_list)
1483{
1484 struct wlan_bcn_frame *bcn;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001485 struct wlan_frame_hdr *hdr;
1486 uint8_t *mbssid_ie = NULL;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001487 uint32_t ie_len = 0;
1488 QDF_STATUS status;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001489 struct scan_mbssid_info mbssid_info = { 0 };
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001490
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001491 hdr = (struct wlan_frame_hdr *)frame;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001492 bcn = (struct wlan_bcn_frame *)
1493 (frame + sizeof(struct wlan_frame_hdr));
1494 ie_len = (uint16_t)(frame_len -
1495 sizeof(struct wlan_frame_hdr) -
1496 offsetof(struct wlan_bcn_frame, ie));
1497
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001498 mbssid_ie = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID,
1499 (uint8_t *)&bcn->ie, ie_len);
1500 if (mbssid_ie) {
1501 qdf_mem_copy(&mbssid_info.trans_bssid,
1502 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1503 mbssid_info.profile_count = 1 << mbssid_ie[2];
1504 }
1505
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001506 status = util_scan_gen_scan_entry(pdev, frame, frame_len,
1507 frm_subtype, rx_param,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001508 &mbssid_info,
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001509 scan_list);
1510
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001511 /*
1512 * IF MBSSID IE is present in the beacon then
1513 * scan component will create a new entry for
1514 * each BSSID found in the MBSSID
1515 */
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001516 if (mbssid_ie)
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301517 status = util_scan_parse_mbssid(pdev, frame, frame_len,
1518 frm_subtype, rx_param,
1519 scan_list);
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001520
Om Prakash Tripathi0e3c5412019-04-08 15:01:34 +05301521 if (QDF_IS_STATUS_ERROR(status))
1522 scm_debug_rl("Failed to create a scan entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001523
1524 return status;
1525}
1526
1527qdf_list_t *
1528util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame,
1529 qdf_size_t frame_len, uint32_t frm_subtype,
1530 struct mgmt_rx_event_params *rx_param)
1531{
1532 qdf_list_t *scan_list;
1533 QDF_STATUS status;
1534
1535 scan_list = qdf_mem_malloc_atomic(sizeof(*scan_list));
1536 if (!scan_list) {
1537 scm_err("failed to allocate scan_list");
1538 return NULL;
1539 }
1540 qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE);
1541
1542 status = util_scan_parse_beacon_frame(pdev, frame, frame_len,
1543 frm_subtype, rx_param,
1544 scan_list);
1545 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301546 ucfg_scan_purge_results(scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001547 return NULL;
1548 }
1549
Sandeep Puligillac6764592017-12-05 21:01:52 -08001550 return scan_list;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301551}
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301552
1553QDF_STATUS
1554util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev,
1555 struct scan_cache_entry *scan_entry)
1556{
1557
1558 if (!pdev || !scan_entry) {
Jeff Johnson878533e2017-09-18 10:07:54 -07001559 scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry);
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301560 return QDF_STATUS_E_INVAL;
1561 }
1562
1563 return scm_update_scan_mlme_info(pdev, scan_entry);
1564}
Sandeep Puligillaf57464c2017-11-16 23:31:52 -08001565
1566bool util_is_scan_completed(struct scan_event *event, bool *success)
1567{
1568 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) ||
1569 (event->type == SCAN_EVENT_TYPE_DEQUEUED) ||
1570 (event->type == SCAN_EVENT_TYPE_START_FAILED)) {
1571 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
1572 (event->reason == SCAN_REASON_COMPLETED))
1573 *success = true;
1574 else
1575 *success = false;
1576
1577 return true;
1578 }
1579
1580 *success = false;
1581 return false;
1582}
1583