Driver-driver communication across different device stacks

Are you sure the vmulti device has loaded and started?

d

Bent from my phone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?3/?23/?2015 8:41 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Driver-driver communication across different device stacks

Thanks all! Those were very helpful. Now then, if I understand Maxim correctly, KMDF enables the device interface by default. However, VMulti only shows up when the DEVICE_INTERFACE_INCLUDE_NONACTIVE flag is set. I’m guessing that somewhere in VMulti, there is some code that makes the device interface inactive? Looking over it, I don’t see any calls to IoSetDeviceInterfaceState anywhere in the code. Or are there any other possible reasons why it is inactive?

Thanks


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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>

I think so, because when I deploy the VMulti driver from Visual Studio onto my target, I can run a provided user-mode application that uses the driver to generate virtual HID input at my command.

The user-mode application uses HidD_GetHidGuid() to get the HID device interface GUID and so to open a file handle to VMulti (I could paste the relevant code in another post if you want), which is why I’m also using GUID_DEVINTERFACE_HID for my IoGetDeviceInterfaces() call. I find it interesting that the VMulti driver code itself doesn’t call WdfDeviceCreateDeviceInterface() to create a device interface for user-mode applications, I wonder if this is a problem for me who wants to access the device interface from another kernel-mode driver?

Hidclass enables the hid driver interface guid and then only on the pdos it enumerates, not the parent

d

Bent from my phone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?3/?23/?2015 9:35 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Driver-driver communication across different device stacks

I think so, because when I deploy the VMulti driver from Visual Studio onto my target, I can run a provided user-mode application that uses the driver to generate virtual HID input at my command.

The user-mode application uses HidD_GetHidGuid() to get the HID device interface GUID and so to open a file handle to VMulti (I could paste the relevant code in another post if you want), which is why I’m also using GUID_DEVINTERFACE_HID for my IoGetDeviceInterfaces() call. I find it interesting that the VMulti driver code itself doesn’t call WdfDeviceCreateDeviceInterface() to create a device interface for user-mode applications, I wonder if this is a problem for me who wants to access the device interface from another kernel-mode driver?


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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>

Okay thanks. Please let me try to digest what you just said.

  1. In Device manager, when the View is set to devices by connection, VMulti is shown to have multiple, different HID devices under it (HID Keyboard Device, HID-compliant mouse, HID-compliant pen…). Am I correct in saying that these HID-compliant xxxx devices are the hidclass-enumerated PDOs that you mentioned?

  2. Is VMulti then the parent of these hidclass-enumerated PDOs?

VMulti’s EvtDeviceAdd() calls WdfFdoInitSetFilter(DeviceInit).

Also, VMulti’s INF file has this code:
[vmulti_Win7_Parameters.AddReg]
HKR,“UpperFilters”,0x00010000,“mshidkmdf”

Also, its device stack looks like this: (from top to bottom) mshidkmdf, vmulti, PnPManager

In light of this, I’m trying to figure out all over again how does the control flow from the user-mode application to the virtual HID device. I know that this is not a Microsoft sample, but do you think the user-mode then communicates directly with VMulti? Or does it try to communicate to the hidclass-enumerated PDO but VMulti filters the IRP before it gets to the PDO (which could be why the user-mode app uses the HID device interface GUID instead of VMulti’s own device interface GUID?)?

Thanks!

It just really seems odd to me that a user-mode application could communicate with VMulti easily but I’m having so much trouble trying to make another kernel-mode driver (a filter driver which I wrote) communicate with VMulti.

I’ve thought of actually having my filter driver communicate with another user-mode app and have that user-mode app communicate with VMulti’s user-mode app (or maybe VMulti’s user app could also communicate directly with my filter driver), but I’m afraid that the whole thing will turn out to be really slow because of all the user-kernel transitions.

1 yes
2 yes (mshidkmdf+hidclass actually reports them)
3 yes, that is the stack

UM does NOT communicate directly with vmulti. UM is communicating with the HIDs enumerated by hiclass. Hidclass then forwards that io down the stack (from the child to the parent) to vmulti.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, March 23, 2015 10:32 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Driver-driver communication across different device stacks

Okay thanks. Please let me try to digest what you just said.

  1. In Device manager, when the View is set to devices by connection, VMulti is shown to have multiple, different HID devices under it (HID Keyboard Device, HID-compliant mouse, HID-compliant pen…). Am I correct in saying that these HID-compliant xxxx devices are the hidclass-enumerated PDOs that you mentioned?

  2. Is VMulti then the parent of these hidclass-enumerated PDOs?

