Home | History | Annotate | Download | only in rsn
      1 /** \file mainSecSm.c
      2  *  \brief 802.1X finite state machine header file
      3  *
      4  *  \see mainSecSm.h
      5  */
      6 
      7 /****************************************************************************
      8 **+-----------------------------------------------------------------------+**
      9 **|                                                                       |**
     10 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
     11 **| All rights reserved.                                                  |**
     12 **|                                                                       |**
     13 **| Redistribution and use in source and binary forms, with or without    |**
     14 **| modification, are permitted provided that the following conditions    |**
     15 **| are met:                                                              |**
     16 **|                                                                       |**
     17 **|  * Redistributions of source code must retain the above copyright     |**
     18 **|    notice, this list of conditions and the following disclaimer.      |**
     19 **|  * Redistributions in binary form must reproduce the above copyright  |**
     20 **|    notice, this list of conditions and the following disclaimer in    |**
     21 **|    the documentation and/or other materials provided with the         |**
     22 **|    distribution.                                                      |**
     23 **|  * Neither the name Texas Instruments nor the names of its            |**
     24 **|    contributors may be used to endorse or promote products derived    |**
     25 **|    from this software without specific prior written permission.      |**
     26 **|                                                                       |**
     27 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     28 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     29 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     30 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     31 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     32 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     33 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     34 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     35 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     36 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     37 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     38 **|                                                                       |**
     39 **+-----------------------------------------------------------------------+**
     40 ****************************************************************************/
     41 
     42 /***************************************************************************/
     43 /*																		   */
     44 /*		MODULE:	mainSecSm.c											   	   */
     45 /*    PURPOSE:	Main Security State Machine API					   		   */
     46 /*																	 	   */
     47 /***************************************************************************/
     48 
     49 #include "osApi.h"
     50 
     51 #include "paramOut.h"
     52 #include "paramIn.h"
     53 
     54 #include "utils.h"
     55 #include "fsm.h"
     56 #include "report.h"
     57 
     58 #include "DataCtrl_Api.h"
     59 #include "smeApi.h"
     60 
     61 #include "rsn.h"
     62 #include "rsnApi.h"
     63 #include "mainSecSm.h"
     64 #include "mainSecKeysOnly.h"
     65 
     66 #include "mainKeysSm.h"
     67 
     68 /* Constants */
     69 
     70 /* Enumerations */
     71 
     72 /* Typedefs */
     73 
     74 /* Structures */
     75 
     76 /* External data definitions */
     77 
     78 /* External functions definitions */
     79 
     80 /* Global variables */
     81 
     82 /* functions */
     83 TI_STATUS mainSecKeysOnly_getAuthState(mainSec_t *pMainSec, TIWLN_SECURITY_STATE *supp1XState);
     84 
     85 TI_STATUS mainSecKeysOnly_reportAuthFailure(mainSec_t *pMainSec, authStatus_e authStatus) ;
     86 TI_STATUS mainSecKeysOnly_setAuthIdentity(mainSec_t *pMainSec, authIdentity_t *authIdentity);
     87 /**
     88 *
     89 * rsn_mainSecSmKeysOnlyInit
     90 *
     91 * \b Description:
     92 *
     93 * Init main security state machine state machine
     94 *
     95 * \b ARGS:
     96 *
     97 *  none
     98 *
     99 * \b RETURNS:
    100 *
    101 *  OK on success, NOK otherwise.
    102 *
    103 * \sa
    104 */
    105 TI_STATUS mainSecKeysOnly_config(mainSec_t *pMainSec,
    106 						  rsn_paeConfig_t *pPaeConfig)
    107 {
    108 	TI_STATUS				status;
    109 	/** Main 802.1X State Machine matrix */
    110 	fsm_actionCell_t	mainSecKeysOnly_matrix[MAIN_SEC_KEYS_ONLY_NUM_STATES][MAIN_SEC_KEYS_ONLY_NUM_EVENTS] =
    111 	{
    112 		/* next state and actions for IDLE state */
    113 		{{MAIN_KO_STATE_START, (fsm_Action_t)mainSecKeysOnly_startIdle},
    114 		 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_Nop},
    115 		 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_unexpected},
    116 		 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_unexpected}
    117 		},
    118 		/* next state and actions for START state */
    119 		{{MAIN_KO_STATE_START, (fsm_Action_t)mainSecKeysOnly_Nop},
    120 		 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_stopStart},
    121 		 {MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_keysCompleteStart},
    122 		 {MAIN_KO_STATE_NONAUTHORIZED, (fsm_Action_t)mainSecKeysOnly_keysTOStart},
    123 		},
    124 		/* next state and actions for AUTHORIZED state */
    125 		{{MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
    126 		 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_stopAuthorized},
    127 		 {MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_Nop},
    128 		 {MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
    129 		},
    130 		/* next state and actions for NONAUTORIZED state */
    131 		{{MAIN_KO_STATE_START, (fsm_Action_t)mainSecKeysOnly_unexpected},
    132 		 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_stopNonAuthorized},
    133 		 {MAIN_KO_STATE_NONAUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
    134 		 {MAIN_KO_STATE_NONAUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
    135 		}
    136 	};
    137 
    138     status = fsm_Config(pMainSec->pMainSecSm, &mainSecKeysOnly_matrix[0][0],
    139 						MAIN_SEC_KEYS_ONLY_NUM_STATES, MAIN_SEC_KEYS_ONLY_NUM_EVENTS, NULL, pMainSec->hOs);
    140 	if (status != OK)
    141 	{
    142 		WLAN_REPORT_ERROR(pMainSec->hReport, RSN_MODULE_LOG,
    143 							("MAIN_SEC_SM: Error in configuring full SM\n"));
    144 		return status;
    145 	}
    146 
    147     pMainSec->currentState          = MAIN_KO_STATE_IDLE;
    148 	pMainSec->start 				= mainSecKeysOnly_start;
    149 	pMainSec->stop 					= mainSecKeysOnly_stop;
    150 	pMainSec->reportKeysStatus 		= mainSecKeysOnly_reportKeysStatus;
    151 	pMainSec->getAuthState 			= (mainSecSm_getAuthState_t)mainSecKeysOnly_getAuthState;
    152 	pMainSec->reportReAuthenticate 	= (mainSecSmReportReauthentication_t)mainSecKeysOnly_unexpected;
    153 	pMainSec->setSessionKey 		= (mainSecSmSetSessionKey_t)mainSecKeysOnly_unexpected;
    154 	pMainSec->getSessionKey 		= (mainSecSmGetSessionKey_t)mainSecKeysOnly_unexpected;
    155 	pMainSec->reportAuthStatus 		= (mainSecSmReportAuthStatus_t)mainSecKeysOnly_unexpected;
    156 	pMainSec->getAuthIdentity  		= (mainSecSm_getAuthIdentity_t)mainSecKeysOnly_unexpected;
    157 	pMainSec->setAuthIdentity  		= (mainSecSm_getAuthIdentity_t)mainSecKeysOnly_setAuthIdentity;
    158     pMainSec->reportAuthFailure     = (mainSecSm_reportAuthFailure_t)mainSecKeysOnly_reportAuthFailure;
    159 
    160     WLAN_REPORT_INFORMATION(pMainSec->hReport, RSN_MODULE_LOG,
    161                     ("mainSecKeysOnly_config\n"));
    162 
    163     return OK;
    164 }
    165 
    166 /**
    167 *
    168 * mainSecSmNull_Start
    169 *
    170 * \b Description:
    171 *
    172 * Start the NULL main security SM. Reports success to the rsn module immediately.
    173 *
    174 * \b ARGS:
    175 *
    176 *  none
    177 *
    178 * \b RETURNS:
    179 *
    180 *  OK on success, NOK otherwise.
    181 *
    182 * \sa
    183 */
    184 TI_STATUS mainSecKeysOnly_start(mainSec_t *pMainSec)
    185 {
    186     TI_STATUS status;
    187 
    188     status = fsm_Event(pMainSec->pMainSecSm, &pMainSec->currentState, MAIN_KO_EVENT_START, pMainSec);
    189 
    190     return status;
    191 }
    192 
    193 /**
    194 *
    195 * mainSecSmNull_Stop
    196 *
    197 * \b Description:
    198 *
    199 * Start the NULL main security SM. Reports success to the rsn module immediately.
    200 *
    201 * \b ARGS:
    202 *
    203 *  none
    204 *
    205 * \b RETURNS:
    206 *
    207 *  OK on success, NOK otherwise.
    208 *
    209 * \sa
    210 */
    211 TI_STATUS mainSecKeysOnly_stop(mainSec_t *pMainSec)
    212 {
    213     TI_STATUS status;
    214 
    215     status = fsm_Event(pMainSec->pMainSecSm, &pMainSec->currentState, MAIN_KO_EVENT_STOP, pMainSec);
    216 
    217     return status;
    218 }
    219 
    220 /**
    221 *
    222 * mainSecSmNull_Stop
    223 *
    224 * \b Description:
    225 *
    226 * Start the NULL main security SM. Reports success to the rsn module immediately.
    227 *
    228 * \b ARGS:
    229 *
    230 *  none
    231 *
    232 * \b RETURNS:
    233 *
    234 *  OK on success, NOK otherwise.
    235 *
    236 * \sa
    237 */
    238 TI_STATUS mainSecKeysOnly_reportKeysStatus(mainSec_t *pMainSec, TI_STATUS keysStatus)
    239 {
    240 	TI_STATUS status;
    241 
    242 	pMainSec->data.status = keysStatus;
    243 
    244 	if (keysStatus == OK)
    245 	{
    246 		status = fsm_Event(pMainSec->pMainSecSm, &pMainSec->currentState, MAIN_KO_EVENT_KEYS_COMPLETE, pMainSec);
    247 	} else {
    248 		WLAN_REPORT_ERROR(pMainSec->hReport, RSN_MODULE_LOG,
    249 							("MAIN_SEC_SM: Error in Keys\n"));
    250 		status  = OK;
    251 	}
    252 
    253 	return status;
    254 }
    255 
    256 /**
    257 *
    258 * mainSecSmNull_setKey
    259 *
    260 * \b Description:
    261 *
    262 * Start the NULL main security SM. Reports success to the rsn module immediately.
    263 *
    264 * \b ARGS:
    265 *
    266 *  none
    267 *
    268 * \b RETURNS:
    269 *
    270 *  OK on success, NOK otherwise.
    271 *
    272 * \sa
    273 */
    274 TI_STATUS mainSecKeysOnly_setSessionKey(mainSec_t *pMainSec, UINT8* pKey, UINT8 keyLen)
    275 {
    276 	os_memoryCopy(pMainSec->hOs, pMainSec->sessionKey, pKey, keyLen);
    277 	pMainSec->sessionKeyLen = keyLen;
    278 
    279 	return OK;
    280 }
    281 
    282 /**
    283 *
    284 * mainSecSmNull_setKey
    285 *
    286 * \b Description:
    287 *
    288 * Start the NULL main security SM. Reports success to the rsn module immediately.
    289 *
    290 * \b ARGS:
    291 *
    292 *  none
    293 *
    294 * \b RETURNS:
    295 *
    296 *  OK on success, NOK otherwise.
    297 *
    298 * \sa
    299 */
    300 TI_STATUS mainSecKeysOnly_getSessionKey(mainSec_t *pMainSec, UINT8* pKey, UINT32* pKeyLen)
    301 {
    302 	os_memoryCopy(pMainSec->hOs, pKey, pMainSec->sessionKey, pMainSec->sessionKeyLen);
    303 	*pKeyLen = pMainSec->sessionKeyLen;
    304 
    305 	return OK;
    306 }
    307 
    308 
    309 
    310 /* State machine implementation functions */
    311 
    312 TI_STATUS mainSecKeysOnly_startIdle(struct _mainSec_t *pMainSec)
    313 {
    314     TI_STATUS		status = OK;
    315 
    316 	WLAN_REPORT_SM(pMainSec->hReport, RSN_MODULE_LOG,
    317 							  ("MAIN_SEC_SM: mainSecKeysOnly_StartIdle...\n"));
    318 	status =  pMainSec->pMainKeys->start(pMainSec->pMainKeys);
    319 
    320 	return status;
    321 }
    322 
    323 TI_STATUS mainSecKeysOnly_stopStart(struct _mainSec_t *pMainSec)
    324 {
    325     TI_STATUS		status = OK;
    326 
    327 	WLAN_REPORT_SM(pMainSec->hReport, RSN_MODULE_LOG,
    328 							  ("MAIN_SEC_SM: mainSecKeysOnly_StopStart...\n"));
    329 	status =  pMainSec->pMainKeys->stop(pMainSec->pMainKeys);
    330 
    331 	return status;
    332 }
    333 
    334 TI_STATUS mainSecKeysOnly_keysCompleteStart(struct _mainSec_t *pMainSec)
    335 {
    336     TI_STATUS		status = OK;
    337 
    338 	WLAN_REPORT_SM(pMainSec->hReport, RSN_MODULE_LOG,
    339 							  ("MAIN_SEC_SM: mainSecKeysOnly_KeysCompleteAuthenticated...\n"));
    340 	status =  pMainSec->pParent->reportStatus(pMainSec->pParent, pMainSec->data.status);
    341 
    342 	return(status);
    343 }
    344 
    345 TI_STATUS mainSecKeysOnly_keysTOStart(struct _mainSec_t *pMainSec)
    346 {
    347     TI_STATUS		status = OK;
    348 
    349 	return(status);
    350 }
    351 
    352 TI_STATUS mainSecKeysOnly_stopAuthorized(struct _mainSec_t *pMainSec)
    353 {
    354     TI_STATUS		status = OK;
    355 
    356 	WLAN_REPORT_SM(pMainSec->hReport, RSN_MODULE_LOG,
    357 							  ("MAIN_SEC_SM: mainSecKeysOnly_StopAuthorized...\n"));
    358 	status =  pMainSec->pMainKeys->stop(pMainSec->pMainKeys);
    359 
    360 	return(status);
    361 }
    362 
    363 TI_STATUS mainSecKeysOnly_stopNonAuthorized(struct _mainSec_t *pMainSec)
    364 {
    365     TI_STATUS		status = OK;
    366 
    367 	WLAN_REPORT_SM(pMainSec->hReport, RSN_MODULE_LOG,
    368 							  ("MAIN_SEC_SM: mainSecKeysOnly_StopNonAuthorized...\n"));
    369 	status =  pMainSec->pMainKeys->stop(pMainSec->pMainKeys);
    370 
    371 	return(status);
    372 }
    373 
    374 /* state machine action functions */
    375 
    376 TI_STATUS mainSecKeysOnly_Nop(void* pData)
    377 {
    378 	return(OK);
    379 }
    380 
    381 TI_STATUS mainSecKeysOnly_unexpected(void* pData)
    382 {
    383 	return NOK;
    384 }
    385 
    386  /**
    387 *
    388 * mainSecKeysOnly_getAuthState:  \n
    389 *
    390 * \b Description:
    391 *
    392 * Get authentication state from supp1x SM.
    393 *
    394 * \b ARGS:
    395 *
    396 *  I   - pMainSec - pMainSec SM context  \n
    397 *  I   - authIdentity - pointer to authentication state \n
    398 *
    399 * \b RETURNS:
    400 *
    401 *  OK if successful, NOK otherwise.
    402 *
    403 * \sa
    404 */
    405 
    406 TI_STATUS mainSecKeysOnly_getAuthState(mainSec_t *pMainSec, TIWLN_SECURITY_STATE *secState)
    407 {
    408 	switch (pMainSec->currentState)
    409 	{
    410 	case MAIN_KO_STATE_START:
    411 		*secState = eSecurityStateAuthenticating;
    412 		break;
    413 
    414 	case MAIN_KO_STATE_AUTHORIZED:
    415 		*secState = eSecurityStateAuthenticated;
    416 		break;
    417 
    418 	case MAIN_KO_STATE_NONAUTHORIZED:
    419 		*secState = eSecurityStateNotAuthenticated ;
    420 		break;
    421 
    422 	default:
    423 		*secState = eSecurityStateHalted;
    424 		break;
    425 	}
    426 
    427 	return OK;
    428 
    429 } /*mainSecKeysOnly_getAuthState*/
    430 
    431 
    432 TI_STATUS mainSecKeysOnly_reportAuthFailure(mainSec_t *pMainSec, authStatus_e authStatus)
    433 {
    434 
    435     return OK;
    436 }
    437 
    438 
    439 TI_STATUS mainSecKeysOnly_setAuthIdentity(mainSec_t *pMainSec, authIdentity_t *authIdentity)
    440 {
    441 
    442 	return OK;
    443 }
    444