Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: tcp/tcp.c
- Revision:
- 72:19457bba58d0
- Parent:
- 71:736a5747ade1
- Child:
- 73:43e3d7fb3d60
--- a/tcp/tcp.c Sat Oct 20 18:56:13 2018 +0000 +++ b/tcp/tcp.c Mon Oct 22 10:24:58 2018 +0000 @@ -78,9 +78,6 @@ urgent = NetToHost16(pHeader->urgent); } -static int positionInQuery; -static int positionInReply; - static uint16_t mss; static struct tcb* pTcb; @@ -101,8 +98,8 @@ Log("TCP header\r\n"); Log(" Source port "); LogF("%hu", srcPort ); Log("\r\n"); Log(" Destination port "); LogF("%hu", dstPort ); Log("\r\n"); - Log(" Seq number "); LogF("%u (%u)", positionInQuery, seqnum); Log("\r\n"); - Log(" Ack number "); LogF("%u (%u)", positionInReply, acknum); Log("\r\n"); + Log(" Seq number "); LogF("%u", seqnum ); Log("\r\n"); + Log(" Ack number "); LogF("%u", acknum ); Log("\r\n"); Log(" Header size "); LogF("%u", headersize ); Log("\r\n"); Log(" Flags " ); logFlags( ); Log("\r\n"); Log(" Window "); LogF("%hu", window ); Log("\r\n"); @@ -121,7 +118,7 @@ { LogF("TCP header %hu >>> %hu", srcPort, dstPort); logFlags(); - LogF(", query %u, reply %u", positionInQuery, positionInReply); + LogF(", query %u, reply %u", pTcb->recdBytes, pTcb->sentBytes); Log("\r\n"); } } @@ -235,11 +232,11 @@ pDataTx = pOptionsTx; //No options headersize = sizeof(struct header); - HttpHandleRequest(&dataLength, pDataRx, positionInQuery - 1, &pTcb->todo); + HttpHandleRequest(&dataLength, pDataRx, pTcb->recdBytes - 1, &pTcb->todo); } static void handleEstablishedConnectionOut() { - HttpSendReply(&dataLength, pDataTx, positionInReply - 1, mss, pTcb->todo); + HttpSendReply(&dataLength, pDataTx, pTcb->sentBytes - 1, mss, pTcb->todo); ACK = true; //Send ACK RST = false; @@ -340,32 +337,16 @@ if (SYN) { pTcb->recvIsn = seqnum; + pTcb->sendIsn = TcbGetIsn(); pTcb->recdBytes = 0; - pTcb->sendIsn = TcbGetIsn(); pTcb->sentBytes = 0; - acknum = pTcb->sendIsn; } - - //Calculate positions - positionInQuery = seqnum - pTcb->recvIsn; - positionInReply = acknum - pTcb->sendIsn; - - //Check packet sequences - if (positionInQuery != pTcb->recdBytes || positionInReply != pTcb->sentBytes) + else { - if (TcpTrace) - { - if (NetTraceNewLine) Log("\r\n"); - LogTime("TCP received packet"); - if (positionInQuery != pTcb->recdBytes) LogF(": starting at byte %u rather than %u so data reread" , positionInQuery, pTcb->recdBytes); - if (positionInReply != pTcb->sentBytes) LogF(": acknowledging byte %u rather than %u so data resent", positionInReply, pTcb->sentBytes); - Log("\r\n"); - - doTrace = true; - } - pTcb->recdBytes = positionInQuery; - pTcb->sentBytes = positionInReply; + pTcb->recdBytes = seqnum - pTcb->recvIsn; + pTcb->sentBytes = acknum - pTcb->sendIsn; } + if (doTrace && NetTraceStack) traceback(); //This will already include the TCP header if (SYN) pTcb->recdBytes += 1; //Add one to acknowledge the SYN @@ -404,17 +385,14 @@ return DO_NOTHING; } - positionInReply = pTcb->recdBytes; //Set up the acknowledgement field ready to send - positionInQuery = pTcb->sentBytes; //Record the start of the query before adding the bytes sent + //Specify the start of the data being sent and acknowledge the data received + acknum = pTcb->recdBytes + pTcb->recvIsn; //Set up the acknowledgement field ready to send + seqnum = pTcb->sentBytes + pTcb->sendIsn; //Set up the start of the message before adding the bytes sent //Keep a record of where we expect the next packet send to start if (SYN) pTcb->sentBytes += 1; //Add one to acknowledge the SYN pTcb->sentBytes += dataLength; //Record the next sequence number if (FIN) pTcb->sentBytes += 1; //Add one to acknowledge the FIN - - //Specify the start of the data being sent and acknowledge the data received - seqnum = positionInQuery + pTcb->sendIsn; - acknum = positionInReply + pTcb->recvIsn; //Swap the ports for the reply srcPort = dstPort;