usbip_common.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /* kernel module names */
  22. #define USBIP_CORE_MOD_NAME "usbip-core"
  23. #define USBIP_HOST_DRV_NAME "usbip-host"
  24. #define USBIP_VHCI_DRV_NAME "vhci_hcd"
  25. /* sysfs constants */
  26. #define SYSFS_MNT_PATH "/sys"
  27. #define SYSFS_BUS_NAME "bus"
  28. #define SYSFS_BUS_TYPE "usb"
  29. #define SYSFS_DRIVERS_NAME "drivers"
  30. #define SYSFS_PATH_MAX 256
  31. #define SYSFS_BUS_ID_SIZE 32
  32. extern int usbip_use_syslog;
  33. extern int usbip_use_stderr;
  34. extern int usbip_use_debug ;
  35. #define PROGNAME "usbip"
  36. #define pr_fmt(fmt) "%s: %s: " fmt "\n", PROGNAME
  37. #define dbg_fmt(fmt) pr_fmt("%s:%d:[%s] " fmt), "debug", \
  38. __FILE__, __LINE__, __func__
  39. #define err(fmt, args...) \
  40. do { \
  41. if (usbip_use_syslog) { \
  42. syslog(LOG_ERR, pr_fmt(fmt), "error", ##args); \
  43. } \
  44. if (usbip_use_stderr) { \
  45. fprintf(stderr, pr_fmt(fmt), "error", ##args); \
  46. } \
  47. } while (0)
  48. #define info(fmt, args...) \
  49. do { \
  50. if (usbip_use_syslog) { \
  51. syslog(LOG_INFO, pr_fmt(fmt), "info", ##args); \
  52. } \
  53. if (usbip_use_stderr) { \
  54. fprintf(stderr, pr_fmt(fmt), "info", ##args); \
  55. } \
  56. } while (0)
  57. #define dbg(fmt, args...) \
  58. do { \
  59. if (usbip_use_debug) { \
  60. if (usbip_use_syslog) { \
  61. syslog(LOG_DEBUG, dbg_fmt(fmt), ##args); \
  62. } \
  63. if (usbip_use_stderr) { \
  64. fprintf(stderr, dbg_fmt(fmt), ##args); \
  65. } \
  66. } \
  67. } while (0)
  68. #define BUG() \
  69. do { \
  70. err("sorry, it's a bug!"); \
  71. abort(); \
  72. } while (0)
  73. struct usbip_usb_interface {
  74. uint8_t bInterfaceClass;
  75. uint8_t bInterfaceSubClass;
  76. uint8_t bInterfaceProtocol;
  77. uint8_t padding; /* alignment */
  78. } __attribute__((packed));
  79. struct usbip_usb_device {
  80. char path[SYSFS_PATH_MAX];
  81. char busid[SYSFS_BUS_ID_SIZE];
  82. uint32_t busnum;
  83. uint32_t devnum;
  84. uint32_t speed;
  85. uint16_t idVendor;
  86. uint16_t idProduct;
  87. uint16_t bcdDevice;
  88. uint8_t bDeviceClass;
  89. uint8_t bDeviceSubClass;
  90. uint8_t bDeviceProtocol;
  91. uint8_t bConfigurationValue;
  92. uint8_t bNumConfigurations;
  93. uint8_t bNumInterfaces;
  94. } __attribute__((packed));
  95. #define to_string(s) #s
  96. void dump_usb_interface(struct usbip_usb_interface *);
  97. void dump_usb_device(struct usbip_usb_device *);
  98. int read_usb_device(struct udev_device *sdev, struct usbip_usb_device *udev);
  99. int read_attr_value(struct udev_device *dev, const char *name,
  100. const char *format);
  101. int read_usb_interface(struct usbip_usb_device *udev, int i,
  102. struct usbip_usb_interface *uinf);
  103. const char *usbip_speed_string(int num);
  104. const char *usbip_status_string(int32_t status);
  105. int usbip_names_init(char *);
  106. void usbip_names_free(void);
  107. void usbip_names_get_product(char *buff, size_t size, uint16_t vendor,
  108. uint16_t product);
  109. void usbip_names_get_class(char *buff, size_t size, uint8_t class,
  110. uint8_t subclass, uint8_t protocol);
  111. #endif /* __USBIP_COMMON_H */