summaryrefslogtreecommitdiff
path: root/network/wlan/WDI/COMMON/Protocol802_11.c
blob: 2943422ca8dca65fed2ee06248a77c229b950482 (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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
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
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
#include "Mp_Precomp.h"

#if WPP_SOFTWARE_TRACE
#include "Protocol802_11.tmh"
#endif

static u2Byte sPacketIEOffsetTable[] = 
{
	sMacHdrLng + 4, 		//SubType_Asoc_Req		= 0,
	sMacHdrLng + 6, 		//SubType_Asoc_Rsp		= 1,
	sMacHdrLng + 10, 		//SubType_Reasoc_Req	= 2,
	sMacHdrLng + 6, 		//SubType_Reasoc_Rsp	= 3,
	sMacHdrLng + 0, 		//SubType_Probe_Req	= 4,
	sMacHdrLng + 12, 		//SubType_Probe_Rsp	= 5,
	0, 					// rsvd				= 6, 	x
	0, 					// rsvd				= 7,	 x
	sMacHdrLng + 12, 		//SubType_Beacon		= 8, 
	0, 					//SubType_Atim			= 9, 	x
	0, 					//SubType_Disasoc		= 10, 	x
	sMacHdrLng + 6, 		//SubType_Auth			= 11,
	0, 					//SubType_Deauth		= 12, 	x
};

// Pattern Array
// Qos (0x1)
u1Byte	PAT_ACT_QOS_ADDTSREQ[] = {0x01, 0x00};
u1Byte	PAT_ACT_QOS_ADDTSRSP[] = {0x01, 0x01};
u1Byte	PAT_ACT_QOS_DELTS[] = {0x01, 0x02};
u1Byte	PAT_ACT_QOS_SCHEDULE[] = {0x01, 0x03};
// DLS (0x2)
u1Byte	PAT_ACT_DLS_DLSREQ[] = {0x02, 0x00};
u1Byte	PAT_ACT_DLS_DLSRSP[] = {0x02, 0x01};
u1Byte	PAT_ACT_DLS_DLSTEARDOWN[] = {0x02, 0x02};
// BA (0x3)
u1Byte	PAT_ACT_BA_ADDBAREQ[] = {0x03, 0x00};
u1Byte	PAT_ACT_BA_ADDBARSP[] = {0x03, 0x01};
u1Byte	PAT_ACT_BA_DELBA[] = {0x03, 0x02};
// Public (0x4)
u1Byte	PAT_ACT_BSS_COEXIST[] = {0x04, 0x00};
u1Byte	PAT_ACT_TDLS_DISC_RSP[] = {0x04, 0x0E};
u1Byte	PAT_ACT_P2P_GO_NEG_REQ[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x00};	// P2P GO Negotiation Request
u1Byte	PAT_ACT_P2P_GO_NEG_RSP[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x01};	// P2P GO Negotiation Response
u1Byte	PAT_ACT_P2P_GO_NEG_CONF[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x02};	// P2P GO Negotiation Confirm
u1Byte	PAT_ACT_P2P_INVIT_REQ[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x03};	// P2P Invitation Request
u1Byte	PAT_ACT_P2P_INVIT_RSP[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x04};	// P2P Invitation Response
u1Byte	PAT_ACT_P2P_DEV_DISCOVERABILITY_REQ[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x05};	// P2P Device Discoverability Request
u1Byte	PAT_ACT_P2P_DEV_DISCOVERABILITY_RSP[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x06};	// P2P Device Discoverability Response
u1Byte	PAT_ACT_P2P_PROV_DISC_REQ[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x07};	// P2P Provision Discovery Request
u1Byte	PAT_ACT_P2P_PROV_DISC_RSP[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x09, 0x08};	// P2P Provision Discovery Response
u1Byte	PAT_ACT_NAN_SDF[] = {0x04, 0x09, 0x50, 0x6F, 0x9A, 0x13};	// NAN SDF
u1Byte	PAT_ACT_GAS_INT_REQ[] = {0x04, 0x0A};	// GAS Initial Request
u1Byte	PAT_ACT_GAS_INT_RSP[] = {0x04, 0x0B};	// GAS Initial Response
u1Byte	PAT_ACT_GAS_COMEBACK_REQ[] = {0x04, 0x0C};	// GAS Comeback Request
u1Byte	PAT_ACT_GAS_COMEBACK_RSP[] = {0x04, 0x0D};	// GAS Comeback Response
// Radio Measurement - 11k (0x5)
u1Byte	PAT_ACT_RM_RM_REQ[] = {0x05, 0x00};	// Radio Measurement Request
u1Byte	PAT_ACT_RM_RM_RPT[] = {0x05, 0x01};	// Radio Measurement Report
u1Byte	PAT_ACT_RM_LM_REQ[] = {0x05, 0x02};	// Link Measurement Request
u1Byte	PAT_ACT_RM_LM_RPT[] = {0x05, 0x03};	// Link Measurement Report
u1Byte	PAT_ACT_RM_NR_REQ[] = {0x05, 0x04};	// Neighbor Report Request
u1Byte	PAT_ACT_RM_NR_RSP[] = {0x05, 0x05};	// Neighbor Report Response
// High Throughput - 11n (0x7)
u1Byte	PAT_ACT_HT_NOTI_CHNL_WIDTH[] = {0x07, 0x00};	// Notify Channel Width
u1Byte	PAT_ACT_HT_SM_PS[] = {0x07, 0x01};	// SM Power Save
u1Byte	PAT_ACT_HT_PSMP[] = {0x07, 0x02};	// PSMP
u1Byte	PAT_ACT_HT_SET_PCO_PHASE[] = {0x07, 0x03};	// Set PCO Phase
u1Byte	PAT_ACT_HT_CSI[] = {0x07, 0x04};	// CSI
u1Byte	PAT_ACT_HT_NON_COMPRESS_BEAMFORMING[] = {0x07, 0x05};	// Noncompressed Beamforming
u1Byte	PAT_ACT_HT_COMPRESS_BEAMFORMING[] = {0x07, 0x06};	// Compressed Beamforming
u1Byte	PAT_ACT_HT_ASEL_FEEDBACK[] = {0x07, 0x07};	// ASEL Indices Feedback
// SA Query (0x8)
u1Byte	PAT_ACT_SA_QUERY_REQ[] = {0x08, 0x00};	// SA Query Request
// TDLS-11z (0x0C)
u1Byte	PAT_ACT_TDLS_REQ[] = {0x0C, 0x00};	// TDLS Setup Request
u1Byte	PAT_ACT_TDLS_RSP[] = {0x0C, 0x01};	// TDLS Setup Response
u1Byte	PAT_ACT_TDLS_CONFIRM[] = {0x0C, 0x02};	// TDLS Setup Confirm
u1Byte	PAT_ACT_TDLS_TEARDOWN[] = {0x0C, 0x03};	// TDLS Setup Teardown
u1Byte	PAT_ACT_TDLS_PEER_TRAFIC_IND[] = {0x0C, 0x04};	// TDLS Peer Traffic Indication
u1Byte	PAT_ACT_TDLS_CHNL_SW_REQ[] = {0x0C, 0x05};	// TDLS Channel Switch Request
u1Byte	PAT_ACT_TDLS_CHNL_SW_RSP[] = {0x0C, 0x06};	// TDLS Channel Switch Response
u1Byte	PAT_ACT_TDLS_PEER_PSM_REQ[] = {0x0C, 0x07};	// TDLS Peer PSM Request
u1Byte	PAT_ACT_TDLS_PEER_PSM_RSP[] = {0x0C, 0x08};	// TDLS Peer PSM Response
u1Byte	PAT_ACT_TDLS_PEER_TRAFIC_RSP[] = {0x0C, 0x09};	// TDLS Peer Traffic Response
u1Byte	PAT_ACT_TDLS_DISC_REQ[] = {0x0C, 0x0A};	// TDLS Discovery Request
// WMM (0x11)
u1Byte	PAT_ACT_WMM_ADDTSREQ[] = {0x11, 0x00};
u1Byte	PAT_ACT_WMM_ADDTSRSP[] = {0x11, 0x01};
u1Byte	PAT_ACT_WMM_DELTS[] = {0x11, 0x02};
// VHT (0x15)
u1Byte	PAT_ACT_VHT_COMPRESSED_BEAMFORMING[] = {0x15, 0x00};
u1Byte	PAT_ACT_VHT_GROUPID_MANAGEMENT[] = {0x15, 0x01};
u1Byte	PAT_ACT_VHT_OPMODE_NOTIFICATION[] = {0x15, 0x02};
//Vendor Specific (0x7F)
u1Byte	PAT_ACT_P2P_NOA[] = {0x7F, 0x50, 0x6F, 0x9A, 0x09, 0x00};	// P2P Notice of Absence
u1Byte	PAT_ACT_P2P_PRESENCE_REQ[] = {0x7F, 0x50, 0x6F, 0x9A, 0x09, 0x01};	// P2P Presence Request
u1Byte	PAT_ACT_P2P_PRESENCE_RSP[] = {0x7F, 0x50, 0x6F, 0x9A, 0x09, 0x02};	// P2P Presence Response
u1Byte	PAT_ACT_P2P_GO_DISCOVERABILITY_REQ[] = {0x7F, 0x50, 0x6F, 0x9A, 0x09, 0x03};	// P2P GO Discoverability Request

#define	FILL_PATTERN_MAP(_Type, _Pattern)	{_Type, sizeof(_Pattern), _Pattern}

// The pattern array of action frames.
// By Bruce, 2012-03-09.
PKT_PATTERN_MAP	PktActPatternsMap[] =
{
	// Qos (0x1)
	FILL_PATTERN_MAP(ACT_PKT_QOS_ADDTSREQ, PAT_ACT_QOS_ADDTSREQ),
	FILL_PATTERN_MAP(ACT_PKT_QOS_ADDTSRSP, PAT_ACT_QOS_ADDTSRSP),
	FILL_PATTERN_MAP(ACT_PKT_QOS_DELTS, PAT_ACT_QOS_DELTS),
	FILL_PATTERN_MAP(ACT_PKT_QOS_SCHEDULE, PAT_ACT_QOS_SCHEDULE),
	// DLS (0x2)
	FILL_PATTERN_MAP(ACT_PKT_DLS_DLSREQ, PAT_ACT_DLS_DLSREQ),
	FILL_PATTERN_MAP(ACT_PKT_DLS_DLSRSP, PAT_ACT_DLS_DLSRSP),
	FILL_PATTERN_MAP(ACT_PKT_DLS_DLSTEARDOWN, PAT_ACT_DLS_DLSTEARDOWN),
	// BA (0x3)
	FILL_PATTERN_MAP(ACT_PKT_BA_ADDBAREQ, PAT_ACT_BA_ADDBAREQ),
	FILL_PATTERN_MAP(ACT_PKT_BA_ADDBARSP, PAT_ACT_BA_ADDBARSP),
	FILL_PATTERN_MAP(ACT_PKT_BA_DELBA, PAT_ACT_BA_DELBA),
	// Public (0x4)
	FILL_PATTERN_MAP(ACT_PKT_BSS_COEXIST, PAT_ACT_BSS_COEXIST),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_DISC_RSP, PAT_ACT_TDLS_DISC_RSP),
	FILL_PATTERN_MAP(ACT_PKT_P2P_GO_NEG_REQ, PAT_ACT_P2P_GO_NEG_REQ),
	FILL_PATTERN_MAP(ACT_PKT_P2P_GO_NEG_RSP, PAT_ACT_P2P_GO_NEG_RSP),
	FILL_PATTERN_MAP(ACT_PKT_P2P_GO_NEG_CONF, PAT_ACT_P2P_GO_NEG_CONF),
	FILL_PATTERN_MAP(ACT_PKT_P2P_INVIT_REQ, PAT_ACT_P2P_INVIT_REQ),
	FILL_PATTERN_MAP(ACT_PKT_P2P_INVIT_RSP, PAT_ACT_P2P_INVIT_RSP),
	FILL_PATTERN_MAP(ACT_PKT_P2P_DEV_DISCOVERABILITY_REQ, PAT_ACT_P2P_DEV_DISCOVERABILITY_REQ),
	FILL_PATTERN_MAP(ACT_PKT_P2P_DEV_DISCOVERABILITY_RSP, PAT_ACT_P2P_DEV_DISCOVERABILITY_RSP),
	FILL_PATTERN_MAP(ACT_PKT_P2P_PROV_DISC_REQ, PAT_ACT_P2P_PROV_DISC_REQ),
	FILL_PATTERN_MAP(ACT_PKT_P2P_PROV_DISC_RSP, PAT_ACT_P2P_PROV_DISC_RSP),
	FILL_PATTERN_MAP(ACT_PKT_NAN_SDF, PAT_ACT_NAN_SDF),
	FILL_PATTERN_MAP(ACT_PKT_GAS_INT_REQ, PAT_ACT_GAS_INT_REQ),
	FILL_PATTERN_MAP(ACT_PKT_GAS_INT_RSP, PAT_ACT_GAS_INT_RSP),
	FILL_PATTERN_MAP(ACT_PKT_GAS_COMEBACK_REQ, PAT_ACT_GAS_COMEBACK_REQ),
	FILL_PATTERN_MAP(ACT_PKT_GAS_COMEBACK_RSP, PAT_ACT_GAS_COMEBACK_RSP),
	// Radio Measurement - 11k (0x5)
	FILL_PATTERN_MAP(ACT_PKT_RM_RM_REQ, PAT_ACT_RM_RM_REQ),
	FILL_PATTERN_MAP(ACT_PKT_RM_RM_RPT, PAT_ACT_RM_RM_RPT),
	FILL_PATTERN_MAP(ACT_PKT_RM_LM_REQ, PAT_ACT_RM_LM_REQ),
	FILL_PATTERN_MAP(ACT_PKT_RM_LM_RPT, PAT_ACT_RM_LM_RPT),
	FILL_PATTERN_MAP(ACT_PKT_RM_NR_REQ, PAT_ACT_RM_NR_REQ),
	FILL_PATTERN_MAP(ACT_PKT_RM_NR_RSP, PAT_ACT_RM_NR_RSP),
	// High Throughput - 11n (0x7)
	FILL_PATTERN_MAP(ACT_PKT_HT_NOTI_CHNL_WIDTH, PAT_ACT_HT_NOTI_CHNL_WIDTH),
	FILL_PATTERN_MAP(ACT_PKT_HT_SM_PS, PAT_ACT_HT_SM_PS),
	FILL_PATTERN_MAP(ACT_PKT_HT_PSMP, PAT_ACT_HT_PSMP),
	FILL_PATTERN_MAP(ACT_PKT_HT_SET_PCO_PHASE, PAT_ACT_HT_SET_PCO_PHASE),
	FILL_PATTERN_MAP(ACT_PKT_HT_CSI, PAT_ACT_HT_CSI),
	FILL_PATTERN_MAP(ACT_PKT_HT_NON_COMPRESSED_BEAMFORMING, PAT_ACT_HT_NON_COMPRESS_BEAMFORMING),
	FILL_PATTERN_MAP(ACT_PKT_HT_COMPRESSED_BEAMFORMING, PAT_ACT_HT_COMPRESS_BEAMFORMING),
	FILL_PATTERN_MAP(ACT_PKT_HT_ASEL_FEEDBACK, PAT_ACT_HT_ASEL_FEEDBACK),
	// SA Query - 11w(0x8)
	FILL_PATTERN_MAP(ACT_PKT_SA_QUERY_REQ, PAT_ACT_SA_QUERY_REQ),
	// TDLS-11z (0x0C)
	FILL_PATTERN_MAP(ACT_PKT_TDLS_REQ, PAT_ACT_TDLS_REQ),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_RSP, PAT_ACT_TDLS_RSP),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_CONFIRM, PAT_ACT_TDLS_CONFIRM),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_TEARDOWN, PAT_ACT_TDLS_TEARDOWN),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_PEER_TRAFIC_IND, PAT_ACT_TDLS_PEER_TRAFIC_IND),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_CHNL_SW_REQ, PAT_ACT_TDLS_CHNL_SW_REQ),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_CHNL_SW_RSP, PAT_ACT_TDLS_CHNL_SW_RSP),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_PEER_PSM_REQ, PAT_ACT_TDLS_PEER_PSM_REQ),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_PEER_PSM_RSP, PAT_ACT_TDLS_PEER_PSM_RSP),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_PEER_TRAFIC_RSP, PAT_ACT_TDLS_PEER_TRAFIC_RSP),
	FILL_PATTERN_MAP(ACT_PKT_TDLS_DISC_REQ, PAT_ACT_TDLS_DISC_REQ),
	// WMM (0x11)
	FILL_PATTERN_MAP(ACT_PKT_WMM_ADDTSREQ, PAT_ACT_WMM_ADDTSREQ),
	FILL_PATTERN_MAP(ACT_PKT_WMM_ADDTSRSP, PAT_ACT_WMM_ADDTSRSP),
	FILL_PATTERN_MAP(ACT_PKT_WMM_DELTS, PAT_ACT_WMM_DELTS),
	// VHT (0x15)
	FILL_PATTERN_MAP(ACT_PKT_VHT_COMPRESSED_BEAMFORMING, PAT_ACT_VHT_COMPRESSED_BEAMFORMING),
	FILL_PATTERN_MAP(ACT_PKT_VHT_GROUPID_MANAGEMENT, PAT_ACT_VHT_GROUPID_MANAGEMENT),
	FILL_PATTERN_MAP(ACT_PKT_VHT_OPMODE_NOTIFICATION, PAT_ACT_VHT_OPMODE_NOTIFICATION),
	//Vendor Specific (0x7F)
	FILL_PATTERN_MAP(ACT_PKT_P2P_NOA, PAT_ACT_P2P_NOA),
	FILL_PATTERN_MAP(ACT_PKT_P2P_PRESENCE_REQ, PAT_ACT_P2P_PRESENCE_REQ),
	FILL_PATTERN_MAP(ACT_PKT_P2P_PRESENCE_RSP, PAT_ACT_P2P_PRESENCE_RSP),
	FILL_PATTERN_MAP(ACT_PKT_P2P_GO_DISCOVERABILITY_REQ, PAT_ACT_P2P_GO_DISCOVERABILITY_REQ),

	// ===== Insert new item above this line =====
	{ACT_PKT_TYPE_UNKNOWN, 0, NULL}
};

