summaryrefslogtreecommitdiff
path: root/network/wlan/WDI/HEADER/SecurityType.h
blob: e3cab0ca26347349080d29dda93600446a8ed7bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
#ifndef __INC_SECURITYTYPE_H
#define __INC_SECURITYTYPE_H

#define		MAX_KEY_LEN				61

#define		KEY_BUF_SIZE			5

#define		TKIP_ENC_KEY_LEN		16		// Added by Annie, 2005-07-05.		
#define		TKIP_MIC_KEY_LEN		8
#define		TKIP_MIC_LEN			8
#define		TKIP_KEY_LEN			(TKIP_ENC_KEY_LEN+TKIP_MIC_KEY_LEN*2)
#define		BIP_KEY_LEN				16

#define		MAXRSNIELEN				256
#define		WEP_IV_LEN				4		// Added by Annie, 2005-12-23.
#define		EXT_IV_LEN				8		// Added by Annie, 2005-12-23.
#define		KEYID_POS_IN_IV		3		// Added by Annie, 2005-12-23.

#define		WEP_ICV_LEN			4		// Added by Annie, 2006-10-19.
#define		TKIP_MIC_LEN			8		// Added by Annie, 2006-10-19.
#define		AES_MIC_LEN			8		// Added by Annie, 2006-10-19.

#define         SMS4_MIC_LEN                16
#define         WAPI_EXT_LEN                18

// Added by Annie, 2005-07-05.
#define		KEK_LEN				16
#define		KCK_LEN				16
#define		TKIP_ENC_KEY_POS		32		//(KEK_LEN+KEK_LEN)
#define		TKIP_MIC_KEY_POS		48		//(TKIP_ENC_KEY_POS+TKIP_ENC_KEY_LEN)

#define		GTK_MIC_TX_POS		16		//GTK Temporal Encryption key length
#define		GTK_MIC_RX_POS		24		//GTK Temporal Encryption key length + TKIP_MIC_KEY_LEN

// CKIP related.
#define		CKIP_KEY_LEN			16		// Added by Annie, 2006-08-17.

#define		MAX_CIPHER_SUITE_NUM		4
#define		MAX_AUTH_SUITE_NUM	4

#define		TWOWAY_HANDSHAKE_WPATKIP_LEN	183
#define		TWOWAY_HANDSHAKE_WPAAES_LEN	187
#define		TWOWAY_HANDSHAKE_2ND_LEN	151

#define		MAX_CCKM_IE_REQ_LEN			32
#define		MAX_CCKM_IE_LEN				512

#define		SW_ENCRYPT_BUF_SIZE			2400

static u1Byte WPA_OUI[SIZE_OUI] = {0x00, 0x50, 0xf2};
static u1Byte RSN_OUI[SIZE_OUI] = {0x00, 0x0F, 0xAC};

#define	WPAIE_OUI_TYPE	1


// HW/SW encryption/decryption related. 2006.09.29, by shien chang.
enum _EnryptionDecryption_Mechanism
{
	EncryptionDecryptionMechanism_Auto	= 0,
	EncryptionDecryptionMechanism_Hw	= 1,
	EncryptionDecryptionMechanism_Sw	= 2,
	EncryptionDecryptionMechanism_Undefined = 3,
};

//
// For check chiper and auth type , add by CCW 2008/09/18
//
enum _PAIRWISE_CHIPER
{
	NONE_WPA 		=  0x00,
	WPA_TKIP		=  0x02,
	WPA_AES			=  0x04,
	WPA2_TKIP		=  0x20,
	WPA2_AES		=  0x40,
};

typedef u4Byte	AKM_SUITE_TYPE, *PAKM_SUITE_TYPE;
#define	AKM_SUITE_NONE			(AKM_SUITE_TYPE)0
#define	AKM_WPA_1X				(AKM_SUITE_TYPE)0x00000001
#define	AKM_WPA_PSK				(AKM_SUITE_TYPE)0x00000002
#define	AKM_WPA_CCKM			(AKM_SUITE_TYPE)0x00000004
#define	AKM_WPA2_1X				(AKM_SUITE_TYPE)0x00000010
#define	AKM_WPA2_PSK			(AKM_SUITE_TYPE)0x00000020
#define	AKM_WPA2_CCKM			(AKM_SUITE_TYPE)0x00000040
#define	AKM_RSNA_1X_SHA256		(AKM_SUITE_TYPE)0x00000080
#define	AKM_RSNA_PSK_SHA256		(AKM_SUITE_TYPE)0x00000100
#define	AKM_FT_1X				(AKM_SUITE_TYPE)0x00000200
#define	AKM_FT_PSK				(AKM_SUITE_TYPE)0x00000400
#define	AKM_1X_CCKM				(AKM_SUITE_TYPE)0x00000800

#define	IS_AKM_SUPPORT_SHA_256(_AkmSuite) TEST_FLAG(_AkmSuite, AKM_RSNA_1X_SHA256 | AKM_RSNA_PSK_SHA256 | AKM_FT_1X | AKM_FT_PSK)

#if(OS_WIN_FROM_WIN10(OS_VERSION))
	#define	DEFAULT_SUPPORT_AKM_SUITE	(AKM_WPA_1X | AKM_WPA_PSK | AKM_WPA2_1X | AKM_WPA2_PSK | AKM_WPA_CCKM | AKM_WPA2_CCKM | AKM_RSNA_1X_SHA256 | AKM_RSNA_PSK_SHA256 | AKM_FT_1X | AKM_FT_PSK)
#elif (OS_WIN_FROM_WIN8(OS_VERSION))
	#define	DEFAULT_SUPPORT_AKM_SUITE	(AKM_WPA_1X | AKM_WPA_PSK | AKM_WPA2_1X | AKM_WPA2_PSK | AKM_WPA_CCKM | AKM_WPA2_CCKM | AKM_RSNA_1X_SHA256 | AKM_RSNA_PSK_SHA256)
#elif (RT_PLATFORM==PLATFORM_WINDOWS)
	#define	DEFAULT_SUPPORT_AKM_SUITE	(AKM_WPA_1X | AKM_WPA_PSK | AKM_WPA2_1X | AKM_WPA2_PSK | AKM_WPA_CCKM | AKM_WPA2_CCKM)
#else
	#define	DEFAULT_SUPPORT_AKM_SUITE	(AKM_WPA_1X | AKM_WPA_PSK | AKM_WPA2_1X | AKM_WPA2_PSK)
#endif


#define	AKM_WPA_1X_OUI_TYPE		1
#define	AKM_WPA_PSK_OUI_TYPE	2

//======================================================================================
// AES_CCMP specific
//======================================================================================

#define AESMSK_FC_DEFAULT			0xC78F	// default value of AES MASK for Frame Control Field. (2 bytes)
#define AESMSK_SC_DEFAULT			0x000F	// default value of AES MASK for Sequence Control Field. (2 bytes)
#define AESMSK_QC_DEFAULT			0x000F	// default value of AES MASK for QoS Control Field. (2 bytes)

enum
{
	AESCCMP_BLK_SIZE			=   16,     // # octets in an AES block
	//AESCCMP_MAX_PACKET 		=   4*512,  // largest packet size   //YJ,test for DTM MPE,120218
	AESCCMP_MAX_PACKET 		=   5*512,  // largest packet size
	AESCCMP_N_RESERVED		=   0,      // reserved nonce octet value
	AESCCMP_A_DATA			=   0x40,   // the Adata bit in the flags
	AESCCMP_M_SHIFT			=   3,      // how much to shift the 3-bit M field
	AESCCMP_L_SHIFT			=   0,      // how much to shift the 3-bit L field
	AESCCMP_L_SIZE			=   2,       // size of the l(m) length field (in octets)
	AESCCMP_OFFSET_SC		=	22,
	AESCCMP_OFFSET_DURATION	=	4,
	AESCCMP_OFFSET_A2		=	10,
	AESCCMP_OFFSET_A4		=	24,
	AESCCMP_QC_TID_MASK		=	0x0f,
	AESCCMP_BLK_SIZE_TOTAL	=   16*16,     // Added by Annie for CKIP AES MIC BSOD, 2006-08-17.
											// 16*8 < 4*60  Resove to 16*16
};
typedef union _AESCCMP_BLOCK		// AES cipher block
{
	u4Byte	x[AESCCMP_BLK_SIZE/4];		// access as 8-bit octets or 32-bit words
	u1Byte	b[AESCCMP_BLK_SIZE];
}AESCCMP_BLOCK;

typedef struct _AESCCMP_PACKET
{
	BOOLEAN			encrypted;		 // TRUE if encrypted
	u1Byte			TA[6];			// xmit address
	u4Byte			micLength;		// # octets of MIC appended to plaintext (M)
	u4Byte			ivLength;
	u4Byte			clrCount;		// # cleartext octets covered by MIC
	u4Byte			pktNum[2];		// unique packet sequence number (like WEP IV)
	AESCCMP_BLOCK	key;			// the encryption key (K)
	u4Byte			length;			// # octets in data[]
	u1Byte			*data;
	u1Byte			dataArray[AESCCMP_MAX_PACKET+ 2*AESCCMP_BLK_SIZE];		// packet contents
}AESCCMP_PACKET;

// Ref: IEEE 802.11 2012 8.4.2.27.2 Cipher suites
typedef u4Byte	RT_ENC_ALG,*PRT_ENC_ALG;
#define	RT_ENC_ALG_NO_CIPHER						0x00000000
#define	RT_ENC_ALG_USE_GROUP						0x00000001	// Use Group Key
#define	RT_ENC_ALG_TKIP								0x00000002
#define	RT_ENC_ALG_AESCCMP							0x00000004
#define	RT_ENC_ALG_WEP40							0x00000008
#define	RT_ENC_ALG_WEP104							0x00000010
#define	RT_ENC_ALG_WEP								(RT_ENC_ALG_WEP40 | RT_ENC_ALG_WEP104)
#define	RT_ENC_ALG_SMS4								0x00000020	// WAPI
#define	RT_ENC_ALG_BIP								0x00000040	// PMF multicast protected management frame
#define	RT_ENC_ALG_GROUP_ADDR_TRAFFIC_DISALLOWED	0x00000080

