From f43d8e65dba4e71b3113d094881cf52f64e7d646 Mon Sep 17 00:00:00 2001 From: Peter Stuge Date: Thu, 18 Mar 2010 12:44:55 +0000 Subject: removed trailing whitespaces (Windows backend) --- examples/xusb.c | 44 +++--- libusb/os/poll_windows.c | 32 ++--- libusb/os/windows_usb.c | 342 +++++++++++++++++++++++------------------------ libusb/os/windows_usb.h | 14 +- 4 files changed, 216 insertions(+), 216 deletions(-) diff --git a/examples/xusb.c b/examples/xusb.c index 5664ce6..cc832af 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -4,7 +4,7 @@ * Based on lsusb, copyright (c) 2007 Daniel Drake * With contributions to Mass Storage test by Alan Stern. * - * This test program tries to access an USB device through WinUSB. + * This test program tries to access an USB device through WinUSB. * To access your device, modify this source and add your VID/PID. * * This library is free software; you can redistribute it and/or @@ -141,7 +141,7 @@ enum test_type { } test_mode; uint16_t VID, PID; -void display_buffer_hex(unsigned char *buffer, unsigned size) +void display_buffer_hex(unsigned char *buffer, unsigned size) { unsigned i; @@ -154,7 +154,7 @@ void display_buffer_hex(unsigned char *buffer, unsigned size) } -// The XBOX Controller is really a HID device that got its HID Report Descriptors +// The XBOX Controller is really a HID device that got its HID Report Descriptors // removed by Microsoft. // Input/Output reports described at http://euc.jp/periphs/xbox-controller.ja.html int display_xbox_status(libusb_device_handle *handle) @@ -162,18 +162,18 @@ int display_xbox_status(libusb_device_handle *handle) int r; uint8_t input_report[20]; printf("\nReading XBox Input Report...\n"); - CALL_CHECK(libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, + CALL_CHECK(libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, HID_GET_REPORT, (HID_REPORT_TYPE_INPUT<<8)|0x00, 0, input_report, 20, 1000)); printf(" D-pad: %02X\n", input_report[2]&0x0F); printf(" Start:%d, Back:%d, Left Stick Press:%d, Right Stick Press:%d\n", B(input_report[2]&0x10), B(input_report[2]&0x20), B(input_report[2]&0x40), B(input_report[2]&0x80)); // A, B, X, Y, Black, White are pressure sensitive - printf(" A:%d, B:%d, X:%d, Y:%d, White:%d, Black:%d\n", input_report[4], input_report[5], + printf(" A:%d, B:%d, X:%d, Y:%d, White:%d, Black:%d\n", input_report[4], input_report[5], input_report[6], input_report[7], input_report[9], input_report[8]); printf(" Left Trigger: %d, Right Trigger: %d\n", input_report[10], input_report[11]); - printf(" Left Analog (X,Y): (%d,%d)\n", (int16_t)((input_report[13]<<8)|input_report[12]), + printf(" Left Analog (X,Y): (%d,%d)\n", (int16_t)((input_report[13]<<8)|input_report[12]), (int16_t)((input_report[15]<<8)|input_report[14])); - printf(" Right Analog (X,Y): (%d,%d)\n", (int16_t)((input_report[17]<<8)|input_report[16]), + printf(" Right Analog (X,Y): (%d,%d)\n", (int16_t)((input_report[17]<<8)|input_report[16]), (int16_t)((input_report[19]<<8)|input_report[18])); return 0; } @@ -190,12 +190,12 @@ int set_xbox_actuators(libusb_device_handle *handle, uint8_t left, uint8_t right output_report[3] = left; output_report[5] = right; - CALL_CHECK(libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, + CALL_CHECK(libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, HID_SET_REPORT, (HID_REPORT_TYPE_OUTPUT<<8)|0x00, 0, output_report, 06, 1000)); return 0; } -int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, uint8_t lun, +int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, uint8_t lun, uint8_t *cdb, uint8_t direction, int data_length, uint32_t *ret_tag) { static uint32_t tag = 1; @@ -245,8 +245,8 @@ int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, ui if (r != LIBUSB_SUCCESS) { perr(" send_mass_storage_command: %s\n", libusb_strerror(r)); return -1; - } - + } + printf(" sent %d CDB bytes\n", cdb_len); return 0; } @@ -341,9 +341,9 @@ int test_mass_storage(libusb_device_handle *handle, uint8_t endpoint_in, uint8_t unsigned char *data; printf("Reading Max LUN:\n"); - r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, + r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, BOMS_GET_MAX_LUN, 0, 0, &lun, 1, 1000); - // Some devices send a STALL instead of the actual value. + // Some devices send a STALL instead of the actual value. // In such cases we should set lun to 0. if (r == 0) { lun = 0; @@ -476,7 +476,7 @@ int test_hid(libusb_device_handle *handle, uint8_t endpoint_in) uint8_t *input_report; printf("\nReading HID Report Descriptors:\n"); - r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_STANDARD|LIBUSB_RECIPIENT_INTERFACE, + r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_STANDARD|LIBUSB_RECIPIENT_INTERFACE, LIBUSB_REQUEST_GET_DESCRIPTOR, LIBUSB_DT_REPORT<<8, 0, hid_report_descriptor, 256, 1000); if (r < 0) { printf("failed\n"); @@ -493,12 +493,12 @@ int test_hid(libusb_device_handle *handle, uint8_t endpoint_in) } printf("\nReading Feature Report...\n"); - r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, + r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, HID_GET_REPORT, (HID_REPORT_TYPE_FEATURE<<8)|0, 0, input_report, (uint16_t)size, 5000); if (r >= 0) { display_buffer_hex(input_report, size); } else { - switch(r) { + switch(r) { case LIBUSB_ERROR_NOT_FOUND: printf(" No Feature Report available for this device\n"); break; @@ -513,7 +513,7 @@ int test_hid(libusb_device_handle *handle, uint8_t endpoint_in) } printf("\nReading Input Report...\n"); - r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, + r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, HID_GET_REPORT, (HID_REPORT_TYPE_INPUT<<8)|0x00, 0, input_report, (uint16_t)size, 5000); if (r >= 0) { display_buffer_hex(input_report, size); @@ -587,15 +587,15 @@ int test_device(uint16_t vid, uint16_t pid) printf(" nb interfaces: %d\n", nb_ifaces); for (i=0; ibNumInterfaces; i++) { for (j=0; jusb_interface[i].num_altsetting; j++) { - printf("interface[%d].altsetting[%d]: num endpoints = %d\n", + printf("interface[%d].altsetting[%d]: num endpoints = %d\n", i, j, conf_desc->usb_interface[i].altsetting[j].bNumEndpoints); - printf(" Class.SubClass.Protocol: %02X.%02X.%02X\n", + printf(" Class.SubClass.Protocol: %02X.%02X.%02X\n", conf_desc->usb_interface[i].altsetting[j].bInterfaceClass, conf_desc->usb_interface[i].altsetting[j].bInterfaceSubClass, conf_desc->usb_interface[i].altsetting[j].bInterfaceProtocol); - if ( (conf_desc->usb_interface[i].altsetting[j].bInterfaceClass == LIBUSB_CLASS_MASS_STORAGE) + if ( (conf_desc->usb_interface[i].altsetting[j].bInterfaceClass == LIBUSB_CLASS_MASS_STORAGE) && ( (conf_desc->usb_interface[i].altsetting[j].bInterfaceSubClass == 0x01) - || (conf_desc->usb_interface[i].altsetting[j].bInterfaceSubClass == 0x06) ) + || (conf_desc->usb_interface[i].altsetting[j].bInterfaceSubClass == 0x06) ) && (conf_desc->usb_interface[i].altsetting[j].bInterfaceProtocol == 0x50) ) { // Mass storage devices that can use basic SCSI commands test_scsi = -1; @@ -647,7 +647,7 @@ int test_device(uint16_t vid, uint16_t pid) } } } - + switch(test_mode) { case USE_XBOX: CALL_CHECK(display_xbox_status(handle)); diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index a7072b2..4497cc6 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -25,7 +25,7 @@ * * The way this layer works is by using OVERLAPPED with async I/O transfers, as * OVERLAPPED have an associated event which is flagged for I/O completion. - * + * * For USB pollable async I/O, you would typically: * - obtain a Windows HANDLE to a file or device that has been opened in * OVERLAPPED mode @@ -34,7 +34,7 @@ * twice, once in _O_RDONLY and once in _O_WRONLY mode to obtain 2 separate * pollable fds * - leave the core functions call the poll routine and flag POLLIN/POLLOUT - * + * * The pipe pollable synchronous I/O works using the overlapped event associated * with a fake pipe. The read/write functions are only meant to be used in that * context. @@ -69,7 +69,7 @@ // cygwin produces a warning unless these prototypes are defined extern int _close(int fd); extern int _snprintf(char *buffer, size_t count, const char *format, ...); -extern int cygwin_attach_handle_to_fd(char *name, int fd, HANDLE handle, int bin, int access); +extern int cygwin_attach_handle_to_fd(char *name, int fd, HANDLE handle, int bin, int access); // _open_osfhandle() is not available on cygwin, but we can emulate // it for our needs with cygwin_attach_handle_to_fd() static inline int _open_osfhandle(intptr_t osfhandle, int flags) @@ -119,7 +119,7 @@ LONG pipe_number = 0; static volatile LONG compat_spinlock = 0; // CancelIoEx, available on Vista and later only, provides the ability to cancel -// a single transfer (OVERLAPPED) when used. As it may not be part of any of the +// a single transfer (OVERLAPPED) when used. As it may not be part of any of the // platform headers, we hook into the Kernel32 system DLL directly to seek it. static BOOL (__stdcall *pCancelIoEx)(HANDLE, LPOVERLAPPED) = NULL; #define CancelIoEx_Available (pCancelIoEx != NULL) @@ -154,7 +154,7 @@ void init_polling(void) if (!is_polling_set) { pCancelIoEx = (BOOL (__stdcall *)(HANDLE,LPOVERLAPPED)) GetProcAddress(GetModuleHandle("KERNEL32"), "CancelIoEx"); - usbi_dbg("Will use CancelIo%s for I/O cancellation", + usbi_dbg("Will use CancelIo%s for I/O cancellation", CancelIoEx_Available?"Ex":""); for (i=0; ihEvent != 0) + if ( (overlapped->hEvent != 0) && (overlapped->hEvent != INVALID_HANDLE_VALUE) ) { CloseHandle(overlapped->hEvent); } @@ -371,14 +371,14 @@ out0: } /* - * Create both an fd and an OVERLAPPED from an open Windows handle, so that + * Create both an fd and an OVERLAPPED from an open Windows handle, so that * it can be used with our polling function * The handle MUST support overlapped transfers (usually requires CreateFile * with FILE_FLAG_OVERLAPPED) * Return a pollable file descriptor struct, or INVALID_WINFD on error * * Note that the fd returned by this function is a per-transfer fd, rather - * than a per-session fd and cannot be used for anything else but our + * than a per-session fd and cannot be used for anything else but our * custom functions (the fd itself points to the NUL: device) * if you plan to do R/W on the same handle, you MUST create 2 fds: one for * read and one for write. Using a single R/W fd is unsupported and will @@ -485,7 +485,7 @@ void _free_index(int index) } /* - * Release a pollable file descriptor. + * Release a pollable file descriptor. * * Note that the associated Windows handle is not closed by this call */ @@ -603,13 +603,13 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) unsigned j; // To address the possibility of missing new fds between the time the new - // pollable fd set is assembled, and the ResetEvent() call below, an + // pollable fd set is assembled, and the ResetEvent() call below, an // additional new_fd[] HANDLE table is used for any new fd that was created // since the last call to poll (see below) ResetEvent(fd_update); // At this stage, any new fd creation will be detected through the fd_update - // event notification, and any previous creation that we may have missed + // event notification, and any previous creation that we may have missed // will be picked up through the existing new_fd[] table. #endif @@ -667,7 +667,7 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) triggered = -1; goto poll_exit; } - + poll_dbg("fd[%d]=%d (overlapped = %p) got events %04X", i, poll_fd[index].fd, poll_fd[index].overlapped, fds[i].events); // The following macro only works if overlapped I/O was reported pending @@ -700,7 +700,7 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) // have been added since the last call to poll, but are not (yet) part // of the pollable fd set. Typically, these would be from fds that have // been created between the construction of the fd set and the calling - // of poll. + // of poll. // Event if we won't be able to return usable poll data on these events, // make sure we monitor them to return an EINTR code usbi_mutex_lock(&new_fd_mutex); // We could probably do without @@ -726,7 +726,7 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) } else { poll_dbg("starting %d ms wait for %d handles...", timeout, (int)nb_handles_to_wait_on); } - ret = WaitForMultipleObjects(nb_handles_to_wait_on, handles_to_wait_on, + ret = WaitForMultipleObjects(nb_handles_to_wait_on, handles_to_wait_on, FALSE, (timeout<0)?INFINITE:(DWORD)timeout); object_index = ret-WAIT_OBJECT_0; if ((object_index >= 0) && ((DWORD)object_index < nb_handles_to_wait_on)) { @@ -820,7 +820,7 @@ ssize_t usbi_write(int fd, const void *buf, size_t count) index = _fd_to_index_and_lock(fd); - if ( (index < 0) || (poll_fd[index].overlapped == NULL) + if ( (index < 0) || (poll_fd[index].overlapped == NULL) || (poll_fd[index].rw != RW_WRITE) ) { errno = EBADF; if (index >= 0) { diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index e21a984..1e66f96 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -22,8 +22,8 @@ // COMPILATION OPTIONS: // - Use HidD_(G/S)et(In/Out)putReport instead of (Read/Write)File for HID -// Note that http://msdn.microsoft.com/en-us/library/ms789883.aspx: -// "In addition, some devices might not support HidD_GetInputReport, +// Note that http://msdn.microsoft.com/en-us/library/ms789883.aspx: +// "In addition, some devices might not support HidD_GetInputReport, // and will become unresponsive if this routine is used." // => Don't blame libusb if you can't read or write HID reports when the // option below is enabled. @@ -56,7 +56,7 @@ // The 2 macros below are used in conjunction with safe loops. #define LOOP_CHECK(fcall) { r=fcall; if (r != LIBUSB_SUCCESS) continue; } -#define LOOP_BREAK(err) { r=err; continue; } +#define LOOP_BREAK(err) { r=err; continue; } extern void usbi_fd_notification(struct libusb_context *ctx); @@ -118,7 +118,7 @@ const uint64_t epoch_time = UINT64_C(116444736000000000); // 1970.01.01 00:00:00 enum windows_version windows_version = WINDOWS_UNSUPPORTED; // Concurrency static int concurrent_usage = -1; -// Timer thread +// Timer thread // NB: index 0 is for monotonic and 1 is for the thread exit event HANDLE timer_thread = NULL; HANDLE timer_mutex = NULL; @@ -169,9 +169,9 @@ static inline BOOLEAN guid_eq(const GUID *guid1, const GUID *guid2) { static char* guid_to_string(const GUID guid) { static char guid_string[MAX_GUID_STRING_LENGTH]; - + sprintf(guid_string, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", - (unsigned int)guid.Data1, guid.Data2, guid.Data3, + (unsigned int)guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); return guid_string; @@ -226,13 +226,13 @@ static char* sanitize_path(const char* path) root_size = sizeof(root_prefix)-1; // Microsoft indiscriminatly uses '\\?\', '\\.\', '##?#" or "##.#" for root prefixes. - if (!((size > 3) && (((path[0] == '\\') && (path[1] == '\\') && (path[3] == '\\')) || + if (!((size > 3) && (((path[0] == '\\') && (path[1] == '\\') && (path[3] == '\\')) || ((path[0] == '#') && (path[1] == '#') && (path[3] == '#'))))) { add_root = root_size; size += add_root; } - if ((ret_path = (char*)calloc(size, 1)) == NULL) + if ((ret_path = (char*)calloc(size, 1)) == NULL) return NULL; safe_strncpy(&ret_path[add_root], size-add_root, path, strlen(path)); @@ -259,7 +259,7 @@ static int Cfgmgr32_init(void) DLL_LOAD(Cfgmgr32.dll, CM_Get_Parent, TRUE); DLL_LOAD(Cfgmgr32.dll, CM_Get_Child, TRUE); DLL_LOAD(Cfgmgr32.dll, CM_Get_Sibling, TRUE); - DLL_LOAD(Cfgmgr32.dll, CM_Get_Device_IDA, TRUE); + DLL_LOAD(Cfgmgr32.dll, CM_Get_Device_IDA, TRUE); DLL_LOAD(Cfgmgr32.dll, CM_Get_Device_IDW, TRUE); return LIBUSB_SUCCESS; @@ -275,10 +275,10 @@ static int Cfgmgr32_init(void) * index: zero based index of the interface in the device info list * * Note: it is the responsibility of the caller to free the DEVICE_INTERFACE_DETAIL_DATA - * structure returned and call this function repeatedly using the same guid (with an + * structure returned and call this function repeatedly using the same guid (with an * incremented index starting at zero) until all interfaces have been returned. */ -SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ctx, +SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ctx, HDEVINFO *dev_info, SP_DEVINFO_DATA *dev_info_data, GUID guid, unsigned index) { SP_DEVICE_INTERFACE_DATA dev_interface_data; @@ -296,7 +296,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct dev_info_data->cbSize = sizeof(SP_DEVINFO_DATA); if (!SetupDiEnumDeviceInfo(*dev_info, index, dev_info_data)) { if (GetLastError() != ERROR_NO_MORE_ITEMS) { - usbi_err(ctx, "Could not obtain device info data for index %u: %s", + usbi_err(ctx, "Could not obtain device info data for index %u: %s", index, windows_error_str(0)); } SetupDiDestroyDeviceInfoList(*dev_info); @@ -308,7 +308,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct dev_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); if (!SetupDiEnumDeviceInterfaces(*dev_info, NULL, &guid, index, &dev_interface_data)) { if (GetLastError() != ERROR_NO_MORE_ITEMS) { - usbi_err(ctx, "Could not obtain interface data for index %u: %s", + usbi_err(ctx, "Could not obtain interface data for index %u: %s", index, windows_error_str(0)); } SetupDiDestroyDeviceInfoList(*dev_info); @@ -320,11 +320,11 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct if (!SetupDiGetDeviceInterfaceDetail(*dev_info, &dev_interface_data, NULL, 0, &size, NULL)) { // The dummy call should fail with ERROR_INSUFFICIENT_BUFFER if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - usbi_err(ctx, "could not access interface data (dummy) for index %u: %s", + usbi_err(ctx, "could not access interface data (dummy) for index %u: %s", index, windows_error_str(0)); goto err_exit; } - } + } else { usbi_err(ctx, "program assertion failed - http://msdn.microsoft.com/en-us/library/ms792901.aspx is wrong."); goto err_exit; @@ -335,10 +335,10 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct goto err_exit; } - dev_interface_details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - if (!SetupDiGetDeviceInterfaceDetail(*dev_info, &dev_interface_data, + dev_interface_details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + if (!SetupDiGetDeviceInterfaceDetail(*dev_info, &dev_interface_data, dev_interface_details, size, &size, NULL)) { - usbi_err(ctx, "could not access interface data (actual) for index %u: %s", + usbi_err(ctx, "could not access interface data (actual) for index %u: %s", index, windows_error_str(0)); } @@ -371,7 +371,7 @@ static void windows_assign_endpoints(struct libusb_device *dev, int iface, int a usbi_dbg("(re)assigned endpoint %02X to interface %d", priv->usb_interface[iface].endpoint[i], iface); } } - libusb_free_config_descriptor(conf_desc); + libusb_free_config_descriptor(conf_desc); } } @@ -420,7 +420,7 @@ static int windows_init(struct libusb_context *ctx) CloseHandle(semaphore); return LIBUSB_ERROR_OTHER; } - + // NB: concurrent usage supposes that init calls are equally balanced with // exit calls. If init is called more than exit, we will not exit properly if ( ++concurrent_usage == 0 ) { // First init? @@ -460,7 +460,7 @@ static int windows_init(struct libusb_context *ctx) } } - // Because QueryPerformanceCounter might report different values when + // Because QueryPerformanceCounter might report different values when // running on different cores, we create a separate thread for the timer // calls, which we glue to the first core always to prevent timing discrepancies. r = LIBUSB_ERROR_NO_MEM; @@ -524,7 +524,7 @@ static int windows_init(struct libusb_context *ctx) if (hcd_root == NULL) r = LIBUSB_ERROR_NO_DEVICE; - else + else r = LIBUSB_SUCCESS; init_exit: // Holds semaphore here. @@ -533,7 +533,7 @@ init_exit: // Holds semaphore here. SetEvent(timer_request[1]); // actually the signal to quit the thread. if (WAIT_OBJECT_0 != WaitForSingleObject(timer_thread, INFINITE)) { usbi_warn(ctx, "could not wait for timer thread to quit"); - TerminateThread(timer_thread, 1); // shouldn't happen, but we're destroying + TerminateThread(timer_thread, 1); // shouldn't happen, but we're destroying // all objects it might have held anyway. } CloseHandle(timer_thread); @@ -565,7 +565,7 @@ init_exit: // Holds semaphore here. /* * Initialize device structure, including active config - */ + */ static int initialize_device(struct libusb_device *dev, libusb_bus_t busnum, libusb_devaddr_t devaddr, char *path, int connection_index, uint8_t active_config, struct libusb_device *parent_dev) @@ -602,7 +602,7 @@ static int initialize_device(struct libusb_device *dev, libusb_bus_t busnum, * Note that we follow the Linux convention and use the "Linux Foundation root hub" * vendor ID as well as the product ID to indicate the hub speed */ -static int force_hcd_device_descriptor(struct libusb_device *dev, HANDLE handle) +static int force_hcd_device_descriptor(struct libusb_device *dev, HANDLE handle) { DWORD size; USB_HUB_CAPABILITIES hub_caps; @@ -619,7 +619,7 @@ static int force_hcd_device_descriptor(struct libusb_device *dev, HANDLE handle) priv->dev_descriptor.idVendor = 0x1d6b; // Linux Foundation root hub if (windows_version >= WINDOWS_VISTA_AND_LATER) { size = sizeof(USB_HUB_CAPABILITIES_EX); - if (DeviceIoControl(handle, IOCTL_USB_GET_HUB_CAPABILITIES_EX, &hub_caps_ex, + if (DeviceIoControl(handle, IOCTL_USB_GET_HUB_CAPABILITIES_EX, &hub_caps_ex, size, &hub_caps_ex, size, &size, NULL)) { // Sanity check. HCD hub should always be root if (!hub_caps_ex.CapabilityFlags.HubIsRoot) { @@ -629,9 +629,9 @@ static int force_hcd_device_descriptor(struct libusb_device *dev, HANDLE handle) } } else { size = sizeof(USB_HUB_CAPABILITIES); - if (!DeviceIoControl(handle, IOCTL_USB_GET_HUB_CAPABILITIES, &hub_caps, + if (!DeviceIoControl(handle, IOCTL_USB_GET_HUB_CAPABILITIES, &hub_caps, size, &hub_caps, size, &size, NULL)) { - usbi_warn(ctx, "could not read hub capabilities (std) for hub %s: %s", + usbi_warn(ctx, "could not read hub capabilities (std) for hub %s: %s", priv->path, windows_error_str(0)); priv->dev_descriptor.idProduct = 1; // Indicate 1x speed } else { @@ -645,7 +645,7 @@ static int force_hcd_device_descriptor(struct libusb_device *dev, HANDLE handle) /* * fetch and cache all the config descriptors through I/O */ -static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle) +static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle) { DWORD size, ret_size; struct libusb_context *ctx = DEVICE_CTX(dev); @@ -666,12 +666,12 @@ static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle for (i=0; inum_configurations; i++) priv->config_descriptor[i] = NULL; - for (i=0, r=LIBUSB_SUCCESS; ; i++) + for (i=0, r=LIBUSB_SUCCESS; ; i++) { // safe loop: release all dynamic resources safe_free(cd_buf_actual); - // safe loop: end of loop condition + // safe loop: end of loop condition if ((i >= dev->num_configurations) || (r != LIBUSB_SUCCESS)) break; @@ -731,7 +731,7 @@ static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle } usbi_dbg("cached config descriptor #%d (%d bytes)", i+1, cd_data->wTotalLength); - + // Sanity check. Ensures that indexes for our list of config desc is in the right order if (i != (cd_data->bConfigurationValue-1)) { usbi_warn(ctx, "program assertion failed - config descriptors are being read out of order"); @@ -751,8 +751,8 @@ static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle /* * Recursively enumerates and finds all hubs & devices */ -static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs **_discdevs, - HANDLE hub_handle, libusb_bus_t busnum, struct libusb_device *parent_dev, uint8_t nb_ports) +static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs **_discdevs, + HANDLE hub_handle, libusb_bus_t busnum, struct libusb_device *parent_dev, uint8_t nb_ports) { struct discovered_devs *discdevs = *_discdevs; struct libusb_device *dev = NULL; @@ -761,7 +761,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs USB_HUB_NAME_FIXED s_hubname; USB_NODE_CONNECTION_INFORMATION conn_info; USB_NODE_INFORMATION hub_node; - bool is_hcd, need_unref = false; + bool is_hcd, need_unref = false; int i, r; LPCWSTR wstr; char *tmp_str = NULL, *path_str = NULL; @@ -793,7 +793,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs // Loop through all the ports on this hub for (i = 1, r = LIBUSB_SUCCESS; ; i++) { - // safe loop: release all dynamic resources + // safe loop: release all dynamic resources if (need_unref) { safe_unref_device(dev); need_unref = false; @@ -802,7 +802,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs safe_free(path_str); safe_closehandle(handle); - // safe loop: end of loop condition + // safe loop: end of loop condition if ((i > nb_ports) || (r != LIBUSB_SUCCESS)) break; @@ -819,17 +819,17 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs if (conn_info.ConnectionStatus == NoDeviceConnected) { continue; - } + } if (conn_info.DeviceAddress == 0) { - usbi_warn(ctx, "program assertion failed - device address is zero " + usbi_warn(ctx, "program assertion failed - device address is zero " "(conflicts with root hub), ignoring device"); continue; } s_hubname.u.node.ConnectionIndex = i; // Only used for non HCDs (s_hubname is an union) - } - else + } + else { // HCDs have only 1 node, and it's always a hub conn_info.DeviceAddress = 0; @@ -838,9 +838,9 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs } // If this node is a hub (HCD or not), open it - if (conn_info.DeviceIsHub) { + if (conn_info.DeviceIsHub) { size = size_initial; - if (!DeviceIoControl(hub_handle, getname_ioctl, &s_hubname, size, + if (!DeviceIoControl(hub_handle, getname_ioctl, &s_hubname, size, &s_hubname, size, &size, NULL)) { usbi_warn(ctx, "could not get hub path (dummy): %s", windows_error_str(0)); continue; @@ -877,7 +877,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs } // Open Hub - handle = CreateFileA(path_str, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + handle = CreateFileA(path_str, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if(handle == INVALID_HANDLE_VALUE) { usbi_warn(ctx, "could not open hub %s: %s", path_str, windows_error_str(0)); @@ -902,25 +902,25 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs if (dev) { usbi_dbg("using existing device for session %ld", session_id); priv = __device_priv(dev); - // Because we are rebuilding the list, there's no guarantee + // Because we are rebuilding the list, there's no guarantee // the parent device pointer is still the same. // Other device data should still be reusable priv->parent_dev = parent_dev; } else { usbi_dbg("allocating new device for session %ld", session_id); - if ((dev = usbi_alloc_device(ctx, session_id)) == NULL) { + if ((dev = usbi_alloc_device(ctx, session_id)) == NULL) { LOOP_BREAK(LIBUSB_ERROR_NO_MEM); } need_unref = true; - LOOP_CHECK(initialize_device(dev, busnum, devaddr, path_str, i, + LOOP_CHECK(initialize_device(dev, busnum, devaddr, path_str, i, conn_info.CurrentConfigurationValue, parent_dev)); priv = __device_priv(dev); path_str = NULL; // protect our path from being freed // Setup the cached descriptors. Note that only non HCDs can fetch descriptors - if (!is_hcd) { + if (!is_hcd) { // The device descriptor has been read with conn_info memcpy(&priv->dev_descriptor, &(conn_info.DeviceDescriptor), sizeof(USB_DEVICE_DESCRIPTOR)); dev->num_configurations = priv->dev_descriptor.bNumConfigurations; @@ -936,7 +936,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs } discdevs = discovered_devs_append(*_discdevs, dev); - if (!discdevs) { + if (!discdevs) { LOOP_BREAK(LIBUSB_ERROR_NO_MEM); } @@ -948,7 +948,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs size = sizeof(USB_NODE_INFORMATION); if (!DeviceIoControl(handle, IOCTL_USB_GET_NODE_INFORMATION, &hub_node, size, &hub_node, size, &size, NULL)) { - usbi_warn(ctx, "could not retreive information for hub %s: %s", + usbi_warn(ctx, "could not retreive information for hub %s: %s", priv->path, windows_error_str(0)); continue; } @@ -960,7 +960,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs usbi_dbg("%d ports Hub: %s", hub_node.u.HubInformation.HubDescriptor.bNumberOfPorts, priv->path); - usb_enumerate_hub(ctx, _discdevs, handle, busnum, dev, + usb_enumerate_hub(ctx, _discdevs, handle, busnum, dev, hub_node.u.HubInformation.HubDescriptor.bNumberOfPorts); } } @@ -974,8 +974,8 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs */ static int set_composite_device(struct libusb_context *ctx, DEVINST devinst, struct windows_device_priv *priv) { -// indexes for additional interface GUIDs, not available from "USB" -// SetupDiGetClassDevs enumeration should go here. Typically, these are +// indexes for additional interface GUIDs, not available from "USB" +// SetupDiGetClassDevs enumeration should go here. Typically, these are // device interfaces that begin with something else than "\\?\usb\" enum libusb_hid_report_type { HID_DEVICE_INTERFACE_GUID_INDEX = 0, @@ -1062,7 +1062,7 @@ enum libusb_hid_report_type { { guid = guid_table[j]; - for (i = 0; ; i++) + for (i = 0; ; i++) { safe_free(dev_interface_details); dev_interface_details = get_interface_details(ctx, &dev_info, &dev_info_data, guid, i); @@ -1073,30 +1073,30 @@ enum libusb_hid_report_type { // for an USB path we can recognize if (j == HID_DEVICE_INTERFACE_GUID_INDEX) { if (CM_Get_Parent(&parent_devinst, dev_info_data.DevInst, 0) != CR_SUCCESS) { - usbi_warn(ctx, "could not retrieve HID parent info data for device %s, skipping: %s", + usbi_warn(ctx, "could not retrieve HID parent info data for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } - + if (CM_Get_Device_ID(parent_devinst, path, MAX_PATH_LENGTH, 0) != CR_SUCCESS) { - usbi_warn(ctx, "could not retrieve HID parent's path for device %s, skipping: %s", + usbi_warn(ctx, "could not retrieve HID parent's path for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } } // In case we can't read the driver string through SPDRP_SERVICE (which is - // the case for HID), we need the ClassGUID for comparison. - if(!SetupDiGetDeviceRegistryPropertyW(dev_info, &dev_info_data, SPDRP_CLASSGUID, + // the case for HID), we need the ClassGUID for comparison. + if(!SetupDiGetDeviceRegistryPropertyW(dev_info, &dev_info_data, SPDRP_CLASSGUID, NULL, (BYTE*)guid_string_w, sizeof(guid_string_w), &size)) { - usbi_warn(ctx, "could not read class GUID for device %s, skipping: %s", + usbi_warn(ctx, "could not read class GUID for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } CLSIDFromString(guid_string_w, &class_guid); // Attempt to read the driver string - if(!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_SERVICE, + if(!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_SERVICE, NULL, (BYTE*)driver, MAX_KEY_LENGTH, &size)) { driver[0] = 0; } @@ -1106,7 +1106,7 @@ enum libusb_hid_report_type { || (guid_eq(&class_guid, usb_api_backend[api].class_guid)) ) { api_type[nb_paths] = api; if (j == HID_DEVICE_INTERFACE_GUID_INDEX) { - hid_path[nb_paths] = sanitize_path(path); + hid_path[nb_paths] = sanitize_path(path); } else { hid_path[nb_paths] = NULL; } @@ -1120,7 +1120,7 @@ enum libusb_hid_report_type { } } - // Finally, match the interface paths with the interfaces. We do that + // Finally, match the interface paths with the interfaces. We do that // by looking at the children of the composite device // NB: if the interfaces are not found in their expected position, // claim_interface will issue a warning @@ -1142,7 +1142,7 @@ enum libusb_hid_report_type { r = CM_Get_Device_ID(child_devinst, path, MAX_PATH_LENGTH, 0); if (r != CR_SUCCESS) { - usbi_err(ctx, "could not retrieve simple path for interface %d: CR error %d", + usbi_err(ctx, "could not retrieve simple path for interface %d: CR error %d", i, r); continue; } @@ -1151,7 +1151,7 @@ enum libusb_hid_report_type { usbi_err(ctx, "could not sanitize path for interface %d", i); continue; } - + // Because MI_## are not necessarily in sequential order (some composite HID // devices will have only MI_00 & MI_03 for instance), we retrieve the actual // interface number from the path's MI value @@ -1165,7 +1165,7 @@ enum libusb_hid_report_type { } } if (sanitized_short[j] == 0) { - usbi_warn(ctx, "failure to read interface number for %s. Using default value %d", + usbi_warn(ctx, "failure to read interface number for %s. Using default value %d", sanitized_short, interface_number); } @@ -1174,7 +1174,7 @@ enum libusb_hid_report_type { || (safe_strcmp(hid_path[j], sanitized_short) == 0 ) ) { // HID devices can have multiple collections (COL##) for each MI_## interface if (priv->usb_interface[interface_number].path != NULL) { - usbi_dbg("interface_path[%d] already set - ignoring HID collection: %s", + usbi_dbg("interface_path[%d] already set - ignoring HID collection: %s", interface_number, sanitized_path[j]); if (api_type[j] != USB_API_HID) { usbi_warn(ctx, "program assertion failed - not an HID collection"); @@ -1193,7 +1193,7 @@ enum libusb_hid_report_type { safe_free(sanitized_short); if (priv->usb_interface[interface_number].path == NULL) { - usbi_warn(ctx, "interface_path[%d]: unhandled API - interface will be disabled", + usbi_warn(ctx, "interface_path[%d]: unhandled API - interface will be disabled", interface_number); continue; } @@ -1232,7 +1232,7 @@ static int set_hid_device(struct libusb_context *ctx, struct windows_device_priv interface_number = 0; HidD_GetHidGuid(&guid); - for (i = 0; ; i++) + for (i = 0; ; i++) { // safe loop: free up any (unprotected) dynamic resource safe_free(dev_interface_details); @@ -1246,13 +1246,13 @@ static int set_hid_device(struct libusb_context *ctx, struct windows_device_priv // Retrieve parent's path using PnP Configuration Manager (CM) if (CM_Get_Parent(&parent_devinst, dev_info_data.DevInst, 0) != CR_SUCCESS) { - usbi_warn(ctx, "could not retrieve parent info data for device %s, skipping: %s", + usbi_warn(ctx, "could not retrieve parent info data for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } - + if (CM_Get_Device_ID(parent_devinst, path, MAX_PATH_LENGTH, 0) != CR_SUCCESS) { - usbi_warn(ctx, "could not retrieve parent's path for device %s, skipping: %s", + usbi_warn(ctx, "could not retrieve parent's path for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } @@ -1281,7 +1281,7 @@ static int set_hid_device(struct libusb_context *ctx, struct windows_device_priv * This function retrieves and sets the paths of all non-hub devices * NB: No I/O with device is required during this call */ -static int set_device_paths(struct libusb_context *ctx, struct discovered_devs *discdevs) +static int set_device_paths(struct libusb_context *ctx, struct discovered_devs *discdevs) { struct windows_device_priv *priv; struct windows_device_priv *parent_priv; @@ -1300,8 +1300,8 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * bool found; // TODO (after first official release): MI_## automated driver installation - guid = GUID_DEVINTERFACE_USB_DEVICE; - for (i = 0; ; i++) + guid = GUID_DEVINTERFACE_USB_DEVICE; + for (i = 0; ; i++) { // safe loop: free up any (unprotected) dynamic resource safe_free(dev_interface_details); @@ -1314,35 +1314,35 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * break; // Check that the driver installation is OK - if ( (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_INSTALL_STATE, - ®_type, (BYTE*)&install_state, 4, &size)) + if ( (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_INSTALL_STATE, + ®_type, (BYTE*)&install_state, 4, &size)) && (size != 4) ){ - usbi_warn(ctx, "could not detect installation state of driver for %s: %s", + usbi_warn(ctx, "could not detect installation state of driver for %s: %s", dev_interface_details->DevicePath, windows_error_str(0)); } else if (install_state != 0) { - usbi_warn(ctx, "driver for device %s is reporting an issue (code: %d) - skipping", + usbi_warn(ctx, "driver for device %s is reporting an issue (code: %d) - skipping", dev_interface_details->DevicePath, install_state); continue; } - + // The SPDRP_ADDRESS for USB devices should be the device port number on the hub - if ( (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_ADDRESS, + if ( (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_ADDRESS, ®_type, (BYTE*)&port_nr, 4, &size)) && (size != 4) ){ - usbi_warn(ctx, "could not retrieve port number for device %s, skipping: %s", + usbi_warn(ctx, "could not retrieve port number for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } // Retrieve parent's path using PnP Configuration Manager (CM) if (CM_Get_Parent(&parent_devinst, dev_info_data.DevInst, 0) != CR_SUCCESS) { - usbi_warn(ctx, "could not retrieve parent info data for device %s, skipping: %s", + usbi_warn(ctx, "could not retrieve parent info data for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } - + if (CM_Get_Device_ID(parent_devinst, path, MAX_PATH_LENGTH, 0) != CR_SUCCESS) { - usbi_warn(ctx, "could not retrieve parent's path for device %s, skipping: %s", + usbi_warn(ctx, "could not retrieve parent's path for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; } @@ -1355,7 +1355,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * continue; } - // With the parent path and port number, we should be able to locate our device + // With the parent path and port number, we should be able to locate our device // by comparing these values to the ones we got when enumerating hubs found = false; for (j=0; jlen; j++) { @@ -1368,20 +1368,20 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * parent_priv = __device_priv(priv->parent_dev); // NB: we compare strings of different lengths below => strncmp - if ( (safe_strncmp(parent_priv->path, sanitized_path, strlen(sanitized_path)) == 0) + if ( (safe_strncmp(parent_priv->path, sanitized_path, strlen(sanitized_path)) == 0) && (port_nr == priv->connection_index) ) { priv->path = sanitize_path(dev_interface_details->DevicePath); - usbi_dbg("path (%d:%d): %s", discdevs->devices[j]->bus_number, + usbi_dbg("path (%d:%d): %s", discdevs->devices[j]->bus_number, discdevs->devices[j]->device_address, priv->path); // Check the service name to know what kind of device we have. // The service name is really the driver name without ".sys" ("WinUSB", "HidUsb", ...) // It tells us if we can use WinUSB, if we have a composite device, and the API to use - if(!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_SERVICE, + if(!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_SERVICE, ®_type, (BYTE*)reg_key, MAX_KEY_LENGTH, &size)) { - usbi_err(ctx, "could not retrieve driver information for device %s, skipping: %s", + usbi_err(ctx, "could not retrieve driver information for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); break; } @@ -1400,7 +1400,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * safe_free(priv->hid); priv->hid = calloc(1, sizeof(struct hid_device_priv)); if (priv->hid == NULL) { - usbi_err(ctx, "could not allocate HID data for %s, skipping", + usbi_err(ctx, "could not allocate HID data for %s, skipping", dev_interface_details->DevicePath); priv->apib = &usb_api_backend[USB_API_UNSUPPORTED]; safe_free(priv->path); @@ -1412,7 +1412,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * // For other devices, the first interface is the same as the device priv->usb_interface[0].path = safe_strdup(priv->path); // needs strdup // The following is needed if we want to API calls to work for both simple - // and composite devices, as + // and composite devices, as for(k=0; kusb_interface[k].apib = &usb_api_backend[api]; } @@ -1437,7 +1437,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * */ static int windows_get_device_list(struct libusb_context *ctx, struct discovered_devs **_discdevs) { - struct windows_hcd_priv* hcd; + struct windows_hcd_priv* hcd; HANDLE handle = INVALID_HANDLE_VALUE; int r = LIBUSB_SUCCESS; libusb_bus_t bus; @@ -1493,7 +1493,7 @@ static void windows_exit(void) CloseHandle(semaphore); return; } - + // Only works if exits and inits are balanced exactly if (--concurrent_usage < 0) { // Last exit while (hcd_root != NULL) @@ -1616,9 +1616,9 @@ 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 +/* + * 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." */ static int windows_set_configuration(struct libusb_device_handle *dev_handle, int config) @@ -1629,7 +1629,7 @@ static int windows_set_configuration(struct libusb_device_handle *dev_handle, in if (config >= USB_MAXCONFIG) return LIBUSB_ERROR_INVALID_PARAM; - r = libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_OUT | + r = libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_STANDARD | LIBUSB_RECIPIENT_DEVICE, LIBUSB_REQUEST_SET_CONFIGURATION, (uint16_t)config, 0, NULL, 0, 1000); @@ -1848,7 +1848,7 @@ static int windows_cancel_transfer(struct usbi_transfer *itransfer) } } -static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t io_result, uint32_t io_size) +static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t io_result, uint32_t io_size) { struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev); @@ -1886,7 +1886,7 @@ static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t usbi_handle_transfer_completion(itransfer, status); } -static void windows_handle_callback (struct usbi_transfer *itransfer, uint32_t io_result, uint32_t io_size) +static void windows_handle_callback (struct usbi_transfer *itransfer, uint32_t io_result, uint32_t io_size) { struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); @@ -1921,9 +1921,9 @@ static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, num_ready--; - // Because a Windows OVERLAPPED is used for poll emulation, + // Because a Windows OVERLAPPED is used for poll emulation, // a pollable fd is created and stored with each transfer - usbi_mutex_lock(&ctx->flying_transfers_lock); + usbi_mutex_lock(&ctx->flying_transfers_lock); list_for_each_entry(transfer, &ctx->flying_transfers, list, struct usbi_transfer) { transfer_priv = usbi_transfer_get_os_priv(transfer); if (transfer_priv->pollable_fd.fd == fds[i].fd) { @@ -1931,7 +1931,7 @@ static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, break; } } - usbi_mutex_unlock(&ctx->flying_transfers_lock); + usbi_mutex_unlock(&ctx->flying_transfers_lock); if (found) { // Handle async requests that completed synchronously first @@ -1939,7 +1939,7 @@ static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, io_result = NO_ERROR; io_size = (DWORD)transfer_priv->pollable_fd.overlapped->InternalHigh; // Regular async overlapped - } else if (GetOverlappedResult(transfer_priv->pollable_fd.handle, + } else if (GetOverlappedResult(transfer_priv->pollable_fd.handle, transfer_priv->pollable_fd.overlapped, &io_size, false)) { io_result = NO_ERROR; } else { @@ -1971,12 +1971,12 @@ unsigned __stdcall windows_clock_gettime_threaded(void* param) if (!QueryPerformanceFrequency(&li_frequency)) { usbi_dbg("no hires timer available on this platform"); hires_frequency = 0; - hires_ticks_to_ps = UINT64_C(0); + hires_ticks_to_ps = UINT64_C(0); } else { hires_frequency = li_frequency.QuadPart; // The hires frequency can go as high as 4 GHz, so we'll use a conversion // to picoseconds to compute the tv_nsecs part in clock_gettime - hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency; + hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency; usbi_dbg("hires timer available (Frequency: %"PRIu64" Hz)", hires_frequency); } @@ -2012,7 +2012,7 @@ unsigned __stdcall windows_clock_gettime_threaded(void* param) ReleaseMutex(timer_mutex); nb_responses = InterlockedExchange((LONG*)&request_count[0], 0); - if ( (nb_responses) + if ( (nb_responses) && (ReleaseSemaphore(timer_response, nb_responses, NULL) == 0) ) { usbi_dbg("unable to release timer semaphore %d: %s", windows_error_str(0)); } @@ -2057,7 +2057,7 @@ static int windows_clock_gettime(int clk_id, struct timespec *tp) case USBI_CLOCK_REALTIME: // We follow http://msdn.microsoft.com/en-us/library/ms724928%28VS.85%29.aspx // with a predef epoch_time to have an epoch that starts at 1970.01.01 00:00 - // Note however that our resolution is bounded by the Windows system time + // Note however that our resolution is bounded by the Windows system time // functions and is at best of the order of 1 ms (or, usually, worse) GetSystemTimeAsFileTime(&ftime); rtime.LowPart = ftime.dwLowDateTime; @@ -2251,7 +2251,7 @@ const struct windows_usb_api_backend usb_api_backend[USB_API_MAX] = { hid_abort_transfers, hid_abort_transfers, hid_copy_transfer_data, - }, + }, }; @@ -2263,10 +2263,10 @@ static int winusb_init(struct libusb_context *ctx) DLL_LOAD(winusb.dll, WinUsb_Initialize, TRUE); DLL_LOAD(winusb.dll, WinUsb_Free, TRUE); DLL_LOAD(winusb.dll, WinUsb_GetAssociatedInterface, TRUE); - DLL_LOAD(winusb.dll, WinUsb_GetDescriptor, TRUE); + DLL_LOAD(winusb.dll, WinUsb_GetDescriptor, TRUE); DLL_LOAD(winusb.dll, WinUsb_QueryInterfaceSettings, TRUE); DLL_LOAD(winusb.dll, WinUsb_QueryDeviceInformation, TRUE); - DLL_LOAD(winusb.dll, WinUsb_SetCurrentAlternateSetting, TRUE); + DLL_LOAD(winusb.dll, WinUsb_SetCurrentAlternateSetting, TRUE); DLL_LOAD(winusb.dll, WinUsb_GetCurrentAlternateSetting, TRUE); DLL_LOAD(winusb.dll, WinUsb_QueryPipe, TRUE); DLL_LOAD(winusb.dll, WinUsb_SetPipePolicy, TRUE); @@ -2282,7 +2282,7 @@ static int winusb_init(struct libusb_context *ctx) return LIBUSB_SUCCESS; } -static int winusb_exit(void) +static int winusb_exit(void) { return LIBUSB_SUCCESS; } @@ -2290,7 +2290,7 @@ static int winusb_exit(void) // NB: open and close must ensure that they only handle interface of // the right API type, as these functions can be called wholesale from // composite_open(), with interfaces belonging to different APIs -static int winusb_open(struct libusb_device_handle *dev_handle) +static int winusb_open(struct libusb_device_handle *dev_handle) { struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); struct windows_device_priv *priv = __device_priv(dev_handle->dev); @@ -2303,9 +2303,9 @@ static int winusb_open(struct libusb_device_handle *dev_handle) // WinUSB requires a seperate handle for each interface for (i = 0; i < USB_MAXINTERFACES; i++) { - if ( (priv->usb_interface[i].path != NULL) + if ( (priv->usb_interface[i].path != NULL) && (priv->usb_interface[i].apib->id == USB_API_WINUSB) ) { - file_handle = CreateFileA(priv->usb_interface[i].path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, + file_handle = CreateFileA(priv->usb_interface[i].path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); if (file_handle == INVALID_HANDLE_VALUE) { usbi_err(ctx, "could not open device %s (interface %d): %s", priv->path, i, windows_error_str(0)); @@ -2359,11 +2359,11 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i CHECK_WINUSB_AVAILABLE; - // interfaces for composite devices are always independent, therefore + // interfaces for composite devices are always independent, therefore // "alt" interfaces are only found on non-composite if ((!is_composite) && (iface != 0)) { winusb_handle = handle_priv->interface_handle[0].api_handle; - // It is a requirement on Windows that to claim an interface >= 1 + // It is a requirement on Windows that to claim an interface >= 1 // on a non-composite WinUSB device, you must first have claimed interface 0 if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) { #if defined(AUTO_CLAIM) @@ -2379,7 +2379,7 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i return LIBUSB_ERROR_ACCESS; #endif } - if (!WinUsb_GetAssociatedInterface(winusb_handle, (UCHAR)(iface-1), + if (!WinUsb_GetAssociatedInterface(winusb_handle, (UCHAR)(iface-1), &handle_priv->interface_handle[iface].api_handle)) { handle_priv->interface_handle[iface].api_handle = INVALID_HANDLE_VALUE; switch(GetLastError()) { @@ -2419,14 +2419,14 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i 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", + 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; - // With handle and enpoints set (in parent), we can setup the default + // With handle and enpoints set (in parent), we can setup the default // pipe properties (copied from libusb-win32-v1) // see http://download.microsoft.com/download/D/1/D/D1DD7745-426B-4CC3-A269-ABBBE427C0EF/DVC-T705_DDC08.pptx for (i=0; iusb_interface[iface].nb_endpoints; i++) { @@ -2480,9 +2480,9 @@ static int get_valid_interface(struct libusb_device_handle *dev_handle) int i; for (i=0; iinterface_handle[i].dev_handle != 0) + if ( (handle_priv->interface_handle[i].dev_handle != 0) && (handle_priv->interface_handle[i].dev_handle != INVALID_HANDLE_VALUE) - && (handle_priv->interface_handle[i].api_handle != 0) + && (handle_priv->interface_handle[i].api_handle != 0) && (handle_priv->interface_handle[i].api_handle != INVALID_HANDLE_VALUE)) { return i; } @@ -2493,7 +2493,7 @@ static int get_valid_interface(struct libusb_device_handle *dev_handle) /* * Lookup interface by endpoint address. -1 if not found */ -static int interface_by_endpoint(struct windows_device_priv *priv, +static int interface_by_endpoint(struct windows_device_priv *priv, struct windows_device_handle_priv *handle_priv, uint8_t endpoint_address) { int i, j; @@ -2730,12 +2730,12 @@ static int winusb_abort_transfers(struct usbi_transfer *itransfer) return LIBUSB_SUCCESS; } -/* +/* * from the "How to Use WinUSB to Communicate with a USB Device" Microsoft white paper * (http://www.microsoft.com/whdc/connect/usb/winusb_howto.mspx): * "WinUSB does not support host-initiated reset port and cycle port operations" and * IOCTL_INTERNAL_USB_CYCLE_PORT is only available in kernel mode and the - * IOCTL_USB_HUB_CYCLE_PORT ioctl was removed from Vista => the best we can do is + * IOCTL_USB_HUB_CYCLE_PORT ioctl was removed from Vista => the best we can do is * cycle the pipes (and even then, the control pipe can not be reset using WinUSB) */ // TODO (2nd official release): see if we can force eject the device and redetect it (reuse hotplug?) @@ -2759,23 +2759,23 @@ static int winusb_reset_device(struct libusb_device_handle *dev_handle) usbi_remove_pollfd(ctx, wfd.fd); usbi_free_fd(wfd.fd); wfd = handle_to_winfd(winusb_handle); - } + } if ( (winusb_handle != 0) && (winusb_handle != INVALID_HANDLE_VALUE)) { for (j=0; jusb_interface[i].nb_endpoints; j++) { usbi_dbg("resetting ep %02X", priv->usb_interface[i].endpoint[j]); if (!WinUsb_AbortPipe(winusb_handle, priv->usb_interface[i].endpoint[j])) { - usbi_err(ctx, "WinUsb_AbortPipe (pipe address %02X) failed: %s", + usbi_err(ctx, "WinUsb_AbortPipe (pipe address %02X) failed: %s", priv->usb_interface[i].endpoint[j], windows_error_str(0)); } // FlushPipe seems to fail on OUT pipes - if ( (priv->usb_interface[i].endpoint[j] & LIBUSB_ENDPOINT_IN) + if ( (priv->usb_interface[i].endpoint[j] & LIBUSB_ENDPOINT_IN) && (!WinUsb_FlushPipe(winusb_handle, priv->usb_interface[i].endpoint[j])) ) { - usbi_err(ctx, "WinUsb_FlushPipe (pipe address %02X) failed: %s", + usbi_err(ctx, "WinUsb_FlushPipe (pipe address %02X) failed: %s", priv->usb_interface[i].endpoint[j], windows_error_str(0)); } if (!WinUsb_ResetPipe(winusb_handle, priv->usb_interface[i].endpoint[j])) { - usbi_err(ctx, "WinUsb_ResetPipe (pipe address %02X) failed: %s", + usbi_err(ctx, "WinUsb_ResetPipe (pipe address %02X) failed: %s", priv->usb_interface[i].endpoint[j], windows_error_str(0)); } } @@ -2785,7 +2785,7 @@ static int winusb_reset_device(struct libusb_device_handle *dev_handle) return LIBUSB_SUCCESS; } -static int winusb_copy_transfer_data(struct usbi_transfer *itransfer, uint32_t io_size) +static int winusb_copy_transfer_data(struct usbi_transfer *itransfer, uint32_t io_size) { itransfer->transferred += io_size; return LIBUSB_TRANSFER_COMPLETED; @@ -2849,7 +2849,7 @@ static int _hid_get_config_descriptor(struct hid_device_priv* dev, void *data, s if (dev->output_report_size) num_endpoints++; - config_total_len = LIBUSB_DT_CONFIG_SIZE + LIBUSB_DT_INTERFACE_SIZE + config_total_len = LIBUSB_DT_CONFIG_SIZE + LIBUSB_DT_INTERFACE_SIZE + LIBUSB_DT_HID_SIZE + num_endpoints * LIBUSB_DT_ENDPOINT_SIZE; @@ -2858,7 +2858,7 @@ static int _hid_get_config_descriptor(struct hid_device_priv* dev, void *data, s hd = (struct libusb_hid_descriptor *)(tmp + LIBUSB_DT_CONFIG_SIZE + LIBUSB_DT_INTERFACE_SIZE); ed = (struct libusb_endpoint_descriptor *)(tmp + LIBUSB_DT_CONFIG_SIZE - + LIBUSB_DT_INTERFACE_SIZE + + LIBUSB_DT_INTERFACE_SIZE + LIBUSB_DT_HID_SIZE); cd->bLength = LIBUSB_DT_CONFIG_SIZE; @@ -2997,8 +2997,8 @@ static int _hid_get_report_descriptor(struct hid_device_priv* dev, void *data, s if (dev->input_report_size) { /* usage (vendor defined) */ d[i++] = 0x09; d[i++] = 0x01; - /* logical minimum (0) */ - d[i++] = 0x15; d[i++] = 0x00; + /* logical minimum (0) */ + d[i++] = 0x15; d[i++] = 0x00; /* logical maximum (255) */ d[i++] = 0x25; d[i++] = 0xFF; /* report size (8 bits) */ @@ -3012,8 +3012,8 @@ static int _hid_get_report_descriptor(struct hid_device_priv* dev, void *data, s if (dev->output_report_size) { /* usage (vendor defined) */ d[i++] = 0x09; d[i++] = 0x02; - /* logical minimum (0) */ - d[i++] = 0x15; d[i++] = 0x00; + /* logical minimum (0) */ + d[i++] = 0x15; d[i++] = 0x00; /* logical maximum (255) */ d[i++] = 0x25; d[i++] = 0xFF; /* report size (8 bits) */ @@ -3067,7 +3067,7 @@ static int _hid_get_descriptor(struct hid_device_priv* dev, HANDLE hid_handle, i return LIBUSB_ERROR_INVALID_PARAM; } -static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int id, void *data, +static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int id, void *data, struct windows_transfer_priv *tp, size_t *size, OVERLAPPED* overlapped) { uint8_t *buf; @@ -3090,8 +3090,8 @@ static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int i buf[0] = (uint8_t)id; usbi_dbg("report ID: 0x%02X", buf[0]); // NB: HidD_GetInputReport returns the last Input Report read whereas ReadFile - // waits for input to be generated => in case your HID device requires human - // action to generate a report, it may wait indefinitely. + // waits for input to be generated => in case your HID device requires human + // action to generate a report, it may wait indefinitely. #if !defined(USE_HIDD_FOR_REPORTS) // Use ReadFile instead of HidD_GetInputReport for async I/O tp->hid_expected_size = read_size; // read_size is modified below! @@ -3135,7 +3135,7 @@ static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int i return r; } -static int _hid_set_report(struct hid_device_priv* dev, HANDLE hid_handle, int id, void *data, +static int _hid_set_report(struct hid_device_priv* dev, HANDLE hid_handle, int id, void *data, struct windows_transfer_priv *tp, size_t *size, OVERLAPPED* overlapped) { uint8_t *buf; @@ -3168,13 +3168,13 @@ static int _hid_set_report(struct hid_device_priv* dev, HANDLE hid_handle, int i } tp->hid_buffer = buf; return LIBUSB_SUCCESS; - } + } #else if (!HidD_SetOutputReport(hid_handle, buf, write_size)) { usbi_dbg("Failed to Write HID Output Report: %s", windows_error_str(0)); safe_free(buf); return LIBUSB_ERROR_IO; - } + } #endif // Transfer completed synchronously if (write_size == 0) { @@ -3217,7 +3217,7 @@ static int _hid_get_feature(struct hid_device_priv* dev, HANDLE hid_handle, int case ERROR_INVALID_FUNCTION: r = LIBUSB_ERROR_NOT_FOUND; break; - default: + default: usbi_dbg("error %s", windows_error_str(err)); r = LIBUSB_ERROR_OTHER; break; @@ -3253,7 +3253,7 @@ static int _hid_set_feature(struct hid_device_priv* dev, HANDLE hid_handle, int switch (err) { case ERROR_INVALID_FUNCTION: r = LIBUSB_ERROR_NOT_FOUND; - default: + default: usbi_dbg("error %s", windows_error_str(r)); r = LIBUSB_ERROR_OTHER; } @@ -3263,7 +3263,7 @@ static int _hid_set_feature(struct hid_device_priv* dev, HANDLE hid_handle, int } static int _hid_class_request(struct hid_device_priv* dev, HANDLE hid_handle, int request_type, - int request, int value, int index, void *data, struct windows_transfer_priv *tp, + int request, int value, int index, void *data, struct windows_transfer_priv *tp, size_t *size, OVERLAPPED* overlapped) { int report_type = (value >> 8) & 0xFF; @@ -3273,22 +3273,22 @@ static int _hid_class_request(struct hid_device_priv* dev, HANDLE hid_handle, in return LIBUSB_ERROR_INVALID_PARAM; if (LIBUSB_REQ_OUT(request_type) - && request == HID_REQ_SET_REPORT + && request == HID_REQ_SET_REPORT && report_type == HID_REPORT_TYPE_OUTPUT) return _hid_set_report(dev, hid_handle, report_id, data, tp, size, overlapped); if (LIBUSB_REQ_IN(request_type) - && request == HID_REQ_GET_REPORT + && request == HID_REQ_GET_REPORT && report_type == HID_REPORT_TYPE_INPUT) return _hid_get_report(dev, hid_handle, report_id, data, tp, size, overlapped); if (LIBUSB_REQ_OUT(request_type) - && request == HID_REQ_SET_REPORT + && request == HID_REQ_SET_REPORT && report_type == HID_REPORT_TYPE_FEATURE) return _hid_set_feature(dev, hid_handle, report_id, data, size); if (LIBUSB_REQ_IN(request_type) - && request == HID_REQ_GET_REPORT + && request == HID_REQ_GET_REPORT && report_type == HID_REPORT_TYPE_FEATURE) return _hid_get_feature(dev, hid_handle, report_id, data, size); @@ -3319,10 +3319,10 @@ static int hid_init(struct libusb_context *ctx) DLL_LOAD(hid.dll, HidP_GetValueCaps, TRUE); api_hid_available = true; - return LIBUSB_SUCCESS; + return LIBUSB_SUCCESS; } -static int hid_exit(void) +static int hid_exit(void) { return LIBUSB_SUCCESS; } @@ -3330,7 +3330,7 @@ static int hid_exit(void) // NB: open and close must ensure that they only handle interface of // the right API type, as these functions can be called wholesale from // composite_open(), with interfaces belonging to different APIs -static int hid_open(struct libusb_device_handle *dev_handle) +static int hid_open(struct libusb_device_handle *dev_handle) { struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); struct windows_device_priv *priv = __device_priv(dev_handle->dev); @@ -3352,20 +3352,20 @@ static int hid_open(struct libusb_device_handle *dev_handle) } for (i = 0; i < USB_MAXINTERFACES; i++) { - if ( (priv->usb_interface[i].path != NULL) + if ( (priv->usb_interface[i].path != NULL) && (priv->usb_interface[i].apib->id == USB_API_HID) ) { - hid_handle = CreateFileA(priv->usb_interface[i].path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, + hid_handle = CreateFileA(priv->usb_interface[i].path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); /* * http://www.lvr.com/hidfaq.htm: Why do I receive "Access denied" when attempting to access my HID? - * "Windows 2000 and later have exclusive read/write access to HIDs that are configured as a system - * keyboards or mice. An application can obtain a handle to a system keyboard or mouse by not - * requesting READ or WRITE access with CreateFile. Applications can then use HidD_SetFeature and + * "Windows 2000 and later have exclusive read/write access to HIDs that are configured as a system + * keyboards or mice. An application can obtain a handle to a system keyboard or mouse by not + * requesting READ or WRITE access with CreateFile. Applications can then use HidD_SetFeature and * HidD_GetFeature (if the device supports Feature reports)." */ if (hid_handle == INVALID_HANDLE_VALUE) { usbi_warn(ctx, "could not open HID device in R/W mode (keyboard or mouse?) - trying without"); - hid_handle = CreateFileA(priv->usb_interface[i].path, 0, FILE_SHARE_WRITE | FILE_SHARE_READ, + hid_handle = CreateFileA(priv->usb_interface[i].path, 0, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); if (hid_handle == INVALID_HANDLE_VALUE) { usbi_err(ctx, "could not open device %s (interface %d): %s", priv->path, i, windows_error_str(0)); @@ -3412,7 +3412,7 @@ static int hid_open(struct libusb_device_handle *dev_handle) priv->hid->input_report_id = 0; if (size > 0) { value_caps = malloc(size * sizeof(HIDP_VALUE_CAPS)); - if ( (value_caps != NULL) + if ( (value_caps != NULL) && (HidP_GetValueCaps(HidP_Input, value_caps, &size, preparsed_data) == HIDP_STATUS_SUCCESS) && (size >= 1) ) { priv->hid->input_report_id = value_caps[0].ReportID; @@ -3436,7 +3436,7 @@ static int hid_open(struct libusb_device_handle *dev_handle) priv->hid->output_report_id = 0; if (size > 0) { value_caps = malloc(size * sizeof(HIDP_VALUE_CAPS)); - if ( (value_caps != NULL) + if ( (value_caps != NULL) && (HidP_GetValueCaps(HidP_Output, value_caps, &size, preparsed_data) == HIDP_STATUS_SUCCESS) && (size >= 1) ) { priv->hid->output_report_id = value_caps[0].ReportID; @@ -3459,11 +3459,11 @@ static int hid_open(struct libusb_device_handle *dev_handle) priv->hid->feature_report_size = capabilities.FeatureReportByteLength; // Fetch string descriptors - HidD_GetManufacturerString(hid_handle, priv->hid->man_string, + HidD_GetManufacturerString(hid_handle, priv->hid->man_string, sizeof(priv->hid->man_string)); - HidD_GetProductString(hid_handle, priv->hid->prod_string, + HidD_GetProductString(hid_handle, priv->hid->prod_string, sizeof(priv->hid->prod_string)); - HidD_GetSerialNumberString(hid_handle, priv->hid->ser_string, + HidD_GetSerialNumberString(hid_handle, priv->hid->ser_string, sizeof(priv->hid->ser_string)); } while(0); @@ -3607,7 +3607,7 @@ static int hid_submit_control_transfer(struct usbi_transfer *itransfer) case LIBUSB_REQUEST_TYPE_STANDARD: switch(setup->request) { case LIBUSB_REQUEST_GET_DESCRIPTOR: - r = _hid_get_descriptor(priv->hid, wfd.handle, LIBUSB_REQ_RECIPIENT(setup->request_type), + r = _hid_get_descriptor(priv->hid, wfd.handle, LIBUSB_REQ_RECIPIENT(setup->request_type), (setup->value >> 8) & 0xFF, setup->value & 0xFF, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, &size); break; case LIBUSB_REQUEST_GET_CONFIGURATION: @@ -3658,7 +3658,7 @@ static int hid_submit_control_transfer(struct usbi_transfer *itransfer) // set InternalHigh to the number of bytes transferred wfd.overlapped->InternalHigh = (DWORD)size; r = LIBUSB_SUCCESS; - } + } if (r == LIBUSB_SUCCESS) { // Use priv_transfer to store data needed for async polling @@ -3855,15 +3855,15 @@ static int hid_copy_transfer_data(struct usbi_transfer *itransfer, uint32_t io_s */ static int composite_init(struct libusb_context *ctx) { - return LIBUSB_SUCCESS; + return LIBUSB_SUCCESS; } -static int composite_exit(void) +static int composite_exit(void) { return LIBUSB_SUCCESS; } -static int composite_open(struct libusb_device_handle *dev_handle) +static int composite_open(struct libusb_device_handle *dev_handle) { struct windows_device_priv *priv = __device_priv(dev_handle->dev); unsigned api; @@ -3882,7 +3882,7 @@ static int composite_open(struct libusb_device_handle *dev_handle) return LIBUSB_SUCCESS; } -static void composite_close(struct libusb_device_handle *dev_handle) +static void composite_close(struct libusb_device_handle *dev_handle) { struct windows_device_priv *priv = __device_priv(dev_handle->dev); unsigned api; @@ -3999,7 +3999,7 @@ static int composite_abort_transfers(struct usbi_transfer *itransfer) return priv->usb_interface[transfer_priv->interface_number].apib->abort_transfers(itransfer); } -static int composite_reset_device(struct libusb_device_handle *dev_handle) +static int composite_reset_device(struct libusb_device_handle *dev_handle) { struct windows_device_priv *priv = __device_priv(dev_handle->dev); unsigned api; diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h index 6a54d7e..330b7bb 100644 --- a/libusb/os/windows_usb.h +++ b/libusb/os/windows_usb.h @@ -188,7 +188,7 @@ struct libusb_hid_descriptor { #define LIBUSB_DT_HID_SIZE 9 #define HID_MAX_CONFIG_DESC_SIZE (LIBUSB_DT_CONFIG_SIZE + LIBUSB_DT_INTERFACE_SIZE \ + LIBUSB_DT_HID_SIZE + 2 * LIBUSB_DT_ENDPOINT_SIZE) -#define HID_MAX_REPORT_SIZE 1024 +#define HID_MAX_REPORT_SIZE 1024 #define HID_IN_EP 0x81 #define HID_OUT_EP 0x02 #define LIBUSB_REQ_RECIPIENT(request_type) ((request_type) & 0x1F) @@ -236,7 +236,7 @@ struct windows_device_priv { char *path; // each interface needs a Windows device interface path, struct windows_usb_api_backend const *apib; // an API backend (multiple drivers support), int8_t nb_endpoints; // and a set of endpoint addresses (USB_MAXENDPOINTS) - uint8_t *endpoint; + uint8_t *endpoint; } usb_interface[USB_MAXINTERFACES]; uint8_t composite_api_flags; // HID and composite devices require additional data struct hid_device_priv *hid; @@ -449,7 +449,7 @@ DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDW, (DEVINST, PWCHAR, ULONG, ULONG // Most of the structures below need to be packed #pragma pack(push, 1) -typedef struct _USB_INTERFACE_DESCRIPTOR { +typedef struct _USB_INTERFACE_DESCRIPTOR { UCHAR bLength; UCHAR bDescriptorType; UCHAR bInterfaceNumber; @@ -461,7 +461,7 @@ typedef struct _USB_INTERFACE_DESCRIPTOR { UCHAR iInterface; } USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR; -typedef struct _USB_CONFIGURATION_DESCRIPTOR { +typedef struct _USB_CONFIGURATION_DESCRIPTOR { UCHAR bLength; UCHAR bDescriptorType; USHORT wTotalLength; @@ -486,7 +486,7 @@ typedef struct _USB_CONFIGURATION_DESCRIPTOR_SHORT { USB_CONFIGURATION_DESCRIPTOR data; } USB_CONFIGURATION_DESCRIPTOR_SHORT; -typedef struct _USB_ENDPOINT_DESCRIPTOR { +typedef struct _USB_ENDPOINT_DESCRIPTOR { UCHAR bLength; UCHAR bDescriptorType; UCHAR bEndpointAddress; @@ -619,7 +619,7 @@ typedef struct _USB_HUB_CAPABILITIES_EX { #define DEVICE_SPEED 0x01 #define LowSpeed 0x01 #define FullSpeed 0x02 -#define HighSpeed 0x03 +#define HighSpeed 0x03 typedef enum _USBD_PIPE_TYPE { UsbdPipeTypeControl, @@ -672,7 +672,7 @@ typedef void* PHIDP_PREPARSED_DATA; #pragma pack(1) typedef struct { - ULONG Size; + ULONG Size; USHORT VendorID; USHORT ProductID; USHORT VersionNumber; -- cgit v1.2.1