blob: bbcecf077bec065145b1e9da53fb5e8dcbe03e40 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Abhishek Singh7996eb72015-12-30 17:24:02 +05302 * Copyright (c) 2011-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/** ------------------------------------------------------------------------- *
29 ------------------------------------------------------------------------- *
30
31 \file csr_util.c
32
33 Implementation supporting routines for CSR.
34 ========================================================================== */
35
36#include "ani_global.h"
37
38#include "csr_support.h"
39#include "csr_inside_api.h"
40#include "sms_debug.h"
41#include "sme_qos_internal.h"
42#include "wma_types.h"
43#include "cds_utils.h"
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +053044#include "cds_concurrency.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080045
46
47uint8_t csr_wpa_oui[][CSR_WPA_OUI_SIZE] = {
48 {0x00, 0x50, 0xf2, 0x00}
49 ,
50 {0x00, 0x50, 0xf2, 0x01}
51 ,
52 {0x00, 0x50, 0xf2, 0x02}
53 ,
54 {0x00, 0x50, 0xf2, 0x03}
55 ,
56 {0x00, 0x50, 0xf2, 0x04}
57 ,
58 {0x00, 0x50, 0xf2, 0x05}
59 ,
60#ifdef FEATURE_WLAN_ESE
61 {0x00, 0x40, 0x96, 0x00}
62 , /* CCKM */
63#endif /* FEATURE_WLAN_ESE */
64};
65
66uint8_t csr_rsn_oui[][CSR_RSN_OUI_SIZE] = {
67 {0x00, 0x0F, 0xAC, 0x00}
68 , /* group cipher */
69 {0x00, 0x0F, 0xAC, 0x01}
70 , /* WEP-40 or RSN */
71 {0x00, 0x0F, 0xAC, 0x02}
72 , /* TKIP or RSN-PSK */
73 {0x00, 0x0F, 0xAC, 0x03}
74 , /* Reserved */
75 {0x00, 0x0F, 0xAC, 0x04}
76 , /* AES-CCMP */
77 {0x00, 0x0F, 0xAC, 0x05}
78 , /* WEP-104 */
79 {0x00, 0x40, 0x96, 0x00}
80 , /* CCKM */
81 {0x00, 0x0F, 0xAC, 0x06}
82 , /* BIP (encryption type) or
83 RSN-PSK-SHA256 (authentication type) */
84 /* RSN-8021X-SHA256 (authentication type) */
85 {0x00, 0x0F, 0xAC, 0x05}
86};
87
88#ifdef FEATURE_WLAN_WAPI
89uint8_t csr_wapi_oui[][CSR_WAPI_OUI_SIZE] = {
90 {0x00, 0x14, 0x72, 0x00}
91 , /* Reserved */
92 {0x00, 0x14, 0x72, 0x01}
93 , /* WAI certificate or SMS4 */
94 {0x00, 0x14, 0x72, 0x02} /* WAI PSK */
95};
96#endif /* FEATURE_WLAN_WAPI */
97uint8_t csr_wme_info_oui[CSR_WME_OUI_SIZE] = { 0x00, 0x50, 0xf2, 0x02 };
98uint8_t csr_wme_parm_oui[CSR_WME_OUI_SIZE] = { 0x00, 0x50, 0xf2, 0x02 };
99
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100/* ////////////////////////////////////////////////////////////////////// */
101
102/**
103 * \var g_phy_rates_suppt
104 *
105 * \brief Rate support lookup table
106 *
107 *
108 * This is a lookup table indexing rates & configuration parameters to
109 * support. Given a rate (in unites of 0.5Mpbs) & three bools (MIMO
110 * Enabled, Channel Bonding Enabled, & Concatenation Enabled), one can
111 * determine whether the given rate is supported by computing two
112 * indices. The first maps the rate to table row as indicated below
113 * (i.e. eHddSuppRate_6Mbps maps to row zero, eHddSuppRate_9Mbps to row
114 * 1, and so on). Index two can be computed like so:
115 *
116 * \code
117 * idx2 = ( fEsf ? 0x4 : 0x0 ) |
118 * ( fCb ? 0x2 : 0x0 ) |
119 * ( fMimo ? 0x1 : 0x0 );
120 * \endcode
121 *
122 *
123 * Given that:
124 *
125 * \code
126 * fSupported = g_phy_rates_suppt[idx1][idx2];
127 * \endcode
128 *
129 *
130 * This table is based on the document "PHY Supported Rates.doc". This
131 * table is permissive in that a rate is reflected as being supported
132 * even when turning off an enabled feature would be required. For
133 * instance, "PHY Supported Rates" lists 42Mpbs as unsupported when CB,
134 * ESF, & MIMO are all on. However, if we turn off either of CB or
135 * MIMO, it then becomes supported. Therefore, we mark it as supported
136 * even in index 7 of this table.
137 *
138 *
139 */
140
141static const bool g_phy_rates_suppt[24][8] = {
142
143 /* SSF SSF SSF SSF ESF ESF ESF ESF */
144 /* SIMO MIMO SIMO MIMO SIMO MIMO SIMO MIMO */
145 /* No CB No CB CB CB No CB No CB CB CB */
146 {true, true, true, true, true, true, true, true}, /* 6Mbps */
147 {true, true, true, true, true, true, true, true}, /* 9Mbps */
148 {true, true, true, true, true, true, true, true}, /* 12Mbps */
149 {true, true, true, true, true, true, true, true}, /* 18Mbps */
150 {false, false, true, true, false, false, true, true}, /* 20Mbps */
151 {true, true, true, true, true, true, true, true}, /* 24Mbps */
152 {true, true, true, true, true, true, true, true}, /* 36Mbps */
153 {false, false, true, true, false, true, true, true}, /* 40Mbps */
154 {false, false, true, true, false, true, true, true}, /* 42Mbps */
155 {true, true, true, true, true, true, true, true}, /* 48Mbps */
156 {true, true, true, true, true, true, true, true}, /* 54Mbps */
157 {false, true, true, true, false, true, true, true}, /* 72Mbps */
158 {false, false, true, true, false, true, true, true}, /* 80Mbps */
159 {false, false, true, true, false, true, true, true}, /* 84Mbps */
160 {false, true, true, true, false, true, true, true}, /* 96Mbps */
161 {false, true, true, true, false, true, true, true}, /* 108Mbps */
162 {false, false, true, true, false, true, true, true}, /* 120Mbps */
163 {false, false, true, true, false, true, true, true}, /* 126Mbps */
164 {false, false, false, true, false, false, false, true}, /* 144Mbps */
165 {false, false, false, true, false, false, false, true}, /* 160Mbps */
166 {false, false, false, true, false, false, false, true}, /* 168Mbps */
167 {false, false, false, true, false, false, false, true}, /* 192Mbps */
168 {false, false, false, true, false, false, false, true}, /* 216Mbps */
169 {false, false, false, true, false, false, false, true}, /* 240Mbps */
170
171};
172
173#define CASE_RETURN_STR(n) {\
174 case (n): return (# n);\
175}
176
177const char *get_e_roam_cmd_status_str(eRoamCmdStatus val)
178{
179 switch (val) {
180 CASE_RETURN_STR(eCSR_ROAM_CANCELLED);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530181 CASE_RETURN_STR(eCSR_ROAM_FAILED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182 CASE_RETURN_STR(eCSR_ROAM_ROAMING_START);
183 CASE_RETURN_STR(eCSR_ROAM_ROAMING_COMPLETION);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530184 CASE_RETURN_STR(eCSR_ROAM_CONNECT_COMPLETION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185 CASE_RETURN_STR(eCSR_ROAM_ASSOCIATION_START);
186 CASE_RETURN_STR(eCSR_ROAM_ASSOCIATION_COMPLETION);
187 CASE_RETURN_STR(eCSR_ROAM_DISASSOCIATED);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530188 CASE_RETURN_STR(eCSR_ROAM_ASSOCIATION_FAILURE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189 CASE_RETURN_STR(eCSR_ROAM_SHOULD_ROAM);
190 CASE_RETURN_STR(eCSR_ROAM_SCAN_FOUND_NEW_BSS);
191 CASE_RETURN_STR(eCSR_ROAM_LOSTLINK);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530192 CASE_RETURN_STR(eCSR_ROAM_LOSTLINK_DETECTED);
193 CASE_RETURN_STR(eCSR_ROAM_MIC_ERROR_IND);
194 CASE_RETURN_STR(eCSR_ROAM_IBSS_IND);
195 CASE_RETURN_STR(eCSR_ROAM_CONNECT_STATUS_UPDATE);
196 CASE_RETURN_STR(eCSR_ROAM_GEN_INFO);
197 CASE_RETURN_STR(eCSR_ROAM_SET_KEY_COMPLETE);
198 CASE_RETURN_STR(eCSR_ROAM_IBSS_LEAVE);
199 CASE_RETURN_STR(eCSR_ROAM_INFRA_IND);
200 CASE_RETURN_STR(eCSR_ROAM_WPS_PBC_PROBE_REQ_IND);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530201 CASE_RETURN_STR(eCSR_ROAM_FT_RESPONSE);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530202 CASE_RETURN_STR(eCSR_ROAM_FT_START);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530203 CASE_RETURN_STR(eCSR_ROAM_REMAIN_CHAN_READY);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530204 CASE_RETURN_STR(eCSR_ROAM_SESSION_OPENED);
205 CASE_RETURN_STR(eCSR_ROAM_FT_REASSOC_FAILED);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530206 CASE_RETURN_STR(eCSR_ROAM_PMK_NOTIFY);
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530207#ifdef FEATURE_WLAN_LFR_METRICS
208 CASE_RETURN_STR(eCSR_ROAM_PREAUTH_INIT_NOTIFY);
209 CASE_RETURN_STR(eCSR_ROAM_PREAUTH_STATUS_SUCCESS);
210 CASE_RETURN_STR(eCSR_ROAM_PREAUTH_STATUS_FAILURE);
211 CASE_RETURN_STR(eCSR_ROAM_HANDOVER_SUCCESS);
212#endif
213#ifdef FEATURE_WLAN_TDLS
214 CASE_RETURN_STR(eCSR_ROAM_TDLS_STATUS_UPDATE);
215 CASE_RETURN_STR(eCSR_ROAM_RESULT_MGMT_TX_COMPLETE_IND);
216#endif
217 CASE_RETURN_STR(eCSR_ROAM_DISCONNECT_ALL_P2P_CLIENTS);
218 CASE_RETURN_STR(eCSR_ROAM_SEND_P2P_STOP_BSS);
219#ifdef WLAN_FEATURE_11W
220 CASE_RETURN_STR(eCSR_ROAM_UNPROT_MGMT_FRAME_IND);
221#endif
222#ifdef WLAN_FEATURE_RMC
223 CASE_RETURN_STR(eCSR_ROAM_IBSS_PEER_INFO_COMPLETE);
224#endif
Srinivas Girigowda515a9ef2015-12-11 11:00:48 -0800225#ifdef FEATURE_WLAN_ESE
Sreelakshmi Konamkic88f5372015-12-22 12:50:15 +0530226 CASE_RETURN_STR(eCSR_ROAM_TSM_IE_IND);
227 CASE_RETURN_STR(eCSR_ROAM_CCKM_PREAUTH_NOTIFY);
228 CASE_RETURN_STR(eCSR_ROAM_ESE_ADJ_AP_REPORT_IND);
229 CASE_RETURN_STR(eCSR_ROAM_ESE_BCN_REPORT_IND);
Srinivas Girigowda515a9ef2015-12-11 11:00:48 -0800230#endif /* FEATURE_WLAN_ESE */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231 default:
232 return "unknown";
233 }
234}
235
236const char *get_e_csr_roam_result_str(eCsrRoamResult val)
237{
238 switch (val) {
239 CASE_RETURN_STR(eCSR_ROAM_RESULT_NONE);
240 CASE_RETURN_STR(eCSR_ROAM_RESULT_FAILURE);
241 CASE_RETURN_STR(eCSR_ROAM_RESULT_ASSOCIATED);
242 CASE_RETURN_STR(eCSR_ROAM_RESULT_NOT_ASSOCIATED);
243 CASE_RETURN_STR(eCSR_ROAM_RESULT_MIC_FAILURE);
244 CASE_RETURN_STR(eCSR_ROAM_RESULT_FORCED);
245 CASE_RETURN_STR(eCSR_ROAM_RESULT_DISASSOC_IND);
246 CASE_RETURN_STR(eCSR_ROAM_RESULT_DEAUTH_IND);
247 CASE_RETURN_STR(eCSR_ROAM_RESULT_CAP_CHANGED);
248 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_CONNECT);
249 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_INACTIVE);
250 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_NEW_PEER);
251 CASE_RETURN_STR(eCSR_ROAM_RESULT_IBSS_COALESCED);
252 default:
253 return "unknown";
254 }
255}
256
257bool csr_get_bss_id_bss_desc(tHalHandle hHal, tSirBssDescription *pSirBssDesc,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530258 struct qdf_mac_addr *pBssId)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800259{
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530260 qdf_mem_copy(pBssId, &pSirBssDesc->bssId[0],
Anurag Chouhan6d760662016-02-20 16:05:43 +0530261 sizeof(struct qdf_mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262 return true;
263}
264
265bool csr_is_bss_id_equal(tHalHandle hHal, tSirBssDescription *pSirBssDesc1,
266 tSirBssDescription *pSirBssDesc2)
267{
268 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
269 bool fEqual = false;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530270 struct qdf_mac_addr bssId1;
271 struct qdf_mac_addr bssId2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800272
273 do {
274 if (!pSirBssDesc1)
275 break;
276 if (!pSirBssDesc2)
277 break;
278
279 if (!csr_get_bss_id_bss_desc(pMac, pSirBssDesc1, &bssId1))
280 break;
281 if (!csr_get_bss_id_bss_desc(pMac, pSirBssDesc2, &bssId2))
282 break;
283
Anurag Chouhanc5548422016-02-24 18:33:27 +0530284 fEqual = qdf_is_macaddr_equal(&bssId1, &bssId2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800285 } while (0);
286
287 return fEqual;
288}
289
290bool csr_is_conn_state_connected_ibss(tpAniSirGlobal pMac, uint32_t sessionId)
291{
292 return eCSR_ASSOC_STATE_TYPE_IBSS_CONNECTED ==
293 pMac->roam.roamSession[sessionId].connectState;
294}
295
296bool csr_is_conn_state_disconnected_ibss(tpAniSirGlobal pMac,
297 uint32_t sessionId)
298{
299 return eCSR_ASSOC_STATE_TYPE_IBSS_DISCONNECTED ==
300 pMac->roam.roamSession[sessionId].connectState;
301}
302
303bool csr_is_conn_state_connected_infra(tpAniSirGlobal pMac, uint32_t sessionId)
304{
305 return eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED ==
306 pMac->roam.roamSession[sessionId].connectState;
307}
308
309bool csr_is_conn_state_connected(tpAniSirGlobal pMac, uint32_t sessionId)
310{
311 if (csr_is_conn_state_connected_ibss(pMac, sessionId)
312 || csr_is_conn_state_connected_infra(pMac, sessionId)
313 || csr_is_conn_state_connected_wds(pMac, sessionId))
314 return true;
315 else
316 return false;
317}
318
319bool csr_is_conn_state_infra(tpAniSirGlobal pMac, uint32_t sessionId)
320{
321 return csr_is_conn_state_connected_infra(pMac, sessionId);
322}
323
324bool csr_is_conn_state_ibss(tpAniSirGlobal pMac, uint32_t sessionId)
325{
326 return csr_is_conn_state_connected_ibss(pMac, sessionId) ||
327 csr_is_conn_state_disconnected_ibss(pMac, sessionId);
328}
329
330bool csr_is_conn_state_connected_wds(tpAniSirGlobal pMac, uint32_t sessionId)
331{
332 return eCSR_ASSOC_STATE_TYPE_WDS_CONNECTED ==
333 pMac->roam.roamSession[sessionId].connectState;
334}
335
336bool csr_is_conn_state_connected_infra_ap(tpAniSirGlobal pMac,
337 uint32_t sessionId)
338{
339 return (eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED ==
340 pMac->roam.roamSession[sessionId].connectState) ||
341 (eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTED ==
342 pMac->roam.roamSession[sessionId].connectState);
343}
344
345bool csr_is_conn_state_disconnected_wds(tpAniSirGlobal pMac, uint32_t sessionId)
346{
347 return eCSR_ASSOC_STATE_TYPE_WDS_DISCONNECTED ==
348 pMac->roam.roamSession[sessionId].connectState;
349}
350
351bool csr_is_conn_state_wds(tpAniSirGlobal pMac, uint32_t sessionId)
352{
353 return csr_is_conn_state_connected_wds(pMac, sessionId) ||
354 csr_is_conn_state_disconnected_wds(pMac, sessionId);
355}
356
357bool csr_is_conn_state_ap(tpAniSirGlobal pMac, uint32_t sessionId)
358{
359 tCsrRoamSession *pSession;
360 pSession = CSR_GET_SESSION(pMac, sessionId);
361 if (!pSession)
362 return false;
363 if (CSR_IS_INFRA_AP(&pSession->connectedProfile))
364 return true;
365 return false;
366}
367
368bool csr_is_any_session_in_connect_state(tpAniSirGlobal pMac)
369{
370 uint32_t i;
371 bool fRc = false;
372
373 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
374 if (CSR_IS_SESSION_VALID(pMac, i) &&
375 (csr_is_conn_state_infra(pMac, i)
376 || csr_is_conn_state_ibss(pMac, i)
377 || csr_is_conn_state_ap(pMac, i))) {
378 fRc = true;
379 break;
380 }
381 }
382
383 return fRc;
384}
385
386int8_t csr_get_infra_session_id(tpAniSirGlobal pMac)
387{
388 uint8_t i;
389 int8_t sessionid = -1;
390
391 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
392 if (CSR_IS_SESSION_VALID(pMac, i)
393 && csr_is_conn_state_infra(pMac, i)) {
394 sessionid = i;
395 break;
396 }
397 }
398
399 return sessionid;
400}
401
402uint8_t csr_get_infra_operation_channel(tpAniSirGlobal pMac, uint8_t sessionId)
403{
404 uint8_t channel;
405
406 if (CSR_IS_SESSION_VALID(pMac, sessionId)) {
407 channel =
408 pMac->roam.roamSession[sessionId].connectedProfile.
409 operationChannel;
410 } else {
411 channel = 0;
412 }
413 return channel;
414}
415
416bool csr_is_session_client_and_connected(tpAniSirGlobal pMac, uint8_t sessionId)
417{
418 tCsrRoamSession *pSession = NULL;
419 if (CSR_IS_SESSION_VALID(pMac, sessionId)
420 && csr_is_conn_state_infra(pMac, sessionId)) {
421 pSession = CSR_GET_SESSION(pMac, sessionId);
422 if (NULL != pSession->pCurRoamProfile) {
423 if ((pSession->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530424 QDF_STA_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800425 || (pSession->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530426 QDF_P2P_CLIENT_MODE))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427 return true;
428 }
429 }
430 return false;
431}
432
433/**
434 * csr_get_concurrent_operation_channel() - To get concurrent operating channel
435 * @mac_ctx: Pointer to mac context
436 *
437 * This routine will return operating channel on FIRST BSS that is
438 * active/operating to be used for concurrency mode.
439 * If other BSS is not up or not connected it will return 0
440 *
441 * Return: uint8_t
442 */
443uint8_t csr_get_concurrent_operation_channel(tpAniSirGlobal mac_ctx)
444{
445 tCsrRoamSession *session = NULL;
446 uint8_t i = 0;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530447 enum tQDF_ADAPTER_MODE persona;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448
449 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
450 if (!CSR_IS_SESSION_VALID(mac_ctx, i))
451 continue;
452 session = CSR_GET_SESSION(mac_ctx, i);
453 if (NULL == session->pCurRoamProfile)
454 continue;
455 persona = session->pCurRoamProfile->csrPersona;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530456 if ((((persona == QDF_STA_MODE) ||
457 (persona == QDF_P2P_CLIENT_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800458 (session->connectState ==
459 eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED)) ||
Anurag Chouhan6d760662016-02-20 16:05:43 +0530460 (((persona == QDF_P2P_GO_MODE) ||
461 (persona == QDF_SAP_MODE))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800462 && (session->connectState !=
463 eCSR_ASSOC_STATE_TYPE_NOT_CONNECTED)))
464 return session->connectedProfile.operationChannel;
465
466 }
467 return 0;
468}
469
470#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
471
472#define HALF_BW_OF(eCSR_bw_val) ((eCSR_bw_val)/2)
473
474/* calculation of center channel based on V/HT BW and WIFI channel bw=5MHz) */
475
476#define CSR_GET_HT40_PLUS_CCH(och) ((och)+2)
477#define CSR_GET_HT40_MINUS_CCH(och) ((och)-2)
478
479#define CSR_GET_HT80_PLUS_LL_CCH(och) ((och)+6)
480#define CSR_GET_HT80_PLUS_HL_CCH(och) ((och)+2)
481#define CSR_GET_HT80_MINUS_LH_CCH(och) ((och)-2)
482#define CSR_GET_HT80_MINUS_HH_CCH(och) ((och)-6)
483
484/**
485 * csr_get_ch_from_ht_profile() - to get channel from HT profile
486 * @pMac: pointer to Mac context
487 * @htp: pointer to HT profile
488 * @och: operating channel
489 * @cfreq: channel frequency
490 * @hbw: half bandwidth
491 *
492 * This function will fill half bandwidth and channel frequency based
493 * on the HT profile
494 *
495 * Return: none
496 */
497void csr_get_ch_from_ht_profile(tpAniSirGlobal pMac, tCsrRoamHTProfile *htp,
498 uint16_t och, uint16_t *cfreq, uint16_t *hbw)
499{
500 uint16_t cch, ch_bond;
501
502 if (och > 14)
503 ch_bond = pMac->roam.configParam.channelBondingMode5GHz;
504 else
505 ch_bond = pMac->roam.configParam.channelBondingMode24GHz;
506
507 cch = och;
508 *hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
509
510 if (!ch_bond)
511 goto ret;
512
513 sms_log(pMac, LOG1, FL("##HTC: %d scbw: %d rcbw: %d sco: %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514 "VHTC: %d apc: %d apbw: %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800515 ),
516 htp->htCapability, htp->htSupportedChannelWidthSet,
517 htp->htRecommendedTxWidthSet,
518 htp->htSecondaryChannelOffset,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800519 htp->vhtCapability, htp->apCenterChan, htp->apChanWidth
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520 );
521
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800522 if (htp->vhtCapability) {
523 cch = htp->apCenterChan;
524 if (htp->apChanWidth == WNI_CFG_VHT_CHANNEL_WIDTH_80MHZ)
525 *hbw = HALF_BW_OF(eCSR_BW_80MHz_VAL);
526 else if (htp->apChanWidth == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
527 *hbw = HALF_BW_OF(eCSR_BW_160MHz_VAL);
528
529 if (!*hbw && htp->htCapability) {
530 if (htp->htSupportedChannelWidthSet ==
531 eHT_CHANNEL_WIDTH_40MHZ)
532 *hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
533 else
534 *hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
535 }
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -0800536 } else if (htp->htCapability) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800537 if (htp->htSupportedChannelWidthSet ==
538 eHT_CHANNEL_WIDTH_40MHZ) {
539 *hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
540 if (htp->htSecondaryChannelOffset ==
541 PHY_DOUBLE_CHANNEL_LOW_PRIMARY)
542 cch = CSR_GET_HT40_PLUS_CCH(och);
543 else if (htp->htSecondaryChannelOffset ==
544 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY)
545 cch = CSR_GET_HT40_MINUS_CCH(och);
546 } else {
547 cch = och;
548 *hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
549 }
550 }
551
552ret:
553 *cfreq = cds_chan_to_freq(cch);
554 return;
555}
556
557/**
558 * csr_calc_chb_for_sap_phymode() - to calc channel bandwidth for sap phymode
559 * @mac_ctx: pointer to mac context
560 * @sap_ch: SAP operating channel
561 * @sap_phymode: SAP physical mode
562 * @sap_cch: concurrency channel
563 * @sap_hbw: SAP half bw
564 * @chb: channel bandwidth
565 *
566 * This routine is called to calculate channel bandwidth
567 *
568 * Return: none
569 */
570static void csr_calc_chb_for_sap_phymode(tpAniSirGlobal mac_ctx,
571 uint16_t *sap_ch, eCsrPhyMode *sap_phymode,
572 uint16_t *sap_cch, uint16_t *sap_hbw, uint8_t *chb)
573{
574 if (*sap_phymode == eCSR_DOT11_MODE_11n ||
575 *sap_phymode == eCSR_DOT11_MODE_11n_ONLY) {
576
577 *sap_hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
578 if (*chb == PHY_DOUBLE_CHANNEL_LOW_PRIMARY)
579 *sap_cch = CSR_GET_HT40_PLUS_CCH(*sap_ch);
580 else if (*chb == PHY_DOUBLE_CHANNEL_HIGH_PRIMARY)
581 *sap_cch = CSR_GET_HT40_MINUS_CCH(*sap_ch);
582
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -0800583 } else if (*sap_phymode == eCSR_DOT11_MODE_11ac ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584 *sap_phymode == eCSR_DOT11_MODE_11ac_ONLY) {
585 /*11AC only 80/40/20 Mhz supported in Rome */
586 if (mac_ctx->roam.configParam.nVhtChannelWidth ==
587 (WNI_CFG_VHT_CHANNEL_WIDTH_80MHZ + 1)) {
588 *sap_hbw = HALF_BW_OF(eCSR_BW_80MHz_VAL);
589 if (*chb ==
590 (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW - 1))
591 *sap_cch = CSR_GET_HT80_PLUS_LL_CCH(*sap_ch);
592 else if (*chb ==
593 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW
594 - 1))
595 *sap_cch = CSR_GET_HT80_PLUS_HL_CCH(*sap_ch);
596 else if (*chb ==
597 (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH
598 - 1))
599 *sap_cch = CSR_GET_HT80_MINUS_LH_CCH(*sap_ch);
600 else if (*chb ==
601 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH
602 - 1))
603 *sap_cch = CSR_GET_HT80_MINUS_HH_CCH(*sap_ch);
604 } else {
605 *sap_hbw = HALF_BW_OF(eCSR_BW_40MHz_VAL);
606 if (*chb == (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW
607 - 1))
608 *sap_cch = CSR_GET_HT40_PLUS_CCH(*sap_ch);
609 else if (*chb ==
610 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW
611 - 1))
612 *sap_cch = CSR_GET_HT40_MINUS_CCH(*sap_ch);
613 else if (*chb ==
614 (PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH
615 - 1))
616 *sap_cch = CSR_GET_HT40_PLUS_CCH(*sap_ch);
617 else if (*chb ==
618 (PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH
619 - 1))
620 *sap_cch = CSR_GET_HT40_MINUS_CCH(*sap_ch);
621 }
622 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623}
624
625/**
626 * csr_handle_conc_chnl_overlap_for_sap_go - To handle overlap for AP+AP
627 * @mac_ctx: pointer to mac context
628 * @session: Current session
629 * @sap_ch: SAP/GO operating channel
630 * @sap_hbw: SAP/GO half bw
631 * @sap_cfreq: SAP/GO channel frequency
632 * @intf_ch: concurrent SAP/GO operating channel
633 * @intf_hbw: concurrent SAP/GO half bw
634 * @intf_cfreq: concurrent SAP/GO channel frequency
635 *
636 * This routine is called to check if one SAP/GO channel is overlapping with
637 * other SAP/GO channel
638 *
639 * Return: none
640 */
641static void csr_handle_conc_chnl_overlap_for_sap_go(tpAniSirGlobal mac_ctx,
642 tCsrRoamSession *session,
643 uint16_t *sap_ch, uint16_t *sap_hbw, uint16_t *sap_cfreq,
644 uint16_t *intf_ch, uint16_t *intf_hbw, uint16_t *intf_cfreq)
645{
646 /*
647 * if conc_custom_rule1 is defined then we don't
648 * want p2pgo to follow SAP's channel or SAP to
649 * follow P2PGO's channel.
650 */
651 if (0 == mac_ctx->roam.configParam.conc_custom_rule1 &&
652 0 == mac_ctx->roam.configParam.conc_custom_rule2) {
653 if (*sap_ch == 0) {
654 *sap_ch = session->connectedProfile.operationChannel;
655 csr_get_ch_from_ht_profile(mac_ctx,
656 &session->connectedProfile.HTProfile,
657 *sap_ch, sap_cfreq, sap_hbw);
658 } else if (*sap_ch !=
659 session->connectedProfile.operationChannel) {
660 *intf_ch = session->connectedProfile.operationChannel;
661 csr_get_ch_from_ht_profile(mac_ctx,
662 &session->connectedProfile.HTProfile,
663 *intf_ch, intf_cfreq, intf_hbw);
664 }
665 } else if (*sap_ch == 0 &&
666 (session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530667 QDF_SAP_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668 *sap_ch = session->connectedProfile.operationChannel;
669 csr_get_ch_from_ht_profile(mac_ctx,
670 &session->connectedProfile.HTProfile,
671 *sap_ch, sap_cfreq, sap_hbw);
672 }
673}
674
675
676/**
677 * csr_check_concurrent_channel_overlap() - To check concurrent overlap chnls
678 * @mac_ctx: Pointer to mac context
679 * @sap_ch: SAP channel
680 * @sap_phymode: SAP phy mode
681 * @cc_switch_mode: concurrent switch mode
682 *
683 * This routine will be called to check concurrent overlap channels
684 *
685 * Return: uint16_t
686 */
687uint16_t csr_check_concurrent_channel_overlap(tpAniSirGlobal mac_ctx,
688 uint16_t sap_ch, eCsrPhyMode sap_phymode,
689 uint8_t cc_switch_mode)
690{
691 tCsrRoamSession *session = NULL;
692 uint8_t i = 0, chb = PHY_SINGLE_CHANNEL_CENTERED;
693 uint16_t intf_ch = 0, sap_hbw = 0, intf_hbw = 0, intf_cfreq = 0;
694 uint16_t sap_cfreq = 0;
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +0530695 uint16_t sap_lfreq, sap_hfreq, intf_lfreq, intf_hfreq, sap_cch = 0;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +0530696 QDF_STATUS status;
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +0530697
698 sms_log(mac_ctx, LOG1, FL("sap_ch:%d sap_phymode:%d"),
699 sap_ch, sap_phymode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800700
701 if (mac_ctx->roam.configParam.cc_switch_mode ==
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530702 QDF_MCC_TO_SCC_SWITCH_DISABLE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800703 return 0;
704
705 if (sap_ch != 0) {
706 sap_cch = sap_ch;
707 sap_hbw = HALF_BW_OF(eCSR_BW_20MHz_VAL);
708
709 if (sap_ch > 14)
710 chb = mac_ctx->roam.configParam.channelBondingMode5GHz;
711 else
712 chb = mac_ctx->roam.configParam.channelBondingMode24GHz;
713
714 if (chb)
715 csr_calc_chb_for_sap_phymode(mac_ctx, &sap_ch,
716 &sap_phymode, &sap_cch, &sap_hbw, &chb);
717 sap_cfreq = cds_chan_to_freq(sap_cch);
718 }
719
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +0530720 sms_log(mac_ctx, LOG1,
721 FL("sap_ch:%d sap_phymode:%d sap_cch:%d sap_hbw:%d chb:%d"),
722 sap_ch, sap_phymode, sap_cch, sap_hbw, chb);
723
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
725 if (!CSR_IS_SESSION_VALID(mac_ctx, i))
726 continue;
727
728 session = CSR_GET_SESSION(mac_ctx, i);
729 if (NULL == session->pCurRoamProfile)
730 continue;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530731 if (((session->pCurRoamProfile->csrPersona == QDF_STA_MODE) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800732 (session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530733 QDF_P2P_CLIENT_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800734 (session->connectState ==
735 eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED)) {
736 intf_ch = session->connectedProfile.operationChannel;
737 csr_get_ch_from_ht_profile(mac_ctx,
738 &session->connectedProfile.HTProfile,
739 intf_ch, &intf_cfreq, &intf_hbw);
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +0530740 sms_log(mac_ctx, LOG1,
741 FL("%d: intf_ch:%d intf_cfreq:%d intf_hbw:%d"),
742 i, intf_ch, intf_cfreq, intf_hbw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743 } else if (((session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530744 QDF_P2P_GO_MODE) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 (session->pCurRoamProfile->csrPersona ==
Anurag Chouhan6d760662016-02-20 16:05:43 +0530746 QDF_SAP_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 (session->connectState !=
748 eCSR_ASSOC_STATE_TYPE_NOT_CONNECTED)) {
Manikandan Mohan22b83722015-12-15 15:03:23 -0800749 if (session->ch_switch_in_progress)
Edhar, Mahesh Kumardf2ec122015-11-16 11:33:16 +0530750 continue;
751
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800752 csr_handle_conc_chnl_overlap_for_sap_go(mac_ctx,
753 session, &sap_ch, &sap_hbw, &sap_cfreq,
754 &intf_ch, &intf_hbw, &intf_cfreq);
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +0530755
756 sms_log(mac_ctx, LOG1,
757 FL("%d: sap_ch:%d sap_hbw:%d sap_cfreq:%d intf_ch:%d intf_hbw:%d, intf_cfreq:%d"),
758 i, sap_ch, sap_hbw, sap_cfreq,
759 intf_ch, intf_hbw, intf_cfreq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760 }
761 }
762
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +0530763 sms_log(mac_ctx, LOG1,
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +0530764 FL("intf_ch:%d sap_ch:%d cc_switch_mode:%d"),
765 intf_ch, sap_ch, cc_switch_mode);
Chandrasekaran Manishekar068e25e2016-03-07 11:51:07 +0530766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767 if (intf_ch && sap_ch != intf_ch &&
Chandrasekaran Manishekarcde33d72016-04-14 19:03:39 +0530768 cc_switch_mode != QDF_MCC_TO_SCC_SWITCH_FORCE &&
769 cc_switch_mode !=
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +0530770 QDF_MCC_TO_SCC_SWITCH_FORCE_WITHOUT_DISCONNECTION &&
771 cc_switch_mode !=
772 QDF_MCC_TO_SCC_SWITCH_WITH_FAVORITE_CHANNEL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800773 sap_lfreq = sap_cfreq - sap_hbw;
774 sap_hfreq = sap_cfreq + sap_hbw;
775 intf_lfreq = intf_cfreq - intf_hbw;
776 intf_hfreq = intf_cfreq + intf_hbw;
777
778 sms_log(mac_ctx, LOGE,
779 FL("\nSAP: OCH: %03d OCF: %d CCH: %03d CF: %d BW: %d LF: %d HF: %d\n"
780 "INTF: OCH: %03d OCF: %d CCH: %03d CF: %d BW: %d LF: %d HF: %d"),
781 sap_ch, cds_chan_to_freq(sap_ch),
782 cds_freq_to_chan(sap_cfreq), sap_cfreq, sap_hbw * 2,
783 sap_lfreq, sap_hfreq, intf_ch,
784 cds_chan_to_freq(intf_ch), cds_freq_to_chan(intf_cfreq),
785 intf_cfreq, intf_hbw * 2, intf_lfreq, intf_hfreq);
786
787 if (!(((sap_lfreq > intf_lfreq && sap_lfreq < intf_hfreq) ||
788 (sap_hfreq > intf_lfreq && sap_hfreq < intf_hfreq)) ||
789 ((intf_lfreq > sap_lfreq && intf_lfreq < sap_hfreq) ||
790 (intf_hfreq > sap_lfreq && intf_hfreq < sap_hfreq))))
791 intf_ch = 0;
792 } else if (intf_ch && sap_ch != intf_ch &&
Manishekar Chandrasekaranf21b3b62016-05-02 16:33:55 +0530793 ((cc_switch_mode == QDF_MCC_TO_SCC_SWITCH_FORCE) ||
794 (cc_switch_mode ==
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +0530795 QDF_MCC_TO_SCC_SWITCH_FORCE_WITHOUT_DISCONNECTION) ||
796 (cc_switch_mode ==
797 QDF_MCC_TO_SCC_SWITCH_WITH_FAVORITE_CHANNEL))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800798 if (!((intf_ch < 14 && sap_ch < 14) ||
799 (intf_ch > 14 && sap_ch > 14)))
800 intf_ch = 0;
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +0530801 else if (cc_switch_mode ==
802 QDF_MCC_TO_SCC_SWITCH_WITH_FAVORITE_CHANNEL) {
803 status =
804 cds_get_sap_mandatory_channel((uint32_t *)&intf_ch);
805 if (QDF_IS_STATUS_ERROR(status)) {
806 sms_log(mac_ctx, LOGE,
807 FL("no mandatory channel"));
808 intf_ch = sap_ch;
809 }
810 }
811 } else if ((intf_ch == sap_ch) && (cc_switch_mode ==
812 QDF_MCC_TO_SCC_SWITCH_WITH_FAVORITE_CHANNEL)) {
813 if (cds_chan_to_band(intf_ch) == CDS_BAND_2GHZ) {
814 status =
815 cds_get_sap_mandatory_channel(
816 (uint32_t *)&intf_ch);
817 if (QDF_IS_STATUS_ERROR(status)) {
818 sms_log(mac_ctx, LOGE,
819 FL("no mandatory channel"));
820 intf_ch = sap_ch;
821 }
822 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 }
824
Manishekar Chandrasekaran1db3abe2016-06-24 03:27:07 +0530825 if (intf_ch == sap_ch)
826 intf_ch = 0;
827
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 sms_log(mac_ctx, LOGE, FL("##Concurrent Channels %s Interfering"),
829 intf_ch == 0 ? "Not" : "Are");
830 return intf_ch;
831}
832#endif
833
834bool csr_is_all_session_disconnected(tpAniSirGlobal pMac)
835{
836 uint32_t i;
837 bool fRc = true;
838
839 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
840 if (CSR_IS_SESSION_VALID(pMac, i)
841 && !csr_is_conn_state_disconnected(pMac, i)) {
842 fRc = false;
843 break;
844 }
845 }
846
847 return fRc;
848}
849
850/**
851 * csr_is_sta_session_connected() - to find if concurrent sta is active
852 * @mac_ctx: pointer to mac context
853 *
854 * This function will iterate through each session and check if sta
855 * session exist and active
856 *
857 * Return: true or false
858 */
859bool csr_is_sta_session_connected(tpAniSirGlobal mac_ctx)
860{
861 uint32_t i;
862 tCsrRoamSession *pSession = NULL;
863
864 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
865 if (CSR_IS_SESSION_VALID(mac_ctx, i) &&
866 !csr_is_conn_state_disconnected(mac_ctx, i)) {
867 pSession = CSR_GET_SESSION(mac_ctx, i);
868
869 if ((NULL != pSession->pCurRoamProfile) &&
Anurag Chouhan6d760662016-02-20 16:05:43 +0530870 (QDF_STA_MODE ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800871 pSession->pCurRoamProfile->csrPersona))
872 return true;
873 }
874 }
875
876 return false;
877}
878
879/**
880 * csr_is_p2p_session_connected() - to find if any p2p session is active
881 * @mac_ctx: pointer to mac context
882 *
883 * This function will iterate through each session and check if any p2p
884 * session exist and active
885 *
886 * Return: true or false
887 */
888bool csr_is_p2p_session_connected(tpAniSirGlobal pMac)
889{
890 uint32_t i;
891 tCsrRoamSession *pSession = NULL;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530892 enum tQDF_ADAPTER_MODE persona;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893
894 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Naveen Rawat9598f5e2016-06-27 15:33:40 -0700895 if (!CSR_IS_SESSION_VALID(pMac, i))
896 continue;
897
898 if (csr_is_conn_state_disconnected(pMac, i))
899 continue;
900
901 pSession = CSR_GET_SESSION(pMac, i);
902 if (pSession->pCurRoamProfile == NULL)
903 continue;
904
905 persona = pSession->pCurRoamProfile->csrPersona;
906 if (QDF_P2P_CLIENT_MODE == persona ||
907 QDF_P2P_GO_MODE == persona)
908 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 }
910
911 return false;
912}
913
914bool csr_is_any_session_connected(tpAniSirGlobal pMac)
915{
916 uint32_t i, count;
917 bool fRc = false;
918
919 count = 0;
920 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
921 if (CSR_IS_SESSION_VALID(pMac, i)
922 && !csr_is_conn_state_disconnected(pMac, i))
923 count++;
924 }
925
926 if (count > 0)
927 fRc = true;
928 return fRc;
929}
930
931bool csr_is_infra_connected(tpAniSirGlobal pMac)
932{
933 uint32_t i;
934 bool fRc = false;
935
936 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
937 if (CSR_IS_SESSION_VALID(pMac, i)
938 && csr_is_conn_state_connected_infra(pMac, i)) {
939 fRc = true;
940 break;
941 }
942 }
943
944 return fRc;
945}
946
947bool csr_is_concurrent_infra_connected(tpAniSirGlobal pMac)
948{
949 uint32_t i, noOfConnectedInfra = 0;
950
951 bool fRc = false;
952
953 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
954 if (CSR_IS_SESSION_VALID(pMac, i)
955 && csr_is_conn_state_connected_infra(pMac, i)) {
956 ++noOfConnectedInfra;
957 }
958 }
959
960 /* More than one Infra Sta Connected */
961 if (noOfConnectedInfra > 1)
962 fRc = true;
963 return fRc;
964}
965
966bool csr_is_ibss_started(tpAniSirGlobal pMac)
967{
968 uint32_t i;
969 bool fRc = false;
970
971 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
972 if (CSR_IS_SESSION_VALID(pMac, i)
973 && csr_is_conn_state_ibss(pMac, i)) {
974 fRc = true;
975 break;
976 }
977 }
978
979 return fRc;
980}
981
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982bool csr_is_concurrent_session_running(tpAniSirGlobal pMac)
983{
984 uint32_t sessionId, noOfCocurrentSession = 0;
985 eCsrConnectState connectState;
986
987 bool fRc = false;
988
989 for (sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++) {
990 if (CSR_IS_SESSION_VALID(pMac, sessionId)) {
991 connectState =
992 pMac->roam.roamSession[sessionId].connectState;
993 if ((eCSR_ASSOC_STATE_TYPE_INFRA_ASSOCIATED ==
994 connectState)
995 || (eCSR_ASSOC_STATE_TYPE_INFRA_CONNECTED ==
996 connectState)
997 || (eCSR_ASSOC_STATE_TYPE_INFRA_DISCONNECTED ==
998 connectState)) {
999 ++noOfCocurrentSession;
1000 }
1001 }
1002 }
1003
1004 /* More than one session is Up and Running */
1005 if (noOfCocurrentSession > 1)
1006 fRc = true;
1007 return fRc;
1008}
1009
1010bool csr_is_infra_ap_started(tpAniSirGlobal pMac)
1011{
1012 uint32_t sessionId;
1013 bool fRc = false;
1014
1015 for (sessionId = 0; sessionId < CSR_ROAM_SESSION_MAX; sessionId++) {
1016 if (CSR_IS_SESSION_VALID(pMac, sessionId)
1017 && (csr_is_conn_state_connected_infra_ap(pMac, sessionId))) {
1018 fRc = true;
1019 break;
1020 }
1021 }
1022
1023 return fRc;
1024
1025}
1026
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027bool csr_is_conn_state_disconnected(tpAniSirGlobal pMac, uint32_t sessionId)
1028{
1029 return eCSR_ASSOC_STATE_TYPE_NOT_CONNECTED ==
1030 pMac->roam.roamSession[sessionId].connectState;
1031}
1032
1033/**
1034 * csr_is_valid_mc_concurrent_session() - To check concurren session is valid
1035 * @mac_ctx: pointer to mac context
1036 * @session_id: session id
1037 * @bss_descr: bss description
1038 *
1039 * This function validates the concurrent session
1040 *
1041 * Return: true or false
1042 */
1043bool csr_is_valid_mc_concurrent_session(tpAniSirGlobal mac_ctx,
1044 uint32_t session_id,
1045 tSirBssDescription *bss_descr)
1046{
1047 tCsrRoamSession *pSession = NULL;
1048
1049 /* Check for MCC support */
1050 if (!mac_ctx->roam.configParam.fenableMCCMode)
1051 return false;
1052 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id))
1053 return false;
1054 /* Validate BeaconInterval */
1055 pSession = CSR_GET_SESSION(mac_ctx, session_id);
1056 if (NULL == pSession->pCurRoamProfile)
1057 return false;
Krunal Sonicbda8552016-07-14 19:39:02 -07001058 if (QDF_STATUS_SUCCESS == csr_validate_mcc_beacon_interval(mac_ctx,
1059 bss_descr->channelId,
1060 &bss_descr->beaconInterval, session_id,
1061 pSession->pCurRoamProfile->csrPersona))
1062 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 return false;
1064}
1065
1066static tSirMacCapabilityInfo csr_get_bss_capabilities(tSirBssDescription *
1067 pSirBssDesc)
1068{
1069 tSirMacCapabilityInfo dot11Caps;
1070
1071 /* tSirMacCapabilityInfo is 16-bit */
Anurag Chouhanc5548422016-02-24 18:33:27 +05301072 qdf_get_u16((uint8_t *) &pSirBssDesc->capabilityInfo,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 (uint16_t *) &dot11Caps);
1074
1075 return dot11Caps;
1076}
1077
1078bool csr_is_infra_bss_desc(tSirBssDescription *pSirBssDesc)
1079{
1080 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1081
1082 return (bool) dot11Caps.ess;
1083}
1084
1085bool csr_is_ibss_bss_desc(tSirBssDescription *pSirBssDesc)
1086{
1087 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1088
1089 return (bool) dot11Caps.ibss;
1090}
1091
1092bool csr_is_qo_s_bss_desc(tSirBssDescription *pSirBssDesc)
1093{
1094 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1095
1096 return (bool) dot11Caps.qos;
1097}
1098
1099bool csr_is_privacy(tSirBssDescription *pSirBssDesc)
1100{
1101 tSirMacCapabilityInfo dot11Caps = csr_get_bss_capabilities(pSirBssDesc);
1102
1103 return (bool) dot11Caps.privacy;
1104}
1105
1106bool csr_is11d_supported(tpAniSirGlobal pMac)
1107{
1108 return pMac->roam.configParam.Is11dSupportEnabled;
1109}
1110
1111bool csr_is11h_supported(tpAniSirGlobal pMac)
1112{
1113 return pMac->roam.configParam.Is11hSupportEnabled;
1114}
1115
1116bool csr_is11e_supported(tpAniSirGlobal pMac)
1117{
1118 return pMac->roam.configParam.Is11eSupportEnabled;
1119}
1120
1121bool csr_is_mcc_supported(tpAniSirGlobal pMac)
1122{
1123 return pMac->roam.configParam.fenableMCCMode;
1124
1125}
1126
1127bool csr_is_wmm_supported(tpAniSirGlobal pMac)
1128{
1129 if (eCsrRoamWmmNoQos == pMac->roam.configParam.WMMSupportMode)
1130 return false;
1131 else
1132 return true;
1133}
1134
1135/* pIes is the IEs for pSirBssDesc2 */
1136bool csr_is_ssid_equal(tHalHandle hHal, tSirBssDescription *pSirBssDesc1,
1137 tSirBssDescription *pSirBssDesc2, tDot11fBeaconIEs *pIes2)
1138{
1139 bool fEqual = false;
1140 tSirMacSSid Ssid1, Ssid2;
1141 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
1142 tDot11fBeaconIEs *pIes1 = NULL;
1143 tDot11fBeaconIEs *pIesLocal = pIes2;
1144
1145 do {
1146 if ((NULL == pSirBssDesc1) || (NULL == pSirBssDesc2))
1147 break;
1148 if (!pIesLocal
1149 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301150 !QDF_IS_STATUS_SUCCESS(csr_get_parsed_bss_description_ies
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 (pMac, pSirBssDesc2,
1152 &pIesLocal))) {
1153 sms_log(pMac, LOGE, FL(" fail to parse IEs"));
1154 break;
1155 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301156 if (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157 (csr_get_parsed_bss_description_ies(pMac,
1158 pSirBssDesc1, &pIes1))) {
1159 break;
1160 }
1161 if ((!pIes1->SSID.present) || (!pIesLocal->SSID.present))
1162 break;
1163 if (pIes1->SSID.num_ssid != pIesLocal->SSID.num_ssid)
1164 break;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301165 qdf_mem_copy(Ssid1.ssId, pIes1->SSID.ssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166 pIes1->SSID.num_ssid);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301167 qdf_mem_copy(Ssid2.ssId, pIesLocal->SSID.ssid,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001168 pIesLocal->SSID.num_ssid);
1169
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301170 fEqual = (!qdf_mem_cmp(Ssid1.ssId, Ssid2.ssId,
1171 pIesLocal->SSID.num_ssid));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172
1173 } while (0);
1174 if (pIes1)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301175 qdf_mem_free(pIes1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176 if (pIesLocal && !pIes2)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301177 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178
1179 return fEqual;
1180}
1181
1182/* pIes can be passed in as NULL if the caller doesn't have one prepared */
1183bool csr_is_bss_description_wme(tHalHandle hHal, tSirBssDescription *pSirBssDesc,
1184 tDot11fBeaconIEs *pIes)
1185{
1186 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
1187 /* Assume that WME is found... */
1188 bool fWme = true;
1189 tDot11fBeaconIEs *pIesTemp = pIes;
1190
1191 do {
1192 if (pIesTemp == NULL) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301193 if (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001194 (csr_get_parsed_bss_description_ies
1195 (pMac, pSirBssDesc, &pIesTemp))) {
1196 fWme = false;
1197 break;
1198 }
1199 }
1200 /* if the Wme Info IE is found, then WME is supported... */
1201 if (CSR_IS_QOS_BSS(pIesTemp))
1202 break;
1203 /* if none of these are found, then WME is NOT supported... */
1204 fWme = false;
1205 } while (0);
1206 if (!csr_is_wmm_supported(pMac) && fWme) {
1207 if (!pIesTemp->HTCaps.present) {
1208 fWme = false;
1209 }
1210 }
1211 if ((pIes == NULL) && (NULL != pIesTemp)) {
1212 /* we allocate memory here so free it before returning */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301213 qdf_mem_free(pIesTemp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 }
1215
1216 return fWme;
1217}
1218
1219eCsrMediaAccessType csr_get_qo_s_from_bss_desc(tHalHandle hHal,
1220 tSirBssDescription *pSirBssDesc,
1221 tDot11fBeaconIEs *pIes)
1222{
1223 eCsrMediaAccessType qosType = eCSR_MEDIUM_ACCESS_DCF;
1224
1225 if (NULL == pIes) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301226 QDF_ASSERT(pIes != NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001227 return qosType;
1228 }
1229
1230 do {
1231 /* if we find WMM in the Bss Description, then we let this */
1232 /* override and use WMM. */
1233 if (csr_is_bss_description_wme(hHal, pSirBssDesc, pIes)) {
1234 qosType = eCSR_MEDIUM_ACCESS_WMM_eDCF_DSCP;
1235 } else {
1236 /* if the QoS bit is on, then the AP is advertising 11E QoS... */
1237 if (csr_is_qo_s_bss_desc(pSirBssDesc)) {
1238 qosType = eCSR_MEDIUM_ACCESS_11e_eDCF;
1239 } else {
1240 qosType = eCSR_MEDIUM_ACCESS_DCF;
1241 }
1242 /* scale back based on the types turned on for the adapter... */
1243 if (eCSR_MEDIUM_ACCESS_11e_eDCF == qosType
1244 && !csr_is11e_supported(hHal)) {
1245 qosType = eCSR_MEDIUM_ACCESS_DCF;
1246 }
1247 }
1248
1249 } while (0);
1250
1251 return qosType;
1252}
1253
1254/* Caller allocates memory for pIEStruct */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301255QDF_STATUS csr_parse_bss_description_ies(tHalHandle hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001256 tSirBssDescription *pBssDesc,
1257 tDot11fBeaconIEs *pIEStruct)
1258{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301259 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001260 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
1261 int ieLen =
1262 (int)(pBssDesc->length + sizeof(pBssDesc->length) -
1263 GET_FIELD_OFFSET(tSirBssDescription, ieFields));
1264
1265 if (ieLen > 0 && pIEStruct) {
1266 if (!DOT11F_FAILED
1267 (dot11f_unpack_beacon_i_es
1268 (pMac, (uint8_t *) pBssDesc->ieFields, ieLen,
1269 pIEStruct))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301270 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 }
1272 }
1273
1274 return status;
1275}
1276
1277/* This function will allocate memory for the parsed IEs to the caller. Caller must free the memory */
1278/* after it is done with the data only if this function succeeds */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301279QDF_STATUS csr_get_parsed_bss_description_ies(tHalHandle hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001280 tSirBssDescription *pBssDesc,
1281 tDot11fBeaconIEs **ppIEStruct)
1282{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301283 QDF_STATUS status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
1285
1286 if (pBssDesc && ppIEStruct) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301287 *ppIEStruct = qdf_mem_malloc(sizeof(tDot11fBeaconIEs));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 if ((*ppIEStruct) != NULL) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301289 qdf_mem_set((void *)*ppIEStruct,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001290 sizeof(tDot11fBeaconIEs), 0);
1291 status =
1292 csr_parse_bss_description_ies(hHal, pBssDesc,
1293 *ppIEStruct);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301294 if (!QDF_IS_STATUS_SUCCESS(status)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301295 qdf_mem_free(*ppIEStruct);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 *ppIEStruct = NULL;
1297 }
1298 } else {
1299 sms_log(pMac, LOGE, FL(" failed to allocate memory"));
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301300 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301301 return QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302 }
1303 }
1304
1305 return status;
1306}
1307
1308bool csr_is_nullssid(uint8_t *pBssSsid, uint8_t len)
1309{
1310 bool fNullSsid = false;
1311
1312 uint32_t SsidLength;
1313 uint8_t *pSsidStr;
1314
1315 do {
1316 if (0 == len) {
1317 fNullSsid = true;
1318 break;
1319 }
1320 /* Consider 0 or space for hidden SSID */
1321 if (0 == pBssSsid[0]) {
1322 fNullSsid = true;
1323 break;
1324 }
1325
1326 SsidLength = len;
1327 pSsidStr = pBssSsid;
1328
1329 while (SsidLength) {
1330 if (*pSsidStr)
1331 break;
1332
1333 pSsidStr++;
1334 SsidLength--;
1335 }
1336
1337 if (0 == SsidLength) {
1338 fNullSsid = true;
1339 break;
1340 }
1341 } while (0);
1342
1343 return fNullSsid;
1344}
1345
1346uint32_t csr_get_frag_thresh(tHalHandle hHal)
1347{
1348 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
1349
1350 return pMac->roam.configParam.FragmentationThreshold;
1351}
1352
1353uint32_t csr_get_rts_thresh(tHalHandle hHal)
1354{
1355 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
1356
1357 return pMac->roam.configParam.RTSThreshold;
1358}
1359
1360eCsrPhyMode csr_translate_to_phy_mode_from_bss_desc(tSirBssDescription *pSirBssDesc)
1361{
1362 eCsrPhyMode phyMode;
1363
1364 switch (pSirBssDesc->nwType) {
1365 case eSIR_11A_NW_TYPE:
1366 phyMode = eCSR_DOT11_MODE_11a;
1367 break;
1368
1369 case eSIR_11B_NW_TYPE:
1370 phyMode = eCSR_DOT11_MODE_11b;
1371 break;
1372
1373 case eSIR_11G_NW_TYPE:
1374 phyMode = eCSR_DOT11_MODE_11g;
1375 break;
1376
1377 case eSIR_11N_NW_TYPE:
1378 phyMode = eCSR_DOT11_MODE_11n;
1379 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001380 case eSIR_11AC_NW_TYPE:
1381 default:
1382 phyMode = eCSR_DOT11_MODE_11ac;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 break;
1384 }
1385 return phyMode;
1386}
1387
1388uint32_t csr_translate_to_wni_cfg_dot11_mode(tpAniSirGlobal pMac,
1389 eCsrCfgDot11Mode csrDot11Mode)
1390{
1391 uint32_t ret;
1392
1393 switch (csrDot11Mode) {
1394 case eCSR_CFG_DOT11_MODE_AUTO:
1395 sms_log(pMac, LOGW,
1396 FL(" Warning: sees eCSR_CFG_DOT11_MODE_AUTO "));
1397 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
1398 ret = WNI_CFG_DOT11_MODE_11AC;
1399 else
1400 ret = WNI_CFG_DOT11_MODE_11N;
1401 break;
1402 case eCSR_CFG_DOT11_MODE_11A:
1403 ret = WNI_CFG_DOT11_MODE_11A;
1404 break;
1405 case eCSR_CFG_DOT11_MODE_11B:
1406 ret = WNI_CFG_DOT11_MODE_11B;
1407 break;
1408 case eCSR_CFG_DOT11_MODE_11G:
1409 ret = WNI_CFG_DOT11_MODE_11G;
1410 break;
1411 case eCSR_CFG_DOT11_MODE_11N:
1412 ret = WNI_CFG_DOT11_MODE_11N;
1413 break;
1414 case eCSR_CFG_DOT11_MODE_11G_ONLY:
1415 ret = WNI_CFG_DOT11_MODE_11G_ONLY;
1416 break;
1417 case eCSR_CFG_DOT11_MODE_11N_ONLY:
1418 ret = WNI_CFG_DOT11_MODE_11N_ONLY;
1419 break;
1420 case eCSR_CFG_DOT11_MODE_11AC_ONLY:
1421 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
1422 ret = WNI_CFG_DOT11_MODE_11AC_ONLY;
1423 else
1424 ret = WNI_CFG_DOT11_MODE_11N;
1425 break;
1426 case eCSR_CFG_DOT11_MODE_11AC:
1427 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC))
1428 ret = WNI_CFG_DOT11_MODE_11AC;
1429 else
1430 ret = WNI_CFG_DOT11_MODE_11N;
1431 break;
1432 default:
1433 sms_log(pMac, LOGW, FL("doesn't expect %d as csrDo11Mode"),
1434 csrDot11Mode);
1435 if (eCSR_BAND_24 == pMac->roam.configParam.eBand) {
1436 ret = WNI_CFG_DOT11_MODE_11G;
1437 } else {
1438 ret = WNI_CFG_DOT11_MODE_11A;
1439 }
1440 break;
1441 }
1442
1443 return ret;
1444}
1445
1446/**
1447 * csr_get_phy_mode_from_bss() - Get Phy Mode
1448 * @pMac: Global MAC context
1449 * @pBSSDescription: BSS Descriptor
1450 * @pPhyMode: Physical Mode
1451 * @pIes: Pointer to the IE fields
1452 *
1453 * This function should only return the super set of supported modes
1454 * 11n implies 11b/g/a/n.
1455 *
1456 * Return: success
1457 **/
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301458QDF_STATUS csr_get_phy_mode_from_bss(tpAniSirGlobal pMac,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 tSirBssDescription *pBSSDescription,
1460 eCsrPhyMode *pPhyMode, tDot11fBeaconIEs *pIes)
1461{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301462 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001463 eCsrPhyMode phyMode =
1464 csr_translate_to_phy_mode_from_bss_desc(pBSSDescription);
1465
1466 if (pIes) {
1467 if (pIes->HTCaps.present) {
1468 phyMode = eCSR_DOT11_MODE_11n;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001469 if (IS_BSS_VHT_CAPABLE(pIes->VHTCaps) ||
1470 IS_BSS_VHT_CAPABLE(pIes->vendor2_ie.VHTCaps))
1471 phyMode = eCSR_DOT11_MODE_11ac;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001472 }
1473 *pPhyMode = phyMode;
1474 }
1475
1476 return status;
1477}
1478
1479/**
1480 * csr_get_phy_mode_in_use() - to get phymode
1481 * @phyModeIn: physical mode
1482 * @bssPhyMode: physical mode in bss
1483 * @f5GhzBand: 5Ghz band
1484 * @pCfgDot11ModeToUse: dot11 mode in use
1485 *
1486 * This function returns the correct eCSR_CFG_DOT11_MODE is the two phyModes
1487 * matches. bssPhyMode is the mode derived from the BSS description
1488 * f5GhzBand is derived from the channel id of BSS description
1489 *
1490 * Return: true or false
1491 */
1492bool csr_get_phy_mode_in_use(eCsrPhyMode phyModeIn, eCsrPhyMode bssPhyMode,
1493 bool f5GhzBand, eCsrCfgDot11Mode *pCfgDot11ModeToUse)
1494{
1495 bool fMatch = false;
1496 eCsrCfgDot11Mode cfgDot11Mode;
1497 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1498
1499 switch (phyModeIn) {
1500 /* 11a or 11b or 11g */
1501 case eCSR_DOT11_MODE_abg:
1502 fMatch = true;
1503 if (f5GhzBand)
1504 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1505 else if (eCSR_DOT11_MODE_11b == bssPhyMode)
1506 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1507 else
1508 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1509 break;
1510
1511 case eCSR_DOT11_MODE_11a:
1512 if (f5GhzBand) {
1513 fMatch = true;
1514 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1515 }
1516 break;
1517
1518 case eCSR_DOT11_MODE_11g:
1519 if (!f5GhzBand) {
1520 fMatch = true;
1521 if (eCSR_DOT11_MODE_11b == bssPhyMode)
1522 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1523 else
1524 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1525 }
1526 break;
1527
1528 case eCSR_DOT11_MODE_11g_ONLY:
1529 if (eCSR_DOT11_MODE_11g == bssPhyMode) {
1530 fMatch = true;
1531 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1532 }
1533 break;
1534
1535 case eCSR_DOT11_MODE_11b:
1536 if (!f5GhzBand) {
1537 fMatch = true;
1538 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1539 }
1540 break;
1541
1542 case eCSR_DOT11_MODE_11b_ONLY:
1543 if (eCSR_DOT11_MODE_11b == bssPhyMode) {
1544 fMatch = true;
1545 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1546 }
1547 break;
1548
1549 case eCSR_DOT11_MODE_11n:
1550 fMatch = true;
1551 switch (bssPhyMode) {
1552 case eCSR_DOT11_MODE_11g:
1553 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1554 break;
1555 case eCSR_DOT11_MODE_11b:
1556 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1557 break;
1558 case eCSR_DOT11_MODE_11a:
1559 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1560 break;
1561 case eCSR_DOT11_MODE_11n:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 case eCSR_DOT11_MODE_11ac:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1564 break;
1565
1566 default:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001567 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 break;
1569 }
1570 break;
1571
1572 case eCSR_DOT11_MODE_11n_ONLY:
1573 if ((eCSR_DOT11_MODE_11n == bssPhyMode)) {
1574 fMatch = true;
1575 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1576
1577 }
1578
1579 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580 case eCSR_DOT11_MODE_11ac:
1581 fMatch = true;
1582 switch (bssPhyMode) {
1583 case eCSR_DOT11_MODE_11g:
1584 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1585 break;
1586 case eCSR_DOT11_MODE_11b:
1587 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1588 break;
1589 case eCSR_DOT11_MODE_11a:
1590 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1591 break;
1592 case eCSR_DOT11_MODE_11n:
1593 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1594 break;
1595 case eCSR_DOT11_MODE_11ac:
1596 default:
1597 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
1598 break;
1599 }
1600 break;
1601
1602 case eCSR_DOT11_MODE_11ac_ONLY:
1603 if ((eCSR_DOT11_MODE_11ac == bssPhyMode)) {
1604 fMatch = true;
1605 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
1606 }
1607 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608
1609 default:
1610 fMatch = true;
1611 switch (bssPhyMode) {
1612 case eCSR_DOT11_MODE_11g:
1613 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
1614 break;
1615 case eCSR_DOT11_MODE_11b:
1616 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
1617 break;
1618 case eCSR_DOT11_MODE_11a:
1619 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
1620 break;
1621 case eCSR_DOT11_MODE_11n:
1622 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
1623 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001624 case eCSR_DOT11_MODE_11ac:
1625 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
1626 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001627 default:
1628 cfgDot11Mode = eCSR_CFG_DOT11_MODE_AUTO;
1629 break;
1630 }
1631 break;
1632 }
1633
1634 if (fMatch && pCfgDot11ModeToUse) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001635 if (cfgDot11Mode == eCSR_CFG_DOT11_MODE_11AC
1636 && (!IS_FEATURE_SUPPORTED_BY_FW(DOT11AC)))
1637 *pCfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
1638 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 *pCfgDot11ModeToUse = cfgDot11Mode;
1640 }
1641 return fMatch;
1642}
1643
1644/**
1645 * csr_is_phy_mode_match() - to find if phy mode matches
1646 * @pMac: pointer to mac context
1647 * @phyMode: physical mode
1648 * @pSirBssDesc: bss description
1649 * @pProfile: pointer to roam profile
1650 * @pReturnCfgDot11Mode: dot1 mode to return
1651 * @pIes: pointer to IEs
1652 *
1653 * This function decides whether the one of the bit of phyMode is matching the
1654 * mode in the BSS and allowed by the user setting
1655 *
1656 * Return: true or false based on mode that fits the criteria
1657 */
1658bool csr_is_phy_mode_match(tpAniSirGlobal pMac, uint32_t phyMode,
1659 tSirBssDescription *pSirBssDesc,
1660 tCsrRoamProfile *pProfile,
1661 eCsrCfgDot11Mode *pReturnCfgDot11Mode,
1662 tDot11fBeaconIEs *pIes)
1663{
1664 bool fMatch = false;
1665 eCsrPhyMode phyModeInBssDesc = eCSR_DOT11_MODE_AUTO, phyMode2;
1666 eCsrCfgDot11Mode cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_AUTO;
1667 uint32_t bitMask, loopCount;
1668
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301669 if (!QDF_IS_STATUS_SUCCESS(csr_get_phy_mode_from_bss(pMac, pSirBssDesc,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 &phyModeInBssDesc, pIes)))
1671 return fMatch;
1672
1673 if ((0 == phyMode) || (eCSR_DOT11_MODE_AUTO & phyMode)) {
1674 if (eCSR_CFG_DOT11_MODE_ABG ==
1675 pMac->roam.configParam.uCfgDot11Mode)
1676 phyMode = eCSR_DOT11_MODE_abg;
1677 else if (eCSR_CFG_DOT11_MODE_AUTO ==
1678 pMac->roam.configParam.uCfgDot11Mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679 phyMode = eCSR_DOT11_MODE_11ac;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001680 else
1681 /* user's pick */
1682 phyMode = pMac->roam.configParam.phyMode;
1683 }
1684
1685 if ((0 == phyMode) || (eCSR_DOT11_MODE_AUTO & phyMode)) {
1686 if (0 != phyMode) {
1687 if (eCSR_DOT11_MODE_AUTO & phyMode) {
1688 phyMode2 =
1689 eCSR_DOT11_MODE_AUTO & phyMode;
1690 }
1691 } else {
1692 phyMode2 = phyMode;
1693 }
1694 fMatch = csr_get_phy_mode_in_use(phyMode2, phyModeInBssDesc,
1695 CDS_IS_CHANNEL_5GHZ(pSirBssDesc->channelId),
1696 &cfgDot11ModeToUse);
1697 } else {
1698 bitMask = 1;
1699 loopCount = 0;
1700 while (loopCount < eCSR_NUM_PHY_MODE) {
1701 phyMode2 = (phyMode & (bitMask << loopCount++));
1702 if (0 != phyMode2 && csr_get_phy_mode_in_use(phyMode2,
1703 phyModeInBssDesc,
1704 CDS_IS_CHANNEL_5GHZ
1705 (pSirBssDesc->channelId),
1706 &cfgDot11ModeToUse)) {
1707 fMatch = true;
1708 break;
1709 }
1710 }
1711 }
1712 if (fMatch && pReturnCfgDot11Mode) {
1713 if (pProfile) {
1714 /*
1715 * IEEE 11n spec (8.4.3): HT STA shall
1716 * eliminate TKIP as a choice for the pairwise
1717 * cipher suite if CCMP is advertised by the AP
1718 * or if the AP included an HT capabilities
1719 * element in its Beacons and Probe Response.
1720 */
1721 if ((!CSR_IS_11n_ALLOWED(
1722 pProfile->negotiatedUCEncryptionType))
1723 && ((eCSR_CFG_DOT11_MODE_11N ==
1724 cfgDot11ModeToUse) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001725 (eCSR_CFG_DOT11_MODE_11AC ==
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -08001726 cfgDot11ModeToUse))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001727 /* We cannot do 11n here */
1728 if (!CDS_IS_CHANNEL_5GHZ
1729 (pSirBssDesc->channelId)) {
1730 cfgDot11ModeToUse =
1731 eCSR_CFG_DOT11_MODE_11G;
1732 } else {
1733 cfgDot11ModeToUse =
1734 eCSR_CFG_DOT11_MODE_11A;
1735 }
1736 }
1737 }
1738 *pReturnCfgDot11Mode = cfgDot11ModeToUse;
1739 }
1740
1741 return fMatch;
1742}
1743
1744eCsrCfgDot11Mode csr_find_best_phy_mode(tpAniSirGlobal pMac, uint32_t phyMode)
1745{
1746 eCsrCfgDot11Mode cfgDot11ModeToUse;
1747 eCsrBand eBand = pMac->roam.configParam.eBand;
1748
1749 if ((0 == phyMode) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750 (eCSR_DOT11_MODE_11ac & phyMode) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001751 (eCSR_DOT11_MODE_AUTO & phyMode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC)) {
1753 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11AC;
Kiran Kumar Lokere9a733a72016-02-17 19:01:15 -08001754 } else {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755 /* Default to 11N mode if user has configured 11ac mode
1756 * and FW doesn't supports 11ac mode .
1757 */
1758 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
1759 }
1760 } else {
1761 if ((eCSR_DOT11_MODE_11n | eCSR_DOT11_MODE_11n_ONLY) & phyMode) {
1762 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11N;
1763 } else if (eCSR_DOT11_MODE_abg & phyMode) {
1764 if (eCSR_BAND_24 != eBand) {
1765 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11A;
1766 } else {
1767 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11G;
1768 }
1769 } else if (eCSR_DOT11_MODE_11a & phyMode) {
1770 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11A;
1771 } else if ((eCSR_DOT11_MODE_11g | eCSR_DOT11_MODE_11g_ONLY) &
1772 phyMode) {
1773 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11G;
1774 } else {
1775 cfgDot11ModeToUse = eCSR_CFG_DOT11_MODE_11B;
1776 }
1777 }
1778
1779 return cfgDot11ModeToUse;
1780}
1781
1782uint32_t csr_get11h_power_constraint(tHalHandle hHal,
1783 tDot11fIEPowerConstraints *pPowerConstraint)
1784{
1785 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
1786 uint32_t localPowerConstraint = 0;
1787
1788 /* check if .11h support is enabled, if not, the power constraint is 0. */
1789 if (pMac->roam.configParam.Is11hSupportEnabled
1790 && pPowerConstraint->present) {
1791 localPowerConstraint = pPowerConstraint->localPowerConstraints;
1792 }
1793
1794 return localPowerConstraint;
1795}
1796
1797bool csr_is_profile_wpa(tCsrRoamProfile *pProfile)
1798{
1799 bool fWpaProfile = false;
1800
1801 switch (pProfile->negotiatedAuthType) {
1802 case eCSR_AUTH_TYPE_WPA:
1803 case eCSR_AUTH_TYPE_WPA_PSK:
1804 case eCSR_AUTH_TYPE_WPA_NONE:
1805#ifdef FEATURE_WLAN_ESE
1806 case eCSR_AUTH_TYPE_CCKM_WPA:
1807#endif
1808 fWpaProfile = true;
1809 break;
1810
1811 default:
1812 fWpaProfile = false;
1813 break;
1814 }
1815
1816 if (fWpaProfile) {
1817 switch (pProfile->negotiatedUCEncryptionType) {
1818 case eCSR_ENCRYPT_TYPE_WEP40:
1819 case eCSR_ENCRYPT_TYPE_WEP104:
1820 case eCSR_ENCRYPT_TYPE_TKIP:
1821 case eCSR_ENCRYPT_TYPE_AES:
1822 fWpaProfile = true;
1823 break;
1824
1825 default:
1826 fWpaProfile = false;
1827 break;
1828 }
1829 }
1830 return fWpaProfile;
1831}
1832
1833bool csr_is_profile_rsn(tCsrRoamProfile *pProfile)
1834{
1835 bool fRSNProfile = false;
1836
1837 switch (pProfile->negotiatedAuthType) {
1838 case eCSR_AUTH_TYPE_RSN:
1839 case eCSR_AUTH_TYPE_RSN_PSK:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840 case eCSR_AUTH_TYPE_FT_RSN:
1841 case eCSR_AUTH_TYPE_FT_RSN_PSK:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842#ifdef FEATURE_WLAN_ESE
1843 case eCSR_AUTH_TYPE_CCKM_RSN:
1844#endif
1845#ifdef WLAN_FEATURE_11W
1846 case eCSR_AUTH_TYPE_RSN_PSK_SHA256:
1847 case eCSR_AUTH_TYPE_RSN_8021X_SHA256:
1848#endif
1849 fRSNProfile = true;
1850 break;
1851
1852 default:
1853 fRSNProfile = false;
1854 break;
1855 }
1856
1857 if (fRSNProfile) {
1858 switch (pProfile->negotiatedUCEncryptionType) {
1859 /* !!REVIEW - For WPA2, use of RSN IE mandates */
1860 /* use of AES as encryption. Here, we qualify */
1861 /* even if encryption type is WEP or TKIP */
1862 case eCSR_ENCRYPT_TYPE_WEP40:
1863 case eCSR_ENCRYPT_TYPE_WEP104:
1864 case eCSR_ENCRYPT_TYPE_TKIP:
1865 case eCSR_ENCRYPT_TYPE_AES:
1866 fRSNProfile = true;
1867 break;
1868
1869 default:
1870 fRSNProfile = false;
1871 break;
1872 }
1873 }
1874 return fRSNProfile;
1875}
1876
1877/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 * csr_update_mcc_p2p_beacon_interval() - update p2p beacon interval
1879 * @mac_ctx: pointer to mac context
1880 *
1881 * This function is to update the mcc p2p beacon interval
1882 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301883 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001884 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301885QDF_STATUS csr_update_mcc_p2p_beacon_interval(tpAniSirGlobal mac_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001886{
1887 uint32_t session_id = 0;
1888 tCsrRoamSession *roam_session;
1889
1890 /* If MCC is not supported just break and return SUCCESS */
1891 if (!mac_ctx->roam.configParam.fenableMCCMode)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301892 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893
1894 for (session_id = 0; session_id < CSR_ROAM_SESSION_MAX; session_id++) {
1895 /*
1896 * If GO in MCC support different beacon interval,
1897 * change the BI of the P2P-GO
1898 */
1899 roam_session = &mac_ctx->roam.roamSession[session_id];
Anurag Chouhan6d760662016-02-20 16:05:43 +05301900 if (roam_session->bssParams.bssPersona != QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001901 continue;
1902 /*
1903 * Handle different BI scneario based on the
1904 * configuration set.If Config is set to 0x02 then
1905 * Disconnect all the P2P clients associated. If config
1906 * is set to 0x04 then update the BI without
1907 * disconnecting all the clients
1908 */
1909 if ((mac_ctx->roam.configParam.fAllowMCCGODiffBI == 0x04)
1910 && (roam_session->bssParams.
1911 updatebeaconInterval)) {
1912 return csr_send_chng_mcc_beacon_interval(mac_ctx,
1913 session_id);
1914 } else if (roam_session->bssParams.updatebeaconInterval) {
1915 /*
1916 * If the configuration of fAllowMCCGODiffBI is set to
1917 * other than 0x04
1918 */
1919 return csr_roam_call_callback(mac_ctx,
1920 session_id,
1921 NULL, 0,
1922 eCSR_ROAM_DISCONNECT_ALL_P2P_CLIENTS,
1923 eCSR_ROAM_RESULT_NONE);
1924 }
1925 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301926 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001927}
1928
1929uint16_t csr_calculate_mcc_beacon_interval(tpAniSirGlobal pMac, uint16_t sta_bi,
1930 uint16_t go_gbi)
1931{
1932 uint8_t num_beacons = 0;
1933 uint8_t is_multiple = 0;
1934 uint16_t go_cbi = 0;
1935 uint16_t go_fbi = 0;
1936 uint16_t sta_cbi = 0;
1937
1938 /* If GO's given beacon Interval is less than 100 */
1939 if (go_gbi < 100)
1940 go_cbi = 100;
1941 /* if GO's given beacon Interval is greater than or equal to 100 */
1942 else
1943 go_cbi = 100 + (go_gbi % 100);
1944
1945 if (sta_bi == 0) {
1946 /* There is possibility to receive zero as value.
1947 Which will cause divide by zero. Hence initialise with 100
1948 */
1949 sta_bi = 100;
1950 sms_log(pMac, LOGW,
1951 FL("sta_bi 2nd parameter is zero, initialize to %d"),
1952 sta_bi);
1953 }
1954 /* check, if either one is multiple of another */
1955 if (sta_bi > go_cbi) {
1956 is_multiple = !(sta_bi % go_cbi);
1957 } else {
1958 is_multiple = !(go_cbi % sta_bi);
1959 }
1960 /* if it is multiple, then accept GO's beacon interval range [100,199] as it is */
1961 if (is_multiple) {
1962 return go_cbi;
1963 }
1964 /* else , if it is not multiple, then then check for number of beacons to be */
1965 /* inserted based on sta BI */
1966 num_beacons = sta_bi / 100;
1967 if (num_beacons) {
1968 /* GO's final beacon interval will be aligned to sta beacon interval, but */
1969 /* in the range of [100, 199]. */
1970 sta_cbi = sta_bi / num_beacons;
1971 go_fbi = sta_cbi;
1972 } else {
1973 /* if STA beacon interval is less than 100, use GO's change bacon interval */
1974 /* instead of updating to STA's beacon interval. */
1975 go_fbi = go_cbi;
1976 }
1977 return go_fbi;
1978}
1979
Naveen Rawat206e2ac2016-04-14 18:01:38 -07001980/**
1981 * csr_validate_p2pcli_bcn_intrvl() - to validate p2pcli beacon interval
1982 * @mac_ctx: pointer to mac context
1983 * @chnl_id: channel id variable
1984 * @bcn_interval: pointer to given beacon interval
1985 * @session_id: given session id
1986 * @status: fill the status in terms of QDF_STATUS to inform caller
1987 *
1988 * This API can provide the validation the beacon interval and re-calculate
1989 * in case concurrency
1990 *
1991 * Return: bool
1992 */
1993static bool csr_validate_p2pcli_bcn_intrvl(tpAniSirGlobal mac_ctx,
1994 uint8_t chnl_id, uint16_t *bcn_interval, uint32_t session_id,
1995 QDF_STATUS *status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996{
Naveen Rawat206e2ac2016-04-14 18:01:38 -07001997 tCsrRoamSession *roamsession;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998
Naveen Rawat206e2ac2016-04-14 18:01:38 -07001999 roamsession = &mac_ctx->roam.roamSession[session_id];
2000 if (roamsession->pCurRoamProfile &&
2001 (roamsession->pCurRoamProfile->csrPersona ==
2002 QDF_STA_MODE)) {
2003 /* check for P2P client mode */
2004 sms_log(mac_ctx, LOG1,
2005 FL(" Ignore Beacon Interval Validation..."));
2006 } else if (roamsession->bssParams.bssPersona == QDF_P2P_GO_MODE) {
2007 /* Check for P2P go scenario */
2008 if ((roamsession->bssParams.operationChn != chnl_id)
2009 && (roamsession->bssParams.beaconInterval !=
2010 *bcn_interval)) {
2011 sms_log(mac_ctx, LOGE,
2012 FL("BcnIntrvl is diff can't connect to P2P_GO network ..."));
2013 *status = QDF_STATUS_E_FAILURE;
2014 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015 }
2016 }
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002017 return false;
2018}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019
Naveen Rawat206e2ac2016-04-14 18:01:38 -07002020/**
2021 * csr_validate_p2pgo_bcn_intrvl() - to validate p2pgo beacon interval
2022 * @mac_ctx: pointer to mac context
2023 * @chnl_id: channel id variable
2024 * @bcn_interval: pointer to given beacon interval
2025 * @session_id: given session id
2026 * @status: fill the status in terms of QDF_STATUS to inform caller
2027 *
2028 * This API can provide the validation the beacon interval and re-calculate
2029 * in case concurrency
2030 *
2031 * Return: bool
2032 */
2033static bool csr_validate_p2pgo_bcn_intrvl(tpAniSirGlobal mac_ctx,
2034 uint8_t chnl_id, uint16_t *bcn_interval,
2035 uint32_t session_id, QDF_STATUS *status)
2036{
2037 tCsrRoamSession *roamsession;
2038 tCsrConfig *cfg_param;
2039 tCsrRoamConnectedProfile *conn_profile;
2040 uint16_t new_bcn_interval;
2041
2042 roamsession = &mac_ctx->roam.roamSession[session_id];
2043 cfg_param = &mac_ctx->roam.configParam;
2044 conn_profile = &roamsession->connectedProfile;
2045 if (roamsession->pCurRoamProfile &&
2046 ((roamsession->pCurRoamProfile->csrPersona ==
2047 QDF_P2P_CLIENT_MODE) ||
2048 (roamsession->pCurRoamProfile->csrPersona ==
2049 QDF_STA_MODE))) {
2050 /* check for P2P_client scenario */
2051 if ((conn_profile->operationChannel == 0) &&
2052 (conn_profile->beaconInterval == 0))
2053 return false;
2054
2055 if (csr_is_conn_state_connected_infra(mac_ctx, session_id) &&
2056 (conn_profile->operationChannel != chnl_id) &&
2057 (conn_profile->beaconInterval != *bcn_interval)) {
2058 /*
2059 * Updated beaconInterval should be used only when
2060 * we are starting a new BSS not incase of
2061 * client or STA case
2062 */
2063
2064 /* Calculate beacon Interval for P2P-GO incase of MCC */
2065 if (cfg_param->conc_custom_rule1 ||
2066 cfg_param->conc_custom_rule2) {
2067 new_bcn_interval = CSR_CUSTOM_CONC_GO_BI;
2068 } else {
2069 new_bcn_interval =
2070 csr_calculate_mcc_beacon_interval(
2071 mac_ctx,
2072 conn_profile->beaconInterval,
2073 *bcn_interval);
2074 }
2075 if (*bcn_interval != new_bcn_interval)
2076 *bcn_interval = new_bcn_interval;
2077 *status = QDF_STATUS_SUCCESS;
2078 return true;
2079 }
2080 }
2081 return false;
2082}
2083
2084/**
2085 * csr_validate_sta_bcn_intrvl() - to validate sta beacon interval
2086 * @mac_ctx: pointer to mac context
2087 * @chnl_id: channel id variable
2088 * @bcn_interval: pointer to given beacon interval
2089 * @session_id: given session id
2090 * @status: fill the status in terms of QDF_STATUS to inform caller
2091 *
2092 * This API can provide the validation the beacon interval and re-calculate
2093 * in case concurrency
2094 *
2095 * Return: bool
2096 */
2097static bool csr_validate_sta_bcn_intrvl(tpAniSirGlobal mac_ctx,
2098 uint8_t chnl_id, uint16_t *bcn_interval,
2099 uint32_t session_id, QDF_STATUS *status)
2100{
2101 tCsrRoamSession *roamsession;
2102 tCsrConfig *cfg_param;
2103 uint16_t new_bcn_interval;
2104
2105 roamsession = &mac_ctx->roam.roamSession[session_id];
2106 cfg_param = &mac_ctx->roam.configParam;
2107
2108 if (roamsession->pCurRoamProfile &&
2109 (roamsession->pCurRoamProfile->csrPersona ==
2110 QDF_P2P_CLIENT_MODE)) {
2111 /* check for P2P client mode */
2112 sms_log(mac_ctx, LOG1,
2113 FL("Bcn Intrvl validation not require for STA/CLIENT"));
2114 return false;
2115 }
2116 if ((roamsession->bssParams.bssPersona == QDF_SAP_MODE) &&
2117 (roamsession->bssParams.operationChn != chnl_id)) {
2118 /*
2119 * IF SAP has started and STA wants to connect
2120 * on different channel MCC should
2121 * MCC should not be enabled so making it
2122 * false to enforce on same channel
2123 */
2124 sms_log(mac_ctx, LOGE,
2125 FL("*** MCC with SAP+STA sessions ****"));
2126 *status = QDF_STATUS_SUCCESS;
2127 return true;
2128 }
2129 /*
2130 * Check for P2P go scenario
2131 * if GO in MCC support different
2132 * beacon interval,
2133 * change the BI of the P2P-GO
2134 */
2135 if ((roamsession->bssParams.bssPersona == QDF_P2P_GO_MODE) &&
2136 (roamsession->bssParams.operationChn != chnl_id) &&
2137 (roamsession->bssParams.beaconInterval != *bcn_interval)) {
2138 /* if GO in MCC support diff beacon interval, return success */
2139 if (cfg_param->fAllowMCCGODiffBI == 0x01) {
2140 *status = QDF_STATUS_SUCCESS;
2141 return true;
2142 }
2143 /*
2144 * Send only Broadcast disassoc and update bcn_interval
2145 * If configuration is set to 0x04 then dont
2146 * disconnect all the station
2147 */
2148 if ((cfg_param->fAllowMCCGODiffBI == 0x02)
2149 || (cfg_param->fAllowMCCGODiffBI == 0x04)) {
2150 /* Check to pass the right beacon Interval */
2151 if (cfg_param->conc_custom_rule1 ||
2152 cfg_param->conc_custom_rule2) {
2153 new_bcn_interval = CSR_CUSTOM_CONC_GO_BI;
2154 } else {
2155 new_bcn_interval =
2156 csr_calculate_mcc_beacon_interval(
2157 mac_ctx, *bcn_interval,
2158 roamsession->bssParams.beaconInterval);
2159 }
2160 sms_log(mac_ctx, LOG1,
2161 FL(" Peer AP BI : %d, new Beacon Interval: %d"),
2162 *bcn_interval, new_bcn_interval);
2163 /* Update the becon Interval */
2164 if (new_bcn_interval !=
2165 roamsession->bssParams.beaconInterval) {
2166 /* Update the bcn_interval now */
2167 sms_log(mac_ctx, LOGE,
2168 FL(" Beacon Interval got changed config used: %d\n"),
2169 cfg_param->fAllowMCCGODiffBI);
2170
2171 roamsession->bssParams.beaconInterval =
2172 new_bcn_interval;
2173 roamsession->bssParams.updatebeaconInterval =
2174 true;
2175 *status = csr_update_mcc_p2p_beacon_interval(
2176 mac_ctx);
2177 return true;
2178 }
2179 *status = QDF_STATUS_SUCCESS;
2180 return true;
2181 }
2182 if (cfg_param->fAllowMCCGODiffBI
2183 == 0x03) {
2184 /* Disconnect the P2P session */
2185 roamsession->bssParams.updatebeaconInterval = false;
2186 *status = csr_roam_call_callback(mac_ctx,
2187 session_id, NULL, 0,
2188 eCSR_ROAM_SEND_P2P_STOP_BSS,
2189 eCSR_ROAM_RESULT_NONE);
2190 return true;
2191 }
2192 sms_log(mac_ctx, LOGE,
2193 FL("BcnIntrvl is diff can't connect to preferred AP..."));
2194 *status = QDF_STATUS_E_FAILURE;
2195 return true;
2196 }
2197 return false;
2198}
2199
2200/**
2201 * csr_validate_mcc_beacon_interval() - to validate the mcc beacon interval
2202 * @mac_ctx: pointer to mac context
2203 * @chnl_id: channel number
2204 * @bcn_interval: provided beacon interval
2205 * @cur_session_id: current session id
2206 * @cur_bss_persona: Current BSS persona
2207 *
2208 * This API will validate the mcc beacon interval
2209 *
2210 * Return: QDF_STATUS
2211 */
2212QDF_STATUS csr_validate_mcc_beacon_interval(tpAniSirGlobal mac_ctx,
2213 uint8_t chnl_id,
2214 uint16_t *bcn_interval,
2215 uint32_t cur_session_id,
2216 enum tQDF_ADAPTER_MODE cur_bss_persona)
2217{
2218 uint32_t session_id = 0;
2219 QDF_STATUS status;
2220 bool is_done;
2221
2222 /* If MCC is not supported just break */
2223 if (!mac_ctx->roam.configParam.fenableMCCMode)
2224 return QDF_STATUS_E_FAILURE;
2225
2226 for (session_id = 0; session_id < CSR_ROAM_SESSION_MAX; session_id++) {
2227 if (cur_session_id == session_id)
2228 continue;
2229
2230 if (!CSR_IS_SESSION_VALID(mac_ctx, session_id))
2231 continue;
2232
2233 switch (cur_bss_persona) {
2234 case QDF_STA_MODE:
2235 is_done = csr_validate_sta_bcn_intrvl(mac_ctx, chnl_id,
2236 bcn_interval, session_id, &status);
2237 if (true == is_done)
2238 return status;
2239 break;
2240
2241 case QDF_P2P_CLIENT_MODE:
2242 is_done = csr_validate_p2pcli_bcn_intrvl(mac_ctx,
2243 chnl_id, bcn_interval, session_id,
2244 &status);
2245 if (true == is_done)
2246 return status;
2247 break;
2248
2249 case QDF_SAP_MODE:
2250 case QDF_IBSS_MODE:
2251 break;
2252
2253 case QDF_P2P_GO_MODE:
2254 is_done = csr_validate_p2pgo_bcn_intrvl(mac_ctx,
2255 chnl_id, bcn_interval,
2256 session_id, &status);
2257 if (true == is_done)
2258 return status;
2259 break;
2260
2261 default:
2262 sms_log(mac_ctx, LOGE,
2263 FL("Persona not supported : %d"),
2264 cur_bss_persona);
2265 return QDF_STATUS_E_FAILURE;
2266 }
2267 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302268 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002269}
2270
Deepak Dhamdhereadd334b2016-01-09 23:40:33 -08002271/**
2272 * csr_is_auth_type11r() - Check if Authentication type is 11R
2273 * @auth_type: The authentication type that is used to make the connection
2274 * @mdie_present: Is MDIE IE present
2275 *
2276 * Return: true if is 11R auth type, false otherwise
2277 */
2278bool csr_is_auth_type11r(eCsrAuthType auth_type, uint8_t mdie_present)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002279{
Deepak Dhamdhereadd334b2016-01-09 23:40:33 -08002280 switch (auth_type) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002281 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
Deepak Dhamdhereadd334b2016-01-09 23:40:33 -08002282 if (mdie_present)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002283 return true;
2284 break;
2285 case eCSR_AUTH_TYPE_FT_RSN_PSK:
2286 case eCSR_AUTH_TYPE_FT_RSN:
2287 return true;
2288 break;
2289 default:
2290 break;
2291 }
2292 return false;
2293}
2294
2295/* Function to return true if the profile is 11r */
2296bool csr_is_profile11r(tCsrRoamProfile *pProfile)
2297{
2298 return csr_is_auth_type11r(pProfile->negotiatedAuthType,
2299 pProfile->MDID.mdiePresent);
2300}
2301
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002302
2303#ifdef FEATURE_WLAN_ESE
2304
2305/* Function to return true if the authtype is ESE */
2306bool csr_is_auth_type_ese(eCsrAuthType AuthType)
2307{
2308 switch (AuthType) {
2309 case eCSR_AUTH_TYPE_CCKM_WPA:
2310 case eCSR_AUTH_TYPE_CCKM_RSN:
2311 return true;
2312 break;
2313 default:
2314 break;
2315 }
2316 return false;
2317}
2318
2319/* Function to return true if the profile is ESE */
2320bool csr_is_profile_ese(tCsrRoamProfile *pProfile)
2321{
2322 return csr_is_auth_type_ese(pProfile->negotiatedAuthType);
2323}
2324
2325#endif
2326
2327#ifdef FEATURE_WLAN_WAPI
2328bool csr_is_profile_wapi(tCsrRoamProfile *pProfile)
2329{
2330 bool fWapiProfile = false;
2331
2332 switch (pProfile->negotiatedAuthType) {
2333 case eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE:
2334 case eCSR_AUTH_TYPE_WAPI_WAI_PSK:
2335 fWapiProfile = true;
2336 break;
2337
2338 default:
2339 fWapiProfile = false;
2340 break;
2341 }
2342
2343 if (fWapiProfile) {
2344 switch (pProfile->negotiatedUCEncryptionType) {
2345 case eCSR_ENCRYPT_TYPE_WPI:
2346 fWapiProfile = true;
2347 break;
2348
2349 default:
2350 fWapiProfile = false;
2351 break;
2352 }
2353 }
2354 return fWapiProfile;
2355}
2356
2357static bool csr_is_wapi_oui_equal(tpAniSirGlobal pMac, uint8_t *Oui1,
2358 uint8_t *Oui2)
2359{
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302360 return !qdf_mem_cmp(Oui1, Oui2, CSR_WAPI_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002361}
2362
2363static bool csr_is_wapi_oui_match(tpAniSirGlobal pMac,
2364 uint8_t AllCyphers[][CSR_WAPI_OUI_SIZE],
2365 uint8_t cAllCyphers, uint8_t Cypher[],
2366 uint8_t Oui[])
2367{
2368 bool fYes = false;
2369 uint8_t idx;
2370
2371 for (idx = 0; idx < cAllCyphers; idx++) {
2372 if (csr_is_wapi_oui_equal(pMac, AllCyphers[idx], Cypher)) {
2373 fYes = true;
2374 break;
2375 }
2376 }
2377
2378 if (fYes && Oui) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302379 qdf_mem_copy(Oui, AllCyphers[idx], CSR_WAPI_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002380 }
2381
2382 return fYes;
2383}
2384#endif /* FEATURE_WLAN_WAPI */
2385
2386static bool csr_is_wpa_oui_equal(tpAniSirGlobal pMac, uint8_t *Oui1,
2387 uint8_t *Oui2)
2388{
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302389 return !qdf_mem_cmp(Oui1, Oui2, CSR_WPA_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002390}
2391
2392static bool csr_is_oui_match(tpAniSirGlobal pMac,
2393 uint8_t AllCyphers[][CSR_WPA_OUI_SIZE],
2394 uint8_t cAllCyphers, uint8_t Cypher[], uint8_t Oui[])
2395{
2396 bool fYes = false;
2397 uint8_t idx;
2398
2399 for (idx = 0; idx < cAllCyphers; idx++) {
2400 if (csr_is_wpa_oui_equal(pMac, AllCyphers[idx], Cypher)) {
2401 fYes = true;
2402 break;
2403 }
2404 }
2405
2406 if (fYes && Oui) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302407 qdf_mem_copy(Oui, AllCyphers[idx], CSR_WPA_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002408 }
2409
2410 return fYes;
2411}
2412
2413static bool csr_match_rsnoui_index(tpAniSirGlobal pMac,
2414 uint8_t AllCyphers[][CSR_RSN_OUI_SIZE],
2415 uint8_t cAllCyphers, uint8_t ouiIndex,
2416 uint8_t Oui[])
2417{
2418 return csr_is_oui_match
2419 (pMac, AllCyphers, cAllCyphers, csr_rsn_oui[ouiIndex], Oui);
2420
2421}
2422
2423#ifdef FEATURE_WLAN_WAPI
2424static bool csr_match_wapi_oui_index(tpAniSirGlobal pMac,
2425 uint8_t AllCyphers[][CSR_WAPI_OUI_SIZE],
2426 uint8_t cAllCyphers, uint8_t ouiIndex,
2427 uint8_t Oui[])
2428{
2429 return csr_is_wapi_oui_match
2430 (pMac, AllCyphers, cAllCyphers, csr_wapi_oui[ouiIndex], Oui);
2431
2432}
2433#endif /* FEATURE_WLAN_WAPI */
2434
2435static bool csr_match_wpaoui_index(tpAniSirGlobal pMac,
2436 uint8_t AllCyphers[][CSR_RSN_OUI_SIZE],
2437 uint8_t cAllCyphers, uint8_t ouiIndex,
2438 uint8_t Oui[])
2439{
2440 return csr_is_oui_match
2441 (pMac, AllCyphers, cAllCyphers, csr_wpa_oui[ouiIndex], Oui);
2442
2443}
2444
2445#ifdef FEATURE_WLAN_WAPI
2446static bool csr_is_auth_wapi_cert(tpAniSirGlobal pMac,
2447 uint8_t AllSuites[][CSR_WAPI_OUI_SIZE],
2448 uint8_t cAllSuites, uint8_t Oui[])
2449{
2450 return csr_is_wapi_oui_match
2451 (pMac, AllSuites, cAllSuites, csr_wapi_oui[1], Oui);
2452}
2453
2454static bool csr_is_auth_wapi_psk(tpAniSirGlobal pMac,
2455 uint8_t AllSuites[][CSR_WAPI_OUI_SIZE],
2456 uint8_t cAllSuites, uint8_t Oui[])
2457{
2458 return csr_is_wapi_oui_match
2459 (pMac, AllSuites, cAllSuites, csr_wapi_oui[2], Oui);
2460}
2461#endif /* FEATURE_WLAN_WAPI */
2462
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002463
2464/*
2465 * Function for 11R FT Authentication. We match the FT Authentication Cipher
2466 * suite here. This matches for FT Auth with the 802.1X exchange.
2467 */
2468static bool csr_is_ft_auth_rsn(tpAniSirGlobal pMac,
2469 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2470 uint8_t cAllSuites, uint8_t Oui[])
2471{
2472 return csr_is_oui_match
2473 (pMac, AllSuites, cAllSuites, csr_rsn_oui[03], Oui);
2474}
2475
2476/*
2477 * Function for 11R FT Authentication. We match the FT Authentication Cipher
2478 * suite here. This matches for FT Auth with the PSK.
2479 */
2480static bool csr_is_ft_auth_rsn_psk(tpAniSirGlobal pMac,
2481 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2482 uint8_t cAllSuites, uint8_t Oui[])
2483{
2484 return csr_is_oui_match
2485 (pMac, AllSuites, cAllSuites, csr_rsn_oui[04], Oui);
2486}
2487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488
2489#ifdef FEATURE_WLAN_ESE
2490
2491/*
2492 * Function for ESE CCKM AKM Authentication. We match the CCKM AKM
2493 * Authentication Key Management suite here. This matches for CCKM AKM Auth
2494 * with the 802.1X exchange.
2495 */
2496static bool csr_is_ese_cckm_auth_rsn(tpAniSirGlobal pMac,
2497 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2498 uint8_t cAllSuites, uint8_t Oui[])
2499{
2500 return csr_is_oui_match
2501 (pMac, AllSuites, cAllSuites, csr_rsn_oui[06], Oui);
2502}
2503
2504static bool csr_is_ese_cckm_auth_wpa(tpAniSirGlobal pMac,
2505 uint8_t AllSuites[][CSR_WPA_OUI_SIZE],
2506 uint8_t cAllSuites, uint8_t Oui[])
2507{
2508 return csr_is_oui_match
2509 (pMac, AllSuites, cAllSuites, csr_wpa_oui[06], Oui);
2510}
2511
2512#endif
2513
2514static bool csr_is_auth_rsn(tpAniSirGlobal pMac,
2515 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2516 uint8_t cAllSuites, uint8_t Oui[])
2517{
2518 return csr_is_oui_match
2519 (pMac, AllSuites, cAllSuites, csr_rsn_oui[01], Oui);
2520}
2521
2522static bool csr_is_auth_rsn_psk(tpAniSirGlobal pMac,
2523 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2524 uint8_t cAllSuites, uint8_t Oui[])
2525{
2526 return csr_is_oui_match
2527 (pMac, AllSuites, cAllSuites, csr_rsn_oui[02], Oui);
2528}
2529
2530#ifdef WLAN_FEATURE_11W
2531static bool csr_is_auth_rsn_psk_sha256(tpAniSirGlobal pMac,
2532 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2533 uint8_t cAllSuites, uint8_t Oui[])
2534{
2535 return csr_is_oui_match
2536 (pMac, AllSuites, cAllSuites, csr_rsn_oui[07], Oui);
2537}
2538static bool csr_is_auth_rsn8021x_sha256(tpAniSirGlobal pMac,
2539 uint8_t AllSuites[][CSR_RSN_OUI_SIZE],
2540 uint8_t cAllSuites, uint8_t Oui[])
2541{
2542 return csr_is_oui_match
2543 (pMac, AllSuites, cAllSuites, csr_rsn_oui[8], Oui);
2544}
2545#endif
2546
2547static bool csr_is_auth_wpa(tpAniSirGlobal pMac,
2548 uint8_t AllSuites[][CSR_WPA_OUI_SIZE],
2549 uint8_t cAllSuites, uint8_t Oui[])
2550{
2551 return csr_is_oui_match
2552 (pMac, AllSuites, cAllSuites, csr_wpa_oui[01], Oui);
2553}
2554
2555static bool csr_is_auth_wpa_psk(tpAniSirGlobal pMac,
2556 uint8_t AllSuites[][CSR_WPA_OUI_SIZE],
2557 uint8_t cAllSuites, uint8_t Oui[])
2558{
2559 return csr_is_oui_match
2560 (pMac, AllSuites, cAllSuites, csr_wpa_oui[02], Oui);
2561}
2562
2563uint8_t csr_get_oui_index_from_cipher(eCsrEncryptionType enType)
2564{
2565 uint8_t OUIIndex;
2566
2567 switch (enType) {
2568 case eCSR_ENCRYPT_TYPE_WEP40:
2569 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
2570 OUIIndex = CSR_OUI_WEP40_OR_1X_INDEX;
2571 break;
2572 case eCSR_ENCRYPT_TYPE_WEP104:
2573 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
2574 OUIIndex = CSR_OUI_WEP104_INDEX;
2575 break;
2576 case eCSR_ENCRYPT_TYPE_TKIP:
2577 OUIIndex = CSR_OUI_TKIP_OR_PSK_INDEX;
2578 break;
2579 case eCSR_ENCRYPT_TYPE_AES:
2580 OUIIndex = CSR_OUI_AES_INDEX;
2581 break;
2582 case eCSR_ENCRYPT_TYPE_NONE:
2583 OUIIndex = CSR_OUI_USE_GROUP_CIPHER_INDEX;
2584 break;
2585#ifdef FEATURE_WLAN_WAPI
2586 case eCSR_ENCRYPT_TYPE_WPI:
2587 OUIIndex = CSR_OUI_WAPI_WAI_CERT_OR_SMS4_INDEX;
2588 break;
2589#endif /* FEATURE_WLAN_WAPI */
2590 default: /* HOWTO handle this? */
2591 OUIIndex = CSR_OUI_RESERVED_INDEX;
2592 break;
2593 } /* switch */
2594
2595 return OUIIndex;
2596}
2597/**
2598 * csr_get_rsn_information() - to get RSN infomation
2599 * @hal: pointer to HAL
2600 * @auth_type: auth type
2601 * @encr_type: encryption type
2602 * @mc_encryption: multicast encryption type
2603 * @rsn_ie: pointer to RSN IE
2604 * @ucast_cipher: Unicast cipher
2605 * @mcast_cipher: Multicast cipher
2606 * @auth_suite: Authentication suite
2607 * @capabilities: RSN capabilities
2608 * @negotiated_authtype: Negotiated auth type
2609 * @negotiated_mccipher: negotiated multicast cipher
2610 *
2611 * This routine will get all RSN information
2612 *
2613 * Return: bool
2614 */
2615bool csr_get_rsn_information(tHalHandle hal, tCsrAuthList *auth_type,
2616 eCsrEncryptionType encr_type,
2617 tCsrEncryptionList *mc_encryption,
2618 tDot11fIERSN *rsn_ie, uint8_t *ucast_cipher,
2619 uint8_t *mcast_cipher, uint8_t *auth_suite,
2620 tCsrRSNCapabilities *capabilities,
2621 eCsrAuthType *negotiated_authtype,
2622 eCsrEncryptionType *negotiated_mccipher)
2623{
2624 tpAniSirGlobal mac_ctx = PMAC_STRUCT(hal);
2625 bool acceptable_cipher = false;
2626 uint8_t c_ucast_cipher = 0;
2627 uint8_t c_mcast_cipher = 0;
2628 uint8_t c_auth_suites = 0, i;
2629 uint8_t unicast[CSR_RSN_OUI_SIZE];
2630 uint8_t multicast[CSR_RSN_OUI_SIZE];
2631 uint8_t authsuites[CSR_RSN_MAX_AUTH_SUITES][CSR_RSN_OUI_SIZE];
2632 uint8_t authentication[CSR_RSN_OUI_SIZE];
2633 uint8_t mccipher_arr[CSR_RSN_MAX_MULTICAST_CYPHERS][CSR_RSN_OUI_SIZE];
2634 eCsrAuthType neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
2635
2636 if (!rsn_ie->present)
2637 goto end;
2638 c_mcast_cipher++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302639 qdf_mem_copy(mccipher_arr, rsn_ie->gp_cipher_suite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002640 CSR_RSN_OUI_SIZE);
2641 c_ucast_cipher =
2642 (uint8_t) (rsn_ie->pwise_cipher_suite_count);
2643 c_auth_suites = (uint8_t) (rsn_ie->akm_suite_count);
2644 for (i = 0; i < c_auth_suites && i < CSR_RSN_MAX_AUTH_SUITES; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302645 qdf_mem_copy((void *)&authsuites[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002646 (void *)&rsn_ie->akm_suites[i], CSR_RSN_OUI_SIZE);
2647 }
2648
2649 /* Check - Is requested unicast Cipher supported by the BSS. */
2650 acceptable_cipher = csr_match_rsnoui_index(mac_ctx,
2651 rsn_ie->pwise_cipher_suites, c_ucast_cipher,
2652 csr_get_oui_index_from_cipher(encr_type),
2653 unicast);
2654
2655 if (!acceptable_cipher)
2656 goto end;
2657
2658 /* unicast is supported. Pick the first matching Group cipher, if any */
2659 for (i = 0; i < mc_encryption->numEntries; i++) {
2660 acceptable_cipher = csr_match_rsnoui_index(mac_ctx,
2661 mccipher_arr, c_mcast_cipher,
2662 csr_get_oui_index_from_cipher(
2663 mc_encryption->encryptionType[i]),
2664 multicast);
2665 if (acceptable_cipher)
2666 break;
2667 }
2668 if (!acceptable_cipher)
2669 goto end;
2670
2671 if (negotiated_mccipher)
2672 *negotiated_mccipher = mc_encryption->encryptionType[i];
2673
2674 /* Initializing with false as it has true value already */
2675 acceptable_cipher = false;
2676 for (i = 0; i < auth_type->numEntries; i++) {
2677 /*
2678 * Ciphers are supported, Match authentication algorithm and
2679 * pick first matching authtype.
2680 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681 /* Changed the AKM suites according to order of preference */
2682 if (csr_is_ft_auth_rsn(mac_ctx, authsuites,
2683 c_auth_suites, authentication)) {
2684 if (eCSR_AUTH_TYPE_FT_RSN == auth_type->authType[i])
2685 neg_authtype = eCSR_AUTH_TYPE_FT_RSN;
2686 }
2687 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
2688 && csr_is_ft_auth_rsn_psk(mac_ctx, authsuites,
2689 c_auth_suites, authentication)) {
2690 if (eCSR_AUTH_TYPE_FT_RSN_PSK ==
2691 auth_type->authType[i])
2692 neg_authtype = eCSR_AUTH_TYPE_FT_RSN_PSK;
2693 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002694#ifdef FEATURE_WLAN_ESE
2695 /* ESE only supports 802.1X. No PSK. */
2696 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
2697 csr_is_ese_cckm_auth_rsn(mac_ctx, authsuites,
2698 c_auth_suites, authentication)) {
2699 if (eCSR_AUTH_TYPE_CCKM_RSN == auth_type->authType[i])
2700 neg_authtype = eCSR_AUTH_TYPE_CCKM_RSN;
2701 }
2702#endif
2703 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
2704 && csr_is_auth_rsn(mac_ctx, authsuites,
2705 c_auth_suites, authentication)) {
2706 if (eCSR_AUTH_TYPE_RSN == auth_type->authType[i])
2707 neg_authtype = eCSR_AUTH_TYPE_RSN;
2708 }
2709 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
2710 && csr_is_auth_rsn_psk(mac_ctx, authsuites,
2711 c_auth_suites, authentication)) {
2712 if (eCSR_AUTH_TYPE_RSN_PSK == auth_type->authType[i])
2713 neg_authtype = eCSR_AUTH_TYPE_RSN_PSK;
2714 }
2715#ifdef WLAN_FEATURE_11W
2716 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
2717 && csr_is_auth_rsn_psk_sha256(mac_ctx, authsuites,
2718 c_auth_suites, authentication)) {
2719 if (eCSR_AUTH_TYPE_RSN_PSK_SHA256 ==
2720 auth_type->authType[i])
2721 neg_authtype = eCSR_AUTH_TYPE_RSN_PSK_SHA256;
2722 }
2723 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
2724 csr_is_auth_rsn8021x_sha256(mac_ctx, authsuites,
2725 c_auth_suites, authentication)) {
2726 if (eCSR_AUTH_TYPE_RSN_8021X_SHA256 ==
2727 auth_type->authType[i])
2728 neg_authtype = eCSR_AUTH_TYPE_RSN_8021X_SHA256;
2729 }
2730#endif
2731
2732 /*
2733 * The 1st auth type in the APs RSN IE, to match stations
2734 * connecting profiles auth type will cause us to exit this
2735 * loop. This is added as some APs advertise multiple akms in
2736 * the RSN IE
2737 */
2738 if (eCSR_AUTH_TYPE_UNKNOWN != neg_authtype) {
2739 acceptable_cipher = true;
2740 break;
2741 }
2742 } /* for */
2743end:
2744 if (acceptable_cipher) {
2745 if (mcast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302746 qdf_mem_copy(mcast_cipher, multicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747 CSR_RSN_OUI_SIZE);
2748
2749 if (ucast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302750 qdf_mem_copy(ucast_cipher, unicast, CSR_RSN_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751
2752 if (auth_suite)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302753 qdf_mem_copy(auth_suite, authentication,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002754 CSR_RSN_OUI_SIZE);
2755
2756 if (negotiated_authtype)
2757 *negotiated_authtype = neg_authtype;
2758
2759 if (capabilities) {
2760 /* Bit 0 Preauthentication */
2761 capabilities->PreAuthSupported =
2762 (rsn_ie->RSN_Cap[0] >> 0) & 0x1;
2763 /* Bit 1 No Pairwise */
2764 capabilities->NoPairwise =
2765 (rsn_ie->RSN_Cap[0] >> 1) & 0x1;
2766 /* Bit 2, 3 PTKSA Replay Counter */
2767 capabilities->PTKSAReplayCounter =
2768 (rsn_ie->RSN_Cap[0] >> 2) & 0x3;
2769 /* Bit 4, 5 GTKSA Replay Counter */
2770 capabilities->GTKSAReplayCounter =
2771 (rsn_ie->RSN_Cap[0] >> 4) & 0x3;
2772#ifdef WLAN_FEATURE_11W
2773 /* Bit 6 MFPR */
2774 capabilities->MFPRequired =
2775 (rsn_ie->RSN_Cap[0] >> 6) & 0x1;
2776 /* Bit 7 MFPC */
2777 capabilities->MFPCapable =
2778 (rsn_ie->RSN_Cap[0] >> 7) & 0x1;
2779#else
2780 /* Bit 6 MFPR */
2781 capabilities->MFPRequired = 0;
2782 /* Bit 7 MFPC */
2783 capabilities->MFPCapable = 0;
2784#endif
2785 /* remaining reserved */
2786 capabilities->Reserved = rsn_ie->RSN_Cap[1] & 0xff;
2787 }
2788 }
2789 return acceptable_cipher;
2790}
2791
2792#ifdef WLAN_FEATURE_11W
2793/**
2794 * csr_is_pmf_capabilities_in_rsn_match() - check for PMF capability
2795 * @hHal: Global HAL handle
2796 * @pFilterMFPEnabled: given by supplicant to us to specify what kind
2797 * of connection supplicant is expecting to make
2798 * if it is enabled then make PMF connection.
2799 * if it is disabled then make normal connection.
2800 * @pFilterMFPRequired: given by supplicant based on our configuration
2801 * if it is 1 then we will require mandatory
2802 * PMF connection and if it is 0 then we PMF
2803 * connection is optional.
2804 * @pFilterMFPCapable: given by supplicant based on our configuration
2805 * if it 1 then we are PMF capable and if it 0
2806 * then we are not PMF capable.
2807 * @pRSNIe: RSNIe from Beacon/probe response of
2808 * neighbor AP against which we will compare
2809 * our capabilities.
2810 *
2811 * This function is to match our current capabilities with the AP
2812 * to which we are expecting make the connection.
2813 *
2814 * Return: if our PMF capabilities matches with AP then we
2815 * will return true to indicate that we are good
2816 * to make connection with it. Else we will return false
2817 **/
2818static bool
2819csr_is_pmf_capabilities_in_rsn_match(tHalHandle hHal,
2820 bool *pFilterMFPEnabled,
2821 uint8_t *pFilterMFPRequired,
2822 uint8_t *pFilterMFPCapable,
2823 tDot11fIERSN *pRSNIe)
2824{
2825 uint8_t apProfileMFPCapable = 0;
2826 uint8_t apProfileMFPRequired = 0;
2827 if (pRSNIe && pFilterMFPEnabled && pFilterMFPCapable
2828 && pFilterMFPRequired) {
2829 /* Extracting MFPCapable bit from RSN Ie */
2830 apProfileMFPCapable = (pRSNIe->RSN_Cap[0] >> 7) & 0x1;
2831 apProfileMFPRequired = (pRSNIe->RSN_Cap[0] >> 6) & 0x1;
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05302832
2833 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
2834 FL("pFilterMFPEnabled=%d pFilterMFPRequired=%d"
2835 "pFilterMFPCapable=%d apProfileMFPCapable=%d"
2836 "apProfileMFPRequired=%d"),
2837 *pFilterMFPEnabled, *pFilterMFPRequired,
2838 *pFilterMFPCapable, apProfileMFPCapable,
2839 apProfileMFPRequired);
2840
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002841 if (*pFilterMFPEnabled && *pFilterMFPCapable
2842 && *pFilterMFPRequired && (apProfileMFPCapable == 0)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302843 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002844 "AP is not capable to make PMF connection");
2845 return false;
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05302846 } else if (!(*pFilterMFPCapable) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002847 apProfileMFPCapable && apProfileMFPRequired) {
2848
2849 /*
2850 * In this case, AP with whom we trying to connect
2851 * requires mandatory PMF connections and we are not
2852 * capable so this AP is not good choice to connect
2853 */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302854 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855 "AP needs PMF connection and we are not capable of pmf connection");
2856 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002857 }
2858 }
2859 return true;
2860}
2861#endif
2862
2863bool csr_is_rsn_match(tHalHandle hHal, tCsrAuthList *pAuthType,
2864 eCsrEncryptionType enType,
2865 tCsrEncryptionList *pEnMcType,
2866 bool *pMFPEnabled, uint8_t *pMFPRequired,
2867 uint8_t *pMFPCapable,
2868 tDot11fBeaconIEs *pIes,
2869 eCsrAuthType *pNegotiatedAuthType,
2870 eCsrEncryptionType *pNegotiatedMCCipher)
2871{
2872 bool fRSNMatch = false;
2873
2874 /* See if the cyphers in the Bss description match with the settings in the profile. */
2875 fRSNMatch =
2876 csr_get_rsn_information(hHal, pAuthType, enType, pEnMcType, &pIes->RSN,
2877 NULL, NULL, NULL, NULL, pNegotiatedAuthType,
2878 pNegotiatedMCCipher);
2879#ifdef WLAN_FEATURE_11W
2880 /* If all the filter matches then finally checks for PMF capabilities */
2881 if (fRSNMatch) {
2882 fRSNMatch = csr_is_pmf_capabilities_in_rsn_match(hHal, pMFPEnabled,
2883 pMFPRequired,
2884 pMFPCapable,
2885 &pIes->RSN);
2886 }
2887#endif
2888 return fRSNMatch;
2889}
2890
2891bool csr_lookup_pmkid(tpAniSirGlobal pMac, uint32_t sessionId, uint8_t *pBSSId,
2892 uint8_t *pPMKId)
2893{
2894 bool fRC = false, fMatchFound = false;
2895 uint32_t Index;
2896 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
2897
2898 if (!pSession) {
2899 sms_log(pMac, LOGE, FL(" session %d not found "), sessionId);
2900 return false;
2901 }
2902
2903 do {
2904 for (Index = 0; Index < CSR_MAX_PMKID_ALLOWED; Index++) {
2905 sms_log(pMac, LOG1,
2906 "match PMKID " MAC_ADDRESS_STR " to ",
2907 MAC_ADDR_ARRAY(pBSSId));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302908 if (!qdf_mem_cmp
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002909 (pBSSId, pSession->PmkidCacheInfo[Index].BSSID.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05302910 sizeof(struct qdf_mac_addr))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911 /* match found */
2912 fMatchFound = true;
2913 break;
2914 }
2915 }
2916
2917 if (!fMatchFound)
2918 break;
2919
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302920 qdf_mem_copy(pPMKId, pSession->PmkidCacheInfo[Index].PMKID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921 CSR_RSN_PMKID_SIZE);
2922
2923 fRC = true;
2924 } while (0);
2925 sms_log(pMac, LOGW,
2926 "csr_lookup_pmkid called return match = %d pMac->roam.NumPmkidCache = %d",
2927 fRC, pSession->NumPmkidCache);
2928
2929 return fRC;
2930}
2931
2932uint8_t csr_construct_rsn_ie(tHalHandle hHal, uint32_t sessionId,
2933 tCsrRoamProfile *pProfile,
2934 tSirBssDescription *pSirBssDesc,
2935 tDot11fBeaconIEs *pIes, tCsrRSNIe *pRSNIe)
2936{
2937 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
2938 bool fRSNMatch;
2939 uint8_t cbRSNIe = 0;
2940 uint8_t UnicastCypher[CSR_RSN_OUI_SIZE];
2941 uint8_t MulticastCypher[CSR_RSN_OUI_SIZE];
2942 uint8_t AuthSuite[CSR_RSN_OUI_SIZE];
2943 tCsrRSNAuthIe *pAuthSuite;
2944 tCsrRSNCapabilities RSNCapabilities;
2945 tCsrRSNPMKIe *pPMK;
2946 uint8_t PMKId[CSR_RSN_PMKID_SIZE];
2947#ifdef WLAN_FEATURE_11W
2948 uint8_t *pGroupMgmtCipherSuite;
2949#endif
2950 tDot11fBeaconIEs *pIesLocal = pIes;
2951 eCsrAuthType negAuthType = eCSR_AUTH_TYPE_UNKNOWN;
2952
2953 sms_log(pMac, LOGW, "%s called...", __func__);
2954
2955 do {
2956 if (!csr_is_profile_rsn(pProfile))
2957 break;
2958
2959 if (!pIesLocal
2960 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302961 (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002962 (csr_get_parsed_bss_description_ies
2963 (pMac, pSirBssDesc, &pIesLocal)))) {
2964 break;
2965 }
2966 /* See if the cyphers in the Bss description match with the settings in the profile. */
2967 fRSNMatch =
2968 csr_get_rsn_information(hHal, &pProfile->AuthType,
2969 pProfile->negotiatedUCEncryptionType,
2970 &pProfile->mcEncryptionType,
2971 &pIesLocal->RSN, UnicastCypher,
2972 MulticastCypher, AuthSuite,
2973 &RSNCapabilities, &negAuthType, NULL);
2974 if (!fRSNMatch)
2975 break;
2976
2977 pRSNIe->IeHeader.ElementID = SIR_MAC_RSN_EID;
2978
2979 pRSNIe->Version = CSR_RSN_VERSION_SUPPORTED;
2980
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302981 qdf_mem_copy(pRSNIe->MulticastOui, MulticastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982 sizeof(MulticastCypher));
2983
2984 pRSNIe->cUnicastCyphers = 1;
2985
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302986 qdf_mem_copy(&pRSNIe->UnicastOui[0], UnicastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002987 sizeof(UnicastCypher));
2988
2989 pAuthSuite =
2990 (tCsrRSNAuthIe *) (&pRSNIe->
2991 UnicastOui[pRSNIe->cUnicastCyphers]);
2992
2993 pAuthSuite->cAuthenticationSuites = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302994 qdf_mem_copy(&pAuthSuite->AuthOui[0], AuthSuite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002995 sizeof(AuthSuite));
2996
2997 /* RSN capabilities follows the Auth Suite (two octects) */
2998 /* !!REVIEW - What should STA put in RSN capabilities, currently */
2999 /* just putting back APs capabilities */
3000 /* For one, we shouldn't EVER be sending out "pre-auth supported". It is an AP only capability */
3001 /* For another, we should use the Management Frame Protection values given by the supplicant */
3002 RSNCapabilities.PreAuthSupported = 0;
3003#ifdef WLAN_FEATURE_11W
3004 if (RSNCapabilities.MFPCapable && pProfile->MFPCapable) {
3005 RSNCapabilities.MFPCapable = pProfile->MFPCapable;
3006 RSNCapabilities.MFPRequired = pProfile->MFPRequired;
3007 } else {
3008 RSNCapabilities.MFPCapable = 0;
3009 RSNCapabilities.MFPRequired = 0;
3010 }
3011#endif
3012 *(uint16_t *) (&pAuthSuite->AuthOui[1]) =
3013 *((uint16_t *) (&RSNCapabilities));
3014
3015 pPMK =
3016 (tCsrRSNPMKIe *) (((uint8_t *) (&pAuthSuite->AuthOui[1])) +
3017 sizeof(uint16_t));
3018
3019 /* Don't include the PMK SA IDs for CCKM associations. */
3020 if (
3021#ifdef FEATURE_WLAN_ESE
3022 (eCSR_AUTH_TYPE_CCKM_RSN != negAuthType) &&
3023#endif
3024 csr_lookup_pmkid(pMac, sessionId, pSirBssDesc->bssId,
3025 &(PMKId[0]))) {
3026 pPMK->cPMKIDs = 1;
3027
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303028 qdf_mem_copy(pPMK->PMKIDList[0].PMKID, PMKId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 CSR_RSN_PMKID_SIZE);
3030 } else {
3031 pPMK->cPMKIDs = 0;
3032 }
3033
3034#ifdef WLAN_FEATURE_11W
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05303035 /* Advertise BIP in group cipher key management only if PMF is
3036 * enabled and AP is capable.
3037 */
3038 if (pProfile->MFPEnabled &&
3039 (RSNCapabilities.MFPCapable && pProfile->MFPCapable)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040 pGroupMgmtCipherSuite =
3041 (uint8_t *) pPMK + sizeof(uint16_t) +
3042 (pPMK->cPMKIDs * CSR_RSN_PMKID_SIZE);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303043 qdf_mem_copy(pGroupMgmtCipherSuite, csr_rsn_oui[07],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003044 CSR_WPA_OUI_SIZE);
3045 }
3046#endif
3047
3048 /* Add in the fixed fields plus 1 Unicast cypher, less the IE Header length */
3049 /* Add in the size of the Auth suite (count plus a single OUI) */
3050 /* Add in the RSN caps field. */
3051 /* Add PMKID count and PMKID (if any) */
3052 /* Add group management cipher suite */
3053 pRSNIe->IeHeader.Length =
3054 (uint8_t) (sizeof(*pRSNIe) - sizeof(pRSNIe->IeHeader) +
3055 sizeof(*pAuthSuite) +
3056 sizeof(tCsrRSNCapabilities));
3057 if (pPMK->cPMKIDs) {
3058 pRSNIe->IeHeader.Length += (uint8_t) (sizeof(uint16_t) +
3059 (pPMK->cPMKIDs *
3060 CSR_RSN_PMKID_SIZE));
3061 }
3062#ifdef WLAN_FEATURE_11W
Deepthi Gowri9f2fc782016-09-01 12:31:18 +05303063 if (pProfile->MFPEnabled &&
3064 (RSNCapabilities.MFPCapable && pProfile->MFPCapable)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003065 if (0 == pPMK->cPMKIDs)
3066 pRSNIe->IeHeader.Length += sizeof(uint16_t);
3067 pRSNIe->IeHeader.Length += CSR_WPA_OUI_SIZE;
3068 }
3069#endif
3070
3071 /* return the size of the IE header (total) constructed... */
3072 cbRSNIe = pRSNIe->IeHeader.Length + sizeof(pRSNIe->IeHeader);
3073
3074 } while (0);
3075
3076 if (!pIes && pIesLocal) {
3077 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303078 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003079 }
3080
3081 return cbRSNIe;
3082}
3083
3084#ifdef FEATURE_WLAN_WAPI
3085/**
3086 * csr_get_wapi_information() - to get WAPI infomation
3087 * @hal: pointer to HAL
3088 * @auth_type: auth type
3089 * @encr_type: encryption type
3090 * @mc_encryption: multicast encryption type
3091 * @wapi_ie: pointer to WAPI IE
3092 * @ucast_cipher: Unicast cipher
3093 * @mcast_cipher: Multicast cipher
3094 * @auth_suite: Authentication suite
3095 * @negotiated_authtype: Negotiated auth type
3096 * @negotiated_mccipher: negotiated multicast cipher
3097 *
3098 * This routine will get all WAPI information
3099 *
3100 * Return: bool
3101 */
3102bool csr_get_wapi_information(tHalHandle hal, tCsrAuthList *auth_type,
3103 eCsrEncryptionType encr_type,
3104 tCsrEncryptionList *mc_encryption,
3105 tDot11fIEWAPI *wapi_ie, uint8_t *ucast_cipher,
3106 uint8_t *mcast_cipher, uint8_t *auth_suite,
3107 eCsrAuthType *negotiated_authtype,
3108 eCsrEncryptionType *negotiated_mccipher)
3109{
3110 tpAniSirGlobal mac_ctx = PMAC_STRUCT(hal);
3111 bool acceptable_cipher = false;
3112 uint8_t c_ucast_cipher = 0;
3113 uint8_t c_mcast_cipher = 0;
3114 uint8_t c_auth_suites = 0, i;
3115 uint8_t unicast[CSR_WAPI_OUI_SIZE];
3116 uint8_t multicast[CSR_WAPI_OUI_SIZE];
3117 uint8_t authsuites[CSR_WAPI_MAX_AUTH_SUITES][CSR_WAPI_OUI_SIZE];
3118 uint8_t authentication[CSR_WAPI_OUI_SIZE];
3119 uint8_t mccipher_arr[CSR_WAPI_MAX_MULTICAST_CYPHERS][CSR_WAPI_OUI_SIZE];
3120 eCsrAuthType neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
3121 uint8_t wapioui_idx = 0;
3122
3123 if (!wapi_ie->present)
3124 goto end;
3125
3126 c_mcast_cipher++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303127 qdf_mem_copy(mccipher_arr, wapi_ie->multicast_cipher_suite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128 CSR_WAPI_OUI_SIZE);
3129 c_ucast_cipher = (uint8_t) (wapi_ie->unicast_cipher_suite_count);
3130 c_auth_suites = (uint8_t) (wapi_ie->akm_suite_count);
3131 for (i = 0; i < c_auth_suites && i < CSR_WAPI_MAX_AUTH_SUITES; i++)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303132 qdf_mem_copy((void *)&authsuites[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133 (void *)&wapi_ie->akm_suites[i], CSR_WAPI_OUI_SIZE);
3134
3135 wapioui_idx = csr_get_oui_index_from_cipher(encr_type);
3136 if (wapioui_idx >= CSR_OUI_WAPI_WAI_MAX_INDEX) {
3137 sms_log(mac_ctx, LOGE,
3138 FL("Wapi OUI index = %d out of limit"),
3139 wapioui_idx);
3140 acceptable_cipher = false;
3141 goto end;
3142 }
3143 /* Check - Is requested unicast Cipher supported by the BSS. */
3144 acceptable_cipher = csr_match_wapi_oui_index(mac_ctx,
3145 wapi_ie->unicast_cipher_suites,
3146 c_ucast_cipher, wapioui_idx, unicast);
3147 if (!acceptable_cipher)
3148 goto end;
3149
3150 /* unicast is supported. Pick the first matching Group cipher, if any */
3151 for (i = 0; i < mc_encryption->numEntries; i++) {
3152 wapioui_idx = csr_get_oui_index_from_cipher(
3153 mc_encryption->encryptionType[i]);
3154 if (wapioui_idx >= CSR_OUI_WAPI_WAI_MAX_INDEX) {
3155 sms_log(mac_ctx, LOGE,
3156 FL("Wapi OUI index = %d out of limit"),
3157 wapioui_idx);
3158 acceptable_cipher = false;
3159 break;
3160 }
3161 acceptable_cipher = csr_match_wapi_oui_index(mac_ctx,
3162 mccipher_arr, c_mcast_cipher,
3163 wapioui_idx, multicast);
3164 if (acceptable_cipher)
3165 break;
3166 }
3167 if (!acceptable_cipher)
3168 goto end;
3169
3170 if (negotiated_mccipher)
3171 *negotiated_mccipher =
3172 mc_encryption->encryptionType[i];
3173
3174 /*
3175 * Ciphers are supported, Match authentication algorithm and
3176 * pick first matching authtype
3177 */
3178 if (csr_is_auth_wapi_cert
3179 (mac_ctx, authsuites, c_auth_suites, authentication)) {
3180 neg_authtype =
3181 eCSR_AUTH_TYPE_WAPI_WAI_CERTIFICATE;
3182 } else if (csr_is_auth_wapi_psk(mac_ctx, authsuites,
3183 c_auth_suites, authentication)) {
3184 neg_authtype = eCSR_AUTH_TYPE_WAPI_WAI_PSK;
3185 } else {
3186 acceptable_cipher = false;
3187 neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
3188 }
3189
3190 /* Caller doesn't care about auth type, or BSS doesn't match */
3191 if ((0 == auth_type->numEntries) || (false == acceptable_cipher))
3192 goto end;
3193
3194 acceptable_cipher = false;
3195 for (i = 0; i < auth_type->numEntries; i++) {
3196 if (auth_type->authType[i] == neg_authtype) {
3197 acceptable_cipher = true;
3198 break;
3199 }
3200 }
3201
3202end:
3203 if (acceptable_cipher) {
3204 if (mcast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303205 qdf_mem_copy(mcast_cipher, multicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206 CSR_WAPI_OUI_SIZE);
3207 if (ucast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303208 qdf_mem_copy(ucast_cipher, unicast, CSR_WAPI_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209 if (auth_suite)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303210 qdf_mem_copy(auth_suite, authentication,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211 CSR_WAPI_OUI_SIZE);
3212 if (negotiated_authtype)
3213 *negotiated_authtype = neg_authtype;
3214 }
3215 return acceptable_cipher;
3216}
3217
3218bool csr_is_wapi_match(tHalHandle hHal, tCsrAuthList *pAuthType,
3219 eCsrEncryptionType enType, tCsrEncryptionList *pEnMcType,
3220 tDot11fBeaconIEs *pIes, eCsrAuthType *pNegotiatedAuthType,
3221 eCsrEncryptionType *pNegotiatedMCCipher)
3222{
3223 bool fWapiMatch = false;
3224
3225 /* See if the cyphers in the Bss description match with the settings in the profile. */
3226 fWapiMatch =
3227 csr_get_wapi_information(hHal, pAuthType, enType, pEnMcType,
3228 &pIes->WAPI, NULL, NULL, NULL,
3229 pNegotiatedAuthType, pNegotiatedMCCipher);
3230
3231 return fWapiMatch;
3232}
3233
3234bool csr_lookup_bkid(tpAniSirGlobal pMac, uint32_t sessionId, uint8_t *pBSSId,
3235 uint8_t *pBKId)
3236{
3237 bool fRC = false, fMatchFound = false;
3238 uint32_t Index;
3239 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
3240
3241 if (!pSession) {
3242 sms_log(pMac, LOGE, FL(" session %d not found "), sessionId);
3243 return false;
3244 }
3245
3246 do {
3247 for (Index = 0; Index < pSession->NumBkidCache; Index++) {
3248 sms_log(pMac, LOGW, "match BKID " MAC_ADDRESS_STR " to ",
3249 MAC_ADDR_ARRAY(pBSSId));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303250 if (!qdf_mem_cmp
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 (pBSSId, pSession->BkidCacheInfo[Index].BSSID.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303252 sizeof(struct qdf_mac_addr))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253 /* match found */
3254 fMatchFound = true;
3255 break;
3256 }
3257 }
3258
3259 if (!fMatchFound)
3260 break;
3261
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303262 qdf_mem_copy(pBKId, pSession->BkidCacheInfo[Index].BKID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263 CSR_WAPI_BKID_SIZE);
3264
3265 fRC = true;
3266 } while (0);
3267 sms_log(pMac, LOGW,
3268 "csr_lookup_bkid called return match = %d pMac->roam.NumBkidCache = %d",
3269 fRC, pSession->NumBkidCache);
3270
3271 return fRC;
3272}
3273
3274uint8_t csr_construct_wapi_ie(tpAniSirGlobal pMac, uint32_t sessionId,
3275 tCsrRoamProfile *pProfile,
3276 tSirBssDescription *pSirBssDesc,
3277 tDot11fBeaconIEs *pIes, tCsrWapiIe *pWapiIe)
3278{
3279 bool fWapiMatch = false;
3280 uint8_t cbWapiIe = 0;
3281 uint8_t UnicastCypher[CSR_WAPI_OUI_SIZE];
3282 uint8_t MulticastCypher[CSR_WAPI_OUI_SIZE];
3283 uint8_t AuthSuite[CSR_WAPI_OUI_SIZE];
3284 uint8_t BKId[CSR_WAPI_BKID_SIZE];
3285 uint8_t *pWapi = NULL;
3286 bool fBKIDFound = false;
3287 tDot11fBeaconIEs *pIesLocal = pIes;
3288
3289 do {
3290 if (!csr_is_profile_wapi(pProfile))
3291 break;
3292
3293 if (!pIesLocal
3294 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303295 (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296 (csr_get_parsed_bss_description_ies
3297 (pMac, pSirBssDesc, &pIesLocal)))) {
3298 break;
3299 }
3300 /* See if the cyphers in the Bss description match with the settings in the profile. */
3301 fWapiMatch =
3302 csr_get_wapi_information(pMac, &pProfile->AuthType,
3303 pProfile->negotiatedUCEncryptionType,
3304 &pProfile->mcEncryptionType,
3305 &pIesLocal->WAPI, UnicastCypher,
3306 MulticastCypher, AuthSuite, NULL,
3307 NULL);
3308 if (!fWapiMatch)
3309 break;
3310
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303311 qdf_mem_set(pWapiIe, sizeof(tCsrWapiIe), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312
3313 pWapiIe->IeHeader.ElementID = DOT11F_EID_WAPI;
3314
3315 pWapiIe->Version = CSR_WAPI_VERSION_SUPPORTED;
3316
3317 pWapiIe->cAuthenticationSuites = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303318 qdf_mem_copy(&pWapiIe->AuthOui[0], AuthSuite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003319 sizeof(AuthSuite));
3320
3321 pWapi = (uint8_t *) (&pWapiIe->AuthOui[1]);
3322
3323 *pWapi = (uint16_t) 1; /* cUnicastCyphers */
3324 pWapi += 2;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303325 qdf_mem_copy(pWapi, UnicastCypher, sizeof(UnicastCypher));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326 pWapi += sizeof(UnicastCypher);
3327
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303328 qdf_mem_copy(pWapi, MulticastCypher, sizeof(MulticastCypher));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329 pWapi += sizeof(MulticastCypher);
3330
3331 /* WAPI capabilities follows the Auth Suite (two octects) */
3332 /* we shouldn't EVER be sending out "pre-auth supported". It is an AP only capability */
3333 /* & since we already did a memset pWapiIe to 0, skip these fields */
3334 pWapi += 2;
3335
3336 fBKIDFound =
3337 csr_lookup_bkid(pMac, sessionId, pSirBssDesc->bssId,
3338 &(BKId[0]));
3339
3340 if (fBKIDFound) {
3341 /* Do we need to change the endianness here */
3342 *pWapi = (uint16_t) 1; /* cBKIDs */
3343 pWapi += 2;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303344 qdf_mem_copy(pWapi, BKId, CSR_WAPI_BKID_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003345 } else {
3346 *pWapi = 0;
3347 pWapi += 1;
3348 *pWapi = 0;
3349 pWapi += 1;
3350 }
3351
3352 /* Add in the IE fields except the IE header */
3353 /* Add BKID count and BKID (if any) */
3354 pWapiIe->IeHeader.Length =
3355 (uint8_t) (sizeof(*pWapiIe) - sizeof(pWapiIe->IeHeader));
3356
3357 /*2 bytes for BKID Count field */
3358 pWapiIe->IeHeader.Length += sizeof(uint16_t);
3359
3360 if (fBKIDFound) {
3361 pWapiIe->IeHeader.Length += CSR_WAPI_BKID_SIZE;
3362 }
3363 /* return the size of the IE header (total) constructed... */
3364 cbWapiIe = pWapiIe->IeHeader.Length + sizeof(pWapiIe->IeHeader);
3365
3366 } while (0);
3367
3368 if (!pIes && pIesLocal) {
3369 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303370 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371 }
3372
3373 return cbWapiIe;
3374}
3375#endif /* FEATURE_WLAN_WAPI */
3376
3377/**
3378 * csr_get_wpa_cyphers() - to get WPA cipher info
3379 * @mac_ctx: pointer to mac context
3380 * @auth_type: auth type
3381 * @encr_type: encryption type
3382 * @mc_encryption: multicast encryption type
3383 * @wpa_ie: pointer to WPA IE
3384 * @ucast_cipher: Unicast cipher
3385 * @mcast_cipher: Multicast cipher
3386 * @auth_suite: Authentication suite
3387 * @negotiated_authtype: Negotiated auth type
3388 * @negotiated_mccipher: negotiated multicast cipher
3389 *
3390 * This routine will get all WPA information
3391 *
3392 * Return: bool
3393 */
3394bool csr_get_wpa_cyphers(tpAniSirGlobal mac_ctx, tCsrAuthList *auth_type,
3395 eCsrEncryptionType encr_type, tCsrEncryptionList *mc_encryption,
3396 tDot11fIEWPA *wpa_ie, uint8_t *ucast_cipher,
3397 uint8_t *mcast_cipher, uint8_t *auth_suite,
3398 eCsrAuthType *negotiated_authtype,
3399 eCsrEncryptionType *negotiated_mccipher)
3400{
3401 bool acceptable_cipher = false;
3402 uint8_t c_ucast_cipher = 0;
3403 uint8_t c_mcast_cipher = 0;
3404 uint8_t c_auth_suites = 0;
3405 uint8_t unicast[CSR_WPA_OUI_SIZE];
3406 uint8_t multicast[CSR_WPA_OUI_SIZE];
3407 uint8_t authentication[CSR_WPA_OUI_SIZE];
3408 uint8_t mccipher_arr[1][CSR_WPA_OUI_SIZE];
3409 uint8_t i;
3410 eCsrAuthType neg_authtype = eCSR_AUTH_TYPE_UNKNOWN;
3411
3412 if (!wpa_ie->present)
3413 goto end;
3414 c_mcast_cipher = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303415 qdf_mem_copy(mccipher_arr, wpa_ie->multicast_cipher, CSR_WPA_OUI_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 c_ucast_cipher = (uint8_t) (wpa_ie->unicast_cipher_count);
3417 c_auth_suites = (uint8_t) (wpa_ie->auth_suite_count);
3418
3419 /* Check - Is requested unicast Cipher supported by the BSS. */
3420 acceptable_cipher = csr_match_wpaoui_index(mac_ctx,
3421 wpa_ie->unicast_ciphers, c_ucast_cipher,
3422 csr_get_oui_index_from_cipher(encr_type),
3423 unicast);
3424 if (!acceptable_cipher)
3425 goto end;
3426 /* unicast is supported. Pick the first matching Group cipher, if any */
3427 for (i = 0; i < mc_encryption->numEntries; i++) {
3428 acceptable_cipher = csr_match_wpaoui_index(mac_ctx,
3429 mccipher_arr, c_mcast_cipher,
3430 csr_get_oui_index_from_cipher(
3431 mc_encryption->encryptionType[i]),
3432 multicast);
3433 if (acceptable_cipher)
3434 break;
3435 }
3436 if (!acceptable_cipher)
3437 goto end;
3438
3439 if (negotiated_mccipher)
3440 *negotiated_mccipher = mc_encryption->encryptionType[i];
3441
3442 /* Initializing with false as it has true value already */
3443 acceptable_cipher = false;
3444 for (i = 0; i < auth_type->numEntries; i++) {
3445 /*
3446 * Ciphers are supported, Match authentication algorithm and
3447 * pick first matching authtype
3448 */
3449 if (csr_is_auth_wpa(mac_ctx, wpa_ie->auth_suites, c_auth_suites,
3450 authentication)) {
3451 if (eCSR_AUTH_TYPE_WPA == auth_type->authType[i])
3452 neg_authtype = eCSR_AUTH_TYPE_WPA;
3453 }
3454 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN) &&
3455 csr_is_auth_wpa_psk(mac_ctx,
3456 wpa_ie->auth_suites, c_auth_suites,
3457 authentication)) {
3458 if (eCSR_AUTH_TYPE_WPA_PSK == auth_type->authType[i])
3459 neg_authtype = eCSR_AUTH_TYPE_WPA_PSK;
3460 }
3461#ifdef FEATURE_WLAN_ESE
3462 if ((neg_authtype == eCSR_AUTH_TYPE_UNKNOWN)
3463 && csr_is_ese_cckm_auth_wpa(mac_ctx,
3464 wpa_ie->auth_suites, c_auth_suites,
3465 authentication)) {
3466 if (eCSR_AUTH_TYPE_CCKM_WPA == auth_type->authType[i])
3467 neg_authtype = eCSR_AUTH_TYPE_CCKM_WPA;
3468 }
3469#endif /* FEATURE_WLAN_ESE */
3470
3471 /*
3472 * The 1st auth type in the APs WPA IE, to match stations
3473 * connecting profiles auth type will cause us to exit this
3474 * loop. This is added as some APs advertise multiple akms in
3475 * the WPA IE
3476 */
3477 if (eCSR_AUTH_TYPE_UNKNOWN != neg_authtype) {
3478 acceptable_cipher = true;
3479 break;
3480 }
3481 }
3482
3483end:
3484 if (acceptable_cipher) {
3485 if (mcast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303486 qdf_mem_copy((uint8_t **) mcast_cipher, multicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487 CSR_WPA_OUI_SIZE);
3488
3489 if (ucast_cipher)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303490 qdf_mem_copy((uint8_t **) ucast_cipher, unicast,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003491 CSR_WPA_OUI_SIZE);
3492
3493 if (auth_suite)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303494 qdf_mem_copy((uint8_t **) auth_suite, authentication,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495 CSR_WPA_OUI_SIZE);
3496
3497 if (negotiated_authtype)
3498 *negotiated_authtype = neg_authtype;
3499 }
3500
3501 return acceptable_cipher;
3502}
3503
3504bool csr_is_wpa_encryption_match(tpAniSirGlobal pMac, tCsrAuthList *pAuthType,
3505 eCsrEncryptionType enType,
3506 tCsrEncryptionList *pEnMcType,
3507 tDot11fBeaconIEs *pIes,
3508 eCsrAuthType *pNegotiatedAuthtype,
3509 eCsrEncryptionType *pNegotiatedMCCipher)
3510{
3511 bool fWpaMatch = false;
3512
3513 /* See if the cyphers in the Bss description match with the settings in the profile. */
3514 fWpaMatch =
3515 csr_get_wpa_cyphers(pMac, pAuthType, enType, pEnMcType, &pIes->WPA,
3516 NULL, NULL, NULL, pNegotiatedAuthtype,
3517 pNegotiatedMCCipher);
3518
3519 return fWpaMatch;
3520}
3521
3522uint8_t csr_construct_wpa_ie(tHalHandle hHal, tCsrRoamProfile *pProfile,
3523 tSirBssDescription *pSirBssDesc,
3524 tDot11fBeaconIEs *pIes, tCsrWpaIe *pWpaIe)
3525{
3526 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
3527 bool fWpaMatch;
3528 uint8_t cbWpaIe = 0;
3529 uint8_t UnicastCypher[CSR_WPA_OUI_SIZE];
3530 uint8_t MulticastCypher[CSR_WPA_OUI_SIZE];
3531 uint8_t AuthSuite[CSR_WPA_OUI_SIZE];
3532 tCsrWpaAuthIe *pAuthSuite;
3533 tDot11fBeaconIEs *pIesLocal = pIes;
3534
3535 do {
3536 if (!csr_is_profile_wpa(pProfile))
3537 break;
3538
3539 if (!pIesLocal
3540 &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303541 (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542 (csr_get_parsed_bss_description_ies
3543 (pMac, pSirBssDesc, &pIesLocal)))) {
3544 break;
3545 }
3546 /* See if the cyphers in the Bss description match with the settings in the profile. */
3547 fWpaMatch =
3548 csr_get_wpa_cyphers(hHal, &pProfile->AuthType,
3549 pProfile->negotiatedUCEncryptionType,
3550 &pProfile->mcEncryptionType,
3551 &pIesLocal->WPA, UnicastCypher,
3552 MulticastCypher, AuthSuite, NULL, NULL);
3553 if (!fWpaMatch)
3554 break;
3555
3556 pWpaIe->IeHeader.ElementID = SIR_MAC_WPA_EID;
3557
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303558 qdf_mem_copy(pWpaIe->Oui, csr_wpa_oui[01], sizeof(pWpaIe->Oui));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559
3560 pWpaIe->Version = CSR_WPA_VERSION_SUPPORTED;
3561
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303562 qdf_mem_copy(pWpaIe->MulticastOui, MulticastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003563 sizeof(MulticastCypher));
3564
3565 pWpaIe->cUnicastCyphers = 1;
3566
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303567 qdf_mem_copy(&pWpaIe->UnicastOui[0], UnicastCypher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003568 sizeof(UnicastCypher));
3569
3570 pAuthSuite =
3571 (tCsrWpaAuthIe *) (&pWpaIe->
3572 UnicastOui[pWpaIe->cUnicastCyphers]);
3573
3574 pAuthSuite->cAuthenticationSuites = 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303575 qdf_mem_copy(&pAuthSuite->AuthOui[0], AuthSuite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 sizeof(AuthSuite));
3577
3578 /* The WPA capabilities follows the Auth Suite (two octects)-- */
3579 /* this field is optional, and we always "send" zero, so just */
3580 /* remove it. This is consistent with our assumptions in the */
3581 /* frames compiler; c.f. bug 15234: */
3582 /* http://gold.woodsidenet.com/bugzilla/show_bug.cgi?id=15234 */
3583
3584 /* Add in the fixed fields plus 1 Unicast cypher, less the IE Header length */
3585 /* Add in the size of the Auth suite (count plus a single OUI) */
3586 pWpaIe->IeHeader.Length =
3587 sizeof(*pWpaIe) - sizeof(pWpaIe->IeHeader) +
3588 sizeof(*pAuthSuite);
3589
3590 /* return the size of the IE header (total) constructed... */
3591 cbWpaIe = pWpaIe->IeHeader.Length + sizeof(pWpaIe->IeHeader);
3592
3593 } while (0);
3594
3595 if (!pIes && pIesLocal) {
3596 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303597 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003598 }
3599
3600 return cbWpaIe;
3601}
3602
3603/* If a WPAIE exists in the profile, just use it. Or else construct one from the BSS */
3604/* Caller allocated memory for pWpaIe and guarrantee it can contain a max length WPA IE */
3605uint8_t csr_retrieve_wpa_ie(tHalHandle hHal, tCsrRoamProfile *pProfile,
3606 tSirBssDescription *pSirBssDesc,
3607 tDot11fBeaconIEs *pIes, tCsrWpaIe *pWpaIe)
3608{
3609 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
3610 uint8_t cbWpaIe = 0;
3611
3612 do {
3613 if (!csr_is_profile_wpa(pProfile))
3614 break;
3615 if (pProfile->nWPAReqIELength && pProfile->pWPAReqIE) {
3616 if (SIR_MAC_WPA_IE_MAX_LENGTH >=
3617 pProfile->nWPAReqIELength) {
3618 cbWpaIe = (uint8_t) pProfile->nWPAReqIELength;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303619 qdf_mem_copy(pWpaIe, pProfile->pWPAReqIE,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 cbWpaIe);
3621 } else {
3622 sms_log(pMac, LOGW,
3623 " csr_retrieve_wpa_ie detect invalid WPA IE length (%d) ",
3624 pProfile->nWPAReqIELength);
3625 }
3626 } else {
3627 cbWpaIe =
3628 csr_construct_wpa_ie(pMac, pProfile, pSirBssDesc, pIes,
3629 pWpaIe);
3630 }
3631 } while (0);
3632
3633 return cbWpaIe;
3634}
3635
3636/* If a RSNIE exists in the profile, just use it. Or else construct one from the BSS */
3637/* Caller allocated memory for pWpaIe and guarrantee it can contain a max length WPA IE */
3638uint8_t csr_retrieve_rsn_ie(tHalHandle hHal, uint32_t sessionId,
3639 tCsrRoamProfile *pProfile,
3640 tSirBssDescription *pSirBssDesc,
3641 tDot11fBeaconIEs *pIes, tCsrRSNIe *pRsnIe)
3642{
3643 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
3644 uint8_t cbRsnIe = 0;
3645
3646 do {
3647 if (!csr_is_profile_rsn(pProfile))
3648 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 if (csr_roam_is_fast_roam_enabled(pMac, sessionId)) {
3650 /* If "Legacy Fast Roaming" is enabled ALWAYS rebuild the RSN IE from */
3651 /* scratch. So it contains the current PMK-IDs */
3652 cbRsnIe =
3653 csr_construct_rsn_ie(pMac, sessionId, pProfile,
3654 pSirBssDesc, pIes, pRsnIe);
Deepak Dhamdhereecce9742015-11-08 01:16:43 -08003655 } else if (pProfile->nRSNReqIELength && pProfile->pRSNReqIE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 /* If you have one started away, re-use it. */
3657 if (SIR_MAC_WPA_IE_MAX_LENGTH >=
3658 pProfile->nRSNReqIELength) {
3659 cbRsnIe = (uint8_t) pProfile->nRSNReqIELength;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303660 qdf_mem_copy(pRsnIe, pProfile->pRSNReqIE,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661 cbRsnIe);
3662 } else {
3663 sms_log(pMac, LOGW,
3664 " csr_retrieve_rsn_ie detect invalid RSN IE length (%d) ",
3665 pProfile->nRSNReqIELength);
3666 }
3667 } else {
3668 cbRsnIe =
3669 csr_construct_rsn_ie(pMac, sessionId, pProfile,
3670 pSirBssDesc, pIes, pRsnIe);
3671 }
3672 } while (0);
3673
3674 return cbRsnIe;
3675}
3676
3677#ifdef FEATURE_WLAN_WAPI
3678/* If a WAPI IE exists in the profile, just use it. Or else construct one from the BSS */
3679/* Caller allocated memory for pWapiIe and guarrantee it can contain a max length WAPI IE */
3680uint8_t csr_retrieve_wapi_ie(tHalHandle hHal, uint32_t sessionId,
3681 tCsrRoamProfile *pProfile,
3682 tSirBssDescription *pSirBssDesc,
3683 tDot11fBeaconIEs *pIes, tCsrWapiIe *pWapiIe)
3684{
3685 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
3686 uint8_t cbWapiIe = 0;
3687
3688 do {
3689 if (!csr_is_profile_wapi(pProfile))
3690 break;
3691 if (pProfile->nWAPIReqIELength && pProfile->pWAPIReqIE) {
3692 if (DOT11F_IE_WAPI_MAX_LEN >=
3693 pProfile->nWAPIReqIELength) {
3694 cbWapiIe = (uint8_t) pProfile->nWAPIReqIELength;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303695 qdf_mem_copy(pWapiIe, pProfile->pWAPIReqIE,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003696 cbWapiIe);
3697 } else {
3698 sms_log(pMac, LOGW,
3699 " csr_retrieve_wapi_ie detect invalid WAPI IE length (%d) ",
3700 pProfile->nWAPIReqIELength);
3701 }
3702 } else {
3703 cbWapiIe =
3704 csr_construct_wapi_ie(pMac, sessionId, pProfile,
3705 pSirBssDesc, pIes, pWapiIe);
3706 }
3707 } while (0);
3708
3709 return cbWapiIe;
3710}
3711#endif /* FEATURE_WLAN_WAPI */
3712
3713bool csr_rates_is_dot11_rate11b_supported_rate(uint8_t dot11Rate)
3714{
3715 bool fSupported = false;
3716 uint16_t nonBasicRate =
3717 (uint16_t) (BITS_OFF(dot11Rate, CSR_DOT11_BASIC_RATE_MASK));
3718
3719 switch (nonBasicRate) {
3720 case eCsrSuppRate_1Mbps:
3721 case eCsrSuppRate_2Mbps:
3722 case eCsrSuppRate_5_5Mbps:
3723 case eCsrSuppRate_11Mbps:
3724 fSupported = true;
3725 break;
3726
3727 default:
3728 break;
3729 }
3730
3731 return fSupported;
3732}
3733
3734bool csr_rates_is_dot11_rate11a_supported_rate(uint8_t dot11Rate)
3735{
3736 bool fSupported = false;
3737 uint16_t nonBasicRate =
3738 (uint16_t) (BITS_OFF(dot11Rate, CSR_DOT11_BASIC_RATE_MASK));
3739
3740 switch (nonBasicRate) {
3741 case eCsrSuppRate_6Mbps:
3742 case eCsrSuppRate_9Mbps:
3743 case eCsrSuppRate_12Mbps:
3744 case eCsrSuppRate_18Mbps:
3745 case eCsrSuppRate_24Mbps:
3746 case eCsrSuppRate_36Mbps:
3747 case eCsrSuppRate_48Mbps:
3748 case eCsrSuppRate_54Mbps:
3749 fSupported = true;
3750 break;
3751
3752 default:
3753 break;
3754 }
3755
3756 return fSupported;
3757}
3758
3759tAniEdType csr_translate_encrypt_type_to_ed_type(eCsrEncryptionType EncryptType)
3760{
3761 tAniEdType edType;
3762
3763 switch (EncryptType) {
3764 default:
3765 case eCSR_ENCRYPT_TYPE_NONE:
3766 edType = eSIR_ED_NONE;
3767 break;
3768
3769 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3770 case eCSR_ENCRYPT_TYPE_WEP40:
3771 edType = eSIR_ED_WEP40;
3772 break;
3773
3774 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3775 case eCSR_ENCRYPT_TYPE_WEP104:
3776 edType = eSIR_ED_WEP104;
3777 break;
3778
3779 case eCSR_ENCRYPT_TYPE_TKIP:
3780 edType = eSIR_ED_TKIP;
3781 break;
3782
3783 case eCSR_ENCRYPT_TYPE_AES:
3784 edType = eSIR_ED_CCMP;
3785 break;
3786#ifdef FEATURE_WLAN_WAPI
3787 case eCSR_ENCRYPT_TYPE_WPI:
3788 edType = eSIR_ED_WPI;
3789 break;
3790#endif
3791#ifdef WLAN_FEATURE_11W
3792 /* 11w BIP */
3793 case eCSR_ENCRYPT_TYPE_AES_CMAC:
3794 edType = eSIR_ED_AES_128_CMAC;
3795 break;
3796#endif
3797 }
3798
3799 return edType;
3800}
3801
3802/**
3803 * csr_validate_wep() - to validate wep
3804 * @uc_encry_type: unicast encryption type
3805 * @auth_list: Auth list
3806 * @mc_encryption_list: multicast encryption type
3807 * @negotiated_authtype: negotiated auth type
3808 * @negotiated_mc_encry: negotiated mc encry type
3809 * @bss_descr: BSS description
3810 * @ie_ptr: IE pointer
3811 *
3812 * This function just checks whether HDD is giving correct values for
3813 * Multicast cipher and Auth
3814 *
3815 * Return: bool
3816 */
3817bool csr_validate_wep(tpAniSirGlobal mac_ctx, eCsrEncryptionType uc_encry_type,
3818 tCsrAuthList *auth_list,
3819 tCsrEncryptionList *mc_encryption_list,
3820 eCsrAuthType *negotiated_authtype,
3821 eCsrEncryptionType *negotiated_mc_encry,
3822 tSirBssDescription *bss_descr, tDot11fBeaconIEs *ie_ptr)
3823{
3824 uint32_t idx;
3825 bool match = false;
3826 eCsrAuthType negotiated_auth = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3827 eCsrEncryptionType negotiated_mccipher = eCSR_ENCRYPT_TYPE_UNKNOWN;
3828
3829 /* If privacy bit is not set, consider no match */
3830 if (!csr_is_privacy(bss_descr))
3831 goto end;
3832
3833 for (idx = 0; idx < mc_encryption_list->numEntries; idx++) {
3834 switch (mc_encryption_list->encryptionType[idx]) {
3835 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
3836 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
3837 case eCSR_ENCRYPT_TYPE_WEP40:
3838 case eCSR_ENCRYPT_TYPE_WEP104:
3839 /*
3840 * Multicast list may contain WEP40/WEP104.
3841 * Check whether it matches UC.
3842 */
3843 if (uc_encry_type ==
3844 mc_encryption_list->encryptionType[idx]) {
3845 match = true;
3846 negotiated_mccipher =
3847 mc_encryption_list->encryptionType[idx];
3848 }
3849 break;
3850 default:
3851 match = false;
3852 break;
3853 }
3854 if (match)
3855 break;
3856 }
3857
3858 if (!match)
3859 goto end;
3860
3861 for (idx = 0; idx < auth_list->numEntries; idx++) {
3862 switch (auth_list->authType[idx]) {
3863 case eCSR_AUTH_TYPE_OPEN_SYSTEM:
3864 case eCSR_AUTH_TYPE_SHARED_KEY:
3865 case eCSR_AUTH_TYPE_AUTOSWITCH:
3866 match = true;
3867 negotiated_auth = auth_list->authType[idx];
3868 break;
3869 default:
3870 match = false;
3871 }
3872 if (match)
3873 break;
3874 }
3875
3876 if (!match)
3877 goto end;
3878
3879 if (!ie_ptr)
3880 goto end;
3881
3882 /*
3883 * In case of WPA / WPA2, check whether it supports WEP as well.
3884 * Prepare the encryption type for WPA/WPA2 functions
3885 */
3886 if (eCSR_ENCRYPT_TYPE_WEP40_STATICKEY == uc_encry_type)
3887 uc_encry_type = eCSR_ENCRYPT_TYPE_WEP40;
3888 else if (eCSR_ENCRYPT_TYPE_WEP104 == uc_encry_type)
3889 uc_encry_type = eCSR_ENCRYPT_TYPE_WEP104;
3890
3891 /* else we can use the encryption type directly */
3892 if (ie_ptr->WPA.present) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303893 match = (!qdf_mem_cmp(ie_ptr->WPA.multicast_cipher,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003894 csr_wpa_oui[csr_get_oui_index_from_cipher(
3895 uc_encry_type)],
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303896 CSR_WPA_OUI_SIZE));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 if (match)
3898 goto end;
3899 }
3900 if (ie_ptr->RSN.present) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303901 match = (!qdf_mem_cmp(ie_ptr->RSN.gp_cipher_suite,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902 csr_rsn_oui[csr_get_oui_index_from_cipher(
3903 uc_encry_type)],
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303904 CSR_RSN_OUI_SIZE));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003905 }
3906
3907
3908end:
3909 if (match) {
3910 if (negotiated_authtype)
3911 *negotiated_authtype = negotiated_auth;
3912 if (negotiated_mc_encry)
3913 *negotiated_mc_encry = negotiated_mccipher;
3914 }
3915 return match;
3916}
3917
3918/**
3919 * csr_validate_open_none() - Check if the security is matching
3920 * @bss_desc: BSS Descriptor on which the check is done
3921 * @mc_enc_type: Multicast encryption type
3922 * @mc_cipher: Multicast Cipher
3923 * @auth_type: Authentication type
3924 * @neg_auth_type: Negotiated Auth type with the AP
3925 *
3926 * Return: Boolean value to tell if matched or not.
3927 */
3928static bool csr_validate_open_none(tSirBssDescription *bss_desc,
3929 tCsrEncryptionList *mc_enc_type, eCsrEncryptionType *mc_cipher,
3930 tCsrAuthList *auth_type, eCsrAuthType *neg_auth_type)
3931{
3932 bool match;
3933 uint8_t idx;
3934
3935 /*
3936 * for NO encryption, if the Bss description has the
3937 * Privacy bit turned on, then encryption is required
3938 * so we have to reject this Bss.
3939 */
3940 if (csr_is_privacy(bss_desc))
3941 match = false;
3942 else
3943 match = true;
3944 if (match) {
3945 match = false;
3946 /* Check MC cipher and Auth type requested. */
3947 for (idx = 0; idx < mc_enc_type->numEntries; idx++) {
3948 if (eCSR_ENCRYPT_TYPE_NONE ==
3949 mc_enc_type->encryptionType[idx]) {
3950 match = true;
3951 *mc_cipher = mc_enc_type->encryptionType[idx];
3952 break;
3953 }
3954 }
3955 if (!match)
3956 return match;
3957
3958 match = false;
3959 /* Check Auth list. It should contain AuthOpen. */
3960 for (idx = 0; idx < auth_type->numEntries; idx++) {
3961 if ((eCSR_AUTH_TYPE_OPEN_SYSTEM ==
3962 auth_type->authType[idx]) ||
3963 (eCSR_AUTH_TYPE_AUTOSWITCH ==
3964 auth_type->authType[idx])) {
3965 match = true;
3966 *neg_auth_type =
3967 eCSR_AUTH_TYPE_OPEN_SYSTEM;
3968 break;
3969 }
3970 }
3971 if (!match)
3972 return match;
3973
3974 }
3975 return match;
3976}
3977
3978/**
3979 * csr_validate_any_default() - Check if the security is matching
3980 * @hal: Global HAL handle
3981 * @auth_type: Authentication type
3982 * @mc_enc_type: Multicast encryption type
3983 * @mfp_enabled: Management frame protection feature
3984 * @mfp_required: Mangement frame protection mandatory
3985 * @mfp_capable: Device capable of MFP
3986 * @ies_ptr: Pointer to the IE fields
3987 * @neg_auth_type: Negotiated Auth type with the AP
3988 * @bss_desc: BSS Descriptor
3989 * @neg_uc_cipher: Negotiated unicast cipher suite
3990 * @neg_mc_cipher: Negotiated multicast cipher
3991 *
3992 * Return: Boolean value to tell if matched or not.
3993 */
3994static bool csr_validate_any_default(tHalHandle hal, tCsrAuthList *auth_type,
3995 tCsrEncryptionList *mc_enc_type, bool *mfp_enabled,
3996 uint8_t *mfp_required, uint8_t *mfp_capable,
3997 tDot11fBeaconIEs *ies_ptr, eCsrAuthType *neg_auth_type,
3998 tSirBssDescription *bss_desc, eCsrEncryptionType *uc_cipher,
3999 eCsrEncryptionType *mc_cipher)
4000{
4001 bool match_any = false;
4002 bool match = true;
4003 tpAniSirGlobal mac_ctx = PMAC_STRUCT(hal);
4004 /* It is allowed to match anything. Try the more secured ones first. */
4005 if (ies_ptr) {
4006 /* Check AES first */
4007 *uc_cipher = eCSR_ENCRYPT_TYPE_AES;
4008 match_any = csr_is_rsn_match(hal, auth_type,
4009 *uc_cipher, mc_enc_type, mfp_enabled,
4010 mfp_required, mfp_capable, ies_ptr,
4011 neg_auth_type, mc_cipher);
4012 if (!match_any) {
4013 /* Check TKIP */
4014 *uc_cipher = eCSR_ENCRYPT_TYPE_TKIP;
4015 match_any = csr_is_rsn_match(hal, auth_type, *uc_cipher,
4016 mc_enc_type, mfp_enabled, mfp_required,
4017 mfp_capable, ies_ptr, neg_auth_type,
4018 mc_cipher);
4019 }
4020#ifdef FEATURE_WLAN_WAPI
4021 if (!match_any) {
4022 /* Check WAPI */
4023 *uc_cipher = eCSR_ENCRYPT_TYPE_WPI;
4024 match_any = csr_is_wapi_match(hal, auth_type,
4025 *uc_cipher, mc_enc_type, ies_ptr,
4026 neg_auth_type, mc_cipher);
4027 }
4028#endif
4029 }
4030 if (match_any)
4031 return match;
4032 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP104;
4033 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
4034 neg_auth_type, mc_cipher, bss_desc, ies_ptr))
4035 return match;
4036 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP40;
4037 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
4038 neg_auth_type, mc_cipher, bss_desc, ies_ptr))
4039 return match;
4040 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP104_STATICKEY;
4041 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
4042 neg_auth_type, mc_cipher, bss_desc, ies_ptr))
4043 return match;
4044 *uc_cipher = eCSR_ENCRYPT_TYPE_WEP40_STATICKEY;
4045 if (csr_validate_wep(mac_ctx, *uc_cipher, auth_type, mc_enc_type,
4046 neg_auth_type, mc_cipher, bss_desc, ies_ptr))
4047 return match;
4048 /* It must be open and no enc */
4049 if (csr_is_privacy(bss_desc)) {
4050 match = false;
4051 return match;
4052 }
4053
4054 *neg_auth_type = eCSR_AUTH_TYPE_OPEN_SYSTEM;
4055 *mc_cipher = eCSR_ENCRYPT_TYPE_NONE;
4056 *uc_cipher = eCSR_ENCRYPT_TYPE_NONE;
4057 return match;
4058
4059}
4060
4061/**
4062 * csr_is_security_match() - Check if the security is matching
4063 * @hal: Global HAL handle
4064 * @auth_type: Authentication type
4065 * @uc_enc_type: Unicast Encryption type
4066 * @mc_enc_type: Multicast encryption type
4067 * @mfp_enabled: Management frame protection feature
4068 * @mfp_required: Mangement frame protection mandatory
4069 * @mfp_capable: Device capable of MFP
4070 * @bss_desc: BSS Descriptor
4071 * @ies_ptr: Pointer to the IE fields
4072 * @neg_auth_type: Negotiated Auth type with the AP
4073 * @neg_uc_cipher: Negotiated unicast cipher suite
4074 * @neg_mc_cipher: Negotiated multicast cipher
4075 *
4076 * Return: Boolean value to tell if matched or not.
4077 */
4078bool csr_is_security_match(tHalHandle hal, tCsrAuthList *auth_type,
4079 tCsrEncryptionList *uc_enc_type,
4080 tCsrEncryptionList *mc_enc_type, bool *mfp_enabled,
4081 uint8_t *mfp_required, uint8_t *mfp_capable,
4082 tSirBssDescription *bss_desc, tDot11fBeaconIEs *ies_ptr,
4083 eCsrAuthType *neg_auth_type,
4084 eCsrEncryptionType *neg_uc_cipher,
4085 eCsrEncryptionType *neg_mc_cipher)
4086{
4087 tpAniSirGlobal mac_ctx = PMAC_STRUCT(hal);
4088 bool match = false;
4089 uint8_t i;
4090 eCsrEncryptionType mc_cipher = eCSR_ENCRYPT_TYPE_UNKNOWN;
4091 eCsrEncryptionType uc_cipher = eCSR_ENCRYPT_TYPE_UNKNOWN;
4092 eCsrAuthType local_neg_auth_type = eCSR_AUTH_TYPE_UNKNOWN;
4093
4094 for (i = 0; ((i < uc_enc_type->numEntries) && (!match)); i++) {
4095 uc_cipher = uc_enc_type->encryptionType[i];
4096 /*
4097 * If the Bss description shows the Privacy bit is on, then we
4098 * must have some sort of encryption configured for the profile
4099 * to work. Don't attempt to join networks with Privacy bit
4100 * set when profiles say NONE for encryption type.
4101 */
4102 switch (uc_cipher) {
4103 case eCSR_ENCRYPT_TYPE_NONE:
4104 match = csr_validate_open_none(bss_desc, mc_enc_type,
4105 &mc_cipher, auth_type,
4106 &local_neg_auth_type);
4107 break;
4108
4109 case eCSR_ENCRYPT_TYPE_WEP40_STATICKEY:
4110 case eCSR_ENCRYPT_TYPE_WEP104_STATICKEY:
4111 /*
4112 * !! might want to check for WEP keys set in the
4113 * Profile.... ? !! don't need to have the privacy bit
4114 * in the Bss description. Many AP policies make
4115 * legacy encryption 'optional' so we don't know if we
4116 * can associate or not. The AP will reject if
4117 * encryption is not allowed without the Privacy bit
4118 * turned on.
4119 */
4120 match = csr_validate_wep(mac_ctx, uc_cipher, auth_type,
4121 mc_enc_type, &local_neg_auth_type,
4122 &mc_cipher, bss_desc, ies_ptr);
4123
4124 break;
4125 /* these are all of the WPA encryption types... */
4126 case eCSR_ENCRYPT_TYPE_WEP40:
4127 case eCSR_ENCRYPT_TYPE_WEP104:
4128 match = csr_validate_wep(mac_ctx, uc_cipher, auth_type,
4129 mc_enc_type, &local_neg_auth_type,
4130 &mc_cipher, bss_desc, ies_ptr);
4131 break;
4132
4133 case eCSR_ENCRYPT_TYPE_TKIP:
4134 case eCSR_ENCRYPT_TYPE_AES:
4135 if (!ies_ptr) {
4136 match = false;
4137 break;
4138 }
4139 /* First check if there is a RSN match */
4140 match = csr_is_rsn_match(mac_ctx, auth_type,
4141 uc_cipher, mc_enc_type,
4142 mfp_enabled, mfp_required,
4143 mfp_capable, ies_ptr,
4144 &local_neg_auth_type,
4145 &mc_cipher);
4146 /* If not RSN, then check WPA match */
4147 if (!match)
4148 match = csr_is_wpa_encryption_match(
4149 mac_ctx, auth_type,
4150 uc_cipher, mc_enc_type,
4151 ies_ptr,
4152 &local_neg_auth_type,
4153 &mc_cipher);
4154 break;
4155#ifdef FEATURE_WLAN_WAPI
4156 case eCSR_ENCRYPT_TYPE_WPI: /* WAPI */
4157 if (ies_ptr)
4158 match = csr_is_wapi_match(hal, auth_type,
4159 uc_cipher, mc_enc_type, ies_ptr,
4160 &local_neg_auth_type,
4161 &mc_cipher);
4162 else
4163 match = false;
4164 break;
4165#endif /* FEATURE_WLAN_WAPI */
4166 case eCSR_ENCRYPT_TYPE_ANY:
4167 default:
4168 match = csr_validate_any_default(hal, auth_type,
4169 mc_enc_type, mfp_enabled, mfp_required,
4170 mfp_capable, ies_ptr,
4171 &local_neg_auth_type, bss_desc,
4172 &uc_cipher, &mc_cipher);
4173 break;
4174 }
4175
4176 }
4177
4178 if (match) {
4179 if (neg_uc_cipher)
4180 *neg_uc_cipher = uc_cipher;
4181 if (neg_mc_cipher)
4182 *neg_mc_cipher = mc_cipher;
4183 if (neg_auth_type)
4184 *neg_auth_type = local_neg_auth_type;
4185 }
4186 return match;
4187}
4188
4189bool csr_is_ssid_match(tpAniSirGlobal pMac, uint8_t *ssid1, uint8_t ssid1Len,
4190 uint8_t *bssSsid, uint8_t bssSsidLen, bool fSsidRequired)
4191{
4192 bool fMatch = false;
4193
4194 do {
4195 /*
4196 * Check for the specification of the Broadcast SSID at the
4197 * beginning of the list. If specified, then all SSIDs are
4198 * matches (broadcast SSID means accept all SSIDs).
4199 */
4200 if (ssid1Len == 0) {
4201 fMatch = true;
4202 break;
4203 }
4204
4205 /* There are a few special cases. If the Bss description has a Broadcast SSID, */
4206 /* then our Profile must have a single SSID without Wildcards so we can program */
4207 /* the SSID. */
4208 /* SSID could be suppressed in beacons. In that case SSID IE has valid length */
4209 /* but the SSID value is all NULL characters. That condition is trated same */
4210 /* as NULL SSID */
4211 if (csr_is_nullssid(bssSsid, bssSsidLen)) {
4212 if (false == fSsidRequired) {
4213 fMatch = true;
4214 break;
4215 }
4216 }
4217
4218 if (ssid1Len != bssSsidLen)
4219 break;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304220 if (!qdf_mem_cmp(bssSsid, ssid1, bssSsidLen)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221 fMatch = true;
4222 break;
4223 }
4224
4225 } while (0);
4226
4227 return fMatch;
4228}
4229
4230/* Null ssid means match */
4231bool csr_is_ssid_in_list(tHalHandle hHal, tSirMacSSid *pSsid,
4232 tCsrSSIDs *pSsidList)
4233{
4234 bool fMatch = false;
4235 uint32_t i;
4236
4237 if (pSsidList && pSsid) {
4238 for (i = 0; i < pSsidList->numOfSSIDs; i++) {
4239 if (csr_is_nullssid
4240 (pSsidList->SSIDList[i].SSID.ssId,
4241 pSsidList->SSIDList[i].SSID.length)
4242 ||
4243 ((pSsidList->SSIDList[i].SSID.length ==
4244 pSsid->length)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304245 && (!qdf_mem_cmp(pSsid->ssId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004246 pSsidList->SSIDList[i].SSID.
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304247 ssId, pSsid->length)))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 fMatch = true;
4249 break;
4250 }
4251 }
4252 }
4253
4254 return fMatch;
4255}
4256
Anurag Chouhan6d760662016-02-20 16:05:43 +05304257bool csr_is_bssid_match(tHalHandle hHal, struct qdf_mac_addr *pProfBssid,
4258 struct qdf_mac_addr *BssBssid)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259{
4260 bool fMatch = false;
Anurag Chouhan6d760662016-02-20 16:05:43 +05304261 struct qdf_mac_addr ProfileBssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262
4263 /* for efficiency of the MAC_ADDRESS functions, move the */
4264 /* Bssid's into MAC_ADDRESS structs. */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304265 qdf_mem_copy(&ProfileBssid, pProfBssid, sizeof(struct qdf_mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004266
4267 do {
4268
4269 /* Give the profile the benefit of the doubt... accept either all 0 or */
4270 /* the real broadcast Bssid (all 0xff) as broadcast Bssids (meaning to */
4271 /* match any Bssids). */
Anurag Chouhanc5548422016-02-24 18:33:27 +05304272 if (qdf_is_macaddr_zero(&ProfileBssid) ||
4273 qdf_is_macaddr_broadcast(&ProfileBssid)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 fMatch = true;
4275 break;
4276 }
4277
Anurag Chouhanc5548422016-02-24 18:33:27 +05304278 if (qdf_is_macaddr_equal(BssBssid, &ProfileBssid)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279 fMatch = true;
4280 break;
4281 }
4282
4283 } while (0);
4284
4285 return fMatch;
4286}
4287
4288bool csr_is_bss_type_match(eCsrRoamBssType bssType1, eCsrRoamBssType bssType2)
4289{
4290 if ((eCSR_BSS_TYPE_ANY != bssType1 && eCSR_BSS_TYPE_ANY != bssType2)
4291 && (bssType1 != bssType2))
4292 return false;
4293 else
4294 return true;
4295}
4296
4297bool csr_is_bss_type_ibss(eCsrRoamBssType bssType)
4298{
4299 return (bool)
4300 (eCSR_BSS_TYPE_START_IBSS == bssType
4301 || eCSR_BSS_TYPE_IBSS == bssType);
4302}
4303
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304
4305bool csr_is_bss_type_caps_match(eCsrRoamBssType bssType,
4306 tSirBssDescription *pSirBssDesc)
4307{
4308 bool fMatch = true;
4309
4310 do {
4311 switch (bssType) {
4312 case eCSR_BSS_TYPE_ANY:
4313 break;
4314
4315 case eCSR_BSS_TYPE_INFRASTRUCTURE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316 if (!csr_is_infra_bss_desc(pSirBssDesc))
4317 fMatch = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318 break;
4319
4320 case eCSR_BSS_TYPE_IBSS:
4321 case eCSR_BSS_TYPE_START_IBSS:
4322 if (!csr_is_ibss_bss_desc(pSirBssDesc))
4323 fMatch = false;
4324
4325 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326 default:
4327 fMatch = false;
4328 break;
4329 }
4330 } while (0);
4331
4332 return fMatch;
4333}
4334
4335static bool csr_is_capabilities_match(tpAniSirGlobal pMac, eCsrRoamBssType bssType,
4336 tSirBssDescription *pSirBssDesc)
4337{
4338 return csr_is_bss_type_caps_match(bssType, pSirBssDesc);
4339}
4340
4341static bool csr_is_specific_channel_match(tpAniSirGlobal pMac,
4342 tSirBssDescription *pSirBssDesc,
4343 uint8_t Channel)
4344{
4345 bool fMatch = true;
4346
4347 do {
4348 /* if the channel is ANY, then always match... */
4349 if (eCSR_OPERATING_CHANNEL_ANY == Channel)
4350 break;
4351 if (Channel == pSirBssDesc->channelId)
4352 break;
4353
4354 /* didn't match anything.. so return NO match */
4355 fMatch = false;
4356
4357 } while (0);
4358
4359 return fMatch;
4360}
4361
4362bool csr_is_channel_band_match(tpAniSirGlobal pMac, uint8_t channelId,
4363 tSirBssDescription *pSirBssDesc)
4364{
4365 bool fMatch = true;
4366
4367 do {
4368 /* if the profile says Any channel AND the global settings says ANY channel, then we */
4369 /* always match... */
4370 if (eCSR_OPERATING_CHANNEL_ANY == channelId)
4371 break;
4372
4373 if (eCSR_OPERATING_CHANNEL_ANY != channelId) {
4374 fMatch =
4375 csr_is_specific_channel_match(pMac, pSirBssDesc,
4376 channelId);
4377 }
4378
4379 } while (0);
4380
4381 return fMatch;
4382}
4383
4384/**
4385 * csr_is_aggregate_rate_supported() - to check if aggregate rate is supported
4386 * @mac_ctx: pointer to mac context
4387 * @rate: A rate in units of 500kbps
4388 *
4389 *
4390 * The rate encoding is just as in 802.11 Information Elements, except
4391 * that the high bit is \em not interpreted as indicating a Basic Rate,
4392 * and proprietary rates are allowed, too.
4393 *
4394 * Note that if the adapter's dot11Mode is g, we don't restrict the
4395 * rates. According to hwReadEepromParameters, this will happen when:
4396 * ... the card is configured for ALL bands through the property
4397 * page. If this occurs, and the card is not an ABG card ,then this
4398 * code is setting the dot11Mode to assume the mode that the
4399 * hardware can support. For example, if the card is an 11BG card
4400 * and we are configured to support ALL bands, then we change the
4401 * dot11Mode to 11g because ALL in this case is only what the
4402 * hardware can support.
4403 *
4404 * Return: true if the adapter is currently capable of supporting this rate
4405 */
4406
4407static bool csr_is_aggregate_rate_supported(tpAniSirGlobal mac_ctx,
4408 uint16_t rate)
4409{
4410 bool supported = false;
4411 uint16_t idx, new_rate;
4412
4413 /* In case basic rate flag is set */
4414 new_rate = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
4415 if (eCSR_CFG_DOT11_MODE_11A ==
4416 mac_ctx->roam.configParam.uCfgDot11Mode) {
4417 switch (new_rate) {
4418 case eCsrSuppRate_6Mbps:
4419 case eCsrSuppRate_9Mbps:
4420 case eCsrSuppRate_12Mbps:
4421 case eCsrSuppRate_18Mbps:
4422 case eCsrSuppRate_24Mbps:
4423 case eCsrSuppRate_36Mbps:
4424 case eCsrSuppRate_48Mbps:
4425 case eCsrSuppRate_54Mbps:
4426 supported = true;
4427 break;
4428 default:
4429 supported = false;
4430 break;
4431 }
4432
4433 } else if (eCSR_CFG_DOT11_MODE_11B ==
4434 mac_ctx->roam.configParam.uCfgDot11Mode) {
4435 switch (new_rate) {
4436 case eCsrSuppRate_1Mbps:
4437 case eCsrSuppRate_2Mbps:
4438 case eCsrSuppRate_5_5Mbps:
4439 case eCsrSuppRate_11Mbps:
4440 supported = true;
4441 break;
4442 default:
4443 supported = false;
4444 break;
4445 }
4446 } else if (!mac_ctx->roam.configParam.ProprietaryRatesEnabled) {
4447
4448 switch (new_rate) {
4449 case eCsrSuppRate_1Mbps:
4450 case eCsrSuppRate_2Mbps:
4451 case eCsrSuppRate_5_5Mbps:
4452 case eCsrSuppRate_6Mbps:
4453 case eCsrSuppRate_9Mbps:
4454 case eCsrSuppRate_11Mbps:
4455 case eCsrSuppRate_12Mbps:
4456 case eCsrSuppRate_18Mbps:
4457 case eCsrSuppRate_24Mbps:
4458 case eCsrSuppRate_36Mbps:
4459 case eCsrSuppRate_48Mbps:
4460 case eCsrSuppRate_54Mbps:
4461 supported = true;
4462 break;
4463 default:
4464 supported = false;
4465 break;
4466 }
4467 } else if (eCsrSuppRate_1Mbps == new_rate ||
4468 eCsrSuppRate_2Mbps == new_rate ||
4469 eCsrSuppRate_5_5Mbps == new_rate ||
4470 eCsrSuppRate_11Mbps == new_rate) {
4471 supported = true;
4472 } else {
4473 idx = 0x1;
4474
4475 switch (new_rate) {
4476 case eCsrSuppRate_6Mbps:
4477 supported = g_phy_rates_suppt[0][idx];
4478 break;
4479 case eCsrSuppRate_9Mbps:
4480 supported = g_phy_rates_suppt[1][idx];
4481 break;
4482 case eCsrSuppRate_12Mbps:
4483 supported = g_phy_rates_suppt[2][idx];
4484 break;
4485 case eCsrSuppRate_18Mbps:
4486 supported = g_phy_rates_suppt[3][idx];
4487 break;
4488 case eCsrSuppRate_20Mbps:
4489 supported = g_phy_rates_suppt[4][idx];
4490 break;
4491 case eCsrSuppRate_24Mbps:
4492 supported = g_phy_rates_suppt[5][idx];
4493 break;
4494 case eCsrSuppRate_36Mbps:
4495 supported = g_phy_rates_suppt[6][idx];
4496 break;
4497 case eCsrSuppRate_40Mbps:
4498 supported = g_phy_rates_suppt[7][idx];
4499 break;
4500 case eCsrSuppRate_42Mbps:
4501 supported = g_phy_rates_suppt[8][idx];
4502 break;
4503 case eCsrSuppRate_48Mbps:
4504 supported = g_phy_rates_suppt[9][idx];
4505 break;
4506 case eCsrSuppRate_54Mbps:
4507 supported = g_phy_rates_suppt[10][idx];
4508 break;
4509 case eCsrSuppRate_72Mbps:
4510 supported = g_phy_rates_suppt[11][idx];
4511 break;
4512 case eCsrSuppRate_80Mbps:
4513 supported = g_phy_rates_suppt[12][idx];
4514 break;
4515 case eCsrSuppRate_84Mbps:
4516 supported = g_phy_rates_suppt[13][idx];
4517 break;
4518 case eCsrSuppRate_96Mbps:
4519 supported = g_phy_rates_suppt[14][idx];
4520 break;
4521 case eCsrSuppRate_108Mbps:
4522 supported = g_phy_rates_suppt[15][idx];
4523 break;
4524 case eCsrSuppRate_120Mbps:
4525 supported = g_phy_rates_suppt[16][idx];
4526 break;
4527 case eCsrSuppRate_126Mbps:
4528 supported = g_phy_rates_suppt[17][idx];
4529 break;
4530 case eCsrSuppRate_144Mbps:
4531 supported = g_phy_rates_suppt[18][idx];
4532 break;
4533 case eCsrSuppRate_160Mbps:
4534 supported = g_phy_rates_suppt[19][idx];
4535 break;
4536 case eCsrSuppRate_168Mbps:
4537 supported = g_phy_rates_suppt[20][idx];
4538 break;
4539 case eCsrSuppRate_192Mbps:
4540 supported = g_phy_rates_suppt[21][idx];
4541 break;
4542 case eCsrSuppRate_216Mbps:
4543 supported = g_phy_rates_suppt[22][idx];
4544 break;
4545 case eCsrSuppRate_240Mbps:
4546 supported = g_phy_rates_suppt[23][idx];
4547 break;
4548 default:
4549 supported = false;
4550 break;
4551 }
4552 }
4553 return supported;
4554}
4555
4556/**
4557 * csr_is_rate_set_match() - to check if rate set is matching
4558 * @mac_ctx: pointer to mac context
4559 * @bss_supported_rates: supported rates of BSS
4560 * @bss_ext_supp_rates: extended rates of bss
4561 *
4562 * This routine is to checke if rate set is matched or no
4563 *
4564 * Return: bool
4565 */
4566static bool csr_is_rate_set_match(tpAniSirGlobal mac_ctx,
4567 tDot11fIESuppRates *bss_supported_rates,
4568 tDot11fIEExtSuppRates *bss_ext_supp_rates)
4569{
4570 bool match = true;
4571 uint32_t i;
4572
4573 /*
4574 * Validate that all of the Basic rates advertised in the Bss
4575 * description are supported
4576 */
4577 if (bss_supported_rates) {
4578 for (i = 0; i < bss_supported_rates->num_rates; i++) {
4579 if (!CSR_IS_BASIC_RATE(bss_supported_rates->rates[i]))
4580 continue;
4581 if (!csr_is_aggregate_rate_supported(mac_ctx,
4582 bss_supported_rates->rates[i])) {
4583 match = false;
4584 break;
4585 }
4586 }
4587 }
4588 if (match && bss_ext_supp_rates) {
4589 for (i = 0; i < bss_ext_supp_rates->num_rates; i++) {
4590 if (!CSR_IS_BASIC_RATE(bss_ext_supp_rates->rates[i]))
4591 continue;
4592 if (!csr_is_aggregate_rate_supported(mac_ctx,
4593 bss_ext_supp_rates->rates[i])) {
4594 match = false;
4595 break;
4596 }
4597 }
4598 }
4599 return match;
4600}
4601
4602/**
4603 * csr_match_bss() - to compare the bss
4604 * @hal: pointer to hal context
4605 * @bss_descr: pointer bss description
4606 * @filter: scan filter
4607 * @neg_auth: negotiated auth
4608 * @neg_uc: negotiated for unicast
4609 * @neg_mc: negotiated for multicast
4610 * @ie_dblptr: double pointer to IE
4611 *
4612 * This routine will be called to match the bss
4613 * If caller want to get the *ie_dblptr allocated by this function,
4614 * pass in *ie_dblptr = NULL
4615 *
4616 * Return: bool
4617 */
4618bool csr_match_bss(tHalHandle hal, tSirBssDescription *bss_descr,
4619 tCsrScanResultFilter *filter, eCsrAuthType *neg_auth,
4620 eCsrEncryptionType *neg_uc, eCsrEncryptionType *neg_mc,
4621 tDot11fBeaconIEs **ie_dblptr)
4622{
4623 tpAniSirGlobal mac_ctx = PMAC_STRUCT(hal);
4624 bool rc = false, check, blacklist_check;
4625 uint32_t i;
4626 tDot11fBeaconIEs *ie_ptr = NULL;
4627 uint8_t *pb;
4628 struct roam_ext_params *roam_params;
4629 uint8_t *p2p_macaddr = NULL;
4630
4631 roam_params = &mac_ctx->roam.configParam.roam_params;
4632 if ((NULL == ie_dblptr) || (*ie_dblptr) == NULL) {
4633 /* If no IEs passed in, get our own. */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304634 if (!QDF_IS_STATUS_SUCCESS(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004635 csr_get_parsed_bss_description_ies(mac_ctx,
4636 bss_descr, &ie_ptr))) {
4637 goto end;
4638 }
4639 } else {
4640 /* Save the one pass in for local use */
4641 ie_ptr = *ie_dblptr;
4642 }
4643
4644 /* Check if caller wants P2P */
4645 check = (!filter->p2pResult || ie_ptr->P2PBeaconProbeRes.present);
4646 if (!check)
4647 goto end;
4648
4649 /* Check for Blacklist BSSID's and avoid connections */
4650 blacklist_check = false;
4651 for (i = 0; i < roam_params->num_bssid_avoid_list; i++) {
Anurag Chouhanc5548422016-02-24 18:33:27 +05304652 if (qdf_is_macaddr_equal((struct qdf_mac_addr *)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653 &roam_params->bssid_avoid_list[i],
Anurag Chouhan6d760662016-02-20 16:05:43 +05304654 (struct qdf_mac_addr *)bss_descr->bssId)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 blacklist_check = true;
4656 break;
4657 }
4658 }
4659 if (blacklist_check) {
4660 sms_log(mac_ctx, LOGE,
4661 FL("Don't Attempt connect to blacklist bssid"));
4662 goto end;
4663 }
4664
4665 if (ie_ptr->SSID.present) {
4666 for (i = 0; i < filter->SSIDs.numOfSSIDs; i++) {
4667 check = csr_is_ssid_match(mac_ctx,
4668 filter->SSIDs.SSIDList[i].SSID.ssId,
4669 filter->SSIDs.SSIDList[i].SSID.length,
4670 ie_ptr->SSID.ssid,
4671 ie_ptr->SSID.num_ssid, true);
4672 if (check)
4673 break;
4674 }
4675 if (!check)
4676 goto end;
4677 }
4678 check = true;
4679 p2p_macaddr = ie_ptr->P2PBeaconProbeRes.P2PDeviceInfo.P2PDeviceAddress;
4680 for (i = 0; i < filter->BSSIDs.numOfBSSIDs; i++) {
4681 check = csr_is_bssid_match(mac_ctx,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304682 (struct qdf_mac_addr *)&filter->BSSIDs.bssid[i],
4683 (struct qdf_mac_addr *)bss_descr->bssId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004684 if (check)
4685 break;
4686
4687 if (filter->p2pResult && ie_ptr->P2PBeaconProbeRes.present) {
4688 check = csr_is_bssid_match(mac_ctx,
Anurag Chouhan6d760662016-02-20 16:05:43 +05304689 (struct qdf_mac_addr *)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004690 &filter->BSSIDs.bssid[i],
Anurag Chouhan6d760662016-02-20 16:05:43 +05304691 (struct qdf_mac_addr *)p2p_macaddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004692 if (check)
4693 break;
4694 }
4695 }
4696 if (!check)
4697 goto end;
4698
4699 check = true;
4700 for (i = 0; i < filter->ChannelInfo.numOfChannels; i++) {
4701 check = csr_is_channel_band_match(mac_ctx,
4702 filter->ChannelInfo.ChannelList[i], bss_descr);
4703 if (check)
4704 break;
4705 }
4706 if (!check)
4707 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004708 /* If this is for measurement filtering */
4709 if (filter->fMeasurement) {
4710 rc = true;
4711 goto end;
4712 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004713 if (!csr_is_phy_mode_match(mac_ctx, filter->phyMode, bss_descr,
4714 NULL, NULL, ie_ptr))
4715 goto end;
4716
4717#ifdef WLAN_FEATURE_11W
4718 if ((!filter->bWPSAssociation) && (!filter->bOSENAssociation) &&
4719 !csr_is_security_match(mac_ctx, &filter->authType,
4720 &filter->EncryptionType,
4721 &filter->mcEncryptionType,
4722 &filter->MFPEnabled,
4723 &filter->MFPRequired,
4724 &filter->MFPCapable,
4725 bss_descr, ie_ptr, neg_auth,
4726 neg_uc, neg_mc))
4727#else
4728 if ((!filter->bWPSAssociation) && (!filter->bOSENAssociation) &&
4729 !csr_is_security_match(mac_ctx, &filter->authType,
4730 &filter->EncryptionType,
4731 &filter->mcEncryptionType,
4732 NULL, NULL, NULL,
4733 bss_descr, ie_ptr, neg_auth,
4734 neg_uc, neg_mc))
4735#endif
4736 goto end;
4737 if (!csr_is_capabilities_match(mac_ctx, filter->BSSType, bss_descr))
4738 goto end;
4739 if (!csr_is_rate_set_match(mac_ctx, &ie_ptr->SuppRates,
4740 &ie_ptr->ExtSuppRates))
4741 goto end;
4742 if ((eCsrRoamWmmQbssOnly == mac_ctx->roam.configParam.WMMSupportMode)
4743 && !CSR_IS_QOS_BSS(ie_ptr))
4744 goto end;
4745 /*
4746 * Check country. check even when pb is NULL because we may
4747 * want to make sure
4748 */
4749 pb = (filter->countryCode[0]) ? (filter->countryCode) : NULL;
4750 check = csr_match_country_code(mac_ctx, pb, ie_ptr);
4751 if (!check)
4752 goto end;
4753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754 if (filter->MDID.mdiePresent && csr_roam_is11r_assoc(mac_ctx,
4755 mac_ctx->roam.roamSession->sessionId)) {
4756 if (bss_descr->mdiePresent) {
4757 if (filter->MDID.mobilityDomain !=
4758 (bss_descr->mdie[1] << 8 |
4759 bss_descr->mdie[0]))
4760 goto end;
4761 } else {
4762 goto end;
4763 }
4764 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004765 rc = true;
4766
4767end:
4768 if (ie_dblptr)
4769 *ie_dblptr = ie_ptr;
4770 else if (ie_ptr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304771 qdf_mem_free(ie_ptr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 return rc;
4773}
4774
4775bool csr_match_connected_bss_security(tpAniSirGlobal pMac,
4776 tCsrRoamConnectedProfile *pProfile,
4777 tSirBssDescription *pBssDesc,
4778 tDot11fBeaconIEs *pIes)
4779{
4780 tCsrEncryptionList ucEncryptionList, mcEncryptionList;
4781 tCsrAuthList authList;
4782
4783 ucEncryptionList.numEntries = 1;
4784 ucEncryptionList.encryptionType[0] = pProfile->EncryptionType;
4785
4786 mcEncryptionList.numEntries = 1;
4787 mcEncryptionList.encryptionType[0] = pProfile->mcEncryptionType;
4788
4789 authList.numEntries = 1;
4790 authList.authType[0] = pProfile->AuthType;
4791
Krunal Sonib2f13042015-11-02 18:41:08 -08004792#ifdef WLAN_FEATURE_11W
4793 return csr_is_security_match(pMac, &authList, &ucEncryptionList,
4794 &mcEncryptionList,
4795 &pProfile->MFPEnabled,
4796 &pProfile->MFPRequired,
4797 &pProfile->MFPCapable,
4798 pBssDesc, pIes, NULL, NULL, NULL);
4799#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004800 return csr_is_security_match(pMac, &authList, &ucEncryptionList,
4801 &mcEncryptionList, NULL, NULL, NULL,
4802 pBssDesc, pIes, NULL, NULL, NULL);
Krunal Sonib2f13042015-11-02 18:41:08 -08004803#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004804
4805}
4806
4807bool csr_match_bss_to_connect_profile(tHalHandle hHal,
4808 tCsrRoamConnectedProfile *pProfile,
4809 tSirBssDescription *pBssDesc,
4810 tDot11fBeaconIEs *pIes)
4811{
4812 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
4813 bool fRC = false, fCheck;
4814 tDot11fBeaconIEs *pIesLocal = pIes;
4815
4816 do {
4817 if (!pIes) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304818 if (!QDF_IS_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004819 (csr_get_parsed_bss_description_ies
4820 (pMac, pBssDesc, &pIesLocal))) {
4821 break;
4822 }
4823 }
4824 fCheck = true;
4825 if (pIesLocal->SSID.present) {
4826 bool fCheckSsid = false;
4827 if (pProfile->SSID.length) {
4828 fCheckSsid = true;
4829 }
4830 fCheck =
4831 csr_is_ssid_match(pMac, pProfile->SSID.ssId,
4832 pProfile->SSID.length,
4833 pIesLocal->SSID.ssid,
4834 pIesLocal->SSID.num_ssid,
4835 fCheckSsid);
4836 if (!fCheck)
4837 break;
4838 }
4839 if (!csr_match_connected_bss_security
4840 (pMac, pProfile, pBssDesc, pIesLocal))
4841 break;
4842 if (!csr_is_capabilities_match(pMac, pProfile->BSSType, pBssDesc))
4843 break;
4844 if (!csr_is_rate_set_match
4845 (pMac, &pIesLocal->SuppRates, &pIesLocal->ExtSuppRates))
4846 break;
4847 fCheck =
4848 csr_is_channel_band_match(pMac, pProfile->operationChannel,
4849 pBssDesc);
4850 if (!fCheck)
4851 break;
4852
4853 fRC = true;
4854
4855 } while (0);
4856
4857 if (!pIes && pIesLocal) {
4858 /* locally allocated */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304859 qdf_mem_free(pIesLocal);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004860 }
4861
4862 return fRC;
4863}
4864
4865void csr_add_rate_bitmap(uint8_t rate, uint16_t *pRateBitmap)
4866{
4867 uint16_t rateBitmap;
4868 uint16_t n = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
4869 rateBitmap = *pRateBitmap;
4870 switch (n) {
4871 case SIR_MAC_RATE_1:
4872 rateBitmap |= SIR_MAC_RATE_1_BITMAP;
4873 break;
4874 case SIR_MAC_RATE_2:
4875 rateBitmap |= SIR_MAC_RATE_2_BITMAP;
4876 break;
4877 case SIR_MAC_RATE_5_5:
4878 rateBitmap |= SIR_MAC_RATE_5_5_BITMAP;
4879 break;
4880 case SIR_MAC_RATE_11:
4881 rateBitmap |= SIR_MAC_RATE_11_BITMAP;
4882 break;
4883 case SIR_MAC_RATE_6:
4884 rateBitmap |= SIR_MAC_RATE_6_BITMAP;
4885 break;
4886 case SIR_MAC_RATE_9:
4887 rateBitmap |= SIR_MAC_RATE_9_BITMAP;
4888 break;
4889 case SIR_MAC_RATE_12:
4890 rateBitmap |= SIR_MAC_RATE_12_BITMAP;
4891 break;
4892 case SIR_MAC_RATE_18:
4893 rateBitmap |= SIR_MAC_RATE_18_BITMAP;
4894 break;
4895 case SIR_MAC_RATE_24:
4896 rateBitmap |= SIR_MAC_RATE_24_BITMAP;
4897 break;
4898 case SIR_MAC_RATE_36:
4899 rateBitmap |= SIR_MAC_RATE_36_BITMAP;
4900 break;
4901 case SIR_MAC_RATE_48:
4902 rateBitmap |= SIR_MAC_RATE_48_BITMAP;
4903 break;
4904 case SIR_MAC_RATE_54:
4905 rateBitmap |= SIR_MAC_RATE_54_BITMAP;
4906 break;
4907 }
4908 *pRateBitmap = rateBitmap;
4909}
4910
4911bool csr_check_rate_bitmap(uint8_t rate, uint16_t rateBitmap)
4912{
4913 uint16_t n = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
4914
4915 switch (n) {
4916 case SIR_MAC_RATE_1:
4917 rateBitmap &= SIR_MAC_RATE_1_BITMAP;
4918 break;
4919 case SIR_MAC_RATE_2:
4920 rateBitmap &= SIR_MAC_RATE_2_BITMAP;
4921 break;
4922 case SIR_MAC_RATE_5_5:
4923 rateBitmap &= SIR_MAC_RATE_5_5_BITMAP;
4924 break;
4925 case SIR_MAC_RATE_11:
4926 rateBitmap &= SIR_MAC_RATE_11_BITMAP;
4927 break;
4928 case SIR_MAC_RATE_6:
4929 rateBitmap &= SIR_MAC_RATE_6_BITMAP;
4930 break;
4931 case SIR_MAC_RATE_9:
4932 rateBitmap &= SIR_MAC_RATE_9_BITMAP;
4933 break;
4934 case SIR_MAC_RATE_12:
4935 rateBitmap &= SIR_MAC_RATE_12_BITMAP;
4936 break;
4937 case SIR_MAC_RATE_18:
4938 rateBitmap &= SIR_MAC_RATE_18_BITMAP;
4939 break;
4940 case SIR_MAC_RATE_24:
4941 rateBitmap &= SIR_MAC_RATE_24_BITMAP;
4942 break;
4943 case SIR_MAC_RATE_36:
4944 rateBitmap &= SIR_MAC_RATE_36_BITMAP;
4945 break;
4946 case SIR_MAC_RATE_48:
4947 rateBitmap &= SIR_MAC_RATE_48_BITMAP;
4948 break;
4949 case SIR_MAC_RATE_54:
4950 rateBitmap &= SIR_MAC_RATE_54_BITMAP;
4951 break;
4952 }
4953 return !!rateBitmap;
4954}
4955
4956bool csr_rates_is_dot11_rate_supported(tHalHandle hHal, uint8_t rate)
4957{
4958 tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
4959 uint16_t n = BITS_OFF(rate, CSR_DOT11_BASIC_RATE_MASK);
4960
4961 return csr_is_aggregate_rate_supported(pMac, n);
4962}
4963
4964uint16_t csr_rates_mac_prop_to_dot11(uint16_t Rate)
4965{
4966 uint16_t ConvertedRate = Rate;
4967
4968 switch (Rate) {
4969 case SIR_MAC_RATE_1:
4970 ConvertedRate = 2;
4971 break;
4972 case SIR_MAC_RATE_2:
4973 ConvertedRate = 4;
4974 break;
4975 case SIR_MAC_RATE_5_5:
4976 ConvertedRate = 11;
4977 break;
4978 case SIR_MAC_RATE_11:
4979 ConvertedRate = 22;
4980 break;
4981
4982 case SIR_MAC_RATE_6:
4983 ConvertedRate = 12;
4984 break;
4985 case SIR_MAC_RATE_9:
4986 ConvertedRate = 18;
4987 break;
4988 case SIR_MAC_RATE_12:
4989 ConvertedRate = 24;
4990 break;
4991 case SIR_MAC_RATE_18:
4992 ConvertedRate = 36;
4993 break;
4994 case SIR_MAC_RATE_24:
4995 ConvertedRate = 48;
4996 break;
4997 case SIR_MAC_RATE_36:
4998 ConvertedRate = 72;
4999 break;
5000 case SIR_MAC_RATE_42:
5001 ConvertedRate = 84;
5002 break;
5003 case SIR_MAC_RATE_48:
5004 ConvertedRate = 96;
5005 break;
5006 case SIR_MAC_RATE_54:
5007 ConvertedRate = 108;
5008 break;
5009
5010 case SIR_MAC_RATE_72:
5011 ConvertedRate = 144;
5012 break;
5013 case SIR_MAC_RATE_84:
5014 ConvertedRate = 168;
5015 break;
5016 case SIR_MAC_RATE_96:
5017 ConvertedRate = 192;
5018 break;
5019 case SIR_MAC_RATE_108:
5020 ConvertedRate = 216;
5021 break;
5022 case SIR_MAC_RATE_126:
5023 ConvertedRate = 252;
5024 break;
5025 case SIR_MAC_RATE_144:
5026 ConvertedRate = 288;
5027 break;
5028 case SIR_MAC_RATE_168:
5029 ConvertedRate = 336;
5030 break;
5031 case SIR_MAC_RATE_192:
5032 ConvertedRate = 384;
5033 break;
5034 case SIR_MAC_RATE_216:
5035 ConvertedRate = 432;
5036 break;
5037 case SIR_MAC_RATE_240:
5038 ConvertedRate = 480;
5039 break;
5040
5041 case 0xff:
5042 ConvertedRate = 0;
5043 break;
5044 }
5045
5046 return ConvertedRate;
5047}
5048
5049uint16_t csr_rates_find_best_rate(tSirMacRateSet *pSuppRates,
5050 tSirMacRateSet *pExtRates,
5051 tSirMacPropRateSet *pPropRates)
5052{
5053 uint8_t i;
5054 uint16_t nBest;
5055
5056 nBest = pSuppRates->rate[0] & (~CSR_DOT11_BASIC_RATE_MASK);
5057
5058 if (pSuppRates->numRates > SIR_MAC_RATESET_EID_MAX) {
5059 pSuppRates->numRates = SIR_MAC_RATESET_EID_MAX;
5060 }
5061
5062 for (i = 1U; i < pSuppRates->numRates; ++i) {
5063 nBest =
5064 (uint16_t) CSR_MAX(nBest,
5065 pSuppRates->
5066 rate[i] & (~CSR_DOT11_BASIC_RATE_MASK));
5067 }
5068
5069 if (NULL != pExtRates) {
5070 for (i = 0U; i < pExtRates->numRates; ++i) {
5071 nBest =
5072 (uint16_t) CSR_MAX(nBest,
5073 pExtRates->
5074 rate[i] &
5075 (~CSR_DOT11_BASIC_RATE_MASK));
5076 }
5077 }
5078
5079 if (NULL != pPropRates) {
5080 for (i = 0U; i < pPropRates->numPropRates; ++i) {
5081 nBest =
5082 (uint16_t) CSR_MAX(nBest,
5083 csr_rates_mac_prop_to_dot11
5084 (pPropRates->propRate[i]));
5085 }
5086 }
5087
5088 return nBest;
5089}
5090
5091void csr_release_profile(tpAniSirGlobal pMac, tCsrRoamProfile *pProfile)
5092{
5093 if (pProfile) {
5094 if (pProfile->BSSIDs.bssid) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305095 qdf_mem_free(pProfile->BSSIDs.bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 pProfile->BSSIDs.bssid = NULL;
5097 }
5098 if (pProfile->SSIDs.SSIDList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305099 qdf_mem_free(pProfile->SSIDs.SSIDList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100 pProfile->SSIDs.SSIDList = NULL;
5101 }
5102 if (pProfile->pWPAReqIE) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305103 qdf_mem_free(pProfile->pWPAReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005104 pProfile->pWPAReqIE = NULL;
5105 }
5106 if (pProfile->pRSNReqIE) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305107 qdf_mem_free(pProfile->pRSNReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005108 pProfile->pRSNReqIE = NULL;
5109 }
5110#ifdef FEATURE_WLAN_WAPI
5111 if (pProfile->pWAPIReqIE) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305112 qdf_mem_free(pProfile->pWAPIReqIE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113 pProfile->pWAPIReqIE = NULL;
5114 }
5115#endif /* FEATURE_WLAN_WAPI */
5116
5117 if (pProfile->pAddIEScan) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305118 qdf_mem_free(pProfile->pAddIEScan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119 pProfile->pAddIEScan = NULL;
5120 }
5121
5122 if (pProfile->pAddIEAssoc) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305123 qdf_mem_free(pProfile->pAddIEAssoc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005124 pProfile->pAddIEAssoc = NULL;
5125 }
5126 if (pProfile->ChannelInfo.ChannelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305127 qdf_mem_free(pProfile->ChannelInfo.ChannelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005128 pProfile->ChannelInfo.ChannelList = NULL;
5129 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305130 qdf_mem_set(pProfile, sizeof(tCsrRoamProfile), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005131 }
5132}
5133
5134void csr_free_scan_filter(tpAniSirGlobal pMac, tCsrScanResultFilter *pScanFilter)
5135{
5136 if (pScanFilter->BSSIDs.bssid) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305137 qdf_mem_free(pScanFilter->BSSIDs.bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 pScanFilter->BSSIDs.bssid = NULL;
5139 }
5140 if (pScanFilter->ChannelInfo.ChannelList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305141 qdf_mem_free(pScanFilter->ChannelInfo.ChannelList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 pScanFilter->ChannelInfo.ChannelList = NULL;
5143 }
5144 if (pScanFilter->SSIDs.SSIDList) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305145 qdf_mem_free(pScanFilter->SSIDs.SSIDList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005146 pScanFilter->SSIDs.SSIDList = NULL;
5147 }
5148}
5149
5150void csr_free_roam_profile(tpAniSirGlobal pMac, uint32_t sessionId)
5151{
5152 tCsrRoamSession *pSession = &pMac->roam.roamSession[sessionId];
5153
5154 if (pSession->pCurRoamProfile) {
5155 csr_release_profile(pMac, pSession->pCurRoamProfile);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305156 qdf_mem_free(pSession->pCurRoamProfile);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 pSession->pCurRoamProfile = NULL;
5158 }
5159}
5160
5161void csr_free_connect_bss_desc(tpAniSirGlobal pMac, uint32_t sessionId)
5162{
5163 tCsrRoamSession *pSession = &pMac->roam.roamSession[sessionId];
5164
5165 if (pSession->pConnectBssDesc) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305166 qdf_mem_free(pSession->pConnectBssDesc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167 pSession->pConnectBssDesc = NULL;
5168 }
5169}
5170
5171tSirResultCodes csr_get_disassoc_rsp_status_code(tSirSmeDisassocRsp *
5172 pSmeDisassocRsp)
5173{
5174 uint8_t *pBuffer = (uint8_t *) pSmeDisassocRsp;
5175 uint32_t ret;
5176
5177 pBuffer += (sizeof(uint16_t) + sizeof(uint16_t) + sizeof(tSirMacAddr));
5178 /* tSirResultCodes is an enum, assuming is 32bit */
5179 /* If we cannot make this assumption, use copymemory */
Anurag Chouhanc5548422016-02-24 18:33:27 +05305180 qdf_get_u32(pBuffer, &ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181
5182 return (tSirResultCodes) ret;
5183}
5184
5185tSirResultCodes csr_get_de_auth_rsp_status_code(tSirSmeDeauthRsp *pSmeRsp)
5186{
5187 uint8_t *pBuffer = (uint8_t *) pSmeRsp;
5188 uint32_t ret;
5189
5190 pBuffer +=
5191 (sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint8_t) +
5192 sizeof(uint16_t));
5193 /* tSirResultCodes is an enum, assuming is 32bit */
5194 /* If we cannot make this assumption, use copymemory */
Anurag Chouhanc5548422016-02-24 18:33:27 +05305195 qdf_get_u32(pBuffer, &ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196
5197 return (tSirResultCodes) ret;
5198}
5199
5200tSirScanType csr_get_scan_type(tpAniSirGlobal pMac, uint8_t chnId)
5201{
5202 tSirScanType scanType = eSIR_PASSIVE_SCAN;
Amar Singhala297bfa2015-10-15 15:07:29 -07005203 enum channel_state channelEnabledType;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005204
5205 channelEnabledType = cds_get_channel_state(chnId);
5206 if (CHANNEL_STATE_ENABLE == channelEnabledType) {
5207 scanType = eSIR_ACTIVE_SCAN;
5208 }
5209 return scanType;
5210}
5211
5212uint8_t csr_to_upper(uint8_t ch)
5213{
5214 uint8_t chOut;
5215
5216 if (ch >= 'a' && ch <= 'z') {
5217 chOut = ch - 'a' + 'A';
5218 } else {
5219 chOut = ch;
5220 }
5221 return chOut;
5222}
5223
5224tSirBssType csr_translate_bsstype_to_mac_type(eCsrRoamBssType csrtype)
5225{
5226 tSirBssType ret;
5227
5228 switch (csrtype) {
5229 case eCSR_BSS_TYPE_INFRASTRUCTURE:
5230 ret = eSIR_INFRASTRUCTURE_MODE;
5231 break;
5232 case eCSR_BSS_TYPE_IBSS:
5233 case eCSR_BSS_TYPE_START_IBSS:
5234 ret = eSIR_IBSS_MODE;
5235 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 case eCSR_BSS_TYPE_INFRA_AP:
5237 ret = eSIR_INFRA_AP_MODE;
5238 break;
Deepak Dhamdheree2dd5442016-05-27 15:05:51 -07005239 case eCSR_BSS_TYPE_NDI:
5240 ret = eSIR_NDI_MODE;
5241 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005242 case eCSR_BSS_TYPE_ANY:
5243 default:
5244 ret = eSIR_AUTO_MODE;
5245 break;
5246 }
5247
5248 return ret;
5249}
5250
5251/* This function use the parameters to decide the CFG value. */
5252/* CSR never sets WNI_CFG_DOT11_MODE_ALL to the CFG */
5253/* So PE should not see WNI_CFG_DOT11_MODE_ALL when it gets the CFG value */
5254eCsrCfgDot11Mode csr_get_cfg_dot11_mode_from_csr_phy_mode(tCsrRoamProfile *pProfile,
5255 eCsrPhyMode phyMode,
5256 bool fProprietary)
5257{
5258 uint32_t cfgDot11Mode = eCSR_CFG_DOT11_MODE_ABG;
5259
5260 switch (phyMode) {
5261 case eCSR_DOT11_MODE_11a:
5262 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11A;
5263 break;
5264 case eCSR_DOT11_MODE_11b:
5265 case eCSR_DOT11_MODE_11b_ONLY:
5266 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11B;
5267 break;
5268 case eCSR_DOT11_MODE_11g:
5269 case eCSR_DOT11_MODE_11g_ONLY:
5270 if (pProfile && (CSR_IS_INFRA_AP(pProfile))
5271 && (phyMode == eCSR_DOT11_MODE_11g_ONLY))
5272 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G_ONLY;
5273 else
5274 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11G;
5275 break;
5276 case eCSR_DOT11_MODE_11n:
5277 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
5278 break;
5279 case eCSR_DOT11_MODE_11n_ONLY:
5280 if (pProfile && CSR_IS_INFRA_AP(pProfile))
5281 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N_ONLY;
5282 else
5283 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
5284 break;
5285 case eCSR_DOT11_MODE_abg:
5286 cfgDot11Mode = eCSR_CFG_DOT11_MODE_ABG;
5287 break;
5288 case eCSR_DOT11_MODE_AUTO:
5289 cfgDot11Mode = eCSR_CFG_DOT11_MODE_AUTO;
5290 break;
5291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 case eCSR_DOT11_MODE_11ac:
5293 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC)) {
5294 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC;
5295 } else {
5296 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
5297 }
5298 break;
5299 case eCSR_DOT11_MODE_11ac_ONLY:
5300 if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AC)) {
5301 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11AC_ONLY;
5302 } else {
5303 cfgDot11Mode = eCSR_CFG_DOT11_MODE_11N;
5304 }
5305 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005306 default:
5307 /* No need to assign anything here */
5308 break;
5309 }
5310
5311 return cfgDot11Mode;
5312}
5313
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305314QDF_STATUS csr_get_regulatory_domain_for_country(tpAniSirGlobal pMac,
Amar Singhala297bfa2015-10-15 15:07:29 -07005315 uint8_t *pCountry,
5316 v_REGDOMAIN_t *pDomainId,
5317 enum country_src source)
5318{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305319 QDF_STATUS status = QDF_STATUS_E_INVAL;
5320 QDF_STATUS qdf_status;
Amar Singhala297bfa2015-10-15 15:07:29 -07005321 uint8_t countryCode[CDS_COUNTRY_CODE_LEN + 1];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322 v_REGDOMAIN_t domainId;
5323
5324 if (pCountry) {
5325 countryCode[0] = pCountry[0];
5326 countryCode[1] = pCountry[1];
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305327 qdf_status = cds_get_reg_domain_from_country_code(&domainId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005328 countryCode,
5329 source);
5330
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305331 if (QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 if (pDomainId) {
5333 *pDomainId = domainId;
5334 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305335 status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 } else {
5337 sms_log(pMac, LOGW,
5338 FL
5339 (" Couldn't find domain for country code %c%c"),
5340 pCountry[0], pCountry[1]);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305341 status = QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 }
5343 }
5344
5345 return status;
5346}
5347
5348/* To check whether a country code matches the one in the IE */
5349/* Only check the first two characters, ignoring in/outdoor */
5350/* pCountry -- caller allocated buffer contain the country code that is checking against */
5351/* the one in pIes. It can be NULL. */
5352/* caller must provide pIes, it cannot be NULL */
5353/* This function always return true if 11d support is not turned on. */
5354bool csr_match_country_code(tpAniSirGlobal pMac, uint8_t *pCountry,
5355 tDot11fBeaconIEs *pIes)
5356{
5357 bool fRet = true;
5358
5359 do {
5360 if (!csr_is11d_supported(pMac)) {
5361 break;
5362 }
5363 if (!pIes) {
5364 sms_log(pMac, LOGE, FL(" No IEs"));
5365 break;
5366 }
5367
5368 if (pCountry) {
5369 uint32_t i;
5370
5371 if (!pIes->Country.present) {
5372 fRet = false;
5373 break;
5374 }
5375 /* Convert the CountryCode characters to upper */
5376 for (i = 0; i < WNI_CFG_COUNTRY_CODE_LEN - 1; i++) {
5377 pCountry[i] = csr_to_upper(pCountry[i]);
5378 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305379 if (qdf_mem_cmp(pIes->Country.country, pCountry,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005380 WNI_CFG_COUNTRY_CODE_LEN - 1)) {
5381 fRet = false;
5382 break;
5383 }
5384 }
5385 } while (0);
5386
5387 return fRet;
5388}
5389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305390QDF_STATUS csr_get_modify_profile_fields(tpAniSirGlobal pMac, uint32_t sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005391 tCsrRoamModifyProfileFields *
5392 pModifyProfileFields)
5393{
5394
5395 if (!pModifyProfileFields) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305396 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005397 }
5398
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305399 qdf_mem_copy(pModifyProfileFields,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005400 &pMac->roam.roamSession[sessionId].connectedProfile.
5401 modifyProfileFields, sizeof(tCsrRoamModifyProfileFields));
5402
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305403 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005404}
5405
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305406QDF_STATUS csr_set_modify_profile_fields(tpAniSirGlobal pMac, uint32_t sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005407 tCsrRoamModifyProfileFields *
5408 pModifyProfileFields)
5409{
5410 tCsrRoamSession *pSession = CSR_GET_SESSION(pMac, sessionId);
5411
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305412 qdf_mem_copy(&pSession->connectedProfile.modifyProfileFields,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005413 pModifyProfileFields, sizeof(tCsrRoamModifyProfileFields));
5414
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305415 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416}
5417
5418
5419bool csr_is_set_key_allowed(tpAniSirGlobal pMac, uint32_t sessionId)
5420{
5421 bool fRet = true;
5422 tCsrRoamSession *pSession;
5423
5424 pSession = CSR_GET_SESSION(pMac, sessionId);
5425
5426 /*
5427 * This condition is not working for infra state. When infra is in
5428 * not-connected state the pSession->pCurRoamProfile is NULL, this
5429 * function returns true, that is incorrect.
5430 * Since SAP requires to set key without any BSS started, it needs
5431 * this condition to be met. In other words, this function is useless.
5432 * The current work-around is to process setcontext_rsp no matter
5433 * what the state is.
5434 */
5435 sms_log(pMac, LOG2,
5436 FL(" is not what it intends to. Must be revisit or removed"));
5437 if ((NULL == pSession)
5438 || (csr_is_conn_state_disconnected(pMac, sessionId)
5439 && (pSession->pCurRoamProfile != NULL)
5440 && (!(CSR_IS_INFRA_AP(pSession->pCurRoamProfile))))
5441 ) {
5442 fRet = false;
5443 }
5444
5445 return fRet;
5446}
5447
5448/* no need to acquire lock for this basic function */
5449uint16_t sme_chn_to_freq(uint8_t chanNum)
5450{
5451 int i;
5452
Amar Singhalb8d4f152016-02-10 10:21:43 -08005453 for (i = 0; i < NUM_CHANNELS; i++) {
Amar Singhal7a1726a2015-10-14 16:28:11 -07005454 if (CDS_CHANNEL_NUM(i) == chanNum)
5455 return CDS_CHANNEL_FREQ(i);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005456 }
5457
5458 return 0;
5459}
5460
5461/* Disconnect all active sessions by sending disassoc. This is mainly used to disconnect the remaining session when we
5462 * transition from concurrent sessions to a single session. The use case is Infra STA and wifi direct multiple sessions are up and
5463 * P2P session is removed. The Infra STA session remains and should resume BMPS if BMPS is enabled by default. However, there
5464 * are some issues seen with BMPS resume during this transition and this is a workaround which will allow the Infra STA session to
5465 * disconnect and auto connect back and enter BMPS this giving the same effect as resuming BMPS
5466 */
5467
5468/* Remove this code once SLM_Sessionization is supported */
5469/* BMPS_WORKAROUND_NOT_NEEDED */
5470void csr_disconnect_all_active_sessions(tpAniSirGlobal pMac)
5471{
5472 uint8_t i;
5473
5474 /* Disconnect all the active sessions */
5475 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
5476 if (CSR_IS_SESSION_VALID(pMac, i)
5477 && !csr_is_conn_state_disconnected(pMac, i)) {
5478 csr_roam_disconnect_internal(pMac, i,
5479 eCSR_DISCONNECT_REASON_UNSPECIFIED);
5480 }
5481 }
5482}
5483
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005484bool csr_is_channel_present_in_list(uint8_t *pChannelList,
5485 int numChannels, uint8_t channel)
5486{
5487 int i = 0;
5488
5489 /* Check for NULL pointer */
5490 if (!pChannelList || (numChannels == 0)) {
5491 return false;
5492 }
5493 /* Look for the channel in the list */
5494 for (i = 0; (i < numChannels) &&
5495 (i < WNI_CFG_VALID_CHANNEL_LIST_LEN); i++) {
5496 if (pChannelList[i] == channel)
5497 return true;
5498 }
5499
5500 return false;
5501}
5502
Sreelakshmi Konamki39acb132015-12-16 13:06:22 +05305503/**
5504 * sme_request_type_to_string(): converts scan request enum to string.
5505 * @request_type: scan request type enum.
5506 *
5507 * Return: Printable string for request_type
5508 */
5509const char *sme_request_type_to_string(const uint8_t request_type)
5510{
5511 switch (request_type) {
5512 CASE_RETURN_STRING(eCSR_SCAN_REQUEST_11D_SCAN);
5513 CASE_RETURN_STRING(eCSR_SCAN_REQUEST_FULL_SCAN);
5514 CASE_RETURN_STRING(eCSR_SCAN_IDLE_MODE_SCAN);
5515 CASE_RETURN_STRING(eCSR_SCAN_HO_PROBE_SCAN);
5516 CASE_RETURN_STRING(eCSR_SCAN_P2P_DISCOVERY);
5517 CASE_RETURN_STRING(eCSR_SCAN_SOFTAP_CHANNEL_RANGE);
5518 CASE_RETURN_STRING(eCSR_SCAN_P2P_FIND_PEER);
5519 default:
5520 return "Unknown Scan Request Type";
5521 }
5522}
5523
Rajeev Kumar43e25b12016-04-15 16:26:36 -07005524/**
5525 * sme_bsstype_to_string() - converts bss type to string.
5526 * @bss_type: bss type enum
5527 *
5528 * Return: printable string for bss type
5529 */
5530const char *sme_bss_type_to_string(const uint8_t bss_type)
5531{
5532 switch (bss_type) {
5533 CASE_RETURN_STRING(eCSR_BSS_TYPE_INFRASTRUCTURE);
5534 CASE_RETURN_STRING(eCSR_BSS_TYPE_INFRA_AP);
5535 CASE_RETURN_STRING(eCSR_BSS_TYPE_IBSS);
5536 CASE_RETURN_STRING(eCSR_BSS_TYPE_START_IBSS);
5537 CASE_RETURN_STRING(eCSR_BSS_TYPE_ANY);
5538 default:
5539 return "unknown bss type";
5540 }
5541}
5542
5543/**
5544 * sme_scantype_to_string() - converts scan type to string.
5545 * @scan_type: scan type enum
5546 *
5547 * Return: printable string for scan type
5548 */
5549const char *sme_scan_type_to_string(const uint8_t scan_type)
5550{
5551 switch (scan_type) {
5552 CASE_RETURN_STRING(eSIR_PASSIVE_SCAN);
5553 CASE_RETURN_STRING(eSIR_ACTIVE_SCAN);
5554 CASE_RETURN_STRING(eSIR_BEACON_TABLE);
5555 default:
5556 return "unknown scan type";
5557 }
5558}
5559
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305560QDF_STATUS csr_add_to_channel_list_front(uint8_t *pChannelList,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561 int numChannels, uint8_t channel)
5562{
5563 int i = 0;
5564
5565 /* Check for NULL pointer */
5566 if (!pChannelList)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305567 return QDF_STATUS_E_NULL_VALUE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005568
5569 /* Make room for the addition. (Start moving from the back.) */
5570 for (i = numChannels; i > 0; i--) {
5571 pChannelList[i] = pChannelList[i - 1];
5572 }
5573
5574 /* Now add the NEW channel...at the front */
5575 pChannelList[0] = channel;
5576
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305577 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005579#ifdef FEATURE_WLAN_DIAG_SUPPORT
5580/**
5581 * csr_diag_event_report() - send PE diag event
5582 * @pmac: pointer to global MAC context.
5583 * @event_typev: sub event type for DIAG event.
5584 * @status: status of the event
5585 * @reasoncode: reasoncode for the given status
5586 *
5587 * This function is called to send diag event
5588 *
5589 * Return: NA
5590 */
5591void csr_diag_event_report(tpAniSirGlobal pmac, uint16_t event_type,
5592 uint16_t status, uint16_t reasoncode)
5593{
5594 WLAN_HOST_DIAG_EVENT_DEF(diag_event, host_event_wlan_pe_payload_type);
5595
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305596 qdf_mem_zero(&diag_event, sizeof(host_event_wlan_pe_payload_type));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005597
5598 /* diag_event.bssid is already all zeroes */
5599 diag_event.sme_state = sme_get_lim_sme_state(pmac);
5600 diag_event.mlm_state = sme_get_lim_mlm_state(pmac);
5601 diag_event.event_type = event_type;
5602 diag_event.status = status;
5603 diag_event.reason_code = reasoncode;
5604
5605 WLAN_HOST_DIAG_EVENT_REPORT(&diag_event, EVENT_WLAN_PE);
5606 return;
5607}
5608#endif
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05305609
5610/**
5611 * csr_wait_for_connection_update() - Wait for hw mode update
5612 * @mac: Pointer to the MAC context
5613 * @do_release_reacquire_lock: Indicates whether release and
5614 * re-acquisition of SME global lock is required.
5615 *
5616 * Waits for CONNECTION_UPDATE_TIMEOUT time so that the
5617 * hw mode update can get processed.
5618 *
5619 * Return: True if the wait was successful, false otherwise
5620 */
5621bool csr_wait_for_connection_update(tpAniSirGlobal mac,
5622 bool do_release_reacquire_lock)
5623{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305624 QDF_STATUS status, ret;
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05305625
5626 if (do_release_reacquire_lock == true) {
5627 ret = sme_release_global_lock(&mac->sme);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305628 if (!QDF_IS_STATUS_SUCCESS(ret)) {
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05305629 cds_err("lock release fail %d", ret);
5630 return false;
5631 }
5632 }
5633
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305634 status = qdf_wait_for_connection_update();
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05305635
5636 if (do_release_reacquire_lock == true) {
5637 ret = sme_acquire_global_lock(&mac->sme);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305638 if (!QDF_IS_STATUS_SUCCESS(ret)) {
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05305639 cds_err("lock acquire fail %d", ret);
5640 return false;
5641 }
5642 }
5643
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305644 if (!QDF_IS_STATUS_SUCCESS(status)) {
Chandrasekaran, Manishekar430ee2e2015-11-16 16:28:30 +05305645 cds_err("wait for event failed");
5646 return false;
5647 }
5648
5649 return true;
5650}
Peng Xuf5d60c82015-10-02 17:17:03 -07005651
5652/**
5653 * csr_get_session_persona() - get persona of a session
5654 * @pmac: pointer to global MAC context
5655 * @session_id: session id
5656 *
5657 * This function is to return the persona of a session
5658 *
Anurag Chouhan6d760662016-02-20 16:05:43 +05305659 * Reture: enum tQDF_ADAPTER_MODE persona
Peng Xuf5d60c82015-10-02 17:17:03 -07005660 */
Anurag Chouhan6d760662016-02-20 16:05:43 +05305661enum tQDF_ADAPTER_MODE csr_get_session_persona(tpAniSirGlobal pmac,
Peng Xuf5d60c82015-10-02 17:17:03 -07005662 uint32_t session_id)
5663{
5664 tCsrRoamSession *session = NULL;
5665
5666 session = CSR_GET_SESSION(pmac, session_id);
5667 if (NULL == session || NULL == session->pCurRoamProfile)
Anurag Chouhan6d760662016-02-20 16:05:43 +05305668 return QDF_MAX_NO_OF_MODE;
Peng Xuf5d60c82015-10-02 17:17:03 -07005669
5670 return session->pCurRoamProfile->csrPersona;
5671}
Ravi Joshi4f447cb2016-07-19 13:42:01 -07005672
5673/**
5674 * csr_is_ndi_started() - function to check if NDI is started
5675 * @mac_ctx: handle to mac context
5676 * @session_id: session identifier
5677 *
5678 * returns: true if NDI is started, false otherwise
5679 */
5680bool csr_is_ndi_started(tpAniSirGlobal mac_ctx, uint32_t session_id)
5681{
5682 tCsrRoamSession *session = CSR_GET_SESSION(mac_ctx, session_id);
5683 if (!session)
5684 return false;
5685
5686 return eCSR_CONNECT_STATE_TYPE_NDI_STARTED == session->connectState;
5687}