2 * Copyright (C) 2005-2007 Takahiro Hirofuchi
5 #ifndef _USBIP_COMMON_H
6 #define _USBIP_COMMON_H
17 #include <sysfs/libsysfs.h>
19 #include <sys/socket.h>
22 #define USBIDS_FILE "/usr/share/hwdata/usb.ids"
25 #ifndef VHCI_STATE_PATH
26 #define VHCI_STATE_PATH "/var/run/vhci_hcd"
29 //#include <linux/usb_ch9.h>
30 enum usb_device_speed {
31 USB_SPEED_UNKNOWN = 0, /* enumerating */
32 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
33 USB_SPEED_HIGH, /* usb 2.0 */
34 USB_SPEED_VARIABLE /* wireless (usb 2.5) */
37 /* FIXME: how to sync with drivers/usbip_common.h ? */
38 enum usbip_device_status{
39 /* sdev is available. */
40 SDEV_ST_AVAILABLE = 0x01,
41 /* sdev is now used. */
43 /* sdev is unusable because of a fatal error. */
46 /* vdev does not connect a remote device. */
48 /* vdev is used, but the USB address is not assigned yet */
54 extern int usbip_use_syslog;
55 extern int usbip_use_stderr;
56 extern int usbip_use_debug ;
58 #define err(fmt, args...) do { \
59 if (usbip_use_syslog) { \
60 syslog(LOG_ERR, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
61 __FILE__, __LINE__, __FUNCTION__, ##args); \
63 if (usbip_use_stderr) { \
64 fprintf(stderr, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
65 __FILE__, __LINE__, __FUNCTION__, ##args); \
69 #define notice(fmt, args...) do { \
70 if (usbip_use_syslog) { \
71 syslog(LOG_DEBUG, "usbip: " fmt, ##args); \
73 if (usbip_use_stderr) { \
74 fprintf(stderr, "usbip: " fmt "\n", ##args); \
78 #define info(fmt, args...) do { \
79 if (usbip_use_syslog) { \
80 syslog(LOG_DEBUG, fmt, ##args); \
82 if (usbip_use_stderr) { \
83 fprintf(stderr, fmt "\n", ##args); \
87 #define dbg(fmt, args...) do { \
88 if (usbip_use_debug) { \
89 if (usbip_use_syslog) { \
90 syslog(LOG_DEBUG, "usbip dbg: %13s:%4d (%-12s) " fmt, \
91 __FILE__, __LINE__, __FUNCTION__, ##args); \
93 if (usbip_use_stderr) { \
94 fprintf(stderr, "usbip dbg: %13s:%4d (%-12s) " fmt "\n", \
95 __FILE__, __LINE__, __FUNCTION__, ##args); \
101 #define BUG() do { err("sorry, it's a bug"); abort(); } while (0)
104 struct usb_interface {
105 uint8_t bInterfaceClass;
106 uint8_t bInterfaceSubClass;
107 uint8_t bInterfaceProtocol;
108 uint8_t padding; /* alignment */
109 } __attribute__((packed));
114 char path[SYSFS_PATH_MAX];
115 char busid[SYSFS_BUS_ID_SIZE];
125 uint8_t bDeviceClass;
126 uint8_t bDeviceSubClass;
127 uint8_t bDeviceProtocol;
128 uint8_t bConfigurationValue;
129 uint8_t bNumConfigurations;
130 uint8_t bNumInterfaces;
131 } __attribute__((packed));
133 #define to_string(s) #s
135 void dump_usb_interface(struct usb_interface *);
136 void dump_usb_device(struct usb_device *);
137 int read_usb_device(struct sysfs_device *sdev, struct usb_device *udev);
138 int read_attr_value(struct sysfs_device *dev, const char *name, const char *format);
139 int read_usb_interface(struct usb_device *udev, int i, struct usb_interface *uinf);
141 const char *usbip_speed_string(int num);
142 const char *usbip_status_string(int32_t status);
144 int usbip_names_init(char *);
145 void usbip_names_free(void);
146 void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t product);
147 void usbip_names_get_class(char *buff, size_t size, uint8_t class, uint8_t subclass, uint8_t protocol);