Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
usbip_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2007 Takahiro Hirofuchi
3  */
4 
5 #ifndef __USBIP_COMMON_H
6 #define __USBIP_COMMON_H
7 
8 #include <sysfs/libsysfs.h>
9 
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #include <syslog.h>
16 #include <unistd.h>
17 
18 #ifndef USBIDS_FILE
19 #define USBIDS_FILE "/usr/share/hwdata/usb.ids"
20 #endif
21 
22 #ifndef VHCI_STATE_PATH
23 #define VHCI_STATE_PATH "/var/run/vhci_hcd"
24 #endif
25 
26 /* kernel module names */
27 #define USBIP_CORE_MOD_NAME "usbip-core"
28 #define USBIP_HOST_DRV_NAME "usbip-host"
29 #define USBIP_VHCI_DRV_NAME "vhci_hcd"
30 
31 extern int usbip_use_syslog;
32 extern int usbip_use_stderr;
33 extern int usbip_use_debug ;
34 
35 #define PROGNAME "usbip"
36 
37 #define pr_fmt(fmt) "%s: %s: " fmt "\n", PROGNAME
38 #define dbg_fmt(fmt) pr_fmt("%s:%d:[%s] " fmt), "debug", \
39  __FILE__, __LINE__, __FUNCTION__
40 
41 #define err(fmt, args...) \
42  do { \
43  if (usbip_use_syslog) { \
44  syslog(LOG_ERR, pr_fmt(fmt), "error", ##args); \
45  } \
46  if (usbip_use_stderr) { \
47  fprintf(stderr, pr_fmt(fmt), "error", ##args); \
48  } \
49  } while (0)
50 
51 #define info(fmt, args...) \
52  do { \
53  if (usbip_use_syslog) { \
54  syslog(LOG_INFO, pr_fmt(fmt), "info", ##args); \
55  } \
56  if (usbip_use_stderr) { \
57  fprintf(stderr, pr_fmt(fmt), "info", ##args); \
58  } \
59  } while (0)
60 
61 #define dbg(fmt, args...) \
62  do { \
63  if (usbip_use_debug) { \
64  if (usbip_use_syslog) { \
65  syslog(LOG_DEBUG, dbg_fmt(fmt), ##args); \
66  } \
67  if (usbip_use_stderr) { \
68  fprintf(stderr, dbg_fmt(fmt), ##args); \
69  } \
70  } \
71  } while (0)
72 
73 #define BUG() \
74  do { \
75  err("sorry, it's a bug!"); \
76  abort(); \
77  } while (0)
78 
80  USB_SPEED_UNKNOWN = 0, /* enumerating */
81  USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
82  USB_SPEED_HIGH, /* usb 2.0 */
83  USB_SPEED_VARIABLE /* wireless (usb 2.5) */
84 };
85 
86 /* FIXME: how to sync with drivers/usbip_common.h ? */
88  /* sdev is available. */
90  /* sdev is now used. */
92  /* sdev is unusable because of a fatal error. */
94 
95  /* vdev does not connect a remote device. */
97  /* vdev is used, but the USB address is not assigned yet */
101 };
102 
107  uint8_t padding; /* alignment */
108 } __attribute__((packed));
112  char busid[SYSFS_BUS_ID_SIZE];
113 
117 
121 
128 } __attribute__((packed));
130 #define to_string(s) #s
131 
134 int read_usb_device(struct sysfs_device *sdev, struct usbip_usb_device *udev);
135 int read_attr_value(struct sysfs_device *dev, const char *name, const char *format);
139 const char *usbip_speed_string(int num);
142 int usbip_names_init(char *);
143 void usbip_names_free(void);
146 
147 #endif /* __USBIP_COMMON_H */