Skip to content

Commit

Permalink
UsbDk: Introduce UsbDk_ResetPipe() user mode API
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
  • Loading branch information
Dmitry Fleytman committed May 3, 2015
1 parent c0fd0b9 commit 2981425
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions UsbDk/Public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 8 additions & 0 deletions UsbDk/RedirectorStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ULONG64>(WdfRequest,
[this, Request](ULONG64 *endpointAddress, size_t)
{return m_Target.ResetPipe(Request, *endpointAddress); });
return;
}
case IOCTL_USBDK_DEVICE_SET_ALTSETTING:
{
ASSERT(m_IncomingRWQueue);
Expand Down
14 changes: 14 additions & 0 deletions UsbDk/UsbTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions UsbDk/UsbTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class CWdfUsbTarget
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:
Expand Down
5 changes: 5 additions & 0 deletions UsbDkHelper/RedirectorAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions UsbDkHelper/RedirectorAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class UsbDkRedirectorAccess : public UsbDkDriverFile
}

void AbortPipe(ULONG64 PipeAddress);
void ResetPipe(ULONG64 PipeAddress);
void SetAltsetting(ULONG64 InterfaceIdx, ULONG64 AltSettingIdx);
void ResetDevice();

Expand Down
15 changes: 15 additions & 0 deletions UsbDkHelper/UsbDkHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ BOOL UsbDk_AbortPipe(HANDLE DeviceHandle, ULONG64 PipeAddress)
}
}

BOOL UsbDk_ResetPipe(HANDLE DeviceHandle, ULONG64 PipeAddress)
{
try
{
auto deviceHandle = reinterpret_cast<PREDIRECTED_DEVICE_HANDLE>(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
Expand Down
13 changes: 13 additions & 0 deletions UsbDkHelper/UsbDkHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2981425

Please sign in to comment.