A protocol driver unbinds from an underlying NIC by calling NdisCloseAdapter. If a protocol driver registers a ProtocolUnbindAdapter function, NDIS will call this function if the underlying NIC is no longer available. For instance, if the NIC timed out, an attempt to reset the NIC failed to make it operational, and NDIS called the MiniportHalt function of the NIC driver for the malfunctioning NIC, NDIS will subsequently call the overlying protocol driver's ProtocolUnbindAdapter function.
If a protocol driver does not register this function, an unbind operation can originate in the driver's ProtocolStatus function, as the result of receiving a status of NDIS_STATUS_CLOSING at GeneralStatus. A protocol driver also should unbind from an adapter during initialization if some action subsequent to opening an adapter, such as allocating a required resource, fails, and the driver needs to unbind because it cannot carry out network operations on the binding.
If a protocol driver registers a ProtocolUnbindAdapter, this function calls NdisCloseAdapter. However, the protocol must not deallocate all its binding-specific resources until it calls NdisCompleteUnbindAdapter. If the protocol driver does not provide a ProtocolUnbindAdapter function, but calls NdisCloseAdapter, it can deallocate any previously allocated resources when either NdisCloseAdapter returns NDIS_STATUS_SUCCESS, or, if NdisCloseAdapter returns NDIS_STATUS_PENDING, when ProtocolCloseAdapterComplete is called.
NDIS delays calling ProtocolCloseAdapterComplete until all outstanding requests on the binding have completed. Once the close request completes, the ProtocolBindingContext handle the protocol driver allocated to represent the binding becomes invalid.