summaryrefslogtreecommitdiffstats
path: root/libusbhost/usbhost.c
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-12-29 08:47:29 -0500
committerMike Lockwood <lockwood@android.com>2010-12-29 09:27:16 -0500
commit7d700f8bdce747a26e3ee4737683194d77286ba3 (patch)
tree18730f8f9be6efcb9a9b4eba00d307cd9d3241d5 /libusbhost/usbhost.c
parent123538954b9c8ad8fe7c2d755391f0b7cbaa1d6f (diff)
downloadsystem_core-7d700f8bdce747a26e3ee4737683194d77286ba3.tar.gz
system_core-7d700f8bdce747a26e3ee4737683194d77286ba3.tar.bz2
system_core-7d700f8bdce747a26e3ee4737683194d77286ba3.zip
libusbhost: Add usb_device_get_name_from_unique_id()
This allows converting from unique IDs to USB device names Change-Id: I8e3b300790c01383aed8e3d4f547b54bcb7c2cd4 Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'libusbhost/usbhost.c')
-rw-r--r--libusbhost/usbhost.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c
index dba0b4813..dbc7962cb 100644
--- a/libusbhost/usbhost.c
+++ b/libusbhost/usbhost.c
@@ -57,6 +57,7 @@
#define USB_FS_DIR "/dev/bus/usb"
#define USB_FS_ID_SCANNER "/dev/bus/usb/%d/%d"
+#define USB_FS_ID_FORMAT "/dev/bus/usb/%03d/%03d"
struct usb_host_context {
@@ -314,6 +315,15 @@ int usb_device_get_unique_id_from_name(const char* name)
return bus * 1000 + dev;
}
+char* usb_device_get_name_from_unique_id(int id)
+{
+ int bus = id / 1000;
+ int dev = id % 1000;
+ char* result = (char *)calloc(1, strlen(USB_FS_ID_FORMAT));
+ snprintf(result, strlen(USB_FS_ID_FORMAT) - 1, USB_FS_ID_FORMAT, bus, dev);
+ return result;
+}
+
uint16_t usb_device_get_vendor_id(struct usb_device *device)
{
struct usb_device_descriptor* desc = (struct usb_device_descriptor*)device->desc;