summaryrefslogtreecommitdiff
path: root/proto_80211_mac_hdr.c
blob: 14e136d7969f4b4c57ba4b4b5c6f2aef6a41c197 (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
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
/*
 * netsniff-ng - the packet sniffing beast
 * Copyright 2012, 2013 Markus Amend <markus@netsniff-ng.org>
 * Copyright 2012 Daniel Borkmann <daniel@netsniff-ng.org>
 * Subject to the GPL, version 2.
 */

/* TODO
 * check all possible frame combinations for their behavior
 * with respect to endianness (little / big)
 */

#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <netinet/in.h>    /* for ntohs() */
#include <asm/byteorder.h>
#include <arpa/inet.h>     /* for inet_ntop() */

#include "proto.h"
#include "dissector_80211.h"
#include "built_in.h"
#include "pkt_buff.h"
#include "linktype.h"
#include "lookup.h"

#define	TU		0.001024

/* Note: Fields are encoded in little-endian! */
struct ieee80211_frm_ctrl {
	union {
		u16 frame_control;
		struct {
#if defined(__LITTLE_ENDIAN_BITFIELD)
		/* Correct order here ... */
		__extension__ u16 proto_version:2,
				  type:2,
				  subtype:4,
				  to_ds:1,
				  from_ds:1,
				  more_frags:1,
				  retry:1,
				  power_mgmt:1,
				  more_data:1,
				  wep:1,
				  order:1;
#elif defined(__BIG_ENDIAN_BITFIELD)
		__extension__ u16 subtype:4,
				  type:2,
				  proto_version:2,
				  order:1,
				  wep:1,
				  more_data:1,
				  power_mgmt:1,
				  retry:1,
				  more_frags:1,
				  from_ds:1,
				  to_ds:1;
#else
# error  "Adjust your <asm/byteorder.h> defines"
#endif
		};
	};
} __packed;

/* Management Frame start */
/* Note: Fields are encoded in little-endian! */
struct ieee80211_mgmt {
	u16 duration;
	u8 da[6];
	u8 sa[6];
	u8 bssid[6];
	u16 seq_ctrl;
} __packed;

struct ieee80211_mgmt_auth {
	u16 auth_alg;
	u16 auth_transaction;
	u16 status_code;
	/* possibly followed by Challenge text */
	u8 variable[0];
} __packed;

struct ieee80211_mgmt_deauth {
	u16 reason_code;
} __packed;

struct ieee80211_mgmt_assoc_req {
	u16 capab_info;
	u16 listen_interval;
	/* followed by SSID and Supported rates */
	u8 variable[0];
} __packed;

struct ieee80211_mgmt_assoc_resp {
	u16 capab_info;
	u16 status_code;
	u16 aid;
	/* followed by Supported rates */
	u8 variable[0];
} __packed;

struct ieee80211_mgmt_reassoc_resp {
	u16 capab_info;
	u16 status_code;
	u16 aid;
	/* followed by Supported rates */
	u8 variable[0];
} __packed;

struct ieee80211_mgmt_reassoc_req {
	u16 capab_info;
	u16 listen_interval;
	u8 current_ap[6];
	/* followed by SSID and Supported rates */
	u8 variable[0];
} __packed;

struct ieee80211_mgmt_disassoc {
	u16 reason_code;
} __packed;

struct ieee80211_mgmt_probe_req {
} __packed;

struct ieee80211_mgmt_beacon {
	u64 timestamp;
	u16 beacon_int;
	u16 capab_info;
	/* followed by some of SSID, Supported rates,
	  * FH Params, DS Params, CF Params, IBSS Params, TIM */
	u8 variable[0];
} __packed;

struct ieee80211_mgmt_probe_resp {
	u8 timestamp[8];
	u16 beacon_int;
	u16 capab_info;
	/* followed by some of SSID, Supported rates,
	  * FH Params, DS Params, CF Params, IBSS Params, TIM */
	u8 variable[0];
} __packed;
/* Management Frame end */

/* Control Frame start */
/* Note: Fields are encoded in little-endian! */
struct ieee80211_ctrl {
} __packed;

struct ieee80211_ctrl_rts {
	u16 duration;
	u8 da[6];
	u8 sa[6];	
} __packed;

struct ieee80211_ctrl_cts {
	u16 duration;
	u8 da[6];
} __packed;

struct ieee80211_ctrl_ack {
	u16 duration;
	u8 da[6];
} __packed;

struct ieee80211_ctrl_ps_poll {
	u16 aid;
	u8 bssid[6];
	u8 sa[6];
} __packed;

struct ieee80211_ctrl_cf_end {
	u16 duration;
	u8 bssid[6];
	u8 sa[6];
} __packed;

struct ieee80211_ctrl_cf_end_ack {
	u16 duration;
	u8 bssid[6];
	u8 sa[6];
} __packed;
/* Control Frame end */

/* Data Frame start */
/* Note: Fields are encoded in little-endian! */
struct ieee80211_data {
} __packed;

/* TODO: Extend */
/* Data Frame end */

struct element_reserved {
	u8 len;
} __packed;

struct element_ssid {
	u8 len;
	u8 SSID[0];
} __packed;

struct element_supp_rates {
	u8 len;
	u8 rates[0];
} __packed;

struct element_fh_ps {
	u8 len;
	u16 dwell_time;
	u8 hop_set;
	u8 hop_pattern;
	u8 hop_index;
} __packed;

struct element_dsss_ps {
	u8 len;
	u8 curr_ch;
} __packed;

struct element_cf_ps {
	u8 len;
	u8 cfp_cnt;
	u8 cfp_period;
	u16 cfp_max_dur;
	u16 cfp_dur_rem;
} __packed;

struct element_tim {
	u8 len;
	u8 dtim_cnt;
	u8 dtim_period;
	u8 bmp_cntrl;
	u8 part_virt_bmp[0];
} __packed;

struct element_ibss_ps {
	u8 len;
	u16 atim_win;
} __packed;

struct element_country_tripled {
	u8 frst_ch;
	u8 nr_ch;
	u8 max_trans;
} __packed;

struct element_country {
	u8 len;
#if defined(__LITTLE_ENDIAN_BITFIELD)
		/* Correct order here ... */
	u8 country_first;
	u8 country_sec;
	u8 country_third;
#elif defined(__BIG_ENDIAN_BITFIELD)
	u8 country_third;
	u8 country_sec;
	u8 country_first;
#else
# error  "Adjust your <asm/byteorder.h> defines"
#endif
	/* triplet may repeat */
	struct element_country_tripled tripled [0];
	/* end triplet */
	u8 pad[0];
} __packed;

struct element_hop_pp {
	u8 len;
	u8 prime_radix;
	u8 nr_ch;
} __packed;

struct element_hop_pt {
	u8 len;
	u8 flag;
	u8 nr_sets;
	u8 modules;
	u8 offs;
	u8 rand_tabl[0];
} __packed;

struct element_req {
	u8 len;
	u8 req_elem_idl[0];
} __packed;

struct element_bss_load {
	u8 len;
	u16 station_cnt;
	u8 ch_util;
	u16 avlb_adm_cap;
} __packed;

struct element_edca_ps {
	u8 len;
	u8 qos_inf;
	u8 res;
	u32 ac_be;
	u32 ac_bk;
	u32 ac_vi;
	u32 ac_vo;
} __packed;

struct element_tspec {
	union {
		u32 len_ts_info;
		struct {
#if defined(__LITTLE_ENDIAN_BITFIELD)
		/* Correct order here ... */
		__extension__ u32 len:8,
				  traffic_type:1,
				  tsid:4,
				  direction:2,
				  access_policy:2,
				  aggr:1,
				  apsd:1,
				  user_prior:3,
				  tsinfo_ack_pol:2,
				  schedule:1,
				  res:7;
#elif defined(__BIG_ENDIAN_BITFIELD)
		__extension__ u32 len:8,
				  res:7,
				  schedule:1,
				  tsinfo_ack_pol:2,
				  user_prior:3,
				  apsd:1,
				  aggr:1,
				  access_policy:2,
				  direction:2,
				  tsid:4,
				  traffic_type:1;
#else
# error  "Adjust your <asm/byteorder.h> defines"
#endif
		};
	};
	u16 nom_msdu_size;
	u16 max_msdu_size;
	u32 min_srv_intv;
	u32 max_srv_intv;
	u32 inactive_intv;
	u32 susp_intv;
	u32 srv_start_time;
	u32 min_data_rate;
	u32 mean_data_rate;
	u32 peak_data_rate;
	u32 burst_size;
	u32 delay_bound;
	u32 min_phy_rate;
	u16 surplus_bandw_allow;
	u16 med_time;
} __packed;

struct element_tclas {
	u8 len;
	u8 user_priority;
	u8 frm_class[0];
} __packed;

struct element_tclas_frm_class {
	u8 type;
	u8 mask;
	u8 param[0];
} __packed;

struct element_tclas_type0 {
	u8 sa[6];
	u8 da[6];
	u16 type;
} __packed;

struct element_tclas_type1 {
	u8 version;
	u8 subparam[0];
} __packed;

struct element_tclas_type1_ip4 {
	u32 sa;
	u32 da;
	u16 sp;
	u16 dp;
	u8 dscp;
	u8 proto;
	u8 reserved;
} __packed;

struct element_tclas_type1_ip6 {
	struct in6_addr sa;
	struct in6_addr da;
	u16 sp;
	u16 dp;
	union {
		u8 flow_label[3];
		struct {
#if defined(__LITTLE_ENDIAN_BITFIELD)
		__extension__ u8  flow_label3:8;
		__extension__ u8  flow_label2:8;
		__extension__ u8  flow_label1:8;
#elif defined(__BIG_ENDIAN_BITFIELD)
		__extension__ u8  flow_label1:8;
		__extension__ u8  flow_label2:8;
		__extension__ u8  flow_label3:8;
#else
# error  "Adjust your <asm/byteorder.h> defines"
#endif
		};
	};
} __packed;

struct element_tclas_type2 {
	u16 vlan_tci;
} __packed;

struct element_tclas_type3 {
	u16 offs;
	u8 value[0];
	u8 mask[0];
} __packed;

struct element_tclas_type4 {
	u8 version;
	u8 subparam[0];
} __packed;

struct element_tclas_type4_ip4 {
	u32 sa;
	u32 da;
	u16 sp;
	u16 dp;
	u8 dscp;
	u8 proto;
	u8 reserved;
} __packed;

struct element_tclas_type4_ip6 {
	struct in6_addr sa;
	struct in6_addr da;
	u16 sp;
	u16 dp;
	u8 dscp;
	u8 nxt_hdr;
	union {
		u8 flow_label[3];
		struct {
#if defined(__LITTLE_ENDIAN_BITFIELD)
		__extension__ u8  flow_label3:8;
		__extension__ u8  flow_label2:8;
		__extension__ u8  flow_label1:8;
#elif defined(__BIG_ENDIAN_BITFIELD)
		__extension__ u8  flow_label1:8;
		__extension__ u8  flow_label2:8;
		__extension__ u8  flow_label3:8;
#else
# error  "Adjust your <asm/byteorder.h> defines"
#endif
		};
	};
} __packed;

struct element_tclas_type5 {
	u8 pcp;
	u8 cfi;
	u8 vid;
} __packed;

struct element_schedule {
	u8 len;
	u16 inf;
	u32 start;
	u32 serv_intv;
	u16 spec_intv;
} __packed;

struct element_chall_txt {
	u8 len;
	u8 chall_txt[0];
} __packed;

struct element_pwr_constr {
	u8 len;
	u8 local_pwr_constr;
} __packed;

struct element_pwr_cap {
	u8 len;
	u8 min_pwr_cap;
	u8 max_pwr_cap;
} __packed;

struct element_tpc_req {
	u8 len;
} __packed;

struct element_tpc_rep {
	u8 len;
	u8 trans_pwr;
	u8 link_marg;
} __packed;

struct element_supp_ch {
	u8 len;
	u8 first_ch_nr[0];
	u8 nr_ch[0];
} __packed;

struct element_supp_ch_tuple {
	u8 first_ch_nr;
	u8 nr_ch;
} __packed;

struct element_ch_sw_ann {
	u8 len;
	u8 switch_mode;
	u8 new_nr;
	u8 switch_cnt;
} __packed;

struct element_meas_basic {
	u8 ch_nr;
	u64 start;
	u16 dur;
} __packed;

struct element_meas_cca {
	u8 ch_nr;
	u64 start;
	u16 dur;
} __packed;

struct element_meas_rpi {
	u8 ch_nr;
	u64 start;
	u16 dur;
} __packed;

struct element_meas_ch_load {
	u8 op_class;
	u8 ch_nr;
	u16 rand_intv;
	u16 dur;
	u8 sub[0];
} __packed;

struct element_meas_noise {
	u8 op_class;
	u8 ch_nr;
	u16 rand_intv;
	u16 dur;
	u8 sub[0];
} __packed;

struct element_meas_beacon {
	u8 op_class;
	u8 ch_nr;
	u16 rand_intv;
	u16 dur;
	u8 mode;
	u8 bssid[6];
	u8 sub[0];
} __packed;

struct element_meas_frame {
	u8 op_class;
	u8 ch_nr;
	u16 rand_intv;
	u16 dur;
	u8 frame;
	u8 mac[6];
	u8 sub[0];
} __packed;

struct element_meas_sta {
	u8 peer_mac[6];
	u16 rand_intv;
	u16 dur;
	u8 group_id;
	u8 sub[0];
} __packed;

struct element_meas_lci {
	u8 loc_subj;
	u8 latitude_req_res;
	u8 longitude_req_res;
	u8 altitude_req_res;
	u8 sub[0];
} __packed;

struct element_meas_trans_str_cat {
	u16 rand_intv;
	u16 dur;
	u8 peer_sta_addr[6];
	u8 traffic_id;
	u8 bin_0_range;
	u8 sub[0];
} __packed;

struct element_meas_mcast_diag {
	u16 rand_intv;
	u16 dur;
	u8 group_mac[6];
	u8 mcast_triggered[0];
	u8 sub[0];
} __packed;

struct element_meas_loc_civic {
	u8 loc_subj;
	u8 civic_loc;
	u8 loc_srv_intv_unit;
	u16 loc_srv_intv;
	u8 sub[0];
} __packed;

struct element_meas_loc_id {
	u8 loc_subj;
	u8 loc_srv_intv_unit;
	u16 loc_srv_intv;
	u8 sub[0];
} __packed;

struct element_meas_pause {
	u8 time;
	u8 sub[0];
} __packed;

struct element_meas_req {
	u8 len;
	u8 token;
	u8 req_mode;
	u8 type;
	u8 req[0];
} __packed;

struct element_meas_rep {
	u8 len;
	u8 token;
	u8 rep_mode;
	u8 type;
	u8 rep[0];
} __packed;

struct element_quiet {
	u8 len;
	u8 cnt;
	u8 period;
	u16 dur;
	u16 offs;
} __packed;

struct element_ibss_dfs {
	u8 len;
	u8 owner[6];
	u8 rec_intv;
	u8 ch_map[0];
} __packed;

struct element_ibss_dfs_tuple {
	u8 ch_nr;
	u8 map;
} __packed;

struct element_erp {
	u8 len;
	u8 param;
} __packed;

struct element_ts_del {
	u8 len;
	u32 delay;
} __packed;

struct element_tclas_proc {
	u8 len;
	u8 proc;
} __packed;

struct element_ht_cap {
	u8 len;
	union {
		u16 info;
		struct {
#if defined(__LITTLE_ENDIAN_BITFIELD)
		/* Correct order here ... */
		__extension__ u16 ldpc:1,
				  supp_width:1,
				  sm_pwr:2,
				  ht_green:1,
				  gi_20mhz:1,
				  gi_40mhz:1,
				  tx_stbc:1,
				  rx_stbc:2,
				  ht_ack:1,
				  max_msdu_length:1,
				  dsss_ck_mode:1,
				  res:1,
				  forty_int:1,
				  prot_supp:1;
#elif defined(__BIG_ENDIAN_BITFIELD)
		__extension__ u16 rx_stbc:2,
				  ht_ack:1,
				  max_msdu_length:1,
				  dsss_ck_mode:1,
				  res:1,
				  forty_int:1,
				  prot_supp:1,
				  ldpc:1,
				  supp_width:1,
				  sm_pwr:2,
				  ht_green:1,
				  gi_20mhz:1,
				  gi_40mhz:1,
				  tx_stbc:1;
#else
# error  "Adjust your <asm/byteorder.h> defines"
#endif
		};
	};
	u8 param;
	union {
		u8 mcs_set[16];
		struct {
#if defined(__LITTLE_ENDIAN_BITFIELD)
		/* Correct order here ... */
		__extension__ u8  bitmask1:8;
		__extension__ u8  bitmask2:8;
		__extension__ u8  bitmask3:8;
		__extension__ u8  bitmask4:8;
		__extension__ u8  bitmask5:8;
		__extension__ u8  bitmask6:8;
		__extension__ u8  bitmask7:8;
		__extension__ u8  bitmask8:8;
		__extension__ u8  bitmask9:8;
		__extension__ u8  bitmask10_res:8;
		__extension__ u16 supp_rate_res:16;
		__extension__ u32 tx_param_res:32;
		
#elif defined(__BIG_ENDIAN_BITFIELD)
		__extension__ u32 tx_param_res:32;
		__extension__ u16 supp_rate_res:16;
		__extension__ u8  bitmask10_res:8;
		__extension__ u8  bitmask9:8;
		__extension__ u8  bitmask8:8;
		__extension__ u8  bitmask7:8;
		__extension__ u8  bitmask6:8;
		__extension__ u8  bitmask5:8;
		__extension__ u8  bitmask4:8;
		__extension__ u8  bitmask3:8;
		__extension__ u8  bitmask2:8;
		__extension__ u8  bitmask1:8;
#else
# error  "Adjust your <asm/byteorder.h> defines"
#endif
		};
	};
	u16 ext_cap;
	u32 beam_cap;
	u8 asel_cap;
} __packed;

struct element_qos_cap {
	u8 len;
	u8 info;
} __packed;

struct element_ext_supp_rates {
	u8 len;
	u8 rates[0];
} __packed;

struct element_vend_spec {
	u8 len;
	u8 oui[0];
	u8 specific[0];
} __packed;

struct ieee80211_radiotap_header {
	u8 version;	/* set to 0 */
	u8 pad;
	u16 len;	/* entire length */
	u32 present;	/* fields present */
} __packed;

static int8_t len_neq_error(u8 len, u8 intended)
{
	if(intended != len) {
		tprintf("Length should be %u Bytes", intended);
		return 1;
	}

	return 0;
}

static int8_t len_lt_error(u8 len, u8 intended)
{
	if(len < intended) {
		tprintf("Length should be greater %u Bytes", intended);
		return 1;
	}

	return 0;
}

static float data_rates(u8 id)
{
	/* XXX Why not (id / 2.f)? */
	switch (id) {
	case   2: return  1.0f;
	case   3: return  1.5f;
	case   4: return  2.0f;
	case   5: return  2.5f;
	case   6: return  3.0f;
	case   9: return  4.5f;
	case  11: return  5.5f;
	case  12: return  6.0f;
	case  18: return  9.0f;
	case  22: return 11.0f;
	case  24: return 12.0f;
	case  27: return 13.5f;
	case  36: return 18.0f;
	case  44: return 22.0f;
	case  48: return 24.0f;
	case  54: return 27.0f;
	case  66: return 33.0f;
	case  72: return 36.0f;
	case  96: return 48.0f;
	case 108: return 54.0f;
	}

	return 0.f;
}

struct subelement {
	u8 id;
	u8 len;
	u8 data[0];
} __packed;


static int8_t subelements(struct pkt_buff *pkt, u8 len)
{
	u8 i, j;
	u8 *data;
	
	for (i=0; i<len;) {
		struct subelement *sub;

		sub = (struct subelement *) pkt_pull(pkt, sizeof(*sub));
		if (sub == NULL)
			return 0;

		tprintf(", Subelement ID %u, ", sub->id);
		tprintf("Length %u, ", sub->len);

		data = pkt_pull(pkt, sub->len);
		if (data == NULL)
			return 0;

		tprintf("Data: 0x");
		for(j=0; j < sub->len; j++)
			tprintf("%.2x ", data[j]);

		i += sub->len + 1;
	}

	/* Not needed ?! Should break before*/
	/*
	 *if (i != len) {
	 *	tprintf("Length error");
	 *	return 0;
	 *}
	 */

      return 1;
}

static int8_t inf_reserved(struct pkt_buff *pkt, u8 *id)
{
	u8 i;
	u8 *data;
	struct element_reserved *reserved;

	reserved = (struct element_reserved *) pkt_pull(pkt, sizeof(*reserved));
	if (reserved == NULL)
		return 0;

	tprintf(" Reserved (%u, Len (%u)): ", *id, reserved->len);

	data = pkt_pull(pkt, reserved->len);
	if (data == NULL)
		return 0;

	tprintf("Data 0x");
	for (i = 0; i < reserved->len; i++)
		tprintf("%.2x", data[i]);

	return 1;
}

static int8_t inf_ssid(struct pkt_buff *pkt, u8 *id)
{
	u8 i;
	struct element_ssid *ssid;
	char *ssid_name;

	ssid = (struct element_ssid *) pkt_pull(pkt, sizeof(*ssid));
	if (ssid == NULL)
		return 0;

	tprintf(" SSID (%u, Len (%u)): ", *id, ssid->len);

	if ((ssid->len - sizeof(*ssid) + 1) > 0) {
		ssid_name = (char *) pkt_pull(pkt, ssid->len);
		if (ssid_name == NULL)
			return 0;

		for (i = 0; i < ssid->len; i++)
			tprintf("%c",ssid_name[i]);
	} else {
		tprintf("Wildcard SSID");
	}

	return 1;
}

static int8_t inf_supp_rates(struct pkt_buff *pkt, u8 *id)
{
	u8 i;
	u8 *rates;
	struct element_supp_rates *supp_rates;

	supp_rates = (struct element_supp_rates *)
			pkt_pull(pkt, sizeof(*supp_rates));
	if (supp_rates == NULL)
		return 0;

	tprintf(" Supp. Rates (%u, Len (%u)): ", *id, supp_rates->len);
	if (len_lt_error(supp_rates->len, 1))
		return 0;

	if ((supp_rates->len - sizeof(*supp_rates) + 1) > 0) {
		rates = pkt_pull(pkt, supp_rates->len);
		if (rates == NULL)
			return 0;

		for (i = 0; i < supp_rates->len; i++)
			tprintf("%g%s ", ((rates[i] & 0x80) >> 7) ?
					data_rates(rates[i] & 0x3f) :
					((rates[i] & 0x3f) * 0.5),
					((rates[i] & 0x80) >> 7) ? "(B)" : "");
		return 1;
	}

	return 0;
}

static int8_t inf_fh_ps(struct pkt_buff *pkt, u8 *id)
{
	struct element_fh_ps *fh_ps;

	fh_ps =	(struct element_fh_ps *) pkt_pull(pkt, sizeof(*fh_ps));
	if (fh_ps == NULL)
		return 0;

	tprintf(" FH Param Set (%u, Len(%u)): ", *id, fh_ps->len);
	if (len_neq_error(fh_ps->len, 5))
		return 0;
	tprintf("Dwell Time: %fs, ", le16_to_cpu(fh_ps->dwell_time) * TU);
	tprintf("HopSet: %u, ", fh_ps->hop_set);
	tprintf("HopPattern: %u, ", fh_ps->hop_pattern);
	tprintf("HopIndex: %u", fh_ps->hop_index);

	return 1;
}

static int8_t inf_dsss_ps(struct pkt_buff *pkt, u8 *id)
{
	struct element_dsss_ps *dsss_ps;

	dsss_ps = (struct element_dsss_ps *) pkt_pull(pkt, sizeof(*dsss_ps));
	if (dsss_ps == NULL)
		return 0;

	tprintf(" DSSS Param Set (%u, Len(%u)): ", *id, dsss_ps->len);
	if (len_neq_error(dsss_ps->len, 1))
		return 0;
	tprintf("Current Channel: %u", dsss_ps->curr_ch);

	return 1;
}

static int8_t inf_cf_ps(struct pkt_buff *pkt, u8 *id)
{
	struct element_cf_ps *cf_ps;

	cf_ps = (struct element_cf_ps *) pkt_pull(pkt, sizeof(*cf_ps));
	if (cf_ps == NULL)
		return 0;

	tprintf(" CF Param Set (%u, Len(%u)): ", *id, cf_ps->len);
	if (len_neq_error(cf_ps->len, 6))
		return 0;
	tprintf("CFP Count: %u, ", cf_ps->cfp_cnt);
	tprintf("CFP Period: %u, ", cf_ps->cfp_period);
	tprintf("CFP MaxDur: %fs, ", le16_to_cpu(cf_ps->cfp_max_dur) * TU);
	tprintf("CFP DurRem: %fs", le16_to_cpu(cf_ps->cfp_dur_rem) * TU);

	return 1;
}

static int8_t inf_tim(struct pkt_buff *pkt, u8 *id)
{
	struct element_tim *tim;
	u8 i;

	tim = (struct element_tim *) pkt_pull(pkt, sizeof(*tim));
	if (tim == NULL)
		return 0;

	tprintf(" TIM (%u, Len(%u)): ", *id, tim->len);
	if (len_lt_error(tim->len, 3))
		return 0;
	tprintf("DTIM Count: %u, ", tim->dtim_cnt);
	tprintf("DTIM Period: %u, ", tim->dtim_period);
	tprintf("Bitmap Control: %u, ", tim->bmp_cntrl);
	if ((tim->len - sizeof(*tim) + 1) > 0) {
		u8 *bmp = pkt_pull(pkt, (tim->len - sizeof(*tim) + 1));
		if (bmp == NULL)
			return 0;

		tprintf("Partial Virtual Bitmap: 0x");
		for (i = 0; i < (tim->len - sizeof(*tim) + 1); i++)
			tprintf("%.2x", bmp[i]);
	}

	return 1;
}

static int8_t inf_ibss_ps(struct pkt_buff *pkt, u8 *id)
{
	struct element_ibss_ps *ibss_ps;

	ibss_ps = (struct element_ibss_ps *) pkt_pull(pkt, sizeof(*ibss_ps));
	if (ibss_ps == NULL)
		return 0;

	tprintf(" IBSS Param Set (%u, Len(%u)): ", *id, ibss_ps->len);
	if (len_neq_error(ibss_ps->len, 2))
		return 0;
	tprintf("ATIM Window: %fs", le16_to_cpu(ibss_ps->atim_win) * TU);

	return 1;
}

static int8_t inf_country(struct pkt_buff *pkt, u8 *id)
{
	u8 i;
	u8 *pad;
	struct element_country *country;

	country = (struct element_country *) pkt_pull(pkt, sizeof(*country));
	if (country == NULL)
		return 0;

	tprintf(" Country (%u, Len(%u)): ", *id, country->len);
	if (len_lt_error(country->len, 6))
		return 0;
	tprintf("Country String: %c%c%c", country->country_first,
		country->country_sec, country->country_third);

	for (i = country->len % 3; i < (country->len - 3); i += 3) {
		struct element_country_tripled *country_tripled;

		country_tripled = (struct element_country_tripled *)
				    pkt_pull(pkt, sizeof(*country_tripled));
		if (country_tripled == NULL)
			return 0;

		tprintf("\n\t\t");
		if(country_tripled->frst_ch >= 201) {
			tprintf("Oper Ext ID: %u, ", country_tripled->frst_ch);
			tprintf("Operating Class: %u, ", country_tripled->nr_ch);
			tprintf("Coverage Class: %u", country_tripled->max_trans);
		} else {
			tprintf("First Ch Nr: %u, ", country_tripled->frst_ch);
			tprintf("Nr of Ch: %u, ", country_tripled->nr_ch);
			tprintf("Max Transmit Pwr Lvl: %u", country_tripled->max_trans);
		}
	}

	if(country->len % 3) {
		pad = pkt_pull(pkt, 1);
		if (pad == NULL)
			return 0;

		tprintf(", Pad: 0x%x", *pad);
	}

	return 1;
}

static int8_t inf_hop_pp(struct pkt_buff *pkt, u8 *id)
{
	struct element_hop_pp *hop_pp;

	hop_pp = (struct element_hop_pp *) pkt_pull(pkt, sizeof(*hop_pp));
	if (hop_pp == NULL)
		return 0;

	tprintf(" Hopping Pattern Param (%u, Len(%u)): ", *id, hop_pp->len);
	if (len_neq_error(hop_pp->len, 2))
		return 0;
	tprintf("Prime Radix: %u, ", hop_pp->prime_radix);
	tprintf("Nr of Ch: %u", hop_pp->nr_ch);

	return 1;
}

static int8_t inf_hop_pt(struct pkt_buff *pkt, u8 *id)
{
	size_t i;
	u8 *rand_tabl;
	struct element_hop_pt *hop_pt;

	hop_pt = (struct element_hop_pt *) pkt_pull(pkt, sizeof(*hop_pt));
	if (hop_pt == NULL)
		return 0;

	tprintf(" Hopping Pattern Table (%u, Len(%u)): ", *id, hop_pt->len);
	if (len_lt_error(hop_pt->len, 4))
		return 0;
	tprintf("Flag: %u, ", hop_pt->flag);
	tprintf("Nr of Sets: %u, ", hop_pt->nr_sets);
	tprintf("Modulus: %u, ", hop_pt->modules);
	tprintf("Offs: %u", hop_pt->offs);

	if ((hop_pt->len - sizeof(*hop_pt) + 1) > 0) {
		rand_tabl = pkt_pull(pkt, (hop_pt->len - sizeof(*hop_pt) + 1));
		if (rand_tabl == NULL)
			return 0;

		tprintf(", Rand table: 0x");
		for (i = 0; i < (hop_pt->len - sizeof(*hop_pt) + 1); i++)
			tprintf("%.2x", rand_tabl[i]);
	}

	return 1;
}

static int8_t inf_req(struct pkt_buff *pkt, u8 *id)
{
	size_t i;
	struct element_req *req;
	u8 *req_ids;

	req = (struct element_req *) pkt_pull(pkt, sizeof(*req));
	if (req == NULL)
		return 0;

	tprintf(" Request Element (%u, Len(%u)): ", *id, req->len);
	if ((req->len - sizeof(*req) + 1) > 0) {
		req_ids = pkt_pull(pkt, (req->len - sizeof(*req) + 1));
		if (req_ids == NULL)
			return 0;

		tprintf(", Requested Element IDs: ");
		for (i = 0; i < (req->len - sizeof(*req) + 1); i++)
			tprintf("%u ", req_ids[i]);
	}

	return 1;
}

static int8_t inf_bss_load(struct pkt_buff *pkt, u8 *id)
{
	struct element_bss_load *bss_load;

	bss_load = (struct element_bss_load *) pkt_pull(pkt, sizeof(*bss_load));
	if (bss_load == NULL)
		return 0;

	tprintf(" BSS Load element (%u, Len(%u)): ", *id, bss_load->len);
	if (len_neq_error(bss_load->len, 5))
		return 0;
	tprintf("Station Count: %u, ", le16_to_cpu(bss_load->station_cnt));
	tprintf("Channel Utilization: %u, ", bss_load->ch_util);
	tprintf("Available Admission Capacity: %uus",
		bss_load->avlb_adm_cap * 32);

	return 1;
}

static int8_t inf_edca_ps(struct pkt_buff *pkt, u8 *id)
{
	u32 ac_be, ac_bk, ac_vi, ac_vo;
	struct element_edca_ps *edca_ps;

	edca_ps = (struct element_edca_ps *) pkt_pull(pkt, sizeof(*edca_ps));
	if (edca_ps == NULL)
		return 0;

	ac_be = le32_to_cpu(edca_ps->ac_be);
	ac_bk = le32_to_cpu(edca_ps->ac_bk);
	ac_vi = le32_to_cpu(edca_ps->ac_vi);
	ac_vo = le32_to_cpu(edca_ps->ac_vo);

	tprintf(" EDCA Param Set (%u, Len(%u)): ", *id, edca_ps->len);
	if (len_neq_error(edca_ps->len, 18))
		return 0;
	tprintf("QoS Info: 0x%x (-> EDCA Param Set Update Count (%u),"
		"Q-Ack (%u), Queue Re (%u), TXOP Req(%u), Res(%u)), ",
		edca_ps->qos_inf, edca_ps->qos_inf >> 4,
		(edca_ps->qos_inf >> 3) & 1, (edca_ps->qos_inf >> 2) & 1,
		(edca_ps->qos_inf >> 1) & 1, edca_ps->qos_inf & 1);
	tprintf("Reserved: 0x%x, ", edca_ps->res);
	tprintf("AC_BE Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
		"Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_be,
		ac_be >> 28, (ac_be >> 27) & 1, (ac_be >> 25) & 3,
		(ac_be >> 24) & 1, (ac_be >> 20) & 15, (ac_be >> 16) & 15,
		bswap_16(ac_be & 0xFFFF) * 32);
	tprintf("AC_BK Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
		"Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_bk,
		ac_bk >> 28, (ac_bk >> 27) & 1, (ac_bk >> 25) & 3,
		(ac_bk >> 24) & 1, (ac_bk >> 20) & 15, (ac_bk >> 16) & 15,
		bswap_16(ac_bk & 0xFFFF) * 32);
	tprintf("AC_VI Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
		"Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_vi,
		ac_vi >> 28, (ac_vi >> 27) & 1, (ac_vi >> 25) & 3,
		(ac_vi >> 24) & 1, (ac_vi >> 20) & 15, (ac_vi >> 16) & 15,
		bswap_16(ac_vi & 0xFFFF) * 32);
	tprintf("AC_VO Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
		"Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)", ac_vo,
		ac_vo >> 28, (ac_vo >> 27) & 1, (ac_vo >> 25) & 3,
		(ac_vo >> 24) & 1, (ac_vo >> 20) & 15, (ac_vo >> 16) & 15,
		bswap_16(ac_vo & 0xFFFF) * 32);

	return 1;
}

static int8_t inf_tspec(struct pkt_buff *pkt, u8 *id)
{
	u16 nom_msdu_size, surplus_bandw_allow;
	struct element_tspec *tspec;

	tspec = (struct element_tspec *) pkt_pull(pkt, sizeof(*tspec));
	if (tspec == NULL)
		return 0;

	nom_msdu_size = le16_to_cpu(tspec->nom_msdu_size);
	surplus_bandw_allow = le16_to_cpu(tspec->surplus_bandw_allow);

	tprintf(" TSPEC (%u, Len(%u)): ", *id, tspec->len);
	if (len_neq_error(tspec->len, 55))
		return 0;
	tprintf("Traffic Type: %u, ", tspec->traffic_type);
	tprintf("TSID: %u, ", tspec->tsid);
	tprintf("Direction: %u, ", tspec->direction);
	tprintf("Access Policy: %u, ", tspec->access_policy);
	tprintf("Aggregation: %u, ", tspec->aggr);
	tprintf("APSD: %u, ", tspec->apsd);
	tprintf("User Priority: %u, ", tspec->user_prior);
	tprintf("TSinfo Ack Policy: %u, ", tspec->tsinfo_ack_pol);
	tprintf("Schedule: %u, ", tspec->schedule);
	tprintf("Reserved: 0x%x, ", tspec->res);
	tprintf("Nominal MSDU Size: %uB (Fixed (%u)), ",
		nom_msdu_size >> 1, nom_msdu_size & 1);
	tprintf("Maximum MSDU Size: %uB, ", le16_to_cpu(tspec->max_msdu_size));
	tprintf("Minimum Service Interval: %uus, ",
		le32_to_cpu(tspec->min_srv_intv));
	tprintf("Maximum Service Interval: %uus, ",
		le32_to_cpu(tspec->max_srv_intv));
	tprintf("Inactivity Interval: %uus, ",
		le32_to_cpu(tspec->inactive_intv));
	tprintf("Suspension Interval: %uus, ", le32_to_cpu(tspec->susp_intv));
	tprintf("Service Start Time: %uus, ",
		le32_to_cpu(tspec->srv_start_time));
	tprintf("Minimum Data Rate: %ub/s, ",le32_to_cpu(tspec->min_data_rate));
	tprintf("Mean Data Rate: %ub/s, ", le32_to_cpu(tspec->mean_data_rate));
	tprintf("Peak Data Rate: %ub/s, ",le32_to_cpu(tspec->peak_data_rate));
	tprintf("Burst Size: %uB, ", le32_to_cpu(tspec->burst_size));
	tprintf("Delay Bound: %uus, ", le32_to_cpu(tspec->delay_bound));
	tprintf("Minimum PHY Rate: %ub/s, ", le32_to_cpu(tspec->min_phy_rate));
	tprintf("Surplus Bandwidth: %u.%u, ", surplus_bandw_allow >> 13,
		surplus_bandw_allow & 0x1FFF);
	tprintf("Medium Time: %uus", le16_to_cpu(tspec->med_time) * 32);

	return 1;
}

static const char *class_type(u8 type)
{
	switch (type) {
	case   0: return "Ethernet parameters";
	case   1: return "TCP/UDP IP parameters";
	case   2: return "IEEE 802.1Q parameters";
	case   3: return "Filter Offset parameters";
	case   4: return "IP and higher layer parameters";
	case   5: return "IEEE 802.1D/Q parameters";
	default: return "Reserved";
	}
}

static int8_t inf_tclas(struct pkt_buff *pkt, u8 *id)
{
	struct element_tclas *tclas;
	struct element_tclas_frm_class *frm_class;

	tclas =	(struct element_tclas *) pkt_pull(pkt, sizeof(*tclas));
	if (tclas == NULL)
		return 0;

	frm_class = (struct element_tclas_frm_class *)
				pkt_pull(pkt, sizeof(*frm_class));
	if (frm_class == NULL)
		return 0;

	tprintf(" TCLAS (%u, Len(%u)): ", *id, tclas->len);
	if (len_lt_error(tclas->len, 3))
		return 0;
	tprintf("User Priority: %u, ", tclas->user_priority);
	tprintf("Classifier Type: %s (%u), ", class_type(frm_class->type),
						  frm_class->type);
	tprintf("Classifier Mask: 0x%x, ", frm_class->mask);

	if(frm_class->type == 0) {
		struct element_tclas_type0 *type0;
		
		type0 =	(struct element_tclas_type0 *)
				  pkt_pull(pkt, sizeof(*type0));
		if (type0 == NULL)
			return 0;
		
		/* I think little endian, like the rest */
		tprintf("Src Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
		type0->sa[5], type0->sa[4], type0->sa[3],
		type0->sa[2], type0->sa[1], type0->sa[0]);
		tprintf("Dst Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
		type0->da[5], type0->da[4], type0->da[3],
		type0->da[2], type0->da[1], type0->da[0]);
		tprintf("Type: 0x%x", le16_to_cpu(type0->type));
	}
	else if(frm_class->type == 1) {
		struct element_tclas_type1 *type1;
		
		type1 =	(struct element_tclas_type1 *)
				  pkt_pull(pkt, sizeof(*type1));
		if (type1 == NULL)
			return 0;
		
		tprintf("Version: %u, ", type1->version);
		/* big endian format follows */
		if(type1->version == 4) {
			struct element_tclas_type1_ip4 *type1_ip4;
			char src_ip[INET_ADDRSTRLEN];
			char dst_ip[INET_ADDRSTRLEN];
			 
			type1_ip4 = (struct element_tclas_type1_ip4 *)
					  pkt_pull(pkt, sizeof(*type1_ip4));
			if (type1_ip4 == NULL)
				return 0;

			inet_ntop(AF_INET, &type1_ip4->sa, src_ip, sizeof(src_ip));
			inet_ntop(AF_INET, &type1_ip4->da, dst_ip, sizeof(dst_ip));
			 
			tprintf("Src IP: %s, ", src_ip);
			tprintf("Dst IP: %s, ", dst_ip);
			tprintf("Src Port: %u, ", ntohs(type1_ip4->sp));
			tprintf("Dst Port: %u, ", ntohs(type1_ip4->dp));
			tprintf("DSCP: 0x%x, ", type1_ip4->dscp);
			tprintf("Proto: %u, ", type1_ip4->proto);
			tprintf("Res: 0x%x", type1_ip4->reserved);
		}
		else if(type1->version == 6) {
			struct element_tclas_type1_ip6 *type1_ip6;
			char src_ip[INET6_ADDRSTRLEN];
			char dst_ip[INET6_ADDRSTRLEN];

			type1_ip6 = (struct element_tclas_type1_ip6 *)
					  pkt_pull(pkt, sizeof(*type1_ip6));
			if (type1_ip6 == NULL)
				return 0;

			inet_ntop(AF_INET6, &type1_ip6->sa,
				  src_ip, sizeof(src_ip));
			inet_ntop(AF_INET6, &type1_ip6->da,
				  dst_ip, sizeof(dst_ip));

			tprintf("Src IP: %s, ", src_ip);
			tprintf("Dst IP: %s, ", dst_ip);
			tprintf("Src Port: %u, ", ntohs(type1_ip6->sp));
			tprintf("Dst Port: %u, ", ntohs(type1_ip6->dp));
			tprintf("Flow Label: 0x%x%x%x", type1_ip6->flow_label1,
				type1_ip6->flow_label2, type1_ip6->flow_label3);
		}
		else {
			tprintf("Version (%u) not supported", type1->version);
			return 0;
		}
		  
	}
	else if(frm_class->type == 2) {
		struct element_tclas_type2 *type2;

		type2 =	(struct element_tclas_type2 *)
				  pkt_pull(pkt, sizeof(*type2));
		if (type2 == NULL)
			return 0;

		tprintf("802.1Q VLAN TCI: 0x%x", ntohs(type2->vlan_tci));
	}
	else if(frm_class->type == 3) {
		struct element_tclas_type3 *type3;
		u8 len, i;
		u8 *val;

		type3 =	(struct element_tclas_type3 *)
				  pkt_pull(pkt, sizeof(*type3));
		if (type3 == NULL)
			return 0;

		len = (tclas->len - 5) / 2;

		tprintf("Filter Offset: %u, ", type3->offs);
		
		if((len & 1) || (len_lt_error(tclas->len, 5))) {
			tprintf("Length of TCLAS (%u) not correct", tclas->len);
			return 0;
		}
		else {
			val = pkt_pull(pkt, len);
			if (val == NULL)
				return 0;

			tprintf("Filter Value: 0x");
			for (i = 0; i < len / 2; i++)
				tprintf("%x ", val[i]);
			tprintf(", ");
			tprintf("Filter Mask: 0x");
			for (i = len / 2; i < len; i++)
				tprintf("%x ", val[i]);
		}
		
	}
	else if(frm_class->type == 4) {
		struct element_tclas_type4 *type4;

		type4 =	(struct element_tclas_type4 *)
				  pkt_pull(pkt, sizeof(*type4));
		if (type4 == NULL)
			return 0;

		tprintf("Version: %u, ", type4->version);
		/* big endian format follows */
		if(type4->version == 4) {
			struct element_tclas_type4_ip4 *type4_ip4;
			char src_ip[INET_ADDRSTRLEN];
			char dst_ip[INET_ADDRSTRLEN];

			type4_ip4 = (struct element_tclas_type4_ip4 *)
					  pkt_pull(pkt, sizeof(*type4_ip4));
			if (type4_ip4 == NULL)
				return 0;

			inet_ntop(AF_INET, &type4_ip4->sa, src_ip, sizeof(src_ip));
			inet_ntop(AF_INET, &type4_ip4->da, dst_ip, sizeof(dst_ip));

			tprintf("Src IP: %s, ", src_ip);
			tprintf("Dst IP: %s, ", dst_ip);
			tprintf("Src Port: %u, ", ntohs(type4_ip4->sp));
			tprintf("Dst Port: %u, ", ntohs(type4_ip4->dp));
			tprintf("DSCP: 0x%x, ", type4_ip4->dscp);
			tprintf("Proto: %u, ", type4_ip4->proto);
			tprintf("Res: 0x%x", type4_ip4->reserved);
		}
		else if(type4->version == 6) {
			struct element_tclas_type4_ip6 *type4_ip6;
			char src_ip[INET6_ADDRSTRLEN];
			char dst_ip[INET6_ADDRSTRLEN];

			type4_ip6 = (struct element_tclas_type4_ip6 *)
					  pkt_pull(pkt, sizeof(*type4_ip6));
			if (type4_ip6 == NULL)
				return 0;

			inet_ntop(AF_INET6, &type4_ip6->sa,
				  src_ip, sizeof(src_ip));
			inet_ntop(AF_INET6, &type4_ip6->da,
				  dst_ip, sizeof(dst_ip));

			tprintf("Src IP: %s, ", src_ip);
			tprintf("Dst IP: %s, ", dst_ip);
			tprintf("Src Port: %u, ", ntohs(type4_ip6->sp));
			tprintf("Dst Port: %u, ", ntohs(type4_ip6->dp));
			tprintf("DSCP: 0x%x, ", type4_ip6->dscp);
			tprintf("Nxt Hdr: %u, ", type4_ip6->nxt_hdr);
			tprintf("Flow Label: 0x%x%x%x", type4_ip6->flow_label1,
				type4_ip6->flow_label2, type4_ip6->flow_label3);
		}
		else {
			tprintf("Version (%u) not supported", type4->version);
			return 0;
		}
	}
	else if(frm_class->type == 5) {
		struct element_tclas_type5 *type5;

		type5 =	(struct element_tclas_type5 *)
				  pkt_pull(pkt, sizeof(*type5));
		if (type5 == NULL)
			return 0;

		tprintf("802.1Q PCP: 0x%x, ", type5->pcp);
		tprintf("802.1Q CFI: 0x%x, ", type5->cfi);
		tprintf("802.1Q VID: 0x%x", type5->vid);
	}
	else {
		tprintf("Classifier Type (%u) not supported", frm_class->type);
		return 0;
	}

	return 1;
}

static int8_t inf_sched(struct pkt_buff *pkt, u8 *id)
{
	struct element_schedule *schedule;
	u16 info;

	schedule = (struct element_schedule *) pkt_pull(pkt, sizeof(*schedule));
	if (schedule == NULL)
		return 0;

	info = le16_to_cpu(schedule->inf);

	tprintf(" Schedule (%u, Len(%u)): ", *id, schedule->len);
	if (len_neq_error(schedule->len, 12))
		return 0;
	
	tprintf("Aggregation: %u, ", info >> 15);
	tprintf("TSID: %u, ", (info >> 11) & 0xF);
	tprintf("Direction: %u, ", (info >> 9) & 0x3);
	tprintf("Res: %u, ", info & 0x1FF);
	tprintf("Serv Start Time: %uus, ", le32_to_cpu(schedule->start));
	tprintf("Serv Interval: %uus, ", le32_to_cpu(schedule->serv_intv));
	tprintf("Spec Interval: %fs", le32_to_cpu(schedule->spec_intv) * TU);

	return 1;
}

static int8_t inf_chall_txt(struct pkt_buff *pkt, u8 *id)
{
	struct element_chall_txt *chall_txt;
	u8 i;
	u8 *txt;

	chall_txt = (struct element_chall_txt *)
			pkt_pull(pkt, sizeof(*chall_txt));
	if (chall_txt == NULL)
		return 0;

	tprintf(" Challenge Text (%u, Len(%u)): ", *id, chall_txt->len);
	if ((chall_txt->len - sizeof(*chall_txt) + 1) > 0) {
		txt = pkt_pull(pkt, (chall_txt->len - sizeof(*chall_txt) + 1));
		if (txt == NULL)
			return 0;

		tprintf("0x");
		for (i = 0; i < (chall_txt->len - sizeof(*chall_txt) + 1); i++)
			tprintf("%x", txt[i]);
	}

	return 1;
}

static int8_t inf_pwr_constr(struct pkt_buff *pkt, u8 *id)
{
	struct element_pwr_constr *pwr_constr;

	pwr_constr = (struct element_pwr_constr *) pkt_pull(pkt, sizeof(*pwr_constr));
	if (pwr_constr == NULL)
		return 0;

	tprintf(" Power Constraint (%u, Len(%u)): ", *id, pwr_constr->len);
	if (len_neq_error(pwr_constr->len, 1))
		return 0;

	tprintf("Local Power Constraint: %udB", pwr_constr->local_pwr_constr);

	return 1;
}

static int8_t inf_pwr_cap(struct pkt_buff *pkt, u8 *id)
{
	struct element_pwr_cap *pwr_cap;

	pwr_cap = (struct element_pwr_cap *) pkt_pull(pkt, sizeof(*pwr_cap));
	if (pwr_cap == NULL)
		return 0;

	tprintf(" Power Capability (%u, Len(%u)): ", *id, pwr_cap->len);
	if (len_neq_error(pwr_cap->len, 2))
		return 0;

	tprintf("Min. Transm. Pwr Cap.: %ddBm, ", (int8_t)pwr_cap->min_pwr_cap);
	tprintf("Max. Transm. Pwr Cap.: %ddBm", (int8_t)pwr_cap->max_pwr_cap);

	return 1;
}

static int8_t inf_tpc_req(struct pkt_buff *pkt, u8 *id)
{
	struct element_tpc_req *tpc_req;

	tpc_req = (struct element_tpc_req *) pkt_pull(pkt, sizeof(*tpc_req));
	if (tpc_req == NULL)
		return 0;

	tprintf(" TPC Request (%u, Len(%u))", *id, tpc_req->len);
	if (len_neq_error(tpc_req->len, 0))
		return 0;

	return 1;
}

static int8_t inf_tpc_rep(struct pkt_buff *pkt, u8 *id)
{
	struct element_tpc_rep *tpc_rep;

	tpc_rep = (struct element_tpc_rep *) pkt_pull(pkt, sizeof(*tpc_rep));
	if (tpc_rep == NULL)
		return 0;

	tprintf(" TPC Report (%u, Len(%u)): ", *id, tpc_rep->len);
	if (len_neq_error(tpc_rep->len, 2))
		return 0;

	tprintf("Transmit Power: %udBm, ", (int8_t)tpc_rep->trans_pwr);
	tprintf("Link Margin: %udB", (int8_t)tpc_rep->trans_pwr);

	return 1;
}

static int8_t inf_supp_ch(struct pkt_buff *pkt, u8 *id)
{
	struct element_supp_ch *supp_ch;
	u8 i;

	supp_ch = (struct element_supp_ch *) pkt_pull(pkt, sizeof(*supp_ch));
	if (supp_ch == NULL)
		return 0;

	tprintf(" Supp Channels (%u, Len(%u)): ", *id, supp_ch->len);
	if (len_lt_error(supp_ch->len, 2))
		return 0;

	if(supp_ch->len & 1) {
		tprintf("Length should be even");
		return 0;
	}
  
	for (i = 0; i < supp_ch->len; i += 2) {
		struct element_supp_ch_tuple *supp_ch_tuple;

		supp_ch_tuple = (struct element_supp_ch_tuple *)
				    pkt_pull(pkt, sizeof(*supp_ch_tuple));
		if (supp_ch_tuple == NULL)
			return 0;

		tprintf("First Channel Nr: %u, ", supp_ch_tuple->first_ch_nr);
		tprintf("Nr of Channels: %u, ", supp_ch_tuple->nr_ch);
	}

	return 1;
}

static int8_t inf_ch_sw_ann(struct pkt_buff *pkt, u8 *id)
{
	struct element_ch_sw_ann *ch_sw_ann;

	ch_sw_ann = (struct element_ch_sw_ann *)
			pkt_pull(pkt, sizeof(*ch_sw_ann));
	if (ch_sw_ann == NULL)
		return 0;

	tprintf(" Channel Switch Announc (%u, Len(%u)): ", *id, ch_sw_ann->len);
	if (len_neq_error(ch_sw_ann->len, 3))
		return 0;

	tprintf("Switch Mode: %u, ", ch_sw_ann->switch_mode);
	tprintf("New Nr: %u, ", ch_sw_ann->new_nr);
	tprintf("Switch Count: %u", ch_sw_ann->switch_cnt);

	return 1;
}

static const char *meas_type(u8 type)
{
	switch (type) {
	case 0:  return "Basic";
	case 1:  return "Clear Channel assesment (CCA)";
	case 2:  return "Receive power indication (RPI) histogram";
	case 3:  return "Channel load";
	case 4:  return "Noise histogram";
	case 5:  return "Beacon";
	case 6:  return "Frame";
	case 7:  return "STA statistics";
	case 8:  return "LCI";
	case 9:  return "Transmit stream/category measurement";
	case 10: return "Multicast diagnostics";
	case 11: return "Location Civic";
	case 12: return "Location Identifier";
	default: return "Reserved";
	}
}

static int8_t inf_meas_req(struct pkt_buff *pkt, u8 *id)
{
	struct element_meas_req *meas_req;

	meas_req = (struct element_meas_req *) pkt_pull(pkt, sizeof(*meas_req));
	if (meas_req == NULL)
		return 0;

	tprintf(" Measurement Req (%u, Len(%u)): ", *id, meas_req->len);
	if (len_lt_error(meas_req->len, 3))
		return 0;

	tprintf("Token: %u, ", meas_req->token);
	tprintf("Req Mode: 0x%x (Parallel (%u), Enable(%u), Request(%u), "
	"Report(%u), Dur Mand(%u), Res(0x%x)),  ", meas_req->req_mode,
					meas_req->req_mode & 0x1,
					(meas_req->req_mode >> 1) & 0x1,
					(meas_req->req_mode >> 2) & 0x1,
					(meas_req->req_mode >> 3) & 0x1,
					(meas_req->req_mode >> 4) & 0x1,
					meas_req->req_mode >> 7);
	tprintf("Type: %s (%u), ", meas_type(meas_req->type), meas_req->type);

	if(meas_req->len > 3) {
		if(meas_req->type == 0) {
			struct element_meas_basic *basic;

			basic = (struct element_meas_basic *)
				    pkt_pull(pkt, sizeof(*basic));
			if (basic == NULL)
				return 0;

			if ((meas_req->len - 3 - sizeof(*basic)) != 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Ch Nr: %uus, ", basic->ch_nr);
			tprintf("Meas Start Time: %"PRIu64", ",
				    le64_to_cpu(basic->start));
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(basic->dur) * TU);
			
		}
		else if(meas_req->type == 1) {
			struct element_meas_cca *cca;

			cca = (struct element_meas_cca *)
				    pkt_pull(pkt, sizeof(*cca));
			if (cca == NULL)
				return 0;

			if ((meas_req->len - 3 - sizeof(*cca)) != 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Ch Nr: %uus, ", cca->ch_nr);
			tprintf("Meas Start Time: %"PRIu64", ",
				    le64_to_cpu(cca->start));
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(cca->dur) * TU);
		}
		else if(meas_req->type == 2) {
			struct element_meas_rpi *rpi;

			rpi = (struct element_meas_rpi *)
				    pkt_pull(pkt, sizeof(*rpi));
			if (rpi == NULL)
				return 0;

			if ((meas_req->len - 3 - sizeof(*rpi)) != 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Ch Nr: %uus, ", rpi->ch_nr);
			tprintf("Meas Start Time: %"PRIu64", ",
				    le64_to_cpu(rpi->start));
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(rpi->dur) * TU);
		}
		else if(meas_req->type == 3) {
			struct element_meas_ch_load *ch_load;

			ch_load = (struct element_meas_ch_load *)
				    pkt_pull(pkt, sizeof(*ch_load));
			if (ch_load == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*ch_load)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("OP Class: %u, ", ch_load->op_class);
			tprintf("Ch Nr: %u, ", ch_load->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(ch_load->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(ch_load->dur) * TU);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*ch_load)))
				return 0;
		}
		else if(meas_req->type == 4) {
			struct element_meas_noise *noise;

			noise = (struct element_meas_noise *)
				    pkt_pull(pkt, sizeof(*noise));
			if (noise == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*noise)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("OP Class: %u, ", noise->op_class);
			tprintf("Ch Nr: %u, ", noise->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(noise->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(noise->dur) * TU);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*noise)))
				return 0;
		}
		else if(meas_req->type == 5) {
			struct element_meas_beacon *beacon;

			beacon = (struct element_meas_beacon *)
				    pkt_pull(pkt, sizeof(*beacon));
			if (beacon == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*beacon)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("OP Class: %u, ", beacon->op_class);
			tprintf("Ch Nr: %u, ", beacon->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(beacon->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(beacon->dur) * TU);
			tprintf("Mode: %u, ", beacon->mode);
			tprintf("BSSID: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				    beacon->bssid[0], beacon->bssid[1],
				    beacon->bssid[2], beacon->bssid[3],
				    beacon->bssid[4], beacon->bssid[5]);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*beacon)))
				return 0;
		}
		else if(meas_req->type == 6) {
			struct element_meas_frame *frame;

			frame = (struct element_meas_frame *)
				    pkt_pull(pkt, sizeof(*frame));
			if (frame == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*frame)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("OP Class: %u, ", frame->op_class);
			tprintf("Ch Nr: %u, ", frame->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(frame->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(frame->dur) * TU);
			tprintf("Request Type: %u, ", frame->frame);
			tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				    frame->mac[0], frame->mac[1],
				    frame->mac[2], frame->mac[3],
				    frame->mac[4], frame->mac[5]);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*frame)))
				return 0;
		}
		else if(meas_req->type == 7) {
			struct element_meas_sta *sta;

			sta = (struct element_meas_sta *)
				    pkt_pull(pkt, sizeof(*sta));
			if (sta == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*sta)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Peer MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				    sta->peer_mac[0], sta->peer_mac[1],
				    sta->peer_mac[2], sta->peer_mac[3],
				    sta->peer_mac[4], sta->peer_mac[5]);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(sta->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(sta->dur) * TU);
			tprintf("Group ID: %u, ", sta->group_id);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*sta)))
				return 0;
		}
		else if(meas_req->type == 8) {
			struct element_meas_lci *lci;

			lci = (struct element_meas_lci *)
				    pkt_pull(pkt, sizeof(*lci));
			if (lci == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*lci)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Location Subj: %u, ", lci->loc_subj);
			tprintf("Latitude Req Res: %udeg",
				    lci->latitude_req_res);
			tprintf("Longitude Req Res: %udeg",
				    lci->longitude_req_res);
			tprintf("Altitude Req Res: %udeg",
				    lci->altitude_req_res);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*lci)))
				return 0;
		}
		else if(meas_req->type == 9) {
			struct element_meas_trans_str_cat *trans;

			trans = (struct element_meas_trans_str_cat *)
				    pkt_pull(pkt, sizeof(*trans));
			if (trans == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*trans)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(trans->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(trans->dur) * TU);
			tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				trans->peer_sta_addr[0], trans->peer_sta_addr[1],
				trans->peer_sta_addr[2], trans->peer_sta_addr[3],
				trans->peer_sta_addr[4], trans->peer_sta_addr[5]);
			tprintf("Traffic ID: %u, ", trans->traffic_id);
			tprintf("Bin 0 Range: %u, ", trans->bin_0_range);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*trans)))
				return 0;
		}
		else if(meas_req->type == 10) {
			struct element_meas_mcast_diag *mcast;

			mcast = (struct element_meas_mcast_diag *)
				    pkt_pull(pkt, sizeof(*mcast));
			if (mcast == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*mcast)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(mcast->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(mcast->dur) * TU);
			tprintf("Group MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				mcast->group_mac[0], mcast->group_mac[1],
				mcast->group_mac[2], mcast->group_mac[3],
				mcast->group_mac[4], mcast->group_mac[5]);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*mcast)))
				return 0;
		}
		else if(meas_req->type == 11) {
			struct element_meas_loc_civic *civic;

			civic = (struct element_meas_loc_civic *)
				    pkt_pull(pkt, sizeof(*civic));
			if (civic == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*civic)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Location Subj: %u, ", civic->loc_subj);
			tprintf("Type: %u, ", civic->civic_loc);
			tprintf("Srv Intv Units: %u, ",
				    le16_to_cpu(civic->loc_srv_intv_unit));
			tprintf("Srv Intv: %u, ", civic->loc_srv_intv);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*civic)))
				return 0;
		}
		else if(meas_req->type == 12) {
			struct element_meas_loc_id *id;

			id = (struct element_meas_loc_id *)
				    pkt_pull(pkt, sizeof(*id));
			if (id == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*id)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Location Subj: %u, ", id->loc_subj);
			tprintf("Srv Intv Units: %u, ",
				    le16_to_cpu(id->loc_srv_intv_unit));
			tprintf("Srv Intv: %u", id->loc_srv_intv);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*id)))
				return 0;
		}
		else if(meas_req->type == 255) {
			struct element_meas_pause *pause;

			pause = (struct element_meas_pause *)
				    pkt_pull(pkt, sizeof(*pause));
			if (pause == NULL)
				return 0;

			if ((ssize_t)(meas_req->len - 3 - sizeof(*pause)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_req->type);
				return 0;
			}

			tprintf("Pause Time: %fs, ", pause->time * 10 * TU);

			if(!subelements(pkt,
					  meas_req->len - 3 - sizeof(*pause)))
				return 0;
		}
		else {
			tprintf("Length field indicates data,"
			" but could not interpreted");
			return 0;
		}
	}

	return 1;
}

