staging: usbip: userspace: set kernel module names in one place
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / usbip / userspace / libsrc / usbip_common.h
blob2c58af51a230387e5374b5576218a8350309b63f
1 /*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */
5 #ifndef _USBIP_COMMON_H
6 #define _USBIP_COMMON_H
8 #include <unistd.h>
9 #include <stdint.h>
10 #include <syslog.h>
11 #include <errno.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <strings.h>
17 #include <sysfs/libsysfs.h>
18 #include <netdb.h>
19 #include <sys/socket.h>
21 #ifndef USBIDS_FILE
22 #define USBIDS_FILE "/usr/share/hwdata/usb.ids"
23 #endif
25 #ifndef VHCI_STATE_PATH
26 #define VHCI_STATE_PATH "/var/run/vhci_hcd"
27 #endif
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. */
46 SDEV_ST_USED,
47 /* sdev is unusable because of a fatal error. */
48 SDEV_ST_ERROR,
50 /* vdev does not connect a remote device. */
51 VDEV_ST_NULL,
52 /* vdev is used, but the USB address is not assigned yet */
53 VDEV_ST_NOTASSIGNED,
54 VDEV_ST_USED,
55 VDEV_ST_ERROR
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); \
66 } \
67 if (usbip_use_stderr) { \
68 fprintf(stderr, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
69 __FILE__, __LINE__, __FUNCTION__, ##args); \
70 } \
71 } while (0)
73 #define notice(fmt, args...) do { \
74 if (usbip_use_syslog) { \
75 syslog(LOG_DEBUG, "usbip: " fmt, ##args); \
76 } \
77 if (usbip_use_stderr) { \
78 fprintf(stderr, "usbip: " fmt "\n", ##args); \
79 } \
80 } while (0)
82 #define info(fmt, args...) do { \
83 if (usbip_use_syslog) { \
84 syslog(LOG_DEBUG, fmt, ##args); \
85 } \
86 if (usbip_use_stderr) { \
87 fprintf(stderr, fmt "\n", ##args); \
88 } \
89 } while (0)
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); \
96 } \
97 if (usbip_use_stderr) { \
98 fprintf(stderr, "usbip dbg: %13s:%4d (%-12s) " fmt "\n", \
99 __FILE__, __LINE__, __FUNCTION__, ##args); \
102 } while (0)
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));
117 struct usb_device {
118 char path[SYSFS_PATH_MAX];
119 char busid[SYSFS_BUS_ID_SIZE];
121 uint32_t busnum;
122 uint32_t devnum;
123 uint32_t speed;
125 uint16_t idVendor;
126 uint16_t idProduct;
127 uint16_t bcdDevice;
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);
153 #endif