summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/drivers/net/wireless/rtl8192cd/wapi_wai.h
blob: 2d251a2d31dae89442011c018f77958e7a37d77c (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
#if	!defined(WAPI_WAI_H)
#define		WAPI_WAI_H	1
#include "8192cd_cfg.h"

#if defined(CONFIG_RTL_WAPI_SUPPORT)

#ifdef __LINUX_2_6__
#ifdef CONFIG_RTL8672
#include "./romeperf.h"
#else
#if !defined(NOT_RTK_BSP)
#include <net/rtl/rtl_types.h>
#else
#include "rtl_types.h"
#endif
#endif
#else
#include "../rtl865x/rtl_types.h"
#endif
#include <linux/timer.h>


#ifndef ETH_ALEN
#define ETH_ALEN    6
#endif

#ifdef __KERNEL__
#include <linux/spinlock.h>
#if 0
extern int	wapi_lock_cnt;
#define	WAPI_LOCK_INIT(__lock__)		do {spin_lock_init(__lock__);} while(0)
#define	WAPI_LOCK(__lock__)		\
		do { \
			spin_lock(__lock__); \
			if(wapi_lock_cnt>0) \
				printk("[%s][%d]: wapi lock cnt %d\n", __FUNCTION__, __LINE__, wapi_lock_cnt); \
			wapi_lock_cnt++; \
		} while(0)
#define	WAPI_UNLOCK(__lock__)	\
		do { \
			spin_unlock(__lock__); \
			wapi_lock_cnt--; \
			if (wapi_lock_cnt<0) \
				printk("[%s][%d]: wapi lock cnt %d\n", __FUNCTION__, __LINE__, wapi_lock_cnt); \
		} while(0)
#else
#define	WAPI_LOCK_INIT(__lock__)
#define	WAPI_LOCK(__lock__)	
#define	WAPI_UNLOCK(__lock__)
#endif
#endif

#define	ETH_P_WAPI			0x88B4

#if 0
#define	FL_TRACE(__FLG__, __NUM__)	printk("[%s][%d]:-[%s][0x%x]\n", __FUNCTION__, __LINE__, __FLG__, __NUM__)
#define	wapiAssert(__FLAGS__)	do {if(!(__FLAGS__)) printk("Assert Error!! ==>[%s][%d]-[%s]\n", __FUNCTION__, __LINE__, __FILE__);} while(0)
#else
#define	wapiAssert(__FLAGS__)
#define	FL_TRACE(__FLG__, __NUM__)
#endif

#define	WAPI_ALIGNMENT_OFFSET	0
#define	WAPI_CERT_MAX_LEN		2688
#define	SMS4_MIC_LEN		16
#define	WAPI_EXT_LEN		18
#define	WAPI_PN_LEN		16
#define	WAPI_KEY_LEN		16
#define	WAPI_N_LEN			32		/*	wapi challange length	*/
#define	WAPI_KEY_MNG_PKT_LEN		4
#define	WAPI_AKM_OFFSET	4
#define	WAPI_WAI_MAX_SEND_RETRY		7
//#define	WAPI_WAI_HEADER_PADDING		(32+sizeof(wapiWaiHeader))	/*	wlan header 26, LLC header 6, ether type 2	*/
#define	WAPI_WAI_HEADER_PADDING		(34)	/*	wlan header 26, LLC header 6, ether type 2	*/

#define	WAPI_RETRY_COUNT			6	/*	max 64	*/
#define	WAPI_CERT_REQ_TIMEOUT	RTL_SECONDS_TO_JIFFIES(10)
#define	WAPI_AUTH_REQ_TIMEOUT	RTL_SECONDS_TO_JIFFIES(31)
#define	WAPI_GENERAL_TIMEOUT	RTL_SECONDS_TO_JIFFIES(1)
#define	WAPI_KEY_UPDATE_TIMEOUT	RTL_SECONDS_TO_JIFFIES(6)
#define	WAPI_KEY_UPDATE_PERIOD	RTL_SECONDS_TO_JIFFIES(600)
#define	WAPI_KEY_UPDATE_PKTCNT		65536
#define	WAPI_WAI_SEQNUM_STEP		8

#define	WAPI_RETURN_SUCCESS		0
#define	WAPI_RETURN_FAILED		-1
#define	WAPI_RETURN_DEASSOC		-2

#define	RX_QUEUE_NUM				4

typedef	enum __wapiMibType	wapiStaType;

typedef	enum __wapiMibEncryptAlgorithm	wapiStaEncryptAlgorithm;

typedef	struct	__wapiKey {
	unsigned char		dataKey[WAPI_KEY_LEN];	/*	used as key for BK		*/
											/*	used as MCastKeyEncrypt Key for WAI */
	unsigned char		micKey[WAPI_KEY_LEN];	/*	used as keyID for BK	*/
											/*	used as UCast MIC Key for WAI */
#if defined(WAPI_SUPPORT_MULTI_ENCRYPT)
	wapiStaEncryptAlgorithm		keyType;
#endif
}	wapiKey;

#define	WAPI_IOCTL_TYPE_ACTIVEAUTH	0
#define	WAPI_IOCTL_TYPE_SETBK			1
#define	WAPI_IOCTL_TYPE_AUTHRSP		2

#define	WAPI_IOCTL_TYPE_REQ_ACTIVE	3
#define	WAPI_IOCTL_TYPE_CA_AUTH		4

typedef struct __wapiCAAppPara {
	uint8			eventID;
	uint8			moreData;
	uint16			type;
	void				*ptr;
	char				name[IFNAMSIZ];
	uint8			data[0];
} __WLAN_ATTRIB_PACK__ wapiCAAppPara;

typedef struct __wapiStaPN {
	unsigned char		rxUCast[RX_QUEUE_NUM][WAPI_PN_LEN];
	unsigned char		txUCast[WAPI_PN_LEN];
	unsigned short		rxSeq[RX_QUEUE_NUM];
}	wapiStaPN;

/*	AE STATE during WAI Handshake	*/
typedef enum __WAPI_AE_STATE { 
	ST_WAPI_AE_IDLE=0, 
	ST_WAPI_AE_ACTIVE_AUTHENTICATION_REQ,	/*	1	*/
	ST_WAPI_AE_ACTIVE_AUTHENTICATION_SNT,	/*	2	*/
	ST_WAPI_AE_ACCESS_AUTHENTICATE_REQ_RCVD,	/*	3	*/	
	ST_WAPI_AE_ACCESS_CERTIFICATE_REQ_SNT,	/*	4	*/
	ST_WAPI_AE_BKSA_ESTABLISH,	/*	5	*/
	ST_WAPI_AE_USK_AGGREMENT_REQ_SNT,	/*	6	*/
	ST_WAPI_AE_USK_AGGREMENT_RSP_SNT,	/*	7	*/
	ST_WAPI_AE_USK_AGGREMENT_RSP_RCVD,	/*	8	*/
	ST_WAPI_AE_USKA_ESTABLISH,	/*	9	*/
	ST_WAPI_AE_MSK_NOTIFICATION_SNT,	/*	a	*/
	ST_WAPI_AE_MSK_NOTIFICATION_RCVD,	/*	b	*/
	ST_WAPI_AE_MSK_RSP_RCVD,	/*	c	*/
	ST_WAPI_AE_MSKA_ESTABLISH	/*	d	*/
}	WAPI_AE_STATE;

typedef	struct	__wapiStaInfo {
	uint8			asueWapiIE[256];
	uint8			waiASUEChallange[WAPI_N_LEN];
	uint8			waiAEChallange[WAPI_N_LEN];	
	uint8			waiAEChallangeNext[WAPI_N_LEN];
	uint8			waiAuthFlag[WAPI_N_LEN];
	uint8			asueWapiIELength;
	uint8			wapiRxFragSeq;
	uint8			wapiUCastKeyId:1;
	uint8			wapiUCastRxEnable:1;
	uint8			wapiUCastTxEnable:1;
	uint8			wapiUCastKeyUpdate:1;
	uint8			wapiMCastEnable:1;
	uint8			wapiMCastKeyUpdateDone:1;
	uint8			wapiRetry:6;
	uint16			waiTxSeq;
	uint16			waiRxSeq;
	wapiStaType		wapiType;
	WAPI_AE_STATE	wapiState;
	wapiStaPN		wapiPN;
	wapiKey			wapiBK;
	wapiKey			wapiUCastKey[2];
	wapiKey			wapiWaiKey;
	uint32			wapiRxFragLen;
	uint32			waiCertRspDataLen;
	uint32			waiCertCachedDataLen;
	unsigned long		wapiUCastKeyUpdateCnt;
	struct timer_list	waiResendTimer;
	struct timer_list	waiUCastKeyUpdateTimer;
	struct sk_buff		*wapiRxFragPskb;
	struct rtl8192cd_priv	*priv;
	uint8			*waiCertCachedData;
	uint8			*waiCertRspData;
#ifdef __KERNEL__
	spinlock_t				lock;
#endif
}	wapiStaInfo;

typedef enum	__wapiWaiProtocolVersion {
	WAI_V1 = 1
}	wapiWaiProtocolVersion;
typedef enum	__wapiWaiType {
	WAI_TYPE_WAI = 1
}	wapiWaiType;
typedef enum	__wapiWaiSubType {
	WAI_SUBTYPE_PREAUTH = 1,
	WAI_SUBTYPE_STA_KEY_REQ = 2,
	WAI_SUBTYPE_AUTH_ACTIVE = 3,
	WAI_SUBTYPE_AUTH_REQ = 4,
	WAI_SUBTYPE_AUTH_RSP = 5,
	WAI_SUBTYPE_CERT_REQ = 6,
	WAI_SUBTYPE_CERT_RSP =7,
	WAI_SUBTYPE_UCAST_KEY_REQ = 8,
	WAI_SUBTYPE_UCAST_KEY_RSP = 9,
	WAI_SUBTYPE_UCAST_KEY_ACK = 10,
	WAI_SUBTYPE_MCAST_KEY_NOTIFY = 11,
	WAI_SUBTYPE_MCAST_KEY_RSP = 12
}	wapiWaiSubType;

#define	WAI_HEADER_MF		0x1
#define	WAI_HEADER_LEN	12
#define	WAI_MIC_LEN			20

typedef struct __wapiTLV {
	uint16	id;
	uint16	len;
	uint8	data[0];
} __WLAN_ATTRIB_PACK__ wapiTLV;

typedef struct __wapiTLV1 {
	uint8	id;
	uint16	len;
	uint8	data[0];
}	__attribute__ ((packed))	wapiTLV1;

typedef struct __wapiWaiHeader {
	uint16	protocolVersion;
	uint8	type;
	uint8	subType;
	uint16	reserved;
	uint16	length;
	uint16	sequenceNum;
	uint8	fragmentNum;
	uint8	flags;
} __WLAN_ATTRIB_PACK__ wapiWaiHeader;

typedef struct __wapiWaiCertActivPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	updateBK:1;
	uint8	preAuth:1;
	uint8	reserved:6;
#else
	uint8	reserved:6;
	uint8	preAuth:1;
	uint8	updateBK:1;
#endif
	/*	8Bit flags over	*/
	uint8	authFlag[WAPI_N_LEN];
	uint8	data[0];
} __WLAN_ATTRIB_PACK__ wapiWaiCertActivPkt;

typedef struct __wapiWaiCertAuthReqPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	updateBK:1;
	uint8	preAuth:1;
	uint8	AEAuthReq:1;
	uint8	options:1;
	uint8	reserved:4;
#else
	uint8	reserved:4;
	uint8	options:1;
	uint8	AEAuthReq:1;
	uint8	preAuth:1;
	uint8	updateBK:1;
#endif
	/*	8Bit flags over	*/
	uint8	authFlag[WAPI_N_LEN];
	uint8	ASUEChallange[WAPI_N_LEN];
	uint8	data[0];
} __WLAN_ATTRIB_PACK__ wapiWaiCertAuthReqPkt;

typedef struct __wapiWaiCertAuthRspPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	updateBK:1;
	uint8	preAuth:1;
	uint8	reserved2:1;
	uint8	options:1;
	uint8	reserved1:4;
#else
	uint8	reserved1:4;
	uint8	options:1;
	uint8	reserved2:1;
	uint8	preAuth:1;
	uint8	updateBK:1;
#endif
	/*	8Bit flags over	*/
	uint8	ASUEChallange[WAPI_N_LEN];
	uint8	AEChallange[WAPI_N_LEN];
	uint8	CAResult;
	uint8	data[0];
} __WLAN_ATTRIB_PACK__ wapiWaiCertAuthRspPkt;

