NDIS connection-less protocol driver sample

SUMMARY

This sample demonstrates a connection-less NDIS 5.0/5.1 protocol driver. The driver supports sending and receiving raw Ethernet frames using ReadFile/WriteFile calls from user-mode. As an NDIS protocol, it illustrates how to establish and tear down bindings to Ethernet adapters, i.e. those that export medium type NdisMedium802_3. It shows how to set a packet filter, send and receive data, and handle plug-and-play events. It also shows use of the following NDIS 5.1 features/APIs:

1.      Canceling sends

2.      NdisQueryPendingIOCount()

The sample works on Windows 2000, Windows XP, and Windows Server 2003 32-bit and 64-bit platforms.

BUILDING THE SAMPLE

From the Free or Checked Build environment, execute build -ceZ in the ndisprot directory.

INSTALLATION

The driver is installed using the INF file ndisprot.inf, which is provided in the driver directory. In Network Connections UI, select an adapter and open Properties.

Click Install, then Protocol, then Add, and then Have disk. Then point to the location of the .inf and driver.

Select Sample NDIS Protocol Driver and click OK. After installing the protocol, copy over the test application uiotest.exe to a convenient location. Please note that the driver service has been set to manual start in the INF file. As a result, it doesn't get loaded automatically when you install.

USAGE

To start the driver, type

          Net start ndisprot

 

To stop the driver, type

          Net stop ndisprot

 

To test the driver, run uiotest. For help on usage, run uiotest -?

 

usage: UIOTEST [options] <devicename>
options:
       -e: Enumerate devices
       -r: Read
       -w: Write (default)
       -l <length>: length of each packet (default: 100)
       -n <count>: number of packets (defaults to infinity)
       -m <MAC address> (defaults to local MAC)

 

Uiotest exercises the IOCTLs supported by NDISPROT, and sends and/or receives data on the selected device. In order to use uiotest, the user must have administrative privilege. Users should pass down a big enough buffer in order to receive the entire received data. If the length of the buffer passed down is smaller than the length of the received data, NDISPROT will only copy part of the data and discard the rest when the given buffer is full.

 

 

Use the –e option to enumerate all devices to which NDISPROT is bound:

C:\uio>uiotest -e
 0. \DEVICE\{9273DA7D-5275-4B9A-AC56-68A49D121F1F}
     - Intel-Based 10/100 Ethernet Card

 

The following command sends and receives 2 packets on a device). Since these packets are sent to the local MAC address (default), both packets are received. The device name parameter to uiotest is picked up from the output of uiotest –e (see above).

 

C:\uio>uiotest -n 2 \DEVICE\{9273DA7D-5275-4B9A-AC56-68A49D121F1F}
DoWriteProc: finished sending 2 packets of 100 bytes each
DoReadProc finished: read 2 packets

For security reasons, this driver does not allow packets with fake MAC addresses to be sent from usermode applications.

TIPS

With a checked version of ndisprot.sys, you can control the volume of debug information generated by changing the variable ndisprotDebugLevel. Refer to debug.h for more information.

CODE TOUR

File Manifest

Directory: Test

 
 
 
 
 
File             Description      
uiotest.c        User-mode test application
 
 
Directory: Sys

 
 
 
 
 
File             Description      
debug.c          Routines to aid debugging
debug.h          Debug macro definitions
macros.h         Spinlock, event, referencing macros
ndisbind.c       NDIS protocol entry points to handle binding/unbinding from adapters
ndisprot.h        Data structure definitions
ndisprot.inf      INF file for installing NDISPROT
ntdisp.c         NT Entry points and dispatch routines for NDISPROT
nuiouser.h       IOCTL and associated structure definitions
recv.c           NDIS protocol entry points for receiving data, and IRP_MJ_READ processing
send.c           NDIS protocol routines for sending data, and IRP_MJ_WRITE processing
 

Top of page

 

© Microsoft Corporation 2000