Compartilhar via


Allocate Network Data Pools in Your NDIS 6.0 Miniport Driver (Compact 2013)

3/26/2014

Before passing the NET_BUFFER and NET_BUFFER_LIST structures between your driver and NDIS, your miniport driver must allocate a NET_BUFFER pool and a NET_BUFFER_LIST pool. Unlike in NDIS 5.x, NDIS 6.0 drivers do not allocate packet pools with the NdisAllocatePacketPool function. Instead, NDIS 6.0 miniport drivers call the NdisAllocateNetBufferListPool and NdisAllocateNetBufferPool functions. Each NET_BUFFER_LIST structure that your driver uses to indicate received network data has at least one associated NET_BUFFER structure. Therefore, we recommend that a driver that indicates received data should allocate a NET_BUFFER_LIST pool with a pre-allocated NET_BUFFER in each NET_BUFFER_LIST.

Your miniport driver's MiniportHaltEx function calls the NdisFreeNetBufferListPool and NdisFreeNetBufferPool functions to free the NET_BUFFER_LIST and NET_BUFFER pools, respectively. These functions replace the NDIS 5.xNdisFreePacketPool function. When you call these functions, you pass the pool handle that the associated allocation functions return.

The following table shows which API elements have been renamed and/or changed for NDIS 6.0.

NDIS 5.x

NDIS 6.0

NdisAllocatePacketPool

NdisAllocateNetBufferListPool
NdisAllocateNetBufferPool

NdisFreePacketPool

NdisFreeNetBufferListPool
NdisFreeNetBufferPool

To allocate and free network data pools in NDIS 6.0

  1. Replace calls to NdisAllocatePacketPool with calls to NdisAllocateNetBufferListPool. Call NdisAllocateNetBufferListPool with the fAllocateNetBuffer member of the NET_BUFFER_LIST_POOL_PARAMETERS structure set to TRUE to allocate a network data pool. Note that it is more efficient to preallocate NET_BUFFER structures when you allocate a pool of NET_BUFFER_LIST structures than allocating NET_BUFFER_LIST structures and NET_BUFFER structures separately.

  2. Replace calls to NdisFreePacketPool with calls to NdisFreeNetBufferListPool and NetFreeNetBufferPool to free NET_BUFFER and NET_BUFFER_LIST structures that you allocated in the previous step.

The following example illustrates the allocation of a receive buffer list pool that contains a pre-allocated NET_BUFFER.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

#define MEM_TAG ((ULONG('DCBA')) 
NET_BUFFER_LIST_POOL_PARAMETERS PoolParameters;

// Configure for a pre-allocated NET_BUFFER:
PoolParameters.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
PoolParameters.Header.Revision = NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1;
PoolParameters.Header.Size = sizeof(PoolParameters);
PoolParameters.ProtocolId = 0;
PoolParameters.ContextSize = 0;
PoolParameters.fAllocateNetBuffer = TRUE;
PoolParameters.PoolTag = MEM_TAG;

// Allocate my receive buffer list pool:
pMyAdapter->RecvNetBufferListPool = 
    NdisAllocateNetBufferListPool(pMyAdapter->AdapterHandle, &PoolParameters);

See Also

Concepts

Update Miniport Driver Send and Receive Functionality for NDIS 6.0