How To Writing WDM/NDIS Miniports for Windows (224784)



The information in this article applies to:

  • Microsoft Windows 2000 Driver Development Kit (DDK)
  • Microsoft Windows 98 Driver Development Kit (DDK)

This article was previously published under Q224784

SUMMARY

Cutting-edge network devices use such new hardware interfaces as USB and 1394 to connect to the PC. These new hardware interfaces require Windows Driver Model (WDM) miniport drivers to support them. However, Windows 2000 and Windows 98 provide specialized interfaces and support for network drivers. An NDIS miniport is required. Therefore, such a network device requires an NDIS miniport driver in which the upper-edge provides an NDIS miniport interface and the lower-edge provides a WDM miniport interface.

MORE INFORMATION

An NDIS miniport driver that supports a WDM-class device is regarded by NDIS as a layered driver because it does not use the NDIS wrapper to access the hardware. Instead, such an NDIS miniport driver adheres to the requirements of the appropriate WDM bus driver interface. With regard to the NDIS specification, the driver must:
  • Identify the device of class as NET in its .inf file.
  • Use NdisMRegisterMiniport in its DriverEntry. The driver must NOT block its MiniportInitialize function waiting for any events.
  • Use NdisSetAttributesEx and set the NDIS_ATTRIBUTE_DESERIALIZE bit of the attribute flags. Thus, the miniport is required to perform serialization of inbound and outbound packets.
  • Use NdisMGetDeviceProperty to the PDO of the underlying device.
  • Use NdisMRegisterDevice instead of IoCreatDevice if it needs a DeviceObject.
  • Queue incoming packets and use an NdisTimerProc to empty this queue and indicate packets to upper network layers. This is done in order to guarantee that the protocols receive these packets at DPC level using a binary compatible method.
  • Allow NDIS to install handlers for the following IRPs:

    IRP_MJ_PNP
    IRP_MJ_POWER
    IRP_MJ_SYSTEM_CONTROL

  • Place NDIS and WDM code in separate source files. There are several token definition conflicts between Ndis.h and Wdm.h.
  • Use Halt handler to wait for all indicated packets to be returned and for all timers to complete. You should use NdisWaitEvent to perform the wait. In the case of the USB/NDIS driver, it should wait for all reads to be canceled.
  • Use NDIS wrapper calls for all Memory management; it should always use an NDIS wrapper function rather than an equivalent WDM call.
  • Indicate media-state transitions; connect-to-disconnect or disconnect-to-connect.
NDIS is the Device Loader, Class Driver, Plug and Play Manager, WMI Manager, and Power Manager for a miniport. If, for example, a developer is writing a miniport for a USB device, the developer should use the USB Bulk sample to base his or her USB client code. However do NOT install IRP handlers as in the USB BULK sample. NDIS installs IRP handlers and determines the appropriate course of action. Then NDIS uses the miniport's RequestHandler to send update requests to the miniport, and uses the callback functions in the miniport's NDIS_MINIPORT_CHARACTERISTICS:
  • NDIS calls the miniport InitializeHandler during IRP_MN_START_DEVICE.
  • NDIS calls the miniport's Halt handler during IRP_MN_STOP_DEVICE and IRP_MN_REMOVE_DEVICE.
  • NDIS calls the miniport's SetInformationHandler and Halt handler during IRP_MN_SET_POWER when the device state is greater than D0.
  • NDIS calls the miniport's InitializeHandler and SetInformationHandler during IRP_MN_SET_POWER when the device state is D0.

Modification Type:MinorLast Reviewed:9/7/2004
Keywords:kbhowto kbKMode kbNDIS KB224784