NDIS_OBJECTS = ndis/main.o ndis/40gone.o ndis/50gone.o ndis/buffer.o ndis/cl.o \
ndis/cm.o ndis/co.o ndis/control.o ndis/hardware.o \
ndis/io.o ndis/memory.o ndis/miniport.o \
- ndis/protocol.o ndis/string.o ndis/stubs.o ndis/time.o \
- $(TARGETNAME).coff
+ ndis/protocol.o ndis/string.o ndis/stubs.o ndis/time.o
all: objects $(TARGETNAME).sys
--kill-at \
--output-lib $(TARGETNAME).a
$(CC) \
+ -nostartfiles -nostdlib \
+ --subsystem=native \
-mdll \
- -specs=../../svc_specs \
+ --dll \
-Wl,-e,_DriverEntry@8 \
-Wl,--base-file,base.tmp \
-Wl,--defsym,_end=end \
--def $(TARGETNAME).edf
- $(RM) base.tmp
$(CC) \
+ -nostartfiles -nostdlib \
+ --subsystem=native \
-mdll \
- -specs=../../svc_specs \
+ --dll \
-Wl,--image-base,0x10000 \
-Wl,-e,_DriverEntry@8 \
-Wl,temp.exp \
#ifndef _MSC_VER
/* FIXME: The following should be moved to ntddk.h */
-/* i386 specific constants */
-
-/* Page size for the Intel 386 is 4096 */
-#define PAGE_SIZE (ULONG)0x1000
-
-/* 4096 is 2^12. Used to find the virtual page number from a virtual address */
-#define PAGE_SHIFT 12L
-
-/*
- * ULONG ADDRESS_AND_SIZE_TO_SPAN_PAGES(
- * IN PVOID Va,
- * IN ULONG Size);
- */
-#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va, Size) \
- ((((ULONG)((ULONG)(Size) - 1) >> PAGE_SHIFT) + \
- (((((ULONG)(Size - 1) & (PAGE_SIZE - 1)) + \
- ((ULONG)Va & (PAGE_SIZE - 1)))) >> PAGE_SHIFT)) + 1)
-
/*
* ULONG MmGetMdlByteCount(
* IN PMDL Mdl)
PNDIS_PACKET Packet,
UINT Size);
+#ifdef DBG
+VOID DisplayIPPacket(
+ PIP_PACKET IPPacket);
+#define DISPLAY_IP_PACKET(x) DisplayIPPacket(x)
+#else
+#define DISPLAY_IP_PACKET(x)
+#endif /* DBG */
+
#endif /* __ROUTINES_H */
/* EOF */
/* Define _NTTEST_ to make test version. Device names are prefixed with
'NT' to allow the driver to run side by side with MS TCP/IP driver */
-#define _NTTEST_
+//#define _NTTEST_
/* FIXME: The following should be moved to ntddk.h or tdi headers */
#ifndef _MSC_VER
# TCPIP.SYS - TCP/IP protocol driver
#
-PATH_TO_TOP = ../../../
+PATH_TO_TOP = ../../..
TARGETNAME=tcpip
--kill-at \
--output-lib $(TARGETNAME).a
$(CC) \
- -mdll \
- -specs=../../svc_specs \
+ -nostartfiles -nostdlib \
+ --subsystem=native \
+ -mdll \
+ --dll \
-Wl,-e,_DriverEntry@8 \
-Wl,--base-file,base.tmp \
-Wl,--defsym,_end=end \
--def $(TARGETNAME).edf
- $(RM) base.tmp
$(CC) \
- -mdll \
- -specs=../../svc_specs \
+ -nostartfiles -nostdlib \
+ --subsystem=native \
+ -mdll \
+ --dll \
-Wl,--image-base,0x10000 \
-Wl,-e,_DriverEntry@8 \
-Wl,temp.exp \
return;
default:
TI_DbgPrint(MIN_TRACE, ("Datagram has an unsupported IP version %d.\n", Version));
+
+ DISPLAY_IP_PACKET(IPPacket);
+
return;
}
}
KeAcquireSpinLock(&AddressFileListLock, &OldIrql);
while (CurrentEntry != &AddressFileListHead) {
- Current = CONTAINING_RECORD(CurrentEntry, ADDRESS_FILE, ListEntry);
+ Current = CONTAINING_RECORD(CurrentEntry, ADDRESS_FILE, ListEntry);
- /* See if this address matches the search criteria */
IPAddress = Current->ADE->Address;
+
+ TI_DbgPrint(DEBUG_ADDRFILE, ("Comparing: ((%d, %d, 0x%X), (%d, %d, 0x%X)).\n",
+ Current->Port,
+ Current->Protocol,
+ IPAddress->Address.IPv4Address,
+ SearchContext->Port,
+ SearchContext->Protocol,
+ SearchContext->Address->Address.IPv4Address));
+
+ /* See if this address matches the search criteria */
if (((Current->Port == SearchContext->Port) &&
(Current->Protocol == SearchContext->Protocol) &&
(AddrIsEqual(IPAddress, SearchContext->Address))) ||
IoAcquireCancelSpinLock(&OldIrql);
- /* Remove the reference placed on the endpoint by the cancel routine.
- The cancelled IRP will be completed by the completion routine for
- the request */
+ /* Remove the reference taken by the cancel routine */
TranContext->RefCount--;
if (TranContext->RefCount == 0) {
* Status of operation
*/
{
-#ifdef _MSC_VER
PTDI_REQUEST_KERNEL_SET_EVENT Parameters;
PTRANSPORT_CONTEXT TranContext;
PIO_STACK_LOCATION IrpSp;
switch (Parameters->EventType) {
case TDI_EVENT_CONNECT:
if (!Parameters->EventHandler) {
- AddrFile->ConnectionHandler =
- (PTDI_IND_CONNECT)TdiDefaultConnectHandler;
+// AddrFile->ConnectionHandler =
+// (PTDI_IND_CONNECT)TdiDefaultConnectHandler;
AddrFile->ConnectionHandlerContext = NULL;
AddrFile->RegisteredConnectionHandler = FALSE;
} else {
case TDI_EVENT_DISCONNECT:
if (!Parameters->EventHandler) {
- AddrFile->DisconnectHandler =
- (PTDI_IND_DISCONNECT)TdiDefaultDisconnectHandler;
+// AddrFile->DisconnectHandler =
+// (PTDI_IND_DISCONNECT)TdiDefaultDisconnectHandler;
AddrFile->DisconnectHandlerContext = NULL;
AddrFile->RegisteredDisconnectHandler = FALSE;
} else {
case TDI_EVENT_RECEIVE:
if (Parameters->EventHandler == NULL) {
- AddrFile->ReceiveHandler =
- (PTDI_IND_RECEIVE)TdiDefaultReceiveHandler;
+// AddrFile->ReceiveHandler =
+// (PTDI_IND_RECEIVE)TdiDefaultReceiveHandler;
AddrFile->ReceiveHandlerContext = NULL;
AddrFile->RegisteredReceiveHandler = FALSE;
} else {
case TDI_EVENT_RECEIVE_EXPEDITED:
if (Parameters->EventHandler == NULL) {
- AddrFile->ExpeditedReceiveHandler =
- (PTDI_IND_RECEIVE_EXPEDITED)TdiDefaultRcvExpeditedHandler;
+// AddrFile->ExpeditedReceiveHandler =
+// (PTDI_IND_RECEIVE_EXPEDITED)TdiDefaultRcvExpeditedHandler;
AddrFile->ExpeditedReceiveHandlerContext = NULL;
AddrFile->RegisteredExpeditedReceiveHandler = FALSE;
} else {
case TDI_EVENT_RECEIVE_DATAGRAM:
if (Parameters->EventHandler == NULL) {
- AddrFile->ReceiveDatagramHandler =
- (PTDI_IND_RECEIVE_DATAGRAM)TdiDefaultRcvDatagramHandler;
+// AddrFile->ReceiveDatagramHandler =
+// (PTDI_IND_RECEIVE_DATAGRAM)TdiDefaultRcvDatagramHandler;
AddrFile->ReceiveDatagramHandlerContext = NULL;
AddrFile->RegisteredReceiveDatagramHandler = FALSE;
} else {
case TDI_EVENT_ERROR:
if (Parameters->EventHandler == NULL) {
- AddrFile->ErrorHandler =
- (PTDI_IND_ERROR)TdiDefaultErrorHandler;
+// AddrFile->ErrorHandler =
+// (PTDI_IND_ERROR)TdiDefaultErrorHandler;
AddrFile->ErrorHandlerContext = NULL;
AddrFile->RegisteredErrorHandler = FALSE;
} else {
KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
return Status;
-#else
- return STATUS_NOT_IMPLEMENTED;
-#endif
}
/* This is a request to open an address */
/* Parameter checks */
- Address = (PTA_ADDRESS_IP)(EaInfo->EaName + EaInfo->EaNameLength + 1);
+ Address = (PTA_ADDRESS_IP)(EaInfo->EaName + EaInfo->EaNameLength);
if ((EaInfo->EaValueLength < sizeof(TA_ADDRESS_IP)) ||
(Address->TAAddressCount != 1) ||
- (Address->Address[0].AddressLength < sizeof(TDI_ADDRESS_IP)) ||
+ (Address->Address[0].AddressLength < TDI_ADDRESS_LENGTH_IP) ||
(Address->Address[0].AddressType != TDI_ADDRESS_TYPE_IP)) {
TI_DbgPrint(MIN_TRACE, ("Parameters are invalid.\n"));
ExFreePool(Context);
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
- TI_DbgPrint(DEBUG_IRP, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n", DeviceObject, Irp));
+ IrpSp = IoGetCurrentIrpStackLocation(Irp);
- IrpSp = IoGetCurrentIrpStackLocation(Irp);
+ TI_DbgPrint(DEBUG_IRP, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X) MN (%d).\n",
+ DeviceObject, Irp, IrpSp->MinorFunction));
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
return STATUS_INSUFFICIENT_RESOURCES;
}
-#if 1
+#if 0
/* Open underlying adapter(s) we are bound to */
/* FIXME: Get binding information from registry */
return OldSize;
}
+#ifdef DBG
+VOID DisplayIPPacket(
+ PIP_PACKET IPPacket)
+{
+ UINT i;
+ PCHAR p;
+ UINT Length;
+ PNDIS_BUFFER Buffer;
+ PNDIS_BUFFER NextBuffer;
+
+ if ((DebugTraceLevel & MAX_TRACE) == 0)
+ return;
+
+ if (!IPPacket) {
+ TI_DbgPrint(MIN_TRACE, ("Cannot display null packet.\n"));
+ return;
+ }
+
+ TI_DbgPrint(MIN_TRACE, ("Header buffer is at (0x%X).\n", IPPacket->Header));
+ TI_DbgPrint(MIN_TRACE, ("Header size is (%d).\n", IPPacket->HeaderSize));
+ TI_DbgPrint(MIN_TRACE, ("TotalSize (%d).\n", IPPacket->TotalSize));
+ TI_DbgPrint(MIN_TRACE, ("ContigSize (%d).\n", IPPacket->ContigSize));
+ TI_DbgPrint(MIN_TRACE, ("NdisPacket (0x%X).\n", IPPacket->NdisPacket));
+
+ NdisQueryPacket(IPPacket->NdisPacket, NULL, NULL, &Buffer, NULL);
+ for (; Buffer != NULL; Buffer = NextBuffer) {
+ NdisGetNextBuffer(Buffer, &NextBuffer);
+ NdisQueryBuffer(Buffer, (PVOID)&p, &Length);
+
+ for (i = 0; i < Length; i++) {
+ if (i % 16 == 0)
+ DbgPrint("\n");
+ DbgPrint("%02X ", (p[i]) & 0xFF);
+ }
+ DbgPrint("\n");
+ }
+}
+#endif /* DBG */
+
/* EOF */
return STATUS_INSUFFICIENT_RESOURCES;
}
+ TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n", BufferSize, Header));
+
/* Allocate NDIS buffer for maximum Link level, IP and UDP header */
NdisAllocateBuffer(&NdisStatus,
&HeaderBuffer,
}
RtlZeroMemory(Packet, sizeof(IP_PACKET));
- Packet->RefCount = 1;
- Packet->TotalSize = sizeof(IPv4_HEADER) +
- sizeof(UDP_HEADER) +
- SendRequest->BufferSize;
+ Packet->RefCount = 1;
+ Packet->TotalSize = sizeof(IPv4_HEADER) +
+ sizeof(UDP_HEADER) +
+ SendRequest->BufferSize;
/* Allocate NDIS packet */
NdisAllocatePacket(&NdisStatus, &Packet->NdisPacket, GlobalPacketPool);
/* Chain data after header */
NdisChainBufferAtBack(Packet->NdisPacket, SendRequest->Buffer);
+ DISPLAY_IP_PACKET(Packet);
+
*IPPacket = Packet;
return STATUS_SUCCESS;
*/
{
KIRQL OldIrql;
+ PTDI_IND_RECEIVE_DATAGRAM ReceiveHandler;
+ PVOID HandlerContext;
+ LONG AddressLength;
+ PVOID SourceAddress;
+ ULONG BytesTaken;
+ NTSTATUS Status;
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
PoolFreeBuffer(Current->RemoteAddress);
PoolFreeBuffer(Current);
}
- } else {
+ } else if (AddrFile->RegisteredReceiveDatagramHandler) {
+ TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n"));
+
+ ReceiveHandler = AddrFile->ReceiveDatagramHandler;
+ HandlerContext = AddrFile->ReceiveDatagramHandlerContext;
+
KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
- /* FIXME: Call event handler */
- TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n"));
+ if (Address->Type == IP_ADDRESS_V4) {
+ AddressLength = sizeof(IPv4_RAW_ADDRESS);
+ SourceAddress = &Address->Address.IPv4Address;
+ } else /* (Address->Type == IP_ADDRESS_V6) */ {
+ AddressLength = sizeof(IPv6_RAW_ADDRESS);
+ SourceAddress = Address->Address.IPv6Address;
+ }
+
+ Status = (*ReceiveHandler)(HandlerContext,
+ AddressLength,
+ SourceAddress,
+ 0,
+ NULL,
+ TDI_RECEIVE_ENTIRE_MESSAGE,
+ DataSize,
+ DataSize,
+ &BytesTaken,
+ IPPacket->Data,
+ NULL);
}
TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));