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.

Monthly Seminars at OSR Headquarters

East Coast USA
Windows Internals and SW Drivers, Dulles (Sterling) VA, 13 November 2017

Kernel Debugging & Crash Analysis for Windows, Nashua (Amherst) NH, 4 December 2017

Writing WDF Drivers I: Core Concepts, Nashua (Amherst) NH, 8 January 2018

WDF Drivers II: Advanced Implementation Techniques, Nashua (Amherst) NH, 15 January 2018


Go Back   OSR Online Lists > ntdev
Welcome, Guest
You must login to post to this list
  Message 1 of 4  
12 Jan 18 15:03
makrurisan makkeln
xxxxxx@x-publisher.com
Join Date: 12 Jan 2018
Posts To This List: 9
FW: Windows Filter driver on different keyboards

Hi All, I am writing an filter driver and want to attach the filter to more than one physical keyboard in the system. If I attach the filter to the first keyboard "\Device\KeyboardClass0" it works fine but it works not for the other keyboards. The IoAttachDevice failed for "\Device\KeyboardClass1". The same with other class. I have attached 3 physical keyboard. Now I have changed the creation of the device to work with IoCreateFile. The routines create and attach my device but now in the DispatchRead the return IoCallDriver(pDevExt->kbdDevice, Irp); ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension) the "kbdDevice" is NULL. The function status = IoAttachDeviceToDeviceStackSafe(pDevObj, pLBKdev, &pDevExt->kbdDevice); calls correctly at the time of creation. It worked before the modification. Now the routine which create and attach the device: RtlInitUnicodeString(&devNameFlt, L"\\Device\\KeyboardClass1"); RtlInitUnicodeString(&devName, L"\\Device\\MultikeyboardCnt"); status = IoCreateDevice(pDriverObject, sizeof(DEVICE_EXTENSION), &devName, FILE_DEVICE_KEYBOARD, SYNCHRONIZE, FALSE, &pDevObj); if (!NT_SUCCESS(status)) { DbgPrint("%s, IoCreateDevice failed:0x%0x\n", __FUNCTION__, status); return status; } HANDLE hFile; OBJECT_ATTRIBUTES oa = { sizeof(oa), 0, 0, OBJ_CASE_INSENSITIVE }; oa.ObjectName = &devNameFlt; IO_STATUS_BLOCK iosb; status = IoCreateFile(&hFile, SYNCHRONIZE, &oa, &iosb, 0, 0, FILE_SHARE_VALID_FLAGS, FILE_OPEN, 0, 0, 0, CreateFileTypeNone, 0, IO_ATTACH_DEVICE); if (!NT_SUCCESS(status)) { DbgPrint("%s, IoCreateFile failed to call:0x%0x\n", __FUNCTION__, status); return status; } /* Get File Object */ PFILE_OBJECT LocalFileObject; status = ObReferenceObjectByHandle(hFile, 0, *IoFileObjectType, KernelMode, (PVOID*)&LocalFileObject, NULL); pLBKdev = IoGetRelatedDeviceObject(LocalFileObject); DbgPrint("%s at IoCreateFile ok\n", __FUNCTION__); ObReferenceObject(pLBKdev); /* * Retrieve device extension pointer from device object */ pDevExt = (PDEVICE_EXTENSION)pLBKdev->DeviceExtension; status = IoAttachDeviceToDeviceStackSafe(pDevObj, pLBKdev, &pDevExt->kbdDevice); if (status != STATUS_SUCCESS) { DbgPrint("IoGetDeviceObjectPointer failed with error = 0x%0x\n", status); goto cleanup_failure; } pDevObj->Flags |= DO_BUFFERED_IO; pDevObj->Flags &= ~DO_DEVICE_INITIALIZING; /* * Create the symbolic link name, this is not mandatory * but can be helpful for user mode apps to communicate */ status = IoCreateSymbolicLink(&symLinkNameFlt, &devNameFlt); if (!NT_SUCCESS(status)) { // if it fails now, must delete Device object DbgPrint("IoCreateSymbolicLink failed with error = 0x%0x\n", status); goto cleanup_failure; } --
  Message 2 of 4  
12 Jan 18 15:25
Don Burn
xxxxxx@windrvr.com
Join Date: 23 Feb 2011
Posts To This List: 1376
FW: Windows Filter driver on different keyboards

If you are going to do a filter driver, you should be Plug and Play. Your approach of using IoCreateFile and trying to attach to the is not going to work. Take a look at the generic filter in the Toaster sample of the WDK, and start there. If you make the filter a class filter, you will attach to all keyboards. Don Burn Windows Driver Consulting Website: <http://www.windrvr.com> http://www.windrvr.com From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@x-publisher.com Sent: Friday, January 12, 2018 3:03 PM To: Windows System Software Devs Interest List <xxxxx@lists.osr.com> Subject: [ntdev] FW: Windows Filter driver on different keyboards Hi All, I am writing an filter driver and want to attach the filter to more than one physical keyboard in the system. If I attach the filter to the first keyboard "\Device\KeyboardClass0" it works fine but it works not for the other keyboards. The IoAttachDevice failed for "\Device\KeyboardClass1". The same with other class. I have attached 3 physical keyboard. Now I have changed the creation of the device to work with IoCreateFile. The routines create and attach my device but now in the DispatchRead the return IoCallDriver(pDevExt->kbdDevice, Irp); ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension) the "kbdDevice" is NULL. The function status = IoAttachDeviceToDeviceStackSafe(pDevObj, pLBKdev, &pDevExt->kbdDevice); calls correctly at the time of creation. It worked before the modification. Now the routine which create and attach the device: RtlInitUnicodeString(&devNameFlt, L"\\Device\\KeyboardClass1 <file:///\\Device\KeyboardClass1> "); RtlInitUnicodeString(&devName, L"\\Device\\MultikeyboardCnt <file:///\\Device\MultikeyboardCnt> "); status = IoCreateDevice(pDriverObject, sizeof(DEVICE_EXTENSION), &devName, FILE_DEVICE_KEYBOARD, SYNCHRONIZE, FALSE, &pDevObj); if (!NT_SUCCESS(status)) { DbgPrint("%s, IoCreateDevice failed:0x%0x\n", __FUNCTION__, status); return status; } HANDLE hFile; OBJECT_ATTRIBUTES oa = { sizeof(oa), 0, 0, OBJ_CASE_INSENSITIVE }; oa.ObjectName = &devNameFlt; IO_STATUS_BLOCK iosb; status = IoCreateFile(&hFile, SYNCHRONIZE, &oa, &iosb, 0, 0, FILE_SHARE_VALID_FLAGS, FILE_OPEN, 0, 0, 0, CreateFileTypeNone, 0, IO_ATTACH_DEVICE); if (!NT_SUCCESS(status)) { DbgPrint("%s, IoCreateFile failed to call:0x%0x\n", __FUNCTION__, status); return status; } /* Get File Object */ PFILE_OBJECT LocalFileObject; status = ObReferenceObjectByHandle(hFile, 0, *IoFileObjectType, KernelMode, (PVOID*)&LocalFileObject, NULL); pLBKdev = IoGetRelatedDeviceObject(LocalFileObject); DbgPrint("%s at IoCreateFile ok\n", __FUNCTION__); ObReferenceObject(pLBKdev); /* * Retrieve device extension pointer from device object */ pDevExt = (PDEVICE_EXTENSION)pLBKdev->DeviceExtension; status = IoAttachDeviceToDeviceStackSafe(pDevObj, pLBKdev, &pDevExt->kbdDevice); if (status != STATUS_SUCCESS) { DbgPrint("IoGetDeviceObjectPointer failed with error = 0x%0x\n", status); goto cleanup_failure; } pDevObj->Flags |= DO_BUFFERED_IO; pDevObj->Flags &= ~DO_DEVICE_INITIALIZING; /* * Create the symbolic link name, this is not mandatory * but can be helpful for user mode apps to communicate */ status = IoCreateSymbolicLink(&symLinkNameFlt, &devNameFlt); if (!NT_SUCCESS(status)) { // if it fails now, must delete Device object DbgPrint("IoCreateSymbolicLink failed with error = 0x%0x\n", status); goto cleanup_failure; } --- NTDEV is sponsored by OSR Visit the list online at: <http://www.osronline.com/showlists.cfm?list=ntdev> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers! Details at <http://www.osr.com/seminars> To unsubscribe, visit the List Server section of OSR Online at <http://www.osronline.com/page.cfm?name=ListServer> --
  Message 3 of 4  
12 Jan 18 15:51
Doron Holan
xxxxxx@microsoft.com
Join Date: 08 Sep 2005
Posts To This List: 10129
FW: Windows Filter driver on different keyboards

To echo what don said, if you install yourself as a class filter driver you will be inserted into all stacks. The legacy names (\device\keyboardclassN) you are using to open devices are problematic and not guaranteed to be sequential (their may be gaps) and you really need to be in the stack as it starts, not afterwards. There is a kbfiltr example in git https://github.com/Microsoft/Windows-driver-samples/tree/master/input/kbfiltr which is written as a device upper filter, but it will work as is as a class filter and you just need to change how it is installed. d From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@windrvr.com Sent: Friday, January 12, 2018 12:25 PM To: Windows System Software Devs Interest List <xxxxx@lists.osr.com> Subject: RE: [ntdev] FW: Windows Filter driver on different keyboards If you are going to do a filter driver, you should be Plug and Play. Your approach of using IoCreateFile and trying to attach to the is not going to work. Take a look at the generic filter in the Toaster sample of the WDK, and start there. If you make the filter a class filter, you will attach to all keyboards. Don Burn Windows Driver Consulting Website: http://www.windrvr.com<https://na01.safelinks.protection.outlook.com/?url=http%3A %2F%2Fwww.windrvr.com&data=02%7C01%7CDoron.Holan%40microsoft.com%7C646d90dfbcd44f 04f4d908d559fa98a5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C63651385522429068 5&sdata=yC5VXypypw2aNNaaXyzSXuHOjnMb1J9MnjRWgWsIreE%3D&reserved=0> From: xxxxx@lists.osr.com<mailto:xxxxx@lists.osr.com> [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@x-publisher.com<mailto:xxxxx@x-publisher.com> Sent: Friday, January 12, 2018 3:03 PM To: Windows System Software Devs Interest List <xxxxx@lists.osr.com<mailto:xxxxx@lists.osr.com>> Subject: [ntdev] FW: Windows Filter driver on different keyboards Hi All, I am writing an filter driver and want to attach the filter to more than one physical keyboard in the system. If I attach the filter to the first keyboard "\Device\KeyboardClass0" it works fine but it works not for the other keyboards. The IoAttachDevice failed for "\Device\KeyboardClass1". The same with other class. I have attached 3 physical keyboard. Now I have changed the creation of the device to work with IoCreateFile. The routines create and attach my device but now in the DispatchRead the return IoCallDriver(pDevExt->kbdDevice, Irp); ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension) the "kbdDevice" is NULL. The function status = IoAttachDeviceToDeviceStackSafe(pDevObj, pLBKdev, &pDevExt->kbdDevice); calls correctly at the time of creation. It worked before the modification. Now the routine which create and attach the device: RtlInitUnicodeString(&devNameFlt, L"\\Device\\KeyboardClass1<file://Device/KeyboardClass1>"); RtlInitUnicodeString(&devName, L"\\Device\\MultikeyboardCnt<file://Device/MultikeyboardCnt>"); status = IoCreateDevice(pDriverObject, sizeof(DEVICE_EXTENSION), &devName, FILE_DEVICE_KEYBOARD, SYNCHRONIZE, FALSE, &pDevObj); if (!NT_SUCCESS(status)) { DbgPrint("%s, IoCreateDevice failed:0x%0x\n", __FUNCTION__, status); return status; } HANDLE hFile; OBJECT_ATTRIBUTES oa = { sizeof(oa), 0, 0, OBJ_CASE_INSENSITIVE }; oa.ObjectName = &devNameFlt; IO_STATUS_BLOCK iosb; status = IoCreateFile(&hFile, SYNCHRONIZE, &oa, &iosb, 0, 0, FILE_SHARE_VALID_FLAGS, FILE_OPEN, 0, 0, 0, CreateFileTypeNone, 0, IO_ATTACH_DEVICE); if (!NT_SUCCESS(status)) { DbgPrint("%s, IoCreateFile failed to call:0x%0x\n", __FUNCTION__, status); return status; } /* Get File Object */ PFILE_OBJECT LocalFileObject; status = ObReferenceObjectByHandle(hFile, 0, *IoFileObjectType, KernelMode, (PVOID*)&LocalFileObject, NULL); pLBKdev = IoGetRelatedDeviceObject(LocalFileObject); DbgPrint("%s at IoCreateFile ok\n", __FUNCTION__); ObReferenceObject(pLBKdev); /* * Retrieve device extension pointer from device object */ pDevExt = (PDEVICE_EXTENSION)pLBKdev->DeviceExtension; status = IoAttachDeviceToDeviceStackSafe(pDevObj, pLBKdev, &pDevExt->kbdDevice); if (status != STATUS_SUCCESS) { DbgPrint("IoGetDeviceObjectPointer failed with error = 0x%0x\n", status); goto cleanup_failure; } pDevObj->Flags |= DO_BUFFERED_IO; pDevObj->Flags &= ~DO_DEVICE_INITIALIZING; /* * Create the symbolic link name, this is not mandatory * but can be helpful for user mode apps to communicate */ status = IoCreateSymbolicLink(&symLinkNameFlt, &devNameFlt); if (!NT_SUCCESS(status)) { // if it fails now, must delete Device object DbgPrint("IoCreateSymbolicLink failed with error = 0x%0x\n", status); goto cleanup_failure; } --- 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%7C646d90dfbcd44f04f4d908d559fa98a5%7 C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636513855224290685&sdata=dzneqL2JNGeP Bht2XEd2Bqb01QPC7Zk2whx69qDnAhY%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%7C6 46d90dfbcd44f04f4d908d559fa98a5%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6365 13855224290685&sdata=FZoIiXmX4lKAcxHMKc3pv24H1vXj39nL9nDlqqzWw8o%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%7C646d90dfbcd44f04f4d908d559fa98a5%7 C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636513855224290685&sdata=VUOhnZUX4vuI MZJdyRVunMweOah1BLQWL2Qwvgd7rWM%3D&reserved=0>> --- NTDEV is sponsored by OSR Visit the list online at: <http://www.osronline.com/showlists.cfm?list=ntdev> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers! Details at <http://www.osr.com/seminars> To unsubscribe, visit the List Server section of OSR Online at <http://www.osronline.com/page.cfm?name=ListServer> --
  Message 4 of 4  
12 Jan 18 16:14
makrurisan makkeln
xxxxxx@x-publisher.com
Join Date: 12 Jan 2018
Posts To This List: 9
FW: Windows Filter driver on different keyboards

Thanks for the answer. I know this with plug and play and this with the class name. My question was what is wrong in the code that it succeeds and the mentioned reference at DispatchRead is NULL.
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 09:18.


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