Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-usb-masstorage.c
blob724070bb7e1b1101e74f139236f81839d89f699b
1 /* packet-usb-masstorage.c
2 * USB Mass Storage class stub dissector
3 * Copyright 2021, Aidan MacDonald <amachronic@protonmail.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include "packet-usb.h"
17 static int proto_usb_ms;
19 static dissector_handle_t usb_ms_bulk_handle;
20 static dissector_handle_t usb_ms_control_handle;
21 static dissector_handle_t usb_ms_interrupt_handle;
22 static dissector_handle_t usb_ms_descriptor_handle;
24 static dissector_table_t usb_ms_bulk_dissector_table;
25 static dissector_table_t usb_ms_control_dissector_table;
26 static dissector_table_t usb_ms_interrupt_dissector_table;
27 static dissector_table_t usb_ms_descriptor_dissector_table;
29 void proto_register_usb_ms(void);
30 void proto_reg_handoff_usb_ms(void);
32 #define MSC_SUBCLASS_SCSI_COMMAND_SET_NOT_REPORTED 0x00
33 #define MSC_SUBCLASS_RBC 0x01
34 #define MSC_SUBCLASS_MMC_5_ATAPI 0x02
35 #define MSC_SUBCLASS_OBSOLETE_QIC_157 0x03
36 #define MSC_SUBCLASS_UFI 0x04
37 #define MSC_SUBCLASS_OBSOLETE_SFF_8070I 0x05
38 #define MSC_SUBCLASS_SCSI_TRANSPARENT_COMMAND_SET 0x06
39 #define MSC_SUBCLASS_LSD_FS 0x07
40 #define MSC_SUBCLASS_IEEE_1667 0x08
41 #define MSC_SUBCLASS_VENDOR 0xFF
43 static const value_string usb_massstorage_subclass_vals[] = {
44 {MSC_SUBCLASS_SCSI_COMMAND_SET_NOT_REPORTED, "SCSI command set not reported"},
45 {MSC_SUBCLASS_RBC, "RBC"},
46 {MSC_SUBCLASS_MMC_5_ATAPI, "MMC-5 (ATAPI)"},
47 {MSC_SUBCLASS_OBSOLETE_QIC_157, "Obsolete (was QIC-157)"},
48 {MSC_SUBCLASS_UFI, "UFI"},
49 {MSC_SUBCLASS_OBSOLETE_SFF_8070I, "Obsolete (was SFF-8070i)"},
50 {MSC_SUBCLASS_SCSI_TRANSPARENT_COMMAND_SET, "SCSI transparent command set"},
51 {MSC_SUBCLASS_LSD_FS, "LSD FS"},
52 {MSC_SUBCLASS_IEEE_1667, "IEEE 1667"},
53 {MSC_SUBCLASS_VENDOR, "Specific to device vendor"},
54 {0, NULL}
56 value_string_ext ext_usb_massstorage_subclass_vals = VALUE_STRING_EXT_INIT(usb_massstorage_subclass_vals);
58 #define MSC_PROTOCOL_CBI_NO_INTERRUPT 0x00
59 #define MSC_PROTOCOL_CBI_WITH_INTERRUPT 0x01
60 #define MSC_PROTOCOL_OBSOLETE 0x02
61 #define MSC_PROTOCOL_BULK_ONLY 0x50
62 #define MSC_PROTOCOL_UAS 0x62
63 #define MSC_PROTOCOL_VENDOR 0xFF
65 static const value_string usb_massstorage_protocol_vals[] = {
66 {MSC_PROTOCOL_CBI_NO_INTERRUPT, "Control/Bulk/Interrupt (CBI) Transport with command completion interrupt"},
67 {MSC_PROTOCOL_CBI_WITH_INTERRUPT, "Control/Bulk/Interrupt (CBI) Transport with no command completion interrupt"},
68 {MSC_PROTOCOL_OBSOLETE, "Obsolete"},
69 {MSC_PROTOCOL_BULK_ONLY, "Bulk-Only (BBB) Transport"},
70 {MSC_PROTOCOL_UAS, "UAS"},
71 {MSC_PROTOCOL_VENDOR, "Specific to device vendor"},
72 {0, NULL}
74 value_string_ext usb_massstorage_protocol_vals_ext = VALUE_STRING_EXT_INIT(usb_massstorage_protocol_vals);
76 static int
77 dissect_usb_ms_bulk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data)
79 urb_info_t *urb;
81 urb = (urb_info_t *)data;
83 return dissector_try_uint_with_data(usb_ms_bulk_dissector_table, urb->conv->interfaceProtocol, tvb, pinfo, parent_tree, true, urb);
86 static int
87 dissect_usb_ms_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data)
89 urb_info_t *urb;
91 urb = (urb_info_t *)data;
93 return dissector_try_uint_with_data(usb_ms_control_dissector_table, urb->conv->interfaceProtocol, tvb, pinfo, parent_tree, true, urb);
96 static int
97 dissect_usb_ms_interrupt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data)
99 urb_info_t *urb;
101 urb = (urb_info_t *)data;
103 return dissector_try_uint_with_data(usb_ms_interrupt_dissector_table, urb->conv->interfaceProtocol, tvb, pinfo, parent_tree, true, urb);
106 static int
107 dissect_usb_ms_descriptor(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data)
109 urb_info_t *urb;
111 urb = (urb_info_t *)data;
113 return dissector_try_uint_with_data(usb_ms_descriptor_dissector_table, urb->conv->interfaceProtocol, tvb, pinfo, parent_tree, true, urb);
116 void
117 proto_register_usb_ms(void)
119 proto_usb_ms = proto_register_protocol("USB Mass Storage Class", "USBMSClass", "usbmsclass");
121 usb_ms_bulk_handle = register_dissector("usbmsclass.bulk", dissect_usb_ms_bulk, proto_usb_ms);
122 usb_ms_control_handle = register_dissector("usbmsclass.control", dissect_usb_ms_control, proto_usb_ms);
123 usb_ms_interrupt_handle = register_dissector("usbmsclass.interrupt", dissect_usb_ms_interrupt, proto_usb_ms);
124 usb_ms_descriptor_handle = register_dissector("usbmsclass.descriptor", dissect_usb_ms_descriptor, proto_usb_ms);
126 usb_ms_bulk_dissector_table = register_dissector_table("usbms.bulk",
127 "USBMS bulk endpoint", proto_usb_ms, FT_UINT8, BASE_HEX);
128 usb_ms_control_dissector_table = register_dissector_table("usbms.control",
129 "USBMS control endpoint", proto_usb_ms, FT_UINT8, BASE_HEX);
130 usb_ms_interrupt_dissector_table = register_dissector_table("usbms.interrupt",
131 "USBMS interrupt endpoint", proto_usb_ms, FT_UINT8, BASE_HEX);
132 usb_ms_descriptor_dissector_table = register_dissector_table("usbms.descriptor",
133 "USBMS descriptor", proto_usb_ms, FT_UINT8, BASE_HEX);
136 void
137 proto_reg_handoff_usb_ms(void)
139 dissector_add_uint("usb.bulk", IF_CLASS_MASS_STORAGE, usb_ms_bulk_handle);
140 dissector_add_uint("usb.control", IF_CLASS_MASS_STORAGE, usb_ms_control_handle);
141 dissector_add_uint("usb.interrupt", IF_CLASS_MASS_STORAGE, usb_ms_interrupt_handle);
142 dissector_add_uint("usb.descriptor", IF_CLASS_MASS_STORAGE, usb_ms_descriptor_handle);
146 * Editor modelines - https://www.wireshark.org/tools/modelines.html
148 * Local variables:
149 * c-basic-offset: 4
150 * tab-width: 8
151 * indent-tabs-mode: nil
152 * End:
154 * vi: set shiftwidth=4 tabstop=8 expandtab:
155 * :indentSize=4:tabSize=8:noTabs=true: