mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Fixed UDP protocol.
Leaned interface between tcpip and ip lib to not include ndis buffers and such, as well as datagram request structs. This both eliminates code setting up these structs as well as making use of ip lib easier from userland. Moved ndis buffer routines to tcpip/buffer.c. They are a bit separate from the neutral routines functions. svn path=/trunk/; revision=11171
This commit is contained in:
parent
a52618ca99
commit
5394560307
20 changed files with 311 additions and 725 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <roscfg.h>
|
#include <roscfg.h>
|
||||||
|
#include <basetsd.h>
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
#include <rosrtl/string.h>
|
#include <rosrtl/string.h>
|
||||||
#include <rosrtl/recmutex.h>
|
#include <rosrtl/recmutex.h>
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
extern int sprintf( char *out, const char *fmt, ... );
|
extern int sprintf( char *out, const char *fmt, ... );
|
||||||
|
|
||||||
#ifdef DBG
|
|
||||||
|
|
||||||
CHAR A2SStr[128];
|
CHAR A2SStr[128];
|
||||||
|
|
||||||
PCHAR A2S(
|
PCHAR A2S(
|
||||||
|
@ -55,8 +53,6 @@ PCHAR A2S(
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* DBG */
|
|
||||||
|
|
||||||
ULONG IPv4NToHl( ULONG Address ) {
|
ULONG IPv4NToHl( ULONG Address ) {
|
||||||
return
|
return
|
||||||
((Address & 0xff) << 24) |
|
((Address & 0xff) << 24) |
|
||||||
|
|
|
@ -53,7 +53,6 @@ PIP_PACKET PrepareICMPPacket(
|
||||||
{
|
{
|
||||||
PIP_PACKET IPPacket;
|
PIP_PACKET IPPacket;
|
||||||
PNDIS_PACKET NdisPacket;
|
PNDIS_PACKET NdisPacket;
|
||||||
PNDIS_BUFFER NdisBuffer;
|
|
||||||
NDIS_STATUS NdisStatus;
|
NDIS_STATUS NdisStatus;
|
||||||
PIPv4_HEADER IPHeader;
|
PIPv4_HEADER IPHeader;
|
||||||
PVOID DataBuffer;
|
PVOID DataBuffer;
|
||||||
|
@ -75,38 +74,17 @@ PIP_PACKET PrepareICMPPacket(
|
||||||
sizeof(ICMP_HEADER) + DataSize;
|
sizeof(ICMP_HEADER) + DataSize;
|
||||||
DataBuffer = exAllocatePool(NonPagedPool, Size);
|
DataBuffer = exAllocatePool(NonPagedPool, Size);
|
||||||
if (!DataBuffer) {
|
if (!DataBuffer) {
|
||||||
|
exFreePool( IPPacket );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_ICMP, ("Size (%d). Data at (0x%X).\n", Size, DataBuffer));
|
TI_DbgPrint(DEBUG_ICMP, ("Size (%d). Data at (0x%X).\n", Size, DataBuffer));
|
||||||
|
|
||||||
/* Allocate NDIS packet */
|
|
||||||
NdisAllocatePacket(&NdisStatus, &NdisPacket, GlobalPacketPool);
|
|
||||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
|
||||||
exFreePool(DataBuffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("NdisPacket at (0x%X).\n", NdisPacket));
|
TI_DbgPrint(MAX_TRACE, ("NdisPacket at (0x%X).\n", NdisPacket));
|
||||||
|
|
||||||
/* Allocate NDIS buffer for maximum link level header and ICMP packet */
|
|
||||||
NdisAllocateBuffer(&NdisStatus, &NdisBuffer, GlobalBufferPool,
|
|
||||||
DataBuffer, Size);
|
|
||||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
|
||||||
FreeNdisPacket(NdisPacket);
|
|
||||||
exFreePool(DataBuffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("NdisBuffer at (0x%X).\n", NdisBuffer));
|
|
||||||
|
|
||||||
/* Link NDIS buffer into packet */
|
|
||||||
NdisChainBufferAtFront(NdisPacket, NdisBuffer);
|
|
||||||
IPPacket->NdisPacket = NdisPacket;
|
|
||||||
IPPacket->Header = (PVOID)((ULONG_PTR)DataBuffer + MaxLLHeaderSize);
|
IPPacket->Header = (PVOID)((ULONG_PTR)DataBuffer + MaxLLHeaderSize);
|
||||||
IPPacket->Data = (PVOID)((ULONG_PTR)DataBuffer + MaxLLHeaderSize + sizeof(IPv4_HEADER));
|
|
||||||
|
|
||||||
IPPacket->HeaderSize = sizeof(IPv4_HEADER);
|
IPPacket->HeaderSize = sizeof(IPv4_HEADER);
|
||||||
|
IPPacket->Data = (PVOID)(((ULONG_PTR)IPPacket->Header) +
|
||||||
|
IPPacket->HeaderSize);
|
||||||
IPPacket->TotalSize = Size - MaxLLHeaderSize;
|
IPPacket->TotalSize = Size - MaxLLHeaderSize;
|
||||||
RtlCopyMemory(&IPPacket->DstAddr, Destination, sizeof(IP_ADDRESS));
|
RtlCopyMemory(&IPPacket->DstAddr, Destination, sizeof(IP_ADDRESS));
|
||||||
|
|
||||||
|
@ -136,10 +114,17 @@ PIP_PACKET PrepareICMPPacket(
|
||||||
/* Destination address */
|
/* Destination address */
|
||||||
IPHeader->DstAddr = Destination->Address.IPv4Address;
|
IPHeader->DstAddr = Destination->Address.IPv4Address;
|
||||||
|
|
||||||
/* Completion handler */
|
TI_DbgPrint(MID_TRACE,("Allocating packet\n"));
|
||||||
PC(NdisPacket)->Complete = SendICMPComplete;
|
/* Allocate NDIS packet */
|
||||||
PC(NdisPacket)->Context = IPPacket;
|
NdisStatus = AllocatePacketWithBuffer( &NdisPacket, DataBuffer, Size );
|
||||||
|
IPPacket->NdisPacket = NdisPacket;
|
||||||
|
|
||||||
|
GetDataPtr( IPPacket->NdisPacket, MaxLLHeaderSize,
|
||||||
|
(PCHAR *)&IPPacket->Header, &IPPacket->ContigSize );
|
||||||
|
IPPacket->Data = ((PCHAR)IPPacket->Header) + IPPacket->HeaderSize;
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE,("Leaving\n"));
|
||||||
|
|
||||||
return IPPacket;
|
return IPPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +140,6 @@ VOID ICMPReceive(
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PICMP_HEADER ICMPHeader;
|
PICMP_HEADER ICMPHeader;
|
||||||
PIP_PACKET NewPacket;
|
|
||||||
UINT DataSize;
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_ICMP, ("Called.\n"));
|
TI_DbgPrint(DEBUG_ICMP, ("Called.\n"));
|
||||||
|
|
||||||
|
@ -181,40 +164,22 @@ VOID ICMPReceive(
|
||||||
|
|
||||||
switch (ICMPHeader->Type) {
|
switch (ICMPHeader->Type) {
|
||||||
case ICMP_TYPE_ECHO_REQUEST:
|
case ICMP_TYPE_ECHO_REQUEST:
|
||||||
/* Reply with an ICMP echo reply message */
|
ICMPReply( NTE, IPPacket, ICMP_TYPE_ECHO_REPLY, 0 );
|
||||||
DataSize = IPPacket->TotalSize - IPPacket->HeaderSize - sizeof(ICMP_HEADER);
|
|
||||||
NewPacket = PrepareICMPPacket(NTE, &IPPacket->SrcAddr, DataSize);
|
|
||||||
if (!NewPacket)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Copy ICMP header and data into new packet */
|
|
||||||
RtlCopyMemory(NewPacket->Data, IPPacket->Data, DataSize + sizeof(ICMP_HEADER));
|
|
||||||
((PICMP_HEADER)NewPacket->Data)->Type = ICMP_TYPE_ECHO_REPLY;
|
|
||||||
((PICMP_HEADER)NewPacket->Data)->Code = 0;
|
|
||||||
((PICMP_HEADER)NewPacket->Data)->Checksum = 0;
|
|
||||||
|
|
||||||
#ifdef DBG
|
|
||||||
DisplayIPPacket(IPPacket);
|
|
||||||
DisplayIPPacket(NewPacket);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ICMPTransmit(NTE, NewPacket);
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_ICMP, ("Echo reply sent.\n"));
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case ICMP_TYPE_ECHO_REPLY:
|
case ICMP_TYPE_ECHO_REPLY:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
TI_DbgPrint(DEBUG_ICMP, ("Discarded ICMP datagram of unknown type %d.\n",
|
TI_DbgPrint(DEBUG_ICMP,
|
||||||
ICMPHeader->Type));
|
("Discarded ICMP datagram of unknown type %d.\n",
|
||||||
|
ICMPHeader->Type));
|
||||||
/* Discard packet */
|
/* Discard packet */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send datagram up the protocol stack */
|
/* Send datagram up the protocol stack */
|
||||||
RawIPReceive(NTE, IPPacket);
|
/*RawIPReceive(NTE, IPPacket);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,8 +224,8 @@ VOID ICMPTransmit(
|
||||||
VOID ICMPReply(
|
VOID ICMPReply(
|
||||||
PNET_TABLE_ENTRY NTE,
|
PNET_TABLE_ENTRY NTE,
|
||||||
PIP_PACKET IPPacket,
|
PIP_PACKET IPPacket,
|
||||||
UCHAR Type,
|
UCHAR Type,
|
||||||
UCHAR Code)
|
UCHAR Code)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Transmits an ICMP packet in response to an incoming packet
|
* FUNCTION: Transmits an ICMP packet in response to an incoming packet
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -280,7 +245,8 @@ VOID ICMPReply(
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_ICMP, ("Called. Type (%d) Code (%d).\n", Type, Code));
|
TI_DbgPrint(DEBUG_ICMP, ("Called. Type (%d) Code (%d).\n", Type, Code));
|
||||||
|
|
||||||
DataSize = IPPacket->TotalSize;
|
DataSize = IPPacket->TotalSize - IPPacket->HeaderSize -
|
||||||
|
sizeof(ICMP_HEADER);;
|
||||||
if ((DataSize) > (576 - sizeof(IPv4_HEADER) - sizeof(ICMP_HEADER)))
|
if ((DataSize) > (576 - sizeof(IPv4_HEADER) - sizeof(ICMP_HEADER)))
|
||||||
DataSize = 576;
|
DataSize = 576;
|
||||||
|
|
||||||
|
@ -288,12 +254,16 @@ VOID ICMPReply(
|
||||||
if (!NewPacket)
|
if (!NewPacket)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RtlCopyMemory((PVOID)((ULONG_PTR)NewPacket->Data + sizeof(ICMP_HEADER)),
|
RtlCopyMemory(NewPacket->Data, IPPacket->Data,
|
||||||
IPPacket->Header, DataSize);
|
DataSize + sizeof(ICMP_HEADER));
|
||||||
|
|
||||||
((PICMP_HEADER)NewPacket->Data)->Type = Type;
|
((PICMP_HEADER)NewPacket->Data)->Type = Type;
|
||||||
((PICMP_HEADER)NewPacket->Data)->Code = Code;
|
((PICMP_HEADER)NewPacket->Data)->Code = Code;
|
||||||
((PICMP_HEADER)NewPacket->Data)->Checksum = 0;
|
((PICMP_HEADER)NewPacket->Data)->Checksum = 0;
|
||||||
|
|
||||||
|
PC(NewPacket->NdisPacket)->Complete = SendICMPComplete;
|
||||||
|
PC(NewPacket->NdisPacket)->Context = NewPacket;
|
||||||
|
|
||||||
ICMPTransmit(NTE, NewPacket);
|
ICMPTransmit(NTE, NewPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,343 +26,6 @@ UINT Random(
|
||||||
return RandomNumber;
|
return RandomNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__inline INT SkipToOffset(
|
|
||||||
PNDIS_BUFFER Buffer,
|
|
||||||
UINT Offset,
|
|
||||||
PCHAR *Data,
|
|
||||||
PUINT Size)
|
|
||||||
/*
|
|
||||||
* FUNCTION: Skip Offset bytes into a buffer chain
|
|
||||||
* ARGUMENTS:
|
|
||||||
* Buffer = Pointer to NDIS buffer
|
|
||||||
* Offset = Number of bytes to skip
|
|
||||||
* Data = Address of a pointer that on return will contain the
|
|
||||||
* address of the offset in the buffer
|
|
||||||
* Size = Address of a pointer that on return will contain the
|
|
||||||
* size of the destination buffer
|
|
||||||
* RETURNS:
|
|
||||||
* Offset into buffer, -1 if buffer chain was smaller than Offset bytes
|
|
||||||
* NOTES:
|
|
||||||
* Buffer may be NULL
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
for (;;) {
|
|
||||||
|
|
||||||
if (!Buffer)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
NdisQueryBuffer(Buffer, (PVOID)Data, Size);
|
|
||||||
|
|
||||||
if (Offset < *Size) {
|
|
||||||
*Data = (PCHAR)((ULONG_PTR) *Data + Offset);
|
|
||||||
*Size -= Offset;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Offset -= *Size;
|
|
||||||
|
|
||||||
NdisGetNextBuffer(Buffer, &Buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UINT CopyBufferToBufferChain(
|
|
||||||
PNDIS_BUFFER DstBuffer,
|
|
||||||
UINT DstOffset,
|
|
||||||
PCHAR SrcData,
|
|
||||||
UINT Length)
|
|
||||||
/*
|
|
||||||
* FUNCTION: Copies data from a buffer to an NDIS buffer chain
|
|
||||||
* ARGUMENTS:
|
|
||||||
* DstBuffer = Pointer to destination NDIS buffer
|
|
||||||
* DstOffset = Destination start offset
|
|
||||||
* SrcData = Pointer to source buffer
|
|
||||||
* Length = Number of bytes to copy
|
|
||||||
* RETURNS:
|
|
||||||
* Number of bytes copied to destination buffer
|
|
||||||
* NOTES:
|
|
||||||
* The number of bytes copied may be limited by the destination
|
|
||||||
* buffer size
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
UINT BytesCopied, BytesToCopy, DstSize;
|
|
||||||
PCHAR DstData;
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_PBUFFER, ("DstBuffer (0x%X) DstOffset (0x%X) SrcData (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcData, Length));
|
|
||||||
|
|
||||||
/* Skip DstOffset bytes in the destination buffer chain */
|
|
||||||
if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Start copying the data */
|
|
||||||
BytesCopied = 0;
|
|
||||||
for (;;) {
|
|
||||||
BytesToCopy = MIN(DstSize, Length);
|
|
||||||
|
|
||||||
RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
|
|
||||||
BytesCopied += BytesToCopy;
|
|
||||||
SrcData = (PCHAR)((ULONG_PTR)SrcData + BytesToCopy);
|
|
||||||
|
|
||||||
Length -= BytesToCopy;
|
|
||||||
if (Length == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
DstSize -= BytesToCopy;
|
|
||||||
if (DstSize == 0) {
|
|
||||||
/* No more bytes in desination buffer. Proceed to
|
|
||||||
the next buffer in the destination buffer chain */
|
|
||||||
NdisGetNextBuffer(DstBuffer, &DstBuffer);
|
|
||||||
if (!DstBuffer)
|
|
||||||
break;
|
|
||||||
|
|
||||||
NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return BytesCopied;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UINT CopyBufferChainToBuffer(
|
|
||||||
PCHAR DstData,
|
|
||||||
PNDIS_BUFFER SrcBuffer,
|
|
||||||
UINT SrcOffset,
|
|
||||||
UINT Length)
|
|
||||||
/*
|
|
||||||
* FUNCTION: Copies data from an NDIS buffer chain to a buffer
|
|
||||||
* ARGUMENTS:
|
|
||||||
* DstData = Pointer to destination buffer
|
|
||||||
* SrcBuffer = Pointer to source NDIS buffer
|
|
||||||
* SrcOffset = Source start offset
|
|
||||||
* Length = Number of bytes to copy
|
|
||||||
* RETURNS:
|
|
||||||
* Number of bytes copied to destination buffer
|
|
||||||
* NOTES:
|
|
||||||
* The number of bytes copied may be limited by the source
|
|
||||||
* buffer size
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
UINT BytesCopied, BytesToCopy, SrcSize;
|
|
||||||
PCHAR SrcData;
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_PBUFFER, ("DstData 0x%X SrcBuffer 0x%X SrcOffset 0x%X Length %d\n",DstData,SrcBuffer, SrcOffset, Length));
|
|
||||||
|
|
||||||
/* Skip SrcOffset bytes in the source buffer chain */
|
|
||||||
if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Start copying the data */
|
|
||||||
BytesCopied = 0;
|
|
||||||
for (;;) {
|
|
||||||
BytesToCopy = MIN(SrcSize, Length);
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_PBUFFER, ("Copying (%d) bytes from 0x%X to 0x%X\n", BytesToCopy, SrcData, DstData));
|
|
||||||
|
|
||||||
RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
|
|
||||||
BytesCopied += BytesToCopy;
|
|
||||||
DstData = (PCHAR)((ULONG_PTR)DstData + BytesToCopy);
|
|
||||||
|
|
||||||
Length -= BytesToCopy;
|
|
||||||
if (Length == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
SrcSize -= BytesToCopy;
|
|
||||||
if (SrcSize == 0) {
|
|
||||||
/* No more bytes in source buffer. Proceed to
|
|
||||||
the next buffer in the source buffer chain */
|
|
||||||
NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
|
|
||||||
if (!SrcBuffer)
|
|
||||||
break;
|
|
||||||
|
|
||||||
NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return BytesCopied;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UINT CopyPacketToBuffer(
|
|
||||||
PCHAR DstData,
|
|
||||||
PNDIS_PACKET SrcPacket,
|
|
||||||
UINT SrcOffset,
|
|
||||||
UINT Length)
|
|
||||||
/*
|
|
||||||
* FUNCTION: Copies data from an NDIS packet to a buffer
|
|
||||||
* ARGUMENTS:
|
|
||||||
* DstData = Pointer to destination buffer
|
|
||||||
* SrcPacket = Pointer to source NDIS packet
|
|
||||||
* SrcOffset = Source start offset
|
|
||||||
* Length = Number of bytes to copy
|
|
||||||
* RETURNS:
|
|
||||||
* Number of bytes copied to destination buffer
|
|
||||||
* NOTES:
|
|
||||||
* The number of bytes copied may be limited by the source
|
|
||||||
* buffer size
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
PNDIS_BUFFER FirstBuffer;
|
|
||||||
PVOID Address;
|
|
||||||
UINT FirstLength;
|
|
||||||
UINT TotalLength;
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_PBUFFER, ("DstData (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstData, SrcPacket, SrcOffset, Length));
|
|
||||||
|
|
||||||
NdisGetFirstBufferFromPacket(SrcPacket,
|
|
||||||
&FirstBuffer,
|
|
||||||
&Address,
|
|
||||||
&FirstLength,
|
|
||||||
&TotalLength);
|
|
||||||
|
|
||||||
return CopyBufferChainToBuffer(DstData, FirstBuffer, SrcOffset, Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UINT CopyPacketToBufferChain(
|
|
||||||
PNDIS_BUFFER DstBuffer,
|
|
||||||
UINT DstOffset,
|
|
||||||
PNDIS_PACKET SrcPacket,
|
|
||||||
UINT SrcOffset,
|
|
||||||
UINT Length)
|
|
||||||
/*
|
|
||||||
* FUNCTION: Copies data from an NDIS packet to an NDIS buffer chain
|
|
||||||
* ARGUMENTS:
|
|
||||||
* DstBuffer = Pointer to destination NDIS buffer
|
|
||||||
* DstOffset = Destination start offset
|
|
||||||
* SrcPacket = Pointer to source NDIS packet
|
|
||||||
* SrcOffset = Source start offset
|
|
||||||
* Length = Number of bytes to copy
|
|
||||||
* RETURNS:
|
|
||||||
* Number of bytes copied to destination buffer
|
|
||||||
* NOTES:
|
|
||||||
* The number of bytes copied may be limited by the source and
|
|
||||||
* destination buffer sizes
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
PNDIS_BUFFER SrcBuffer;
|
|
||||||
PCHAR DstData, SrcData;
|
|
||||||
UINT DstSize, SrcSize;
|
|
||||||
UINT Count, Total;
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_PBUFFER, ("DstBuffer (0x%X) DstOffset (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcPacket, SrcOffset, Length));
|
|
||||||
|
|
||||||
/* Skip DstOffset bytes in the destination buffer chain */
|
|
||||||
NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
|
|
||||||
if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Skip SrcOffset bytes in the source packet */
|
|
||||||
NdisGetFirstBufferFromPacket(SrcPacket, &SrcBuffer, &SrcData, &SrcSize, &Total);
|
|
||||||
if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Copy the data */
|
|
||||||
for (Total = 0;;) {
|
|
||||||
/* Find out how many bytes we can copy at one time */
|
|
||||||
if (Length < SrcSize)
|
|
||||||
Count = Length;
|
|
||||||
else
|
|
||||||
Count = SrcSize;
|
|
||||||
if (DstSize < Count)
|
|
||||||
Count = DstSize;
|
|
||||||
|
|
||||||
RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, Count);
|
|
||||||
|
|
||||||
Total += Count;
|
|
||||||
Length -= Count;
|
|
||||||
if (Length == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
DstSize -= Count;
|
|
||||||
if (DstSize == 0) {
|
|
||||||
/* No more bytes in destination buffer. Proceed to
|
|
||||||
the next buffer in the destination buffer chain */
|
|
||||||
NdisGetNextBuffer(DstBuffer, &DstBuffer);
|
|
||||||
if (!DstBuffer)
|
|
||||||
break;
|
|
||||||
|
|
||||||
NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
SrcSize -= Count;
|
|
||||||
if (SrcSize == 0) {
|
|
||||||
/* No more bytes in source buffer. Proceed to
|
|
||||||
the next buffer in the source buffer chain */
|
|
||||||
NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
|
|
||||||
if (!SrcBuffer)
|
|
||||||
break;
|
|
||||||
|
|
||||||
NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Total;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PVOID AdjustPacket(
|
|
||||||
PNDIS_PACKET Packet,
|
|
||||||
UINT Available,
|
|
||||||
UINT Needed)
|
|
||||||
/*
|
|
||||||
* FUNCTION: Adjusts the amount of unused space at the beginning of the packet
|
|
||||||
* ARGUMENTS:
|
|
||||||
* Packet = Pointer to packet
|
|
||||||
* Available = Number of bytes available at start of first buffer
|
|
||||||
* Needed = Number of bytes needed for the header
|
|
||||||
* RETURNS:
|
|
||||||
* Pointer to start of packet
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
PNDIS_BUFFER NdisBuffer;
|
|
||||||
INT Adjust;
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_PBUFFER, ("Available = %d, Needed = %d.\n", Available, Needed));
|
|
||||||
|
|
||||||
Adjust = Available - Needed;
|
|
||||||
|
|
||||||
NdisQueryPacket(Packet, NULL, NULL, &NdisBuffer, NULL);
|
|
||||||
|
|
||||||
/* If Adjust is zero there is no need to adjust this packet as
|
|
||||||
there is no additional space at start the of first buffer */
|
|
||||||
if (Adjust != 0) {
|
|
||||||
NdisBuffer->MappedSystemVa = (PVOID) ((ULONG_PTR)(NdisBuffer->MappedSystemVa) + Adjust);
|
|
||||||
NdisBuffer->ByteOffset += Adjust;
|
|
||||||
NdisBuffer->ByteCount -= Adjust;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NdisBuffer->MappedSystemVa;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UINT ResizePacket(
|
|
||||||
PNDIS_PACKET Packet,
|
|
||||||
UINT Size)
|
|
||||||
/*
|
|
||||||
* FUNCTION: Resizes an NDIS packet
|
|
||||||
* ARGUMENTS:
|
|
||||||
* Packet = Pointer to packet
|
|
||||||
* Size = Number of bytes in first buffer
|
|
||||||
* RETURNS:
|
|
||||||
* Previous size of first buffer
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
PNDIS_BUFFER NdisBuffer;
|
|
||||||
UINT OldSize;
|
|
||||||
|
|
||||||
NdisQueryPacket(Packet, NULL, NULL, &NdisBuffer, NULL);
|
|
||||||
|
|
||||||
OldSize = NdisBuffer->ByteCount;
|
|
||||||
|
|
||||||
if (Size != OldSize)
|
|
||||||
NdisBuffer->ByteCount = Size;
|
|
||||||
|
|
||||||
return OldSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
|
|
||||||
static VOID DisplayIPHeader(
|
static VOID DisplayIPHeader(
|
||||||
|
@ -518,83 +181,3 @@ VOID DisplayTCPPacket(
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif/* DBG */
|
#endif/* DBG */
|
||||||
|
|
||||||
void GetDataPtr( PNDIS_PACKET Packet,
|
|
||||||
UINT Offset,
|
|
||||||
PCHAR *DataOut,
|
|
||||||
PUINT Size ) {
|
|
||||||
PNDIS_BUFFER Buffer;
|
|
||||||
|
|
||||||
NdisQueryPacket(Packet, NULL, NULL, &Buffer, NULL);
|
|
||||||
if( !Buffer ) return;
|
|
||||||
SkipToOffset( Buffer, Offset, DataOut, Size );
|
|
||||||
}
|
|
||||||
|
|
||||||
NDIS_STATUS AllocatePacketWithBufferX( PNDIS_PACKET *NdisPacket,
|
|
||||||
PCHAR Data, UINT Len,
|
|
||||||
PCHAR File, UINT Line ) {
|
|
||||||
PNDIS_PACKET Packet;
|
|
||||||
PNDIS_BUFFER Buffer;
|
|
||||||
NDIS_STATUS Status;
|
|
||||||
PCHAR NewData;
|
|
||||||
|
|
||||||
NewData = ExAllocatePool( NonPagedPool, Len );
|
|
||||||
if( !NewData ) return NDIS_STATUS_NOT_ACCEPTED; // XXX
|
|
||||||
TrackWithTag(EXALLOC_TAG, NewData, File, Line);
|
|
||||||
|
|
||||||
if( Data )
|
|
||||||
RtlCopyMemory(NewData, Data, Len);
|
|
||||||
|
|
||||||
NdisAllocatePacket( &Status, &Packet, GlobalPacketPool );
|
|
||||||
if( Status != NDIS_STATUS_SUCCESS ) {
|
|
||||||
ExFreePool( NewData );
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
TrackWithTag(NDIS_PACKET_TAG, Packet, File, Line);
|
|
||||||
|
|
||||||
NdisAllocateBuffer( &Status, &Buffer, GlobalBufferPool, NewData, Len );
|
|
||||||
if( Status != NDIS_STATUS_SUCCESS ) {
|
|
||||||
ExFreePool( NewData );
|
|
||||||
FreeNdisPacket( Packet );
|
|
||||||
}
|
|
||||||
TrackWithTag(NDIS_BUFFER_TAG, Buffer, File, Line);
|
|
||||||
|
|
||||||
NdisChainBufferAtFront( Packet, Buffer );
|
|
||||||
*NdisPacket = Packet;
|
|
||||||
|
|
||||||
return NDIS_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
VOID FreeNdisPacketX
|
|
||||||
( PNDIS_PACKET Packet,
|
|
||||||
PCHAR File,
|
|
||||||
UINT Line )
|
|
||||||
/*
|
|
||||||
* FUNCTION: Frees an NDIS packet
|
|
||||||
* ARGUMENTS:
|
|
||||||
* Packet = Pointer to NDIS packet to be freed
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
PNDIS_BUFFER Buffer, NextBuffer;
|
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_PBUFFER, ("Packet (0x%X)\n", Packet));
|
|
||||||
|
|
||||||
/* Free all the buffers in the packet first */
|
|
||||||
NdisQueryPacket(Packet, NULL, NULL, &Buffer, NULL);
|
|
||||||
for (; Buffer != NULL; Buffer = NextBuffer) {
|
|
||||||
PVOID Data;
|
|
||||||
UINT Length;
|
|
||||||
|
|
||||||
NdisGetNextBuffer(Buffer, &NextBuffer);
|
|
||||||
NdisQueryBuffer(Buffer, &Data, &Length);
|
|
||||||
UntrackFL(File,Line,Buffer);
|
|
||||||
NdisFreeBuffer(Buffer);
|
|
||||||
UntrackFL(File,Line,Data);
|
|
||||||
ExFreePool(Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Finally free the NDIS packet discriptor */
|
|
||||||
UntrackFL(File,Line,Packet);
|
|
||||||
NdisFreePacket(Packet);
|
|
||||||
}
|
|
||||||
|
|
|
@ -112,22 +112,8 @@ NTSTATUS SendFragments(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate NDIS packet */
|
/* Allocate NDIS packet */
|
||||||
NdisAllocatePacket(&NdisStatus, &IFC->NdisPacket, GlobalPacketPool);
|
NdisStatus = AllocatePacketWithBuffer
|
||||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
( &IFC->NdisPacket, Data, MaxLLHeaderSize + PathMTU );
|
||||||
exFreePool(Data);
|
|
||||||
exFreePool(IFC);
|
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate NDIS buffer */
|
|
||||||
NdisAllocateBuffer(&NdisStatus, &IFC->NdisBuffer,
|
|
||||||
GlobalBufferPool, Data, MaxLLHeaderSize + PathMTU);
|
|
||||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
|
||||||
FreeNdisPacket(IFC->NdisPacket);
|
|
||||||
exFreePool(Data);
|
|
||||||
exFreePool(IFC);
|
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Link NDIS buffer into packet */
|
/* Link NDIS buffer into packet */
|
||||||
NdisChainBufferAtFront(IFC->NdisPacket, IFC->NdisBuffer);
|
NdisChainBufferAtFront(IFC->NdisPacket, IFC->NdisBuffer);
|
||||||
|
|
|
@ -318,10 +318,9 @@ VOID DGDeliverData(
|
||||||
TI_DbgPrint(MAX_TRACE, ("Suitable receive request found.\n"));
|
TI_DbgPrint(MAX_TRACE, ("Suitable receive request found.\n"));
|
||||||
|
|
||||||
/* Copy the data into buffer provided by the user */
|
/* Copy the data into buffer provided by the user */
|
||||||
CopyBufferToBufferChain(Current->Buffer,
|
RtlCopyMemory( Current->Buffer,
|
||||||
0,
|
DataBuffer,
|
||||||
DataBuffer,
|
DataSize );
|
||||||
DataSize);
|
|
||||||
|
|
||||||
/* Complete the receive request */
|
/* Complete the receive request */
|
||||||
(*Current->Complete)(Current->Context, STATUS_SUCCESS, DataSize);
|
(*Current->Complete)(Current->Context, STATUS_SUCCESS, DataSize);
|
||||||
|
@ -506,9 +505,12 @@ NTSTATUS DGTransmit(
|
||||||
return STATUS_PENDING;
|
return STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
NTSTATUS DGSendDatagram(
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PADDRESS_FILE AddrFile,
|
||||||
PIP_PACKET Packet ) {
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
|
PCHAR BufferData,
|
||||||
|
ULONG DataSize,
|
||||||
|
PULONG DataUsed )
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Sends a datagram to a remote address
|
* FUNCTION: Sends a datagram to a remote address
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -518,14 +520,14 @@ NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
||||||
* RETURNS:
|
* RETURNS:
|
||||||
* Status of operation
|
* Status of operation
|
||||||
*/
|
*/
|
||||||
PADDRESS_FILE AddrFile;
|
{
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PDATAGRAM_SEND_REQUEST SendRequest;
|
PDATAGRAM_SEND_REQUEST SendRequest;
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||||
|
|
||||||
AddrFile = Request->Handle.AddressHandle;
|
*DataUsed = DataSize;
|
||||||
|
|
||||||
KeAcquireSpinLock(&AddrFile->Lock, &OldIrql);
|
KeAcquireSpinLock(&AddrFile->Lock, &OldIrql);
|
||||||
|
|
||||||
|
@ -538,12 +540,12 @@ NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
||||||
KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
|
KeReleaseSpinLock(&AddrFile->Lock, OldIrql);
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
SendRequest->Complete = Request->RequestNotifyObject;
|
SendRequest->Complete = NULL;
|
||||||
SendRequest->Context = Request->RequestContext;
|
SendRequest->Context = NULL;
|
||||||
NdisQueryPacketLength( Packet->NdisPacket,
|
SendRequest->Packet.Header = BufferData + MaxLLHeaderSize;
|
||||||
&SendRequest->BufferSize );
|
SendRequest->Packet.ContigSize = DataSize;
|
||||||
SendRequest->Packet = *Packet;
|
SendRequest->Packet.TotalSize = DataSize;
|
||||||
|
|
||||||
if (NT_SUCCESS(Status)) {
|
if (NT_SUCCESS(Status)) {
|
||||||
Status = AddrGetAddress(ConnInfo->RemoteAddress,
|
Status = AddrGetAddress(ConnInfo->RemoteAddress,
|
||||||
|
@ -578,13 +580,13 @@ NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS DGReceiveDatagram(
|
NTSTATUS DGReceiveDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR Buffer,
|
||||||
ULONG ReceiveLength,
|
ULONG ReceiveLength,
|
||||||
ULONG ReceiveFlags,
|
ULONG ReceiveFlags,
|
||||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||||
PULONG BytesReceived)
|
PULONG BytesReceived)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Attempts to receive a datagram from a remote address
|
* FUNCTION: Attempts to receive a datagram from a remote address
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -601,15 +603,12 @@ NTSTATUS DGReceiveDatagram(
|
||||||
* This is the high level interface for receiving datagrams
|
* This is the high level interface for receiving datagrams
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PADDRESS_FILE AddrFile;
|
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PDATAGRAM_RECEIVE_REQUEST ReceiveRequest;
|
PDATAGRAM_RECEIVE_REQUEST ReceiveRequest;
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||||
|
|
||||||
AddrFile = Request->Handle.AddressHandle;
|
|
||||||
|
|
||||||
KeAcquireSpinLock(&AddrFile->Lock, &OldIrql);
|
KeAcquireSpinLock(&AddrFile->Lock, &OldIrql);
|
||||||
|
|
||||||
if (AF_IS_VALID(AddrFile))
|
if (AF_IS_VALID(AddrFile))
|
||||||
|
@ -639,10 +638,9 @@ NTSTATUS DGReceiveDatagram(
|
||||||
ReceiveRequest->ReturnInfo = ReturnInfo;
|
ReceiveRequest->ReturnInfo = ReturnInfo;
|
||||||
ReceiveRequest->Buffer = Buffer;
|
ReceiveRequest->Buffer = Buffer;
|
||||||
/* If ReceiveLength is 0, the whole buffer is available to us */
|
/* If ReceiveLength is 0, the whole buffer is available to us */
|
||||||
ReceiveRequest->BufferSize = (ReceiveLength == 0) ?
|
ReceiveRequest->BufferSize = ReceiveLength;
|
||||||
MmGetMdlByteCount(Buffer) : ReceiveLength;
|
ReceiveRequest->Complete = NULL;
|
||||||
ReceiveRequest->Complete = Request->RequestNotifyObject;
|
ReceiveRequest->Context = NULL;
|
||||||
ReceiveRequest->Context = Request->RequestContext;
|
|
||||||
|
|
||||||
/* Queue receive request */
|
/* Queue receive request */
|
||||||
InsertTailList(&AddrFile->ReceiveQueue, &ReceiveRequest->ListEntry);
|
InsertTailList(&AddrFile->ReceiveQueue, &ReceiveRequest->ListEntry);
|
||||||
|
|
|
@ -76,10 +76,10 @@ NTSTATUS BuildRawIPPacket(
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS RawIPSendDatagram(
|
NTSTATUS RawIPSendDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR BufferData,
|
||||||
ULONG DataSize,
|
ULONG BufferLen,
|
||||||
PULONG DataUsed )
|
PULONG DataUsed )
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Sends a raw IP datagram to a remote address
|
* FUNCTION: Sends a raw IP datagram to a remote address
|
||||||
|
@ -93,13 +93,8 @@ NTSTATUS RawIPSendDatagram(
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
NDIS_STATUS Status;
|
NDIS_STATUS Status;
|
||||||
PCHAR BufferData;
|
|
||||||
UINT BufferLen;
|
|
||||||
PADDRESS_FILE AddrFile =
|
|
||||||
(PADDRESS_FILE)Request->Handle.AddressHandle;
|
|
||||||
IP_PACKET Packet;
|
IP_PACKET Packet;
|
||||||
|
|
||||||
NdisQueryBuffer( Buffer, &BufferData, &BufferLen );
|
|
||||||
Status = AllocatePacketWithBuffer( &Packet.NdisPacket,
|
Status = AllocatePacketWithBuffer( &Packet.NdisPacket,
|
||||||
BufferData,
|
BufferData,
|
||||||
BufferLen );
|
BufferLen );
|
||||||
|
@ -114,7 +109,8 @@ NTSTATUS RawIPSendDatagram(
|
||||||
AddrFile->ADE->Address,
|
AddrFile->ADE->Address,
|
||||||
AddrFile->Port );
|
AddrFile->Port );
|
||||||
if( Status == NDIS_STATUS_SUCCESS )
|
if( Status == NDIS_STATUS_SUCCESS )
|
||||||
Status = DGSendDatagram(Request, ConnInfo, &Packet);
|
Status = DGSendDatagram(AddrFile, ConnInfo, BufferData, BufferLen,
|
||||||
|
DataUsed);
|
||||||
else
|
else
|
||||||
FreeNdisPacket( Packet.NdisPacket );
|
FreeNdisPacket( Packet.NdisPacket );
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,6 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
VOID STDCALL KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql);
|
|
||||||
VOID STDCALL KeLowerIrql(KIRQL NewIrql);
|
|
||||||
|
|
||||||
extern ULONG TCP_IPIdentification;
|
extern ULONG TCP_IPIdentification;
|
||||||
extern LIST_ENTRY SleepingThreadsList;
|
extern LIST_ENTRY SleepingThreadsList;
|
||||||
extern FAST_MUTEX SleepingThreadsLock;
|
extern FAST_MUTEX SleepingThreadsLock;
|
||||||
|
@ -128,7 +125,6 @@ void TCPPacketSendComplete( PVOID Context,
|
||||||
|
|
||||||
int TCPPacketSend(void *ClientData, OSK_PCHAR data, OSK_UINT len ) {
|
int TCPPacketSend(void *ClientData, OSK_PCHAR data, OSK_UINT len ) {
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
KIRQL OldIrql;
|
|
||||||
NDIS_STATUS NdisStatus;
|
NDIS_STATUS NdisStatus;
|
||||||
ROUTE_CACHE_NODE *RCN;
|
ROUTE_CACHE_NODE *RCN;
|
||||||
IP_PACKET Packet = { 0 };
|
IP_PACKET Packet = { 0 };
|
||||||
|
@ -164,14 +160,12 @@ int TCPPacketSend(void *ClientData, OSK_PCHAR data, OSK_UINT len ) {
|
||||||
|
|
||||||
if( !NT_SUCCESS(Status) || !RCN ) return OSK_EADDRNOTAVAIL;
|
if( !NT_SUCCESS(Status) || !RCN ) return OSK_EADDRNOTAVAIL;
|
||||||
|
|
||||||
KeRaiseIrql( DISPATCH_LEVEL, &OldIrql );
|
|
||||||
|
|
||||||
NdisStatus =
|
NdisStatus =
|
||||||
AllocatePacketWithBuffer( &Packet.NdisPacket, data, len );
|
AllocatePacketWithBuffer( &Packet.NdisPacket, data, len );
|
||||||
|
|
||||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
||||||
TI_DbgPrint(MAX_TRACE, ("Error from NDIS: %08x\n", NdisStatus));
|
TI_DbgPrint(MAX_TRACE, ("Error from NDIS: %08x\n", NdisStatus));
|
||||||
goto end;
|
return STATUS_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdjustPacket( Packet.NdisPacket, 0, MaxLLHeaderSize );
|
AdjustPacket( Packet.NdisPacket, 0, MaxLLHeaderSize );
|
||||||
|
@ -187,9 +181,6 @@ int TCPPacketSend(void *ClientData, OSK_PCHAR data, OSK_UINT len ) {
|
||||||
|
|
||||||
IPSendFragment( Packet.NdisPacket, RCN->NCE );
|
IPSendFragment( Packet.NdisPacket, RCN->NCE );
|
||||||
|
|
||||||
end:
|
|
||||||
KeLowerIrql( OldIrql );
|
|
||||||
|
|
||||||
if( !NT_SUCCESS(NdisStatus) ) return OSK_EINVAL;
|
if( !NT_SUCCESS(NdisStatus) ) return OSK_EINVAL;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,10 @@ NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection,
|
||||||
UINT Family, UINT Type, UINT Proto ) {
|
UINT Family, UINT Type, UINT Proto ) {
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE,("Called: Connection %x, Family %d, Type %d, "
|
||||||
|
"Proto %d\n",
|
||||||
|
Connection, Family, Type, Proto));
|
||||||
|
|
||||||
RecursiveMutexEnter( &TCPLock, TRUE );
|
RecursiveMutexEnter( &TCPLock, TRUE );
|
||||||
Status = TCPTranslateError( OskitTCPSocket( Connection,
|
Status = TCPTranslateError( OskitTCPSocket( Connection,
|
||||||
&Connection->SocketContext,
|
&Connection->SocketContext,
|
||||||
|
|
|
@ -15,10 +15,12 @@ BOOLEAN UDPInitialized = FALSE;
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS AddUDPHeaderIPv4(
|
NTSTATUS AddUDPHeaderIPv4(
|
||||||
PDATAGRAM_SEND_REQUEST SendRequest,
|
PIP_ADDRESS RemoteAddress,
|
||||||
PIP_ADDRESS LocalAddress,
|
USHORT RemotePort,
|
||||||
USHORT LocalPort,
|
PIP_ADDRESS LocalAddress,
|
||||||
PIP_PACKET IPPacket)
|
USHORT LocalPort,
|
||||||
|
PIP_PACKET IPPacket,
|
||||||
|
UINT DataLength)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Adds an IPv4 and UDP header to an IP packet
|
* FUNCTION: Adds an IPv4 and UDP header to an IP packet
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -30,81 +32,77 @@ NTSTATUS AddUDPHeaderIPv4(
|
||||||
* Status of operation
|
* Status of operation
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PIPv4_HEADER IPHeader;
|
PIPv4_HEADER IPHeader;
|
||||||
PUDP_HEADER UDPHeader;
|
PUDP_HEADER UDPHeader;
|
||||||
PVOID Header;
|
ULONG BufferSize;
|
||||||
ULONG BufferSize;
|
|
||||||
NDIS_STATUS NdisStatus;
|
TI_DbgPrint(MID_TRACE, ("Packet: %x NdisPacket %x\n",
|
||||||
PNDIS_BUFFER HeaderBuffer;
|
IPPacket, IPPacket->NdisPacket));
|
||||||
|
|
||||||
|
BufferSize = MaxLLHeaderSize + sizeof(IPv4_HEADER) + sizeof(UDP_HEADER);
|
||||||
|
|
||||||
|
GetDataPtr( IPPacket->NdisPacket,
|
||||||
|
MaxLLHeaderSize,
|
||||||
|
(PCHAR *)&IPPacket->Header,
|
||||||
|
&IPPacket->ContigSize );
|
||||||
|
|
||||||
|
IPPacket->HeaderSize = 20;
|
||||||
|
|
||||||
|
TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n",
|
||||||
|
BufferSize, IPPacket->Header));
|
||||||
|
|
||||||
|
/* Build IPv4 header */
|
||||||
|
IPHeader = (PIPv4_HEADER)IPPacket->Header;
|
||||||
|
/* Version = 4, Length = 5 DWORDs */
|
||||||
|
IPHeader->VerIHL = 0x45;
|
||||||
|
/* Normal Type-of-Service */
|
||||||
|
IPHeader->Tos = 0;
|
||||||
|
/* Length of header and data */
|
||||||
|
IPHeader->TotalLength = WH2N((USHORT)IPPacket->TotalSize);
|
||||||
|
/* Identification */
|
||||||
|
IPHeader->Id = 0;
|
||||||
|
/* One fragment at offset 0 */
|
||||||
|
IPHeader->FlagsFragOfs = 0;
|
||||||
|
/* Time-to-Live is 128 */
|
||||||
|
IPHeader->Ttl = 128;
|
||||||
|
/* User Datagram Protocol */
|
||||||
|
IPHeader->Protocol = IPPROTO_UDP;
|
||||||
|
/* Checksum is 0 (for later calculation of this) */
|
||||||
|
IPHeader->Checksum = 0;
|
||||||
|
/* Source address */
|
||||||
|
IPHeader->SrcAddr = LocalAddress->Address.IPv4Address;
|
||||||
|
/* Destination address. FIXME: IPv4 only */
|
||||||
|
IPHeader->DstAddr = RemoteAddress->Address.IPv4Address;
|
||||||
|
|
||||||
|
/* Build UDP header */
|
||||||
|
UDPHeader = (PUDP_HEADER)(((PCHAR)IPHeader) + sizeof(IPv4_HEADER));
|
||||||
|
/* Port values are already big-endian values */
|
||||||
|
UDPHeader->SourcePort = LocalPort;
|
||||||
|
UDPHeader->DestPort = RemotePort;
|
||||||
|
/* FIXME: Calculate UDP checksum and put it in UDP header */
|
||||||
|
UDPHeader->Checksum = 0;
|
||||||
|
/* Length of UDP header and data */
|
||||||
|
UDPHeader->Length = WH2N(DataLength);
|
||||||
|
|
||||||
BufferSize = MaxLLHeaderSize + sizeof(IPv4_HEADER) + sizeof(UDP_HEADER);
|
IPPacket->Data = ((PCHAR)UDPHeader) + sizeof(UDP_HEADER);
|
||||||
Header = ExAllocatePool(NonPagedPool, BufferSize);
|
|
||||||
if (!Header) {
|
TI_DbgPrint(MID_TRACE, ("Packet: %d ip %d udp %d payload\n",
|
||||||
TI_DbgPrint(MIN_TRACE, ("Cannot allocate memory for packet headers.\n"));
|
(PCHAR)UDPHeader - (PCHAR)IPHeader,
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
(PCHAR)IPPacket->Data - (PCHAR)UDPHeader,
|
||||||
}
|
DataLength));
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n", BufferSize, Header));
|
return STATUS_SUCCESS;
|
||||||
|
|
||||||
/* Allocate NDIS buffer for maximum Link level, IP and UDP header */
|
|
||||||
NdisAllocateBuffer(&NdisStatus,
|
|
||||||
&HeaderBuffer,
|
|
||||||
GlobalBufferPool,
|
|
||||||
Header,
|
|
||||||
BufferSize);
|
|
||||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
|
||||||
TI_DbgPrint(MIN_TRACE, ("Cannot allocate NDIS buffer for packet headers. NdisStatus = (0x%X)\n", NdisStatus));
|
|
||||||
ExFreePool(Header);
|
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Chain header at front of NDIS packet */
|
|
||||||
NdisChainBufferAtFront(IPPacket->NdisPacket, HeaderBuffer);
|
|
||||||
|
|
||||||
IPPacket->Header = (PVOID)((ULONG_PTR)Header + MaxLLHeaderSize);
|
|
||||||
IPPacket->HeaderSize = 20;
|
|
||||||
|
|
||||||
/* Build IPv4 header */
|
|
||||||
IPHeader = (PIPv4_HEADER)IPPacket->Header;
|
|
||||||
/* Version = 4, Length = 5 DWORDs */
|
|
||||||
IPHeader->VerIHL = 0x45;
|
|
||||||
/* Normal Type-of-Service */
|
|
||||||
IPHeader->Tos = 0;
|
|
||||||
/* Length of header and data */
|
|
||||||
IPHeader->TotalLength = WH2N((USHORT)IPPacket->TotalSize);
|
|
||||||
/* Identification */
|
|
||||||
IPHeader->Id = 0;
|
|
||||||
/* One fragment at offset 0 */
|
|
||||||
IPHeader->FlagsFragOfs = 0;
|
|
||||||
/* Time-to-Live is 128 */
|
|
||||||
IPHeader->Ttl = 128;
|
|
||||||
/* User Datagram Protocol */
|
|
||||||
IPHeader->Protocol = IPPROTO_UDP;
|
|
||||||
/* Checksum is 0 (for later calculation of this) */
|
|
||||||
IPHeader->Checksum = 0;
|
|
||||||
/* Source address */
|
|
||||||
IPHeader->SrcAddr = LocalAddress->Address.IPv4Address;
|
|
||||||
/* Destination address. FIXME: IPv4 only */
|
|
||||||
IPHeader->DstAddr = SendRequest->RemoteAddress.Address.IPv4Address;
|
|
||||||
|
|
||||||
/* Build UDP header */
|
|
||||||
UDPHeader = (PUDP_HEADER)((ULONG_PTR)IPHeader + sizeof(IPv4_HEADER));
|
|
||||||
/* Port values are already big-endian values */
|
|
||||||
UDPHeader->SourcePort = LocalPort;
|
|
||||||
UDPHeader->DestPort = SendRequest->RemotePort;
|
|
||||||
/* FIXME: Calculate UDP checksum and put it in UDP header */
|
|
||||||
UDPHeader->Checksum = 0;
|
|
||||||
/* Length of UDP header and data */
|
|
||||||
UDPHeader->Length = WH2N((USHORT)IPPacket->TotalSize - IPPacket->HeaderSize);
|
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS BuildUDPPacket(
|
NTSTATUS BuildUDPPacket(
|
||||||
PVOID Context,
|
PIP_PACKET Packet,
|
||||||
PIP_ADDRESS LocalAddress,
|
PIP_ADDRESS RemoteAddress,
|
||||||
USHORT LocalPort)
|
USHORT RemotePort,
|
||||||
|
PIP_ADDRESS LocalAddress,
|
||||||
|
USHORT LocalPort,
|
||||||
|
PCHAR DataBuffer,
|
||||||
|
UINT DataLen )
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Builds an UDP packet
|
* FUNCTION: Builds an UDP packet
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -116,52 +114,68 @@ NTSTATUS BuildUDPPacket(
|
||||||
* Status of operation
|
* Status of operation
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PDATAGRAM_SEND_REQUEST SendRequest = (PDATAGRAM_SEND_REQUEST)Context;
|
|
||||||
PIP_PACKET Packet = &SendRequest->Packet;
|
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
/* FIXME: Assumes IPv4 */
|
||||||
|
IPInitializePacket(Packet, IP_ADDRESS_V4);
|
||||||
/* Prepare packet */
|
if (!Packet)
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
/* FIXME: Assumes IPv4 */
|
|
||||||
IPInitializePacket(&SendRequest->Packet, IP_ADDRESS_V4);
|
Packet->TotalSize =
|
||||||
if (!Packet)
|
MaxLLHeaderSize + sizeof(IPv4_HEADER) + sizeof(UDP_HEADER) + DataLen;
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
|
/* Prepare packet */
|
||||||
Packet->TotalSize = sizeof(IPv4_HEADER) +
|
Status = AllocatePacketWithBuffer( &Packet->NdisPacket,
|
||||||
sizeof(UDP_HEADER) +
|
NULL,
|
||||||
SendRequest->BufferSize;
|
Packet->TotalSize );
|
||||||
|
|
||||||
switch (SendRequest->RemoteAddress.Type) {
|
TI_DbgPrint(MID_TRACE, ("Allocated packet: %x\n", Packet->NdisPacket));
|
||||||
case IP_ADDRESS_V4:
|
TI_DbgPrint(MID_TRACE, ("Local Addr : %s\n", A2S(LocalAddress)));
|
||||||
Status = AddUDPHeaderIPv4(SendRequest, LocalAddress, LocalPort, Packet);
|
TI_DbgPrint(MID_TRACE, ("Remote Addr: %s\n", A2S(RemoteAddress)));
|
||||||
break;
|
|
||||||
case IP_ADDRESS_V6:
|
switch (RemoteAddress->Type) {
|
||||||
/* FIXME: Support IPv6 */
|
case IP_ADDRESS_V4:
|
||||||
TI_DbgPrint(MIN_TRACE, ("IPv6 UDP datagrams are not supported.\n"));
|
Status = AddUDPHeaderIPv4(RemoteAddress, RemotePort,
|
||||||
default:
|
LocalAddress, LocalPort, Packet, DataLen);
|
||||||
Status = STATUS_UNSUCCESSFUL;
|
break;
|
||||||
break;
|
case IP_ADDRESS_V6:
|
||||||
}
|
/* FIXME: Support IPv6 */
|
||||||
if (!NT_SUCCESS(Status)) {
|
TI_DbgPrint(MIN_TRACE, ("IPv6 UDP datagrams are not supported.\n"));
|
||||||
TI_DbgPrint(MIN_TRACE, ("Cannot add UDP header. Status = (0x%X)\n", Status));
|
default:
|
||||||
FreeNdisPacket(Packet->NdisPacket);
|
Status = STATUS_UNSUCCESSFUL;
|
||||||
return Status;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!NT_SUCCESS(Status)) {
|
||||||
DISPLAY_IP_PACKET(Packet);
|
TI_DbgPrint(MIN_TRACE, ("Cannot add UDP header. Status = (0x%X)\n",
|
||||||
|
Status));
|
||||||
return STATUS_SUCCESS;
|
FreeNdisPacket(Packet->NdisPacket);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE, ("Copying data (hdr %x data %x (%d))\n",
|
||||||
|
Packet->Header, Packet->Data,
|
||||||
|
(PCHAR)Packet->Data - (PCHAR)Packet->Header));
|
||||||
|
|
||||||
|
RtlCopyMemory( Packet->Data, DataBuffer, DataLen );
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE, ("Displaying packet\n"));
|
||||||
|
|
||||||
|
DISPLAY_IP_PACKET(Packet);
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE, ("Leaving\n"));
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS UDPSendDatagram(
|
NTSTATUS UDPSendDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR BufferData,
|
||||||
ULONG DataSize,
|
ULONG DataSize,
|
||||||
PULONG DataUsed )
|
PULONG DataUsed )
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Sends an UDP datagram to a remote address
|
* FUNCTION: Sends an UDP datagram to a remote address
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -173,31 +187,47 @@ NTSTATUS UDPSendDatagram(
|
||||||
* Status of operation
|
* Status of operation
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PDATAGRAM_SEND_REQUEST SendRequest;
|
IP_PACKET Packet;
|
||||||
PADDRESS_FILE AddrFile =
|
PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress;
|
||||||
(PADDRESS_FILE)Request->Handle.AddressHandle;
|
IP_ADDRESS RemoteAddress;
|
||||||
PCHAR BufferData;
|
USHORT RemotePort;
|
||||||
UINT BufferLen;
|
|
||||||
|
|
||||||
NdisQueryBuffer( Buffer, &BufferData, &BufferLen );
|
TI_DbgPrint(MID_TRACE,("Sending Datagram(%x %x %x %d)\n",
|
||||||
|
AddrFile, ConnInfo, BufferData, DataSize));
|
||||||
|
TI_DbgPrint(MID_TRACE,("RemoteAddressTa: %x\n", RemoteAddressTa));
|
||||||
|
|
||||||
*DataUsed = BufferLen;
|
switch( RemoteAddressTa->Address[0].AddressType ) {
|
||||||
|
case TDI_ADDRESS_TYPE_IP:
|
||||||
|
RemoteAddress.Type = IP_ADDRESS_V4;
|
||||||
|
RemoteAddress.Address.IPv4Address =
|
||||||
|
RemoteAddressTa->Address[0].Address[0].in_addr;
|
||||||
|
RemotePort = RemoteAddressTa->Address[0].Address[0].sin_port;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
|
||||||
BuildUDPPacket( SendRequest,
|
BuildUDPPacket( &Packet,
|
||||||
(PIP_ADDRESS)&AddrFile->ADE->Address->Address.
|
&RemoteAddress,
|
||||||
IPv4Address,
|
RemotePort,
|
||||||
AddrFile->Port );
|
AddrFile->ADE->Address,
|
||||||
|
AddrFile->Port,
|
||||||
|
BufferData,
|
||||||
|
DataSize );
|
||||||
|
|
||||||
return DGSendDatagram(Request,
|
return DGSendDatagram(AddrFile,
|
||||||
ConnInfo,
|
ConnInfo,
|
||||||
&SendRequest->Packet);
|
Packet.Header,
|
||||||
|
Packet.TotalSize,
|
||||||
|
DataUsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS UDPReceiveDatagram(
|
NTSTATUS UDPReceiveDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR BufferData,
|
||||||
ULONG ReceiveLength,
|
ULONG ReceiveLength,
|
||||||
ULONG ReceiveFlags,
|
ULONG ReceiveFlags,
|
||||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||||
|
@ -218,9 +248,9 @@ NTSTATUS UDPReceiveDatagram(
|
||||||
* This is the high level interface for receiving UDP datagrams
|
* This is the high level interface for receiving UDP datagrams
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
return DGReceiveDatagram(Request,
|
return DGReceiveDatagram(AddrFile,
|
||||||
ConnInfo,
|
ConnInfo,
|
||||||
Buffer,
|
BufferData,
|
||||||
ReceiveLength,
|
ReceiveLength,
|
||||||
ReceiveFlags,
|
ReceiveFlags,
|
||||||
ReturnInfo,
|
ReturnInfo,
|
||||||
|
|
|
@ -33,18 +33,20 @@ NTSTATUS DGTransmit(
|
||||||
PDATAGRAM_SEND_REQUEST SendRequest);
|
PDATAGRAM_SEND_REQUEST SendRequest);
|
||||||
|
|
||||||
NTSTATUS DGSendDatagram(
|
NTSTATUS DGSendDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PIP_PACKET Packet);
|
PCHAR BufferData,
|
||||||
|
ULONG DataSize,
|
||||||
|
PULONG DataUsed );
|
||||||
|
|
||||||
NTSTATUS DGReceiveDatagram(
|
NTSTATUS DGReceiveDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR Buffer,
|
||||||
ULONG ReceiveLength,
|
ULONG ReceiveLength,
|
||||||
ULONG ReceiveFlags,
|
ULONG ReceiveFlags,
|
||||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||||
PULONG BytesReceived);
|
PULONG BytesReceived);
|
||||||
|
|
||||||
NTSTATUS DGStartup(
|
NTSTATUS DGStartup(
|
||||||
VOID);
|
VOID);
|
||||||
|
|
|
@ -14,6 +14,9 @@ PVOID PoolAllocateBuffer(
|
||||||
VOID PoolFreeBuffer(
|
VOID PoolFreeBuffer(
|
||||||
PVOID Buffer);
|
PVOID Buffer);
|
||||||
|
|
||||||
|
NDIS_STATUS PrependPacket( PNDIS_PACKET Packet, PCHAR Data, UINT Len,
|
||||||
|
BOOLEAN Copy );
|
||||||
|
|
||||||
#endif /* __POOL_H */
|
#endif /* __POOL_H */
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
#define __RAWIP_H
|
#define __RAWIP_H
|
||||||
|
|
||||||
NTSTATUS RawIPSendDatagram(
|
NTSTATUS RawIPSendDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR Buffer,
|
||||||
ULONG DataSize,
|
ULONG DataSize,
|
||||||
PULONG DataUsed);
|
PULONG DataUsed);
|
||||||
|
|
||||||
|
|
|
@ -91,15 +91,16 @@
|
||||||
|
|
||||||
#include <ip.h>
|
#include <ip.h>
|
||||||
|
|
||||||
|
struct _ADDRESS_FILE;
|
||||||
|
|
||||||
/***************************************************
|
/***************************************************
|
||||||
* Connection-less communication support structures *
|
* Connection-less communication support structures *
|
||||||
***************************************************/
|
***************************************************/
|
||||||
|
|
||||||
typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE)(
|
typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE)(
|
||||||
PTDI_REQUEST Request,
|
struct _ADDRESS_FILE *AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR Buffer,
|
||||||
ULONG DataSize,
|
ULONG DataSize,
|
||||||
PULONG DataUsed);
|
PULONG DataUsed);
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ typedef struct _DATAGRAM_RECEIVE_REQUEST {
|
||||||
IP_ADDRESS RemoteAddress; /* Remote address we receive from (NULL means any) */
|
IP_ADDRESS RemoteAddress; /* Remote address we receive from (NULL means any) */
|
||||||
USHORT RemotePort; /* Remote port we receive from (0 means any) */
|
USHORT RemotePort; /* Remote port we receive from (0 means any) */
|
||||||
PTDI_CONNECTION_INFORMATION ReturnInfo; /* Return information */
|
PTDI_CONNECTION_INFORMATION ReturnInfo; /* Return information */
|
||||||
PNDIS_BUFFER Buffer; /* Pointer to receive buffer */
|
PCHAR Buffer; /* Pointer to receive buffer */
|
||||||
ULONG BufferSize; /* Size of Buffer */
|
ULONG BufferSize; /* Size of Buffer */
|
||||||
DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
|
DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
|
||||||
PVOID Context; /* Pointer to context information */
|
PVOID Context; /* Pointer to context information */
|
||||||
|
|
|
@ -39,20 +39,20 @@ VOID UDPSend(
|
||||||
PDATAGRAM_SEND_REQUEST SendRequest);
|
PDATAGRAM_SEND_REQUEST SendRequest);
|
||||||
|
|
||||||
NTSTATUS UDPSendDatagram(
|
NTSTATUS UDPSendDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR BufferData,
|
||||||
ULONG DataSize,
|
ULONG DataSize,
|
||||||
PULONG DataUsed);
|
PULONG DataUsed );
|
||||||
|
|
||||||
NTSTATUS UDPReceiveDatagram(
|
NTSTATUS UDPReceiveDatagram(
|
||||||
PTDI_REQUEST Request,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
PNDIS_BUFFER Buffer,
|
PCHAR Buffer,
|
||||||
ULONG ReceiveLength,
|
ULONG ReceiveLength,
|
||||||
ULONG ReceiveFlags,
|
ULONG ReceiveFlags,
|
||||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||||
PULONG BytesReceived);
|
PULONG BytesReceived);
|
||||||
|
|
||||||
VOID UDPReceive(
|
VOID UDPReceive(
|
||||||
PNET_TABLE_ENTRY NTE,
|
PNET_TABLE_ENTRY NTE,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# $Id: makefile,v 1.24 2004/09/30 16:30:43 arty Exp $
|
# $Id: makefile,v 1.25 2004/10/03 20:38:48 arty Exp $
|
||||||
|
|
||||||
PATH_TO_TOP = ../../..
|
PATH_TO_TOP = ../../..
|
||||||
|
|
||||||
|
@ -28,11 +28,12 @@ TARGET_DDKLIBS = \
|
||||||
|
|
||||||
TARGET_CLEAN = tcpip/*.o datalink/*.o
|
TARGET_CLEAN = tcpip/*.o datalink/*.o
|
||||||
|
|
||||||
TCPIP_OBJECTS = tcpip/main.o \
|
TCPIP_OBJECTS = tcpip/buffer.o \
|
||||||
tcpip/dispatch.o \
|
tcpip/dispatch.o \
|
||||||
tcpip/fileobjs.o \
|
tcpip/fileobjs.o \
|
||||||
tcpip/pool.o \
|
tcpip/irp.o \
|
||||||
tcpip/irp.o
|
tcpip/main.o \
|
||||||
|
tcpip/pool.o
|
||||||
INFO_OBJECTS = tcpip/info.o tcpip/ninfo.o tcpip/tinfo.o tcpip/iinfo.o
|
INFO_OBJECTS = tcpip/info.o tcpip/ninfo.o tcpip/tinfo.o tcpip/iinfo.o
|
||||||
DATALINK_OBJECTS = datalink/lan.o datalink/loopback.o
|
DATALINK_OBJECTS = datalink/lan.o datalink/loopback.o
|
||||||
|
|
||||||
|
|
|
@ -754,14 +754,21 @@ NTSTATUS DispTdiReceiveDatagram(
|
||||||
(PDRIVER_CANCEL)DispCancelRequest);
|
(PDRIVER_CANCEL)DispCancelRequest);
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
PCHAR DataBuffer;
|
||||||
|
UINT BufferSize;
|
||||||
|
|
||||||
|
NdisQueryBuffer( (PNDIS_BUFFER)Irp->MdlAddress,
|
||||||
|
&DataBuffer,
|
||||||
|
&BufferSize );
|
||||||
|
|
||||||
Status = UDPReceiveDatagram(
|
Status = UDPReceiveDatagram(
|
||||||
&Request,
|
Request.Handle.AddressHandle,
|
||||||
DgramInfo->ReceiveDatagramInformation,
|
DgramInfo->ReceiveDatagramInformation,
|
||||||
(PNDIS_BUFFER)Irp->MdlAddress,
|
DataBuffer,
|
||||||
DgramInfo->ReceiveLength,
|
DgramInfo->ReceiveLength,
|
||||||
DgramInfo->ReceiveFlags,
|
DgramInfo->ReceiveFlags,
|
||||||
DgramInfo->ReturnDatagramInformation,
|
DgramInfo->ReturnDatagramInformation,
|
||||||
&BytesReceived);
|
&BytesReceived);
|
||||||
if (Status != STATUS_PENDING)
|
if (Status != STATUS_PENDING)
|
||||||
{
|
{
|
||||||
DispDataRequestComplete(Irp, Status, BytesReceived);
|
DispDataRequestComplete(Irp, Status, BytesReceived);
|
||||||
|
@ -881,14 +888,28 @@ NTSTATUS DispTdiSendDatagram(
|
||||||
Irp,
|
Irp,
|
||||||
(PDRIVER_CANCEL)DispCancelRequest);
|
(PDRIVER_CANCEL)DispCancelRequest);
|
||||||
if (NT_SUCCESS(Status)) {
|
if (NT_SUCCESS(Status)) {
|
||||||
|
PCHAR DataBuffer;
|
||||||
|
UINT BufferSize;
|
||||||
|
|
||||||
|
TI_DbgPrint(MID_TRACE,("About to query buffer %x\n", Irp->MdlAddress));
|
||||||
|
|
||||||
|
NdisQueryBuffer( (PNDIS_BUFFER)Irp->MdlAddress,
|
||||||
|
&DataBuffer,
|
||||||
|
&BufferSize );
|
||||||
|
|
||||||
/* FIXME: DgramInfo->SendDatagramInformation->RemoteAddress
|
/* FIXME: DgramInfo->SendDatagramInformation->RemoteAddress
|
||||||
must be of type PTDI_ADDRESS_IP */
|
must be of type PTDI_ADDRESS_IP */
|
||||||
|
TI_DbgPrint(MID_TRACE,
|
||||||
|
("About to call send routine %x\n",
|
||||||
|
(*((PADDRESS_FILE)Request.Handle.AddressHandle)->Send)));
|
||||||
|
|
||||||
Status = (*((PADDRESS_FILE)Request.Handle.AddressHandle)->Send)(
|
Status = (*((PADDRESS_FILE)Request.Handle.AddressHandle)->Send)(
|
||||||
&Request, DgramInfo->SendDatagramInformation,
|
Request.Handle.AddressHandle,
|
||||||
(PNDIS_BUFFER)Irp->MdlAddress, DgramInfo->SendLength,
|
DgramInfo->SendDatagramInformation,
|
||||||
|
DataBuffer,
|
||||||
|
BufferSize,
|
||||||
&Irp->IoStatus.Information);
|
&Irp->IoStatus.Information);
|
||||||
|
|
||||||
if (Status != STATUS_PENDING) {
|
if (Status != STATUS_PENDING) {
|
||||||
DispDataRequestComplete(Irp, Status, Irp->IoStatus.Information);
|
DispDataRequestComplete(Irp, Status, Irp->IoStatus.Information);
|
||||||
/* Return STATUS_PENDING because DispPrepareIrpForCancel
|
/* Return STATUS_PENDING because DispPrepareIrpForCancel
|
||||||
|
@ -903,8 +924,7 @@ NTSTATUS DispTdiSendDatagram(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS DispTdiSetEventHandler(
|
NTSTATUS DispTdiSetEventHandler(PIRP Irp)
|
||||||
PIRP Irp)
|
|
||||||
/*
|
/*
|
||||||
* FUNCTION: TDI_SET_EVENT_HANDER handler
|
* FUNCTION: TDI_SET_EVENT_HANDER handler
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
|
|
@ -124,8 +124,7 @@ VOID ControlChannelFree(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID DeleteAddress(
|
VOID DeleteAddress(PADDRESS_FILE AddrFile)
|
||||||
PADDRESS_FILE AddrFile)
|
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Deletes an address file object
|
* FUNCTION: Deletes an address file object
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -514,8 +513,11 @@ NTSTATUS FileOpenConnection(
|
||||||
PCONNECTION_ENDPOINT Connection;
|
PCONNECTION_ENDPOINT Connection;
|
||||||
|
|
||||||
TI_DbgPrint(MID_TRACE, ("Called.\n"));
|
TI_DbgPrint(MID_TRACE, ("Called.\n"));
|
||||||
|
|
||||||
|
|
||||||
|
Connection = TCPAllocateConnectionEndpoint( ClientContext );
|
||||||
|
|
||||||
|
if( !Connection ) return STATUS_NO_MEMORY;
|
||||||
|
|
||||||
Status = TCPSocket( Connection, AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
Status = TCPSocket( Connection, AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||||
DbgPrint("STATUS from OSKITTCP was %08x\n", Status);
|
DbgPrint("STATUS from OSKITTCP was %08x\n", Status);
|
||||||
|
|
||||||
|
|
|
@ -503,6 +503,7 @@ TiDispatchInternal(
|
||||||
|
|
||||||
case TDI_RECEIVE_DATAGRAM:
|
case TDI_RECEIVE_DATAGRAM:
|
||||||
Status = DispTdiReceiveDatagram(Irp);
|
Status = DispTdiReceiveDatagram(Irp);
|
||||||
|
Complete = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TDI_SEND:
|
case TDI_SEND:
|
||||||
|
@ -512,6 +513,7 @@ TiDispatchInternal(
|
||||||
|
|
||||||
case TDI_SEND_DATAGRAM:
|
case TDI_SEND_DATAGRAM:
|
||||||
Status = DispTdiSendDatagram(Irp);
|
Status = DispTdiSendDatagram(Irp);
|
||||||
|
Complete = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TDI_ACCEPT:
|
case TDI_ACCEPT:
|
||||||
|
|
|
@ -24,7 +24,7 @@ PVOID PoolAllocateBuffer(
|
||||||
|
|
||||||
/* FIXME: Get buffer from a free buffer pool with enough room */
|
/* FIXME: Get buffer from a free buffer pool with enough room */
|
||||||
|
|
||||||
Buffer = ExAllocatePool(NonPagedPool, Size);
|
Buffer = exAllocatePool(NonPagedPool, Size);
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_MEMORY, ("Allocated (%i) bytes at (0x%X).\n", Size, Buffer));
|
TI_DbgPrint(DEBUG_MEMORY, ("Allocated (%i) bytes at (0x%X).\n", Size, Buffer));
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ VOID PoolFreeBuffer(
|
||||||
|
|
||||||
TI_DbgPrint(DEBUG_MEMORY, ("Freeing buffer at (0x%X).\n", Buffer));
|
TI_DbgPrint(DEBUG_MEMORY, ("Freeing buffer at (0x%X).\n", Buffer));
|
||||||
|
|
||||||
ExFreePool(Buffer);
|
exFreePool(Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Reference in a new issue