static int8_t inf_meas_rep(struct pkt_buff *pkt, u8 *id)
{
	struct element_meas_rep *meas_rep;

	meas_rep = (struct element_meas_rep *) pkt_pull(pkt, sizeof(*meas_rep));
	if (meas_rep == NULL)
		return 0;

	tprintf(" Measurement Rep (%u, Len(%u)): ", *id, meas_rep->len);
	if (len_lt_error(meas_rep->len, 3))
		return 0;

	tprintf("Token: %u, ", meas_rep->token);
	tprintf("Rep Mode: 0x%x (Late (%u), Incapable(%u), Refused(%u), ",
		meas_rep->rep_mode, meas_rep->rep_mode >> 7,
		(meas_rep->rep_mode >> 6) & 0x1,
		(meas_rep->rep_mode >> 5) & 0x1);
	tprintf("Type: %s (%u), ", meas_type(meas_rep->type), meas_rep->type);

	if(meas_rep->len > 3) {
		if(meas_rep->type == 0) {
			struct element_meas_basic *basic;

			basic = (struct element_meas_basic *)
				    pkt_pull(pkt, sizeof(*basic));
			if (basic == NULL)
				return 0;

			if ((meas_rep->len - 3 - sizeof(*basic)) != 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Ch Nr: %uus, ", basic->ch_nr);
			tprintf("Meas Start Time: %"PRIu64", ",
				    le64_to_cpu(basic->start));
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(basic->dur) * TU);

		}
		else if(meas_rep->type == 1) {
			struct element_meas_cca *cca;

			cca = (struct element_meas_cca *)
				    pkt_pull(pkt, sizeof(*cca));
			if (cca == NULL)
				return 0;

			if ((meas_rep->len - 3 - sizeof(*cca)) != 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Ch Nr: %uus, ", cca->ch_nr);
			tprintf("Meas Start Time: %"PRIu64", ",
				    le64_to_cpu(cca->start));
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(cca->dur) * TU);
		}
		else if(meas_rep->type == 2) {
			struct element_meas_rpi *rpi;

			rpi = (struct element_meas_rpi *)
				    pkt_pull(pkt, sizeof(*rpi));
			if (rpi == NULL)
				return 0;

			if ((meas_rep->len - 3 - sizeof(*rpi)) != 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Ch Nr: %uus, ", rpi->ch_nr);
			tprintf("Meas Start Time: %"PRIu64", ",
				    le64_to_cpu(rpi->start));
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(rpi->dur) * TU);
		}
		else if(meas_rep->type == 3) {
			struct element_meas_ch_load *ch_load;

			ch_load = (struct element_meas_ch_load *)
				    pkt_pull(pkt, sizeof(*ch_load));
			if (ch_load == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*ch_load)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("OP Class: %u, ", ch_load->op_class);
			tprintf("Ch Nr: %u, ", ch_load->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(ch_load->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(ch_load->dur) * TU);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*ch_load)))
				return 0;
		}
		else if(meas_rep->type == 4) {
			struct element_meas_noise *noise;

			noise = (struct element_meas_noise *)
				    pkt_pull(pkt, sizeof(*noise));
			if (noise == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*noise)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("OP Class: %u, ", noise->op_class);
			tprintf("Ch Nr: %u, ", noise->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(noise->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(noise->dur) * TU);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*noise)))
				return 0;
		}
		else if(meas_rep->type == 5) {
			struct element_meas_beacon *beacon;

			beacon = (struct element_meas_beacon *)
				    pkt_pull(pkt, sizeof(*beacon));
			if (beacon == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*beacon)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("OP Class: %u, ", beacon->op_class);
			tprintf("Ch Nr: %u, ", beacon->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(beacon->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(beacon->dur) * TU);
			tprintf("Mode: %u, ", beacon->mode);
			tprintf("BSSID: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				    beacon->bssid[0], beacon->bssid[1],
				    beacon->bssid[2], beacon->bssid[3],
				    beacon->bssid[4], beacon->bssid[5]);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*beacon)))
				return 0;
		}
		else if(meas_rep->type == 6) {
			struct element_meas_frame *frame;

			frame = (struct element_meas_frame *)
				    pkt_pull(pkt, sizeof(*frame));
			if (frame == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*frame)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("OP Class: %u, ", frame->op_class);
			tprintf("Ch Nr: %u, ", frame->ch_nr);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(frame->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(frame->dur) * TU);
			tprintf("Request Type: %u, ", frame->frame);
			tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				    frame->mac[0], frame->mac[1],
				    frame->mac[2], frame->mac[3],
				    frame->mac[4], frame->mac[5]);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*frame)))
				return 0;
		}
		else if(meas_rep->type == 7) {
			struct element_meas_sta *sta;

			sta = (struct element_meas_sta *)
				    pkt_pull(pkt, sizeof(*sta));
			if (sta == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*sta)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Peer MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
				    sta->peer_mac[0], sta->peer_mac[1],
				    sta->peer_mac[2], sta->peer_mac[3],
				    sta->peer_mac[4], sta->peer_mac[5]);
			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(sta->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(sta->dur) * TU);
			tprintf("Group ID: %u, ", sta->group_id);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*sta)))
				return 0;
		}
		else if(meas_rep->type == 8) {
			struct element_meas_lci *lci;

			lci = (struct element_meas_lci *)
				    pkt_pull(pkt, sizeof(*lci));
			if (lci == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*lci)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Location Subj: %u, ", lci->loc_subj);
			tprintf("Latitude Req Res: %udeg",
				    lci->latitude_req_res);
			tprintf("Longitude Req Res: %udeg",
				    lci->longitude_req_res);
			tprintf("Altitude Req Res: %udeg",
				    lci->altitude_req_res);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*lci)))
				return 0;
		}
		else if(meas_rep->type == 9) {
			struct element_meas_trans_str_cat *trans;

			trans = (struct element_meas_trans_str_cat *)
				    pkt_pull(pkt, sizeof(*trans));
			if (trans == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*trans)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(trans->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(trans->dur) * TU);
			tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
				trans->peer_sta_addr[0], trans->peer_sta_addr[1],
				trans->peer_sta_addr[2], trans->peer_sta_addr[3],
				trans->peer_sta_addr[4], trans->peer_sta_addr[5]);
			tprintf("Traffic ID: %u, ", trans->traffic_id);
			tprintf("Bin 0 Range: %u, ", trans->bin_0_range);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*trans)))
				return 0;
		}
		else if(meas_rep->type == 10) {
			struct element_meas_mcast_diag *mcast;

			mcast = (struct element_meas_mcast_diag *)
				    pkt_pull(pkt, sizeof(*mcast));
			if (mcast == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*mcast)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Rand Intv: %fs, ",
				    le16_to_cpu(mcast->rand_intv) * TU);
			tprintf("Meas Duration: %fs",
				    le16_to_cpu(mcast->dur) * TU);
			tprintf("Group MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
				mcast->group_mac[0], mcast->group_mac[1],
				mcast->group_mac[2], mcast->group_mac[3],
				mcast->group_mac[4], mcast->group_mac[5]);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*mcast)))
				return 0;
		}
		else if(meas_rep->type == 11) {
			struct element_meas_loc_civic *civic;

			civic = (struct element_meas_loc_civic *)
				    pkt_pull(pkt, sizeof(*civic));
			if (civic == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*civic)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Location Subj: %u, ", civic->loc_subj);
			tprintf("Type: %u, ", civic->civic_loc);
			tprintf("Srv Intv Units: %u, ",
				    le16_to_cpu(civic->loc_srv_intv_unit));
			tprintf("Srv Intv: %u, ", civic->loc_srv_intv);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*civic)))
				return 0;
		}
		else if(meas_rep->type == 12) {
			struct element_meas_loc_id *id;

			id = (struct element_meas_loc_id *)
				    pkt_pull(pkt, sizeof(*id));
			if (id == NULL)
				return 0;

			if ((ssize_t)(meas_rep->len - 3 - sizeof(*id)) < 0) {
				tprintf("Length of Req matchs not Type %u",
					    meas_rep->type);
				return 0;
			}

			tprintf("Location Subj: %u, ", id->loc_subj);
			tprintf("Srv Intv Units: %u, ",
				    le16_to_cpu(id->loc_srv_intv_unit));
			tprintf("Srv Intv: %u", id->loc_srv_intv);

			if(!subelements(pkt,
					  meas_rep->len - 3 - sizeof(*id)))
				return 0;
		}
		else {
			tprintf("Length field indicates data,"
			" but could not interpreted");
			return 0;
		}
	}

	return 1;
}

