Driver Problems? Questions? Issues?
Put OSR's experience to work for you! Contact us for assistance with:
  • Creating the right design for your requirements
  • Reviewing your existing driver code
  • Analyzing driver reliability/performance issues
  • Custom training mixed with consulting and focused directly on your specific areas of interest/concern.
Check us out. OSR, the Windows driver experts.

Upcoming OSR Seminars:

Writing WDF Drivers I: Core Concepts, Nashua, NH 15-19 May, 2017
Writing WDF Drivers II: Advanced Implementation Tech., Nashua, NH 23-26 May, 2017
Kernel Debugging and Crash Analysis, Dulles, VA 26-30 June, 2017
Windows Internals & Software Driver Development, Nashua, NH 24-28 July, 2017


Go Back   OSR Online Lists > ntdev
Welcome, Guest
You must login to post to this list
  Message 1 of 8  
09 May 17 09:14
Johnny Dakovo
xxxxxx@gmail.com
Join Date: 11 Nov 2016
Posts To This List: 12
Share information between two UMDF driver instances

Hello NTDEV, I have written a UMDF driver for my USB smartcard readers. What I want to do is to increment a "global" counter each time the driver loads the driver for the same smartcard reader brand and type, in order to be able to tell Windows which instance it is (when Windows issues an IOCTL_SMARTCARD_GET_ATTRIBUTE code SCARD_ATTR_DEVICE_UNIT). So I inside my driver I want to return SCARD_ATTR_DEVICE_UNIT "0" for the first reader of brand A and type B and "1" for the second reader of same brand and type. What is the most elegant way to do this? Currently I am tracking device instances and their indexes via the Windows registry. Is there a better way to do this inside the driver? The native Windows smartcard driver is also an UMDF driver. How does it solve this task?
  Message 2 of 8  
09 May 17 12:53
Tim Roberts
xxxxxx@probo.com
Join Date: 28 Jan 2005
Posts To This List: 11455
Share information between two UMDF driver instances

xxxxx@gmail.com wrote: > I have written a UMDF driver for my USB smartcard readers. What I want to do is to increment a "global" counter each time the driver loads the driver for the same smartcard reader brand and type, in order to be able to tell Windows which instance it is (when Windows issues an IOCTL_SMARTCARD_GET_ATTRIBUTE code SCARD_ATTR_DEVICE_UNIT). > > So I inside my driver I want to return SCARD_ATTR_DEVICE_UNIT "0" for the first reader of brand A and type B and "1" for the second reader of same brand and type. > > What is the most elegant way to do this? Currently I am tracking device instances and their indexes via the Windows registry. Is there a better way to do this inside the driver? You can use a simple global variable for this. If the concept of a global offends you, then add a context structure to your WDFDRIVER object and store the counter in your context. -- Tim Roberts, xxxxx@probo.com Providenza & Boekelheide, Inc.
  Message 3 of 8  
09 May 17 13:26
Johnny Dakovo
xxxxxx@gmail.com
Join Date: 11 Nov 2016
Posts To This List: 12
Share information between two UMDF driver instances

Hello Tim, I forgot to mention that I am using UMDF 1.11 because of backward compability reasons. Also, for each USB smartcard reader I connect, a separate WUDFHost.exe process is started (I can see them in the task manager). I already tried to use a global variable but it did not work, because I get different values when accessing it from different driver processes (which is logical). I am really wondering how Microsoft solved this. 2017-05-09 18:52 GMT+02:00 Tim Roberts <xxxxx@probo.com>: > xxxxx@gmail.com wrote: > > I have written a UMDF driver for my USB smartcard readers. What I want > to do is to increment a "global" counter each time the driver loads the > driver for the same smartcard reader brand and type, in order to be able to > tell Windows which instance it is (when Windows issues an > IOCTL_SMARTCARD_GET_ATTRIBUTE code SCARD_ATTR_DEVICE_UNIT). > > > > So I inside my driver I want to return SCARD_ATTR_DEVICE_UNIT "0" for > the first reader of brand A and type B and "1" for the second reader of > same brand and type. <...excess quoted lines suppressed...> --
  Message 4 of 8  
09 May 17 16:33
Tim Roberts
xxxxxx@probo.com
Join Date: 28 Jan 2005
Posts To This List: 11455
Share information between two UMDF driver instances

Johnny Dakovo wrote: > > I forgot to mention that I am using UMDF 1.11 because of backward > compability reasons. Also, for each USB smartcard reader I connect, a > separate WUDFHost.exe process is started (I can see them in the task > manager). I already tried to use a global variable but it did not > work, because I get different values when accessing it from different > driver processes (which is logical). I am really wondering how > Microsoft solved this. One way would be to use a memory-mapped file. Well, the mapping object gets a name, but the file does not need one. The technique is described here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366551.aspx There are also ways to declare one of your DLL's sections to be "shared data", which ends up being implemented in much the same way. -- Tim Roberts, xxxxx@probo.com Providenza & Boekelheide, Inc.
  Message 5 of 8  
10 May 17 07:42
matt sykes
xxxxxx@hotmail.com
Join Date:
Posts To This List: 202
Share information between two UMDF driver instances

Interproces communication. There are a number of solutions, Hooks are very effective (SetWindowsHookEx), windows messages (needs a window though), or writing to a file... Since the registry is just a file your current method has as much merit as any, so stick with it.
  Message 6 of 8  
10 May 17 11:42
Johnny Dakovo
xxxxxx@gmail.com
Join Date: 11 Nov 2016
Posts To This List: 12
Share information between two UMDF driver instances

This works great, thank you. 2017-05-09 22:32 GMT+02:00 Tim Roberts <xxxxx@probo.com>: > Johnny Dakovo wrote: > > > > I forgot to mention that I am using UMDF 1.11 because of backward > > compability reasons. Also, for each USB smartcard reader I connect, a > > separate WUDFHost.exe process is started (I can see them in the task > > manager). I already tried to use a global variable but it did not > > work, because I get different values when accessing it from different > > driver processes (which is logical). I am really wondering how > > Microsoft solved this. > <...excess quoted lines suppressed...> --
  Message 7 of 8  
18 May 17 08:26
Johnny Dakovo
xxxxxx@gmail.com
Join Date: 11 Nov 2016
Posts To This List: 12
Share information between two UMDF driver instances

However, this works if only readers are connected to my system, which are using my driver. There is inconsistency when I connect a reader which uses my driver and afterwards connect a reader which uses Windows native driver. The Windows driver will not see my memory-mapped file I created and apply index 0 for its device. I found out that, when the Windows driver is loaded it queries attributes SCARD_ATTR_VENDOR_IFD_TYPE, SCARD_ATTR_VENDOR_IFD_TYPE and SCARD_ATTR_DEVICE_UNIT from my driver (and from all other drivers currently loaded). I guess this way the Windows driver can know which device units are taken and apply a free one to its reader. Does anybody how I can query these attributes from all loaded smart card reader driver instances in my system? 2017-05-10 17:41 GMT+02:00 Johnny Dakovo <xxxxx@gmail.com>: > This works great, thank you. > > 2017-05-09 22:32 GMT+02:00 Tim Roberts <xxxxx@probo.com>: > >> Johnny Dakovo wrote: >> > >> > I forgot to mention that I am using UMDF 1.11 because of backward >> > compability reasons. Also, for each USB smartcard reader I connect, a >> > separate WUDFHost.exe process is started (I can see them in the task >> > manager). I already tried to use a global variable but it did not <...excess quoted lines suppressed...> --
  Message 8 of 8  
18 May 17 10:32
Doron Holan
xxxxxx@microsoft.com
Join Date: 08 Sep 2005
Posts To This List: 10016
Share information between two UMDF driver instances

Are you using smclib or equivalent? None of the other smart card drivers query global state to report a unit id. This should be something you can do without global state. Bent from my phone ________________________________ From: xxxxx@lists.osr.com <xxxxx@lists.osr.com> on behalf of Johnny Dakovo <xxxxx@gmail.com> Sent: Thursday, May 18, 2017 5:25:21 AM To: Windows System Software Devs Interest List Subject: Re: [ntdev] Share information between two UMDF driver instances However, this works if only readers are connected to my system, which are using my driver. There is inconsistency when I connect a reader which uses my driver and afterwards connect a reader which uses Windows native driver. The Windows driver will not see my memory-mapped file I created and apply index 0 for its device. I found out that, when the Windows driver is loaded it queries attributes SCARD_ATTR_VENDOR_IFD_TYPE, SCARD_ATTR_VENDOR_IFD_TYPE and SCARD_ATTR_DEVICE_UNIT from my driver (and from all other drivers currently loaded). I guess this way the Windows driver can know which device units are taken and apply a free one to its reader. Does anybody how I can query these attributes from all loaded smart card reader driver instances in my system? 2017-05-10 17:41 GMT+02:00 Johnny Dakovo <xxxxx@gmail.com<mailto:xxxxx@gmail.com>>: This works great, thank you. 2017-05-09 22:32 GMT+02:00 Tim Roberts <xxxxx@probo.com<mailto:xxxxx@probo.com>>: Johnny Dakovo wrote: > > I forgot to mention that I am using UMDF 1.11 because of backward > compability reasons. Also, for each USB smartcard reader I connect, a > separate WUDFHost.exe process is started (I can see them in the task > manager). I already tried to use a global variable but it did not > work, because I get different values when accessing it from different > driver processes (which is logical). I am really wondering how > Microsoft solved this. One way would be to use a memory-mapped file. Well, the mapping object gets a name, but the file does not need one. The technique is described here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366551.aspx<https://na 01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmsdn.microsoft.com%2Fen-us %2Flibrary%2Fwindows%2Fdesktop%2Faa366551.aspx&data=02%7C01%7CDoron.Holan%40micro soft.com%7C9f78dd65f2444c931b2008d49de8fee0%7C72f988bf86f141af91ab2d7cd011db47%7C 1%7C0%7C636307071422051077&sdata=PJyQxbGPnTTqW%2F09j9C6D4pAe7ldOKXT1M8GMLRUZ20%3D &reserved=0> There are also ways to declare one of your DLL's sections to be "shared data", which ends up being implemented in much the same way. -- Tim Roberts, xxxxx@probo.com<mailto:xxxxx@probo.com> Providenza & Boekelheide, Inc. --- NTDEV is sponsored by OSR Visit the list online at: <http://www.osronline.com/showlists.cfm?list=ntdev<https://na01.safelinks.protect ion.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fshowlists.cfm%3Flist%3Dntde v&data=02%7C01%7CDoron.Holan%40microsoft.com%7C9f78dd65f2444c931b2008d49de8fee0%7 C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636307071422051077&sdata=EXzCI75i3qu1 N0dP2QLWlFwjMpBEtDl62xXnNttK%2FWI%3D&reserved=0>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers! Details at <http://www.osr.com/seminars<https://na01.safelinks.protection.outlook.com/?url=h ttp%3A%2F%2Fwww.osr.com%2Fseminars&data=02%7C01%7CDoron.Holan%40microsoft.com%7C9 f78dd65f2444c931b2008d49de8fee0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6363 07071422051077&sdata=Ahyi1%2BG99OTiRHMBHK4kgESj9%2Bspr8NCW2RWSCLv5u8%3D&reserved= 0>> To unsubscribe, visit the List Server section of OSR Online at <http://www.osronline.com/page.cfm?name=ListServer<https://na01.safelinks.protect ion.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fpage.cfm%3Fname%3DListServe r&data=02%7C01%7CDoron.Holan%40microsoft.com%7C9f78dd65f2444c931b2008d49de8fee0%7 C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636307071422051077&sdata=k6Q2ZiNG6sHL Z4Z7MNLfhRiAeiRtGOF%2FdLpcSfrUywY%3D&reserved=0>> --- NTDEV is sponsored by OSR Visit the list online at: MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers! Details at To unsubscribe, visit the List Server section of OSR Online at --
Posting Rules  
You may not post new threads
You may not post replies
You may not post attachments
You must login to OSR Online AND be a member of the ntdev list to be able to post.

All times are GMT -5. The time now is 03:13.


Copyright ©2015, OSR Open Systems Resources, Inc.
Based on vBulletin Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Modified under license