2 * Copyright (C) 2015-2016 Samsung Electronics
6 * Refactored from usbip_host_driver.c, which is:
8 * 2005-2007 Takahiro Hirofuchi
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.
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.
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/>.
24 #ifndef __USBIP_HOST_COMMON_H
25 #define __USBIP_HOST_COMMON_H
31 #include "usbip_common.h"
32 #include "sysfs_utils.h"
34 struct usbip_host_driver;
36 struct usbip_host_driver_ops {
37 int (*open)(struct usbip_host_driver *hdriver);
38 void (*close)(struct usbip_host_driver *hdriver);
39 int (*refresh_device_list)(struct usbip_host_driver *hdriver);
40 struct usbip_exported_device * (*get_device)(
41 struct usbip_host_driver *hdriver, int num);
43 int (*read_device)(struct udev_device *sdev,
44 struct usbip_usb_device *dev);
45 int (*read_interface)(struct usbip_usb_device *udev, int i,
46 struct usbip_usb_interface *uinf);
47 int (*is_my_device)(struct udev_device *udev);
50 struct usbip_host_driver {
52 /* list of exported device */
53 struct list_head edev_list;
54 const char *udev_subsystem;
55 struct usbip_host_driver_ops ops;
58 struct usbip_exported_device {
59 struct udev_device *sudev;
61 struct usbip_usb_device udev;
62 struct list_head node;
63 struct usbip_usb_interface uinf[];
66 /* External API to access the driver */
67 static inline int usbip_driver_open(struct usbip_host_driver *hdriver)
69 if (!hdriver->ops.open)
71 return hdriver->ops.open(hdriver);
74 static inline void usbip_driver_close(struct usbip_host_driver *hdriver)
76 if (!hdriver->ops.close)
78 hdriver->ops.close(hdriver);
81 static inline int usbip_refresh_device_list(struct usbip_host_driver *hdriver)
83 if (!hdriver->ops.refresh_device_list)
85 return hdriver->ops.refresh_device_list(hdriver);
88 static inline struct usbip_exported_device *
89 usbip_get_device(struct usbip_host_driver *hdriver, int num)
91 if (!hdriver->ops.get_device)
93 return hdriver->ops.get_device(hdriver, num);
96 /* Helper functions for implementing driver backend */
97 int usbip_generic_driver_open(struct usbip_host_driver *hdriver);
98 void usbip_generic_driver_close(struct usbip_host_driver *hdriver);
99 int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver);
100 int usbip_export_device(struct usbip_exported_device *edev, int sockfd);
101 struct usbip_exported_device *usbip_generic_get_device(
102 struct usbip_host_driver *hdriver, int num);
104 #endif /* __USBIP_HOST_COMMON_H */