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#include "../rt_config.h"
39
40UCHAR OUI_WPA_NONE_AKM[4] = {0x00, 0x50, 0xF2, 0x00};
41UCHAR OUI_WPA_VERSION[4] = {0x00, 0x50, 0xF2, 0x01};
42UCHAR OUI_WPA_WEP40[4] = {0x00, 0x50, 0xF2, 0x01};
43UCHAR OUI_WPA_TKIP[4] = {0x00, 0x50, 0xF2, 0x02};
44UCHAR OUI_WPA_CCMP[4] = {0x00, 0x50, 0xF2, 0x04};
45UCHAR OUI_WPA_WEP104[4] = {0x00, 0x50, 0xF2, 0x05};
46UCHAR OUI_WPA_8021X_AKM[4] = {0x00, 0x50, 0xF2, 0x01};
47UCHAR OUI_WPA_PSK_AKM[4] = {0x00, 0x50, 0xF2, 0x02};
48
49UCHAR OUI_WPA2_WEP40[4] = {0x00, 0x0F, 0xAC, 0x01};
50UCHAR OUI_WPA2_TKIP[4] = {0x00, 0x0F, 0xAC, 0x02};
51UCHAR OUI_WPA2_CCMP[4] = {0x00, 0x0F, 0xAC, 0x04};
52UCHAR OUI_WPA2_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x01};
53UCHAR OUI_WPA2_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x02};
54UCHAR OUI_WPA2_WEP104[4] = {0x00, 0x0F, 0xAC, 0x05};
55
56UCHAR OUI_MSA_8021X_AKM[4] = {0x00, 0x0F, 0xAC, 0x05};
57UCHAR OUI_MSA_PSK_AKM[4] = {0x00, 0x0F, 0xAC, 0x06};
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
86VOID PRF(
87 IN UCHAR *key,
88 IN INT key_len,
89 IN UCHAR *prefix,
90 IN INT prefix_len,
91 IN UCHAR *data,
92 IN INT data_len,
93 OUT UCHAR *output,
94 IN INT len)
95{
96 INT i;
97 UCHAR *input;
98 INT currentindex = 0;
99 INT total_len;
100
101
102 os_alloc_mem(NULL, (PUCHAR *)&input, 1024);
103
104 if (input == NULL)
105 {
106 DBGPRINT(RT_DEBUG_ERROR, ("!!!PRF: no memory!!!\n"));
107 return;
108 }
109
110
111 NdisMoveMemory(input, prefix, prefix_len);
112
113
114 input[prefix_len] = 0;
115
116
117 NdisMoveMemory(&input[prefix_len + 1], data, data_len);
118 total_len = prefix_len + 1 + data_len;
119
120
121
122 input[total_len] = 0;
123 total_len++;
124
125
126
127 for (i = 0; i < (len + 19) / 20; i++)
128 {
129 HMAC_SHA1(input, total_len, key, key_len, &output[currentindex]);
130 currentindex += 20;
131
132
133 input[total_len - 1]++;
134 }
135 os_free_mem(NULL, input);
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
162VOID WpaCountPTK(
163 IN PRTMP_ADAPTER pAd,
164 IN UCHAR *PMK,
165 IN UCHAR *ANonce,
166 IN UCHAR *AA,
167 IN UCHAR *SNonce,
168 IN UCHAR *SA,
169 OUT UCHAR *output,
170 IN UINT len)
171{
172 UCHAR concatenation[76];
173 UINT CurrPos = 0;
174 UCHAR temp[32];
175 UCHAR Prefix[] = {'P', 'a', 'i', 'r', 'w', 'i', 's', 'e', ' ', 'k', 'e', 'y', ' ',
176 'e', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n'};
177
178
179 NdisZeroMemory(temp, sizeof(temp));
180 NdisZeroMemory(concatenation, 76);
181
182
183 if (RTMPCompareMemory(SA, AA, 6) == 1)
184 NdisMoveMemory(concatenation, AA, 6);
185 else
186 NdisMoveMemory(concatenation, SA, 6);
187 CurrPos += 6;
188
189
190 if (RTMPCompareMemory(SA, AA, 6) == 1)
191 NdisMoveMemory(&concatenation[CurrPos], SA, 6);
192 else
193 NdisMoveMemory(&concatenation[CurrPos], AA, 6);
194
195
196
197 NdisMoveMemory(temp, &concatenation[CurrPos], MAC_ADDR_LEN);
198 CurrPos += 6;
199
200
201 if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
202 NdisMoveMemory(&concatenation[CurrPos], temp, 32);
203 else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
204 NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
205 else
206 NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
207 CurrPos += 32;
208
209
210 if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
211 NdisMoveMemory(&concatenation[CurrPos], temp, 32);
212 else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
213 NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
214 else
215 NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
216 CurrPos += 32;
217
218 hex_dump("concatenation=", concatenation, 76);
219
220
221 PRF(PMK, LEN_MASTER_KEY, Prefix, 22, concatenation, 76, output, len);
222
223}
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242VOID GenRandom(
243 IN PRTMP_ADAPTER pAd,
244 IN UCHAR *macAddr,
245 OUT UCHAR *random)
246{
247 INT i, curr;
248 UCHAR local[80], KeyCounter[32];
249 UCHAR result[80];
250 ULONG CurrentTime;
251 UCHAR prefix[] = {'I', 'n', 'i', 't', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r'};
252
253
254 NdisZeroMemory(result, 80);
255 NdisZeroMemory(local, 80);
256 NdisZeroMemory(KeyCounter, 32);
257
258 for (i = 0; i < 32; i++)
259 {
260
261 COPY_MAC_ADDR(local, macAddr);
262 curr = MAC_ADDR_LEN;
263
264
265 NdisGetSystemUpTime(&CurrentTime);
266 NdisMoveMemory(&local[curr], &CurrentTime, sizeof(CurrentTime));
267 curr += sizeof(CurrentTime);
268
269
270 NdisMoveMemory(&local[curr], result, 32);
271 curr += 32;
272
273
274 NdisMoveMemory(&local[curr], &i, 2);
275 curr += 2;
276
277
278 PRF(KeyCounter, 32, prefix,12, local, curr, result, 32);
279 }
280
281 NdisMoveMemory(random, result, 32);
282}
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304static VOID RTMPInsertRsnIeCipher(
305 IN PRTMP_ADAPTER pAd,
306 IN UCHAR ElementID,
307 IN UINT WepStatus,
308 IN BOOLEAN bMixCipher,
309 IN UCHAR FlexibleCipher,
310 OUT PUCHAR pRsnIe,
311 OUT UCHAR *rsn_len)
312{
313 UCHAR PairwiseCnt;
314
315 *rsn_len = 0;
316
317
318 if (ElementID == Wpa2Ie)
319 {
320 RSNIE2 *pRsnie_cipher = (RSNIE2*)pRsnIe;
321
322
323 pRsnie_cipher->version = 1;
324
325 switch (WepStatus)
326 {
327
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);
333 break;
334
335
336 case Ndis802_11Encryption3Enabled:
337 if (bMixCipher)
338 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
339 else
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);
344 break;
345
346
347 case Ndis802_11Encryption4Enabled:
348 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
349
350 PairwiseCnt = 1;
351
352 if (MIX_CIPHER_WPA2_TKIP_ON(FlexibleCipher))
353 {
354 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_TKIP, 4);
355
356 if (MIX_CIPHER_WPA2_AES_ON(FlexibleCipher))
357 {
358 NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA2_CCMP, 4);
359 PairwiseCnt = 2;
360 }
361 }
362 else
363 {
364
365 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA2_CCMP, 4);
366 }
367
368 pRsnie_cipher->ucount = PairwiseCnt;
369 *rsn_len = sizeof(RSNIE2) + (4 * (PairwiseCnt - 1));
370 break;
371 }
372
373#ifdef CONFIG_STA_SUPPORT
374 if ((pAd->OpMode == OPMODE_STA) &&
375 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
376 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled))
377 {
378 UINT GroupCipher = pAd->StaCfg.GroupCipher;
379 switch(GroupCipher)
380 {
381 case Ndis802_11GroupWEP40Enabled:
382 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP40, 4);
383 break;
384 case Ndis802_11GroupWEP104Enabled:
385 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_WEP104, 4);
386 break;
387 }
388 }
389#endif
390
391
392 pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
393 pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
394 }
395 else
396 {
397 RSNIE *pRsnie_cipher = (RSNIE*)pRsnIe;
398
399
400 NdisMoveMemory(pRsnie_cipher->oui, OUI_WPA_VERSION, 4);
401 pRsnie_cipher->version = 1;
402
403 switch (WepStatus)
404 {
405
406 case Ndis802_11Encryption2Enabled:
407 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
408 pRsnie_cipher->ucount = 1;
409 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
410 *rsn_len = sizeof(RSNIE);
411 break;
412
413
414 case Ndis802_11Encryption3Enabled:
415 if (bMixCipher)
416 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
417 else
418 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_CCMP, 4);
419 pRsnie_cipher->ucount = 1;
420 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
421 *rsn_len = sizeof(RSNIE);
422 break;
423
424
425 case Ndis802_11Encryption4Enabled:
426 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
427
428 PairwiseCnt = 1;
429
430 if (MIX_CIPHER_WPA_TKIP_ON(FlexibleCipher))
431 {
432 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_TKIP, 4);
433
434 if (MIX_CIPHER_WPA_AES_ON(FlexibleCipher))
435 {
436 NdisMoveMemory(pRsnie_cipher->ucast[0].oui + 4, OUI_WPA_CCMP, 4);
437 PairwiseCnt = 2;
438 }
439 }
440 else
441 {
442
443 NdisMoveMemory(pRsnie_cipher->ucast[0].oui, OUI_WPA_CCMP, 4);
444 }
445
446 pRsnie_cipher->ucount = PairwiseCnt;
447 *rsn_len = sizeof(RSNIE) + (4 * (PairwiseCnt - 1));
448 break;
449 }
450
451#ifdef CONFIG_STA_SUPPORT
452 if ((pAd->OpMode == OPMODE_STA) &&
453 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
454 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled))
455 {
456 UINT GroupCipher = pAd->StaCfg.GroupCipher;
457 switch(GroupCipher)
458 {
459 case Ndis802_11GroupWEP40Enabled:
460 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP40, 4);
461 break;
462 case Ndis802_11GroupWEP104Enabled:
463 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_WEP104, 4);
464 break;
465 }
466 }
467#endif
468
469
470 pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
471 pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
472 }
473}
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494static VOID RTMPInsertRsnIeAKM(
495 IN PRTMP_ADAPTER pAd,
496 IN UCHAR ElementID,
497 IN UINT AuthMode,
498 IN UCHAR apidx,
499 OUT PUCHAR pRsnIe,
500 OUT UCHAR *rsn_len)
501{
502 RSNIE_AUTH *pRsnie_auth;
503
504 pRsnie_auth = (RSNIE_AUTH*)(pRsnIe + (*rsn_len));
505
506
507 if (ElementID == Wpa2Ie)
508 {
509 switch (AuthMode)
510 {
511 case Ndis802_11AuthModeWPA2:
512 case Ndis802_11AuthModeWPA1WPA2:
513 pRsnie_auth->acount = 1;
514 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_8021X_AKM, 4);
515 break;
516
517 case Ndis802_11AuthModeWPA2PSK:
518 case Ndis802_11AuthModeWPA1PSKWPA2PSK:
519 pRsnie_auth->acount = 1;
520 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA2_PSK_AKM, 4);
521 break;
522 }
523 }
524 else
525 {
526 switch (AuthMode)
527 {
528 case Ndis802_11AuthModeWPA:
529 case Ndis802_11AuthModeWPA1WPA2:
530 pRsnie_auth->acount = 1;
531 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_8021X_AKM, 4);
532 break;
533
534 case Ndis802_11AuthModeWPAPSK:
535 case Ndis802_11AuthModeWPA1PSKWPA2PSK:
536 pRsnie_auth->acount = 1;
537 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_PSK_AKM, 4);
538 break;
539
540 case Ndis802_11AuthModeWPANone:
541 pRsnie_auth->acount = 1;
542 NdisMoveMemory(pRsnie_auth->auth[0].oui, OUI_WPA_NONE_AKM, 4);
543 break;
544 }
545 }
546
547 pRsnie_auth->acount = cpu2le16(pRsnie_auth->acount);
548
549 (*rsn_len) += sizeof(RSNIE_AUTH);
550
551}
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571static VOID RTMPInsertRsnIeCap(
572 IN PRTMP_ADAPTER pAd,
573 IN UCHAR ElementID,
574 IN UCHAR apidx,
575 OUT PUCHAR pRsnIe,
576 OUT UCHAR *rsn_len)
577{
578 RSN_CAPABILITIES *pRSN_Cap;
579
580
581 if (ElementID == WpaIe)
582 return;
583
584 pRSN_Cap = (RSN_CAPABILITIES*)(pRsnIe + (*rsn_len));
585
586
587 pRSN_Cap->word = cpu2le16(pRSN_Cap->word);
588
589 (*rsn_len) += sizeof(RSN_CAPABILITIES);
590
591}
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612VOID RTMPMakeRSNIE(
613 IN PRTMP_ADAPTER pAd,
614 IN UINT AuthMode,
615 IN UINT WepStatus,
616 IN UCHAR apidx)
617{
618 PUCHAR pRsnIe = NULL;
619 UCHAR *rsnielen_cur_p = 0;
620 UCHAR *rsnielen_ex_cur_p = 0;
621 UCHAR PrimaryRsnie;
622 BOOLEAN bMixCipher = FALSE;
623 UCHAR p_offset;
624 WPA_MIX_PAIR_CIPHER FlexibleCipher = MIX_CIPHER_NOTUSE;
625
626 rsnielen_cur_p = NULL;
627 rsnielen_ex_cur_p = NULL;
628
629 {
630#ifdef CONFIG_STA_SUPPORT
631 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
632 {
633#ifdef WPA_SUPPLICANT_SUPPORT
634 if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
635 {
636 if (AuthMode < Ndis802_11AuthModeWPA)
637 return;
638 }
639 else
640#endif
641 {
642
643
644 if ((AuthMode != Ndis802_11AuthModeWPAPSK) &&
645 (AuthMode != Ndis802_11AuthModeWPA2PSK) &&
646 (AuthMode != Ndis802_11AuthModeWPANone)
647 )
648 return;
649 }
650
651 DBGPRINT(RT_DEBUG_TRACE,("==> RTMPMakeRSNIE(STA)\n"));
652
653
654 pAd->StaCfg.RSNIE_Len = 0;
655 NdisZeroMemory(pAd->StaCfg.RSN_IE, MAX_LEN_OF_RSNIE);
656
657
658 rsnielen_cur_p = &pAd->StaCfg.RSNIE_Len;
659 pRsnIe = pAd->StaCfg.RSN_IE;
660
661 bMixCipher = pAd->StaCfg.bMixCipher;
662 }
663#endif
664 }
665
666
667 if ((AuthMode == Ndis802_11AuthModeWPA) ||
668 (AuthMode == Ndis802_11AuthModeWPAPSK) ||
669 (AuthMode == Ndis802_11AuthModeWPANone) ||
670 (AuthMode == Ndis802_11AuthModeWPA1WPA2) ||
671 (AuthMode == Ndis802_11AuthModeWPA1PSKWPA2PSK))
672 PrimaryRsnie = WpaIe;
673 else
674 PrimaryRsnie = Wpa2Ie;
675
676 {
677
678
679 RTMPInsertRsnIeCipher(pAd, PrimaryRsnie, WepStatus, bMixCipher, FlexibleCipher, pRsnIe, &p_offset);
680
681
682 RTMPInsertRsnIeAKM(pAd, PrimaryRsnie, AuthMode, apidx, pRsnIe, &p_offset);
683
684
685 RTMPInsertRsnIeCap(pAd, PrimaryRsnie, apidx, pRsnIe, &p_offset);
686 }
687
688
689 *rsnielen_cur_p = p_offset;
690
691 hex_dump("The primary RSNIE", pRsnIe, (*rsnielen_cur_p));
692
693
694}
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713BOOLEAN RTMPCheckWPAframe(
714 IN PRTMP_ADAPTER pAd,
715 IN PMAC_TABLE_ENTRY pEntry,
716 IN PUCHAR pData,
717 IN ULONG DataByteCount,
718 IN UCHAR FromWhichBSSID)
719{
720 ULONG Body_len;
721 BOOLEAN Cancelled;
722
723
724 if(DataByteCount < (LENGTH_802_1_H + LENGTH_EAPOL_H))
725 return FALSE;
726
727
728
729 if (NdisEqualMemory(SNAP_802_1H, pData, 6) ||
730
731 NdisEqualMemory(SNAP_BRIDGE_TUNNEL, pData, 6))
732 {
733 pData += 6;
734 }
735
736 if (NdisEqualMemory(EAPOL, pData, 2))
737 {
738 pData += 2;
739 }
740 else
741 return FALSE;
742
743 switch (*(pData+1))
744 {
745 case EAPPacket:
746 Body_len = (*(pData+2)<<8) | (*(pData+3));
747 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAP-Packet frame, TYPE = 0, Length = %ld\n", Body_len));
748 break;
749 case EAPOLStart:
750 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Start frame, TYPE = 1 \n"));
751 if (pEntry->EnqueueEapolStartTimerRunning != EAPOL_START_DISABLE)
752 {
753 DBGPRINT(RT_DEBUG_TRACE, ("Cancel the EnqueueEapolStartTimerRunning \n"));
754 RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, &Cancelled);
755 pEntry->EnqueueEapolStartTimerRunning = EAPOL_START_DISABLE;
756 }
757 break;
758 case EAPOLLogoff:
759 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLLogoff frame, TYPE = 2 \n"));
760 break;
761 case EAPOLKey:
762 Body_len = (*(pData+2)<<8) | (*(pData+3));
763 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOL-Key frame, TYPE = 3, Length = %ld\n", Body_len));
764 break;
765 case EAPOLASFAlert:
766 DBGPRINT(RT_DEBUG_TRACE, ("Receive EAPOLASFAlert frame, TYPE = 4 \n"));
767 break;
768 default:
769 return FALSE;
770
771 }
772 return TRUE;
773}
774
775
776
777
778
779
780
781
782
783
784
785VOID AES_GTK_KEY_WRAP(
786 IN UCHAR *key,
787 IN UCHAR *plaintext,
788 IN UCHAR p_len,
789 OUT UCHAR *ciphertext)
790{
791 UCHAR A[8], BIN[16], BOUT[16];
792 UCHAR R[512];
793 INT num_blocks = p_len/8;
794 INT i, j;
795 aes_context aesctx;
796 UCHAR xor;
797
798 rtmp_aes_set_key(&aesctx, key, 128);
799
800
801 for (i = 0; i < 8; i++)
802 A[i] = 0xa6;
803
804
805 for (i = 0; i < num_blocks; i++)
806 {
807 for (j = 0 ; j < 8; j++)
808 R[8 * (i + 1) + j] = plaintext[8 * i + j];
809 }
810
811
812 for (j = 0; j < 6; j++)
813 {
814 for(i = 1; i <= num_blocks; i++)
815 {
816
817 NdisMoveMemory(BIN, A, 8);
818 NdisMoveMemory(&BIN[8], &R[8 * i], 8);
819 rtmp_aes_encrypt(&aesctx, BIN, BOUT);
820
821 NdisMoveMemory(A, &BOUT[0], 8);
822 xor = num_blocks * j + i;
823 A[7] = BOUT[7] ^ xor;
824 NdisMoveMemory(&R[8 * i], &BOUT[8], 8);
825 }
826 }
827
828
829 NdisMoveMemory(ciphertext, A, 8);
830
831 for (i = 1; i <= num_blocks; i++)
832 {
833 for (j = 0 ; j < 8; j++)
834 ciphertext[8 * i + j] = R[8 * i + j];
835 }
836}
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854VOID AES_GTK_KEY_UNWRAP(
855 IN UCHAR *key,
856 OUT UCHAR *plaintext,
857 IN UCHAR c_len,
858 IN UCHAR *ciphertext)
859
860{
861 UCHAR A[8], BIN[16], BOUT[16];
862 UCHAR xor;
863 INT i, j;
864 aes_context aesctx;
865 UCHAR *R;
866 INT num_blocks = c_len/8;
867
868
869 os_alloc_mem(NULL, (PUCHAR *)&R, 512);
870
871 if (R == NULL)
872 {
873 DBGPRINT(RT_DEBUG_ERROR, ("!!!AES_GTK_KEY_UNWRAP: no memory!!!\n"));
874 return;
875 }
876
877
878 NdisMoveMemory(A, ciphertext, 8);
879
880 for(i = 0; i < (c_len-8); i++)
881 {
882 R[ i] = ciphertext[i + 8];
883 }
884
885 rtmp_aes_set_key(&aesctx, key, 128);
886
887 for(j = 5; j >= 0; j--)
888 {
889 for(i = (num_blocks-1); i > 0; i--)
890 {
891 xor = (num_blocks -1 )* j + i;
892 NdisMoveMemory(BIN, A, 8);
893 BIN[7] = A[7] ^ xor;
894 NdisMoveMemory(&BIN[8], &R[(i-1)*8], 8);
895 rtmp_aes_decrypt(&aesctx, BIN, BOUT);
896 NdisMoveMemory(A, &BOUT[0], 8);
897 NdisMoveMemory(&R[(i-1)*8], &BOUT[8], 8);
898 }
899 }
900
901
902 for(i = 0; i < c_len; i++)
903 {
904 plaintext[i] = R[i];
905 }
906
907
908 os_free_mem(NULL, R);
909}
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929CHAR *GetEapolMsgType(CHAR msg)
930{
931 if(msg == EAPOL_PAIR_MSG_1)
932 return "Pairwise Message 1";
933 else if(msg == EAPOL_PAIR_MSG_2)
934 return "Pairwise Message 2";
935 else if(msg == EAPOL_PAIR_MSG_3)
936 return "Pairwise Message 3";
937 else if(msg == EAPOL_PAIR_MSG_4)
938 return "Pairwise Message 4";
939 else if(msg == EAPOL_GROUP_MSG_1)
940 return "Group Message 1";
941 else if(msg == EAPOL_GROUP_MSG_2)
942 return "Group Message 2";
943 else
944 return "Invalid Message";
945}
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961BOOLEAN RTMPCheckRSNIE(
962 IN PRTMP_ADAPTER pAd,
963 IN PUCHAR pData,
964 IN UCHAR DataLen,
965 IN MAC_TABLE_ENTRY *pEntry,
966 OUT UCHAR *Offset)
967{
968 PUCHAR pVIE;
969 UCHAR len;
970 PEID_STRUCT pEid;
971 BOOLEAN result = FALSE;
972
973 pVIE = pData;
974 len = DataLen;
975 *Offset = 0;
976
977 while (len > sizeof(RSNIE2))
978 {
979 pEid = (PEID_STRUCT) pVIE;
980
981 if ((pEid->Eid == IE_WPA) && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)))
982 {
983 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA || pEntry->AuthMode == Ndis802_11AuthModeWPAPSK) &&
984 (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
985 (pEntry->RSNIE_Len == (pEid->Len + 2)))
986 {
987 result = TRUE;
988 }
989
990 *Offset += (pEid->Len + 2);
991 }
992
993 else if ((pEid->Eid == IE_RSN) && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3)))
994 {
995 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2 || pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) &&
996 (NdisEqualMemory(pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) &&
997 (pEntry->RSNIE_Len == (pEid->Len + 2)))
998 {
999 result = TRUE;
1000 }
1001
1002 *Offset += (pEid->Len + 2);
1003 }
1004 else
1005 {
1006 break;
1007 }
1008
1009 pVIE += (pEid->Len + 2);
1010 len -= (pEid->Len + 2);
1011 }
1012
1013
1014 return result;
1015
1016}
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035BOOLEAN RTMPParseEapolKeyData(
1036 IN PRTMP_ADAPTER pAd,
1037 IN PUCHAR pKeyData,
1038 IN UCHAR KeyDataLen,
1039 IN UCHAR GroupKeyIndex,
1040 IN UCHAR MsgType,
1041 IN BOOLEAN bWPA2,
1042 IN MAC_TABLE_ENTRY *pEntry)
1043{
1044 PKDE_ENCAP pKDE = NULL;
1045 PUCHAR pMyKeyData = pKeyData;
1046 UCHAR KeyDataLength = KeyDataLen;
1047 UCHAR GTKLEN = 0;
1048 UCHAR DefaultIdx = 0;
1049 UCHAR skip_offset;
1050
1051
1052 if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_3)
1053 {
1054
1055 if (!RTMPCheckRSNIE(pAd, pKeyData, KeyDataLen, pEntry, &skip_offset))
1056 {
1057
1058 if (pAd->CommonCfg.bWirelessEvent)
1059 RTMPSendWirelessEvent(pAd, IW_RSNIE_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0);
1060
1061 DBGPRINT(RT_DEBUG_ERROR, ("RSN_IE Different in msg %d of 4-way handshake!\n", MsgType));
1062 hex_dump("Receive RSN_IE ", pKeyData, KeyDataLen);
1063 hex_dump("Desired RSN_IE ", pEntry->RSN_IE, pEntry->RSNIE_Len);
1064
1065 return FALSE;
1066 }
1067 else
1068 {
1069 if (bWPA2 && MsgType == EAPOL_PAIR_MSG_3)
1070 {
1071
1072 pMyKeyData += skip_offset;
1073 KeyDataLength -= skip_offset;
1074 DBGPRINT(RT_DEBUG_TRACE, ("RTMPParseEapolKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", skip_offset));
1075 }
1076 else
1077 return TRUE;
1078 }
1079 }
1080
1081 DBGPRINT(RT_DEBUG_TRACE,("RTMPParseEapolKeyData ==> KeyDataLength %d without RSN_IE \n", KeyDataLength));
1082
1083
1084 if (bWPA2 && (MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1))
1085 {
1086 if (KeyDataLength >= 8)
1087 {
1088 pKDE = (PKDE_ENCAP) pMyKeyData;
1089
1090
1091 DefaultIdx = pKDE->GTKEncap.Kid;
1092
1093
1094 if (KeyDataLength < (pKDE->Len + 2))
1095 {
1096 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: The len from KDE is too short \n"));
1097 return FALSE;
1098 }
1099
1100
1101 GTKLEN = pKDE->Len -6;
1102 if (GTKLEN < LEN_AES_KEY)
1103 {
1104 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key length is too short (%d) \n", GTKLEN));
1105 return FALSE;
1106 }
1107
1108 }
1109 else
1110 {
1111 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: KDE format length is too short \n"));
1112 return FALSE;
1113 }
1114
1115 DBGPRINT(RT_DEBUG_TRACE, ("GTK in KDE format ,DefaultKeyID=%d, KeyLen=%d \n", DefaultIdx, GTKLEN));
1116
1117 pMyKeyData += 8;
1118 KeyDataLength -= 8;
1119
1120 }
1121 else if (!bWPA2 && MsgType == EAPOL_GROUP_MSG_1)
1122 {
1123 DefaultIdx = GroupKeyIndex;
1124 DBGPRINT(RT_DEBUG_TRACE, ("GTK DefaultKeyID=%d \n", DefaultIdx));
1125 }
1126
1127
1128 if (DefaultIdx < 1 || DefaultIdx > 3)
1129 {
1130 DBGPRINT(RT_DEBUG_ERROR, ("ERROR: GTK Key index(%d) is invalid in %s %s \n", DefaultIdx, ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
1131 return FALSE;
1132 }
1133
1134
1135#ifdef CONFIG_STA_SUPPORT
1136
1137#endif
1138
1139 return TRUE;
1140
1141}
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192VOID ConstructEapolMsg(
1193 IN PRTMP_ADAPTER pAd,
1194 IN UCHAR AuthMode,
1195 IN UCHAR WepStatus,
1196 IN UCHAR GroupKeyWepStatus,
1197 IN UCHAR MsgType,
1198 IN UCHAR DefaultKeyIdx,
1199 IN UCHAR *ReplayCounter,
1200 IN UCHAR *KeyNonce,
1201 IN UCHAR *TxRSC,
1202 IN UCHAR *PTK,
1203 IN UCHAR *GTK,
1204 IN UCHAR *RSNIE,
1205 IN UCHAR RSNIE_Len,
1206 OUT PEAPOL_PACKET pMsg)
1207{
1208 BOOLEAN bWPA2 = FALSE;
1209
1210
1211 if ((AuthMode == Ndis802_11AuthModeWPA2) || (AuthMode == Ndis802_11AuthModeWPA2PSK))
1212 bWPA2 = TRUE;
1213
1214
1215 pMsg->ProVer = EAPOL_VER;
1216 pMsg->ProType = EAPOLKey;
1217
1218
1219 pMsg->Body_Len[1] = LEN_EAPOL_KEY_MSG;
1220
1221
1222 if (bWPA2)
1223 pMsg->KeyDesc.Type = WPA2_KEY_DESC;
1224 else
1225 pMsg->KeyDesc.Type = WPA1_KEY_DESC;
1226
1227
1228
1229 pMsg->KeyDesc.KeyInfo.KeyDescVer =
1230 (((WepStatus == Ndis802_11Encryption3Enabled) || (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) : (DESC_TYPE_TKIP));
1231
1232
1233 if (MsgType >= EAPOL_GROUP_MSG_1)
1234 pMsg->KeyDesc.KeyInfo.KeyType = GROUPKEY;
1235 else
1236 pMsg->KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
1237
1238
1239 if (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))
1240 pMsg->KeyDesc.KeyInfo.KeyIndex = DefaultKeyIdx;
1241
1242 if (MsgType == EAPOL_PAIR_MSG_3)
1243 pMsg->KeyDesc.KeyInfo.Install = 1;
1244
1245 if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1))
1246 pMsg->KeyDesc.KeyInfo.KeyAck = 1;
1247
1248 if (MsgType != EAPOL_PAIR_MSG_1)
1249 pMsg->KeyDesc.KeyInfo.KeyMic = 1;
1250
1251 if ((bWPA2 && (MsgType >= EAPOL_PAIR_MSG_3)) || (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1)))
1252 {
1253 pMsg->KeyDesc.KeyInfo.Secure = 1;
1254 }
1255
1256 if (bWPA2 && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
1257 {
1258 pMsg->KeyDesc.KeyInfo.EKD_DL = 1;
1259 }
1260
1261
1262 *(USHORT *)(&pMsg->KeyDesc.KeyInfo) = cpu2le16(*(USHORT *)(&pMsg->KeyDesc.KeyInfo));
1263
1264
1265 {
1266 if (MsgType >= EAPOL_GROUP_MSG_1)
1267 {
1268
1269 pMsg->KeyDesc.KeyLength[1] = ((GroupKeyWepStatus == Ndis802_11Encryption2Enabled) ? TKIP_GTK_LENGTH : LEN_AES_KEY);
1270 }
1271 else
1272 {
1273
1274 pMsg->KeyDesc.KeyLength[1] = ((WepStatus == Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : LEN_AES_KEY);
1275 }
1276 }
1277
1278
1279 NdisMoveMemory(pMsg->KeyDesc.ReplayCounter, ReplayCounter, LEN_KEY_DESC_REPLAY);
1280
1281
1282
1283
1284
1285 if ((MsgType <= EAPOL_PAIR_MSG_3) || ((!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))))
1286 NdisMoveMemory(pMsg->KeyDesc.KeyNonce, KeyNonce, LEN_KEY_DESC_NONCE);
1287
1288
1289 if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))
1290 {
1291
1292 NdisMoveMemory(pMsg->KeyDesc.KeyIv, &KeyNonce[16], LEN_KEY_DESC_IV);
1293 pMsg->KeyDesc.KeyIv[15] += 2;
1294 }
1295
1296
1297
1298 if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1))
1299 {
1300 NdisMoveMemory(pMsg->KeyDesc.KeyRsc, TxRSC, 6);
1301 }
1302
1303
1304 NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
1305
1306 ConstructEapolKeyData(pAd,
1307 AuthMode,
1308 WepStatus,
1309 GroupKeyWepStatus,
1310 MsgType,
1311 DefaultKeyIdx,
1312 bWPA2,
1313 PTK,
1314 GTK,
1315 RSNIE,
1316 RSNIE_Len,
1317 pMsg);
1318
1319
1320 if (MsgType != EAPOL_PAIR_MSG_1)
1321 {
1322 CalculateMIC(pAd, WepStatus, PTK, pMsg);
1323 }
1324
1325 DBGPRINT(RT_DEBUG_TRACE, ("===> ConstructEapolMsg for %s %s\n", ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
1326 DBGPRINT(RT_DEBUG_TRACE, (" Body length = %d \n", pMsg->Body_Len[1]));
1327 DBGPRINT(RT_DEBUG_TRACE, (" Key length = %d \n", pMsg->KeyDesc.KeyLength[1]));
1328
1329
1330}
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349VOID ConstructEapolKeyData(
1350 IN PRTMP_ADAPTER pAd,
1351 IN UCHAR AuthMode,
1352 IN UCHAR WepStatus,
1353 IN UCHAR GroupKeyWepStatus,
1354 IN UCHAR MsgType,
1355 IN UCHAR DefaultKeyIdx,
1356 IN BOOLEAN bWPA2Capable,
1357 IN UCHAR *PTK,
1358 IN UCHAR *GTK,
1359 IN UCHAR *RSNIE,
1360 IN UCHAR RSNIE_LEN,
1361 OUT PEAPOL_PACKET pMsg)
1362{
1363 UCHAR *mpool, *Key_Data, *Rc4GTK;
1364 UCHAR ekey[(LEN_KEY_DESC_IV+LEN_EAP_EK)];
1365 UCHAR data_offset;
1366
1367
1368 if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2)
1369 return;
1370
1371
1372 os_alloc_mem(pAd, (PUCHAR *)&mpool, 1500);
1373
1374 if (mpool == NULL)
1375 return;
1376
1377
1378 Rc4GTK = (UCHAR *) ROUND_UP(mpool, 4);
1379
1380 Key_Data = (UCHAR *) ROUND_UP(Rc4GTK + 512, 4);
1381
1382 NdisZeroMemory(Key_Data, 512);
1383 pMsg->KeyDesc.KeyDataLen[1] = 0;
1384 data_offset = 0;
1385
1386
1387 if (RSNIE_LEN && ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3)))
1388 {
1389 if (bWPA2Capable)
1390 Key_Data[data_offset + 0] = IE_WPA2;
1391 else
1392 Key_Data[data_offset + 0] = IE_WPA;
1393
1394 Key_Data[data_offset + 1] = RSNIE_LEN;
1395 NdisMoveMemory(&Key_Data[data_offset + 2], RSNIE, RSNIE_LEN);
1396 data_offset += (2 + RSNIE_LEN);
1397 }
1398
1399
1400 if (bWPA2Capable && ((MsgType == EAPOL_PAIR_MSG_3) || (MsgType == EAPOL_GROUP_MSG_1)))
1401 {
1402
1403 Key_Data[data_offset + 0] = 0xDD;
1404
1405 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
1406 {
1407 Key_Data[data_offset + 1] = 0x16;
1408 }
1409 else
1410 {
1411 Key_Data[data_offset + 1] = 0x26;
1412 }
1413
1414 Key_Data[data_offset + 2] = 0x00;
1415 Key_Data[data_offset + 3] = 0x0F;
1416 Key_Data[data_offset + 4] = 0xAC;
1417 Key_Data[data_offset + 5] = 0x01;
1418
1419
1420 Key_Data[data_offset + 6] = (DefaultKeyIdx & 0x03);
1421 Key_Data[data_offset + 7] = 0x00;
1422
1423 data_offset += 8;
1424 }
1425
1426
1427
1428
1429 if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable) || (MsgType == EAPOL_GROUP_MSG_1))
1430 {
1431
1432 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
1433 {
1434 NdisMoveMemory(&Key_Data[data_offset], GTK, LEN_AES_KEY);
1435 data_offset += LEN_AES_KEY;
1436 }
1437 else
1438 {
1439 NdisMoveMemory(&Key_Data[data_offset], GTK, TKIP_GTK_LENGTH);
1440 data_offset += TKIP_GTK_LENGTH;
1441 }
1442
1443
1444
1445 if (MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable)
1446 {
1447 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
1448 {
1449 Key_Data[data_offset + 0] = 0xDD;
1450 Key_Data[data_offset + 1] = 0;
1451 data_offset += 2;
1452 }
1453 else
1454 {
1455 Key_Data[data_offset + 0] = 0xDD;
1456 Key_Data[data_offset + 1] = 0;
1457 Key_Data[data_offset + 2] = 0;
1458 Key_Data[data_offset + 3] = 0;
1459 Key_Data[data_offset + 4] = 0;
1460 Key_Data[data_offset + 5] = 0;
1461 data_offset += 6;
1462 }
1463 }
1464
1465
1466 if (WepStatus == Ndis802_11Encryption3Enabled)
1467 {
1468 AES_GTK_KEY_WRAP(&PTK[16], Key_Data, data_offset, Rc4GTK);
1469
1470 data_offset += 8;
1471 }
1472 else
1473 {
1474
1475
1476 pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32;
1477
1478
1479 NdisMoveMemory(ekey, pMsg->KeyDesc.KeyIv, LEN_KEY_DESC_IV);
1480 NdisMoveMemory(&ekey[LEN_KEY_DESC_IV], &PTK[16], LEN_EAP_EK);
1481 ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, ekey, sizeof(ekey));
1482 pAd->PrivateInfo.FCSCRC32 = RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, Key_Data, data_offset);
1483 WPAARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, Rc4GTK, Key_Data, data_offset);
1484 }
1485
1486 NdisMoveMemory(pMsg->KeyDesc.KeyData, Rc4GTK, data_offset);
1487 }
1488 else
1489 {
1490 NdisMoveMemory(pMsg->KeyDesc.KeyData, Key_Data, data_offset);
1491 }
1492
1493
1494 pMsg->KeyDesc.KeyDataLen[1] = data_offset;
1495 pMsg->Body_Len[1] += data_offset;
1496
1497 os_free_mem(pAd, mpool);
1498
1499}
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517VOID CalculateMIC(
1518 IN PRTMP_ADAPTER pAd,
1519 IN UCHAR PeerWepStatus,
1520 IN UCHAR *PTK,
1521 OUT PEAPOL_PACKET pMsg)
1522{
1523 UCHAR *OutBuffer;
1524 ULONG FrameLen = 0;
1525 UCHAR mic[LEN_KEY_DESC_MIC];
1526 UCHAR digest[80];
1527
1528
1529 os_alloc_mem(pAd, (PUCHAR *)&OutBuffer, 512);
1530
1531 if (OutBuffer == NULL)
1532 {
1533 DBGPRINT(RT_DEBUG_ERROR, ("!!!CalculateMIC: no memory!!!\n"));
1534 return;
1535 }
1536
1537
1538 MakeOutgoingFrame(OutBuffer, &FrameLen,
1539 pMsg->Body_Len[1] + 4, pMsg,
1540 END_OF_ARGS);
1541
1542 NdisZeroMemory(mic, sizeof(mic));
1543
1544
1545 if (PeerWepStatus == Ndis802_11Encryption3Enabled)
1546 {
1547 HMAC_SHA1(OutBuffer, FrameLen, PTK, LEN_EAP_MICK, digest);
1548 NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
1549 }
1550 else
1551 {
1552 hmac_md5(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, mic);
1553 }
1554
1555
1556 NdisMoveMemory(pMsg->KeyDesc.KeyMic, mic, LEN_KEY_DESC_MIC);
1557
1558 os_free_mem(pAd, OutBuffer);
1559}
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577NDIS_STATUS RTMPSoftDecryptBroadCastData(
1578 IN PRTMP_ADAPTER pAd,
1579 IN RX_BLK *pRxBlk,
1580 IN NDIS_802_11_ENCRYPTION_STATUS GroupCipher,
1581 IN PCIPHER_KEY pShard_key)
1582{
1583 PRXWI_STRUC pRxWI = pRxBlk->pRxWI;
1584
1585
1586
1587
1588 if (GroupCipher == Ndis802_11Encryption1Enabled)
1589 {
1590 if (RTMPSoftDecryptWEP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, pShard_key))
1591 {
1592
1593
1594 pRxWI->MPDUtotalByteCount -= 8;
1595 }
1596 else
1597 {
1598 DBGPRINT(RT_DEBUG_ERROR, ("ERROR : Software decrypt WEP data fails.\n"));
1599
1600 return NDIS_STATUS_FAILURE;
1601 }
1602 }
1603
1604 else if (GroupCipher == Ndis802_11Encryption2Enabled)
1605 {
1606 if (RTMPSoftDecryptTKIP(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, 0, pShard_key))
1607 {
1608
1609
1610 pRxWI->MPDUtotalByteCount -= 20;
1611 }
1612 else
1613 {
1614 DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptTKIP Failed\n"));
1615
1616 return NDIS_STATUS_FAILURE;
1617 }
1618 }
1619
1620 else if (GroupCipher == Ndis802_11Encryption3Enabled)
1621 {
1622 if (RTMPSoftDecryptAES(pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount , pShard_key))
1623 {
1624
1625
1626 pRxWI->MPDUtotalByteCount -= 16;
1627 }
1628 else
1629 {
1630 DBGPRINT(RT_DEBUG_ERROR, ("ERROR : RTMPSoftDecryptAES Failed\n"));
1631
1632 return NDIS_STATUS_FAILURE;
1633 }
1634 }
1635 else
1636 {
1637
1638 return NDIS_STATUS_FAILURE;
1639 }
1640
1641 return NDIS_STATUS_SUCCESS;
1642
1643}
1644
1645