-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathusbip_common.c
102 lines (80 loc) · 2.41 KB
/
usbip_common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#include "usbip.h"
#include <stdlib.h>
#include <stdio.h>
struct speed_string {
int num;
char *speed;
char *desc;
};
static const struct speed_string speed_strings[] = {
{ USB_SPEED_UNKNOWN, "unknown", "Unknown Speed"},
{ USB_SPEED_LOW, "1.5", "Low Speed(1.5Mbps)" },
{ USB_SPEED_FULL, "12", "Full Speed(12Mbps)" },
{ USB_SPEED_HIGH, "480", "High Speed(480Mbps)" },
{ 0, NULL, NULL }
};
const char *usbip_speed_string(int num)
{
int i;
for (i=0; speed_strings[i].speed != NULL; i++)
if (speed_strings[i].num == num)
return speed_strings[i].desc;
return "Unknown Speed";
}
#define DBG_UDEV_INTEGER(name)\
dbg("%-20s = %x", to_string(name), (int) udev->name)
#define DBG_UINF_INTEGER(name)\
dbg("%-20s = %x", to_string(name), (int) uinf->name)
void dump_usb_interface(struct usb_interface *uinf)
{
char buff[100];
usbip_names_get_class(buff, sizeof(buff),
uinf->bInterfaceClass,
uinf->bInterfaceSubClass,
uinf->bInterfaceProtocol);
dbg("%-20s = %s", "Interface(C/SC/P)", buff);
}
void dump_usb_device(struct usb_device *udev)
{
char buff[100];
dbg("%-20s = %s", "path", udev->path);
dbg("%-20s = %s", "busid", udev->busid);
usbip_names_get_class(buff, sizeof(buff),
udev->bDeviceClass,
udev->bDeviceSubClass,
udev->bDeviceProtocol);
dbg("%-20s = %s", "Device(C/SC/P)", buff);
DBG_UDEV_INTEGER(bcdDevice);
usbip_names_get_product(buff, sizeof(buff),
udev->idVendor,
udev->idProduct);
dbg("%-20s = %s", "Vendor/Product", buff);
DBG_UDEV_INTEGER(bNumConfigurations);
DBG_UDEV_INTEGER(bNumInterfaces);
dbg("%-20s = %s", "speed",
usbip_speed_string(udev->speed));
DBG_UDEV_INTEGER(busnum);
DBG_UDEV_INTEGER(devnum);
}
void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t product)
{
const char *prod, *vend;
prod = "unknown product";
vend = "unknown vendor";
_snprintf(buff, size, "%s : %s (%04x:%04x)", vend, prod, vendor, product);
}
void usbip_names_get_class(char *buff, size_t size, uint8_t class0, uint8_t subclass, uint8_t protocol)
{
const char *c, *s, *p;
if (class0 == 0 && subclass == 0 && protocol == 0) {
_snprintf(buff, size, "(Defined at Interface level) (%02x/%02x/%02x)", class0, subclass, protocol);
return;
}
p = "unknown protocol";
s = "unknown subclass";
c = "unknown class";
_snprintf(buff, size, "%s / %s / %s (%02x/%02x/%02x)", c, s, p, class0, subclass, protocol);
}