Remove armeb FreeBSD 6 compat shim
[freebsd-src.git] / contrib / tcpdump / print-usb.c
blob75f78fc9025a825a4fc3064b768a00ddd4868b4b
1 /*
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 #define NETDISSECT_REWORKED
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <tcpdump-stdinc.h>
29 #include "interface.h"
32 #if defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX)
33 #include <pcap/usb.h>
35 static const char tstr[] = "[|usb]";
37 /* returns direction: 1=inbound 2=outbound -1=invalid */
38 static int
39 get_direction(int transfer_type, int event_type)
41 int direction;
43 direction = -1;
44 switch(transfer_type){
45 case URB_BULK:
46 case URB_CONTROL:
47 case URB_ISOCHRONOUS:
48 switch(event_type)
50 case URB_SUBMIT:
51 direction = 2;
52 break;
53 case URB_COMPLETE:
54 case URB_ERROR:
55 direction = 1;
56 break;
57 default:
58 direction = -1;
60 break;
61 case URB_INTERRUPT:
62 switch(event_type)
64 case URB_SUBMIT:
65 direction = 1;
66 break;
67 case URB_COMPLETE:
68 case URB_ERROR:
69 direction = 2;
70 break;
71 default:
72 direction = -1;
74 break;
75 default:
76 direction = -1;
79 return direction;
82 static void
83 usb_header_print(netdissect_options *ndo, const pcap_usb_header *uh)
85 int direction;
87 switch(uh->transfer_type)
89 case URB_ISOCHRONOUS:
90 ND_PRINT((ndo, "ISOCHRONOUS"));
91 break;
92 case URB_INTERRUPT:
93 ND_PRINT((ndo, "INTERRUPT"));
94 break;
95 case URB_CONTROL:
96 ND_PRINT((ndo, "CONTROL"));
97 break;
98 case URB_BULK:
99 ND_PRINT((ndo, "BULK"));
100 break;
101 default:
102 ND_PRINT((ndo, " ?"));
105 switch(uh->event_type)
107 case URB_SUBMIT:
108 ND_PRINT((ndo, " SUBMIT"));
109 break;
110 case URB_COMPLETE:
111 ND_PRINT((ndo, " COMPLETE"));
112 break;
113 case URB_ERROR:
114 ND_PRINT((ndo, " ERROR"));
115 break;
116 default:
117 ND_PRINT((ndo, " ?"));
120 direction = get_direction(uh->transfer_type, uh->event_type);
121 if(direction == 1)
122 ND_PRINT((ndo, " from"));
123 else if(direction == 2)
124 ND_PRINT((ndo, " to"));
125 ND_PRINT((ndo, " %d:%d:%d", uh->bus_id, uh->device_address, uh->endpoint_number & 0x7f));
129 * This is the top level routine of the printer for captures with a
130 * 48-byte header.
132 * 'p' points to the header of the packet, 'h->ts' is the timestamp,
133 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
134 * is the number of bytes actually captured.
136 u_int
137 usb_linux_48_byte_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
138 register const u_char *p)
140 if (h->caplen < sizeof(pcap_usb_header)) {
141 ND_PRINT((ndo, "%s", tstr));
142 return(sizeof(pcap_usb_header));
145 usb_header_print(ndo, (const pcap_usb_header *) p);
147 return(sizeof(pcap_usb_header));
150 #ifdef DLT_USB_LINUX_MMAPPED
152 * This is the top level routine of the printer for captures with a
153 * 64-byte header.
155 * 'p' points to the header of the packet, 'h->ts' is the timestamp,
156 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
157 * is the number of bytes actually captured.
159 u_int
160 usb_linux_64_byte_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
161 register const u_char *p)
163 if (h->caplen < sizeof(pcap_usb_header_mmapped)) {
164 ND_PRINT((ndo, "%s", tstr));
165 return(sizeof(pcap_usb_header_mmapped));
168 usb_header_print(ndo, (const pcap_usb_header *) p);
170 return(sizeof(pcap_usb_header_mmapped));
172 #endif /* DLT_USB_LINUX_MMAPPED */
174 #endif /* defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX) */