blob: bffffb04198a79ddfdd0cc5029d403a26bf0921b [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;
521 // 'Change' timer for future activations
522 limDeactivateAndChangeTimer(pMac, eLIM_AUTH_RETRY_TIMER);
Jeff Johnson295189b2012-06-20 16:38:30 -0700523 // 'Change' timer for future activations
524 limDeactivateAndChangeTimer(pMac, eLIM_AUTH_FAIL_TIMER);
525
526 #if 0
527 if (wlan_cfgGetStr(pMac, WNI_CFG_BSSID, currentBssId, &cfg) != eSIR_SUCCESS)
528 {
529 /// Could not get BSSID from CFG. Log error.
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700530 limLog(pMac, LOGP, FL("could not retrieve BSSID"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700531 }
532 #endif //TO SUPPORT BT-AMP
533 sirCopyMacAddr(currentBssId,sessionEntry->bssId);
534
535 if (sessionEntry->limSmeState == eLIM_SME_WT_PRE_AUTH_STATE)
536 {
537 pMac->lim.gLimPreAuthChannelNumber = 0;
538 }
539
Paul Zhang83289792017-02-28 18:58:52 +0800540 if ((protStatusCode == eSIR_MAC_MAX_ASSOC_STA_REACHED_STATUS)
541 && (sessionEntry->sta_auth_retries_for_code17 <
542 pMac->sta_auth_retries_for_code17)) {
543 limLog(pMac, LOG1, FL("Retry Auth "));
544 limDoSendAuthMgmtFrame(pMac, sessionEntry);
545 sessionEntry->sta_auth_retries_for_code17++;
546 } else {
547 /// Free up buffer allocated
548 /// for pMac->lim.gLimMlmAuthReq
549 vos_mem_free(pMac->lim.gpLimMlmAuthReq);
550 pMac->lim.gpLimMlmAuthReq = NULL;
551
552 sessionEntry->limMlmState = sessionEntry->limPrevMlmState;
553
554 limPostSmeMessage(pMac,
Jeff Johnson295189b2012-06-20 16:38:30 -0700555 LIM_MLM_AUTH_CNF,
556 (tANI_U32 *) &mlmAuthCnf);
Paul Zhang83289792017-02-28 18:58:52 +0800557 sessionEntry->sta_auth_retries_for_code17 = 0;
558 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700559} /*** end limRestoreFromAuthState() ***/
560
561
562
563/**
564 * limLookUpKeyMappings()
565 *
566 *FUNCTION:
567 * This function is called in limProcessAuthFrame() function
568 * to determine if there exists a Key Mapping key for a given
569 * MAC address.
570 *
571 *LOGIC:
572 *
573 *ASSUMPTIONS:
574 * NA
575 *
576 *NOTE:
577 * NA
578 *
579 * @param macAddr MAC address of the peer STA for which existence
580 * of Key Mapping key is to be determined
581 *
582 * @return pKeyMapEntry - Pointer to the keyMapEntry returned by CFG
583 */
584
585tCfgWepKeyEntry *
586limLookUpKeyMappings(tSirMacAddr macAddr)
587{
588 return NULL;
589} /****** end limLookUpKeyMappings() ******/
590
591
592
593/**
594 * limEncryptAuthFrame()
595 *
596 *FUNCTION:
597 * This function is called in limProcessAuthFrame() function
598 * to encrypt Authentication frame3 body.
599 *
600 *LOGIC:
601 *
602 *ASSUMPTIONS:
603 * NA
604 *
605 *NOTE:
606 * NA
607 *
608 * @param pMac Pointer to Global MAC structure
609 * @param keyId key id to used
610 * @param pKey Pointer to the key to be used for encryption
611 * @param pPlainText Pointer to the body to be encrypted
612 * @param pEncrBody Pointer to the encrypted auth frame body
613 * @param keyLength 8 (WEP40) or 16 (WEP104)
614 * @return None
615 */
616
617void
618limEncryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 keyId, tANI_U8 *pKey, tANI_U8 *pPlainText,
619 tANI_U8 *pEncrBody, tANI_U32 keyLength)
620{
621 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530622 tANI_U16 frame_len;
Jeff Johnson295189b2012-06-20 16:38:30 -0700623
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530624 frame_len = ((tpSirMacAuthFrameBody)pPlainText)->length +
625 SIR_MAC_AUTH_FRAME_INFO_LEN + SIR_MAC_CHALLENGE_ID_LEN;
Jeff Johnson295189b2012-06-20 16:38:30 -0700626 keyLength += 3;
627
628 // Bytes 0-2 of seed is IV
629 // Read TSF timestamp into seed to get random IV - 1st 3 bytes
630 halGetTxTSFtimer(pMac, (tSirMacTimeStamp *) &seed);
631
632 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530633 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700634
635 // Compute CRC-32 and place them in last 4 bytes of plain text
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530636 limComputeCrc32(icv, pPlainText, frame_len);
Jeff Johnson295189b2012-06-20 16:38:30 -0700637
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530638 vos_mem_copy( pPlainText + frame_len,
Jeff Johnson295189b2012-06-20 16:38:30 -0700639 icv, SIR_MAC_WEP_ICV_LENGTH);
640
641 // Run RC4 on plain text with the seed
642 limRC4(pEncrBody + SIR_MAC_WEP_IV_LENGTH,
643 (tANI_U8 *) pPlainText, seed, keyLength,
yeshwanth sriram guntukaccf694b2017-08-14 13:30:56 +0530644 frame_len + SIR_MAC_WEP_ICV_LENGTH);
Jeff Johnson295189b2012-06-20 16:38:30 -0700645
646 // Prepare IV
647 pEncrBody[0] = seed[0];
648 pEncrBody[1] = seed[1];
649 pEncrBody[2] = seed[2];
650 pEncrBody[3] = keyId << 6;
651} /****** end limEncryptAuthFrame() ******/
652
653
654
655/**
656 * limComputeCrc32()
657 *
658 *FUNCTION:
659 * This function is called to compute CRC-32 on a given source.
660 * Used while encrypting/decrypting Authentication frame 3.
661 *
662 *LOGIC:
663 *
664 *ASSUMPTIONS:
665 * NA
666 *
667 *NOTE:
668 * NA
669 *
670 * @param pDest Destination location for computed CRC
671 * @param pSrc Source location to be CRC computed
672 * @param len Length over which CRC to be computed
673 * @return None
674 */
675
676void
Sridhar Selvaraj05a07142017-07-18 11:51:34 +0530677limComputeCrc32(tANI_U8 *pDest, tANI_U8 * pSrc, tANI_U16 len)
Jeff Johnson295189b2012-06-20 16:38:30 -0700678{
679 tANI_U32 crc;
680 int i;
681
682 crc = 0;
683 crc = ~crc;
684
685 while(len-- > 0)
686 crc = limCrcUpdate(crc, *pSrc++);
687
688 crc = ~crc;
689
690 for (i=0; i < SIR_MAC_WEP_IV_LENGTH; i++)
691 {
692 pDest[i] = (tANI_U8)crc;
693 crc >>= 8;
694 }
695} /****** end limComputeCrc32() ******/
696
697
698
699/**
700 * limRC4()
701 *
702 *FUNCTION:
703 * This function is called to run RC4 algorithm. Called while
704 * encrypting/decrypting Authentication frame 3.
705 *
706 *LOGIC:
707 *
708 *ASSUMPTIONS:
709 * NA
710 *
711 *NOTE:
712 * NA
713 *
714 * @param pDest Destination location for encrypted text
715 * @param pSrc Source location to be encrypted
716 * @param seed Contains seed (IV + key) for PRNG
717 * @param keyLength 8 (WEP40) or 16 (WEP104)
718 * @param frameLen Length of the frame
719 *
720 * @return None
721 */
722
723void
724limRC4(tANI_U8 *pDest, tANI_U8 *pSrc, tANI_U8 *seed, tANI_U32 keyLength, tANI_U16 frameLen)
725{
726 typedef struct
727 {
728 tANI_U8 i, j;
729 tANI_U8 sbox[256];
730 } tRC4Context;
731
732 tRC4Context ctx;
733
734 {
735 tANI_U16 i, j, k;
736
737 //
738 // Initialize sbox using seed
739 //
740
741 ctx.i = ctx.j = 0;
742 for (i=0; i<256; i++)
743 ctx.sbox[i] = (tANI_U8)i;
744
745 j = 0;
746 k = 0;
747 for (i=0; i<256; i++)
748 {
749 tANI_U8 temp;
Kiran Kumar Lokerea4db3dc2013-03-25 18:05:24 -0700750 if ( k < LIM_SEED_LENGTH )
751 j = (tANI_U8)(j + ctx.sbox[i] + seed[k]);
Jeff Johnson295189b2012-06-20 16:38:30 -0700752 temp = ctx.sbox[i];
753 ctx.sbox[i] = ctx.sbox[j];
754 ctx.sbox[j] = temp;
755
756 if (++k >= keyLength)
757 k = 0;
758 }
759 }
760
761 {
762 tANI_U8 i = ctx.i;
763 tANI_U8 j = ctx.j;
Sridhar Selvarajdd6518f2017-07-27 20:24:13 +0530764 tANI_U16 len = frameLen;
Jeff Johnson295189b2012-06-20 16:38:30 -0700765
766 while (len-- > 0)
767 {
768 tANI_U8 temp1, temp2;
769
770 i = (tANI_U8)(i+1);
771 temp1 = ctx.sbox[i];
772 j = (tANI_U8)(j + temp1);
773
774 ctx.sbox[i] = temp2 = ctx.sbox[j];
775 ctx.sbox[j] = temp1;
776
777 temp1 = (tANI_U8)(temp1 + temp2);
778 temp1 = ctx.sbox[temp1];
779 temp2 = (tANI_U8)(pSrc ? *pSrc++ : 0);
780
781 *pDest++ = (tANI_U8)(temp1 ^ temp2);
782 }
783
784 ctx.i = i;
785 ctx.j = j;
786 }
787} /****** end limRC4() ******/
788
789
790
791/**
792 * limDecryptAuthFrame()
793 *
794 *FUNCTION:
795 * This function is called in limProcessAuthFrame() function
796 * to decrypt received Authentication frame3 body.
797 *
798 *LOGIC:
799 *
800 *ASSUMPTIONS:
801 * NA
802 *
803 *NOTE:
804 * NA
805 *
806 * @param pMac Pointer to Global MAC structure
807 * @param pKey Pointer to the key to be used for decryption
808 * @param pEncrBody Pointer to the body to be decrypted
809 * @param pPlainBody Pointer to the decrypted body
810 * @param keyLength 8 (WEP40) or 16 (WEP104)
811 *
812 * @return Decrypt result - eSIR_SUCCESS for success and
813 * LIM_DECRYPT_ICV_FAIL for ICV mismatch.
814 * If decryption is a success, pBody will
815 * have decrypted auth frame body.
816 */
817
818tANI_U8
819limDecryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 *pKey, tANI_U8 *pEncrBody,
820 tANI_U8 *pPlainBody, tANI_U32 keyLength, tANI_U16 frameLen)
821{
822 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
823 int i;
824 keyLength += 3;
825
826
827 // Bytes 0-2 of seed is received IV
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530828 vos_mem_copy((tANI_U8 *) seed, pEncrBody, SIR_MAC_WEP_IV_LENGTH - 1);
Jeff Johnson295189b2012-06-20 16:38:30 -0700829
830 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530831 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700832
833 // Run RC4 on encrypted text with the seed
834 limRC4(pPlainBody,
835 pEncrBody + SIR_MAC_WEP_IV_LENGTH,
836 seed,
837 keyLength,
838 frameLen);
839
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700840 PELOG4(limLog(pMac, LOG4, FL("plainbody is "));
Jeff Johnson295189b2012-06-20 16:38:30 -0700841 sirDumpBuf(pMac, SIR_LIM_MODULE_ID, LOG4, pPlainBody, frameLen);)
842
843 // Compute CRC-32 and place them in last 4 bytes of encrypted body
844 limComputeCrc32(icv,
845 (tANI_U8 *) pPlainBody,
Sridhar Selvarajdd6518f2017-07-27 20:24:13 +0530846 (frameLen - SIR_MAC_WEP_ICV_LENGTH));
Jeff Johnson295189b2012-06-20 16:38:30 -0700847
848 // Compare RX_ICV with computed ICV
849 for (i = 0; i < SIR_MAC_WEP_ICV_LENGTH; i++)
850 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700851 PELOG4(limLog(pMac, LOG4, FL(" computed ICV%d[%x], rxed ICV%d[%x]"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700852 i, icv[i], i, pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i]);)
853 if (icv[i] != pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i])
854 return LIM_DECRYPT_ICV_FAIL;
855 }
856
857 return eSIR_SUCCESS;
858} /****** end limDecryptAuthFrame() ******/
859
860/**
861 * limPostSmeSetKeysCnf
862 *
863 * A utility API to send MLM_SETKEYS_CNF to SME
864 */
865void limPostSmeSetKeysCnf( tpAniSirGlobal pMac,
866 tLimMlmSetKeysReq *pMlmSetKeysReq,
867 tLimMlmSetKeysCnf *mlmSetKeysCnf)
868{
869 // Prepare and Send LIM_MLM_SETKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530870 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700871 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
872 sizeof(tSirMacAddr));
873
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
Jeff Johnson295189b2012-06-20 16:38:30 -0700878
879 /// Free up buffer allocated for mlmSetKeysReq
Vinay Krishna Eranna6f22c1f2014-10-13 16:03:06 +0530880 vos_mem_zero(pMlmSetKeysReq, sizeof(tLimMlmSetKeysReq));
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530881 vos_mem_free( pMlmSetKeysReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700882 pMac->lim.gpLimMlmSetKeysReq = NULL;
883
884 limPostSmeMessage( pMac,
885 LIM_MLM_SETKEYS_CNF,
886 (tANI_U32 *) mlmSetKeysCnf );
887}
888
889/**
890 * limPostSmeRemoveKeysCnf
891 *
892 * A utility API to send MLM_REMOVEKEY_CNF to SME
893 */
894void limPostSmeRemoveKeyCnf( tpAniSirGlobal pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -0700895 tpPESession psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -0700896 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
897 tLimMlmRemoveKeyCnf *mlmRemoveKeyCnf)
898{
899 // Prepare and Send LIM_MLM_REMOVEKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530900 vos_mem_copy( (tANI_U8 *) &mlmRemoveKeyCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700901 (tANI_U8 *) pMlmRemoveKeyReq->peerMacAddr,
902 sizeof(tSirMacAddr));
903
904 /// Free up buffer allocated for mlmRemoveKeysReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530905 vos_mem_free( pMlmRemoveKeyReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700906 pMac->lim.gpLimMlmRemoveKeyReq = NULL;
907
Jeff Johnsone7245742012-09-05 17:12:55 -0700908 psessionEntry->limMlmState = psessionEntry->limPrevMlmState; //Restore the state.
909 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, psessionEntry->peSessionId, psessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -0700910
911 limPostSmeMessage( pMac,
912 LIM_MLM_REMOVEKEY_CNF,
913 (tANI_U32 *) mlmRemoveKeyCnf );
914}
915
916/**
917 * limSendSetBssKeyReq()
918 *
919 *FUNCTION:
920 * This function is called from limProcessMlmSetKeysReq(),
921 * when PE is trying to setup the Group Keys related
922 * to a specified encryption type
923 *
924 *LOGIC:
925 *
926 *ASSUMPTIONS:
927 * NA
928 *
929 *NOTE:
930 * NA
931 *
932 * @param pMac Pointer to Global MAC structure
933 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
934 * @return none
935 */
936void limSendSetBssKeyReq( tpAniSirGlobal pMac,
937 tLimMlmSetKeysReq *pMlmSetKeysReq,
938 tpPESession psessionEntry)
939{
940tSirMsgQ msgQ;
941tpSetBssKeyParams pSetBssKeyParams = NULL;
942tLimMlmSetKeysCnf mlmSetKeysCnf;
943tSirRetStatus retCode;
944tANI_U32 val = 0;
945
946 if(pMlmSetKeysReq->numKeys > SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
947 {
948 limLog( pMac, LOG1,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700949 FL( "numKeys = %d is more than SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS" ), pMlmSetKeysReq->numKeys);
Jeff Johnson295189b2012-06-20 16:38:30 -0700950
951 // Respond to SME with error code
952 mlmSetKeysCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
953 goto end;
954 }
955
956 // Package WDA_SET_BSSKEY_REQ message parameters
957
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530958 pSetBssKeyParams = vos_mem_malloc(sizeof( tSetBssKeyParams ));
959 if ( NULL == pSetBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -0700960 {
961 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530962 FL( "Unable to allocate memory during SET_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700963
964 // Respond to SME with error code
965 mlmSetKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
966 goto end;
967 }
968 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530969 vos_mem_set( (void *) pSetBssKeyParams,
970 sizeof( tSetBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700971
972 // Update the WDA_SET_BSSKEY_REQ parameters
973 pSetBssKeyParams->bssIdx = psessionEntry->bssIdx;
974 pSetBssKeyParams->encType = pMlmSetKeysReq->edType;
Jeff Johnsone7245742012-09-05 17:12:55 -0700975
Jeff Johnson295189b2012-06-20 16:38:30 -0700976
977 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
978 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700979 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700980 }
981
982 pSetBssKeyParams->singleTidRc = (tANI_U8)val;
983
984 /* Update PE session Id*/
985 pSetBssKeyParams->sessionId = psessionEntry ->peSessionId;
986
Jeff Johnsone7245742012-09-05 17:12:55 -0700987 if(pMlmSetKeysReq->key[0].keyId &&
988 ((pMlmSetKeysReq->edType == eSIR_ED_WEP40) ||
989 (pMlmSetKeysReq->edType == eSIR_ED_WEP104))
990 )
991 {
992 /* IF the key id is non-zero and encryption type is WEP, Send all the 4
993 * keys to HAL with filling the key at right index in pSetBssKeyParams->key. */
994 pSetBssKeyParams->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530995 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key[pMlmSetKeysReq->key[0].keyId],
996 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof(pMlmSetKeysReq->key[0]));
Jeff Johnsone7245742012-09-05 17:12:55 -0700997
998 }
999 else
1000 {
1001 pSetBssKeyParams->numKeys = pMlmSetKeysReq->numKeys;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301002 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key,
1003 (tANI_U8 *) &pMlmSetKeysReq->key,
1004 sizeof( tSirKeys ) * pMlmSetKeysReq->numKeys );
Jeff Johnsone7245742012-09-05 17:12:55 -07001005 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001006
1007 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1008 msgQ.type = WDA_SET_BSSKEY_REQ;
1009 //
1010 // FIXME_GEN4
1011 // A global counter (dialog token) is required to keep track of
1012 // all PE <-> HAL communication(s)
1013 //
1014 msgQ.reserved = 0;
1015 msgQ.bodyptr = pSetBssKeyParams;
1016 msgQ.bodyval = 0;
1017
1018 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001019 FL( "Sending WDA_SET_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001020 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001021 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1022 {
1023 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001024 FL("Posting SET_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001025 retCode );
1026
1027 // Respond to SME with LIM_MLM_SETKEYS_CNF
1028 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1029 }
1030 else
1031 return; // Continue after WDA_SET_BSSKEY_RSP...
1032
1033end:
1034 limPostSmeSetKeysCnf( pMac,
1035 pMlmSetKeysReq,
1036 &mlmSetKeysCnf );
1037
1038}
1039
1040/**
1041 * @function : limSendSetStaKeyReq()
1042 *
1043 * @brief : This function is called from limProcessMlmSetKeysReq(),
1044 * when PE is trying to setup the Unicast Keys related
1045 * to a specified STA with specified encryption type
1046 *
1047 *LOGIC:
1048 *
1049 *ASSUMPTIONS:
1050 * NA
1051 *
1052 *NOTE:
1053 * NA
1054 *
1055 * @param pMac Pointer to Global MAC structure
1056 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
1057 * @param staIdx STA index for which the keys are being set
1058 * @param defWEPIdx The default WEP key index [0..3]
1059 * @return none
1060 */
1061void limSendSetStaKeyReq( tpAniSirGlobal pMac,
1062 tLimMlmSetKeysReq *pMlmSetKeysReq,
1063 tANI_U16 staIdx,
1064 tANI_U8 defWEPIdx,
1065 tpPESession sessionEntry)
1066{
1067tSirMsgQ msgQ;
1068tpSetStaKeyParams pSetStaKeyParams = NULL;
1069tLimMlmSetKeysCnf mlmSetKeysCnf;
1070tSirRetStatus retCode;
1071tANI_U32 val = 0;
1072
1073 // Package WDA_SET_STAKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301074 pSetStaKeyParams = vos_mem_malloc(sizeof( tSetStaKeyParams ));
1075 if ( NULL == pSetStaKeyParams )
1076 {
1077 limLog( pMac, LOGP, FL( "Unable to allocate memory during SET_BSSKEY" ));
1078 return;
1079 }
1080 else
1081 vos_mem_set( (void *) pSetStaKeyParams, sizeof( tSetStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001082
1083 // Update the WDA_SET_STAKEY_REQ parameters
1084 pSetStaKeyParams->staIdx = staIdx;
1085 pSetStaKeyParams->encType = pMlmSetKeysReq->edType;
1086
1087
1088 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
1089 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001090 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001091 }
1092
1093 pSetStaKeyParams->singleTidRc = (tANI_U8)val;
1094
1095 /* Update PE session ID*/
1096 pSetStaKeyParams->sessionId = sessionEntry->peSessionId;
1097
1098 /**
1099 * For WEP - defWEPIdx indicates the default WEP
1100 * Key to be used for TX
1101 * For all others, there's just one key that can
1102 * be used and hence it is assumed that
1103 * defWEPIdx = 0 (from the caller)
1104 */
1105
1106 pSetStaKeyParams->defWEPIdx = defWEPIdx;
1107
1108 /** Store the Previous MlmState*/
1109 sessionEntry->limPrevMlmState = sessionEntry->limMlmState;
1110 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1111
1112 if(sessionEntry->limSystemRole == eLIM_STA_IN_IBSS_ROLE && !pMlmSetKeysReq->key[0].unicast) {
1113 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_BCASTKEY_STATE;
1114 msgQ.type = WDA_SET_STA_BCASTKEY_REQ;
1115 }else {
1116 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
1117 msgQ.type = WDA_SET_STAKEY_REQ;
1118 }
Jeff Johnsone7245742012-09-05 17:12:55 -07001119 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001120
1121 /**
1122 * In the Case of WEP_DYNAMIC, ED_TKIP and ED_CCMP
1123 * the Key[0] contains the KEY, so just copy that alone,
1124 * for the case of WEP_STATIC the hal gets the key from cfg
1125 */
1126 switch( pMlmSetKeysReq->edType ) {
1127 case eSIR_ED_WEP40:
1128 case eSIR_ED_WEP104:
1129 // FIXME! Is this OK?
1130 if( 0 == pMlmSetKeysReq->numKeys ) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001131 tANI_U32 i;
1132
1133 for(i=0; i < SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS ;i++)
1134 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301135 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key[i],
1136 (tANI_U8 *) &pMlmSetKeysReq->key[i], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001137 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001138 pSetStaKeyParams->wepType = eSIR_WEP_STATIC;
1139 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
Jeff Johnsone7245742012-09-05 17:12:55 -07001140 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001141 }else {
Jeff Johnsone7245742012-09-05 17:12:55 -07001142 /*This case the keys are coming from upper layer so need to fill the
1143 * key at the default wep key index and send to the HAL */
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301144 if (defWEPIdx >= SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
1145 {
1146 limLog( pMac, LOGE, FL("WEPIdx length %d more than "
1147 "the Max limit, reset to Max"),defWEPIdx);
Mukul Sharmad2b81862014-07-01 21:01:04 +05301148 vos_mem_free (pSetStaKeyParams);
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301149 return;
1150 }
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301151 vos_mem_copy((tANI_U8 *) &pSetStaKeyParams->key[defWEPIdx],
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301152 (tANI_U8 *) &pMlmSetKeysReq->key[0],
1153 sizeof( pMlmSetKeysReq->key[0] ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001154 pMlmSetKeysReq->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301155
Jeff Johnson295189b2012-06-20 16:38:30 -07001156 }
1157 break;
1158 case eSIR_ED_TKIP:
1159 case eSIR_ED_CCMP:
1160#ifdef FEATURE_WLAN_WAPI
1161 case eSIR_ED_WPI:
1162#endif
1163 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301164 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key,
1165 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001166 }
1167 break;
1168 default:
1169 break;
1170 }
1171
1172
1173 //
1174 // FIXME_GEN4
1175 // A global counter (dialog token) is required to keep track of
1176 // all PE <-> HAL communication(s)
1177 //
1178 msgQ.reserved = 0;
1179 msgQ.bodyptr = pSetStaKeyParams;
1180 msgQ.bodyval = 0;
1181
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001182 limLog( pMac, LOG1, FL( "Sending WDA_SET_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001183 MTRACE(macTraceMsgTx(pMac, sessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001184 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ ))) {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001185 limLog( pMac, LOGE, FL("Posting SET_STAKEY to HAL failed, reason=%X"), retCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07001186 // Respond to SME with LIM_MLM_SETKEYS_CNF
1187 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1188 }else
1189 return; // Continue after WDA_SET_STAKEY_RSP...
1190
1191 limPostSmeSetKeysCnf( pMac, pMlmSetKeysReq, &mlmSetKeysCnf );
1192}
1193
1194/**
1195 * limSendRemoveBssKeyReq()
1196 *
1197 *FUNCTION:
1198 * This function is called from limProcessMlmRemoveReq(),
1199 * when PE is trying to Remove a Group Key related
1200 * to a specified encryption type
1201 *
1202 *LOGIC:
1203 *
1204 *ASSUMPTIONS:
1205 * NA
1206 *
1207 *NOTE:
1208 * NA
1209 *
1210 * @param pMac Pointer to Global MAC structure
1211 * @param pMlmRemoveKeyReq Pointer to MLM_REMOVEKEY_REQ buffer
1212 * @return none
1213 */
1214void limSendRemoveBssKeyReq( tpAniSirGlobal pMac,
1215 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
1216 tpPESession psessionEntry)
1217{
1218tSirMsgQ msgQ;
1219tpRemoveBssKeyParams pRemoveBssKeyParams = NULL;
1220tLimMlmRemoveKeyCnf mlmRemoveKeysCnf;
1221tSirRetStatus retCode;
1222
1223 // Package WDA_REMOVE_BSSKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301224 pRemoveBssKeyParams = vos_mem_malloc(sizeof( tRemoveBssKeyParams ));
1225 if ( NULL == pRemoveBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001226 {
1227 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301228 FL( "Unable to allocate memory during REMOVE_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001229
1230 // Respond to SME with error code
1231 mlmRemoveKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1232 goto end;
1233 }
1234 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301235 vos_mem_set( (void *) pRemoveBssKeyParams,
1236 sizeof( tRemoveBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001237
1238 // Update the WDA_REMOVE_BSSKEY_REQ parameters
1239 pRemoveBssKeyParams->bssIdx = psessionEntry->bssIdx;
1240 pRemoveBssKeyParams->encType = pMlmRemoveKeyReq->edType;
1241 pRemoveBssKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1242 pRemoveBssKeyParams->wepType = pMlmRemoveKeyReq->wepType;
1243
1244 /* Update PE session Id*/
1245
1246 pRemoveBssKeyParams->sessionId = psessionEntry->peSessionId;
1247
1248 msgQ.type = WDA_REMOVE_BSSKEY_REQ;
1249 //
1250 // FIXME_GEN4
1251 // A global counter (dialog token) is required to keep track of
1252 // all PE <-> HAL communication(s)
1253 //
1254 msgQ.reserved = 0;
1255 msgQ.bodyptr = pRemoveBssKeyParams;
1256 msgQ.bodyval = 0;
1257
1258 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001259 FL( "Sending WDA_REMOVE_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001260 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001261
1262 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1263 {
1264 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001265 FL("Posting REMOVE_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001266 retCode );
1267
1268 // Respond to SME with LIM_MLM_REMOVEKEYS_CNF
1269 mlmRemoveKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1270 }
1271 else
1272 return;
1273
1274end:
1275 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001276 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001277 pMlmRemoveKeyReq,
1278 &mlmRemoveKeysCnf );
1279
1280}
1281
1282/**
1283 * limSendRemoveStaKeyReq()
1284 *
1285 *FUNCTION:
1286 * This function is called from limProcessMlmRemoveKeysReq(),
1287 * when PE is trying to setup the Unicast Keys related
1288 * to a specified STA with specified encryption type
1289 *
1290 *LOGIC:
1291 *
1292 *ASSUMPTIONS:
1293 * NA
1294 *
1295 *NOTE:
1296 * NA
1297 *
1298 * @param pMac Pointer to Global MAC structure
1299 * @param pMlmRemoveKeysReq Pointer to MLM_REMOVEKEYS_REQ buffer
1300 * @param staIdx STA index for which the keys are being set
1301 * @return none
1302 */
1303void limSendRemoveStaKeyReq( tpAniSirGlobal pMac,
1304 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301305 tANI_U16 staIdx,
Jeff Johnsone7245742012-09-05 17:12:55 -07001306 tpPESession psessionEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07001307{
1308tSirMsgQ msgQ;
1309tpRemoveStaKeyParams pRemoveStaKeyParams = NULL;
1310tLimMlmRemoveKeyCnf mlmRemoveKeyCnf;
1311tSirRetStatus retCode;
1312
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301313 pRemoveStaKeyParams = vos_mem_malloc(sizeof( tRemoveStaKeyParams ));
1314 if ( NULL == pRemoveStaKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001315 {
1316 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301317 FL( "Unable to allocate memory during REMOVE_STAKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001318
1319 // Respond to SME with error code
1320 mlmRemoveKeyCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1321 goto end;
1322 }
1323 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301324 vos_mem_set( (void *) pRemoveStaKeyParams,
1325 sizeof( tRemoveStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001326
1327 if( (pMlmRemoveKeyReq->edType == eSIR_ED_WEP104 || pMlmRemoveKeyReq->edType == eSIR_ED_WEP40) &&
1328 pMlmRemoveKeyReq->wepType == eSIR_WEP_STATIC )
1329 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001330 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 -07001331 mlmRemoveKeyCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
1332 goto end;
1333 }
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001334
Jeff Johnson295189b2012-06-20 16:38:30 -07001335 // Update the WDA_REMOVEKEY_REQ parameters
1336 pRemoveStaKeyParams->staIdx = staIdx;
1337 pRemoveStaKeyParams->encType = pMlmRemoveKeyReq->edType;
1338 pRemoveStaKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1339 pRemoveStaKeyParams->unicast = pMlmRemoveKeyReq->unicast;
1340
1341 /* Update PE session ID*/
Jeff Johnsone7245742012-09-05 17:12:55 -07001342 pRemoveStaKeyParams->sessionId = psessionEntry->peSessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001343
1344 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001345
Jeff Johnson295189b2012-06-20 16:38:30 -07001346 msgQ.type = WDA_REMOVE_STAKEY_REQ;
1347 //
1348 // FIXME_GEN4
1349 // A global counter (dialog token) is required to keep track of
1350 // all PE <-> HAL communication(s)
1351 //
1352 msgQ.reserved = 0;
1353 msgQ.bodyptr = pRemoveStaKeyParams;
1354 msgQ.bodyval = 0;
1355
1356 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001357 FL( "Sending WDA_REMOVE_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001358 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001359 retCode = wdaPostCtrlMsg( pMac, &msgQ );
1360 if (eSIR_SUCCESS != retCode)
Jeff Johnson295189b2012-06-20 16:38:30 -07001361 {
1362 limLog( pMac, LOGE,
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001363 FL("Posting REMOVE_STAKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001364 retCode );
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301365 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001366 pRemoveStaKeyParams = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07001367
1368 // Respond to SME with LIM_MLM_REMOVEKEY_CNF
1369 mlmRemoveKeyCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1370 }
1371 else
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001372 return;
Jeff Johnson295189b2012-06-20 16:38:30 -07001373
1374end:
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001375 if (pRemoveStaKeyParams)
1376 {
Kiet Lam842c3e12013-11-16 22:40:57 +05301377 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001378 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001379 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001380 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001381 pMlmRemoveKeyReq,
1382 &mlmRemoveKeyCnf );
1383
1384}
1385
1386