From adcaff491d684600e229333dbee0179b1505b495 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 23 Dec 2008 21:38:50 +0000 Subject: Get some USB information from rather than defining it ourselves. Add some comments and other tweaks from another of Jon Smirl's patches. --- pcap-usb-linux.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'pcap-usb-linux.c') diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c index 4eda913..b4b8952 100644 --- a/pcap-usb-linux.c +++ b/pcap-usb-linux.c @@ -34,7 +34,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-usb-linux.c,v 1.32 2008-12-23 20:55:28 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-usb-linux.c,v 1.33 2008-12-23 21:38:50 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -60,6 +60,7 @@ static const char rcsid[] _U_ = #include #include #include +#include #ifdef HAVE_LINUX_USBDEVICE_FS_H #include #endif @@ -207,28 +208,26 @@ int usb_mmap(pcap_t* handle) #define CTRL_TIMEOUT (5*1000) /* milliseconds */ -#define USB_ENDPOINT_IN 0x80 -#define USB_TYPE_STANDARD 0x00 -#define USB_RECIP_DEVICE 0x00 - -#define USB_REQ_GET_DESCRIPTOR 6 - -#define USB_DT_DEVICE 1 - +/* probe the descriptors of the devices attached to the bus */ +/* the descriptors will end up in the captured packet stream */ +/* and be decoded by external apps like wireshark */ +/* without these identifying probes packet data can't be fully decoded */ static void probe_devices(int bus) { struct usbdevfs_ctrltransfer ctrl; + struct usb_device_descriptor device; struct dirent* data; int ret = 0; char buf[40]; DIR* dir; - /* scan profs usb bus directories */ - snprintf(buf, sizeof buf, "/dev/bus/usb/%03d", bus); + /* scan usb bus directories for device nodes */ + snprintf(buf, sizeof(buf), "/dev/bus/usb/%03d", bus); dir = opendir(buf); if (!dir) return; + while ((ret >= 0) && ((data = readdir(dir)) != 0)) { int fd; char* name = data->d_name; @@ -236,19 +235,18 @@ probe_devices(int bus) if (name[0] == '.') continue; - snprintf(buf, sizeof buf, "/dev/bus/usb/%03d/%s", bus, data->d_name); + snprintf(buf, sizeof(buf), "/dev/bus/usb/%03d/%s", bus, data->d_name); fd = open(buf, O_RDWR); if (fd == -1) continue; - ctrl.bRequestType = USB_ENDPOINT_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; + ctrl.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; ctrl.bRequest = USB_REQ_GET_DESCRIPTOR; ctrl.wValue = USB_DT_DEVICE << 8; ctrl.wIndex = 0; - ctrl.wLength = sizeof buf; - - ctrl.data = buf; + ctrl.wLength = sizeof(device); + ctrl.data = &device; ctrl.timeout = CTRL_TIMEOUT; ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl); -- cgit v1.2.3