// 802.11 Action Frame IE offset
PKT_IE_OFFSET_MAP	ActPktIeOffsetMap[] =
{	
	// Qos (0x1)
	{ACT_PKT_QOS_ADDTSREQ, (sMacHdrLng + 3)},
	{ACT_PKT_QOS_ADDTSRSP, (sMacHdrLng + 5)},
	{ACT_PKT_QOS_SCHEDULE, (sMacHdrLng + 2)},
	// DLS (0x2)
	{ACT_PKT_DLS_DLSREQ, (sMacHdrLng + 18)},
	{ACT_PKT_DLS_DLSRSP, (sMacHdrLng + 18)},
	// Public (0x4)
	{ACT_PKT_BSS_COEXIST, (sMacHdrLng + 2)},
	{ACT_PKT_TDLS_DISC_RSP, (sMacHdrLng + 5)},
	{ACT_PKT_P2P_GO_NEG_REQ, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_GO_NEG_RSP, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_GO_NEG_CONF, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_INVIT_REQ, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_INVIT_RSP, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_DEV_DISCOVERABILITY_REQ, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_DEV_DISCOVERABILITY_RSP, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_PROV_DISC_REQ, (sMacHdrLng + 8)},
	{ACT_PKT_P2P_PROV_DISC_RSP, (sMacHdrLng + 8)},
	// WMM (0x11)
	{ACT_PKT_WMM_ADDTSREQ, (sMacHdrLng + 4)},
	{ACT_PKT_WMM_ADDTSRSP, (sMacHdrLng + 4)},
	{ACT_PKT_WMM_DELTS, (sMacHdrLng + 4)},
	//Vendor Specific (0x7F)
	{ACT_PKT_P2P_NOA, (sMacHdrLng + 7)},
	{ACT_PKT_P2P_PRESENCE_REQ, (sMacHdrLng + 7)},
	{ACT_PKT_P2P_PRESENCE_RSP, (sMacHdrLng + 7)},
	{ACT_PKT_P2P_GO_DISCOVERABILITY_REQ, (sMacHdrLng + 7)},
	
	// ===== Insert new item above this line =====
	{ACT_PKT_TYPE_UNKNOWN, 0}
};

// Pattern Array
//TDLS
u1Byte	PAT_ENCAP_DATA_TDLS_SETUP_REQ[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x00};
u1Byte	PAT_ENCAP_DATA_TDLS_SETUP_RSP[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x01};
u1Byte	PAT_ENCAP_DATA_TDLS_SETUP_CONFIRM[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x02};
u1Byte	PAT_ENCAP_DATA_TDLS_TEARDOWN[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x03};
u1Byte	PAT_ENCAP_DATA_TDLS_TRAFFIC_INDI[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x04};
u1Byte	PAT_ENCAP_DATA_TDLS_CHNL_SW_REQ[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x05};
u1Byte	PAT_ENCAP_DATA_TDLS_CHNL_SW_RSP[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x06};
u1Byte	PAT_ENCAP_DATA_TDLS_PSM_REQ[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x07};
u1Byte	PAT_ENCAP_DATA_TDLS_PSM_RSP[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x08};
u1Byte	PAT_ENCAP_DATA_TDLS_TRAFFIC_RSP[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x09};
u1Byte	PAT_ENCAP_DATA_TDLS_DISC_REQ[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x0C, 0x0A};
u1Byte	PAT_ENCAP_DATA_TDLS_PROBE_REQ[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x7F, 0x50, 0x6F, 0x9A, 0x04};
u1Byte	PAT_ENCAP_DATA_TDLS_PROBE_RSP[] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00, 0x89, 0x0D, 0x02, 0x7F, 0x50, 0x6F, 0x9A, 0x05};

// CCX
u1Byte	PAT_ENCAP_DATA_CCX_IAPP[] = {0xAA, 0xAA, 0x03, 0x00, 0x40, 0x96, 0x00, 0x00};

// The pattern array of encapsulated data frames.
// By Bruce, 2012-03-23.
PKT_PATTERN_MAP	PktEncapDataPatternsMap[] =
{
	// TDLS
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_SETUP_REQ, PAT_ENCAP_DATA_TDLS_SETUP_REQ),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_SETUP_RSP, PAT_ENCAP_DATA_TDLS_SETUP_RSP),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_SETUP_CONFIRM, PAT_ENCAP_DATA_TDLS_SETUP_CONFIRM),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_TEARDOWN, PAT_ENCAP_DATA_TDLS_TEARDOWN),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_TRAFFIC_INDI, PAT_ENCAP_DATA_TDLS_TRAFFIC_INDI),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_CHNL_SW_REQ, PAT_ENCAP_DATA_TDLS_CHNL_SW_REQ),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_CHNL_SW_RSP, PAT_ENCAP_DATA_TDLS_CHNL_SW_RSP),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_PSM_REQ, PAT_ENCAP_DATA_TDLS_PSM_REQ),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_PSM_RSP, PAT_ENCAP_DATA_TDLS_PSM_RSP),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_TRAFFIC_RSP, PAT_ENCAP_DATA_TDLS_TRAFFIC_RSP),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_DISC_REQ, PAT_ENCAP_DATA_TDLS_DISC_REQ),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_PROBE_REQ, PAT_ENCAP_DATA_TDLS_PROBE_REQ),
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_TDLS_PROBE_RSP, PAT_ENCAP_DATA_TDLS_PROBE_RSP),

	// CCX RM
	FILL_PATTERN_MAP(ENCAP_DATA_PKT_CCX_IAPP, PAT_ENCAP_DATA_CCX_IAPP),

	// ===== Insert new item above this line =====
	{ENCAP_DATA_PKT_UNKNOWN, 0, NULL}
};



BOOLEAN
EqualOS(
	IN	OCTET_STRING	os1,
	IN	OCTET_STRING	os2
	)
{
	if( os1.Length!=os2.Length )
		return FALSE;

	if( os1.Length==0 )
		return FALSE;		

	return (PlatformCompareMemory(os1.Octet,os2.Octet,os1.Length)==0) ? TRUE:FALSE;
}


BOOLEAN
IsSSIDAny(
	IN	OCTET_STRING	ssid
	)
{
	BOOLEAN retValue = FALSE;
	
	if(ssid.Length == 0)	// a kind of "ANY SSID"
		retValue =  TRUE;
	else if(ssid.Length == 3)
	{
		if(	(ssid.Octet[0]=='A' || ssid.Octet[0]=='a') &&
			(ssid.Octet[1]=='N' || ssid.Octet[1]=='n') &&
			(ssid.Octet[2]=='Y' || ssid.Octet[2]=='y')	 	)
		retValue =  TRUE;
	}

	return retValue;	
}


BOOLEAN
IsSSIDDummy(
	IN	OCTET_STRING	ssid
	)
{
	u2Byte	i;
	u1Byte	ch;

	if(ssid.Length == 0)	// a kind of "ANY SSID"
		return FALSE;
	for(i = 0; i < ssid.Length; i++)
	{
		ch = ssid.Octet[i];
		if( (ch >= 0x20) && (ch <= 0x7e) )	//wifi, printable ascii code must be supported
			;//ok
		else
		{
			// If the SSID contain Any Illeagl ASCII Code
			// It should be reganize as dummy SSID.
			// It modified for No Link any If UI does no Set the OID or registery
			// Modifid by Mars, 20090722
			// 2010/04/12 MH For SEC Korea SSID case, we will not treat it as dummy SSID.
			// if the SSID length is not 32.
			if (ssid.Length == MAX_SSID_LEN)
				return TRUE;
		}
	}
	return FALSE;
}

BOOLEAN
IsSSIDNdisTest(
	IN	OCTET_STRING	ssid
	)
{
	if(ssid.Length ==0)	// a kind of "ANY SSID"
	{
		return TRUE;
	}
	
	if(	(ssid.Length >= 8) &&
		(	(ssid.Octet[0]=='N' || ssid.Octet[0]=='n') &&
			(ssid.Octet[1]=='D' || ssid.Octet[1]=='d') &&
			(ssid.Octet[2]=='I' || ssid.Octet[2]=='i') &&	 	
			(ssid.Octet[3]=='S' || ssid.Octet[2]=='s') && 
			(ssid.Octet[4]=='T' || ssid.Octet[2]=='t') &&
			(ssid.Octet[5]=='E' || ssid.Octet[2]=='e') &&
			(ssid.Octet[6]=='S' || ssid.Octet[2]=='s') &&
			(ssid.Octet[7]=='T' || ssid.Octet[2]=='t'))	 )
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
	
}

//
// Description:
//		Checks whether a packet contains any invalid IE.
//		Implemented based on PacketGetElement().
// 
// 2008.12.32, haich
//
BOOLEAN
PacketCheckIEValidity(
	IN	OCTET_STRING	packet,
	IN	PRT_RFD			pRfd
	)
{
	u2Byte			PacketSubType;
	u2Byte			offset = 0; 		// current offset to the packet
	BOOLEAN			bRet = TRUE;		// used for return
	u1Byte			u1EID;			// EID of  current IE
	u1Byte			u1ELength;		// Length of current IE
	u2Byte			ValidPacketLength=0;

	do
	{
		if(sMacHdrLng > packet.Length)
		{// not able to get packet type
			RT_TRACE(COMP_SCAN, DBG_LOUD, 
				("PacketCheckIEValidity(): sMacHdrLng(%u) > packet.Length (%u)\n", sMacHdrLng, packet.Length));
			bRet = FALSE;
			break;
		}

		if(!IsMgntFrame(packet.Octet))
		{// not a mangaement frame
			RT_TRACE(COMP_SCAN, DBG_LOUD, 
				("PacketCheckIEValidity(): frame type: %u\n", Frame_Type(packet)));
			bRet = FALSE;
			break;
		}

		PacketSubType = Frame_Subtype(packet);
		
		if(PacketSubType > 12)
		{// beyond deauth
			RT_TRACE(COMP_SCAN, DBG_LOUD, 
				("PacketCheckIEValidity(): wrong subtype: %u\n", PacketSubType));
			bRet = FALSE;
			break;
		}

		if(!(offset = sPacketIEOffsetTable[PacketSubType]))
		{// not a sub type of frame that could have IEs
			RT_TRACE(COMP_SCAN, DBG_LOUD, 
				("PacketCheckIEValidity(): not a sub type of frame that could have IEs, subtype: %u\n", PacketSubType));
			bRet = FALSE;
			break;
		}

		do // for all IEs
		{
			if(offset + 2 >= packet.Length)
			{// [malicious attack] not ok to read EID and Element Length
				RT_TRACE(COMP_SCAN, DBG_LOUD, 
					("PacketCheckIEValidity(): [malicious attack] not ok to read EID and Element Length\n"));
				bRet = TRUE;
				break;
			}

			u1EID = packet.Octet[offset];		// Get current Element ID.
			u1ELength = packet.Octet[offset+1];	// Get current length of the IE.

			if(!IsIELengthValid(u1EID, u1ELength))
			{
				bRet = FALSE;
				break;
			}
			
			if(offset + 2 + u1ELength < packet.Length) 
			{// Jump to the position of length of next IE. (2 byte is for the ID and length field.)
				offset = offset + 2 + u1ELength; // incr at least 2 for every loop
				ValidPacketLength = offset;
			}
			else if(offset + 2 + u1ELength == packet.Length) 
			{// the IEs in the packet are all valid.
				bRet = TRUE;
				ValidPacketLength = offset + 2 + u1ELength;
				break;
			}
			else 
			{// [malicious attack] length of IE exceeds packet length
				RT_TRACE(COMP_SCAN, DBG_LOUD, 
					("PacketCheckIEValidity(): [malicious attack] length of IE exceeds packet length\n"));
				bRet = TRUE;
				break;
			}
		}while(TRUE);

	}while(FALSE);

	if(!bRet)
	{
		RT_PRINT_DATA(COMP_SCAN, DBG_TRACE, "Packet with wrong IE:", packet.Octet, packet.Length);
	}
	pRfd->ValidPacketLength = ValidPacketLength;
	return bRet;

}

//
// Description:
//	Determine the packet type of the action frame.
// Argument:
//	[in] posMpdu -
//		The full 802.11 packet.
// Return:
//	If this packet is determined successfully, return the ACT_PKT_xxx.
//	If this function cannot recognize this packet, return ACT_PKT_TYPE_UNKNOWN.
// Remark:
//	It checks the category, action field (if there is such one) and OUI information to determine the type.
//	Do not input non-action frame to this function and it doesn't check if this packet is action frame.
// By Bruce, 2012-03-09.	
//
ACT_PKT_TYPE
PacketGetActionFrameType(
	IN	POCTET_STRING	posMpdu
	)
{
	u4Byte	idx = 0;

	if(posMpdu->Length <= sMacHdrLng)
	{
		RT_TRACE_F(COMP_DBG, DBG_WARNING, ("[WARNING] Invalid length (%d) for this packet!\n", posMpdu->Length));
		return ACT_PKT_TYPE_UNKNOWN;
	}

	//Retrieve the table and check the patterns
	for(idx = 0; ACT_PKT_TYPE_UNKNOWN != (ACT_PKT_TYPE)(PktActPatternsMap[idx].PktType); idx ++)
	{
		// Packet length mismatch
		if((posMpdu->Length - sMacHdrLng) < PktActPatternsMap[idx].PatternLen)
			continue;

		// Compare pattern
		if(0 == PlatformCompareMemory(Frame_FrameBody(*posMpdu), PktActPatternsMap[idx].Pattern, PktActPatternsMap[idx].PatternLen))
		{
			return (ACT_PKT_TYPE)(PktActPatternsMap[idx].PktType);
		}		
	}
	return ACT_PKT_TYPE_UNKNOWN;
}

//
// Description:
//	Determine the packet type of the encapsulated data frame.
// Argument:
//	[in] posDataContent -
//		The full data content after 802.11 header(including Qos + Security header + HC control header).
//		It should be the header of LLC.
// Return:
//	If this packet is determined successfully, return the ENCAP_DATA_PKT_xxx.
//	If this function cannot recognize this packet, return ENCAP_DATA_PKT_UNKNOWN.
// Remark:
//	It checks the LLC/SNAP header, and the following patters.
//	This function does not check the security or any 802.11 condition.
// By Bruce, 2012-03-23.
//
ENCAP_DATA_PKT_TYPE
PacketGetEncapDataFrameType(
	IN	POCTET_STRING	posDataContent
	)
{
	u4Byte	idx = 0;

	//Retrieve the table and check the patterns
	for(idx = 0; ENCAP_DATA_PKT_UNKNOWN != (ACT_PKT_TYPE)(PktEncapDataPatternsMap[idx].PktType); idx ++)
	{
		// Packet length mismatch
		if(posDataContent->Length < PktEncapDataPatternsMap[idx].PatternLen)
			continue;

		// Compare pattern
		if(0 == PlatformCompareMemory(posDataContent->Octet, PktEncapDataPatternsMap[idx].Pattern, PktEncapDataPatternsMap[idx].PatternLen))
		{
			return (ENCAP_DATA_PKT_TYPE)(PktEncapDataPatternsMap[idx].PktType);
		}		
	}
	return ENCAP_DATA_PKT_UNKNOWN;
}


//
// Description:
//	Get the offset according to the packet type.
// Arguments:
//	[in] posMpdu -
//		The full 802.11 packet.
//	[out] pOffset -
//		The returned offset for the fist IE.
// Return:
//	If this executes without any error, return FALSE.
//	If this packet has no IE, return FALSE.
// Remark:
//	None.
// By Bruce, 2012-03-09.
//
BOOLEAN
PacketGetIeOffset(
	IN	POCTET_STRING	posMpdu,
	OUT	pu2Byte			pOffset
	)
{
	BOOLEAN		bValid = TRUE;
	u4Byte		idx = 0;
	
	switch(PacketGetType(*posMpdu))
	{
		default:
			bValid = FALSE;
			break;
			
		case Type_Auth:
			*pOffset = (sMacHdrLng + 6);
			break;
			
		case Type_Probe_Req:
			*pOffset = (sMacHdrLng + 0);
			break;
			
		case Type_Beacon:
		case Type_Probe_Rsp:
			*pOffset = (sMacHdrLng + 12);
			break;
			
		case Type_Reasoc_Req:
			*pOffset = (sMacHdrLng + 10);
			break;
			
		case Type_Asoc_Req:
			*pOffset = (sMacHdrLng + 4);
			break;
			
		case Type_Asoc_Rsp:
		case Type_Reasoc_Rsp:
			*pOffset = (sMacHdrLng + 6);
			break;
			
		case Type_Disasoc:
		case Type_Deauth:
			*pOffset = (sMacHdrLng + 2);
			break;
				
		case Type_Action:
			{
				ACT_PKT_TYPE	actType = PacketGetActionFrameType(posMpdu);

				bValid = FALSE;
				if(ACT_PKT_TYPE_UNKNOWN == actType)
				{
					RT_TRACE_F(COMP_DBG, DBG_WARNING, ("[WARNING] Unrecognized action frame type!\n"));
					break;
				}
				for(idx = 0; ACT_PKT_TYPE_UNKNOWN != (ACT_PKT_TYPE)(ActPktIeOffsetMap[idx].PktType); idx ++)
				{
					if(actType == (ACT_PKT_TYPE)(ActPktIeOffsetMap[idx].PktType))
					{
						*pOffset = ActPktIeOffsetMap[idx].IeOffset;
						bValid = TRUE;
						break;
					}
				}

				if(!bValid)
				{
					RT_TRACE_F(COMP_DBG, DBG_WARNING, ("[WARNING] cannot find offset for action frame type = %d!\n", actType));
				}
			}
			break;
	}

	return bValid;
}

//
// Parsing Information Elements.
//
// This function is used to search the WPS Fragment IE
// In WPS 2.0. It wil content more then 2 IE is the forment
// DD-Len-00-50-f2-04-xxxxx-DD-Len-00-50-f2-04
//
u1Byte
PacketGetElementNum(
	IN	OCTET_STRING	packet,
	IN	ELEMENT_ID		ID,
	IN	OUI_TYPE		OUIType,
	IN	u1Byte			OUISubType
	)
{
	u2Byte			offset;
	OCTET_STRING	IEs;
	OCTET_STRING	ret={0,0};	// used for return
	u1Byte 			IENum = 0;

	if(!PacketGetIeOffset(&packet, &offset))
	{
		return 0;
	}
	
	if(offset < packet.Length)
	{
		pu1Byte	pIE;
		u2Byte IELen = (packet.Length - offset);
		
		pIE = (packet.Octet + offset);
		FillOctetString(IEs, pIE,IELen);

		RT_PRINT_DATA(COMP_WPS, DBG_TRACE, "The IE in the packet :\n", pIE, IELen);
		do
		{
			ret= IEGetElement(IEs, ID, OUIType, OUISubType);
			if(ret.Length > 0)
			{
				IENum++;
				RT_TRACE(COMP_WPS, DBG_TRACE,("We find a WPS IE in probe or beacon Fragment num is %d \n",IENum));
				IELen = IELen - ((u2Byte)(ret.Octet - pIE) + ret.Length);
				pIE = (ret.Octet + ret.Length);			
				FillOctetString(IEs, pIE,IELen);			
				RT_PRINT_DATA(COMP_WPS, DBG_TRACE, "The IE after WPS IE in the packet :\n", pIE, IELen);
			}
			else
			{
				RT_TRACE(COMP_WPS, DBG_TRACE,("There is no WPS IE in the probe or beacon\n"));				
			}
		}
		while(ret.Length != 0);
		
		return IENum;
	}
	else
	{
		return IENum;
	}
}


//
// Parsing Information Elements.
//
// Added a parameter "OUISubType" and rewrited by Annie, 2005-11-08,
// since the element ID of WPA-IE and WMM-IE are the same(0xDD=221).
//
OCTET_STRING 
PacketGetElement(
	IN	OCTET_STRING	packet,
	IN	ELEMENT_ID		ID,
	IN	OUI_TYPE		OUIType,
	IN	u1Byte			OUISubType
	)
{
	u2Byte			offset;
	OCTET_STRING	IEs;
	OCTET_STRING	ret={0,0};	// used for return

	if(!PacketGetIeOffset(&packet, &offset))
		return ret;

	if(offset < packet.Length)
	{
		FillOctetString(IEs, (packet.Octet + offset), (packet.Length - offset));
		return IEGetElement(IEs, ID, OUIType, OUISubType);
	}
	else
	{
		return ret;
	}
}

VOID
PacketMakeElement(
	IN	POCTET_STRING	packet,
	IN	ELEMENT_ID		ID,
	IN	OCTET_STRING	info
	)
{
	pu1Byte buf = packet->Octet + packet->Length;

	buf[0] = (u1Byte)ID;
	buf[1] = (u1Byte)info.Length;

	if(info.Length > 0)
	{
		PlatformMoveMemory( buf + 2, info.Octet, info.Length);
	}

	packet->Length += info.Length + 2;
}

VOID
PacketAppendData(
	IN	POCTET_STRING	packet,
	IN	OCTET_STRING	data
	)
{
	pu1Byte buf = packet->Octet + packet->Length;

	PlatformMoveMemory( buf, data.Octet, data.Length);

	packet->Length = packet->Length + data.Length;
}

BOOLEAN
TimGetBcMcBit(
	IN	OCTET_STRING	Tim
	)
{
	return	((Tim.Octet[2] & 0x01) == 0x01);
}

BOOLEAN	
TimGetAIDBit( 
	IN	OCTET_STRING	Tim, 
	IN	u2Byte			AID
	)
{
	BOOLEAN		result;
	u2Byte		offset,offset_byte;
	u1Byte		offset_bit;
	u2Byte		FirstStationInTim;
	
	FirstStationInTim = (Tim.Octet[2] & 0xFE) * 8;
	if( AID<FirstStationInTim || AID >= (FirstStationInTim+(Tim.Length-3)*8) )
	{	// Out of the range(too large)
		return FALSE;
	}
	else
	{
		
		offset = AID - FirstStationInTim;
		
		offset_byte = offset >>3;
		offset_bit  = (unsigned char)(offset & 0x7);

		// Look up in the partial virtual bitmap
		result = Tim.Octet[3 + offset_byte]&(0x01<<offset_bit);

		return result;
	}
}

u2Byte
N_DBPSOfRate(
		u4Byte	DataRate
		)
{
	u2Byte	N_DBPS = 24;

	switch(DataRate)
	{
	case 12:
		N_DBPS = 24;
		break;

	case 18:
		N_DBPS = 36;
		break;

	case 24:
		N_DBPS = 48;
		break;

	case 36:
		N_DBPS = 72;
		break;

	case 48:
		N_DBPS = 96;
		break;

	case 72:
		N_DBPS = 144;
		break;

	case 96:
		N_DBPS = 192;
		break;

	case 108:
		N_DBPS = 216;
		break;

	default:
		break;
	}

	return N_DBPS;
}

u2Byte 
ComputeTxTime(
	IN	u2Byte			FrameLength,
	IN	u4Byte			DataRate,
	IN	BOOLEAN			bManagementFrame,
	IN	BOOLEAN			bShortPreamble
	)
{
	u2Byte			FrameTime=0;
	u2Byte			N_DBPS;
	u2Byte			Ceiling;

	switch(DataRate)
	{
	case 2:
	case 4:
	case 11:
	case 22:
			// 1M can only use Long Preamble. Ref. 802.11b 18.2.2.2. 2005.01.18, by rcnjko.
			if( bManagementFrame || !bShortPreamble || DataRate == 2 )
			{	// long preamble
				FrameTime = (u2Byte)(144+48+(FrameLength*8*2/DataRate));		
			}
			else
			{	// Short preamble
				FrameTime = (u2Byte)(72+24+(FrameLength*8*2/DataRate));
			}

			if( ( FrameLength*8*2 % DataRate ) != 0 )
				FrameTime ++;
			break;
	case 12:
	case 18:
	case 24:
	case 36:
	case 44:
	case 48:
	case 66:
	case 72:
	case 96:
	case 108:
		N_DBPS = N_DBPSOfRate(DataRate);
		Ceiling = (16 + 8*FrameLength + 6) / N_DBPS + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
		FrameTime = (u2Byte)(16 + 4 + 4*Ceiling + 6);
		break;
	}
	
	return FrameTime;
}


BOOLEAN
IsHiddenSsid(
	OCTET_STRING		ssid
	)
{
        if( ((ssid.Length == 1) &&      (ssid.Octet[0] == 0x20) ) ||
                ((ssid.Length >  0) &&  (ssid.Octet[0] == 0x0 ) ) ||
                (ssid.Length == 0)        )
        {
                return TRUE;
        }
        return FALSE;
}