VMulti’s EvtDeviceAdd() calls WdfFdoInitSetFilter(DeviceInit).

Also, VMulti’s INF file has this code:
[vmulti_Win7_Parameters.AddReg]
HKR,“UpperFilters”,0x00010000,“mshidkmdf”

Also, its device stack looks like this: (from top to bottom) mshidkmdf, vmulti, PnPManager

In light of this, I’m trying to figure out all over again how does the control flow from the user-mode application to the virtual HID device. I know that this is not a Microsoft sample, but do you think the user-mode then communicates directly with VMulti? Or does it try to communicate to the hidclass-enumerated PDO but VMulti filters the IRP before it gets to the PDO (which could be why the user-mode app uses the HID device interface GUID instead of VMulti’s own device interface GUID?)?

Thanks!


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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 see, thanks so much! So does this mean that if I want my filter to trigger vmulti’s generation of virtual HID input, I shouldn’t even bother trying to create a query interface in vmulti itself that my filter will use?

The other option I see is modifying the provided UM application that talks to the whole vmulti system so that it also receives data from the filter. Can a KM filter generate an event in the UM side that the UM app can handle? If this is possible, then every time the event fires, the UM app receives data from the filter and then it also sends data out to VMulti (of course, really it’s actually talking to VMulti’s hidclass-enumerated PDOs as you’ve said before). The only drawback I see in here is the overhead that the UM/KM transitions will entail. What do you think about this?

Also, looking back to the earlier parts of this thread, you’ve suggested having the HID miniport (which is mshidkmdf if I’m not mistaken?) expose a CDO or additional TLC. Does that still apply in light of the information in these recent posts?

Thanks!

The cdo or tlc still applies. How exactly does the app configure vmulti? It is either through a tlc or cdo as well

d

Bent from my phone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?3/?24/?2015 7:55 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Driver-driver communication across different device stacks

I see, thanks so much! So does this mean that if I want my filter to trigger vmulti’s generation of virtual HID input, I shouldn’t even bother trying to create a query interface in vmulti itself that my filter will use?

The other option I see is modifying the provided UM application that talks to the whole vmulti system so that it also receives data from the filter. Can a KM filter generate an event in the UM side that the UM app can handle? If this is possible, then every time the event fires, the UM app receives data from the filter and then it also sends data out to VMulti (of course, really it’s actually talking to VMulti’s hidclass-enumerated PDOs as you’ve said before). The only drawback I see in here is the overhead that the UM/KM transitions will entail. What do you think about this?

Also, looking back to the earlier parts of this thread, you’ve suggested having the HID miniport (which is mshidkmdf if I’m not mistaken?) expose a CDO or additional TLC. Does that still apply in light of the information in these recent posts?

Thanks!


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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>

Okay thanks. I’m not too sure how if vmulti’s hidkmdf exposes a cdo or tlc because the hidkmdf.c in vmulti’s solution seems rather plain, or maybe I just don’t know what exactly to look for. In any case though, here is a code snippet where the vmulti app finds vmulti’s PDO:

HidD_GetHidGuid(&hidguid);
printf(“GUID: %x %x %x %x\n”, hidguid.Data1, hidguid.Data2, hidguid.Data3, hidguid.Data4);

hardwareDeviceInfo =
SetupDiGetClassDevs ((LPGUID)&hidguid,
NULL,
NULL, // Define no
(DIGCF_PRESENT |
DIGCF_INTERFACEDEVICE));

if (INVALID_HANDLE_VALUE == hardwareDeviceInfo)
{
printf(“SetupDiGetClassDevs failed: %x\n”, GetLastError());
return INVALID_HANDLE_VALUE;
}

deviceInterfaceData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);

devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

//
// Enumerate devices of this interface class
//

printf("\n…looking for our HID device (with UP=0x%x "
“and Usage=0x%x)\n”, myUsagePage, myUsage);

for (i = 0; SetupDiEnumDeviceInterfaces (hardwareDeviceInfo,
0, // No care about specific PDOs
(LPGUID)&hidguid,
i, //
&deviceInterfaceData);
i++)
{

//
// Open the device interface and Check if it is our device
// by matching the Usage page and Usage from Hid_Caps.
// If this is our device then send the hid request.
//

HANDLE file = OpenDeviceInterface(hardwareDeviceInfo, &deviceInterfaceData, myUsagePage, myUsage);

if (file != INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);
return file;
}

