xref: /linux/tools/usb/usbip/src/usbip_port.c (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2588b48caSValentina Manea /*
3588b48caSValentina Manea  * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
4588b48caSValentina Manea  *               2005-2007 Takahiro Hirofuchi
5588b48caSValentina Manea  */
6588b48caSValentina Manea 
7588b48caSValentina Manea #include "vhci_driver.h"
8588b48caSValentina Manea #include "usbip_common.h"
9588b48caSValentina Manea 
list_imported_devices(void)10588b48caSValentina Manea static int list_imported_devices(void)
11588b48caSValentina Manea {
12588b48caSValentina Manea 	int i;
13588b48caSValentina Manea 	struct usbip_imported_device *idev;
14588b48caSValentina Manea 	int ret;
15588b48caSValentina Manea 
16e66fa8b0SNobuo Iwata 	if (usbip_names_init(USBIDS_FILE))
17e66fa8b0SNobuo Iwata 		err("failed to open %s", USBIDS_FILE);
18e66fa8b0SNobuo Iwata 
19588b48caSValentina Manea 	ret = usbip_vhci_driver_open();
20588b48caSValentina Manea 	if (ret < 0) {
21*0c7f35d2SGalen Guyer 		err("open vhci_driver (is vhci_hcd loaded?)");
22e66fa8b0SNobuo Iwata 		goto err_names_free;
23588b48caSValentina Manea 	}
24588b48caSValentina Manea 
25588b48caSValentina Manea 	printf("Imported USB devices\n");
26588b48caSValentina Manea 	printf("====================\n");
27588b48caSValentina Manea 
28588b48caSValentina Manea 	for (i = 0; i < vhci_driver->nports; i++) {
29588b48caSValentina Manea 		idev = &vhci_driver->idev[i];
30588b48caSValentina Manea 
31588b48caSValentina Manea 		if (usbip_vhci_imported_device_dump(idev) < 0)
32e66fa8b0SNobuo Iwata 			goto err_driver_close;
33588b48caSValentina Manea 	}
34588b48caSValentina Manea 
35588b48caSValentina Manea 	usbip_vhci_driver_close();
36e66fa8b0SNobuo Iwata 	usbip_names_free();
37588b48caSValentina Manea 
38588b48caSValentina Manea 	return ret;
39588b48caSValentina Manea 
40e66fa8b0SNobuo Iwata err_driver_close:
41e66fa8b0SNobuo Iwata 	usbip_vhci_driver_close();
42e66fa8b0SNobuo Iwata err_names_free:
43e66fa8b0SNobuo Iwata 	usbip_names_free();
44e66fa8b0SNobuo Iwata 	return -1;
45588b48caSValentina Manea }
46588b48caSValentina Manea 
usbip_port_show(int argc,char * argv[])47588b48caSValentina Manea int usbip_port_show(__attribute__((unused)) int argc,
48588b48caSValentina Manea 		    __attribute__((unused)) char *argv[])
49588b48caSValentina Manea {
50588b48caSValentina Manea 	int ret;
51588b48caSValentina Manea 
52588b48caSValentina Manea 	ret = list_imported_devices();
53588b48caSValentina Manea 	if (ret < 0)
54588b48caSValentina Manea 		err("list imported devices");
55588b48caSValentina Manea 
56588b48caSValentina Manea 	return ret;
57588b48caSValentina Manea }
58