blob: 88141223f0369d72835950b3cecf10f889345364 [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
30const char*
31util_scan_get_ev_type_name(enum scan_event_type type)
32{
33 static const char * const event_name[] = {
34 [SCAN_EVENT_TYPE_STARTED] = "STARTED",
35 [SCAN_EVENT_TYPE_COMPLETED] = "COMPLETED",
36 [SCAN_EVENT_TYPE_BSS_CHANNEL] = "HOME_CHANNEL",
37 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL] = "FOREIGN_CHANNEL",
38 [SCAN_EVENT_TYPE_DEQUEUED] = "DEQUEUED",
39 [SCAN_EVENT_TYPE_PREEMPTED] = "PREEMPTED",
40 [SCAN_EVENT_TYPE_START_FAILED] = "START_FAILED",
41 [SCAN_EVENT_TYPE_RESTARTED] = "RESTARTED",
42 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_EXIT] = "FOREIGN_CHANNEL_EXIT",
43 [SCAN_EVENT_TYPE_SUSPENDED] = "SUSPENDED",
44 [SCAN_EVENT_TYPE_RESUMED] = "RESUMED",
45 [SCAN_EVENT_TYPE_NLO_COMPLETE] = "NLO_COMPLETE",
Abhishek Singh8c6e82d2017-03-03 21:57:29 +053046 [SCAN_EVENT_TYPE_NLO_MATCH] = "NLO_MATCH",
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053047 [SCAN_EVENT_TYPE_INVALID] = "INVALID",
48 [SCAN_EVENT_TYPE_GPIO_TIMEOUT] = "GPIO_TIMEOUT",
49 [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_START] =
50 "RADIO_MEASUREMENT_START",
51 [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_END] =
52 "RADIO_MEASUREMENT_END",
53 [SCAN_EVENT_TYPE_BSSID_MATCH] = "BSSID_MATCH",
54 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_GET_NF] =
55 "FOREIGN_CHANNEL_GET_NF",
56 };
57
Abhishek Singh483d9142017-03-06 13:28:13 +053058 if (type >= SCAN_EVENT_TYPE_MAX)
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053059 return "UNKNOWN";
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053060
61 return event_name[type];
62}
63
64
65const char*
66util_scan_get_ev_reason_name(enum scan_completion_reason reason)
67{
68 static const char * const reason_name[] = {
69 [SCAN_REASON_NONE] = "NONE",
70 [SCAN_REASON_COMPLETED] = "COMPLETED",
71 [SCAN_REASON_CANCELLED] = "CANCELLED",
72 [SCAN_REASON_PREEMPTED] = "PREEMPTED",
73 [SCAN_REASON_TIMEDOUT] = "TIMEDOUT",
74 [SCAN_REASON_INTERNAL_FAILURE] = "INTERNAL_FAILURE",
75 [SCAN_REASON_SUSPENDED] = "SUSPENDED",
76 [SCAN_REASON_RUN_FAILED] = "RUN_FAILED",
77 [SCAN_REASON_TERMINATION_FUNCTION] = "TERMINATION_FUNCTION",
78 [SCAN_REASON_MAX_OFFCHAN_RETRIES] = "MAX_OFFCHAN_RETRIES",
79 };
80
Abhishek Singh483d9142017-03-06 13:28:13 +053081 if (reason >= SCAN_REASON_MAX)
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053082 return "UNKNOWN";
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053083
84 return reason_name[reason];
85}
86
87qdf_time_t
88util_get_last_scan_time(struct wlan_objmgr_vdev *vdev)
89{
90 uint8_t pdev_id;
91 struct wlan_scan_obj *scan_obj;
92
93 if (!vdev) {
94 scm_warn("null vdev");
95 QDF_ASSERT(0);
96 return 0;
97 }
98 pdev_id = wlan_scan_vdev_get_pdev_id(vdev);
99 scan_obj = wlan_vdev_get_scan_obj(vdev);
100
101 return scan_obj->pdev_info[pdev_id].last_scan_time;
102}
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530103
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530104enum wlan_band util_scan_scm_chan_to_band(uint32_t chan)
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530105{
106 if (WLAN_CHAN_IS_2GHZ(chan))
107 return WLAN_BAND_2_4_GHZ;
108
109 return WLAN_BAND_5_GHZ;
110}
111
Shashikala Prabhu48ecda82018-04-13 01:13:30 +0530112enum wlan_band util_scan_scm_freq_to_band(uint16_t freq)
113{
114 if (WLAN_REG_IS_24GHZ_CH_FREQ(freq))
115 return WLAN_BAND_2_4_GHZ;
116
117 return WLAN_BAND_5_GHZ;
118}
119
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530120bool util_is_scan_entry_match(
121 struct scan_cache_entry *entry1,
122 struct scan_cache_entry *entry2)
123{
124
125 if (entry1->cap_info.wlan_caps.ess !=
wadesong49ae4cb2018-01-22 15:03:12 +0800126 entry2->cap_info.wlan_caps.ess)
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530127 return false;
128
129 if (entry1->cap_info.wlan_caps.ess &&
130 !qdf_mem_cmp(entry1->bssid.bytes,
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530131 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE) &&
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530132 util_scan_scm_chan_to_band(
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530133 entry1->channel.chan_idx) ==
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530134 util_scan_scm_chan_to_band(entry2->channel.chan_idx)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530135 /* Check for BSS */
136 if (util_is_ssid_match(
137 &entry1->ssid, &entry2->ssid))
138 return true;
139 } else if (entry1->cap_info.wlan_caps.ibss &&
140 (entry1->channel.chan_idx ==
141 entry2->channel.chan_idx)) {
142 /*
143 * Same channel cannot have same SSID for
144 * different IBSS, so no need to check BSSID
145 */
146 if (util_is_ssid_match(
147 &entry1->ssid, &entry2->ssid))
148 return true;
149 } else if (!entry1->cap_info.wlan_caps.ibss &&
150 !entry1->cap_info.wlan_caps.ess &&
151 !qdf_mem_cmp(entry1->bssid.bytes,
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530152 entry2->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530153 /* In case of P2P devices, ess and ibss will be set to zero */
154 return true;
155 }
156
157 return false;
158}
159
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530160static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates)
161{
162 static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108};
163 bool pureg = false;
164 uint8_t i, j;
165
166 for (i = 0; i < nrates; i++) {
167 for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) {
168 if (WLAN_RV(rates[i]) == g_rates[j]) {
169 pureg = true;
170 break;
171 }
172 }
173 if (pureg)
174 break;
175 }
176
177 return pureg;
178}
179static enum wlan_phymode
180util_scan_get_phymode_5g(struct scan_cache_entry *scan_params)
181{
182 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
183 uint16_t ht_cap = 0;
184 struct htcap_cmn_ie *htcap;
185 struct wlan_ie_htinfo_cmn *htinfo;
186 struct wlan_ie_vhtop *vhtop;
187
188 htcap = (struct htcap_cmn_ie *)
189 util_scan_entry_htcap(scan_params);
190 htinfo = (struct wlan_ie_htinfo_cmn *)
191 util_scan_entry_htinfo(scan_params);
192 vhtop = (struct wlan_ie_vhtop *)
193 util_scan_entry_vhtop(scan_params);
194
195 if (!(htcap && htinfo))
196 return WLAN_PHYMODE_11A;
197
198 if (htcap)
199 ht_cap = le16toh(htcap->hc_cap);
200
201 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
202 switch (vhtop->vht_op_chwidth) {
203 case WLAN_VHTOP_CHWIDTH_2040:
204 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
205 (htinfo->hi_extchoff ==
206 WLAN_HTINFO_EXTOFFSET_ABOVE))
207 phymode = WLAN_PHYMODE_11AC_VHT40PLUS;
208 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
209 (htinfo->hi_extchoff ==
210 WLAN_HTINFO_EXTOFFSET_BELOW))
211 phymode = WLAN_PHYMODE_11AC_VHT40MINUS;
212 else
213 phymode = WLAN_PHYMODE_11AC_VHT20;
214 break;
215 case WLAN_VHTOP_CHWIDTH_80:
216 if (WLAN_IS_REVSIG_VHT80_80(vhtop))
217 phymode = WLAN_PHYMODE_11AC_VHT80_80;
218 else if (WLAN_IS_REVSIG_VHT160(vhtop))
219 phymode = WLAN_PHYMODE_11AC_VHT160;
220 else
221 phymode = WLAN_PHYMODE_11AC_VHT80;
222 break;
223 case WLAN_VHTOP_CHWIDTH_160:
224 phymode = WLAN_PHYMODE_11AC_VHT160;
225 break;
226 case WLAN_VHTOP_CHWIDTH_80_80:
227 phymode = WLAN_PHYMODE_11AC_VHT80_80;
228 break;
229 default:
230 scm_err("bad channel: %d",
231 vhtop->vht_op_chwidth);
232 break;
233 }
234 } else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
235 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
236 phymode = WLAN_PHYMODE_11NA_HT40PLUS;
237 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
238 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
239 phymode = WLAN_PHYMODE_11NA_HT40MINUS;
240 else
241 phymode = WLAN_PHYMODE_11NA_HT20;
242
243 return phymode;
244}
245
246static enum wlan_phymode
247util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
248{
249 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
250 uint16_t ht_cap = 0;
251 struct htcap_cmn_ie *htcap;
252 struct wlan_ie_htinfo_cmn *htinfo;
253 struct wlan_ie_vhtop *vhtop;
254
255 htcap = (struct htcap_cmn_ie *)
256 util_scan_entry_htcap(scan_params);
257 htinfo = (struct wlan_ie_htinfo_cmn *)
258 util_scan_entry_htinfo(scan_params);
259 vhtop = (struct wlan_ie_vhtop *)
260 util_scan_entry_vhtop(scan_params);
261
262 if (htcap)
263 ht_cap = le16toh(htcap->hc_cap);
264
265 if (htcap && htinfo) {
266 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
267 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
268 phymode = WLAN_PHYMODE_11NG_HT40PLUS;
269 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
270 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
271 phymode = WLAN_PHYMODE_11NG_HT40MINUS;
272 else
273 phymode = WLAN_PHYMODE_11NG_HT20;
274 } else if (util_scan_entry_xrates(scan_params)) {
275 /* only 11G stations will have more than 8 rates */
276 phymode = WLAN_PHYMODE_11G;
277 } else {
278 /* Some mischievous g-only APs do not set extended rates */
279 if (util_scan_entry_rates(scan_params)) {
280 if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
281 scan_params->ie_list.rates[1]))
282 phymode = WLAN_PHYMODE_11G;
283 else
284 phymode = WLAN_PHYMODE_11B;
285 } else {
286 phymode = WLAN_PHYMODE_11B;
287 }
288 }
289
290 return phymode;
291}
292
293static QDF_STATUS
294util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
295 struct ie_header *sub_ie, qdf_size_t sub_ie_len)
296{
297 /* Walk through to check nothing is malformed */
298 while (sub_ie_len >= sizeof(struct ie_header)) {
299 /* At least one more header is present */
300 sub_ie_len -= sizeof(struct ie_header);
301
302 if (sub_ie->ie_len == 0) {
303 sub_ie += 1;
304 continue;
305 }
306 if (sub_ie_len < sub_ie->ie_len) {
307 scm_err("Incomplete corrupted IE:%x",
308 WLAN_ELEMID_CHAN_SWITCH_WRAP);
309 return QDF_STATUS_E_INVAL;
310 }
311 switch (sub_ie->ie_id) {
312 case WLAN_ELEMID_COUNTRY:
313 scan_params->ie_list.country = (uint8_t *)sub_ie;
314 break;
315 case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
316 scan_params->ie_list.widebw = (uint8_t *)sub_ie;
317 break;
318 case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
319 scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
320 break;
321 }
322 /* Consume sub info element */
323 sub_ie_len -= sub_ie->ie_len;
324 /* go to next Sub IE */
325 sub_ie = (struct ie_header *)
326 (((uint8_t *) sub_ie) +
327 sizeof(struct ie_header) + sub_ie->ie_len);
328 }
329
330 return QDF_STATUS_SUCCESS;
331}
332
Om Prakash Tripathi1d1525d2017-09-08 13:59:34 +0530333bool
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530334util_scan_is_hidden_ssid(struct ie_ssid *ssid)
335{
336 uint8_t i;
337
338 /*
339 * We flag this as Hidden SSID if the Length is 0
340 * of the SSID only contains 0's
341 */
342 if (!ssid || !ssid->ssid_len)
343 return true;
344
345 for (i = 0; i < ssid->ssid_len; i++)
346 if (ssid->ssid[i] != 0)
347 return false;
348
349 /* All 0's */
350 return true;
351}
352
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530353static QDF_STATUS
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530354util_scan_parse_extn_ie(struct scan_cache_entry *scan_params,
355 struct ie_header *ie)
356{
357 struct extn_ie_header *extn_ie = (struct extn_ie_header *) ie;
358
359 switch (extn_ie->ie_extn_id) {
360 case WLAN_EXTN_ELEMID_SRP:
Gyanranjan Hazarikab5d426d2017-08-22 21:45:07 -0700361 scan_params->ie_list.srp = (uint8_t *)ie;
362 break;
363 case WLAN_EXTN_ELEMID_HECAP:
364 scan_params->ie_list.hecap = (uint8_t *)ie;
365 break;
366 case WLAN_EXTN_ELEMID_HEOP:
367 scan_params->ie_list.heop = (uint8_t *)ie;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530368 break;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530369 case WLAN_EXTN_ELEMID_ESP:
370 scan_params->ie_list.esp = (uint8_t *)ie;
371 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530372 default:
373 break;
374 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530375 return QDF_STATUS_SUCCESS;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530376}
377
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530378static QDF_STATUS
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530379util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
380 struct ie_header *ie)
381{
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530382 if (scan_params->ie_list.vendor == NULL)
383 scan_params->ie_list.vendor = (uint8_t *)ie;
384
385 if (is_wpa_oui((uint8_t *)ie)) {
386 scan_params->ie_list.wpa = (uint8_t *)ie;
387 } else if (is_wps_oui((uint8_t *)ie)) {
388 scan_params->ie_list.wps = (uint8_t *)ie;
389 /* WCN IE should be a subset of WPS IE */
390 if (is_wcn_oui((uint8_t *)ie))
391 scan_params->ie_list.wcn = (uint8_t *)ie;
392 } else if (is_wme_param((uint8_t *)ie)) {
393 scan_params->ie_list.wmeparam = (uint8_t *)ie;
394 } else if (is_wme_info((uint8_t *)ie)) {
395 scan_params->ie_list.wmeinfo = (uint8_t *)ie;
396 } else if (is_atheros_oui((uint8_t *)ie)) {
397 scan_params->ie_list.athcaps = (uint8_t *)ie;
398 } else if (is_atheros_extcap_oui((uint8_t *)ie)) {
399 scan_params->ie_list.athextcaps = (uint8_t *)ie;
400 } else if (is_sfa_oui((uint8_t *)ie)) {
401 scan_params->ie_list.sfa = (uint8_t *)ie;
402 } else if (is_p2p_oui((uint8_t *)ie)) {
403 scan_params->ie_list.p2p = (uint8_t *)ie;
Bharat Bhushan Chakravarty145d3932017-03-20 12:52:16 -0700404 } else if (is_qca_son_oui((uint8_t *)ie,
405 QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530406 scan_params->ie_list.sonadv = (uint8_t *)ie;
407 } else if (is_ht_cap((uint8_t *)ie)) {
408 /* we only care if there isn't already an HT IE (ANA) */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530409 if (scan_params->ie_list.htcap == NULL) {
410 if (ie->ie_len != (WLAN_VENDOR_HT_IE_OFFSET_LEN +
411 sizeof(struct htcap_cmn_ie)))
412 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530413 scan_params->ie_list.htcap =
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530414 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
415 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530416 } else if (is_ht_info((uint8_t *)ie)) {
417 /* we only care if there isn't already an HT IE (ANA) */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530418 if (scan_params->ie_list.htinfo == NULL) {
419 if (ie->ie_len != WLAN_VENDOR_HT_IE_OFFSET_LEN +
420 sizeof(struct wlan_ie_htinfo_cmn))
421 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530422 scan_params->ie_list.htinfo =
423 (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
424 ie)->hi_ie);
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530425 }
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530426 } else if (is_interop_vht((uint8_t *)ie) &&
427 !(scan_params->ie_list.vhtop)) {
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530428 uint8_t *vendor_ie = (uint8_t *)(ie);
429
430 if (ie->ie_len < ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
431 sizeof(struct wlan_ie_vhtcaps)) -
432 sizeof(struct ie_header)))
433 return QDF_STATUS_E_INVAL;
434 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTCAP_IE_OFFSET;
435 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtcaps)) -
436 sizeof(struct ie_header))
437 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530438 /* location where Interop Vht Cap IE and VHT OP IE Present */
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530439 scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) +
440 WLAN_VENDOR_VHTCAP_IE_OFFSET);
441 if (ie->ie_len > ((WLAN_VENDOR_VHTCAP_IE_OFFSET +
442 sizeof(struct wlan_ie_vhtcaps)) -
443 sizeof(struct ie_header)) &&
444 ie->ie_len < ((WLAN_VENDOR_VHTOP_IE_OFFSET +
445 sizeof(struct wlan_ie_vhtop)) -
446 sizeof(struct ie_header)))
447 return QDF_STATUS_E_INVAL;
448 vendor_ie = ((uint8_t *)(ie)) + WLAN_VENDOR_VHTOP_IE_OFFSET;
449 if (vendor_ie[1] != (sizeof(struct wlan_ie_vhtop) -
450 sizeof(struct ie_header)))
451 return QDF_STATUS_E_INVAL;
452 scan_params->ie_list.vhtop = (((uint8_t *)(ie)) +
453 WLAN_VENDOR_VHTOP_IE_OFFSET);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530454 } else if (is_bwnss_oui((uint8_t *)ie)) {
455 /*
456 * Bandwidth-NSS map has sub-type & version.
457 * hence copy data just after version byte
458 */
459 scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
Abhishek Singh7b599032017-11-10 14:42:31 +0530460 } else if (is_mbo_oce_oui((uint8_t *)ie)) {
461 scan_params->ie_list.mbo_oce = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530462 }
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530463 return QDF_STATUS_SUCCESS;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530464}
465
466static QDF_STATUS
467util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params)
468{
469 struct ie_header *ie, *sub_ie;
470 uint32_t ie_len, sub_ie_len;
471 QDF_STATUS status;
472
473 ie_len = util_scan_entry_ie_len(scan_params);
474 ie = (struct ie_header *)
475 util_scan_entry_ie_data(scan_params);
476
477 while (ie_len >= sizeof(struct ie_header)) {
478 ie_len -= sizeof(struct ie_header);
479
480 if (!ie->ie_len) {
481 ie += 1;
482 continue;
483 }
484
485 if (ie_len < ie->ie_len) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +0530486 scm_debug("Incomplete corrupted IE:%x",
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530487 ie->ie_id);
488 return QDF_STATUS_E_INVAL;
489 }
490
491 switch (ie->ie_id) {
492 case WLAN_ELEMID_SSID:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530493 if (ie->ie_len > (sizeof(struct ie_ssid) -
494 sizeof(struct ie_header)))
495 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530496 scan_params->ie_list.ssid = (uint8_t *)ie;
497 break;
498 case WLAN_ELEMID_RATES:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530499 if (ie->ie_len > WLAN_SUPPORTED_RATES_IE_MAX_LEN)
500 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530501 scan_params->ie_list.rates = (uint8_t *)ie;
502 break;
503 case WLAN_ELEMID_DSPARMS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530504 if (ie->ie_len != WLAN_DS_PARAM_IE_MAX_LEN)
505 return QDF_STATUS_E_INVAL;
Abhishek Singhc05285d2018-01-12 15:19:32 +0530506 scan_params->ie_list.ds_param = (uint8_t *)ie;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530507 scan_params->channel.chan_idx =
508 ((struct ds_ie *)ie)->cur_chan;
509 break;
510 case WLAN_ELEMID_TIM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530511 if (ie->ie_len < WLAN_TIM_IE_MIN_LENGTH)
512 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530513 scan_params->ie_list.tim = (uint8_t *)ie;
514 scan_params->dtim_period =
515 ((struct wlan_tim_ie *)ie)->tim_period;
516 break;
517 case WLAN_ELEMID_COUNTRY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530518 if (ie->ie_len < WLAN_COUNTRY_IE_MIN_LEN)
519 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530520 scan_params->ie_list.country = (uint8_t *)ie;
521 break;
522 case WLAN_ELEMID_QBSS_LOAD:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530523 if (ie->ie_len != sizeof(struct qbss_load_ie) -
524 sizeof(struct ie_header))
525 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530526 scan_params->ie_list.qbssload = (uint8_t *)ie;
527 break;
528 case WLAN_ELEMID_CHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530529 if (ie->ie_len != WLAN_CSA_IE_MAX_LEN)
530 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530531 scan_params->ie_list.csa = (uint8_t *)ie;
532 break;
533 case WLAN_ELEMID_IBSSDFS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530534 if (ie->ie_len < WLAN_IBSSDFS_IE_MIN_LEN)
535 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530536 scan_params->ie_list.ibssdfs = (uint8_t *)ie;
537 break;
538 case WLAN_ELEMID_QUIET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530539 if (ie->ie_len != WLAN_QUIET_IE_MAX_LEN)
540 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530541 scan_params->ie_list.quiet = (uint8_t *)ie;
542 break;
543 case WLAN_ELEMID_ERP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530544 if (ie->ie_len != (sizeof(struct erp_ie) -
545 sizeof(struct ie_header)))
546 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530547 scan_params->erp = ((struct erp_ie *)ie)->value;
548 break;
549 case WLAN_ELEMID_HTCAP_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530550 if (ie->ie_len != sizeof(struct htcap_cmn_ie))
551 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530552 scan_params->ie_list.htcap =
553 (uint8_t *)&(((struct htcap_ie *)ie)->ie);
554 break;
555 case WLAN_ELEMID_RSN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530556 if (ie->ie_len < WLAN_RSN_IE_MIN_LEN)
557 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530558 scan_params->ie_list.rsn = (uint8_t *)ie;
559 break;
560 case WLAN_ELEMID_XRATES:
561 scan_params->ie_list.xrates = (uint8_t *)ie;
562 break;
563 case WLAN_ELEMID_EXTCHANSWITCHANN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530564 if (ie->ie_len != WLAN_XCSA_IE_MAX_LEN)
565 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530566 scan_params->ie_list.xcsa = (uint8_t *)ie;
567 break;
568 case WLAN_ELEMID_SECCHANOFFSET:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530569 if (ie->ie_len != WLAN_SECCHANOFF_IE_MAX_LEN)
570 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530571 scan_params->ie_list.secchanoff = (uint8_t *)ie;
572 break;
573 case WLAN_ELEMID_HTINFO_ANA:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530574 if (ie->ie_len != sizeof(struct wlan_ie_htinfo_cmn))
575 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530576 scan_params->ie_list.htinfo =
577 (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
578 scan_params->channel.chan_idx =
579 ((struct wlan_ie_htinfo_cmn *)
580 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
581 break;
582 case WLAN_ELEMID_WAPI:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530583 if (ie->ie_len < WLAN_WAPI_IE_MIN_LEN)
584 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530585 scan_params->ie_list.wapi = (uint8_t *)ie;
586 break;
587 case WLAN_ELEMID_XCAPS:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530588 if (ie->ie_len > WLAN_EXTCAP_IE_MAX_LEN)
589 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530590 scan_params->ie_list.extcaps = (uint8_t *)ie;
591 break;
592 case WLAN_ELEMID_VHTCAP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530593 if (ie->ie_len != (sizeof(struct wlan_ie_vhtcaps) -
594 sizeof(struct ie_header)))
595 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530596 scan_params->ie_list.vhtcap = (uint8_t *)ie;
597 break;
598 case WLAN_ELEMID_VHTOP:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530599 if (ie->ie_len != (sizeof(struct wlan_ie_vhtop) -
600 sizeof(struct ie_header)))
601 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530602 scan_params->ie_list.vhtop = (uint8_t *)ie;
603 break;
604 case WLAN_ELEMID_OP_MODE_NOTIFY:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530605 if (ie->ie_len != WLAN_OPMODE_IE_MAX_LEN)
606 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530607 scan_params->ie_list.opmode = (uint8_t *)ie;
608 break;
609 case WLAN_ELEMID_MOBILITY_DOMAIN:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530610 if (ie->ie_len != WLAN_MOBILITY_DOMAIN_IE_MAX_LEN)
611 return QDF_STATUS_E_INVAL;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530612 scan_params->ie_list.mdie = (uint8_t *)ie;
613 break;
614 case WLAN_ELEMID_VENDOR:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530615 status = util_scan_parse_vendor_ie(scan_params,
616 ie);
617 if (QDF_IS_STATUS_ERROR(status))
618 return status;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530619 break;
620 case WLAN_ELEMID_CHAN_SWITCH_WRAP:
621 scan_params->ie_list.cswrp = (uint8_t *)ie;
622 /* Go to next sub IE */
623 sub_ie = (struct ie_header *)
624 (((uint8_t *)ie) + sizeof(struct ie_header));
625 sub_ie_len = ie->ie_len;
626 status =
627 util_scan_parse_chan_switch_wrapper_ie(
628 scan_params, sub_ie, sub_ie_len);
629 if (QDF_IS_STATUS_ERROR(status)) {
630 scm_err("failed to parse chan_switch_wrapper_ie");
631 return status;
632 }
633 break;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530634 case WLAN_ELEMID_FILS_INDICATION:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530635 if (ie->ie_len < WLAN_FILS_INDICATION_IE_MIN_LEN)
636 return QDF_STATUS_E_INVAL;
Kapil Guptade02d4f2017-06-05 12:37:59 +0530637 scan_params->ie_list.fils_indication = (uint8_t *)ie;
638 break;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530639 case WLAN_ELEMID_EXTN_ELEM:
gaurank kathpalia7d65c1b2018-02-07 19:56:00 +0530640 status = util_scan_parse_extn_ie(scan_params, ie);
641 if (QDF_IS_STATUS_ERROR(status))
642 return status;
Venkateswara Swamy Bandaru851184b2017-04-25 11:02:39 +0530643 break;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530644 default:
645 break;
646 }
647
648 /* Consume info element */
649 ie_len -= ie->ie_len;
650 /* Go to next IE */
651 ie = (struct ie_header *)
652 (((uint8_t *) ie) +
653 sizeof(struct ie_header) +
654 ie->ie_len);
655 }
656
657 return QDF_STATUS_SUCCESS;
658}
659
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530660/**
661 * util_scan_update_esp_data: update ESP params from beacon/probe response
662 * @esp_information: pointer to wlan_esp_information
663 * @scan_entry: new received entry
664 *
665 * The Estimated Service Parameters element is
666 * used by a AP to provide information to another STA which
667 * can then use the information as input to an algorithm to
668 * generate an estimate of throughput between the two STAs.
669 * The ESP Information List field contains from 1 to 4 ESP
670 * Information fields(each field 24 bits), each corresponding
671 * to an access category for which estimated service parameters
672 * information is provided.
673 *
674 * Return: None
675 */
676static void util_scan_update_esp_data(struct wlan_esp_ie *esp_information,
677 struct scan_cache_entry *scan_entry)
678{
679
680 uint8_t *data;
681 int i = 0;
Sathyanarayanan0a000622017-10-10 17:17:28 +0530682 uint64_t total_elements;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530683 struct wlan_esp_info *esp_info;
684 struct wlan_esp_ie *esp_ie;
685
686 esp_ie = (struct wlan_esp_ie *)
687 util_scan_entry_esp_info(scan_entry);
688
689 total_elements = esp_ie->esp_len;
690 data = (uint8_t *)esp_ie + 3;
691 do_div(total_elements, ESP_INFORMATION_LIST_LENGTH);
692
693 if (total_elements > MAX_ESP_INFORMATION_FIELD) {
694 scm_err("No of Air time fractions are greater than supported");
695 return;
696 }
697
698 for (i = 0; i < total_elements; i++) {
699 esp_info = (struct wlan_esp_info *)data;
700 if (esp_info->access_category == ESP_AC_BK) {
701 qdf_mem_copy(&esp_information->esp_info_AC_BK,
702 data, 3);
703 data = data + ESP_INFORMATION_LIST_LENGTH;
704 continue;
705 }
706 if (esp_info->access_category == ESP_AC_BE) {
707 qdf_mem_copy(&esp_information->esp_info_AC_BE,
708 data, 3);
709 data = data + ESP_INFORMATION_LIST_LENGTH;
710 continue;
711 }
712 if (esp_info->access_category == ESP_AC_VI) {
713 qdf_mem_copy(&esp_information->esp_info_AC_VI,
714 data, 3);
715 data = data + ESP_INFORMATION_LIST_LENGTH;
716 continue;
717 }
718 if (esp_info->access_category == ESP_AC_VO) {
719 qdf_mem_copy(&esp_information->esp_info_AC_VO,
720 data, 3);
721 data = data + ESP_INFORMATION_LIST_LENGTH;
722 break;
723 }
724 }
725}
726
727/**
728 * util_scan_scm_update_bss_with_esp_dataa: calculate estimated air time
729 * fraction
730 * @scan_entry: new received entry
731 *
732 * This function process all Access category ESP params and provide
733 * best effort air time fraction.
734 * If best effort is not available, it will choose VI, VO and BK in sequence
735 *
736 */
737static void util_scan_scm_update_bss_with_esp_data(
738 struct scan_cache_entry *scan_entry)
739{
740 uint8_t air_time_fraction = 0;
741 struct wlan_esp_ie esp_information;
742
743 if (!scan_entry->ie_list.esp)
744 return;
745
746 util_scan_update_esp_data(&esp_information, scan_entry);
747
748 /*
749 * If the ESP metric is transmitting multiple airtime fractions, then
750 * follow the sequence AC_BE, AC_VI, AC_VO, AC_BK and pick whichever is
751 * the first one available
752 */
753 if (esp_information.esp_info_AC_BE.access_category
754 == ESP_AC_BE)
755 air_time_fraction =
756 esp_information.esp_info_AC_BE.
757 estimated_air_fraction;
758 else if (esp_information.esp_info_AC_VI.access_category
759 == ESP_AC_VI)
760 air_time_fraction =
761 esp_information.esp_info_AC_VI.
762 estimated_air_fraction;
763 else if (esp_information.esp_info_AC_VO.access_category
764 == ESP_AC_VO)
765 air_time_fraction =
766 esp_information.esp_info_AC_VO.
767 estimated_air_fraction;
768 else if (esp_information.esp_info_AC_BK.access_category
769 == ESP_AC_BK)
770 air_time_fraction =
771 esp_information.esp_info_AC_BK.
772 estimated_air_fraction;
773 scan_entry->air_time_fraction = air_time_fraction;
774}
775
776/**
777 * util_scan_scm_calc_nss_supported_by_ap() - finds out nss from AP
778 * @scan_entry: new received entry
779 *
780 * Return: number of nss advertised by AP
781 */
782static int util_scan_scm_calc_nss_supported_by_ap(
783 struct scan_cache_entry *scan_params)
784{
785 struct htcap_cmn_ie *htcap;
786 struct wlan_ie_vhtcaps *vhtcaps;
787 uint8_t rx_mcs_map;
788
789 htcap = (struct htcap_cmn_ie *)
790 util_scan_entry_htcap(scan_params);
791 vhtcaps = (struct wlan_ie_vhtcaps *)
792 util_scan_entry_vhtcap(scan_params);
793 if (vhtcaps) {
794 rx_mcs_map = vhtcaps->rx_mcs_map;
795 if ((rx_mcs_map & 0xC0) != 0xC0)
796 return 4;
797
798 if ((rx_mcs_map & 0x30) != 0x30)
799 return 3;
800
801 if ((rx_mcs_map & 0x0C) != 0x0C)
802 return 2;
803 } else if (htcap) {
804 if (htcap->mcsset[3])
805 return 4;
806
807 if (htcap->mcsset[2])
808 return 3;
809
810 if (htcap->mcsset[1])
811 return 2;
812
813 }
814 return 1;
815}
816
Sandeep Puligillac6764592017-12-05 21:01:52 -0800817qdf_list_t *
Shashikala Prabhu7edbb052018-04-12 09:55:25 +0530818util_scan_unpack_beacon_frame(struct wlan_objmgr_pdev *pdev, uint8_t *frame,
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530819 qdf_size_t frame_len, uint32_t frm_subtype,
820 struct mgmt_rx_event_params *rx_param)
821{
822 struct wlan_frame_hdr *hdr;
823 struct wlan_bcn_frame *bcn;
824 QDF_STATUS status;
825 struct ie_ssid *ssid;
Sandeep Puligillac6764592017-12-05 21:01:52 -0800826 struct scan_cache_entry *scan_entry;
Abhishek Singh7b599032017-11-10 14:42:31 +0530827 struct qbss_load_ie *qbss_load;
Sandeep Puligillac6764592017-12-05 21:01:52 -0800828 qdf_list_t *scan_list;
829 struct scan_cache_node *scan_node;
830
831 scan_list = qdf_mem_malloc(sizeof(*scan_list));
832 if (!scan_list) {
833 scm_err("failed to allocate scan_list");
834 return NULL;
835 }
836 qdf_list_create(scan_list, MAX_SCAN_CACHE_SIZE);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530837
838 scan_entry = qdf_mem_malloc(sizeof(*scan_entry));
839 if (!scan_entry) {
840 scm_err("failed to allocate memory for scan_entry");
Sandeep Puligillac6764592017-12-05 21:01:52 -0800841 qdf_mem_free(scan_list);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530842 return NULL;
843 }
844 scan_entry->raw_frame.ptr =
845 qdf_mem_malloc(frame_len);
846 if (!scan_entry->raw_frame.ptr) {
847 scm_err("failed to allocate memory for frame");
848 qdf_mem_free(scan_entry);
Sandeep Puligillac6764592017-12-05 21:01:52 -0800849 qdf_mem_free(scan_list);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530850 return NULL;
851 }
852
853 bcn = (struct wlan_bcn_frame *)
854 (frame + sizeof(*hdr));
855 hdr = (struct wlan_frame_hdr *)frame;
856
gaurank kathpalia26f98332018-01-29 18:09:06 +0530857 /* update timestamp in nanoseconds needed by kernel layers */
Arif Hussain6fcc7902018-03-22 12:33:12 -0700858 scan_entry->boottime_ns = qdf_get_bootbased_boottime_ns();
gaurank kathpalia26f98332018-01-29 18:09:06 +0530859
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530860 scan_entry->frm_subtype = frm_subtype;
861 qdf_mem_copy(scan_entry->bssid.bytes,
862 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
863 /* Scr addr */
864 qdf_mem_copy(scan_entry->mac_addr.bytes,
865 hdr->i_addr2, QDF_MAC_ADDR_SIZE);
866 scan_entry->seq_num =
867 (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
868
869 scan_entry->rssi_raw = rx_param->rssi;
Om Prakash Tripathi6af738b2017-08-22 15:46:38 +0530870 scan_entry->avg_rssi = WLAN_RSSI_IN(scan_entry->rssi_raw);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530871 scan_entry->tsf_delta = rx_param->tsf_delta;
872
gaurank kathpalia26f98332018-01-29 18:09:06 +0530873 /* Copy per chain rssi to scan entry */
874 qdf_mem_copy(scan_entry->per_chain_snr, rx_param->rssi_ctl,
875 WLAN_MGMT_TXRX_HOST_MAX_ANTENNA);
876
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530877 /* store jiffies */
878 scan_entry->rrm_parent_tsf = (u_int32_t) qdf_system_ticks();
879
880 scan_entry->bcn_int = le16toh(bcn->beacon_interval);
881
882 /*
883 * In case if the beacon dosnt have
884 * valid beacon interval falback to def
885 */
886 if (!scan_entry->bcn_int)
887 scan_entry->bcn_int = 100;
888 scan_entry->cap_info.value = le16toh(bcn->capability.value);
889 qdf_mem_copy(scan_entry->tsf_info.data,
890 bcn->timestamp, 8);
891 scan_entry->erp = ERP_NON_ERP_PRESENT;
892
Om Prakash Tripathicdcbb392017-04-18 18:51:20 +0530893 scan_entry->scan_entry_time =
894 qdf_mc_timer_get_system_time();
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530895
896 scan_entry->raw_frame.len = frame_len;
897 qdf_mem_copy(scan_entry->raw_frame.ptr,
898 frame, frame_len);
899 status = util_scan_populate_bcn_ie_list(scan_entry);
900 if (QDF_IS_STATUS_ERROR(status)) {
Om Prakash Tripathi8e9beae2018-04-27 14:35:39 +0530901 scm_debug("failed to parse beacon IE");
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530902 qdf_mem_free(scan_entry->raw_frame.ptr);
903 qdf_mem_free(scan_entry);
Sandeep Puligillac6764592017-12-05 21:01:52 -0800904 qdf_mem_free(scan_list);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530905 return NULL;
906 }
907
908 if (!scan_entry->ie_list.rates) {
909 qdf_mem_free(scan_entry->raw_frame.ptr);
910 qdf_mem_free(scan_entry);
Sandeep Puligillac6764592017-12-05 21:01:52 -0800911 qdf_mem_free(scan_list);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530912 return NULL;
913 }
914
915 ssid = (struct ie_ssid *)
916 scan_entry->ie_list.ssid;
917
918 if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
919 qdf_mem_free(scan_entry->raw_frame.ptr);
920 qdf_mem_free(scan_entry);
Sandeep Puligillac6764592017-12-05 21:01:52 -0800921 qdf_mem_free(scan_list);
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530922 return NULL;
923 }
924
925 if (scan_entry->ie_list.p2p)
926 scan_entry->is_p2p = true;
927
928 /* If no channel info is present in beacon use meta channel */
929 if (!scan_entry->channel.chan_idx) {
930 scan_entry->channel.chan_idx =
931 rx_param->channel;
932 } else if (rx_param->channel !=
933 scan_entry->channel.chan_idx) {
Shashikala Prabhu7edbb052018-04-12 09:55:25 +0530934 if (!wlan_reg_chan_is_49ghz(pdev, scan_entry->channel.chan_idx))
935 scan_entry->channel_mismatch = true;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530936 }
937
938 if (util_scan_is_hidden_ssid(ssid)) {
939 scan_entry->ie_list.ssid = NULL;
940 } else {
941 qdf_mem_copy(scan_entry->ssid.ssid,
942 ssid->ssid, WLAN_SSID_MAX_LEN);
943 scan_entry->ssid.length = ssid->ssid_len;
944 scan_entry->hidden_ssid_timestamp =
945 scan_entry->scan_entry_time;
946 }
947
948 if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx))
949 scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry);
950 else
951 scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry);
952
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530953 scan_entry->nss = util_scan_scm_calc_nss_supported_by_ap(scan_entry);
954 util_scan_scm_update_bss_with_esp_data(scan_entry);
Abhishek Singh7b599032017-11-10 14:42:31 +0530955 qbss_load = (struct qbss_load_ie *)
956 util_scan_entry_qbssload(scan_entry);
957 if (qbss_load)
958 scan_entry->qbss_chan_load = qbss_load->qbss_chan_load;
Abhishek Singhb80af7e2017-07-19 18:48:42 +0530959
Sandeep Puligillac6764592017-12-05 21:01:52 -0800960 scan_node = qdf_mem_malloc(sizeof(*scan_node));
961 if (!scan_node) {
Om Prakash Tripathi52402552018-02-21 16:31:49 +0530962 qdf_mem_free(scan_entry->raw_frame.ptr);
Sandeep Puligillac6764592017-12-05 21:01:52 -0800963 qdf_mem_free(scan_entry);
964 qdf_mem_free(scan_list);
965 return NULL;
966 }
967
968 scan_node->entry = scan_entry;
969 qdf_list_insert_front(scan_list, &scan_node->node);
970
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530971 /* TODO calculate channel struct */
Sandeep Puligillac6764592017-12-05 21:01:52 -0800972 return scan_list;
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530973}
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530974
975QDF_STATUS
976util_scan_entry_update_mlme_info(struct wlan_objmgr_pdev *pdev,
977 struct scan_cache_entry *scan_entry)
978{
979
980 if (!pdev || !scan_entry) {
Jeff Johnson878533e2017-09-18 10:07:54 -0700981 scm_err("pdev 0x%pK, scan_entry: 0x%pK", pdev, scan_entry);
Om Prakash Tripathic3fcb682017-08-01 18:24:55 +0530982 return QDF_STATUS_E_INVAL;
983 }
984
985 return scm_update_scan_mlme_info(pdev, scan_entry);
986}