Home | History | Annotate | Download | only in mlme
      1 /** \file mlmeSM.c
      2  *  \brief 802.11 MLME SM source
      3  *
      4  *  \see mlmeSM.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:	mlmeSM.c												   */
     45 /*    PURPOSE:	802.11 MLME 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 "smeApi.h"
     58 #include "Assoc/AssocSM.h"
     59 #include "Auth/authSm.h"
     60 #include "mlmeBuilder.h"
     61 #include "mlmeSm.h"
     62 #include "Auth/open/openAuthSm.h"
     63 #include "Auth/shared/sharedKeyAuthSm.h"
     64 #include "whalCtrl_api.h"
     65 #include "connApi.h"
     66 
     67 
     68 #ifdef TI_DBG
     69 #include "siteMgrApi.h"
     70 #endif
     71 /* Constants */
     72 
     73 /* Enumerations */
     74 
     75 /* Typedefs */
     76 
     77 /* Structures */
     78 
     79 /* External data definitions */
     80 
     81 /* External functions definitions */
     82 
     83 /* Global variables */
     84 
     85 /* Local function prototypes */
     86 #ifdef NO_HAL_VOB
     87 static void mlme_logBeaconReceived(TI_HANDLE hMlme);
     88 #endif
     89 
     90 void mlme_stopAssocAndAuth(mlme_t *pMlme);
     91 
     92 /* functions */
     93 
     94 /**
     95 *
     96 * mlme_Create - allocate memory for MLME SM
     97 *
     98 * \b Description:
     99 *
    100 * Allocate memory for MLME SM. \n
    101 * 		Allocates memory for MLME context. \n
    102 * 		Allocates memory for MLME timer. \n
    103 * 		Allocates memory for MLME SM matrix. \n
    104 *
    105 * \b ARGS:
    106 *
    107 *  I   - pOs - OS context  \n
    108 *
    109 * \b RETURNS:
    110 *
    111 *  OK if successful, NOK otherwise.
    112 *
    113 * \sa rsn_mainSecSmKeysOnlyStop()
    114 */
    115 TI_HANDLE mlme_create(TI_HANDLE hOs)
    116 {
    117 	mlme_t 	*pHandle;
    118 	TI_STATUS		status;
    119 
    120 	/* allocate MLME context memory */
    121 	pHandle = (mlme_t*)os_memoryAlloc(hOs, sizeof(mlme_t));
    122 	if (pHandle == NULL)
    123 	{
    124 		return NULL;
    125 	}
    126 
    127 	/* zero all MLME context */
    128 	os_memoryZero(hOs, pHandle, sizeof(mlme_t));
    129 
    130 	pHandle->hOs = hOs;
    131 
    132 	/* allocate memory for MLME state machine */
    133 	status = fsm_Create(hOs, &pHandle->pMlmeSm, MLME_SM_NUM_STATES, MLME_SM_NUM_EVENTS);
    134 	if (status != OK)
    135 	{
    136 		os_memoryFree(hOs, pHandle, sizeof(mlme_t));
    137 		return NULL;
    138 	}
    139 
    140 	return pHandle;
    141 }
    142 
    143 
    144 /**
    145 *
    146 * mlme_Unload - unload MLME SM from memory
    147 *
    148 * \b Description:
    149 *
    150 * Unload MLME SM from memory
    151 *
    152 * \b ARGS:
    153 *
    154 *  I   - hMlme - MLME SM context  \n
    155 *
    156 * \b RETURNS:
    157 *
    158 *  OK if successful, NOK otherwise.
    159 *
    160 * \sa rsn_mainSecSmKeysOnlyStop()
    161 */
    162 TI_STATUS mlme_unload(TI_HANDLE hMlme)
    163 {
    164     TI_STATUS 		status;
    165 	mlme_t		*pHandle;
    166 
    167 	pHandle = (mlme_t*)hMlme;
    168 
    169 	status = fsm_Unload(pHandle->hOs, pHandle->pMlmeSm);
    170     if (status != OK)
    171 	{
    172 		/* report failure but don't stop... */
    173 	}
    174 
    175 	os_memoryFree(pHandle->hOs, hMlme, sizeof(mlme_t));
    176 
    177 	return OK;
    178 }
    179 
    180 /**
    181 *
    182 * mlme_smConfig - configure a new MLME SM
    183 *
    184 * \b Description:
    185 *
    186 * Configure a new MLME SM.
    187 *
    188 * \b ARGS:
    189 *
    190 *  I   - hMlme - MLME SM context  \n
    191 *  I   - pMlme - MLME SM context  \n
    192 *  I   - pSiteMgr - Site manager context  \n
    193 *  I   - pCtrlData - Control data context  \n
    194 *  I   - pTxData - TX data context  \n
    195 *  I   - pHalCtrl - Hal control context  \n
    196 *  I   - pReport - Report context  \n
    197 *  I   - pOs - OS context  \n
    198 *  I   - mlmeTimeout - MLME SM timeout \n
    199 *  I   - mlmeMaxCount - Max number of MLME requests to send  \n
    200 *
    201 * \b RETURNS:
    202 *
    203 *  OK if successful, NOK otherwise.
    204 *
    205 * \sa mlme_Create, mlme_Unload
    206 */
    207 TI_STATUS mlme_config(TI_HANDLE hMlme,
    208 				   TI_HANDLE hAuth,
    209 				   TI_HANDLE hAssoc,
    210 				   TI_HANDLE hSiteMgr,
    211 				   TI_HANDLE hCtrlData,
    212 				   TI_HANDLE hConn,
    213 				   TI_HANDLE hTxData,
    214 				   TI_HANDLE hHalCtrl,
    215 				   TI_HANDLE hMemMgr,
    216 				   TI_HANDLE hMeasurementMgr,
    217 				   TI_HANDLE hSwitchChannel,
    218 				   TI_HANDLE hRegulatoryDomain,
    219 				   TI_HANDLE hReport,
    220 				   TI_HANDLE hOs,
    221 				   TI_HANDLE hCurrBss,
    222 				   TI_HANDLE hAPConn,
    223 				   TI_HANDLE hScanCncn,
    224 				   TI_HANDLE hQosMngr,
    225                    TI_HANDLE hConfigMgr)
    226 {
    227 	mlme_t		*pHandle;
    228 	TI_STATUS		status;
    229 	/** Main 802.1X State Machine matrix */
    230 	fsm_actionCell_t	mlme_smMatrix[MLME_SM_NUM_STATES][MLME_SM_NUM_EVENTS] =
    231 	{
    232 		/* next state and actions for IDLE state */
    233 		{{MLME_SM_STATE_AUTH_WAIT, (fsm_Action_t)mlme_smStartIdle},         	/* MLME_SM_EVENT_START */
    234 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smNOP},	                 /* MLME_SM_EVENT_STOP  */
    235 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smActionUnexpected},		/* MLME_SM_EVENT_AUTH_SUCCESS */
    236 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smActionUnexpected},		/* MLME_SM_EVENT_AUTH_FAIL */
    237 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smActionUnexpected},		/* MLME_SM_EVENT_ASSOC_SUCCESS */
    238 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smActionUnexpected}		/* MLME_SM_EVENT_ASSOC_FAIL */
    239 		},
    240 		/* next state and actions for AUTH_WAIT state */
    241 		{{MLME_SM_STATE_AUTH_WAIT, (fsm_Action_t)mlme_smActionUnexpected},  	/* MLME_SM_EVENT_START */
    242 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smNOP},			 		   /* MLME_SM_EVENT_STOP  */
    243 		 {MLME_SM_STATE_ASSOC_WAIT, (fsm_Action_t)mlme_smAuthSuccessAuthWait}, 	/* MLME_SM_EVENT_AUTH_SUCCESS */
    244 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smAuthFailAuthWait},			/* MLME_SM_EVENT_AUTH_FAIL */
    245 		 {MLME_SM_STATE_AUTH_WAIT, (fsm_Action_t)mlme_smActionUnexpected},		/* MLME_SM_EVENT_ASSOC_SUCCESS */
    246 		 {MLME_SM_STATE_AUTH_WAIT, (fsm_Action_t)mlme_smActionUnexpected}		/* MLME_SM_EVENT_ASSOC_FAIL */
    247 		},
    248 		/* next state and actions for ASSOC_WAIT state */
    249 		{{MLME_SM_STATE_ASSOC_WAIT, (fsm_Action_t)mlme_smActionUnexpected}, /* MLME_SM_EVENT_START */
    250 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smStopAssocWait},			/* MLME_SM_EVENT_STOP  */
    251 		 {MLME_SM_STATE_ASSOC_WAIT, (fsm_Action_t)mlme_smActionUnexpected},	/* MLME_SM_EVENT_AUTH_SUCCESS */
    252 		 {MLME_SM_STATE_ASSOC_WAIT, (fsm_Action_t)mlme_smActionUnexpected},	/* MLME_SM_EVENT_AUTH_FAIL */
    253 		 {MLME_SM_STATE_ASSOC, (fsm_Action_t)mlme_smAssocSuccessAssocWait},	/* MLME_SM_EVENT_ASSOC_SUCCESS */
    254 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smAssocFailAssocWait}		/* MLME_SM_EVENT_ASSOC_FAIL */
    255 		},
    256 		/* next state and actions for ASSOC state */
    257 		{{MLME_SM_STATE_ASSOC, (fsm_Action_t)mlme_smActionUnexpected}, 	/* MLME_SM_EVENT_START */
    258 		 {MLME_SM_STATE_IDLE, (fsm_Action_t)mlme_smStopAssoc},			/* MLME_SM_EVENT_STOP  */
    259 		 {MLME_SM_STATE_ASSOC, (fsm_Action_t)mlme_smActionUnexpected},	/* MLME_SM_EVENT_AUTH_SUCCESS */
    260 		 {MLME_SM_STATE_ASSOC, (fsm_Action_t)mlme_smActionUnexpected},	/* MLME_SM_EVENT_AUTH_FAIL */
    261 		 {MLME_SM_STATE_ASSOC, (fsm_Action_t)mlme_smActionUnexpected},	/* MLME_SM_EVENT_ASSOC_SUCCESS */
    262 		 {MLME_SM_STATE_ASSOC, (fsm_Action_t)mlme_smActionUnexpected}	/* MLME_SM_EVENT_ASSOC_FAIL */
    263 		}
    264 	};
    265 
    266 
    267 	if (hMlme == NULL)
    268 	{
    269 		return NOK;
    270 	}
    271 
    272 	pHandle = (mlme_t*)hMlme;
    273 
    274 	status = fsm_Config(pHandle->pMlmeSm, &mlme_smMatrix[0][0], MLME_SM_NUM_STATES, MLME_SM_NUM_EVENTS, mlme_smEvent, hOs);
    275 	if (status != OK)
    276 	{
    277 		return NOK;
    278 	}
    279 
    280 	pHandle->currentState = MLME_SM_STATE_IDLE;
    281 	pHandle->legacyAuthType = AUTH_LEGACY_NONE;
    282 	pHandle->reAssoc = FALSE;
    283 	pHandle->disConnType = DISCONN_TYPE_IMMEDIATE;
    284 	pHandle->disConnReason = STATUS_UNSPECIFIED;
    285 
    286 	pHandle->hAssoc = hAssoc;
    287 	pHandle->hAuth = hAuth;
    288 	pHandle->hSiteMgr = hSiteMgr;
    289 	pHandle->hCtrlData = hCtrlData;
    290 	pHandle->hTxData = hTxData;
    291 	pHandle->hHalCtrl = hHalCtrl;
    292 	pHandle->hMemMgr = hMemMgr;
    293 	pHandle->hMeasurementMgr = hMeasurementMgr;
    294 	pHandle->hSwitchChannel = hSwitchChannel;
    295 	pHandle->hRegulatoryDomain = hRegulatoryDomain;
    296 	pHandle->hReport = hReport;
    297 	pHandle->hOs = hOs;
    298 	pHandle->hConn = hConn;
    299 	pHandle->hCurrBss = hCurrBss;
    300 	pHandle->hApConn = hAPConn;
    301 	pHandle->hScanCncn = hScanCncn;
    302     pHandle->hConfigMgr = hConfigMgr;
    303 
    304     /* nullify beacon and probe response registration information */
    305     pHandle->resultCBFunc = NULL;
    306     pHandle->resultCBObj = NULL;
    307 	pHandle->hQosMngr = hQosMngr;
    308     /*
    309     debug info
    310     */
    311     pHandle->debug_lastProbeRspTSFTime = 0;
    312     pHandle->debug_lastDtimBcnTSFTime = 0;
    313     pHandle->debug_lastBeaconTSFTime = 0;
    314     pHandle->debug_isFunctionFirstTime = TRUE;
    315 	pHandle->BeaconsCounterPS = 0;
    316 
    317 #ifdef NO_HAL_VOB
    318 	/* Register the Beacon interrrput that can be used for debug -
    319 		i.e. on each received beacon in the FW, the FW generated  a beacon interrupt. */
    320 
    321 	/*	there is no Beacon Receive in WSP7.1, in 4.1 its for Prints only hence will not
    322 		be supported at this time */
    323 	WLAN_OS_REPORT(("mlme_config : NO_HAL_VOB not supported"));
    324 #endif
    325 	return OK;
    326 }
    327 
    328 
    329 TI_STATUS mlme_setParam(TI_HANDLE			hMlmeSm,
    330 						paramInfo_t			*pParam)
    331 {
    332 	mlme_t *pMlmeSm = (mlme_t *)hMlmeSm;
    333 
    334 	switch(pParam->paramType)
    335 	{
    336 	case MLME_LEGACY_TYPE_PARAM:
    337 
    338 		switch (pParam->content.mlmeLegacyAuthType)
    339 		{
    340         case AUTH_LEGACY_RESERVED1:
    341 		case AUTH_LEGACY_OPEN_SYSTEM:
    342 			/* First configure the MLME with the new legacy authentication type */
    343 			pMlmeSm->legacyAuthType = pParam->content.mlmeLegacyAuthType;
    344 			/* Now configure the authentication module. */
    345 			pParam->paramType = AUTH_LEGACY_TYPE_PARAM;
    346 			return auth_setParam(pMlmeSm->hAuth, pParam);
    347 
    348 		case AUTH_LEGACY_SHARED_KEY:
    349 			/* First configure the MLME with the new legacy authentication type */
    350 			pMlmeSm->legacyAuthType = AUTH_LEGACY_SHARED_KEY;
    351 			/* Now configure the authentication module. */
    352 			pParam->paramType = AUTH_LEGACY_TYPE_PARAM;
    353 			return auth_setParam(pMlmeSm->hAuth, pParam);
    354 
    355 		case AUTH_LEGACY_AUTO_SWITCH:
    356 			/* First configure the MLME with the new legacy authentication type */
    357 			pMlmeSm->legacyAuthType = AUTH_LEGACY_AUTO_SWITCH;
    358 			/* Now configure the authentication module,
    359 				Auto switch mode means start always with shared key, if fail move to open system. */
    360 			pParam->paramType = AUTH_LEGACY_TYPE_PARAM;
    361 			pParam->content.authLegacyAuthType = AUTH_LEGACY_SHARED_KEY;
    362 			return auth_setParam(pMlmeSm->hAuth, pParam);
    363 
    364 		default:
    365 			WLAN_REPORT_ERROR(pMlmeSm->hReport, MLME_SM_MODULE_LOG, ("Set param, Params is not supported, 0x%x\n\n", pParam->content.mlmeLegacyAuthType));
    366 			return PARAM_VALUE_NOT_VALID;
    367 		}
    368 /*		break;  - unreachable */
    369 
    370 	case MLME_RE_ASSOC_PARAM:
    371 		pMlmeSm->reAssoc = pParam->content.mlmeReAssoc;
    372 		break;
    373 
    374 	default:
    375 		WLAN_REPORT_ERROR(pMlmeSm->hReport, MLME_SM_MODULE_LOG, ("Set param, Params is not supported, 0x%x\n\n", pParam->paramType));
    376 		return PARAM_NOT_SUPPORTED;
    377 	}
    378 
    379 	return OK;
    380 }
    381 
    382 TI_STATUS mlme_getParam(TI_HANDLE			hMlmeSm,
    383 						paramInfo_t			*pParam)
    384 {
    385 	mlme_t *pMlmeSm = (mlme_t *)hMlmeSm;
    386 
    387 	switch(pParam->paramType)
    388 	{
    389 	case MLME_LEGACY_TYPE_PARAM:
    390 		pParam->content.mlmeLegacyAuthType = pMlmeSm->legacyAuthType;
    391 		break;
    392 
    393 	case MLME_CAPABILITY_PARAM:
    394 		pParam->content.mlmeLegacyAuthType = pMlmeSm->legacyAuthType;
    395 		assoc_smCapBuild(pMlmeSm->hAssoc, &(pParam->content.siteMgrSiteCapability));
    396 		break;
    397 
    398     case MLME_BEACON_RECV:
    399         pParam->content.siteMgrTiWlanCounters.BeaconsRecv = pMlmeSm->BeaconsCounterPS;
    400         break;
    401 
    402 	default:
    403 		WLAN_REPORT_ERROR(pMlmeSm->hReport, MLME_SM_MODULE_LOG, ("Get param, Params is not supported, %d\n\n", pParam->content.mlmeLegacyAuthType));
    404 		return PARAM_NOT_SUPPORTED;
    405 	}
    406 
    407 	return OK;
    408 }
    409 
    410 /**
    411 *
    412 * mlme_Start - Start event for the MLME SM
    413 *
    414 * \b Description:
    415 *
    416 * Start event for the MLME SM
    417 *
    418 * \b ARGS:
    419 *
    420 *  I   - hMlme - MLME SM context  \n
    421 *
    422 * \b RETURNS:
    423 *
    424 *  OK if successful, NOK otherwise.
    425 *
    426 * \sa mlme_Stop, mlme_Recv
    427 */
    428 TI_STATUS mlme_start(TI_HANDLE hMlme)
    429 {
    430 	TI_STATUS 		status;
    431 	mlme_t		*pHandle;
    432 
    433 	pHandle = (mlme_t*)hMlme;
    434 
    435 	if (pHandle == NULL)
    436 		return NOK;
    437 
    438 	if (pHandle->legacyAuthType == AUTH_LEGACY_NONE)
    439 		return NOK;
    440 
    441 	status = mlme_smEvent(&pHandle->currentState, MLME_SM_EVENT_START, pHandle);
    442 
    443 	return status;
    444 }
    445 
    446 /**
    447 *
    448 * mlme_Stop - Stop event for the MLME SM
    449 *
    450 * \b Description:
    451 *
    452 * Stop event for the MLME SM
    453 *
    454 * \b ARGS:
    455 *
    456 *  I   - hMlme - MLME SM context  \n
    457 *
    458 * \b RETURNS:
    459 *
    460 *  OK if successful, NOK otherwise.
    461 *
    462 * \sa mlme_Start, mlme_Recv
    463 */
    464 TI_STATUS mlme_stop(TI_HANDLE hMlme, disConnType_e disConnType, mgmtStatus_e reason)
    465 {
    466 	TI_STATUS 		status;
    467 	mlme_t		*pHandle;
    468 
    469 	pHandle = (mlme_t*)hMlme;
    470 
    471 	if (pHandle->legacyAuthType == AUTH_LEGACY_NONE)
    472 		return NOK;
    473 
    474 	pHandle->disConnType = disConnType;
    475 	pHandle->disConnReason = reason;
    476 
    477 	status = mlme_smEvent(&pHandle->currentState, MLME_SM_EVENT_STOP, pHandle);
    478 
    479 	return status;
    480 }
    481 
    482 
    483 /**
    484 *
    485 * mlme_reportAuthStatus - Set a specific parameter to the MLME SM
    486 *
    487 * \b Description:
    488 *
    489 * Set a specific parameter to the MLME SM.
    490 *
    491 * \b ARGS:
    492 *
    493 *  I   - hMlme - MLME SM context  \n
    494 *  I/O - pParam - Parameter \n
    495 *
    496 * \b RETURNS:
    497 *
    498 *  OK if successful, NOK otherwise.
    499 *
    500 * \sa mlme_Start, mlme_Stop
    501 */
    502 TI_STATUS mlme_reportAuthStatus(TI_HANDLE hMlme, UINT16 status)
    503 {
    504 	mlme_t			*pHandle;
    505 	paramInfo_t		param;
    506     TI_STATUS       fStatus;
    507 
    508 	pHandle = (mlme_t*)hMlme;
    509 
    510 	if (pHandle == NULL)
    511 		return NOK;
    512 
    513 	if (pHandle->legacyAuthType == AUTH_LEGACY_NONE)
    514 		return NOK;
    515 
    516 	pHandle->mlmeData.uStatusCode = status;
    517 
    518 	/* If status is successful */
    519 	if (status == 0)
    520 	{
    521 		/* Mark a successful status - used for conn.c */
    522 		pHandle->mlmeData.mgmtStatus = STATUS_SUCCESSFUL;
    523 
    524 		fStatus = mlme_smEvent(&pHandle->currentState, MLME_SM_EVENT_AUTH_SUCCESS, pHandle);
    525 	}
    526 	else
    527 	{
    528 		/* Now, if the MLME legacy auth type is AUTO_SWITCH, and the Auth legacy auth type is shared key,
    529 			we configure the auth SM to open system, otherwise, this is really an authentication failure. */
    530 		param.paramType = AUTH_LEGACY_TYPE_PARAM;
    531 		auth_getParam(pHandle->hAuth, &param);
    532 
    533 		if ((pHandle->legacyAuthType == AUTH_LEGACY_AUTO_SWITCH) && (param.content.authLegacyAuthType ==  AUTH_LEGACY_SHARED_KEY))
    534 		{
    535 			param.content.authLegacyAuthType = AUTH_LEGACY_OPEN_SYSTEM;
    536 			fStatus = auth_setParam(pHandle->hAuth, &param);
    537 			fStatus = auth_start(pHandle->hAuth);
    538 		}
    539 		else
    540 		{
    541 			pHandle->mlmeData.mgmtStatus = STATUS_AUTH_REJECT;
    542 			fStatus = mlme_smEvent(&pHandle->currentState, MLME_SM_EVENT_AUTH_FAIL, pHandle);
    543 		}
    544 	}
    545 
    546 	return fStatus;
    547 }
    548 
    549 /**
    550 *
    551 * mlme_reportAssocStatus - Set a specific parameter to the MLME SM
    552 *
    553 * \b Description:
    554 *
    555 * Set a specific parameter to the MLME SM.
    556 *
    557 * \b ARGS:
    558 *
    559 *  I   - hMlme - MLME SM context  \n
    560 *  I/O - pParam - Parameter \n
    561 *
    562 * \b RETURNS:
    563 *
    564 *  OK if successful, NOK otherwise.
    565 *
    566 * \sa mlme_Start, mlme_Stop
    567 */
    568 TI_STATUS mlme_reportAssocStatus(TI_HANDLE hMlme, UINT16 status)
    569 {
    570 	mlme_t		*pHandle;
    571     TI_STATUS   fStatus;
    572 
    573 	pHandle = (mlme_t*)hMlme;
    574 
    575 	if (pHandle == NULL)
    576 		return NOK;
    577 
    578 	if (pHandle->legacyAuthType == AUTH_LEGACY_NONE)
    579 		return NOK;
    580 
    581 	pHandle->mlmeData.uStatusCode = status;
    582 
    583 	/* If status is successful */
    584 	if (status == 0)
    585 	{
    586 		pHandle->mlmeData.mgmtStatus = STATUS_SUCCESSFUL;
    587 		fStatus = mlme_smEvent(&pHandle->currentState, MLME_SM_EVENT_ASSOC_SUCCESS, pHandle);
    588 	} else
    589 	{
    590 		pHandle->mlmeData.mgmtStatus = STATUS_ASSOC_REJECT;
    591 		fStatus = mlme_smEvent(&pHandle->currentState, MLME_SM_EVENT_ASSOC_FAIL, pHandle);
    592 	}
    593 
    594 	return fStatus;
    595 }
    596 
    597 
    598 /**
    599 *
    600 * mlme_SetParam - Set a specific parameter to the MLME SM
    601 *
    602 * \b Description:
    603 *
    604 * Set a specific parameter to the MLME SM.
    605 *
    606 * \b ARGS:
    607 *
    608 *  I   - hMlme - MLME SM context  \n
    609 *  I/O - pParam - Parameter \n
    610 *
    611 * \b RETURNS:
    612 *
    613 *  OK if successful, NOK otherwise.
    614 *
    615 * \sa mlme_Start, mlme_Stop
    616 */
    617 
    618 #ifdef REPORT_LOG
    619 
    620 static char *mlmeSMStateDesc[MLME_SM_NUM_STATES] = {
    621 		"MLME_SM_STATE_IDLE",
    622 		"MLME_SM_STATE_AUTH_WAIT",
    623 		"MLME_SM_STATE_ASSOC_WAIT",
    624 		"MLME_SM_STATE_ASSOC"
    625 	};
    626 
    627 	/* State machine inputs */
    628 static char *mlmeSMEventDesc[MLME_SM_NUM_EVENTS] = {
    629 		"MLME_SM_EVENT_START",
    630 		"MLME_SM_EVENT_STOP",
    631 		"MLME_SM_EVENT_AUTH_SUCCESS",
    632 		"MLME_SM_EVENT_AUTH_FAIL",
    633 		"MLME_SM_EVENT_ASSOC_SUCCESS",
    634 		"MLME_SM_EVENT_ASSOC_FAIL"
    635 	};
    636 
    637 #endif
    638 
    639 
    640 TI_STATUS mlme_smEvent(UINT8 *currentState, UINT8 event, TI_HANDLE hMlme)
    641 {
    642    mlme_t *pMlme = (mlme_t *)hMlme;
    643 	TI_STATUS 		status;
    644 	UINT8		nextState;
    645 
    646 	status = fsm_GetNextState(pMlme->pMlmeSm, *currentState, event, &nextState);
    647 	if (status != OK)
    648 	{
    649 		WLAN_REPORT_ERROR(pMlme->hReport, MLME_SM_MODULE_LOG,
    650 						  ("MLME_SM: ERROR - failed getting next state \n"));
    651 
    652 		return(NOK);
    653 	}
    654 
    655 	WLAN_REPORT_SM(pMlme->hReport, MLME_SM_MODULE_LOG,
    656 					 ("MLME_SM: <%s, %s> --> %s\n",
    657 					  mlmeSMStateDesc[*currentState],
    658 					  mlmeSMEventDesc[event],
    659 					  mlmeSMStateDesc[nextState]));
    660 
    661 	status = fsm_Event(pMlme->pMlmeSm, currentState, event, (void *)pMlme);
    662 
    663 	return(status);
    664 }
    665 
    666 /* state machine functions */
    667 
    668 TI_STATUS mlme_smStartIdle(mlme_t *pMlme)
    669 {
    670 	TI_STATUS		status;
    671 
    672 	status = auth_start(pMlme->hAuth);
    673 
    674 	return status;
    675 }
    676 
    677 TI_STATUS mlme_smClass3Idle(mlme_t *pMlme)
    678 {
    679 	return OK;
    680 }
    681 
    682 
    683 
    684 TI_STATUS mlme_smAuthSuccessAuthWait(mlme_t *pMlme)
    685 {
    686 	TI_STATUS		status;
    687 
    688 	if (pMlme->reAssoc)
    689 	{
    690 		status = reassoc_start(pMlme->hAssoc);
    691 	}
    692 	else
    693 	{
    694 		status = assoc_start(pMlme->hAssoc);
    695 	}
    696 
    697 	return status;
    698 }
    699 
    700 TI_STATUS mlme_smAuthFailAuthWait(mlme_t *pMlme)
    701 {
    702 	TI_STATUS		status;
    703 
    704 	status = mlme_smReportStatus(pMlme);
    705 
    706 	return status;
    707 }
    708 
    709 TI_STATUS mlme_smStopAssocWait(mlme_t *pMlme)
    710 {
    711 	mlme_stopAssocAndAuth(pMlme);
    712 	return OK;
    713 }
    714 
    715 TI_STATUS mlme_smAssocSuccessAssocWait(mlme_t *pMlme)
    716 {
    717 	TI_STATUS		status;
    718 
    719 	status = mlme_smReportStatus(pMlme);
    720 
    721 	return status;
    722 }
    723 
    724 TI_STATUS mlme_smAssocFailAssocWait(mlme_t *pMlme)
    725 {
    726 	TI_STATUS		status;
    727 
    728 	status = mlme_smReportStatus(pMlme);
    729 
    730 	return status;
    731 }
    732 
    733 
    734 TI_STATUS mlme_smStopAssoc(mlme_t *pMlme)
    735 {
    736 	mlme_stopAssocAndAuth(pMlme);
    737 	return OK;
    738 }
    739 
    740 
    741 
    742 TI_STATUS mlme_smNOP(mlme_t *pMlme)
    743 {
    744 	return OK;
    745 }
    746 
    747 TI_STATUS mlme_smActionUnexpected(mlme_t *pMlme)
    748 {
    749 	return OK;
    750 }
    751 
    752 /* local functions */
    753 
    754 TI_STATUS mlme_smReportStatus(mlme_t *pMlme)
    755 {
    756 	TI_STATUS		status;
    757 
    758 	if (pMlme == NULL)
    759 	{
    760 		return NOK;
    761 	}
    762 
    763 	status = conn_reportMlmeStatus(pMlme->hConn, pMlme->mlmeData.mgmtStatus, pMlme->mlmeData.uStatusCode);
    764 
    765 	return status;
    766 }
    767 
    768 
    769 #ifdef NO_HAL_VOB
    770 static void mlme_logBeaconReceived(TI_HANDLE hMlme)
    771 {
    772 	mlme_beaconReceivedPrint(hMlme);
    773 }
    774 #endif
    775 
    776 void mlme_stopAssocAndAuth(mlme_t *pMlme)
    777 {
    778 
    779 	BOOL 		sendDeAuth;
    780 	BOOL 		sendDisAssoc;
    781 
    782 	switch( pMlme->disConnType )
    783 	{
    784 	case DISCONN_TYPE_IMMEDIATE:
    785 		sendDeAuth 	 = FALSE;
    786 		sendDisAssoc = FALSE;
    787 		break;
    788 
    789 	case DISCONN_TYPE_DISASSOC:
    790 		sendDisAssoc = TRUE;
    791 		sendDeAuth   = FALSE;
    792 		break;
    793 
    794 	case DISCONN_TYPE_DEAUTH:
    795 		sendDisAssoc = FALSE;
    796 		sendDeAuth   = TRUE;
    797 		break;
    798 
    799 	default:
    800 		return;
    801 	}
    802 
    803 	assoc_setDisAssocFlag(pMlme->hAssoc, sendDisAssoc);
    804 	assoc_stop(pMlme->hAssoc);
    805 
    806 	auth_stop(pMlme->hAuth, sendDeAuth, pMlme->disConnReason );
    807 
    808 	/* If the dis association frame is not sent the MLME generate the event
    809 	   by itself */
    810 	if (( sendDisAssoc == FALSE) && (sendDeAuth==FALSE)) {
    811 		conn_disConnFrameSentCBFunc(pMlme->hConn);
    812 	}
    813 }
    814 /*****************************************************************************
    815 **
    816 ** MLME messages builder/Parser
    817 **
    818 *****************************************************************************/
    819 
    820 
    821 
    822 
    823 
    824 
    825 
    826