blob: 4b2691aa322417284bfd9615f7e977190ff5dbdc [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,
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530134 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE) &&
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530135 util_scan_scm_chan_to_band(
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530136 entry1->channel.chan_idx) ==
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530137 util_scan_scm_chan_to_band(entry2->channel.chan_idx)) {
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) ||
140 util_scan_is_null_ssid(&entry1->ssid))
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530141 return true;
142 } else if (entry1->cap_info.wlan_caps.ibss &&
143 (entry1->channel.chan_idx ==
144 entry2->channel.chan_idx)) {
145 /*
146 * Same channel cannot have same SSID for
147 * different IBSS, so no need to check BSSID
148 */
149 if (util_is_ssid_match(
150 &entry1->ssid, &entry2->ssid))
151 return true;
152 } else if (!entry1->cap_info.wlan_caps.ibss &&
153 !entry1->cap_info.wlan_caps.ess &&
154 !qdf_mem_cmp(entry1->bssid.bytes,
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530155 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530156 /* In case of P2P devices, ess and ibss will be set to zero */
157 return true;
158 }
159
160 return false;
161}
162
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530163static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates)
164{
165 static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108};
166 bool pureg = false;
167 uint8_t i, j;
168
169 for (i = 0; i < nrates; i++) {
170 for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) {
171 if (WLAN_RV(rates[i]) == g_rates[j]) {
172 pureg = true;
173 break;
174 }
175 }
176 if (pureg)
177 break;
178 }
179
180 return pureg;
181}
182static enum wlan_phymode
183util_scan_get_phymode_5g(struct scan_cache_entry *scan_params)
184{
185 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
186 uint16_t ht_cap = 0;
187 struct htcap_cmn_ie *htcap;
188 struct wlan_ie_htinfo_cmn *htinfo;
189 struct wlan_ie_vhtop *vhtop;
190
191 htcap = (struct htcap_cmn_ie *)
192 util_scan_entry_htcap(scan_params);
193 htinfo = (struct wlan_ie_htinfo_cmn *)
194 util_scan_entry_htinfo(scan_params);
195 vhtop = (struct wlan_ie_vhtop *)
196 util_scan_entry_vhtop(scan_params);
197
198 if (!(htcap && htinfo))
199 return WLAN_PHYMODE_11A;
200
201 if (htcap)
202 ht_cap = le16toh(htcap->hc_cap);
203
204 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
205 switch (vhtop->vht_op_chwidth) {
206 case WLAN_VHTOP_CHWIDTH_2040:
207 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
208 (htinfo->hi_extchoff ==
209 WLAN_HTINFO_EXTOFFSET_ABOVE))
210 phymode = WLAN_PHYMODE_11AC_VHT40PLUS;
211 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
212 (htinfo->hi_extchoff ==
213 WLAN_HTINFO_EXTOFFSET_BELOW))
214 phymode = WLAN_PHYMODE_11AC_VHT40MINUS;
215 else
216 phymode = WLAN_PHYMODE_11AC_VHT20;
217 break;
218 case WLAN_VHTOP_CHWIDTH_80:
219 if (WLAN_IS_REVSIG_VHT80_80(vhtop))
220 phymode = WLAN_PHYMODE_11AC_VHT80_80;
221 else if (WLAN_IS_REVSIG_VHT160(vhtop))
222 phymode = WLAN_PHYMODE_11AC_VHT160;
223 else
224 phymode = WLAN_PHYMODE_11AC_VHT80;
225 break;
226 case WLAN_VHTOP_CHWIDTH_160:
227 phymode = WLAN_PHYMODE_11AC_VHT160;
228 break;
229 case WLAN_VHTOP_CHWIDTH_80_80:
230 phymode = WLAN_PHYMODE_11AC_VHT80_80;
231 break;
232 default:
233 scm_err("bad channel: %d",
234 vhtop->vht_op_chwidth);
235 break;
236 }
237 } else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
238 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
239 phymode = WLAN_PHYMODE_11NA_HT40PLUS;
240 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
241 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
242 phymode = WLAN_PHYMODE_11NA_HT40MINUS;
243 else
244 phymode = WLAN_PHYMODE_11NA_HT20;
245
246 return phymode;
247}
248
249static enum wlan_phymode
250util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
251{
252 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
253 uint16_t ht_cap = 0;
254 struct htcap_cmn_ie *htcap;
255 struct wlan_ie_htinfo_cmn *htinfo;
256 struct wlan_ie_vhtop *vhtop;
257
258 htcap = (struct htcap_cmn_ie *)
259 util_scan_entry_htcap(scan_params);
260 htinfo = (struct wlan_ie_htinfo_cmn *)
261 util_scan_entry_htinfo(scan_params);
262 vhtop = (struct wlan_ie_vhtop *)
263 util_scan_entry_vhtop(scan_params);
264
265 if (htcap)
266 ht_cap = le16toh(htcap->hc_cap);
267
268 if (htcap && htinfo) {
269 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
270 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
271 phymode = WLAN_PHYMODE_11NG_HT40PLUS;
272 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
273 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
274 phymode = WLAN_PHYMODE_11NG_HT40MINUS;
275 else
276 phymode = WLAN_PHYMODE_11NG_HT20;
277 } else if (util_scan_entry_xrates(scan_params)) {
278 /* only 11G stations will have more than 8 rates */
279 phymode = WLAN_PHYMODE_11G;
280 } else {
281 /* Some mischievous g-only APs do not set extended rates */
282 if (util_scan_entry_rates(scan_params)) {
283 if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
284 scan_params->ie_list.rates[1]))
285 phymode = WLAN_PHYMODE_11G;
286 else
287 phymode = WLAN_PHYMODE_11B;
288 } else {
289 phymode = WLAN_PHYMODE_11B;
290 }
291 }
292
293 return phymode;
294}
295
296static QDF_STATUS
297util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
298 struct ie_header *sub_ie, qdf_size_t sub_ie_len)
299{
300 /* Walk through to check nothing is malformed */
301 while (sub_ie_len >= sizeof(struct ie_header)) {
302 /* At least one more header is present */
303 sub_ie_len -= sizeof(struct ie_header);
304
305 if (sub_ie->ie_len == 0) {
306 sub_ie += 1;
307 continue;
308 }
309 if (sub_ie_len < sub_ie->ie_len) {
310 scm_err("Incomplete corrupted IE:%x",
311 WLAN_ELEMID_CHAN_SWITCH_WRAP);
312 return QDF_STATUS_E_INVAL;
313 }
314 switch (sub_ie->ie_id) {
315 case WLAN_ELEMID_COUNTRY:
316 scan_params->ie_list.country = (uint8_t *)sub_ie;
317 break;
318 case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
319 scan_params->ie_list.widebw = (uint8_t *)sub_ie;
320 break;
321 case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
322 scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
323 break;
324 }
325 /* Consume sub info element */
326 sub_ie_len -= sub_ie->ie_len;
327 /* go to next Sub IE */
328 sub_ie = (struct ie_header *)
329 (((uint8_t *) sub_ie) +
330 sizeof(struct ie_header) + sub_ie->ie_len);
331 }
332
333 return QDF_STATUS_SUCCESS;
334}
335
Om Prakash Tripathi1d1525d2017-09-08 13:59:34 +0530336bool
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530337util_scan_is_hidden_ssid(struct ie_ssid *ssid)
338{
339 uint8_t i;
340
341 /*
342 * We flag this as Hidden SSID if the Length is 0
343 * of the SSID only contains 0's
344 */
345 if (!ssid || !ssid->ssid_len)
346 return true;
347
348 for (i = 0; i < ssid->ssid_len; i++)
349 if (ssid->ssid[i] != 0)
350 return false;
351
352 /* All 0's */
353 return true;
354}
355
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530356static QDF_STATUS
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530357util_scan_parse_extn_ie(struct scan_cache_entry *scan_params,
358 struct ie_header *ie)
359{
360 struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie;
361
362 switch (extn_ie->ie_extn_id) {
363 case WLAN_EXTN_ELEMID_SRP:
Gyanranjan Hazarikab5d426d2017-08-22 21:45:07 -0700364 scan_params->ie_list.srp = (uint8_t *)ie;
365 break;
366 case WLAN_EXTN_ELEMID_HECAP:
367 scan_params->ie_list.hecap = (uint8_t *)ie;
368 break;
369 case WLAN_EXTN_ELEMID_HEOP:
370 scan_params->ie_list.heop = (uint8_t *)ie;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530371 break;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530372 case WLAN_EXTN_ELEMID_ESP:
373 scan_params->ie_list.esp = (uint8_t *)ie;
374 break;
Rhythm Patwaa6ba9ee2018-05-23 19:29:57 -0700375 case WLAN_EXTN_ELEMID_MUEDCA:
376 scan_params->ie_list.muedca = (uint8_t *)ie;
377 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530378 default:
379 break;
380 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530381 return QDF_STATUS_SUCCESS;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530382}
383
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530384static QDF_STATUS
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530385util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
386 struct ie_header *ie)
387{
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530388 if (scan_params->ie_list.vendor == NULL)
389 scan_params->ie_list.vendor = (uint8_t *)ie;
390
391 if (is_wpa_oui((uint8_t *)ie)) {
392 scan_params->ie_list.wpa = (uint8_t *)ie;
393 } else if (is_wps_oui((uint8_t *)ie)) {
394 scan_params->ie_list.wps = (uint8_t *)ie;
395 /* WCN IE should be a subset of WPS IE */
396 if (is_wcn_oui((uint8_t *)ie))
397 scan_params->ie_list.wcn = (uint8_t *)ie;
398 } else if (is_wme_param((uint8_t *)ie)) {
399 scan_params->ie_list.wmeparam = (uint8_t *)ie;
400 } else if (is_wme_info((uint8_t *)ie)) {
401 scan_params->ie_list.wmeinfo = (uint8_t *)ie;
402 } else if (is_atheros_oui((uint8_t *)ie)) {
403 scan_params->ie_list.athcaps = (uint8_t *)ie;
404 } else if (is_atheros_extcap_oui((uint8_t *)ie)) {
405 scan_params->ie_list.athextcaps = (uint8_t *)ie;
406 } else if (is_sfa_oui((uint8_t *)ie)) {
407 scan_params->ie_list.sfa = (uint8_t *)ie;
408 } else if (is_p2p_oui((uint8_t *)ie)) {
409 scan_params->ie_list.p2p = (uint8_t *)ie;
Bharat Bhushan Chakravarty145d3932017-03-20 12:52:16 -0700410 } else if (is_qca_son_oui((uint8_t *)ie,
411 QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530412 scan_params->ie_list.sonadv = (uint8_t *)ie;
413 } else if (is_ht_cap((uint8_t *)ie)) {
414 /* we only care if there isn't already an HT IE (ANA) */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530415 if (scan_params->ie_list.htcap == NULL) {
416 if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN +
417 sizeof(struct htcap_cmn_ie)))
418 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530419 scan_params->ie_list.htcap =
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530420 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
421 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530422 } else if (is_ht_info((uint8_t *)ie)) {
423 /* we only care if there isn't already an HT IE (ANA) */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530424 if (scan_params->ie_list.htinfo == NULL) {
425 if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN +
426 sizeof(struct wlan_ie_htinfo_cmn))
427 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530428 scan_params->ie_list.htinfo =
429 (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
430 ie)->hi_ie);
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530431 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530432 } else if (is_interop_vht((uint8_t *)ie) &&
433 !(scan_params->ie_list.vhtop)) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530434 uint8_t *vendor_ie = (uint8_t *)(ie);
435
436 if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
437 sizeof(struct wlan_ie_vhtcaps)) -
438 sizeof(struct ie_header)))
439 return QDF_STATUS_E_INVAL;
440 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET;
441 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) -
442 sizeof(struct ie_header))
443 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530444 /* location where Interop Vht Cap IE and VHT OP IE Present */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530445 scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) +
446 WLAN_VENDOR_VHTCAP_IE_OFFSET);
447 if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
448 sizeof(struct wlan_ie_vhtcaps)) -
449 sizeof(struct ie_header)) &&
450 ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET +
451 sizeof(struct wlan_ie_vhtop)) -
452 sizeof(struct ie_header)))
453 return QDF_STATUS_E_INVAL;
454 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTOP_IE_OFFSET;
455 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) -
456 sizeof(struct ie_header)))
457 return QDF_STATUS_E_INVAL;
458 scan_params->ie_list.vhtop = (((uint8_t *)(ie)) +
459 WLAN_VENDOR_VHTOP_IE_OFFSET);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530460 } else if (is_bwnss_oui((uint8_t *)ie)) {
461 /*
462 * Bandwidth-NSS map has sub-type & version.
463 * hence copy data just after version byte
464 */
465 scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
Abhishek Singh7b599032017-11-10 14:42:31 +0530466 } else if (is_mbo_oce_oui((uint8_t *)ie)) {
467 scan_params->ie_list.mbo_oce = (uint8_t *)ie;
Rathees kumar Chinannanb8f2d082018-07-04 15:51:51 +0530468 } else if (is_extender_oui((uint8_t *)ie)) {
469 scan_params->ie_list.extender = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530470 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530471 return QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530472}
473
474static QDF_STATUS
475util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params)
476{
477 struct ie_header *ie, *sub_ie;
478 uint32_t ie_len, sub_ie_len;
479 QDF_STATUS status;
480
481 ie_len = util_scan_entry_ie_len(scan_params);
482 ie = (struct ie_header *)
483 util_scan_entry_ie_data(scan_params);
484
485 while (ie_len >= sizeof(struct ie_header)) {
486 ie_len -= sizeof(struct ie_header);
487
488 if (!ie->ie_len) {
489 ie += 1;
490 continue;
491 }
492
493 if (ie_len < ie->ie_len) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +0530494 scm_debug("Incomplete corrupted IE:%x",
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530495 ie->ie_id);
496 return QDF_STATUS_E_INVAL;
497 }
498
499 switch (ie->ie_id) {
500 case WLAN_ELEMID_SSID:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530501 if (ie->ie_len > (sizeof(struct ie_ssid) -
502 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530503 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530504 scan_params->ie_list.ssid = (uint8_t *)ie;
505 break;
506 case WLAN_ELEMID_RATES:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530507 if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530508 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530509 scan_params->ie_list.rates = (uint8_t *)ie;
510 break;
511 case WLAN_ELEMID_DSPARMS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530512 if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN)
513 return QDF_STATUS_E_INVAL;
Abhishek Singhc05285d2018-01-12 15:19:32 +0530514 scan_params->ie_list.ds_param = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530515 scan_params->channel.chan_idx =
516 ((struct ds_ie *)ie)->cur_chan;
517 break;
518 case WLAN_ELEMID_TIM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530519 if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530520 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530521 scan_params->ie_list.tim = (uint8_t *)ie;
522 scan_params->dtim_period =
523 ((struct wlan_tim_ie *)ie)->tim_period;
524 break;
525 case WLAN_ELEMID_COUNTRY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530526 if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530527 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530528 scan_params->ie_list.country = (uint8_t *)ie;
529 break;
530 case WLAN_ELEMID_QBSS_LOAD:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530531 if (ie->ie_len != sizeof(struct qbss_load_ie) -
Jingxiang Gec5f0bd12018-06-13 18:00:02 +0800532 sizeof(struct ie_header)) {
533 /*
534 * Expected QBSS IE length is 5Bytes; For some
535 * old cisco AP, QBSS IE length is 4Bytes, which
536 * doesn't match with latest spec, So ignore
537 * QBSS IE in such case.
538 */
539 break;
540 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530541 scan_params->ie_list.qbssload = (uint8_t *)ie;
542 break;
543 case WLAN_ELEMID_CHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530544 if (ie->ie_len != WLAN_CSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530545 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530546 scan_params->ie_list.csa = (uint8_t *)ie;
547 break;
548 case WLAN_ELEMID_IBSSDFS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530549 if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530550 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530551 scan_params->ie_list.ibssdfs = (uint8_t *)ie;
552 break;
553 case WLAN_ELEMID_QUIET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530554 if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530555 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530556 scan_params->ie_list.quiet = (uint8_t *)ie;
557 break;
558 case WLAN_ELEMID_ERP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530559 if (ie->ie_len != (sizeof(struct erp_ie) -
560 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530561 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530562 scan_params->erp = ((struct erp_ie *)ie)->value;
563 break;
564 case WLAN_ELEMID_HTCAP_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530565 if (ie->ie_len != sizeof(struct htcap_cmn_ie))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530566 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530567 scan_params->ie_list.htcap =
568 (uint8_t *)&(((struct htcap_ie *)ie)->ie);
569 break;
570 case WLAN_ELEMID_RSN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530571 if (ie->ie_len < WLAN_RSN_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530572 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530573 scan_params->ie_list.rsn = (uint8_t *)ie;
574 break;
575 case WLAN_ELEMID_XRATES:
576 scan_params->ie_list.xrates = (uint8_t *)ie;
577 break;
578 case WLAN_ELEMID_EXTCHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530579 if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530580 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530581 scan_params->ie_list.xcsa = (uint8_t *)ie;
582 break;
583 case WLAN_ELEMID_SECCHANOFFSET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530584 if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530585 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530586 scan_params->ie_list.secchanoff = (uint8_t *)ie;
587 break;
588 case WLAN_ELEMID_HTINFO_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530589 if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530590 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530591 scan_params->ie_list.htinfo =
592 (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
593 scan_params->channel.chan_idx =
594 ((struct wlan_ie_htinfo_cmn *)
595 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
596 break;
597 case WLAN_ELEMID_WAPI:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530598 if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530599 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530600 scan_params->ie_list.wapi = (uint8_t *)ie;
601 break;
602 case WLAN_ELEMID_XCAPS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530603 if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530604 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530605 scan_params->ie_list.extcaps = (uint8_t *)ie;
606 break;
607 case WLAN_ELEMID_VHTCAP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530608 if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) -
609 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530610 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530611 scan_params->ie_list.vhtcap = (uint8_t *)ie;
612 break;
613 case WLAN_ELEMID_VHTOP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530614 if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) -
615 sizeof(struct ie_header)))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530616 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530617 scan_params->ie_list.vhtop = (uint8_t *)ie;
618 break;
619 case WLAN_ELEMID_OP_MODE_NOTIFY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530620 if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530621 goto err;
wadesongd58eaf42018-05-23 11:30:02 +0800622 scan_params->ie_list.opmode = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530623 break;
624 case WLAN_ELEMID_MOBILITY_DOMAIN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530625 if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530626 goto err;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530627 scan_params->ie_list.mdie = (uint8_t *)ie;
628 break;
629 case WLAN_ELEMID_VENDOR:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530630 status = util_scan_parse_vendor_ie(scan_params,
631 ie);
632 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530633 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530634 break;
635 case WLAN_ELEMID_CHAN_SWITCH_WRAP:
636 scan_params->ie_list.cswrp = (uint8_t *)ie;
637 /* Go to next sub IE */
638 sub_ie = (struct ie_header *)
639 (((uint8_t *)ie) + sizeof(struct ie_header));
640 sub_ie_len = ie->ie_len;
641 status =
642 util_scan_parse_chan_switch_wrapper_ie(
643 scan_params, sub_ie, sub_ie_len);
644 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530645 goto err_status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530646 }
647 break;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530648 case WLAN_ELEMID_FILS_INDICATION:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530649 if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN)
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530650 goto err;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530651 scan_params->ie_list.fils_indication = (uint8_t *)ie;
652 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530653 case WLAN_ELEMID_EXTN_ELEM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530654 status = util_scan_parse_extn_ie(scan_params, ie);
655 if (QDF_IS_STATUS_ERROR(status))
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530656 goto err_status;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530657 break;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530658 default:
659 break;
660 }
661
662 /* Consume info element */
663 ie_len -= ie->ie_len;
664 /* Go to next IE */
665 ie = (struct ie_header *)
666 (((uint8_t *) ie) +
667 sizeof(struct ie_header) +
668 ie->ie_len);
669 }
670
671 return QDF_STATUS_SUCCESS;
Om Prakash Tripathi628dfd32018-10-18 16:08:28 +0530672
673err:
674 status = QDF_STATUS_E_INVAL;
675err_status:
676 scm_debug("failed to parse IE - id: %d, len: %d",
677 ie->ie_id, ie->ie_len);
678
679 return status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530680}
681
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530682/**
683 * util_scan_update_esp_data: update ESP params from beacon/probe response
684 * @esp_information: pointer to wlan_esp_information
685 * @scan_entry: new received entry
686 *
687 * The Estimated Service Parameters element is
688 * used by a AP to provide information to another STA which
689 * can then use the information as input to an algorithm to
690 * generate an estimate of throughput between the two STAs.
691 * The ESP Information List field contains from 1 to 4 ESP
692 * Information fields(each field 24 bits), each corresponding
693 * to an access category for which estimated service parameters
694 * information is provided.
695 *
696 * Return: None
697 */
698static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information,
699 struct scan_cache_entry *scan_entry)
700{
701
702 uint8_t *data;
703 int i = 0;
Sathyanarayanan0a000622017-10-10 17:17:28 +0530704 uint64_t total_elements;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530705 struct wlan_esp_info *esp_info;
706 struct wlan_esp_ie *esp_ie;
707
708 esp_ie = (struct wlan_esp_ie *)
709 util_scan_entry_esp_info(scan_entry);
710
711 total_elements = esp_ie->esp_len;
712 data = (uint8_t *)esp_ie + 3;
713 do_div(total_elements, ESP_INFORMATION_LIST_LENGTH);
714
715 if (total_elements > MAX_ESP_INFORMATION_FIELD) {
716 scm_err("No of Air time fractions are greater than supported");
717 return;
718 }
719
720 for (i = 0; i < total_elements; i++) {
721 esp_info = (struct wlan_esp_info *)data;
722 if (esp_info->access_category == ESP_AC_BK) {
723 qdf_mem_copy(&esp_information->esp_info_AC_BK,
724 data, 3);
725 data = data + ESP_INFORMATION_LIST_LENGTH;
726 continue;
727 }
728 if (esp_info->access_category == ESP_AC_BE) {
729 qdf_mem_copy(&esp_information->esp_info_AC_BE,
730 data, 3);
731 data = data + ESP_INFORMATION_LIST_LENGTH;
732 continue;
733 }
734 if (esp_info->access_category == ESP_AC_VI) {
735 qdf_mem_copy(&esp_information->esp_info_AC_VI,
736 data, 3);
737 data = data + ESP_INFORMATION_LIST_LENGTH;
738 continue;
739 }
740 if (esp_info->access_category == ESP_AC_VO) {
741 qdf_mem_copy(&esp_information->esp_info_AC_VO,
742 data, 3);
743 data = data + ESP_INFORMATION_LIST_LENGTH;
744 break;
745 }
746 }
747}
748
749/**
750 * util_scan_scm_update_bss_with_esp_dataa: calculate estimated air time
751 * fraction
752 * @scan_entry: new received entry
753 *
754 * This function process all Access category ESP params and provide
755 * best effort air time fraction.
756 * If best effort is not available, it will choose VI, VO and BK in sequence
757 *
758 */
759static void util_scan_scm_update_bss_with_esp_data(
760 struct scan_cache_entry *scan_entry)
761{
762 uint8_t air_time_fraction = 0;
763 struct wlan_esp_ie esp_information;
764
765 if (!scan_entry->ie_list.esp)
766 return;
767
768 util_scan_update_esp_data(&esp_information, scan_entry);
769
770 /*
771 * If the ESP metric is transmitting multiple airtime fractions, then
772 * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is
773 * the first one available
774 */
775 if (esp_information.esp_info_AC_BE.access_category
776 == ESP_AC_BE)
777 air_time_fraction =
778 esp_information.esp_info_AC_BE.
779 estimated_air_fraction;
780 else if (esp_information.esp_info_AC_VI.access_category
781 == ESP_AC_VI)
782 air_time_fraction =
783 esp_information.esp_info_AC_VI.
784 estimated_air_fraction;
785 else if (esp_information.esp_info_AC_VO.access_category
786 == ESP_AC_VO)
787 air_time_fraction =
788 esp_information.esp_info_AC_VO.
789 estimated_air_fraction;
790 else if (esp_information.esp_info_AC_BK.access_category
791 == ESP_AC_BK)
792 air_time_fraction =
793 esp_information.esp_info_AC_BK.
794 estimated_air_fraction;
795 scan_entry->air_time_fraction = air_time_fraction;
796}
797
798/**
799 * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP
800 * @scan_entry: new received entry
801 *
802 * Return: number of nss advertised by AP
803 */
804static int util_scan_scm_calc_nss_supported_by_ap(
805 struct scan_cache_entry *scan_params)
806{
807 struct htcap_cmn_ie *htcap;
808 struct wlan_ie_vhtcaps *vhtcaps;
809 uint8_t rx_mcs_map;
810
811 htcap = (struct htcap_cmn_ie *)
812 util_scan_entry_htcap(scan_params);
813 vhtcaps = (struct wlan_ie_vhtcaps *)
814 util_scan_entry_vhtcap(scan_params);
815 if (vhtcaps) {
816 rx_mcs_map = vhtcaps->rx_mcs_map;
817 if ((rx_mcs_map & 0xC0) != 0xC0)
818 return 4;
819
820 if ((rx_mcs_map & 0x30) != 0x30)
821 return 3;
822
823 if ((rx_mcs_map & 0x0C) != 0x0C)
824 return 2;
825 } else if (htcap) {
826 if (htcap->mcsset[3])
827 return 4;
828
829 if (htcap->mcsset[2])
830 return 3;
831
832 if (htcap->mcsset[1])
833 return 2;
834
835 }
836 return 1;
837}
838
Basamma Yakkanahalliab48ce32018-07-06 18:49:19 +0530839#ifdef WLAN_DFS_CHAN_HIDDEN_SSID
840QDF_STATUS
841util_scan_add_hidden_ssid(struct wlan_objmgr_pdev *pdev, qdf_nbuf_t bcnbuf)
842{
843 struct wlan_frame_hdr *hdr;
844 struct wlan_bcn_frame *bcn;
845 struct wlan_scan_obj *scan_obj;
846 struct wlan_ssid *conf_ssid;
847 struct ie_header *ie;
848 uint32_t frame_len = qdf_nbuf_len(bcnbuf);
849 uint16_t bcn_ie_offset, ssid_ie_start_offset, ssid_ie_end_offset;
850 uint16_t tmplen, ie_length;
851 uint8_t *pbeacon, *tmp;
852 bool set_ssid_flag = false;
853 struct ie_ssid *ssid;
854 uint8_t pdev_id;
855
856 if (!pdev) {
857 scm_warn("pdev: 0x%pK is NULL", pdev);
858 return QDF_STATUS_E_NULL_VALUE;
859 }
860 pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
861 scan_obj = wlan_pdev_get_scan_obj(pdev);
862
863 conf_ssid = &scan_obj->pdev_info[pdev_id].conf_ssid;
864
865 hdr = (struct wlan_frame_hdr *)qdf_nbuf_data(bcnbuf);
866
867 /* received bssid does not match configured bssid */
868 if (qdf_mem_cmp(hdr->i_addr3, scan_obj->pdev_info[pdev_id].conf_bssid,
869 QDF_MAC_ADDR_SIZE) ||
870 conf_ssid->length == 0) {
871 return QDF_STATUS_SUCCESS;
872 }
873
874 bcn = (struct wlan_bcn_frame *)(qdf_nbuf_data(bcnbuf) + sizeof(*hdr));
875 pbeacon = (uint8_t *)bcn;
876
877 ie = (struct ie_header *)(pbeacon +
878 offsetof(struct wlan_bcn_frame, ie));
879
880 bcn_ie_offset = offsetof(struct wlan_bcn_frame, ie);
881 ie_length = (uint16_t)(frame_len - sizeof(*hdr) -
882 bcn_ie_offset);
883
884 while (ie_length >= sizeof(struct ie_header)) {
885 ie_length -= sizeof(struct ie_header);
886
887 bcn_ie_offset += sizeof(struct ie_header);
888
889 if (ie_length < ie->ie_len) {
890 scm_debug("Incomplete corrupted IE:%x", ie->ie_id);
891 return QDF_STATUS_E_INVAL;
892 }
893 if (ie->ie_id == WLAN_ELEMID_SSID) {
894 if (ie->ie_len > (sizeof(struct ie_ssid) -
895 sizeof(struct ie_header))) {
896 return QDF_STATUS_E_INVAL;
897 }
898 ssid = (struct ie_ssid *)ie;
899 if (util_scan_is_hidden_ssid(ssid)) {
900 set_ssid_flag = true;
901 ssid_ie_start_offset = bcn_ie_offset -
902 sizeof(struct ie_header);
903 ssid_ie_end_offset = bcn_ie_offset +
904 ie->ie_len;
905 }
906 }
907 if (ie->ie_len == 0) {
908 ie += 1; /* next IE */
909 continue;
910 }
911 if (ie->ie_id == WLAN_ELEMID_VENDOR &&
912 is_wps_oui((uint8_t *)ie)) {
913 set_ssid_flag = false;
914 break;
915 }
916 /* Consume info element */
917 ie_length -= ie->ie_len;
918 /* Go to next IE */
919 ie = (struct ie_header *)(((uint8_t *)ie) +
920 sizeof(struct ie_header) +
921 ie->ie_len);
922 }
923
924 if (set_ssid_flag) {
925 /* Hidden SSID if the Length is 0 */
926 if (!ssid->ssid_len) {
927 /* increase the taillength by length of ssid */
928 if (qdf_nbuf_put_tail(bcnbuf,
929 conf_ssid->length) == NULL) {
930 scm_debug("No enough tailroom");
931 return QDF_STATUS_E_NOMEM;
932 }
933 /* length of the buffer to be copied */
934 tmplen = frame_len -
935 sizeof(*hdr) - ssid_ie_end_offset;
936 /*
937 * tmp memory to copy the beacon info
938 * after ssid ie.
939 */
940 tmp = qdf_mem_malloc(tmplen * sizeof(u_int8_t));
941 if (!tmp) {
942 scm_debug("tmp memory alloc failed");
943 return QDF_STATUS_E_NOMEM;
944 }
945 /* Copy beacon data after ssid ie to tmp */
946 qdf_nbuf_copy_bits(bcnbuf, (sizeof(*hdr) +
947 ssid_ie_end_offset), tmplen, tmp);
948 /* Add ssid length */
949 *(pbeacon + (ssid_ie_start_offset + 1))
950 = conf_ssid->length;
951 /* Insert the SSID string */
952 qdf_mem_copy((pbeacon + ssid_ie_end_offset),
953 conf_ssid->ssid, conf_ssid->length);
954 /* Copy rest of the beacon data */
955 qdf_mem_copy((pbeacon + ssid_ie_end_offset +
956 conf_ssid->length), tmp, tmplen);
957 qdf_mem_free(tmp);
958
959 /* Hidden ssid with all 0's */
960 } else if (ssid->ssid_len == conf_ssid->length) {
961 /* Insert the SSID string */
962 qdf_mem_copy((pbeacon + ssid_ie_start_offset +
963 sizeof(struct ie_header)),
964 conf_ssid->ssid, conf_ssid->length);
965 } else {
966 scm_debug("mismatch in hidden ssid length");
967 return QDF_STATUS_E_INVAL;
968 }
969 }
970 return QDF_STATUS_SUCCESS;
971}
972#endif /* WLAN_DFS_CHAN_HIDDEN_SSID */
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700973static QDF_STATUS
974util_scan_gen_scan_entry(struct wlan_objmgr_pdev *pdev,
975 uint8_t *frame, qdf_size_t frame_len,
976 uint32_t frm_subtype,
977 struct mgmt_rx_event_params *rx_param,
978 qdf_list_t *scan_list)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530979{
980 struct wlan_frame_hdr *hdr;
981 struct wlan_bcn_frame *bcn;
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700982 QDF_STATUS status = QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530983 struct ie_ssid *ssid;
Sandeep Puligillac6764592017-12-05 21:01:52 -0800984 struct scan_cache_entry *scan_entry;
Abhishek Singh7b599032017-11-10 14:42:31 +0530985 struct qbss_load_ie *qbss_load;
Sandeep Puligillac6764592017-12-05 21:01:52 -0800986 struct scan_cache_node *scan_node;
987
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +0530988 scan_entry = qdf_mem_malloc_atomic(sizeof(*scan_entry));
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530989 if (!scan_entry) {
990 scm_err("failed to allocate memory for scan_entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700991 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530992 }
993 scan_entry->raw_frame.ptr =
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +0530994 qdf_mem_malloc_atomic(frame_len);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530995 if (!scan_entry->raw_frame.ptr) {
996 scm_err("failed to allocate memory for frame");
997 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -0700998 return QDF_STATUS_E_NOMEM;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530999 }
1000
1001 bcn = (struct wlan_bcn_frame *)
1002 (frame + sizeof(*hdr));
1003 hdr = (struct wlan_frame_hdr *)frame;
1004
gaurank kathpalia26f98332018-01-29 18:09:06 +05301005 /* update timestamp in nanoseconds needed by kernel layers */
Arif Hussain6fcc7902018-03-22 12:33:12 -07001006 scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns();
gaurank kathpalia26f98332018-01-29 18:09:06 +05301007
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301008 scan_entry->frm_subtype = frm_subtype;
1009 qdf_mem_copy(scan_entry->bssid.bytes,
1010 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1011 /* Scr addr */
1012 qdf_mem_copy(scan_entry->mac_addr.bytes,
1013 hdr->i_addr2, QDF_MAC_ADDR_SIZE);
1014 scan_entry->seq_num =
1015 (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
1016
1017 scan_entry->rssi_raw = rx_param->rssi;
Om Prakash Tripathi6af738b2017-08-22 15:46:38 +05301018 scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw);
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301019 scan_entry->tsf_delta = rx_param->tsf_delta;
1020
gaurank kathpalia26f98332018-01-29 18:09:06 +05301021 /* Copy per chain rssi to scan entry */
1022 qdf_mem_copy(scan_entry->per_chain_snr, rx_param->rssi_ctl,
1023 WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
1024
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301025 /* store jiffies */
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001026 scan_entry->rrm_parent_tsf = (uint32_t)qdf_system_ticks();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301027
1028 scan_entry->bcn_int = le16toh(bcn->beacon_interval);
1029
1030 /*
1031 * In case if the beacon dosnt have
1032 * valid beacon interval falback to def
1033 */
1034 if (!scan_entry->bcn_int)
1035 scan_entry->bcn_int = 100;
1036 scan_entry->cap_info.value = le16toh(bcn->capability.value);
1037 qdf_mem_copy(scan_entry->tsf_info.data,
1038 bcn->timestamp, 8);
1039 scan_entry->erp = ERP_NON_ERP_PRESENT;
1040
Om Prakash Tripathicdcbb392017-04-18 18:51:20 +05301041 scan_entry->scan_entry_time =
1042 qdf_mc_timer_get_system_time();
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301043
1044 scan_entry->raw_frame.len = frame_len;
1045 qdf_mem_copy(scan_entry->raw_frame.ptr,
1046 frame, frame_len);
1047 status = util_scan_populate_bcn_ie_list(scan_entry);
1048 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +05301049 scm_debug("failed to parse beacon IE");
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301050 qdf_mem_free(scan_entry->raw_frame.ptr);
1051 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001052 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301053 }
1054
1055 if (!scan_entry->ie_list.rates) {
1056 qdf_mem_free(scan_entry->raw_frame.ptr);
1057 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001058 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301059 }
1060
1061 ssid = (struct ie_ssid *)
1062 scan_entry->ie_list.ssid;
1063
1064 if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
1065 qdf_mem_free(scan_entry->raw_frame.ptr);
1066 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001067 return QDF_STATUS_E_FAILURE;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301068 }
1069
1070 if (scan_entry->ie_list.p2p)
1071 scan_entry->is_p2p = true;
1072
1073 /* If no channel info is present in beacon use meta channel */
1074 if (!scan_entry->channel.chan_idx) {
1075 scan_entry->channel.chan_idx =
1076 rx_param->channel;
1077 } else if (rx_param->channel !=
1078 scan_entry->channel.chan_idx) {
Shashikala Prabhu7edbb052018-04-12 09:55:25 +05301079 if (!wlan_reg_chan_is_49ghz(pdev, scan_entry->channel.chan_idx))
1080 scan_entry->channel_mismatch = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301081 }
1082
1083 if (util_scan_is_hidden_ssid(ssid)) {
1084 scan_entry->ie_list.ssid = NULL;
1085 } else {
1086 qdf_mem_copy(scan_entry->ssid.ssid,
1087 ssid->ssid, WLAN_SSID_MAX_LEN);
1088 scan_entry->ssid.length = ssid->ssid_len;
1089 scan_entry->hidden_ssid_timestamp =
1090 scan_entry->scan_entry_time;
1091 }
1092
1093 if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx))
1094 scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry);
1095 else
1096 scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry);
1097
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301098 scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry);
1099 util_scan_scm_update_bss_with_esp_data(scan_entry);
Abhishek Singh7b599032017-11-10 14:42:31 +05301100 qbss_load = (struct qbss_load_ie *)
1101 util_scan_entry_qbssload(scan_entry);
1102 if (qbss_load)
1103 scan_entry->qbss_chan_load = qbss_load->qbss_chan_load;
Abhishek Singhb80af7e2017-07-19 18:48:42 +05301104
Om Prakash Tripathi9b56f5d2018-05-29 11:42:19 +05301105 scan_node = qdf_mem_malloc_atomic(sizeof(*scan_node));
Sandeep Puligillac6764592017-12-05 21:01:52 -08001106 if (!scan_node) {
Om Prakash Tripathi52402552018-02-21 16:31:49 +05301107 qdf_mem_free(scan_entry->raw_frame.ptr);
Sandeep Puligillac6764592017-12-05 21:01:52 -08001108 qdf_mem_free(scan_entry);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001109 return QDF_STATUS_E_FAILURE;
Sandeep Puligillac6764592017-12-05 21:01:52 -08001110 }
1111
1112 scan_node->entry = scan_entry;
1113 qdf_list_insert_front(scan_list, &scan_node->node);
1114
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001115 return status;
1116}
1117
1118/**
1119 * util_scan_find_ie() - find information element
1120 * @eid: element id
1121 * @ies: pointer consisting of IEs
1122 * @len: IE length
1123 *
1124 * Return: NULL if the element ID is not found or
1125 * a pointer to the first byte of the requested
1126 * element
1127 */
1128static uint8_t *util_scan_find_ie(uint8_t eid, uint8_t *ies,
1129 int32_t len)
1130{
1131 while (len >= 2 && len >= ies[1] + 2) {
1132 if (ies[0] == eid)
1133 return ies;
1134 len -= ies[1] + 2;
1135 ies += ies[1] + 2;
1136 }
1137
1138 return NULL;
1139}
1140
1141#ifdef WLAN_FEATURE_MBSSID
1142static void util_gen_new_bssid(uint8_t *bssid, uint8_t max_bssid,
1143 uint8_t mbssid_index,
1144 uint8_t *new_bssid_addr)
1145{
1146 uint64_t bssid_tmp = 0, new_bssid = 0;
1147 uint64_t lsb_n;
1148 int i;
1149
1150 for (i = 0; i < QDF_MAC_ADDR_SIZE; i++)
1151 bssid_tmp = bssid_tmp << 8 | bssid[i];
1152
1153 lsb_n = bssid_tmp & ((1 << max_bssid) - 1);
1154 new_bssid = bssid_tmp;
1155 new_bssid &= ~((1 << max_bssid) - 1);
1156 new_bssid |= (lsb_n + mbssid_index) % (1 << max_bssid);
1157
1158 for (i = QDF_MAC_ADDR_SIZE - 1; i >= 0; i--) {
1159 new_bssid_addr[i] = new_bssid & 0xff;
1160 new_bssid = new_bssid >> 8;
1161 }
1162}
1163
1164static uint32_t util_gen_new_ie(uint8_t *ie, uint32_t ielen,
1165 uint8_t *subelement,
1166 size_t subie_len, uint8_t *new_ie)
1167{
1168 uint8_t *pos, *tmp;
1169 const uint8_t *tmp_old, *tmp_new;
1170 uint8_t *sub_copy;
1171
1172 /* copy subelement as we need to change its content to
1173 * mark an ie after it is processed.
1174 */
1175 sub_copy = qdf_mem_malloc(subie_len);
1176 if (!sub_copy)
1177 return 0;
1178 qdf_mem_copy(sub_copy, subelement, subie_len);
1179
1180 pos = &new_ie[0];
1181
1182 /* new ssid */
1183 tmp_new = util_scan_find_ie(WLAN_ELEMID_SSID, sub_copy, subie_len);
1184 if (tmp_new) {
1185 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1186 pos += (tmp_new[1] + 2);
1187 }
1188
1189 /* go through IEs in ie (skip SSID) and subelement,
1190 * merge them into new_ie
1191 */
1192 tmp_old = util_scan_find_ie(WLAN_ELEMID_SSID, ie, ielen);
1193 tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie;
1194
1195 while (tmp_old + tmp_old[1] + 2 - ie <= ielen) {
1196 if (tmp_old[0] == 0) {
1197 tmp_old++;
1198 continue;
1199 }
1200
1201 tmp = (uint8_t *)util_scan_find_ie(tmp_old[0], sub_copy,
1202 subie_len);
1203 if (!tmp) {
1204 /* ie in old ie but not in subelement */
1205 if (tmp_old[0] != WLAN_ELEMID_MULTIPLE_BSSID) {
1206 qdf_mem_copy(pos, tmp_old, tmp_old[1] + 2);
1207 pos += tmp_old[1] + 2;
1208 }
1209 } else {
1210 /* ie in transmitting ie also in subelement,
1211 * copy from subelement and flag the ie in subelement
1212 * as copied (by setting eid field to 0xff). For
1213 * vendor ie, compare OUI + type + subType to
1214 * determine if they are the same ie.
1215 */
1216 if (tmp_old[0] == WLAN_ELEMID_VENDOR) {
1217 if (!qdf_mem_cmp(tmp_old + 2, tmp + 2, 5)) {
1218 /* same vendor ie, copy from
1219 * subelement
1220 */
1221 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1222 pos += tmp[1] + 2;
1223 tmp[0] = 0xff;
1224 } else {
1225 qdf_mem_copy(pos, tmp_old,
1226 tmp_old[1] + 2);
1227 pos += tmp_old[1] + 2;
1228 }
1229 } else {
1230 /* copy ie from subelement into new ie */
1231 qdf_mem_copy(pos, tmp, tmp[1] + 2);
1232 pos += tmp[1] + 2;
1233 tmp[0] = 0xff;
1234 }
1235 }
1236
1237 if (tmp_old + tmp_old[1] + 2 - ie == ielen)
1238 break;
1239
1240 tmp_old += tmp_old[1] + 2;
1241 }
1242
1243 /* go through subelement again to check if there is any ie not
1244 * copied to new ie, skip ssid, capability, bssid-index ie
1245 */
1246 tmp_new = sub_copy;
1247 while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
1248 if (!(tmp_new[0] == WLAN_ELEMID_NONTX_BSSID_CAP ||
1249 tmp_new[0] == WLAN_ELEMID_SSID ||
1250 tmp_new[0] == WLAN_ELEMID_MULTI_BSSID_IDX ||
1251 tmp_new[0] == 0xff)) {
1252 qdf_mem_copy(pos, tmp_new, tmp_new[1] + 2);
1253 pos += tmp_new[1] + 2;
1254 }
1255 if (tmp_new + tmp_new[1] + 2 - sub_copy == subie_len)
1256 break;
1257 tmp_new += tmp_new[1] + 2;
1258 }
1259
1260 qdf_mem_free(sub_copy);
1261 return pos - new_ie;
1262}
1263
1264static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1265 uint8_t *frame, qdf_size_t frame_len,
1266 uint32_t frm_subtype,
1267 struct mgmt_rx_event_params *rx_param,
1268 qdf_list_t *scan_list)
1269{
1270 struct wlan_bcn_frame *bcn;
1271 struct wlan_frame_hdr *hdr;
1272 QDF_STATUS status;
1273 uint8_t *pos, *subelement, *mbssid_end_pos;
1274 uint8_t *tmp, *mbssid_index_ie;
1275 uint32_t subie_len, new_ie_len;
1276 uint8_t new_bssid[QDF_MAC_ADDR_SIZE], bssid[QDF_MAC_ADDR_SIZE];
1277 uint8_t *new_ie;
1278 uint8_t *ie, *new_frame = NULL;
1279 uint64_t ielen, new_frame_len;
1280
1281 hdr = (struct wlan_frame_hdr *)frame;
1282 bcn = (struct wlan_bcn_frame *)(frame + sizeof(struct wlan_frame_hdr));
1283 ie = (uint8_t *)&bcn->ie;
1284 ielen = (uint16_t)(frame_len -
1285 sizeof(struct wlan_frame_hdr) -
1286 offsetof(struct wlan_bcn_frame, ie));
1287 qdf_mem_copy(bssid, hdr->i_addr3, QDF_MAC_ADDR_SIZE);
1288
1289 if (!util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, ie, ielen))
1290 return QDF_STATUS_E_FAILURE;
1291
1292 pos = ie;
1293
1294 new_ie = qdf_mem_malloc(MAX_IE_LEN);
1295 if (!new_ie) {
1296 scm_err("Failed to allocate memory for new ie");
1297 return QDF_STATUS_E_NOMEM;
1298 }
1299
1300 while (pos < ie + ielen + 2) {
1301 tmp = util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID, pos,
1302 ielen - (pos - ie));
1303 if (!tmp)
1304 break;
1305
1306 mbssid_end_pos = tmp + tmp[1] + 2;
1307 /* Skip Element ID, Len, MaxBSSID Indicator */
1308 if (tmp[1] < 4)
1309 break;
1310 for (subelement = tmp + 3; subelement < mbssid_end_pos - 1;
1311 subelement += 2 + subelement[1]) {
1312 subie_len = subelement[1];
1313 if (mbssid_end_pos - subelement < 2 + subie_len)
1314 break;
1315 if (subelement[0] != 0 || subelement[1] < 4) {
1316 /* not a valid BSS profile */
1317 continue;
1318 }
1319
1320 if (subelement[2] != WLAN_ELEMID_NONTX_BSSID_CAP ||
1321 subelement[3] != 2) {
1322 /* The first element within the Nontransmitted
1323 * BSSID Profile is not the Nontransmitted
1324 * BSSID Capability element.
1325 */
1326 continue;
1327 }
1328
1329 /* found a Nontransmitted BSSID Profile */
1330 mbssid_index_ie =
1331 util_scan_find_ie(WLAN_ELEMID_MULTI_BSSID_IDX,
1332 subelement + 2, subie_len);
1333 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 ||
1334 mbssid_index_ie[2] == 0) {
1335 /* No valid Multiple BSSID-Index element */
1336 continue;
1337 }
1338
1339 util_gen_new_bssid(bssid, tmp[2], mbssid_index_ie[2],
1340 new_bssid);
1341 new_ie_len = util_gen_new_ie(ie, ielen, subelement + 2,
1342 subie_len, new_ie);
1343 if (!new_ie_len)
1344 continue;
1345
1346 new_frame_len = frame_len - ielen + new_ie_len;
1347 new_frame = qdf_mem_malloc(new_frame_len);
1348 if (!new_frame) {
1349 qdf_mem_free(new_ie);
1350 scm_err("failed to allocate memory");
1351 return QDF_STATUS_E_NOMEM;
1352 }
1353
1354 /*
1355 * Copy the header(24byte), timestamp(8 byte),
1356 * beaconinterval(2byte) and capability(2byte)
1357 */
1358 qdf_mem_copy(new_frame, frame, 36);
1359 /* Copy the new ie generated from MBSSID profile*/
1360 qdf_mem_copy(new_frame +
1361 offsetof(struct wlan_bcn_frame, ie),
1362 new_ie, new_ie_len);
1363 status = util_scan_gen_scan_entry(pdev, new_frame,
1364 new_frame_len,
1365 frm_subtype,
1366 rx_param, scan_list);
1367 if (QDF_IS_STATUS_ERROR(status)) {
1368 qdf_mem_free(new_frame);
1369 scm_err("failed to generate a scan entry");
1370 break;
1371 }
1372 /* scan entry makes its own copy so free the frame*/
1373 qdf_mem_free(new_frame);
1374 }
1375
1376 pos = mbssid_end_pos;
1377 }
1378 qdf_mem_free(new_ie);
1379
1380 return QDF_STATUS_SUCCESS;
1381}
1382#else
1383static QDF_STATUS util_scan_parse_mbssid(struct wlan_objmgr_pdev *pdev,
1384 uint8_t *frame, qdf_size_t frame_len,
1385 uint32_t frm_subtype,
1386 struct mgmt_rx_event_params *rx_param,
1387 qdf_list_t *scan_list)
1388{
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301389 return util_scan_gen_scan_entry(pdev, frame, frame_len,
1390 frm_subtype, rx_param, scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001391}
1392#endif
1393
1394static QDF_STATUS
1395util_scan_parse_beacon_frame(struct wlan_objmgr_pdev *pdev,
1396 uint8_t *frame,
1397 qdf_size_t frame_len,
1398 uint32_t frm_subtype,
1399 struct mgmt_rx_event_params *rx_param,
1400 qdf_list_t *scan_list)
1401{
1402 struct wlan_bcn_frame *bcn;
1403 uint32_t ie_len = 0;
1404 QDF_STATUS status;
1405
1406 bcn = (struct wlan_bcn_frame *)
1407 (frame + sizeof(struct wlan_frame_hdr));
1408 ie_len = (uint16_t)(frame_len -
1409 sizeof(struct wlan_frame_hdr) -
1410 offsetof(struct wlan_bcn_frame, ie));
1411
1412 /*
1413 * IF MBSSID IE is present in the beacon then
1414 * scan component will create a new entry for
1415 * each BSSID found in the MBSSID
1416 */
1417 if (util_scan_find_ie(WLAN_ELEMID_MULTIPLE_BSSID,
1418 (uint8_t *)&bcn->ie, ie_len))
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301419 status = util_scan_parse_mbssid(pdev, frame, frame_len,
1420 frm_subtype, rx_param,
1421 scan_list);
1422 else
1423 status = util_scan_gen_scan_entry(pdev, frame, frame_len,
1424 frm_subtype, rx_param,
1425 scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001426 if (QDF_IS_STATUS_ERROR(status)) {
phadiman8a322292018-09-17 14:54:09 +05301427 scm_err_rl("Failed to create a scan entry");
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001428 }
1429
1430 return status;
1431}
1432
1433qdf_list_t *
1434util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame,
1435 qdf_size_t frame_len, uint32_t frm_subtype,
1436 struct mgmt_rx_event_params *rx_param)
1437{
1438 qdf_list_t *scan_list;
1439 QDF_STATUS status;
1440
1441 scan_list = qdf_mem_malloc_atomic(sizeof(*scan_list));
1442 if (!scan_list) {
1443 scm_err("failed to allocate scan_list");
1444 return NULL;
1445 }
1446 qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE);
1447
1448 status = util_scan_parse_beacon_frame(pdev, frame, frame_len,
1449 frm_subtype, rx_param,
1450 scan_list);
1451 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathic341ca72018-08-14 15:41:34 +05301452 ucfg_scan_purge_results(scan_list);
Sandeep Puligilla54d8b642018-07-06 17:35:26 -07001453 return NULL;
1454 }
1455
Sandeep Puligillac6764592017-12-05 21:01:52 -08001456 return scan_list;
Abhishek Singh4caf1a92017-02-21 15:01:08 +05301457}
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301458
1459QDF_STATUS
1460util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev,
1461 struct scan_cache_entry *scan_entry)
1462{
1463
1464 if (!pdev || !scan_entry) {
Jeff Johnson878533e2017-09-18 10:07:54 -07001465 scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry);
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +05301466 return QDF_STATUS_E_INVAL;
1467 }
1468
1469 return scm_update_scan_mlme_info(pdev, scan_entry);
1470}
Sandeep Puligillaf57464c2017-11-16 23:31:52 -08001471
1472bool util_is_scan_completed(struct scan_event *event, bool *success)
1473{
1474 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) ||
1475 (event->type == SCAN_EVENT_TYPE_DEQUEUED) ||
1476 (event->type == SCAN_EVENT_TYPE_START_FAILED)) {
1477 if ((event->type == SCAN_EVENT_TYPE_COMPLETED) &&
1478 (event->reason == SCAN_REASON_COMPLETED))
1479 *success = true;
1480 else
1481 *success = false;
1482
1483 return true;
1484 }
1485
1486 *success = false;
1487 return false;
1488}
1489