Handling the Surprise Removal of a NIC (NDIS 5.1)
Note NDIS 5. x has been deprecated and is superseded by NDIS 6. x. For new NDIS driver development, see Network Drivers Starting with Windows Vista. For information about porting NDIS 5. x drivers to NDIS 6. x, see Porting NDIS 5.x Drivers to NDIS 6.0.
A surprise removal occurs when a user removes a NIC from a running system without notifying the system beforehand through the user interface (UI).
Miniport drivers for Microsoft Windows XP and later versions should be able to handle surprise removals. In particular, NDIS miniport drivers with a WDM lower edge should be able to handle such events. If an NDIS-WDM miniport driver does not handle a surprise removal, any pending IRPs that the miniport driver sent to the underlying bus driver before the surprise removal cannot be completed.
For Windows XP and later versions, a miniport driver (such as a miniport driver with a WDM lower edge) that does not control hardware directly, should set the NDIS_ATTRIBUTE_SURPRISE_REMOVE_OK attribute flag when calling NdisMSetAttributesEx. Setting this flag prevents a warning from being displayed when a user performs a surprise removal of a NIC. A miniport driver that cannot handle a surprise removal should not set this flag.
A miniport driver that supports surprise removal should itself attempt to detect a surprise removal during normal operations--outside the context of MiniportPnPEventNotify. After a NIC is removed, an attempt to read a NIC's I/O ports typically results in return values that have all bits set to one. If a miniport driver reads such a value, it should check for the presence of the hardware with a more conclusive test. For example, the miniport driver could write a value to an I/O port and then try to read the value from that port. The miniport driver could also check for valid values in the NIC's I/O registers. Detecting a surprise removal in such a way prevents the miniport driver from hanging in an infinite loop when it attempts to read a removed NIC's registers. A miniport driver that hangs in this way cannot respond when NDIS calls the driver's MiniportPnPEventNotifyfunction.