static int8_t inf_quiet(struct pkt_buff *pkt, u8 *id)
{
	struct element_quiet *quiet;

	quiet = (struct element_quiet *) pkt_pull(pkt, sizeof(*quiet));
	if (quiet == NULL)
		return 0;

	tprintf(" Quit (%u, Len(%u)): ", *id, quiet->len);
	if (len_neq_error(quiet->len, 6))
		return 0;

	tprintf("Count: %ud, ", quiet->cnt);
	tprintf("Period: %u, ", quiet->period);
	tprintf("Duration: %fs, ", le16_to_cpu(quiet->dur) * TU);
	tprintf("Offs: %fs", le16_to_cpu(quiet->offs) * TU);
	

	return 1;
}

static int8_t inf_ibss_dfs(struct pkt_buff *pkt, u8 *id)
{
	struct element_ibss_dfs *ibss_dfs;
	u8 i;

	ibss_dfs = (struct element_ibss_dfs *) pkt_pull(pkt, sizeof(*ibss_dfs));
	if (ibss_dfs == NULL)
		return 0;

	tprintf(" IBSS DFS (%u, Len(%u)): ", *id, ibss_dfs->len);
	if (len_lt_error(ibss_dfs->len, 7))
		return 0;

	tprintf("Owner: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
		    ibss_dfs->owner[0], ibss_dfs->owner[1],
		    ibss_dfs->owner[2], ibss_dfs->owner[3],
		    ibss_dfs->owner[4], ibss_dfs->owner[5]);
	tprintf("Recovery Intv: %u, ", ibss_dfs->rec_intv);

	if((ibss_dfs->len - sizeof(*ibss_dfs) + 1) & 1) {
		tprintf("Length of Channel Map should be modulo 2");
		return 0;
	}

	for (i = 0; i < ibss_dfs->len; i += 2) {
		struct element_ibss_dfs_tuple *ibss_dfs_tuple;

		ibss_dfs_tuple = (struct element_ibss_dfs_tuple *)
				    pkt_pull(pkt, sizeof(*ibss_dfs_tuple));
		if (ibss_dfs_tuple == NULL)
			return 0;

		tprintf("Channel Nr: %u, ", ibss_dfs_tuple->ch_nr);
		tprintf("Map: %u, ", ibss_dfs_tuple->map);
	}

	return 1;
}

