aboutsummaryrefslogtreecommitdiffstats
path: root/pcap-usb-linux.c
diff options
context:
space:
mode:
authorguy <guy>2008-12-23 21:38:50 +0000
committerguy <guy>2008-12-23 21:38:50 +0000
commitadcaff491d684600e229333dbee0179b1505b495 (patch)
treecbf0134532aa3ff5e4f1d99775dc51e1233488cf /pcap-usb-linux.c
parenta6693354156136b101601f91379149aec6b97da9 (diff)
Get some USB information from <linux/usb/ch9.h> rather than defining it
ourselves. Add some comments and other tweaks from another of Jon Smirl's patches.
Diffstat (limited to 'pcap-usb-linux.c')
-rw-r--r--pcap-usb-linux.c30
1 files changed, 14 insertions, 16 deletions
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 <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
+#include <linux/usb/ch9.h>
#ifdef HAVE_LINUX_USBDEVICE_FS_H
#include <linux/usbdevice_fs.h>
#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);