Sending IOCTL Request ioTarget

I want to make an WdfIoTargetSendIoctlSynchronously call. All is clear but the only thing left is how to get the “ioTarget” inside of EvtDeviceAdd in the filter driver.
I know that the most of you know that but for me it is not clear how to get the IoTarget. There are so many functions.

Are you sending it down the stack? WdfDeviceGetIoTarget will return the target for down the stack. If elsewhere, you need create your own and open it.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@x-publisher.com
Sent: Friday, February 9, 2018 8:16 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Sending IOCTL Request ioTarget

I want to make an WdfIoTargetSendIoctlSynchronously call. All is clear but the only thing left is how to get the “ioTarget” inside of EvtDeviceAdd in the filter driver.
I know that the most of you know that but for me it is not clear how to get the IoTarget. There are so many functions.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

I want the KEYBOARD_EXTENDED_ATTRIBUTES from the actual keyboard.
Thank you.

That’s nice, but it doesn’t answer the question: To which device in the system do you want to send your IOCTL? If its the Device Object directly below you, you want your Local I/O Target, which you retrieve (as Doron said) with WdfDeviceGetIoTarget.

If you want to send your IOCTL to a DIFFERENT device in the system, you can open an I/O Target to that device by name or using a given WDM Device Object pointer.

Peter
OSR
@OSRDrivers

Ok, I thought it was clear because I wrote “EvtDeviceAdd”. As I know this function is called for each keyboard, virtual or physical in the system. I think it is clear now.
Thank you.

xxxxx@x-publisher.com wrote:

I want to make an WdfIoTargetSendIoctlSynchronously call. All is clear but the only thing left is how to get the “ioTarget” inside of EvtDeviceAdd in the filter driver.
I know that the most of you know that but for me it is not clear how to get the IoTarget. There are so many functions.

The KMDF designers have done an excellent job of naming their methods,
so many times it is quite possible to guess what you need.  KMDF is a
tree of objects, where each node has stored a copy of the its
parents/owners/associates.  So, in a case like this, you need to ask
yourself, "what information do I need, and what resources do I have?" 
You need a WDFIOTARGET.  You have a WDFDEVICE.  When you need to ask an
X for a Y, the KMDF rule is that the routine is called XGetY.  So, look
for WdfDeviceGetIoTarget, and there it is.

Sometimes you have to go through several steps.  For example, to get a
WDFDEVICE from a WDFREQUEST, you have to go through the WDFQUEUE
(WdfRequestGetIoQueue, WdfIoQueueGetDevice).


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

Yes, I see there is a systematic but I know that I must know more.
For example: If I call now WdfDeviceGetIoTarget with the device handle I get that this device does not support this IOCTL and therefore I thought.
Ok, I remembered that there is a connection and in this connection I have done:
devExt->UpperConnectData = *connectData;
and here I looked at
PDEVICE_OBJECT ClassDeviceObject;
If I look in PDEVICE_OBJECT I see
struct _DRIVER_OBJECT *DriverObject;
struct _DEVICE_OBJECT *NextDevice;
struct _DEVICE_OBJECT *AttachedDevice;
Which one should I use now?
Questions after questions! :frowning:

xxxxx@x-publisher.com wrote:

Yes, I see there is a systematic but I know that I must know more.
For example: If I call now WdfDeviceGetIoTarget with the device handle I get that this device does not support this IOCTL and therefore I thought.
Ok, I remembered that there is a connection and in this connection I have done:
devExt->UpperConnectData = *connectData;
and here I looked at
PDEVICE_OBJECT ClassDeviceObject;
If I look in PDEVICE_OBJECT I see
struct _DRIVER_OBJECT *DriverObject;
struct _DEVICE_OBJECT *NextDevice;
struct _DEVICE_OBJECT *AttachedDevice;
Which one should I use now?

None of them.  Those are all going the wrong direction – upward.  The
hardware is below you, at WdfDeviceGetIoTarget(hDevice).

Are you trying to send IOCTL_KEYBOARD_QUERY_EXTENDED_ATTRIBUTES?  What
operating system are you using for testing?  That ioctl was not added
until Windows 10.


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

Oh!
Yes, I want this IOCTL_KEYBOARD_QUERY_EXTENDED_ATTRIBUTES. I work with the latest win10.

I tried with other Ioctl like IOCTL_KEYBOARD_SET_INDICATORS and always get error 0xc0000010.

status = WdfIoTargetSendIoctlSynchronously(
WdfDeviceGetIoTarget(device),
WDF_NO_HANDLE, // Request WDF_NO_HANDLE
IoctlControlCode,
pInputDesc,
pOutputDesc,
NULL, // PWDF_REQUEST_SEND_OPTIONS
NULL);
Any ideas?

The filter driver is above kbdclass as Upperfilter. This is the reason that I get 0xc0000010. If I set it below kbdclass the function works.

Now I tried WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME. Is this the way to go?

Open by name will open the top of the stack , essentially opening your driver if you are above kbdclass. The recommended location is below kbdclass because it is rather restrictive about who can open it and what io gets through.

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@x-publisher.com
Sent: Saturday, February 10, 2018 6:42:16 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Sending IOCTL Request ioTarget

The filter driver is above kbdclass as Upperfilter. This is the reason that I get 0xc0000010. If I set it below kbdclass the function works.

Now I tried WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME. Is this the way to go?


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

English is not my first language therefore I ask the following questions for my better understanding.
My filter driver modifies the keyboard data. Can this also be done if the filter driver is below kbdclass? I tested it without modification and it do not work below kdbdclass.

Is it right that a filter driver which is above can not set keyboard indicators? If I can’t set the indicators it is not so easy to change the input data because I must know for example the state of the capslock.