Path: blob/master/tools/usb/usbip/libsrc/usbip_host_common.h
26288 views
/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Copyright (C) 2015-2016 Samsung Electronics3* Igor Kotrasinski <[email protected]>4* Krzysztof Opasiak <[email protected]>5*6* Refactored from usbip_host_driver.c, which is:7* Copyright (C) 2011 matt mooney <[email protected]>8* 2005-2007 Takahiro Hirofuchi9*/1011#ifndef __USBIP_HOST_COMMON_H12#define __USBIP_HOST_COMMON_H1314#include <stdint.h>15#include <libudev.h>16#include <errno.h>17#include "list.h"18#include "usbip_common.h"19#include "sysfs_utils.h"2021struct usbip_host_driver;2223struct usbip_host_driver_ops {24int (*open)(struct usbip_host_driver *hdriver);25void (*close)(struct usbip_host_driver *hdriver);26int (*refresh_device_list)(struct usbip_host_driver *hdriver);27struct usbip_exported_device * (*get_device)(28struct usbip_host_driver *hdriver, int num);2930int (*read_device)(struct udev_device *sdev,31struct usbip_usb_device *dev);32int (*read_interface)(struct usbip_usb_device *udev, int i,33struct usbip_usb_interface *uinf);34int (*is_my_device)(struct udev_device *udev);35};3637struct usbip_host_driver {38int ndevs;39/* list of exported device */40struct list_head edev_list;41const char *udev_subsystem;42struct usbip_host_driver_ops ops;43};4445struct usbip_exported_device {46struct udev_device *sudev;47int32_t status;48struct usbip_usb_device udev;49struct list_head node;50struct usbip_usb_interface uinf[];51};5253/* External API to access the driver */54static inline int usbip_driver_open(struct usbip_host_driver *hdriver)55{56if (!hdriver->ops.open)57return -EOPNOTSUPP;58return hdriver->ops.open(hdriver);59}6061static inline void usbip_driver_close(struct usbip_host_driver *hdriver)62{63if (!hdriver->ops.close)64return;65hdriver->ops.close(hdriver);66}6768static inline int usbip_refresh_device_list(struct usbip_host_driver *hdriver)69{70if (!hdriver->ops.refresh_device_list)71return -EOPNOTSUPP;72return hdriver->ops.refresh_device_list(hdriver);73}7475static inline struct usbip_exported_device *76usbip_get_device(struct usbip_host_driver *hdriver, int num)77{78if (!hdriver->ops.get_device)79return NULL;80return hdriver->ops.get_device(hdriver, num);81}8283/* Helper functions for implementing driver backend */84int usbip_generic_driver_open(struct usbip_host_driver *hdriver);85void usbip_generic_driver_close(struct usbip_host_driver *hdriver);86int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver);87int usbip_export_device(struct usbip_exported_device *edev, int sockfd);88struct usbip_exported_device *usbip_generic_get_device(89struct usbip_host_driver *hdriver, int num);9091#endif /* __USBIP_HOST_COMMON_H */929394