summaryrefslogtreecommitdiffstats
path: root/libusbhost
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2014-01-13 09:54:13 -0800
committerMike Lockwood <lockwood@google.com>2014-01-13 09:54:13 -0800
commitd2e798b53039f35967705acd5f6c399742f97e72 (patch)
tree0e0c8e6e08788fddbca2d67cb77e1fe9996f8e43 /libusbhost
parentf922380f9ab3fcb0f1ac27c85bbb2dd394f8d2a5 (diff)
downloadsystem_core-d2e798b53039f35967705acd5f6c399742f97e72.zip
system_core-d2e798b53039f35967705acd5f6c399742f97e72.tar.gz
system_core-d2e798b53039f35967705acd5f6c399742f97e72.tar.bz2
libusbhost: Add usb_device_set_configuration and usb_device_set_interface
usb_device_set_configuration is to support devices with multiple configurations usb_device_set_interface supports switching between interfaces with alternate settings Also moved zero string index checking to usb_device_get_string Change-Id: I34610b25f135894a0cf752a33e5738d4314d7122
Diffstat (limited to 'libusbhost')
-rw-r--r--libusbhost/usbhost.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c
index 8be393e..ab1b856 100644
--- a/libusbhost/usbhost.c
+++ b/libusbhost/usbhost.c
@@ -453,6 +453,8 @@ char* usb_device_get_string(struct usb_device *device, int id)
int i, result;
int languageCount = 0;
+ if (id == 0) return NULL;
+
string[0] = 0;
memset(languages, 0, sizeof(languages));
@@ -486,31 +488,19 @@ char* usb_device_get_string(struct usb_device *device, int id)
char* usb_device_get_manufacturer_name(struct usb_device *device)
{
struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
-
- if (desc->iManufacturer)
- return usb_device_get_string(device, desc->iManufacturer);
- else
- return NULL;
+ return usb_device_get_string(device, desc->iManufacturer);
}
char* usb_device_get_product_name(struct usb_device *device)
{
struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
-
- if (desc->iProduct)
- return usb_device_get_string(device, desc->iProduct);
- else
- return NULL;
+ return usb_device_get_string(device, desc->iProduct);
}
char* usb_device_get_serial(struct usb_device *device)
{
struct usb_device_descriptor *desc = (struct usb_device_descriptor *)device->desc;
-
- if (desc->iSerialNumber)
- return usb_device_get_string(device, desc->iSerialNumber);
- else
- return NULL;
+ return usb_device_get_string(device, desc->iSerialNumber);
}
int usb_device_is_writeable(struct usb_device *device)
@@ -556,6 +546,21 @@ int usb_device_connect_kernel_driver(struct usb_device *device,
return ioctl(device->fd, USBDEVFS_IOCTL, &ctl);
}
+int usb_device_set_configuration(struct usb_device *device, int configuration)
+{
+ return ioctl(device->fd, USBDEVFS_SETCONFIGURATION, &configuration);
+}
+
+int usb_device_set_interface(struct usb_device *device, unsigned int interface,
+ unsigned int alt_setting)
+{
+ struct usbdevfs_setinterface ctl;
+
+ ctl.interface = interface;
+ ctl.altsetting = alt_setting;
+ return ioctl(device->fd, USBDEVFS_SETINTERFACE, &ctl);
+}
+
int usb_device_control_transfer(struct usb_device *device,
int requestType,
int request,