static int8_t inf_erp(struct pkt_buff *pkt, u8 *id)
{
	struct element_erp *erp;

	erp = (struct element_erp *) pkt_pull(pkt, sizeof(*erp));
	if (erp == NULL)
		return 0;

	tprintf(" ERP (%u, Len(%u)): ", *id, erp->len);
	if (len_neq_error(erp->len, 1))
		return 0;
	tprintf("Non ERP Present (%u), ", erp->param & 0x1);
	tprintf("Use Protection (%u), ", (erp->param >> 1) & 0x1);
	tprintf("Barker Preamble Mode (%u), ", (erp->param >> 2) & 0x1);
	tprintf("Reserved (0x%.5x)", erp->param >> 3);

	return 1;
}

static int8_t inf_ts_del(struct pkt_buff *pkt, u8 *id)
{
	struct element_ts_del *ts_del;

	ts_del = (struct element_ts_del *) pkt_pull(pkt, sizeof(*ts_del));
	if (ts_del == NULL)
		return 0;

	tprintf(" TS Delay (%u, Len(%u)): ", *id, ts_del->len);
	if (len_neq_error(ts_del->len, 4))
		return 0;
	tprintf("Delay (%fs)", le32_to_cpu(ts_del->delay) * TU);

	return 1;
}

static int8_t inf_tclas_proc(struct pkt_buff *pkt, u8 *id)
{
	struct element_tclas_proc *tclas_proc;

	tclas_proc = (struct element_tclas_proc *)
			  pkt_pull(pkt, sizeof(*tclas_proc));
	if (tclas_proc == NULL)
		return 0;

	tprintf(" TCLAS Procesing (%u, Len(%u)): ", *id, tclas_proc->len);
	if (len_neq_error(tclas_proc->len, 1))
		return 0;
	tprintf("Processing (%u)", tclas_proc->proc);

	return 1;
}

