Home | History | Annotate | Download | only in open
      1 /** \file authSM.c
      2  *  \brief 802.11 authentication SM source
      3  *
      4  *  \see authSM.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:	authSM.c												   */
     45 /*    PURPOSE:	802.11 authentication SM source							   */
     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 #include "mlmeApi.h"
     58 #include "../authSm.h"
     59 #include "openAuthSm.h"
     60 #include "rsnApi.h"
     61 
     62 /* Constants */
     63 
     64 /** number of states in the state machine */
     65 #define	OPEN_AUTH_SM_NUM_STATES		3
     66 
     67 /** number of events in the state machine */
     68 #define	OPEN_AUTH_SM_NUM_EVENTS		6
     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 /* Local function prototypes */
     83 
     84 /* functions */
     85 
     86 /**
     87 *
     88 * openAuth_smConfig - configure a new authentication SM
     89 *
     90 * \b Description:
     91 *
     92 * Configure a new authentication SM.
     93 *
     94 * \b ARGS:
     95 *
     96 *  I   - hAuth - Association SM context  \n
     97 *  I   - hMlme - MLME SM context  \n
     98 *  I   - hSiteMgr - Site manager context  \n
     99 *  I   - hCtrlData - Control data context  \n
    100 *  I   - hTxData - TX data context  \n
    101 *  I   - hHalCtrl - Hal control context  \n
    102 *  I   - hReport - Report context  \n
    103 *  I   - hOs - OS context  \n
    104 *  I   - authTimeout - Association SM timeout \n
    105 *  I   - authMaxCount - Max number of authentication requests to send  \n
    106 *
    107 * \b RETURNS:
    108 *
    109 *  OK if successful, NOK otherwise.
    110 *
    111 * \sa openAuth_Create, openAuth_Unload
    112 */
    113 TI_STATUS openAuth_Config(TI_HANDLE hAuth, TI_HANDLE hOs)
    114 {
    115 	auth_t		*pHandle;
    116 	TI_STATUS		status;
    117 	/** Main 802.1X State Machine matrix */
    118 	fsm_actionCell_t	openAuth_smMatrix[OPEN_AUTH_SM_NUM_STATES][OPEN_AUTH_SM_NUM_EVENTS] =
    119 	{
    120 		/* next state and actions for IDLE state */
    121 		{{OPEN_AUTH_SM_STATE_WAIT, (fsm_Action_t)openAuth_smStartIdle},
    122 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smActionUnexpected},
    123 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smActionUnexpected},
    124 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smActionUnexpected},
    125 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smActionUnexpected},
    126 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smActionUnexpected}
    127 		},
    128 		/* next state and actions for WAIT state */
    129 		{{OPEN_AUTH_SM_STATE_WAIT, (fsm_Action_t)openAuth_smActionUnexpected},
    130 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smStopWait},
    131 		 {OPEN_AUTH_SM_STATE_AUTH, (fsm_Action_t)openAuth_smSuccessWait},
    132 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smFailureWait},
    133 		 {OPEN_AUTH_SM_STATE_WAIT, (fsm_Action_t)openAuth_smTimeoutWait},
    134 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smMaxRetryWait}
    135 		},
    136 		/* next state and actions for AUTH state */
    137 		{{OPEN_AUTH_SM_STATE_AUTH, (fsm_Action_t)openAuth_smActionUnexpected},
    138 		 {OPEN_AUTH_SM_STATE_IDLE, (fsm_Action_t)openAuth_smStopAuth},
    139 		 {OPEN_AUTH_SM_STATE_AUTH, (fsm_Action_t)openAuth_smActionUnexpected},
    140 		 {OPEN_AUTH_SM_STATE_AUTH, (fsm_Action_t)openAuth_smActionUnexpected},
    141 		 {OPEN_AUTH_SM_STATE_AUTH, (fsm_Action_t)openAuth_smActionUnexpected},
    142 		 {OPEN_AUTH_SM_STATE_AUTH, (fsm_Action_t)openAuth_smActionUnexpected}
    143 		}};
    144 
    145 
    146 	if (hAuth == NULL)
    147 	{
    148 		return NOK;
    149 	}
    150 
    151 	pHandle = (auth_t*)hAuth;
    152 
    153 	status = fsm_Config(pHandle->pAuthSm, &openAuth_smMatrix[0][0],
    154 						OPEN_AUTH_SM_NUM_STATES, OPEN_AUTH_SM_NUM_EVENTS, auth_osSMEvent, hOs);
    155 	if (status != OK)
    156 	{
    157 		return NOK;
    158 	}
    159 
    160 	pHandle->currentState = OPEN_AUTH_SM_STATE_IDLE;
    161 
    162 	return OK;
    163 }
    164 
    165 
    166 #ifdef REPORT_LOG
    167 
    168 static char *stateDesc[OPEN_AUTH_SM_NUM_STATES] =
    169 	{
    170 		"OPEN_AUTH_SM_STATE_IDLE",
    171 		"OPEN_AUTH_SM_STATE_WAIT",
    172 		"OPEN_AUTH_SM_STATE_AUTH",
    173 	};
    174 
    175 static char *eventDesc[OPEN_AUTH_SM_NUM_EVENTS] =
    176 	{
    177 		"OPEN_AUTH_SM_EVENT_START",
    178 		"OPEN_AUTH_SM_EVENT_STOP",
    179 		"OPEN_AUTH_SM_EVENT_SUCCESS",
    180 		"OPEN_AUTH_SM_EVENT_FAIL",
    181 		"OPEN_AUTH_SM_EVENT_TIMEOUT",
    182 		"OPEN_AUTH_SM_EVENT_MAX_RETRY",
    183 	};
    184 
    185 #endif
    186 
    187 
    188 TI_STATUS auth_osSMEvent(UINT8 *currentState, UINT8 event, TI_HANDLE hAuth)
    189 {
    190    auth_t *pAuth = (auth_t *)hAuth;
    191 	TI_STATUS 		status;
    192 	UINT8		nextState;
    193 
    194 	status = fsm_GetNextState(pAuth->pAuthSm, *currentState, event, &nextState);
    195 	if (status != OK)
    196 	{
    197 		WLAN_REPORT_SM(pAuth->hReport, AUTH_MODULE_LOG, ("State machine error, failed getting next state\n"));
    198 		return(NOK);
    199 	}
    200 
    201 	WLAN_REPORT_SM(pAuth->hReport, AUTH_MODULE_LOG,
    202 							  ("<%s, %s> --> %s\n\n",
    203 							   stateDesc[*currentState],
    204 							   eventDesc[event],
    205 							   stateDesc[nextState]));
    206 
    207 	status = fsm_Event(pAuth->pAuthSm, currentState, event, (void *)pAuth);
    208 
    209 	return status;
    210 }
    211 
    212 /**
    213 *
    214 * openAuth_Recv - Recive a message from the AP
    215 *
    216 * \b Description:
    217 *
    218 * Parse a message form the AP and perform the appropriate event.
    219 *
    220 * \b ARGS:
    221 *
    222 *  I   - hAuth - Association SM context  \n
    223 *
    224 * \b RETURNS:
    225 *
    226 *  OK if successful, NOK otherwise.
    227 *
    228 * \sa openAuth_Start, openAuth_Stop
    229 */
    230 TI_STATUS openAuth_Recv(TI_HANDLE hAuth, mlmeFrameInfo_t *pFrame)
    231 {
    232 	TI_STATUS 			status;
    233 	auth_t			*pHandle;
    234 	UINT16			authAlgo;
    235 
    236 	pHandle = (auth_t*)hAuth;
    237 
    238 	if (pHandle == NULL)
    239 	{
    240 		return NOK;
    241 	}
    242 
    243 	/* check response status */
    244 	authAlgo = pFrame->content.auth.authAlgo;
    245 	if ((authAlgo != AUTH_LEGACY_OPEN_SYSTEM) &&
    246         (authAlgo != AUTH_LEGACY_RESERVED1))
    247 	{
    248 		WLAN_REPORT_SM(pHandle->hReport, AUTH_MODULE_LOG,
    249 				  ("OPEN_AUTH_SM: DEBUG recieved authentication message with wrong algorithm \n"));
    250         rsn_reportAuthFailure(pHandle->hRsn, RSN_AUTH_STATUS_INVALID_TYPE);
    251         return NOK;
    252 	}
    253 
    254     if ((pHandle->authType==AUTH_LEGACY_RESERVED1) && (authAlgo !=AUTH_LEGACY_RESERVED1))
    255     {
    256         rsn_reportAuthFailure(pHandle->hRsn, RSN_AUTH_STATUS_INVALID_TYPE);
    257     }
    258     WLAN_REPORT_SM(pHandle->hReport, AUTH_MODULE_LOG,
    259               ("OPEN_AUTH_SM: DEBUG Authentication status is %d \n", pFrame->content.auth.status));
    260 
    261 	pHandle->authData.status = pFrame->content.auth.status;
    262 
    263     if (pHandle->authData.status == STATUS_SUCCESSFUL)
    264     {
    265         status = auth_osSMEvent(&pHandle->currentState, OPEN_AUTH_SM_EVENT_SUCCESS, pHandle);
    266     } else {
    267 		rsn_reportAuthFailure(pHandle->hRsn, RSN_AUTH_STATUS_INVALID_TYPE);
    268 		status = auth_osSMEvent(&pHandle->currentState, OPEN_AUTH_SM_EVENT_FAIL, pHandle);
    269     }
    270 
    271 	return status;
    272 }
    273 
    274 /* state machine functions */
    275 
    276 TI_STATUS openAuth_smStartIdle(auth_t *hAuth)
    277 {
    278 	TI_STATUS		status;
    279 
    280 	status = openAuth_smResetRetry(hAuth);
    281 	status = openAuth_smSendAuthReq(hAuth);
    282 	status = openAuth_smStartTimer(hAuth);
    283 	status = openAuth_smIncRetry(hAuth);
    284 
    285 	return status;
    286 }
    287 
    288 TI_STATUS openAuth_smStopWait(auth_t *hAuth)
    289 {
    290 	TI_STATUS		status;
    291 
    292 	status = openAuth_smStopTimer(hAuth);
    293 
    294 	return status;
    295 }
    296 
    297 TI_STATUS openAuth_smSuccessWait(auth_t *hAuth)
    298 {
    299 	TI_STATUS		status;
    300 
    301 	status = openAuth_smStopTimer(hAuth);
    302 	status = openAuth_smReportSuccess(hAuth);
    303 
    304 	return status;
    305 }
    306 
    307 TI_STATUS openAuth_smFailureWait(auth_t *hAuth)
    308 {
    309 	TI_STATUS		status;
    310 
    311 	status = openAuth_smStopTimer(hAuth);
    312 	status = openAuth_smReportFailure(hAuth);
    313 
    314 	return status;
    315 }
    316 
    317 TI_STATUS openAuth_smTimeoutWait(auth_t *hAuth)
    318 {
    319 	TI_STATUS		status;
    320 
    321 	status = openAuth_smSendAuthReq(hAuth);
    322 	status = openAuth_smStartTimer(hAuth);
    323 	status = openAuth_smIncRetry(hAuth);
    324 
    325 	return status;
    326 }
    327 
    328 TI_STATUS openAuth_smMaxRetryWait(auth_t *hAuth)
    329 {
    330 	TI_STATUS		status;
    331 
    332     rsn_reportAuthFailure(hAuth->hRsn, RSN_AUTH_STATUS_TIMEOUT);
    333 	status = openAuth_smReportFailure(hAuth);
    334 
    335 	return status;
    336 }
    337 
    338 TI_STATUS openAuth_smSendAuthReq(auth_t *hAuth)
    339 {
    340 	TI_STATUS		status;
    341 
    342 	status = auth_smMsgBuild(hAuth, 1, 0, NULL, 0);
    343 
    344 	return status;
    345 }
    346 
    347 TI_STATUS openAuth_smStopAuth(auth_t *hAuth)
    348 {
    349 	return OK;
    350 }
    351 
    352 TI_STATUS openAuth_smActionUnexpected(auth_t *hAuth)
    353 {
    354 	return OK;
    355 }
    356 
    357 /* local functions */
    358 
    359 
    360 TI_STATUS openAuth_smResetRetry(auth_t *hAuth)
    361 {
    362 	if (hAuth == NULL)
    363 	{
    364 		return NOK;
    365 	}
    366 
    367 	hAuth->retryCount = 0;
    368 
    369 	return OK;
    370 }
    371 
    372 TI_STATUS openAuth_smIncRetry(auth_t *hAuth)
    373 {
    374 	if (hAuth == NULL)
    375 	{
    376 		return NOK;
    377 	}
    378 
    379 	hAuth->retryCount++;
    380 
    381 	return OK;
    382 }
    383 
    384 TI_STATUS openAuth_smReportSuccess(auth_t *hAuth)
    385 {
    386 	TI_STATUS 		status;
    387 
    388 	if (hAuth == NULL)
    389 	{
    390 		return NOK;
    391 	}
    392     status = mlme_reportAuthStatus(hAuth->hMlme, hAuth->authData.status);
    393 
    394 	return status;
    395 }
    396 
    397 TI_STATUS openAuth_smReportFailure(auth_t *hAuth)
    398 {
    399 	TI_STATUS 		status;
    400 
    401 	if (hAuth == NULL)
    402 	{
    403 		return NOK;
    404 	}
    405 
    406 
    407     status = mlme_reportAuthStatus(hAuth->hMlme, hAuth->authData.status);
    408 
    409 	return status;
    410 }
    411 
    412 TI_STATUS openAuth_smStartTimer(auth_t *hAuth)
    413 {
    414 	if (hAuth == NULL)
    415 	{
    416 		return NOK;
    417 	}
    418 
    419 	os_timerStart(hAuth->hOs, hAuth->timer, hAuth->timeout, FALSE);
    420 
    421 	return OK;
    422 }
    423 
    424 TI_STATUS openAuth_smStopTimer(auth_t *hAuth)
    425 {
    426 	if (hAuth == NULL)
    427 	{
    428 		return NOK;
    429 	}
    430 
    431 	os_timerStop(hAuth->hOs, hAuth->timer);
    432 
    433 	return OK;
    434 }
    435 
    436 TI_STATUS openAuth_Timeout(auth_t *pAuth)
    437 {
    438 	if (pAuth->retryCount >= pAuth->maxCount)
    439 	{
    440 		pAuth->authData.status = STATUS_PACKET_REJ_TIMEOUT;
    441 		return auth_osSMEvent(&pAuth->currentState, OPEN_AUTH_SM_EVENT_MAX_RETRY, pAuth);
    442 	}
    443 
    444 	return auth_osSMEvent(&pAuth->currentState, OPEN_AUTH_SM_EVENT_TIMEOUT, pAuth);
    445 }
    446 
    447 
    448