]> The Tcpdump Group git mirrors - tcpdump/blob - print-usb.c
We have to set the filter on every new file.
[tcpdump] / print-usb.c
1 /*
2 * Copyright 2009 Bert Vermeulen <bert@biot.com>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code distributions
6 * retain the above copyright notice and this paragraph in its entirety, (2)
7 * distributions including binary code include the above copyright notice and
8 * this paragraph in its entirety in the documentation or other materials
9 * provided with the distribution, and (3) all advertising materials mentioning
10 * features or use of this software display the following acknowledgement:
11 * ``This product includes software developed by Paolo Abeni.''
12 * The name of author may not be used to endorse or promote products derived
13 * from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * Support for USB packets
19 *
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <netdissect-stdinc.h>
27
28 #include "netdissect.h"
29
30
31 #if defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX)
32 #include <pcap/usb.h>
33
34 static const char tstr[] = "[|usb]";
35
36 /* returns direction: 1=inbound 2=outbound -1=invalid */
37 static int
38 get_direction(int transfer_type, int event_type)
39 {
40 int direction;
41
42 direction = -1;
43 switch(transfer_type){
44 case URB_BULK:
45 case URB_CONTROL:
46 case URB_ISOCHRONOUS:
47 switch(event_type)
48 {
49 case URB_SUBMIT:
50 direction = 2;
51 break;
52 case URB_COMPLETE:
53 case URB_ERROR:
54 direction = 1;
55 break;
56 default:
57 direction = -1;
58 }
59 break;
60 case URB_INTERRUPT:
61 switch(event_type)
62 {
63 case URB_SUBMIT:
64 direction = 1;
65 break;
66 case URB_COMPLETE:
67 case URB_ERROR:
68 direction = 2;
69 break;
70 default:
71 direction = -1;
72 }
73 break;
74 default:
75 direction = -1;
76 }
77
78 return direction;
79 }
80
81 static void
82 usb_header_print(netdissect_options *ndo, const pcap_usb_header *uh)
83 {
84 int direction;
85
86 switch(uh->transfer_type)
87 {
88 case URB_ISOCHRONOUS:
89 ND_PRINT((ndo, "ISOCHRONOUS"));
90 break;
91 case URB_INTERRUPT:
92 ND_PRINT((ndo, "INTERRUPT"));
93 break;
94 case URB_CONTROL:
95 ND_PRINT((ndo, "CONTROL"));
96 break;
97 case URB_BULK:
98 ND_PRINT((ndo, "BULK"));
99 break;
100 default:
101 ND_PRINT((ndo, " ?"));
102 }
103
104 switch(uh->event_type)
105 {
106 case URB_SUBMIT:
107 ND_PRINT((ndo, " SUBMIT"));
108 break;
109 case URB_COMPLETE:
110 ND_PRINT((ndo, " COMPLETE"));
111 break;
112 case URB_ERROR:
113 ND_PRINT((ndo, " ERROR"));
114 break;
115 default:
116 ND_PRINT((ndo, " ?"));
117 }
118
119 direction = get_direction(uh->transfer_type, uh->event_type);
120 if(direction == 1)
121 ND_PRINT((ndo, " from"));
122 else if(direction == 2)
123 ND_PRINT((ndo, " to"));
124 ND_PRINT((ndo, " %d:%d:%d", uh->bus_id, uh->device_address, uh->endpoint_number & 0x7f));
125 }
126
127 /*
128 * This is the top level routine of the printer for captures with a
129 * 48-byte header.
130 *
131 * 'p' points to the header of the packet, 'h->ts' is the timestamp,
132 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
133 * is the number of bytes actually captured.
134 */
135 u_int
136 usb_linux_48_byte_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
137 register const u_char *p)
138 {
139 if (h->caplen < sizeof(pcap_usb_header)) {
140 ND_PRINT((ndo, "%s", tstr));
141 return(sizeof(pcap_usb_header));
142 }
143
144 usb_header_print(ndo, (const pcap_usb_header *) p);
145
146 return(sizeof(pcap_usb_header));
147 }
148
149 #ifdef DLT_USB_LINUX_MMAPPED
150 /*
151 * This is the top level routine of the printer for captures with a
152 * 64-byte header.
153 *
154 * 'p' points to the header of the packet, 'h->ts' is the timestamp,
155 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
156 * is the number of bytes actually captured.
157 */
158 u_int
159 usb_linux_64_byte_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
160 register const u_char *p)
161 {
162 if (h->caplen < sizeof(pcap_usb_header_mmapped)) {
163 ND_PRINT((ndo, "%s", tstr));
164 return(sizeof(pcap_usb_header_mmapped));
165 }
166
167 usb_header_print(ndo, (const pcap_usb_header *) p);
168
169 return(sizeof(pcap_usb_header_mmapped));
170 }
171 #endif /* DLT_USB_LINUX_MMAPPED */
172
173 #endif /* defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX) */
174