diff options
author | Pete Batard <pbatard@gmail.com> | 2010-01-14 12:57:07 +0000 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-01-14 12:57:07 +0000 |
commit | e45233574257f5ffd409e830c0d1d32fc6b37d81 (patch) | |
tree | 4fed47145a1c04e8bd41ac5af11e448d87ea9e88 /libusb | |
parent | 6cc0e6afc4ee0f66ff355ec76bee4f1828118b6e (diff) | |
download | libusb-e45233574257f5ffd409e830c0d1d32fc6b37d81.tar.gz |
Fix CR/LF inconsistencies
Diffstat (limited to 'libusb')
-rw-r--r-- | libusb/core.c | 6 | ||||
-rw-r--r-- | libusb/io.c | 6 | ||||
-rw-r--r-- | libusb/libusb-1.0.def | 110 | ||||
-rw-r--r-- | libusb/libusb.h | 14 | ||||
-rw-r--r-- | libusb/libusbi.h | 6 | ||||
-rw-r--r-- | libusb/os/windows_compat.c | 90 | ||||
-rw-r--r-- | libusb/os/windows_compat.h | 32 | ||||
-rw-r--r-- | libusb/os/windows_usb.c | 334 | ||||
-rw-r--r-- | libusb/sync.c | 6 |
9 files changed, 302 insertions, 302 deletions
diff --git a/libusb/core.c b/libusb/core.c index 1728e35..1a2fdca 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -18,9 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef _MSC_VER
-#include <config_msvc.h>
-#else
+#ifdef _MSC_VER +#include <config_msvc.h> +#else #include <config.h> #endif #include <errno.h> diff --git a/libusb/io.c b/libusb/io.c index 50fd532..4ed956c 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -18,9 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef _MSC_VER
-#include <config_msvc.h>
-#else
+#ifdef _MSC_VER +#include <config_msvc.h> +#else #include <config.h> #endif #include <errno.h> diff --git a/libusb/libusb-1.0.def b/libusb/libusb-1.0.def index b08f81c..2ed5266 100644 --- a/libusb/libusb-1.0.def +++ b/libusb/libusb-1.0.def @@ -1,55 +1,55 @@ -LIBRARY libusb-1.0.dll
-EXPORTS
- libusb_init
- libusb_exit
- libusb_set_debug
- libusb_get_device_list
- libusb_free_device_list
- libusb_ref_device
- libusb_unref_device
- libusb_get_configuration
- libusb_get_device_descriptor
- libusb_get_active_config_descriptor
- libusb_get_config_descriptor
- libusb_get_config_descriptor_by_value
- libusb_free_config_descriptor
- libusb_get_bus_number
- libusb_get_device_address
- libusb_get_max_packet_size
- libusb_get_max_iso_packet_size
- libusb_open
- libusb_close
- libusb_get_device
- libusb_set_configuration
- libusb_claim_interface
- libusb_release_interface
- libusb_open_device_with_vid_pid
- libusb_set_interface_alt_setting
- libusb_clear_halt
- libusb_reset_device
- libusb_kernel_driver_active
- libusb_detach_kernel_driver
- libusb_attach_kernel_driver
- libusb_alloc_transfer
- libusb_submit_transfer
- libusb_cancel_transfer
- libusb_free_transfer
- libusb_control_transfer
- libusb_bulk_transfer
- libusb_interrupt_transfer
- libusb_get_string_descriptor_ascii
- libusb_try_lock_events
- libusb_lock_events
- libusb_unlock_events
- libusb_event_handling_ok
- libusb_event_handler_active
- libusb_lock_event_waiters
- libusb_unlock_event_waiters
- libusb_wait_for_event
- libusb_handle_events_timeout
- libusb_handle_events
- libusb_handle_events_locked
- libusb_pollfds_handle_timeouts
- libusb_get_next_timeout
- libusb_get_pollfds
- libusb_set_pollfd_notifiers
+LIBRARY libusb-1.0.dll +EXPORTS + libusb_init + libusb_exit + libusb_set_debug + libusb_get_device_list + libusb_free_device_list + libusb_ref_device + libusb_unref_device + libusb_get_configuration + libusb_get_device_descriptor + libusb_get_active_config_descriptor + libusb_get_config_descriptor + libusb_get_config_descriptor_by_value + libusb_free_config_descriptor + libusb_get_bus_number + libusb_get_device_address + libusb_get_max_packet_size + libusb_get_max_iso_packet_size + libusb_open + libusb_close + libusb_get_device + libusb_set_configuration + libusb_claim_interface + libusb_release_interface + libusb_open_device_with_vid_pid + libusb_set_interface_alt_setting + libusb_clear_halt + libusb_reset_device + libusb_kernel_driver_active + libusb_detach_kernel_driver + libusb_attach_kernel_driver + libusb_alloc_transfer + libusb_submit_transfer + libusb_cancel_transfer + libusb_free_transfer + libusb_control_transfer + libusb_bulk_transfer + libusb_interrupt_transfer + libusb_get_string_descriptor_ascii + libusb_try_lock_events + libusb_lock_events + libusb_unlock_events + libusb_event_handling_ok + libusb_event_handler_active + libusb_lock_event_waiters + libusb_unlock_event_waiters + libusb_wait_for_event + libusb_handle_events_timeout + libusb_handle_events + libusb_handle_events_locked + libusb_pollfds_handle_timeouts + libusb_get_next_timeout + libusb_get_pollfds + libusb_set_pollfd_notifiers diff --git a/libusb/libusb.h b/libusb/libusb.h index 7070898..1fa01ac 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -36,13 +36,13 @@ extern "C" { #endif -/** \def libusb_cpu_to_le16
- * \ingroup misc
- * Convert a 16-bit value from host-endian to little-endian format. On
- * little endian systems, this function does nothing. On big endian systems,
- * the bytes are swapped.
- * \param x the host-endian value to convert
- * \returns the value in little-endian byte order
+/** \def libusb_cpu_to_le16 + * \ingroup misc + * Convert a 16-bit value from host-endian to little-endian format. On + * little endian systems, this function does nothing. On big endian systems, + * the bytes are swapped. + * \param x the host-endian value to convert + * \returns the value in little-endian byte order */ static inline uint16_t libusb_cpu_to_le16(uint16_t x) { union { diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 462e864..9cdbba5 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -21,9 +21,9 @@ #ifndef __LIBUSBI_H__ #define __LIBUSBI_H__ -#ifdef _MSC_VER
-#include <config_msvc.h>
-#else
+#ifdef _MSC_VER +#include <config_msvc.h> +#else #include <config.h> #endif #include <pthread.h> diff --git a/libusb/os/windows_compat.c b/libusb/os/windows_compat.c index f1311a2..641ef15 100644 --- a/libusb/os/windows_compat.c +++ b/libusb/os/windows_compat.c @@ -88,7 +88,7 @@ #endif #endif -#define CHECK_INIT_POLLING do {if(!is_polling_set) init_polling();} while(0)
+#define CHECK_INIT_POLLING do {if(!is_polling_set) init_polling();} while(0) // public fd data const struct winfd INVALID_WINFD = {-1, NULL, NULL, RW_NONE}; @@ -217,7 +217,7 @@ __inline void _init_read_marker(int index) CancelIo(poll_fd[index].handle); // Setup a new async read on our marker reset_overlapped(poll_fd[index].overlapped); - if (!ReadFile(poll_fd[index].handle, &_poll_fd[index].marker, 1, NULL, poll_fd[index].overlapped)) {
+ if (!ReadFile(poll_fd[index].handle, &_poll_fd[index].marker, 1, NULL, poll_fd[index].overlapped)) { if(GetLastError() != ERROR_IO_PENDING) { printb("_init_read_marker: didn't get IO_PENDING!\n"); reset_overlapped(poll_fd[index].overlapped); @@ -240,24 +240,24 @@ int pipe_for_poll(int filedes[2]) HANDLE handle[2]; OVERLAPPED *overlapped0, *overlapped1; char pipe_name[] = "\\\\.\\pipe\\libusb000000000000"; -
- CHECK_INIT_POLLING;
-
- overlapped0 = calloc(1, sizeof(OVERLAPPED));
+ + CHECK_INIT_POLLING; + + overlapped0 = calloc(1, sizeof(OVERLAPPED)); if (overlapped0 == NULL) { return -1; } -
- overlapped1 = calloc(1, sizeof(OVERLAPPED));
+ + overlapped1 = calloc(1, sizeof(OVERLAPPED)); if (overlapped1 == NULL) { free(overlapped0); return -1; } -
- _snprintf(pipe_name, sizeof(pipe_name), "\\\\.\\pipe\\libusb%08x%04x", (unsigned)GetCurrentProcessId(), pipe_number++);
+ + _snprintf(pipe_name, sizeof(pipe_name), "\\\\.\\pipe\\libusb%08x%04x", (unsigned)GetCurrentProcessId(), pipe_number++); // Read end of the pipe - handle[0] = CreateNamedPipeA(pipe_name, PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED,
+ handle[0] = CreateNamedPipeA(pipe_name, PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE, 1, 4096, 4096, 0, NULL); if (handle[0] == INVALID_HANDLE_VALUE) { printb("Could not create pipe (read end): errcode %d\n", (int)GetLastError()); @@ -267,7 +267,7 @@ int pipe_for_poll(int filedes[2]) printb("filedes[0] = %d\n", filedes[0]); // Write end of the pipe - handle[1] = CreateFileA(pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
+ handle[1] = CreateFileA(pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, NULL); if (handle[1] == INVALID_HANDLE_VALUE) { printb("Could not create pipe (write end): errcode %d\n", (int)GetLastError()); @@ -357,8 +357,8 @@ struct winfd create_fd_for_poll(HANDLE handle, int access_mode) } // Ensure that we get a non system conflicting unique fd - fd = _open_osfhandle((intptr_t)CreateFileA("NUL", 0, 0,
- NULL, OPEN_EXISTING, 0, NULL), _O_RDWR);
+ fd = _open_osfhandle((intptr_t)CreateFileA("NUL", 0, 0, + NULL, OPEN_EXISTING, 0, NULL), _O_RDWR); if (fd < 0) { return INVALID_WINFD; } @@ -564,14 +564,14 @@ int poll(struct pollfd *fds, unsigned int nfds, int timeout) // If nothing was triggered, wait on all fds that require it if (nb_handles_to_wait_on != 0) { - printb("poll: starting %d ms wait for %d handles...\n", timeout, (int)nb_handles_to_wait_on);
- ret = WaitForMultipleObjects(nb_handles_to_wait_on, handles_to_wait_on,
- FALSE, (timeout==-1)?INFINITE:timeout);
-
- if (((ret-WAIT_OBJECT_0) >= 0) && ((ret-WAIT_OBJECT_0) < nb_handles_to_wait_on)) {
+ printb("poll: starting %d ms wait for %d handles...\n", timeout, (int)nb_handles_to_wait_on); + ret = WaitForMultipleObjects(nb_handles_to_wait_on, handles_to_wait_on, + FALSE, (timeout==-1)?INFINITE:timeout); + + if (((ret-WAIT_OBJECT_0) >= 0) && ((ret-WAIT_OBJECT_0) < nb_handles_to_wait_on)) { printb(" completed after wait\n"); - i = handle_to_index[ret-WAIT_OBJECT_0];
- index = _fd_to_index_and_lock(fds[i].fd);
+ i = handle_to_index[ret-WAIT_OBJECT_0]; + index = _fd_to_index_and_lock(fds[i].fd); fds[i].revents = fds[i].events; triggered++; if (index >= 0) { @@ -657,21 +657,21 @@ ssize_t write_for_poll(int fd, const void *buf, size_t count) printb("write_for_poll: writing %d bytes to fd=%d\n", count, poll_fd[index].fd); reset_overlapped(poll_fd[index].overlapped); - if (!WriteFile(poll_fd[index].handle, buf, (DWORD)count, &wr_count, poll_fd[index].overlapped)) {
+ if (!WriteFile(poll_fd[index].handle, buf, (DWORD)count, &wr_count, poll_fd[index].overlapped)) { if(GetLastError() == ERROR_IO_PENDING) { // I/O started but is not completed => wait till completion switch(WaitForSingleObject(poll_fd[index].overlapped->hEvent, INFINITE)) { case WAIT_OBJECT_0: - if (GetOverlappedResult(poll_fd[index].handle,
- poll_fd[index].overlapped, &wr_count, FALSE)) {
- errno = 0;
- goto out;
- } else {
+ if (GetOverlappedResult(poll_fd[index].handle, + poll_fd[index].overlapped, &wr_count, FALSE)) { + errno = 0; + goto out; + } else { printb("write_for_poll: GetOverlappedResult failed with error %d\n", (int)GetLastError()); - errno = EIO;
- goto out;
- }
+ errno = EIO; + goto out; + } default: errno = EIO; goto out; @@ -681,27 +681,27 @@ ssize_t write_for_poll(int fd, const void *buf, size_t count) printb("write_for_poll: WriteFile failed with error %d\n", (int)GetLastError()); errno = EIO; goto out; - }
- }
-
- // I/O started and completed synchronously
- errno = 0;
-
-out:
- if (errno) {
- reset_overlapped(poll_fd[index].overlapped);
+ } + } + + // I/O started and completed synchronously + errno = 0; + +out: + if (errno) { + reset_overlapped(poll_fd[index].overlapped); pthread_mutex_unlock(&_poll_fd[index].mutex); return -1; } else { pthread_mutex_unlock(&_poll_fd[index].mutex); return (ssize_t)wr_count; } -}
-
+} + /* * synchronous read for custom poll (works on Windows file handles that * have been opened with the FILE_FLAG_OVERLAPPED flag) - */
+ */ ssize_t read_for_poll(int fd, void *buf, size_t count) { int index; @@ -761,7 +761,7 @@ ssize_t read_for_poll(int fd, void *buf, size_t count) // Read supplementary bytes if needed (blocking) if (count > 1) { reset_overlapped(poll_fd[index].overlapped); - if (!ReadFile(poll_fd[index].handle, (char*)buf+1, (DWORD)(count-1), &rd_count, poll_fd[index].overlapped)) {
+ if (!ReadFile(poll_fd[index].handle, (char*)buf+1, (DWORD)(count-1), &rd_count, poll_fd[index].overlapped)) { if(GetLastError() == ERROR_IO_PENDING) { if (!GetOverlappedResult(poll_fd[index].handle, poll_fd[index].overlapped, &rd_count, TRUE)) { // TODO: handle more data! @@ -772,8 +772,8 @@ ssize_t read_for_poll(int fd, void *buf, size_t count) } else { printb("read_for_poll: could not start blocking read of supplementary: %d\n", (int)GetLastError()); errno = EIO; - goto out;
- }
+ goto out; + } } // If ReadFile completed synchronously, we're fine too diff --git a/libusb/os/windows_compat.h b/libusb/os/windows_compat.h index 95f8d75..61de32d 100644 --- a/libusb/os/windows_compat.h +++ b/libusb/os/windows_compat.h @@ -26,15 +26,15 @@ * * This is placed in the .h to limit changes required to the core files */ -#if defined(interface)
-#undef interface
+#if defined(interface) +#undef interface #endif #if !defined(ssize_t) -#if defined (_WIN64)
-#define ssize_t __int64
-#else
-#define ssize_t long
+#if defined (_WIN64) +#define ssize_t __int64 +#else +#define ssize_t long #endif #endif @@ -92,13 +92,13 @@ struct winfd overlapped_to_winfd(OVERLAPPED* overlapped); } #endif #if !defined(timersub) -#define timersub(a, b, result) \
-do { \
- (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
- (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
- if ((result)->tv_usec < 0) { \
- --(result)->tv_sec; \
- (result)->tv_usec += 1000000; \
- } \
-} while (0)
-#endif
+#define timersub(a, b, result) \ +do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ +} while (0) +#endif diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 3002787..2ec0970 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -17,7 +17,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(_MSC_VER)
+#if defined(_MSC_VER) // If the following is true, then Microsoft provided an improper WINVER // to Visual Studio 2008 on Windows 7. Both should be set to 0x601 #if (WINVER <= _WIN32_WINNT_LONGHORN) && (WINVER >= _WIN32_WINNT_WIN7) @@ -25,9 +25,9 @@ #define WINVER 0x601 #undef _WIN32_WINNT_WIN7 #define _WIN32_WINNT_WIN7 0x601 -#endif
-#include <config_msvc.h>
-#else
+#endif +#include <config_msvc.h> +#else #include <config.h> #endif #include <ctype.h> @@ -275,11 +275,11 @@ err_exit: SetupDiDestroyDeviceInfoList(*dev_info); *dev_info = INVALID_HANDLE_VALUE; return NULL; -}
-
-/*
- * Populate the endpoints addresses of the device_priv interface helper structs
- */
+} + +/* + * Populate the endpoints addresses of the device_priv interface helper structs + */ static void windows_assign_endpoints(struct libusb_device *dev, int iface, int altsetting) { int i; @@ -300,8 +300,8 @@ static void windows_assign_endpoints(struct libusb_device *dev, int iface, int a } libusb_free_config_descriptor(conf_desc); } -}
-
+} + /* * init: libusb backend init function * @@ -330,14 +330,14 @@ static int windows_init(struct libusb_context *ctx) // Detect OS version memset(&os_version, 0, sizeof(OSVERSIONINFO)); - os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- windows_version = WINDOWS_UNSUPPORTED;
+ os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + windows_version = WINDOWS_UNSUPPORTED; if ((GetVersionEx(&os_version) != 0) && (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT)) { - if ((os_version.dwMajorVersion == 5) && (os_version.dwMinorVersion == 1)) {
- windows_version = WINDOWS_XP;
- } else if (os_version.dwMajorVersion >= 6) {
- windows_version = WINDOWS_VISTA_AND_LATER;
- }
+ if ((os_version.dwMajorVersion == 5) && (os_version.dwMinorVersion == 1)) { + windows_version = WINDOWS_XP; + } else if (os_version.dwMajorVersion >= 6) { + windows_version = WINDOWS_VISTA_AND_LATER; + } } if (windows_version == WINDOWS_UNSUPPORTED) { usbi_err(ctx, "This version of Windows is NOT supported"); @@ -821,14 +821,14 @@ static int set_composite_device(struct libusb_context *ctx, DEVINST devinst, str SP_DEVINFO_DATA dev_info_data; SP_DEVICE_INTERFACE_DETAIL_DATA *dev_interface_details = NULL; HKEY key; - WCHAR guid_string_w[GUID_STRING_LENGTH];
+ WCHAR guid_string_w[GUID_STRING_LENGTH]; GUID guid; GUID guid_table[MAX_USB_DEVICES]; char* sanitized_path[MAX_USB_DEVICES]; char* sanitized_short = NULL; char path[MAX_PATH_LENGTH]; - char driver[MAX_KEY_LENGTH];
-
+ char driver[MAX_KEY_LENGTH]; + dev_info = SetupDiGetClassDevs(NULL, "USB", NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES); if (dev_info == INVALID_HANDLE_VALUE) { return LIBUSB_ERROR_NOT_FOUND; @@ -1235,12 +1235,12 @@ static int windows_get_configuration(struct libusb_device_handle *dev_handle, in return LIBUSB_SUCCESS; } -/*
- * from http://msdn.microsoft.com/en-us/library/ms793522.aspx: "The port driver
- * does not currently expose a service that allows higher-level drivers to set
- * the configuration."
- * TODO: See what users of devices with multiple confs report with this call
- */
+/* + * from http://msdn.microsoft.com/en-us/library/ms793522.aspx: "The port driver + * does not currently expose a service that allows higher-level drivers to set + * the configuration." + * TODO: See what users of devices with multiple confs report with this call + */ static int windows_set_configuration(struct libusb_device_handle *dev_handle, int config) { int r = LIBUSB_SUCCESS; @@ -1353,7 +1353,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) if (r != LIBUSB_SUCCESS) { return r; } -
+ usbi_add_pollfd(ctx, transfer_priv->pollable_fd.fd, (transfer->endpoint & LIBUSB_ENDPOINT_IN)?POLLIN:POLLOUT); @@ -1391,7 +1391,7 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) if (r != LIBUSB_SUCCESS) { return r; } -
+ usbi_add_pollfd(ctx, transfer_priv->pollable_fd.fd, POLLIN); return LIBUSB_SUCCESS; @@ -1521,14 +1521,14 @@ static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, } if (found) { - if (GetOverlappedResult(transfer_priv->pollable_fd.handle,
- transfer_priv->pollable_fd.overlapped, &io_size, false)) {
- io_result = NO_ERROR;
- } else {
- io_result = GetLastError();
- }
- usbi_remove_pollfd(ctx, transfer_priv->pollable_fd.fd);
- free_fd_for_poll(transfer_priv->pollable_fd.fd);
+ if (GetOverlappedResult(transfer_priv->pollable_fd.handle, + transfer_priv->pollable_fd.overlapped, &io_size, false)) { + io_result = NO_ERROR; + } else { + io_result = GetLastError(); + } + usbi_remove_pollfd(ctx, transfer_priv->pollable_fd.fd); + free_fd_for_poll(transfer_priv->pollable_fd.fd); windows_handle_callback(transfer, io_result, io_size); } else { usbi_err(ctx, "could not find a matching transfer for fd %x", fds[i]); @@ -1798,9 +1798,9 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i return LIBUSB_ERROR_ACCESS; } - if (!WinUsb_GetAssociatedInterface(winusb_handle, iface-1,
- &handle_priv->interface_handle[iface].winusb)) {
- handle_priv->interface_handle[iface].winusb = INVALID_HANDLE_VALUE;
+ if (!WinUsb_GetAssociatedInterface(winusb_handle, iface-1, + &handle_priv->interface_handle[iface].winusb)) { + handle_priv->interface_handle[iface].winusb = INVALID_HANDLE_VALUE; switch(GetLastError()) { case ERROR_NO_MORE_ITEMS: // invalid iface return LIBUSB_ERROR_NOT_FOUND; @@ -1834,13 +1834,13 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i } handle_priv->interface_handle[iface].winusb = winusb_handle; } - if (!WinUsb_QueryInterfaceSettings(winusb_handle, 0, &if_desc)) {
+ if (!WinUsb_QueryInterfaceSettings(winusb_handle, 0, &if_desc)) { usbi_err(ctx, "could not query interface settings for interface %d: %s", iface, windows_error_str(0)); - } else if (if_desc.bInterfaceNumber != iface) {
- usbi_warn(ctx, "program assertion failed - WinUSB interface %d found at position %d",
- if_desc.bInterfaceNumber, iface);
- }
-
+ } else if (if_desc.bInterfaceNumber != iface) { + usbi_warn(ctx, "program assertion failed - WinUSB interface %d found at position %d", + if_desc.bInterfaceNumber, iface); + } + usbi_dbg("claimed interface %d", iface); handle_priv->active_interface = iface; @@ -1889,12 +1889,12 @@ static int winusb_release_interface(struct libusb_device_handle *dev_handle, int return LIBUSB_SUCCESS; } -/*
- * Return the first valid WinUSB handle, for control transfers
- */
-static int winusb_get_valid_interface(struct windows_device_handle_priv *handle_priv)
-{
- int i;
+/* + * Return the first valid WinUSB handle, for control transfers + */ +static int winusb_get_valid_interface(struct windows_device_handle_priv *handle_priv) +{ + int i; for (i=0; i<USB_MAXINTERFACES; i++) { if ( (handle_priv->interface_handle[i].winusb != 0) @@ -1902,30 +1902,30 @@ static int winusb_get_valid_interface(struct windows_device_handle_priv *handle_ return i; } } - return -1;
+ return -1; } -/*
- * Lookup interface by endpoint address. -1 if not found
- */
+/* + * Lookup interface by endpoint address. -1 if not found + */ static int winusb_interface_by_endpoint(struct windows_device_priv *priv, struct windows_device_handle_priv *handle_priv, uint8_t endpoint_address) { - int i, j;
- for (i=0; i<USB_MAXINTERFACES; i++) {
- if (handle_priv->interface_handle[i].winusb == INVALID_HANDLE_VALUE)
- continue;
- if (handle_priv->interface_handle[i].winusb == 0)
- continue;
- if (priv->interface[i].endpoint == NULL)
- continue;
- for (j=0; j<priv->interface[i].nb_endpoints; j++) {
- if (priv->interface[i].endpoint[j] == endpoint_address) {
- return i;
- }
- }
- }
- return -1;
+ int i, j; + for (i=0; i<USB_MAXINTERFACES; i++) { + if (handle_priv->interface_handle[i].winusb == INVALID_HANDLE_VALUE) + continue; + if (handle_priv->interface_handle[i].winusb == 0) + continue; + if (priv->interface[i].endpoint == NULL) + continue; + for (j=0; j<priv->interface[i].nb_endpoints; j++) { + if (priv->interface[i].endpoint[j] == endpoint_address) { + return i; + } + } + } + return -1; } static int winusb_submit_control_transfer(struct usbi_transfer *itransfer) @@ -1971,25 +1971,25 @@ static int winusb_submit_control_transfer(struct usbi_transfer *itransfer) return LIBUSB_ERROR_NO_MEM; } - if (!WinUsb_ControlTransfer(wfd.handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, NULL, wfd.overlapped)) {
+ if (!WinUsb_ControlTransfer(wfd.handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, NULL, wfd.overlapped)) { if(GetLastError() != ERROR_IO_PENDING) { usbi_err(ctx, "WinUsb_ControlTransfer failed: %s", windows_error_str(0)); free_fd_for_poll(wfd.fd); - return LIBUSB_ERROR_IO;
- }
- } else {
- // TODO: find out if this ever happens through user test reports
- usbi_err(ctx, "chill out man; this is like way too fast for async I/O...");
- free_fd_for_poll(wfd.fd);
+ return LIBUSB_ERROR_IO; + } + } else { + // TODO: find out if this ever happens through user test reports + usbi_err(ctx, "chill out man; this is like way too fast for async I/O..."); + free_fd_for_poll(wfd.fd); return LIBUSB_ERROR_IO; - }
-
- // Use priv_transfer to store data needed for async polling
- transfer_priv->pollable_fd = wfd;
-
- return LIBUSB_SUCCESS;
-}
-
+ } + + // Use priv_transfer to store data needed for async polling + transfer_priv->pollable_fd = wfd; + + return LIBUSB_SUCCESS; +} + static int winusb_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting) { struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); @@ -2004,16 +2004,16 @@ static int winusb_set_interface_altsetting(struct libusb_device_handle *dev_hand return LIBUSB_ERROR_NOT_FOUND; } - if (!WinUsb_SetCurrentAlternateSetting(winusb_handle, altsetting)) {
+ if (!WinUsb_SetCurrentAlternateSetting(winusb_handle, altsetting)) { usbi_err(ctx, "WinUsb_SetCurrentAlternateSetting failed: %s", windows_error_str(0)); - return LIBUSB_ERROR_IO;
- }
-
- return LIBUSB_SUCCESS;
-}
-
-static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer)
-{
+ return LIBUSB_ERROR_IO; + } + + return LIBUSB_SUCCESS; +} + +static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer) +{ struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer); @@ -2024,53 +2024,53 @@ static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer) int current_interface; struct winfd wfd; - CHECK_WINUSB_AVAILABLE;
+ CHECK_WINUSB_AVAILABLE; transfer_priv->pollable_fd = INVALID_WINFD; -
- current_interface = winusb_interface_by_endpoint(priv, handle_priv, transfer->endpoint);
- if (current_interface < 0) {
- usbi_err(ctx, "unable to match endpoint to an open interface - cancelling transfer");
- return LIBUSB_ERROR_NOT_FOUND;
- }
-
- usbi_dbg("matched endpoint %02X with interface %d", transfer->endpoint, current_interface);
-
- winusb_handle = handle_priv->interface_handle[current_interface].winusb;
- direction_in = transfer->endpoint & LIBUSB_ENDPOINT_IN;
-
+ + current_interface = winusb_interface_by_endpoint(priv, handle_priv, transfer->endpoint); + if (current_interface < 0) { + usbi_err(ctx, "unable to match endpoint to an open interface - cancelling transfer"); + return LIBUSB_ERROR_NOT_FOUND; + } + + usbi_dbg("matched endpoint %02X with interface %d", transfer->endpoint, current_interface); + + winusb_handle = handle_priv->interface_handle[current_interface].winusb; + direction_in = transfer->endpoint & LIBUSB_ENDPOINT_IN; + wfd = create_fd_for_poll(winusb_handle, direction_in?_O_RDONLY:_O_WRONLY); if (wfd.fd < 0) { return LIBUSB_ERROR_NO_MEM; } -
- if (direction_in) {
- usbi_dbg("reading %d bytes", transfer->length);
- ret = WinUsb_ReadPipe(winusb_handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, wfd.overlapped);
- } else {
- usbi_dbg("writing %d bytes", transfer->length);
- ret = WinUsb_WritePipe(winusb_handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, wfd.overlapped);
- }
- if (!ret) {
+ + if (direction_in) { + usbi_dbg("reading %d bytes", transfer->length); + ret = WinUsb_ReadPipe(winusb_handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, wfd.overlapped); + } else { + usbi_dbg("writing %d bytes", transfer->length); + ret = WinUsb_WritePipe(winusb_handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, wfd.overlapped); + } + if (!ret) { if(GetLastError() != ERROR_IO_PENDING) { usbi_err(ctx, "WinUsb_Pipe Transfer failed: %s", windows_error_str(0)); free_fd_for_poll(wfd.fd); - return LIBUSB_ERROR_IO;
- }
- } else {
- // TODO: find out if this ever happens through user test reports
- usbi_err(ctx, "chill out man; this is like way too fast for async I/O...");
- free_fd_for_poll(wfd.fd);
+ return LIBUSB_ERROR_IO; + } + } else { + // TODO: find out if this ever happens through user test reports + usbi_err(ctx, "chill out man; this is like way too fast for async I/O..."); + free_fd_for_poll(wfd.fd); return LIBUSB_ERROR_IO; - }
-
- transfer_priv->pollable_fd = wfd;
-
- return LIBUSB_SUCCESS;
-}
-
-static int winusb_submit_iso_transfer(struct usbi_transfer *itransfer) {
- // WinUSB does not support isochronous transfers
+ } + + transfer_priv->pollable_fd = wfd; + + return LIBUSB_SUCCESS; +} + +static int winusb_submit_iso_transfer(struct usbi_transfer *itransfer) { + // WinUSB does not support isochronous transfers return LIBUSB_ERROR_NOT_SUPPORTED; } @@ -2082,21 +2082,21 @@ static int winusb_clear_halt(struct libusb_device_handle *dev_handle, unsigned c HANDLE winusb_handle; int current_interface; - CHECK_WINUSB_AVAILABLE;
+ CHECK_WINUSB_AVAILABLE; + + current_interface = winusb_interface_by_endpoint(priv, handle_priv, endpoint); + if (current_interface < 0) { + usbi_err(ctx, "unable to match endpoint to an open interface - cannot clear"); + return LIBUSB_ERROR_NOT_FOUND; + } - current_interface = winusb_interface_by_endpoint(priv, handle_priv, endpoint);
- if (current_interface < 0) {
- usbi_err(ctx, "unable to match endpoint to an open interface - cannot clear");
- return LIBUSB_ERROR_NOT_FOUND;
- }
-
- usbi_dbg("matched endpoint %02X with interface %d", endpoint, current_interface);
- winusb_handle = handle_priv->interface_handle[current_interface].winusb;
+ usbi_dbg("matched endpoint %02X with interface %d", endpoint, current_interface); + winusb_handle = handle_priv->interface_handle[current_interface].winusb; - if (!WinUsb_ResetPipe(winusb_handle, endpoint)) {
+ if (!WinUsb_ResetPipe(winusb_handle, endpoint)) { usbi_err(ctx, "WinUsb_ResetPipe failed: %s", windows_error_str(0)); - return LIBUSB_ERROR_NO_DEVICE;
- }
+ return LIBUSB_ERROR_NO_DEVICE; + } return LIBUSB_SUCCESS; } @@ -2104,7 +2104,7 @@ static int winusb_clear_halt(struct libusb_device_handle *dev_handle, unsigned c /* * from http://www.winvistatips.com/winusb-bugchecks-t335323.html (confirmed * through testing as well): - * "You can not call WinUsb_AbortPipe on control pipe. You can possibly cancel
+ * "You can not call WinUsb_AbortPipe on control pipe. You can possibly cancel * the control transfer using CancelIo" */ static int winusb_abort_control(struct usbi_transfer *itransfer) @@ -2122,22 +2122,22 @@ static int winusb_abort_transfers(struct usbi_transfer *itransfer) HANDLE winusb_handle; int current_interface; - CHECK_WINUSB_AVAILABLE;
- - current_interface = winusb_interface_by_endpoint(priv, handle_priv, transfer->endpoint);
- if (current_interface < 0) {
- usbi_err(ctx, "unable to match endpoint to an open interface - cancelling abort");
- return LIBUSB_ERROR_NOT_FOUND;
- }
-
- usbi_dbg("matched endpoint %02X with interface %d", transfer->endpoint, current_interface);
-
- winusb_handle = handle_priv->interface_handle[current_interface].winusb;
-
- if (!WinUsb_AbortPipe(winusb_handle, transfer->endpoint)) {
+ CHECK_WINUSB_AVAILABLE; + + current_interface = winusb_interface_by_endpoint(priv, handle_priv, transfer->endpoint); + if (current_interface < 0) { + usbi_err(ctx, "unable to match endpoint to an open interface - cancelling abort"); + return LIBUSB_ERROR_NOT_FOUND; + } + + usbi_dbg("matched endpoint %02X with interface %d", transfer->endpoint, current_interface); + + winusb_handle = handle_priv->interface_handle[current_interface].winusb; + + if (!WinUsb_AbortPipe(winusb_handle, transfer->endpoint)) { usbi_err(ctx, "WinUsb_AbortPipe failed: %s", windows_error_str(0)); - return LIBUSB_ERROR_NO_DEVICE;
- }
+ return LIBUSB_ERROR_NO_DEVICE; + } return LIBUSB_SUCCESS; } @@ -2159,9 +2159,9 @@ static int winusb_reset_device(struct libusb_device_handle *dev_handle) HANDLE winusb_handle; int i, j; - CHECK_WINUSB_AVAILABLE;
-
- // Reset any available pipe (except control)
+ CHECK_WINUSB_AVAILABLE; + + // Reset any available pipe (except control) for (i=0; i<USB_MAXINTERFACES; i++) { winusb_handle = handle_priv->interface_handle[i].winusb; for (wfd = handle_to_winfd(winusb_handle); wfd.fd > 0;) @@ -2176,17 +2176,17 @@ static int winusb_reset_device(struct libusb_device_handle *dev_handle) for (j=0; j<priv->interface[i].nb_endpoints; j++) { usbi_dbg("resetting ep %02X", priv->interface[i].endpoint[j]); // TODO: looks like whatever you try here, you can't get an actual reset of the ep - if (!WinUsb_AbortPipe(winusb_handle, priv->interface[i].endpoint[j])) {
+ if (!WinUsb_AbortPipe(winusb_handle, priv->interface[i].endpoint[j])) { usbi_err(ctx, "WinUsb_AbortPipe (pipe address %02X) failed: %s", priv->interface[i].endpoint[j], windows_error_str(0)); } // FlushPipe seems to fail on OUT pipes - if ( (priv->interface[i].endpoint[j] & LIBUSB_ENDPOINT_IN)
- && (!WinUsb_FlushPipe(winusb_handle, priv->interface[i].endpoint[j])) ) {
+ if ( (priv->interface[i].endpoint[j] & LIBUSB_ENDPOINT_IN) + && (!WinUsb_FlushPipe(winusb_handle, priv->interface[i].endpoint[j])) ) { usbi_err(ctx, "WinUsb_FlushPipe (pipe address %02X) failed: %s", priv->interface[i].endpoint[j], windows_error_str(0)); } - if (!WinUsb_ResetPipe(winusb_handle, priv->interface[i].endpoint[j])) {
+ if (!WinUsb_ResetPipe(winusb_handle, priv->interface[i].endpoint[j])) { usbi_err(ctx, "WinUsb_ResetPipe (pipe address %02X) failed: %s", priv->interface[i].endpoint[j], windows_error_str(0)); } diff --git a/libusb/sync.c b/libusb/sync.c index 75b7af7..6e65bce 100644 --- a/libusb/sync.c +++ b/libusb/sync.c @@ -17,9 +17,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef _MSC_VER
-#include <config_msvc.h>
-#else
+#ifdef _MSC_VER +#include <config_msvc.h> +#else #include <config.h> #endif #include <errno.h> |