2009-03-04 04:32:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
2012-02-28 16:21:08 +01:00
|
|
|
* the documentation and/or other materials provided with the
|
2009-03-04 04:32:55 +01:00
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
2012-02-28 16:21:08 +01:00
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
2009-03-04 04:32:55 +01:00
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
2012-04-06 21:39:30 +02:00
|
|
|
#include <sys/stat.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <linux/usbdevice_fs.h>
|
|
|
|
#include <linux/usbdevice_fs.h>
|
|
|
|
#include <linux/version.h>
|
|
|
|
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20)
|
|
|
|
#include <linux/usb/ch9.h>
|
|
|
|
#else
|
|
|
|
#include <linux/usb_ch9.h>
|
|
|
|
#endif
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
|
|
|
#include "usb.h"
|
|
|
|
|
2009-08-18 16:41:09 +02:00
|
|
|
#define MAX_RETRIES 5
|
|
|
|
|
|
|
|
#ifdef TRACE_USB
|
2009-03-04 04:32:55 +01:00
|
|
|
#define DBG1(x...) fprintf(stderr, x)
|
|
|
|
#define DBG(x...) fprintf(stderr, x)
|
|
|
|
#else
|
|
|
|
#define DBG(x...)
|
|
|
|
#define DBG1(x...)
|
|
|
|
#endif
|
|
|
|
|
2011-03-08 07:10:16 +01:00
|
|
|
/* The max bulk size for linux is 16384 which is defined
|
|
|
|
* in drivers/usb/core/devio.c.
|
|
|
|
*/
|
|
|
|
#define MAX_USBFS_BULK_SIZE (16 * 1024)
|
|
|
|
|
2012-02-28 16:21:08 +01:00
|
|
|
struct usb_handle
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
|
|
|
char fname[64];
|
|
|
|
int desc;
|
|
|
|
unsigned char ep_in;
|
|
|
|
unsigned char ep_out;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int badname(const char *name)
|
|
|
|
{
|
|
|
|
while(*name) {
|
|
|
|
if(!isdigit(*name++)) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check(void *_desc, int len, unsigned type, int size)
|
|
|
|
{
|
|
|
|
unsigned char *desc = _desc;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(len < size) return -1;
|
|
|
|
if(desc[0] < size) return -1;
|
|
|
|
if(desc[0] > len) return -1;
|
|
|
|
if(desc[1] != type) return -1;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-07 03:07:49 +02:00
|
|
|
static int filter_usb_device(int fd, char *ptr, int len, int writable,
|
|
|
|
ifc_match_func callback,
|
2009-03-04 04:32:55 +01:00
|
|
|
int *ept_in_id, int *ept_out_id, int *ifc_id)
|
|
|
|
{
|
|
|
|
struct usb_device_descriptor *dev;
|
|
|
|
struct usb_config_descriptor *cfg;
|
|
|
|
struct usb_interface_descriptor *ifc;
|
|
|
|
struct usb_endpoint_descriptor *ept;
|
|
|
|
struct usb_ifc_info info;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
int in, out;
|
|
|
|
unsigned i;
|
|
|
|
unsigned e;
|
|
|
|
|
2012-04-06 21:39:30 +02:00
|
|
|
struct stat st;
|
|
|
|
int result;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(check(ptr, len, USB_DT_DEVICE, USB_DT_DEVICE_SIZE))
|
|
|
|
return -1;
|
|
|
|
dev = (void*) ptr;
|
|
|
|
len -= dev->bLength;
|
|
|
|
ptr += dev->bLength;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(check(ptr, len, USB_DT_CONFIG, USB_DT_CONFIG_SIZE))
|
|
|
|
return -1;
|
|
|
|
cfg = (void*) ptr;
|
|
|
|
len -= cfg->bLength;
|
|
|
|
ptr += cfg->bLength;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
info.dev_vendor = dev->idVendor;
|
|
|
|
info.dev_product = dev->idProduct;
|
|
|
|
info.dev_class = dev->bDeviceClass;
|
|
|
|
info.dev_subclass = dev->bDeviceSubClass;
|
|
|
|
info.dev_protocol = dev->bDeviceProtocol;
|
2009-10-07 03:07:49 +02:00
|
|
|
info.writable = writable;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
// read device serial number (if there is one)
|
|
|
|
info.serial_number[0] = 0;
|
|
|
|
if (dev->iSerialNumber) {
|
|
|
|
struct usbdevfs_ctrltransfer ctrl;
|
2012-04-19 00:30:56 +02:00
|
|
|
// Keep it short enough because some bootloaders are borked if the URB len is > 255
|
|
|
|
// 128 is too big by 1.
|
|
|
|
__u16 buffer[127];
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
|
|
|
ctrl.bRequestType = USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE;
|
|
|
|
ctrl.bRequest = USB_REQ_GET_DESCRIPTOR;
|
|
|
|
ctrl.wValue = (USB_DT_STRING << 8) | dev->iSerialNumber;
|
2011-07-08 02:08:10 +02:00
|
|
|
//language ID (en-us) for serial number string
|
|
|
|
ctrl.wIndex = 0x0409;
|
2009-03-04 04:32:55 +01:00
|
|
|
ctrl.wLength = sizeof(buffer);
|
|
|
|
ctrl.data = buffer;
|
2011-07-08 02:08:10 +02:00
|
|
|
ctrl.timeout = 50;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
result = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
|
|
|
|
if (result > 0) {
|
|
|
|
int i;
|
|
|
|
// skip first word, and copy the rest to the serial string, changing shorts to bytes.
|
|
|
|
result /= 2;
|
|
|
|
for (i = 1; i < result; i++)
|
|
|
|
info.serial_number[i - 1] = buffer[i];
|
|
|
|
info.serial_number[i - 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-06 21:39:30 +02:00
|
|
|
/* We need to get a path that represents a particular port on a particular
|
|
|
|
* hub. We are passed an fd that was obtained by opening an entry under
|
|
|
|
* /dev/bus/usb. Unfortunately, the names of those entries change each
|
|
|
|
* time devices are plugged and unplugged. So how to get a repeatable
|
|
|
|
* path? udevadm provided the inspiration. We can get the major and
|
|
|
|
* minor of the device file, read the symlink that can be found here:
|
|
|
|
* /sys/dev/char/<major>:<minor>
|
|
|
|
* and then use the last element of that path. As a concrete example, I
|
|
|
|
* have an Android device at /dev/bus/usb/001/027 so working with bash:
|
|
|
|
* $ ls -l /dev/bus/usb/001/027
|
|
|
|
* crw-rw-r-- 1 root plugdev 189, 26 Apr 9 11:03 /dev/bus/usb/001/027
|
|
|
|
* $ ls -l /sys/dev/char/189:26
|
|
|
|
* lrwxrwxrwx 1 root root 0 Apr 9 11:03 /sys/dev/char/189:26 ->
|
|
|
|
* ../../devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4.2/1-4.2.3
|
|
|
|
* So our device_path would be 1-4.2.3 which says my device is connected
|
|
|
|
* to port 3 of a hub on port 2 of a hub on port 4 of bus 1 (per
|
|
|
|
* http://www.linux-usb.org/FAQ.html).
|
|
|
|
*/
|
|
|
|
info.device_path[0] = '\0';
|
|
|
|
result = fstat(fd, &st);
|
|
|
|
if (!result && S_ISCHR(st.st_mode)) {
|
|
|
|
char cdev[128];
|
|
|
|
char link[256];
|
|
|
|
char *slash;
|
|
|
|
ssize_t link_len;
|
|
|
|
snprintf(cdev, sizeof(cdev), "/sys/dev/char/%d:%d",
|
|
|
|
major(st.st_rdev), minor(st.st_rdev));
|
|
|
|
link_len = readlink(cdev, link, sizeof(link) - 1);
|
|
|
|
if (link_len > 0) {
|
|
|
|
link[link_len] = '\0';
|
|
|
|
slash = strrchr(link, '/');
|
|
|
|
if (slash)
|
|
|
|
snprintf(info.device_path, sizeof(info.device_path), "usb:%s", slash+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
for(i = 0; i < cfg->bNumInterfaces; i++) {
|
|
|
|
if(check(ptr, len, USB_DT_INTERFACE, USB_DT_INTERFACE_SIZE))
|
|
|
|
return -1;
|
|
|
|
ifc = (void*) ptr;
|
|
|
|
len -= ifc->bLength;
|
|
|
|
ptr += ifc->bLength;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
in = -1;
|
|
|
|
out = -1;
|
|
|
|
info.ifc_class = ifc->bInterfaceClass;
|
|
|
|
info.ifc_subclass = ifc->bInterfaceSubClass;
|
|
|
|
info.ifc_protocol = ifc->bInterfaceProtocol;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
for(e = 0; e < ifc->bNumEndpoints; e++) {
|
|
|
|
if(check(ptr, len, USB_DT_ENDPOINT, USB_DT_ENDPOINT_SIZE))
|
|
|
|
return -1;
|
|
|
|
ept = (void*) ptr;
|
|
|
|
len -= ept->bLength;
|
|
|
|
ptr += ept->bLength;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if((ept->bmAttributes & 0x03) != 0x02)
|
|
|
|
continue;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(ept->bEndpointAddress & 0x80) {
|
|
|
|
in = ept->bEndpointAddress;
|
|
|
|
} else {
|
|
|
|
out = ept->bEndpointAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info.has_bulk_in = (in != -1);
|
|
|
|
info.has_bulk_out = (out != -1);
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(callback(&info) == 0) {
|
|
|
|
*ept_in_id = in;
|
|
|
|
*ept_out_id = out;
|
|
|
|
*ifc_id = ifc->bInterfaceNumber;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static usb_handle *find_usb_device(const char *base, ifc_match_func callback)
|
|
|
|
{
|
|
|
|
usb_handle *usb = 0;
|
|
|
|
char busname[64], devname[64];
|
|
|
|
char desc[1024];
|
|
|
|
int n, in, out, ifc;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
DIR *busdir, *devdir;
|
|
|
|
struct dirent *de;
|
|
|
|
int fd;
|
2009-10-08 02:24:39 +02:00
|
|
|
int writable;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
busdir = opendir(base);
|
|
|
|
if(busdir == 0) return 0;
|
|
|
|
|
|
|
|
while((de = readdir(busdir)) && (usb == 0)) {
|
|
|
|
if(badname(de->d_name)) continue;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
sprintf(busname, "%s/%s", base, de->d_name);
|
|
|
|
devdir = opendir(busname);
|
|
|
|
if(devdir == 0) continue;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
// DBG("[ scanning %s ]\n", busname);
|
|
|
|
while((de = readdir(devdir)) && (usb == 0)) {
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(badname(de->d_name)) continue;
|
|
|
|
sprintf(devname, "%s/%s", busname, de->d_name);
|
|
|
|
|
|
|
|
// DBG("[ scanning %s ]\n", devname);
|
2009-10-08 02:24:39 +02:00
|
|
|
writable = 1;
|
2009-03-04 04:32:55 +01:00
|
|
|
if((fd = open(devname, O_RDWR)) < 0) {
|
2009-10-07 03:07:49 +02:00
|
|
|
// Check if we have read-only access, so we can give a helpful
|
|
|
|
// diagnostic like "adb devices" does.
|
|
|
|
writable = 0;
|
|
|
|
if((fd = open(devname, O_RDONLY)) < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
n = read(fd, desc, sizeof(desc));
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-10-07 03:07:49 +02:00
|
|
|
if(filter_usb_device(fd, desc, n, writable, callback,
|
|
|
|
&in, &out, &ifc) == 0) {
|
2009-03-04 04:32:55 +01:00
|
|
|
usb = calloc(1, sizeof(usb_handle));
|
|
|
|
strcpy(usb->fname, devname);
|
|
|
|
usb->ep_in = in;
|
|
|
|
usb->ep_out = out;
|
|
|
|
usb->desc = fd;
|
|
|
|
|
|
|
|
n = ioctl(fd, USBDEVFS_CLAIMINTERFACE, &ifc);
|
|
|
|
if(n != 0) {
|
|
|
|
close(fd);
|
|
|
|
free(usb);
|
|
|
|
usb = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(devdir);
|
|
|
|
}
|
|
|
|
closedir(busdir);
|
|
|
|
|
|
|
|
return usb;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_write(usb_handle *h, const void *_data, int len)
|
|
|
|
{
|
|
|
|
unsigned char *data = (unsigned char*) _data;
|
|
|
|
unsigned count = 0;
|
|
|
|
struct usbdevfs_bulktransfer bulk;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if(h->ep_out == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(len == 0) {
|
|
|
|
bulk.ep = h->ep_out;
|
|
|
|
bulk.len = 0;
|
|
|
|
bulk.data = data;
|
|
|
|
bulk.timeout = 0;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
n = ioctl(h->desc, USBDEVFS_BULK, &bulk);
|
|
|
|
if(n != 0) {
|
|
|
|
fprintf(stderr,"ERROR: n = %d, errno = %d (%s)\n",
|
|
|
|
n, errno, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
while(len > 0) {
|
|
|
|
int xfer;
|
2011-03-08 07:10:16 +01:00
|
|
|
xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
bulk.ep = h->ep_out;
|
|
|
|
bulk.len = xfer;
|
|
|
|
bulk.data = data;
|
|
|
|
bulk.timeout = 0;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
n = ioctl(h->desc, USBDEVFS_BULK, &bulk);
|
|
|
|
if(n != xfer) {
|
|
|
|
DBG("ERROR: n = %d, errno = %d (%s)\n",
|
|
|
|
n, errno, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
count += xfer;
|
|
|
|
len -= xfer;
|
|
|
|
data += xfer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_read(usb_handle *h, void *_data, int len)
|
|
|
|
{
|
|
|
|
unsigned char *data = (unsigned char*) _data;
|
|
|
|
unsigned count = 0;
|
|
|
|
struct usbdevfs_bulktransfer bulk;
|
2009-08-18 16:41:09 +02:00
|
|
|
int n, retry;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
if(h->ep_in == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
while(len > 0) {
|
2011-03-08 07:10:16 +01:00
|
|
|
int xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
bulk.ep = h->ep_in;
|
|
|
|
bulk.len = xfer;
|
|
|
|
bulk.data = data;
|
|
|
|
bulk.timeout = 0;
|
2009-08-18 16:41:09 +02:00
|
|
|
retry = 0;
|
|
|
|
|
|
|
|
do{
|
|
|
|
DBG("[ usb read %d fd = %d], fname=%s\n", xfer, h->desc, h->fname);
|
|
|
|
n = ioctl(h->desc, USBDEVFS_BULK, &bulk);
|
|
|
|
DBG("[ usb read %d ] = %d, fname=%s, Retry %d \n", xfer, n, h->fname, retry);
|
|
|
|
|
|
|
|
if( n < 0 ) {
|
|
|
|
DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno));
|
|
|
|
if ( ++retry > MAX_RETRIES ) return -1;
|
|
|
|
sleep( 1 );
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2009-08-18 16:41:09 +02:00
|
|
|
while( n < 0 );
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
count += n;
|
|
|
|
len -= n;
|
|
|
|
data += n;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
if(n < xfer) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_kick(usb_handle *h)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = h->desc;
|
|
|
|
h->desc = -1;
|
|
|
|
if(fd >= 0) {
|
|
|
|
close(fd);
|
|
|
|
DBG("[ usb closed %d ]\n", fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_close(usb_handle *h)
|
|
|
|
{
|
|
|
|
int fd;
|
2012-02-28 16:21:08 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
fd = h->desc;
|
|
|
|
h->desc = -1;
|
|
|
|
if(fd >= 0) {
|
|
|
|
close(fd);
|
|
|
|
DBG("[ usb closed %d ]\n", fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_handle *usb_open(ifc_match_func callback)
|
|
|
|
{
|
|
|
|
return find_usb_device("/dev/bus/usb", callback);
|
|
|
|
}
|