1 /*
2 * keyDerive.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 keyDeriveSM.c
35 * \brief station unicast key SM implementation
36 *
37 * \see keyDeriveSM.h
38 */
39
40 /****************************************************************************
41 * *
42 * MODULE: station unicast key SM *
43 * PURPOSE: station unicast key SM implementation *
44 * *
45 ****************************************************************************/
46
47 #define __FILE_ID__ FILE_ID_28
48 #include "osApi.h"
49 #include "report.h"
50 #include "rsnApi.h"
51
52 #include "keyDerive.h"
53 #include "keyDeriveWep.h"
54 #include "keyDeriveTkip.h"
55 #include "keyDeriveAes.h"
56 #ifdef XCC_MODULE_INCLUDED
57 #include "keyDeriveCkip.h"
58 #endif
59
60 /**
61 *
62 * Function - Init KEY Parser module.
63 *
64 * \b Description:
65 *
66 * Called by RSN Manager.
67 * Registers the function 'rsn_KeyDeriveRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event.
68 *
69 * \b ARGS:
70 *
71 *
72 * \b RETURNS:
73 *
74 * TI_STATUS - 0 on success, any other value on failure.
75 *
76 */
77
keyDerive_create(TI_HANDLE hOs)78 keyDerive_t* keyDerive_create(TI_HANDLE hOs)
79 {
80 keyDerive_t *pKeyDerive;
81
82 /* allocate key parser context memory */
83 pKeyDerive = (keyDerive_t*)os_memoryAlloc(hOs, sizeof(keyDerive_t));
84 if (pKeyDerive == NULL)
85 {
86 return NULL;
87 }
88
89 os_memoryZero(hOs, pKeyDerive, sizeof(keyDerive_t));
90
91 pKeyDerive->hOs = hOs;
92
93 return pKeyDerive;
94 }
95
96 /**
97 *
98 * Function - Init KEY Parser module.
99 *
100 * \b Description:
101 *
102 * Called by RSN Manager.
103 * Registers the function 'rsn_KeyDeriveRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event.
104 *
105 * \b ARGS:
106 *
107 *
108 * \b RETURNS:
109 *
110 * TI_STATUS - 0 on success, any other value on failure.
111 *
112 */
113
keyDerive_unload(struct _keyDerive_t * pKeyDerive)114 TI_STATUS keyDerive_unload(struct _keyDerive_t *pKeyDerive)
115 {
116 /* free key parser context memory */
117 os_memoryFree(pKeyDerive->hOs, pKeyDerive, sizeof(keyDerive_t));
118
119 return TI_OK;
120 }
121
122 /**
123 *
124 * Function - Init KEY Parser module.
125 *
126 * \b Description:
127 *
128 * Called by RSN Manager.
129 * Registers the function 'rsn_KeyDeriveRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event.
130 *
131 * \b ARGS:
132 *
133 *
134 * \b RETURNS:
135 *
136 * TI_STATUS - 0 on success, any other value on failure.
137 *
138 */
139
keyDerive_config(struct _keyDerive_t * pKeyDerive,ECipherSuite cipher,struct _mainKeys_t * pMainKeys,TI_HANDLE hReport,TI_HANDLE hOs)140 TI_STATUS keyDerive_config(struct _keyDerive_t *pKeyDerive,
141 ECipherSuite cipher,
142 struct _mainKeys_t *pMainKeys,
143 TI_HANDLE hReport,
144 TI_HANDLE hOs)
145 {
146
147 TI_STATUS status = TI_NOK;
148
149 pKeyDerive->hReport = hReport;
150 pKeyDerive->hOs = hOs;
151 pKeyDerive->pMainKeys = pMainKeys;
152
153 switch (cipher)
154 {
155 case TWD_CIPHER_NONE:
156 status = keyDeriveNone_config(pKeyDerive);
157 break;
158 case TWD_CIPHER_WEP:
159 case TWD_CIPHER_WEP104:
160 status = keyDeriveWep_config(pKeyDerive);
161 break;
162 case TWD_CIPHER_TKIP:
163 status = keyDeriveTkip_config(pKeyDerive);
164 break;
165 #ifdef XCC_MODULE_INCLUDED
166 case TWD_CIPHER_CKIP:
167 status = keyDeriveCkip_config(pKeyDerive);
168 break;
169 #endif
170
171 case TWD_CIPHER_AES_CCMP:
172 status = keyDeriveAes_config(pKeyDerive);
173 break;
174 default:
175 return TI_NOK;
176 }
177
178 return status;
179 }
180
181
182
183