tmp = netlink_message_parse(buffer, len, "BUSNUM");
if (NULL == tmp) {
- /* no bus number (likely a usb interface). ignore*/
- return -1;
+ /* no bus number. try "DEVICE" */
+ tmp = netlink_message_parse(buffer, len, "DEVICE");
+ if (NULL == tmp) {
+ /* not usb. ignore */
+ return -1;
+ }
+
+ /* Parse a device path such as /dev/bus/usb/003/004 */
+ char *pLastSlash = (char*)strrchr(tmp,'/');
+ if(NULL == pLastSlash) {
+ return -1;
+ }
+
+ *devaddr = strtoul(pLastSlash + 1, NULL, 10);
+ if (errno) {
+ errno = 0;
+ return -1;
+ }
+
+ *busnum = strtoul(pLastSlash - 3, NULL, 10);
+ if (errno) {
+ errno = 0;
+ return -1;
+ }
+
+ return 0;
}
*busnum = (uint8_t)(strtoul(tmp, NULL, 10) & 0xff);
struct libusb_context *ctx = DEVICE_CTX(dev);
char path[PATH_MAX];
int fd;
+ int delay = 10000;
if (usbdev_names)
snprintf(path, PATH_MAX, "%s/usbdev%d.%d",
if (fd != -1)
return fd; /* Success */
+ if (errno == ENOENT) {
+ if (!silent)
+ usbi_err(ctx, "File doesn't exist, wait %d ms and try again\n", delay/1000);
+
+ /* Wait 10ms for USB device path creation.*/
+ usleep(delay);
+
+ fd = open(path, mode);
+ if (fd != -1)
+ return fd; /* Success */
+ }
+
if (!silent) {
usbi_err(ctx, "libusb couldn't open USB device %s: %s",
path, strerror(errno));