usbip: userspace improvements
cover usbip: userspace improvements
Hi Greg,
Here is a series to go in your queue until you have time to look at them and open up your tree for patches. The major patch in the series is userspace tools v1.0.0. There is a _lot_ of work left to improve the userspace stuff, but this is what I think is a big step in the right direction, which will lead into major work in the kernel code.
I would also like to let you guys know (Arjan!) that I am working on a draft of a protocol for usbip. This will attempt to provide a well-defined and unified userspace and kernel protocol, along with providing some documentation of what usbip is doing, which seems to be in high demand. The goal is to have interoperability between different systems without the need to have the same implementation. I will post a draft soon so that everyone interested can help me refine it. Unfortunately, I am going out of town for the next few days, so I am not exactly sure when that will be.
Thanks,
matt
matt mooney (6):
staging: usbip: userspace: set kernel module names in one place
staging: usbip: userspace: change struct class_device to
usbip_class_device
staging: usbip: userspace: vhci_driver: parameterize path names
staging: usbip: userspace tools v1.0.0
staging: usbip: userspace: usbipd.c: add header into source file
staging: usbip: userspace: usbip_network: rename and cleanup function
drivers/staging/usbip/userspace/configure.ac | 4 +- .../staging/usbip/userspace/libsrc/stub_driver.c | 12 +- .../staging/usbip/userspace/libsrc/usbip_common.h | 6 +- .../staging/usbip/userspace/libsrc/vhci_driver.c | 76 ++- .../staging/usbip/userspace/libsrc/vhci_driver.h | 19 +- drivers/staging/usbip/userspace/src/Makefile.am | 11 +- drivers/staging/usbip/userspace/src/bind-driver.c | 643 ---------------- drivers/staging/usbip/userspace/src/usbip.c | 813 ++++---------------- drivers/staging/usbip/userspace/src/usbip.h | 39 + drivers/staging/usbip/userspace/src/usbip_attach.c | 228 ++++++ drivers/staging/usbip/userspace/src/usbip_bind.c | 261 +++++++ drivers/staging/usbip/userspace/src/usbip_detach.c | 103 +++ drivers/staging/usbip/userspace/src/usbip_list.c | 306 ++++++++ .../staging/usbip/userspace/src/usbip_network.c | 73 +- .../staging/usbip/userspace/src/usbip_network.h | 37 +- drivers/staging/usbip/userspace/src/usbip_unbind.c | 95 +++ drivers/staging/usbip/userspace/src/usbipd.c | 8 +- drivers/staging/usbip/userspace/src/utils.c | 60 ++- drivers/staging/usbip/userspace/src/utils.h | 1 + 19 files changed, 1347 insertions(+), 1448 deletions(-) delete mode 100644 drivers/staging/usbip/userspace/src/bind-driver.c create mode 100644 drivers/staging/usbip/userspace/src/usbip.h create mode 100644 drivers/staging/usbip/userspace/src/usbip_attach.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_bind.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_detach.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_list.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_unbind.c
Signature · 1 line
1.7.5.1
PATCH 1/6 staging: usbip: userspace: set kernel module names in one place
Move kernel module name setting to usbip_common.h so that macros can be used instead of hard coding the names in multiple places.
--- .../staging/usbip/userspace/libsrc/stub_driver.c | 12 ++++------ .../staging/usbip/userspace/libsrc/usbip_common.h | 6 ++++- .../staging/usbip/userspace/libsrc/vhci_driver.c | 8 ++---- drivers/staging/usbip/userspace/src/bind-driver.c | 23 +++++++++++++------ 4 files changed, 29 insertions(+), 20 deletions(-)
drivers/staging/usbip/userspace/libsrc/stub_driver.c +5 -7
@@ -8,10 +8,6 @@#include "usbip.h" -/* kernel module name */ -static const char *usbip_stub_driver_name ="usbip-host" ; - -struct usbip_stub_driver *stub_driver;static struct sysfs_driver *open_sysfs_stub_driver (void )
@@ -31,11 +27,12 @@ static struct sysfs_driver *open_sysfs_stub_driver(void)snprintf (stub_driver_path,SYSFS_PATH_MAX ,"%s/%s/usb/%s/%s" , sysfs_mntpath,SYSFS_BUS_NAME ,SYSFS_DRIVERS_NAME , - usbip_stub_driver_name); +USBIP_HOST_DRV_NAME ); stub_driver =sysfs_open_driver_path (stub_driver_path);if (!stub_driver) { -err ("usbip-core.ko and usbip-host.ko must be loaded" ); +err (USBIP_CORE_MOD_NAME ".ko and " USBIP_HOST_DRV_NAME +".ko must be loaded" );return NULL ; }
@@ -200,7 +197,8 @@ static int refresh_exported_devices(void) suinf_list =sysfs_get_driver_devices (stub_driver->sysfs_driver);if (!suinf_list) { -printf ("Bind usbip-host.ko to a usb device to be exportable!\n" ); +info ("bind " USBIP_HOST_DRV_NAME ".ko to a usb device to be " +"exportable!\n" ); goto bye; }
drivers/staging/usbip/userspace/libsrc/usbip_common.h +5 -1
@@ -26,7 +26,11 @@#define VHCI_STATE_PATH "/var/run/vhci_hcd"#endif -//#include <linux/usb_ch9.h> +/* kernel module names */ +#define USBIP_CORE_MOD_NAME "usbip-core" +#define USBIP_HOST_DRV_NAME "usbip-host" +#define USBIP_VHCI_DRV_NAME "vhci_hcd" +enum usb_device_speed {USB_SPEED_UNKNOWN =0 ,/* enumerating */ USB_SPEED_LOW ,USB_SPEED_FULL ,/* usb 1.1 */
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +3 -5
@@ -5,9 +5,6 @@#include "usbip.h" - -static const char vhci_driver_name[] ="vhci_hcd" ; -struct usbip_vhci_driver *vhci_driver;static struct usbip_imported_device *imported_device_init (struct usbip_imported_device *idev,char *busid)
@@ -277,12 +274,13 @@ static int get_hc_busid(char *sysfs_mntpath, char *hc_busid)snprintf (sdriver_path,SYSFS_PATH_MAX ,"%s/%s/platform/%s/%s" , sysfs_mntpath,SYSFS_BUS_NAME ,SYSFS_DRIVERS_NAME , - vhci_driver_name); +USBIP_VHCI_DRV_NAME ); sdriver =sysfs_open_driver_path (sdriver_path);if (!sdriver) {info ("%s is not found" , sdriver_path); -info ("load usbip-core.ko and vhci-hcd.ko !" ); +info ("please load " USBIP_CORE_MOD_NAME ".ko and " +USBIP_VHCI_DRV_NAME ".ko!" );return -1 ; }
drivers/staging/usbip/userspace/src/bind-driver.c +16 -7
@@ -3,13 +3,12 @@* Copyright (C) 2005-2007 Takahiro Hirofuchi */ -#include "utils.h" -#define _GNU_SOURCE#include <getopt.h> #include <glib.h> - +#include "usbip.h" +#include "utils.h" static const struct option longopts[] = { {"usbip" , required_argument,NULL ,'u' },
@@ -27,9 +26,6 @@ static const struct option longopts[] = { {NULL, 0, NULL, 0} }; -static const char match_busid_path[] ="/sys/bus/usb/drivers/usbip-host/match_busid" ; - -static void show_help (void ) {printf ("Usage: usbip_bind_driver [OPTION]\n" );
@@ -51,6 +47,18 @@ static int modify_match_busid(char *busid, int add)int fd;int ret;char buff[BUS_ID_SIZE +4 ]; +char sysfs_mntpath[SYSFS_PATH_MAX ]; +char match_busid_path[SYSFS_PATH_MAX ]; + + ret =sysfs_get_mnt_path (sysfs_mntpath,SYSFS_PATH_MAX ); +if (ret <0 ) { +err ("sysfs must be mounted" ); +return -1 ; + } + +snprintf (match_busid_path,sizeof (match_busid_path), +"%s/%s/usb/%s/%s/match_busid" , sysfs_mntpath,SYSFS_BUS_NAME , +SYSFS_DRIVERS_NAME ,USBIP_HOST_DRV_NAME );/* BUS_IS_SIZE includes NULL termination? */ if (strnlen (busid,BUS_ID_SIZE ) >BUS_ID_SIZE -1 ) {
@@ -228,7 +236,8 @@ static int bind_to_usbip(char *busid)for (i =0 ; i < ninterface; i++) {int ret; - ret =bind_interface (busid, configvalue, i,"usbip-host" ); + ret =bind_interface (busid, configvalue, i, +USBIP_HOST_DRV_NAME );if (ret <0 ) {g_warning ("bind usbip at %s:%d.%d, failed" , busid, configvalue, i);
Signature · 1 line
1.7.5.1
PATCH 2/6 staging: usbip: userspace: change struct class_device to usbip_class_device
In reply to matt mooneyRename class_device struct to avoid confusion and change member names.
--- .../staging/usbip/userspace/libsrc/vhci_driver.c | 48 ++++++++++--------- .../staging/usbip/userspace/libsrc/vhci_driver.h | 17 ++++--- drivers/staging/usbip/userspace/src/usbip.c | 9 ++-- 3 files changed, 40 insertions(+), 34 deletions(-)
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +25 -23
@@ -20,10 +20,12 @@ static struct usbip_imported_device *imported_device_init(struct usbip_imported_sysfs_close_device (sudev);/* add class devices of this imported device */ -struct class_device *cdev; - dlist_for_each_data(vhci_driver->cdev_list, cdev, struct class_device) { -if (!strncmp (cdev->devpath, idev->udev.path,strlen (idev->udev.path))) { -struct class_device *new_cdev; +struct usbip_class_device *cdev; +dlist_for_each_data (vhci_driver->cdev_list, cdev, + struct usbip_class_device) { +if (!strncmp (cdev->dev_path, idev->udev.path, +strlen (idev->udev.path))) { +struct usbip_class_device *new_cdev;/* alloc and copy because dlist is linked from only one list */ new_cdev =calloc (1 ,sizeof (*new_cdev));
@@ -87,7 +89,7 @@ static int parse_status(char *value) idev->busnum = (devid >>16 ); idev->devnum = (devid &0x0000ffff ); - idev->cdev_list =dlist_new (sizeof (struct class_device )); + idev->cdev_list =dlist_new (sizeof (struct usbip_class_device ));if (!idev->cdev_list) {err ("init new device" );return -1 ;
@@ -115,29 +117,29 @@ static int parse_status(char *value)static int check_usbip_device (struct sysfs_class_device *cdev) { -char clspath[SYSFS_PATH_MAX ];/* /sys/class/video4linux/video0/device */ -char devpath[SYSFS_PATH_MAX ];/* /sys/devices/platform/vhci_hcd/usb6/6-1:1.1 */ - +char class_path[SYSFS_PATH_MAX ];/* /sys/class/video4linux/video0/device */ +char dev_path[SYSFS_PATH_MAX ];/* /sys/devices/platform/vhci_hcd/usb6/6-1:1.1 */ int ret; +struct usbip_class_device *usbip_cdev; -snprintf (clspath,sizeof (clspath),"%s/device" , cdev->path); +snprintf (class_path,sizeof (class_path),"%s/device" , cdev->path); - ret =sysfs_get_link (clspath, devpath,SYSFS_PATH_MAX ); -if (!ret) { -if (!strncmp (devpath, vhci_driver->hc_device->path, -strlen (vhci_driver->hc_device->path))) { + ret =sysfs_get_link (class_path, dev_path,sizeof (dev_path)); +if (ret ==0 ) { +if (!strncmp (dev_path, vhci_driver->hc_device->path, +strlen (vhci_driver->hc_device->path))) {/* found usbip device */ -struct class_device *cdev; - - cdev =calloc (1 ,sizeof (*cdev)); + usbip_cdev =calloc (1 ,sizeof (*usbip_cdev));if (!cdev) { -err ("calloc cdev" ); +err ("calloc usbip_cdev" );return -1 ; } -dlist_unshift (vhci_driver->cdev_list, (void *) cdev); -strncpy (cdev->clspath, clspath,sizeof (cdev->clspath)); -strncpy (cdev->devpath, devpath,sizeof (cdev->clspath)); -dbg (" found %s %s" , clspath, devpath); +dlist_unshift (vhci_driver->cdev_list, usbip_cdev); +strncpy (usbip_cdev->class_path, class_path, +sizeof (usbip_cdev->class_path)); +strncpy (usbip_cdev->dev_path, dev_path, +sizeof (usbip_cdev->dev_path)); +dbg (" found %s %s" , class_path, dev_path); } }
@@ -341,7 +343,7 @@ int usbip_vhci_driver_open(void)info ("%d ports available\n" , vhci_driver->nports); - vhci_driver->cdev_list =dlist_new (sizeof (struct class_device )); + vhci_driver->cdev_list =dlist_new (sizeof (struct usbip_class_device ));if (!vhci_driver->cdev_list) goto err;
@@ -400,7 +402,7 @@ int usbip_vhci_refresh_device_list(void)dlist_destroy (vhci_driver->idev[i].cdev_list); } - vhci_driver->cdev_list =dlist_new (sizeof (struct class_device )); + vhci_driver->cdev_list =dlist_new (sizeof (struct usbip_class_device ));if (!vhci_driver->cdev_list) goto err;
drivers/staging/usbip/userspace/libsrc/vhci_driver.h +10 -7
@@ -11,9 +11,9 @@#define MAXNPORT 128 -struct class_device { -char clspath[SYSFS_PATH_MAX ]; -char devpath[SYSFS_PATH_MAX ]; +struct usbip_class_device { +char class_path[SYSFS_PATH_MAX ]; +char dev_path[SYSFS_PATH_MAX ]; };struct usbip_imported_device {
@@ -25,16 +25,19 @@ struct usbip_imported_device {uint8_t busnum;uint8_t devnum; - -struct dlist *cdev_list;/* list of class device */ +/* usbip_class_device list */ +struct dlist *cdev_list;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 */ +/* /sys/devices/platform/vhci_hcd */ +struct sysfs_device *hc_device; + +/* usbip_class_device list */ +struct dlist *cdev_list;int nports;struct usbip_imported_device idev[MAXNPORT ];
drivers/staging/usbip/userspace/src/usbip.c +5 -4
@@ -174,12 +174,13 @@ int usbip_vhci_imported_device_dump(struct usbip_imported_device *idev)sysfs_close_device (suinf);/* show class device information */ -struct class_device *cdev; +struct usbip_class_device *cdev; - dlist_for_each_data(idev->cdev_list, cdev, struct class_device) { -int ifnum =get_interface_number (cdev->devpath); +dlist_for_each_data (idev->cdev_list, cdev, + struct usbip_class_device) { +int ifnum =get_interface_number (cdev->dev_path);if (ifnum == i) { -info (" %s" , cdev->clspath); +info (" %s" , cdev->class_path); } } }
Signature · 1 line
1.7.5.1
PATCH 3/6 staging: usbip: userspace: vhci_driver: parameterize path names
In reply to matt mooneyDefine a macro for the bus type and use libsysfs for class path.
--- .../staging/usbip/userspace/libsrc/vhci_driver.c | 22 +++++++++++++++---- .../staging/usbip/userspace/libsrc/vhci_driver.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-)
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +17 -5
@@ -186,9 +186,20 @@ static int refresh_class_device_list(void)int ret;struct dlist *cname_list;char *cname; +char sysfs_mntpath[SYSFS_PATH_MAX ]; +char class_path[SYSFS_PATH_MAX ]; + + ret =sysfs_get_mnt_path (sysfs_mntpath,SYSFS_PATH_MAX ); +if (ret <0 ) { +err ("sysfs must be mounted" ); +return -1 ; + } + +snprintf (class_path,sizeof (class_path),"%s/%s" , sysfs_mntpath, +SYSFS_CLASS_NAME );/* search under /sys/class */ - cname_list =sysfs_open_directory_list ("/sys/class" ); + cname_list =sysfs_open_directory_list (class_path);if (!cname_list) {err ("open class directory" );return -1 ;
@@ -274,9 +285,9 @@ static int get_hc_busid(char *sysfs_mntpath, char *hc_busid)int found =0 ; -snprintf (sdriver_path,SYSFS_PATH_MAX ,"%s/%s/platform/%s/%s" , - sysfs_mntpath,SYSFS_BUS_NAME ,SYSFS_DRIVERS_NAME , -USBIP_VHCI_DRV_NAME ); +snprintf (sdriver_path,SYSFS_PATH_MAX ,"%s/%s/%s/%s/%s" , sysfs_mntpath, +SYSFS_BUS_NAME ,USBIP_VHCI_BUS_TYPE ,SYSFS_DRIVERS_NAME , +USBIP_VHCI_DRV_NAME ); sdriver =sysfs_open_driver_path (sdriver_path);if (!sdriver) {
@@ -333,7 +344,8 @@ int usbip_vhci_driver_open(void) goto err;/* will be freed in usbip_driver_close() */ - vhci_driver->hc_device =sysfs_open_device ("platform" , hc_busid); + vhci_driver->hc_device =sysfs_open_device (USBIP_VHCI_BUS_TYPE , + hc_busid);if (!vhci_driver->hc_device) {err ("get sysfs vhci_driver" ); goto err;
drivers/staging/usbip/userspace/libsrc/vhci_driver.h +1 -1
@@ -7,7 +7,7 @@#include "usbip.h" - +#define USBIP_VHCI_BUS_TYPE "platform"#define MAXNPORT 128
Signature · 1 line
1.7.5.1
PATCH 4/6 staging: usbip: userspace tools v1.0.0
In reply to matt mooneyThe new and improved (well somewhat, with a ways to go) userspace utility.
mfm:pts/8[~/tmp/userspace]
May26 05:18:31 % ./src/usbip help
usage: usbip [--debug] [version]
[help] <command> <args>
attach Attach a remote USB device
detach Detach a remote USB device
list List exported or local USB devices
bind Bind device to usbip-host.ko
unbind Unbind device from usbip-host.ko
This first commit of the userspace usbip' utility uses to same implementation as the old tools, usbip' and `usbip_bind_driver'. Nothing significant has changed so compatibility with windows has _not_ been broken. However, the tools remain broken in many ways due to the old implementation.
--- drivers/staging/usbip/userspace/configure.ac | 4 +- drivers/staging/usbip/userspace/src/Makefile.am | 11 +- drivers/staging/usbip/userspace/src/bind-driver.c | 652 ---------------- drivers/staging/usbip/userspace/src/usbip.c | 814 ++++---------------- drivers/staging/usbip/userspace/src/usbip.h | 39 + drivers/staging/usbip/userspace/src/usbip_attach.c | 228 ++++++ drivers/staging/usbip/userspace/src/usbip_bind.c | 261 +++++++ drivers/staging/usbip/userspace/src/usbip_detach.c | 103 +++ drivers/staging/usbip/userspace/src/usbip_list.c | 306 ++++++++ drivers/staging/usbip/userspace/src/usbip_unbind.c | 95 +++ drivers/staging/usbip/userspace/src/utils.c | 60 ++- drivers/staging/usbip/userspace/src/utils.h | 1 + 12 files changed, 1233 insertions(+), 1341 deletions(-) delete mode 100644 drivers/staging/usbip/userspace/src/bind-driver.c create mode 100644 drivers/staging/usbip/userspace/src/usbip.h create mode 100644 drivers/staging/usbip/userspace/src/usbip_attach.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_bind.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_detach.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_list.c create mode 100644 drivers/staging/usbip/userspace/src/usbip_unbind.c
drivers/staging/usbip/userspace/configure.ac +2 -2
@@ -1,8 +1,8 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([usbip], [0.1.8], [[email protected]]) -AC_DEFINE([USBIP_VERSION], [0x000106], [numeric version number]) +AC_INIT([usbip], [1.0.0], [[email protected]]) +AC_DEFINE([USBIP_VERSION], [0x00000100], [binary-coded decimal version number]) CURRENT=0 REVISION=1
drivers/staging/usbip/userspace/src/Makefile.am +6 -5
@@ -2,9 +2,10 @@ AM_CPPFLAGS := -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' AM_CFLAGS := @EXTRA_CFLAGS@ @PACKAGE_CFLAGS@ LDADD := $(top_srcdir)/libsrc/libusbip.la @PACKAGE_LIBS@ -sbin_PROGRAMS := usbip usbipd usbip_bind_driver +sbin_PROGRAMS := usbip usbipd -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 +usbip_SOURCES := usbip.c utils.c usbip_network.c \ + usbip_attach.c usbip_detach.c usbip_list.c \ + usbip_bind.c usbip_unbind.c + +usbipd_SOURCES := usbipd.c usbip_network.c
drivers/staging/usbip/userspace/src/bind-driver.c deleted +0 -652
652 lines not on this page · raw message
drivers/staging/usbip/userspace/src/usbip.c +135 -679
859 lines not on this page · raw message
drivers/staging/usbip/userspace/src/usbip.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (C) 2011 matt mooney <[email protected]> +* 2005-2007 Takahiro Hirofuchi +* +* 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __USBIP_H +#define __USBIP_H + +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif + +/* usbip commands */ +int usbip_attach (int argc,char *argv[]); +int usbip_detach (int argc,char *argv[]); +int usbip_list (int argc,char *argv[]); +int usbip_bind (int argc,char *argv[]); +int usbip_unbind (int argc,char *argv[]); + +void usbip_attach_usage (void ); +void usbip_detach_usage (void ); +void usbip_list_usage (void ); +void usbip_bind_usage (void ); +void usbip_unbind_usage (void ); + +#endif /* __USBIP_H */
drivers/staging/usbip/userspace/src/usbip_attach.c new file +228 -0
228 lines not on this page · raw message
drivers/staging/usbip/userspace/src/usbip_bind.c new file +261 -0
261 lines not on this page · raw message
drivers/staging/usbip/userspace/src/usbip_detach.c new file +103 -0
103 lines not on this page · raw message
drivers/staging/usbip/userspace/src/usbip_list.c new file +306 -0
306 lines not on this page · raw message
drivers/staging/usbip/userspace/src/usbip_unbind.c new file +95 -0
95 lines not on this page · raw message
drivers/staging/usbip/userspace/src/utils.c +57 -3
87 lines not on this page · raw message
drivers/staging/usbip/userspace/src/utils.h +1 -0
@@ -25,6 +25,7 @@/* Be sync to kernel header */ #define BUS_ID_SIZE 20 +int modify_match_busid (char *busid,int add);int read_string (char *path,char *,size_t len);int read_integer (char *path);int getdevicename (char *busid,char *name,size_t len);
Signature · 1 line
1.7.5.1
PATCH 5/6 staging: usbip: userspace: usbipd.c: add header into source file
In reply to matt mooneyThe old usbip.h header that was only used to masked what each source file needed has been changed. So some headers this file needed had to be added.
--- drivers/staging/usbip/userspace/src/usbipd.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/usbip/userspace/src/usbipd.c +4 -4
@@ -7,6 +7,7 @@#include "../config.h" #endif +#include <errno.h> #include <unistd.h> #include <netdb.h> #include <strings.h>
@@ -23,16 +24,15 @@#define _GNU_SOURCE#include <getopt.h> +#include <glib.h> #include <signal.h> -#include "usbip.h" +#include "stub_driver.h" +#include "usbip_common.h" #include "usbip_network.h" -#include <glib.h> -static const char version[] =PACKAGE_STRING ; -static int send_reply_devlist (int sockfd) {int ret;
Signature · 1 line
1.7.5.1
PATCH 6/6 staging: usbip: userspace: usbip_network: rename and cleanup function
In reply to matt mooneyRename tcp_connection to usbip_net_tcp_connection, which alludes to a usbip network library that will eventually follow. The implementation of this function has also been cleaned up.
Headers had to be adjusted due to the elimination of the old usbip.h.
--- .../staging/usbip/userspace/src/usbip_network.c | 73 +++++++++----------- .../staging/usbip/userspace/src/usbip_network.h | 37 +++------- 2 files changed, 45 insertions(+), 65 deletions(-)
drivers/staging/usbip/userspace/src/usbip_network.c +33 -40
@@ -3,6 +3,16 @@* Copyright (C) 2005-2007 Takahiro Hirofuchi */ +#include <sys/socket.h> +#include <arpa/inet.h> + +#include <string.h> + +#include <netdb.h> +#include <netinet/tcp.h> +#include <unistd.h> + +#include "usbip_common.h" #include "usbip_network.h" void pack_uint32_t (int pack,uint32_t *num)
@@ -186,66 +196,49 @@ int usbip_set_keepalive(int sockfd)return ret; } -/* IPv6 Ready */ /* -* moved here from vhci_attach.c +* IPv6 Ready */ -int tcp_connect (char *hostname,char *service) +int usbip_net_tcp_connect (char *hostname,char *port) { -struct addrinfo hints, *res, *res0; +struct addrinfo hints, *res, *rp;int sockfd; -int err; - +int ret;memset (&hints,0 ,sizeof (hints)); + hints.ai_family =AF_UNSPEC ; 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 ; + ret =getaddrinfo (hostname, port, &hints, &res); +if (ret <0 ) { +dbg ("getaddrinfo: %s port %s: %s" , hostname, port, +gai_strerror (ret)); +return ret; } -/* 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" ); +/* try the addresses */ +for (rp = res; rp; rp = rp->ai_next) { + sockfd =socket (rp->ai_family, rp->ai_socktype, + rp->ai_protocol); +if (sockfd <0 )continue ; - }/* should set TCP_NODELAY for usbip */ usbip_set_nodelay (sockfd); -/* TODO: write code for heatbeat */ +/* TODO: write code for heartbeat */ usbip_set_keepalive (sockfd); - err =connect (sockfd, res->ai_addr, res->ai_addrlen); -if (err <0 ) { -close (sockfd); -continue ; - } +if (connect (sockfd, rp->ai_addr, rp->ai_addrlen) ==0 ) +break ; -/* connected */ -dbg ("connected to %s:%s" , hbuf, sbuf); -freeaddrinfo (res0); -return sockfd; +close (sockfd); } +if (!rp) +return EAI_SYSTEM ; -dbg ("%s:%s, %s" , hostname, service,"no destination to connect to" ); -freeaddrinfo (res0); +freeaddrinfo (res); -return -1 ; +return sockfd; }
drivers/staging/usbip/userspace/src/usbip_network.h +12 -25
@@ -2,19 +2,20 @@* Copyright (C) 2005-2007 Takahiro Hirofuchi */ -#ifndef _USBIP_NETWORK_H -#define _USBIP_NETWORK_H +#ifndef __USBIP_NETWORK_H +#define __USBIP_NETWORK_H -#include "usbip.h" -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/tcp.h> +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif +#include <sys/types.h> +#include <sysfs/libsysfs.h> -/* -------------------------------------------------- */ -/* Define Protocol Format */ -/* -------------------------------------------------- */ +#include <stdint.h> +#define USBIP_PORT 3240 +#define USBIP_PORT_STRING "3240"/* ---------------------------------------------------------------------- */ /* Common header for all the kinds of PDUs. */
@@ -38,7 +39,6 @@ struct op_common {pack_uint32_t (pack, &(op_common)->status );\ }while (0 ) -/* ---------------------------------------------------------------------- */ /* Dummy Code */#define OP_UNSPEC 0x00
@@ -60,7 +60,6 @@ struct op_devinfo_reply {struct usb_interface uinf[]; } __attribute__((packed)); -/* ---------------------------------------------------------------------- */ /* Import a remote USB device. */ #define OP_IMPORT 0x03
@@ -83,8 +82,6 @@ struct op_import_reply {pack_usb_device (pack, &(reply)->udev);\ }while (0 ) - -/* ---------------------------------------------------------------------- */ /* Export a USB device to a remote host. */#define OP_EXPORT 0x06
@@ -128,8 +125,6 @@ struct op_unexport_reply {#define PACK_OP_UNEXPORT_REPLY (pack, reply) do {\ } while (0) - -/* ---------------------------------------------------------------------- */ /* Negotiate IPSec encryption key. (still not used) */ #define OP_CRYPKEY 0x04
@@ -172,11 +167,6 @@ struct op_devlist_reply_extra {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);
@@ -190,9 +180,6 @@ 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); +int usbip_net_tcp_connect (char *hostname,char *port); -#define USBIP_PORT 3240 -#define USBIP_PORT_STRING "3240" - -#endif +#endif /* __USBIP_NETWORK_H */
Signature · 1 line
1.7.5.1