Question regard Device ID/Node

Let me first mention that I am not win32 driver guru, just a self-taught beginner.

I am creating a device within a driver, and assigning it a device id with WdfPdoInitAssignDeviceID(). Ultimately this will create a Node under the dev class for Smart Card Readers (in my case). Once the device is created and configured, I am calling WdfAddStaticChild() (which is where I think my problem is…) My question is that once I am done with the device, it is marked as missing but the Node still stays. This creates a problem since I can’t easily uninstall the driver since it still has active nodes; it looks like it is still in use, along with over time I could create a ton of nodes that are essentially dead. What can I do so that they are removed when I am done with the device?

This is what I am doing now for removal:
// Lock the list of children PDOs
WdfFdoLockStaticChildListForIteration(hParentDevice);
// Retrieve the first one
hPdo = WdfFdoRetrieveNextStaticChild( hParentDevice,NULL, WdfRetrievePresentChildren);
while (hPdo != NULL)
{
pPdoDevExt = GetPdoDevExt(hPdo);

// Compare the names
if (pPdoDevExt->DeviceInfo.ReaderId == ReaderId)
{
// We found the device of interest
status = WdfPdoMarkMissing(hPdo);
if (!NT_SUCCESS(status))
{
//Log Message
}
}

// Go to the next item on the list
hPdo = WdfFdoRetrieveNextStaticChild(hParentDevice, hPdo,WdfRetrievePresentChildren);
}

// Check to see if the list is empty
hPdo = WdfFdoRetrieveNextStaticChild( hParentDevice, NULL, WdfRetrievePresentChildren);
if (hPdo == NULL)
{
pDevExt->InstanceId = 0;
}

WdfFdoUnlockStaticChildListFromIteration(hParentDevice);

One thought that just jumped into my head is to determine if reader ids ever do match. I will be checking that.

Thanks,

Nik Twerdochlib
Software Developer

+1.601.607.8309 O
+1.866.522.8678 F

BOMGAR | Enterprise Remote Support™

One of the Fastest-Growing Technology Companies in America | Technology Fast 500™

What does

!wdfkd.wdfdevice 0xfff

Say when you have marked it missing but it is still present? Typically the root cause of this either there are still pending locks on the list OR the query device relations has not yet been sent because some other thread is blocking with the pnp lock held (typically due to a pnp state change operation happening like remove or add). Also, consider using a WDFCHILDLIST instead of static enumeration. There are simpler APIs for clearing out the list of reported children.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Nik Twerdochlib
Sent: Tuesday, March 27, 2012 3:51 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Question regard Device ID/Node

Let me first mention that I am not win32 driver guru, just a self-taught beginner.

I am creating a device within a driver, and assigning it a device id with WdfPdoInitAssignDeviceID(). Ultimately this will create a Node under the dev class for Smart Card Readers (in my case). Once the device is created and configured, I am calling WdfAddStaticChild() (which is where I think my problem is…) My question is that once I am done with the device, it is marked as missing but the Node still stays. This creates a problem since I can’t easily uninstall the driver since it still has active nodes; it looks like it is still in use, along with over time I could create a ton of nodes that are essentially dead. What can I do so that they are removed when I am done with the device?

This is what I am doing now for removal:
// Lock the list of children PDOs
WdfFdoLockStaticChildListForIteration(hParentDevice);
// Retrieve the first one
hPdo = WdfFdoRetrieveNextStaticChild( hParentDevice,NULL, WdfRetrievePresentChildren);
while (hPdo != NULL)
{
pPdoDevExt = GetPdoDevExt(hPdo);

// Compare the names
if (pPdoDevExt->DeviceInfo.ReaderId == ReaderId)
{
// We found the device of interest
status = WdfPdoMarkMissing(hPdo);
if (!NT_SUCCESS(status))
{
//Log Message
}
}

// Go to the next item on the list
hPdo = WdfFdoRetrieveNextStaticChild(hParentDevice, hPdo,WdfRetrievePresentChildren);
}

// Check to see if the list is empty
hPdo = WdfFdoRetrieveNextStaticChild( hParentDevice, NULL, WdfRetrievePresentChildren);
if (hPdo == NULL)
{
pDevExt->InstanceId = 0;
}

WdfFdoUnlockStaticChildListFromIteration(hParentDevice);

One thought that just jumped into my head is to determine if reader ids ever do match. I will be checking that.

Thanks,

Nik Twerdochlib
Software Developer

+1.601.607.8309 O
+1.866.522.8678 F

BOMGAR | Enterprise Remote Support™

One of the Fastest-Growing Technology Companies in America | Technology Fast 500™


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