//
//device was not found so loop around.
//

}

printf(“Failure: Could not find our HID device \n”);

Please let me know if this is more or less what you were asking for when you asked how does the app configure vmulti?

The control TLC would be reported in the hid report descriptor vmulti returns to hidclass. Given the code below, the CDO option is not being used

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, March 26, 2015 9:51 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Driver-driver communication across different device stacks

Okay thanks. I’m not too sure how if vmulti’s hidkmdf exposes a cdo or tlc because the hidkmdf.c in vmulti’s solution seems rather plain, or maybe I just don’t know what exactly to look for. In any case though, here is a code snippet where the vmulti app finds vmulti’s PDO:

HidD_GetHidGuid(&hidguid);
printf(“GUID: %x %x %x %x\n”, hidguid.Data1, hidguid.Data2, hidguid.Data3, hidguid.Data4);

hardwareDeviceInfo =
SetupDiGetClassDevs ((LPGUID)&hidguid,
NULL,
NULL, // Define no
(DIGCF_PRESENT |
DIGCF_INTERFACEDEVICE));

if (INVALID_HANDLE_VALUE == hardwareDeviceInfo)
{
printf(“SetupDiGetClassDevs failed: %x\n”, GetLastError());
return INVALID_HANDLE_VALUE;
}

deviceInterfaceData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);

devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

//
// Enumerate devices of this interface class
//

printf("\n…looking for our HID device (with UP=0x%x "
“and Usage=0x%x)\n”, myUsagePage, myUsage);

for (i = 0; SetupDiEnumDeviceInterfaces (hardwareDeviceInfo,
0, // No care about specific PDOs
(LPGUID)&hidguid,
i, //
&deviceInterfaceData);
i++)
{

//
// Open the device interface and Check if it is our device
// by matching the Usage page and Usage from Hid_Caps.
// If this is our device then send the hid request.
//

HANDLE file = OpenDeviceInterface(hardwareDeviceInfo, &deviceInterfaceData, myUsagePage, myUsage);

if (file != INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);
return file;
}

//
//device was not found so loop around.
//

}

printf(“Failure: Could not find our HID device \n”);

Please let me know if this is more or less what you were asking for when you asked how does the app configure vmulti?


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

Thank you very much! By the way, could you please tell me if there are any WDK samples that illustrates the process of your suggestion?

More specifically, are there any WDK samples that show a similar case where an HID filter opens the TLC of a hidclass-enumerated PDO from another device stack?

Not specifically, but any code that opens a remote Io target is the same pattern. The toaster sample toastmon project is close

d

Bent from my phone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?4/?3/?2015 12:21 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Driver-driver communication across different device stacks

More specifically, are there any WDK samples that show a similar case where an HID filter opens the TLC of a hidclass-enumerated PDO from another device stack?


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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>

So over the past couple of days, I’ve been trying to follow the pattern of toastmon and also the pattern of the provided vmulti UM app. However, I’m stumped because the UM app seems like it’s able to call HidD_SetOutputReport(), but when my KM filter tries to do WdfIoTargetSendIoctlSynchronously() with IOCTL code IOCTL_HID_SET_OUTPUT_REPORT, it fails with STATUS_INVALID_DEVICE_REQUEST. Is it possible that this happens because the format of my report is just wrong?

Thanks!

How are you creating the remote io target? By name? by supplying the raw device object? Hid requires that you have a valid PFILE_OBJECT in the request, if you open the target not by name, the io target cannot set the file object.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Tuesday, April 07, 2015 6:51 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Driver-driver communication across different device stacks

So over the past couple of days, I’ve been trying to follow the pattern of toastmon and also the pattern of the provided vmulti UM app. However, I’m stumped because the UM app seems like it’s able to call HidD_SetOutputReport(), but when my KM filter tries to do WdfIoTargetSendIoctlSynchronously() with IOCTL code IOCTL_HID_SET_OUTPUT_REPORT, it fails with STATUS_INVALID_DEVICE_REQUEST. Is it possible that this happens because the format of my report is just wrong?

Thanks!


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

Thank you very much! However, the problem turned out to be that I’m sending the wrong format of data to the remote IO target.