typedef struct __wapiWaiUCastReqPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	reserved2:4;
	uint8	uskUpdate:1;
	uint8	reserved1:3;
#else
	uint8	reserved1:3;
	uint8	uskUpdate:1;
	uint8	reserved2:4;
#endif
	/*	8Bit flags over	*/
	uint8	bkId[WAPI_KEY_LEN];
	uint8	uskId;
	uint8	mac1[ETH_ALEN];
	uint8	mac2[ETH_ALEN];
	uint8	AEChallange[WAPI_N_LEN];
} __WLAN_ATTRIB_PACK__ wapiWaiUCastReqPkt;

typedef struct __wapiWaiUCastRspPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	reserved2:4;
	uint8	uskUpdate:1;
	uint8	reserved1:3;
#else
	uint8	reserved1:3;
	uint8	uskUpdate:1;
	uint8	reserved2:4;
#endif
	/*	8Bit flags over	*/
	uint8	bkId[WAPI_KEY_LEN];
	uint8	uskId;
	uint8	mac1[ETH_ALEN];
	uint8	mac2[ETH_ALEN];
	uint8	ASUEChallange[WAPI_N_LEN];
	uint8	AEChallange[WAPI_N_LEN];
	uint8	WIEasue[0];
} __WLAN_ATTRIB_PACK__ wapiWaiUCastRspPkt;

