[Midnightbsd-cvs] src [9847] trunk/lib/libusb: sync libusb with freebsd 9-stable

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue May 22 22:32:44 EDT 2018


Revision: 9847
          http://svnweb.midnightbsd.org/src/?rev=9847
Author:   laffer1
Date:     2018-05-22 22:32:43 -0400 (Tue, 22 May 2018)
Log Message:
-----------
sync libusb with freebsd 9-stable

Modified Paths:
--------------
    trunk/lib/libusb/Makefile
    trunk/lib/libusb/libusb.3
    trunk/lib/libusb/libusb.h
    trunk/lib/libusb/libusb01.c
    trunk/lib/libusb/libusb10.c
    trunk/lib/libusb/libusb10.h
    trunk/lib/libusb/libusb10_desc.c
    trunk/lib/libusb/libusb10_io.c
    trunk/lib/libusb/libusb20.3
    trunk/lib/libusb/libusb20.c
    trunk/lib/libusb/libusb20.h
    trunk/lib/libusb/libusb20_desc.c
    trunk/lib/libusb/libusb20_desc.h
    trunk/lib/libusb/libusb20_int.h
    trunk/lib/libusb/libusb20_ugen20.c
    trunk/lib/libusb/usb.h

Added Paths:
-----------
    trunk/lib/libusb/libusb10_hotplug.c

Property Changed:
----------------
    trunk/lib/libusb/libusb.3
    trunk/lib/libusb/libusb20.3

Modified: trunk/lib/libusb/Makefile
===================================================================
--- trunk/lib/libusb/Makefile	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/Makefile	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,8 +1,9 @@
-#
 # $MidnightBSD$
 #
-# Makefile for the MidnightBSD specific LibUSB 2.0
+# $FreeBSD: stable/9/lib/libusb/Makefile 302276 2016-06-29 11:06:13Z hselasky $
 #
+# Makefile for the FreeBSD specific LibUSB 2.0
+#
 
 LIB=		usb
 SHLIB_MAJOR=	2
@@ -31,6 +32,7 @@
 INCS+=		libusb.h
 SRCS+=		libusb10.c
 SRCS+=		libusb10_desc.c
+SRCS+=		libusb10_hotplug.c
 SRCS+=		libusb10_io.c
 
 .if defined(COMPAT_32BIT)
@@ -40,6 +42,7 @@
 .include <bsd.lib.mk>
 
 # LibUSB v1.0
+MLINKS += libusb.3 libusb_get_version.3
 MLINKS += libusb.3 libusb_init.3
 MLINKS += libusb.3 libusb_exit.3
 MLINKS += libusb.3 libusb_strerror.3
@@ -48,6 +51,7 @@
 MLINKS += libusb.3 libusb_get_device_list.3
 MLINKS += libusb.3 libusb_free_device_list.3
 MLINKS += libusb.3 libusb_get_bus_number.3
+MLINKS += libusb.3 libusb_get_port_number.3
 MLINKS += libusb.3 libusb_get_device_address.3
 MLINKS += libusb.3 libusb_get_device_speed.3
 MLINKS += libusb.3 libusb_get_max_packet_size.3
@@ -72,18 +76,32 @@
 MLINKS += libusb.3 libusb_detach_kernel_driver.3
 MLINKS += libusb.3 libusb_detach_kernel_driver_np.3
 MLINKS += libusb.3 libusb_attach_kernel_driver.3
+MLINKS += libusb.3 libusb_set_auto_detach_kernel_driver.3
 MLINKS += libusb.3 libusb_get_device_descriptor.3
 MLINKS += libusb.3 libusb_get_active_config_descriptor.3
 MLINKS += libusb.3 libusb_get_config_descriptor.3
 MLINKS += libusb.3 libusb_get_config_descriptor_by_value.3
 MLINKS += libusb.3 libusb_free_config_descriptor.3
+MLINKS += libusb.3 libusb_get_string_descriptor.3
 MLINKS += libusb.3 libusb_get_string_descriptor_ascii.3
 MLINKS += libusb.3 libusb_parse_ss_endpoint_comp.3
 MLINKS += libusb.3 libusb_free_ss_endpoint_comp.3
+MLINKS += libusb.3 libusb_get_ss_endpoint_companion_descriptor.3
+MLINKS += libusb.3 libusb_free_ss_endpoint_companion_descriptor.3
 MLINKS += libusb.3 libusb_parse_bos_descriptor.3
 MLINKS += libusb.3 libusb_free_bos_descriptor.3
+MLINKS += libusb.3 libusb_get_usb_2_0_extension_descriptor.3
+MLINKS += libusb.3 libusb_free_usb_2_0_extension_descriptor.3
+MLINKS += libusb.3 libusb_get_ss_usb_device_capability_descriptor.3
+MLINKS += libusb.3 libusb_free_ss_usb_device_capability_descriptor.3
+MLINKS += libusb.3 libusb_get_container_id_descriptor.3
+MLINKS += libusb.3 libusb_free_container_id_descriptor.3
+MLINKS += libusb.3 libusb_alloc_streams.3
+MLINKS += libusb.3 libusb_free_streams.3
 MLINKS += libusb.3 libusb_alloc_transfer.3
 MLINKS += libusb.3 libusb_free_transfer.3
+MLINKS += libusb.3 libusb_transfer_set_stream_id.3
+MLINKS += libusb.3 libusb_transfer_get_stream_id.3
 MLINKS += libusb.3 libusb_submit_transfer.3
 MLINKS += libusb.3 libusb_cancel_transfer.3
 MLINKS += libusb.3 libusb_control_transfer.3
@@ -97,6 +115,8 @@
 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
@@ -103,6 +123,8 @@
 MLINKS += libusb.3 libusb_get_next_timeout.3
 MLINKS += libusb.3 libusb_set_pollfd_notifiers.3
 MLINKS += libusb.3 libusb_get_pollfds.3
+MLINKS += libusb.3 libusb_hotplug_register_callback.3
+MLINKS += libusb.3 libusb_hotplug_deregister_callback.3
 
 # LibUSB v0.1
 MLINKS += libusb.3 usb_open.3
@@ -189,6 +211,7 @@
 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

Modified: trunk/lib/libusb/libusb.3
===================================================================
--- trunk/lib/libusb/libusb.3	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb.3	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" Copyright (c) 2009 Sylvestre Gallon
 .\"
@@ -24,9 +25,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/9/lib/libusb/libusb.3 302276 2016-06-29 11:06:13Z hselasky $
 .\"
-.Dd April 12, 2012
+.Dd June 23, 2016
 .Dt LIBUSB 3
 .Os
 .Sh NAME
@@ -43,6 +44,10 @@
 library contains interfaces for directly managing a usb device.
 The current implementation supports v1.0 of the libusb API.
 .Sh LIBRARY INITIALISATION / DEINITIALISATION
+.Ft "const struct libusb_version *"
+.Fn libusb_get_version "void"
+This function returns version information about LibUSB.
+.Pp
 .Ft int
 .Fn libusb_init libusb_context **ctx
 This function initialises libusb.
@@ -103,6 +108,25 @@
 .Fa dev .
 .Pp
 .Ft uint8_t
+.Fn libusb_get_port_number "libusb_device *dev"
+Returns the port number which the device given by
+.Fa dev
+is attached to.
+.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
 .Fa dev .
@@ -275,6 +299,18 @@
 if the device has been disconnected, LIBUSB_ERROR_BUSY if the driver cannot be
 attached because the interface is claimed by a program or driver and a
 LIBUSB_ERROR code on failure.
+.Pp
+.Ft int
+.Fn libusb_set_auto_detach_kernel_driver "libusb_device_handle *devh" "int enable"
+This function enables automatic kernel interface driver detach when an
+interface is claimed.
+When the interface is restored the kernel driver is allowed to be re-attached.
+If the
+.Fa enable
+argument is non-zero the feature is enabled.
+Else disabled.
+Returns 0 on success and a LIBUSB_ERROR code on
+failure.
 .Sh USB DESCRIPTORS
 .Ft int
 .Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc"
@@ -314,6 +350,12 @@
 Free a configuration descriptor.
 .Pp
 .Ft int
+.Fn libusb_get_string_descriptor "libusb_device_handle *devh" "uint8_t desc_idx" "uint16_t langid" "unsigned char *data" "int length"
+Retrieve a string descriptor in raw format.
+Returns the number of bytes actually transferred on success
+or a negative LIBUSB_ERROR code on failure.
+.Pp
+.Ft int
 .Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length"
 Retrieve a string descriptor in C style ASCII.
 Returns the positive number of bytes in the resulting ASCII string
@@ -335,9 +377,33 @@
 .Pp
 .Ft void
 .Fn libusb_free_ss_endpoint_comp "libusb_ss_endpoint_companion_descriptor *ep_comp"
-This function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor.
+This function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor given by
+.Fa ep_comp .
 .Pp
 .Ft int
+.Fn libusb_get_ss_endpoint_companion_descriptor "struct libusb_context *ctx" "const struct libusb_endpoint_descriptor *endpoint" "struct libusb_ss_endpoint_companion_descriptor **ep_comp"
+This function finds and parses the USB 3.0 endpoint companion descriptor given by
+.Fa endpoint .
+Returns zero on success and a LIBUSB_ERROR code on failure.
+On success the parsed USB 3.0 endpoint companion descriptor must be
+freed using the libusb_free_ss_endpoint_companion_descriptor function.
+.Pp
+.Ft void
+.Fn libusb_free_ss_endpoint_companion_descriptor "struct libusb_ss_endpoint_companion_descriptor *ep_comp"
+This function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor given by
+.Fa ep_comp .
+.Pp
+.Ft int
+.Fn libusb_get_bos_descriptor "libusb_device_handle *handle" "struct libusb_bos_descriptor **bos"
+This function queries the USB device given by
+.Fa handle
+and stores a pointer to a parsed BOS descriptor into
+.Fa bos .
+Returns zero on success and a LIBUSB_ERROR code on failure.
+On success the parsed BOS descriptor must be
+freed using the libusb_free_bos_descriptor function.
+.Pp
+.Ft int
 .Fn libusb_parse_bos_descriptor "const void *buf" "int len" "libusb_bos_descriptor **bos"
 This function parses a Binary Object Store, BOS, descriptor into host endian format pointed to by
 .Fa buf
@@ -351,7 +417,53 @@
 .Pp
 .Ft void
 .Fn libusb_free_bos_descriptor "libusb_bos_descriptor *bos"
-This function is NULL safe and frees a parsed BOS descriptor.
+This function is NULL safe and frees a parsed BOS descriptor given by
+.Fa bos .
+.Pp
+.Ft int
+.Fn libusb_get_usb_2_0_extension_descriptor "struct libusb_context *ctx" "struct libusb_bos_dev_capability_descriptor *dev_cap" "struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension"
+This function parses the USB 2.0 extension descriptor from the descriptor given by
+.Fa dev_cap
+and stores a pointer to the parsed descriptor into
+.Fa usb_2_0_extension .
+Returns zero on success and a LIBUSB_ERROR code on failure.
+On success the parsed USB 2.0 extension descriptor must be freed using the
+libusb_free_usb_2_0_extension_descriptor function.
+.Pp
+.Ft void
+.Fn libusb_free_usb_2_0_extension_descriptor "struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension"
+This function is NULL safe and frees a parsed USB 2.0 extension descriptor given by
+.Fa usb_2_0_extension .
+.Pp
+.Ft int
+.Fn libusb_get_ss_usb_device_capability_descriptor "struct libusb_context *ctx" "struct libusb_bos_dev_capability_descriptor *dev_cap" "struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_capability"
+This function parses the SuperSpeed device capability descriptor from the descriptor given by
+.Fa dev_cap
+and stores a pointer to the parsed descriptor into
+.Fa ss_usb_device_capability .
+Returns zero on success and a LIBUSB_ERROR code on failure.
+On success the parsed SuperSpeed device capability descriptor must be freed using the
+libusb_free_ss_usb_device_capability_descriptor function.
+.Pp
+.Ft void
+.Fn libusb_free_ss_usb_device_capability_descriptor "struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_capability"
+This function is NULL safe and frees a parsed SuperSpeed device capability descriptor given by
+.Fa ss_usb_device_capability .
+.Pp
+.Ft int
+.Fn libusb_get_container_id_descriptor "struct libusb_context *ctx" "struct libusb_bos_dev_capability_descriptor *dev_cap" "struct libusb_container_id_descriptor **container_id"
+This function parses the container ID descriptor from the descriptor given by
+.Fa dev_cap
+and stores a pointer to the parsed descriptor into
+.Fa container_id .
+Returns zero on success and a LIBUSB_ERROR code on failure.
+On success the parsed container ID descriptor must be freed using the
+libusb_free_container_id_descriptor function.
+.Pp
+.Ft void
+.Fn libusb_free_container_id_descriptor "struct libusb_container_id_descriptor *container_id"
+This function is NULL safe and frees a parsed container ID descriptor given by
+.Fa container_id .
 .Sh USB ASYNCHRONOUS I/O
 .Ft struct libusb_transfer *
 .Fn libusb_alloc_transfer "int iso_packets"
@@ -410,6 +522,29 @@
 supported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
 LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
 a LIBUSB_ERROR code on other failure.
+.Sh USB STREAMS SUPPORT
+.Ft int
+.Fn libusb_alloc_streams "libusb_device_handle *dev" "uint32_t num_streams" "unsigned char *endpoints" "int num_endpoints"
+This function verifies that the given number of streams using the
+given number of endpoints is allowed and allocates the resources
+needed to use so-called USB streams.
+Currently only a single stream per endpoint is supported to simplify
+the internals of LibUSB.
+This function returns 0 on success or a LIBUSB_ERROR code on failure.
+.Pp
+.Ft int
+.Fn libusb_free_streams "libusb_device_handle *dev" "unsigned char *endpoints" "int num_endpoints"
+This function release resources needed for streams usage.
+Returns 0 on success or a LIBUSB_ERROR code on failure.
+.Pp
+.Ft void
+.Fn libusb_transfer_set_stream_id "struct libusb_transfer *transfer" "uint32_t stream_id"
+This function sets the stream ID for the given USB transfer.
+.Pp
+.Ft uint32_t
+.Fn libusb_transfer_get_stream_id "struct libusb_transfer *transfer"
+This function returns the stream ID for the given USB transfer.
+If no stream ID is used a value of zero is returned.
 .Sh USB EVENTS
 .Ft int
 .Fn libusb_try_lock_events "libusb_context *ctx"
@@ -466,11 +601,40 @@
 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"
@@ -489,7 +653,7 @@
 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"
@@ -502,6 +666,47 @@
 Retrive a list of file descriptors that should be polled by your main loop as
 libusb event sources.
 Returns a NULL-terminated list on success or NULL on failure.
+.Pp
+.Ft int
+.Fn libusb_hotplug_register_callback "libusb_context *ctx" "libusb_hotplug_event events" "libusb_hotplug_flag flags" "int vendor_id" "int product_id" "int dev_class" "libusb_hotplug_callback_fn cb_fn" "void *user_data" "libusb_hotplug_callback_handle *handle"
+This function registers a hotplug filter.
+The
+.Fa events
+argument select which events makes the hotplug filter trigger.
+Available event values are LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED and LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT.
+One or more events must be specified.
+The
+.Fa vendor_id ,
+.Fa product_id
+and
+.Fa dev_class
+arguments can be set to LIBUSB_HOTPLUG_MATCH_ANY to match any value in the USB device descriptor.
+Else the specified value is used for matching.
+If the
+.Fa flags
+argument is set to LIBUSB_HOTPLUG_ENUMERATE, all currently attached and matching USB devices will be passed to the hotplug filter, given by the
+.Fa cb_fn
+argument.
+Else the
+.Fa flags
+argument should be set to LIBUSB_HOTPLUG_NO_FLAGS.
+This function returns 0 upon success or a LIBUSB_ERROR code on failure.
+.Pp
+.Ft int
+.Fn libusb_hotplug_callback_fn "libusb_context *ctx" "libusb_device *device" "libusb_hotplug_event event" "void *user_data"
+The hotplug filter function.
+If this function returns non-zero, the filter is removed.
+Else the filter is kept and can receive more events.
+The
+.Fa user_data
+argument is the same as given when the filter was registered.
+The
+.Fa event
+argument can be either of LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED or LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT.
+.Pp
+.Ft void
+.Fn libusb_hotplug_deregister_callback "libusb_context *ctx" "libusb_hotplug_callback_handle handle"
+This function unregisters a hotplug filter.
 .Sh LIBUSB VERSION 0.1 COMPATIBILITY
 The library is also compliant with LibUSB version 0.1.12.
 .Pp


Property changes on: trunk/lib/libusb/libusb.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libusb/libusb.h
===================================================================
--- trunk/lib/libusb/libusb.h	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb.h	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb.h 302276 2016-06-29 11:06:13Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  *
@@ -30,6 +31,10 @@
 #include <sys/time.h>
 #include <sys/types.h>
 
+#define	LIBUSB_API_VERSION 0x01000102
+
+#define	LIBUSB_CALL
+
 #ifdef __cplusplus
 extern	"C" {
 #endif
@@ -46,10 +51,18 @@
 	LIBUSB_CLASS_COMM = 2,
 	LIBUSB_CLASS_HID = 3,
 	LIBUSB_CLASS_PTP = 6,
+	LIBUSB_CLASS_IMAGE = 6,
 	LIBUSB_CLASS_PRINTER = 7,
 	LIBUSB_CLASS_MASS_STORAGE = 8,
 	LIBUSB_CLASS_HUB = 9,
 	LIBUSB_CLASS_DATA = 10,
+	LIBUSB_CLASS_SMART_CARD = 11,
+	LIBUSB_CLASS_CONTENT_SECURITY = 13,
+	LIBUSB_CLASS_VIDEO = 14,
+	LIBUSB_CLASS_PERSONAL_HEALTHCARE = 15,
+	LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
+	LIBUSB_CLASS_WIRELESS = 0xe0,
+	LIBUSB_CLASS_APPLICATION = 0xfe,
 	LIBUSB_CLASS_VENDOR_SPEC = 0xff,
 };
 
@@ -86,6 +99,10 @@
 #define	LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE	7
 #define	LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE	10
 
+#define	LIBUSB_BT_USB_2_0_EXTENSION_SIZE	7
+#define	LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE	10
+#define	LIBUSB_BT_CONTAINER_ID_SIZE		20
+
 #define	LIBUSB_ENDPOINT_ADDRESS_MASK	0x0f
 #define	LIBUSB_ENDPOINT_DIR_MASK	0x80
 
@@ -115,6 +132,8 @@
 	LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
 	LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
 	LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
+	LIBUSB_REQUEST_SET_SEL = 0x30,
+	LIBUSB_REQUEST_SET_ISOCH_DELAY = 0x31,
 };
 
 enum libusb_request_type {
@@ -148,6 +167,13 @@
 	LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
 };
 
+enum libusb_bos_type {
+	LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,
+	LIBUSB_BT_USB_2_0_EXTENSION = 2,
+	LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3,
+	LIBUSB_BT_CONTAINER_ID = 4,
+};
+
 enum libusb_error {
 	LIBUSB_SUCCESS = 0,
 	LIBUSB_ERROR_IO = -1,
@@ -195,6 +221,18 @@
 	LIBUSB_DEBUG_TRANSFER=2,
 };
 
+#define	LIBUSB_HOTPLUG_MATCH_ANY -1
+
+typedef enum {
+	LIBUSB_HOTPLUG_NO_FLAGS = 0,
+	LIBUSB_HOTPLUG_ENUMERATE = 1 << 0,
+} libusb_hotplug_flag;
+
+typedef enum {
+	LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 1,
+	LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 2,
+} libusb_hotplug_event;
+
 /* libusb structures */
 
 struct libusb_context;
@@ -201,6 +239,7 @@
 struct libusb_device;
 struct libusb_transfer;
 struct libusb_device_handle;
+struct libusb_hotplug_callback_handle_struct;
 
 struct libusb_pollfd {
 	int	fd;
@@ -207,6 +246,15 @@
 	short	events;
 };
 
+struct libusb_version {
+	const uint16_t major;
+	const uint16_t minor;
+	const uint16_t micro;
+	const uint16_t nano;
+	const char *rc;
+	const char *describe;
+};
+
 typedef struct libusb_context libusb_context;
 typedef struct libusb_device libusb_device;
 typedef struct libusb_device_handle libusb_device_handle;
@@ -213,6 +261,7 @@
 typedef struct libusb_pollfd libusb_pollfd;
 typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data);
 typedef void (*libusb_pollfd_removed_cb) (int fd, void *user_data);
+typedef struct libusb_hotplug_callback_handle_struct *libusb_hotplug_callback_handle;
 
 typedef struct libusb_device_descriptor {
 	uint8_t	bLength;
@@ -310,6 +359,13 @@
 	uint16_t wU2DevExitLat;
 }	libusb_ss_usb_device_capability_descriptor __aligned(sizeof(void *));
 
+typedef struct libusb_bos_dev_capability_descriptor {
+	uint8_t bLength;
+	uint8_t bDescriptorType;
+	uint8_t bDevCapabilityType;
+	uint8_t dev_capability_data[0];
+}	libusb_bos_dev_capability_descriptor __aligned(sizeof(void *));
+
 typedef struct libusb_bos_descriptor {
 	uint8_t bLength;
 	uint8_t bDescriptorType;
@@ -319,6 +375,21 @@
 	struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap;
 }	libusb_bos_descriptor __aligned(sizeof(void *));
 
+typedef struct libusb_usb_2_0_extension_descriptor {
+	uint8_t bLength;
+	uint8_t bDescriptorType;
+	uint8_t bDevCapabilityType;
+	uint32_t bmAttributes;
+}	libusb_usb_2_0_extension_descriptor __aligned(sizeof(void *));
+
+typedef struct libusb_container_id_descriptor {
+	uint8_t bLength;
+	uint8_t bDescriptorType;
+	uint8_t bDevCapabilityType;
+	uint8_t	bReserved;
+	uint8_t ContainerID[16];
+}	libusb_container_id_descriptor __aligned(sizeof(void *));
+
 typedef struct libusb_control_setup {
 	uint8_t	bmRequestType;
 	uint8_t	bRequest;
@@ -357,6 +428,7 @@
 /* Library initialisation */
 
 void	libusb_set_debug(libusb_context * ctx, int level);
+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);
@@ -367,6 +439,9 @@
 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);
+uint8_t	libusb_get_port_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);
@@ -390,6 +465,7 @@
 int 	libusb_detach_kernel_driver_np(libusb_device_handle * devh, int interface);
 int 	libusb_detach_kernel_driver(libusb_device_handle * devh, int interface);
 int 	libusb_attach_kernel_driver(libusb_device_handle * devh, int interface);
+int	libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev, int enable);
 int	libusb_set_interface_alt_setting(libusb_device_handle * devh, int interface_number, int alternate_setting);
 
 /* USB Descriptors */
@@ -399,6 +475,9 @@
 int	libusb_get_config_descriptor(libusb_device * dev, uint8_t config_index, struct libusb_config_descriptor **config);
 int	libusb_get_config_descriptor_by_value(libusb_device * dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
 void	libusb_free_config_descriptor(struct libusb_config_descriptor *config);
+int	libusb_get_ss_endpoint_companion_descriptor(struct libusb_context *ctx, const struct libusb_endpoint_descriptor *endpoint, struct libusb_ss_endpoint_companion_descriptor **ep_comp);
+void	libusb_free_ss_endpoint_companion_descriptor(struct libusb_ss_endpoint_companion_descriptor *ep_comp);
+int	libusb_get_string_descriptor(libusb_device_handle * devh, uint8_t desc_index, uint16_t langid, unsigned char *data, int length);
 int	libusb_get_string_descriptor_ascii(libusb_device_handle * devh, uint8_t desc_index, uint8_t *data, int length);
 int	libusb_get_descriptor(libusb_device_handle * devh, uint8_t desc_type, uint8_t desc_index, uint8_t *data, int length);
 int	libusb_parse_ss_endpoint_comp(const void *buf, int len, struct libusb_ss_endpoint_companion_descriptor **ep_comp);
@@ -405,6 +484,13 @@
 void	libusb_free_ss_endpoint_comp(struct libusb_ss_endpoint_companion_descriptor *ep_comp);
 int	libusb_parse_bos_descriptor(const void *buf, int len, struct libusb_bos_descriptor **bos);
 void	libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
+int	libusb_get_bos_descriptor(libusb_device_handle *handle, struct libusb_bos_descriptor **bos);
+int	libusb_get_usb_2_0_extension_descriptor(struct libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension);
+void	libusb_free_usb_2_0_extension_descriptor(struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension);
+int	libusb_get_ss_usb_device_capability_descriptor(struct libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_capability);
+void	libusb_free_ss_usb_device_capability_descriptor(struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_capability);
+int	libusb_get_container_id_descriptor(struct libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_container_id_descriptor **container_id);
+void	libusb_free_container_id_descriptor(struct libusb_container_id_descriptor *container_id);
 
 /* Asynchronous device I/O */
 
@@ -433,12 +519,14 @@
 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 */
 
@@ -451,6 +539,21 @@
 uint16_t libusb_cpu_to_le16(uint16_t x);
 uint16_t libusb_le16_to_cpu(uint16_t x);
 
+/* Hotplug support */
+
+typedef int (*libusb_hotplug_callback_fn)(libusb_context *ctx,
+    libusb_device *device, libusb_hotplug_event event, void *user_data);
+
+int	libusb_hotplug_register_callback(libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class, libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *handle);
+void	libusb_hotplug_deregister_callback(libusb_context *ctx, libusb_hotplug_callback_handle handle);
+
+/* Streams support */
+
+int	libusb_alloc_streams(libusb_device_handle *dev, uint32_t num_streams, unsigned char *endpoints, int num_endpoints);
+int	libusb_free_streams(libusb_device_handle *dev, unsigned char *endpoints, int num_endpoints);
+void	libusb_transfer_set_stream_id(struct libusb_transfer *transfer, uint32_t stream_id);
+uint32_t libusb_transfer_get_stream_id(struct libusb_transfer *transfer);
+
 #if 0
 {					/* indent fix */
 #endif

Modified: trunk/lib/libusb/libusb01.c
===================================================================
--- trunk/lib/libusb/libusb01.c	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb01.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb01.c 264637 2014-04-18 07:42:47Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -122,6 +123,8 @@
 		bufsize = 256;
 	} else if (speed == LIBUSB20_SPEED_FULL) {
 		bufsize = 4096;
+	} else if (speed == LIBUSB20_SPEED_SUPER) {
+		bufsize = 65536;
 	} else {
 		bufsize = 16384;
 	}

Modified: trunk/lib/libusb/libusb10.c
===================================================================
--- trunk/lib/libusb/libusb10.c	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb10.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb10.c 302276 2016-06-29 11:06:13Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  * Copyright (c) 2009 Hans Petter Selasky. All rights reserved.
@@ -45,6 +46,8 @@
 #include "libusb.h"
 #include "libusb10.h"
 
+#define	LIBUSB_NUM_SW_ENDPOINTS	(16 * 4)
+
 static pthread_mutex_t default_context_lock = PTHREAD_MUTEX_INITIALIZER;
 struct libusb_context *usbi_default_context = NULL;
 
@@ -61,6 +64,22 @@
 
 /*  Library initialisation / deinitialisation */
 
+static const struct libusb_version libusb_version = {
+	.major = 1,
+	.minor = 0,
+	.micro = 0,
+	.nano = 2016,
+	.rc = "",
+	.describe = "http://www.midnightbsd.org"
+};
+
+const struct libusb_version *
+libusb_get_version(void)
+{
+
+	return (&libusb_version);
+}
+
 void
 libusb_set_debug(libusb_context *ctx, int level)
 {
@@ -110,18 +129,27 @@
 	}
 	TAILQ_INIT(&ctx->pollfds);
 	TAILQ_INIT(&ctx->tr_done);
+	TAILQ_INIT(&ctx->hotplug_cbh);
+	TAILQ_INIT(&ctx->hotplug_devs);
 
 	if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) {
 		free(ctx);
 		return (LIBUSB_ERROR_NO_MEM);
 	}
+	if (pthread_mutex_init(&ctx->hotplug_lock, NULL) != 0) {
+		pthread_mutex_destroy(&ctx->ctx_lock);
+		free(ctx);
+		return (LIBUSB_ERROR_NO_MEM);
+	}
 	if (pthread_condattr_init(&attr) != 0) {
 		pthread_mutex_destroy(&ctx->ctx_lock);
+		pthread_mutex_destroy(&ctx->hotplug_lock);
 		free(ctx);
 		return (LIBUSB_ERROR_NO_MEM);
 	}
 	if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) != 0) {
 		pthread_mutex_destroy(&ctx->ctx_lock);
+		pthread_mutex_destroy(&ctx->hotplug_lock);
 		pthread_condattr_destroy(&attr);
 		free(ctx);
 		return (LIBUSB_ERROR_OTHER);
@@ -128,6 +156,7 @@
 	}
 	if (pthread_cond_init(&ctx->ctx_cond, &attr) != 0) {
 		pthread_mutex_destroy(&ctx->ctx_lock);
+		pthread_mutex_destroy(&ctx->hotplug_lock);
 		pthread_condattr_destroy(&attr);
 		free(ctx);
 		return (LIBUSB_ERROR_NO_MEM);
@@ -135,10 +164,12 @@
 	pthread_condattr_destroy(&attr);
 
 	ctx->ctx_handler = NO_THREAD;
+	ctx->hotplug_handler = NO_THREAD;
 
 	ret = pipe(ctx->ctrl_pipe);
 	if (ret < 0) {
 		pthread_mutex_destroy(&ctx->ctx_lock);
+		pthread_mutex_destroy(&ctx->hotplug_lock);
 		pthread_cond_destroy(&ctx->ctx_cond);
 		free(ctx);
 		return (LIBUSB_ERROR_OTHER);
@@ -171,6 +202,20 @@
 	if (ctx == NULL)
 		return;
 
+	/* stop hotplug thread, if any */
+
+	if (ctx->hotplug_handler != NO_THREAD) {
+		pthread_t td;
+		void *ptr;
+
+		HOTPLUG_LOCK(ctx);
+		td = ctx->hotplug_handler;
+		ctx->hotplug_handler = NO_THREAD;
+		HOTPLUG_UNLOCK(ctx);
+
+		pthread_join(td, &ptr);
+	}
+
 	/* XXX cleanup devices */
 
 	libusb10_remove_pollfd(ctx, &ctx->ctx_poll);
@@ -177,6 +222,7 @@
 	close(ctx->ctrl_pipe[0]);
 	close(ctx->ctrl_pipe[1]);
 	pthread_mutex_destroy(&ctx->ctx_lock);
+	pthread_mutex_destroy(&ctx->hotplug_lock);
 	pthread_cond_destroy(&ctx->ctx_cond);
 
 	pthread_mutex_lock(&default_context_lock);
@@ -285,6 +331,27 @@
 }
 
 uint8_t
+libusb_get_port_number(libusb_device *dev)
+{
+	if (dev == NULL)
+		return (0);		/* should not happen */
+	return (libusb20_dev_get_parent_port(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)
 {
 	if (dev == NULL)
@@ -423,7 +490,7 @@
 	if (dev == NULL)
 		return (LIBUSB_ERROR_INVALID_PARAM);
 
-	err = libusb20_dev_open(pdev, 16 * 4 /* number of endpoints */ );
+	err = libusb20_dev_open(pdev, LIBUSB_NUM_SW_ENDPOINTS);
 	if (err) {
 		libusb_unref_device(dev);
 		return (LIBUSB_ERROR_NO_MEM);
@@ -601,13 +668,16 @@
 	if (interface_number < 0 || interface_number > 31)
 		return (LIBUSB_ERROR_INVALID_PARAM);
 
+	if (pdev->auto_detach != 0) {
+		err = libusb_detach_kernel_driver(pdev, interface_number);
+		if (err != 0)
+			goto done;
+	}
+
 	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);
+done:
 	return (err);
 }
 
@@ -624,13 +694,19 @@
 	if (interface_number < 0 || interface_number > 31)
 		return (LIBUSB_ERROR_INVALID_PARAM);
 
+	if (pdev->auto_detach != 0) {
+		err = libusb_attach_kernel_driver(pdev, interface_number);
+		if (err != 0)
+			goto done;
+	}
+
 	CTX_LOCK(dev->ctx);
 	if (!(dev->claimed_interfaces & (1 << interface_number)))
 		err = LIBUSB_ERROR_NOT_FOUND;
-
-	if (!err)
+	else
 		dev->claimed_interfaces &= ~(1 << interface_number);
 	CTX_UNLOCK(dev->ctx);
+done:
 	return (err);
 }
 
@@ -832,6 +908,13 @@
 	return (0);
 }
 
+int
+libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev, int enable)
+{
+	dev->auto_detach = (enable ? 1 : 0);
+	return (0);
+}
+
 /* Asynchronous device I/O */
 
 struct libusb_transfer *
@@ -920,6 +1003,9 @@
 		case LIBUSB20_SPEED_FULL:
 			ret = 4096;
 			break;
+		case LIBUSB20_SPEED_SUPER:
+			ret = 65536;
+			break;
 		default:
 			ret = 16384;
 			break;
@@ -1477,7 +1563,17 @@
 UNEXPORTED void
 libusb10_cancel_all_transfer(libusb_device *dev)
 {
-	/* TODO */
+	struct libusb20_device *pdev = dev->os_priv;
+	unsigned x;
+
+	for (x = 0; x != LIBUSB_NUM_SW_ENDPOINTS; x++) {
+		struct libusb20_transfer *xfer;
+
+		xfer = libusb20_tr_get_pointer(pdev, x);
+		if (xfer == NULL)
+			continue;
+		libusb20_tr_close(xfer);
+	}
 }
 
 uint16_t

Modified: trunk/lib/libusb/libusb10.h
===================================================================
--- trunk/lib/libusb/libusb10.h	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb10.h	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb10.h 302276 2016-06-29 11:06:13Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  *
@@ -34,6 +35,8 @@
 #define	CTX_LOCK(ctx) pthread_mutex_lock(&(ctx)->ctx_lock)
 #define	CTX_TRYLOCK(ctx) pthread_mutex_trylock(&(ctx)->ctx_lock)
 #define	CTX_UNLOCK(ctx) pthread_mutex_unlock(&(ctx)->ctx_lock)
+#define	HOTPLUG_LOCK(ctx) pthread_mutex_lock(&(ctx)->hotplug_lock)
+#define	HOTPLUG_UNLOCK(ctx) pthread_mutex_unlock(&(ctx)->hotplug_lock)
 
 #define	DPRINTF(ctx, dbg, format, args...) do {	\
     if ((ctx)->debug == dbg) {			\
@@ -65,11 +68,22 @@
 	uint8_t *curr_data;
 	uint32_t rem_len;
 	uint32_t last_len;
+	uint32_t stream_id;
 	uint8_t	state;
 #define	LIBUSB_SUPER_XFER_ST_NONE 0
 #define	LIBUSB_SUPER_XFER_ST_PEND 1
 };
 
+struct libusb_hotplug_callback_handle_struct {
+	TAILQ_ENTRY(libusb_hotplug_callback_handle_struct) entry;
+	int events;
+	int vendor;
+	int product;
+	int devclass;
+	libusb_hotplug_callback_fn fn;
+	void *user_data;
+};
+
 struct libusb_context {
 	int	debug;
 	int	debug_fixed;
@@ -78,12 +92,16 @@
 	int	tr_done_gen;
 
 	pthread_mutex_t ctx_lock;
+  	pthread_mutex_t hotplug_lock;
 	pthread_cond_t ctx_cond;
+	pthread_t hotplug_handler;
 	pthread_t ctx_handler;
 #define	NO_THREAD ((pthread_t)-1)
 
 	TAILQ_HEAD(, libusb_super_pollfd) pollfds;
 	TAILQ_HEAD(, libusb_super_transfer) tr_done;
+	TAILQ_HEAD(, libusb_hotplug_callback_handle_struct) hotplug_cbh;
+  	TAILQ_HEAD(, libusb_device) hotplug_devs;
 
 	struct libusb_super_pollfd ctx_poll;
 
@@ -101,6 +119,8 @@
 
 	struct libusb_context *ctx;
 
+	TAILQ_ENTRY(libusb_device) hotplug_entry;
+
 	TAILQ_HEAD(, libusb_super_transfer) tr_head;
 
 	struct libusb20_device *os_priv;

Modified: trunk/lib/libusb/libusb10_desc.c
===================================================================
--- trunk/lib/libusb/libusb10_desc.c	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb10_desc.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb10_desc.c 302276 2016-06-29 11:06:13Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  *
@@ -294,6 +295,25 @@
 }
 
 int
+libusb_get_string_descriptor(libusb_device_handle *pdev,
+    uint8_t desc_index, uint16_t langid, unsigned char *data,
+    int length)
+{
+	if (pdev == NULL || data == NULL || length < 1)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+
+	if (length > 65535)
+		length = 65535;
+
+	/* put some default data into the destination buffer */
+	data[0] = 0;
+
+	return (libusb_control_transfer(pdev, LIBUSB_ENDPOINT_IN,
+	    LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc_index,
+	    langid, data, length, 1000));
+}
+
+int
 libusb_get_string_descriptor_ascii(libusb_device_handle *pdev,
     uint8_t desc_index, unsigned char *data, int length)
 {
@@ -386,6 +406,23 @@
 }
 
 int
+libusb_get_ss_endpoint_companion_descriptor(struct libusb_context *ctx,
+    const struct libusb_endpoint_descriptor *endpoint,
+    struct libusb_ss_endpoint_companion_descriptor **ep_comp)
+{
+	if (endpoint == NULL)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+	return (libusb_parse_ss_endpoint_comp(endpoint->extra, endpoint->extra_length, ep_comp));
+}
+
+void
+libusb_free_ss_endpoint_companion_descriptor(struct libusb_ss_endpoint_companion_descriptor *ep_comp)
+{
+
+	libusb_free_ss_endpoint_comp(ep_comp);
+}
+
+int
 libusb_parse_bos_descriptor(const void *buf, int len,
     struct libusb_bos_descriptor **bos)
 {
@@ -496,3 +533,154 @@
 
 	free(bos);
 }
+
+int
+libusb_get_bos_descriptor(libusb_device_handle *handle,
+    struct libusb_bos_descriptor **bos)
+{
+	uint8_t bos_header[LIBUSB_DT_BOS_SIZE] = {0};
+	uint16_t wTotalLength;
+	uint8_t *bos_data;
+	int err;
+
+	err = libusb_get_descriptor(handle, LIBUSB_DT_BOS, 0,
+	    bos_header, sizeof(bos_header));
+	if (err < 0)
+		return (err);
+
+	wTotalLength = bos_header[2] | (bos_header[3] << 8);
+	if (wTotalLength < LIBUSB_DT_BOS_SIZE)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+
+	bos_data = calloc(wTotalLength, 1);
+	if (bos_data == NULL)
+		return (LIBUSB_ERROR_NO_MEM);
+
+	err = libusb_get_descriptor(handle, LIBUSB_DT_BOS, 0,
+	    bos_data, wTotalLength);
+	if (err < 0)
+		goto done;
+
+	/* avoid descriptor length mismatches */
+	bos_data[2] = (wTotalLength & 0xFF);
+	bos_data[3] = (wTotalLength >> 8);
+
+	err = libusb_parse_bos_descriptor(bos_data, wTotalLength, bos);
+done:
+	free(bos_data);
+	return (err);
+}
+
+int
+libusb_get_usb_2_0_extension_descriptor(struct libusb_context *ctx,
+    struct libusb_bos_dev_capability_descriptor *dev_cap,
+    struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension)
+{
+	struct libusb_usb_2_0_extension_descriptor *desc;
+
+	if (dev_cap == NULL || usb_2_0_extension == NULL ||
+	    dev_cap->bDevCapabilityType != LIBUSB_BT_USB_2_0_EXTENSION)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+	if (dev_cap->bLength < LIBUSB_BT_USB_2_0_EXTENSION_SIZE)
+		return (LIBUSB_ERROR_IO);
+
+	desc = malloc(sizeof(*desc));
+	if (desc == NULL)
+		return (LIBUSB_ERROR_NO_MEM);
+
+	desc->bLength = LIBUSB_BT_USB_2_0_EXTENSION_SIZE;
+	desc->bDescriptorType = dev_cap->bDescriptorType;
+	desc->bDevCapabilityType = dev_cap->bDevCapabilityType;
+	desc->bmAttributes =
+	    (dev_cap->dev_capability_data[0]) |
+	    (dev_cap->dev_capability_data[1] << 8) |
+	    (dev_cap->dev_capability_data[2] << 16) |
+	    (dev_cap->dev_capability_data[3] << 24);
+
+	*usb_2_0_extension = desc;
+	return (0);
+}
+
+void
+libusb_free_usb_2_0_extension_descriptor(
+    struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension)
+{
+
+	free(usb_2_0_extension);
+}
+
+int
+libusb_get_ss_usb_device_capability_descriptor(struct libusb_context *ctx,
+    struct libusb_bos_dev_capability_descriptor *dev_cap,
+    struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_capability)
+{
+	struct libusb_ss_usb_device_capability_descriptor *desc;
+
+	if (dev_cap == NULL || ss_usb_device_capability == NULL ||
+	    dev_cap->bDevCapabilityType != LIBUSB_BT_SS_USB_DEVICE_CAPABILITY)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+	if (dev_cap->bLength < LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE)
+		return (LIBUSB_ERROR_IO);
+
+	desc = malloc(sizeof(*desc));
+	if (desc == NULL)
+		return (LIBUSB_ERROR_NO_MEM);
+
+	desc->bLength = LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE;
+	desc->bDescriptorType = dev_cap->bDescriptorType;
+	desc->bDevCapabilityType = dev_cap->bDevCapabilityType;
+	desc->bmAttributes = dev_cap->dev_capability_data[0];
+	desc->wSpeedSupported = dev_cap->dev_capability_data[1] |
+	    (dev_cap->dev_capability_data[2] << 8);
+	desc->bFunctionalitySupport = dev_cap->dev_capability_data[3];
+	desc->bU1DevExitLat = dev_cap->dev_capability_data[4];
+	desc->wU2DevExitLat = dev_cap->dev_capability_data[5] |
+	    (dev_cap->dev_capability_data[6] << 8);
+
+	*ss_usb_device_capability = desc;
+	return (0);
+}
+
+void
+libusb_free_ss_usb_device_capability_descriptor(
+    struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_capability)
+{
+
+	free(ss_usb_device_capability);
+}
+
+int
+libusb_get_container_id_descriptor(struct libusb_context *ctx,
+    struct libusb_bos_dev_capability_descriptor *dev_cap,
+    struct libusb_container_id_descriptor **container_id)
+{
+	struct libusb_container_id_descriptor *desc;
+
+	if (dev_cap == NULL || container_id == NULL ||
+	    dev_cap->bDevCapabilityType != LIBUSB_BT_CONTAINER_ID)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+	if (dev_cap->bLength < LIBUSB_BT_CONTAINER_ID_SIZE)
+		return (LIBUSB_ERROR_IO);
+
+	desc = malloc(sizeof(*desc));
+	if (desc == NULL)
+		return (LIBUSB_ERROR_NO_MEM);
+
+	desc->bLength = LIBUSB_BT_CONTAINER_ID_SIZE;
+	desc->bDescriptorType = dev_cap->bDescriptorType;
+	desc->bDevCapabilityType = dev_cap->bDevCapabilityType;
+	desc->bReserved = dev_cap->dev_capability_data[0];
+	memcpy(desc->ContainerID, dev_cap->dev_capability_data + 1,
+	    sizeof(desc->ContainerID));
+
+	*container_id = desc;
+	return (0);
+}
+
+void
+libusb_free_container_id_descriptor(
+    struct libusb_container_id_descriptor *container_id)
+{
+
+	free(container_id);
+}

Added: trunk/lib/libusb/libusb10_hotplug.c
===================================================================
--- trunk/lib/libusb/libusb10_hotplug.c	                        (rev 0)
+++ trunk/lib/libusb/libusb10_hotplug.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -0,0 +1,238 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb10_hotplug.c 302276 2016-06-29 11:06:13Z hselasky $ */
+/*-
+ * Copyright (c) 2016 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.
+ */
+
+#ifdef LIBUSB_GLOBAL_INCLUDE_FILE
+#include LIBUSB_GLOBAL_INCLUDE_FILE
+#else
+#include <assert.h>
+#include <errno.h>
+#include <poll.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/queue.h>
+#include <sys/endian.h>
+#endif
+
+#define	libusb_device_handle libusb20_device
+
+#include "libusb20.h"
+#include "libusb20_desc.h"
+#include "libusb20_int.h"
+#include "libusb.h"
+#include "libusb10.h"
+
+static int
+libusb_hotplug_equal(libusb_device *_adev, libusb_device *_bdev)
+{
+	struct libusb20_device *adev = _adev->os_priv;
+	struct libusb20_device *bdev = _bdev->os_priv;
+
+	if (adev->bus_number != bdev->bus_number)
+		return (0);
+	if (adev->device_address != bdev->device_address)
+		return (0);
+	if (memcmp(&adev->ddesc, &bdev->ddesc, sizeof(adev->ddesc)))
+		return (0);
+	if (memcmp(&adev->session_data, &bdev->session_data, sizeof(adev->session_data)))
+		return (0);
+	return (1);
+}
+
+static int
+libusb_hotplug_filter(libusb_context *ctx, libusb_hotplug_callback_handle pcbh,
+    libusb_device *dev, libusb_hotplug_event event)
+{
+	if (!(pcbh->events & event))
+		return (0);
+	if (pcbh->vendor != LIBUSB_HOTPLUG_MATCH_ANY &&
+	    pcbh->vendor != libusb20_dev_get_device_desc(dev->os_priv)->idVendor)
+		return (0);
+	if (pcbh->product != LIBUSB_HOTPLUG_MATCH_ANY &&
+	    pcbh->product != libusb20_dev_get_device_desc(dev->os_priv)->idProduct)
+		return (0);
+	if (pcbh->devclass != LIBUSB_HOTPLUG_MATCH_ANY &&
+	    pcbh->devclass != libusb20_dev_get_device_desc(dev->os_priv)->bDeviceClass)
+		return (0);
+	return (pcbh->fn(ctx, dev, event, pcbh->user_data));
+}
+
+static void *
+libusb_hotplug_scan(void *arg)
+{
+	TAILQ_HEAD(, libusb_device) hotplug_devs;
+	libusb_hotplug_callback_handle acbh;
+	libusb_hotplug_callback_handle bcbh;
+	libusb_context *ctx = arg;
+	libusb_device **ppdev;
+	libusb_device *temp;
+	libusb_device *adev;
+	libusb_device *bdev;
+	unsigned do_loop = 1;
+	ssize_t count;
+	ssize_t x;
+
+	while (do_loop) {
+		usleep(4000000);
+
+		HOTPLUG_LOCK(ctx);
+
+		TAILQ_INIT(&hotplug_devs);
+
+		if (ctx->hotplug_handler != NO_THREAD) {
+			count = libusb_get_device_list(ctx, &ppdev);
+			if (count < 0)
+				continue;
+			for (x = 0; x != count; x++) {
+				TAILQ_INSERT_TAIL(&hotplug_devs, ppdev[x],
+				    hotplug_entry);
+			}
+			libusb_free_device_list(ppdev, 0);
+		} else {
+			do_loop = 0;
+		}
+
+		/* figure out which devices are gone */
+		TAILQ_FOREACH_SAFE(adev, &ctx->hotplug_devs, hotplug_entry, temp) {
+			TAILQ_FOREACH(bdev, &hotplug_devs, hotplug_entry) {
+				if (libusb_hotplug_equal(adev, bdev))
+					break;
+			}
+			if (bdev == NULL) {
+				TAILQ_REMOVE(&ctx->hotplug_devs, adev, hotplug_entry);
+				TAILQ_FOREACH_SAFE(acbh, &ctx->hotplug_cbh, entry, bcbh) {
+					if (libusb_hotplug_filter(ctx, acbh, adev,
+					    LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT) == 0)
+						continue;
+					TAILQ_REMOVE(&ctx->hotplug_cbh, acbh, entry);
+					free(acbh);
+				}
+				libusb_unref_device(adev);
+			}
+		}
+
+		/* figure out which devices are new */
+		TAILQ_FOREACH_SAFE(adev, &hotplug_devs, hotplug_entry, temp) {
+			TAILQ_FOREACH(bdev, &ctx->hotplug_devs, hotplug_entry) {
+				if (libusb_hotplug_equal(adev, bdev))
+					break;
+			}
+			if (bdev == NULL) {
+				TAILQ_REMOVE(&hotplug_devs, adev, hotplug_entry);
+				TAILQ_INSERT_TAIL(&ctx->hotplug_devs, adev, hotplug_entry);
+				TAILQ_FOREACH_SAFE(acbh, &ctx->hotplug_cbh, entry, bcbh) {
+					if (libusb_hotplug_filter(ctx, acbh, adev,
+					    LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) == 0)
+						continue;
+					TAILQ_REMOVE(&ctx->hotplug_cbh, acbh, entry);
+					free(acbh);
+				}
+			}
+		}
+		HOTPLUG_UNLOCK(ctx);
+
+		/* unref remaining devices */
+		while ((adev = TAILQ_FIRST(&hotplug_devs)) != NULL) {
+			TAILQ_REMOVE(&hotplug_devs, adev, hotplug_entry);
+			libusb_unref_device(adev);
+		}
+	}
+	return (NULL);
+}
+
+int libusb_hotplug_register_callback(libusb_context *ctx,
+    libusb_hotplug_event events, libusb_hotplug_flag flags,
+    int vendor_id, int product_id, int dev_class,
+    libusb_hotplug_callback_fn cb_fn, void *user_data,
+    libusb_hotplug_callback_handle *phandle)
+{
+	libusb_hotplug_callback_handle handle;
+	struct libusb_device *adev;
+
+	ctx = GET_CONTEXT(ctx);
+
+	if (ctx == NULL || cb_fn == NULL || events == 0 ||
+	    vendor_id < -1 || vendor_id > 0xffff ||
+	    product_id < -1 || product_id > 0xffff ||
+	    dev_class < -1 || dev_class > 0xff)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+
+	handle = malloc(sizeof(*handle));
+	if (handle == NULL)
+		return (LIBUSB_ERROR_NO_MEM);
+
+	HOTPLUG_LOCK(ctx);
+	if (ctx->hotplug_handler == NO_THREAD) {
+		if (pthread_create(&ctx->hotplug_handler, NULL,
+		    &libusb_hotplug_scan, ctx) != 0)
+			ctx->hotplug_handler = NO_THREAD;
+	}
+	handle->events = events;
+	handle->vendor = vendor_id;
+	handle->product = product_id;
+	handle->devclass = dev_class;
+	handle->fn = cb_fn;
+	handle->user_data = user_data;
+
+	if (flags & LIBUSB_HOTPLUG_ENUMERATE) {
+		TAILQ_FOREACH(adev, &ctx->hotplug_devs, hotplug_entry) {
+			if (libusb_hotplug_filter(ctx, handle, adev,
+			    LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) == 0)
+				continue;
+			free(handle);
+			handle = NULL;
+			break;
+		}
+	}
+	if (handle != NULL)
+		TAILQ_INSERT_TAIL(&ctx->hotplug_cbh, handle, entry);
+	HOTPLUG_UNLOCK(ctx);
+
+	if (phandle != NULL)
+		*phandle = handle;
+	return (LIBUSB_SUCCESS);
+}
+
+void libusb_hotplug_deregister_callback(libusb_context *ctx,
+    libusb_hotplug_callback_handle handle)
+{
+  	ctx = GET_CONTEXT(ctx);
+
+	if (ctx == NULL || handle == NULL)
+		return;
+
+	HOTPLUG_LOCK(ctx);
+	TAILQ_REMOVE(&ctx->hotplug_cbh, handle, entry);
+	HOTPLUG_UNLOCK(ctx);
+
+	free(handle);
+}


Property changes on: trunk/lib/libusb/libusb10_hotplug.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/lib/libusb/libusb10_io.c
===================================================================
--- trunk/lib/libusb/libusb10_io.c	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb10_io.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb10_io.c 302276 2016-06-29 11:06:13Z hselasky $ */
 /*-
  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
  *
@@ -331,29 +332,50 @@
 }
 
 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 +388,9 @@
 	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 +415,7 @@
 	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 +441,7 @@
 
 done:
 	CTX_UNLOCK(ctx);
-	return (ret);
+	return ((const struct libusb_pollfd **)ret);
 }
 
 
@@ -740,3 +763,47 @@
 	transfer->callback = callback;
 }
 
+int
+libusb_alloc_streams(libusb_device_handle *dev, uint32_t num_streams,
+    unsigned char *endpoints, int num_endpoints)
+{
+
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+int
+libusb_free_streams(libusb_device_handle *dev, unsigned char *endpoints, int num_endpoints)
+{
+
+	return (0);
+}
+
+void
+libusb_transfer_set_stream_id(struct libusb_transfer *transfer, uint32_t stream_id)
+{
+	struct libusb_super_transfer *sxfer;
+
+	if (transfer == NULL)
+		return;
+
+	sxfer = (struct libusb_super_transfer *)(
+	    ((uint8_t *)transfer) - sizeof(*sxfer));
+
+	/* set stream ID */
+	sxfer->stream_id = stream_id;
+}
+
+uint32_t
+libusb_transfer_get_stream_id(struct libusb_transfer *transfer)
+{
+	struct libusb_super_transfer *sxfer;
+
+	if (transfer == NULL)
+		return (0);
+
+	sxfer = (struct libusb_super_transfer *)(
+	    ((uint8_t *)transfer) - sizeof(*sxfer));
+
+	/* get stream ID */
+	return (sxfer->stream_id);
+}

Modified: trunk/lib/libusb/libusb20.3
===================================================================
--- trunk/lib/libusb/libusb20.3	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb20.3	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" Copyright (c) 2008 Hans Petter Selasky
 .\"
@@ -24,9 +25,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD$
 .\"
-.Dd February 14, 2013
+.Dd May 3, 2013
 .Dt LIBUSB20 3
 .Os
 .Sh NAME
@@ -113,6 +114,8 @@
 .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"
@@ -541,6 +544,20 @@
 .
 .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 .


Property changes on: trunk/lib/libusb/libusb20.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libusb/libusb20.c
===================================================================
--- trunk/lib/libusb/libusb20.c	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb20.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
-/* $FreeBSD: release/9.2.0/lib/libusb/libusb20.c 247475 2013-02-28 16:56:08Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb20.c 305642 2016-09-09 06:31:25Z hselasky $ */
 /*-
  * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved.
  *
@@ -71,6 +72,7 @@
 #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
@@ -164,6 +166,12 @@
 		return (LIBUSB20_ERROR_BUSY);
 	if (MaxFrameCount & LIBUSB20_MAX_FRAME_PRE_SCALE) {
 		MaxFrameCount &= ~LIBUSB20_MAX_FRAME_PRE_SCALE;
+		/*
+		 * The kernel can setup 8 times more frames when
+		 * pre-scaling ISOCHRONOUS transfers. Make sure the
+		 * length and pointer buffers are big enough:
+		 */
+		MaxFrameCount *= 8;
 		pre_scale = 1;
 	} else {
 		pre_scale = 0;
@@ -188,8 +196,13 @@
 	}
 	memset(xfer->ppBuffer, 0, size);
 
-	error = xfer->pdev->methods->tr_open(xfer, MaxBufSize,
-	    MaxFrameCount, ep_no, pre_scale);
+	if (pre_scale) {
+		error = xfer->pdev->methods->tr_open(xfer, MaxBufSize,
+		    MaxFrameCount / 8, ep_no, 1);
+	} else {
+		error = xfer->pdev->methods->tr_open(xfer, MaxBufSize,
+		    MaxFrameCount, ep_no, 0);
+	}
 
 	if (error) {
 		free(xfer->ppBuffer);
@@ -589,6 +602,12 @@
 	 */
 	pdev->claimed_interface = 0;
 
+	/*
+	 * The following variable is only used by the libusb v1.0
+	 * compat layer:
+	 */
+	pdev->auto_detach = 0;
+
 	return (error);
 }
 
@@ -711,6 +730,12 @@
 	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)
 {
@@ -1199,7 +1224,7 @@
 {
 	struct libusb20_backend *pbe;
 
-#if defined(__MidnightBSD__) || defined(__MidnightBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 	pbe = libusb20_be_alloc(&libusb20_ugen20_backend);
 #else
 	pbe = NULL;

Modified: trunk/lib/libusb/libusb20.h
===================================================================
--- trunk/lib/libusb/libusb20.h	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb20.h	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD$ */
 /*-
  * Copyright (c) 2008-2009 Hans Petter Selasky. All rights reserved.
  * Copyright (c) 2007-2008 Daniel Drake.  All rights reserved.
@@ -254,6 +255,7 @@
 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);

Modified: trunk/lib/libusb/libusb20_desc.c
===================================================================
--- trunk/lib/libusb/libusb20_desc.c	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb20_desc.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb20_desc.c 286334 2015-08-05 18:55:26Z pfg $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -133,15 +134,13 @@
 	 * Make a copy of the config descriptor, so that the caller can free
 	 * the inital config descriptor pointer!
 	 */
-	ptr = (void *)(lub_endpoint + nendpoint);
-	memcpy(LIBUSB20_ADD_BYTES(ptr, 0), config_desc, pcdesc.len);
+	memcpy((void *)(lub_endpoint + nendpoint), config_desc, pcdesc.len);
+
+	ptr = (const void *)(lub_endpoint + nendpoint);
 	pcdesc.ptr = LIBUSB20_ADD_BYTES(ptr, 0);
-	config_desc = LIBUSB20_ADD_BYTES(ptr, 0);
 
 	/* init config structure */
 
-	ptr = config_desc;
-
 	LIBUSB20_INIT(LIBUSB20_CONFIG_DESC, &lub_config->desc);
 
 	if (libusb20_me_decode(ptr, ptr[0], &lub_config->desc)) {

Modified: trunk/lib/libusb/libusb20_desc.h
===================================================================
--- trunk/lib/libusb/libusb20_desc.h	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb20_desc.h	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb20_desc.h 277848 2015-01-28 19:53:00Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  * Copyright (c) 2007-2008 Daniel Drake.  All rights reserved.
@@ -477,6 +478,12 @@
 
 	/** Set then report an endpoint's synchronization frame */
 	LIBUSB20_REQUEST_SYNCH_FRAME = 0x0C,
+
+	/** Set U1 and U2 system exit latency */
+	LIBUSB20_REQUEST_SET_SEL = 0x30,
+
+	/** Set isochronous delay */
+	LIBUSB20_REQUEST_SET_ISOCH_DELAY = 0x31,
 };
 
 /** \ingroup misc

Modified: trunk/lib/libusb/libusb20_int.h
===================================================================
--- trunk/lib/libusb/libusb20_int.h	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb20_int.h	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb20_int.h 302276 2016-06-29 11:06:13Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -105,6 +106,7 @@
 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 +130,7 @@
   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) \
@@ -211,6 +214,9 @@
 	/* claimed interface */
 	uint8_t claimed_interface;
 
+	/* auto detach kernel driver */
+	uint8_t auto_detach;
+  
 	/* device file handle */
 	int	file;
 

Modified: trunk/lib/libusb/libusb20_ugen20.c
===================================================================
--- trunk/lib/libusb/libusb20_ugen20.c	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/libusb20_ugen20.c	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD: stable/9/lib/libusb/libusb20_ugen20.c 310282 2016-12-19 18:31:22Z trasz $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -69,6 +70,7 @@
 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;
@@ -205,8 +207,8 @@
 
 	snprintf(pdev->usb_desc, sizeof(pdev->usb_desc),
 	    USB_GENERIC_NAME "%u.%u: <%s %s> at usbus%u", pdev->bus_number,
-	    pdev->device_address, devinfo.udi_product,
-	    devinfo.udi_vendor, pdev->bus_number);
+	    pdev->device_address, devinfo.udi_vendor,
+	    devinfo.udi_product, pdev->bus_number);
 
 	error = 0;
 done:
@@ -640,6 +642,22 @@
 }
 
 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, 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;

Modified: trunk/lib/libusb/usb.h
===================================================================
--- trunk/lib/libusb/usb.h	2018-05-23 02:27:07 UTC (rev 9846)
+++ trunk/lib/libusb/usb.h	2018-05-23 02:32:43 UTC (rev 9847)
@@ -1,4 +1,5 @@
 /* $MidnightBSD$ */
+/* $FreeBSD$ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *



More information about the Midnightbsd-cvs mailing list