summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-mausb.c
blob: d392396315af4de6756b5eeeecba3f56e7d918d6 (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
/* packet-mausb.c
 * Routines for Media Agnostic USB dissection
 * Copyright 2014, Intel Corporation
 * Author: Sean O. Stalley <sean.stalley@intel.com>
 *
 * Dedicated to Robert & Dorothy Stalley
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/oui.h>
#include "packet-tcp.h"
#include "packet-llc.h"
#include "packet-usb.h"
#include "packet-mausb.h"

void proto_reg_handoff_mausb(void);
void proto_register_mausb(void);

static dissector_handle_t mausb_tcp_handle;
static dissector_handle_t mausb_pkt_handle;

/* For SNAP Packets */
static int hf_llc_mausb_pid = -1;

/* Initialize the protocol and registered fields */
static int proto_mausb = -1;
static int hf_mausb_version = -1;
static int hf_mausb_flags = -1;
static int hf_mausb_flag_host = -1;
static int hf_mausb_flag_retry = -1;
static int hf_mausb_flag_timestamp = -1;
static int hf_mausb_flag_reserved = -1;


static int * const mausb_flag_fields[] = {
    &hf_mausb_flag_host,
    &hf_mausb_flag_retry,
    &hf_mausb_flag_timestamp,
    &hf_mausb_flag_reserved,
    NULL
};

static int hf_mausb_type = -1;
static int hf_mausb_length = -1;
static int hf_mausb_dev_handle = -1;
static int hf_mausb_ep_handle = -1;
static int hf_mausb_ep_handle_d = -1;
static int hf_mausb_ep_handle_ep_num = -1;
static int hf_mausb_ep_handle_dev_addr = -1;
static int hf_mausb_ep_handle_bus_num = -1;
static int hf_mausb_ma_dev_addr = -1;
static int hf_mausb_ssid = -1;
static int hf_mausb_status = -1;

/* management packet specific */
static int hf_mausb_token = -1;
static int hf_mausb_mgmt_pad = -1;
static int hf_mausb_mgmt_ep_handle_num = -1;
static int hf_mausb_mgmt_ep_handle_pad = -1;
static int hf_mausb_mgmt_ep_des_num = -1;
static int hf_mausb_mgmt_ep_des_size = -1;
static int hf_mausb_mgmt_ep_des_pad = -1;
static int hf_mausb_mgmt_type_spec = -1;
static int hf_mausb_mgmt_type_spec_generic = -1;

/* CapResp packet specific */
static int hf_mausb_cap_resp_num_ep = -1;
static int hf_mausb_cap_resp_num_dev = -1;
static int hf_mausb_cap_resp_num_stream = -1;
static int hf_mausb_cap_resp_dev_type = -1;
static int hf_mausb_cap_resp_desc_count = -1;
static int hf_mausb_cap_resp_desc_len = -1;
static int hf_mausb_cap_resp_transfer_req = -1;
static int hf_mausb_cap_resp_mgmt_req = -1;
static int hf_mausb_cap_resp_rsvd = -1;

static int hf_mausb_dev_cap_len = -1;
static int hf_mausb_dev_cap_type = -1;
static int hf_mausb_dev_cap_generic = -1;

/* EPHandleReq & Resp packet specific */
static int hf_mausb_ep_handle_req_pad = -1;
static int hf_mausb_ep_handle_resp_dir = -1;
static int hf_mausb_ep_handle_resp_iso = -1;
static int hf_mausb_ep_handle_resp_lman = -1;
static int hf_mausb_ep_handle_resp_valid = -1;
static int hf_mausb_ep_handle_resp_ccu = -1;
static int hf_mausb_ep_handle_resp_buf_size = -1;
static int hf_mausb_ep_handle_resp_iso_prog_dly = -1;
static int hf_mausb_ep_handle_resp_iso_resp_dly = -1;

/* (Clear/Cancel)TransferReq & Resp packet specific */
static int hf_mausb_clear_transfers_info_block = -1;
static int hf_mausb_clear_transfers_status_block = -1;
static int hf_mausb_cancel_transfer_rsvd = -1;
static int hf_mausb_clear_transfers_req_num = -1;
static int hf_mausb_clear_transfers_req_rsvd = -1;
static int hf_mausb_clear_transfers_resp_num = -1;
static int hf_mausb_clear_transfers_resp_rsvd = -1;
static int hf_mausb_cancel_transfer_status = -1;
static int hf_mausb_cancel_transfer_rsvd_2 = -1;
static int hf_mausb_clear_transfers_status = -1;
static int hf_mausb_clear_transfers_partial = -1;
static int hf_mausb_clear_transfers_start_req_id = -1;
static int hf_mausb_clear_transfers_last_req_id = -1;
static int hf_mausb_clear_transfers_req_block_rsvd = -1;
static int hf_mausb_clear_transfers_resp_block_rsvd = -1;
static int hf_mausb_cancel_transfer_seq_num = -1;
static int hf_mausb_cancel_transfer_byte_offset = -1;

/* data packet specific */
static int hf_mausb_eps = -1;
static int hf_mausb_eps_rsvd = -1;
static int hf_mausb_tflags = -1;
static int hf_mausb_tflag_arq = -1;
static int hf_mausb_tflag_neg = -1;
static int hf_mausb_tflag_eot = -1;
static int hf_mausb_tflag_type = -1;
static int hf_mausb_tflag_rsvd = -1;

static int * const mausb_tflag_fields[] = {
    &hf_mausb_tflag_arq,
    &hf_mausb_tflag_neg,
    &hf_mausb_tflag_eot,
    &hf_mausb_tflag_type,
    &hf_mausb_tflag_rsvd,
    NULL
};

static int hf_mausb_num_iso_hdr = -1;
static int hf_mausb_iflags = -1;
static int hf_mausb_iflag_mtd = -1;
static int hf_mausb_iflag_hdr_format = -1;
static int hf_mausb_iflag_asap = -1;

static int * const mausb_iflag_fields[] = {
    &hf_mausb_iflag_mtd,
    &hf_mausb_iflag_hdr_format,
    &hf_mausb_iflag_asap,
    NULL
};

static int hf_mausb_stream_id = -1;
static int hf_mausb_seq_num = -1;
static int hf_mausb_req_id = -1;
static int hf_mausb_present_time = -1;
static int hf_mausb_uframe = -1;
static int hf_mausb_frame = -1;
static int hf_mausb_num_segs = -1;

static int hf_mausb_timestamp = -1;
static int hf_mausb_delta = -1;
static int hf_mausb_nom_interval = -1;



static int hf_mausb_mtd = -1;
static int hf_mausb_rem_size_credit = -1;

/* expert info fields */
static expert_field ei_ep_handle_len = EI_INIT;
static expert_field ei_len = EI_INIT;
static expert_field ei_mgmt_type_undef = EI_INIT;
static expert_field ei_mgmt_type_spec_len_long = EI_INIT;
static expert_field ei_mgmt_type_spec_len_short = EI_INIT;
static expert_field ei_dev_cap_len = EI_INIT;
static expert_field ei_dev_cap_resp_desc_len = EI_INIT;
static expert_field ei_cap_resp_desc_len = EI_INIT;

/* MAUSB Version, per 6.2.1.1 */
#define MAUSB_VERSION_1_0     0x0
#define MAUSB_VERSION_MASK    0x0F

/* for dissecting snap packets */
/*
 * TODO: determine assigned PID value
 * (yet to be assigned as of Earth Day 2014)
 */
#define PID_MAUSB 0x1500

static const value_string mausb_pid_string[] = {
    { PID_MAUSB, "MAUSB" },
    { 0, NULL}
};

static const value_string mausb_version_string[] = {
    { MAUSB_VERSION_1_0, "MAUSB protocol version 1.0" },
    { 0, NULL}
};

/* Packet flags, per 6.2.1.2 */
#define MAUSB_FLAG_MASK       0xF0
#define MAUSB_FLAG_HOST       (1 << 0)
#define MAUSB_FLAG_RETRY      (1 << 1)
#define MAUSB_FLAG_TIMESTAMP  (1 << 2)
#define MAUSB_FLAG_RESERVED   (1 << 3)
#define MAUSB_FLAG_OFFSET     4

/* Packet Types, per 6.2.1.3 */
#define MAUSB_PKT_TYPE_MASK       0xC0
#define MAUSB_PKT_TYPE_MGMT       (0 << 6)
#define MAUSB_PKT_TYPE_CTRL       (1 << 6)
#define MAUSB_PKT_TYPE_DATA       (2 << 6)

/* Packet Subtypes, per 6.2.1.3 */
#define MAUSB_SUBTYPE_MASK        0x3F

enum mausb_pkt_type {
    /* Management packets */
    CapReq = 0x00 | MAUSB_PKT_TYPE_MGMT,
    CapResp               ,
    USBDevHandleReq       ,
    USBDevHandleResp      ,
    EPHandleReq           ,
    EPHandleResp          ,
    EPActivateReq         ,
    EPActivateResp        ,
    EPInactivateReq       ,
    EPInactivateResp      ,
    EPResetReq            ,
    EPResetResp           ,
    ClearTransfersReq     ,
    ClearTransfersResp    ,
    EPHandleDeleteReq     ,
    EPHandleDeleteResp    ,

    DevResetReq           ,
    DevResetResp          ,
    ModifyEP0Req          ,
    ModifyEP0Resp         ,
    SetUSBDevAddrReq      ,
    SetUSBDevAddrResp     ,
    UpdateDevReq          ,
    UpdateDevResp         ,
    USBDevDisconnectReq   ,
    USBDevDisconnectResp  ,
    USBSuspendReq         ,
    USBSuspendResp        ,
    USBResumeReq          ,
    USBResumeResp         ,
    RemoteWakeReq         ,
    RemoteWakeResp        ,

    PingReq               ,
    PingResp              ,
    DevDisconnectReq      ,
    DevDisconnectResp     ,
    DevInitDisconnectReq  ,
    DevInitDisconnectResp ,
    SynchReq              ,
    SynchResp             ,
    CancelTransferReq     ,
    CancelTransferResp    ,
    EPOpenStreamReq       ,
    EPOpenStreamResp      ,
    EPCloseStreamReq      ,
    EPCloseStreamResp     ,
    USBDevResetReq        ,
    USBDevResetResp       ,

    DevNotificationReq    ,
    DevNotificationResp   ,
    EPSetKeepAliveReq     ,
    EPSetKeepAliveResp    ,
    GetPortBWReq          ,
    GetPortBWResp         ,
    SleepReq              ,
    SleepResp             ,
    WakeReq               ,
    WakeResp              ,

    /* Vendor-Specific Management Packets */
    VendorSpecificReq = 0x3E | MAUSB_PKT_TYPE_MGMT,
    VendorSpecificResp    ,

    /* Control Packets */
    TransferSetupReq = 0x00 | MAUSB_PKT_TYPE_CTRL,
    TransferSetupResp     ,
    TransferTearDownConf  ,

    /* Data Packets */
    TransferReq = 0x00 | MAUSB_PKT_TYPE_DATA,
    TransferResp          ,
    TransferAck           ,
    IsochTransferReq      ,
    IsochTransferResp
};


/**
 * Type & Subtype values for MAUSB packet variants, per 6.2.1.3, Table 5
 */
static const value_string mausb_type_string[] = {
    /* Management packets */
    { CapReq               , "CapReq" },
    { CapResp              , "CapResp" },
    { USBDevHandleReq      , "USBDevHandleReq" },
    { USBDevHandleResp     , "USBDevHandleResp" },
    { EPHandleReq          , "EPHandleReq" },
    { EPHandleResp         , "EPHandleResp" },
    { EPActivateReq        , "EPActivateReq" },
    { EPActivateResp       , "EPActivateResp" },
    { EPInactivateReq      , "EPInactivateReq" },
    { EPInactivateResp     , "EPInactivateResp" },
    { EPResetReq           , "EPResetReq" },
    { EPResetResp          , "EPResetResp" },
    { ClearTransfersReq    , "ClearTransfersReq" },
    { ClearTransfersResp   , "ClearTransfersResp" },
    { EPHandleDeleteReq    , "EPHandleDeleteReq" },
    { EPHandleDeleteResp   , "EPHandleDeleteResp" },

    { DevResetReq          , "DevResetReq" },
    { DevResetResp         , "DevResetResp" },
    { ModifyEP0Req         , "ModifyEP0Req" },
    { ModifyEP0Resp        , "ModifyEP0Resp" },
    { SetUSBDevAddrReq     , "SetUSBDevAddrReq" },
    { SetUSBDevAddrResp    , "SetUSBDevAddrResp" },
    { UpdateDevReq         , "UpdateDevReq" },
    { UpdateDevResp        , "UpdateDevResp" },
    { USBDevDisconnectReq  , "USBDevDisconnectReq" },
    { USBDevDisconnectResp , "USBDevDisconnectResp" },
    { USBSuspendReq        , "USBSuspendReq" },
    { USBSuspendResp       , "USBSuspendResp" },
    { USBResumeReq         , "USBResumeReq" },
    { USBResumeResp        , "USBResumeResp" },
    { RemoteWakeReq        , "RemoteWakeReq" },
    { RemoteWakeResp       , "RemoteWakeResp" },

    { PingReq              , "PingReq" },
    { PingResp             , "PingResp" },
    { DevDisconnectReq     , "DevDisconnectReq " },
    { DevDisconnectResp    , "DevDisconnectResp" },
    { DevInitDisconnectReq , "DevInitDisconnectReq" },
    { DevInitDisconnectResp, "DevInitDisconnectResp" },
    { SynchReq             , "SynchReq" },
    { SynchResp            , "SynchResp" },
    { CancelTransferReq    , "CancelTransferReq" },
    { CancelTransferResp   , "CancelTransferResp" },
    { EPOpenStreamReq      , "EPOpenStreamReq" },
    { EPOpenStreamResp     , "EPOpenStreamResp" },
    { EPCloseStreamReq     , "EPCloseStreamReq" },
    { EPCloseStreamResp    , "EPCloseStreamResp" },
    { USBDevResetReq       , "USBDevResetReq" },
    { USBDevResetResp      , "USBDevResetResp" },

    { DevNotificationReq   , "DevNotificationReq" },
    { DevNotificationResp  , "DevNotificationResp" },
    { EPSetKeepAliveReq    , "EPSetKeepAliveReq" },
    { EPSetKeepAliveResp   , "EPSetKeepAliveResp" },
    { GetPortBWReq         , "GetPortBWReq" },
    { GetPortBWResp        , "GetPortBWResp" },
    { SleepReq             , "SleepReq" },
    { SleepResp            , "SleepResp" },
    { WakeReq              , "WakeReq" },
    { WakeResp             , "WakeResp" },

    /* Vendor-Specific Management Packets */
    { VendorSpecificReq    , "VendorSpecificReq" },
    { VendorSpecificResp   , "VendorSpecificResp" },

    /* Control Packets */
    { TransferSetupReq     , "TransferSetupReq" },
    { TransferSetupResp    , "TransferSetupResp" },
    { TransferTearDownConf , "TransferTearDownConf" },

    /* Data Packets */
    { TransferReq          , "TransferReq" },
    { TransferResp         , "TransferResp" },
    { TransferAck          , "TransferAck" },
    { IsochTransferReq     , "IsochTransferReq" },
    { IsochTransferResp    , "IsochTransferResp" },
    { 0, NULL}
};

#define MAUSB_EP_HANDLE_D        0x0001
#define MAUSB_EP_HANDLE_EP_NUM   0x001e
#define MAUSB_EP_HANDLE_DEV_ADDR 0x0fe0
#define MAUSB_EP_HANDLE_BUS_NUM  0xf000

#define MAUSB_EP_HANDLE_D_OFFSET        0
#define MAUSB_EP_HANDLE_EP_NUM_OFFSET   1
#define MAUSB_EP_HANDLE_DEV_ADDR_OFFSET 5
#define MAUSB_EP_HANDLE_BUS_NUM_OFFSET  12

static const value_string mausb_status_string[] = {
    {   0, "SUCCESS (NO_ERROR)" },
    { 128, "UNSUCCESSFUL" },
    { 129, "INVALID_MA_USB_SESSION_STATE" },
    { 130, "INVALID_DEVICE_HANDLE" },
    { 131, "INVALID_EP_HANDLE" },
    { 132, "INVALID_EP_HANDLE_STATE" },
    { 133, "INVALID_REQUEST" },
    { 134, "MISSING_SEQUENCE_NUMBER" },
    { 135, "TRANSFER_PENDING" },
    { 136, "TRANSFER_EP_STALL" },
    { 137, "TRANSFER_SIZE_ERROR" },
    { 138, "TRANSFER_DATA_BUFFER_ERROR" },
    { 139, "TRANSFER_BABBLE_DETECTED" },
    { 140, "TRANSFER_TRANSACTION_ERROR" },
    { 141, "TRANSFER_SHORT_TRANSFER" },
    { 142, "TRANSFER_CANCELLED" },
    { 143, "INSUFFICIENT_RESOURCES" },
    { 144, "NOT_SUFFICIENT_BANDWIDTH" },
    { 145, "INTERNAL_ERROR" },
    { 146, "DATA_OVERRUN" },
    { 147, "DEVICE_NOT_ACCESSED" },
    { 148, "BUFFER_OVERRUN" },
    { 149, "BUSY" },
    { 150, "DROPPED_PACKET" },
    { 151, "ISOC_TIME_EXPIRED" },
    { 152, "ISOCH_TIME_INVALID" },
    { 153, "NO_USB_PING_RESPONSE" },
    { 154, "NOT_SUPPORTED" },
    { 155, "REQUEST_DENIED" },
    { 156, "MISSING_REQUEST_ID" },
    { 0, NULL}
};


/* Nuber of Isochronous Headers, per 6.5.1.7 */
#define MAUSB_NUM_ISO_HDR_MASK 0x0fff

/* I-Flags, per 6.5.1.8 */
#define MAUSB_IFLAG_ASAP       (1 << 0)
#define MAUSB_IFLAG_HDR_FORMAT (3 << 1)
#define MAUSB_IFLAG_MTD        (1 << 3)
#define MAUSB_IFLAG_OFFSET     12
#define MAUSB_IFLAG_MASK       (0xF << MAUSB_IFLAG_OFFSET)

/* Presentation Time, per 6.5.1.9 */
#define MAUSB_PRESENT_TIME_MASK 0x000fffff
#define MAUSB_UFRAME_MASK       0x00000007
#define MAUSB_FRAME_MASK        0x000ffff8

/* Number of Segments, per 6.5.1.10 */
#define MAUSB_NUM_SEGS_MASK     0xfff00000

/* MA USB Global Time fields, per 6.6.1 */
#define MAUSB_DELTA_MASK        0x00000fff
#define MAUSB_INTERVAL_MASK     0xfffff000



#define MAUSB_TOKEN_MASK  0x03ff
#define MAUSB_MGMT_PAD_MASK  0xfffc
#define MAUSB_MGMT_NUM_EP_DES_MASK 0x1f
#define MAUSB_MGMT_SIZE_EP_DES_OFFSET 5
#define MAUSB_MGMT_SIZE_EP_DES_MASK (0x003f << MAUSB_MGMT_SIZE_EP_DES_OFFSET)

#define MAUSB_MGMT_CLEAR_TRANSFER_RESP_NUM_MASK 0x1f

/* CapResp Bitfield Masks */
#define MAUSB_CAP_RESP_NUM_STREAM_MASK 0x1f
#define MAUSB_CAP_RESP_DEV_TYPE_OFFSET 5
#define MAUSB_CAP_RESP_DEV_TYPE_MASK (0x07 << MAUSB_CAP_RESP_DEV_TYPE_OFFSET)
#define MAUSB_CAP_RESP_MGMT_REQ_MASK 0x0fff
#define MAUSB_CAP_RESP_RSVD_MASK 0xf000

static const value_string mausb_cap_resp_dev_type[] = {
    { 0, "Integrated Device" },
    { 1, "MAUSB 2.0 hub" },
    { 2, "MAUSB 3.1 hub" },
    { 0, NULL}
};

static const value_string mausb_dev_cap_string[] = {
    { 0, "Speed Capability" },
    { 1, "P-managed OUT Capabilities" },
    { 2, "Isochronous Capabilities" },
    { 3, "Synchronization Capabilities" },
    { 4, "Container ID Capability" },
    { 5, "Link Sleep Capability" },
    { 0, NULL}
};

enum mausb_dev_cap_type {
    SpeedCap = 0,
    PmanCap,
    IsoCap,
    SyncCap,
    ContainerIDCap,
    LinkSleepCap
};

#define DWORD_MASK 0xffffffff
#define MAUSB_MGMT_NUM_EP_HANDLE_PAD_MASK \
            (DWORD_MASK & !(MAUSB_MGMT_NUM_EP_DES_MASK))
#define MAUSB_MGMT_EP_DES_PAD_MASK \
            ((DWORD_MASK & !(MAUSB_MGMT_NUM_EP_DES_MASK | \
                           MAUSB_MGMT_SIZE_EP_DES_MASK)) >> 8)


/* EPHandleResp Bitfield Masks */
#define MAUSB_EP_HANDLE_RESP_DIR_MASK   (1 << 0)
#define MAUSB_EP_HANDLE_RESP_ISO_MASK   (1 << 1)
#define MAUSB_EP_HANDLE_RESP_LMAN_MASK  (1 << 2)
#define MAUSB_EP_HANDLE_RESP_VALID_MASK (1 << 3)

static const value_string mausb_eps_string[] = {
    { 0, "Unassigned" },
    { 1, "Active" },
    { 2, "Inactive" },
    { 3, "Halted" },
    { 0, NULL}
};

#define MAUSB_EPS_MASK 0x03

#define MAUSB_TFLAG_MASK   0xfc

#define MAUSB_TX_TYPE_CTRL (0 << 3)
#define MAUSB_TX_TYPE_ISOC (1 << 3)
#define MAUSB_TX_TYPE_BULK (2 << 3)
#define MAUSB_TX_TYPE_INTR (3 << 3)

#define MAUSB_TFLAG_OFFSET     2
#define MAUSB_TFLAG_ARQ  (1 << 0)
#define MAUSB_TFLAG_NEG  (1 << 1)
#define MAUSB_TFLAG_EOT  (1 << 2)
#define MAUSB_TFLAG_TRANSFER_TYPE (3 << 3)
#define MAUSB_TFLAG_RSVD (1 << 5)

static const value_string mausb_transfer_type_string[] = {
    { 0, "Control" },
    { 1, "Isochronous" },
    { 2, "Bulk" },
    { 3, "Interrupt" },
    { 0, NULL}
};

static const true_false_string tfs_ep_handle_resp_dir = { "IN", "OUT or Control" };

#define MAUSB_TRANSFER_TYPE_OFFSET 3 /* Offset from start of TFlags Field */
                                     /* (EPS not included) */
#define MAUSB_TRANSFER_TYPE_CTRL      (0 << MAUSB_TRANSFER_TYPE_OFFSET)
#define MAUSB_TRANSFER_TYPE_ISO       (1 << MAUSB_TRANSFER_TYPE_OFFSET)
#define MAUSB_TRANSFER_TYPE_BULK      (2 << MAUSB_TRANSFER_TYPE_OFFSET)
#define MAUSB_TRANSFER_TYPE_INTERRUPT (3 << MAUSB_TRANSFER_TYPE_OFFSET)

static const value_string mausb_cancel_transfer_status_string[] = {
    { 0, "Cancel Unsuccessful"},
    { 1, "Canceled before any data was moved"},
    { 2, "Canceled after some data was moved"},
    { 3, "Transfer completed"},
    { 4, "Transfer not yet received"},
    { 5, "Transfer cleared without any data moved"},
    { 0, NULL}
};

#define MAUSB_CANCEL_TRANSFER_STATUS_MASK 0x07

#define MAUSB_CLEAR_TRANSFERS_RESP_NUM_MASK 0x1f
#define MAUSB_CLEAR_TRANSFERS_STATUS_MASK 0x01
#define MAUSB_CLEAR_TRANSFERS_PARTIAL_MASK 0x02
#define MAUSB_CLEAR_TRANSFERS_RESP_BLOCK_RSVD_MASK 0xfffffffc


/* We need at least the first DWORD to determine the packet length (for TCP) */
#define MAUSB_MIN_LENGTH 4

#define MAUSB_MIN_MGMT_LENGTH 12
#define MAUSB_MIN_DATA_LENGTH 20
#define MAUSB_COMMON_LEN 9


/*** Packet parsing helper functions ***/

gboolean mausb_is_from_host(struct mausb_header *header)
{
    return (MAUSB_FLAG_HOST << MAUSB_FLAG_OFFSET) & header->ver_flags;
}

static gboolean mausb_is_mgmt_pkt(struct mausb_header *header)
{
    return MAUSB_PKT_TYPE_MGMT == (header->type & MAUSB_PKT_TYPE_MASK);
}

static gboolean mausb_is_data_pkt(struct mausb_header *header)
{
    return MAUSB_PKT_TYPE_DATA == (header->type & MAUSB_PKT_TYPE_MASK);
}

static gboolean mausb_is_transfer_req(struct mausb_header *header)
{
    return TransferReq == header->type;
}

static gboolean mausb_is_transfer_ack(struct mausb_header *header)
{
    return TransferAck == header->type;
}

static gint8 mausb_tx_type(struct mausb_header *header)
{
    return (header->u.s.eps_tflags >> MAUSB_TFLAG_OFFSET) & MAUSB_TFLAG_TRANSFER_TYPE;
}

static gboolean mausb_is_iso_pkt(struct mausb_header *header)
{
    return MAUSB_TX_TYPE_ISOC == mausb_tx_type(header);
}

static gboolean mausb_has_timestamp(struct mausb_header *header)
{
    return (MAUSB_FLAG_TIMESTAMP << MAUSB_FLAG_OFFSET) & header->ver_flags;
}

static gboolean mausb_has_mtd(struct mausb_header *header)
{
    return (MAUSB_IFLAG_MTD << MAUSB_IFLAG_OFFSET) & header->u.s.u1.num_headers_iflags;
}

static gboolean mausb_has_setup_data(struct mausb_header *header)
{
    if ((TransferReq == header->type ) &&
        (mausb_is_from_host(header)) &&
        (0 == header->u.s.seq_num) &&
        (MAUSB_TX_TYPE_CTRL == mausb_tx_type(header))) {

        return TRUE;
    }
    return FALSE;
}

static gboolean mausb_is_setup_response(struct mausb_header *header)
{
    if ((TransferResp == header->type) &&
        (!mausb_is_from_host(header)) &&
        (MAUSB_TX_TYPE_CTRL == mausb_tx_type(header))) {

        return TRUE;
    }
    return FALSE;
}

/*** EP Handle parsing helper functions */

guint8 mausb_ep_handle_ep_num(guint16 handle) {
    return (handle & MAUSB_EP_HANDLE_EP_NUM) >> MAUSB_EP_HANDLE_EP_NUM_OFFSET;
}

guint8 mausb_ep_handle_dev_addr(guint16 handle) {
    return (handle & MAUSB_EP_HANDLE_DEV_ADDR) >> MAUSB_EP_HANDLE_DEV_ADDR_OFFSET;
}

guint8 mausb_ep_handle_bus_num(guint16 handle) {
    return (handle & MAUSB_EP_HANDLE_BUS_NUM) >> MAUSB_EP_HANDLE_BUS_NUM_OFFSET;
}

/* returns the length field of the MAUSB packet */
static guint mausb_get_pkt_len(packet_info *pinfo _U_, tvbuff_t *tvb,
                               int offset, void *data _U_)
{
    return tvb_get_letohs(tvb, offset + 2);
}

/* Initialize the subtree pointers */
static gint ett_mausb = -1;
static gint ett_mausb_flags = -1;
static gint ett_mausb_ep_handle = -1;
static gint ett_mausb_tflags = -1;
static gint ett_mausb_iflags = -1;
static gint ett_mausb_present_time = -1;
static gint ett_mausb_timestamp = -1;
static gint ett_mgmt = -1;
static gint ett_dev_cap = -1;
static gint ett_clear_transfers_block = -1;


#define USB_DT_EP_SIZE              7
#define USB_DT_SS_EP_COMP_SIZE      6
#define USB_DT_ISO_SSP_EP_COMP_SIZE 8

/* Size of EPHandleReq Descriptors */
#define MAUSB_EP_DES_SIZE 8
#define MAUSB_SS_EP_DES_SIZE 16
#define MAUSB_ISO_SSP_EP_DES_SIZE 24

/* EPHandleReq Descriptor Padding */
#define MAUSB_EP_DES_PAD         (MAUSB_EP_DES_SIZE - USB_DT_EP_SIZE)

#define MAUSB_SS_EP_DES_PAD      (MAUSB_SS_EP_DES_SIZE - \
        (USB_DT_EP_SIZE + USB_DT_SS_EP_COMP_SIZE))

