summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/ndiswan/loopback.c
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/ntos/ndis/ndiswan/loopback.c
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to 'private/ntos/ndis/ndiswan/loopback.c')
-rw-r--r--private/ntos/ndis/ndiswan/loopback.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/private/ntos/ndis/ndiswan/loopback.c b/private/ntos/ndis/ndiswan/loopback.c
new file mode 100644
index 000000000..a7702da3b
--- /dev/null
+++ b/private/ntos/ndis/ndiswan/loopback.c
@@ -0,0 +1,148 @@
+/*++
+
+Copyright (c) 1990-1995 Microsoft Corporation
+
+Module Name:
+
+ Loopback.c
+
+Abstract:
+
+ This file contains the procedures for doing loopback of send
+ packets for ndiswan. Loopback is being done in NdisWan because
+ the NDIS wrapper could not meet all of the needs of NdisWan.
+
+Author:
+
+ Tony Bell (TonyBe) January 25, 1996
+
+Environment:
+
+ Kernel Mode
+
+Revision History:
+
+ TonyBe 01/25/96 Created
+
+--*/
+
+#include "wan.h"
+
+VOID
+NdisWanQueueLoopbackPacket(
+ PADAPTERCB AdapterCB,
+ PNDIS_PACKET NdisPacket
+ )
+{
+ PLOOPBACK_DESC LoopbackDesc;
+ ULONG AllocationSize, BufferLength;
+
+ NdisWanDbgOut(DBG_TRACE, DBG_LOOPBACK, ("NdisWanQueueLoopbackPacket: Enter"));
+ NdisWanDbgOut(DBG_INFO, DBG_LOOPBACK, ("AdapterCB: 0x%8.8x, NdisPacket: 0x%8.8x",
+ AdapterCB, NdisPacket));
+
+ //
+ // Create a loopback descriptor
+ //
+ NdisQueryPacket(NdisPacket,
+ NULL,
+ NULL,
+ NULL,
+ &BufferLength);
+
+ AllocationSize = BufferLength + sizeof(LOOPBACK_DESC);
+
+ NdisWanAllocateMemory(&LoopbackDesc, AllocationSize);
+
+ if (LoopbackDesc != NULL) {
+ ULONG BytesCopied;
+ PDEFERRED_DESC DeferredDesc;
+
+ //
+ // For loopback we do not care about the bundlecb/protocolcb
+ // states so they will remain NULL.
+ //
+ LoopbackDesc->AllocationSize = (USHORT)AllocationSize;
+ LoopbackDesc->BufferLength = (USHORT)BufferLength;
+ LoopbackDesc->Buffer = (PUCHAR)LoopbackDesc + sizeof(LOOPBACK_DESC);
+
+ //
+ // Copy the current packet
+ //
+ NdisWanCopyFromPacketToBuffer(NdisPacket,
+ 0,
+ 0xFFFFFFFF,
+ LoopbackDesc->Buffer,
+ &BytesCopied);
+
+ ASSERT(BytesCopied == BufferLength);
+
+ NdisAcquireSpinLock(&AdapterCB->Lock);
+
+ NdisWanGetDeferredDesc(AdapterCB, &DeferredDesc);
+
+ ASSERT(DeferredDesc != NULL);
+
+ DeferredDesc->Context = (PVOID)LoopbackDesc;
+
+ InsertTailDeferredQueue(&AdapterCB->DeferredQueue[Loopback], DeferredDesc);
+
+ NdisWanSetDeferred(AdapterCB);
+
+ NdisReleaseSpinLock(&AdapterCB->Lock);
+
+ } else {
+ NdisWanDbgOut(DBG_FAILURE, DBG_LOOPBACK, ("NdisWanQueueLoopbackPacket: Memory allocation failure!"));
+ }
+}
+
+VOID
+NdisWanProcessLoopbacks(
+ PADAPTERCB AdapterCB
+ )
+{
+ RECV_DESC RecvDesc;
+
+ NdisWanDbgOut(DBG_TRACE, DBG_LOOPBACK, ("NdisWanIndicateLoopback: Enter"));
+ NdisWanDbgOut(DBG_TRACE, DBG_LOOPBACK, ("NdisWanIndicateLoopback: AdapterCB 0x%8.8x", AdapterCB));
+
+ while (!IsDeferredQueueEmpty(&AdapterCB->DeferredQueue[Loopback])) {
+
+ PDEFERRED_DESC ReturnDesc;
+ PLOOPBACK_DESC LoopbackDesc;
+
+ ReturnDesc = RemoveHeadDeferredQueue(&AdapterCB->DeferredQueue[Loopback]);
+
+ NdisReleaseSpinLock(&AdapterCB->Lock);
+
+ LoopbackDesc = ReturnDesc->Context;
+
+ NdisWanDbgOut(DBG_INFO, DBG_LOOPBACK, ("NdisWanIndicateLoopback: Desc 0x%8.8x", LoopbackDesc));
+
+ RecvDesc.Flags = 0x4c4F4F50;
+ RecvDesc.WanHeader = LoopbackDesc->Buffer;
+ RecvDesc.WanHeaderLength = 14;
+ RecvDesc.LookAhead = NULL;
+ RecvDesc.LookAheadLength = 0;
+ RecvDesc.CurrentBuffer = LoopbackDesc->Buffer + 14;
+ RecvDesc.CurrentBufferLength = LoopbackDesc->BufferLength - 14;
+
+ ASSERT((LONG)RecvDesc.CurrentBufferLength > 0);
+
+ NdisMEthIndicateReceive(AdapterCB->hMiniportHandle,
+ &RecvDesc,
+ LoopbackDesc->Buffer,
+ 14,
+ LoopbackDesc->Buffer + 14,
+ LoopbackDesc->BufferLength - 14,
+ LoopbackDesc->BufferLength - 14);
+
+ NdisWanFreeMemory(LoopbackDesc);
+
+ NdisAcquireSpinLock(&AdapterCB->Lock);
+
+ AdapterCB->Flags |= RECEIVE_COMPLETE;
+
+ InsertHeadDeferredQueue(&AdapterCB->FreeDeferredQueue, ReturnDesc);
+ }
+}