symbolic names for multiple instances of devices

  • Follow


Hi,

I've got a bus driver that (statically) enumerates a number of child
devices (PDOs) for which I have a corresponding driver. FWIW this is a
*closed* system and devices don't go away.

I want to create ordered Symbolic names for each device - ie. MyDev0,
MyDev1, ... etc, specifically so an application can open them
unambiguously using CreateFile("MyDev0")... (ie I need to absolutely know
which is 0, which is 1) etc...

Right now in AddDevice() I'm calling:

WdfDeviceInitAssignName("\\Device\\MyDev%d")
WdfDeviceCreate()
WdfDeviceCreateSymbolicLink("\\DosDevices\\MyDev%d")

However, I need the device *number* to insert into the assigned name and
subsequently the symbolic link. How can I get this - especially *before* I
call WdfDeviceCreate() ???

Can I create the SymbolicLink in EvtPrepareHw()? If so, I still have the
problem with the assigned name, since I read that you can't call
CreateSymbolicLink() if you don't call InitAssignName() - although it does
appear to work for me?!?

Or is there a better way?

Regards,

-- 
Mark McDougall, Engineer
Virtual Logic Pty Ltd, <http://www.vl.com.au>
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
0
Reply Mark 4/19/2010 2:43:54 PM

RtlUnicodeStringPrintf will format the string for you ala printf style 
formatting.  you can create a symbolic link name to an unnamed FDO if you 
want, KMDF will just create the symlink to the PDO name for you.  remember 
that the number or even the name itself on the FDO has no relationship with 
the symlink name, your dev name could be \Device\FooBar999 and the symlink 
could be \DosDevices\BarFoo100.

d
-- 

This posting is provided "AS IS" with no warranties, and confers no rights.


"Mark McDougall" <markm@vl.com.au> wrote in message 
news:#0GT#683KHA.1624@TK2MSFTNGP06.phx.gbl...
> Hi,
>
> I've got a bus driver that (statically) enumerates a number of child
> devices (PDOs) for which I have a corresponding driver. FWIW this is a
> *closed* system and devices don't go away.
>
> I want to create ordered Symbolic names for each device - ie. MyDev0,
> MyDev1, ... etc, specifically so an application can open them
> unambiguously using CreateFile("MyDev0")... (ie I need to absolutely know
> which is 0, which is 1) etc...
>
> Right now in AddDevice() I'm calling:
>
> WdfDeviceInitAssignName("\\Device\\MyDev%d")
> WdfDeviceCreate()
> WdfDeviceCreateSymbolicLink("\\DosDevices\\MyDev%d")
>
> However, I need the device *number* to insert into the assigned name and
> subsequently the symbolic link. How can I get this - especially *before* I
> call WdfDeviceCreate() ???
>
> Can I create the SymbolicLink in EvtPrepareHw()? If so, I still have the
> problem with the assigned name, since I read that you can't call
> CreateSymbolicLink() if you don't call InitAssignName() - although it does
> appear to work for me?!?
>
> Or is there a better way?
>
> Regards,
>
> -- 
> Mark McDougall, Engineer
> Virtual Logic Pty Ltd, <http://www.vl.com.au>
> 21-25 King St, Rockdale, 2216
> Ph: +612-9599-3255 Fax: +612-9599-3266 

0
Reply Doron 4/19/2010 5:46:21 PM


> However, I need the device *number* to insert into the assigned name =
and
> subsequently the symbolic link

Use the global counter and ++ it on each creation.

But it is much better to use device interfaces instead.

--=20
Maxim S. Shatskih
Windows DDK MVP
maxim@storagecraft.com
http://www.storagecraft.com

0
Reply Maxim 4/19/2010 7:18:11 PM

"Maxim S. Shatskih" <maxim@storagecraft.com.no.spam> wrote in message 
news:eA9COU$3KHA.5588@TK2MSFTNGP06.phx.gbl...
>> However, I need the device *number* to insert into the assigned name and
>> subsequently the symbolic link
>
> Use the global counter and ++ it on each creation.
>
> But it is much better to use device interfaces instead.

Maybe, combination of both: Device interface to detect all the devices, then 
query some property
(stored in the registry, or call the driver) to get the numbers assigned to 
devices.
-- pa

> -- 
> Maxim S. Shatskih
> Windows DDK MVP
> maxim@storagecraft.com
> http://www.storagecraft.com
> 
0
Reply Pavel 4/19/2010 10:37:12 PM

Maxim S. Shatskih wrote:

> Use the global counter and ++ it on each creation.

I have subsequently discovered that this is how the serial driver does it.
In this case, IIUC there's no guaranteed correlation between the first PDO
enumerated and the first AddDevice() call - ie. a PDO enumerated as MyPdo2
could conceivably get its AddDevice() called first, and the
Assigned/Symbolic name could be "MyDev0" - right?

FTR I think I can live with this anyway, since I can store the port number
(global counter) in the FDO device extension in AddDevice() and then
assign the physical resources in EvtPrepareHw() based on this port number.

> But it is much better to use device interfaces instead.

Ugghh!! No thanks. These are actually custom communications ports and they
will never need to do detection. It's a closed system and each port has a
predetermined connection to the outside world.

Regards,

-- 
Mark McDougall, Engineer
Virtual Logic Pty Ltd, <http://www.vl.com.au>
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
0
Reply Mark 4/20/2010 12:35:42 AM

Mark McDougall <markm@vl.com.au> wrote:
>
>> But it is much better to use device interfaces instead.
>
>Ugghh!! No thanks. These are actually custom communications ports and they
>will never need to do detection. It's a closed system and each port has a
>predetermined connection to the outside world.

Your response indicates that you do not know what device interfaces are.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
0
Reply Tim 4/20/2010 6:41:06 AM

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<blockquote cite="mid:%230GT%23683KHA.1624@TK2MSFTNGP06.phx.gbl"
 type="cite">
  <p wrap="">Or is there a better way?<br>
  </p>
</blockquote>
<p>Yes.&nbsp; Device interfaces.&nbsp; You register the interface for each
device, and there's <em>already</em> a library of <code>SetupDiXXX()</code>
functions that allow application-mode code to enumerate all devices
exporting that interface.&nbsp; All that your application-mode code needs to
know is the GUID used by your kernel-mode code to register the
interface for each device.&nbsp; Device interface names are stable across
reboots (as long as the hardware doesn't physically move around, of
course); don't require bodges in your driver such as incrementing
global counters to generate names and handling name collisions; don't
require special knowledge in application-mode code of idiosyncratic
naming schemes used by kernel-mode code; and incorporate bus addresses
in <a
 href="http://msdn.microsoft.com/en-us/library/ff547656%28VS.85%29.aspx">instance
IDs</a>, retrievable in application-mode code via <code><a
 href="http://msdn.microsoft.com/en-us/library/ff551106%28VS.85%29.aspx">SetupDiGetDeviceInstanceID()</a></code>.&nbsp;
Don't reinvent this wheel.</p>
</body>
</html>
0
Reply Jonathan 4/20/2010 11:12:55 AM

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<blockquote
 cite="mid:FBD08674-6453-40F3-80EC-204918E9D0B8@microsoft.com"
 type="cite">
  <blockquote type="cite">
    <p>But it is much better to use device interfaces instead.
    </p>
  </blockquote>
  <p>Maybe, combination of both: Device interface to detect all the
devices, then query some property
(stored in the registry, or call the driver) to get the numbers
assigned to devices.
  </p>
</blockquote>
<p>There's no need for the global counter for the latter.&nbsp; M.
MacDougall wants to be able to find the specific bus address of the
device.&nbsp; <a
 href="http://msdn.microsoft.com/en-us/library/ff547656%28VS.85%29.aspx">Instance
IDs</a> already incorporate that, and they are retrievable by
application-mode code via <code><a
 href="http://msdn.microsoft.com/en-us/library/ff551106%28VS.85%29.aspx">SetupDiGetDeviceInstanceID()</a></code>.&nbsp;
Since it's xyr own bus driver, xe has full control over the instance
IDs in the first place, too.<br>
</p>
</body>
</html>
0
Reply Jonathan 4/20/2010 11:17:29 AM

> In this case, IIUC there's no guaranteed correlation between the first =
PDO
> enumerated=20

Enumeration order of the PDOs is not defined at all.

> FTR I think I can live with this anyway, since I can store the port =
number
> (global counter) in the FDO device extension in AddDevice() and then
> assign the physical resources in EvtPrepareHw() based on this port =
number.

Correct.

--=20
Maxim S. Shatskih
Windows DDK MVP
maxim@storagecraft.com
http://www.storagecraft.com

0
Reply Maxim 4/21/2010 12:04:27 AM

I don't know if I quite understand your need, but maybe you can
preallocate your own array of device structure areas in the nonpaged
pool, have an atomic counter that increments for every device you
create, and store a pointer to its Device Object in the corresponding
slot. When the Open request comes your driver gets control anyway, and
from there you can quickly figure out which device you're talking
about.

In other words, devices are primarily identified by your own
structure, not by the Device Object - you just use the Device Object
to keep Windows quiet. Instead of embedding your device-unique storage
in the Device Object as a device extension,  you just maintain your
own array of device structures, and do not include a device extension
in your device object.

I use a variation of this technique in my driver, and I have
successfully run production volume through up to 6-board
configurations.

I do not like device interfaces - correct me if I'm wrong - because
they require a nonstandard API in the user side.


Hope this helps,


Alberto.




On Apr 19, 8:35=A0pm, Mark McDougall <ma...@vl.com.au> wrote:
> Maxim S. Shatskih wrote:
> > Use the global counter and ++ it on each creation.
>
> I have subsequently discovered that this is how the serial driver does it=
..
> In this case, IIUC there's no guaranteed correlation between the first PD=
O
> enumerated and the first AddDevice() call - ie. a PDO enumerated as MyPdo=
2
> could conceivably get its AddDevice() called first, and the
> Assigned/Symbolic name could be "MyDev0" - right?
>
> FTR I think I can live with this anyway, since I can store the port numbe=
r
> (global counter) in the FDO device extension in AddDevice() and then
> assign the physical resources in EvtPrepareHw() based on this port number=
..
>
> > But it is much better to use device interfaces instead.
>
> Ugghh!! No thanks. These are actually custom communications ports and the=
y
> will never need to do detection. It's a closed system and each port has a
> predetermined connection to the outside world.
>
> Regards,
>
> --
> Mark McDougall, Engineer
> Virtual Logic Pty Ltd, <http://www.vl.com.au>
> 21-25 King St, Rockdale, 2216
> Ph: +612-9599-3255 Fax: +612-9599-3266

0
Reply alberto 4/21/2010 6:06:55 PM

> I do not like device interfaces - correct me if I'm wrong - because
> they require a nonstandard API in the user side.

what is non standard about using SetupAPI to enumerate the device interface?

-- 

This posting is provided "AS IS" with no warranties, and confers no rights.


"alberto" <amoreira@ieee.org> wrote in message 
news:01938386-bc6e-4d7a-ba45-6c8112d1f817@x38g2000vbx.googlegroups.com...
>
> I don't know if I quite understand your need, but maybe you can
> preallocate your own array of device structure areas in the nonpaged
> pool, have an atomic counter that increments for every device you
> create, and store a pointer to its Device Object in the corresponding
> slot. When the Open request comes your driver gets control anyway, and
> from there you can quickly figure out which device you're talking
> about.
>
> In other words, devices are primarily identified by your own
> structure, not by the Device Object - you just use the Device Object
> to keep Windows quiet. Instead of embedding your device-unique storage
> in the Device Object as a device extension,  you just maintain your
> own array of device structures, and do not include a device extension
> in your device object.
>
> I use a variation of this technique in my driver, and I have
> successfully run production volume through up to 6-board
> configurations.
>
> I do not like device interfaces - correct me if I'm wrong - because
> they require a nonstandard API in the user side.
>
>
> Hope this helps,
>
>
> Alberto.
>
>
>
>
> On Apr 19, 8:35 pm, Mark McDougall <ma...@vl.com.au> wrote:
>> Maxim S. Shatskih wrote:
>> > Use the global counter and ++ it on each creation.
>>
>> I have subsequently discovered that this is how the serial driver does 
>> it.
>> In this case, IIUC there's no guaranteed correlation between the first 
>> PDO
>> enumerated and the first AddDevice() call - ie. a PDO enumerated as 
>> MyPdo2
>> could conceivably get its AddDevice() called first, and the
>> Assigned/Symbolic name could be "MyDev0" - right?
>>
>> FTR I think I can live with this anyway, since I can store the port 
>> number
>> (global counter) in the FDO device extension in AddDevice() and then
>> assign the physical resources in EvtPrepareHw() based on this port 
>> number.
>>
>> > But it is much better to use device interfaces instead.
>>
>> Ugghh!! No thanks. These are actually custom communications ports and 
>> they
>> will never need to do detection. It's a closed system and each port has a
>> predetermined connection to the outside world.
>>
>> Regards,
>>
>> --
>> Mark McDougall, Engineer
>> Virtual Logic Pty Ltd, <http://www.vl.com.au>
>> 21-25 King St, Rockdale, 2216
>> Ph: +612-9599-3255 Fax: +612-9599-3266
> 
0
Reply Doron 4/21/2010 9:27:34 PM

"Doron Holan [MSFT]" <doron.holan@online.microsoft.com> wrote in message 
news:ufuG7lZ4KHA.5880@TK2MSFTNGP04.phx.gbl...
>> I do not like device interfaces - correct me if I'm wrong - because
>> they require a nonstandard API in the user side.
>
> what is non standard about using SetupAPI to enumerate the device 
> interface?

No such thing in posix :-)

-- pa

