4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 /** \file sharedKeyAuthSm.c
35 * \brief shared key 802.11 authentication SM source
37 * \see sharedKeyAuthSm.h
41 /***************************************************************************/
43 /* MODULE: sharedKeyAuthSm.c */
44 /* PURPOSE: shared key 802.11 authentication SM source */
46 /***************************************************************************/
48 #define __FILE_ID__ FILE_ID_83
56 #include "sharedKeyAuthSm.h"
60 /** number of states in the state machine */
61 #define SHARED_KEY_AUTH_SM_NUM_STATES 4
63 /** number of events in the state machine */
64 #define SHARED_KEY_AUTH_SM_NUM_EVENTS 8
72 /* External data definitions */
74 /* External functions definitions */
76 /* Global variables */
78 /* Local function prototypes */
84 * sharedKeyAuth_smConfig - configure a new authentication SM
88 * Configure a new authentication SM.
92 * I - hAuth - Association SM context \n
93 * I - hMlme - MLME SM context \n
94 * I - hSiteMgr - Site manager context \n
95 * I - hCtrlData - Control data context \n
96 * I - hTxData - TX data context \n
97 * I - hHalCtrl - Hal control context \n
98 * I - hReport - Report context \n
99 * I - hOs - OS context \n
100 * I - authTimeout - Association SM timeout \n
101 * I - authMaxCount - Max number of authentication requests to send \n
105 * TI_OK if successful, TI_NOK otherwise.
107 * \sa sharedKeyAuth_Create, sharedKeyAuth_Unload
109 TI_STATUS sharedKeyAuth_Config(TI_HANDLE hAuth, TI_HANDLE hOs)
113 /** Main 802.1X State Machine matrix */
114 fsm_actionCell_t sharedKeyAuth_smMatrix[SHARED_KEY_AUTH_SM_NUM_STATES][SHARED_KEY_AUTH_SM_NUM_EVENTS] =
116 /* next state and actions for IDLE state */
117 {{SHARED_KEY_AUTH_SM_STATE_WAIT_1, (fsm_Action_t)sharedKeyAuth_smStartIdle},
118 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
119 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
120 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
121 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
122 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
123 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
124 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smActionUnexpected}
126 /* next state and actions for WAIT_1 state */
127 {{SHARED_KEY_AUTH_SM_STATE_WAIT_1, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
128 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smStopWait},
129 {SHARED_KEY_AUTH_SM_STATE_WAIT_2, (fsm_Action_t)sharedKeyAuth_smSuccess1Wait1},
130 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smFailure1Wait1},
131 {SHARED_KEY_AUTH_SM_STATE_WAIT_1, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
132 {SHARED_KEY_AUTH_SM_STATE_WAIT_1, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
133 {SHARED_KEY_AUTH_SM_STATE_WAIT_1, (fsm_Action_t)sharedKeyAuth_smTimeoutWait1},
134 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smMaxRetryWait}
136 /* next state and actions for WAIT_2 state */
137 {{SHARED_KEY_AUTH_SM_STATE_WAIT_2, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
138 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smStopWait},
139 {SHARED_KEY_AUTH_SM_STATE_WAIT_2, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
140 {SHARED_KEY_AUTH_SM_STATE_WAIT_2, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
141 {SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smSuccess2Wait2},
142 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smFailure2Wait2},
143 {SHARED_KEY_AUTH_SM_STATE_WAIT_2, (fsm_Action_t)sharedKeyAuth_smTimeoutWait2},
144 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smMaxRetryWait}
146 /* next state and actions for AUTH state */
147 {{SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
148 {SHARED_KEY_AUTH_SM_STATE_IDLE, (fsm_Action_t)sharedKeyAuth_smStopAuth},
149 {SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
150 {SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
151 {SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
152 {SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
153 {SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smActionUnexpected},
154 {SHARED_KEY_AUTH_SM_STATE_AUTH, (fsm_Action_t)sharedKeyAuth_smActionUnexpected}
163 pHandle = (auth_t*)hAuth;
165 status = fsm_Config(pHandle->pAuthSm, &sharedKeyAuth_smMatrix[0][0],
166 SHARED_KEY_AUTH_SM_NUM_STATES, SHARED_KEY_AUTH_SM_NUM_EVENTS, auth_skSMEvent, hOs);
172 pHandle->currentState = SHARED_KEY_AUTH_SM_STATE_IDLE;
178 TI_STATUS auth_skSMEvent(TI_UINT8 *currentState, TI_UINT8 event, TI_HANDLE hAuth)
180 auth_t *pAuth = (auth_t *)hAuth;
184 status = fsm_GetNextState(pAuth->pAuthSm, *currentState, event, &nextState);
187 TRACE0(pAuth->hReport, REPORT_SEVERITY_SM, "State machine error, failed getting next state\n");
191 TRACE3(pAuth->hReport, REPORT_SEVERITY_INFORMATION, "auth_skSMEvent: <currentState = %d, event = %d> --> nextState = %d\n", *currentState, event, nextState);
193 status = fsm_Event(pAuth->pAuthSm, currentState, event, (void *)pAuth);
201 * sharedKeyAuth_Recv - Recive a message from the AP
205 * Parse a message form the AP and perform the appropriate event.
209 * I - hAuth - Association SM context \n
213 * TI_OK if successful, TI_NOK otherwise.
215 * \sa sharedKeyAuth_Start, sharedKeyAuth_Stop
217 TI_STATUS sharedKeyAuth_Recv(TI_HANDLE hAuth, mlmeFrameInfo_t *pFrame)
219 TI_STATUS status = TI_NOK;
224 pHandle = (auth_t*)hAuth;
231 /* check response status */
232 authAlgo = ENDIAN_HANDLE_WORD(pFrame->content.auth.authAlgo);
233 if (authAlgo != AUTH_LEGACY_SHARED_KEY)
235 TRACE0(pHandle->hReport, REPORT_SEVERITY_SM, "SHARED_KEY_AUTH_SM: DEBUG recieved authentication message with wrong algorithm \n");
239 /* check response status */
240 rspSeq = pFrame->content.auth.seqNum;
242 pHandle->authData.status = pFrame->content.auth.status;
243 pHandle->authData.pChalange = (char *)(pFrame->content.auth.pChallenge->text);
244 pHandle->authData.challangeLen = pFrame->content.auth.pChallenge->hdr[1];
246 if (pHandle->authData.status == STATUS_SUCCESSFUL)
251 TRACE0(pHandle->hReport, REPORT_SEVERITY_SM, "SHARED_KEY_AUTH_SM: DEBUG Success authenticating to AP stage 1\n");
253 if (pFrame->content.auth.pChallenge->hdr[0] != CHALLANGE_TEXT_IE_ID)
255 TRACE0(pHandle->hReport, REPORT_SEVERITY_ERROR, "SHARED_KEY_AUTH_SM: Wrong element ID for challange \n");
260 status = auth_skSMEvent(&pHandle->currentState, SHARED_KEY_AUTH_SM_EVENT_SUCCESS_1, hAuth);
264 TRACE0(pHandle->hReport, REPORT_SEVERITY_SM, "SHARED_KEY_AUTH_SM: DEBUG Success authenticating to AP stage 2\n");
266 status = auth_skSMEvent(&pHandle->currentState, SHARED_KEY_AUTH_SM_EVENT_SUCCESS_2, hAuth);
270 TRACE0(pHandle->hReport, REPORT_SEVERITY_ERROR, "SHARED_KEY_AUTH_SM: Wrong sequence number \n");
281 status = auth_skSMEvent(&pHandle->currentState, SHARED_KEY_AUTH_SM_EVENT_FAIL_1, hAuth);
285 status = auth_skSMEvent(&pHandle->currentState, SHARED_KEY_AUTH_SM_EVENT_FAIL_2, hAuth);
297 /* state machine functions */
299 TI_STATUS sharedKeyAuth_smStartIdle(auth_t *hAuth)
303 status = sharedKeyAuth_smResetRetry(hAuth);
304 status = sharedKeyAuth_smSendAuth1(hAuth);
305 status = sharedKeyAuth_smStartTimer(hAuth);
306 status = sharedKeyAuth_smIncRetry(hAuth);
311 TI_STATUS sharedKeyAuth_smStopWait(auth_t *hAuth)
315 status = sharedKeyAuth_smStopTimer(hAuth);
320 TI_STATUS sharedKeyAuth_smSuccess1Wait1(auth_t *hAuth)
324 status = sharedKeyAuth_smResetRetry(hAuth);
327 status = sharedKeyAuth_smStopTimer(hAuth);
330 status = sharedKeyAuth_smSendAuth2(hAuth);
333 status = sharedKeyAuth_smStartTimer(hAuth);
336 status = sharedKeyAuth_smIncRetry(hAuth);
341 TI_STATUS sharedKeyAuth_smFailure1Wait1(auth_t *hAuth)
345 status = sharedKeyAuth_smStopTimer(hAuth);
346 status = sharedKeyAuth_smReportFailure(hAuth);
351 TI_STATUS sharedKeyAuth_smTimeoutWait1(auth_t *hAuth)
355 status = sharedKeyAuth_smSendAuth1(hAuth);
356 status = sharedKeyAuth_smStartTimer(hAuth);
357 status = sharedKeyAuth_smIncRetry(hAuth);
362 TI_STATUS sharedKeyAuth_smMaxRetryWait(auth_t *hAuth)
366 status = sharedKeyAuth_smReportFailure(hAuth);
371 TI_STATUS sharedKeyAuth_smSuccess2Wait2(auth_t *hAuth)
375 status = sharedKeyAuth_smStopTimer(hAuth);
376 status = sharedKeyAuth_smReportSuccess(hAuth);
381 TI_STATUS sharedKeyAuth_smFailure2Wait2(auth_t *hAuth)
385 status = sharedKeyAuth_smStopTimer(hAuth);
386 status = sharedKeyAuth_smReportFailure(hAuth);
391 TI_STATUS sharedKeyAuth_smTimeoutWait2(auth_t *hAuth)
395 status = sharedKeyAuth_smSendAuth2(hAuth);
396 status = sharedKeyAuth_smStartTimer(hAuth);
397 status = sharedKeyAuth_smIncRetry(hAuth);
402 /* action routines for authentication SM */
404 TI_STATUS sharedKeyAuth_smSendAuth1(auth_t *hAuth)
408 status = auth_smMsgBuild(hAuth, 1, 0, NULL, 0);
413 TI_STATUS sharedKeyAuth_smSendAuth2(auth_t *hAuth)
419 /* ENCRYPT CHALLANGE WITH SECRET */
421 status = auth_smMsgBuild(hAuth, 3, 0, (TI_UINT8 *)(hAuth->authData.pChalange), hAuth->authData.challangeLen);
426 TI_STATUS sharedKeyAuth_smStopAuth(auth_t *hAuth)
431 TI_STATUS sharedKeyAuth_smActionUnexpected(auth_t *hAuth)
436 /* local functions */
439 TI_STATUS sharedKeyAuth_smResetRetry(auth_t *hAuth)
446 hAuth->retryCount = 0;
451 TI_STATUS sharedKeyAuth_smIncRetry(auth_t *hAuth)
463 TI_STATUS sharedKeyAuth_smReportSuccess(auth_t *hAuth)
472 status = mlme_reportAuthStatus(hAuth->hMlme, hAuth->authData.status);
477 TI_STATUS sharedKeyAuth_smReportFailure(auth_t *hAuth)
486 status = mlme_reportAuthStatus(hAuth->hMlme, hAuth->authData.status);
491 TI_STATUS sharedKeyAuth_smStartTimer(auth_t *hAuth)
498 tmr_StartTimer (hAuth->hAuthSmTimer,
507 TI_STATUS sharedKeyAuth_smStopTimer(auth_t *hAuth)
514 tmr_StopTimer (hAuth->hAuthSmTimer);
519 TI_STATUS sharedKey_Timeout(auth_t *pAuth)
521 if (pAuth->retryCount >= pAuth->maxCount)
523 pAuth->authData.status = STATUS_PACKET_REJ_TIMEOUT;
524 return auth_skSMEvent(&pAuth->currentState, SHARED_KEY_AUTH_SM_EVENT_MAX_RETRY, pAuth);
527 return auth_skSMEvent(&pAuth->currentState, SHARED_KEY_AUTH_SM_EVENT_TIMEOUT, pAuth);