void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Header, int Length);
int TCP_INT_AppendRecieved(tTCPConnection *Connection, const void *Data, size_t Length);
void TCP_INT_UpdateRecievedFromFuture(tTCPConnection *Connection);
void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Header, int Length);
int TCP_INT_AppendRecieved(tTCPConnection *Connection, const void *Data, size_t Length);
void TCP_INT_UpdateRecievedFromFuture(tTCPConnection *Connection);
Uint16 TCP_GetUnusedPort();
int TCP_AllocatePort(Uint16 Port);
int TCP_DeallocatePort(Uint16 Port);
Uint16 TCP_GetUnusedPort();
int TCP_AllocatePort(Uint16 Port);
int TCP_DeallocatePort(Uint16 Port);
Log_Log("TCP", "TCP_GetPacket: <Local>:%i from [%s]:%i, Flags = %s%s%s%s%s%s%s%s",
ntohs(hdr->DestPort),
IPStack_PrintAddress(Interface->Type, Address),
Log_Log("TCP", "TCP_GetPacket: <Local>:%i from [%s]:%i, Flags = %s%s%s%s%s%s%s%s",
ntohs(hdr->DestPort),
IPStack_PrintAddress(Interface->Type, Address),
(hdr->Flags & TCP_FLAG_SYN) ? "SYN " : "",
(hdr->Flags & TCP_FLAG_FIN) ? "FIN " : ""
);
(hdr->Flags & TCP_FLAG_SYN) ? "SYN " : "",
(hdr->Flags & TCP_FLAG_FIN) ? "FIN " : ""
);
if(Header->Flags & TCP_FLAG_SYN) {
// TODO: What if the packet also has data?
if( Connection->LastACKSequence != Connection->NextSequenceRcv )
if(Header->Flags & TCP_FLAG_SYN) {
// TODO: What if the packet also has data?
if( Connection->LastACKSequence != Connection->NextSequenceRcv )
Connection->NextSequenceRcv = ntohl(Header->SequenceNumber);
Connection->LastACKSequence = Connection->NextSequenceRcv;
}
Connection->NextSequenceRcv = ntohl(Header->SequenceNumber);
Connection->LastACKSequence = Connection->NextSequenceRcv;
}
// Get length of data
dataLen = Length - (Header->DataOffset>>4)*4;
LOG("dataLen = %i", dataLen);
// Get length of data
dataLen = Length - (Header->DataOffset>>4)*4;
LOG("dataLen = %i", dataLen);
Log_Debug("TCP", "State %i, dataLen = %x", Connection->State, dataLen);
Log_Debug("TCP", "State %i, dataLen = %x", Connection->State, dataLen);
}
Connection->NextSequenceRcv ++; // TODO: Is this right? (empty packet counts as one byte)
Log_Log("TCP", "Empty Packet, inc and ACK the current sequence number");
}
Connection->NextSequenceRcv ++; // TODO: Is this right? (empty packet counts as one byte)
Log_Log("TCP", "Empty Packet, inc and ACK the current sequence number");
// - Only send an ACK if we've had a burst
if( Connection->NextSequenceRcv > (Uint32)(TCP_DACK_THRESHOLD + Connection->LastACKSequence) )
{
// - Only send an ACK if we've had a burst
if( Connection->NextSequenceRcv > (Uint32)(TCP_DACK_THRESHOLD + Connection->LastACKSequence) )
{
// - Extend TCP deferred ACK timer
Time_RemoveTimer(Connection->DeferredACKTimer);
}
// - Schedule the deferred ACK timer (if already scheduled, this is a NOP)
Time_ScheduleTimer(Connection->DeferredACKTimer, TCP_DACK_TIMEOUT);
#else
// - Extend TCP deferred ACK timer
Time_RemoveTimer(Connection->DeferredACKTimer);
}
// - Schedule the deferred ACK timer (if already scheduled, this is a NOP)
Time_ScheduleTimer(Connection->DeferredACKTimer, TCP_DACK_TIMEOUT);
#else
Log_Log("TCP", "Fully out of sequence packet (0x%08x not between 0x%08x and 0x%08x), dropped",
sequence_num, Connection->NextSequenceRcv, Connection->NextSequenceRcv+TCP_WINDOW_SIZE);
// Spec says we should send an empty ACK with the current state
Log_Log("TCP", "Fully out of sequence packet (0x%08x not between 0x%08x and 0x%08x), dropped",
sequence_num, Connection->NextSequenceRcv, Connection->NextSequenceRcv+TCP_WINDOW_SIZE);
// Spec says we should send an empty ACK with the current state
-void TCP_INT_SendACK(tTCPConnection *Connection)
+void TCP_int_SendDelayedACK(void *ConnPtr)
+{
+ TCP_INT_SendACK(ConnPtr, "DACK Timeout");
+}
+
+void TCP_INT_SendACK(tTCPConnection *Connection, const char *Reason)
hdr.Flags = TCP_FLAG_ACK; // TODO: Determine if SYN is wanted too
hdr.Checksum = 0; // TODO: Checksum
hdr.UrgentPointer = 0;
hdr.Flags = TCP_FLAG_ACK; // TODO: Determine if SYN is wanted too
hdr.Checksum = 0; // TODO: Checksum
hdr.UrgentPointer = 0;
- Log_Debug("TCP", "Sending ACK for 0x%08x", Connection->NextSequenceRcv);
+ Log_Debug("TCP", "Sending ACK for 0x%08x (%s)", Connection->NextSequenceRcv, Reason);
TCP_SendPacket( Connection, &hdr, 0, NULL );
//Connection->NextSequenceSend ++;
Connection->LastACKSequence = Connection->NextSequenceRcv;
TCP_SendPacket( Connection, &hdr, 0, NULL );
//Connection->NextSequenceSend ++;
Connection->LastACKSequence = Connection->NextSequenceRcv;