blob: fb63738fa95c1e778796f3de1f56147632fae469 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Abhishek Singhed55b242017-12-20 11:02:34 +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/*
Nishank Aggarwal9ca32552017-03-31 16:23:26 +053020 * DOC: csr_util.c
21 *
22 * Implementation supporting routines for CSR.
23 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080024
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080025#include "ani_global.h"
26
27#include "csr_support.h"
28#include "csr_inside_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080029#include "sme_qos_internal.h"
30#include "wma_types.h"
31#include "cds_utils.h"
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -080032#include "wlan_policy_mgr_api.h"
Varun Reddy Yeturu35c07f92017-02-28 10:35:00 -080033#include "wlan_serialization_legacy_api.h"
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070034#include "wlan_reg_services_api.h"
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -070035#include "wlan_crypto_global_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080036
37
38uint8_t csr_wpa_oui[][CSR_WPA_OUI_SIZE] = {
39 {0x00, 0x50, 0xf2, 0x00}
40 ,
41 {0x00, 0x50, 0xf2, 0x01}
42 ,
43 {0x00, 0x50, 0xf2, 0x02}
44 ,
45 {0x00, 0x50, 0xf2, 0x03}
46 ,
47 {0x00, 0x50, 0xf2, 0x04}
48 ,
49 {0x00, 0x50, 0xf2, 0x05}
50 ,
51#ifdef FEATURE_WLAN_ESE
52 {0x00, 0x40, 0x96, 0x00}
53 , /* CCKM */
54#endif /* FEATURE_WLAN_ESE */
55};
56
Mukul Sharma05504ac2017-06-08 12:35:53 +053057/*
58 * PLEASE DO NOT ADD THE #IFDEF IN BELOW TABLE,
59 * IF STILL REQUIRE THEN PLEASE ADD NULL ENTRIES
60 * OTHERWISE IT WILL BREAK OTHER LOWER
61 * SECUIRTY MODES.
62 */
63
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064uint8_t csr_rsn_oui[][CSR_RSN_OUI_SIZE] = {
65 {0x00, 0x0F, 0xAC, 0x00}
66 , /* group cipher */
67 {0x00, 0x0F, 0xAC, 0x01}
68 , /* WEP-40 or RSN */
69 {0x00, 0x0F, 0xAC, 0x02}
70 , /* TKIP or RSN-PSK */
71 {0x00, 0x0F, 0xAC, 0x03}
72 , /* Reserved */
73 {0x00, 0x0F, 0xAC, 0x04}
74 , /* AES-CCMP */
75 {0x00, 0x0F, 0xAC, 0x05}
76 , /* WEP-104 */
77 {0x00, 0x40, 0x96, 0x00}
78 , /* CCKM */
79 {0x00, 0x0F, 0xAC, 0x06}
80 , /* BIP (encryption type) or
Nishank Aggarwal9ca32552017-03-31 16:23:26 +053081 * RSN-PSK-SHA256 (authentication type)
82 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080083 /* RSN-8021X-SHA256 (authentication type) */
Mukul Sharma05504ac2017-06-08 12:35:53 +053084 {0x00, 0x0F, 0xAC, 0x05},
85#ifdef WLAN_FEATURE_FILS_SK
86#define ENUM_FILS_SHA256 9
87 /* FILS SHA256 */
88 {0x00, 0x0F, 0xAC, 0x0E},
89#define ENUM_FILS_SHA384 10
90 /* FILS SHA384 */
91 {0x00, 0x0F, 0xAC, 0x0F},
92#define ENUM_FT_FILS_SHA256 11
93 /* FILS FT SHA256 */
94 {0x00, 0x0F, 0xAC, 0x10},
95#define ENUM_FT_FILS_SHA384 12
96 /* FILS FT SHA384 */
97 {0x00, 0x0F, 0xAC, 0x11},
98#else
99 {0x00, 0x00, 0x00, 0x00},
100 {0x00, 0x00, 0x00, 0x00},
101 {0x00, 0x00, 0x00, 0x00},
102 {0x00, 0x00, 0x00, 0x00},
103#endif
104 /* AES GCMP */
105 {0x00, 0x0F, 0xAC, 0x08},
106 /* AES GCMP-256 */
107 {0x00, 0x0F, 0xAC, 0x09},
Abhishek Singh02cb9e02017-08-30 17:39:50 +0530108#define ENUM_DPP_RSN 15
109 /* DPP RSN */
110 {0x50, 0x6F, 0x9A, 0x02},
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +0530111#define ENUM_OWE 16
112 /* OWE https://tools.ietf.org/html/rfc8110 */
113 {0x00, 0x0F, 0xAC, 0x12},
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +0530114#define ENUM_SUITEB_EAP256 17
115 {0x00, 0x0F, 0xAC, 0x0B},
116#define ENUM_SUITEB_EAP384 18
117 {0x00, 0x0F, 0xAC, 0x0C},
118
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +0530119#ifdef WLAN_FEATURE_SAE
120#define ENUM_SAE 19
121 /* SAE */
122 {0x00, 0x0F, 0xAC, 0x08},
123#define ENUM_FT_SAE 20
124 /* FT SAE */
125 {0x00, 0x0F, 0xAC, 0x09},
126#else
127 {0x00, 0x00, 0x00, 0x00},
128 {0x00, 0x00, 0x00, 0x00},
129#endif
130
Mukul Sharma05504ac2017-06-08 12:35:53 +0530131 /* define new oui here, update #define CSR_OUI_***_INDEX */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800132};
133
134#ifdef FEATURE_WLAN_WAPI
135uint8_t csr_wapi_oui[][CSR_WAPI_OUI_SIZE] = {
136 {0x00, 0x14, 0x72, 0x00}
137 , /* Reserved */
138 {0x00, 0x14, 0x72, 0x01}
139 , /* WAI certificate or SMS4 */
140 {0x00, 0x14, 0x72, 0x02} /* WAI PSK */
141};
142#endif /* FEATURE_WLAN_WAPI */
143uint8_t csr_wme_info_oui[CSR_WME_OUI_SIZE] = { 0x00, 0x50, 0xf2, 0x02 };
144uint8_t csr_wme_parm_oui[CSR_WME_OUI_SIZE] = { 0x00, 0x50, 0xf2, 0x02 };
145
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +0530146uint8_t csr_group_mgmt_oui[][CSR_RSN_OUI_SIZE] = {
147#define ENUM_CMAC 0
148 {0x00, 0x0F, 0xAC, 0x06},
149#define ENUM_GMAC_128 1
150 {0x00, 0x0F, 0xAC, 0x0B},
151#define ENUM_GMAC_256 2
152 {0x00, 0x0F, 0xAC, 0x0C},
153};
154
155
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156/* ////////////////////////////////////////////////////////////////////// */
157
158/**
159 * \var g_phy_rates_suppt
160 *
161 * \brief Rate support lookup table
162 *
163 *
164 * This is a lookup table indexing rates & configuration parameters to
165 * support. Given a rate (in unites of 0.5Mpbs) & three bools (MIMO
166 * Enabled, Channel Bonding Enabled, & Concatenation Enabled), one can
167 * determine whether the given rate is supported by computing two
168 * indices. The first maps the rate to table row as indicated below
169 * (i.e. eHddSuppRate_6Mbps maps to row zero, eHddSuppRate_9Mbps to row
170 * 1, and so on). Index two can be computed like so:
171 *
172 * \code
173 * idx2 = ( fEsf ? 0x4 : 0x0 ) |
174 * ( fCb ? 0x2 : 0x0 ) |
175 * ( fMimo ? 0x1 : 0x0 );
176 * \endcode
177 *
178 *
179 * Given that:
180 *
181 * \code
182 * fSupported = g_phy_rates_suppt[idx1][idx2];
183 * \endcode
184 *
185 *
186 * This table is based on the document "PHY Supported Rates.doc". This
187 * table is permissive in that a rate is reflected as being supported
188 * even when turning off an enabled feature would be required. For
189 * instance, "PHY Supported Rates" lists 42Mpbs as unsupported when CB,
190 * ESF, & MIMO are all on. However, if we turn off either of CB or
191 * MIMO, it then becomes supported. Therefore, we mark it as supported
192 * even in index 7 of this table.
193 *
194 *
195 */
196
197static const bool g_phy_rates_suppt[24][8] = {
198
199 /* SSF SSF SSF SSF ESF ESF ESF ESF */
200 /* SIMO MIMO SIMO MIMO SIMO MIMO SIMO MIMO */
201 /* No CB No CB CB CB No CB No CB CB CB */
202 {true, true, true, true, true, true, true, true}, /* 6Mbps */
203 {true, true, true, true, true, true, true, true}, /* 9Mbps */
204 {true, true, true, true, true, true, true, true}, /* 12Mbps */
205 {true, true, true, true, true, true, true, true}, /* 18Mbps */
206 {false, false, true, true, false, false, true, true}, /* 20Mbps */
207 {true, true, true, true, true, true, true, true}, /* 24Mbps */
208 {true, true, true, true, true, true, true, true}, /* 36Mbps */
209 {false, false, true, true, false, true, true, true}, /* 40Mbps */
210 {false, false, true, true, false, true, true, true}, /* 42Mbps */
211 {true, true, true, true, true, true, true, true}, /* 48Mbps */
212 {true, true, true, true, true, true, true, true}, /* 54Mbps */
213 {false, true, true, true, false, true, true, true}, /* 72Mbps */
214 {false, false, true, true, false, true, true, true}, /* 80Mbps */
215 {false, false, true, true, false, true, true, true}, /* 84Mbps */
216 {false, true, true, true, false, true, true, true}, /* 96Mbps */
217 {false, true, true, true, false, true, true, true}, /* 108Mbps */
218 {false, false, true, true, false, true, true, true}, /* 120Mbps */
219 {false, false, true, true, false, true, true, true}, /* 126Mbps */
220 {false, false, false, true, false, false, false, true}, /* 144Mbps */
221 {false, false, false, true, false, false, false, true}, /* 160Mbps */
222 {false, false, false, true, false, false, false, true}, /* 168Mbps */
223 {false, false, false, true, false, false, false, true}, /* 192Mbps */
224 {false, false, false, true, false, false, false, true}, /* 216Mbps */
225 {false, false, false, true, false, false, false, true}, /* 240Mbps */
226
227};
228
229#define CASE_RETURN_STR(n) {\
230 case (n): return (# n);\
231}
232
233const char *get_e_roam_cmd_status_str(eRoamCmdStatus val)
234{
235 switch (val) {
236 CASE_RETURN_STR(eCSR_ROAM_CANCELLED);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530237 CASE_RETURN_STR(eCSR_ROAM_FAILED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800238 CASE_RETURN_STR(eCSR_ROAM_ROAMING_START);
239 CASE_RETURN_STR(eCSR_ROAM_ROAMING_COMPLETION);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530240 CASE_RETURN_STR(eCSR_ROAM_CONNECT_COMPLETION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800241 CASE_RETURN_STR(eCSR_ROAM_ASSOCIATION_START);
242 CASE_RETURN_STR(eCSR_ROAM_ASSOCIATION_COMPLETION);
243 CASE_RETURN_STR(eCSR_ROAM_DISASSOCIATED);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530244 CASE_RETURN_STR(eCSR_ROAM_ASSOCIATION_FAILURE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800245 CASE_RETURN_STR(eCSR_ROAM_SHOULD_ROAM);
246 CASE_RETURN_STR(eCSR_ROAM_SCAN_FOUND_NEW_BSS);
247 CASE_RETURN_STR(eCSR_ROAM_LOSTLINK);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530248 CASE_RETURN_STR(eCSR_ROAM_LOSTLINK_DETECTED);
249 CASE_RETURN_STR(eCSR_ROAM_MIC_ERROR_IND);
250 CASE_RETURN_STR(eCSR_ROAM_IBSS_IND);
251 CASE_RETURN_STR(eCSR_ROAM_CONNECT_STATUS_UPDATE);
252 CASE_RETURN_STR(eCSR_ROAM_GEN_INFO);
253 CASE_RETURN_STR(eCSR_ROAM_SET_KEY_COMPLETE);
254 CASE_RETURN_STR(eCSR_ROAM_IBSS_LEAVE);
255 CASE_RETURN_STR(eCSR_ROAM_INFRA_IND);
256 CASE_RETURN_STR(eCSR_ROAM_WPS_PBC_PROBE_REQ_IND);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530257 CASE_RETURN_STR(eCSR_ROAM_FT_RESPONSE);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530258 CASE_RETURN_STR(eCSR_ROAM_FT_START);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530259 CASE_RETURN_STR(eCSR_ROAM_SESSION_OPENED);
260 CASE_RETURN_STR(eCSR_ROAM_FT_REASSOC_FAILED);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530261 CASE_RETURN_STR(eCSR_ROAM_PMK_NOTIFY);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530262#ifdef FEATURE_WLAN_LFR_METRICS
263 CASE_RETURN_STR(eCSR_ROAM_PREAUTH_INIT_NOTIFY);
264 CASE_RETURN_STR(eCSR_ROAM_PREAUTH_STATUS_SUCCESS);
265 CASE_RETURN_STR(eCSR_ROAM_PREAUTH_STATUS_FAILURE);
266 CASE_RETURN_STR(eCSR_ROAM_HANDOVER_SUCCESS);
267#endif
268#ifdef FEATURE_WLAN_TDLS
269 CASE_RETURN_STR(eCSR_ROAM_TDLS_STATUS_UPDATE);
270 CASE_RETURN_STR(eCSR_ROAM_RESULT_MGMT_TX_COMPLETE_IND);
271#endif
272 CASE_RETURN_STR(eCSR_ROAM_DISCONNECT_ALL_P2P_CLIENTS);
273 CASE_RETURN_STR(eCSR_ROAM_SEND_P2P_STOP_BSS);
274#ifdef WLAN_FEATURE_11W
275 CASE_RETURN_STR(eCSR_ROAM_UNPROT_MGMT_FRAME_IND);
276#endif
277#ifdef WLAN_FEATURE_RMC
278 CASE_RETURN_STR(eCSR_ROAM_IBSS_PEER_INFO_COMPLETE);
279#endif
Srinivas Girigowda515a9ef2015-12-11 11:00:48 -0800280#ifdef FEATURE_WLAN_ESE
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530281 CASE_RETURN_STR(eCSR_ROAM_TSM_IE_IND);
282 CASE_RETURN_STR(eCSR_ROAM_CCKM_PREAUTH_NOTIFY);
283 CASE_RETURN_STR(eCSR_ROAM_ESE_ADJ_AP_REPORT_IND);
284 CASE_RETURN_STR(eCSR_ROAM_ESE_BCN_REPORT_IND);
Srinivas Girigowda515a9ef2015-12-11 11:00:48 -0800285#endif /* FEATURE_WLAN_ESE */
Sreelakshmi Konamki2d67be22017-03-15 18:23:05 +0530286 CASE_RETURN_STR(eCSR_ROAM_DFS_RADAR_IND);
287 CASE_RETURN_STR(eCSR_ROAM_SET_CHANNEL_RSP);
288 CASE_RETURN_STR(eCSR_ROAM_DFS_CHAN_SW_NOTIFY);
289 CASE_RETURN_STR(eCSR_ROAM_EXT_CHG_CHNL_IND);
290 CASE_RETURN_STR(eCSR_ROAM_STA_CHANNEL_SWITCH);
291 CASE_RETURN_STR(eCSR_ROAM_NDP_STATUS_UPDATE);
292 CASE_RETURN_STR(eCSR_ROAM_UPDATE_SCAN_RESULT);
293 CASE_RETURN_STR(eCSR_ROAM_START);
294 CASE_RETURN_STR(eCSR_ROAM_ABORT);
295 CASE_RETURN_STR(eCSR_ROAM_NAPI_OFF);
296 CASE_RETURN_STR(eCSR_ROAM_CHANNEL_COMPLETE_IND);
Padma, Santhosh Kumarb38ab512018-01-16 16:16:46 +0530297 CASE_RETURN_STR(eCSR_ROAM_SAE_COMPUTE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800298 default:
299 return "unknown";
300 }
301}
302
303const char *get_e_csr_roam_result_str(eCsrRoamResult val)
304{
305 switch (val) {
306 CASE_RETURN_STR(eCSR_ROAM_RESULT_NONE);
307 CASE_RETURN_STR(eCSR_ROAM_RESULT_FAILURE);
308 CASE_RETURN_STR(eCSR_ROAM_RESULT_ASSOCIATED);
309 CASE_RETURN_STR(eCSR_ROAM_RESULT_NOT_ASSOCIATED);
310 CASE_RETURN_STR(eCSR_ROAM_RESULT_MIC_FAILURE);
311 CASE_RETURN_STR(eCSR_ROAM_RESULT_FORCED);
312 CASE_RETURN_STR(eCSR_ROAM_RESULT_DISASSOC_IND);
313 CASE_RETURN_STR(eCSR_ROAM_RESULT_DEAUTH_IND);
314 CASE_RETURN_STR(eCSR_ROAM_RESULT_CAP_CHANGED);
Sreelakshmi Konamki2d67be22017-03-15 18:23:05 +0530315 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_STARTED);
316 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_START_FAILED);
317 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_JOIN_SUCCESS);
318 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_JOIN_FAILED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800319 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_CONNECT);
320 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_INACTIVE);
321 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_NEW_PEER);
Sreelakshmi Konamki2d67be22017-03-15 18:23:05 +0530322 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_PEER_DEPARTED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800323 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_COALESCED);
Sreelakshmi Konamki2d67be22017-03-15 18:23:05 +0530324 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_STOP);
325 CASE_RETURN_STR(eCSR_ROAM_RESULT_LOSTLINK);
326 CASE_RETURN_STR(eCSR_ROAM_RESULT_MIC_ERROR_UNICAST);
327 CASE_RETURN_STR(eCSR_ROAM_RESULT_MIC_ERROR_GROUP);
328 CASE_RETURN_STR(eCSR_ROAM_RESULT_AUTHENTICATED);
329 CASE_RETURN_STR(eCSR_ROAM_RESULT_NEW_RSN_BSS);
330 #ifdef FEATURE_WLAN_WAPI
331 CASE_RETURN_STR(eCSR_ROAM_RESULT_NEW_WAPI_BSS);
332 #endif /* FEATURE_WLAN_WAPI */
333 CASE_RETURN_STR(eCSR_ROAM_RESULT_INFRA_STARTED);
334 CASE_RETURN_STR(eCSR_ROAM_RESULT_INFRA_START_FAILED);
335 CASE_RETURN_STR(eCSR_ROAM_RESULT_INFRA_STOPPED);
336 CASE_RETURN_STR(eCSR_ROAM_RESULT_INFRA_ASSOCIATION_IND);
337 CASE_RETURN_STR(eCSR_ROAM_RESULT_INFRA_ASSOCIATION_CNF);
338 CASE_RETURN_STR(eCSR_ROAM_RESULT_INFRA_DISASSOCIATED);
339 CASE_RETURN_STR(eCSR_ROAM_RESULT_WPS_PBC_PROBE_REQ_IND);
340 CASE_RETURN_STR(eCSR_ROAM_RESULT_SEND_ACTION_FAIL);
341 CASE_RETURN_STR(eCSR_ROAM_RESULT_MAX_ASSOC_EXCEEDED);
342 CASE_RETURN_STR(eCSR_ROAM_RESULT_ASSOC_FAIL_CON_CHANNEL);
343 CASE_RETURN_STR(eCSR_ROAM_RESULT_ADD_TDLS_PEER);
344 CASE_RETURN_STR(eCSR_ROAM_RESULT_UPDATE_TDLS_PEER);
345 CASE_RETURN_STR(eCSR_ROAM_RESULT_DELETE_TDLS_PEER);
346 CASE_RETURN_STR(eCSR_ROAM_RESULT_TEARDOWN_TDLS_PEER_IND);
347 CASE_RETURN_STR(eCSR_ROAM_RESULT_DELETE_ALL_TDLS_PEER_IND);
348 CASE_RETURN_STR(eCSR_ROAM_RESULT_LINK_ESTABLISH_REQ_RSP);
349 CASE_RETURN_STR(eCSR_ROAM_RESULT_TDLS_SHOULD_DISCOVER);
350 CASE_RETURN_STR(eCSR_ROAM_RESULT_TDLS_SHOULD_TEARDOWN);
351 CASE_RETURN_STR(eCSR_ROAM_RESULT_TDLS_SHOULD_PEER_DISCONNECTED);
352 CASE_RETURN_STR
353 (eCSR_ROAM_RESULT_TDLS_CONNECTION_TRACKER_NOTIFICATION);
354 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_PEER_INFO_SUCCESS);
355 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_PEER_INFO_FAILED);
356 CASE_RETURN_STR(eCSR_ROAM_RESULT_DFS_RADAR_FOUND_IND);
357 CASE_RETURN_STR(eCSR_ROAM_RESULT_CHANNEL_CHANGE_SUCCESS);
358 CASE_RETURN_STR(eCSR_ROAM_RESULT_CHANNEL_CHANGE_FAILURE);
Abhishek Singh20a8e442018-09-12 15:50:44 +0530359 CASE_RETURN_STR(eCSR_ROAM_RESULT_CSA_RESTART_RSP);
Sreelakshmi Konamki2d67be22017-03-15 18:23:05 +0530360 CASE_RETURN_STR(eCSR_ROAM_RESULT_DFS_CHANSW_UPDATE_SUCCESS);
361 CASE_RETURN_STR(eCSR_ROAM_EXT_CHG_CHNL_UPDATE_IND);
362 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDI_CREATE_RSP);
363 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDI_DELETE_RSP);
364 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_INITIATOR_RSP);
365 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_NEW_PEER_IND);
366 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_CONFIRM_IND);
367 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_INDICATION);
368 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_SCHED_UPDATE_RSP);
369 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_RESPONDER_RSP);
370 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_END_RSP);
371 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_PEER_DEPARTED_IND);
372 CASE_RETURN_STR(eCSR_ROAM_RESULT_NDP_END_IND);
373 CASE_RETURN_STR(eCSR_ROAM_RESULT_SCAN_FOR_SSID_FAILURE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800374 default:
375 return "unknown";
376 }
377}
378
wadesongcb0ded22018-02-02 17:57:20 +0800379const char *csr_phy_mode_str(eCsrPhyMode phy_mode)
380{
381 switch (phy_mode) {
382 case eCSR_DOT11_MODE_abg:
383 return "abg";
384 case eCSR_DOT11_MODE_11a:
385 return "11a";
386 case eCSR_DOT11_MODE_11b:
387 return "11b";
388 case eCSR_DOT11_MODE_11g:
389 return "11g";
390 case eCSR_DOT11_MODE_11n:
391 return "11n";
392 case eCSR_DOT11_MODE_11g_ONLY:
393 return "11g_only";
394 case eCSR_DOT11_MODE_11n_ONLY:
395 return "11n_only";
396 case eCSR_DOT11_MODE_11b_ONLY:
397 return "11b_only";
398 case eCSR_DOT11_MODE_11ac:
399 return "11ac";
400 case eCSR_DOT11_MODE_11ac_ONLY:
401 return "11ac_only";
402 case eCSR_DOT11_MODE_AUTO:
403 return "auto";
404 case eCSR_DOT11_MODE_11ax:
405 return "11ax";
406 case eCSR_DOT11_MODE_11ax_ONLY:
407 return "11ax_only";
408 default:
409 return "unknown";
410 }
411}
412
Jeff Johnson009c40f2018-11-05 09:54:37 -0800413void csr_purge_vdev_pending_ser_cmd_list(struct mac_context *mac_ctx,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +0530414 uint32_t vdev_id)
Sandeep Puligillaef415362017-08-30 16:37:13 -0700415{
Sandeep Puligillaef415362017-08-30 16:37:13 -0700416 wlan_serialization_purge_cmd_list_by_vdev_id(mac_ctx->psoc, vdev_id,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +0530417 false, true, false,
418 true, false);
Sandeep Puligillaef415362017-08-30 16:37:13 -0700419}
420
Jeff Johnson009c40f2018-11-05 09:54:37 -0800421void csr_purge_vdev_all_ser_cmd_list(struct mac_context *mac_ctx,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +0530422 uint32_t vdev_id)
Krunal Soni81f068c2017-02-23 19:51:55 -0800423{
Krunal Soni33787902017-08-29 11:39:28 -0700424 wlan_serialization_purge_cmd_list_by_vdev_id(mac_ctx->psoc, vdev_id,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +0530425 true, true, true,
426 true, true);
Krunal Soni81f068c2017-02-23 19:51:55 -0800427}
428
Jeff Johnson009c40f2018-11-05 09:54:37 -0800429void csr_purge_vdev_all_scan_ser_cmd_list(struct mac_context *mac_ctx,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +0530430 uint32_t vdev_id)
Krunal Sonia8270f52017-02-23 19:51:25 -0800431{
Krunal Soni33787902017-08-29 11:39:28 -0700432 wlan_serialization_purge_cmd_list_by_vdev_id(mac_ctx->psoc, vdev_id,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +0530433 true, true, false,
434 false, false);
Krunal Sonia8270f52017-02-23 19:51:25 -0800435}
436
Jeff Johnson009c40f2018-11-05 09:54:37 -0800437void csr_purge_pdev_all_ser_cmd_list(struct mac_context *mac_ctx)
Krunal Sonia8270f52017-02-23 19:51:25 -0800438{
Abhishek Singh13bf0ce2018-10-24 14:26:14 +0530439 wlan_serialization_purge_cmd_list(mac_ctx->psoc, NULL, true, true,
440 true, true, true);
Krunal Sonia8270f52017-02-23 19:51:25 -0800441}
442
Jeff Johnson009c40f2018-11-05 09:54:37 -0800443void csr_nonscan_active_ll_insert_head(struct mac_context *mac_ctx,
444 tListElem *entry, bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800445{
446}
447
Jeff Johnson009c40f2018-11-05 09:54:37 -0800448void csr_nonscan_pending_ll_insert_head(struct mac_context *mac_ctx,
449 tListElem *entry, bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800450{
451}
452
Jeff Johnson009c40f2018-11-05 09:54:37 -0800453void csr_nonscan_pending_ll_insert_tail(struct mac_context *mac_ctx,
454 tListElem *entry, bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800455{
456}
Krunal Soni81f068c2017-02-23 19:51:55 -0800457
Jeff Johnson009c40f2018-11-05 09:54:37 -0800458void csr_nonscan_pending_ll_unlock(struct mac_context *mac_ctx)
Krunal Soni20126cb2017-02-15 16:26:57 -0800459{
Krunal Soni20126cb2017-02-15 16:26:57 -0800460}
461
Jeff Johnson009c40f2018-11-05 09:54:37 -0800462void csr_nonscan_active_ll_unlock(struct mac_context *mac_ctx)
Krunal Soni20126cb2017-02-15 16:26:57 -0800463{
Krunal Soni20126cb2017-02-15 16:26:57 -0800464}
465
Jeff Johnson009c40f2018-11-05 09:54:37 -0800466void csr_nonscan_pending_ll_lock(struct mac_context *mac_ctx)
Krunal Soni20126cb2017-02-15 16:26:57 -0800467{
Krunal Soni20126cb2017-02-15 16:26:57 -0800468}
469
Jeff Johnson009c40f2018-11-05 09:54:37 -0800470void csr_nonscan_active_ll_lock(struct mac_context *mac_ctx)
Krunal Soni20126cb2017-02-15 16:26:57 -0800471{
Krunal Sonia8270f52017-02-23 19:51:25 -0800472}
Krunal Soni81f068c2017-02-23 19:51:55 -0800473
Jeff Johnson009c40f2018-11-05 09:54:37 -0800474uint32_t csr_nonscan_active_ll_count(struct mac_context *mac_ctx)
Krunal Sonia8270f52017-02-23 19:51:25 -0800475{
476 return wlan_serialization_get_active_list_count(mac_ctx->psoc, false);
477}
478
Jeff Johnson009c40f2018-11-05 09:54:37 -0800479uint32_t csr_nonscan_pending_ll_count(struct mac_context *mac_ctx)
Krunal Sonia8270f52017-02-23 19:51:25 -0800480{
481 return wlan_serialization_get_pending_list_count(mac_ctx->psoc, false);
482}
483
Jeff Johnson009c40f2018-11-05 09:54:37 -0800484bool csr_nonscan_active_ll_is_list_empty(struct mac_context *mac_ctx,
485 bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800486{
487 return !wlan_serialization_get_active_list_count(mac_ctx->psoc, false);
488}
Jeff Johnson009c40f2018-11-05 09:54:37 -0800489
490bool csr_nonscan_pending_ll_is_list_empty(struct mac_context *mac_ctx,
491 bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800492{
493 return !wlan_serialization_get_pending_list_count(mac_ctx->psoc, false);
494}
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -0700495
Jeff Johnson009c40f2018-11-05 09:54:37 -0800496tListElem *csr_nonscan_active_ll_peek_head(struct mac_context *mac_ctx,
497 bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800498{
499 struct wlan_serialization_command *cmd;
500 tSmeCmd *sme_cmd;
501
Krunal Sonia8270f52017-02-23 19:51:25 -0800502 cmd = wlan_serialization_peek_head_active_cmd_using_psoc(mac_ctx->psoc,
503 false);
504 if (!cmd) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -0700505 sme_err("No cmd found");
Krunal Sonia8270f52017-02-23 19:51:25 -0800506 return NULL;
507 }
508 sme_cmd = cmd->umac_cmd;
Krunal Sonia8270f52017-02-23 19:51:25 -0800509
510 return &sme_cmd->Link;
511}
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -0700512
Jeff Johnson009c40f2018-11-05 09:54:37 -0800513tListElem *csr_nonscan_pending_ll_peek_head(struct mac_context *mac_ctx,
514 bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800515{
516 struct wlan_serialization_command *cmd;
517 tSmeCmd *sme_cmd;
518
Krunal Sonia8270f52017-02-23 19:51:25 -0800519 cmd = wlan_serialization_peek_head_pending_cmd_using_psoc(mac_ctx->psoc,
520 false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -0700521 if (!cmd)
Krunal Sonia8270f52017-02-23 19:51:25 -0800522 return NULL;
Dustin Brown1e3ec6b2018-08-07 11:18:47 -0700523
Krunal Sonia8270f52017-02-23 19:51:25 -0800524 sme_cmd = cmd->umac_cmd;
Krunal Sonia8270f52017-02-23 19:51:25 -0800525
526 return &sme_cmd->Link;
527}
Krunal Soni81f068c2017-02-23 19:51:55 -0800528
Jeff Johnson009c40f2018-11-05 09:54:37 -0800529bool csr_nonscan_active_ll_remove_entry(struct mac_context *mac_ctx,
530 tListElem *entry, bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800531{
532 tListElem *head;
533
Krunal Sonia8270f52017-02-23 19:51:25 -0800534 head = csr_nonscan_active_ll_peek_head(mac_ctx, inter_locked);
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -0700535 if (head == entry)
536 return true;
537
538 return false;
Krunal Sonia8270f52017-02-23 19:51:25 -0800539}
Krunal Sonid8e8e3d2017-02-23 19:52:28 -0800540
Jeff Johnson009c40f2018-11-05 09:54:37 -0800541tListElem *csr_nonscan_active_ll_remove_head(struct mac_context *mac_ctx,
542 bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800543{
544 return csr_nonscan_active_ll_peek_head(mac_ctx, inter_locked);
545}
Krunal Soni81f068c2017-02-23 19:51:55 -0800546
Jeff Johnson009c40f2018-11-05 09:54:37 -0800547tListElem *csr_nonscan_pending_ll_remove_head(struct mac_context *mac_ctx,
548 bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800549{
550 return csr_nonscan_pending_ll_peek_head(mac_ctx, inter_locked);
551}
552
Jeff Johnson009c40f2018-11-05 09:54:37 -0800553tListElem *csr_nonscan_pending_ll_next(struct mac_context *mac_ctx,
554 tListElem *entry, bool inter_locked)
Krunal Sonia8270f52017-02-23 19:51:25 -0800555{
556 tSmeCmd *sme_cmd;
557 struct wlan_serialization_command cmd, *tcmd;
558
Krunal Sonia8270f52017-02-23 19:51:25 -0800559 if (!entry)
560 return NULL;
561 sme_cmd = GET_BASE_ADDR(entry, tSmeCmd, Link);
Krunal Sonida0e1e72018-06-01 10:50:38 -0700562 cmd.cmd_id = sme_cmd->cmd_id;
Krunal Sonia8270f52017-02-23 19:51:25 -0800563 cmd.cmd_type = csr_get_cmd_type(sme_cmd);
Jianmin Zhu9058c522018-09-18 20:24:35 +0800564 cmd.vdev = wlan_objmgr_get_vdev_by_id_from_psoc_no_state(
565 mac_ctx->psoc,
Krunal Sonia8270f52017-02-23 19:51:25 -0800566 sme_cmd->sessionId, WLAN_LEGACY_SME_ID);
567 tcmd = wlan_serialization_get_pending_list_next_node_using_psoc(
568 mac_ctx->psoc, &cmd, false);
Krunal Sonid8e8e3d2017-02-23 19:52:28 -0800569 if (cmd.vdev)
570 wlan_objmgr_vdev_release_ref(cmd.vdev, WLAN_LEGACY_SME_ID);
Krunal Sonia8270f52017-02-23 19:51:25 -0800571 if (!tcmd) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -0700572 sme_err("No cmd found");
Krunal Sonia8270f52017-02-23 19:51:25 -0800573 return NULL;
574 }
575 sme_cmd = tcmd->umac_cmd;
Krunal Sonia8270f52017-02-23 19:51:25 -0800576 return &sme_cmd->Link;
Krunal Soni20126cb2017-02-15 16:26:57 -0800577}
578
Jeff Johnson20ac1c42018-06-03 12:09:02 -0700579bool csr_get_bss_id_bss_desc(tSirBssDescription *pSirBssDesc,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530580 struct qdf_mac_addr *pBssId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800581{
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530582 qdf_mem_copy(pBssId, &pSirBssDesc->bssId[0],
Anurag Chouhan6d760662016-02-20 16:05:43 +0530583 sizeof(struct qdf_mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584 return true;
585}
586
Jeff Johnson8aef3f62018-06-03 13:21:15 -0700587bool csr_is_bss_id_equal(tSirBssDescription *pSirBssDesc1,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800588 tSirBssDescription *pSirBssDesc2)
589{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800590 bool fEqual = false;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530591 struct qdf_mac_addr bssId1;
592 struct qdf_mac_addr bssId2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800593
594 do {
595 if (!pSirBssDesc1)
596 break;
597 if (!pSirBssDesc2)
598 break;
599
Jeff Johnson20ac1c42018-06-03 12:09:02 -0700600 if (!csr_get_bss_id_bss_desc(pSirBssDesc1, &bssId1))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601 break;
Jeff Johnson20ac1c42018-06-03 12:09:02 -0700602 if (!csr_get_bss_id_bss_desc(pSirBssDesc2, &bssId2))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 break;
604
Anurag Chouhanc5548422016-02-24 18:33:27 +0530605 fEqual = qdf_is_macaddr_equal(&bssId1, &bssId2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606 } while (0);
607
608 return fEqual;
609}
610
Dustin Brown6619bc22018-07-18 15:04:33 -0700611static bool csr_is_conn_state(tpAniSirGlobal mac_ctx, uint32_t session_id,
612 eCsrConnectState state)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800613{
Dustin Brown6619bc22018-07-18 15:04:33 -0700614 QDF_BUG(session_id < CSR_ROAM_SESSION_MAX);
615 if (session_id >= CSR_ROAM_SESSION_MAX)
616 return false;
617
618 return mac_ctx->roam.roamSession[session_id].connectState == state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800619}
620
Dustin Brown6619bc22018-07-18 15:04:33 -0700621bool csr_is_conn_state_connected_ibss(tpAniSirGlobal mac_ctx,
622 uint32_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623{
Dustin Brown6619bc22018-07-18 15:04:33 -0700624 return csr_is_conn_state(mac_ctx, session_id,
625 eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626}
627
Dustin Brown6619bc22018-07-18 15:04:33 -0700628bool csr_is_conn_state_disconnected_ibss(tpAniSirGlobal mac_ctx,
629 uint32_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800630{
Dustin Brown6619bc22018-07-18 15:04:33 -0700631 return csr_is_conn_state(mac_ctx, session_id,
632 eCSR_ASSOC_STATE_TYPE_IBSS_DISCONNECTED);
633}
634
635bool csr_is_conn_state_connected_infra(tpAniSirGlobal mac_ctx,
636 uint32_t session_id)
637{
638 return csr_is_conn_state(mac_ctx, session_id,
639 eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800640}
641
642bool csr_is_conn_state_connected(tpAniSirGlobal pMac, uint32_t sessionId)
643{
Dustin Brown6619bc22018-07-18 15:04:33 -0700644 return csr_is_conn_state_connected_ibss(pMac, sessionId) ||
645 csr_is_conn_state_connected_infra(pMac, sessionId) ||
646 csr_is_conn_state_connected_wds(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800647}
648
649bool csr_is_conn_state_infra(tpAniSirGlobal pMac, uint32_t sessionId)
650{
651 return csr_is_conn_state_connected_infra(pMac, sessionId);
652}
653
654bool csr_is_conn_state_ibss(tpAniSirGlobal pMac, uint32_t sessionId)
655{
656 return csr_is_conn_state_connected_ibss(pMac, sessionId) ||
657 csr_is_conn_state_disconnected_ibss(pMac, sessionId);
658}
659
Dustin Brown6619bc22018-07-18 15:04:33 -0700660bool csr_is_conn_state_connected_wds(tpAniSirGlobal mac_ctx,
661 uint32_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800662{
Dustin Brown6619bc22018-07-18 15:04:33 -0700663 return csr_is_conn_state(mac_ctx, session_id,
664 eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800665}
666
Dustin Brown6619bc22018-07-18 15:04:33 -0700667bool csr_is_conn_state_connected_infra_ap(tpAniSirGlobal mac_ctx,
668 uint32_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800669{
Dustin Brown6619bc22018-07-18 15:04:33 -0700670 return csr_is_conn_state(mac_ctx, session_id,
671 eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED) ||
672 csr_is_conn_state(mac_ctx, session_id,
673 eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674}
675
Dustin Brown6619bc22018-07-18 15:04:33 -0700676bool csr_is_conn_state_disconnected_wds(tpAniSirGlobal mac_ctx,
677 uint32_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800678{
Dustin Brown6619bc22018-07-18 15:04:33 -0700679 return csr_is_conn_state(mac_ctx, session_id,
680 eCSR_ASSOC_STATE_TYPE_WDS_DISCONNECTED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681}
682
683bool csr_is_conn_state_wds(tpAniSirGlobal pMac, uint32_t sessionId)
684{
685 return csr_is_conn_state_connected_wds(pMac, sessionId) ||
686 csr_is_conn_state_disconnected_wds(pMac, sessionId);
687}
688
Jeff Johnson054d0282016-10-07 10:35:54 -0700689static bool csr_is_conn_state_ap(tpAniSirGlobal pMac, uint32_t sessionId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690{
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530691 struct csr_roam_session *pSession;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +0530692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 pSession = CSR_GET_SESSION(pMac, sessionId);
694 if (!pSession)
695 return false;
696 if (CSR_IS_INFRA_AP(&pSession->connectedProfile))
697 return true;
698 return false;
699}
700
701bool csr_is_any_session_in_connect_state(tpAniSirGlobal pMac)
702{
703 uint32_t i;
704 bool fRc = false;
705
706 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
707 if (CSR_IS_SESSION_VALID(pMac, i) &&
708 (csr_is_conn_state_infra(pMac, i)
709 || csr_is_conn_state_ibss(pMac, i)
710 || csr_is_conn_state_ap(pMac, i))) {
711 fRc = true;
712 break;
713 }
714 }
715
716 return fRc;
717}
718
719int8_t csr_get_infra_session_id(tpAniSirGlobal pMac)
720{
721 uint8_t i;
722 int8_t sessionid = -1;
723
724 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
725 if (CSR_IS_SESSION_VALID(pMac, i)
726 && csr_is_conn_state_infra(pMac, i)) {
727 sessionid = i;
728 break;
729 }
730 }
731
732 return sessionid;
733}
734
735uint8_t csr_get_infra_operation_channel(tpAniSirGlobal pMac, uint8_t sessionId)
736{
737 uint8_t channel;
738
739 if (CSR_IS_SESSION_VALID(pMac, sessionId)) {
740 channel =
741 pMac->roam.roamSession[sessionId].connectedProfile.
742 operationChannel;
743 } else {
744 channel = 0;
745 }
746 return channel;
747}
748
749bool csr_is_session_client_and_connected(tpAniSirGlobal pMac, uint8_t sessionId)
750{
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530751 struct csr_roam_session *pSession = NULL;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +0530752
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 if (CSR_IS_SESSION_VALID(pMac, sessionId)
754 && csr_is_conn_state_infra(pMac, sessionId)) {
755 pSession = CSR_GET_SESSION(pMac, sessionId);
756 if (NULL != pSession->pCurRoamProfile) {
757 if ((pSession->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530758 QDF_STA_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759 || (pSession->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530760 QDF_P2P_CLIENT_MODE))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 return true;
762 }
763 }
764 return false;
765}
766
767/**
768 * csr_get_concurrent_operation_channel() - To get concurrent operating channel
769 * @mac_ctx: Pointer to mac context
770 *
771 * This routine will return operating channel on FIRST BSS that is
772 * active/operating to be used for concurrency mode.
773 * If other BSS is not up or not connected it will return 0
774 *
775 * Return: uint8_t
776 */
777uint8_t csr_get_concurrent_operation_channel(tpAniSirGlobal mac_ctx)
778{
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530779 struct csr_roam_session *session = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800780 uint8_t i = 0;
Jeff Johnsonc1e62782017-11-09 09:50:17 -0800781 enum QDF_OPMODE persona;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782
783 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
784 if (!CSR_IS_SESSION_VALID(mac_ctx, i))
785 continue;
786 session = CSR_GET_SESSION(mac_ctx, i);
787 if (NULL == session->pCurRoamProfile)
788 continue;
789 persona = session->pCurRoamProfile->csrPersona;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530790 if ((((persona == QDF_STA_MODE) ||
791 (persona == QDF_P2P_CLIENT_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 (session->connectState ==
793 eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED)) ||
Anurag Chouhan6d760662016-02-20 16:05:43 +0530794 (((persona == QDF_P2P_GO_MODE) ||
795 (persona == QDF_SAP_MODE))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796 && (session->connectState !=
797 eCSR_ASSOC_STATE_TYPE_NOT_CONNECTED)))
798 return session->connectedProfile.operationChannel;
799
800 }
801 return 0;
802}
803
804#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
805
806#define HALF_BW_OF(eCSR_bw_val) ((eCSR_bw_val)/2)
807
808/* calculation of center channel based on V/HT BW and WIFI channel bw=5MHz) */
809
810#define CSR_GET_HT40_PLUS_CCH(och) ((och)+2)
811#define CSR_GET_HT40_MINUS_CCH(och) ((och)-2)
812
813#define CSR_GET_HT80_PLUS_LL_CCH(och) ((och)+6)
814#define CSR_GET_HT80_PLUS_HL_CCH(och) ((och)+2)
815#define CSR_GET_HT80_MINUS_LH_CCH(och) ((och)-2)
816#define CSR_GET_HT80_MINUS_HH_CCH(och) ((och)-6)
817
818/**
819 * csr_get_ch_from_ht_profile() - to get channel from HT profile
820 * @pMac: pointer to Mac context
821 * @htp: pointer to HT profile
822 * @och: operating channel
823 * @cfreq: channel frequency
824 * @hbw: half bandwidth
825 *
826 * This function will fill half bandwidth and channel frequency based
827 * on the HT profile
828 *
829 * Return: none
830 */
Jeff Johnson054d0282016-10-07 10:35:54 -0700831static void csr_get_ch_from_ht_profile(tpAniSirGlobal pMac,
832 tCsrRoamHTProfile *htp,
833 uint16_t och, uint16_t *cfreq,
834 uint16_t *hbw)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835{
836 uint16_t cch, ch_bond;
837
838 if (och > 14)
839 ch_bond = pMac->roam.configParam.channelBondingMode5GHz;
840 else
841 ch_bond = pMac->roam.configParam.channelBondingMode24GHz;
842
843 cch = och;
844 *hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
845
846 if (!ch_bond)
847 goto ret;
848
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -0700849 sme_debug("HTC: %d scbw: %d rcbw: %d sco: %d VHTC: %d apc: %d apbw: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 htp->htCapability, htp->htSupportedChannelWidthSet,
851 htp->htRecommendedTxWidthSet,
852 htp->htSecondaryChannelOffset,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 htp->vhtCapability, htp->apCenterChan, htp->apChanWidth
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 );
855
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 if (htp->vhtCapability) {
857 cch = htp->apCenterChan;
858 if (htp->apChanWidth == WNI_CFG_VHT_CHANNEL_WIDTH_80MHZ)
859 *hbw = HALF_BW_OF(eCSR_BW_80MHz_VAL);
860 else if (htp->apChanWidth == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
861 *hbw = HALF_BW_OF(eCSR_BW_160MHz_VAL);
862
863 if (!*hbw && htp->htCapability) {
864 if (htp->htSupportedChannelWidthSet ==
865 eHT_CHANNEL_WIDTH_40MHZ)
866 *hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
867 else
868 *hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
869 }
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -0800870 } else if (htp->htCapability) {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +0530871 if (htp->htSupportedChannelWidthSet ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872 eHT_CHANNEL_WIDTH_40MHZ) {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +0530873 *hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
874 if (htp->htSecondaryChannelOffset ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875 PHY_DOUBLE_CHANNEL_LOW_PRIMARY)
Nishank Aggarwal9ca32552017-03-31 16:23:26 +0530876 cch = CSR_GET_HT40_PLUS_CCH(och);
877 else if (htp->htSecondaryChannelOffset ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY)
Nishank Aggarwal9ca32552017-03-31 16:23:26 +0530879 cch = CSR_GET_HT40_MINUS_CCH(och);
880 } else {
881 cch = och;
882 *hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 }
Nishank Aggarwal9ca32552017-03-31 16:23:26 +0530884 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885
886ret:
887 *cfreq = cds_chan_to_freq(cch);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888}
889
890/**
891 * csr_calc_chb_for_sap_phymode() - to calc channel bandwidth for sap phymode
892 * @mac_ctx: pointer to mac context
893 * @sap_ch: SAP operating channel
894 * @sap_phymode: SAP physical mode
895 * @sap_cch: concurrency channel
896 * @sap_hbw: SAP half bw
897 * @chb: channel bandwidth
898 *
899 * This routine is called to calculate channel bandwidth
900 *
901 * Return: none
902 */
903static void csr_calc_chb_for_sap_phymode(tpAniSirGlobal mac_ctx,
904 uint16_t *sap_ch, eCsrPhyMode *sap_phymode,
905 uint16_t *sap_cch, uint16_t *sap_hbw, uint8_t *chb)
906{
907 if (*sap_phymode == eCSR_DOT11_MODE_11n ||
908 *sap_phymode == eCSR_DOT11_MODE_11n_ONLY) {
909
910 *sap_hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
911 if (*chb == PHY_DOUBLE_CHANNEL_LOW_PRIMARY)
912 *sap_cch = CSR_GET_HT40_PLUS_CCH(*sap_ch);
913 else if (*chb == PHY_DOUBLE_CHANNEL_HIGH_PRIMARY)
914 *sap_cch = CSR_GET_HT40_MINUS_CCH(*sap_ch);
915
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -0800916 } else if (*sap_phymode == eCSR_DOT11_MODE_11ac ||
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800917 *sap_phymode == eCSR_DOT11_MODE_11ac_ONLY ||
918 *sap_phymode == eCSR_DOT11_MODE_11ax ||
919 *sap_phymode == eCSR_DOT11_MODE_11ax_ONLY) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 /*11AC only 80/40/20 Mhz supported in Rome */
921 if (mac_ctx->roam.configParam.nVhtChannelWidth ==
922 (WNI_CFG_VHT_CHANNEL_WIDTH_80MHZ + 1)) {
923 *sap_hbw = HALF_BW_OF(eCSR_BW_80MHz_VAL);
924 if (*chb ==
925 (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW - 1))
926 *sap_cch = CSR_GET_HT80_PLUS_LL_CCH(*sap_ch);
927 else if (*chb ==
928 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW
929 - 1))
930 *sap_cch = CSR_GET_HT80_PLUS_HL_CCH(*sap_ch);
931 else if (*chb ==
932 (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH
933 - 1))
934 *sap_cch = CSR_GET_HT80_MINUS_LH_CCH(*sap_ch);
935 else if (*chb ==
936 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH
937 - 1))
938 *sap_cch = CSR_GET_HT80_MINUS_HH_CCH(*sap_ch);
939 } else {
940 *sap_hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
941 if (*chb == (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW
942 - 1))
943 *sap_cch = CSR_GET_HT40_PLUS_CCH(*sap_ch);
944 else if (*chb ==
945 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW
946 - 1))
947 *sap_cch = CSR_GET_HT40_MINUS_CCH(*sap_ch);
948 else if (*chb ==
949 (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH
950 - 1))
951 *sap_cch = CSR_GET_HT40_PLUS_CCH(*sap_ch);
952 else if (*chb ==
953 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH
954 - 1))
955 *sap_cch = CSR_GET_HT40_MINUS_CCH(*sap_ch);
956 }
957 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958}
959
960/**
961 * csr_handle_conc_chnl_overlap_for_sap_go - To handle overlap for AP+AP
962 * @mac_ctx: pointer to mac context
963 * @session: Current session
964 * @sap_ch: SAP/GO operating channel
965 * @sap_hbw: SAP/GO half bw
966 * @sap_cfreq: SAP/GO channel frequency
967 * @intf_ch: concurrent SAP/GO operating channel
968 * @intf_hbw: concurrent SAP/GO half bw
969 * @intf_cfreq: concurrent SAP/GO channel frequency
970 *
971 * This routine is called to check if one SAP/GO channel is overlapping with
972 * other SAP/GO channel
973 *
974 * Return: none
975 */
976static void csr_handle_conc_chnl_overlap_for_sap_go(tpAniSirGlobal mac_ctx,
gaurank kathpalia14e2f912017-08-31 14:51:45 +0530977 struct csr_roam_session *session,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 uint16_t *sap_ch, uint16_t *sap_hbw, uint16_t *sap_cfreq,
979 uint16_t *intf_ch, uint16_t *intf_hbw, uint16_t *intf_cfreq)
980{
981 /*
982 * if conc_custom_rule1 is defined then we don't
983 * want p2pgo to follow SAP's channel or SAP to
984 * follow P2PGO's channel.
985 */
986 if (0 == mac_ctx->roam.configParam.conc_custom_rule1 &&
987 0 == mac_ctx->roam.configParam.conc_custom_rule2) {
988 if (*sap_ch == 0) {
989 *sap_ch = session->connectedProfile.operationChannel;
990 csr_get_ch_from_ht_profile(mac_ctx,
991 &session->connectedProfile.HTProfile,
992 *sap_ch, sap_cfreq, sap_hbw);
993 } else if (*sap_ch !=
994 session->connectedProfile.operationChannel) {
995 *intf_ch = session->connectedProfile.operationChannel;
996 csr_get_ch_from_ht_profile(mac_ctx,
997 &session->connectedProfile.HTProfile,
998 *intf_ch, intf_cfreq, intf_hbw);
999 }
1000 } else if (*sap_ch == 0 &&
1001 (session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +05301002 QDF_SAP_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003 *sap_ch = session->connectedProfile.operationChannel;
1004 csr_get_ch_from_ht_profile(mac_ctx,
1005 &session->connectedProfile.HTProfile,
1006 *sap_ch, sap_cfreq, sap_hbw);
1007 }
1008}
1009
1010
1011/**
1012 * csr_check_concurrent_channel_overlap() - To check concurrent overlap chnls
1013 * @mac_ctx: Pointer to mac context
1014 * @sap_ch: SAP channel
1015 * @sap_phymode: SAP phy mode
1016 * @cc_switch_mode: concurrent switch mode
1017 *
1018 * This routine will be called to check concurrent overlap channels
1019 *
1020 * Return: uint16_t
1021 */
1022uint16_t csr_check_concurrent_channel_overlap(tpAniSirGlobal mac_ctx,
1023 uint16_t sap_ch, eCsrPhyMode sap_phymode,
1024 uint8_t cc_switch_mode)
1025{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301026 struct csr_roam_session *session = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 uint8_t i = 0, chb = PHY_SINGLE_CHANNEL_CENTERED;
1028 uint16_t intf_ch = 0, sap_hbw = 0, intf_hbw = 0, intf_cfreq = 0;
1029 uint16_t sap_cfreq = 0;
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +05301030 uint16_t sap_lfreq, sap_hfreq, intf_lfreq, intf_hfreq, sap_cch = 0;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05301031 QDF_STATUS status;
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +05301032
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001033 sme_debug("sap_ch: %d sap_phymode: %d", sap_ch, sap_phymode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034
1035 if (mac_ctx->roam.configParam.cc_switch_mode ==
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301036 QDF_MCC_TO_SCC_SWITCH_DISABLE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 return 0;
1038
1039 if (sap_ch != 0) {
1040 sap_cch = sap_ch;
1041 sap_hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
1042
1043 if (sap_ch > 14)
1044 chb = mac_ctx->roam.configParam.channelBondingMode5GHz;
1045 else
1046 chb = mac_ctx->roam.configParam.channelBondingMode24GHz;
1047
1048 if (chb)
1049 csr_calc_chb_for_sap_phymode(mac_ctx, &sap_ch,
1050 &sap_phymode, &sap_cch, &sap_hbw, &chb);
1051 sap_cfreq = cds_chan_to_freq(sap_cch);
1052 }
1053
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001054 sme_debug("sap_ch:%d sap_phymode:%d sap_cch:%d sap_hbw:%d chb:%d",
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +05301055 sap_ch, sap_phymode, sap_cch, sap_hbw, chb);
1056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1058 if (!CSR_IS_SESSION_VALID(mac_ctx, i))
1059 continue;
1060
1061 session = CSR_GET_SESSION(mac_ctx, i);
1062 if (NULL == session->pCurRoamProfile)
1063 continue;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301064 if (((session->pCurRoamProfile->csrPersona == QDF_STA_MODE) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 (session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +05301066 QDF_P2P_CLIENT_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 (session->connectState ==
1068 eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED)) {
1069 intf_ch = session->connectedProfile.operationChannel;
1070 csr_get_ch_from_ht_profile(mac_ctx,
1071 &session->connectedProfile.HTProfile,
1072 intf_ch, &intf_cfreq, &intf_hbw);
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001073 sme_debug("%d: intf_ch:%d intf_cfreq:%d intf_hbw:%d",
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +05301074 i, intf_ch, intf_cfreq, intf_hbw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075 } else if (((session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +05301076 QDF_P2P_GO_MODE) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077 (session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +05301078 QDF_SAP_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 (session->connectState !=
1080 eCSR_ASSOC_STATE_TYPE_NOT_CONNECTED)) {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301081 if (session->ch_switch_in_progress)
1082 continue;
Edhar, Mahesh Kumardf2ec122015-11-16 11:33:16 +05301083
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301084 csr_handle_conc_chnl_overlap_for_sap_go(mac_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 session, &sap_ch, &sap_hbw, &sap_cfreq,
1086 &intf_ch, &intf_hbw, &intf_cfreq);
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +05301087
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301088 sme_debug("%d: sap_ch:%d sap_hbw:%d sap_cfreq:%d intf_ch:%d intf_hbw:%d, intf_cfreq:%d",
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +05301089 i, sap_ch, sap_hbw, sap_cfreq,
1090 intf_ch, intf_hbw, intf_cfreq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 }
Rachit Kankane11ac4bc2017-09-18 19:58:07 +05301092 if (intf_ch && ((intf_ch > 14 && sap_ch > 14) ||
1093 (intf_ch <= 14 && sap_ch <= 14)))
1094 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001095 }
1096
Ganesh Kondabattinib2eabe32017-09-13 15:16:44 +05301097 sme_debug("intf_ch:%d sap_ch:%d cc_switch_mode:%d, dbs:%d",
1098 intf_ch, sap_ch, cc_switch_mode,
1099 policy_mgr_is_dbs_enable(mac_ctx->psoc));
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +05301100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101 if (intf_ch && sap_ch != intf_ch &&
Bala Venkateshb816ce82018-06-28 17:00:54 +05301102 !policy_mgr_is_force_scc(mac_ctx->psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 sap_lfreq = sap_cfreq - sap_hbw;
1104 sap_hfreq = sap_cfreq + sap_hbw;
1105 intf_lfreq = intf_cfreq - intf_hbw;
1106 intf_hfreq = intf_cfreq + intf_hbw;
1107
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001108 sme_err("SAP: OCH: %03d OCF: %d CCH: %03d CF: %d BW: %d LF: %d HF: %d INTF: OCH: %03d OCF: %d CCH: %03d CF: %d BW: %d LF: %d HF: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 sap_ch, cds_chan_to_freq(sap_ch),
1110 cds_freq_to_chan(sap_cfreq), sap_cfreq, sap_hbw * 2,
1111 sap_lfreq, sap_hfreq, intf_ch,
1112 cds_chan_to_freq(intf_ch), cds_freq_to_chan(intf_cfreq),
1113 intf_cfreq, intf_hbw * 2, intf_lfreq, intf_hfreq);
1114
1115 if (!(((sap_lfreq > intf_lfreq && sap_lfreq < intf_hfreq) ||
1116 (sap_hfreq > intf_lfreq && sap_hfreq < intf_hfreq)) ||
1117 ((intf_lfreq > sap_lfreq && intf_lfreq < sap_hfreq) ||
1118 (intf_hfreq > sap_lfreq && intf_hfreq < sap_hfreq))))
1119 intf_ch = 0;
1120 } else if (intf_ch && sap_ch != intf_ch &&
Manishekar Chandrasekaranf21b3b62016-05-02 16:33:55 +05301121 ((cc_switch_mode == QDF_MCC_TO_SCC_SWITCH_FORCE) ||
Bala Venkateshb816ce82018-06-28 17:00:54 +05301122 policy_mgr_is_force_scc(mac_ctx->psoc))) {
Tushnim Bhattacharyya03103fd2017-06-23 10:48:52 -07001123 if (!((intf_ch <= 14 && sap_ch <= 14) ||
Ganesh Kondabattinib2eabe32017-09-13 15:16:44 +05301124 (intf_ch > 14 && sap_ch > 14))) {
Bala Venkateshb816ce82018-06-28 17:00:54 +05301125 if (policy_mgr_is_dbs_enable(mac_ctx->psoc) ||
1126 cc_switch_mode ==
1127 QDF_MCC_TO_SCC_WITH_PREFERRED_BAND)
Ganesh Kondabattinib2eabe32017-09-13 15:16:44 +05301128 intf_ch = 0;
Jeff Johnson0daa9442017-10-10 16:30:36 -07001129 } else if (cc_switch_mode ==
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05301130 QDF_MCC_TO_SCC_SWITCH_WITH_FAVORITE_CHANNEL) {
1131 status =
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08001132 policy_mgr_get_sap_mandatory_channel(
1133 mac_ctx->psoc,
1134 (uint32_t *)&intf_ch);
Jeff Johnson0daa9442017-10-10 16:30:36 -07001135 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001136 sme_err("no mandatory channel");
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05301137 }
1138 } else if ((intf_ch == sap_ch) && (cc_switch_mode ==
1139 QDF_MCC_TO_SCC_SWITCH_WITH_FAVORITE_CHANNEL)) {
1140 if (cds_chan_to_band(intf_ch) == CDS_BAND_2GHZ) {
1141 status =
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08001142 policy_mgr_get_sap_mandatory_channel(
1143 mac_ctx->psoc, (uint32_t *)&intf_ch);
Jeff Johnson0daa9442017-10-10 16:30:36 -07001144 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001145 sme_err("no mandatory channel");
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05301146 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001147 }
1148
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +05301149 if (intf_ch == sap_ch)
1150 intf_ch = 0;
1151
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001152 sme_err("##Concurrent Channels %s Interfering",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001153 intf_ch == 0 ? "Not" : "Are");
1154 return intf_ch;
1155}
1156#endif
1157
1158bool csr_is_all_session_disconnected(tpAniSirGlobal pMac)
1159{
1160 uint32_t i;
1161 bool fRc = true;
1162
1163 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1164 if (CSR_IS_SESSION_VALID(pMac, i)
1165 && !csr_is_conn_state_disconnected(pMac, i)) {
1166 fRc = false;
1167 break;
1168 }
1169 }
1170
1171 return fRc;
1172}
1173
1174/**
1175 * csr_is_sta_session_connected() - to find if concurrent sta is active
1176 * @mac_ctx: pointer to mac context
1177 *
1178 * This function will iterate through each session and check if sta
1179 * session exist and active
1180 *
1181 * Return: true or false
1182 */
1183bool csr_is_sta_session_connected(tpAniSirGlobal mac_ctx)
1184{
1185 uint32_t i;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301186 struct csr_roam_session *pSession = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187
1188 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1189 if (CSR_IS_SESSION_VALID(mac_ctx, i) &&
1190 !csr_is_conn_state_disconnected(mac_ctx, i)) {
1191 pSession = CSR_GET_SESSION(mac_ctx, i);
1192
1193 if ((NULL != pSession->pCurRoamProfile) &&
Anurag Chouhan6d760662016-02-20 16:05:43 +05301194 (QDF_STA_MODE ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195 pSession->pCurRoamProfile->csrPersona))
1196 return true;
1197 }
1198 }
1199
1200 return false;
1201}
1202
1203/**
1204 * csr_is_p2p_session_connected() - to find if any p2p session is active
1205 * @mac_ctx: pointer to mac context
1206 *
1207 * This function will iterate through each session and check if any p2p
1208 * session exist and active
1209 *
1210 * Return: true or false
1211 */
1212bool csr_is_p2p_session_connected(tpAniSirGlobal pMac)
1213{
1214 uint32_t i;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301215 struct csr_roam_session *pSession = NULL;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08001216 enum QDF_OPMODE persona;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001217
1218 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Naveen Rawat9598f5e2016-06-27 15:33:40 -07001219 if (!CSR_IS_SESSION_VALID(pMac, i))
1220 continue;
1221
1222 if (csr_is_conn_state_disconnected(pMac, i))
1223 continue;
1224
1225 pSession = CSR_GET_SESSION(pMac, i);
1226 if (pSession->pCurRoamProfile == NULL)
1227 continue;
1228
1229 persona = pSession->pCurRoamProfile->csrPersona;
1230 if (QDF_P2P_CLIENT_MODE == persona ||
1231 QDF_P2P_GO_MODE == persona)
1232 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233 }
1234
1235 return false;
1236}
1237
1238bool csr_is_any_session_connected(tpAniSirGlobal pMac)
1239{
1240 uint32_t i, count;
1241 bool fRc = false;
1242
1243 count = 0;
1244 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1245 if (CSR_IS_SESSION_VALID(pMac, i)
1246 && !csr_is_conn_state_disconnected(pMac, i))
1247 count++;
1248 }
1249
1250 if (count > 0)
1251 fRc = true;
1252 return fRc;
1253}
1254
1255bool csr_is_infra_connected(tpAniSirGlobal pMac)
1256{
1257 uint32_t i;
1258 bool fRc = false;
1259
1260 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1261 if (CSR_IS_SESSION_VALID(pMac, i)
1262 && csr_is_conn_state_connected_infra(pMac, i)) {
1263 fRc = true;
1264 break;
1265 }
1266 }
1267
1268 return fRc;
1269}
1270
Abhishek Singh1f217ec2017-12-22 11:48:27 +05301271uint8_t csr_get_connected_infra(tpAniSirGlobal mac_ctx)
1272{
1273 uint32_t i;
1274 uint8_t connected_session = CSR_SESSION_ID_INVALID;
1275
1276 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1277 if (CSR_IS_SESSION_VALID(mac_ctx, i)
1278 && csr_is_conn_state_connected_infra(mac_ctx, i)) {
1279 connected_session = i;
1280 break;
1281 }
1282 }
1283
1284 return connected_session;
1285}
1286
1287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288bool csr_is_concurrent_infra_connected(tpAniSirGlobal pMac)
1289{
1290 uint32_t i, noOfConnectedInfra = 0;
1291
1292 bool fRc = false;
1293
1294 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1295 if (CSR_IS_SESSION_VALID(pMac, i)
1296 && csr_is_conn_state_connected_infra(pMac, i)) {
1297 ++noOfConnectedInfra;
1298 }
1299 }
1300
1301 /* More than one Infra Sta Connected */
1302 if (noOfConnectedInfra > 1)
1303 fRc = true;
1304 return fRc;
1305}
1306
1307bool csr_is_ibss_started(tpAniSirGlobal pMac)
1308{
1309 uint32_t i;
1310 bool fRc = false;
1311
1312 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1313 if (CSR_IS_SESSION_VALID(pMac, i)
1314 && csr_is_conn_state_ibss(pMac, i)) {
1315 fRc = true;
1316 break;
1317 }
1318 }
1319
1320 return fRc;
1321}
1322
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323bool csr_is_concurrent_session_running(tpAniSirGlobal pMac)
1324{
1325 uint32_t sessionId, noOfCocurrentSession = 0;
1326 eCsrConnectState connectState;
1327
1328 bool fRc = false;
1329
1330 for (sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++) {
1331 if (CSR_IS_SESSION_VALID(pMac, sessionId)) {
1332 connectState =
1333 pMac->roam.roamSession[sessionId].connectState;
1334 if ((eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED ==
1335 connectState)
1336 || (eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED ==
1337 connectState)
1338 || (eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTED ==
1339 connectState)) {
1340 ++noOfCocurrentSession;
1341 }
1342 }
1343 }
1344
1345 /* More than one session is Up and Running */
1346 if (noOfCocurrentSession > 1)
1347 fRc = true;
1348 return fRc;
1349}
1350
1351bool csr_is_infra_ap_started(tpAniSirGlobal pMac)
1352{
1353 uint32_t sessionId;
1354 bool fRc = false;
1355
1356 for (sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++) {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301357 if (CSR_IS_SESSION_VALID(pMac, sessionId) &&
1358 (csr_is_conn_state_connected_infra_ap(pMac,
1359 sessionId))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 fRc = true;
1361 break;
1362 }
1363 }
1364
1365 return fRc;
1366
1367}
1368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001369bool csr_is_conn_state_disconnected(tpAniSirGlobal pMac, uint32_t sessionId)
1370{
1371 return eCSR_ASSOC_STATE_TYPE_NOT_CONNECTED ==
1372 pMac->roam.roamSession[sessionId].connectState;
1373}
1374
1375/**
1376 * csr_is_valid_mc_concurrent_session() - To check concurren session is valid
1377 * @mac_ctx: pointer to mac context
1378 * @session_id: session id
1379 * @bss_descr: bss description
1380 *
1381 * This function validates the concurrent session
1382 *
1383 * Return: true or false
1384 */
1385bool csr_is_valid_mc_concurrent_session(tpAniSirGlobal mac_ctx,
1386 uint32_t session_id,
1387 tSirBssDescription *bss_descr)
1388{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301389 struct csr_roam_session *pSession = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390
1391 /* Check for MCC support */
1392 if (!mac_ctx->roam.configParam.fenableMCCMode)
1393 return false;
1394 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id))
1395 return false;
1396 /* Validate BeaconInterval */
1397 pSession = CSR_GET_SESSION(mac_ctx, session_id);
1398 if (NULL == pSession->pCurRoamProfile)
1399 return false;
Krunal Sonicbda8552016-07-14 19:39:02 -07001400 if (QDF_STATUS_SUCCESS == csr_validate_mcc_beacon_interval(mac_ctx,
1401 bss_descr->channelId,
1402 &bss_descr->beaconInterval, session_id,
1403 pSession->pCurRoamProfile->csrPersona))
1404 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001405 return false;
1406}
1407
1408static tSirMacCapabilityInfo csr_get_bss_capabilities(tSirBssDescription *
1409 pSirBssDesc)
1410{
1411 tSirMacCapabilityInfo dot11Caps;
1412
1413 /* tSirMacCapabilityInfo is 16-bit */
Anurag Chouhanc5548422016-02-24 18:33:27 +05301414 qdf_get_u16((uint8_t *) &pSirBssDesc->capabilityInfo,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415 (uint16_t *) &dot11Caps);
1416
1417 return dot11Caps;
1418}
1419
1420bool csr_is_infra_bss_desc(tSirBssDescription *pSirBssDesc)
1421{
1422 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1423
1424 return (bool) dot11Caps.ess;
1425}
1426
1427bool csr_is_ibss_bss_desc(tSirBssDescription *pSirBssDesc)
1428{
1429 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1430
1431 return (bool) dot11Caps.ibss;
1432}
1433
Jeff Johnson054d0282016-10-07 10:35:54 -07001434static bool csr_is_qos_bss_desc(tSirBssDescription *pSirBssDesc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435{
1436 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1437
1438 return (bool) dot11Caps.qos;
1439}
1440
1441bool csr_is_privacy(tSirBssDescription *pSirBssDesc)
1442{
1443 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1444
1445 return (bool) dot11Caps.privacy;
1446}
1447
1448bool csr_is11d_supported(tpAniSirGlobal pMac)
1449{
1450 return pMac->roam.configParam.Is11dSupportEnabled;
1451}
1452
1453bool csr_is11h_supported(tpAniSirGlobal pMac)
1454{
1455 return pMac->roam.configParam.Is11hSupportEnabled;
1456}
1457
1458bool csr_is11e_supported(tpAniSirGlobal pMac)
1459{
1460 return pMac->roam.configParam.Is11eSupportEnabled;
1461}
1462
1463bool csr_is_mcc_supported(tpAniSirGlobal pMac)
1464{
1465 return pMac->roam.configParam.fenableMCCMode;
1466
1467}
1468
1469bool csr_is_wmm_supported(tpAniSirGlobal pMac)
1470{
1471 if (eCsrRoamWmmNoQos == pMac->roam.configParam.WMMSupportMode)
1472 return false;
1473 else
1474 return true;
1475}
1476
1477/* pIes is the IEs for pSirBssDesc2 */
Jeff Johnson515b3ec2018-06-03 20:11:05 -07001478bool csr_is_ssid_equal(tpAniSirGlobal pMac,
1479 tSirBssDescription *pSirBssDesc1,
1480 tSirBssDescription *pSirBssDesc2,
1481 tDot11fBeaconIEs *pIes2)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001482{
1483 bool fEqual = false;
1484 tSirMacSSid Ssid1, Ssid2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485 tDot11fBeaconIEs *pIes1 = NULL;
1486 tDot11fBeaconIEs *pIesLocal = pIes2;
1487
1488 do {
1489 if ((NULL == pSirBssDesc1) || (NULL == pSirBssDesc2))
1490 break;
1491 if (!pIesLocal
1492 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301493 !QDF_IS_STATUS_SUCCESS(csr_get_parsed_bss_description_ies
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001494 (pMac, pSirBssDesc2,
1495 &pIesLocal))) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001496 sme_err("fail to parse IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 break;
1498 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301499 if (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500 (csr_get_parsed_bss_description_ies(pMac,
1501 pSirBssDesc1, &pIes1))) {
1502 break;
1503 }
1504 if ((!pIes1->SSID.present) || (!pIesLocal->SSID.present))
1505 break;
1506 if (pIes1->SSID.num_ssid != pIesLocal->SSID.num_ssid)
1507 break;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301508 qdf_mem_copy(Ssid1.ssId, pIes1->SSID.ssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001509 pIes1->SSID.num_ssid);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301510 qdf_mem_copy(Ssid2.ssId, pIesLocal->SSID.ssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511 pIesLocal->SSID.num_ssid);
1512
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301513 fEqual = (!qdf_mem_cmp(Ssid1.ssId, Ssid2.ssId,
1514 pIesLocal->SSID.num_ssid));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515
1516 } while (0);
1517 if (pIes1)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301518 qdf_mem_free(pIes1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001519 if (pIesLocal && !pIes2)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301520 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521
1522 return fEqual;
1523}
1524
1525/* pIes can be passed in as NULL if the caller doesn't have one prepared */
Jeff Johnson3f9d9fb2018-06-09 23:53:16 -07001526static bool csr_is_bss_description_wme(tpAniSirGlobal pMac,
Jeff Johnson054d0282016-10-07 10:35:54 -07001527 tSirBssDescription *pSirBssDesc,
1528 tDot11fBeaconIEs *pIes)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 /* Assume that WME is found... */
1531 bool fWme = true;
1532 tDot11fBeaconIEs *pIesTemp = pIes;
1533
1534 do {
1535 if (pIesTemp == NULL) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301536 if (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001537 (csr_get_parsed_bss_description_ies
1538 (pMac, pSirBssDesc, &pIesTemp))) {
1539 fWme = false;
1540 break;
1541 }
1542 }
1543 /* if the Wme Info IE is found, then WME is supported... */
1544 if (CSR_IS_QOS_BSS(pIesTemp))
1545 break;
1546 /* if none of these are found, then WME is NOT supported... */
1547 fWme = false;
1548 } while (0);
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301549 if (!csr_is_wmm_supported(pMac) && fWme)
1550 if (!pIesTemp->HTCaps.present)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001551 fWme = false;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301552
1553 if ((pIes == NULL) && (NULL != pIesTemp))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554 /* we allocate memory here so free it before returning */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301555 qdf_mem_free(pIesTemp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556
1557 return fWme;
1558}
1559
Jeff Johnson12ec0102018-06-03 16:26:55 -07001560eCsrMediaAccessType csr_get_qos_from_bss_desc(tpAniSirGlobal mac_ctx,
1561 tSirBssDescription *pSirBssDesc,
1562 tDot11fBeaconIEs *pIes)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563{
1564 eCsrMediaAccessType qosType = eCSR_MEDIUM_ACCESS_DCF;
1565
1566 if (NULL == pIes) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301567 QDF_ASSERT(pIes != NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 return qosType;
1569 }
1570
1571 do {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301572 /* If we find WMM in the Bss Description, then we let this
1573 * override and use WMM.
1574 */
Jeff Johnson12ec0102018-06-03 16:26:55 -07001575 if (csr_is_bss_description_wme(mac_ctx, pSirBssDesc, pIes))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576 qosType = eCSR_MEDIUM_ACCESS_WMM_eDCF_DSCP;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301577 else {
1578 /* If the QoS bit is on, then the AP is
1579 * advertising 11E QoS.
1580 */
1581 if (csr_is_qos_bss_desc(pSirBssDesc))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582 qosType = eCSR_MEDIUM_ACCESS_11e_eDCF;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301583 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584 qosType = eCSR_MEDIUM_ACCESS_DCF;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301585
1586 /* Scale back based on the types turned on
1587 * for the adapter.
1588 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001589 if (eCSR_MEDIUM_ACCESS_11e_eDCF == qosType
Jeff Johnson12ec0102018-06-03 16:26:55 -07001590 && !csr_is11e_supported(mac_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001591 qosType = eCSR_MEDIUM_ACCESS_DCF;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001592 }
1593
1594 } while (0);
1595
1596 return qosType;
1597}
1598
1599/* Caller allocates memory for pIEStruct */
Jeff Johnson57d8ee82018-06-04 06:25:32 -07001600QDF_STATUS csr_parse_bss_description_ies(tpAniSirGlobal mac_ctx,
1601 tSirBssDescription *pBssDesc,
1602 tDot11fBeaconIEs *pIEStruct)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301604 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001605 int ieLen =
1606 (int)(pBssDesc->length + sizeof(pBssDesc->length) -
1607 GET_FIELD_OFFSET(tSirBssDescription, ieFields));
1608
1609 if (ieLen > 0 && pIEStruct) {
Abhishek Singh3f13a812018-01-16 14:24:44 +05301610 if (!DOT11F_FAILED(dot11f_unpack_beacon_i_es
Jeff Johnson57d8ee82018-06-04 06:25:32 -07001611 (mac_ctx, (uint8_t *) pBssDesc->ieFields,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301612 ieLen, pIEStruct, false)))
1613 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 }
1615
1616 return status;
1617}
1618
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301619/* This function will allocate memory for the parsed IEs to the caller.
1620 * Caller must free the memory after it is done with the data only if
1621 * this function succeeds
1622 */
Jeff Johnsond4c61de2018-06-04 06:33:39 -07001623QDF_STATUS csr_get_parsed_bss_description_ies(tpAniSirGlobal mac_ctx,
1624 tSirBssDescription *pBssDesc,
1625 tDot11fBeaconIEs **ppIEStruct)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001626{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301627 QDF_STATUS status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628
1629 if (pBssDesc && ppIEStruct) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301630 *ppIEStruct = qdf_mem_malloc(sizeof(tDot11fBeaconIEs));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 if ((*ppIEStruct) != NULL) {
Jeff Johnsond4c61de2018-06-04 06:33:39 -07001632 status = csr_parse_bss_description_ies(mac_ctx,
1633 pBssDesc,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634 *ppIEStruct);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301635 if (!QDF_IS_STATUS_SUCCESS(status)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301636 qdf_mem_free(*ppIEStruct);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 *ppIEStruct = NULL;
1638 }
1639 } else {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001640 sme_err("failed to allocate memory");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301641 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301642 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643 }
1644 }
1645
1646 return status;
1647}
1648
1649bool csr_is_nullssid(uint8_t *pBssSsid, uint8_t len)
1650{
1651 bool fNullSsid = false;
1652
1653 uint32_t SsidLength;
1654 uint8_t *pSsidStr;
1655
1656 do {
1657 if (0 == len) {
1658 fNullSsid = true;
1659 break;
1660 }
1661 /* Consider 0 or space for hidden SSID */
1662 if (0 == pBssSsid[0]) {
1663 fNullSsid = true;
1664 break;
1665 }
1666
1667 SsidLength = len;
1668 pSsidStr = pBssSsid;
1669
1670 while (SsidLength) {
1671 if (*pSsidStr)
1672 break;
1673
1674 pSsidStr++;
1675 SsidLength--;
1676 }
1677
1678 if (0 == SsidLength) {
1679 fNullSsid = true;
1680 break;
1681 }
1682 } while (0);
1683
1684 return fNullSsid;
1685}
1686
Jeff Johnsoncb2193a2018-06-03 17:06:41 -07001687uint32_t csr_get_frag_thresh(tpAniSirGlobal mac_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688{
Harprit Chhabadabec6de42018-09-10 10:21:15 -07001689 return mac_ctx->mlme_cfg->threshold.frag_threshold;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690}
1691
Jeff Johnson9fbc2332018-06-03 17:11:31 -07001692uint32_t csr_get_rts_thresh(tpAniSirGlobal mac_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693{
Harprit Chhabadabec6de42018-09-10 10:21:15 -07001694 return mac_ctx->mlme_cfg->threshold.rts_threshold;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695}
1696
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301697static eCsrPhyMode
1698csr_translate_to_phy_mode_from_bss_desc(tpAniSirGlobal mac_ctx,
1699 tSirBssDescription *pSirBssDesc,
1700 tDot11fBeaconIEs *ies)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701{
1702 eCsrPhyMode phyMode;
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301703 uint8_t i;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704
1705 switch (pSirBssDesc->nwType) {
1706 case eSIR_11A_NW_TYPE:
1707 phyMode = eCSR_DOT11_MODE_11a;
1708 break;
1709
1710 case eSIR_11B_NW_TYPE:
1711 phyMode = eCSR_DOT11_MODE_11b;
1712 break;
1713
1714 case eSIR_11G_NW_TYPE:
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301715 phyMode = eCSR_DOT11_MODE_11g_ONLY;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301717 /* Check if the BSS is in b/g mixed mode or g_only mode */
1718 if (!ies || !ies->SuppRates.present) {
1719 sme_debug("Unable to get rates, assume G only mode");
1720 break;
1721 }
1722
1723 for (i = 0; i < ies->SuppRates.num_rates; i++) {
1724 if (csr_rates_is_dot11_rate11b_supported_rate(
1725 ies->SuppRates.rates[i])) {
1726 sme_debug("One B rate is supported");
1727 phyMode = eCSR_DOT11_MODE_11g;
1728 break;
1729 }
1730 }
1731 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 case eSIR_11N_NW_TYPE:
1733 phyMode = eCSR_DOT11_MODE_11n;
1734 break;
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001735 case eSIR_11AX_NW_TYPE:
1736 phyMode = eCSR_DOT11_MODE_11ax;
1737 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 case eSIR_11AC_NW_TYPE:
1739 default:
1740 phyMode = eCSR_DOT11_MODE_11ac;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741 break;
1742 }
1743 return phyMode;
1744}
1745
1746uint32_t csr_translate_to_wni_cfg_dot11_mode(tpAniSirGlobal pMac,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301747 enum csr_cfgdot11mode csrDot11Mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001748{
1749 uint32_t ret;
1750
1751 switch (csrDot11Mode) {
1752 case eCSR_CFG_DOT11_MODE_AUTO:
Sandeep Puligilla1f1e4002018-08-18 12:15:01 -07001753 sme_debug("eCSR_CFG_DOT11_MODE_AUTO");
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001754 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
1755 ret = WNI_CFG_DOT11_MODE_11AX;
1756 else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 ret = WNI_CFG_DOT11_MODE_11AC;
1758 else
1759 ret = WNI_CFG_DOT11_MODE_11N;
1760 break;
1761 case eCSR_CFG_DOT11_MODE_11A:
1762 ret = WNI_CFG_DOT11_MODE_11A;
1763 break;
1764 case eCSR_CFG_DOT11_MODE_11B:
1765 ret = WNI_CFG_DOT11_MODE_11B;
1766 break;
1767 case eCSR_CFG_DOT11_MODE_11G:
1768 ret = WNI_CFG_DOT11_MODE_11G;
1769 break;
1770 case eCSR_CFG_DOT11_MODE_11N:
1771 ret = WNI_CFG_DOT11_MODE_11N;
1772 break;
1773 case eCSR_CFG_DOT11_MODE_11G_ONLY:
1774 ret = WNI_CFG_DOT11_MODE_11G_ONLY;
1775 break;
1776 case eCSR_CFG_DOT11_MODE_11N_ONLY:
1777 ret = WNI_CFG_DOT11_MODE_11N_ONLY;
1778 break;
1779 case eCSR_CFG_DOT11_MODE_11AC_ONLY:
1780 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
1781 ret = WNI_CFG_DOT11_MODE_11AC_ONLY;
1782 else
1783 ret = WNI_CFG_DOT11_MODE_11N;
1784 break;
1785 case eCSR_CFG_DOT11_MODE_11AC:
1786 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
1787 ret = WNI_CFG_DOT11_MODE_11AC;
1788 else
1789 ret = WNI_CFG_DOT11_MODE_11N;
1790 break;
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001791 case eCSR_CFG_DOT11_MODE_11AX_ONLY:
1792 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
1793 ret = WNI_CFG_DOT11_MODE_11AX_ONLY;
1794 else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
1795 ret = WNI_CFG_DOT11_MODE_11AC;
1796 else
1797 ret = WNI_CFG_DOT11_MODE_11N;
1798 break;
1799 case eCSR_CFG_DOT11_MODE_11AX:
1800 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
1801 ret = WNI_CFG_DOT11_MODE_11AX;
1802 else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
1803 ret = WNI_CFG_DOT11_MODE_11AC;
1804 else
1805 ret = WNI_CFG_DOT11_MODE_11N;
1806 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001807 default:
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07001808 sme_warn("doesn't expect %d as csrDo11Mode", csrDot11Mode);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301809 if (BAND_2G == pMac->mlme_cfg->gen.band)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001810 ret = WNI_CFG_DOT11_MODE_11G;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301811 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001812 ret = WNI_CFG_DOT11_MODE_11A;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001813 break;
1814 }
1815
1816 return ret;
1817}
1818
1819/**
1820 * csr_get_phy_mode_from_bss() - Get Phy Mode
1821 * @pMac: Global MAC context
1822 * @pBSSDescription: BSS Descriptor
1823 * @pPhyMode: Physical Mode
1824 * @pIes: Pointer to the IE fields
1825 *
1826 * This function should only return the super set of supported modes
1827 * 11n implies 11b/g/a/n.
1828 *
1829 * Return: success
1830 **/
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301831QDF_STATUS csr_get_phy_mode_from_bss(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001832 tSirBssDescription *pBSSDescription,
1833 eCsrPhyMode *pPhyMode, tDot11fBeaconIEs *pIes)
1834{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301835 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001836 eCsrPhyMode phyMode =
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301837 csr_translate_to_phy_mode_from_bss_desc(pMac, pBSSDescription,
1838 pIes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001839
1840 if (pIes) {
1841 if (pIes->HTCaps.present) {
1842 phyMode = eCSR_DOT11_MODE_11n;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843 if (IS_BSS_VHT_CAPABLE(pIes->VHTCaps) ||
Kapil Gupta4b2efbb2016-10-03 13:07:20 +05301844 IS_BSS_VHT_CAPABLE(pIes->vendor_vht_ie.VHTCaps))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845 phyMode = eCSR_DOT11_MODE_11ac;
Naveen Rawatd8feac12017-09-08 15:08:39 -07001846 if (pIes->he_cap.present)
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001847 phyMode = eCSR_DOT11_MODE_11ax;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848 }
1849 *pPhyMode = phyMode;
1850 }
1851
1852 return status;
1853}
1854
1855/**
1856 * csr_get_phy_mode_in_use() - to get phymode
1857 * @phyModeIn: physical mode
1858 * @bssPhyMode: physical mode in bss
1859 * @f5GhzBand: 5Ghz band
1860 * @pCfgDot11ModeToUse: dot11 mode in use
1861 *
1862 * This function returns the correct eCSR_CFG_DOT11_MODE is the two phyModes
1863 * matches. bssPhyMode is the mode derived from the BSS description
1864 * f5GhzBand is derived from the channel id of BSS description
1865 *
1866 * Return: true or false
1867 */
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301868static bool csr_get_phy_mode_in_use(tpAniSirGlobal mac_ctx,
1869 eCsrPhyMode phyModeIn,
Jeff Johnson054d0282016-10-07 10:35:54 -07001870 eCsrPhyMode bssPhyMode,
1871 bool f5GhzBand,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301872 enum csr_cfgdot11mode *pCfgDot11ModeToUse)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873{
1874 bool fMatch = false;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05301875 enum csr_cfgdot11mode cfgDot11Mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001876
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301877 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 switch (phyModeIn) {
1879 /* 11a or 11b or 11g */
1880 case eCSR_DOT11_MODE_abg:
1881 fMatch = true;
1882 if (f5GhzBand)
1883 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1884 else if (eCSR_DOT11_MODE_11b == bssPhyMode)
1885 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1886 else
1887 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1888 break;
1889
1890 case eCSR_DOT11_MODE_11a:
1891 if (f5GhzBand) {
1892 fMatch = true;
1893 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1894 }
1895 break;
1896
1897 case eCSR_DOT11_MODE_11g:
1898 if (!f5GhzBand) {
1899 fMatch = true;
1900 if (eCSR_DOT11_MODE_11b == bssPhyMode)
1901 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1902 else
1903 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1904 }
1905 break;
1906
1907 case eCSR_DOT11_MODE_11g_ONLY:
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301908 if ((bssPhyMode == eCSR_DOT11_MODE_11g) ||
1909 (bssPhyMode == eCSR_DOT11_MODE_11g_ONLY)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910 fMatch = true;
1911 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1912 }
1913 break;
1914
1915 case eCSR_DOT11_MODE_11b:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916 case eCSR_DOT11_MODE_11b_ONLY:
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301917 if (!f5GhzBand && (bssPhyMode != eCSR_DOT11_MODE_11g_ONLY)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001918 fMatch = true;
1919 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1920 }
1921 break;
1922
1923 case eCSR_DOT11_MODE_11n:
1924 fMatch = true;
1925 switch (bssPhyMode) {
1926 case eCSR_DOT11_MODE_11g:
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301927 case eCSR_DOT11_MODE_11g_ONLY:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001928 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1929 break;
1930 case eCSR_DOT11_MODE_11b:
1931 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1932 break;
1933 case eCSR_DOT11_MODE_11a:
1934 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1935 break;
1936 case eCSR_DOT11_MODE_11n:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001937 case eCSR_DOT11_MODE_11ac:
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001938 case eCSR_DOT11_MODE_11ax:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001939 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1940 break;
1941
1942 default:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001943 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001944 break;
1945 }
1946 break;
1947
1948 case eCSR_DOT11_MODE_11n_ONLY:
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301949 if (eCSR_DOT11_MODE_11n == bssPhyMode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 fMatch = true;
1951 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1952
1953 }
1954
1955 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001956 case eCSR_DOT11_MODE_11ac:
1957 fMatch = true;
1958 switch (bssPhyMode) {
1959 case eCSR_DOT11_MODE_11g:
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301960 case eCSR_DOT11_MODE_11g_ONLY:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001961 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1962 break;
1963 case eCSR_DOT11_MODE_11b:
1964 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1965 break;
1966 case eCSR_DOT11_MODE_11a:
1967 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1968 break;
1969 case eCSR_DOT11_MODE_11n:
1970 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1971 break;
1972 case eCSR_DOT11_MODE_11ac:
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001973 case eCSR_DOT11_MODE_11ax:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001974 default:
1975 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
1976 break;
1977 }
1978 break;
1979
1980 case eCSR_DOT11_MODE_11ac_ONLY:
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05301981 if (eCSR_DOT11_MODE_11ac == bssPhyMode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001982 fMatch = true;
1983 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
1984 }
1985 break;
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001986 case eCSR_DOT11_MODE_11ax:
1987 fMatch = true;
1988 switch (bssPhyMode) {
1989 case eCSR_DOT11_MODE_11g:
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05301990 case eCSR_DOT11_MODE_11g_ONLY:
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001991 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1992 break;
1993 case eCSR_DOT11_MODE_11b:
1994 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1995 break;
1996 case eCSR_DOT11_MODE_11a:
1997 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1998 break;
1999 case eCSR_DOT11_MODE_11n:
2000 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
2001 break;
2002 case eCSR_DOT11_MODE_11ac:
2003 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
2004 break;
2005 case eCSR_DOT11_MODE_11ax:
2006 default:
2007 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AX;
2008 break;
2009 }
2010 break;
2011
2012 case eCSR_DOT11_MODE_11ax_ONLY:
2013 if (eCSR_DOT11_MODE_11ax == bssPhyMode) {
2014 fMatch = true;
2015 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AX;
2016 }
2017 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018
2019 default:
2020 fMatch = true;
2021 switch (bssPhyMode) {
2022 case eCSR_DOT11_MODE_11g:
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05302023 case eCSR_DOT11_MODE_11g_ONLY:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
2025 break;
2026 case eCSR_DOT11_MODE_11b:
2027 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
2028 break;
2029 case eCSR_DOT11_MODE_11a:
2030 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
2031 break;
2032 case eCSR_DOT11_MODE_11n:
2033 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
2034 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002035 case eCSR_DOT11_MODE_11ac:
2036 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
2037 break;
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08002038 case eCSR_DOT11_MODE_11ax:
2039 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AX;
2040 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041 default:
2042 cfgDot11Mode = eCSR_CFG_DOT11_MODE_AUTO;
2043 break;
2044 }
2045 break;
2046 }
2047
2048 if (fMatch && pCfgDot11ModeToUse) {
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08002049 if (cfgDot11Mode == eCSR_CFG_DOT11_MODE_11AX) {
2050 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
2051 *pCfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11AX;
2052 else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
2053 *pCfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11AC;
2054 else
2055 *pCfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
2056 } else {
2057 if (cfgDot11Mode == eCSR_CFG_DOT11_MODE_11AC
2058 && (!IS_FEATURE_SUPPORTED_BY_FW(DOT11AC)))
2059 *pCfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
2060 else
2061 *pCfgDot11ModeToUse = cfgDot11Mode;
2062 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002063 }
2064 return fMatch;
2065}
2066
2067/**
2068 * csr_is_phy_mode_match() - to find if phy mode matches
2069 * @pMac: pointer to mac context
2070 * @phyMode: physical mode
2071 * @pSirBssDesc: bss description
2072 * @pProfile: pointer to roam profile
2073 * @pReturnCfgDot11Mode: dot1 mode to return
2074 * @pIes: pointer to IEs
2075 *
2076 * This function decides whether the one of the bit of phyMode is matching the
2077 * mode in the BSS and allowed by the user setting
2078 *
2079 * Return: true or false based on mode that fits the criteria
2080 */
2081bool csr_is_phy_mode_match(tpAniSirGlobal pMac, uint32_t phyMode,
2082 tSirBssDescription *pSirBssDesc,
Jeff Johnson66ee8a92018-03-17 15:24:26 -07002083 struct csr_roam_profile *pProfile,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302084 enum csr_cfgdot11mode *pReturnCfgDot11Mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002085 tDot11fBeaconIEs *pIes)
2086{
2087 bool fMatch = false;
2088 eCsrPhyMode phyModeInBssDesc = eCSR_DOT11_MODE_AUTO, phyMode2;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302089 enum csr_cfgdot11mode cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002090 uint32_t bitMask, loopCount;
2091
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302092 if (!QDF_IS_STATUS_SUCCESS(csr_get_phy_mode_from_bss(pMac, pSirBssDesc,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002093 &phyModeInBssDesc, pIes)))
2094 return fMatch;
2095
2096 if ((0 == phyMode) || (eCSR_DOT11_MODE_AUTO & phyMode)) {
2097 if (eCSR_CFG_DOT11_MODE_ABG ==
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08002098 pMac->roam.configParam.uCfgDot11Mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002099 phyMode = eCSR_DOT11_MODE_abg;
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08002100 } else if (eCSR_CFG_DOT11_MODE_AUTO ==
2101 pMac->roam.configParam.uCfgDot11Mode) {
2102 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
2103 phyMode = eCSR_DOT11_MODE_11ax;
2104 else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
2105 phyMode = eCSR_DOT11_MODE_11ac;
2106 else
2107 phyMode = eCSR_DOT11_MODE_11n;
2108 } else {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002109 /* user's pick */
2110 phyMode = pMac->roam.configParam.phyMode;
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08002111 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112 }
2113
2114 if ((0 == phyMode) || (eCSR_DOT11_MODE_AUTO & phyMode)) {
2115 if (0 != phyMode) {
2116 if (eCSR_DOT11_MODE_AUTO & phyMode) {
2117 phyMode2 =
2118 eCSR_DOT11_MODE_AUTO & phyMode;
2119 }
2120 } else {
2121 phyMode2 = phyMode;
2122 }
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05302123 fMatch = csr_get_phy_mode_in_use(pMac, phyMode2,
2124 phyModeInBssDesc,
2125 WLAN_REG_IS_5GHZ_CH(
2126 pSirBssDesc->channelId),
2127 &cfgDot11ModeToUse);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002128 } else {
2129 bitMask = 1;
2130 loopCount = 0;
2131 while (loopCount < eCSR_NUM_PHY_MODE) {
2132 phyMode2 = (phyMode & (bitMask << loopCount++));
Vignesh Viswanathanad265f22018-10-09 14:40:45 +05302133 if (0 != phyMode2 &&
2134 csr_get_phy_mode_in_use(pMac, phyMode2,
2135 phyModeInBssDesc,
2136 WLAN_REG_IS_5GHZ_CH(pSirBssDesc->channelId),
2137 &cfgDot11ModeToUse)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138 fMatch = true;
2139 break;
2140 }
2141 }
2142 }
2143 if (fMatch && pReturnCfgDot11Mode) {
2144 if (pProfile) {
2145 /*
2146 * IEEE 11n spec (8.4.3): HT STA shall
2147 * eliminate TKIP as a choice for the pairwise
2148 * cipher suite if CCMP is advertised by the AP
2149 * or if the AP included an HT capabilities
2150 * element in its Beacons and Probe Response.
2151 */
2152 if ((!CSR_IS_11n_ALLOWED(
2153 pProfile->negotiatedUCEncryptionType))
2154 && ((eCSR_CFG_DOT11_MODE_11N ==
2155 cfgDot11ModeToUse) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002156 (eCSR_CFG_DOT11_MODE_11AC ==
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08002157 cfgDot11ModeToUse) ||
2158 (eCSR_CFG_DOT11_MODE_11AX ==
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -08002159 cfgDot11ModeToUse))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002160 /* We cannot do 11n here */
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07002161 if (!WLAN_REG_IS_5GHZ_CH
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002162 (pSirBssDesc->channelId)) {
2163 cfgDot11ModeToUse =
2164 eCSR_CFG_DOT11_MODE_11G;
2165 } else {
2166 cfgDot11ModeToUse =
2167 eCSR_CFG_DOT11_MODE_11A;
2168 }
2169 }
2170 }
2171 *pReturnCfgDot11Mode = cfgDot11ModeToUse;
2172 }
2173
2174 return fMatch;
2175}
2176
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302177enum csr_cfgdot11mode csr_find_best_phy_mode(tpAniSirGlobal pMac,
2178 uint32_t phyMode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302180 enum csr_cfgdot11mode cfgDot11ModeToUse;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05302181 enum band_info eBand = pMac->mlme_cfg->gen.band;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002182
2183 if ((0 == phyMode) ||
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08002184 (eCSR_DOT11_MODE_AUTO & phyMode) ||
2185 (eCSR_DOT11_MODE_11ax & phyMode)) {
2186 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX)) {
2187 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11AX;
2188 } else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC)) {
2189 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11AC;
2190 } else {
2191 /* Default to 11N mode if user has configured 11ac mode
2192 * and FW doesn't supports 11ac mode .
2193 */
2194 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
2195 }
2196 } else if (eCSR_DOT11_MODE_11ac & phyMode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002197 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC)) {
2198 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11AC;
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -08002199 } else {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002200 /* Default to 11N mode if user has configured 11ac mode
2201 * and FW doesn't supports 11ac mode .
2202 */
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302203 } cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002204 } else {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302205 if ((eCSR_DOT11_MODE_11n | eCSR_DOT11_MODE_11n_ONLY) & phyMode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002206 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302207 else if (eCSR_DOT11_MODE_abg & phyMode) {
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08002208 if (BAND_2G != eBand)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002209 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11A;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302210 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002211 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11G;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302212 } else if (eCSR_DOT11_MODE_11a & phyMode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002213 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11A;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302214 else if ((eCSR_DOT11_MODE_11g | eCSR_DOT11_MODE_11g_ONLY) &
2215 phyMode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002216 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11G;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302217 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002218 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11B;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002219 }
2220
2221 return cfgDot11ModeToUse;
2222}
2223
Jeff Johnsonb7de91b2018-06-03 18:15:02 -07002224uint32_t csr_get11h_power_constraint(tpAniSirGlobal mac_ctx,
2225 tDot11fIEPowerConstraints *constraints)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002226{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002227 uint32_t localPowerConstraint = 0;
2228
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302229 /* check if .11h support is enabled, if not,
2230 * the power constraint is 0.
2231 */
Jeff Johnsonb7de91b2018-06-03 18:15:02 -07002232 if (mac_ctx->roam.configParam.Is11hSupportEnabled &&
2233 constraints->present) {
2234 localPowerConstraint = constraints->localPowerConstraints;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002235 }
2236
2237 return localPowerConstraint;
2238}
2239
Jeff Johnson66ee8a92018-03-17 15:24:26 -07002240bool csr_is_profile_wpa(struct csr_roam_profile *pProfile)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241{
2242 bool fWpaProfile = false;
2243
2244 switch (pProfile->negotiatedAuthType) {
2245 case eCSR_AUTH_TYPE_WPA:
2246 case eCSR_AUTH_TYPE_WPA_PSK:
2247 case eCSR_AUTH_TYPE_WPA_NONE:
2248#ifdef FEATURE_WLAN_ESE
2249 case eCSR_AUTH_TYPE_CCKM_WPA:
2250#endif
2251 fWpaProfile = true;
2252 break;
2253
2254 default:
2255 fWpaProfile = false;
2256 break;
2257 }
2258
2259 if (fWpaProfile) {
2260 switch (pProfile->negotiatedUCEncryptionType) {
2261 case eCSR_ENCRYPT_TYPE_WEP40:
2262 case eCSR_ENCRYPT_TYPE_WEP104:
2263 case eCSR_ENCRYPT_TYPE_TKIP:
2264 case eCSR_ENCRYPT_TYPE_AES:
2265 fWpaProfile = true;
2266 break;
2267
2268 default:
2269 fWpaProfile = false;
2270 break;
2271 }
2272 }
2273 return fWpaProfile;
2274}
2275
Jeff Johnson66ee8a92018-03-17 15:24:26 -07002276bool csr_is_profile_rsn(struct csr_roam_profile *pProfile)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002277{
2278 bool fRSNProfile = false;
2279
2280 switch (pProfile->negotiatedAuthType) {
2281 case eCSR_AUTH_TYPE_RSN:
2282 case eCSR_AUTH_TYPE_RSN_PSK:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002283 case eCSR_AUTH_TYPE_FT_RSN:
2284 case eCSR_AUTH_TYPE_FT_RSN_PSK:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002285#ifdef FEATURE_WLAN_ESE
2286 case eCSR_AUTH_TYPE_CCKM_RSN:
2287#endif
2288#ifdef WLAN_FEATURE_11W
2289 case eCSR_AUTH_TYPE_RSN_PSK_SHA256:
2290 case eCSR_AUTH_TYPE_RSN_8021X_SHA256:
2291#endif
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05302292 /* fallthrough */
2293 case eCSR_AUTH_TYPE_FILS_SHA256:
2294 case eCSR_AUTH_TYPE_FILS_SHA384:
2295 case eCSR_AUTH_TYPE_FT_FILS_SHA256:
2296 case eCSR_AUTH_TYPE_FT_FILS_SHA384:
Abhishek Singh02cb9e02017-08-30 17:39:50 +05302297 case eCSR_AUTH_TYPE_DPP_RSN:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002298 fRSNProfile = true;
2299 break;
2300
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05302301 case eCSR_AUTH_TYPE_OWE:
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05302302 case eCSR_AUTH_TYPE_SUITEB_EAP_SHA256:
2303 case eCSR_AUTH_TYPE_SUITEB_EAP_SHA384:
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05302304 fRSNProfile = true;
2305 break;
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05302306 case eCSR_AUTH_TYPE_SAE:
2307 fRSNProfile = true;
2308 break;
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05302309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 default:
2311 fRSNProfile = false;
2312 break;
2313 }
2314
2315 if (fRSNProfile) {
2316 switch (pProfile->negotiatedUCEncryptionType) {
2317 /* !!REVIEW - For WPA2, use of RSN IE mandates */
2318 /* use of AES as encryption. Here, we qualify */
2319 /* even if encryption type is WEP or TKIP */
2320 case eCSR_ENCRYPT_TYPE_WEP40:
2321 case eCSR_ENCRYPT_TYPE_WEP104:
2322 case eCSR_ENCRYPT_TYPE_TKIP:
2323 case eCSR_ENCRYPT_TYPE_AES:
Mukul Sharma05504ac2017-06-08 12:35:53 +05302324 case eCSR_ENCRYPT_TYPE_AES_GCMP:
2325 case eCSR_ENCRYPT_TYPE_AES_GCMP_256:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002326 fRSNProfile = true;
2327 break;
2328
2329 default:
2330 fRSNProfile = false;
2331 break;
2332 }
2333 }
2334 return fRSNProfile;
2335}
2336
2337/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002338 * csr_update_mcc_p2p_beacon_interval() - update p2p beacon interval
2339 * @mac_ctx: pointer to mac context
2340 *
2341 * This function is to update the mcc p2p beacon interval
2342 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302343 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002344 */
Jeff Johnson054d0282016-10-07 10:35:54 -07002345static QDF_STATUS csr_update_mcc_p2p_beacon_interval(tpAniSirGlobal mac_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002346{
2347 uint32_t session_id = 0;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302348 struct csr_roam_session *roam_session;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002349
2350 /* If MCC is not supported just break and return SUCCESS */
2351 if (!mac_ctx->roam.configParam.fenableMCCMode)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302352 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002353
2354 for (session_id = 0; session_id < CSR_ROAM_SESSION_MAX; session_id++) {
2355 /*
2356 * If GO in MCC support different beacon interval,
2357 * change the BI of the P2P-GO
2358 */
2359 roam_session = &mac_ctx->roam.roamSession[session_id];
Anurag Chouhan6d760662016-02-20 16:05:43 +05302360 if (roam_session->bssParams.bssPersona != QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002361 continue;
2362 /*
2363 * Handle different BI scneario based on the
2364 * configuration set.If Config is set to 0x02 then
2365 * Disconnect all the P2P clients associated. If config
2366 * is set to 0x04 then update the BI without
2367 * disconnecting all the clients
2368 */
2369 if ((mac_ctx->roam.configParam.fAllowMCCGODiffBI == 0x04)
2370 && (roam_session->bssParams.
2371 updatebeaconInterval)) {
2372 return csr_send_chng_mcc_beacon_interval(mac_ctx,
2373 session_id);
2374 } else if (roam_session->bssParams.updatebeaconInterval) {
2375 /*
2376 * If the configuration of fAllowMCCGODiffBI is set to
2377 * other than 0x04
2378 */
2379 return csr_roam_call_callback(mac_ctx,
2380 session_id,
2381 NULL, 0,
2382 eCSR_ROAM_DISCONNECT_ALL_P2P_CLIENTS,
2383 eCSR_ROAM_RESULT_NONE);
2384 }
2385 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302386 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002387}
2388
Jeff Johnson054d0282016-10-07 10:35:54 -07002389static uint16_t csr_calculate_mcc_beacon_interval(tpAniSirGlobal pMac,
2390 uint16_t sta_bi,
2391 uint16_t go_gbi)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002392{
2393 uint8_t num_beacons = 0;
2394 uint8_t is_multiple = 0;
2395 uint16_t go_cbi = 0;
2396 uint16_t go_fbi = 0;
2397 uint16_t sta_cbi = 0;
2398
2399 /* If GO's given beacon Interval is less than 100 */
2400 if (go_gbi < 100)
2401 go_cbi = 100;
2402 /* if GO's given beacon Interval is greater than or equal to 100 */
2403 else
2404 go_cbi = 100 + (go_gbi % 100);
2405
2406 if (sta_bi == 0) {
2407 /* There is possibility to receive zero as value.
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302408 * Which will cause divide by zero. Hence initialise with 100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002409 */
2410 sta_bi = 100;
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002411 sme_warn("sta_bi 2nd parameter is zero, initialize to %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412 sta_bi);
2413 }
2414 /* check, if either one is multiple of another */
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302415 if (sta_bi > go_cbi)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002416 is_multiple = !(sta_bi % go_cbi);
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302417 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002418 is_multiple = !(go_cbi % sta_bi);
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302419
2420 /* if it is multiple, then accept GO's beacon interval
2421 * range [100,199] as it is
2422 */
2423 if (is_multiple)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002424 return go_cbi;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302425
2426 /* else , if it is not multiple, then then check for number of beacons
2427 * to be inserted based on sta BI
2428 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429 num_beacons = sta_bi / 100;
2430 if (num_beacons) {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302431 /* GO's final beacon interval will be aligned to sta beacon
2432 * interval, but in the range of [100, 199].
2433 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002434 sta_cbi = sta_bi / num_beacons;
2435 go_fbi = sta_cbi;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302436 } else
2437 /* if STA beacon interval is less than 100, use GO's change
2438 * bacon interval instead of updating to STA's beacon interval.
2439 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002440 go_fbi = go_cbi;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302441
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442 return go_fbi;
2443}
2444
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002445/**
2446 * csr_validate_p2pcli_bcn_intrvl() - to validate p2pcli beacon interval
2447 * @mac_ctx: pointer to mac context
2448 * @chnl_id: channel id variable
2449 * @bcn_interval: pointer to given beacon interval
2450 * @session_id: given session id
2451 * @status: fill the status in terms of QDF_STATUS to inform caller
2452 *
2453 * This API can provide the validation the beacon interval and re-calculate
2454 * in case concurrency
2455 *
2456 * Return: bool
2457 */
2458static bool csr_validate_p2pcli_bcn_intrvl(tpAniSirGlobal mac_ctx,
2459 uint8_t chnl_id, uint16_t *bcn_interval, uint32_t session_id,
2460 QDF_STATUS *status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002461{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302462 struct csr_roam_session *roamsession;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002463
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002464 roamsession = &mac_ctx->roam.roamSession[session_id];
2465 if (roamsession->pCurRoamProfile &&
2466 (roamsession->pCurRoamProfile->csrPersona ==
2467 QDF_STA_MODE)) {
2468 /* check for P2P client mode */
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002469 sme_debug("Ignore Beacon Interval Validation...");
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002470 } else if (roamsession->bssParams.bssPersona == QDF_P2P_GO_MODE) {
2471 /* Check for P2P go scenario */
2472 if ((roamsession->bssParams.operationChn != chnl_id)
2473 && (roamsession->bssParams.beaconInterval !=
2474 *bcn_interval)) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002475 sme_err("BcnIntrvl is diff can't connect to P2P_GO network");
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002476 *status = QDF_STATUS_E_FAILURE;
2477 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002478 }
2479 }
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002480 return false;
2481}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002482
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002483/**
2484 * csr_validate_p2pgo_bcn_intrvl() - to validate p2pgo beacon interval
2485 * @mac_ctx: pointer to mac context
2486 * @chnl_id: channel id variable
2487 * @bcn_interval: pointer to given beacon interval
2488 * @session_id: given session id
2489 * @status: fill the status in terms of QDF_STATUS to inform caller
2490 *
2491 * This API can provide the validation the beacon interval and re-calculate
2492 * in case concurrency
2493 *
2494 * Return: bool
2495 */
2496static bool csr_validate_p2pgo_bcn_intrvl(tpAniSirGlobal mac_ctx,
2497 uint8_t chnl_id, uint16_t *bcn_interval,
2498 uint32_t session_id, QDF_STATUS *status)
2499{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302500 struct csr_roam_session *roamsession;
2501 struct csr_config *cfg_param;
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002502 tCsrRoamConnectedProfile *conn_profile;
2503 uint16_t new_bcn_interval;
2504
2505 roamsession = &mac_ctx->roam.roamSession[session_id];
2506 cfg_param = &mac_ctx->roam.configParam;
2507 conn_profile = &roamsession->connectedProfile;
2508 if (roamsession->pCurRoamProfile &&
2509 ((roamsession->pCurRoamProfile->csrPersona ==
2510 QDF_P2P_CLIENT_MODE) ||
2511 (roamsession->pCurRoamProfile->csrPersona ==
2512 QDF_STA_MODE))) {
2513 /* check for P2P_client scenario */
2514 if ((conn_profile->operationChannel == 0) &&
2515 (conn_profile->beaconInterval == 0))
2516 return false;
2517
2518 if (csr_is_conn_state_connected_infra(mac_ctx, session_id) &&
2519 (conn_profile->operationChannel != chnl_id) &&
2520 (conn_profile->beaconInterval != *bcn_interval)) {
2521 /*
2522 * Updated beaconInterval should be used only when
2523 * we are starting a new BSS not incase of
2524 * client or STA case
2525 */
2526
2527 /* Calculate beacon Interval for P2P-GO incase of MCC */
2528 if (cfg_param->conc_custom_rule1 ||
2529 cfg_param->conc_custom_rule2) {
2530 new_bcn_interval = CSR_CUSTOM_CONC_GO_BI;
2531 } else {
2532 new_bcn_interval =
2533 csr_calculate_mcc_beacon_interval(
2534 mac_ctx,
2535 conn_profile->beaconInterval,
2536 *bcn_interval);
2537 }
2538 if (*bcn_interval != new_bcn_interval)
2539 *bcn_interval = new_bcn_interval;
2540 *status = QDF_STATUS_SUCCESS;
2541 return true;
2542 }
2543 }
2544 return false;
2545}
2546
2547/**
2548 * csr_validate_sta_bcn_intrvl() - to validate sta beacon interval
2549 * @mac_ctx: pointer to mac context
2550 * @chnl_id: channel id variable
2551 * @bcn_interval: pointer to given beacon interval
2552 * @session_id: given session id
2553 * @status: fill the status in terms of QDF_STATUS to inform caller
2554 *
2555 * This API can provide the validation the beacon interval and re-calculate
2556 * in case concurrency
2557 *
2558 * Return: bool
2559 */
2560static bool csr_validate_sta_bcn_intrvl(tpAniSirGlobal mac_ctx,
2561 uint8_t chnl_id, uint16_t *bcn_interval,
2562 uint32_t session_id, QDF_STATUS *status)
2563{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05302564 struct csr_roam_session *roamsession;
2565 struct csr_config *cfg_param;
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002566 uint16_t new_bcn_interval;
2567
2568 roamsession = &mac_ctx->roam.roamSession[session_id];
2569 cfg_param = &mac_ctx->roam.configParam;
2570
2571 if (roamsession->pCurRoamProfile &&
2572 (roamsession->pCurRoamProfile->csrPersona ==
2573 QDF_P2P_CLIENT_MODE)) {
2574 /* check for P2P client mode */
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002575 sme_debug("Bcn Intrvl validation not require for STA/CLIENT");
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002576 return false;
2577 }
2578 if ((roamsession->bssParams.bssPersona == QDF_SAP_MODE) &&
2579 (roamsession->bssParams.operationChn != chnl_id)) {
2580 /*
2581 * IF SAP has started and STA wants to connect
2582 * on different channel MCC should
2583 * MCC should not be enabled so making it
2584 * false to enforce on same channel
2585 */
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002586 sme_err("*** MCC with SAP+STA sessions ****");
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002587 *status = QDF_STATUS_SUCCESS;
2588 return true;
2589 }
2590 /*
2591 * Check for P2P go scenario
2592 * if GO in MCC support different
2593 * beacon interval,
2594 * change the BI of the P2P-GO
2595 */
2596 if ((roamsession->bssParams.bssPersona == QDF_P2P_GO_MODE) &&
2597 (roamsession->bssParams.operationChn != chnl_id) &&
2598 (roamsession->bssParams.beaconInterval != *bcn_interval)) {
2599 /* if GO in MCC support diff beacon interval, return success */
2600 if (cfg_param->fAllowMCCGODiffBI == 0x01) {
2601 *status = QDF_STATUS_SUCCESS;
2602 return true;
2603 }
2604 /*
2605 * Send only Broadcast disassoc and update bcn_interval
2606 * If configuration is set to 0x04 then dont
2607 * disconnect all the station
2608 */
2609 if ((cfg_param->fAllowMCCGODiffBI == 0x02)
2610 || (cfg_param->fAllowMCCGODiffBI == 0x04)) {
2611 /* Check to pass the right beacon Interval */
2612 if (cfg_param->conc_custom_rule1 ||
2613 cfg_param->conc_custom_rule2) {
2614 new_bcn_interval = CSR_CUSTOM_CONC_GO_BI;
2615 } else {
2616 new_bcn_interval =
2617 csr_calculate_mcc_beacon_interval(
2618 mac_ctx, *bcn_interval,
2619 roamsession->bssParams.beaconInterval);
2620 }
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002621 sme_debug("Peer AP BI : %d, new Beacon Interval: %d",
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002622 *bcn_interval, new_bcn_interval);
2623 /* Update the becon Interval */
2624 if (new_bcn_interval !=
2625 roamsession->bssParams.beaconInterval) {
2626 /* Update the bcn_interval now */
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002627 sme_err("Beacon Interval got changed config used: %d",
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002628 cfg_param->fAllowMCCGODiffBI);
2629
2630 roamsession->bssParams.beaconInterval =
2631 new_bcn_interval;
2632 roamsession->bssParams.updatebeaconInterval =
2633 true;
2634 *status = csr_update_mcc_p2p_beacon_interval(
2635 mac_ctx);
2636 return true;
2637 }
2638 *status = QDF_STATUS_SUCCESS;
2639 return true;
2640 }
2641 if (cfg_param->fAllowMCCGODiffBI
2642 == 0x03) {
2643 /* Disconnect the P2P session */
2644 roamsession->bssParams.updatebeaconInterval = false;
2645 *status = csr_roam_call_callback(mac_ctx,
2646 session_id, NULL, 0,
2647 eCSR_ROAM_SEND_P2P_STOP_BSS,
2648 eCSR_ROAM_RESULT_NONE);
2649 return true;
2650 }
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002651 sme_err("BcnIntrvl is diff can't connect to preferred AP");
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002652 *status = QDF_STATUS_E_FAILURE;
2653 return true;
2654 }
2655 return false;
2656}
2657
2658/**
2659 * csr_validate_mcc_beacon_interval() - to validate the mcc beacon interval
2660 * @mac_ctx: pointer to mac context
2661 * @chnl_id: channel number
2662 * @bcn_interval: provided beacon interval
2663 * @cur_session_id: current session id
2664 * @cur_bss_persona: Current BSS persona
2665 *
2666 * This API will validate the mcc beacon interval
2667 *
2668 * Return: QDF_STATUS
2669 */
2670QDF_STATUS csr_validate_mcc_beacon_interval(tpAniSirGlobal mac_ctx,
2671 uint8_t chnl_id,
2672 uint16_t *bcn_interval,
2673 uint32_t cur_session_id,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002674 enum QDF_OPMODE cur_bss_persona)
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002675{
2676 uint32_t session_id = 0;
2677 QDF_STATUS status;
2678 bool is_done;
2679
2680 /* If MCC is not supported just break */
2681 if (!mac_ctx->roam.configParam.fenableMCCMode)
2682 return QDF_STATUS_E_FAILURE;
2683
2684 for (session_id = 0; session_id < CSR_ROAM_SESSION_MAX; session_id++) {
2685 if (cur_session_id == session_id)
2686 continue;
2687
2688 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id))
2689 continue;
2690
2691 switch (cur_bss_persona) {
2692 case QDF_STA_MODE:
2693 is_done = csr_validate_sta_bcn_intrvl(mac_ctx, chnl_id,
2694 bcn_interval, session_id, &status);
2695 if (true == is_done)
2696 return status;
2697 break;
2698
2699 case QDF_P2P_CLIENT_MODE:
2700 is_done = csr_validate_p2pcli_bcn_intrvl(mac_ctx,
2701 chnl_id, bcn_interval, session_id,
2702 &status);
2703 if (true == is_done)
2704 return status;
2705 break;
2706
2707 case QDF_SAP_MODE:
2708 case QDF_IBSS_MODE:
2709 break;
2710
2711 case QDF_P2P_GO_MODE:
2712 is_done = csr_validate_p2pgo_bcn_intrvl(mac_ctx,
2713 chnl_id, bcn_interval,
2714 session_id, &status);
2715 if (true == is_done)
2716 return status;
2717 break;
2718
2719 default:
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07002720 sme_err("Persona not supported: %d", cur_bss_persona);
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002721 return QDF_STATUS_E_FAILURE;
2722 }
2723 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302724 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002725}
2726
Deepak Dhamdhereadd334b2016-01-09 23:40:33 -08002727/**
2728 * csr_is_auth_type11r() - Check if Authentication type is 11R
Abhinav Kumar271f0632018-03-29 16:01:30 +05302729 * @mac: pointer to mac context
Deepak Dhamdhereadd334b2016-01-09 23:40:33 -08002730 * @auth_type: The authentication type that is used to make the connection
2731 * @mdie_present: Is MDIE IE present
2732 *
2733 * Return: true if is 11R auth type, false otherwise
2734 */
Abhinav Kumar271f0632018-03-29 16:01:30 +05302735bool csr_is_auth_type11r(tpAniSirGlobal mac, eCsrAuthType auth_type,
2736 uint8_t mdie_present)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002737{
Deepak Dhamdhereadd334b2016-01-09 23:40:33 -08002738 switch (auth_type) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002739 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
Abhinav Kumar271f0632018-03-29 16:01:30 +05302740 if (mdie_present &&
2741 mac->roam.configParam.enable_ftopen)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002742 return true;
Naveen Rawat23be88d2017-04-18 17:34:43 -07002743 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 case eCSR_AUTH_TYPE_FT_RSN_PSK:
2745 case eCSR_AUTH_TYPE_FT_RSN:
2746 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747 default:
2748 break;
2749 }
2750 return false;
2751}
2752
2753/* Function to return true if the profile is 11r */
Abhinav Kumar271f0632018-03-29 16:01:30 +05302754bool csr_is_profile11r(tpAniSirGlobal mac,
2755 struct csr_roam_profile *pProfile)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756{
Abhinav Kumar271f0632018-03-29 16:01:30 +05302757 return csr_is_auth_type11r(mac, pProfile->negotiatedAuthType,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002758 pProfile->MDID.mdiePresent);
2759}
2760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761bool csr_is_auth_type_ese(eCsrAuthType AuthType)
2762{
2763 switch (AuthType) {
2764 case eCSR_AUTH_TYPE_CCKM_WPA:
2765 case eCSR_AUTH_TYPE_CCKM_RSN:
2766 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002767 default:
2768 break;
2769 }
2770 return false;
2771}
2772
Padma, Santhosh Kumar2d1f77c2017-11-22 16:20:28 +05302773#ifdef FEATURE_WLAN_ESE
2774
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002775/* Function to return true if the profile is ESE */
Jeff Johnson66ee8a92018-03-17 15:24:26 -07002776bool csr_is_profile_ese(struct csr_roam_profile *pProfile)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002777{
2778 return csr_is_auth_type_ese(pProfile->negotiatedAuthType);
2779}
2780
2781#endif
2782
2783#ifdef FEATURE_WLAN_WAPI
Jeff Johnson66ee8a92018-03-17 15:24:26 -07002784bool csr_is_profile_wapi(struct csr_roam_profile *pProfile)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785{
2786 bool fWapiProfile = false;
2787
2788 switch (pProfile->negotiatedAuthType) {
2789 case eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
2790 case eCSR_AUTH_TYPE_WAPI_WAI_PSK:
2791 fWapiProfile = true;
2792 break;
2793
2794 default:
2795 fWapiProfile = false;
2796 break;
2797 }
2798
2799 if (fWapiProfile) {
2800 switch (pProfile->negotiatedUCEncryptionType) {
2801 case eCSR_ENCRYPT_TYPE_WPI:
2802 fWapiProfile = true;
2803 break;
2804
2805 default:
2806 fWapiProfile = false;
2807 break;
2808 }
2809 }
2810 return fWapiProfile;
2811}
2812
2813static bool csr_is_wapi_oui_equal(tpAniSirGlobal pMac, uint8_t *Oui1,
2814 uint8_t *Oui2)
2815{
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302816 return !qdf_mem_cmp(Oui1, Oui2, CSR_WAPI_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002817}
2818
2819static bool csr_is_wapi_oui_match(tpAniSirGlobal pMac,
2820 uint8_t AllCyphers[][CSR_WAPI_OUI_SIZE],
2821 uint8_t cAllCyphers, uint8_t Cypher[],
2822 uint8_t Oui[])
2823{
2824 bool fYes = false;
2825 uint8_t idx;
2826
2827 for (idx = 0; idx < cAllCyphers; idx++) {
2828 if (csr_is_wapi_oui_equal(pMac, AllCyphers[idx], Cypher)) {
2829 fYes = true;
2830 break;
2831 }
2832 }
2833
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302834 if (fYes && Oui)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302835 qdf_mem_copy(Oui, AllCyphers[idx], CSR_WAPI_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002836
2837 return fYes;
2838}
2839#endif /* FEATURE_WLAN_WAPI */
2840
2841static bool csr_is_wpa_oui_equal(tpAniSirGlobal pMac, uint8_t *Oui1,
2842 uint8_t *Oui2)
2843{
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302844 return !qdf_mem_cmp(Oui1, Oui2, CSR_WPA_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845}
2846
2847static bool csr_is_oui_match(tpAniSirGlobal pMac,
2848 uint8_t AllCyphers[][CSR_WPA_OUI_SIZE],
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302849 uint8_t cAllCyphers, uint8_t Cypher[], uint8_t Oui[])
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002850{
2851 bool fYes = false;
2852 uint8_t idx;
2853
2854 for (idx = 0; idx < cAllCyphers; idx++) {
2855 if (csr_is_wpa_oui_equal(pMac, AllCyphers[idx], Cypher)) {
2856 fYes = true;
2857 break;
2858 }
2859 }
2860
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05302861 if (fYes && Oui)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302862 qdf_mem_copy(Oui, AllCyphers[idx], CSR_WPA_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002863
2864 return fYes;
2865}
2866
2867static bool csr_match_rsnoui_index(tpAniSirGlobal pMac,
2868 uint8_t AllCyphers[][CSR_RSN_OUI_SIZE],
2869 uint8_t cAllCyphers, uint8_t ouiIndex,
2870 uint8_t Oui[])
2871{
2872 return csr_is_oui_match
2873 (pMac, AllCyphers, cAllCyphers, csr_rsn_oui[ouiIndex], Oui);
2874
2875}
2876
2877#ifdef FEATURE_WLAN_WAPI
2878static bool csr_match_wapi_oui_index(tpAniSirGlobal pMac,
2879 uint8_t AllCyphers[][CSR_WAPI_OUI_SIZE],
2880 uint8_t cAllCyphers, uint8_t ouiIndex,
2881 uint8_t Oui[])
2882{
2883 return csr_is_wapi_oui_match
2884 (pMac, AllCyphers, cAllCyphers, csr_wapi_oui[ouiIndex], Oui);
2885
2886}
2887#endif /* FEATURE_WLAN_WAPI */
2888
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07002889#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002890static bool csr_match_wpaoui_index(tpAniSirGlobal pMac,
2891 uint8_t AllCyphers[][CSR_RSN_OUI_SIZE],
2892 uint8_t cAllCyphers, uint8_t ouiIndex,
2893 uint8_t Oui[])
2894{
Padma, Santhosh Kumar5f428922017-07-24 12:48:00 +05302895 if (ouiIndex < QDF_ARRAY_SIZE(csr_wpa_oui))
2896 return csr_is_oui_match
2897 (pMac, AllCyphers, cAllCyphers,
2898 csr_wpa_oui[ouiIndex], Oui);
2899 else
2900 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002901}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07002902#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903
2904#ifdef FEATURE_WLAN_WAPI
2905static bool csr_is_auth_wapi_cert(tpAniSirGlobal pMac,
2906 uint8_t AllSuites[][CSR_WAPI_OUI_SIZE],
2907 uint8_t cAllSuites, uint8_t Oui[])
2908{
2909 return csr_is_wapi_oui_match
2910 (pMac, AllSuites, cAllSuites, csr_wapi_oui[1], Oui);
2911}
2912
2913static bool csr_is_auth_wapi_psk(tpAniSirGlobal pMac,
2914 uint8_t AllSuites[][CSR_WAPI_OUI_SIZE],
2915 uint8_t cAllSuites, uint8_t Oui[])
2916{
2917 return csr_is_wapi_oui_match
2918 (pMac, AllSuites, cAllSuites, csr_wapi_oui[2], Oui);
2919}
2920#endif /* FEATURE_WLAN_WAPI */
2921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922
2923/*
2924 * Function for 11R FT Authentication. We match the FT Authentication Cipher
2925 * suite here. This matches for FT Auth with the 802.1X exchange.
2926 */
2927static bool csr_is_ft_auth_rsn(tpAniSirGlobal pMac,
2928 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2929 uint8_t cAllSuites, uint8_t Oui[])
2930{
2931 return csr_is_oui_match
2932 (pMac, AllSuites, cAllSuites, csr_rsn_oui[03], Oui);
2933}
2934
2935/*
2936 * Function for 11R FT Authentication. We match the FT Authentication Cipher
2937 * suite here. This matches for FT Auth with the PSK.
2938 */
2939static bool csr_is_ft_auth_rsn_psk(tpAniSirGlobal pMac,
2940 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2941 uint8_t cAllSuites, uint8_t Oui[])
2942{
2943 return csr_is_oui_match
2944 (pMac, AllSuites, cAllSuites, csr_rsn_oui[04], Oui);
2945}
2946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947
2948#ifdef FEATURE_WLAN_ESE
2949
2950/*
2951 * Function for ESE CCKM AKM Authentication. We match the CCKM AKM
2952 * Authentication Key Management suite here. This matches for CCKM AKM Auth
2953 * with the 802.1X exchange.
2954 */
2955static bool csr_is_ese_cckm_auth_rsn(tpAniSirGlobal pMac,
2956 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2957 uint8_t cAllSuites, uint8_t Oui[])
2958{
2959 return csr_is_oui_match
2960 (pMac, AllSuites, cAllSuites, csr_rsn_oui[06], Oui);
2961}
2962
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07002963#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002964static bool csr_is_ese_cckm_auth_wpa(tpAniSirGlobal pMac,
2965 uint8_t AllSuites[][CSR_WPA_OUI_SIZE],
2966 uint8_t cAllSuites, uint8_t Oui[])
2967{
2968 return csr_is_oui_match
2969 (pMac, AllSuites, cAllSuites, csr_wpa_oui[06], Oui);
2970}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07002971#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002972
2973#endif
2974
2975static bool csr_is_auth_rsn(tpAniSirGlobal pMac,
2976 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2977 uint8_t cAllSuites, uint8_t Oui[])
2978{
2979 return csr_is_oui_match
2980 (pMac, AllSuites, cAllSuites, csr_rsn_oui[01], Oui);
2981}
2982
2983static bool csr_is_auth_rsn_psk(tpAniSirGlobal pMac,
2984 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2985 uint8_t cAllSuites, uint8_t Oui[])
2986{
2987 return csr_is_oui_match
2988 (pMac, AllSuites, cAllSuites, csr_rsn_oui[02], Oui);
2989}
2990
2991#ifdef WLAN_FEATURE_11W
2992static bool csr_is_auth_rsn_psk_sha256(tpAniSirGlobal pMac,
2993 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2994 uint8_t cAllSuites, uint8_t Oui[])
2995{
2996 return csr_is_oui_match
2997 (pMac, AllSuites, cAllSuites, csr_rsn_oui[07], Oui);
2998}
2999static bool csr_is_auth_rsn8021x_sha256(tpAniSirGlobal pMac,
3000 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
3001 uint8_t cAllSuites, uint8_t Oui[])
3002{
3003 return csr_is_oui_match
3004 (pMac, AllSuites, cAllSuites, csr_rsn_oui[8], Oui);
3005}
3006#endif
3007
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05303008#ifdef WLAN_FEATURE_FILS_SK
3009/*
3010 * csr_is_auth_fils_sha256() - check whether oui is fils sha256
3011 * @mac: Global MAC context
3012 * @all_suites: pointer to all supported akm suites
3013 * @suite_count: all supported akm suites count
3014 * @oui: Oui needs to be matched
3015 *
3016 * Return: True if OUI is FILS SHA256, false otherwise
3017 */
3018static bool csr_is_auth_fils_sha256(tpAniSirGlobal mac,
3019 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3020 uint8_t suite_count, uint8_t oui[])
3021{
3022 return csr_is_oui_match(mac, all_suites, suite_count,
3023 csr_rsn_oui[ENUM_FILS_SHA256], oui);
3024}
3025
3026/*
3027 * csr_is_auth_fils_sha384() - check whether oui is fils sha384
3028 * @mac: Global MAC context
3029 * @all_suites: pointer to all supported akm suites
3030 * @suite_count: all supported akm suites count
3031 * @oui: Oui needs to be matched
3032 *
3033 * Return: True if OUI is FILS SHA384, false otherwise
3034 */
3035static bool csr_is_auth_fils_sha384(tpAniSirGlobal mac,
3036 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3037 uint8_t suite_count, uint8_t oui[])
3038{
3039 return csr_is_oui_match(mac, all_suites, suite_count,
3040 csr_rsn_oui[ENUM_FILS_SHA384], oui);
3041}
3042
3043/*
3044 * csr_is_auth_fils_ft_sha256() - check whether oui is fils ft sha256
3045 * @mac: Global MAC context
3046 * @all_suites: pointer to all supported akm suites
3047 * @suite_count: all supported akm suites count
3048 * @oui: Oui needs to be matched
3049 *
3050 * Return: True if OUI is FT FILS SHA256, false otherwise
3051 */
3052static bool csr_is_auth_fils_ft_sha256(tpAniSirGlobal mac,
3053 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3054 uint8_t suite_count, uint8_t oui[])
3055{
3056 return csr_is_oui_match(mac, all_suites, suite_count,
3057 csr_rsn_oui[ENUM_FT_FILS_SHA256], oui);
3058}
3059
3060/*
3061 * csr_is_auth_fils_ft_sha384() - check whether oui is fils ft sha384
3062 * @mac: Global MAC context
3063 * @all_suites: pointer to all supported akm suites
3064 * @suite_count: all supported akm suites count
3065 * @oui: Oui needs to be matched
3066 *
3067 * Return: True if OUI is FT FILS SHA384, false otherwise
3068 */
3069static bool csr_is_auth_fils_ft_sha384(tpAniSirGlobal mac,
3070 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3071 uint8_t suite_count, uint8_t oui[])
3072{
3073 return csr_is_oui_match(mac, all_suites, suite_count,
3074 csr_rsn_oui[ENUM_FT_FILS_SHA384], oui);
3075}
3076#endif
3077
Abhishek Singh02cb9e02017-08-30 17:39:50 +05303078/*
3079 * csr_is_auth_dpp_rsn() - check whether oui is dpp rsn
3080 * @mac: Global MAC context
3081 * @all_suites: pointer to all supported akm suites
3082 * @suite_count: all supported akm suites count
3083 * @oui: Oui needs to be matched
3084 *
3085 * Return: True if OUI is dpp rsn, false otherwise
3086 */
3087static bool csr_is_auth_dpp_rsn(tpAniSirGlobal mac,
3088 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3089 uint8_t suite_count, uint8_t oui[])
3090{
3091 return csr_is_oui_match(mac, all_suites, suite_count,
3092 csr_rsn_oui[ENUM_DPP_RSN], oui);
3093}
3094
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05303095/*
3096 * csr_is_auth_wpa_owe() - check whether oui is OWE
3097 * @mac: Global MAC context
3098 * @all_suites: pointer to all supported akm suites
3099 * @suite_count: all supported akm suites count
3100 * @oui: Oui needs to be matched
3101 *
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303102 * Return: True if OUI is OWE, false otherwise
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05303103 */
3104static bool csr_is_auth_wpa_owe(tpAniSirGlobal mac,
3105 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3106 uint8_t suite_count, uint8_t oui[])
3107{
3108 return csr_is_oui_match
3109 (mac, all_suites, suite_count, csr_rsn_oui[ENUM_OWE], oui);
3110}
3111
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05303112/*
3113 * csr_is_auth_suiteb_eap_256() - check whether oui is SuiteB EAP256
3114 * @mac: Global MAC context
3115 * @all_suites: pointer to all supported akm suites
3116 * @suite_count: all supported akm suites count
3117 * @oui: Oui needs to be matched
3118 *
3119 * Return: True if OUI is SuiteB EAP256, false otherwise
3120 */
3121static bool csr_is_auth_suiteb_eap_256(tpAniSirGlobal mac,
3122 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3123 uint8_t suite_count, uint8_t oui[])
3124{
3125 return csr_is_oui_match(mac, all_suites, suite_count,
3126 csr_rsn_oui[ENUM_SUITEB_EAP256], oui);
3127}
3128
3129/*
3130 * csr_is_auth_suiteb_eap_384() - check whether oui is SuiteB EAP384
3131 * @mac: Global MAC context
3132 * @all_suites: pointer to all supported akm suites
3133 * @suite_count: all supported akm suites count
3134 * @oui: Oui needs to be matched
3135 *
3136 * Return: True if OUI is SuiteB EAP384, false otherwise
3137 */
3138static bool csr_is_auth_suiteb_eap_384(tpAniSirGlobal mac,
3139 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3140 uint8_t suite_count, uint8_t oui[])
3141{
3142 return csr_is_oui_match(mac, all_suites, suite_count,
3143 csr_rsn_oui[ENUM_SUITEB_EAP384], oui);
3144}
3145
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05303146#ifdef WLAN_FEATURE_SAE
3147/*
3148 * csr_is_auth_wpa_sae() - check whether oui is SAE
3149 * @mac: Global MAC context
3150 * @all_suites: pointer to all supported akm suites
3151 * @suite_count: all supported akm suites count
3152 * @oui: Oui needs to be matched
3153 *
3154 * Return: True if OUI is SAE, false otherwise
3155 */
3156static bool csr_is_auth_wpa_sae(tpAniSirGlobal mac,
3157 uint8_t all_suites[][CSR_RSN_OUI_SIZE],
3158 uint8_t suite_count, uint8_t oui[])
3159{
3160 return csr_is_oui_match
3161 (mac, all_suites, suite_count, csr_rsn_oui[ENUM_SAE], oui);
3162}
3163#endif
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05303164
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003165#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166static bool csr_is_auth_wpa(tpAniSirGlobal pMac,
3167 uint8_t AllSuites[][CSR_WPA_OUI_SIZE],
3168 uint8_t cAllSuites, uint8_t Oui[])
3169{
3170 return csr_is_oui_match
3171 (pMac, AllSuites, cAllSuites, csr_wpa_oui[01], Oui);
3172}
3173
3174static bool csr_is_auth_wpa_psk(tpAniSirGlobal pMac,
3175 uint8_t AllSuites[][CSR_WPA_OUI_SIZE],
3176 uint8_t cAllSuites, uint8_t Oui[])
3177{
3178 return csr_is_oui_match
3179 (pMac, AllSuites, cAllSuites, csr_wpa_oui[02], Oui);
3180}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003181#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303183/*
3184 * csr_is_group_mgmt_gmac_128() - check whether oui is GMAC_128
3185 * @mac: Global MAC context
3186 * @all_suites: pointer to all supported akm suites
3187 * @suite_count: all supported akm suites count
3188 * @oui: Oui needs to be matched
3189 *
3190 * Return: True if OUI is GMAC_128, false otherwise
3191 */
3192static bool csr_is_group_mgmt_gmac_128(tpAniSirGlobal pMac,
3193 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
3194 uint8_t cAllSuites, uint8_t Oui[])
3195{
3196 return csr_is_oui_match(pMac, AllSuites, cAllSuites,
3197 csr_group_mgmt_oui[ENUM_GMAC_128], Oui);
3198}
3199
3200/*
3201 * csr_is_group_mgmt_gmac_256() - check whether oui is GMAC_256
3202 * @mac: Global MAC context
3203 * @all_suites: pointer to all supported akm suites
3204 * @suite_count: all supported akm suites count
3205 * @oui: Oui needs to be matched
3206 *
3207 * Return: True if OUI is GMAC_256, false otherwise
3208 */
3209static bool csr_is_group_mgmt_gmac_256(tpAniSirGlobal pMac,
3210 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
3211 uint8_t cAllSuites, uint8_t Oui[])
3212{
3213 return csr_is_oui_match(pMac, AllSuites, cAllSuites,
3214 csr_group_mgmt_oui[ENUM_GMAC_256], Oui);
3215}
3216
Jeff Johnson054d0282016-10-07 10:35:54 -07003217static uint8_t csr_get_oui_index_from_cipher(eCsrEncryptionType enType)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003218{
3219 uint8_t OUIIndex;
3220
3221 switch (enType) {
3222 case eCSR_ENCRYPT_TYPE_WEP40:
3223 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3224 OUIIndex = CSR_OUI_WEP40_OR_1X_INDEX;
3225 break;
3226 case eCSR_ENCRYPT_TYPE_WEP104:
3227 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3228 OUIIndex = CSR_OUI_WEP104_INDEX;
3229 break;
3230 case eCSR_ENCRYPT_TYPE_TKIP:
3231 OUIIndex = CSR_OUI_TKIP_OR_PSK_INDEX;
3232 break;
3233 case eCSR_ENCRYPT_TYPE_AES:
3234 OUIIndex = CSR_OUI_AES_INDEX;
3235 break;
Mukul Sharma05504ac2017-06-08 12:35:53 +05303236 case eCSR_ENCRYPT_TYPE_AES_GCMP:
3237 OUIIndex = CSR_OUI_AES_GCMP_INDEX;
3238 break;
3239 case eCSR_ENCRYPT_TYPE_AES_GCMP_256:
3240 OUIIndex = CSR_OUI_AES_GCMP_256_INDEX;
3241 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003242 case eCSR_ENCRYPT_TYPE_NONE:
3243 OUIIndex = CSR_OUI_USE_GROUP_CIPHER_INDEX;
3244 break;
3245#ifdef FEATURE_WLAN_WAPI
3246 case eCSR_ENCRYPT_TYPE_WPI:
3247 OUIIndex = CSR_OUI_WAPI_WAI_CERT_OR_SMS4_INDEX;
3248 break;
3249#endif /* FEATURE_WLAN_WAPI */
3250 default: /* HOWTO handle this? */
3251 OUIIndex = CSR_OUI_RESERVED_INDEX;
3252 break;
3253 } /* switch */
3254
3255 return OUIIndex;
3256}
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05303257
3258#ifdef WLAN_FEATURE_FILS_SK
3259/**
3260 * csr_is_fils_auth() - update negotiated auth if matches to FILS auth type
3261 * @mac_ctx: pointer to mac context
3262 * @authsuites: auth suites
3263 * @c_auth_suites: auth suites count
3264 * @authentication: authentication
3265 * @auth_type: authentication type list
3266 * @index: current counter
3267 * @neg_authtype: pointer to negotiated auth
3268 *
3269 * Return: None
3270 */
3271static void csr_is_fils_auth(tpAniSirGlobal mac_ctx,
3272 uint8_t authsuites[][CSR_RSN_OUI_SIZE], uint8_t c_auth_suites,
3273 uint8_t authentication[], tCsrAuthList *auth_type,
3274 uint8_t index, eCsrAuthType *neg_authtype)
3275{
3276 /*
3277 * TODO Always try with highest security
3278 * move this down once sha384 is validated
3279 */
3280 if (csr_is_auth_fils_sha256(mac_ctx, authsuites,
3281 c_auth_suites, authentication)) {
3282 if (eCSR_AUTH_TYPE_FILS_SHA256 ==
3283 auth_type->authType[index])
3284 *neg_authtype = eCSR_AUTH_TYPE_FILS_SHA256;
3285 }
3286 if ((*neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3287 csr_is_auth_fils_sha384(mac_ctx, authsuites,
3288 c_auth_suites, authentication)) {
3289 if (eCSR_AUTH_TYPE_FILS_SHA384 ==
3290 auth_type->authType[index])
3291 *neg_authtype = eCSR_AUTH_TYPE_FILS_SHA384;
3292 }
3293 if ((*neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3294 csr_is_auth_fils_ft_sha256(mac_ctx, authsuites,
3295 c_auth_suites, authentication)) {
3296 if (eCSR_AUTH_TYPE_FT_FILS_SHA256 ==
3297 auth_type->authType[index])
3298 *neg_authtype = eCSR_AUTH_TYPE_FT_FILS_SHA256;
3299 }
3300 if ((*neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3301 csr_is_auth_fils_ft_sha384(mac_ctx, authsuites,
3302 c_auth_suites, authentication)) {
3303 if (eCSR_AUTH_TYPE_FT_FILS_SHA384 ==
3304 auth_type->authType[index])
3305 *neg_authtype = eCSR_AUTH_TYPE_FT_FILS_SHA384;
3306 }
3307 sme_debug("negotiated auth type is %d", *neg_authtype);
3308}
3309#else
3310static void csr_is_fils_auth(tpAniSirGlobal mac_ctx,
3311 uint8_t authsuites[][CSR_RSN_OUI_SIZE], uint8_t c_auth_suites,
3312 uint8_t authentication[], tCsrAuthList *auth_type,
3313 uint8_t index, eCsrAuthType *neg_authtype)
3314{
3315}
3316#endif
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05303317
3318#ifdef WLAN_FEATURE_SAE
3319/**
3320 * csr_check_sae_auth() - update negotiated auth if matches to SAE auth type
3321 * @mac_ctx: pointer to mac context
3322 * @authsuites: auth suites
3323 * @c_auth_suites: auth suites count
3324 * @authentication: authentication
3325 * @auth_type: authentication type list
3326 * @index: current counter
3327 * @neg_authtype: pointer to negotiated auth
3328 *
3329 * Return: None
3330 */
3331static void csr_check_sae_auth(tpAniSirGlobal mac_ctx,
3332 uint8_t authsuites[][CSR_RSN_OUI_SIZE], uint8_t c_auth_suites,
3333 uint8_t authentication[], tCsrAuthList *auth_type,
3334 uint8_t index, eCsrAuthType *neg_authtype)
3335{
3336 if ((*neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3337 csr_is_auth_wpa_sae(mac_ctx, authsuites,
3338 c_auth_suites, authentication)) {
3339 if (eCSR_AUTH_TYPE_SAE == auth_type->authType[index])
3340 *neg_authtype = eCSR_AUTH_TYPE_SAE;
3341 }
3342 sme_debug("negotiated auth type is %d", *neg_authtype);
3343}
3344#else
3345static void csr_check_sae_auth(tpAniSirGlobal mac_ctx,
3346 uint8_t authsuites[][CSR_RSN_OUI_SIZE], uint8_t c_auth_suites,
3347 uint8_t authentication[], tCsrAuthList *auth_type,
3348 uint8_t index, eCsrAuthType *neg_authtype)
3349{
3350}
3351#endif
3352
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353/**
Jeff Johnson698eacd2018-05-12 17:00:03 -07003354 * csr_get_rsn_information() - to get RSN information
Jeff Johnson353650e2018-06-10 16:29:42 -07003355 * @mac_ctx: pointer to global MAC context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356 * @auth_type: auth type
3357 * @encr_type: encryption type
3358 * @mc_encryption: multicast encryption type
3359 * @rsn_ie: pointer to RSN IE
3360 * @ucast_cipher: Unicast cipher
3361 * @mcast_cipher: Multicast cipher
3362 * @auth_suite: Authentication suite
3363 * @capabilities: RSN capabilities
3364 * @negotiated_authtype: Negotiated auth type
3365 * @negotiated_mccipher: negotiated multicast cipher
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303366 * @gp_mgmt_cipher: group management cipher
3367 * @mgmt_encryption_type: group management encryption type
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368 *
3369 * This routine will get all RSN information
3370 *
3371 * Return: bool
3372 */
Jeff Johnson353650e2018-06-10 16:29:42 -07003373static bool csr_get_rsn_information(tpAniSirGlobal mac_ctx,
3374 tCsrAuthList *auth_type,
Jeff Johnson054d0282016-10-07 10:35:54 -07003375 eCsrEncryptionType encr_type,
3376 tCsrEncryptionList *mc_encryption,
3377 tDot11fIERSN *rsn_ie, uint8_t *ucast_cipher,
3378 uint8_t *mcast_cipher, uint8_t *auth_suite,
gaurank kathpaliac63859d2018-05-03 18:48:41 +05303379 struct rsn_caps *capabilities,
Jeff Johnson054d0282016-10-07 10:35:54 -07003380 eCsrAuthType *negotiated_authtype,
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303381 eCsrEncryptionType *negotiated_mccipher,
3382 uint8_t *gp_mgmt_cipher,
3383 tAniEdType *mgmt_encryption_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 bool acceptable_cipher = false;
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303386 bool group_mgmt_acceptable_cipher = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387 uint8_t c_ucast_cipher = 0;
3388 uint8_t c_mcast_cipher = 0;
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303389 uint8_t c_group_mgmt_cipher = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003390 uint8_t c_auth_suites = 0, i;
3391 uint8_t unicast[CSR_RSN_OUI_SIZE];
3392 uint8_t multicast[CSR_RSN_OUI_SIZE];
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303393 uint8_t group_mgmt[CSR_RSN_OUI_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394 uint8_t authsuites[CSR_RSN_MAX_AUTH_SUITES][CSR_RSN_OUI_SIZE];
3395 uint8_t authentication[CSR_RSN_OUI_SIZE];
3396 uint8_t mccipher_arr[CSR_RSN_MAX_MULTICAST_CYPHERS][CSR_RSN_OUI_SIZE];
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303397 uint8_t group_mgmt_arr[CSR_RSN_MAX_MULTICAST_CYPHERS][CSR_RSN_OUI_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003398 eCsrAuthType neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
3399
3400 if (!rsn_ie->present)
3401 goto end;
3402 c_mcast_cipher++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303403 qdf_mem_copy(mccipher_arr, rsn_ie->gp_cipher_suite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 CSR_RSN_OUI_SIZE);
3405 c_ucast_cipher =
3406 (uint8_t) (rsn_ie->pwise_cipher_suite_count);
Abhishek Singh7dcb85b2017-12-27 15:15:01 +05303407
Abhishek Singh3f13a812018-01-16 14:24:44 +05303408 c_auth_suites = (uint8_t) (rsn_ie->akm_suite_cnt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 for (i = 0; i < c_auth_suites && i < CSR_RSN_MAX_AUTH_SUITES; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303410 qdf_mem_copy((void *)&authsuites[i],
Abhishek Singh3f13a812018-01-16 14:24:44 +05303411 (void *)&rsn_ie->akm_suite[i], CSR_RSN_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 }
3413
3414 /* Check - Is requested unicast Cipher supported by the BSS. */
3415 acceptable_cipher = csr_match_rsnoui_index(mac_ctx,
3416 rsn_ie->pwise_cipher_suites, c_ucast_cipher,
3417 csr_get_oui_index_from_cipher(encr_type),
3418 unicast);
3419
3420 if (!acceptable_cipher)
3421 goto end;
3422
3423 /* unicast is supported. Pick the first matching Group cipher, if any */
3424 for (i = 0; i < mc_encryption->numEntries; i++) {
3425 acceptable_cipher = csr_match_rsnoui_index(mac_ctx,
3426 mccipher_arr, c_mcast_cipher,
3427 csr_get_oui_index_from_cipher(
3428 mc_encryption->encryptionType[i]),
3429 multicast);
3430 if (acceptable_cipher)
3431 break;
3432 }
3433 if (!acceptable_cipher)
3434 goto end;
3435
3436 if (negotiated_mccipher)
3437 *negotiated_mccipher = mc_encryption->encryptionType[i];
3438
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303439 /* Group Management Cipher only for 11w */
3440 if (mgmt_encryption_type) {
3441 c_group_mgmt_cipher++;
3442 qdf_mem_copy(group_mgmt_arr, rsn_ie->gp_mgmt_cipher_suite,
3443 CSR_RSN_OUI_SIZE);
3444 if (csr_is_group_mgmt_gmac_128(mac_ctx, group_mgmt_arr,
3445 c_group_mgmt_cipher, group_mgmt)) {
3446 group_mgmt_acceptable_cipher = true;
3447 *mgmt_encryption_type = eSIR_ED_AES_GMAC_128;
3448 } else if (csr_is_group_mgmt_gmac_256(mac_ctx, group_mgmt_arr,
3449 c_group_mgmt_cipher, group_mgmt)) {
3450 group_mgmt_acceptable_cipher = true;
3451 *mgmt_encryption_type = eSIR_ED_AES_GMAC_256;
3452 } else {
3453 /* Default is CMAC */
3454 group_mgmt_acceptable_cipher = true;
3455 *mgmt_encryption_type = eSIR_ED_AES_128_CMAC;
3456 qdf_mem_copy(group_mgmt, csr_group_mgmt_oui[ENUM_CMAC],
3457 CSR_RSN_OUI_SIZE);
3458 }
3459 }
3460
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461 /* Initializing with false as it has true value already */
3462 acceptable_cipher = false;
3463 for (i = 0; i < auth_type->numEntries; i++) {
3464 /*
3465 * Ciphers are supported, Match authentication algorithm and
3466 * pick first matching authtype.
3467 */
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05303468 /* Set FILS as first preference */
3469 csr_is_fils_auth(mac_ctx, authsuites, c_auth_suites,
3470 authentication, auth_type, i, &neg_authtype);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 /* Changed the AKM suites according to order of preference */
Padma, Santhosh Kumar07eb80b2017-07-05 16:10:06 +05303472 csr_check_sae_auth(mac_ctx, authsuites, c_auth_suites,
3473 authentication, auth_type, i, &neg_authtype);
3474
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05303475 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
Abhishek Singh02cb9e02017-08-30 17:39:50 +05303476 csr_is_auth_dpp_rsn(mac_ctx, authsuites,
3477 c_auth_suites, authentication)) {
3478 if (eCSR_AUTH_TYPE_DPP_RSN == auth_type->authType[i])
3479 neg_authtype = eCSR_AUTH_TYPE_DPP_RSN;
3480 }
3481 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
Sridhar Selvaraj6cf642f2017-08-21 14:28:10 +05303482 csr_is_ft_auth_rsn(mac_ctx, authsuites,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 c_auth_suites, authentication)) {
3484 if (eCSR_AUTH_TYPE_FT_RSN == auth_type->authType[i])
3485 neg_authtype = eCSR_AUTH_TYPE_FT_RSN;
3486 }
3487 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
3488 && csr_is_ft_auth_rsn_psk(mac_ctx, authsuites,
3489 c_auth_suites, authentication)) {
3490 if (eCSR_AUTH_TYPE_FT_RSN_PSK ==
3491 auth_type->authType[i])
3492 neg_authtype = eCSR_AUTH_TYPE_FT_RSN_PSK;
3493 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494#ifdef FEATURE_WLAN_ESE
3495 /* ESE only supports 802.1X. No PSK. */
3496 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3497 csr_is_ese_cckm_auth_rsn(mac_ctx, authsuites,
3498 c_auth_suites, authentication)) {
3499 if (eCSR_AUTH_TYPE_CCKM_RSN == auth_type->authType[i])
3500 neg_authtype = eCSR_AUTH_TYPE_CCKM_RSN;
3501 }
3502#endif
3503 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
3504 && csr_is_auth_rsn(mac_ctx, authsuites,
3505 c_auth_suites, authentication)) {
3506 if (eCSR_AUTH_TYPE_RSN == auth_type->authType[i])
3507 neg_authtype = eCSR_AUTH_TYPE_RSN;
3508 }
3509 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
3510 && csr_is_auth_rsn_psk(mac_ctx, authsuites,
3511 c_auth_suites, authentication)) {
3512 if (eCSR_AUTH_TYPE_RSN_PSK == auth_type->authType[i])
3513 neg_authtype = eCSR_AUTH_TYPE_RSN_PSK;
3514 }
3515#ifdef WLAN_FEATURE_11W
3516 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
3517 && csr_is_auth_rsn_psk_sha256(mac_ctx, authsuites,
3518 c_auth_suites, authentication)) {
3519 if (eCSR_AUTH_TYPE_RSN_PSK_SHA256 ==
3520 auth_type->authType[i])
3521 neg_authtype = eCSR_AUTH_TYPE_RSN_PSK_SHA256;
3522 }
3523 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3524 csr_is_auth_rsn8021x_sha256(mac_ctx, authsuites,
3525 c_auth_suites, authentication)) {
3526 if (eCSR_AUTH_TYPE_RSN_8021X_SHA256 ==
3527 auth_type->authType[i])
3528 neg_authtype = eCSR_AUTH_TYPE_RSN_8021X_SHA256;
3529 }
3530#endif
Padma, Santhosh Kumarc69ce072017-11-06 18:21:05 +05303531 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3532 csr_is_auth_wpa_owe(mac_ctx, authsuites,
3533 c_auth_suites, authentication)) {
3534 if (eCSR_AUTH_TYPE_OWE == auth_type->authType[i])
3535 neg_authtype = eCSR_AUTH_TYPE_OWE;
3536 }
Padma, Santhosh Kumare587a5c2017-12-21 12:44:46 +05303537 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3538 csr_is_auth_suiteb_eap_256(mac_ctx, authsuites,
3539 c_auth_suites, authentication)) {
3540 if (eCSR_AUTH_TYPE_SUITEB_EAP_SHA256 ==
3541 auth_type->authType[i])
3542 neg_authtype = eCSR_AUTH_TYPE_SUITEB_EAP_SHA256;
3543 }
3544 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3545 csr_is_auth_suiteb_eap_384(mac_ctx, authsuites,
3546 c_auth_suites, authentication)) {
3547 if (eCSR_AUTH_TYPE_SUITEB_EAP_SHA384 ==
3548 auth_type->authType[i])
3549 neg_authtype = eCSR_AUTH_TYPE_SUITEB_EAP_SHA384;
3550 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551
3552 /*
3553 * The 1st auth type in the APs RSN IE, to match stations
3554 * connecting profiles auth type will cause us to exit this
3555 * loop. This is added as some APs advertise multiple akms in
3556 * the RSN IE
3557 */
3558 if (eCSR_AUTH_TYPE_UNKNOWN != neg_authtype) {
3559 acceptable_cipher = true;
3560 break;
3561 }
3562 } /* for */
3563end:
3564 if (acceptable_cipher) {
3565 if (mcast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303566 qdf_mem_copy(mcast_cipher, multicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003567 CSR_RSN_OUI_SIZE);
3568
3569 if (ucast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303570 qdf_mem_copy(ucast_cipher, unicast, CSR_RSN_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003571
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303572 if (gp_mgmt_cipher && group_mgmt_acceptable_cipher)
3573 qdf_mem_copy(gp_mgmt_cipher, group_mgmt,
3574 CSR_RSN_OUI_SIZE);
3575
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 if (auth_suite)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303577 qdf_mem_copy(auth_suite, authentication,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 CSR_RSN_OUI_SIZE);
3579
3580 if (negotiated_authtype)
3581 *negotiated_authtype = neg_authtype;
3582
3583 if (capabilities) {
3584 /* Bit 0 Preauthentication */
3585 capabilities->PreAuthSupported =
3586 (rsn_ie->RSN_Cap[0] >> 0) & 0x1;
3587 /* Bit 1 No Pairwise */
3588 capabilities->NoPairwise =
3589 (rsn_ie->RSN_Cap[0] >> 1) & 0x1;
3590 /* Bit 2, 3 PTKSA Replay Counter */
3591 capabilities->PTKSAReplayCounter =
3592 (rsn_ie->RSN_Cap[0] >> 2) & 0x3;
3593 /* Bit 4, 5 GTKSA Replay Counter */
3594 capabilities->GTKSAReplayCounter =
3595 (rsn_ie->RSN_Cap[0] >> 4) & 0x3;
3596#ifdef WLAN_FEATURE_11W
3597 /* Bit 6 MFPR */
3598 capabilities->MFPRequired =
3599 (rsn_ie->RSN_Cap[0] >> 6) & 0x1;
3600 /* Bit 7 MFPC */
3601 capabilities->MFPCapable =
3602 (rsn_ie->RSN_Cap[0] >> 7) & 0x1;
3603#else
3604 /* Bit 6 MFPR */
3605 capabilities->MFPRequired = 0;
3606 /* Bit 7 MFPC */
3607 capabilities->MFPCapable = 0;
3608#endif
3609 /* remaining reserved */
3610 capabilities->Reserved = rsn_ie->RSN_Cap[1] & 0xff;
3611 }
3612 }
3613 return acceptable_cipher;
3614}
3615
3616#ifdef WLAN_FEATURE_11W
3617/**
3618 * csr_is_pmf_capabilities_in_rsn_match() - check for PMF capability
Jeff Johnson13386da2018-06-09 23:55:41 -07003619 * @mac: Global MAC Context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 * @pFilterMFPEnabled: given by supplicant to us to specify what kind
3621 * of connection supplicant is expecting to make
3622 * if it is enabled then make PMF connection.
3623 * if it is disabled then make normal connection.
3624 * @pFilterMFPRequired: given by supplicant based on our configuration
3625 * if it is 1 then we will require mandatory
3626 * PMF connection and if it is 0 then we PMF
3627 * connection is optional.
3628 * @pFilterMFPCapable: given by supplicant based on our configuration
3629 * if it 1 then we are PMF capable and if it 0
3630 * then we are not PMF capable.
3631 * @pRSNIe: RSNIe from Beacon/probe response of
3632 * neighbor AP against which we will compare
3633 * our capabilities.
3634 *
3635 * This function is to match our current capabilities with the AP
3636 * to which we are expecting make the connection.
3637 *
3638 * Return: if our PMF capabilities matches with AP then we
3639 * will return true to indicate that we are good
3640 * to make connection with it. Else we will return false
3641 **/
3642static bool
Jeff Johnson13386da2018-06-09 23:55:41 -07003643csr_is_pmf_capabilities_in_rsn_match(tpAniSirGlobal mac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 bool *pFilterMFPEnabled,
3645 uint8_t *pFilterMFPRequired,
3646 uint8_t *pFilterMFPCapable,
3647 tDot11fIERSN *pRSNIe)
3648{
3649 uint8_t apProfileMFPCapable = 0;
3650 uint8_t apProfileMFPRequired = 0;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05303651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 if (pRSNIe && pFilterMFPEnabled && pFilterMFPCapable
3653 && pFilterMFPRequired) {
3654 /* Extracting MFPCapable bit from RSN Ie */
Srinivas Girigowda6519b932017-08-03 14:10:57 -07003655 apProfileMFPCapable = csr_is_mfpc_capable(pRSNIe);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 apProfileMFPRequired = (pRSNIe->RSN_Cap[0] >> 6) & 0x1;
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05303657
Srinivas Girigowda2db365c2017-03-10 14:03:55 -08003658 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05303659 "pFilterMFPEnabled: %d pFilterMFPRequired: %d pFilterMFPCapable: %d apProfileMFPCapable: %d apProfileMFPRequired: %d",
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05303660 *pFilterMFPEnabled, *pFilterMFPRequired,
3661 *pFilterMFPCapable, apProfileMFPCapable,
3662 apProfileMFPRequired);
3663
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664 if (*pFilterMFPEnabled && *pFilterMFPCapable
3665 && *pFilterMFPRequired && (apProfileMFPCapable == 0)) {
Srinivas Girigowda2db365c2017-03-10 14:03:55 -08003666 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 "AP is not capable to make PMF connection");
3668 return false;
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05303669 } else if (!(*pFilterMFPCapable) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 apProfileMFPCapable && apProfileMFPRequired) {
3671
3672 /*
3673 * In this case, AP with whom we trying to connect
3674 * requires mandatory PMF connections and we are not
3675 * capable so this AP is not good choice to connect
3676 */
Srinivas Girigowda2db365c2017-03-10 14:03:55 -08003677 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678 "AP needs PMF connection and we are not capable of pmf connection");
3679 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 }
3681 }
3682 return true;
3683}
3684#endif
3685
Jeff Johnson44d0c092018-06-10 16:02:47 -07003686static bool csr_is_rsn_match(tpAniSirGlobal mac_ctx, tCsrAuthList *pAuthType,
Jeff Johnson054d0282016-10-07 10:35:54 -07003687 eCsrEncryptionType enType,
3688 tCsrEncryptionList *pEnMcType,
3689 bool *pMFPEnabled, uint8_t *pMFPRequired,
3690 uint8_t *pMFPCapable,
3691 tDot11fBeaconIEs *pIes,
3692 eCsrAuthType *pNegotiatedAuthType,
3693 eCsrEncryptionType *pNegotiatedMCCipher)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694{
3695 bool fRSNMatch = false;
3696
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05303697 /* See if the cyphers in the Bss description match with the
3698 * settings in the profile.
3699 */
Jeff Johnson44d0c092018-06-10 16:02:47 -07003700 fRSNMatch = csr_get_rsn_information(mac_ctx, pAuthType, enType,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05303701 pEnMcType, &pIes->RSN,
3702 NULL, NULL, NULL, NULL,
3703 pNegotiatedAuthType,
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303704 pNegotiatedMCCipher, NULL, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003705#ifdef WLAN_FEATURE_11W
3706 /* If all the filter matches then finally checks for PMF capabilities */
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05303707 if (fRSNMatch)
Jeff Johnson44d0c092018-06-10 16:02:47 -07003708 fRSNMatch = csr_is_pmf_capabilities_in_rsn_match(mac_ctx,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05303709 pMFPEnabled,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710 pMFPRequired,
3711 pMFPCapable,
3712 &pIes->RSN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003713#endif
3714 return fRSNMatch;
3715}
3716
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003717#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303718/**
3719 * csr_lookup_pmkid_using_ssid() - lookup pmkid using ssid and cache_id
3720 * @mac: pointer to mac
3721 * @session: sme session pointer
3722 * @pmk_cache: pointer to pmk cache
3723 * @index: index value needs to be seached
3724 *
3725 * Return: true if pmkid is found else false
3726 */
3727static bool csr_lookup_pmkid_using_ssid(tpAniSirGlobal mac,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05303728 struct csr_roam_session *session,
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303729 tPmkidCacheInfo *pmk_cache,
3730 uint32_t *index)
3731{
3732 uint32_t i;
3733 tPmkidCacheInfo *session_pmk;
3734
3735 for (i = 0; i < session->NumPmkidCache; i++) {
3736 session_pmk = &session->PmkidCacheInfo[i];
3737 sme_debug("match PMKID ssid %*.*s cache id %x %x ssid_len %d to ssid %s cache_id %x %x",
3738 pmk_cache->ssid_len, pmk_cache->ssid_len,
3739 pmk_cache->ssid, pmk_cache->cache_id[0],
3740 pmk_cache->cache_id[1], pmk_cache->ssid_len,
3741 session_pmk->ssid,
3742 session_pmk->cache_id[0], session_pmk->cache_id[1]);
3743
3744 if ((!qdf_mem_cmp(pmk_cache->ssid, session_pmk->ssid,
3745 pmk_cache->ssid_len)) &&
3746 (!qdf_mem_cmp(session_pmk->cache_id,
3747 pmk_cache->cache_id, CACHE_ID_LEN))) {
3748 /* match found */
3749 *index = i;
3750 sme_debug("PMKID found at index %d", i);
3751 return true;
3752 }
3753 }
3754
3755 return false;
3756}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003757#endif
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303758
Padma, Santhosh Kumarb8f65d92017-09-14 13:05:42 +05303759bool csr_lookup_pmkid_using_bssid(tpAniSirGlobal mac,
gaurank kathpalia14e2f912017-08-31 14:51:45 +05303760 struct csr_roam_session *session,
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303761 tPmkidCacheInfo *pmk_cache,
3762 uint32_t *index)
3763{
3764 uint32_t i;
3765 tPmkidCacheInfo *session_pmk;
3766
3767 for (i = 0; i < session->NumPmkidCache; i++) {
3768 session_pmk = &session->PmkidCacheInfo[i];
3769 sme_debug("Matching BSSID: " MAC_ADDRESS_STR " to cached BSSID:"
3770 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(pmk_cache->BSSID.bytes),
3771 MAC_ADDR_ARRAY(session_pmk->BSSID.bytes));
3772 if (qdf_is_macaddr_equal(&pmk_cache->BSSID,
3773 &session_pmk->BSSID)) {
3774 /* match found */
3775 *index = i;
3776 sme_debug("PMKID found at index %d", i);
3777 return true;
3778 }
3779 }
3780
3781 return false;
3782}
3783
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003784#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303785/**
3786 * csr_lookup_pmkid() - lookup pmkid using bssid or ssid + cache_id
3787 * @mac: pointer to mac
3788 * @session: sme session pointer
3789 * @pmk_cache: pointer to pmk cache
3790 * @index: index value needs to be seached
3791 *
3792 * Return: true if pmkid is found else false
3793 */
Jeff Johnson054d0282016-10-07 10:35:54 -07003794static bool csr_lookup_pmkid(tpAniSirGlobal pMac, uint32_t sessionId,
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303795 tPmkidCacheInfo *pmk_cache)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003796{
3797 bool fRC = false, fMatchFound = false;
3798 uint32_t Index;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05303799 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003800
3801 if (!pSession) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07003802 sme_err("session %d not found", sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803 return false;
3804 }
3805
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303806 if (pmk_cache->ssid_len) {
3807 /* Try to find based on cache_id and ssid first */
3808 fMatchFound = csr_lookup_pmkid_using_ssid(pMac, pSession,
3809 pmk_cache, &Index);
3810 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303812 /* If not able to find using cache id or ssid_len is not present */
3813 if (!fMatchFound)
3814 fMatchFound = csr_lookup_pmkid_using_bssid(pMac,
3815 pSession, pmk_cache, &Index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303817 if (!fMatchFound) {
3818 sme_debug("no pmkid match found NumPmkidCache = %d",
3819 pSession->NumPmkidCache);
3820 return false;
3821 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003822
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303823 qdf_mem_copy(pmk_cache->PMKID,
3824 pSession->PmkidCacheInfo[Index].PMKID,
3825 CSR_RSN_PMKID_SIZE);
3826
3827 qdf_mem_copy(pmk_cache->pmk,
3828 pSession->PmkidCacheInfo[Index].pmk,
3829 pSession->PmkidCacheInfo[Index].pmk_len);
3830 pmk_cache->pmk_len = pSession->PmkidCacheInfo[Index].pmk_len;
3831
3832 fRC = true;
3833 sme_debug("match = %d NumPmkidCache = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003834 fRC, pSession->NumPmkidCache);
3835
3836 return fRC;
3837}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003838#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05303840#ifdef WLAN_FEATURE_FILS_SK
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003841#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05303842/*
3843 * csr_update_pmksa_for_cache_id: update tPmkidCacheInfo to lookup using
3844 * ssid and cache id
3845 * @bss_desc: bss description
3846 * @profile: csr roam profile
3847 * @pmkid_cache: pmksa cache
3848 *
3849 * Return: true if cache identifier present else false
3850 */
3851static bool csr_update_pmksa_for_cache_id(tSirBssDescription *bss_desc,
Jeff Johnson66ee8a92018-03-17 15:24:26 -07003852 struct csr_roam_profile *profile,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05303853 tPmkidCacheInfo *pmkid_cache)
3854{
3855 if (!bss_desc->fils_info_element.is_cache_id_present)
3856 return false;
3857
3858 pmkid_cache->ssid_len =
3859 profile->SSIDs.SSIDList[0].SSID.length;
3860 qdf_mem_copy(pmkid_cache->ssid,
3861 profile->SSIDs.SSIDList[0].SSID.ssId,
3862 profile->SSIDs.SSIDList[0].SSID.length);
3863 qdf_mem_copy(pmkid_cache->cache_id,
3864 bss_desc->fils_info_element.cache_id,
3865 CACHE_ID_LEN);
3866 qdf_mem_copy(pmkid_cache->BSSID.bytes,
3867 bss_desc->bssId, QDF_MAC_ADDR_SIZE);
3868
3869 return true;
3870
3871}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003872#endif
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05303873/*
3874 * csr_update_pmksa_to_profile: update pmk and pmkid to profile which will be
3875 * used in case of fils session
3876 * @profile: profile
3877 * @pmkid_cache: pmksa cache
3878 *
3879 * Return: None
3880 */
Jeff Johnson66ee8a92018-03-17 15:24:26 -07003881static inline void csr_update_pmksa_to_profile(struct csr_roam_profile *profile,
3882 tPmkidCacheInfo *pmkid_cache)
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05303883{
3884 if (!profile->fils_con_info)
3885 return;
3886
3887 profile->fils_con_info->pmk_len = pmkid_cache->pmk_len;
3888 qdf_mem_copy(profile->fils_con_info->pmk,
3889 pmkid_cache->pmk, pmkid_cache->pmk_len);
3890 qdf_mem_copy(profile->fils_con_info->pmkid,
3891 pmkid_cache->PMKID, CSR_RSN_PMKID_SIZE);
3892
3893}
3894#else
3895static inline bool csr_update_pmksa_for_cache_id(tSirBssDescription *bss_desc,
Jeff Johnson66ee8a92018-03-17 15:24:26 -07003896 struct csr_roam_profile *profile,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05303897 tPmkidCacheInfo *pmkid_cache)
3898{
3899 return false;
3900}
3901
Jeff Johnson66ee8a92018-03-17 15:24:26 -07003902static inline void csr_update_pmksa_to_profile(struct csr_roam_profile *profile,
3903 tPmkidCacheInfo *pmkid_cache)
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05303904{
3905}
3906#endif
3907
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07003908#ifdef WLAN_CONV_CRYPTO_IE_SUPPORT
3909uint8_t csr_construct_rsn_ie(tpAniSirGlobal pMac, uint32_t sessionId,
3910 struct csr_roam_profile *pProfile,
3911 tSirBssDescription *pSirBssDesc,
3912 tDot11fBeaconIEs *pIes, tCsrRSNIe *pRSNIe)
3913{
3914 struct wlan_objmgr_vdev *vdev;
3915 uint8_t *rsn_ie_end = NULL;
3916 uint8_t *rsn_ie = (uint8_t *)pRSNIe;
3917 uint8_t ie_len = 0;
3918
3919 vdev = wlan_objmgr_get_vdev_by_id_from_psoc(pMac->psoc, sessionId,
3920 WLAN_LEGACY_SME_ID);
3921 if (!vdev) {
3922 sme_err("Invalid vdev");
3923 return ie_len;
3924 }
3925 rsn_ie_end = wlan_crypto_build_rsnie(vdev, rsn_ie);
3926 if (rsn_ie_end)
3927 ie_len = rsn_ie_end - rsn_ie;
3928
3929 wlan_objmgr_vdev_release_ref(vdev, WLAN_LEGACY_SME_ID);
3930
3931 return ie_len;
3932}
3933#else
Vignesh Viswanathan32f21c82018-09-11 17:36:30 +05303934/**
3935 * csr_update_session_pmk() - Update the pmk len and pmk in the roam session
3936 * @session: pointer to the CSR Roam session
3937 * @pmkid_cache: pointer to the pmkid cache
3938 *
3939 * Return: None
3940 */
3941#ifdef WLAN_FEATURE_ROAM_OFFLOAD
3942static void csr_update_session_pmk(struct csr_roam_session *session,
3943 tPmkidCacheInfo *pmkid_cache)
3944{
3945 session->pmk_len = pmkid_cache->pmk_len;
3946 qdf_mem_zero(session->psk_pmk, sizeof(session->psk_pmk));
3947 qdf_mem_copy(session->psk_pmk, pmkid_cache->pmk, session->pmk_len);
3948}
3949#else
3950static inline void csr_update_session_pmk(struct csr_roam_session *session,
3951 tPmkidCacheInfo *pmkid_cache)
3952{
3953}
3954#endif
3955
Jeff Johnson079c0022018-06-03 18:43:36 -07003956uint8_t csr_construct_rsn_ie(tpAniSirGlobal pMac, uint32_t sessionId,
Jeff Johnson66ee8a92018-03-17 15:24:26 -07003957 struct csr_roam_profile *pProfile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 tSirBssDescription *pSirBssDesc,
3959 tDot11fBeaconIEs *pIes, tCsrRSNIe *pRSNIe)
3960{
Naveen Rawat72475db2017-12-13 18:07:35 -08003961 uint32_t ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 bool fRSNMatch;
3963 uint8_t cbRSNIe = 0;
3964 uint8_t UnicastCypher[CSR_RSN_OUI_SIZE];
3965 uint8_t MulticastCypher[CSR_RSN_OUI_SIZE];
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05303966 uint8_t gp_mgmt_cipher_suite[CSR_RSN_OUI_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 uint8_t AuthSuite[CSR_RSN_OUI_SIZE];
3968 tCsrRSNAuthIe *pAuthSuite;
gaurank kathpaliac63859d2018-05-03 18:48:41 +05303969 struct rsn_caps RSNCapabilities;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970 tCsrRSNPMKIe *pPMK;
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05303971 tPmkidCacheInfo pmkid_cache;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972#ifdef WLAN_FEATURE_11W
3973 uint8_t *pGroupMgmtCipherSuite;
3974#endif
3975 tDot11fBeaconIEs *pIesLocal = pIes;
3976 eCsrAuthType negAuthType = eCSR_AUTH_TYPE_UNKNOWN;
Abhishek Singh3f13a812018-01-16 14:24:44 +05303977 tDot11fIERSN rsn_ie = {0};
gaurank kathpaliac63859d2018-05-03 18:48:41 +05303978 struct csr_roam_session *session = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979
gaurank kathpaliac63859d2018-05-03 18:48:41 +05303980 if (!CSR_IS_SESSION_VALID(pMac, sessionId) || !session)
3981 return 0;
Sandeep Puligillaa3cac402017-10-03 12:42:43 -07003982 qdf_mem_zero(&pmkid_cache, sizeof(pmkid_cache));
Jiachao Wu17d37b32018-01-24 14:24:02 +08003983 qdf_mem_zero(&rsn_ie, sizeof(rsn_ie));
3984
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 do {
3986 if (!csr_is_profile_rsn(pProfile))
3987 break;
3988
3989 if (!pIesLocal
3990 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303991 (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 (csr_get_parsed_bss_description_ies
3993 (pMac, pSirBssDesc, &pIesLocal)))) {
3994 break;
3995 }
Abhishek Singhed55b242017-12-20 11:02:34 +05303996
3997 /*
3998 * Use intersection of the RSN cap sent by user space and
3999 * the AP, so that only common capability are enabled.
4000 */
4001 if (pProfile->pRSNReqIE && pProfile->nRSNReqIELength) {
Naveen Rawat72475db2017-12-13 18:07:35 -08004002 ret = dot11f_unpack_ie_rsn(pMac,
4003 pProfile->pRSNReqIE + 2,
Abhishek Singhed55b242017-12-20 11:02:34 +05304004 pProfile->nRSNReqIELength -2, &rsn_ie, false);
Naveen Rawat72475db2017-12-13 18:07:35 -08004005 if (!DOT11F_FAILED(ret)) {
4006 pIesLocal->RSN.RSN_Cap[0] =
4007 pIesLocal->RSN.RSN_Cap[0] &
4008 rsn_ie.RSN_Cap[0];
4009 pIesLocal->RSN.RSN_Cap[1] =
4010 pIesLocal->RSN.RSN_Cap[1] &
4011 rsn_ie.RSN_Cap[1];
4012 }
Abhishek Singhed55b242017-12-20 11:02:34 +05304013 }
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304014 /* See if the cyphers in the Bss description match with the
4015 * settings in the profile.
4016 */
Jeff Johnson079c0022018-06-03 18:43:36 -07004017 fRSNMatch = csr_get_rsn_information(pMac, &pProfile->AuthType,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304018 pProfile->negotiatedUCEncryptionType,
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05304019 &pProfile->mcEncryptionType,
4020 &pIesLocal->RSN, UnicastCypher,
4021 MulticastCypher, AuthSuite,
4022 &RSNCapabilities, &negAuthType, NULL,
4023 gp_mgmt_cipher_suite,
4024 &pProfile->mgmt_encryption_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 if (!fRSNMatch)
4026 break;
4027
4028 pRSNIe->IeHeader.ElementID = SIR_MAC_RSN_EID;
4029
4030 pRSNIe->Version = CSR_RSN_VERSION_SUPPORTED;
4031
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304032 qdf_mem_copy(pRSNIe->MulticastOui, MulticastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 sizeof(MulticastCypher));
4034
4035 pRSNIe->cUnicastCyphers = 1;
4036
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304037 qdf_mem_copy(&pRSNIe->UnicastOui[0], UnicastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 sizeof(UnicastCypher));
4039
4040 pAuthSuite =
4041 (tCsrRSNAuthIe *) (&pRSNIe->
4042 UnicastOui[pRSNIe->cUnicastCyphers]);
4043
4044 pAuthSuite->cAuthenticationSuites = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304045 qdf_mem_copy(&pAuthSuite->AuthOui[0], AuthSuite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004046 sizeof(AuthSuite));
4047
Abhishek Singhed55b242017-12-20 11:02:34 +05304048 /* PreAuthSupported is an AP only capability */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 RSNCapabilities.PreAuthSupported = 0;
Abhishek Singhed55b242017-12-20 11:02:34 +05304050 /*
4051 * Use the Management Frame Protection values given by the
4052 * supplicant, if AP and STA both are MFP capable.
4053 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054#ifdef WLAN_FEATURE_11W
4055 if (RSNCapabilities.MFPCapable && pProfile->MFPCapable) {
4056 RSNCapabilities.MFPCapable = pProfile->MFPCapable;
4057 RSNCapabilities.MFPRequired = pProfile->MFPRequired;
4058 } else {
4059 RSNCapabilities.MFPCapable = 0;
4060 RSNCapabilities.MFPRequired = 0;
4061 }
4062#endif
4063 *(uint16_t *) (&pAuthSuite->AuthOui[1]) =
4064 *((uint16_t *) (&RSNCapabilities));
4065
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304066 pPMK = (tCsrRSNPMKIe *) (((uint8_t *) (&pAuthSuite->AuthOui[1]))
4067 + sizeof(uint16_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304069 if (!csr_update_pmksa_for_cache_id(pSirBssDesc,
4070 pProfile, &pmkid_cache))
4071 qdf_mem_copy(pmkid_cache.BSSID.bytes,
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05304072 pSirBssDesc->bssId, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 /* Don't include the PMK SA IDs for CCKM associations. */
4074 if (
4075#ifdef FEATURE_WLAN_ESE
4076 (eCSR_AUTH_TYPE_CCKM_RSN != negAuthType) &&
4077#endif
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05304078 csr_lookup_pmkid(pMac, sessionId, &pmkid_cache)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079 pPMK->cPMKIDs = 1;
4080
Sridhar Selvarajc3684c72017-08-21 14:32:47 +05304081 qdf_trace_hex_dump(QDF_MODULE_ID_PE,
4082 QDF_TRACE_LEVEL_INFO,
4083 pmkid_cache.pmk, pmkid_cache.pmk_len);
4084 qdf_mem_copy(pPMK->PMKIDList[0].PMKID,
4085 pmkid_cache.PMKID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086 CSR_RSN_PMKID_SIZE);
Vignesh Viswanathan32f21c82018-09-11 17:36:30 +05304087
4088 /*
4089 * If a PMK cache is found for the BSSID, then
4090 * update the PMK in CSR session also as this
4091 * will be sent to the FW during RSO.
4092 */
4093 csr_update_session_pmk(session, &pmkid_cache);
4094
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304095 csr_update_pmksa_to_profile(pProfile, &pmkid_cache);
4096 } else {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 pPMK->cPMKIDs = 0;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304098 }
gaurank kathpaliac63859d2018-05-03 18:48:41 +05304099 session->rsn_caps = RSNCapabilities;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100
4101#ifdef WLAN_FEATURE_11W
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05304102 /* Advertise BIP in group cipher key management only if PMF is
4103 * enabled and AP is capable.
4104 */
4105 if (pProfile->MFPEnabled &&
4106 (RSNCapabilities.MFPCapable && pProfile->MFPCapable)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107 pGroupMgmtCipherSuite =
4108 (uint8_t *) pPMK + sizeof(uint16_t) +
4109 (pPMK->cPMKIDs * CSR_RSN_PMKID_SIZE);
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05304110 qdf_mem_copy(pGroupMgmtCipherSuite,
4111 gp_mgmt_cipher_suite, CSR_RSN_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 }
4113#endif
Abhinav Kumar85561672018-04-17 12:48:51 +05304114 host_log_rsn_info(UnicastCypher, MulticastCypher,
4115 AuthSuite, gp_mgmt_cipher_suite);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304117 /* Add in the fixed fields plus 1 Unicast cypher, less the
4118 * IE Header length Add in the size of the Auth suite (count
4119 * plus a single OUI) Add in the RSN caps field.
4120 * Add PMKID count and PMKID (if any)
4121 * Add group management cipher suite
4122 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 pRSNIe->IeHeader.Length =
4124 (uint8_t) (sizeof(*pRSNIe) - sizeof(pRSNIe->IeHeader) +
4125 sizeof(*pAuthSuite) +
gaurank kathpaliac63859d2018-05-03 18:48:41 +05304126 sizeof(struct rsn_caps));
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304127 if (pPMK->cPMKIDs)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 pRSNIe->IeHeader.Length += (uint8_t) (sizeof(uint16_t) +
4129 (pPMK->cPMKIDs *
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304130 CSR_RSN_PMKID_SIZE));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131#ifdef WLAN_FEATURE_11W
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05304132 if (pProfile->MFPEnabled &&
4133 (RSNCapabilities.MFPCapable && pProfile->MFPCapable)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134 if (0 == pPMK->cPMKIDs)
4135 pRSNIe->IeHeader.Length += sizeof(uint16_t);
4136 pRSNIe->IeHeader.Length += CSR_WPA_OUI_SIZE;
4137 }
4138#endif
4139
4140 /* return the size of the IE header (total) constructed... */
4141 cbRSNIe = pRSNIe->IeHeader.Length + sizeof(pRSNIe->IeHeader);
4142
4143 } while (0);
4144
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304145 if (!pIes && pIesLocal)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304147 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148
4149 return cbRSNIe;
4150}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004151#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152
4153#ifdef FEATURE_WLAN_WAPI
4154/**
Jeff Johnson698eacd2018-05-12 17:00:03 -07004155 * csr_get_wapi_information() - to get WAPI information
Jeff Johnsond80e9152018-06-10 16:35:43 -07004156 * @mac_ctx: pointer to global MAC context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004157 * @auth_type: auth type
4158 * @encr_type: encryption type
4159 * @mc_encryption: multicast encryption type
4160 * @wapi_ie: pointer to WAPI IE
4161 * @ucast_cipher: Unicast cipher
4162 * @mcast_cipher: Multicast cipher
4163 * @auth_suite: Authentication suite
4164 * @negotiated_authtype: Negotiated auth type
4165 * @negotiated_mccipher: negotiated multicast cipher
4166 *
4167 * This routine will get all WAPI information
4168 *
4169 * Return: bool
4170 */
Jeff Johnsond80e9152018-06-10 16:35:43 -07004171static bool csr_get_wapi_information(tpAniSirGlobal mac_ctx,
4172 tCsrAuthList *auth_type,
Jeff Johnson054d0282016-10-07 10:35:54 -07004173 eCsrEncryptionType encr_type,
4174 tCsrEncryptionList *mc_encryption,
4175 tDot11fIEWAPI *wapi_ie,
4176 uint8_t *ucast_cipher,
4177 uint8_t *mcast_cipher, uint8_t *auth_suite,
4178 eCsrAuthType *negotiated_authtype,
4179 eCsrEncryptionType *negotiated_mccipher)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181 bool acceptable_cipher = false;
4182 uint8_t c_ucast_cipher = 0;
4183 uint8_t c_mcast_cipher = 0;
4184 uint8_t c_auth_suites = 0, i;
4185 uint8_t unicast[CSR_WAPI_OUI_SIZE];
4186 uint8_t multicast[CSR_WAPI_OUI_SIZE];
4187 uint8_t authsuites[CSR_WAPI_MAX_AUTH_SUITES][CSR_WAPI_OUI_SIZE];
4188 uint8_t authentication[CSR_WAPI_OUI_SIZE];
4189 uint8_t mccipher_arr[CSR_WAPI_MAX_MULTICAST_CYPHERS][CSR_WAPI_OUI_SIZE];
4190 eCsrAuthType neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
4191 uint8_t wapioui_idx = 0;
4192
4193 if (!wapi_ie->present)
4194 goto end;
4195
4196 c_mcast_cipher++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304197 qdf_mem_copy(mccipher_arr, wapi_ie->multicast_cipher_suite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198 CSR_WAPI_OUI_SIZE);
4199 c_ucast_cipher = (uint8_t) (wapi_ie->unicast_cipher_suite_count);
4200 c_auth_suites = (uint8_t) (wapi_ie->akm_suite_count);
4201 for (i = 0; i < c_auth_suites && i < CSR_WAPI_MAX_AUTH_SUITES; i++)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304202 qdf_mem_copy((void *)&authsuites[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203 (void *)&wapi_ie->akm_suites[i], CSR_WAPI_OUI_SIZE);
4204
4205 wapioui_idx = csr_get_oui_index_from_cipher(encr_type);
4206 if (wapioui_idx >= CSR_OUI_WAPI_WAI_MAX_INDEX) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07004207 sme_err("Wapi OUI index = %d out of limit",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 wapioui_idx);
4209 acceptable_cipher = false;
4210 goto end;
4211 }
4212 /* Check - Is requested unicast Cipher supported by the BSS. */
4213 acceptable_cipher = csr_match_wapi_oui_index(mac_ctx,
4214 wapi_ie->unicast_cipher_suites,
4215 c_ucast_cipher, wapioui_idx, unicast);
4216 if (!acceptable_cipher)
4217 goto end;
4218
4219 /* unicast is supported. Pick the first matching Group cipher, if any */
4220 for (i = 0; i < mc_encryption->numEntries; i++) {
4221 wapioui_idx = csr_get_oui_index_from_cipher(
4222 mc_encryption->encryptionType[i]);
4223 if (wapioui_idx >= CSR_OUI_WAPI_WAI_MAX_INDEX) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07004224 sme_err("Wapi OUI index = %d out of limit",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225 wapioui_idx);
4226 acceptable_cipher = false;
4227 break;
4228 }
4229 acceptable_cipher = csr_match_wapi_oui_index(mac_ctx,
4230 mccipher_arr, c_mcast_cipher,
4231 wapioui_idx, multicast);
4232 if (acceptable_cipher)
4233 break;
4234 }
4235 if (!acceptable_cipher)
4236 goto end;
4237
4238 if (negotiated_mccipher)
4239 *negotiated_mccipher =
4240 mc_encryption->encryptionType[i];
4241
4242 /*
4243 * Ciphers are supported, Match authentication algorithm and
4244 * pick first matching authtype
4245 */
4246 if (csr_is_auth_wapi_cert
4247 (mac_ctx, authsuites, c_auth_suites, authentication)) {
4248 neg_authtype =
4249 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
4250 } else if (csr_is_auth_wapi_psk(mac_ctx, authsuites,
4251 c_auth_suites, authentication)) {
4252 neg_authtype = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
4253 } else {
4254 acceptable_cipher = false;
4255 neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
4256 }
4257
4258 /* Caller doesn't care about auth type, or BSS doesn't match */
4259 if ((0 == auth_type->numEntries) || (false == acceptable_cipher))
4260 goto end;
4261
4262 acceptable_cipher = false;
4263 for (i = 0; i < auth_type->numEntries; i++) {
4264 if (auth_type->authType[i] == neg_authtype) {
4265 acceptable_cipher = true;
4266 break;
4267 }
4268 }
4269
4270end:
4271 if (acceptable_cipher) {
4272 if (mcast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304273 qdf_mem_copy(mcast_cipher, multicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 CSR_WAPI_OUI_SIZE);
4275 if (ucast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304276 qdf_mem_copy(ucast_cipher, unicast, CSR_WAPI_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004277 if (auth_suite)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304278 qdf_mem_copy(auth_suite, authentication,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279 CSR_WAPI_OUI_SIZE);
4280 if (negotiated_authtype)
4281 *negotiated_authtype = neg_authtype;
4282 }
4283 return acceptable_cipher;
4284}
4285
Jeff Johnson0589eec2018-06-10 16:40:10 -07004286static bool csr_is_wapi_match(tpAniSirGlobal mac_ctx, tCsrAuthList *pAuthType,
Jeff Johnson054d0282016-10-07 10:35:54 -07004287 eCsrEncryptionType enType,
4288 tCsrEncryptionList *pEnMcType,
4289 tDot11fBeaconIEs *pIes,
4290 eCsrAuthType *pNegotiatedAuthType,
4291 eCsrEncryptionType *pNegotiatedMCCipher)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292{
4293 bool fWapiMatch = false;
4294
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304295 /* See if the cyphers in the Bss description match with the
4296 * settings in the profile.
4297 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004298 fWapiMatch =
Jeff Johnson0589eec2018-06-10 16:40:10 -07004299 csr_get_wapi_information(mac_ctx, pAuthType, enType, pEnMcType,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300 &pIes->WAPI, NULL, NULL, NULL,
Jeff Johnson054d0282016-10-07 10:35:54 -07004301 pNegotiatedAuthType,
4302 pNegotiatedMCCipher);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303
4304 return fWapiMatch;
4305}
4306
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004307#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Jeff Johnson054d0282016-10-07 10:35:54 -07004308static bool csr_lookup_bkid(tpAniSirGlobal pMac, uint32_t sessionId,
4309 uint8_t *pBSSId, uint8_t *pBKId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310{
4311 bool fRC = false, fMatchFound = false;
4312 uint32_t Index;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05304313 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314
4315 if (!pSession) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07004316 sme_err("session %d not found", sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 return false;
4318 }
4319
4320 do {
4321 for (Index = 0; Index < pSession->NumBkidCache; Index++) {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07004322 sme_debug("match BKID " MAC_ADDRESS_STR " to ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 MAC_ADDR_ARRAY(pBSSId));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304324 if (!qdf_mem_cmp
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004325 (pBSSId, pSession->BkidCacheInfo[Index].BSSID.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304326 sizeof(struct qdf_mac_addr))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 /* match found */
4328 fMatchFound = true;
4329 break;
4330 }
4331 }
4332
4333 if (!fMatchFound)
4334 break;
4335
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304336 qdf_mem_copy(pBKId, pSession->BkidCacheInfo[Index].BKID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004337 CSR_WAPI_BKID_SIZE);
4338
4339 fRC = true;
4340 } while (0);
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07004341 sme_debug(
Srinivas Girigowda09625b02018-09-10 15:28:09 -07004342 "return match = %d pMac->roam.NumBkidCache = %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343 fRC, pSession->NumBkidCache);
4344
4345 return fRC;
4346}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004347#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004349#ifdef WLAN_CONV_CRYPTO_IE_SUPPORT
4350uint8_t csr_construct_wapi_ie(tpAniSirGlobal pMac, uint32_t sessionId,
4351 struct csr_roam_profile *pProfile,
4352 tSirBssDescription *pSirBssDesc,
4353 tDot11fBeaconIEs *pIes, tCsrWapiIe *pWapiIe)
4354{
4355 struct wlan_objmgr_vdev *vdev;
4356 uint8_t *wapi_ie_end = NULL;
4357 uint8_t *wapi_ie = (uint8_t *)pWapiIe;
4358 uint8_t ie_len = 0;
4359
4360 vdev = wlan_objmgr_get_vdev_by_id_from_psoc(pMac->psoc, sessionId,
4361 WLAN_LEGACY_SME_ID);
4362 if (!vdev) {
4363 sme_err("Invalid vdev");
4364 return ie_len;
4365 }
4366 wapi_ie_end = wlan_crypto_build_wapiie(vdev, wapi_ie);
4367 if (wapi_ie_end)
4368 ie_len = wapi_ie_end - wapi_ie;
4369
4370 wlan_objmgr_vdev_release_ref(vdev, WLAN_LEGACY_SME_ID);
4371
4372 return ie_len;
4373}
4374#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375uint8_t csr_construct_wapi_ie(tpAniSirGlobal pMac, uint32_t sessionId,
Jeff Johnson66ee8a92018-03-17 15:24:26 -07004376 struct csr_roam_profile *pProfile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377 tSirBssDescription *pSirBssDesc,
4378 tDot11fBeaconIEs *pIes, tCsrWapiIe *pWapiIe)
4379{
4380 bool fWapiMatch = false;
4381 uint8_t cbWapiIe = 0;
4382 uint8_t UnicastCypher[CSR_WAPI_OUI_SIZE];
4383 uint8_t MulticastCypher[CSR_WAPI_OUI_SIZE];
4384 uint8_t AuthSuite[CSR_WAPI_OUI_SIZE];
4385 uint8_t BKId[CSR_WAPI_BKID_SIZE];
4386 uint8_t *pWapi = NULL;
4387 bool fBKIDFound = false;
4388 tDot11fBeaconIEs *pIesLocal = pIes;
4389
4390 do {
4391 if (!csr_is_profile_wapi(pProfile))
4392 break;
4393
4394 if (!pIesLocal
4395 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304396 (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397 (csr_get_parsed_bss_description_ies
4398 (pMac, pSirBssDesc, &pIesLocal)))) {
4399 break;
4400 }
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304401 /* See if the cyphers in the Bss description match with the
4402 * settings in the profile.
4403 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404 fWapiMatch =
4405 csr_get_wapi_information(pMac, &pProfile->AuthType,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304406 pProfile->negotiatedUCEncryptionType,
4407 &pProfile->mcEncryptionType,
4408 &pIesLocal->WAPI, UnicastCypher,
4409 MulticastCypher, AuthSuite, NULL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410 NULL);
4411 if (!fWapiMatch)
4412 break;
4413
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304414 qdf_mem_set(pWapiIe, sizeof(tCsrWapiIe), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415
4416 pWapiIe->IeHeader.ElementID = DOT11F_EID_WAPI;
4417
4418 pWapiIe->Version = CSR_WAPI_VERSION_SUPPORTED;
4419
4420 pWapiIe->cAuthenticationSuites = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304421 qdf_mem_copy(&pWapiIe->AuthOui[0], AuthSuite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 sizeof(AuthSuite));
4423
4424 pWapi = (uint8_t *) (&pWapiIe->AuthOui[1]);
4425
4426 *pWapi = (uint16_t) 1; /* cUnicastCyphers */
4427 pWapi += 2;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304428 qdf_mem_copy(pWapi, UnicastCypher, sizeof(UnicastCypher));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429 pWapi += sizeof(UnicastCypher);
4430
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304431 qdf_mem_copy(pWapi, MulticastCypher, sizeof(MulticastCypher));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 pWapi += sizeof(MulticastCypher);
4433
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304434 /* WAPI capabilities follows the Auth Suite (two octects)
4435 * we shouldn't EVER be sending out "pre-auth supported".
4436 * It is an AP only capability & since we already did a memset
4437 * pWapiIe to 0, skip these fields
4438 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439 pWapi += 2;
4440
4441 fBKIDFound =
4442 csr_lookup_bkid(pMac, sessionId, pSirBssDesc->bssId,
4443 &(BKId[0]));
4444
4445 if (fBKIDFound) {
4446 /* Do we need to change the endianness here */
4447 *pWapi = (uint16_t) 1; /* cBKIDs */
4448 pWapi += 2;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304449 qdf_mem_copy(pWapi, BKId, CSR_WAPI_BKID_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004450 } else {
4451 *pWapi = 0;
4452 pWapi += 1;
4453 *pWapi = 0;
4454 pWapi += 1;
4455 }
4456
4457 /* Add in the IE fields except the IE header */
4458 /* Add BKID count and BKID (if any) */
4459 pWapiIe->IeHeader.Length =
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304460 (uint8_t) (sizeof(*pWapiIe) -
4461 sizeof(pWapiIe->IeHeader));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004462
4463 /*2 bytes for BKID Count field */
4464 pWapiIe->IeHeader.Length += sizeof(uint16_t);
4465
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304466 if (fBKIDFound)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467 pWapiIe->IeHeader.Length += CSR_WAPI_BKID_SIZE;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304468
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469 /* return the size of the IE header (total) constructed... */
4470 cbWapiIe = pWapiIe->IeHeader.Length + sizeof(pWapiIe->IeHeader);
4471
4472 } while (0);
4473
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304474 if (!pIes && pIesLocal)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004475 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304476 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004477
4478 return cbWapiIe;
4479}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004480#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481#endif /* FEATURE_WLAN_WAPI */
4482
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004483#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004484/**
4485 * csr_get_wpa_cyphers() - to get WPA cipher info
4486 * @mac_ctx: pointer to mac context
4487 * @auth_type: auth type
4488 * @encr_type: encryption type
4489 * @mc_encryption: multicast encryption type
4490 * @wpa_ie: pointer to WPA IE
4491 * @ucast_cipher: Unicast cipher
4492 * @mcast_cipher: Multicast cipher
4493 * @auth_suite: Authentication suite
4494 * @negotiated_authtype: Negotiated auth type
4495 * @negotiated_mccipher: negotiated multicast cipher
4496 *
4497 * This routine will get all WPA information
4498 *
4499 * Return: bool
4500 */
Jeff Johnson054d0282016-10-07 10:35:54 -07004501static bool csr_get_wpa_cyphers(tpAniSirGlobal mac_ctx, tCsrAuthList *auth_type,
4502 eCsrEncryptionType encr_type,
4503 tCsrEncryptionList *mc_encryption,
4504 tDot11fIEWPA *wpa_ie, uint8_t *ucast_cipher,
4505 uint8_t *mcast_cipher, uint8_t *auth_suite,
4506 eCsrAuthType *negotiated_authtype,
4507 eCsrEncryptionType *negotiated_mccipher)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004508{
4509 bool acceptable_cipher = false;
4510 uint8_t c_ucast_cipher = 0;
4511 uint8_t c_mcast_cipher = 0;
4512 uint8_t c_auth_suites = 0;
4513 uint8_t unicast[CSR_WPA_OUI_SIZE];
4514 uint8_t multicast[CSR_WPA_OUI_SIZE];
4515 uint8_t authentication[CSR_WPA_OUI_SIZE];
4516 uint8_t mccipher_arr[1][CSR_WPA_OUI_SIZE];
4517 uint8_t i;
Varun Reddy Yeturua863ec22017-08-02 16:47:51 -07004518 uint8_t index;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004519 eCsrAuthType neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
4520
4521 if (!wpa_ie->present)
4522 goto end;
4523 c_mcast_cipher = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304524 qdf_mem_copy(mccipher_arr, wpa_ie->multicast_cipher, CSR_WPA_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525 c_ucast_cipher = (uint8_t) (wpa_ie->unicast_cipher_count);
4526 c_auth_suites = (uint8_t) (wpa_ie->auth_suite_count);
4527
Varun Reddy Yeturua863ec22017-08-02 16:47:51 -07004528 /*
4529 * csr_match_wpaoui_index will provide the index of the
4530 * array csr_wpa_oui to be read and determine if it is
4531 * accepatable cipher or not. Below check ensures that
4532 * the index will not be out of range of the array size.
4533 */
4534 index = csr_get_oui_index_from_cipher(encr_type);
4535 if (!(index < (sizeof(csr_wpa_oui)/CSR_WPA_OUI_SIZE))) {
4536 sme_debug("Unacceptable index: %d", index);
4537 goto end;
4538 }
4539
4540 sme_debug("kw_dbg: index: %d", index);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004541 /* Check - Is requested unicast Cipher supported by the BSS. */
4542 acceptable_cipher = csr_match_wpaoui_index(mac_ctx,
4543 wpa_ie->unicast_ciphers, c_ucast_cipher,
Varun Reddy Yeturua863ec22017-08-02 16:47:51 -07004544 index, unicast);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545 if (!acceptable_cipher)
4546 goto end;
4547 /* unicast is supported. Pick the first matching Group cipher, if any */
4548 for (i = 0; i < mc_encryption->numEntries; i++) {
Varun Reddy Yeturua863ec22017-08-02 16:47:51 -07004549 index = csr_get_oui_index_from_cipher(
4550 mc_encryption->encryptionType[i]);
4551 sme_debug("kw_dbg: index: %d", index);
4552 if (!(index < (sizeof(csr_wpa_oui)/CSR_WPA_OUI_SIZE))) {
4553 sme_debug("Unacceptable MC index: %d", index);
4554 acceptable_cipher = false;
4555 continue;
4556 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004557 acceptable_cipher = csr_match_wpaoui_index(mac_ctx,
4558 mccipher_arr, c_mcast_cipher,
Varun Reddy Yeturua863ec22017-08-02 16:47:51 -07004559 index, multicast);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560 if (acceptable_cipher)
4561 break;
4562 }
4563 if (!acceptable_cipher)
4564 goto end;
4565
4566 if (negotiated_mccipher)
4567 *negotiated_mccipher = mc_encryption->encryptionType[i];
4568
4569 /* Initializing with false as it has true value already */
4570 acceptable_cipher = false;
4571 for (i = 0; i < auth_type->numEntries; i++) {
4572 /*
4573 * Ciphers are supported, Match authentication algorithm and
4574 * pick first matching authtype
4575 */
4576 if (csr_is_auth_wpa(mac_ctx, wpa_ie->auth_suites, c_auth_suites,
4577 authentication)) {
4578 if (eCSR_AUTH_TYPE_WPA == auth_type->authType[i])
4579 neg_authtype = eCSR_AUTH_TYPE_WPA;
4580 }
4581 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
4582 csr_is_auth_wpa_psk(mac_ctx,
4583 wpa_ie->auth_suites, c_auth_suites,
4584 authentication)) {
4585 if (eCSR_AUTH_TYPE_WPA_PSK == auth_type->authType[i])
4586 neg_authtype = eCSR_AUTH_TYPE_WPA_PSK;
4587 }
4588#ifdef FEATURE_WLAN_ESE
4589 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
4590 && csr_is_ese_cckm_auth_wpa(mac_ctx,
4591 wpa_ie->auth_suites, c_auth_suites,
4592 authentication)) {
4593 if (eCSR_AUTH_TYPE_CCKM_WPA == auth_type->authType[i])
4594 neg_authtype = eCSR_AUTH_TYPE_CCKM_WPA;
4595 }
4596#endif /* FEATURE_WLAN_ESE */
4597
4598 /*
4599 * The 1st auth type in the APs WPA IE, to match stations
4600 * connecting profiles auth type will cause us to exit this
4601 * loop. This is added as some APs advertise multiple akms in
4602 * the WPA IE
4603 */
4604 if (eCSR_AUTH_TYPE_UNKNOWN != neg_authtype) {
4605 acceptable_cipher = true;
4606 break;
4607 }
4608 }
4609
4610end:
4611 if (acceptable_cipher) {
4612 if (mcast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304613 qdf_mem_copy((uint8_t **) mcast_cipher, multicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004614 CSR_WPA_OUI_SIZE);
4615
4616 if (ucast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304617 qdf_mem_copy((uint8_t **) ucast_cipher, unicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618 CSR_WPA_OUI_SIZE);
4619
4620 if (auth_suite)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304621 qdf_mem_copy((uint8_t **) auth_suite, authentication,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004622 CSR_WPA_OUI_SIZE);
4623
4624 if (negotiated_authtype)
4625 *negotiated_authtype = neg_authtype;
4626 }
4627
4628 return acceptable_cipher;
4629}
4630
Jeff Johnson054d0282016-10-07 10:35:54 -07004631static bool csr_is_wpa_encryption_match(tpAniSirGlobal pMac,
4632 tCsrAuthList *pAuthType,
4633 eCsrEncryptionType enType,
4634 tCsrEncryptionList *pEnMcType,
4635 tDot11fBeaconIEs *pIes,
4636 eCsrAuthType *pNegotiatedAuthtype,
4637 eCsrEncryptionType *pNegotiatedMCCipher)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004638{
4639 bool fWpaMatch = false;
4640
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304641 /* See if the cyphers in the Bss description match with the
4642 * settings in the profile.
4643 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 fWpaMatch =
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304645 csr_get_wpa_cyphers(pMac, pAuthType, enType, pEnMcType,
4646 &pIes->WPA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647 NULL, NULL, NULL, pNegotiatedAuthtype,
4648 pNegotiatedMCCipher);
4649
4650 return fWpaMatch;
4651}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004652#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004654#ifdef WLAN_CONV_CRYPTO_IE_SUPPORT
4655uint8_t csr_construct_wpa_ie(tpAniSirGlobal pMac, uint8_t session_id,
4656 struct csr_roam_profile *pProfile,
4657 tSirBssDescription *pSirBssDesc,
4658 tDot11fBeaconIEs *pIes, tCsrWpaIe *pWpaIe)
4659{
4660 struct wlan_objmgr_vdev *vdev;
4661 uint8_t *wpa_ie_end = NULL;
4662 uint8_t *wpa_ie = (uint8_t *)pWpaIe;
4663 uint8_t ie_len = 0;
4664
4665 vdev = wlan_objmgr_get_vdev_by_id_from_psoc(pMac->psoc, session_id,
4666 WLAN_LEGACY_SME_ID);
4667 if (!vdev) {
4668 sme_err("Invalid vdev");
4669 return ie_len;
4670 }
4671 wpa_ie_end = wlan_crypto_build_wpaie(vdev, wpa_ie);
4672 if (wpa_ie_end)
4673 ie_len = wpa_ie_end - wpa_ie;
4674
4675 wlan_objmgr_vdev_release_ref(vdev, WLAN_LEGACY_SME_ID);
4676
4677 return ie_len;
4678}
4679#else
4680uint8_t csr_construct_wpa_ie(tpAniSirGlobal pMac, uint8_t session_id,
Jeff Johnsona6a191a2018-06-03 19:25:33 -07004681 struct csr_roam_profile *pProfile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682 tSirBssDescription *pSirBssDesc,
4683 tDot11fBeaconIEs *pIes, tCsrWpaIe *pWpaIe)
4684{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004685 bool fWpaMatch;
4686 uint8_t cbWpaIe = 0;
4687 uint8_t UnicastCypher[CSR_WPA_OUI_SIZE];
4688 uint8_t MulticastCypher[CSR_WPA_OUI_SIZE];
4689 uint8_t AuthSuite[CSR_WPA_OUI_SIZE];
4690 tCsrWpaAuthIe *pAuthSuite;
4691 tDot11fBeaconIEs *pIesLocal = pIes;
4692
4693 do {
4694 if (!csr_is_profile_wpa(pProfile))
4695 break;
4696
4697 if (!pIesLocal
4698 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304699 (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004700 (csr_get_parsed_bss_description_ies
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304701 (pMac, pSirBssDesc, &pIesLocal))))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004702 break;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304703 /* See if the cyphers in the Bss description match with the
4704 * settings in the profile.
4705 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004706 fWpaMatch =
Jeff Johnsona6a191a2018-06-03 19:25:33 -07004707 csr_get_wpa_cyphers(pMac, &pProfile->AuthType,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304708 pProfile->negotiatedUCEncryptionType,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004709 &pProfile->mcEncryptionType,
4710 &pIesLocal->WPA, UnicastCypher,
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304711 MulticastCypher, AuthSuite, NULL, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712 if (!fWpaMatch)
4713 break;
4714
4715 pWpaIe->IeHeader.ElementID = SIR_MAC_WPA_EID;
4716
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304717 qdf_mem_copy(pWpaIe->Oui, csr_wpa_oui[01], sizeof(pWpaIe->Oui));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718
4719 pWpaIe->Version = CSR_WPA_VERSION_SUPPORTED;
4720
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304721 qdf_mem_copy(pWpaIe->MulticastOui, MulticastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004722 sizeof(MulticastCypher));
4723
4724 pWpaIe->cUnicastCyphers = 1;
4725
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304726 qdf_mem_copy(&pWpaIe->UnicastOui[0], UnicastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727 sizeof(UnicastCypher));
4728
4729 pAuthSuite =
4730 (tCsrWpaAuthIe *) (&pWpaIe->
4731 UnicastOui[pWpaIe->cUnicastCyphers]);
4732
4733 pAuthSuite->cAuthenticationSuites = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304734 qdf_mem_copy(&pAuthSuite->AuthOui[0], AuthSuite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735 sizeof(AuthSuite));
4736
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304737 /* The WPA capabilities follows the Auth Suite (two octects)-
4738 * this field is optional, and we always "send" zero, so just
4739 * remove it. This is consistent with our assumptions in the
4740 * frames compiler; c.f. bug 15234:
4741 * http://gold.woodsidenet.com/bugzilla/show_bug.cgi?id=15234
4742 * Add in the fixed fields plus 1 Unicast cypher, less the IE
4743 * Header length Add in the size of the Auth suite (count plus
4744 * a single OUI)
4745 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004746 pWpaIe->IeHeader.Length =
4747 sizeof(*pWpaIe) - sizeof(pWpaIe->IeHeader) +
4748 sizeof(*pAuthSuite);
4749
4750 /* return the size of the IE header (total) constructed... */
4751 cbWpaIe = pWpaIe->IeHeader.Length + sizeof(pWpaIe->IeHeader);
4752
4753 } while (0);
4754
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304755 if (!pIes && pIesLocal)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004756 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304757 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004758
4759 return cbWpaIe;
4760}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004761#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304763/* If a WPAIE exists in the profile, just use it. Or else construct
4764 * one from the BSS Caller allocated memory for pWpaIe and guarrantee
4765 * it can contain a max length WPA IE
4766 */
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004767uint8_t csr_retrieve_wpa_ie(tpAniSirGlobal pMac, uint8_t session_id,
Jeff Johnson17c7fbf2018-06-03 19:33:51 -07004768 struct csr_roam_profile *pProfile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769 tSirBssDescription *pSirBssDesc,
4770 tDot11fBeaconIEs *pIes, tCsrWpaIe *pWpaIe)
4771{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 uint8_t cbWpaIe = 0;
4773
4774 do {
4775 if (!csr_is_profile_wpa(pProfile))
4776 break;
4777 if (pProfile->nWPAReqIELength && pProfile->pWPAReqIE) {
Naveen Rawatb88d73e2016-11-17 11:43:11 -08004778 if (pProfile->nWPAReqIELength <=
4779 DOT11F_IE_RSN_MAX_LEN) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004780 cbWpaIe = (uint8_t) pProfile->nWPAReqIELength;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304781 qdf_mem_copy(pWpaIe, pProfile->pWPAReqIE,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004782 cbWpaIe);
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004783 } else {
4784 sme_warn("Invalid WPA IE length %d",
4785 pProfile->nWPAReqIELength);
4786 }
4787 break;
4788 }
4789 cbWpaIe = csr_construct_wpa_ie(pMac, session_id, pProfile,
4790 pSirBssDesc, pIes, pWpaIe);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 } while (0);
4792
4793 return cbWpaIe;
4794}
4795
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304796/* If a RSNIE exists in the profile, just use it. Or else construct
4797 * one from the BSS Caller allocated memory for pWpaIe and guarrantee
4798 * it can contain a max length WPA IE
4799 */
Jeff Johnsonc8f9b672018-06-03 20:56:41 -07004800uint8_t csr_retrieve_rsn_ie(tpAniSirGlobal pMac, uint32_t sessionId,
Jeff Johnson66ee8a92018-03-17 15:24:26 -07004801 struct csr_roam_profile *pProfile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004802 tSirBssDescription *pSirBssDesc,
4803 tDot11fBeaconIEs *pIes, tCsrRSNIe *pRsnIe)
4804{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004805 uint8_t cbRsnIe = 0;
4806
4807 do {
4808 if (!csr_is_profile_rsn(pProfile))
4809 break;
Abhishek Singh6454ad32017-12-20 10:42:21 +05304810 /* copy RSNIE from user as it is if test mode is enabled */
4811 if (pProfile->force_rsne_override &&
4812 pProfile->nRSNReqIELength && pProfile->pRSNReqIE) {
4813 sme_debug("force_rsne_override, copy RSN IE provided by user");
4814 if (pProfile->nRSNReqIELength <=
4815 DOT11F_IE_RSN_MAX_LEN) {
4816 cbRsnIe = (uint8_t) pProfile->nRSNReqIELength;
4817 qdf_mem_copy(pRsnIe, pProfile->pRSNReqIE,
4818 cbRsnIe);
4819 } else {
Srinivas Girigowda09625b02018-09-10 15:28:09 -07004820 sme_warn("Invalid RSN IE length: %d",
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004821 pProfile->nRSNReqIELength);
Abhishek Singh6454ad32017-12-20 10:42:21 +05304822 }
4823 break;
4824 }
bings13f45e62018-08-22 11:24:56 +08004825 cbRsnIe = csr_construct_rsn_ie(pMac, sessionId, pProfile,
4826 pSirBssDesc, pIes, pRsnIe);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827 } while (0);
4828
4829 return cbRsnIe;
4830}
4831
4832#ifdef FEATURE_WLAN_WAPI
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05304833/* If a WAPI IE exists in the profile, just use it. Or else construct
4834 * one from the BSS Caller allocated memory for pWapiIe and guarrantee
4835 * it can contain a max length WAPI IE
4836 */
Jeff Johnsonc2769622018-06-03 21:14:25 -07004837uint8_t csr_retrieve_wapi_ie(tpAniSirGlobal pMac, uint32_t sessionId,
Jeff Johnson66ee8a92018-03-17 15:24:26 -07004838 struct csr_roam_profile *pProfile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839 tSirBssDescription *pSirBssDesc,
4840 tDot11fBeaconIEs *pIes, tCsrWapiIe *pWapiIe)
4841{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004842 uint8_t cbWapiIe = 0;
4843
4844 do {
4845 if (!csr_is_profile_wapi(pProfile))
4846 break;
4847 if (pProfile->nWAPIReqIELength && pProfile->pWAPIReqIE) {
4848 if (DOT11F_IE_WAPI_MAX_LEN >=
4849 pProfile->nWAPIReqIELength) {
4850 cbWapiIe = (uint8_t) pProfile->nWAPIReqIELength;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304851 qdf_mem_copy(pWapiIe, pProfile->pWAPIReqIE,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004852 cbWapiIe);
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004853 } else {
4854 sme_warn("Invalid WAPI IE length %d",
4855 pProfile->nWAPIReqIELength);
4856 }
4857 break;
4858 }
4859 cbWapiIe = csr_construct_wapi_ie(pMac, sessionId,
4860 pProfile, pSirBssDesc,
4861 pIes, pWapiIe);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004862 } while (0);
4863
4864 return cbWapiIe;
4865}
4866#endif /* FEATURE_WLAN_WAPI */
4867
4868bool csr_rates_is_dot11_rate11b_supported_rate(uint8_t dot11Rate)
4869{
4870 bool fSupported = false;
4871 uint16_t nonBasicRate =
4872 (uint16_t) (BITS_OFF(dot11Rate, CSR_DOT11_BASIC_RATE_MASK));
4873
4874 switch (nonBasicRate) {
4875 case eCsrSuppRate_1Mbps:
4876 case eCsrSuppRate_2Mbps:
4877 case eCsrSuppRate_5_5Mbps:
4878 case eCsrSuppRate_11Mbps:
4879 fSupported = true;
4880 break;
4881
4882 default:
4883 break;
4884 }
4885
4886 return fSupported;
4887}
4888
4889bool csr_rates_is_dot11_rate11a_supported_rate(uint8_t dot11Rate)
4890{
4891 bool fSupported = false;
4892 uint16_t nonBasicRate =
4893 (uint16_t) (BITS_OFF(dot11Rate, CSR_DOT11_BASIC_RATE_MASK));
4894
4895 switch (nonBasicRate) {
4896 case eCsrSuppRate_6Mbps:
4897 case eCsrSuppRate_9Mbps:
4898 case eCsrSuppRate_12Mbps:
4899 case eCsrSuppRate_18Mbps:
4900 case eCsrSuppRate_24Mbps:
4901 case eCsrSuppRate_36Mbps:
4902 case eCsrSuppRate_48Mbps:
4903 case eCsrSuppRate_54Mbps:
4904 fSupported = true;
4905 break;
4906
4907 default:
4908 break;
4909 }
4910
4911 return fSupported;
4912}
4913
4914tAniEdType csr_translate_encrypt_type_to_ed_type(eCsrEncryptionType EncryptType)
4915{
4916 tAniEdType edType;
4917
4918 switch (EncryptType) {
4919 default:
4920 case eCSR_ENCRYPT_TYPE_NONE:
4921 edType = eSIR_ED_NONE;
4922 break;
4923
4924 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
4925 case eCSR_ENCRYPT_TYPE_WEP40:
4926 edType = eSIR_ED_WEP40;
4927 break;
4928
4929 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
4930 case eCSR_ENCRYPT_TYPE_WEP104:
4931 edType = eSIR_ED_WEP104;
4932 break;
4933
4934 case eCSR_ENCRYPT_TYPE_TKIP:
4935 edType = eSIR_ED_TKIP;
4936 break;
4937
4938 case eCSR_ENCRYPT_TYPE_AES:
4939 edType = eSIR_ED_CCMP;
4940 break;
4941#ifdef FEATURE_WLAN_WAPI
4942 case eCSR_ENCRYPT_TYPE_WPI:
4943 edType = eSIR_ED_WPI;
4944 break;
4945#endif
4946#ifdef WLAN_FEATURE_11W
4947 /* 11w BIP */
4948 case eCSR_ENCRYPT_TYPE_AES_CMAC:
4949 edType = eSIR_ED_AES_128_CMAC;
4950 break;
Mukul Sharma05504ac2017-06-08 12:35:53 +05304951 case eCSR_ENCRYPT_TYPE_AES_GCMP:
4952 edType = eSIR_ED_GCMP;
4953 break;
4954 case eCSR_ENCRYPT_TYPE_AES_GCMP_256:
4955 edType = eSIR_ED_GCMP_256;
4956 break;
Padma, Santhosh Kumar4117d7a2017-12-20 17:39:33 +05304957 case eCSR_ENCRYPT_TYPE_AES_GMAC_128:
4958 edType = eSIR_ED_AES_GMAC_128;
4959 break;
4960 case eCSR_ENCRYPT_TYPE_AES_GMAC_256:
4961 edType = eSIR_ED_AES_GMAC_256;
4962 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004963#endif
4964 }
4965
4966 return edType;
4967}
4968
4969/**
4970 * csr_validate_wep() - to validate wep
4971 * @uc_encry_type: unicast encryption type
4972 * @auth_list: Auth list
4973 * @mc_encryption_list: multicast encryption type
4974 * @negotiated_authtype: negotiated auth type
4975 * @negotiated_mc_encry: negotiated mc encry type
4976 * @bss_descr: BSS description
4977 * @ie_ptr: IE pointer
4978 *
4979 * This function just checks whether HDD is giving correct values for
4980 * Multicast cipher and Auth
4981 *
4982 * Return: bool
4983 */
Jeff Johnson054d0282016-10-07 10:35:54 -07004984static bool csr_validate_wep(tpAniSirGlobal mac_ctx,
4985 eCsrEncryptionType uc_encry_type,
4986 tCsrAuthList *auth_list,
4987 tCsrEncryptionList *mc_encryption_list,
Jeff Johnson054d0282016-10-07 10:35:54 -07004988 tSirBssDescription *bss_descr,
4989 tDot11fBeaconIEs *ie_ptr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990{
4991 uint32_t idx;
4992 bool match = false;
Padma, Santhosh Kumar5f428922017-07-24 12:48:00 +05304993 uint8_t oui_index;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004994
4995 /* If privacy bit is not set, consider no match */
4996 if (!csr_is_privacy(bss_descr))
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07004997 return match;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998
4999 for (idx = 0; idx < mc_encryption_list->numEntries; idx++) {
5000 switch (mc_encryption_list->encryptionType[idx]) {
5001 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
5002 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
5003 case eCSR_ENCRYPT_TYPE_WEP40:
5004 case eCSR_ENCRYPT_TYPE_WEP104:
5005 /*
5006 * Multicast list may contain WEP40/WEP104.
5007 * Check whether it matches UC.
5008 */
5009 if (uc_encry_type ==
5010 mc_encryption_list->encryptionType[idx]) {
5011 match = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005012 }
5013 break;
5014 default:
5015 match = false;
5016 break;
5017 }
5018 if (match)
5019 break;
5020 }
5021
5022 if (!match)
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005023 return match;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005024
5025 for (idx = 0; idx < auth_list->numEntries; idx++) {
5026 switch (auth_list->authType[idx]) {
5027 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
5028 case eCSR_AUTH_TYPE_SHARED_KEY:
5029 case eCSR_AUTH_TYPE_AUTOSWITCH:
5030 match = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031 break;
5032 default:
5033 match = false;
5034 }
5035 if (match)
5036 break;
5037 }
5038
5039 if (!match)
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005040 return match;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005041
5042 if (!ie_ptr)
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005043 return match;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005044
5045 /*
5046 * In case of WPA / WPA2, check whether it supports WEP as well.
5047 * Prepare the encryption type for WPA/WPA2 functions
5048 */
5049 if (eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == uc_encry_type)
5050 uc_encry_type = eCSR_ENCRYPT_TYPE_WEP40;
5051 else if (eCSR_ENCRYPT_TYPE_WEP104 == uc_encry_type)
5052 uc_encry_type = eCSR_ENCRYPT_TYPE_WEP104;
5053
5054 /* else we can use the encryption type directly */
5055 if (ie_ptr->WPA.present) {
Padma, Santhosh Kumar5f428922017-07-24 12:48:00 +05305056 oui_index = csr_get_oui_index_from_cipher(uc_encry_type);
5057 if (oui_index < QDF_ARRAY_SIZE(csr_wpa_oui))
5058 match = (!qdf_mem_cmp(ie_ptr->WPA.multicast_cipher,
5059 csr_wpa_oui[oui_index],
5060 CSR_WPA_OUI_SIZE));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061 if (match)
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005062 return match;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063 }
5064 if (ie_ptr->RSN.present) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305065 match = (!qdf_mem_cmp(ie_ptr->RSN.gp_cipher_suite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005066 csr_rsn_oui[csr_get_oui_index_from_cipher(
5067 uc_encry_type)],
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305068 CSR_RSN_OUI_SIZE));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069 }
5070
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071 return match;
5072}
5073
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005074#ifndef WLAN_CONV_CRYPTO_IE_SUPPORT
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005075/**
5076 * csr_validate_open_none() - Check if the security is matching
5077 * @bss_desc: BSS Descriptor on which the check is done
5078 * @mc_enc_type: Multicast encryption type
5079 * @mc_cipher: Multicast Cipher
5080 * @auth_type: Authentication type
5081 * @neg_auth_type: Negotiated Auth type with the AP
5082 *
5083 * Return: Boolean value to tell if matched or not.
5084 */
5085static bool csr_validate_open_none(tSirBssDescription *bss_desc,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005086 tCsrEncryptionList *mc_enc_type,
5087 tCsrAuthList *auth_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088{
5089 bool match;
5090 uint8_t idx;
5091
5092 /*
5093 * for NO encryption, if the Bss description has the
5094 * Privacy bit turned on, then encryption is required
5095 * so we have to reject this Bss.
5096 */
5097 if (csr_is_privacy(bss_desc))
5098 match = false;
5099 else
5100 match = true;
5101 if (match) {
5102 match = false;
5103 /* Check MC cipher and Auth type requested. */
5104 for (idx = 0; idx < mc_enc_type->numEntries; idx++) {
5105 if (eCSR_ENCRYPT_TYPE_NONE ==
5106 mc_enc_type->encryptionType[idx]) {
5107 match = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005108 break;
5109 }
5110 }
5111 if (!match)
5112 return match;
5113
5114 match = false;
5115 /* Check Auth list. It should contain AuthOpen. */
5116 for (idx = 0; idx < auth_type->numEntries; idx++) {
5117 if ((eCSR_AUTH_TYPE_OPEN_SYSTEM ==
5118 auth_type->authType[idx]) ||
5119 (eCSR_AUTH_TYPE_AUTOSWITCH ==
5120 auth_type->authType[idx])) {
5121 match = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122 break;
5123 }
5124 }
5125 if (!match)
5126 return match;
5127
5128 }
5129 return match;
5130}
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005131#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132/**
5133 * csr_validate_any_default() - Check if the security is matching
Jeff Johnsonc6ab08f2018-06-10 16:47:32 -07005134 * @mac_ctx: Global MAC context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 * @auth_type: Authentication type
5136 * @mc_enc_type: Multicast encryption type
5137 * @mfp_enabled: Management frame protection feature
Jeff Johnson9020f0c2018-05-06 08:08:25 -07005138 * @mfp_required: Management frame protection mandatory
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005139 * @mfp_capable: Device capable of MFP
5140 * @ies_ptr: Pointer to the IE fields
5141 * @neg_auth_type: Negotiated Auth type with the AP
5142 * @bss_desc: BSS Descriptor
5143 * @neg_uc_cipher: Negotiated unicast cipher suite
5144 * @neg_mc_cipher: Negotiated multicast cipher
5145 *
5146 * Return: Boolean value to tell if matched or not.
5147 */
Jeff Johnsonc6ab08f2018-06-10 16:47:32 -07005148static bool csr_validate_any_default(tpAniSirGlobal mac_ctx,
5149 tCsrAuthList *auth_type,
5150 tCsrEncryptionList *mc_enc_type,
5151 bool *mfp_enabled,
5152 uint8_t *mfp_required,
5153 uint8_t *mfp_capable,
5154 tDot11fBeaconIEs *ies_ptr,
5155 eCsrAuthType *neg_auth_type,
5156 tSirBssDescription *bss_desc,
5157 eCsrEncryptionType *uc_cipher,
5158 eCsrEncryptionType *mc_cipher)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159{
5160 bool match_any = false;
5161 bool match = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005162 /* It is allowed to match anything. Try the more secured ones first. */
5163 if (ies_ptr) {
Mukul Sharma05504ac2017-06-08 12:35:53 +05305164 /* Check GCMP-256 first */
5165 *uc_cipher = eCSR_ENCRYPT_TYPE_AES_GCMP_256;
Jeff Johnson44d0c092018-06-10 16:02:47 -07005166 match_any = csr_is_rsn_match(mac_ctx, auth_type,
Mukul Sharma05504ac2017-06-08 12:35:53 +05305167 *uc_cipher, mc_enc_type, mfp_enabled,
5168 mfp_required, mfp_capable, ies_ptr,
5169 neg_auth_type, mc_cipher);
5170 /* Check GCMP second */
5171 *uc_cipher = eCSR_ENCRYPT_TYPE_AES_GCMP;
Jeff Johnson44d0c092018-06-10 16:02:47 -07005172 match_any = csr_is_rsn_match(mac_ctx, auth_type,
Mukul Sharma05504ac2017-06-08 12:35:53 +05305173 *uc_cipher, mc_enc_type, mfp_enabled,
5174 mfp_required, mfp_capable, ies_ptr,
5175 neg_auth_type, mc_cipher);
5176 /* Check AES third */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177 *uc_cipher = eCSR_ENCRYPT_TYPE_AES;
Jeff Johnson44d0c092018-06-10 16:02:47 -07005178 match_any = csr_is_rsn_match(mac_ctx, auth_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005179 *uc_cipher, mc_enc_type, mfp_enabled,
5180 mfp_required, mfp_capable, ies_ptr,
5181 neg_auth_type, mc_cipher);
5182 if (!match_any) {
5183 /* Check TKIP */
5184 *uc_cipher = eCSR_ENCRYPT_TYPE_TKIP;
Jeff Johnson44d0c092018-06-10 16:02:47 -07005185 match_any = csr_is_rsn_match(mac_ctx, auth_type,
5186 *uc_cipher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187 mc_enc_type, mfp_enabled, mfp_required,
5188 mfp_capable, ies_ptr, neg_auth_type,
5189 mc_cipher);
5190 }
5191#ifdef FEATURE_WLAN_WAPI
5192 if (!match_any) {
5193 /* Check WAPI */
5194 *uc_cipher = eCSR_ENCRYPT_TYPE_WPI;
Jeff Johnson0589eec2018-06-10 16:40:10 -07005195 match_any = csr_is_wapi_match(mac_ctx, auth_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196 *uc_cipher, mc_enc_type, ies_ptr,
5197 neg_auth_type, mc_cipher);
5198 }
5199#endif
5200 }
5201 if (match_any)
5202 return match;
5203 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP104;
5204 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005205 bss_desc, ies_ptr))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206 return match;
5207 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP40;
5208 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005209 bss_desc, ies_ptr))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 return match;
5211 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
5212 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005213 bss_desc, ies_ptr))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214 return match;
5215 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
5216 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005217 bss_desc, ies_ptr))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 return match;
5219 /* It must be open and no enc */
5220 if (csr_is_privacy(bss_desc)) {
5221 match = false;
5222 return match;
5223 }
5224
5225 *neg_auth_type = eCSR_AUTH_TYPE_OPEN_SYSTEM;
5226 *mc_cipher = eCSR_ENCRYPT_TYPE_NONE;
5227 *uc_cipher = eCSR_ENCRYPT_TYPE_NONE;
5228 return match;
5229
5230}
5231
5232/**
5233 * csr_is_security_match() - Check if the security is matching
Jeff Johnsonad4e8052018-06-03 21:24:49 -07005234 * @mac_ctx: Global MAC context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005235 * @auth_type: Authentication type
5236 * @uc_enc_type: Unicast Encryption type
5237 * @mc_enc_type: Multicast encryption type
5238 * @mfp_enabled: Management frame protection feature
Jeff Johnson9020f0c2018-05-06 08:08:25 -07005239 * @mfp_required: Management frame protection mandatory
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240 * @mfp_capable: Device capable of MFP
5241 * @bss_desc: BSS Descriptor
5242 * @ies_ptr: Pointer to the IE fields
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005243 * @session_id: Session Id
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 *
5245 * Return: Boolean value to tell if matched or not.
5246 */
Jeff Johnsonad4e8052018-06-03 21:24:49 -07005247bool csr_is_security_match(tpAniSirGlobal mac_ctx, tCsrAuthList *auth_type,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005248 tCsrEncryptionList *uc_enc_type,
5249 tCsrEncryptionList *mc_enc_type, bool *mfp_enabled,
5250 uint8_t *mfp_required, uint8_t *mfp_capable,
5251 tSirBssDescription *bss_desc,
5252 tDot11fBeaconIEs *ies_ptr, uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 bool match = false;
5255 uint8_t i;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005256 eCsrEncryptionType uc_cipher = eCSR_ENCRYPT_TYPE_UNKNOWN;
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005257 uint16_t ie_len;
5258
5259 ie_len = (bss_desc->length + sizeof(bss_desc->length) -
5260 GET_FIELD_OFFSET(tSirBssDescription, ieFields));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005261
5262 for (i = 0; ((i < uc_enc_type->numEntries) && (!match)); i++) {
5263 uc_cipher = uc_enc_type->encryptionType[i];
5264 /*
5265 * If the Bss description shows the Privacy bit is on, then we
5266 * must have some sort of encryption configured for the profile
5267 * to work. Don't attempt to join networks with Privacy bit
5268 * set when profiles say NONE for encryption type.
5269 */
5270 switch (uc_cipher) {
5271 case eCSR_ENCRYPT_TYPE_NONE:
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005272#ifdef WLAN_CONV_CRYPTO_IE_SUPPORT
5273 if (csr_is_privacy(bss_desc))
5274 return false;
5275
5276 match = wlan_crypto_check_open_none(mac_ctx->psoc,
5277 session_id);
5278#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005279 match = csr_validate_open_none(bss_desc, mc_enc_type,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005280 auth_type);
5281#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282 break;
5283
5284 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
5285 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005286 case eCSR_ENCRYPT_TYPE_WEP40:
5287 case eCSR_ENCRYPT_TYPE_WEP104:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005288 /*
5289 * !! might want to check for WEP keys set in the
5290 * Profile.... ? !! don't need to have the privacy bit
5291 * in the Bss description. Many AP policies make
5292 * legacy encryption 'optional' so we don't know if we
5293 * can associate or not. The AP will reject if
5294 * encryption is not allowed without the Privacy bit
5295 * turned on.
5296 */
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005297#ifdef WLAN_CONV_CRYPTO_IE_SUPPORT
5298 if (!csr_is_privacy(bss_desc))
5299 return false;
5300
5301 match = wlan_crypto_check_wep(mac_ctx->psoc,
5302 session_id);
5303#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005304 match = csr_validate_wep(mac_ctx, uc_cipher, auth_type,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005305 mc_enc_type, bss_desc,
5306 ies_ptr);
5307#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005308
5309 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310 case eCSR_ENCRYPT_TYPE_TKIP:
5311 case eCSR_ENCRYPT_TYPE_AES:
Mukul Sharma05504ac2017-06-08 12:35:53 +05305312 case eCSR_ENCRYPT_TYPE_AES_GCMP:
5313 case eCSR_ENCRYPT_TYPE_AES_GCMP_256:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 if (!ies_ptr) {
5315 match = false;
5316 break;
5317 }
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005318#ifdef WLAN_CONV_CRYPTO_IE_SUPPORT
5319 match = wlan_crypto_check_rsn_match(mac_ctx->psoc,
5320 session_id,
5321 (uint8_t *)
5322 &bss_desc->ieFields,
5323 ie_len);
5324 if (match)
5325 break;
5326 match = wlan_crypto_check_wpa_match(mac_ctx->psoc,
5327 session_id,
5328 (uint8_t *)
5329 &bss_desc->ieFields,
5330 ie_len);
5331#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 /* First check if there is a RSN match */
5333 match = csr_is_rsn_match(mac_ctx, auth_type,
5334 uc_cipher, mc_enc_type,
5335 mfp_enabled, mfp_required,
5336 mfp_capable, ies_ptr,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005337 NULL, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005338 /* If not RSN, then check WPA match */
5339 if (!match)
5340 match = csr_is_wpa_encryption_match(
5341 mac_ctx, auth_type,
5342 uc_cipher, mc_enc_type,
5343 ies_ptr,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005344 NULL, NULL);
5345#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346 break;
5347#ifdef FEATURE_WLAN_WAPI
5348 case eCSR_ENCRYPT_TYPE_WPI: /* WAPI */
5349 if (ies_ptr)
Jeff Johnsonad4e8052018-06-03 21:24:49 -07005350 match = csr_is_wapi_match(mac_ctx, auth_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005351 uc_cipher, mc_enc_type, ies_ptr,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005352 NULL, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353 else
5354 match = false;
5355 break;
5356#endif /* FEATURE_WLAN_WAPI */
5357 case eCSR_ENCRYPT_TYPE_ANY:
5358 default:
Jeff Johnsonad4e8052018-06-03 21:24:49 -07005359 match = csr_validate_any_default(mac_ctx, auth_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360 mc_enc_type, mfp_enabled, mfp_required,
5361 mfp_capable, ies_ptr,
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07005362 NULL, bss_desc,
5363 &uc_cipher, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364 break;
5365 }
5366
5367 }
5368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005369 return match;
5370}
5371
5372bool csr_is_ssid_match(tpAniSirGlobal pMac, uint8_t *ssid1, uint8_t ssid1Len,
5373 uint8_t *bssSsid, uint8_t bssSsidLen, bool fSsidRequired)
5374{
5375 bool fMatch = false;
5376
5377 do {
5378 /*
5379 * Check for the specification of the Broadcast SSID at the
5380 * beginning of the list. If specified, then all SSIDs are
5381 * matches (broadcast SSID means accept all SSIDs).
5382 */
5383 if (ssid1Len == 0) {
5384 fMatch = true;
5385 break;
5386 }
5387
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305388 /* There are a few special cases. If the Bss description has
5389 * a Broadcast SSID, then our Profile must have a single SSID
5390 * without Wildcards so we can program the SSID.
5391 *
5392 * SSID could be suppressed in beacons. In that case SSID IE
5393 * has valid length but the SSID value is all NULL characters.
5394 * That condition is trated same as NULL SSID
5395 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396 if (csr_is_nullssid(bssSsid, bssSsidLen)) {
5397 if (false == fSsidRequired) {
5398 fMatch = true;
5399 break;
5400 }
5401 }
5402
5403 if (ssid1Len != bssSsidLen)
5404 break;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305405 if (!qdf_mem_cmp(bssSsid, ssid1, bssSsidLen)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406 fMatch = true;
5407 break;
5408 }
5409
5410 } while (0);
5411
5412 return fMatch;
5413}
5414
5415/* Null ssid means match */
Jeff Johnsonb9307a92018-06-03 11:22:32 -07005416bool csr_is_ssid_in_list(tSirMacSSid *pSsid, tCsrSSIDs *pSsidList)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417{
5418 bool fMatch = false;
5419 uint32_t i;
5420
5421 if (pSsidList && pSsid) {
5422 for (i = 0; i < pSsidList->numOfSSIDs; i++) {
5423 if (csr_is_nullssid
5424 (pSsidList->SSIDList[i].SSID.ssId,
5425 pSsidList->SSIDList[i].SSID.length)
5426 ||
5427 ((pSsidList->SSIDList[i].SSID.length ==
5428 pSsid->length)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305429 && (!qdf_mem_cmp(pSsid->ssId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005430 pSsidList->SSIDList[i].SSID.
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305431 ssId, pSsid->length)))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 fMatch = true;
5433 break;
5434 }
5435 }
5436 }
5437
5438 return fMatch;
5439}
5440
Jeff Johnson0da6fed2018-06-03 11:41:09 -07005441bool csr_is_bssid_match(struct qdf_mac_addr *pProfBssid,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305442 struct qdf_mac_addr *BssBssid)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005443{
5444 bool fMatch = false;
Anurag Chouhan6d760662016-02-20 16:05:43 +05305445 struct qdf_mac_addr ProfileBssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005446
5447 /* for efficiency of the MAC_ADDRESS functions, move the */
5448 /* Bssid's into MAC_ADDRESS structs. */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305449 qdf_mem_copy(&ProfileBssid, pProfBssid, sizeof(struct qdf_mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005450
5451 do {
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305452 /* Give the profile the benefit of the doubt... accept
5453 * either all 0 or the real broadcast Bssid (all 0xff)
5454 * as broadcast Bssids (meaning to match any Bssids).
5455 */
Anurag Chouhanc5548422016-02-24 18:33:27 +05305456 if (qdf_is_macaddr_zero(&ProfileBssid) ||
5457 qdf_is_macaddr_broadcast(&ProfileBssid)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005458 fMatch = true;
5459 break;
5460 }
5461
Anurag Chouhanc5548422016-02-24 18:33:27 +05305462 if (qdf_is_macaddr_equal(BssBssid, &ProfileBssid)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005463 fMatch = true;
5464 break;
5465 }
5466
5467 } while (0);
5468
5469 return fMatch;
5470}
5471
5472bool csr_is_bss_type_match(eCsrRoamBssType bssType1, eCsrRoamBssType bssType2)
5473{
5474 if ((eCSR_BSS_TYPE_ANY != bssType1 && eCSR_BSS_TYPE_ANY != bssType2)
5475 && (bssType1 != bssType2))
5476 return false;
5477 else
5478 return true;
5479}
5480
5481bool csr_is_bss_type_ibss(eCsrRoamBssType bssType)
5482{
5483 return (bool)
5484 (eCSR_BSS_TYPE_START_IBSS == bssType
5485 || eCSR_BSS_TYPE_IBSS == bssType);
5486}
5487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005488/**
5489 * csr_is_aggregate_rate_supported() - to check if aggregate rate is supported
5490 * @mac_ctx: pointer to mac context
5491 * @rate: A rate in units of 500kbps
5492 *
5493 *
5494 * The rate encoding is just as in 802.11 Information Elements, except
5495 * that the high bit is \em not interpreted as indicating a Basic Rate,
5496 * and proprietary rates are allowed, too.
5497 *
5498 * Note that if the adapter's dot11Mode is g, we don't restrict the
5499 * rates. According to hwReadEepromParameters, this will happen when:
5500 * ... the card is configured for ALL bands through the property
5501 * page. If this occurs, and the card is not an ABG card ,then this
5502 * code is setting the dot11Mode to assume the mode that the
5503 * hardware can support. For example, if the card is an 11BG card
5504 * and we are configured to support ALL bands, then we change the
5505 * dot11Mode to 11g because ALL in this case is only what the
5506 * hardware can support.
5507 *
5508 * Return: true if the adapter is currently capable of supporting this rate
5509 */
5510
5511static bool csr_is_aggregate_rate_supported(tpAniSirGlobal mac_ctx,
5512 uint16_t rate)
5513{
5514 bool supported = false;
5515 uint16_t idx, new_rate;
5516
5517 /* In case basic rate flag is set */
5518 new_rate = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
5519 if (eCSR_CFG_DOT11_MODE_11A ==
5520 mac_ctx->roam.configParam.uCfgDot11Mode) {
5521 switch (new_rate) {
5522 case eCsrSuppRate_6Mbps:
5523 case eCsrSuppRate_9Mbps:
5524 case eCsrSuppRate_12Mbps:
5525 case eCsrSuppRate_18Mbps:
5526 case eCsrSuppRate_24Mbps:
5527 case eCsrSuppRate_36Mbps:
5528 case eCsrSuppRate_48Mbps:
5529 case eCsrSuppRate_54Mbps:
5530 supported = true;
5531 break;
5532 default:
5533 supported = false;
5534 break;
5535 }
5536
5537 } else if (eCSR_CFG_DOT11_MODE_11B ==
5538 mac_ctx->roam.configParam.uCfgDot11Mode) {
5539 switch (new_rate) {
5540 case eCsrSuppRate_1Mbps:
5541 case eCsrSuppRate_2Mbps:
5542 case eCsrSuppRate_5_5Mbps:
5543 case eCsrSuppRate_11Mbps:
5544 supported = true;
5545 break;
5546 default:
5547 supported = false;
5548 break;
5549 }
5550 } else if (!mac_ctx->roam.configParam.ProprietaryRatesEnabled) {
5551
5552 switch (new_rate) {
5553 case eCsrSuppRate_1Mbps:
5554 case eCsrSuppRate_2Mbps:
5555 case eCsrSuppRate_5_5Mbps:
5556 case eCsrSuppRate_6Mbps:
5557 case eCsrSuppRate_9Mbps:
5558 case eCsrSuppRate_11Mbps:
5559 case eCsrSuppRate_12Mbps:
5560 case eCsrSuppRate_18Mbps:
5561 case eCsrSuppRate_24Mbps:
5562 case eCsrSuppRate_36Mbps:
5563 case eCsrSuppRate_48Mbps:
5564 case eCsrSuppRate_54Mbps:
5565 supported = true;
5566 break;
5567 default:
5568 supported = false;
5569 break;
5570 }
5571 } else if (eCsrSuppRate_1Mbps == new_rate ||
5572 eCsrSuppRate_2Mbps == new_rate ||
5573 eCsrSuppRate_5_5Mbps == new_rate ||
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305574 eCsrSuppRate_11Mbps == new_rate)
5575 supported = true;
5576 else {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005577 idx = 0x1;
5578
5579 switch (new_rate) {
5580 case eCsrSuppRate_6Mbps:
5581 supported = g_phy_rates_suppt[0][idx];
5582 break;
5583 case eCsrSuppRate_9Mbps:
5584 supported = g_phy_rates_suppt[1][idx];
5585 break;
5586 case eCsrSuppRate_12Mbps:
5587 supported = g_phy_rates_suppt[2][idx];
5588 break;
5589 case eCsrSuppRate_18Mbps:
5590 supported = g_phy_rates_suppt[3][idx];
5591 break;
5592 case eCsrSuppRate_20Mbps:
5593 supported = g_phy_rates_suppt[4][idx];
5594 break;
5595 case eCsrSuppRate_24Mbps:
5596 supported = g_phy_rates_suppt[5][idx];
5597 break;
5598 case eCsrSuppRate_36Mbps:
5599 supported = g_phy_rates_suppt[6][idx];
5600 break;
5601 case eCsrSuppRate_40Mbps:
5602 supported = g_phy_rates_suppt[7][idx];
5603 break;
5604 case eCsrSuppRate_42Mbps:
5605 supported = g_phy_rates_suppt[8][idx];
5606 break;
5607 case eCsrSuppRate_48Mbps:
5608 supported = g_phy_rates_suppt[9][idx];
5609 break;
5610 case eCsrSuppRate_54Mbps:
5611 supported = g_phy_rates_suppt[10][idx];
5612 break;
5613 case eCsrSuppRate_72Mbps:
5614 supported = g_phy_rates_suppt[11][idx];
5615 break;
5616 case eCsrSuppRate_80Mbps:
5617 supported = g_phy_rates_suppt[12][idx];
5618 break;
5619 case eCsrSuppRate_84Mbps:
5620 supported = g_phy_rates_suppt[13][idx];
5621 break;
5622 case eCsrSuppRate_96Mbps:
5623 supported = g_phy_rates_suppt[14][idx];
5624 break;
5625 case eCsrSuppRate_108Mbps:
5626 supported = g_phy_rates_suppt[15][idx];
5627 break;
5628 case eCsrSuppRate_120Mbps:
5629 supported = g_phy_rates_suppt[16][idx];
5630 break;
5631 case eCsrSuppRate_126Mbps:
5632 supported = g_phy_rates_suppt[17][idx];
5633 break;
5634 case eCsrSuppRate_144Mbps:
5635 supported = g_phy_rates_suppt[18][idx];
5636 break;
5637 case eCsrSuppRate_160Mbps:
5638 supported = g_phy_rates_suppt[19][idx];
5639 break;
5640 case eCsrSuppRate_168Mbps:
5641 supported = g_phy_rates_suppt[20][idx];
5642 break;
5643 case eCsrSuppRate_192Mbps:
5644 supported = g_phy_rates_suppt[21][idx];
5645 break;
5646 case eCsrSuppRate_216Mbps:
5647 supported = g_phy_rates_suppt[22][idx];
5648 break;
5649 case eCsrSuppRate_240Mbps:
5650 supported = g_phy_rates_suppt[23][idx];
5651 break;
5652 default:
5653 supported = false;
5654 break;
5655 }
5656 }
5657 return supported;
5658}
5659
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660void csr_add_rate_bitmap(uint8_t rate, uint16_t *pRateBitmap)
5661{
5662 uint16_t rateBitmap;
5663 uint16_t n = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305664
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005665 rateBitmap = *pRateBitmap;
5666 switch (n) {
5667 case SIR_MAC_RATE_1:
5668 rateBitmap |= SIR_MAC_RATE_1_BITMAP;
5669 break;
5670 case SIR_MAC_RATE_2:
5671 rateBitmap |= SIR_MAC_RATE_2_BITMAP;
5672 break;
5673 case SIR_MAC_RATE_5_5:
5674 rateBitmap |= SIR_MAC_RATE_5_5_BITMAP;
5675 break;
5676 case SIR_MAC_RATE_11:
5677 rateBitmap |= SIR_MAC_RATE_11_BITMAP;
5678 break;
5679 case SIR_MAC_RATE_6:
5680 rateBitmap |= SIR_MAC_RATE_6_BITMAP;
5681 break;
5682 case SIR_MAC_RATE_9:
5683 rateBitmap |= SIR_MAC_RATE_9_BITMAP;
5684 break;
5685 case SIR_MAC_RATE_12:
5686 rateBitmap |= SIR_MAC_RATE_12_BITMAP;
5687 break;
5688 case SIR_MAC_RATE_18:
5689 rateBitmap |= SIR_MAC_RATE_18_BITMAP;
5690 break;
5691 case SIR_MAC_RATE_24:
5692 rateBitmap |= SIR_MAC_RATE_24_BITMAP;
5693 break;
5694 case SIR_MAC_RATE_36:
5695 rateBitmap |= SIR_MAC_RATE_36_BITMAP;
5696 break;
5697 case SIR_MAC_RATE_48:
5698 rateBitmap |= SIR_MAC_RATE_48_BITMAP;
5699 break;
5700 case SIR_MAC_RATE_54:
5701 rateBitmap |= SIR_MAC_RATE_54_BITMAP;
5702 break;
5703 }
5704 *pRateBitmap = rateBitmap;
5705}
5706
5707bool csr_check_rate_bitmap(uint8_t rate, uint16_t rateBitmap)
5708{
5709 uint16_t n = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
5710
5711 switch (n) {
5712 case SIR_MAC_RATE_1:
5713 rateBitmap &= SIR_MAC_RATE_1_BITMAP;
5714 break;
5715 case SIR_MAC_RATE_2:
5716 rateBitmap &= SIR_MAC_RATE_2_BITMAP;
5717 break;
5718 case SIR_MAC_RATE_5_5:
5719 rateBitmap &= SIR_MAC_RATE_5_5_BITMAP;
5720 break;
5721 case SIR_MAC_RATE_11:
5722 rateBitmap &= SIR_MAC_RATE_11_BITMAP;
5723 break;
5724 case SIR_MAC_RATE_6:
5725 rateBitmap &= SIR_MAC_RATE_6_BITMAP;
5726 break;
5727 case SIR_MAC_RATE_9:
5728 rateBitmap &= SIR_MAC_RATE_9_BITMAP;
5729 break;
5730 case SIR_MAC_RATE_12:
5731 rateBitmap &= SIR_MAC_RATE_12_BITMAP;
5732 break;
5733 case SIR_MAC_RATE_18:
5734 rateBitmap &= SIR_MAC_RATE_18_BITMAP;
5735 break;
5736 case SIR_MAC_RATE_24:
5737 rateBitmap &= SIR_MAC_RATE_24_BITMAP;
5738 break;
5739 case SIR_MAC_RATE_36:
5740 rateBitmap &= SIR_MAC_RATE_36_BITMAP;
5741 break;
5742 case SIR_MAC_RATE_48:
5743 rateBitmap &= SIR_MAC_RATE_48_BITMAP;
5744 break;
5745 case SIR_MAC_RATE_54:
5746 rateBitmap &= SIR_MAC_RATE_54_BITMAP;
5747 break;
5748 }
5749 return !!rateBitmap;
5750}
5751
Jeff Johnsoned463e12018-06-03 21:33:33 -07005752bool csr_rates_is_dot11_rate_supported(tpAniSirGlobal mac_ctx, uint8_t rate)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005754 uint16_t n = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
5755
Jeff Johnsoned463e12018-06-03 21:33:33 -07005756 return csr_is_aggregate_rate_supported(mac_ctx, n);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005757}
5758
Jeff Johnson054d0282016-10-07 10:35:54 -07005759static uint16_t csr_rates_mac_prop_to_dot11(uint16_t Rate)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760{
5761 uint16_t ConvertedRate = Rate;
5762
5763 switch (Rate) {
5764 case SIR_MAC_RATE_1:
5765 ConvertedRate = 2;
5766 break;
5767 case SIR_MAC_RATE_2:
5768 ConvertedRate = 4;
5769 break;
5770 case SIR_MAC_RATE_5_5:
5771 ConvertedRate = 11;
5772 break;
5773 case SIR_MAC_RATE_11:
5774 ConvertedRate = 22;
5775 break;
5776
5777 case SIR_MAC_RATE_6:
5778 ConvertedRate = 12;
5779 break;
5780 case SIR_MAC_RATE_9:
5781 ConvertedRate = 18;
5782 break;
5783 case SIR_MAC_RATE_12:
5784 ConvertedRate = 24;
5785 break;
5786 case SIR_MAC_RATE_18:
5787 ConvertedRate = 36;
5788 break;
5789 case SIR_MAC_RATE_24:
5790 ConvertedRate = 48;
5791 break;
5792 case SIR_MAC_RATE_36:
5793 ConvertedRate = 72;
5794 break;
5795 case SIR_MAC_RATE_42:
5796 ConvertedRate = 84;
5797 break;
5798 case SIR_MAC_RATE_48:
5799 ConvertedRate = 96;
5800 break;
5801 case SIR_MAC_RATE_54:
5802 ConvertedRate = 108;
5803 break;
5804
5805 case SIR_MAC_RATE_72:
5806 ConvertedRate = 144;
5807 break;
5808 case SIR_MAC_RATE_84:
5809 ConvertedRate = 168;
5810 break;
5811 case SIR_MAC_RATE_96:
5812 ConvertedRate = 192;
5813 break;
5814 case SIR_MAC_RATE_108:
5815 ConvertedRate = 216;
5816 break;
5817 case SIR_MAC_RATE_126:
5818 ConvertedRate = 252;
5819 break;
5820 case SIR_MAC_RATE_144:
5821 ConvertedRate = 288;
5822 break;
5823 case SIR_MAC_RATE_168:
5824 ConvertedRate = 336;
5825 break;
5826 case SIR_MAC_RATE_192:
5827 ConvertedRate = 384;
5828 break;
5829 case SIR_MAC_RATE_216:
5830 ConvertedRate = 432;
5831 break;
5832 case SIR_MAC_RATE_240:
5833 ConvertedRate = 480;
5834 break;
5835
5836 case 0xff:
5837 ConvertedRate = 0;
5838 break;
5839 }
5840
5841 return ConvertedRate;
5842}
5843
5844uint16_t csr_rates_find_best_rate(tSirMacRateSet *pSuppRates,
5845 tSirMacRateSet *pExtRates,
5846 tSirMacPropRateSet *pPropRates)
5847{
5848 uint8_t i;
5849 uint16_t nBest;
5850
5851 nBest = pSuppRates->rate[0] & (~CSR_DOT11_BASIC_RATE_MASK);
5852
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305853 if (pSuppRates->numRates > SIR_MAC_RATESET_EID_MAX)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005854 pSuppRates->numRates = SIR_MAC_RATESET_EID_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005855
5856 for (i = 1U; i < pSuppRates->numRates; ++i) {
5857 nBest =
5858 (uint16_t) CSR_MAX(nBest,
5859 pSuppRates->
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305860 rate[i] & (~CSR_DOT11_BASIC_RATE_MASK));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005861 }
5862
5863 if (NULL != pExtRates) {
5864 for (i = 0U; i < pExtRates->numRates; ++i) {
5865 nBest =
5866 (uint16_t) CSR_MAX(nBest,
5867 pExtRates->
5868 rate[i] &
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305869 (~CSR_DOT11_BASIC_RATE_MASK));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005870 }
5871 }
5872
5873 if (NULL != pPropRates) {
5874 for (i = 0U; i < pPropRates->numPropRates; ++i) {
5875 nBest =
5876 (uint16_t) CSR_MAX(nBest,
5877 csr_rates_mac_prop_to_dot11
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305878 (pPropRates->propRate[i]));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005879 }
5880 }
5881
5882 return nBest;
5883}
5884
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305885#ifdef WLAN_FEATURE_FILS_SK
Jeff Johnson66ee8a92018-03-17 15:24:26 -07005886static inline void csr_free_fils_profile_info(struct csr_roam_profile *profile)
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305887{
5888 if (profile->fils_con_info) {
5889 qdf_mem_free(profile->fils_con_info);
5890 profile->fils_con_info = NULL;
5891 }
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305892
5893 if (profile->hlp_ie) {
5894 qdf_mem_free(profile->hlp_ie);
5895 profile->hlp_ie = NULL;
5896 profile->hlp_ie_len = 0;
5897 }
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305898}
5899#else
Jeff Johnson66ee8a92018-03-17 15:24:26 -07005900static inline void csr_free_fils_profile_info(struct csr_roam_profile *profile)
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305901{ }
5902#endif
5903
Jeff Johnson66ee8a92018-03-17 15:24:26 -07005904void csr_release_profile(tpAniSirGlobal pMac, struct csr_roam_profile *pProfile)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005905{
5906 if (pProfile) {
5907 if (pProfile->BSSIDs.bssid) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305908 qdf_mem_free(pProfile->BSSIDs.bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005909 pProfile->BSSIDs.bssid = NULL;
5910 }
5911 if (pProfile->SSIDs.SSIDList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305912 qdf_mem_free(pProfile->SSIDs.SSIDList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005913 pProfile->SSIDs.SSIDList = NULL;
5914 }
5915 if (pProfile->pWPAReqIE) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305916 qdf_mem_free(pProfile->pWPAReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005917 pProfile->pWPAReqIE = NULL;
5918 }
5919 if (pProfile->pRSNReqIE) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305920 qdf_mem_free(pProfile->pRSNReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005921 pProfile->pRSNReqIE = NULL;
5922 }
5923#ifdef FEATURE_WLAN_WAPI
5924 if (pProfile->pWAPIReqIE) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305925 qdf_mem_free(pProfile->pWAPIReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005926 pProfile->pWAPIReqIE = NULL;
5927 }
5928#endif /* FEATURE_WLAN_WAPI */
5929
5930 if (pProfile->pAddIEScan) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305931 qdf_mem_free(pProfile->pAddIEScan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005932 pProfile->pAddIEScan = NULL;
5933 }
5934
5935 if (pProfile->pAddIEAssoc) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305936 qdf_mem_free(pProfile->pAddIEAssoc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937 pProfile->pAddIEAssoc = NULL;
5938 }
5939 if (pProfile->ChannelInfo.ChannelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305940 qdf_mem_free(pProfile->ChannelInfo.ChannelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941 pProfile->ChannelInfo.ChannelList = NULL;
5942 }
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305943 csr_free_fils_profile_info(pProfile);
Jeff Johnson66ee8a92018-03-17 15:24:26 -07005944 qdf_mem_set(pProfile, sizeof(struct csr_roam_profile), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945 }
5946}
5947
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05305948void csr_free_scan_filter(tpAniSirGlobal pMac, tCsrScanResultFilter
5949 *pScanFilter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950{
5951 if (pScanFilter->BSSIDs.bssid) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305952 qdf_mem_free(pScanFilter->BSSIDs.bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005953 pScanFilter->BSSIDs.bssid = NULL;
5954 }
5955 if (pScanFilter->ChannelInfo.ChannelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305956 qdf_mem_free(pScanFilter->ChannelInfo.ChannelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005957 pScanFilter->ChannelInfo.ChannelList = NULL;
5958 }
5959 if (pScanFilter->SSIDs.SSIDList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305960 qdf_mem_free(pScanFilter->SSIDs.SSIDList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005961 pScanFilter->SSIDs.SSIDList = NULL;
5962 }
5963}
5964
5965void csr_free_roam_profile(tpAniSirGlobal pMac, uint32_t sessionId)
5966{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05305967 struct csr_roam_session *pSession = &pMac->roam.roamSession[sessionId];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968
5969 if (pSession->pCurRoamProfile) {
5970 csr_release_profile(pMac, pSession->pCurRoamProfile);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305971 qdf_mem_free(pSession->pCurRoamProfile);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005972 pSession->pCurRoamProfile = NULL;
5973 }
5974}
5975
5976void csr_free_connect_bss_desc(tpAniSirGlobal pMac, uint32_t sessionId)
5977{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05305978 struct csr_roam_session *pSession = &pMac->roam.roamSession[sessionId];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979
5980 if (pSession->pConnectBssDesc) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305981 qdf_mem_free(pSession->pConnectBssDesc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982 pSession->pConnectBssDesc = NULL;
5983 }
5984}
5985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986tSirResultCodes csr_get_de_auth_rsp_status_code(tSirSmeDeauthRsp *pSmeRsp)
5987{
5988 uint8_t *pBuffer = (uint8_t *) pSmeRsp;
5989 uint32_t ret;
5990
5991 pBuffer +=
5992 (sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint8_t) +
5993 sizeof(uint16_t));
5994 /* tSirResultCodes is an enum, assuming is 32bit */
5995 /* If we cannot make this assumption, use copymemory */
Anurag Chouhanc5548422016-02-24 18:33:27 +05305996 qdf_get_u32(pBuffer, &ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997
5998 return (tSirResultCodes) ret;
5999}
6000
6001tSirScanType csr_get_scan_type(tpAniSirGlobal pMac, uint8_t chnId)
6002{
6003 tSirScanType scanType = eSIR_PASSIVE_SCAN;
Amar Singhala297bfa2015-10-15 15:07:29 -07006004 enum channel_state channelEnabledType;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006005
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006006 channelEnabledType = wlan_reg_get_channel_state(pMac->pdev, chnId);
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306007 if (CHANNEL_STATE_ENABLE == channelEnabledType)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006008 scanType = eSIR_ACTIVE_SCAN;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306009
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010 return scanType;
6011}
6012
6013uint8_t csr_to_upper(uint8_t ch)
6014{
6015 uint8_t chOut;
6016
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306017 if (ch >= 'a' && ch <= 'z')
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006018 chOut = ch - 'a' + 'A';
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306019 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006020 chOut = ch;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306021
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022 return chOut;
6023}
6024
6025tSirBssType csr_translate_bsstype_to_mac_type(eCsrRoamBssType csrtype)
6026{
6027 tSirBssType ret;
6028
6029 switch (csrtype) {
6030 case eCSR_BSS_TYPE_INFRASTRUCTURE:
6031 ret = eSIR_INFRASTRUCTURE_MODE;
6032 break;
6033 case eCSR_BSS_TYPE_IBSS:
6034 case eCSR_BSS_TYPE_START_IBSS:
6035 ret = eSIR_IBSS_MODE;
6036 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006037 case eCSR_BSS_TYPE_INFRA_AP:
6038 ret = eSIR_INFRA_AP_MODE;
6039 break;
Deepak Dhamdheree2dd5442016-05-27 15:05:51 -07006040 case eCSR_BSS_TYPE_NDI:
6041 ret = eSIR_NDI_MODE;
6042 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006043 case eCSR_BSS_TYPE_ANY:
6044 default:
6045 ret = eSIR_AUTO_MODE;
6046 break;
6047 }
6048
6049 return ret;
6050}
6051
6052/* This function use the parameters to decide the CFG value. */
6053/* CSR never sets WNI_CFG_DOT11_MODE_ALL to the CFG */
6054/* So PE should not see WNI_CFG_DOT11_MODE_ALL when it gets the CFG value */
Jeff Johnson66ee8a92018-03-17 15:24:26 -07006055enum csr_cfgdot11mode
6056csr_get_cfg_dot11_mode_from_csr_phy_mode(struct csr_roam_profile *pProfile,
6057 eCsrPhyMode phyMode,
6058 bool fProprietary)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059{
6060 uint32_t cfgDot11Mode = eCSR_CFG_DOT11_MODE_ABG;
6061
6062 switch (phyMode) {
6063 case eCSR_DOT11_MODE_11a:
6064 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
6065 break;
6066 case eCSR_DOT11_MODE_11b:
6067 case eCSR_DOT11_MODE_11b_ONLY:
6068 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
6069 break;
6070 case eCSR_DOT11_MODE_11g:
6071 case eCSR_DOT11_MODE_11g_ONLY:
6072 if (pProfile && (CSR_IS_INFRA_AP(pProfile))
6073 && (phyMode == eCSR_DOT11_MODE_11g_ONLY))
6074 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G_ONLY;
6075 else
6076 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
6077 break;
6078 case eCSR_DOT11_MODE_11n:
6079 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
6080 break;
6081 case eCSR_DOT11_MODE_11n_ONLY:
6082 if (pProfile && CSR_IS_INFRA_AP(pProfile))
6083 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N_ONLY;
6084 else
6085 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
6086 break;
6087 case eCSR_DOT11_MODE_abg:
6088 cfgDot11Mode = eCSR_CFG_DOT11_MODE_ABG;
6089 break;
6090 case eCSR_DOT11_MODE_AUTO:
6091 cfgDot11Mode = eCSR_CFG_DOT11_MODE_AUTO;
6092 break;
6093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094 case eCSR_DOT11_MODE_11ac:
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306095 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006096 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306097 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099 break;
6100 case eCSR_DOT11_MODE_11ac_ONLY:
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306101 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006102 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC_ONLY;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306103 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006104 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105 break;
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08006106 case eCSR_DOT11_MODE_11ax:
6107 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
6108 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AX;
6109 else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
6110 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
6111 else
6112 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
6113 break;
6114 case eCSR_DOT11_MODE_11ax_ONLY:
6115 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
6116 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AX_ONLY;
6117 else if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
6118 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
6119 else
6120 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
6121 break;
6122
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006123 default:
6124 /* No need to assign anything here */
6125 break;
6126 }
6127
6128 return cfgDot11Mode;
6129}
6130
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306131QDF_STATUS csr_get_regulatory_domain_for_country(tpAniSirGlobal pMac,
Amar Singhala297bfa2015-10-15 15:07:29 -07006132 uint8_t *pCountry,
6133 v_REGDOMAIN_t *pDomainId,
6134 enum country_src source)
6135{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306136 QDF_STATUS status = QDF_STATUS_E_INVAL;
6137 QDF_STATUS qdf_status;
Amar Singhala297bfa2015-10-15 15:07:29 -07006138 uint8_t countryCode[CDS_COUNTRY_CODE_LEN + 1];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139 v_REGDOMAIN_t domainId;
6140
6141 if (pCountry) {
6142 countryCode[0] = pCountry[0];
6143 countryCode[1] = pCountry[1];
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006144 qdf_status = wlan_reg_get_domain_from_country_code(&domainId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006145 countryCode,
6146 source);
6147
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306148 if (QDF_IS_STATUS_SUCCESS(qdf_status)) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006149 if (pDomainId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150 *pDomainId = domainId;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306151 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152 } else {
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07006153 sme_warn("Couldn't find domain for country code %c%c",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006154 pCountry[0], pCountry[1]);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306155 status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006156 }
6157 }
6158
6159 return status;
6160}
6161
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306162QDF_STATUS csr_get_modify_profile_fields(tpAniSirGlobal pMac,
6163 uint32_t sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006164 tCsrRoamModifyProfileFields *
6165 pModifyProfileFields)
6166{
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306167 if (!pModifyProfileFields)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306168 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306170 qdf_mem_copy(pModifyProfileFields,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006171 &pMac->roam.roamSession[sessionId].connectedProfile.
6172 modifyProfileFields, sizeof(tCsrRoamModifyProfileFields));
6173
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306174 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175}
6176
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306177QDF_STATUS csr_set_modify_profile_fields(tpAniSirGlobal pMac,
6178 uint32_t sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006179 tCsrRoamModifyProfileFields *
6180 pModifyProfileFields)
6181{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05306182 struct csr_roam_session *pSession = CSR_GET_SESSION(pMac, sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006183
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306184 qdf_mem_copy(&pSession->connectedProfile.modifyProfileFields,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 pModifyProfileFields, sizeof(tCsrRoamModifyProfileFields));
6186
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306187 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006188}
6189
6190
6191bool csr_is_set_key_allowed(tpAniSirGlobal pMac, uint32_t sessionId)
6192{
6193 bool fRet = true;
gaurank kathpalia14e2f912017-08-31 14:51:45 +05306194 struct csr_roam_session *pSession;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006195
6196 pSession = CSR_GET_SESSION(pMac, sessionId);
6197
6198 /*
6199 * This condition is not working for infra state. When infra is in
6200 * not-connected state the pSession->pCurRoamProfile is NULL, this
6201 * function returns true, that is incorrect.
6202 * Since SAP requires to set key without any BSS started, it needs
6203 * this condition to be met. In other words, this function is useless.
6204 * The current work-around is to process setcontext_rsp no matter
6205 * what the state is.
6206 */
Srinivas Girigowdae00f73f2017-03-17 14:07:26 -07006207 sme_debug("is not what it intends to. Must be revisit or removed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208 if ((NULL == pSession)
6209 || (csr_is_conn_state_disconnected(pMac, sessionId)
6210 && (pSession->pCurRoamProfile != NULL)
6211 && (!(CSR_IS_INFRA_AP(pSession->pCurRoamProfile))))
6212 ) {
6213 fRet = false;
6214 }
6215
6216 return fRet;
6217}
6218
6219/* no need to acquire lock for this basic function */
6220uint16_t sme_chn_to_freq(uint8_t chanNum)
6221{
6222 int i;
6223
Amar Singhalb8d4f152016-02-10 10:21:43 -08006224 for (i = 0; i < NUM_CHANNELS; i++) {
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006225 if (WLAN_REG_CH_NUM(i) == chanNum)
6226 return WLAN_REG_CH_TO_FREQ(i);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227 }
6228
6229 return 0;
6230}
6231
Jeff Johnson1be200a2018-07-07 10:57:32 -07006232struct lim_channel_status *
6233csr_get_channel_status(tpAniSirGlobal mac, uint32_t channel_id)
gaoleze5108942017-03-31 16:56:42 +08006234{
6235 uint8_t i;
6236 struct lim_scan_channel_status *channel_status;
Jeff Johnson1be200a2018-07-07 10:57:32 -07006237 struct lim_channel_status *entry;
gaoleze5108942017-03-31 16:56:42 +08006238
Jeff Johnson1be200a2018-07-07 10:57:32 -07006239 if (!mac->sap.acs_with_more_param)
gaoleze5108942017-03-31 16:56:42 +08006240 return NULL;
6241
Jeff Johnson1be200a2018-07-07 10:57:32 -07006242 channel_status = &mac->lim.scan_channel_status;
gaoleze5108942017-03-31 16:56:42 +08006243 for (i = 0; i < channel_status->total_channel; i++) {
Jeff Johnson1be200a2018-07-07 10:57:32 -07006244 entry = &channel_status->channel_status_list[i];
6245 if (entry->channel_id == channel_id)
6246 return entry;
gaoleze5108942017-03-31 16:56:42 +08006247 }
Jeff Johnson1be200a2018-07-07 10:57:32 -07006248 sme_err("Channel %d status info not exist", channel_id);
gaoleze5108942017-03-31 16:56:42 +08006249
6250 return NULL;
6251}
6252
Jeff Johnson1be200a2018-07-07 10:57:32 -07006253void csr_clear_channel_status(tpAniSirGlobal mac)
gaoleze5108942017-03-31 16:56:42 +08006254{
gaoleze5108942017-03-31 16:56:42 +08006255 struct lim_scan_channel_status *channel_status;
6256
Jeff Johnson1be200a2018-07-07 10:57:32 -07006257 if (!mac->sap.acs_with_more_param)
gaoleze5108942017-03-31 16:56:42 +08006258 return;
6259
Jeff Johnson1be200a2018-07-07 10:57:32 -07006260 channel_status = &mac->lim.scan_channel_status;
gaoleze5108942017-03-31 16:56:42 +08006261 channel_status->total_channel = 0;
6262
6263 return;
6264}
6265
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266bool csr_is_channel_present_in_list(uint8_t *pChannelList,
6267 int numChannels, uint8_t channel)
6268{
6269 int i = 0;
6270
6271 /* Check for NULL pointer */
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306272 if (!pChannelList || (numChannels == 0))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273 return false;
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306274
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006275 /* Look for the channel in the list */
6276 for (i = 0; (i < numChannels) &&
6277 (i < WNI_CFG_VALID_CHANNEL_LIST_LEN); i++) {
6278 if (pChannelList[i] == channel)
6279 return true;
6280 }
6281
6282 return false;
6283}
6284
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05306285/**
Rajeev Kumar43e25b12016-04-15 16:26:36 -07006286 * sme_bsstype_to_string() - converts bss type to string.
6287 * @bss_type: bss type enum
6288 *
6289 * Return: printable string for bss type
6290 */
6291const char *sme_bss_type_to_string(const uint8_t bss_type)
6292{
6293 switch (bss_type) {
6294 CASE_RETURN_STRING(eCSR_BSS_TYPE_INFRASTRUCTURE);
6295 CASE_RETURN_STRING(eCSR_BSS_TYPE_INFRA_AP);
6296 CASE_RETURN_STRING(eCSR_BSS_TYPE_IBSS);
6297 CASE_RETURN_STRING(eCSR_BSS_TYPE_START_IBSS);
6298 CASE_RETURN_STRING(eCSR_BSS_TYPE_ANY);
6299 default:
6300 return "unknown bss type";
6301 }
6302}
6303
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306304QDF_STATUS csr_add_to_channel_list_front(uint8_t *pChannelList,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305 int numChannels, uint8_t channel)
6306{
6307 int i = 0;
6308
6309 /* Check for NULL pointer */
6310 if (!pChannelList)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306311 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006312
6313 /* Make room for the addition. (Start moving from the back.) */
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306314 for (i = numChannels; i > 0; i--)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315 pChannelList[i] = pChannelList[i - 1];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006316
6317 /* Now add the NEW channel...at the front */
6318 pChannelList[0] = channel;
6319
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306320 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006321}
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05306322
6323/**
6324 * csr_wait_for_connection_update() - Wait for hw mode update
6325 * @mac: Pointer to the MAC context
6326 * @do_release_reacquire_lock: Indicates whether release and
6327 * re-acquisition of SME global lock is required.
6328 *
6329 * Waits for CONNECTION_UPDATE_TIMEOUT time so that the
6330 * hw mode update can get processed.
6331 *
6332 * Return: True if the wait was successful, false otherwise
6333 */
6334bool csr_wait_for_connection_update(tpAniSirGlobal mac,
6335 bool do_release_reacquire_lock)
6336{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306337 QDF_STATUS status, ret;
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05306338
6339 if (do_release_reacquire_lock == true) {
6340 ret = sme_release_global_lock(&mac->sme);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306341 if (!QDF_IS_STATUS_SUCCESS(ret)) {
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05306342 cds_err("lock release fail %d", ret);
6343 return false;
6344 }
6345 }
6346
Tushnim Bhattacharyya0c4ad2d2017-03-09 15:59:03 -08006347 status = policy_mgr_wait_for_connection_update(mac->psoc);
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05306348
6349 if (do_release_reacquire_lock == true) {
6350 ret = sme_acquire_global_lock(&mac->sme);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306351 if (!QDF_IS_STATUS_SUCCESS(ret)) {
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05306352 cds_err("lock acquire fail %d", ret);
6353 return false;
6354 }
6355 }
6356
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306357 if (!QDF_IS_STATUS_SUCCESS(status)) {
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05306358 cds_err("wait for event failed");
6359 return false;
6360 }
6361
6362 return true;
6363}
Peng Xuf5d60c82015-10-02 17:17:03 -07006364
6365/**
6366 * csr_get_session_persona() - get persona of a session
6367 * @pmac: pointer to global MAC context
6368 * @session_id: session id
6369 *
6370 * This function is to return the persona of a session
6371 *
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006372 * Reture: enum QDF_OPMODE persona
Peng Xuf5d60c82015-10-02 17:17:03 -07006373 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006374enum QDF_OPMODE csr_get_session_persona(tpAniSirGlobal pmac,
6375 uint32_t session_id)
Peng Xuf5d60c82015-10-02 17:17:03 -07006376{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05306377 struct csr_roam_session *session = NULL;
Peng Xuf5d60c82015-10-02 17:17:03 -07006378
6379 session = CSR_GET_SESSION(pmac, session_id);
6380 if (NULL == session || NULL == session->pCurRoamProfile)
Anurag Chouhan6d760662016-02-20 16:05:43 +05306381 return QDF_MAX_NO_OF_MODE;
Peng Xuf5d60c82015-10-02 17:17:03 -07006382
6383 return session->pCurRoamProfile->csrPersona;
6384}
Ravi Joshi4f447cb2016-07-19 13:42:01 -07006385
6386/**
6387 * csr_is_ndi_started() - function to check if NDI is started
6388 * @mac_ctx: handle to mac context
6389 * @session_id: session identifier
6390 *
6391 * returns: true if NDI is started, false otherwise
6392 */
6393bool csr_is_ndi_started(tpAniSirGlobal mac_ctx, uint32_t session_id)
6394{
gaurank kathpalia14e2f912017-08-31 14:51:45 +05306395 struct csr_roam_session *session = CSR_GET_SESSION(mac_ctx, session_id);
Nishank Aggarwal9ca32552017-03-31 16:23:26 +05306396
Ravi Joshi4f447cb2016-07-19 13:42:01 -07006397 if (!session)
6398 return false;
6399
6400 return eCSR_CONNECT_STATE_TYPE_NDI_STARTED == session->connectState;
6401}
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05306402
Jeff Johnson9d118852018-06-10 16:54:59 -07006403bool csr_is_mcc_channel(tpAniSirGlobal mac_ctx, uint8_t channel)
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05306404{
Vignesh Viswanathan9dd88d32017-11-22 14:22:03 +05306405 struct csr_roam_session *session;
6406 enum QDF_OPMODE oper_mode;
6407 uint8_t oper_channel = 0;
6408 uint8_t session_id;
6409
6410 if (channel == 0)
6411 return false;
6412
6413 for (session_id = 0; session_id < CSR_ROAM_SESSION_MAX; session_id++) {
6414 if (CSR_IS_SESSION_VALID(mac_ctx, session_id)) {
6415 session = CSR_GET_SESSION(mac_ctx, session_id);
6416 if (NULL == session->pCurRoamProfile)
6417 continue;
6418 oper_mode = session->pCurRoamProfile->csrPersona;
6419 if ((((oper_mode == QDF_STA_MODE) ||
6420 (oper_mode == QDF_P2P_CLIENT_MODE)) &&
6421 (session->connectState ==
6422 eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED)) ||
6423 (((oper_mode == QDF_P2P_GO_MODE) ||
6424 (oper_mode == QDF_SAP_MODE))
6425 && (session->connectState !=
6426 eCSR_ASSOC_STATE_TYPE_NOT_CONNECTED)))
6427 oper_channel = session->connectedProfile.
6428 operationChannel;
6429
6430 if (oper_channel && channel != oper_channel &&
6431 (!policy_mgr_is_hw_dbs_capable(mac_ctx->psoc) ||
6432 WLAN_REG_IS_SAME_BAND_CHANNELS(channel,
6433 oper_channel)))
6434 return true;
6435 }
6436 }
6437
6438 return false;
6439}
6440