1/*
2 * mainKeysSm.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/** \file mainKeySM.c
35 * \brief Main key state machine implementation.
36 *
37 * \see mainKeySM.h
38*/
39
40/****************************************************************************
41 *                                                                          *
42 *   MODULE:  Main key SM													*
43 *   PURPOSE: Main key SM implmentation				  						*
44 *                                                                          *
45 ****************************************************************************/
46
47#define __FILE_ID__  FILE_ID_36
48#include "osApi.h"
49#include "paramOut.h"
50#include "timer.h"
51#include "report.h"
52#include "rsn.h"
53#include "rsnApi.h"
54#include "smeApi.h"
55#include "mainSecSm.h"
56#include "keyParser.h"
57#include "broadcastKeySM.h"
58#include "unicastKeySM.h"
59#include "mainKeysSm.h"
60#include "mainKeysSmInternal.h"
61#include "DataCtrl_Api.h"
62#include "admCtrl.h"
63#include "EvHandler.h"
64#include "TI_IPC_Api.h"
65#include "connApi.h"
66
67static TI_STATUS mainKeys_smEvent(struct _mainKeys_t *pMainKeys, TI_UINT8 event, void* pData);
68
69/**
70*
71* mainKeys_create
72*
73* \b Description:
74*
75* Allocate memory for the main security context, and create all the rest of the needed contexts.
76*
77* \b ARGS:
78*
79*  I - hOs - OS handle for OS operations.
80*
81* \b RETURNS:
82*
83*  pointer to main security context. If failed, returns NULL.
84*
85* \sa
86*/
87mainKeys_t* mainKeys_create(TI_HANDLE hOs)
88{
89	mainKeys_t 	*pHandle;
90	TI_STATUS		status;
91
92	/* allocate association context memory */
93	pHandle = (mainKeys_t*)os_memoryAlloc(hOs, sizeof(mainKeys_t));
94	if (pHandle == NULL)
95	{
96		return NULL;
97	}
98
99	os_memoryZero(hOs, pHandle, sizeof(mainKeys_t));
100
101	/* allocate memory for association state machine */
102	status = fsm_Create(hOs, &pHandle->pMainKeysSm, MAIN_KEYS_NUM_STATES, MAIN_KEYS_NUM_EVENTS);
103	if (status != TI_OK)
104	{
105		os_memoryFree(hOs, pHandle, sizeof(mainKeys_t));
106		return NULL;
107	}
108
109	pHandle->pKeyParser = keyParser_create(hOs);
110	if (pHandle->pKeyParser == NULL)
111	{
112		fsm_Unload(hOs, pHandle->pMainKeysSm);
113		os_memoryFree(hOs, pHandle, sizeof(mainKeys_t));
114		return NULL;
115	}
116
117	pHandle->pBcastSm = broadcastKey_create(hOs);
118	if (pHandle->pBcastSm == NULL)
119	{
120		keyParser_unload(pHandle->pKeyParser);
121		fsm_Unload(hOs, pHandle->pMainKeysSm);
122		os_memoryFree(hOs, pHandle, sizeof(mainKeys_t));
123		return NULL;
124	}
125
126	pHandle->pUcastSm = unicastKey_create(hOs);
127	if (pHandle->pBcastSm == NULL)
128	{
129		broadcastKey_unload(pHandle->pBcastSm);
130		keyParser_unload(pHandle->pKeyParser);
131		fsm_Unload(hOs, pHandle->pMainKeysSm);
132		os_memoryFree(hOs, pHandle, sizeof(mainKeys_t));
133		return NULL;
134	}
135
136	pHandle->hOs = hOs;
137
138	/* At first Timeout we will send MediaSpecific Event   */
139	/* At any other Timeout we will send the Timeout Event */
140
141	pHandle->mainKeysTimeoutCounter = TI_FALSE;
142
143	return pHandle;
144}
145
146/**
147*
148* mainKeys_config
149*
150* \b Description:
151*
152* Init main security state machine state machine
153*
154* \b ARGS:
155*
156*  none
157*
158* \b RETURNS:
159*
160*  TI_OK on success, TI_NOK otherwise.
161*
162* \sa
163*/
164TI_STATUS mainKeys_config (mainKeys_t    *pMainKeys,
165                           TRsnPaeConfig *pPaeConfig,
166                           void          *pParent,
167                           TI_HANDLE      hReport,
168                           TI_HANDLE      hOs,
169                           TI_HANDLE      hCtrlData,
170                           TI_HANDLE      hEvHandler,
171                           TI_HANDLE      hConn,
172                           TI_HANDLE      hRsn,
173                           TI_HANDLE      hTimer)
174
175{
176    TI_STATUS      status;
177
178	/** Main key State Machine matrix */
179	fsm_actionCell_t    mainKeysSM_matrix[MAIN_KEYS_NUM_STATES][MAIN_KEYS_NUM_EVENTS] =
180	{
181		/* next state and actions for IDLE state */
182		{	{MAIN_KEYS_STATE_START, (fsm_Action_t)mainKeys_startIdle},
183			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeySmNop},
184			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeySmUnexpected},
185			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeySmUnexpected},
186			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeySmUnexpected}
187		},
188
189		/* next state and actions for START state */
190		{	{MAIN_KEYS_STATE_START, (fsm_Action_t)mainKeySmUnexpected},
191			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeys_stopStart},
192			{MAIN_KEYS_STATE_UNICAST_COMPLETE, (fsm_Action_t)mainKeySmNop},
193			{MAIN_KEYS_STATE_BROADCAST_COMPLETE, (fsm_Action_t)mainKeySmNop},
194			{MAIN_KEYS_STATE_START, (fsm_Action_t)mainKeys_smTimeOut}
195		},
196
197		/* next state and actions for UNICAST COMPLETE state */
198		{	{MAIN_KEYS_STATE_UNICAST_COMPLETE, (fsm_Action_t)mainKeySmUnexpected},
199			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeys_stopUcastComplete},
200			{MAIN_KEYS_STATE_UNICAST_COMPLETE, (fsm_Action_t)mainKeySmNop},
201			{MAIN_KEYS_STATE_COMPLETE, (fsm_Action_t)mainKeys_bcastCompleteUcastComplete},
202			{MAIN_KEYS_STATE_UNICAST_COMPLETE, (fsm_Action_t)mainKeys_smTimeOut}
203		},
204
205		/* next state and actions for BROADCAST COMPLETE state */
206		{	{MAIN_KEYS_STATE_BROADCAST_COMPLETE, (fsm_Action_t)mainKeySmUnexpected},
207			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeys_stopBcastComplete},
208			{MAIN_KEYS_STATE_COMPLETE, (fsm_Action_t)mainKeys_ucastCompleteBcastComplete},
209			{MAIN_KEYS_STATE_BROADCAST_COMPLETE, (fsm_Action_t)mainKeySmNop},
210			{MAIN_KEYS_STATE_BROADCAST_COMPLETE, (fsm_Action_t)mainKeys_smTimeOut}
211		},
212
213		/* next state and actions for COMPLETE state */
214		{	{MAIN_KEYS_STATE_COMPLETE, (fsm_Action_t)mainKeySmUnexpected},
215			{MAIN_KEYS_STATE_IDLE, (fsm_Action_t)mainKeys_stopComplete},
216			{MAIN_KEYS_STATE_COMPLETE, (fsm_Action_t)mainKeySmNop},
217			{MAIN_KEYS_STATE_COMPLETE, (fsm_Action_t)mainKeySmNop},
218			{MAIN_KEYS_STATE_COMPLETE, (fsm_Action_t)mainKeySmUnexpected}
219		}
220	};
221
222	pMainKeys->hCtrlData = hCtrlData;
223	pMainKeys->hOs = hOs;
224	pMainKeys->hReport = hReport;
225    pMainKeys->hEvHandler = hEvHandler;
226    pMainKeys->hConn = hConn;
227    pMainKeys->hRsn = hRsn;
228    pMainKeys->hTimer = hTimer;
229
230    pMainKeys->pParent = pParent;
231	pMainKeys->keysTimeout = MAIN_KEYS_TIMEOUT;
232
233	pMainKeys->start = mainKeys_start;
234	pMainKeys->stop = mainKeys_stop;
235	pMainKeys->reportUcastStatus = mainKeys_reportUcastStatus;
236	pMainKeys->reportBcastStatus = mainKeys_reportBcastStatus;
237	pMainKeys->setKey = mainKeys_setKey;
238	pMainKeys->removeKey = mainKeys_removeKey;
239	pMainKeys->setDefaultKeyId = mainKeys_setDefaultKeyId;
240	pMainKeys->getSessionKey = mainKeys_getSessionKey;
241
242	pMainKeys->currentState = MAIN_KEYS_STATE_IDLE;
243
244	/* allocate OS timer memory */
245    if (pMainKeys->hSessionTimer == NULL)
246    {
247        pMainKeys->hSessionTimer = tmr_CreateTimer (pMainKeys->hTimer);
248        if (pMainKeys->hSessionTimer == NULL)
249        {
250            TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "mainKeys_config(): Failed to create hSessionTimer!\n");
251            return TI_NOK;
252        }
253	}
254
255    status = fsm_Config(pMainKeys->pMainKeysSm, &mainKeysSM_matrix[0][0],
256						MAIN_KEYS_NUM_STATES, MAIN_KEYS_NUM_EVENTS, NULL, pMainKeys->hOs);
257	if (status != TI_OK)
258	{
259TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error in configuring SM\n");
260		return status;
261	}
262
263	status = keyParser_config(pMainKeys->pKeyParser,
264                              pPaeConfig,
265                              pMainKeys->pUcastSm,
266                              pMainKeys->pBcastSm,
267                              pMainKeys,
268                              hReport,
269                              hOs,
270                              hCtrlData);
271	if (status != TI_OK)
272	{
273TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error in configuring key parser\n");
274		return status;
275	}
276
277	status = broadcastKey_config(pMainKeys->pBcastSm, pPaeConfig, pMainKeys, hReport, hOs);
278	if (status != TI_OK)
279	{
280TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error in configuring broadcast key SM\n");
281		return status;
282	}
283
284	status = unicastKey_config(pMainKeys->pUcastSm, pPaeConfig, pMainKeys, hReport, hOs);
285	if (status != TI_OK)
286	{
287TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error in configuring unicast key SM\n");
288		return status;
289	}
290
291	return TI_OK;
292}
293
294/**
295*
296* mainKeys_config
297*
298* \b Description:
299*
300* Init main security state machine state machine
301*
302* \b ARGS:
303*
304*  none
305*
306* \b RETURNS:
307*
308*  TI_OK on success, TI_NOK otherwise.
309*
310* \sa
311*/
312TI_STATUS mainKeys_unload(mainKeys_t *pMainKeys)
313{
314	TI_STATUS	status;
315
316	if (pMainKeys == NULL)
317	{
318		return TI_NOK;
319	}
320
321	status = fsm_Unload(pMainKeys->hOs, pMainKeys->pMainKeysSm);
322    if (status != TI_OK)
323	{
324		/* report failure but don't stop... */
325        TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error releasing FSM memory \n");
326	}
327
328	if (pMainKeys->hSessionTimer)
329	{
330		tmr_DestroyTimer (pMainKeys->hSessionTimer);
331	}
332    pMainKeys->hSessionTimer = NULL;
333
334    status = keyParser_unload(pMainKeys->pKeyParser);
335    if (status != TI_OK)
336	{
337		/* report failure but don't stop... */
338        TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error unloading key parser\n");
339	}
340
341	status = broadcastKey_unload(pMainKeys->pBcastSm);
342    if (status != TI_OK)
343	{
344		/* report failure but don't stop... */
345        TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error unloading broadcast key SM\n");
346	}
347
348	status = unicastKey_unload(pMainKeys->pUcastSm);
349    if (status != TI_OK)
350	{
351		/* report failure but don't stop... */
352        TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: Error unloading unicast key SM\n");
353	}
354
355	os_memoryFree(pMainKeys->hOs, pMainKeys, sizeof(mainKeys_t));
356
357    return TI_OK;
358}
359
360
361/**
362*
363* rsn_mainKeySmStart
364*
365* \b Description:
366*
367* START event handler
368*
369* \b ARGS:
370*
371*  I   - pCtrlB - station control block  \n
372*
373* \b RETURNS:
374*
375*  TI_OK on success, TI_NOK otherwise.
376*
377* \sa rsn_mainKeySmStop()
378*/
379
380TI_STATUS mainKeys_start(struct _mainKeys_t *pMainKeys)
381{
382	TI_STATUS  status;
383
384	status = mainKeys_smEvent(pMainKeys, MAIN_KEYS_EVENT_START, pMainKeys);
385
386	return status;
387}
388
389/**
390*
391* rsn_mainKeySmStop
392*
393* \b Description:
394*
395* STOP event handler
396*
397* \b ARGS:
398*
399*  I   - pCtrlB - station control block  \n
400*
401* \b RETURNS:
402*
403*  TI_OK on success, TI_NOK otherwise.
404*
405* \sa rsn_mainKeySmStart()
406*/
407
408TI_STATUS mainKeys_stop(struct _mainKeys_t *pMainKeys)
409{
410	TI_STATUS  status;
411
412	status = mainKeys_smEvent(pMainKeys, MAIN_KEYS_EVENT_STOP, pMainKeys);
413
414	return status;
415}
416
417/**
418*
419* rsn_mainKeySmReportUnicastComplete
420*
421* \b Description:
422*
423* UNICAST_COMPLETE event handler
424*
425* \b ARGS:
426*
427*  I   - pCtrlB - station control block  \n
428*
429* \b RETURNS:
430*
431*  TI_OK on success, TI_NOK otherwise.
432*
433* \sa rsn_mainKeySmReportBroadcastComplete()
434*/
435
436TI_STATUS mainKeys_reportUcastStatus(struct _mainKeys_t *pMainKeys, TI_STATUS ucastStatus)
437{
438	TI_STATUS    status=TI_NOK;
439    EExternalAuthMode extAuthMode;
440	struct _rsn_t *pRsn = pMainKeys->pParent->pParent;
441
442	if (ucastStatus == TI_OK)
443	{
444
445		txCtrlParams_setCurrentPrivacyInvokedMode(pRsn->hTxCtrl, TI_TRUE);
446
447		status = pRsn->pAdmCtrl->getExtAuthMode(pRsn->pAdmCtrl, &extAuthMode);
448        if (status != TI_OK)
449        {
450            return status;
451        }
452        if (extAuthMode >= RSN_EXT_AUTH_MODE_WPA)
453        {
454			txCtrlParams_setEapolEncryptionStatus(pRsn->hTxCtrl, TI_TRUE);
455        }
456        else
457        {
458			txCtrlParams_setEapolEncryptionStatus(pRsn->hTxCtrl, TI_FALSE);
459        }
460
461        status = mainKeys_smEvent(pMainKeys, MAIN_KEYS_EVENT_UCAST_COMPLETE, pMainKeys);
462	}
463
464	return status;
465}
466
467
468/**
469*
470* rsn_mainKeySmReportBroadcastComplete
471*
472* \b Description:
473*
474* BROADCAST_COMPLETE event handler
475*
476* \b ARGS:
477*
478*  I   - pCtrlB - station control block  \n
479*
480* \b RETURNS:
481*
482*  TI_OK on success, TI_NOK otherwise.
483*
484* \sa rsn_mainKeySmReportUnicastComplete()
485*/
486
487TI_STATUS mainKeys_reportBcastStatus(struct _mainKeys_t *pMainKeys, TI_STATUS bcastStatus)
488{
489	TI_STATUS  status=TI_NOK;
490
491	if (bcastStatus == TI_OK)
492	{
493		status = mainKeys_smEvent(pMainKeys, MAIN_KEYS_EVENT_BCAST_COMPLETE, pMainKeys);
494	}
495
496	return status;
497}
498
499/**
500*
501* mainKeySmSessionTimeout
502*
503* \b Description:
504*
505* SESSION_TIMEOUOT event handler
506*
507* \b ARGS:
508*
509*  I   - pData - station control block  \n
510*
511* \b RETURNS:
512*
513*  TI_OK on success, TI_NOK otherwise.
514*/
515TI_STATUS mainKeys_setKey(struct _mainKeys_t *pMainKeys, TSecurityKeys *pKey)
516{
517	return (pMainKeys->pParent->setKey(pMainKeys->pParent, pKey));
518}
519
520/**
521*
522* mainKeySmSessionTimeout
523*
524* \b Description:
525*
526* SESSION_TIMEOUOT event handler
527*
528* \b ARGS:
529*
530*  I   - pData - station control block  \n
531*
532* \b RETURNS:
533*
534*  TI_OK on success, TI_NOK otherwise.
535*/
536TI_STATUS mainKeys_removeKey(struct _mainKeys_t *pMainKeys, TSecurityKeys *pKey)
537{
538	return (pMainKeys->pParent->removeKey(pMainKeys->pParent, pKey));
539}
540
541/**
542*
543* mainKeySmSessionTimeout
544*
545* \b Description:
546*
547* SESSION_TIMEOUOT event handler
548*
549* \b ARGS:
550*
551*  I   - pData - station control block  \n
552*
553* \b RETURNS:
554*
555*  TI_OK on success, TI_NOK otherwise.
556*/
557TI_STATUS mainKeys_setDefaultKeyId(struct _mainKeys_t *pMainKeys, TI_UINT8 keyId)
558{
559	return (pMainKeys->pParent->setDefaultKeyId(pMainKeys->pParent, keyId));
560}
561
562/**
563*
564* mainKeySmSessionTimeout
565*
566* \b Description:
567*
568* SESSION_TIMEOUOT event handler
569*
570* \b ARGS:
571*
572*  I   - pData - station control block  \n
573*
574* \b RETURNS:
575*
576*  TI_OK on success, TI_NOK otherwise.
577*/
578TI_STATUS mainKeys_getSessionKey(struct _mainKeys_t *pMainKeys, TI_UINT8 *pKey, TI_UINT32 *pKeyLen)
579{
580	TI_STATUS		status;
581
582	status = pMainKeys->pParent->getSessionKey(pMainKeys->pParent, pKey, pKeyLen);
583
584	return status;
585}
586
587/**
588*
589* mainKeySmSessionTimeout
590*
591* \b Description:
592*
593* SESSION_TIMEOUOT event handler
594*
595* \b ARGS:
596*
597*  I   - pMainKeys - module handle  \n
598*  I   - bTwdInitOccured - Indicates if TWDriver recovery occured since timer started   \n
599*
600* \b RETURNS:
601*
602*  TI_OK on success, TI_NOK otherwise.
603*/
604
605void mainKeys_sessionTimeout(void *pMainKeys, TI_BOOL bTwdInitOccured)
606{
607
608	mainKeys_smEvent(pMainKeys, MAIN_KEYS_EVENT_SESSION_TIMEOUOT, pMainKeys);
609
610}
611
612
613static TI_STATUS mainKeys_smEvent(struct _mainKeys_t *pMainKeys, TI_UINT8 event, void* pData)
614{
615	TI_STATUS		status;
616	TI_UINT8		nextState;
617
618
619	status = fsm_GetNextState(pMainKeys->pMainKeysSm, pMainKeys->currentState, event, &nextState);
620	if (status != TI_OK)
621	{
622TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEYS_SM: ERROR - failed getting next state \n");
623
624		return(TI_NOK);
625	}
626
627	TRACE3( pMainKeys->hReport, REPORT_SEVERITY_INFORMATION, "mainKeys_smEvent: <currentState = %d, event = %d> --> nextState = %d\n", pMainKeys->currentState, event, nextState);
628
629	status = fsm_Event(pMainKeys->pMainKeysSm, &pMainKeys->currentState, event, pData);
630
631	return status;
632}
633/**
634*
635* mainKeySmStartSubKeySmsAndTimer
636*
637* \b Description:
638*
639* Starts unicast & broadcast key SMs and session timer.
640*
641* \b ARGS:
642*
643*  I   - pData - station control block  \n
644*
645* \b RETURNS:
646*
647*  TI_OK on success, TI_NOK otherwise.
648*/
649
650TI_STATUS mainKeys_startIdle(struct _mainKeys_t *pMainKeys)
651{
652	TI_STATUS  status;
653
654	status = pMainKeys->pUcastSm->start(pMainKeys->pUcastSm);
655	if (status != TI_OK)
656	{
657		return TI_NOK;
658	}
659
660	status = pMainKeys->pBcastSm->start(pMainKeys->pBcastSm);
661	if (status != TI_OK)
662	{
663		return TI_NOK;
664	}
665
666    tmr_StartTimer (pMainKeys->hSessionTimer,
667                    mainKeys_sessionTimeout,
668                    (TI_HANDLE)pMainKeys,
669                    pMainKeys->keysTimeout,
670                    TI_FALSE);
671
672	status = pMainKeys->pKeyParser->replayReset(pMainKeys->pKeyParser);
673
674	return status;
675}
676
677
678/**
679*
680* mainKeySmStopSubKeySmsAndTimer
681*
682* \b Description:
683*
684* Stops unicast & broadcast key SMs and session timer.
685*
686* \b ARGS:
687*
688*  I   - pData - station control block  \n
689*
690* \b RETURNS:
691*
692*  TI_OK on success, TI_NOK otherwise.
693*/
694TI_STATUS mainKeys_stopStart(struct _mainKeys_t *pMainKeys)
695{
696	TI_STATUS  status = TI_OK;
697
698	status = pMainKeys->pUcastSm->stop(pMainKeys->pUcastSm);
699	if (status != TI_OK)
700	{
701		return TI_NOK;
702	}
703
704	status = pMainKeys->pBcastSm->stop(pMainKeys->pBcastSm);
705	if (status != TI_OK)
706	{
707		return TI_NOK;
708	}
709
710	tmr_StopTimer (pMainKeys->hSessionTimer);
711
712	return status;
713}
714
715
716/**
717*
718* mainKeySmStopSubKeySmsAndTimer
719*
720* \b Description:
721*
722* Stops unicast & broadcast key SMs and session timer.
723*
724* \b ARGS:
725*
726*  I   - pData - station control block  \n
727*
728* \b RETURNS:
729*
730*  TI_OK on success, TI_NOK otherwise.
731*/
732TI_STATUS mainKeys_stopUcastComplete(struct _mainKeys_t *pMainKeys)
733{
734	TI_STATUS  status = TI_OK;
735
736	status = pMainKeys->pUcastSm->stop(pMainKeys->pUcastSm);
737	if (status != TI_OK)
738	{
739		return TI_NOK;
740	}
741
742	status = pMainKeys->pBcastSm->stop(pMainKeys->pBcastSm);
743	if (status != TI_OK)
744	{
745		return TI_NOK;
746	}
747
748	tmr_StopTimer (pMainKeys->hSessionTimer);
749
750	return status;
751}
752
753/**
754*
755* mainKeySmReportComplete
756*
757* \b Description:
758*
759* Report key complete to the main security SM.
760*
761* \b ARGS:
762*
763*  I   - pData - station control block  \n
764*
765* \b RETURNS:
766*
767*  TI_OK on success, TI_NOK otherwise.
768*/
769TI_STATUS mainKeys_bcastCompleteUcastComplete(struct _mainKeys_t *pMainKeys)
770{
771	TI_STATUS  status;
772
773    TRACE0(pMainKeys->hReport, REPORT_SEVERITY_INFORMATION, "mainKeys_bcastCompleteUcastComplete - sending Interrogate \n");
774
775    tmr_StopTimer (pMainKeys->hSessionTimer);
776
777	status = pMainKeys->pParent->reportKeysStatus(pMainKeys->pParent, TI_OK);
778
779	return status;
780}
781
782
783/**
784*
785* mainKeySmStopSubKeySmsAndTimer
786*
787* \b Description:
788*
789* Stops unicast & broadcast key SMs and session timer.
790*
791* \b ARGS:
792*
793*  I   - pData - station control block  \n
794*
795* \b RETURNS:
796*
797*  TI_OK on success, TI_NOK otherwise.
798*/
799TI_STATUS mainKeys_stopBcastComplete(struct _mainKeys_t *pMainKeys)
800{
801	TI_STATUS  status = TI_OK;
802
803	status = pMainKeys->pUcastSm->stop(pMainKeys->pUcastSm);
804	if (status != TI_OK)
805	{
806		return TI_NOK;
807	}
808
809	status = pMainKeys->pBcastSm->stop(pMainKeys->pBcastSm);
810	if (status != TI_OK)
811	{
812		return TI_NOK;
813	}
814
815	tmr_StopTimer (pMainKeys->hSessionTimer);
816
817	return status;
818}
819
820/**
821*
822* mainKeySmReportComplete
823*
824* \b Description:
825*
826* Report key complete to the main security SM.
827*
828* \b ARGS:
829*
830*  I   - pData - station control block  \n
831*
832* \b RETURNS:
833*
834*  TI_OK on success, TI_NOK otherwise.
835*/
836TI_STATUS mainKeys_ucastCompleteBcastComplete(struct _mainKeys_t *pMainKeys)
837{
838	TI_STATUS  status;
839
840    TRACE0(pMainKeys->hReport, REPORT_SEVERITY_INFORMATION, "mainKeys_ucastCompleteBcastComplete \n");
841
842	tmr_StopTimer (pMainKeys->hSessionTimer);
843	pMainKeys->mainKeysTimeoutCounter = TI_FALSE;
844	status = pMainKeys->pParent->reportKeysStatus(pMainKeys->pParent, TI_OK);
845
846	return status;
847}
848
849/**
850*
851* mainKeySmStopSubKeySmsAndTimer
852*
853* \b Description:
854*
855* Stops unicast & broadcast key SMs and session timer.
856*
857* \b ARGS:
858*
859*  I   - pData - station control block  \n
860*
861* \b RETURNS:
862*
863*  TI_OK on success, TI_NOK otherwise.
864*/
865TI_STATUS mainKeys_stopComplete(struct _mainKeys_t *pMainKeys)
866{
867	TI_STATUS  status = TI_OK;
868
869	status = pMainKeys->pUcastSm->stop(pMainKeys->pUcastSm);
870	if (status != TI_OK)
871	{
872		return TI_NOK;
873	}
874
875	status = pMainKeys->pBcastSm->stop(pMainKeys->pBcastSm);
876	if (status != TI_OK)
877	{
878		return TI_NOK;
879	}
880
881	return status;
882}
883
884/**
885*
886* mainKeySmLogMessage
887*
888* \b Description:
889*
890* Prints Log messge.\n
891* Start session timer.
892*
893* \b ARGS:
894*
895*  I   - pData - station control block  \n
896*
897* \b RETURNS:
898*
899*  TI_OK on success, TI_NOK otherwise.
900*/
901TI_STATUS mainKeys_smTimeOut(void* data)
902{
903	OS_802_11_AUTHENTICATION_REQUEST   *request;
904	TI_UINT8                   AuthBuf[sizeof(TI_UINT32) + sizeof(OS_802_11_AUTHENTICATION_REQUEST)];
905	paramInfo_t				param;
906	TI_STATUS				status;
907	struct _mainKeys_t 		*pMainKeys = (struct _mainKeys_t *)data;
908
909
910TRACE1(pMainKeys->hReport, REPORT_SEVERITY_INFORMATION, "MAIN_KEY_SM: TRAP: Session Timeout for station , mainKeysTimeoutCounter=%d\n", pMainKeys->mainKeysTimeoutCounter);
911
912	request = (OS_802_11_AUTHENTICATION_REQUEST *)(AuthBuf + sizeof(TI_UINT32));
913	request->Length = sizeof(OS_802_11_AUTHENTICATION_REQUEST);
914
915	param.paramType = CTRL_DATA_CURRENT_BSSID_PARAM;
916	status = ctrlData_getParam(pMainKeys->hCtrlData, &param);
917	if (status != TI_OK)
918	{
919		return TI_NOK;
920	}
921
922    TRACE1(pMainKeys->hReport, REPORT_SEVERITY_INFORMATION, "current station is banned from the roaming candidates list for %d Ms\n", RSN_MAIN_KEYS_SESSION_TIMEOUT);
923
924    rsn_banSite(pMainKeys->hRsn, param.content.ctrlDataCurrentBSSID, RSN_SITE_BAN_LEVEL_FULL, RSN_MAIN_KEYS_SESSION_TIMEOUT);
925
926
927	/* mainKeysTimeoutCounter is a boolean variable, With states:	*/
928	/* TI_TRUE - It is a Timeout Association Event						*/
929	/* TI_FALSE - It is a Media specific Event							*/
930
931	if (!pMainKeys->mainKeysTimeoutCounter)
932	{
933		/* Fill Media specific indication fields and send to OS/User    */
934		MAC_COPY (request->BSSID, param.content.ctrlDataCurrentBSSID);
935
936		request->Flags = OS_802_11_REQUEST_REAUTH;
937
938		*(TI_UINT32*)AuthBuf = os802_11StatusType_Authentication;
939
940TRACE1(pMainKeys->hReport, REPORT_SEVERITY_INFORMATION, " %d Ms\n",RSN_MAIN_KEYS_SESSION_TIMEOUT);
941
942		EvHandlerSendEvent(pMainKeys->hEvHandler, IPC_EVENT_MEDIA_SPECIFIC, (TI_UINT8*)AuthBuf,
943							sizeof(TI_UINT32) + sizeof(OS_802_11_AUTHENTICATION_REQUEST));
944
945        tmr_StartTimer (pMainKeys->hSessionTimer,
946                        mainKeys_sessionTimeout,
947                        (TI_HANDLE)pMainKeys,
948                        pMainKeys->keysTimeout,
949                        TI_FALSE);
950
951		pMainKeys->mainKeysTimeoutCounter = TI_TRUE;
952	}
953	else
954	{
955        pMainKeys->mainKeysTimeoutCounter = TI_FALSE;
956        rsn_reportAuthFailure(pMainKeys->hRsn, RSN_AUTH_STATUS_TIMEOUT);
957        conn_reportRsnStatus(pMainKeys->hConn, (mgmtStatus_e)STATUS_SECURITY_FAILURE);
958	}
959	return TI_OK;
960}
961
962
963TI_STATUS mainKeySmUnexpected(struct _mainKeys_t *pMainKeys)
964{
965TRACE0(pMainKeys->hReport, REPORT_SEVERITY_ERROR, "MAIN_KEY_SM: ERROR UnExpected Event\n");
966
967	return(TI_OK);
968}
969
970TI_STATUS mainKeySmNop(struct _mainKeys_t *pMainKeys)
971{
972	return(TI_OK);
973}
974
975void mainKeys_reAuth(TI_HANDLE pHandle)
976{
977	mainKeys_t 	*pMainKeys = (mainKeys_t *)pHandle;
978
979	rsn_reAuth(pMainKeys->hRsn);
980}
981