1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
4  *               2005-2007 Takahiro Hirofuchi
5  * Copyright (C) 2015-2016 Samsung Electronics
6  *               Igor Kotrasinski <i.kotrasinsk@samsung.com>
7  *               Krzysztof Opasiak <k.opasiak@samsung.com>
8  */
9 
10 #include <unistd.h>
11 #include <libudev.h>
12 
13 #include "usbip_host_common.h"
14 #include "usbip_host_driver.h"
15 
16 #undef  PROGNAME
17 #define PROGNAME "libusbip"
18 
is_my_device(struct udev_device * dev)19 static int is_my_device(struct udev_device *dev)
20 {
21 	const char *driver;
22 
23 	driver = udev_device_get_driver(dev);
24 	return driver != NULL && !strcmp(driver, USBIP_HOST_DRV_NAME);
25 }
26 
usbip_host_driver_open(struct usbip_host_driver * hdriver)27 static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
28 {
29 	int ret;
30 
31 	hdriver->ndevs = 0;
32 	INIT_LIST_HEAD(&hdriver->edev_list);
33 
34 	ret = usbip_generic_driver_open(hdriver);
35 	if (ret)
36 		err("please load " USBIP_CORE_MOD_NAME ".ko and "
37 		    USBIP_HOST_DRV_NAME ".ko!");
38 	return ret;
39 }
40 
41 struct usbip_host_driver host_driver = {
42 	.edev_list = LIST_HEAD_INIT(host_driver.edev_list),
43 	.udev_subsystem = "usb",
44 	.ops = {
45 		.open = usbip_host_driver_open,
46 		.close = usbip_generic_driver_close,
47 		.refresh_device_list = usbip_generic_refresh_device_list,
48 		.get_device = usbip_generic_get_device,
49 		.read_device = read_usb_device,
50 		.read_interface = read_usb_interface,
51 		.is_my_device = is_my_device,
52 	},
53 };
54