1.8 Intermediate Driver Unbinding Operations

An intermediate driver unbinds from the underlying NIC driver by calling NdisCloseAdapter. If an intermediate driver registers a ProtocolUnbindAdapter function, NDIS will call ProtocolUnbindAdapter if the underlying NIC is no longer available. For instance, if the underlying NIC timed out, and NDIS called the MiniportHalt function of the NIC driver for the malfunctioning NIC, NDIS will subsequently call the overlying intermediate driver’s ProtocolUnbindAdapter function.

An intermediate driver can also originate the unbind operation, for instance in ProtocolStatus, if the status it receives at GeneralStatus is NDIS_STATUS_CLOSING. An intermediate driver also must unbind from an adapter during initialization if some action subsequent to opening an adapter, such as allocating a required resource, fails, and the intermediate driver needs to unbind because it cannot carry out network operations on the binding.

An intermediate driver’s ProtocolUnbindAdapter function calls NdisCloseAdapter. The intermediate driver must not release the per-binding resources until NdisCloseAdapter returns NDIS_STATUS_SUCCESS or the driver calls NdisCompleteUnbindAdapter. If NdisCloseAdapter returns NDIS_STATUS_PENDING, the intermediate driver cannot deallocate any per-binding resources until ProtocolCloseAdapterComplete is called.

NDIS does not call ProtocolCloseAdapterComplete until all outstanding requests on the binding have completed. When ProtocolCloseAdapterComplete returns control, the ProtocolBindingContext  handle the intermediate driver allocated to represent the binding is invalid.

If the underlying NIC binding that is being closed is mapped to a device exported by the intermediate driver and if that device was initialized by calling NdisIMInitializeDeviceInstance, the intermediate driver can close these devices by calling NdisIMDeInitializeDeviceInstance. The result is that the intermediate driver's virtual NIC becomes no longer available for sends or requests made by higher level drivers.

After an intermediate driver calls NdisCloseAdapter, it should fail any send requests for that binding with an appropriate error status.