--- trunk/reactos/drivers/net/ndis/ndis/buffer.c 2005-08-23 22:25:35 UTC (rev 17490)
+++ trunk/reactos/drivers/net/ndis/ndis/buffer.c 2005-08-23 23:02:35 UTC (rev 17491)
@@ -348,49 +348,16 @@
* Length = Number of bytes in data buffer
*/
{
- KIRQL OldIrql;
- PNETWORK_HEADER Temp;
- PNDIS_BUFFER_POOL Pool = (PNDIS_BUFFER_POOL)PoolHandle;
-
- NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X) Buffer (0x%X) PoolHandle (0x%X) "
- "VirtualAddress (0x%X) Length (%d)\n",
- Status, Buffer, PoolHandle, VirtualAddress, Length));
-
-#if 0
- Temp = Pool->FreeList;
- while( Temp ) {
- NDIS_DbgPrint(MID_TRACE,("Free buffer -> %x\n", Temp));
- Temp = Temp->Next;
- }
-
- NDIS_DbgPrint(MID_TRACE,("|:. <- End free buffers"));
-#endif
-
- if(!VirtualAddress && !Length) return;
-
- KeAcquireSpinLock(&Pool->SpinLock, &OldIrql);
-
- if (Pool->FreeList) {
- Temp = Pool->FreeList;
- Pool->FreeList = Temp->Next;
-
- KeReleaseSpinLock(&Pool->SpinLock, OldIrql);
-
- Temp->Next = NULL;
-
- MmInitializeMdl(&Temp->Mdl, VirtualAddress, Length);
- Temp->Mdl.MdlFlags |= (MDL_SOURCE_IS_NONPAGED_POOL | MDL_ALLOCATED_FIXED_SIZE);
- Temp->Mdl.MappedSystemVa = VirtualAddress;
-
- Temp->BufferPool = Pool;
-
- *Buffer = (PNDIS_BUFFER)Temp;
+ ASSERT(VirtualAddress != NULL);
+ ASSERT(Length > 0);
+
+ *Buffer = IoAllocateMdl(VirtualAddress, Length, FALSE, FALSE, NULL);
+ if (*Buffer != NULL) {
+ MmBuildMdlForNonPagedPool(*Buffer);
+ (*Buffer)->Next = NULL;
*Status = NDIS_STATUS_SUCCESS;
} else {
- KeReleaseSpinLock(&Pool->SpinLock, OldIrql);
*Status = NDIS_STATUS_FAILURE;
- NDIS_DbgPrint(MID_TRACE, ("Can't get another packet.\n"));
- KeBugCheck(0);
}
}
@@ -412,38 +379,8 @@
* NumberOfDescriptors = Size of buffer pool in number of descriptors
*/
{
- UINT i;
- PNDIS_BUFFER_POOL Pool;
- PNETWORK_HEADER Buffer;
-
- NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X) PoolHandle (0x%X) NumberOfDescriptors (%d).\n",
- Status, PoolHandle, NumberOfDescriptors));
-
- Pool = ExAllocatePool(NonPagedPool,
- sizeof(NDIS_BUFFER_POOL) +
- sizeof(NETWORK_HEADER) *
- NumberOfDescriptors);
- if (Pool) {
- KeInitializeSpinLock(&Pool->SpinLock);
-
- if (NumberOfDescriptors > 0) {
- Buffer = &Pool->Buffers[0];
- NDIS_DbgPrint(MAX_TRACE, ("NDIS BUFFER ADDRESS << %x >>\n", Buffer));
- Pool->FreeList = Buffer;
- for (i = 1; i < NumberOfDescriptors; i++) {
- Buffer->Next = &Pool->Buffers[i];
- Buffer = Buffer->Next;
- NDIS_DbgPrint(MAX_TRACE, ("NDIS BUFFER ADDRESS << %x >>\n",
- Buffer));
- }
- Buffer->Next = NULL;
- } else
- Pool->FreeList = NULL;
-
- *Status = NDIS_STATUS_SUCCESS;
- *PoolHandle = (PNDIS_HANDLE)Pool;
- } else
- *Status = NDIS_STATUS_RESOURCES;
+ *Status = NDIS_STATUS_SUCCESS;
+ *PoolHandle = 0;
}
@@ -616,12 +553,12 @@
* Length of NDIS buffer
*/
{
- return Buffer->ByteCount;
+ return MmGetMdlByteCount(Buffer);
}
/*
- * @unimplemented
+ * @implemented
*/
#undef NdisBufferVirtualAddress
PVOID
@@ -635,9 +572,7 @@
* NDIS 5.0
*/
{
- UNIMPLEMENTED
-
- return NULL;
+ return MmGetSystemAddressForMdl(Buffer);
}
@@ -839,7 +774,6 @@
* PoolHandle = Handle returned by NdisAllocateBufferPool
*/
{
- ExFreePool((PVOID)PoolHandle);
}
@@ -874,18 +808,7 @@
* Buffer = Pointer to buffer descriptor
*/
{
- KIRQL OldIrql;
- PNDIS_BUFFER_POOL Pool;
- PNETWORK_HEADER Temp = (PNETWORK_HEADER)Buffer;
-
- NDIS_DbgPrint(MAX_TRACE, ("Buffer (0x%X).\n", Buffer));
-
- Pool = Temp->BufferPool;
-
- KeAcquireSpinLock(&Pool->SpinLock, &OldIrql);
- Temp->Next = (PNETWORK_HEADER)Pool->FreeList;
- Pool->FreeList = (PNETWORK_HEADER)Temp;
- KeReleaseSpinLock(&Pool->SpinLock, OldIrql);
+ IoFreeMdl(Buffer);
}