summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/drivers/net/wireless/rtl8192cd/8192cd_psk.h
blob: 53626a6d05be64c9b0f0dddd946df53bd30813f8 (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
/*
 *  Header files of WPA PSK module
 *
 *  $Id: 8192cd_psk.h,v 1.1 2009/11/06 12:26:48 victoryman Exp $
 *
 *  Copyright (c) 2009 Realtek Semiconductor Corp.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 */

#ifndef _8192CD_PSK_H_
#define _8192CD_PSK_H_

#define GMK_LEN						32
#define GTK_LEN						32
#define PMK_LEN						32
#define PTK_LEN						32
#define KEY_NONCE_LEN				32
#define NumGroupKey					4
#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 PTK_LEN_EAPOLMIC        	16
#define PTK_LEN_EAPOLENC        	16
#define PTK_LEN_TKIP           		64
#define PMKID_LEN					16
#define LIB1X_ETHER_EAPOL_TYPE		0x888E

#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 LIB1X_EAPOL_VER				1		//00000001B
#define LIB1X_EAPOL_LOGOFF			2       //0000 0010B
#define LIB1X_EAPOL_EAPPKT			0       //0000 0000B
#define LIB1X_EAPOL_START			1		//0000 0001B
#define LIB1X_EAPOL_KEY				3		//0000 0011B
#define LIB1X_EAPOL_ENCASFALERT		4		//0000 0100B


#define RANDOM_EXPANSION_CONST		"Init Counter"
#define RANDOM_EXPANSION_CONST_SIZE			12
#define A_SHA_DIGEST_LEN			20
#define ETHER_HDRLEN				14
#define LIB1X_EAPOL_HDRLEN			4
#define INFO_ELEMENT_SIZE       	128
#define MAX_EAPOLMSG_LEN        	512
#define MAX_EAPOLKEYMSG_LEN	(MAX_EAPOLMSG_LEN-(ETHER_HDRLEN+LIB1X_EAPOL_HDRLEN))
#define EAPOLMSG_HDRLEN				95      //EAPOL-key payload length without KeyData
#define MAX_UNICAST_CIPHER			2
#define WPA_ELEMENT_ID				0xDD
#define WPA2_ELEMENT_ID				0x30

typedef enum	{ desc_type_WPA2 = 2, desc_type_RSN = 254 } DescTypeRSN;
typedef enum	{ type_Group = 0, type_Pairwise = 1 } KeyType;
typedef enum	{ key_desc_ver1 = 1, key_desc_ver2 = 2 } KeyDescVer;
enum { PSK_WPA=1, PSK_WPA2=2};

#ifdef TLN_STATS
enum { STATS_AUTH_OPEN=0, STATS_AUTH_SHARE=1,
		STATS_PSK_WPA=2, STATS_PSK_WPA2=3,
		STATS_ETP_WPA=4, STATS_ETP_WPA2=5
	};
#endif

enum {
	PSK_STATE_IDLE,
	PSK_STATE_PTKSTART,
	PSK_STATE_PTKINITNEGOTIATING,
	PSK_STATE_PTKINITDONE,
};

enum {
	PSK_GSTATE_REKEYNEGOTIATING,
	PSK_GSTATE_REKEYESTABLISHED,
	PSK_GSTATE_KEYERROR,
};

/*
 * Reason code for Disconnect
 */
typedef enum _ReasonCode{
	unspec_reason					= 0x01,
	auth_not_valid  				= 0x02,
	deauth_lv_ss    				= 0x03,
	inactivity						= 0x04,
	ap_overload						= 0x05,
	class2_err						= 0x06,
	class3_err						= 0x07,
	disas_lv_ss						= 0x08,
	asoc_not_auth					= 0x09,
	RSN_invalid_info_element		= 13,
	RSN_MIC_failure					= 14,
	RSN_4_way_handshake_timeout	= 15,
	RSN_diff_info_element			= 17,
	RSN_multicast_cipher_not_valid	= 18,
	RSN_unicast_cipher_not_valid	= 19,
	RSN_AKMP_not_valid				= 20,
	RSN_unsupported_RSNE_version	= 21,
	RSN_invalid_RSNE_capabilities	= 22,
	RSN_ieee_802dot1x_failed		= 23,
	//belowing are Realtek definition
	RSN_PMK_not_avaliable			= 24,
	expire							= 30,
	session_timeout					= 31,
	acct_idle_timeout				= 32,
	acct_user_request				= 33
}ReasonCode;


typedef	struct _OCTET_STRING {
	unsigned char	*Octet;
	int				Length;
} OCTET_STRING;

typedef union _LARGE_INTEGER {
		unsigned char 	charData[8];
        struct {
			unsigned long 	HighPart;
			unsigned long 	LowPart;
        } field;
} LARGE_INTEGER, *PLARGE_INTEGER;

typedef union _OCTET16_INTEGER {
		unsigned char 	charData[16];
        struct {
			LARGE_INTEGER	HighPart;
			LARGE_INTEGER	LowPart;
        } field;
} OCTET16_INTEGER;

typedef union  _OCTET32_INTEGER {
		unsigned char	charData[32];
        struct {
			OCTET16_INTEGER	HighPart;
			OCTET16_INTEGER	LowPart;
        } field;
} OCTET32_INTEGER;

typedef struct _DOT11_WPA2_IE_HEADER {
        unsigned char ElementID;
        unsigned char Length;
        unsigned short Version;
} DOT11_WPA2_IE_HEADER;

#if defined(WIFI_HAPD) && !defined(HAPD_DRV_PSK_WPS)
// group key info
typedef struct _wpa_global_info {
	OCTET_STRING		AuthInfoElement;
	unsigned char		AuthInfoBuf[INFO_ELEMENT_SIZE];
	unsigned char		MulticastCipher;
	int					NumOfUnicastCipher;
	unsigned char		UnicastCipher[MAX_UNICAST_CIPHER];
#ifdef RTL_WPA2
	int					NumOfUnicastCipherWPA2;
	unsigned char		UnicastCipherWPA2[MAX_UNICAST_CIPHER];
#endif
} WPA_GLOBAL_INFO;

#else

// group key info
typedef struct _wpa_global_info {
	OCTET32_INTEGER		Counter;
	unsigned char		PSK[A_SHA_DIGEST_LEN*2];
	unsigned char		PSKGuest[A_SHA_DIGEST_LEN*2];
	int					GTKAuthenticator;
	int					GKeyDoneStations;
	int					GInitAKeys;
	int					GUpdateStationKeys;
	int					GkeyReady;
	OCTET_STRING		AuthInfoElement;
	unsigned char		AuthInfoBuf[INFO_ELEMENT_SIZE];
	unsigned char		MulticastCipher;
	int					NumOfUnicastCipher;
	unsigned char		UnicastCipher[MAX_UNICAST_CIPHER];
#ifdef RTL_WPA2
	int					NumOfUnicastCipherWPA2;
	unsigned char		UnicastCipherWPA2[MAX_UNICAST_CIPHER];
#endif
	OCTET_STRING		GNonce;
	unsigned char		GNonceBuf[KEY_NONCE_LEN];
	unsigned char		GTK[NumGroupKey][GTK_LEN];
	unsigned char		GMK[GMK_LEN];
	int					GN;
	int					GM;
	int					GRekeyCounts;
	int					GResetCounter;

	int					IntegrityFailed;
	int					GTKRekey;
	int					GKeyFailure;
	struct timer_list	GKRekeyTimer;
} WPA_GLOBAL_INFO;
#endif

#if defined(WIFI_HAPD) && !defined(HAPD_DRV_PSK_WPS)
// wpa sta info
typedef struct _wpa_sta_info {
	int 				state;
	int					RSNEnabled;		// bit0-WPA, bit1-WPA2
	unsigned char		UnicastCipher;
	struct rtl8192cd_priv	*priv;
} WPA_STA_INFO;

#else

// wpa sta info
typedef struct _wpa_sta_info {
	int					state;
	int					gstate;
	int					RSNEnabled;		// bit0-WPA, bit1-WPA2
	int					PMKCached;
	int					PInitAKeys;
	unsigned char		UnicastCipher;
 	unsigned char		NumOfRxTSC;
 	unsigned char		AuthKeyMethod;
 	int					isSuppSupportPreAuthentication;
	int					isSuppSupportPairwiseAsDefaultKey;
	LARGE_INTEGER		CurrentReplayCounter;
	LARGE_INTEGER		ReplayCounterStarted; // david+1-12-2007
	OCTET_STRING		ANonce;
	OCTET_STRING		SNonce;
	unsigned char		AnonceBuf[KEY_NONCE_LEN];
	unsigned char		SnonceBuf[KEY_NONCE_LEN];
 	unsigned char		PMK[PMK_LEN];
 	unsigned char		PTK[PTK_LEN_TKIP];
	OCTET_STRING		EAPOLMsgRecvd;
	OCTET_STRING		EAPOLMsgSend;
	OCTET_STRING		EapolKeyMsgRecvd;
	OCTET_STRING		EapolKeyMsgSend;
	unsigned char		eapSendBuf[MAX_EAPOLMSG_LEN];
	unsigned char		eapRecvdBuf[MAX_EAPOLMSG_LEN];
	struct timer_list	resendTimer;
	struct rtl8192cd_priv	*priv;
	int					resendCnt;
	int					isGuest;
	int					clientHndshkProcessing;
	int					clientHndshkDone;
	int 				clientGkeyUpdate;
	LARGE_INTEGER		clientMICReportReplayCounter;
} WPA_STA_INFO;
#endif

#if defined(PACK_STRUCTURE) || defined(__ECOS)
#pragma pack(1)
#endif

__PACK typedef struct _LIB1X_EAPOL_KEY
{
 	unsigned char		key_desc_ver;
 	unsigned char		key_info[2];
 	unsigned char		key_len[2];
 	unsigned char		key_replay_counter[KEY_RC_LEN];
 	unsigned char		key_nounce[KEY_NONCE_LEN];
 	unsigned char		key_iv[KEY_IV_LEN];
 	unsigned char		key_rsc[KEY_RSC_LEN];
 	unsigned char		key_id[KEY_ID_LEN];
 	unsigned char		key_mic[KEY_MIC_LEN];
 	unsigned char		key_data_len[KEY_MATERIAL_LEN];
 	unsigned char		*key_data;
}__WLAN_ATTRIB_PACK__ lib1x_eapol_key;


__PACK struct lib1x_eapol
{
 	unsigned char		protocol_version;
 	unsigned char		packet_type;			// This makes it odd in number !
 	unsigned short		packet_body_length;
}__WLAN_ATTRIB_PACK__;

#if defined(PACK_STRUCTURE) || defined(__ECOS)
#pragma pack()
#endif

#define SetSubStr(f,a,l)				memcpy(f.Octet+l,a.Octet,a.Length)
#define GetKeyInfo0(f, mask) 			((f.Octet[KeyInfoPos + 1] & mask) ? 1 :0)
#define SetKeyInfo0(f,mask,b)			(f.Octet[KeyInfoPos + 1] = (f.Octet[KeyInfoPos + 1] & ~mask) | ( b?mask:0x0) )
#define GetKeyInfo1(f, mask)			((f.Octet[KeyInfoPos] & mask) ? 1 :0)
#define SetKeyInfo1(f,mask,b)			(f.Octet[KeyInfoPos] = (f.Octet[KeyInfoPos] & ~mask) | ( b?mask:0x0) )

// EAPOLKey
#define Message_DescType(f)				(f.Octet[DescTypePos])
#define Message_setDescType(f, type)	(f.Octet[DescTypePos] = type)
// Key Information Filed
#define Message_KeyDescVer(f)			(f.Octet[KeyInfoPos+1] & 0x07)//(f.Octet[KeyInfoPos+1] & 0x01) | (f.Octet[KeyInfoPos+1] & 0x02) <<1 | (f.Octet[KeyInfoPos+1] & 0x04) <<2
#define Message_setKeyDescVer(f, v)		(f.Octet[KeyInfoPos+1] &= 0xf8) , f.Octet[KeyInfoPos+1] |= (v & 0x07)//(f.Octet[KeyInfoPos+1] |= ((v&0x01)<<7 | (v&0x02)<<6 | (v&0x04)<<5) )
#define Message_KeyType(f)				GetKeyInfo0(f,0x08)
#define Message_setKeyType(f, b)		SetKeyInfo0(f,0x08,b)
#define Message_KeyIndex(f)				((f.Octet[KeyInfoPos+1] & 0x30) >> 4) & 0x03//(f.Octet[KeyInfoPos+1] & 0x20) | (f.Octet[KeyInfoPos+1] & 0x10) <<1
#define Message_setKeyIndex(f, v)		(f.Octet[KeyInfoPos+1] &= 0xcf), f.Octet[KeyInfoPos+1] |= ((v<<4) & 0x07)//(f.Octet[KeyInfoPos+1] |= ( (v&0x01)<<5 | (v&0x02)<<4)  )
#define Message_Install(f)				GetKeyInfo0(f,0x40)
#define Message_setInstall(f, b)		SetKeyInfo0(f,0x40,b)
#define Message_KeyAck(f)				GetKeyInfo0(f,0x80)
#define Message_setKeyAck(f, b)			SetKeyInfo0(f,0x80,b)

#define Message_KeyMIC(f)				GetKeyInfo1(f,0x01)
#define Message_setKeyMIC(f, b)			SetKeyInfo1(f,0x01,b)
#define Message_Secure(f)				GetKeyInfo1(f,0x02)
#define Message_setSecure(f, b)			SetKeyInfo1(f,0x02,b)
#define Message_Error(f)				GetKeyInfo1(f,0x04)
#define Message_setError(f, b)			SetKeyInfo1(f,0x04,b)
#define Message_Request(f)				GetKeyInfo1(f,0x08)
#define Message_setRequest(f, b)		SetKeyInfo1(f,0x08,b)
#define Message_Reserved(f)				(f.Octet[KeyInfoPos] & 0xf0)
#define Message_setReserved(f, v)		(f.Octet[KeyInfoPos] |= (v<<4&0xff))
#define Message_KeyLength(f)			((unsigned short)(f.Octet[KeyLenPos] <<8) + (unsigned short)(f.Octet[KeyLenPos+1]))
#define Message_setKeyLength(f, v)		(f.Octet[KeyLenPos] = (v&0xff00) >>8 ,  f.Octet[KeyLenPos+1] = (v&0x00ff))

#define Message_KeyNonce(f)					SubStr(f,KeyNoncePos,KEY_NONCE_LEN)
#define Message_setKeyNonce(f, v)			SetSubStr(f, v, KeyNoncePos)
#define Message_EqualKeyNonce(f1, f2)		memcmp(f1.Octet + KeyNoncePos, f2.Octet, KEY_NONCE_LEN)? 0:1
#define Message_KeyIV(f)					Substr(f, KeyIVPos, KEY_IV_LEN)
#define Message_setKeyIV(f, v)				SetSubStr(f, v, KeyIVPos)
#define Message_KeyRSC(f)					Substr(f, KeyRSCPos, KEY_RSC_LEN)
#define Message_setKeyRSC(f, v)				SetSubStr(f, v, KeyRSCPos)
#define Message_KeyID(f)					Substr(f, KeyIDPos, KEY_ID_LEN)
#define Message_setKeyID(f, v)				SetSubStr(f, v, KeyIDPos)
#define Message_MIC(f)						SubStr(f, KeyMICPos, KEY_MIC_LEN)
#define Message_setMIC(f, v)				SetSubStr(f, v, KeyMICPos)
#define Message_clearMIC(f)					memset(f.Octet+KeyMICPos, 0, KEY_MIC_LEN)
#define Message_KeyDataLength(f)			((unsigned short)(f.Octet[KeyDataLenPos] <<8) + (unsigned short)(f.Octet[KeyDataLenPos+1]))
#define Message_setKeyDataLength(f, v)		(f.Octet[KeyDataLenPos] = (v&0xff00) >>8 ,  f.Octet[KeyDataLenPos+1] = (v&0x00ff))
#define Message_KeyData(f, l)				SubStr(f, KeyDataPos, l)
#define Message_setKeyData(f, v)			SetSubStr(f, v, KeyDataPos);
#define Message_EqualRSNIE(f1 , f2, l)		memcmp(f1.Octet, f2.Octet, l) ? 0:1
#define Message_ReturnKeyDataLength(f)		f.Length - (ETHER_HDRLEN + LIB1X_EAPOL_HDRLEN + EAPOLMSG_HDRLEN)

#define Message_CopyReplayCounter(f1, f2)	memcpy(f1.Octet + ReplayCounterPos, f2.Octet + ReplayCounterPos, KEY_RC_LEN)
#define Message_DefaultReplayCounter(li)	((li.field.HighPart == 0xffffffff) && (li.field.LowPart == 0xffffffff) ) ?1:0

#if defined(CONFIG_RTL8186_KB_N)
extern int authRes;//0: success; 1: fail
#endif

#endif // _8192CD_PSK_H_