diff options
author | Pete Batard <pbatard@gmail.com> | 2010-01-14 00:30:20 +0000 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-01-14 00:30:20 +0000 |
commit | df329ef40549e040d3638e18232ef41f89d47764 (patch) | |
tree | e767269410d10ed5e68e59912b73f90d5ed7b46a | |
parent | d5d7f721bb06a3c2f513826218c89fcbb50af8fd (diff) | |
download | libusb-df329ef40549e040d3638e18232ef41f89d47764.tar.gz |
mirror libusb-winusb git branch from 2009.12.03 part 2 - core files
-rw-r--r--[-rwxr-xr-x] | autogen.sh | 0 | ||||
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | libusb/Makefile.am | 7 | ||||
-rw-r--r-- | libusb/core.c | 32 | ||||
-rw-r--r-- | libusb/descriptor.c | 46 | ||||
-rw-r--r-- | libusb/io.c | 4 | ||||
-rw-r--r-- | libusb/libusb.h | 12 | ||||
-rw-r--r-- | libusb/libusbi.h | 17 |
8 files changed, 79 insertions, 49 deletions
diff --git a/autogen.sh b/autogen.sh index d5c6a19..d5c6a19 100755..100644 --- a/autogen.sh +++ b/autogen.sh diff --git a/configure.ac b/configure.ac index 8aedfba..088c9ac 100644 --- a/configure.ac +++ b/configure.ac @@ -30,12 +30,22 @@ case $host in backend="darwin" AM_LDFLAGS="-Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation -Wl,-prebind -no-undefined" ;; +*-mingw*) + AC_DEFINE(OS_WINDOWS, [], [Windows backend]) + AC_SUBST(OS_WINDOWS) + AC_DEFINE(USBI_OS_HANDLES_TIMEOUT, [], [Backend handles timeout]) + AC_MSG_RESULT([Windows]) + backend="windows" + LIBS="-lpthread -lsetupapi -lws2_32" + AM_LDFLAGS="" + ;; *) AC_MSG_ERROR([unsupported operating system]) esac AM_CONDITIONAL([OS_LINUX], [test "x$backend" == "xlinux"]) AM_CONDITIONAL([OS_DARWIN], [test "x$backend" == "xdarwin"]) +AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" == "xwindows"]) # Library versioning lt_major="0" diff --git a/libusb/Makefile.am b/libusb/Makefile.am index a2be46c..cf777bc 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -2,8 +2,9 @@ lib_LTLIBRARIES = libusb-1.0.la LINUX_USBFS_SRC = os/linux_usbfs.h os/linux_usbfs.c DARWIN_USB_SRC = os/darwin_usb.h os/darwin_usb.c +WINDOWS_USB_SRC = os/windows_usb.h os/windows_usb.c os/windows_compat.h os/windows_compat.c -EXTRA_DIST = $(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) +EXTRA_DIST = $(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) $(WINDOWS_USB_SRC) if OS_LINUX OS_SRC = $(LINUX_USBFS_SRC) @@ -14,6 +15,10 @@ OS_SRC = $(DARWIN_USB_SRC) AM_CFLAGS_EXT = -no-cpp-precomp endif +if OS_WINDOWS +OS_SRC = $(WINDOWS_USB_SRC) +endif + libusb_1_0_la_CFLAGS = $(VISIBILITY_CFLAGS) $(AM_CFLAGS) -pthread libusb_1_0_la_SOURCES = libusbi.h core.c descriptor.c io.c sync.c $(OS_SRC) diff --git a/libusb/core.c b/libusb/core.c index 7e4fd24..448f0b9 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -21,7 +21,11 @@ #include <config.h> #include <errno.h> +#ifdef OS_WINDOWS +#include "os/windows_compat.h" +#else #include <poll.h> +#endif #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -36,6 +40,8 @@ const struct usbi_os_backend * const usbi_backend = &linux_usbfs_backend; #elif defined(OS_DARWIN) const struct usbi_os_backend * const usbi_backend = &darwin_backend; +#elif defined(OS_WINDOWS) +const struct usbi_os_backend * const usbi_backend = &windows_backend; #else #error "Unsupported OS" #endif @@ -676,7 +682,7 @@ static const struct libusb_endpoint_descriptor *find_endpoint( { int iface_idx; for (iface_idx = 0; iface_idx < config->bNumInterfaces; iface_idx++) { - const struct libusb_interface *iface = &config->interface[iface_idx]; + const struct libusb_interface *iface = &config->iface[iface_idx]; int altsetting_idx; for (altsetting_idx = 0; altsetting_idx < iface->num_altsetting; @@ -1344,7 +1350,7 @@ API_EXPORTED int libusb_reset_device(libusb_device_handle *dev) * perform I/O. * * \param dev a device handle - * \param interface the interface to check + * \param interface_number the interface to check * \returns 0 if no kernel driver is active * \returns 1 if a kernel driver is active * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected @@ -1352,11 +1358,11 @@ API_EXPORTED int libusb_reset_device(libusb_device_handle *dev) * \see libusb_detach_kernel_driver() */ API_EXPORTED int libusb_kernel_driver_active(libusb_device_handle *dev, - int interface) + int interface_number) { - usbi_dbg("interface %d", interface); + usbi_dbg("interface %d", interface_number); if (usbi_backend->kernel_driver_active) - return usbi_backend->kernel_driver_active(dev, interface); + return usbi_backend->kernel_driver_active(dev, interface_number); else return LIBUSB_ERROR_NOT_SUPPORTED; } @@ -1366,7 +1372,7 @@ API_EXPORTED int libusb_kernel_driver_active(libusb_device_handle *dev, * able to claim the interface and perform I/O. * * \param dev a device handle - * \param interface the interface to detach the driver from + * \param interface_number the interface to detach the driver from * \returns 0 on success * \returns LIBUSB_ERROR_NOT_FOUND if no kernel driver was active * \returns LIBUSB_ERROR_INVALID_PARAM if the interface does not exist @@ -1375,11 +1381,11 @@ API_EXPORTED int libusb_kernel_driver_active(libusb_device_handle *dev, * \see libusb_kernel_driver_active() */ API_EXPORTED int libusb_detach_kernel_driver(libusb_device_handle *dev, - int interface) + int interface_number) { - usbi_dbg("interface %d", interface); + usbi_dbg("interface %d", interface_number); if (usbi_backend->detach_kernel_driver) - return usbi_backend->detach_kernel_driver(dev, interface); + return usbi_backend->detach_kernel_driver(dev, interface_number); else return LIBUSB_ERROR_NOT_SUPPORTED; } @@ -1389,7 +1395,7 @@ API_EXPORTED int libusb_detach_kernel_driver(libusb_device_handle *dev, * using libusb_detach_kernel_driver(). * * \param dev a device handle - * \param interface the interface to attach the driver from + * \param interface_number the interface to attach the driver from * \returns 0 on success * \returns LIBUSB_ERROR_NOT_FOUND if no kernel driver was active * \returns LIBUSB_ERROR_INVALID_PARAM if the interface does not exist @@ -1400,11 +1406,11 @@ API_EXPORTED int libusb_detach_kernel_driver(libusb_device_handle *dev, * \see libusb_kernel_driver_active() */ API_EXPORTED int libusb_attach_kernel_driver(libusb_device_handle *dev, - int interface) + int interface_number) { - usbi_dbg("interface %d", interface); + usbi_dbg("interface %d", interface_number); if (usbi_backend->attach_kernel_driver) - return usbi_backend->attach_kernel_driver(dev, interface); + return usbi_backend->attach_kernel_driver(dev, interface_number); else return LIBUSB_ERROR_NOT_SUPPORTED; } diff --git a/libusb/descriptor.c b/libusb/descriptor.c index acd7668..dea0bce 100644 --- a/libusb/descriptor.c +++ b/libusb/descriptor.c @@ -154,16 +154,16 @@ static int parse_endpoint(struct libusb_context *ctx, return parsed; } -static void clear_interface(struct libusb_interface *interface) +static void clear_interface(struct libusb_interface *iface) { int i; int j; - if (interface->altsetting) { - for (i = 0; i < interface->num_altsetting; i++) { + if (iface->altsetting) { + for (i = 0; i < iface->num_altsetting; i++) { struct libusb_interface_descriptor *ifp = (struct libusb_interface_descriptor *) - interface->altsetting + i; + iface->altsetting + i; if (ifp->extra) free((void *) ifp->extra); if (ifp->endpoint) { @@ -173,14 +173,14 @@ static void clear_interface(struct libusb_interface *interface) free((void *) ifp->endpoint); } } - free((void *) interface->altsetting); - interface->altsetting = NULL; + free((void *) iface->altsetting); + iface->altsetting = NULL; } } static int parse_interface(libusb_context *ctx, - struct libusb_interface *interface, unsigned char *buffer, int size, + struct libusb_interface *iface, unsigned char *buffer, int size, int host_endian) { int i; @@ -192,22 +192,22 @@ static int parse_interface(libusb_context *ctx, struct libusb_interface_descriptor *ifp; unsigned char *begin; - interface->num_altsetting = 0; + iface->num_altsetting = 0; while (size >= INTERFACE_DESC_LENGTH) { struct libusb_interface_descriptor *altsetting = - (struct libusb_interface_descriptor *) interface->altsetting; + (struct libusb_interface_descriptor *) iface->altsetting; altsetting = realloc(altsetting, sizeof(struct libusb_interface_descriptor) * - (interface->num_altsetting + 1)); + (iface->num_altsetting + 1)); if (!altsetting) { r = LIBUSB_ERROR_NO_MEM; goto err; } - interface->altsetting = altsetting; + iface->altsetting = altsetting; - ifp = altsetting + interface->num_altsetting; - interface->num_altsetting++; + ifp = altsetting + iface->num_altsetting; + iface->num_altsetting++; usbi_parse_descriptor(buffer, "bbbbbbbbb", ifp, 0); ifp->extra = NULL; ifp->extra_length = 0; @@ -309,18 +309,18 @@ static int parse_interface(libusb_context *ctx, return parsed; err: - clear_interface(interface); + clear_interface(iface); return r; } static void clear_configuration(struct libusb_config_descriptor *config) { - if (config->interface) { + if (config->iface) { int i; for (i = 0; i < config->bNumInterfaces; i++) clear_interface((struct libusb_interface *) - config->interface + i); - free((void *) config->interface); + config->iface + i); + free((void *) config->iface); } if (config->extra) free((void *) config->extra); @@ -335,7 +335,7 @@ static int parse_configuration(struct libusb_context *ctx, int size; int tmp; struct usb_descriptor_header header; - struct libusb_interface *interface; + struct libusb_interface *iface; usbi_parse_descriptor(buffer, "bbwbbbbb", config, host_endian); size = config->wTotalLength; @@ -346,12 +346,12 @@ static int parse_configuration(struct libusb_context *ctx, } tmp = config->bNumInterfaces * sizeof(struct libusb_interface); - interface = malloc(tmp); - config->interface = interface; - if (!config->interface) + iface = malloc(tmp); + config->iface = iface; + if (!config->iface) return LIBUSB_ERROR_NO_MEM; - memset(interface, 0, tmp); + memset(iface, 0, tmp); buffer += config->bLength; size -= config->bLength; @@ -405,7 +405,7 @@ static int parse_configuration(struct libusb_context *ctx, } } - r = parse_interface(ctx, interface + i, buffer, size, host_endian); + r = parse_interface(ctx, iface + i, buffer, size, host_endian); if (r < 0) goto err; diff --git a/libusb/io.c b/libusb/io.c index 387be4c..552e54c 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -20,7 +20,11 @@ #include <config.h> #include <errno.h> +#ifdef OS_WINDOWS +#include "os/windows_compat.h" +#else #include <poll.h> +#endif #include <pthread.h> #include <signal.h> #include <stdint.h> diff --git a/libusb/libusb.h b/libusb/libusb.h index 2dbb9a5..4dbbed9 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -491,7 +491,7 @@ struct libusb_config_descriptor { /** Array of interfaces supported by this configuration. The length of * this array is determined by the bNumInterfaces field. */ - const struct libusb_interface *interface; + const struct libusb_interface *iface; /** Extra descriptors. If libusb encounters unknown configuration * descriptors, it will store them here, should you wish to parse them. */ @@ -795,8 +795,8 @@ void libusb_close(libusb_device_handle *dev_handle); libusb_device *libusb_get_device(libusb_device_handle *dev_handle); int libusb_set_configuration(libusb_device_handle *dev, int configuration); -int libusb_claim_interface(libusb_device_handle *dev, int iface); -int libusb_release_interface(libusb_device_handle *dev, int iface); +int libusb_claim_interface(libusb_device_handle *dev, int interface_number); +int libusb_release_interface(libusb_device_handle *dev, int interface_number); libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id); @@ -806,9 +806,9 @@ int libusb_set_interface_alt_setting(libusb_device_handle *dev, int libusb_clear_halt(libusb_device_handle *dev, unsigned char endpoint); int libusb_reset_device(libusb_device_handle *dev); -int libusb_kernel_driver_active(libusb_device_handle *dev, int interface); -int libusb_detach_kernel_driver(libusb_device_handle *dev, int interface); -int libusb_attach_kernel_driver(libusb_device_handle *dev, int interface); +int libusb_kernel_driver_active(libusb_device_handle *dev, int interface_number); +int libusb_detach_kernel_driver(libusb_device_handle *dev, int interface_number); +int libusb_attach_kernel_driver(libusb_device_handle *dev, int interface_number); /* async I/O */ diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 10a4994..1d5c9e4 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -23,7 +23,11 @@ #include <config.h> +#ifdef OS_WINDOWS +#include "os/windows_compat.h" +#else #include <poll.h> +#endif #include <pthread.h> #include <stddef.h> #include <time.h> @@ -577,7 +581,7 @@ struct usbi_os_backend { * was opened * - another LIBUSB_ERROR code on other failure */ - int (*claim_interface)(struct libusb_device_handle *handle, int iface); + int (*claim_interface)(struct libusb_device_handle *handle, int interface_number); /* Release a previously claimed interface. * @@ -594,7 +598,7 @@ struct usbi_os_backend { * was opened * - another LIBUSB_ERROR code on other failure */ - int (*release_interface)(struct libusb_device_handle *handle, int iface); + int (*release_interface)(struct libusb_device_handle *handle, int interface_number); /* Set the alternate setting for an interface. * @@ -611,7 +615,7 @@ struct usbi_os_backend { * - another LIBUSB_ERROR code on other failure */ int (*set_interface_altsetting)(struct libusb_device_handle *handle, - int iface, int altsetting); + int interface_number, int altsetting); /* Clear a halt/stall condition on an endpoint. * @@ -658,7 +662,7 @@ struct usbi_os_backend { * - another LIBUSB_ERROR code on other failure */ int (*kernel_driver_active)(struct libusb_device_handle *handle, - int interface); + int interface_number); /* Detach a kernel driver from an interface. Optional. * @@ -674,7 +678,7 @@ struct usbi_os_backend { * - another LIBUSB_ERROR code on other failure */ int (*detach_kernel_driver)(struct libusb_device_handle *handle, - int interface); + int interface_number); /* Attach a kernel driver to an interface. Optional. * @@ -691,7 +695,7 @@ struct usbi_os_backend { * - another LIBUSB_ERROR code on other failure */ int (*attach_kernel_driver)(struct libusb_device_handle *handle, - int interface); + int interface_number); /* Destroy a device. Optional. * @@ -805,6 +809,7 @@ extern const struct usbi_os_backend * const usbi_backend; extern const struct usbi_os_backend linux_usbfs_backend; extern const struct usbi_os_backend darwin_backend; +extern const struct usbi_os_backend windows_backend; #endif |