summaryrefslogtreecommitdiff
path: root/network/wlan/WDI/COMMON/ParserGen.h
blob: c956945e85098275bfdd23bbee2fc0aada866c55 (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
/*++
Copyright (c) Realtek Semiconductor Corp. All rights reserved.

Module Name:
	ParserGen.h
	
Abstract:
	Parse MSDU to match the specified type, fetch fixed offset.
	    
Major Change History:
	When           Who					What
	---------- ---------------   -------------------------------
	2007-06-11	shienchang			Create.
	2008-03-10	Bruce				Modify from 818xB.
	
--*/
#ifndef __INC_PARSERGEN_H
#define __INC_PARSERGEN_H
/////////////////////////////////////////////////////////
//  Global defines
/////////////////////////////////////////////////////////

//
// Protocol identity define.
// Add your own id here if new parser need.
//
#define PROTO_UNKNOWN			0
#define PROTO_ETHERNET			1
#define PROTO_WLAN_80211		2
#define PROTO_WLAN_LLC			3
#define PROTO_IP				4
#define PROTO_TCP				5
#define PROTO_UDP				6
#define PROTO_RTP				7
#define PROTO_SIP_INVITE		8
#define PROTO_SIP_STATUS		9
#define PROTO_SIP_BYE			10
#define PROTO_SIP_NOTIFY		11
#define PROTO_SIP_ACK			12
#define PROTO_SIP_SDP			13
#define PROTO_RTP_G711			14

//
// Protocol fixed header length
//
#define PROTO_UNKNOWN_HDRLEN			0
#define PROTO_ETHERNET_HDRLEN			(12+2)
#define PROTO_WLAN_LLC_HDRLEN			(6+2)
#define PROTO_IP_HDRLEN					20
#define PROTO_UDP_HDRLEN				8

// Flag defines.
#define GPFLAG_TX						1
#define GPFLAG_RX						2


// Basic parse block
#define MAX_PROTOCOL_NUM				32

//
// Main generic parser defines.
//
#define MAX_PARSER_NUM					16
#define MAX_PARSER_NAME					32
#define MAX_SIG_LENGTH					32

#define MAX_HP_PROTOCOL_PER_PARSER		32
#define MAX_HP_RULES_PER_PARSER			64

////////////////////////////////////////////////////////
// Macro Definition
////////////////////////////////////////////////////////

#define GP_REGISTER_RULES(_parser, _rules) \
	(_parser)->pParseRules = (_rules)

#define GP_UNREGISTER_RULES(_parser) \
	(_parser)->pParseRules = NULL

#define GP_GET_CONTEXT(_parser) \
	(_parser)->ParserContext

#define GP_HP_GET_NODE_START(_pTree) \
	(_pTree)

#define GP_HP_GET_ENTRY_START(_pTree) \
	((_pTree) + MAX_HP_PROTOCOL_PER_PARSER)

#define GP_BIND_CONTEXT(_parser, _context) \
	(_parser)->ParserContext = (_context)

#define GP_UNBIND_CONTEXT(_parser) \
	(_parser)->ParserContext = NULL

#define GP_HP_GET_NODE_BY_INDEX(_pTree, _idx) \
	((PGP_HP_NODE)GP_HP_GET_NODE_START(_pTree)) + (_idx)

#define GP_HP_GET_ENTRY_BY_INDEX(_pTree, _idx) \
	((PGP_HP_ENTRY)GP_HP_GET_ENTRY_START(_pTree)) + (_idx)


typedef u4Byte	PROTO_ID, *PPROTO_ID;

typedef struct _GPPARSE_TOKEN
{
	SHARED_MEMORY		BufferList[MAX_PER_PACKET_BUFFER_LIST_LENGTH];
	u4Byte				BufferCount;
	u4Byte				currBufferIndex;
	u4Byte				currBufferOffset;
	PROTO_ID			currProtocol;
	PROTO_ID			ProtocolSuite[MAX_PROTOCOL_NUM];
	u1Byte				ProtocolCount;
	PVOID				pDataObj;
	u1Byte				gpFlag;
} GPPARSE_TOKEN, *PGPPARSE_TOKEN;


// For TCB/RFD action, 2007.06.21 by shien chang.
typedef enum{
	TR_ACTION_CONTINUE = 0,
	TR_ACTION_HANDLED = 1,
	TR_ACTION_DROPPED = 2,
}TR_ACTION;

typedef BOOLEAN
	(*GPParseHandler)(
		IN		PADAPTER		Adapter,
		IN		PVOID			pParseContext,
		IN		PROTO_ID		CurrProtocol,
		IN		PROTO_ID		NextProtocol,
		OUT		pu1Byte			pSigBuffer,
		IN		u4Byte			SigBufferLen,
		IN		PGPPARSE_TOKEN	pToken,
		OUT		pu4Byte			AdvBytes
		);


typedef struct _GP_RULE
{
	u4Byte				CurrProtocol;
	u4Byte				NextProtocol;
	u4Byte				SigStart;
	u4Byte				SigLength;
	GPParseHandler		ParseHandler;
} GP_RULE, *PGP_RULE;

typedef BOOLEAN
	(*GPParserGate)(
		IN		PADAPTER		Adapter,
		IN		PVOID			pParser
		);

typedef TR_ACTION
	(*GPParserAction)(
		IN		PADAPTER		Adapter,
		IN		PGPPARSE_TOKEN	pToken,
		IN		PVOID			pParser
		);

typedef struct _GP_HP_ENTRY
{
	RT_LIST_ENTRY	Link;
	PGP_RULE		pRule;
	u1Byte			index;
} GP_HP_ENTRY, *PGP_HP_ENTRY;


typedef struct _GP_HP_NODE
{
	RT_LIST_ENTRY	Link;
	PROTO_ID		ProtocolId;
	BOOLEAN			bUsed;
} GP_HP_NODE, *PGP_HP_NODE;


//
// Description:
//	PID:
//		This generic parser identifier.
//	ParserName:
//		The name of this generic parser.
//	ParserRules:
//		The corrresponding handler and the next protocol to the current protocol. 
//	ParserContext:
//		The input context about for this parser.
//	Gate:
//		A routine to determine if this parser should go parsing it or not.
//	Action:
//		An action routine to handle parserd packet.
//	pParsingTree:
//
//	bUseHP:
//		Use high performance parser.
// By Bruce, 2008-03-11.
//
typedef struct _GENERIC_PARSER
{
	u1Byte			PID;
	u1Byte			ParserName[MAX_PARSER_NAME];
	PGP_RULE		pParseRules;
	PVOID			ParserContext;	
	GPParserGate	Gate;
	GPParserAction	Action;
	PGP_HP_NODE		pParsingTree;
	BOOLEAN			bUseHP;
} GENERIC_PARSER, *PGENERIC_PARSER;

//
// Interface.
//
typedef BOOLEAN
	(*ifAllocateParser)(
		IN		PADAPTER			Adapter, 
		IN		PGENERIC_PARSER		pParser
		);

typedef BOOLEAN
	(*ifFreeParser)(
		IN		PADAPTER	Adapter,
		IN		PGENERIC_PARSER		pParser
		);



//=============================================================================
//	Prototype of public function in ParserGen.c.
//=============================================================================

//
// Parser routines.
//
#if DBG
VOID
DbgProtocol(
	IN		u4Byte				protocol
	);
#else
	#define DbgProtocol(_p)
#endif


VOID
GPUseHPParser(
	IN		PGENERIC_PARSER	pParser
	);

BOOLEAN
GPParserHandlerEthernet(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserHandlerWlan(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserHandlerWlanLlc(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserHandlerIP(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPAllocateParser(
	IN		PADAPTER			Adapter,
	IN		u1Byte				Pid,
	IN		const char*				strParserName,
	IN		ifAllocateParser	AllocateRoutine,
	IN		GPParserGate		ParserGateRoutine,
	IN		GPParserAction		ParserActionRoutine,
	IN		BOOLEAN				bUseHP
	);

VOID
GPFreeParser(
	IN		PADAPTER		Adapter,
	IN		u1Byte			Pid,
	IN		ifFreeParser	FreeRoutine
	);


TR_ACTION
GPParseTCB(
	IN		PADAPTER	Adapter,
	IN		PRT_TCB		pTcb,
	IN		PROTO_ID	InitProtocol
	);

TR_ACTION
GPParseRFD(
	IN		PADAPTER	Adapter,
	IN		PRT_RFD		pRfd,
	IN		PROTO_ID	InitProtocol
	);





//=============================================================================
//	End of Prototype of public function in ParserGen.c.
//=============================================================================

//=============================================================================
// Customized parser section of GP_VOWLAN_SIP.
//=============================================================================

//
// Custom parser defines.
//
#define GP_VOWLAN_SIP			1	// The SIP Custom ID

#define MAX_SESSION				16
#define MAX_SESSION_ID			80

// Signature start.
#define UNKNOWN_SIG				0

typedef struct _SESSION
{
	u2Byte		srcPort;
	u2Byte		dstPort;
	u1Byte		sessionId[MAX_SESSION_ID];
	u4Byte		sessionIdLen;
	BOOLEAN		bUsed;
} SESSION, *PSESSION;

typedef struct _GP_VOWLAN_CONTEXT
{
	SESSION		Session[MAX_SESSION];
} GP_VOWLAN_CONTEXT, *PGP_VOWLAN_CONTEXT;

BOOLEAN
GPParserGateVoWlanSIP(
	IN		PADAPTER	Adapter,
	IN		PVOID		pParser
	);

TR_ACTION
GPParserActionVoWlanSIP(
	IN		PADAPTER	Adapter,
	IN		PGPPARSE_TOKEN		pToken,
	IN		PVOID		pParser
	);

BOOLEAN
GPAllocateParserVoWlanSIP(
	IN		PADAPTER			Adapter,
	IN		PGENERIC_PARSER		pParser
	);


BOOLEAN
GPFreeParserVoWlanSIP(
	IN		PADAPTER			Adapter,
	IN		PGENERIC_PARSER		pParser
	);

BOOLEAN
GPParserCustomHandleUDP2SIP(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserCustomHandleSIP2SDP(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserCustomHandleSIPSTATUS(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GetCallId(
	IN		PGPPARSE_TOKEN	pToken,
	IN		BOOLEAN			bNoAdvance,
	OUT		pu1Byte			callId,
	OUT		pu4Byte			callIdLen
	);

BOOLEAN
AddSession(
	IN		PGP_VOWLAN_CONTEXT	pContext,
	IN		pu1Byte				sessionId,
	IN		u4Byte				sessionIdLen
	);


VOID
RemoveSession(
	IN		PGP_VOWLAN_CONTEXT	pContext,
	IN		pu1Byte				sessionId,
	IN		u4Byte				sessionIdLen
	);

BOOLEAN
UpdateSessionInfo(
	IN		PGP_VOWLAN_CONTEXT	pContext,
	IN		pu1Byte				sessionId,
	IN		u4Byte				sessionIdLen,
	IN		u2Byte				srcPort,
	IN		u2Byte				dstPort
	);

BOOLEAN
MatchSession(
	IN		PGP_VOWLAN_CONTEXT	pContext,
	IN		u2Byte				Port,
	IN		u1Byte				Flag
	);

BOOLEAN
GPParserCustomHandleSDP(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserCustomHandleSIPBYE(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserCustomHandleUDP2RTP(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserCustomHandleRTP2G711(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPParserCustomHandleG711(
	IN		PADAPTER		Adapter,
	IN		PVOID			pParserContext,
	IN		PROTO_ID		CurrProtocol,
	IN		PROTO_ID		NextProtocol,
	OUT		pu1Byte			pSigBuffer,
	IN		u4Byte			SigBufferLen,
	IN		PGPPARSE_TOKEN	pToken,
	OUT		pu4Byte			AdvBytes
	);

BOOLEAN
GPGetParseRFDInfo(
	IN		PADAPTER		Adapter,
	IN		PRT_RFD			pRfd,
	IN		PRX_FILTER_INFO	pRxfiterInfo
	);


//=============================================================================
// End of Customized parser section of GP_VOWLAN_SIP.
//=============================================================================


#endif // end of __INC_PARSERGEN_H