typedef struct __wapiWaiUCastAckPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	reserved2:4;
	uint8	uskUpdate:1;
	uint8	reserved1:3;
#else
	uint8	reserved1:3;
	uint8	uskUpdate:1;
	uint8	reserved2:4;
#endif
	/*	8Bit flags over	*/
	uint8	bkId[WAPI_KEY_LEN];
	uint8	uskId;
	uint8	mac1[ETH_ALEN];
	uint8	mac2[ETH_ALEN];
	uint8	ASUEChallange[WAPI_N_LEN];
	uint8	WIEae[0];
} __WLAN_ATTRIB_PACK__ wapiWaiUCastAckPkt;

typedef struct __wapiWaiMCastNotiPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	reserved2:5;
	uint8	staKeyFlag:1;
	uint8	delKeyFlag:1;
	uint8	reserved1:1;
#else
	uint8	reserved1:1;
	uint8	delKeyFlag:1;
	uint8	staKeyFlag:1;
	uint8	reserved2:5;
#endif
	/*	8Bit flags over	*/
	uint8	mskId;
	uint8	uskId;
	uint8	mac1[ETH_ALEN];
	uint8	mac2[ETH_ALEN];
	uint8	dataPN[WAPI_PN_LEN];
	uint8	keyPN[WAPI_PN_LEN];
	uint8	keyData[0];
} __WLAN_ATTRIB_PACK__ wapiWaiMCastNofiPkt;

typedef struct __wapiWaiMCastRspPkt {
	/*	8Bit flags	*/
#ifdef	_LITTLE_ENDIAN_
	uint8	reserved2:5;
	uint8	staKeyFlag:1;
	uint8	delKeyFlag:1;
	uint8	reserved1:1;
#else
	uint8	reserved1:1;
	uint8	delKeyFlag:1;
	uint8	staKeyFlag:1;
	uint8	reserved2:5;
#endif
	/*	8Bit flags over	*/
	uint8	mskId;
	uint8	uskId;
	uint8	mac1[ETH_ALEN];
	uint8	mac2[ETH_ALEN];
	uint8	keyPN[WAPI_PN_LEN];
	uint8	mic[0];
} __WLAN_ATTRIB_PACK__ wapiWaiMCastRspPkt;

void wapiInit(struct rtl8192cd_priv *priv);
void wapiExit(struct rtl8192cd_priv *priv);
void wapiStationInit(struct stat_info *pstat);
void free_sta_wapiInfo(struct rtl8192cd_priv *priv, struct stat_info *pstat);
void wapiSetIE(struct rtl8192cd_priv	*priv);
int	wapiIEInfoInstall(struct rtl8192cd_priv *priv, struct stat_info *pstat);
void wapiReleaseFragementQueue(wapiStaInfo *wapiInfo);
void wapiReqActiveCA(struct stat_info *pstat);
void	wapiSetBK(struct stat_info *pstat);
int32 WapiComparePN(uint8 *PN1, uint8 *PN2);
int32 WapiIncreasePN(uint8 *PN, uint8 AddCount);
int wapiHandleRecvPacket(struct rx_frinfo *pfrinfo, struct stat_info *pstat);
int	wapiSendActiveAuthenticationPacket(struct rtl8192cd_priv *priv, struct stat_info *pstat, int len, uint8 *data);
int	wapiSendUnicastKeyAgrementRequeset(struct rtl8192cd_priv *priv, struct stat_info *pstat);
int	wapiSendUnicastKeyAgrementConfirm(struct rtl8192cd_priv *priv, struct stat_info *pstat);
int	wapiSendMulticastKeyNotification(struct rtl8192cd_priv *priv, struct stat_info *pstat);
int	wapiUpdateUSK(struct rtl8192cd_priv *priv, struct stat_info *pstat);
int	wapiUpdateMSK(struct rtl8192cd_priv *priv, struct stat_info *pstat);

extern struct timer_list	waiMCastKeyUpdateTimer;

int DOT11_Process_WAPI_Info(struct rtl8192cd_priv *priv, uint8 *data, int32 len);
#endif	/*	CONFIG_RTL_WAPI_SUPPORT	*/

#endif	/*	WAPI_WAI_H			*/