• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * rsn.c
3  *
4  * Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  *  * Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *  * Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *  * Neither the name Texas Instruments nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 
35 /** \file rsn.c
36  *  \brief 802.11 rsniation SM source
37  *
38  *  \see rsnSM.h
39  */
40 
41 
42 /***************************************************************************/
43 /*                                                                         */
44 /*      MODULE: rsnSM.c                                                    */
45 /*    PURPOSE:  802.11 rsniation SM source                                 */
46 /*                                                                         */
47 /***************************************************************************/
48 
49 #define __FILE_ID__  FILE_ID_40
50 #include "osApi.h"
51 #include "paramOut.h"
52 #include "timer.h"
53 #include "report.h"
54 #include "DataCtrl_Api.h"
55 #include "siteMgrApi.h"
56 #include "smeApi.h"
57 #include "mainSecSm.h"
58 #include "admCtrl.h"
59 #include "rsnApi.h"
60 #include "rsn.h"
61 #include "keyParser.h"
62 #include "EvHandler.h"
63 #include "TI_IPC_Api.h"
64 #include "sme.h"
65 #include "apConn.h"
66 #include "802_11Defs.h"
67 #include "externalSec.h"
68 #include "connApi.h"
69 #ifdef XCC_MODULE_INCLUDED
70 #include "admCtrlWpa.h"
71 #include "XCCMngr.h"
72 #include "admCtrlXCC.h"
73 #endif
74 #include "TWDriver.h"
75 #include "DrvMainModules.h"
76 #include "PowerMgr_API.h"
77 
78 /* Constants */
79 
80 /* Enumerations */
81 
82 /* Typedefs */
83 
84 /* Structures */
85 
86 /* External data definitions */
87 
88 /* External functions definitions */
89 
90 /* Global variables */
91 
92 /* Local function prototypes */
93 TI_STATUS rsn_sendKeysNotSet(rsn_t *pRsn);
94 void rsn_pairwiseReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured);
95 void rsn_groupReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured);
96 void rsn_micFailureReportTimeout (TI_HANDLE hRsn, TI_BOOL bTwdInitOccured);
97 static rsn_siteBanEntry_t * findEntryForInsert(TI_HANDLE hRsn);
98 static rsn_siteBanEntry_t * findBannedSiteAndCleanup(TI_HANDLE hRsn, TMacAddr siteBssid);
99 
100 /* functions */
101 
102 /**
103 *
104 * rsn_Create - allocate memory for rsniation SM
105 *
106 * \b Description:
107 *
108 * Allocate memory for rsniation SM. \n
109 *       Allocates memory for Rsniation context. \n
110 *       Allocates memory for rsniation timer. \n
111 *       Allocates memory for rsniation SM matrix. \n
112 *
113 * \b ARGS:
114 *
115 *  I   - hOs - OS context  \n
116 *
117 * \b RETURNS:
118 *
119 *  TI_OK if successful, TI_NOK otherwise.
120 *
121 * \sa rsn_mainSecKeysOnlyStop()
122 */
rsn_create(TI_HANDLE hOs)123 TI_HANDLE rsn_create(TI_HANDLE hOs)
124 {
125     rsn_t  *pRsn;
126 
127     /* allocate rsniation context memory */
128     pRsn = (rsn_t*)os_memoryAlloc (hOs, sizeof(rsn_t));
129     if (pRsn == NULL)
130     {
131         return NULL;
132     }
133 
134     os_memoryZero (hOs, pRsn, sizeof(rsn_t));
135 
136     /* create admission control */
137     pRsn->pAdmCtrl = admCtrl_create (hOs);
138     if (pRsn->pAdmCtrl == NULL)
139     {
140         os_memoryFree (hOs, pRsn, sizeof(rsn_t));
141         return NULL;
142     }
143 
144     /* create main security SM */
145     pRsn->pMainSecSm = mainSec_create (hOs);
146     if (pRsn->pMainSecSm == NULL)
147     {
148         admCtrl_unload (pRsn->pAdmCtrl);
149         os_memoryFree (hOs, pRsn, sizeof(rsn_t));
150         return NULL;
151     }
152 
153     pRsn->pKeyParser = pRsn->pMainSecSm->pKeyParser;
154 
155     pRsn->hOs = hOs;
156 
157     return pRsn;
158 }
159 
160 
161 /**
162 *
163 * rsn_Unload - unload rsniation SM from memory
164 *
165 * \b Description:
166 *
167 * Unload rsniation SM from memory
168 *
169 * \b ARGS:
170 *
171 *  I   - hRsn - rsniation SM context  \n
172 *
173 * \b RETURNS:
174 *
175 *  TI_OK if successful, TI_NOK otherwise.
176 *
177 * \sa rsn_mainSecKeysOnlyStop()
178 */
rsn_unload(TI_HANDLE hRsn)179 TI_STATUS rsn_unload (TI_HANDLE hRsn)
180 {
181     rsn_t           *pRsn;
182     TI_STATUS       status;
183 
184     if (hRsn == NULL)
185     {
186         return TI_NOK;
187     }
188 
189     pRsn = (rsn_t*)hRsn;
190 
191 	if (pRsn->hMicFailureReportWaitTimer)
192 	{
193 		tmr_DestroyTimer (pRsn->hMicFailureReportWaitTimer);
194 	}
195 	if (pRsn->hMicFailureGroupReKeyTimer)
196 	{
197 		tmr_DestroyTimer (pRsn->hMicFailureGroupReKeyTimer);
198 	}
199 	if (pRsn->hMicFailurePairwiseReKeyTimer)
200 	{
201 		tmr_DestroyTimer (pRsn->hMicFailurePairwiseReKeyTimer);
202 	}
203 
204     status = admCtrl_unload (pRsn->pAdmCtrl);
205     status = mainSec_unload (pRsn->pMainSecSm);
206 
207     os_memoryFree (pRsn->hOs, hRsn, sizeof(rsn_t));
208 
209     return status;
210 }
211 
212 
213 /**
214 *
215 * rsn_init - Init module
216 *
217 * \b Description:
218 *
219 * Init module handles and variables.
220 *
221 * \b RETURNS:
222 *
223 *  void
224 *
225 * \sa rsn_Create, rsn_Unload
226 */
rsn_init(TStadHandlesList * pStadHandles)227 void rsn_init (TStadHandlesList *pStadHandles)
228 {
229     rsn_t *pRsn = (rsn_t*)(pStadHandles->hRsn);
230 
231     pRsn->eGroupKeyUpdate = GROUP_KEY_UPDATE_FALSE;
232     pRsn->ePairwiseKeyUpdate = PAIRWISE_KEY_UPDATE_FALSE;
233     pRsn->PrivacyOptionImplemented = TI_TRUE;
234 
235 	pRsn->hTxCtrl   = pStadHandles->hTxCtrl;
236     pRsn->hRx       = pStadHandles->hRxData;
237     pRsn->hConn     = pStadHandles->hConn;
238     pRsn->hTWD      = pStadHandles->hTWD;
239     pRsn->hCtrlData = pStadHandles->hCtrlData;
240     pRsn->hSiteMgr  = pStadHandles->hSiteMgr;
241     pRsn->hReport   = pStadHandles->hReport;
242     pRsn->hOs       = pStadHandles->hOs;
243     pRsn->hXCCMngr  = pStadHandles->hXCCMngr;
244     pRsn->hEvHandler= pStadHandles->hEvHandler;
245     pRsn->hSmeSm    = pStadHandles->hSme;
246     pRsn->hAPConn   = pStadHandles->hAPConnection;
247     pRsn->hMlme     = pStadHandles->hMlmeSm;
248     pRsn->hPowerMgr = pStadHandles->hPowerMgr;
249     pRsn->hTimer    = pStadHandles->hTimer;
250     pRsn->hCurrBss  = pStadHandles->hCurrBss;
251 
252     pRsn->setPaeConfig = rsn_setPaeConfig;
253     pRsn->getNetworkMode = rsn_getNetworkMode;
254     pRsn->setKey = rsn_setKey;
255     pRsn->removeKey = rsn_removeKey;
256     pRsn->reportStatus = rsn_reportStatus;
257     pRsn->setDefaultKeyId = rsn_setDefaultKeyId;
258 	pRsn->getPortStatus = rsn_getPortStatus;
259 	pRsn->setPortStatus = rsn_setPortStatus;
260 
261     pRsn->defaultKeysOn = TI_TRUE;
262     pRsn->eapType = OS_EAP_TYPE_NONE;
263     pRsn->numOfBannedSites = 0;
264 	pRsn->genericIE.length = 0;
265 }
266 
267 
rsn_SetDefaults(TI_HANDLE hRsn,TRsnInitParams * pInitParam)268 TI_STATUS rsn_SetDefaults (TI_HANDLE hRsn, TRsnInitParams *pInitParam)
269 {
270     rsn_t       *pRsn = (rsn_t*)hRsn;
271     TI_UINT8     keyIndex;
272     TI_STATUS    status;
273 
274     /* Create the module's timers */
275     pRsn->hMicFailureReportWaitTimer = tmr_CreateTimer (pRsn->hTimer);
276     if (pRsn->hMicFailureReportWaitTimer == NULL)
277     {
278         TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_SetDefaults(): Failed to create hMicFailureReportWaitTimer!\n");
279 		return TI_NOK;
280     }
281     pRsn->hMicFailureGroupReKeyTimer = tmr_CreateTimer (pRsn->hTimer);
282     if (pRsn->hMicFailureGroupReKeyTimer == NULL)
283     {
284         TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_SetDefaults(): Failed to create hMicFailureGroupReKeyTimer!\n");
285 		return TI_NOK;
286     }
287 
288     /* Configure the RSN external mode (by default we're in internal mode) */
289     pRsn->bRsnExternalMode = 0;
290 
291 
292     pRsn->hMicFailurePairwiseReKeyTimer = tmr_CreateTimer (pRsn->hTimer);
293     if (pRsn->hMicFailurePairwiseReKeyTimer == NULL)
294     {
295         TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_SetDefaults(): Failed to create hMicFailurePairwiseReKeyTimer!\n");
296 		return TI_NOK;
297     }
298 
299 	pRsn->bPairwiseMicFailureFilter = pInitParam->bPairwiseMicFailureFilter;
300     /* config the admission control with the authentication suite selected.
301        Admission control will configure the main security SM. */
302     status = admCtrl_config (pRsn->pAdmCtrl,
303                              pRsn->hMlme,
304                              pRsn->hRx,
305                              pRsn->hReport,
306                              pRsn->hOs,
307                              pRsn,
308                              pRsn->hXCCMngr,
309                              pRsn->hPowerMgr,
310                              pRsn->hEvHandler,
311                              pRsn->hTimer,
312                              pRsn->hCurrBss,
313                              pInitParam);
314 
315     if (status != TI_OK)
316     {
317         return status;
318     }
319 
320     /* Configure keys from registry */
321     if (pInitParam->privacyOn)
322     {
323         pRsn->wepStaticKey = TI_TRUE;
324     }
325 
326     pRsn->defaultKeyId = pInitParam->defaultKeyId;
327     for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
328     {
329         os_memoryCopy (pRsn->hOs, &pRsn->keys[keyIndex], &pInitParam->keys[keyIndex], sizeof(TSecurityKeys));
330         if (pRsn->keys[keyIndex].keyType != KEY_NULL)
331         {
332             pRsn->wepDefaultKeys[keyIndex] = TI_TRUE;
333         }
334         pRsn->keys_en [keyIndex] = TI_FALSE;
335     }
336 
337     return status;
338 }
339 
340 
341 /**
342 *
343 * rsn_reconfig - re-configure a rsniation
344 *
345 * \b Description:
346 *
347 * Re-configure rsniation
348 *
349 * \b ARGS:
350 *
351 *  I   - hRsn - Rsniation SM context  \n
352 *
353 * \b RETURNS:
354 *
355 *  TI_OK if successful, TI_NOK otherwise.
356 *
357 * \sa rsn_Create, rsn_Unload
358 */
rsn_reconfig(TI_HANDLE hRsn)359 TI_STATUS rsn_reconfig (TI_HANDLE hRsn)
360 {
361     rsn_t  *pRsn = (rsn_t *)hRsn;
362     TI_UINT8   keyIndex;
363 
364     /* Mark all keys as removed */
365     for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
366         pRsn->keys_en [keyIndex] = TI_FALSE;
367 
368     return TI_OK;
369 }
370 
371 
372 /**
373 *
374 * rsn_setDefaultKeys -
375 *
376 * \b Description:
377 *
378 *
379 *
380 * \b ARGS:
381 *
382 *  I   - hRsn - Rsn SM context  \n
383 *
384 * \b RETURNS:
385 *
386 *  TI_OK if successful, TI_NOK otherwise.
387 *
388 * \sa rsn_Stop, rsn_Recv
389 */
rsn_setDefaultKeys(rsn_t * pRsn)390 TI_STATUS rsn_setDefaultKeys(rsn_t *pRsn)
391 {
392     TI_STATUS       status = TI_OK;
393     TTwdParamInfo   tTwdParam;
394     TI_UINT8           keyIndex;
395 
396     for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
397     {
398         /* Set the WEP key to the HAL */
399         if (pRsn->wepDefaultKeys[keyIndex] /*pRsn->keys[keyIndex].encLen>0*/)
400         {
401             /* Change key type to WEP-key before setting*/
402             pRsn->keys[keyIndex].keyType = KEY_WEP;
403 
404             status = pRsn->pMainSecSm->setKey (pRsn->pMainSecSm, &pRsn->keys[keyIndex]);
405 
406             if (status != TI_OK)
407             {
408                 TRACE1(pRsn->hReport, REPORT_SEVERITY_ERROR, "RSN: Setting key #%d failed \n", keyIndex);
409                 return status;
410             }
411         }
412     }
413 
414     /* Now we configure default key ID to the HAL */
415     if (pRsn->defaultKeyId < MAX_KEYS_NUM)
416     {
417         tTwdParam.paramType = TWD_RSN_DEFAULT_KEY_ID_PARAM_ID;
418         tTwdParam.content.configureCmdCBParams.pCb = &pRsn->defaultKeyId;
419         tTwdParam.content.configureCmdCBParams.fCb = NULL;
420         tTwdParam.content.configureCmdCBParams.hCb = NULL;
421         status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
422 
423         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: default key ID =%d \n", pRsn->defaultKeyId);
424     }
425 
426     return status;
427 }
428 
429 
430 /**
431 *
432 * rsn_Start - Start event for the rsniation SM
433 *
434 * \b Description:
435 *
436 * Start event for the rsniation SM
437 *
438 * \b ARGS:
439 *
440 *  I   - hRsn - Rsniation SM context  \n
441 *
442 * \b RETURNS:
443 *
444 *  TI_OK if successful, TI_NOK otherwise.
445 *
446 * \sa rsn_Stop, rsn_Recv
447 */
rsn_start(TI_HANDLE hRsn)448 TI_STATUS rsn_start(TI_HANDLE hRsn)
449 {
450     TI_STATUS           status;
451     rsn_t               *pRsn;
452     ECipherSuite        suite;
453     EExternalAuthMode   extAuthMode;
454     TTwdParamInfo       tTwdParam;
455 
456     pRsn = (rsn_t*)hRsn;
457 
458     if (pRsn == NULL)
459     {
460         return TI_NOK;
461     }
462 
463     TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_start ...\n");
464     pRsn->rsnStartedTs = os_timeStampMs (pRsn->hOs);
465 
466     status = pRsn->pMainSecSm->start (pRsn->pMainSecSm);
467     /* Set keys that need to be set */
468     pRsn->defaultKeysOn = TI_FALSE;
469     pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &suite);
470     pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &extAuthMode);
471 
472     if (pRsn->wepStaticKey && ( (suite == TWD_CIPHER_WEP) || (suite == TWD_CIPHER_CKIP) ) )
473     {   /* set default WEP keys */
474         status = rsn_sendKeysNotSet (pRsn);
475         pRsn->eapType = OS_EAP_TYPE_NONE;
476     }
477     else if (suite == TWD_CIPHER_NONE && extAuthMode != RSN_EXT_AUTH_MODE_OPEN)
478     {   /* remove previously WEP key for SHARED */
479         pRsn->wepStaticKey = TI_FALSE;
480         status = rsn_removedDefKeys (pRsn);
481 
482         /* Set None to HAL */
483         tTwdParam.paramType = TWD_RSN_SECURITY_MODE_PARAM_ID;
484         tTwdParam.content.rsnEncryptionStatus = (ECipherSuite)TWD_CIPHER_NONE;
485         status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
486 
487     }
488     else if (suite==TWD_CIPHER_NONE)
489     {
490         pRsn->eapType = OS_EAP_TYPE_NONE;
491     }
492 
493     return status;
494 }
495 
496 
rsn_sendKeysNotSet(rsn_t * pRsn)497 TI_STATUS rsn_sendKeysNotSet(rsn_t *pRsn)
498 {
499     TI_UINT8           keyIndex;
500     OS_802_11_KEY   rsnOsKey;
501     TI_STATUS       status = TI_OK;
502 
503     for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
504     {
505         if (pRsn->wepDefaultKeys[keyIndex])
506         {
507             rsnOsKey.KeyIndex  = pRsn->keys[keyIndex].keyIndex;
508             rsnOsKey.KeyLength = pRsn->keys[keyIndex].encLen;
509             rsnOsKey.Length    = sizeof(rsnOsKey);
510 
511             /* Change key type to WEP-key before setting*/
512             pRsn->keys[keyIndex].keyType = KEY_WEP;
513 
514             MAC_COPY (rsnOsKey.BSSID, pRsn->keys[keyIndex].macAddress);
515             os_memoryCopy (pRsn->hOs, &rsnOsKey.KeyRSC,
516                            (void *)pRsn->keys[keyIndex].keyRsc,
517                            KEY_RSC_LEN);
518             os_memoryCopy (pRsn->hOs, rsnOsKey.KeyMaterial,
519                            (void *)pRsn->keys[keyIndex].encKey,
520                            MAX_KEY_LEN /*pRsn->keys[keyIndex].encLen*/);
521 
522             /* Set WEP transmit key mask on the default key */
523             if (keyIndex == pRsn->defaultKeyId)
524             {
525                 rsnOsKey.KeyIndex |= 0x80000000;
526             }
527 
528             status = pRsn->pKeyParser->recv (pRsn->pKeyParser, (TI_UINT8*)&rsnOsKey, sizeof(rsnOsKey));
529         }
530     }
531 
532     return status;
533 }
534 
535 
rsn_removedDefKeys(TI_HANDLE hRsn)536 TI_STATUS rsn_removedDefKeys (TI_HANDLE hRsn)
537 {
538     TI_UINT8  keyIndex;
539     rsn_t  *pRsn = (rsn_t*)hRsn;
540 
541     TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removedDefKeys Enter \n");
542 
543     for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
544     {
545         TSecurityKeys   key;
546 
547         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removedDefKeys, Remove keyId=%d\n", keyIndex);
548 
549         pRsn->wepDefaultKeys[keyIndex] = TI_FALSE;
550         os_memoryCopy (pRsn->hOs, &key, &pRsn->keys[keyIndex], sizeof(TSecurityKeys));
551         pRsn->removeKey (pRsn, &key);
552 
553         /* Set WEP transmit key mask on the default key */
554         if (keyIndex == pRsn->defaultKeyId)
555         {
556             pRsn->defaultKeyId = 0;
557         }
558     }
559 
560     return TI_OK;
561 }
562 
563 
564 /**
565 *
566 * rsn_Stop - Stop event for the rsniation SM
567 *
568 * \b Description:
569 *
570 * Stop event for the rsniation SM
571 *
572 * \b ARGS:
573 *
574 *  I   - hRsn - Rsniation SM context  \n
575 *
576 * \b RETURNS:
577 *
578 *  TI_OK if successful, TI_NOK otherwise.
579 *
580 * \sa rsn_Start, rsn_Recv
581 */
rsn_stop(TI_HANDLE hRsn,TI_BOOL removeKeys)582 TI_STATUS rsn_stop (TI_HANDLE hRsn, TI_BOOL removeKeys)
583 {
584     TI_STATUS        status;
585     rsn_t           *pRsn;
586     TI_UINT8            keyIndex;
587     TSecurityKeys   key;
588 
589     pRsn = (rsn_t*)hRsn;
590 
591     if (pRsn == NULL)
592     {
593         return TI_NOK;
594     }
595 
596     TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: calling STOP... removeKeys=%d\n", removeKeys);
597 
598     for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
599     {
600         os_memoryCopy (pRsn->hOs, &key, &pRsn->keys[keyIndex], sizeof(TSecurityKeys));
601         key.keyIndex = keyIndex;
602 
603         if (!pRsn->wepDefaultKeys[keyIndex])
604         {	/* Remove only dynamic keys. Default keys are removed by calling: rsn_removedDefKeys() */
605             TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_stop, Remove keyIndex=%d, key.keyIndex=%d\n",keyIndex, key.keyIndex);
606 
607             TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)key.macAddress, 6);
608 
609             pRsn->removeKey (pRsn, &key);
610         }
611 
612     }
613 
614     tmr_StopTimer (pRsn->hMicFailureReportWaitTimer);
615 
616     /* Stop the pre-authentication timer in case we are disconnecting */
617     tmr_StopTimer (pRsn->pAdmCtrl->hPreAuthTimerWpa2);
618 
619     status = pRsn->pMainSecSm->stop (pRsn->pMainSecSm);
620 
621     pRsn->eGroupKeyUpdate = GROUP_KEY_UPDATE_FALSE;
622     pRsn->ePairwiseKeyUpdate = PAIRWISE_KEY_UPDATE_FALSE;
623     pRsn->defaultKeysOn = TI_TRUE;
624 
625 #ifdef XCC_MODULE_INCLUDED
626 	pRsn->pAdmCtrl->networkEapMode = OS_XCC_NETWORK_EAP_OFF;
627 #endif
628 
629     if (removeKeys)
630     {   /* reset PMKID list if exist */
631         pRsn->pAdmCtrl->resetPmkidList (pRsn->pAdmCtrl);
632         /* reset unicast and broadcast ciphers after disconnect */
633         pRsn->pAdmCtrl->unicastSuite = TWD_CIPHER_NONE;
634         pRsn->pAdmCtrl->broadcastSuite = TWD_CIPHER_NONE;
635     }
636 
637     return status;
638 }
639 
rsn_getParamEncryptionStatus(TI_HANDLE hRsn,ECipherSuite * rsnStatus)640 TI_STATUS rsn_getParamEncryptionStatus(TI_HANDLE hRsn, ECipherSuite *rsnStatus)
641 { /* RSN_ENCRYPTION_STATUS_PARAM */
642     rsn_t       *pRsn = (rsn_t *)hRsn;
643     TI_STATUS   status = TI_NOK;
644 
645     if ( (NULL == pRsn) || (NULL == rsnStatus) )
646     {
647         return status;
648     }
649     status = pRsn->pAdmCtrl->getCipherSuite(pRsn->pAdmCtrl, rsnStatus);
650     return status;
651 }
652 
653 /**
654 *
655 * rsn_GetParam - Get a specific parameter from the rsniation SM
656 *
657 * \b Description:
658 *
659 * Get a specific parameter from the rsniation SM.
660 *
661 * \b ARGS:
662 *
663 *  I   - hRsn - Rsniation SM context  \n
664 *  I/O - pParam - Parameter \n
665 *
666 * \b RETURNS:
667 *
668 *  TI_OK if successful, TI_NOK otherwise.
669 *
670 * \sa rsn_Start, rsn_Stop
671 */
rsn_getParam(TI_HANDLE hRsn,void * param)672 TI_STATUS rsn_getParam(TI_HANDLE hRsn, void *param)
673 {
674     rsn_t       *pRsn = (rsn_t *)hRsn;
675     paramInfo_t *pParam = (paramInfo_t *)param;
676     TI_STATUS   status = TI_OK;
677 
678     if ( (NULL == pRsn) || (NULL == pParam) )
679     {
680         return TI_NOK;
681     }
682 
683     switch (pParam->paramType)
684     {
685     case RSN_PRIVACY_OPTION_IMPLEMENTED_PARAM:
686         pParam->content.rsnPrivacyOptionImplemented = TI_TRUE;
687         break;
688 
689     case RSN_KEY_PARAM:
690         pParam->content.pRsnKey = &pRsn->keys[pParam->content.pRsnKey->keyIndex];
691         if (pParam->content.pRsnKey->keyIndex == pRsn->defaultKeyId)
692         {
693             pParam->content.pRsnKey->keyIndex |= 0x80000000;
694             TRACE1(pRsn->hReport, REPORT_SEVERITY_WARNING, "default Key: %d\n", pRsn->defaultKeyId);
695         }
696         break;
697 
698     case RSN_SECURITY_STATE_PARAM:
699         status = pRsn->pMainSecSm->getAuthState (pRsn->pMainSecSm, (TIWLN_SECURITY_STATE*)&(pParam->content.rsnAuthState));
700         break;
701 
702     case RSN_ENCRYPTION_STATUS_PARAM:
703         status = pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &pParam->content.rsnEncryptionStatus);
704         break;
705 
706     case RSN_EXT_AUTHENTICATION_MODE:
707         status = pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &pParam->content.rsnExtAuthneticationMode);
708         break;
709 
710     case RSN_MIXED_MODE:
711         status = pRsn->pAdmCtrl->getMixedMode (pRsn->pAdmCtrl, &pParam->content.rsnMixedMode);
712         break;
713 
714     case RSN_AUTH_ENCR_CAPABILITY:
715         status = pRsn->pAdmCtrl->getAuthEncrCap(pRsn->pAdmCtrl, pParam->content.pRsnAuthEncrCapability);
716         break;
717 
718     case RSN_PMKID_LIST:
719         pParam->content.rsnPMKIDList.Length = pParam->paramLength;
720         status = pRsn->pAdmCtrl->getPmkidList (pRsn->pAdmCtrl, &pParam->content.rsnPMKIDList);
721         pParam->paramLength = pParam->content.rsnPMKIDList.Length + 2 * sizeof(TI_UINT32);
722         break;
723 
724     case RSN_PRE_AUTH_STATUS:
725         {
726             TI_UINT8 cacheIndex;
727 
728             pParam->content.rsnPreAuthStatus = pRsn->pAdmCtrl->getPreAuthStatus (pRsn->pAdmCtrl, &pParam->content.rsnApMac, &cacheIndex);
729         }
730         break;
731 
732     case  RSN_WPA_PROMOTE_AVAILABLE_OPTIONS:
733         status = pRsn->pAdmCtrl->getWPAMixedModeSupport (pRsn->pAdmCtrl, &pParam->content.rsnWPAMixedModeSupport);
734         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get WPA Mixed MODE support  %d \n",pParam->content.rsnWPAMixedModeSupport);
735         break;
736 
737     case RSN_WPA_PROMOTE_OPTIONS:
738         status = pRsn->pAdmCtrl->getPromoteFlags (pRsn->pAdmCtrl,
739                                                   &pParam->content.rsnWPAPromoteFlags);
740                 TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get WPA promote flags  %d \n",pParam->content.rsnWPAPromoteFlags);
741 
742         break;
743 
744 #ifdef XCC_MODULE_INCLUDED
745     case RSN_XCC_NETWORK_EAP:
746         status = pRsn->pAdmCtrl->getNetworkEap (pRsn->pAdmCtrl, &pParam->content.networkEap);
747         break;
748 #endif
749     case RSN_EAP_TYPE:
750         pParam->content.eapType = pRsn->eapType;
751         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get RSN_EAP_TYPE eapType  %d \n", pParam->content.eapType);
752         break;
753 
754     case WPA_801_1X_AKM_EXISTS:
755 
756         status = pRsn->pAdmCtrl->get802_1x_AkmExists(pRsn->pAdmCtrl, &pParam->content.wpa_802_1x_AkmExists);
757         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get WPA_801_1X_AKM_EXISTS  %d \n", pParam->content.wpa_802_1x_AkmExists);
758         break;
759 
760     case RSN_DEFAULT_KEY_ID:
761         pParam->content.rsnDefaultKeyID = pRsn->defaultKeyId;
762         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get RSN_DEFAULT_KEY_ID  %d \n", pParam->content.rsnDefaultKeyID);
763         break;
764 
765     case RSN_PORT_STATUS_PARAM:
766 		TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get Port Status\n"  );
767 
768 		if (pRsn->bRsnExternalMode) {
769 				pParam->content.rsnPortStatus = pRsn->getPortStatus( pRsn );
770 		} else {
771 				status = TI_NOK;
772 		}
773         break;
774 
775     case RSN_EXTERNAL_MODE_PARAM:
776 		TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get External Mode\n"  );
777 
778 		pParam->content.rsnExternalMode = pRsn->bRsnExternalMode;
779         break;
780 
781     default:
782         return TI_NOK;
783     }
784 
785     return status;
786 }
787 
788 
789 /**
790 *
791 * rsn_SetParam - Set a specific parameter to the rsniation SM
792 *
793 * \b Description:
794 *
795 * Set a specific parameter to the rsniation SM.
796 *
797 * \b ARGS:
798 *
799 *  I   - hRsn - Rsniation SM context  \n
800 *  I/O - pParam - Parameter \n
801 *
802 * \b RETURNS:
803 *
804 *  TI_OK if successful, TI_NOK otherwise.
805 *
806 * \sa rsn_Start, rsn_Stop
807 */
rsn_setParam(TI_HANDLE hRsn,void * param)808 TI_STATUS rsn_setParam (TI_HANDLE hRsn, void *param)
809 {
810     rsn_t               *pRsn;
811     paramInfo_t         *pParam = (paramInfo_t*)param;
812     TTwdParamInfo       tTwdParam;
813     TI_STATUS           status = TI_OK;
814 
815     pRsn = (rsn_t*)hRsn;
816 
817     if ( (NULL == pRsn) || (NULL == pParam) )
818     {
819         return TI_NOK;
820     }
821 
822     TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set rsn_setParam   %X \n", pParam->paramType);
823 
824     switch (pParam->paramType)
825     {
826 
827     case RSN_DEFAULT_KEY_ID:
828     {
829         TI_UINT8  defKeyId, i;
830 
831         defKeyId = pParam->content.rsnDefaultKeyID;
832 
833         if(defKeyId >= MAX_KEYS_NUM)
834         {
835             TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "RSN: Error - the value of the default Key Id  is incorrect \n");
836             return TI_NOK;
837         }
838 
839         /* Clean transmit flag (1 in the bit31) in the previous default key */
840         for(i = 0; i < MAX_KEYS_NUM; i++)
841         {
842             pRsn->keys[i].keyIndex &= 0x7FFFFFFF;
843         }
844 
845         /* Set the default key ID value in the RSN data structure */
846         pRsn->defaultKeyId = defKeyId;
847 
848         /* Set the default key ID in the HAL */
849         tTwdParam.paramType = TWD_RSN_DEFAULT_KEY_ID_PARAM_ID;
850         tTwdParam.content.configureCmdCBParams.pCb = &pRsn->defaultKeyId;
851         tTwdParam.content.configureCmdCBParams.fCb = NULL;
852         tTwdParam.content.configureCmdCBParams.hCb = NULL;
853         status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
854 
855         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: default key ID =%d \n", pRsn->defaultKeyId);
856 
857         sme_Restart (pRsn->hSmeSm);
858         break;
859     }
860 
861     case RSN_ADD_KEY_PARAM:
862     {
863         TI_UINT8           keyIndex, i = 0;
864         ECipherSuite   cipherSuite;
865 
866         status = pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &cipherSuite);
867         if (status !=TI_OK)
868         {
869             return status;
870         }
871 
872         TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_ADD_KEY_PARAM KeyIndex  %x , keyLength=%d\n", pParam->content.rsnOsKey.KeyIndex,pParam->content.rsnOsKey.KeyLength);
873         keyIndex = (TI_UINT8)pParam->content.rsnOsKey.KeyIndex;
874         if (keyIndex >= MAX_KEYS_NUM)
875         {
876 			return TI_NOK;
877         }
878 
879 		status = pRsn->pKeyParser->recv (pRsn->pKeyParser, (TI_UINT8*)&pParam->content.rsnOsKey, sizeof(pParam->content.rsnOsKey));
880 
881         if (status != TI_OK)
882         {
883 TRACE1(pRsn->hReport, REPORT_SEVERITY_WARNING, ": pRsn->pKeyParser->recv satus returned with status=%x. returning with NOK\n", status);
884             return TI_NOK;
885         }
886 
887         /* If the Key is not BAD, it may be that WEP key is sent before WEP status is set,
888             save the key, and set it later at rsn_start */
889 
890 		/* If default Key not cleaned by calling rsn_removedDefKeys for keyIndex, Clean it */
891 		if (pRsn->wepDefaultKeys[keyIndex] == TI_TRUE)
892 		{
893 			TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "Set RSN_ADD_KEY_PARAM KeyIndex  %x\n", keyIndex);
894 			TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "Set RSN_ADD_KEY_PARAM wepDefaultKeys=%d\n", pRsn->wepDefaultKeys[keyIndex]);
895 
896 			pRsn->wepDefaultKeys[keyIndex] = TI_FALSE;
897 
898 		}
899 
900 		pRsn->keys[keyIndex].keyIndex = pParam->content.rsnOsKey.KeyIndex;
901 		pRsn->keys[keyIndex].encLen = pParam->content.rsnOsKey.KeyLength;
902 		MAC_COPY (pRsn->keys[keyIndex].macAddress, pParam->content.rsnOsKey.BSSID);
903 		os_memoryCopy (pRsn->hOs, (void *)pRsn->keys[keyIndex].keyRsc, (TI_UINT8*)&(pParam->content.rsnOsKey.KeyRSC), KEY_RSC_LEN);
904 		os_memoryCopy (pRsn->hOs, (void *)pRsn->keys[keyIndex].encKey, pParam->content.rsnOsKey.KeyMaterial, MAX_KEY_LEN);
905 
906         /* Process the transmit flag (31-st bit of keyIndex).        */
907         /* If the added key has the TX bit set to TI_TRUE (i.e. the key */
908         /* is the new transmit key (default key), update             */
909         /* RSN data def.key Id and clean this bit in all other keys  */
910         if (pParam->content.rsnOsKey.KeyIndex & 0x80000000)
911         {
912             pRsn->defaultKeyId = keyIndex;
913 
914             for (i = 0; i < MAX_KEYS_NUM; i ++)
915             {
916                 if (i != keyIndex)
917                 {
918                     pRsn->keys[i].keyIndex &= 0x7FFFFFFF;
919                 }
920             }
921         }
922 
923         if (pRsn->defaultKeysOn)
924         {   /* This is a WEP default key */
925             TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN_ADD_KEY_PARAM, Default key configured - keyIndex=%d-TI_TRUE\n", keyIndex);
926 
927             pRsn->wepDefaultKeys[keyIndex] = TI_TRUE;
928             pRsn->wepStaticKey = TI_TRUE;
929             status = TI_OK;
930         }
931         break;
932     }
933     case RSN_REMOVE_KEY_PARAM:
934     {
935         TI_UINT8           keyIndex;
936         ECipherSuite   cipherSuite;
937 
938         status = pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &cipherSuite);
939         if (status !=TI_OK)
940         {
941             return status;
942         }
943         /*if (cipherSuite == RSN_CIPHER_NONE)
944         {
945             TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "RSN: Error Remove Wep/Key when no encryption \n");
946             return TI_NOK;
947         }*/
948 
949         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_REMOVE_KEY_PARAM KeyIndex  %x \n", pParam->content.rsnOsKey.KeyIndex);
950         keyIndex = (TI_UINT8)pParam->content.rsnOsKey.KeyIndex;
951         if (keyIndex >= MAX_KEYS_NUM)
952         {
953             return TI_NOK;
954         }
955 
956         status = pRsn->pKeyParser->remove (pRsn->pKeyParser,
957                                            (TI_UINT8*)&pParam->content.rsnOsKey,
958                                            sizeof(pParam->content.rsnOsKey));
959 
960         if (status == TI_OK)
961         {
962             pRsn->keys[keyIndex].keyType = KEY_NULL;
963             pRsn->keys[keyIndex].keyIndex &= 0x000000FF;
964         }
965 
966         break;
967     }
968 
969     case RSN_ENCRYPTION_STATUS_PARAM:
970         {
971             ECipherSuite   cipherSuite;
972 
973             TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_ENCRYPTION_STATUS_PARAM rsnEncryptionStatus  %d \n", pParam->content.rsnEncryptionStatus);
974 
975             pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &cipherSuite);
976             if (cipherSuite != pParam->content.rsnEncryptionStatus)
977             {
978                 status = pRsn->pAdmCtrl->setUcastSuite (pRsn->pAdmCtrl, pParam->content.rsnEncryptionStatus);
979                 status = pRsn->pAdmCtrl->setBcastSuite (pRsn->pAdmCtrl, pParam->content.rsnEncryptionStatus);
980                 TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, " status = %d \n", status);
981             }
982             pRsn->defaultKeysOn = TI_TRUE;
983         }
984         break;
985 
986     case RSN_EXT_AUTHENTICATION_MODE:
987         {
988             EExternalAuthMode  extAuthMode;
989 
990             pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &extAuthMode);
991             if (pParam->content.rsnExtAuthneticationMode!=extAuthMode)
992             {
993                 TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_EXT_AUTHENTICATION_MODE rsnExtAuthneticationMode  %d \n", pParam->content.rsnExtAuthneticationMode);
994 
995                 /*
996 TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: remove all Keys\n");
997 
998                 for (keyIndex=0; keyIndex<MAX_KEYS_NUM; keyIndex++)
999                 {
1000                     os_memoryCopy(pRsn->hOs, &key, &pRsn->keys[keyIndex], sizeof(TSecurityKeys));
1001                     pRsn->removeKey(pRsn, &key);
1002 
1003                 }*/
1004 
1005                 status = pRsn->pAdmCtrl->setExtAuthMode (pRsn->pAdmCtrl, pParam->content.rsnExtAuthneticationMode);
1006             }
1007             pRsn->defaultKeysOn = TI_TRUE;
1008         }
1009         break;
1010 
1011 #ifdef XCC_MODULE_INCLUDED
1012     case RSN_XCC_NETWORK_EAP:
1013         {
1014             OS_XCC_NETWORK_EAP      networkEap;
1015 
1016             pRsn->pAdmCtrl->getNetworkEap (pRsn->pAdmCtrl, &networkEap);
1017             if (networkEap != pParam->content.networkEap)
1018             {
1019                 TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_XCC_NETWORK_EAP networkEap  %d \n", pParam->content.networkEap);
1020 
1021                 status = pRsn->pAdmCtrl->setNetworkEap (pRsn->pAdmCtrl, pParam->content.networkEap);
1022                 if (status == TI_OK)
1023                 {
1024                     /*status = RE_SCAN_NEEDED;*/
1025                 }
1026             }
1027         }
1028         break;
1029 #endif
1030     case RSN_MIXED_MODE:
1031         {
1032             TI_BOOL mixedMode;
1033 
1034             pRsn->pAdmCtrl->getMixedMode (pRsn->pAdmCtrl, &mixedMode);
1035             if (mixedMode!=pParam->content.rsnMixedMode)
1036             {
1037                 status = pRsn->pAdmCtrl->setMixedMode (pRsn->pAdmCtrl, pParam->content.rsnMixedMode);
1038 
1039                 TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_MIXED_MODE mixedMode  %d, status=%d \n", pParam->content.rsnMixedMode, status);
1040             }
1041             break;
1042         }
1043 
1044     case RSN_PMKID_LIST:
1045         TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_PMKID_LIST \n");
1046 
1047         TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8*)&pParam->content.rsnPMKIDList ,sizeof(OS_802_11_PMKID));
1048          status = pRsn->pAdmCtrl->setPmkidList (pRsn->pAdmCtrl,
1049                                                 &pParam->content.rsnPMKIDList);
1050          if(status == TI_OK)
1051          {
1052             TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_PMKID_LIST:   %d PMKID entries has been added to the cache.\n", pParam->content.rsnPMKIDList.BSSIDInfoCount);
1053          }
1054          else
1055          {
1056             TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_PMKID_LIST failure");
1057          }
1058         break;
1059 
1060     case RSN_WPA_PROMOTE_OPTIONS:
1061          status = pRsn->pAdmCtrl->setPromoteFlags (pRsn->pAdmCtrl,
1062                                                    pParam->content.rsnWPAPromoteFlags);
1063          if(status == TI_OK)
1064          {
1065             TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set WPA promote options:  %d \n", pParam->content.rsnWPAPromoteFlags);
1066          }
1067          else
1068          {
1069             TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set WPA promote options failure");
1070          }
1071         break;
1072 
1073     case RSN_EAP_TYPE:
1074         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_EAP_TYPE eapType  %d \n", pParam->content.eapType);
1075 
1076         pRsn->eapType = pParam->content.eapType;
1077 	pRsn->defaultKeysOn = TI_TRUE;
1078         break;
1079 
1080     case RSN_SET_KEY_PARAM:
1081         {
1082             TSecurityKeys *pSecurityKey = pParam->content.pRsnKey;
1083             TI_UINT32     keyIndex;
1084             TI_UINT8      j=0;
1085 
1086             TRACE2(pRsn->hReport,REPORT_SEVERITY_INFORMATION,"RSN:Set RSN_SET_KEY_PARAM KeyIndex %x,keyLength=%d\n",pSecurityKey->keyIndex,pSecurityKey->encLen);
1087 
1088             if(pSecurityKey->keyIndex >= MAX_KEYS_NUM)
1089             {
1090                 return TI_NOK;
1091             }
1092 
1093            keyIndex = (TI_UINT8)pSecurityKey->keyIndex;
1094 		/* Remove the key when the length is 0, or the type is not set */
1095 		   if ( (pSecurityKey->keyType == KEY_NULL) ||
1096 				 (pSecurityKey->encLen == 0))
1097 		   {
1098 				/* Clearing a key */
1099 				status = rsn_removeKey( pRsn, pSecurityKey );
1100 				break;
1101            }
1102 		   else
1103 		   {
1104            status = rsn_setKey (pRsn, pSecurityKey);  /* send key to FW*/
1105 
1106            if (status == TI_OK)
1107            {
1108                //os_memoryCopy(pKeyDerive->hOs,&pRsn->pKeyParser->pUcastKey/pBcastKey, pEncodedKey, sizeof(encodedKeyMaterial_t));
1109            } /* check this copy */
1110 
1111 
1112            /* If the Key is not BAD, it may be that WEP key is sent before WEP status is set,
1113            save the key, and set it later at rsn_start */
1114 
1115            pRsn->keys[keyIndex].keyIndex = pSecurityKey->keyIndex;
1116            pRsn->keys[keyIndex].encLen = pSecurityKey->encLen;
1117            MAC_COPY (pRsn->keys[keyIndex].macAddress, pSecurityKey->macAddress);
1118            os_memoryCopy(pRsn->hOs,(void*)pRsn->keys[keyIndex].keyRsc, (TI_UINT8*)&(pSecurityKey->keyRsc), KEY_RSC_LEN);
1119            os_memoryCopy (pRsn->hOs, (void *)pRsn->keys[keyIndex].encKey, (void*)pSecurityKey->encKey, MAX_KEY_LEN);
1120 
1121            /* Process the transmit flag (31-st bit of keyIndex).        */
1122            /* If the added key has the TX bit set to TI_TRUE (i.e. the key */
1123            /* is the new transmit key (default key), update             */
1124            /* RSN data def.key Id and clean this bit in all other keys  */
1125            if (pSecurityKey->keyIndex & 0x80000000)
1126            {
1127                pRsn->defaultKeyId = keyIndex;
1128 
1129                for (j = 0; j < MAX_KEYS_NUM; j++)
1130                {
1131                    if (j != keyIndex)
1132                    {
1133                        pRsn->keys[j].keyIndex &= 0x7FFFFFFF;
1134                    }
1135                }
1136            }
1137 
1138            if (pRsn->defaultKeysOn)
1139            {   /* This is a WEP default key */
1140                TRACE1(pRsn->hReport,REPORT_SEVERITY_INFORMATION, "RSN_SET_KEY_PARAM, Default key configured-keyIndex=%d-TI_TRUE\n", keyIndex);
1141 
1142                pRsn->wepDefaultKeys[keyIndex] = TI_TRUE;
1143                pRsn->wepStaticKey = TI_TRUE;
1144                status = TI_OK;
1145            }
1146            break;
1147         }
1148        }
1149        break;
1150 
1151 
1152     case RSN_PORT_STATUS_PARAM:
1153             TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set Port Status %d \n", pParam->content.rsnPortStatus);
1154 
1155             if (pRsn->bRsnExternalMode) {
1156                     status = pRsn->setPortStatus( hRsn, pParam->content.rsnPortStatus );
1157             } else {
1158                     status = TI_NOK;
1159             }
1160             break;
1161 
1162     case RSN_GENERIC_IE_PARAM:
1163             TRACE4(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set Generic IE: length=%d, IE=%02x%02x%02x... \n",
1164                    pParam->content.rsnGenericIE.length,
1165                pParam->content.rsnGenericIE.data[0], pParam->content.rsnGenericIE.data[1],pParam->content.rsnGenericIE.data[2] );
1166 
1167             status = TI_OK;
1168 
1169             /* make sure it's a valid IE: datal-ength > 2 AND a matching length field */
1170             if ((pParam->content.rsnGenericIE.length > 2) &&
1171                 ((pParam->content.rsnGenericIE.data[1] + 2) == pParam->content.rsnGenericIE.length)) {
1172                     /* Setting the IE */
1173                     pRsn->genericIE.length = pParam->content.rsnGenericIE.length;
1174                     os_memoryCopy(pRsn->hOs,(void*)pRsn->genericIE.data, (TI_UINT8*)pParam->content.rsnGenericIE.data, pParam->content.rsnGenericIE.length);
1175             } else if ( pParam->content.rsnGenericIE.length == 0 ) {
1176                     /* Deleting the IE */
1177                     pRsn->genericIE.length = pParam->content.rsnGenericIE.length;
1178             } else {
1179                     TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "RSN: Set Generic IE: FAILED sanity checks \n" );
1180                     status = TI_NOK;
1181             }
1182 	    break;
1183 
1184     case RSN_EXTERNAL_MODE_PARAM:
1185 		TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set External Mode\n"  );
1186 
1187 		pRsn->bRsnExternalMode = pParam->content.rsnExternalMode;
1188             break;
1189 
1190     default:
1191         return TI_NOK;
1192     }
1193 
1194     return status;
1195 }
1196 
1197 
1198 /**
1199 *
1200 * rsn_eventRecv - Set a specific parameter to the rsniation SM
1201 *
1202 * \b Description:
1203 *
1204 * Set a specific parameter to the rsniation SM.
1205 *
1206 * \b ARGS:
1207 *
1208 *  I   - hRsn - Rsniation SM context  \n
1209 *  I/O - pParam - Parameter \n
1210 *
1211 * \b RETURNS:
1212 *
1213 *  TI_OK if successful, TI_NOK otherwise.
1214 *
1215 * \sa rsn_Start, rsn_Stop
1216 */
rsn_reportStatus(rsn_t * pRsn,TI_STATUS rsnStatus)1217 TI_STATUS rsn_reportStatus (rsn_t *pRsn, TI_STATUS rsnStatus)
1218 {
1219     TI_STATUS           status = TI_OK;
1220     paramInfo_t         param;
1221     EExternalAuthMode   extAuthMode;
1222 
1223     if (pRsn == NULL)
1224     {
1225         return TI_NOK;
1226     }
1227 
1228     if (rsnStatus == TI_OK)
1229     {
1230         /* set EAPOL encryption status according to authentication protocol */
1231         pRsn->rsnCompletedTs = os_timeStampMs (pRsn->hOs);
1232 
1233         status = pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &extAuthMode);
1234         if (status != TI_OK)
1235         {
1236             return status;
1237         }
1238 
1239         if (extAuthMode >= RSN_EXT_AUTH_MODE_WPA)
1240 			txCtrlParams_setEapolEncryptionStatus (pRsn->hTxCtrl, TI_TRUE);
1241 		else
1242 			txCtrlParams_setEapolEncryptionStatus (pRsn->hTxCtrl, TI_FALSE);
1243 
1244         /* set WEP invoked mode according to cipher suite */
1245         switch (pRsn->paeConfig.unicastSuite)
1246         {
1247         case TWD_CIPHER_NONE:
1248             param.content.txDataCurrentPrivacyInvokedMode = TI_FALSE;
1249             break;
1250 
1251         default:
1252             param.content.txDataCurrentPrivacyInvokedMode = TI_TRUE;
1253             break;
1254         }
1255 
1256 		if (pRsn->bRsnExternalMode) {
1257 				param.content.txDataCurrentPrivacyInvokedMode = TI_TRUE;
1258                 txCtrlParams_setEapolEncryptionStatus (pRsn->hTxCtrl, TI_FALSE);
1259 		}
1260 
1261 		txCtrlParams_setCurrentPrivacyInvokedMode(pRsn->hTxCtrl, param.content.txDataCurrentPrivacyInvokedMode);
1262         /* The value of exclude unencrypted should be as privacy invoked */
1263         param.paramType = RX_DATA_EXCLUDE_UNENCRYPTED_PARAM;
1264         rxData_setParam (pRsn->hRx, &param);
1265 
1266         param.paramType = RX_DATA_EXCLUDE_BROADCAST_UNENCRYPTED_PARAM;
1267         if (pRsn->pAdmCtrl->mixedMode)
1268         {   /* do not exclude Broadcast packets */
1269             param.content.txDataCurrentPrivacyInvokedMode = TI_FALSE;
1270         }
1271         rxData_setParam (pRsn->hRx, &param);
1272     }
1273 
1274     else
1275         rsnStatus = (TI_STATUS)STATUS_SECURITY_FAILURE;
1276 
1277     status = conn_reportRsnStatus (pRsn->hConn, (mgmtStatus_e)rsnStatus);
1278 
1279     if (status!=TI_OK)
1280     {
1281         return status;
1282     }
1283 
1284     if (rsnStatus == TI_OK)
1285     {
1286         EvHandlerSendEvent (pRsn->hEvHandler, IPC_EVENT_AUTH_SUCC, NULL, 0);
1287     }
1288 
1289     TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_reportStatus \n");
1290 
1291     return TI_OK;
1292 }
1293 
1294 
1295 /**
1296 *
1297 * rsn_eventRecv - Set a specific parameter to the rsniation SM
1298 *
1299 * \b Description:
1300 *
1301 * Set a specific parameter to the rsniation SM.
1302 *
1303 * \b ARGS:
1304 *
1305 *  I   - hRsn - Rsniation SM context  \n
1306 *  I/O - pParam - Parameter \n
1307 *
1308 * \b RETURNS:
1309 *
1310 *  TI_OK if successful, TI_NOK otherwise.
1311 *
1312 * \sa rsn_Start, rsn_Stop
1313 */
rsn_setPaeConfig(rsn_t * pRsn,TRsnPaeConfig * pPaeConfig)1314 TI_STATUS rsn_setPaeConfig(rsn_t *pRsn, TRsnPaeConfig *pPaeConfig)
1315 {
1316     TI_STATUS           status;
1317     mainSecInitData_t   initData;
1318 
1319     if ( (NULL == pRsn) || (NULL == pPaeConfig) )
1320     {
1321         return TI_NOK;
1322     }
1323 
1324     TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Calling set PAE config..., unicastSuite = %d, broadcastSuite = %d \n", pPaeConfig->unicastSuite, pPaeConfig->broadcastSuite);
1325 
1326     os_memoryCopy(pRsn->hOs, &pRsn->paeConfig, pPaeConfig, sizeof(TRsnPaeConfig));
1327 
1328     initData.pPaeConfig = &pRsn->paeConfig;
1329 
1330     status = mainSec_config (pRsn->pMainSecSm,
1331                              &initData,
1332                              pRsn,
1333                              pRsn->hReport,
1334                              pRsn->hOs,
1335                              pRsn->hCtrlData,
1336                              pRsn->hEvHandler,
1337                              pRsn->hConn,
1338                              pRsn->hTimer);
1339 
1340     return status;
1341 }
1342 
1343 
1344 /**
1345 *
1346 * rsn_eventRecv - Set a specific parameter to the rsniation SM
1347 *
1348 * \b Description:
1349 *
1350 * Set a specific parameter to the rsniation SM.
1351 *
1352 * \b ARGS:
1353 *
1354 *  I   - hRsn - Rsniation SM context  \n
1355 *  I/O - pParam - Parameter \n
1356 *
1357 * \b RETURNS:
1358 *
1359 *  TI_OK if successful, TI_NOK otherwise.
1360 *
1361 * \sa rsn_Start, rsn_Stop
1362 */
rsn_getNetworkMode(rsn_t * pRsn,ERsnNetworkMode * pNetMode)1363 TI_STATUS rsn_getNetworkMode(rsn_t *pRsn, ERsnNetworkMode *pNetMode)
1364 {
1365     paramInfo_t     param;
1366     TI_STATUS       status;
1367 
1368     param.paramType = CTRL_DATA_CURRENT_BSS_TYPE_PARAM;
1369 
1370     status =  ctrlData_getParam (pRsn->hCtrlData, &param);
1371 
1372     if (status == TI_OK)
1373     {
1374         if (param.content.ctrlDataCurrentBssType == BSS_INFRASTRUCTURE)
1375         {
1376             *pNetMode = RSN_INFRASTRUCTURE;
1377         }
1378         else
1379         {
1380             *pNetMode = RSN_IBSS;
1381         }
1382     }
1383     else
1384     {
1385         return TI_NOK;
1386     }
1387 
1388     return TI_OK;
1389 }
1390 
1391 
1392 /**
1393 *
1394 * rsn_eventRecv - Set a specific parameter to the rsniation SM
1395 *
1396 * \b Description:
1397 *
1398 * Set a specific parameter to the rsniation SM.
1399 *
1400 * \b ARGS:
1401 *
1402 *  I   - hRsn - Rsniation SM context  \n
1403 *  I/O - pParam - Parameter \n
1404 *
1405 * \b RETURNS:
1406 *
1407 *  TI_OK if successful, TI_NOK otherwise.
1408 *
1409 * \sa rsn_Start, rsn_Stop
1410 */
rsn_evalSite(TI_HANDLE hRsn,TRsnData * pRsnData,TRsnSiteParams * pRsnSiteParams,TI_UINT32 * pMetric)1411 TI_STATUS rsn_evalSite(TI_HANDLE hRsn, TRsnData *pRsnData, TRsnSiteParams *pRsnSiteParams, TI_UINT32 *pMetric)
1412 {
1413 
1414     rsn_t       *pRsn;
1415     TI_STATUS    status;
1416 
1417     if ( (NULL == pRsnData) || (NULL == hRsn) )
1418     {
1419         *pMetric = 0;
1420         return TI_NOK;
1421     }
1422 
1423     pRsn = (rsn_t*)hRsn;
1424 
1425     if (rsn_isSiteBanned(hRsn, pRsnSiteParams->bssid) == TI_TRUE)
1426     {
1427         *pMetric = 0;
1428         TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Site is banned!\n");
1429         return TI_NOK;
1430     }
1431 
1432 	if ( pRsn->bRsnExternalMode ) {
1433 			/* In external mode, the supplicant is responsible to make sure that site security matches */
1434 			status = TI_OK;
1435 	} else {
1436     status = pRsn->pAdmCtrl->evalSite (pRsn->pAdmCtrl, pRsnData, pRsnSiteParams, pMetric);
1437 	}
1438 
1439     TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": pMetric=%d status=%d\n", *pMetric, status);
1440 
1441     return status;
1442 }
1443 
1444 
1445 /**
1446 *
1447 * rsn_getInfoElement -
1448 *
1449 * \b Description:
1450 *
1451 * Get the RSN information element.
1452 *
1453 * \b ARGS:
1454 *
1455 *  I   - hRsn - Rsn SM context  \n
1456 *  I/O - pRsnIe - Pointer to the return information element \n
1457 *  I/O - pRsnIeLen - Pointer to the returned IE's length \n
1458 *
1459 * \b RETURNS:
1460 *
1461 *  TI_OK if successful, TI_NOK otherwise.
1462 *
1463 * \sa
1464 */
rsn_getInfoElement(TI_HANDLE hRsn,TI_UINT8 * pRsnIe,TI_UINT32 * pRsnIeLen)1465 TI_STATUS rsn_getInfoElement(TI_HANDLE hRsn, TI_UINT8 *pRsnIe, TI_UINT32 *pRsnIeLen)
1466 {
1467     rsn_t       *pRsn;
1468     TI_STATUS   status;
1469     TI_UINT32   ie_len = 0;
1470 
1471     if ( (NULL == hRsn) || (NULL == pRsnIe) || (NULL == pRsnIeLen) )
1472     {
1473         return TI_NOK;
1474     }
1475 
1476     pRsn = (rsn_t*)hRsn;
1477 
1478     if (!pRsn->bRsnExternalMode)
1479 		{
1480 
1481     status = pRsn->pAdmCtrl->getInfoElement (pRsn->pAdmCtrl, pRsnIe, &ie_len);
1482 
1483     TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_getInfoElement pRsnIeLen= %d\n",*pRsnIeLen);
1484 
1485     if ( status != TI_OK ) {
1486     return status;
1487     }
1488 
1489     pRsnIe += ie_len;
1490 		}
1491 
1492     status = rsn_getGenInfoElement(hRsn, pRsnIe, pRsnIeLen);
1493 
1494     *pRsnIeLen += ie_len;
1495 
1496     return status;
1497 
1498 }
1499 
1500 
1501 #ifdef XCC_MODULE_INCLUDED
1502 /**
1503 *
1504 * rsn_getXCCExtendedInfoElement -
1505 *
1506 * \b Description:
1507 *
1508 * Get the Aironet information element.
1509 *
1510 * \b ARGS:
1511 *
1512 *  I   - hRsn - Rsn SM context  \n
1513 *  I/O - pRsnIe - Pointer to the return information element \n
1514 *  I/O - pRsnIeLen - Pointer to the returned IE's length \n
1515 *
1516 * \b RETURNS:
1517 *
1518 *  TI_OK if successful, TI_NOK otherwise.
1519 *
1520 * \sa
1521 */
rsn_getXCCExtendedInfoElement(TI_HANDLE hRsn,TI_UINT8 * pRsnIe,TI_UINT8 * pRsnIeLen)1522 TI_STATUS rsn_getXCCExtendedInfoElement(TI_HANDLE hRsn, TI_UINT8 *pRsnIe, TI_UINT8 *pRsnIeLen)
1523 {
1524     rsn_t       *pRsn;
1525     TI_STATUS   status;
1526 
1527     if ( (NULL == hRsn) || (NULL == pRsnIe) || (NULL == pRsnIeLen) )
1528     {
1529         return TI_NOK;
1530     }
1531 
1532     pRsn = (rsn_t*)hRsn;
1533 
1534     status = admCtrlXCC_getInfoElement (pRsn->pAdmCtrl, pRsnIe, pRsnIeLen);
1535 
1536     TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_getXCCExtendedInfoElement pRsnIeLen= %d\n",*pRsnIeLen);
1537 
1538     return status;
1539 }
1540 #endif
1541 
1542 
1543 /**
1544 *
1545 * rsn_eventRecv - Set a specific parameter to the rsniation SM
1546 *
1547 * \b Description:
1548 *
1549 * Set a specific parameter to the rsniation SM.
1550 *
1551 * \b ARGS:
1552 *
1553 *  I   - hRsn - Rsniation SM context  \n
1554 *  I/O - pParam - Parameter \n
1555 *
1556 * \b RETURNS:
1557 *
1558 *  TI_OK if successful, TI_NOK otherwise.
1559 *
1560 * \sa rsn_Start, rsn_Stop
1561 */
rsn_setSite(TI_HANDLE hRsn,TRsnData * pRsnData,TI_UINT8 * pAssocIe,TI_UINT8 * pAssocIeLen)1562 TI_STATUS rsn_setSite(TI_HANDLE hRsn, TRsnData *pRsnData, TI_UINT8 *pAssocIe, TI_UINT8 *pAssocIeLen)
1563 {
1564     rsn_t      *pRsn;
1565     TI_STATUS   status;
1566 
1567     if ( (NULL == pRsnData) || (NULL == hRsn) )
1568     {
1569         *pAssocIeLen = 0;
1570         return TI_NOK;
1571     }
1572 
1573     pRsn = (rsn_t*)hRsn;
1574 
1575     status = pRsn->pAdmCtrl->setSite (pRsn->pAdmCtrl, pRsnData, pAssocIe, pAssocIeLen);
1576 
1577     TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_setSite ieLen= %d\n",pRsnData->ieLen);
1578     return status;
1579 }
1580 
1581 
rsn_setKey(rsn_t * pRsn,TSecurityKeys * pKey)1582 TI_STATUS rsn_setKey (rsn_t *pRsn, TSecurityKeys *pKey)
1583 {
1584     TTwdParamInfo       tTwdParam;
1585     TI_UINT8            keyIndex;
1586     TI_BOOL				macIsBroadcast = TI_FALSE;
1587     TI_STATUS           status = TI_OK;
1588 
1589 	if (pRsn == NULL || pKey == NULL)
1590 	{
1591 		return TI_NOK;
1592 	}
1593 
1594 	keyIndex = (TI_UINT8)pKey->keyIndex;
1595     if (keyIndex >= MAX_KEYS_NUM)
1596     {
1597         return TI_NOK;
1598     }
1599 
1600     if (pKey->keyType != KEY_NULL)
1601     {
1602 
1603 			/* If in external mode, set driver's security mode according to the key */
1604 			if (pRsn->bRsnExternalMode) {
1605 					tTwdParam.paramType = TWD_RSN_SECURITY_MODE_PARAM_ID;
1606 
1607 					switch (pKey->keyType) {
1608 					case KEY_TKIP:
1609 							tTwdParam.content.rsnEncryptionStatus = (ECipherSuite)TWD_CIPHER_TKIP;
1610 							break;
1611 					case KEY_AES:
1612 							tTwdParam.content.rsnEncryptionStatus = (ECipherSuite)TWD_CIPHER_AES_CCMP;
1613 							break;
1614 #ifdef GEM_SUPPORTED
1615 					case KEY_GEM:
1616 							tTwdParam.content.rsnEncryptionStatus = (ECipherSuite)TWD_CIPHER_GEM;
1617 							status = pRsn->pAdmCtrl->setUcastSuite (pRsn->pAdmCtrl, TWD_CIPHER_GEM);
1618 							status = pRsn->pAdmCtrl->setBcastSuite (pRsn->pAdmCtrl, TWD_CIPHER_GEM);
1619 							break;
1620 #endif
1621 					case KEY_WEP:
1622 							tTwdParam.content.rsnEncryptionStatus = (ECipherSuite)TWD_CIPHER_WEP;
1623 							break;
1624 					case KEY_NULL:
1625 					case KEY_XCC:
1626 					default:
1627 							tTwdParam.content.rsnEncryptionStatus = (ECipherSuite)TWD_CIPHER_NONE;
1628 							break;
1629 					}
1630 					status = TWD_SetParam(pRsn->hTWD, &tTwdParam);
1631 					if ( status != TI_OK ) {
1632 							return status;
1633 					}
1634 			}
1635 
1636         /* set the size to reserve for encryption to the tx */
1637         /* update this parameter only in accordance with pairwise key setting */
1638        if (!MAC_BROADCAST(pKey->macAddress))
1639         {
1640 
1641         /* set the size to reserve for encryption to the tx */
1642             switch (pKey->keyType)
1643             {
1644                 case KEY_TKIP:
1645 			        txCtrlParams_setEncryptionFieldSizes (pRsn->hTxCtrl, IV_FIELD_SIZE);
1646                     break;
1647                 case KEY_AES:
1648 			        txCtrlParams_setEncryptionFieldSizes (pRsn->hTxCtrl, AES_AFTER_HEADER_FIELD_SIZE);
1649                     break;
1650 #ifdef GEM_SUPPORTED
1651 			    case KEY_GEM:
1652 #endif
1653                 case KEY_WEP:
1654                 case KEY_NULL:
1655                 case KEY_XCC:
1656                 default:
1657 			        txCtrlParams_setEncryptionFieldSizes (pRsn->hTxCtrl, 0);
1658                     break;
1659             }
1660 
1661         }
1662 
1663         pRsn->keys[keyIndex].keyType = pKey->keyType;
1664         pRsn->keys[keyIndex].keyIndex = keyIndex;
1665 
1666 		if (!pRsn->bRsnExternalMode) {
1667 
1668         macIsBroadcast = MAC_BROADCAST (pKey->macAddress);
1669 		if ((pRsn->keys[keyIndex].keyType != KEY_NULL )&&
1670 			macIsBroadcast && !MAC_BROADCAST((pRsn->keys[keyIndex].macAddress)))
1671 		{	/* In case a new Group key is set instead of a Unicast key,
1672 			first remove the UNIcast key from FW */
1673 			rsn_removeKey(pRsn, &pRsn->keys[keyIndex]);
1674 		}
1675 
1676 		if (macIsBroadcast)
1677         {
1678             TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setKey, Group ReKey timer started\n");
1679             tmr_StopTimer (pRsn->hMicFailureGroupReKeyTimer);
1680             tmr_StartTimer (pRsn->hMicFailureGroupReKeyTimer,
1681                             rsn_groupReKeyTimeout,
1682                             (TI_HANDLE)pRsn,
1683                             RSN_MIC_FAILURE_RE_KEY_TIMEOUT,
1684                             TI_FALSE);
1685             pRsn->eGroupKeyUpdate = GROUP_KEY_UPDATE_TRUE;
1686         }
1687 		else
1688         {
1689 			if (pRsn->bPairwiseMicFailureFilter)	/* the value of this flag is taken from registry */
1690 			{
1691 				TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setKey, Pairwise ReKey timer started\n");
1692 				tmr_StopTimer (pRsn->hMicFailurePairwiseReKeyTimer);
1693 				tmr_StartTimer (pRsn->hMicFailurePairwiseReKeyTimer,
1694 								rsn_pairwiseReKeyTimeout,
1695 								(TI_HANDLE)pRsn,
1696 								RSN_MIC_FAILURE_RE_KEY_TIMEOUT,
1697 								TI_FALSE);
1698 				pRsn->ePairwiseKeyUpdate = PAIRWISE_KEY_UPDATE_TRUE;
1699 			}
1700         }
1701 		}
1702 
1703         /* Mark key as added */
1704         pRsn->keys_en [keyIndex] = TI_TRUE;
1705 
1706         tTwdParam.paramType = TWD_RSN_KEY_ADD_PARAM_ID;
1707         tTwdParam.content.configureCmdCBParams.pCb = (TI_UINT8*) pKey;
1708         tTwdParam.content.configureCmdCBParams.fCb = NULL;
1709         tTwdParam.content.configureCmdCBParams.hCb = NULL;
1710         status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
1711     TRACE3(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setKey, KeyType=%d, KeyId = 0x%lx,encLen=0x%x\n", pKey->keyType,pKey->keyIndex, pKey->encLen);
1712 
1713     TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nEncKey = ");
1714 
1715     TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->encKey, pKey->encLen);
1716 
1717     if (pKey->keyType != KEY_WEP)
1718     {
1719         TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nMac address = ");
1720         TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->macAddress, MAC_ADDR_LEN);
1721         TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nRSC = ");
1722         TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->keyRsc, KEY_RSC_LEN);
1723         TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nMic RX = ");
1724         TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->micRxKey, MAX_KEY_LEN);
1725         TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nMic TX = ");
1726         TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->micTxKey, MAX_KEY_LEN);
1727     }
1728     }
1729 
1730     return status;
1731 }
1732 
1733 
rsn_removeKey(rsn_t * pRsn,TSecurityKeys * pKey)1734 TI_STATUS rsn_removeKey (rsn_t *pRsn, TSecurityKeys *pKey)
1735 {
1736     TI_STATUS           status = TI_OK;
1737     TTwdParamInfo       tTwdParam;
1738     TI_UINT8               keyIndex;
1739 
1740 	if (pRsn == NULL || pKey == NULL)
1741 	{
1742 		return TI_NOK;
1743 	}
1744 
1745 	keyIndex = (TI_UINT8)pKey->keyIndex;
1746     if (keyIndex >= MAX_KEYS_NUM)
1747     {
1748         return TI_NOK;
1749     }
1750 
1751     TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removeKey Entry, keyType=%d, keyIndex=0x%lx\n",pKey->keyType, keyIndex);
1752 
1753     /* Now set to the RSN structure. */
1754     if (pRsn->keys_en[keyIndex])
1755     {
1756         tTwdParam.paramType = TWD_RSN_KEY_REMOVE_PARAM_ID;
1757         /*os_memoryCopy(pRsn->hOs, &tTwdParam.content.rsnKey, pKey, sizeof(TSecurityKeys));*/
1758         tTwdParam.content.configureCmdCBParams.pCb = (TI_UINT8*) pKey;
1759         tTwdParam.content.configureCmdCBParams.fCb = NULL;
1760         tTwdParam.content.configureCmdCBParams.hCb = NULL;
1761 
1762         if ( pKey->keyType == KEY_NULL ) {
1763 				/* If keytype is unknown, retreive it from the RSN context */
1764 				pKey->keyType = pRsn->keys[keyIndex].keyType;
1765         }
1766 
1767         /* If keyType is TKIP or AES, set the encLen to the KEY enc len - 16 */
1768         if (pKey->keyType == KEY_TKIP || pKey->keyType == KEY_AES)
1769         {
1770             pKey->encLen = 16;
1771             if (keyIndex != 0)
1772             {
1773                 const TI_UINT8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1774                 /*
1775                  * if keyType is TKIP or AES, and the key index is broadcast, overwrite the MAC address as broadcast
1776                  * for removing the Broadcast key from the FW
1777                  */
1778                 MAC_COPY (pKey->macAddress, broadcast);
1779             }
1780         }
1781 		else if (pKey->keyType == KEY_WEP)
1782 		{
1783 			/* In full driver we use only WEP default keys. To remove it we make sure that the MAC address is NULL */
1784 			os_memoryZero(pRsn->hOs,(void*)pKey->macAddress,sizeof(TMacAddr));
1785 		}
1786 
1787 
1788         /* Mark key as deleted */
1789         pRsn->keys_en[keyIndex] = TI_FALSE;
1790 
1791         status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
1792 
1793         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removeKey in whal, status =%d\n", status);
1794 
1795         /* clean the key flags*/
1796         pRsn->keys[keyIndex].keyIndex &= 0x000000FF;
1797         pRsn->keys[keyIndex].keyType   = KEY_NULL;
1798         pRsn->keys[keyIndex].encLen    = 0;
1799         pRsn->wepDefaultKeys[keyIndex] = TI_FALSE;
1800     }
1801 
1802     return status;
1803 }
1804 
1805 
rsn_setDefaultKeyId(rsn_t * pRsn,TI_UINT8 keyId)1806 TI_STATUS rsn_setDefaultKeyId(rsn_t *pRsn, TI_UINT8 keyId)
1807 {
1808     TI_STATUS               status = TI_OK;
1809     TTwdParamInfo           tTwdParam;
1810 
1811     if (pRsn == NULL)
1812     {
1813         return TI_NOK;
1814     }
1815     pRsn->defaultKeyId = keyId;
1816     /* Now we configure default key ID to the HAL */
1817     tTwdParam.paramType = TWD_RSN_DEFAULT_KEY_ID_PARAM_ID;
1818     tTwdParam.content.configureCmdCBParams.pCb = &keyId;
1819     tTwdParam.content.configureCmdCBParams.fCb = NULL;
1820     tTwdParam.content.configureCmdCBParams.hCb = NULL;
1821     status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
1822 
1823     TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setDefaultKeyId, KeyId = 0x%lx\n", keyId);
1824     return status;
1825 }
1826 
1827 
rsn_reportAuthFailure(TI_HANDLE hRsn,EAuthStatus authStatus)1828 TI_STATUS rsn_reportAuthFailure(TI_HANDLE hRsn, EAuthStatus authStatus)
1829 {
1830     TI_STATUS    status = TI_OK;
1831     rsn_t       *pRsn;
1832     paramInfo_t param;
1833 
1834     if (hRsn==NULL)
1835     {
1836         return TI_NOK;
1837     }
1838 
1839     pRsn = (rsn_t*)hRsn;
1840 
1841     /* Remove AP from candidate list for a specified amount of time */
1842 	param.paramType = CTRL_DATA_CURRENT_BSSID_PARAM;
1843 	status = ctrlData_getParam(pRsn->hCtrlData, &param);
1844 	if (status != TI_OK)
1845 	{
1846 TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_reportAuthFailure, unable to retrieve BSSID \n");
1847 	}
1848     else
1849     {
1850         TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "current station is banned from the roaming candidates list for %d Ms\n", RSN_AUTH_FAILURE_TIMEOUT);
1851 
1852         rsn_banSite(hRsn, param.content.ctrlDataCurrentBSSID, RSN_SITE_BAN_LEVEL_FULL, RSN_AUTH_FAILURE_TIMEOUT);
1853     }
1854 
1855 
1856 #ifdef XCC_MODULE_INCLUDED
1857 TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "CALLING rougeAP, status= %d \n",authStatus);
1858     status = XCCMngr_rogueApDetected (pRsn->hXCCMngr, authStatus);
1859 #endif
1860     TI_VOIDCAST(pRsn);
1861     return status;
1862 }
1863 
1864 
1865 /******
1866 This is the CB function for mic failure event from the FW
1867 *******/
rsn_reportMicFailure(TI_HANDLE hRsn,TI_UINT8 * pType,TI_UINT32 Length)1868 TI_STATUS rsn_reportMicFailure(TI_HANDLE hRsn, TI_UINT8 *pType, TI_UINT32 Length)
1869 {
1870     rsn_t                               *pRsn = (rsn_t *) hRsn;
1871     ERsnSiteBanLevel                    banLevel;
1872     OS_802_11_AUTHENTICATION_REQUEST    *request;
1873     TI_UINT8 AuthBuf[sizeof(TI_UINT32) + sizeof(OS_802_11_AUTHENTICATION_REQUEST)];
1874     paramInfo_t                         param;
1875     TI_UINT8                               failureType;
1876 
1877     failureType = *pType;
1878 
1879    if (((pRsn->paeConfig.unicastSuite == TWD_CIPHER_TKIP) && (failureType == KEY_TKIP_MIC_PAIRWISE)) ||
1880         ((pRsn->paeConfig.broadcastSuite == TWD_CIPHER_TKIP) && (failureType == KEY_TKIP_MIC_GROUP)))
1881     {
1882         /* check if the MIC failure is group and group key update */
1883         /* was performed during the last 3 seconds */
1884         if ((failureType == KEY_TKIP_MIC_GROUP) &&
1885             (pRsn->eGroupKeyUpdate == GROUP_KEY_UPDATE_TRUE))
1886         {
1887             TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Group MIC failure ignored, key update was performed within the last 3 seconds.\n");
1888             return TI_OK;
1889         }
1890 
1891 		/* check if the MIC failure is pairwise and pairwise key update */
1892         /* was performed during the last 3 seconds */
1893         if ((failureType == KEY_TKIP_MIC_PAIRWISE) &&
1894             (pRsn->ePairwiseKeyUpdate == PAIRWISE_KEY_UPDATE_TRUE))
1895         {
1896             TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Pairwise MIC failure ignored, key update was performed within the last 3 seconds.\n");
1897             return TI_OK;
1898         }
1899 
1900         /* Prepare the Authentication Request */
1901         request = (OS_802_11_AUTHENTICATION_REQUEST *)(AuthBuf + sizeof(TI_UINT32));
1902         request->Length = sizeof(OS_802_11_AUTHENTICATION_REQUEST);
1903 
1904         param.paramType = CTRL_DATA_CURRENT_BSSID_PARAM;
1905         if (ctrlData_getParam (pRsn->hCtrlData, &param) != TI_OK)
1906         {
1907             return TI_NOK;
1908         }
1909 
1910         /* Generate 802 Media specific indication event */
1911         *(TI_UINT32*)AuthBuf = os802_11StatusType_Authentication;
1912 
1913         MAC_COPY (request->BSSID, param.content.ctrlDataCurrentBSSID);
1914 
1915         if (failureType == KEY_TKIP_MIC_PAIRWISE)
1916         {
1917             request->Flags = OS_802_11_REQUEST_PAIRWISE_ERROR;
1918         }
1919         else
1920         {
1921             request->Flags = OS_802_11_REQUEST_GROUP_ERROR;
1922         }
1923 
1924 		EvHandlerSendEvent (pRsn->hEvHandler,
1925                             IPC_EVENT_MEDIA_SPECIFIC,
1926                             (TI_UINT8*)AuthBuf,
1927                             sizeof(TI_UINT32) + sizeof(OS_802_11_AUTHENTICATION_REQUEST));
1928 
1929 		if ( pRsn->bRsnExternalMode ) {
1930 			return TI_OK;
1931 		}
1932 
1933         /* Update and check the ban level to decide what actions need to take place */
1934         banLevel = rsn_banSite (hRsn, param.content.ctrlDataCurrentBSSID, RSN_SITE_BAN_LEVEL_HALF, RSN_MIC_FAILURE_TIMEOUT);
1935         if (banLevel == RSN_SITE_BAN_LEVEL_FULL)
1936         {
1937             /* Site is banned so prepare to disconnect */
1938             TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Second MIC failure, closing Rx port...\n");
1939 
1940             param.paramType = RX_DATA_PORT_STATUS_PARAM;
1941             param.content.rxDataPortStatus = CLOSE;
1942             rxData_setParam(pRsn->hRx, &param);
1943 
1944             /* stop the mic failure Report timer and start a new one for 0.5 seconds */
1945             tmr_StopTimer (pRsn->hMicFailureReportWaitTimer);
1946 		    apConn_setDeauthPacketReasonCode(pRsn->hAPConn, STATUS_MIC_FAILURE);
1947             tmr_StartTimer (pRsn->hMicFailureReportWaitTimer,
1948                             rsn_micFailureReportTimeout,
1949                             (TI_HANDLE)pRsn,
1950                             RSN_MIC_FAILURE_REPORT_TIMEOUT,
1951                             TI_FALSE);
1952         }
1953         else
1954         {
1955             /* Site is only half banned so nothing needs to be done for now */
1956             TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": First MIC failure, business as usual for now...\n");
1957         }
1958     }
1959 
1960     return TI_OK;
1961 }
1962 
1963 
rsn_groupReKeyTimeout(TI_HANDLE hRsn,TI_BOOL bTwdInitOccured)1964 void rsn_groupReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured)
1965 {
1966     rsn_t *pRsn;
1967 
1968     pRsn = (rsn_t*)hRsn;
1969 
1970     if (pRsn == NULL)
1971     {
1972         return;
1973     }
1974 
1975     pRsn->eGroupKeyUpdate = GROUP_KEY_UPDATE_FALSE;
1976 }
1977 
1978 
rsn_pairwiseReKeyTimeout(TI_HANDLE hRsn,TI_BOOL bTwdInitOccured)1979 void rsn_pairwiseReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured)
1980 {
1981     rsn_t *pRsn;
1982 
1983     pRsn = (rsn_t*)hRsn;
1984 
1985     if (pRsn == NULL)
1986     {
1987         return;
1988     }
1989 
1990     pRsn->ePairwiseKeyUpdate = PAIRWISE_KEY_UPDATE_FALSE;
1991 }
1992 
rsn_micFailureReportTimeout(TI_HANDLE hRsn,TI_BOOL bTwdInitOccured)1993 void rsn_micFailureReportTimeout (TI_HANDLE hRsn, TI_BOOL bTwdInitOccured)
1994 {
1995     rsn_t *pRsn;
1996 
1997     pRsn = (rsn_t*)hRsn;
1998 
1999     if (pRsn == NULL)
2000     {
2001         return;
2002     }
2003 
2004     TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": MIC failure reported, disassociating...\n");
2005 
2006     apConn_reportRoamingEvent (pRsn->hAPConn, ROAMING_TRIGGER_SECURITY_ATTACK, NULL);
2007 }
2008 
2009 
2010 /**
2011 *
2012 * rsn_resetPMKIDList -
2013 *
2014 * \b Description:
2015 *   Cleans up the PMKID cache.
2016 *   Called when SSID is being changed.
2017 *
2018 * \b ARGS:
2019 *
2020 *  I   - hRsn - Rsniation SM context  \n
2021 *
2022 * \b RETURNS:
2023 *
2024 *  TI_OK if successful, TI_NOK otherwise.
2025 */
2026 
rsn_resetPMKIDList(TI_HANDLE hRsn)2027 TI_STATUS rsn_resetPMKIDList(TI_HANDLE hRsn)
2028 {
2029     rsn_t  *pRsn = (rsn_t*)hRsn;
2030 
2031     if (!pRsn)
2032         return TI_NOK;
2033 
2034     return (pRsn->pAdmCtrl->resetPmkidList (pRsn->pAdmCtrl));
2035 }
2036 
2037 
rsn_debugFunc(TI_HANDLE hRsn)2038 void rsn_debugFunc(TI_HANDLE hRsn)
2039 {
2040     rsn_t *pRsn;
2041 
2042     if (hRsn == NULL)
2043     {
2044         return;
2045     }
2046     pRsn = (rsn_t*)hRsn;
2047 
2048     WLAN_OS_REPORT(("rsnStartedTs, ts = %d\n", pRsn->rsnStartedTs));
2049     WLAN_OS_REPORT(("rsnCompletedTs, ts = %d\n", pRsn->rsnCompletedTs));
2050 }
2051 
2052 
2053 /**
2054 *
2055 * rsn_startPreAuth -
2056 *
2057 * \b Description:
2058 *
2059 * Start pre-authentication on a list of given BSSIDs.
2060 *
2061 * \b ARGS:
2062 *
2063 *  I   - hRsn - Rsniation SM context  \n
2064 *  I/O - pBssidList - list of BSSIDs that require Pre-Auth \n
2065 *
2066 * \b RETURNS:
2067 *
2068 *  TI_OK if successful, TI_NOK otherwise.
2069 *
2070 * \sa
2071 */
rsn_startPreAuth(TI_HANDLE hRsn,TBssidList4PreAuth * pBssidList)2072 TI_STATUS rsn_startPreAuth(TI_HANDLE hRsn, TBssidList4PreAuth *pBssidList)
2073 {
2074     rsn_t       *pRsn;
2075     TI_STATUS    status;
2076 
2077     if ( (NULL == hRsn) || (NULL == pBssidList) )
2078     {
2079         return TI_NOK;
2080     }
2081 
2082     pRsn = (rsn_t*)hRsn;
2083 
2084     status = pRsn->pAdmCtrl->startPreAuth (pRsn->pAdmCtrl, pBssidList);
2085 
2086     TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_startPreAuth \n");
2087 
2088     return status;
2089 }
2090 
2091 
2092 /**
2093  *
2094  * isSiteBanned -
2095  *
2096  * \b Description:
2097  *
2098  * Returns whether or not the site with the specified Bssid is banned or not.
2099  *
2100  * \b ARGS:
2101  *
2102  *  I   - hRsn - RSN module context \n
2103  *  I   - siteBssid - The desired site's bssid \n
2104  *
2105  * \b RETURNS:
2106  *
2107  *  TI_NOK iff site is banned.
2108  *
2109  */
rsn_isSiteBanned(TI_HANDLE hRsn,TMacAddr siteBssid)2110 TI_BOOL rsn_isSiteBanned(TI_HANDLE hRsn, TMacAddr siteBssid)
2111 {
2112     rsn_t * pRsn = (rsn_t *) hRsn;
2113     rsn_siteBanEntry_t * entry;
2114 
2115     /* Check if site is in the list */
2116     if ((entry = findBannedSiteAndCleanup(hRsn, siteBssid)) == NULL)
2117     {
2118         return TI_FALSE;
2119     }
2120 
2121     TRACE7(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Site %02X-%02X-%02X-%02X-%02X-%02X found with ban level %d...\n", siteBssid[0], siteBssid[1], siteBssid[2], siteBssid[3], siteBssid[4], siteBssid[5], entry->banLevel);
2122 
2123     return (entry->banLevel == RSN_SITE_BAN_LEVEL_FULL);
2124 }
2125 
2126 
2127 /**
2128  *
2129  * rsn_PortStatus_Set API implementation-
2130  *
2131  * \b Description:
2132  *
2133  * set the status port according to the status flag
2134  *
2135  * \b ARGS:
2136  *
2137  *  I   - hRsn - RSN module context \n
2138  *  I   - state - The status flag \n
2139  *
2140  * \b RETURNS:
2141  *
2142  *  TI_STATUS.
2143  *
2144  */
rsn_setPortStatus(TI_HANDLE hRsn,TI_BOOL state)2145 TI_STATUS rsn_setPortStatus(TI_HANDLE hRsn, TI_BOOL state)
2146 {
2147     rsn_t                   *pRsn = (rsn_t *)hRsn;
2148     struct externalSec_t	*pExtSec;
2149 
2150     pExtSec = pRsn->pMainSecSm->pExternalSec;
2151     pExtSec->bPortStatus = state;
2152     if (state)
2153 			pRsn->reportStatus( pRsn, TI_OK );
2154     return externalSec_rsnComplete(pExtSec);
2155 }
2156 
2157 
2158 /**
2159  *
2160  * rsn_banSite -
2161  *
2162  * \b Description:
2163  *
2164  * Bans the specified site from being associated to for the specified duration.
2165  * If a ban level of WARNING is given and no previous ban was in effect the
2166  * warning is marked down but other than that nothing happens. In case a previous
2167  * warning (or ban of course) is still in effect
2168  *
2169  * \b ARGS:
2170  *
2171  *  I   - hRsn - RSN module context \n
2172  *  I   - siteBssid - The desired site's bssid \n
2173  *  I   - banLevel - The desired level of ban (Warning / Ban)
2174  *  I   - durationMs - The duration of ban in milliseconds
2175  *
2176  * \b RETURNS:
2177  *
2178  *  The level of ban (warning / banned).
2179  *
2180  */
rsn_banSite(TI_HANDLE hRsn,TMacAddr siteBssid,ERsnSiteBanLevel banLevel,TI_UINT32 durationMs)2181 ERsnSiteBanLevel rsn_banSite(TI_HANDLE hRsn, TMacAddr siteBssid, ERsnSiteBanLevel banLevel, TI_UINT32 durationMs)
2182 {
2183     rsn_t * pRsn = (rsn_t *) hRsn;
2184     rsn_siteBanEntry_t * entry;
2185 
2186     /* Try finding the site in the list */
2187     if ((entry = findBannedSiteAndCleanup(hRsn, siteBssid)) != NULL)
2188     {
2189         /* Site found so a previous ban is still in effect */
2190         TRACE6(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Site %02X-%02X-%02X-%02X-%02X-%02X found and has been set to ban level full!\n", siteBssid[0], siteBssid[1], siteBssid[2], siteBssid[3], siteBssid[4], siteBssid[5]);
2191 
2192         entry->banLevel = RSN_SITE_BAN_LEVEL_FULL;
2193     }
2194     else
2195     {
2196         /* Site doesn't appear in the list, so find a place to insert it */
2197         TRACE7(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Site %02X-%02X-%02X-%02X-%02X-%02X added with ban level %d!\n", siteBssid[0], siteBssid[1], siteBssid[2], siteBssid[3], siteBssid[4], siteBssid[5], banLevel);
2198 
2199         entry = findEntryForInsert (hRsn);
2200 
2201 		MAC_COPY (entry->siteBssid, siteBssid);
2202         entry->banLevel = banLevel;
2203 
2204         pRsn->numOfBannedSites++;
2205     }
2206 
2207     entry->banStartedMs = os_timeStampMs (pRsn->hOs);
2208     entry->banDurationMs = durationMs;
2209 
2210     return entry->banLevel;
2211 }
2212 
2213 
2214 /**
2215  *
2216  * findEntryForInsert -
2217  *
2218  * \b Description:
2219  *
2220  * Returns a place to insert a new banned site.
2221  *
2222  * \b ARGS:
2223  *
2224  *  I   - hRsn - RSN module context \n
2225  *
2226  * \b RETURNS:
2227  *
2228  *  A pointer to a suitable site entry.
2229  *
2230  */
findEntryForInsert(TI_HANDLE hRsn)2231 static rsn_siteBanEntry_t * findEntryForInsert(TI_HANDLE hRsn)
2232 {
2233     rsn_t * pRsn = (rsn_t *) hRsn;
2234 
2235     /* In the extreme case that the list is full we overwrite an old entry */
2236     if (pRsn->numOfBannedSites == RSN_MAX_NUMBER_OF_BANNED_SITES)
2237     {
2238         TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, ": No room left to insert new banned site, overwriting old one!\n");
2239 
2240         return &(pRsn->bannedSites[0]);
2241     }
2242 
2243     return &(pRsn->bannedSites[pRsn->numOfBannedSites]);
2244 }
2245 
2246 
2247 /**
2248  *
2249  * findBannedSiteAndCleanup -
2250  *
2251  * \b Description:
2252  *
2253  * Searches the banned sites list for the desired site while cleaning up
2254  * expired sites found along the way.
2255  *
2256  * Note that this function might change the structure of the banned sites
2257  * list so old iterators into the list might be invalidated.
2258  *
2259  * \b ARGS:
2260  *
2261  *  I   - hRsn - RSN module context \n
2262  *  I   - siteBssid - The desired site's bssid \n
2263  *
2264  * \b RETURNS:
2265  *
2266  *  A pointer to the desired site's entry if found,
2267  *  NULL otherwise.
2268  *
2269  */
findBannedSiteAndCleanup(TI_HANDLE hRsn,TMacAddr siteBssid)2270 static rsn_siteBanEntry_t * findBannedSiteAndCleanup(TI_HANDLE hRsn, TMacAddr siteBssid)
2271 {
2272     rsn_t * pRsn = (rsn_t *) hRsn;
2273     int iter;
2274 
2275     for (iter = 0; iter < pRsn->numOfBannedSites; iter++)
2276     {
2277         /* If this entry has expired we'd like to clean it up */
2278         if (os_timeStampMs(pRsn->hOs) - pRsn->bannedSites[iter].banStartedMs >= pRsn->bannedSites[iter].banDurationMs)
2279         {
2280             TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Found expired entry at index %d, cleaning it up...\n", iter);
2281 
2282             /* Replace this entry with the last one */
2283             pRsn->bannedSites[iter] = pRsn->bannedSites[pRsn->numOfBannedSites - 1];
2284             pRsn->numOfBannedSites--;
2285 
2286             /* we now repeat the iteration on this entry */
2287             iter--;
2288 
2289             continue;
2290         }
2291 
2292         /* Is this the entry for the site we're looking for? */
2293         if (MAC_EQUAL (siteBssid, pRsn->bannedSites[iter].siteBssid))
2294         {
2295             TRACE7(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Site %02X-%02X-%02X-%02X-%02X-%02X found at index %d!\n", siteBssid[0], siteBssid[1], siteBssid[2], siteBssid[3], siteBssid[4], siteBssid[5], iter);
2296 
2297             return &pRsn->bannedSites[iter];
2298         }
2299     }
2300 
2301     /* Entry not found... */
2302     TRACE6(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Site %02X-%02X-%02X-%02X-%02X-%02X not found...\n", siteBssid[0], siteBssid[1], siteBssid[2], siteBssid[3], siteBssid[4], siteBssid[5]);
2303 
2304     return NULL;
2305 }
2306 
2307 /**
2308  *
2309  * rsn_getPortStatus -
2310  *
2311  * \b Description:
2312  *
2313  * Returns the extrenalSec port status
2314  *
2315  * \b ARGS:
2316  *
2317  *  pRsn - pointer to RSN module context \n
2318  *
2319  * \b RETURNS:
2320  *
2321  *  TI_BOOL - the port status True = Open , False = Close
2322  *
2323  */
rsn_getPortStatus(rsn_t * pRsn)2324 TI_BOOL rsn_getPortStatus(rsn_t *pRsn)
2325 {
2326     struct externalSec_t	*pExtSec;
2327 
2328     pExtSec = pRsn->pMainSecSm->pExternalSec;
2329     return pExtSec->bPortStatus;
2330 }
2331 
2332 /**
2333  *
2334  * rsn_getGenInfoElement -
2335  *
2336  * \b Description:
2337  *
2338  * Copies the Generic IE to a given buffer
2339  *
2340  * \b ARGS:
2341  *
2342  *  I     pRsn           - pointer to RSN module context \n
2343  *  O     out_buff       - pointer to the output buffer  \n
2344  *  O     out_buf_length - length of data copied into output buffer \n
2345  *
2346  * \b RETURNS:
2347  *
2348  *  TI_UINT8 - The amount of bytes copied.
2349  *
2350  */
rsn_getGenInfoElement(rsn_t * pRsn,TI_UINT8 * out_buff,TI_UINT32 * out_buf_length)2351 TI_STATUS rsn_getGenInfoElement(rsn_t *pRsn, TI_UINT8 *out_buff, TI_UINT32 *out_buf_length)
2352 {
2353 	if ( !(pRsn && out_buff && out_buf_length) ) {
2354 			return TI_NOK;
2355 	}
2356 
2357 	*out_buf_length = pRsn->genericIE.length;
2358 	if (pRsn->genericIE.length > 0) {
2359 			os_memoryCopy(pRsn->hOs, out_buff, pRsn->genericIE.data, pRsn->genericIE.length);
2360 	}
2361 
2362 	return TI_OK;
2363 }
2364 
2365 /**
2366  *
2367  * rsn_clearGenInfoElement -
2368  *
2369  * \b Description:
2370  *
2371  * Clears the Generic IE
2372  *
2373  * \b ARGS:
2374  *
2375  *  I     pRsn           - pointer to RSN module context \n
2376  *
2377  */
rsn_clearGenInfoElement(rsn_t * pRsn)2378 void rsn_clearGenInfoElement(rsn_t *pRsn )
2379 {
2380     os_memoryZero(pRsn->hOs, &pRsn->genericIE, sizeof(pRsn->genericIE));
2381 }
2382 
2383 
2384 #ifdef RSN_NOT_USED
2385 
convertAscii2Unicode(TI_INT8 * userPwd,TI_INT16 len)2386 static TI_INT16 convertAscii2Unicode(TI_INT8* userPwd, TI_INT16 len)
2387 {
2388     TI_INT16 i;
2389     TI_INT8 unsiiPwd[MAX_PASSWD_LEN];
2390 
2391 
2392     for (i=0; i<len; i++)
2393     {
2394         unsiiPwd[i] = userPwd[i];
2395     }
2396     for (i=0; i<len; i++)
2397     {
2398         userPwd[i*2] = unsiiPwd[i];
2399         userPwd[i*2+1] = 0;
2400     }
2401     return (TI_INT16)(len*2);
2402 }
2403 
2404 #endif
2405 
2406 /***************************************************************************
2407 *							rsn_reAuth				                   *
2408 ****************************************************************************
2409 * DESCRIPTION:	This is a callback function called by the whalWPA module whenever
2410 *				a broadcast TKIP key was configured to the FW.
2411 *				It does the following:
2412 *					-	resets the ReAuth flag
2413 *					-	stops the ReAuth timer
2414 *					-	restore the PS state
2415 *					-	Send RE_AUTH_COMPLETED event to the upper layer.
2416 *
2417 * INPUTS:		hRsn - the object
2418 *
2419 * OUTPUT:		None
2420 *
2421 * RETURNS:		None
2422 *
2423 ***************************************************************************/
rsn_reAuth(TI_HANDLE hRsn)2424 void rsn_reAuth(TI_HANDLE hRsn)
2425 {
2426 	rsn_t *pRsn;
2427 
2428 	pRsn = (rsn_t*)hRsn;
2429 
2430 	if (pRsn == NULL)
2431 	{
2432 		return;
2433 	}
2434 
2435 	if (rxData_IsReAuthInProgress(pRsn->hRx))
2436 	{
2437 		rxData_SetReAuthInProgress(pRsn->hRx, TI_FALSE);
2438 		rxData_StopReAuthActiveTimer(pRsn->hRx);
2439 		rxData_ReauthDisablePriority(pRsn->hRx);
2440 		EvHandlerSendEvent(pRsn->hEvHandler, IPC_EVENT_RE_AUTH_COMPLETED, NULL, 0);
2441 	}
2442 }
2443