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 /* kernel module names */
30 #define USBIP_CORE_MOD_NAME "usbip-core"
31 #define USBIP_HOST_DRV_NAME "usbip-host"
32 #define USBIP_VHCI_DRV_NAME "vhci_hcd"
34 enum usb_device_speed
{
35 USB_SPEED_UNKNOWN
= 0, /* enumerating */
36 USB_SPEED_LOW
, USB_SPEED_FULL
, /* usb 1.1 */
37 USB_SPEED_HIGH
, /* usb 2.0 */
38 USB_SPEED_VARIABLE
/* wireless (usb 2.5) */
41 /* FIXME: how to sync with drivers/usbip_common.h ? */
42 enum usbip_device_status
{
43 /* sdev is available. */
44 SDEV_ST_AVAILABLE
= 0x01,
45 /* sdev is now used. */
47 /* sdev is unusable because of a fatal error. */
50 /* vdev does not connect a remote device. */
52 /* vdev is used, but the USB address is not assigned yet */
58 extern int usbip_use_syslog
;
59 extern int usbip_use_stderr
;
60 extern int usbip_use_debug
;
62 #define err(fmt, args...) do { \
63 if (usbip_use_syslog) { \
64 syslog(LOG_ERR, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
65 __FILE__, __LINE__, __FUNCTION__, ##args); \
67 if (usbip_use_stderr) { \
68 fprintf(stderr, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
69 __FILE__, __LINE__, __FUNCTION__, ##args); \
73 #define notice(fmt, args...) do { \
74 if (usbip_use_syslog) { \
75 syslog(LOG_DEBUG, "usbip: " fmt, ##args); \
77 if (usbip_use_stderr) { \
78 fprintf(stderr, "usbip: " fmt "\n", ##args); \
82 #define info(fmt, args...) do { \
83 if (usbip_use_syslog) { \
84 syslog(LOG_DEBUG, fmt, ##args); \
86 if (usbip_use_stderr) { \
87 fprintf(stderr, fmt "\n", ##args); \
91 #define dbg(fmt, args...) do { \
92 if (usbip_use_debug) { \
93 if (usbip_use_syslog) { \
94 syslog(LOG_DEBUG, "usbip dbg: %13s:%4d (%-12s) " fmt, \
95 __FILE__, __LINE__, __FUNCTION__, ##args); \
97 if (usbip_use_stderr) { \
98 fprintf(stderr, "usbip dbg: %13s:%4d (%-12s) " fmt "\n", \
99 __FILE__, __LINE__, __FUNCTION__, ##args); \
105 #define BUG() do { err("sorry, it's a bug"); abort(); } while (0)
108 struct usb_interface
{
109 uint8_t bInterfaceClass
;
110 uint8_t bInterfaceSubClass
;
111 uint8_t bInterfaceProtocol
;
112 uint8_t padding
; /* alignment */
113 } __attribute__((packed
));
118 char path
[SYSFS_PATH_MAX
];
119 char busid
[SYSFS_BUS_ID_SIZE
];
129 uint8_t bDeviceClass
;
130 uint8_t bDeviceSubClass
;
131 uint8_t bDeviceProtocol
;
132 uint8_t bConfigurationValue
;
133 uint8_t bNumConfigurations
;
134 uint8_t bNumInterfaces
;
135 } __attribute__((packed
));
137 #define to_string(s) #s
139 void dump_usb_interface(struct usb_interface
*);
140 void dump_usb_device(struct usb_device
*);
141 int read_usb_device(struct sysfs_device
*sdev
, struct usb_device
*udev
);
142 int read_attr_value(struct sysfs_device
*dev
, const char *name
, const char *format
);
143 int read_usb_interface(struct usb_device
*udev
, int i
, struct usb_interface
*uinf
);
145 const char *usbip_speed_string(int num
);
146 const char *usbip_status_string(int32_t status
);
148 int usbip_names_init(char *);
149 void usbip_names_free(void);
150 void usbip_names_get_product(char *buff
, size_t size
, uint16_t vendor
, uint16_t product
);
151 void usbip_names_get_class(char *buff
, size_t size
, uint8_t class, uint8_t subclass
, uint8_t protocol
);