2 * Routines for USB Communications and CDC Control dissection
3 * Copyright 2013, Pascal Quantin <pascal.quantin@gmail.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/packet.h>
29 #include "packet-usb.h"
31 /* protocols and header fields */
32 static int proto_usb_com
= -1;
33 static int hf_usb_com_descriptor_subtype
= -1;
34 static int hf_usb_com_descriptor_cdc
= -1;
35 static int hf_usb_com_descriptor_payload
= -1;
36 static int hf_usb_com_control_subclass
= -1;
37 static int hf_usb_com_capabilities
= -1;
38 static int hf_usb_com_descriptor_acm_capabilities_reserved
= -1;
39 static int hf_usb_com_descriptor_acm_capabilities_network_connection
= -1;
40 static int hf_usb_com_descriptor_acm_capabilities_send_break
= -1;
41 static int hf_usb_com_descriptor_acm_capabilities_line_and_state
= -1;
42 static int hf_usb_com_descriptor_acm_capabilities_comm_features
= -1;
43 static int hf_usb_com_control_interface
= -1;
44 static int hf_usb_com_subordinate_interface
= -1;
45 static int hf_usb_com_descriptor_cm_capabilities_reserved
= -1;
46 static int hf_usb_com_descriptor_cm_capabilities_call_managment_over_data_class_interface
= -1;
47 static int hf_usb_com_descriptor_cm_capabilities_call_managment
= -1;
48 static int hf_usb_com_descriptor_cm_data_interface
= -1;
49 static int hf_usb_com_control_payload
= -1;
51 static gint ett_usb_com
= -1;
52 static gint ett_usb_com_capabilities
= -1;
54 static dissector_handle_t mbim_control_handle
;
55 static dissector_handle_t mbim_descriptor_handle
;
56 static dissector_handle_t mbim_bulk_handle
;
57 static dissector_handle_t eth_withoutfcs_handle
;
59 #define CS_INTERFACE 0x24
60 #define CS_ENDPOINT 0x25
62 static const value_string usb_com_descriptor_type_vals
[] = {
63 { CS_INTERFACE
, "CS_INTERFACE"},
64 { CS_ENDPOINT
, "CS_ENDPOINT"},
67 static value_string_ext usb_com_descriptor_type_vals_ext
= VALUE_STRING_EXT_INIT(usb_com_descriptor_type_vals
);
69 static const value_string usb_com_descriptor_subtype_vals
[] = {
70 { 0x00, "Header Functional Descriptor"},
71 { 0x01, "Call Management Functional Descriptor"},
72 { 0x02, "Abstract Control Management Functional Descriptor"},
73 { 0x03, "Direct Line Management Functional Descriptor"},
74 { 0x04, "Telephone Ringer Functional Descriptor"},
75 { 0x05, "Telephone Call and Line State Reporting Capabilities Functional Descriptor"},
76 { 0x06, "Union Functional Descriptor"},
77 { 0x07, "Country Selection Functional Descriptor"},
78 { 0x08, "Telephone Operational Modes Functional Descriptor"},
79 { 0x09, "USB Terminal Functional Descriptor"},
80 { 0x0A, "Network Channel Terminal Descriptor"},
81 { 0x0B, "Protocol Unit Functional Descriptor"},
82 { 0x0C, "Extension Unit Functional Descriptor"},
83 { 0x0D, "Multi-Channel Management Functional Descriptor"},
84 { 0x0E, "CAPI Control Management Functional Descriptor"},
85 { 0x0F, "Ethernet Networking Functional Descriptor"},
86 { 0x10, "ATM Networking Functional Descriptor"},
87 { 0x11, "Wireless Handset Control Model Functional Descriptor"},
88 { 0x12, "Mobile Direct Line Model Functional Descriptor"},
89 { 0x13, "MDLM Detail Functional Descriptor"},
90 { 0x14, "Device Management Model Functional Descriptor"},
91 { 0x15, "OBEX Functional Descriptor"},
92 { 0x16, "Command Set Functional Descriptor"},
93 { 0x17, "Command Set Detail Functional Descriptor"},
94 { 0x18, "Telephone Control Model Functional Descriptor"},
95 { 0x19, "OBEX Service Identifier Functional Descriptor"},
96 { 0x1A, "NCM Functional Descriptor"},
97 { 0x1B, "MBIM Functional Descriptor"},
98 { 0x1C, "MBIM Extended Functional Descriptor"},
101 static value_string_ext usb_com_descriptor_subtype_vals_ext
= VALUE_STRING_EXT_INIT(usb_com_descriptor_subtype_vals
);
103 #define COM_SUBCLASS_RESERVED 0x00
104 #define COM_SUBCLASS_DLCM 0x01
105 #define COM_SUBCLASS_ACM 0x02
106 #define COM_SUBCLASS_TCM 0x03
107 #define COM_SUBCLASS_MCCM 0x04
108 #define COM_SUBCLASS_CCM 0x05
109 #define COM_SUBCLASS_ENCM 0x06
110 #define COM_SUBCLASS_ANCM 0x07
111 #define COM_SUBCLASS_WHCM 0x08
112 #define COM_SUBCLASS_DM 0x09
113 #define COM_SUBCLASS_MDLM 0x0a
114 #define COM_SUBCLASS_OBEX 0x0b
115 #define COM_SUBCLASS_EEM 0x0c
116 #define COM_SUBCLASS_NCM 0x0d
117 #define COM_SUBCLASS_MBIM 0x0e
119 static const value_string usb_com_subclass_vals
[] = {
120 {COM_SUBCLASS_RESERVED
, "RESERVED"},
121 {COM_SUBCLASS_DLCM
, "Direct Line Control Model"},
122 {COM_SUBCLASS_ACM
, "Abstract Control Model"},
123 {COM_SUBCLASS_TCM
, "Telephone Control Model"},
124 {COM_SUBCLASS_MCCM
, "Multi-Channel Control Model"},
125 {COM_SUBCLASS_CCM
, "CAPI Control Model"},
126 {COM_SUBCLASS_ENCM
, "Ethernet Networking Control Model"},
127 {COM_SUBCLASS_ANCM
, "ATM Networking Control Model"},
128 {COM_SUBCLASS_WHCM
, "Wireless Handset Control Model"},
129 {COM_SUBCLASS_DM
, "Device Management"},
130 {COM_SUBCLASS_MDLM
, "Mobile Direct Line Model"},
131 {COM_SUBCLASS_OBEX
, "OBEX"},
132 {COM_SUBCLASS_EEM
, "Ethernet Emulation Model"},
133 {COM_SUBCLASS_NCM
, "Network Control Model"},
134 {COM_SUBCLASS_MBIM
, "Mobile Broadband Interface Model"},
137 value_string_ext ext_usb_com_subclass_vals
= VALUE_STRING_EXT_INIT(usb_com_subclass_vals
);
139 void proto_register_usb_com(void);
140 void proto_reg_handoff_usb_com(void);
143 dissect_usb_com_descriptor(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
145 guint8 offset
= 0, type
, subtype
;
147 proto_tree
*subtree_capabilities
;
148 proto_item
*subitem_capabilities
;
151 ti
= proto_tree_add_text(tree
, tvb
, offset
, -1, "COMMUNICATIONS DESCRIPTOR");
152 subtree
= proto_item_add_subtree(ti
, ett_usb_com
);
154 dissect_usb_descriptor_header(subtree
, tvb
, offset
, &usb_com_descriptor_type_vals_ext
);
157 type
= tvb_get_guint8(tvb
, 1);
160 subtype
= tvb_get_guint8(tvb
, offset
);
161 proto_tree_add_uint(subtree
, hf_usb_com_descriptor_subtype
, tvb
, offset
, 1, subtype
);
165 proto_tree_add_item(subtree
, hf_usb_com_descriptor_cdc
, tvb
, offset
, 2, ENC_LITTLE_ENDIAN
);
169 subitem_capabilities
= proto_tree_add_item(subtree
, hf_usb_com_capabilities
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
170 subtree_capabilities
= proto_item_add_subtree(subitem_capabilities
, ett_usb_com_capabilities
);
172 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_cm_capabilities_reserved
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
173 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_cm_capabilities_call_managment_over_data_class_interface
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
174 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_cm_capabilities_call_managment
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
176 proto_tree_add_item(subtree
, hf_usb_com_descriptor_cm_data_interface
, tvb
, 4, 1, ENC_LITTLE_ENDIAN
);
180 subitem_capabilities
= proto_tree_add_item(subtree
, hf_usb_com_capabilities
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
181 subtree_capabilities
= proto_item_add_subtree(subitem_capabilities
, ett_usb_com_capabilities
);
183 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_acm_capabilities_reserved
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
184 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_acm_capabilities_network_connection
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
185 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_acm_capabilities_send_break
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
186 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_acm_capabilities_line_and_state
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
187 proto_tree_add_item(subtree_capabilities
, hf_usb_com_descriptor_acm_capabilities_comm_features
, tvb
, 3, 1, ENC_LITTLE_ENDIAN
);
192 proto_tree_add_item(subtree
, hf_usb_com_control_interface
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
194 while (tvb_length_remaining(tvb
,offset
) > 0) {
195 proto_tree_add_item(subtree
, hf_usb_com_subordinate_interface
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
201 offset
= call_dissector_only(mbim_descriptor_handle
, tvb
, pinfo
, subtree
, data
);
212 if (tvb_reported_length_remaining(tvb
, offset
) != 0) {
213 proto_tree_add_item(subtree
, hf_usb_com_descriptor_payload
, tvb
, offset
, -1, ENC_NA
);
215 return tvb_length(tvb
);
219 dissect_usb_com_control(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
221 usb_conv_info_t
*usb_conv_info
= (usb_conv_info_t
*)data
;
226 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "USBCOM");
228 ti
= proto_tree_add_item(tree
, proto_usb_com
, tvb
, 0, -1, ENC_NA
);
229 subtree
= proto_item_add_subtree(ti
, ett_usb_com
);
232 ti
= proto_tree_add_uint(subtree
, hf_usb_com_control_subclass
, tvb
, 0, 0,
233 usb_conv_info
->interfaceSubclass
);
234 PROTO_ITEM_SET_GENERATED(ti
);
236 switch (usb_conv_info
->interfaceSubclass
)
238 case COM_SUBCLASS_MBIM
:
239 offset
= call_dissector_only(mbim_control_handle
, tvb
, pinfo
, tree
, NULL
);
246 if (tvb_reported_length_remaining(tvb
, offset
) != 0) {
247 proto_tree_add_item(subtree
, hf_usb_com_control_payload
, tvb
, offset
, -1, ENC_NA
);
249 return tvb_length(tvb
);
253 dissect_usb_com_bulk(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
255 usb_conv_info_t
*usb_conv_info
= (usb_conv_info_t
*)data
;
258 switch (usb_conv_info
->interfaceProtocol
)
260 case 0x01: /* Network Transfer Block */
261 case 0x02: /* Network Transfer Block (IP + DSS) */
262 return call_dissector_only(mbim_bulk_handle
, tvb
, pinfo
, tree
, NULL
);
269 /* By default, assume it is ethernet without FCS */
270 return call_dissector_only(eth_withoutfcs_handle
, tvb
, pinfo
, tree
, NULL
);
274 proto_register_usb_com(void)
276 static hf_register_info hf
[] = {
277 { &hf_usb_com_descriptor_subtype
,
278 { "bDescriptorSubtype", "usbcom.descriptor.subtype", FT_UINT8
, BASE_HEX
|BASE_EXT_STRING
,
279 &usb_com_descriptor_subtype_vals_ext
, 0, NULL
, HFILL
}},
280 { &hf_usb_com_descriptor_cdc
,
281 { "bcdCDC", "usbcom.descriptor.cdc", FT_UINT16
, BASE_HEX
,
282 NULL
, 0, NULL
, HFILL
}},
283 { &hf_usb_com_descriptor_payload
,
284 { "Payload", "usbcom.descriptor.payload", FT_BYTES
, BASE_NONE
,
285 NULL
, 0, NULL
, HFILL
}},
286 { &hf_usb_com_control_subclass
,
287 { "Subclass", "usbcom.control.subclass", FT_UINT8
, BASE_HEX
|BASE_EXT_STRING
,
288 &ext_usb_com_subclass_vals
, 0, NULL
, HFILL
}},
289 { &hf_usb_com_capabilities
,
290 { "bmCapabilities", "usbcom.descriptor.capabilities", FT_UINT8
, BASE_HEX
,
291 NULL
, 0, NULL
, HFILL
}},
292 { &hf_usb_com_descriptor_acm_capabilities_reserved
,
293 { "Reserved", "usbcom.descriptor.acm.capabilities.reserved", FT_UINT8
, BASE_HEX
,
294 NULL
, 0xF0, NULL
, HFILL
}},
295 { &hf_usb_com_descriptor_acm_capabilities_network_connection
,
296 { "Network_Connection", "usbcom.descriptor.acm.capabilities.network_connection", FT_BOOLEAN
, 8,
297 &tfs_supported_not_supported
, 0x08, NULL
, HFILL
}},
298 { &hf_usb_com_descriptor_acm_capabilities_send_break
,
299 { "Send_Break", "usbcom.descriptor.acm.capabilities.network_connection", FT_BOOLEAN
, 8,
300 &tfs_supported_not_supported
, 0x04, NULL
, HFILL
}},
301 { &hf_usb_com_descriptor_acm_capabilities_line_and_state
,
302 { "Line Requests and State Notification", "usbcom.descriptor.acm.capabilities.line_and_state", FT_BOOLEAN
, 8,
303 &tfs_supported_not_supported
, 0x02, NULL
, HFILL
}},
304 { &hf_usb_com_descriptor_acm_capabilities_comm_features
,
305 { "Comm Features Combinations", "usbcom.descriptor.acm.capabilities.comm_features", FT_BOOLEAN
, 8,
306 &tfs_supported_not_supported
, 0x01, NULL
, HFILL
}},
307 { &hf_usb_com_control_interface
,
308 { "bControlInterface", "usbcom.descriptor.control_interface", FT_UINT8
, BASE_HEX
,
309 NULL
, 0, NULL
, HFILL
}},
310 { &hf_usb_com_subordinate_interface
,
311 { "bSubordinateInterface", "usbcom.descriptor.subordinate_interface", FT_UINT8
, BASE_HEX
,
312 NULL
, 0, NULL
, HFILL
}},
313 { &hf_usb_com_descriptor_cm_capabilities_reserved
,
314 { "Reserved", "usbcom.descriptor.cm.capabilities.reserved", FT_UINT8
, BASE_HEX
,
315 NULL
, 0xFC, NULL
, HFILL
}},
316 { &hf_usb_com_descriptor_cm_capabilities_call_managment_over_data_class_interface
,
317 { "Call Managment over Data Class Interface", "usbcom.descriptor.cm.capabilities.call_managment_over_data_class_interface", FT_BOOLEAN
, 8,
318 &tfs_supported_not_supported
, 0x02, NULL
, HFILL
}},
319 { &hf_usb_com_descriptor_cm_capabilities_call_managment
,
320 { "Call Managment", "usbcom.descriptor.cm.capabilities.call_managment", FT_BOOLEAN
, 8,
321 &tfs_supported_not_supported
, 0x01, NULL
, HFILL
}},
322 { &hf_usb_com_descriptor_cm_data_interface
,
323 { "bDataInterface", "usbcom.descriptor.cm.data_interface", FT_UINT8
, BASE_HEX
,
324 NULL
, 0, NULL
, HFILL
}},
325 { &hf_usb_com_control_payload
,
326 { "Payload", "usbcom.control.payload", FT_BYTES
, BASE_NONE
,
327 NULL
, 0, NULL
, HFILL
}}
330 static gint
*usb_com_subtrees
[] = {
332 &ett_usb_com_capabilities
335 proto_usb_com
= proto_register_protocol("USB Communications and CDC Control", "USBCOM", "usbcom");
336 proto_register_field_array(proto_usb_com
, hf
, array_length(hf
));
337 proto_register_subtree_array(usb_com_subtrees
, array_length(usb_com_subtrees
));
341 proto_reg_handoff_usb_com(void)
343 dissector_handle_t usb_com_descriptor_handle
, usb_com_control_handle
, usb_com_bulk_handle
;
345 usb_com_descriptor_handle
= new_create_dissector_handle(dissect_usb_com_descriptor
, proto_usb_com
);
346 dissector_add_uint("usb.descriptor", IF_CLASS_COMMUNICATIONS
, usb_com_descriptor_handle
);
347 usb_com_control_handle
= new_create_dissector_handle(dissect_usb_com_control
, proto_usb_com
);
348 dissector_add_uint("usb.control", IF_CLASS_COMMUNICATIONS
, usb_com_control_handle
);
349 usb_com_bulk_handle
= new_create_dissector_handle(dissect_usb_com_bulk
, proto_usb_com
);
350 dissector_add_uint("usb.bulk", IF_CLASS_CDC_DATA
, usb_com_bulk_handle
);
351 mbim_control_handle
= find_dissector("mbim.control");
352 mbim_descriptor_handle
= find_dissector("mbim.descriptor");
353 mbim_bulk_handle
= find_dissector("mbim.bulk");
354 eth_withoutfcs_handle
= find_dissector("eth_withoutfcs");
358 * Editor modelines - http://www.wireshark.org/tools/modelines.html
363 * indent-tabs-mode: nil
366 * vi: set shiftwidth=4 tabstop=8 expandtab:
367 * :indentSize=4:tabSize=8:noTabs=true: