2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
34 -------- ---------- ----------------------------------------------
35 Jan Lee 03-07-22 Initial
36 Paul Lin 03-11-28 Modify for supplicant
38 #include "../rt_config.h"
40 UCHAR OUI_WPA_NONE_AKM[4] = {0x00, 0x50, 0xF2, 0x00};
41 UCHAR OUI_WPA_VERSION[4] = {0x00, 0x50, 0xF2, 0x01};
42 UCHAR OUI_WPA_WEP40[4] = {0x00, 0x50, 0xF2, 0x01};
43 UCHAR OUI_WPA_TKIP[4] = {0x00, 0x50, 0xF2, 0x02};
44 UCHAR OUI_WPA_CCMP[4] = {0x00, 0x50, 0xF2, 0x04};
45 UCHAR OUI_WPA_WEP104[4] = {0x00, 0x50, 0xF2, 0x05};
46 UCHAR OUI_WPA_8021X_AKM[4] = {0x00, 0x50, 0xF2, 0x01};
47 UCHAR OUI_WPA_PSK_AKM[4] = {0x00, 0x50, 0xF2, 0x02};
49 UCHAR OUI_WPA2_WEP40[4] = {0x00, 0x0F, 0xAC, 0x01};
50 UCHAR OUI_WPA2_TKIP[4] = {0x00, 0x0F, 0xAC, 0x02};
51 UCHAR OUI_WPA2_CCMP[4] = {0x00, 0x0F, 0xAC, 0x04};
52 UCHAR OUI_WPA2_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x01};
53 UCHAR OUI_WPA2_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x02};
54 UCHAR OUI_WPA2_WEP104[4] = {0x00, 0x0F, 0xAC, 0x05};
56 UCHAR OUI_MSA_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x05}; // Not yet final - IEEE 802.11s-D1.06
57 UCHAR OUI_MSA_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x06}; // Not yet final - IEEE 802.11s-D1.06
60 ========================================================================
63 The pseudo-random function(PRF) that hashes various inputs to
64 derive a pseudo-random value. To add liveness to the pseudo-random
65 value, a nonce should be one of the inputs.
67 It is used to generate PTK, GTK or some specific random value.
70 UCHAR *key, - the key material for HMAC_SHA1 use
71 INT key_len - the length of key
72 UCHAR *prefix - a prefix label
73 INT prefix_len - the length of the label
74 UCHAR *data - a specific data with variable length
75 INT data_len - the length of a specific data
76 INT len - the output lenght
79 UCHAR *output - the calculated result
82 802.11i-2004 Annex H.3
84 ========================================================================
101 // Allocate memory for input
102 os_alloc_mem(NULL, (PUCHAR *)&input, 1024);
106 DBGPRINT(RT_DEBUG_ERROR, ("!!!PRF: no memory!!!\n"));
110 // Generate concatenation input
111 NdisMoveMemory(input, prefix, prefix_len);
113 // Concatenate a single octet containing 0
114 input[prefix_len] = 0;
116 // Concatenate specific data
117 NdisMoveMemory(&input[prefix_len + 1], data, data_len);
118 total_len = prefix_len + 1 + data_len;
120 // Concatenate a single octet containing 0
121 // This octet shall be update later
122 input[total_len] = 0;
125 // Iterate to calculate the result by hmac-sha-1
126 // Then concatenate to last result
127 for (i = 0; i < (len + 19) / 20; i++)
129 HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]);
132 // update the last octet
133 input[total_len - 1]++;
135 os_free_mem(NULL, input);
139 ========================================================================
142 It utilizes PRF-384 or PRF-512 to derive session-specific keys from a PMK.
143 It shall be called by 4-way handshake processing.
146 pAd - pointer to our pAdapter context
148 ANonce - pointer to ANonce
149 AA - pointer to Authenticator Address
150 SNonce - pointer to SNonce
151 SA - pointer to Supplicant Address
152 len - indicate the length of PTK (octet)
155 Output pointer to the PTK
158 Refer to IEEE 802.11i-2004 8.5.1.2
160 ========================================================================
163 IN PRTMP_ADAPTER pAd,
172 UCHAR concatenation[76];
175 UCHAR Prefix[] = {'P', 'a', 'i', 'r', 'w', 'i', 's', 'e', ' ', 'k', 'e', 'y', ' ',
176 'e', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n'};
178 // initiate the concatenation input
179 NdisZeroMemory(temp, sizeof(temp));
180 NdisZeroMemory(concatenation, 76);
182 // Get smaller address
183 if (RTMPCompareMemory(SA, AA, 6) == 1)
184 NdisMoveMemory(concatenation, AA, 6);
186 NdisMoveMemory(concatenation, SA, 6);
189 // Get larger address
190 if (RTMPCompareMemory(SA, AA, 6) == 1)
191 NdisMoveMemory(&concatenation[CurrPos], SA, 6);
193 NdisMoveMemory(&concatenation[CurrPos], AA, 6);
195 // store the larger mac address for backward compatible of
196 // ralink proprietary STA-key issue
197 NdisMoveMemory(temp, &concatenation[CurrPos], MAC_ADDR_LEN);
201 if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
202 NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue
203 else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
204 NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
206 NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
210 if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
211 NdisMoveMemory(&concatenation[CurrPos], temp, 32); // patch for ralink proprietary STA-key issue
212 else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
213 NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
215 NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
218 hex_dump("concatenation=", concatenation, 76);
220 // Use PRF to generate PTK
221 PRF(PMK, LEN_MASTER_KEY, Prefix, 22, concatenation, 76, output, len);
226 ========================================================================
229 Generate random number by software.
232 pAd - pointer to our pAdapter context
233 macAddr - pointer to local MAC address
238 802.1ii-2004 Annex H.5
240 ========================================================================
243 IN PRTMP_ADAPTER pAd,
248 UCHAR local[80], KeyCounter[32];
251 UCHAR prefix[] = {'I', 'n', 'i', 't', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r'};
253 // Zero the related information
254 NdisZeroMemory(result, 80);
255 NdisZeroMemory(local, 80);
256 NdisZeroMemory(KeyCounter, 32);
258 for (i = 0; i < 32; i++)
260 // copy the local MAC address
261 COPY_MAC_ADDR(local, macAddr);
264 // concatenate the current time
265 NdisGetSystemUpTime(&CurrentTime);
266 NdisMoveMemory(&local[curr], &CurrentTime, sizeof(CurrentTime));
267 curr += sizeof(CurrentTime);
269 // concatenate the last result
270 NdisMoveMemory(&local[curr], result, 32);
273 // concatenate a variable
274 NdisMoveMemory(&local[curr], &i, 2);
277 // calculate the result
278 PRF(KeyCounter, 32, prefix,12, local, curr, result, 32);
281 NdisMoveMemory(random, result, 32);
285 ========================================================================
288 Build cipher suite in RSN-IE.
289 It only shall be called by RTMPMakeRSNIE.
292 pAd - pointer to our pAdapter context
293 ElementID - indicate the WPA1 or WPA2
294 WepStatus - indicate the encryption type
295 bMixCipher - a boolean to indicate the pairwise cipher and group
296 cipher are the same or not
302 ========================================================================
304 static VOID RTMPInsertRsnIeCipher(
305 IN PRTMP_ADAPTER pAd,
308 IN BOOLEAN bMixCipher,
309 IN UCHAR FlexibleCipher,
317 // decide WPA2 or WPA1
318 if (ElementID == Wpa2Ie)
320 RSNIE2 *pRsnie_cipher = (RSNIE2*)pRsnIe;
322 // Assign the verson as 1
323 pRsnie_cipher->version = 1;
328 case Ndis802_11Encryption2Enabled:
329 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
330 pRsnie_cipher->ucount = 1;
331 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4);
332 *rsn_len = sizeof(RSNIE2);
336 case Ndis802_11Encryption3Enabled:
338 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
340 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_CCMP, 4);
341 pRsnie_cipher->ucount = 1;
342 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4);
343 *rsn_len = sizeof(RSNIE2);
347 case Ndis802_11Encryption4Enabled:
348 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
351 // Insert WPA2 TKIP as the first pairwise cipher
352 if (MIX_CIPHER_WPA2_TKIP_ON(FlexibleCipher))
354 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4);
355 // Insert WPA2 AES as the secondary pairwise cipher
356 if (MIX_CIPHER_WPA2_AES_ON(FlexibleCipher))
358 NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA2_CCMP, 4);
364 // Insert WPA2 AES as the first pairwise cipher
365 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4);
368 pRsnie_cipher->ucount = PairwiseCnt;
369 *rsn_len = sizeof(RSNIE2) + (4 * (PairwiseCnt - 1));
373 if ((pAd->OpMode == OPMODE_STA) &&
374 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
375 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled))
377 UINT GroupCipher = pAd->StaCfg.GroupCipher;
380 case Ndis802_11GroupWEP40Enabled:
381 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP40, 4);
383 case Ndis802_11GroupWEP104Enabled:
384 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP104, 4);
389 // swap for big-endian platform
390 pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
391 pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
395 RSNIE *pRsnie_cipher = (RSNIE*)pRsnIe;
397 // Assign OUI and version
398 NdisMoveMemory(pRsnie_cipher->oui, OUI_WPA_VERSION, 4);
399 pRsnie_cipher->version = 1;
404 case Ndis802_11Encryption2Enabled:
405 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
406 pRsnie_cipher->ucount = 1;
407 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
408 *rsn_len = sizeof(RSNIE);
412 case Ndis802_11Encryption3Enabled:
414 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
416 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_CCMP, 4);
417 pRsnie_cipher->ucount = 1;
418 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
419 *rsn_len = sizeof(RSNIE);
423 case Ndis802_11Encryption4Enabled:
424 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
427 // Insert WPA TKIP as the first pairwise cipher
428 if (MIX_CIPHER_WPA_TKIP_ON(FlexibleCipher))
430 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
431 // Insert WPA AES as the secondary pairwise cipher
432 if (MIX_CIPHER_WPA_AES_ON(FlexibleCipher))
434 NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA_CCMP, 4);
440 // Insert WPA AES as the first pairwise cipher
441 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
444 pRsnie_cipher->ucount = PairwiseCnt;
445 *rsn_len = sizeof(RSNIE) + (4 * (PairwiseCnt - 1));
449 if ((pAd->OpMode == OPMODE_STA) &&
450 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
451 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled))
453 UINT GroupCipher = pAd->StaCfg.GroupCipher;
456 case Ndis802_11GroupWEP40Enabled:
457 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP40, 4);
459 case Ndis802_11GroupWEP104Enabled:
460 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP104, 4);
465 // swap for big-endian platform
466 pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
467 pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
472 ========================================================================
475 Build AKM suite in RSN-IE.
476 It only shall be called by RTMPMakeRSNIE.
479 pAd - pointer to our pAdapter context
480 ElementID - indicate the WPA1 or WPA2
481 AuthMode - indicate the authentication mode
482 apidx - indicate the interface index
488 ========================================================================
490 static VOID RTMPInsertRsnIeAKM(
491 IN PRTMP_ADAPTER pAd,
498 RSNIE_AUTH *pRsnie_auth;
500 pRsnie_auth = (RSNIE_AUTH*)(pRsnIe + (*rsn_len));
502 // decide WPA2 or WPA1
503 if (ElementID == Wpa2Ie)
507 case Ndis802_11AuthModeWPA2:
508 case Ndis802_11AuthModeWPA1WPA2:
509 pRsnie_auth->acount = 1;
510 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_8021X_AKM, 4);
513 case Ndis802_11AuthModeWPA2PSK:
514 case Ndis802_11AuthModeWPA1PSKWPA2PSK:
515 pRsnie_auth->acount = 1;
516 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_PSK_AKM, 4);
524 case Ndis802_11AuthModeWPA:
525 case Ndis802_11AuthModeWPA1WPA2:
526 pRsnie_auth->acount = 1;
527 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_8021X_AKM, 4);
530 case Ndis802_11AuthModeWPAPSK:
531 case Ndis802_11AuthModeWPA1PSKWPA2PSK:
532 pRsnie_auth->acount = 1;
533 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_PSK_AKM, 4);
536 case Ndis802_11AuthModeWPANone:
537 pRsnie_auth->acount = 1;
538 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_NONE_AKM, 4);
543 pRsnie_auth->acount = cpu2le16(pRsnie_auth->acount);
545 (*rsn_len) += sizeof(RSNIE_AUTH); // update current RSNIE length
550 ========================================================================
553 Build capability in RSN-IE.
554 It only shall be called by RTMPMakeRSNIE.
557 pAd - pointer to our pAdapter context
558 ElementID - indicate the WPA1 or WPA2
559 apidx - indicate the interface index
565 ========================================================================
567 static VOID RTMPInsertRsnIeCap(
568 IN PRTMP_ADAPTER pAd,
574 RSN_CAPABILITIES *pRSN_Cap;
576 // it could be ignored in WPA1 mode
577 if (ElementID == WpaIe)
580 pRSN_Cap = (RSN_CAPABILITIES*)(pRsnIe + (*rsn_len));
583 pRSN_Cap->word = cpu2le16(pRSN_Cap->word);
585 (*rsn_len) += sizeof(RSN_CAPABILITIES); // update current RSNIE length
591 ========================================================================
594 Build RSN IE context. It is not included element-ID and length.
597 pAd - pointer to our pAdapter context
598 AuthMode - indicate the authentication mode
599 WepStatus - indicate the encryption type
600 apidx - indicate the interface index
606 ========================================================================
609 IN PRTMP_ADAPTER pAd,
614 PUCHAR pRsnIe = NULL; // primary RSNIE
615 UCHAR *rsnielen_cur_p = 0; // the length of the primary RSNIE
616 UCHAR *rsnielen_ex_cur_p = 0; // the length of the secondary RSNIE
618 BOOLEAN bMixCipher = FALSE; // indicate the pairwise and group cipher are different
620 WPA_MIX_PAIR_CIPHER FlexibleCipher = MIX_CIPHER_NOTUSE; // it provide the more flexible cipher combination in WPA-WPA2 and TKIPAES mode
622 rsnielen_cur_p = NULL;
623 rsnielen_ex_cur_p = NULL;
627 if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
629 if (AuthMode < Ndis802_11AuthModeWPA)
634 // Support WPAPSK or WPA2PSK in STA-Infra mode
635 // Support WPANone in STA-Adhoc mode
636 if ((AuthMode != Ndis802_11AuthModeWPAPSK) &&
637 (AuthMode != Ndis802_11AuthModeWPA2PSK) &&
638 (AuthMode != Ndis802_11AuthModeWPANone)
643 DBGPRINT(RT_DEBUG_TRACE,("==> RTMPMakeRSNIE(STA)\n"));
645 // Zero RSNIE context
646 pAd->StaCfg.RSNIE_Len = 0;
647 NdisZeroMemory(pAd->StaCfg.RSN_IE, MAX_LEN_OF_RSNIE);
650 rsnielen_cur_p = &pAd->StaCfg.RSNIE_Len;
651 pRsnIe = pAd->StaCfg.RSN_IE;
653 bMixCipher = pAd->StaCfg.bMixCipher;
657 // indicate primary RSNIE as WPA or WPA2
658 if ((AuthMode == Ndis802_11AuthModeWPA) ||
659 (AuthMode == Ndis802_11AuthModeWPAPSK) ||
660 (AuthMode == Ndis802_11AuthModeWPANone) ||
661 (AuthMode == Ndis802_11AuthModeWPA1WPA2) ||
662 (AuthMode == Ndis802_11AuthModeWPA1PSKWPA2PSK))
663 PrimaryRsnie = WpaIe;
665 PrimaryRsnie = Wpa2Ie;
668 // Build the primary RSNIE
669 // 1. insert cipher suite
670 RTMPInsertRsnIeCipher(pAd, PrimaryRsnie, WepStatus, bMixCipher, FlexibleCipher, pRsnIe, &p_offset);
673 RTMPInsertRsnIeAKM(pAd, PrimaryRsnie, AuthMode, apidx, pRsnIe, &p_offset);
675 // 3. insert capability
676 RTMPInsertRsnIeCap(pAd, PrimaryRsnie, apidx, pRsnIe, &p_offset);
679 // 4. update the RSNIE length
680 *rsnielen_cur_p = p_offset;
682 hex_dump("The primary RSNIE", pRsnIe, (*rsnielen_cur_p));
688 ==========================================================================
690 Check whether the received frame is EAP frame.
693 pAd - pointer to our pAdapter context
694 pEntry - pointer to active entry
695 pData - the received frame
696 DataByteCount - the received frame's length
697 FromWhichBSSID - indicate the interface index
700 TRUE - This frame is EAP frame
702 ==========================================================================
704 BOOLEAN RTMPCheckWPAframe(
705 IN PRTMP_ADAPTER pAd,
706 IN PMAC_TABLE_ENTRY pEntry,
708 IN ULONG DataByteCount,
709 IN UCHAR FromWhichBSSID)
715 if(DataByteCount < (LENGTH_802_1_H + LENGTH_EAPOL_H))
720 if (NdisEqualMemory(SNAP_802_1H, pData, 6) ||
721 // Cisco 1200 AP may send packet with SNAP_BRIDGE_TUNNEL
722 NdisEqualMemory(SNAP_BRIDGE_TUNNEL, pData, 6))
726 // Skip 2-bytes EAPoL type
727 if (NdisEqualMemory(EAPOL, pData, 2))
737 Body_len = (*(pData+2)<<8) | (*(pData+3));
738 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAP-Packet frame, TYPE = 0, Length = %ld\n", Body_len));
741 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Start frame, TYPE = 1 \n"));
742 if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE)
744 DBGPRINT(RT_DEBUG_TRACE, ("Cancel the EnqueueEapolStartTimerRunning \n"));
745 RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled);
746 pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
750 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLLogoff frame, TYPE = 2 \n"));
753 Body_len = (*(pData+2)<<8) | (*(pData+3));
754 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Key frame, TYPE = 3, Length = %ld\n", Body_len));
757 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLASFAlert frame, TYPE = 4 \n"));
768 ==========================================================================
770 ENCRYPT AES GTK before sending in EAPOL frame.
771 AES GTK length = 128 bit, so fix blocks for aes-key-wrap as 2 in this function.
772 This function references to RFC 3394 for aes key wrap algorithm.
774 ==========================================================================
776 VOID AES_GTK_KEY_WRAP(
780 OUT UCHAR *ciphertext)
782 UCHAR A[8], BIN[16], BOUT[16];
784 INT num_blocks = p_len/8; // unit:64bits
789 rtmp_aes_set_key(&aesctx, key, 128);
792 for (i = 0; i < 8; i++)
796 for (i = 0; i < num_blocks; i++)
798 for (j = 0 ; j < 8; j++)
799 R[8 * (i + 1) + j] = plaintext[8 * i + j];
803 for (j = 0; j < 6; j++)
805 for(i = 1; i <= num_blocks; i++)
808 NdisMoveMemory(BIN, A, 8);
809 NdisMoveMemory(&BIN[8], &R[8 * i], 8);
810 rtmp_aes_encrypt(&aesctx, BIN, BOUT);
812 NdisMoveMemory(A, &BOUT[0], 8);
813 xor = num_blocks * j + i;
814 A[7] = BOUT[7] ^ xor;
815 NdisMoveMemory(&R[8 * i], &BOUT[8], 8);
820 NdisMoveMemory(ciphertext, A, 8);
822 for (i = 1; i <= num_blocks; i++)
824 for (j = 0 ; j < 8; j++)
825 ciphertext[8 * i + j] = R[8 * i + j];
831 ========================================================================
834 Misc function to decrypt AES body
841 This function references to RFC 3394 for aes key unwrap algorithm.
843 ========================================================================
845 VOID AES_GTK_KEY_UNWRAP(
847 OUT UCHAR *plaintext,
849 IN UCHAR *ciphertext)
852 UCHAR A[8], BIN[16], BOUT[16];
857 INT num_blocks = c_len/8; // unit:64bits
860 os_alloc_mem(NULL, (PUCHAR *)&R, 512);
864 DBGPRINT(RT_DEBUG_ERROR, ("!!!AES_GTK_KEY_UNWRAP: no memory!!!\n"));
869 NdisMoveMemory(A, ciphertext, 8);
871 for(i = 0; i < (c_len-8); i++)
873 R[ i] = ciphertext[i + 8];
876 rtmp_aes_set_key(&aesctx, key, 128);
878 for(j = 5; j >= 0; j--)
880 for(i = (num_blocks-1); i > 0; i--)
882 xor = (num_blocks -1 )* j + i;
883 NdisMoveMemory(BIN, A, 8);
885 NdisMoveMemory(&BIN[8], &R[(i-1)*8], 8);
886 rtmp_aes_decrypt(&aesctx, BIN, BOUT);
887 NdisMoveMemory(A, &BOUT[0], 8);
888 NdisMoveMemory(&R[(i-1)*8], &BOUT[8], 8);
893 for(i = 0; i < c_len; i++)
899 os_free_mem(NULL, R);
903 ==========================================================================
905 Report the EAP message type
908 msg - EAPOL_PAIR_MSG_1
918 ==========================================================================
920 CHAR *GetEapolMsgType(CHAR msg)
922 if(msg == EAPOL_PAIR_MSG_1)
923 return "Pairwise Message 1";
924 else if(msg == EAPOL_PAIR_MSG_2)
925 return "Pairwise Message 2";
926 else if(msg == EAPOL_PAIR_MSG_3)
927 return "Pairwise Message 3";
928 else if(msg == EAPOL_PAIR_MSG_4)
929 return "Pairwise Message 4";
930 else if(msg == EAPOL_GROUP_MSG_1)
931 return "Group Message 1";
932 else if(msg == EAPOL_GROUP_MSG_2)
933 return "Group Message 2";
935 return "Invalid Message";
940 ========================================================================
943 Check Sanity RSN IE of EAPoL message
950 ========================================================================
952 BOOLEAN RTMPCheckRSNIE(
953 IN PRTMP_ADAPTER pAd,
956 IN MAC_TABLE_ENTRY *pEntry,
962 BOOLEAN result = FALSE;
968 while (len > sizeof(RSNIE2))
970 pEid = (PEID_STRUCT) pVIE;
972 if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)))
974 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA || pEntry->AuthMode == Ndis802_11AuthModeWPAPSK) &&
975 (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
976 (pEntry->RSNIE_Len == (pEid->Len + 2)))
981 *Offset += (pEid->Len + 2);
984 else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)))
986 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2 || pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) &&
987 (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
988 (pEntry->RSNIE_Len == (pEid->Len + 2))/* ToDo-AlbertY for mesh*/)
993 *Offset += (pEid->Len + 2);
1000 pVIE += (pEid->Len + 2);
1001 len -= (pEid->Len + 2);
1011 ========================================================================
1013 Routine Description:
1014 Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK.
1015 GTK is encaptulated in KDE format at p.83 802.11i D10
1024 ========================================================================
1026 BOOLEAN RTMPParseEapolKeyData(
1027 IN PRTMP_ADAPTER pAd,
1029 IN UCHAR KeyDataLen,
1030 IN UCHAR GroupKeyIndex,
1033 IN MAC_TABLE_ENTRY *pEntry)
1035 PKDE_ENCAP pKDE = NULL;
1036 PUCHAR pMyKeyData = pKeyData;
1037 UCHAR KeyDataLength = KeyDataLen;
1039 UCHAR DefaultIdx = 0;
1042 // Verify The RSN IE contained in pairewise_msg_2 && pairewise_msg_3 and skip it
1043 if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_3)
1045 // Check RSN IE whether it is WPA2/WPA2PSK
1046 if (!RTMPCheckRSNIE(pAd, pKeyData, KeyDataLen, pEntry, &skip_offset))
1048 // send wireless event - for RSN IE different
1049 if (pAd->CommonCfg.bWirelessEvent)
1050 RTMPSendWirelessEvent(pAd, IW_RSNIE_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
1052 DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in msg %d of 4-way handshake!\n", MsgType));
1053 hex_dump("Receive RSN_IE ", pKeyData, KeyDataLen);
1054 hex_dump("Desired RSN_IE ", pEntry->RSN_IE, pEntry->RSNIE_Len);
1060 if (bWPA2 && MsgType == EAPOL_PAIR_MSG_3)
1063 pMyKeyData += skip_offset;
1064 KeyDataLength -= skip_offset;
1065 DBGPRINT(RT_DEBUG_TRACE, ("RTMPParseEapolKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset));
1072 DBGPRINT(RT_DEBUG_TRACE,("RTMPParseEapolKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength));
1074 // Parse EKD format in pairwise_msg_3_WPA2 && group_msg_1_WPA2
1075 if (bWPA2 && (MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1))
1077 if (KeyDataLength >= 8) // KDE format exclude GTK length
1079 pKDE = (PKDE_ENCAP) pMyKeyData;
1082 DefaultIdx = pKDE->GTKEncap.Kid;
1084 // Sanity check - KED length
1085 if (KeyDataLength < (pKDE->Len + 2))
1087 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n"));
1091 // Get GTK length - refer to IEEE 802.11i-2004 p.82
1092 GTKLEN = pKDE->Len -6;
1093 if (GTKLEN < LEN_AES_KEY)
1095 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN));
1102 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KDE format length is too short \n"));
1106 DBGPRINT(RT_DEBUG_TRACE, ("GTK in KDE format ,DefaultKeyID=%d, KeyLen=%d \n", DefaultIdx, GTKLEN));
1112 else if (!bWPA2 && MsgType == EAPOL_GROUP_MSG_1)
1114 DefaultIdx = GroupKeyIndex;
1115 DBGPRINT(RT_DEBUG_TRACE, ("GTK DefaultKeyID=%d \n", DefaultIdx));
1118 // Sanity check - shared key index must be 1 ~ 3
1119 if (DefaultIdx < 1 || DefaultIdx > 3)
1121 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index(%d) is invalid in %s %s \n", DefaultIdx, ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
1131 ========================================================================
1133 Routine Description:
1134 Construct EAPoL message for WPA handshaking
1135 Its format is below,
1137 +--------------------+
1138 | Protocol Version | 1 octet
1139 +--------------------+
1140 | Protocol Type | 1 octet
1141 +--------------------+
1142 | Body Length | 2 octets
1143 +--------------------+
1144 | Descriptor Type | 1 octet
1145 +--------------------+
1146 | Key Information | 2 octets
1147 +--------------------+
1148 | Key Length | 1 octet
1149 +--------------------+
1150 | Key Repaly Counter | 8 octets
1151 +--------------------+
1152 | Key Nonce | 32 octets
1153 +--------------------+
1154 | Key IV | 16 octets
1155 +--------------------+
1156 | Key RSC | 8 octets
1157 +--------------------+
1158 | Key ID or Reserved | 8 octets
1159 +--------------------+
1160 | Key MIC | 16 octets
1161 +--------------------+
1162 | Key Data Length | 2 octets
1163 +--------------------+
1164 | Key Data | n octets
1165 +--------------------+
1169 pAd Pointer to our adapter
1176 ========================================================================
1178 VOID ConstructEapolMsg(
1179 IN PRTMP_ADAPTER pAd,
1182 IN UCHAR GroupKeyWepStatus,
1184 IN UCHAR DefaultKeyIdx,
1185 IN UCHAR *ReplayCounter,
1192 OUT PEAPOL_PACKET pMsg)
1194 BOOLEAN bWPA2 = FALSE;
1196 // Choose WPA2 or not
1197 if ((AuthMode == Ndis802_11AuthModeWPA2) || (AuthMode == Ndis802_11AuthModeWPA2PSK))
1200 // Init Packet and Fill header
1201 pMsg->ProVer = EAPOL_VER;
1202 pMsg->ProType = EAPOLKey;
1204 // Default 95 bytes, the EAPoL-Key descriptor exclude Key-data field
1205 pMsg->Body_Len[1] = LEN_EAPOL_KEY_MSG;
1207 // Fill in EAPoL descriptor
1209 pMsg->KeyDesc.Type = WPA2_KEY_DESC;
1211 pMsg->KeyDesc.Type = WPA1_KEY_DESC;
1213 // Fill in Key information, refer to IEEE Std 802.11i-2004 page 78
1214 // When either the pairwise or the group cipher is AES, the DESC_TYPE_AES(2) shall be used.
1215 pMsg->KeyDesc.KeyInfo.KeyDescVer =
1216 (((WepStatus == Ndis802_11Encryption3Enabled) || (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
1218 // Specify Key Type as Group(0) or Pairwise(1)
1219 if (MsgType >= EAPOL_GROUP_MSG_1)
1220 pMsg->KeyDesc.KeyInfo.KeyType = GROUPKEY;
1222 pMsg->KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
1224 // Specify Key Index, only group_msg1_WPA1
1225 if (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))
1226 pMsg->KeyDesc.KeyInfo.KeyIndex = DefaultKeyIdx;
1228 if (MsgType == EAPOL_PAIR_MSG_3)
1229 pMsg->KeyDesc.KeyInfo.Install = 1;
1231 if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1))
1232 pMsg->KeyDesc.KeyInfo.KeyAck = 1;
1234 if (MsgType != EAPOL_PAIR_MSG_1)
1235 pMsg->KeyDesc.KeyInfo.KeyMic = 1;
1237 if ((bWPA2 && (MsgType >= EAPOL_PAIR_MSG_3)) || (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1)))
1239 pMsg->KeyDesc.KeyInfo.Secure = 1;
1242 if (bWPA2 && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
1244 pMsg->KeyDesc.KeyInfo.EKD_DL = 1;
1247 // key Information element has done.
1248 *(USHORT *)(&pMsg->KeyDesc.KeyInfo) = cpu2le16(*(USHORT *)(&pMsg->KeyDesc.KeyInfo));
1250 // Fill in Key Length
1254 // In WPA2 mode, the field indicates the length of pairwise key cipher,
1255 // so only pairwise_msg_1 and pairwise_msg_3 need to fill.
1256 if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3))
1257 pMsg->KeyDesc.KeyLength[1] = ((WepStatus == Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : LEN_AES_KEY);
1262 if (MsgType >= EAPOL_GROUP_MSG_1)
1264 // the length of group key cipher
1265 pMsg->KeyDesc.KeyLength[1] = ((GroupKeyWepStatus == Ndis802_11Encryption2Enabled) ? TKIP_GTK_LENGTH : LEN_AES_KEY);
1269 // the length of pairwise key cipher
1270 pMsg->KeyDesc.KeyLength[1] = ((WepStatus == Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : LEN_AES_KEY);
1274 // Fill in replay counter
1275 NdisMoveMemory(pMsg->KeyDesc.ReplayCounter, ReplayCounter, LEN_KEY_DESC_REPLAY);
1277 // Fill Key Nonce field
1278 // ANonce : pairwise_msg1 & pairwise_msg3
1279 // SNonce : pairwise_msg2
1280 // GNonce : group_msg1_wpa1
1281 if ((MsgType <= EAPOL_PAIR_MSG_3) || ((!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))))
1282 NdisMoveMemory(pMsg->KeyDesc.KeyNonce, KeyNonce, LEN_KEY_DESC_NONCE);
1284 // Fill key IV - WPA2 as 0, WPA1 as random
1285 if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))
1287 // Suggest IV be random number plus some number,
1288 NdisMoveMemory(pMsg->KeyDesc.KeyIv, &KeyNonce[16], LEN_KEY_DESC_IV);
1289 pMsg->KeyDesc.KeyIv[15] += 2;
1292 // Fill Key RSC field
1293 // It contains the RSC for the GTK being installed.
1294 if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1))
1296 NdisMoveMemory(pMsg->KeyDesc.KeyRsc, TxRSC, 6);
1299 // Clear Key MIC field for MIC calculation later
1300 NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
1302 ConstructEapolKeyData(pAd,
1315 // Calculate MIC and fill in KeyMic Field except Pairwise Msg 1.
1316 if (MsgType != EAPOL_PAIR_MSG_1)
1318 CalculateMIC(pAd, WepStatus, PTK, pMsg);
1321 DBGPRINT(RT_DEBUG_TRACE, ("===> ConstructEapolMsg for %s %s\n", ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
1322 DBGPRINT(RT_DEBUG_TRACE, (" Body length = %d \n", pMsg->Body_Len[1]));
1323 DBGPRINT(RT_DEBUG_TRACE, (" Key length = %d \n", pMsg->KeyDesc.KeyLength[1]));
1329 ========================================================================
1331 Routine Description:
1332 Construct the Key Data field of EAPoL message
1335 pAd Pointer to our adapter
1343 ========================================================================
1345 VOID ConstructEapolKeyData(
1346 IN PRTMP_ADAPTER pAd,
1349 IN UCHAR GroupKeyWepStatus,
1351 IN UCHAR DefaultKeyIdx,
1352 IN BOOLEAN bWPA2Capable,
1357 OUT PEAPOL_PACKET pMsg)
1359 UCHAR *mpool, *Key_Data, *Rc4GTK;
1360 UCHAR ekey[(LEN_KEY_DESC_IV+LEN_EAP_EK)];
1364 if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2)
1367 // allocate memory pool
1368 os_alloc_mem(pAd, (PUCHAR *)&mpool, 1500);
1373 /* Rc4GTK Len = 512 */
1374 Rc4GTK = (UCHAR *) ROUND_UP(mpool, 4);
1375 /* Key_Data Len = 512 */
1376 Key_Data = (UCHAR *) ROUND_UP(Rc4GTK + 512, 4);
1378 NdisZeroMemory(Key_Data, 512);
1379 pMsg->KeyDesc.KeyDataLen[1] = 0;
1382 // Encapsulate RSNIE in pairwise_msg2 & pairwise_msg3
1383 if (RSNIE_LEN && ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3)))
1386 Key_Data[data_offset + 0] = IE_WPA2;
1388 Key_Data[data_offset + 0] = IE_WPA;
1390 Key_Data[data_offset + 1] = RSNIE_LEN;
1391 NdisMoveMemory(&Key_Data[data_offset + 2], RSNIE, RSNIE_LEN);
1392 data_offset += (2 + RSNIE_LEN);
1395 // Encapsulate KDE format in pairwise_msg3_WPA2 & group_msg1_WPA2
1396 if (bWPA2Capable && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
1398 // Key Data Encapsulation (KDE) format - 802.11i-2004 Figure-43w and Table-20h
1399 Key_Data[data_offset + 0] = 0xDD;
1401 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
1403 Key_Data[data_offset + 1] = 0x16;// 4+2+16(OUI+DataType+DataField)
1407 Key_Data[data_offset + 1] = 0x26;// 4+2+32(OUI+DataType+DataField)
1410 Key_Data[data_offset + 2] = 0x00;
1411 Key_Data[data_offset + 3] = 0x0F;
1412 Key_Data[data_offset + 4] = 0xAC;
1413 Key_Data[data_offset + 5] = 0x01;
1415 // GTK KDE format - 802.11i-2004 Figure-43x
1416 Key_Data[data_offset + 6] = (DefaultKeyIdx & 0x03);
1417 Key_Data[data_offset + 7] = 0x00; // Reserved Byte
1423 // Encapsulate GTK and encrypt the key-data field with KEK.
1424 // Only for pairwise_msg3_WPA2 and group_msg1
1425 if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable) || (MsgType == EAPOL_GROUP_MSG_1))
1428 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
1430 NdisMoveMemory(&Key_Data[data_offset], GTK, LEN_AES_KEY);
1431 data_offset += LEN_AES_KEY;
1435 NdisMoveMemory(&Key_Data[data_offset], GTK, TKIP_GTK_LENGTH);
1436 data_offset += TKIP_GTK_LENGTH;
1439 // Still dont know why, but if not append will occur "GTK not include in MSG3"
1440 // Patch for compatibility between zero config and funk
1441 if (MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable)
1443 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
1445 Key_Data[data_offset + 0] = 0xDD;
1446 Key_Data[data_offset + 1] = 0;
1451 Key_Data[data_offset + 0] = 0xDD;
1452 Key_Data[data_offset + 1] = 0;
1453 Key_Data[data_offset + 2] = 0;
1454 Key_Data[data_offset + 3] = 0;
1455 Key_Data[data_offset + 4] = 0;
1456 Key_Data[data_offset + 5] = 0;
1461 // Encrypt the data material in key data field
1462 if (WepStatus == Ndis802_11Encryption3Enabled)
1464 AES_GTK_KEY_WRAP(&PTK[16], Key_Data, data_offset, Rc4GTK);
1465 // AES wrap function will grow 8 bytes in length
1470 // PREPARE Encrypted "Key DATA" field. (Encrypt GTK with RC4, usinf PTK[16]->[31] as Key, IV-field as IV)
1471 // put TxTsc in Key RSC field
1472 pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; //Init crc32.
1474 // ekey is the contanetion of IV-field, and PTK[16]->PTK[31]
1475 NdisMoveMemory(ekey, pMsg->KeyDesc.KeyIv, LEN_KEY_DESC_IV);
1476 NdisMoveMemory(&ekey[LEN_KEY_DESC_IV], &PTK[16], LEN_EAP_EK);
1477 ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, ekey, sizeof(ekey)); //INIT SBOX, KEYLEN+3(IV)
1478 pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, Key_Data, data_offset);
1479 WPAARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, Rc4GTK, Key_Data, data_offset);
1482 NdisMoveMemory(pMsg->KeyDesc.KeyData, Rc4GTK, data_offset);
1486 NdisMoveMemory(pMsg->KeyDesc.KeyData, Key_Data, data_offset);
1489 // set key data length field and total length
1490 pMsg->KeyDesc.KeyDataLen[1] = data_offset;
1491 pMsg->Body_Len[1] += data_offset;
1493 os_free_mem(pAd, mpool);
1498 ========================================================================
1500 Routine Description:
1501 Calcaulate MIC. It is used during 4-ways handsharking.
1504 pAd - pointer to our pAdapter context
1505 PeerWepStatus - indicate the encryption type
1511 ========================================================================
1514 IN PRTMP_ADAPTER pAd,
1515 IN UCHAR PeerWepStatus,
1517 OUT PEAPOL_PACKET pMsg)
1521 UCHAR mic[LEN_KEY_DESC_MIC];
1524 // allocate memory for MIC calculation
1525 os_alloc_mem(pAd, (PUCHAR *)&OutBuffer, 512);
1527 if (OutBuffer == NULL)
1529 DBGPRINT(RT_DEBUG_ERROR, ("!!!CalculateMIC: no memory!!!\n"));
1533 // make a frame for calculating MIC.
1534 MakeOutgoingFrame(OutBuffer, &FrameLen,
1535 pMsg->Body_Len[1] + 4, pMsg,
1538 NdisZeroMemory(mic, sizeof(mic));
1541 if (PeerWepStatus == Ndis802_11Encryption3Enabled)
1543 HMAC_SHA1(OutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
1544 NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
1548 hmac_md5(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, mic);
1551 // store the calculated MIC
1552 NdisMoveMemory(pMsg->KeyDesc.KeyMic, mic, LEN_KEY_DESC_MIC);
1554 os_free_mem(pAd, OutBuffer);
1558 ========================================================================
1560 Routine Description:
1561 Some received frames can't decrypt by Asic, so decrypt them by software.
1564 pAd - pointer to our pAdapter context
1565 PeerWepStatus - indicate the encryption type
1568 NDIS_STATUS_SUCCESS - decryption successful
1569 NDIS_STATUS_FAILURE - decryption failure
1571 ========================================================================
1573 NDIS_STATUS RTMPSoftDecryptBroadCastData(
1574 IN PRTMP_ADAPTER pAd,
1576 IN NDIS_802_11_ENCRYPTION_STATUS GroupCipher,
1577 IN PCIPHER_KEY pShard_key)
1579 PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
1583 // handle WEP decryption
1584 if (GroupCipher == Ndis802_11Encryption1Enabled)
1586 if (RTMPSoftDecryptWEP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, pShard_key))
1589 //Minus IV[4] & ICV[4]
1590 pRxWI->MPDUtotalByteCount -= 8;
1594 DBGPRINT(RT_DEBUG_ERROR, ("ERROR : Software decrypt WEP data fails.\n"));
1595 // give up this frame
1596 return NDIS_STATUS_FAILURE;
1599 // handle TKIP decryption
1600 else if (GroupCipher == Ndis802_11Encryption2Enabled)
1602 if (RTMPSoftDecryptTKIP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, 0, pShard_key))
1605 //Minus 8 bytes MIC, 8 bytes IV/EIV, 4 bytes ICV
1606 pRxWI->MPDUtotalByteCount -= 20;
1610 DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptTKIP Failed\n"));
1611 // give up this frame
1612 return NDIS_STATUS_FAILURE;
1615 // handle AES decryption
1616 else if (GroupCipher == Ndis802_11Encryption3Enabled)
1618 if (RTMPSoftDecryptAES(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount , pShard_key))
1621 //8 bytes MIC, 8 bytes IV/EIV (CCMP Header)
1622 pRxWI->MPDUtotalByteCount -= 16;
1626 DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptAES Failed\n"));
1627 // give up this frame
1628 return NDIS_STATUS_FAILURE;
1633 // give up this frame
1634 return NDIS_STATUS_FAILURE;
1637 return NDIS_STATUS_SUCCESS;