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 <roscfg.h>
|
||||
#include <basetsd.h>
|
||||
#include <ddk/ntddk.h>
|
||||
#include <rosrtl/string.h>
|
||||
#include <rosrtl/recmutex.h>
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
|
||||
extern int sprintf( char *out, const char *fmt, ... );
|
||||
|
||||
#ifdef DBG
|
||||
|
||||
CHAR A2SStr[128];
|
||||
|
||||
PCHAR A2S(
|
||||
|
@ -55,8 +53,6 @@ PCHAR A2S(
|
|||
return p;
|
||||
}
|
||||
|
||||
#endif /* DBG */
|
||||
|
||||
ULONG IPv4NToHl( ULONG Address ) {
|
||||
return
|
||||
((Address & 0xff) << 24) |
|
||||
|
|
|
@ -53,7 +53,6 @@ PIP_PACKET PrepareICMPPacket(
|
|||
{
|
||||
PIP_PACKET IPPacket;
|
||||
PNDIS_PACKET NdisPacket;
|
||||
PNDIS_BUFFER NdisBuffer;
|
||||
NDIS_STATUS NdisStatus;
|
||||
PIPv4_HEADER IPHeader;
|
||||
PVOID DataBuffer;
|
||||
|
@ -75,38 +74,17 @@ PIP_PACKET PrepareICMPPacket(
|
|||
sizeof(ICMP_HEADER) + DataSize;
|
||||
DataBuffer = exAllocatePool(NonPagedPool, Size);
|
||||
if (!DataBuffer) {
|
||||
exFreePool( IPPacket );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
/* 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->Data = (PVOID)((ULONG_PTR)DataBuffer + MaxLLHeaderSize + sizeof(IPv4_HEADER));
|
||||
|
||||
IPPacket->HeaderSize = sizeof(IPv4_HEADER);
|
||||
IPPacket->Data = (PVOID)(((ULONG_PTR)IPPacket->Header) +
|
||||
IPPacket->HeaderSize);
|
||||
IPPacket->TotalSize = Size - MaxLLHeaderSize;
|
||||
RtlCopyMemory(&IPPacket->DstAddr, Destination, sizeof(IP_ADDRESS));
|
||||
|
||||
|
@ -136,9 +114,16 @@ PIP_PACKET PrepareICMPPacket(
|
|||
/* Destination address */
|
||||
IPHeader->DstAddr = Destination->Address.IPv4Address;
|
||||
|
||||
/* Completion handler */
|
||||
PC(NdisPacket)->Complete = SendICMPComplete;
|
||||
PC(NdisPacket)->Context = IPPacket;
|
||||
TI_DbgPrint(MID_TRACE,("Allocating packet\n"));
|
||||
/* Allocate NDIS packet */
|
||||
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;
|
||||
}
|
||||
|
@ -155,8 +140,6 @@ VOID ICMPReceive(
|
|||
*/
|
||||
{
|
||||
PICMP_HEADER ICMPHeader;
|
||||
PIP_PACKET NewPacket;
|
||||
UINT DataSize;
|
||||
|
||||
TI_DbgPrint(DEBUG_ICMP, ("Called.\n"));
|
||||
|
||||
|
@ -181,40 +164,22 @@ VOID ICMPReceive(
|
|||
|
||||
switch (ICMPHeader->Type) {
|
||||
case ICMP_TYPE_ECHO_REQUEST:
|
||||
/* Reply with an ICMP echo reply message */
|
||||
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"));
|
||||
ICMPReply( NTE, IPPacket, ICMP_TYPE_ECHO_REPLY, 0 );
|
||||
return;
|
||||
|
||||
case ICMP_TYPE_ECHO_REPLY:
|
||||
break;
|
||||
|
||||
default:
|
||||
TI_DbgPrint(DEBUG_ICMP, ("Discarded ICMP datagram of unknown type %d.\n",
|
||||
TI_DbgPrint(DEBUG_ICMP,
|
||||
("Discarded ICMP datagram of unknown type %d.\n",
|
||||
ICMPHeader->Type));
|
||||
/* Discard packet */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Send datagram up the protocol stack */
|
||||
RawIPReceive(NTE, IPPacket);
|
||||
/*RawIPReceive(NTE, IPPacket);*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -280,7 +245,8 @@ VOID ICMPReply(
|
|||
|
||||
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)))
|
||||
DataSize = 576;
|
||||
|
||||
|
@ -288,12 +254,16 @@ VOID ICMPReply(
|
|||
if (!NewPacket)
|
||||
return;
|
||||
|
||||
RtlCopyMemory((PVOID)((ULONG_PTR)NewPacket->Data + sizeof(ICMP_HEADER)),
|
||||
IPPacket->Header, DataSize);
|
||||
RtlCopyMemory(NewPacket->Data, IPPacket->Data,
|
||||
DataSize + sizeof(ICMP_HEADER));
|
||||
|
||||
((PICMP_HEADER)NewPacket->Data)->Type = Type;
|
||||
((PICMP_HEADER)NewPacket->Data)->Code = Code;
|
||||
((PICMP_HEADER)NewPacket->Data)->Checksum = 0;
|
||||
|
||||
PC(NewPacket->NdisPacket)->Complete = SendICMPComplete;
|
||||
PC(NewPacket->NdisPacket)->Context = NewPacket;
|
||||
|
||||
ICMPTransmit(NTE, NewPacket);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,343 +26,6 @@ UINT Random(
|
|||
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
|
||||
|
||||
static VOID DisplayIPHeader(
|
||||
|
@ -518,83 +181,3 @@ VOID DisplayTCPPacket(
|
|||
}
|
||||
|
||||
#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 */
|
||||
NdisAllocatePacket(&NdisStatus, &IFC->NdisPacket, GlobalPacketPool);
|
||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
||||
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;
|
||||
}
|
||||
NdisStatus = AllocatePacketWithBuffer
|
||||
( &IFC->NdisPacket, Data, MaxLLHeaderSize + PathMTU );
|
||||
|
||||
/* Link NDIS buffer into packet */
|
||||
NdisChainBufferAtFront(IFC->NdisPacket, IFC->NdisBuffer);
|
||||
|
|
|
@ -318,8 +318,7 @@ VOID DGDeliverData(
|
|||
TI_DbgPrint(MAX_TRACE, ("Suitable receive request found.\n"));
|
||||
|
||||
/* Copy the data into buffer provided by the user */
|
||||
CopyBufferToBufferChain(Current->Buffer,
|
||||
0,
|
||||
RtlCopyMemory( Current->Buffer,
|
||||
DataBuffer,
|
||||
DataSize );
|
||||
|
||||
|
@ -506,9 +505,12 @@ NTSTATUS DGTransmit(
|
|||
return STATUS_PENDING;
|
||||
}
|
||||
|
||||
NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
||||
NTSTATUS DGSendDatagram(
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PIP_PACKET Packet ) {
|
||||
PCHAR BufferData,
|
||||
ULONG DataSize,
|
||||
PULONG DataUsed )
|
||||
/*
|
||||
* FUNCTION: Sends a datagram to a remote address
|
||||
* ARGUMENTS:
|
||||
|
@ -518,14 +520,14 @@ NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
|||
* RETURNS:
|
||||
* Status of operation
|
||||
*/
|
||||
PADDRESS_FILE AddrFile;
|
||||
{
|
||||
KIRQL OldIrql;
|
||||
NTSTATUS Status;
|
||||
PDATAGRAM_SEND_REQUEST SendRequest;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
|
||||
AddrFile = Request->Handle.AddressHandle;
|
||||
*DataUsed = DataSize;
|
||||
|
||||
KeAcquireSpinLock(&AddrFile->Lock, &OldIrql);
|
||||
|
||||
|
@ -539,11 +541,11 @@ NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
|||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
SendRequest->Complete = Request->RequestNotifyObject;
|
||||
SendRequest->Context = Request->RequestContext;
|
||||
NdisQueryPacketLength( Packet->NdisPacket,
|
||||
&SendRequest->BufferSize );
|
||||
SendRequest->Packet = *Packet;
|
||||
SendRequest->Complete = NULL;
|
||||
SendRequest->Context = NULL;
|
||||
SendRequest->Packet.Header = BufferData + MaxLLHeaderSize;
|
||||
SendRequest->Packet.ContigSize = DataSize;
|
||||
SendRequest->Packet.TotalSize = DataSize;
|
||||
|
||||
if (NT_SUCCESS(Status)) {
|
||||
Status = AddrGetAddress(ConnInfo->RemoteAddress,
|
||||
|
@ -578,9 +580,9 @@ NTSTATUS DGSendDatagram( PTDI_REQUEST Request,
|
|||
|
||||
|
||||
NTSTATUS DGReceiveDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR Buffer,
|
||||
ULONG ReceiveLength,
|
||||
ULONG ReceiveFlags,
|
||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||
|
@ -601,15 +603,12 @@ NTSTATUS DGReceiveDatagram(
|
|||
* This is the high level interface for receiving datagrams
|
||||
*/
|
||||
{
|
||||
PADDRESS_FILE AddrFile;
|
||||
KIRQL OldIrql;
|
||||
NTSTATUS Status;
|
||||
PDATAGRAM_RECEIVE_REQUEST ReceiveRequest;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
|
||||
AddrFile = Request->Handle.AddressHandle;
|
||||
|
||||
KeAcquireSpinLock(&AddrFile->Lock, &OldIrql);
|
||||
|
||||
if (AF_IS_VALID(AddrFile))
|
||||
|
@ -639,10 +638,9 @@ NTSTATUS DGReceiveDatagram(
|
|||
ReceiveRequest->ReturnInfo = ReturnInfo;
|
||||
ReceiveRequest->Buffer = Buffer;
|
||||
/* If ReceiveLength is 0, the whole buffer is available to us */
|
||||
ReceiveRequest->BufferSize = (ReceiveLength == 0) ?
|
||||
MmGetMdlByteCount(Buffer) : ReceiveLength;
|
||||
ReceiveRequest->Complete = Request->RequestNotifyObject;
|
||||
ReceiveRequest->Context = Request->RequestContext;
|
||||
ReceiveRequest->BufferSize = ReceiveLength;
|
||||
ReceiveRequest->Complete = NULL;
|
||||
ReceiveRequest->Context = NULL;
|
||||
|
||||
/* Queue receive request */
|
||||
InsertTailList(&AddrFile->ReceiveQueue, &ReceiveRequest->ListEntry);
|
||||
|
|
|
@ -76,10 +76,10 @@ NTSTATUS BuildRawIPPacket(
|
|||
|
||||
|
||||
NTSTATUS RawIPSendDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
ULONG DataSize,
|
||||
PCHAR BufferData,
|
||||
ULONG BufferLen,
|
||||
PULONG DataUsed )
|
||||
/*
|
||||
* FUNCTION: Sends a raw IP datagram to a remote address
|
||||
|
@ -93,13 +93,8 @@ NTSTATUS RawIPSendDatagram(
|
|||
*/
|
||||
{
|
||||
NDIS_STATUS Status;
|
||||
PCHAR BufferData;
|
||||
UINT BufferLen;
|
||||
PADDRESS_FILE AddrFile =
|
||||
(PADDRESS_FILE)Request->Handle.AddressHandle;
|
||||
IP_PACKET Packet;
|
||||
|
||||
NdisQueryBuffer( Buffer, &BufferData, &BufferLen );
|
||||
Status = AllocatePacketWithBuffer( &Packet.NdisPacket,
|
||||
BufferData,
|
||||
BufferLen );
|
||||
|
@ -114,7 +109,8 @@ NTSTATUS RawIPSendDatagram(
|
|||
AddrFile->ADE->Address,
|
||||
AddrFile->Port );
|
||||
if( Status == NDIS_STATUS_SUCCESS )
|
||||
Status = DGSendDatagram(Request, ConnInfo, &Packet);
|
||||
Status = DGSendDatagram(AddrFile, ConnInfo, BufferData, BufferLen,
|
||||
DataUsed);
|
||||
else
|
||||
FreeNdisPacket( Packet.NdisPacket );
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
|
||||
#include "precomp.h"
|
||||
|
||||
VOID STDCALL KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql);
|
||||
VOID STDCALL KeLowerIrql(KIRQL NewIrql);
|
||||
|
||||
extern ULONG TCP_IPIdentification;
|
||||
extern LIST_ENTRY SleepingThreadsList;
|
||||
extern FAST_MUTEX SleepingThreadsLock;
|
||||
|
@ -128,7 +125,6 @@ void TCPPacketSendComplete( PVOID Context,
|
|||
|
||||
int TCPPacketSend(void *ClientData, OSK_PCHAR data, OSK_UINT len ) {
|
||||
NTSTATUS Status;
|
||||
KIRQL OldIrql;
|
||||
NDIS_STATUS NdisStatus;
|
||||
ROUTE_CACHE_NODE *RCN;
|
||||
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;
|
||||
|
||||
KeRaiseIrql( DISPATCH_LEVEL, &OldIrql );
|
||||
|
||||
NdisStatus =
|
||||
AllocatePacketWithBuffer( &Packet.NdisPacket, data, len );
|
||||
|
||||
if (NdisStatus != NDIS_STATUS_SUCCESS) {
|
||||
TI_DbgPrint(MAX_TRACE, ("Error from NDIS: %08x\n", NdisStatus));
|
||||
goto end;
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
AdjustPacket( Packet.NdisPacket, 0, MaxLLHeaderSize );
|
||||
|
@ -187,9 +181,6 @@ int TCPPacketSend(void *ClientData, OSK_PCHAR data, OSK_UINT len ) {
|
|||
|
||||
IPSendFragment( Packet.NdisPacket, RCN->NCE );
|
||||
|
||||
end:
|
||||
KeLowerIrql( OldIrql );
|
||||
|
||||
if( !NT_SUCCESS(NdisStatus) ) return OSK_EINVAL;
|
||||
else return 0;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,10 @@ NTSTATUS TCPSocket( PCONNECTION_ENDPOINT Connection,
|
|||
UINT Family, UINT Type, UINT Proto ) {
|
||||
NTSTATUS Status;
|
||||
|
||||
TI_DbgPrint(MID_TRACE,("Called: Connection %x, Family %d, Type %d, "
|
||||
"Proto %d\n",
|
||||
Connection, Family, Type, Proto));
|
||||
|
||||
RecursiveMutexEnter( &TCPLock, TRUE );
|
||||
Status = TCPTranslateError( OskitTCPSocket( Connection,
|
||||
&Connection->SocketContext,
|
||||
|
|
|
@ -15,10 +15,12 @@ BOOLEAN UDPInitialized = FALSE;
|
|||
|
||||
|
||||
NTSTATUS AddUDPHeaderIPv4(
|
||||
PDATAGRAM_SEND_REQUEST SendRequest,
|
||||
PIP_ADDRESS RemoteAddress,
|
||||
USHORT RemotePort,
|
||||
PIP_ADDRESS LocalAddress,
|
||||
USHORT LocalPort,
|
||||
PIP_PACKET IPPacket)
|
||||
PIP_PACKET IPPacket,
|
||||
UINT DataLength)
|
||||
/*
|
||||
* FUNCTION: Adds an IPv4 and UDP header to an IP packet
|
||||
* ARGUMENTS:
|
||||
|
@ -32,38 +34,23 @@ NTSTATUS AddUDPHeaderIPv4(
|
|||
{
|
||||
PIPv4_HEADER IPHeader;
|
||||
PUDP_HEADER UDPHeader;
|
||||
PVOID Header;
|
||||
ULONG BufferSize;
|
||||
NDIS_STATUS NdisStatus;
|
||||
PNDIS_BUFFER HeaderBuffer;
|
||||
|
||||
TI_DbgPrint(MID_TRACE, ("Packet: %x NdisPacket %x\n",
|
||||
IPPacket, IPPacket->NdisPacket));
|
||||
|
||||
BufferSize = MaxLLHeaderSize + sizeof(IPv4_HEADER) + sizeof(UDP_HEADER);
|
||||
Header = ExAllocatePool(NonPagedPool, BufferSize);
|
||||
if (!Header) {
|
||||
TI_DbgPrint(MIN_TRACE, ("Cannot allocate memory for packet headers.\n"));
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n", BufferSize, Header));
|
||||
GetDataPtr( IPPacket->NdisPacket,
|
||||
MaxLLHeaderSize,
|
||||
(PCHAR *)&IPPacket->Header,
|
||||
&IPPacket->ContigSize );
|
||||
|
||||
/* 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;
|
||||
|
||||
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 */
|
||||
|
@ -85,26 +72,37 @@ NTSTATUS AddUDPHeaderIPv4(
|
|||
/* Source address */
|
||||
IPHeader->SrcAddr = LocalAddress->Address.IPv4Address;
|
||||
/* Destination address. FIXME: IPv4 only */
|
||||
IPHeader->DstAddr = SendRequest->RemoteAddress.Address.IPv4Address;
|
||||
IPHeader->DstAddr = RemoteAddress->Address.IPv4Address;
|
||||
|
||||
/* Build UDP header */
|
||||
UDPHeader = (PUDP_HEADER)((ULONG_PTR)IPHeader + sizeof(IPv4_HEADER));
|
||||
UDPHeader = (PUDP_HEADER)(((PCHAR)IPHeader) + sizeof(IPv4_HEADER));
|
||||
/* Port values are already big-endian values */
|
||||
UDPHeader->SourcePort = LocalPort;
|
||||
UDPHeader->DestPort = SendRequest->RemotePort;
|
||||
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((USHORT)IPPacket->TotalSize - IPPacket->HeaderSize);
|
||||
UDPHeader->Length = WH2N(DataLength);
|
||||
|
||||
IPPacket->Data = ((PCHAR)UDPHeader) + sizeof(UDP_HEADER);
|
||||
|
||||
TI_DbgPrint(MID_TRACE, ("Packet: %d ip %d udp %d payload\n",
|
||||
(PCHAR)UDPHeader - (PCHAR)IPHeader,
|
||||
(PCHAR)IPPacket->Data - (PCHAR)UDPHeader,
|
||||
DataLength));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS BuildUDPPacket(
|
||||
PVOID Context,
|
||||
PIP_PACKET Packet,
|
||||
PIP_ADDRESS RemoteAddress,
|
||||
USHORT RemotePort,
|
||||
PIP_ADDRESS LocalAddress,
|
||||
USHORT LocalPort)
|
||||
USHORT LocalPort,
|
||||
PCHAR DataBuffer,
|
||||
UINT DataLen )
|
||||
/*
|
||||
* FUNCTION: Builds an UDP packet
|
||||
* ARGUMENTS:
|
||||
|
@ -117,25 +115,30 @@ NTSTATUS BuildUDPPacket(
|
|||
*/
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PDATAGRAM_SEND_REQUEST SendRequest = (PDATAGRAM_SEND_REQUEST)Context;
|
||||
PIP_PACKET Packet = &SendRequest->Packet;
|
||||
|
||||
TI_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
|
||||
/* Prepare packet */
|
||||
|
||||
/* FIXME: Assumes IPv4 */
|
||||
IPInitializePacket(&SendRequest->Packet, IP_ADDRESS_V4);
|
||||
IPInitializePacket(Packet, IP_ADDRESS_V4);
|
||||
if (!Packet)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
Packet->TotalSize = sizeof(IPv4_HEADER) +
|
||||
sizeof(UDP_HEADER) +
|
||||
SendRequest->BufferSize;
|
||||
Packet->TotalSize =
|
||||
MaxLLHeaderSize + sizeof(IPv4_HEADER) + sizeof(UDP_HEADER) + DataLen;
|
||||
|
||||
switch (SendRequest->RemoteAddress.Type) {
|
||||
/* Prepare packet */
|
||||
Status = AllocatePacketWithBuffer( &Packet->NdisPacket,
|
||||
NULL,
|
||||
Packet->TotalSize );
|
||||
|
||||
TI_DbgPrint(MID_TRACE, ("Allocated packet: %x\n", Packet->NdisPacket));
|
||||
TI_DbgPrint(MID_TRACE, ("Local Addr : %s\n", A2S(LocalAddress)));
|
||||
TI_DbgPrint(MID_TRACE, ("Remote Addr: %s\n", A2S(RemoteAddress)));
|
||||
|
||||
switch (RemoteAddress->Type) {
|
||||
case IP_ADDRESS_V4:
|
||||
Status = AddUDPHeaderIPv4(SendRequest, LocalAddress, LocalPort, Packet);
|
||||
Status = AddUDPHeaderIPv4(RemoteAddress, RemotePort,
|
||||
LocalAddress, LocalPort, Packet, DataLen);
|
||||
break;
|
||||
case IP_ADDRESS_V6:
|
||||
/* FIXME: Support IPv6 */
|
||||
|
@ -145,21 +148,32 @@ NTSTATUS BuildUDPPacket(
|
|||
break;
|
||||
}
|
||||
if (!NT_SUCCESS(Status)) {
|
||||
TI_DbgPrint(MIN_TRACE, ("Cannot add UDP header. Status = (0x%X)\n", Status));
|
||||
TI_DbgPrint(MIN_TRACE, ("Cannot add UDP header. Status = (0x%X)\n",
|
||||
Status));
|
||||
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(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR BufferData,
|
||||
ULONG DataSize,
|
||||
PULONG DataUsed )
|
||||
/*
|
||||
|
@ -173,31 +187,47 @@ NTSTATUS UDPSendDatagram(
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
PDATAGRAM_SEND_REQUEST SendRequest;
|
||||
PADDRESS_FILE AddrFile =
|
||||
(PADDRESS_FILE)Request->Handle.AddressHandle;
|
||||
PCHAR BufferData;
|
||||
UINT BufferLen;
|
||||
IP_PACKET Packet;
|
||||
PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress;
|
||||
IP_ADDRESS RemoteAddress;
|
||||
USHORT RemotePort;
|
||||
|
||||
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;
|
||||
|
||||
BuildUDPPacket( SendRequest,
|
||||
(PIP_ADDRESS)&AddrFile->ADE->Address->Address.
|
||||
IPv4Address,
|
||||
AddrFile->Port );
|
||||
default:
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
return DGSendDatagram(Request,
|
||||
BuildUDPPacket( &Packet,
|
||||
&RemoteAddress,
|
||||
RemotePort,
|
||||
AddrFile->ADE->Address,
|
||||
AddrFile->Port,
|
||||
BufferData,
|
||||
DataSize );
|
||||
|
||||
return DGSendDatagram(AddrFile,
|
||||
ConnInfo,
|
||||
&SendRequest->Packet);
|
||||
Packet.Header,
|
||||
Packet.TotalSize,
|
||||
DataUsed);
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS UDPReceiveDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR BufferData,
|
||||
ULONG ReceiveLength,
|
||||
ULONG ReceiveFlags,
|
||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||
|
@ -218,9 +248,9 @@ NTSTATUS UDPReceiveDatagram(
|
|||
* This is the high level interface for receiving UDP datagrams
|
||||
*/
|
||||
{
|
||||
return DGReceiveDatagram(Request,
|
||||
return DGReceiveDatagram(AddrFile,
|
||||
ConnInfo,
|
||||
Buffer,
|
||||
BufferData,
|
||||
ReceiveLength,
|
||||
ReceiveFlags,
|
||||
ReturnInfo,
|
||||
|
|
|
@ -33,14 +33,16 @@ NTSTATUS DGTransmit(
|
|||
PDATAGRAM_SEND_REQUEST SendRequest);
|
||||
|
||||
NTSTATUS DGSendDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PIP_PACKET Packet);
|
||||
PCHAR BufferData,
|
||||
ULONG DataSize,
|
||||
PULONG DataUsed );
|
||||
|
||||
NTSTATUS DGReceiveDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR Buffer,
|
||||
ULONG ReceiveLength,
|
||||
ULONG ReceiveFlags,
|
||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||
|
|
|
@ -14,6 +14,9 @@ PVOID PoolAllocateBuffer(
|
|||
VOID PoolFreeBuffer(
|
||||
PVOID Buffer);
|
||||
|
||||
NDIS_STATUS PrependPacket( PNDIS_PACKET Packet, PCHAR Data, UINT Len,
|
||||
BOOLEAN Copy );
|
||||
|
||||
#endif /* __POOL_H */
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
#define __RAWIP_H
|
||||
|
||||
NTSTATUS RawIPSendDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR Buffer,
|
||||
ULONG DataSize,
|
||||
PULONG DataUsed);
|
||||
|
||||
|
|
|
@ -91,15 +91,16 @@
|
|||
|
||||
#include <ip.h>
|
||||
|
||||
struct _ADDRESS_FILE;
|
||||
|
||||
/***************************************************
|
||||
* Connection-less communication support structures *
|
||||
***************************************************/
|
||||
|
||||
typedef NTSTATUS (*DATAGRAM_SEND_ROUTINE)(
|
||||
PTDI_REQUEST Request,
|
||||
struct _ADDRESS_FILE *AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR Buffer,
|
||||
ULONG DataSize,
|
||||
PULONG DataUsed);
|
||||
|
||||
|
@ -114,7 +115,7 @@ typedef struct _DATAGRAM_RECEIVE_REQUEST {
|
|||
IP_ADDRESS RemoteAddress; /* Remote address we receive from (NULL means any) */
|
||||
USHORT RemotePort; /* Remote port we receive from (0 means any) */
|
||||
PTDI_CONNECTION_INFORMATION ReturnInfo; /* Return information */
|
||||
PNDIS_BUFFER Buffer; /* Pointer to receive buffer */
|
||||
PCHAR Buffer; /* Pointer to receive buffer */
|
||||
ULONG BufferSize; /* Size of Buffer */
|
||||
DATAGRAM_COMPLETION_ROUTINE Complete; /* Completion routine */
|
||||
PVOID Context; /* Pointer to context information */
|
||||
|
|
|
@ -39,16 +39,16 @@ VOID UDPSend(
|
|||
PDATAGRAM_SEND_REQUEST SendRequest);
|
||||
|
||||
NTSTATUS UDPSendDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR BufferData,
|
||||
ULONG DataSize,
|
||||
PULONG DataUsed );
|
||||
|
||||
NTSTATUS UDPReceiveDatagram(
|
||||
PTDI_REQUEST Request,
|
||||
PADDRESS_FILE AddrFile,
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||
PNDIS_BUFFER Buffer,
|
||||
PCHAR Buffer,
|
||||
ULONG ReceiveLength,
|
||||
ULONG ReceiveFlags,
|
||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||
|
|
|
@ -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 = ../../..
|
||||
|
||||
|
@ -28,11 +28,12 @@ TARGET_DDKLIBS = \
|
|||
|
||||
TARGET_CLEAN = tcpip/*.o datalink/*.o
|
||||
|
||||
TCPIP_OBJECTS = tcpip/main.o \
|
||||
TCPIP_OBJECTS = tcpip/buffer.o \
|
||||
tcpip/dispatch.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
|
||||
DATALINK_OBJECTS = datalink/lan.o datalink/loopback.o
|
||||
|
||||
|
|
|
@ -754,10 +754,17 @@ NTSTATUS DispTdiReceiveDatagram(
|
|||
(PDRIVER_CANCEL)DispCancelRequest);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
PCHAR DataBuffer;
|
||||
UINT BufferSize;
|
||||
|
||||
NdisQueryBuffer( (PNDIS_BUFFER)Irp->MdlAddress,
|
||||
&DataBuffer,
|
||||
&BufferSize );
|
||||
|
||||
Status = UDPReceiveDatagram(
|
||||
&Request,
|
||||
Request.Handle.AddressHandle,
|
||||
DgramInfo->ReceiveDatagramInformation,
|
||||
(PNDIS_BUFFER)Irp->MdlAddress,
|
||||
DataBuffer,
|
||||
DgramInfo->ReceiveLength,
|
||||
DgramInfo->ReceiveFlags,
|
||||
DgramInfo->ReturnDatagramInformation,
|
||||
|
@ -881,14 +888,28 @@ NTSTATUS DispTdiSendDatagram(
|
|||
Irp,
|
||||
(PDRIVER_CANCEL)DispCancelRequest);
|
||||
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
|
||||
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)(
|
||||
&Request, DgramInfo->SendDatagramInformation,
|
||||
(PNDIS_BUFFER)Irp->MdlAddress, DgramInfo->SendLength,
|
||||
Request.Handle.AddressHandle,
|
||||
DgramInfo->SendDatagramInformation,
|
||||
DataBuffer,
|
||||
BufferSize,
|
||||
&Irp->IoStatus.Information);
|
||||
|
||||
if (Status != STATUS_PENDING) {
|
||||
DispDataRequestComplete(Irp, Status, Irp->IoStatus.Information);
|
||||
/* Return STATUS_PENDING because DispPrepareIrpForCancel
|
||||
|
@ -903,8 +924,7 @@ NTSTATUS DispTdiSendDatagram(
|
|||
}
|
||||
|
||||
|
||||
NTSTATUS DispTdiSetEventHandler(
|
||||
PIRP Irp)
|
||||
NTSTATUS DispTdiSetEventHandler(PIRP Irp)
|
||||
/*
|
||||
* FUNCTION: TDI_SET_EVENT_HANDER handler
|
||||
* ARGUMENTS:
|
||||
|
|
|
@ -124,8 +124,7 @@ VOID ControlChannelFree(
|
|||
}
|
||||
|
||||
|
||||
VOID DeleteAddress(
|
||||
PADDRESS_FILE AddrFile)
|
||||
VOID DeleteAddress(PADDRESS_FILE AddrFile)
|
||||
/*
|
||||
* FUNCTION: Deletes an address file object
|
||||
* ARGUMENTS:
|
||||
|
@ -515,6 +514,9 @@ NTSTATUS FileOpenConnection(
|
|||
|
||||
TI_DbgPrint(MID_TRACE, ("Called.\n"));
|
||||
|
||||
Connection = TCPAllocateConnectionEndpoint( ClientContext );
|
||||
|
||||
if( !Connection ) return STATUS_NO_MEMORY;
|
||||
|
||||
Status = TCPSocket( Connection, AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
DbgPrint("STATUS from OSKITTCP was %08x\n", Status);
|
||||
|
|
|
@ -503,6 +503,7 @@ TiDispatchInternal(
|
|||
|
||||
case TDI_RECEIVE_DATAGRAM:
|
||||
Status = DispTdiReceiveDatagram(Irp);
|
||||
Complete = FALSE;
|
||||
break;
|
||||
|
||||
case TDI_SEND:
|
||||
|
@ -512,6 +513,7 @@ TiDispatchInternal(
|
|||
|
||||
case TDI_SEND_DATAGRAM:
|
||||
Status = DispTdiSendDatagram(Irp);
|
||||
Complete = FALSE;
|
||||
break;
|
||||
|
||||
case TDI_ACCEPT:
|
||||
|
|
|
@ -24,7 +24,7 @@ PVOID PoolAllocateBuffer(
|
|||
|
||||
/* 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));
|
||||
|
||||
|
@ -44,7 +44,7 @@ VOID PoolFreeBuffer(
|
|||
|
||||
TI_DbgPrint(DEBUG_MEMORY, ("Freeing buffer at (0x%X).\n", Buffer));
|
||||
|
||||
ExFreePool(Buffer);
|
||||
exFreePool(Buffer);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
Loading…
Reference in a new issue