blob: 1867a1c570fb3719c941da5a9276cabc6e59a5dc [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Edhar, Mahesh Kumar0d82c212015-02-03 17:47:16 +05302 * Copyright (c) 2013-2015 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"
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
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,
436 FL(" Release data entry:%p idx %d peer: " MAC_ADDRESS_STR),
437 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,
458 FL("Release data entry: %p id %d peer: "MAC_ADDRESS_STR),
459 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
476
Jeff Johnson295189b2012-06-20 16:38:30 -0700477
478
479
480/**
481 * limRestoreFromPreAuthState
482 *
483 *FUNCTION:
484 * This function is called on STA whenever an Authentication
485 * sequence is complete and state prior to auth need to be
486 * restored.
487 *
488 *LOGIC:
489 * MLM_AUTH_CNF is prepared and sent to SME state machine.
490 * In case of restoring from pre-auth:
491 * - Channel Id is programmed at LO/RF synthesizer
492 * - BSSID is programmed at RHP
493 *
494 *ASSUMPTIONS:
495 *
496 *NOTE:
497 *
498 * @param pMac - Pointer to Global MAC structure
499 * @param resultCode - result of authentication attempt
500 * @return None
501 */
502
503void
504limRestoreFromAuthState(tpAniSirGlobal pMac, tSirResultCodes resultCode, tANI_U16 protStatusCode,tpPESession sessionEntry)
505{
506 tSirMacAddr currentBssId;
507 tLimMlmAuthCnf mlmAuthCnf;
508
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530509 vos_mem_copy( (tANI_U8 *) &mlmAuthCnf.peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700510 (tANI_U8 *) &pMac->lim.gpLimMlmAuthReq->peerMacAddr,
511 sizeof(tSirMacAddr));
512 mlmAuthCnf.authType = pMac->lim.gpLimMlmAuthReq->authType;
513 mlmAuthCnf.resultCode = resultCode;
514 mlmAuthCnf.protStatusCode = protStatusCode;
515
516 /* Update PE session ID*/
517 mlmAuthCnf.sessionId = sessionEntry->peSessionId;
518
519 /// Free up buffer allocated
520 /// for pMac->lim.gLimMlmAuthReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530521 vos_mem_free(pMac->lim.gpLimMlmAuthReq);
Jeff Johnson295189b2012-06-20 16:38:30 -0700522 pMac->lim.gpLimMlmAuthReq = NULL;
523
524 sessionEntry->limMlmState = sessionEntry->limPrevMlmState;
525
Jeff Johnsone7245742012-09-05 17:12:55 -0700526 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -0700527
528
529 // 'Change' timer for future activations
530 limDeactivateAndChangeTimer(pMac, eLIM_AUTH_FAIL_TIMER);
531
532 #if 0
533 if (wlan_cfgGetStr(pMac, WNI_CFG_BSSID, currentBssId, &cfg) != eSIR_SUCCESS)
534 {
535 /// Could not get BSSID from CFG. Log error.
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700536 limLog(pMac, LOGP, FL("could not retrieve BSSID"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700537 }
538 #endif //TO SUPPORT BT-AMP
539 sirCopyMacAddr(currentBssId,sessionEntry->bssId);
540
541 if (sessionEntry->limSmeState == eLIM_SME_WT_PRE_AUTH_STATE)
542 {
543 pMac->lim.gLimPreAuthChannelNumber = 0;
544 }
545
546 limPostSmeMessage(pMac,
547 LIM_MLM_AUTH_CNF,
548 (tANI_U32 *) &mlmAuthCnf);
549} /*** end limRestoreFromAuthState() ***/
550
551
552
553/**
554 * limLookUpKeyMappings()
555 *
556 *FUNCTION:
557 * This function is called in limProcessAuthFrame() function
558 * to determine if there exists a Key Mapping key for a given
559 * MAC address.
560 *
561 *LOGIC:
562 *
563 *ASSUMPTIONS:
564 * NA
565 *
566 *NOTE:
567 * NA
568 *
569 * @param macAddr MAC address of the peer STA for which existence
570 * of Key Mapping key is to be determined
571 *
572 * @return pKeyMapEntry - Pointer to the keyMapEntry returned by CFG
573 */
574
575tCfgWepKeyEntry *
576limLookUpKeyMappings(tSirMacAddr macAddr)
577{
578 return NULL;
579} /****** end limLookUpKeyMappings() ******/
580
581
582
583/**
584 * limEncryptAuthFrame()
585 *
586 *FUNCTION:
587 * This function is called in limProcessAuthFrame() function
588 * to encrypt Authentication frame3 body.
589 *
590 *LOGIC:
591 *
592 *ASSUMPTIONS:
593 * NA
594 *
595 *NOTE:
596 * NA
597 *
598 * @param pMac Pointer to Global MAC structure
599 * @param keyId key id to used
600 * @param pKey Pointer to the key to be used for encryption
601 * @param pPlainText Pointer to the body to be encrypted
602 * @param pEncrBody Pointer to the encrypted auth frame body
603 * @param keyLength 8 (WEP40) or 16 (WEP104)
604 * @return None
605 */
606
607void
608limEncryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 keyId, tANI_U8 *pKey, tANI_U8 *pPlainText,
609 tANI_U8 *pEncrBody, tANI_U32 keyLength)
610{
611 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
612
613 keyLength += 3;
614
615 // Bytes 0-2 of seed is IV
616 // Read TSF timestamp into seed to get random IV - 1st 3 bytes
617 halGetTxTSFtimer(pMac, (tSirMacTimeStamp *) &seed);
618
619 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530620 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700621
622 // Compute CRC-32 and place them in last 4 bytes of plain text
623 limComputeCrc32(icv, pPlainText, sizeof(tSirMacAuthFrameBody));
624
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530625 vos_mem_copy( pPlainText + sizeof(tSirMacAuthFrameBody),
Jeff Johnson295189b2012-06-20 16:38:30 -0700626 icv, SIR_MAC_WEP_ICV_LENGTH);
627
628 // Run RC4 on plain text with the seed
629 limRC4(pEncrBody + SIR_MAC_WEP_IV_LENGTH,
630 (tANI_U8 *) pPlainText, seed, keyLength,
631 LIM_ENCR_AUTH_BODY_LEN - SIR_MAC_WEP_IV_LENGTH);
632
633 // Prepare IV
634 pEncrBody[0] = seed[0];
635 pEncrBody[1] = seed[1];
636 pEncrBody[2] = seed[2];
637 pEncrBody[3] = keyId << 6;
638} /****** end limEncryptAuthFrame() ******/
639
640
641
642/**
643 * limComputeCrc32()
644 *
645 *FUNCTION:
646 * This function is called to compute CRC-32 on a given source.
647 * Used while encrypting/decrypting Authentication frame 3.
648 *
649 *LOGIC:
650 *
651 *ASSUMPTIONS:
652 * NA
653 *
654 *NOTE:
655 * NA
656 *
657 * @param pDest Destination location for computed CRC
658 * @param pSrc Source location to be CRC computed
659 * @param len Length over which CRC to be computed
660 * @return None
661 */
662
663void
664limComputeCrc32(tANI_U8 *pDest, tANI_U8 * pSrc, tANI_U8 len)
665{
666 tANI_U32 crc;
667 int i;
668
669 crc = 0;
670 crc = ~crc;
671
672 while(len-- > 0)
673 crc = limCrcUpdate(crc, *pSrc++);
674
675 crc = ~crc;
676
677 for (i=0; i < SIR_MAC_WEP_IV_LENGTH; i++)
678 {
679 pDest[i] = (tANI_U8)crc;
680 crc >>= 8;
681 }
682} /****** end limComputeCrc32() ******/
683
684
685
686/**
687 * limRC4()
688 *
689 *FUNCTION:
690 * This function is called to run RC4 algorithm. Called while
691 * encrypting/decrypting Authentication frame 3.
692 *
693 *LOGIC:
694 *
695 *ASSUMPTIONS:
696 * NA
697 *
698 *NOTE:
699 * NA
700 *
701 * @param pDest Destination location for encrypted text
702 * @param pSrc Source location to be encrypted
703 * @param seed Contains seed (IV + key) for PRNG
704 * @param keyLength 8 (WEP40) or 16 (WEP104)
705 * @param frameLen Length of the frame
706 *
707 * @return None
708 */
709
710void
711limRC4(tANI_U8 *pDest, tANI_U8 *pSrc, tANI_U8 *seed, tANI_U32 keyLength, tANI_U16 frameLen)
712{
713 typedef struct
714 {
715 tANI_U8 i, j;
716 tANI_U8 sbox[256];
717 } tRC4Context;
718
719 tRC4Context ctx;
720
721 {
722 tANI_U16 i, j, k;
723
724 //
725 // Initialize sbox using seed
726 //
727
728 ctx.i = ctx.j = 0;
729 for (i=0; i<256; i++)
730 ctx.sbox[i] = (tANI_U8)i;
731
732 j = 0;
733 k = 0;
734 for (i=0; i<256; i++)
735 {
736 tANI_U8 temp;
Kiran Kumar Lokerea4db3dc2013-03-25 18:05:24 -0700737 if ( k < LIM_SEED_LENGTH )
738 j = (tANI_U8)(j + ctx.sbox[i] + seed[k]);
Jeff Johnson295189b2012-06-20 16:38:30 -0700739 temp = ctx.sbox[i];
740 ctx.sbox[i] = ctx.sbox[j];
741 ctx.sbox[j] = temp;
742
743 if (++k >= keyLength)
744 k = 0;
745 }
746 }
747
748 {
749 tANI_U8 i = ctx.i;
750 tANI_U8 j = ctx.j;
751 tANI_U8 len = (tANI_U8) frameLen;
752
753 while (len-- > 0)
754 {
755 tANI_U8 temp1, temp2;
756
757 i = (tANI_U8)(i+1);
758 temp1 = ctx.sbox[i];
759 j = (tANI_U8)(j + temp1);
760
761 ctx.sbox[i] = temp2 = ctx.sbox[j];
762 ctx.sbox[j] = temp1;
763
764 temp1 = (tANI_U8)(temp1 + temp2);
765 temp1 = ctx.sbox[temp1];
766 temp2 = (tANI_U8)(pSrc ? *pSrc++ : 0);
767
768 *pDest++ = (tANI_U8)(temp1 ^ temp2);
769 }
770
771 ctx.i = i;
772 ctx.j = j;
773 }
774} /****** end limRC4() ******/
775
776
777
778/**
779 * limDecryptAuthFrame()
780 *
781 *FUNCTION:
782 * This function is called in limProcessAuthFrame() function
783 * to decrypt received Authentication frame3 body.
784 *
785 *LOGIC:
786 *
787 *ASSUMPTIONS:
788 * NA
789 *
790 *NOTE:
791 * NA
792 *
793 * @param pMac Pointer to Global MAC structure
794 * @param pKey Pointer to the key to be used for decryption
795 * @param pEncrBody Pointer to the body to be decrypted
796 * @param pPlainBody Pointer to the decrypted body
797 * @param keyLength 8 (WEP40) or 16 (WEP104)
798 *
799 * @return Decrypt result - eSIR_SUCCESS for success and
800 * LIM_DECRYPT_ICV_FAIL for ICV mismatch.
801 * If decryption is a success, pBody will
802 * have decrypted auth frame body.
803 */
804
805tANI_U8
806limDecryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 *pKey, tANI_U8 *pEncrBody,
807 tANI_U8 *pPlainBody, tANI_U32 keyLength, tANI_U16 frameLen)
808{
809 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
810 int i;
811 keyLength += 3;
812
813
814 // Bytes 0-2 of seed is received IV
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530815 vos_mem_copy((tANI_U8 *) seed, pEncrBody, SIR_MAC_WEP_IV_LENGTH - 1);
Jeff Johnson295189b2012-06-20 16:38:30 -0700816
817 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530818 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700819
820 // Run RC4 on encrypted text with the seed
821 limRC4(pPlainBody,
822 pEncrBody + SIR_MAC_WEP_IV_LENGTH,
823 seed,
824 keyLength,
825 frameLen);
826
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700827 PELOG4(limLog(pMac, LOG4, FL("plainbody is "));
Jeff Johnson295189b2012-06-20 16:38:30 -0700828 sirDumpBuf(pMac, SIR_LIM_MODULE_ID, LOG4, pPlainBody, frameLen);)
829
830 // Compute CRC-32 and place them in last 4 bytes of encrypted body
831 limComputeCrc32(icv,
832 (tANI_U8 *) pPlainBody,
833 (tANI_U8) (frameLen - SIR_MAC_WEP_ICV_LENGTH));
834
835 // Compare RX_ICV with computed ICV
836 for (i = 0; i < SIR_MAC_WEP_ICV_LENGTH; i++)
837 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700838 PELOG4(limLog(pMac, LOG4, FL(" computed ICV%d[%x], rxed ICV%d[%x]"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700839 i, icv[i], i, pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i]);)
840 if (icv[i] != pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i])
841 return LIM_DECRYPT_ICV_FAIL;
842 }
843
844 return eSIR_SUCCESS;
845} /****** end limDecryptAuthFrame() ******/
846
847/**
848 * limPostSmeSetKeysCnf
849 *
850 * A utility API to send MLM_SETKEYS_CNF to SME
851 */
852void limPostSmeSetKeysCnf( tpAniSirGlobal pMac,
853 tLimMlmSetKeysReq *pMlmSetKeysReq,
854 tLimMlmSetKeysCnf *mlmSetKeysCnf)
855{
856 // Prepare and Send LIM_MLM_SETKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530857 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700858 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
859 sizeof(tSirMacAddr));
860
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530861 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700862 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
863 sizeof(tSirMacAddr));
864
Jeff Johnson295189b2012-06-20 16:38:30 -0700865
866 /// Free up buffer allocated for mlmSetKeysReq
Vinay Krishna Eranna6f22c1f2014-10-13 16:03:06 +0530867 vos_mem_zero(pMlmSetKeysReq, sizeof(tLimMlmSetKeysReq));
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530868 vos_mem_free( pMlmSetKeysReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700869 pMac->lim.gpLimMlmSetKeysReq = NULL;
870
871 limPostSmeMessage( pMac,
872 LIM_MLM_SETKEYS_CNF,
873 (tANI_U32 *) mlmSetKeysCnf );
874}
875
876/**
877 * limPostSmeRemoveKeysCnf
878 *
879 * A utility API to send MLM_REMOVEKEY_CNF to SME
880 */
881void limPostSmeRemoveKeyCnf( tpAniSirGlobal pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -0700882 tpPESession psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -0700883 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
884 tLimMlmRemoveKeyCnf *mlmRemoveKeyCnf)
885{
886 // Prepare and Send LIM_MLM_REMOVEKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530887 vos_mem_copy( (tANI_U8 *) &mlmRemoveKeyCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700888 (tANI_U8 *) pMlmRemoveKeyReq->peerMacAddr,
889 sizeof(tSirMacAddr));
890
891 /// Free up buffer allocated for mlmRemoveKeysReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530892 vos_mem_free( pMlmRemoveKeyReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700893 pMac->lim.gpLimMlmRemoveKeyReq = NULL;
894
Jeff Johnsone7245742012-09-05 17:12:55 -0700895 psessionEntry->limMlmState = psessionEntry->limPrevMlmState; //Restore the state.
896 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, psessionEntry->peSessionId, psessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -0700897
898 limPostSmeMessage( pMac,
899 LIM_MLM_REMOVEKEY_CNF,
900 (tANI_U32 *) mlmRemoveKeyCnf );
901}
902
903/**
904 * limSendSetBssKeyReq()
905 *
906 *FUNCTION:
907 * This function is called from limProcessMlmSetKeysReq(),
908 * when PE is trying to setup the Group Keys related
909 * to a specified encryption type
910 *
911 *LOGIC:
912 *
913 *ASSUMPTIONS:
914 * NA
915 *
916 *NOTE:
917 * NA
918 *
919 * @param pMac Pointer to Global MAC structure
920 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
921 * @return none
922 */
923void limSendSetBssKeyReq( tpAniSirGlobal pMac,
924 tLimMlmSetKeysReq *pMlmSetKeysReq,
925 tpPESession psessionEntry)
926{
927tSirMsgQ msgQ;
928tpSetBssKeyParams pSetBssKeyParams = NULL;
929tLimMlmSetKeysCnf mlmSetKeysCnf;
930tSirRetStatus retCode;
931tANI_U32 val = 0;
932
933 if(pMlmSetKeysReq->numKeys > SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
934 {
935 limLog( pMac, LOG1,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700936 FL( "numKeys = %d is more than SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS" ), pMlmSetKeysReq->numKeys);
Jeff Johnson295189b2012-06-20 16:38:30 -0700937
938 // Respond to SME with error code
939 mlmSetKeysCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
940 goto end;
941 }
942
943 // Package WDA_SET_BSSKEY_REQ message parameters
944
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530945 pSetBssKeyParams = vos_mem_malloc(sizeof( tSetBssKeyParams ));
946 if ( NULL == pSetBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -0700947 {
948 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530949 FL( "Unable to allocate memory during SET_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700950
951 // Respond to SME with error code
952 mlmSetKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
953 goto end;
954 }
955 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530956 vos_mem_set( (void *) pSetBssKeyParams,
957 sizeof( tSetBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700958
959 // Update the WDA_SET_BSSKEY_REQ parameters
960 pSetBssKeyParams->bssIdx = psessionEntry->bssIdx;
961 pSetBssKeyParams->encType = pMlmSetKeysReq->edType;
Jeff Johnsone7245742012-09-05 17:12:55 -0700962
Jeff Johnson295189b2012-06-20 16:38:30 -0700963
964 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
965 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700966 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700967 }
968
969 pSetBssKeyParams->singleTidRc = (tANI_U8)val;
970
971 /* Update PE session Id*/
972 pSetBssKeyParams->sessionId = psessionEntry ->peSessionId;
973
Jeff Johnsone7245742012-09-05 17:12:55 -0700974 if(pMlmSetKeysReq->key[0].keyId &&
975 ((pMlmSetKeysReq->edType == eSIR_ED_WEP40) ||
976 (pMlmSetKeysReq->edType == eSIR_ED_WEP104))
977 )
978 {
979 /* IF the key id is non-zero and encryption type is WEP, Send all the 4
980 * keys to HAL with filling the key at right index in pSetBssKeyParams->key. */
981 pSetBssKeyParams->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530982 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key[pMlmSetKeysReq->key[0].keyId],
983 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof(pMlmSetKeysReq->key[0]));
Jeff Johnsone7245742012-09-05 17:12:55 -0700984
985 }
986 else
987 {
988 pSetBssKeyParams->numKeys = pMlmSetKeysReq->numKeys;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530989 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key,
990 (tANI_U8 *) &pMlmSetKeysReq->key,
991 sizeof( tSirKeys ) * pMlmSetKeysReq->numKeys );
Jeff Johnsone7245742012-09-05 17:12:55 -0700992 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700993
994 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
995 msgQ.type = WDA_SET_BSSKEY_REQ;
996 //
997 // FIXME_GEN4
998 // A global counter (dialog token) is required to keep track of
999 // all PE <-> HAL communication(s)
1000 //
1001 msgQ.reserved = 0;
1002 msgQ.bodyptr = pSetBssKeyParams;
1003 msgQ.bodyval = 0;
1004
1005 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001006 FL( "Sending WDA_SET_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001007 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001008 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1009 {
1010 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001011 FL("Posting SET_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001012 retCode );
1013
1014 // Respond to SME with LIM_MLM_SETKEYS_CNF
1015 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1016 }
1017 else
1018 return; // Continue after WDA_SET_BSSKEY_RSP...
1019
1020end:
1021 limPostSmeSetKeysCnf( pMac,
1022 pMlmSetKeysReq,
1023 &mlmSetKeysCnf );
1024
1025}
1026
1027/**
1028 * @function : limSendSetStaKeyReq()
1029 *
1030 * @brief : This function is called from limProcessMlmSetKeysReq(),
1031 * when PE is trying to setup the Unicast Keys related
1032 * to a specified STA with specified encryption type
1033 *
1034 *LOGIC:
1035 *
1036 *ASSUMPTIONS:
1037 * NA
1038 *
1039 *NOTE:
1040 * NA
1041 *
1042 * @param pMac Pointer to Global MAC structure
1043 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
1044 * @param staIdx STA index for which the keys are being set
1045 * @param defWEPIdx The default WEP key index [0..3]
1046 * @return none
1047 */
1048void limSendSetStaKeyReq( tpAniSirGlobal pMac,
1049 tLimMlmSetKeysReq *pMlmSetKeysReq,
1050 tANI_U16 staIdx,
1051 tANI_U8 defWEPIdx,
1052 tpPESession sessionEntry)
1053{
1054tSirMsgQ msgQ;
1055tpSetStaKeyParams pSetStaKeyParams = NULL;
1056tLimMlmSetKeysCnf mlmSetKeysCnf;
1057tSirRetStatus retCode;
1058tANI_U32 val = 0;
1059
1060 // Package WDA_SET_STAKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301061 pSetStaKeyParams = vos_mem_malloc(sizeof( tSetStaKeyParams ));
1062 if ( NULL == pSetStaKeyParams )
1063 {
1064 limLog( pMac, LOGP, FL( "Unable to allocate memory during SET_BSSKEY" ));
1065 return;
1066 }
1067 else
1068 vos_mem_set( (void *) pSetStaKeyParams, sizeof( tSetStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001069
1070 // Update the WDA_SET_STAKEY_REQ parameters
1071 pSetStaKeyParams->staIdx = staIdx;
1072 pSetStaKeyParams->encType = pMlmSetKeysReq->edType;
1073
1074
1075 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
1076 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001077 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001078 }
1079
1080 pSetStaKeyParams->singleTidRc = (tANI_U8)val;
1081
1082 /* Update PE session ID*/
1083 pSetStaKeyParams->sessionId = sessionEntry->peSessionId;
1084
1085 /**
1086 * For WEP - defWEPIdx indicates the default WEP
1087 * Key to be used for TX
1088 * For all others, there's just one key that can
1089 * be used and hence it is assumed that
1090 * defWEPIdx = 0 (from the caller)
1091 */
1092
1093 pSetStaKeyParams->defWEPIdx = defWEPIdx;
1094
1095 /** Store the Previous MlmState*/
1096 sessionEntry->limPrevMlmState = sessionEntry->limMlmState;
1097 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1098
1099 if(sessionEntry->limSystemRole == eLIM_STA_IN_IBSS_ROLE && !pMlmSetKeysReq->key[0].unicast) {
1100 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_BCASTKEY_STATE;
1101 msgQ.type = WDA_SET_STA_BCASTKEY_REQ;
1102 }else {
1103 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
1104 msgQ.type = WDA_SET_STAKEY_REQ;
1105 }
Jeff Johnsone7245742012-09-05 17:12:55 -07001106 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001107
1108 /**
1109 * In the Case of WEP_DYNAMIC, ED_TKIP and ED_CCMP
1110 * the Key[0] contains the KEY, so just copy that alone,
1111 * for the case of WEP_STATIC the hal gets the key from cfg
1112 */
1113 switch( pMlmSetKeysReq->edType ) {
1114 case eSIR_ED_WEP40:
1115 case eSIR_ED_WEP104:
1116 // FIXME! Is this OK?
1117 if( 0 == pMlmSetKeysReq->numKeys ) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001118 tANI_U32 i;
1119
1120 for(i=0; i < SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS ;i++)
1121 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301122 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key[i],
1123 (tANI_U8 *) &pMlmSetKeysReq->key[i], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001124 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001125 pSetStaKeyParams->wepType = eSIR_WEP_STATIC;
1126 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
Jeff Johnsone7245742012-09-05 17:12:55 -07001127 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001128 }else {
Jeff Johnsone7245742012-09-05 17:12:55 -07001129 /*This case the keys are coming from upper layer so need to fill the
1130 * key at the default wep key index and send to the HAL */
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301131 if (defWEPIdx >= SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
1132 {
1133 limLog( pMac, LOGE, FL("WEPIdx length %d more than "
1134 "the Max limit, reset to Max"),defWEPIdx);
Mukul Sharmad2b81862014-07-01 21:01:04 +05301135 vos_mem_free (pSetStaKeyParams);
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301136 return;
1137 }
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301138 vos_mem_copy((tANI_U8 *) &pSetStaKeyParams->key[defWEPIdx],
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301139 (tANI_U8 *) &pMlmSetKeysReq->key[0],
1140 sizeof( pMlmSetKeysReq->key[0] ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001141 pMlmSetKeysReq->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301142
Jeff Johnson295189b2012-06-20 16:38:30 -07001143 }
1144 break;
1145 case eSIR_ED_TKIP:
1146 case eSIR_ED_CCMP:
1147#ifdef FEATURE_WLAN_WAPI
1148 case eSIR_ED_WPI:
1149#endif
1150 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301151 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key,
1152 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001153 }
1154 break;
1155 default:
1156 break;
1157 }
1158
1159
1160 //
1161 // FIXME_GEN4
1162 // A global counter (dialog token) is required to keep track of
1163 // all PE <-> HAL communication(s)
1164 //
1165 msgQ.reserved = 0;
1166 msgQ.bodyptr = pSetStaKeyParams;
1167 msgQ.bodyval = 0;
1168
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001169 limLog( pMac, LOG1, FL( "Sending WDA_SET_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001170 MTRACE(macTraceMsgTx(pMac, sessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001171 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ ))) {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001172 limLog( pMac, LOGE, FL("Posting SET_STAKEY to HAL failed, reason=%X"), retCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07001173 // Respond to SME with LIM_MLM_SETKEYS_CNF
1174 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1175 }else
1176 return; // Continue after WDA_SET_STAKEY_RSP...
1177
1178 limPostSmeSetKeysCnf( pMac, pMlmSetKeysReq, &mlmSetKeysCnf );
1179}
1180
1181/**
1182 * limSendRemoveBssKeyReq()
1183 *
1184 *FUNCTION:
1185 * This function is called from limProcessMlmRemoveReq(),
1186 * when PE is trying to Remove a Group Key related
1187 * to a specified encryption type
1188 *
1189 *LOGIC:
1190 *
1191 *ASSUMPTIONS:
1192 * NA
1193 *
1194 *NOTE:
1195 * NA
1196 *
1197 * @param pMac Pointer to Global MAC structure
1198 * @param pMlmRemoveKeyReq Pointer to MLM_REMOVEKEY_REQ buffer
1199 * @return none
1200 */
1201void limSendRemoveBssKeyReq( tpAniSirGlobal pMac,
1202 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
1203 tpPESession psessionEntry)
1204{
1205tSirMsgQ msgQ;
1206tpRemoveBssKeyParams pRemoveBssKeyParams = NULL;
1207tLimMlmRemoveKeyCnf mlmRemoveKeysCnf;
1208tSirRetStatus retCode;
1209
1210 // Package WDA_REMOVE_BSSKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301211 pRemoveBssKeyParams = vos_mem_malloc(sizeof( tRemoveBssKeyParams ));
1212 if ( NULL == pRemoveBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001213 {
1214 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301215 FL( "Unable to allocate memory during REMOVE_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001216
1217 // Respond to SME with error code
1218 mlmRemoveKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1219 goto end;
1220 }
1221 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301222 vos_mem_set( (void *) pRemoveBssKeyParams,
1223 sizeof( tRemoveBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001224
1225 // Update the WDA_REMOVE_BSSKEY_REQ parameters
1226 pRemoveBssKeyParams->bssIdx = psessionEntry->bssIdx;
1227 pRemoveBssKeyParams->encType = pMlmRemoveKeyReq->edType;
1228 pRemoveBssKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1229 pRemoveBssKeyParams->wepType = pMlmRemoveKeyReq->wepType;
1230
1231 /* Update PE session Id*/
1232
1233 pRemoveBssKeyParams->sessionId = psessionEntry->peSessionId;
1234
1235 msgQ.type = WDA_REMOVE_BSSKEY_REQ;
1236 //
1237 // FIXME_GEN4
1238 // A global counter (dialog token) is required to keep track of
1239 // all PE <-> HAL communication(s)
1240 //
1241 msgQ.reserved = 0;
1242 msgQ.bodyptr = pRemoveBssKeyParams;
1243 msgQ.bodyval = 0;
1244
1245 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001246 FL( "Sending WDA_REMOVE_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001247 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001248
1249 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1250 {
1251 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001252 FL("Posting REMOVE_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001253 retCode );
1254
1255 // Respond to SME with LIM_MLM_REMOVEKEYS_CNF
1256 mlmRemoveKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1257 }
1258 else
1259 return;
1260
1261end:
1262 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001263 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001264 pMlmRemoveKeyReq,
1265 &mlmRemoveKeysCnf );
1266
1267}
1268
1269/**
1270 * limSendRemoveStaKeyReq()
1271 *
1272 *FUNCTION:
1273 * This function is called from limProcessMlmRemoveKeysReq(),
1274 * when PE is trying to setup the Unicast Keys related
1275 * to a specified STA with specified encryption type
1276 *
1277 *LOGIC:
1278 *
1279 *ASSUMPTIONS:
1280 * NA
1281 *
1282 *NOTE:
1283 * NA
1284 *
1285 * @param pMac Pointer to Global MAC structure
1286 * @param pMlmRemoveKeysReq Pointer to MLM_REMOVEKEYS_REQ buffer
1287 * @param staIdx STA index for which the keys are being set
1288 * @return none
1289 */
1290void limSendRemoveStaKeyReq( tpAniSirGlobal pMac,
1291 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301292 tANI_U16 staIdx,
Jeff Johnsone7245742012-09-05 17:12:55 -07001293 tpPESession psessionEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07001294{
1295tSirMsgQ msgQ;
1296tpRemoveStaKeyParams pRemoveStaKeyParams = NULL;
1297tLimMlmRemoveKeyCnf mlmRemoveKeyCnf;
1298tSirRetStatus retCode;
1299
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301300 pRemoveStaKeyParams = vos_mem_malloc(sizeof( tRemoveStaKeyParams ));
1301 if ( NULL == pRemoveStaKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001302 {
1303 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301304 FL( "Unable to allocate memory during REMOVE_STAKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001305
1306 // Respond to SME with error code
1307 mlmRemoveKeyCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1308 goto end;
1309 }
1310 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301311 vos_mem_set( (void *) pRemoveStaKeyParams,
1312 sizeof( tRemoveStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001313
1314 if( (pMlmRemoveKeyReq->edType == eSIR_ED_WEP104 || pMlmRemoveKeyReq->edType == eSIR_ED_WEP40) &&
1315 pMlmRemoveKeyReq->wepType == eSIR_WEP_STATIC )
1316 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001317 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 -07001318 mlmRemoveKeyCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
1319 goto end;
1320 }
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001321
Jeff Johnson295189b2012-06-20 16:38:30 -07001322 // Update the WDA_REMOVEKEY_REQ parameters
1323 pRemoveStaKeyParams->staIdx = staIdx;
1324 pRemoveStaKeyParams->encType = pMlmRemoveKeyReq->edType;
1325 pRemoveStaKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1326 pRemoveStaKeyParams->unicast = pMlmRemoveKeyReq->unicast;
1327
1328 /* Update PE session ID*/
Jeff Johnsone7245742012-09-05 17:12:55 -07001329 pRemoveStaKeyParams->sessionId = psessionEntry->peSessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001330
1331 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001332
Jeff Johnson295189b2012-06-20 16:38:30 -07001333 msgQ.type = WDA_REMOVE_STAKEY_REQ;
1334 //
1335 // FIXME_GEN4
1336 // A global counter (dialog token) is required to keep track of
1337 // all PE <-> HAL communication(s)
1338 //
1339 msgQ.reserved = 0;
1340 msgQ.bodyptr = pRemoveStaKeyParams;
1341 msgQ.bodyval = 0;
1342
1343 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001344 FL( "Sending WDA_REMOVE_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001345 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001346 retCode = wdaPostCtrlMsg( pMac, &msgQ );
1347 if (eSIR_SUCCESS != retCode)
Jeff Johnson295189b2012-06-20 16:38:30 -07001348 {
1349 limLog( pMac, LOGE,
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001350 FL("Posting REMOVE_STAKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001351 retCode );
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301352 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001353 pRemoveStaKeyParams = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07001354
1355 // Respond to SME with LIM_MLM_REMOVEKEY_CNF
1356 mlmRemoveKeyCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1357 }
1358 else
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001359 return;
Jeff Johnson295189b2012-06-20 16:38:30 -07001360
1361end:
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001362 if (pRemoveStaKeyParams)
1363 {
Kiet Lam842c3e12013-11-16 22:40:57 +05301364 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001365 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001366 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001367 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001368 pMlmRemoveKeyReq,
1369 &mlmRemoveKeyCnf );
1370
1371}
1372
1373