X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Ftcp.c;h=36837a5f5b09bcc8d67fbbc1363db7be1db904f5;hb=45f9a29e481ce9ea7ca7121541f0e0f90147f5b1;hp=135c9c80a3af7fdcc2ad20bf13fa68741e7e4734;hpb=f2fd50e797e6a3b3590e4c2e13b6782dd87c25a2;p=tpg%2Facess2.git diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index 135c9c80..36837a5f 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -48,8 +48,9 @@ Uint32 gaTCP_PortBitmap[0x800]; // === CODE === /** - * \fn void TCP_Initialise() * \brief Initialise the TCP Layer + * + * Registers the client and server files and the GetPacket callback */ void TCP_Initialise() { @@ -60,6 +61,7 @@ void TCP_Initialise() /** * \brief Open a connection to another host using TCP + * \param Conn Connection structure */ void TCP_StartConnection(tTCPConnection *Conn) { @@ -74,7 +76,7 @@ void TCP_StartConnection(tTCPConnection *Conn) hdr.WindowSize = 0; // TODO hdr.Checksum = 0; // TODO hdr.UrgentPointer = 0; - // SEND PACKET + TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr ); return ; } @@ -83,7 +85,7 @@ void TCP_StartConnection(tTCPConnection *Conn) * \brief Sends a packet from the specified connection, calculating the checksums * \param Conn Connection * \param Length Length of data - * \param Data Packet data + * \param Data Packet data (cast as a TCP Header) */ void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data ) { @@ -107,8 +109,11 @@ void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data ) } /** - * \fn void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer) * \brief Handles a packet from the IP Layer + * \param Interface Interface the packet arrived from + * \param Address Pointer to the addres structure + * \param Length Size of packet in bytes + * \param Buffer Packet data */ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer) { @@ -204,7 +209,6 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe } conn->NextSequenceRcv = ntohl( hdr->SequenceNumber ) + 1; - // + (Length-(hdr->DataOffset>>4)*4); conn->NextSequenceSend = rand(); // Create node @@ -271,6 +275,9 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe /** * \brief Handles a packet sent to a specific connection + * \param Connection TCP Connection pointer + * \param Header TCP Packet pointer + * \param Length Length of the packet */ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Header, int Length) { @@ -308,7 +315,7 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head // Is this packet the next expected packet? if( pkt->Sequence != Connection->NextSequenceRcv ) { - tTCPStoredPacket *tmp, *prev; + tTCPStoredPacket *tmp, *prev = NULL; Log("[TCP ] Out of sequence packet (0x%08x != 0x%08x)", pkt->Sequence, Connection->NextSequenceRcv); @@ -332,7 +339,10 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head { // Ooh, Goodie! Add it to the recieved list TCP_INT_AppendRecieved(Connection, pkt); - Connection->NextSequenceRcv ++; + if(dataLen) + Connection->NextSequenceRcv += dataLen; + else + Connection->NextSequenceRcv += 1; // TODO: This should be moved out of the watcher thread, // so that a single lost packet on one connection doesn't cause @@ -341,7 +351,7 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head } // TODO: Check ACK code validity - Header->AcknowlegementNumber = ntohl(pkt->Sequence); + Header->AcknowlegementNumber = ntohl(pkt->Sequence) + dataLen; Header->SequenceNumber = ntohl(Connection->NextSequenceSend); Header->Flags &= TCP_FLAG_SYN; Header->Flags = TCP_FLAG_ACK; @@ -350,6 +360,8 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head /** * \brief Appends a packet to the recieved list + * \param Connection Connection structure + * \param Pkt Packet structure on heap */ void TCP_INT_AppendRecieved(tTCPConnection *Connection, tTCPStoredPacket *Pkt) { @@ -369,6 +381,11 @@ void TCP_INT_AppendRecieved(tTCPConnection *Connection, tTCPStoredPacket *Pkt) /** * \brief Updates the connections recieved list from the future list + * \param Connection Connection structure + * + * Updates the recieved packets list with packets from the future (out + * of order) packets list that are now able to be added in direct + * sequence. */ void TCP_INT_UpdateRecievedFromFuture(tTCPConnection *Connection) { @@ -465,6 +482,13 @@ tVFS_Node *TCP_Server_Init(tInterface *Interface) { tTCPListener *srv = malloc( sizeof(tTCPListener) ); + Log_Debug("TCP", "srv = %p", srv); + + if( srv == NULL ) { + Log_Warning("TCP", "malloc failed for listener (%i) bytes", sizeof(tTCPListener)); + return NULL; + } + srv->Interface = Interface; srv->Port = 0; srv->NextID = 0;