--- detach-yealink.c 2007-08-26 09:38:38.000000000 -0700 +++ detach-usb.c 2007-08-26 09:24:19.000000000 -0700 @@ -1,5 +1,5 @@ /* - * detach-yealink.c - a tool to detach a kernel module from a yealink device + * detach-usb.c - a tool to detach a kernel module from a USB device * Copyright (C) 2007 Thomas Reitmayr * * This program is free software; you can redistribute it and/or modify @@ -33,11 +33,6 @@ #include -#define VENDOR 0x6993 -#define PRODUCT 0xb001 -#define INTERFACE 3 - - #define USB_PATH1 "/dev/bus/usb" #define USB_PATH2 "/proc/bus/usb" @@ -61,7 +56,7 @@ }; -int check_dir(char *dirname) +int check_dir(char *dirname, unsigned vendor, unsigned product) { DIR *dir; struct dirent *entry; @@ -78,7 +73,7 @@ continue; snprintf(filepath, sizeof(filepath) - 1, "%s/%s", dirname, entry->d_name); if (entry->d_type & DT_DIR) { - fd = check_dir(filepath); + fd = check_dir(filepath, vendor, product); } else { printf("checking %s\n", filepath); @@ -93,10 +88,10 @@ } else { /* compare IDs */ - int vendorid = (device_desc[9] << 8) | device_desc[8]; - int productid = (device_desc[11] << 8) | device_desc[10]; + unsigned vendorid = (device_desc[9] << 8) | device_desc[8]; + unsigned productid = (device_desc[11] << 8) | device_desc[10]; printf(" v=%04x, p=%04x\n", vendorid, productid); - if ((vendorid != VENDOR) || (productid != PRODUCT)) { + if ((vendorid != vendor) || (productid != product)) { close(fd); fd = -1; } @@ -112,13 +107,13 @@ } -char *driver(int fd) +char *driver(int fd, unsigned interface) { struct usb_getdriver getdrv; static char drv[USB_MAXDRIVERNAME + 1]; int ret; - getdrv.interface = INTERFACE; + getdrv.interface = interface; ret = ioctl(fd, IOCTL_USB_GETDRIVER, &getdrv); if (ret) { if (errno == ENODATA) { @@ -136,12 +131,12 @@ } -int detach(int fd) +int detach(int fd, unsigned interface) { struct usb_ioctl command; int ret; - command.ifno = INTERFACE; + command.ifno = interface; command.ioctl_code = IOCTL_USB_DISCONNECT; command.data = NULL; @@ -152,28 +147,35 @@ return ret; } - +#define USAGE "Usage: detach-usb VENDOR PRODUCT INTERFACE\n" int main(int argc, char **argv) { - int fd; - int ret = 0; + if (argc < 4) { + fputs("detach-usb: missing operands\n" USAGE, stderr); + exit(EXIT_FAILURE); + } + + unsigned vendor = strtoul(argv[1], NULL, 16); + unsigned product = strtoul(argv[2], NULL, 16); + unsigned interface = strtoul(argv[3], NULL, 16); - fd = check_dir(USB_PATH1); + int ret = 0; + int fd = check_dir(USB_PATH1, vendor, product); if (fd < 0) - fd = check_dir(USB_PATH2); + fd = check_dir(USB_PATH2, vendor, product); if (fd < 0) { - printf("could not find yealink device\n"); + printf("could not find USB device\n"); ret = 1; } else { char *drv; - printf("found yealink device\n"); - drv = driver(fd); + printf("found USB device\n"); + drv = driver(fd, interface); if (drv) { if (drv[0]) { - if (detach(fd) == 0) { + if (detach(fd, interface) == 0) { printf("successfully detached driver %s\n", drv); } else {