Skip to content

Commit

Permalink
UsbTarget: Introduce TargetRequest class
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Fleytman <[email protected]>
  • Loading branch information
Dmitry Fleytman committed Feb 10, 2016
1 parent 603d98e commit 3d0a205
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
11 changes: 6 additions & 5 deletions UsbDk/RedirectorStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ NTSTATUS CUsbDkRedirectorStrategy::PNPPreProcess(PIRP Irp)
}
}

typedef struct tag_USBDK_REDIRECTOR_REQUEST_CONTEXT
using USBDK_REDIRECTOR_REQUEST_CONTEXT = struct : public USBDK_TARGET_REQUEST_CONTEXT
{
bool PreprocessingDone;

Expand All @@ -189,17 +189,18 @@ typedef struct tag_USBDK_REDIRECTOR_REQUEST_CONTEXT

WDFMEMORY LockedIsochronousPacketsArray;
WDFMEMORY LockedIsochronousResultsArray;
} USBDK_REDIRECTOR_REQUEST_CONTEXT, *PUSBDK_REDIRECTOR_REQUEST_CONTEXT;
};
using PUSBDK_REDIRECTOR_REQUEST_CONTEXT = USBDK_REDIRECTOR_REQUEST_CONTEXT*;

class CRedirectorRequest : public CWdfRequest
class CRedirectorRequest : public CTargetRequest
{
public:
explicit CRedirectorRequest(WDFREQUEST Request)
: CWdfRequest(Request)
: CTargetRequest(Request)
{}

PUSBDK_REDIRECTOR_REQUEST_CONTEXT Context() const
{ return reinterpret_cast<PUSBDK_REDIRECTOR_REQUEST_CONTEXT>(CWdfRequest::Context()); }
{ return static_cast<PUSBDK_REDIRECTOR_REQUEST_CONTEXT>(CTargetRequest::Context()); }

private:
void SetBytesWritten(size_t numBytes);
Expand Down
16 changes: 8 additions & 8 deletions UsbDk/UsbTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void CWdfUsbPipe::Create(WDFUSBDEVICE Device, WDFUSBINTERFACE Interface, UCHAR P
m_Info.Interval);
}