#define MAUSB_ISO_SSP_EP_DES_PAD (MAUSB_ISO_SSP_EP_DES_SIZE - \
        (USB_DT_EP_SIZE + USB_DT_SS_EP_COMP_SIZE + USB_DT_ISO_SSP_EP_COMP_SIZE))


/* Size of EPHandleResp Descriptor */
#define MAUSB_SIZE_MAUSB_EP_DES 16


/* Size of EPHandleResp Descriptor */
#define MAUSB_SIZE_EP_HANDLE 2


/* Dissects an individual Device Capability Descriptor */
static guint16 dissect_mausb_dev_cap_desc(proto_tree *tree, tvbuff_t *tvb,
                                          packet_info *pinfo, gint16 offset)
{
    guint8 desc_len;
    guint8 cap_type;
    gint16 desc_offset;
    proto_item *len_field;
    proto_tree *dev_cap_tree;

    desc_offset = offset;
    desc_len = tvb_get_guint8(tvb, desc_offset);
    cap_type = tvb_get_guint8(tvb, desc_offset + 1);

    dev_cap_tree = proto_tree_add_subtree(tree, tvb, desc_offset, desc_len,
        ett_dev_cap, NULL,
        val_to_str_const(cap_type, mausb_dev_cap_string, "Unknown Capability"));

    len_field = proto_tree_add_item(dev_cap_tree, hf_mausb_dev_cap_len,
        tvb, desc_offset, 1, ENC_LITTLE_ENDIAN);
    desc_offset += 1;

    proto_tree_add_item(dev_cap_tree, hf_mausb_dev_cap_type,
        tvb, desc_offset, 1, ENC_LITTLE_ENDIAN);
    desc_offset += 1;

    if (desc_len > 2) {

        /* TODO: dissect individual capabilities */
        switch (cap_type) {
        case SpeedCap:
        case PmanCap:
        case IsoCap:
        case SyncCap:
        case ContainerIDCap:
        case LinkSleepCap:
        default:
            proto_tree_add_item(dev_cap_tree, hf_mausb_dev_cap_generic,
            tvb, desc_offset, (desc_len - 2), ENC_NA);
            desc_offset += (desc_len - 2);

            break;
        }
    }

    /* Was this descriptor a different length than expected */
    if (desc_offset != offset + desc_len) {
        expert_add_info(pinfo, len_field, &ei_dev_cap_len);
    }

    return offset + desc_len;
}


/* Dissects a MAUSB capability response packet
 * also dissects Capability Descriptors
 */
static guint16 dissect_mausb_mgmt_pkt_cap_resp(struct mausb_header *header,
       proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint16 offset)
{

    guint desc_len;
    guint8 desc_count;
    proto_item *len_field;
    guint16 loop_offset;
    int i;

    /* Fields present in all CapResp packets */
    proto_tree_add_item(tree, hf_mausb_cap_resp_num_ep,
        tvb, offset, 2, ENC_LITTLE_ENDIAN);
    offset += 2;

    proto_tree_add_item(tree, hf_mausb_cap_resp_num_dev,
        tvb, offset, 1, ENC_LITTLE_ENDIAN);
    offset += 1;

    proto_tree_add_item(tree, hf_mausb_cap_resp_num_stream,
        tvb, offset, 1, ENC_LITTLE_ENDIAN); /* really 5 bits */
    proto_tree_add_item(tree, hf_mausb_cap_resp_dev_type,
        tvb, offset, 1, ENC_LITTLE_ENDIAN); /* really 3 bits */
    offset += 1;

    proto_tree_add_item(tree, hf_mausb_cap_resp_desc_count,
        tvb, offset, 1, ENC_LITTLE_ENDIAN);
    desc_count = tvb_get_guint8(tvb, offset);
    offset += 1;

    len_field = proto_tree_add_item(tree, hf_mausb_cap_resp_desc_len,
        tvb, offset, 3, ENC_LITTLE_ENDIAN);
    desc_len = tvb_get_letoh24(tvb, offset);
    offset += 3;

    proto_tree_add_item(tree, hf_mausb_cap_resp_transfer_req,
        tvb, offset, 2, ENC_LITTLE_ENDIAN);
    offset += 2;

    proto_tree_add_item(tree, hf_mausb_cap_resp_mgmt_req,
        tvb, offset, 2, ENC_LITTLE_ENDIAN); /* really 12 bits */
    proto_tree_add_item(tree, hf_mausb_cap_resp_rsvd,
        tvb, offset, 2, ENC_LITTLE_ENDIAN); /* really 4 bits */
    offset += 2;

    /* Descriptors length longer than remainder of packet */
    if (offset + desc_len > header->length) {
        expert_add_info(pinfo, len_field, &ei_cap_resp_desc_len);
        desc_len = header->length - offset; /* to avoid overflows */
    }

    loop_offset = offset;

    /* dissect capability descriptors */
    for (i = 0; i < desc_count; i++) {
        loop_offset = dissect_mausb_dev_cap_desc(tree, tvb, pinfo, loop_offset);
    }

    /* were the descriptors a different length than expected */
    if (loop_offset != offset + desc_len) {
        expert_add_info(pinfo, len_field, &ei_dev_cap_resp_desc_len);
        desc_len = header->length - offset; /* to avoid overflows */
    }

    return offset + desc_len;
}

/* Dissects a MAUSB endpoint handle */
static gint dissect_ep_handle(proto_tree *tree, tvbuff_t *tvb, gint offset)
{

    proto_item *ti;
    proto_tree *ep_handle_tree;

    ti = proto_tree_add_item(tree, hf_mausb_ep_handle, tvb,
        offset, MAUSB_SIZE_EP_HANDLE, ENC_LITTLE_ENDIAN);

    ep_handle_tree = proto_item_add_subtree(ti, ett_mausb_ep_handle);
    proto_tree_add_item(ep_handle_tree, hf_mausb_ep_handle_d, tvb,
        offset, MAUSB_SIZE_EP_HANDLE, ENC_LITTLE_ENDIAN);
    proto_tree_add_item(ep_handle_tree, hf_mausb_ep_handle_ep_num, tvb,
        offset, MAUSB_SIZE_EP_HANDLE, ENC_LITTLE_ENDIAN);
    proto_tree_add_item(ep_handle_tree, hf_mausb_ep_handle_dev_addr, tvb,
        offset, MAUSB_SIZE_EP_HANDLE, ENC_LITTLE_ENDIAN);
    proto_tree_add_item(ep_handle_tree, hf_mausb_ep_handle_bus_num, tvb,
        offset, MAUSB_SIZE_EP_HANDLE, ENC_LITTLE_ENDIAN);

    return MAUSB_SIZE_EP_HANDLE;

}

/* dissects presentation time & subfields */
static void dissect_mausb_present_time(proto_tree *tree, tvbuff_t *tvb,
            gint offset)
{
    proto_item *ti;
    proto_tree *present_time_tree;

    ti = proto_tree_add_item(tree, hf_mausb_present_time, tvb,
        offset, 4, ENC_LITTLE_ENDIAN);

    present_time_tree = proto_item_add_subtree(ti, ett_mausb_present_time);
    proto_tree_add_item(present_time_tree, hf_mausb_uframe, tvb,
        offset, 4, ENC_LITTLE_ENDIAN);
    proto_tree_add_item(present_time_tree, hf_mausb_frame, tvb,
        offset, 4, ENC_LITTLE_ENDIAN);

}

static void dissect_mausb_timestamp(proto_tree *tree, tvbuff_t *tvb,
            gint offset)
{
    proto_item *ti;
    proto_tree *timestamp_tree;

    ti = proto_tree_add_item(tree, hf_mausb_timestamp, tvb,
        offset, 4, ENC_LITTLE_ENDIAN);

    timestamp_tree = proto_item_add_subtree(ti, ett_mausb_timestamp);
    proto_tree_add_item(timestamp_tree, hf_mausb_delta, tvb,
        offset, 4, ENC_LITTLE_ENDIAN);
    proto_tree_add_item(timestamp_tree, hf_mausb_nom_interval, tvb,
        offset, 4, ENC_LITTLE_ENDIAN);

}

/* gets the size of the endpoint descriptors in a EPHandleReq packet */
static guint8 mausb_get_size_ep_des(tvbuff_t *tvb, gint offset)
{
    guint8 size_ep_des = 0;
    guint16 temp_buffer = 0; /* for storing the offset data */

    /* grab the 2 bytes with the size field */
    temp_buffer = tvb_get_letohs(tvb, offset);

    /* mask & shift the size field */
    temp_buffer = temp_buffer & MAUSB_MGMT_SIZE_EP_DES_MASK;
    size_ep_des = (temp_buffer >> MAUSB_MGMT_SIZE_EP_DES_OFFSET);

    return size_ep_des;
}

/* dissect an individual block for ClearTransfers */
static guint16 dissect_clear_transfers_block(proto_tree *tree,
               tvbuff_t *tvb, gint16 offset, gboolean req)
{
    proto_item *ti;
    proto_tree *block_tree;

    if (req) {
        ti = proto_tree_add_item(tree, hf_mausb_clear_transfers_info_block,
                                 tvb, offset, 8, ENC_NA);
    } else {
        ti = proto_tree_add_item(tree, hf_mausb_clear_transfers_status_block,
                                 tvb, offset, 16, ENC_NA);
    }

    block_tree = proto_item_add_subtree(ti, ett_clear_transfers_block);


    /* EP Handle */
    offset += dissect_ep_handle(block_tree, tvb, offset);

    /* Stream ID */
    proto_tree_add_item(block_tree, hf_mausb_stream_id, tvb, offset, 2,
                        ENC_LITTLE_ENDIAN);
    offset += 2;

    if (req) {
        /* Start Request ID */
        proto_tree_add_item(block_tree, hf_mausb_clear_transfers_start_req_id,
                            tvb, offset, 1, ENC_LITTLE_ENDIAN);
        offset += 1;

        /* Rsvd */
        proto_tree_add_item(block_tree, hf_mausb_clear_transfers_req_block_rsvd,
                            tvb, offset, 3, ENC_NA);
        offset += 3;

    } else {
        /* Cancel Status */
        proto_tree_add_item(block_tree, hf_mausb_clear_transfers_status,
                            tvb, offset, 4, ENC_LITTLE_ENDIAN);
        /* Partial Delivery */
        proto_tree_add_item(block_tree, hf_mausb_clear_transfers_partial,
                            tvb, offset, 4, ENC_LITTLE_ENDIAN);
        /* Rsvd */
        proto_tree_add_item(block_tree, hf_mausb_clear_transfers_resp_block_rsvd,
                            tvb, offset, 4, ENC_LITTLE_ENDIAN);
        offset += 4;

        /* Last Request ID */
        proto_tree_add_item(block_tree, hf_mausb_clear_transfers_last_req_id,
                            tvb, offset, 1, ENC_LITTLE_ENDIAN);
        offset += 1;

        /* Delivered Sequence Number */
        proto_tree_add_item(block_tree, hf_mausb_cancel_transfer_seq_num, tvb,
                            offset, 3, ENC_LITTLE_ENDIAN);
        offset += 3;
        /* Delivered Byte Offset */
        proto_tree_add_item(block_tree, hf_mausb_cancel_transfer_byte_offset,
                            tvb, offset, 4, ENC_LITTLE_ENDIAN);
        offset += 4;
    }

    return offset;
}

/* dissects portions of a MA USB packet specific to ClearTransfers packets */
static guint16 dissect_mausb_mgmt_pkt_clear_transfers(proto_tree *tree,
               tvbuff_t *tvb, gint16 offset, gboolean req)
{
    guint8 num_block;
    int i;

    num_block = tvb_get_guint8(tvb, offset);
    if (req) {
        /* Number of entries */
        proto_tree_add_item(tree, hf_mausb_clear_transfers_req_num, tvb,
                            offset, 1, ENC_LITTLE_ENDIAN);
        offset += 1;

        /* Rsvd */
        proto_tree_add_item(tree, hf_mausb_clear_transfers_req_rsvd, tvb,
                            offset, 3, ENC_NA);
        offset += 3;

    } else {
        num_block &= MAUSB_MGMT_CLEAR_TRANSFER_RESP_NUM_MASK;

        /* Number of entries */
        proto_tree_add_item(tree, hf_mausb_clear_transfers_resp_num, tvb,
                            offset, 1, ENC_LITTLE_ENDIAN);
        /* Rsvd */
        proto_tree_add_item(tree, hf_mausb_clear_transfers_resp_rsvd, tvb,
                            offset, 1, ENC_LITTLE_ENDIAN);
        offset += 4;
    }

    for (i = 0; i < num_block; i++) {
        offset = dissect_clear_transfers_block(tree, tvb, offset, req);
    }

    return offset;
}

/* dissects portions of a MA USB packet specific to Endpoint Handle Request packets */
static guint16 dissect_mausb_mgmt_pkt_ep_handle( proto_tree *tree, tvbuff_t *tvb,
            packet_info *pinfo, gint16 start, gboolean req, gboolean del)
{
    usb_conv_info_t usb_conv_info;
    proto_item *size_field = NULL;
    guint16 offset = start;
    guint16 loop_offset;
    guint8 num_ep;
    guint8 size_ep_des;
    guint8 last_ep_type = ENDPOINT_TYPE_NOT_SET;
    int i;

    memset(&usb_conv_info,  0, sizeof(usb_conv_info_t));

    num_ep = tvb_get_guint8(tvb, offset) & MAUSB_MGMT_NUM_EP_DES_MASK;

    if (!del) {
        proto_tree_add_item(tree, hf_mausb_mgmt_ep_des_num, tvb,
            offset, 1, ENC_LITTLE_ENDIAN); /* really 5 bits */
    } else {
        proto_tree_add_item(tree, hf_mausb_mgmt_ep_handle_num, tvb,
            offset, 1, ENC_LITTLE_ENDIAN); /* really 5 bits */
    }

     if (req && !del) {

        size_ep_des = mausb_get_size_ep_des(tvb, offset);
        size_field = proto_tree_add_item(tree, hf_mausb_mgmt_ep_des_size, tvb,
            offset, 2, ENC_LITTLE_ENDIAN); /* really 6 bits over a byte boundry */
        offset += 1;

        /* Padding to DWORD */
        proto_tree_add_item(tree, hf_mausb_mgmt_ep_des_pad, tvb,
            offset, 3, ENC_NA);
        offset += 3;

    } else if (!req && !del) {
        size_ep_des = MAUSB_SIZE_MAUSB_EP_DES;
        proto_tree_add_item(tree, hf_mausb_mgmt_ep_handle_pad, tvb,
            offset, 4, ENC_NA); /* really 5 bits */
        /* Padding to DWORD */
        offset += 4;

    } else { /* If it is an EPHandleDelete Req or Resp */
        size_ep_des = MAUSB_SIZE_EP_HANDLE;
        /* Padding to DWORD */
        proto_tree_add_item(tree, hf_mausb_mgmt_ep_handle_pad, tvb,
            offset, 4, ENC_NA);
        offset += 4; /* Padding to DWORD */

    }

    /* For every entry */
    for (i = 0; i < num_ep; ++i) {
        loop_offset = offset;

        /* If it is an EPHandleDelete Req or Resp */
        if (del) {
            loop_offset += dissect_ep_handle(tree, tvb, loop_offset);

        } else if (req) {

            /* Standard USB Endpoint Descriptor */
            dissect_usb_endpoint_descriptor(pinfo, tree, tvb, loop_offset,
                    &usb_conv_info, &last_ep_type, USB_SPEED_UNKNOWN);
            loop_offset += USB_DT_EP_SIZE;

            /* If there are more descriptors to read */
            if (MAUSB_EP_DES_SIZE < size_ep_des) {
                /* TODO: Dissector for SS EP Companion Descriptors */
                dissect_usb_unknown_descriptor(pinfo, tree,
                        tvb, loop_offset, &usb_conv_info);
                loop_offset += USB_DT_SS_EP_COMP_SIZE;

                if (MAUSB_SS_EP_DES_SIZE < size_ep_des) {
                    /* TODO: Dissector for SSP ISO EP Companion Descriptors */
                    loop_offset += dissect_usb_unknown_descriptor(pinfo, tree,
                            tvb, loop_offset, &usb_conv_info);

                    /* Pad to a DWORD */
                    proto_tree_add_item(tree, hf_mausb_ep_handle_req_pad, tvb,
                        loop_offset, MAUSB_ISO_SSP_EP_DES_PAD, ENC_NA);
                    loop_offset += MAUSB_ISO_SSP_EP_DES_PAD;

                } else {
                    /* Pad to a DWORD */
                    proto_tree_add_item(tree, hf_mausb_ep_handle_req_pad, tvb,
                        loop_offset, MAUSB_SS_EP_DES_PAD, ENC_NA);
                    loop_offset += MAUSB_SS_EP_DES_PAD;
                }

            } else {
                /* Pad to a DWORD */
                proto_tree_add_item(tree, hf_mausb_ep_handle_req_pad, tvb,
                    loop_offset, MAUSB_EP_DES_PAD, ENC_NA);
                loop_offset += MAUSB_EP_DES_PAD;
            }

        } else { /* IE: it's a EPHandleResp */
            /* EP Handle */
            loop_offset += dissect_ep_handle(tree, tvb, loop_offset);

            /* direction */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_dir, tvb,
                loop_offset, 1, ENC_LITTLE_ENDIAN);

            /* isochronous */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_iso, tvb,
                loop_offset, 1, ENC_LITTLE_ENDIAN);

            /* L-managed transfers */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_lman, tvb,
                loop_offset, 1, ENC_LITTLE_ENDIAN);

            /* valid handle bit */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_valid, tvb,
                loop_offset, 1, ENC_LITTLE_ENDIAN);
            loop_offset += 2; /* 4 bit flags + 12 reserved bits */

            /* credit consumption unit */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_ccu, tvb,
                loop_offset, 2, ENC_LITTLE_ENDIAN);
            loop_offset += 2;

            loop_offset += 2; /* 2 bytes reserved */

            /* buffer size (in bytes) */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_buf_size, tvb,
                loop_offset, 4, ENC_LITTLE_ENDIAN);
            loop_offset += 4;


            /* max iso programming delay (in uSec) */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_iso_prog_dly, tvb,
                loop_offset, 2, ENC_LITTLE_ENDIAN);
            loop_offset += 2;

            /* max iso response delay (in uSec) */
            proto_tree_add_item(tree, hf_mausb_ep_handle_resp_iso_resp_dly, tvb,
                loop_offset, 2, ENC_LITTLE_ENDIAN);
            loop_offset += 2;
        }


        offset += size_ep_des;

        if (req && !del && loop_offset != offset){
            expert_add_info(pinfo, size_field, &ei_ep_handle_len);
        }

    }

    return offset;

}

/* dissects portions of a MA USB packet specific to CancelTransfer packets */
static guint16 dissect_mausb_mgmt_pkt_cancel_transfer( proto_tree *tree,
        tvbuff_t *tvb, gint offset, gboolean req)
{

    guint8 status;

    offset += dissect_ep_handle(tree, tvb, offset);

    proto_tree_add_item(tree, hf_mausb_stream_id, tvb, offset, 2,
                        ENC_LITTLE_ENDIAN);
    offset += 2;

    proto_tree_add_item(tree, hf_mausb_req_id, tvb, offset, 1,
                        ENC_LITTLE_ENDIAN);
    offset += 1;

    if (req) {
        proto_tree_add_item(tree, hf_mausb_cancel_transfer_rsvd, tvb, offset, 3,
                            ENC_NA);
        offset += 3;

        return offset;
    } /* else resp */

    status = tvb_get_guint8(tvb, offset) |
                       MAUSB_CANCEL_TRANSFER_STATUS_MASK;

    proto_tree_add_item(tree, hf_mausb_cancel_transfer_status, tvb, offset, 3,
                        ENC_LITTLE_ENDIAN);

    proto_tree_add_item(tree, hf_mausb_cancel_transfer_rsvd_2, tvb, offset, 3,
                        ENC_LITTLE_ENDIAN);
    /* Reserved */
    offset += 3;

    /* if some data was moved */
    if (2 == status) {
        /* TODO: sequence number reserved for INs */
        proto_tree_add_item(tree, hf_mausb_cancel_transfer_seq_num, tvb, offset,
                            3, ENC_LITTLE_ENDIAN);
        offset += 3;

        proto_tree_add_item(tree, hf_mausb_cancel_transfer_rsvd, tvb, offset, 1,
                            ENC_NA);
        offset += 1;

        proto_tree_add_item(tree, hf_mausb_cancel_transfer_byte_offset, tvb,
                            offset, 4, ENC_LITTLE_ENDIAN);
        offset += 4;

    } else {
        proto_tree_add_item(tree, hf_mausb_cancel_transfer_rsvd, tvb, offset, 8,
                            ENC_NA);
        offset += 8;
    }

    return offset;

}

/* dissects portions of a MA USB packet specific to particular management packets */
static guint16 dissect_mausb_mgmt_pkt_flds(struct mausb_header *header,
        proto_tree *tree, tvbuff_t *tvb,
        packet_info *pinfo, gint16 start)
{

    proto_item *ti;
    proto_tree *mgmt_tree;
    guint16 offset = start;
    gint type_spec_len = tvb_reported_length(tvb) - start;

    if (0 > type_spec_len) {
        expert_add_info(pinfo, tree, &ei_mgmt_type_spec_len_short);
        return offset;
    }

    ti = proto_tree_add_item(tree, hf_mausb_mgmt_type_spec, tvb,
                             offset, type_spec_len, ENC_NA);

    mgmt_tree = proto_item_add_subtree(ti, ett_mgmt);

    switch (header->type) {

    /* subtypes with variable length additional data */
    case CapResp:
        offset = dissect_mausb_mgmt_pkt_cap_resp(header, mgmt_tree, tvb, pinfo, offset);
        break;
    case EPHandleReq:
        offset = dissect_mausb_mgmt_pkt_ep_handle(mgmt_tree, tvb, pinfo,
                                                  offset, TRUE, FALSE);
    break;

    case EPHandleResp:
        offset = dissect_mausb_mgmt_pkt_ep_handle(mgmt_tree, tvb, pinfo,
                                                  offset, FALSE, FALSE);
    break;

    /* TODO: Dissect type-specific management packet fields */
    case EPActivateReq:
    case EPActivateResp:
    case EPInactivateReq:
    case EPInactivateResp:
    case EPResetReq:
    case EPResetResp:
        proto_tree_add_item(mgmt_tree, hf_mausb_mgmt_type_spec_generic,
                            tvb, offset, type_spec_len, ENC_NA);
        offset += type_spec_len;
        break;
    case ClearTransfersReq:
        offset = dissect_mausb_mgmt_pkt_clear_transfers(mgmt_tree, tvb, offset, TRUE);
        break;
    case ClearTransfersResp:
        offset = dissect_mausb_mgmt_pkt_clear_transfers(mgmt_tree, tvb, offset, FALSE);
        break;
    case EPHandleDeleteReq:
        offset = dissect_mausb_mgmt_pkt_ep_handle(mgmt_tree, tvb, pinfo,
                                                  offset, TRUE, TRUE);
    break;
    case EPHandleDeleteResp:
        offset = dissect_mausb_mgmt_pkt_ep_handle(mgmt_tree, tvb, pinfo,
                                                  offset, FALSE, TRUE);
    break;
    case ModifyEP0Resp:
    case EPCloseStreamResp:
    case USBDevResetReq:
    case USBDevResetResp:
    case EPOpenStreamResp:
    case VendorSpecificReq:
    case VendorSpecificResp:
        /* FALLTHROUGH */

    /* subtypes with constant length additional data */
    case CapReq:
    case USBDevHandleReq:
    case USBDevHandleResp:
    case ModifyEP0Req:
    case SetUSBDevAddrReq:
    case SetUSBDevAddrResp:
    case UpdateDevReq:
    case SynchReq:
    case EPCloseStreamReq:
        proto_tree_add_item(mgmt_tree, hf_mausb_mgmt_type_spec_generic,
                            tvb, offset, type_spec_len, ENC_NA);
        offset += type_spec_len;
        break;

    case CancelTransferReq:
        offset = dissect_mausb_mgmt_pkt_cancel_transfer(mgmt_tree, tvb, offset,
                                                        TRUE);
        break;
    case CancelTransferResp:
        offset = dissect_mausb_mgmt_pkt_cancel_transfer(mgmt_tree, tvb, offset,
                                                        FALSE);
        break;
    case EPOpenStreamReq:

        proto_tree_add_item(mgmt_tree, hf_mausb_mgmt_type_spec_generic,
                            tvb, offset, type_spec_len, ENC_NA);
        offset += type_spec_len;
        break;


    /* Managment packets with no additional data */
    case DevResetReq:
    case DevResetResp:
    case UpdateDevResp:
    case USBDevDisconnectReq:
    case USBDevDisconnectResp:
    case SleepReq:
    case SleepResp:
    case WakeReq:
    case WakeResp:
    case PingReq:
    case PingResp:
    case DevDisconnectReq:
    case DevDisconnectResp:
    case DevInitDisconnectReq:
    case DevInitDisconnectResp:
    case SynchResp:
    break;

    default:
        expert_add_info(pinfo, mgmt_tree, &ei_mgmt_type_undef);
    break;

    }


    if (offset < tvb_reported_length(tvb)) {
        expert_add_info(pinfo, mgmt_tree, &ei_mgmt_type_spec_len_long);
    }

    return offset;
}

void mausb_set_usb_conv_info(usb_conv_info_t *usb_conv_info,
                             struct mausb_header *header)
{
        usb_conv_info->is_request = mausb_is_transfer_req(header);
        usb_conv_info->bus_id = mausb_ep_handle_bus_num(header->handle);
        usb_conv_info->device_address = mausb_ep_handle_dev_addr(header->handle);
        usb_conv_info->direction = mausb_is_from_host(header);
        usb_conv_info->endpoint = mausb_ep_handle_ep_num(header->handle);
        usb_conv_info->is_setup = mausb_has_setup_data(header) ||
                                  mausb_is_setup_response(header);
        switch (mausb_tx_type(header)) {
        case MAUSB_TX_TYPE_CTRL:
                usb_conv_info->transfer_type = URB_CONTROL;
                break;
        case MAUSB_TX_TYPE_ISOC:
                usb_conv_info->transfer_type = URB_ISOCHRONOUS;
                break;
        case MAUSB_TX_TYPE_BULK:
                usb_conv_info->transfer_type = URB_BULK;
                break;
        case MAUSB_TX_TYPE_INTR:
                usb_conv_info->transfer_type = URB_INTERRUPT;
                break;
        default:
                usb_conv_info->transfer_type = URB_UNKNOWN;
                break;
        }
}

