// JP opened flex table

Click to See Complete Forum and Search --> : NDIS Drivers


JagWire
August 15th, 2004, 05:12 PM
Can anyone direct me to a source that shows the procedure for making a network driver via NDIS? Any help would be greatly appreciated. Also, I have the book Programming the Windows Driver Model (not much help in the matter) and MSDN covers basic requirements and helpful hints but no straight forward guides to showing how to write and build one. Thanx.

Mick
August 15th, 2004, 05:30 PM
There are NDIS samples included in the DDK, in the <DDK install dir>\src directory.

I know a couple of people (including myself) who have purchased the source samples from:

http://www.pcausa.com/

The need to code a NDIS driver went away though so I have not fully review those samples as of yet. But like I said I know some developers where they have also used those samples to get a baseline understanding for thier product line.

the DDK help in <ddk installdir\help> have sections on NDIS driver development.

If all else fails -> google: NDIS driver development

JagWire
August 15th, 2004, 05:35 PM
I have googled, several times. This is quite a hard topic. I've found no walkthroughs or tutorial series(plural?), on the topic. I daresay I'll probably write one if I ever learn this.

Mick
August 15th, 2004, 05:38 PM
I have googled, several times. This is quite a hard topic. I've found no walkthroughs or tutorial series(plural?), on the topic. I daresay I'll probably write one if I ever learn this.

What is your target OS? And do you have the DDK for that target OS?

Mick
August 15th, 2004, 05:42 PM
Some more things...

You can try the driver development newsgroups, should be a couple of microsoft specific ones, there may be some good books out there that they can recommend.

Did you search the MS driver homepage?
http://search.microsoft.com/search/results.aspx?na=84&st=a&View=en-us&qu=ndis&qp=&qa=&qn=&c=&s=7

homepage:
http://www.microsoft.com/whdc/default.mspx

JagWire
August 15th, 2004, 10:51 PM
windows 2000 is target OS and I did manage to snatch the ddk before ms started making people pay for it.

Mick
August 15th, 2004, 11:51 PM
windows 2000 is target OS and I did manage to snatch the ddk before ms started making people pay for it.

Here is another site that might be useful...

http://www.ndis.com/

jack.chess
September 17th, 2004, 06:07 AM
SKETCH OVERVIEW (from memory)...

The NDIS miniport concept involves registering your driver (providing callbacks which are described individually in the DDK) with the NDIS wrapper support library. The library does all the hard stuff for you (really!).

Some callbacks in the registration table are mandatory some are not, some are alternatives. Pick the smallest subset using the simplest options to start with.

You must start by calling NDIS Initialize Wrapper. You get a handle back which identifies your device instance. You need to keep that handle to call into the NDIS library to do pretty much anything else.

You will need to hold device details and track state in some 'instance' data. Use the adapter object to collect this in one place. Include there, pointers to your packet pool etc.

Your NIC driver will be called back when network events occur, when protocols want to write data, or if WMI or other components query your device capabilities or set configurable adapter parameters such as mac address (if you support that).

Treat all ndis callbacks as reentrant (use stack data and the adapater object exclusively) You do that anyway right?

You need to process the callbacks carefully according to what the DDK tells you to do for each of the callbacks. The DDK is pretty heavy going but it is also pretty accurate about what is needed.

Before you start you'll need to get a grip on NDIS_PACKETS. You typically build a pool of packets to use. When network data is indicated to you, you pull one out, set up its header, populate it with the received data. and indicate it up to all bound protocols. Ndis gives you an indication when the packet data has been consumed, and you can then return the packet to the pool.

The send side is analogous, but you should remember that you don't own the packets you receive (they belong to the protocol driver so don't mess with them).

The only other aspect that is important is the NDIS_QUERY stuff. You need to support a certain number objects that describe your device and driver capabilities to NDIS and the rest of the operating system. This wasn't documented at all when I last looked, so there is some guesswork involved. Start with the NE2000 values and change what you KNOW you need to change, and you won't go far wrong.

GETTING STARTED
Assuming you want to write a network card driver, the buzzword in the DDK is "NIC miniport driver". Read the Windows DDK Network Drivers Design Guide Miniport NIC drivers. Use the reference section of the DDK when writing the code.

Then take a good look at the NDIS NE2000 sample. Try to build it with the DDK tools. Then set up an MSVC project and browse capability using ddkbuild.bat (see OSR) so you aren't developing in the stone-age.

GET A FEEL FOR THE LIFE OF A PACKET
===========================
Draw yourself a picture of the sequence of callbacks that occur from data arriving at the adapter (get for one packet from the pool pass it around and put it back inthe pool). Do the same for data arriving from the protocol side.

Dont worry about out of band (OOB) info to start with. Your driver will do its thing without this.

ADVANCED (don't go here if you don't need to)
========
You might it useful to use lists to track your packets.

There is a bit of space 16 bytes in the packet which you can use if you need it.

You can make any call to the kernel libraries from ndis driver, but the intent is that you use the NDIS library exclusively. In the end it is cleaner to stick with "ndis.h".

You can actually do anything a kernel driver can do - like adding IOCTL interface etc, but don't make life hard for yourself.


AND FINALLY...
=========
Really that's all there is to it. If you are really careful, keep it simple, and believe what it says in the DDK then you'll be OK.

There are some difficult ambiguities in the area of the lookahead buffer size and various length calculations, so keep an open mind here until you see for yourself. Actually what the DDK says is true.

//JP added flex table