1 /*
2 * mainSecKeysOnly.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 mainSecSm.c
35 * \brief 802.1X finite state machine header file
36 *
37 * \see mainSecSm.h
38 */
39
40
41 /***************************************************************************/
42 /* */
43 /* MODULE: mainSecSm.c */
44 /* PURPOSE: Main Security State Machine API */
45 /* */
46 /***************************************************************************/
47
48 #define __FILE_ID__ FILE_ID_37
49 #include "osApi.h"
50 #include "paramOut.h"
51 #include "fsm.h"
52 #include "report.h"
53 #include "DataCtrl_Api.h"
54 #include "smeApi.h"
55 #include "rsn.h"
56 #include "rsnApi.h"
57 #include "mainSecSm.h"
58 #include "mainSecKeysOnly.h"
59 #include "mainKeysSm.h"
60
61 /* Constants */
62
63 /* Enumerations */
64
65 /* Typedefs */
66
67 /* Structures */
68
69 /* External data definitions */
70
71 /* External functions definitions */
72
73 /* Global variables */
74
75 /* functions */
76 TI_STATUS mainSecKeysOnly_getAuthState(mainSec_t *pMainSec, TIWLN_SECURITY_STATE *supp1XState);
77
78 TI_STATUS mainSecKeysOnly_reportAuthFailure(mainSec_t *pMainSec, EAuthStatus authStatus) ;
79 TI_STATUS mainSecKeysOnly_setAuthIdentity(mainSec_t *pMainSec, authIdentity_t *authIdentity);
80 /**
81 *
82 * rsn_mainSecSmKeysOnlyInit
83 *
84 * \b Description:
85 *
86 * Init main security state machine state machine
87 *
88 * \b ARGS:
89 *
90 * none
91 *
92 * \b RETURNS:
93 *
94 * TI_OK on success, TI_NOK otherwise.
95 *
96 * \sa
97 */
mainSecKeysOnly_config(mainSec_t * pMainSec,TRsnPaeConfig * pPaeConfig)98 TI_STATUS mainSecKeysOnly_config(mainSec_t *pMainSec,
99 TRsnPaeConfig *pPaeConfig)
100 {
101 TI_STATUS status;
102 /** Main 802.1X State Machine matrix */
103 fsm_actionCell_t mainSecKeysOnly_matrix[MAIN_SEC_KEYS_ONLY_NUM_STATES][MAIN_SEC_KEYS_ONLY_NUM_EVENTS] =
104 {
105 /* next state and actions for IDLE state */
106 {{MAIN_KO_STATE_START, (fsm_Action_t)mainSecKeysOnly_startIdle},
107 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_Nop},
108 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_unexpected},
109 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_unexpected}
110 },
111 /* next state and actions for START state */
112 {{MAIN_KO_STATE_START, (fsm_Action_t)mainSecKeysOnly_Nop},
113 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_stopStart},
114 {MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_keysCompleteStart},
115 {MAIN_KO_STATE_NONAUTHORIZED, (fsm_Action_t)mainSecKeysOnly_keysTOStart},
116 },
117 /* next state and actions for AUTHORIZED state */
118 {{MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
119 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_stopAuthorized},
120 {MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_Nop},
121 {MAIN_KO_STATE_AUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
122 },
123 /* next state and actions for NONAUTORIZED state */
124 {{MAIN_KO_STATE_START, (fsm_Action_t)mainSecKeysOnly_unexpected},
125 {MAIN_KO_STATE_IDLE, (fsm_Action_t)mainSecKeysOnly_stopNonAuthorized},
126 {MAIN_KO_STATE_NONAUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
127 {MAIN_KO_STATE_NONAUTHORIZED, (fsm_Action_t)mainSecKeysOnly_unexpected},
128 }
129 };
130
131 status = fsm_Config(pMainSec->pMainSecSm, &mainSecKeysOnly_matrix[0][0],
132 MAIN_SEC_KEYS_ONLY_NUM_STATES, MAIN_SEC_KEYS_ONLY_NUM_EVENTS, NULL, pMainSec->hOs);
133 if (status != TI_OK)
134 {
135 TRACE0(pMainSec->hReport, REPORT_SEVERITY_ERROR, "MAIN_SEC_SM: Error in configuring full SM\n");
136 return status;
137 }
138
139 pMainSec->currentState = MAIN_KO_STATE_IDLE;
140 pMainSec->start = mainSecKeysOnly_start;
141 pMainSec->stop = mainSecKeysOnly_stop;
142 pMainSec->reportKeysStatus = mainSecKeysOnly_reportKeysStatus;
143 pMainSec->getAuthState = (mainSecSm_getAuthState_t)mainSecKeysOnly_getAuthState;
144 pMainSec->reportReAuthenticate = (mainSecSmReportReauthentication_t)mainSecKeysOnly_unexpected;
145 pMainSec->setSessionKey = (mainSecSmSetSessionKey_t)mainSecKeysOnly_unexpected;
146 pMainSec->getSessionKey = (mainSecSmGetSessionKey_t)mainSecKeysOnly_unexpected;
147 pMainSec->reportAuthStatus = (mainSecSmReportAuthStatus_t)mainSecKeysOnly_unexpected;
148 pMainSec->getAuthIdentity = (mainSecSm_getAuthIdentity_t)mainSecKeysOnly_unexpected;
149 pMainSec->setAuthIdentity = (mainSecSm_getAuthIdentity_t)mainSecKeysOnly_setAuthIdentity;
150 pMainSec->reportAuthFailure = (mainSecSm_reportAuthFailure_t)mainSecKeysOnly_reportAuthFailure;
151
152 TRACE0(pMainSec->hReport, REPORT_SEVERITY_INFORMATION, "mainSecKeysOnly_config\n");
153
154 return TI_OK;
155 }
156
157 /**
158 *
159 * mainSecSmNull_Start
160 *
161 * \b Description:
162 *
163 * Start the NULL main security SM. Reports success to the rsn module immediately.
164 *
165 * \b ARGS:
166 *
167 * none
168 *
169 * \b RETURNS:
170 *
171 * TI_OK on success, TI_NOK otherwise.
172 *
173 * \sa
174 */
mainSecKeysOnly_start(mainSec_t * pMainSec)175 TI_STATUS mainSecKeysOnly_start(mainSec_t *pMainSec)
176 {
177 TI_STATUS status;
178
179 status = fsm_Event(pMainSec->pMainSecSm, &pMainSec->currentState, MAIN_KO_EVENT_START, pMainSec);
180
181 return status;
182 }
183
184 /**
185 *
186 * mainSecSmNull_Stop
187 *
188 * \b Description:
189 *
190 * Start the NULL main security SM. Reports success to the rsn module immediately.
191 *
192 * \b ARGS:
193 *
194 * none
195 *
196 * \b RETURNS:
197 *
198 * TI_OK on success, TI_NOK otherwise.
199 *
200 * \sa
201 */
mainSecKeysOnly_stop(mainSec_t * pMainSec)202 TI_STATUS mainSecKeysOnly_stop(mainSec_t *pMainSec)
203 {
204 TI_STATUS status;
205
206 status = fsm_Event(pMainSec->pMainSecSm, &pMainSec->currentState, MAIN_KO_EVENT_STOP, pMainSec);
207
208 return status;
209 }
210
211 /**
212 *
213 * mainSecSmNull_Stop
214 *
215 * \b Description:
216 *
217 * Start the NULL main security SM. Reports success to the rsn module immediately.
218 *
219 * \b ARGS:
220 *
221 * none
222 *
223 * \b RETURNS:
224 *
225 * TI_OK on success, TI_NOK otherwise.
226 *
227 * \sa
228 */
mainSecKeysOnly_reportKeysStatus(mainSec_t * pMainSec,TI_STATUS keysStatus)229 TI_STATUS mainSecKeysOnly_reportKeysStatus(mainSec_t *pMainSec, TI_STATUS keysStatus)
230 {
231 TI_STATUS status;
232
233 pMainSec->data.status = keysStatus;
234
235 if (keysStatus == TI_OK)
236 {
237 status = fsm_Event(pMainSec->pMainSecSm, &pMainSec->currentState, MAIN_KO_EVENT_KEYS_COMPLETE, pMainSec);
238 } else {
239 TRACE0(pMainSec->hReport, REPORT_SEVERITY_ERROR, "MAIN_SEC_SM: Error in Keys\n");
240 status = TI_OK;
241 }
242
243 return status;
244 }
245
246 /**
247 *
248 * mainSecSmNull_setKey
249 *
250 * \b Description:
251 *
252 * Start the NULL main security SM. Reports success to the rsn module immediately.
253 *
254 * \b ARGS:
255 *
256 * none
257 *
258 * \b RETURNS:
259 *
260 * TI_OK on success, TI_NOK otherwise.
261 *
262 * \sa
263 */
mainSecKeysOnly_setSessionKey(mainSec_t * pMainSec,TI_UINT8 * pKey,TI_UINT8 keyLen)264 TI_STATUS mainSecKeysOnly_setSessionKey(mainSec_t *pMainSec, TI_UINT8* pKey, TI_UINT8 keyLen)
265 {
266 os_memoryCopy(pMainSec->hOs, pMainSec->sessionKey, pKey, keyLen);
267 pMainSec->sessionKeyLen = keyLen;
268
269 return TI_OK;
270 }
271
272 /**
273 *
274 * mainSecSmNull_setKey
275 *
276 * \b Description:
277 *
278 * Start the NULL main security SM. Reports success to the rsn module immediately.
279 *
280 * \b ARGS:
281 *
282 * none
283 *
284 * \b RETURNS:
285 *
286 * TI_OK on success, TI_NOK otherwise.
287 *
288 * \sa
289 */
mainSecKeysOnly_getSessionKey(mainSec_t * pMainSec,TI_UINT8 * pKey,TI_UINT32 * pKeyLen)290 TI_STATUS mainSecKeysOnly_getSessionKey(mainSec_t *pMainSec, TI_UINT8* pKey, TI_UINT32* pKeyLen)
291 {
292 os_memoryCopy(pMainSec->hOs, pKey, pMainSec->sessionKey, pMainSec->sessionKeyLen);
293 *pKeyLen = pMainSec->sessionKeyLen;
294
295 return TI_OK;
296 }
297
298
299
300 /* State machine implementation functions */
301
mainSecKeysOnly_startIdle(struct _mainSec_t * pMainSec)302 TI_STATUS mainSecKeysOnly_startIdle(struct _mainSec_t *pMainSec)
303 {
304 TI_STATUS status = TI_OK;
305
306 TRACE0(pMainSec->hReport, REPORT_SEVERITY_SM, "MAIN_SEC_SM: mainSecKeysOnly_StartIdle...\n");
307 status = pMainSec->pMainKeys->start(pMainSec->pMainKeys);
308
309 return status;
310 }
311
mainSecKeysOnly_stopStart(struct _mainSec_t * pMainSec)312 TI_STATUS mainSecKeysOnly_stopStart(struct _mainSec_t *pMainSec)
313 {
314 TI_STATUS status = TI_OK;
315
316 TRACE0(pMainSec->hReport, REPORT_SEVERITY_SM, "MAIN_SEC_SM: mainSecKeysOnly_StopStart...\n");
317 status = pMainSec->pMainKeys->stop(pMainSec->pMainKeys);
318
319 return status;
320 }
321
mainSecKeysOnly_keysCompleteStart(struct _mainSec_t * pMainSec)322 TI_STATUS mainSecKeysOnly_keysCompleteStart(struct _mainSec_t *pMainSec)
323 {
324 TI_STATUS status = TI_OK;
325
326 TRACE0(pMainSec->hReport, REPORT_SEVERITY_SM, "MAIN_SEC_SM: mainSecKeysOnly_KeysCompleteAuthenticated...\n");
327 status = pMainSec->pParent->reportStatus(pMainSec->pParent, pMainSec->data.status);
328
329 return(status);
330 }
331
mainSecKeysOnly_keysTOStart(struct _mainSec_t * pMainSec)332 TI_STATUS mainSecKeysOnly_keysTOStart(struct _mainSec_t *pMainSec)
333 {
334 TI_STATUS status = TI_OK;
335
336 return(status);
337 }
338
mainSecKeysOnly_stopAuthorized(struct _mainSec_t * pMainSec)339 TI_STATUS mainSecKeysOnly_stopAuthorized(struct _mainSec_t *pMainSec)
340 {
341 TI_STATUS status = TI_OK;
342
343 TRACE0(pMainSec->hReport, REPORT_SEVERITY_SM, "MAIN_SEC_SM: mainSecKeysOnly_StopAuthorized...\n");
344 status = pMainSec->pMainKeys->stop(pMainSec->pMainKeys);
345
346 return(status);
347 }
348
mainSecKeysOnly_stopNonAuthorized(struct _mainSec_t * pMainSec)349 TI_STATUS mainSecKeysOnly_stopNonAuthorized(struct _mainSec_t *pMainSec)
350 {
351 TI_STATUS status = TI_OK;
352
353 TRACE0(pMainSec->hReport, REPORT_SEVERITY_SM, "MAIN_SEC_SM: mainSecKeysOnly_StopNonAuthorized...\n");
354 status = pMainSec->pMainKeys->stop(pMainSec->pMainKeys);
355
356 return(status);
357 }
358
359 /* state machine action functions */
360
mainSecKeysOnly_Nop(void * pData)361 TI_STATUS mainSecKeysOnly_Nop(void* pData)
362 {
363 return(TI_OK);
364 }
365
mainSecKeysOnly_unexpected(void * pData)366 TI_STATUS mainSecKeysOnly_unexpected(void* pData)
367 {
368 return TI_NOK;
369 }
370
371 /**
372 *
373 * mainSecKeysOnly_getAuthState: \n
374 *
375 * \b Description:
376 *
377 * Get authentication state from supp1x SM.
378 *
379 * \b ARGS:
380 *
381 * I - pMainSec - pMainSec SM context \n
382 * I - authIdentity - pointer to authentication state \n
383 *
384 * \b RETURNS:
385 *
386 * TI_OK if successful, TI_NOK otherwise.
387 *
388 * \sa
389 */
390
mainSecKeysOnly_getAuthState(mainSec_t * pMainSec,TIWLN_SECURITY_STATE * secState)391 TI_STATUS mainSecKeysOnly_getAuthState(mainSec_t *pMainSec, TIWLN_SECURITY_STATE *secState)
392 {
393 switch (pMainSec->currentState)
394 {
395 case MAIN_KO_STATE_START:
396 *secState = eSecurityStateAuthenticating;
397 break;
398
399 case MAIN_KO_STATE_AUTHORIZED:
400 *secState = eSecurityStateAuthenticated;
401 break;
402
403 case MAIN_KO_STATE_NONAUTHORIZED:
404 *secState = eSecurityStateNotAuthenticated ;
405 break;
406
407 default:
408 *secState = eSecurityStateHalted;
409 break;
410 }
411
412 return TI_OK;
413
414 } /*mainSecKeysOnly_getAuthState*/
415
416
mainSecKeysOnly_reportAuthFailure(mainSec_t * pMainSec,EAuthStatus authStatus)417 TI_STATUS mainSecKeysOnly_reportAuthFailure(mainSec_t *pMainSec, EAuthStatus authStatus)
418 {
419
420 return TI_OK;
421 }
422
423
mainSecKeysOnly_setAuthIdentity(mainSec_t * pMainSec,authIdentity_t * authIdentity)424 TI_STATUS mainSecKeysOnly_setAuthIdentity(mainSec_t *pMainSec, authIdentity_t *authIdentity)
425 {
426
427 return TI_OK;
428 }
429