tkip_mic.c 19 KB

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