Skip to content

Commit

Permalink
[Code] Adding IAD support for WinUSB
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoussin committed Feb 3, 2016
1 parent c7cad7e commit 4ce43f9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
33 changes: 27 additions & 6 deletions src/qwinusb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/qwinusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 4ce43f9

Please sign in to comment.