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