J
Jasonbit
Guest
I am writing an USB lower filter driver which can intercept URB by creating IOqueue handler EvtIoInternalDeviceControl. Below is my code to process URB.
VOID
FilterEvtIoInternalDeviceControl(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength,
IN ULONG IoControlCode
)
{
WDF_REQUEST_PARAMETERS para;
PURB pUrb = NULL;
WDFDEVICE device;
device = WdfIoQueueGetDevice(Queue);
switch (IoControlCode) {
case IOCTL_INTERNAL_USB_SUBMIT_URB:
WDF_REQUEST_PARAMETERS_INIT(¶);
WdfRequestGetParameters(Request, ¶);
pUrb = (PURB)para.Parameters.Others.Arg1;
if (pUrb != NULL)
{
switch (pUrb->UrbHeader.Function) {
case URB_FUNCTION_CONTROL_TRANSFER:
//process code here
break;
case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
//process code here
break;
}
...
}
The URB structure combines Bulk and Interrupt transfer in URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER. My filter driver is only interested in interrupt transfer, so the question is how to differentiate them? According to below URB definition, looks like the only relevant field is PipeHandle. Is it possible to get WDFUSBPIPE object from USBD_PIPE_HANDLE? Or filter driver can get some info e.g. WDFUSBDEVICE obj in DriverEntry or EvtDeviceAdd?
struct _URB_BULK_OR_INTERRUPT_TRANSFER {
struct URB_HEADER Hdr;
USBD_PIPE_HANDLE PipeHandle;
ULONG TransferFlags;
ULONG TransferBufferLength;
PVOID TransferBuffer;
PMDL TransferBufferMDL;
struct URB *UrbLink;
struct URB_HCD_AREA hca;
};
Thanks!
Continue reading...
VOID
FilterEvtIoInternalDeviceControl(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength,
IN ULONG IoControlCode
)
{
WDF_REQUEST_PARAMETERS para;
PURB pUrb = NULL;
WDFDEVICE device;
device = WdfIoQueueGetDevice(Queue);
switch (IoControlCode) {
case IOCTL_INTERNAL_USB_SUBMIT_URB:
WDF_REQUEST_PARAMETERS_INIT(¶);
WdfRequestGetParameters(Request, ¶);
pUrb = (PURB)para.Parameters.Others.Arg1;
if (pUrb != NULL)
{
switch (pUrb->UrbHeader.Function) {
case URB_FUNCTION_CONTROL_TRANSFER:
//process code here
break;
case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
//process code here
break;
}
...
}
The URB structure combines Bulk and Interrupt transfer in URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER. My filter driver is only interested in interrupt transfer, so the question is how to differentiate them? According to below URB definition, looks like the only relevant field is PipeHandle. Is it possible to get WDFUSBPIPE object from USBD_PIPE_HANDLE? Or filter driver can get some info e.g. WDFUSBDEVICE obj in DriverEntry or EvtDeviceAdd?
struct _URB_BULK_OR_INTERRUPT_TRANSFER {
struct URB_HEADER Hdr;
USBD_PIPE_HANDLE PipeHandle;
ULONG TransferFlags;
ULONG TransferBufferLength;
PVOID TransferBuffer;
PMDL TransferBufferMDL;
struct URB *UrbLink;
struct URB_HCD_AREA hca;
};
Thanks!
Continue reading...