From 29814251f4579876b290491697e7108346d6b628 Mon Sep 17 00:00:00 2001 From: Dmitry Fleytman Date: Sun, 3 May 2015 10:36:23 +0300 Subject: UsbDk: Introduce UsbDk_ResetPipe() user mode API Signed-off-by: Dmitry Fleytman --- UsbDk/Public.h | 2 ++ UsbDk/RedirectorStrategy.cpp | 8 ++++++++ UsbDk/UsbTarget.cpp | 14 ++++++++++++++ UsbDk/UsbTarget.h | 1 + UsbDkHelper/RedirectorAccess.cpp | 5 +++++ UsbDkHelper/RedirectorAccess.h | 1 + UsbDkHelper/UsbDkHelper.cpp | 15 +++++++++++++++ UsbDkHelper/UsbDkHelper.h | 13 +++++++++++++ 8 files changed, 59 insertions(+) diff --git a/UsbDk/Public.h b/UsbDk/Public.h index 488d57c..6729410 100644 --- a/UsbDk/Public.h +++ b/UsbDk/Public.h @@ -57,6 +57,8 @@ ULONG(CTL_CODE( USBDK_DEVICE_TYPE, 0x953, METHOD_BUFFERED, FILE_WRITE_ACCESS )) #define IOCTL_USBDK_DEVICE_RESET_DEVICE \ ULONG(CTL_CODE( USBDK_DEVICE_TYPE, 0x954, METHOD_BUFFERED, FILE_WRITE_ACCESS )) +#define IOCTL_USBDK_DEVICE_RESET_PIPE \ + ULONG(CTL_CODE( USBDK_DEVICE_TYPE, 0x955, METHOD_BUFFERED, FILE_WRITE_ACCESS )) typedef struct tag_USBDK_ALTSETTINGS_IDXS { diff --git a/UsbDk/RedirectorStrategy.cpp b/UsbDk/RedirectorStrategy.cpp index a532cc0..57ab629 100644 --- a/UsbDk/RedirectorStrategy.cpp +++ b/UsbDk/RedirectorStrategy.cpp @@ -518,6 +518,14 @@ void CUsbDkRedirectorStrategy::IoDeviceControl(WDFREQUEST Request, {return m_Target.AbortPipe(Request, *endpointAddress); }); return; } + case IOCTL_USBDK_DEVICE_RESET_PIPE: + { + CWdfRequest WdfRequest(Request); + UsbDkHandleRequestWithInput(WdfRequest, + [this, Request](ULONG64 *endpointAddress, size_t) + {return m_Target.ResetPipe(Request, *endpointAddress); }); + return; + } case IOCTL_USBDK_DEVICE_SET_ALTSETTING: { ASSERT(m_IncomingRWQueue); diff --git a/UsbDk/UsbTarget.cpp b/UsbDk/UsbTarget.cpp index 982219c..a2d291f 100644 --- a/UsbDk/UsbTarget.cpp +++ b/UsbDk/UsbTarget.cpp @@ -390,6 +390,20 @@ NTSTATUS CWdfUsbTarget::AbortPipe(WDFREQUEST Request, ULONG64 EndpointAddress) } } +NTSTATUS CWdfUsbTarget::ResetPipe(WDFREQUEST Request, ULONG64 EndpointAddress) +{ + auto Pipe = FindPipeByEndpointAddress(EndpointAddress); + if (Pipe != nullptr) + { + return Pipe->Reset(Request); + } + else + { + TraceEvents(TRACE_LEVEL_ERROR, TRACE_USBTARGET, "%!FUNC! Failed: Pipe not found"); + return STATUS_NOT_FOUND; + } +} + NTSTATUS CWdfUsbTarget::ResetDevice(WDFREQUEST Request) { NTSTATUS status = STATUS_SUCCESS; diff --git a/UsbDk/UsbTarget.h b/UsbDk/UsbTarget.h index d5c665c..f75a02e 100644 --- a/UsbDk/UsbTarget.h +++ b/UsbDk/UsbTarget.h @@ -125,6 +125,7 @@ public: NTSTATUS ControlTransferAsync(CWdfRequest &WdfRequest, PWDF_USB_CONTROL_SETUP_PACKET SetupPacket, WDFMEMORY Data, PWDFMEMORY_OFFSET TransferOffset, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion); NTSTATUS AbortPipe(WDFREQUEST Request, ULONG64 EndpointAddress); + NTSTATUS ResetPipe(WDFREQUEST Request, ULONG64 EndpointAddress); NTSTATUS ResetDevice(WDFREQUEST Request); private: diff --git a/UsbDkHelper/RedirectorAccess.cpp b/UsbDkHelper/RedirectorAccess.cpp index e4dafee..0182255 100644 --- a/UsbDkHelper/RedirectorAccess.cpp +++ b/UsbDkHelper/RedirectorAccess.cpp @@ -30,6 +30,11 @@ void UsbDkRedirectorAccess::AbortPipe(ULONG64 PipeAddress) IoctlSync(IOCTL_USBDK_DEVICE_ABORT_PIPE, false, &PipeAddress, sizeof(PipeAddress)); } +void UsbDkRedirectorAccess::ResetPipe(ULONG64 PipeAddress) +{ + IoctlSync(IOCTL_USBDK_DEVICE_RESET_PIPE, false, &PipeAddress, sizeof(PipeAddress)); +} + void UsbDkRedirectorAccess::SetAltsetting(ULONG64 InterfaceIdx, ULONG64 AltSettingIdx) { USBDK_ALTSETTINGS_IDXS AltSetting; diff --git a/UsbDkHelper/RedirectorAccess.h b/UsbDkHelper/RedirectorAccess.h index 283ec6c..c8f1b2e 100644 --- a/UsbDkHelper/RedirectorAccess.h +++ b/UsbDkHelper/RedirectorAccess.h @@ -58,6 +58,7 @@ public: } void AbortPipe(ULONG64 PipeAddress); + void ResetPipe(ULONG64 PipeAddress); void SetAltsetting(ULONG64 InterfaceIdx, ULONG64 AltSettingIdx); void ResetDevice(); diff --git a/UsbDkHelper/UsbDkHelper.cpp b/UsbDkHelper/UsbDkHelper.cpp index 41b1d00..d0eadbc 100644 --- a/UsbDkHelper/UsbDkHelper.cpp +++ b/UsbDkHelper/UsbDkHelper.cpp @@ -213,6 +213,21 @@ BOOL UsbDk_AbortPipe(HANDLE DeviceHandle, ULONG64 PipeAddress) } } +BOOL UsbDk_ResetPipe(HANDLE DeviceHandle, ULONG64 PipeAddress) +{ + try + { + auto deviceHandle = reinterpret_cast(DeviceHandle); + deviceHandle->RedirectorAccess->ResetPipe(PipeAddress); + return TRUE; + } + catch (const exception &e) + { + printExceptionString(e.what()); + return FALSE; + } +} + BOOL UsbDk_SetAltsetting(HANDLE DeviceHandle, ULONG64 InterfaceIdx, ULONG64 AltSettingIdx) { try diff --git a/UsbDkHelper/UsbDkHelper.h b/UsbDkHelper/UsbDkHelper.h index 5a640ed..dd9ac54 100644 --- a/UsbDkHelper/UsbDkHelper.h +++ b/UsbDkHelper/UsbDkHelper.h @@ -198,6 +198,19 @@ extern "C" { */ DLL BOOL UsbDk_AbortPipe(HANDLE DeviceHandle, ULONG64 PipeAddress); + /* Issue an USB reset pipe request + * + * @params + * IN - DeviceHandle - handle of target USB device + * - PipeAddress - address of pipe to be reset + * OUT - None + * + * @return + * TRUE if function succeeds + * + */ + DLL BOOL UsbDk_ResetPipe(HANDLE DeviceHandle, ULONG64 PipeAddress); + /* Set active alternative settings for USB device * * @params -- cgit v1.2.3