summaryrefslogtreecommitdiffstats
path: root/lib/libusb
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
committersjg <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
commit62bb1062226d3ce6a2350808256a25508978352d (patch)
tree22b131dceb13c3df96da594fbaadb693504797c7 /lib/libusb
parent72ab90509b3a51ab361bf710338f2ef44a4e360d (diff)
parent04932445481c2cb89ff69a83b961bdef3d64757e (diff)
downloadFreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.zip
FreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.tar.gz
Merge from head
Diffstat (limited to 'lib/libusb')
-rw-r--r--lib/libusb/Makefile24
-rw-r--r--lib/libusb/libusb-0.1.pc11
-rw-r--r--lib/libusb/libusb-1.0.pc11
-rw-r--r--lib/libusb/libusb-2.0.pc11
-rw-r--r--lib/libusb/libusb.315
-rw-r--r--lib/libusb/libusb.h4
-rw-r--r--lib/libusb/libusb10.c13
-rw-r--r--lib/libusb/libusb10_io.c4
-rw-r--r--lib/libusb/libusb20.324
-rw-r--r--lib/libusb/libusb20.c27
-rw-r--r--lib/libusb/libusb20.h1
-rw-r--r--lib/libusb/libusb20_int.h2
-rw-r--r--lib/libusb/libusb20_ugen20.c97
-rw-r--r--lib/libusb/libusb_global_linux.h9
14 files changed, 189 insertions, 64 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index 66dd795..99bdfc2 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -15,11 +15,12 @@ INCS+= libusb20_desc.h
MAN= libusb.3 libusb20.3
MKLINT= no
NOGCCERROR=
+PTHREAD_LIBS?= -lpthread
WARNS?= 2
DPADD= ${LIBPTHREAD}
-LDADD= -lpthread
+LDADD= ${PTHREAD_LIBS}
MLINKS+= libusb.3 usb.3
@@ -37,12 +38,30 @@ SRCS+= libusb10_io.c
CFLAGS+= -DCOMPAT_32BIT
.endif
+beforeinstall:
+ ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${.CURDIR}/libusb-0.1.pc ${DESTDIR}${LIBDATADIR}/pkgconfig
+ ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${.CURDIR}/libusb-1.0.pc ${DESTDIR}${LIBDATADIR}/pkgconfig
+ ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${.CURDIR}/libusb-2.0.pc ${DESTDIR}${LIBDATADIR}/pkgconfig
+
#
# Cross platform support
#
# Examples:
# make LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h
-# make COMPAT_32BIT=YES LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h
+# make COMPAT_32BIT=YES \
+# LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h \
+# DEBUG_FLAGS="-g"
+#
+# From Ubuntu 10.04:
+# freebsd-make LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h \
+# PTHREAD_LIBS="-lpthread -lrt"
+# freebsd-make COMPAT32_BIT=YES \
+# LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h \
+# PTHREAD_LIBS="-lpthread -lrt"
+#
#
.if defined(LIBUSB_GLOBAL_INCLUDE_FILE)
CFLAGS+= -DLIBUSB_GLOBAL_INCLUDE_FILE=\"${LIBUSB_GLOBAL_INCLUDE_FILE}\"
@@ -203,6 +222,7 @@ MLINKS += libusb20.3 libusb20_dev_reset.3
MLINKS += libusb20.3 libusb20_dev_check_connected.3
MLINKS += libusb20.3 libusb20_dev_set_power_mode.3
MLINKS += libusb20.3 libusb20_dev_get_power_mode.3
+MLINKS += libusb20.3 libusb20_dev_get_port_path.3
MLINKS += libusb20.3 libusb20_dev_get_power_usage.3
MLINKS += libusb20.3 libusb20_dev_set_alt_index.3
MLINKS += libusb20.3 libusb20_dev_get_device_desc.3
diff --git a/lib/libusb/libusb-0.1.pc b/lib/libusb/libusb-0.1.pc
new file mode 100644
index 0000000..afd7a99
--- /dev/null
+++ b/lib/libusb/libusb-0.1.pc
@@ -0,0 +1,11 @@
+# $FreeBSD$
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: libusb-0.1
+Description: Library that abstracts ways to access USB devices (v0.1)
+Version: 0.1.0
+Libs: -L${libdir} -lusb
+Cflags: -I${includedir}
diff --git a/lib/libusb/libusb-1.0.pc b/lib/libusb/libusb-1.0.pc
new file mode 100644
index 0000000..bed98de
--- /dev/null
+++ b/lib/libusb/libusb-1.0.pc
@@ -0,0 +1,11 @@
+# $FreeBSD$
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: libusb-1.0
+Description: Library that abstracts ways to access USB devices (v1.0)
+Version: 1.0.9
+Libs: -L${libdir} -lusb
+Cflags: -I${includedir}
diff --git a/lib/libusb/libusb-2.0.pc b/lib/libusb/libusb-2.0.pc
new file mode 100644
index 0000000..34eabb8
--- /dev/null
+++ b/lib/libusb/libusb-2.0.pc
@@ -0,0 +1,11 @@
+# $FreeBSD$
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: libusb-2.0
+Description: Library that abstracts ways to access USB devices (v2.0)
+Version: 2.0.0
+Libs: -L${libdir} -lusb
+Cflags: -I${includedir}
diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3
index ffc761b..b50981c 100644
--- a/lib/libusb/libusb.3
+++ b/lib/libusb/libusb.3
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 7, 2012
+.Dd June 7, 2013
.Dt LIBUSB 3
.Os
.Sh NAME
@@ -102,6 +102,19 @@ counter decremented once.
Returns the number of the bus contained by the device
.Fa dev .
.Pp
+.Ft int
+.Fn libusb_get_port_numbers "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize"
+Stores, in the buffer
+.Fa buf
+of size
+.Fa bufsize ,
+the list of all port numbers from root for the device
+.Fa dev .
+.Pp
+.Ft int
+.Fn libusb_get_port_path "libusb_context *ctx" "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize"
+Deprecated function equivalent to libusb_get_port_numbers.
+.Pp
.Ft uint8_t
.Fn libusb_get_device_address "libusb_device *dev"
Returns the device_address contained by the device
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
index 225b539..b14990e 100644
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -369,6 +369,8 @@ void libusb_exit(struct libusb_context *ctx);
ssize_t libusb_get_device_list(libusb_context * ctx, libusb_device *** list);
void libusb_free_device_list(libusb_device ** list, int unref_devices);
uint8_t libusb_get_bus_number(libusb_device * dev);
+int libusb_get_port_numbers(libusb_device *dev, uint8_t *buf, uint8_t bufsize);
+int libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *buf, uint8_t bufsize);
uint8_t libusb_get_device_address(libusb_device * dev);
enum libusb_speed libusb_get_device_speed(libusb_device * dev);
int libusb_clear_halt(libusb_device_handle *devh, uint8_t endpoint);
@@ -441,7 +443,7 @@ int libusb_handle_events(libusb_context * ctx);
int libusb_handle_events_locked(libusb_context * ctx, struct timeval *tv);
int libusb_get_next_timeout(libusb_context * ctx, struct timeval *tv);
void libusb_set_pollfd_notifiers(libusb_context * ctx, libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, void *user_data);
-struct libusb_pollfd **libusb_get_pollfds(libusb_context * ctx);
+const struct libusb_pollfd **libusb_get_pollfds(libusb_context * ctx);
/* Synchronous device I/O */
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index 0212296..79a570e 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -290,6 +290,19 @@ libusb_get_bus_number(libusb_device *dev)
return (libusb20_dev_get_bus_number(dev->os_priv));
}
+int
+libusb_get_port_numbers(libusb_device *dev, uint8_t *buf, uint8_t bufsize)
+{
+ return (libusb20_dev_get_port_path(dev->os_priv, buf, bufsize));
+}
+
+int
+libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *buf,
+ uint8_t bufsize)
+{
+ return (libusb20_dev_get_port_path(dev->os_priv, buf, bufsize));
+}
+
uint8_t
libusb_get_device_address(libusb_device *dev)
{
diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c
index 489ceb7..9aa31c4 100644
--- a/lib/libusb/libusb10_io.c
+++ b/lib/libusb/libusb10_io.c
@@ -397,7 +397,7 @@ libusb_set_pollfd_notifiers(libusb_context *ctx,
ctx->fd_cb_user_data = user_data;
}
-struct libusb_pollfd **
+const struct libusb_pollfd **
libusb_get_pollfds(libusb_context *ctx)
{
struct libusb_super_pollfd *pollfd;
@@ -423,7 +423,7 @@ libusb_get_pollfds(libusb_context *ctx)
done:
CTX_UNLOCK(ctx);
- return (ret);
+ return ((const struct libusb_pollfd **)ret);
}
diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3
index 8d286f1..f6004a5 100644
--- a/lib/libusb/libusb20.3
+++ b/lib/libusb/libusb20.3
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 14, 2013
+.Dd May 3, 2013
.Dt LIBUSB20 3
.Os
.Sh NAME
@@ -114,6 +114,8 @@ USB access library (libusb -lusb)
.Ft const char *
.Fn libusb20_dev_get_backend_name "struct libusb20_device *"
.Ft int
+.Fn libusb20_dev_get_port_path "struct libusb20_device *pdev" "uint8_t *buf" "uint8_t bufsize"
+.Ft int
.Fn libusb20_dev_get_info "struct libusb20_device *pdev" "struct usb_device_info *pinfo"
.Ft int
.Fn libusb20_dev_get_iface_desc "struct libusb20_device *pdev" "uint8_t iface_index" "char *buf" "uint8_t len"
@@ -552,6 +554,20 @@ returns a zero terminated string describing the backend used.
.
.Pp
.
+.Fn libusb20_dev_get_port_path
+retrieves the list of USB port numbers which the datastream for a given USB device follows.
+The first port number is the Root HUB port number.
+Then children port numbers follow.
+The Root HUB device itself has a port path length of zero.
+Valid port numbers start at one and range until and including 255.
+Typically there should not be more than 16 levels, due to electrical and protocol limitations.
+This functions returns the number of actual port levels upon success
+else a LIBUSB20_ERROR value is returned which are always negative.
+If the actual number of port levels is greater than the maximum
+specified, a LIBUSB20_ERROR value is returned.
+.
+.Pp
+.
.Fn libusb20_dev_get_info
retrieves the BSD specific usb_device_info structure into the memory location given by
.Fa pinfo .
@@ -1033,9 +1049,9 @@ argument.
This function does not return NULL.
.
.Sh FILES
-.
-.
-/dev/usb
+.Bl -tag -width Pa
+.It Pa /dev/usb
+.El
.Sh SEE ALSO
.Xr usb 4 ,
.Xr libusb 3 ,
diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c
index 644eda4..1de3a26 100644
--- a/lib/libusb/libusb20.c
+++ b/lib/libusb/libusb20.c
@@ -75,6 +75,7 @@ dummy_callback(struct libusb20_transfer *xfer)
#define dummy_check_connected (void *)dummy_int
#define dummy_set_power_mode (void *)dummy_int
#define dummy_get_power_mode (void *)dummy_int
+#define dummy_get_port_path (void *)dummy_int
#define dummy_get_power_usage (void *)dummy_int
#define dummy_kernel_driver_active (void *)dummy_int
#define dummy_detach_kernel_driver (void *)dummy_int
@@ -722,6 +723,12 @@ libusb20_dev_get_power_mode(struct libusb20_device *pdev)
return (power_mode);
}
+int
+libusb20_dev_get_port_path(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize)
+{
+ return (pdev->methods->get_port_path(pdev, buf, bufsize));
+}
+
uint16_t
libusb20_dev_get_power_usage(struct libusb20_device *pdev)
{
@@ -1195,27 +1202,13 @@ libusb20_be_alloc(const struct libusb20_backend_methods *methods)
struct libusb20_backend *
libusb20_be_alloc_linux(void)
{
- struct libusb20_backend *pbe;
-
-#ifdef __linux__
- pbe = libusb20_be_alloc(&libusb20_linux_backend);
-#else
- pbe = NULL;
-#endif
- return (pbe);
+ return (NULL);
}
struct libusb20_backend *
libusb20_be_alloc_ugen20(void)
{
- struct libusb20_backend *pbe;
-
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
- pbe = libusb20_be_alloc(&libusb20_ugen20_backend);
-#else
- pbe = NULL;
-#endif
- return (pbe);
+ return (libusb20_be_alloc(&libusb20_ugen20_backend));
}
struct libusb20_backend *
@@ -1223,10 +1216,12 @@ libusb20_be_alloc_default(void)
{
struct libusb20_backend *pbe;
+#ifdef __linux__
pbe = libusb20_be_alloc_linux();
if (pbe) {
return (pbe);
}
+#endif
pbe = libusb20_be_alloc_ugen20();
if (pbe) {
return (pbe);
diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h
index 4a57b49..6d1613e 100644
--- a/lib/libusb/libusb20.h
+++ b/lib/libusb/libusb20.h
@@ -251,6 +251,7 @@ int libusb20_dev_reset(struct libusb20_device *pdev);
int libusb20_dev_check_connected(struct libusb20_device *pdev);
int libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode);
uint8_t libusb20_dev_get_power_mode(struct libusb20_device *pdev);
+int libusb20_dev_get_port_path(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize);
uint16_t libusb20_dev_get_power_usage(struct libusb20_device *pdev);
int libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
int libusb20_dev_get_info(struct libusb20_device *pdev, struct usb_device_info *pinfo);
diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h
index 6705c63..27adf00 100644
--- a/lib/libusb/libusb20_int.h
+++ b/lib/libusb/libusb20_int.h
@@ -105,6 +105,7 @@ typedef int (libusb20_process_t)(struct libusb20_device *pdev);
typedef int (libusb20_reset_device_t)(struct libusb20_device *pdev);
typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode);
typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode);
+typedef int (libusb20_get_port_path_t)(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize);
typedef int (libusb20_get_power_usage_t)(struct libusb20_device *pdev, uint16_t *power_usage);
typedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
typedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index);
@@ -128,6 +129,7 @@ typedef void (libusb20_tr_cancel_async_t)(struct libusb20_transfer *xfer);
m(n, check_connected) \
m(n, set_power_mode) \
m(n, get_power_mode) \
+ m(n, get_port_path) \
m(n, get_power_usage) \
m(n, set_alt_index) \
m(n, set_config_index) \
diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c
index 0846eb4..e40bc07 100644
--- a/lib/libusb/libusb20_ugen20.c
+++ b/lib/libusb/libusb20_ugen20.c
@@ -46,6 +46,10 @@
#include "libusb20_desc.h"
#include "libusb20_int.h"
+#ifndef IOUSB
+#define IOUSB(a) a
+#endif
+
static libusb20_init_backend_t ugen20_init_backend;
static libusb20_open_device_t ugen20_open_device;
static libusb20_close_device_t ugen20_close_device;
@@ -73,6 +77,7 @@ static libusb20_reset_device_t ugen20_reset_device;
static libusb20_check_connected_t ugen20_check_connected;
static libusb20_set_power_mode_t ugen20_set_power_mode;
static libusb20_get_power_mode_t ugen20_get_power_mode;
+static libusb20_get_port_path_t ugen20_get_port_path;
static libusb20_get_power_usage_t ugen20_get_power_usage;
static libusb20_kernel_driver_active_t ugen20_kernel_driver_active;
static libusb20_detach_kernel_driver_t ugen20_detach_kernel_driver;
@@ -144,14 +149,14 @@ ugen20_enumerate(struct libusb20_device *pdev, const char *id)
if (f < 0) {
return (LIBUSB20_ERROR_OTHER);
}
- if (ioctl(f, USB_GET_PLUGTIME, &plugtime)) {
+ if (ioctl(f, IOUSB(USB_GET_PLUGTIME), &plugtime)) {
error = LIBUSB20_ERROR_OTHER;
goto done;
}
/* store when the device was plugged */
pdev->session_data.plugtime = plugtime;
- if (ioctl(f, USB_GET_DEVICE_DESC, &ddesc)) {
+ if (ioctl(f, IOUSB(USB_GET_DEVICE_DESC), &ddesc)) {
error = LIBUSB20_ERROR_OTHER;
goto done;
}
@@ -166,7 +171,7 @@ ugen20_enumerate(struct libusb20_device *pdev, const char *id)
error = LIBUSB20_ERROR_OTHER;
goto done;
}
- if (ioctl(f, USB_GET_DEVICEINFO, &devinfo)) {
+ if (ioctl(f, IOUSB(USB_GET_DEVICEINFO), &devinfo)) {
error = LIBUSB20_ERROR_OTHER;
goto done;
}
@@ -240,7 +245,7 @@ repeat:
st->urd.urd_maxlen = sizeof(st->buf);
st->nparsed = 0;
- if (ioctl(st->f, USB_READ_DIR, &st->urd)) {
+ if (ioctl(st->f, IOUSB(USB_READ_DIR), &st->urd)) {
return (EINVAL);
}
st->ptr = st->buf;
@@ -312,7 +317,7 @@ ugen20_tr_release(struct libusb20_device *pdev)
/* release all pending USB transfers */
if (pdev->privBeData != NULL) {
memset(&fs_uninit, 0, sizeof(fs_uninit));
- if (ioctl(pdev->file, USB_FS_UNINIT, &fs_uninit)) {
+ if (ioctl(pdev->file, IOUSB(USB_FS_UNINIT), &fs_uninit)) {
/* ignore any errors of this kind */
}
}
@@ -352,7 +357,7 @@ ugen20_tr_renew(struct libusb20_device *pdev)
fs_init.pEndpoints = libusb20_pass_ptr(pdev->privBeData);
fs_init.ep_index_max = nMaxTransfer;
- if (ioctl(pdev->file, USB_FS_INIT, &fs_init)) {
+ if (ioctl(pdev->file, IOUSB(USB_FS_INIT), &fs_init)) {
error = LIBUSB20_ERROR_OTHER;
goto done;
}
@@ -386,7 +391,7 @@ ugen20_open_device(struct libusb20_device *pdev, uint16_t nMaxTransfer)
close(g);
return (LIBUSB20_ERROR_NO_DEVICE);
}
- if (ioctl(f, USB_GET_PLUGTIME, &plugtime)) {
+ if (ioctl(f, IOUSB(USB_GET_PLUGTIME), &plugtime)) {
error = LIBUSB20_ERROR_OTHER;
goto done;
}
@@ -429,7 +434,7 @@ ugen20_close_device(struct libusb20_device *pdev)
if (pdev->privBeData) {
memset(&fs_uninit, 0, sizeof(fs_uninit));
- if (ioctl(pdev->file, USB_FS_UNINIT, &fs_uninit)) {
+ if (ioctl(pdev->file, IOUSB(USB_FS_UNINIT), &fs_uninit)) {
/* ignore this error */
}
free(pdev->privBeData);
@@ -467,7 +472,7 @@ ugen20_get_config_desc_full(struct libusb20_device *pdev,
gen_desc.ugd_maxlen = sizeof(cdesc);
gen_desc.ugd_config_index = cfg_index;
- error = ioctl(pdev->file_ctrl, USB_GET_FULL_DESC, &gen_desc);
+ error = ioctl(pdev->file_ctrl, IOUSB(USB_GET_FULL_DESC), &gen_desc);
if (error) {
return (LIBUSB20_ERROR_OTHER);
}
@@ -487,7 +492,7 @@ ugen20_get_config_desc_full(struct libusb20_device *pdev,
gen_desc.ugd_data = libusb20_pass_ptr(ptr);
gen_desc.ugd_maxlen = len;
- error = ioctl(pdev->file_ctrl, USB_GET_FULL_DESC, &gen_desc);
+ error = ioctl(pdev->file_ctrl, IOUSB(USB_GET_FULL_DESC), &gen_desc);
if (error) {
free(ptr);
return (LIBUSB20_ERROR_OTHER);
@@ -506,7 +511,7 @@ ugen20_get_config_index(struct libusb20_device *pdev, uint8_t *pindex)
{
int temp;
- if (ioctl(pdev->file_ctrl, USB_GET_CONFIG, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_GET_CONFIG), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
*pindex = temp;
@@ -522,7 +527,7 @@ ugen20_set_config_index(struct libusb20_device *pdev, uint8_t cfg_index)
/* release all active USB transfers */
ugen20_tr_release(pdev);
- if (ioctl(pdev->file_ctrl, USB_SET_CONFIG, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_SET_CONFIG), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
return (ugen20_tr_renew(pdev));
@@ -542,7 +547,7 @@ ugen20_set_alt_index(struct libusb20_device *pdev,
/* release all active USB transfers */
ugen20_tr_release(pdev);
- if (ioctl(pdev->file_ctrl, USB_SET_ALTINTERFACE, &alt_iface)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_SET_ALTINTERFACE), &alt_iface)) {
return (LIBUSB20_ERROR_OTHER);
}
return (ugen20_tr_renew(pdev));
@@ -556,7 +561,7 @@ ugen20_reset_device(struct libusb20_device *pdev)
/* release all active USB transfers */
ugen20_tr_release(pdev);
- if (ioctl(pdev->file_ctrl, USB_DEVICEENUMERATE, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_DEVICEENUMERATE), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
return (ugen20_tr_renew(pdev));
@@ -568,7 +573,7 @@ ugen20_check_connected(struct libusb20_device *pdev)
uint32_t plugtime;
int error = 0;
- if (ioctl(pdev->file_ctrl, USB_GET_PLUGTIME, &plugtime)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_GET_PLUGTIME), &plugtime)) {
error = LIBUSB20_ERROR_NO_DEVICE;
goto done;
}
@@ -605,7 +610,7 @@ ugen20_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode)
default:
return (LIBUSB20_ERROR_INVALID_PARAM);
}
- if (ioctl(pdev->file_ctrl, USB_SET_POWER_MODE, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_SET_POWER_MODE), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
return (0);
@@ -616,7 +621,7 @@ ugen20_get_power_mode(struct libusb20_device *pdev, uint8_t *power_mode)
{
int temp;
- if (ioctl(pdev->file_ctrl, USB_GET_POWER_MODE, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_GET_POWER_MODE), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
switch (temp) {
@@ -644,11 +649,27 @@ ugen20_get_power_mode(struct libusb20_device *pdev, uint8_t *power_mode)
}
static int
+ugen20_get_port_path(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize)
+{
+ struct usb_device_port_path udpp;
+
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_GET_DEV_PORT_PATH), &udpp))
+ return (LIBUSB20_ERROR_OTHER);
+
+ if (udpp.udp_port_level > bufsize)
+ return (LIBUSB20_ERROR_OVERFLOW);
+
+ memcpy(buf, udpp.udp_port_no, udpp.udp_port_level);
+
+ return (udpp.udp_port_level); /* success */
+}
+
+static int
ugen20_get_power_usage(struct libusb20_device *pdev, uint16_t *power_usage)
{
int temp;
- if (ioctl(pdev->file_ctrl, USB_GET_POWER_USAGE, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_GET_POWER_USAGE), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
*power_usage = temp;
@@ -661,7 +682,7 @@ ugen20_kernel_driver_active(struct libusb20_device *pdev,
{
int temp = iface_index;
- if (ioctl(pdev->file_ctrl, USB_IFACE_DRIVER_ACTIVE, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_IFACE_DRIVER_ACTIVE), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
return (0); /* kernel driver is active */
@@ -673,10 +694,10 @@ ugen20_detach_kernel_driver(struct libusb20_device *pdev,
{
int temp = iface_index;
- if (ioctl(pdev->file_ctrl, USB_IFACE_DRIVER_DETACH, &temp)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_IFACE_DRIVER_DETACH), &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
- return (0); /* kernel driver is active */
+ return (0); /* kernel driver is detached */
}
static int
@@ -696,14 +717,14 @@ ugen20_do_request_sync(struct libusb20_device *pdev,
sizeof(req.ucr_request), setup)) {
/* ignore */
}
- if (ioctl(pdev->file_ctrl, USB_DO_REQUEST, &req)) {
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_DO_REQUEST), &req)) {
return (LIBUSB20_ERROR_OTHER);
}
if (pactlen) {
/* get actual length */
*pactlen = req.ucr_actlen;
}
- return (0); /* kernel driver is active */
+ return (0); /* request was successful */
}
static int
@@ -715,7 +736,7 @@ ugen20_process(struct libusb20_device *pdev)
while (1) {
- if (ioctl(pdev->file, USB_FS_COMPLETE, &temp)) {
+ if (ioctl(pdev->file, IOUSB(USB_FS_COMPLETE), &temp)) {
if (errno == EBUSY) {
break;
} else {
@@ -783,10 +804,10 @@ ugen20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize,
if (stream_id != 0) {
temp.fs_open_stream.stream_id = stream_id;
- if (ioctl(xfer->pdev->file, USB_FS_OPEN_STREAM, &temp.fs_open_stream))
+ if (ioctl(xfer->pdev->file, IOUSB(USB_FS_OPEN_STREAM), &temp.fs_open_stream))
return (LIBUSB20_ERROR_INVALID_PARAM);
} else {
- if (ioctl(xfer->pdev->file, USB_FS_OPEN, &temp.fs_open))
+ if (ioctl(xfer->pdev->file, IOUSB(USB_FS_OPEN), &temp.fs_open))
return (LIBUSB20_ERROR_INVALID_PARAM);
}
/* maximums might have changed - update */
@@ -812,7 +833,7 @@ ugen20_tr_close(struct libusb20_transfer *xfer)
temp.ep_index = xfer->trIndex;
- if (ioctl(xfer->pdev->file, USB_FS_CLOSE, &temp)) {
+ if (ioctl(xfer->pdev->file, IOUSB(USB_FS_CLOSE), &temp)) {
return (LIBUSB20_ERROR_INVALID_PARAM);
}
return (0); /* success */
@@ -829,7 +850,7 @@ ugen20_tr_clear_stall_sync(struct libusb20_transfer *xfer)
temp.ep_index = xfer->trIndex;
- if (ioctl(xfer->pdev->file, USB_FS_CLEAR_STALL_SYNC, &temp)) {
+ if (ioctl(xfer->pdev->file, IOUSB(USB_FS_CLEAR_STALL_SYNC), &temp)) {
return (LIBUSB20_ERROR_INVALID_PARAM);
}
return (0); /* success */
@@ -868,7 +889,7 @@ ugen20_tr_submit(struct libusb20_transfer *xfer)
temp.ep_index = xfer->trIndex;
- if (ioctl(xfer->pdev->file, USB_FS_START, &temp)) {
+ if (ioctl(xfer->pdev->file, IOUSB(USB_FS_START), &temp)) {
/* ignore any errors - should never happen */
}
return; /* success */
@@ -883,7 +904,7 @@ ugen20_tr_cancel_async(struct libusb20_transfer *xfer)
temp.ep_index = xfer->trIndex;
- if (ioctl(xfer->pdev->file, USB_FS_STOP, &temp)) {
+ if (ioctl(xfer->pdev->file, IOUSB(USB_FS_STOP), &temp)) {
/* ignore any errors - should never happen */
}
return;
@@ -922,7 +943,7 @@ ugen20_dev_get_iface_desc(struct libusb20_device *pdev,
ugd.ugd_maxlen = len;
ugd.ugd_iface_index = iface_index;
- if (ioctl(pdev->file, USB_GET_IFACE_DRIVER, &ugd)) {
+ if (ioctl(pdev->file, IOUSB(USB_GET_IFACE_DRIVER), &ugd)) {
return (LIBUSB20_ERROR_INVALID_PARAM);
}
return (0);
@@ -932,7 +953,7 @@ static int
ugen20_dev_get_info(struct libusb20_device *pdev,
struct usb_device_info *pinfo)
{
- if (ioctl(pdev->file, USB_GET_DEVICEINFO, pinfo)) {
+ if (ioctl(pdev->file, IOUSB(USB_GET_DEVICEINFO), pinfo)) {
return (LIBUSB20_ERROR_INVALID_PARAM);
}
return (0);
@@ -949,7 +970,7 @@ ugen20_root_get_dev_quirk(struct libusb20_backend *pbe,
q.index = quirk_index;
- error = ugen20_be_ioctl(USB_DEV_QUIRK_GET, &q);
+ error = ugen20_be_ioctl(IOUSB(USB_DEV_QUIRK_GET), &q);
if (error) {
if (errno == EINVAL) {
@@ -976,7 +997,7 @@ ugen20_root_get_quirk_name(struct libusb20_backend *pbe, uint16_t quirk_index,
q.index = quirk_index;
- error = ugen20_be_ioctl(USB_QUIRK_NAME_GET, &q);
+ error = ugen20_be_ioctl(IOUSB(USB_QUIRK_NAME_GET), &q);
if (error) {
if (errno == EINVAL) {
@@ -1003,7 +1024,7 @@ ugen20_root_add_dev_quirk(struct libusb20_backend *pbe,
q.bcdDeviceHigh = pq->bcdDeviceHigh;
strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
- error = ugen20_be_ioctl(USB_DEV_QUIRK_ADD, &q);
+ error = ugen20_be_ioctl(IOUSB(USB_DEV_QUIRK_ADD), &q);
if (error) {
if (errno == ENOMEM) {
return (LIBUSB20_ERROR_NO_MEM);
@@ -1027,7 +1048,7 @@ ugen20_root_remove_dev_quirk(struct libusb20_backend *pbe,
q.bcdDeviceHigh = pq->bcdDeviceHigh;
strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
- error = ugen20_be_ioctl(USB_DEV_QUIRK_REMOVE, &q);
+ error = ugen20_be_ioctl(IOUSB(USB_DEV_QUIRK_REMOVE), &q);
if (error) {
if (errno == EINVAL) {
return (LIBUSB20_ERROR_NOT_FOUND);
@@ -1039,11 +1060,11 @@ ugen20_root_remove_dev_quirk(struct libusb20_backend *pbe,
static int
ugen20_root_set_template(struct libusb20_backend *pbe, int temp)
{
- return (ugen20_be_ioctl(USB_SET_TEMPLATE, &temp));
+ return (ugen20_be_ioctl(IOUSB(USB_SET_TEMPLATE), &temp));
}
static int
ugen20_root_get_template(struct libusb20_backend *pbe, int *ptemp)
{
- return (ugen20_be_ioctl(USB_GET_TEMPLATE, ptemp));
+ return (ugen20_be_ioctl(IOUSB(USB_GET_TEMPLATE), ptemp));
}
diff --git a/lib/libusb/libusb_global_linux.h b/lib/libusb/libusb_global_linux.h
index cbdd2c6..13d344a 100644
--- a/lib/libusb/libusb_global_linux.h
+++ b/lib/libusb/libusb_global_linux.h
@@ -29,7 +29,9 @@
#define _XOPEN_SOURCE
#define _BSD_SOURCE
+#ifdef __linux__
#define _POSIX_SOURCE
+#endif
#define _POSIX_C_SOURCE 200809
#include <ctype.h>
@@ -39,10 +41,13 @@
#include <stdint.h>
#include <time.h>
#include <unistd.h>
+#ifdef __linux__
#include <alloca.h>
+#endif
#include <string.h>
#include <fcntl.h>
#include <limits.h>
+#include <setjmp.h>
#include <pthread.h>
#include <sys/queue.h>
#include <sys/ioctl.h>
@@ -51,6 +56,10 @@
#include <dev/usb/usb_endian.h>
#include <dev/usb/usb_freebsd.h>
+#include <compat/linux/linux_ioctl.h>
+
+#define IOUSB(a) FBSD_L##a
+
#ifndef __aligned
#define __aligned(x) __attribute__((__aligned__(x)))
#endif
OpenPOWER on IntegriCloud