Have separate buffers for device pathnames and USB device descriptors;
that may take extra memory on the stack, but it makes the code somewhat
cleaner.
+#define USB_DEVICE_DESCRIPTOR_SIZE 18
+
/* 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 */
/* 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 */
struct usbdevfs_ctrltransfer ctrl;
struct dirent* data;
int ret = 0;
struct usbdevfs_ctrltransfer ctrl;
struct dirent* data;
int ret = 0;
- char buf[sizeof("/dev/bus/usb/000/") + NAME_MAX];
+ char busdevpath[sizeof("/dev/bus/usb/000/") + NAME_MAX];
+ char descriptor[USB_DEVICE_DESCRIPTOR_SIZE];
/* scan usb bus directories for device nodes */
/* scan usb bus directories for device nodes */
- snprintf(buf, sizeof(buf), "/dev/bus/usb/%03d", bus);
- dir = opendir(buf);
+ snprintf(busdevpath, sizeof(busdevpath), "/dev/bus/usb/%03d", bus);
+ dir = opendir(busdevpath);
if (name[0] == '.')
continue;
if (name[0] == '.')
continue;
- snprintf(buf, sizeof(buf), "/dev/bus/usb/%03d/%s", bus, data->d_name);
+ snprintf(busdevpath, sizeof(busdevpath), "/dev/bus/usb/%03d/%s", bus, data->d_name);
- fd = open(buf, O_RDWR);
+ fd = open(busdevpath, O_RDWR);
ctrl.bRequest = USB_REQ_GET_DESCRIPTOR;
ctrl.wValue = USB_DT_DEVICE << 8;
ctrl.wIndex = 0;
ctrl.bRequest = USB_REQ_GET_DESCRIPTOR;
ctrl.wValue = USB_DT_DEVICE << 8;
ctrl.wIndex = 0;
- ctrl.wLength = sizeof(buf);
+ ctrl.wLength = sizeof(descriptor);
#else
ctrl.requesttype = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
ctrl.request = USB_REQ_GET_DESCRIPTOR;
ctrl.value = USB_DT_DEVICE << 8;
ctrl.index = 0;
#else
ctrl.requesttype = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
ctrl.request = USB_REQ_GET_DESCRIPTOR;
ctrl.value = USB_DT_DEVICE << 8;
ctrl.index = 0;
- ctrl.length = sizeof(buf);
+ ctrl.length = sizeof(descriptor);
+ ctrl.data = descriptor;
ctrl.timeout = CTRL_TIMEOUT;
ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
ctrl.timeout = CTRL_TIMEOUT;
ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl);