ReactOS  0.4.15-dev-5455-g015cd25
loopback.c File Reference
#include "precomp.h"
Include dependency graph for loopback.c:

Go to the source code of this file.

Functions

VOID LoopPassiveWorker (PVOID Context)
 
VOID LoopTransmit (PVOID Context, PNDIS_PACKET NdisPacket, UINT Offset, PVOID LinkAddress, USHORT Type)
 
NDIS_STATUS LoopRegisterAdapter (PNDIS_STRING AdapterName, PLAN_ADAPTER *Adapter)
 
NDIS_STATUS LoopUnregisterAdapter (PLAN_ADAPTER Adapter)
 

Variables

PIP_INTERFACE Loopback = NULL
 

Function Documentation

◆ LoopPassiveWorker()

VOID LoopPassiveWorker ( PVOID  Context)

Definition at line 15 of file loopback.c.

17 {
18  PIP_PACKET IPPacket = Context;
19 
20  /* IPReceive() takes care of the NDIS packet */
21  IPReceive(Loopback, IPPacket);
22 
23  ExFreePool(IPPacket);
24 }
VOID IPReceive(PIP_INTERFACE IF, PIP_PACKET IPPacket)
Definition: receive.c:638
struct tagContext Context
Definition: acpixf.h:1038
PIP_INTERFACE Loopback
Definition: loopback.c:13
Definition: ip.h:77
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by LoopTransmit().

◆ LoopRegisterAdapter()

NDIS_STATUS LoopRegisterAdapter ( PNDIS_STRING  AdapterName,
PLAN_ADAPTER Adapter 
)

Definition at line 96 of file loopback.c.

