1 /*
2 * Copyright 2008-2012, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Jérôme Duval
7 */
8
9
10 #include <stdio.h>
11
12 #include "usbhdr.h"
13
14
15 static void
usb_get_class_info(uint8 usb_class_base_id,uint8 usb_class_sub_id,uint8 usb_class_proto_id,char * classInfo,size_t size)16 usb_get_class_info(uint8 usb_class_base_id, uint8 usb_class_sub_id, uint8 usb_class_proto_id,
17 char *classInfo, size_t size)
18 {
19 USB_CLASSCODETABLE *foundItem = NULL;
20 int i;
21 for (i = 0; i < (int)USB_CLASSCODETABLE_LEN; i++) {
22 if ((usb_class_base_id == UsbClassCodeTable[i].BaseClass)
23 && (usb_class_sub_id == UsbClassCodeTable[i].SubClass)) {
24 foundItem = &UsbClassCodeTable[i];
25 if (usb_class_proto_id == UsbClassCodeTable[i].Protocol)
26 break;
27 }
28 }
29 if (foundItem) {
30 snprintf(classInfo, size, "%s (%s%s%s)", foundItem->BaseDesc, foundItem->SubDesc,
31 (foundItem->ProtocolDesc && strcmp("", foundItem->ProtocolDesc)) ? ", " : "",
32 foundItem->ProtocolDesc);
33 } else
34 snprintf(classInfo, size, "%s (%u:%u:%u)", "(Unknown)",
35 usb_class_base_id, usb_class_sub_id, usb_class_proto_id);
36 }
37
38
39 void
usb_get_vendor_info(uint16 vendorID,const char ** vendorName)40 usb_get_vendor_info(uint16 vendorID, const char **vendorName)
41 {
42 int i;
43 for (i = 0; i < (int)USB_VENTABLE_LEN; i++) {
44 if (UsbVenTable[i].VenId == vendorID) {
45 *vendorName = UsbVenTable[i].VenName && UsbVenTable[i].VenName[0]
46 ? UsbVenTable[i].VenName : NULL;
47 return;
48 }
49 }
50 *vendorName = NULL;
51 }
52
53
54 void
usb_get_device_info(uint16 vendorID,uint16 deviceID,const char ** deviceName)55 usb_get_device_info(uint16 vendorID, uint16 deviceID, const char **deviceName)
56 {
57 int i;
58 // search for the device
59 for (i = 0; i < (int)USB_DEVTABLE_LEN; i++) {
60 if (UsbDevTable[i].VenId == vendorID && UsbDevTable[i].DevId == deviceID ) {
61 *deviceName = UsbDevTable[i].ChipDesc && UsbDevTable[i].ChipDesc[0]
62 ? UsbDevTable[i].ChipDesc : NULL;
63 return;
64 }
65 }
66 *deviceName = NULL;
67 }
68