usb client filter driver

Hi all,

i am developing a USB upper filter client driver in which i need to send a request to the usb device(OUT endpoint) attached on receiving certain events.

i would like to know how to send the request from the filter driver to the lower drivers.
i am using USB HID filter driver sample from msdn. i am using UsbBuildInterruptOrBulkTransferRequest() to create the URB, and send to out pipe by calling WdfUsbTargetPipeSendUrbSynchronously() function.
now i am facing a small problem …
i get STATUS_INVALID_PARAMETER1 error for WdfUsbTargetDeviceCreateWithParameters() call.
parameter1 is the WDFDEVICE … i am using the sample code itself… i have not modified creation of the device object …
is there any way that the ‘Device’ parameter getting wrong … ?
please let me know if i have gone wrong anywhere …

my sample code is as below …

send_cmd(WDFDEVICE Device,
COMMAND_PKT *pcmd_pkt
)
{
NTSTATUS status = STATUS_SUCCESS;

PURB purb = NULL;
USBD_PIPE_HANDLE PipeHandle = NULL;

WDF_USB_DEVICE_CREATE_CONFIG Config;
//ULONG USBDClientContractVersion = 0;

WDFUSBINTERFACE UsbInterface = NULL;
WDF_OBJECT_ATTRIBUTES Attributes;
WDFUSBDEVICE UsbDevice = NULL;

UCHAR InterfaceIndex = 1;//Interface 1

WDFUSBPIPE Pipe = NULL;
UCHAR PipeIndex = 1; //Endpoint 2[OUT ep]
WDF_USB_PIPE_INFORMATION PipeInfo;

PDEVICE_CONTEXT pDeviceContext;

PIRP pirp;
CCHAR StackSize;
BOOLEAN ChargeQuota;

KdPrint((“send_read_command\n”));
#ifdef USB_INT_TRANSFER2

//=======1. Generate Pipe Handle=============================
WDF_USB_DEVICE_CREATE_CONFIG_INIT(//memset0, size, version update
&Config,
USBD_CLIENT_CONTRACT_VERSION_602
);

KdPrint((“Device: 0x%x\n”, Device));

//pDeviceContext = WdfObjectGet_DEVICE_CONTEXT(Device);

status = WdfUsbTargetDeviceCreateWithParameters(
Device,
&Config,
WDF_NO_OBJECT_ATTRIBUTES,//&Attributes,
&UsbDevice//&pDeviceContext->wdfusbdevice
);
if (!NT_SUCCESS(status))
{
KdPrint((“WdfUsbTargetDeviceCreateWithParameters failed %x\n”, status));
return status;
}
else
{
KdPrint((“WdfUsbTargetDeviceCreateWithParameters succcess\n”));
}
UsbInterface = WdfUsbTargetDeviceGetInterface(
UsbDevice,
InterfaceIndex
);

if(!UsbInterface)
{
KdPrint((“WdfUsbTargetDeviceGetInterface failed\n”));
return STATUS_INVALID_PARAMETER;//
}
else
KdPrint((“WdfUsbTargetDeviceGetInterface success\n”));

Pipe = WdfUsbInterfaceGetConfiguredPipe(
UsbInterface,
PipeIndex,
&PipeInfo);
if(!Pipe)
KdPrint((“WdfUsbInterfaceGetConfiguredPipe failed\n”));

KdPrint((“PipeInfo.EndpointAddress: 0x%x\n”, PipeInfo.EndpointAddress));
KdPrint((“PipeInfo.PipeType: 0x%x\n”, PipeInfo.PipeType));
KdPrint((“PipeInfo.SettingIndex: 0x%x\n”, PipeInfo.SettingIndex));
KdPrint((“PipeInfo.SettingIndex: 0x%x\n”, PipeInfo.SettingIndex));
KdPrint((“Pipe: 0x%x\n”, Pipe));

PipeHandle = WdfUsbTargetPipeWdmGetPipeHandle(
Pipe
);

KdPrint((“PipeInfo.PipeHandle: 0x%x\n”, PipeHandle));

//==========================================================

//=======2. create URB for Sending Interrupt Data============

UsbBuildInterruptOrBulkTransferRequest (
purb,
sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
PipeHandle,
pcmd_pkt,//TransferBuffer
NULL,//TransferBufferMDL
sizeof(COMMAND_PKT),//TransferBufferLength
0,//TransferFlags
NULL//Link
);
KdPrint((“purb: 0x%x\n”, purb));
//==========================================================

//============3. Send Urb to Interrupt OUT Pipe=============
WdfUsbTargetPipeSendUrbSynchronously(
Pipe,
NULL,//Request: check
NULL,//Request Options: check
purb
);
//==========================================================

Which stack are you an upper filter on? Typically upper filters can’t send URBs, the fdo will block them. Regardless, creating a wdfusbdevice every time you want to send one is overkill. And you can’t call WdfUsbInterfaceGetConfiguredPipe until you have configured the device, which is a diff call than creating a wdfusbdevice.

d

dent from pjone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?11/?27/?2012 5:42 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] usb client filter driver

Hi all,

i am developing a USB upper filter client driver in which i need to send a request to the usb device(OUT endpoint) attached on receiving certain events.

i would like to know how to send the request from the filter driver to the lower drivers.
i am using USB HID filter driver sample from msdn. i am using UsbBuildInterruptOrBulkTransferRequest() to create the URB, and send to out pipe by calling WdfUsbTargetPipeSendUrbSynchronously() function.
now i am facing a small problem …
i get STATUS_INVALID_PARAMETER1 error for WdfUsbTargetDeviceCreateWithParameters() call.
parameter1 is the WDFDEVICE … i am using the sample code itself… i have not modified creation of the device object …
is there any way that the ‘Device’ parameter getting wrong … ?
please let me know if i have gone wrong anywhere …

my sample code is as below …

send_cmd(WDFDEVICE Device,
COMMAND_PKT *pcmd_pkt
)
{
NTSTATUS status = STATUS_SUCCESS;

PURB purb = NULL;
USBD_PIPE_HANDLE PipeHandle = NULL;

WDF_USB_DEVICE_CREATE_CONFIG Config;
//ULONG USBDClientContractVersion = 0;

WDFUSBINTERFACE UsbInterface = NULL;
WDF_OBJECT_ATTRIBUTES Attributes;
WDFUSBDEVICE UsbDevice = NULL;

UCHAR InterfaceIndex = 1;//Interface 1

WDFUSBPIPE Pipe = NULL;
UCHAR PipeIndex = 1; //Endpoint 2[OUT ep]
WDF_USB_PIPE_INFORMATION PipeInfo;

PDEVICE_CONTEXT pDeviceContext;

PIRP pirp;
CCHAR StackSize;
BOOLEAN ChargeQuota;

KdPrint((“send_read_command\n”));
#ifdef USB_INT_TRANSFER2

//=======1. Generate Pipe Handle=============================
WDF_USB_DEVICE_CREATE_CONFIG_INIT(//memset0, size, version update
&Config,
USBD_CLIENT_CONTRACT_VERSION_602
);

KdPrint((“Device: 0x%x\n”, Device));

//pDeviceContext = WdfObjectGet_DEVICE_CONTEXT(Device);

status = WdfUsbTargetDeviceCreateWithParameters(
Device,
&Config,
WDF_NO_OBJECT_ATTRIBUTES,//&Attributes,
&UsbDevice//&pDeviceContext->wdfusbdevice
);
if (!NT_SUCCESS(status))
{
KdPrint((“WdfUsbTargetDeviceCreateWithParameters failed %x\n”, status));
return status;
}
else
{
KdPrint((“WdfUsbTargetDeviceCreateWithParameters succcess\n”));
}
UsbInterface = WdfUsbTargetDeviceGetInterface(
UsbDevice,
InterfaceIndex
);

if(!UsbInterface)
{
KdPrint((“WdfUsbTargetDeviceGetInterface failed\n”));
return STATUS_INVALID_PARAMETER;//
}
else
KdPrint((“WdfUsbTargetDeviceGetInterface success\n”));

Pipe = WdfUsbInterfaceGetConfiguredPipe(
UsbInterface,
PipeIndex,
&PipeInfo);
if(!Pipe)
KdPrint((“WdfUsbInterfaceGetConfiguredPipe failed\n”));

KdPrint((“PipeInfo.EndpointAddress: 0x%x\n”, PipeInfo.EndpointAddress));
KdPrint((“PipeInfo.PipeType: 0x%x\n”, PipeInfo.PipeType));
KdPrint((“PipeInfo.SettingIndex: 0x%x\n”, PipeInfo.SettingIndex));
KdPrint((“PipeInfo.SettingIndex: 0x%x\n”, PipeInfo.SettingIndex));
KdPrint((“Pipe: 0x%x\n”, Pipe));

PipeHandle = WdfUsbTargetPipeWdmGetPipeHandle(
Pipe
);

KdPrint((“PipeInfo.PipeHandle: 0x%x\n”, PipeHandle));

//==========================================================

//=======2. create URB for Sending Interrupt Data============

UsbBuildInterruptOrBulkTransferRequest (
purb,
sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
PipeHandle,
pcmd_pkt,//TransferBuffer
NULL,//TransferBufferMDL
sizeof(COMMAND_PKT),//TransferBufferLength
0,//TransferFlags
NULL//Link
);
KdPrint((“purb: 0x%x\n”, purb));
//==========================================================

//============3. Send Urb to Interrupt OUT Pipe=============
WdfUsbTargetPipeSendUrbSynchronously(
Pipe,
NULL,//Request: check
NULL,//Request Options: check
purb
);
//==========================================================


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

my driver is an upper filter driver for hidclass …
i need to control a usb hid device connected. hence i need to send a command request to OUT endpoint of the interface of the USB device…
if the filter driver cant send an URB then is there an alternate approach ??

and doran …
my device is a USB HID device …

An upper filter of hidusb/hidclass is useless. You want a lower filter. From there you can send an urb. You can use a wdfdevice / wdfusbpipe to do that, but you have to configure the device with the config urb that hidusb sends

d

dent from pjone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?11/?27/?2012 7:44 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] usb client filter driver

my driver is an upper filter driver for hidclass …
i need to control a usb hid device connected. hence i need to send a command request to OUT endpoint of the interface of the USB device…
if the filter driver cant send an URB then is there an alternate approach ??


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

xxxxx@gmail.com wrote:

my driver is an upper filter driver for hidclass …
i need to control a usb hid device connected. hence i need to send a command request to OUT endpoint of the interface of the USB device…
if the filter driver cant send an URB then is there an alternate approach ??

You need to think about the “language” that each component speaks. A
hidclass driver speaks HID. It doesn’t understand USB. So, when you
send it a URB, it discards it with a sneer. Indeed, hidclass can be
used with devices that are not USB at all.

If you want to send URBs, you have to be at a level in the driver stack
where the driver underneath you speaks USB.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.