usbip_common.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (C) 2005-2007 Takahiro Hirofuchi
  3. */
  4. #ifndef __USBIP_COMMON_H
  5. #define __USBIP_COMMON_H
  6. #include <libudev.h>
  7. #include <stdint.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <syslog.h>
  12. #include <unistd.h>
  13. #include <linux/usb/ch9.h>
  14. #include <linux/usbip.h>
  15. #ifndef USBIDS_FILE
  16. #define USBIDS_FILE "/usr/share/hwdata/usb.ids"
  17. #endif
  18. #ifndef VHCI_STATE_PATH
  19. #define VHCI_STATE_PATH "/var/run/vhci_hcd"
  20. #endif
  21. #define VUDC_DEVICE_DESCR_FILE "dev_desc"
  22. /* kernel module names */
  23. #define USBIP_CORE_MOD_NAME "usbip-core"
  24. #define USBIP_HOST_DRV_NAME "usbip-host"
  25. #define USBIP_DEVICE_DRV_NAME "usbip-vudc"
  26. #define USBIP_VHCI_DRV_NAME "vhci_hcd"
  27. /* sysfs constants */
  28. #define SYSFS_MNT_PATH "/sys"
  29. #define SYSFS_BUS_NAME "bus"
  30. #define SYSFS_BUS_TYPE "usb"
  31. #define SYSFS_DRIVERS_NAME "drivers"
  32. #define SYSFS_PATH_MAX 256
  33. #define SYSFS_BUS_ID_SIZE 32
  34. extern int usbip_use_syslog;
  35. extern int usbip_use_stderr;
  36. extern int usbip_use_debug ;
  37. #define PROGNAME "usbip"
  38. #define pr_fmt(fmt) "%s: %s: " fmt "\n", PROGNAME
  39. #define dbg_fmt(fmt) pr_fmt("%s:%d:[%s] " fmt), "debug", \
  40. __FILE__, __LINE__, __func__
  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. #define info(fmt, args...) \
  51. do { \
  52. if (usbip_use_syslog) { \
  53. syslog(LOG_INFO, pr_fmt(fmt), "info", ##args); \
  54. } \
  55. if (usbip_use_stderr) { \
  56. fprintf(stderr, pr_fmt(fmt), "info", ##args); \
  57. } \
  58. } while (0)
  59. #define dbg(fmt, args...) \
  60. do { \
  61. if (usbip_use_debug) { \
  62. if (usbip_use_syslog) { \
  63. syslog(LOG_DEBUG, dbg_fmt(fmt), ##args); \
  64. } \
  65. if (usbip_use_stderr) { \
  66. fprintf(stderr, dbg_fmt(fmt), ##args); \
  67. } \
  68. } \
  69. } while (0)
  70. #define BUG() \
  71. do { \
  72. err("sorry, it's a bug!"); \
  73. abort(); \
  74. } while (0)
  75. struct usbip_usb_interface {
  76. uint8_t bInterfaceClass;
  77. uint8_t bInterfaceSubClass;
  78. uint8_t bInterfaceProtocol;
  79. uint8_t padding; /* alignment */
  80. } __attribute__((packed));
  81. struct usbip_usb_device {
  82. char path[SYSFS_PATH_MAX];
  83. char busid[SYSFS_BUS_ID_SIZE];
  84. uint32_t busnum;
  85. uint32_t devnum;
  86. uint32_t speed;
  87. uint16_t idVendor;
  88. uint16_t idProduct;
  89. uint16_t bcdDevice;
  90. uint8_t bDeviceClass;
  91. uint8_t bDeviceSubClass;
  92. uint8_t bDeviceProtocol;
  93. uint8_t bConfigurationValue;
  94. uint8_t bNumConfigurations;
  95. uint8_t bNumInterfaces;
  96. } __attribute__((packed));
  97. #define to_string(s) #s
  98. void dump_usb_interface(struct usbip_usb_interface *);
  99. void dump_usb_device(struct usbip_usb_device *);
  100. int read_usb_device(struct udev_device *sdev, struct usbip_usb_device *udev);
  101. int read_attr_value(struct udev_device *dev, const char *name,
  102. const char *format);
  103. int read_usb_interface(struct usbip_usb_device *udev, int i,
  104. struct usbip_usb_interface *uinf);
  105. const char *usbip_speed_string(int num);
  106. const char *usbip_status_string(int32_t status);
  107. int usbip_names_init(char *);
  108. void usbip_names_free(void);
  109. void usbip_names_get_product(char *buff, size_t size, uint16_t vendor,
  110. uint16_t product);
  111. void usbip_names_get_class(char *buff, size_t size, uint8_t class,
  112. uint8_t subclass, uint8_t protocol);
  113. #endif /* __USBIP_COMMON_H */