> "alberto" <amoreira@ieee.org> wrote in message 
> news:01938386-bc6e-4d7a-ba45-6c8112d1f817@x38g2000vbx.googlegroups.com...
>>
>> I don't know if I quite understand your need, but maybe you can
>> preallocate your own array of device structure areas in the nonpaged
>> pool, have an atomic counter that increments for every device you
>> create, and store a pointer to its Device Object in the corresponding
>> slot. When the Open request comes your driver gets control anyway, and
>> from there you can quickly figure out which device you're talking
>> about.
>>
>> In other words, devices are primarily identified by your own
>> structure, not by the Device Object - you just use the Device Object
>> to keep Windows quiet. Instead of embedding your device-unique storage
>> in the Device Object as a device extension,  you just maintain your
>> own array of device structures, and do not include a device extension
>> in your device object.
>>
>> I use a variation of this technique in my driver, and I have
>> successfully run production volume through up to 6-board
>> configurations.
>>
>> I do not like device interfaces - correct me if I'm wrong - because
>> they require a nonstandard API in the user side.
>>
>>
>> Hope this helps,
>>
>>
>> Alberto.
>>
>>
>>
>>
>> On Apr 19, 8:35 pm, Mark McDougall <ma...@vl.com.au> wrote:
>>> Maxim S. Shatskih wrote:
>>> > Use the global counter and ++ it on each creation.
>>>
>>> I have subsequently discovered that this is how the serial driver does 
>>> it.
>>> In this case, IIUC there's no guaranteed correlation between the first 
>>> PDO
>>> enumerated and the first AddDevice() call - ie. a PDO enumerated as 
>>> MyPdo2
>>> could conceivably get its AddDevice() called first, and the
>>> Assigned/Symbolic name could be "MyDev0" - right?
>>>
>>> FTR I think I can live with this anyway, since I can store the port 
>>> number
>>> (global counter) in the FDO device extension in AddDevice() and then
>>> assign the physical resources in EvtPrepareHw() based on this port 
>>> number.
>>>
>>> > But it is much better to use device interfaces instead.
>>>
>>> Ugghh!! No thanks. These are actually custom communications ports and 
>>> they
>>> will never need to do detection. It's a closed system and each port has 
>>> a
>>> predetermined connection to the outside world.
>>>
>>> Regards,
>>>
>>> --
>>> Mark McDougall, Engineer
>>> Virtual Logic Pty Ltd, <http://www.vl.com.au>
>>> 21-25 King St, Rockdale, 2216
>>> Ph: +612-9599-3255 Fax: +612-9599-3266
>> 
0
Reply Pavel 4/21/2010 9:54:22 PM

> No such thing in posix :-)

POSIX is non-standard, it violates the Microsoft's tradition :-)

--=20
Maxim S. Shatskih
Windows DDK MVP
maxim@storagecraft.com
http://www.storagecraft.com

0
Reply Maxim 4/22/2010 12:42:17 PM

The problem is, the SetupAPI is Windows-unique. Doesn't exist in
Linux, Solaris, or MacOS. Forces me to write the application or test
program more than once, meaning, I have to spend additional time and
money to satisfy the vagaries of the OS.

And, believe me, I like ifstream/ofstream way better!


Alberto.



On Apr 21, 5:27=A0pm, "Doron Holan [MSFT]"
<doron.ho...@online.microsoft.com> wrote:
> > I do not like device interfaces - correct me if I'm wrong - because
> > they require a nonstandard API in the user side.
>
> what is non standard about using SetupAPI to enumerate the device interfa=
ce?
>
> --
>
> This posting is provided "AS IS" with no warranties, and confers no right=
s
>
0
Reply alberto 4/22/2010 4:49:45 PM

>And, believe me, I like ifstream/ofstream way better!

For me, the use of << or >> for file reads and writes is schizoid, but =
well, this is a matter of taste.

I never use these libraries, only printf and fprintf and =
StringCb/CchPrintf

POSIX API is OK, so is Win32.

--=20
Maxim S. Shatskih
Windows DDK MVP
maxim@storagecraft.com
http://www.storagecraft.com

0
Reply Maxim 4/22/2010 7:37:57 PM

alberto wrote:

> I don't know if I quite understand your need, 

You do, but I've found the solution, which also solved another problem
with friendly names in Device Manager.

Firstly, the bus driver, which enumerates the PDOs, sets the UINumber
member of the PnPCaps structure. For good measure, I also recorded it in
the PDO's device-extension.

The child device FDO then queries the UINumber device property to both
name the device and create a symbolic link. Again for good measure, I
recorded this in the child device FDO device-extension.

Lastly, the coinstaller also queries the UINumber from the registry to use
for the friendly name in Device Manager.

Thusly, the bus driver, the child PDO, child FDO, FDO symbolic name and
Device Manager friendly name all use the same indexing for the child devices!

Phew! :)

-- 
Mark McDougall, Engineer
Virtual Logic Pty Ltd, <http://www.vl.com.au>
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
0
Reply Mark 4/23/2010 7:21:14 AM

15 Replies
580 Views

(page loaded in 0.553 seconds)

Similiar Articles:































7/23/2012 11:56:12 AM


Reply: