blob: a2a6b4dceee6303753e40e20ab17f6ccd3e261d7 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Srinivas Girigowdaf936d822017-03-19 23:23:59 -07002 * Copyright (c) 2011-2017 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 * This file lim_process_auth_frame.cc contains the code
31 * for processing received Authentication Frame.
32 * Author: Chandra Modumudi
33 * Date: 03/11/02
34 * History:-
35 * Date Modified by Modification Information
36 * --------------------------------------------------------------------
37 * 05/12/2010 js To support Shared key authentication at AP side
38 *
39 */
40
41#include "wni_api.h"
42#include "wni_cfg.h"
43#include "ani_global.h"
44#include "cfg_api.h"
45
46#include "utils_api.h"
47#include "lim_utils.h"
48#include "lim_assoc_utils.h"
49#include "lim_security_utils.h"
50#include "lim_ser_des_utils.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080051#include "lim_ft.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080052#include "cds_utils.h"
yeshwanth sriram guntukafde0d522017-08-17 19:52:11 +053053#include "lim_send_messages.h"
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +053054#include "lim_process_fils.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080055
56/**
57 * is_auth_valid
58 *
59 ***FUNCTION:
60 * This function is called by lim_process_auth_frame() upon Authentication
61 * frame reception.
62 *
63 ***LOGIC:
64 * This function is used to test validity of auth frame:
65 * - AUTH1 and AUTH3 must be received in AP mode
66 * - AUTH2 and AUTH4 must be received in STA mode
67 * - AUTH3 and AUTH4 must have challenge text IE, that is,'type' field has been set to
68 * SIR_MAC_CHALLENGE_TEXT_EID by parser
69 * -
70 *
71 ***ASSUMPTIONS:
72 *
73 ***NOTE:
74 *
75 * @param *auth - Pointer to extracted auth frame body
76 *
77 * @return 0 or 1 (Valid)
78 */
79
80static inline unsigned int is_auth_valid(tpAniSirGlobal pMac,
81 tpSirMacAuthFrameBody auth,
82 tpPESession sessionEntry)
83{
84 unsigned int valid = 1;
85
86 if (((auth->authTransactionSeqNumber == SIR_MAC_AUTH_FRAME_1) ||
87 (auth->authTransactionSeqNumber == SIR_MAC_AUTH_FRAME_3)) &&
Rajeev Kumarbe5d7fd2016-04-15 14:35:12 -070088 (LIM_IS_STA_ROLE(sessionEntry)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080089 valid = 0;
90
91 if (((auth->authTransactionSeqNumber == SIR_MAC_AUTH_FRAME_2) ||
92 (auth->authTransactionSeqNumber == SIR_MAC_AUTH_FRAME_4)) &&
Rajeev Kumarbe5d7fd2016-04-15 14:35:12 -070093 (LIM_IS_AP_ROLE(sessionEntry)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080094 valid = 0;
95
96 if (((auth->authTransactionSeqNumber == SIR_MAC_AUTH_FRAME_3) ||
97 (auth->authTransactionSeqNumber == SIR_MAC_AUTH_FRAME_4)) &&
98 (auth->type != SIR_MAC_CHALLENGE_TEXT_EID) &&
99 (auth->authAlgoNumber != eSIR_SHARED_KEY))
100 valid = 0;
101
102 return valid;
103}
104
Krunal Sonia8f946d2016-01-06 20:06:06 -0800105static void lim_process_auth_shared_system_algo(tpAniSirGlobal mac_ctx,
106 tpSirMacMgmtHdr mac_hdr,
107 tSirMacAuthFrameBody *rx_auth_frm_body,
108 tSirMacAuthFrameBody *auth_frame,
109 uint8_t *challenge_txt_arr,
110 tpPESession pe_session)
111{
112 uint32_t val;
113 uint8_t cfg_privacy_opt_imp, *challenge;
114 struct tLimPreAuthNode *auth_node;
115
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530116 pe_debug("=======> eSIR_SHARED_KEY");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800117 if (LIM_IS_AP_ROLE(pe_session))
118 val = pe_session->privacy;
119 else if (wlan_cfg_get_int(mac_ctx,
120 WNI_CFG_PRIVACY_ENABLED, &val) != eSIR_SUCCESS)
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530121 pe_warn("couldnt retrieve Privacy option");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800122 cfg_privacy_opt_imp = (uint8_t) val;
123 if (!cfg_privacy_opt_imp) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530124 pe_err("rx Auth frame for unsupported auth algorithm %d "
125 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800126 rx_auth_frm_body->authAlgoNumber,
127 MAC_ADDR_ARRAY(mac_hdr->sa));
128
129 /*
130 * Authenticator does not have WEP
131 * implemented.
132 * Reject by sending Authentication frame
133 * with Auth algorithm not supported status
134 * code.
135 */
136 auth_frame->authAlgoNumber = rx_auth_frm_body->authAlgoNumber;
137 auth_frame->authTransactionSeqNumber =
138 rx_auth_frm_body->authTransactionSeqNumber + 1;
139 auth_frame->authStatusCode =
140 eSIR_MAC_AUTH_ALGO_NOT_SUPPORTED_STATUS;
141
142 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530143 mac_hdr->sa, LIM_NO_WEP_IN_FC,
144 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800145 return;
146 } else {
147 /* Create entry for this STA in pre-auth list */
148 auth_node = lim_acquire_free_pre_auth_node(mac_ctx,
149 &mac_ctx->lim.gLimPreAuthTimerTable);
150 if (auth_node == NULL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530151 pe_warn("Max preauth-nodes reached");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800152 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGW);
153 return;
154 }
155
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530156 qdf_mem_copy((uint8_t *) auth_node->peerMacAddr, mac_hdr->sa,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800157 sizeof(tSirMacAddr));
158 auth_node->mlmState = eLIM_MLM_WT_AUTH_FRAME3_STATE;
159 auth_node->authType =
160 (tAniAuthType) rx_auth_frm_body->authAlgoNumber;
161 auth_node->fSeen = 0;
162 auth_node->fTimerStarted = 0;
163 auth_node->seq_num = ((mac_hdr->seqControl.seqNumHi << 4) |
164 (mac_hdr->seqControl.seqNumLo));
Anurag Chouhan210db072016-02-22 18:42:15 +0530165 auth_node->timestamp = qdf_mc_timer_get_system_ticks();
Krunal Sonia8f946d2016-01-06 20:06:06 -0800166 lim_add_pre_auth_node(mac_ctx, auth_node);
167
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530168 pe_debug("Alloc new data: %p id: %d peer ",
Krunal Sonia8f946d2016-01-06 20:06:06 -0800169 auth_node, auth_node->authNodeIdx);
170 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOG1);
171 /* / Create and activate Auth Response timer */
172 if (tx_timer_change_context(&auth_node->timer,
173 auth_node->authNodeIdx) != TX_SUCCESS) {
174 /* Could not start Auth response timer. Log error */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530175 pe_warn("Unable to chg context auth response timer for peer");
Nishank Aggarwalabfd70b2017-03-11 16:48:25 +0530176 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGW);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800177
178 /*
Krunal Soni7ff86032016-01-19 19:20:55 -0800179 * Send Auth frame with unspecified failure status code.
Krunal Sonia8f946d2016-01-06 20:06:06 -0800180 */
181
182 auth_frame->authAlgoNumber =
183 rx_auth_frm_body->authAlgoNumber;
184 auth_frame->authTransactionSeqNumber =
185 rx_auth_frm_body->authTransactionSeqNumber + 1;
186 auth_frame->authStatusCode =
187 eSIR_MAC_UNSPEC_FAILURE_STATUS;
188
189 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530190 mac_hdr->sa, LIM_NO_WEP_IN_FC,
191 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800192 lim_delete_pre_auth_node(mac_ctx, mac_hdr->sa);
193 return;
194 }
195 lim_activate_auth_rsp_timer(mac_ctx, auth_node);
196 auth_node->fTimerStarted = 1;
197 /*
198 * get random bytes and use as challenge text.
199 * If it fails we already have random stack bytes.
200 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530201 if (!QDF_IS_STATUS_SUCCESS(cds_rand_get_bytes(0,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800202 (uint8_t *) challenge_txt_arr,
203 SIR_MAC_AUTH_CHALLENGE_LENGTH)))
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530204 pe_err("Challenge text preparation failed");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800205 challenge = auth_node->challengeText;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530206 qdf_mem_copy(challenge, (uint8_t *)challenge_txt_arr,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800207 sizeof(challenge_txt_arr));
208 /*
209 * Sending Authenticaton frame with challenge.
210 */
211 auth_frame->authAlgoNumber = rx_auth_frm_body->authAlgoNumber;
212 auth_frame->authTransactionSeqNumber =
213 rx_auth_frm_body->authTransactionSeqNumber + 1;
214 auth_frame->authStatusCode = eSIR_MAC_SUCCESS_STATUS;
215 auth_frame->type = SIR_MAC_CHALLENGE_TEXT_EID;
216 auth_frame->length = SIR_MAC_AUTH_CHALLENGE_LENGTH;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530217 qdf_mem_copy(auth_frame->challengeText,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800218 auth_node->challengeText,
219 SIR_MAC_AUTH_CHALLENGE_LENGTH);
220 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530221 mac_hdr->sa, LIM_NO_WEP_IN_FC,
222 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800223 }
224}
225
226static void lim_process_auth_open_system_algo(tpAniSirGlobal mac_ctx,
227 tpSirMacMgmtHdr mac_hdr,
228 tSirMacAuthFrameBody *rx_auth_frm_body,
229 tSirMacAuthFrameBody *auth_frame,
230 tpPESession pe_session)
231{
232 struct tLimPreAuthNode *auth_node;
233
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530234 pe_debug("=======> eSIR_OPEN_SYSTEM");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800235 /* Create entry for this STA in pre-auth list */
236 auth_node = lim_acquire_free_pre_auth_node(mac_ctx,
237 &mac_ctx->lim.gLimPreAuthTimerTable);
238 if (auth_node == NULL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530239 pe_warn("Max pre-auth nodes reached ");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800240 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGW);
241 return;
242 }
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530243 pe_debug("Alloc new data: %p peer", auth_node);
244 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGD);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530245 qdf_mem_copy((uint8_t *) auth_node->peerMacAddr,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800246 mac_hdr->sa, sizeof(tSirMacAddr));
247 auth_node->mlmState = eLIM_MLM_AUTHENTICATED_STATE;
248 auth_node->authType = (tAniAuthType) rx_auth_frm_body->authAlgoNumber;
249 auth_node->fSeen = 0;
250 auth_node->fTimerStarted = 0;
251 auth_node->seq_num = ((mac_hdr->seqControl.seqNumHi << 4) |
252 (mac_hdr->seqControl.seqNumLo));
Anurag Chouhan210db072016-02-22 18:42:15 +0530253 auth_node->timestamp = qdf_mc_timer_get_system_ticks();
Krunal Sonia8f946d2016-01-06 20:06:06 -0800254 lim_add_pre_auth_node(mac_ctx, auth_node);
255 /*
256 * Send Authenticaton frame with Success
257 * status code.
258 */
259 auth_frame->authAlgoNumber = rx_auth_frm_body->authAlgoNumber;
260 auth_frame->authTransactionSeqNumber =
261 rx_auth_frm_body->authTransactionSeqNumber + 1;
262 auth_frame->authStatusCode = eSIR_MAC_SUCCESS_STATUS;
263 lim_send_auth_mgmt_frame(mac_ctx, auth_frame, mac_hdr->sa,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530264 LIM_NO_WEP_IN_FC,
265 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800266}
267
268static void lim_process_auth_frame_type1(tpAniSirGlobal mac_ctx,
269 tpSirMacMgmtHdr mac_hdr,
270 tSirMacAuthFrameBody *rx_auth_frm_body,
271 uint8_t *rx_pkt_info, uint16_t curr_seq_num,
272 tSirMacAuthFrameBody *auth_frame, tpPESession pe_session)
273{
274 tpDphHashNode sta_ds_ptr = NULL;
275 struct tLimPreAuthNode *auth_node;
276 uint8_t challenge_txt_arr[SIR_MAC_AUTH_CHALLENGE_LENGTH];
277 uint32_t maxnum_preauth;
278 uint16_t associd = 0;
279
280 /* AuthFrame 1 */
281 sta_ds_ptr = dph_lookup_hash_entry(mac_ctx, mac_hdr->sa,
282 &associd, &pe_session->dph.dphHashTable);
283 if (sta_ds_ptr) {
284 tLimMlmDisassocReq *pMlmDisassocReq = NULL;
285 tLimMlmDeauthReq *pMlmDeauthReq = NULL;
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700286 bool isConnected = true;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800287
288 pMlmDisassocReq =
289 mac_ctx->lim.limDisassocDeauthCnfReq.pMlmDisassocReq;
290 if (pMlmDisassocReq &&
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530291 (!qdf_mem_cmp((uint8_t *) mac_hdr->sa, (uint8_t *)
Krunal Sonia8f946d2016-01-06 20:06:06 -0800292 &pMlmDisassocReq->peer_macaddr.bytes,
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530293 QDF_MAC_ADDR_SIZE))) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530294 pe_debug("TODO:Ack for disassoc frame is pending Issue delsta for "
295 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800296 MAC_ADDR_ARRAY(
297 pMlmDisassocReq->peer_macaddr.bytes));
298 lim_process_disassoc_ack_timeout(mac_ctx);
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700299 isConnected = false;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800300 }
301 pMlmDeauthReq =
302 mac_ctx->lim.limDisassocDeauthCnfReq.pMlmDeauthReq;
303 if (pMlmDeauthReq &&
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530304 (!qdf_mem_cmp((uint8_t *) mac_hdr->sa, (uint8_t *)
Krunal Sonia8f946d2016-01-06 20:06:06 -0800305 &pMlmDeauthReq->peer_macaddr.bytes,
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530306 QDF_MAC_ADDR_SIZE))) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530307 pe_debug("TODO:Ack for deauth frame is pending Issue delsta for "
308 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800309 MAC_ADDR_ARRAY(
310 pMlmDeauthReq->peer_macaddr.bytes));
311 lim_process_deauth_ack_timeout(mac_ctx);
Srinivas Girigowda74a66d62017-06-21 23:28:25 -0700312 isConnected = false;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800313 }
314
315 /*
316 * pStaDS != NULL and isConnected = 1 means the STA is already
317 * connected, But SAP received the Auth from that station.
318 * For non PMF connection send Deauth frame as STA will retry
319 * to connect back.
320 *
321 * For PMF connection the AP should not tear down or otherwise
322 * modify the state of the existing association until the
323 * SA-Query procedure determines that the original SA is
324 * invalid.
325 */
326 if (isConnected
327#ifdef WLAN_FEATURE_11W
328 && !sta_ds_ptr->rmfEnabled
329#endif
330 ) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530331 pe_err("STA is already connected but received auth frame"
Krunal Sonia8f946d2016-01-06 20:06:06 -0800332 "Send the Deauth and lim Delete Station Context"
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530333 "(staId: %d, associd: %d) ",
Krunal Sonia8f946d2016-01-06 20:06:06 -0800334 sta_ds_ptr->staIndex, associd);
335 lim_send_deauth_mgmt_frame(mac_ctx,
336 eSIR_MAC_UNSPEC_FAILURE_REASON,
337 (uint8_t *) mac_hdr->sa,
338 pe_session, false);
339 lim_trigger_sta_deletion(mac_ctx, sta_ds_ptr,
340 pe_session);
341 return;
342 }
343 }
344 /* Check if there exists pre-auth context for this STA */
345 auth_node = lim_search_pre_auth_list(mac_ctx, mac_hdr->sa);
346 if (auth_node) {
347 /* Pre-auth context exists for the STA */
348 if (!(mac_hdr->fc.retry == 0 ||
349 auth_node->seq_num != curr_seq_num)) {
350 /*
351 * This can happen when first authentication frame is
352 * received but ACK lost at STA side, in this case 2nd
353 * auth frame is already in transmission queue
354 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530355 pe_warn("STA is initiating Auth after ACK lost");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800356 return;
357 }
358 /*
359 * STA is initiating brand-new Authentication
360 * sequence after local Auth Response timeout Or STA
361 * retrying to transmit First Auth frame due to packet
362 * drop OTA Delete Pre-auth node and fall through.
363 */
364 if (auth_node->fTimerStarted)
365 lim_deactivate_and_change_per_sta_id_timer(
366 mac_ctx, eLIM_AUTH_RSP_TIMER,
367 auth_node->authNodeIdx);
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530368 pe_debug("STA is initiating brand-new Auth");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800369 lim_delete_pre_auth_node(mac_ctx, mac_hdr->sa);
370 /*
371 * SAP Mode:Disassociate the station and
372 * delete its entry if we have its entry
373 * already and received "auth" from the
374 * same station.
375 * SAP dphHashTable.size = 8
376 */
377 for (associd = 0; associd < pe_session->dph.dphHashTable.size;
378 associd++) {
379 sta_ds_ptr = dph_get_hash_entry(mac_ctx, associd,
380 &pe_session->dph.dphHashTable);
381 if (NULL == sta_ds_ptr)
382 continue;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530383 if (sta_ds_ptr->valid && (!qdf_mem_cmp(
Krunal Sonia8f946d2016-01-06 20:06:06 -0800384 (uint8_t *)&sta_ds_ptr->staAddr,
385 (uint8_t *) &(mac_hdr->sa),
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530386 (uint8_t) sizeof(tSirMacAddr))))
Krunal Sonia8f946d2016-01-06 20:06:06 -0800387 break;
388 sta_ds_ptr = NULL;
389 }
390
391 if (NULL != sta_ds_ptr
392#ifdef WLAN_FEATURE_11W
393 && !sta_ds_ptr->rmfEnabled
394#endif
395 ) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530396 pe_debug("lim Delete Station Context staId: %d associd: %d",
Krunal Sonia8f946d2016-01-06 20:06:06 -0800397 sta_ds_ptr->staIndex, associd);
398 lim_send_deauth_mgmt_frame(mac_ctx,
399 eSIR_MAC_UNSPEC_FAILURE_REASON,
400 (uint8_t *)auth_node->peerMacAddr,
401 pe_session, false);
402 lim_trigger_sta_deletion(mac_ctx, sta_ds_ptr,
403 pe_session);
404 return;
405 }
406 }
407 if (wlan_cfg_get_int(mac_ctx, WNI_CFG_MAX_NUM_PRE_AUTH,
408 (uint32_t *) &maxnum_preauth) != eSIR_SUCCESS)
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530409 pe_warn("could not retrieve MaxNumPreAuth");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800410
411 if (mac_ctx->lim.gLimNumPreAuthContexts == maxnum_preauth &&
412 !lim_delete_open_auth_pre_auth_node(mac_ctx)) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530413 pe_err("Max no of preauth context reached");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800414 /*
Krunal Soni7ff86032016-01-19 19:20:55 -0800415 * Maximum number of pre-auth contexts reached.
416 * Send Authentication frame with unspecified failure
Krunal Sonia8f946d2016-01-06 20:06:06 -0800417 */
418 auth_frame->authAlgoNumber = rx_auth_frm_body->authAlgoNumber;
419 auth_frame->authTransactionSeqNumber =
420 rx_auth_frm_body->authTransactionSeqNumber + 1;
421 auth_frame->authStatusCode =
422 eSIR_MAC_UNSPEC_FAILURE_STATUS;
423
424 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530425 mac_hdr->sa, LIM_NO_WEP_IN_FC,
426 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800427 return;
428 }
429 /* No Pre-auth context exists for the STA. */
430 if (lim_is_auth_algo_supported(mac_ctx,
431 (tAniAuthType) rx_auth_frm_body->authAlgoNumber,
432 pe_session)) {
Arif Hussainee677012017-01-26 17:50:13 -0800433
Arif Hussain7631afa2017-02-08 14:35:00 -0800434 if (lim_get_session_by_macaddr(mac_ctx, mac_hdr->sa)) {
Arif Hussainee677012017-01-26 17:50:13 -0800435
436 auth_frame->authAlgoNumber =
437 rx_auth_frm_body->authAlgoNumber;
438 auth_frame->authTransactionSeqNumber =
439 rx_auth_frm_body->authTransactionSeqNumber + 1;
440 auth_frame->authStatusCode =
441 eSIR_MAC_WME_INVALID_PARAMS_STATUS;
442
443 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
444 mac_hdr->sa, LIM_NO_WEP_IN_FC,
445 pe_session, false);
446 return;
447 }
448
Krunal Sonia8f946d2016-01-06 20:06:06 -0800449 switch (rx_auth_frm_body->authAlgoNumber) {
450 case eSIR_OPEN_SYSTEM:
451 lim_process_auth_open_system_algo(mac_ctx, mac_hdr,
452 rx_auth_frm_body, auth_frame, pe_session);
453 break;
454
455 case eSIR_SHARED_KEY:
456 lim_process_auth_shared_system_algo(mac_ctx, mac_hdr,
457 rx_auth_frm_body, auth_frame,
458 challenge_txt_arr, pe_session);
459 break;
460 default:
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530461 pe_err("rx Auth frm for unsupported auth algo %d "
462 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800463 rx_auth_frm_body->authAlgoNumber,
464 MAC_ADDR_ARRAY(mac_hdr->sa));
465
466 /*
467 * Responding party does not support the
468 * authentication algorithm requested by
469 * sending party.
470 * Reject by sending Authentication frame
471 * with auth algorithm not supported status code
472 */
473 auth_frame->authAlgoNumber =
474 rx_auth_frm_body->authAlgoNumber;
475 auth_frame->authTransactionSeqNumber =
476 rx_auth_frm_body->authTransactionSeqNumber + 1;
477 auth_frame->authStatusCode =
478 eSIR_MAC_AUTH_ALGO_NOT_SUPPORTED_STATUS;
479 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530480 mac_hdr->sa, LIM_NO_WEP_IN_FC,
481 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800482 return;
483 }
484 } else {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530485 pe_err("received Authentication frame for unsupported auth algorithm %d "
486 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800487 rx_auth_frm_body->authAlgoNumber,
488 MAC_ADDR_ARRAY(mac_hdr->sa));
489
490 /*
491 * Responding party does not support the
492 * authentication algorithm requested by sending party.
493 * Reject Authentication with StatusCode=13.
494 */
495 auth_frame->authAlgoNumber = rx_auth_frm_body->authAlgoNumber;
496 auth_frame->authTransactionSeqNumber =
497 rx_auth_frm_body->authTransactionSeqNumber + 1;
498 auth_frame->authStatusCode =
499 eSIR_MAC_AUTH_ALGO_NOT_SUPPORTED_STATUS;
500
501 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
502 mac_hdr->sa,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530503 LIM_NO_WEP_IN_FC,
504 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800505 return;
506 }
507}
508
509static void lim_process_auth_frame_type2(tpAniSirGlobal mac_ctx,
510 tpSirMacMgmtHdr mac_hdr,
511 tSirMacAuthFrameBody *rx_auth_frm_body,
512 tSirMacAuthFrameBody *auth_frame,
513 uint8_t *plainbody,
514 uint8_t *body_ptr, uint16_t frame_len,
515 tpPESession pe_session)
516{
517 uint8_t key_id, cfg_privacy_opt_imp;
518 uint32_t val, key_length = 8;
519 uint8_t defaultkey[SIR_MAC_KEY_LENGTH];
520 struct tLimPreAuthNode *auth_node;
yeshwanth sriram guntuka343a3f22017-07-27 18:30:18 +0530521 uint8_t *encr_auth_frame;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800522
523 /* AuthFrame 2 */
524 if (pe_session->limMlmState != eLIM_MLM_WT_AUTH_FRAME2_STATE) {
Krunal Sonia8f946d2016-01-06 20:06:06 -0800525 /**
526 * Check if a Reassociation is in progress and this is a
527 * Pre-Auth frame
528 */
Rajeev Kumarbe5d7fd2016-04-15 14:35:12 -0700529 if (LIM_IS_STA_ROLE(pe_session) &&
Krunal Sonia8f946d2016-01-06 20:06:06 -0800530 (pe_session->limSmeState == eLIM_SME_WT_REASSOC_STATE) &&
531 (rx_auth_frm_body->authStatusCode ==
532 eSIR_MAC_SUCCESS_STATUS) &&
533 (pe_session->ftPEContext.pFTPreAuthReq != NULL) &&
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530534 (!qdf_mem_cmp(
Krunal Sonia8f946d2016-01-06 20:06:06 -0800535 pe_session->ftPEContext.pFTPreAuthReq->preAuthbssId,
536 mac_hdr->sa, sizeof(tSirMacAddr)))) {
537
538 /* Update the FTIEs in the saved auth response */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530539 pe_warn("rx PreAuth frm2 in smestate: %d from: %pM",
Krunal Sonia8f946d2016-01-06 20:06:06 -0800540 pe_session->limSmeState, mac_hdr->sa);
541 pe_session->ftPEContext.saved_auth_rsp_length = 0;
542
543 if ((body_ptr != NULL) && (frame_len < MAX_FTIE_SIZE)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530544 qdf_mem_copy(
Krunal Sonia8f946d2016-01-06 20:06:06 -0800545 pe_session->ftPEContext.saved_auth_rsp,
546 body_ptr, frame_len);
547 pe_session->ftPEContext.saved_auth_rsp_length =
548 frame_len;
549 }
Deepak Dhamdhere262d95a2016-01-10 16:36:53 -0800550 } else {
Krunal Sonia8f946d2016-01-06 20:06:06 -0800551 /*
552 * Received Auth frame2 in an unexpected state.
553 * Log error and ignore the frame.
554 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530555 pe_debug("rx Auth frm2 from peer in state: %d addr",
Krunal Sonia8f946d2016-01-06 20:06:06 -0800556 pe_session->limMlmState);
557 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOG1);
558 }
559 return;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800560 }
561
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530562 if (qdf_mem_cmp((uint8_t *) mac_hdr->sa,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800563 (uint8_t *) &mac_ctx->lim.gpLimMlmAuthReq->peerMacAddr,
564 sizeof(tSirMacAddr))) {
565 /*
566 * Received Authentication frame from an entity
567 * other than one request was initiated.
568 * Wait until Authentication Failure Timeout.
569 */
570
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530571 pe_warn("received Auth frame2 from unexpected peer"
572 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(mac_hdr->sa));
Krunal Soni7ff86032016-01-19 19:20:55 -0800573 return;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800574 }
575
576 if (rx_auth_frm_body->authStatusCode ==
577 eSIR_MAC_AUTH_ALGO_NOT_SUPPORTED_STATUS) {
578 /*
579 * Interoperability workaround: Linksys WAP4400N is returning
580 * wrong authType in OpenAuth response in case of
581 * SharedKey AP configuration. Pretend we don't see that,
582 * so upper layer can fallback to SharedKey authType,
583 * and successfully connect to the AP.
584 */
585 if (rx_auth_frm_body->authAlgoNumber !=
586 mac_ctx->lim.gpLimMlmAuthReq->authType) {
587 rx_auth_frm_body->authAlgoNumber =
588 mac_ctx->lim.gpLimMlmAuthReq->authType;
589 }
590 }
591
592 if (rx_auth_frm_body->authAlgoNumber !=
593 mac_ctx->lim.gpLimMlmAuthReq->authType) {
594 /*
595 * Received Authentication frame with an auth
596 * algorithm other than one requested.
597 * Wait until Authentication Failure Timeout.
598 */
599
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530600 pe_warn("rx Auth frame2 for unexpected auth algo number %d "
601 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800602 rx_auth_frm_body->authAlgoNumber,
603 MAC_ADDR_ARRAY(mac_hdr->sa));
Krunal Soni7ff86032016-01-19 19:20:55 -0800604 return;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800605 }
606
607 if (rx_auth_frm_body->authStatusCode != eSIR_MAC_SUCCESS_STATUS) {
608 /*
609 * Authentication failure.
610 * Return Auth confirm with received failure code to SME
611 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530612 pe_err("rx Auth frame from peer with failure code %d "
613 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800614 rx_auth_frm_body->authStatusCode,
615 MAC_ADDR_ARRAY(mac_hdr->sa));
616 lim_restore_from_auth_state(mac_ctx, eSIR_SME_AUTH_REFUSED,
617 rx_auth_frm_body->authStatusCode,
618 pe_session);
619 return;
620 }
621
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +0530622 if (lim_process_fils_auth_frame2(mac_ctx, pe_session,
623 rx_auth_frm_body)) {
624 lim_restore_from_auth_state(mac_ctx, eSIR_SME_SUCCESS,
625 rx_auth_frm_body->authStatusCode, pe_session);
626 return;
627 }
628
Krunal Sonia8f946d2016-01-06 20:06:06 -0800629 if (rx_auth_frm_body->authAlgoNumber == eSIR_OPEN_SYSTEM) {
630 pe_session->limCurrentAuthType = eSIR_OPEN_SYSTEM;
631 auth_node = lim_acquire_free_pre_auth_node(mac_ctx,
632 &mac_ctx->lim.gLimPreAuthTimerTable);
633 if (auth_node == NULL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530634 pe_warn("Max pre-auth nodes reached");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800635 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGW);
636 return;
637 }
638
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530639 pe_debug("Alloc new data: %p peer", auth_node);
640 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGD);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530641 qdf_mem_copy((uint8_t *) auth_node->peerMacAddr,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800642 mac_ctx->lim.gpLimMlmAuthReq->peerMacAddr,
643 sizeof(tSirMacAddr));
644 auth_node->fTimerStarted = 0;
645 auth_node->authType =
646 mac_ctx->lim.gpLimMlmAuthReq->authType;
647 auth_node->seq_num =
648 ((mac_hdr->seqControl.seqNumHi << 4) |
649 (mac_hdr->seqControl.seqNumLo));
Anurag Chouhan210db072016-02-22 18:42:15 +0530650 auth_node->timestamp = qdf_mc_timer_get_system_ticks();
Krunal Sonia8f946d2016-01-06 20:06:06 -0800651 lim_add_pre_auth_node(mac_ctx, auth_node);
652 lim_restore_from_auth_state(mac_ctx, eSIR_SME_SUCCESS,
653 rx_auth_frm_body->authStatusCode, pe_session);
654 } else {
655 /* Shared key authentication */
656 if (LIM_IS_AP_ROLE(pe_session))
657 val = pe_session->privacy;
658 else if (wlan_cfg_get_int(mac_ctx,
659 WNI_CFG_PRIVACY_ENABLED,
660 &val) != eSIR_SUCCESS)
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530661 pe_warn("couldnt retrieve Privacy option");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800662 cfg_privacy_opt_imp = (uint8_t) val;
663 if (!cfg_privacy_opt_imp) {
Krunal Soni7ff86032016-01-19 19:20:55 -0800664 /*
Krunal Sonia8f946d2016-01-06 20:06:06 -0800665 * Requesting STA does not have WEP implemented.
666 * Reject with unsupported authentication algo
667 * Status code & wait until auth failure timeout
668 */
669
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530670 pe_err("rx Auth frm from peer for unsupported auth algo %d "
671 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800672 rx_auth_frm_body->authAlgoNumber,
673 MAC_ADDR_ARRAY(mac_hdr->sa));
674
675 auth_frame->authAlgoNumber =
676 rx_auth_frm_body->authAlgoNumber;
677 auth_frame->authTransactionSeqNumber =
678 rx_auth_frm_body->authTransactionSeqNumber + 1;
679 auth_frame->authStatusCode =
680 eSIR_MAC_AUTH_ALGO_NOT_SUPPORTED_STATUS;
681 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
682 mac_hdr->sa, LIM_NO_WEP_IN_FC,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530683 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800684 return;
685 }
686 if (rx_auth_frm_body->type != SIR_MAC_CHALLENGE_TEXT_EID) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530687 pe_err("rx auth frm with invalid challenge txtie");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800688 return;
689 }
690 if (wlan_cfg_get_int(mac_ctx, WNI_CFG_WEP_DEFAULT_KEYID,
691 &val) != eSIR_SUCCESS)
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530692 pe_warn("could not retrieve Default key_id");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800693 key_id = (uint8_t) val;
694 val = SIR_MAC_KEY_LENGTH;
695 if (LIM_IS_AP_ROLE(pe_session)) {
696 tpSirKeys key_ptr =
697 &pe_session->WEPKeyMaterial[key_id].key[0];
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530698 qdf_mem_copy(defaultkey, key_ptr->key,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800699 key_ptr->keyLength);
700 } else if (wlan_cfg_get_str(mac_ctx,
701 (uint16_t)(WNI_CFG_WEP_DEFAULT_KEY_1 + key_id),
702 defaultkey, &val) != eSIR_SUCCESS) {
703 /* Couldnt get Default key from CFG. */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530704 pe_warn("cant retrieve Defaultkey");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800705 auth_frame->authAlgoNumber =
706 rx_auth_frm_body->authAlgoNumber;
707 auth_frame->authTransactionSeqNumber =
708 rx_auth_frm_body->authTransactionSeqNumber + 1;
709 auth_frame->authStatusCode =
710 eSIR_MAC_CHALLENGE_FAILURE_STATUS;
711 lim_send_auth_mgmt_frame(mac_ctx,
712 auth_frame, mac_hdr->sa,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530713 LIM_NO_WEP_IN_FC,
714 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800715 lim_restore_from_auth_state(mac_ctx,
716 eSIR_SME_INVALID_WEP_DEFAULT_KEY,
717 eSIR_MAC_UNSPEC_FAILURE_REASON,
718 pe_session);
719 return;
720 }
721 key_length = val;
722 ((tpSirMacAuthFrameBody)plainbody)->authAlgoNumber =
723 sir_swap_u16if_needed(rx_auth_frm_body->authAlgoNumber);
724 ((tpSirMacAuthFrameBody)plainbody)->authTransactionSeqNumber =
725 sir_swap_u16if_needed((uint16_t)(
726 rx_auth_frm_body->authTransactionSeqNumber
727 + 1));
728 ((tpSirMacAuthFrameBody)plainbody)->authStatusCode =
729 eSIR_MAC_SUCCESS_STATUS;
730 ((tpSirMacAuthFrameBody)plainbody)->type =
731 SIR_MAC_CHALLENGE_TEXT_EID;
732 ((tpSirMacAuthFrameBody)plainbody)->length =
yeshwanth sriram guntuka343a3f22017-07-27 18:30:18 +0530733 rx_auth_frm_body->length;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530734 qdf_mem_copy((uint8_t *) (
Krunal Sonia8f946d2016-01-06 20:06:06 -0800735 (tpSirMacAuthFrameBody)plainbody)->challengeText,
736 rx_auth_frm_body->challengeText,
yeshwanth sriram guntuka343a3f22017-07-27 18:30:18 +0530737 rx_auth_frm_body->length);
738 encr_auth_frame = qdf_mem_malloc(rx_auth_frm_body->length +
739 LIM_ENCR_AUTH_INFO_LEN);
740 if (!encr_auth_frame) {
741 pe_err("failed to allocate memory");
742 return;
743 }
Krunal Sonia8f946d2016-01-06 20:06:06 -0800744 lim_encrypt_auth_frame(mac_ctx, key_id,
745 defaultkey, plainbody,
746 encr_auth_frame, key_length);
747 pe_session->limMlmState = eLIM_MLM_WT_AUTH_FRAME4_STATE;
748 MTRACE(mac_trace(mac_ctx, TRACE_CODE_MLM_STATE,
749 pe_session->peSessionId,
750 pe_session->limMlmState));
751 lim_send_auth_mgmt_frame(mac_ctx,
752 (tpSirMacAuthFrameBody)encr_auth_frame,
yeshwanth sriram guntuka343a3f22017-07-27 18:30:18 +0530753 mac_hdr->sa, rx_auth_frm_body->length,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530754 pe_session, false);
yeshwanth sriram guntuka343a3f22017-07-27 18:30:18 +0530755 qdf_mem_free(encr_auth_frame);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800756 return;
757 }
758}
759
760static void lim_process_auth_frame_type3(tpAniSirGlobal mac_ctx,
761 tpSirMacMgmtHdr mac_hdr,
762 tSirMacAuthFrameBody *rx_auth_frm_body,
763 tSirMacAuthFrameBody *auth_frame,
764 tpPESession pe_session)
765{
766 struct tLimPreAuthNode *auth_node;
767
768 /* AuthFrame 3 */
769 if (rx_auth_frm_body->authAlgoNumber != eSIR_SHARED_KEY) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530770 pe_err("rx Auth frame3 from peer with auth algo number %d "
771 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800772 rx_auth_frm_body->authAlgoNumber,
773 MAC_ADDR_ARRAY(mac_hdr->sa));
774 /*
775 * Received Authentication frame3 with algorithm other than
776 * Shared Key authentication type. Reject with Auth frame4
777 * with 'out of sequence' status code.
778 */
779 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
780 auth_frame->authTransactionSeqNumber = SIR_MAC_AUTH_FRAME_4;
781 auth_frame->authStatusCode =
782 eSIR_MAC_AUTH_FRAME_OUT_OF_SEQ_STATUS;
783 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530784 mac_hdr->sa, LIM_NO_WEP_IN_FC,
785 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800786 return;
787 }
788
789 if (LIM_IS_AP_ROLE(pe_session) ||
Krunal Sonia8f946d2016-01-06 20:06:06 -0800790 LIM_IS_IBSS_ROLE(pe_session)) {
791 /*
792 * Check if wep bit was set in FC. If not set,
793 * reject with Authentication frame4 with
794 * 'challenge failure' status code.
795 */
796 if (!mac_hdr->fc.wep) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530797 pe_err("received Auth frame3 from peer with no WEP bit set "
798 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800799 MAC_ADDR_ARRAY(mac_hdr->sa));
800 /* WEP bit is not set in FC of Auth Frame3 */
801 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
802 auth_frame->authTransactionSeqNumber =
803 SIR_MAC_AUTH_FRAME_4;
804 auth_frame->authStatusCode =
805 eSIR_MAC_CHALLENGE_FAILURE_STATUS;
806 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
807 mac_hdr->sa,
808 LIM_NO_WEP_IN_FC,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530809 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800810 return;
811 }
812
813 auth_node = lim_search_pre_auth_list(mac_ctx, mac_hdr->sa);
814 if (auth_node == NULL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530815 pe_warn("received AuthFrame3 from peer that has no preauth context "
816 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800817 MAC_ADDR_ARRAY(mac_hdr->sa));
818 /*
Krunal Soni7ff86032016-01-19 19:20:55 -0800819 * No 'pre-auth' context exists for this STA that sent
820 * an Authentication frame3. Send Auth frame4 with
821 * 'out of sequence' status code.
Krunal Sonia8f946d2016-01-06 20:06:06 -0800822 */
823 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
824 auth_frame->authTransactionSeqNumber =
825 SIR_MAC_AUTH_FRAME_4;
826 auth_frame->authStatusCode =
827 eSIR_MAC_AUTH_FRAME_OUT_OF_SEQ_STATUS;
828 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530829 mac_hdr->sa, LIM_NO_WEP_IN_FC,
830 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800831 return;
832 }
833
834 if (auth_node->mlmState == eLIM_MLM_AUTH_RSP_TIMEOUT_STATE) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530835 pe_warn("auth response timer timedout for peer "
836 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800837 MAC_ADDR_ARRAY(mac_hdr->sa));
838 /*
839 * Received Auth Frame3 after Auth Response timeout.
840 * Reject by sending Auth Frame4 with
841 * Auth respone timeout Status Code.
842 */
843 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
844 auth_frame->authTransactionSeqNumber =
845 SIR_MAC_AUTH_FRAME_4;
846 auth_frame->authStatusCode =
847 eSIR_MAC_AUTH_RSP_TIMEOUT_STATUS;
848
849 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530850 mac_hdr->sa, LIM_NO_WEP_IN_FC,
851 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800852 /* Delete pre-auth context of STA */
853 lim_delete_pre_auth_node(mac_ctx, mac_hdr->sa);
854 return;
855 }
856 if (rx_auth_frm_body->authStatusCode !=
857 eSIR_MAC_SUCCESS_STATUS) {
858 /*
859 * Received Authenetication Frame 3 with status code
860 * other than success. Wait until Auth response timeout
861 * to delete STA context.
862 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530863 pe_err("rx Auth frm3 from peer with status code %d "
864 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800865 rx_auth_frm_body->authStatusCode,
866 MAC_ADDR_ARRAY(mac_hdr->sa));
867 return;
868 }
869 /*
870 * Check if received challenge text is same as one sent in
871 * Authentication frame3
872 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530873 if (!qdf_mem_cmp(rx_auth_frm_body->challengeText,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800874 auth_node->challengeText,
875 SIR_MAC_AUTH_CHALLENGE_LENGTH)) {
Krunal Soni7ff86032016-01-19 19:20:55 -0800876 /*
877 * Challenge match. STA is autheticated
878 * Delete Authentication response timer if running
879 */
Krunal Sonia8f946d2016-01-06 20:06:06 -0800880 lim_deactivate_and_change_per_sta_id_timer(mac_ctx,
881 eLIM_AUTH_RSP_TIMER, auth_node->authNodeIdx);
882
883 auth_node->fTimerStarted = 0;
884 auth_node->mlmState = eLIM_MLM_AUTHENTICATED_STATE;
885
886 /*
887 * Send Auth Frame4 with 'success' Status Code.
888 */
889 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
890 auth_frame->authTransactionSeqNumber =
891 SIR_MAC_AUTH_FRAME_4;
892 auth_frame->authStatusCode =
893 eSIR_MAC_SUCCESS_STATUS;
894 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530895 mac_hdr->sa, LIM_NO_WEP_IN_FC,
896 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800897 return;
898 } else {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530899 pe_warn("Challenge failure for peer "MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800900 MAC_ADDR_ARRAY(mac_hdr->sa));
901 /*
902 * Challenge Failure.
903 * Send Authentication frame4 with 'challenge failure'
904 * status code and wait until Auth response timeout to
905 * delete STA context.
906 */
907 auth_frame->authAlgoNumber =
908 rx_auth_frm_body->authAlgoNumber;
909 auth_frame->authTransactionSeqNumber =
910 SIR_MAC_AUTH_FRAME_4;
911 auth_frame->authStatusCode =
912 eSIR_MAC_CHALLENGE_FAILURE_STATUS;
913 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +0530914 mac_hdr->sa, LIM_NO_WEP_IN_FC,
915 pe_session, false);
Krunal Sonia8f946d2016-01-06 20:06:06 -0800916 return;
917 }
918 }
919}
920
921static void lim_process_auth_frame_type4(tpAniSirGlobal mac_ctx,
922 tpSirMacMgmtHdr mac_hdr,
923 tSirMacAuthFrameBody *rx_auth_frm_body,
924 tpPESession pe_session)
925{
926 struct tLimPreAuthNode *auth_node;
927
928 if (pe_session->limMlmState != eLIM_MLM_WT_AUTH_FRAME4_STATE) {
929 /*
930 * Received Authentication frame4 in an unexpected state.
931 * Log error and ignore the frame.
932 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530933 pe_warn("received unexpected Auth frame4 from peer in state %d, addr "
934 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800935 pe_session->limMlmState,
936 MAC_ADDR_ARRAY(mac_hdr->sa));
Krunal Soni7ff86032016-01-19 19:20:55 -0800937 return;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800938 }
939
940 if (rx_auth_frm_body->authAlgoNumber != eSIR_SHARED_KEY) {
941 /*
942 * Received Authentication frame4 with algorithm other than
943 * Shared Key authentication type.
944 * Wait until Auth failure timeout to report authentication
945 * failure to SME.
946 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530947 pe_err("received Auth frame4 from peer with invalid auth algo %d"
948 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800949 rx_auth_frm_body->authAlgoNumber,
950 MAC_ADDR_ARRAY(mac_hdr->sa));
Krunal Soni7ff86032016-01-19 19:20:55 -0800951 return;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800952 }
953
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530954 if (qdf_mem_cmp((uint8_t *) mac_hdr->sa,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800955 (uint8_t *) &mac_ctx->lim.gpLimMlmAuthReq->peerMacAddr,
956 sizeof(tSirMacAddr))) {
957 /*
958 * Received Authentication frame from an entity
959 * other than one to which request was initiated.
960 * Wait until Authentication Failure Timeout.
961 */
962
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530963 pe_warn("received Auth frame4 from unexpected peer "MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800964 MAC_ADDR_ARRAY(mac_hdr->sa));
Krunal Soni7ff86032016-01-19 19:20:55 -0800965 return;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800966 }
967
968 if (rx_auth_frm_body->authAlgoNumber !=
969 mac_ctx->lim.gpLimMlmAuthReq->authType) {
970 /*
971 * Received Authentication frame with an auth algorithm
972 * other than one requested.
973 * Wait until Authentication Failure Timeout.
974 */
975
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530976 pe_err("received Authentication frame from peer with invalid auth seq number %d "
977 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800978 rx_auth_frm_body->authTransactionSeqNumber,
979 MAC_ADDR_ARRAY(mac_hdr->sa));
Krunal Soni7ff86032016-01-19 19:20:55 -0800980 return;
Krunal Sonia8f946d2016-01-06 20:06:06 -0800981 }
982
983 if (rx_auth_frm_body->authStatusCode == eSIR_MAC_SUCCESS_STATUS) {
Krunal Soni7ff86032016-01-19 19:20:55 -0800984 /*
985 * Authentication Success, Inform SME of same.
Krunal Sonia8f946d2016-01-06 20:06:06 -0800986 */
987 pe_session->limCurrentAuthType = eSIR_SHARED_KEY;
988 auth_node = lim_acquire_free_pre_auth_node(mac_ctx,
989 &mac_ctx->lim.gLimPreAuthTimerTable);
990 if (auth_node == NULL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530991 pe_warn("Max pre-auth nodes reached");
Krunal Sonia8f946d2016-01-06 20:06:06 -0800992 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGW);
993 return;
994 }
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +0530995 pe_debug("Alloc new data: %p peer", auth_node);
996 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGD);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530997 qdf_mem_copy((uint8_t *) auth_node->peerMacAddr,
Krunal Sonia8f946d2016-01-06 20:06:06 -0800998 mac_ctx->lim.gpLimMlmAuthReq->peerMacAddr,
999 sizeof(tSirMacAddr));
1000 auth_node->fTimerStarted = 0;
1001 auth_node->authType = mac_ctx->lim.gpLimMlmAuthReq->authType;
1002 auth_node->seq_num = ((mac_hdr->seqControl.seqNumHi << 4) |
1003 (mac_hdr->seqControl.seqNumLo));
Anurag Chouhan210db072016-02-22 18:42:15 +05301004 auth_node->timestamp = qdf_mc_timer_get_system_ticks();
Krunal Sonia8f946d2016-01-06 20:06:06 -08001005 lim_add_pre_auth_node(mac_ctx, auth_node);
1006 lim_restore_from_auth_state(mac_ctx, eSIR_SME_SUCCESS,
1007 rx_auth_frm_body->authStatusCode, pe_session);
1008 } else {
1009 /*
1010 * Authentication failure.
1011 * Return Auth confirm with received failure code to SME
1012 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301013 pe_err("Authentication failure from peer "MAC_ADDRESS_STR,
1014 MAC_ADDR_ARRAY(mac_hdr->sa));
Krunal Sonia8f946d2016-01-06 20:06:06 -08001015 lim_restore_from_auth_state(mac_ctx, eSIR_SME_AUTH_REFUSED,
1016 rx_auth_frm_body->authStatusCode,
1017 pe_session);
1018 }
1019}
1020
yeshwanth sriram guntukafde0d522017-08-17 19:52:11 +05301021void lim_send_open_system_auth(void *ctx, uint32_t param)
1022{
1023 tLimMlmAuthReq *auth_req;
1024 tpPESession session_entry;
1025 tpAniSirGlobal mac_ctx = (tpAniSirGlobal)ctx;
1026 uint8_t session_id;
1027
1028 session_id = mac_ctx->lim.limTimers.open_sys_auth_timer.sessionId;
1029 session_entry = pe_find_session_by_session_id(mac_ctx, session_id);
1030
1031 if (!session_entry)
1032 return;
1033 /* Trigger MAC based Authentication */
1034 auth_req = qdf_mem_malloc(sizeof(tLimMlmAuthReq));
1035 if (!auth_req) {
1036 pe_err("mlmAuthReq :Memory alloc failed");
1037 lim_handle_sme_join_result(mac_ctx,
1038 eSIR_SME_AUTH_TIMEOUT_RESULT_CODE,
1039 eSIR_MAC_AUTH_ALGO_NOT_SUPPORTED_STATUS,
1040 session_entry);
1041 tx_timer_deactivate(&mac_ctx->lim.limTimers.
1042 open_sys_auth_timer);
1043 return;
1044 }
1045 sir_copy_mac_addr(auth_req->peerMacAddr, session_entry->bssId);
1046 auth_req->authType = eSIR_OPEN_SYSTEM;
1047 /* Update PE session Id */
1048 auth_req->sessionId = session_id;
1049 if (wlan_cfg_get_int(mac_ctx, WNI_CFG_AUTHENTICATE_FAILURE_TIMEOUT,
1050 (uint32_t *) &auth_req->authFailureTimeout) != eSIR_SUCCESS) {
1051 pe_err("Fail:retrieve AuthFailureTimeout");
1052 }
1053 lim_post_mlm_message(mac_ctx, LIM_MLM_AUTH_REQ, (uint32_t *) auth_req);
1054 tx_timer_deactivate(&mac_ctx->lim.limTimers.open_sys_auth_timer);
1055
1056}
1057
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058/**
Krunal Sonia8f946d2016-01-06 20:06:06 -08001059 * lim_process_auth_frame() - to process auth frame
1060 * @mac_ctx - Pointer to Global MAC structure
1061 * @rx_pkt_info - A pointer to Rx packet info structure
1062 * @session - A pointer to session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064 * This function is called by limProcessMessageQueue() upon Authentication
1065 * frame reception.
1066 *
Krunal Sonia8f946d2016-01-06 20:06:06 -08001067 * LOGIC:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068 * This function processes received Authentication frame and responds
1069 * with either next Authentication frame in sequence to peer MAC entity
1070 * or LIM_MLM_AUTH_IND on AP or LIM_MLM_AUTH_CNF on STA.
1071 *
Krunal Sonia8f946d2016-01-06 20:06:06 -08001072 * NOTE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 * 1. Authentication failures are reported to SME with same status code
1074 * received from the peer MAC entity.
1075 * 2. Authentication frame2/4 received with alogirthm number other than
1076 * one requested in frame1/3 are logged with an error and auth confirm
1077 * will be sent to SME only after auth failure timeout.
1078 * 3. Inconsistency in the spec:
1079 * On receiving Auth frame2, specs says that if WEP key mapping key
1080 * or default key is NULL, Auth frame3 with a status code 15 (challenge
1081 * failure to be returned to peer entity. However, section 7.2.3.10,
1082 * table 14 says that status code field is 'reserved' for frame3 !
1083 * In the current implementation, Auth frame3 is returned with status
1084 * code 15 overriding section 7.2.3.10.
1085 * 4. If number pre-authentications reach configrable max limit,
1086 * Authentication frame with 'unspecified failure' status code is
1087 * returned to requesting entity.
1088 *
Krunal Sonia8f946d2016-01-06 20:06:06 -08001089 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001090 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091void
Krunal Sonia8f946d2016-01-06 20:06:06 -08001092lim_process_auth_frame(tpAniSirGlobal mac_ctx, uint8_t *rx_pkt_info,
1093 tpPESession pe_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001094{
Krunal Sonia8f946d2016-01-06 20:06:06 -08001095 uint8_t *body_ptr, key_id, cfg_privacy_opt_imp;
1096 uint8_t defaultkey[SIR_MAC_KEY_LENGTH];
Krishna Kumaar Natarajan9cc71e62017-07-24 21:08:29 -07001097 uint8_t plainbody[LIM_ENCR_AUTH_BODY_LEN];
Krunal Sonia8f946d2016-01-06 20:06:06 -08001098 uint8_t decrypt_result;
1099 uint16_t frame_len, curr_seq_num = 0;
1100 uint32_t val, key_length = 8;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301101 tSirMacAuthFrameBody *rx_auth_frm_body, *rx_auth_frame, *auth_frame;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001102 tpSirMacMgmtHdr mac_hdr;
1103 struct tLimPreAuthNode *auth_node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001104
1105 /* Get pointer to Authentication frame header and body */
Krunal Sonia8f946d2016-01-06 20:06:06 -08001106 mac_hdr = WMA_GET_RX_MAC_HEADER(rx_pkt_info);
1107 frame_len = WMA_GET_RX_PAYLOAD_LEN(rx_pkt_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001108
Krunal Sonia8f946d2016-01-06 20:06:06 -08001109 if (!frame_len) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001110 /* Log error */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301111 pe_err("received Auth frame with no body from: %pM",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001112 mac_hdr->sa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001113 return;
1114 }
1115
Krunal Sonia8f946d2016-01-06 20:06:06 -08001116 if (lim_is_group_addr(mac_hdr->sa)) {
1117 /*
1118 * Received Auth frame from a BC/MC address
1119 * Log error and ignore it
1120 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301121 pe_err("received Auth frame from a BC/MC addr: %pM",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001122 mac_hdr->sa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001123 return;
1124 }
Krunal Sonia8f946d2016-01-06 20:06:06 -08001125 curr_seq_num = (mac_hdr->seqControl.seqNumHi << 4) |
1126 (mac_hdr->seqControl.seqNumLo);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -07001128 pe_info("Sessionid: %d System role: %d limMlmState: %d: Auth response Received BSSID: "MAC_ADDRESS_STR" RSSI: %d",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001129 pe_session->peSessionId, GET_LIM_SYSTEM_ROLE(pe_session),
1130 pe_session->limMlmState, MAC_ADDR_ARRAY(mac_hdr->bssId),
1131 (uint) abs((int8_t) WMA_GET_RX_RSSI_NORMALIZED(rx_pkt_info)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001132
Krunal Sonia8f946d2016-01-06 20:06:06 -08001133 body_ptr = WMA_GET_RX_MPDU_DATA(rx_pkt_info);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134
1135 /* Restore default failure timeout */
Anurag Chouhan6d760662016-02-20 16:05:43 +05301136 if (QDF_P2P_CLIENT_MODE == pe_session->pePersona &&
Krunal Sonia8f946d2016-01-06 20:06:06 -08001137 pe_session->defaultAuthFailureTimeout) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301138 pe_debug("Restore default failure timeout");
Krunal Sonia8f946d2016-01-06 20:06:06 -08001139 cfg_set_int(mac_ctx, WNI_CFG_AUTHENTICATE_FAILURE_TIMEOUT,
1140 pe_session->defaultAuthFailureTimeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 }
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301142
1143 rx_auth_frame = qdf_mem_malloc(sizeof(tSirMacAuthFrameBody));
1144 if (!rx_auth_frame) {
1145 pe_err("failed to allocate memory");
1146 return;
1147 }
1148
1149 auth_frame = qdf_mem_malloc(sizeof(tSirMacAuthFrameBody));
1150 if (!auth_frame) {
1151 pe_err("failed to allocate memory");
1152 goto free;
1153 }
1154
Krunal Sonia8f946d2016-01-06 20:06:06 -08001155 /*
1156 * Determine if WEP bit is set in the FC or received MAC header
1157 * Note: WEP bit is set in FC of MAC header.
1158 */
1159 if (mac_hdr->fc.wep) {
1160 /*
1161 * If TKIP counter measures enabled then issue Deauth
1162 * frame to station
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 */
Krunal Sonia8f946d2016-01-06 20:06:06 -08001164 if (pe_session->bTkipCntrMeasActive &&
1165 LIM_IS_AP_ROLE(pe_session)) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301166 pe_err("Tkip counter enabled, send deauth to: %pM",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001167 mac_hdr->sa);
1168 lim_send_deauth_mgmt_frame(mac_ctx,
1169 eSIR_MAC_MIC_FAILURE_REASON,
1170 mac_hdr->sa, pe_session, false);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301171 goto free;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172 }
1173 /* Extract key ID from IV (most 2 bits of 4th byte of IV) */
Krunal Sonia8f946d2016-01-06 20:06:06 -08001174 key_id = (*(body_ptr + 3)) >> 6;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001175
Krunal Sonia8f946d2016-01-06 20:06:06 -08001176 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001177 * On STA in infrastructure BSS, Authentication frames received
1178 * with WEP bit set in the FC must be rejected with challenge
Krunal Sonia8f946d2016-01-06 20:06:06 -08001179 * failure status code (wierd thing in the spec - this should've
1180 * been rejected with unspecified failure/unexpected assertion
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001181 * of wep bit (this status code does not exist though) or
1182 * Out-of-sequence-Authentication-Frame status code.
1183 */
Rajeev Kumarbe5d7fd2016-04-15 14:35:12 -07001184 if (LIM_IS_STA_ROLE(pe_session)) {
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301185 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
1186 auth_frame->authTransactionSeqNumber =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 SIR_MAC_AUTH_FRAME_4;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301188 auth_frame->authStatusCode =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001189 eSIR_MAC_CHALLENGE_FAILURE_STATUS;
1190 /* Log error */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301191 pe_err("rx Auth frm with wep bit set role: %d %pM",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001192 GET_LIM_SYSTEM_ROLE(pe_session), mac_hdr->sa);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301193 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +05301194 mac_hdr->sa, LIM_NO_WEP_IN_FC,
1195 pe_session, false);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301196 goto free;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197 }
1198
Krunal Sonia8f946d2016-01-06 20:06:06 -08001199 if (frame_len < LIM_ENCR_AUTH_BODY_LEN) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200 /* Log error */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301201 pe_err("Not enough size: %d to decry rx Auth frm",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001202 frame_len);
1203 lim_print_mac_addr(mac_ctx, mac_hdr->sa, LOGE);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301204 goto free;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205 }
Krunal Sonia8f946d2016-01-06 20:06:06 -08001206 if (LIM_IS_AP_ROLE(pe_session)) {
1207 val = pe_session->privacy;
1208 } else if (wlan_cfg_get_int(mac_ctx, WNI_CFG_PRIVACY_ENABLED,
1209 &val) != eSIR_SUCCESS) {
1210 /*
1211 * Accept Authentication frame only if Privacy is
1212 * implemented, if Could not get Privacy option
1213 * from CFG then Log fatal error
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301215 pe_warn("could not retrieve Privacy option");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001216 }
Krunal Sonia8f946d2016-01-06 20:06:06 -08001217 cfg_privacy_opt_imp = (uint8_t) val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001218
Krunal Sonia8f946d2016-01-06 20:06:06 -08001219 if (!cfg_privacy_opt_imp) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301220 pe_err("received Authentication frame3 from peer that while privacy option is turned OFF "
1221 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001222 MAC_ADDR_ARRAY(mac_hdr->sa));
1223 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001224 * Privacy option is not implemented.
1225 * So reject Authentication frame received with
1226 * WEP bit set by sending Authentication frame
1227 * with 'challenge failure' status code. This is
1228 * another strange thing in the spec. Status code
1229 * should have been 'unsupported algorithm' status code.
1230 */
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301231 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
1232 auth_frame->authTransactionSeqNumber =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233 SIR_MAC_AUTH_FRAME_4;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301234 auth_frame->authStatusCode =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235 eSIR_MAC_CHALLENGE_FAILURE_STATUS;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301236 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +05301237 mac_hdr->sa, LIM_NO_WEP_IN_FC,
1238 pe_session, false);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301239 goto free;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241
Krunal Sonia8f946d2016-01-06 20:06:06 -08001242 /*
1243 * Privacy option is implemented. Check if the received frame is
1244 * Authentication frame3 and there is a context for requesting
1245 * STA. If not, reject with unspecified failure status code
1246 */
1247 auth_node = lim_search_pre_auth_list(mac_ctx, mac_hdr->sa);
1248 if (auth_node == NULL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301249 pe_err("rx Auth frame with no preauth ctx with WEP bit set "
1250 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001251 MAC_ADDR_ARRAY(mac_hdr->sa));
1252 /*
1253 * No 'pre-auth' context exists for this STA
1254 * that sent an Authentication frame with FC
1255 * bit set. Send Auth frame4 with
1256 * 'out of sequence' status code.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001257 */
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301258 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
1259 auth_frame->authTransactionSeqNumber =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001260 SIR_MAC_AUTH_FRAME_4;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301261 auth_frame->authStatusCode =
Krunal Sonia8f946d2016-01-06 20:06:06 -08001262 eSIR_MAC_AUTH_FRAME_OUT_OF_SEQ_STATUS;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301263 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +05301264 mac_hdr->sa, LIM_NO_WEP_IN_FC,
1265 pe_session, false);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301266 goto free;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001267 }
1268 /* Change the auth-response timeout */
1269 lim_deactivate_and_change_per_sta_id_timer(mac_ctx,
1270 eLIM_AUTH_RSP_TIMER, auth_node->authNodeIdx);
1271
1272 /* 'Pre-auth' status exists for STA */
1273 if ((auth_node->mlmState != eLIM_MLM_WT_AUTH_FRAME3_STATE) &&
1274 (auth_node->mlmState !=
1275 eLIM_MLM_AUTH_RSP_TIMEOUT_STATE)) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301276 pe_err("received Authentication frame from peer that is in state %d "
1277 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001278 auth_node->mlmState,
1279 MAC_ADDR_ARRAY(mac_hdr->sa));
1280 /*
1281 * Should not have received Authentication frame
1282 * with WEP bit set in FC in other states.
1283 * Reject by sending Authenticaton frame with
1284 * out of sequence Auth frame status code.
1285 */
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301286 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
1287 auth_frame->authTransactionSeqNumber =
Krunal Sonia8f946d2016-01-06 20:06:06 -08001288 SIR_MAC_AUTH_FRAME_4;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301289 auth_frame->authStatusCode =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001290 eSIR_MAC_AUTH_FRAME_OUT_OF_SEQ_STATUS;
1291
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301292 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +05301293 mac_hdr->sa, LIM_NO_WEP_IN_FC,
1294 pe_session, false);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301295 goto free;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 }
1297
Krunal Sonia8f946d2016-01-06 20:06:06 -08001298 val = SIR_MAC_KEY_LENGTH;
1299
1300 if (LIM_IS_AP_ROLE(pe_session)) {
1301 tpSirKeys key_ptr;
1302 key_ptr = &pe_session->WEPKeyMaterial[key_id].key[0];
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301303 qdf_mem_copy(defaultkey, key_ptr->key,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001304 key_ptr->keyLength);
1305 val = key_ptr->keyLength;
1306 } else if (wlan_cfg_get_str(mac_ctx,
1307 (uint16_t) (WNI_CFG_WEP_DEFAULT_KEY_1 + key_id),
1308 defaultkey, &val) != eSIR_SUCCESS) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301309 pe_warn("could not retrieve Default key");
Krunal Sonia8f946d2016-01-06 20:06:06 -08001310
1311 /*
1312 * Send Authentication frame
1313 * with challenge failure status code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 */
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301315 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
1316 auth_frame->authTransactionSeqNumber =
Krunal Sonia8f946d2016-01-06 20:06:06 -08001317 SIR_MAC_AUTH_FRAME_4;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301318 auth_frame->authStatusCode =
Krunal Sonia8f946d2016-01-06 20:06:06 -08001319 eSIR_MAC_CHALLENGE_FAILURE_STATUS;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301320 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +05301321 mac_hdr->sa, LIM_NO_WEP_IN_FC,
1322 pe_session, false);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301323 goto free;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001324 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325
Krunal Sonia8f946d2016-01-06 20:06:06 -08001326 key_length = val;
1327 decrypt_result = lim_decrypt_auth_frame(mac_ctx, defaultkey,
1328 body_ptr, plainbody, key_length,
1329 (uint16_t) (frame_len -
1330 SIR_MAC_WEP_IV_LENGTH));
1331 if (decrypt_result == LIM_DECRYPT_ICV_FAIL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301332 pe_err("received Authentication frame from peer that failed decryption: "
1333 MAC_ADDRESS_STR,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001334 MAC_ADDR_ARRAY(mac_hdr->sa));
1335 /* ICV failure */
1336 lim_delete_pre_auth_node(mac_ctx, mac_hdr->sa);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301337 auth_frame->authAlgoNumber = eSIR_SHARED_KEY;
1338 auth_frame->authTransactionSeqNumber =
Krunal Sonia8f946d2016-01-06 20:06:06 -08001339 SIR_MAC_AUTH_FRAME_4;
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301340 auth_frame->authStatusCode =
Krunal Sonia8f946d2016-01-06 20:06:06 -08001341 eSIR_MAC_CHALLENGE_FAILURE_STATUS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301343 lim_send_auth_mgmt_frame(mac_ctx, auth_frame,
Abhishek Singh7d3bc3e2016-02-03 17:45:01 +05301344 mac_hdr->sa, LIM_NO_WEP_IN_FC,
1345 pe_session, false);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301346 goto free;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001347 }
1348 if ((sir_convert_auth_frame2_struct(mac_ctx, plainbody,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301349 frame_len - 8, rx_auth_frame) != eSIR_SUCCESS)
1350 || (!is_auth_valid(mac_ctx, rx_auth_frame,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001351 pe_session))) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301352 pe_err("failed to convert Auth Frame to structure or Auth is not valid");
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301353 goto free;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001354 }
1355 } else if ((sir_convert_auth_frame2_struct(mac_ctx, body_ptr,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301356 frame_len, rx_auth_frame) != eSIR_SUCCESS)
1357 || (!is_auth_valid(mac_ctx, rx_auth_frame,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001358 pe_session))) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301359 pe_err("failed to convert Auth Frame to structure or Auth is not valid");
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301360 goto free;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001361 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301363 rx_auth_frm_body = rx_auth_frame;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301365 pe_debug("Received Auth frame with type: %d seqnum: %d status: %d %d",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001366 (uint32_t) rx_auth_frm_body->authAlgoNumber,
1367 (uint32_t) rx_auth_frm_body->authTransactionSeqNumber,
1368 (uint32_t) rx_auth_frm_body->authStatusCode,
1369 (uint32_t) mac_ctx->lim.gLimNumPreAuthContexts);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301371 if (!lim_is_valid_fils_auth_frame(mac_ctx, pe_session,
1372 rx_auth_frm_body)) {
1373 pe_err("Received invalid FILS auth packet");
1374 goto free;
1375 }
1376
Rajeev Kumar9b755ef2016-04-14 15:32:21 -07001377 /*
1378 * IOT Workaround: with invalid WEP key, some APs reply
1379 * AuthFrame 4 with invalid seqNumber. This AuthFrame
1380 * will be dropped by driver, thus driver sends the
1381 * generic status code instead of protocol status code.
1382 * As a workaround, override AuthFrame 4's seqNumber.
1383 */
1384 if ((pe_session->limMlmState ==
1385 eLIM_MLM_WT_AUTH_FRAME4_STATE) &&
1386 (rx_auth_frm_body->authTransactionSeqNumber !=
1387 SIR_MAC_AUTH_FRAME_1) &&
1388 (rx_auth_frm_body->authTransactionSeqNumber !=
1389 SIR_MAC_AUTH_FRAME_2) &&
1390 (rx_auth_frm_body->authTransactionSeqNumber !=
1391 SIR_MAC_AUTH_FRAME_3)) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301392 pe_warn("Override AuthFrame 4's seqNumber to 4");
Rajeev Kumar9b755ef2016-04-14 15:32:21 -07001393 rx_auth_frm_body->authTransactionSeqNumber =
1394 SIR_MAC_AUTH_FRAME_4;
1395 }
1396
1397
Krunal Sonia8f946d2016-01-06 20:06:06 -08001398 switch (rx_auth_frm_body->authTransactionSeqNumber) {
1399 case SIR_MAC_AUTH_FRAME_1:
1400 lim_process_auth_frame_type1(mac_ctx,
1401 mac_hdr, rx_auth_frm_body, rx_pkt_info,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301402 curr_seq_num, auth_frame, pe_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 break;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001404 case SIR_MAC_AUTH_FRAME_2:
1405 lim_process_auth_frame_type2(mac_ctx,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301406 mac_hdr, rx_auth_frm_body, auth_frame, plainbody,
Krunal Sonia8f946d2016-01-06 20:06:06 -08001407 body_ptr, frame_len, pe_session);
1408 break;
1409 case SIR_MAC_AUTH_FRAME_3:
1410 lim_process_auth_frame_type3(mac_ctx,
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301411 mac_hdr, rx_auth_frm_body, auth_frame, pe_session);
Krunal Sonia8f946d2016-01-06 20:06:06 -08001412 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 case SIR_MAC_AUTH_FRAME_4:
Krunal Sonia8f946d2016-01-06 20:06:06 -08001414 lim_process_auth_frame_type4(mac_ctx,
1415 mac_hdr, rx_auth_frm_body, pe_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001416 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 default:
Krunal Sonia8f946d2016-01-06 20:06:06 -08001418 /* Invalid Authentication Frame received. Ignore it. */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301419 pe_warn("rx auth frm with invalid authseq no: %d from: %pM",
Krunal Sonia8f946d2016-01-06 20:06:06 -08001420 rx_auth_frm_body->authTransactionSeqNumber,
1421 mac_hdr->sa);
Krunal Soni7ff86032016-01-19 19:20:55 -08001422 break;
Krunal Sonia8f946d2016-01-06 20:06:06 -08001423 }
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05301424free:
1425 if (auth_frame)
1426 qdf_mem_free(auth_frame);
1427 if (rx_auth_frame)
1428 qdf_mem_free(rx_auth_frame);
Krunal Sonia8f946d2016-01-06 20:06:06 -08001429}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431/*----------------------------------------------------------------------
1432 *
1433 * Pass the received Auth frame. This is possibly the pre-auth from the
1434 * neighbor AP, in the same mobility domain.
1435 * This will be used in case of 11r FT.
1436 *
1437 * !!!! This is going to be renoved for the next checkin. We will be creating
1438 * the session before sending out the Auth. Thus when auth response
1439 * is received we will have a session in progress. !!!!!
1440 ***----------------------------------------------------------------------
1441 */
1442tSirRetStatus lim_process_auth_frame_no_session(tpAniSirGlobal pMac, uint8_t *pBd,
1443 void *body)
1444{
1445 tpSirMacMgmtHdr pHdr;
1446 tpPESession psessionEntry = NULL;
1447 uint8_t *pBody;
1448 uint16_t frameLen;
1449 tSirMacAuthFrameBody rxAuthFrame;
1450 tSirMacAuthFrameBody *pRxAuthFrameBody = NULL;
1451 tSirRetStatus ret_status = eSIR_FAILURE;
1452 int i;
1453
1454 pHdr = WMA_GET_RX_MAC_HEADER(pBd);
1455 pBody = WMA_GET_RX_MPDU_DATA(pBd);
1456 frameLen = WMA_GET_RX_PAYLOAD_LEN(pBd);
1457
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301458 pe_info("Auth Frame Received: BSSID " MAC_ADDRESS_STR " (RSSI %d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 MAC_ADDR_ARRAY(pHdr->bssId),
Deepak Dhamdhere68929ec2015-08-05 15:16:35 -07001460 (uint) abs((int8_t) WMA_GET_RX_RSSI_NORMALIZED(pBd)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461
1462 /* Auth frame has come on a new BSS, however, we need to find the session
1463 * from where the auth-req was sent to the new AP
1464 */
1465 for (i = 0; i < pMac->lim.maxBssId; i++) {
1466 /* Find first free room in session table */
1467 if (pMac->lim.gpSession[i].valid == true &&
1468 pMac->lim.gpSession[i].ftPEContext.ftPreAuthSession ==
1469 true) {
1470 /* Found the session */
1471 psessionEntry = &pMac->lim.gpSession[i];
1472 pMac->lim.gpSession[i].ftPEContext.ftPreAuthSession =
1473 false;
1474 }
1475 }
1476
1477 if (psessionEntry == NULL) {
Varun Reddy Yeturuaa5a80c2017-05-23 18:40:07 -07001478 pe_debug("cannot find session id in FT pre-auth phase");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001479 return eSIR_FAILURE;
1480 }
1481
1482 if (psessionEntry->ftPEContext.pFTPreAuthReq == NULL) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301483 pe_err("Error: No FT");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 /* No FT in progress. */
1485 return eSIR_FAILURE;
1486 }
1487
1488 if (frameLen == 0) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301489 pe_err("Error: Frame len = 0");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 return eSIR_FAILURE;
1491 }
Nishank Aggarwalabfd70b2017-03-11 16:48:25 +05301492 lim_print_mac_addr(pMac, pHdr->bssId, LOGD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 lim_print_mac_addr(pMac,
1494 psessionEntry->ftPEContext.pFTPreAuthReq->preAuthbssId,
Nishank Aggarwalabfd70b2017-03-11 16:48:25 +05301495 LOGD);
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301496 pe_debug("seqControl: 0x%X",
Deepak Dhamdhere26bda452016-01-09 22:54:48 -08001497 ((pHdr->seqControl.seqNumHi << 8) |
1498 (pHdr->seqControl.seqNumLo << 4) |
1499 (pHdr->seqControl.fragNum)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500
1501 /* Check that its the same bssId we have for preAuth */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301502 if (qdf_mem_cmp
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503 (psessionEntry->ftPEContext.pFTPreAuthReq->preAuthbssId,
1504 pHdr->bssId, sizeof(tSirMacAddr))) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301505 pe_err("Error: Same bssid as preauth BSSID");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001506 /* In this case SME if indeed has triggered a */
1507 /* pre auth it will time out. */
1508 return eSIR_FAILURE;
1509 }
1510
1511 if (true ==
1512 psessionEntry->ftPEContext.pFTPreAuthReq->bPreAuthRspProcessed) {
1513 /*
1514 * This is likely a duplicate for the same pre-auth request.
1515 * PE/LIM already posted a response to SME. Hence, drop it.
1516 * TBD:
1517 * 1) How did we even receive multiple auth responses?
1518 * 2) Do we need to delete pre-auth session? Suppose we
1519 * previously received an auth resp with failure which
1520 * would not have created the session and forwarded to SME.
1521 * And, we subsequently received an auth resp with success
1522 * which would have created the session. This will now be
1523 * dropped without being forwarded to SME! However, it is
1524 * very unlikely to receive auth responses from the same
1525 * AP with different reason codes.
1526 * NOTE: return eSIR_SUCCESS so that the packet is dropped
1527 * as this was indeed a response from the BSSID we tried to
1528 * pre-auth.
1529 */
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301530 pe_debug("Auth rsp already posted to SME"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531 " (session %p, FT session %p)", psessionEntry,
1532 psessionEntry);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533 return eSIR_SUCCESS;
1534 } else {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301535 pe_warn("Auth rsp not yet posted to SME"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536 " (session %p, FT session %p)", psessionEntry,
1537 psessionEntry);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001538 psessionEntry->ftPEContext.pFTPreAuthReq->bPreAuthRspProcessed =
1539 true;
1540 }
1541
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301542 pe_debug("Pre-Auth response received from neighbor");
1543 pe_debug("Pre-Auth done state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001544 /* Stopping timer now, that we have our unicast from the AP */
1545 /* of our choice. */
1546 lim_deactivate_and_change_timer(pMac, eLIM_FT_PREAUTH_RSP_TIMER);
1547
1548 /* Save off the auth resp. */
1549 if ((sir_convert_auth_frame2_struct(pMac, pBody, frameLen, &rxAuthFrame) !=
1550 eSIR_SUCCESS)) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301551 pe_err("failed to convert Auth frame to struct");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 lim_handle_ft_pre_auth_rsp(pMac, eSIR_FAILURE, NULL, 0,
1553 psessionEntry);
1554 return eSIR_FAILURE;
1555 }
1556 pRxAuthFrameBody = &rxAuthFrame;
1557
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301558 pe_debug("Received Auth frame with type: %d seqnum: %d status: %d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001559 (uint32_t) pRxAuthFrameBody->authAlgoNumber,
1560 (uint32_t) pRxAuthFrameBody->authTransactionSeqNumber,
1561 (uint32_t) pRxAuthFrameBody->authStatusCode,
1562 (uint32_t) pMac->lim.gLimNumPreAuthContexts);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 switch (pRxAuthFrameBody->authTransactionSeqNumber) {
1564 case SIR_MAC_AUTH_FRAME_2:
1565 if (pRxAuthFrameBody->authStatusCode != eSIR_MAC_SUCCESS_STATUS) {
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301566 pe_err("Auth status code received is %d",
Deepak Dhamdhere26bda452016-01-09 22:54:48 -08001567 (uint32_t) pRxAuthFrameBody->authStatusCode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 if (eSIR_MAC_MAX_ASSOC_STA_REACHED_STATUS ==
1569 pRxAuthFrameBody->authStatusCode)
1570 ret_status = eSIR_LIM_MAX_STA_REACHED_ERROR;
1571 } else {
1572 ret_status = eSIR_SUCCESS;
1573 }
1574 break;
1575
1576 default:
Nishank Aggarwal2dfc5192017-03-24 20:20:15 +05301577 pe_warn("Seq. no incorrect expected 2 received %d",
Deepak Dhamdhere26bda452016-01-09 22:54:48 -08001578 (uint32_t) pRxAuthFrameBody->authTransactionSeqNumber);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 break;
1580 }
1581
1582 /* Send the Auth response to SME */
1583 lim_handle_ft_pre_auth_rsp(pMac, ret_status, pBody, frameLen, psessionEntry);
1584
1585 return ret_status;
1586}