Getting a HID_DESCRIPTOR data

Hi, I’m having trouble getting the HID_DESCRIPTOR for my device and would be grateful for any help. Here’s where I’m at:

I started from the hidusbfx2 sample and the driver works great as long as I provide a hard coded hid and report descriptor. But since the device I’m working with is a hid device I want to get the descriptors from the hardware and change them instead of making them up. So in response to IOCTL_HID_GET_DEVICE_DESCRIPTOR I forward the request with a completion routine to my usb device like this:

HidMyPMForwardRequestWithCompletionRoutine( Request, WdfUsbTargetDeviceGetIoTarget( devContext->UsbDevice ) );

VOID
HidMyPMForwardRequestWithCompletionRoutine( IN WDFREQUEST Request, IN WDFIOTARGET Target )
{
BOOLEAN ret;
NTSTATUS status;

WdfRequestFormatRequestUsingCurrentType( Request );
WdfRequestSetCompletionRoutine( Request, HidMyPMRequestCompletionRoutine, WDF_NO_CONTEXT );

ret = WdfRequestSend(Request, Target, WDF_NO_SEND_OPTIONS);

if( ret == FALSE )
{
status = WdfRequestGetStatus (Request);
WdfRequestComplete(Request, status);
}

return;
}

my completion routine gets a status of success and I try to get the data like this:

currentIrpStack = IoGetCurrentIrpStackLocation( WdfRequestWdmGetIrp( Request ) );
size = currentIrpStack->Parameters.DeviceIoControl.OutputBufferLength;
data = (PHID_DESCRIPTOR)WdfRequestWdmGetIrp(Request)->UserBuffer;

size is 9 as I would hope but the buffer contains only zeros instead of the HID_DESCRIPTOR data. Any idea what I’m missing?

Thanks for any help

Who converts the IOCTL into a URB? If your device is HID at the USB level, why do you need to write a custom HID miniport?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, February 08, 2010 11:21 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Getting a HID_DESCRIPTOR data

Hi, I’m having trouble getting the HID_DESCRIPTOR for my device and would be grateful for any help. Here’s where I’m at:

I started from the hidusbfx2 sample and the driver works great as long as I provide a hard coded hid and report descriptor. But since the device I’m working with is a hid device I want to get the descriptors from the hardware and change them instead of making them up. So in response to IOCTL_HID_GET_DEVICE_DESCRIPTOR I forward the request with a completion routine to my usb device like this:

HidMyPMForwardRequestWithCompletionRoutine( Request, WdfUsbTargetDeviceGetIoTarget( devContext->UsbDevice ) );

VOID
HidMyPMForwardRequestWithCompletionRoutine( IN WDFREQUEST Request, IN WDFIOTARGET Target )
{
BOOLEAN ret;
NTSTATUS status;

WdfRequestFormatRequestUsingCurrentType( Request );
WdfRequestSetCompletionRoutine( Request, HidMyPMRequestCompletionRoutine, WDF_NO_CONTEXT );

ret = WdfRequestSend(Request, Target, WDF_NO_SEND_OPTIONS);

if( ret == FALSE )
{
status = WdfRequestGetStatus (Request);
WdfRequestComplete(Request, status);
}

return;
}

my completion routine gets a status of success and I try to get the data like this:

currentIrpStack = IoGetCurrentIrpStackLocation( WdfRequestWdmGetIrp( Request ) );
size = currentIrpStack->Parameters.DeviceIoControl.OutputBufferLength;
data = (PHID_DESCRIPTOR)WdfRequestWdmGetIrp(Request)->UserBuffer;

size is 9 as I would hope but the buffer contains only zeros instead of the HID_DESCRIPTOR data. Any idea what I’m missing?

Thanks for any help


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

I guess no one is converting it to an URB since I’m just forwarding the request on down. The completion IoStatus.Status is success and the output buffer size is filled in with the right number so I thought I was close. I’ll look at formatting an URB first though.

The reason I’m doing this is twofold:

  1. I want to learn how to do it. I have my driver working the way I want by hard coding the descriptors but I want to push it one step further.
  2. The reason for the miniport driver in the first place is that this device reports a custom collection which the manufacturer intends to be used via a service. This service has lots of options and does not do what I want by default. It’s a USB knob / button with an led lit base. I want the knob to be volume up / down and the button to toggle play / pause. By default the service sets the button to be mute / unmute. I can set it to play / pause in their control panel but for some reason it only works if Media Player has focus, which is far less than ideal. If I’m working in VS or IE and I want to pause I don’t want to have to first switch to Media Player. I’m guessing they are just sending keystrokes. Creating a media control collection does what I want it to do and works well (unless explorer.exe has focus for some reason). Plus I wanted to learn more about WDF and this seemed like a doable project to start with. Once I get this part working I’m going to steal the firefly hid sample idea and make the led base beat to my music.

Thanks,
-Dan

If you can get access to the “raw” usb commands via the service interface, all you need to do is post WM_APPCOMMAND messages with the apppriate command (vol up, down) etc to the current window in focus and you can wire in sound. If the current window does not support the app command, it goes to DefWndProc which then applies them to the global state (at least for volume).

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Tuesday, February 09, 2010 11:44 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Getting a HID_DESCRIPTOR data

I guess no one is converting it to an URB since I’m just forwarding the request on down. The completion IoStatus.Status is success and the output buffer size is filled in with the right number so I thought I was close. I’ll look at formatting an URB first though.

The reason I’m doing this is twofold:

  1. I want to learn how to do it. I have my driver working the way I want by hard coding the descriptors but I want to push it one step further.
  2. The reason for the miniport driver in the first place is that this device reports a custom collection which the manufacturer intends to be used via a service. This service has lots of options and does not do what I want by default. It’s a USB knob / button with an led lit base. I want the knob to be volume up / down and the button to toggle play / pause. By default the service sets the button to be mute / unmute. I can set it to play / pause in their control panel but for some reason it only works if Media Player has focus, which is far less than ideal. If I’m working in VS or IE and I want to pause I don’t want to have to first switch to Media Player. I’m guessing they are just sending keystrokes. Creating a media control collection does what I want it to do and works well (unless explorer.exe has focus for some reason). Plus I wanted to learn more about WDF and this seemed like a doable project to start with. Once I get this part working I’m going to steal the firefly hid sample idea and make the led base beat to my music.

Thanks,
-Dan


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

Yeah, I’m sure I could achieve my functional goals with a little app that I drop in my startup folder.

Thanks,
-Dan