Skip to content

Commit

Permalink
libusbhost: Add usb_device_connect_kernel_driver()
Browse files Browse the repository at this point in the history
This can be used to ask the kernel to disconnect its driver for a device
so usb_device_claim_interface() can claim it instead.

Also increased size of descriptor buffer and added some debugging logs

Change-Id: I4945196d957fb8493716eb9b7e5463c06b168ef1
Signed-off-by: Mike Lockwood <lockwood@android.com>
  • Loading branch information
mikeandroid committed Jan 22, 2011
1 parent 0897a43 commit ec9e7b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/usbhost/usbhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ int usb_device_claim_interface(struct usb_device *device, unsigned int interface
/* Releases the specified interface of a USB device */
int usb_device_release_interface(struct usb_device *device, unsigned int interface);

/* Requests the kernel to connect or disconnect its driver for the specified interface.
* This can be used to ask the kernel to disconnect its driver for a device
* so usb_device_claim_interface can claim it instead.
*/
int usb_device_connect_kernel_driver(struct usb_device *device,
unsigned int interface, int connect);

/* Creates a new usb_request. */
struct usb_request *usb_request_new(struct usb_device *dev,
const struct usb_endpoint_descriptor *ep_desc);
Expand Down
19 changes: 17 additions & 2 deletions libusbhost/usbhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct usb_host_context {

struct usb_device {
char dev_name[64];
unsigned char desc[256];
unsigned char desc[4096];
int desc_length;
int fd;
int writeable;
Expand Down Expand Up @@ -204,6 +204,8 @@ struct usb_device *usb_device_open(const char *dev_name)
{
int fd, did_retry = 0, writeable = 1;

D("usb_device_open %s\n", dev_name);

retry:
fd = open(dev_name, O_RDWR);
if (fd < 0) {
Expand Down Expand Up @@ -240,10 +242,12 @@ struct usb_device *usb_device_new(const char *dev_name, int fd)
struct usb_device *device = calloc(1, sizeof(struct usb_device));
int length;

D("usb_device_new %s fd: %d\n", dev_name, fd);

if (lseek(fd, 0, SEEK_SET) != 0)
goto failed;
length = read(fd, device->desc, sizeof(device->desc));
D("usb_device_new read returned %d errno %d\n", fd, errno);
D("usb_device_new read returned %d errno %d\n", length, errno);
if (length < 0)
goto failed;

Expand Down Expand Up @@ -452,6 +456,17 @@ int usb_device_release_interface(struct usb_device *device, unsigned int interfa
return ioctl(device->fd, USBDEVFS_RELEASEINTERFACE, &interface);
}

int usb_device_connect_kernel_driver(struct usb_device *device,
unsigned int interface, int connect)
{
struct usbdevfs_ioctl ctl;

ctl.ifno = interface;
ctl.ioctl_code = (connect ? USBDEVFS_CONNECT : USBDEVFS_DISCONNECT);
ctl.data = NULL;
return ioctl(device->fd, USBDEVFS_IOCTL, &ctl);
}

struct usb_request *usb_request_new(struct usb_device *dev,
const struct usb_endpoint_descriptor *ep_desc)
{
Expand Down

0 comments on commit ec9e7b1

Please sign in to comment.