• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * authSm.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 authSM.c
35  *  \brief 802.11 authentication SM source
36  *
37  *  \see authSM.h
38  */
39 
40 
41 /***************************************************************************/
42 /*																		   */
43 /*		MODULE:	authSM.c												   */
44 /*    PURPOSE:	802.11 authentication SM source							   */
45 /*																	 	   */
46 /***************************************************************************/
47 
48 #define __FILE_ID__  FILE_ID_64
49 #include "osApi.h"
50 
51 #include "paramOut.h"
52 #include "fsm.h"
53 #include "report.h"
54 #include "timer.h"
55 #include "mlmeApi.h"
56 #include "mlmeBuilder.h"
57 #include "authSm.h"
58 #include "openAuthSm.h"
59 #include "sharedKeyAuthSm.h"
60 #include "DrvMainModules.h"
61 
62 /* Constants */
63 
64 /** number of states in the state machine */
65 #define	AUTH_SM_MAX_NUM_STATES		4
66 
67 /** number of events in the state machine */
68 #define	AUTH_SM_MAX_NUM_EVENTS		8
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 * auth_create - allocate memory for authentication SM
89 *
90 * \b Description:
91 *
92 * Allocate memory for authentication SM. \n
93 * 		Allocates memory for Association context. \n
94 * 		Allocates memory for authentication timer. \n
95 * 		Allocates memory for authentication SM matrix. \n
96 *
97 * \b ARGS:
98 *
99 *  I   - hOs - OS context  \n
100 *
101 * \b RETURNS:
102 *
103 *  TI_OK if successful, TI_NOK otherwise.
104 *
105 * \sa rsn_mainSecSmKeysOnlyStop()
106 */
auth_create(TI_HANDLE hOs)107 TI_HANDLE auth_create(TI_HANDLE hOs)
108 {
109 	auth_t 	*pHandle;
110 	TI_STATUS		status;
111 
112 	/* allocate authentication context memory */
113 	pHandle = (auth_t*)os_memoryAlloc(hOs, sizeof(auth_t));
114 	if (pHandle == NULL)
115 	{
116 		return NULL;
117 	}
118 
119 	os_memoryZero(hOs, pHandle, sizeof(auth_t));
120 
121 	pHandle->hOs = hOs;
122 
123 	/* allocate memory for authentication state machine */
124 	status = fsm_Create(hOs, &pHandle->pAuthSm, AUTH_SM_MAX_NUM_STATES, AUTH_SM_MAX_NUM_EVENTS);
125 	if (status != TI_OK)
126 	{
127 		os_memoryFree(hOs, pHandle, sizeof(auth_t));
128 		return NULL;
129 	}
130 
131 	return pHandle;
132 }
133 
134 
135 /**
136 *
137 * auth_unload - unload authentication SM from memory
138 *
139 * \b Description:
140 *
141 * Unload authentication SM from memory
142 *
143 * \b ARGS:
144 *
145 *  I   - hAuth - Authentication SM context  \n
146 *
147 * \b RETURNS:
148 *
149 *  TI_OK if successful, TI_NOK otherwise.
150 *
151 * \sa rsn_mainSecSmKeysOnlyStop()
152 */
auth_unload(TI_HANDLE hAuth)153 TI_STATUS auth_unload(TI_HANDLE hAuth)
154 {
155     TI_STATUS 		status;
156 	auth_t		*pHandle;
157 
158 	pHandle = (auth_t*)hAuth;
159 
160 	status = fsm_Unload(pHandle->hOs, pHandle->pAuthSm);
161     if (status != TI_OK)
162 	{
163 		/* report failure but don't stop... */
164 TRACE0(pHandle->hReport, REPORT_SEVERITY_ERROR, "AUTH_SM: Error releasing FSM memory \n");
165 	}
166 
167 	if (pHandle->hAuthSmTimer)
168 	{
169 		tmr_DestroyTimer (pHandle->hAuthSmTimer);
170 	}
171 
172 	os_memoryFree(pHandle->hOs, pHandle, sizeof(auth_t));
173 
174 	return TI_OK;
175 }
176 
177 /**
178 *
179 * auth_init - Init required handles and module variables,
180 *
181 * \b Description:
182 *
183 * Init required handles and module variables,
184 *
185 * \b ARGS:
186 *
187 *  I   - pStadHandles - The driver modules handles  \n
188 *
189 * \b RETURNS:
190 *
191 *  void
192 *
193 * \sa auth_Create, auth_Unload
194 */
auth_init(TStadHandlesList * pStadHandles)195 void auth_init (TStadHandlesList *pStadHandles)
196 {
197 	auth_t *pHandle = (auth_t*)(pStadHandles->hAuth);
198 
199 	pHandle->hMlme   = pStadHandles->hMlmeSm;
200 	pHandle->hRsn    = pStadHandles->hRsn;
201 	pHandle->hReport = pStadHandles->hReport;
202 	pHandle->hOs     = pStadHandles->hOs;
203     pHandle->hTimer  = pStadHandles->hTimer;
204 }
205 
206 
auth_SetDefaults(TI_HANDLE hAuth,authInitParams_t * pAuthInitParams)207 TI_STATUS auth_SetDefaults (TI_HANDLE hAuth, authInitParams_t *pAuthInitParams)
208 {
209     auth_t		*pHandle = (TI_HANDLE) hAuth;
210 
211 	pHandle->timeout = pAuthInitParams->authResponseTimeout;
212 	pHandle->maxCount = pAuthInitParams->authMaxRetryCount;
213 
214 	pHandle->retryCount = 0;
215 	pHandle->authRejectCount = 0;
216 	pHandle->authTimeoutCount = 0;
217 
218 	pHandle->authType = AUTH_LEGACY_NONE;
219 
220 	/* allocate OS timer memory */
221     pHandle->hAuthSmTimer = tmr_CreateTimer (pHandle->hTimer);
222 	if (pHandle->hAuthSmTimer == NULL)
223 	{
224         TRACE0(pHandle->hReport, REPORT_SEVERITY_ERROR, "auth_SetDefaults(): Failed to create hAuthSmTimer!\n");
225 		return TI_NOK;
226 	}
227 
228 	return TI_OK;
229 }
230 
231 
232 /**
233 *
234 * auth_start - Start event for the authentication SM
235 *
236 * \b Description:
237 *
238 * Start event for the authentication SM
239 *
240 * \b ARGS:
241 *
242 *  I   - hAuth - Authentication SM context  \n
243 *
244 * \b RETURNS:
245 *
246 *  TI_OK if successful, TI_NOK otherwise.
247 *
248 * \sa auth_Stop, auth_Recv
249 */
auth_start(TI_HANDLE hAuth)250 TI_STATUS auth_start(TI_HANDLE hAuth)
251 {
252 	auth_t		*pHandle = (auth_t*)hAuth;
253 
254 	if (pHandle == NULL)
255     {
256 		return TI_NOK;
257     }
258 
259 	if (pHandle->authType == AUTH_LEGACY_NONE)
260     {
261         TRACE0(pHandle->hReport, REPORT_SEVERITY_ERROR, "auth_start: pHandle->authType == AUTH_LEGACY_NONE\n");
262 		return TI_NOK;
263     }
264 
265 	switch (pHandle->authType)
266 	{
267     case AUTH_LEGACY_RESERVED1:
268 	case AUTH_LEGACY_OPEN_SYSTEM:
269 		return auth_osSMEvent(&pHandle->currentState, OPEN_AUTH_SM_EVENT_START, pHandle);
270 
271 	case AUTH_LEGACY_SHARED_KEY:
272 		return auth_skSMEvent(&pHandle->currentState, SHARED_KEY_AUTH_SM_EVENT_START, pHandle);
273 
274 	default:
275         TRACE0(pHandle->hReport, REPORT_SEVERITY_ERROR, "auth_start: pHandle->authType unknown.\n");
276 		return TI_NOK;
277 	}
278 }
279 
280 /**
281 *
282 * auth_stop - Stop event for the authentication SM
283 *
284 * \b Description:
285 *
286 * Stop event for the authentication SM
287 *
288 * \b ARGS:
289 *
290 *  I   - hAuth - Authentication SM context  \n
291 *
292 * \b RETURNS:
293 *
294 *  TI_OK if successful, TI_NOK otherwise.
295 *
296 * \sa auth_Start, auth_Recv
297 */
auth_stop(TI_HANDLE hAuth,TI_BOOL sendDeAuth,mgmtStatus_e reason)298 TI_STATUS auth_stop(TI_HANDLE hAuth, TI_BOOL sendDeAuth, mgmtStatus_e reason )
299 {
300 	auth_t		*pHandle;
301 
302 	pHandle = (auth_t*)hAuth;
303 
304 	if (pHandle == NULL)
305 		return TI_NOK;
306 
307 	if (pHandle->authType == AUTH_LEGACY_NONE)
308 		return TI_NOK;
309 
310 	if( sendDeAuth == TI_TRUE )
311 	{
312 		deAuth_t	deAuth;
313 		deAuth.reason = ENDIAN_HANDLE_WORD(reason);
314 		mlmeBuilder_sendFrame(pHandle->hMlme, DE_AUTH, (TI_UINT8*)&deAuth, sizeof(deAuth_t), 0);
315 	}
316 
317 	switch (pHandle->authType)
318 	{
319     case AUTH_LEGACY_RESERVED1:
320 	case AUTH_LEGACY_OPEN_SYSTEM:
321 		return auth_osSMEvent(&pHandle->currentState, OPEN_AUTH_SM_EVENT_STOP, pHandle);
322 
323 	case AUTH_LEGACY_SHARED_KEY:
324 		return auth_skSMEvent(&pHandle->currentState, SHARED_KEY_AUTH_SM_EVENT_STOP, pHandle);
325 
326 	default:
327 		return TI_NOK;
328 	}
329 }
330 
331 /**
332 *
333 * auth_recv - Recive a message from the AP
334 *
335 * \b Description:
336 *
337 * Parse a message form the AP and perform the appropriate event.
338 *
339 * \b ARGS:
340 *
341 *  I   - hAuth - Authentication SM context  \n
342 *
343 * \b RETURNS:
344 *
345 *  TI_OK if successful, TI_NOK otherwise.
346 *
347 * \sa auth_Start, auth_Stop
348 */
auth_recv(TI_HANDLE hAuth,mlmeFrameInfo_t * pFrame)349 TI_STATUS auth_recv(TI_HANDLE hAuth, mlmeFrameInfo_t *pFrame)
350 {
351 	auth_t			*pHandle;
352 
353 	pHandle = (auth_t*)hAuth;
354 
355 	if (pHandle == NULL)
356 		return TI_NOK;
357 
358 	if (pFrame->subType != AUTH)
359 		return TI_NOK;
360 
361 	if (pHandle->authType == AUTH_LEGACY_NONE)
362 		return TI_NOK;
363 
364 	if (pFrame->content.auth.status != STATUS_SUCCESSFUL)
365 		pHandle->authRejectCount++;
366 
367 	switch (pHandle->authType)
368 	{
369 	case AUTH_LEGACY_RESERVED1:
370 	case AUTH_LEGACY_OPEN_SYSTEM:
371 		return openAuth_Recv(hAuth, pFrame);
372 
373 	case AUTH_LEGACY_SHARED_KEY:
374 		return sharedKeyAuth_Recv(hAuth, pFrame);
375 
376 	default:
377 		return TI_OK;
378 	}
379 }
380 
381 /**
382 *
383 * auth_getParam - Get a specific parameter from the authentication SM
384 *
385 * \b Description:
386 *
387 * Get a specific parameter from the authentication SM.
388 *
389 * \b ARGS:
390 *
391 *  I   - hAuth - Authentication SM context  \n
392 *  I/O - pParam - Parameter \n
393 *
394 * \b RETURNS:
395 *
396 *  TI_OK if successful, TI_NOK otherwise.
397 *
398 * \sa auth_Start, auth_Stop
399 */
auth_getParam(TI_HANDLE hAuth,paramInfo_t * pParam)400 TI_STATUS auth_getParam(TI_HANDLE hAuth, paramInfo_t *pParam)
401 {
402 	auth_t		*pHandle;
403 
404 	pHandle = (auth_t*)hAuth;
405 
406 	if ((pHandle == NULL) || (pParam == NULL))
407 	{
408 		return TI_NOK;
409 	}
410 
411 	switch (pParam->paramType)
412 	{
413 	case AUTH_RESPONSE_TIMEOUT_PARAM:
414 		pParam->content.authResponseTimeout = pHandle->timeout;
415 		break;
416 
417 	case AUTH_COUNTERS_PARAM:
418 		pParam->content.siteMgrTiWlanCounters.AuthRejects = pHandle->authRejectCount;
419 		pParam->content.siteMgrTiWlanCounters.AuthTimeouts = pHandle->authTimeoutCount;
420 		break;
421 
422 	case AUTH_LEGACY_TYPE_PARAM:
423 		pParam->content.authLegacyAuthType = pHandle->authType;
424 		break;
425 
426 	default:
427 		return TI_NOK;
428 	}
429 
430 	return TI_OK;
431 }
432 
433 /**
434 *
435 * auth_setParam - Set a specific parameter to the authentication SM
436 *
437 * \b Description:
438 *
439 * Set a specific parameter to the authentication SM.
440 *
441 * \b ARGS:
442 *
443 *  I   - hAuth - Authentication SM context  \n
444 *  I/O - pParam - Parameter \n
445 *
446 * \b RETURNS:
447 *
448 *  TI_OK if successful, TI_NOK otherwise.
449 *
450 * \sa auth_Start, auth_Stop
451 */
auth_setParam(TI_HANDLE hAuth,paramInfo_t * pParam)452 TI_STATUS auth_setParam(TI_HANDLE hAuth, paramInfo_t *pParam)
453 {
454 	auth_t		*pHandle;
455 
456 	pHandle = (auth_t*)hAuth;
457 
458 	if ((pHandle == NULL) || (pParam == NULL))
459 	{
460 		return TI_NOK;
461 	}
462 
463 	switch (pParam->paramType)
464 	{
465 	case AUTH_LEGACY_TYPE_PARAM:
466 		pHandle->authType = pParam->content.authLegacyAuthType;
467 
468 		switch (pHandle->authType)
469 		{
470         case AUTH_LEGACY_RESERVED1:
471 		case AUTH_LEGACY_OPEN_SYSTEM:
472 			openAuth_Config(hAuth, pHandle->hOs);
473 			break;
474 
475 		case AUTH_LEGACY_SHARED_KEY:
476 			sharedKeyAuth_Config(hAuth, pHandle->hOs);
477 			break;
478 
479 		default:
480 			return TI_NOK;
481 		}
482 		break;
483 
484 	case AUTH_RESPONSE_TIMEOUT_PARAM:
485 		if ((pParam->content.authResponseTimeout >= AUTH_RESPONSE_TIMEOUT_MIN) &&
486 			(pParam->content.authResponseTimeout <= AUTH_RESPONSE_TIMEOUT_MAX))
487 		{
488 			pHandle->timeout = pParam->content.authResponseTimeout;
489 		}
490 		else
491 		{
492 			return TI_NOK;
493 		}
494 		break;
495 
496 	default:
497 		return TI_NOK;
498 	}
499 
500 	return TI_OK;
501 }
502 
503 /**
504 *
505 * auth_smTimeout - Set a specific parameter to the authentication SM
506 *
507 * \b Description:
508 *
509 * Set a specific parameter to the authentication SM.
510 *
511 * \b ARGS:
512 *
513 *  I   - hAuth - authentication SM context  \n
514 *  I   - bTwdInitOccured - Indicates if TWDriver recovery occured since timer started  \n
515 *
516 * \b RETURNS:
517 *
518 *  TI_OK if successful, TI_NOK otherwise.
519 *
520 * \sa auth_Start, auth_Stop
521 */
auth_smTimeout(TI_HANDLE hAuth,TI_BOOL bTwdInitOccured)522 void auth_smTimeout (TI_HANDLE hAuth, TI_BOOL bTwdInitOccured)
523 {
524 	auth_t		*pHandle;
525 
526 	pHandle = (auth_t*)hAuth;
527 
528 	if (pHandle == NULL)
529 		return;
530 
531 	if (pHandle->authType == AUTH_LEGACY_NONE)
532 		return;
533 
534 	pHandle->authTimeoutCount++;
535 
536 	switch (pHandle->authType)
537 	{
538     case AUTH_LEGACY_RESERVED1:
539 	case AUTH_LEGACY_OPEN_SYSTEM:
540 		openAuth_Timeout(pHandle);
541 		break;
542 
543 	case AUTH_LEGACY_SHARED_KEY:
544 		sharedKey_Timeout(pHandle);
545 		break;
546 
547 	default:
548 		break;
549 	}
550 }
551 
552 /*****************************************************************************
553 **
554 ** Authentication messages builder/Parser
555 **
556 *****************************************************************************/
557 
558 /**
559 *
560 * auth_smMsgBuild - Build an authentication message and send it to the mlme builder
561 *
562 * \b Description:
563 *
564 * Build an authentication message and send it to the mlme builder.
565 *
566 * \b ARGS:
567 *
568 *  I   - pAssoc - Association SM context  \n
569 *  I/O - pParam - Parameter \n
570 *
571 * \b RETURNS:
572 *
573 *  TI_OK if successful, TI_NOK otherwise.
574 *
575 * \sa auth_Start, auth_Stop
576 */
auth_smMsgBuild(auth_t * pCtx,TI_UINT16 seq,TI_UINT16 statusCode,TI_UINT8 * pChallange,TI_UINT8 challangeLen)577 TI_STATUS auth_smMsgBuild(auth_t *pCtx, TI_UINT16 seq, TI_UINT16 statusCode, TI_UINT8* pChallange, TI_UINT8 challangeLen)
578 {
579 	TI_STATUS				status;
580 	TI_UINT8				len;
581 	TI_UINT8				authMsg[MAX_AUTH_MSG_LEN];
582 	authMsg_t			*pAuthMsg;
583 	dot11_CHALLENGE_t	*pDot11Challenge;
584 	TI_UINT8				wepOpt;
585 
586 	wepOpt = 0;
587 
588 	pAuthMsg = (authMsg_t*)authMsg;
589 
590 	/* insert algorithm */
591 	pAuthMsg->authAlgo = (TI_UINT16)pCtx->authType;
592 
593 	/* insert sequense */
594 	pAuthMsg->seqNum = ENDIAN_HANDLE_WORD(seq);
595 
596 	/* insert status code */
597 	pAuthMsg->status = ENDIAN_HANDLE_WORD(statusCode);
598 
599 	len = sizeof(pAuthMsg->authAlgo) + sizeof(pAuthMsg->seqNum) + sizeof(pAuthMsg->status);
600 
601 	if (pChallange != NULL)
602 	{
603 		pDot11Challenge = (dot11_CHALLENGE_t*)&authMsg[len];
604 
605 		pDot11Challenge->hdr[0] = CHALLANGE_TEXT_IE_ID;
606 		pDot11Challenge->hdr[1] = challangeLen;
607 
608 		os_memoryCopy(pCtx->hOs, (void *)pDot11Challenge->text, pChallange, challangeLen);
609 		len += challangeLen + 2;
610 
611 		wepOpt = 1;
612 	}
613 
614 	status =  mlmeBuilder_sendFrame(pCtx->hMlme, AUTH, authMsg, len, wepOpt);
615 
616 	return status;
617 }
618 
619 
620 
621 
622 
623 
624 
625