blob: 3d5d4f4ffd6df616b85bddd14bb0bf0ccad83d33 [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:
208 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
209 (htinfo->hi_extchoff ==
210 WLAN_HTINFO_EXTOFFSET_ABOVE))
211 phymode = WLAN_PHYMODE_11AC_VHT40PLUS;
212 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
213 (htinfo->hi_extchoff ==
214 WLAN_HTINFO_EXTOFFSET_BELOW))
215 phymode = WLAN_PHYMODE_11AC_VHT40MINUS;
216 else
217 phymode = WLAN_PHYMODE_11AC_VHT20;
218 break;
219 case WLAN_VHTOP_CHWIDTH_80:
220 if (WLAN_IS_REVSIG_VHT80_80(vhtop))
221 phymode = WLAN_PHYMODE_11AC_VHT80_80;
222 else if (WLAN_IS_REVSIG_VHT160(vhtop))
223 phymode = WLAN_PHYMODE_11AC_VHT160;
224 else
225 phymode = WLAN_PHYMODE_11AC_VHT80;
226 break;
227 case WLAN_VHTOP_CHWIDTH_160:
228 phymode = WLAN_PHYMODE_11AC_VHT160;
229 break;
230 case WLAN_VHTOP_CHWIDTH_80_80:
231 phymode = WLAN_PHYMODE_11AC_VHT80_80;
232 break;
233 default:
234 scm_err("bad channel: %d",
235 vhtop->vht_op_chwidth);
236 break;
237 }
238 } else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
239 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
240 phymode = WLAN_PHYMODE_11NA_HT40PLUS;
241 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
242 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
243 phymode = WLAN_PHYMODE_11NA_HT40MINUS;
244 else
245 phymode = WLAN_PHYMODE_11NA_HT20;
246
247 return phymode;
248}
249
250static enum wlan_phymode
251util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
252{
253 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
254 uint16_t ht_cap = 0;
255 struct htcap_cmn_ie *htcap;
256 struct wlan_ie_htinfo_cmn *htinfo;
257 struct wlan_ie_vhtop *vhtop;
258
259 htcap = (struct htcap_cmn_ie *)
260 util_scan_entry_htcap(scan_params);
261 htinfo = (struct wlan_ie_htinfo_cmn *)
262 util_scan_entry_htinfo(scan_params);
263 vhtop = (struct wlan_ie_vhtop *)
264 util_scan_entry_vhtop(scan_params);
265
266 if (htcap)
267 ht_cap = le16toh(htcap->hc_cap);
268
269 if (htcap && htinfo) {
270 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
271 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
272 phymode = WLAN_PHYMODE_11NG_HT40PLUS;
273 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
274 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
275 phymode = WLAN_PHYMODE_11NG_HT40MINUS;
276 else
277 phymode = WLAN_PHYMODE_11NG_HT20;
278 } else if (util_scan_entry_xrates(scan_params)) {
279 /* only 11G stations will have more than 8 rates */
280 phymode = WLAN_PHYMODE_11G;
281 } else {
282 /* Some mischievous g-only APs do not set extended rates */
283 if (util_scan_entry_rates(scan_params)) {
284 if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
285 scan_params->ie_list.rates[1]))
286 phymode = WLAN_PHYMODE_11G;
287 else
288 phymode = WLAN_PHYMODE_11B;
289 } else {
290 phymode = WLAN_PHYMODE_11B;
291 }
292 }
293
294 return phymode;
295}
296
297static QDF_STATUS
298util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
299 struct ie_header *sub_ie, qdf_size_t sub_ie_len)
300{
301 /* Walk through to check nothing is malformed */
302 while (sub_ie_len >= sizeof(struct ie_header)) {
303 /* At least one more header is present */
304 sub_ie_len -= sizeof(struct ie_header);
305
306 if (sub_ie->ie_len == 0) {
307 sub_ie += 1;
308 continue;
309 }
310 if (sub_ie_len < sub_ie->ie_len) {
311 scm_err("Incomplete corrupted IE:%x",
312 WLAN_ELEMID_CHAN_SWITCH_WRAP);
313 return QDF_STATUS_E_INVAL;
314 }
315 switch (sub_ie->ie_id) {
316 case WLAN_ELEMID_COUNTRY:
317 scan_params->ie_list.country = (uint8_t *)sub_ie;
318 break;
319 case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
320 scan_params->ie_list.widebw = (uint8_t *)sub_ie;
321 break;
322 case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
323 scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
324 break;
325 }
326 /* Consume sub info element */
327 sub_ie_len -= sub_ie->ie_len;
328 /* go to next Sub IE */
329 sub_ie = (struct ie_header *)
330 (((uint8_t *) sub_ie) +
331 sizeof(struct ie_header) + sub_ie->ie_len);
332 }
333
334 return QDF_STATUS_SUCCESS;
335}
336
Om Prakash Tripathi1d1525d2017-09-08 13:59:34 +0530337bool
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530338util_scan_is_hidden_ssid(struct ie_ssid *ssid)
339{
340 uint8_t i;
341
342 /*
343 * We flag this as Hidden SSID if the Length is 0
344 * of the SSID only contains 0's
345 */
346 if (!ssid || !ssid->ssid_len)
347 return true;
348
349 for (i = 0; i < ssid->ssid_len; i++)
350 if (ssid->ssid[i] != 0)
351 return false;
352
353 /* All 0's */
354 return true;
355}
356
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530357static QDF_STATUS
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530358util_scan_parse_extn_ie(struct scan_cache_entry *scan_params,
359 struct ie_header *ie)
360{
361 struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie;
362
363 switch (extn_ie->ie_extn_id) {
Hariharan Basuthkar738320e2018-11-26 11:19:19 +0530364 case WLAN_EXTN_ELEMID_MAX_CHAN_SWITCH_TIME:
365 scan_params->ie_list.mcst = (uint8_t *)ie;
366 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530367 case WLAN_EXTN_ELEMID_SRP:
Gyanranjan Hazarikab5d426d2017-08-22 21:45:07 -0700368 scan_params->ie_list.srp = (uint8_t *)ie;
369 break;
370 case WLAN_EXTN_ELEMID_HECAP:
371 scan_params->ie_list.hecap = (uint8_t *)ie;
372 break;
373 case WLAN_EXTN_ELEMID_HEOP:
374 scan_params->ie_list.heop = (uint8_t *)ie;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530375 break;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530376 case WLAN_EXTN_ELEMID_ESP:
377 scan_params->ie_list.esp = (uint8_t *)ie;
378 break;
Rhythm Patwaa6ba9ee2018-05-23 19:29:57 -0700379 case WLAN_EXTN_ELEMID_MUEDCA:
380 scan_params->ie_list.muedca = (uint8_t *)ie;
381 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530382 default:
383 break;
384 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530385 return QDF_STATUS_SUCCESS;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530386}
387
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530388static QDF_STATUS
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530389util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
390 struct ie_header *ie)
391{
Jeff Johnson82eb2122019-03-20 12:16:13 -0700392 if (!scan_params->ie_list.vendor)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530393 scan_params->ie_list.vendor = (uint8_t *)ie;
394
395 if (is_wpa_oui((uint8_t *)ie)) {
396 scan_params->ie_list.wpa = (uint8_t *)ie;
397 } else if (is_wps_oui((uint8_t *)ie)) {
398 scan_params->ie_list.wps = (uint8_t *)ie;
399 /* WCN IE should be a subset of WPS IE */
400 if (is_wcn_oui((uint8_t *)ie))
401 scan_params->ie_list.wcn = (uint8_t *)ie;
402 } else if (is_wme_param((uint8_t *)ie)) {
403 scan_params->ie_list.wmeparam = (uint8_t *)ie;
404 } else if (is_wme_info((uint8_t *)ie)) {
405 scan_params->ie_list.wmeinfo = (uint8_t *)ie;
406 } else if (is_atheros_oui((uint8_t *)ie)) {
407 scan_params->ie_list.athcaps = (uint8_t *)ie;
408 } else if (is_atheros_extcap_oui((uint8_t *)ie)) {
409 scan_params->ie_list.athextcaps = (uint8_t *)ie;
410 } else if (is_sfa_oui((uint8_t *)ie)) {
411 scan_params->ie_list.sfa = (uint8_t *)ie;
412 } else if (is_p2p_oui((uint8_t *)ie)) {
413 scan_params->ie_list.p2p = (uint8_t *)ie;
Bharat Bhushan Chakravarty145d3932017-03-20 12:52:16 -0700414 } else if (is_qca_son_oui((uint8_t *)ie,
415 QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530416 scan_params->ie_list.sonadv = (uint8_t *)ie;
417 } else if (is_ht_cap((uint8_t *)ie)) {
418 /* we only care if there isn't already an HT IE (ANA) */
Jeff Johnson82eb2122019-03-20 12:16:13 -0700419 if (!scan_params->ie_list.htcap) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530420 if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN +
421 sizeof(struct htcap_cmn_ie)))
422 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530423 scan_params->ie_list.htcap =
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530424 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
425 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530426 } else if (is_ht_info((uint8_t *)ie)) {
427 /* we only care if there isn't already an HT IE (ANA) */
Jeff Johnson82eb2122019-03-20 12:16:13 -0700428 if (!scan_params->ie_list.htinfo) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530429 if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN +
430 sizeof(struct wlan_ie_htinfo_cmn))
431 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530432 scan_params->ie_list.htinfo =
433 (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
434 ie)->hi_ie);
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530435 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530436 } else if (is_interop_vht((uint8_t *)ie) &&
Min Liub2183122019-05-17 13:29:00 +0800437 !(scan_params->ie_list.vhtcap)) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530438 uint8_t *vendor_ie = (uint8_t *)(ie);
439
440 if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
441 sizeof(struct wlan_ie_vhtcaps)) -
442 sizeof(struct ie_header)))
443 return QDF_STATUS_E_INVAL;
444 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET;
445 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) -
446 sizeof(struct ie_header))
447 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530448 /* location where Interop Vht Cap IE and VHT OP IE Present */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530449 scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) +
450 WLAN_VENDOR_VHTCAP_IE_OFFSET);
451 if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
452 sizeof(struct wlan_ie_vhtcaps)) -
Min Liub2183122019-05-17 13:29:00 +0800453 sizeof(struct ie_header))) {
454 if (ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET +
455 sizeof(struct wlan_ie_vhtop)) -
456 sizeof(struct ie_header)))
457 return QDF_STATUS_E_INVAL;
458 vendor_ie = ((uint8_t *)(ie)) +
459 WLAN_VENDOR_VHTOP_IE_OFFSET;
460 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) -
461 sizeof(struct ie_header)))
462 return QDF_STATUS_E_INVAL;
463 scan_params->ie_list.vhtop = (((uint8_t *)(ie)) +
464 WLAN_VENDOR_VHTOP_IE_OFFSET);
465 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530466 } else if (is_bwnss_oui((uint8_t *)ie)) {
467 /*
468 * Bandwidth-NSS map has sub-type & version.
469 * hence copy data just after version byte
470 */
471 scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
Abhishek Singh7b599032017-11-10 14:42:31 +0530472 } else if (is_mbo_oce_oui((uint8_t *)ie)) {
473 scan_params->ie_list.mbo_oce = (uint8_t *)ie;
Rathees kumar Chinannanb8f2d082018-07-04 15:51:51 +0530474 } else if (is_extender_oui((uint8_t *)ie)) {
475 scan_params->ie_list.extender = (uint8_t *)ie;
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +0530476 } else if (is_adaptive_11r_oui((uint8_t *)ie)) {
477 if ((ie->ie_len < OUI_LENGTH) ||
478 (ie->ie_len > MAX_ADAPTIVE_11R_IE_LEN))
479 return QDF_STATUS_E_INVAL;
480
481 scan_params->ie_list.adaptive_11r = (uint8_t *)ie +
482 sizeof(struct ie_header);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530483 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530484 return QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530485}
486
487static QDF_STATUS
488util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params)
489{
490 struct ie_header *ie, *sub_ie;
491 uint32_t ie_len, sub_ie_len;
492 QDF_STATUS status;
493
494 ie_len = util_scan_entry_ie_len(scan_params);
495 ie = (struct ie_header *)
496 util_scan_entry_ie_data(scan_params);
497
498 while (ie_len >= sizeof(struct ie_header)) {
499 ie_len -= sizeof(struct ie_header);
500
501 if (!ie->ie_len) {
502 ie += 1;
503 continue;
504 }
505
506 if (ie_len < ie->ie_len) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +0530507 scm_debug("Incomplete corrupted IE:%x",
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530508 ie->ie_id);
509 return QDF_STATUS_E_INVAL;
510 }
511
512 switch (ie->ie_id) {
513 case WLAN_ELEMID_SSID:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530514 if (ie->ie_len > (sizeof(struct ie_ssid) -
515 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530516 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530517 scan_params->ie_list.ssid = (uint8_t *)ie;
518 break;
519 case WLAN_ELEMID_RATES:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530520 if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530521 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530522 scan_params->ie_list.rates = (uint8_t *)ie;
523 break;
524 case WLAN_ELEMID_DSPARMS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530525 if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN)
526 return QDF_STATUS_E_INVAL;
Abhishek Singhc05285d2018-01-12 15:19:32 +0530527 scan_params->ie_list.ds_param = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530528 scan_params->channel.chan_idx =
529 ((struct ds_ie *)ie)->cur_chan;
530 break;
531 case WLAN_ELEMID_TIM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530532 if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530533 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530534 scan_params->ie_list.tim = (uint8_t *)ie;
535 scan_params->dtim_period =
536 ((struct wlan_tim_ie *)ie)->tim_period;
537 break;
538 case WLAN_ELEMID_COUNTRY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530539 if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530540 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530541 scan_params->ie_list.country = (uint8_t *)ie;
542 break;
543 case WLAN_ELEMID_QBSS_LOAD:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530544 if (ie->ie_len != sizeof(struct qbss_load_ie) -
Jingxiang Gec5f0bd12018-06-13 18:00:02 +0800545 sizeof(struct ie_header)) {
546 /*
547 * Expected QBSS IE length is 5Bytes; For some
548 * old cisco AP, QBSS IE length is 4Bytes, which
549 * doesn't match with latest spec, So ignore
550 * QBSS IE in such case.
551 */
552 break;
553 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530554 scan_params->ie_list.qbssload = (uint8_t *)ie;
555 break;
556 case WLAN_ELEMID_CHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530557 if (ie->ie_len != WLAN_CSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530558 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530559 scan_params->ie_list.csa = (uint8_t *)ie;
560 break;
561 case WLAN_ELEMID_IBSSDFS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530562 if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530563 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530564 scan_params->ie_list.ibssdfs = (uint8_t *)ie;
565 break;
566 case WLAN_ELEMID_QUIET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530567 if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530568 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530569 scan_params->ie_list.quiet = (uint8_t *)ie;
570 break;
571 case WLAN_ELEMID_ERP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530572 if (ie->ie_len != (sizeof(struct erp_ie) -
573 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530574 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530575 scan_params->erp = ((struct erp_ie *)ie)->value;
576 break;
577 case WLAN_ELEMID_HTCAP_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530578 if (ie->ie_len != sizeof(struct htcap_cmn_ie))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530579 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530580 scan_params->ie_list.htcap =
581 (uint8_t *)&(((struct htcap_ie *)ie)->ie);
582 break;
583 case WLAN_ELEMID_RSN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530584 if (ie->ie_len < WLAN_RSN_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530585 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530586 scan_params->ie_list.rsn = (uint8_t *)ie;
587 break;
588 case WLAN_ELEMID_XRATES:
589 scan_params->ie_list.xrates = (uint8_t *)ie;
590 break;
591 case WLAN_ELEMID_EXTCHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530592 if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530593 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530594 scan_params->ie_list.xcsa = (uint8_t *)ie;
595 break;
596 case WLAN_ELEMID_SECCHANOFFSET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530597 if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530598 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530599 scan_params->ie_list.secchanoff = (uint8_t *)ie;
600 break;
601 case WLAN_ELEMID_HTINFO_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530602 if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530603 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530604 scan_params->ie_list.htinfo =
605 (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
606 scan_params->channel.chan_idx =
607 ((struct wlan_ie_htinfo_cmn *)
608 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
609 break;
610 case WLAN_ELEMID_WAPI:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530611 if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530612 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530613 scan_params->ie_list.wapi = (uint8_t *)ie;
614 break;
615 case WLAN_ELEMID_XCAPS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530616 if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530617 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530618 scan_params->ie_list.extcaps = (uint8_t *)ie;
619 break;
620 case WLAN_ELEMID_VHTCAP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530621 if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) -
622 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530623 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530624 scan_params->ie_list.vhtcap = (uint8_t *)ie;
625 break;
626 case WLAN_ELEMID_VHTOP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530627 if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) -
628 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530629 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530630 scan_params->ie_list.vhtop = (uint8_t *)ie;
631 break;
632 case WLAN_ELEMID_OP_MODE_NOTIFY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530633 if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530634 goto err;
wadesongd58eaf42018-05-23 11:30:02 +0800635 scan_params->ie_list.opmode = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530636 break;
637 case WLAN_ELEMID_MOBILITY_DOMAIN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530638 if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530639 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530640 scan_params->ie_list.mdie = (uint8_t *)ie;
641 break;
642 case WLAN_ELEMID_VENDOR:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530643 status = util_scan_parse_vendor_ie(scan_params,
644 ie);
645 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530646 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530647 break;
648 case WLAN_ELEMID_CHAN_SWITCH_WRAP:
649 scan_params->ie_list.cswrp = (uint8_t *)ie;
650 /* Go to next sub IE */
651 sub_ie = (struct ie_header *)
652 (((uint8_t *)ie) + sizeof(struct ie_header));
653 sub_ie_len = ie->ie_len;
654 status =
655 util_scan_parse_chan_switch_wrapper_ie(
656 scan_params, sub_ie, sub_ie_len);
657 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530658 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530659 }
660 break;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530661 case WLAN_ELEMID_FILS_INDICATION:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530662 if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530663 goto err;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530664 scan_params->ie_list.fils_indication = (uint8_t *)ie;
665 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530666 case WLAN_ELEMID_EXTN_ELEM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530667 status = util_scan_parse_extn_ie(scan_params, ie);
668 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530669 goto err_status;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530670 break;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530671 default:
672 break;
673 }
674
675 /* Consume info element */
676 ie_len -= ie->ie_len;
677 /* Go to next IE */
678 ie = (struct ie_header *)
679 (((uint8_t *) ie) +
680 sizeof(struct ie_header) +
681 ie->ie_len);
682 }
683
684 return QDF_STATUS_SUCCESS;
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530685
686err:
687 status = QDF_STATUS_E_INVAL;
688err_status:
689 scm_debug("failed to parse IE - id: %d, len: %d",
690 ie->ie_id, ie->ie_len);
691
692 return status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530693}
694
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530695/**
696 * util_scan_update_esp_data: update ESP params from beacon/probe response
697 * @esp_information: pointer to wlan_esp_information
698 * @scan_entry: new received entry
699 *
700 * The Estimated Service Parameters element is
701 * used by a AP to provide information to another STA which
702 * can then use the information as input to an algorithm to
703 * generate an estimate of throughput between the two STAs.
704 * The ESP Information List field contains from 1 to 4 ESP
705 * Information fields(each field 24 bits), each corresponding
706 * to an access category for which estimated service parameters
707 * information is provided.
708 *
709 * Return: None
710 */
711static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information,
712 struct scan_cache_entry *scan_entry)
713{
714
715 uint8_t *data;
716 int i = 0;
Sathyanarayanan0a000622017-10-10 17:17:28 +0530717 uint64_t total_elements;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530718 struct wlan_esp_info *esp_info;
719 struct wlan_esp_ie *esp_ie;
720
721 esp_ie = (struct wlan_esp_ie *)
722 util_scan_entry_esp_info(scan_entry);
723
724 total_elements = esp_ie->esp_len;
725 data = (uint8_t *)esp_ie + 3;
726 do_div(total_elements, ESP_INFORMATION_LIST_LENGTH);
727
728 if (total_elements > MAX_ESP_INFORMATION_FIELD) {
729 scm_err("No of Air time fractions are greater than supported");
730 return;
731 }
732
733 for (i = 0; i < total_elements; i++) {
734 esp_info = (struct wlan_esp_info *)data;
735 if (esp_info->access_category == ESP_AC_BK) {
736 qdf_mem_copy(&esp_information->esp_info_AC_BK,
737 data, 3);
738 data = data + ESP_INFORMATION_LIST_LENGTH;
739 continue;
740 }
741 if (esp_info->access_category == ESP_AC_BE) {
742 qdf_mem_copy(&esp_information->esp_info_AC_BE,
743 data, 3);
744 data = data + ESP_INFORMATION_LIST_LENGTH;
745 continue;
746 }
747 if (esp_info->access_category == ESP_AC_VI) {
748 qdf_mem_copy(&esp_information->esp_info_AC_VI,
749 data, 3);
750 data = data + ESP_INFORMATION_LIST_LENGTH;
751 continue;
752 }
753 if (esp_info->access_category == ESP_AC_VO) {
754 qdf_mem_copy(&esp_information->esp_info_AC_VO,
755 data, 3);
756 data = data + ESP_INFORMATION_LIST_LENGTH;
757 break;
758 }
759 }
760}
761
762/**
763 * util_scan_scm_update_bss_with_esp_dataa: calculate estimated air time
764 * fraction
765 * @scan_entry: new received entry
766 *
767 * This function process all Access category ESP params and provide
768 * best effort air time fraction.
769 * If best effort is not available, it will choose VI, VO and BK in sequence
770 *
771 */
772static void util_scan_scm_update_bss_with_esp_data(
773 struct scan_cache_entry *scan_entry)
774{
775 uint8_t air_time_fraction = 0;
776 struct wlan_esp_ie esp_information;
777
778 if (!scan_entry->ie_list.esp)
779 return;
780
781 util_scan_update_esp_data(&esp_information, scan_entry);
782
783 /*
784 * If the ESP metric is transmitting multiple airtime fractions, then
785 * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is
786 * the first one available
787 */
788 if (esp_information.esp_info_AC_BE.access_category
789 == ESP_AC_BE)
790 air_time_fraction =
791 esp_information.esp_info_AC_BE.
792 estimated_air_fraction;
793 else if (esp_information.esp_info_AC_VI.access_category
794 == ESP_AC_VI)
795 air_time_fraction =
796 esp_information.esp_info_AC_VI.
797 estimated_air_fraction;
798 else if (esp_information.esp_info_AC_VO.access_category
799 == ESP_AC_VO)
800 air_time_fraction =
801 esp_information.esp_info_AC_VO.
802 estimated_air_fraction;
803 else if (esp_information.esp_info_AC_BK.access_category
804 == ESP_AC_BK)
805 air_time_fraction =
806 esp_information.esp_info_AC_BK.
807 estimated_air_fraction;
808 scan_entry->air_time_fraction = air_time_fraction;
809}
810
811/**
812 * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP
813 * @scan_entry: new received entry
814 *
815 * Return: number of nss advertised by AP
816 */
817static int util_scan_scm_calc_nss_supported_by_ap(
818 struct scan_cache_entry *scan_params)
819{
820 struct htcap_cmn_ie *htcap;
821 struct wlan_ie_vhtcaps *vhtcaps;
822 uint8_t rx_mcs_map;
823
824 htcap = (struct htcap_cmn_ie *)
825 util_scan_entry_htcap(scan_params);
826 vhtcaps = (struct wlan_ie_vhtcaps *)
827 util_scan_entry_vhtcap(scan_params);
828 if (vhtcaps) {
829 rx_mcs_map = vhtcaps->rx_mcs_map;
830 if ((rx_mcs_map & 0xC0) != 0xC0)
831 return 4;
832
833 if ((rx_mcs_map & 0x30) != 0x30)
834 return 3;
835
836 if ((rx_mcs_map & 0x0C) != 0x0C)
837 return 2;
838 } else if (htcap) {
839 if (htcap->mcsset[3])
840 return 4;
841
842 if (htcap->mcsset[2])
843 return 3;
844
845 if (htcap->mcsset[1])
846 return 2;
847
848 }
849 return 1;
850}
851
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530852#ifdef WLAN_DFS_CHAN_HIDDEN_SSID
853QDF_STATUS
854util_scan_add_hidden_ssid(struct wlan_objmgr_pdev *pdev, qdf_nbuf_t bcnbuf)
855{
856 struct wlan_frame_hdr *hdr;
857 struct wlan_bcn_frame *bcn;
858 struct wlan_scan_obj *scan_obj;
859 struct wlan_ssid *conf_ssid;
860 struct ie_header *ie;
861 uint32_t frame_len = qdf_nbuf_len(bcnbuf);
862 uint16_t bcn_ie_offset, ssid_ie_start_offset, ssid_ie_end_offset;
863 uint16_t tmplen, ie_length;
864 uint8_t *pbeacon, *tmp;
865 bool set_ssid_flag = false;
866 struct ie_ssid *ssid;
867 uint8_t pdev_id;
868
869 if (!pdev) {
870 scm_warn("pdev: 0x%pK is NULL", pdev);
871 return QDF_STATUS_E_NULL_VALUE;
872 }
873 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
874 scan_obj = wlan_pdev_get_scan_obj(pdev);
Om Prakash Tripathi510a27c2019-03-01 11:53:18 +0530875 if (!scan_obj) {
876 scm_warn("null scan_obj");
877 return QDF_STATUS_E_NULL_VALUE;
878 }
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530879
880 conf_ssid = &scan_obj->pdev_info[pdev_id].conf_ssid;
881
882 hdr = (struct wlan_frame_hdr *)qdf_nbuf_data(bcnbuf);
883
884 /* received bssid does not match configured bssid */
885 if (qdf_mem_cmp(hdr->i_addr3, scan_obj->pdev_info[pdev_id].conf_bssid,
886 QDF_MAC_ADDR_SIZE) ||
887 conf_ssid->length == 0) {
888 return QDF_STATUS_SUCCESS;
889 }
890
891 bcn = (struct wlan_bcn_frame *)(qdf_nbuf_data(bcnbuf) + sizeof(*hdr));
892 pbeacon = (uint8_t *)bcn;
893
894 ie = (struct ie_header *)(pbeacon +
895 offsetof(struct wlan_bcn_frame, ie));
896
897 bcn_ie_offset = offsetof(struct wlan_bcn_frame, ie);
898 ie_length = (uint16_t)(frame_len - sizeof(*hdr) -
899 bcn_ie_offset);
900
901 while (ie_length >= sizeof(struct ie_header)) {
902 ie_length -= sizeof(struct ie_header);
903
904 bcn_ie_offset += sizeof(struct ie_header);
905
906 if (ie_length < ie->ie_len) {
907 scm_debug("Incomplete corrupted IE:%x", ie->ie_id);
908 return QDF_STATUS_E_INVAL;
909 }
910 if (ie->ie_id == WLAN_ELEMID_SSID) {
911 if (ie->ie_len > (sizeof(struct ie_ssid) -
912 sizeof(struct ie_header))) {
913 return QDF_STATUS_E_INVAL;
914 }
915 ssid = (struct ie_ssid *)ie;
916 if (util_scan_is_hidden_ssid(ssid)) {
917 set_ssid_flag = true;
918 ssid_ie_start_offset = bcn_ie_offset -
919 sizeof(struct ie_header);
920 ssid_ie_end_offset = bcn_ie_offset +
921 ie->ie_len;
922 }
923 }
924 if (ie->ie_len == 0) {
925 ie += 1; /* next IE */
926 continue;
927 }
928 if (ie->ie_id == WLAN_ELEMID_VENDOR &&
929 is_wps_oui((uint8_t *)ie)) {
930 set_ssid_flag = false;
931 break;
932 }
933 /* Consume info element */
934 ie_length -= ie->ie_len;
935 /* Go to next IE */
936 ie = (struct ie_header *)(((uint8_t *)ie) +
937 sizeof(struct ie_header) +
938 ie->ie_len);
939 }
940
941 if (set_ssid_flag) {
942 /* Hidden SSID if the Length is 0 */
943 if (!ssid->ssid_len) {
944 /* increase the taillength by length of ssid */
945 if (qdf_nbuf_put_tail(bcnbuf,
946 conf_ssid->length) == NULL) {
947 scm_debug("No enough tailroom");
948 return QDF_STATUS_E_NOMEM;
949 }
950 /* length of the buffer to be copied */
951 tmplen = frame_len -
952 sizeof(*hdr) - ssid_ie_end_offset;
953 /*
954 * tmp memory to copy the beacon info
955 * after ssid ie.
956 */
957 tmp = qdf_mem_malloc(tmplen * sizeof(u_int8_t));
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +0530958 if (!tmp)
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530959 return QDF_STATUS_E_NOMEM;
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +0530960
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530961 /* Copy beacon data after ssid ie to tmp */
962 qdf_nbuf_copy_bits(bcnbuf, (sizeof(*hdr) +
963 ssid_ie_end_offset), tmplen, tmp);
964 /* Add ssid length */
965 *(pbeacon + (ssid_ie_start_offset + 1))
966 = conf_ssid->length;
967 /* Insert the SSID string */
968 qdf_mem_copy((pbeacon + ssid_ie_end_offset),
969 conf_ssid->ssid, conf_ssid->length);
970 /* Copy rest of the beacon data */
971 qdf_mem_copy((pbeacon + ssid_ie_end_offset +
972 conf_ssid->length), tmp, tmplen);
973 qdf_mem_free(tmp);
974
975 /* Hidden ssid with all 0's */
976 } else if (ssid->ssid_len == conf_ssid->length) {
977 /* Insert the SSID string */
978 qdf_mem_copy((pbeacon + ssid_ie_start_offset +
979 sizeof(struct ie_header)),
980 conf_ssid->ssid, conf_ssid->length);
981 } else {
982 scm_debug("mismatch in hidden ssid length");
983 return QDF_STATUS_E_INVAL;
984 }
985 }
986 return QDF_STATUS_SUCCESS;
987}
988#endif /* WLAN_DFS_CHAN_HIDDEN_SSID */
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +0530989
990#ifdef WLAN_ADAPTIVE_11R
991/**
992 * scm_fill_adaptive_11r_cap() - Check if the AP supports adaptive 11r
993 * @scan_entry: Pointer to the scan entry
994 *
995 * Return: true if adaptive 11r is advertised else false
996 */
997static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
998{
999 uint8_t *ie;
1000 uint8_t data;
1001 bool adaptive_11r;
1002
1003 ie = util_scan_entry_adaptive_11r(scan_entry);
1004 if (!ie)
1005 return;
1006
1007 data = *(ie + OUI_LENGTH);
1008 adaptive_11r = (data & 0x1) ? true : false;
1009
1010 scan_entry->adaptive_11r_ap = adaptive_11r;
1011}
1012#else
1013static void scm_fill_adaptive_11r_cap(struct scan_cache_entry *scan_entry)
1014{
1015 scan_entry->adaptive_11r_ap = false;
1016}
1017#endif
1018
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001019static QDF_STATUS
1020util_scan_gen_scan_entry(struct wlan_objmgr_pdev *pdev,
1021 uint8_t *frame, qdf_size_t frame_len,
1022 uint32_t frm_subtype,
1023 struct mgmt_rx_event_params *rx_param,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001024 struct scan_mbssid_info *mbssid_info,
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001025 qdf_list_t *scan_list)
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301026{
1027 struct wlan_frame_hdr *hdr;
1028 struct wlan_bcn_frame *bcn;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001029 QDF_STATUS status = QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301030 struct ie_ssid *ssid;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001031 struct scan_cache_entry *scan_entry;
Abhishek Singh7b599032017-11-10 14:42:31 +05301032 struct qbss_load_ie *qbss_load;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001033 struct scan_cache_node *scan_node;
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301034 uint8_t i;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001035
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301036 scan_entry = qdf_mem_malloc_atomic(sizeof(*scan_entry));
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301037 if (!scan_entry) {
1038 scm_err("failed to allocate memory for scan_entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001039 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301040 }
1041 scan_entry->raw_frame.ptr =
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301042 qdf_mem_malloc_atomic(frame_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301043 if (!scan_entry->raw_frame.ptr) {
1044 scm_err("failed to allocate memory for frame");
1045 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001046 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301047 }
1048
1049 bcn = (struct wlan_bcn_frame *)
1050 (frame + sizeof(*hdr));
1051 hdr = (struct wlan_frame_hdr *)frame;
1052
gaurank kathpalia26f98332018-01-29 18:09:06 +05301053 /* update timestamp in nanoseconds needed by kernel layers */
Arif Hussain6fcc7902018-03-22 12:33:12 -07001054 scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns();
gaurank kathpalia26f98332018-01-29 18:09:06 +05301055
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301056 scan_entry->frm_subtype = frm_subtype;
1057 qdf_mem_copy(scan_entry->bssid.bytes,
1058 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1059 /* Scr addr */
1060 qdf_mem_copy(scan_entry->mac_addr.bytes,
1061 hdr->i_addr2, QDF_MAC_ADDR_SIZE);
1062 scan_entry->seq_num =
1063 (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
1064
1065 scan_entry->rssi_raw = rx_param->rssi;
Om Prakash Tripathi6af738b2017-08-22 15:46:38 +05301066 scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301067 scan_entry->tsf_delta = rx_param->tsf_delta;
1068
gaurank kathpalia26f98332018-01-29 18:09:06 +05301069 /* Copy per chain rssi to scan entry */
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301070 qdf_mem_copy(scan_entry->per_chain_rssi, rx_param->rssi_ctl,
gaurank kathpalia26f98332018-01-29 18:09:06 +05301071 WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
1072
Yeshwanth Sriram Guntukac4a14ea2018-09-21 15:08:46 +05301073 if (!wlan_psoc_nif_fw_ext_cap_get(wlan_pdev_get_psoc(pdev),
1074 WLAN_SOC_CEXT_HW_DB2DBM)) {
1075 for (i = 0; i < WLAN_MGMT_TXRX_HOST_MAX_ANTENNA; i++) {
1076 if (scan_entry->per_chain_rssi[i] !=
1077 WLAN_INVALID_PER_CHAIN_SNR)
1078 scan_entry->per_chain_rssi[i] +=
1079 WLAN_NOISE_FLOOR_DBM_DEFAULT;
1080 else
1081 scan_entry->per_chain_rssi[i] =
1082 WLAN_INVALID_PER_CHAIN_RSSI;
1083 }
1084 }
1085
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301086 /* store jiffies */
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001087 scan_entry->rrm_parent_tsf = (uint32_t)qdf_system_ticks();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301088
1089 scan_entry->bcn_int = le16toh(bcn->beacon_interval);
1090
1091 /*
1092 * In case if the beacon dosnt have
1093 * valid beacon interval falback to def
1094 */
1095 if (!scan_entry->bcn_int)
1096 scan_entry->bcn_int = 100;
1097 scan_entry->cap_info.value = le16toh(bcn->capability.value);
1098 qdf_mem_copy(scan_entry->tsf_info.data,
1099 bcn->timestamp, 8);
1100 scan_entry->erp = ERP_NON_ERP_PRESENT;
1101
Om Prakash Tripathicdcbb392017-04-18 18:51:20 +05301102 scan_entry->scan_entry_time =
1103 qdf_mc_timer_get_system_time();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301104
1105 scan_entry->raw_frame.len = frame_len;
1106 qdf_mem_copy(scan_entry->raw_frame.ptr,
1107 frame, frame_len);
1108 status = util_scan_populate_bcn_ie_list(scan_entry);
1109 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +05301110 scm_debug("failed to parse beacon IE");
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301111 qdf_mem_free(scan_entry->raw_frame.ptr);
1112 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001113 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301114 }
1115
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301116 ssid = (struct ie_ssid *)
1117 scan_entry->ie_list.ssid;
1118
1119 if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
1120 qdf_mem_free(scan_entry->raw_frame.ptr);
1121 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001122 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301123 }
1124
1125 if (scan_entry->ie_list.p2p)
1126 scan_entry->is_p2p = true;
1127
1128 /* If no channel info is present in beacon use meta channel */
1129 if (!scan_entry->channel.chan_idx) {
1130 scan_entry->channel.chan_idx =
1131 rx_param->channel;
1132 } else if (rx_param->channel !=
1133 scan_entry->channel.chan_idx) {
Shashikala Prabhu7edbb052018-04-12 09:55:25 +05301134 if (!wlan_reg_chan_is_49ghz(pdev, scan_entry->channel.chan_idx))
1135 scan_entry->channel_mismatch = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301136 }
1137
1138 if (util_scan_is_hidden_ssid(ssid)) {
1139 scan_entry->ie_list.ssid = NULL;
Abhishek Singh7062efa2019-03-05 15:37:07 +05301140 scan_entry->is_hidden_ssid = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301141 } else {
1142 qdf_mem_copy(scan_entry->ssid.ssid,
Harprit Chhabadaab6c10d2018-10-31 10:52:34 -07001143 ssid->ssid, ssid->ssid_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301144 scan_entry->ssid.length = ssid->ssid_len;
1145 scan_entry->hidden_ssid_timestamp =
1146 scan_entry->scan_entry_time;
1147 }
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001148 qdf_mem_copy(&scan_entry->mbssid_info, mbssid_info,
1149 sizeof(scan_entry->mbssid_info));
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301150 if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx))
1151 scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry);
1152 else
1153 scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry);
1154
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301155 scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry);
Pragaspathi Thilagaraj45a8c1e2019-04-25 17:20:59 +05301156 scm_fill_adaptive_11r_cap(scan_entry);
1157
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301158 util_scan_scm_update_bss_with_esp_data(scan_entry);
Abhishek Singh7b599032017-11-10 14:42:31 +05301159 qbss_load = (struct qbss_load_ie *)
1160 util_scan_entry_qbssload(scan_entry);
1161 if (qbss_load)
1162 scan_entry->qbss_chan_load = qbss_load->qbss_chan_load;
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301163
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301164 scan_node = qdf_mem_malloc_atomic(sizeof(*scan_node));
Sandeep Puligillac6764592017-12-05 21:01:52 -08001165 if (!scan_node) {
Om Prakash Tripathi52402552018-02-21 16:31:49 +05301166 qdf_mem_free(scan_entry->raw_frame.ptr);
Sandeep Puligillac6764592017-12-05 21:01:52 -08001167 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001168 return QDF_STATUS_E_FAILURE;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001169 }
1170
1171 scan_node->entry = scan_entry;
1172 qdf_list_insert_front(scan_list, &scan_node->node);
1173
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001174 return status;
1175}
1176
1177/**
1178 * util_scan_find_ie() - find information element
1179 * @eid: element id
1180 * @ies: pointer consisting of IEs
1181 * @len: IE length
1182 *
1183 * Return: NULL if the element ID is not found or
1184 * a pointer to the first byte of the requested
1185 * element
1186 */
1187static uint8_t *util_scan_find_ie(uint8_t eid, uint8_t *ies,
1188 int32_t len)
1189{
1190 while (len >= 2 && len >= ies[1] + 2) {
1191 if (ies[0] == eid)
1192 return ies;
1193 len -= ies[1] + 2;
1194 ies += ies[1] + 2;
1195 }
1196
1197 return NULL;
1198}
1199
1200#ifdef WLAN_FEATURE_MBSSID
1201static void util_gen_new_bssid(uint8_t *bssid, uint8_t max_bssid,
1202 uint8_t mbssid_index,
1203 uint8_t *new_bssid_addr)
1204{
1205 uint64_t bssid_tmp = 0, new_bssid = 0;
1206 uint64_t lsb_n;
1207 int i;
1208
1209 for (i = 0; i < QDF_MAC_ADDR_SIZE; i++)
1210 bssid_tmp = bssid_tmp << 8 | bssid[i];
1211
1212 lsb_n = bssid_tmp & ((1 << max_bssid) - 1);
1213 new_bssid = bssid_tmp;
1214 new_bssid &= ~((1 << max_bssid) - 1);
1215 new_bssid |= (lsb_n + mbssid_index) % (1 << max_bssid);
1216
1217 for (i = QDF_MAC_ADDR_SIZE - 1; i >= 0; i--) {
1218 new_bssid_addr[i] = new_bssid & 0xff;
1219 new_bssid = new_bssid >> 8;
1220 }
1221}
1222
1223static uint32_t util_gen_new_ie(uint8_t *ie, uint32_t ielen,
1224 uint8_t *subelement,
1225 size_t subie_len, uint8_t *new_ie)
1226{
1227 uint8_t *pos, *tmp;
1228 const uint8_t *tmp_old, *tmp_new;
1229 uint8_t *sub_copy;
1230
1231 /* copy subelement as we need to change its content to
1232 * mark an ie after it is processed.
1233 */
1234 sub_copy = qdf_mem_malloc(subie_len);
1235 if (!sub_copy)
1236 return 0;
1237 qdf_mem_copy(sub_copy, subelement, subie_len);
1238
1239 pos = &new_ie[0];
1240
1241 /* new ssid */
1242 tmp_new = util_scan_find_ie(WLAN_ELEMID_SSID, sub_copy, subie_len);
1243 if (tmp_new) {
1244 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1245 pos += (tmp_new[1] + 2);
1246 }
1247
1248 /* go through IEs in ie (skip SSID) and subelement,
1249 * merge them into new_ie
1250 */
1251 tmp_old = util_scan_find_ie(WLAN_ELEMID_SSID, ie, ielen);
1252 tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie;
1253
1254 while (tmp_old + tmp_old[1] + 2 - ie <= ielen) {
1255 if (tmp_old[0] == 0) {
1256 tmp_old++;
1257 continue;
1258 }
1259
1260 tmp = (uint8_t *)util_scan_find_ie(tmp_old[0], sub_copy,
1261 subie_len);
1262 if (!tmp) {
1263 /* ie in old ie but not in subelement */
1264 if (tmp_old[0] != WLAN_ELEMID_MULTIPLE_BSSID) {
1265 qdf_mem_copy(pos, tmp_old, tmp_old[1] + 2);
1266 pos += tmp_old[1] + 2;
1267 }
1268 } else {
1269 /* ie in transmitting ie also in subelement,
1270 * copy from subelement and flag the ie in subelement
1271 * as copied (by setting eid field to 0xff). For
1272 * vendor ie, compare OUI + type + subType to
1273 * determine if they are the same ie.
1274 */
1275 if (tmp_old[0] == WLAN_ELEMID_VENDOR) {
1276 if (!qdf_mem_cmp(tmp_old + 2, tmp + 2, 5)) {
1277 /* same vendor ie, copy from
1278 * subelement
1279 */
1280 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1281 pos += tmp[1] + 2;
1282 tmp[0] = 0xff;
1283 } else {
1284 qdf_mem_copy(pos, tmp_old,
1285 tmp_old[1] + 2);
1286 pos += tmp_old[1] + 2;
1287 }
1288 } else {
1289 /* copy ie from subelement into new ie */
1290 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1291 pos += tmp[1] + 2;
1292 tmp[0] = 0xff;
1293 }
1294 }
1295
1296 if (tmp_old + tmp_old[1] + 2 - ie == ielen)
1297 break;
1298
1299 tmp_old += tmp_old[1] + 2;
1300 }
1301
1302 /* go through subelement again to check if there is any ie not
1303 * copied to new ie, skip ssid, capability, bssid-index ie
1304 */
1305 tmp_new = sub_copy;
1306 while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
1307 if (!(tmp_new[0] == WLAN_ELEMID_NONTX_BSSID_CAP ||
1308 tmp_new[0] == WLAN_ELEMID_SSID ||
1309 tmp_new[0] == WLAN_ELEMID_MULTI_BSSID_IDX ||
1310 tmp_new[0] == 0xff)) {
1311 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1312 pos += tmp_new[1] + 2;
1313 }
1314 if (tmp_new + tmp_new[1] + 2 - sub_copy == subie_len)
1315 break;
1316 tmp_new += tmp_new[1] + 2;
1317 }
1318
1319 qdf_mem_free(sub_copy);
1320 return pos - new_ie;
1321}
1322
1323static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1324 uint8_t *frame, qdf_size_t frame_len,
1325 uint32_t frm_subtype,
1326 struct mgmt_rx_event_params *rx_param,
1327 qdf_list_t *scan_list)
1328{
1329 struct wlan_bcn_frame *bcn;
1330 struct wlan_frame_hdr *hdr;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001331 struct scan_mbssid_info mbssid_info;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001332 QDF_STATUS status;
1333 uint8_t *pos, *subelement, *mbssid_end_pos;
1334 uint8_t *tmp, *mbssid_index_ie;
1335 uint32_t subie_len, new_ie_len;
1336 uint8_t new_bssid[QDF_MAC_ADDR_SIZE], bssid[QDF_MAC_ADDR_SIZE];
1337 uint8_t *new_ie;
1338 uint8_t *ie, *new_frame = NULL;
1339 uint64_t ielen, new_frame_len;
1340
1341 hdr = (struct wlan_frame_hdr *)frame;
1342 bcn = (struct wlan_bcn_frame *)(frame + sizeof(struct wlan_frame_hdr));
1343 ie = (uint8_t *)&bcn->ie;
1344 ielen = (uint16_t)(frame_len -
1345 sizeof(struct wlan_frame_hdr) -
1346 offsetof(struct wlan_bcn_frame, ie));
1347 qdf_mem_copy(bssid, hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1348
1349 if (!util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, ie, ielen))
1350 return QDF_STATUS_E_FAILURE;
1351
1352 pos = ie;
1353
1354 new_ie = qdf_mem_malloc(MAX_IE_LEN);
Madhvapathi Sriramb73fc282019-01-07 09:12:25 +05301355 if (!new_ie)
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001356 return QDF_STATUS_E_NOMEM;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001357
1358 while (pos < ie + ielen + 2) {
1359 tmp = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, pos,
1360 ielen - (pos - ie));
1361 if (!tmp)
1362 break;
1363
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001364 mbssid_info.profile_count = 1 << tmp[2];
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001365 mbssid_end_pos = tmp + tmp[1] + 2;
1366 /* Skip Element ID, Len, MaxBSSID Indicator */
1367 if (tmp[1] < 4)
1368 break;
1369 for (subelement = tmp + 3; subelement < mbssid_end_pos - 1;
1370 subelement += 2 + subelement[1]) {
1371 subie_len = subelement[1];
1372 if (mbssid_end_pos - subelement < 2 + subie_len)
1373 break;
1374 if (subelement[0] != 0 || subelement[1] < 4) {
1375 /* not a valid BSS profile */
1376 continue;
1377 }
1378
1379 if (subelement[2] != WLAN_ELEMID_NONTX_BSSID_CAP ||
1380 subelement[3] != 2) {
1381 /* The first element within the Nontransmitted
1382 * BSSID Profile is not the Nontransmitted
1383 * BSSID Capability element.
1384 */
1385 continue;
1386 }
1387
1388 /* found a Nontransmitted BSSID Profile */
1389 mbssid_index_ie =
1390 util_scan_find_ie(WLAN_ELEMID_MULTI_BSSID_IDX,
1391 subelement + 2, subie_len);
1392 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 ||
1393 mbssid_index_ie[2] == 0) {
1394 /* No valid Multiple BSSID-Index element */
1395 continue;
1396 }
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001397 qdf_mem_copy(&mbssid_info.trans_bssid, bssid,
1398 QDF_MAC_ADDR_SIZE);
1399 mbssid_info.profile_num = mbssid_index_ie[2];
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001400 util_gen_new_bssid(bssid, tmp[2], mbssid_index_ie[2],
1401 new_bssid);
1402 new_ie_len = util_gen_new_ie(ie, ielen, subelement + 2,
1403 subie_len, new_ie);
1404 if (!new_ie_len)
1405 continue;
1406
1407 new_frame_len = frame_len - ielen + new_ie_len;
1408 new_frame = qdf_mem_malloc(new_frame_len);
1409 if (!new_frame) {
1410 qdf_mem_free(new_ie);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001411 return QDF_STATUS_E_NOMEM;
1412 }
1413
1414 /*
1415 * Copy the header(24byte), timestamp(8 byte),
1416 * beaconinterval(2byte) and capability(2byte)
1417 */
1418 qdf_mem_copy(new_frame, frame, 36);
1419 /* Copy the new ie generated from MBSSID profile*/
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001420 hdr = (struct wlan_frame_hdr *)new_frame;
1421 qdf_mem_copy(hdr->i_addr2, new_bssid,
1422 QDF_MAC_ADDR_SIZE);
1423 qdf_mem_copy(hdr->i_addr3, new_bssid,
1424 QDF_MAC_ADDR_SIZE);
1425 /* Copy the new ie generated from MBSSID profile*/
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001426 qdf_mem_copy(new_frame +
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001427 offsetof(struct wlan_bcn_frame, ie) +
1428 sizeof(struct wlan_frame_hdr),
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001429 new_ie, new_ie_len);
1430 status = util_scan_gen_scan_entry(pdev, new_frame,
1431 new_frame_len,
1432 frm_subtype,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001433 rx_param,
1434 &mbssid_info,
1435 scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001436 if (QDF_IS_STATUS_ERROR(status)) {
1437 qdf_mem_free(new_frame);
1438 scm_err("failed to generate a scan entry");
1439 break;
1440 }
1441 /* scan entry makes its own copy so free the frame*/
1442 qdf_mem_free(new_frame);
1443 }
1444
1445 pos = mbssid_end_pos;
1446 }
1447 qdf_mem_free(new_ie);
1448
1449 return QDF_STATUS_SUCCESS;
1450}
1451#else
1452static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1453 uint8_t *frame, qdf_size_t frame_len,
1454 uint32_t frm_subtype,
1455 struct mgmt_rx_event_params *rx_param,
1456 qdf_list_t *scan_list)
1457{
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001458 return QDF_STATUS_SUCCESS;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001459}
1460#endif
1461
1462static QDF_STATUS
1463util_scan_parse_beacon_frame(struct wlan_objmgr_pdev *pdev,
1464 uint8_t *frame,
1465 qdf_size_t frame_len,
1466 uint32_t frm_subtype,
1467 struct mgmt_rx_event_params *rx_param,
1468 qdf_list_t *scan_list)
1469{
1470 struct wlan_bcn_frame *bcn;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001471 struct wlan_frame_hdr *hdr;
1472 uint8_t *mbssid_ie = NULL;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001473 uint32_t ie_len = 0;
1474 QDF_STATUS status;
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001475 struct scan_mbssid_info mbssid_info = { 0 };
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001476
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001477 hdr = (struct wlan_frame_hdr *)frame;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001478 bcn = (struct wlan_bcn_frame *)
1479 (frame + sizeof(struct wlan_frame_hdr));
1480 ie_len = (uint16_t)(frame_len -
1481 sizeof(struct wlan_frame_hdr) -
1482 offsetof(struct wlan_bcn_frame, ie));
1483
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001484 mbssid_ie = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID,
1485 (uint8_t *)&bcn->ie, ie_len);
1486 if (mbssid_ie) {
1487 qdf_mem_copy(&mbssid_info.trans_bssid,
1488 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1489 mbssid_info.profile_count = 1 << mbssid_ie[2];
1490 }
1491
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001492 status = util_scan_gen_scan_entry(pdev, frame, frame_len,
1493 frm_subtype, rx_param,
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001494 &mbssid_info,
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001495 scan_list);
1496
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001497 /*
1498 * IF MBSSID IE is present in the beacon then
1499 * scan component will create a new entry for
1500 * each BSSID found in the MBSSID
1501 */
Sandeep Puligilla949faf52019-02-15 10:32:00 -08001502 if (mbssid_ie)
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301503 status = util_scan_parse_mbssid(pdev, frame, frame_len,
1504 frm_subtype, rx_param,
1505 scan_list);
Sandeep Puligillada4a4522019-01-23 13:54:38 -08001506
Om Prakash Tripathi0e3c5412019-04-08 15:01:34 +05301507 if (QDF_IS_STATUS_ERROR(status))
1508 scm_debug_rl("Failed to create a scan entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001509
1510 return status;
1511}
1512
1513qdf_list_t *
1514util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame,
1515 qdf_size_t frame_len, uint32_t frm_subtype,
1516 struct mgmt_rx_event_params *rx_param)
1517{
1518 qdf_list_t *scan_list;
1519 QDF_STATUS status;
1520
1521 scan_list = qdf_mem_malloc_atomic(sizeof(*scan_list));
1522 if (!scan_list) {
1523 scm_err("failed to allocate scan_list");
1524 return NULL;
1525 }
1526 qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE);
1527
1528 status = util_scan_parse_beacon_frame(pdev, frame, frame_len,
1529 frm_subtype, rx_param,
1530 scan_list);
1531 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301532 ucfg_scan_purge_results(scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001533 return NULL;
1534 }
1535
Sandeep Puligillac6764592017-12-05 21:01:52 -08001536 return scan_list;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301537}
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301538
1539QDF_STATUS
1540util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev,
1541 struct scan_cache_entry *scan_entry)
1542{
1543
1544 if (!pdev || !scan_entry) {
Jeff Johnson878533e2017-09-18 10:07:54 -07001545 scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry);
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301546 return QDF_STATUS_E_INVAL;
1547 }
1548
1549 return scm_update_scan_mlme_info(pdev, scan_entry);
1550}
Sandeep Puligillaf57464c2017-11-16 23:31:52 -08001551
1552bool util_is_scan_completed(struct scan_event *event, bool *success)
1553{
1554 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) ||
1555 (event->type == SCAN_EVENT_TYPE_DEQUEUED) ||
1556 (event->type == SCAN_EVENT_TYPE_START_FAILED)) {
1557 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
1558 (event->reason == SCAN_REASON_COMPLETED))
1559 *success = true;
1560 else
1561 *success = false;
1562
1563 return true;
1564 }
1565
1566 *success = false;
1567 return false;
1568}
1569