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
|
/* packet-usb.h
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __PACKET_USB_H__
#define __PACKET_USB_H__
#include <epan/value_string.h>
#include <epan/wmem/wmem.h>
#include <epan/conversation.h>
typedef struct _usb_address_t {
guint32 device;
guint32 endpoint;
guint16 bus_id;
} usb_address_t;
#define USB_ADDR_LEN (sizeof(usb_address_t))
/* Flag used to mark usb_address_t.endpoint as an interface
* address instead of the normal endpoint address.
*/
#define INTERFACE_PORT 0x80000000
typedef struct _usb_conv_info_t usb_conv_info_t;
/* header flags */
#define USB_HEADER_IS_LINUX (1 << 0)
#define USB_HEADER_IS_64_BYTES (1 << 1)
#define USB_HEADER_IS_USBPCAP (1 << 2)
#define USB_HEADER_IS_MAUSB (1 << 3)
/* there is one such structure for each request/response */
typedef struct _usb_trans_info_t {
guint32 request_in;
guint32 response_in;
nstime_t req_time;
guint8 header_info;
/* Valid only for SETUP transactions */
struct _usb_setup {
guint8 requesttype;
guint8 request;
guint16 wValue;
guint16 wIndex;
guint16 wLength;
} setup;
/* Valid only during GET DESCRIPTOR transactions */
union {
struct {
guint8 type;
guint8 index;
} get_descriptor;
} u;
/* used to pass the interface class from the
* interface descriptor onto the endpoint
* descriptors so that we can create a
* conversation with the appropriate class
* once we know the endpoint.
* Valid only during GET CONFIGURATION response.
*/
usb_conv_info_t *interface_info;
} usb_trans_info_t;
/* Conversation Structure
* there is one such structure for each device/endpoint conversation */
struct _usb_conv_info_t {
guint16 bus_id;
guint16 device_address;
guint8 endpoint;
gint direction;
guint8 transfer_type;
guint32 device_protocol;
gboolean is_request;
gboolean is_setup;
guint8 setup_requesttype;
guint16 interfaceClass; /* Interface Descriptor - class */
guint16 interfaceSubclass; /* Interface Descriptor - subclass */
guint16 interfaceProtocol; /* Interface Descriptor - protocol */
guint8 interfaceNum; /* Most recent interface number */
guint16 deviceVendor; /* Device Descriptor - USB Vendor ID */
guint32 deviceProduct; /* Device Descriptor - USB Product ID - MSBs only for encoding unknown */
wmem_tree_t *transactions;
usb_trans_info_t *usb_trans_info; /* pointer to the current transaction */
void *class_data; /* private class/id decode data */
};
/* This is what a tap will tap */
typedef struct _usb_tap_data_t {
guint8 urb_type;
guint8 transfer_type;
usb_conv_info_t *conv_info;
usb_trans_info_t *trans_info;
} usb_tap_data_t;
/* the value for "no endpoint" that's used usb_addr_t, e.g. for the address of the host */
#define NO_ENDPOINT 0xffffffff
/* the 8bit version of NO_ENDPOINT, it's used in usb_conv_info_t
0xff would be an invalid endpoint number (reserved bits are 1) */
#define NO_ENDPOINT8 ((guint8)(NO_ENDPOINT& G_MAXUINT8))
/*
* Values from the Linux USB pseudo-header.
*/
/*
* event_type values
*/
#define URB_SUBMIT 'S'
#define URB_COMPLETE 'C'
#define URB_ERROR 'E'
/*
* URB transfer_type values
*/
#define URB_ISOCHRONOUS 0x0
#define URB_INTERRUPT 0x1
#define URB_CONTROL 0x2
#define URB_BULK 0x3
#define URB_UNKNOWN 0xFF
#define URB_TRANSFER_IN 0x80 /* to host */
/* http://www.usb.org/developers/defined_class */
#define IF_CLASS_DEVICE 0x00
#define IF_CLASS_AUDIO 0x01
#define IF_CLASS_COMMUNICATIONS 0x02
#define IF_CLASS_HID 0x03
#define IF_CLASS_PHYSICAL 0x05
#define IF_CLASS_IMAGE 0x06
#define IF_CLASS_PRINTER 0x07
#define IF_CLASS_MASS_STORAGE 0x08
#define IF_CLASS_HUB 0x09
#define IF_CLASS_CDC_DATA 0x0a
#define IF_CLASS_SMART_CARD 0x0b
#define IF_CLASS_CONTENT_SECURITY 0x0d
#define IF_CLASS_VIDEO 0x0e
#define IF_CLASS_PERSONAL_HEALTHCARE 0x0f
#define IF_CLASS_AUDIO_VIDEO 0x10
#define IF_CLASS_DIAGNOSTIC_DEVICE 0xdc
#define IF_CLASS_WIRELESS_CONTROLLER 0xe0
#define IF_CLASS_MISCELLANEOUS 0xef
#define IF_CLASS_APPLICATION_SPECIFIC 0xfe
#define IF_CLASS_VENDOR_SPECIFIC 0xff
#define IF_CLASS_UNKNOWN 0xffff
#define IF_SUBCLASS_UNKNOWN 0xffff
#define IF_PROTOCOL_UNKNOWN 0xffff
#define DEV_VENDOR_UNKNOWN 0x0000 /* this id is unassigned */
#define DEV_PRODUCT_UNKNOWN 0xfffffff /* 0x0000 and 0xffff are used values by vendors, so MSBs encode unknown */
/* bmRequestType values */
#define USB_DIR_OUT 0 /* to device */
#define USB_DIR_IN 0x80 /* to host */
#define USB_TYPE_MASK (0x03 << 5)
#define USB_TYPE(type) (((type) & USB_TYPE_MASK) >> 5)
#define RQT_SETUP_TYPE_STANDARD 0
#define RQT_SETUP_TYPE_CLASS 1
#define RQT_SETUP_TYPE_VENDOR 2
#define USB_RECIPIENT_MASK 0x1F
#define USB_RECIPIENT(type) ((type) & USB_RECIPIENT_MASK)
#define RQT_SETUP_RECIPIENT_DEVICE 0
#define RQT_SETUP_RECIPIENT_INTERFACE 1
#define RQT_SETUP_RECIPIENT_ENDPOINT 2
#define RQT_SETUP_RECIPIENT_OTHER 3
/* Endpoint descriptor bmAttributes */
#define ENDPOINT_TYPE(ep_attrib) ((ep_attrib) & 0x03)
#define ENDPOINT_TYPE_CONTROL 0
#define ENDPOINT_TYPE_ISOCHRONOUS 1
#define ENDPOINT_TYPE_BULK 2
#define ENDPOINT_TYPE_INTERRUPT 3
/* 9.6.6 */
extern const true_false_string tfs_endpoint_direction;
usb_conv_info_t *
get_usb_conv_info(conversation_t *conversation);
conversation_t *
get_usb_conversation(packet_info *pinfo,
address *src_addr, address *dst_addr,
guint32 src_endpoint, guint32 dst_endpoint);
usb_conv_info_t *get_usb_iface_conv_info(packet_info *pinfo, guint8 interface_num);
proto_item * dissect_usb_descriptor_header(proto_tree *tree,
tvbuff_t *tvb, int offset,
value_string_ext *type_val_str);
void dissect_usb_endpoint_address(proto_tree *tree, tvbuff_t *tvb, int offset);
int
dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
tvbuff_t *tvb, int offset,
usb_conv_info_t *usb_conv_info);
int
dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
tvbuff_t *tvb, int offset,
usb_conv_info_t *usb_conv_info _U_);
int
dissect_usb_setup_response(packet_info *pinfo, proto_tree *tree,
proto_tree *parent, tvbuff_t *tvb, int offset,
guint8 urb_type, usb_conv_info_t *usb_conv_info);
int
dissect_usb_setup_request(packet_info *pinfo, proto_tree *tree,
proto_tree *parent, tvbuff_t *tvb, int offset,
guint8 urb_type, usb_conv_info_t *usb_conv_info,
guint8 header_info);
void
usb_set_addr(packet_info *pinfo, usb_address_t *src_addr,
usb_address_t *dst_addr, guint16 bus_id, guint16 device_address,
int endpoint, gboolean req);
usb_trans_info_t
*usb_get_trans_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
guint8 header_info, usb_conv_info_t *usb_conv_info);
#endif
|