blob: 51ef5fe485dde86f53b7b7debe88682ab3ba693c [file] [log] [blame]
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -07001/*
2 * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 */
4
matt mooney4fd83e82011-06-19 22:44:34 -07005#ifndef __USBIP_COMMON_H
6#define __USBIP_COMMON_H
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -07007
Valentina Manea021aed82014-03-08 14:53:26 +02008#include <libudev.h>
matt mooney4fd83e82011-06-19 22:44:34 -07009
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>
Shuah Khand1fd43d2014-01-24 11:34:13 -070017#include <linux/usb/ch9.h>
Piotr Król6fa9e1b2014-09-05 00:58:02 +020018#include <linux/usbip.h>
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070019
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
Krzysztof Opasiak7b3f74f2016-03-08 21:49:05 +010028#define VUDC_DEVICE_DESCR_FILE "dev_desc"
29
matt mooney5a285cf2011-05-26 06:17:08 -070030/* kernel module names */
31#define USBIP_CORE_MOD_NAME "usbip-core"
32#define USBIP_HOST_DRV_NAME "usbip-host"
Krzysztof Opasiak7b3f74f2016-03-08 21:49:05 +010033#define USBIP_DEVICE_DRV_NAME "usbip-vudc"
matt mooney5a285cf2011-05-26 06:17:08 -070034#define USBIP_VHCI_DRV_NAME "vhci_hcd"
35
Valentina Manea1e940312014-03-08 14:53:19 +020036/* sysfs constants */
37#define SYSFS_MNT_PATH "/sys"
38#define SYSFS_BUS_NAME "bus"
39#define SYSFS_BUS_TYPE "usb"
40#define SYSFS_DRIVERS_NAME "drivers"
41
42#define SYSFS_PATH_MAX 256
43#define SYSFS_BUS_ID_SIZE 32
44
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070045extern int usbip_use_syslog;
46extern int usbip_use_stderr;
47extern int usbip_use_debug ;
48
matt mooney213fd4a2011-06-19 22:44:32 -070049#define PROGNAME "usbip"
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070050
matt mooney213fd4a2011-06-19 22:44:32 -070051#define pr_fmt(fmt) "%s: %s: " fmt "\n", PROGNAME
52#define dbg_fmt(fmt) pr_fmt("%s:%d:[%s] " fmt), "debug", \
Joe Perchesf8628a42014-05-23 22:13:20 -070053 __FILE__, __LINE__, __func__
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070054
matt mooney213fd4a2011-06-19 22:44:32 -070055#define err(fmt, args...) \
56 do { \
57 if (usbip_use_syslog) { \
58 syslog(LOG_ERR, pr_fmt(fmt), "error", ##args); \
59 } \
60 if (usbip_use_stderr) { \
61 fprintf(stderr, pr_fmt(fmt), "error", ##args); \
62 } \
63 } while (0)
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070064
matt mooney213fd4a2011-06-19 22:44:32 -070065#define info(fmt, args...) \
66 do { \
67 if (usbip_use_syslog) { \
68 syslog(LOG_INFO, pr_fmt(fmt), "info", ##args); \
69 } \
70 if (usbip_use_stderr) { \
71 fprintf(stderr, pr_fmt(fmt), "info", ##args); \
72 } \
73 } while (0)
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070074
matt mooney213fd4a2011-06-19 22:44:32 -070075#define dbg(fmt, args...) \
76 do { \
77 if (usbip_use_debug) { \
78 if (usbip_use_syslog) { \
79 syslog(LOG_DEBUG, dbg_fmt(fmt), ##args); \
80 } \
81 if (usbip_use_stderr) { \
82 fprintf(stderr, dbg_fmt(fmt), ##args); \
83 } \
84 } \
85 } while (0)
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070086
matt mooney213fd4a2011-06-19 22:44:32 -070087#define BUG() \
88 do { \
89 err("sorry, it's a bug!"); \
90 abort(); \
91 } while (0)
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070092
matt mooney35dd0c22011-05-27 01:44:14 -070093struct usbip_usb_interface {
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -070094 uint8_t bInterfaceClass;
95 uint8_t bInterfaceSubClass;
96 uint8_t bInterfaceProtocol;
97 uint8_t padding; /* alignment */
98} __attribute__((packed));
99
matt mooney35dd0c22011-05-27 01:44:14 -0700100struct usbip_usb_device {
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -0700101 char path[SYSFS_PATH_MAX];
102 char busid[SYSFS_BUS_ID_SIZE];
103
104 uint32_t busnum;
105 uint32_t devnum;
106 uint32_t speed;
107
108 uint16_t idVendor;
109 uint16_t idProduct;
110 uint16_t bcdDevice;
111
112 uint8_t bDeviceClass;
113 uint8_t bDeviceSubClass;
114 uint8_t bDeviceProtocol;
115 uint8_t bConfigurationValue;
116 uint8_t bNumConfigurations;
117 uint8_t bNumInterfaces;
118} __attribute__((packed));
119
120#define to_string(s) #s
121
matt mooney35dd0c22011-05-27 01:44:14 -0700122void dump_usb_interface(struct usbip_usb_interface *);
123void dump_usb_device(struct usbip_usb_device *);
Valentina Manea021aed82014-03-08 14:53:26 +0200124int read_usb_device(struct udev_device *sdev, struct usbip_usb_device *udev);
125int read_attr_value(struct udev_device *dev, const char *name,
Kurt Kanzenbach9db91e12013-02-22 12:13:29 +0100126 const char *format);
matt mooney35dd0c22011-05-27 01:44:14 -0700127int read_usb_interface(struct usbip_usb_device *udev, int i,
128 struct usbip_usb_interface *uinf);
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -0700129
130const char *usbip_speed_string(int num);
131const char *usbip_status_string(int32_t status);
132
133int usbip_names_init(char *);
134void usbip_names_free(void);
Kurt Kanzenbach9db91e12013-02-22 12:13:29 +0100135void usbip_names_get_product(char *buff, size_t size, uint16_t vendor,
136 uint16_t product);
137void usbip_names_get_class(char *buff, size_t size, uint8_t class,
138 uint8_t subclass, uint8_t protocol);
Takahiro Hirofuchi0945b4f2011-05-14 03:55:07 -0700139
matt mooney4fd83e82011-06-19 22:44:34 -0700140#endif /* __USBIP_COMMON_H */