• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * unicastKey802_1x.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 unicastKey802_1x.c
35  * \brief station unicast key 802_1x implementation
36  *
37  * \see unicastKey802_1x.h
38 */
39 
40 /****************************************************************************
41  *                                                                          *
42  *   MODULE:	station unicast key 802_1x		                                *
43  *   PURPOSE:   station unicast key 802_1x implementation						*
44  *                                                                          *
45  ****************************************************************************/
46 
47 #define __FILE_ID__  FILE_ID_44
48 #include "osApi.h"
49 #include "report.h"
50 #include "rsnApi.h"
51 
52 #include "unicastKey802_1x.h"
53 #include "mainKeysSm.h"
54 
55 /** number of states in the state machine */
56 #define	UCAST_KEY_802_1X_MAX_NUM_STATES		3
57 
58 /** number of events in the state machine */
59 #define	UCAST_KEY_802_1X_MAX_NUM_EVENTS		4
60 
61 
62 TI_STATUS unicastKey802_1x_start(struct _unicastKey_t *pUnicastKey);
63 
64 TI_STATUS unicastKey802_1x_stop(struct _unicastKey_t *pUnicastKey);
65 
66 TI_STATUS unicastKey802_1x_recvSuccess(struct _unicastKey_t *pUnicastKey,
67 									encodedKeyMaterial_t *pEncodedKeyMaterial);
68 
69 TI_STATUS unicastKey802_1x_recvFailure(struct _unicastKey_t *pUnicastKey);
70 
71 TI_STATUS unicastKey802_1x_distribute(struct _unicastKey_t *pUnicastKey);
72 
73 TI_STATUS unicastKey802_1x_redistribute(struct _unicastKey_t *pUnicastKey);
74 
75 TI_STATUS unicastKey802_1x_event(struct _unicastKey_t *pUnicastKey,
76 							  TI_UINT8 event,
77 							  void *pData);
78 
79 
80 
81 /**
82 *
83 * Function  - Config KEY Parser module.
84 *
85 * \b Description:
86 *
87 * Called by RSN Manager.
88 * Registers the function 'rsn_UnicastKeyRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event.
89 *
90 * \b ARGS:
91 *
92 *
93 * \b RETURNS:
94 *
95 *  TI_STATUS - 0 on success, any other value on failure.
96 *
97 */
98 
unicastKey802_1x_config(struct _unicastKey_t * pUnicastKey)99 TI_STATUS unicastKey802_1x_config(struct _unicastKey_t *pUnicastKey)
100 {
101 	TI_STATUS		status = TI_NOK;
102 
103 	/** 802.1X Station unicast key State Machine matrix */
104 	fsm_actionCell_t    unicastKey802_1x_matrix[UCAST_KEY_802_1X_NUM_STATES][UCAST_KEY_802_1X_NUM_EVENTS] =
105 	{
106 		/* next state and actions for IDLE state */
107 		{	{UCAST_KEY_802_1X_STATE_START, (fsm_Action_t)unicastKeySmNop},
108 			{UCAST_KEY_802_1X_STATE_IDLE, (fsm_Action_t)unicastKeySmNop},
109 			{UCAST_KEY_802_1X_STATE_IDLE, (fsm_Action_t)unicastKeySmNop},
110 			{UCAST_KEY_802_1X_STATE_IDLE, (fsm_Action_t)unicastKeySmUnexpected}
111 		},
112 
113 		/* next state and actions for START state */
114 		{	{UCAST_KEY_802_1X_STATE_START, (fsm_Action_t)unicastKeySmUnexpected},
115 			{UCAST_KEY_802_1X_STATE_IDLE, (fsm_Action_t)unicastKeySmNop},
116 			{UCAST_KEY_802_1X_STATE_COMPLETE, (fsm_Action_t)unicastKey802_1x_distribute},
117 			{UCAST_KEY_802_1X_STATE_START, (fsm_Action_t)unicastKeySmNop}
118 		},
119 
120 		/* next state and actions for COMPLETE state */
121 		{	{UCAST_KEY_802_1X_STATE_COMPLETE, (fsm_Action_t)unicastKeySmUnexpected},
122 			{UCAST_KEY_802_1X_STATE_IDLE, (fsm_Action_t)unicastKeySmNop},
123 			{UCAST_KEY_802_1X_STATE_COMPLETE, (fsm_Action_t)unicastKey802_1x_distribute},
124 			{UCAST_KEY_802_1X_STATE_COMPLETE, (fsm_Action_t)unicastKeySmUnexpected}
125 		}
126 	};
127 
128 
129 	pUnicastKey->start = unicastKey802_1x_start;
130 	pUnicastKey->stop = unicastKey802_1x_stop;
131 	pUnicastKey->recvFailure = unicastKey802_1x_recvFailure;
132 	pUnicastKey->recvSuccess = unicastKey802_1x_recvSuccess;
133 
134 	pUnicastKey->currentState = UCAST_KEY_802_1X_STATE_IDLE;
135 
136 	status = fsm_Config(pUnicastKey->pUcastKeySm,
137 						&unicastKey802_1x_matrix[0][0],
138 						UCAST_KEY_802_1X_NUM_STATES,
139 						UCAST_KEY_802_1X_NUM_EVENTS,
140 						NULL, pUnicastKey->hOs);
141 
142 
143 	return status;
144 }
145 
146 
147 
148 /**
149 *
150 * unicastKey802_1x_event
151 *
152 * \b Description:
153 *
154 * 802.1x station unicast key state machine transition function
155 *
156 * \b ARGS:
157 *
158 *  I/O - currentState - current state in the state machine\n
159 *  I   - event - specific event for the state machine\n
160 *  I   - pData - Data for state machine action function\n
161 *
162 * \b RETURNS:
163 *
164 *  TI_OK on success, TI_NOK otherwise.
165 *
166 * \sa
167 */
unicastKey802_1x_event(struct _unicastKey_t * pUnicastKey,TI_UINT8 event,void * pData)168 TI_STATUS unicastKey802_1x_event(struct _unicastKey_t *pUnicastKey, TI_UINT8 event, void *pData)
169 {
170 	TI_STATUS 		status;
171 	TI_UINT8		nextState;
172 
173 	status = fsm_GetNextState(pUnicastKey->pUcastKeySm, pUnicastKey->currentState, event, &nextState);
174 	if (status != TI_OK)
175 	{
176 TRACE0(pUnicastKey->hReport, REPORT_SEVERITY_ERROR, "UNICAST_KEY_802_1x: ERROR: failed getting next state\n");
177 		return TI_NOK;
178 	}
179 
180 TRACE3(pUnicastKey->hReport, REPORT_SEVERITY_INFORMATION, "STATION_UNICAST_KEY_802_1x: <currentState = %d, event = %d> --> nextState = %d\n", pUnicastKey->currentState, event, nextState);
181 
182 	status = fsm_Event(pUnicastKey->pUcastKeySm, &pUnicastKey->currentState, event, pData);
183 
184 	return status;
185 }
186 
187 
188 /**
189 *
190 * unicastKey802_1x_start
191 *
192 * \b Description:
193 *
194 * START event handler
195 *
196 * \b ARGS:
197 *
198 *  I   - pCtrlB - station control block  \n
199 *
200 * \b RETURNS:
201 *
202 *  TI_OK on success, TI_NOK otherwise.
203 *
204 * \sa unicastKey802_1x_stop()
205 */
unicastKey802_1x_start(struct _unicastKey_t * pUnicastKey)206 TI_STATUS unicastKey802_1x_start(struct _unicastKey_t *pUnicastKey)
207 {
208 	TI_STATUS  status;
209 
210 	status = unicastKey802_1x_event(pUnicastKey, UCAST_KEY_802_1X_EVENT_START, pUnicastKey);
211 
212 	return status;
213 }
214 
215 
216 /**
217 *
218 * unicastKey802_1x_stop
219 *
220 * \b Description:
221 *
222 * START event handler
223 *
224 * \b ARGS:
225 *
226 *  I   - pCtrlB - station control block  \n
227 *
228 * \b RETURNS:
229 *
230 *  TI_OK on success, TI_NOK otherwise.
231 *
232 * \sa unicastKey802_1x_start()
233 */
unicastKey802_1x_stop(struct _unicastKey_t * pUnicastKey)234 TI_STATUS unicastKey802_1x_stop(struct _unicastKey_t *pUnicastKey)
235 {
236 	TI_STATUS  status;
237 
238 	status = unicastKey802_1x_event(pUnicastKey, UCAST_KEY_802_1X_EVENT_STOP, pUnicastKey);
239 
240 	return status;
241 }
242 
243 
244 /**
245 *
246 * unicastKey802_1x_recvSuccess
247 *
248 * \b Description:
249 *
250 * SUCCESS event handler
251 *
252 * \b ARGS:
253 *
254 *  I   - pCtrlB - station control block  \n
255 *  I   - pEncodedKeyMaterial - Encoded key material \n
256 *
257 * \b RETURNS:
258 *
259 *  TI_OK on success, TI_NOK otherwise.
260 *
261 */
unicastKey802_1x_recvSuccess(struct _unicastKey_t * pUnicastKey,encodedKeyMaterial_t * pEncodedKeyMaterial)262 TI_STATUS unicastKey802_1x_recvSuccess(struct _unicastKey_t *pUnicastKey, encodedKeyMaterial_t *pEncodedKeyMaterial)
263 {
264 	TI_STATUS  status;
265 
266 	pUnicastKey->data.pEncodedKeyMaterial = pEncodedKeyMaterial;
267 
268 	status = unicastKey802_1x_event(pUnicastKey, UCAST_KEY_802_1X_EVENT_SUCCESS, pUnicastKey);
269 
270 	return status;
271 }
272 
273 
274 /**
275 *
276 * unicastKey802_1x_recvFailure
277 *
278 * \b Description:
279 *
280 * FAILURE event handler
281 *
282 * \b ARGS:
283 *
284 *  I   - pCtrlB - station control block  \n
285 *
286 * \b RETURNS:
287 *
288 *  TI_OK on success, TI_NOK otherwise.
289 *
290 */
unicastKey802_1x_recvFailure(struct _unicastKey_t * pUnicastKey)291 TI_STATUS unicastKey802_1x_recvFailure(struct _unicastKey_t *pUnicastKey)
292 {
293 	TI_STATUS  status;
294 
295 	status = unicastKey802_1x_event(pUnicastKey, UCAST_KEY_802_1X_EVENT_FAILURE, pUnicastKey);
296 
297 	return status;
298 }
299 
300 
301 /**
302 *
303 * unicastKey802_1x_distribute
304 *
305 * \b Description:
306 *
307 * Distribute unicast key material to the driver and report the main key SM on unicast complete.
308 *
309 * \b ARGS:
310 *
311 *  I   - pData - Encoded key material  \n
312 *
313 * \b RETURNS:
314 *
315 *  TI_OK on success, TI_NOK otherwise.
316 */
unicastKey802_1x_distribute(struct _unicastKey_t * pUnicastKey)317 TI_STATUS unicastKey802_1x_distribute(struct _unicastKey_t *pUnicastKey)
318 {
319 	TI_STATUS  status=TI_NOK;
320 
321 	if (pUnicastKey->pKeyDerive->derive!=NULL)
322     {
323 	status = pUnicastKey->pKeyDerive->derive(pUnicastKey->pKeyDerive,
324 												   pUnicastKey->data.pEncodedKeyMaterial);
325     }
326 	if (status != TI_OK)
327 	{
328 		return TI_NOK;
329 	}
330 
331 	if (pUnicastKey->pParent->setDefaultKeyId!=NULL)
332     {
333 	status = pUnicastKey->pParent->setDefaultKeyId(pUnicastKey->pParent,
334 												   (TI_UINT8)pUnicastKey->data.pEncodedKeyMaterial->keyId);
335     }
336 	if (status != TI_OK)
337 	{
338 		return status;
339 	}
340 
341 	if (pUnicastKey->pParent->reportUcastStatus!=NULL)
342     {
343 	status = pUnicastKey->pParent->reportUcastStatus(pUnicastKey->pParent, TI_OK);
344     }
345 
346 	return status;
347 }
348