static int8_t inf_ht_cap(struct pkt_buff *pkt, u8 *id)
{
	struct element_ht_cap *ht_cap;
	u32 tx_param_res, beam_cap;
	u16 ext_cap;

	ht_cap = (struct element_ht_cap *)
			  pkt_pull(pkt, sizeof(*ht_cap));
	if (ht_cap == NULL)
		return 0;

	tx_param_res = le32_to_cpu(ht_cap->tx_param_res);
	beam_cap = le32_to_cpu(ht_cap->beam_cap);
	ext_cap = le16_to_cpu(ht_cap->ext_cap);

	tprintf(" HT Capabilities (%u, Len(%u)):\n", *id, ht_cap->len);
	if (len_neq_error(ht_cap->len, 26))
		return 0;

	tprintf("\t\t Info:\n");
	tprintf("\t\t\t LDCP Cod Cap (%u)\n", ht_cap->ldpc);
	tprintf("\t\t\t Supp Ch Width Set (%u)\n", ht_cap->supp_width);
	tprintf("\t\t\t SM Pwr Save(%u)\n", ht_cap->sm_pwr);
	tprintf("\t\t\t HT-Greenfield (%u)\n", ht_cap->ht_green);
	tprintf("\t\t\t Short GI for 20/40 MHz (%u/%u)\n", ht_cap->gi_20mhz,
			ht_cap->gi_40mhz);
	tprintf("\t\t\t Tx/Rx STBC (%u/%u)\n", ht_cap->tx_stbc,
			ht_cap->rx_stbc);
	tprintf("\t\t\t HT-Delayed Block Ack (%u)\n", ht_cap->ht_ack);
	tprintf("\t\t\t Max A-MSDU Len (%u)\n", ht_cap->max_msdu_length);
	tprintf("\t\t\t DSSS/CCK Mode in 40 MHz (%u)\n",
			ht_cap->dsss_ck_mode);
	tprintf("\t\t\t Res (0x%x)\n", ht_cap->res);
	tprintf("\t\t\t Forty MHz Intol (%u)\n", ht_cap->forty_int);
	tprintf("\t\t\t L-SIG TXOP Protection Supp (%u)\n",
			ht_cap->prot_supp);

	tprintf("\t\t A-MPDU Params:\n");
	tprintf("\t\t\t Max Len Exp (%u)\n", ht_cap->param >> 6);
	tprintf("\t\t\t Min Start Spacing (%u)\n",
			(ht_cap->param >> 3) & 0x7);
	tprintf("\t\t\t Res (0x%x)\n", ht_cap->param & 0x07);

	tprintf("\t\t Supp MCS Set:\n");
	tprintf("\t\t\t Rx MCS Bitmask (0x%x%x%x%x%x%x%x%x%x%x)\n",
			ht_cap->bitmask1, ht_cap->bitmask2, ht_cap->bitmask3,
			ht_cap->bitmask4, ht_cap->bitmask5, ht_cap->bitmask6,
			ht_cap->bitmask7, ht_cap->bitmask8, ht_cap->bitmask9,
			ht_cap->bitmask10_res >> 3);
	tprintf("\t\t\t Res (0x%x)\n", ht_cap->bitmask10_res & 0x7);
	tprintf("\t\t\t Rx High Supp Data Rate (%u)\n",
			le16_to_cpu(ht_cap->supp_rate_res) >> 6);
	tprintf("\t\t\t Res (0x%x)\n",
			le16_to_cpu(ht_cap->supp_rate_res) & 0x3F);
	tprintf("\t\t\t Tx MCS Set Def (%u)\n", tx_param_res >> 31);
	tprintf("\t\t\t Tx Rx MCS Set Not Eq (%u)\n",
			(tx_param_res >> 30) & 1);
	tprintf("\t\t\t Tx Max Number Spat Str Supp (%u)\n",
			(tx_param_res >> 28) & 3);
	tprintf("\t\t\t Tx Uneq Mod Supp (%u)\n", (tx_param_res >> 27) & 1);
	tprintf("\t\t\t Res (0x%x)\n", tx_param_res & 0x7FFFFFF);

	tprintf("\t\t Ext Cap:\n");
	tprintf("\t\t\t PCO (%u)\n", ext_cap >> 15);
	tprintf("\t\t\t PCO Trans Time (%u)\n", (ext_cap >> 13) & 3);
	tprintf("\t\t\t Res (0x%x)\n", (ext_cap >> 8) & 0x1F);
	tprintf("\t\t\t MCS Feedb (%u)\n", (ext_cap >> 6) & 3);
	tprintf("\t\t\t +HTC Supp (%u)\n", (ext_cap >> 5) & 1);
	tprintf("\t\t\t RD Resp (%u)\n", (ext_cap >> 4) & 1);
	tprintf("\t\t\t Res (0x%x)\n", ext_cap & 0xF);

	tprintf("\t\t Transm Beamf:\n");
	tprintf("\t\t\t Impl Transm Beamf Rec Cap (%u)\n", beam_cap >> 31);
	tprintf("\t\t\t Rec/Transm Stagg Sound Cap (%u/%u)\n",
			(beam_cap >> 30) & 1, (beam_cap >> 29) & 1);
	tprintf("\t\t\t Rec/Trans NDP Cap (%u/%u)\n",
			(beam_cap >> 28) & 1, (beam_cap >> 27) & 1);
	tprintf("\t\t\t Impl Transm Beamf Cap (%u)\n", (beam_cap >> 26) & 1);
	tprintf("\t\t\t Cal (%u)\n", (beam_cap >> 24) & 3);
	tprintf("\t\t\t Expl CSI Transm Beamf Cap (%u)\n",
			(beam_cap >> 23) & 1);
	tprintf("\t\t\t Expl Noncmpr/Compr Steering Cap (%u/%u)\n",
			(beam_cap >> 22) & 1, (beam_cap >> 21) & 1);
	tprintf("\t\t\t Expl Trans Beamf CSI Feedb (%u)\n",
			(beam_cap >> 19) & 3);
	tprintf("\t\t\t Expl Noncmpr/Cmpr Feedb Cap (%u/%u)\n",
			(beam_cap >> 17) & 3, (beam_cap >> 15) & 3);
	tprintf("\t\t\t Min Grpg (%u)\n", (beam_cap >> 13) & 3);
	tprintf("\t\t\t CSI Num Beamf Ant Supp (%u)\n", (beam_cap >> 11) & 3);
	tprintf("\t\t\t Noncmpr/Cmpr Steering Nr Beamf Ant Supp (%u/%u)\n",
			(beam_cap >> 9) & 3, (beam_cap >> 7) & 3);
	tprintf("\t\t\t CSI Max Nr Rows Beamf Supp (%u)\n",
			(beam_cap >> 5) & 3);
	tprintf("\t\t\t Ch Estim Cap (%u)\n", (beam_cap >> 3) & 3);
	tprintf("\t\t\t Res (0x%x)\n", beam_cap & 7);

	tprintf("\t\t ASEL:\n");
	tprintf("\t\t\t Ant Select Cap (%u)\n", ht_cap->asel_cap >> 7);
	tprintf("\t\t\t Expl CSI Feedb Based Transm ASEL Cap (%u)\n",
			(ht_cap->asel_cap >> 6) & 1);
	tprintf("\t\t\t Ant Indic Feedb Based Transm ASEL Cap (%u)\n",
			(ht_cap->asel_cap >> 5) & 1);
	tprintf("\t\t\t Expl CSI Feedb Cap (%u)\n",
			(ht_cap->asel_cap >> 4) & 1);
	tprintf("\t\t\t Ant Indic Feedb Cap (%u)\n",
			(ht_cap->asel_cap >> 3) & 1);
	tprintf("\t\t\t Rec ASEL Cap (%u)\n", (ht_cap->asel_cap >> 2) & 1);
	tprintf("\t\t\t Transm Sound PPDUs Cap (%u)\n",
			(ht_cap->asel_cap >> 1) & 1);
	tprintf("\t\t\t Res (0x%x)", ht_cap->asel_cap & 1);

	return 1;
}

