blob: e364e73a21303ccdd352a5bbe67e0a8532252794 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Paul Zhang83289792017-02-28 18:58:52 +08002 * Copyright (c) 2013-2015, 2017 The Linux Foundation. All rights reserved.
Kiet Lam842dad02014-02-18 18:44:02 -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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam842dad02014-02-18 18:44:02 -080021
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080022/*
Kiet Lam842dad02014-02-18 18:44:02 -080023 * 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/*
Jeff Johnson295189b2012-06-20 16:38:30 -070029 * This file limUtils.cc contains the utility functions
30 * LIM uses.
31 * Author: Chandra Modumudi
32 * Date: 02/13/02
33 * History:-
34 * Date Modified by Modification Information
35 * --------------------------------------------------------------------
36 */
37
38#include "aniGlobal.h"
39#include "wniApi.h"
40
41#include "sirCommon.h"
Satyanarayana Dash6f438272015-03-03 18:01:06 +053042#include "wniCfg.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070043#include "cfgApi.h"
44
Jeff Johnson295189b2012-06-20 16:38:30 -070045
46#include "utilsApi.h"
47#include "limUtils.h"
48#include "limSecurityUtils.h"
49#include "limSession.h"
50
51
52#define LIM_SEED_LENGTH 16
Edhar, Mahesh Kumar0d82c212015-02-03 17:47:16 +053053/**
54 *preauth node timeout value in interval of 10msec
55 */
56#define LIM_OPENAUTH_TIMEOUT 500
Jeff Johnson295189b2012-06-20 16:38:30 -070057
58/**
59 * limIsAuthAlgoSupported()
60 *
61 *FUNCTION:
62 * This function is called in various places within LIM code
63 * to determine whether passed authentication algorithm is enabled
64 * or not
65 *
66 *LOGIC:
67 *
68 *ASSUMPTIONS:
69 * NA
70 *
71 *NOTE:
72 * NA
73 *
74 * @param authType Indicates MAC based authentication type
75 * (eSIR_OPEN_SYSTEM or eSIR_SHARED_KEY)
76 * If Shared Key authentication to be used,
77 * 'Privacy Option Implemented' flag is also
78 * checked.
79 *
80 * @return true if passed authType is enabled else false
81 */
Jeff Johnson295189b2012-06-20 16:38:30 -070082tANI_U8
83limIsAuthAlgoSupported(tpAniSirGlobal pMac, tAniAuthType authType, tpPESession psessionEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -070084{
85 tANI_U32 algoEnable, privacyOptImp;
86
87 if (authType == eSIR_OPEN_SYSTEM)
88 {
89
Jeff Johnson295189b2012-06-20 16:38:30 -070090 if(psessionEntry->limSystemRole == eLIM_AP_ROLE)
91 {
92 if((psessionEntry->authType == eSIR_OPEN_SYSTEM) || (psessionEntry->authType == eSIR_AUTO_SWITCH))
93 return true;
94 else
95 return false;
96 }
Jeff Johnson295189b2012-06-20 16:38:30 -070097
98 if (wlan_cfgGetInt(pMac, WNI_CFG_OPEN_SYSTEM_AUTH_ENABLE,
99 &algoEnable) != eSIR_SUCCESS)
100 {
101 /**
102 * Could not get AuthAlgo1 Enable value
103 * from CFG. Log error.
104 */
105 limLog(pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700106 FL("could not retrieve AuthAlgo1 Enable value"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700107
108 return false;
109 }
110 else
111 return ( (algoEnable > 0 ? true : false) );
112 }
113 else
114 {
115
Jeff Johnson295189b2012-06-20 16:38:30 -0700116 if(psessionEntry->limSystemRole == eLIM_AP_ROLE)
117 {
118 if((psessionEntry->authType == eSIR_SHARED_KEY) || (psessionEntry->authType == eSIR_AUTO_SWITCH))
119 algoEnable = true;
120 else
121 algoEnable = false;
122
123 }
124 else
Jeff Johnson295189b2012-06-20 16:38:30 -0700125
126 if (wlan_cfgGetInt(pMac, WNI_CFG_SHARED_KEY_AUTH_ENABLE,
127 &algoEnable) != eSIR_SUCCESS)
128 {
129 /**
130 * Could not get AuthAlgo2 Enable value
131 * from CFG. Log error.
132 */
133 limLog(pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700134 FL("could not retrieve AuthAlgo2 Enable value"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700135
136 return false;
137 }
138
Jeff Johnson295189b2012-06-20 16:38:30 -0700139 if(psessionEntry->limSystemRole == eLIM_AP_ROLE)
140 {
141 privacyOptImp = psessionEntry->privacy;
142 }
143 else
Jeff Johnson295189b2012-06-20 16:38:30 -0700144
145 if (wlan_cfgGetInt(pMac, WNI_CFG_PRIVACY_ENABLED,
146 &privacyOptImp) != eSIR_SUCCESS)
147 {
148 /**
149 * Could not get PrivacyOptionImplemented value
150 * from CFG. Log error.
151 */
152 limLog(pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700153 FL("could not retrieve PrivacyOptImplemented value"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700154
155 return false;
156 }
157 return (algoEnable && privacyOptImp);
158 }
159} /****** end limIsAuthAlgoSupported() ******/
160
161
162
163/**
164 * limInitPreAuthList
165 *
166 *FUNCTION:
167 * This function is called while starting a BSS at AP
168 * to initialize MAC authenticated STA list. This may also be called
169 * while joining/starting an IBSS if MAC authentication is allowed
170 * in IBSS mode.
171 *
172 *LOGIC:
173 *
174 *ASSUMPTIONS:
175 *
176 *NOTE:
177 *
178 * @param pMac - Pointer to Global MAC structure
179 * @return None
180 */
181
182void
183limInitPreAuthList(tpAniSirGlobal pMac)
184{
185 pMac->lim.pLimPreAuthList = NULL;
186
Jeff Johnson295189b2012-06-20 16:38:30 -0700187} /*** end limInitPreAuthList() ***/
188
189
190
191/**
192 * limDeletePreAuthList
193 *
194 *FUNCTION:
195 * This function is called cleanup Pre-auth list either on
196 * AP or on STA when moving from one persona to other.
197 *
198 *LOGIC:
199 *
200 *ASSUMPTIONS:
201 *
202 *NOTE:
203 *
204 * @param pMac - Pointer to Global MAC structure
205 * @return None
206 */
207
208void
209limDeletePreAuthList(tpAniSirGlobal pMac)
210{
211 struct tLimPreAuthNode *pCurrNode, *pTempNode;
212
213 pCurrNode = pTempNode = pMac->lim.pLimPreAuthList;
214 while (pCurrNode != NULL)
215 {
216 pTempNode = pCurrNode->next;
217
Abhishek Singh3cbf6052014-12-15 16:46:42 +0530218 limLog(pMac, LOG1, FL("=====> limDeletePreAuthList "));
Jeff Johnson295189b2012-06-20 16:38:30 -0700219 limReleasePreAuthNode(pMac, pCurrNode);
220
221 pCurrNode = pTempNode;
222 }
223 pMac->lim.pLimPreAuthList = NULL;
224} /*** end limDeletePreAuthList() ***/
225
226
227
228/**
229 * limSearchPreAuthList
230 *
231 *FUNCTION:
232 * This function is called when Authentication frame is received
233 * by AP (or at a STA in IBSS supporting MAC based authentication)
234 * to search if a STA is in the middle of MAC Authentication
235 * transaction sequence.
236 *
237 *LOGIC:
238 *
239 *ASSUMPTIONS:
240 *
241 *NOTE:
242 *
243 * @param macAddr - MAC address of the STA that sent
244 * Authentication frame.
245 *
246 * @return Pointer to pre-auth node if found, else NULL
247 */
248
249struct tLimPreAuthNode *
250limSearchPreAuthList(tpAniSirGlobal pMac, tSirMacAddr macAddr)
251{
252 struct tLimPreAuthNode *pTempNode = pMac->lim.pLimPreAuthList;
253
254 while (pTempNode != NULL)
255 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530256 if (vos_mem_compare( (tANI_U8 *) macAddr,
257 (tANI_U8 *) &pTempNode->peerMacAddr,
258 sizeof(tSirMacAddr)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700259 break;
260
261 pTempNode = pTempNode->next;
262 }
263
264 return pTempNode;
265} /*** end limSearchPreAuthList() ***/
266
Edhar, Mahesh Kumar0d82c212015-02-03 17:47:16 +0530267/**
268 * limDeleteOpenAuthPreAuthNode
269 *
270 *FUNCTION:
271 * This function is called to delete any stale preauth nodes on
272 * receiving authentication frame and existing preauth nodes
273 * reached the maximum allowed limit.
274 *
275 *LOGIC:
276 *
277 *ASSUMPTIONS:
278 *
279 *NOTE:
280 *
281 * @param pMac - Pointer to Global MAC structure
282 *
283 * @return true if any preauthnode deleted else false
284 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700285
Edhar, Mahesh Kumar0d82c212015-02-03 17:47:16 +0530286tANI_U8
287limDeleteOpenAuthPreAuthNode(tpAniSirGlobal pMac)
288{
289 struct tLimPreAuthNode *pPrevNode, *pTempNode, *pFoundNode;
290 tANI_U8 authNodeFreed = false;
291
292 pTempNode = pPrevNode = pMac->lim.pLimPreAuthList;
293
294 if (pTempNode == NULL)
295 return authNodeFreed;
296
297 while (pTempNode != NULL)
298 {
299 if (pTempNode->mlmState == eLIM_MLM_AUTHENTICATED_STATE &&
300 pTempNode->authType == eSIR_OPEN_SYSTEM &&
301 (vos_timer_get_system_ticks() >
302 (LIM_OPENAUTH_TIMEOUT + pTempNode->timestamp) ||
303 vos_timer_get_system_ticks() < pTempNode->timestamp))
304 {
305 // Found node to be deleted
306 authNodeFreed = true;
307 pFoundNode = pTempNode;
308 if (pMac->lim.pLimPreAuthList == pTempNode)
309 {
310 pPrevNode = pMac->lim.pLimPreAuthList = pTempNode =
311 pFoundNode->next;
312 }
313 else
314 {
315 pPrevNode->next = pTempNode->next;
316 pTempNode = pPrevNode->next;
317 }
318
319 limReleasePreAuthNode(pMac, pFoundNode);
320 }
321 else
322 {
323 pPrevNode = pTempNode;
324 pTempNode = pPrevNode->next;
325 }
326 }
327
328 return authNodeFreed;
329}
Jeff Johnson295189b2012-06-20 16:38:30 -0700330
331/**
332 * limAddPreAuthNode
333 *
334 *FUNCTION:
335 * This function is called at AP while sending Authentication
336 * frame2.
337 * This may also be called on a STA in IBSS if MAC authentication is
338 * allowed in IBSS mode.
339 *
340 *LOGIC:
341 * Node is always added to the front of the list
342 *
343 *ASSUMPTIONS:
344 *
345 *NOTE:
346 *
347 * @param pMac - Pointer to Global MAC structure
348 * @param pAuthNode - Pointer to pre-auth node to be added to the list.
349 *
350 * @return None
351 */
352
353void
354limAddPreAuthNode(tpAniSirGlobal pMac, struct tLimPreAuthNode *pAuthNode)
355{
356 pMac->lim.gLimNumPreAuthContexts++;
357
358 pAuthNode->next = pMac->lim.pLimPreAuthList;
359
360 pMac->lim.pLimPreAuthList = pAuthNode;
361} /*** end limAddPreAuthNode() ***/
362
363
364/**
365 * limReleasePreAuthNode
366 *
367 *FUNCTION:
368 * This function is called to realease the accquired
369 * pre auth node from list.
370 *
371 *LOGIC:
372 *
373 *ASSUMPTIONS:
374 *
375 *NOTE:
376 *
377 * @param pMac - Pointer to Global MAC structure
378 * @param pAuthNode - Pointer to Pre Auth node to be released
379 * @return None
380 */
381
382void
383limReleasePreAuthNode(tpAniSirGlobal pMac, tpLimPreAuthNode pAuthNode)
384{
385 pAuthNode->fFree = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -0700386 MTRACE(macTrace(pMac, TRACE_CODE_TIMER_DEACTIVATE, NO_SESSION, eLIM_PRE_AUTH_CLEANUP_TIMER));
Jeff Johnson295189b2012-06-20 16:38:30 -0700387 tx_timer_deactivate(&pAuthNode->timer);
388 pMac->lim.gLimNumPreAuthContexts--;
389} /*** end limReleasePreAuthNode() ***/
390
391
392/**
393 * limDeletePreAuthNode
394 *
395 *FUNCTION:
396 * This function is called at AP when a pre-authenticated STA is
397 * Associated/Reassociated or when AuthFrame4 is received after
398 * Auth Response timeout.
399 * This may also be called on a STA in IBSS if MAC authentication and
400 * Association/Reassociation is allowed in IBSS mode.
401 *
402 *LOGIC:
403 *
404 *ASSUMPTIONS:
405 *
406 *NOTE:
407 *
408 * @param pMac - Pointer to Global MAC structure
409 * @param peerMacAddr - MAC address of the STA that need to be deleted
410 * from pre-auth node list.
411 *
412 * @return None
413 */
414
415void
416limDeletePreAuthNode(tpAniSirGlobal pMac, tSirMacAddr macAddr)
417{
418 struct tLimPreAuthNode *pPrevNode, *pTempNode;
419
420 pTempNode = pPrevNode = pMac->lim.pLimPreAuthList;
421
422 if (pTempNode == NULL)
423 return;
424
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530425 if (vos_mem_compare( (tANI_U8 *) macAddr,
426 (tANI_U8 *) &pTempNode->peerMacAddr,
427 sizeof(tSirMacAddr)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700428 {
429 // First node to be deleted
430
431 pMac->lim.pLimPreAuthList = pTempNode->next;
432
Jeff Johnson295189b2012-06-20 16:38:30 -0700433
Abhishek Singh3cbf6052014-12-15 16:46:42 +0530434 limLog(pMac, LOG1, FL(" first node to delete"));
435 limLog(pMac, LOG1,
Jeff Johnson0fe596e2017-09-19 08:36:48 -0700436 FL(" Release data entry:%pK idx %d peer: " MAC_ADDRESS_STR),
Abhishek Singh3cbf6052014-12-15 16:46:42 +0530437 pTempNode, pTempNode->authNodeIdx,
438 MAC_ADDR_ARRAY(macAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -0700439 limReleasePreAuthNode(pMac, pTempNode);
440
441 return;
442 }
443
444 pTempNode = pTempNode->next;
445
446 while (pTempNode != NULL)
447 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530448 if (vos_mem_compare( (tANI_U8 *) macAddr,
449 (tANI_U8 *) &pTempNode->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700450 sizeof(tSirMacAddr)) )
451 {
452 // Found node to be deleted
453
454 pPrevNode->next = pTempNode->next;
455
Abhishek Singh3cbf6052014-12-15 16:46:42 +0530456 limLog(pMac, LOG1, FL(" subsequent node to delete"));
457 limLog(pMac, LOG1,
Jeff Johnson0fe596e2017-09-19 08:36:48 -0700458 FL("Release data entry: %pK id %d peer: "MAC_ADDRESS_STR),
Abhishek Singh3cbf6052014-12-15 16:46:42 +0530459 pTempNode, pTempNode->authNodeIdx, MAC_ADDR_ARRAY(macAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -0700460 limReleasePreAuthNode(pMac, pTempNode);
461
462 return;
463 }
464
465 pPrevNode = pTempNode;
466 pTempNode = pTempNode->next;
467 }
468
469 // Should not be here
470 // Log error
471 limLog(pMac, LOGP, FL("peer not found in pre-auth list, addr= "));
472 limPrintMacAddr(pMac, macAddr, LOGP);
473
474} /*** end limDeletePreAuthNode() ***/
475
Jeff Johnson295189b2012-06-20 16:38:30 -0700476/**
477 * limRestoreFromPreAuthState
478 *
479 *FUNCTION:
480 * This function is called on STA whenever an Authentication
481 * sequence is complete and state prior to auth need to be
482 * restored.
483 *
484 *LOGIC:
485 * MLM_AUTH_CNF is prepared and sent to SME state machine.
486 * In case of restoring from pre-auth:
487 * - Channel Id is programmed at LO/RF synthesizer
488 * - BSSID is programmed at RHP
489 *
490 *ASSUMPTIONS:
491 *
492 *NOTE:
493 *
494 * @param pMac - Pointer to Global MAC structure
495 * @param resultCode - result of authentication attempt
496 * @return None
497 */
498
499void
500limRestoreFromAuthState(tpAniSirGlobal pMac, tSirResultCodes resultCode, tANI_U16 protStatusCode,tpPESession sessionEntry)
501{
502 tSirMacAddr currentBssId;
503 tLimMlmAuthCnf mlmAuthCnf;
504
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530505 vos_mem_copy( (tANI_U8 *) &mlmAuthCnf.peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700506 (tANI_U8 *) &pMac->lim.gpLimMlmAuthReq->peerMacAddr,
507 sizeof(tSirMacAddr));
508 mlmAuthCnf.authType = pMac->lim.gpLimMlmAuthReq->authType;
509 mlmAuthCnf.resultCode = resultCode;
510 mlmAuthCnf.protStatusCode = protStatusCode;
511
512 /* Update PE session ID*/
513 mlmAuthCnf.sessionId = sessionEntry->peSessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -0700514
Jeff Johnsone7245742012-09-05 17:12:55 -0700515 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Sushant Kaushik9e923872015-04-02 17:09:31 +0530516 /* Set the authAckStatus status flag as sucess as
517 * host have received the auth rsp and no longer auth
518 * retry is needed also cancel the auth rety timer
519 */
520 pMac->authAckStatus = LIM_AUTH_ACK_RCD_SUCCESS;
Abhinav Kumard9664da2019-08-05 17:11:25 +0530521 /* Auth retry and AUth failure timers are not started for SAE
522 * Change' timer for future activations
523 */
524 if (tx_timer_running(&pMac->lim.limTimers.gLimPeriodicAuthRetryTimer))
525 limDeactivateAndChangeTimer(pMac, eLIM_AUTH_RETRY_TIMER);
526 /* Change' timer for future activations */
527 if (tx_timer_running(&pMac->lim.limTimers.gLimAuthFailureTimer))
528 limDeactivateAndChangeTimer(pMac, eLIM_AUTH_FAIL_TIMER);
Jeff Johnson295189b2012-06-20 16:38:30 -0700529
530 #if 0
531 if (wlan_cfgGetStr(pMac, WNI_CFG_BSSID, currentBssId, &cfg) != eSIR_SUCCESS)
532 {
533 /// Could not get BSSID from CFG. Log error.
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700534 limLog(pMac, LOGP, FL("could not retrieve BSSID"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700535 }
536 #endif //TO SUPPORT BT-AMP
537 sirCopyMacAddr(currentBssId,sessionEntry->bssId);
538
539 if (sessionEntry->limSmeState == eLIM_SME_WT_PRE_AUTH_STATE)
540 {
541 pMac->lim.gLimPreAuthChannelNumber = 0;
542 }
543
Paul Zhang83289792017-02-28 18:58:52 +0800544 if ((protStatusCode == eSIR_MAC_MAX_ASSOC_STA_REACHED_STATUS)
545 && (sessionEntry->sta_auth_retries_for_code17 <
546 pMac->sta_auth_retries_for_code17)) {
547 limLog(pMac, LOG1, FL("Retry Auth "));
548 limDoSendAuthMgmtFrame(pMac, sessionEntry);
549 sessionEntry->sta_auth_retries_for_code17++;
550 } else {
551 /// Free up buffer allocated
552 /// for pMac->lim.gLimMlmAuthReq
553 vos_mem_free(pMac->lim.gpLimMlmAuthReq);
554 pMac->lim.gpLimMlmAuthReq = NULL;
555
556 sessionEntry->limMlmState = sessionEntry->limPrevMlmState;
557
558 limPostSmeMessage(pMac,
Jeff Johnson295189b2012-06-20 16:38:30 -0700559 LIM_MLM_AUTH_CNF,
560 (tANI_U32 *) &mlmAuthCnf);
Paul Zhang83289792017-02-28 18:58:52 +0800561 sessionEntry->sta_auth_retries_for_code17 = 0;
562 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700563} /*** end limRestoreFromAuthState() ***/
564
565
566
567/**
568 * limLookUpKeyMappings()
569 *
570 *FUNCTION:
571 * This function is called in limProcessAuthFrame() function
572 * to determine if there exists a Key Mapping key for a given
573 * MAC address.
574 *
575 *LOGIC:
576 *
577 *ASSUMPTIONS:
578 * NA
579 *
580 *NOTE:
581 * NA
582 *
583 * @param macAddr MAC address of the peer STA for which existence
584 * of Key Mapping key is to be determined
585 *
586 * @return pKeyMapEntry - Pointer to the keyMapEntry returned by CFG
587 */
588
589tCfgWepKeyEntry *
590limLookUpKeyMappings(tSirMacAddr macAddr)
591{
592 return NULL;
593} /****** end limLookUpKeyMappings() ******/
594
595
596
597/**
598 * limEncryptAuthFrame()
599 *
600 *FUNCTION:
601 * This function is called in limProcessAuthFrame() function
602 * to encrypt Authentication frame3 body.
603 *
604 *LOGIC:
605 *
606 *ASSUMPTIONS:
607 * NA
608 *
609 *NOTE:
610 * NA
611 *
612 * @param pMac Pointer to Global MAC structure
613 * @param keyId key id to used
614 * @param pKey Pointer to the key to be used for encryption
615 * @param pPlainText Pointer to the body to be encrypted
616 * @param pEncrBody Pointer to the encrypted auth frame body
617 * @param keyLength 8 (WEP40) or 16 (WEP104)
618 * @return None
619 */
620
621void
622limEncryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 keyId, tANI_U8 *pKey, tANI_U8 *pPlainText,
623 tANI_U8 *pEncrBody, tANI_U32 keyLength)
624{
625 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530626 tANI_U16 frame_len;
Jeff Johnson295189b2012-06-20 16:38:30 -0700627
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530628 frame_len = ((tpSirMacAuthFrameBody)pPlainText)->length +
629 SIR_MAC_AUTH_FRAME_INFO_LEN + SIR_MAC_CHALLENGE_ID_LEN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700630 keyLength += 3;
631
632 // Bytes 0-2 of seed is IV
633 // Read TSF timestamp into seed to get random IV - 1st 3 bytes
634 halGetTxTSFtimer(pMac, (tSirMacTimeStamp *) &seed);
635
636 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530637 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700638
639 // Compute CRC-32 and place them in last 4 bytes of plain text
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530640 limComputeCrc32(icv, pPlainText, frame_len);
Jeff Johnson295189b2012-06-20 16:38:30 -0700641
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530642 vos_mem_copy( pPlainText + frame_len,
Jeff Johnson295189b2012-06-20 16:38:30 -0700643 icv, SIR_MAC_WEP_ICV_LENGTH);
644
645 // Run RC4 on plain text with the seed
646 limRC4(pEncrBody + SIR_MAC_WEP_IV_LENGTH,
647 (tANI_U8 *) pPlainText, seed, keyLength,
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530648 frame_len + SIR_MAC_WEP_ICV_LENGTH);
Jeff Johnson295189b2012-06-20 16:38:30 -0700649
650 // Prepare IV
651 pEncrBody[0] = seed[0];
652 pEncrBody[1] = seed[1];
653 pEncrBody[2] = seed[2];
654 pEncrBody[3] = keyId << 6;
655} /****** end limEncryptAuthFrame() ******/
656
657
658
659/**
660 * limComputeCrc32()
661 *
662 *FUNCTION:
663 * This function is called to compute CRC-32 on a given source.
664 * Used while encrypting/decrypting Authentication frame 3.
665 *
666 *LOGIC:
667 *
668 *ASSUMPTIONS:
669 * NA
670 *
671 *NOTE:
672 * NA
673 *
674 * @param pDest Destination location for computed CRC
675 * @param pSrc Source location to be CRC computed
676 * @param len Length over which CRC to be computed
677 * @return None
678 */
679
680void
Sridhar Selvaraj05a07142017-07-18 11:51:34 +0530681limComputeCrc32(tANI_U8 *pDest, tANI_U8 * pSrc, tANI_U16 len)
Jeff Johnson295189b2012-06-20 16:38:30 -0700682{
683 tANI_U32 crc;
684 int i;
685
686 crc = 0;
687 crc = ~crc;
688
689 while(len-- > 0)
690 crc = limCrcUpdate(crc, *pSrc++);
691
692 crc = ~crc;
693
694 for (i=0; i < SIR_MAC_WEP_IV_LENGTH; i++)
695 {
696 pDest[i] = (tANI_U8)crc;
697 crc >>= 8;
698 }
699} /****** end limComputeCrc32() ******/
700
701
702
703/**
704 * limRC4()
705 *
706 *FUNCTION:
707 * This function is called to run RC4 algorithm. Called while
708 * encrypting/decrypting Authentication frame 3.
709 *
710 *LOGIC:
711 *
712 *ASSUMPTIONS:
713 * NA
714 *
715 *NOTE:
716 * NA
717 *
718 * @param pDest Destination location for encrypted text
719 * @param pSrc Source location to be encrypted
720 * @param seed Contains seed (IV + key) for PRNG
721 * @param keyLength 8 (WEP40) or 16 (WEP104)
722 * @param frameLen Length of the frame
723 *
724 * @return None
725 */
726
727void
728limRC4(tANI_U8 *pDest, tANI_U8 *pSrc, tANI_U8 *seed, tANI_U32 keyLength, tANI_U16 frameLen)
729{
730 typedef struct
731 {
732 tANI_U8 i, j;
733 tANI_U8 sbox[256];
734 } tRC4Context;
735
736 tRC4Context ctx;
737
738 {
739 tANI_U16 i, j, k;
740
741 //
742 // Initialize sbox using seed
743 //
744
745 ctx.i = ctx.j = 0;
746 for (i=0; i<256; i++)
747 ctx.sbox[i] = (tANI_U8)i;
748
749 j = 0;
750 k = 0;
751 for (i=0; i<256; i++)
752 {
753 tANI_U8 temp;
Kiran Kumar Lokerea4db3dc2013-03-25 18:05:24 -0700754 if ( k < LIM_SEED_LENGTH )
755 j = (tANI_U8)(j + ctx.sbox[i] + seed[k]);
Jeff Johnson295189b2012-06-20 16:38:30 -0700756 temp = ctx.sbox[i];
757 ctx.sbox[i] = ctx.sbox[j];
758 ctx.sbox[j] = temp;
759
760 if (++k >= keyLength)
761 k = 0;
762 }
763 }
764
765 {
766 tANI_U8 i = ctx.i;
767 tANI_U8 j = ctx.j;
Sridhar Selvarajdd6518f2017-07-27 20:24:13 +0530768 tANI_U16 len = frameLen;
Jeff Johnson295189b2012-06-20 16:38:30 -0700769
770 while (len-- > 0)
771 {
772 tANI_U8 temp1, temp2;
773
774 i = (tANI_U8)(i+1);
775 temp1 = ctx.sbox[i];
776 j = (tANI_U8)(j + temp1);
777
778 ctx.sbox[i] = temp2 = ctx.sbox[j];
779 ctx.sbox[j] = temp1;
780
781 temp1 = (tANI_U8)(temp1 + temp2);
782 temp1 = ctx.sbox[temp1];
783 temp2 = (tANI_U8)(pSrc ? *pSrc++ : 0);
784
785 *pDest++ = (tANI_U8)(temp1 ^ temp2);
786 }
787
788 ctx.i = i;
789 ctx.j = j;
790 }
791} /****** end limRC4() ******/
792
793
794
795/**
796 * limDecryptAuthFrame()
797 *
798 *FUNCTION:
799 * This function is called in limProcessAuthFrame() function
800 * to decrypt received Authentication frame3 body.
801 *
802 *LOGIC:
803 *
804 *ASSUMPTIONS:
805 * NA
806 *
807 *NOTE:
808 * NA
809 *
810 * @param pMac Pointer to Global MAC structure
811 * @param pKey Pointer to the key to be used for decryption
812 * @param pEncrBody Pointer to the body to be decrypted
813 * @param pPlainBody Pointer to the decrypted body
814 * @param keyLength 8 (WEP40) or 16 (WEP104)
815 *
816 * @return Decrypt result - eSIR_SUCCESS for success and
817 * LIM_DECRYPT_ICV_FAIL for ICV mismatch.
818 * If decryption is a success, pBody will
819 * have decrypted auth frame body.
820 */
821
822tANI_U8
823limDecryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 *pKey, tANI_U8 *pEncrBody,
824 tANI_U8 *pPlainBody, tANI_U32 keyLength, tANI_U16 frameLen)
825{
826 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
827 int i;
828 keyLength += 3;
829
830
831 // Bytes 0-2 of seed is received IV
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530832 vos_mem_copy((tANI_U8 *) seed, pEncrBody, SIR_MAC_WEP_IV_LENGTH - 1);
Jeff Johnson295189b2012-06-20 16:38:30 -0700833
834 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530835 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700836
837 // Run RC4 on encrypted text with the seed
838 limRC4(pPlainBody,
839 pEncrBody + SIR_MAC_WEP_IV_LENGTH,
840 seed,
841 keyLength,
842 frameLen);
843
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700844 PELOG4(limLog(pMac, LOG4, FL("plainbody is "));
Jeff Johnson295189b2012-06-20 16:38:30 -0700845 sirDumpBuf(pMac, SIR_LIM_MODULE_ID, LOG4, pPlainBody, frameLen);)
846
847 // Compute CRC-32 and place them in last 4 bytes of encrypted body
848 limComputeCrc32(icv,
849 (tANI_U8 *) pPlainBody,
Sridhar Selvarajdd6518f2017-07-27 20:24:13 +0530850 (frameLen - SIR_MAC_WEP_ICV_LENGTH));
Jeff Johnson295189b2012-06-20 16:38:30 -0700851
852 // Compare RX_ICV with computed ICV
853 for (i = 0; i < SIR_MAC_WEP_ICV_LENGTH; i++)
854 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700855 PELOG4(limLog(pMac, LOG4, FL(" computed ICV%d[%x], rxed ICV%d[%x]"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700856 i, icv[i], i, pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i]);)
857 if (icv[i] != pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i])
858 return LIM_DECRYPT_ICV_FAIL;
859 }
860
861 return eSIR_SUCCESS;
862} /****** end limDecryptAuthFrame() ******/
863
864/**
865 * limPostSmeSetKeysCnf
866 *
867 * A utility API to send MLM_SETKEYS_CNF to SME
868 */
869void limPostSmeSetKeysCnf( tpAniSirGlobal pMac,
870 tLimMlmSetKeysReq *pMlmSetKeysReq,
871 tLimMlmSetKeysCnf *mlmSetKeysCnf)
872{
873 // Prepare and Send LIM_MLM_SETKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530874 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700875 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
876 sizeof(tSirMacAddr));
877
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530878 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700879 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
880 sizeof(tSirMacAddr));
881
Jeff Johnson295189b2012-06-20 16:38:30 -0700882
883 /// Free up buffer allocated for mlmSetKeysReq
Vinay Krishna Eranna6f22c1f2014-10-13 16:03:06 +0530884 vos_mem_zero(pMlmSetKeysReq, sizeof(tLimMlmSetKeysReq));
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530885 vos_mem_free( pMlmSetKeysReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700886 pMac->lim.gpLimMlmSetKeysReq = NULL;
887
888 limPostSmeMessage( pMac,
889 LIM_MLM_SETKEYS_CNF,
890 (tANI_U32 *) mlmSetKeysCnf );
891}
892
893/**
894 * limPostSmeRemoveKeysCnf
895 *
896 * A utility API to send MLM_REMOVEKEY_CNF to SME
897 */
898void limPostSmeRemoveKeyCnf( tpAniSirGlobal pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -0700899 tpPESession psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -0700900 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
901 tLimMlmRemoveKeyCnf *mlmRemoveKeyCnf)
902{
903 // Prepare and Send LIM_MLM_REMOVEKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530904 vos_mem_copy( (tANI_U8 *) &mlmRemoveKeyCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700905 (tANI_U8 *) pMlmRemoveKeyReq->peerMacAddr,
906 sizeof(tSirMacAddr));
907
908 /// Free up buffer allocated for mlmRemoveKeysReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530909 vos_mem_free( pMlmRemoveKeyReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700910 pMac->lim.gpLimMlmRemoveKeyReq = NULL;
911
Jeff Johnsone7245742012-09-05 17:12:55 -0700912 psessionEntry->limMlmState = psessionEntry->limPrevMlmState; //Restore the state.
913 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, psessionEntry->peSessionId, psessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -0700914
915 limPostSmeMessage( pMac,
916 LIM_MLM_REMOVEKEY_CNF,
917 (tANI_U32 *) mlmRemoveKeyCnf );
918}
919
920/**
921 * limSendSetBssKeyReq()
922 *
923 *FUNCTION:
924 * This function is called from limProcessMlmSetKeysReq(),
925 * when PE is trying to setup the Group Keys related
926 * to a specified encryption type
927 *
928 *LOGIC:
929 *
930 *ASSUMPTIONS:
931 * NA
932 *
933 *NOTE:
934 * NA
935 *
936 * @param pMac Pointer to Global MAC structure
937 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
938 * @return none
939 */
940void limSendSetBssKeyReq( tpAniSirGlobal pMac,
941 tLimMlmSetKeysReq *pMlmSetKeysReq,
942 tpPESession psessionEntry)
943{
944tSirMsgQ msgQ;
945tpSetBssKeyParams pSetBssKeyParams = NULL;
946tLimMlmSetKeysCnf mlmSetKeysCnf;
947tSirRetStatus retCode;
948tANI_U32 val = 0;
949
950 if(pMlmSetKeysReq->numKeys > SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
951 {
952 limLog( pMac, LOG1,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700953 FL( "numKeys = %d is more than SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS" ), pMlmSetKeysReq->numKeys);
Jeff Johnson295189b2012-06-20 16:38:30 -0700954
955 // Respond to SME with error code
956 mlmSetKeysCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
957 goto end;
958 }
959
960 // Package WDA_SET_BSSKEY_REQ message parameters
961
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530962 pSetBssKeyParams = vos_mem_malloc(sizeof( tSetBssKeyParams ));
963 if ( NULL == pSetBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -0700964 {
965 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530966 FL( "Unable to allocate memory during SET_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700967
968 // Respond to SME with error code
969 mlmSetKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
970 goto end;
971 }
972 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530973 vos_mem_set( (void *) pSetBssKeyParams,
974 sizeof( tSetBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700975
976 // Update the WDA_SET_BSSKEY_REQ parameters
977 pSetBssKeyParams->bssIdx = psessionEntry->bssIdx;
978 pSetBssKeyParams->encType = pMlmSetKeysReq->edType;
Jeff Johnsone7245742012-09-05 17:12:55 -0700979
Jeff Johnson295189b2012-06-20 16:38:30 -0700980
981 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
982 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700983 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700984 }
985
986 pSetBssKeyParams->singleTidRc = (tANI_U8)val;
987
988 /* Update PE session Id*/
989 pSetBssKeyParams->sessionId = psessionEntry ->peSessionId;
990
Jeff Johnsone7245742012-09-05 17:12:55 -0700991 if(pMlmSetKeysReq->key[0].keyId &&
992 ((pMlmSetKeysReq->edType == eSIR_ED_WEP40) ||
993 (pMlmSetKeysReq->edType == eSIR_ED_WEP104))
994 )
995 {
996 /* IF the key id is non-zero and encryption type is WEP, Send all the 4
997 * keys to HAL with filling the key at right index in pSetBssKeyParams->key. */
998 pSetBssKeyParams->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530999 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key[pMlmSetKeysReq->key[0].keyId],
1000 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof(pMlmSetKeysReq->key[0]));
Jeff Johnsone7245742012-09-05 17:12:55 -07001001
1002 }
1003 else
1004 {
1005 pSetBssKeyParams->numKeys = pMlmSetKeysReq->numKeys;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301006 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key,
1007 (tANI_U8 *) &pMlmSetKeysReq->key,
1008 sizeof( tSirKeys ) * pMlmSetKeysReq->numKeys );
Jeff Johnsone7245742012-09-05 17:12:55 -07001009 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001010
1011 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1012 msgQ.type = WDA_SET_BSSKEY_REQ;
1013 //
1014 // FIXME_GEN4
1015 // A global counter (dialog token) is required to keep track of
1016 // all PE <-> HAL communication(s)
1017 //
1018 msgQ.reserved = 0;
1019 msgQ.bodyptr = pSetBssKeyParams;
1020 msgQ.bodyval = 0;
1021
1022 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001023 FL( "Sending WDA_SET_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001024 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001025 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1026 {
1027 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001028 FL("Posting SET_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001029 retCode );
1030
1031 // Respond to SME with LIM_MLM_SETKEYS_CNF
1032 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1033 }
1034 else
1035 return; // Continue after WDA_SET_BSSKEY_RSP...
1036
1037end:
1038 limPostSmeSetKeysCnf( pMac,
1039 pMlmSetKeysReq,
1040 &mlmSetKeysCnf );
1041
1042}
1043
1044/**
1045 * @function : limSendSetStaKeyReq()
1046 *
1047 * @brief : This function is called from limProcessMlmSetKeysReq(),
1048 * when PE is trying to setup the Unicast Keys related
1049 * to a specified STA with specified encryption type
1050 *
1051 *LOGIC:
1052 *
1053 *ASSUMPTIONS:
1054 * NA
1055 *
1056 *NOTE:
1057 * NA
1058 *
1059 * @param pMac Pointer to Global MAC structure
1060 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
1061 * @param staIdx STA index for which the keys are being set
1062 * @param defWEPIdx The default WEP key index [0..3]
1063 * @return none
1064 */
1065void limSendSetStaKeyReq( tpAniSirGlobal pMac,
1066 tLimMlmSetKeysReq *pMlmSetKeysReq,
1067 tANI_U16 staIdx,
1068 tANI_U8 defWEPIdx,
1069 tpPESession sessionEntry)
1070{
1071tSirMsgQ msgQ;
1072tpSetStaKeyParams pSetStaKeyParams = NULL;
1073tLimMlmSetKeysCnf mlmSetKeysCnf;
1074tSirRetStatus retCode;
1075tANI_U32 val = 0;
1076
1077 // Package WDA_SET_STAKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301078 pSetStaKeyParams = vos_mem_malloc(sizeof( tSetStaKeyParams ));
1079 if ( NULL == pSetStaKeyParams )
1080 {
1081 limLog( pMac, LOGP, FL( "Unable to allocate memory during SET_BSSKEY" ));
1082 return;
1083 }
1084 else
1085 vos_mem_set( (void *) pSetStaKeyParams, sizeof( tSetStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001086
1087 // Update the WDA_SET_STAKEY_REQ parameters
1088 pSetStaKeyParams->staIdx = staIdx;
1089 pSetStaKeyParams->encType = pMlmSetKeysReq->edType;
1090
1091
1092 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
1093 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001094 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001095 }
1096
1097 pSetStaKeyParams->singleTidRc = (tANI_U8)val;
1098
1099 /* Update PE session ID*/
1100 pSetStaKeyParams->sessionId = sessionEntry->peSessionId;
1101
1102 /**
1103 * For WEP - defWEPIdx indicates the default WEP
1104 * Key to be used for TX
1105 * For all others, there's just one key that can
1106 * be used and hence it is assumed that
1107 * defWEPIdx = 0 (from the caller)
1108 */
1109
1110 pSetStaKeyParams->defWEPIdx = defWEPIdx;
1111
1112 /** Store the Previous MlmState*/
1113 sessionEntry->limPrevMlmState = sessionEntry->limMlmState;
1114 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1115
1116 if(sessionEntry->limSystemRole == eLIM_STA_IN_IBSS_ROLE && !pMlmSetKeysReq->key[0].unicast) {
1117 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_BCASTKEY_STATE;
1118 msgQ.type = WDA_SET_STA_BCASTKEY_REQ;
1119 }else {
1120 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
1121 msgQ.type = WDA_SET_STAKEY_REQ;
1122 }
Jeff Johnsone7245742012-09-05 17:12:55 -07001123 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001124
1125 /**
1126 * In the Case of WEP_DYNAMIC, ED_TKIP and ED_CCMP
1127 * the Key[0] contains the KEY, so just copy that alone,
1128 * for the case of WEP_STATIC the hal gets the key from cfg
1129 */
1130 switch( pMlmSetKeysReq->edType ) {
1131 case eSIR_ED_WEP40:
1132 case eSIR_ED_WEP104:
1133 // FIXME! Is this OK?
1134 if( 0 == pMlmSetKeysReq->numKeys ) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001135 tANI_U32 i;
1136
1137 for(i=0; i < SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS ;i++)
1138 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301139 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key[i],
1140 (tANI_U8 *) &pMlmSetKeysReq->key[i], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001141 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001142 pSetStaKeyParams->wepType = eSIR_WEP_STATIC;
1143 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
Jeff Johnsone7245742012-09-05 17:12:55 -07001144 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001145 }else {
Jeff Johnsone7245742012-09-05 17:12:55 -07001146 /*This case the keys are coming from upper layer so need to fill the
1147 * key at the default wep key index and send to the HAL */
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301148 if (defWEPIdx >= SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
1149 {
1150 limLog( pMac, LOGE, FL("WEPIdx length %d more than "
1151 "the Max limit, reset to Max"),defWEPIdx);
Mukul Sharmad2b81862014-07-01 21:01:04 +05301152 vos_mem_free (pSetStaKeyParams);
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301153 return;
1154 }
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301155 vos_mem_copy((tANI_U8 *) &pSetStaKeyParams->key[defWEPIdx],
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301156 (tANI_U8 *) &pMlmSetKeysReq->key[0],
1157 sizeof( pMlmSetKeysReq->key[0] ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001158 pMlmSetKeysReq->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301159
Jeff Johnson295189b2012-06-20 16:38:30 -07001160 }
1161 break;
1162 case eSIR_ED_TKIP:
1163 case eSIR_ED_CCMP:
1164#ifdef FEATURE_WLAN_WAPI
1165 case eSIR_ED_WPI:
1166#endif
1167 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301168 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key,
1169 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001170 }
1171 break;
1172 default:
1173 break;
1174 }
1175
1176
1177 //
1178 // FIXME_GEN4
1179 // A global counter (dialog token) is required to keep track of
1180 // all PE <-> HAL communication(s)
1181 //
1182 msgQ.reserved = 0;
1183 msgQ.bodyptr = pSetStaKeyParams;
1184 msgQ.bodyval = 0;
1185
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001186 limLog( pMac, LOG1, FL( "Sending WDA_SET_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001187 MTRACE(macTraceMsgTx(pMac, sessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001188 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ ))) {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001189 limLog( pMac, LOGE, FL("Posting SET_STAKEY to HAL failed, reason=%X"), retCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07001190 // Respond to SME with LIM_MLM_SETKEYS_CNF
1191 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1192 }else
1193 return; // Continue after WDA_SET_STAKEY_RSP...
1194
1195 limPostSmeSetKeysCnf( pMac, pMlmSetKeysReq, &mlmSetKeysCnf );
1196}
1197
1198/**
1199 * limSendRemoveBssKeyReq()
1200 *
1201 *FUNCTION:
1202 * This function is called from limProcessMlmRemoveReq(),
1203 * when PE is trying to Remove a Group Key related
1204 * to a specified encryption type
1205 *
1206 *LOGIC:
1207 *
1208 *ASSUMPTIONS:
1209 * NA
1210 *
1211 *NOTE:
1212 * NA
1213 *
1214 * @param pMac Pointer to Global MAC structure
1215 * @param pMlmRemoveKeyReq Pointer to MLM_REMOVEKEY_REQ buffer
1216 * @return none
1217 */
1218void limSendRemoveBssKeyReq( tpAniSirGlobal pMac,
1219 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
1220 tpPESession psessionEntry)
1221{
1222tSirMsgQ msgQ;
1223tpRemoveBssKeyParams pRemoveBssKeyParams = NULL;
1224tLimMlmRemoveKeyCnf mlmRemoveKeysCnf;
1225tSirRetStatus retCode;
1226
1227 // Package WDA_REMOVE_BSSKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301228 pRemoveBssKeyParams = vos_mem_malloc(sizeof( tRemoveBssKeyParams ));
1229 if ( NULL == pRemoveBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001230 {
1231 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301232 FL( "Unable to allocate memory during REMOVE_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001233
1234 // Respond to SME with error code
1235 mlmRemoveKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1236 goto end;
1237 }
1238 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301239 vos_mem_set( (void *) pRemoveBssKeyParams,
1240 sizeof( tRemoveBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001241
1242 // Update the WDA_REMOVE_BSSKEY_REQ parameters
1243 pRemoveBssKeyParams->bssIdx = psessionEntry->bssIdx;
1244 pRemoveBssKeyParams->encType = pMlmRemoveKeyReq->edType;
1245 pRemoveBssKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1246 pRemoveBssKeyParams->wepType = pMlmRemoveKeyReq->wepType;
1247
1248 /* Update PE session Id*/
1249
1250 pRemoveBssKeyParams->sessionId = psessionEntry->peSessionId;
1251
1252 msgQ.type = WDA_REMOVE_BSSKEY_REQ;
1253 //
1254 // FIXME_GEN4
1255 // A global counter (dialog token) is required to keep track of
1256 // all PE <-> HAL communication(s)
1257 //
1258 msgQ.reserved = 0;
1259 msgQ.bodyptr = pRemoveBssKeyParams;
1260 msgQ.bodyval = 0;
1261
1262 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001263 FL( "Sending WDA_REMOVE_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001264 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001265
1266 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1267 {
1268 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001269 FL("Posting REMOVE_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001270 retCode );
1271
1272 // Respond to SME with LIM_MLM_REMOVEKEYS_CNF
1273 mlmRemoveKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1274 }
1275 else
1276 return;
1277
1278end:
1279 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001280 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001281 pMlmRemoveKeyReq,
1282 &mlmRemoveKeysCnf );
1283
1284}
1285
1286/**
1287 * limSendRemoveStaKeyReq()
1288 *
1289 *FUNCTION:
1290 * This function is called from limProcessMlmRemoveKeysReq(),
1291 * when PE is trying to setup the Unicast Keys related
1292 * to a specified STA with specified encryption type
1293 *
1294 *LOGIC:
1295 *
1296 *ASSUMPTIONS:
1297 * NA
1298 *
1299 *NOTE:
1300 * NA
1301 *
1302 * @param pMac Pointer to Global MAC structure
1303 * @param pMlmRemoveKeysReq Pointer to MLM_REMOVEKEYS_REQ buffer
1304 * @param staIdx STA index for which the keys are being set
1305 * @return none
1306 */
1307void limSendRemoveStaKeyReq( tpAniSirGlobal pMac,
1308 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301309 tANI_U16 staIdx,
Jeff Johnsone7245742012-09-05 17:12:55 -07001310 tpPESession psessionEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07001311{
1312tSirMsgQ msgQ;
1313tpRemoveStaKeyParams pRemoveStaKeyParams = NULL;
1314tLimMlmRemoveKeyCnf mlmRemoveKeyCnf;
1315tSirRetStatus retCode;
1316
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301317 pRemoveStaKeyParams = vos_mem_malloc(sizeof( tRemoveStaKeyParams ));
1318 if ( NULL == pRemoveStaKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001319 {
1320 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301321 FL( "Unable to allocate memory during REMOVE_STAKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001322
1323 // Respond to SME with error code
1324 mlmRemoveKeyCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1325 goto end;
1326 }
1327 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301328 vos_mem_set( (void *) pRemoveStaKeyParams,
1329 sizeof( tRemoveStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001330
1331 if( (pMlmRemoveKeyReq->edType == eSIR_ED_WEP104 || pMlmRemoveKeyReq->edType == eSIR_ED_WEP40) &&
1332 pMlmRemoveKeyReq->wepType == eSIR_WEP_STATIC )
1333 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001334 PELOGE(limLog(pMac, LOGE, FL("Request to remove static WEP keys through station interface\n Should use BSS interface"));)
Jeff Johnson295189b2012-06-20 16:38:30 -07001335 mlmRemoveKeyCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
1336 goto end;
1337 }
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001338
Jeff Johnson295189b2012-06-20 16:38:30 -07001339 // Update the WDA_REMOVEKEY_REQ parameters
1340 pRemoveStaKeyParams->staIdx = staIdx;
1341 pRemoveStaKeyParams->encType = pMlmRemoveKeyReq->edType;
1342 pRemoveStaKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1343 pRemoveStaKeyParams->unicast = pMlmRemoveKeyReq->unicast;
1344
1345 /* Update PE session ID*/
Jeff Johnsone7245742012-09-05 17:12:55 -07001346 pRemoveStaKeyParams->sessionId = psessionEntry->peSessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001347
1348 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001349
Jeff Johnson295189b2012-06-20 16:38:30 -07001350 msgQ.type = WDA_REMOVE_STAKEY_REQ;
1351 //
1352 // FIXME_GEN4
1353 // A global counter (dialog token) is required to keep track of
1354 // all PE <-> HAL communication(s)
1355 //
1356 msgQ.reserved = 0;
1357 msgQ.bodyptr = pRemoveStaKeyParams;
1358 msgQ.bodyval = 0;
1359
1360 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001361 FL( "Sending WDA_REMOVE_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001362 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001363 retCode = wdaPostCtrlMsg( pMac, &msgQ );
1364 if (eSIR_SUCCESS != retCode)
Jeff Johnson295189b2012-06-20 16:38:30 -07001365 {
1366 limLog( pMac, LOGE,
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001367 FL("Posting REMOVE_STAKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001368 retCode );
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301369 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001370 pRemoveStaKeyParams = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07001371
1372 // Respond to SME with LIM_MLM_REMOVEKEY_CNF
1373 mlmRemoveKeyCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1374 }
1375 else
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001376 return;
Jeff Johnson295189b2012-06-20 16:38:30 -07001377
1378end:
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001379 if (pRemoveStaKeyParams)
1380 {
Kiet Lam842c3e12013-11-16 22:40:57 +05301381 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001382 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001383 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001384 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001385 pMlmRemoveKeyReq,
1386 &mlmRemoveKeyCnf );
1387
1388}
1389
1390