Thursday, May 31, 2007

Installing NDIS Protocols and Filters Programmatically

The Windows INetCfg API is used to install NDIS components, and the WDK includes the BindView sample application that illustrates its use.

BindView is a flexible Windows application that can install and uninstall NDIS clients, protocols and services. It is a good tool for use at certain stages of driver development, but can't be easily adapted to support programmatic NDIS component installation.

The Windows 2000 DDK includes a command-line tool called SNetCfg which could be used to programmatically install NDIS components if it was fed with the proper arguments. However, SNetCfg was clumsy to use and was a little buggy. It was dropped from later DDK versions in favor the more user-friendly BindView tool.

What I have found is that if you finally get one simple NDIS component installer (e.g., an installer for the DDK NDISPROT driver) to work the way you want it to, then it is easy to extend that installer to work with other NDIS services and protocols.

Installing the NDISPROT NDIS Protocol Driver Programmatically

As a starting point for my own work I wanted a simple tool that would help me understand how to use the INetCfg API to install a single NDIS protocol driver. In addition, I wanted this tool to be callable from a Windows Installer as a Custom Action.

I started with the old SNetCfg application and the current BindView application and made a command-line tool called ProtInstall. I modified the code to allow it to be built under Visual Studio instead of the Windows DDK build environment.

I have posted a page on NDIS.com that describes ProtInstall. It can be found at the URL:

http://ndis.com/ndis-general/ndisinstall/programinstall.htm

That page also includes a link for downloading the ProtInstall source code.

The installer uses hard-coded service and PnP ID strings. These are all defined in the ProtInstall header files, which is intended to be a common header shared between drivers, installers and user-mode applications. So, if changes are made to this one file and referencing components are rebuilt, then they all should work properly.

ProtInstall works for me. Perhaps it can be of use to some readers as well.

Installing a NDIS 5 Intermediate Filter Drivers

This can be done by making a simple modification to the HrInstallNetComponent method in the netcgfapi.cpp module. Simply insure that the IM filter service and the companion IM filter miniport INF files are both copied using SetupCopyOEMInf call.

That's about it!

Installing a NDIS 6 Lightweight Filter Driver Programmatically

Just like installing a NDIS 5 protocol driver…

Multi-Platform NDIS Protocol and Filter Installers

Only simple additional modifications are needed to detect the OS and use different service, INF and PnP ID strings for the actual host platform.

Caveat Emptor

Although I have been using variations of ProtInstall in my own work, some folks have apparently extracted the code and included it within their own applications or services. That's fine with me, but if it doesn't work in a different application or service environment, then it's up to you to determine what's different.



No comments: