├── Documentation
└── usb
│ └── usbip_protocol.txt
├── README
├── cleanup.sh
├── drivers
└── usb
│ └── usbip
│ ├── Kconfig
│ ├── Makefile
│ ├── README
│ ├── stub.h
│ ├── stub_dev.c
│ ├── stub_main.c
│ ├── stub_rx.c
│ ├── stub_tx.c
│ ├── usbip_common.c
│ ├── usbip_common.h
│ ├── usbip_event.c
│ ├── usbip_ux.c
│ ├── usbip_ux.h
│ ├── vhci.h
│ ├── vhci_hcd.c
│ ├── vhci_rx.c
│ ├── vhci_sysfs.c
│ ├── vhci_tx.c
│ ├── vudc.h
│ ├── vudc_dev.c
│ ├── vudc_main.c
│ ├── vudc_rx.c
│ ├── vudc_sysfs.c
│ ├── vudc_transfer.c
│ └── vudc_tx.c
├── include
└── uapi
│ └── linux
│ ├── usbip.h
│ ├── usbip_api.h
│ └── usbip_ux.h
├── install.sh
└── tools
└── usb
└── usbip
├── .gitignore
├── AUTHORS
├── COPYING
├── INSTALL
├── Makefile.am
├── README
├── api-example
├── INSTALL
├── Makefile.am
├── README
├── autogen.sh
├── cleanup.sh
├── configure.ac
├── doc
│ ├── usbip_ex_cmd_attach.8
│ ├── usbip_ex_cmd_bind.8
│ ├── usbip_ex_cmd_connect.8
│ ├── usbip_ex_cmd_detach.8
│ ├── usbip_ex_cmd_disconnect.8
│ ├── usbip_ex_cmd_list_local.8
│ ├── usbip_ex_cmd_list_remote.8
│ ├── usbip_ex_cmd_port.8
│ ├── usbip_ex_cmd_unbind.8
│ ├── usbip_ex_daemon_app.8
│ └── usbip_ex_daemon_dev.8
└── src
│ ├── Makefile.am
│ ├── usbip_ex.h
│ ├── usbip_ex_cmd_attach.c
│ ├── usbip_ex_cmd_bind.c
│ ├── usbip_ex_cmd_connect.c
│ ├── usbip_ex_cmd_detach.c
│ ├── usbip_ex_cmd_disconnect.c
│ ├── usbip_ex_cmd_list_local.c
│ ├── usbip_ex_cmd_list_remote.c
│ ├── usbip_ex_cmd_port.c
│ ├── usbip_ex_cmd_unbind.c
│ ├── usbip_ex_daemon.c
│ ├── usbip_ex_net_client.c
│ ├── usbip_ex_net_common.c
│ └── usbip_ex_net_server.c
├── autogen.sh
├── cleanup.sh
├── configure.ac
├── doc
├── usbip.8
├── usbip_attach_device.3
├── usbip_bind_device.3
├── usbip_break_all_connections.3
├── usbip_break_connection.3
├── usbip_conn_init.3
├── usbip_connect_device.3
├── usbip_detach_port.3
├── usbip_disconnect_device.3
├── usbip_hdriver_set.3
├── usbip_list_importable_devices.3
├── usbip_list_imported_devices.3
├── usbip_list_local_devices.3
├── usbip_set_debug_flags.3
├── usbip_set_use_debug.3
├── usbip_set_use_stderr.3
├── usbip_set_use_syslog.3
├── usbip_sock_init.3
├── usbip_unbind_device.3
├── usbipa.8
├── usbipd.8
├── usbipd_driver_close.3
├── usbipd_driver_open.3
└── usbipd_recv_pdu.3
├── libsrc
├── Makefile.am
├── list.h
├── names.c
├── names.h
├── sysfs_utils.c
├── sysfs_utils.h
├── usbip_common.c
├── usbip_common.h
├── usbip_config.h
├── usbip_device_driver.c
├── usbip_device_driver.h
├── usbip_host_api.c
├── usbip_host_common.c
├── usbip_host_common.h
├── usbip_host_driver.c
├── usbip_host_driver.h
├── usbip_ux.c
├── usbip_ux.h
├── vhci_driver.c
└── vhci_driver.h
├── libusb
├── INSTALL
├── Makefile.am
├── autogen.sh
├── cleanup.sh
├── configure.ac
├── doc
│ ├── usbip_libusb.8
│ └── usbipd_libusb.8
├── libsrc
│ ├── Makefile.am
│ └── dummy_device_driver.c
├── os
│ ├── darwin
│ │ ├── BUILD
│ │ ├── README
│ │ └── usbip_os.h
│ ├── unix
│ │ └── BUILD
│ ├── usbip_os.h
│ ├── usbip_sock.h
│ └── win32
│ │ ├── BUILD
│ │ ├── README
│ │ ├── copy_usbip_to_win32.sh
│ │ ├── usbip_os.h
│ │ └── usbip_sock.h
├── src
│ └── Makefile.am
└── stub
│ ├── Makefile.am
│ ├── stub.h
│ ├── stub_common.c
│ ├── stub_common.h
│ ├── stub_dev.c
│ ├── stub_event.c
│ ├── stub_main.c
│ ├── stub_rx.c
│ └── stub_tx.c
└── src
├── Makefile.am
├── usbip.c
├── usbip.h
├── usbip_attach.c
├── usbip_bind.c
├── usbip_connect.c
├── usbip_detach.c
├── usbip_disconnect.c
├── usbip_list.c
├── usbip_network.c
├── usbip_network.h
├── usbip_port.c
├── usbip_unbind.c
├── usbipd.c
├── usbipd.h
├── usbipd_app.c
└── usbipd_dev.c
/README:
--------------------------------------------------------------------------------
1 | An advanced USB/IP including features:
2 |
3 | 1. Exporting device
4 |
5 | It allows to connect from device side. Many devices can be connected to
6 | remote with plug-and-play manner.
7 |
8 | EXISTING) - invites devices from application(vhci)-side
9 | +------+ +------------------+
10 | device--+ STUB | | application/VHCI |
11 | +------+ +------------------+
12 | 1) # usbipd ... start daemon
13 | = = =
14 | 2) # usbip list --local
15 | 3) # usbip bind
16 | <--- list bound devices --- 4) # usbip list --remote
17 | <--- import a device ------ 5) # usbip attach
18 | = = =
19 | X disconnected 6) # usbip detach
20 | 7) usbip unbind
21 |
22 | NEW) - dedicates devices from device(stub)-side
23 | +------+ +------------------+
24 | device--+ STUB | | application/VHCI |
25 | +------+ +------------------+
26 | 1) # usbipa ... start daemon
27 | = = =
28 | 2) # usbip list --local
29 | 3) # usbip connect --- export a device ------>
30 | = = =
31 | 4) # usbip disconnect --- un-export a device --->
32 |
33 | You can add allow/deny rules with TCP wrappers (./configure
34 | --with-tcp-wrappers) and/or udev rules.
35 |
36 | 2. VHCI number of ports extension
37 |
38 | It extends number of ports limitaion in application (vhci) side by
39 | multiplying number of VHCI.
40 |
41 | Driver portion of static extension has been merged at 4.9-rc1. Userspace
42 | tools and dynamic extenstion are added.
43 |
44 | USBIP_VHCI_HC_PORTS:
45 | Number of ports per USB/IP virtual host controller. The default is 8.
46 | USBIP_VHCI_MAX_HCS:
47 | Maximum number of USB/IP virtual host controllers. The default is 1.
48 | USBIP_VHCI_INIT_HCS:
49 | Initial number of USB/IP virtual host controllers. The default is 1.
50 |
51 | 3. Cross platform device side node
52 |
53 | It adds porting of USB/IP device side command and daemon with libusb instead
54 | of stub driver. It allows to port device side node to other operation
55 | systems which are supported by libusb.
56 |
57 | tools/usb/usbip
58 | +-- src: command and daemon
59 | +-- libsrc: common, host driver interface and vhci driver interface
60 | +-- doc: manuals
61 | +-- libusb : implementation with libusb (newly added)
62 | +-- src: makes ../../src objects without stub driver dependent
63 | | code giving -DUSBIP_WITH_LIBUSB.
64 | +-- libsrc: makes ../../libsrc objects giving -DUSBIP_WITH_LIBUSB.
65 | | +-- dummy_device_driver.c : dummy host device driver
66 | +-- stub: stub driver emulation library with libusb.
67 | +-- os: OS dependent code.
68 | | +-- unix: unix dependent code used in libusb.
69 | | +-- win32: Win32 dependent cocde.
70 | +-- doc: manuals
71 |
72 | Make
73 | in tools/usb/usbip : original with stub driver
74 | in tools/usb/usbip/libusb : new with stub emulator with libusb
75 | ./configure --with-dummy-driver applies dummy host device driver
76 | instead of vUDC.
77 |
78 | Binary names
79 | usbip: command with stub/vhci driver (original)
80 | usbipd: daemon with vhci driver (original)
81 | usbipa: daemon with stub driver (new as 1)
82 | libusbip: command with stub emulator (new)
83 | libusbipd: daemon with stub emulator (new)
84 |
85 | 4. API to add arbitrary network protocol
86 |
87 | It introduces userspace API to add network protocols to USB/IP. The API
88 | allows to program to wrap USB/IP with arbitrary network protocol using
89 | network protocol library, for example, libwebsockets or Poco C++ for
90 | WebSocket.
91 |
92 | The detail of the API is written as manual pages.
93 |
94 | The shared libraries below are created.
95 | libusbip.so : common, as same as original
96 | libusbipc.so : for commands
97 | libusbipd.so : for device side daemon
98 | libusbipa.so : for application side daemon
99 | Device side libraries with libub are created by build at
100 | tools/usb/usbip/libusb.
101 | libusbip_libusb.so : common
102 | libusbip_stub.so : stub emulator with libusb
103 | libusdipc_libusb.so : for device side commands
104 | libusbipd_libusb.so : for device side daemon
105 |
106 | To enable the API, a driver to forward packets to userspace should be
107 | loaded.
108 | # modprobe usbip-host (original, device side)
109 | # modprobe vhci-hcd (original, application side)
110 | # modprobe usbip-ux (new, both device and application side)
111 |
112 | A simple example for USB/IP API using IPv4 socket is included. USB over
113 | WebSocket using OSSs are stored in github below.
114 | with Poco C++ : https://github.com/novimusica/usbws-poco
115 | with libwebsockets : https://github.com/novimusica/usbws-lws
116 |
117 | //
118 |
--------------------------------------------------------------------------------
/cleanup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | function clean_tool() {
4 | sudo make uninstall
5 | make clean
6 | if [ ! -x cleanup.sh ]; then
7 | chmod a+x cleanup.sh
8 | fi
9 | ./cleanup.sh
10 | }
11 |
12 | DIR_TEST=`pwd`
13 | DIR_DRV=$DIR_TEST/drivers/usb/usbip
14 | DIR_TOOL=$DIR_TEST/tools/usb/usbip
15 | DIR_EX=$DIR_TEST/tools/usb/usbip/api-example
16 | DIR_LIBUSB_TOOL=$DIR_TEST/tools/usb/usbip/libusb
17 | KERNEL=`uname -r`
18 | DIR_KERN_INC=/lib/modules/$KERNEL/build/include
19 | DIR_KERN_MOD=/lib/modules/$KERNEL/kernel/drivers/usb/usbip
20 | DIR_UAPI_INC=/usr/include/linux
21 |
22 | sudo rm -f $DIR_KERN_INC/uapi/linux/usbip_ux.h
23 | sudo rm -f $DIR_UAPI_INC/usbip_ux.h
24 | sudo rm -f $DIR_UAPI_INC/usbip_api.h
25 |
26 | pushd .
27 | cd $DIR_DRV
28 | make clean
29 | sudo rm $DIR_KERN_MOD/*.ko
30 | sudo depmod -a
31 | popd
32 |
33 | if [ -e $DIR_EX ]; then
34 | pushd .
35 | cd $DIR_EX
36 | clean_tool
37 | popd
38 | fi
39 |
40 | if [ -e $DIR_LIBUSB_TOOL ]; then
41 | pushd .
42 | cd $DIR_LIBUSB_TOOL
43 | clean_tool
44 | popd
45 | fi
46 |
47 | pushd .
48 | cd $DIR_TOOL
49 | clean_tool
50 | popd
51 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/Kconfig:
--------------------------------------------------------------------------------
1 | config USBIP_CORE
2 | tristate "USB/IP support"
3 | depends on NET
4 | select USB_COMMON
5 | ---help---
6 | This enables pushing USB packets over IP to allow remote
7 | machines direct access to USB devices. It provides the
8 | USB/IP core that is required by both drivers.
9 |
10 | For more details, and to get the userspace utility
11 | programs, please see .
12 |
13 | To compile this as a module, choose M here: the module will
14 | be called usbip-core.
15 |
16 | If unsure, say N.
17 |
18 | config USBIP_UX
19 | tristate "USB/IP userspace URB transmission"
20 | depends on USBIP_CORE
21 | ---help---
22 | This moves USB/IP URB transmission to userspace
23 | to use USB/IP API.
24 |
25 | To compile this driver as a module, choose M here: the
26 | module will be called usbip-ux.
27 |
28 | config USBIP_VHCI_HCD
29 | tristate "VHCI hcd"
30 | depends on USBIP_CORE && USB
31 | ---help---
32 | This enables the USB/IP virtual host controller driver,
33 | which is run on the remote machine.
34 |
35 | To compile this driver as a module, choose M here: the
36 | module will be called vhci-hcd.
37 |
38 | config USBIP_VHCI_HC_PORTS
39 | int "Number of ports per USB/IP virtual host controller"
40 | range 1 31
41 | default 8
42 | depends on USBIP_VHCI_HCD
43 | ---help---
44 | To increase number of ports available for USB/IP virtual
45 | host controller driver, this defines number of ports per
46 | USB/IP virtual host controller.
47 |
48 | config USBIP_VHCI_MAX_HCS
49 | int "Maximum number of USB/IP virtual host controllers"
50 | range 1 128
51 | default 1
52 | depends on USBIP_VHCI_HCD
53 | ---help---
54 | To increase number of ports available for USB/IP virtual
55 | host controller driver, this defines number of USB/IP
56 | virtual host controllers as if adding physical host
57 | controllers. This defines the maximum number.
58 |
59 | config USBIP_VHCI_INIT_HCS
60 | int "Initial number of USB/IP virtual host controllers"
61 | range 1 USBIP_VHCI_MAX_HCS
62 | default 1
63 | depends on USBIP_VHCI_MAX_HCS
64 | ---help---
65 | To increase number of ports available for USB/IP virtual
66 | host controller driver, this defines number of USB/IP
67 | virtual host controllers as if adding physical host
68 | controllers. This defines the number at initializing.
69 |
70 | config USBIP_HOST
71 | tristate "Host driver"
72 | depends on USBIP_CORE && USB
73 | ---help---
74 | This enables the USB/IP host driver, which is run on the
75 | machine that is sharing the USB devices.
76 |
77 | To compile this driver as a module, choose M here: the
78 | module will be called usbip-host.
79 |
80 | config USBIP_VUDC
81 | tristate "VUDC driver"
82 | depends on USBIP_CORE && USB_GADGET
83 | ---help---
84 | This enables the USB/IP virtual USB device controller
85 | driver, which is run on the host machine, allowing the
86 | machine itself to act as a device.
87 |
88 | To compile this driver as a module, choose M here: the
89 | module will be called usbip-vudc.
90 |
91 | config USBIP_DEBUG
92 | bool "Debug messages for USB/IP"
93 | depends on USBIP_CORE
94 | ---help---
95 | This enables the debug messages from the USB/IP drivers.
96 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Made from Makefile.org by nobuo.iwata@fujixerox.co.jp
3 | #
4 |
5 | ccflags-y += -DDEBUG
6 |
7 | obj-m += usbip-core.o
8 | usbip-core-y := usbip_common.o usbip_event.o
9 |
10 | obj-m += usbip-ux.o
11 | usbip-ux-y := usbip_ux.o
12 |
13 | obj-m += vhci-hcd.o
14 | vhci-hcd-y := vhci_sysfs.o vhci_tx.o vhci_rx.o vhci_hcd.o
15 |
16 | obj-m += usbip-host.o
17 | usbip-host-y := stub_dev.o stub_main.o stub_rx.o stub_tx.o
18 |
19 | # obj-m += usbip-vudc.o
20 | # usbip-vudc-y := vudc_dev.o vudc_sysfs.o vudc_tx.o vudc_rx.o vudc_transfer.o vudc_main.o
21 |
22 | # ccflags-y := -I$(src)/../../../include
23 |
24 | KERNELDIR ?= /lib/modules/$(shell uname -r)/build
25 | PWD := $(shell pwd)
26 |
27 | modules:
28 | $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules \
29 | C=1 CF=-D__CHECK_ENDIAN__
30 |
31 | all:
32 | @for mod in $(MODULES) ; do \
33 | (make MODULE=$$mod) ;\
34 | done
35 |
36 | clean:
37 | rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
38 |
39 | depend .depend dep:
40 | $(CC) $(CFLAGS) -M *.c > .depend
41 |
42 | ifeq (.depend,$(wildcard .depend))
43 | include .depend
44 | endif
45 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/README:
--------------------------------------------------------------------------------
1 | TODO:
2 | - more discussion about the protocol
3 | - testing
4 | - review of the userspace interface
5 | - document the protocol
6 |
7 | Please send patches for this code to Greg Kroah-Hartman
8 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/stub.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2003-2008 Takahiro Hirofuchi
3 | *
4 | * This is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation; either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 | * USA.
18 | */
19 |
20 | #ifndef __USBIP_STUB_H
21 | #define __USBIP_STUB_H
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | #define STUB_BUSID_OTHER 0
31 | #define STUB_BUSID_REMOV 1
32 | #define STUB_BUSID_ADDED 2
33 | #define STUB_BUSID_ALLOC 3
34 |
35 | struct stub_device {
36 | struct usb_device *udev;
37 |
38 | struct usbip_device ud;
39 | __u32 devid;
40 |
41 | /*
42 | * stub_priv preserves private data of each urb.
43 | * It is allocated as stub_priv_cache and assigned to urb->context.
44 | *
45 | * stub_priv is always linked to any one of 3 lists;
46 | * priv_init: linked to this until the comletion of a urb.
47 | * priv_tx : linked to this after the completion of a urb.
48 | * priv_free: linked to this after the sending of the result.
49 | *
50 | * Any of these list operations should be locked by priv_lock.
51 | */
52 | spinlock_t priv_lock;
53 | struct list_head priv_init;
54 | struct list_head priv_tx;
55 | struct list_head priv_free;
56 |
57 | /* see comments for unlinking in stub_rx.c */
58 | struct list_head unlink_tx;
59 | struct list_head unlink_free;
60 |
61 | wait_queue_head_t tx_waitq;
62 | };
63 |
64 | /* private data into urb->priv */
65 | struct stub_priv {
66 | unsigned long seqnum;
67 | struct list_head list;
68 | struct stub_device *sdev;
69 | struct urb *urb;
70 |
71 | int unlinking;
72 | };
73 |
74 | struct stub_unlink {
75 | unsigned long seqnum;
76 | struct list_head list;
77 | __u32 status;
78 | };
79 |
80 | /* same as SYSFS_BUS_ID_SIZE */
81 | #define BUSID_SIZE 32
82 |
83 | struct bus_id_priv {
84 | char name[BUSID_SIZE];
85 | char status;
86 | int interf_count;
87 | struct stub_device *sdev;
88 | struct usb_device *udev;
89 | char shutdown_busid;
90 | };
91 |
92 | /* stub_priv is allocated from stub_priv_cache */
93 | extern struct kmem_cache *stub_priv_cache;
94 |
95 | /* stub_dev.c */
96 | extern struct usb_device_driver stub_driver;
97 |
98 | /* stub_main.c */
99 | struct bus_id_priv *get_busid_priv(const char *busid);
100 | int del_match_busid(char *busid);
101 | void stub_device_cleanup_urbs(struct stub_device *sdev);
102 |
103 | /* stub_rx.c */
104 | int stub_rx_loop(void *data);
105 |
106 | /* stub_tx.c */
107 | void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
108 | __u32 status);
109 | void stub_complete(struct urb *urb);
110 | int stub_tx_loop(void *data);
111 |
112 | #endif /* __USBIP_STUB_H */
113 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/usbip_event.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2003-2008 Takahiro Hirofuchi
3 | * Copyright (C) 2015 Nobuo Iwata
4 | *
5 | * This is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 2 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 | * USA.
19 | */
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include "usbip_common.h"
27 |
28 | struct usbip_event {
29 | struct list_head node;
30 | struct usbip_device *ud;
31 | };
32 |
33 | static DEFINE_SPINLOCK(event_lock);
34 | static LIST_HEAD(event_list);
35 |
36 | static void set_event(struct usbip_device *ud, unsigned long event)
37 | {
38 | unsigned long flags;
39 |
40 | spin_lock_irqsave(&ud->lock, flags);
41 | ud->event |= event;
42 | spin_unlock_irqrestore(&ud->lock, flags);
43 | }
44 |
45 | static void unset_event(struct usbip_device *ud, unsigned long event)
46 | {
47 | unsigned long flags;
48 |
49 | spin_lock_irqsave(&ud->lock, flags);
50 | ud->event &= ~event;
51 | spin_unlock_irqrestore(&ud->lock, flags);
52 | }
53 |
54 | static struct usbip_device *get_event(void)
55 | {
56 | struct usbip_event *ue = NULL;
57 | struct usbip_device *ud = NULL;
58 | unsigned long flags;
59 |
60 | spin_lock_irqsave(&event_lock, flags);
61 | if (!list_empty(&event_list)) {
62 | ue = list_first_entry(&event_list, struct usbip_event, node);
63 | list_del(&ue->node);
64 | }
65 | spin_unlock_irqrestore(&event_lock, flags);
66 |
67 | if (ue) {
68 | ud = ue->ud;
69 | kfree(ue);
70 | }
71 | return ud;
72 | }
73 |
74 | static struct task_struct *worker_context;
75 |
76 | static void event_handler(struct work_struct *work)
77 | {
78 | struct usbip_device *ud;
79 |
80 | if (worker_context == NULL) {
81 | worker_context = current;
82 | }
83 |
84 | while ((ud = get_event()) != NULL) {
85 | usbip_dbg_eh("pending event %lx\n", ud->event);
86 |
87 | /*
88 | * NOTE: shutdown must come first.
89 | * Shutdown the device.
90 | */
91 | if (ud->event & USBIP_EH_SHUTDOWN) {
92 | ud->eh_ops.shutdown(ud);
93 | unset_event(ud, USBIP_EH_SHUTDOWN);
94 | }
95 |
96 | /* Reset the device. */
97 | if (ud->event & USBIP_EH_RESET) {
98 | ud->eh_ops.reset(ud);
99 | unset_event(ud, USBIP_EH_RESET);
100 | }
101 |
102 | /* Mark the device as unusable. */
103 | if (ud->event & USBIP_EH_UNUSABLE) {
104 | ud->eh_ops.unusable(ud);
105 | unset_event(ud, USBIP_EH_UNUSABLE);
106 | }
107 |
108 | /* Stop the error handler. */
109 | if (ud->event & USBIP_EH_BYE)
110 | usbip_dbg_eh("removed %p\n", ud);
111 |
112 | wake_up(&ud->eh_waitq);
113 | }
114 | }
115 |
116 | int usbip_start_eh(struct usbip_device *ud)
117 | {
118 | init_waitqueue_head(&ud->eh_waitq);
119 | ud->event = 0;
120 | return 0;
121 | }
122 | EXPORT_SYMBOL_GPL(usbip_start_eh);
123 |
124 | void usbip_stop_eh(struct usbip_device *ud)
125 | {
126 | unsigned long pending = ud->event & ~USBIP_EH_BYE;
127 |
128 | if (!(ud->event & USBIP_EH_BYE))
129 | usbip_dbg_eh("usbip_eh stopping but not removed\n");
130 |
131 | if (pending)
132 | usbip_dbg_eh("usbip_eh waiting completion %lx\n", pending);
133 |
134 | wait_event_interruptible(ud->eh_waitq, !(ud->event & ~USBIP_EH_BYE));
135 | usbip_dbg_eh("usbip_eh has stopped\n");
136 | }
137 | EXPORT_SYMBOL_GPL(usbip_stop_eh);
138 |
139 | #define WORK_QUEUE_NAME "usbip_event"
140 |
141 | static struct workqueue_struct *usbip_queue;
142 | static DECLARE_WORK(usbip_work, event_handler);
143 |
144 | int usbip_init_eh(void)
145 | {
146 | usbip_queue = create_singlethread_workqueue(WORK_QUEUE_NAME);
147 | if (usbip_queue == NULL) {
148 | pr_err("failed to create usbip_event\n");
149 | return -ENOMEM;
150 | }
151 | return 0;
152 | }
153 |
154 | void usbip_finish_eh(void)
155 | {
156 | flush_workqueue(usbip_queue);
157 | destroy_workqueue(usbip_queue);
158 | usbip_queue = NULL;
159 | }
160 |
161 | void usbip_event_add(struct usbip_device *ud, unsigned long event)
162 | {
163 | struct usbip_event *ue;
164 | unsigned long flags;
165 |
166 | if (ud->event & USBIP_EH_BYE)
167 | return;
168 |
169 | set_event(ud, event);
170 |
171 | spin_lock_irqsave(&event_lock, flags);
172 |
173 | list_for_each_entry_reverse(ue, &event_list, node) {
174 | if (ue->ud == ud)
175 | goto out;
176 | }
177 |
178 | ue = kmalloc(sizeof(struct usbip_event), GFP_ATOMIC);
179 | if (ue == NULL)
180 | goto out;
181 |
182 | ue->ud = ud;
183 |
184 | list_add_tail(&ue->node, &event_list);
185 | queue_work(usbip_queue, &usbip_work);
186 |
187 | out:
188 | spin_unlock_irqrestore(&event_lock, flags);
189 | }
190 | EXPORT_SYMBOL_GPL(usbip_event_add);
191 |
192 | int usbip_event_happened(struct usbip_device *ud)
193 | {
194 | int happened = 0;
195 | unsigned long flags;
196 |
197 | spin_lock_irqsave(&ud->lock, flags);
198 | if (ud->event != 0)
199 | happened = 1;
200 | spin_unlock_irqrestore(&ud->lock, flags);
201 |
202 | return happened;
203 | }
204 | EXPORT_SYMBOL_GPL(usbip_event_happened);
205 |
206 | int usbip_in_eh(struct task_struct *task)
207 | {
208 | if (task == worker_context)
209 | return 1;
210 |
211 | return 0;
212 | }
213 | EXPORT_SYMBOL_GPL(usbip_in_eh);
214 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/usbip_ux.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Nobuo Iwata
3 | *
4 | * This is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation; either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef __USBIP_UX_H
19 | #define __USBIP_UX_H
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #define USBIP_UX_INT 3
28 | #define USBIP_UX_TX_INT 1
29 | #define USBIP_UX_RX_INT 2
30 |
31 | #define USBIP_UX_SET_INT(ux) ((ux)->interrupted = USBIP_UX_INT)
32 | #define USBIP_UX_SET_TX_INT(ux) ((ux)->interrupted |= USBIP_UX_TX_INT)
33 | #define USBIP_UX_SET_RX_INT(ux) ((ux)->interrupted |= USBIP_UX_RX_INT)
34 | #define USBIP_UX_IS_INT(ux) ((ux)->interrupted & USBIP_UX_INT)
35 | #define USBIP_UX_IS_TX_INT(ux) ((ux)->interrupted & USBIP_UX_TX_INT)
36 | #define USBIP_UX_IS_RX_INT(ux) ((ux)->interrupted & USBIP_UX_RX_INT)
37 |
38 | #define USBIP_UX_REQ 1
39 | #define USBIP_UX_RSP 2
40 | #define USBIP_UX_SET_TX_REQ(ux) ((ux)->tx_flags |= USBIP_UX_REQ)
41 | #define USBIP_UX_SET_TX_RSP(ux) ((ux)->tx_flags |= USBIP_UX_RSP)
42 | #define USBIP_UX_SET_RX_REQ(ux) ((ux)->rx_flags |= USBIP_UX_REQ)
43 | #define USBIP_UX_SET_RX_RSP(ux) ((ux)->rx_flags |= USBIP_UX_RSP)
44 | #define USBIP_UX_CLEAR_TX_REQ(ux) ((ux)->tx_flags &= ~USBIP_UX_REQ)
45 | #define USBIP_UX_CLEAR_TX_RSP(ux) ((ux)->tx_flags &= ~USBIP_UX_RSP)
46 | #define USBIP_UX_CLEAR_RX_REQ(ux) ((ux)->rx_flags &= ~USBIP_UX_REQ)
47 | #define USBIP_UX_CLEAR_RX_RSP(ux) ((ux)->rx_flags &= ~USBIP_UX_RSP)
48 | #define USBIP_UX_HAS_TX_REQ(ux) ((ux)->tx_flags & USBIP_UX_REQ)
49 | #define USBIP_UX_HAS_TX_RSP(ux) ((ux)->tx_flags & USBIP_UX_RSP)
50 | #define USBIP_UX_HAS_RX_REQ(ux) ((ux)->rx_flags & USBIP_UX_REQ)
51 | #define USBIP_UX_HAS_RX_RSP(ux) ((ux)->rx_flags & USBIP_UX_RSP)
52 |
53 | struct usbip_ux {
54 | struct list_head node;
55 | int sockfd;
56 | struct socket *tcp_socket;
57 | struct semaphore lock;
58 | atomic_t count;
59 | wait_queue_head_t wait_count;
60 | struct usbip_device *ud;
61 | wait_queue_head_t wait_unlink;
62 | pid_t pgid;
63 | int interrupted;
64 | int tx_tout_sec;
65 | int tx_flags;
66 | int tx_error;
67 | int tx_bytes;
68 | int tx_count;
69 | char *tx_buf;
70 | wait_queue_head_t tx_req_q;
71 | wait_queue_head_t tx_rsp_q;
72 | int rx_flags;
73 | int rx_error;
74 | int rx_bytes;
75 | int rx_count;
76 | char *rx_buf;
77 | wait_queue_head_t rx_req_q;
78 | wait_queue_head_t rx_rsp_q;
79 | };
80 |
81 | #endif /* __USBIP_UX_H */
82 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/vhci.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2003-2008 Takahiro Hirofuchi
3 | * Copyright (C) 2015 Nobuo Iwata
4 | *
5 | * This is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 2 of the License, or
8 | * (at your option) any later version.
9 | *
10 | */
11 |
12 | #ifndef __USBIP_VHCI_H
13 | #define __USBIP_VHCI_H
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | struct vhci_device {
25 | struct usb_device *udev;
26 |
27 | /*
28 | * devid specifies a remote usb device uniquely instead
29 | * of combination of busnum and devnum.
30 | */
31 | __u32 devid;
32 |
33 | /* speed of a remote device */
34 | enum usb_device_speed speed;
35 |
36 | /* vhci root-hub port to which this device is attached */
37 | __u32 rhport;
38 |
39 | struct usbip_device ud;
40 |
41 | /* lock for the below link lists */
42 | spinlock_t priv_lock;
43 |
44 | /* vhci_priv is linked to one of them. */
45 | struct list_head priv_tx;
46 | struct list_head priv_rx;
47 |
48 | /* vhci_unlink is linked to one of them */
49 | struct list_head unlink_tx;
50 | struct list_head unlink_rx;
51 |
52 | /* vhci_tx thread sleeps for this queue */
53 | wait_queue_head_t waitq_tx;
54 |
55 | /* denotes port is in-use */
56 | atomic_t using_port;
57 | };
58 |
59 | /* urb->hcpriv, use container_of() */
60 | struct vhci_priv {
61 | unsigned long seqnum;
62 | struct list_head list;
63 |
64 | struct vhci_device *vdev;
65 | struct urb *urb;
66 | };
67 |
68 | struct vhci_unlink {
69 | /* seqnum of this request */
70 | unsigned long seqnum;
71 |
72 | struct list_head list;
73 |
74 | /* seqnum of the unlink target */
75 | unsigned long unlink_seqnum;
76 | };
77 |
78 | /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
79 | #ifdef CONFIG_USBIP_VHCI_HC_PORTS
80 | #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
81 | #else
82 | #define VHCI_HC_PORTS 8
83 | #endif
84 |
85 | #ifdef CONFIG_USBIP_VHCI_MAX_HCS
86 | #define VHCI_MAX_HCS CONFIG_USBIP_VHCI_MAX_HCS
87 | #else
88 | #define VHCI_MAX_HCS 1
89 | #endif
90 |
91 | #ifdef CONFIG_USBIP_VHCI_INIT_HCS
92 | #define VHCI_INIT_HCS CONFIG_USBIP_VHCI_INIT_HCS
93 | #else
94 | #define VHCI_INIT_HCS 1
95 | #endif
96 |
97 | /* VHCI_FREE_HCS * VHCI_HC_PORTS: ports to keep free at unregister */
98 | #define VHCI_FREE_HCS 2
99 |
100 | #define MAX_STATUS_NAME 16
101 |
102 | /* for usb_bus.hcpriv */
103 | struct vhci_hcd {
104 | spinlock_t lock;
105 |
106 | u32 port_status[VHCI_HC_PORTS];
107 |
108 | unsigned resuming:1;
109 | unsigned long re_timeout;
110 |
111 | atomic_t seqnum;
112 |
113 | unsigned int using_ports;
114 |
115 | /*
116 | * NOTE:
117 | * wIndex shows the port number and begins from 1.
118 | * But, the index of this array begins from 0.
119 | */
120 | struct vhci_device vdev[VHCI_HC_PORTS];
121 | };
122 |
123 | extern int vhci_max_controllers;
124 | extern int vhci_init_controllers;
125 | extern int vhci_num_controllers;
126 | extern struct platform_device **vhci_pdevs;
127 | extern struct attribute_group vhci_attr_group;
128 |
129 | /* vhci_hcd.c */
130 | void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
131 | int vhci_get_device(__u32 pdev_nr, __u32 rhport,
132 | struct vhci_hcd **vhci, struct vhci_device **vdev);
133 | void vhci_put_device(struct vhci_device *vdev);
134 | void vhci_event_add(struct usbip_device *ud, unsigned long event);
135 |
136 | /* vhci_sysfs.c */
137 | int vhci_init_attr_group(void);
138 | void vhci_finish_attr_group(void);
139 |
140 | /* vhci_rx.c */
141 | struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
142 | int vhci_rx_loop(void *data);
143 |
144 | /* vhci_tx.c */
145 | int vhci_tx_loop(void *data);
146 |
147 | static inline __u32 port_to_rhport(__u32 port)
148 | {
149 | return port % VHCI_HC_PORTS;
150 | }
151 |
152 | static inline int port_to_pdev_nr(__u32 port)
153 | {
154 | return port / VHCI_HC_PORTS;
155 | }
156 |
157 | static inline struct vhci_hcd *hcd_to_vhci(struct usb_hcd *hcd)
158 | {
159 | return (struct vhci_hcd *) (hcd->hcd_priv);
160 | }
161 |
162 | static inline struct device *hcd_dev(struct usb_hcd *hcd)
163 | {
164 | return (hcd)->self.controller;
165 | }
166 |
167 | static inline const char *hcd_name(struct usb_hcd *hcd)
168 | {
169 | return (hcd)->self.bus_name;
170 | }
171 |
172 | static inline struct usb_hcd *vhci_to_hcd(struct vhci_hcd *vhci)
173 | {
174 | return container_of((void *) vhci, struct usb_hcd, hcd_priv);
175 | }
176 |
177 | static inline struct vhci_hcd *vdev_to_vhci(struct vhci_device *vdev)
178 | {
179 | return container_of(
180 | (void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
181 | }
182 |
183 | static inline int pdev_id2nr(int id)
184 | {
185 | return (id < 0) ? 0 : id;
186 | }
187 |
188 | static inline int pdev_nr2id(int nr)
189 | {
190 | return (nr == 0) ? -1 : nr;
191 | }
192 |
193 | #endif /* __USBIP_VHCI_H */
194 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/vudc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Karol Kosik
3 | * Copyright (C) 2015-2016 Samsung Electronics
4 | * Igor Kotrasinski
5 | * Krzysztof Opasiak
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 2 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 |
21 | #ifndef __USBIP_VUDC_H
22 | #define __USBIP_VUDC_H
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | #include "usbip_common.h"
34 |
35 | #define GADGET_NAME "usbip-vudc"
36 |
37 | struct vep {
38 | struct usb_ep ep;
39 | unsigned type:2; /* type, as USB_ENDPOINT_XFER_* */
40 | char name[8]; /* space for ep name */
41 |
42 | const struct usb_endpoint_descriptor *desc;
43 | struct usb_gadget *gadget;
44 | struct list_head req_queue; /* Request queue */
45 | unsigned halted:1;
46 | unsigned wedged:1;
47 | unsigned already_seen:1;
48 | unsigned setup_stage:1;
49 | };
50 |
51 | struct vrequest {
52 | struct usb_request req;
53 | struct vudc *udc;
54 | struct list_head req_entry; /* Request queue */
55 | };
56 |
57 | struct urbp {
58 | struct urb *urb;
59 | struct vep *ep;
60 | struct list_head urb_entry; /* urb queue */
61 | unsigned long seqnum;
62 | unsigned type:2; /* for tx, since ep type can change after */
63 | unsigned new:1;
64 | };
65 |
66 | struct v_unlink {
67 | unsigned long seqnum;
68 | __u32 status;
69 | };
70 |
71 | enum tx_type {
72 | TX_UNLINK,
73 | TX_SUBMIT,
74 | };
75 |
76 | struct tx_item {
77 | struct list_head tx_entry;
78 | enum tx_type type;
79 | union {
80 | struct urbp *s;
81 | struct v_unlink *u;
82 | };
83 | };
84 |
85 | enum tr_state {
86 | VUDC_TR_RUNNING,
87 | VUDC_TR_IDLE,
88 | VUDC_TR_STOPPED,
89 | };
90 |
91 | struct transfer_timer {
92 | struct timer_list timer;
93 | enum tr_state state;
94 | unsigned long frame_start;
95 | int frame_limit;
96 | };
97 |
98 | struct vudc {
99 | struct usb_gadget gadget;
100 | struct usb_gadget_driver *driver;
101 | struct platform_device *pdev;
102 |
103 | struct usb_device_descriptor dev_desc;
104 |
105 | struct usbip_device ud;
106 | struct transfer_timer tr_timer;
107 | struct timeval start_time;
108 |
109 | struct list_head urb_queue;
110 |
111 | spinlock_t lock_tx;
112 | struct list_head tx_queue;
113 | wait_queue_head_t tx_waitq;
114 |
115 | spinlock_t lock;
116 | struct vep *ep;
117 | int address;
118 | u16 devstatus;
119 |
120 | unsigned pullup:1;
121 | unsigned connected:1;
122 | unsigned desc_cached:1;
123 | };
124 |
125 | struct vudc_device {
126 | struct platform_device *pdev;
127 | struct list_head dev_entry;
128 | };
129 |
130 | extern const struct attribute_group vudc_attr_group;
131 |
132 | /* visible everywhere */
133 |
134 | static inline struct vep *to_vep(struct usb_ep *_ep)
135 | {
136 | return container_of(_ep, struct vep, ep);
137 | }
138 |
139 | static inline struct vrequest *to_vrequest(
140 | struct usb_request *_req)
141 | {
142 | return container_of(_req, struct vrequest, req);
143 | }
144 |
145 | static inline struct vudc *usb_gadget_to_vudc(
146 | struct usb_gadget *_gadget)
147 | {
148 | return container_of(_gadget, struct vudc, gadget);
149 | }
150 |
151 | static inline struct vudc *ep_to_vudc(struct vep *ep)
152 | {
153 | return container_of(ep->gadget, struct vudc, gadget);
154 | }
155 |
156 | /* vudc_sysfs.c */
157 |
158 | int get_gadget_descs(struct vudc *udc);
159 |
160 | /* vudc_tx.c */
161 |
162 | int v_tx_loop(void *data);
163 | void v_enqueue_ret_unlink(struct vudc *udc, __u32 seqnum, __u32 status);
164 | void v_enqueue_ret_submit(struct vudc *udc, struct urbp *urb_p);
165 |
166 | /* vudc_rx.c */
167 |
168 | int v_rx_loop(void *data);
169 |
170 | /* vudc_transfer.c */
171 |
172 | void v_init_timer(struct vudc *udc);
173 | void v_start_timer(struct vudc *udc);
174 | void v_kick_timer(struct vudc *udc, unsigned long time);
175 | void v_stop_timer(struct vudc *udc);
176 |
177 | /* vudc_dev.c */
178 |
179 | struct urbp *alloc_urbp(void);
180 | void free_urbp_and_urb(struct urbp *urb_p);
181 |
182 | struct vep *vudc_find_endpoint(struct vudc *udc, u8 address);
183 |
184 | struct vudc_device *alloc_vudc_device(int devid);
185 | void put_vudc_device(struct vudc_device *udc_dev);
186 |
187 | int vudc_probe(struct platform_device *pdev);
188 | int vudc_remove(struct platform_device *pdev);
189 |
190 | #endif /* __USBIP_VUDC_H */
191 |
--------------------------------------------------------------------------------
/drivers/usb/usbip/vudc_main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Karol Kosik
3 | * Copyright (C) 2015-2016 Samsung Electronics
4 | * Igor Kotrasinski
5 | * Krzysztof Opasiak
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 2 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 |
21 | #include
22 | #include
23 | #include
24 |
25 | #include "vudc.h"
26 |
27 | static unsigned int vudc_number = 1;
28 |
29 | module_param_named(num, vudc_number, uint, S_IRUGO);
30 | MODULE_PARM_DESC(num, "number of emulated controllers");
31 |
32 | static struct platform_driver vudc_driver = {
33 | .probe = vudc_probe,
34 | .remove = vudc_remove,
35 | .driver = {
36 | .name = GADGET_NAME,
37 | },
38 | };
39 |
40 | static struct list_head vudc_devices = LIST_HEAD_INIT(vudc_devices);
41 |
42 | static int __init init(void)
43 | {
44 | int retval = -ENOMEM;
45 | int i;
46 | struct vudc_device *udc_dev = NULL, *udc_dev2 = NULL;
47 |
48 | if (usb_disabled())
49 | return -ENODEV;
50 |
51 | if (vudc_number < 1) {
52 | pr_err("Number of emulated UDC must be no less than 1");
53 | return -EINVAL;
54 | }
55 |
56 | retval = platform_driver_register(&vudc_driver);
57 | if (retval < 0)
58 | goto out;
59 |
60 | for (i = 0; i < vudc_number; i++) {
61 | udc_dev = alloc_vudc_device(i);
62 | if (!udc_dev) {
63 | retval = -ENOMEM;
64 | goto cleanup;
65 | }
66 |
67 | retval = platform_device_add(udc_dev->pdev);
68 | if (retval < 0) {
69 | put_vudc_device(udc_dev);
70 | goto cleanup;
71 | }
72 |
73 | list_add_tail(&udc_dev->dev_entry, &vudc_devices);
74 | if (!platform_get_drvdata(udc_dev->pdev)) {
75 | /*
76 | * The udc was added successfully but its probe
77 | * function failed for some reason.
78 | */
79 | retval = -EINVAL;
80 | goto cleanup;
81 | }
82 | }
83 | goto out;
84 |
85 | cleanup:
86 | list_for_each_entry_safe(udc_dev, udc_dev2, &vudc_devices, dev_entry) {
87 | list_del(&udc_dev->dev_entry);
88 | platform_device_del(udc_dev->pdev);
89 | put_vudc_device(udc_dev);
90 | }
91 |
92 | platform_driver_unregister(&vudc_driver);
93 | out:
94 | return retval;
95 | }
96 | module_init(init);
97 |
98 | static void __exit cleanup(void)
99 | {
100 | struct vudc_device *udc_dev = NULL, *udc_dev2 = NULL;
101 |
102 | list_for_each_entry_safe(udc_dev, udc_dev2, &vudc_devices, dev_entry) {
103 | list_del(&udc_dev->dev_entry);
104 | platform_device_unregister(udc_dev->pdev);
105 | put_vudc_device(udc_dev);
106 | }
107 | platform_driver_unregister(&vudc_driver);
108 | }
109 | module_exit(cleanup);
110 |
111 | MODULE_DESCRIPTION("USB over IP Device Controller");
112 | MODULE_AUTHOR("Krzysztof Opasiak, Karol Kosik, Igor Kotrasinski");
113 | MODULE_LICENSE("GPL");
114 |
--------------------------------------------------------------------------------
/include/uapi/linux/usbip.h:
--------------------------------------------------------------------------------
1 | /*
2 | * usbip.h
3 | *
4 | * USBIP uapi defines and function prototypes etc.
5 | */
6 |
7 | #ifndef _UAPI_LINUX_USBIP_H
8 | #define _UAPI_LINUX_USBIP_H
9 |
10 | /* usbip device status - exported in usbip device sysfs status */
11 | enum usbip_device_status {
12 | /* sdev is available. */
13 | SDEV_ST_AVAILABLE = 0x01,
14 | /* sdev is now used. */
15 | SDEV_ST_USED,
16 | /* sdev is unusable because of a fatal error. */
17 | SDEV_ST_ERROR,
18 |
19 | /* vdev does not connect a remote device. */
20 | VDEV_ST_NULL,
21 | /* vdev is used, but the USB address is not assigned yet */
22 | VDEV_ST_NOTASSIGNED,
23 | VDEV_ST_USED,
24 | VDEV_ST_ERROR
25 | };
26 | #endif /* _UAPI_LINUX_USBIP_H */
27 |
--------------------------------------------------------------------------------
/include/uapi/linux/usbip_api.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | /*
19 | * USB/IP API to create command(s) and daemons with arbitrary network protocol.
20 | */
21 |
22 | #ifndef __UAPI_LINUX_USBIP_API_H
23 | #define __UAPI_LINUX_USBIP_API_H
24 |
25 | #ifdef __cplusplus
26 | extern "C"
27 | {
28 | #endif
29 |
30 | /*
31 | * Using int rather than size_t and ssize_t for cross OS portability.
32 | */
33 | struct usbip_sock {
34 | int fd;
35 | void *arg;
36 | void *ux;
37 | int (*send)(void *arg, void *buf, int len);
38 | int (*recv)(void *arg, void *buf, int len, int wait_all);
39 | void (*shutdown)(void *arg);
40 | };
41 |
42 | void usbip_sock_init(struct usbip_sock *sock, int fd, void *arg,
43 | int (*send)(void *arg, void *buf, int len),
44 | int (*recv)(void *arg, void *buf, int len, int wait_all),
45 | void (*shutdown)(void *arg));
46 |
47 | struct usbip_connection_operations {
48 | struct usbip_sock *(*open)(const char *host, const char *port,
49 | void *opt);
50 | void (*close)(struct usbip_sock *sock);
51 | void *opt;
52 | };
53 |
54 | void usbip_conn_init(
55 | struct usbip_sock *(*open)(const char *host, const char *port,
56 | void *opt),
57 | void (*close)(struct usbip_sock *sock),
58 | void *opt);
59 |
60 | void usbip_break_all_connections(void);
61 | void usbip_break_connection(struct usbip_sock *sock);
62 |
63 | void usbip_set_use_debug(int val);
64 | void usbip_set_use_stderr(int val);
65 | void usbip_set_use_syslog(int val);
66 |
67 | #ifdef USBIP_WITH_LIBUSB
68 | void usbip_set_debug_flags(unsigned long flags);
69 | #endif
70 |
71 | int usbip_attach_device(const char *host, const char *port, const char *busid);
72 | int usbip_detach_port(const char *port);
73 | int usbip_bind_device(const char *busid);
74 | int usbip_unbind_device(const char *busid);
75 | int usbip_list_imported_devices(void);
76 | int usbip_list_importable_devices(const char *host, const char *port);
77 | int usbip_list_local_devices(int parsable);
78 | int usbip_connect_device(const char *host, const char *port,
79 | const char *busid);
80 | int usbip_disconnect_device(const char *host, const char *port,
81 | const char *busid);
82 |
83 | int usbipd_recv_pdu(struct usbip_sock *sock,
84 | const char *host, const char *port);
85 | int usbipd_driver_open(void);
86 | void usbipd_driver_close(void);
87 |
88 | int usbip_hdriver_set(int type);
89 |
90 | #define USBIP_HDRIVER_TYPE_HOST 0
91 | #define USBIP_HDRIVER_TYPE_DEVICE 1
92 |
93 | #ifdef __cplusplus
94 | }
95 | #endif
96 |
97 | #endif /* !__UAPI_LINUX_USBIP_API_H */
98 |
--------------------------------------------------------------------------------
/include/uapi/linux/usbip_ux.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation; either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef __UAPI_LINUX_USBIP_UX_H
19 | #define __UAPI_LINUX_USBIP_UX_H
20 |
21 | #define USBIP_UX_MINOR 0
22 | #define USBIP_UX_CLASS_NAME "usbip"
23 | #define USBIP_UX_DEV_NAME "usbip-ux"
24 | #define USBIP_UX_KADDR_LEN 16
25 |
26 | struct usbip_ux_kaddr {
27 | char ux[USBIP_UX_KADDR_LEN+1];
28 | char sock[USBIP_UX_KADDR_LEN+1];
29 | };
30 |
31 | #define USBIP_UX_MAGIC_IOC 'm'
32 |
33 | #define USBIP_UX_IOCSETSOCKFD \
34 | _IOW(USBIP_UX_MAGIC_IOC, 1, int)
35 | #define USBIP_UX_IOCINTR \
36 | _IO(USBIP_UX_MAGIC_IOC, 2)
37 | #define USBIP_UX_IOCINTRPGRP \
38 | _IO(USBIP_UX_MAGIC_IOC, 3)
39 | #define USBIP_UX_IOCGETKADDR \
40 | _IOR(USBIP_UX_MAGIC_IOC, 4, struct usbip_ux_kaddr)
41 |
42 | #endif /* __UAPI_LINUX_USBIP_UX_H */
43 |
--------------------------------------------------------------------------------
/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | CMD=`basename $0`
4 | WHICH=$1
5 |
6 | if [ "$WHICH" != "all" -a \
7 | "$WHICH" != "driver" -a \
8 | "$WHICH" != "libusb" ]; then
9 | echo "usage: $CMD [all|driver|libusb]"
10 | exit 0
11 | fi
12 |
13 | function mktool() {
14 | if [ ! -e configure ]; then
15 | if [ ! -x ./autogen.sh ]; then
16 | chmod a+x ./autogen.sh
17 | chmod a+x ./cleanup.sh
18 | fi
19 | ./autogen.sh
20 | if [ $? -ne 0 ]; then
21 | exit 1
22 | fi
23 | ./configure $1
24 | if [ $? -ne 0 ]; then
25 | exit 1
26 | fi
27 | fi
28 | make
29 | sudo make install
30 | }
31 |
32 | DIR_UTLS=$( cd "$( dirname "$0" )" && pwd )
33 | DIR_TEST=`pwd`
34 | DIR_DRV=$DIR_TEST/drivers/usb/usbip
35 | DIR_TOOL=$DIR_TEST/tools/usb/usbip
36 | DIR_EX=$DIR_TEST/tools/usb/usbip/api-example
37 | DIR_LIBUSB_TOOL=$DIR_TEST/tools/usb/usbip/libusb
38 | KERNEL=`uname -r`
39 | DIR_KERN_INC=/lib/modules/$KERNEL/build/include
40 | DIR_KERN_MOD=/lib/modules/$KERNEL/kernel/drivers/usb/usbip
41 | DIR_UAPI_INC=/usr/include/linux
42 |
43 | sudo cp $DIR_TEST/include/uapi/linux/usbip_ux.h $DIR_KERN_INC/uapi/linux/
44 |
45 | sudo cp $DIR_TEST/include/uapi/linux/usbip_ux.h $DIR_UAPI_INC/
46 |
47 | sudo cp $DIR_TEST/include/uapi/linux/usbip_api.h $DIR_UAPI_INC/
48 |
49 | if [ "$WHICH" = "all" -o "$WHICH" = "driver" ]; then
50 | sudo mkdir -p $DIR_KERN_MOD
51 |
52 | pushd .
53 | cd $DIR_DRV
54 | make
55 | sudo cp *.ko $DIR_KERN_MOD/
56 | sudo depmod -a
57 | popd
58 |
59 | pushd .
60 | cd $DIR_TOOL
61 | mktool
62 | popd
63 | fi
64 |
65 | if [ "$WHICH" = "all" -o "$WHICH" = "libusb" ]; then
66 | if [ -e $DIR_LIBUSB_TOOL ]; then
67 | pushd .
68 | cd $DIR_LIBUSB_TOOL
69 | mktool "--with-dummy-driver"
70 | popd
71 | fi
72 | fi
73 |
74 | # if [ -e $DIR_EX ]; then
75 | # pushd .
76 | # cd $DIR_EX
77 | # mktool
78 | # popd
79 | # fi
80 |
--------------------------------------------------------------------------------
/tools/usb/usbip/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | Makefile.in
3 | aclocal.m4
4 | autom4te.cache/
5 | config.guess
6 | config.h
7 | config.h.in
8 | config.log
9 | config.status
10 | config.sub
11 | configure
12 | depcomp
13 | install-sh
14 | libsrc/Makefile
15 | libsrc/Makefile.in
16 | libtool
17 | ltmain.sh
18 | missing
19 | src/Makefile
20 | src/Makefile.in
21 | stamp-h1
22 | libsrc/libusbip.la
23 | libsrc/libusbip_la-names.lo
24 | libsrc/libusbip_la-usbip_common.lo
25 | libsrc/libusbip_la-usbip_host_driver.lo
26 | libsrc/libusbip_la-vhci_driver.lo
27 | src/usbip
28 | src/usbipd
29 |
--------------------------------------------------------------------------------
/tools/usb/usbip/AUTHORS:
--------------------------------------------------------------------------------
1 | Takahiro Hirofuchi
2 | Robert Leibl
3 | matt mooney
4 |
--------------------------------------------------------------------------------
/tools/usb/usbip/Makefile.am:
--------------------------------------------------------------------------------
1 | SUBDIRS := libsrc src
2 | includedir = @includedir@/usbip
3 | include_HEADERS := $(addprefix libsrc/, \
4 | usbip_common.h vhci_driver.h usbip_host_driver.h)
5 |
6 | dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbipa.8 \
7 | usbip_sock_init.3 usbip_conn_init.3 \
8 | usbip_break_all_connections.3 usbip_break_connection.3 \
9 | usbip_set_use_debug.3 usbip_set_use_stderr.3 \
10 | usbip_set_use_syslog.3 usbip_set_debug_flags.3 \
11 | usbip_attach_device.3 usbip_detach_port.3 \
12 | usbip_bind_device.3 usbip_unbind_device.3 \
13 | usbip_list_imported_devices.3 \
14 | usbip_list_importable_devices.3 \
15 | usbip_list_local_devices.3 \
16 | usbip_connect_device.3 usbip_disconnect_device.3 \
17 | usbipd_recv_pdu.3 \
18 | usbipd_driver_open.3 usbipd_driver_close.3 \
19 | usbip_hdriver_set.3)
20 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/Makefile.am:
--------------------------------------------------------------------------------
1 | SUBDIRS := src
2 |
3 | dist_man_MANS :=
4 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/README:
--------------------------------------------------------------------------------
1 | A simple example for USB/IP network protocol programming interface using IPv4
2 | socket.
3 |
4 | 1) Another samples
5 |
6 | USB over WebSocket using libwebsockets and Poco C++ are in github.
7 |
8 | https://github.com/novimusica/
9 |
10 | 2) Build with libusb
11 |
12 | ./configure --with-libusb
13 |
14 | [EOF]
15 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -x
2 |
3 | #aclocal
4 | #autoheader
5 | #libtoolize --copy --force
6 | #automake-1.9 -acf
7 | #autoconf
8 |
9 | autoreconf -i -f -v
10 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/cleanup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | if [ -r Makefile ]; then
4 | make distclean
5 | fi
6 |
7 | FILES="aclocal.m4 autom4te.cache compile config.guess config.h.in config.log \
8 | config.status config.sub configure cscope.out depcomp install-sh \
9 | src/Makefile src/Makefile.in libtool ltmain.sh Makefile \
10 | Makefile.in missing"
11 |
12 | rm -vRf $FILES
13 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/configure.ac:
--------------------------------------------------------------------------------
1 | dnl Process this file with autoconf to produce a configure script.
2 |
3 | AC_PREREQ(2.59)
4 | AC_INIT([usbws-utils], [0.1.0], [linux-usb@vger.kernel.org])
5 |
6 | AC_CONFIG_HEADERS([config.h])
7 |
8 | AM_INIT_AUTOMAKE([foreign])
9 | LT_INIT
10 |
11 | # Silent build for automake >= 1.11
12 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
13 |
14 | AC_SUBST([EXTRA_CFLAGS], ["-Wall -Werror -Wextra -std=gnu99"])
15 |
16 | # Checks for programs.
17 | AC_PROG_CC
18 | AC_PROG_INSTALL
19 | AC_PROG_MAKE_SET
20 |
21 | # Checks for header files.
22 | AC_HEADER_DIRENT
23 | AC_HEADER_STDC
24 | AC_CHECK_HEADERS([fcntl.h unistd.h])
25 |
26 | # Checks for typedefs, structures, and compiler characteristics.
27 | AC_TYPE_SIZE_T
28 | AC_TYPE_SSIZE_T
29 |
30 | # Checks for library functions.
31 | AC_CHECK_FUNCS([socket])
32 |
33 | # Using libusb
34 | AC_MSG_CHECKING([whether to use libusb])
35 | AC_ARG_WITH([libusb],
36 | [ --with-libusb with libusb],
37 | [with_libusb=yes],
38 | [with_libusb=no])
39 | AC_MSG_RESULT([$with_libusb])
40 | AM_CONDITIONAL([WITH_LIBUSB], [test x$with_libusb = xyes])
41 |
42 | AC_CONFIG_FILES([Makefile src/Makefile])
43 | AC_OUTPUT
44 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_attach.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_attach \- attaches remote USB device.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_attach
6 | <\fIremote-addr\fR> <\fIbus-id\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Attaches a remote device which is made importable on
10 | remote and listed by \fBlist remote\fR command.
11 |
12 | .SH OPTIONS
13 | .HP
14 | \fIremote-addr\fR
15 | .IP
16 | IPv4 address of a remote machine.
17 | .PP
18 |
19 | .HP
20 | \fIbus-id\fR
21 | .IP
22 | Bus ID of a remote device to be importable.
23 | .PP
24 |
25 | .SH "SEE ALSO"
26 | \fBusbip_ex_cmd_list_local\fP\fB(8)\fB\fP
27 | \fBusbip_ex_cmd_bind\fP\fB(8)\fB\fP
28 | \fBusbip_ex_cmd_list_remote\fP\fB(8)\fB\fP
29 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_bind.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_bind \- binds local USB device.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_bind
6 | <\fIbus-id\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Makes a local device importable from remote.
10 |
11 | .HP
12 | \fIbus-id\fR
13 | .IP
14 | Bus ID of remote device to be importable.
15 | .PP
16 |
17 | .SH "SEE ALSO"
18 | \fBusbip_ex_cmd_list_local\fP\fB(8)\fB\fP
19 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_connect.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_connect \- connect local USB device to remote.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_connect
6 | <\fIremote-addr\fR> <\fIbus-id\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Connects a local device to remote machine.
10 |
11 | .SH OPTIONS
12 | .HP
13 | \fIremote-addr\fR
14 | .IP
15 | IPv4 address of a remote machine.
16 | .PP
17 |
18 | .HP
19 | \fIbus-id\fR
20 | .IP
21 | Bus ID of a local device to be connected.
22 | .PP
23 |
24 | .SH "SEE ALSO"
25 | \fBusbip_ex_cmd_list_local\fP\fB(8)\fB\fP
26 | \fBusbip_ex_cmd_disconnect\fP\fB(8)\fB\fP
27 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_detach.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_detach \- detaches USB device.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_detach
6 | <\fIport-number\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Detaches a device which is shown by \fBport\fR command.
10 |
11 | .SH OPTIONS
12 | .HP
13 | \fIport-number\fR
14 | .IP
15 | Port number of attached device.
16 | .PP
17 |
18 | .SH "SEE ALSO"
19 | \fBusbip_ex_cmd_attach\fP\fB(8)\fB\fP
20 | \fBusbip_ex_cmd_port\fP\fB(8)\fB\fP
21 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_disconnect.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_connect \- disconnect local USB device from remote.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_connect
6 | <\fIremote-addr\fR> <\fIbus-id\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Connects a local device from remote machine.
10 |
11 | .SH OPTIONS
12 | .HP
13 | \fIremote-addr\fR
14 | .IP
15 | IPv4 address of a remote machine.
16 | .PP
17 |
18 | .HP
19 | \fIbus-id\fR
20 | .IP
21 | Bus ID of a local device to be disconnected.
22 | .PP
23 |
24 | .SH "SEE ALSO"
25 | \fBusbip_ex_cmd_connect\fP\fB(8)\fB\fP
26 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_list_local.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_list_local \- lists local USB devices.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_list_local
6 |
7 | .SH DESCRIPTION
8 | A USB/IP API example. Lists local USB devices.
9 |
10 | .SH "SEE ALSO"
11 | \fBusbip_ex_cmd_bind\fP\fB(8)\fB\fP
12 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_list_remote.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_list_remote \- lists remote USB devices.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_list_remote
6 | <\fIremote-addr\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Lists remote devices which are made importable on
10 | remote.
11 |
12 | .SH OPTIONS
13 | .HP
14 | \fIremote-addr\fR
15 | .IP
16 | IPv4 address of a remote machine.
17 | .PP
18 |
19 | .SH "SEE ALSO"
20 | \fBusbip_ex_cmd_list_local\fP\fB(8)\fB\fP
21 | \fBusbip_ex_cmd_bind\fP\fB(8)\fB\fP
22 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_port.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_port \- lists attahced USB device.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_detach
6 | <\fIport-number\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Lists devices which are imported by \fBattach\fR command.
10 |
11 | .SH "SEE ALSO"
12 | \fBusbip_ex_cmd_attach\fP\fB(8)\fB\fP
13 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_cmd_unbind.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 2016" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_cmd_unbind \- unbinds local USB device.
4 | .SH SYNOPSIS
5 | .B usbip_ex_cmd_unbind
6 | <\fIbus-id\fR>
7 |
8 | .SH DESCRIPTION
9 | A USB/IP API example. Makes a local device not importable from remote.
10 |
11 | .HP
12 | \fIbus-id\fR
13 | .IP
14 | Bus ID of remote device to be importable.
15 | .PP
16 |
17 | .SH "SEE ALSO"
18 | \fBusbip_ex_cmd_list_local\fP\fB(8)\fB\fP
19 | \fBusbip_ex_cmd_bind\fP\fB(8)\fB\fP
20 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_daemon_app.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 20i16" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_daemon_app \- USB/IP daemon for application side machine
4 | .SH SYNOPSIS
5 | .B usbip_ex_daemon_app
6 |
7 | .SH DESCRIPTION
8 | .B usbip_ex_daemon_app
9 | runs in a application side machine and serves devices connected from remote machines by \fBconnect\fR command.
10 |
11 | .SH "SEE ALSO"
12 | \fBusbip_ex_cmd_list_local\fP\fB(8)\fB\fP
13 | \fBusbip_ex_cmd_connect\fP\fB(8)\fB\fP
14 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/doc/usbip_ex_daemon_dev.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "May 20i16" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip_ex_daemon_dev \- USB/IP daemon for device side machine
4 | .SH SYNOPSIS
5 | .B usbip_ex_daemon_dev
6 |
7 | .SH DESCRIPTION
8 | .B usbip_ex_daemon_dev
9 | runs in a device side machine and makes local devices accessible from a remote machine by \fBattach\fR command. The local devices should be accessible by \fBbind\fR command.
10 |
11 | .SH "SEE ALSO"
12 | \fBusbip_ex_cmd_list_local\fP\fB(8)\fB\fP
13 | \fBusbip_ex_cmd_bind\fP\fB(8)\fB\fP
14 | \fBusbip_ex_cmd_list_remote\fP\fB(8)\fB\fP
15 | \fBusbip_ex_cmd_attach\fP\fB(8)\fB\fP
16 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/Makefile.am:
--------------------------------------------------------------------------------
1 | AM_CFLAGS =
2 | AM_LDFLAGS = -L@libdir@
3 |
4 | if !WITH_LIBUSB
5 | LDFLAGS_DAEMON_DEV = -lusbip -lusbipd
6 | LDFLAGS_DAEMON_APP = -lusbip -lusbipa
7 | LDFLAGS_CMD = -lusbip -lusbipc
8 |
9 | sbin_PROGRAMS = usbip_ex_daemon_dev usbip_ex_daemon_app \
10 | usbip_ex_cmd_connect usbip_ex_cmd_disconnect \
11 | usbip_ex_cmd_bind usbip_ex_cmd_unbind \
12 | usbip_ex_cmd_list_local \
13 | usbip_ex_cmd_attach usbip_ex_cmd_detach \
14 | usbip_ex_cmd_list_remote usbip_ex_cmd_port
15 | else
16 | LDFLAGS_DAEMON_DEV = -lusbip_libusb -lusbip_stub -lusbipd_libusb
17 | LDFLAGS_DAEMON_APP =
18 | LDFLAGS_CMD = -lusbip_libusb -lusbip_stub -lusbipc_libusb
19 |
20 | sbin_PROGRAMS = usbip_ex_daemon_dev \
21 | usbip_ex_cmd_connect usbip_ex_cmd_disconnect \
22 | usbip_ex_cmd_bind usbip_ex_cmd_unbind \
23 | usbip_ex_cmd_list_local
24 | endif
25 |
26 | usbip_ex_daemon_dev_SOURCES = usbip_ex_daemon.c \
27 | usbip_ex_net_common.c usbip_ex_net_server.c
28 | usbip_ex_daemon_dev_LDFLAGS = $(LDFLAGS_DAEMON_DEV)
29 | usbip_ex_daemon_dev_CFLAGS = $(AM_CFLAGS)
30 |
31 | if !WITH_LIBUSB
32 | usbip_ex_daemon_app_SOURCES = usbip_ex_daemon.c \
33 | usbip_ex_net_common.c usbip_ex_net_server.c
34 | usbip_ex_daemon_app_LDFLAGS = $(LDFLAGS_DAEMON_APP)
35 | usbip_ex_daemon_app_CFLAGS = $(AM_CFLAGS)
36 | endif
37 |
38 | usbip_ex_cmd_connect_SOURCES = usbip_ex_cmd_connect.c \
39 | usbip_ex_net_common.c usbip_ex_net_client.c
40 | usbip_ex_cmd_connect_LDFLAGS = $(LDFLAGS_CMD)
41 | usbip_ex_cmd_connect_CFLAGS = $(AM_CFLAGS)
42 |
43 | usbip_ex_cmd_disconnect_SOURCES = usbip_ex_cmd_disconnect.c \
44 | usbip_ex_net_common.c usbip_ex_net_client.c
45 | usbip_ex_cmd_disconnect_LDFLAGS = $(LDFLAGS_CMD)
46 | usbip_ex_cmd_disconnect_CFLAGS = $(AM_CFLAGS)
47 |
48 | usbip_ex_cmd_bind_SOURCES = usbip_ex_cmd_bind.c
49 | usbip_ex_cmd_bind_LDFLAGS = $(LDFLAGS_CMD)
50 | usbip_ex_cmd_bind_CFLAGS = $(AM_CFLAGS)
51 |
52 | usbip_ex_cmd_unbind_SOURCES = usbip_ex_cmd_unbind.c
53 | usbip_ex_cmd_unbind_LDFLAGS = $(LDFLAGS_CMD)
54 | usbip_ex_cmd_unbind_CFLAGS = $(AM_CFLAGS)
55 |
56 | usbip_ex_cmd_list_local_SOURCES = usbip_ex_cmd_list_local.c \
57 | usbip_ex_net_common.c usbip_ex_net_client.c
58 | usbip_ex_cmd_list_local_LDFLAGS = $(LDFLAGS_CMD)
59 | usbip_ex_cmd_list_local_CFLAGS = $(AM_CFLAGS)
60 |
61 | if !WITH_LIBUSB
62 | usbip_ex_cmd_attach_SOURCES = usbip_ex_cmd_attach.c \
63 | usbip_ex_net_common.c usbip_ex_net_client.c
64 | usbip_ex_cmd_attach_LDFLAGS = $(LDFLAGS_CMD)
65 | usbip_ex_cmd_attach_CFLAGS = $(AM_CFLAGS)
66 |
67 | usbip_ex_cmd_detach_SOURCES = usbip_ex_cmd_detach.c
68 | usbip_ex_cmd_detach_LDFLAGS = $(LDFLAGS_CMD)
69 | usbip_ex_cmd_detach_CFLAGS = $(AM_CFLAGS)
70 |
71 | usbip_ex_cmd_list_remote_SOURCES = usbip_ex_cmd_list_remote.c \
72 | usbip_ex_net_common.c usbip_ex_net_client.c
73 | usbip_ex_cmd_list_remote_LDFLAGS = $(LDFLAGS_CMD)
74 | usbip_ex_cmd_list_remote_CFLAGS = $(AM_CFLAGS)
75 |
76 | usbip_ex_cmd_port_SOURCES = usbip_ex_cmd_port.c
77 | usbip_ex_cmd_port_LDFLAGS = $(LDFLAGS_CMD)
78 | usbip_ex_cmd_port_CFLAGS = $(AM_CFLAGS)
79 | endif
80 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef __USBIP_API_EXAMPLE_H
19 | #define __USBIP_API_EXAMPLE_H
20 |
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 |
27 | #define EXAMPLE_PORT 3240
28 | #define EXAMPLE_PORT_STR "3240"
29 |
30 | struct usbip_ex_net_info {
31 | char host[NI_MAXHOST];
32 | char port[NI_MAXSERV];
33 | };
34 |
35 | struct usbip_ex_net_arg {
36 | int connfd;
37 | };
38 |
39 | int usbip_ex_listen(void);
40 | int usbip_ex_accept(int listenfd, struct usbip_ex_net_info *info);
41 |
42 | struct usbip_sock *usbip_ex_connect(const char *host, const char *port,
43 | void *opt);
44 | void usbip_ex_close(struct usbip_sock *sock);
45 |
46 | int usbip_ex_send(void *arg, void *buf, int len);
47 | int usbip_ex_recv(void *arg, void *buf, int len, int wait_all);
48 | void usbip_ex_shutdown(void *arg);
49 |
50 | #endif /* !__USBIP_API_EXAMPLE_H */
51 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_attach.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | static void usage(const char *cmd)
23 | {
24 | printf("%s \n", cmd);
25 | }
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | if (argc < 3) {
30 | usage(argv[0]);
31 | goto err_out;
32 | }
33 |
34 | usbip_conn_init(usbip_ex_connect, usbip_ex_close, NULL);
35 |
36 | printf("transferring\n");
37 | if (usbip_attach_device(argv[1], EXAMPLE_PORT_STR, argv[2])) {
38 | perror("Failed to attach device");
39 | goto err_out;
40 | }
41 | printf("end of transfer\n");
42 |
43 | return EXIT_SUCCESS;
44 | err_out:
45 | return EXIT_FAILURE;
46 | }
47 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_bind.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | static void usage(const char *cmd)
23 | {
24 | printf("%s \n", cmd);
25 | }
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | if (argc < 2) {
30 | usage(argv[0]);
31 | goto err_out;
32 | }
33 |
34 | if (usbip_bind_device(argv[1])) {
35 | perror("Failed to bind device");
36 | goto err_out;
37 | }
38 |
39 | return EXIT_SUCCESS;
40 | err_out:
41 | return EXIT_FAILURE;
42 | }
43 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_connect.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | static void usage(const char *cmd)
23 | {
24 | printf("%s \n", cmd);
25 | }
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | if (argc < 3) {
30 | usage(argv[0]);
31 | goto err_out;
32 | }
33 |
34 | usbip_conn_init(usbip_ex_connect, usbip_ex_close, NULL);
35 |
36 | printf("transferring\n");
37 | if (usbip_connect_device(argv[1], EXAMPLE_PORT_STR, argv[2])) {
38 | perror("Failed to connect device");
39 | goto err_out;
40 | }
41 | printf("end of transfer\n");
42 |
43 | return EXIT_SUCCESS;
44 | err_out:
45 | return EXIT_FAILURE;
46 | }
47 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_detach.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | static void usage(const char *cmd)
23 | {
24 | printf("%s \n", cmd);
25 | }
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | if (argc < 2) {
30 | usage(argv[0]);
31 | goto err_out;
32 | }
33 |
34 | if (usbip_detach_port(argv[1])) {
35 | perror("Failed to detach device");
36 | goto err_out;
37 | }
38 |
39 | return EXIT_SUCCESS;
40 | err_out:
41 | return EXIT_FAILURE;
42 | }
43 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_disconnect.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | static void usage(const char *cmd)
23 | {
24 | printf("%s \n", cmd);
25 | }
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | if (argc < 3) {
30 | usage(argv[0]);
31 | goto err_out;
32 | }
33 |
34 | usbip_conn_init(usbip_ex_connect, usbip_ex_close, NULL);
35 |
36 | if (usbip_disconnect_device(argv[1], EXAMPLE_PORT_STR, argv[2])) {
37 | perror("Failed to disconnect device");
38 | goto err_out;
39 | }
40 |
41 | return EXIT_SUCCESS;
42 | err_out:
43 | return EXIT_FAILURE;
44 | }
45 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_list_local.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 |
21 | int main(int argc, char *argv[])
22 | {
23 | if (usbip_list_local_devices(0)) {
24 | perror("Failed to list devices");
25 | goto err_out;
26 | }
27 |
28 | return EXIT_SUCCESS;
29 | err_out:
30 | return EXIT_FAILURE;
31 | }
32 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_list_remote.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | static void usage(const char *cmd)
23 | {
24 | printf("%s \n", cmd);
25 | }
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | if (argc < 2) {
30 | usage(argv[0]);
31 | goto err_out;
32 | }
33 |
34 | usbip_conn_init(usbip_ex_connect, usbip_ex_close, NULL);
35 |
36 | if (usbip_list_importable_devices(argv[1], EXAMPLE_PORT_STR)) {
37 | perror("Failed to list importable devices");
38 | goto err_out;
39 | }
40 |
41 | return EXIT_SUCCESS;
42 | err_out:
43 | return EXIT_FAILURE;
44 | }
45 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_port.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 |
21 | int main(int argc, char *argv[])
22 | {
23 | if (usbip_list_imported_devices()) {
24 | perror("Failed to list imported devices");
25 | goto err_out;
26 | }
27 |
28 | return EXIT_SUCCESS;
29 | err_out:
30 | return EXIT_FAILURE;
31 | }
32 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_cmd_unbind.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | static void usage(const char *cmd)
23 | {
24 | printf("%s \n", cmd);
25 | }
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | if (argc < 2) {
30 | usage(argv[0]);
31 | goto err_out;
32 | }
33 |
34 | if (usbip_unbind_device(argv[1])) {
35 | perror("Failed to unbind device");
36 | goto err_out;
37 | }
38 |
39 | return EXIT_SUCCESS;
40 | err_out:
41 | return EXIT_FAILURE;
42 | }
43 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_daemon.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | static void signal_handler(int i)
25 | {
26 | usbip_break_all_connections();
27 | }
28 |
29 | static void set_signal(void)
30 | {
31 | struct sigaction act;
32 |
33 | memset(&act, 0, sizeof(act));
34 | act.sa_handler = signal_handler;
35 | sigemptyset(&act.sa_mask);
36 | sigaction(SIGTERM, &act, NULL);
37 | act.sa_handler = SIG_IGN;
38 | sigaction(SIGCLD, &act, NULL);
39 | }
40 |
41 | int main(int argc, char *argv[])
42 | {
43 | pid_t childpid;
44 | int listenfd, connfd;
45 | struct usbip_sock sock;
46 | struct usbip_ex_net_info info;
47 | struct usbip_ex_net_arg arg;
48 |
49 | set_signal();
50 |
51 | if (usbipd_driver_open()) {
52 | perror("Failed to open driver");
53 | goto err_out;
54 | }
55 |
56 | listenfd = usbip_ex_listen();
57 | if (listenfd < 0)
58 | goto err_driver_close;
59 |
60 | while (1) {
61 | connfd = usbip_ex_accept(listenfd, &info);
62 | if (connfd < 0)
63 | goto err_sock_close;
64 |
65 | childpid = fork();
66 | if (childpid < 0) {
67 | perror("Failed to fork");
68 | goto err_conn_close;
69 | } else if (childpid == 0) {
70 | close(listenfd);
71 | arg.connfd = connfd;
72 | usbip_sock_init(&sock, connfd, &arg,
73 | usbip_ex_send, usbip_ex_recv,
74 | usbip_ex_shutdown);
75 | printf("processing %s:%s\n", info.host, info.port);
76 | usbipd_recv_pdu(&sock, info.host, info.port);
77 | printf("end of process %s:%s\n", info.host, info.port);
78 | return EXIT_SUCCESS;
79 | }
80 | close(connfd);
81 | }
82 |
83 | close(listenfd);
84 | usbipd_driver_close();
85 | EXIT_SUCCESS;
86 | err_conn_close:
87 | close(connfd);
88 | err_sock_close:
89 | close(listenfd);
90 | err_driver_close:
91 | usbipd_driver_close();
92 | err_out:
93 | return EXIT_FAILURE;
94 | }
95 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_net_client.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 | #include
21 |
22 | struct usbip_sock *usbip_ex_connect(const char *host, const char *port,
23 | void *opt)
24 | {
25 | int connfd;
26 | struct addrinfo hints, *rp;
27 | struct sockaddr_in addr;
28 | struct usbip_sock *sock;
29 | struct usbip_ex_net_arg *arg;
30 | int nodelay = 1;
31 |
32 | memset(&hints, 0, sizeof(hints));
33 | hints.ai_socktype = SOCK_STREAM;
34 | hints.ai_family = AF_INET;
35 |
36 | if (getaddrinfo(host, port, &hints, &rp)) {
37 | perror("Failed to getaddrinfo");
38 | goto err_out;
39 | }
40 |
41 | connfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
42 | if (connfd < 0) {
43 | perror("Failed to socket");
44 | goto err_addr_free;
45 | }
46 |
47 | sock = (struct usbip_sock *)malloc(sizeof(struct usbip_sock));
48 | if (!sock) {
49 | perror("Failed to mallo sock");
50 | goto err_sock_close;
51 | }
52 |
53 | arg = (struct usbip_ex_net_arg *)
54 | malloc(sizeof(struct usbip_ex_net_arg));
55 | if (!arg) {
56 | perror("Failed to mallo arg");
57 | goto err_sock_free;
58 | }
59 |
60 | if (connect(connfd, rp->ai_addr, rp->ai_addrlen)) {
61 | perror("Failed to connect");
62 | goto err_arg_free;
63 | }
64 |
65 | if (setsockopt(connfd, IPPROTO_TCP, TCP_NODELAY,
66 | &nodelay, sizeof(nodelay))) {
67 | perror("Failed to set nodelay");
68 | goto err_sock_close;
69 | }
70 |
71 | arg->connfd = connfd;
72 |
73 | usbip_sock_init(sock, connfd, arg,
74 | usbip_ex_send, usbip_ex_recv,
75 | usbip_ex_shutdown);
76 | freeaddrinfo(rp);
77 | return sock;
78 | err_arg_free:
79 | free(arg);
80 | err_sock_free:
81 | free(sock);
82 | err_sock_close:
83 | close(connfd);
84 | err_addr_free:
85 | freeaddrinfo(rp);
86 | err_out:
87 | return NULL;
88 | }
89 |
90 | void usbip_ex_close(struct usbip_sock *sock)
91 | {
92 | struct usbip_ex_net_arg *arg = (struct usbip_ex_net_arg *)sock->arg;
93 |
94 | close(arg->connfd);
95 | free(arg);
96 | free(sock);
97 | }
98 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_net_common.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 |
20 | int usbip_ex_send(void *_arg, void *buf, int len)
21 | {
22 | struct usbip_ex_net_arg *arg = (struct usbip_ex_net_arg *)_arg;
23 |
24 | return send(arg->connfd, buf, len, 0);
25 | }
26 |
27 | int usbip_ex_recv(void *_arg, void *buf, int len, int wait_all)
28 | {
29 | struct usbip_ex_net_arg *arg = (struct usbip_ex_net_arg *)_arg;
30 |
31 | return recv(arg->connfd, buf, len, wait_all ? MSG_WAITALL : 0);
32 | }
33 |
34 | void usbip_ex_shutdown(void *_arg)
35 | {
36 | struct usbip_ex_net_arg *arg = (struct usbip_ex_net_arg *)_arg;
37 |
38 | shutdown(arg->connfd, SHUT_RDWR);
39 | }
40 |
--------------------------------------------------------------------------------
/tools/usb/usbip/api-example/src/usbip_ex_net_server.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_ex.h"
19 | #include
20 |
21 | int usbip_ex_listen(void)
22 | {
23 | int listenfd;
24 | struct sockaddr_in addr;
25 |
26 | listenfd = socket(AF_INET, SOCK_STREAM, 0);
27 | if (listenfd < 0) {
28 | perror("Failed to socket");
29 | goto err_out;
30 | }
31 |
32 | memset(&addr, 0, sizeof(addr));
33 | addr.sin_family = AF_INET;
34 | addr.sin_addr.s_addr = INADDR_ANY;
35 | addr.sin_port = htons(EXAMPLE_PORT);
36 |
37 | if (bind(listenfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
38 | perror("Failed to bind");
39 | goto err_sock_close;
40 | }
41 |
42 | if (listen(listenfd, 5) < 0) {
43 | perror("Failed to listen");
44 | goto err_sock_close;
45 | }
46 |
47 | return listenfd;
48 | err_sock_close:
49 | close(listenfd);
50 | err_out:
51 | return -1;
52 | }
53 |
54 | int usbip_ex_accept(int listenfd, struct usbip_ex_net_info *info)
55 | {
56 | int connfd;
57 | struct sockaddr_in addr;
58 | int addrlen = sizeof(addr);
59 | int reuseaddr = 1;
60 | int nodelay = 1;
61 |
62 | connfd = accept(listenfd, (struct sockaddr *)&addr, &addrlen);
63 | if (connfd < 0) {
64 | perror("Failed to accept");
65 | goto err_out;
66 | }
67 |
68 | if (getnameinfo((struct sockaddr *)&addr, addrlen,
69 | info->host, NI_MAXHOST, info->port, NI_MAXSERV,
70 | NI_NUMERICHOST | NI_NUMERICSERV)) {
71 | perror("Failed to getnameinfo");
72 | goto err_sock_close;
73 | }
74 |
75 | if (setsockopt(connfd, SOL_SOCKET, SO_REUSEADDR,
76 | &reuseaddr, sizeof(reuseaddr))) {
77 | perror("Failed to set reuse addr");
78 | goto err_sock_close;
79 | }
80 |
81 | if (setsockopt(connfd, IPPROTO_TCP, TCP_NODELAY,
82 | &nodelay, sizeof(nodelay))) {
83 | perror("Failed to set nodelay");
84 | goto err_sock_close;
85 | }
86 |
87 | return connfd;
88 | err_sock_close:
89 | close(connfd);
90 | err_out:
91 | return -1;
92 | }
93 |
--------------------------------------------------------------------------------
/tools/usb/usbip/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -x
2 |
3 | #aclocal
4 | #autoheader
5 | #libtoolize --copy --force
6 | #automake-1.9 -acf
7 | #autoconf
8 |
9 | autoreconf -i -f -v
10 |
--------------------------------------------------------------------------------
/tools/usb/usbip/cleanup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | if [ -r Makefile ]; then
4 | make distclean
5 | fi
6 |
7 | FILES="aclocal.m4 autom4te.cache compile config.guess config.h.in config.log \
8 | config.status config.sub configure cscope.out depcomp install-sh \
9 | libsrc/Makefile libsrc/Makefile.in libtool ltmain.sh Makefile \
10 | Makefile.in missing src/Makefile src/Makefile.in"
11 |
12 | rm -vRf $FILES
13 |
--------------------------------------------------------------------------------
/tools/usb/usbip/configure.ac:
--------------------------------------------------------------------------------
1 | dnl Process this file with autoconf to produce a configure script.
2 |
3 | AC_PREREQ(2.59)
4 | AC_INIT([usbip-utils], [2.0], [linux-usb@vger.kernel.org])
5 | AC_DEFINE([USBIP_VERSION], [0x00000111], [binary-coded decimal version number])
6 |
7 | CURRENT=0
8 | REVISION=1
9 | AGE=0
10 | AC_SUBST([LIBUSBIP_VERSION], [$CURRENT:$REVISION:$AGE], [library version])
11 |
12 | AC_CONFIG_SRCDIR([src/usbipd.c])
13 | AC_CONFIG_HEADERS([config.h])
14 |
15 | AM_INIT_AUTOMAKE([foreign])
16 | LT_INIT
17 |
18 | # Silent build for automake >= 1.11
19 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
20 |
21 | AC_SUBST([EXTRA_CFLAGS], ["-Wall -Werror -Wextra -std=gnu99"])
22 |
23 | # Checks for programs.
24 | AC_PROG_CC
25 | AC_PROG_INSTALL
26 | AC_PROG_MAKE_SET
27 |
28 | # Checks for header files.
29 | AC_HEADER_DIRENT
30 | AC_HEADER_STDC
31 | AC_CHECK_HEADERS([arpa/inet.h fcntl.h libudev.h netdb.h netinet/in.h dnl
32 | pthread.h poll.h stdint.h stdlib.h dnl
33 | string.h sys/socket.h syslog.h unistd.h])
34 |
35 | # Checks for typedefs, structures, and compiler characteristics.
36 | AC_TYPE_INT32_T
37 | AC_TYPE_SIZE_T
38 | AC_TYPE_SSIZE_T
39 | AC_TYPE_UINT16_T
40 | AC_TYPE_UINT32_T
41 | AC_TYPE_UINT8_T
42 |
43 | # Checks for declarations.
44 | AC_CHECK_DECLS([container_of])
45 | AC_CHECK_DECLS([P_tmpdir])
46 |
47 | # Checks for library functions.
48 | AC_FUNC_REALLOC
49 | AC_CHECK_FUNCS([daemon fork memset mkdir regcomp socket strchr dnl
50 | strerror strstr strtoul syslog])
51 |
52 | AC_CHECK_HEADER([libudev.h],
53 | [AC_CHECK_LIB([udev], [udev_new],
54 | [LIBS="$LIBS -ludev"],
55 | [AC_MSG_ERROR([Missing udev library!])])],
56 | [AC_MSG_ERROR([Missing /usr/include/libudev.h])])
57 |
58 | # Checks for libwrap library.
59 | AC_MSG_CHECKING([whether to use the libwrap (TCP wrappers) library])
60 | AC_ARG_WITH([tcp-wrappers],
61 | [AS_HELP_STRING([--with-tcp-wrappers],
62 | [use the libwrap (TCP wrappers) library])],
63 | dnl [ACTION-IF-GIVEN]
64 | [if test "$withval" = "yes"; then
65 | AC_MSG_RESULT([yes])
66 | AC_MSG_CHECKING([for hosts_access in -lwrap])
67 | saved_LIBS="$LIBS"
68 | LIBS="-lwrap $saved_LIBS"
69 | AC_TRY_LINK(
70 | [int hosts_access(); int allow_severity, deny_severity;],
71 | [hosts_access()],
72 | [AC_MSG_RESULT([yes]);
73 | AC_DEFINE([HAVE_LIBWRAP], [1],
74 | [use tcp wrapper]) wrap_LIB="-lwrap"],
75 | [AC_MSG_RESULT([not found]); exit 1])
76 | else
77 | AC_MSG_RESULT([no]);
78 | fi],
79 | dnl [ACTION-IF-NOT-GIVEN]
80 | [AC_MSG_RESULT([(default)])
81 | AC_MSG_CHECKING([for hosts_access in -lwrap])
82 | saved_LIBS="$LIBS"
83 | LIBS="-lwrap $saved_LIBS"
84 | AC_TRY_LINK(
85 | [int hosts_access(); int allow_severity, deny_severity;],
86 | [hosts_access()],
87 | [AC_MSG_RESULT([yes]);
88 | AC_DEFINE([HAVE_LIBWRAP], [1], [use tcp wrapper])],
89 | [AC_MSG_RESULT([no]); LIBS="$saved_LIBS"])])
90 |
91 | # Sets directory containing usb.ids.
92 | AC_ARG_WITH([usbids-dir],
93 | [AS_HELP_STRING([--with-usbids-dir=DIR],
94 | [where usb.ids is found (default /usr/share/hwdata/)])],
95 | [USBIDS_DIR=$withval], [USBIDS_DIR="/usr/share/hwdata/"])
96 | AC_SUBST([USBIDS_DIR])
97 |
98 | # use _FORTIFY_SOURCE
99 | AC_MSG_CHECKING([whether to use fortify])
100 | AC_ARG_WITH([fortify],
101 | [AS_HELP_STRING([--with-fortify],
102 | [use _FORTIFY_SROUCE option when compiling)])],
103 | dnl [ACTION-IF-GIVEN]
104 | [if test "$withval" = "yes"; then
105 | AC_MSG_RESULT([yes])
106 | CFLAGS="$CFLAGS -D_FORTIFY_SOURCE -O"
107 | else
108 | AC_MSG_RESULT([no])
109 | CFLAGS="$CFLAGS -U_FORTIFY_SOURCE"
110 | fi
111 | ],
112 | dnl [ACTION-IF-NOT-GIVEN]
113 | [AC_MSG_RESULT([default])])
114 |
115 | AC_CONFIG_FILES([Makefile libsrc/Makefile src/Makefile])
116 | AC_OUTPUT
117 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "February 2009" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbip \- manage USB/IP devices
4 | .SH SYNOPSIS
5 | .B usbip
6 | [\fIoptions\fR] <\fIcommand\fR> <\fIargs\fR>
7 |
8 | .SH DESCRIPTION
9 | On a USB/IP device side computer,
10 | lists local devices, makes a device importable, makes not importable,
11 | connects a device and disconnects a device.
12 |
13 | On a USB/IP application side computer,
14 | lists devices importable from a remote computer, attaches a remote device and detaches an attached device.
15 |
16 | .SH OPTIONS
17 | .HP
18 | \fB\-d\fR, \fB\-\-debug\fR
19 | .IP
20 | Print debugging information.
21 | .PP
22 |
23 | .HP
24 | \fB\-l\fR, \fB\-\-log\fR
25 | .IP
26 | Log to syslog.
27 | .PP
28 |
29 | .HP
30 | \fB\-tPORT\fR, \fB\-\-tcp-port PORT\fR
31 | .IP
32 | TCP port number used by remote usbip daemon. Default is 3240.
33 | .PP
34 |
35 | .SH COMMANDS
36 | .HP
37 | \fBversion\fR
38 | .IP
39 | Show version and exit.
40 | .PP
41 |
42 | .HP
43 | \fBhelp\fR [\fIcommand\fR]
44 | .IP
45 | Print the program help message, or help on a specific command, and
46 | then exit.
47 | .PP
48 |
49 | .HP
50 | \fBattach\fR \-\-remote <\fIhost\fR> \-\-busid <\fIbusid\fR>
51 | .IP
52 | Attach a importable USB device from remote computer.
53 | .PP
54 |
55 | .HP
56 | \fBdetach\fR \-\-port <\fIport\fR>
57 | .IP
58 | Detach an imported USB device.
59 | .PP
60 |
61 | .HP
62 | \fBconnect\fR \-\-remote <\fIhost\fR> \-\-busid <\fIbusid\fR> [\-\-device]
63 | .IP
64 | Connect a USB device to remote computer.
65 | .PP
66 |
67 | .HP
68 | \fBdisconnect\fR \-\-remote <\fIhost\fR> \-\-busid <\fIbusid\fR> [\-\-device]
69 | .IP
70 | Disconnect a USB device from remote computer. It allows to disconnet from a computer which issued connect operation.
71 | .PP
72 |
73 | .HP
74 | \fBbind\fR \-\-busid <\fIbusid\fR>
75 | .IP
76 | Make a USB device importable from remote computer.
77 | .PP
78 |
79 | .HP
80 | \fBunbind\fR \-\-busid <\fIbusid\fR>
81 | .IP
82 | Make a USB device not importable so it can be used by a local driver.
83 | .PP
84 |
85 | .HP
86 | \fBlist\fR \-\-remote <\fIhost\fR>
87 | .IP
88 | List importable USB devices from a remote computer.
89 | .PP
90 |
91 | .HP
92 | \fBlist\fR [\-\-parsable] \-\-local
93 | .IP
94 | List local USB devices.
95 | .PP
96 |
97 | .HP
98 | \fBlist\fR [\-\-parsable] \-\-device
99 | .IP
100 | List local USB devices with an alternate driver, e.g. vUDC.
101 | .PP
102 |
103 | .HP
104 | \fBport\fR
105 | .HP
106 | .IP
107 | List imported USB devices.
108 | .PP
109 |
110 |
111 | .SH ARGUMENTS
112 | .HP
113 | \fB\-rHOST\fR, \fB\-\-remote HOST\fR
114 | .IP
115 | Remote host address.
116 | .PP
117 |
118 | .HP
119 | \fB\-bBUSID\fR, \fB\-\-busid BUSID\fR
120 | .IP
121 | Bus ID of a device to be handled.
122 | .PP
123 |
124 | .HP
125 | \fB\-pPORT\fR, \fB\-\-port PORT\fR
126 | .IP
127 | d.
128 | Port number of an imported device shown by port command.
129 | .PP
130 |
131 | .HP
132 | \fB\-l\fR, \fB\-\-local\fR
133 | .IP
134 | Target local devices.
135 | .PP
136 |
137 | .HP
138 | \fB\-p\fR, \fB\-\-parsable\fR
139 | .IP
140 | Parsable format.
141 | .PP
142 |
143 | .HP
144 | \fB\-d\fR, \fB\-\-device\fR
145 | .IP
146 | Run with with an alternate driver, e.g. vUDC.
147 | .PP
148 |
149 |
150 | .SH EXAMPLES
151 |
152 | dev: at a device side computer
153 | .br
154 | app: at an application side computer
155 |
156 | Attach a device from a remote computer
157 | dev:# usbip list
158 | - List local USB devices.
159 | dev:# usbip bind --busid 1-2
160 | - Make a USB device importable from a remote computer.
161 | app:# usbip list --remote 172.1.2.3
162 | - List importable USB devices on the computer.
163 | app:# usbip attach --remote 172.1.2.3 --busid 1-2
164 | - Import a remote USB device.
165 | app:# usbip port
166 | - List imported USB devices.
167 | app:# usbip detach --port 0
168 | - Detach the USB device.
169 | dev:# usbip unbind --busid 1-2
170 | - Make a USB device not importable, then release to local.
171 |
172 | Connect a device to a remote computer
173 | dev:# usbip list
174 | - List local USB devices.
175 | dev:# usbip connect --remote 172.4.5.6 --busid 1-2
176 | - Export a USB device to a remote computer.
177 | dev:# usbip disconnect --remote 172.4.5.6 --busid 1-2
178 | - Unxport a USB device from a remote computer.
179 |
180 |
181 | .SH "SEE ALSO"
182 | \fBusbipd\fP\fB(8)\fB\fP
183 | \fBusbipa\fP\fB(8)\fB\fP
184 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_attach_device.3:
--------------------------------------------------------------------------------
1 | .TH USBIP 3 2016-02-01 "" "Linux Programmer's Manual"
2 | .SH NAME
3 | usbip_attach_device, usbip_detach_port, usbip_bind_device, usbip_unbind_device,
4 | usbip_list_imported_devices, usbip_list_importable_devices,
5 | usbip_list_importable_devices, usbip_list_local_devices,
6 | usbip_connect_device, usbip_disconnect_device \- USB/IP command functions
7 | .SH SYNOPSIS
8 | .nf
9 | .B #include
10 | .sp
11 | .BI "int usbip_attach_device(const char *" host ", const char *" tcp-port ","
12 | .BI " const char *" busid ");"
13 | .sp
14 | .BI "int usbip_detach_port(const char *" port ");"
15 | .sp
16 | .BI "int usbip_bind_device(const char *" busid ");"
17 | .sp
18 | .BI "int usbip_unbind_device(const char *" busid ");"
19 | .sp
20 | .BI "int usbip_list_imported_devices(void);"
21 | .sp
22 | .BI "int usbip_list_importable_devices(const char *" host ",
23 | .BI " const char *" tcp-port ");"
24 | .sp
25 | .BI "int usbip_list_local_devices(int parsable);"
26 | .sp
27 | .BI "int usbip_connect_device(const char *" host ", const char *" tcp-port ","
28 | .BI " const char *" busid ");"
29 | .sp
30 | .BI "usbip_disconnect_device(const char *" host ", const char *" tcp-port ","
31 | .BI " const char *" busid ");"
32 | .ad b
33 | .SH DESCRIPTION
34 | These functions adds an application protocol
35 | to each command supported by \fBusbip(8)\fP
36 | in combination with \fBusbip_conn_init(3)\fP and \fBusbip_sock_init(3)\fP.
37 | .PP
38 | Here,
39 | .BR usbip_list_imported_devices()
40 | is corresponding to \fBport\fP command,
41 | .BR usbip_list_importable_devices()
42 | and
43 | .BR usbip_list_devices()
44 | are corresponding to \fBlist\fP command
45 | with remote or local option respectively.
46 | .SH RETURN VALUE
47 | 0 on success otherwise none zero.
48 | .SH "SEE ALSO"
49 | .BR usbip (8)
50 | .BR usbip_conn_init (3)
51 | .BR usbip_sock_init (3)
52 | .BR usbip_recv_pdu (3)
53 | .BR usbip_set_use_debug (3)
54 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_bind_device.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_break_all_connections.3:
--------------------------------------------------------------------------------
1 | .TH USBIP 3 2016-02-01 "" "Linux Programmer's Manual"
2 | .SH NAME
3 | usbip_conn_init, usbip_sock_init \- USB/IP setup functions
4 | .SH SYNOPSIS
5 | .nf
6 | .B #include
7 | .sp
8 | .BI "void usbip_break_all_connections(void);"
9 | .sp
10 | .BI "void usbip_break_connection(struct usbip_sock *sock);"
11 | .ad b
12 | .SH DESCRIPTION
13 | \fBusbip_break_all_connections()\fP breaks
14 | all reading threads from USB/IP driver.
15 | \fBusbip_break_connection()\fP breaks
16 | reading thread specified by \fIsock\fP from USB/IP driver.
17 | Valid when usbip_ux module is loaded otherwise they have no effect.
18 | Netowrk connection must be closed in combination with these functions.
19 | .SH "SEE ALSO"
20 | .BR usbip_recv_pdu (3)
21 | .BR usbip_attach_device (3)
22 | .BR usbip_connect_device (3)
23 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_break_connection.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_break_all_connections.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_conn_init.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_sock_init.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_connect_device.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_detach_port.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_disconnect_device.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_hdriver_set.3:
--------------------------------------------------------------------------------
1 | .TH USBIP 3 2016-02-01 "" "Linux Programmer's Manual"
2 | .SH NAME
3 | usbip_hdriver_set
4 | \- Alternate host driver
5 | .SH SYNOPSIS
6 | .nf
7 | .B #include
8 | .sp
9 | .BI "void usbip_hdriver_set(int type);"
10 | .ad b
11 | .SH DESCRIPTION
12 | This function changes host driver to specified type for device side daemon and commands. The default setting is the host driver. List of the type is as below.
13 | .TP
14 | .B USBIP_HDRIVER_TYPE_HOST
15 | Host driver. i.e. STUB driver.
16 | .TP
17 | .B USBIP_HDRIVER_TYPE_DEVICE
18 | Device driver. e.g. vUDC.
19 | .PP
20 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_list_importable_devices.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_list_imported_devices.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_list_local_devices.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_set_debug_flags.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_set_use_debug.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_set_use_debug.3:
--------------------------------------------------------------------------------
1 | .TH USBIP 3 2016-02-01 "" "Linux Programmer's Manual"
2 | .SH NAME
3 | usbip_set_use_debug, usbip_set_use_stderr, usbip_set_use_syslog,
4 | usbip_set_debug_flags \- USB/IP debug functions
5 | .SH SYNOPSIS
6 | .nf
7 | .B #include
8 | .sp
9 | .BI "void usbip_set_use_debug(int val);"
10 | .sp
11 | .BI "void usbip_set_use_stderr(int val);"
12 | .sp
13 | .BI "void usbip_set_use_syslog(int val);"
14 | .sp
15 | .BI "void usbip_set_debug_flags(unsigned long flags);"
16 | .sp
17 | .ad b
18 | .SH DESCRIPTION
19 | These functions set debug mode to USB/IP.
20 | .PP
21 | .BR usbip_set_use_debug()
22 | sets boolean value to enable debug log.
23 | .PP
24 | .BR usbip_set_use_stderr()
25 | sets boolean value to enable stderr output.
26 | .PP
27 | .BR usbip_set_use_syslog()
28 | sets boolean value to enable syslog output.
29 | .PP
30 | .BR usbip_set_debug_flags()
31 | sets debug flags for STUB emulator for libusb.
32 | Available when -DUSBIP_WITH_LIBUSB is used.
33 | .PP
34 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_set_use_stderr.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_set_use_debug.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_set_use_syslog.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_set_use_debug.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_sock_init.3:
--------------------------------------------------------------------------------
1 | .TH USBIP 3 2016-02-01 "" "Linux Programmer's Manual"
2 | .SH NAME
3 | usbip_conn_init, usbip_sock_init \- USB/IP setup functions
4 | .SH SYNOPSIS
5 | .nf
6 | .B #include
7 | .sp
8 | .BI "void usbip_conn_init("
9 | .BI " struct usbip_sock *(*" open ")(const char *, const char *,
10 | .BI " void *),"
11 | .BI " void (*" close ")(struct usbip_sock *),
12 | .BI " void *opt);"
13 | .sp
14 | .BI "void usbip_sock_init("
15 | .BI " struct usbip_sock *" sock ", int " fd ", void *" arg ","
16 | .BI " int (*" send ")(void *, void *, int),"
17 | .BI " int (*" recv ")(void *, void *, int, int),"
18 | .BI " void (*shutdown)(void *));"
19 | .ad b
20 | .SH DESCRIPTION
21 | These functions adds an application protocols to USB/IP daemon and command.
22 | .PP
23 | .BR usbip_conn_init()
24 | sets connection open and close callback invoked in command APIs:
25 | \fBusbip_attach_device()\fP,
26 | \fBusbip_list_importable_devices()\fP,
27 | \fBusbip_connect_device()\fP and
28 | \fBusbip_disconnect_device()\fP.
29 | The \fIopen\fP callback will be called with host and port string as arguments.
30 | \fIopt\fP will be passed to \fIopen\fP as the third argument.
31 | \fIopen\fP should return \fIstruct_sock\fP which are filled with
32 | \fBusbip_sock_init()\fP.
33 | .PP
34 | The \fIclose\fP callbask will be called to deallocate
35 | .IR struct_sock .
36 | .PP
37 | .BR usbip_sock_init()
38 | fills
39 | .IR struct_sock
40 | with \fIfd\fP, \fIarg\fP and callbacks.
41 | \fIfd\fP is used for default socket functions
42 | which are used when NULL is specified for the callbacks
43 | invoked in both command and daemon APIs.
44 | The \fIarg\fP is a pointer to any data
45 | which will be passed as the first argument to the callbacks.
46 | .PP
47 | \fIsend\fP
48 | will be called with pointer to buffer which includes data to be sent
49 | and bytes of data to send.
50 | It should return number of bytes sent or -1 on error.
51 | .PP
52 | \fIrecv\fP
53 | will be called with pointer to a buffer to store received data,
54 | buffer length and a flag.
55 | The last flag argument of \fIrecv\fP is a boolean value
56 | which denote wait all bytes or not.
57 | It should return number of bytes received or -1 on error.
58 | .PP
59 | \fIshutdown\fP is called to disconnect.
60 | .PP
61 | .SH "SEE ALSO"
62 | .BR usbip (8)
63 | .BR usbipd (8)
64 | .BR usbipa (8)
65 | .BR usbip_recv_pdu (3)
66 | .BR usbip_attach_device (3)
67 | .BR usbip_detach_port (3)
68 | .BR usbip_bind_device (3)
69 | .BR usbip_unbind_device (3)
70 | .BR usbip_list_imported_devices (3)
71 | .BR usbip_list_importable_devices (3)
72 | .BR usbip_list_devices (3)
73 | .BR usbip_connect_device (3)
74 | .BR usbip_disconnect_device (3)
75 | .BR usbip_set_use_debug (3)
76 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbip_unbind_device.3:
--------------------------------------------------------------------------------
1 | .so man3/usbip_attach_device.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbipa.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "March 2015" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbipa \- USB/IP application side daemon
4 | .SH SYNOPSIS
5 | .B usbipa
6 | [\fIoptions\fR]
7 |
8 | .SH DESCRIPTION
9 | .B usbipa
10 | runs on an application side computer and make remote USB devices connected using \fBusbip connect\fR at remote computers accessible on the application side computer.
11 |
12 | .SH OPTIONS
13 | .HP
14 | \fB\-4\fR, \fB\-\-ipv4\fR
15 | .IP
16 | Bind to IPv4. Default is both.
17 | .PP
18 |
19 | .HP
20 | \fB\-6\fR, \fB\-\-ipv6\fR
21 | .IP
22 | Bind to IPv6. Default is both.
23 | .PP
24 |
25 | .HP
26 | \fB\-D\fR, \fB\-\-daemon\fR
27 | .IP
28 | Run as a daemon process.
29 | .PP
30 |
31 | .HP
32 | \fB\-d\fR, \fB\-\-debug\fR
33 | .IP
34 | Print debugging information.
35 | .PP
36 |
37 | .HP
38 | \fB\-PFILE\fR, \fB\-\-pid FILE\fR
39 | .IP
40 | Write process id to FILE.
41 | .br
42 | If no FILE specified, use /var/run/usbipd.pid
43 | .PP
44 |
45 | .HP
46 | \fB\-tPORT\fR, \fB\-\-tcp\-port PORT\fR
47 | .IP
48 | Listen on TCP/IP port PORT. Default is 3240.
49 | .PP
50 |
51 | .HP
52 | \fB\-h\fR, \fB\-\-help\fR
53 | .IP
54 | Print the program help message and exit.
55 | .PP
56 |
57 | .HP
58 | \fB\-v\fR, \fB\-\-version\fR
59 | .IP
60 | Show version.
61 | .PP
62 |
63 | .SH LIMITATIONS
64 |
65 | .B usbipa
66 | offers no authentication or authorization for USB/IP. Any
67 | USB/IP client can connect and use exported devices.
68 |
69 | .SH EXAMPLES
70 |
71 | app:# modprobe vhci-hcd
72 |
73 | app:# usbipa -D
74 | - Start usbip daemon.
75 |
76 | .SH "SEE ALSO"
77 | \fBusbip\fP\fB(8)\fB\fP
78 | \fBusbipd\fP\fB(8)\fB\fP
79 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbipd.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "February 2009" "usbip" "System Administration Utilities"
2 | .SH NAME
3 | usbipd \- USB/IP device side daemon
4 | .SH SYNOPSIS
5 | .B usbipd
6 | [\fIoptions\fR]
7 |
8 | .SH DESCRIPTION
9 | .B usbipd
10 | runs on a divice side computer and provides USB/IP access from remote computers.
11 |
12 | To make devices accessible from remote computers, they must be made importable using \fBusbip bind\fR.
13 |
14 | .SH OPTIONS
15 | .HP
16 | \fB\-4\fR, \fB\-\-ipv4\fR
17 | .IP
18 | Bind to IPv4. Default is both.
19 | .PP
20 |
21 | .HP
22 | \fB\-6\fR, \fB\-\-ipv6\fR
23 | .IP
24 | Bind to IPv6. Default is both.
25 | .PP
26 |
27 | .HP
28 | \fB\-D\fR, \fB\-\-daemon\fR
29 | .IP
30 | Run as a daemon process.
31 | .PP
32 |
33 | .HP
34 | \fB\-d\fR, \fB\-\-debug\fR
35 | .IP
36 | Print debugging information.
37 | .PP
38 |
39 | .HP
40 | \fB\-PFILE\fR, \fB\-\-pid FILE\fR
41 | .IP
42 | Write process id to FILE.
43 | .br
44 | If no FILE specified, use /var/run/usbipd.pid
45 | .PP
46 |
47 | .HP
48 | \fB\-tPORT\fR, \fB\-\-tcp\-port PORT\fR
49 | .IP
50 | Listen on TCP/IP port PORT. Default is 3240.
51 | .PP
52 |
53 | .HP
54 | \fB\-e\fR, \fB\-\-device\fR
55 | .IP
56 | Run with with an alternate driver, e.g. vUDC.
57 | .PP
58 |
59 | .HP
60 | \fB\-h\fR, \fB\-\-help\fR
61 | .IP
62 | Print the program help message and exit.
63 | .PP
64 |
65 | .HP
66 | \fB\-v\fR, \fB\-\-version\fR
67 | .IP
68 | Show version.
69 | .PP
70 |
71 | .SH LIMITATIONS
72 |
73 | .B usbipd
74 | offers no authentication or authorization for USB/IP. Any
75 | USB/IP client can connect and use exported devices.
76 |
77 | .SH EXAMPLES
78 |
79 | dev:# modprobe usbip-host
80 |
81 | dev:# usbipd -D
82 | - Start usbip daemon.
83 |
84 | dev:# usbip list --local
85 | - List driver assignments for usb devices.
86 |
87 | dev:# usbip bind --busid 1-2
88 | - Bind usbip-host.ko to the device of busid 1-2.
89 | - USB device 1-2 is now importable from other computer!
90 |
91 | dev:# usbip unbind --busid 1-2
92 | - Unind usbip-host.ko from the device of busid 1-2.
93 | - USB device 1-2 is not importable from other computer.
94 |
95 | .SH "SEE ALSO"
96 | \fBusbip\fP\fB(8)\fB\fP
97 | \fBusbipa\fP\fB(8)\fB\fP
98 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbipd_driver_close.3:
--------------------------------------------------------------------------------
1 | .so man3/usbipd_recv_pdu.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbipd_driver_open.3:
--------------------------------------------------------------------------------
1 | .so man3/usbipd_recv_pdu.3
2 |
--------------------------------------------------------------------------------
/tools/usb/usbip/doc/usbipd_recv_pdu.3:
--------------------------------------------------------------------------------
1 | .TH USBIP 3 2016-02-01 "" "Linux Programmer's Manual"
2 | .SH NAME
3 | usbipd_driver_open, usbipd_recv_pdu, usbipd_driver_close
4 | \- USB/IP daemon functions
5 | .SH SYNOPSIS
6 | .nf
7 | .B #include
8 | .sp
9 | .BI "int usbipd_driver_open(void);"
10 | .sp
11 | .BI "int usbipd_recv_pdu(struct usbip_sock *" sock ",
12 | .BI " const char *" host ", const char *" tcp-port ");"
13 | .sp
14 | .BI "void usbipd_driver_close(void);"
15 | .ad b
16 | .SH DESCRIPTION
17 | These functions adds an application protocol to USB/IP daemons
18 | in combination with \fBusbip_conn_init(3)\fP and \fBusbip_sock_init(3)\fP.
19 | .PP
20 | .BR usbipd_driver_open()
21 | opens VHCI or STUB driver in the beggining of a daemon.
22 | .PP
23 | .BR usbipd_recv_pdu()
24 | processes a request which is sent form remote command.
25 | \fIhost\fP and \fport\P are remote host and port
26 | which are used to create internal control records.
27 | .PP
28 | .BR usbipd_driver_close()
29 | closes VHCI or STUB driver at the end of a daemon.
30 | .SH RETURN VALUE
31 | 0 on success otherwise none zero.
32 | .SH "SEE ALSO"
33 | .BR usbipd (8)
34 | .BR usbipa (8)
35 | .BR usbip (8)
36 | .BR usbip_conn_init (3)
37 | .BR usbip_sock_init (3)
38 | .BR usbip_set_use_debug (3)
39 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/Makefile.am:
--------------------------------------------------------------------------------
1 | libusbip_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
2 | libusbip_la_CFLAGS = @EXTRA_CFLAGS@
3 | libusbip_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@
4 |
5 | lib_LTLIBRARIES := libusbip.la
6 | libusbip_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \
7 | usbip_device_driver.c usbip_device_driver.h \
8 | usbip_common.c usbip_common.h usbip_host_common.h \
9 | usbip_host_common.c usbip_host_api.c \
10 | vhci_driver.c vhci_driver.h \
11 | usbip_ux.c usbip_ux.h \
12 | sysfs_utils.c sysfs_utils.h
13 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/list.h:
--------------------------------------------------------------------------------
1 | #ifndef _LIST_H
2 | #define _LIST_H
3 |
4 | #include "usbip_common.h"
5 |
6 | /* Stripped down implementation of linked list taken
7 | * from the Linux Kernel.
8 | */
9 |
10 | /*
11 | * Simple doubly linked list implementation.
12 | *
13 | * Some of the internal functions ("__xxx") are useful when
14 | * manipulating whole lists rather than single entries, as
15 | * sometimes we already know the next/prev entries and we can
16 | * generate better code by using them directly rather than
17 | * using the generic single-entry routines.
18 | */
19 |
20 | struct list_head {
21 | struct list_head *next, *prev;
22 | };
23 |
24 | #define LIST_HEAD_INIT(name) { &(name), &(name) }
25 |
26 | #define LIST_HEAD(name) \
27 | struct list_head name = LIST_HEAD_INIT(name)
28 |
29 | static inline void INIT_LIST_HEAD(struct list_head *list)
30 | {
31 | list->next = list;
32 | list->prev = list;
33 | }
34 |
35 | /*
36 | * Insert a new entry between two known consecutive entries.
37 | *
38 | * This is only for internal list manipulation where we know
39 | * the prev/next entries already!
40 | */
41 | static inline void __list_add(struct list_head *neo,
42 | struct list_head *prev,
43 | struct list_head *next)
44 | {
45 | next->prev = neo;
46 | neo->next = next;
47 | neo->prev = prev;
48 | prev->next = neo;
49 | }
50 |
51 | /**
52 | * list_add - add a new entry
53 | * @new: new entry to be added
54 | * @head: list head to add it after
55 | *
56 | * Insert a new entry after the specified head.
57 | * This is good for implementing stacks.
58 | */
59 | static inline void list_add(struct list_head *neo, struct list_head *head)
60 | {
61 | __list_add(neo, head, head->next);
62 | }
63 |
64 | /*
65 | * Delete a list entry by making the prev/next entries
66 | * point to each other.
67 | *
68 | * This is only for internal list manipulation where we know
69 | * the prev/next entries already!
70 | */
71 | static inline void __list_del(struct list_head * prev, struct list_head * next)
72 | {
73 | next->prev = prev;
74 | prev->next = next;
75 | }
76 |
77 | #define POISON_POINTER_DELTA 0
78 | #define LIST_POISON1 ((char *) 0x00100100 + POISON_POINTER_DELTA)
79 | #define LIST_POISON2 ((char *) 0x00200200 + POISON_POINTER_DELTA)
80 |
81 | /**
82 | * list_del - deletes entry from list.
83 | * @entry: the element to delete from the list.
84 | * Note: list_empty() on entry does not return true after this, the entry is
85 | * in an undefined state.
86 | */
87 | static inline void __list_del_entry(struct list_head *entry)
88 | {
89 | __list_del(entry->prev, entry->next);
90 | }
91 |
92 | static inline void list_del(struct list_head *entry)
93 | {
94 | __list_del(entry->prev, entry->next);
95 | entry->next = (struct list_head *)LIST_POISON1;
96 | entry->prev = (struct list_head *)LIST_POISON2;
97 | }
98 |
99 | /**
100 | * list_entry - get the struct for this entry
101 | * @ptr: the &struct list_head pointer.
102 | * @type: the type of the struct this is embedded in.
103 | * @member: the name of the list_head within the struct.
104 | */
105 | #define list_entry(ptr, type, member) \
106 | container_of(ptr, type, member)
107 | /**
108 | * list_for_each - iterate over a list
109 | * @pos: the &struct list_head to use as a loop cursor.
110 | * @head: the head for your list.
111 | */
112 | #define list_for_each(pos, head) \
113 | for (pos = (head)->next; pos != (head); pos = pos->next)
114 |
115 | /**
116 | * list_for_each_safe - iterate over a list safe against removal of list entry
117 | * @pos: the &struct list_head to use as a loop cursor.
118 | * @n: another &struct list_head to use as temporary storage
119 | * @head: the head for your list.
120 | */
121 | #define list_for_each_safe(pos, n, head) \
122 | for (pos = (head)->next, n = pos->next; pos != (head); \
123 | pos = n, n = pos->next)
124 |
125 | /**
126 | * container_of - cast a member of a structure out to the containing structure
127 | * @ptr: the pointer to the member.
128 | * @type: the type of the container struct this is embedded in.
129 | * @member: the name of the member within the struct.
130 | *
131 | */
132 | #ifndef USBIP_OS_HAVE_CONTAINER_OF
133 | #define container_of(ptr, type, member) ({ \
134 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \
135 | (type *)( (char *)__mptr - offsetof(type,member) );})
136 | #endif
137 |
138 | #endif
139 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/names.h:
--------------------------------------------------------------------------------
1 | /*
2 | * names.h -- USB name database manipulation routines
3 | *
4 | * Copyright (C) 1999, 2000 Thomas Sailer (sailer@ife.ee.ethz.ch)
5 | *
6 | * This program is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation; either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 | *
20 | *
21 | *
22 | * Copyright (C) 2005 Takahiro Hirofuchi
23 | * - names_free() is added.
24 | */
25 |
26 | #ifndef _NAMES_H
27 | #define _NAMES_H
28 |
29 | #include
30 | #include "usbip_common.h"
31 |
32 | /* used by usbip_common.c */
33 | extern const char *names_vendor(u_int16_t vendorid);
34 | extern const char *names_product(u_int16_t vendorid, u_int16_t productid);
35 | extern const char *names_class(u_int8_t classid);
36 | extern const char *names_subclass(u_int8_t classid, u_int8_t subclassid);
37 | extern const char *names_protocol(u_int8_t classid, u_int8_t subclassid,
38 | u_int8_t protocolid);
39 | extern int names_init(char *n);
40 | extern void names_free(void);
41 |
42 | #endif /* _NAMES_H */
43 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/sysfs_utils.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include "sysfs_utils.h"
7 | #include "usbip_common.h"
8 |
9 | int write_sysfs_attribute(const char *attr_path, const char *new_value,
10 | size_t len)
11 | {
12 | int fd;
13 | int length;
14 |
15 | fd = open(attr_path, O_WRONLY);
16 | if (fd < 0) {
17 | dbg("error opening attribute %s", attr_path);
18 | return -1;
19 | }
20 |
21 | length = write(fd, new_value, len);
22 | if (length < 0) {
23 | dbg("error writing to attribute %s", attr_path);
24 | close(fd);
25 | return -1;
26 | }
27 |
28 | close(fd);
29 |
30 | return 0;
31 | }
32 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/sysfs_utils.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __SYSFS_UTILS_H
3 | #define __SYSFS_UTILS_H
4 |
5 | int write_sysfs_attribute(const char *attr_path, const char *new_value,
6 | size_t len);
7 |
8 | #endif
9 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 | * Copyright (C) 2015-2016 Nobuo Iwata
4 | */
5 |
6 | #ifndef __USBIP_COMMON_H
7 | #define __USBIP_COMMON_H
8 |
9 | #include "usbip_config.h"
10 |
11 | #ifdef USBIP_WITH_LIBUSB
12 | #include "usbip_os.h"
13 | #else
14 | #include "usbip_ux.h"
15 | #endif
16 | #ifndef USBIP_OS_NO_LIBUDEV
17 | #include
18 | #endif
19 |
20 | #include
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #ifndef USBIP_OS_NO_SYSLOG
29 | #include
30 | #endif
31 | #ifndef USBIP_OS_NO_UNISTD_H
32 | #include
33 | #endif
34 | #ifdef __linux__
35 | #include
36 | #include
37 | #endif
38 |
39 | #ifndef USBIDS_FILE
40 | #define USBIDS_FILE "/usr/share/hwdata/usb.ids"
41 | #endif
42 |
43 | #ifndef VHCI_STATE_PATH
44 | #define VHCI_STATE_PATH "/var/run/vhci_hcd"
45 | #endif
46 |
47 | #define VUDC_DEVICE_DESCR_FILE "dev_desc"
48 |
49 | #ifdef __GNUC__
50 | #define PACK(__Declaration__) \
51 | __Declaration__ __attribute__((__packed__))
52 | #define UNUSED __attribute__((__unused__))
53 | #endif
54 |
55 | /* kernel module names */
56 | #define USBIP_CORE_MOD_NAME "usbip-core"
57 | #define USBIP_HOST_DRV_NAME "usbip-host"
58 | #define USBIP_DEVICE_DRV_NAME "usbip-vudc"
59 | #define USBIP_VHCI_DRV_NAME "vhci_hcd"
60 |
61 | /* sysfs constants */
62 | #define SYSFS_MNT_PATH "/sys"
63 | #define SYSFS_BUS_NAME "bus"
64 | #define SYSFS_BUS_TYPE "usb"
65 | #define SYSFS_DRIVERS_NAME "drivers"
66 |
67 | #define SYSFS_PATH_MAX 256
68 | #define SYSFS_BUS_ID_SIZE 32
69 | #ifndef SYSFS_NAME_LEN
70 | #define SYSFS_NAME_LEN 64
71 | #endif
72 |
73 | extern int usbip_use_syslog;
74 | extern int usbip_use_stderr;
75 | extern int usbip_use_debug ;
76 |
77 | #define PROGNAME "usbip"
78 |
79 | #define pr_fmt(fmt) "%s: %s: " fmt "\n", PROGNAME
80 |
81 | #ifndef USBIP_OS_NO_NR_ARGS
82 | #define dbg_fmt(fmt) pr_fmt("%s:%d:[%s] " fmt), "debug", \
83 | __FILE__, __LINE__, __func__
84 |
85 | #define err(fmt, args...) \
86 | do { \
87 | if (usbip_use_syslog) { \
88 | syslog(LOG_ERR, pr_fmt(fmt), "error", ##args); \
89 | } \
90 | if (usbip_use_stderr) { \
91 | fprintf(stderr, pr_fmt(fmt), "error", ##args); \
92 | } \
93 | } while (0)
94 |
95 | #define info(fmt, args...) \
96 | do { \
97 | if (usbip_use_syslog) { \
98 | syslog(LOG_INFO, pr_fmt(fmt), "info", ##args); \
99 | } \
100 | if (usbip_use_stderr) { \
101 | fprintf(stderr, pr_fmt(fmt), "info", ##args); \
102 | } \
103 | } while (0)
104 |
105 | #define dbg(fmt, args...) \
106 | do { \
107 | if (usbip_use_debug) { \
108 | if (usbip_use_syslog) { \
109 | syslog(LOG_DEBUG, dbg_fmt(fmt), ##args); \
110 | } \
111 | if (usbip_use_stderr) { \
112 | fprintf(stderr, dbg_fmt(fmt), ##args); \
113 | } \
114 | } \
115 | } while (0)
116 | #endif /* !USBIP_OS_NO_NR_ARGS */
117 |
118 | #define BUG() \
119 | do { \
120 | err("sorry, it's a bug!"); \
121 | abort(); \
122 | } while (0)
123 |
124 | PACK(
125 | struct usbip_usb_interface {
126 | uint8_t bInterfaceClass;
127 | uint8_t bInterfaceSubClass;
128 | uint8_t bInterfaceProtocol;
129 | uint8_t bInterfaceNumber;
130 | });
131 |
132 | PACK(
133 | struct usbip_usb_device {
134 | char path[SYSFS_PATH_MAX];
135 | char busid[SYSFS_BUS_ID_SIZE];
136 |
137 | uint32_t busnum;
138 | uint32_t devnum;
139 | uint32_t speed;
140 |
141 | uint16_t idVendor;
142 | uint16_t idProduct;
143 | uint16_t bcdDevice;
144 |
145 | uint8_t bDeviceClass;
146 | uint8_t bDeviceSubClass;
147 | uint8_t bDeviceProtocol;
148 | uint8_t bConfigurationValue;
149 | uint8_t bNumConfigurations;
150 | uint8_t bNumInterfaces;
151 | });
152 |
153 | #define to_string(s) #s
154 |
155 | void dump_usb_interface(struct usbip_usb_interface *);
156 | void dump_usb_device(struct usbip_usb_device *);
157 | #ifndef USBIP_WITH_LIBUSB
158 | int read_usb_device(struct udev_device *sdev, struct usbip_usb_device *udev);
159 | int read_attr_value(struct udev_device *dev, const char *name,
160 | const char *format);
161 | int read_usb_interface(struct usbip_usb_device *udev, int i,
162 | struct usbip_usb_interface *uinf);
163 | #endif
164 |
165 | const char *usbip_speed_string(int num);
166 | const char *usbip_status_string(int32_t status);
167 |
168 | int usbip_names_init(char *);
169 | void usbip_names_free(void);
170 | void usbip_names_get_product(char *buff, size_t size, uint16_t vendor,
171 | uint16_t product);
172 | void usbip_names_get_class(char *buff, size_t size, uint8_t clazz,
173 | uint8_t subclass, uint8_t protocol);
174 |
175 | extern struct usbip_connection_operations usbip_conn_ops;
176 |
177 | static inline struct usbip_sock *
178 | usbip_conn_open(const char *host, const char *port)
179 | {
180 | struct usbip_sock *sock;
181 |
182 | sock = usbip_conn_ops.open(host, port, usbip_conn_ops.opt);
183 |
184 | #ifndef USBIP_WITH_LIBUSB
185 | if (sock)
186 | usbip_ux_setup(sock);
187 | #endif
188 | return sock;
189 | }
190 |
191 | static inline void
192 | usbip_conn_close(struct usbip_sock *sock)
193 | {
194 | usbip_conn_ops.close(sock);
195 | #ifndef USBIP_WITH_LIBUSB
196 | usbip_ux_cleanup(sock);
197 | #endif
198 | }
199 |
200 | #endif /* __USBIP_COMMON_H */
201 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef __USBIP_CONFIG_H
19 | #define __USBIP_CONFIG_H
20 |
21 | #ifdef HAVE_CONFIG_H
22 |
23 | #include "../config.h"
24 |
25 | #if !HAVE_DAEMON
26 | #define USBIP_OS_NO_DAEMON
27 | #endif
28 |
29 | #if HAVE_DECL_CONTAINER_OF
30 | #define USBIP_OS_HAVE_CONTAINER_OF
31 | #endif
32 |
33 | #if !HAVE_DECL_P_TMPDIR
34 | #define USBIP_OS_NO_P_TMPDIR
35 | #endif
36 |
37 | #if !HAVE_DIRENT_H
38 | #define USBIP_OS_NO_DIRENT_H
39 | #endif
40 |
41 | #if !HAVE_FORK
42 | #define USBIP_OS_NO_FORK
43 | #endif
44 |
45 | #if !HAVE_LIBUDEV_H
46 | #define USBIP_OS_NO_LIBUDEV
47 | #endif
48 |
49 | #if !HAVE_PTHREAD_H
50 | #define USBIP_OS_NO_PTHREAD_H
51 | #endif
52 |
53 | #if !HAVE_POLL_H
54 | #define USBIP_OS_NO_POLL_H
55 | #endif
56 |
57 | #if !HAVE_SYS_SOCKET_H
58 | #define USBIP_OS_NO_SYS_SOCKET
59 | #endif
60 |
61 | #if !HAVE_SYSLOG
62 | #define USBIP_OS_NO_SYSLOG
63 | #endif
64 |
65 | #if !HAVE_UNISTD_H
66 | #define USBIP_OS_NO_UNISTD_H
67 | #endif
68 |
69 | #endif /* HAVE_CONFIG_H */
70 |
71 | #endif /* !__USBIP_CONFIG_H */
72 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_device_driver.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Karol Kosik
3 | * 2015 Samsung Electronics
4 | * Author: Igor Kotrasinski
5 | *
6 | * Based on tools/usb/usbip/libsrc/usbip_host_driver.c, which is:
7 | * Copyright (C) 2011 matt mooney
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 .
22 | */
23 |
24 | #ifndef __USBIP_DEVICE_DRIVER_H
25 | #define __USBIP_DEVICE_DRIVER_H
26 |
27 | #include
28 | #include "usbip_common.h"
29 | #include "usbip_host_common.h"
30 | #include "list.h"
31 |
32 | extern struct usbip_host_driver device_driver;
33 |
34 | #endif /* __USBIP_DEVICE_DRIVER_H */
35 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_host_api.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_common.h"
19 | #include "usbip_host_common.h"
20 | #include "usbip_host_driver.h"
21 | #include "usbip_device_driver.h"
22 |
23 | int usbip_hdriver_set(int type)
24 | {
25 | switch (type) {
26 | case USBIP_HDRIVER_TYPE_HOST:
27 | usbip_hdriver = &host_driver;
28 | break;
29 | case USBIP_HDRIVER_TYPE_DEVICE:
30 | usbip_hdriver = &device_driver;
31 | break;
32 | default:
33 | err("unknown driver type to set %d", type);
34 | return -1;
35 | }
36 | return 0;
37 | }
38 |
39 | int usbip_bind_device(const char *busid)
40 | {
41 | if (!usbip_hdriver->ops.bind_device)
42 | return 0;
43 | return usbip_hdriver->ops.bind_device(busid);
44 | }
45 |
46 | int usbip_unbind_device(const char *busid)
47 | {
48 | if (!usbip_hdriver->ops.unbind_device)
49 | return 0;
50 | return usbip_hdriver->ops.unbind_device(busid);
51 | }
52 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_host_common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Samsung Electronics
3 | * Igor Kotrasinski
4 | * Krzysztof Opasiak
5 | * Copyright (C) 2015-2016 Nobuo Iwata
6 | *
7 | * Refactored from usbip_host_driver.c, which is:
8 | * Copyright (C) 2011 matt mooney
9 | * 2005-2007 Takahiro Hirofuchi
10 | *
11 | * This program is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 2 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * This program is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program. If not, see .
23 | */
24 |
25 | #ifndef __USBIP_HOST_COMMON_H
26 | #define __USBIP_HOST_COMMON_H
27 |
28 | #include "usbip_config.h"
29 |
30 | #include
31 | #ifdef USBIP_OS_NO_LIBUDEV
32 | struct udev_device {
33 | void *p;
34 | };
35 | #else
36 | #include
37 | #endif
38 | #include
39 | #include "list.h"
40 | #include "usbip_common.h"
41 |
42 | extern struct udev *udev_context;
43 |
44 | struct usbip_host_driver;
45 | struct usbip_exported_devices;
46 |
47 | struct usbip_host_driver_ops {
48 | int (*open)(void);
49 | void (*close)(void);
50 | int (*refresh_device_list)(struct usbip_exported_devices *edevs);
51 | void (*free_device_list)(struct usbip_exported_devices *edevs);
52 | struct usbip_exported_device * (*get_device)(
53 | struct usbip_exported_devices *edevs,
54 | const char *busid);
55 |
56 | int (*list_devices)(struct usbip_usb_device **udevs);
57 | int (*bind_device)(const char *busid);
58 | int (*unbind_device)(const char *busid);
59 | int (*export_device)(struct usbip_exported_device *edev,
60 | struct usbip_sock *sock);
61 | int (*try_transfer)(struct usbip_exported_device *edev,
62 | struct usbip_sock *sock);
63 | int (*has_transferred)(void);
64 |
65 | int (*read_device)(struct udev_device *sdev,
66 | struct usbip_usb_device *dev);
67 | int (*read_interface)(struct usbip_usb_device *udev, int i,
68 | struct usbip_usb_interface *uinf);
69 | int (*is_my_device)(struct udev_device *udev);
70 | };
71 |
72 | struct usbip_host_driver {
73 | const char *udev_subsystem;
74 | struct usbip_host_driver_ops ops;
75 | };
76 |
77 | extern struct usbip_host_driver *usbip_hdriver;
78 |
79 | struct usbip_exported_devices {
80 | int ndevs;
81 | struct list_head edev_list;
82 | void *data;
83 | };
84 |
85 | struct usbip_exported_device {
86 | struct udev_device *sudev;
87 | int32_t status;
88 | struct usbip_usb_device udev;
89 | struct list_head node;
90 | struct usbip_usb_interface uinf[];
91 | };
92 |
93 | /* External API to access the driver */
94 | static inline int usbip_driver_open(void)
95 | {
96 | if (!usbip_hdriver->ops.open)
97 | return -EOPNOTSUPP;
98 | return usbip_hdriver->ops.open();
99 | }
100 |
101 | static inline void usbip_driver_close(void)
102 | {
103 | if (!usbip_hdriver->ops.close)
104 | return;
105 | usbip_hdriver->ops.close();
106 | }
107 |
108 | static inline int usbip_refresh_device_list(
109 | struct usbip_exported_devices *edevs)
110 | {
111 | if (!usbip_hdriver->ops.refresh_device_list)
112 | return -EOPNOTSUPP;
113 | return usbip_hdriver->ops.refresh_device_list(edevs);
114 | }
115 |
116 | static inline int usbip_free_device_list(
117 | struct usbip_exported_devices *edevs)
118 | {
119 | if (!usbip_hdriver->ops.refresh_device_list)
120 | return -EOPNOTSUPP;
121 | return usbip_hdriver->ops.refresh_device_list(edevs);
122 | }
123 |
124 | static inline struct usbip_exported_device *usbip_get_device(
125 | struct usbip_exported_devices *edevs,
126 | const char *busid)
127 | {
128 | if (!usbip_hdriver->ops.get_device)
129 | return NULL;
130 | return usbip_hdriver->ops.get_device(edevs, busid);
131 | }
132 |
133 | static inline int usbip_list_devices(struct usbip_usb_device **udevs)
134 | {
135 | if (!usbip_hdriver->ops.list_devices)
136 | return -1;
137 | return usbip_hdriver->ops.list_devices(udevs);
138 | }
139 |
140 | static inline int usbip_export_device(struct usbip_exported_device *edev,
141 | struct usbip_sock *sock)
142 | {
143 | if (!usbip_hdriver->ops.export_device)
144 | return -1;
145 | return usbip_hdriver->ops.export_device(edev, sock);
146 | }
147 |
148 | static inline int usbip_try_transfer(struct usbip_exported_device *edev,
149 | struct usbip_sock *sock)
150 | {
151 | if (!usbip_hdriver->ops.try_transfer)
152 | return -1;
153 | return usbip_hdriver->ops.try_transfer(edev, sock);
154 | }
155 |
156 | static inline int usbip_has_transferred(void)
157 | {
158 | if (!usbip_hdriver->ops.has_transferred)
159 | return -1;
160 | return usbip_hdriver->ops.has_transferred();
161 | }
162 |
163 | /* Helper functions for implementing driver backend */
164 | int usbip_generic_driver_open(void);
165 | void usbip_generic_driver_close(void);
166 | int usbip_generic_refresh_device_list(struct usbip_exported_devices *edevs);
167 | void usbip_generic_free_device_list(struct usbip_exported_devices *edevs);
168 | struct usbip_exported_device *usbip_generic_get_device(
169 | struct usbip_exported_devices *edevs,
170 | const char *busid);
171 | int usbip_generic_list_devices(struct usbip_usb_device **udevs);
172 | int usbip_generic_bind_device(const char *busid);
173 | int usbip_generic_unbind_device(const char *busid);
174 | int usbip_generic_export_device(
175 | struct usbip_exported_device *edev,
176 | struct usbip_sock *sock);
177 | int usbip_generic_try_transfer(
178 | struct usbip_exported_device *edev,
179 | struct usbip_sock *sock);
180 | int usbip_generic_has_transferred(void);
181 |
182 | #endif /* __USBIP_HOST_COMMON_H */
183 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_host_driver.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Samsung Electronics
5 | * Igor Kotrasinski
6 | * Krzysztof Opasiak
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 |
22 | #include
23 | #include
24 |
25 | #include "usbip_host_common.h"
26 | #include "usbip_host_driver.h"
27 |
28 | #undef PROGNAME
29 | #define PROGNAME "libusbip"
30 |
31 | static int is_my_device(struct udev_device *dev)
32 | {
33 | const char *driver;
34 |
35 | driver = udev_device_get_driver(dev);
36 | return driver != NULL && !strcmp(driver, USBIP_HOST_DRV_NAME);
37 | }
38 |
39 | static int usbip_host_driver_open(void)
40 | {
41 | int ret;
42 |
43 | ret = usbip_generic_driver_open();
44 | if (ret)
45 | err("please load " USBIP_CORE_MOD_NAME ".ko and "
46 | USBIP_HOST_DRV_NAME ".ko!");
47 | return ret;
48 | }
49 |
50 | struct usbip_host_driver host_driver = {
51 | .udev_subsystem = "usb",
52 | .ops = {
53 | .open = usbip_host_driver_open,
54 | .close = usbip_generic_driver_close,
55 | .refresh_device_list = usbip_generic_refresh_device_list,
56 | .free_device_list = usbip_generic_free_device_list,
57 | .get_device = usbip_generic_get_device,
58 | .list_devices = usbip_generic_list_devices,
59 | .bind_device = usbip_generic_bind_device,
60 | .unbind_device = usbip_generic_unbind_device,
61 | .export_device = usbip_generic_export_device,
62 | .try_transfer = usbip_generic_try_transfer,
63 | .has_transferred = usbip_generic_has_transferred,
64 | .read_device = read_usb_device,
65 | .read_interface = read_usb_interface,
66 | .is_my_device = is_my_device,
67 | },
68 | };
69 |
70 | struct usbip_host_driver *usbip_hdriver = &host_driver;
71 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_host_driver.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Samsung Electronics
5 | * Igor Kotrasinski
6 | * Krzysztof Opasiak
7 | *
8 | * This program is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program. If not, see .
20 | */
21 |
22 | #ifndef __USBIP_HOST_DRIVER_H
23 | #define __USBIP_HOST_DRIVER_H
24 |
25 | #include
26 | #include "usbip_common.h"
27 | #include "list.h"
28 | #include "usbip_host_common.h"
29 |
30 | extern struct usbip_host_driver host_driver;
31 |
32 | #endif /* __USBIP_HOST_DRIVER_H */
33 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/usbip_ux.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | /*
19 | * USB/IP URB transmission in userspace.
20 | */
21 |
22 | #ifndef __USBIP_UX_H
23 | #define __USBIP_UX_H
24 |
25 | #include
26 | #include
27 |
28 | struct usbip_ux {
29 | struct usbip_sock *sock;
30 | int devfd;
31 | int started;
32 | pthread_t tx, rx;
33 | struct usbip_ux_kaddr kaddr;
34 | };
35 |
36 | struct usbip_sock;
37 |
38 | int usbip_ux_setup(struct usbip_sock *sock);
39 | void usbip_ux_cleanup(struct usbip_sock *sock);
40 | int usbip_ux_try_transfer(struct usbip_sock *sock);
41 | void usbip_ux_interrupt(struct usbip_sock *sock);
42 | void usbip_ux_interrupt_pgrp(void);
43 | int usbip_ux_installed(void);
44 |
45 | #endif /* !__USBIP_UX_H */
46 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libsrc/vhci_driver.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2005-2007 Takahiro Hirofuchi
3 | */
4 |
5 | #ifndef __VHCI_DRIVER_H
6 | #define __VHCI_DRIVER_H
7 |
8 | #include
9 | #include
10 |
11 | #include "usbip_common.h"
12 |
13 | #define USBIP_VHCI_BUS_TYPE "platform"
14 |
15 | int usbip_vhci_driver_open(void);
16 | void usbip_vhci_driver_close(void);
17 |
18 | int usbip_vhci_get_free_port(void);
19 | int usbip_vhci_find_device(const char *host, const char *busid);
20 |
21 | /* will be removed */
22 | int usbip_vhci_attach_device(int port, int sockfd, uint8_t busnum,
23 | uint8_t devnum, uint32_t speed);
24 | int usbip_vhci_detach_device(int port);
25 |
26 | int usbip_vhci_create_record(const char *host, const char *port,
27 | const char *busid, int rhport);
28 | int usbip_vhci_delete_record(int rhport);
29 |
30 | int usbip_vhci_imported_devices_dump(void);
31 |
32 | #endif /* __VHCI_DRIVER_H */
33 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/Makefile.am:
--------------------------------------------------------------------------------
1 | SUBDIRS := stub libsrc src
2 |
3 | dist_man_MANS := $(addprefix doc/, usbip_libusb.8 usbipd_libusb.8)
4 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -x
2 |
3 | #aclocal
4 | #autoheader
5 | #libtoolize --copy --force
6 | #automake-1.9 -acf
7 | #autoconf
8 |
9 | autoreconf -i -f -v
10 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/cleanup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | if [ -r Makefile ]; then
4 | make distclean
5 | fi
6 |
7 | FILES="aclocal.m4 autom4te.cache compile config.guess config.h.in config.log \
8 | config.status config.sub configure cscope.out depcomp install-sh \
9 | poco/Makefile poco/Makefile.in libtool ltmain.sh Makefile \
10 | Makefile.in missing"
11 |
12 | rm -vRf $FILES
13 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/configure.ac:
--------------------------------------------------------------------------------
1 | dnl Process this file with autoconf to produce a configure script.
2 |
3 | AC_PREREQ(2.59)
4 | AC_INIT([usbip-utils-libusb], [0.1.0], [linux-usb@vger.kernel.org])
5 | AC_DEFINE([USBIP_VERSION], [0x00000111], [binary-coded decimal version number])
6 |
7 | CURRENT=0
8 | REVISION=1
9 | AGE=0
10 | AC_SUBST([LIBUSBIP_VERSION], [$CURRENT:$REVISION:$AGE], [library version])
11 |
12 | AC_CONFIG_HEADERS([config.h])
13 |
14 | AM_INIT_AUTOMAKE([foreign subdir-objects])
15 | LT_INIT
16 |
17 | # Silent build for automake >= 1.11
18 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
19 |
20 | AC_SUBST([EXTRA_CFLAGS], ["-Wall -Werror -Wextra -std=gnu99"])
21 |
22 | # Checks for programs.
23 | AC_PROG_CC
24 | AC_PROG_INSTALL
25 | AC_PROG_MAKE_SET
26 |
27 | # Checks for header files.
28 | AC_HEADER_DIRENT
29 | AC_HEADER_STDC
30 | AC_CHECK_HEADERS([arpa/inet.h fcntl.h libudev.h netdb.h netinet/in.h dnl
31 | pthread.h poll.h stdint.h stdlib.h dnl
32 | string.h sys/socket.h syslog.h unistd.h])
33 |
34 | # Checks for typedefs, structures, and compiler characteristics.
35 | AC_TYPE_INT32_T
36 | AC_TYPE_SIZE_T
37 | AC_TYPE_SSIZE_T
38 | AC_TYPE_UINT16_T
39 | AC_TYPE_UINT32_T
40 | AC_TYPE_UINT8_T
41 |
42 | # Checks for declarations.
43 | AC_CHECK_DECLS([container_of])
44 | AC_CHECK_DECLS([P_tmpdir])
45 |
46 | # Checks for library functions.
47 | AC_FUNC_REALLOC
48 | AC_CHECK_FUNCS([daemon fork memset mkdir regcomp socket strchr dnl
49 | strerror strstr strtoul syslog])
50 |
51 | # Checks libusb
52 | AC_CHECK_HEADER([libusb-1.0/libusb.h],
53 | [AC_CHECK_LIB([usb-1.0], [main],
54 | [LIBS="$LIBS -lusb-1.0"],
55 | [AC_MSG_ERROR([libusb-1.0 not found!])])],
56 | [AC_MSG_ERROR([Missing libusb-1.0/libusb.h])])
57 |
58 | # Checks usage of empty struct
59 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([
60 | #include
61 | struct s {} v;
62 | int main(void) { return printf("%p", &v); }])],
63 | [AC_MSG_RESULT([passed empty struct test])],
64 | [AC_MSG_RESULT([failed empty struct test])
65 | AC_DEFINE([USBIP_OS_NO_EMPTY_STRUCT],
66 | [1], [usage of empty struct])])
67 |
68 | # Checks container_of
69 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([
70 | #include
71 | struct s { int a, b; } v;
72 | int main(void) {
73 | struct s *p = container_of(&v.a, struct s, a);
74 | return printf("%p", p);
75 | }])],
76 | [AC_MSG_RESULT([have container_of])
77 | AC_DEFINE([USBIP_OS_HAVE_CONTAINER_OF],
78 | [1], [usage of container_of])],
79 | [AC_MSG_RESULT([no container_of])])
80 |
81 | # Checks for libwrap library.
82 | AC_MSG_CHECKING([whether to use the libwrap (TCP wrappers) library])
83 | AC_ARG_WITH([tcp-wrappers],
84 | [AS_HELP_STRING([--with-tcp-wrappers],
85 | [use the libwrap (TCP wrappers) library])],
86 | dnl [ACTION-IF-GIVEN]
87 | [if test "$withval" = "yes"; then
88 | AC_MSG_RESULT([yes])
89 | AC_MSG_CHECKING([for hosts_access in -lwrap])
90 | saved_LIBS="$LIBS"
91 | LIBS="-lwrap $saved_LIBS"
92 | AC_TRY_LINK(
93 | [int hosts_access(); int allow_severity, deny_severity;],
94 | [hosts_access()],
95 | [AC_MSG_RESULT([yes]);
96 | AC_DEFINE([HAVE_LIBWRAP], [1],
97 | [use tcp wrapper]) wrap_LIB="-lwrap"],
98 | [AC_MSG_RESULT([not found]); exit 1])
99 | else
100 | AC_MSG_RESULT([no]);
101 | fi],
102 | dnl [ACTION-IF-NOT-GIVEN]
103 | [AC_MSG_RESULT([(default)])
104 | AC_MSG_CHECKING([for hosts_access in -lwrap])
105 | saved_LIBS="$LIBS"
106 | LIBS="-lwrap $saved_LIBS"
107 | AC_TRY_LINK(
108 | [int hosts_access(); int allow_severity, deny_severity;],
109 | [hosts_access()],
110 | [AC_MSG_RESULT([yes]);
111 | AC_DEFINE([HAVE_LIBWRAP], [1], [use tcp wrapper])],
112 | [AC_MSG_RESULT([no]); LIBS="$saved_LIBS"])])
113 |
114 | # Sets directory containing usb.ids.
115 | AC_ARG_WITH([usbids-dir],
116 | [AS_HELP_STRING([--with-usbids-dir=DIR],
117 | [where usb.ids is found (default /usr/share/hwdata/)])],
118 | [USBIDS_DIR=$withval], [USBIDS_DIR="/usr/share/hwdata/"])
119 | AC_SUBST([USBIDS_DIR])
120 |
121 | # use _FORTIFY_SOURCE
122 | AC_MSG_CHECKING([whether to use fortify])
123 | AC_ARG_WITH([fortify],
124 | [AS_HELP_STRING([--with-fortify],
125 | [use _FORTIFY_SROUCE option when compiling)])],
126 | dnl [ACTION-IF-GIVEN]
127 | [if test "$withval" = "yes"; then
128 | AC_MSG_RESULT([yes])
129 | CFLAGS="$CFLAGS -D_FORTIFY_SOURCE -O"
130 | else
131 | AC_MSG_RESULT([no])
132 | CFLAGS="$CFLAGS -U_FORTIFY_SOURCE"
133 | fi
134 | ],
135 | dnl [ACTION-IF-NOT-GIVEN]
136 | [AC_MSG_RESULT([default])])
137 |
138 | # use dummy device driver
139 | AC_MSG_CHECKING([whether to use dummy driver])
140 | AC_ARG_WITH([dummy-driver],
141 | [AS_HELP_STRING([--with-dummy-driver],
142 | [use dummy device driver instead of vUDC ])],
143 | dnl [ACTION-IF-GIVEN]
144 | [if test "$withval" = "yes"; then
145 | dummy_driver=yes
146 | else
147 | dummy_driver=no
148 | fi
149 | ],
150 | dnl [ACTION-IF-NOT-GIVEN]
151 | dummy_driver=no)
152 | AC_MSG_RESULT([$dummy_driver])
153 | AM_CONDITIONAL([USE_DUMMY_DRIVER], [test x$dummy_driver = xyes])
154 |
155 | AC_CONFIG_FILES([Makefile stub/Makefile
156 | libsrc/Makefile src/Makefile])
157 | AC_OUTPUT
158 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/doc/usbip_libusb.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "June 2015" "usbip_libusb" "System Administration Utilities"
2 | .SH NAME
3 | usbip_libusb \- manage USB/IP devices
4 | .SH SYNOPSIS
5 | .B usbip_libusb
6 | [\fIoptions\fR] <\fIcommand\fR> <\fIargs\fR>
7 |
8 | .SH DESCRIPTION
9 | On a USB/IP device side computer,
10 | lists local devices, makes a device importable, makes not importable,
11 | connects a device and disconnects a device.
12 |
13 | This commnad is an alternate of usbip command with libusb instead of native linux USB/IP drivers.
14 |
15 | .SH OPTIONS
16 | .HP
17 | \fB\-\-debug\fR
18 | .IP
19 | Print debugging information.
20 | .PP
21 |
22 | .HP
23 | \fB\-\-log\fR
24 | .IP
25 | Log to syslog.
26 | .PP
27 |
28 | .HP
29 | \fB\-\-tcp-port PORT\fR
30 | .IP
31 | TCP port number used by remote usbip daemon. Default is 3240.
32 | .PP
33 |
34 | .SH COMMANDS
35 | .HP
36 | \fBversion\fR
37 | .IP
38 | Show version and exit.
39 | .PP
40 |
41 | .HP
42 | \fBhelp\fR [\fIcommand\fR]
43 | .IP
44 | Print the program help message, or help on a specific command, and
45 | then exit.
46 | .PP
47 |
48 | .HP
49 | \fBconnect\fR \-\-remote=<\fIhost\fR> \-\-busid=<\fIbusid\fR>
50 | .IP
51 | Connect a USB device to remote computer.
52 | .PP
53 |
54 | .HP
55 | \fBdisconnect\fR \-\-remote=<\fIhost\fR> \-\-busid=<\fIbusid\fR>
56 | .IP
57 | Disconnect a USB device from remote computer. It allows to disconnet from a computer which issued connect operation.
58 | .PP
59 |
60 | .HP
61 | \fBbind\fR \-\-busid=<\fIbusid\fR>
62 | .IP
63 | Make a USB device importable from remote computer.
64 | .PP
65 |
66 | .HP
67 | \fBunbind\fR \-\-busid=<\fIbusid\fR>
68 | .IP
69 | Make a USB device not importable so it can be used by a local driver.
70 | .PP
71 |
72 | .HP
73 | \fBlist\fR \-\-local
74 | .IP
75 | List local USB devices.
76 | .PP
77 |
78 | .HP
79 | \fBport\fR
80 | .IP
81 | List imported USB devices.
82 | .PP
83 |
84 |
85 | .SH ARGUMENTS
86 | .HP
87 | \fB\-rHOST\fR, \fB\-\-remote HOST\fR
88 | .IP
89 | Remote host address.
90 | .PP
91 |
92 | .HP
93 | \fB\-bBUSID\fR, \fB\-\-busid BUSID\fR
94 | .IP
95 | Bus ID of a device to be handled.
96 | .PP
97 |
98 | .HP
99 | \fB\-l\fR, \fB\-\-local\fR
100 | .IP
101 | Target local devices.
102 | .PP
103 |
104 | .HP
105 | \fB\-p\fR, \fB\-\-parsable\fR
106 | .IP
107 | Parsable format.
108 | .PP
109 |
110 |
111 | .SH EXAMPLES
112 |
113 | dev: at a device side computer
114 | .br
115 | app: at an application side computer
116 |
117 | Attach a device from a remote computer
118 | dev:# usbipd_libusb
119 | - Start daemon.
120 | dev:# usbip_libusb list
121 | - List local USB devices.
122 | dev:# usbip_libusb bind --busid=1-2
123 | - Make a USB device importable from a remote computer.
124 | app:# usbip list --remote=172.1.2.3
125 | - List importable USB devices on the computer.
126 | app:# usbip attach --remote=172.1.2.3 --busid=1-2
127 | - Import a remote USB device.
128 | app:# usbip port
129 | - List imported USB devices.
130 | app:# usbip detach --port=0
131 | - Detach the USB device.
132 | dev:# usbip_libusb unbind --busid=1-2
133 | - Make a USB device not importable, then release to local.
134 |
135 | Connect a device to a remote computer
136 | app:# usbipa
137 | - Start daemon.
138 | dev:# usbip_libusb list
139 | - List local USB devices.
140 | dev:# usbip_libusb connect --remote=172.4.5.6 --busid=1-2
141 | - Export a USB device to a remote computer.
142 | dev:# usbip_libusb disconnect --remote=172.4.5.6 --busid=1-2
143 | - Unxport a USB device from a remote computer.
144 |
145 |
146 | .SH "SEE ALSO"
147 | \fBusbipd_libusb\fP\fB(8)\fB\fP
148 | \fBusbip\fP\fB(8)\fB\fP
149 | \fBusbipa\fP\fB(8)\fB\fP
150 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/doc/usbipd_libusb.8:
--------------------------------------------------------------------------------
1 | .TH USBIP "8" "June 2015" "usbip_libusb" "System Administration Utilities"
2 | .SH NAME
3 | usbipd_libusb \- USB/IP device side daemon
4 | .SH SYNOPSIS
5 | .B usbipd_libusb
6 | [\fIoptions\fR]
7 |
8 | .SH DESCRIPTION
9 | .B usbipd_libusb
10 | runs on a divice side computer and provides USB/IP access from remote computers.
11 |
12 | To make devices accessible from remote computers, they must be made importable using \fBusbip_libusb bind\fR.
13 |
14 | This is an alternate of usbipd with libusb instead of native linux USB/IP drivers.
15 |
16 | .SH OPTIONS
17 | .HP
18 | \fB\-4\fR, \fB\-\-ipv4\fR
19 | .IP
20 | Bind to IPv4. Default is both.
21 | .PP
22 |
23 | .HP
24 | \fB\-6\fR, \fB\-\-ipv6\fR
25 | .IP
26 | Bind to IPv6. Default is both.
27 | .PP
28 |
29 | .HP
30 | \fB\-D\fR, \fB\-\-daemon\fR
31 | .IP
32 | Run as a daemon process.
33 | .PP
34 |
35 | .HP
36 | \fB\-d\fR, \fB\-\-debug\fR
37 | .IP
38 | Print debugging information.
39 | .PP
40 |
41 | .HP
42 | \fB\-PFILE\fR, \fB\-\-pid FILE\fR
43 | .IP
44 | Write process id to FILE.
45 | .br
46 | If no FILE specified, use /var/run/usbipd.pid
47 | .PP
48 |
49 | \fB\-tPORT\fR, \fB\-\-tcp\-port PORT\fR
50 | .IP
51 | Listen on TCP/IP port PORT. Default is 3240.
52 | .PP
53 |
54 | \fB\-h\fR, \fB\-\-help\fR
55 | .IP
56 | Print the program help message and exit.
57 | .PP
58 |
59 | .HP
60 | \fB\-v\fR, \fB\-\-version\fR
61 | .IP
62 | Show version.
63 | .PP
64 |
65 | .SH LIMITATIONS
66 |
67 | .B usbipd
68 | offers no authentication or authorization for USB/IP. Any
69 | USB/IP client can connect and use exported devices.
70 |
71 | .SH EXAMPLES
72 |
73 | dev:# usbipd_libusb -D
74 | - Start usbip daemon.
75 |
76 | dev:# usbip_libusb list --local
77 | - List driver assignments for usb devices.
78 |
79 | dev:# usbip_libusb bind --busid=1-2
80 | - Bind usbip-host.ko to the device of busid 1-2.
81 | - USB device 1-2 is now importable from other computer!
82 |
83 | dev:# usbip_libusb unbind --busid=1-2
84 | - Unind usbip-host.ko from the device of busid 1-2.
85 | - USB device 1-2 is not importable from other computer.
86 |
87 | .SH "SEE ALSO"
88 | \fBusbip_libusb\fP\fB(8)\fB\fP
89 | \fBusbip\fP\fB(8)\fB\fP
90 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/libsrc/Makefile.am:
--------------------------------------------------------------------------------
1 | libusbip_libusb_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
2 | libusbip_libusb_la_CFLAGS = -DDEBUG -DUSBIP_WITH_LIBUSB @EXTRA_CFLAGS@ \
3 | -I$(top_srcdir)/os -I$(top_srcdir)/../libsrc
4 | libusbip_libusb_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@
5 |
6 | if USE_DUMMY_DRIVER
7 | DEV_DRV = ../../libsrc/usbip_device_driver.h \
8 | ./dummy_device_driver.c
9 | else
10 | DEV_DRV = ../../libsrc/usbip_host_common.h \
11 | ../../libsrc/usbip_host_common.c \
12 | ../../libsrc/usbip_device_driver.h \
13 | ../../libsrc/usbip_device_driver.c \
14 | ../../libsrc/usbip_ux.h \
15 | ../../libsrc/usbip_ux.c \
16 | ../../libsrc/sysfs_utils.h \
17 | ../../libsrc/sysfs_utils.c
18 | endif
19 |
20 | lib_LTLIBRARIES = libusbip_libusb.la
21 | libusbip_libusb_la_SOURCES = \
22 | ../../libsrc/names.h \
23 | ../../libsrc/names.c \
24 | ../../libsrc/usbip_common.h \
25 | ../../libsrc/usbip_common.c \
26 | ../../libsrc/usbip_host_api.c \
27 | $(DEV_DRV)
28 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/libsrc/dummy_device_driver.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation; either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "usbip_host_common.h"
19 |
20 | static int dummy_driver_open(void)
21 | {
22 | info("dummy_driver_open");
23 | return -1;
24 | }
25 |
26 | static void dummy_driver_close(void)
27 | {
28 | info("dummy_driver_close");
29 | }
30 |
31 | static int dummy_refresh_device_list(struct usbip_exported_devices *edevs)
32 | {
33 | info("dummy_refresh_device_list %p", edevs);
34 | return -1;
35 | }
36 |
37 | static void dummy_free_device_list(struct usbip_exported_devices *edevs)
38 | {
39 | info("dummy_free_device_list %p", edevs);
40 | }
41 |
42 | static struct usbip_exported_device *dummy_get_device(
43 | struct usbip_exported_devices *edevs,
44 | const char *busid)
45 | {
46 | info("dummy_get_device %p %s", edevs, busid);
47 | return NULL;
48 | }
49 |
50 | static int dummy_list_devices(struct usbip_usb_device **udevs)
51 | {
52 | info("dummy_get_device %p", udevs);
53 | return -1;
54 | }
55 |
56 | static int dummy_export_device(struct usbip_exported_device *edev,
57 | struct usbip_sock *sock)
58 | {
59 | info("dummy_get_device %p %p", edev, sock);
60 | return -1;
61 | }
62 |
63 | /* do not use gcc initialization syntax for other compilers */
64 | struct usbip_host_driver device_driver = {
65 | "dummy-device",
66 | {
67 | dummy_driver_open,
68 | dummy_driver_close,
69 | dummy_refresh_device_list,
70 | dummy_free_device_list,
71 | dummy_get_device,
72 | dummy_list_devices,
73 | NULL, /* bind */
74 | NULL, /* unbind */
75 | dummy_export_device,
76 | NULL, /* transfer */
77 | NULL, /* has_transferred */
78 | NULL, /* read_device */
79 | NULL, /* read_interface */
80 | NULL /* is_my_device */
81 | },
82 | };
83 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/darwin/BUILD:
--------------------------------------------------------------------------------
1 | 1) Prepare libtool
2 |
3 | Download autoconf, automake and libtools.
4 | 'sudo make install' them.
5 |
6 | 2) Prepare usb.ids
7 |
8 | Copy from /usr/share/hwdata/ or downloaded from net.
9 |
10 | 3) Compile with libusb
11 |
12 | $ cd /tools/usb/usbip/libusb/
13 | $ ./autogen.sh
14 | $ ./configure CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib \
15 | --with-usbids-dir= --with-dummy-driver
16 | $ make
17 | $ sudo make install
18 |
19 | [EOF]
20 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/darwin/README:
--------------------------------------------------------------------------------
1 | Still debugging.
2 |
3 | 1. Problems
4 |
5 | 1) libusb_claim_interface() fails with LIBUSB_ERROR_ACCESS(-3)
6 |
7 | OSX doesn't support libusb_detach_kernel_driver().
8 | It needs to be detached manually if it's hot plugged.
9 |
10 | 2) libusb_submit_transfer() fails with LIBUSB_ERROR_NOT_FOUND(-5)
11 |
12 | For USB storage, it can be claimed after ejected and unloaded
13 | com.apple.iokit.IOUSBMassStorage. But the device cannot be seen after
14 | successfully claimed.
15 |
16 | [EOF]
17 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/darwin/usbip_os.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef _USBIP_DARWIN_OS_H
19 | #define _USBIP_DARWIN_OS_H
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #define USBIP_OS_NO_DAEMON /* deplicated */
28 |
29 | #define SIGCLD SIGCHLD
30 |
31 | static inline int ppoll(struct pollfd *fds, nfds_t nfds,
32 | const struct timespec *timeout_ts,
33 | const sigset_t *sigmask)
34 | {
35 | sigset_t origmask;
36 | int ready, timeout;
37 |
38 | timeout = (timeout_ts == NULL) ? -1 :
39 | (timeout_ts->tv_sec * 1000 + timeout_ts->tv_nsec / 1000000);
40 | sigprocmask(SIG_SETMASK, sigmask, &origmask);
41 | ready = poll(fds, nfds, timeout);
42 | sigprocmask(SIG_SETMASK, &origmask, NULL);
43 | return ready;
44 | }
45 |
46 | /*
47 | * Copied from /usr/include/linux/usb/ch9.h
48 | */
49 | enum usb_device_speed {
50 | USB_SPEED_UNKNOWN = 0, /* enumerating */
51 | USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
52 | USB_SPEED_HIGH, /* usb 2.0 */
53 | USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
54 | USB_SPEED_SUPER, /* usb 3.0 */
55 | };
56 |
57 | /*
58 | * Copied from /usr/include/linux/usbip.h
59 | */
60 | enum usbip_device_status {
61 | /* sdev is available. */
62 | SDEV_ST_AVAILABLE = 0x01,
63 | /* sdev is now used. */
64 | SDEV_ST_USED,
65 | /* sdev is unusable because of a fatal error. */
66 | SDEV_ST_ERROR,
67 |
68 | /* vdev does not connect a remote device. */
69 | VDEV_ST_NULL,
70 | /* vdev is used, but the USB address is not assigned yet */
71 | VDEV_ST_NOTASSIGNED,
72 | VDEV_ST_USED,
73 | VDEV_ST_ERROR
74 | };
75 |
76 | #endif /* !_USBIP_DARWIN_OS_H */
77 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/unix/BUILD:
--------------------------------------------------------------------------------
1 | 1) compile and install
2 |
3 | $ cd /tools/usb/usbip/libusb
4 | $ ./autogen.sh
5 | $ ./configure
6 | $ make
7 | # make install
8 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/usbip_os.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef _USBIP_OS_H
19 | #define _USBIP_OS_H
20 |
21 | #if defined(__unix__)
22 | #elif defined(__APPLE__)
23 | #include "darwin/usbip_os.h"
24 | #elif defined(_WIN32)
25 | #include "win32/usbip_os.h"
26 | #else
27 | #error "unimplemented os"
28 | #endif
29 |
30 | #endif /* !_USBIP_OS_H */
31 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/usbip_sock.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef _USBIP_SOCK_H
19 | #define _USBIP_SOCK_H
20 |
21 | /*
22 | * This header is needed to clear duplicate definition errors in windows.
23 | */
24 | #if defined(__unix__)
25 | #elif defined(__APPLE__)
26 | #elif defined(_WIN32)
27 | #include "win32/usbip_sock.h"
28 | #else
29 | #error "unimplemented os"
30 | #endif
31 |
32 | #endif /* !_USBIP_SOCK_H */
33 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/win32/BUILD:
--------------------------------------------------------------------------------
1 | VisualStudio solution structure example
2 |
3 | [For usbip and usbipd]
4 |
5 | $(SolutionDir)
6 | |
7 | +-getopt
8 | | Type: dll
9 | | Sources: getopt.c
10 | | Headers: getopt.h
11 | | NOTE: these files are excluded. Use GNU or compatible open source.
12 | |
13 | +-lib
14 | | Type: lib
15 | | Sources: usbip_network.c usbip_common.c usbip_host_api.c names.c
16 | | stub_*.c # from libusb/stub
17 | | dummy_device_driver.c # from libusb/libsrc
18 | | Headers: usbip_network.h usbip_common.h usbip_config.h
19 | | usbip_host_common.h usbip_host_driver.h usbip_device_driver.h
20 | | names.h list.h
21 | | stub_common.h stub.h # from libusb/stub
22 | | usbip_os.h usbip_sock.h # from libusb/os
23 | | Includes: $(SolutionDir);$(SolutionDir)\win32
24 | | Definitions: USBIP_WITH_LIBUSB;HAVE_CONFIG_H
25 | |
26 | +-libusb-1.0 (dll)
27 | | Added as existing project from \msvc\libusb_dll_.vcxproj
28 | | OutputDir: $(SolutionDir)$(Configuration)\
29 | |
30 | +-usbip
31 | | Type: exe
32 | | Sources: usbip.c usbip_bind.c usbip_connect.c usbip_disconnect.c
33 | | usbip_list.c usbip_unbind.c
34 | | Headers: usbip.h
35 | | Includes: $(SolutionDir);$(SolutionDir)\lib;$(SolutionDir)\getopt;
36 | | $(SolutionDir)\win32
37 | | Definitions: USBIP_WITH_LIBUSB;HAVE_CONFIG_H;USBIDS_FILE="..\\usb.ids"
38 | | Depending Files: ws2_32.lib
39 | | Reference: getopt;lib;libusb-1.0 (dll);win32
40 | |
41 | +-usbipd
42 | | Type: exe
43 | | Sources: usbipd.c usbipd_dev.c
44 | | Headers: usbipd.h
45 | | Includes: $(SolutionDir);$(SolutionDir)\lib;$(SolutionDir)\getopt;
46 | | $(SolutionDir)\win32
47 | | Definitions: USBIP_WITH_LIBUSB;HAVE_CONFIG_H
48 | | Depending Files: ws2_32.lib
49 | | Reference: getopt;lib;libusb-1.0 (dll);win32
50 | |
51 | +-win32
52 | | Headers: usbip_os.h usbip_sock.h # from libusb/os/win32
53 | |
54 | +linux
55 | | Headers: usbip_api.h # from include/uapi/linux
56 | |
57 | +-config.h
58 | | Copied from libusb/os/win32
59 | |
60 | +-usb.ids
61 | | Copied from /usr/share/hwdata/ or downloaded from net.
62 | | AccentAcute character must be modified to avoid invalid ascii exception.
63 | | ex) sed -i -e 's/\xb4/\x00/' usb.ids
64 | |
65 | +-libusb-1.0
66 | SYMLINK to \libusb
67 | ex) mklink /D libusb-1.0 \libusb
68 |
69 | NOTE:
70 | To support Windows 7 and Visual Studio 2012, programs must not be c99.
71 |
72 | Winsock headers must be included at first than any other headers.
73 | Please, check the position which includes usbip_sock.h if duplicated
74 | definition errors relating winsock headers occur.
75 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/win32/README:
--------------------------------------------------------------------------------
1 | Conditions
2 |
3 | 1) Tested with libusb-1.0.19 and 1.0.20
4 |
5 | Limitations
6 |
7 | 1) Isochronous transfer is not supported by libusb-1.0.19 nor 1.0.20.
8 | Patches enables isochronous has been send to libusb mailing list.
9 |
10 | 2) WinUSB (a generic USB driver) supports isochronous from Windows 8.1.
11 | Please, check "WinUSB (Winusb.sys)" page in Microsoft site.
12 |
13 | How to apply WinUSB
14 |
15 | 1) References
16 |
17 | [1] http://www.libusb.org/wiki/winusb_driver_installation
18 |
19 | This page shows detail how-to with screen capture and includes a link
20 | to winusb_driver.zip which contains installation DLLs and an template
21 | of INF files but may not up-to-date.
22 |
23 | [2] "WinUSB (Winusb.sys) Installation" page in Microsoft site.
24 |
25 | 2) Create a working directory
26 |
27 | ex) c:\winusb
28 |
29 | 3) Get installation DLLs
30 |
31 | Download and install Windows Driver Kit (WDK).
32 |
33 | C:\Program Files\Windows Kits\\Redist\wdf\ contains the DLLs.
34 |
35 | Copy them to the working directory
36 |
37 | 4) Find device in Device Manager
38 |
39 | View > Devices by connection
40 |
41 | 5) Check vendor ID and product ID
42 |
43 | At target device, right-click > properties > Detail > Hardware ID.
44 |
45 | 6) Prepare INF file
46 |
47 | Example can be found in Microsoft "WinUSB (Winusb.sys) Installation" page.
48 |
49 | a) DeviceName : arbitrary string
50 | b) VendorID : ID checked above.
51 | c) ProductID : ID checked above.
52 | d) DeviceInterfaceGUIDs : newly generated GUID
53 | with ex. VisualStudio > tools > Create GUID or createguid.com.
54 | e) Conform architecture strings NTamd64 / NTx86 to your machine.
55 |
56 | 5) Uninstall driver (option)
57 |
58 | If already a driver is installed, at target device's driver, right-click >
59 | uninstall. Otherwise error below may occur at applying INF file.
60 |
61 | "the folder you specified doesn't contain a compatible software driver
62 | for your device. If the folder contains a driver, make sure it is
63 | designed to work with windows for x64-based systems."
64 |
65 | 6) Apply INF file
66 |
67 | At target devie, right-click > Update driver software... >
68 | Browse my computer for driver software >
69 | Let me pick from a list of device drivers on my computer >
70 | Use disk, then specify INF file.
71 |
72 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/win32/copy_usbip_to_win32.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | DIR=`dirname $0`
4 | CMD=`basename $0`
5 |
6 | TOP=$DIR/../../..
7 | INC=$TOP/../../../include
8 | HWDATA=/usr/share/hwdata/
9 |
10 | if [ -z "$1" ]; then
11 | echo "Usage: $CMD "
12 | exit 1
13 | fi
14 |
15 | DST_SOL=$1
16 |
17 | DST_LIB=$DST_SOL/lib
18 | DST_USBIP=$DST_SOL/usbip
19 | DST_USBIPD=$DST_SOL/usbipd
20 | DST_WIN=$DST_SOL/win32
21 | DST_LINUX=$DST_SOL/linux
22 | DST_CFG=$DST_SOL
23 | DST_IDS=$DST_SOL/usb.ids
24 |
25 | # getopt.[ch] are excluded.
26 |
27 | FILES_LIB="\
28 | $TOP/src/usbip_network.[ch] \
29 | $TOP/libsrc/usbip_common.[ch] \
30 | $TOP/libsrc/usbip_host_api.c \
31 | $TOP/libsrc/usbip_config.h \
32 | $TOP/libsrc/usbip_host_common.h \
33 | $TOP/libsrc/usbip_host_driver.h \
34 | $TOP/libsrc/usbip_device_driver.h \
35 | $TOP/libsrc/names.[ch] \
36 | $TOP/libsrc/list.h \
37 | $TOP/libusb/stub/*.[ch] \
38 | $TOP/libusb/libsrc/dummy_device_driver.c \
39 | $TOP/libusb/os/usbip_os.h \
40 | $TOP/libusb/os/usbip_sock.h"
41 | FILES_USBIP="\
42 | $TOP/src/usbip.[ch] \
43 | $TOP/src/usbip_bind.c \
44 | $TOP/src/usbip_connect.c \
45 | $TOP/src/usbip_disconnect.c \
46 | $TOP/src/usbip_list.c \
47 | $TOP/src/usbip_unbind.c"
48 | FILES_USBIPD="\
49 | $TOP/src/usbipd.[ch] \
50 | $TOP/src/usbipd_dev.c"
51 | FILES_WIN="\
52 | $TOP/libusb/os/win32/usbip_os.h \
53 | $TOP/libusb/os/win32/usbip_sock.h"
54 | FILES_LINUX="\
55 | $INC/uapi/linux/usbip_api.h"
56 | FILE_CFG=$TOP/libusb/os/win32/config.h
57 | FILE_IDS=$HWDATA/usb.ids
58 |
59 | cp $FILES_LIB $DST_LIB
60 | cp $FILES_USBIP $DST_USBIP
61 | cp $FILES_USBIPD $DST_USBIPD
62 | cp $FILES_WIN $DST_WIN
63 | cp $FILES_LINUX $DST_LINUX
64 | cp $FILE_CFG $DST_CFG
65 |
66 | sed -e 's/\xb4/\x20/' $FILE_IDS > $DST_IDS
67 | echo "AccentAcute character(s) in $DST_IDS has been modified."
68 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/os/win32/usbip_sock.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015-2016 Nobuo Iwata
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef _USBIP_WIN32_SOCK_H
19 | #define _USBIP_WIN32_SOCK_H
20 |
21 | /*
22 | * This header is needed to clear duplicate definition errors in windows.
23 | */
24 | #include
25 | #include
26 |
27 | #endif /* !_USBIP_WIN32_SOCK_H */
28 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/src/Makefile.am:
--------------------------------------------------------------------------------
1 | AM_CPPFLAGS = -I$(top_srcdir)/../libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
2 | AM_CFLAGS = -DDEBUG -DUSBIP_WITH_LIBUSB @EXTRA_CFLAGS@ \
3 | -I$(top_srcdir)/../libsrc -I$(top_srcdir)/../src \
4 | -I$(top_srcdir)/libsrc -I$(top_srcdir)/os \
5 | -I$(top_srcdir)/stub
6 | LDADD = $(top_builddir)/libsrc/libusbip_libusb.la \
7 | $(top_builddir)/stub/libusbip_stub.la
8 |
9 | sbin_PROGRAMS := usbip_libusb usbipd_libusb
10 | lib_LTLIBRARIES := libusbipc_libusb.la libusbipd_libusb.la
11 |
12 | usbip_libusb_SOURCES := \
13 | ../../src/usbip.h \
14 | ../../src/usbip.c \
15 | ../../src/usbip_network.c \
16 | ../../src/usbip_connect.c \
17 | ../../src/usbip_disconnect.c \
18 | ../../src/usbip_list.c \
19 | ../../src/usbip_bind.c \
20 | ../../src/usbip_unbind.c
21 | usbip_libusb_CFLAGS := $(AM_CFLAGS)
22 |
23 | usbipd_libusb_SOURCES := \
24 | ../../src/usbip_network.h \
25 | ../../src/usbipd.c \
26 | ../../src/usbipd_dev.c \
27 | ../../src/usbip_network.c
28 | usbipd_libusb_CFLAGS := $(AM_CFLAGS)
29 |
30 | libusbipc_libusb_la_SOURCES := \
31 | ../../src/usbip_network.c \
32 | ../../src/usbip_connect.c \
33 | ../../src/usbip_disconnect.c \
34 | ../../src/usbip_list.c
35 | libusbipc_libusb_la_CFLAGS := $(AM_CFLAGS) -DUSBIP_AS_LIBRARY
36 |
37 | libusbipd_libusb_la_SOURCES := \
38 | ../../src/usbipd.c \
39 | ../../src/usbipd_dev.c \
40 | ../../src/usbip_network.c
41 | libusbipd_libusb_la_CFLAGS := $(AM_CFLAGS) -DUSBIP_AS_LIBRARY
42 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/stub/Makefile.am:
--------------------------------------------------------------------------------
1 | libusbip_stub_la_CPPFLAGS =
2 | libusbip_stub_la_CFLAGS = -DDEBUG -DUSBIP_WITH_LIBUSB @EXTRA_CFLAGS@ \
3 | -I$(top_srcdir)/../libsrc \
4 | -I$(top_srcdir)/libsrc -I$(top_srcdir)/os
5 | libusbip_stub_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@ -lpthread -lusb-1.0
6 |
7 | lib_LTLIBRARIES = libusbip_stub.la
8 | libusbip_stub_la_SOURCES = stub_common.c stub_common.h \
9 | stub_main.c stub_dev.c stub_tx.c stub_rx.c stub_event.c stub.h
10 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/stub/stub.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Nobuo Iwata
3 | *
4 | * This is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation; either version 2 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef __USBIP_STUB_H
19 | #define __USBIP_STUB_H
20 |
21 | #include "usbip_config.h"
22 |
23 | #include
24 | #include
25 | #include
26 | #ifndef USBIP_OS_NO_PTHREAD_H
27 | #include
28 | #endif
29 | #include
30 | #include "usbip_host_common.h"
31 | #include "stub_common.h"
32 | #include "list.h"
33 |
34 | #define STUB_BUSID_OTHER 0
35 | #define STUB_BUSID_REMOV 1
36 | #define STUB_BUSID_ADDED 2
37 | #define STUB_BUSID_ALLOC 3
38 |
39 | struct stub_interface {
40 | struct usbip_usb_interface uinf;
41 | uint8_t detached;
42 | uint8_t claimed;
43 | };
44 |
45 | struct stub_endpoint {
46 | uint8_t nr;
47 | uint8_t dir; /* LIBUSB_ENDPOINT_IN || LIBUSB_ENDPOINT_OUT */
48 | uint8_t type; /* LIBUSB_TRANSFER_TYPE_ */
49 | };
50 |
51 | struct stub_device {
52 | libusb_device *dev;
53 | libusb_device_handle *dev_handle;
54 | struct usbip_usb_device udev;
55 | struct usbip_device ud;
56 | uint32_t devid;
57 | int num_eps;
58 | struct stub_endpoint *eps;
59 |
60 | pthread_t tx, rx;
61 |
62 | /*
63 | * stub_priv preserves private data of each urb.
64 | * It is allocated as stub_priv_cache and assigned to urb->context.
65 | *
66 | * stub_priv is always linked to any one of 3 lists;
67 | * priv_init: linked to this until the comletion of a urb.
68 | * priv_tx : linked to this after the completion of a urb.
69 | * priv_free: linked to this after the sending of the result.
70 | *
71 | * Any of these list operations should be locked by priv_lock.
72 | */
73 | pthread_mutex_t priv_lock;
74 | struct list_head priv_init;
75 | struct list_head priv_tx;
76 | struct list_head priv_free;
77 |
78 | /* see comments for unlinking in stub_rx.c */
79 | struct list_head unlink_tx;
80 | struct list_head unlink_free;
81 |
82 | pthread_mutex_t tx_waitq;
83 | int should_stop;
84 |
85 | struct stub_interface ifs[];
86 | };
87 |
88 | /* private data into urb->priv */
89 | struct stub_priv {
90 | unsigned long seqnum;
91 | struct list_head list;
92 | struct stub_device *sdev;
93 | struct libusb_transfer *trx;
94 |
95 | uint8_t dir;
96 | uint8_t unlinking;
97 | };
98 |
99 | struct stub_unlink {
100 | unsigned long seqnum;
101 | struct list_head list;
102 | enum libusb_transfer_status status;
103 | };
104 |
105 | /* same as SYSFS_BUS_ID_SIZE */
106 | #define BUSID_SIZE 32
107 |
108 | struct bus_id_priv {
109 | char name[BUSID_SIZE];
110 | char status;
111 | int interf_count;
112 | struct stub_device *sdev;
113 | char shutdown_busid;
114 | };
115 |
116 | struct stub_edev_data {
117 | libusb_device *dev;
118 | struct stub_device *sdev;
119 | int num_eps;
120 | struct stub_endpoint eps[];
121 | };
122 |
123 | /* stub_rx.c */
124 | void *stub_rx_loop(void *data);
125 |
126 | /* stub_tx.c */
127 | void stub_enqueue_ret_unlink(struct stub_device *sdev, uint32_t seqnum,
128 | enum libusb_transfer_status status);
129 | void LIBUSB_CALL stub_complete(struct libusb_transfer *trx);
130 | void *stub_tx_loop(void *data);
131 |
132 | /* for libusb */
133 | extern libusb_context *stub_libusb_ctx;
134 | uint8_t stub_get_transfer_type(struct stub_device *sdev, uint8_t ep);
135 | uint8_t stub_endpoint_dir(struct stub_device *sdev, uint8_t ep);
136 | int stub_endpoint_dir_out(struct stub_device *sdev, uint8_t ep);
137 | uint8_t stub_get_transfer_flags(uint32_t in);
138 |
139 | /* from stub_main.c */
140 | void stub_device_cleanup_transfers(struct stub_device *sdev);
141 | void stub_device_cleanup_unlinks(struct stub_device *sdev);
142 |
143 | #endif /* __USBIP_STUB_H */
144 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/stub/stub_event.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2003-2008 Takahiro Hirofuchi
3 | * Copyright (C) 2015 Nobuo Iwata
4 | *
5 | * This is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 2 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "stub.h"
20 |
21 | static unsigned long event_get(struct usbip_device *ud)
22 | {
23 | unsigned long event;
24 |
25 | pthread_mutex_lock(&ud->lock);
26 | event = ud->event;
27 | ud->event = 0;
28 | pthread_mutex_unlock(&ud->lock);
29 |
30 | return event;
31 | }
32 |
33 | static int event_handler(struct usbip_device *ud)
34 | {
35 | unsigned long event = event_get(ud);
36 |
37 | usbip_dbg_eh("enter event_handler\n");
38 |
39 | /*
40 | * Events are handled by only this thread.
41 | */
42 | usbip_dbg_eh("pending event %lx\n", event);
43 |
44 | /*
45 | * NOTE: shutdown must come first.
46 | * Shutdown the device.
47 | */
48 | if (event & USBIP_EH_SHUTDOWN)
49 | ud->eh_ops.shutdown(ud);
50 |
51 | /* Reset the device. */
52 | if (event & USBIP_EH_RESET)
53 | ud->eh_ops.reset(ud);
54 |
55 | /* Mark the device as unusable. */
56 | if (event & USBIP_EH_UNUSABLE)
57 | ud->eh_ops.unusable(ud);
58 |
59 | /* Stop the error handler. */
60 | if (event & USBIP_EH_BYE)
61 | return -1;
62 |
63 | return 0;
64 | }
65 |
66 | static void *event_handler_loop(void *data)
67 | {
68 | struct usbip_device *ud = (struct usbip_device *)data;
69 |
70 | while (!ud->eh_should_stop) {
71 | pthread_mutex_lock(&ud->eh_waitq);
72 | usbip_dbg_eh("wakeup\n");
73 |
74 | if (event_handler(ud) < 0)
75 | break;
76 | }
77 |
78 | return 0;
79 | }
80 |
81 | int usbip_start_eh(struct usbip_device *ud)
82 | {
83 | pthread_mutex_init(&ud->eh_waitq, NULL);
84 | ud->eh_should_stop = 0;
85 | ud->event = 0;
86 |
87 | if (pthread_create(&ud->eh, NULL, event_handler_loop, ud)) {
88 | pr_warn("Unable to start control thread\n");
89 | return -1;
90 | }
91 | return 0;
92 | }
93 |
94 | void usbip_stop_eh(struct usbip_device *ud)
95 | {
96 | usbip_dbg_eh("finishing usbip_eh\n");
97 | ud->eh_should_stop = 1;
98 | pthread_mutex_unlock(&ud->eh_waitq);
99 | }
100 |
101 | void usbip_join_eh(struct usbip_device *ud)
102 | {
103 | pthread_join(ud->eh, NULL);
104 | pthread_mutex_destroy(&ud->eh_waitq);
105 | }
106 |
107 | void usbip_event_add(struct usbip_device *ud, unsigned long event)
108 | {
109 | pthread_mutex_lock(&ud->lock);
110 | ud->event |= event;
111 | pthread_mutex_unlock(&ud->lock);
112 | pthread_mutex_unlock(&ud->eh_waitq);
113 | }
114 |
115 | int usbip_event_happened(struct usbip_device *ud)
116 | {
117 | int happened = 0;
118 |
119 | pthread_mutex_lock(&ud->lock);
120 | if (ud->event != 0)
121 | happened = 1;
122 | pthread_mutex_unlock(&ud->lock);
123 |
124 | return happened;
125 | }
126 |
--------------------------------------------------------------------------------
/tools/usb/usbip/libusb/stub/stub_main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2003-2008 Takahiro Hirofuchi
3 | * Copyright (C) 2015-2016 Nobuo Iwata
4 | *
5 | * This is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 2 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "stub.h"
20 |
21 | static struct stub_priv *stub_priv_pop_from_listhead(struct list_head *listhead)
22 | {
23 | struct list_head *pos, *tmp;
24 | struct stub_priv *priv;
25 |
26 | list_for_each_safe(pos, tmp, listhead) {
27 | priv = list_entry(pos, struct stub_priv, list);
28 | pr_warn("Found pending trx %p.\n", priv->trx);
29 | }
30 |
31 | return NULL;
32 | }
33 |
34 | static struct stub_priv *stub_priv_pop(struct stub_device *sdev)
35 | {
36 | struct stub_priv *priv;
37 |
38 | pthread_mutex_lock(&sdev->priv_lock);
39 |
40 | priv = stub_priv_pop_from_listhead(&sdev->priv_init);
41 | if (priv)
42 | goto done;
43 |
44 | priv = stub_priv_pop_from_listhead(&sdev->priv_tx);
45 | if (priv)
46 | goto done;
47 |
48 | priv = stub_priv_pop_from_listhead(&sdev->priv_free);
49 |
50 | done:
51 | pthread_mutex_unlock(&sdev->priv_lock);
52 | return priv;
53 | }
54 |
55 | void stub_device_cleanup_transfers(struct stub_device *sdev)
56 | {
57 | struct stub_priv *priv;
58 | struct libusb_transfer *trx;
59 |
60 | dev_dbg(sdev->dev, "free sdev %p\n", sdev);
61 |
62 | while (1) {
63 | priv = stub_priv_pop(sdev);
64 | if (!priv)
65 | break;
66 |
67 | trx = priv->trx;
68 | libusb_cancel_transfer(trx);
69 |
70 | dev_dbg(sdev->dev, "free trx %p\n", trx);
71 | free(priv);
72 | free(trx->buffer);
73 | libusb_free_transfer(trx);
74 | }
75 | }
76 |
77 | void stub_device_cleanup_unlinks(struct stub_device *sdev)
78 | {
79 | /* derived from stub_shutdown_connection */
80 | struct list_head *pos, *tmp;
81 | struct stub_unlink *unlink;
82 |
83 | pthread_mutex_lock(&sdev->priv_lock);
84 | list_for_each_safe(pos, tmp, &sdev->unlink_tx) {
85 | unlink = list_entry(pos, struct stub_unlink, list);
86 | list_del(&unlink->list);
87 | free(unlink);
88 | }
89 | list_for_each_safe(pos, tmp, &sdev->unlink_free) {
90 | unlink = list_entry(pos, struct stub_unlink, list);
91 | list_del(&unlink->list);
92 | free(unlink);
93 | }
94 | pthread_mutex_unlock(&sdev->priv_lock);
95 | }
96 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/Makefile.am:
--------------------------------------------------------------------------------
1 | AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
2 | AM_CFLAGS = @EXTRA_CFLAGS@ -pthread
3 | LDADD = $(top_builddir)/libsrc/libusbip.la
4 |
5 | sbin_PROGRAMS := usbip usbipd usbipa
6 | lib_LTLIBRARIES := libusbipc.la libusbipd.la libusbipa.la
7 |
8 | usbip_SOURCES := usbip.h usbip.c usbip_network.c \
9 | usbip_attach.c usbip_detach.c usbip_list.c \
10 | usbip_bind.c usbip_unbind.c usbip_port.c \
11 | usbip_connect.c usbip_disconnect.c
12 | usbip_CFLAGS := $(AM_CFLAGS)
13 |
14 | usbipd_SOURCES := usbip_network.h usbipd.c usbipd_dev.c usbip_network.c
15 | usbipd_CFLAGS := $(AM_CFLAGS)
16 |
17 | usbipa_SOURCES := usbip_network.h usbipd.c usbipd_app.c usbip_network.c
18 | usbipa_CFLAGS := $(AM_CFLAGS) -DUSBIP_DAEMON_APP
19 |
20 | libusbipc_la_SOURCES := usbip_network.c \
21 | usbip_attach.c usbip_detach.c usbip_list.c \
22 | usbip_port.c \
23 | usbip_connect.c usbip_disconnect.c
24 | libusbipc_la_CFLAGS := $(AM_CFLAGS) -DUSBIP_AS_LIBRARY
25 | libusbipc_la_LDFLAGS := -version-info @LIBUSBIP_VERSION@
26 |
27 | libusbipd_la_SOURCES := usbipd.c usbipd_dev.c usbip_network.c
28 | libusbipd_la_CFLAGS := $(AM_CFLAGS) -DUSBIP_AS_LIBRARY
29 | libusbipd_la_LDFLAGS := -version-info @LIBUSBIP_VERSION@
30 |
31 | libusbipa_la_SOURCES := usbipd.c usbipd_app.c usbip_network.c
32 | libusbipa_la_CFLAGS := $(AM_CFLAGS) -DUSBIP_AS_LIBRARY
33 | libusbipa_la_LDFLAGS := -version-info @LIBUSBIP_VERSION@
34 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip.c:
--------------------------------------------------------------------------------
1 | /*
2 | * command structure borrowed from udev
3 | * (git://git.kernel.org/pub/scm/linux/hotplug/udev.git)
4 | *
5 | * Copyright (C) 2011 matt mooney
6 | * 2005-2007 Takahiro Hirofuchi
7 | * Copyright (C) 2015-2016 Nobuo Iwata
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program. If not, see .
21 | */
22 |
23 | #include "usbip_config.h"
24 |
25 | #include
26 | #include
27 |
28 | #include
29 |
30 | #include "usbip_common.h"
31 | #include "usbip_network.h"
32 | #include "usbip.h"
33 |
34 | static int usbip_help(int argc, char *argv[]);
35 | static int usbip_version(int argc, char *argv[]);
36 |
37 | static const char usbip_version_string[] = PACKAGE_STRING;
38 |
39 | static const char usbip_usage_string[] =
40 | "usbip [--debug]"
41 | #ifdef USBIP_WITH_LIBUSB
42 | " [--debug-flags HEX]"
43 | #endif
44 | " [--log] [--tcp-port PORT] [version]\n"
45 | " [help] \n";
46 |
47 | static void usbip_usage(void)
48 | {
49 | printf("usage: %s", usbip_usage_string);
50 | }
51 |
52 | struct command {
53 | const char *name;
54 | int (*fn)(int argc, char *argv[]);
55 | const char *help;
56 | void (*usage)(void);
57 | };
58 |
59 | static const struct command cmds[] = {
60 | {
61 | "help",
62 | usbip_help,
63 | NULL,
64 | NULL
65 | },
66 | {
67 | "version",
68 | usbip_version,
69 | NULL,
70 | NULL
71 | },
72 | #ifndef USBIP_WITH_LIBUSB
73 | {
74 | "attach",
75 | usbip_attach,
76 | "Attach a remote USB device",
77 | usbip_attach_usage
78 | },
79 | {
80 | "detach",
81 | usbip_detach,
82 | "Detach a remote USB device",
83 | usbip_detach_usage
84 | },
85 | #endif
86 | {
87 | "connect",
88 | usbip_connect,
89 | "Connect a USB device to a remote computer",
90 | usbip_connect_usage
91 | },
92 | {
93 | "disconnect",
94 | usbip_disconnect,
95 | "Disconnect a USB device from a remote computer",
96 | usbip_disconnect_usage
97 | },
98 | {
99 | "list",
100 | usbip_list,
101 | "List exportable or local USB devices",
102 | usbip_list_usage
103 | },
104 | {
105 | "bind",
106 | usbip_bind,
107 | "Bind device to " USBIP_HOST_DRV_NAME ".ko",
108 | usbip_bind_usage
109 | },
110 | {
111 | "unbind",
112 | usbip_unbind,
113 | "Unbind device from " USBIP_HOST_DRV_NAME ".ko",
114 | usbip_unbind_usage
115 | },
116 | #ifndef USBIP_WITH_LIBUSB
117 | {
118 | "port",
119 | usbip_port_show,
120 | "Show imported USB devices",
121 | NULL
122 | },
123 | #endif
124 | { NULL, NULL, NULL, NULL }
125 | };
126 |
127 | static int usbip_help(int argc, char *argv[])
128 | {
129 | const struct command *cmd;
130 | int i;
131 | int ret = 0;
132 |
133 | if (argc > 1 && argv++) {
134 | for (i = 0; cmds[i].name != NULL; i++)
135 | if (!strcmp(cmds[i].name, argv[0]) && cmds[i].usage) {
136 | cmds[i].usage();
137 | goto done;
138 | }
139 | ret = -1;
140 | }
141 |
142 | usbip_usage();
143 | printf("\n");
144 | for (cmd = cmds; cmd->name != NULL; cmd++)
145 | if (cmd->help != NULL)
146 | printf(" %-10s %s\n", cmd->name, cmd->help);
147 | printf("\n");
148 | done:
149 | return ret;
150 | }
151 |
152 | static int usbip_version(int argc, char *argv[])
153 | {
154 | (void) argc;
155 | (void) argv;
156 |
157 | printf(PROGNAME " (%s)\n", usbip_version_string);
158 | return 0;
159 | }
160 |
161 | static int run_command(const struct command *cmd, int argc, char *argv[])
162 | {
163 | dbg("running command: `%s'", cmd->name);
164 | return cmd->fn(argc, argv);
165 | }
166 |
167 | int main(int argc, char *argv[])
168 | {
169 | static const struct option opts[] = {
170 | { "debug", no_argument, NULL, 'd' },
171 | #ifdef USBIP_WITH_LIBUSB
172 | { "debug-flags", required_argument, NULL, 'f' },
173 | #endif
174 | { "log", no_argument, NULL, 'l' },
175 | { "tcp-port", required_argument, NULL, 't' },
176 | { NULL, 0, NULL, 0 }
177 | };
178 |
179 | char *cmd;
180 | int opt;
181 | int i, rc = -1;
182 |
183 | usbip_use_stderr = 1;
184 | opterr = 0;
185 | for (;;) {
186 | opt = getopt_long(argc, argv, "+d"
187 | #ifdef USBIP_WITH_LIBUSB
188 | "f:"
189 | #endif
190 | "lt:", opts, NULL);
191 | if (opt == -1)
192 | break;
193 |
194 | switch (opt) {
195 | case 'd':
196 | usbip_use_debug = 1;
197 | break;
198 | #ifdef USBIP_WITH_LIBUSB
199 | case 'f':
200 | usbip_debug_flag = strtoul(optarg, NULL, 16);
201 | break;
202 | #endif
203 | case 'l':
204 | #ifndef USBIP_OS_NO_SYSLOG
205 | usbip_use_syslog = 1;
206 | openlog("", LOG_PID, LOG_USER);
207 | #endif
208 | break;
209 | case 't':
210 | usbip_setup_port_number(optarg);
211 | break;
212 | case '?':
213 | printf("usbip: invalid option\n");
214 | default:
215 | usbip_usage();
216 | goto out;
217 | }
218 | }
219 |
220 | cmd = argv[optind];
221 | if (cmd) {
222 | for (i = 0; cmds[i].name != NULL; i++)
223 | if (!strcmp(cmds[i].name, cmd)) {
224 | argc -= optind;
225 | argv += optind;
226 | optind = 0;
227 | usbip_net_tcp_conn_init();
228 | rc = run_command(&cmds[i], argc, argv);
229 | goto out;
230 | }
231 | }
232 |
233 | /* invalid command */
234 | usbip_help(0, NULL);
235 | out:
236 | return (rc > -1 ? EXIT_SUCCESS : EXIT_FAILURE);
237 | }
238 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Nobuo Iwata
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef __USBIP_H
21 | #define __USBIP_H
22 |
23 | #ifdef USBIP_WITH_LIBUSB
24 | extern unsigned long usbip_debug_flag;
25 | #endif
26 |
27 | /* usbip commands */
28 | int usbip_attach(int argc, char *argv[]);
29 | int usbip_detach(int argc, char *argv[]);
30 | int usbip_list(int argc, char *argv[]);
31 | int usbip_bind(int argc, char *argv[]);
32 | int usbip_unbind(int argc, char *argv[]);
33 | int usbip_port_show(int argc, char *argv[]);
34 | int usbip_connect(int argc, char *argv[]);
35 | int usbip_disconnect(int argc, char *argv[]);
36 |
37 | void usbip_attach_usage(void);
38 | void usbip_detach_usage(void);
39 | void usbip_list_usage(void);
40 | void usbip_bind_usage(void);
41 | void usbip_unbind_usage(void);
42 | void usbip_connect_usage(void);
43 | void usbip_disconnect_usage(void);
44 |
45 | #endif /* __USBIP_H */
46 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip_attach.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Samsung Electronics
5 | * Igor Kotrasinski
6 | * Krzysztof Opasiak
7 | * Copyright (C) 2015-2016 Nobuo Iwata
8 | *
9 | * This program is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program. If not, see .
21 | */
22 |
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | #ifndef USBIP_AS_LIBRARY
31 | #include
32 | #endif
33 | #include
34 | #include
35 |
36 | #include "vhci_driver.h"
37 | #include "usbip_common.h"
38 | #include "usbip_network.h"
39 | #include "usbip.h"
40 |
41 | #ifndef USBIP_AS_LIBRARY
42 | static const char usbip_attach_usage_string[] =
43 | "usbip attach \n"
44 | " -r, --remote= The machine with exported USB devices\n"
45 | " -b, --busid= Busid of the device on \n"
46 | " -d, --device= Id of the virtual UDC on \n";
47 |
48 | void usbip_attach_usage(void)
49 | {
50 | printf("usage: %s", usbip_attach_usage_string);
51 | }
52 | #endif
53 |
54 | static int import_device(struct usbip_sock *sock,
55 | struct usbip_usb_device *udev,
56 | const char *host, const char *port, const char *busid)
57 | {
58 | int rc;
59 | int port_nr;
60 |
61 | rc = usbip_vhci_driver_open();
62 | if (rc < 0) {
63 | err("open vhci_driver");
64 | goto err_out;
65 | }
66 |
67 | do {
68 | port_nr = usbip_vhci_get_free_port();
69 | if (port_nr < 0) {
70 | err("no free port");
71 | goto err_driver_close;
72 | }
73 |
74 | rc = usbip_vhci_attach_device(port_nr, sock->fd, udev->busnum,
75 | udev->devnum, udev->speed);
76 | if (rc < 0 && errno != EBUSY) {
77 | err("import device");
78 | goto err_driver_close;
79 | return -1;
80 | }
81 | } while (rc < 0);
82 |
83 | rc = usbip_vhci_create_record(host, port, busid, port_nr);
84 | if (rc < 0) {
85 | err("record connection");
86 | goto err_detach_device;
87 | }
88 |
89 | usbip_vhci_driver_close();
90 |
91 | return 0;
92 |
93 | err_detach_device:
94 | usbip_vhci_detach_device(port_nr);
95 | err_driver_close:
96 | usbip_vhci_driver_close();
97 | err_out:
98 | return -1;
99 | }
100 |
101 | static int query_import_device(struct usbip_sock *sock,
102 | const char *host, const char *port,
103 | const char *busid)
104 | {
105 | int rc;
106 | struct op_import_request request;
107 | struct op_import_reply reply;
108 | uint16_t code = OP_REP_IMPORT;
109 |
110 | memset(&request, 0, sizeof(request));
111 | memset(&reply, 0, sizeof(reply));
112 |
113 | /* send a request */
114 | rc = usbip_net_send_op_common(sock, OP_REQ_IMPORT, 0);
115 | if (rc < 0) {
116 | err("send op_common");
117 | return -1;
118 | }
119 |
120 | strncpy(request.busid, busid, SYSFS_BUS_ID_SIZE-1);
121 |
122 | PACK_OP_IMPORT_REQUEST(0, &request);
123 |
124 | rc = usbip_net_send(sock, (void *) &request, sizeof(request));
125 | if (rc < 0) {
126 | err("send op_import_request");
127 | return -1;
128 | }
129 |
130 | /* receive a reply */
131 | rc = usbip_net_recv_op_common(sock, &code);
132 | if (rc < 0) {
133 | err("recv op_common");
134 | return -1;
135 | }
136 |
137 | rc = usbip_net_recv(sock, (void *) &reply, sizeof(reply));
138 | if (rc < 0) {
139 | err("recv op_import_reply");
140 | return -1;
141 | }
142 |
143 | PACK_OP_IMPORT_REPLY(0, &reply);
144 |
145 | /* check the reply */
146 | if (strncmp(reply.udev.busid, busid, SYSFS_BUS_ID_SIZE)) {
147 | err("recv different busid %s", reply.udev.busid);
148 | return -1;
149 | }
150 |
151 | return import_device(sock, &reply.udev, host, port, busid);
152 | }
153 |
154 | int usbip_attach_device(const char *host, const char *port, const char *busid)
155 | {
156 | struct usbip_sock *sock;
157 | int rc;
158 |
159 | sock = usbip_conn_open(host, usbip_port_string);
160 | if (!sock) {
161 | err("tcp connect");
162 | goto err_out;
163 | }
164 |
165 | rc = query_import_device(sock, host, port, busid);
166 | if (rc < 0) {
167 | err("query");
168 | goto err_tcp_close;
169 | }
170 |
171 | rc = usbip_ux_try_transfer(sock);
172 | if (rc < 0) {
173 | err("try transfer");
174 | goto err_tcp_close;
175 | }
176 |
177 | usbip_conn_close(sock);
178 |
179 | return 0;
180 |
181 | err_tcp_close:
182 | usbip_conn_close(sock);
183 | err_out:
184 | return -1;
185 | }
186 |
187 | #ifndef USBIP_AS_LIBRARY
188 | int usbip_attach(int argc, char *argv[])
189 | {
190 | static const struct option opts[] = {
191 | { "remote", required_argument, NULL, 'r' },
192 | { "busid", required_argument, NULL, 'b' },
193 | { "device", required_argument, NULL, 'd' },
194 | { NULL, 0, NULL, 0 }
195 | };
196 | char *host = NULL;
197 | char *busid = NULL;
198 | int opt;
199 | int ret = -1;
200 |
201 | for (;;) {
202 | opt = getopt_long(argc, argv, "d:r:b:", opts, NULL);
203 |
204 | if (opt == -1)
205 | break;
206 |
207 | switch (opt) {
208 | case 'r':
209 | host = optarg;
210 | break;
211 | case 'd':
212 | case 'b':
213 | busid = optarg;
214 | break;
215 | default:
216 | goto err_out;
217 | }
218 | }
219 |
220 | if (!host || !busid)
221 | goto err_out;
222 |
223 | ret = usbip_attach_device(host, usbip_port_string, busid);
224 | goto out;
225 |
226 | err_out:
227 | usbip_attach_usage();
228 | out:
229 | return ret;
230 | }
231 | #endif /* !USBIP_AS_LIBRARY */
232 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip_bind.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Nobuo Iwata
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 |
27 | #include "usbip_host_driver.h"
28 | #include "usbip_common.h"
29 | #include "usbip.h"
30 |
31 | static const char usbip_bind_usage_string[] =
32 | "usbip bind \n"
33 | " -b, --busid= Bind " USBIP_HOST_DRV_NAME ".ko to device "
34 | "on \n";
35 |
36 | void usbip_bind_usage(void)
37 | {
38 | printf("usage: %s", usbip_bind_usage_string);
39 | }
40 |
41 | int usbip_bind(int argc, char *argv[])
42 | {
43 | static const struct option opts[] = {
44 | { "busid", required_argument, NULL, 'b' },
45 | { NULL, 0, NULL, 0 }
46 | };
47 |
48 | int opt;
49 | int ret = -1;
50 |
51 | for (;;) {
52 | opt = getopt_long(argc, argv, "b:", opts, NULL);
53 |
54 | if (opt == -1)
55 | break;
56 |
57 | switch (opt) {
58 | case 'b':
59 | ret = usbip_bind_device(optarg);
60 | goto out;
61 | default:
62 | goto err_out;
63 | }
64 | }
65 |
66 | err_out:
67 | usbip_bind_usage();
68 | out:
69 | return ret;
70 | }
71 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip_connect.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Nobuo Iwata
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #ifndef USBIP_AS_LIBRARY
28 | #include
29 | #endif
30 |
31 | #include "usbip_host_driver.h"
32 | #include "usbip_device_driver.h"
33 | #include "usbip_common.h"
34 | #include "usbip_network.h"
35 | #include "usbip.h"
36 |
37 | #ifndef USBIP_AS_LIBRARY
38 | static const char usbip_connect_usage_string[] =
39 | "usbip connect \n"
40 | " -r, --remote= Address of a remote computer\n"
41 | " -b, --busid= Bus ID of a device to be connected\n"
42 | " -d, --device Run with an alternate driver, e.g. vUDC\n"
43 | ;
44 |
45 | void usbip_connect_usage(void)
46 | {
47 | printf("usage: %s", usbip_connect_usage_string);
48 | }
49 | #endif
50 |
51 | static int send_export_device(struct usbip_sock *sock,
52 | struct usbip_usb_device *udev)
53 | {
54 | int rc;
55 | struct op_export_request request;
56 | uint16_t code = OP_REP_EXPORT;
57 |
58 | /* send a request */
59 | rc = usbip_net_send_op_common(sock, OP_REQ_EXPORT, 0);
60 | if (rc < 0) {
61 | err("send op_common");
62 | return -1;
63 | }
64 |
65 | memset(&request, 0, sizeof(request));
66 | memcpy(&request.udev, udev, sizeof(request.udev));
67 |
68 | PACK_OP_EXPORT_REQUEST(0, &request);
69 |
70 | rc = usbip_net_send(sock, (void *) &request, sizeof(request));
71 | if (rc < 0) {
72 | err("send op_export_request");
73 | return -1;
74 | }
75 |
76 | /* receive a reply */
77 | rc = usbip_net_recv_op_common(sock, &code);
78 | if (rc < 0) {
79 | err("recv op_common");
80 | return -1;
81 | }
82 |
83 | return 0;
84 | }
85 |
86 | static int export_device(const char *busid, struct usbip_sock *sock)
87 | {
88 | struct usbip_exported_devices edevs;
89 | struct usbip_exported_device *edev;
90 | int rc;
91 |
92 | rc = usbip_driver_open();
93 | if (rc) {
94 | err("open driver");
95 | goto err_out;
96 | }
97 |
98 | rc = usbip_refresh_device_list(&edevs);
99 | if (rc < 0) {
100 | err("could not refresh device list");
101 | goto err_driver_close;
102 | }
103 |
104 | edev = usbip_get_device(&edevs, busid);
105 | if (edev == NULL) {
106 | err("find device");
107 | goto err_free_edevs;
108 | }
109 |
110 | rc = send_export_device(sock, &edev->udev);
111 | if (rc < 0) {
112 | err("send export");
113 | goto err_free_edevs;
114 | }
115 |
116 | rc = usbip_export_device(edev, sock);
117 | if (rc < 0) {
118 | err("export device");
119 | goto err_free_edevs;
120 | }
121 |
122 | rc = usbip_try_transfer(edev, sock);
123 | if (rc < 0) {
124 | err("try transfer");
125 | goto err_free_edevs;
126 | }
127 |
128 | usbip_free_device_list(&edevs);
129 | usbip_driver_close();
130 |
131 | return 0;
132 |
133 | err_free_edevs:
134 | usbip_free_device_list(&edevs);
135 | err_driver_close:
136 | usbip_driver_close();
137 | err_out:
138 | return -1;
139 | }
140 |
141 | int usbip_connect_device(const char *host, const char *port, const char *busid)
142 | {
143 | struct usbip_sock *sock;
144 | int rc;
145 |
146 | rc = usbip_bind_device(busid);
147 | if (rc) {
148 | err("bind");
149 | goto err_out;
150 | }
151 |
152 | sock = usbip_conn_open(host, port);
153 | if (!sock) {
154 | err("tcp connect");
155 | goto err_unbind_device;
156 | }
157 |
158 | rc = export_device(busid, sock);
159 | if (rc < 0) {
160 | err("export");
161 | goto err_close_conn;
162 | }
163 |
164 | if (usbip_has_transferred())
165 | usbip_unbind_device(busid);
166 |
167 | usbip_conn_close(sock);
168 |
169 | return 0;
170 | err_close_conn:
171 | usbip_conn_close(sock);
172 | err_unbind_device:
173 | usbip_unbind_device(busid);
174 | err_out:
175 | return -1;
176 | }
177 |
178 | #ifndef USBIP_AS_LIBRARY
179 | int usbip_connect(int argc, char *argv[])
180 | {
181 | static const struct option opts[] = {
182 | { "remote", required_argument, NULL, 'r' },
183 | { "busid", required_argument, NULL, 'b' },
184 | { "device", no_argument, NULL, 'd' },
185 | { NULL, 0, NULL, 0 }
186 | };
187 | char *host = NULL;
188 | char *busid = NULL;
189 | int opt;
190 | int ret = -1;
191 |
192 | for (;;) {
193 | opt = getopt_long(argc, argv, "r:b:d", opts, NULL);
194 |
195 | if (opt == -1)
196 | break;
197 |
198 | switch (opt) {
199 | case 'r':
200 | host = optarg;
201 | break;
202 | case 'b':
203 | busid = optarg;
204 | break;
205 | case 'd':
206 | usbip_hdriver_set(USBIP_HDRIVER_TYPE_DEVICE);
207 | break;
208 | default:
209 | goto err_out;
210 | }
211 | }
212 |
213 | if (!host || !busid)
214 | goto err_out;
215 |
216 | ret = usbip_connect_device(host, usbip_port_string, busid);
217 | goto out;
218 |
219 | err_out:
220 | usbip_connect_usage();
221 | out:
222 | return ret;
223 | }
224 | #endif /* !USBIP_AS_LIBRARY */
225 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip_detach.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Nobuo Iwata
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #ifndef USBIP_AS_LIBRARY
28 | #include
29 | #endif
30 | #include
31 |
32 | #include "vhci_driver.h"
33 | #include "usbip_common.h"
34 | #include "usbip_network.h"
35 | #include "usbip.h"
36 |
37 | #ifndef USBIP_AS_LIBRARY
38 | static const char usbip_detach_usage_string[] =
39 | "usbip detach \n"
40 | " -p, --port= " USBIP_VHCI_DRV_NAME
41 | " port the device is on\n";
42 |
43 | void usbip_detach_usage(void)
44 | {
45 | printf("usage: %s", usbip_detach_usage_string);
46 | }
47 | #endif
48 |
49 | int usbip_detach_port(const char *port)
50 | {
51 | int ret;
52 | uint8_t portnum;
53 | unsigned int i, port_len = strlen(port);
54 |
55 | for (i = 0; i < port_len; i++)
56 | if (!isdigit(port[i])) {
57 | err("invalid port %s", port);
58 | return -1;
59 | }
60 |
61 | /* check max port */
62 |
63 | portnum = atoi(port);
64 |
65 | ret = usbip_vhci_driver_open();
66 | if (ret < 0) {
67 | err("open vhci_driver");
68 | return -1;
69 | }
70 |
71 | ret = usbip_vhci_detach_device(portnum);
72 | if (ret < 0) {
73 | usbip_vhci_driver_close();
74 | return -1;
75 | }
76 |
77 | usbip_vhci_delete_record(portnum);
78 |
79 | usbip_vhci_driver_close();
80 |
81 | return 0;
82 | }
83 |
84 | #ifndef USBIP_AS_LIBRARY
85 | int usbip_detach(int argc, char *argv[])
86 | {
87 | static const struct option opts[] = {
88 | { "port", required_argument, NULL, 'p' },
89 | { NULL, 0, NULL, 0 }
90 | };
91 | int opt;
92 | int ret = -1;
93 |
94 | for (;;) {
95 | opt = getopt_long(argc, argv, "p:", opts, NULL);
96 |
97 | if (opt == -1)
98 | break;
99 |
100 | switch (opt) {
101 | case 'p':
102 | ret = usbip_detach_port(optarg);
103 | goto out;
104 | default:
105 | goto err_out;
106 | }
107 | }
108 |
109 | err_out:
110 | usbip_detach_usage();
111 | out:
112 | return ret;
113 | }
114 | #endif /* !USBIP_AS_LIBRARY */
115 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip_disconnect.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Nobuo Iwata
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #ifndef USBIP_AS_LIBRARY
28 | #include
29 | #endif
30 |
31 | #include "usbip_host_driver.h"
32 | #include "usbip_device_driver.h"
33 | #include "usbip_common.h"
34 | #include "usbip_network.h"
35 | #include "usbip.h"
36 |
37 | #ifndef USBIP_AS_LIBRARY
38 | static const char usbip_disconnect_usage_string[] =
39 | "usbip disconnect \n"
40 | " -r, --remote= Address of a remote computer\n"
41 | " -b, --busid= Bus ID of a device to be disconnected\n"
42 | " -d, --device Run with an alternate driver, e.g. vUDC\n"
43 | ;
44 |
45 | void usbip_disconnect_usage(void)
46 | {
47 | printf("usage: %s", usbip_disconnect_usage_string);
48 | }
49 | #endif
50 |
51 | static int send_unexport_device(struct usbip_sock *sock,
52 | struct usbip_usb_device *udev)
53 | {
54 | int rc;
55 | struct op_unexport_request request;
56 | uint16_t code = OP_REP_UNEXPORT;
57 |
58 | /* send a request */
59 | rc = usbip_net_send_op_common(sock, OP_REQ_UNEXPORT, 0);
60 | if (rc < 0) {
61 | err("send op_common");
62 | return -1;
63 | }
64 |
65 | memset(&request, 0, sizeof(request));
66 | memcpy(&request.udev, udev, sizeof(request.udev));
67 |
68 | PACK_OP_UNEXPORT_REQUEST(0, &request);
69 |
70 | rc = usbip_net_send(sock, (void *) &request, sizeof(request));
71 | if (rc < 0) {
72 | err("send op_export_request");
73 | return -1;
74 | }
75 |
76 | /* receive a reply */
77 | rc = usbip_net_recv_op_common(sock, &code);
78 | if (rc < 0) {
79 | err("recv op_common");
80 | return -1;
81 | }
82 |
83 | return 0;
84 | }
85 |
86 | static int unexport_device(const char *busid, struct usbip_sock *sock)
87 | {
88 | struct usbip_exported_devices edevs;
89 | struct usbip_exported_device *edev;
90 | int rc;
91 |
92 | rc = usbip_driver_open();
93 | if (rc < 0) {
94 | err("open driver");
95 | goto err_out;
96 | }
97 |
98 | rc = usbip_refresh_device_list(&edevs);
99 | if (rc < 0) {
100 | err("could not refresh device list");
101 | goto err_driver_close;
102 | }
103 |
104 | edev = usbip_get_device(&edevs, busid);
105 | if (edev == NULL) {
106 | err("find device");
107 | goto err_free_edevs;
108 | }
109 |
110 | rc = send_unexport_device(sock, &edev->udev);
111 | if (rc < 0) {
112 | err("send unexport");
113 | goto err_free_edevs;
114 | }
115 |
116 | usbip_free_device_list(&edevs);
117 | usbip_driver_close();
118 |
119 | return 0;
120 |
121 | err_free_edevs:
122 | usbip_free_device_list(&edevs);
123 | err_driver_close:
124 | usbip_driver_close();
125 | err_out:
126 | return -1;
127 | }
128 |
129 | int usbip_disconnect_device(const char *host, const char *port,
130 | const char *busid)
131 | {
132 | struct usbip_sock *sock;
133 | int rc;
134 |
135 | sock = usbip_conn_open(host, port);
136 | if (!sock) {
137 | err("tcp connect");
138 | return -1;
139 | }
140 |
141 | rc = unexport_device(busid, sock);
142 | if (rc < 0) {
143 | err("unexport");
144 | usbip_conn_close(sock);
145 | return -1;
146 | }
147 |
148 | usbip_conn_close(sock);
149 |
150 | if (!usbip_has_transferred()) {
151 | rc = usbip_unbind_device(busid);
152 | if (rc) {
153 | err("unbind");
154 | return -1;
155 | }
156 | }
157 |
158 | return 0;
159 | }
160 |
161 | #ifndef USBIP_AS_LIBRARY
162 | int usbip_disconnect(int argc, char *argv[])
163 | {
164 | static const struct option opts[] = {
165 | { "remote", required_argument, NULL, 'r' },
166 | { "busid", required_argument, NULL, 'b' },
167 | { "device", no_argument, NULL, 'd' },
168 | { NULL, 0, NULL, 0 }
169 | };
170 | char *host = NULL;
171 | char *busid = NULL;
172 | int opt;
173 | int ret = -1;
174 |
175 | for (;;) {
176 | opt = getopt_long(argc, argv, "r:b:d", opts, NULL);
177 |
178 | if (opt == -1)
179 | break;
180 |
181 | switch (opt) {
182 | case 'r':
183 | host = optarg;
184 | break;
185 | case 'b':
186 | busid = optarg;
187 | break;
188 | case 'd':
189 | usbip_hdriver_set(USBIP_HDRIVER_TYPE_DEVICE);
190 | break;
191 | default:
192 | goto err_out;
193 | }
194 | }
195 |
196 | if (!host || !busid)
197 | goto err_out;
198 |
199 | ret = usbip_disconnect_device(host, usbip_port_string, busid);
200 | goto out;
201 |
202 | err_out:
203 | usbip_disconnect_usage();
204 | out:
205 | return ret;
206 | }
207 | #endif /* !USBIP_AS_LIBRARY */
208 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip_port.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 2 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | */
15 |
16 | #include "vhci_driver.h"
17 | #include "usbip.h"
18 |
19 | int usbip_list_imported_devices(void)
20 | {
21 | int ret;
22 |
23 | if (usbip_names_init(USBIDS_FILE))
24 | err("failed to open %s", USBIDS_FILE);
25 |
26 | ret = usbip_vhci_driver_open();
27 | if (ret < 0) {
28 | err("open vhci driver");
29 | goto err_names_free;
30 | }
31 |
32 | printf("Imported USB devices\n");
33 | printf("====================\n");
34 |
35 | ret = usbip_vhci_imported_devices_dump();
36 | if (ret < 0) {
37 | err("dump vhci devices");
38 | goto err_driver_close;
39 | }
40 |
41 | usbip_vhci_driver_close();
42 | usbip_names_free();
43 |
44 | return ret;
45 |
46 | err_driver_close:
47 | usbip_vhci_driver_close();
48 | err_names_free:
49 | usbip_names_free();
50 | return -1;
51 | }
52 |
53 | #ifndef USBIP_AS_LIBRARY
54 | int usbip_port_show(__attribute__((unused)) int argc,
55 | __attribute__((unused)) char *argv[])
56 | {
57 | int ret;
58 |
59 | ret = usbip_list_imported_devices();
60 | if (ret < 0)
61 | err("list imported devices");
62 |
63 | return ret;
64 | }
65 | #endif
66 |
--------------------------------------------------------------------------------
/tools/usb/usbip/src/usbip_unbind.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 matt mooney
3 | * 2005-2007 Takahiro Hirofuchi
4 | * Copyright (C) 2015-2016 Nobuo Iwata
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include
25 |
26 | #include "usbip_host_driver.h"
27 | #include "usbip_common.h"
28 | #include "usbip.h"
29 |
30 | static const char usbip_unbind_usage_string[] =
31 | "usbip unbind \n"
32 | " -b, --busid=