// Ref: 802.11i sepc D10.0 7.3.2.25.1 Cipher Suites
//Encryption Algorithms
//2 // Note: The following encryption algorithm is deprecated, do not use again.
typedef enum{
	NO_Encryption			= 0,
	WEP40_Encryption		= 1,
	TKIP_Encryption			= 2,
	Reserved_Encryption		= 3,
	AESCCMP_Encryption 	= 4,
	WEP104_Encryption		= 5,
	WEP_Encryption    		= 6, // WEP + WPA
	SMS4_Encryption             =7,
	Max_Encryption			=0xFF
	//WEP_Encryption = 7,

}RT_ENC_ALG_DEP, *PRT_ENC_ALG_DEP;


typedef enum _RT_AUTH_MODE
{
    RT_802_11AuthModeOpen,
    RT_802_11AuthModeShared,
    RT_802_11AuthModeAutoSwitch,
    RT_802_11AuthModeWPA,
    RT_802_11AuthModeWPAPSK,
    RT_802_11AuthModeWPANone,
    RT_802_11AuthModeWPA2,
    RT_802_11AuthModeWPA2PSK,
    RT_802_11AuthModeCCKM,
    RT_802_11AuthModeWAPI,
    RT_802_11AuthModeCertificateWAPI, 
    //===== Add new Mode above this line=====//
    RT_802_11AuthModeMax,

	RT_NETWORK_EAP = 0x80,
    
} RT_AUTH_MODE, *PRT_AUTH_MODE;

typedef enum _RT_802_11_WEP_STATUS
{
    RT802_11WEPEnabled,
    RT802_11Encryption1Enabled = RT802_11WEPEnabled,
    RT802_11WEPDisabled,
    RT802_11EncryptionDisabled = RT802_11WEPDisabled,
    RT802_11WEPKeyAbsent,
    RT802_11Encryption1KeyAbsent = RT802_11WEPKeyAbsent,
    RT802_11WEPNotSupported,
    RT802_11EncryptionNotSupported = RT802_11WEPNotSupported,
    RT802_11Encryption2Enabled, 
    RT802_11Encryption2KeyAbsent,
    RT802_11Encryption3Enabled, 
    RT802_11Encryption3KeyAbsent,
    Wapi_Encryption,
    Wapi_Certificate

} RT_802_11_WEP_STATUS, *PRT_802_11_WEP_STATUS, RT_802_11_ENCRYPTION_STATUS, *PRT_802_11_ENCRYPTION_STATUS;

typedef enum _RT_SECURITY_LEVEL
{
	RT_SEC_LVL_NONE = 0,
	RT_SEC_LVL_WPA,
	RT_SEC_LVL_WPA2,
	RT_SEC_LVL_WAPI

}RT_SECURITY_LEVEL, *PRT_SECURITY_LEVEL;

typedef struct _RT_PMKID_TYPE
{
	u1Byte flag;
}RT_PMKID_TYPE, *PRT_PMKID_TYPE;

#define MAX_DENY_BSSID_LIST_CNT 20
typedef struct _RT_DENY_BSSID
{
	BOOLEAN	bUsed;
	u8Byte	StartTime;
	u1Byte	Bssid[6];
}RT_DENY_BSSID, *PRT_DENY_BSSID;


// WPA2 Parameters
#define NUM_PRE_AUTH_KEY	16					// Reference NumOfPreAuthKey in 8185. Added by Annie, 2006-05-07.
#define NUM_PMKID_CACHE	NUM_PRE_AUTH_KEY	// Added by Annie, 2006-05-07.
#define NUM_CAT_PMKID		1					// Added by Annie, 2006-05-07.
#define PMKID_LEN			16

typedef struct _RT_PMKID_LIST
{
	BOOLEAN						bUsed;
	u1Byte 						Bssid[6];
	u1Byte						PMKID[PMKID_LEN];
	u1Byte						SsidBuf[33];
	OCTET_STRING				Ssid;
} RT_PMKID_LIST, *PRT_PMKID_LIST;

typedef struct _DOT11_RSN_IE_PMKID
{
	u2Byte		SuiteCount;
	u1Byte		PMKList[1];
} DOT11_RSN_IE_PMKID, *PDOT11_RSN_IE_PMKID;


//
// CCX 1 S13: CKIP Related Parameters.
// Revised by Annie, 2006-08-14.
//
#define IE_CISCO_CWMIN_POSITION	0x04
#define IE_CISCO_CWMAX_POSITION	0x06
#define IE_CISCO_FLAG_POSITION		0x08	// Flag byte: byte 8, numbered from 0.
#define SUPPORT_CKIP_MIC			0x08	// bit3
#define SUPPORT_CKIP_PK			0x10	// bit4
typedef struct _CKIP_PARAMETER
{
	DECLARE_RT_OBJECT(CKIP_PARAMETER);

	BOOLEAN				bIsKP;
	BOOLEAN				bIsMIC;
	BOOLEAN				bCkipSupported;		// Aironet IE support CKIP or not.
	ULONG				ulSeqUpLink;
	u1Byte				CKIPKeyBuf[KEY_BUF_SIZE][CKIP_KEY_LEN];
} CKIP_PARAMETER, *PCKIP_PARAMETER;


//
// Add for RSNA Per-station default Key ,by CCW
// Per-Sta default key is used for group traffic.
//
typedef struct _PER_STA_DEFAULT_KEY_ENTRY
{
	u1Byte                      MACAdrss[6];
	BOOLEAN                  Valid;
	u1Byte			    DefKeyBuf[4][AESCCMP_BLK_SIZE_TOTAL];
	BOOLEAN                  DefkeyValid[4];
}PER_STA_DEFAULT_KEY_ENTRY,*PPER_STA_DEFAULT_KEY_ENTRY;

//
// Add for RSNA Per-station mapping Key ,by CCW
// Per-Sta key mapping key for unicast traffic.
//
typedef struct _PER_STA_MPAKEY_ENTRY
{
	u1Byte                      MACAdrss[6];
	BOOLEAN                  Valid;
	u1Byte                      MapKeyBuf[AESCCMP_BLK_SIZE_TOTAL];
}PER_STA_MPAKEY_ENTRY,*PPER_STA_MPAKEY_ENTRY;

#define MAX_NUM_PER_STA_KEY		12
// TSC in TKIP and PN in AES shall be initialized to 1 in 802.11i.
// The spec doesn't determine the initialized value so we set the same value.
// When the temporal key (including wep) is reset, we need to refresh the Tx IV.
// By Bruce, 2010-11-04.
#define	DEFAULT_INIT_TX_IV			1
// 0 means we don't check the rx IV as the IV replay attack.
#define	DEFAULT_INIT_RX_IV			0

typedef enum _RT_SA_QUERY_STATE
{
	RT_SA_QUERY_STATE_UNINITIALIZED = 0,
	RT_SA_QUERY_STATE_SA_DETECTED = 0,
	RT_SA_QUERY_STATE_SA_REQ_IN_PROGRESS,
	//=== Insert new method above this line === //
	RT_SA_QUERY_STATE_MAX,	// Reserved
	RT_SA_QUERY_STATE_FORCE_UINT32 = 0xFFFFFFFF	//Reserved, force this enumeration to compile to 32 bits in size (by Win SDK 8.0).
}RT_SA_QUERY_STATE, *PRT_SA_QUERY_STATE;
//Security information structure
typedef struct _RT_SECURITY_T{

	//Encryption Algorithm for Unicast Packet
	RT_ENC_ALG		PairwiseEncAlgorithm;

	//Encryption Algorithm for Brocast/Multicast
	RT_ENC_ALG		GroupEncAlgorithm;
	RT_ENC_ALG		GroupEncAlgorithmCap;	// Capability/Combination of group cipher suites

	BOOLEAN			UseDefaultKey;		// Set if default key used

	//The Index of Default Key(WEP)
	u1Byte			DefaultTransmitKeyIdx;

	//The index of Group Transmit Key
	u1Byte			GroupTransmitKeyIdx;

	//Key buffer
	u1Byte			KeyBuf[KEY_BUF_SIZE][MAX_KEY_LEN];
	u1Byte			KeyLen[KEY_BUF_SIZE];

	//2004/09/15, for AES
	u1Byte			AESKeyBuf[KEY_BUF_SIZE][AESCCMP_BLK_SIZE_TOTAL];

	//The pointer of Pairwise Key, it always points to KeyBuf[4]
	pu1Byte			PairwiseKey;
	
	u1Byte			TxMICKey[TKIP_MIC_KEY_LEN];		//  Tx MIC Key
	u1Byte			RxMICKey[TKIP_MIC_KEY_LEN];		//  Rx MIC Key

	BOOLEAN			SWTxEncryptFlag;	// Software send encrypt flag
	BOOLEAN			SWRxDecryptFlag;	// Software recv decrypt flag
	BOOLEAN			SWRxAESMICFlag;			// Software TKIP MIC flag
	BOOLEAN			bGroupKeyFixed;	// Can not modify group key
	// Manual config read from system to force HW or SW encryption/decryption.
	// 0: Auto.  1: HW enc/dec.  2: SW enc/dec. 2006.09.29, by shien chang.
	u1Byte			RegSWTxEncryptFlag;
	u1Byte			RegSWRxDecryptFlag;

	u1Byte			EncryptionHeadOverhead;
	u1Byte			EncryptionTailOverhead;

	RT_AUTH_MODE						AuthMode;

	RT_802_11_ENCRYPTION_STATUS		EncryptionStatus;

	OCTET_STRING	RSNIE;
	u1Byte			RSNIEBuf[MAXRSNIELEN];

	u8Byte			TxIV;

	RT_SECURITY_LEVEL	SecLvl;

	u1Byte					AssocInfo[512];
	
	//---------------------------------------------------------------------------
	// For MIC failure.
	//---------------------------------------------------------------------------
	u8Byte			LastPairewiseTKIPMICErrorTime;	// Last pairewise key TKIP MIC error happen time or 0 if it has not happed in 60 seconds.
	BOOLEAN			bToDisassocAfterMICFailureReportSend;	// Disassociate from the AP for twice MIC failure in 60 seconds.
	RT_DENY_BSSID	DenyBssidList[MAX_DENY_BSSID_LIST_CNT]; // List of BSS denied by us for MIC failure. 	  


	//---------------------------------------------------------------------------
	// For WPA2 Pre-Authentication.
	//---------------------------------------------------------------------------
	BOOLEAN				RegEnablePreAuth;				// Default value: Pre-Authentication enabled or not, from registry "EnablePreAuth". Added by Annie, 2005-11-01.
	BOOLEAN				EnablePreAuthentication;			// Current Value: Pre-Authentication enabled or not.
	RT_PMKID_LIST		PMKIDList[NUM_PMKID_CACHE];	// Renamed from PreAuthKey[NUM_PRE_AUTH_KEY]. Annie, 2006-10-13.
	u4Byte				PMKIDCount;						// Added by Annie, 2006-10-13.
	u1Byte				szCapability[256];				// For WPA2-PSK using zero-config, by Annie, 2005-09-20.


	//---------------------------------------------------------------------------
	// For Software AES Encryption.
	//---------------------------------------------------------------------------
	AESCCMP_PACKET	AESCCMP_Packet;
	AESCCMP_PACKET 	RX_AESCCMP_Packet;
	u4Byte			AESCCMPMicLen ;
	
	//
	// For CKIP. Revised by Annie, 2006-08-14.
	//
	PCKIP_PARAMETER	pCkipPara;
	//---------------------------------------
	//For CCKM KRK key , by CCW
	//---------------------------------------
	u1Byte                 KRK[128];
	OCTET_STRING	CCKMReqIE;
	u1Byte			CCKMReqIEBuf[MAX_CCKM_IE_REQ_LEN];
	OCTET_STRING	CCKMIE;
	u1Byte			CCKMIEBuf[MAX_CCKM_IE_LEN];
	
	//--------------------------------------
	// For NDIS6 RSNA, by CCW
	//--------------------------------------
	// TODO: remvoe our group key from PerStaDefKeyTable[]
	PER_STA_DEFAULT_KEY_ENTRY		PerStaDefKeyTable[MAX_NUM_PER_STA_KEY]; // Keep group key of each STA in the IBSS.
	PER_STA_MPAKEY_ENTRY			MAPKEYTable[MAX_NUM_PER_STA_KEY]; // Keep pairwise key of each STA in the IBSS.
	
	//
	// For Check IV 
	//
	u8Byte			RXMutiIV;	// Rx multicast IV for IV replay check, and 0 means do not check IV replay.
	u8Byte			RXUntiIV;	// Rx unicast IV for IV replay check, and 0 means do not check IV replay.

	u1Byte			SecBuffer[SW_ENCRYPT_BUF_SIZE];

	// 802.11w BIP
	u1Byte				BIPKeyBuffer[MAX_KEY_LEN];
	u1Byte				IPN[6];
	RT_TIMER			SAQueryTimer;
	RT_SA_QUERY_STATE	pmfSaState;
	u2Byte				SAReqIdentifier;
}RT_SECURITY_T, *PRT_SECURITY_T;



//------------------------------------------------------------------------------
// Authenticator related operations. Added by Annie, 2005-06-28.
//------------------------------------------------------------------------------

//
// Key Length
//
// Reference:
// 1. Code from AP team: auth\include\1x_kmsm_keydef.h
//

#define LIB1X_EAPOL_HDRLEN		4	// defined in auth\include\1x_eapol.h, from AP team.

#define PASSPHRASE_LEN			64	// modified by Annie, 2005-07-01.

#define PMK_LEN					32
#define PTK_LEN					64
#define PTK_LEN_TKIP			64
#define PTK_LEN_NO_TKIP		48      //for CCMP, WRAP, WEP
#define PTK_LEN_CCMP			48
#define PTK_LEN_WRAP			48
#define PTK_LEN_WEP			48

#define PTK_LEN_EAPOLMIC		16
#define PTK_LEN_EAPOLENC		16

#define GMK_LEN					32
#define GTK_LEN					32
#define GTK_LEN_TKIP			32      //32 for TKIP and 16 for CCMP, WRAP, WEP
#define GTK_LEN_NO_TKIP		16
#define GTK_LEN_CCMP			16
#define GTK_LEN_WRAP			16
#define GTK_LEN_WEP			16


