summaryrefslogtreecommitdiffstats
path: root/drivers/staging/usbip/userspace/libsrc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:26:34 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:26:34 -0700
commit138051659902da7e6a09d379fee5dade2a80fcfd (patch)
treee0a90e27451b1fcd812675092d30c1059369cb87 /drivers/staging/usbip/userspace/libsrc
parentd5ef642355bdd9b383ff5c18cbc6102a06eecbaf (diff)
parente1703b329f7c7ea82ea181dc4c50020f25061a2c (diff)
downloadop-kernel-dev-138051659902da7e6a09d379fee5dade2a80fcfd.zip
op-kernel-dev-138051659902da7e6a09d379fee5dade2a80fcfd.tar.gz
Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
* 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6: (741 commits) staging:iio:meter:ade7753 should be 16 bit read not 8 bit for mode register. staging:iio:kfifo_buf fix double initialization of the ring device structure. staging:iio:accel:lis3l02dq: fix incorrect pointer passed to spi_set_drvdata. staging:iio:imu fix missing register table index for some channels spectra: enable device before poking it staging: rts_pstor: Fix a miswriting staging/lirc_bt829: Return -ENODEV when no hardware is found. staging/lirc_parallel: remove pointless prototypes. staging/lirc_parallel: fix panic on rmmod staging:iio:adc:ad7476: Incorrect pointer into spi_set_drvdata. Staging: zram: Fix kunmapping order Revert "gma500: Fix dependencies" gma500: Add medfield header gma500: wire up the mrst i2c bus from chip_info gma500: Fix DPU build gma500: Clean up the DPU config and make it runtime gma500: resync with Medfield progress gma500: Use the mrst helpers and power control for mode commit gma500@ Fix backlight range error gma500: More Moorestown muddle meddling means MM maybe might modeset ... Fix up fairly trivial conflicts all over, mostly due to header file cleanup conflicts, but some deleted files and some just context changes: - Documentation/feature-removal-schedule.txt - drivers/staging/bcm/headers.h - drivers/staging/brcm80211/brcmfmac/dhd_linux.c - drivers/staging/brcm80211/brcmfmac/dhd_sdio.c - drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h - drivers/staging/brcm80211/brcmfmac/wl_iw.c - drivers/staging/et131x/et131x_netdev.c - drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c - drivers/staging/rtl8192e/r8192E.h - drivers/staging/usbip/userspace/src/utils.h
Diffstat (limited to 'drivers/staging/usbip/userspace/libsrc')
-rw-r--r--drivers/staging/usbip/userspace/libsrc/Makefile.am8
-rw-r--r--drivers/staging/usbip/userspace/libsrc/stub_driver.c391
-rw-r--r--drivers/staging/usbip/userspace/libsrc/stub_driver.h36
-rw-r--r--drivers/staging/usbip/userspace/libsrc/usbip.h19
-rw-r--r--drivers/staging/usbip/userspace/libsrc/usbip_common.c28
-rw-r--r--drivers/staging/usbip/userspace/libsrc/usbip_common.h138
-rw-r--r--drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c401
-rw-r--r--drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h48
-rw-r--r--drivers/staging/usbip/userspace/libsrc/vhci_driver.c167
-rw-r--r--drivers/staging/usbip/userspace/libsrc/vhci_driver.h32
10 files changed, 646 insertions, 622 deletions
diff --git a/drivers/staging/usbip/userspace/libsrc/Makefile.am b/drivers/staging/usbip/userspace/libsrc/Makefile.am
index 77ecf6b..4921189 100644
--- a/drivers/staging/usbip/userspace/libsrc/Makefile.am
+++ b/drivers/staging/usbip/userspace/libsrc/Makefile.am
@@ -1,7 +1,7 @@
-libusbip_la_CPPFLAGS := -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
-libusbip_la_CFLAGS := @EXTRA_CFLAGS@
-libusbip_la_LDFLAGS := -version-info @LIBUSBIP_VERSION@
+libusbip_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
+libusbip_la_CFLAGS = @EXTRA_CFLAGS@
+libusbip_la_LDFLAGS = -version-info @LIBUSBIP_VERSION@
lib_LTLIBRARIES := libusbip.la
-libusbip_la_SOURCES := names.c names.h stub_driver.c stub_driver.h usbip.h \
+libusbip_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \
usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h
diff --git a/drivers/staging/usbip/userspace/libsrc/stub_driver.c b/drivers/staging/usbip/userspace/libsrc/stub_driver.c
deleted file mode 100644
index cc33643..0000000
--- a/drivers/staging/usbip/userspace/libsrc/stub_driver.c
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#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)
-{
- int ret;
-
- char sysfs_mntpath[SYSFS_PATH_MAX];
- char stub_driver_path[SYSFS_PATH_MAX];
- struct sysfs_driver *stub_driver;
-
-
- ret = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
- if (ret < 0) {
- err("sysfs must be mounted");
- return NULL;
- }
-
- snprintf(stub_driver_path, SYSFS_PATH_MAX, "%s/%s/usb/%s/%s",
- sysfs_mntpath, SYSFS_BUS_NAME, SYSFS_DRIVERS_NAME,
- usbip_stub_driver_name);
-
- stub_driver = sysfs_open_driver_path(stub_driver_path);
- if (!stub_driver) {
- err("usbip-core.ko and usbip-host.ko must be loaded");
- return NULL;
- }
-
- return stub_driver;
-}
-
-
-#define SYSFS_OPEN_RETRIES 100
-
-/* only the first interface value is true! */
-static int32_t read_attr_usbip_status(struct usb_device *udev)
-{
- char attrpath[SYSFS_PATH_MAX];
- struct sysfs_attribute *attr;
- int value = 0;
- int ret;
- struct stat s;
- int retries = SYSFS_OPEN_RETRIES;
-
- /* This access is racy!
- *
- * Just after detach, our driver removes the sysfs
- * files and recreates them.
- *
- * We may try and fail to open the usbip_status of
- * an exported device in the (short) window where
- * it has been removed and not yet recreated.
- *
- * This is a bug in the interface. Nothing we can do
- * except work around it here by polling for the sysfs
- * usbip_status to reappear.
- */
-
- snprintf(attrpath, SYSFS_PATH_MAX, "%s/%s:%d.%d/usbip_status",
- udev->path, udev->busid,
- udev->bConfigurationValue,
- 0);
-
- while (retries > 0) {
- if (stat(attrpath, &s) == 0)
- break;
-
- if (errno != ENOENT) {
- err("error stat'ing %s", attrpath);
- return -1;
- }
-
- usleep(10000); /* 10ms */
- retries--;
- }
-
- if (retries == 0)
- err("usbip_status not ready after %d retries",
- SYSFS_OPEN_RETRIES);
- else if (retries < SYSFS_OPEN_RETRIES)
- info("warning: usbip_status ready after %d retries",
- SYSFS_OPEN_RETRIES - retries);
-
- attr = sysfs_open_attribute(attrpath);
- if (!attr) {
- err("open %s", attrpath);
- return -1;
- }
-
- ret = sysfs_read_attribute(attr);
- if (ret) {
- err("read %s", attrpath);
- sysfs_close_attribute(attr);
- return -1;
- }
-
- value = atoi(attr->value);
-
- sysfs_close_attribute(attr);
-
- return value;
-}
-
-
-static void usbip_exported_device_delete(void *dev)
-{
- struct usbip_exported_device *edev =
- (struct usbip_exported_device *) dev;
-
- sysfs_close_device(edev->sudev);
- free(dev);
-}
-
-
-static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
-{
- struct usbip_exported_device *edev = NULL;
-
- edev = (struct usbip_exported_device *) calloc(1, sizeof(*edev));
- if (!edev) {
- err("alloc device");
- return NULL;
- }
-
- edev->sudev = sysfs_open_device_path(sdevpath);
- if (!edev->sudev) {
- err("open %s", sdevpath);
- goto err;
- }
-
- read_usb_device(edev->sudev, &edev->udev);
-
- edev->status = read_attr_usbip_status(&edev->udev);
- if (edev->status < 0)
- goto err;
-
- /* reallocate buffer to include usb interface data */
- size_t size = sizeof(*edev) + edev->udev.bNumInterfaces * sizeof(struct usb_interface);
- edev = (struct usbip_exported_device *) realloc(edev, size);
- if (!edev) {
- err("alloc device");
- goto err;
- }
-
- for (int i=0; i < edev->udev.bNumInterfaces; i++)
- read_usb_interface(&edev->udev, i, &edev->uinf[i]);
-
- return edev;
-
-err:
- if (edev && edev->sudev)
- sysfs_close_device(edev->sudev);
- if (edev)
- free(edev);
- return NULL;
-}
-
-
-static int check_new(struct dlist *dlist, struct sysfs_device *target)
-{
- struct sysfs_device *dev;
-
- dlist_for_each_data(dlist, dev, struct sysfs_device) {
- if (!strncmp(dev->bus_id, target->bus_id, SYSFS_BUS_ID_SIZE))
- /* found. not new */
- return 0;
- }
-
- return 1;
-}
-
-static void delete_nothing(void *dev __attribute__((unused)))
-{
- /* do not delete anything. but, its container will be deleted. */
-}
-
-static int refresh_exported_devices(void)
-{
- struct sysfs_device *suinf; /* sysfs_device of usb_interface */
- struct dlist *suinf_list;
-
- struct sysfs_device *sudev; /* sysfs_device of usb_device */
- struct dlist *sudev_list;
-
-
- sudev_list = dlist_new_with_delete(sizeof(struct sysfs_device), delete_nothing);
-
- 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");
- goto bye;
- }
-
- /* collect unique USB devices (not interfaces) */
- dlist_for_each_data(suinf_list, suinf, struct sysfs_device) {
-
- /* get usb device of this usb interface */
- sudev = sysfs_get_device_parent(suinf);
- if (!sudev) {
- err("get parent dev of %s", suinf->name);
- continue;
- }
-
- if (check_new(sudev_list, sudev)) {
- dlist_unshift(sudev_list, sudev);
- }
- }
-
- dlist_for_each_data(sudev_list, sudev, struct sysfs_device) {
- struct usbip_exported_device *edev;
-
- edev = usbip_exported_device_new(sudev->path);
- if (!edev) {
- err("usbip_exported_device new");
- continue;
- }
-
- dlist_unshift(stub_driver->edev_list, (void *) edev);
- stub_driver->ndevs++;
- }
-
-
- dlist_destroy(sudev_list);
-
-bye:
-
- return 0;
-}
-
-int usbip_stub_refresh_device_list(void)
-{
- int ret;
-
- if (stub_driver->edev_list)
- dlist_destroy(stub_driver->edev_list);
-
- stub_driver->ndevs = 0;
-
- stub_driver->edev_list = dlist_new_with_delete(sizeof(struct usbip_exported_device),
- usbip_exported_device_delete);
- if (!stub_driver->edev_list) {
- err("alloc dlist");
- return -1;
- }
-
- ret = refresh_exported_devices();
- if (ret < 0)
- return ret;
-
- return 0;
-}
-
-int usbip_stub_driver_open(void)
-{
- int ret;
-
-
- stub_driver = (struct usbip_stub_driver *) calloc(1, sizeof(*stub_driver));
- if (!stub_driver) {
- err("alloc stub_driver");
- return -1;
- }
-
- stub_driver->ndevs = 0;
-
- stub_driver->edev_list = dlist_new_with_delete(sizeof(struct usbip_exported_device),
- usbip_exported_device_delete);
- if (!stub_driver->edev_list) {
- err("alloc dlist");
- goto err;
- }
-
- stub_driver->sysfs_driver = open_sysfs_stub_driver();
- if (!stub_driver->sysfs_driver)
- goto err;
-
- ret = refresh_exported_devices();
- if (ret < 0)
- goto err;
-
- return 0;
-
-
-err:
- if (stub_driver->sysfs_driver)
- sysfs_close_driver(stub_driver->sysfs_driver);
- if (stub_driver->edev_list)
- dlist_destroy(stub_driver->edev_list);
- free(stub_driver);
-
- stub_driver = NULL;
- return -1;
-}
-
-
-void usbip_stub_driver_close(void)
-{
- if (!stub_driver)
- return;
-
- if (stub_driver->edev_list)
- dlist_destroy(stub_driver->edev_list);
- if (stub_driver->sysfs_driver)
- sysfs_close_driver(stub_driver->sysfs_driver);
- free(stub_driver);
-
- stub_driver = NULL;
-}
-
-int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd)
-{
- char attrpath[SYSFS_PATH_MAX];
- struct sysfs_attribute *attr;
- char sockfd_buff[30];
- int ret;
-
-
- if (edev->status != SDEV_ST_AVAILABLE) {
- info("device not available, %s", edev->udev.busid);
- switch( edev->status ) {
- case SDEV_ST_ERROR:
- info(" status SDEV_ST_ERROR");
- break;
- case SDEV_ST_USED:
- info(" status SDEV_ST_USED");
- break;
- default:
- info(" status unknown: 0x%x", edev->status);
- }
- return -1;
- }
-
- /* only the first interface is true */
- snprintf(attrpath, sizeof(attrpath), "%s/%s:%d.%d/%s",
- edev->udev.path,
- edev->udev.busid,
- edev->udev.bConfigurationValue, 0,
- "usbip_sockfd");
-
- attr = sysfs_open_attribute(attrpath);
- if (!attr) {
- err("open %s", attrpath);
- return -1;
- }
-
- snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", sockfd);
-
- dbg("write: %s", sockfd_buff);
-
- ret = sysfs_write_attribute(attr, sockfd_buff, strlen(sockfd_buff));
- if (ret < 0) {
- err("write sockfd %s to %s", sockfd_buff, attrpath);
- goto err_write_sockfd;
- }
-
- info("connect %s", edev->udev.busid);
-
-err_write_sockfd:
- sysfs_close_attribute(attr);
-
- return ret;
-}
-
-struct usbip_exported_device *usbip_stub_get_device(int num)
-{
- struct usbip_exported_device *edev;
- struct dlist *dlist = stub_driver->edev_list;
- int count = 0;
-
- dlist_for_each_data(dlist, edev, struct usbip_exported_device) {
- if (num == count)
- return edev;
- else
- count++ ;
- }
-
- return NULL;
-}
diff --git a/drivers/staging/usbip/userspace/libsrc/stub_driver.h b/drivers/staging/usbip/userspace/libsrc/stub_driver.h
deleted file mode 100644
index 3107d18..0000000
--- a/drivers/staging/usbip/userspace/libsrc/stub_driver.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip.h b/drivers/staging/usbip/userspace/libsrc/usbip.h
deleted file mode 100644
index 7cb8e6f..0000000
--- a/drivers/staging/usbip/userspace/libsrc/usbip.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.c b/drivers/staging/usbip/userspace/libsrc/usbip_common.c
index a128a92..154b4b1 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_common.c
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.c
@@ -2,9 +2,12 @@
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
-#include "usbip.h"
+#include "usbip_common.h"
#include "names.h"
+#undef PROGNAME
+#define PROGNAME "libusbip"
+
int usbip_use_syslog = 0;
int usbip_use_stderr = 0;
int usbip_use_debug = 0;
@@ -64,7 +67,7 @@ const char *usbip_speed_string(int num)
#define DBG_UINF_INTEGER(name)\
dbg("%-20s = %x", to_string(name), (int) uinf->name)
-void dump_usb_interface(struct usb_interface *uinf)
+void dump_usb_interface(struct usbip_usb_interface *uinf)
{
char buff[100];
usbip_names_get_class(buff, sizeof(buff),
@@ -74,7 +77,7 @@ void dump_usb_interface(struct usb_interface *uinf)
dbg("%-20s = %s", "Interface(C/SC/P)", buff);
}
-void dump_usb_device(struct usb_device *udev)
+void dump_usb_device(struct usbip_usb_device *udev)
{
char buff[100];
@@ -117,19 +120,19 @@ int read_attr_value(struct sysfs_device *dev, const char *name, const char *form
attr = sysfs_open_attribute(attrpath);
if (!attr) {
- err("open attr %s", attrpath);
+ dbg("sysfs_open_attribute failed: %s", attrpath);
return 0;
}
ret = sysfs_read_attribute(attr);
if (ret < 0) {
- err("read attr");
+ dbg("sysfs_read_attribute failed");
goto err;
}
ret = sscanf(attr->value, format, &num);
if (ret < 1) {
- err("sscanf");
+ dbg("sscanf failed");
goto err;
}
@@ -151,19 +154,19 @@ int read_attr_speed(struct sysfs_device *dev)
attr = sysfs_open_attribute(attrpath);
if (!attr) {
- err("open attr");
+ dbg("sysfs_open_attribute failed: %s", attrpath);
return 0;
}
ret = sysfs_read_attribute(attr);
if (ret < 0) {
- err("read attr");
+ dbg("sysfs_read_attribute failed");
goto err;
}
ret = sscanf(attr->value, "%s\n", speed);
if (ret < 1) {
- err("sscanf");
+ dbg("sscanf failed");
goto err;
}
err:
@@ -181,7 +184,7 @@ err:
do { (object)->name = (type) read_attr_value(dev, to_string(name), format); } while (0)
-int read_usb_device(struct sysfs_device *sdev, struct usb_device *udev)
+int read_usb_device(struct sysfs_device *sdev, struct usbip_usb_device *udev)
{
uint32_t busnum, devnum;
@@ -209,7 +212,8 @@ int read_usb_device(struct sysfs_device *sdev, struct usb_device *udev)
return 0;
}
-int read_usb_interface(struct usb_device *udev, int i, struct usb_interface *uinf)
+int read_usb_interface(struct usbip_usb_device *udev, int i,
+ struct usbip_usb_interface *uinf)
{
char busid[SYSFS_BUS_ID_SIZE];
struct sysfs_device *sif;
@@ -218,7 +222,7 @@ int read_usb_interface(struct usb_device *udev, int i, struct usb_interface *uin
sif = sysfs_open_device("usb", busid);
if (!sif) {
- err("open sif of %s", busid);
+ dbg("sysfs_open_device(\"usb\", \"%s\") failed", busid);
return -1;
}
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.h b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
index c254b54..eedefbd 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_common.h
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
@@ -2,21 +2,18 @@
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
-#ifndef _USBIP_COMMON_H
-#define _USBIP_COMMON_H
+#ifndef __USBIP_COMMON_H
+#define __USBIP_COMMON_H
+
+#include <sysfs/libsysfs.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 <string.h>
-#include <sysfs/libsysfs.h>
-#include <netdb.h>
-#include <sys/socket.h>
+#include <syslog.h>
+#include <unistd.h>
#ifndef USBIDS_FILE
#define USBIDS_FILE "/usr/share/hwdata/usb.ids"
@@ -26,7 +23,59 @@
#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"
+
+extern int usbip_use_syslog;
+extern int usbip_use_stderr;
+extern int usbip_use_debug ;
+
+#define PROGNAME "usbip"
+
+#define pr_fmt(fmt) "%s: %s: " fmt "\n", PROGNAME
+#define dbg_fmt(fmt) pr_fmt("%s:%d:[%s] " fmt), "debug", \
+ __FILE__, __LINE__, __FUNCTION__
+
+#define err(fmt, args...) \
+ do { \
+ if (usbip_use_syslog) { \
+ syslog(LOG_ERR, pr_fmt(fmt), "error", ##args); \
+ } \
+ if (usbip_use_stderr) { \
+ fprintf(stderr, pr_fmt(fmt), "error", ##args); \
+ } \
+ } while (0)
+
+#define info(fmt, args...) \
+ do { \
+ if (usbip_use_syslog) { \
+ syslog(LOG_INFO, pr_fmt(fmt), "info", ##args); \
+ } \
+ if (usbip_use_stderr) { \
+ fprintf(stderr, pr_fmt(fmt), "info", ##args); \
+ } \
+ } while (0)
+
+#define dbg(fmt, args...) \
+ do { \
+ if (usbip_use_debug) { \
+ if (usbip_use_syslog) { \
+ syslog(LOG_DEBUG, dbg_fmt(fmt), ##args); \
+ } \
+ if (usbip_use_stderr) { \
+ fprintf(stderr, dbg_fmt(fmt), ##args); \
+ } \
+ } \
+ } while (0)
+
+#define BUG() \
+ do { \
+ err("sorry, it's a bug!"); \
+ abort(); \
+ } while (0)
+
enum usb_device_speed {
USB_SPEED_UNKNOWN = 0, /* enumerating */
USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
@@ -51,66 +100,14 @@ enum usbip_device_status{
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 {
+struct usbip_usb_interface {
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t padding; /* alignment */
} __attribute__((packed));
-
-
-struct usb_device {
+struct usbip_usb_device {
char path[SYSFS_PATH_MAX];
char busid[SYSFS_BUS_ID_SIZE];
@@ -132,11 +129,12 @@ struct usb_device {
#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);
+void dump_usb_interface(struct usbip_usb_interface *);
+void dump_usb_device(struct usbip_usb_device *);
+int read_usb_device(struct sysfs_device *sdev, struct usbip_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);
+int read_usb_interface(struct usbip_usb_device *udev, int i,
+ struct usbip_usb_interface *uinf);
const char *usbip_speed_string(int num);
const char *usbip_status_string(int32_t status);
@@ -146,4 +144,4 @@ 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
+#endif /* __USBIP_COMMON_H */
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
new file mode 100644
index 0000000..71a449c
--- /dev/null
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
@@ -0,0 +1,401 @@
+/*
+ * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
+ * 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/>.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "usbip_common.h"
+#include "usbip_host_driver.h"
+
+#undef PROGNAME
+#define PROGNAME "libusbip"
+
+struct usbip_host_driver *host_driver;
+
+#define SYSFS_OPEN_RETRIES 100
+
+/* only the first interface value is true! */
+static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
+{
+ char attrpath[SYSFS_PATH_MAX];
+ struct sysfs_attribute *attr;
+ int value = 0;
+ int rc;
+ struct stat s;
+ int retries = SYSFS_OPEN_RETRIES;
+
+ /* This access is racy!
+ *
+ * Just after detach, our driver removes the sysfs
+ * files and recreates them.
+ *
+ * We may try and fail to open the usbip_status of
+ * an exported device in the (short) window where
+ * it has been removed and not yet recreated.
+ *
+ * This is a bug in the interface. Nothing we can do
+ * except work around it here by polling for the sysfs
+ * usbip_status to reappear.
+ */
+
+ snprintf(attrpath, SYSFS_PATH_MAX, "%s/%s:%d.%d/usbip_status",
+ udev->path, udev->busid, udev->bConfigurationValue, 0);
+
+ while (retries > 0) {
+ if (stat(attrpath, &s) == 0)
+ break;
+
+ if (errno != ENOENT) {
+ dbg("stat failed: %s", attrpath);
+ return -1;
+ }
+
+ usleep(10000); /* 10ms */
+ retries--;
+ }
+
+ if (retries == 0)
+ dbg("usbip_status not ready after %d retries",
+ SYSFS_OPEN_RETRIES);
+ else if (retries < SYSFS_OPEN_RETRIES)
+ dbg("warning: usbip_status ready after %d retries",
+ SYSFS_OPEN_RETRIES - retries);
+
+ attr = sysfs_open_attribute(attrpath);
+ if (!attr) {
+ dbg("sysfs_open_attribute failed: %s", attrpath);
+ return -1;
+ }
+
+ rc = sysfs_read_attribute(attr);
+ if (rc) {
+ dbg("sysfs_read_attribute failed: %s", attrpath);
+ sysfs_close_attribute(attr);
+ return -1;
+ }
+
+ value = atoi(attr->value);
+
+ sysfs_close_attribute(attr);
+
+ return value;
+}
+
+static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
+{
+ struct usbip_exported_device *edev = NULL;
+ size_t size;
+ int i;
+
+ edev = calloc(1, sizeof(*edev));
+ if (!edev) {
+ dbg("calloc failed");
+ return NULL;
+ }
+
+ edev->sudev = sysfs_open_device_path(sdevpath);
+ if (!edev->sudev) {
+ dbg("sysfs_open_device_path failed: %s", sdevpath);
+ goto err;
+ }
+
+ read_usb_device(edev->sudev, &edev->udev);
+
+ edev->status = read_attr_usbip_status(&edev->udev);
+ if (edev->status < 0)
+ goto err;
+
+ /* reallocate buffer to include usb interface data */
+ size = sizeof(*edev) + edev->udev.bNumInterfaces *
+ sizeof(struct usbip_usb_interface);
+
+ edev = realloc(edev, size);
+ if (!edev) {
+ dbg("realloc failed");
+ goto err;
+ }
+
+ for (i = 0; i < edev->udev.bNumInterfaces; i++)
+ read_usb_interface(&edev->udev, i, &edev->uinf[i]);
+
+ return edev;
+err:
+ if (edev && edev->sudev)
+ sysfs_close_device(edev->sudev);
+ if (edev)
+ free(edev);
+
+ return NULL;
+}
+
+static int check_new(struct dlist *dlist, struct sysfs_device *target)
+{
+ struct sysfs_device *dev;
+
+ dlist_for_each_data(dlist, dev, struct sysfs_device) {
+ if (!strncmp(dev->bus_id, target->bus_id, SYSFS_BUS_ID_SIZE))
+ /* device found and is not new */
+ return 0;
+ }
+ return 1;
+}
+
+static void delete_nothing(void *unused_data)
+{
+ /*
+ * NOTE: Do not delete anything, but the container will be deleted.
+ */
+ (void) unused_data;
+}
+
+static int refresh_exported_devices(void)
+{
+ /* sysfs_device of usb_interface */
+ struct sysfs_device *suintf;
+ struct dlist *suintf_list;
+ /* sysfs_device of usb_device */
+ struct sysfs_device *sudev;
+ struct dlist *sudev_list;
+ struct usbip_exported_device *edev;
+
+ sudev_list = dlist_new_with_delete(sizeof(struct sysfs_device),
+ delete_nothing);
+
+ suintf_list = sysfs_get_driver_devices(host_driver->sysfs_driver);
+ if (!suintf_list) {
+ /*
+ * Not an error condition. There are simply no devices bound to
+ * the driver yet.
+ */
+ dbg("bind " USBIP_HOST_DRV_NAME ".ko to a usb device to be "
+ "exportable!");
+ return 0;
+ }
+
+ /* collect unique USB devices (not interfaces) */
+ dlist_for_each_data(suintf_list, suintf, struct sysfs_device) {
+ /* get usb device of this usb interface */
+ sudev = sysfs_get_device_parent(suintf);
+ if (!sudev) {
+ dbg("sysfs_get_device_parent failed: %s", suintf->name);
+ continue;
+ }
+
+ if (check_new(sudev_list, sudev)) {
+ /* insert item at head of list */
+ dlist_unshift(sudev_list, sudev);
+ }
+ }
+
+ dlist_for_each_data(sudev_list, sudev, struct sysfs_device) {
+ edev = usbip_exported_device_new(sudev->path);
+ if (!edev) {
+ dbg("usbip_exported_device_new failed");
+ continue;
+ }
+
+ dlist_unshift(host_driver->edev_list, edev);
+ host_driver->ndevs++;
+ }
+
+ dlist_destroy(sudev_list);
+
+ return 0;
+}
+
+static struct sysfs_driver *open_sysfs_host_driver(void)
+{
+ char bus_type[] = "usb";
+ char sysfs_mntpath[SYSFS_PATH_MAX];
+ char host_drv_path[SYSFS_PATH_MAX];
+ struct sysfs_driver *host_drv;
+ int rc;
+
+ rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
+ if (rc < 0) {
+ dbg("sysfs_get_mnt_path failed");
+ return NULL;
+ }
+
+ snprintf(host_drv_path, SYSFS_PATH_MAX, "%s/%s/%s/%s/%s",
+ sysfs_mntpath, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
+ USBIP_HOST_DRV_NAME);
+
+ host_drv = sysfs_open_driver_path(host_drv_path);
+ if (!host_drv) {
+ dbg("sysfs_open_driver_path failed");
+ return NULL;
+ }
+
+ return host_drv;
+}
+
+static void usbip_exported_device_delete(void *dev)
+{
+ struct usbip_exported_device *edev = dev;
+ sysfs_close_device(edev->sudev);
+ free(dev);
+}
+
+int usbip_host_driver_open(void)
+{
+ int rc;
+
+ host_driver = calloc(1, sizeof(*host_driver));
+ if (!host_driver) {
+ dbg("calloc failed");
+ return -1;
+ }
+
+ host_driver->ndevs = 0;
+ host_driver->edev_list =
+ dlist_new_with_delete(sizeof(struct usbip_exported_device),
+ usbip_exported_device_delete);
+ if (!host_driver->edev_list) {
+ dbg("dlist_new_with_delete failed");
+ goto err_free_host_driver;
+ }
+
+ host_driver->sysfs_driver = open_sysfs_host_driver();
+ if (!host_driver->sysfs_driver)
+ goto err_destroy_edev_list;
+
+ rc = refresh_exported_devices();
+ if (rc < 0)
+ goto err_close_sysfs_driver;
+
+ return 0;
+
+err_close_sysfs_driver:
+ sysfs_close_driver(host_driver->sysfs_driver);
+err_destroy_edev_list:
+ dlist_destroy(host_driver->edev_list);
+err_free_host_driver:
+ free(host_driver);
+ host_driver = NULL;
+
+ return -1;
+}
+
+void usbip_host_driver_close(void)
+{
+ if (!host_driver)
+ return;
+
+ if (host_driver->edev_list)
+ dlist_destroy(host_driver->edev_list);
+ if (host_driver->sysfs_driver)
+ sysfs_close_driver(host_driver->sysfs_driver);
+
+ free(host_driver);
+ host_driver = NULL;
+}
+
+int usbip_host_refresh_device_list(void)
+{
+ int rc;
+
+ if (host_driver->edev_list)
+ dlist_destroy(host_driver->edev_list);
+
+ host_driver->ndevs = 0;
+ host_driver->edev_list =
+ dlist_new_with_delete(sizeof(struct usbip_exported_device),
+ usbip_exported_device_delete);
+ if (!host_driver->edev_list) {
+ dbg("dlist_new_with_delete failed");
+ return -1;
+ }
+
+ rc = refresh_exported_devices();
+ if (rc < 0)
+ return -1;
+
+ return 0;
+}
+
+int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd)
+{
+ char attr_name[] = "usbip_sockfd";
+ char attr_path[SYSFS_PATH_MAX];
+ struct sysfs_attribute *attr;
+ char sockfd_buff[30];
+ int ret;
+
+ if (edev->status != SDEV_ST_AVAILABLE) {
+ dbg("device not available: %s", edev->udev.busid);
+ switch (edev->status) {
+ case SDEV_ST_ERROR:
+ dbg("status SDEV_ST_ERROR");
+ break;
+ case SDEV_ST_USED:
+ dbg("status SDEV_ST_USED");
+ break;
+ default:
+ dbg("status unknown: 0x%x", edev->status);
+ }
+ return -1;
+ }
+
+ /* only the first interface is true */
+ snprintf(attr_path, sizeof(attr_path), "%s/%s:%d.%d/%s",
+ edev->udev.path, edev->udev.busid,
+ edev->udev.bConfigurationValue, 0, attr_name);
+
+ attr = sysfs_open_attribute(attr_path);
+ if (!attr) {
+ dbg("sysfs_open_attribute failed: %s", attr_path);
+ return -1;
+ }
+
+ snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", sockfd);
+ dbg("write: %s", sockfd_buff);
+
+ ret = sysfs_write_attribute(attr, sockfd_buff, strlen(sockfd_buff));
+ if (ret < 0) {
+ dbg("sysfs_write_attribute failed: sockfd %s to %s",
+ sockfd_buff, attr_path);
+ goto err_write_sockfd;
+ }
+
+ dbg("connect: %s", edev->udev.busid);
+
+err_write_sockfd:
+ sysfs_close_attribute(attr);
+
+ return ret;
+}
+
+struct usbip_exported_device *usbip_host_get_device(int num)
+{
+ struct usbip_exported_device *edev;
+ struct dlist *dlist = host_driver->edev_list;
+ int cnt = 0;
+
+ dlist_for_each_data(dlist, edev, struct usbip_exported_device) {
+ if (num == cnt)
+ return edev;
+ else
+ cnt++;
+ }
+
+ return NULL;
+}
diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h
new file mode 100644
index 0000000..34fd14c
--- /dev/null
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
+ * 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_HOST_DRIVER_H
+#define __USBIP_HOST_DRIVER_H
+
+#include <stdint.h>
+#include "usbip_common.h"
+
+struct usbip_host_driver {
+ int ndevs;
+ struct sysfs_driver *sysfs_driver;
+ /* list of exported device */
+ struct dlist *edev_list;
+};
+
+struct usbip_exported_device {
+ struct sysfs_device *sudev;
+ int32_t status;
+ struct usbip_usb_device udev;
+ struct usbip_usb_interface uinf[];
+};
+
+extern struct usbip_host_driver *host_driver;
+
+int usbip_host_driver_open(void);
+void usbip_host_driver_close(void);
+
+int usbip_host_refresh_device_list(void);
+int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd);
+struct usbip_exported_device *usbip_host_get_device(int num);
+
+#endif /* __USBIP_HOST_DRIVER_H */
diff --git a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
index db43f8d..abbc285 100644
--- a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
+++ b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
@@ -2,11 +2,11 @@
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
+#include "usbip_common.h"
+#include "vhci_driver.h"
-#include "usbip.h"
-
-
-static const char vhci_driver_name[] = "vhci_hcd";
+#undef PROGNAME
+#define PROGNAME "libusbip"
struct usbip_vhci_driver *vhci_driver;
@@ -16,17 +16,19 @@ static struct usbip_imported_device *imported_device_init(struct usbip_imported_
sudev = sysfs_open_device("usb", busid);
if (!sudev) {
- err("sysfs_open_device %s", busid);
+ dbg("sysfs_open_device failed: %s", busid);
goto err;
}
read_usb_device(sudev, &idev->udev);
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));
@@ -53,7 +55,7 @@ static int parse_status(char *value)
for (int i = 0; i < vhci_driver->nports; i++)
- bzero(&vhci_driver->idev[i], sizeof(struct usbip_imported_device));
+ memset(&vhci_driver->idev[i], 0, sizeof(vhci_driver->idev[i]));
/* skip a header line */
@@ -69,7 +71,7 @@ static int parse_status(char *value)
&devid, &socket, lbusid);
if (ret < 5) {
- err("scanf %d", ret);
+ dbg("sscanf failed: %d", ret);
BUG();
}
@@ -90,16 +92,16 @@ 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");
+ dbg("dlist_new failed");
return -1;
}
if (idev->status != VDEV_ST_NULL && idev->status != VDEV_ST_NOTASSIGNED) {
idev = imported_device_init(idev, lbusid);
if (!idev) {
- err("init new device");
+ dbg("imported_device_init failed");
return -1;
}
}
@@ -118,29 +120,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");
+ dbg("calloc failed");
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);
}
}
@@ -157,11 +159,11 @@ static int search_class_for_usbip_device(char *cname)
class = sysfs_open_class(cname);
if (!class) {
- err("open class");
+ dbg("sysfs_open_class failed");
return -1;
}
- dbg("class %s", class->name);
+ dbg("class: %s", class->name);
cdev_list = sysfs_get_class_devices(class);
if (!cdev_list)
@@ -169,7 +171,7 @@ static int search_class_for_usbip_device(char *cname)
goto out;
dlist_for_each_data(cdev_list, cdev, struct sysfs_class_device) {
- dbg(" cdev %s", cdev->name);
+ dbg("cdev: %s", cdev->name);
ret = check_usbip_device(cdev);
if (ret < 0)
goto out;
@@ -187,11 +189,22 @@ 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) {
+ dbg("sysfs_get_mnt_path failed");
+ 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");
+ dbg("sysfs_open_directory failed");
return -1;
}
@@ -221,45 +234,42 @@ static int refresh_imported_device_list(void)
attr_status = sysfs_get_device_attr(vhci_driver->hc_device, "status");
if (!attr_status) {
- err("get attr %s of %s", "status", vhci_driver->hc_device->name);
+ dbg("sysfs_get_device_attr(\"status\") failed: %s",
+ vhci_driver->hc_device->name);
return -1;
}
- dbg("name %s, path %s, len %d, method %d\n", attr_status->name,
- attr_status->path, attr_status->len, attr_status->method);
-
- dbg("%s", attr_status->value);
+ dbg("name: %s path: %s len: %d method: %d value: %s",
+ attr_status->name, attr_status->path, attr_status->len,
+ attr_status->method, attr_status->value);
return parse_status(attr_status->value);
}
static int get_nports(void)
{
+ char *c;
int nports = 0;
struct sysfs_attribute *attr_status;
attr_status = sysfs_get_device_attr(vhci_driver->hc_device, "status");
if (!attr_status) {
- err("get attr %s of %s", "status", vhci_driver->hc_device->name);
+ dbg("sysfs_get_device_attr(\"status\") failed: %s",
+ vhci_driver->hc_device->name);
return -1;
}
- dbg("name %s, path %s, len %d, method %d\n", attr_status->name,
- attr_status->path, attr_status->len, attr_status->method);
-
- dbg("%s", attr_status->value);
+ dbg("name: %s path: %s len: %d method: %d value: %s",
+ attr_status->name, attr_status->path, attr_status->len,
+ attr_status->method, attr_status->value);
- {
- char *c;
-
- /* skip a header line */
- c = strchr(attr_status->value, '\n') + 1;
+ /* skip a header line */
+ c = strchr(attr_status->value, '\n') + 1;
- while (*c != '\0') {
- /* go to the next line */
- c = strchr(c, '\n') + 1;
- nports += 1;
- }
+ while (*c != '\0') {
+ /* go to the next line */
+ c = strchr(c, '\n') + 1;
+ nports += 1;
}
return nports;
@@ -275,20 +285,21 @@ 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,
- vhci_driver_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) {
- info("%s is not found", sdriver_path);
- info("load usbip-core.ko and vhci-hcd.ko !");
+ dbg("sysfs_open_driver_path failed: %s", sdriver_path);
+ dbg("make sure " USBIP_CORE_MOD_NAME ".ko and "
+ USBIP_VHCI_DRV_NAME ".ko are loaded!");
return -1;
}
hc_devs = sysfs_get_driver_devices(sdriver);
if (!hc_devs) {
- err("get hc list");
+ dbg("sysfs_get_driver failed");
goto err;
}
@@ -304,7 +315,7 @@ err:
if (found)
return 0;
- err("not found usbip hc");
+ dbg("%s not found", hc_busid);
return -1;
}
@@ -318,13 +329,13 @@ int usbip_vhci_driver_open(void)
vhci_driver = (struct usbip_vhci_driver *) calloc(1, sizeof(*vhci_driver));
if (!vhci_driver) {
- err("alloc vhci_driver");
+ dbg("calloc failed");
return -1;
}
ret = sysfs_get_mnt_path(vhci_driver->sysfs_mntpath, SYSFS_PATH_MAX);
if (ret < 0) {
- err("sysfs must be mounted");
+ dbg("sysfs_get_mnt_path failed");
goto err;
}
@@ -333,17 +344,18 @@ 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");
+ dbg("sysfs_open_device failed");
goto err;
}
vhci_driver->nports = get_nports();
- info("%d ports available\n", vhci_driver->nports);
+ dbg("available ports: %d", 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;
@@ -402,7 +414,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;
@@ -422,7 +434,7 @@ err:
dlist_destroy(vhci_driver->idev[i].cdev_list);
}
- err("refresh device list");
+ dbg("failed to refresh device list");
return -1;
}
@@ -445,7 +457,8 @@ int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
attr_attach = sysfs_get_device_attr(vhci_driver->hc_device, "attach");
if (!attr_attach) {
- err("get attach");
+ dbg("sysfs_get_device_attr(\"attach\") failed: %s",
+ vhci_driver->hc_device->name);
return -1;
}
@@ -455,11 +468,11 @@ int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
ret = sysfs_write_attribute(attr_attach, buff, strlen(buff));
if (ret < 0) {
- err("write to attach failed");
+ dbg("sysfs_write_attribute failed");
return -1;
}
- info("port %d attached", port);
+ dbg("attached port: %d", port);
return 0;
}
@@ -486,21 +499,21 @@ int usbip_vhci_detach_device(uint8_t port)
attr_detach = sysfs_get_device_attr(vhci_driver->hc_device, "detach");
if (!attr_detach) {
- err("get detach");
+ dbg("sysfs_get_device_attr(\"detach\") failed: %s",
+ vhci_driver->hc_device->name);
return -1;
}
snprintf(buff, sizeof(buff), "%u", port);
- dbg("writing to detach");
dbg("writing: %s", buff);
ret = sysfs_write_attribute(attr_detach, buff, strlen(buff));
if (ret < 0) {
- err("write to detach failed");
+ dbg("sysfs_write_attribute failed");
return -1;
}
- info("port %d detached", port);
+ dbg("detached port: %d", port);
return 0;
}
diff --git a/drivers/staging/usbip/userspace/libsrc/vhci_driver.h b/drivers/staging/usbip/userspace/libsrc/vhci_driver.h
index cad8ad7..89949aa 100644
--- a/drivers/staging/usbip/userspace/libsrc/vhci_driver.h
+++ b/drivers/staging/usbip/userspace/libsrc/vhci_driver.h
@@ -2,18 +2,20 @@
* Copyright (C) 2005-2007 Takahiro Hirofuchi
*/
-#ifndef _VHCI_DRIVER_H
-#define _VHCI_DRIVER_H
-
-#include "usbip.h"
+#ifndef __VHCI_DRIVER_H
+#define __VHCI_DRIVER_H
+#include <sysfs/libsysfs.h>
+#include <stdint.h>
+#include "usbip_common.h"
+#define USBIP_VHCI_BUS_TYPE "platform"
#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 +27,19 @@ struct usbip_imported_device {
uint8_t busnum;
uint8_t devnum;
-
- struct dlist *cdev_list; /* list of class device */
- struct usb_device udev;
+ /* usbip_class_device list */
+ struct dlist *cdev_list;
+ struct usbip_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];
@@ -58,4 +63,5 @@ 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
+
+#endif /* __VHCI_DRIVER_H */
OpenPOWER on IntegriCloud