static int8_t inf_qos_cap(struct pkt_buff *pkt, u8 *id)
{
	struct element_qos_cap *qos_cap;

	qos_cap = (struct element_qos_cap *)
			  pkt_pull(pkt, sizeof(*qos_cap));
	if (qos_cap == NULL)
		return 0;

	tprintf(" QoS Capabilities (%u, Len(%u)): ", *id, qos_cap->len);
	if (len_neq_error(qos_cap->len, 1))
		return 0;

	tprintf("Info (0x%x)", qos_cap->info);

	return 1;
}

static int8_t inf_ext_supp_rates(struct pkt_buff *pkt, u8 *id)
{
	u8 i;
	u8 *rates;
	struct element_ext_supp_rates *ext_supp_rates;

	ext_supp_rates = (struct element_ext_supp_rates *)
				pkt_pull(pkt, sizeof(*ext_supp_rates));
	if (ext_supp_rates == NULL)
		return 0;

	tprintf(" Ext Support Rates (%u, Len(%u)): ", *id, ext_supp_rates->len);

	if ((ext_supp_rates->len - sizeof(*ext_supp_rates) + 1) > 0) {
		rates = pkt_pull(pkt, ext_supp_rates->len);
		if (rates == NULL)
			return 0;

		for (i = 0; i < ext_supp_rates->len; i++)
			tprintf("%g ", (rates[i] & 0x80) ?
				((rates[i] & 0x3f) * 0.5) :
				data_rates(rates[i]));
		return 1;
	}

	return 0;
}

static int8_t inf_vend_spec(struct pkt_buff *pkt, u8 *id)
{
	u8 i;
	u8 *data;
	struct element_vend_spec *vend_spec;

	vend_spec = (struct element_vend_spec *)
			pkt_pull(pkt, sizeof(*vend_spec));
	if (vend_spec == NULL)
		return 0;

	tprintf(" Vendor Specific (%u, Len (%u)): ", *id, vend_spec->len);

	data = pkt_pull(pkt, vend_spec->len);
	if (data == NULL)
		return 0;

	tprintf("Data 0x");
	for (i = 0; i < vend_spec->len; i++)
		tprintf("%.2x", data[i]);

	return 1;
}

static int8_t inf_unimplemented(struct pkt_buff *pkt __maybe_unused,
				u8 *id __maybe_unused)
{
	return 0;
}

static int8_t inf_elements(struct pkt_buff *pkt)
{
	u8 *id = pkt_pull(pkt, 1);
	if (id == NULL)
		return 0;

	switch (*id) {
	case   0: return inf_ssid(pkt, id);
	case   1: return inf_supp_rates(pkt, id);
	case   2: return inf_fh_ps(pkt, id);
	case   3: return inf_dsss_ps(pkt, id);
	case   4: return inf_cf_ps(pkt, id);
	case   5: return inf_tim(pkt, id);
	case   6: return inf_ibss_ps(pkt, id);
	case   7: return inf_country(pkt, id);
	case   8: return inf_hop_pp(pkt, id);
	case   9: return inf_hop_pt(pkt, id);
	case  10: return inf_req(pkt, id);
	case  11: return inf_bss_load(pkt, id);
	case  12: return inf_edca_ps(pkt, id);
	case  13: return inf_tspec(pkt, id);
	case  14: return inf_tclas(pkt, id);
	case  15: return inf_sched(pkt, id);
	case  16: return inf_chall_txt(pkt, id);
	case  17 ... 31: return inf_reserved(pkt, id);
	case  32: return inf_pwr_constr(pkt, id);
	case  33: return inf_pwr_cap(pkt, id);
	case  34: return inf_tpc_req(pkt, id);
	case  35: return inf_tpc_rep(pkt, id);
	case  36: return inf_supp_ch(pkt, id);
	case  37: return inf_ch_sw_ann(pkt, id);
	case  38: return inf_meas_req(pkt, id);
	case  39: return inf_meas_rep(pkt, id);
	case  40: return inf_quiet(pkt, id);
	case  41: return inf_ibss_dfs(pkt, id);
	case  42: return inf_erp(pkt, id);
	case  43: return inf_ts_del(pkt, id);
	case  44: return inf_tclas_proc(pkt, id);
	case  45: return inf_ht_cap(pkt, id);
	case  46: return inf_qos_cap(pkt, id);
	case  47: return inf_reserved(pkt, id);
	case  48: return inf_unimplemented(pkt, id);
	case  49: return inf_unimplemented(pkt, id);
	case  50: return inf_ext_supp_rates(pkt, id);
	case  51: return inf_unimplemented(pkt, id);
	case  52: return inf_unimplemented(pkt, id);
	case  53: return inf_unimplemented(pkt, id);
	case  54: return inf_unimplemented(pkt, id);
	case  55: return inf_unimplemented(pkt, id);
	case  56: return inf_unimplemented(pkt, id);
	case  57: return inf_unimplemented(pkt, id);
	case  58: return inf_unimplemented(pkt, id);
	case  59: return inf_unimplemented(pkt, id);
	case  60: return inf_unimplemented(pkt, id);
	case  61: return inf_unimplemented(pkt, id);
	case  62: return inf_unimplemented(pkt, id);
	case  63: return inf_unimplemented(pkt, id);
	case  64: return inf_unimplemented(pkt, id);
	case  65: return inf_unimplemented(pkt, id);
	case  66: return inf_unimplemented(pkt, id);
	case  67: return inf_unimplemented(pkt, id);
	case  68: return inf_unimplemented(pkt, id);
	case  69: return inf_unimplemented(pkt, id);
	case  70: return inf_unimplemented(pkt, id);
	case  71: return inf_unimplemented(pkt, id);
	case  72: return inf_unimplemented(pkt, id);
	case  73: return inf_unimplemented(pkt, id);
	case  74: return inf_unimplemented(pkt, id);
	case  75: return inf_unimplemented(pkt, id);
	case  76: return inf_unimplemented(pkt, id);
	case  78: return inf_unimplemented(pkt, id);
	case  79: return inf_unimplemented(pkt, id);
	case  80: return inf_unimplemented(pkt, id);
	case  81: return inf_unimplemented(pkt, id);
	case  82: return inf_unimplemented(pkt, id);
	case  83: return inf_unimplemented(pkt, id);
	case  84: return inf_unimplemented(pkt, id);
	case  85: return inf_unimplemented(pkt, id);
	case  86: return inf_unimplemented(pkt, id);
	case  87: return inf_unimplemented(pkt, id);
	case  88: return inf_unimplemented(pkt, id);
	case  89: return inf_unimplemented(pkt, id);
	case  90: return inf_unimplemented(pkt, id);
	case  91: return inf_unimplemented(pkt, id);
	case  92: return inf_unimplemented(pkt, id);
	case  93: return inf_unimplemented(pkt, id);
	case  94: return inf_unimplemented(pkt, id);
	case  95: return inf_unimplemented(pkt, id);
	case  96: return inf_unimplemented(pkt, id);
	case  97: return inf_unimplemented(pkt, id);
	case  98: return inf_unimplemented(pkt, id);
	case  99: return inf_unimplemented(pkt, id);
	case 100: return inf_unimplemented(pkt, id);
	case 101: return inf_unimplemented(pkt, id);
	case 102: return inf_unimplemented(pkt, id);
	case 104: return inf_unimplemented(pkt, id);
	case 105: return inf_unimplemented(pkt, id);
	case 106: return inf_unimplemented(pkt, id);
	case 107: return inf_unimplemented(pkt, id);
	case 108: return inf_unimplemented(pkt, id);
	case 109: return inf_unimplemented(pkt, id);
	case 110: return inf_unimplemented(pkt, id);
	case 111: return inf_unimplemented(pkt, id);
	case 112: return inf_unimplemented(pkt, id);
	case 113: return inf_unimplemented(pkt, id);
	case 114: return inf_unimplemented(pkt, id);
	case 115: return inf_unimplemented(pkt, id);
	case 116: return inf_unimplemented(pkt, id);
	case 117: return inf_unimplemented(pkt, id);
	case 118: return inf_unimplemented(pkt, id);
	case 119: return inf_unimplemented(pkt, id);
	case 120: return inf_unimplemented(pkt, id);
	case 121: return inf_unimplemented(pkt, id);
	case 122: return inf_unimplemented(pkt, id);
	case 123: return inf_unimplemented(pkt, id);
	case 124: return inf_unimplemented(pkt, id);
	case 125: return inf_unimplemented(pkt, id);
	case 126: return inf_unimplemented(pkt, id);
	case 127: return inf_unimplemented(pkt, id);
	case 128: return inf_reserved(pkt, id);
	case 129: return inf_reserved(pkt, id);
	case 130: return inf_unimplemented(pkt, id);
	case 131: return inf_unimplemented(pkt, id);
	case 132: return inf_unimplemented(pkt, id);
	case 133: return inf_reserved(pkt, id);
	case 134: return inf_reserved(pkt, id);
	case 135: return inf_reserved(pkt, id);
	case 136: return inf_reserved(pkt, id);
	case 137: return inf_unimplemented(pkt, id);
	case 138: return inf_unimplemented(pkt, id);
	case 139: return inf_unimplemented(pkt, id);
	case 140: return inf_unimplemented(pkt, id);
	case 141: return inf_unimplemented(pkt, id);
	case 142: return inf_unimplemented(pkt, id);
	case 143 ... 173: return inf_reserved(pkt, id);
	case 174: return inf_unimplemented(pkt, id);
	case 221: return inf_vend_spec(pkt, id);
	}

	return 0;
}

