3.2.1  Keeping State

Typically, a miniport allocates memory for a driver-internal structure in which it stores adapter-specific context, such as the miniport adapter handle provided by NDIS in the initialization call, the configuration information derived from calling NdisReadConfiguration and any other state information the miniport requires. For instance, a driver that allocates a staging buffer for received data in its MiniportInitialize function could attach the buffer to this structure. If the driver queues sends, the listhead for this queue could be part of this structure.

A miniport calls NdisAllocateMemory to allocate storage for such a structure and NdisZeroMemory to clear this storage before initializing it. The miniport subsequently passes a pointer to this structure to NdisMSetAttributes or NdisMSetAttributesEx. NDIS retains the pointer to this adapter-specific context and passes it to the miniport’s MiniportXxx functions, for example MiniportSend, MiniportISR, MiniportInterruptHandler, and others. Therefore, a miniport uses this context area to maintain whatever adapter-specific runtime state it requires to process sends, receives, and requests.

A miniport allocates such a structure for each adapter it supports. If the miniport supports more than one adapter, when the miniport’s MiniportInitialize function is called once for each adapter, it will create an adapter-specific context area each time it is called.