BOOLEAN
BeHiddenSsid(
	pu1Byte	ssidbuf,
	u1Byte	ssidlen
	)
{
        if( ((ssidlen == 1) &&      (ssidbuf[0] == 0x20) ) ||
                ((ssidlen >  0) &&  (ssidbuf[0] == 0x0 ) ) ||
                (ssidlen == 0)        )
        {
                return TRUE;
        }
        return FALSE;
}



BOOLEAN
NullSSID(
	OCTET_STRING	bcnPkt
	)
{
	OCTET_STRING	ssIdBeacon;
	u2Byte			i;
	BOOLEAN			athHdnAP;	//sean,20030410, fix for linksys BEFW11S4

//	ssIdBeacon = PacketGetElement( bcnPkt, EID_SsId );		// Rewrited for new added parameter. Annie, 2005-11-08.
//	ssIdBeacon = PacketGetElement( bcnPkt, EID_SsId, OUI_SUB_DONT_CARE );
	ssIdBeacon = PacketGetElement( bcnPkt, EID_SsId, OUI_SUB_DONT_CARE, OUI_SUBTYPE_DONT_CARE );
	for(i=0;i<ssIdBeacon.Length;i++)
	{
		if( ssIdBeacon.Octet[i] != 0x0 )
		{
			break;
		}
	}

	athHdnAP = (ssIdBeacon.Length == 1) && (ssIdBeacon.Octet[0]==0x20);
	return ((i==ssIdBeacon.Length)||athHdnAP)?TRUE:FALSE;
}

BOOLEAN
CompareSSID(
	pu1Byte	ssidbuf1,
	u2Byte	ssidlen1,
	pu1Byte	ssidbuf2,
	u2Byte	ssidlen2
)
{
	if(ssidlen1 == ssidlen2)
	{
		if((ssidlen1 == 0) ||
		    ( PlatformCompareMemory(ssidbuf1, ssidbuf2, ssidlen1) == 0 ))
		return TRUE;
	}
	
	return FALSE;
}

u1Byte
ComputeAckRate(
	IN	OCTET_STRING	BSSBasicRateSet,
	IN	u1Byte			DataRate)
{
	u2Byte	i;
	u1Byte	AckRate = 0;
	u1Byte	BasicRate;

	DataRate &= 0x7F;

	// Find the highest rate in the BSSBasicRateSet 
	// that is less than or equal to DataRate.
	for( i = 0; i < BSSBasicRateSet.Length; i++)
	{
		BasicRate = BSSBasicRateSet.Octet[i] & 0x7F; 
		if(	BasicRate <= DataRate && BasicRate > AckRate)
			AckRate = BasicRate; 
	}

	// Make sure the AckRate is in the same modulation of DataRate, 
	// otherwise we it shall use highest mandatory rate of PHY 
	// that is less than or equal to DataRate.
	switch(DataRate)
	{
	// CCK. 
	case MGN_1M:
	case MGN_2M:
	case MGN_5_5M:
	case MGN_11M:
		if(AckRate == 0 || !IS_CCK_RATE(AckRate) )
			AckRate = MGN_1M;
		break;

	// OFDM.
	case 12:
	case 18:
	case 24:
	case 36:
	case 48:
	case 72:
	case 96:
	case 108:
		if(	AckRate == 0 || IS_CCK_RATE(AckRate) )
		{
			if(DataRate >= 48)
			{ // 24M
				AckRate = 48;
			}
			else if(DataRate >= 24)
			{ // 12M
				AckRate = 24;
			}
			else
			{ // 6M
				AckRate = 12;
			}
		}
		break;

	default:
		RT_TRACE(COMP_DBG, DBG_SERIOUS, ("ComputeAckRate(): unsupported rate %#02X !!!\n", DataRate));
		if(AckRate == 0)
			AckRate = MGN_1M;
		break;
	}

	RT_ASSERT(AckRate != 0, ("ComputeAckRate(): AckRate should not be 0 !!!\n"));

	return AckRate;
}

//
//	Description:
//		Check if current offset of the MPDU is a valid IE.
//
BOOLEAN
HasNextIE(
	IN	POCTET_STRING	posMpdu,
	IN	u4Byte			Offset
	)
{
	if(Offset + 2 > posMpdu->Length) // 2 = 1(ID) + 1(Length).
		return FALSE;

	if(Offset + 2 + *(posMpdu->Octet + Offset + 1) > posMpdu->Length) 
		return FALSE;

	return TRUE;
}

//
//	Description:
//		Wrap the IE in an RT_DOT11_IE object and advance offset 
//		to next IE.
//
//	Assumption: 
//		Currnet offset contains a valid IE, that is, HasNextIE() 
//		returns TRUE before calling this function.
//
RT_DOT11_IE
AdvanceToNextIE(
	IN		POCTET_STRING	posMpdu,
	IN OUT	pu4Byte			pOffset
	)
{
	RT_DOT11_IE Ie;

	Ie.Id = *(posMpdu->Octet + *pOffset);
	Ie.Content.Length = *(posMpdu->Octet + *pOffset + 1);
	Ie.Content.Octet = posMpdu->Octet + *pOffset + 2;

	*pOffset += (2 + *(posMpdu->Octet + *pOffset + 1));
	return Ie;
}

// 
// Description:
//	Get the number of IE elements and extract the interested element for return.
// Arguments:
//	[in] IEs -
//		The IE elements to be retrived.
// 	[in] ID -
//		The referenced element ID in the IEs to be extracted.
// 	[in] OUIType -
//		Vendor specified OUI to be determined in the element.
//	[in] OUISubType -
//		The oui subtype of the element
// Return:
//	The number of the IEs.
// Revised by Bruce, 2012-03-26.
//
u1Byte
IEGetElementNum(
	IN	OCTET_STRING	IEs,
	IN	ELEMENT_ID		ID,
	IN	OUI_TYPE		OUIType,
	IN	u1Byte			OUISubType
	)
{
	u1Byte 			IENum = 0;
	OCTET_STRING	osTmp, osSingleIE;
	u2Byte			offset = 0;
	
	do
	{
		if(offset >= IEs.Length)
			break;

		FillOctetString(osTmp, IEs.Octet + offset, (IEs.Length - offset));
		
		osSingleIE = IEGetElement(osTmp, ID, OUIType, OUISubType);
		if(osSingleIE.Length > 0)
		{
			IENum ++;

			offset += (SIZE_EID_AND_LEN + osSingleIE.Length);
		}
		else
		{
			break;
		}
	}
	while(TRUE);
		
	return IENum;
}


// 
// Description:
//	Parse the IE elements and extract the interested element for return.
// Arguments:
//	IEs -
//		The IE elements to be retrived.
// 	ID -
//		The referenced element ID in the IEs to be extracted.
// 	OUISubType -
//		Vendor specified OUI to be determined in the element.
// Revised by Bruce, 2009-02-12.
//
OCTET_STRING 
IEGetElement(
	IN	OCTET_STRING	IEs,
	IN	ELEMENT_ID		ID,
	IN	OUI_TYPE		OUIType,
	IN	u1Byte			OUISubType
	)
{
	u2Byte			offset = 0;
	u2Byte			length = IEs.Length;
	OCTET_STRING	ret={0,0};	// used for return
	u1Byte			temp;
	BOOLEAN 		bIEMatched = FALSE;
	OCTET_STRING	osOuiSub;
	u1Byte			MaxElementLen;

	static u1Byte	WPATag[] = {0x00, 0x50, 0xf2, 0x01};
	static u1Byte	WMMTag[] = {0x00, 0x50, 0xf2, 0x02};				// Added by Annie, 2005-11-08.
	static u1Byte	Simpleconf[]={0x00, 0x50, 0xF2, 0x04};				//added by David, 2006-10-02
	static u1Byte	CcxRmCapTag[] = {0x00, 0x40, 0x96, 0x01};			// For CCX 2 S36, Radio Management Capability element, 2006.05.15, by rcnjko.
	static u1Byte	CcxVerNumTag[] = {0x00, 0x40, 0x96, 0x03};			// For CCX 2 S38, WLAN Device Version Number element. Annie, 2006-08-20.
	static u1Byte	WPA2GTKTag[] = {0x00, 0x0f, 0xac, 0x01};			// For MAC GTK data IE by CCW
	static u1Byte	CcxTsmTag[] = {0x00, 0x40, 0x96, 0x07};				// For CCX4 S56, Traffic Stream Metrics, 070615, by rcnjko.
	static u1Byte	CcxSSIDLTag[] = {0x00, 0x50, 0xf2, 0x05};
	static u1Byte	RealtekTurboModeTag[] = {0x00, 0xE0, 0x4C, 0x01};	// Added by Annie, 2005-12-27
	static u1Byte	RealtekAggModeTag[] = {0x00, 0xe0, 0x4c, 0x02};
	static u1Byte	RealtekBTIOTModeTag[] = {0x00, 0xe0, 0x4c, 0x03};	// Add for BT IOT 
	static u1Byte	RealtekBtHsTag[] = {0x00, 0xe0, 0x4c, 0x04};		// Add for BT HS 	
	static u1Byte	Epigram[] = {0x00,0x90,0x4c};
	static u1Byte	EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x033};			// For 11n EWC definition, 2007.07.17, by Emily
	static u1Byte	EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x034};			// For 11n EWC definition, 2007.07.17, by Emily	
	static u1Byte	Epigram11ACCap[] = {0x00, 0x90, 0x4c, 0x04, 0x08, 0xBF, 0x0C};	// For 11ac Epigram definition
	static u1Byte	BroadcomCap_1[] = {0x00, 0x10, 0x18};
	static u1Byte	BroadcomCap_2[] = {0x00, 0x0a, 0xf7};
	static u1Byte	BroadcomCap_3[] = {0x00, 0x05, 0xb5};
	static u1Byte	BroadcomLinksysE4200Cap_1[] = {0x00, 0x10, 0x18,0x02,0x00,0xf0,0x3c};  // for Linksys E4200
	static u1Byte	BroadcomLinksysE4200Cap_2[] = {0x00, 0x10, 0x18,0x02,0x01,0xf0,0x3c};
	static u1Byte	BroadcomLinksysE4200Cap_3[] = {0x00, 0x10, 0x18,0x02,0x00,0xf0,0x2c};
	static u1Byte	CiscoCap[] = {0x00, 0x40, 0x96};			// For Cisco AP IOT issue, by Emily
	static u1Byte	MeruCap[] = {0x00, 0x0c, 0xe6};
	static u1Byte	RalinkCap[] ={0x00, 0x0c, 0x43};
	static u1Byte	AtherosCap_1[] = {0x00,0x03,0x7F};
	static u1Byte	AtherosCap_2[] = {0x00,0x13,0x74};
	static u1Byte	MarvellCap[] = {0x00, 0x50, 0x43};
	static u1Byte	AirgoCap[] = {0x00, 0x0a, 0xf5};
	static u1Byte	CcxSFA[] = {0x00, 0x40, 0x96, 0x14};
	static u1Byte	CcxDiagReqReason[] = {0x00, 0x40, 0x96, 0x12};
	static u1Byte	CcxMHDR[] = {0x00, 0x40, 0x96, 0x10};
	static u1Byte	P2P_OUI_WITH_TYPE[] = {0x50, 0x6F, 0x9A, WLAN_PA_VENDOR_SPECIFIC};
	static u1Byte	WFD_OUI_WITH_TYPE[] = {0x50, 0x6F, 0x9A, WFD_OUI_TYPE};
	static u1Byte	NAN_OUI_WITH_TYPE[] = {0x50, 0x6F, 0x9A, 0x13}; 
	static u1Byte	RealtekTDLSTag[] = {0x00, 0xe0, 0x4c, 0x03};

	//Mix mode can't get DHCP in MacOS Driver. CCW revice offset 2008-04-15
	//offset = 12;

	do
	{
		if( (offset + 2) >= length )
		{
			return ret;
		}
		
		temp = IEs.Octet[offset];	// Get current Element ID.

		if( temp == ID )
		{
			if( ID == EID_Vendor )
			{ // EID_Vendor(=0xDD=221): Vendor Specific, currently we have to consider WPA and WMM Information Element.
				switch(OUIType)
				{
					case OUI_SUB_WPA:
						FillOctetString(osOuiSub, WPATag,  sizeof(WPATag));
						break;
					case OUI_SUB_WPA2GTK:
						FillOctetString(osOuiSub, WPA2GTKTag,  sizeof(WPA2GTKTag));
						break;
						
					case OUI_SUB_CCX_TSM:
						FillOctetString(osOuiSub, CcxTsmTag,  sizeof(CcxTsmTag));
						break;

					case OUI_SUB_SSIDL:
						FillOctetString(osOuiSub, CcxSSIDLTag,	sizeof(CcxSSIDLTag));
						break;

					case OUI_SUB_WMM:
						FillOctetString(osOuiSub, WMMTag,  sizeof(WMMTag));
							break;

					case OUI_SUB_REALTEK_TURBO:
						FillOctetString(osOuiSub, RealtekTurboModeTag,	sizeof(RealtekTurboModeTag));
						break;

					case OUI_SUB_REALTEK_AGG:
						FillOctetString(osOuiSub, RealtekAggModeTag, sizeof(RealtekAggModeTag));
						break;

					case OUI_SUB_SimpleConfig:
						FillOctetString(osOuiSub, Simpleconf,  sizeof(Simpleconf));
						break;

					case OUI_SUB_CCX_RM_CAP:
						FillOctetString(osOuiSub, CcxRmCapTag,	sizeof(CcxRmCapTag));
						break;

					case OUI_SUB_CCX_VER_NUM:
						FillOctetString(osOuiSub, CcxVerNumTag,  sizeof(CcxVerNumTag));
						break;
						
					case OUI_SUB_EPIG_IE:
						FillOctetString(osOuiSub, Epigram,  sizeof(Epigram));
						break;

					case OUI_SUB_11N_EWC_HT_CAP:
						FillOctetString(osOuiSub, EWC11NHTCap,	sizeof(EWC11NHTCap));
						break;

					case OUI_SUB_11N_EWC_HT_INFO:
						FillOctetString(osOuiSub, EWC11NHTInfo,  sizeof(EWC11NHTInfo));
						break;

					case OUI_SUB_11AC_EPIG_VHT_CAP:
						FillOctetString(osOuiSub, Epigram11ACCap,  sizeof(Epigram11ACCap));
						break;

					case OUI_SUB_BROADCOM_IE_1:
						FillOctetString(osOuiSub, BroadcomCap_1,  sizeof(BroadcomCap_1));						
						break;
						
					case OUI_SUB_BROADCOM_IE_2:
						FillOctetString(osOuiSub, BroadcomCap_2,  sizeof(BroadcomCap_2));						
						break;
						
					case OUI_SUB_BROADCOM_IE_3:
						FillOctetString(osOuiSub, BroadcomCap_3,  sizeof(BroadcomCap_3));						
						break;
						
					case OUI_SUB_BROADCOM_LINKSYSE4200_IE_1:
						FillOctetString(osOuiSub, BroadcomLinksysE4200Cap_1,  sizeof(BroadcomLinksysE4200Cap_1));						
						break;
						
					case OUI_SUB_BROADCOM_LINKSYSE4200_IE_2:
						FillOctetString(osOuiSub, BroadcomLinksysE4200Cap_2,  sizeof(BroadcomLinksysE4200Cap_2));						
						break;
						
					case OUI_SUB_BROADCOM_LINKSYSE4200_IE_3:
						FillOctetString(osOuiSub, BroadcomLinksysE4200Cap_3,  sizeof(BroadcomLinksysE4200Cap_3));						
						break;			

					case OUI_SUB_CISCO_IE:
						FillOctetString(osOuiSub, CiscoCap, sizeof(CiscoCap));
						break;

					case OUI_SUB_MERU_IE:
						FillOctetString(osOuiSub, MeruCap, sizeof(MeruCap));
						break;

					case OUI_SUB_RALINK_IE:
						FillOctetString(osOuiSub, RalinkCap, sizeof(RalinkCap));
						break;
						
					case OUI_SUB_ATHEROS_IE_1:
						FillOctetString(osOuiSub, AtherosCap_1, sizeof(AtherosCap_1));
						break;
						
					case OUI_SUB_ATHEROS_IE_2:
						FillOctetString(osOuiSub, AtherosCap_2, sizeof(AtherosCap_2));
						break;
						
					case OUI_SUB_MARVELL:
						FillOctetString(osOuiSub, MarvellCap, sizeof(MarvellCap));
						break;
						
					case OUI_SUB_AIRGO:
						FillOctetString(osOuiSub, AirgoCap, sizeof(AirgoCap));
						break;	
						
					case OUI_SUB_CCX_SFA:
						FillOctetString(osOuiSub, CcxSFA, sizeof(CcxSFA));
						break;
						
					case OUI_SUB_CCX_DIAG_REQ_REASON:
						FillOctetString(osOuiSub, CcxDiagReqReason, sizeof(CcxDiagReqReason));
						break;

					case OUI_SUB_CCX_MFP_MHDR:
						FillOctetString(osOuiSub, CcxMHDR, sizeof(CcxMHDR));
						break;
						
					case OUI_SUB_WIFI_DIRECT:
						FillOctetString(osOuiSub, P2P_OUI_WITH_TYPE, sizeof(P2P_OUI_WITH_TYPE));
						break;

					case OUI_SUB_WIFI_DISPLAY:
						FillOctetString(osOuiSub, WFD_OUI_WITH_TYPE, sizeof(WFD_OUI_WITH_TYPE));
						break;
						
					case OUI_SUB_NAN:
						FillOctetString(osOuiSub, NAN_OUI_WITH_TYPE, sizeof(NAN_OUI_WITH_TYPE));
						break;
							
					case OUI_SUB_REALTEK_TDLS:
						FillOctetString(osOuiSub, RealtekTDLSTag, sizeof(RealtekTDLSTag));
						break;
						
					case OUI_SUB_REALTEK_BT_IOT :
						FillOctetString(osOuiSub, RealtekBTIOTModeTag, sizeof(RealtekBTIOTModeTag));
						break;

					case OUI_SUB_REALTEK_BT_HS:
						FillOctetString(osOuiSub, RealtekBtHsTag, sizeof(RealtekBtHsTag));
						break;
						
					default:
						FillOctetString(osOuiSub, NULL, 0);
						break;
				}
				if( osOuiSub.Length > 0 && (length >= (offset + 2 + osOuiSub.Length)) ) // Prevent malicious attack.
				{
					if( PlatformCompareMemory(
						(IEs.Octet + offset + 2), 
						osOuiSub.Octet, 
						osOuiSub.Length) == 0 )
					{ // OUI field and subtype field are matched
						bIEMatched = TRUE;

						//
						// 060801, Isaiah:
						// [UAPSD Logo] Marvel AP has similar element, [DD 07 00 50 F2 02 05 01 24].
						//
						if( (OUI_SUB_WMM == OUIType) && 
							(length >= (offset + 2 + osOuiSub.Length + 1)) )
						{ // WMM-IE Matched!
						 	u1Byte WmmSubtype = *(IEs.Octet+offset+2+sizeof(WMMTag));

							if(WmmSubtype != OUISubType)
								bIEMatched = FALSE;
						}
					}
				}
			}
			else	
			{ // Other ID: Matched!
				bIEMatched = TRUE;
			}
		}

		if(bIEMatched &&
			(length >= offset + 2 + IEs.Octet[offset+1]) ) // Prevent malicious attack.
		{ // IE matched! break to return.
			//
			// Get the length of current IE.
			// We also perform length checking here to pervent malicious attack.	
			//
			switch(ID)
			{
			case EID_SsId:
				MaxElementLen = MAX_SSID_LEN;
				break;
			case EID_SupRates:
				MaxElementLen = 12; //Because Belkin 11AC  on g Mode only has 12 Octets in this IE
				break;
			case EID_FHParms:
				MaxElementLen = MAX_FH_PARM_LEN;
				break;
			case EID_DSParms:
				MaxElementLen = MAX_DS_PARM_LEN;
				break;
			case EID_CFParms:
				MaxElementLen = MAX_CF_PARM_LEN;
				break;
			case EID_Tim:
				MaxElementLen = MAX_TIM_PARM_LEN;
				break;
			case EID_IbssParms:
				MaxElementLen = MAX_IBSS_PARM_LEN;
				break;
			case EID_QBSSLoad:
				MaxElementLen = MAX_QBSS_LOAD_LEN;
				break;
			case EID_EDCAParms:
				MaxElementLen = MAX_EDCA_PARM_LEN;
				break;
			case EID_TSpec:
				MaxElementLen = MAX_TSPEC_LEN;
				break;
			case EID_Schedule:
				MaxElementLen = MAX_SCHEDULE_LEN;
				break;
			case EID_Ctext:
				MaxElementLen = MAX_CTEXT_LEN;
				break;
			case EID_ERPInfo:
				MaxElementLen = MAX_ERP_INFO_LEN;
				break;
			case EID_TSDelay:
				MaxElementLen = MAX_TS_DELAY_LEN;
				break;
			case EID_TCLASProc:
				MaxElementLen = MAX_TC_PROC_LEN;
				break;
			case EID_HTCapability:
				MaxElementLen = MAX_HT_CAP_LEN;
				break;
			case EID_HTInfo:
				MaxElementLen = MAX_HT_INFO_LEN;
				break;
			case EID_QoSCap:
				MaxElementLen = MAX_QOS_CAP;
				break;
			case EID_ExtSupRates:
				MaxElementLen = MAX_EXT_SUP_RATE_LEN;
				break;

			case EID_WAPI:
				MaxElementLen = MAX_WAPI_IE_LEN;
				break;
			case EID_LinkIdentifier:
				MaxElementLen = MAX_LINKID_LEN;
				break;
			case EID_SupportedChannels:
				MaxElementLen = MAX_SUPCHNL_LEN;
				break;
			case EID_SupRegulatory:
				MaxElementLen = MAX_SUPREGULATORY_LEN;
				break;
			case EID_SecondaryChnlOffset:
				MaxElementLen = MAX_SECONDARYOFFSET_LEN;
				break;
			case EID_ChnlSwitchTimeing:
				MaxElementLen = MAX_CHNLSWITCHTIMING_LEN;
				break;
			case EID_VHTCapability:
				MaxElementLen = MAX_VHT_CAP_LEN;
				break;
			default:
				MaxElementLen = MAX_IE_LEN;
				break;
			}
			ret.Length = (IEs.Octet[offset+1] <= MaxElementLen) ? IEs.Octet[offset+1] : MaxElementLen;

			//
			// Get pointer to the first byte (ElementID and length are not included).
			//
			ret.Octet = IEs.Octet + offset + 2;

			break;
		}
		else
		{ // Different.
			temp = IEs.Octet[offset+1]; 		// Get the length of current IE.
			offset += (temp+2); 				// Jump to the position of length of next IE. (2 byte is for the ID and length field.)
		}
	}while(1);

	return ret;
}


//
//	Description:
//		Verify if specific IE length is valid.
//
BOOLEAN
IsIELengthValid(
	IN	u1Byte		IDIE,
	IN	u1Byte		IELength
	)
{
	BOOLEAN			bRet = TRUE;	
	u1Byte			MaxIELength = MAX_IE_LEN;

	switch(IDIE)
	{
		case EID_SsId:
			MaxIELength = MAX_SSID_LEN;
			break;

		case EID_SupRates:
			MaxIELength = 12;//Because Belkin 11AC  on g Mode only has 12 Octets in this IE
			break;
			
		case EID_FHParms:
			MaxIELength = MAX_FH_PARM_LEN;
			break;
			
		case EID_DSParms:
			MaxIELength = MAX_DS_PARM_LEN;
			break;
			
		case EID_CFParms:
			MaxIELength = MAX_CF_PARM_LEN;
			break;
			
		case EID_Tim:
			MaxIELength = MAX_TIM_PARM_LEN;
			break;
			
		case EID_IbssParms:
			MaxIELength = MAX_IBSS_PARM_LEN;
			break;
			
		case EID_QBSSLoad:
			MaxIELength = MAX_QBSS_LOAD_LEN;
			break;
			
		case EID_EDCAParms:
			MaxIELength = MAX_EDCA_PARM_LEN;
			break;
			
		case EID_TSpec:
			MaxIELength = MAX_TSPEC_LEN;
			break;
			
		case EID_Schedule:
			MaxIELength = MAX_SCHEDULE_LEN;
			break;
			
		case EID_Ctext:
			MaxIELength = MAX_CTEXT_LEN;
			break;
			
		case EID_ERPInfo:
			MaxIELength = MAX_ERP_INFO_LEN;
			break;
			
		case EID_TSDelay:
			MaxIELength = MAX_TS_DELAY_LEN;
			break;
			
		case EID_TCLASProc:
			MaxIELength = MAX_TC_PROC_LEN;
			break;
			
		case EID_QoSCap:
			MaxIELength = MAX_QOS_CAP;
			break;
			
		case EID_ExtSupRates:
			MaxIELength = MAX_EXT_SUP_RATE_LEN;
			break;

		case EID_WAPI:
			MaxIELength = MAX_WAPI_IE_LEN;
			break;
			
		case EID_LinkIdentifier:
			MaxIELength = MAX_LINKID_LEN;
			break;
			
		case EID_SupportedChannels:
			MaxIELength = MAX_SUPCHNL_LEN;
			break;
			
		case EID_SupRegulatory:
			MaxIELength = MAX_SUPREGULATORY_LEN;
			break;
			
		case EID_SecondaryChnlOffset:
			MaxIELength = MAX_SECONDARYOFFSET_LEN;
			break;
			
		case EID_ChnlSwitchTimeing:
			MaxIELength = MAX_CHNLSWITCHTIMING_LEN;
			break;

		default:
			MaxIELength = MAX_IE_LEN;
	}

	if(IELength > MaxIELength)
		bRet = FALSE;

	return bRet;
}