Multiple devices and WdfDeviceCreateDeviceInterface

Hi experts

In KMDF we created a bus extended driver and we create a tool to interact with driver through ioctl, so if the machine has the multiple card how can we reach the specific card interface and how can we handle multiple instance with a single driver, if we have a same multiple pci card.
so i can get the specific PFDO of a specific card by passing BDF of the card.

Thanks

You are confused. Each interface will have its own pdo, multiple instances each with their own do is fine. No work on your behalf other than to enable it

Sent from my Windows 10 phone

From: xxxxx@gmail.commailto:xxxxx
Sent: Saturday, March 19, 2016 12:35 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] Multiple devices and WdfDeviceCreateDeviceInterface

Hi experts

In KMDF we created a bus extended driver and we create a tool to interact with driver through ioctl, so if the machine has the multiple card how can we reach the specific card interface and how can we handle multiple instance with a single driver, if we have a same multiple pci card.
so i can get the specific PFDO of a specific card by passing BDF of the card.

Thanks


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:></mailto:xxxxx></mailto:xxxxx>

Thanks a lot Doron for clarifying my doubts on driver instance.

and i have done some change in code

I have created a device interface with WdfDeviceCreateDeviceInterface with the reference string being an encoded with Func Number in driver.

In the user app how can i connect to the specific hardware (with the reference string ) encoded

hardwareDeviceInfo = SetupDiGetClassDevs(
(LPGUID)&GUID_MYDEVICE,
NULL, // Define no enumerator (global)
NULL, // Define no
(DIGCF_PRESENT | // Only Devices present
DIGCF_DEVICEINTERFACE)); // Function class devices.

deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

printf(“Calling SetupDiEnumDeviceInterfaces()…\n”);

bResult = SetupDiEnumDeviceInterfaces(hardwareDeviceInfo,
0,
(LPGUID)&GUID_MYDEVICE,
0,
&deviceInterfaceData);

printf(“Calling SetupDiGetDeviceInterfaceDetail()…\n”);

SetupDiGetDeviceInterfaceDetail(
hardwareDeviceInfo,
&deviceInterfaceData,
NULL,
0,
&RequiredLength,
NULL
);

deviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)
LocalAlloc(LMEM_FIXED, RequiredLength);

deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

predictedLength = RequiredLength;

bResult = SetupDiGetDeviceInterfaceDetail(
hardwareDeviceInfo,
&deviceInterfaceData,
deviceInterfaceDetailData,
predictedLength,
&RequiredLength,
NULL);

printf(" SetupDiGetDeviceInterfaceDetail() bResult=0x%x…\n", bResult);

*handle= CreateFile(deviceInterfaceDetailData->DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
0, // No special attributes
NULL); // No template file

if (DeviceIoControl(handle,
MYDEVICE_FW_IOCTL_BDF,
&pci_addr,
sizeof(test_pci_addr_t),
NULL,
NULL,
&bytes,
NULL))

Through this, I can hit the driver, but even though if I give the wrong function number its hitting the driver ioctl, where I am missing to add the reference string in user code.

Thanks for your help

xxxxx@gmail.com wrote:

I have created a device interface with WdfDeviceCreateDeviceInterface with the reference string being an encoded with Func Number in driver.

In the user app how can i connect to the specific hardware (with the reference string ) encoded

Through this, I can hit the driver, but even though if I give the wrong function number its hitting the driver ioctl, where I am missing to add the reference string in user code.

Your view of the workings here doesn’t match Device Manager’s view.
Here’s the principle.

Let’s say you register the same device interface four times, with
reference strings aaa, bbb, ccc, and ddd. That means there are four
different entries for SetupDiEnumDeviceInterfaces to enumerate through.
Each entry corresponds to one specific instance. Each instance will
have a specific reference string. Your code is merely grabbing the
first one. When you open that device, you’ll get whatever reference
string is associated with that registration.

As it turns out, the reference string is embedded in the DevicePath.
You should call SetupDiEnumDeviceInterfaces in a loop until it doesn’t
return any more, then look for your reference string in the DevicePath.
You can print out the path to see the format.


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

Tim Roberts wrote:

xxxxx@gmail.com wrote:
> I have created a device interface with WdfDeviceCreateDeviceInterface with the reference string being an encoded with Func Number in driver.
>
As it turns out, the reference string is embedded in the DevicePath.
You should call SetupDiEnumDeviceInterfaces in a loop until it doesn’t
return any more, then look for your reference string in the DevicePath.
You can print out the path to see the format.

I should also point out that there is a different approach that might
suit you better. If you have one device that happens to offer 4
submodes, for example, then you can register your device interface once
without a reference string, and append the submode to the DevicePath you
get back from SetupDi. Your driver has to enable file object handling.
If EvtFileCreate, you use WdfFileObjectGetFileName to fetch the appended
part. In my example, the file name would be “\aaa”.

That way, enumerating with SetupDiEnumDeviceInterfaces will return you
one entry per physical device.


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