diff options
Diffstat (limited to 'lib/libusb')
-rw-r--r-- | lib/libusb/Makefile | 9 | ||||
-rw-r--r-- | lib/libusb/Makefile.depend | 1 | ||||
-rw-r--r-- | lib/libusb/libusb-0.1.pc.in (renamed from lib/libusb/libusb-0.1.pc) | 6 | ||||
-rw-r--r-- | lib/libusb/libusb-1.0.pc.in (renamed from lib/libusb/libusb-1.0.pc) | 6 | ||||
-rw-r--r-- | lib/libusb/libusb-2.0.pc.in (renamed from lib/libusb/libusb-2.0.pc) | 6 | ||||
-rw-r--r-- | lib/libusb/libusb.3 | 40 | ||||
-rw-r--r-- | lib/libusb/libusb.h | 22 | ||||
-rw-r--r-- | lib/libusb/libusb01.c | 3 | ||||
-rw-r--r-- | lib/libusb/libusb10.c | 59 | ||||
-rw-r--r-- | lib/libusb/libusb10.h | 3 | ||||
-rw-r--r-- | lib/libusb/libusb10_desc.c | 3 | ||||
-rw-r--r-- | lib/libusb/libusb10_hotplug.c | 1 | ||||
-rw-r--r-- | lib/libusb/libusb10_io.c | 3 | ||||
-rw-r--r-- | lib/libusb/libusb20.3 | 2 | ||||
-rw-r--r-- | lib/libusb/libusb20.c | 3 | ||||
-rw-r--r-- | lib/libusb/libusb20.h | 3 | ||||
-rw-r--r-- | lib/libusb/libusb20_desc.c | 3 | ||||
-rw-r--r-- | lib/libusb/libusb20_desc.h | 3 | ||||
-rw-r--r-- | lib/libusb/libusb20_int.h | 3 | ||||
-rw-r--r-- | lib/libusb/libusb20_ugen20.c | 3 | ||||
-rw-r--r-- | lib/libusb/libusb_global_linux.h | 3 | ||||
-rw-r--r-- | lib/libusb/usb.h | 3 |
22 files changed, 123 insertions, 65 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile index 3cb2fbd7a462..4a0c392f0d8f 100644 --- a/lib/libusb/Makefile +++ b/lib/libusb/Makefile @@ -1,5 +1,4 @@ # -# $FreeBSD$ # # Makefile for the FreeBSD specific LibUSB 2.0 # @@ -35,6 +34,12 @@ SRCS+= libusb10_hotplug.c SRCS+= libusb10_io.c PCFILES= libusb-0.1.pc libusb-1.0.pc libusb-2.0.pc +.for pcfile in ${PCFILES} +${pcfile}: ${pcfile}.in + sed -e 's,@libdir@,${LIBDIR},g ; s,@sharedlibdir@,${SHLIBDIR},g ; \ + s,@includedir@,${INCLUDEDIR},g ;' ${.ALLSRC} > ${.TARGET} +.endfor +CLEANFILES+= ${PCFILES} # # Cross platform support @@ -62,6 +67,7 @@ CFLAGS+= -I ../../sys # LibUSB v1.0 MLINKS += libusb.3 libusb_get_version.3 MLINKS += libusb.3 libusb_init.3 +MLINKS += libusb.3 libusb_init_context.3 MLINKS += libusb.3 libusb_exit.3 MLINKS += libusb.3 libusb_has_capability.3 MLINKS += libusb.3 libusb_strerror.3 @@ -131,6 +137,7 @@ MLINKS += libusb.3 libusb_lock_events.3 MLINKS += libusb.3 libusb_unlock_events.3 MLINKS += libusb.3 libusb_event_handling_ok.3 MLINKS += libusb.3 libusb_event_handler_active.3 +MLINKS += libusb.3 libusb_interrupt_event_handler.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 diff --git a/lib/libusb/Makefile.depend b/lib/libusb/Makefile.depend index 25b26ea326c8..577dc5747f1e 100644 --- a/lib/libusb/Makefile.depend +++ b/lib/libusb/Makefile.depend @@ -1,4 +1,3 @@ -# $FreeBSD$ # Autogenerated - do NOT edit! DIRDEPS = \ diff --git a/lib/libusb/libusb-0.1.pc b/lib/libusb/libusb-0.1.pc.in index afd7a9960798..72b7a60eadd0 100644 --- a/lib/libusb/libusb-0.1.pc +++ b/lib/libusb/libusb-0.1.pc.in @@ -1,8 +1,8 @@ -# $FreeBSD$ prefix=/usr exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include +libdir=@libdir@ +sharedlibdir=@sharedlibdir@ +includedir=@includedir@ Name: libusb-0.1 Description: Library that abstracts ways to access USB devices (v0.1) diff --git a/lib/libusb/libusb-1.0.pc b/lib/libusb/libusb-1.0.pc.in index b31affadbed6..7dbf746e773e 100644 --- a/lib/libusb/libusb-1.0.pc +++ b/lib/libusb/libusb-1.0.pc.in @@ -1,8 +1,8 @@ -# $FreeBSD$ prefix=/usr exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include +libdir=@libdir@ +sharedlibdir=@sharedlibdir@ +includedir=@includedir@ Name: libusb-1.0 Description: Library that abstracts ways to access USB devices (v1.0) diff --git a/lib/libusb/libusb-2.0.pc b/lib/libusb/libusb-2.0.pc.in index 34eabb88ab17..4ac152bb09ff 100644 --- a/lib/libusb/libusb-2.0.pc +++ b/lib/libusb/libusb-2.0.pc.in @@ -1,8 +1,8 @@ -# $FreeBSD$ prefix=/usr exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include +libdir=@libdir@ +sharedlibdir=@sharedlibdir@ +includedir=@includedir@ Name: libusb-2.0 Description: Library that abstracts ways to access USB devices (v2.0) diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3 index 0d0e2b1a4ef1..43afa55380a8 100644 --- a/lib/libusb/libusb.3 +++ b/lib/libusb/libusb.3 @@ -1,8 +1,6 @@ .\" .\" Copyright (c) 2009 Sylvestre Gallon .\" -.\" All rights reserved. -.\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: @@ -24,9 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ -.\" -.Dd June 9, 2020 +.Dd January, 26, 2023 .Dt LIBUSB 3 .Os .Sh NAME @@ -49,11 +45,26 @@ This function returns version information about LibUSB. .Pp .Ft int .Fn libusb_init "libusb_context **ctx" -This function initialises libusb. -It must be called at the beginning -of the program, before other libusb routines are used. -This function returns 0 on success or LIBUSB_ERROR on -failure. +Call this function before any other libusb v1.0 API function, to +initialise a valid libusb v1.0 context. +If the +.Fa ctx +argument is non-NULL, a pointer to the libusb context is stored at +the given location. +This function returns 0 upon success or LIBUSB_ERROR on failure. +.Pp +.Ft int +.Fn libusb_init_context "libusb_context **ctx" "const struct libusb_init_option []" "int num_options" +Call this function before any other libusb v1.0 API function, to +initialise a valid libusb v1.0 context. +If the +.Fa ctx +argument is non-NULL, a pointer to the libusb context is stored at +the given location. +Additional options, like the USB debug level, may be given using the +second and third argument. +If no options are needed, simply use libusb_init(). +This function returns 0 upon success or a LIBUSB_ERROR value on failure. .Pp .Ft void .Fn libusb_exit "libusb_context *ctx" @@ -604,6 +615,15 @@ Returns 1 if there is a thread handling events and 0 if there are no threads currently handling events. .Pp .Ft void +.Fn libusb_interrupt_event_handler "libusb_context *ctx" +Causes the +.Fn libusb_handle_events +familiy of functions to return to the caller one time. +The +.Fn libusb_handle_events +functions may be called again after calling this function. +.Pp +.Ft void .Fn libusb_lock_event_waiters "libusb_context *ctx" Acquire the event_waiters lock. This lock is designed to be obtained in the diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h index 3d353402ea06..732fc9dca1e0 100644 --- a/lib/libusb/libusb.h +++ b/lib/libusb/libusb.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * @@ -246,7 +245,7 @@ enum libusb_log_level { /* XXX */ /* libusb_set_debug should take parameters from libusb_log_level * above according to - * http://libusb.sourceforge.net/api-1.0/group__lib.html + * https://libusb.sourceforge.io/api-1.0/group__libusb__lib.html */ enum libusb_debug_level { LIBUSB_DEBUG_NO=0, @@ -266,6 +265,14 @@ typedef enum { LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 2, } libusb_hotplug_event; +enum libusb_option { + LIBUSB_OPTION_LOG_LEVEL = 0, + LIBUSB_OPTION_USE_USBDK = 1, + LIBUSB_OPTION_NO_DEVICE_DISCOVERY = 2, + LIBUSB_OPTION_WEAK_AUTHORITY = 2, + LIBUSB_OPTION_MAX = 3, +}; + /* libusb structures */ struct libusb_context; @@ -288,6 +295,13 @@ struct libusb_version { const char *describe; }; +struct libusb_init_option { + enum libusb_option option; + union { + int64_t ival; + } value; +}; + typedef struct libusb_context libusb_context; typedef struct libusb_device libusb_device; typedef struct libusb_device_handle libusb_device_handle; @@ -465,6 +479,7 @@ const struct libusb_version *libusb_get_version(void); const char *libusb_strerror(int code); const char *libusb_error_name(int code); int libusb_init(libusb_context ** context); +int libusb_init_context(libusb_context **, const struct libusb_init_option [], int num_options); void libusb_exit(struct libusb_context *ctx); int libusb_has_capability(uint32_t capability); @@ -550,6 +565,7 @@ void libusb_lock_events(libusb_context * ctx); void libusb_unlock_events(libusb_context * ctx); int libusb_event_handling_ok(libusb_context * ctx); int libusb_event_handler_active(libusb_context * ctx); +void libusb_interrupt_event_handler(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); diff --git a/lib/libusb/libusb01.c b/lib/libusb/libusb01.c index 8b2031e0b804..7017016693af 100644 --- a/lib/libusb/libusb01.c +++ b/lib/libusb/libusb01.c @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index ecfffde555aa..6d9c11910ea0 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -1,9 +1,8 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. - * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2009-2023 Hans Petter Selasky * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -116,12 +115,16 @@ libusb_set_nonblocking(int f) fcntl(f, F_SETFL, flags); } -static void -libusb10_wakeup_event_loop(libusb_context *ctx) +void +libusb_interrupt_event_handler(libusb_context *ctx) { - uint8_t dummy = 0; + uint8_t dummy; int err; + if (ctx == NULL) + return; + + dummy = 0; err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); if (err < (int)sizeof(dummy)) { /* ignore error, if any */ @@ -132,11 +135,21 @@ libusb10_wakeup_event_loop(libusb_context *ctx) int libusb_init(libusb_context **context) { + return (libusb_init_context(context, NULL, 0)); +} + +int +libusb_init_context(libusb_context **context, + const struct libusb_init_option option[], int num_options) +{ struct libusb_context *ctx; pthread_condattr_t attr; char *debug, *ep; int ret; + if (num_options < 0) + return (LIBUSB_ERROR_INVALID_PARAM); + ctx = malloc(sizeof(*ctx)); if (!ctx) return (LIBUSB_ERROR_INVALID_PARAM); @@ -146,8 +159,9 @@ libusb_init(libusb_context **context) debug = getenv("LIBUSB_DEBUG"); if (debug != NULL) { /* - * If LIBUSB_DEBUG is set, we'll honor that and use it to - * override libusb_set_debug calls. + * If LIBUSB_DEBUG is set, we'll honor that first and + * use it to override any future libusb_set_debug() + * calls or init options. */ errno = 0; ctx->debug = strtol(debug, &ep, 10); @@ -162,7 +176,24 @@ libusb_init(libusb_context **context) */ ctx->debug = 0; } + } else { + /* + * If the LIBUSB_OPTION_LOG_LEVEL is set, honor that. + */ + for (int i = 0; i != num_options; i++) { + if (option[i].option != LIBUSB_OPTION_LOG_LEVEL) + continue; + + ctx->debug = (int)option[i].value.ival; + if ((int64_t)ctx->debug == option[i].value.ival) { + ctx->debug_fixed = 1; + } else { + free(ctx); + return (LIBUSB_ERROR_INVALID_PARAM); + } + } } + TAILQ_INIT(&ctx->pollfds); TAILQ_INIT(&ctx->tr_done); TAILQ_INIT(&ctx->hotplug_cbh); @@ -545,7 +576,7 @@ libusb_open(libusb_device *dev, libusb_device_handle **devh) POLLOUT | POLLRDNORM | POLLWRNORM); /* make sure our event loop detects the new device */ - libusb10_wakeup_event_loop(ctx); + libusb_interrupt_event_handler(ctx); *devh = pdev; @@ -614,7 +645,7 @@ libusb_close(struct libusb20_device *pdev) libusb_unref_device(dev); /* make sure our event loop detects the closed device */ - libusb10_wakeup_event_loop(ctx); + libusb_interrupt_event_handler(ctx); } libusb_device * @@ -1443,7 +1474,7 @@ found: failure: libusb10_complete_transfer(pxfer0, sxfer, LIBUSB_TRANSFER_ERROR); /* make sure our event loop spins the done handler */ - libusb10_wakeup_event_loop(dev->ctx); + libusb_interrupt_event_handler(dev->ctx); } /* The following function must be called unlocked */ @@ -1555,7 +1586,7 @@ libusb_cancel_transfer(struct libusb_transfer *uxfer) libusb10_complete_transfer(NULL, sxfer, LIBUSB_TRANSFER_CANCELLED); /* make sure our event loop spins the done handler */ - libusb10_wakeup_event_loop(dev->ctx); + libusb_interrupt_event_handler(dev->ctx); } else if (pxfer0 == NULL || pxfer1 == NULL) { /* not started */ retval = LIBUSB_ERROR_NOT_FOUND; @@ -1566,7 +1597,7 @@ libusb_cancel_transfer(struct libusb_transfer *uxfer) /* clear transfer pointer */ libusb20_tr_set_priv_sc1(pxfer0, NULL); /* make sure our event loop spins the done handler */ - libusb10_wakeup_event_loop(dev->ctx); + libusb_interrupt_event_handler(dev->ctx); } else { libusb20_tr_stop(pxfer0); /* make sure the queue doesn't stall */ @@ -1580,7 +1611,7 @@ libusb_cancel_transfer(struct libusb_transfer *uxfer) /* clear transfer pointer */ libusb20_tr_set_priv_sc1(pxfer1, NULL); /* make sure our event loop spins the done handler */ - libusb10_wakeup_event_loop(dev->ctx); + libusb_interrupt_event_handler(dev->ctx); } else { libusb20_tr_stop(pxfer1); /* make sure the queue doesn't stall */ diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h index 5caa56666c32..544364386061 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * diff --git a/lib/libusb/libusb10_desc.c b/lib/libusb/libusb10_desc.c index b0866a78b791..3e36009cbb3a 100644 --- a/lib/libusb/libusb10_desc.c +++ b/lib/libusb/libusb10_desc.c @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * diff --git a/lib/libusb/libusb10_hotplug.c b/lib/libusb/libusb10_hotplug.c index fb1c3d59e51f..9d00b1dbe5a0 100644 --- a/lib/libusb/libusb10_hotplug.c +++ b/lib/libusb/libusb10_hotplug.c @@ -1,4 +1,3 @@ -/* $FreeBSD$ */ /*- * Copyright (c) 2016-2019 Hans Petter Selasky. All rights reserved. * diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 0e32fc31c8e0..59bac60c4672 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. * diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3 index 66d868cfea37..1d07db8f32a4 100644 --- a/lib/libusb/libusb20.3 +++ b/lib/libusb/libusb20.3 @@ -24,8 +24,6 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ -.\" .Dd December 27, 2019 .Dt LIBUSB20 3 .Os diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c index 60a5f8448888..25c95adc27ff 100644 --- a/lib/libusb/libusb20.c +++ b/lib/libusb/libusb20.c @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved. * diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h index 52684aa802d5..7bca2f7508c7 100644 --- a/lib/libusb/libusb20.h +++ b/lib/libusb/libusb20.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved. * Copyright (c) 2007-2008 Daniel Drake. All rights reserved. diff --git a/lib/libusb/libusb20_desc.c b/lib/libusb/libusb20_desc.c index 3052af09e9c2..89c01d5afeff 100644 --- a/lib/libusb/libusb20_desc.c +++ b/lib/libusb/libusb20_desc.c @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h index bb7724294cb4..017148a34b1c 100644 --- a/lib/libusb/libusb20_desc.h +++ b/lib/libusb/libusb20_desc.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * Copyright (c) 2007-2008 Daniel Drake. All rights reserved. diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h index 16796dc1233d..4b0cef442c36 100644 --- a/lib/libusb/libusb20_int.h +++ b/lib/libusb/libusb20_int.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c index efffff2b5ef0..11064d2644d6 100644 --- a/lib/libusb/libusb20_ugen20.c +++ b/lib/libusb/libusb20_ugen20.c @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * diff --git a/lib/libusb/libusb_global_linux.h b/lib/libusb/libusb_global_linux.h index 3e83bb2a6ea4..1964f19c6e5e 100644 --- a/lib/libusb/libusb_global_linux.h +++ b/lib/libusb/libusb_global_linux.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2013 Hans Petter Selasky. All rights reserved. * diff --git a/lib/libusb/usb.h b/lib/libusb/usb.h index 1a71029e9c0e..ab225060c55e 100644 --- a/lib/libusb/usb.h +++ b/lib/libusb/usb.h @@ -1,6 +1,5 @@ -/* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * |