diff options
author | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
commit | 97d8b9495668afa398ab17c8c5f7e223b5fd2e89 (patch) | |
tree | 54038c9ac32a45f8741dcc23fb9a8ffc0e15ff89 /lib/libusb | |
parent | 5ee3bfdb338e7c80af29a67f4425c4be24c7b866 (diff) | |
parent | 086d73aef6d0ab7d21daa2076fdc8d25961f9b05 (diff) | |
download | FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.zip FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.tar.gz |
sync from head
Diffstat (limited to 'lib/libusb')
-rw-r--r-- | lib/libusb/Makefile | 14 | ||||
-rw-r--r-- | lib/libusb/libusb.h | 3 | ||||
-rw-r--r-- | lib/libusb/libusb01.c | 9 | ||||
-rw-r--r-- | lib/libusb/libusb10.c | 16 | ||||
-rw-r--r-- | lib/libusb/libusb10.h | 2 | ||||
-rw-r--r-- | lib/libusb/libusb10_desc.c | 9 | ||||
-rw-r--r-- | lib/libusb/libusb10_io.c | 9 | ||||
-rw-r--r-- | lib/libusb/libusb20.3 | 10 | ||||
-rw-r--r-- | lib/libusb/libusb20.c | 21 | ||||
-rw-r--r-- | lib/libusb/libusb20.h | 9 | ||||
-rw-r--r-- | lib/libusb/libusb20_desc.c | 8 | ||||
-rw-r--r-- | lib/libusb/libusb20_desc.h | 4 | ||||
-rw-r--r-- | lib/libusb/libusb20_int.h | 2 | ||||
-rw-r--r-- | lib/libusb/libusb20_ugen20.c | 31 | ||||
-rw-r--r-- | lib/libusb/libusb_global_linux.h | 69 | ||||
-rw-r--r-- | lib/libusb/usb.h | 5 |
16 files changed, 190 insertions, 31 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile index d45dd56..66dd795 100644 --- a/lib/libusb/Makefile +++ b/lib/libusb/Makefile @@ -37,6 +37,19 @@ SRCS+= libusb10_io.c CFLAGS+= -DCOMPAT_32BIT .endif +# +# 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 +# +.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 <bsd.lib.mk> # LibUSB v1.0 @@ -190,6 +203,7 @@ MLINKS += libusb20.3 libusb20_dev_reset.3 MLINKS += libusb20.3 libusb20_dev_check_connected.3 MLINKS += libusb20.3 libusb20_dev_set_power_mode.3 MLINKS += libusb20.3 libusb20_dev_get_power_mode.3 +MLINKS += libusb20.3 libusb20_dev_get_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.h b/lib/libusb/libusb.h index 1675f46..225b539 100644 --- a/lib/libusb/libusb.h +++ b/lib/libusb/libusb.h @@ -27,8 +27,11 @@ #ifndef __LIBUSB_H__ #define __LIBUSB_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include <stdint.h> #include <sys/time.h> #include <sys/types.h> +#endif #ifdef __cplusplus extern "C" { diff --git a/lib/libusb/libusb01.c b/lib/libusb/libusb01.c index 17edb0e..30a1430 100644 --- a/lib/libusb/libusb01.c +++ b/lib/libusb/libusb01.c @@ -28,11 +28,16 @@ * This file contains the emulation layer for LibUSB v0.1 from sourceforge. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 256d67e..0212296 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -25,17 +25,23 @@ * SUCH DAMAGE. */ -#include <sys/fcntl.h> -#include <sys/ioctl.h> -#include <sys/queue.h> - +#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 @@ -1331,7 +1337,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 d2a2bd7..f1e5460 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -27,7 +27,9 @@ #ifndef __LIBUSB10_H__ #define __LIBUSB10_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include <sys/queue.h> +#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 11e201f..d2f3f53 100644 --- a/lib/libusb/libusb10_desc.c +++ b/lib/libusb/libusb10_desc.c @@ -24,10 +24,15 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #define libusb_device_handle libusb20_device diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 302fdb8..489ceb7 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -24,15 +24,20 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <errno.h> #include <poll.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> +#include <sys/queue.h> +#include <sys/endian.h> +#endif #define libusb_device_handle libusb20_device diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3 index af80c6c..8d286f1 100644 --- a/lib/libusb/libusb20.3 +++ b/lib/libusb/libusb20.3 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 13, 2012 +.Dd February 14, 2013 .Dt LIBUSB20 3 .Os .Sh NAME @@ -149,6 +149,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 * @@ -740,6 +742,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. diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c index aa45991..644eda4 100644 --- a/lib/libusb/libusb20.c +++ b/lib/libusb/libusb20.c @@ -24,13 +24,17 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <ctype.h> #include <poll.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #include "libusb20.h" #include "libusb20_desc.h" @@ -71,6 +75,7 @@ dummy_callback(struct libusb20_transfer *xfer) #define dummy_check_connected (void *)dummy_int #define dummy_set_power_mode (void *)dummy_int #define dummy_get_power_mode (void *)dummy_int +#define dummy_get_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 @@ -717,6 +722,18 @@ libusb20_dev_get_power_mode(struct libusb20_device *pdev) return (power_mode); } +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) { diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h index 87e0572..4a57b49 100644 --- a/lib/libusb/libusb20.h +++ b/lib/libusb/libusb20.h @@ -29,13 +29,9 @@ #ifndef _LIBUSB20_H_ #define _LIBUSB20_H_ -#include <sys/endian.h> -#include <sys/time.h> -#include <sys/types.h> - +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include <stdint.h> -#include <string.h> -#include <time.h> +#endif #ifdef __cplusplus extern "C" { @@ -255,6 +251,7 @@ int libusb20_dev_reset(struct libusb20_device *pdev); int libusb20_dev_check_connected(struct libusb20_device *pdev); int libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode); uint8_t libusb20_dev_get_power_mode(struct libusb20_device *pdev); +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 e2fa5b5..22077b6 100644 --- a/lib/libusb/libusb20_desc.c +++ b/lib/libusb/libusb20_desc.c @@ -24,11 +24,15 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h index a069ee9..48e2715 100644 --- a/lib/libusb/libusb20_desc.h +++ b/lib/libusb/libusb20_desc.h @@ -45,6 +45,10 @@ #ifndef _LIBUSB20_DESC_H_ #define _LIBUSB20_DESC_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include <stdint.h> +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h index 0251c5f..6705c63 100644 --- a/lib/libusb/libusb20_int.h +++ b/lib/libusb/libusb20_int.h @@ -105,6 +105,7 @@ typedef int (libusb20_process_t)(struct libusb20_device *pdev); typedef int (libusb20_reset_device_t)(struct libusb20_device *pdev); typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode); typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode); +typedef int (libusb20_get_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); @@ -127,6 +128,7 @@ typedef void (libusb20_tr_cancel_async_t)(struct libusb20_transfer *xfer); m(n, check_connected) \ m(n, set_power_mode) \ m(n, get_power_mode) \ + m(n, get_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 2c67778..0846eb4 100644 --- a/lib/libusb/libusb20_ugen20.c +++ b/lib/libusb/libusb20_ugen20.c @@ -24,24 +24,28 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> -#include <sys/types.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> - -#include "libusb20.h" -#include "libusb20_desc.h" -#include "libusb20_int.h" +#include <time.h> +#include <sys/queue.h> +#include <sys/types.h> +#endif #include <dev/usb/usb.h> #include <dev/usb/usbdi.h> #include <dev/usb/usb_ioctl.h> +#include "libusb20.h" +#include "libusb20_desc.h" +#include "libusb20_int.h" + static libusb20_init_backend_t ugen20_init_backend; static libusb20_open_device_t ugen20_open_device; static libusb20_close_device_t ugen20_close_device; @@ -69,6 +73,7 @@ static libusb20_reset_device_t ugen20_reset_device; static libusb20_check_connected_t ugen20_check_connected; static libusb20_set_power_mode_t ugen20_set_power_mode; static libusb20_get_power_mode_t ugen20_get_power_mode; +static libusb20_get_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; @@ -639,6 +644,18 @@ ugen20_get_power_mode(struct libusb20_device *pdev, uint8_t *power_mode) } static int +ugen20_get_power_usage(struct libusb20_device *pdev, uint16_t *power_usage) +{ + int temp; + + if (ioctl(pdev->file_ctrl, USB_GET_POWER_USAGE, &temp)) { + return (LIBUSB20_ERROR_OTHER); + } + *power_usage = temp; + return (0); /* success */ +} + +static int ugen20_kernel_driver_active(struct libusb20_device *pdev, uint8_t iface_index) { diff --git a/lib/libusb/libusb_global_linux.h b/lib/libusb/libusb_global_linux.h new file mode 100644 index 0000000..cbdd2c6 --- /dev/null +++ b/lib/libusb/libusb_global_linux.h @@ -0,0 +1,69 @@ +/* $FreeBSD$ */ +/*- + * 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 +#define _POSIX_SOURCE +#define _POSIX_C_SOURCE 200809 + +#include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <time.h> +#include <unistd.h> +#include <alloca.h> +#include <string.h> +#include <fcntl.h> +#include <limits.h> +#include <pthread.h> +#include <sys/queue.h> +#include <sys/ioctl.h> +#include <sys/poll.h> +#include <sys/time.h> +#include <dev/usb/usb_endian.h> +#include <dev/usb/usb_freebsd.h> + +#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 dc3959e..d7bbaa5 100644 --- a/lib/libusb/usb.h +++ b/lib/libusb/usb.h @@ -27,10 +27,11 @@ #ifndef _LIBUSB20_COMPAT_01_H_ #define _LIBUSB20_COMPAT_01_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include <stdint.h> #include <sys/param.h> #include <sys/endian.h> - -#include <stdint.h> +#endif /* USB interface class codes */ |