#define	ESS		0x0001
#define	IBSS		0x0002
#define	CF_Pollable	0x0004
#define	CF_Poll_Req	0x0008
#define	Privacy		0x0010
#define	Short_Pre	0x0020
#define	PBCC		0x0040
#define	Ch_Agility	0x0080
#define	Spec_Mgmt	0x0100
#define	QoS		0x0200
#define	Short_Slot_t	0x0400
#define	APSD		0x0800
#define	Radio_Meas	0x1000
#define	DSSS_OFDM	0x2000
#define	Del_Block_ACK	0x4000
#define	Imm_Block_ACK	0x8000

static int8_t cap_field(u16 cap_inf)
{
	if (ESS & cap_inf)
		tprintf(" ESS;");
	if (IBSS & cap_inf)
		tprintf(" IBSS;");
	if (CF_Pollable & cap_inf)
		tprintf(" CF Pollable;");
	if (CF_Poll_Req & cap_inf)
		tprintf(" CF-Poll Request;");
	if (Privacy & cap_inf)
		tprintf(" Privacy;");
	if (Short_Pre & cap_inf)
		tprintf(" Short Preamble;");
	if (PBCC & cap_inf)
		tprintf(" PBCC;");
	if (Ch_Agility & cap_inf)
		tprintf(" Channel Agility;");
	if (Spec_Mgmt & cap_inf)
		tprintf(" Spectrum Management;");
	if (QoS & cap_inf)
		tprintf(" QoS;");
	if (Short_Slot_t & cap_inf)
		tprintf(" Short Slot Time;");
	if (APSD & cap_inf)
		tprintf(" APSD;");
	if (Radio_Meas & cap_inf)
		tprintf(" Radio Measurement;");
	if (DSSS_OFDM & cap_inf)
		tprintf(" DSSS-OFDM;");
	if (Del_Block_ACK & cap_inf)
		tprintf(" Delayed Block Ack;");
	if (Imm_Block_ACK & cap_inf)
		tprintf(" Immediate Block Ack;");
	
	return 1;
}

static void print_inf_elements(struct pkt_buff *pkt)
{
	if (pkt_len(pkt)) {
		do {
			if (pkt_len(pkt))
				tprintf("\n\tIE:");

		} while (inf_elements(pkt));
	}
}

/* Management Dissectors */
static int8_t mgmt_beacon_dissect(struct pkt_buff *pkt)
{
	struct ieee80211_mgmt_beacon *beacon;

	beacon = (struct ieee80211_mgmt_beacon *)
			pkt_pull(pkt, sizeof(*beacon));
	if (beacon == NULL)
		return 0;

	tprintf("Timestamp 0x%.16"PRIx64", ", le64_to_cpu(beacon->timestamp));
	tprintf("Beacon Interval (%fs), ", le16_to_cpu(beacon->beacon_int)*TU);
	tprintf("Capabilities (0x%x <->", le16_to_cpu(beacon->capab_info));
	cap_field(le16_to_cpu(beacon->capab_info));
	tprintf(")");

	print_inf_elements(pkt);

	if (pkt_len(pkt))
		return 0;

	return 1;
}

static int8_t mgmt_probe_request_dissect(struct pkt_buff *pkt)
{
	print_inf_elements(pkt);

	if (pkt_len(pkt))
		return 0;

	return 1;
}

static int8_t mgmt_unimplemented(struct pkt_buff *pkt __maybe_unused)
{
	return 0;
}
/* End Management Dissectors */

/* Control Dissectors */
static int8_t ctrl_unimplemented(struct pkt_buff *pkt __maybe_unused)
{
	return 0;
}
/* End Control Dissectors */

/* Data Dissectors */
static int8_t data_unimplemented(struct pkt_buff *pkt __maybe_unused)
{
	return 0;
}
/* End Data Dissectors */

static const char *mgt_sub(u8 subtype, struct pkt_buff *pkt,
			   int8_t (**get_content)(struct pkt_buff *pkt))
{
	u16 seq_ctrl;
	struct ieee80211_mgmt *mgmt;
	const char *dst, *src, *bssid;

	mgmt = (struct ieee80211_mgmt *) pkt_pull(pkt, sizeof(*mgmt));
	if (!mgmt)
		return NULL;

	dst = lookup_vendor((mgmt->da[0] << 16) |
			    (mgmt->da[1] <<  8) |
			     mgmt->da[2]);
	src = lookup_vendor((mgmt->sa[0] << 16) |
			    (mgmt->sa[1] <<  8) |
			     mgmt->sa[2]);

	bssid = lookup_vendor((mgmt->bssid[0] << 16) |
			      (mgmt->bssid[1] <<  8) |
			       mgmt->bssid[2]);
	seq_ctrl = le16_to_cpu(mgmt->seq_ctrl);

	tprintf("Duration (%u),", le16_to_cpu(mgmt->duration));
	tprintf("\n\tDestination (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
		mgmt->da[0], mgmt->da[1], mgmt->da[2],
		mgmt->da[3], mgmt->da[4], mgmt->da[5]);
	if (dst) {
		tprintf("=> (%s:%.2x:%.2x:%.2x)", dst,
			mgmt->da[3], mgmt->da[4], mgmt->da[5]);
	}

	tprintf("\n\tSource (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
		mgmt->sa[0], mgmt->sa[1], mgmt->sa[2],
		mgmt->sa[3], mgmt->sa[4], mgmt->sa[5]);
	if (src) {
		tprintf("=> (%s:%.2x:%.2x:%.2x)", src,
			mgmt->sa[3], mgmt->sa[4], mgmt->sa[5]);
	}

	tprintf("\n\tBSSID (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
		mgmt->bssid[0], mgmt->bssid[1], mgmt->bssid[2],
		mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5]);
	if(bssid) {
		tprintf("=> (%s:%.2x:%.2x:%.2x)", bssid,
			mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5]);
	}

	tprintf("\n\tFragmentnr. (%u), Seqnr. (%u). ",
		seq_ctrl & 0xf, seq_ctrl >> 4);

	switch (subtype) {
	case 0x0:
		*get_content = mgmt_unimplemented;
		return "Association Request";
	case 0x1:
		*get_content = mgmt_unimplemented;
		return "Association Response";
	case 0x2:
		*get_content = mgmt_unimplemented;
		return "Reassociation Request";
	case 0x3:
		*get_content = mgmt_unimplemented;
		return "Reassociation Response";
	case 0x4:
		*get_content = mgmt_probe_request_dissect;
		return "Probe Request";
	case 0x5:
		/* Probe Response is very similar to Beacon except some IEs */
		*get_content = mgmt_beacon_dissect;
		return "Probe Response";
	case 0x8:
		*get_content = mgmt_beacon_dissect;
		return "Beacon";
	case 0x9:
		*get_content = mgmt_unimplemented;
		return "ATIM";
	case 0xA:
		*get_content = mgmt_unimplemented;
		return "Disassociation";
	case 0xB:
		*get_content = mgmt_unimplemented;
		return "Authentication";
	case 0xC:
		*get_content = mgmt_unimplemented;
		return "Deauthentication";
	default:
		*get_content = NULL;
		return "Reserved";
	}
}

static const char *ctrl_sub(u8 subtype, struct pkt_buff *pkt __maybe_unused,
			    int8_t (**get_content)(struct pkt_buff *pkt))
{
	switch (subtype) {
	case 0xA:
		*get_content = ctrl_unimplemented;
		return "PS-Poll";
	case 0xB:
		*get_content = ctrl_unimplemented;
		return "RTS";
	case 0xC:
		*get_content = ctrl_unimplemented;
		return "CTS";
	case 0xD:
		*get_content = ctrl_unimplemented;
		return "ACK";
	case 0xE:
		*get_content = ctrl_unimplemented;
		return "CF End";
	case 0xF:
		*get_content = ctrl_unimplemented;
		return "CF End + CF-ACK";
	default:
		*get_content = NULL;
		return "Reserved";
	}
}

static const char *data_sub(u8 subtype, struct pkt_buff *pkt __maybe_unused,
		 	    int8_t (**get_content)(struct pkt_buff *pkt))
{
	switch (subtype) {
	case 0x0:
		*get_content = data_unimplemented;
		return "Data";
	case 0x1:
		*get_content = data_unimplemented;
		return "Data + CF-ACK";
	case 0x2:
		*get_content = data_unimplemented;
		return "Data + CF-Poll";
	case 0x3:
		*get_content = data_unimplemented;
		return "Data + CF-ACK + CF-Poll";
	case 0x4:
		*get_content = data_unimplemented;
		return "Null";
	case 0x5:
		*get_content = data_unimplemented;
		return "CF-ACK";
	case 0x6:
		*get_content = data_unimplemented;
		return "CF-Poll";
	case 0x7:
		*get_content = data_unimplemented;
		return "CF-ACK + CF-Poll";
	default:
		*get_content = NULL;
		return "Reserved";
	}
}

static const char *
frame_control_type(u8 type, const char *(**get_subtype)(u8 subtype,
		   struct pkt_buff *pkt, int8_t (**get_content)(struct pkt_buff *pkt)))
{
	switch (type) {
	case 0x0:
		*get_subtype = mgt_sub;
		return "Management";
	case 0x1:
		*get_subtype = ctrl_sub;
		return "Control";
	case 0x2:
		*get_subtype = data_sub;
		return "Data";
	case 0x3:
		*get_subtype = NULL;
		return "Reserved";
	default:
		*get_subtype = NULL;
		return "Control Type unknown";
	}
}

static void ieee80211(struct pkt_buff *pkt)
{
	int8_t (*get_content)(struct pkt_buff *pkt) = NULL;
	const char *(*get_subtype)(u8 subtype, struct pkt_buff *pkt,
		int8_t (**get_content)(struct pkt_buff *pkt)) = NULL;
	const char *subtype = NULL;
	struct ieee80211_frm_ctrl *frm_ctrl;

	if (pkt->link_type == LINKTYPE_IEEE802_11_RADIOTAP) {
		struct ieee80211_radiotap_header *rtap;

		rtap = (struct ieee80211_radiotap_header *)pkt_pull(pkt,
				sizeof(*rtap));
		if (rtap == NULL)
			return;

		tprintf(" [ Radiotap ");
		tprintf("Version (%u), ", rtap->version);
		tprintf("Length (%u), ", le16_to_cpu(rtap->len));
		tprintf("Flags (0x%08x) ]\n", le32_to_cpu(rtap->present));

		pkt_pull(pkt, le16_to_cpu(rtap->len) - sizeof(*rtap));
	}

	frm_ctrl = (struct ieee80211_frm_ctrl *)pkt_pull(pkt, sizeof(*frm_ctrl));
	if (frm_ctrl == NULL)
		return;

	tprintf(" [ 802.11 Frame Control (0x%04x)]\n",
		le16_to_cpu(frm_ctrl->frame_control));

	tprintf(" [ Proto Version (%u), ", frm_ctrl->proto_version);
	tprintf("Type (%u, %s), ", frm_ctrl->type,
		frame_control_type(frm_ctrl->type, &get_subtype));
	if (get_subtype) {
		subtype = (*get_subtype)(frm_ctrl->subtype, pkt, &get_content);
		tprintf("Subtype (%u, %s)", frm_ctrl->subtype, subtype);
	} else {
		tprintf("%s%s%s", colorize_start_full(black, red),
			"No SubType Data available", colorize_end());
	}

	tprintf("%s%s", frm_ctrl->to_ds ? ", Frame goes to DS" : "",
		frm_ctrl->from_ds ?  ", Frame comes from DS" : "");
	tprintf("%s", frm_ctrl->more_frags ? ", More Fragments" : "");
	tprintf("%s", frm_ctrl->retry ? ", Frame is retransmitted" : "");
	tprintf("%s", frm_ctrl->power_mgmt ? ", In Power Saving Mode" : "");
	tprintf("%s", frm_ctrl->more_data ? ", More Data" : "");
	tprintf("%s", frm_ctrl->wep ? ", Needs WEP" : "");
	tprintf("%s", frm_ctrl->order ? ", Order" : "");
	tprintf(" ]\n");

	if (get_content) {
		tprintf(" [ Subtype %s: ", subtype);
		if (!((*get_content) (pkt)))
			tprintf("%s%s%s", colorize_start_full(black, red),
				"Failed to dissect Subtype", colorize_end());
		tprintf(" ]");
	} else {
		tprintf("%s%s%s", colorize_start_full(black, red),
			"No SubType Data available", colorize_end());
	}

	tprintf("\n");

//	pkt_set_dissector(pkt, &ieee802_lay2, ntohs(eth->h_proto));
}

static void ieee80211_less(struct pkt_buff *pkt __maybe_unused)
{
	tprintf("802.11 frame (more on todo)");
}

struct protocol ieee80211_ops = {
	.key = 0,
	.print_full = ieee80211,
	.print_less = ieee80211_less,
};