From 4ce43f9c6131c83cb8ff3dd43d3a3f43ae80791e Mon Sep 17 00:00:00 2001 From: Fabien Poussin Date: Wed, 3 Feb 2016 22:10:40 +0100 Subject: [PATCH] [Code] Adding IAD support for WinUSB --- src/qwinusb.cpp | 33 +++++++++++++++++++++++++++------ src/qwinusb.h | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/qwinusb.cpp b/src/qwinusb.cpp index f4ed023..741f1b9 100755 --- a/src/qwinusb.cpp +++ b/src/qwinusb.cpp @@ -131,7 +131,7 @@ qint32 QUsbDevice::open() return -1; if (!getDeviceHandle(mGuid, &mDevHandle)) return -1; - else if (!getWinUSBHandle(mDevHandle, &mUsbHandle)) return -2; + else if (!getWinUSBHandle(mDevHandle, &mUsbHandle, mConfig.interface)) return -2; else if (!getUSBDeviceSpeed(mUsbHandle, &mDevSpeed)) return -3; else if (!queryDeviceEndpoints(mUsbHandle, &mPipeId)) return -4; @@ -376,7 +376,7 @@ bool QUsbDevice::getDeviceHandle(GUID guidDeviceInterface, PHANDLE hDeviceHandle return bResult; } -bool QUsbDevice::getWinUSBHandle(HANDLE hDeviceHandle, PWINUSB_INTERFACE_HANDLE phWinUSBHandle) +bool QUsbDevice::getWinUSBHandle(HANDLE hDeviceHandle, PWINUSB_INTERFACE_HANDLE phWinUSBHandle, UCHAR interface) { UsbPrintFuncName(); if (hDeviceHandle == INVALID_HANDLE_VALUE) @@ -385,12 +385,27 @@ bool QUsbDevice::getWinUSBHandle(HANDLE hDeviceHandle, PWINUSB_INTERFACE_HANDLE return false; } - if(!WinUsb_Initialize(hDeviceHandle, phWinUSBHandle)) + PWINUSB_INTERFACE_HANDLE tempHandlePtr = phWinUSBHandle; + if(!WinUsb_Initialize(hDeviceHandle, tempHandlePtr)) { - //Error. printUsbError("WinUsb_Initialize"); return false; } + qDebug() << "interface" << interface; + if (interface > 0) + { + interface -= 1; + qDebug() << "interface" << interface; + if(!WinUsb_GetAssociatedInterface(*tempHandlePtr, interface, phWinUSBHandle)) + { + printUsbError("WinUsb_GetAssociatedInterface"); + return false; + } + } + else + { + phWinUSBHandle = tempHandlePtr; + } return true; } @@ -459,13 +474,19 @@ bool QUsbDevice::queryDeviceEndpoints(WINUSB_INTERFACE_HANDLE hWinUSBHandle, QUs WINUSB_PIPE_INFORMATION pipe; ZeroMemory(&pipe, sizeof(WINUSB_PIPE_INFORMATION)); - bResult = WinUsb_QueryInterfaceSettings(hWinUSBHandle, mConfig.interface, &InterfaceDescriptor); + UCHAR interface = mConfig.interface; + if (interface > 0) + { + interface -= 1; + } + + bResult = WinUsb_QueryInterfaceSettings(hWinUSBHandle, interface, &InterfaceDescriptor); if (bResult) { for (int index = 0; index < InterfaceDescriptor.bNumEndpoints; index++) { - bResult = WinUsb_QueryPipe(hWinUSBHandle, mConfig.interface, index, &pipe); + bResult = WinUsb_QueryPipe(hWinUSBHandle, interface, index, &pipe); if (bResult) { diff --git a/src/qwinusb.h b/src/qwinusb.h index d8ebb0d..cd4926f 100755 --- a/src/qwinusb.h +++ b/src/qwinusb.h @@ -139,7 +139,7 @@ public slots: * @param phWinUSBHandle * @return bool */ - bool getWinUSBHandle(HANDLE hDeviceHandle, PWINUSB_INTERFACE_HANDLE phWinUSBHandle); + bool getWinUSBHandle(HANDLE hDeviceHandle, PWINUSB_INTERFACE_HANDLE phWinUSBHandle, UCHAR interface); /** * @brief *