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