usbip_host_common.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2015-2016 Samsung Electronics
  3. * Igor Kotrasinski <i.kotrasinsk@samsung.com>
  4. * Krzysztof Opasiak <k.opasiak@samsung.com>
  5. *
  6. * Refactored from usbip_host_driver.c, which is:
  7. * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
  8. * 2005-2007 Takahiro Hirofuchi
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #ifndef __USBIP_HOST_COMMON_H
  24. #define __USBIP_HOST_COMMON_H
  25. #include <stdint.h>
  26. #include <libudev.h>
  27. #include <errno.h>
  28. #include "list.h"
  29. #include "usbip_common.h"
  30. #include "sysfs_utils.h"
  31. struct usbip_host_driver;
  32. struct usbip_host_driver_ops {
  33. int (*open)(struct usbip_host_driver *hdriver);
  34. void (*close)(struct usbip_host_driver *hdriver);
  35. int (*refresh_device_list)(struct usbip_host_driver *hdriver);
  36. struct usbip_exported_device * (*get_device)(
  37. struct usbip_host_driver *hdriver, int num);
  38. int (*read_device)(struct udev_device *sdev,
  39. struct usbip_usb_device *dev);
  40. int (*read_interface)(struct usbip_usb_device *udev, int i,
  41. struct usbip_usb_interface *uinf);
  42. int (*is_my_device)(struct udev_device *udev);
  43. };
  44. struct usbip_host_driver {
  45. int ndevs;
  46. /* list of exported device */
  47. struct list_head edev_list;
  48. const char *udev_subsystem;
  49. struct usbip_host_driver_ops ops;
  50. };
  51. struct usbip_exported_device {
  52. struct udev_device *sudev;
  53. int32_t status;
  54. struct usbip_usb_device udev;
  55. struct list_head node;
  56. struct usbip_usb_interface uinf[];
  57. };
  58. /* External API to access the driver */
  59. static inline int usbip_driver_open(struct usbip_host_driver *hdriver)
  60. {
  61. if (!hdriver->ops.open)
  62. return -EOPNOTSUPP;
  63. return hdriver->ops.open(hdriver);
  64. }
  65. static inline void usbip_driver_close(struct usbip_host_driver *hdriver)
  66. {
  67. if (!hdriver->ops.close)
  68. return;
  69. hdriver->ops.close(hdriver);
  70. }
  71. static inline int usbip_refresh_device_list(struct usbip_host_driver *hdriver)
  72. {
  73. if (!hdriver->ops.refresh_device_list)
  74. return -EOPNOTSUPP;
  75. return hdriver->ops.refresh_device_list(hdriver);
  76. }
  77. static inline struct usbip_exported_device *
  78. usbip_get_device(struct usbip_host_driver *hdriver, int num)
  79. {
  80. if (!hdriver->ops.get_device)
  81. return NULL;
  82. return hdriver->ops.get_device(hdriver, num);
  83. }
  84. /* Helper functions for implementing driver backend */
  85. int usbip_generic_driver_open(struct usbip_host_driver *hdriver);
  86. void usbip_generic_driver_close(struct usbip_host_driver *hdriver);
  87. int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver);
  88. int usbip_export_device(struct usbip_exported_device *edev, int sockfd);
  89. struct usbip_exported_device *usbip_generic_get_device(
  90. struct usbip_host_driver *hdriver, int num);
  91. #endif /* __USBIP_HOST_COMMON_H */