int usb_detach_kernel_driver_np(usb_dev_handle * dev, int interface) { struct libusb20_device *pdev; int err; pdev = (void *)dev; if (pdev == NULL) return (-1); err = libusb20_dev_detach_kernel_driver(pdev, interface); if (err != 0) return (-1); return (0); }
static void exec_host_modem_test(struct modem *p, uint16_t vid, uint16_t pid) { struct libusb20_device *pdev; uint8_t ntest = 0; uint8_t x; uint8_t in_ep; uint8_t out_ep; uint8_t iface; int error; pdev = find_usb_device(vid, pid); if (pdev == NULL) { printf("USB device not found\n"); return; } if (p->use_vendor_specific) find_usb_endpoints(pdev, 255, 255, 255, 0, &iface, &in_ep, &out_ep, 0); else find_usb_endpoints(pdev, 2, 2, 1, 0, &iface, &in_ep, &out_ep, 1); if ((in_ep == 0) || (out_ep == 0)) { printf("Could not find USB endpoints\n"); libusb20_dev_free(pdev); return; } printf("Attaching to: %s @ iface %d\n", libusb20_dev_get_desc(pdev), iface); if (libusb20_dev_open(pdev, 2)) { printf("Could not open USB device\n"); libusb20_dev_free(pdev); return; } if (libusb20_dev_detach_kernel_driver(pdev, iface)) { printf("WARNING: Could not detach kernel driver\n"); } p->xfer_in = libusb20_tr_get_pointer(pdev, 0); error = libusb20_tr_open(p->xfer_in, 65536 / 4, 1, in_ep); if (error) { printf("Could not open USB endpoint %d\n", in_ep); libusb20_dev_free(pdev); return; } p->xfer_out = libusb20_tr_get_pointer(pdev, 1); error = libusb20_tr_open(p->xfer_out, 65536 / 4, 1, out_ep); if (error) { printf("Could not open USB endpoint %d\n", out_ep); libusb20_dev_free(pdev); return; } p->usb_dev = pdev; p->usb_iface = iface; p->errors = 0; if (p->control_ep_test) ntest += 7; if (p->data_stress_test) ntest += 1; if (ntest == 0) { printf("No tests selected\n"); } else { if (p->control_ep_test) { for (x = 1; x != 8; x++) { usb_modem_control_ep_test(p, (p->duration + ntest - 1) / ntest, x); } } if (p->data_stress_test) { usb_modem_data_stress_test(p, (p->duration + ntest - 1) / ntest); } } printf("\nDone\n"); libusb20_dev_free(pdev); }
void usb_set_alt_interface_test(uint16_t vid, uint16_t pid) { struct libusb20_device *pdev; struct libusb20_config *config; int iter; int error; int errcnt; int n; int m; pdev = find_usb_device(vid, pid); if (pdev == NULL) { printf("USB device not found\n"); return; } printf("Starting set alternate setting test " "for VID=0x%04x PID=0x%04x\n", vid, pid); config = libusb20_dev_alloc_config(pdev, libusb20_dev_get_config_index(pdev)); if (config == NULL) { printf("Could not get configuration descriptor\n"); libusb20_dev_free(pdev); return; } iter = 0; errcnt = 0; for (n = 0; n != config->num_interface; n++) { /* detach kernel driver */ libusb20_dev_detach_kernel_driver(pdev, n); error = libusb20_dev_open(pdev, 0); if (error) printf("ERROR could not open device\n"); /* Try the alternate settings */ for (m = 0; m != config->interface[n].num_altsetting; m++) { iter++; if (libusb20_dev_set_alt_index(pdev, n, m + 1)) { printf("ERROR on interface %d alt %d\n", n, m + 1); errcnt++; } } /* Restore to default */ iter++; if (libusb20_dev_set_alt_index(pdev, n, 0)) { printf("ERROR on interface %d alt %d\n", n, 0); errcnt++; } libusb20_dev_close(pdev); } libusb20_dev_free(pdev); printf("\n" "Test summary\n" "============\n" "Interfaces tested: %d\n" "Errors: %d\n", iter, errcnt); }