diff options
-rw-r--r-- | libusb/os/windows_usb.c | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index e9cb175..26907b5 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -171,6 +171,7 @@ static char* guid_to_string(const GUID* guid) * Converts a windows error to human readable string * uses retval as errorcode, or, if 0, use GetLastError() */ +#if defined(ENABLE_LOGGING) static char *windows_error_str(uint32_t retval) { static char err_string[ERR_BUFFER_SIZE]; @@ -201,6 +202,7 @@ static char err_string[ERR_BUFFER_SIZE]; } return err_string; } +#endif /* * Sanitize Microsoft's paths: convert to uppercase, add prefix and fix backslashes. @@ -589,11 +591,13 @@ static unsigned long get_ancestor_session_id(DWORD devinst, unsigned level) */ static int windows_assign_endpoints(struct libusb_device_handle *dev_handle, int iface, int altsetting) { +#if defined(ENABLE_LOGGING) + struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); +#endif int i, r; struct windows_device_priv *priv = __device_priv(dev_handle->dev); struct libusb_config_descriptor *conf_desc; const struct libusb_interface_descriptor *if_desc; - struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); r = libusb_get_config_descriptor(dev_handle->dev, 0, &conf_desc); if (r != LIBUSB_SUCCESS) { @@ -661,7 +665,9 @@ static bool is_api_driver(char* driver, uint8_t api) #if defined(AUTO_CLAIM) static int auto_claim(struct libusb_transfer *transfer, int *interface_number, int api_type) { +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv( transfer->dev_handle); struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev); @@ -876,8 +882,10 @@ init_exit: // Holds semaphore here. */ static int force_hcd_device_descriptor(struct libusb_device *dev) { - struct windows_device_priv *parent_priv, *priv = __device_priv(dev); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev); +#endif + struct windows_device_priv *parent_priv, *priv = __device_priv(dev); int vid, pid; dev->num_configurations = 1; @@ -907,8 +915,10 @@ static int force_hcd_device_descriptor(struct libusb_device *dev) */ static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle, char* device_id) { - DWORD size, ret_size; +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev); +#endif + DWORD size, ret_size; struct windows_device_priv *priv = __device_priv(dev); int r; uint8_t i; @@ -1085,7 +1095,7 @@ static int init_device(struct libusb_device* dev, struct libusb_device* parent_d default: usbi_warn(ctx, "Got unknown device speed %d", conn_info.Speed); break; - } + } memcpy(&priv->dev_descriptor, &(conn_info.DeviceDescriptor), sizeof(USB_DEVICE_DESCRIPTOR)); dev->num_configurations = priv->dev_descriptor.bNumConfigurations; priv->active_config = conn_info.CurrentConfigurationValue; @@ -1215,7 +1225,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered { struct discovered_devs *discdevs = *_discdevs; HDEVINFO dev_info = { 0 }; - char* usb_class[2] = {"USB", "NUSB3"}; + char* usb_class[2] = {"USB", "NUSB3"}; SP_DEVINFO_DATA dev_info_data; SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL; #define MAX_ENUM_GUIDS 64 @@ -1319,7 +1329,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered } else { // Workaround for a Nec/Renesas USB 3.0 driver bug where root hubs are // being listed under the "NUSB3" PnP Symbolic Name rather than "USB" - while ( (class_index < 2) && + while ( (class_index < 2) && (!(b = get_devinfo_data(ctx, &dev_info, &dev_info_data, usb_class[class_index], i))) ) { class_index++; i = 0; @@ -1658,8 +1668,10 @@ static int windows_get_active_config_descriptor(struct libusb_device *dev, unsig static int windows_open(struct libusb_device_handle *dev_handle) { - struct windows_device_priv *priv = __device_priv(dev_handle->dev); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); +#endif + struct windows_device_priv *priv = __device_priv(dev_handle->dev); if (priv->apib == NULL) { usbi_err(ctx, "program assertion failed - device is not initialized"); @@ -2378,7 +2390,9 @@ static int winusb_exit(void) // composite_open(), with interfaces belonging to different APIs static int winusb_open(struct libusb_device_handle *dev_handle) { +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); +#endif struct windows_device_priv *priv = __device_priv(dev_handle->dev); struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle); @@ -2477,7 +2491,9 @@ static int winusb_configure_endpoints(struct libusb_device_handle *dev_handle, i static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int iface) { +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle); struct windows_device_priv *priv = __device_priv(dev_handle->dev); bool is_using_usbccgp = (priv->apib->id == USB_API_COMPOSITE); @@ -2612,7 +2628,9 @@ static int interface_by_endpoint(struct windows_device_priv *priv, static int winusb_submit_control_transfer(struct usbi_transfer *itransfer) { struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); +#endif struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev); struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer); struct windows_device_handle_priv *handle_priv = __device_handle_priv( @@ -2684,7 +2702,9 @@ static int winusb_submit_control_transfer(struct usbi_transfer *itransfer) static int winusb_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting) { +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle); HANDLE winusb_handle; @@ -2711,7 +2731,9 @@ static int winusb_set_interface_altsetting(struct libusb_device_handle *dev_hand static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer) { struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); +#endif struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer); struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle); struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev); @@ -2767,7 +2789,9 @@ static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer) static int winusb_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint) { +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle); struct windows_device_priv *priv = __device_priv(dev_handle->dev); HANDLE winusb_handle; @@ -2807,7 +2831,9 @@ static int winusb_abort_control(struct usbi_transfer *itransfer) static int winusb_abort_transfers(struct usbi_transfer *itransfer) { struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle); struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer); HANDLE winusb_handle; @@ -2961,7 +2987,9 @@ static int composite_release_interface(struct libusb_device_handle *dev_handle, static int composite_submit_control_transfer(struct usbi_transfer *itransfer) { struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); +#endif struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev); int i; @@ -2976,9 +3004,12 @@ static int composite_submit_control_transfer(struct usbi_transfer *itransfer) return LIBUSB_ERROR_NOT_FOUND; } -static int composite_submit_bulk_transfer(struct usbi_transfer *itransfer) { +static int composite_submit_bulk_transfer(struct usbi_transfer *itransfer) +{ struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle); struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev); int current_interface; @@ -2992,9 +3023,12 @@ static int composite_submit_bulk_transfer(struct usbi_transfer *itransfer) { return priv->usb_interface[current_interface].apib->submit_bulk_transfer(itransfer); } -static int composite_submit_iso_transfer(struct usbi_transfer *itransfer) { +static int composite_submit_iso_transfer(struct usbi_transfer *itransfer) +{ struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle); struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev); int current_interface; @@ -3010,7 +3044,9 @@ static int composite_submit_iso_transfer(struct usbi_transfer *itransfer) { static int composite_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint) { +#if defined(ENABLE_LOGGING) struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev); +#endif struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle); struct windows_device_priv *priv = __device_priv(dev_handle->dev); int current_interface; |