b38396f618d116f0c83d8f88aec43b3f0c068125
[deliverable/linux.git] / drivers / staging / usbip / userspace / libsrc / usbip_common.h
1 /*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */
4
5 #ifndef _USBIP_COMMON_H
6 #define _USBIP_COMMON_H
7
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
16 #include <sysfs/libsysfs.h>
17 #include <netdb.h>
18 #include <sys/socket.h>
19
20 #ifndef USBIDS_FILE
21 #define USBIDS_FILE "/usr/share/hwdata/usb.ids"
22 #endif
23
24 #ifndef VHCI_STATE_PATH
25 #define VHCI_STATE_PATH "/var/run/vhci_hcd"
26 #endif
27
28 /* kernel module names */
29 #define USBIP_CORE_MOD_NAME "usbip-core"
30 #define USBIP_HOST_DRV_NAME "usbip-host"
31 #define USBIP_VHCI_DRV_NAME "vhci_hcd"
32
33 enum usb_device_speed {
34 USB_SPEED_UNKNOWN = 0, /* enumerating */
35 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
36 USB_SPEED_HIGH, /* usb 2.0 */
37 USB_SPEED_VARIABLE /* wireless (usb 2.5) */
38 };
39
40 /* FIXME: how to sync with drivers/usbip_common.h ? */
41 enum usbip_device_status{
42 /* sdev is available. */
43 SDEV_ST_AVAILABLE = 0x01,
44 /* sdev is now used. */
45 SDEV_ST_USED,
46 /* sdev is unusable because of a fatal error. */
47 SDEV_ST_ERROR,
48
49 /* vdev does not connect a remote device. */
50 VDEV_ST_NULL,
51 /* vdev is used, but the USB address is not assigned yet */
52 VDEV_ST_NOTASSIGNED,
53 VDEV_ST_USED,
54 VDEV_ST_ERROR
55 };
56
57 extern int usbip_use_syslog;
58 extern int usbip_use_stderr;
59 extern int usbip_use_debug ;
60
61 #define err(fmt, args...) do { \
62 if (usbip_use_syslog) { \
63 syslog(LOG_ERR, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
64 __FILE__, __LINE__, __FUNCTION__, ##args); \
65 } \
66 if (usbip_use_stderr) { \
67 fprintf(stderr, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
68 __FILE__, __LINE__, __FUNCTION__, ##args); \
69 } \
70 } while (0)
71
72 #define notice(fmt, args...) do { \
73 if (usbip_use_syslog) { \
74 syslog(LOG_DEBUG, "usbip: " fmt, ##args); \
75 } \
76 if (usbip_use_stderr) { \
77 fprintf(stderr, "usbip: " fmt "\n", ##args); \
78 } \
79 } while (0)
80
81 #define info(fmt, args...) do { \
82 if (usbip_use_syslog) { \
83 syslog(LOG_DEBUG, fmt, ##args); \
84 } \
85 if (usbip_use_stderr) { \
86 fprintf(stderr, fmt "\n", ##args); \
87 } \
88 } while (0)
89
90 #define dbg(fmt, args...) do { \
91 if (usbip_use_debug) { \
92 if (usbip_use_syslog) { \
93 syslog(LOG_DEBUG, "usbip dbg: %13s:%4d (%-12s) " fmt, \
94 __FILE__, __LINE__, __FUNCTION__, ##args); \
95 } \
96 if (usbip_use_stderr) { \
97 fprintf(stderr, "usbip dbg: %13s:%4d (%-12s) " fmt "\n", \
98 __FILE__, __LINE__, __FUNCTION__, ##args); \
99 } \
100 } \
101 } while (0)
102
103
104 #define BUG() do { err("sorry, it's a bug"); abort(); } while (0)
105
106
107 struct usb_interface {
108 uint8_t bInterfaceClass;
109 uint8_t bInterfaceSubClass;
110 uint8_t bInterfaceProtocol;
111 uint8_t padding; /* alignment */
112 } __attribute__((packed));
113
114
115
116 struct usb_device {
117 char path[SYSFS_PATH_MAX];
118 char busid[SYSFS_BUS_ID_SIZE];
119
120 uint32_t busnum;
121 uint32_t devnum;
122 uint32_t speed;
123
124 uint16_t idVendor;
125 uint16_t idProduct;
126 uint16_t bcdDevice;
127
128 uint8_t bDeviceClass;
129 uint8_t bDeviceSubClass;
130 uint8_t bDeviceProtocol;
131 uint8_t bConfigurationValue;
132 uint8_t bNumConfigurations;
133 uint8_t bNumInterfaces;
134 } __attribute__((packed));
135
136 #define to_string(s) #s
137
138 void dump_usb_interface(struct usb_interface *);
139 void dump_usb_device(struct usb_device *);
140 int read_usb_device(struct sysfs_device *sdev, struct usb_device *udev);
141 int read_attr_value(struct sysfs_device *dev, const char *name, const char *format);
142 int read_usb_interface(struct usb_device *udev, int i, struct usb_interface *uinf);
143
144 const char *usbip_speed_string(int num);
145 const char *usbip_status_string(int32_t status);
146
147 int usbip_names_init(char *);
148 void usbip_names_free(void);
149 void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t product);
150 void usbip_names_get_class(char *buff, size_t size, uint8_t class, uint8_t subclass, uint8_t protocol);
151
152 #endif
This page took 0.034349 seconds and 4 git commands to generate.