Deactivating an NDIS Port
To deactivate NDIS ports, a miniport driver sends a port deactivation Plug and Play (PnP) event to NDIS. After a miniport driver successfully activates a port, the driver must deactivate the port before it can free the port. Also, the driver might deactivate a port for application-specific reasons. A port can be reactivated after it is deactivated, but a port cannot be reactivated if it is freed.
To send a port deactivation PnP event, miniport drivers use the NetEventPortDeactivation PnP event code in the call to the NdisMNetPnPEvent function. To deactivate ports, the miniport driver must set the members of the NET_PNP_EVENT_NOTIFICATION structure that the NetPnPEvent parameter of NdisMNetPnPEvent points to as follows:
PortNumber
The source port of the event notification. Set this member to zero because the port numbers are provided in the Buffer member of the structure that the NetPnPEvent member specifies.
NetPnPEvent
A NET_PNP_EVENT structure that describes the port deactivation event. Set the members of this structure as follows:
NetEvent
An event code that describes the event. Set this member to NetEventPortDeactivation.
Buffer
A pointer to an array of NDIS_PORT_NUMBER-typed elements. The array contains the port numbers of all of the ports that the miniport driver is deactivating.
BufferLength
The number of bytes that are specified in Buffer . Set BufferLength to the size of the array that Buffer points to. To obtain the number of elements in the array, divide the value in BufferLength by the size of the NDIS_PORT_NUMBER data type.
Other members
Set the remaining members of NET_PNP_EVENT to NULL.
A miniport driver can provide an array with a list of ports to deactivate. However, if the default port of a miniport adapter is the target of a NetEventPortDeactivation PnP event, the default port must be the only port that is specified in the array.
Miniport drivers can deactivate active ports at any time. However, before a miniport driver deactivates a port, it must ensure that there are no outstanding status indications or receive indications that are associated with that port. After the miniport driver sends the port deactivation PnP event, it must not initiate any status or receive indications that are associated with the deactivated ports.
A miniport driver can also reactivate a port. For more information about activating NDIS ports, see Activating NDIS Ports.
When a miniport driver deactivates ports, NDIS notifies all of the protocol drivers that are bound to the miniport driver with the NetEventPortDeactivation PnP event. This PnP event lists those ports that have changed to the allocated state and does not include any ports that are already deactivated. For more information about handling port deactivation events in a protocol driver, see Handling the Port Deactivation PnP Event.
Before a miniport driver allocates an NDIS port, the driver must call the NdisMSetMiniportAttributes function to set the registration attributes in the NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES structure. Miniport drivers can control the activation of the default port by setting the NDIS_MINIPORT_CONTROLS_DEFAULT_PORT attribute flag when they call NdisMSetMiniportAttributes. If a miniport driver assumes the responsibility for activating the default port and the miniport driver activated the default port, it must deactivate the default port before returning from the MiniportHaltEx function.
All of the ports that are specified by the array of NDIS_PORT_NUMBER elements must be in the activated state. A miniport driver should not attempt to deactivate a port that has already deactivated.
If NDIS fails to deactivate any ports in the port array, none of the ports in the port array will change state. If the deactivation fails because some of the specified ports do not exist, the NdisMNetPnPEvent function returns the NDIS_STATUS_INVALID_PORT return value. If the deactivation fails because some of the ports are not in the activated state, NdisMNetPnPEvent returns the NDIS_STATUS_INVALID_PORT_STATE return value.
Until the call to NdisMNetPnPEvent returns, a port is not deactivated, and miniport drivers must be able to handle OID requests and send requests that are associated with that port.
When a miniport driver deactivates the default port, NDIS closes all of the bindings between the overlying protocol drivers and the miniport adapter. If a miniport driver tries to deactivate the default port and default port is already deactivated, NdisMNetPnPEvent fails and returns the NDIS_STATUS_INVALID_PORT_STATE return value. If a miniport driver tries to deactivates the default port and the default port is not the only port that is specified in the array of NDIS_PORT_NUMBER elements, NdisMNetPnPEvent fails and returns the NDIS_STATUS_INVALID_PORT return value. If a miniport driver sets the Buffer member to NULL or BufferLength member to zero, NDIS fails the NdisMNetPnPEvent call and returns the NDIS_STATUS_INVALID_PARAMETER return value.
After a port is successfully deactivated, the port is in the allocated state. Miniport drivers cannot indicate received data or status for the port in the allocated state.