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