]> The Tcpdump Group git mirrors - tcpdump/blob - print-usb.c
From Bert Vermeulen: add a USB printer, and fix the error message
[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 <tcpdump-stdinc.h>
27
28 #include <pcap.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "interface.h"
33
34
35 #if defined(HAVE_PCAP_USB_H) && defined(DLT_USB_LINUX)
36 #include <pcap/usb.h>
37
38 /* returns direction: 1=inbound 2=outbound -1=invalid */
39 static int get_direction(int transfer_type, int event_type)
40 {
41 int direction;
42
43 direction = -1;
44 switch(transfer_type){
45 case URB_BULK:
46 case URB_CONTROL:
47 case URB_ISOCHRONOUS:
48 switch(event_type)
49 {
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;
59 }
60 break;
61 case URB_INTERRUPT:
62 switch(event_type)
63 {
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;
73 }
74 break;
75 default:
76 direction = -1;
77 }
78
79 return direction;
80 }
81
82
83 u_int usb_linux_print(const struct pcap_pkthdr *h, register const u_char *p)
84 {
85 const pcap_usb_header *uh;
86 int direction;
87
88 uh = (const pcap_usb_header *) p;
89 switch(uh->transfer_type)
90 {
91 case URB_ISOCHRONOUS:
92 printf("ISOCHRONOUS");
93 break;
94 case URB_INTERRUPT:
95 printf("INTERRUPT");
96 break;
97 case URB_CONTROL:
98 printf("CONTROL");
99 break;
100 case URB_BULK:
101 printf("BULK");
102 break;
103 default:
104 printf(" ?");
105 }
106
107 switch(uh->event_type)
108 {
109 case URB_SUBMIT:
110 printf(" SUBMIT");
111 break;
112 case URB_COMPLETE:
113 printf(" COMPLETE");
114 break;
115 case URB_ERROR:
116 printf(" ERROR");
117 break;
118 default:
119 printf(" ?");
120 }
121
122 direction = get_direction(uh->transfer_type, uh->event_type);
123 if(direction == 1)
124 printf(" from");
125 else if(direction == 2)
126 printf(" to");
127 printf(" %d:%d:%d", uh->bus_id, uh->device_address, uh->endpoint_number & 0x7f);
128
129 return(sizeof(pcap_usb_header));
130 }
131
132 #endif
133