Merge 3.9-rc5 into staging-next
[deliverable/linux.git] / drivers / staging / usbip / userspace / libsrc / usbip_common.h
CommitLineData
0945b4fe
TH
1/*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */
4
4fd83e84 5#ifndef __USBIP_COMMON_H
6#define __USBIP_COMMON_H
7
8#include <sysfs/libsysfs.h>
0945b4fe 9
0945b4fe 10#include <stdint.h>
0945b4fe 11#include <stdio.h>
0945b4fe 12#include <stdlib.h>
4fd83e84 13#include <string.h>
0945b4fe 14
4fd83e84 15#include <syslog.h>
16#include <unistd.h>
0945b4fe
TH
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
5a285cf5 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
0945b4fe
TH
31extern int usbip_use_syslog;
32extern int usbip_use_stderr;
33extern int usbip_use_debug ;
34
213fd4ad 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)
0945b4fe 78
93e18e0e 79enum usb_device_speed {
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 ? */
ba0edc23 87enum usbip_device_status {
93e18e0e 88 /* sdev is available. */
89 SDEV_ST_AVAILABLE = 0x01,
90 /* sdev is now used. */
91 SDEV_ST_USED,
92 /* sdev is unusable because of a fatal error. */
93 SDEV_ST_ERROR,
94
95 /* vdev does not connect a remote device. */
96 VDEV_ST_NULL,
97 /* vdev is used, but the USB address is not assigned yet */
98 VDEV_ST_NOTASSIGNED,
99 VDEV_ST_USED,
100 VDEV_ST_ERROR
101};
102
35dd0c2d 103struct usbip_usb_interface {
0945b4fe
TH
104 uint8_t bInterfaceClass;
105 uint8_t bInterfaceSubClass;
106 uint8_t bInterfaceProtocol;
107 uint8_t padding; /* alignment */
108} __attribute__((packed));
109
35dd0c2d 110struct usbip_usb_device {
0945b4fe
TH
111 char path[SYSFS_PATH_MAX];
112 char busid[SYSFS_BUS_ID_SIZE];
113
114 uint32_t busnum;
115 uint32_t devnum;
116 uint32_t speed;
117
118 uint16_t idVendor;
119 uint16_t idProduct;
120 uint16_t bcdDevice;
121
122 uint8_t bDeviceClass;
123 uint8_t bDeviceSubClass;
124 uint8_t bDeviceProtocol;
125 uint8_t bConfigurationValue;
126 uint8_t bNumConfigurations;
127 uint8_t bNumInterfaces;
128} __attribute__((packed));
129
130#define to_string(s) #s
131
35dd0c2d 132void dump_usb_interface(struct usbip_usb_interface *);
133void dump_usb_device(struct usbip_usb_device *);
134int read_usb_device(struct sysfs_device *sdev, struct usbip_usb_device *udev);
9db91e1b
KK
135int read_attr_value(struct sysfs_device *dev, const char *name,
136 const char *format);
35dd0c2d 137int read_usb_interface(struct usbip_usb_device *udev, int i,
138 struct usbip_usb_interface *uinf);
0945b4fe
TH
139
140const char *usbip_speed_string(int num);
141const char *usbip_status_string(int32_t status);
142
143int usbip_names_init(char *);
144void usbip_names_free(void);
9db91e1b
KK
145void usbip_names_get_product(char *buff, size_t size, uint16_t vendor,
146 uint16_t product);
147void usbip_names_get_class(char *buff, size_t size, uint8_t class,
148 uint8_t subclass, uint8_t protocol);
0945b4fe 149
4fd83e84 150#endif /* __USBIP_COMMON_H */
This page took 0.200775 seconds and 5 git commands to generate.