import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / connectivity / combo / drv_wlan / mt6630 / wlan / mgmt / tkip_mic.c
CommitLineData
6fa3eb70
S
1/*
2** $Id: //Department/DaVinci/TRUNK/MT6620_WiFi_Firmware/mcu/wifi/mgmt/tkip_mic.c#7 $
3*/
4
5/*! \file tkip_sw.c
6 \brief This file include the tkip encrypted / decrypted mic function.
7*/
8/*******************************************************************************
9* Copyright (c) 2003-2004 Inprocomm, Inc.
10*
11* All rights reserved. Copying, compilation, modification, distribution
12* or any other use whatsoever of this material is strictly prohibited
13* except in accordance with a Software License Agreement with
14* Inprocomm, Inc.
15********************************************************************************
16*/
17/*
18** $Log: tkip_mic.c $
19**
20** 06 14 2013 eddie.chen
21** [BORA00002450] [WIFISYS][MT6630] New design for mt6630
22** 1. Add initial rate seting. 2. Add more information in sta command 3. add VHT info
23**
24** 10 04 2012 yarco.yang
25** [BORA00002189] [MT6630]Synch. Davinc 20120927 FW to Bora
26** .
27 *
28 * 06 12 2012 wh.su
29 * [WCXRP00001253] [MT6628 Wi-Fi][FW] Supporting the TKIP Tx/Rx fragment at Hotspot
30 * add the tx/rx fragment support for TKIP at hotspot,
31 *
32 * 10 12 2011 wh.su
33 * [WCXRP00001036] [MT6620 Wi-Fi][Driver][FW] Adding the 802.11w code for MFP
34 * Adding the code for 802.11w, default disable.
35 *
36 * 10 05 2011 eddie.chen
37 * [WCXRP00001027] [MT6628 Wi-Fi][Firmware/Driver] Tx fragmentation
38 * Tx fragment.
39 *
40 * 08 30 2011 chinglan.wang
41 * NULL
42 * Add the initial value in the tikipMicGen function.
43 *
44 * 08 10 2011 chinglan.wang
45 * [WCXRP00000903] [WiFi Direct][Driver] Support invitation request, invitation abort, invitation status, invitation indicate feature API
46 * .
47 *
48 * 11 15 2010 wh.su
49 * [WCXRP00000171] [MT6620 Wi-Fi][Driver] Add message check code same behavior as mt5921
50 * fixed the compiling error due the macro define change.
51 *
52 * 07 12 2010 cp.wu
53 *
54 * commit Wi-Fi firmware part for MT6620
55 *
56 * 03 03 2010 wh.su
57 * [BORA00000637][MT6620 Wi-Fi] [Bug] WPA2 pre-authentication timer not correctly initialize
58 * move the AIS specific variable for security to AIS specific structure.
59 *
60 * 01 27 2010 wh.su
61 * [BORA00000476][Wi-Fi][firmware] Add the security module initialize code
62 * add and fixed some security function.
63 *
64 * 12 18 2009 cm.chang
65 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
66 * .
67 *
68 * Dec 3 2009 mtk01088
69 * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
70 *
71** \main\maintrunk.MT5921\9 2008-10-22 10:59:31 GMT mtk01461
72** Update for lint diagnosis support
73** \main\maintrunk.MT5921\8 2008-08-28 20:44:03 GMT mtk01088
74** remove non-used code
75**
76** \main\maintrunk.MT5921\7 2008-05-30 14:39:01 GMT mtk01461
77** Fix compile warnning
78** \main\maintrunk.MT5921\6 2008-05-28 14:42:59 GMT mtk01088
79** fixed the caculate TKIP MIC error, also adjust the type of variable
80** \main\maintrunk.MT5921\5 2007-11-08 20:36:27 GMT mtk01088
81** add tkip tx gen mic code
82** \main\maintrunk.MT5921\4 2007-11-06 20:28:12 GMT mtk01088
83** check in the template tkip mic code
84** Revision 1.2 2007/07/17 12:59:45 MTK01088
85** add the tkip mic function
86**
87**
88*/
89/*******************************************************************************
90* C O M P I L E R F L A G S
91********************************************************************************
92*/
93
94/*******************************************************************************
95* E X T E R N A L R E F E R E N C E S
96********************************************************************************
97*/
98#include "precomp.h"
99
100/*******************************************************************************
101* C O N S T A N T S
102********************************************************************************
103*/
104
105/*******************************************************************************
106* D A T A T Y P E S
107********************************************************************************
108*/
109
110/*******************************************************************************
111* P U B L I C D A T A
112********************************************************************************
113*/
114
115/*******************************************************************************
116* P R I V A T E D A T A
117********************************************************************************
118*/
119
120/*******************************************************************************
121* M A C R O S
122********************************************************************************
123*/
124
125#define WLAN_MAC_MIC_LEN 8 /* length of TKIP and CCMP MIC field */
126
127#define MK16_TKIP(x, y) (((UINT_16) (x) << 8) | (UINT_16) (y))
128
129#define LO_8BITS(x) ((x) & 0x00ff) /* obtain low 8-bit from 16-bit value, OK */
130#define HI_8BITS(x) ((x) >> 8) /* obtain high 8-bit from 16-bit value, OK */
131
132#define ROTR32(x, y) (((x) >> (y)) | ((x) << (32 - (y))))
133#define ROTL32(x, y) (((x) << (y)) | ((x) >> (32 - (y))))
134#define ROTR16(x, y) (((x) >> (y)) | ((x) << (16 - (y))))
135#define ROTL16(x, y) (((x) << (y)) | ((x) >> (16 - (y))))
136
137#define XSWAP32(x) ((((x) & 0xFF00FF00) >> 8) | (((x) & 0x00FF00FF) << 8))
138
139#define SBOX(x) (tkipSBOX1[LO_8BITS(x)] ^ tkipSBOX2[HI_8BITS(x)]) /* obtain 16-bit entries SBOX form two 8-bit entries SBOX1 and SBOX2 */
140
141
142/*******************************************************************************
143* D A T A T Y P E S
144********************************************************************************
145*/
146
147/*******************************************************************************
148* P U B L I C D A T A
149********************************************************************************
150*/
151const UINT_16 tkipSBOX1[256] = {
152 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
153 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
154 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
155 0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
156 0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
157 0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
158 0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
159 0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
160 0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
161 0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
162 0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
163 0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
164 0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
165 0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
166 0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
167 0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
168 0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
169 0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
170 0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
171 0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
172 0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
173 0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
174 0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
175 0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
176 0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
177 0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
178 0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
179 0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
180 0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
181 0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
182 0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
183 0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A
184};
185
186const UINT_16 tkipSBOX2[256] = {
187 0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491,
188 0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC,
189 0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB,
190 0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B,
191 0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83,
192 0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A,
193 0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F,
194 0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA,
195 0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B,
196 0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713,
197 0xF5A6, 0x68B9, 0x0000, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6,
198 0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85,
199 0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411,
200 0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B,
201 0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1,
202 0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF,
203 0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E,
204 0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6,
205 0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B,
206 0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD,
207 0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8,
208 0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2,
209 0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049,
210 0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810,
211 0xD56F, 0x88F0, 0x6F4A, 0x725C, 0x2438, 0xF157, 0xC773, 0x5197,
212 0x23CB, 0x7CA1, 0x9CE8, 0x213E, 0xDD96, 0xDC61, 0x860D, 0x850F,
213 0x90E0, 0x427C, 0xC471, 0xAACC, 0xD890, 0x0506, 0x01F7, 0x121C,
214 0xA3C2, 0x5F6A, 0xF9AE, 0xD069, 0x9117, 0x5899, 0x273A, 0xB927,
215 0x38D9, 0x13EB, 0xB32B, 0x3322, 0xBBD2, 0x70A9, 0x8907, 0xA733,
216 0xB62D, 0x223C, 0x9215, 0x20C9, 0x4987, 0xFFAA, 0x7850, 0x7AA5,
217 0x8F03, 0xF859, 0x8009, 0x171A, 0xDA65, 0x31D7, 0xC684, 0xB8D0,
218 0xC382, 0xB029, 0x775A, 0x111E, 0xCB7B, 0xFCA8, 0xD66D, 0x3A2C
219};
220
221/*******************************************************************************
222* P R I V A T E D A T A
223********************************************************************************
224*/
225
226/*******************************************************************************
227* F U N C T I O N D E C L A R A T I O N S
228********************************************************************************
229*/
230
231/*******************************************************************************
232* F U N C T I O N S
233********************************************************************************
234*/
235
236/*----------------------------------------------------------------------------*/
237/*!
238* \brief TKIP Michael block function
239*
240* \param[in][out] pu4L - pointer to left value
241* \param[in][out] pu4PR - pointer to right value
242*
243* \return (none)
244*/
245/*----------------------------------------------------------------------------*/
246VOID tkipMicB(IN OUT PUINT_32 pu4L, IN OUT PUINT_32 pu4R)
247{
248 ASSERT(pu4L);
249 ASSERT(pu4R);
250
251 *pu4R = *pu4R ^ ROTL32(*pu4L, 17); /* r <- r ^ (l<<<17) */
252 *pu4L = (*pu4L + *pu4R); /* l <- (l+r) mod 2^32 */
253 *pu4R = *pu4R ^ XSWAP32(*pu4L); /* r <- r ^ XSWAP(l) */
254 *pu4L = (*pu4L + *pu4R); /* l <- (l+r) mod 2^32 */
255 *pu4R = *pu4R ^ ROTL32(*pu4L, 3); /* r <- r ^ (l<<<3) */
256 *pu4L = (*pu4L + *pu4R); /* l <- (l+r) mod 2^32 */
257 *pu4R = *pu4R ^ ROTR32(*pu4L, 2); /* r <- r ^ (l>>>2) */
258 *pu4L = (*pu4L + *pu4R); /* l <- (l+r) mod 2^32 */
259} /* tkipMicB */
260
261
262/*----------------------------------------------------------------------------*/
263/*!
264* \brief TKIP Michael generation function
265*
266* \param[in] pucMickey Pointer to MIC key
267* \param[in] pucData Pointer to message
268* \param[in] u4DataLen Message length, in byte(s)
269* \param[in] pucSa Pointer to source address SA
270* \param[in] pucDa Pointer to destination address DA
271* \param[in] ucPriority Priority of IEEE 802.11 traffic class
272* \param[out] pucMic Pointer to 64-bit MIC
273*
274* \return (none)
275*/
276/*----------------------------------------------------------------------------*/
277VOID
278tkipMicGen(IN PUCHAR pucMickey,
279 IN PUCHAR pucData,
280 IN UINT_32 u4DataLen,
281 IN PUCHAR pucSa, IN PUCHAR pucDa, IN UCHAR ucPriority, OUT PUCHAR pucMic)
282{
283
284 UINT_32 i;
285 UINT_32 l, r;
286 UINT_32 au4Msg[3];
287
288
289 ASSERT(pucMickey);
290 ASSERT(pucData);
291 ASSERT(pucSa);
292 ASSERT(pucDa);
293 ASSERT(pucMic);
294
295 WLAN_GET_FIELD_32(pucMickey, &l);
296 WLAN_GET_FIELD_32(pucMickey + 4, &r);
297
298 /* Michael message processing for DA and SA. */
299 WLAN_GET_FIELD_32(pucDa, &au4Msg[0]);
300 au4Msg[1] = ((UINT_32) pucDa[4]) | ((UINT_32) pucDa[5] << 8) |
301 ((UINT_32) pucSa[0] << 16) | ((UINT_32) pucSa[1] << 24);
302 WLAN_GET_FIELD_32(pucSa + 2, &au4Msg[2]);
303
304 for (i = 0; i < 3; i++) {
305 l = l ^ au4Msg[i];
306 tkipMicB(&l, &r);
307 }
308
309 /* Michael message processing for priority. */
310 au4Msg[0] = (UINT_32) ucPriority;
311
312 l = l ^ au4Msg[0];
313 tkipMicB(&l, &r);
314
315 /* Michael message processing for MSDU data playload except the last octets
316 which cannot be partitioned into a 32-bit word. */
317 for (i = 0; i < (UINT_32) u4DataLen / 4; i++) {
318 WLAN_GET_FIELD_32(pucData + i * 4, &au4Msg[0]);
319 l = l ^ au4Msg[0];
320 tkipMicB(&l, &r);
321 }
322
323 /* Michael message processing for the last uncomplete octets, if present,
324 and the padding. */
325 switch (u4DataLen & 3) {
326 case 1:
327 au4Msg[0] = ((UINT_32) pucData[u4DataLen - 1]) | 0x00005A00;
328 break;
329
330 case 2:
331 au4Msg[0] = ((UINT_32) pucData[u4DataLen - 2]) |
332 ((UINT_32) pucData[u4DataLen - 1] << 8) | 0x005A0000;
333 break;
334
335 case 3:
336 au4Msg[0] = ((UINT_32) pucData[u4DataLen - 3]) |
337 ((UINT_32) pucData[u4DataLen - 2] << 8) |
338 ((UINT_32) pucData[u4DataLen - 1] << 16) | 0x5A000000;
339 break;
340
341 default:
342 au4Msg[0] = 0x0000005A;
343 }
344 au4Msg[1] = 0;
345 for (i = 0; i < 2; i++) {
346 l = l ^ au4Msg[i];
347 tkipMicB(&l, &r);
348 }
349
350 /* return ( l, r ), i.e. MIC */
351 WLAN_SET_FIELD_32(pucMic, l);
352 WLAN_SET_FIELD_32(pucMic + 4, r);
353
354} /* tkipMicGen */
355
356
357/*----------------------------------------------------------------------------*/
358/*!
359* \brief this function decapsulate MSDU frame body( with MIC ) according
360* to IEEE 802.11i TKIP sepcification.
361*
362* \param[in] prAdapter Pointer to the adapter object data area.
363* \param[in] pucDa Pointer to destination address DA
364* \param[in] pucSa Pointer to source address SA
365* \param[in] ucPriority Priority of IEEE 802.11 traffic class
366* \param[in] pucPayload Pointer to message
367* \param[in] u2PayloadLen Message length, in byte(s)
368* \param[out] pucMic Pointer to 64-bit MIC
369*
370* \retval NONE
371*/
372/*----------------------------------------------------------------------------*/
373VOID
374tkipMicEncapsulate(IN PUINT_8 pucDa,
375 IN PUINT_8 pucSa,
376 IN UINT_8 ucPriority,
377 IN UINT_16 u2PayloadLen,
378 IN PUINT_8 pucPayload, IN PUINT_8 pucMic, IN PUINT_8 pucMicKey)
379{
380 UCHAR aucMic[8]; /* MIC' */
381
382 DEBUGFUNC("tkipSwMsduEncapsulate");
383
384 ASSERT(pucDa);
385 ASSERT(pucSa);
386 ASSERT(pucPayload);
387 ASSERT(pucMic);
388 ASSERT(pucMicKey);
389
390 DBGLOG(RSN, LOUD, ("MIC key %02x-%02x-%02x-%02x %02x-%02x-%02x-%02x\n",
391 pucMicKey[0], pucMicKey[1], pucMicKey[2], pucMicKey[3],
392 pucMicKey[4], pucMicKey[5], pucMicKey[6], pucMicKey[7]));
393
394 tkipMicGen(pucMicKey, (PUINT_8) pucPayload, u2PayloadLen, pucSa, pucDa, ucPriority, aucMic);
395
396 kalMemCopy((PUINT_8) pucMic, &aucMic[0], WLAN_MAC_MIC_LEN);
397
398 DBGLOG(RSN, LOUD, ("Mic %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
399 pucMic[0], pucMic[1], pucMic[2], pucMic[3],
400 pucMic[4], pucMic[5], pucMic[6], pucMic[7]));
401
402} /* tkipSwMsduEncapsulate */
403
404
405/*----------------------------------------------------------------------------*/
406/*!
407* \brief This function decapsulate MSDU frame body (with MIC) according
408* to IEEE 802.11i TKIP sepcification.
409*
410* \param[in] prAdapter Pointer to the adapter object data area.
411* \param[in] prMacHeader Pointer to frame MAC header
412* \param[in] pucFrameBody Pointer to frame body
413* \param[in] u4FrameBodyLen Length of frame body (in bytes), include
414* length of ICV and MIC
415* \param[in] pucMickey Pointer to MIC key
416* \param[out] pu4ResultFrameBodyLen Pointer to put the result frame body length.
417*
418* \retval FALSE(TKIP_MIC_ERR), if this MSDU is not decapsulatable, i.e. MIC
419* verification is failure.
420* TRUE(TKIP_DECAPSULATE_SUCCESS), if this TKIP MSDU is decapsulated
421* successfully, i.e. MIC verification is successful.
422*
423* \note 1 If return TRUE, result frame body length
424* is only equal to data payload legth, and the result frame
425* body's format is MSDU
426* 2. If return FALSE, result frame body length is equal
427* to data payload legth plus MIC and MIC', and the result
428* frame body's format is: MSDU + MIC
429*/
430/*----------------------------------------------------------------------------*/
431BOOLEAN tkipMicDecapsulate(IN P_SW_RFB_T prSwRfb, IN PUINT_8 pucMicKey)
432{
433 PUCHAR pucMic1; /* MIC */
434 UCHAR aucMic2[8]; /* MIC' */
435 UCHAR ucPriority;
436 BOOLEAN fgStatus;
437 PUCHAR pucSa, pucDa;
438 /* PUCHAR pucMickey; */
439 PUCHAR pucFrameBody;
440 UINT_16 u2FrameBodyLen;
441 P_WLAN_MAC_HEADER_T prMacHeader;
442
443 DEBUGFUNC("tkipMicDecapsulate");
444
445 ASSERT(prSwRfb);
446 ASSERT(pucMicKey);
447
448 /* prRxStatus = prSwRfb->prRxStatus; */
449 pucFrameBody = prSwRfb->pucPayload;
450 u2FrameBodyLen = prSwRfb->u2PayloadLength;
451
452 /* if ((prRxStatus->ucKIdxSecMode & BITS(0,3)) != CIPHER_SUITE_TKIP_WO_MIC){ */
453 /* return TRUE; */
454 /* } */
455
456 DBGLOG(RSN, LOUD, ("Before TKIP MSDU Decapsulate:\n"));
457 DBGLOG(RSN, LOUD, ("MIC key:\n"));
458 /* DBGLOG_MEM8(RSN, LOUD, pucMicKey, 8); */
459
460 prMacHeader = (P_WLAN_MAC_HEADER_T) prSwRfb->pvHeader;
461 ASSERT(prMacHeader);
462
463 pucDa = prMacHeader->aucAddr1;
464 pucSa = prMacHeader->aucAddr3;
465
466 switch (prMacHeader->u2FrameCtrl & MASK_TO_DS_FROM_DS) {
467 case 0:
468 pucDa = prMacHeader->aucAddr1;
469 pucSa = prMacHeader->aucAddr2;
470 break;
471 case MASK_FC_FROM_DS:
472 pucDa = prMacHeader->aucAddr1;
473 pucSa = prMacHeader->aucAddr3;
474 break;
475 default:
476 ASSERT((prMacHeader->u2FrameCtrl & MASK_FC_TO_DS) == 0);
477 return TRUE;
478 }
479
480 if (RXM_IS_QOS_DATA_FRAME(prSwRfb->u2FrameCtrl)) {
481 ucPriority =
482 (UCHAR) ((((P_WLAN_MAC_HEADER_QOS_T) prSwRfb->pvHeader)->
483 u2QosCtrl) & MASK_QC_TID);
484 } else {
485 ucPriority = 0;
486 }
487
488 /* generate MIC' */
489 tkipMicGen(pucMicKey, pucFrameBody, u2FrameBodyLen - WLAN_MAC_MIC_LEN,
490 pucSa, pucDa, ucPriority, aucMic2);
491
492 /* verify MIC and MIC' */
493 pucMic1 = &pucFrameBody[u2FrameBodyLen - WLAN_MAC_MIC_LEN];
494 if (pucMic1[0] == aucMic2[0] && pucMic1[1] == aucMic2[1] &&
495 pucMic1[2] == aucMic2[2] && pucMic1[3] == aucMic2[3] &&
496 pucMic1[4] == aucMic2[4] && pucMic1[5] == aucMic2[5] &&
497 pucMic1[6] == aucMic2[6] && pucMic1[7] == aucMic2[7]) {
498 u2FrameBodyLen -= WLAN_MAC_MIC_LEN;
499 fgStatus = TRUE;
500 } else {
501 fgStatus = FALSE;
502 }
503
504 /* DBGLOG(RSN, LOUD, ("TKIP MIC:\n")); */
505 /* DBGLOG_MEM8(RSN, LOUD, pucMic1, 8); */
506 /* DBGLOG(RSN, LOUD, ("TKIP MIC':\n")); */
507 /* DBGLOG_MEM8(RSN, LOUD, aucMic2, 8); */
508
509 prSwRfb->u2PayloadLength = u2FrameBodyLen;
510
511 DBGLOG(RSN, LOUD, ("After TKIP MSDU Decapsulate:\n"));
512 DBGLOG(RSN, LOUD, ("Frame body: (length = %u)\n", u2FrameBodyLen));
513 /* DBGLOG_MEM8(RSN, LOUD, pucFrameBody, u2FrameBodyLen); */
514
515 return fgStatus;
516
517} /* tkipMicDecapsulate */