Implemented (copied from NdisAllocatePacketPool) NdisAllocatePacketPoolEx.
authorHartmut Birr <osexpert@googlemail.com>
Thu, 11 Aug 2005 20:16:03 +0000 (20:16 +0000)
committerHartmut Birr <osexpert@googlemail.com>
Thu, 11 Aug 2005 20:16:03 +0000 (20:16 +0000)
svn path=/trunk/; revision=17303

reactos/drivers/net/ndis/ndis/buffer.c

index 20e40e1..7479ac4 100644 (file)
@@ -469,6 +469,12 @@ NdisAllocatePacket(
     NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X)  Packet (0x%X)  PoolHandle (0x%X).\n",
         Status, Packet, PoolHandle));
 
+    if (Pool == NULL)
+    {
+        *Status = NDIS_STATUS_FAILURE;
+        return;
+    }
+
     KeAcquireSpinLock(&Pool->SpinLock.SpinLock, &OldIrql);
 
     if (Pool->FreeList) {
@@ -563,7 +569,57 @@ NdisAllocatePacketPoolEx(
  *    NDIS 5.0
  */
 {
-    UNIMPLEMENTED
+    PNDIS_PACKET_POOL Pool;
+    UINT Size, Length, i;
+    PNDIS_PACKET Packet, NextPacket;
+
+    NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X)  PoolHandle (0x%X)  "
+        "NumberOfDescriptors (%d)  ProtocolReservedLength (%d).\n",
+        Status, PoolHandle, NumberOfDescriptors, ProtocolReservedLength));
+
+    if (NumberOfDescriptors > 0xffff)
+    {
+        *Status = NDIS_STATUS_RESOURCES;
+    }
+    else
+    {
+        NumberOfDescriptors += NumberOfOverflowDescriptors;
+        if (NumberOfDescriptors > 0xffff)
+        {
+            NumberOfDescriptors = 0xffff;
+        }
+
+        Length = sizeof(NDIS_PACKET) + ProtocolReservedLength;
+        Size   = sizeof(NDIS_PACKET_POOL) + Length * NumberOfDescriptors;
+
+        Pool   = ExAllocatePool(NonPagedPool, Size);
+        if (Pool) 
+        {
+            KeInitializeSpinLock(&Pool->SpinLock.SpinLock);
+            Pool->PacketLength = Length;
+
+            if (NumberOfDescriptors > 0) 
+            {
+                Packet         = (PNDIS_PACKET)&Pool->Buffer;
+                Pool->FreeList = Packet;
+
+                NextPacket = (PNDIS_PACKET)((ULONG_PTR)Packet + Length);
+                for (i = 1; i < NumberOfDescriptors; i++) 
+                {
+                    Packet->Private.Head = (PNDIS_BUFFER)NextPacket;
+                    Packet               = NextPacket;
+                    NextPacket           = (PNDIS_PACKET)((ULONG_PTR)Packet + Length);
+                }
+                Packet->Private.Head = NULL;
+            } 
+            else
+                Pool->FreeList = NULL;
+
+            *Status     = NDIS_STATUS_SUCCESS;
+            *PoolHandle = (PNDIS_HANDLE)Pool;
+        } else
+            *Status = NDIS_STATUS_RESOURCES;
+    }
 }