blob: 4b7858bd5f50984629942ef58ed413e6aa6b359c [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lam842dad02014-02-18 18:44:02 -08002 * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
3 *
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"
Jeff Johnson295189b2012-06-20 16:38:30 -070042#include "wniCfgSta.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
53
54/**
55 * limIsAuthAlgoSupported()
56 *
57 *FUNCTION:
58 * This function is called in various places within LIM code
59 * to determine whether passed authentication algorithm is enabled
60 * or not
61 *
62 *LOGIC:
63 *
64 *ASSUMPTIONS:
65 * NA
66 *
67 *NOTE:
68 * NA
69 *
70 * @param authType Indicates MAC based authentication type
71 * (eSIR_OPEN_SYSTEM or eSIR_SHARED_KEY)
72 * If Shared Key authentication to be used,
73 * 'Privacy Option Implemented' flag is also
74 * checked.
75 *
76 * @return true if passed authType is enabled else false
77 */
Jeff Johnson295189b2012-06-20 16:38:30 -070078tANI_U8
79limIsAuthAlgoSupported(tpAniSirGlobal pMac, tAniAuthType authType, tpPESession psessionEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -070080{
81 tANI_U32 algoEnable, privacyOptImp;
82
83 if (authType == eSIR_OPEN_SYSTEM)
84 {
85
Jeff Johnson295189b2012-06-20 16:38:30 -070086 if(psessionEntry->limSystemRole == eLIM_AP_ROLE)
87 {
88 if((psessionEntry->authType == eSIR_OPEN_SYSTEM) || (psessionEntry->authType == eSIR_AUTO_SWITCH))
89 return true;
90 else
91 return false;
92 }
Jeff Johnson295189b2012-06-20 16:38:30 -070093
94 if (wlan_cfgGetInt(pMac, WNI_CFG_OPEN_SYSTEM_AUTH_ENABLE,
95 &algoEnable) != eSIR_SUCCESS)
96 {
97 /**
98 * Could not get AuthAlgo1 Enable value
99 * from CFG. Log error.
100 */
101 limLog(pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700102 FL("could not retrieve AuthAlgo1 Enable value"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700103
104 return false;
105 }
106 else
107 return ( (algoEnable > 0 ? true : false) );
108 }
109 else
110 {
111
Jeff Johnson295189b2012-06-20 16:38:30 -0700112 if(psessionEntry->limSystemRole == eLIM_AP_ROLE)
113 {
114 if((psessionEntry->authType == eSIR_SHARED_KEY) || (psessionEntry->authType == eSIR_AUTO_SWITCH))
115 algoEnable = true;
116 else
117 algoEnable = false;
118
119 }
120 else
Jeff Johnson295189b2012-06-20 16:38:30 -0700121
122 if (wlan_cfgGetInt(pMac, WNI_CFG_SHARED_KEY_AUTH_ENABLE,
123 &algoEnable) != eSIR_SUCCESS)
124 {
125 /**
126 * Could not get AuthAlgo2 Enable value
127 * from CFG. Log error.
128 */
129 limLog(pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700130 FL("could not retrieve AuthAlgo2 Enable value"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700131
132 return false;
133 }
134
Jeff Johnson295189b2012-06-20 16:38:30 -0700135 if(psessionEntry->limSystemRole == eLIM_AP_ROLE)
136 {
137 privacyOptImp = psessionEntry->privacy;
138 }
139 else
Jeff Johnson295189b2012-06-20 16:38:30 -0700140
141 if (wlan_cfgGetInt(pMac, WNI_CFG_PRIVACY_ENABLED,
142 &privacyOptImp) != eSIR_SUCCESS)
143 {
144 /**
145 * Could not get PrivacyOptionImplemented value
146 * from CFG. Log error.
147 */
148 limLog(pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700149 FL("could not retrieve PrivacyOptImplemented value"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700150
151 return false;
152 }
153 return (algoEnable && privacyOptImp);
154 }
155} /****** end limIsAuthAlgoSupported() ******/
156
157
158
159/**
160 * limInitPreAuthList
161 *
162 *FUNCTION:
163 * This function is called while starting a BSS at AP
164 * to initialize MAC authenticated STA list. This may also be called
165 * while joining/starting an IBSS if MAC authentication is allowed
166 * in IBSS mode.
167 *
168 *LOGIC:
169 *
170 *ASSUMPTIONS:
171 *
172 *NOTE:
173 *
174 * @param pMac - Pointer to Global MAC structure
175 * @return None
176 */
177
178void
179limInitPreAuthList(tpAniSirGlobal pMac)
180{
181 pMac->lim.pLimPreAuthList = NULL;
182
Jeff Johnson295189b2012-06-20 16:38:30 -0700183} /*** end limInitPreAuthList() ***/
184
185
186
187/**
188 * limDeletePreAuthList
189 *
190 *FUNCTION:
191 * This function is called cleanup Pre-auth list either on
192 * AP or on STA when moving from one persona to other.
193 *
194 *LOGIC:
195 *
196 *ASSUMPTIONS:
197 *
198 *NOTE:
199 *
200 * @param pMac - Pointer to Global MAC structure
201 * @return None
202 */
203
204void
205limDeletePreAuthList(tpAniSirGlobal pMac)
206{
207 struct tLimPreAuthNode *pCurrNode, *pTempNode;
208
209 pCurrNode = pTempNode = pMac->lim.pLimPreAuthList;
210 while (pCurrNode != NULL)
211 {
212 pTempNode = pCurrNode->next;
213
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700214 PELOG1(limLog(pMac, LOG1, FL("=====> limDeletePreAuthList "));)
Jeff Johnson295189b2012-06-20 16:38:30 -0700215 limReleasePreAuthNode(pMac, pCurrNode);
216
217 pCurrNode = pTempNode;
218 }
219 pMac->lim.pLimPreAuthList = NULL;
220} /*** end limDeletePreAuthList() ***/
221
222
223
224/**
225 * limSearchPreAuthList
226 *
227 *FUNCTION:
228 * This function is called when Authentication frame is received
229 * by AP (or at a STA in IBSS supporting MAC based authentication)
230 * to search if a STA is in the middle of MAC Authentication
231 * transaction sequence.
232 *
233 *LOGIC:
234 *
235 *ASSUMPTIONS:
236 *
237 *NOTE:
238 *
239 * @param macAddr - MAC address of the STA that sent
240 * Authentication frame.
241 *
242 * @return Pointer to pre-auth node if found, else NULL
243 */
244
245struct tLimPreAuthNode *
246limSearchPreAuthList(tpAniSirGlobal pMac, tSirMacAddr macAddr)
247{
248 struct tLimPreAuthNode *pTempNode = pMac->lim.pLimPreAuthList;
249
250 while (pTempNode != NULL)
251 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530252 if (vos_mem_compare( (tANI_U8 *) macAddr,
253 (tANI_U8 *) &pTempNode->peerMacAddr,
254 sizeof(tSirMacAddr)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700255 break;
256
257 pTempNode = pTempNode->next;
258 }
259
260 return pTempNode;
261} /*** end limSearchPreAuthList() ***/
262
263
264
265/**
266 * limAddPreAuthNode
267 *
268 *FUNCTION:
269 * This function is called at AP while sending Authentication
270 * frame2.
271 * This may also be called on a STA in IBSS if MAC authentication is
272 * allowed in IBSS mode.
273 *
274 *LOGIC:
275 * Node is always added to the front of the list
276 *
277 *ASSUMPTIONS:
278 *
279 *NOTE:
280 *
281 * @param pMac - Pointer to Global MAC structure
282 * @param pAuthNode - Pointer to pre-auth node to be added to the list.
283 *
284 * @return None
285 */
286
287void
288limAddPreAuthNode(tpAniSirGlobal pMac, struct tLimPreAuthNode *pAuthNode)
289{
290 pMac->lim.gLimNumPreAuthContexts++;
291
292 pAuthNode->next = pMac->lim.pLimPreAuthList;
293
294 pMac->lim.pLimPreAuthList = pAuthNode;
295} /*** end limAddPreAuthNode() ***/
296
297
298/**
299 * limReleasePreAuthNode
300 *
301 *FUNCTION:
302 * This function is called to realease the accquired
303 * pre auth node from list.
304 *
305 *LOGIC:
306 *
307 *ASSUMPTIONS:
308 *
309 *NOTE:
310 *
311 * @param pMac - Pointer to Global MAC structure
312 * @param pAuthNode - Pointer to Pre Auth node to be released
313 * @return None
314 */
315
316void
317limReleasePreAuthNode(tpAniSirGlobal pMac, tpLimPreAuthNode pAuthNode)
318{
319 pAuthNode->fFree = 1;
Jeff Johnsone7245742012-09-05 17:12:55 -0700320 MTRACE(macTrace(pMac, TRACE_CODE_TIMER_DEACTIVATE, NO_SESSION, eLIM_PRE_AUTH_CLEANUP_TIMER));
Jeff Johnson295189b2012-06-20 16:38:30 -0700321 tx_timer_deactivate(&pAuthNode->timer);
322 pMac->lim.gLimNumPreAuthContexts--;
323} /*** end limReleasePreAuthNode() ***/
324
325
326/**
327 * limDeletePreAuthNode
328 *
329 *FUNCTION:
330 * This function is called at AP when a pre-authenticated STA is
331 * Associated/Reassociated or when AuthFrame4 is received after
332 * Auth Response timeout.
333 * This may also be called on a STA in IBSS if MAC authentication and
334 * Association/Reassociation is allowed in IBSS mode.
335 *
336 *LOGIC:
337 *
338 *ASSUMPTIONS:
339 *
340 *NOTE:
341 *
342 * @param pMac - Pointer to Global MAC structure
343 * @param peerMacAddr - MAC address of the STA that need to be deleted
344 * from pre-auth node list.
345 *
346 * @return None
347 */
348
349void
350limDeletePreAuthNode(tpAniSirGlobal pMac, tSirMacAddr macAddr)
351{
352 struct tLimPreAuthNode *pPrevNode, *pTempNode;
353
354 pTempNode = pPrevNode = pMac->lim.pLimPreAuthList;
355
356 if (pTempNode == NULL)
357 return;
358
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530359 if (vos_mem_compare( (tANI_U8 *) macAddr,
360 (tANI_U8 *) &pTempNode->peerMacAddr,
361 sizeof(tSirMacAddr)) )
Jeff Johnson295189b2012-06-20 16:38:30 -0700362 {
363 // First node to be deleted
364
365 pMac->lim.pLimPreAuthList = pTempNode->next;
366
Jeff Johnson295189b2012-06-20 16:38:30 -0700367
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700368 PELOG1(limLog(pMac, LOG1, FL("=====> limDeletePreAuthNode : first node to delete"));)
369 PELOG1(limLog(pMac, LOG1, FL("Release data entry: %x id %d peer "),
Jeff Johnson295189b2012-06-20 16:38:30 -0700370 pTempNode, pTempNode->authNodeIdx);
371 limPrintMacAddr(pMac, macAddr, LOG1);)
372 limReleasePreAuthNode(pMac, pTempNode);
373
374 return;
375 }
376
377 pTempNode = pTempNode->next;
378
379 while (pTempNode != NULL)
380 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530381 if (vos_mem_compare( (tANI_U8 *) macAddr,
382 (tANI_U8 *) &pTempNode->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700383 sizeof(tSirMacAddr)) )
384 {
385 // Found node to be deleted
386
387 pPrevNode->next = pTempNode->next;
388
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700389 PELOG1(limLog(pMac, LOG1, FL("=====> limDeletePreAuthNode : subsequent node to delete"));
390 limLog(pMac, LOG1, FL("Release data entry: %x id %d peer "),
Jeff Johnson295189b2012-06-20 16:38:30 -0700391 pTempNode, pTempNode->authNodeIdx);
392 limPrintMacAddr(pMac, macAddr, LOG1);)
393 limReleasePreAuthNode(pMac, pTempNode);
394
395 return;
396 }
397
398 pPrevNode = pTempNode;
399 pTempNode = pTempNode->next;
400 }
401
402 // Should not be here
403 // Log error
404 limLog(pMac, LOGP, FL("peer not found in pre-auth list, addr= "));
405 limPrintMacAddr(pMac, macAddr, LOGP);
406
407} /*** end limDeletePreAuthNode() ***/
408
409
Jeff Johnson295189b2012-06-20 16:38:30 -0700410
411
412
413/**
414 * limRestoreFromPreAuthState
415 *
416 *FUNCTION:
417 * This function is called on STA whenever an Authentication
418 * sequence is complete and state prior to auth need to be
419 * restored.
420 *
421 *LOGIC:
422 * MLM_AUTH_CNF is prepared and sent to SME state machine.
423 * In case of restoring from pre-auth:
424 * - Channel Id is programmed at LO/RF synthesizer
425 * - BSSID is programmed at RHP
426 *
427 *ASSUMPTIONS:
428 *
429 *NOTE:
430 *
431 * @param pMac - Pointer to Global MAC structure
432 * @param resultCode - result of authentication attempt
433 * @return None
434 */
435
436void
437limRestoreFromAuthState(tpAniSirGlobal pMac, tSirResultCodes resultCode, tANI_U16 protStatusCode,tpPESession sessionEntry)
438{
439 tSirMacAddr currentBssId;
440 tLimMlmAuthCnf mlmAuthCnf;
441
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530442 vos_mem_copy( (tANI_U8 *) &mlmAuthCnf.peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700443 (tANI_U8 *) &pMac->lim.gpLimMlmAuthReq->peerMacAddr,
444 sizeof(tSirMacAddr));
445 mlmAuthCnf.authType = pMac->lim.gpLimMlmAuthReq->authType;
446 mlmAuthCnf.resultCode = resultCode;
447 mlmAuthCnf.protStatusCode = protStatusCode;
448
449 /* Update PE session ID*/
450 mlmAuthCnf.sessionId = sessionEntry->peSessionId;
451
452 /// Free up buffer allocated
453 /// for pMac->lim.gLimMlmAuthReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530454 vos_mem_free(pMac->lim.gpLimMlmAuthReq);
Jeff Johnson295189b2012-06-20 16:38:30 -0700455 pMac->lim.gpLimMlmAuthReq = NULL;
456
457 sessionEntry->limMlmState = sessionEntry->limPrevMlmState;
458
Jeff Johnsone7245742012-09-05 17:12:55 -0700459 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -0700460
461
462 // 'Change' timer for future activations
463 limDeactivateAndChangeTimer(pMac, eLIM_AUTH_FAIL_TIMER);
464
465 #if 0
466 if (wlan_cfgGetStr(pMac, WNI_CFG_BSSID, currentBssId, &cfg) != eSIR_SUCCESS)
467 {
468 /// Could not get BSSID from CFG. Log error.
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700469 limLog(pMac, LOGP, FL("could not retrieve BSSID"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700470 }
471 #endif //TO SUPPORT BT-AMP
472 sirCopyMacAddr(currentBssId,sessionEntry->bssId);
473
474 if (sessionEntry->limSmeState == eLIM_SME_WT_PRE_AUTH_STATE)
475 {
476 pMac->lim.gLimPreAuthChannelNumber = 0;
477 }
478
479 limPostSmeMessage(pMac,
480 LIM_MLM_AUTH_CNF,
481 (tANI_U32 *) &mlmAuthCnf);
482} /*** end limRestoreFromAuthState() ***/
483
484
485
486/**
487 * limLookUpKeyMappings()
488 *
489 *FUNCTION:
490 * This function is called in limProcessAuthFrame() function
491 * to determine if there exists a Key Mapping key for a given
492 * MAC address.
493 *
494 *LOGIC:
495 *
496 *ASSUMPTIONS:
497 * NA
498 *
499 *NOTE:
500 * NA
501 *
502 * @param macAddr MAC address of the peer STA for which existence
503 * of Key Mapping key is to be determined
504 *
505 * @return pKeyMapEntry - Pointer to the keyMapEntry returned by CFG
506 */
507
508tCfgWepKeyEntry *
509limLookUpKeyMappings(tSirMacAddr macAddr)
510{
511 return NULL;
512} /****** end limLookUpKeyMappings() ******/
513
514
515
516/**
517 * limEncryptAuthFrame()
518 *
519 *FUNCTION:
520 * This function is called in limProcessAuthFrame() function
521 * to encrypt Authentication frame3 body.
522 *
523 *LOGIC:
524 *
525 *ASSUMPTIONS:
526 * NA
527 *
528 *NOTE:
529 * NA
530 *
531 * @param pMac Pointer to Global MAC structure
532 * @param keyId key id to used
533 * @param pKey Pointer to the key to be used for encryption
534 * @param pPlainText Pointer to the body to be encrypted
535 * @param pEncrBody Pointer to the encrypted auth frame body
536 * @param keyLength 8 (WEP40) or 16 (WEP104)
537 * @return None
538 */
539
540void
541limEncryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 keyId, tANI_U8 *pKey, tANI_U8 *pPlainText,
542 tANI_U8 *pEncrBody, tANI_U32 keyLength)
543{
544 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
545
546 keyLength += 3;
547
548 // Bytes 0-2 of seed is IV
549 // Read TSF timestamp into seed to get random IV - 1st 3 bytes
550 halGetTxTSFtimer(pMac, (tSirMacTimeStamp *) &seed);
551
552 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530553 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700554
555 // Compute CRC-32 and place them in last 4 bytes of plain text
556 limComputeCrc32(icv, pPlainText, sizeof(tSirMacAuthFrameBody));
557
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530558 vos_mem_copy( pPlainText + sizeof(tSirMacAuthFrameBody),
Jeff Johnson295189b2012-06-20 16:38:30 -0700559 icv, SIR_MAC_WEP_ICV_LENGTH);
560
561 // Run RC4 on plain text with the seed
562 limRC4(pEncrBody + SIR_MAC_WEP_IV_LENGTH,
563 (tANI_U8 *) pPlainText, seed, keyLength,
564 LIM_ENCR_AUTH_BODY_LEN - SIR_MAC_WEP_IV_LENGTH);
565
566 // Prepare IV
567 pEncrBody[0] = seed[0];
568 pEncrBody[1] = seed[1];
569 pEncrBody[2] = seed[2];
570 pEncrBody[3] = keyId << 6;
571} /****** end limEncryptAuthFrame() ******/
572
573
574
575/**
576 * limComputeCrc32()
577 *
578 *FUNCTION:
579 * This function is called to compute CRC-32 on a given source.
580 * Used while encrypting/decrypting Authentication frame 3.
581 *
582 *LOGIC:
583 *
584 *ASSUMPTIONS:
585 * NA
586 *
587 *NOTE:
588 * NA
589 *
590 * @param pDest Destination location for computed CRC
591 * @param pSrc Source location to be CRC computed
592 * @param len Length over which CRC to be computed
593 * @return None
594 */
595
596void
597limComputeCrc32(tANI_U8 *pDest, tANI_U8 * pSrc, tANI_U8 len)
598{
599 tANI_U32 crc;
600 int i;
601
602 crc = 0;
603 crc = ~crc;
604
605 while(len-- > 0)
606 crc = limCrcUpdate(crc, *pSrc++);
607
608 crc = ~crc;
609
610 for (i=0; i < SIR_MAC_WEP_IV_LENGTH; i++)
611 {
612 pDest[i] = (tANI_U8)crc;
613 crc >>= 8;
614 }
615} /****** end limComputeCrc32() ******/
616
617
618
619/**
620 * limRC4()
621 *
622 *FUNCTION:
623 * This function is called to run RC4 algorithm. Called while
624 * encrypting/decrypting Authentication frame 3.
625 *
626 *LOGIC:
627 *
628 *ASSUMPTIONS:
629 * NA
630 *
631 *NOTE:
632 * NA
633 *
634 * @param pDest Destination location for encrypted text
635 * @param pSrc Source location to be encrypted
636 * @param seed Contains seed (IV + key) for PRNG
637 * @param keyLength 8 (WEP40) or 16 (WEP104)
638 * @param frameLen Length of the frame
639 *
640 * @return None
641 */
642
643void
644limRC4(tANI_U8 *pDest, tANI_U8 *pSrc, tANI_U8 *seed, tANI_U32 keyLength, tANI_U16 frameLen)
645{
646 typedef struct
647 {
648 tANI_U8 i, j;
649 tANI_U8 sbox[256];
650 } tRC4Context;
651
652 tRC4Context ctx;
653
654 {
655 tANI_U16 i, j, k;
656
657 //
658 // Initialize sbox using seed
659 //
660
661 ctx.i = ctx.j = 0;
662 for (i=0; i<256; i++)
663 ctx.sbox[i] = (tANI_U8)i;
664
665 j = 0;
666 k = 0;
667 for (i=0; i<256; i++)
668 {
669 tANI_U8 temp;
Kiran Kumar Lokerea4db3dc2013-03-25 18:05:24 -0700670 if ( k < LIM_SEED_LENGTH )
671 j = (tANI_U8)(j + ctx.sbox[i] + seed[k]);
Jeff Johnson295189b2012-06-20 16:38:30 -0700672 temp = ctx.sbox[i];
673 ctx.sbox[i] = ctx.sbox[j];
674 ctx.sbox[j] = temp;
675
676 if (++k >= keyLength)
677 k = 0;
678 }
679 }
680
681 {
682 tANI_U8 i = ctx.i;
683 tANI_U8 j = ctx.j;
684 tANI_U8 len = (tANI_U8) frameLen;
685
686 while (len-- > 0)
687 {
688 tANI_U8 temp1, temp2;
689
690 i = (tANI_U8)(i+1);
691 temp1 = ctx.sbox[i];
692 j = (tANI_U8)(j + temp1);
693
694 ctx.sbox[i] = temp2 = ctx.sbox[j];
695 ctx.sbox[j] = temp1;
696
697 temp1 = (tANI_U8)(temp1 + temp2);
698 temp1 = ctx.sbox[temp1];
699 temp2 = (tANI_U8)(pSrc ? *pSrc++ : 0);
700
701 *pDest++ = (tANI_U8)(temp1 ^ temp2);
702 }
703
704 ctx.i = i;
705 ctx.j = j;
706 }
707} /****** end limRC4() ******/
708
709
710
711/**
712 * limDecryptAuthFrame()
713 *
714 *FUNCTION:
715 * This function is called in limProcessAuthFrame() function
716 * to decrypt received Authentication frame3 body.
717 *
718 *LOGIC:
719 *
720 *ASSUMPTIONS:
721 * NA
722 *
723 *NOTE:
724 * NA
725 *
726 * @param pMac Pointer to Global MAC structure
727 * @param pKey Pointer to the key to be used for decryption
728 * @param pEncrBody Pointer to the body to be decrypted
729 * @param pPlainBody Pointer to the decrypted body
730 * @param keyLength 8 (WEP40) or 16 (WEP104)
731 *
732 * @return Decrypt result - eSIR_SUCCESS for success and
733 * LIM_DECRYPT_ICV_FAIL for ICV mismatch.
734 * If decryption is a success, pBody will
735 * have decrypted auth frame body.
736 */
737
738tANI_U8
739limDecryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 *pKey, tANI_U8 *pEncrBody,
740 tANI_U8 *pPlainBody, tANI_U32 keyLength, tANI_U16 frameLen)
741{
742 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
743 int i;
744 keyLength += 3;
745
746
747 // Bytes 0-2 of seed is received IV
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530748 vos_mem_copy((tANI_U8 *) seed, pEncrBody, SIR_MAC_WEP_IV_LENGTH - 1);
Jeff Johnson295189b2012-06-20 16:38:30 -0700749
750 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530751 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700752
753 // Run RC4 on encrypted text with the seed
754 limRC4(pPlainBody,
755 pEncrBody + SIR_MAC_WEP_IV_LENGTH,
756 seed,
757 keyLength,
758 frameLen);
759
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700760 PELOG4(limLog(pMac, LOG4, FL("plainbody is "));
Jeff Johnson295189b2012-06-20 16:38:30 -0700761 sirDumpBuf(pMac, SIR_LIM_MODULE_ID, LOG4, pPlainBody, frameLen);)
762
763 // Compute CRC-32 and place them in last 4 bytes of encrypted body
764 limComputeCrc32(icv,
765 (tANI_U8 *) pPlainBody,
766 (tANI_U8) (frameLen - SIR_MAC_WEP_ICV_LENGTH));
767
768 // Compare RX_ICV with computed ICV
769 for (i = 0; i < SIR_MAC_WEP_ICV_LENGTH; i++)
770 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700771 PELOG4(limLog(pMac, LOG4, FL(" computed ICV%d[%x], rxed ICV%d[%x]"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700772 i, icv[i], i, pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i]);)
773 if (icv[i] != pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i])
774 return LIM_DECRYPT_ICV_FAIL;
775 }
776
777 return eSIR_SUCCESS;
778} /****** end limDecryptAuthFrame() ******/
779
780/**
781 * limPostSmeSetKeysCnf
782 *
783 * A utility API to send MLM_SETKEYS_CNF to SME
784 */
785void limPostSmeSetKeysCnf( tpAniSirGlobal pMac,
786 tLimMlmSetKeysReq *pMlmSetKeysReq,
787 tLimMlmSetKeysCnf *mlmSetKeysCnf)
788{
789 // Prepare and Send LIM_MLM_SETKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530790 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700791 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
792 sizeof(tSirMacAddr));
793
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530794 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700795 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
796 sizeof(tSirMacAddr));
797
Jeff Johnson295189b2012-06-20 16:38:30 -0700798
799 /// Free up buffer allocated for mlmSetKeysReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530800 vos_mem_free( pMlmSetKeysReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700801 pMac->lim.gpLimMlmSetKeysReq = NULL;
802
803 limPostSmeMessage( pMac,
804 LIM_MLM_SETKEYS_CNF,
805 (tANI_U32 *) mlmSetKeysCnf );
806}
807
808/**
809 * limPostSmeRemoveKeysCnf
810 *
811 * A utility API to send MLM_REMOVEKEY_CNF to SME
812 */
813void limPostSmeRemoveKeyCnf( tpAniSirGlobal pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -0700814 tpPESession psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -0700815 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
816 tLimMlmRemoveKeyCnf *mlmRemoveKeyCnf)
817{
818 // Prepare and Send LIM_MLM_REMOVEKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530819 vos_mem_copy( (tANI_U8 *) &mlmRemoveKeyCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700820 (tANI_U8 *) pMlmRemoveKeyReq->peerMacAddr,
821 sizeof(tSirMacAddr));
822
823 /// Free up buffer allocated for mlmRemoveKeysReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530824 vos_mem_free( pMlmRemoveKeyReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700825 pMac->lim.gpLimMlmRemoveKeyReq = NULL;
826
Jeff Johnsone7245742012-09-05 17:12:55 -0700827 psessionEntry->limMlmState = psessionEntry->limPrevMlmState; //Restore the state.
828 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, psessionEntry->peSessionId, psessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -0700829
830 limPostSmeMessage( pMac,
831 LIM_MLM_REMOVEKEY_CNF,
832 (tANI_U32 *) mlmRemoveKeyCnf );
833}
834
835/**
836 * limSendSetBssKeyReq()
837 *
838 *FUNCTION:
839 * This function is called from limProcessMlmSetKeysReq(),
840 * when PE is trying to setup the Group Keys related
841 * to a specified encryption type
842 *
843 *LOGIC:
844 *
845 *ASSUMPTIONS:
846 * NA
847 *
848 *NOTE:
849 * NA
850 *
851 * @param pMac Pointer to Global MAC structure
852 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
853 * @return none
854 */
855void limSendSetBssKeyReq( tpAniSirGlobal pMac,
856 tLimMlmSetKeysReq *pMlmSetKeysReq,
857 tpPESession psessionEntry)
858{
859tSirMsgQ msgQ;
860tpSetBssKeyParams pSetBssKeyParams = NULL;
861tLimMlmSetKeysCnf mlmSetKeysCnf;
862tSirRetStatus retCode;
863tANI_U32 val = 0;
864
865 if(pMlmSetKeysReq->numKeys > SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
866 {
867 limLog( pMac, LOG1,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700868 FL( "numKeys = %d is more than SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS" ), pMlmSetKeysReq->numKeys);
Jeff Johnson295189b2012-06-20 16:38:30 -0700869
870 // Respond to SME with error code
871 mlmSetKeysCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
872 goto end;
873 }
874
875 // Package WDA_SET_BSSKEY_REQ message parameters
876
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530877 pSetBssKeyParams = vos_mem_malloc(sizeof( tSetBssKeyParams ));
878 if ( NULL == pSetBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -0700879 {
880 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530881 FL( "Unable to allocate memory during SET_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700882
883 // Respond to SME with error code
884 mlmSetKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
885 goto end;
886 }
887 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530888 vos_mem_set( (void *) pSetBssKeyParams,
889 sizeof( tSetBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700890
891 // Update the WDA_SET_BSSKEY_REQ parameters
892 pSetBssKeyParams->bssIdx = psessionEntry->bssIdx;
893 pSetBssKeyParams->encType = pMlmSetKeysReq->edType;
Jeff Johnsone7245742012-09-05 17:12:55 -0700894
Jeff Johnson295189b2012-06-20 16:38:30 -0700895
896 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
897 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700898 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700899 }
900
901 pSetBssKeyParams->singleTidRc = (tANI_U8)val;
902
903 /* Update PE session Id*/
904 pSetBssKeyParams->sessionId = psessionEntry ->peSessionId;
905
Jeff Johnsone7245742012-09-05 17:12:55 -0700906 if(pMlmSetKeysReq->key[0].keyId &&
907 ((pMlmSetKeysReq->edType == eSIR_ED_WEP40) ||
908 (pMlmSetKeysReq->edType == eSIR_ED_WEP104))
909 )
910 {
911 /* IF the key id is non-zero and encryption type is WEP, Send all the 4
912 * keys to HAL with filling the key at right index in pSetBssKeyParams->key. */
913 pSetBssKeyParams->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530914 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key[pMlmSetKeysReq->key[0].keyId],
915 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof(pMlmSetKeysReq->key[0]));
Jeff Johnsone7245742012-09-05 17:12:55 -0700916
917 }
918 else
919 {
920 pSetBssKeyParams->numKeys = pMlmSetKeysReq->numKeys;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530921 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key,
922 (tANI_U8 *) &pMlmSetKeysReq->key,
923 sizeof( tSirKeys ) * pMlmSetKeysReq->numKeys );
Jeff Johnsone7245742012-09-05 17:12:55 -0700924 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700925
926 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
927 msgQ.type = WDA_SET_BSSKEY_REQ;
928 //
929 // FIXME_GEN4
930 // A global counter (dialog token) is required to keep track of
931 // all PE <-> HAL communication(s)
932 //
933 msgQ.reserved = 0;
934 msgQ.bodyptr = pSetBssKeyParams;
935 msgQ.bodyval = 0;
936
937 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700938 FL( "Sending WDA_SET_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -0700939 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -0700940 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
941 {
942 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700943 FL("Posting SET_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700944 retCode );
945
946 // Respond to SME with LIM_MLM_SETKEYS_CNF
947 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
948 }
949 else
950 return; // Continue after WDA_SET_BSSKEY_RSP...
951
952end:
953 limPostSmeSetKeysCnf( pMac,
954 pMlmSetKeysReq,
955 &mlmSetKeysCnf );
956
957}
958
959/**
960 * @function : limSendSetStaKeyReq()
961 *
962 * @brief : This function is called from limProcessMlmSetKeysReq(),
963 * when PE is trying to setup the Unicast Keys related
964 * to a specified STA with specified encryption type
965 *
966 *LOGIC:
967 *
968 *ASSUMPTIONS:
969 * NA
970 *
971 *NOTE:
972 * NA
973 *
974 * @param pMac Pointer to Global MAC structure
975 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
976 * @param staIdx STA index for which the keys are being set
977 * @param defWEPIdx The default WEP key index [0..3]
978 * @return none
979 */
980void limSendSetStaKeyReq( tpAniSirGlobal pMac,
981 tLimMlmSetKeysReq *pMlmSetKeysReq,
982 tANI_U16 staIdx,
983 tANI_U8 defWEPIdx,
984 tpPESession sessionEntry)
985{
986tSirMsgQ msgQ;
987tpSetStaKeyParams pSetStaKeyParams = NULL;
988tLimMlmSetKeysCnf mlmSetKeysCnf;
989tSirRetStatus retCode;
990tANI_U32 val = 0;
991
992 // Package WDA_SET_STAKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530993 pSetStaKeyParams = vos_mem_malloc(sizeof( tSetStaKeyParams ));
994 if ( NULL == pSetStaKeyParams )
995 {
996 limLog( pMac, LOGP, FL( "Unable to allocate memory during SET_BSSKEY" ));
997 return;
998 }
999 else
1000 vos_mem_set( (void *) pSetStaKeyParams, sizeof( tSetStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001001
1002 // Update the WDA_SET_STAKEY_REQ parameters
1003 pSetStaKeyParams->staIdx = staIdx;
1004 pSetStaKeyParams->encType = pMlmSetKeysReq->edType;
1005
1006
1007 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
1008 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001009 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001010 }
1011
1012 pSetStaKeyParams->singleTidRc = (tANI_U8)val;
1013
1014 /* Update PE session ID*/
1015 pSetStaKeyParams->sessionId = sessionEntry->peSessionId;
1016
1017 /**
1018 * For WEP - defWEPIdx indicates the default WEP
1019 * Key to be used for TX
1020 * For all others, there's just one key that can
1021 * be used and hence it is assumed that
1022 * defWEPIdx = 0 (from the caller)
1023 */
1024
1025 pSetStaKeyParams->defWEPIdx = defWEPIdx;
1026
1027 /** Store the Previous MlmState*/
1028 sessionEntry->limPrevMlmState = sessionEntry->limMlmState;
1029 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1030
1031 if(sessionEntry->limSystemRole == eLIM_STA_IN_IBSS_ROLE && !pMlmSetKeysReq->key[0].unicast) {
1032 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_BCASTKEY_STATE;
1033 msgQ.type = WDA_SET_STA_BCASTKEY_REQ;
1034 }else {
1035 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
1036 msgQ.type = WDA_SET_STAKEY_REQ;
1037 }
Jeff Johnsone7245742012-09-05 17:12:55 -07001038 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001039
1040 /**
1041 * In the Case of WEP_DYNAMIC, ED_TKIP and ED_CCMP
1042 * the Key[0] contains the KEY, so just copy that alone,
1043 * for the case of WEP_STATIC the hal gets the key from cfg
1044 */
1045 switch( pMlmSetKeysReq->edType ) {
1046 case eSIR_ED_WEP40:
1047 case eSIR_ED_WEP104:
1048 // FIXME! Is this OK?
1049 if( 0 == pMlmSetKeysReq->numKeys ) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001050 tANI_U32 i;
1051
1052 for(i=0; i < SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS ;i++)
1053 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301054 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key[i],
1055 (tANI_U8 *) &pMlmSetKeysReq->key[i], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001056 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001057 pSetStaKeyParams->wepType = eSIR_WEP_STATIC;
1058 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
Jeff Johnsone7245742012-09-05 17:12:55 -07001059 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001060 }else {
Jeff Johnsone7245742012-09-05 17:12:55 -07001061 /*This case the keys are coming from upper layer so need to fill the
1062 * key at the default wep key index and send to the HAL */
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301063 if (defWEPIdx >= SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
1064 {
1065 limLog( pMac, LOGE, FL("WEPIdx length %d more than "
1066 "the Max limit, reset to Max"),defWEPIdx);
Mukul Sharmad2b81862014-07-01 21:01:04 +05301067 vos_mem_free (pSetStaKeyParams);
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301068 return;
1069 }
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301070 vos_mem_copy((tANI_U8 *) &pSetStaKeyParams->key[defWEPIdx],
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301071 (tANI_U8 *) &pMlmSetKeysReq->key[0],
1072 sizeof( pMlmSetKeysReq->key[0] ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001073 pMlmSetKeysReq->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301074
Jeff Johnson295189b2012-06-20 16:38:30 -07001075 }
1076 break;
1077 case eSIR_ED_TKIP:
1078 case eSIR_ED_CCMP:
1079#ifdef FEATURE_WLAN_WAPI
1080 case eSIR_ED_WPI:
1081#endif
1082 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301083 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key,
1084 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001085 }
1086 break;
1087 default:
1088 break;
1089 }
1090
1091
1092 //
1093 // FIXME_GEN4
1094 // A global counter (dialog token) is required to keep track of
1095 // all PE <-> HAL communication(s)
1096 //
1097 msgQ.reserved = 0;
1098 msgQ.bodyptr = pSetStaKeyParams;
1099 msgQ.bodyval = 0;
1100
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001101 limLog( pMac, LOG1, FL( "Sending WDA_SET_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001102 MTRACE(macTraceMsgTx(pMac, sessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001103 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ ))) {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001104 limLog( pMac, LOGE, FL("Posting SET_STAKEY to HAL failed, reason=%X"), retCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07001105 // Respond to SME with LIM_MLM_SETKEYS_CNF
1106 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1107 }else
1108 return; // Continue after WDA_SET_STAKEY_RSP...
1109
1110 limPostSmeSetKeysCnf( pMac, pMlmSetKeysReq, &mlmSetKeysCnf );
1111}
1112
1113/**
1114 * limSendRemoveBssKeyReq()
1115 *
1116 *FUNCTION:
1117 * This function is called from limProcessMlmRemoveReq(),
1118 * when PE is trying to Remove a Group Key related
1119 * to a specified encryption type
1120 *
1121 *LOGIC:
1122 *
1123 *ASSUMPTIONS:
1124 * NA
1125 *
1126 *NOTE:
1127 * NA
1128 *
1129 * @param pMac Pointer to Global MAC structure
1130 * @param pMlmRemoveKeyReq Pointer to MLM_REMOVEKEY_REQ buffer
1131 * @return none
1132 */
1133void limSendRemoveBssKeyReq( tpAniSirGlobal pMac,
1134 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
1135 tpPESession psessionEntry)
1136{
1137tSirMsgQ msgQ;
1138tpRemoveBssKeyParams pRemoveBssKeyParams = NULL;
1139tLimMlmRemoveKeyCnf mlmRemoveKeysCnf;
1140tSirRetStatus retCode;
1141
1142 // Package WDA_REMOVE_BSSKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301143 pRemoveBssKeyParams = vos_mem_malloc(sizeof( tRemoveBssKeyParams ));
1144 if ( NULL == pRemoveBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001145 {
1146 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301147 FL( "Unable to allocate memory during REMOVE_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001148
1149 // Respond to SME with error code
1150 mlmRemoveKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1151 goto end;
1152 }
1153 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301154 vos_mem_set( (void *) pRemoveBssKeyParams,
1155 sizeof( tRemoveBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001156
1157 // Update the WDA_REMOVE_BSSKEY_REQ parameters
1158 pRemoveBssKeyParams->bssIdx = psessionEntry->bssIdx;
1159 pRemoveBssKeyParams->encType = pMlmRemoveKeyReq->edType;
1160 pRemoveBssKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1161 pRemoveBssKeyParams->wepType = pMlmRemoveKeyReq->wepType;
1162
1163 /* Update PE session Id*/
1164
1165 pRemoveBssKeyParams->sessionId = psessionEntry->peSessionId;
1166
1167 msgQ.type = WDA_REMOVE_BSSKEY_REQ;
1168 //
1169 // FIXME_GEN4
1170 // A global counter (dialog token) is required to keep track of
1171 // all PE <-> HAL communication(s)
1172 //
1173 msgQ.reserved = 0;
1174 msgQ.bodyptr = pRemoveBssKeyParams;
1175 msgQ.bodyval = 0;
1176
1177 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001178 FL( "Sending WDA_REMOVE_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001179 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001180
1181 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1182 {
1183 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001184 FL("Posting REMOVE_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001185 retCode );
1186
1187 // Respond to SME with LIM_MLM_REMOVEKEYS_CNF
1188 mlmRemoveKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1189 }
1190 else
1191 return;
1192
1193end:
1194 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001195 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001196 pMlmRemoveKeyReq,
1197 &mlmRemoveKeysCnf );
1198
1199}
1200
1201/**
1202 * limSendRemoveStaKeyReq()
1203 *
1204 *FUNCTION:
1205 * This function is called from limProcessMlmRemoveKeysReq(),
1206 * when PE is trying to setup the Unicast Keys related
1207 * to a specified STA with specified encryption type
1208 *
1209 *LOGIC:
1210 *
1211 *ASSUMPTIONS:
1212 * NA
1213 *
1214 *NOTE:
1215 * NA
1216 *
1217 * @param pMac Pointer to Global MAC structure
1218 * @param pMlmRemoveKeysReq Pointer to MLM_REMOVEKEYS_REQ buffer
1219 * @param staIdx STA index for which the keys are being set
1220 * @return none
1221 */
1222void limSendRemoveStaKeyReq( tpAniSirGlobal pMac,
1223 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301224 tANI_U16 staIdx,
Jeff Johnsone7245742012-09-05 17:12:55 -07001225 tpPESession psessionEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07001226{
1227tSirMsgQ msgQ;
1228tpRemoveStaKeyParams pRemoveStaKeyParams = NULL;
1229tLimMlmRemoveKeyCnf mlmRemoveKeyCnf;
1230tSirRetStatus retCode;
1231
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301232 pRemoveStaKeyParams = vos_mem_malloc(sizeof( tRemoveStaKeyParams ));
1233 if ( NULL == pRemoveStaKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001234 {
1235 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301236 FL( "Unable to allocate memory during REMOVE_STAKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001237
1238 // Respond to SME with error code
1239 mlmRemoveKeyCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1240 goto end;
1241 }
1242 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301243 vos_mem_set( (void *) pRemoveStaKeyParams,
1244 sizeof( tRemoveStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001245
1246 if( (pMlmRemoveKeyReq->edType == eSIR_ED_WEP104 || pMlmRemoveKeyReq->edType == eSIR_ED_WEP40) &&
1247 pMlmRemoveKeyReq->wepType == eSIR_WEP_STATIC )
1248 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001249 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 -07001250 mlmRemoveKeyCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
1251 goto end;
1252 }
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001253
Jeff Johnson295189b2012-06-20 16:38:30 -07001254 // Update the WDA_REMOVEKEY_REQ parameters
1255 pRemoveStaKeyParams->staIdx = staIdx;
1256 pRemoveStaKeyParams->encType = pMlmRemoveKeyReq->edType;
1257 pRemoveStaKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1258 pRemoveStaKeyParams->unicast = pMlmRemoveKeyReq->unicast;
1259
1260 /* Update PE session ID*/
Jeff Johnsone7245742012-09-05 17:12:55 -07001261 pRemoveStaKeyParams->sessionId = psessionEntry->peSessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001262
1263 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001264
Jeff Johnson295189b2012-06-20 16:38:30 -07001265 msgQ.type = WDA_REMOVE_STAKEY_REQ;
1266 //
1267 // FIXME_GEN4
1268 // A global counter (dialog token) is required to keep track of
1269 // all PE <-> HAL communication(s)
1270 //
1271 msgQ.reserved = 0;
1272 msgQ.bodyptr = pRemoveStaKeyParams;
1273 msgQ.bodyval = 0;
1274
1275 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001276 FL( "Sending WDA_REMOVE_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001277 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001278 retCode = wdaPostCtrlMsg( pMac, &msgQ );
1279 if (eSIR_SUCCESS != retCode)
Jeff Johnson295189b2012-06-20 16:38:30 -07001280 {
1281 limLog( pMac, LOGE,
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001282 FL("Posting REMOVE_STAKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001283 retCode );
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301284 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001285 pRemoveStaKeyParams = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07001286
1287 // Respond to SME with LIM_MLM_REMOVEKEY_CNF
1288 mlmRemoveKeyCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1289 }
1290 else
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001291 return;
Jeff Johnson295189b2012-06-20 16:38:30 -07001292
1293end:
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001294 if (pRemoveStaKeyParams)
1295 {
Kiet Lam842c3e12013-11-16 22:40:57 +05301296 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001297 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001298 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001299 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001300 pMlmRemoveKeyReq,
1301 &mlmRemoveKeyCnf );
1302
1303}
1304
1305