Hi all,
Is it possible to write a NDIS filter driver by using KMDF? I had searched several documents and the only one I found is “Using KMDF in Miniport Drivers”. But it’s for writing m miniport of NDIS instead of NDIS filter driver. So here are my questions.
- Is it possible to write a NDIS filter driver by using WDF?
- Is there any reference regarding of this?
- I like WDF but I’m not sure what the effort of writing it by WDF is if it’s possible.
Any comments or suggestions are welcome. Thanks.
Ziv
When KMDF refers to “Miniport Drivers” it is a more general concept than
NDIS Miniport Drivers. In this regard it means that the responsibility
for handling the IRP dispatch entry points are handled by some “Port” driver
and not KMDF. It also means that a whole lot of functionality in KMDF is
not available as it is not responsible for abstracting I/O to your device
objects.
NDIS LWF drivers while not called ‘miniports’ per-se do delegate IRP
dispatch to NDIS. Creating a ‘control device object’ in a LWF driver is
accomplished by asking NDIS to do it and providing NDIS with a table of IRP
dispatch entries. I/O to this CDO cannot be handled by KMDF.
So the bigger question is what features of KMDF do you find attractive and
wish to leverage in your NDIS LWF? It surely is possible. You get some
of the core services - the ‘Miniport’ subset. Is that what you want?
Good Luck,
Dave Cattley
Yes, it’s possible. KMDF won’t help at all with the NDIS side of things - that part of your driver looks the same, regardless of whether your driver uses KMDF or WDM. KMDF will help you with non-NDIS chores though. For example, if you want to create a control device object to talk to usermode, KMDF will save you time.
Because NDIS filters are typically non-pnp drivers, you’ll want to follow the instructions here: http://msdn.microsoft.com/en-us/library/windows/hardware/ff545487(v=vs.85).aspx
NDIS LWF drivers while not called ‘miniports’ per-se do delegate IRP dispatch to NDIS. Creating a ‘control device object’ in a LWF driver is accomplished by asking NDIS to do it and providing NDIS with a table of IRP dispatch entries. I/O to this CDO cannot be handled by KMDF.
There’s not a strict requirement that you use NDIS’s APIs for CDOs. And given that NDIS’s CDO APIs are not as good as KMDF APIs, I recommend that you use KMDF in favor of NDIS here.
> There’s not a strict requirement that you use NDIS’s APIs for CDOs. And
given that NDIS’s CDO APIs are not as good as KMDF APIs, I recommend that
you use KMDF in favor of NDIS here.
I did not realize it was possible.
So are you saying that after NDIS fills the DRIVER_OBJECT::MajorFunction
dispatch table with ndis!ndisDummyIrpHandler and takes over dispatch, it is
ok to then initialize KMDF in ‘legacy’ mode and have KMDF take over from
NDIS?
It seems like there must be some careful order to maintain. Is there a
sample or guidance on coordinating the filter driver
registration/deregistration and the KMDF driver initialization/termination?
Regards,
Dave Cattley
I meant only in the context of LWFs. Miniports must still abdicate their dispatch table to NDIS; there’s no way around *that*.
But where NdisFRegisterFilterDriver does still take a DriverObject parameter, we don’t immediately use it to replace your dispatch table. So your LWF can keep its dispatch table. (Or offer it up to WDF instead).
Cool!
Sent from my Windows Phone
From: Jeffrey Tippetmailto:xxxxx
Sent: 3/7/2014 5:58 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE: [ntdev] NDIS Filter Driver by WDF
I meant only in the context of LWFs. Miniports must still abdicate their dispatch table to NDIS; there’s no way around that.
But where NdisFRegisterFilterDriver does still take a DriverObject parameter, we don’t immediately use it to replace your dispatch table. So your LWF can keep its dispatch table. (Or offer it up to WDF instead).
—
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
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</mailto:xxxxx></mailto:xxxxx>
Sorry for response late and thanks for all of your feedback. I’ll try it.
By the way, I like the object framework of WDF because I can manage resources by setting parent-child relationship up. I only have to take care of the life cycle of root(parent) objects and WDF framework will handle the reset of their children for me automatically. Even more, I can do extra cleanup inside object’s cleanup callback when the object is being deleted.
Most of time I use WDFMEMORY to represent all objects and write my code like OO programming. It’s so cool and I like it. 
Ziv
+1
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, March 10, 2014 11:06 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] NDIS Filter Driver by WDF
Sorry for response late and thanks for all of your feedback. I’ll try it.
By the way, I like the object framework of WDF because I can manage
resources by setting parent-child relationship up. I only have to take care
of the life cycle of root(parent) objects and WDF framework will handle the
reset of their children for me automatically. Even more, I can do extra
cleanup inside object’s cleanup callback when the object is being deleted.
Most of time I use WDFMEMORY to represent all objects and write my code like
OO programming. It’s so cool and I like it. 
Ziv
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
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
You can use those parts in kmdf miniport mode if you like
d
Bent from my phone
From: xxxxx@gmail.commailto:xxxxx
Sent: ?3/?10/?2014 8:06 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] NDIS Filter Driver by WDF
Sorry for response late and thanks for all of your feedback. I’ll try it.
By the way, I like the object framework of WDF because I can manage resources by setting parent-child relationship up. I only have to take care of the life cycle of root(parent) objects and WDF framework will handle the reset of their children for me automatically. Even more, I can do extra cleanup inside object’s cleanup callback when the object is being deleted.
Most of time I use WDFMEMORY to represent all objects and write my code like OO programming. It’s so cool and I like it. 
Ziv
—
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
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</mailto:xxxxx></mailto:xxxxx>
Hi Doron,
I’m trying this part in NDIS lightWeight filter instead of miniport driver. Unfortunately I was not able to do that so far. The problem I encountered is I got NULL WdfDriverGlobals when calling WdfDriverCreate.
Here are my steps of this experiment.
- Create a “Filter Driver: NDIS” project by VS2013.
- Add necessary KMDF include/lib paths and kmdf libs to the new created project.
- Modify inf file to include all needed sections of WDF coinstaller.
- Add following code snippet in DriverEntry.
- Got NULL WdfDriverGlobals when calling WdfDriverCreate and crash. @@
Any suggestions or comments?
Thanks,
Ziv
[DriverEntry]
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.EvtCleanupCallback = FilterEvtDriverCleanup;
WDF_DRIVER_CONFIG_INIT(&config, WDF_NO_EVENT_CALLBACK);
config.DriverInitFlags |= WdfDriverInitNonPnpDriver;
config.EvtDriverUnload = FilterEvtDriverUnload;
Status = WdfDriverCreate(DriverObject,
RegistryPath,
&attributes,
&config,
WDF_NO_HANDLE
);
[Crash]
Must_inspect_result
IRQL_requires_max(PASSIVE_LEVEL)
NTSTATUS
FORCEINLINE
WdfDriverCreate(
In
PDRIVER_OBJECT DriverObject,
In
PCUNICODE_STRING RegistryPath,
In_opt
PWDF_OBJECT_ATTRIBUTES DriverAttributes,
In
PWDF_DRIVER_CONFIG DriverConfig,
Out_opt
WDFDRIVER* Driver
)
{
return ((PFN_WDFDRIVERCREATE) WdfFunctions[WdfDriverCreateTableIndex])(WdfDriverGlobals, DriverObject, RegistryPath, DriverAttributes, DriverConfig, Driver);
}
You need to go to project properties and say it is a kmdf driver, you should never have to add the kmdf include oath or libs to the project manually. It might be better to start with a kmdf project then ndis lwf
d
Bent from my phone
From: xxxxx@gmail.commailto:xxxxx
Sent: ?3/?11/?2014 2:52 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] NDIS Filter Driver by WDF
Hi Doron,
I’m trying this part in NDIS lightWeight filter instead of miniport driver. Unfortunately I was not able to do that so far. The problem I encountered is I got NULL WdfDriverGlobals when calling WdfDriverCreate.
Here are my steps of this experiment.
1. Create a “Filter Driver: NDIS” project by VS2013.
2. Add necessary KMDF include/lib paths and kmdf libs to the new created project.
3. Modify inf file to include all needed sections of WDF coinstaller.
4. Add following code snippet in DriverEntry.
5. Got NULL WdfDriverGlobals when calling WdfDriverCreate and crash. @@
Any suggestions or comments?
Thanks,
Ziv
[DriverEntry]
==================================
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.EvtCleanupCallback = FilterEvtDriverCleanup;
WDF_DRIVER_CONFIG_INIT(&config, WDF_NO_EVENT_CALLBACK);
config.DriverInitFlags |= WdfDriverInitNonPnpDriver;
config.EvtDriverUnload = FilterEvtDriverUnload;
Status = WdfDriverCreate(DriverObject,
RegistryPath,
&attributes,
&config,
WDF_NO_HANDLE
);
[Crash]
==================================
Must_inspect_result
IRQL_requires_max(PASSIVE_LEVEL)
NTSTATUS
FORCEINLINE
WdfDriverCreate(
In
PDRIVER_OBJECT DriverObject,
In
PCUNICODE_STRING RegistryPath,
In_opt
PWDF_OBJECT_ATTRIBUTES DriverAttributes,
In
PWDF_DRIVER_CONFIG DriverConfig,
Out_opt
WDFDRIVER* Driver
)
{
return ((PFN_WDFDRIVERCREATE) WdfFunctions[WdfDriverCreateTableIndex])(WdfDriverGlobals, DriverObject, RegistryPath, DriverAttributes, DriverConfig, Driver);
}
—
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
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</mailto:xxxxx></mailto:xxxxx>
Thanks Doron. It works now when I created a kmdf driver project and then modified it to NDIS filter. 