1/*
2 * rsn.c
3 *
4 * Copyright(c) 1998 - 2009 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 */
93TI_STATUS rsn_sendKeysNotSet(rsn_t *pRsn);
94void rsn_pairwiseReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured);
95void rsn_groupReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured);
96void rsn_micFailureReportTimeout (TI_HANDLE hRsn, TI_BOOL bTwdInitOccured);
97static rsn_siteBanEntry_t * findEntryForInsert(TI_HANDLE hRsn);
98static 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*/
123TI_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*/
179TI_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*/
227void 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->defaultKeysOn = TI_TRUE;
259    pRsn->eapType = OS_EAP_TYPE_NONE;
260    pRsn->numOfBannedSites = 0;
261}
262
263
264TI_STATUS rsn_SetDefaults (TI_HANDLE hRsn, TRsnInitParams *pInitParam)
265{
266    rsn_t       *pRsn = (rsn_t*)hRsn;
267    TI_UINT8     keyIndex;
268    TI_STATUS    status;
269
270    /* Create the module's timers */
271    pRsn->hMicFailureReportWaitTimer = tmr_CreateTimer (pRsn->hTimer);
272    if (pRsn->hMicFailureReportWaitTimer == NULL)
273    {
274        TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_SetDefaults(): Failed to create hMicFailureReportWaitTimer!\n");
275		return TI_NOK;
276    }
277    pRsn->hMicFailureGroupReKeyTimer = tmr_CreateTimer (pRsn->hTimer);
278    if (pRsn->hMicFailureGroupReKeyTimer == NULL)
279    {
280        TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_SetDefaults(): Failed to create hMicFailureGroupReKeyTimer!\n");
281		return TI_NOK;
282    }
283
284    /* Configure the RSN external mode */
285    pRsn->bRsnExternalMode = pInitParam->bRsnExternalMode;
286
287    pRsn->hMicFailurePairwiseReKeyTimer = tmr_CreateTimer (pRsn->hTimer);
288    if (pRsn->hMicFailurePairwiseReKeyTimer == NULL)
289    {
290        TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_SetDefaults(): Failed to create hMicFailurePairwiseReKeyTimer!\n");
291		return TI_NOK;
292    }
293
294	pRsn->bPairwiseMicFailureFilter = pInitParam->bPairwiseMicFailureFilter;
295    /* config the admission control with the authentication suite selected.
296       Admission control will configure the main security SM. */
297    status = admCtrl_config (pRsn->pAdmCtrl,
298                             pRsn->hMlme,
299                             pRsn->hRx,
300                             pRsn->hReport,
301                             pRsn->hOs,
302                             pRsn,
303                             pRsn->hXCCMngr,
304                             pRsn->hPowerMgr,
305                             pRsn->hEvHandler,
306                             pRsn->hTimer,
307                             pRsn->hCurrBss,
308                             pInitParam);
309
310    if (status != TI_OK)
311    {
312        return status;
313    }
314
315    /* Configure keys from registry */
316    if (pInitParam->privacyOn)
317    {
318        pRsn->wepStaticKey = TI_TRUE;
319    }
320
321    pRsn->defaultKeyId = pInitParam->defaultKeyId;
322    for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
323    {
324        os_memoryCopy (pRsn->hOs, &pRsn->keys[keyIndex], &pInitParam->keys[keyIndex], sizeof(TSecurityKeys));
325        if (pRsn->keys[keyIndex].keyType != KEY_NULL)
326        {
327            pRsn->wepDefaultKeys[keyIndex] = TI_TRUE;
328        }
329        pRsn->keys_en [keyIndex] = TI_FALSE;
330    }
331
332    return status;
333}
334
335
336/**
337*
338* rsn_reconfig - re-configure a rsniation
339*
340* \b Description:
341*
342* Re-configure rsniation
343*
344* \b ARGS:
345*
346*  I   - hRsn - Rsniation SM context  \n
347*
348* \b RETURNS:
349*
350*  TI_OK if successful, TI_NOK otherwise.
351*
352* \sa rsn_Create, rsn_Unload
353*/
354TI_STATUS rsn_reconfig (TI_HANDLE hRsn)
355{
356    rsn_t  *pRsn = (rsn_t *)hRsn;
357    TI_UINT8   keyIndex;
358
359    /* Mark all keys as removed */
360    for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
361        pRsn->keys_en [keyIndex] = TI_FALSE;
362
363    return TI_OK;
364}
365
366
367/**
368*
369* rsn_setDefaultKeys -
370*
371* \b Description:
372*
373*
374*
375* \b ARGS:
376*
377*  I   - hRsn - Rsn SM context  \n
378*
379* \b RETURNS:
380*
381*  TI_OK if successful, TI_NOK otherwise.
382*
383* \sa rsn_Stop, rsn_Recv
384*/
385TI_STATUS rsn_setDefaultKeys(rsn_t *pRsn)
386{
387    TI_STATUS       status = TI_OK;
388    TTwdParamInfo   tTwdParam;
389    TI_UINT8           keyIndex;
390
391    for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
392    {
393        /* Set the WEP key to the HAL */
394        if (pRsn->wepDefaultKeys[keyIndex] /*pRsn->keys[keyIndex].encLen>0*/)
395        {
396            /* Change key type to WEP-key before setting*/
397            pRsn->keys[keyIndex].keyType = KEY_WEP;
398
399            status = pRsn->pMainSecSm->setKey (pRsn->pMainSecSm, &pRsn->keys[keyIndex]);
400
401            if (status != TI_OK)
402            {
403                TRACE1(pRsn->hReport, REPORT_SEVERITY_ERROR, "RSN: Setting key #%d failed \n", keyIndex);
404                return status;
405            }
406        }
407    }
408
409    /* Now we configure default key ID to the HAL */
410    if (pRsn->defaultKeyId < MAX_KEYS_NUM)
411    {
412        tTwdParam.paramType = TWD_RSN_DEFAULT_KEY_ID_PARAM_ID;
413        tTwdParam.content.configureCmdCBParams.pCb = &pRsn->defaultKeyId;
414        tTwdParam.content.configureCmdCBParams.fCb = NULL;
415        tTwdParam.content.configureCmdCBParams.hCb = NULL;
416        status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
417
418        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: default key ID =%d \n", pRsn->defaultKeyId);
419    }
420
421    return status;
422}
423
424
425/**
426*
427* rsn_Start - Start event for the rsniation SM
428*
429* \b Description:
430*
431* Start event for the rsniation SM
432*
433* \b ARGS:
434*
435*  I   - hRsn - Rsniation SM context  \n
436*
437* \b RETURNS:
438*
439*  TI_OK if successful, TI_NOK otherwise.
440*
441* \sa rsn_Stop, rsn_Recv
442*/
443TI_STATUS rsn_start(TI_HANDLE hRsn)
444{
445    TI_STATUS           status;
446    rsn_t               *pRsn;
447    ECipherSuite        suite;
448    EExternalAuthMode   extAuthMode;
449    TTwdParamInfo       tTwdParam;
450
451    pRsn = (rsn_t*)hRsn;
452
453    if (pRsn == NULL)
454    {
455        return TI_NOK;
456    }
457
458    TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_start ...\n");
459    pRsn->rsnStartedTs = os_timeStampMs (pRsn->hOs);
460
461    status = pRsn->pMainSecSm->start (pRsn->pMainSecSm);
462    /* Set keys that need to be set */
463    pRsn->defaultKeysOn = TI_FALSE;
464    pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &suite);
465    pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &extAuthMode);
466
467    if (pRsn->wepStaticKey && ( (suite == TWD_CIPHER_WEP) || (suite == TWD_CIPHER_CKIP) ) )
468    {   /* set default WEP keys */
469        status = rsn_sendKeysNotSet (pRsn);
470        pRsn->eapType = OS_EAP_TYPE_NONE;
471    }
472    else if (suite == TWD_CIPHER_NONE && extAuthMode != RSN_EXT_AUTH_MODE_OPEN)
473    {   /* remove previously WEP key for SHARED */
474        pRsn->wepStaticKey = TI_FALSE;
475        status = rsn_removedDefKeys (pRsn);
476
477        /* Set None to HAL */
478        tTwdParam.paramType = TWD_RSN_SECURITY_MODE_PARAM_ID;
479        tTwdParam.content.rsnEncryptionStatus = (ECipherSuite)TWD_CIPHER_NONE;
480        status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
481
482    }
483    else if (suite==TWD_CIPHER_NONE)
484    {
485        pRsn->eapType = OS_EAP_TYPE_NONE;
486    }
487
488    return status;
489}
490
491
492TI_STATUS rsn_sendKeysNotSet(rsn_t *pRsn)
493{
494    TI_UINT8           keyIndex;
495    OS_802_11_KEY   rsnOsKey;
496    TI_STATUS       status = TI_OK;
497
498    for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
499    {
500        if (pRsn->wepDefaultKeys[keyIndex])
501        {
502            rsnOsKey.KeyIndex  = pRsn->keys[keyIndex].keyIndex;
503            rsnOsKey.KeyLength = pRsn->keys[keyIndex].encLen;
504            rsnOsKey.Length    = sizeof(rsnOsKey);
505
506            /* Change key type to WEP-key before setting*/
507            pRsn->keys[keyIndex].keyType = KEY_WEP;
508
509            MAC_COPY (rsnOsKey.BSSID, pRsn->keys[keyIndex].macAddress);
510            os_memoryCopy (pRsn->hOs, &rsnOsKey.KeyRSC,
511                           (void *)pRsn->keys[keyIndex].keyRsc,
512                           KEY_RSC_LEN);
513            os_memoryCopy (pRsn->hOs, rsnOsKey.KeyMaterial,
514                           (void *)pRsn->keys[keyIndex].encKey,
515                           MAX_KEY_LEN /*pRsn->keys[keyIndex].encLen*/);
516
517            /* Set WEP transmit key mask on the default key */
518            if (keyIndex == pRsn->defaultKeyId)
519            {
520                rsnOsKey.KeyIndex |= 0x80000000;
521            }
522
523            status = pRsn->pKeyParser->recv (pRsn->pKeyParser, (TI_UINT8*)&rsnOsKey, sizeof(rsnOsKey));
524        }
525    }
526
527    return status;
528}
529
530
531TI_STATUS rsn_removedDefKeys (TI_HANDLE hRsn)
532{
533    TI_UINT8  keyIndex;
534    rsn_t  *pRsn = (rsn_t*)hRsn;
535
536    TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removedDefKeys Enter \n");
537
538    for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
539    {
540        TSecurityKeys   key;
541
542        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removedDefKeys, Remove keyId=%d\n", keyIndex);
543
544        pRsn->wepDefaultKeys[keyIndex] = TI_FALSE;
545        os_memoryCopy (pRsn->hOs, &key, &pRsn->keys[keyIndex], sizeof(TSecurityKeys));
546        pRsn->removeKey (pRsn, &key);
547
548        /* Set WEP transmit key mask on the default key */
549        if (keyIndex == pRsn->defaultKeyId)
550        {
551            pRsn->defaultKeyId = 0;
552        }
553    }
554
555    return TI_OK;
556}
557
558
559/**
560*
561* rsn_Stop - Stop event for the rsniation SM
562*
563* \b Description:
564*
565* Stop event for the rsniation SM
566*
567* \b ARGS:
568*
569*  I   - hRsn - Rsniation SM context  \n
570*
571* \b RETURNS:
572*
573*  TI_OK if successful, TI_NOK otherwise.
574*
575* \sa rsn_Start, rsn_Recv
576*/
577TI_STATUS rsn_stop (TI_HANDLE hRsn, TI_BOOL removeKeys)
578{
579    TI_STATUS        status;
580    rsn_t           *pRsn;
581    TI_UINT8            keyIndex;
582    TSecurityKeys   key;
583
584    pRsn = (rsn_t*)hRsn;
585
586    if (pRsn == NULL)
587    {
588        return TI_NOK;
589    }
590
591    TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: calling STOP... removeKeys=%d\n", removeKeys);
592
593    for (keyIndex = 0; keyIndex < MAX_KEYS_NUM; keyIndex++)
594    {
595        os_memoryCopy (pRsn->hOs, &key, &pRsn->keys[keyIndex], sizeof(TSecurityKeys));
596
597        if (!pRsn->wepDefaultKeys[keyIndex])
598        {	/* Remove only dynamic keys. Default keys are removed by calling: rsn_removedDefKeys() */
599            TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_stop, Remove keyIndex=%d, key.keyIndex=%d\n",keyIndex, key.keyIndex);
600
601            TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)key.macAddress, 6);
602
603            pRsn->removeKey (pRsn, &key);
604        }
605
606    }
607
608    tmr_StopTimer (pRsn->hMicFailureReportWaitTimer);
609
610    /* Stop the pre-authentication timer in case we are disconnecting */
611    tmr_StopTimer (pRsn->pAdmCtrl->hPreAuthTimerWpa2);
612
613    status = pRsn->pMainSecSm->stop (pRsn->pMainSecSm);
614
615    pRsn->eGroupKeyUpdate = GROUP_KEY_UPDATE_FALSE;
616    pRsn->ePairwiseKeyUpdate = PAIRWISE_KEY_UPDATE_FALSE;
617    pRsn->defaultKeysOn = TI_TRUE;
618
619    if (removeKeys)
620    {   /* reset PMKID list if exist */
621        pRsn->pAdmCtrl->resetPmkidList (pRsn->pAdmCtrl);
622    }
623
624    return status;
625}
626
627TI_STATUS rsn_getParamEncryptionStatus(TI_HANDLE hRsn, ECipherSuite *rsnStatus)
628{ /* RSN_ENCRYPTION_STATUS_PARAM */
629    rsn_t       *pRsn = (rsn_t *)hRsn;
630    TI_STATUS   status = TI_NOK;
631
632    if ( (NULL == pRsn) || (NULL == rsnStatus) )
633    {
634        return status;
635    }
636    status = pRsn->pAdmCtrl->getCipherSuite(pRsn->pAdmCtrl, rsnStatus);
637    return status;
638}
639
640/**
641*
642* rsn_GetParam - Get a specific parameter from the rsniation SM
643*
644* \b Description:
645*
646* Get a specific parameter from the rsniation SM.
647*
648* \b ARGS:
649*
650*  I   - hRsn - Rsniation SM context  \n
651*  I/O - pParam - Parameter \n
652*
653* \b RETURNS:
654*
655*  TI_OK if successful, TI_NOK otherwise.
656*
657* \sa rsn_Start, rsn_Stop
658*/
659TI_STATUS rsn_getParam(TI_HANDLE hRsn, void *param)
660{
661    rsn_t       *pRsn = (rsn_t *)hRsn;
662    paramInfo_t *pParam = (paramInfo_t *)param;
663    TI_STATUS   status = TI_OK;
664
665    if ( (NULL == pRsn) || (NULL == pParam) )
666    {
667        return TI_NOK;
668    }
669
670    switch (pParam->paramType)
671    {
672    case RSN_PRIVACY_OPTION_IMPLEMENTED_PARAM:
673        pParam->content.rsnPrivacyOptionImplemented = TI_TRUE;
674        break;
675
676    case RSN_KEY_PARAM:
677        pParam->content.pRsnKey = &pRsn->keys[pParam->content.pRsnKey->keyIndex];
678        if (pParam->content.pRsnKey->keyIndex == pRsn->defaultKeyId)
679        {
680            pParam->content.pRsnKey->keyIndex |= 0x80000000;
681            TRACE1(pRsn->hReport, REPORT_SEVERITY_WARNING, "default Key: %d\n", pRsn->defaultKeyId);
682        }
683        break;
684
685    case RSN_SECURITY_STATE_PARAM:
686        status = pRsn->pMainSecSm->getAuthState (pRsn->pMainSecSm, (TIWLN_SECURITY_STATE*)&(pParam->content.rsnAuthState));
687        break;
688
689    case RSN_ENCRYPTION_STATUS_PARAM:
690        status = pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &pParam->content.rsnEncryptionStatus);
691        break;
692
693    case RSN_EXT_AUTHENTICATION_MODE:
694        status = pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &pParam->content.rsnExtAuthneticationMode);
695        break;
696
697    case RSN_MIXED_MODE:
698        status = pRsn->pAdmCtrl->getMixedMode (pRsn->pAdmCtrl, &pParam->content.rsnMixedMode);
699        break;
700
701    case RSN_AUTH_ENCR_CAPABILITY:
702        status = pRsn->pAdmCtrl->getAuthEncrCap(pRsn->pAdmCtrl, pParam->content.pRsnAuthEncrCapability);
703        break;
704
705    case RSN_PMKID_LIST:
706        pParam->content.rsnPMKIDList.Length = pParam->paramLength;
707        status = pRsn->pAdmCtrl->getPmkidList (pRsn->pAdmCtrl, &pParam->content.rsnPMKIDList);
708        pParam->paramLength = pParam->content.rsnPMKIDList.Length + 2 * sizeof(TI_UINT32);
709        break;
710
711    case RSN_PRE_AUTH_STATUS:
712        {
713            TI_UINT8 cacheIndex;
714
715            pParam->content.rsnPreAuthStatus = pRsn->pAdmCtrl->getPreAuthStatus (pRsn->pAdmCtrl, &pParam->content.rsnApMac, &cacheIndex);
716        }
717        break;
718
719    case  RSN_WPA_PROMOTE_AVAILABLE_OPTIONS:
720        status = pRsn->pAdmCtrl->getWPAMixedModeSupport (pRsn->pAdmCtrl, &pParam->content.rsnWPAMixedModeSupport);
721        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get WPA Mixed MODE support  %d \n",pParam->content.rsnWPAMixedModeSupport);
722        break;
723
724    case RSN_WPA_PROMOTE_OPTIONS:
725        status = pRsn->pAdmCtrl->getPromoteFlags (pRsn->pAdmCtrl,
726                                                  &pParam->content.rsnWPAPromoteFlags);
727                TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get WPA promote flags  %d \n",pParam->content.rsnWPAPromoteFlags);
728
729        break;
730
731#ifdef XCC_MODULE_INCLUDED
732    case RSN_XCC_NETWORK_EAP:
733        status = pRsn->pAdmCtrl->getNetworkEap (pRsn->pAdmCtrl, &pParam->content.networkEap);
734        break;
735#endif
736    case RSN_EAP_TYPE:
737        pParam->content.eapType = pRsn->eapType;
738        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get RSN_EAP_TYPE eapType  %d \n", pParam->content.eapType);
739        break;
740
741    case WPA_801_1X_AKM_EXISTS:
742
743        status = pRsn->pAdmCtrl->get802_1x_AkmExists(pRsn->pAdmCtrl, &pParam->content.wpa_802_1x_AkmExists);
744        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get WPA_801_1X_AKM_EXISTS  %d \n", pParam->content.wpa_802_1x_AkmExists);
745        break;
746
747    case RSN_DEFAULT_KEY_ID:
748        pParam->content.rsnDefaultKeyID = pRsn->defaultKeyId;
749        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Get RSN_DEFAULT_KEY_ID  %d \n", pParam->content.rsnDefaultKeyID);
750        break;
751
752    default:
753        return TI_NOK;
754    }
755
756    return status;
757}
758
759
760/**
761*
762* rsn_SetParam - Set a specific parameter to the rsniation SM
763*
764* \b Description:
765*
766* Set a specific parameter to the rsniation SM.
767*
768* \b ARGS:
769*
770*  I   - hRsn - Rsniation SM context  \n
771*  I/O - pParam - Parameter \n
772*
773* \b RETURNS:
774*
775*  TI_OK if successful, TI_NOK otherwise.
776*
777* \sa rsn_Start, rsn_Stop
778*/
779TI_STATUS rsn_setParam (TI_HANDLE hRsn, void *param)
780{
781    rsn_t               *pRsn;
782    paramInfo_t         *pParam = (paramInfo_t*)param;
783    TTwdParamInfo       tTwdParam;
784    TI_STATUS           status = TI_OK;
785
786    pRsn = (rsn_t*)hRsn;
787
788    if ( (NULL == pRsn) || (NULL == pParam) )
789    {
790        return TI_NOK;
791    }
792
793    TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set rsn_setParam   %X \n", pParam->paramType);
794
795    switch (pParam->paramType)
796    {
797
798    case RSN_DEFAULT_KEY_ID:
799    {
800        TI_UINT8  defKeyId, i;
801
802        defKeyId = pParam->content.rsnDefaultKeyID;
803
804        if(defKeyId >= MAX_KEYS_NUM)
805        {
806            TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "RSN: Error - the value of the default Key Id  is incorrect \n");
807            return TI_NOK;
808        }
809
810        /* Clean transmit flag (1 in the bit31) in the previous default key */
811        for(i = 0; i < MAX_KEYS_NUM; i++)
812        {
813            pRsn->keys[i].keyIndex &= 0x7FFFFFFF;
814        }
815
816        /* Set the default key ID value in the RSN data structure */
817        pRsn->defaultKeyId = defKeyId;
818
819        /* Set the default key ID in the HAL */
820        tTwdParam.paramType = TWD_RSN_DEFAULT_KEY_ID_PARAM_ID;
821        tTwdParam.content.configureCmdCBParams.pCb = &pRsn->defaultKeyId;
822        tTwdParam.content.configureCmdCBParams.fCb = NULL;
823        tTwdParam.content.configureCmdCBParams.hCb = NULL;
824        status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
825
826        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: default key ID =%d \n", pRsn->defaultKeyId);
827
828        sme_Restart (pRsn->hSmeSm);
829        break;
830    }
831
832    case RSN_ADD_KEY_PARAM:
833    {
834        TI_UINT8           keyIndex, i = 0;
835        ECipherSuite   cipherSuite;
836
837        status = pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &cipherSuite);
838        if (status !=TI_OK)
839        {
840            return status;
841        }
842
843        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);
844        keyIndex = (TI_UINT8)pParam->content.rsnOsKey.KeyIndex;
845        if (keyIndex >= MAX_KEYS_NUM)
846        {
847			return TI_NOK;
848        }
849
850		status = pRsn->pKeyParser->recv (pRsn->pKeyParser, (TI_UINT8*)&pParam->content.rsnOsKey, sizeof(pParam->content.rsnOsKey));
851
852        if (status != TI_OK)
853        {
854TRACE1(pRsn->hReport, REPORT_SEVERITY_WARNING, ": pRsn->pKeyParser->recv satus returned with status=%x. returning with NOK\n", status);
855            return TI_NOK;
856        }
857
858        /* If the Key is not BAD, it may be that WEP key is sent before WEP status is set,
859            save the key, and set it later at rsn_start */
860
861		/* If default Key not cleaned by calling rsn_removedDefKeys for keyIndex, Clean it */
862		if (pRsn->wepDefaultKeys[keyIndex] == TI_TRUE)
863		{
864			TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "Set RSN_ADD_KEY_PARAM KeyIndex  %x\n", keyIndex);
865			TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "Set RSN_ADD_KEY_PARAM wepDefaultKeys=%d\n", pRsn->wepDefaultKeys[keyIndex]);
866
867			pRsn->wepDefaultKeys[keyIndex] = TI_FALSE;
868
869		}
870
871		pRsn->keys[keyIndex].keyIndex = pParam->content.rsnOsKey.KeyIndex;
872		pRsn->keys[keyIndex].encLen = pParam->content.rsnOsKey.KeyLength;
873		MAC_COPY (pRsn->keys[keyIndex].macAddress, pParam->content.rsnOsKey.BSSID);
874		os_memoryCopy (pRsn->hOs, (void *)pRsn->keys[keyIndex].keyRsc, (TI_UINT8*)&(pParam->content.rsnOsKey.KeyRSC), KEY_RSC_LEN);
875		os_memoryCopy (pRsn->hOs, (void *)pRsn->keys[keyIndex].encKey, pParam->content.rsnOsKey.KeyMaterial, MAX_KEY_LEN);
876
877        /* Process the transmit flag (31-st bit of keyIndex).        */
878        /* If the added key has the TX bit set to TI_TRUE (i.e. the key */
879        /* is the new transmit key (default key), update             */
880        /* RSN data def.key Id and clean this bit in all other keys  */
881        if (pParam->content.rsnOsKey.KeyIndex & 0x80000000)
882        {
883            pRsn->defaultKeyId = keyIndex;
884
885            for (i = 0; i < MAX_KEYS_NUM; i ++)
886            {
887                if (i != keyIndex)
888                {
889                    pRsn->keys[i].keyIndex &= 0x7FFFFFFF;
890                }
891            }
892        }
893
894        if (pRsn->defaultKeysOn)
895        {   /* This is a WEP default key */
896            TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN_ADD_KEY_PARAM, Default key configured - keyIndex=%d-TI_TRUE\n", keyIndex);
897
898            pRsn->wepDefaultKeys[keyIndex] = TI_TRUE;
899            pRsn->wepStaticKey = TI_TRUE;
900            status = TI_OK;
901        }
902        break;
903    }
904    case RSN_REMOVE_KEY_PARAM:
905    {
906        TI_UINT8           keyIndex;
907        ECipherSuite   cipherSuite;
908
909        status = pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &cipherSuite);
910        if (status !=TI_OK)
911        {
912            return status;
913        }
914        /*if (cipherSuite == RSN_CIPHER_NONE)
915        {
916            TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "RSN: Error Remove Wep/Key when no encryption \n");
917            return TI_NOK;
918        }*/
919
920        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_REMOVE_KEY_PARAM KeyIndex  %x \n", pParam->content.rsnOsKey.KeyIndex);
921        keyIndex = (TI_UINT8)pParam->content.rsnOsKey.KeyIndex;
922        if (keyIndex >= MAX_KEYS_NUM)
923        {
924            return TI_NOK;
925        }
926
927        status = pRsn->pKeyParser->remove (pRsn->pKeyParser,
928                                           (TI_UINT8*)&pParam->content.rsnOsKey,
929                                           sizeof(pParam->content.rsnOsKey));
930
931        if (status == TI_OK)
932        {
933            pRsn->keys[keyIndex].keyType = KEY_NULL;
934            pRsn->keys[keyIndex].keyIndex &= 0x000000FF;
935        }
936
937        break;
938    }
939
940    case RSN_ENCRYPTION_STATUS_PARAM:
941        {
942            ECipherSuite   cipherSuite;
943
944            TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_ENCRYPTION_STATUS_PARAM rsnEncryptionStatus  %d \n", pParam->content.rsnEncryptionStatus);
945
946            pRsn->pAdmCtrl->getCipherSuite (pRsn->pAdmCtrl, &cipherSuite);
947            if (cipherSuite != pParam->content.rsnEncryptionStatus)
948            {
949                status = pRsn->pAdmCtrl->setUcastSuite (pRsn->pAdmCtrl, pParam->content.rsnEncryptionStatus);
950                status = pRsn->pAdmCtrl->setBcastSuite (pRsn->pAdmCtrl, pParam->content.rsnEncryptionStatus);
951                TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, " status = %d \n", status);
952            }
953            pRsn->defaultKeysOn = TI_TRUE;
954        }
955        break;
956
957    case RSN_EXT_AUTHENTICATION_MODE:
958        {
959            EExternalAuthMode  extAuthMode;
960
961            pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &extAuthMode);
962            if (pParam->content.rsnExtAuthneticationMode!=extAuthMode)
963            {
964                TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_EXT_AUTHENTICATION_MODE rsnExtAuthneticationMode  %d \n", pParam->content.rsnExtAuthneticationMode);
965
966                /*
967TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: remove all Keys\n");
968
969                for (keyIndex=0; keyIndex<MAX_KEYS_NUM; keyIndex++)
970                {
971                    os_memoryCopy(pRsn->hOs, &key, &pRsn->keys[keyIndex], sizeof(TSecurityKeys));
972                    pRsn->removeKey(pRsn, &key);
973
974                }*/
975
976                status = pRsn->pAdmCtrl->setExtAuthMode (pRsn->pAdmCtrl, pParam->content.rsnExtAuthneticationMode);
977            }
978            pRsn->defaultKeysOn = TI_TRUE;
979        }
980        break;
981
982#ifdef XCC_MODULE_INCLUDED
983    case RSN_XCC_NETWORK_EAP:
984        {
985            OS_XCC_NETWORK_EAP      networkEap;
986
987            pRsn->pAdmCtrl->getNetworkEap (pRsn->pAdmCtrl, &networkEap);
988            if (networkEap != pParam->content.networkEap)
989            {
990                TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_XCC_NETWORK_EAP networkEap  %d \n", pParam->content.networkEap);
991
992                status = pRsn->pAdmCtrl->setNetworkEap (pRsn->pAdmCtrl, pParam->content.networkEap);
993                if (status == TI_OK)
994                {
995                    /*status = RE_SCAN_NEEDED;*/
996                }
997            }
998        }
999        break;
1000#endif
1001    case RSN_MIXED_MODE:
1002        {
1003            TI_BOOL mixedMode;
1004
1005            pRsn->pAdmCtrl->getMixedMode (pRsn->pAdmCtrl, &mixedMode);
1006            if (mixedMode!=pParam->content.rsnMixedMode)
1007            {
1008                status = pRsn->pAdmCtrl->setMixedMode (pRsn->pAdmCtrl, pParam->content.rsnMixedMode);
1009
1010                TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_MIXED_MODE mixedMode  %d, status=%d \n", pParam->content.rsnMixedMode, status);
1011            }
1012            break;
1013        }
1014
1015    case RSN_PMKID_LIST:
1016        TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_PMKID_LIST \n");
1017
1018        TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8*)&pParam->content.rsnPMKIDList ,sizeof(OS_802_11_PMKID));
1019         status = pRsn->pAdmCtrl->setPmkidList (pRsn->pAdmCtrl,
1020                                                &pParam->content.rsnPMKIDList);
1021         if(status == TI_OK)
1022         {
1023            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);
1024         }
1025         else
1026         {
1027            TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_PMKID_LIST failure");
1028         }
1029        break;
1030
1031    case RSN_WPA_PROMOTE_OPTIONS:
1032         status = pRsn->pAdmCtrl->setPromoteFlags (pRsn->pAdmCtrl,
1033                                                   pParam->content.rsnWPAPromoteFlags);
1034         if(status == TI_OK)
1035         {
1036            TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set WPA promote options:  %d \n", pParam->content.rsnWPAPromoteFlags);
1037         }
1038         else
1039         {
1040            TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set WPA promote options failure");
1041         }
1042        break;
1043
1044    case RSN_EAP_TYPE:
1045        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Set RSN_EAP_TYPE eapType  %d \n", pParam->content.eapType);
1046
1047        pRsn->eapType = pParam->content.eapType;
1048	pRsn->defaultKeysOn = TI_TRUE;
1049        break;
1050
1051    case RSN_SET_KEY_PARAM:
1052        {
1053            TSecurityKeys *pSecurityKey = pParam->content.pRsnKey;
1054            TI_UINT32     keyIndex;
1055            TI_UINT8      j=0;
1056
1057            TRACE2(pRsn->hReport,REPORT_SEVERITY_INFORMATION,"RSN:Set RSN_SET_KEY_PARAM KeyIndex %x,keyLength=%d\n",pSecurityKey->keyIndex,pSecurityKey->encLen);
1058
1059            if(pSecurityKey->keyIndex >= MAX_KEYS_NUM)
1060            {
1061                return TI_NOK;
1062            }
1063
1064           keyIndex = (TI_UINT8)pSecurityKey->keyIndex;
1065           status = rsn_setKey (pRsn, pSecurityKey);  /* send key to FW*/
1066
1067           if (status == TI_OK)
1068           {
1069               //os_memoryCopy(pKeyDerive->hOs,&pRsn->pKeyParser->pUcastKey/pBcastKey, pEncodedKey, sizeof(encodedKeyMaterial_t));
1070           } /* check this copy */
1071
1072
1073           /* If the Key is not BAD, it may be that WEP key is sent before WEP status is set,
1074           save the key, and set it later at rsn_start */
1075
1076           pRsn->keys[keyIndex].keyIndex = pSecurityKey->keyIndex;
1077           pRsn->keys[keyIndex].encLen = pSecurityKey->encLen;
1078           MAC_COPY (pRsn->keys[keyIndex].macAddress, pSecurityKey->macAddress);
1079           os_memoryCopy(pRsn->hOs,(void*)pRsn->keys[keyIndex].keyRsc, (TI_UINT8*)&(pSecurityKey->keyRsc), KEY_RSC_LEN);
1080           os_memoryCopy (pRsn->hOs, (void *)pRsn->keys[keyIndex].encKey, (void*)pSecurityKey->encKey, MAX_KEY_LEN);
1081
1082           /* Process the transmit flag (31-st bit of keyIndex).        */
1083           /* If the added key has the TX bit set to TI_TRUE (i.e. the key */
1084           /* is the new transmit key (default key), update             */
1085           /* RSN data def.key Id and clean this bit in all other keys  */
1086           if (pSecurityKey->keyIndex & 0x80000000)
1087           {
1088               pRsn->defaultKeyId = keyIndex;
1089
1090               for (j = 0; j < MAX_KEYS_NUM; j++)
1091               {
1092                   if (j != keyIndex)
1093                   {
1094                       pRsn->keys[j].keyIndex &= 0x7FFFFFFF;
1095                   }
1096               }
1097           }
1098
1099           if (pRsn->defaultKeysOn)
1100           {   /* This is a WEP default key */
1101               TRACE1(pRsn->hReport,REPORT_SEVERITY_INFORMATION, "RSN_SET_KEY_PARAM, Default key configured-keyIndex=%d-TI_TRUE\n", keyIndex);
1102
1103               pRsn->wepDefaultKeys[keyIndex] = TI_TRUE;
1104               pRsn->wepStaticKey = TI_TRUE;
1105               status = TI_OK;
1106           }
1107           break;
1108        }
1109
1110    default:
1111        return TI_NOK;
1112    }
1113
1114    return status;
1115}
1116
1117
1118/**
1119*
1120* rsn_eventRecv - Set a specific parameter to the rsniation SM
1121*
1122* \b Description:
1123*
1124* Set a specific parameter to the rsniation SM.
1125*
1126* \b ARGS:
1127*
1128*  I   - hRsn - Rsniation SM context  \n
1129*  I/O - pParam - Parameter \n
1130*
1131* \b RETURNS:
1132*
1133*  TI_OK if successful, TI_NOK otherwise.
1134*
1135* \sa rsn_Start, rsn_Stop
1136*/
1137TI_STATUS rsn_reportStatus (rsn_t *pRsn, TI_STATUS rsnStatus)
1138{
1139    TI_STATUS           status = TI_OK;
1140    paramInfo_t         param;
1141    EExternalAuthMode   extAuthMode;
1142
1143    if (pRsn == NULL)
1144    {
1145        return TI_NOK;
1146    }
1147
1148    if (rsnStatus == TI_OK)
1149    {
1150        /* set EAPOL encryption status according to authentication protocol */
1151        pRsn->rsnCompletedTs = os_timeStampMs (pRsn->hOs);
1152
1153        status = pRsn->pAdmCtrl->getExtAuthMode (pRsn->pAdmCtrl, &extAuthMode);
1154        if (status != TI_OK)
1155        {
1156            return status;
1157        }
1158
1159        if (extAuthMode >= RSN_EXT_AUTH_MODE_WPA)
1160			txCtrlParams_setEapolEncryptionStatus (pRsn->hTxCtrl, TI_TRUE);
1161		else
1162			txCtrlParams_setEapolEncryptionStatus (pRsn->hTxCtrl, TI_FALSE);
1163
1164        /* set WEP invoked mode according to cipher suite */
1165        switch (pRsn->paeConfig.unicastSuite)
1166        {
1167        case TWD_CIPHER_NONE:
1168            param.content.txDataCurrentPrivacyInvokedMode = TI_FALSE;
1169            break;
1170
1171        default:
1172            param.content.txDataCurrentPrivacyInvokedMode = TI_TRUE;
1173            break;
1174        }
1175
1176		txCtrlParams_setCurrentPrivacyInvokedMode(pRsn->hTxCtrl, param.content.txDataCurrentPrivacyInvokedMode);
1177        /* The value of exclude unencrypted should be as privacy invoked */
1178        param.paramType = RX_DATA_EXCLUDE_UNENCRYPTED_PARAM;
1179        rxData_setParam (pRsn->hRx, &param);
1180
1181        param.paramType = RX_DATA_EXCLUDE_BROADCAST_UNENCRYPTED_PARAM;
1182        if (pRsn->pAdmCtrl->mixedMode)
1183        {   /* do not exclude Broadcast packets */
1184            param.content.txDataCurrentPrivacyInvokedMode = TI_FALSE;
1185        }
1186        rxData_setParam (pRsn->hRx, &param);
1187    }
1188
1189    else
1190        rsnStatus = (TI_STATUS)STATUS_SECURITY_FAILURE;
1191
1192    status = conn_reportRsnStatus (pRsn->hConn, (mgmtStatus_e)rsnStatus);
1193
1194    if (status!=TI_OK)
1195    {
1196        return status;
1197    }
1198
1199    if (rsnStatus == TI_OK)
1200    {
1201        EvHandlerSendEvent (pRsn->hEvHandler, IPC_EVENT_AUTH_SUCC, NULL, 0);
1202    }
1203
1204    TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_reportStatus \n");
1205
1206    return TI_OK;
1207}
1208
1209
1210/**
1211*
1212* rsn_eventRecv - Set a specific parameter to the rsniation SM
1213*
1214* \b Description:
1215*
1216* Set a specific parameter to the rsniation SM.
1217*
1218* \b ARGS:
1219*
1220*  I   - hRsn - Rsniation SM context  \n
1221*  I/O - pParam - Parameter \n
1222*
1223* \b RETURNS:
1224*
1225*  TI_OK if successful, TI_NOK otherwise.
1226*
1227* \sa rsn_Start, rsn_Stop
1228*/
1229TI_STATUS rsn_setPaeConfig(rsn_t *pRsn, TRsnPaeConfig *pPaeConfig)
1230{
1231    TI_STATUS           status;
1232    mainSecInitData_t   initData;
1233
1234    if ( (NULL == pRsn) || (NULL == pPaeConfig) )
1235    {
1236        return TI_NOK;
1237    }
1238
1239    TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: Calling set PAE config..., unicastSuite = %d, broadcastSuite = %d \n", pPaeConfig->unicastSuite, pPaeConfig->broadcastSuite);
1240
1241    os_memoryCopy(pRsn->hOs, &pRsn->paeConfig, pPaeConfig, sizeof(TRsnPaeConfig));
1242
1243    initData.pPaeConfig = &pRsn->paeConfig;
1244
1245    status = mainSec_config (pRsn->pMainSecSm,
1246                             &initData,
1247                             pRsn,
1248                             pRsn->hReport,
1249                             pRsn->hOs,
1250                             pRsn->hCtrlData,
1251                             pRsn->hEvHandler,
1252                             pRsn->hConn,
1253                             pRsn->hTimer);
1254
1255    return status;
1256}
1257
1258
1259/**
1260*
1261* rsn_eventRecv - Set a specific parameter to the rsniation SM
1262*
1263* \b Description:
1264*
1265* Set a specific parameter to the rsniation SM.
1266*
1267* \b ARGS:
1268*
1269*  I   - hRsn - Rsniation SM context  \n
1270*  I/O - pParam - Parameter \n
1271*
1272* \b RETURNS:
1273*
1274*  TI_OK if successful, TI_NOK otherwise.
1275*
1276* \sa rsn_Start, rsn_Stop
1277*/
1278TI_STATUS rsn_getNetworkMode(rsn_t *pRsn, ERsnNetworkMode *pNetMode)
1279{
1280    paramInfo_t     param;
1281    TI_STATUS       status;
1282
1283    param.paramType = CTRL_DATA_CURRENT_BSS_TYPE_PARAM;
1284
1285    status =  ctrlData_getParam (pRsn->hCtrlData, &param);
1286
1287    if (status == TI_OK)
1288    {
1289        if (param.content.ctrlDataCurrentBssType == BSS_INFRASTRUCTURE)
1290        {
1291            *pNetMode = RSN_INFRASTRUCTURE;
1292        }
1293        else
1294        {
1295            *pNetMode = RSN_IBSS;
1296        }
1297    }
1298    else
1299    {
1300        return TI_NOK;
1301    }
1302
1303    return TI_OK;
1304}
1305
1306
1307/**
1308*
1309* rsn_eventRecv - Set a specific parameter to the rsniation SM
1310*
1311* \b Description:
1312*
1313* Set a specific parameter to the rsniation SM.
1314*
1315* \b ARGS:
1316*
1317*  I   - hRsn - Rsniation SM context  \n
1318*  I/O - pParam - Parameter \n
1319*
1320* \b RETURNS:
1321*
1322*  TI_OK if successful, TI_NOK otherwise.
1323*
1324* \sa rsn_Start, rsn_Stop
1325*/
1326TI_STATUS rsn_evalSite(TI_HANDLE hRsn, TRsnData *pRsnData, TRsnSiteParams *pRsnSiteParams, TI_UINT32 *pMetric)
1327{
1328
1329    rsn_t       *pRsn;
1330    TI_STATUS    status;
1331
1332    if ( (NULL == pRsnData) || (NULL == hRsn) )
1333    {
1334        *pMetric = 0;
1335        return TI_NOK;
1336    }
1337
1338    pRsn = (rsn_t*)hRsn;
1339
1340    if (rsn_isSiteBanned(hRsn, pRsnSiteParams->bssid) == TI_TRUE)
1341    {
1342        *pMetric = 0;
1343        TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Site is banned!\n");
1344        return TI_NOK;
1345    }
1346
1347    status = pRsn->pAdmCtrl->evalSite (pRsn->pAdmCtrl, pRsnData, pRsnSiteParams, pMetric);
1348
1349    TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": pMetric=%d status=%d\n", *pMetric, status);
1350
1351    return status;
1352}
1353
1354
1355/**
1356*
1357* rsn_getInfoElement -
1358*
1359* \b Description:
1360*
1361* Get the RSN information element.
1362*
1363* \b ARGS:
1364*
1365*  I   - hRsn - Rsn SM context  \n
1366*  I/O - pRsnIe - Pointer to the return information element \n
1367*  I/O - pRsnIeLen - Pointer to the returned IE's length \n
1368*
1369* \b RETURNS:
1370*
1371*  TI_OK if successful, TI_NOK otherwise.
1372*
1373* \sa
1374*/
1375TI_STATUS rsn_getInfoElement(TI_HANDLE hRsn, TI_UINT8 *pRsnIe, TI_UINT32 *pRsnIeLen)
1376{
1377    rsn_t       *pRsn;
1378    TI_STATUS   status;
1379
1380    if ( (NULL == hRsn) || (NULL == pRsnIe) || (NULL == pRsnIeLen) )
1381    {
1382        return TI_NOK;
1383    }
1384
1385    pRsn = (rsn_t*)hRsn;
1386
1387    status = pRsn->pAdmCtrl->getInfoElement (pRsn->pAdmCtrl, pRsnIe, pRsnIeLen);
1388
1389    TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_getInfoElement pRsnIeLen= %d\n",*pRsnIeLen);
1390
1391    return status;
1392}
1393
1394
1395#ifdef XCC_MODULE_INCLUDED
1396/**
1397*
1398* rsn_getXCCExtendedInfoElement -
1399*
1400* \b Description:
1401*
1402* Get the Aironet information element.
1403*
1404* \b ARGS:
1405*
1406*  I   - hRsn - Rsn SM context  \n
1407*  I/O - pRsnIe - Pointer to the return information element \n
1408*  I/O - pRsnIeLen - Pointer to the returned IE's length \n
1409*
1410* \b RETURNS:
1411*
1412*  TI_OK if successful, TI_NOK otherwise.
1413*
1414* \sa
1415*/
1416TI_STATUS rsn_getXCCExtendedInfoElement(TI_HANDLE hRsn, TI_UINT8 *pRsnIe, TI_UINT8 *pRsnIeLen)
1417{
1418    rsn_t       *pRsn;
1419    TI_STATUS   status;
1420
1421    if ( (NULL == hRsn) || (NULL == pRsnIe) || (NULL == pRsnIeLen) )
1422    {
1423        return TI_NOK;
1424    }
1425
1426    pRsn = (rsn_t*)hRsn;
1427
1428    status = admCtrlXCC_getInfoElement (pRsn->pAdmCtrl, pRsnIe, pRsnIeLen);
1429
1430    TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_getXCCExtendedInfoElement pRsnIeLen= %d\n",*pRsnIeLen);
1431
1432    return status;
1433}
1434#endif
1435
1436
1437/**
1438*
1439* rsn_eventRecv - Set a specific parameter to the rsniation SM
1440*
1441* \b Description:
1442*
1443* Set a specific parameter to the rsniation SM.
1444*
1445* \b ARGS:
1446*
1447*  I   - hRsn - Rsniation SM context  \n
1448*  I/O - pParam - Parameter \n
1449*
1450* \b RETURNS:
1451*
1452*  TI_OK if successful, TI_NOK otherwise.
1453*
1454* \sa rsn_Start, rsn_Stop
1455*/
1456TI_STATUS rsn_setSite(TI_HANDLE hRsn, TRsnData *pRsnData, TI_UINT8 *pAssocIe, TI_UINT8 *pAssocIeLen)
1457{
1458    rsn_t      *pRsn;
1459    TI_STATUS   status;
1460
1461    if ( (NULL == pRsnData) || (NULL == hRsn) )
1462    {
1463        *pAssocIeLen = 0;
1464        return TI_NOK;
1465    }
1466
1467    pRsn = (rsn_t*)hRsn;
1468
1469    status = pRsn->pAdmCtrl->setSite (pRsn->pAdmCtrl, pRsnData, pAssocIe, pAssocIeLen);
1470
1471    TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_setSite ieLen= %d\n",pRsnData->ieLen);
1472    return status;
1473}
1474
1475
1476TI_STATUS rsn_setKey (rsn_t *pRsn, TSecurityKeys *pKey)
1477{
1478    TTwdParamInfo       tTwdParam;
1479    TI_UINT8            keyIndex;
1480    TI_BOOL				macIsBroadcast = TI_FALSE;
1481    TI_STATUS           status = TI_OK;
1482
1483	if (pRsn == NULL || pKey == NULL)
1484	{
1485		return TI_NOK;
1486	}
1487
1488	keyIndex = (TI_UINT8)pKey->keyIndex;
1489    if (keyIndex >= MAX_KEYS_NUM)
1490    {
1491        return TI_NOK;
1492    }
1493
1494    if (pKey->keyType != KEY_NULL)
1495    {
1496        /* set the size to reserve for encryption to the tx */
1497        /* update this parameter only in accordance with pairwise key setting */
1498       if (!MAC_BROADCAST(pKey->macAddress))
1499        {
1500
1501        /* set the size to reserve for encryption to the tx */
1502            switch (pKey->keyType)
1503            {
1504                case KEY_TKIP:
1505			        txCtrlParams_setEncryptionFieldSizes (pRsn->hTxCtrl, IV_FIELD_SIZE);
1506                    break;
1507                case KEY_AES:
1508			        txCtrlParams_setEncryptionFieldSizes (pRsn->hTxCtrl, AES_AFTER_HEADER_FIELD_SIZE);
1509                    break;
1510                case KEY_NULL:
1511                case KEY_WEP:
1512                case KEY_XCC:
1513                default:
1514			        txCtrlParams_setEncryptionFieldSizes (pRsn->hTxCtrl, 0);
1515                    break;
1516            }
1517
1518        }
1519
1520
1521        macIsBroadcast = MAC_BROADCAST (pKey->macAddress);
1522		if ((pRsn->keys[keyIndex].keyType != KEY_NULL )&&
1523			macIsBroadcast && !MAC_BROADCAST((pRsn->keys[keyIndex].macAddress)))
1524		{	/* In case a new Group key is set instead of a Unicast key,
1525			first remove the UNIcast key from FW */
1526			rsn_removeKey(pRsn, &pRsn->keys[keyIndex]);
1527		}
1528
1529        pRsn->keys[keyIndex].keyType = pKey->keyType;
1530        pRsn->keys[keyIndex].keyIndex = keyIndex;
1531
1532        tTwdParam.paramType = TWD_RSN_KEY_ADD_PARAM_ID;
1533        tTwdParam.content.configureCmdCBParams.pCb = (TI_UINT8*) pKey;
1534        tTwdParam.content.configureCmdCBParams.fCb = NULL;
1535        tTwdParam.content.configureCmdCBParams.hCb = NULL;
1536
1537		if (macIsBroadcast)
1538        {
1539            TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setKey, Group ReKey timer started\n");
1540            tmr_StopTimer (pRsn->hMicFailureGroupReKeyTimer);
1541            tmr_StartTimer (pRsn->hMicFailureGroupReKeyTimer,
1542                            rsn_groupReKeyTimeout,
1543                            (TI_HANDLE)pRsn,
1544                            RSN_MIC_FAILURE_RE_KEY_TIMEOUT,
1545                            TI_FALSE);
1546            pRsn->eGroupKeyUpdate = GROUP_KEY_UPDATE_TRUE;
1547        }
1548		else
1549        {
1550			if (pRsn->bPairwiseMicFailureFilter)	/* the value of this flag is taken from registry */
1551			{
1552				TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setKey, Pairwise ReKey timer started\n");
1553				tmr_StopTimer (pRsn->hMicFailurePairwiseReKeyTimer);
1554				tmr_StartTimer (pRsn->hMicFailurePairwiseReKeyTimer,
1555								rsn_pairwiseReKeyTimeout,
1556								(TI_HANDLE)pRsn,
1557								RSN_MIC_FAILURE_RE_KEY_TIMEOUT,
1558								TI_FALSE);
1559				pRsn->ePairwiseKeyUpdate = PAIRWISE_KEY_UPDATE_TRUE;
1560			}
1561        }
1562
1563
1564        /* Mark key as added */
1565        pRsn->keys_en [keyIndex] = TI_TRUE;
1566
1567        status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
1568    }
1569
1570    TRACE3(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setKey, KeyType=%d, KeyId = 0x%lx,encLen=0x%x\n", pKey->keyType,pKey->keyIndex, pKey->encLen);
1571
1572    TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nEncKey = ");
1573
1574    TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->encKey, pKey->encLen);
1575
1576    if (pKey->keyType != KEY_WEP)
1577    {
1578        TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nMac address = ");
1579        TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->macAddress, MAC_ADDR_LEN);
1580        TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nRSC = ");
1581        TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->keyRsc, KEY_RSC_LEN);
1582        TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nMic RX = ");
1583        TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->micRxKey, MAX_KEY_LEN);
1584        TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "\nMic TX = ");
1585        TRACE_INFO_HEX(pRsn->hReport, (TI_UINT8 *)pKey->micTxKey, MAX_KEY_LEN);
1586    }
1587
1588    return status;
1589}
1590
1591
1592TI_STATUS rsn_removeKey (rsn_t *pRsn, TSecurityKeys *pKey)
1593{
1594    TI_STATUS           status = TI_OK;
1595    TTwdParamInfo       tTwdParam;
1596    TI_UINT8               keyIndex;
1597
1598	if (pRsn == NULL || pKey == NULL)
1599	{
1600		return TI_NOK;
1601	}
1602
1603	keyIndex = (TI_UINT8)pKey->keyIndex;
1604    if (keyIndex >= MAX_KEYS_NUM)
1605    {
1606        return TI_NOK;
1607    }
1608
1609    TRACE2(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removeKey Entry, keyType=%d, keyIndex=0x%lx\n",pKey->keyType, keyIndex);
1610
1611    /* Now set to the RSN structure. */
1612    if (pKey->keyType != KEY_NULL && pRsn->keys_en[keyIndex])
1613    {
1614        tTwdParam.paramType = TWD_RSN_KEY_REMOVE_PARAM_ID;
1615        /*os_memoryCopy(pRsn->hOs, &tTwdParam.content.rsnKey, pKey, sizeof(TSecurityKeys));*/
1616        tTwdParam.content.configureCmdCBParams.pCb = (TI_UINT8*) pKey;
1617        tTwdParam.content.configureCmdCBParams.fCb = NULL;
1618        tTwdParam.content.configureCmdCBParams.hCb = NULL;
1619
1620        /* If keyType is TKIP or AES, set the encLen to the KEY enc len - 16 */
1621        if (pKey->keyType == KEY_TKIP || pKey->keyType == KEY_AES)
1622        {
1623            pKey->encLen = 16;
1624            if (keyIndex != 0)
1625            {
1626                const TI_UINT8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1627                /*
1628                 * if keyType is TKIP or AES, and the key index is broadcast, overwrite the MAC address as broadcast
1629                 * for removing the Broadcast key from the FW
1630                 */
1631                MAC_COPY (pKey->macAddress, broadcast);
1632            }
1633        }
1634		else if (pKey->keyType == KEY_WEP)
1635		{
1636			/* In full driver we use only WEP default keys. To remove it we make sure that the MAC address is NULL */
1637			os_memoryZero(pRsn->hOs,(void*)pKey->macAddress,sizeof(TMacAddr));
1638		}
1639
1640
1641        /* Mark key as deleted */
1642        pRsn->keys_en[keyIndex] = TI_FALSE;
1643
1644        status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
1645
1646        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_removeKey in whal, status =%d\n", status);
1647
1648        /* clean the key flags*/
1649        pRsn->keys[keyIndex].keyIndex &= 0x000000FF;
1650        pRsn->keys[keyIndex].keyType   = KEY_NULL;
1651        pRsn->keys[keyIndex].encLen    = 0;
1652        pRsn->wepDefaultKeys[keyIndex] = TI_FALSE;
1653    }
1654
1655    return status;
1656}
1657
1658
1659TI_STATUS rsn_setDefaultKeyId(rsn_t *pRsn, TI_UINT8 keyId)
1660{
1661    TI_STATUS               status = TI_OK;
1662    TTwdParamInfo           tTwdParam;
1663
1664    if (pRsn == NULL)
1665    {
1666        return TI_NOK;
1667    }
1668    pRsn->defaultKeyId = keyId;
1669    /* Now we configure default key ID to the HAL */
1670    tTwdParam.paramType = TWD_RSN_DEFAULT_KEY_ID_PARAM_ID;
1671    tTwdParam.content.configureCmdCBParams.pCb = &keyId;
1672    tTwdParam.content.configureCmdCBParams.fCb = NULL;
1673    tTwdParam.content.configureCmdCBParams.hCb = NULL;
1674    status = TWD_SetParam (pRsn->hTWD, &tTwdParam);
1675
1676    TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "RSN: rsn_setDefaultKeyId, KeyId = 0x%lx\n", keyId);
1677    return status;
1678}
1679
1680
1681TI_STATUS rsn_reportAuthFailure(TI_HANDLE hRsn, EAuthStatus authStatus)
1682{
1683    TI_STATUS    status = TI_OK;
1684    rsn_t       *pRsn;
1685    paramInfo_t param;
1686
1687    if (hRsn==NULL)
1688    {
1689        return TI_NOK;
1690    }
1691
1692    pRsn = (rsn_t*)hRsn;
1693
1694    /* Remove AP from candidate list for a specified amount of time */
1695	param.paramType = CTRL_DATA_CURRENT_BSSID_PARAM;
1696	status = ctrlData_getParam(pRsn->hCtrlData, &param);
1697	if (status != TI_OK)
1698	{
1699TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, "rsn_reportAuthFailure, unable to retrieve BSSID \n");
1700	}
1701    else
1702    {
1703        TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "current station is banned from the roaming candidates list for %d Ms\n", RSN_AUTH_FAILURE_TIMEOUT);
1704
1705        rsn_banSite(hRsn, param.content.ctrlDataCurrentBSSID, RSN_SITE_BAN_LEVEL_FULL, RSN_AUTH_FAILURE_TIMEOUT);
1706    }
1707
1708
1709#ifdef XCC_MODULE_INCLUDED
1710TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "CALLING rougeAP, status= %d \n",authStatus);
1711    status = XCCMngr_rogueApDetected (pRsn->hXCCMngr, authStatus);
1712#endif
1713    TI_VOIDCAST(pRsn);
1714    return status;
1715}
1716
1717
1718/******
1719This is the CB function for mic failure event from the FW
1720*******/
1721TI_STATUS rsn_reportMicFailure(TI_HANDLE hRsn, TI_UINT8 *pType, TI_UINT32 Length)
1722{
1723    rsn_t                               *pRsn = (rsn_t *) hRsn;
1724    ERsnSiteBanLevel                    banLevel;
1725    OS_802_11_AUTHENTICATION_REQUEST    *request;
1726    TI_UINT8 AuthBuf[sizeof(TI_UINT32) + sizeof(OS_802_11_AUTHENTICATION_REQUEST)];
1727    paramInfo_t                         param;
1728    TI_UINT8                               failureType;
1729
1730    failureType = *pType;
1731
1732   if (((pRsn->paeConfig.unicastSuite == TWD_CIPHER_TKIP) && (failureType == KEY_TKIP_MIC_PAIRWISE)) ||
1733        ((pRsn->paeConfig.broadcastSuite == TWD_CIPHER_TKIP) && (failureType == KEY_TKIP_MIC_GROUP)))
1734    {
1735        /* check if the MIC failure is group and group key update */
1736        /* was performed during the last 3 seconds */
1737        if ((failureType == KEY_TKIP_MIC_GROUP) &&
1738            (pRsn->eGroupKeyUpdate == GROUP_KEY_UPDATE_TRUE))
1739        {
1740            TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Group MIC failure ignored, key update was performed within the last 3 seconds.\n");
1741            return TI_OK;
1742        }
1743
1744		/* check if the MIC failure is pairwise and pairwise key update */
1745        /* was performed during the last 3 seconds */
1746        if ((failureType == KEY_TKIP_MIC_PAIRWISE) &&
1747            (pRsn->ePairwiseKeyUpdate == PAIRWISE_KEY_UPDATE_TRUE))
1748        {
1749            TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Pairwise MIC failure ignored, key update was performed within the last 3 seconds.\n");
1750            return TI_OK;
1751        }
1752
1753        /* Prepare the Authentication Request */
1754        request = (OS_802_11_AUTHENTICATION_REQUEST *)(AuthBuf + sizeof(TI_UINT32));
1755        request->Length = sizeof(OS_802_11_AUTHENTICATION_REQUEST);
1756
1757        param.paramType = CTRL_DATA_CURRENT_BSSID_PARAM;
1758        if (ctrlData_getParam (pRsn->hCtrlData, &param) != TI_OK)
1759        {
1760            return TI_NOK;
1761        }
1762
1763        /* Generate 802 Media specific indication event */
1764        *(TI_UINT32*)AuthBuf = os802_11StatusType_Authentication;
1765
1766        MAC_COPY (request->BSSID, param.content.ctrlDataCurrentBSSID);
1767
1768        if (failureType == KEY_TKIP_MIC_PAIRWISE)
1769        {
1770            request->Flags = OS_802_11_REQUEST_PAIRWISE_ERROR;
1771        }
1772        else
1773        {
1774            request->Flags = OS_802_11_REQUEST_GROUP_ERROR;
1775        }
1776
1777		EvHandlerSendEvent (pRsn->hEvHandler,
1778                            IPC_EVENT_MEDIA_SPECIFIC,
1779                            (TI_UINT8*)AuthBuf,
1780                            sizeof(TI_UINT32) + sizeof(OS_802_11_AUTHENTICATION_REQUEST));
1781        /* Update and check the ban level to decide what actions need to take place */
1782        banLevel = rsn_banSite (hRsn, param.content.ctrlDataCurrentBSSID, RSN_SITE_BAN_LEVEL_HALF, RSN_MIC_FAILURE_TIMEOUT);
1783        if (banLevel == RSN_SITE_BAN_LEVEL_FULL)
1784        {
1785            /* Site is banned so prepare to disconnect */
1786            TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Second MIC failure, closing Rx port...\n");
1787
1788            param.paramType = RX_DATA_PORT_STATUS_PARAM;
1789            param.content.rxDataPortStatus = CLOSE;
1790            rxData_setParam(pRsn->hRx, &param);
1791
1792            /* stop the mic failure Report timer and start a new one for 0.5 seconds */
1793            tmr_StopTimer (pRsn->hMicFailureReportWaitTimer);
1794		    apConn_setDeauthPacketReasonCode(pRsn->hAPConn, STATUS_MIC_FAILURE);
1795            tmr_StartTimer (pRsn->hMicFailureReportWaitTimer,
1796                            rsn_micFailureReportTimeout,
1797                            (TI_HANDLE)pRsn,
1798                            RSN_MIC_FAILURE_REPORT_TIMEOUT,
1799                            TI_FALSE);
1800        }
1801        else
1802        {
1803            /* Site is only half banned so nothing needs to be done for now */
1804            TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": First MIC failure, business as usual for now...\n");
1805        }
1806    }
1807
1808    return TI_OK;
1809}
1810
1811
1812void rsn_groupReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured)
1813{
1814    rsn_t *pRsn;
1815
1816    pRsn = (rsn_t*)hRsn;
1817
1818    if (pRsn == NULL)
1819    {
1820        return;
1821    }
1822
1823    pRsn->eGroupKeyUpdate = GROUP_KEY_UPDATE_FALSE;
1824}
1825
1826
1827void rsn_pairwiseReKeyTimeout(TI_HANDLE hRsn, TI_BOOL bTwdInitOccured)
1828{
1829    rsn_t *pRsn;
1830
1831    pRsn = (rsn_t*)hRsn;
1832
1833    if (pRsn == NULL)
1834    {
1835        return;
1836    }
1837
1838    pRsn->ePairwiseKeyUpdate = PAIRWISE_KEY_UPDATE_FALSE;
1839}
1840
1841void rsn_micFailureReportTimeout (TI_HANDLE hRsn, TI_BOOL bTwdInitOccured)
1842{
1843    rsn_t *pRsn;
1844
1845    pRsn = (rsn_t*)hRsn;
1846
1847    if (pRsn == NULL)
1848    {
1849        return;
1850    }
1851
1852    TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": MIC failure reported, disassociating...\n");
1853
1854    apConn_reportRoamingEvent (pRsn->hAPConn, ROAMING_TRIGGER_SECURITY_ATTACK, NULL);
1855}
1856
1857
1858/**
1859*
1860* rsn_resetPMKIDList -
1861*
1862* \b Description:
1863*   Cleans up the PMKID cache.
1864*   Called when SSID is being changed.
1865*
1866* \b ARGS:
1867*
1868*  I   - hRsn - Rsniation SM context  \n
1869*
1870* \b RETURNS:
1871*
1872*  TI_OK if successful, TI_NOK otherwise.
1873*/
1874
1875TI_STATUS rsn_resetPMKIDList(TI_HANDLE hRsn)
1876{
1877    rsn_t  *pRsn = (rsn_t*)hRsn;
1878
1879    if (!pRsn)
1880        return TI_NOK;
1881
1882    return (pRsn->pAdmCtrl->resetPmkidList (pRsn->pAdmCtrl));
1883}
1884
1885
1886void rsn_debugFunc(TI_HANDLE hRsn)
1887{
1888    rsn_t *pRsn;
1889
1890    if (hRsn == NULL)
1891    {
1892        return;
1893    }
1894    pRsn = (rsn_t*)hRsn;
1895
1896    WLAN_OS_REPORT(("rsnStartedTs, ts = %d\n", pRsn->rsnStartedTs));
1897    WLAN_OS_REPORT(("rsnCompletedTs, ts = %d\n", pRsn->rsnCompletedTs));
1898}
1899
1900
1901/**
1902*
1903* rsn_startPreAuth -
1904*
1905* \b Description:
1906*
1907* Start pre-authentication on a list of given BSSIDs.
1908*
1909* \b ARGS:
1910*
1911*  I   - hRsn - Rsniation SM context  \n
1912*  I/O - pBssidList - list of BSSIDs that require Pre-Auth \n
1913*
1914* \b RETURNS:
1915*
1916*  TI_OK if successful, TI_NOK otherwise.
1917*
1918* \sa
1919*/
1920TI_STATUS rsn_startPreAuth(TI_HANDLE hRsn, TBssidList4PreAuth *pBssidList)
1921{
1922    rsn_t       *pRsn;
1923    TI_STATUS    status;
1924
1925    if ( (NULL == hRsn) || (NULL == pBssidList) )
1926    {
1927        return TI_NOK;
1928    }
1929
1930    pRsn = (rsn_t*)hRsn;
1931
1932    status = pRsn->pAdmCtrl->startPreAuth (pRsn->pAdmCtrl, pBssidList);
1933
1934    TRACE0(pRsn->hReport, REPORT_SEVERITY_INFORMATION, "rsn_startPreAuth \n");
1935
1936    return status;
1937}
1938
1939
1940/**
1941 *
1942 * isSiteBanned -
1943 *
1944 * \b Description:
1945 *
1946 * Returns whether or not the site with the specified Bssid is banned or not.
1947 *
1948 * \b ARGS:
1949 *
1950 *  I   - hRsn - RSN module context \n
1951 *  I   - siteBssid - The desired site's bssid \n
1952 *
1953 * \b RETURNS:
1954 *
1955 *  TI_NOK iff site is banned.
1956 *
1957 */
1958TI_BOOL rsn_isSiteBanned(TI_HANDLE hRsn, TMacAddr siteBssid)
1959{
1960    rsn_t * pRsn = (rsn_t *) hRsn;
1961    rsn_siteBanEntry_t * entry;
1962
1963    /* Check if site is in the list */
1964    if ((entry = findBannedSiteAndCleanup(hRsn, siteBssid)) == NULL)
1965    {
1966        return TI_FALSE;
1967    }
1968
1969    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);
1970
1971    return (entry->banLevel == RSN_SITE_BAN_LEVEL_FULL);
1972}
1973
1974
1975/**
1976 *
1977 * rsn_PortStatus_Set API implementation-
1978 *
1979 * \b Description:
1980 *
1981 * set the status port according to the status flag
1982 *
1983 * \b ARGS:
1984 *
1985 *  I   - hRsn - RSN module context \n
1986 *  I   - state - The status flag \n
1987 *
1988 * \b RETURNS:
1989 *
1990 *  TI_STATUS.
1991 *
1992 */
1993TI_STATUS rsn_setPortStatus(TI_HANDLE hRsn, TI_BOOL state)
1994{
1995    rsn_t                   *pRsn = (rsn_t *)hRsn;
1996    struct externalSec_t	*pExtSec;
1997
1998    pExtSec = pRsn->pMainSecSm->pExternalSec;
1999    pExtSec->bPortStatus = state;
2000    return externalSec_rsnComplete(pExtSec);
2001}
2002
2003
2004/**
2005 *
2006 * rsn_banSite -
2007 *
2008 * \b Description:
2009 *
2010 * Bans the specified site from being associated to for the specified duration.
2011 * If a ban level of WARNING is given and no previous ban was in effect the
2012 * warning is marked down but other than that nothing happens. In case a previous
2013 * warning (or ban of course) is still in effect
2014 *
2015 * \b ARGS:
2016 *
2017 *  I   - hRsn - RSN module context \n
2018 *  I   - siteBssid - The desired site's bssid \n
2019 *  I   - banLevel - The desired level of ban (Warning / Ban)
2020 *  I   - durationMs - The duration of ban in milliseconds
2021 *
2022 * \b RETURNS:
2023 *
2024 *  The level of ban (warning / banned).
2025 *
2026 */
2027ERsnSiteBanLevel rsn_banSite(TI_HANDLE hRsn, TMacAddr siteBssid, ERsnSiteBanLevel banLevel, TI_UINT32 durationMs)
2028{
2029    rsn_t * pRsn = (rsn_t *) hRsn;
2030    rsn_siteBanEntry_t * entry;
2031
2032    /* Try finding the site in the list */
2033    if ((entry = findBannedSiteAndCleanup(hRsn, siteBssid)) != NULL)
2034    {
2035        /* Site found so a previous ban is still in effect */
2036        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]);
2037
2038        entry->banLevel = RSN_SITE_BAN_LEVEL_FULL;
2039    }
2040    else
2041    {
2042        /* Site doesn't appear in the list, so find a place to insert it */
2043        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);
2044
2045        entry = findEntryForInsert (hRsn);
2046
2047		MAC_COPY (entry->siteBssid, siteBssid);
2048        entry->banLevel = banLevel;
2049
2050        pRsn->numOfBannedSites++;
2051    }
2052
2053    entry->banStartedMs = os_timeStampMs (pRsn->hOs);
2054    entry->banDurationMs = durationMs;
2055
2056    return entry->banLevel;
2057}
2058
2059
2060/**
2061 *
2062 * findEntryForInsert -
2063 *
2064 * \b Description:
2065 *
2066 * Returns a place to insert a new banned site.
2067 *
2068 * \b ARGS:
2069 *
2070 *  I   - hRsn - RSN module context \n
2071 *
2072 * \b RETURNS:
2073 *
2074 *  A pointer to a suitable site entry.
2075 *
2076 */
2077static rsn_siteBanEntry_t * findEntryForInsert(TI_HANDLE hRsn)
2078{
2079    rsn_t * pRsn = (rsn_t *) hRsn;
2080
2081    /* In the extreme case that the list is full we overwrite an old entry */
2082    if (pRsn->numOfBannedSites == RSN_MAX_NUMBER_OF_BANNED_SITES)
2083    {
2084        TRACE0(pRsn->hReport, REPORT_SEVERITY_ERROR, ": No room left to insert new banned site, overwriting old one!\n");
2085
2086        return &(pRsn->bannedSites[0]);
2087    }
2088
2089    return &(pRsn->bannedSites[pRsn->numOfBannedSites]);
2090}
2091
2092
2093/**
2094 *
2095 * findBannedSiteAndCleanup -
2096 *
2097 * \b Description:
2098 *
2099 * Searches the banned sites list for the desired site while cleaning up
2100 * expired sites found along the way.
2101 *
2102 * Note that this function might change the structure of the banned sites
2103 * list so old iterators into the list might be invalidated.
2104 *
2105 * \b ARGS:
2106 *
2107 *  I   - hRsn - RSN module context \n
2108 *  I   - siteBssid - The desired site's bssid \n
2109 *
2110 * \b RETURNS:
2111 *
2112 *  A pointer to the desired site's entry if found,
2113 *  NULL otherwise.
2114 *
2115 */
2116static rsn_siteBanEntry_t * findBannedSiteAndCleanup(TI_HANDLE hRsn, TMacAddr siteBssid)
2117{
2118    rsn_t * pRsn = (rsn_t *) hRsn;
2119    int iter;
2120
2121    for (iter = 0; iter < pRsn->numOfBannedSites; iter++)
2122    {
2123        /* If this entry has expired we'd like to clean it up */
2124        if (os_timeStampMs(pRsn->hOs) - pRsn->bannedSites[iter].banStartedMs >= pRsn->bannedSites[iter].banDurationMs)
2125        {
2126            TRACE1(pRsn->hReport, REPORT_SEVERITY_INFORMATION, ": Found expired entry at index %d, cleaning it up...\n", iter);
2127
2128            /* Replace this entry with the last one */
2129            pRsn->bannedSites[iter] = pRsn->bannedSites[pRsn->numOfBannedSites - 1];
2130            pRsn->numOfBannedSites--;
2131
2132            /* we now repeat the iteration on this entry */
2133            iter--;
2134
2135            continue;
2136        }
2137
2138        /* Is this the entry for the site we're looking for? */
2139        if (MAC_EQUAL (siteBssid, pRsn->bannedSites[iter].siteBssid))
2140        {
2141            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);
2142
2143            return &pRsn->bannedSites[iter];
2144        }
2145    }
2146
2147    /* Entry not found... */
2148    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]);
2149
2150    return NULL;
2151}
2152
2153/**
2154 *
2155 * rsn_getPortStatus -
2156 *
2157 * \b Description:
2158 *
2159 * Returns the extrenalSec port status
2160 *
2161 * \b ARGS:
2162 *
2163 *  pRsn - pointer to RSN module context \n
2164 *
2165 * \b RETURNS:
2166 *
2167 *  TI_BOOL - the port status True = Open , False = Close
2168 *
2169 */
2170TI_BOOL rsn_getPortStatus(rsn_t *pRsn)
2171{
2172    struct externalSec_t	*pExtSec;
2173
2174    pExtSec = pRsn->pMainSecSm->pExternalSec;
2175    return pExtSec->bPortStatus;
2176}
2177
2178
2179#ifdef RSN_NOT_USED
2180
2181static TI_INT16 convertAscii2Unicode(TI_INT8* userPwd, TI_INT16 len)
2182{
2183    TI_INT16 i;
2184    TI_INT8 unsiiPwd[MAX_PASSWD_LEN];
2185
2186
2187    for (i=0; i<len; i++)
2188    {
2189        unsiiPwd[i] = userPwd[i];
2190    }
2191    for (i=0; i<len; i++)
2192    {
2193        userPwd[i*2] = unsiiPwd[i];
2194        userPwd[i*2+1] = 0;
2195    }
2196    return (TI_INT16)(len*2);
2197}
2198
2199#endif
2200
2201/***************************************************************************
2202*							rsn_reAuth				                   *
2203****************************************************************************
2204* DESCRIPTION:	This is a callback function called by the whalWPA module whenever
2205*				a broadcast TKIP key was configured to the FW.
2206*				It does the following:
2207*					-	resets the ReAuth flag
2208*					-	stops the ReAuth timer
2209*					-	restore the PS state
2210*					-	Send RE_AUTH_COMPLETED event to the upper layer.
2211*
2212* INPUTS:		hRsn - the object
2213*
2214* OUTPUT:		None
2215*
2216* RETURNS:		None
2217*
2218***************************************************************************/
2219void rsn_reAuth(TI_HANDLE hRsn)
2220{
2221	rsn_t *pRsn;
2222
2223	pRsn = (rsn_t*)hRsn;
2224
2225	if (pRsn == NULL)
2226	{
2227		return;
2228	}
2229
2230	if (rxData_IsReAuthInProgress(pRsn->hRx))
2231	{
2232		rxData_SetReAuthInProgress(pRsn->hRx, TI_FALSE);
2233		rxData_StopReAuthActiveTimer(pRsn->hRx);
2234		rxData_ReauthDisablePriority(pRsn->hRx);
2235		EvHandlerSendEvent(pRsn->hEvHandler, IPC_EVENT_RE_AUTH_COMPLETED, NULL, 0);
2236	}
2237}
2238