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