cm-kernel /drivers/net/wireless/tiwlan1251/common/src/hal/security/whalWpa.c

Language C Lines 325
MD5 Hash 88972f7a30dcc6c15728da39a1c26ec2 Estimated Cost $3,351 (why?)
Repository git://github.com/CyanogenMod/cm-kernel.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/****************************************************************************
**+-----------------------------------------------------------------------+**
**|                                                                       |**
**| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
**| All rights reserved.                                                  |**
**|                                                                       |**
**| Redistribution and use in source and binary forms, with or without    |**
**| modification, are permitted provided that the following conditions    |**
**| are met:                                                              |**
**|                                                                       |**
**|  * Redistributions of source code must retain the above copyright     |**
**|    notice, this list of conditions and the following disclaimer.      |**
**|  * Redistributions in binary form must reproduce the above copyright  |**
**|    notice, this list of conditions and the following disclaimer in    |**
**|    the documentation and/or other materials provided with the         |**
**|    distribution.                                                      |**
**|  * Neither the name Texas Instruments nor the names of its            |**
**|    contributors may be used to endorse or promote products derived    |**
**|    from this software without specific prior written permission.      |**
**|                                                                       |**
**| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
**| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
**| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
**| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
**| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
**| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
**| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
**| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
**| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
**| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
**| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
**|                                                                       |**
**+-----------------------------------------------------------------------+**
****************************************************************************/

#include "802_11Defs.h"
#include "Ethernet.h"
#include "whalCommon.h"
#include "whalCtrl_api.h"
#include "whalCtrl.h"
#include "whalSecurity.h"
#include "whalWpa.h"



#undef WHAL_WPA_MODULE_LOG_PRINT_ENABLE

static void	whal_MsduContentDump (TI_HANDLE hWhalWpa, mem_MSDU_T* pMsdu, char* str);

/*
 * ----------------------------------------------------------------------------
 * Function : whal_MsduContentDump
 *
 * Input    : 
 * Output   :									 
 * Process  : 
 * Note(s)  :
 * -----------------------------------------------------------------------------
 */
static void	whal_MsduContentDump (TI_HANDLE hWhalWpa, mem_MSDU_T* pMsdu, char *str)
{	
#ifdef WHAL_WPA_MODULE_LOG_PRINT_ENABLE
    UINT32 msduLen;
	mem_BD_T* pCurrBd;
	WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa;
    
	WLAN_REPORT_INFORMATION(pWhalWpa->hReport, HAL_SECURITY_MODULE_LOG,  
					("%s totalLen=%d^^^^^ \n", str, pMsdu->dataLen));
	
	msduLen = pMsdu->dataLen;
	pCurrBd = pMsdu->firstBDPtr;
	
	while ((msduLen >= 0)&&(pCurrBd!=NULL))
	{
		WLAN_REPORT_INFORMATION(pWhalWpa->hReport, HAL_SECURITY_MODULE_LOG,  
			("\nBdLen = %d\n", pCurrBd->length));
		
		HexDumpData((UINT8*)(pCurrBd->data+pCurrBd->dataOffset), pCurrBd->length);
	
		msduLen -=  pCurrBd->length;
		pCurrBd =  pCurrBd->nextBDPtr;
	}

#endif /*WHAL_WPA_MODULE_LOG_PRINT_ENABLE*/
}
/*
 * ----------------------------------------------------------------------------
 * Function : whalWpa_Create
 *
 * Input    : 
 * Output   :
 * Process  : Create the WPA - security sub-module.
 * Note(s)  :
 * -----------------------------------------------------------------------------
 */
TI_HANDLE whalWpa_Create (TI_HANDLE hOs, TI_HANDLE hWhalCtrl)
{
	WHAL_WPA* pWhalWpa;

	pWhalWpa = (WHAL_WPA *)os_memoryAlloc (hOs, sizeof(WHAL_WPA));
	if (pWhalWpa == NULL)
		return NULL;

	os_memoryZero (hOs, (void *)pWhalWpa, sizeof(WHAL_WPA));

	pWhalWpa->pWhalCtrl = (WHAL_CTRL *)hWhalCtrl;
	pWhalWpa->hOs = hOs;
	
	return((TI_HANDLE)pWhalWpa);
}

