Commit 0945b4fe authored by Takahiro Hirofuchi's avatar Takahiro Hirofuchi Committed by Greg Kroah-Hartman

staging: usbip: add userspace code

Add userspace code from svn trunk revision 175. Located at
https://usbip.svn.sourceforge.net/svnroot/usbip/linux/trunk/src.
Signed-off-by: default avatarmatt mooney <mfm@muteddisk.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a9869c94
Takahiro Hirofuchi
Robert Leibl
This diff is collapsed.
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006, 2007 Free Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
6. Often, you can also type `make uninstall' to remove the installed
files again.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that the
`configure' script does not know about. Run `./configure --help' for
details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' cannot figure out automatically,
but needs to determine by the type of machine the package will run on.
Usually, assuming the package is built to be run on the _same_
architectures, `configure' can figure that out, but if it prints a
message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share, you
can create a site shell script called `config.site' that gives default
values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it operates.
`--help'
`-h'
Print a summary of the options to `configure', and exit.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
SUBDIRS = lib cmd
includedir=@includedir@/usbip
include_HEADERS = lib/usbip.h lib/usbip_common.h lib/vhci_driver.h lib/stub_driver.h
if INSTALL_USBIDS
pkgdata_DATA = usb.ids
EXTRA_DIST = $(pkgdata_DATA)
endif
link ../NEWS
\ No newline at end of file
# vim:tw=78:ts=4:expandtab:ai:sw=4
#
# README for usbip-utils
#
# Copyright (C) 2005-2008 Takahiro Hirofuchi
[Requirements]
- USB/IP device drivers
Its source code is included under $(top)/drivers/.
- sysfsutils >= 2.0.0
sysfsutils library
- libwrap0-dev
tcp wrapper library
- gcc >= 4.0
- libglib2.0-dev >= 2.6.0
- libtool, automake >= 1.9, autoconf >= 2.5.0, pkg-config
[Install]
0. Skip here if you see a configure script.
$ ./autogen.sh
1. Compile & install.
$ ./configure
$ make install
2. Compile & install USB/IP drivers if not yet.
[Usage]
server:# (Attach your USB device physically.)
server:# insmod usbip_common_mod.ko
server:# insmod usbip.ko
- It was formerly named as stub.ko.
server:# usbipd -D
- Start usbip daemon.
server:# usbip_bind_driver --list
- List driver assignments for usb devices.
server:# usbip_bind_driver --usbip 1-2
- Bind usbip.ko to the device of busid 1-2.
- A usb device 1-2 is now exportable to other hosts!
- Use 'usbip_bind_driver --other 1-2' when you want to shutdown exporting
and use the device locally.
client:# insmod usbip_common_mod.ko
client:# insmod vhci-hcd.ko
- It was formerly named as vhci.ko.
client:# usbip --list server
- List exportable usb devices on the server.
client:# usbip --attach server 1-2
- Connect the remote USB device.
client:# usbip --port
- Show virtual port status.
client:# usbip --detach 0
- Detach the usb device.
[Output Example]
--------------------------------------------------------------------------------------------------------
- SERVER SIDE (physically attach your USB devices to this host) ----------------------------------------
--------------------------------------------------------------------------------------------------------
trois:# insmod (somewhere)/usbip_common_mod.ko
trois:# insmod (somewhere)/usbip.ko
trois:# usbipd -D
--------------------------------------------------------------------------------------------------------
In another terminal, let's look up what usb devices are physically attached to
this host. We can see a usb storage device of busid 3-3.2 is now bound to
usb-storage driver. To export this device, we first mark the device as
"exportable"; the device is bound to usbip driver. Please remember you can not
export a usb hub.
trois:# usbip_bind_driver --list
List USB devices
- busid 3-3.2 (04bb:0206)
3-3.2:1.0 -> usb-storage
- busid 3-3.1 (08bb:2702)
3-3.1:1.0 -> snd-usb-audio
3-3.1:1.1 -> snd-usb-audio
- busid 3-3 (0409:0058)
3-3:1.0 -> hub
- busid 3-2 (0711:0902)
3-2:1.0 -> none
- busid 1-1 (05a9:a511)
1-1:1.0 -> ov511
- busid 4-1 (046d:08b2)
4-1:1.0 -> none
4-1:1.1 -> none
4-1:1.2 -> none
- busid 5-2 (058f:9254)
5-2:1.0 -> hub
--------------------------------------------------------------------------------------------------------
Mark the device of busid 3-3.2 as exportable.
trois:# usbip_bind_driver --usbip 3-3.2
** (process:24621): DEBUG: 3-3.2:1.0 -> none
** (process:24621): DEBUG: write "add 3-3.2" to /sys/bus/usb/drivers/usbip/match_busid
** Message: bind 3-3.2 to usbip, complete!
trois:# usbip_bind_driver --list
List USB devices
- busid 3-3.2 (04bb:0206)
3-3.2:1.0 -> usbip
(snip)
Iterate the above operation for other devices if you like.
--------------------------------------------------------------------------------------------------------
- CLIENT SIDE ------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
First, let's list available remote devices which are marked as exportable in
the server host.
deux:# insmod (somewhere)/usbip_common_mod.ko
deux:# insmod (somewhere)/vhci_hcd.ko
deux:# usbip --list 10.0.0.3
- 10.0.0.3
1-1: Prolific Technology, Inc. : unknown product (067b:3507)
: /sys/devices/pci0000:00/0000:00:1f.2/usb1/1-1
: (Defined at Interface level) / unknown subclass / unknown protocol (00/00/00)
: 0 - Mass Storage / SCSI / Bulk (Zip) (08/06/50)
1-2.2.1: Apple Computer, Inc. : unknown product (05ac:0203)
: /sys/devices/pci0000:00/0000:00:1f.2/usb1/1-2/1-2.2/1-2.2.1
: (Defined at Interface level) / unknown subclass / unknown protocol (00/00/00)
: 0 - Human Interface Devices / Boot Interface Subclass / Keyboard (03/01/01)
1-2.2.3: OmniVision Technologies, Inc. : OV511+ WebCam (05a9:a511)
: /sys/devices/pci0000:00/0000:00:1f.2/usb1/1-2/1-2.2/1-2.2.3
: (Defined at Interface level) / unknown subclass / unknown protocol (00/00/00)
: 0 - Vendor Specific Class / unknown subclass / unknown protocol (ff/00/00)
3-1: Logitech, Inc. : QuickCam Pro 4000 (046d:08b2)
: /sys/devices/pci0000:00/0000:00:1e.0/0000:02:0a.0/usb3/3-1
: (Defined at Interface level) / unknown subclass / unknown protocol (00/00/00)
: 0 - Data / unknown subclass / unknown protocol (0a/ff/00)
: 1 - Audio / Control Device / unknown protocol (01/01/00)
: 2 - Audio / Streaming / unknown protocol (01/02/00)
4-1: Logitech, Inc. : QuickCam Express (046d:0870)
: /sys/devices/pci0000:00/0000:00:1e.0/0000:02:0a.1/usb4/4-1
: Vendor Specific Class / Vendor Specific Subclass / Vendor Specific Protocol (ff/ff/ff)
: 0 - Vendor Specific Class / Vendor Specific Subclass / Vendor Specific Protocol (ff/ff/ff)
4-2: Texas Instruments Japan : unknown product (08bb:2702)
: /sys/devices/pci0000:00/0000:00:1e.0/0000:02:0a.1/usb4/4-2
: (Defined at Interface level) / unknown subclass / unknown protocol (00/00/00)
: 0 - Audio / Control Device / unknown protocol (01/01/00)
: 1 - Audio / Streaming / unknown protocol (01/02/00)
--------------------------------------------------------------------------------------------------------
Attach a remote usb device!
deux:# usbip --attach 10.0.0.3 1-1
port 0 attached
--------------------------------------------------------------------------------------------------------
Show what devices are attached to this client.
deux:# usbip --port
Port 00: <Port in Use> at Full Speed(12Mbps)
Prolific Technology, Inc. : unknown product (067b:3507)
6-1 -> usbip://10.0.0.3:3240/1-1 (remote bus/dev 001/004)
6-1:1.0 used by usb-storage
/sys/class/scsi_device/0:0:0:0/device
/sys/class/scsi_host/host0/device
/sys/block/sda/device
--------------------------------------------------------------------------------------------------------
Detach the imported device.
deux:# usbip --detach 0
port 0 detached
--------------------------------------------------------------------------------------------------------
[Check List]
- See Debug Tips in the project wiki.
- http://usbip.wiki.sourceforge.net/how-to-debug-usbip
- usbip.ko must be bound to the target device.
- See /proc/bus/usb/devices and find "Driver=..." lines of the device.
- Shutdown firewall.
- usbip now uses TCP port 3240.
- Disable SELinux.
- If possible, compile your kernel with CONFIG_USB_DEBUG flag and try
again.
- Check your kernel and daemon messages.
ex. /var/log/{messages, kern.log, daemon.log, syslog}
[Contact]
Mailing List: usbip-devel _at_ lists.sourceforge.net
#!/bin/sh -x
#aclocal
#autoheader
#libtoolize --copy --force
#automake-1.9 -acf
#autoconf
autoreconf -i -f -v
#!/bin/sh -x
if [ -r Makefile ]; then
make distclean
fi
FILES="configure cscope.out Makefile.in depcomp compile config.guess config.sub config.h.in~ config.log config.status ltmain.sh libtool config.h.in autom4te.cache missing aclocal.m4 install-sh cmd/Makefile.in lib/Makefile.in Makefile lib/Makefile cmd/Makefile"
rm -Rf $FILES
# $Id$
sbin_PROGRAMS = usbip usbipd usbip_bind_driver
usbip_SOURCES = usbip.c usbip_network.c usbip_network.h
usbipd_SOURCES = usbipd.c usbip_network.c usbip_network.h
usbip_bind_driver_SOURCES = bind-driver.c \
utils.c utils.h \
usbip_network.h usbip_network.c
dist_man_MANS = usbip.8 usbipd.8 usbip_bind_driver.8
#usbip_bind_driver_CFLAGS = -Wall -W -Wstrict-prototypes @PACKAGE_CFLAGS@
#usbip_bind_driver_LDADD = @PACKAGE_LIBS@
#AM_CPPFLAGS = -I../include -Wall -std=gnu99
INCLUDES = -I$(top_srcdir)/lib
LDADD = ../lib/libusbip.la @PACKAGE_LIBS@
EXTRA_CFLAGS = @EXTRA_CFLAGS@
AM_CFLAGS = -Wall -W -Wstrict-prototypes -std=gnu99 $(EXTRA_CFLAGS) @PACKAGE_CFLAGS@ -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
This diff is collapsed.
.TH USBIP "8" "February 2009" "usbip" "System Administration Utilities"
.SH NAME
usbip \- manage USB/IP devices
.SH SYNOPSIS
.B usbip
[\fIoptions\fR]
.SH DESCRIPTION
Devices exported by USB/IP servers can be listed, attached and
detached using this program.
.SH OPTIONS
.HP
\fB\-a\fR, \fB\-\-attach\fR <host> <bus_id>
.IP
Attach a remote USB device.
.PP
.HP
\fB\-x\fR, \fB\-\-attachall\fR <host>
.IP
Attach all remote USB devices on the specific host.
.PP
.HP
\fB\-d\fR, \fB\-\-detach\fR <ports>
.IP
Detach an imported USB device.
.PP
.HP
\fB\-l\fR, \fB\-\-list\fR <hosts>
.IP
List exported USB devices.
.PP
.HP
\fB\-p\fR, \fB\-\-port\fR
.IP
List virtual USB port status.
.PP
.HP
\fB\-D\fR, \fB\-\-debug\fR
.IP
Print debugging information.
.PP
.HP
\fB\-v\fR, \fB\-\-version\fR
.IP
Show version.
.PP
.SH EXAMPLES
client:# usbip --list server
- List exportable usb devices on the server.
client:# usbip --attach server 1-2
- Connect the remote USB device.
client:# usbip --port
- Show virtual port status.
client:# usbip --detach 0
- Detach the usb device.
.SH "SEE ALSO"
\fBusbipd\fP\fB(8)\fB\fP,
\fBusbip_attach_driver\fP\fB(8)\fB\fP
This diff is collapsed.
.TH USBIP_BIND_DRIVER "8" "February 2009" "usbip" "System Administration Utilities"
.SH NAME
usbip_bind_driver \- change driver binding for USB/IP
.SH SYNOPSIS
.B usbip_bind_driver
[\fIoptions\fR]
.SH DESCRIPTION
Driver bindings for USB devices can be changed using
this program. It is used to export and unexport USB
devices over USB/IP.
.SH OPTIONS
.TP
\fB\-u\fR, \fB\-\-usbip\fR <busid>
Make a device exportable
.TP
\fB\-o\fR, \fB\-\-other\fR <busid>
Use a device by a local driver
.TP
\fB\-l\fR, \fB\-\-list\fR
Print usb devices and their drivers
.TP
\fB\-L\fR, \fB\-\-list2\fR
Print usb devices and their drivers in parseable mode
.SH EXAMPLES
server:# usbip_bind_driver --list
- List driver assignments for usb devices.
server:# usbip_bind_driver --usbip 1-2
- Bind usbip.ko to the device of busid 1-2.
- A usb device 1-2 is now exportable to other hosts!
server:# usbip_bind_driver --other 1-2
- Shutdown exporting and use the device locally.
.SH "SEE ALSO"
\fBusbip\fP\fB(8)\fB\fP,
\fBusbipd\fP\fB(8)\fB\fP
/*
* $Id$
*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#include "usbip_network.h"
void pack_uint32_t(int pack, uint32_t *num)
{
uint32_t i;
if (pack)
i = htonl(*num);
else
i = ntohl(*num);
*num = i;
}
void pack_uint16_t(int pack, uint16_t *num)
{
uint16_t i;
if (pack)
i = htons(*num);
else
i = ntohs(*num);
*num = i;
}
void pack_usb_device(int pack, struct usb_device *udev)
{
pack_uint32_t(pack, &udev->busnum);
pack_uint32_t(pack, &udev->devnum);
pack_uint32_t(pack, &udev->speed );
pack_uint16_t(pack, &udev->idVendor );
pack_uint16_t(pack, &udev->idProduct);
pack_uint16_t(pack, &udev->bcdDevice);
}
void pack_usb_interface(int pack, struct usb_interface *udev)
{
/* uint8_t members need nothing */
}
static ssize_t usbip_xmit(int sockfd, void *buff, size_t bufflen, int sending)
{
ssize_t total = 0;
if (!bufflen)
return 0;
do {
ssize_t nbytes;
if (sending)
nbytes = send(sockfd, buff, bufflen, 0);
else
nbytes = recv(sockfd, buff, bufflen, MSG_WAITALL);
if (nbytes <= 0)
return -1;
buff = (void *) ((intptr_t) buff + nbytes);
bufflen -= nbytes;
total += nbytes;
} while (bufflen > 0);
return total;
}
ssize_t usbip_recv(int sockfd, void *buff, size_t bufflen)
{
return usbip_xmit(sockfd, buff, bufflen, 0);
}
ssize_t usbip_send(int sockfd, void *buff, size_t bufflen)
{
return usbip_xmit(sockfd, buff, bufflen, 1);
}
int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status)
{
int ret;
struct op_common op_common;
bzero(&op_common, sizeof(op_common));
op_common.version = USBIP_VERSION;
op_common.code = code;
op_common.status = status;
PACK_OP_COMMON(1, &op_common);
ret = usbip_send(sockfd, (void *) &op_common, sizeof(op_common));
if (ret < 0) {
err("send op_common");
return -1;
}
return 0;
}
int usbip_recv_op_common(int sockfd, uint16_t *code)
{
int ret;
struct op_common op_common;
bzero(&op_common, sizeof(op_common));
ret = usbip_recv(sockfd, (void *) &op_common, sizeof(op_common));
if (ret < 0) {
err("recv op_common, %d", ret);
goto err;
}
PACK_OP_COMMON(0, &op_common);
if (op_common.version != USBIP_VERSION) {
err("version mismatch, %d %d", op_common.version, USBIP_VERSION);
goto err;
}
switch(*code) {
case OP_UNSPEC:
break;
default:
if (op_common.code != *code) {
info("unexpected pdu %d for %d", op_common.code, *code);
goto err;
}
}
if (op_common.status != ST_OK) {
info("request failed at peer, %d", op_common.status);
goto err;
}
*code = op_common.code;
return 0;
err:
return -1;
}
int usbip_set_reuseaddr(int sockfd)
{
const int val = 1;
int ret;
ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
if (ret < 0)
err("setsockopt SO_REUSEADDR");
return ret;
}
int usbip_set_nodelay(int sockfd)
{
const int val = 1;
int ret;
ret = setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
if (ret < 0)
err("setsockopt TCP_NODELAY");
return ret;
}
int usbip_set_keepalive(int sockfd)
{
const int val = 1;
int ret;
ret = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
if (ret < 0)
err("setsockopt SO_KEEPALIVE");
return ret;
}
/* IPv6 Ready */
/*
* moved here from vhci_attach.c
*/
int tcp_connect(char *hostname, char *service)
{
struct addrinfo hints, *res, *res0;
int sockfd;
int err;
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
/* get all possible addresses */
err = getaddrinfo(hostname, service, &hints, &res0);
if (err) {
err("%s %s: %s", hostname, service, gai_strerror(err));
return -1;
}
/* try all the addresses */
for (res = res0; res; res = res->ai_next) {
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
err = getnameinfo(res->ai_addr, res->ai_addrlen,
hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
if (err) {
err("%s %s: %s", hostname, service, gai_strerror(err));
continue;
}
dbg("trying %s port %s\n", hbuf, sbuf);
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd < 0) {
err("socket");
continue;
}
/* should set TCP_NODELAY for usbip */
usbip_set_nodelay(sockfd);
/* TODO: write code for heatbeat */
usbip_set_keepalive(sockfd);
err = connect(sockfd, res->ai_addr, res->ai_addrlen);
if (err < 0) {
close(sockfd);
continue;
}
/* connected */
dbg("connected to %s:%s", hbuf, sbuf);
freeaddrinfo(res0);
return sockfd;
}
dbg("%s:%s, %s", hostname, service, "no destination to connect to");
freeaddrinfo(res0);
return -1;
}
/*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#ifndef _USBIP_NETWORK_H
#define _USBIP_NETWORK_H
#include "usbip.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
/* -------------------------------------------------- */
/* Define Protocol Format */
/* -------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* Common header for all the kinds of PDUs. */
struct op_common {
uint16_t version;
#define OP_REQUEST (0x80 << 8)
#define OP_REPLY (0x00 << 8)
uint16_t code;
/* add more error code */
#define ST_OK 0x00
#define ST_NA 0x01
uint32_t status; /* op_code status (for reply) */
} __attribute__((packed));
#define PACK_OP_COMMON(pack, op_common) do {\
pack_uint16_t(pack, &(op_common)->version);\
pack_uint16_t(pack, &(op_common)->code );\
pack_uint32_t(pack, &(op_common)->status );\
} while (0)
/* ---------------------------------------------------------------------- */
/* Dummy Code */
#define OP_UNSPEC 0x00
#define OP_REQ_UNSPEC OP_UNSPEC
#define OP_REP_UNSPEC OP_UNSPEC
/* ---------------------------------------------------------------------- */
/* Retrieve USB device information. (still not used) */
#define OP_DEVINFO 0x02
#define OP_REQ_DEVINFO (OP_REQUEST | OP_DEVINFO)
#define OP_REP_DEVINFO (OP_REPLY | OP_DEVINFO)
struct op_devinfo_request {
char busid[SYSFS_BUS_ID_SIZE];
} __attribute__((packed));
struct op_devinfo_reply {
struct usb_device udev;
struct usb_interface uinf[];
} __attribute__((packed));
/* ---------------------------------------------------------------------- */
/* Import a remote USB device. */
#define OP_IMPORT 0x03
#define OP_REQ_IMPORT (OP_REQUEST | OP_IMPORT)
#define OP_REP_IMPORT (OP_REPLY | OP_IMPORT)
struct op_import_request {
char busid[SYSFS_BUS_ID_SIZE];
} __attribute__((packed));
struct op_import_reply {
struct usb_device udev;
// struct usb_interface uinf[];
} __attribute__((packed));
#define PACK_OP_IMPORT_REQUEST(pack, request) do {\
} while (0)
#define PACK_OP_IMPORT_REPLY(pack, reply) do {\
pack_usb_device(pack, &(reply)->udev);\
} while (0)
/* ---------------------------------------------------------------------- */
/* Export a USB device to a remote host. */
#define OP_EXPORT 0x06
#define OP_REQ_EXPORT (OP_REQUEST | OP_EXPORT)
#define OP_REP_EXPORT (OP_REPLY | OP_EXPORT)
struct op_export_request {
struct usb_device udev;
} __attribute__((packed));
struct op_export_reply {
int returncode;
} __attribute__((packed));
#define PACK_OP_EXPORT_REQUEST(pack, request) do {\
pack_usb_device(pack, &(request)->udev);\
} while (0)
#define PACK_OP_EXPORT_REPLY(pack, reply) do {\
} while (0)
/* ---------------------------------------------------------------------- */
/* un-Export a USB device from a remote host. */
#define OP_UNEXPORT 0x07
#define OP_REQ_UNEXPORT (OP_REQUEST | OP_UNEXPORT)
#define OP_REP_UNEXPORT (OP_REPLY | OP_UNEXPORT)
struct op_unexport_request {
struct usb_device udev;
} __attribute__((packed));
struct op_unexport_reply {
int returncode;
} __attribute__((packed));
#define PACK_OP_UNEXPORT_REQUEST(pack, request) do {\
pack_usb_device(pack, &(request)->udev);\
} while (0)
#define PACK_OP_UNEXPORT_REPLY(pack, reply) do {\
} while (0)
/* ---------------------------------------------------------------------- */
/* Negotiate IPSec encryption key. (still not used) */
#define OP_CRYPKEY 0x04
#define OP_REQ_CRYPKEY (OP_REQUEST | OP_CRYPKEY)
#define OP_REP_CRYPKEY (OP_REPLY | OP_CRYPKEY)
struct op_crypkey_request {
/* 128bit key */
uint32_t key[4];
} __attribute__((packed));
struct op_crypkey_reply {
uint32_t __reserved;
} __attribute__((packed));
/* ---------------------------------------------------------------------- */
/* Retrieve the list of exported USB devices. */
#define OP_DEVLIST 0x05
#define OP_REQ_DEVLIST (OP_REQUEST | OP_DEVLIST)
#define OP_REP_DEVLIST (OP_REPLY | OP_DEVLIST)
struct op_devlist_request {
} __attribute__((packed));
struct op_devlist_reply {
uint32_t ndev;
/* followed by reply_extra[] */
} __attribute__((packed));
struct op_devlist_reply_extra {
struct usb_device udev;
struct usb_interface uinf[];
} __attribute__((packed));
#define PACK_OP_DEVLIST_REQUEST(pack, request) do {\
} while (0)
#define PACK_OP_DEVLIST_REPLY(pack, reply) do {\
pack_uint32_t(pack, &(reply)->ndev);\
} while (0)
/* -------------------------------------------------- */
/* Declare Prototype Function */
/* -------------------------------------------------- */
void pack_uint32_t(int pack, uint32_t *num);
void pack_uint16_t(int pack, uint16_t *num);
void pack_usb_device(int pack, struct usb_device *udev);
void pack_usb_interface(int pack, struct usb_interface *uinf);
ssize_t usbip_recv(int sockfd, void *buff, size_t bufflen);
ssize_t usbip_send(int sockfd, void *buff, size_t bufflen);
int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status);
int usbip_recv_op_common(int sockfd, uint16_t *code);
int usbip_set_reuseaddr(int sockfd);
int usbip_set_nodelay(int sockfd);
int usbip_set_keepalive(int sockfd);
int tcp_connect(char *hostname, char *service);
#define USBIP_PORT 3240
#define USBIP_PORT_STRING "3240"
#endif
.TH USBIP "8" "February 2009" "usbip" "System Administration Utilities"
.SH NAME
usbipd \- USB/IP server daemon
.SH SYNOPSIS
.B usbipd
[\fIoptions\fR]
.SH DESCRIPTION
.B usbipd
provides USB/IP clients access to exported USB devices.
Devices have to explicitly be exported using
.B usbip_bind_driver
before usbipd makes them available to other hosts.
The daemon accepts connections from USB/IP clients
on TCP port 3240.
.SH OPTIONS
.HP
\fB\-D\fR, \fB\-\-daemon\fR
.IP
Run as a daemon process.
.PP
.HP
\fB\-d\fR, \fB\-\-debug\fR
.IP
Print debugging information.
.PP
.HP
\fB\-v\fR, \fB\-\-version\fR
.IP
Show version.
.PP
.SH LIMITATIONS
.B usbipd
offers no authentication or authorization for USB/IP. Any
USB/IP client can connect and use exported devices.
.SH EXAMPLES
server:# modprobe usbip
server:# usbipd -D
- Start usbip daemon.
server:# usbip_bind_driver --list
- List driver assignments for usb devices.
server:# usbip_bind_driver --usbip 1-2
- Bind usbip.ko to the device of busid 1-2.
- A usb device 1-2 is now exportable to other hosts!
- Use 'usbip_bind_driver --other 1-2' when you want to shutdown exporting and use the device locally.
.SH "SEE ALSO"
\fBusbip\fP\fB(8)\fB\fP,
\fBusbip_attach_driver\fP\fB(8)\fB\fP
This diff is collapsed.
/*
* $Id$
*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#include "utils.h"
int read_integer(char *path)
{
char buff[100];
int fd;
int ret = 0;
bzero(buff, sizeof(buff));
fd = open(path, O_RDONLY);
if (fd < 0)
return -1;
ret = read(fd, buff, sizeof(buff));
if (ret < 0) {
close(fd);
return -1;
}
sscanf(buff, "%d", &ret);
close(fd);
return ret;
}
int read_string(char *path, char *string, size_t len)
{
int fd;
int ret = 0;
char *p;
bzero(string, len);
fd = open(path, O_RDONLY);
if (fd < 0) {
string = NULL;
return -1;
}
ret = read(fd, string, len-1);
if (ret < 0) {
string = NULL;
close(fd);
return -1;
}
p = strchr(string, '\n');
*p = '\0';
close(fd);
return 0;
}
int write_integer(char *path, int value)
{
int fd;
int ret;
char buff[100];
snprintf(buff, sizeof(buff), "%d", value);
fd = open(path, O_WRONLY);
if (fd < 0)
return -1;
ret = write(fd, buff, strlen(buff));
if (ret < 0) {
close(fd);
return -1;
}
close(fd);
return 0;
}
int read_bConfigurationValue(char *busid)
{
char path[PATH_MAX];
snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bConfigurationValue", busid);
return read_integer(path);
}
int write_bConfigurationValue(char *busid, int config)
{
char path[PATH_MAX];
snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bConfigurationValue", busid);
return write_integer(path, config);
}
int read_bNumInterfaces(char *busid)
{
char path[PATH_MAX];
snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bNumInterfaces", busid);
return read_integer(path);
}
int read_bDeviceClass(char *busid)
{
char path[PATH_MAX];
snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bDeviceClass", busid);
return read_integer(path);
}
int getdriver(char *busid, int conf, int infnum, char *driver, size_t len)
{
char path[PATH_MAX];
char linkto[PATH_MAX];
int ret;
snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s:%d.%d/driver", busid, conf, infnum);
/* readlink does not add NULL */
bzero(linkto, sizeof(linkto));
ret = readlink(path, linkto, sizeof(linkto)-1);
if (ret < 0) {
strncpy(driver, "none", len);
return -1;
} else {
strncpy(driver, basename(linkto), len);
return 0;
}
}
int getdevicename(char *busid, char *name, size_t len)
{
char path[PATH_MAX];
char idProduct[10], idVendor[10];
snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/idVendor", busid);
read_string(path, idVendor, sizeof(idVendor));
snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/idProduct", busid);
read_string(path, idProduct, sizeof(idProduct));
if (!idVendor[0] || !idProduct[0])
return -1;
snprintf(name, len, "%s:%s", idVendor, idProduct);
return 0;
}
#define MAXLINE 100
/* if this cannot read a whole line, return -1 */
int readline(int sockfd, char *buff, int bufflen)
{
int ret;
char c;
int index = 0;
while (index < bufflen) {
ret = read(sockfd, &c, sizeof(c));
if (ret < 0 && errno == EINTR)
continue;
if (ret <= 0) {
return -1;
}
buff[index] = c;
if ( index > 0 && buff[index-1] == '\r' && buff[index] == '\n') {
/* end of line */
buff[index-1] = '\0'; /* get rid of delimitor */
return index;
} else
index++;
}
return -1;
}
#if 0
int writeline(int sockfd, char *str, int strlen)
{
int ret;
int index = 0;
int len;
char buff[MAXLINE];
if (strlen + 3 > MAXLINE)
return -1;
strncpy(buff, str, strlen);
buff[strlen+1] = '\r';
buff[strlen+2] = '\n';
buff[strlen+3] = '\0';
len = strlen + 3;
while (len > 0) {
ret = write(sockfd, buff+index, len);
if (ret <= 0) {
return -1;
}
len -= ret;
index += ret;
}
return index;
}
#endif
int writeline(int sockfd, char *str, int strlen)
{
int ret;
int index = 0;
int len;
char buff[MAXLINE];
len = strnlen(str, strlen);
if (strlen + 2 > MAXLINE)
return -1;
memcpy(buff, str, strlen);
buff[strlen] = '\r';
buff[strlen+1] = '\n'; /* strlen+1 <= MAXLINE-1 */
len = strlen + 2;
while (len > 0) {
ret = write(sockfd, buff+index, len);
if (ret < 0 && errno == EINTR)
continue;
if (ret <= 0) {
return -1;
}
len -= ret;
index += ret;
}
return index;
}
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#define _GNU_SOURCE
#include <string.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sysfs/libsysfs.h>
#include <glib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
/* Be sync to kernel header */
#define BUS_ID_SIZE 20
int read_string(char *path, char *, size_t len);
int read_integer(char *path);
int getdevicename(char *busid, char *name, size_t len);
int getdriver(char *busid, int conf, int infnum, char *driver, size_t len);
int read_bNumInterfaces(char *busid);
int read_bConfigurationValue(char *busid);
int write_integer(char *path, int value);
int write_bConfigurationValue(char *busid, int config);
int read_bDeviceClass(char *busid);
int readline(int sockfd, char *str, int strlen);
int writeline(int sockfd, char *buff, int bufflen);
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_REVISION($Id$)
AC_INIT(usbip, 0.1.8, usbip-devel@lists.sourceforge.net)
AC_DEFINE(USBIP_VERSION, 0x000106, Numeric version number)
AC_CONFIG_SRCDIR([config.h.in])
AM_INIT_AUTOMAKE([foreign])
# Silent build for automake >= 1.11
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AM_CONFIG_HEADER(config.h)
AC_SUBST([EXTRA_CFLAGS])
AC_PROG_LIBTOOL
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
# Checks for libraries.
# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h netdb.h stdint.h stdlib.h string.h strings.h sys/socket.h syslog.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([bzero memset strchr strerror strstr strtoul])
AC_CHECK_HEADER(sysfs/libsysfs.h,
[AC_CHECK_LIB(sysfs, sysfs_open_directory_list,
[LIBS="$LIBS -lsysfs"],
[AC_MSG_ERROR([Missing sysfs2 library!])])],
[AC_MSG_ERROR([Missing /usr/include/sysfs/libsysfs.h])])
# get from stunnel
dnl Check for libwrap library.
AC_MSG_CHECKING([whether to use the libwrap (TCP wrappers) library])
AC_ARG_WITH(tcp-wrappers,
[ --with-tcp-wrappers Use the libwrap (TCP wrappers) library ],
[saved_LIBS="$LIBS"
if test "$withval" = "yes"; then
AC_MSG_RESULT([yes])
AC_MSG_CHECKING([for hosts_access in -lwrap])
LIBS="-lwrap $LIBS"
AC_TRY_LINK(
[int hosts_access(); int allow_severity, deny_severity;],
[hosts_access()],
[AC_MSG_RESULT([yes]); AC_DEFINE(HAVE_LIBWRAP, 1, use tcp wrapper) wrap_LIB="-lwrap"],
[AC_MSG_RESULT([not found]); exit 1])
else
AC_MSG_RESULT([no])
fi
LIBS="$saved_LIBS"],
[AC_MSG_RESULT([(default)])
AC_MSG_CHECKING([for hosts_access in -lwrap])
saved_LIBS="$LIBS"
LIBS="-lwrap $saved_LIBS"
AC_TRY_LINK(
[int hosts_access(); int allow_severity, deny_severity;],
[hosts_access()],
[AC_MSG_RESULT([yes]); AC_DEFINE(HAVE_LIBWRAP, 1, use tcp wrapper)],
[AC_MSG_RESULT([no]); LIBS="$saved_LIBS"])
])
USBIDS_DIR='${datadir}/usbip'
AC_ARG_WITH(usbids-dir, [ --with-usbids-dir=DIR where usb.ids is found (default ${datadir}/usbip)], [USBIDS_DIR=$withval])
AC_SUBST(USBIDS_DIR)
dnl FIXME: when disabled, empty directry is created
usbids=install
AC_ARG_ENABLE(usbids-install,
[ --enable-usbids-install install usb.ids (default)],
[case "${enableval}" in
yes) usbids=install ;;
no) usbids=notinstall ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-usbids-install) ;;
esac])
AM_CONDITIONAL(INSTALL_USBIDS, test x$usbids = xinstall)
GLIB2_REQUIRED=2.6.0
PKG_CHECK_MODULES(PACKAGE, glib-2.0 >= $GLIB2_REQUIRED)
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
AC_CONFIG_FILES([Makefile lib/Makefile cmd/Makefile])
AC_OUTPUT
# AM_CFLAGS = -Wall -std=gnu99
lib_LTLIBRARIES = libusbip.la
libusbip_la_SOURCES = names.c names.h stub_driver.c stub_driver.h usbip.h usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h
#libusbip_la_SOURCES = names.c names.h stub_driver.c usbip_common.c vhci_driver.c
#INCLUDES = -I../include
#AM_CPPFLAGS = -I../include -Wall -std=gnu99
libusbip_la_LDFLAGS = -version-info 0:1:0
EXTRA_CFLAGS = @EXTRA_CFLAGS@
libusbip_la_CFLAGS = -Wall -W -Wstrict-prototypes -std=gnu99 $(EXTRA_CFLAGS) -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
This diff is collapsed.
/*****************************************************************************/
/*
* names.h -- USB name database manipulation routines
*
* Copyright (C) 1999, 2000 Thomas Sailer (sailer@ife.ee.ethz.ch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
*/
/*
* Copyright (C) 2005 Takahiro Hirofuchi
* - names_free() is added.
*/
/*****************************************************************************/
#ifndef _NAMES_H
#define _NAMES_H
#include <sys/types.h>
/* ---------------------------------------------------------------------- */
extern const char *names_vendor(u_int16_t vendorid);
extern const char *names_product(u_int16_t vendorid, u_int16_t productid);
extern const char *names_class(u_int8_t classid);
extern const char *names_subclass(u_int8_t classid, u_int8_t subclassid);
extern const char *names_protocol(u_int8_t classid, u_int8_t subclassid, u_int8_t protocolid);
extern const char *names_audioterminal(u_int16_t termt);
extern const char *names_hid(u_int8_t hidd);
extern const char *names_reporttag(u_int8_t rt);
extern const char *names_huts(unsigned int data);
extern const char *names_hutus(unsigned int data);
extern const char *names_langid(u_int16_t langid);
extern const char *names_physdes(u_int8_t ph);
extern const char *names_bias(u_int8_t b);
extern const char *names_countrycode(unsigned int countrycode);
extern int names_init(char *n);
extern void names_free(void);
/* ---------------------------------------------------------------------- */
#endif /* _NAMES_H */
This diff is collapsed.
/*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#ifndef _USBIP_STUB_DRIVER_H
#define _USBIP_STUB_DRIVER_H
#include "usbip.h"
struct usbip_stub_driver {
int ndevs;
struct sysfs_driver *sysfs_driver;
struct dlist *edev_list; /* list of exported device */
};
struct usbip_exported_device {
struct sysfs_device *sudev;
int32_t status;
struct usb_device udev;
struct usb_interface uinf[];
};
extern struct usbip_stub_driver *stub_driver;
int usbip_stub_driver_open(void);
void usbip_stub_driver_close(void);
int usbip_stub_refresh_device_list(void);
int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd);
struct usbip_exported_device *usbip_stub_get_device(int num);
#endif
/*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#ifndef _USBIP_H
#define _USBIP_H
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include "usbip_common.h"
#include "stub_driver.h"
#include "vhci_driver.h"
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#endif
This diff is collapsed.
/*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#ifndef _USBIP_COMMON_H
#define _USBIP_COMMON_H
#include <unistd.h>
#include <stdint.h>
#include <syslog.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <sysfs/libsysfs.h>
#include <netdb.h>
#include <sys/socket.h>
#ifndef USBIDS_FILE
#define USBIDS_FILE "/usr/share/hwdata/usb.ids"
#endif
#ifndef VHCI_STATE_PATH
#define VHCI_STATE_PATH "/var/run/vhci_hcd"
#endif
//#include <linux/usb_ch9.h>
enum usb_device_speed {
USB_SPEED_UNKNOWN = 0, /* enumerating */
USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
USB_SPEED_HIGH, /* usb 2.0 */
USB_SPEED_VARIABLE /* wireless (usb 2.5) */
};
/* FIXME: how to sync with drivers/usbip_common.h ? */
enum usbip_device_status{
/* sdev is available. */
SDEV_ST_AVAILABLE = 0x01,
/* sdev is now used. */
SDEV_ST_USED,
/* sdev is unusable because of a fatal error. */
SDEV_ST_ERROR,
/* vdev does not connect a remote device. */
VDEV_ST_NULL,
/* vdev is used, but the USB address is not assigned yet */
VDEV_ST_NOTASSIGNED,
VDEV_ST_USED,
VDEV_ST_ERROR
};
extern int usbip_use_syslog;
extern int usbip_use_stderr;
extern int usbip_use_debug ;
#define err(fmt, args...) do { \
if (usbip_use_syslog) { \
syslog(LOG_ERR, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
__FILE__, __LINE__, __FUNCTION__, ##args); \
} \
if (usbip_use_stderr) { \
fprintf(stderr, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
__FILE__, __LINE__, __FUNCTION__, ##args); \
} \
} while (0)
#define notice(fmt, args...) do { \
if (usbip_use_syslog) { \
syslog(LOG_DEBUG, "usbip: " fmt, ##args); \
} \
if (usbip_use_stderr) { \
fprintf(stderr, "usbip: " fmt "\n", ##args); \
} \
} while (0)
#define info(fmt, args...) do { \
if (usbip_use_syslog) { \
syslog(LOG_DEBUG, fmt, ##args); \
} \
if (usbip_use_stderr) { \
fprintf(stderr, fmt "\n", ##args); \
} \
} while (0)
#define dbg(fmt, args...) do { \
if (usbip_use_debug) { \
if (usbip_use_syslog) { \
syslog(LOG_DEBUG, "usbip dbg: %13s:%4d (%-12s) " fmt, \
__FILE__, __LINE__, __FUNCTION__, ##args); \
} \
if (usbip_use_stderr) { \
fprintf(stderr, "usbip dbg: %13s:%4d (%-12s) " fmt "\n", \
__FILE__, __LINE__, __FUNCTION__, ##args); \
} \
} \
} while (0)
#define BUG() do { err("sorry, it's a bug"); abort(); } while (0)
struct usb_interface {
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t padding; /* alignment */
} __attribute__((packed));
struct usb_device {
char path[SYSFS_PATH_MAX];
char busid[SYSFS_BUS_ID_SIZE];
uint32_t busnum;
uint32_t devnum;
uint32_t speed;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bConfigurationValue;
uint8_t bNumConfigurations;
uint8_t bNumInterfaces;
} __attribute__((packed));
#define to_string(s) #s
void dump_usb_interface(struct usb_interface *);
void dump_usb_device(struct usb_device *);
int read_usb_device(struct sysfs_device *sdev, struct usb_device *udev);
int read_attr_value(struct sysfs_device *dev, const char *name, const char *format);
int read_usb_interface(struct usb_device *udev, int i, struct usb_interface *uinf);
const char *usbip_speed_string(int num);
const char *usbip_status_string(int32_t status);
int usbip_names_init(char *);
void usbip_names_free(void);
void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t product);
void usbip_names_get_class(char *buff, size_t size, uint8_t class, uint8_t subclass, uint8_t protocol);
#endif
This diff is collapsed.
/*
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
#ifndef _VHCI_DRIVER_H
#define _VHCI_DRIVER_H
#include "usbip.h"
#define MAXNPORT 128
struct class_device {
char clspath[SYSFS_PATH_MAX];
char devpath[SYSFS_PATH_MAX];
};
struct usbip_imported_device {
uint8_t port;
uint32_t status;
uint32_t devid;
uint8_t busnum;
uint8_t devnum;
struct dlist *cdev_list; /* list of class device */
struct usb_device udev;
};
struct usbip_vhci_driver {
char sysfs_mntpath[SYSFS_PATH_MAX];
struct sysfs_device *hc_device; /* /sys/devices/platform/vhci_hcd */
struct dlist *cdev_list; /* list of class device */
int nports;
struct usbip_imported_device idev[MAXNPORT];
};
extern struct usbip_vhci_driver *vhci_driver;
int usbip_vhci_driver_open(void);
void usbip_vhci_driver_close(void);
int usbip_vhci_refresh_device_list(void);
int usbip_vhci_get_free_port(void);
int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
uint32_t speed);
/* will be removed */
int usbip_vhci_attach_device(uint8_t port, int sockfd, uint8_t busnum,
uint8_t devnum, uint32_t speed);
int usbip_vhci_detach_device(uint8_t port);
#endif
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment