int usb_reset(usb_dev_handle * dev) { int err; err = libusb20_dev_reset((void *)dev); if (err) return (-1); /* * Be compatible with LibUSB from sourceforge and close the * handle after reset! */ return (usb_close(dev)); }
void usb_port_reset_test(uint16_t vid, uint16_t pid, uint32_t duration) { struct timeval sub_tv; struct timeval ref_tv; struct timeval res_tv; struct libusb20_device *pdev; int error; int iter; int errcnt; time_t last_sec; /* sysctl() - no set config */ pdev = find_usb_device(vid, pid); if (pdev == NULL) { printf("USB device not found\n"); return; } error = libusb20_dev_open(pdev, 0); if (error) { libusb20_dev_free(pdev); printf("Could not open USB device\n"); return; } iter = 0; errcnt = 0; gettimeofday(&ref_tv, 0); last_sec = ref_tv.tv_sec; while (1) { gettimeofday(&sub_tv, 0); if (last_sec != sub_tv.tv_sec) { printf("STATUS: ID=%u, ERR=%u\n", (int)iter, (int)errcnt); fflush(stdout); last_sec = sub_tv.tv_sec; } timersub(&sub_tv, &ref_tv, &res_tv); if ((res_tv.tv_sec < 0) || (res_tv.tv_sec >= (int)duration)) break; if (libusb20_dev_reset(pdev)) { errcnt++; usleep(50000); } if (libusb20_dev_check_connected(pdev) != 0) { printf("Device disconnected\n"); break; } iter++; } libusb20_dev_reset(pdev); libusb20_dev_free(pdev); }