#define INFO_ELEMENT_SIZE		128

#define EAP_HDR_LEN				(sMacHdrLng+LLC_HEADER_SIZE+TYPE_LENGTH_FIELD_SIZE)		// added by Annie, 2005-07-04.

#define MAX_EAPOLMSG_LEN		512
#define MAX_EAPOLKEYMSG_LEN	(MAX_EAPOLMSG_LEN-(ETHERNET_HEADER_SIZE+LIB1X_EAPOL_HDRLEN))
#define EAPOLMSG_HDRLEN		95      //EAPOL-key payload length without KeyData

#define KEY_RC_LEN				8
#define KEY_NONCE_LEN			32
#define KEY_IV_LEN				16
#define KEY_RSC_LEN				8
#define KEY_ID_LEN				8
#define KEY_MIC_LEN				16
#define KEY_MATERIAL_LEN		2

#define DescTypePos				0
#define KeyInfoPos				1
#define KeyLenPos				3
#define ReplayCounterPos			5
#define KeyNoncePos				13
#define KeyIVPos					45
#define KeyRSCPos				61
#define KeyIDPos					69
#define KeyMICPos				77
#define KeyDataLenPos			93
#define KeyDataPos				95

#define MAX_TIMEOUT_CNT		3

//
// Key management
//
// Reference:
// 1. IEEE 802.11i/D3.0  8.5.6.1 & state machine diagram in Figure 53(p.113)
// 2. Code from AP team: auth\include\1x_kmsm.h
//

// Definition of events in ASM (Authenticator state machine)
typedef enum _ASM_EVENT_ID { 
	ASMEID_NoEvent,
	ASMEID_AssociationRequest,
	ASMEID_ReAssociationRequest,
	ASMEID_AuthenticationRequest,
	ASMEID_ReAuthenticationRequest,
	ASMEID_AuthenticationSuccess,
	ASMEID_Disconnect,
	ASMEID_DeauthenticationRequest,
	ASMEID_Init,
	ASMEID_Disassociate,
	ASMEID_IntegrityFailure,
	ASMEID_EAPOLKeyRecvd,
	ASMEID_TimeOut,
	ASMEID_TimeOutExceeded,
} ASM_EVENT_ID, *PASM_EVENT_ID;



// Definition of PTK key state in ASM
// Ref: 8.5.6, page 111, 802.11 D3.0.
typedef enum _ASM_PAIRWISEKEY_STATE {
	//ASMPS_DEAUTHENTICATE,
	ASMPS_INITIALIZE,
	ASMPS_DISCONNECTE,
	ASMPS_DISCONNECTED,
	ASMPS_AUTHENTICATION,
	ASMPS_AUTHENTICATION2,		// described on Fig.53. 802.11i D3.0.
	ASMPS_INITPMK, 
	ASMPS_INITPSK,
	ASMPS_PTKSTART,
	ASMPS_PTKINITNEGOTIATING,
	ASMPS_PTKINITDONE,
	ASMPS_UPDATEKEYS,
	ASMPS_MICFAILURE,
	ASMPS_INTEGRITYFAILURE,		// Added by Annie, 2005-07-18.
	ASMPS_KEYUPDATE,
	ASMPS_ERRORHANDLE,			// Added states 
}ASM_PAIRWISEKEY_STATE, *PASM_PAIRWISEKEY_STATE;


// Definition of PTK group key (GTK) state in ASM
// Ref: 8.5.6, page 112, 802.11 D3.0.
typedef enum _ASM_GROUPKEY_STATE {
	ASMGS_INITIALIZE,
	ASMGS_REKEYNEGOTIATING,
	ASMGS_REKEYESTABLISHED,
	ASMGS_KEYERROR,
//	ASMGS_SETKEYS,
//	ASMGS_SETKEYSDONE,
} ASM_GROUPKEY_STATE, *PASM_GROUPKEY_STATE;

typedef enum _PORT_MODE_TYPE {
//	pmt_ForceUnauthorized,		// Rewrited as pmt_Disable by Annie
//	pmt_ForceAuthorized,		// Rewrited as pmt_Enable by Annie
	pmt_Disable,
	pmt_Enable,
	pmt_Auto
} PORT_MODE_TYPE, *PPORT_MODE_TYPE;

// defined by Annie, 2005-07-01.
typedef enum _PORT_CONTROL_TYPE {
	pct_Unauthorized,
	pct_Authorized,
	pct_Auto
} PORT_CONTROL_TYPE, *PPORT_CONTROL_TYPE;

// defined by Annie, 2005-07-01.
typedef enum _PORT_SECURE_TYPE {
	psec_Unauthorized,
	psec_Authorized
} PORT_SECURE_TYPE, *PPORT_SECURE_TYPE;


typedef struct _AUTH_PKEY_MGNT_TAG{
	
	//2 machine state

       ASM_PAIRWISEKEY_STATE	PrState;
	ASM_GROUPKEY_STATE		GrState;
	ASM_EVENT_ID			EvntID;

	//2 Variables

	struct _RT_WLAN_STA*	pWLanSTA;		// added by Annie

	//2004/06/29, kcwu, for WPA RSN-IE
//	u1Byte						IEBuf[1024];
//	OCTET_STRING				IE;
	RT_SECURITY_LEVEL			SecLvl;
	u1Byte						SecIEBuf[64];
	u1Byte						SecIELen;
	u2Byte						SecVersion;
	RT_ENC_ALG					GroupCipherSuite;
	RT_ENC_ALG					PairwiseCipherSuite[MAX_CIPHER_SUITE_NUM];
	u2Byte						PairwiseCipherCount;
	AKM_SUITE_TYPE				AuthSuite[MAX_AUTH_SUITE_NUM];
	u2Byte						AuthSuiteCount;	

	BOOLEAN						bPreAuth;
	u1Byte						NumOfPTKReplayCounter;
	u1Byte						NumOfGTKReplayCounter;

	PORT_MODE_TYPE				portMode;
	PORT_CONTROL_TYPE			portControl;
	PORT_SECURE_TYPE			portSecure;	// moved to global. Annie, 2005-07-01.

	u1Byte			TimeoutCtr;
	u8Byte			TimeSlot_sendstart;			// Record the time slot at sending 1st message in 4-way handshake.
	u8Byte			TimeSlot_lastsend;			// Record the time slot at received last EAPOL-key.
// 	//sc_yang
//	int				TickCnt;
//	BOOLEAN			L2Failure;
	BOOLEAN			MICVerified;

	BOOLEAN			Pair;					    // If Unicast cipher supported by Authenticator, set it TRUE. Jay 0708
	BOOLEAN			GInitAKeys;					// It is set to TRUE when the Group key update state machine is required. Jay 0708
	BOOLEAN			PInitAKeys;					// It is set to TRUE when the Authenticator is ready to send a Group key to its Supplicant after initialization. Jay 0708
	                                            // I use it to replace bPTKInstalled according to sepc. Annie, 2005-07-02.
//	OCTET_STRING	ANonce;
//	OCTET_STRING	SNonce; //added by Emily
	u8Byte			KeyReplayCounter;
	u1Byte			SNonce[KEY_NONCE_LEN];
	u1Byte			PTK[PTK_LEN];
	u1Byte			PTK_update[PTK_LEN];			// Used in key updateding. Added by Annie, 2005-07-12.
	u1Byte			ANonce[KEY_NONCE_LEN];

	pu1Byte			TempEncKey;				// Temporal Encryption Key
	pu1Byte			TxMICKey;					// Tx MIC Key
	pu1Byte			RxMICKey;					// Rx MIC Key
	
#if 1 //Added by Jay 0712 for security IV
	u8Byte			TxIV;
	u8Byte			RxIV;
	u8Byte			KeyRSC;
#endif
#if 1//Added by Jay 0713 for processing integrity failure
	u8Byte			TimeSlot_lastIntegrityFailed; 
#endif

	int				MicErrorCnt;		// Added by Annie for debug, 2005-07-25.
	int				WEPErrorCnt;

	//AP-WPA AES ,CCW
	u1Byte			AESKeyBuf[AESCCMP_BLK_SIZE_TOTAL];

}AUTH_PKEY_MGNT_TAG, *PAUTH_PKEY_MGNT_TAG;


#define	NumGroupKey	1	// Group key number: currently we use only one group key. Annie, 2005-06-28.


typedef struct _AUTH_GLOBAL_KEY_TAG
{

	int					currentId;		// Id for current authentication session
	int					receivedId;
	
        OCTET_STRING		EAPOLMsgRecvd;			//The Overall 802.1x message
        OCTET_STRING		EapolKeyMsgRecvd;		//The start point of eapol-key payload

	// Added by Annie, 2005-06-28.
	char					Passphrase[PASSPHRASE_LEN];		// define in char from u1Byte. Annie, 2005-07-01.
	u1Byte				PassphraseLen;
	u1Byte				PMK[PMK_LEN];
//	u1Byte				GMK[GMK_LEN];			//marked by Annie: It seems that we can use GTK directly.
	u1Byte				GTK[GTK_LEN];
	pu1Byte				TxMICKey;				// Group Tx MIC Key		// Added by Annie, 2005-07-06.
	pu1Byte				RxMICKey;				// Group Rx MIC Key
	u1Byte				AESGTK[AESCCMP_BLK_SIZE_TOTAL];
	
//	AUTH_GKEY_MGNT_TAG	groupKeyInfo;			//marked by Annie: It seems not necessary.
	u1Byte				ANonce[KEY_NONCE_LEN];
	u1Byte				GNonce[KEY_NONCE_LEN];
//	u8Byte				GroupReplayCounter;		// Added by Annie, 2005-07-02.
	u8Byte				KeyRSC;					// Added by Annie, 2005-07-02
	// End of Annie add.
	

	u1Byte				MaxRetryCounts;
	u1Byte				EventId;
	u1Byte				DescriptorType; //initialize to 254 in RSN
	u1Byte				KeyDescriptorVer;
//	u1Byte				CurrentAddress[ETHERNET_HEADER_SIZE];
	BOOLEAN				bMacAuthEnabled;

	RT_TIMER			KeyMgntTimer;			// added by Annie, 2005-06-29.
	u8Byte				CurrentTimeSlot;			// increase 1 per-second. Added by Annie, 2005-07-12.

	//RSNIE related variable
//	struct _DOT11_RSN_SUPPLICANT_VARIABLE   RSNVariable;
//	Dot11RSNConfigEntry		Dot11RSNConfig;

//	struct _Dot1x_Authenticator	*auth;
	//End Added WPA
#if 1 //Added by Jay 0713 for processing integrity failure
	u8Byte				TimeSlot_IntegrityFail2;			
#endif
} AUTH_GLOBAL_KEY_TAG, *PAUTH_GLOBAL_KEY_TAG;


