From 9b0c1abe99cfd7e619068968896b466f0d1d6f69 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Mon, 10 Mar 2014 21:22:22 +0100 Subject: [PATCH] Sync libusb with FreeBSD. --- etc/mtree/BSD.usr.dist | 2 + lib/libusb/Makefile | 40 +++++++- lib/libusb/libusb-0.1.pc | 11 +++ lib/libusb/libusb-1.0.pc | 11 +++ lib/libusb/libusb-2.0.pc | 11 +++ lib/libusb/libusb.3 | 50 +++++++++- lib/libusb/libusb.h | 11 ++- lib/libusb/libusb01.c | 11 ++- lib/libusb/libusb10.c | 44 ++++++--- lib/libusb/libusb10.h | 4 +- lib/libusb/libusb10_desc.c | 11 ++- lib/libusb/libusb10_io.c | 53 ++++++++--- lib/libusb/libusb20.3 | 47 ++++++++-- lib/libusb/libusb20.c | 59 ++++++++---- lib/libusb/libusb20.h | 13 ++- lib/libusb/libusb20_desc.c | 14 ++- lib/libusb/libusb20_desc.h | 6 +- lib/libusb/libusb20_int.h | 8 +- lib/libusb/libusb20_ugen20.c | 154 ++++++++++++++++++++----------- lib/libusb/libusb_global_linux.h | 78 ++++++++++++++++ lib/libusb/usb.h | 7 +- 21 files changed, 507 insertions(+), 138 deletions(-) create mode 100644 lib/libusb/libusb-0.1.pc create mode 100644 lib/libusb/libusb-1.0.pc create mode 100644 lib/libusb/libusb-2.0.pc create mode 100644 lib/libusb/libusb_global_linux.h diff --git a/etc/mtree/BSD.usr.dist b/etc/mtree/BSD.usr.dist index 5e74994e5a..b97ff9f348 100644 --- a/etc/mtree/BSD.usr.dist +++ b/etc/mtree/BSD.usr.dist @@ -66,6 +66,8 @@ ssp .. .. + pkgconfig + .. .. libexec binutils222 diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile index 84a9a40331..4cdb161f4b 100644 --- a/lib/libusb/Makefile +++ b/lib/libusb/Makefile @@ -1,5 +1,5 @@ # -# $FreeBSD: src/lib/libusb/Makefile,v 1.18 2012/06/12 07:28:25 hselasky Exp $ +# $FreeBSD: head/lib/libusb/Makefile 260315 2014-01-05 10:41:43Z hselasky $ # # Makefile for the FreeBSD specific LibUSB 2.0 # @@ -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,6 +38,37 @@ 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 \ +# 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}\" +CFLAGS+= -DUSB_GLOBAL_INCLUDE_FILE=\"${LIBUSB_GLOBAL_INCLUDE_FILE}\" +CFLAGS+= -I ../../sys +.endif + .include # LibUSB v1.0 @@ -98,6 +130,8 @@ MLINKS += libusb.3 libusb_event_handler_active.3 MLINKS += libusb.3 libusb_lock_event_waiters.3 MLINKS += libusb.3 libusb_unlock_event_waiters.3 MLINKS += libusb.3 libusb_wait_for_event.3 +MLINKS += libusb.3 libusb_handle_events_timeout_completed.3 +MLINKS += libusb.3 libusb_handle_events_completed.3 MLINKS += libusb.3 libusb_handle_events_timeout.3 MLINKS += libusb.3 libusb_handle_events.3 MLINKS += libusb.3 libusb_handle_events_locked.3 @@ -190,6 +224,8 @@ 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 MLINKS += libusb20.3 libusb20_dev_alloc_config.3 diff --git a/lib/libusb/libusb-0.1.pc b/lib/libusb/libusb-0.1.pc new file mode 100644 index 0000000000..f67e4880ef --- /dev/null +++ b/lib/libusb/libusb-0.1.pc @@ -0,0 +1,11 @@ +# $FreeBSD: head/lib/libusb/libusb-0.1.pc 253637 2013-07-25 03:54:08Z rpaulo $ +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 0000000000..1918212eac --- /dev/null +++ b/lib/libusb/libusb-1.0.pc @@ -0,0 +1,11 @@ +# $FreeBSD: head/lib/libusb/libusb-1.0.pc 253637 2013-07-25 03:54:08Z rpaulo $ +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 0000000000..2c04058e52 --- /dev/null +++ b/lib/libusb/libusb-2.0.pc @@ -0,0 +1,11 @@ +# $FreeBSD: head/lib/libusb/libusb-2.0.pc 253637 2013-07-25 03:54:08Z rpaulo $ +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 4babc2d2d0..dd1a78c886 100644 --- a/lib/libusb/libusb.3 +++ b/lib/libusb/libusb.3 @@ -24,9 +24,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libusb/libusb.3,v 1.27 2012/05/11 20:06:46 gjb Exp $ +.\" $FreeBSD: head/lib/libusb/libusb.3 260315 2014-01-05 10:41:43Z hselasky $ .\" -.Dd October 14, 2012 +.Dd January 5, 2014 .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 @@ -472,11 +485,40 @@ transfer completes or another thread stops event handling, and 1 if the timeout expired. .Pp .Ft int +.Fn libusb_handle_events_timeout_completed "libusb_context *ctx" "struct timeval *tv" "int *completed" +Handle any pending events by checking if timeouts have expired and by +checking the set of file descriptors for activity. +If the +.Fa completed +argument is not equal to NULL, this function will +loop until a transfer completion callback sets the variable pointed to +by the +.Fa completed +argument to non-zero. +If the +.Fa tv +argument is not equal to NULL, this function will return +LIBUSB_ERROR_TIMEOUT after the given timeout. +Returns 0 on success, or a LIBUSB_ERROR code on failure or timeout. +.Pp +.Ft int +.Fn libusb_handle_events_completed "libusb_context *ctx" "int *completed" +Handle any pending events by checking the set of file descriptors for activity. +If the +.Fa completed +argument is not equal to NULL, this function will +loop until a transfer completion callback sets the variable pointed to +by the +.Fa completed +argument to non-zero. +Returns 0 on success, or a LIBUSB_ERROR code on failure. +.Pp +.Ft int .Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv" Handle any pending events by checking if timeouts have expired and by checking the set of file descriptors for activity. Returns 0 on success, or a -LIBUSB_ERROR code on failure. +LIBUSB_ERROR code on failure or timeout. .Pp .Ft int .Fn libusb_handle_events "libusb_context *ctx" @@ -495,7 +537,7 @@ Must be called with the event lock held. Determine the next internal timeout that libusb needs to handle. Returns 0 if there are no pending timeouts, 1 if a timeout was returned, or a LIBUSB_ERROR -code on failure. +code on failure or timeout. .Pp .Ft void .Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data" diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h index 0705588f83..a4a7345955 100644 --- a/lib/libusb/libusb.h +++ b/lib/libusb/libusb.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb.h,v 1.21 2012/05/07 14:07:13 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb.h 260315 2014-01-05 10:41:43Z hselasky $ */ /*- * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * @@ -27,8 +27,11 @@ #ifndef __LIBUSB_H__ #define __LIBUSB_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include #include #include +#endif #ifdef __cplusplus extern "C" { @@ -366,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); @@ -433,12 +438,14 @@ int libusb_event_handler_active(libusb_context * ctx); void libusb_lock_event_waiters(libusb_context * ctx); void libusb_unlock_event_waiters(libusb_context * ctx); int libusb_wait_for_event(libusb_context * ctx, struct timeval *tv); +int libusb_handle_events_timeout_completed(libusb_context * ctx, struct timeval *tv, int *completed); +int libusb_handle_events_completed(libusb_context * ctx, int *completed); int libusb_handle_events_timeout(libusb_context * ctx, struct timeval *tv); 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/libusb01.c b/lib/libusb/libusb01.c index 9312198ff7..cd31b55d0d 100644 --- a/lib/libusb/libusb01.c +++ b/lib/libusb/libusb01.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb01.c,v 1.2 2011/07/16 08:29:12 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb01.c 248236 2013-03-13 12:23:14Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * @@ -28,11 +28,16 @@ * This file contains the emulation layer for LibUSB v0.1 from sourceforge. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include +#include +#include +#include +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 21e8f353f7..ffb34eac80 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb10.c,v 1.25 2012/06/12 07:28:25 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb10.c 261224 2014-01-28 07:21:46Z hselasky $ */ /*- * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. @@ -25,17 +25,23 @@ * SUCH DAMAGE. */ -#include -#include -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include #include +#include #include +#include +#include +#include +#include +#include +#endif #define libusb_device_handle libusb20_device @@ -284,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) { @@ -592,7 +611,6 @@ int libusb_claim_interface(struct libusb20_device *pdev, int interface_number) { libusb_device *dev; - int err = 0; dev = libusb_get_device(pdev); if (dev == NULL) @@ -602,13 +620,10 @@ libusb_claim_interface(struct libusb20_device *pdev, int interface_number) return (LIBUSB_ERROR_INVALID_PARAM); CTX_LOCK(dev->ctx); - if (dev->claimed_interfaces & (1 << interface_number)) - err = LIBUSB_ERROR_BUSY; - - if (!err) - dev->claimed_interfaces |= (1 << interface_number); + dev->claimed_interfaces |= (1 << interface_number); CTX_UNLOCK(dev->ctx); - return (err); + + return (0); } int @@ -990,6 +1005,7 @@ libusb10_isoc_proxy(struct libusb20_transfer *pxfer) uint16_t iso_packets; uint16_t i; uint8_t status; + uint8_t flags; status = libusb20_tr_get_status(pxfer); sxfer = libusb20_tr_get_priv_sc1(pxfer); @@ -1011,6 +1027,8 @@ libusb10_isoc_proxy(struct libusb20_transfer *pxfer) /* make sure that the number of ISOCHRONOUS packets is valid */ uxfer->num_iso_packets = iso_packets; + flags = uxfer->flags; + switch (status) { case LIBUSB20_TRANSFER_COMPLETED: @@ -1328,7 +1346,7 @@ failure: /* make sure our event loop spins the done handler */ dummy = 0; - write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); + err = write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); } /* The following function must be called unlocked */ diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h index 722da45a37..7f4545cc77 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb10.h,v 1.4 2009/11/20 08:57:25 thompsa Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb10.h 248236 2013-03-13 12:23:14Z hselasky $ */ /*- * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * @@ -27,7 +27,9 @@ #ifndef __LIBUSB10_H__ #define __LIBUSB10_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include +#endif #define GET_CONTEXT(ctx) (((ctx) == NULL) ? usbi_default_context : (ctx)) #define UNEXPORTED __attribute__((__visibility__("hidden"))) diff --git a/lib/libusb/libusb10_desc.c b/lib/libusb/libusb10_desc.c index bcf4510e23..724affb45e 100644 --- a/lib/libusb/libusb10_desc.c +++ b/lib/libusb/libusb10_desc.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb10_desc.c,v 1.11 2012/05/07 14:07:13 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb10_desc.c 248236 2013-03-13 12:23:14Z hselasky $ */ /*- * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * @@ -24,10 +24,15 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include +#include +#include +#include +#endif #define libusb_device_handle libusb20_device diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 30995e4d7b..a221a35839 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb10_io.c,v 1.11 2012/06/12 07:28:25 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb10_io.c 260315 2014-01-05 10:41:43Z hselasky $ */ /*- * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * @@ -24,15 +24,20 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include +#include #include #include +#include +#include +#endif #define libusb_device_handle libusb20_device @@ -331,29 +336,50 @@ libusb_wait_for_event(libusb_context *ctx, struct timeval *tv) } int -libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv) +libusb_handle_events_timeout_completed(libusb_context *ctx, + struct timeval *tv, int *completed) { - int err; + int err = 0; ctx = GET_CONTEXT(ctx); - DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_handle_events_timeout enter"); + DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_handle_events_timeout_completed enter"); libusb_lock_events(ctx); - err = libusb_handle_events_locked(ctx, tv); + while (1) { + if (completed != NULL) { + if (*completed != 0 || err != 0) + break; + } + err = libusb_handle_events_locked(ctx, tv); + if (completed == NULL) + break; + } libusb_unlock_events(ctx); - DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_handle_events_timeout leave"); + DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_handle_events_timeout_completed exit"); return (err); } +int +libusb_handle_events_completed(libusb_context *ctx, int *completed) +{ + return (libusb_handle_events_timeout_completed(ctx, NULL, completed)); +} + +int +libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv) +{ + return (libusb_handle_events_timeout_completed(ctx, tv, NULL)); +} + int libusb_handle_events(libusb_context *ctx) { - return (libusb_handle_events_timeout(ctx, NULL)); + return (libusb_handle_events_timeout_completed(ctx, NULL, NULL)); } int @@ -366,8 +392,9 @@ libusb_handle_events_locked(libusb_context *ctx, struct timeval *tv) if (libusb_event_handling_ok(ctx)) { err = libusb10_handle_events_sub(ctx, tv); } else { - libusb_wait_for_event(ctx, tv); - err = 0; + err = libusb_wait_for_event(ctx, tv); + if (err != 0) + err = LIBUSB_ERROR_TIMEOUT; } return (err); } @@ -392,7 +419,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; @@ -418,7 +445,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 41bfa24723..670aa09212 100644 --- a/lib/libusb/libusb20.3 +++ b/lib/libusb/libusb20.3 @@ -24,9 +24,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libusb/libusb20.3,v 1.17 2012/08/13 18:10:52 hselasky Exp $ +.\" $FreeBSD: head/lib/libusb/libusb20.3 250582 2013-05-12 22:22:12Z joel $ .\" -.Dd October 14, 2012 +.Dd May 3, 2013 .Dt LIBUSB20 3 .Os .Sh NAME @@ -48,6 +48,7 @@ USB access library (libusb -lusb) .Fn libusb20_tr_close "struct libusb20_transfer *xfer" .Ft int .Fn libusb20_tr_open "struct libusb20_transfer *xfer" "uint32_t max_buf_size" "uint32_t max_frame_count" "uint8_t ep_no" +.Fn libusb20_tr_open_stream "struct libusb20_transfer *xfer" "uint32_t max_buf_size" "uint32_t max_frame_count" "uint8_t ep_no" "uint16_t stream_id" .Ft struct libusb20_transfer* .Fn libusb20_tr_get_pointer "struct libusb20_device *pdev" "uint16_t tr_index" .Ft uint16_t @@ -113,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" @@ -148,6 +151,8 @@ USB access library (libusb -lusb) .Fn libusb20_dev_set_power_mode "struct libusb20_device *pdev" "uint8_t power_mode" .Ft uint8_t .Fn libusb20_dev_get_power_mode "struct libusb20_device *pdev" +.Ft uint16_t +.Fn libusb20_dev_get_power_usage "struct libusb20_device *pdev" .Ft int .Fn libusb20_dev_set_alt_index "struct libusb20_device *pdev" "uint8_t iface_index" "uint8_t alt_index" .Ft struct LIBUSB20_DEVICE_DESC_DECODED * @@ -284,6 +289,16 @@ Non-zero return values indicate a LIBUSB20_ERROR value. . .Pp . +.Fn libusb20_tr_open_stream +is identical to +.Fn libusb20_tr_open +except that a stream ID can be specified for BULK endpoints having +such a feature. +.Fn libusb20_tr_open +can be used to open stream ID zero. +. +.Pp +. .Fn libusb20_tr_get_pointer will return a pointer to the allocated USB transfer according to the .Fa pdev @@ -539,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 . @@ -729,6 +758,12 @@ USB device. . .Pp . +.Fn libusb20_dev_get_power_usage +returns the reported power usage in milliamps for the given USB device. +A power usage of zero typically means that the device is self powered. +. +.Pp +. .Fn libusb20_dev_set_alt_index will try to set the given alternate index for the given USB interface index. @@ -1014,12 +1049,12 @@ argument. This function does not return NULL. . .Sh FILES -. -. -/dev/usb +.Bl -tag -width Pa +.It Pa /dev/usb +.El .Sh SEE ALSO -.Xr libusb 3 , .Xr usb 4 , +.Xr libusb 3 , .Xr usbconfig 8 , .Xr usbdump 8 . diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c index 0cadca2080..f0224c7978 100644 --- a/lib/libusb/libusb20.c +++ b/lib/libusb/libusb20.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb20.c,v 1.15 2012/04/20 14:29:45 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb20.c 253339 2013-07-14 10:22:00Z hselasky $ */ /*- * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved. * @@ -24,13 +24,17 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include +#include +#include +#endif #include "libusb20.h" #include "libusb20_desc.h" @@ -71,6 +75,8 @@ 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 #define dummy_do_request_sync (void *)dummy_int @@ -154,6 +160,13 @@ libusb20_tr_close(struct libusb20_transfer *xfer) int libusb20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no) +{ + return (libusb20_tr_open_stream(xfer, MaxBufSize, MaxFrameCount, ep_no, 0)); +} + +int +libusb20_tr_open_stream(struct libusb20_transfer *xfer, uint32_t MaxBufSize, + uint32_t MaxFrameCount, uint8_t ep_no, uint16_t stream_id) { uint32_t size; uint8_t pre_scale; @@ -188,7 +201,7 @@ libusb20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize, memset(xfer->ppBuffer, 0, size); error = xfer->pdev->methods->tr_open(xfer, MaxBufSize, - MaxFrameCount, ep_no, pre_scale); + MaxFrameCount, ep_no, stream_id, pre_scale); if (error) { free(xfer->ppBuffer); @@ -710,6 +723,24 @@ 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) +{ + int error; + uint16_t power_usage; + + error = pdev->methods->get_power_usage(pdev, &power_usage); + if (error) + power_usage = 0; + return (power_usage); +} + int libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t ifaceIndex, uint8_t altIndex) { @@ -1171,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__) || defined(__DragonFly__) - pbe = libusb20_be_alloc(&libusb20_ugen20_backend); -#else - pbe = NULL; -#endif - return (pbe); + return (libusb20_be_alloc(&libusb20_ugen20_backend)); } struct libusb20_backend * @@ -1199,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 a04c1e4d89..3db52d6274 100644 --- a/lib/libusb/libusb20.h +++ b/lib/libusb/libusb20.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb20.h,v 1.11 2011/09/19 08:52:06 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb20.h 250201 2013-05-03 07:44:58Z hselasky $ */ /*- * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved. * Copyright (c) 2007-2008 Daniel Drake. All rights reserved. @@ -29,13 +29,9 @@ #ifndef _LIBUSB20_H_ #define _LIBUSB20_H_ -#include -#include -#include - +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include -#include -#include +#endif #ifdef __cplusplus extern "C" { @@ -202,6 +198,7 @@ struct libusb20_quirk { /* USB transfer operations */ int libusb20_tr_close(struct libusb20_transfer *xfer); int libusb20_tr_open(struct libusb20_transfer *xfer, uint32_t max_buf_size, uint32_t max_frame_count, uint8_t ep_no); +int libusb20_tr_open_stream(struct libusb20_transfer *xfer, uint32_t max_buf_size, uint32_t max_frame_count, uint8_t ep_no, uint16_t stream_id); struct libusb20_transfer *libusb20_tr_get_pointer(struct libusb20_device *pdev, uint16_t tr_index); uint16_t libusb20_tr_get_time_complete(struct libusb20_transfer *xfer); uint32_t libusb20_tr_get_actual_frames(struct libusb20_transfer *xfer); @@ -254,6 +251,8 @@ 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); int libusb20_dev_get_iface_desc(struct libusb20_device *pdev, uint8_t iface_index, char *buf, uint8_t len); diff --git a/lib/libusb/libusb20_desc.c b/lib/libusb/libusb20_desc.c index fcf58419da..583ede47c8 100644 --- a/lib/libusb/libusb20_desc.c +++ b/lib/libusb/libusb20_desc.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb20_desc.c,v 1.6 2012/04/20 14:29:45 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb20_desc.c 248236 2013-03-13 12:23:14Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * @@ -24,11 +24,15 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include +#include +#include +#endif #include "libusb20.h" #include "libusb20_desc.h" @@ -513,7 +517,7 @@ libusb20_me_encode(void *ptr, uint16_t len, const void *pd) * room for the * complete structure: */ - __unused uint16_t dummy; + uint16_t dummy; dummy = libusb20_me_encode(buf, 0xFFFF - 3, ps->ptr); @@ -669,7 +673,7 @@ libusb20_me_decode(const void *ptr, uint16_t len, void *pd) ~(LIBUSB20_ME_STRUCT_ALIGN - 1)); /* align */ while (pd_count--) { uint16_t temp; - __unused uint16_t dummy; + uint16_t dummy; struct libusb20_me_struct *ps; ps = LIBUSB20_ADD_BYTES(pd, pd_offset); diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h index 11d18e4fc2..efb534fd74 100644 --- a/lib/libusb/libusb20_desc.h +++ b/lib/libusb/libusb20_desc.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb20_desc.h,v 1.2 2011/11/09 19:03:26 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb20_desc.h 248236 2013-03-13 12:23:14Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * Copyright (c) 2007-2008 Daniel Drake. All rights reserved. @@ -45,6 +45,10 @@ #ifndef _LIBUSB20_DESC_H_ #define _LIBUSB20_DESC_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h index 3807b269ac..e71f0501b0 100644 --- a/lib/libusb/libusb20_int.h +++ b/lib/libusb/libusb20_int.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb20_int.h,v 1.8 2011/06/24 11:14:09 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb20_int.h 250201 2013-05-03 07:44:58Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * @@ -105,12 +105,14 @@ 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); typedef int (libusb20_check_connected_t)(struct libusb20_device *pdev); /* USB transfer specific */ -typedef int (libusb20_tr_open_t)(struct libusb20_transfer *xfer, uint32_t MaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no, uint8_t pre_scale); +typedef int (libusb20_tr_open_t)(struct libusb20_transfer *xfer, uint32_t MaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no, uint16_t stream_id, uint8_t pre_scale); typedef int (libusb20_tr_close_t)(struct libusb20_transfer *xfer); typedef int (libusb20_tr_clear_stall_sync_t)(struct libusb20_transfer *xfer); typedef void (libusb20_tr_submit_t)(struct libusb20_transfer *xfer); @@ -127,6 +129,8 @@ 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) \ m(n, tr_cancel_async) \ diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c index bbb99e3539..9ccf6ae589 100644 --- a/lib/libusb/libusb20_ugen20.c +++ b/lib/libusb/libusb20_ugen20.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/libusb20_ugen20.c,v 1.13 2012/04/20 14:29:45 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/libusb20_ugen20.c 255242 2013-09-05 12:21:11Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * @@ -24,23 +24,31 @@ * SUCH DAMAGE. */ -#include -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include #include +#include +#include +#include +#endif + +#include +#include +#include #include "libusb20.h" #include "libusb20_desc.h" #include "libusb20_int.h" -#include -#include -#include +#ifndef IOUSB +#define IOUSB(a) a +#endif static libusb20_init_backend_t ugen20_init_backend; static libusb20_open_device_t ugen20_open_device; @@ -69,6 +77,8 @@ 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; static libusb20_do_request_sync_t ugen20_do_request_sync; @@ -139,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; } @@ -161,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; } @@ -235,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; @@ -307,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 */ } } @@ -347,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; } @@ -381,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; } @@ -424,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); @@ -462,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); } @@ -482,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); @@ -501,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; @@ -517,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)); @@ -537,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)); @@ -551,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)); @@ -563,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; } @@ -600,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); @@ -611,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) { @@ -638,13 +648,41 @@ ugen20_get_power_mode(struct libusb20_device *pdev, uint8_t *power_mode) return (0); /* success */ } +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, IOUSB(USB_GET_POWER_USAGE), &temp)) { + return (LIBUSB20_ERROR_OTHER); + } + *power_usage = temp; + return (0); /* success */ +} + static int ugen20_kernel_driver_active(struct libusb20_device *pdev, uint8_t iface_index) { 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 */ @@ -656,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 @@ -679,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 @@ -698,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 { @@ -741,9 +779,13 @@ ugen20_process(struct libusb20_device *pdev) static int ugen20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize, - uint32_t MaxFrameCount, uint8_t ep_no, uint8_t pre_scale) + uint32_t MaxFrameCount, uint8_t ep_no, uint16_t stream_id, + uint8_t pre_scale) { - struct usb_fs_open temp; + union { + struct usb_fs_open fs_open; + struct usb_fs_open_stream fs_open_stream; + } temp; struct usb_fs_endpoint *fsep; if (pre_scale) @@ -754,20 +796,26 @@ ugen20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize, fsep = xfer->pdev->privBeData; fsep += xfer->trIndex; - temp.max_bufsize = MaxBufSize; - temp.max_frames = MaxFrameCount; - temp.ep_index = xfer->trIndex; - temp.ep_no = ep_no; + temp.fs_open.max_bufsize = MaxBufSize; + temp.fs_open.max_frames = MaxFrameCount; + temp.fs_open.ep_index = xfer->trIndex; + temp.fs_open.ep_no = ep_no; - if (ioctl(xfer->pdev->file, USB_FS_OPEN, &temp)) { - return (LIBUSB20_ERROR_INVALID_PARAM); + if (stream_id != 0) { + temp.fs_open_stream.stream_id = stream_id; + + 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, IOUSB(USB_FS_OPEN), &temp.fs_open)) + return (LIBUSB20_ERROR_INVALID_PARAM); } /* maximums might have changed - update */ - xfer->maxFrames = temp.max_frames; + xfer->maxFrames = temp.fs_open.max_frames; /* "max_bufsize" should be multiple of "max_packet_length" */ - xfer->maxTotalLength = temp.max_bufsize; - xfer->maxPacketLen = temp.max_packet_length; + xfer->maxTotalLength = temp.fs_open.max_bufsize; + xfer->maxPacketLen = temp.fs_open.max_packet_length; /* setup buffer and length lists using zero copy */ fsep->ppBuffer = libusb20_pass_ptr(xfer->ppBuffer); @@ -785,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 */ @@ -802,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 */ @@ -841,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 */ @@ -856,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; @@ -895,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); @@ -905,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); @@ -922,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) { @@ -949,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) { @@ -976,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); @@ -1000,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); @@ -1012,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 new file mode 100644 index 0000000000..1984b43d95 --- /dev/null +++ b/lib/libusb/libusb_global_linux.h @@ -0,0 +1,78 @@ +/* $FreeBSD: head/lib/libusb/libusb_global_linux.h 253339 2013-07-14 10:22:00Z hselasky $ */ +/*- + * Copyright (c) 2013 Hans Petter Selasky. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _LIBUSB_GLOBAL_LINUX_H_ +#define _LIBUSB_GLOBAL_LINUX_H_ + +#define _XOPEN_SOURCE +#define _BSD_SOURCE +#ifdef __linux__ +#define _POSIX_SOURCE +#endif +#define _POSIX_C_SOURCE 200809 + +#include +#include +#include +#include +#include +#include +#include +#ifdef __linux__ +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define IOUSB(a) FBSD_L##a + +#ifndef __aligned +#define __aligned(x) __attribute__((__aligned__(x))) +#endif + +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif + +#ifndef strlcpy +#define strlcpy(d,s,len) do { \ + strncpy(d,s,len); \ + ((char *)d)[(len) - 1] = 0; \ +} while (0) +#endif + +#endif /* _LIBUSB_GLOBAL_LINUX_H_ */ diff --git a/lib/libusb/usb.h b/lib/libusb/usb.h index 75b9a4443c..c1f2105ff6 100644 --- a/lib/libusb/usb.h +++ b/lib/libusb/usb.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libusb/usb.h,v 1.5 2011/07/16 08:29:12 hselasky Exp $ */ +/* $FreeBSD: head/lib/libusb/usb.h 248236 2013-03-13 12:23:14Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * @@ -27,10 +27,11 @@ #ifndef _LIBUSB20_COMPAT_01_H_ #define _LIBUSB20_COMPAT_01_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include #include #include - -#include +#endif /* USB interface class codes */ -- 2.41.0