[KMDF 1.9] How to restrict the number of device interface opened

Hi all,

I develop a smartcard reader multiSlot ( multiple device interface )
I have a reader with 3 slot, so I call 3 times WdfDeviceCreateDeviceInterface.
I have used the blog of Doron for distinguish what is the device interface presented.
But now, I would like to know how to proceed for restrict the number of device interface created ?

Or a way for cancel the “createFile” from user application and use only the interface already created.

Thanks in advance,

Best regards,

Moulefrite

Do you mean how to restrict the number of handles opened? Probably one handle per interface instance ? If so, keep a count of open handles per slot that you test in evtdevicecreatefile. If the max is met, complete the request with failure. Otherwise inc the count and complete it successfully . On evtfileclose, decrement the count

d

dent from a phine with no keynoard

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Wednesday, February 23, 2011 7:41 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] [KMDF 1.9] How to restrict the number of device interface opened

Hi all,

I develop a smartcard reader multiSlot ( multiple device interface )
I have a reader with 3 slot, so I call 3 times WdfDeviceCreateDeviceInterface.
I have used the blog of Doron for distinguish what is the device interface presented.
But now, I would like to know how to proceed for restrict the number of device interface created ?

Or a way for cancel the “createFile” from user application and use only the interface already created.

Thanks in advance,

Best regards,

Moulefrite


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

Yes Doron it’s exactly one handle by device interface.
Now I have found a solution.

For those that encounter the same problem :

evtDeviceAdd
{
devContext->SlotContext[i]->OpenHandleCount = 0;
}

evtFileCreate
{
ULONG PrevOpenHandleCount = InterlockedCompareExchange (
&deviceExtension->OpenHandleCount,
TRUE, // New value
FALSE); // Previous value

if(PrevOpenHandleCount == 0)
{
BulkUsb_DebugPrint(1, (“BulkUsb_DispatchCreate - device not opened\n”));
slotContext->OpenHandleCount = 1;
WdfRequestComplete(Request, STATUS_SUCCESS);
}
else
{
WdfRequestComplete(Request, STATUS_UNSUCCESSFUL);
}
}
}

Thanks a lot Doron for your help

Best regards,

Moulefrite

xxxxx@hotmail.com wrote:

Yes Doron it’s exactly one handle by device interface.
Now I have found a solution.

For those that encounter the same problem :

evtDeviceAdd
{
devContext->SlotContext[i]->OpenHandleCount = 0;
}

KMDF will do this for you automatically if you call
WdfDeviceInitSetExclusive() when you create your device.


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

Thanks Tim for your reply,
But I have tried to use WdfDeviceInitSetExclusive, but the problem is I have 3 device interface.
And If I add this to WdfDeviceInitSetExclusive(TRUE) Just one interface is created.
I suppose this function is useful for a driver with just one device interface.

Thanks a lot Tim and Doron for your help

Best regards,

Moulefrite

You are doing something wrong since WdfDeviceInitSetExclusive works on a
per device basis. Are creating your interfaces for the same device?

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@hotmail.com” wrote in message
news:xxxxx@ntdev:

> Thanks Tim for your reply,
> But I have tried to use WdfDeviceInitSetExclusive, but the problem is I have 3 device interface.
> And If I add this to WdfDeviceInitSetExclusive(TRUE) Just one interface is created.
> I suppose this function is useful for a driver with just one device interface.
>
> Thanks a lot Tim and Doron for your help
>
> Best regards,
>
> Moulefrite

He is not doing something wrong. He has 3 instances of the same device interface on his device. He wants exclusivity on each interface, basically a namespace where each name is exclusive. WdfDeviceInitSetExclusive creates exclusivity across the entire device, regardless of namespace. With that said, this is kind of weird, at least the use of TRUE and FALSE with a Count variable

ULONG PrevOpenHandleCount = InterlockedCompareExchange (
&deviceExtension->OpenHandleCount,
TRUE, // New value
FALSE); // Previous value

And I think you meant
& devContext->SlotContext[i]->OpenHandleCount,

For the first param

d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Wednesday, February 23, 2011 10:06 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] [KMDF 1.9] How to restrict the number of device interface opened

You are doing something wrong since WdfDeviceInitSetExclusive works on a per device basis. Are creating your interfaces for the same device?

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@hotmail.com” wrote in message
news:xxxxx@ntdev:

> Thanks Tim for your reply,
> But I have tried to use WdfDeviceInitSetExclusive, but the problem is I have 3 device interface.
> And If I add this to WdfDeviceInitSetExclusive(TRUE) Just one interface is created.
> I suppose this function is useful for a driver with just one device interface.
>
> Thanks a lot Tim and Doron for your help
>
> Best regards,
>
> Moulefrite


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

Yes Don I have created 3 device interfaces from the same wdfDevice.
Yes Doron that’s exactly what I’m doing.

Thanks a lot for your help

Best regards,

Moulefrite