diff --git a/libusbK/src/lusbk_bknd_libusb0.c b/libusbK/src/lusbk_bknd_libusb0.c index 57333bd..775be76 100644 --- a/libusbK/src/lusbk_bknd_libusb0.c +++ b/libusbK/src/lusbk_bknd_libusb0.c @@ -50,12 +50,10 @@ KUSB_EXP BOOL KUSB_API LUsb0_ControlTransfer( int ret; PKUSB_HANDLE_INTERNAL handle; - UNUSED(Overlapped); - Pub_To_Priv_UsbK(InterfaceHandle, handle, return FALSE); ErrorSetAction(!PoolHandle_Inc_UsbK(handle), ERROR_RESOURCE_NOT_AVAILABLE, return FALSE, "->PoolHandle_Inc_UsbK"); - ret = usb_control_msg(Dev_Handle(), SetupPacket.RequestType, SetupPacket.Request, SetupPacket.Value, SetupPacket.Index, Buffer, BufferLength, LIBUSB_DEFAULT_TIMEOUT); + ret = usb_control_msg(Dev_Handle(), SetupPacket.RequestType, SetupPacket.Request, SetupPacket.Value, SetupPacket.Index, Buffer, BufferLength, LIBUSB_DEFAULT_TIMEOUT, Overlapped); if (ret >= 0) { @@ -119,7 +117,7 @@ int usb_set_configuration(HANDLE *dev, int configuration) req.timeout = LIBUSB_DEFAULT_TIMEOUT; if (!_usb_io_sync(dev, LIBUSB_IOCTL_SET_CONFIGURATION, - &req, sizeof(libusb_request), NULL, 0, NULL)) + &req, sizeof(libusb_request), NULL, 0, NULL, NULL)) { USBERR("could not set config %d: ", configuration); return FALSE; @@ -130,7 +128,8 @@ int usb_set_configuration(HANDLE *dev, int configuration) // See libusb-win32 windows.c:671-815 int usb_control_msg(HANDLE *dev, int requesttype, int request, - int value, int index, PUCHAR bytes, int size, int timeout) + int value, int index, PUCHAR bytes, int size, int timeout, + LPOVERLAPPED Overlapped) { int read = 0; libusb_request req; @@ -255,7 +254,8 @@ int usb_control_msg(HANDLE *dev, int requesttype, int request, in_size = 0; } - if (!_usb_io_sync(dev, code, out, out_size, in, in_size, &read)) + if (!_usb_io_sync(dev, code, out, out_size, in, in_size, &read, + Overlapped)) { USBERR("sending control message failed"); if (!(requesttype & USB_ENDPOINT_IN)) @@ -276,9 +276,10 @@ int usb_control_msg(HANDLE *dev, int requesttype, int request, } int _usb_io_sync(HANDLE dev, unsigned int code, void *out, int out_size, - void *in, int in_size, int *ret) + void *in, int in_size, int *ret, LPOVERLAPPED Overlapped) { OVERLAPPED ol; + OVERLAPPED *olp; DWORD _ret; memset(&ol, 0, sizeof(ol)); @@ -286,28 +287,42 @@ int _usb_io_sync(HANDLE dev, unsigned int code, void *out, int out_size, if (ret) *ret = 0; - ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!Overlapped) + { + ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (!ol.hEvent) - return FALSE; + if (!ol.hEvent) + return FALSE; + + olp = &ol; + } + else + { + olp = Overlapped; + } - if (!DeviceIoControl(dev, code, out, out_size, in, in_size, NULL, &ol)) + if (!DeviceIoControl(dev, code, out, out_size, in, in_size, NULL, olp)) { if (GetLastError() != ERROR_IO_PENDING) { - CloseHandle(ol.hEvent); + USBERR("DeviceIoControl failed"); + if (!Overlapped) + CloseHandle(ol.hEvent); return FALSE; } } - if (GetOverlappedResult(dev, &ol, &_ret, TRUE)) + if (GetOverlappedResult(dev, olp, &_ret, TRUE)) { if (ret) *ret = (int)_ret; - CloseHandle(ol.hEvent); + if (!Overlapped) + CloseHandle(ol.hEvent); return TRUE; } - CloseHandle(ol.hEvent); + USBERR("GetOverlappedResult failed"); + if (!Overlapped) + CloseHandle(ol.hEvent); return FALSE; -} \ No newline at end of file +} diff --git a/libusbK/src/lusbk_bknd_libusb0.h b/libusbK/src/lusbk_bknd_libusb0.h index 441f293..34a96f6 100644 --- a/libusbK/src/lusbk_bknd_libusb0.h +++ b/libusbK/src/lusbk_bknd_libusb0.h @@ -27,9 +27,10 @@ binary distributions. #endif int _usb_io_sync(HANDLE dev, unsigned int code, void *out, int out_size, - void *in, int in_size, int *ret); + void *in, int in_size, int *ret, LPOVERLAPPED Overlapped); int usb_control_msg(HANDLE *dev, int requesttype, int request, - int value, int index, PUCHAR bytes, int size, int timeout); + int value, int index, PUCHAR bytes, int size, int timeout, + LPOVERLAPPED Overlapped); -int usb_set_configuration(HANDLE *dev, int configuration); \ No newline at end of file +int usb_set_configuration(HANDLE *dev, int configuration);