blob: 456a6b42beb7d69d442dd1303420406cde76b706 [file] [log] [blame]
Om Prakash Tripathi7e3f45d2016-12-28 16:58:54 +05301/*
wadesong49ae4cb2018-01-22 15:03:12 +08002 * Copyright (c) 2017-2018 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
104 return scan_obj->pdev_info[pdev_id].last_scan_time;
105}
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530106
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530107enum wlan_band util_scan_scm_chan_to_band(uint32_t chan)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530108{
109 if (WLAN_CHAN_IS_2GHZ(chan))
110 return WLAN_BAND_2_4_GHZ;
111
112 return WLAN_BAND_5_GHZ;
113}
114
Shashikala Prabhu48ecda82018-04-13 01:13:30 +0530115enum wlan_band util_scan_scm_freq_to_band(uint16_t freq)
116{
117 if (WLAN_REG_IS_24GHZ_CH_FREQ(freq))
118 return WLAN_BAND_2_4_GHZ;
119
120 return WLAN_BAND_5_GHZ;
121}
122
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530123bool util_is_scan_entry_match(
124 struct scan_cache_entry *entry1,
125 struct scan_cache_entry *entry2)
126{
127
128 if (entry1->cap_info.wlan_caps.ess !=
wadesong49ae4cb2018-01-22 15:03:12 +0800129 entry2->cap_info.wlan_caps.ess)
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530130 return false;
131
132 if (entry1->cap_info.wlan_caps.ess &&
133 !qdf_mem_cmp(entry1->bssid.bytes,
Yeshwanth Sriram Guntukadca006c2018-11-16 17:58:08 +0530134 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530135 /* Check for BSS */
Yeshwanth Sriram Guntuka294ce112018-10-23 16:49:19 +0530136 if (util_is_ssid_match(&entry1->ssid, &entry2->ssid) ||
Yeshwanth Sriram Guntukadca006c2018-11-16 17:58:08 +0530137 util_scan_is_null_ssid(&entry1->ssid) ||
138 util_scan_is_null_ssid(&entry2->ssid))
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530139 return true;
140 } else if (entry1->cap_info.wlan_caps.ibss &&
141 (entry1->channel.chan_idx ==
142 entry2->channel.chan_idx)) {
143 /*
144 * Same channel cannot have same SSID for
145 * different IBSS, so no need to check BSSID
146 */
147 if (util_is_ssid_match(
148 &entry1->ssid, &entry2->ssid))
149 return true;
150 } else if (!entry1->cap_info.wlan_caps.ibss &&
151 !entry1->cap_info.wlan_caps.ess &&
152 !qdf_mem_cmp(entry1->bssid.bytes,
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530153 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530154 /* In case of P2P devices, ess and ibss will be set to zero */
155 return true;
156 }
157
158 return false;
159}
160
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530161static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates)
162{
163 static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108};
164 bool pureg = false;
165 uint8_t i, j;
166
167 for (i = 0; i < nrates; i++) {
168 for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) {
169 if (WLAN_RV(rates[i]) == g_rates[j]) {
170 pureg = true;
171 break;
172 }
173 }
174 if (pureg)
175 break;
176 }
177
178 return pureg;
179}
180static enum wlan_phymode
181util_scan_get_phymode_5g(struct scan_cache_entry *scan_params)
182{
183 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
184 uint16_t ht_cap = 0;
185 struct htcap_cmn_ie *htcap;
186 struct wlan_ie_htinfo_cmn *htinfo;
187 struct wlan_ie_vhtop *vhtop;
188
189 htcap = (struct htcap_cmn_ie *)
190 util_scan_entry_htcap(scan_params);
191 htinfo = (struct wlan_ie_htinfo_cmn *)
192 util_scan_entry_htinfo(scan_params);
193 vhtop = (struct wlan_ie_vhtop *)
194 util_scan_entry_vhtop(scan_params);
195
196 if (!(htcap && htinfo))
197 return WLAN_PHYMODE_11A;
198
199 if (htcap)
200 ht_cap = le16toh(htcap->hc_cap);
201
202 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
203 switch (vhtop->vht_op_chwidth) {
204 case WLAN_VHTOP_CHWIDTH_2040:
205 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
206 (htinfo->hi_extchoff ==
207 WLAN_HTINFO_EXTOFFSET_ABOVE))
208 phymode = WLAN_PHYMODE_11AC_VHT40PLUS;
209 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
210 (htinfo->hi_extchoff ==
211 WLAN_HTINFO_EXTOFFSET_BELOW))
212 phymode = WLAN_PHYMODE_11AC_VHT40MINUS;
213 else
214 phymode = WLAN_PHYMODE_11AC_VHT20;
215 break;
216 case WLAN_VHTOP_CHWIDTH_80:
217 if (WLAN_IS_REVSIG_VHT80_80(vhtop))
218 phymode = WLAN_PHYMODE_11AC_VHT80_80;
219 else if (WLAN_IS_REVSIG_VHT160(vhtop))
220 phymode = WLAN_PHYMODE_11AC_VHT160;
221 else
222 phymode = WLAN_PHYMODE_11AC_VHT80;
223 break;
224 case WLAN_VHTOP_CHWIDTH_160:
225 phymode = WLAN_PHYMODE_11AC_VHT160;
226 break;
227 case WLAN_VHTOP_CHWIDTH_80_80:
228 phymode = WLAN_PHYMODE_11AC_VHT80_80;
229 break;
230 default:
231 scm_err("bad channel: %d",
232 vhtop->vht_op_chwidth);
233 break;
234 }
235 } else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
236 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
237 phymode = WLAN_PHYMODE_11NA_HT40PLUS;
238 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
239 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
240 phymode = WLAN_PHYMODE_11NA_HT40MINUS;
241 else
242 phymode = WLAN_PHYMODE_11NA_HT20;
243
244 return phymode;
245}
246
247static enum wlan_phymode
248util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
249{
250 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
251 uint16_t ht_cap = 0;
252 struct htcap_cmn_ie *htcap;
253 struct wlan_ie_htinfo_cmn *htinfo;
254 struct wlan_ie_vhtop *vhtop;
255
256 htcap = (struct htcap_cmn_ie *)
257 util_scan_entry_htcap(scan_params);
258 htinfo = (struct wlan_ie_htinfo_cmn *)
259 util_scan_entry_htinfo(scan_params);
260 vhtop = (struct wlan_ie_vhtop *)
261 util_scan_entry_vhtop(scan_params);
262
263 if (htcap)
264 ht_cap = le16toh(htcap->hc_cap);
265
266 if (htcap && htinfo) {
267 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
268 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
269 phymode = WLAN_PHYMODE_11NG_HT40PLUS;
270 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
271 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
272 phymode = WLAN_PHYMODE_11NG_HT40MINUS;
273 else
274 phymode = WLAN_PHYMODE_11NG_HT20;
275 } else if (util_scan_entry_xrates(scan_params)) {
276 /* only 11G stations will have more than 8 rates */
277 phymode = WLAN_PHYMODE_11G;
278 } else {
279 /* Some mischievous g-only APs do not set extended rates */
280 if (util_scan_entry_rates(scan_params)) {
281 if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
282 scan_params->ie_list.rates[1]))
283 phymode = WLAN_PHYMODE_11G;
284 else
285 phymode = WLAN_PHYMODE_11B;
286 } else {
287 phymode = WLAN_PHYMODE_11B;
288 }
289 }
290
291 return phymode;
292}
293
294static QDF_STATUS
295util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
296 struct ie_header *sub_ie, qdf_size_t sub_ie_len)
297{
298 /* Walk through to check nothing is malformed */
299 while (sub_ie_len >= sizeof(struct ie_header)) {
300 /* At least one more header is present */
301 sub_ie_len -= sizeof(struct ie_header);
302
303 if (sub_ie->ie_len == 0) {
304 sub_ie += 1;
305 continue;
306 }
307 if (sub_ie_len < sub_ie->ie_len) {
308 scm_err("Incomplete corrupted IE:%x",
309 WLAN_ELEMID_CHAN_SWITCH_WRAP);
310 return QDF_STATUS_E_INVAL;
311 }
312 switch (sub_ie->ie_id) {
313 case WLAN_ELEMID_COUNTRY:
314 scan_params->ie_list.country = (uint8_t *)sub_ie;
315 break;
316 case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
317 scan_params->ie_list.widebw = (uint8_t *)sub_ie;
318 break;
319 case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
320 scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
321 break;
322 }
323 /* Consume sub info element */
324 sub_ie_len -= sub_ie->ie_len;
325 /* go to next Sub IE */
326 sub_ie = (struct ie_header *)
327 (((uint8_t *) sub_ie) +
328 sizeof(struct ie_header) + sub_ie->ie_len);
329 }
330
331 return QDF_STATUS_SUCCESS;
332}
333
Om Prakash Tripathi1d1525d2017-09-08 13:59:34 +0530334bool
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530335util_scan_is_hidden_ssid(struct ie_ssid *ssid)
336{
337 uint8_t i;
338
339 /*
340 * We flag this as Hidden SSID if the Length is 0
341 * of the SSID only contains 0's
342 */
343 if (!ssid || !ssid->ssid_len)
344 return true;
345
346 for (i = 0; i < ssid->ssid_len; i++)
347 if (ssid->ssid[i] != 0)
348 return false;
349
350 /* All 0's */
351 return true;
352}
353
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530354static QDF_STATUS
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530355util_scan_parse_extn_ie(struct scan_cache_entry *scan_params,
356 struct ie_header *ie)
357{
358 struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie;
359
360 switch (extn_ie->ie_extn_id) {
361 case WLAN_EXTN_ELEMID_SRP:
Gyanranjan Hazarikab5d426d2017-08-22 21:45:07 -0700362 scan_params->ie_list.srp = (uint8_t *)ie;
363 break;
364 case WLAN_EXTN_ELEMID_HECAP:
365 scan_params->ie_list.hecap = (uint8_t *)ie;
366 break;
367 case WLAN_EXTN_ELEMID_HEOP:
368 scan_params->ie_list.heop = (uint8_t *)ie;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530369 break;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530370 case WLAN_EXTN_ELEMID_ESP:
371 scan_params->ie_list.esp = (uint8_t *)ie;
372 break;
Rhythm Patwaa6ba9ee2018-05-23 19:29:57 -0700373 case WLAN_EXTN_ELEMID_MUEDCA:
374 scan_params->ie_list.muedca = (uint8_t *)ie;
375 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530376 default:
377 break;
378 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530379 return QDF_STATUS_SUCCESS;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530380}
381
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530382static QDF_STATUS
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530383util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
384 struct ie_header *ie)
385{
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530386 if (scan_params->ie_list.vendor == NULL)
387 scan_params->ie_list.vendor = (uint8_t *)ie;
388
389 if (is_wpa_oui((uint8_t *)ie)) {
390 scan_params->ie_list.wpa = (uint8_t *)ie;
391 } else if (is_wps_oui((uint8_t *)ie)) {
392 scan_params->ie_list.wps = (uint8_t *)ie;
393 /* WCN IE should be a subset of WPS IE */
394 if (is_wcn_oui((uint8_t *)ie))
395 scan_params->ie_list.wcn = (uint8_t *)ie;
396 } else if (is_wme_param((uint8_t *)ie)) {
397 scan_params->ie_list.wmeparam = (uint8_t *)ie;
398 } else if (is_wme_info((uint8_t *)ie)) {
399 scan_params->ie_list.wmeinfo = (uint8_t *)ie;
400 } else if (is_atheros_oui((uint8_t *)ie)) {
401 scan_params->ie_list.athcaps = (uint8_t *)ie;
402 } else if (is_atheros_extcap_oui((uint8_t *)ie)) {
403 scan_params->ie_list.athextcaps = (uint8_t *)ie;
404 } else if (is_sfa_oui((uint8_t *)ie)) {
405 scan_params->ie_list.sfa = (uint8_t *)ie;
406 } else if (is_p2p_oui((uint8_t *)ie)) {
407 scan_params->ie_list.p2p = (uint8_t *)ie;
Bharat Bhushan Chakravarty145d3932017-03-20 12:52:16 -0700408 } else if (is_qca_son_oui((uint8_t *)ie,
409 QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530410 scan_params->ie_list.sonadv = (uint8_t *)ie;
411 } else if (is_ht_cap((uint8_t *)ie)) {
412 /* we only care if there isn't already an HT IE (ANA) */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530413 if (scan_params->ie_list.htcap == NULL) {
414 if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN +
415 sizeof(struct htcap_cmn_ie)))
416 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530417 scan_params->ie_list.htcap =
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530418 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
419 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530420 } else if (is_ht_info((uint8_t *)ie)) {
421 /* we only care if there isn't already an HT IE (ANA) */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530422 if (scan_params->ie_list.htinfo == NULL) {
423 if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN +
424 sizeof(struct wlan_ie_htinfo_cmn))
425 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530426 scan_params->ie_list.htinfo =
427 (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
428 ie)->hi_ie);
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530429 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530430 } else if (is_interop_vht((uint8_t *)ie) &&
431 !(scan_params->ie_list.vhtop)) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530432 uint8_t *vendor_ie = (uint8_t *)(ie);
433
434 if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
435 sizeof(struct wlan_ie_vhtcaps)) -
436 sizeof(struct ie_header)))
437 return QDF_STATUS_E_INVAL;
438 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET;
439 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) -
440 sizeof(struct ie_header))
441 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530442 /* location where Interop Vht Cap IE and VHT OP IE Present */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530443 scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) +
444 WLAN_VENDOR_VHTCAP_IE_OFFSET);
445 if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
446 sizeof(struct wlan_ie_vhtcaps)) -
447 sizeof(struct ie_header)) &&
448 ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET +
449 sizeof(struct wlan_ie_vhtop)) -
450 sizeof(struct ie_header)))
451 return QDF_STATUS_E_INVAL;
452 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTOP_IE_OFFSET;
453 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) -
454 sizeof(struct ie_header)))
455 return QDF_STATUS_E_INVAL;
456 scan_params->ie_list.vhtop = (((uint8_t *)(ie)) +
457 WLAN_VENDOR_VHTOP_IE_OFFSET);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530458 } else if (is_bwnss_oui((uint8_t *)ie)) {
459 /*
460 * Bandwidth-NSS map has sub-type & version.
461 * hence copy data just after version byte
462 */
463 scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
Abhishek Singh7b599032017-11-10 14:42:31 +0530464 } else if (is_mbo_oce_oui((uint8_t *)ie)) {
465 scan_params->ie_list.mbo_oce = (uint8_t *)ie;
Rathees kumar Chinannanb8f2d082018-07-04 15:51:51 +0530466 } else if (is_extender_oui((uint8_t *)ie)) {
467 scan_params->ie_list.extender = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530468 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530469 return QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530470}
471
472static QDF_STATUS
473util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params)
474{
475 struct ie_header *ie, *sub_ie;
476 uint32_t ie_len, sub_ie_len;
477 QDF_STATUS status;
478
479 ie_len = util_scan_entry_ie_len(scan_params);
480 ie = (struct ie_header *)
481 util_scan_entry_ie_data(scan_params);
482
483 while (ie_len >= sizeof(struct ie_header)) {
484 ie_len -= sizeof(struct ie_header);
485
486 if (!ie->ie_len) {
487 ie += 1;
488 continue;
489 }
490
491 if (ie_len < ie->ie_len) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +0530492 scm_debug("Incomplete corrupted IE:%x",
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530493 ie->ie_id);
494 return QDF_STATUS_E_INVAL;
495 }
496
497 switch (ie->ie_id) {
498 case WLAN_ELEMID_SSID:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530499 if (ie->ie_len > (sizeof(struct ie_ssid) -
500 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530501 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530502 scan_params->ie_list.ssid = (uint8_t *)ie;
503 break;
504 case WLAN_ELEMID_RATES:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530505 if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530506 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530507 scan_params->ie_list.rates = (uint8_t *)ie;
508 break;
509 case WLAN_ELEMID_DSPARMS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530510 if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN)
511 return QDF_STATUS_E_INVAL;
Abhishek Singhc05285d2018-01-12 15:19:32 +0530512 scan_params->ie_list.ds_param = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530513 scan_params->channel.chan_idx =
514 ((struct ds_ie *)ie)->cur_chan;
515 break;
516 case WLAN_ELEMID_TIM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530517 if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530518 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530519 scan_params->ie_list.tim = (uint8_t *)ie;
520 scan_params->dtim_period =
521 ((struct wlan_tim_ie *)ie)->tim_period;
522 break;
523 case WLAN_ELEMID_COUNTRY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530524 if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530525 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530526 scan_params->ie_list.country = (uint8_t *)ie;
527 break;
528 case WLAN_ELEMID_QBSS_LOAD:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530529 if (ie->ie_len != sizeof(struct qbss_load_ie) -
Jingxiang Gec5f0bd12018-06-13 18:00:02 +0800530 sizeof(struct ie_header)) {
531 /*
532 * Expected QBSS IE length is 5Bytes; For some
533 * old cisco AP, QBSS IE length is 4Bytes, which
534 * doesn't match with latest spec, So ignore
535 * QBSS IE in such case.
536 */
537 break;
538 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530539 scan_params->ie_list.qbssload = (uint8_t *)ie;
540 break;
541 case WLAN_ELEMID_CHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530542 if (ie->ie_len != WLAN_CSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530543 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530544 scan_params->ie_list.csa = (uint8_t *)ie;
545 break;
546 case WLAN_ELEMID_IBSSDFS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530547 if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530548 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530549 scan_params->ie_list.ibssdfs = (uint8_t *)ie;
550 break;
551 case WLAN_ELEMID_QUIET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530552 if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530553 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530554 scan_params->ie_list.quiet = (uint8_t *)ie;
555 break;
556 case WLAN_ELEMID_ERP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530557 if (ie->ie_len != (sizeof(struct erp_ie) -
558 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530559 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530560 scan_params->erp = ((struct erp_ie *)ie)->value;
561 break;
562 case WLAN_ELEMID_HTCAP_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530563 if (ie->ie_len != sizeof(struct htcap_cmn_ie))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530564 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530565 scan_params->ie_list.htcap =
566 (uint8_t *)&(((struct htcap_ie *)ie)->ie);
567 break;
568 case WLAN_ELEMID_RSN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530569 if (ie->ie_len < WLAN_RSN_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530570 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530571 scan_params->ie_list.rsn = (uint8_t *)ie;
572 break;
573 case WLAN_ELEMID_XRATES:
574 scan_params->ie_list.xrates = (uint8_t *)ie;
575 break;
576 case WLAN_ELEMID_EXTCHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530577 if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530578 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530579 scan_params->ie_list.xcsa = (uint8_t *)ie;
580 break;
581 case WLAN_ELEMID_SECCHANOFFSET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530582 if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530583 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530584 scan_params->ie_list.secchanoff = (uint8_t *)ie;
585 break;
586 case WLAN_ELEMID_HTINFO_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530587 if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530588 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530589 scan_params->ie_list.htinfo =
590 (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
591 scan_params->channel.chan_idx =
592 ((struct wlan_ie_htinfo_cmn *)
593 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
594 break;
595 case WLAN_ELEMID_WAPI:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530596 if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530597 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530598 scan_params->ie_list.wapi = (uint8_t *)ie;
599 break;
600 case WLAN_ELEMID_XCAPS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530601 if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530602 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530603 scan_params->ie_list.extcaps = (uint8_t *)ie;
604 break;
605 case WLAN_ELEMID_VHTCAP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530606 if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) -
607 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530608 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530609 scan_params->ie_list.vhtcap = (uint8_t *)ie;
610 break;
611 case WLAN_ELEMID_VHTOP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530612 if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) -
613 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530614 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530615 scan_params->ie_list.vhtop = (uint8_t *)ie;
616 break;
617 case WLAN_ELEMID_OP_MODE_NOTIFY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530618 if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530619 goto err;
wadesongd58eaf42018-05-23 11:30:02 +0800620 scan_params->ie_list.opmode = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530621 break;
622 case WLAN_ELEMID_MOBILITY_DOMAIN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530623 if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530624 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530625 scan_params->ie_list.mdie = (uint8_t *)ie;
626 break;
627 case WLAN_ELEMID_VENDOR:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530628 status = util_scan_parse_vendor_ie(scan_params,
629 ie);
630 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530631 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530632 break;
633 case WLAN_ELEMID_CHAN_SWITCH_WRAP:
634 scan_params->ie_list.cswrp = (uint8_t *)ie;
635 /* Go to next sub IE */
636 sub_ie = (struct ie_header *)
637 (((uint8_t *)ie) + sizeof(struct ie_header));
638 sub_ie_len = ie->ie_len;
639 status =
640 util_scan_parse_chan_switch_wrapper_ie(
641 scan_params, sub_ie, sub_ie_len);
642 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530643 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530644 }
645 break;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530646 case WLAN_ELEMID_FILS_INDICATION:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530647 if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530648 goto err;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530649 scan_params->ie_list.fils_indication = (uint8_t *)ie;
650 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530651 case WLAN_ELEMID_EXTN_ELEM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530652 status = util_scan_parse_extn_ie(scan_params, ie);
653 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530654 goto err_status;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530655 break;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530656 default:
657 break;
658 }
659
660 /* Consume info element */
661 ie_len -= ie->ie_len;
662 /* Go to next IE */
663 ie = (struct ie_header *)
664 (((uint8_t *) ie) +
665 sizeof(struct ie_header) +
666 ie->ie_len);
667 }
668
669 return QDF_STATUS_SUCCESS;
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530670
671err:
672 status = QDF_STATUS_E_INVAL;
673err_status:
674 scm_debug("failed to parse IE - id: %d, len: %d",
675 ie->ie_id, ie->ie_len);
676
677 return status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530678}
679
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530680/**
681 * util_scan_update_esp_data: update ESP params from beacon/probe response
682 * @esp_information: pointer to wlan_esp_information
683 * @scan_entry: new received entry
684 *
685 * The Estimated Service Parameters element is
686 * used by a AP to provide information to another STA which
687 * can then use the information as input to an algorithm to
688 * generate an estimate of throughput between the two STAs.
689 * The ESP Information List field contains from 1 to 4 ESP
690 * Information fields(each field 24 bits), each corresponding
691 * to an access category for which estimated service parameters
692 * information is provided.
693 *
694 * Return: None
695 */
696static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information,
697 struct scan_cache_entry *scan_entry)
698{
699
700 uint8_t *data;
701 int i = 0;
Sathyanarayanan0a000622017-10-10 17:17:28 +0530702 uint64_t total_elements;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530703 struct wlan_esp_info *esp_info;
704 struct wlan_esp_ie *esp_ie;
705
706 esp_ie = (struct wlan_esp_ie *)
707 util_scan_entry_esp_info(scan_entry);
708
709 total_elements = esp_ie->esp_len;
710 data = (uint8_t *)esp_ie + 3;
711 do_div(total_elements, ESP_INFORMATION_LIST_LENGTH);
712
713 if (total_elements > MAX_ESP_INFORMATION_FIELD) {
714 scm_err("No of Air time fractions are greater than supported");
715 return;
716 }
717
718 for (i = 0; i < total_elements; i++) {
719 esp_info = (struct wlan_esp_info *)data;
720 if (esp_info->access_category == ESP_AC_BK) {
721 qdf_mem_copy(&esp_information->esp_info_AC_BK,
722 data, 3);
723 data = data + ESP_INFORMATION_LIST_LENGTH;
724 continue;
725 }
726 if (esp_info->access_category == ESP_AC_BE) {
727 qdf_mem_copy(&esp_information->esp_info_AC_BE,
728 data, 3);
729 data = data + ESP_INFORMATION_LIST_LENGTH;
730 continue;
731 }
732 if (esp_info->access_category == ESP_AC_VI) {
733 qdf_mem_copy(&esp_information->esp_info_AC_VI,
734 data, 3);
735 data = data + ESP_INFORMATION_LIST_LENGTH;
736 continue;
737 }
738 if (esp_info->access_category == ESP_AC_VO) {
739 qdf_mem_copy(&esp_information->esp_info_AC_VO,
740 data, 3);
741 data = data + ESP_INFORMATION_LIST_LENGTH;
742 break;
743 }
744 }
745}
746
747/**
748 * util_scan_scm_update_bss_with_esp_dataa: calculate estimated air time
749 * fraction
750 * @scan_entry: new received entry
751 *
752 * This function process all Access category ESP params and provide
753 * best effort air time fraction.
754 * If best effort is not available, it will choose VI, VO and BK in sequence
755 *
756 */
757static void util_scan_scm_update_bss_with_esp_data(
758 struct scan_cache_entry *scan_entry)
759{
760 uint8_t air_time_fraction = 0;
761 struct wlan_esp_ie esp_information;
762
763 if (!scan_entry->ie_list.esp)
764 return;
765
766 util_scan_update_esp_data(&esp_information, scan_entry);
767
768 /*
769 * If the ESP metric is transmitting multiple airtime fractions, then
770 * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is
771 * the first one available
772 */
773 if (esp_information.esp_info_AC_BE.access_category
774 == ESP_AC_BE)
775 air_time_fraction =
776 esp_information.esp_info_AC_BE.
777 estimated_air_fraction;
778 else if (esp_information.esp_info_AC_VI.access_category
779 == ESP_AC_VI)
780 air_time_fraction =
781 esp_information.esp_info_AC_VI.
782 estimated_air_fraction;
783 else if (esp_information.esp_info_AC_VO.access_category
784 == ESP_AC_VO)
785 air_time_fraction =
786 esp_information.esp_info_AC_VO.
787 estimated_air_fraction;
788 else if (esp_information.esp_info_AC_BK.access_category
789 == ESP_AC_BK)
790 air_time_fraction =
791 esp_information.esp_info_AC_BK.
792 estimated_air_fraction;
793 scan_entry->air_time_fraction = air_time_fraction;
794}
795
796/**
797 * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP
798 * @scan_entry: new received entry
799 *
800 * Return: number of nss advertised by AP
801 */
802static int util_scan_scm_calc_nss_supported_by_ap(
803 struct scan_cache_entry *scan_params)
804{
805 struct htcap_cmn_ie *htcap;
806 struct wlan_ie_vhtcaps *vhtcaps;
807 uint8_t rx_mcs_map;
808
809 htcap = (struct htcap_cmn_ie *)
810 util_scan_entry_htcap(scan_params);
811 vhtcaps = (struct wlan_ie_vhtcaps *)
812 util_scan_entry_vhtcap(scan_params);
813 if (vhtcaps) {
814 rx_mcs_map = vhtcaps->rx_mcs_map;
815 if ((rx_mcs_map & 0xC0) != 0xC0)
816 return 4;
817
818 if ((rx_mcs_map & 0x30) != 0x30)
819 return 3;
820
821 if ((rx_mcs_map & 0x0C) != 0x0C)
822 return 2;
823 } else if (htcap) {
824 if (htcap->mcsset[3])
825 return 4;
826
827 if (htcap->mcsset[2])
828 return 3;
829
830 if (htcap->mcsset[1])
831 return 2;
832
833 }
834 return 1;
835}
836
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530837#ifdef WLAN_DFS_CHAN_HIDDEN_SSID
838QDF_STATUS
839util_scan_add_hidden_ssid(struct wlan_objmgr_pdev *pdev, qdf_nbuf_t bcnbuf)
840{
841 struct wlan_frame_hdr *hdr;
842 struct wlan_bcn_frame *bcn;
843 struct wlan_scan_obj *scan_obj;
844 struct wlan_ssid *conf_ssid;
845 struct ie_header *ie;
846 uint32_t frame_len = qdf_nbuf_len(bcnbuf);
847 uint16_t bcn_ie_offset, ssid_ie_start_offset, ssid_ie_end_offset;
848 uint16_t tmplen, ie_length;
849 uint8_t *pbeacon, *tmp;
850 bool set_ssid_flag = false;
851 struct ie_ssid *ssid;
852 uint8_t pdev_id;
853
854 if (!pdev) {
855 scm_warn("pdev: 0x%pK is NULL", pdev);
856 return QDF_STATUS_E_NULL_VALUE;
857 }
858 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
859 scan_obj = wlan_pdev_get_scan_obj(pdev);
860
861 conf_ssid = &scan_obj->pdev_info[pdev_id].conf_ssid;
862
863 hdr = (struct wlan_frame_hdr *)qdf_nbuf_data(bcnbuf);
864
865 /* received bssid does not match configured bssid */
866 if (qdf_mem_cmp(hdr->i_addr3, scan_obj->pdev_info[pdev_id].conf_bssid,
867 QDF_MAC_ADDR_SIZE) ||
868 conf_ssid->length == 0) {
869 return QDF_STATUS_SUCCESS;
870 }
871
872 bcn = (struct wlan_bcn_frame *)(qdf_nbuf_data(bcnbuf) + sizeof(*hdr));
873 pbeacon = (uint8_t *)bcn;
874
875 ie = (struct ie_header *)(pbeacon +
876 offsetof(struct wlan_bcn_frame, ie));
877
878 bcn_ie_offset = offsetof(struct wlan_bcn_frame, ie);
879 ie_length = (uint16_t)(frame_len - sizeof(*hdr) -
880 bcn_ie_offset);
881
882 while (ie_length >= sizeof(struct ie_header)) {
883 ie_length -= sizeof(struct ie_header);
884
885 bcn_ie_offset += sizeof(struct ie_header);
886
887 if (ie_length < ie->ie_len) {
888 scm_debug("Incomplete corrupted IE:%x", ie->ie_id);
889 return QDF_STATUS_E_INVAL;
890 }
891 if (ie->ie_id == WLAN_ELEMID_SSID) {
892 if (ie->ie_len > (sizeof(struct ie_ssid) -
893 sizeof(struct ie_header))) {
894 return QDF_STATUS_E_INVAL;
895 }
896 ssid = (struct ie_ssid *)ie;
897 if (util_scan_is_hidden_ssid(ssid)) {
898 set_ssid_flag = true;
899 ssid_ie_start_offset = bcn_ie_offset -
900 sizeof(struct ie_header);
901 ssid_ie_end_offset = bcn_ie_offset +
902 ie->ie_len;
903 }
904 }
905 if (ie->ie_len == 0) {
906 ie += 1; /* next IE */
907 continue;
908 }
909 if (ie->ie_id == WLAN_ELEMID_VENDOR &&
910 is_wps_oui((uint8_t *)ie)) {
911 set_ssid_flag = false;
912 break;
913 }
914 /* Consume info element */
915 ie_length -= ie->ie_len;
916 /* Go to next IE */
917 ie = (struct ie_header *)(((uint8_t *)ie) +
918 sizeof(struct ie_header) +
919 ie->ie_len);
920 }
921
922 if (set_ssid_flag) {
923 /* Hidden SSID if the Length is 0 */
924 if (!ssid->ssid_len) {
925 /* increase the taillength by length of ssid */
926 if (qdf_nbuf_put_tail(bcnbuf,
927 conf_ssid->length) == NULL) {
928 scm_debug("No enough tailroom");
929 return QDF_STATUS_E_NOMEM;
930 }
931 /* length of the buffer to be copied */
932 tmplen = frame_len -
933 sizeof(*hdr) - ssid_ie_end_offset;
934 /*
935 * tmp memory to copy the beacon info
936 * after ssid ie.
937 */
938 tmp = qdf_mem_malloc(tmplen * sizeof(u_int8_t));
939 if (!tmp) {
940 scm_debug("tmp memory alloc failed");
941 return QDF_STATUS_E_NOMEM;
942 }
943 /* Copy beacon data after ssid ie to tmp */
944 qdf_nbuf_copy_bits(bcnbuf, (sizeof(*hdr) +
945 ssid_ie_end_offset), tmplen, tmp);
946 /* Add ssid length */
947 *(pbeacon + (ssid_ie_start_offset + 1))
948 = conf_ssid->length;
949 /* Insert the SSID string */
950 qdf_mem_copy((pbeacon + ssid_ie_end_offset),
951 conf_ssid->ssid, conf_ssid->length);
952 /* Copy rest of the beacon data */
953 qdf_mem_copy((pbeacon + ssid_ie_end_offset +
954 conf_ssid->length), tmp, tmplen);
955 qdf_mem_free(tmp);
956
957 /* Hidden ssid with all 0's */
958 } else if (ssid->ssid_len == conf_ssid->length) {
959 /* Insert the SSID string */
960 qdf_mem_copy((pbeacon + ssid_ie_start_offset +
961 sizeof(struct ie_header)),
962 conf_ssid->ssid, conf_ssid->length);
963 } else {
964 scm_debug("mismatch in hidden ssid length");
965 return QDF_STATUS_E_INVAL;
966 }
967 }
968 return QDF_STATUS_SUCCESS;
969}
970#endif /* WLAN_DFS_CHAN_HIDDEN_SSID */
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700971static QDF_STATUS
972util_scan_gen_scan_entry(struct wlan_objmgr_pdev *pdev,
973 uint8_t *frame, qdf_size_t frame_len,
974 uint32_t frm_subtype,
975 struct mgmt_rx_event_params *rx_param,
976 qdf_list_t *scan_list)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530977{
978 struct wlan_frame_hdr *hdr;
979 struct wlan_bcn_frame *bcn;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700980 QDF_STATUS status = QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530981 struct ie_ssid *ssid;
Sandeep Puligillac6764592017-12-05 21:01:52 -0800982 struct scan_cache_entry *scan_entry;
Abhishek Singh7b599032017-11-10 14:42:31 +0530983 struct qbss_load_ie *qbss_load;
Sandeep Puligillac6764592017-12-05 21:01:52 -0800984 struct scan_cache_node *scan_node;
985
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +0530986 scan_entry = qdf_mem_malloc_atomic(sizeof(*scan_entry));
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530987 if (!scan_entry) {
988 scm_err("failed to allocate memory for scan_entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700989 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530990 }
991 scan_entry->raw_frame.ptr =
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +0530992 qdf_mem_malloc_atomic(frame_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530993 if (!scan_entry->raw_frame.ptr) {
994 scm_err("failed to allocate memory for frame");
995 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700996 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530997 }
998
999 bcn = (struct wlan_bcn_frame *)
1000 (frame + sizeof(*hdr));
1001 hdr = (struct wlan_frame_hdr *)frame;
1002
gaurank kathpalia26f98332018-01-29 18:09:06 +05301003 /* update timestamp in nanoseconds needed by kernel layers */
Arif Hussain6fcc7902018-03-22 12:33:12 -07001004 scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns();
gaurank kathpalia26f98332018-01-29 18:09:06 +05301005
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301006 scan_entry->frm_subtype = frm_subtype;
1007 qdf_mem_copy(scan_entry->bssid.bytes,
1008 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1009 /* Scr addr */
1010 qdf_mem_copy(scan_entry->mac_addr.bytes,
1011 hdr->i_addr2, QDF_MAC_ADDR_SIZE);
1012 scan_entry->seq_num =
1013 (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
1014
1015 scan_entry->rssi_raw = rx_param->rssi;
Om Prakash Tripathi6af738b2017-08-22 15:46:38 +05301016 scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301017 scan_entry->tsf_delta = rx_param->tsf_delta;
1018
gaurank kathpalia26f98332018-01-29 18:09:06 +05301019 /* Copy per chain rssi to scan entry */
1020 qdf_mem_copy(scan_entry->per_chain_snr, rx_param->rssi_ctl,
1021 WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
1022
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301023 /* store jiffies */
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001024 scan_entry->rrm_parent_tsf = (uint32_t)qdf_system_ticks();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301025
1026 scan_entry->bcn_int = le16toh(bcn->beacon_interval);
1027
1028 /*
1029 * In case if the beacon dosnt have
1030 * valid beacon interval falback to def
1031 */
1032 if (!scan_entry->bcn_int)
1033 scan_entry->bcn_int = 100;
1034 scan_entry->cap_info.value = le16toh(bcn->capability.value);
1035 qdf_mem_copy(scan_entry->tsf_info.data,
1036 bcn->timestamp, 8);
1037 scan_entry->erp = ERP_NON_ERP_PRESENT;
1038
Om Prakash Tripathicdcbb392017-04-18 18:51:20 +05301039 scan_entry->scan_entry_time =
1040 qdf_mc_timer_get_system_time();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301041
1042 scan_entry->raw_frame.len = frame_len;
1043 qdf_mem_copy(scan_entry->raw_frame.ptr,
1044 frame, frame_len);
1045 status = util_scan_populate_bcn_ie_list(scan_entry);
1046 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +05301047 scm_debug("failed to parse beacon IE");
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301048 qdf_mem_free(scan_entry->raw_frame.ptr);
1049 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001050 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301051 }
1052
1053 if (!scan_entry->ie_list.rates) {
1054 qdf_mem_free(scan_entry->raw_frame.ptr);
1055 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001056 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301057 }
1058
1059 ssid = (struct ie_ssid *)
1060 scan_entry->ie_list.ssid;
1061
1062 if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
1063 qdf_mem_free(scan_entry->raw_frame.ptr);
1064 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001065 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301066 }
1067
1068 if (scan_entry->ie_list.p2p)
1069 scan_entry->is_p2p = true;
1070
1071 /* If no channel info is present in beacon use meta channel */
1072 if (!scan_entry->channel.chan_idx) {
1073 scan_entry->channel.chan_idx =
1074 rx_param->channel;
1075 } else if (rx_param->channel !=
1076 scan_entry->channel.chan_idx) {
Shashikala Prabhu7edbb052018-04-12 09:55:25 +05301077 if (!wlan_reg_chan_is_49ghz(pdev, scan_entry->channel.chan_idx))
1078 scan_entry->channel_mismatch = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301079 }
1080
1081 if (util_scan_is_hidden_ssid(ssid)) {
1082 scan_entry->ie_list.ssid = NULL;
1083 } else {
1084 qdf_mem_copy(scan_entry->ssid.ssid,
Harprit Chhabadaab6c10d2018-10-31 10:52:34 -07001085 ssid->ssid, ssid->ssid_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301086 scan_entry->ssid.length = ssid->ssid_len;
1087 scan_entry->hidden_ssid_timestamp =
1088 scan_entry->scan_entry_time;
1089 }
1090
1091 if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx))
1092 scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry);
1093 else
1094 scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry);
1095
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301096 scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry);
1097 util_scan_scm_update_bss_with_esp_data(scan_entry);
Abhishek Singh7b599032017-11-10 14:42:31 +05301098 qbss_load = (struct qbss_load_ie *)
1099 util_scan_entry_qbssload(scan_entry);
1100 if (qbss_load)
1101 scan_entry->qbss_chan_load = qbss_load->qbss_chan_load;
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301102
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301103 scan_node = qdf_mem_malloc_atomic(sizeof(*scan_node));
Sandeep Puligillac6764592017-12-05 21:01:52 -08001104 if (!scan_node) {
Om Prakash Tripathi52402552018-02-21 16:31:49 +05301105 qdf_mem_free(scan_entry->raw_frame.ptr);
Sandeep Puligillac6764592017-12-05 21:01:52 -08001106 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001107 return QDF_STATUS_E_FAILURE;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001108 }
1109
1110 scan_node->entry = scan_entry;
1111 qdf_list_insert_front(scan_list, &scan_node->node);
1112
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001113 return status;
1114}
1115
1116/**
1117 * util_scan_find_ie() - find information element
1118 * @eid: element id
1119 * @ies: pointer consisting of IEs
1120 * @len: IE length
1121 *
1122 * Return: NULL if the element ID is not found or
1123 * a pointer to the first byte of the requested
1124 * element
1125 */
1126static uint8_t *util_scan_find_ie(uint8_t eid, uint8_t *ies,
1127 int32_t len)
1128{
1129 while (len >= 2 && len >= ies[1] + 2) {
1130 if (ies[0] == eid)
1131 return ies;
1132 len -= ies[1] + 2;
1133 ies += ies[1] + 2;
1134 }
1135
1136 return NULL;
1137}
1138
1139#ifdef WLAN_FEATURE_MBSSID
1140static void util_gen_new_bssid(uint8_t *bssid, uint8_t max_bssid,
1141 uint8_t mbssid_index,
1142 uint8_t *new_bssid_addr)
1143{
1144 uint64_t bssid_tmp = 0, new_bssid = 0;
1145 uint64_t lsb_n;
1146 int i;
1147
1148 for (i = 0; i < QDF_MAC_ADDR_SIZE; i++)
1149 bssid_tmp = bssid_tmp << 8 | bssid[i];
1150
1151 lsb_n = bssid_tmp & ((1 << max_bssid) - 1);
1152 new_bssid = bssid_tmp;
1153 new_bssid &= ~((1 << max_bssid) - 1);
1154 new_bssid |= (lsb_n + mbssid_index) % (1 << max_bssid);
1155
1156 for (i = QDF_MAC_ADDR_SIZE - 1; i >= 0; i--) {
1157 new_bssid_addr[i] = new_bssid & 0xff;
1158 new_bssid = new_bssid >> 8;
1159 }
1160}
1161
1162static uint32_t util_gen_new_ie(uint8_t *ie, uint32_t ielen,
1163 uint8_t *subelement,
1164 size_t subie_len, uint8_t *new_ie)
1165{
1166 uint8_t *pos, *tmp;
1167 const uint8_t *tmp_old, *tmp_new;
1168 uint8_t *sub_copy;
1169
1170 /* copy subelement as we need to change its content to
1171 * mark an ie after it is processed.
1172 */
1173 sub_copy = qdf_mem_malloc(subie_len);
1174 if (!sub_copy)
1175 return 0;
1176 qdf_mem_copy(sub_copy, subelement, subie_len);
1177
1178 pos = &new_ie[0];
1179
1180 /* new ssid */
1181 tmp_new = util_scan_find_ie(WLAN_ELEMID_SSID, sub_copy, subie_len);
1182 if (tmp_new) {
1183 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1184 pos += (tmp_new[1] + 2);
1185 }
1186
1187 /* go through IEs in ie (skip SSID) and subelement,
1188 * merge them into new_ie
1189 */
1190 tmp_old = util_scan_find_ie(WLAN_ELEMID_SSID, ie, ielen);
1191 tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie;
1192
1193 while (tmp_old + tmp_old[1] + 2 - ie <= ielen) {
1194 if (tmp_old[0] == 0) {
1195 tmp_old++;
1196 continue;
1197 }
1198
1199 tmp = (uint8_t *)util_scan_find_ie(tmp_old[0], sub_copy,
1200 subie_len);
1201 if (!tmp) {
1202 /* ie in old ie but not in subelement */
1203 if (tmp_old[0] != WLAN_ELEMID_MULTIPLE_BSSID) {
1204 qdf_mem_copy(pos, tmp_old, tmp_old[1] + 2);
1205 pos += tmp_old[1] + 2;
1206 }
1207 } else {
1208 /* ie in transmitting ie also in subelement,
1209 * copy from subelement and flag the ie in subelement
1210 * as copied (by setting eid field to 0xff). For
1211 * vendor ie, compare OUI + type + subType to
1212 * determine if they are the same ie.
1213 */
1214 if (tmp_old[0] == WLAN_ELEMID_VENDOR) {
1215 if (!qdf_mem_cmp(tmp_old + 2, tmp + 2, 5)) {
1216 /* same vendor ie, copy from
1217 * subelement
1218 */
1219 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1220 pos += tmp[1] + 2;
1221 tmp[0] = 0xff;
1222 } else {
1223 qdf_mem_copy(pos, tmp_old,
1224 tmp_old[1] + 2);
1225 pos += tmp_old[1] + 2;
1226 }
1227 } else {
1228 /* copy ie from subelement into new ie */
1229 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1230 pos += tmp[1] + 2;
1231 tmp[0] = 0xff;
1232 }
1233 }
1234
1235 if (tmp_old + tmp_old[1] + 2 - ie == ielen)
1236 break;
1237
1238 tmp_old += tmp_old[1] + 2;
1239 }
1240
1241 /* go through subelement again to check if there is any ie not
1242 * copied to new ie, skip ssid, capability, bssid-index ie
1243 */
1244 tmp_new = sub_copy;
1245 while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
1246 if (!(tmp_new[0] == WLAN_ELEMID_NONTX_BSSID_CAP ||
1247 tmp_new[0] == WLAN_ELEMID_SSID ||
1248 tmp_new[0] == WLAN_ELEMID_MULTI_BSSID_IDX ||
1249 tmp_new[0] == 0xff)) {
1250 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1251 pos += tmp_new[1] + 2;
1252 }
1253 if (tmp_new + tmp_new[1] + 2 - sub_copy == subie_len)
1254 break;
1255 tmp_new += tmp_new[1] + 2;
1256 }
1257
1258 qdf_mem_free(sub_copy);
1259 return pos - new_ie;
1260}
1261
1262static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1263 uint8_t *frame, qdf_size_t frame_len,
1264 uint32_t frm_subtype,
1265 struct mgmt_rx_event_params *rx_param,
1266 qdf_list_t *scan_list)
1267{
1268 struct wlan_bcn_frame *bcn;
1269 struct wlan_frame_hdr *hdr;
1270 QDF_STATUS status;
1271 uint8_t *pos, *subelement, *mbssid_end_pos;
1272 uint8_t *tmp, *mbssid_index_ie;
1273 uint32_t subie_len, new_ie_len;
1274 uint8_t new_bssid[QDF_MAC_ADDR_SIZE], bssid[QDF_MAC_ADDR_SIZE];
1275 uint8_t *new_ie;
1276 uint8_t *ie, *new_frame = NULL;
1277 uint64_t ielen, new_frame_len;
1278
1279 hdr = (struct wlan_frame_hdr *)frame;
1280 bcn = (struct wlan_bcn_frame *)(frame + sizeof(struct wlan_frame_hdr));
1281 ie = (uint8_t *)&bcn->ie;
1282 ielen = (uint16_t)(frame_len -
1283 sizeof(struct wlan_frame_hdr) -
1284 offsetof(struct wlan_bcn_frame, ie));
1285 qdf_mem_copy(bssid, hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1286
1287 if (!util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, ie, ielen))
1288 return QDF_STATUS_E_FAILURE;
1289
1290 pos = ie;
1291
1292 new_ie = qdf_mem_malloc(MAX_IE_LEN);
1293 if (!new_ie) {
1294 scm_err("Failed to allocate memory for new ie");
1295 return QDF_STATUS_E_NOMEM;
1296 }
1297
1298 while (pos < ie + ielen + 2) {
1299 tmp = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, pos,
1300 ielen - (pos - ie));
1301 if (!tmp)
1302 break;
1303
1304 mbssid_end_pos = tmp + tmp[1] + 2;
1305 /* Skip Element ID, Len, MaxBSSID Indicator */
1306 if (tmp[1] < 4)
1307 break;
1308 for (subelement = tmp + 3; subelement < mbssid_end_pos - 1;
1309 subelement += 2 + subelement[1]) {
1310 subie_len = subelement[1];
1311 if (mbssid_end_pos - subelement < 2 + subie_len)
1312 break;
1313 if (subelement[0] != 0 || subelement[1] < 4) {
1314 /* not a valid BSS profile */
1315 continue;
1316 }
1317
1318 if (subelement[2] != WLAN_ELEMID_NONTX_BSSID_CAP ||
1319 subelement[3] != 2) {
1320 /* The first element within the Nontransmitted
1321 * BSSID Profile is not the Nontransmitted
1322 * BSSID Capability element.
1323 */
1324 continue;
1325 }
1326
1327 /* found a Nontransmitted BSSID Profile */
1328 mbssid_index_ie =
1329 util_scan_find_ie(WLAN_ELEMID_MULTI_BSSID_IDX,
1330 subelement + 2, subie_len);
1331 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 ||
1332 mbssid_index_ie[2] == 0) {
1333 /* No valid Multiple BSSID-Index element */
1334 continue;
1335 }
1336
1337 util_gen_new_bssid(bssid, tmp[2], mbssid_index_ie[2],
1338 new_bssid);
1339 new_ie_len = util_gen_new_ie(ie, ielen, subelement + 2,
1340 subie_len, new_ie);
1341 if (!new_ie_len)
1342 continue;
1343
1344 new_frame_len = frame_len - ielen + new_ie_len;
1345 new_frame = qdf_mem_malloc(new_frame_len);
1346 if (!new_frame) {
1347 qdf_mem_free(new_ie);
1348 scm_err("failed to allocate memory");
1349 return QDF_STATUS_E_NOMEM;
1350 }
1351
1352 /*
1353 * Copy the header(24byte), timestamp(8 byte),
1354 * beaconinterval(2byte) and capability(2byte)
1355 */
1356 qdf_mem_copy(new_frame, frame, 36);
1357 /* Copy the new ie generated from MBSSID profile*/
1358 qdf_mem_copy(new_frame +
1359 offsetof(struct wlan_bcn_frame, ie),
1360 new_ie, new_ie_len);
1361 status = util_scan_gen_scan_entry(pdev, new_frame,
1362 new_frame_len,
1363 frm_subtype,
1364 rx_param, scan_list);
1365 if (QDF_IS_STATUS_ERROR(status)) {
1366 qdf_mem_free(new_frame);
1367 scm_err("failed to generate a scan entry");
1368 break;
1369 }
1370 /* scan entry makes its own copy so free the frame*/
1371 qdf_mem_free(new_frame);
1372 }
1373
1374 pos = mbssid_end_pos;
1375 }
1376 qdf_mem_free(new_ie);
1377
1378 return QDF_STATUS_SUCCESS;
1379}
1380#else
1381static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1382 uint8_t *frame, qdf_size_t frame_len,
1383 uint32_t frm_subtype,
1384 struct mgmt_rx_event_params *rx_param,
1385 qdf_list_t *scan_list)
1386{
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301387 return util_scan_gen_scan_entry(pdev, frame, frame_len,
1388 frm_subtype, rx_param, scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001389}
1390#endif
1391
1392static QDF_STATUS
1393util_scan_parse_beacon_frame(struct wlan_objmgr_pdev *pdev,
1394 uint8_t *frame,
1395 qdf_size_t frame_len,
1396 uint32_t frm_subtype,
1397 struct mgmt_rx_event_params *rx_param,
1398 qdf_list_t *scan_list)
1399{
1400 struct wlan_bcn_frame *bcn;
1401 uint32_t ie_len = 0;
1402 QDF_STATUS status;
1403
1404 bcn = (struct wlan_bcn_frame *)
1405 (frame + sizeof(struct wlan_frame_hdr));
1406 ie_len = (uint16_t)(frame_len -
1407 sizeof(struct wlan_frame_hdr) -
1408 offsetof(struct wlan_bcn_frame, ie));
1409
1410 /*
1411 * IF MBSSID IE is present in the beacon then
1412 * scan component will create a new entry for
1413 * each BSSID found in the MBSSID
1414 */
1415 if (util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID,
1416 (uint8_t *)&bcn->ie, ie_len))
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301417 status = util_scan_parse_mbssid(pdev, frame, frame_len,
1418 frm_subtype, rx_param,
1419 scan_list);
1420 else
1421 status = util_scan_gen_scan_entry(pdev, frame, frame_len,
1422 frm_subtype, rx_param,
1423 scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001424 if (QDF_IS_STATUS_ERROR(status)) {
phadiman8a322292018-09-17 14:54:09 +05301425 scm_err_rl("Failed to create a scan entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001426 }
1427
1428 return status;
1429}
1430
1431qdf_list_t *
1432util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame,
1433 qdf_size_t frame_len, uint32_t frm_subtype,
1434 struct mgmt_rx_event_params *rx_param)
1435{
1436 qdf_list_t *scan_list;
1437 QDF_STATUS status;
1438
1439 scan_list = qdf_mem_malloc_atomic(sizeof(*scan_list));
1440 if (!scan_list) {
1441 scm_err("failed to allocate scan_list");
1442 return NULL;
1443 }
1444 qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE);
1445
1446 status = util_scan_parse_beacon_frame(pdev, frame, frame_len,
1447 frm_subtype, rx_param,
1448 scan_list);
1449 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301450 ucfg_scan_purge_results(scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001451 return NULL;
1452 }
1453
Sandeep Puligillac6764592017-12-05 21:01:52 -08001454 return scan_list;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301455}
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301456
1457QDF_STATUS
1458util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev,
1459 struct scan_cache_entry *scan_entry)
1460{
1461
1462 if (!pdev || !scan_entry) {
Jeff Johnson878533e2017-09-18 10:07:54 -07001463 scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry);
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301464 return QDF_STATUS_E_INVAL;
1465 }
1466
1467 return scm_update_scan_mlme_info(pdev, scan_entry);
1468}
Sandeep Puligillaf57464c2017-11-16 23:31:52 -08001469
1470bool util_is_scan_completed(struct scan_event *event, bool *success)
1471{
1472 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) ||
1473 (event->type == SCAN_EVENT_TYPE_DEQUEUED) ||
1474 (event->type == SCAN_EVENT_TYPE_START_FAILED)) {
1475 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
1476 (event->reason == SCAN_REASON_COMPLETED))
1477 *success = true;
1478 else
1479 *success = false;
1480
1481 return true;
1482 }
1483
1484 *success = false;
1485 return false;
1486}
1487