void CWdfUsbPipe::ReadAsync(CWdfRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
void CWdfUsbPipe::ReadAsync(CTargetRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
{
auto status = WdfUsbTargetPipeFormatRequestForRead(m_Pipe, Request, Buffer, nullptr);
if (!NT_SUCCESS(status))
Expand All @@ -147,7 +147,7 @@ void CWdfUsbPipe::ReadAsync(CWdfRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQU
}
}

void CWdfUsbPipe::WriteAsync(CWdfRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
void CWdfUsbPipe::WriteAsync(CTargetRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
{
auto status = WdfUsbTargetPipeFormatRequestForWrite(m_Pipe, Request, Buffer, nullptr);
if (!NT_SUCCESS(status))
Expand All @@ -165,7 +165,7 @@ void CWdfUsbPipe::WriteAsync(CWdfRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQ
}
}

void CWdfUsbPipe::SubmitIsochronousTransfer(CWdfRequest &Request,
void CWdfUsbPipe::SubmitIsochronousTransfer(CTargetRequest &Request,
CIsochronousUrb::Direction Direction,
WDFMEMORY Buffer,
PULONG64 PacketSizes,
Expand Down Expand Up @@ -305,7 +305,7 @@ NTSTATUS CWdfUsbTarget::SetInterfaceAltSetting(ULONG64 InterfaceIdx, ULONG64 Alt

void CWdfUsbTarget::WritePipeAsync(WDFREQUEST Request, ULONG64 EndpointAddress, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
{
CWdfRequest WdfRequest(Request);
CTargetRequest WdfRequest(Request);

if (!DoPipeOperation<CWdfUsbInterface::SharedLock>(EndpointAddress,
[&WdfRequest, Buffer, Completion](CWdfUsbPipe &Pipe)
Expand All @@ -320,7 +320,7 @@ void CWdfUsbTarget::WritePipeAsync(WDFREQUEST Request, ULONG64 EndpointAddress,

void CWdfUsbTarget::ReadPipeAsync(WDFREQUEST Request, ULONG64 EndpointAddress, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
{
CWdfRequest WdfRequest(Request);
CTargetRequest WdfRequest(Request);

if (!DoPipeOperation<CWdfUsbInterface::SharedLock>(EndpointAddress,
[&WdfRequest, Buffer, Completion](CWdfUsbPipe &Pipe)
Expand All @@ -337,7 +337,7 @@ void CWdfUsbTarget::ReadIsochronousPipeAsync(WDFREQUEST Request, ULONG64 Endpoin
PULONG64 PacketSizes, size_t PacketNumber,
PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
{
CWdfRequest WdfRequest(Request);
CTargetRequest WdfRequest(Request);

if (!DoPipeOperation<CWdfUsbInterface::SharedLock>(EndpointAddress,
[&WdfRequest, Buffer, PacketSizes, PacketNumber, Completion](CWdfUsbPipe &Pipe)
Expand All @@ -354,7 +354,7 @@ void CWdfUsbTarget::WriteIsochronousPipeAsync(WDFREQUEST Request, ULONG64 Endpoi
PULONG64 PacketSizes, size_t PacketNumber,
PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
{
CWdfRequest WdfRequest(Request);
CTargetRequest WdfRequest(Request);

if (!DoPipeOperation<CWdfUsbInterface::SharedLock>(EndpointAddress,
[&WdfRequest, Buffer, PacketSizes, PacketNumber, Completion](CWdfUsbPipe &Pipe)
Expand Down Expand Up @@ -439,7 +439,7 @@ NTSTATUS CWdfUsbTarget::ResetDevice(WDFREQUEST Request)
return status;
}

NTSTATUS CWdfUsbTarget::ControlTransferAsync(CWdfRequest &WdfRequest, PWDF_USB_CONTROL_SETUP_PACKET SetupPacket, WDFMEMORY Data,
NTSTATUS CWdfUsbTarget::ControlTransferAsync(CTargetRequest &WdfRequest, PWDF_USB_CONTROL_SETUP_PACKET SetupPacket, WDFMEMORY Data,
PWDFMEMORY_OFFSET TransferOffset, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion)
{
auto status = WdfUsbTargetDeviceFormatRequestForControlTransfer(m_UsbDevice, WdfRequest, SetupPacket, Data, TransferOffset);
Expand Down
30 changes: 23 additions & 7 deletions UsbDk/UsbTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,24 @@
#include "Alloc.h"
#include "UsbDkUtil.h"
#include "Urb.h"
#include "WdfRequest.h"

class CWdfRequest;
using USBDK_TARGET_REQUEST_CONTEXT = struct : public WDF_REQUEST_CONTEXT
{
ULONG64 RequestId;
};
using PUSBDK_TARGET_REQUEST_CONTEXT = USBDK_TARGET_REQUEST_CONTEXT*;

class CTargetRequest : public CWdfRequest
{
public:
explicit CTargetRequest(WDFREQUEST Request)
: CWdfRequest(Request)
{}

PUSBDK_TARGET_REQUEST_CONTEXT Context() const
{ return static_cast<PUSBDK_TARGET_REQUEST_CONTEXT>(CWdfRequest::Context()); }
};

class CWdfUsbPipe : public CAllocatable<NonPagedPool, 'PUHR'>
{
Expand All @@ -36,10 +52,10 @@ class CWdfUsbPipe : public CAllocatable<NonPagedPool, 'PUHR'>
{}

void Create(WDFUSBDEVICE Device, WDFUSBINTERFACE Interface, UCHAR PipeIndex);
void ReadAsync(CWdfRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion);
void WriteAsync(CWdfRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion);
void ReadAsync(CTargetRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion);
void WriteAsync(CTargetRequest &Request, WDFMEMORY Buffer, PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion);

void ReadIsochronousAsync(CWdfRequest &Request,
void ReadIsochronousAsync(CTargetRequest &Request,
WDFMEMORY Buffer,
PULONG64 PacketSizes,
size_t PacketNumber,
Expand All @@ -48,7 +64,7 @@ class CWdfUsbPipe : public CAllocatable<NonPagedPool, 'PUHR'>
SubmitIsochronousTransfer(Request, CIsochronousUrb::URB_DIRECTION_IN, Buffer, PacketSizes, PacketNumber, Completion);
}

void WriteIsochronousAsync(CWdfRequest &Request,
void WriteIsochronousAsync(CTargetRequest &Request,
WDFMEMORY Buffer,
PULONG64 PacketSizes,
size_t PacketNumber,
Expand All @@ -70,7 +86,7 @@ class CWdfUsbPipe : public CAllocatable<NonPagedPool, 'PUHR'>
WDFUSBPIPE m_Pipe = WDF_NO_HANDLE;
WDF_USB_PIPE_INFORMATION m_Info;

void SubmitIsochronousTransfer(CWdfRequest &Request,
void SubmitIsochronousTransfer(CTargetRequest &Request,
CIsochronousUrb::Direction Direction,
WDFMEMORY Buffer,
PULONG64 PacketSizes,
Expand Down Expand Up @@ -153,7 +169,7 @@ class CWdfUsbTarget
PULONG64 PacketSizes, size_t PacketNumber,
PFN_WDF_REQUEST_COMPLETION_ROUTINE Completion);

NTSTATUS ControlTransferAsync(CWdfRequest &WdfRequest, PWDF_USB_CONTROL_SETUP_PACKET SetupPacket, WDFMEMORY Data,
NTSTATUS ControlTransferAsync(CTargetRequest &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);
Expand Down

0 comments on commit 3d0a205

Please sign in to comment.