107 {
108  LLIP_BIND_INFO BindInfo;
109 
110  TI_DbgPrint(MID_TRACE, ("Called.\n"));
111 
112  /* Bind the adapter to network (IP) layer */
113  BindInfo.Context = NULL;
114  BindInfo.HeaderSize = 0;
115  BindInfo.MinFrameSize = 0;
116  BindInfo.Address = NULL;
117  BindInfo.AddressLength = 0;
118  BindInfo.Transmit = LoopTransmit;
119 
120  Loopback = IPCreateInterface(&BindInfo);
121  if (!Loopback) return NDIS_STATUS_RESOURCES;
122 
123  Loopback->MTU = 16384;
124 
125  Loopback->Name.Buffer = L"Loopback";
127  (USHORT)wcslen(Loopback->Name.Buffer) * sizeof(WCHAR);
128 
132 
134 
136 
137  TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
138 
139  return NDIS_STATUS_SUCCESS;
140 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
IP_ADDRESS Broadcast
Definition: ip.h:162
UINT AddressLength
Definition: ip.h:131
#define MID_TRACE
Definition: debug.h:15
#define LOOPBACK_BCASTADDR_IPv4
Definition: ip.h:187
USHORT MaximumLength
Definition: env_spec_w32.h:370
UINT MinFrameSize
Definition: ip.h:129
PVOID Context
Definition: ip.h:127
PIP_INTERFACE IPCreateInterface(PLLIP_BIND_INFO BindInfo)
Definition: ip.c:182
UNICODE_STRING Name
Definition: ip.h:163
PUCHAR Address
Definition: ip.h:130
LL_TRANSMIT_ROUTINE Transmit
Definition: ip.h:132
#define L(x)
Definition: ntvdm.h:50
IP_ADDRESS Unicast
Definition: ip.h:159
BOOLEAN IPRegisterInterface(PIP_INTERFACE IF)
Definition: ip.c:293
UINT MTU
Definition: ip.h:157
__wchar_t WCHAR
Definition: xmlstorage.h:180
UINT HeaderSize
Definition: ip.h:128
#define AddrInitIPv4(IPAddress, RawAddress)
Definition: address.h:16
VOID IPAddInterfaceRoute(PIP_INTERFACE IF)
Definition: ip.c:266
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
IP_ADDRESS Netmask
Definition: ip.h:161
#define LOOPBACK_ADDRMASK_IPv4
Definition: ip.h:188
#define MAX_TRACE
Definition: debug.h:16
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
#define LOOPBACK_ADDRESS_IPv4
Definition: ip.h:186
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
PIP_INTERFACE Loopback
Definition: loopback.c:13
VOID LoopTransmit(PVOID Context, PNDIS_PACKET NdisPacket, UINT Offset, PVOID LinkAddress, USHORT Type)
Definition: loopback.c:26

Referenced by DriverEntry().

◆ LoopTransmit()

VOID LoopTransmit ( PVOID  Context,
PNDIS_PACKET  NdisPacket,
UINT  Offset,
PVOID  LinkAddress,
USHORT  Type 
)

Definition at line 26 of file loopback.c.

41 {
42  PCHAR PacketBuffer;
43  UINT PacketLength;
44  PNDIS_PACKET XmitPacket;
45  NDIS_STATUS NdisStatus;
46  PIP_PACKET IPPacket;
47 
48  ASSERT_KM_POINTER(NdisPacket);
49  ASSERT_KM_POINTER(PC(NdisPacket));
50  ASSERT_KM_POINTER(PC(NdisPacket)->DLComplete);
51 
52  if (Type != LAN_PROTO_IPv4)
53  {
54  TI_DbgPrint(MAX_TRACE, ("Received unsupported protocol %u\n", Type));
55  PC(NdisPacket)->DLComplete(PC(NdisPacket)->Context, NdisPacket, NDIS_STATUS_NOT_SUPPORTED);
56  return;
57  }
58 
59  TI_DbgPrint(MAX_TRACE, ("Called (NdisPacket = %x)\n", NdisPacket));
60 
61  GetDataPtr( NdisPacket, 0, &PacketBuffer, &PacketLength );
62 
63  NdisStatus = AllocatePacketWithBuffer
64  ( &XmitPacket, PacketBuffer, PacketLength );
65 
66  if( NT_SUCCESS(NdisStatus) ) {
67  IPPacket = ExAllocatePool(NonPagedPool, sizeof(IP_PACKET));
68  if (IPPacket)
69  {
70  IPInitializePacket(IPPacket, 0);
71 
72  IPPacket->NdisPacket = XmitPacket;
73 
74  GetDataPtr(IPPacket->NdisPacket,
75  0,
76  (PCHAR*)&IPPacket->Header,
77  &IPPacket->TotalSize);
78 
79  IPPacket->MappedHeader = TRUE;
80 
81  if (!ChewCreate(LoopPassiveWorker, IPPacket))
82  {
83  IPPacket->Free(IPPacket);
84  ExFreePool(IPPacket);
85  NdisStatus = NDIS_STATUS_RESOURCES;
86  }
87  }
88  else
89  NdisStatus = NDIS_STATUS_RESOURCES;
90  }
91 
92  (PC(NdisPacket)->DLComplete)
93  ( PC(NdisPacket)->Context, NdisPacket, NdisStatus );
94 }
signed char * PCHAR
Definition: retypes.h:7
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define TRUE
Definition: types.h:120
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
OBJECT_FREE_ROUTINE Free
Definition: ip.h:78
int NDIS_STATUS
Definition: ntddndis.h:475
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
PIP_PACKET IPInitializePacket(PIP_PACKET IPPacket, ULONG Type)
Definition: ip.c:92
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
PVOID Header
Definition: ip.h:83
BOOLEAN ChewCreate(VOID(*Worker)(PVOID), PVOID WorkerContext)
Definition: workqueue.c:65
#define LAN_PROTO_IPv4
Definition: lan.h:126
VOID LoopPassiveWorker(PVOID Context)
Definition: loopback.c:15
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UINT TotalSize
Definition: ip.h:86
Type
Definition: Type.h:6
#define ASSERT_KM_POINTER(_x)
Definition: debug.h:74
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
PNDIS_PACKET NdisPacket
Definition: ip.h:88
BOOLEAN MappedHeader
Definition: ip.h:81
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
Definition: ip.h:77
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by LoopRegisterAdapter().

◆ LoopUnregisterAdapter()

NDIS_STATUS LoopUnregisterAdapter ( PLAN_ADAPTER  Adapter)

Definition at line 143 of file loopback.c.

154 {
155  TI_DbgPrint(MID_TRACE, ("Called.\n"));
156 
157  if (Loopback != NULL)
158  {
161  Loopback = NULL;
162  }
163 
164  TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
165 
166  return NDIS_STATUS_SUCCESS;
167 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
VOID IPDestroyInterface(PIP_INTERFACE IF)
Definition: ip.c:246
#define MID_TRACE
Definition: debug.h:15
VOID IPUnregisterInterface(PIP_INTERFACE IF)
Definition: ip.c:353
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define MAX_TRACE
Definition: debug.h:16
#define NULL
Definition: types.h:112
PIP_INTERFACE Loopback
Definition: loopback.c:13

Referenced by TiUnload().

Variable Documentation

◆ Loopback