blob: 81028d65ac4c1b54ab2b1b1478d1e2dfead46462 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Abhinav Kumar5670d362018-01-16 17:31:54 +05302 * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * 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/*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080020 * This file lim_scan_result_utils.cc contains the utility functions
21 * LIM uses for maintaining and accessing scan results on STA.
22 * Author: Chandra Modumudi
23 * Date: 02/13/02
24 * History:-
25 * Date Modified by Modification Information
26 * --------------------------------------------------------------------
27 */
28
29#include "lim_types.h"
30#include "lim_utils.h"
31#include "lim_ser_des_utils.h"
32#include "lim_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080033#include "lim_ft_defs.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080034#include "lim_session.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080035#include "rrm_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080036#include "cds_utils.h"
37
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080038/**
39 * lim_collect_bss_description()
40 *
41 ***FUNCTION:
42 * This function is called during scan upon receiving
43 * Beacon/Probe Response frame to check if the received
44 * frame matches scan criteria, collect BSS description
45 * and add it to cached scan results.
46 *
47 ***LOGIC:
48 *
49 ***ASSUMPTIONS:
50 * NA
51 *
52 ***NOTE:
53 * NA
54 *
Jeff Johnson348973e2018-11-22 16:51:12 -080055 * @param mac - Pointer to Global MAC structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080056 * @param pBPR - Pointer to parsed Beacon/Probe Response structure
57 * @param pRxPacketInfo - Pointer to Received frame's BD
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080058 * @param fScanning - flag to indicate if it is during scan.
59 * ---------------------------------------------
60 *
61 * @return None
62 */
Ganesh Kondabattini53e873e2016-05-30 15:29:03 +053063void
Jeff Johnson9320c1e2018-12-02 13:09:20 -080064lim_collect_bss_description(struct mac_context *mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080065 tSirBssDescription *pBssDescr,
66 tpSirProbeRespBeacon pBPR,
67 uint8_t *pRxPacketInfo, uint8_t fScanning)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080068{
69 uint8_t *pBody;
70 uint32_t ieLen = 0;
71 tpSirMacMgmtHdr pHdr;
72 uint8_t channelNum;
73 uint8_t rxChannel;
74 uint8_t rfBand = 0;
75
76 pHdr = WMA_GET_RX_MAC_HEADER(pRxPacketInfo);
77
78 if (SIR_MAC_B_PR_SSID_OFFSET > WMA_GET_RX_PAYLOAD_LEN(pRxPacketInfo)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053079 QDF_ASSERT(WMA_GET_RX_PAYLOAD_LEN(pRxPacketInfo) >=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080 SIR_MAC_B_PR_SSID_OFFSET);
Ganesh Kondabattini53e873e2016-05-30 15:29:03 +053081 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082 }
83 ieLen =
84 WMA_GET_RX_PAYLOAD_LEN(pRxPacketInfo) - SIR_MAC_B_PR_SSID_OFFSET;
85 rxChannel = WMA_GET_RX_CH(pRxPacketInfo);
86 pBody = WMA_GET_RX_MPDU_DATA(pRxPacketInfo);
87 rfBand = WMA_GET_RX_RFBAND(pRxPacketInfo);
88
89 /**
90 * Length of BSS desription is without length of
91 * length itself and length of pointer that holds ieFields.
92 *
93 * tSirBssDescription
94 * +--------+---------------------------------+---------------+
95 * | length | other fields | pointer to IEs|
96 * +--------+---------------------------------+---------------+
97 * ^
98 * ieFields
99 */
100 pBssDescr->length = (uint16_t)(offsetof(tSirBssDescription, ieFields[0])
101 - sizeof(pBssDescr->length) + ieLen);
102
103 /* Copy BSS Id */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530104 qdf_mem_copy((uint8_t *) &pBssDescr->bssId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800105 (uint8_t *) pHdr->bssId, sizeof(tSirMacAddr));
106
107 /* Copy Timestamp, Beacon Interval and Capability Info */
Ashish Kumar Dhanotiya09d22cf2017-06-29 14:09:16 +0530108 pBssDescr->scansystimensec = qdf_get_bootbased_boottime_ns();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800109
110 pBssDescr->timeStamp[0] = pBPR->timeStamp[0];
111 pBssDescr->timeStamp[1] = pBPR->timeStamp[1];
112 pBssDescr->beaconInterval = pBPR->beaconInterval;
113 pBssDescr->capabilityInfo =
114 lim_get_u16((uint8_t *) &pBPR->capabilityInfo);
115
116 if (!pBssDescr->beaconInterval) {
Nishank Aggarwal89713662017-03-23 16:55:13 +0530117 pe_warn("Beacon Interval is ZERO, making it to default 100 "
118 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pHdr->bssId));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800119 pBssDescr->beaconInterval = 100;
120 }
121 /*
122 * There is a narrow window after Channel Switch msg is sent to HAL and before the AGC is shut
123 * down and beacons/Probe Rsps can trickle in and we may report the incorrect channel in 5Ghz
124 * band, so not relying on the 'last Scanned Channel' stored in LIM.
125 * Instead use the value returned by RXP in BD. This the the same value which HAL programs into
126 * RXP before every channel switch.
127 * Right now there is a problem in 5Ghz, where we are receiving beacons from a channel different from
128 * the currently scanned channel. so incorrect channel is reported to CSR and association does not happen.
129 * So for now we keep on looking for the channel info in the beacon (DSParamSet IE OR HT Info IE), and only if it
130 * is not present in the beacon, we go for the channel info present in RXP.
131 * This fix will work for 5Ghz 11n devices, but for 11a devices, we have to rely on RXP routing flag to get the correct channel.
132 * So The problem of incorrect channel reporting in 5Ghz will still remain for 11a devices.
133 */
Jeff Johnson348973e2018-11-22 16:51:12 -0800134 pBssDescr->channelId = lim_get_channel_from_beacon(mac, pBPR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800135
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800136 pBssDescr->channelIdSelf = pBssDescr->channelId;
Deepak Dhamdhere652d7e82015-08-06 14:16:53 -0700137 pBssDescr->rx_channel = rxChannel;
138
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800139 /* set the network type in bss description */
140 channelNum = pBssDescr->channelId;
141 pBssDescr->nwType =
Jeff Johnson348973e2018-11-22 16:51:12 -0800142 lim_get_nw_type(mac, channelNum, SIR_MAC_MGMT_FRAME, pBPR);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800143
144 /* Copy RSSI & SINR from BD */
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -0700145 pBssDescr->rssi = (int8_t) WMA_GET_RX_RSSI_NORMALIZED(pRxPacketInfo);
146 pBssDescr->rssi_raw = (int8_t) WMA_GET_RX_RSSI_RAW(pRxPacketInfo);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800147
148 /* SINR no longer reported by HW */
149 pBssDescr->sinr = 0;
Nishank Aggarwal89713662017-03-23 16:55:13 +0530150 pe_debug(MAC_ADDRESS_STR " rssi: normalized: %d, absolute: %d",
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -0700151 MAC_ADDR_ARRAY(pHdr->bssId), pBssDescr->rssi,
152 pBssDescr->rssi_raw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800153
Deepthi Gowri6acee342016-10-28 15:00:38 +0530154 pBssDescr->received_time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155 pBssDescr->tsf_delta = WMA_GET_RX_TSF_DELTA(pRxPacketInfo);
Krishna Kumaar Natarajan89a99d42016-08-04 15:44:38 -0700156 pBssDescr->seq_ctrl = pHdr->seqControl;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800157
Abhinav Kumar5670d362018-01-16 17:31:54 +0530158 pe_debug("Received %s from BSSID: %pM tsf_delta = %u Seq Num: %x ssid:%.*s, rssi: %d",
159 pBssDescr->fProbeRsp ? "Probe Rsp" : "Beacon", pHdr->bssId,
160 pBssDescr->tsf_delta, ((pHdr->seqControl.seqNumHi <<
161 HIGH_SEQ_NUM_OFFSET) | pHdr->seqControl.seqNumLo),
162 pBPR->ssId.length, pBPR->ssId.ssId, pBssDescr->rssi_raw);
Krishna Kumaar Natarajan89a99d42016-08-04 15:44:38 -0700163
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164 if (fScanning) {
Jeff Johnson348973e2018-11-22 16:51:12 -0800165 rrm_get_start_tsf(mac, pBssDescr->startTSF);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800166 pBssDescr->parentTSF = WMA_GET_RX_TIMESTAMP(pRxPacketInfo);
167 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800168
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800169 /* MobilityDomain */
170 pBssDescr->mdie[0] = 0;
171 pBssDescr->mdie[1] = 0;
172 pBssDescr->mdie[2] = 0;
173 pBssDescr->mdiePresent = false;
174 /* If mdie is present in the probe resp we */
175 /* fill it in the bss description */
176 if (pBPR->mdiePresent) {
177 pBssDescr->mdiePresent = true;
178 pBssDescr->mdie[0] = pBPR->mdie[0];
179 pBssDescr->mdie[1] = pBPR->mdie[1];
180 pBssDescr->mdie[2] = pBPR->mdie[2];
181 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182
183#ifdef FEATURE_WLAN_ESE
184 pBssDescr->QBSSLoad_present = false;
185 pBssDescr->QBSSLoad_avail = 0;
186 if (pBPR->QBSSLoad.present) {
187 pBssDescr->QBSSLoad_present = true;
188 pBssDescr->QBSSLoad_avail = pBPR->QBSSLoad.avail;
189 }
190#endif
191 /* Copy IE fields */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530192 qdf_mem_copy((uint8_t *) &pBssDescr->ieFields,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800193 pBody + SIR_MAC_B_PR_SSID_OFFSET, ieLen);
194
195 /*set channel number in beacon in case it is not present */
196 pBPR->channelNumber = pBssDescr->channelId;
Jeff Johnson348973e2018-11-22 16:51:12 -0800197 mac->lim.beacon_probe_rsp_cnt_per_scan++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198
Ganesh Kondabattini53e873e2016-05-30 15:29:03 +0530199 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800200} /*** end lim_collect_bss_description() ***/