blob: 373440eb6e316d5945f4a56d3e81bc1977623386 [file] [log] [blame]
Om Prakash Tripathi7e3f45d2016-12-28 16:58:54 +05301/*
2 * Copyright (c) 2017 The Linux Foundation. All rights reserved.
3 *
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>
28
29const char*
30util_scan_get_ev_type_name(enum scan_event_type type)
31{
32 static const char * const event_name[] = {
33 [SCAN_EVENT_TYPE_STARTED] = "STARTED",
34 [SCAN_EVENT_TYPE_COMPLETED] = "COMPLETED",
35 [SCAN_EVENT_TYPE_BSS_CHANNEL] = "HOME_CHANNEL",
36 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL] = "FOREIGN_CHANNEL",
37 [SCAN_EVENT_TYPE_DEQUEUED] = "DEQUEUED",
38 [SCAN_EVENT_TYPE_PREEMPTED] = "PREEMPTED",
39 [SCAN_EVENT_TYPE_START_FAILED] = "START_FAILED",
40 [SCAN_EVENT_TYPE_RESTARTED] = "RESTARTED",
41 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_EXIT] = "FOREIGN_CHANNEL_EXIT",
42 [SCAN_EVENT_TYPE_SUSPENDED] = "SUSPENDED",
43 [SCAN_EVENT_TYPE_RESUMED] = "RESUMED",
44 [SCAN_EVENT_TYPE_NLO_COMPLETE] = "NLO_COMPLETE",
45 [SCAN_EVENT_TYPE_INVALID] = "INVALID",
46 [SCAN_EVENT_TYPE_GPIO_TIMEOUT] = "GPIO_TIMEOUT",
47 [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_START] =
48 "RADIO_MEASUREMENT_START",
49 [SCAN_EVENT_TYPE_RADIO_MEASUREMENT_END] =
50 "RADIO_MEASUREMENT_END",
51 [SCAN_EVENT_TYPE_BSSID_MATCH] = "BSSID_MATCH",
52 [SCAN_EVENT_TYPE_FOREIGN_CHANNEL_GET_NF] =
53 "FOREIGN_CHANNEL_GET_NF",
54 };
55
Abhishek Singh483d9142017-03-06 13:28:13 +053056 if (type >= SCAN_EVENT_TYPE_MAX)
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053057 return "UNKNOWN";
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053058
59 return event_name[type];
60}
61
62
63const char*
64util_scan_get_ev_reason_name(enum scan_completion_reason reason)
65{
66 static const char * const reason_name[] = {
67 [SCAN_REASON_NONE] = "NONE",
68 [SCAN_REASON_COMPLETED] = "COMPLETED",
69 [SCAN_REASON_CANCELLED] = "CANCELLED",
70 [SCAN_REASON_PREEMPTED] = "PREEMPTED",
71 [SCAN_REASON_TIMEDOUT] = "TIMEDOUT",
72 [SCAN_REASON_INTERNAL_FAILURE] = "INTERNAL_FAILURE",
73 [SCAN_REASON_SUSPENDED] = "SUSPENDED",
74 [SCAN_REASON_RUN_FAILED] = "RUN_FAILED",
75 [SCAN_REASON_TERMINATION_FUNCTION] = "TERMINATION_FUNCTION",
76 [SCAN_REASON_MAX_OFFCHAN_RETRIES] = "MAX_OFFCHAN_RETRIES",
77 };
78
Abhishek Singh483d9142017-03-06 13:28:13 +053079 if (reason >= SCAN_REASON_MAX)
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053080 return "UNKNOWN";
Om Prakash Tripathi22f95dc2016-12-19 10:45:59 +053081
82 return reason_name[reason];
83}
84
85qdf_time_t
86util_get_last_scan_time(struct wlan_objmgr_vdev *vdev)
87{
88 uint8_t pdev_id;
89 struct wlan_scan_obj *scan_obj;
90
91 if (!vdev) {
92 scm_warn("null vdev");
93 QDF_ASSERT(0);
94 return 0;
95 }
96 pdev_id = wlan_scan_vdev_get_pdev_id(vdev);
97 scan_obj = wlan_vdev_get_scan_obj(vdev);
98
99 return scan_obj->pdev_info[pdev_id].last_scan_time;
100}
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530101
102static enum wlan_band scm_chan_to_band(uint32_t chan)
103{
104 if (WLAN_CHAN_IS_2GHZ(chan))
105 return WLAN_BAND_2_4_GHZ;
106
107 return WLAN_BAND_5_GHZ;
108}
109
Abhishek Singhd4e600f2017-02-21 15:16:28 +0530110bool util_is_scan_entry_match(
111 struct scan_cache_entry *entry1,
112 struct scan_cache_entry *entry2)
113{
114
115 if (entry1->cap_info.wlan_caps.ess !=
116 entry1->cap_info.wlan_caps.ess)
117 return false;
118
119 if (entry1->cap_info.wlan_caps.ess &&
120 !qdf_mem_cmp(entry1->bssid.bytes,
121 entry1->bssid.bytes, QDF_MAC_ADDR_SIZE) &&
122 scm_chan_to_band(
123 entry1->channel.chan_idx) ==
124 scm_chan_to_band(entry2->channel.chan_idx)) {
125 /* Check for BSS */
126 if (util_is_ssid_match(
127 &entry1->ssid, &entry2->ssid))
128 return true;
129 } else if (entry1->cap_info.wlan_caps.ibss &&
130 (entry1->channel.chan_idx ==
131 entry2->channel.chan_idx)) {
132 /*
133 * Same channel cannot have same SSID for
134 * different IBSS, so no need to check BSSID
135 */
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->cap_info.wlan_caps.ess &&
141 !qdf_mem_cmp(entry1->bssid.bytes,
142 entry1->bssid.bytes, QDF_MAC_ADDR_SIZE)) {
143 /* In case of P2P devices, ess and ibss will be set to zero */
144 return true;
145 }
146
147 return false;
148}
149
Abhishek Singh4caf1a92017-02-21 15:01:08 +0530150static bool util_is_pureg_rate(uint8_t *rates, uint8_t nrates)
151{
152 static const uint8_t g_rates[] = {12, 18, 24, 36, 48, 72, 96, 108};
153 bool pureg = false;
154 uint8_t i, j;
155
156 for (i = 0; i < nrates; i++) {
157 for (j = 0; j < QDF_ARRAY_SIZE(g_rates); j++) {
158 if (WLAN_RV(rates[i]) == g_rates[j]) {
159 pureg = true;
160 break;
161 }
162 }
163 if (pureg)
164 break;
165 }
166
167 return pureg;
168}
169static enum wlan_phymode
170util_scan_get_phymode_5g(struct scan_cache_entry *scan_params)
171{
172 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
173 uint16_t ht_cap = 0;
174 struct htcap_cmn_ie *htcap;
175 struct wlan_ie_htinfo_cmn *htinfo;
176 struct wlan_ie_vhtop *vhtop;
177
178 htcap = (struct htcap_cmn_ie *)
179 util_scan_entry_htcap(scan_params);
180 htinfo = (struct wlan_ie_htinfo_cmn *)
181 util_scan_entry_htinfo(scan_params);
182 vhtop = (struct wlan_ie_vhtop *)
183 util_scan_entry_vhtop(scan_params);
184
185 if (!(htcap && htinfo))
186 return WLAN_PHYMODE_11A;
187
188 if (htcap)
189 ht_cap = le16toh(htcap->hc_cap);
190
191 if (util_scan_entry_vhtcap(scan_params) && vhtop) {
192 switch (vhtop->vht_op_chwidth) {
193 case WLAN_VHTOP_CHWIDTH_2040:
194 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
195 (htinfo->hi_extchoff ==
196 WLAN_HTINFO_EXTOFFSET_ABOVE))
197 phymode = WLAN_PHYMODE_11AC_VHT40PLUS;
198 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
199 (htinfo->hi_extchoff ==
200 WLAN_HTINFO_EXTOFFSET_BELOW))
201 phymode = WLAN_PHYMODE_11AC_VHT40MINUS;
202 else
203 phymode = WLAN_PHYMODE_11AC_VHT20;
204 break;
205 case WLAN_VHTOP_CHWIDTH_80:
206 if (WLAN_IS_REVSIG_VHT80_80(vhtop))
207 phymode = WLAN_PHYMODE_11AC_VHT80_80;
208 else if (WLAN_IS_REVSIG_VHT160(vhtop))
209 phymode = WLAN_PHYMODE_11AC_VHT160;
210 else
211 phymode = WLAN_PHYMODE_11AC_VHT80;
212 break;
213 case WLAN_VHTOP_CHWIDTH_160:
214 phymode = WLAN_PHYMODE_11AC_VHT160;
215 break;
216 case WLAN_VHTOP_CHWIDTH_80_80:
217 phymode = WLAN_PHYMODE_11AC_VHT80_80;
218 break;
219 default:
220 scm_err("bad channel: %d",
221 vhtop->vht_op_chwidth);
222 break;
223 }
224 } else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
225 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
226 phymode = WLAN_PHYMODE_11NA_HT40PLUS;
227 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
228 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
229 phymode = WLAN_PHYMODE_11NA_HT40MINUS;
230 else
231 phymode = WLAN_PHYMODE_11NA_HT20;
232
233 return phymode;
234}
235
236static enum wlan_phymode
237util_scan_get_phymode_2g(struct scan_cache_entry *scan_params)
238{
239 enum wlan_phymode phymode = WLAN_PHYMODE_AUTO;
240 uint16_t ht_cap = 0;
241 struct htcap_cmn_ie *htcap;
242 struct wlan_ie_htinfo_cmn *htinfo;
243 struct wlan_ie_vhtop *vhtop;
244
245 htcap = (struct htcap_cmn_ie *)
246 util_scan_entry_htcap(scan_params);
247 htinfo = (struct wlan_ie_htinfo_cmn *)
248 util_scan_entry_htinfo(scan_params);
249 vhtop = (struct wlan_ie_vhtop *)
250 util_scan_entry_vhtop(scan_params);
251
252 if (htcap)
253 ht_cap = le16toh(htcap->hc_cap);
254
255 if (htcap && htinfo) {
256 if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
257 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_ABOVE))
258 phymode = WLAN_PHYMODE_11NG_HT40PLUS;
259 else if ((ht_cap & WLAN_HTCAP_C_CHWIDTH40) &&
260 (htinfo->hi_extchoff == WLAN_HTINFO_EXTOFFSET_BELOW))
261 phymode = WLAN_PHYMODE_11NG_HT40MINUS;
262 else
263 phymode = WLAN_PHYMODE_11NG_HT20;
264 } else if (util_scan_entry_xrates(scan_params)) {
265 /* only 11G stations will have more than 8 rates */
266 phymode = WLAN_PHYMODE_11G;
267 } else {
268 /* Some mischievous g-only APs do not set extended rates */
269 if (util_scan_entry_rates(scan_params)) {
270 if (util_is_pureg_rate(&scan_params->ie_list.rates[2],
271 scan_params->ie_list.rates[1]))
272 phymode = WLAN_PHYMODE_11G;
273 else
274 phymode = WLAN_PHYMODE_11B;
275 } else {
276 phymode = WLAN_PHYMODE_11B;
277 }
278 }
279
280 return phymode;
281}
282
283static QDF_STATUS
284util_scan_parse_chan_switch_wrapper_ie(struct scan_cache_entry *scan_params,
285 struct ie_header *sub_ie, qdf_size_t sub_ie_len)
286{
287 /* Walk through to check nothing is malformed */
288 while (sub_ie_len >= sizeof(struct ie_header)) {
289 /* At least one more header is present */
290 sub_ie_len -= sizeof(struct ie_header);
291
292 if (sub_ie->ie_len == 0) {
293 sub_ie += 1;
294 continue;
295 }
296 if (sub_ie_len < sub_ie->ie_len) {
297 scm_err("Incomplete corrupted IE:%x",
298 WLAN_ELEMID_CHAN_SWITCH_WRAP);
299 return QDF_STATUS_E_INVAL;
300 }
301 switch (sub_ie->ie_id) {
302 case WLAN_ELEMID_COUNTRY:
303 scan_params->ie_list.country = (uint8_t *)sub_ie;
304 break;
305 case WLAN_ELEMID_WIDE_BAND_CHAN_SWITCH:
306 scan_params->ie_list.widebw = (uint8_t *)sub_ie;
307 break;
308 case WLAN_ELEMID_VHT_TX_PWR_ENVLP:
309 scan_params->ie_list.txpwrenvlp = (uint8_t *)sub_ie;
310 break;
311 }
312 /* Consume sub info element */
313 sub_ie_len -= sub_ie->ie_len;
314 /* go to next Sub IE */
315 sub_ie = (struct ie_header *)
316 (((uint8_t *) sub_ie) +
317 sizeof(struct ie_header) + sub_ie->ie_len);
318 }
319
320 return QDF_STATUS_SUCCESS;
321}
322
323static bool
324util_scan_is_hidden_ssid(struct ie_ssid *ssid)
325{
326 uint8_t i;
327
328 /*
329 * We flag this as Hidden SSID if the Length is 0
330 * of the SSID only contains 0's
331 */
332 if (!ssid || !ssid->ssid_len)
333 return true;
334
335 for (i = 0; i < ssid->ssid_len; i++)
336 if (ssid->ssid[i] != 0)
337 return false;
338
339 /* All 0's */
340 return true;
341}
342
343static void
344util_scan_parse_vendor_ie(struct scan_cache_entry *scan_params,
345 struct ie_header *ie)
346{
347
348 if (scan_params->ie_list.vendor == NULL)
349 scan_params->ie_list.vendor = (uint8_t *)ie;
350
351 if (is_wpa_oui((uint8_t *)ie)) {
352 scan_params->ie_list.wpa = (uint8_t *)ie;
353 } else if (is_wps_oui((uint8_t *)ie)) {
354 scan_params->ie_list.wps = (uint8_t *)ie;
355 /* WCN IE should be a subset of WPS IE */
356 if (is_wcn_oui((uint8_t *)ie))
357 scan_params->ie_list.wcn = (uint8_t *)ie;
358 } else if (is_wme_param((uint8_t *)ie)) {
359 scan_params->ie_list.wmeparam = (uint8_t *)ie;
360 } else if (is_wme_info((uint8_t *)ie)) {
361 scan_params->ie_list.wmeinfo = (uint8_t *)ie;
362 } else if (is_atheros_oui((uint8_t *)ie)) {
363 scan_params->ie_list.athcaps = (uint8_t *)ie;
364 } else if (is_atheros_extcap_oui((uint8_t *)ie)) {
365 scan_params->ie_list.athextcaps = (uint8_t *)ie;
366 } else if (is_sfa_oui((uint8_t *)ie)) {
367 scan_params->ie_list.sfa = (uint8_t *)ie;
368 } else if (is_p2p_oui((uint8_t *)ie)) {
369 scan_params->ie_list.p2p = (uint8_t *)ie;
370 } else if (is_qca_whc_oui((uint8_t *)ie,
371 QCA_OUI_WHC_AP_INFO_SUBTYPE)) {
372 scan_params->ie_list.sonadv = (uint8_t *)ie;
373 } else if (is_ht_cap((uint8_t *)ie)) {
374 /* we only care if there isn't already an HT IE (ANA) */
375 if (scan_params->ie_list.htcap == NULL)
376 scan_params->ie_list.htcap =
377 (uint8_t *)&(((struct wlan_vendor_ie_htcap *)ie)->ie);
378 } else if (is_ht_info((uint8_t *)ie)) {
379 /* we only care if there isn't already an HT IE (ANA) */
380 if (scan_params->ie_list.htinfo == NULL)
381 scan_params->ie_list.htinfo =
382 (uint8_t *)&(((struct wlan_vendor_ie_htinfo *)
383 ie)->hi_ie);
384 } else if (is_interop_vht((uint8_t *)ie) &&
385 !(scan_params->ie_list.vhtop)) {
386 /* location where Interop Vht Cap IE and VHT OP IE Present */
387 scan_params->ie_list.vhtcap = (((uint8_t *)(ie)) + 7);
388 scan_params->ie_list.vhtop = (((uint8_t *)(ie)) + 21);
389 } else if (is_bwnss_oui((uint8_t *)ie)) {
390 /*
391 * Bandwidth-NSS map has sub-type & version.
392 * hence copy data just after version byte
393 */
394 scan_params->ie_list.bwnss_map = (((uint8_t *)ie) + 8);
395 }
396}
397
398static QDF_STATUS
399util_scan_populate_bcn_ie_list(struct scan_cache_entry *scan_params)
400{
401 struct ie_header *ie, *sub_ie;
402 uint32_t ie_len, sub_ie_len;
403 QDF_STATUS status;
404
405 ie_len = util_scan_entry_ie_len(scan_params);
406 ie = (struct ie_header *)
407 util_scan_entry_ie_data(scan_params);
408
409 while (ie_len >= sizeof(struct ie_header)) {
410 ie_len -= sizeof(struct ie_header);
411
412 if (!ie->ie_len) {
413 ie += 1;
414 continue;
415 }
416
417 if (ie_len < ie->ie_len) {
418 scm_err("Incomplete corrupted IE:%x",
419 ie->ie_id);
420 return QDF_STATUS_E_INVAL;
421 }
422
423 switch (ie->ie_id) {
424 case WLAN_ELEMID_SSID:
425 scan_params->ie_list.ssid = (uint8_t *)ie;
426 break;
427 case WLAN_ELEMID_RATES:
428 scan_params->ie_list.rates = (uint8_t *)ie;
429 break;
430 case WLAN_ELEMID_DSPARMS:
431 scan_params->channel.chan_idx =
432 ((struct ds_ie *)ie)->cur_chan;
433 break;
434 case WLAN_ELEMID_TIM:
435 scan_params->ie_list.tim = (uint8_t *)ie;
436 scan_params->dtim_period =
437 ((struct wlan_tim_ie *)ie)->tim_period;
438 break;
439 case WLAN_ELEMID_COUNTRY:
440 scan_params->ie_list.country = (uint8_t *)ie;
441 break;
442 case WLAN_ELEMID_QBSS_LOAD:
443 scan_params->ie_list.qbssload = (uint8_t *)ie;
444 break;
445 case WLAN_ELEMID_CHANSWITCHANN:
446 scan_params->ie_list.csa = (uint8_t *)ie;
447 break;
448 case WLAN_ELEMID_IBSSDFS:
449 scan_params->ie_list.ibssdfs = (uint8_t *)ie;
450 break;
451 case WLAN_ELEMID_QUIET:
452 scan_params->ie_list.quiet = (uint8_t *)ie;
453 break;
454 case WLAN_ELEMID_ERP:
455 scan_params->erp = ((struct erp_ie *)ie)->value;
456 break;
457 case WLAN_ELEMID_HTCAP_ANA:
458 scan_params->ie_list.htcap =
459 (uint8_t *)&(((struct htcap_ie *)ie)->ie);
460 break;
461 case WLAN_ELEMID_RSN:
462 scan_params->ie_list.rsn = (uint8_t *)ie;
463 break;
464 case WLAN_ELEMID_XRATES:
465 scan_params->ie_list.xrates = (uint8_t *)ie;
466 break;
467 case WLAN_ELEMID_EXTCHANSWITCHANN:
468 scan_params->ie_list.xcsa = (uint8_t *)ie;
469 break;
470 case WLAN_ELEMID_SECCHANOFFSET:
471 scan_params->ie_list.secchanoff = (uint8_t *)ie;
472 break;
473 case WLAN_ELEMID_HTINFO_ANA:
474 scan_params->ie_list.htinfo =
475 (uint8_t *)&(((struct wlan_ie_htinfo *) ie)->hi_ie);
476 scan_params->channel.chan_idx =
477 ((struct wlan_ie_htinfo_cmn *)
478 (scan_params->ie_list.htinfo))->hi_ctrlchannel;
479 break;
480 case WLAN_ELEMID_WAPI:
481 scan_params->ie_list.wapi = (uint8_t *)ie;
482 break;
483 case WLAN_ELEMID_XCAPS:
484 scan_params->ie_list.extcaps = (uint8_t *)ie;
485 break;
486 case WLAN_ELEMID_VHTCAP:
487 scan_params->ie_list.vhtcap = (uint8_t *)ie;
488 break;
489 case WLAN_ELEMID_VHTOP:
490 scan_params->ie_list.vhtop = (uint8_t *)ie;
491 break;
492 case WLAN_ELEMID_OP_MODE_NOTIFY:
493 scan_params->ie_list.opmode = (uint8_t *)ie;
494 break;
495 case WLAN_ELEMID_MOBILITY_DOMAIN:
496 scan_params->ie_list.mdie = (uint8_t *)ie;
497 break;
498 case WLAN_ELEMID_VENDOR:
499 util_scan_parse_vendor_ie(scan_params,
500 ie);
501 break;
502 case WLAN_ELEMID_CHAN_SWITCH_WRAP:
503 scan_params->ie_list.cswrp = (uint8_t *)ie;
504 /* Go to next sub IE */
505 sub_ie = (struct ie_header *)
506 (((uint8_t *)ie) + sizeof(struct ie_header));
507 sub_ie_len = ie->ie_len;
508 status =
509 util_scan_parse_chan_switch_wrapper_ie(
510 scan_params, sub_ie, sub_ie_len);
511 if (QDF_IS_STATUS_ERROR(status)) {
512 scm_err("failed to parse chan_switch_wrapper_ie");
513 return status;
514 }
515 break;
516 default:
517 break;
518 }
519
520 /* Consume info element */
521 ie_len -= ie->ie_len;
522 /* Go to next IE */
523 ie = (struct ie_header *)
524 (((uint8_t *) ie) +
525 sizeof(struct ie_header) +
526 ie->ie_len);
527 }
528
529 return QDF_STATUS_SUCCESS;
530}
531
532struct scan_cache_entry *
533util_scan_unpack_beacon_frame(uint8_t *frame,
534 qdf_size_t frame_len, uint32_t frm_subtype,
535 struct mgmt_rx_event_params *rx_param)
536{
537 struct wlan_frame_hdr *hdr;
538 struct wlan_bcn_frame *bcn;
539 QDF_STATUS status;
540 struct ie_ssid *ssid;
541 struct scan_cache_entry *scan_entry = NULL;
542
543 scan_entry = qdf_mem_malloc(sizeof(*scan_entry));
544 if (!scan_entry) {
545 scm_err("failed to allocate memory for scan_entry");
546 return NULL;
547 }
548 scan_entry->raw_frame.ptr =
549 qdf_mem_malloc(frame_len);
550 if (!scan_entry->raw_frame.ptr) {
551 scm_err("failed to allocate memory for frame");
552 qdf_mem_free(scan_entry);
553 return NULL;
554 }
555
556 bcn = (struct wlan_bcn_frame *)
557 (frame + sizeof(*hdr));
558 hdr = (struct wlan_frame_hdr *)frame;
559
560 scan_entry->frm_subtype = frm_subtype;
561 qdf_mem_copy(scan_entry->bssid.bytes,
562 hdr->i_addr3, QDF_MAC_ADDR_SIZE);
563 /* Scr addr */
564 qdf_mem_copy(scan_entry->mac_addr.bytes,
565 hdr->i_addr2, QDF_MAC_ADDR_SIZE);
566 scan_entry->seq_num =
567 (le16toh(*(uint16_t *)hdr->i_seq) >> WLAN_SEQ_SEQ_SHIFT);
568
569 scan_entry->rssi_raw = rx_param->rssi;
570 scan_entry->tsf_delta = rx_param->tsf_delta;
571
572 /* store jiffies */
573 scan_entry->rrm_parent_tsf = (u_int32_t) qdf_system_ticks();
574
575 scan_entry->bcn_int = le16toh(bcn->beacon_interval);
576
577 /*
578 * In case if the beacon dosnt have
579 * valid beacon interval falback to def
580 */
581 if (!scan_entry->bcn_int)
582 scan_entry->bcn_int = 100;
583 scan_entry->cap_info.value = le16toh(bcn->capability.value);
584 qdf_mem_copy(scan_entry->tsf_info.data,
585 bcn->timestamp, 8);
586 scan_entry->erp = ERP_NON_ERP_PRESENT;
587
588
589 scan_entry->rssi_timestamp =
590 scan_entry->scan_entry_time =
591 qdf_mc_timer_get_system_time();
592
593 scan_entry->raw_frame.len = frame_len;
594 qdf_mem_copy(scan_entry->raw_frame.ptr,
595 frame, frame_len);
596 status = util_scan_populate_bcn_ie_list(scan_entry);
597 if (QDF_IS_STATUS_ERROR(status)) {
598 scm_err("failed to parse beacon IE");
599 qdf_mem_free(scan_entry->raw_frame.ptr);
600 qdf_mem_free(scan_entry);
601 return NULL;
602 }
603
604 if (!scan_entry->ie_list.rates) {
605 qdf_mem_free(scan_entry->raw_frame.ptr);
606 qdf_mem_free(scan_entry);
607 return NULL;
608 }
609
610 ssid = (struct ie_ssid *)
611 scan_entry->ie_list.ssid;
612
613 if (ssid && (ssid->ssid_len > WLAN_SSID_MAX_LEN)) {
614 qdf_mem_free(scan_entry->raw_frame.ptr);
615 qdf_mem_free(scan_entry);
616 return NULL;
617 }
618
619 if (scan_entry->ie_list.p2p)
620 scan_entry->is_p2p = true;
621
622 /* If no channel info is present in beacon use meta channel */
623 if (!scan_entry->channel.chan_idx) {
624 scan_entry->channel.chan_idx =
625 rx_param->channel;
626 } else if (rx_param->channel !=
627 scan_entry->channel.chan_idx) {
628 scan_entry->channel_mismatch = true;
629 }
630
631 if (util_scan_is_hidden_ssid(ssid)) {
632 scan_entry->ie_list.ssid = NULL;
633 } else {
634 qdf_mem_copy(scan_entry->ssid.ssid,
635 ssid->ssid, WLAN_SSID_MAX_LEN);
636 scan_entry->ssid.length = ssid->ssid_len;
637 scan_entry->hidden_ssid_timestamp =
638 scan_entry->scan_entry_time;
639 }
640
641 if (WLAN_CHAN_IS_5GHZ(scan_entry->channel.chan_idx))
642 scan_entry->phy_mode = util_scan_get_phymode_5g(scan_entry);
643 else
644 scan_entry->phy_mode = util_scan_get_phymode_2g(scan_entry);
645
646 /* TODO calculate channel struct */
647 return scan_entry;
648}