kernel - Revert part of the contig allocation work
[dragonfly.git] / contrib / tcpdump / print-usb.c
blob8e15e7bf39d1eb93c0e7960aed9ad4a699866f96
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 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include <tcpdump-stdinc.h>
28 #include <pcap.h>
29 #include <stdio.h>
30 #include <string.h>
32 #include "interface.h"
35 #if defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX)
36 #include <pcap/usb.h>
38 /* returns direction: 1=inbound 2=outbound -1=invalid */
39 static int
40 get_direction(int transfer_type, int event_type)
42 int direction;
44 direction = -1;
45 switch(transfer_type){
46 case URB_BULK:
47 case URB_CONTROL:
48 case URB_ISOCHRONOUS:
49 switch(event_type)
51 case URB_SUBMIT:
52 direction = 2;
53 break;
54 case URB_COMPLETE:
55 case URB_ERROR:
56 direction = 1;
57 break;
58 default:
59 direction = -1;
61 break;
62 case URB_INTERRUPT:
63 switch(event_type)
65 case URB_SUBMIT:
66 direction = 1;
67 break;
68 case URB_COMPLETE:
69 case URB_ERROR:
70 direction = 2;
71 break;
72 default:
73 direction = -1;
75 break;
76 default:
77 direction = -1;
80 return direction;
83 static void
84 usb_header_print(const pcap_usb_header *uh)
86 int direction;
88 switch(uh->transfer_type)
90 case URB_ISOCHRONOUS:
91 printf("ISOCHRONOUS");
92 break;
93 case URB_INTERRUPT:
94 printf("INTERRUPT");
95 break;
96 case URB_CONTROL:
97 printf("CONTROL");
98 break;
99 case URB_BULK:
100 printf("BULK");
101 break;
102 default:
103 printf(" ?");
106 switch(uh->event_type)
108 case URB_SUBMIT:
109 printf(" SUBMIT");
110 break;
111 case URB_COMPLETE:
112 printf(" COMPLETE");
113 break;
114 case URB_ERROR:
115 printf(" ERROR");
116 break;
117 default:
118 printf(" ?");
121 direction = get_direction(uh->transfer_type, uh->event_type);
122 if(direction == 1)
123 printf(" from");
124 else if(direction == 2)
125 printf(" to");
126 printf(" %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
131 * 48-byte header.
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.
137 u_int
138 usb_linux_48_byte_print(const struct pcap_pkthdr *h, register const u_char *p)
140 if (h->caplen < sizeof(pcap_usb_header)) {
141 printf("[|usb]");
142 return(sizeof(pcap_usb_header));
145 usb_header_print((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(const struct pcap_pkthdr *h, register const u_char *p)
162 if (h->caplen < sizeof(pcap_usb_header_mmapped)) {
163 printf("[|usb]");
164 return(sizeof(pcap_usb_header_mmapped));
167 usb_header_print((const pcap_usb_header *) p);
169 return(sizeof(pcap_usb_header_mmapped));
171 #endif /* DLT_USB_LINUX_MMAPPED */
173 #endif /* defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX) */