/*
 * ----------------------------------------------------------------------------
 * Function : whalWpa_Config
 *
 * Input    : 
 * Output   :
 * Process  : Configure the WPA - security sub-module.
 * Note(s)  :
 * -----------------------------------------------------------------------------
 */
int whalWpa_Config (TI_HANDLE hWhalWpa, whalWpa_config_t* pWhalWpaCfg)
{
	WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa;

	pWhalWpa->hReport = pWhalWpaCfg->hReport;
	pWhalWpa->hMemMgr = pWhalWpaCfg->hMemMgr;

	return (OK);
}			    
						    
/*
 * ----------------------------------------------------------------------------
 * Function : whalWpa_MpduListFieldsAdd
 *
 * Input    : Transmitted MSDU
 * Output   : MSDU after padding for TKIP EIV or AES RSN fields.
 * Process  : Shift LLC+SNAP apart from WLAN header to add padding for EIV/RSN field. 
 *			  	
 * Note(s)  : An LLC+SNAP is located just after the 802.11 header	
 *			  	 on the first MPDU header only.
 * -----------------------------------------------------------------------------
 */
int whalWpa_MpduListFieldsAdd (TI_HANDLE hWhalWpa, mem_MSDU_T* pMpduList)
{
	WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa;
	UINT32 AddFieldSize;
	UINT8 tempbuff[WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN];

	/* 
	 * Check TX key type
	 * In case of TKIP we need to add bytes for IV
	 * For AES  we need to add 8 bytes
	 * For unified AES - always add 8 bytes
	 */
	if(pWhalWpa->currTxKeyType == TKIP_KEY)
	{
		AddFieldSize = IV_FIELD_SIZE;
	}
	else
	if(pWhalWpa->currTxKeyType == AES_KEY)
	{
		AddFieldSize = AES_AFTER_HEADER_FIELD_SIZE;
	}
	else
		return OK;

	/* Check if LLC+SNAP exist in the buffer of the header. */
	if ( (memMgr_MsduFirstLen(pMpduList) == pMpduList->headerLen+WLAN_SNAP_HDR_LEN) || 
		 (memMgr_MsduFirstLen(pMpduList) == pMpduList->headerLen+WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN ) )
	{
		UINT8 *pHeaderEnd =	(UINT8*)( (UINT32)memMgr_BufData(pMpduList->firstBDPtr) +
			memMgr_BufOffset(pMpduList->firstBDPtr) + pMpduList->headerLen );

		/* Copy LLC+SNAP to temp buffer. */
		os_memoryCopy (pWhalWpa->hOs, (void *)tempbuff, (void *)pHeaderEnd, WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN);

		/* Copy LLC+SNAP from temp buffer back to BD with required padding. */
		os_memoryCopy (pWhalWpa->hOs, (void *)(pHeaderEnd + AddFieldSize), (void *)tempbuff, WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN);
	  
		/* Clear padding field. */
		os_memoryZero (pWhalWpa->hOs, (void *)pHeaderEnd, AddFieldSize);
	}
	else
	{
		WLAN_REPORT_WARNING(pWhalWpa->hReport, HAL_SECURITY_MODULE_LOG,  
		      ("whalWpa_MpduListFieldsAdd:  ERROR: First Buffer Length Is Illegal !!!!!! \n"));
	}

	/* Update BD and MSDU sizes to include the padding. */
	memMgr_MsduFirstLen(pMpduList) += AddFieldSize;
	memMgr_MsduDataSize(pMpduList) += AddFieldSize;
		
	whal_MsduContentDump (pWhalWpa, pMpduList, "whalWpa_MpduListFieldsAdd: Exit (Tx Path) ");
	return (OK);			  
}

/*
 * ----------------------------------------------------------------------------
 * Function : whalWpa_KeyAdd
 *
 * Input    : 
 * Output   :									 
 * Process  : Add key to the HW.
 * Note(s)  :
 * -----------------------------------------------------------------------------
 */
int whalWpa_KeyAdd (TI_HANDLE hWhalWpa, securityKeys_t* pKey, void *CB_Func, TI_HANDLE CB_handle)
{
	WHAL_WPA* 		pWhalWpa = (WHAL_WPA *)hWhalWpa;
 
	/* Only WEP, TKIP, AES keys are handled*/
	switch (pKey->keyType)
	{
		case WEP_KEY:
			/* Configure the encKeys to the HW - default keys cache*/
			return (whal_hwCtrl_WepDefaultKeyAdd (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle));
		
		case TKIP_KEY:
			/* Set the REAL TKIP key into the TKIP key cache*/
			if (whal_hwCtrl_TkipMicMappingKeyAdd (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK)
				return (NOK);

			break;
		
		case AES_KEY:
			if (whal_hwCtrl_AesMappingKeyAdd (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK)
				return (NOK);
			break;
		
		default:
			return (NOK);
	}
	
	/* AES or TKIP key has been successfully added. Store the current */
	/* key type of the unicast (i.e. transmit !) key                  */
	if(!MAC_BROADCAST((&pKey->macAddress)))
	{
		pWhalWpa->currTxKeyType = pKey->keyType;
	}

	return (OK);
}

/*
 * ----------------------------------------------------------------------------
 * Function : whalWpa_KeyRemove
 *
 * Input    : 
 * Output   :									 
 * Process  : Add key to the HW.
 * Note(s)  :
 * -----------------------------------------------------------------------------
 */
int whalWpa_KeyRemove (TI_HANDLE hWhalWpa, securityKeys_t* pKey, void *CB_Func, TI_HANDLE CB_handle)
{
	WHAL_WPA* 		pWhalWpa = (WHAL_WPA *)hWhalWpa;

	/* Only WEP, TKIP, AES keys are handled*/
	switch (pKey->keyType)
	{
		case WEP_KEY:
			/* Configure the encKeys to the HW - default keys cache*/
			return (whal_hwCtrl_WepDefaultKeyRemove (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle));
		
		case TKIP_KEY:
			/* Configure the encKeys to the HW - mapping keys cache*/
			/* configure through SET_KEYS command */

			/* remove the TKIP key from the TKIP key cache*/
			if (whal_hwCtrl_TkipMicMappingKeyRemove (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK)
				return (NOK);

			break;
		
		case AES_KEY:
			if (whal_hwCtrl_AesMappingKeyRemove (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK)
				return (NOK);
			break;

		
		default:
			return (NOK);
	}
	
	return (OK);
}

/*
 * ----------------------------------------------------------------------------
 * Function : whalWpa_DefaultKeyIdSet
 *
 * Input    : 
 * Output   :									 
 * Process  : Configure the default key Id to the HW.
 * Note(s)  :
 * -----------------------------------------------------------------------------
 */
int whalWpa_DefaultKeyIdSet (TI_HANDLE hWhalWpa, UINT8 aKeyId, void *CB_Func, TI_HANDLE CB_handle)
{
	/* Do not configure the default key id to the HW, return OK to the caller*/
	return (OK);
}

/*
 * ----------------------------------------------------------------------------
 * Function : whalWpa_Destroy
 *
 * Input    : 
 * Output   :									 
 * Process  : Destroy the WPA - security sub-module.
 * Note(s)  :
 * -----------------------------------------------------------------------------
 */
int whalWpa_Destroy (TI_HANDLE hWhalWpa)
{
	WHAL_WPA *pWhalWpa = (WHAL_WPA *)hWhalWpa;

	if (pWhalWpa)
		os_memoryFree (pWhalWpa->hOs, pWhalWpa, sizeof(WHAL_WPA));
	
	return (OK);
}
Back to Top