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
This commit is contained in:
parent
f922380f9a
commit
d2e798b530
2 changed files with 27 additions and 15 deletions
|
@ -189,6 +189,13 @@ int usb_device_release_interface(struct usb_device *device, unsigned int interfa
|
|||
int usb_device_connect_kernel_driver(struct usb_device *device,
|
||||
unsigned int interface, int connect);
|
||||
|
||||
/* Sets the current configuration for the device to the specified configuration */
|
||||
int usb_device_set_configuration(struct usb_device *device, int configuration);
|
||||
|
||||
/* Sets the specified interface of a USB device */
|
||||
int usb_device_set_interface(struct usb_device *device, unsigned int interface,
|
||||
unsigned int alt_setting);
|
||||
|
||||
/* Sends a control message to the specified device on endpoint zero */
|
||||
int usb_device_control_transfer(struct usb_device *device,
|
||||
int requestType,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue