2 * Copyright 2009 Bert Vermeulen <bert@biot.com>
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.
18 * Support for USB packets
22 /* \summary: USB printer */
28 #include <netdissect-stdinc.h>
30 #include "netdissect.h"
33 #if defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX)
36 static const char tstr
[] = "[|usb]";
38 /* returns direction: 1=inbound 2=outbound -1=invalid */
40 get_direction(int transfer_type
, int event_type
)
45 switch(transfer_type
){
84 usb_header_print(netdissect_options
*ndo
, const pcap_usb_header
*uh
)
88 switch(uh
->transfer_type
)
91 ND_PRINT((ndo
, "ISOCHRONOUS"));
94 ND_PRINT((ndo
, "INTERRUPT"));
97 ND_PRINT((ndo
, "CONTROL"));
100 ND_PRINT((ndo
, "BULK"));
103 ND_PRINT((ndo
, " ?"));
106 switch(uh
->event_type
)
109 ND_PRINT((ndo
, " SUBMIT"));
112 ND_PRINT((ndo
, " COMPLETE"));
115 ND_PRINT((ndo
, " ERROR"));
118 ND_PRINT((ndo
, " ?"));
121 direction
= get_direction(uh
->transfer_type
, uh
->event_type
);
123 ND_PRINT((ndo
, " from"));
124 else if(direction
== 2)
125 ND_PRINT((ndo
, " to"));
126 ND_PRINT((ndo
, " %d:%d:%d", uh
->bus_id
, uh
->device_address
, uh
->endpoint_number
& 0x7f));
130 * This is the top level routine of the printer for captures with a
133 * 'p' points to the header of the packet, 'h->ts' is the timestamp,
134 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
135 * is the number of bytes actually captured.
138 usb_linux_48_byte_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
,
139 register const u_char
*p
)
141 if (h
->caplen
< sizeof(pcap_usb_header
)) {
142 ND_PRINT((ndo
, "%s", tstr
));
143 return(sizeof(pcap_usb_header
));
146 usb_header_print(ndo
, (const pcap_usb_header
*) p
);
148 return(sizeof(pcap_usb_header
));
151 #ifdef DLT_USB_LINUX_MMAPPED
153 * This is the top level routine of the printer for captures with a
156 * 'p' points to the header of the packet, 'h->ts' is the timestamp,
157 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
158 * is the number of bytes actually captured.
161 usb_linux_64_byte_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
,
162 register const u_char
*p
)
164 if (h
->caplen
< sizeof(pcap_usb_header_mmapped
)) {
165 ND_PRINT((ndo
, "%s", tstr
));
166 return(sizeof(pcap_usb_header_mmapped
));
169 usb_header_print(ndo
, (const pcap_usb_header
*) p
);
171 return(sizeof(pcap_usb_header_mmapped
));
173 #endif /* DLT_USB_LINUX_MMAPPED */
175 #endif /* defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX) */