blob: 468b6a493f16b32603ccd1a02ddfb7e4ab0b81da [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,
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
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];
622
623 keyLength += 3;
624
625 // Bytes 0-2 of seed is IV
626 // Read TSF timestamp into seed to get random IV - 1st 3 bytes
627 halGetTxTSFtimer(pMac, (tSirMacTimeStamp *) &seed);
628
629 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530630 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700631
632 // Compute CRC-32 and place them in last 4 bytes of plain text
633 limComputeCrc32(icv, pPlainText, sizeof(tSirMacAuthFrameBody));
634
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530635 vos_mem_copy( pPlainText + sizeof(tSirMacAuthFrameBody),
Jeff Johnson295189b2012-06-20 16:38:30 -0700636 icv, SIR_MAC_WEP_ICV_LENGTH);
637
638 // Run RC4 on plain text with the seed
639 limRC4(pEncrBody + SIR_MAC_WEP_IV_LENGTH,
640 (tANI_U8 *) pPlainText, seed, keyLength,
641 LIM_ENCR_AUTH_BODY_LEN - SIR_MAC_WEP_IV_LENGTH);
642
643 // Prepare IV
644 pEncrBody[0] = seed[0];
645 pEncrBody[1] = seed[1];
646 pEncrBody[2] = seed[2];
647 pEncrBody[3] = keyId << 6;
648} /****** end limEncryptAuthFrame() ******/
649
650
651
652/**
653 * limComputeCrc32()
654 *
655 *FUNCTION:
656 * This function is called to compute CRC-32 on a given source.
657 * Used while encrypting/decrypting Authentication frame 3.
658 *
659 *LOGIC:
660 *
661 *ASSUMPTIONS:
662 * NA
663 *
664 *NOTE:
665 * NA
666 *
667 * @param pDest Destination location for computed CRC
668 * @param pSrc Source location to be CRC computed
669 * @param len Length over which CRC to be computed
670 * @return None
671 */
672
673void
Sridhar Selvaraj05a07142017-07-18 11:51:34 +0530674limComputeCrc32(tANI_U8 *pDest, tANI_U8 * pSrc, tANI_U16 len)
Jeff Johnson295189b2012-06-20 16:38:30 -0700675{
676 tANI_U32 crc;
677 int i;
678
679 crc = 0;
680 crc = ~crc;
681
682 while(len-- > 0)
683 crc = limCrcUpdate(crc, *pSrc++);
684
685 crc = ~crc;
686
687 for (i=0; i < SIR_MAC_WEP_IV_LENGTH; i++)
688 {
689 pDest[i] = (tANI_U8)crc;
690 crc >>= 8;
691 }
692} /****** end limComputeCrc32() ******/
693
694
695
696/**
697 * limRC4()
698 *
699 *FUNCTION:
700 * This function is called to run RC4 algorithm. Called while
701 * encrypting/decrypting Authentication frame 3.
702 *
703 *LOGIC:
704 *
705 *ASSUMPTIONS:
706 * NA
707 *
708 *NOTE:
709 * NA
710 *
711 * @param pDest Destination location for encrypted text
712 * @param pSrc Source location to be encrypted
713 * @param seed Contains seed (IV + key) for PRNG
714 * @param keyLength 8 (WEP40) or 16 (WEP104)
715 * @param frameLen Length of the frame
716 *
717 * @return None
718 */
719
720void
721limRC4(tANI_U8 *pDest, tANI_U8 *pSrc, tANI_U8 *seed, tANI_U32 keyLength, tANI_U16 frameLen)
722{
723 typedef struct
724 {
725 tANI_U8 i, j;
726 tANI_U8 sbox[256];
727 } tRC4Context;
728
729 tRC4Context ctx;
730
731 {
732 tANI_U16 i, j, k;
733
734 //
735 // Initialize sbox using seed
736 //
737
738 ctx.i = ctx.j = 0;
739 for (i=0; i<256; i++)
740 ctx.sbox[i] = (tANI_U8)i;
741
742 j = 0;
743 k = 0;
744 for (i=0; i<256; i++)
745 {
746 tANI_U8 temp;
Kiran Kumar Lokerea4db3dc2013-03-25 18:05:24 -0700747 if ( k < LIM_SEED_LENGTH )
748 j = (tANI_U8)(j + ctx.sbox[i] + seed[k]);
Jeff Johnson295189b2012-06-20 16:38:30 -0700749 temp = ctx.sbox[i];
750 ctx.sbox[i] = ctx.sbox[j];
751 ctx.sbox[j] = temp;
752
753 if (++k >= keyLength)
754 k = 0;
755 }
756 }
757
758 {
759 tANI_U8 i = ctx.i;
760 tANI_U8 j = ctx.j;
Sridhar Selvarajdd6518f2017-07-27 20:24:13 +0530761 tANI_U16 len = frameLen;
Jeff Johnson295189b2012-06-20 16:38:30 -0700762
763 while (len-- > 0)
764 {
765 tANI_U8 temp1, temp2;
766
767 i = (tANI_U8)(i+1);
768 temp1 = ctx.sbox[i];
769 j = (tANI_U8)(j + temp1);
770
771 ctx.sbox[i] = temp2 = ctx.sbox[j];
772 ctx.sbox[j] = temp1;
773
774 temp1 = (tANI_U8)(temp1 + temp2);
775 temp1 = ctx.sbox[temp1];
776 temp2 = (tANI_U8)(pSrc ? *pSrc++ : 0);
777
778 *pDest++ = (tANI_U8)(temp1 ^ temp2);
779 }
780
781 ctx.i = i;
782 ctx.j = j;
783 }
784} /****** end limRC4() ******/
785
786
787
788/**
789 * limDecryptAuthFrame()
790 *
791 *FUNCTION:
792 * This function is called in limProcessAuthFrame() function
793 * to decrypt received Authentication frame3 body.
794 *
795 *LOGIC:
796 *
797 *ASSUMPTIONS:
798 * NA
799 *
800 *NOTE:
801 * NA
802 *
803 * @param pMac Pointer to Global MAC structure
804 * @param pKey Pointer to the key to be used for decryption
805 * @param pEncrBody Pointer to the body to be decrypted
806 * @param pPlainBody Pointer to the decrypted body
807 * @param keyLength 8 (WEP40) or 16 (WEP104)
808 *
809 * @return Decrypt result - eSIR_SUCCESS for success and
810 * LIM_DECRYPT_ICV_FAIL for ICV mismatch.
811 * If decryption is a success, pBody will
812 * have decrypted auth frame body.
813 */
814
815tANI_U8
816limDecryptAuthFrame(tpAniSirGlobal pMac, tANI_U8 *pKey, tANI_U8 *pEncrBody,
817 tANI_U8 *pPlainBody, tANI_U32 keyLength, tANI_U16 frameLen)
818{
819 tANI_U8 seed[LIM_SEED_LENGTH], icv[SIR_MAC_WEP_ICV_LENGTH];
820 int i;
821 keyLength += 3;
822
823
824 // Bytes 0-2 of seed is received IV
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530825 vos_mem_copy((tANI_U8 *) seed, pEncrBody, SIR_MAC_WEP_IV_LENGTH - 1);
Jeff Johnson295189b2012-06-20 16:38:30 -0700826
827 // Bytes 3-7 of seed is key
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530828 vos_mem_copy((tANI_U8 *) &seed[3], pKey, keyLength - 3);
Jeff Johnson295189b2012-06-20 16:38:30 -0700829
830 // Run RC4 on encrypted text with the seed
831 limRC4(pPlainBody,
832 pEncrBody + SIR_MAC_WEP_IV_LENGTH,
833 seed,
834 keyLength,
835 frameLen);
836
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700837 PELOG4(limLog(pMac, LOG4, FL("plainbody is "));
Jeff Johnson295189b2012-06-20 16:38:30 -0700838 sirDumpBuf(pMac, SIR_LIM_MODULE_ID, LOG4, pPlainBody, frameLen);)
839
840 // Compute CRC-32 and place them in last 4 bytes of encrypted body
841 limComputeCrc32(icv,
842 (tANI_U8 *) pPlainBody,
Sridhar Selvarajdd6518f2017-07-27 20:24:13 +0530843 (frameLen - SIR_MAC_WEP_ICV_LENGTH));
Jeff Johnson295189b2012-06-20 16:38:30 -0700844
845 // Compare RX_ICV with computed ICV
846 for (i = 0; i < SIR_MAC_WEP_ICV_LENGTH; i++)
847 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700848 PELOG4(limLog(pMac, LOG4, FL(" computed ICV%d[%x], rxed ICV%d[%x]"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700849 i, icv[i], i, pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i]);)
850 if (icv[i] != pPlainBody[frameLen - SIR_MAC_WEP_ICV_LENGTH + i])
851 return LIM_DECRYPT_ICV_FAIL;
852 }
853
854 return eSIR_SUCCESS;
855} /****** end limDecryptAuthFrame() ******/
856
857/**
858 * limPostSmeSetKeysCnf
859 *
860 * A utility API to send MLM_SETKEYS_CNF to SME
861 */
862void limPostSmeSetKeysCnf( tpAniSirGlobal pMac,
863 tLimMlmSetKeysReq *pMlmSetKeysReq,
864 tLimMlmSetKeysCnf *mlmSetKeysCnf)
865{
866 // Prepare and Send LIM_MLM_SETKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530867 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700868 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
869 sizeof(tSirMacAddr));
870
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530871 vos_mem_copy( (tANI_U8 *) &mlmSetKeysCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700872 (tANI_U8 *) pMlmSetKeysReq->peerMacAddr,
873 sizeof(tSirMacAddr));
874
Jeff Johnson295189b2012-06-20 16:38:30 -0700875
876 /// Free up buffer allocated for mlmSetKeysReq
Vinay Krishna Eranna6f22c1f2014-10-13 16:03:06 +0530877 vos_mem_zero(pMlmSetKeysReq, sizeof(tLimMlmSetKeysReq));
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530878 vos_mem_free( pMlmSetKeysReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700879 pMac->lim.gpLimMlmSetKeysReq = NULL;
880
881 limPostSmeMessage( pMac,
882 LIM_MLM_SETKEYS_CNF,
883 (tANI_U32 *) mlmSetKeysCnf );
884}
885
886/**
887 * limPostSmeRemoveKeysCnf
888 *
889 * A utility API to send MLM_REMOVEKEY_CNF to SME
890 */
891void limPostSmeRemoveKeyCnf( tpAniSirGlobal pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -0700892 tpPESession psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -0700893 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
894 tLimMlmRemoveKeyCnf *mlmRemoveKeyCnf)
895{
896 // Prepare and Send LIM_MLM_REMOVEKEYS_CNF
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530897 vos_mem_copy( (tANI_U8 *) &mlmRemoveKeyCnf->peerMacAddr,
Jeff Johnson295189b2012-06-20 16:38:30 -0700898 (tANI_U8 *) pMlmRemoveKeyReq->peerMacAddr,
899 sizeof(tSirMacAddr));
900
901 /// Free up buffer allocated for mlmRemoveKeysReq
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530902 vos_mem_free( pMlmRemoveKeyReq );
Jeff Johnson295189b2012-06-20 16:38:30 -0700903 pMac->lim.gpLimMlmRemoveKeyReq = NULL;
904
Jeff Johnsone7245742012-09-05 17:12:55 -0700905 psessionEntry->limMlmState = psessionEntry->limPrevMlmState; //Restore the state.
906 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, psessionEntry->peSessionId, psessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -0700907
908 limPostSmeMessage( pMac,
909 LIM_MLM_REMOVEKEY_CNF,
910 (tANI_U32 *) mlmRemoveKeyCnf );
911}
912
913/**
914 * limSendSetBssKeyReq()
915 *
916 *FUNCTION:
917 * This function is called from limProcessMlmSetKeysReq(),
918 * when PE is trying to setup the Group Keys related
919 * to a specified encryption type
920 *
921 *LOGIC:
922 *
923 *ASSUMPTIONS:
924 * NA
925 *
926 *NOTE:
927 * NA
928 *
929 * @param pMac Pointer to Global MAC structure
930 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
931 * @return none
932 */
933void limSendSetBssKeyReq( tpAniSirGlobal pMac,
934 tLimMlmSetKeysReq *pMlmSetKeysReq,
935 tpPESession psessionEntry)
936{
937tSirMsgQ msgQ;
938tpSetBssKeyParams pSetBssKeyParams = NULL;
939tLimMlmSetKeysCnf mlmSetKeysCnf;
940tSirRetStatus retCode;
941tANI_U32 val = 0;
942
943 if(pMlmSetKeysReq->numKeys > SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
944 {
945 limLog( pMac, LOG1,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700946 FL( "numKeys = %d is more than SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS" ), pMlmSetKeysReq->numKeys);
Jeff Johnson295189b2012-06-20 16:38:30 -0700947
948 // Respond to SME with error code
949 mlmSetKeysCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
950 goto end;
951 }
952
953 // Package WDA_SET_BSSKEY_REQ message parameters
954
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530955 pSetBssKeyParams = vos_mem_malloc(sizeof( tSetBssKeyParams ));
956 if ( NULL == pSetBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -0700957 {
958 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530959 FL( "Unable to allocate memory during SET_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700960
961 // Respond to SME with error code
962 mlmSetKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
963 goto end;
964 }
965 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530966 vos_mem_set( (void *) pSetBssKeyParams,
967 sizeof( tSetBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700968
969 // Update the WDA_SET_BSSKEY_REQ parameters
970 pSetBssKeyParams->bssIdx = psessionEntry->bssIdx;
971 pSetBssKeyParams->encType = pMlmSetKeysReq->edType;
Jeff Johnsone7245742012-09-05 17:12:55 -0700972
Jeff Johnson295189b2012-06-20 16:38:30 -0700973
974 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
975 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -0700976 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -0700977 }
978
979 pSetBssKeyParams->singleTidRc = (tANI_U8)val;
980
981 /* Update PE session Id*/
982 pSetBssKeyParams->sessionId = psessionEntry ->peSessionId;
983
Jeff Johnsone7245742012-09-05 17:12:55 -0700984 if(pMlmSetKeysReq->key[0].keyId &&
985 ((pMlmSetKeysReq->edType == eSIR_ED_WEP40) ||
986 (pMlmSetKeysReq->edType == eSIR_ED_WEP104))
987 )
988 {
989 /* IF the key id is non-zero and encryption type is WEP, Send all the 4
990 * keys to HAL with filling the key at right index in pSetBssKeyParams->key. */
991 pSetBssKeyParams->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530992 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key[pMlmSetKeysReq->key[0].keyId],
993 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof(pMlmSetKeysReq->key[0]));
Jeff Johnsone7245742012-09-05 17:12:55 -0700994
995 }
996 else
997 {
998 pSetBssKeyParams->numKeys = pMlmSetKeysReq->numKeys;
Bansidhar Gopalachari12731232013-07-11 10:56:36 +0530999 vos_mem_copy( (tANI_U8 *) &pSetBssKeyParams->key,
1000 (tANI_U8 *) &pMlmSetKeysReq->key,
1001 sizeof( tSirKeys ) * pMlmSetKeysReq->numKeys );
Jeff Johnsone7245742012-09-05 17:12:55 -07001002 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001003
1004 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1005 msgQ.type = WDA_SET_BSSKEY_REQ;
1006 //
1007 // FIXME_GEN4
1008 // A global counter (dialog token) is required to keep track of
1009 // all PE <-> HAL communication(s)
1010 //
1011 msgQ.reserved = 0;
1012 msgQ.bodyptr = pSetBssKeyParams;
1013 msgQ.bodyval = 0;
1014
1015 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001016 FL( "Sending WDA_SET_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001017 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001018 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1019 {
1020 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001021 FL("Posting SET_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001022 retCode );
1023
1024 // Respond to SME with LIM_MLM_SETKEYS_CNF
1025 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1026 }
1027 else
1028 return; // Continue after WDA_SET_BSSKEY_RSP...
1029
1030end:
1031 limPostSmeSetKeysCnf( pMac,
1032 pMlmSetKeysReq,
1033 &mlmSetKeysCnf );
1034
1035}
1036
1037/**
1038 * @function : limSendSetStaKeyReq()
1039 *
1040 * @brief : This function is called from limProcessMlmSetKeysReq(),
1041 * when PE is trying to setup the Unicast Keys related
1042 * to a specified STA with specified encryption type
1043 *
1044 *LOGIC:
1045 *
1046 *ASSUMPTIONS:
1047 * NA
1048 *
1049 *NOTE:
1050 * NA
1051 *
1052 * @param pMac Pointer to Global MAC structure
1053 * @param pMlmSetKeysReq Pointer to MLM_SETKEYS_REQ buffer
1054 * @param staIdx STA index for which the keys are being set
1055 * @param defWEPIdx The default WEP key index [0..3]
1056 * @return none
1057 */
1058void limSendSetStaKeyReq( tpAniSirGlobal pMac,
1059 tLimMlmSetKeysReq *pMlmSetKeysReq,
1060 tANI_U16 staIdx,
1061 tANI_U8 defWEPIdx,
1062 tpPESession sessionEntry)
1063{
1064tSirMsgQ msgQ;
1065tpSetStaKeyParams pSetStaKeyParams = NULL;
1066tLimMlmSetKeysCnf mlmSetKeysCnf;
1067tSirRetStatus retCode;
1068tANI_U32 val = 0;
1069
1070 // Package WDA_SET_STAKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301071 pSetStaKeyParams = vos_mem_malloc(sizeof( tSetStaKeyParams ));
1072 if ( NULL == pSetStaKeyParams )
1073 {
1074 limLog( pMac, LOGP, FL( "Unable to allocate memory during SET_BSSKEY" ));
1075 return;
1076 }
1077 else
1078 vos_mem_set( (void *) pSetStaKeyParams, sizeof( tSetStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001079
1080 // Update the WDA_SET_STAKEY_REQ parameters
1081 pSetStaKeyParams->staIdx = staIdx;
1082 pSetStaKeyParams->encType = pMlmSetKeysReq->edType;
1083
1084
1085 if(eSIR_SUCCESS != wlan_cfgGetInt(pMac, WNI_CFG_SINGLE_TID_RC, &val))
1086 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001087 limLog( pMac, LOGP, FL( "Unable to read WNI_CFG_SINGLE_TID_RC" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001088 }
1089
1090 pSetStaKeyParams->singleTidRc = (tANI_U8)val;
1091
1092 /* Update PE session ID*/
1093 pSetStaKeyParams->sessionId = sessionEntry->peSessionId;
1094
1095 /**
1096 * For WEP - defWEPIdx indicates the default WEP
1097 * Key to be used for TX
1098 * For all others, there's just one key that can
1099 * be used and hence it is assumed that
1100 * defWEPIdx = 0 (from the caller)
1101 */
1102
1103 pSetStaKeyParams->defWEPIdx = defWEPIdx;
1104
1105 /** Store the Previous MlmState*/
1106 sessionEntry->limPrevMlmState = sessionEntry->limMlmState;
1107 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
1108
1109 if(sessionEntry->limSystemRole == eLIM_STA_IN_IBSS_ROLE && !pMlmSetKeysReq->key[0].unicast) {
1110 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_BCASTKEY_STATE;
1111 msgQ.type = WDA_SET_STA_BCASTKEY_REQ;
1112 }else {
1113 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
1114 msgQ.type = WDA_SET_STAKEY_REQ;
1115 }
Jeff Johnsone7245742012-09-05 17:12:55 -07001116 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001117
1118 /**
1119 * In the Case of WEP_DYNAMIC, ED_TKIP and ED_CCMP
1120 * the Key[0] contains the KEY, so just copy that alone,
1121 * for the case of WEP_STATIC the hal gets the key from cfg
1122 */
1123 switch( pMlmSetKeysReq->edType ) {
1124 case eSIR_ED_WEP40:
1125 case eSIR_ED_WEP104:
1126 // FIXME! Is this OK?
1127 if( 0 == pMlmSetKeysReq->numKeys ) {
Jeff Johnson295189b2012-06-20 16:38:30 -07001128 tANI_U32 i;
1129
1130 for(i=0; i < SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS ;i++)
1131 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301132 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key[i],
1133 (tANI_U8 *) &pMlmSetKeysReq->key[i], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001134 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001135 pSetStaKeyParams->wepType = eSIR_WEP_STATIC;
1136 sessionEntry->limMlmState = eLIM_MLM_WT_SET_STA_KEY_STATE;
Jeff Johnsone7245742012-09-05 17:12:55 -07001137 MTRACE(macTrace(pMac, TRACE_CODE_MLM_STATE, sessionEntry->peSessionId, sessionEntry->limMlmState));
Jeff Johnson295189b2012-06-20 16:38:30 -07001138 }else {
Jeff Johnsone7245742012-09-05 17:12:55 -07001139 /*This case the keys are coming from upper layer so need to fill the
1140 * key at the default wep key index and send to the HAL */
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301141 if (defWEPIdx >= SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS)
1142 {
1143 limLog( pMac, LOGE, FL("WEPIdx length %d more than "
1144 "the Max limit, reset to Max"),defWEPIdx);
Mukul Sharmad2b81862014-07-01 21:01:04 +05301145 vos_mem_free (pSetStaKeyParams);
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301146 return;
1147 }
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301148 vos_mem_copy((tANI_U8 *) &pSetStaKeyParams->key[defWEPIdx],
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301149 (tANI_U8 *) &pMlmSetKeysReq->key[0],
1150 sizeof( pMlmSetKeysReq->key[0] ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001151 pMlmSetKeysReq->numKeys = SIR_MAC_MAX_NUM_OF_DEFAULT_KEYS;
Kaushik, Sushant40e595a2014-05-03 15:58:30 +05301152
Jeff Johnson295189b2012-06-20 16:38:30 -07001153 }
1154 break;
1155 case eSIR_ED_TKIP:
1156 case eSIR_ED_CCMP:
1157#ifdef FEATURE_WLAN_WAPI
1158 case eSIR_ED_WPI:
1159#endif
1160 {
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301161 vos_mem_copy( (tANI_U8 *) &pSetStaKeyParams->key,
1162 (tANI_U8 *) &pMlmSetKeysReq->key[0], sizeof( tSirKeys ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001163 }
1164 break;
1165 default:
1166 break;
1167 }
1168
1169
1170 //
1171 // FIXME_GEN4
1172 // A global counter (dialog token) is required to keep track of
1173 // all PE <-> HAL communication(s)
1174 //
1175 msgQ.reserved = 0;
1176 msgQ.bodyptr = pSetStaKeyParams;
1177 msgQ.bodyval = 0;
1178
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001179 limLog( pMac, LOG1, FL( "Sending WDA_SET_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001180 MTRACE(macTraceMsgTx(pMac, sessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001181 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ ))) {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001182 limLog( pMac, LOGE, FL("Posting SET_STAKEY to HAL failed, reason=%X"), retCode );
Jeff Johnson295189b2012-06-20 16:38:30 -07001183 // Respond to SME with LIM_MLM_SETKEYS_CNF
1184 mlmSetKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1185 }else
1186 return; // Continue after WDA_SET_STAKEY_RSP...
1187
1188 limPostSmeSetKeysCnf( pMac, pMlmSetKeysReq, &mlmSetKeysCnf );
1189}
1190
1191/**
1192 * limSendRemoveBssKeyReq()
1193 *
1194 *FUNCTION:
1195 * This function is called from limProcessMlmRemoveReq(),
1196 * when PE is trying to Remove a Group Key related
1197 * to a specified encryption type
1198 *
1199 *LOGIC:
1200 *
1201 *ASSUMPTIONS:
1202 * NA
1203 *
1204 *NOTE:
1205 * NA
1206 *
1207 * @param pMac Pointer to Global MAC structure
1208 * @param pMlmRemoveKeyReq Pointer to MLM_REMOVEKEY_REQ buffer
1209 * @return none
1210 */
1211void limSendRemoveBssKeyReq( tpAniSirGlobal pMac,
1212 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
1213 tpPESession psessionEntry)
1214{
1215tSirMsgQ msgQ;
1216tpRemoveBssKeyParams pRemoveBssKeyParams = NULL;
1217tLimMlmRemoveKeyCnf mlmRemoveKeysCnf;
1218tSirRetStatus retCode;
1219
1220 // Package WDA_REMOVE_BSSKEY_REQ message parameters
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301221 pRemoveBssKeyParams = vos_mem_malloc(sizeof( tRemoveBssKeyParams ));
1222 if ( NULL == pRemoveBssKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001223 {
1224 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301225 FL( "Unable to allocate memory during REMOVE_BSSKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001226
1227 // Respond to SME with error code
1228 mlmRemoveKeysCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1229 goto end;
1230 }
1231 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301232 vos_mem_set( (void *) pRemoveBssKeyParams,
1233 sizeof( tRemoveBssKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001234
1235 // Update the WDA_REMOVE_BSSKEY_REQ parameters
1236 pRemoveBssKeyParams->bssIdx = psessionEntry->bssIdx;
1237 pRemoveBssKeyParams->encType = pMlmRemoveKeyReq->edType;
1238 pRemoveBssKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1239 pRemoveBssKeyParams->wepType = pMlmRemoveKeyReq->wepType;
1240
1241 /* Update PE session Id*/
1242
1243 pRemoveBssKeyParams->sessionId = psessionEntry->peSessionId;
1244
1245 msgQ.type = WDA_REMOVE_BSSKEY_REQ;
1246 //
1247 // FIXME_GEN4
1248 // A global counter (dialog token) is required to keep track of
1249 // all PE <-> HAL communication(s)
1250 //
1251 msgQ.reserved = 0;
1252 msgQ.bodyptr = pRemoveBssKeyParams;
1253 msgQ.bodyval = 0;
1254
1255 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001256 FL( "Sending WDA_REMOVE_BSSKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001257 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson295189b2012-06-20 16:38:30 -07001258
1259 if( eSIR_SUCCESS != (retCode = wdaPostCtrlMsg( pMac, &msgQ )))
1260 {
1261 limLog( pMac, LOGE,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001262 FL("Posting REMOVE_BSSKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001263 retCode );
1264
1265 // Respond to SME with LIM_MLM_REMOVEKEYS_CNF
1266 mlmRemoveKeysCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1267 }
1268 else
1269 return;
1270
1271end:
1272 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001273 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001274 pMlmRemoveKeyReq,
1275 &mlmRemoveKeysCnf );
1276
1277}
1278
1279/**
1280 * limSendRemoveStaKeyReq()
1281 *
1282 *FUNCTION:
1283 * This function is called from limProcessMlmRemoveKeysReq(),
1284 * when PE is trying to setup the Unicast Keys related
1285 * to a specified STA with specified encryption type
1286 *
1287 *LOGIC:
1288 *
1289 *ASSUMPTIONS:
1290 * NA
1291 *
1292 *NOTE:
1293 * NA
1294 *
1295 * @param pMac Pointer to Global MAC structure
1296 * @param pMlmRemoveKeysReq Pointer to MLM_REMOVEKEYS_REQ buffer
1297 * @param staIdx STA index for which the keys are being set
1298 * @return none
1299 */
1300void limSendRemoveStaKeyReq( tpAniSirGlobal pMac,
1301 tLimMlmRemoveKeyReq *pMlmRemoveKeyReq,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301302 tANI_U16 staIdx,
Jeff Johnsone7245742012-09-05 17:12:55 -07001303 tpPESession psessionEntry)
Jeff Johnson295189b2012-06-20 16:38:30 -07001304{
1305tSirMsgQ msgQ;
1306tpRemoveStaKeyParams pRemoveStaKeyParams = NULL;
1307tLimMlmRemoveKeyCnf mlmRemoveKeyCnf;
1308tSirRetStatus retCode;
1309
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301310 pRemoveStaKeyParams = vos_mem_malloc(sizeof( tRemoveStaKeyParams ));
1311 if ( NULL == pRemoveStaKeyParams )
Jeff Johnson295189b2012-06-20 16:38:30 -07001312 {
1313 limLog( pMac, LOGE,
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301314 FL( "Unable to allocate memory during REMOVE_STAKEY" ));
Jeff Johnson295189b2012-06-20 16:38:30 -07001315
1316 // Respond to SME with error code
1317 mlmRemoveKeyCnf.resultCode = eSIR_SME_RESOURCES_UNAVAILABLE;
1318 goto end;
1319 }
1320 else
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301321 vos_mem_set( (void *) pRemoveStaKeyParams,
1322 sizeof( tRemoveStaKeyParams ), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001323
1324 if( (pMlmRemoveKeyReq->edType == eSIR_ED_WEP104 || pMlmRemoveKeyReq->edType == eSIR_ED_WEP40) &&
1325 pMlmRemoveKeyReq->wepType == eSIR_WEP_STATIC )
1326 {
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001327 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 -07001328 mlmRemoveKeyCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
1329 goto end;
1330 }
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001331
Jeff Johnson295189b2012-06-20 16:38:30 -07001332 // Update the WDA_REMOVEKEY_REQ parameters
1333 pRemoveStaKeyParams->staIdx = staIdx;
1334 pRemoveStaKeyParams->encType = pMlmRemoveKeyReq->edType;
1335 pRemoveStaKeyParams->keyId = pMlmRemoveKeyReq->keyId;
1336 pRemoveStaKeyParams->unicast = pMlmRemoveKeyReq->unicast;
1337
1338 /* Update PE session ID*/
Jeff Johnsone7245742012-09-05 17:12:55 -07001339 pRemoveStaKeyParams->sessionId = psessionEntry->peSessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -07001340
1341 SET_LIM_PROCESS_DEFD_MESGS(pMac, false);
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001342
Jeff Johnson295189b2012-06-20 16:38:30 -07001343 msgQ.type = WDA_REMOVE_STAKEY_REQ;
1344 //
1345 // FIXME_GEN4
1346 // A global counter (dialog token) is required to keep track of
1347 // all PE <-> HAL communication(s)
1348 //
1349 msgQ.reserved = 0;
1350 msgQ.bodyptr = pRemoveStaKeyParams;
1351 msgQ.bodyval = 0;
1352
1353 limLog( pMac, LOGW,
Kiran Kumar Lokere5be73a62013-04-01 18:40:00 -07001354 FL( "Sending WDA_REMOVE_STAKEY_REQ..." ));
Jeff Johnsone7245742012-09-05 17:12:55 -07001355 MTRACE(macTraceMsgTx(pMac, psessionEntry->peSessionId, msgQ.type));
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001356 retCode = wdaPostCtrlMsg( pMac, &msgQ );
1357 if (eSIR_SUCCESS != retCode)
Jeff Johnson295189b2012-06-20 16:38:30 -07001358 {
1359 limLog( pMac, LOGE,
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001360 FL("Posting REMOVE_STAKEY to HAL failed, reason=%X"),
Jeff Johnson295189b2012-06-20 16:38:30 -07001361 retCode );
Bansidhar Gopalachari12731232013-07-11 10:56:36 +05301362 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001363 pRemoveStaKeyParams = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -07001364
1365 // Respond to SME with LIM_MLM_REMOVEKEY_CNF
1366 mlmRemoveKeyCnf.resultCode = eSIR_SME_HAL_SEND_MESSAGE_FAIL;
1367 }
1368 else
Jeff Johnson2e77e8c2013-04-03 15:10:02 -07001369 return;
Jeff Johnson295189b2012-06-20 16:38:30 -07001370
1371end:
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001372 if (pRemoveStaKeyParams)
1373 {
Kiet Lam842c3e12013-11-16 22:40:57 +05301374 vos_mem_free(pRemoveStaKeyParams);
Kiran Kumar Lokerefdf42412013-07-17 17:40:58 -07001375 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001376 limPostSmeRemoveKeyCnf( pMac,
Jeff Johnsone7245742012-09-05 17:12:55 -07001377 psessionEntry,
Jeff Johnson295189b2012-06-20 16:38:30 -07001378 pMlmRemoveKeyReq,
1379 &mlmRemoveKeyCnf );
1380
1381}
1382
1383