#define 	KeyMgntStateIsWaitingEAPOLKey(_pKeyMgnt)									\
	(																		\
		( (_pKeyMgnt)->PrState == ASMPS_PTKSTART )				||			\
		( (_pKeyMgnt)->PrState == ASMPS_PTKINITNEGOTIATING )		||			\
		( (_pKeyMgnt)->GrState == ASMGS_REKEYNEGOTIATING )		||			\
		( (_pKeyMgnt)->GrState == ASMGS_REKEYESTABLISHED)     				\
	)

//
// Higher layer meaning and related context information for security purpose. 
// 2006.01.08, by rcnjko.
//
typedef	u4Byte	RT_SEC_PROT_INFO;
#define RT_SEC_NORMAL_DATA 0x00000000 // Default case.

// Note that! RT_SEC_EAPOL_BEFORE_KEY_INSTALLED and RT_SEC_EAPOL_AFTER_KEY_INSTALLED are mutually exclusive.
#define RT_SEC_EAPOL_BEFORE_KEY_INSTALLED 0x80000000 // EAPOL packet before PTK installed, e.g. 4-way handshake before PTK installed and so on.
#define RT_SEC_EAPOL_AFTER_KEY_INSTALLED 0x40000000 // EAPOL packet after PTK installed, e.g. 4-way handshake after PTK installed, 2-way handshake, MIC failure report and so on.

#define RT_SEC_MIC_FAILURE_REPORT 0x00000001 // MIC failure report frame.


//
// Helper macros to maniupate RT_SEC_PROT_INFO.
// 2006.01.08, by rcnjko.
//
#define IsSecProtEapolBeforeKeyInstalled(_SecProtInfo) \
	((_SecProtInfo & RT_SEC_EAPOL_BEFORE_KEY_INSTALLED) ? TRUE : FALSE)

#define IsSecProtEapolAfterKeyInstalled(_SecProtInfo) \
	((_SecProtInfo & RT_SEC_EAPOL_AFTER_KEY_INSTALLED) ? TRUE : FALSE)

#define IsSecProtEapol(_SecProtInfo) \
	((IsSecProtEapolAfterKeyInstalled(_SecProtInfo) || IsSecProtEapolBeforeKeyInstalled(_SecProtInfo)) ? TRUE : FALSE)

#define IsSecProtMicFailureReport(_SecProtInfo) \
	((_SecProtInfo & RT_SEC_MIC_FAILURE_REPORT) ? TRUE : FALSE)


//
// Per-packe encryption information structure.
// 2006.01.08, by rcnjko.
//
typedef struct _STA_ENC_INFO_T{
	RT_ENC_ALG			EncAlg;
	BOOLEAN				IsEncByHW;		// FALSE if this packet SHOULD NOT be encrypted by HW, TRUE otherwise. Note that, it is used in conjuntion with pMgntInfo->SecurityInfo.SWTxEncryptFlag to determine if we shall encrypt the packet by HW or SW.
	u1Byte				keyId;
	u2Byte                       ExemptionActionType; //0:Auto 1:encrypt 2:no encrypt 3: key UNAVAILABLE
	BOOLEAN				bMFPPacket;
	u4Byte				keylen;
	pu1Byte				keybuf;
	RT_SEC_PROT_INFO	SecProtInfo;	// Keep higher layer meaning and context information about this packet, see definition of RT_SEC_PROT_INFO for details.
}STA_ENC_INFO_T, *PSTA_ENC_INFO_T;

#define	IsCkipEnabled(_pMgntInfo) \
	( (_pMgntInfo->SecurityInfo.pCkipPara->bIsMIC || _pMgntInfo->SecurityInfo.pCkipPara->bIsKP)? TRUE : FALSE )


#endif // #ifndef __INC_SECURITYTYPE_H