/* Used to detect multiple MA Packets in a single TCP packet */
/* Not used for MA Packets in SNAP Packets */
static gint mausb_num_pdus = 0;


/* dissect fields common to all MAUSB packet types */
static int
dissect_mausb_pkt_common(tvbuff_t *tvb, gint offset, packet_info *pinfo,
        proto_tree *mausb_tree, struct mausb_header *header)
{
    proto_item *len_field;

    /* MAUSB Protocol Version */
    header->ver_flags = tvb_get_guint8(tvb, offset);
    proto_tree_add_item(mausb_tree, hf_mausb_version, tvb,
            offset, 1, ENC_LITTLE_ENDIAN);

    /* Flags */
    proto_tree_add_bitmask(mausb_tree, tvb, offset, hf_mausb_flags,
            ett_mausb_flags, mausb_flag_fields, ENC_LITTLE_ENDIAN);
    offset += 1;

    /* Packet Type */
    header->type = tvb_get_guint8(tvb, offset);
    col_append_str(pinfo->cinfo, COL_INFO, val_to_str(header->type, mausb_type_string, "%d"));
    proto_tree_add_item(mausb_tree, hf_mausb_type, tvb,
            offset, 1, ENC_LITTLE_ENDIAN);
    offset += 1;

    /* Packet Length */
    header->length = tvb_get_letohs(tvb, offset);
    col_append_fstr(pinfo->cinfo, COL_INFO, " Length=%u", header->length);
    len_field = proto_tree_add_item(mausb_tree, hf_mausb_length, tvb,
            offset, 2, ENC_LITTLE_ENDIAN);
    offset += 2;

    /* Check to see if length field is valid */
    if (tvb_reported_length(tvb) != header->length) {
        expert_add_info(pinfo, len_field, &ei_len);
    }

    /* Is the next field a device handle or an endpoint handle */
    header->handle = tvb_get_letohs(tvb, offset);

    if (mausb_is_mgmt_pkt(header)) {
        proto_tree_add_item(mausb_tree, hf_mausb_dev_handle, tvb,
              offset, 2, ENC_LITTLE_ENDIAN);
        offset += 2;
    } else {
        offset += dissect_ep_handle(mausb_tree, tvb, offset);
    }

    /* MA Device Address */
    header->ma_dev_addr = tvb_get_guint8(tvb, offset);
    proto_tree_add_item(mausb_tree, hf_mausb_ma_dev_addr, tvb,
            offset, 1, ENC_LITTLE_ENDIAN);
    offset += 1;

    /* SSID */
    header->mass_id = tvb_get_guint8(tvb, offset);
    proto_tree_add_item(mausb_tree, hf_mausb_ssid, tvb,
            offset, 1, ENC_LITTLE_ENDIAN);
    offset += 1;

    /* Status */
    header->status = tvb_get_guint8(tvb, offset);
    proto_tree_add_item(mausb_tree, hf_mausb_status, tvb,
            offset, 1, ENC_LITTLE_ENDIAN);
    offset += 1;

    return offset;
}

/* dissect datapacket specific values */
static int
dissect_mausb_pkt_data(tvbuff_t *tvb, gint offset, packet_info *pinfo,
        proto_tree *mausb_tree, struct mausb_header *header)
{
    /* EPS */
    header->u.s.eps_tflags = tvb_get_guint8(tvb, offset);
    if (mausb_is_from_host(header)) {
        proto_tree_add_item(mausb_tree, hf_mausb_eps_rsvd, tvb,
            offset, 1, ENC_LITTLE_ENDIAN);
    } else {
        proto_tree_add_item(mausb_tree, hf_mausb_eps, tvb,
            offset, 1, ENC_LITTLE_ENDIAN);
    }

    /* T-Flags */
    proto_tree_add_bitmask(mausb_tree, tvb, offset, hf_mausb_tflags,
            ett_mausb_tflags, mausb_tflag_fields, ENC_LITTLE_ENDIAN);
    offset += 1;

    if (mausb_is_iso_pkt(header)) {
        /* Number of Headers */
        header->u.s.u1.num_headers_iflags = tvb_get_letohs(tvb, offset);
        proto_tree_add_item(mausb_tree, hf_mausb_num_iso_hdr, tvb,
            offset, 2, ENC_LITTLE_ENDIAN);

        /* I-Flags */
        proto_tree_add_bitmask(mausb_tree, tvb, offset, hf_mausb_iflags,
                ett_mausb_iflags, mausb_iflag_fields, ENC_LITTLE_ENDIAN);

    } else {
        /* Stream ID */
        header->u.s.u1.stream_id = tvb_get_letohs(tvb, offset);
        proto_tree_add_item(mausb_tree, hf_mausb_stream_id, tvb,
            offset, 2, ENC_LITTLE_ENDIAN);
    }
    offset += 2;

    /* Sequence Number */
    header->u.s.seq_num = tvb_get_letoh24(tvb, offset);
    col_append_fstr(pinfo->cinfo, COL_INFO, " SeqNum=%u", header->u.s.seq_num);
    proto_tree_add_item(mausb_tree, hf_mausb_seq_num, tvb,
        offset, 3, ENC_LITTLE_ENDIAN);
    offset += 3;

    /* Request ID */
    header->u.s.req_id = tvb_get_guint8(tvb, offset);
    col_append_fstr(pinfo->cinfo, COL_INFO, " ReqID=%u", header->u.s.req_id);
    proto_tree_add_item(mausb_tree, hf_mausb_req_id, tvb,
        offset, 1, ENC_LITTLE_ENDIAN);
    offset += 1;

    if (mausb_is_iso_pkt(header)) {
        /* Presentation Time */
        header->u.s.u2.present_time_num_seg = tvb_get_letohl(tvb, offset);
        dissect_mausb_present_time(mausb_tree, tvb, offset);

        /* Number of Segments */
        proto_tree_add_item(mausb_tree, hf_mausb_num_segs, tvb,
            offset, 4, ENC_LITTLE_ENDIAN);
        offset += 4;

        /* MA USB Timestamp */
        if (mausb_has_timestamp(header)) {
            header->u.s.timestamp = tvb_get_letohl(tvb, offset);
            dissect_mausb_timestamp(mausb_tree, tvb, offset);
            offset += 4;
        }

        /* Media Time/Transmission Delay */
        if (mausb_has_mtd(header)) {
            header->u.s.tx_dly = tvb_get_letohl(tvb, offset);
            proto_tree_add_item(mausb_tree, hf_mausb_mtd, tvb,
                offset, 4, ENC_LITTLE_ENDIAN);
            offset += 4;
        }

    /* Not Iso */
    } else {
        /* Remaining Size/Credit */
        header->u.s.u2.credit = tvb_get_letohl(tvb, offset);
        proto_tree_add_item(mausb_tree, hf_mausb_rem_size_credit, tvb,
            offset, 4, ENC_LITTLE_ENDIAN);
        offset += 4;
    }

    return offset;
}

/* Code to actually dissect the packets */
static int
dissect_mausb_pkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
        void *data _U_)
{
    /* Set up structures needed to add the protocol subtree and manage it */
    proto_item *ti;
    proto_tree *mausb_tree;
    /* Other misc. local variables. */
    struct mausb_header header;
    gint offset = 0;

    memset(&header, 0, sizeof(struct mausb_header));

    /* Set the Protocol column to the constant string of mausb */
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "MAUSB");

    mausb_num_pdus++;

    col_add_str(pinfo->cinfo, COL_INFO, "[");
    col_set_fence(pinfo->cinfo, COL_INFO);

    /*** PROTOCOL TREE ***/

    /* create display subtree for the protocol */
    ti = proto_tree_add_item(tree, proto_mausb, tvb, 0,
                mausb_get_pkt_len(pinfo, tvb, offset, NULL), ENC_NA);

    mausb_tree = proto_item_add_subtree(ti, ett_mausb);

    /* Add an item to the subtree, see section 1.5 of README.dissector for more
     * information. */

    offset = dissect_mausb_pkt_common(tvb, offset, pinfo, mausb_tree, &header);

    if (mausb_is_mgmt_pkt(&header)) {

        /* Dialog Token */
        header.u.token = tvb_get_letohs(tvb, 9) & MAUSB_TOKEN_MASK;
        col_append_fstr(pinfo->cinfo, COL_INFO, " Token=%u", header.u.token);
        proto_tree_add_item(mausb_tree, hf_mausb_token, tvb,
            offset, 2, ENC_LITTLE_ENDIAN); /* Really 10 bits */
        offset += 1; /* token */

        /* Padding to a DWORD */
        proto_tree_add_item(mausb_tree, hf_mausb_mgmt_pad, tvb,
            offset, 2, ENC_LITTLE_ENDIAN); /* Really 14 bits */

        offset += 2; /* DWORD*/

        /* Dissect additional management fields (when applicable) */
        if (offset < header.length) {
            dissect_mausb_mgmt_pkt_flds(&header, mausb_tree, tvb, pinfo, offset);
        }

    }
    else if (mausb_is_data_pkt(&header)) {
        dissect_mausb_pkt_data(tvb, offset, pinfo, mausb_tree, &header);

        if (!mausb_is_transfer_ack(&header)) {
            dissect_usb_common(tvb, pinfo, tree, USB_HEADER_MAUSB, &header);
        }
    }

    col_append_str(pinfo->cinfo, COL_INFO, "]");
    col_set_fence(pinfo->cinfo, COL_INFO);

    return header.length;
}

/* Code to dissect the stream */
static int
dissect_mausb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{

    mausb_num_pdus = 0;

    tcp_dissect_pdus(tvb, pinfo, tree, TRUE, MAUSB_MIN_LENGTH,
            mausb_get_pkt_len, dissect_mausb_pkt, data);

    if (1 < mausb_num_pdus) {
        col_clear_fence(pinfo->cinfo, COL_INFO);
        col_prepend_fstr(pinfo->cinfo, COL_INFO, "[%i packets] ", mausb_num_pdus);
    }

    return tvb_reported_length(tvb);
}


/* Register the protocol with Wireshark.
 */
void
proto_register_mausb(void)
{

    static hf_register_info hf[] = {
        { &hf_mausb_version,
            { "Version", "mausb.version", FT_UINT8, BASE_DEC,
              VALS(mausb_version_string), MAUSB_VERSION_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_flags,
            { "Flags", "mausb.flags", FT_UINT8, BASE_HEX,
              NULL, MAUSB_FLAG_MASK, NULL, HFILL
            }
        },

        /* Flag Subfields */
        { &hf_mausb_flag_host,
            { "Host", "mausb.flags.host", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), (MAUSB_FLAG_HOST << MAUSB_FLAG_OFFSET),
              NULL, HFILL
            }
        },
        { &hf_mausb_flag_retry,
            { "Retry", "mausb.flags.retry", FT_BOOLEAN, 8,
              TFS(&tfs_yes_no), (MAUSB_FLAG_RETRY << MAUSB_FLAG_OFFSET),
              NULL, HFILL
            }
        },
        { &hf_mausb_flag_timestamp,
            { "Timestamp", "mausb.flags.timestamp", FT_BOOLEAN, 8,
              TFS(&tfs_present_not_present),
              (MAUSB_FLAG_TIMESTAMP << MAUSB_FLAG_OFFSET),
              NULL, HFILL
            }
        },
        { &hf_mausb_flag_reserved,
            { "Reserved", "mausb.flags.reserved", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), (MAUSB_FLAG_RESERVED << MAUSB_FLAG_OFFSET),
              NULL, HFILL
            }
        },


        { &hf_mausb_type,
            { "Type", "mausb.type", FT_UINT8, BASE_HEX,
              VALS(mausb_type_string), 0, NULL, HFILL
            }
        },
        { &hf_mausb_length,
            { "Length", "mausb.length", FT_UINT16, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_dev_handle,
            { "Device Handle", "mausb.dev_handle", FT_UINT16, BASE_HEX,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle,
            { "Endpoint Handle", "mausb.ep_handle", FT_UINT16, BASE_HEX,
              NULL, 0, NULL, HFILL
            }
        },

        /* EP Handle Subfields */
        { &hf_mausb_ep_handle_d,
            { "Direction", "mausb.ep_handle.d", FT_BOOLEAN, 16,
              TFS(&tfs_endpoint_direction), MAUSB_EP_HANDLE_D, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_ep_num,
            { "Endpoint Number", "mausb.ep_handle.ep_num", FT_UINT16, BASE_DEC,
              NULL, MAUSB_EP_HANDLE_EP_NUM, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_dev_addr,
            { "USB Device Address", "mausb.ep_handle.dev_addr", FT_UINT16, BASE_DEC,
              NULL, MAUSB_EP_HANDLE_DEV_ADDR, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_bus_num,
            { "USB Bus Number", "mausb.ep_handle.bus_num", FT_UINT16, BASE_DEC,
              NULL, MAUSB_EP_HANDLE_BUS_NUM, NULL, HFILL
            }
        },


        { &hf_mausb_ma_dev_addr,
            { "MA Device Address", "mausb.ma_dev_addr", FT_UINT8, BASE_HEX,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_ssid,
            { "Service Set ID", "mausb.ssid", FT_UINT8, BASE_HEX,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_status,
            { "Status", "mausb.status", FT_UINT8, BASE_DEC,
              VALS(mausb_status_string), 0, NULL, HFILL
            }
        },

        /* Managment Packets Only */
        { &hf_mausb_token,
            { "Token", "mausb.token", FT_UINT16, BASE_DEC,
              NULL, MAUSB_TOKEN_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_mgmt_pad,
            { "Padding to a DWORD", "mausb.mgmt_pad",
              FT_UINT16, BASE_HEX, NULL, MAUSB_MGMT_PAD_MASK,
              NULL, HFILL
            }
        },
        { &hf_mausb_mgmt_type_spec,
            { "Type-specific management packet fields", "mausb.mgmt_flds",
              FT_NONE, 0, NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_mgmt_type_spec_generic,
            { "Type-specific management packet fields", "mausb.mgmt_flds.generic",
              FT_NONE, 0, NULL, 0, NULL, HFILL
            }
        },

        /* Data Packets Only */
        { &hf_mausb_eps,
            { "EP Status", "mausb.eps", FT_UINT8, BASE_HEX,
              VALS(mausb_eps_string), MAUSB_EPS_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_eps_rsvd,
            { "EP Status", "mausb.eps.reserved", FT_UINT8, BASE_HEX,
              NULL, MAUSB_EPS_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_tflags,
            { "Transfer Flags", "mausb.tflag", FT_UINT8, BASE_HEX,
              NULL, MAUSB_TFLAG_MASK, NULL, HFILL
            }
        },

        /* T-Flag Subfields */
        { &hf_mausb_tflag_arq,
            { "ARQ", "mausb.tflag.arq", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), MAUSB_TFLAG_ARQ << MAUSB_TFLAG_OFFSET,
              NULL, HFILL
            }
        },
        { &hf_mausb_tflag_neg,
            { "NEG", "mausb.tflag.neg", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), MAUSB_TFLAG_NEG << MAUSB_TFLAG_OFFSET,
              NULL, HFILL
            }
        },
        { &hf_mausb_tflag_eot,
            { "EoT", "mausb.tflag.eot", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), MAUSB_TFLAG_EOT << MAUSB_TFLAG_OFFSET,
              NULL, HFILL
            }
        },
        { &hf_mausb_tflag_type,
            { "Transfer Type", "mausb.tflag.type", FT_UINT8, BASE_HEX,
              VALS(mausb_transfer_type_string),
              MAUSB_TFLAG_TRANSFER_TYPE << MAUSB_TFLAG_OFFSET,
              NULL, HFILL
            }
        },
        { &hf_mausb_tflag_rsvd,
            { "Reserved", "mausb.tflag.rsvd", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), MAUSB_TFLAG_RSVD << MAUSB_TFLAG_OFFSET,
              NULL, HFILL
            }
        },


        { &hf_mausb_num_iso_hdr,
            { "Number of Iso Headers", "mausb.numisohdr", FT_UINT16, BASE_DEC,
              NULL, MAUSB_NUM_ISO_HDR_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_iflags,
            { "Isochronous Flags", "mausb.iflag", FT_UINT16, BASE_HEX,
              NULL, MAUSB_IFLAG_MASK, NULL, HFILL
            }
        },

        /* I-Flag Subfields */
        { &hf_mausb_iflag_mtd,
            { "MTD Valid", "mausb.iflag.mtd", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), MAUSB_IFLAG_MTD << MAUSB_IFLAG_OFFSET,
              NULL, HFILL
            }
        },
        { &hf_mausb_iflag_hdr_format,
            { "Isochronous Header Format", "mausb.iflag.ihf", FT_UINT8, BASE_HEX,
              NULL, MAUSB_IFLAG_HDR_FORMAT << MAUSB_IFLAG_OFFSET, NULL, HFILL
            }
        },
        { &hf_mausb_iflag_asap,
            { "ASAP", "mausb.iflag.asap", FT_BOOLEAN, 8,
              TFS(&tfs_set_notset), MAUSB_IFLAG_ASAP << MAUSB_IFLAG_OFFSET,
              NULL, HFILL
            }
        },

        { &hf_mausb_stream_id,
            { "Stream ID", "mausb.streamid", FT_UINT16, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_seq_num,
            { "Sequence Number", "mausb.seqnum", FT_UINT24, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_req_id,
            { "Request ID", "mausb.reqid", FT_UINT8, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_present_time,
            { "Presentation Time", "mausb.presenttime", FT_UINT32, BASE_DEC,
              NULL, MAUSB_PRESENT_TIME_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_uframe,
            { "Microframe Number", "mausb.uframe", FT_UINT32, BASE_DEC,
              NULL, MAUSB_UFRAME_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_frame,
            { "Frame Number", "mausb.frame", FT_UINT32, BASE_DEC,
              NULL, MAUSB_FRAME_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_num_segs,
            { "Number of Segments", "mausb.numseg", FT_UINT32, BASE_DEC,
              NULL, MAUSB_NUM_SEGS_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_timestamp,
            { "Timestamp", "mausb.timestamp", FT_UINT32, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_delta,
            { "Delta", "mausb.delta", FT_UINT32, BASE_DEC,
              NULL, MAUSB_DELTA_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_nom_interval,
            { "Nominal Bus Interval", "mausb.nomitvl", FT_UINT32, BASE_DEC,
              NULL, MAUSB_INTERVAL_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_mtd,
            { "Media Time/Transmission Delay", "mausb.mtd", FT_UINT32, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_rem_size_credit,
            { "Remaining Size/Credit", "mausb.remsize_credit", FT_UINT32, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
    };


    /* Register info for CapReq/Resp specific fields */
    static hf_register_info hf_cap[] = {

        { &hf_mausb_cap_resp_num_ep,
            { "Number of Endpoints", "mausb.cap_resp.num_ep",
              FT_UINT16, BASE_DEC, NULL, 0,
              "the maximum number of endpoints for this device",
              HFILL
            }
        },
        { &hf_mausb_cap_resp_num_dev,
            { "Number of Devices", "mausb.cap_resp.num_dev",
              FT_UINT8, BASE_DEC, NULL, 0,
              "the maximum number of USB devices the MA USB device can manage",
              HFILL
            }
        },
        { &hf_mausb_cap_resp_num_stream,
            { "Number of Streams", "mausb.cap_resp.num_stream",
              FT_UINT8, BASE_DEC, NULL, MAUSB_CAP_RESP_NUM_STREAM_MASK,
              "2 to the power of this value is the max number of streams supported",
              /* TODO: have dissector print the actual number of streams supported */
              HFILL
            }
        },
        { &hf_mausb_cap_resp_dev_type,
            { "Device Type", "mausb.cap_resp.dev_type", FT_UINT8, BASE_HEX,
              VALS(mausb_cap_resp_dev_type), MAUSB_CAP_RESP_DEV_TYPE_MASK,
              NULL, HFILL
            }
        },
        { &hf_mausb_cap_resp_desc_count,
            { "Descriptors Count", "mausb.cap_resp.desc_count",
              FT_UINT8, BASE_DEC,
              NULL, 0, "The total number of MA Device Capabilities descriptors",
              HFILL
            }
        },
        { &hf_mausb_cap_resp_desc_len,
            { "Descriptors Length", "mausb.cap_resp.desc_len",
              FT_UINT24, BASE_DEC,
              NULL, 0, "The total size of MA Device Capabilities descriptors",
              HFILL
            }
        },
        { &hf_mausb_cap_resp_transfer_req,
            { "Number of Outstanding Transfer Requests",
              "mausb.cap_resp.transfer_req",
              FT_UINT16, BASE_DEC, NULL, 0,
              "The maximum number of total outstanding transfer requests", HFILL
            }
        },
        { &hf_mausb_cap_resp_mgmt_req,
            { "Number of Outstanding Management Requests", "mausb.cap_resp.mgmt_req",
              FT_UINT16, BASE_DEC, NULL,
              MAUSB_CAP_RESP_MGMT_REQ_MASK,
              "The maximum number of host initiated outstanding management requests",
              HFILL
            }
        },
        { &hf_mausb_cap_resp_rsvd,
            { "Reserved", "mausb.cap_resp.rsvd", FT_UINT16, BASE_HEX,
              NULL, MAUSB_CAP_RESP_RSVD_MASK, NULL, HFILL
            }
        },

        /* Device Capability Descriptors */
        { &hf_mausb_dev_cap_len,
            { "Length", "mausb.cap_resp.dev_cap.length",
              FT_UINT8, BASE_DEC, NULL,
              0, NULL, HFILL
            }
        },
        { &hf_mausb_dev_cap_type,
            { "Type", "mausb.cap_resp.dev_cap.type",
              FT_UINT8, BASE_DEC, VALS(mausb_dev_cap_string),
              0, NULL, HFILL
            }
        },
        { &hf_mausb_dev_cap_generic,
            { "Type-specific device capability descriptor fields",
              "mausb.cap_resp.dev_cap.generic",
              FT_NONE, 0, NULL, 0, NULL, HFILL
            }
        }
    };


    /* register info for ep_handle_* specific fields */
    static hf_register_info hf_ep_handle[] = {
        { &hf_mausb_mgmt_ep_handle_num,
            { "Number of Endpoint Handles", "mausb.ep_handle_num",
              FT_UINT8, BASE_DEC,
              NULL, MAUSB_MGMT_NUM_EP_DES_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_mgmt_ep_handle_pad,
            { "Padding to a DWORD", "mausb.ep_handle_pad",
              FT_NONE, 0,
              NULL, 0x0, NULL, HFILL
            }
        },
        { &hf_mausb_mgmt_ep_des_num,
            { "Number of Endpoint Descriptors", "mausb.ep_des_num",
              FT_UINT8, BASE_DEC,
              NULL, MAUSB_MGMT_NUM_EP_DES_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_mgmt_ep_des_size,
            { "Size of Endpoint Descriptors", "mausb.ep_des_size",
              FT_UINT16, BASE_DEC,
              NULL, MAUSB_MGMT_SIZE_EP_DES_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_mgmt_ep_des_pad,
            { "Padding to a DWORD", "mausb.ep_des_pad",
              FT_NONE, 0, NULL,
              0x0,
              NULL, HFILL
            }
        },

        { &hf_mausb_ep_handle_req_pad,
            { "Padding to a DWORD", "mausb.ep_handle_req.pad",
              FT_NONE, 0, NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_dir,
            { "Direction", "mausb.ep_dir", FT_BOOLEAN, 6,
              TFS(&tfs_ep_handle_resp_dir), MAUSB_EP_HANDLE_RESP_DIR_MASK,
              NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_iso,
            { "Isochronous", "mausb.ep_iso", FT_BOOLEAN, 6,
              TFS(&tfs_yes_no), MAUSB_EP_HANDLE_RESP_ISO_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_lman,
            { "L-Managed", "mausb.ep_lman", FT_BOOLEAN, 6,
              TFS(&tfs_supported_not_supported), MAUSB_EP_HANDLE_RESP_LMAN_MASK,
              NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_valid,
            { "Valid", "mausb.ep_valid", FT_BOOLEAN, 6,
              TFS(&tfs_invalid_valid), MAUSB_EP_HANDLE_RESP_VALID_MASK,
              NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_ccu,
            { "CCU", "mausb.ep_ccu", FT_UINT16, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_buf_size,
            { "Buffer Size", "mausb.ep_buf_size", FT_UINT32, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_iso_prog_dly,
            { "Iso Programming Delay", "mausb.ep_iso_prog_dly", FT_UINT16, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_ep_handle_resp_iso_resp_dly,
            { "Iso Response Delay", "mausb.ep_iso_resp_dly", FT_UINT16, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        }


    };

    /* (Cancel/Clear)Transfer(Req/Resp) specific fields */
    static hf_register_info hf_cancel_transfer[] = {
        { &hf_mausb_clear_transfers_info_block,
            { "Clear Transfers Information Block", "mausb.clear_transfers.info", FT_NONE, 0,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_clear_transfers_status_block,
            { "Cancel Transfers Status Block", "mausb.clear_transfers.status_block", FT_NONE, 0,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_cancel_transfer_rsvd,
            { "Reserved", "mausb.cancel_transfer.rsvd", FT_NONE, 0,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_clear_transfers_req_num,
            { "Number of Blocks", "mausb.clear_transfers_req.num", FT_UINT8, BASE_DEC,
              NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_clear_transfers_req_rsvd,
             { "Reserved", "mausb.clear_transfers_req.rsvd", FT_NONE, 0,
               NULL, 0, NULL, HFILL
             }
        },
        { &hf_mausb_clear_transfers_resp_num,
            { "Number of Blocks", "mausb.clear_transfers_resp.num", FT_UINT32, BASE_DEC,
              NULL, MAUSB_CLEAR_TRANSFERS_RESP_NUM_MASK , NULL, HFILL
            }
        },
        { &hf_mausb_clear_transfers_resp_rsvd,
             { "Reserved", "mausb.clear_transfers_resp.rsvd", FT_UINT32, BASE_HEX,
               NULL, ~MAUSB_CLEAR_TRANSFERS_RESP_NUM_MASK, NULL, HFILL
             }
        },
        { &hf_mausb_cancel_transfer_status,
            { "Status", "mausb.cancel_transfer.status", FT_UINT24, BASE_HEX,
              VALS(mausb_cancel_transfer_status_string),
              MAUSB_CANCEL_TRANSFER_STATUS_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_cancel_transfer_rsvd_2,
            { "Reserved", "mausb.cancel_transfer.rsvd_2", FT_UINT24, BASE_HEX,
              NULL, ~MAUSB_CANCEL_TRANSFER_STATUS_MASK, NULL, HFILL
            }
        },
        { &hf_mausb_clear_transfers_status,
            { "Cancellation Status", "mausb.clear_transfers.status", FT_BOOLEAN, 6,
              TFS(&tfs_success_fail), MAUSB_CLEAR_TRANSFERS_STATUS_MASK,
              NULL, HFILL
            }
        },
        { &hf_mausb_clear_transfers_partial,
            { "Partial Delivery", "mausb.clear_transfers.partial", FT_BOOLEAN, 6,
              NULL, MAUSB_CLEAR_TRANSFERS_PARTIAL_MASK,
              NULL, HFILL
            }
       },
       { &hf_mausb_clear_transfers_start_req_id,
           { "Start Request ID", "mausb.clear_transfers.start_reqid", FT_UINT8, BASE_DEC,
             NULL, 0, NULL, HFILL
           }
       },
       { &hf_mausb_clear_transfers_last_req_id,
           { "Last Request ID", "mausb.clear_transfers.last_reqid", FT_UINT8, BASE_DEC,
             NULL, 0, NULL, HFILL
           }
       },
       { &hf_mausb_clear_transfers_req_block_rsvd,
            { "Reserved", "mausb.clear_transfers_req.block_rsvd", FT_NONE, 0,
              NULL, 0, NULL, HFILL
            }
       },
       { &hf_mausb_clear_transfers_resp_block_rsvd,
            { "Reserved", "mausb.clear_transfers_resp.block_rsvd", FT_UINT32, BASE_HEX,
              NULL, MAUSB_CLEAR_TRANSFERS_RESP_BLOCK_RSVD_MASK, NULL, HFILL
            }
       },

       { &hf_mausb_cancel_transfer_seq_num,
            { "Delivered Sequence Number", "mausb.cancel_transfer.seqnum",
              FT_UINT24, BASE_DEC, NULL, 0, NULL, HFILL
            }
        },
        { &hf_mausb_cancel_transfer_byte_offset,
            { "Delivered Byte Offset", "mausb.cancel_transfer.byte_offset",
              FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL
            }
        },
    };

    static hf_register_info oui_hf[] = {
      { &hf_llc_mausb_pid,
        { "PID",    "mausb.pid",  FT_UINT16, BASE_HEX,
          VALS(mausb_pid_string), 0x0, NULL, HFILL }
      }
    };

    /* Setup protocol subtree array */
    static gint *ett[] = {
        &ett_mausb,
        &ett_mausb_flags,
        &ett_mausb_ep_handle,
        &ett_mausb_tflags,
        &ett_mausb_iflags,
        &ett_mausb_present_time,
        &ett_mausb_timestamp,
        &ett_mgmt,
        &ett_dev_cap,
        &ett_clear_transfers_block
    };

    static ei_register_info ei[] = {
        { &ei_ep_handle_len,
            { "mausb.ei.ep_handle.length", PI_PROTOCOL, PI_WARN,
              "Invalid Endpoint handle length field", EXPFILL }
        },
        { &ei_len,
            { "mausb.ei.length", PI_MALFORMED, PI_ERROR,
              "Packet length field does not match size of packet", EXPFILL }
        },
        { &ei_mgmt_type_undef,
            { "mausb.ei.type", PI_PROTOCOL, PI_WARN,
              "Undefined management packet type", EXPFILL }
        },
        { &ei_mgmt_type_spec_len_long,
            { "mausb.ei.type_spec.len", PI_PROTOCOL, PI_WARN,
              "Data exists after type-specific management packet field", EXPFILL }
        },
        { &ei_mgmt_type_spec_len_short,
            { "mausb.ei.type_spec.len", PI_PROTOCOL, PI_WARN,
              "Expected type-specific management packet data", EXPFILL }
        },
        { &ei_dev_cap_len,
            { "mausb.ei.cap_resp.dev_cap.length", PI_PROTOCOL, PI_WARN,
              "Incorrect length value for this device capability descriptor",
              EXPFILL }
        },
        { &ei_dev_cap_resp_desc_len,
            { "mausb.ei.dev_cap_resp.desc_len", PI_PROTOCOL, PI_WARN,
              "Incorrect value in Device Descriptors Length field", EXPFILL }
        },
        { &ei_cap_resp_desc_len,
            { "mausb.ei.cap_resp.desc_len", PI_PROTOCOL, PI_WARN,
              "Value in Descriptors Length field exceeds actual space in packet", EXPFILL }
        },
    };

    expert_module_t* expert_mausb;

    /* Register the protocol name and description */
    proto_mausb = proto_register_protocol("Media Agnostic USB", "MAUSB", "mausb");

    /* Required function calls to register the header fields and subtrees */
    proto_register_field_array(proto_mausb, hf, array_length(hf));
    proto_register_field_array(proto_mausb, hf_cap, array_length(hf_cap));
    proto_register_field_array(proto_mausb, hf_ep_handle, array_length(hf_ep_handle));
    proto_register_field_array(proto_mausb, hf_cancel_transfer, array_length(hf_cancel_transfer));
    proto_register_subtree_array(ett, array_length(ett));

    /* for Expert info */
    expert_mausb = expert_register_protocol(proto_mausb);
    expert_register_field_array(expert_mausb, ei, array_length(ei));

    llc_add_oui(OUI_WFA, "llc.wfa_pid", "LLC WFA OUI PID", oui_hf, proto_mausb);

    /* Register the dissectors */
    mausb_tcp_handle = register_dissector("mausb", dissect_mausb, proto_mausb);
    mausb_pkt_handle = register_dissector("mausb.pkt", dissect_mausb_pkt, proto_mausb);

}

void
proto_reg_handoff_mausb(void)
{
    dissector_add_uint("llc.wfa_pid", PID_MAUSB, mausb_pkt_handle);

    dissector_add_uint_range_with_preference("tcp.port", "", mausb_tcp_handle);
    dissector_add_for_decode_as_with_preference("udp.port", mausb_pkt_handle);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */