A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
tcp/tcp.txt@72:19457bba58d0, 2018-10-22 (annotated)
- Committer:
- andrewboyson
- Date:
- Mon Oct 22 10:24:58 2018 +0000
- Revision:
- 72:19457bba58d0
- Parent:
- 71:736a5747ade1
- Child:
- 75:603b10404183
Removed positioninquery and positioninreply variables. Working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 71:736a5747ade1 | 1 | Names |
andrewboyson | 71:736a5747ade1 | 2 | ===== |
andrewboyson | 71:736a5747ade1 | 3 | ISN == Initial Sequence Number |
andrewboyson | 71:736a5747ade1 | 4 | SEQ num == Sequence Number is the sequence of the first byte of the sent data packet - unless a SYN in which case it is the ISN |
andrewboyson | 71:736a5747ade1 | 5 | ACK num == Acknowledge Number is the next sequence number that the sender of the ACK is expecting |
andrewboyson | 71:736a5747ade1 | 6 | TCB == Transmission Control Block |
andrewboyson | 71:736a5747ade1 | 7 | RTO == Retransmission Time Out |
andrewboyson | 71:736a5747ade1 | 8 | |
andrewboyson | 71:736a5747ade1 | 9 | Protocol |
andrewboyson | 71:736a5747ade1 | 10 | ======== |
andrewboyson | 71:736a5747ade1 | 11 | Goes: |
andrewboyson | 71:736a5747ade1 | 12 | 0 SYN |
andrewboyson | 71:736a5747ade1 | 13 | 1 Data (length == MSS) |
andrewboyson | 71:736a5747ade1 | 14 | 1+ MSS Data (length == MSS) |
andrewboyson | 71:736a5747ade1 | 15 | 1+2xMSS Data (length < MSS) + FIN |
andrewboyson | 71:736a5747ade1 | 16 | |
andrewboyson | 71:736a5747ade1 | 17 | TcpHandleReceivedPacket |
andrewboyson | 71:736a5747ade1 | 18 | ======================= |
andrewboyson | 71:736a5747ade1 | 19 | Called from the network stack |
andrewboyson | 71:736a5747ade1 | 20 | Reads the header to get: the src and dst ports; the ACK and SEQ numbers; SYN, ACK, PSH, RST and FIN flags |
andrewboyson | 71:736a5747ade1 | 21 | Only handles dst port 80 (HTTP) |
andrewboyson | 71:736a5747ade1 | 22 | Retrieves the TCB for the src port |
andrewboyson | 71:736a5747ade1 | 23 | Handles RST or SYN requests |
andrewboyson | 71:736a5747ade1 | 24 | Subtract the initial sequence numbers to get the position in the query from the SEQ num and the position in the reply from the ACK num. |
andrewboyson | 71:736a5747ade1 | 25 | If the position in the query is not the same as the TCB recd bytes then adjust the TCB recd bytes |
andrewboyson | 71:736a5747ade1 | 26 | If the position in the reply is not the same as the TCB sent bytes then adjust the TCB sent bytes |
andrewboyson | 71:736a5747ade1 | 27 | Increment the TCB recd bytes by the received datalength and by 1 for a SYN or FIN |
andrewboyson | 71:736a5747ade1 | 28 | Handle the packet according to the TCB state, for established connections pass the position in the query and the position in the reply |
andrewboyson | 71:736a5747ade1 | 29 | Set the ACK number to the TCB recd bytes plus the ISN |
andrewboyson | 71:736a5747ade1 | 30 | Set the SEQ number to the TCB sent bytes plus the ISN |
andrewboyson | 71:736a5747ade1 | 31 | Increment the TCB sent bytes by the sent datalength and by 1 for a SYN or FIN |
andrewboyson | 71:736a5747ade1 | 32 | Swap the ports |
andrewboyson | 71:736a5747ade1 | 33 | Return to the network stack for unicast transmission |
andrewboyson | 71:736a5747ade1 | 34 | |
andrewboyson | 71:736a5747ade1 | 35 | Todo |
andrewboyson | 71:736a5747ade1 | 36 | ==== |
andrewboyson | 71:736a5747ade1 | 37 | Separate the work into TcpHandleReceivedPacket and TcpPollForPacketToSend: this would allow RTO to be implemented. |
andrewboyson | 71:736a5747ade1 | 38 | Need to add the IP to the TCB |
andrewboyson | 71:736a5747ade1 | 39 | Change TCB_ACK_WAIT and TCB_FIN_WAIT to TCB_CLOSE_ACK_WAIT and TCB_CLOSE_FIN_WAIT |
andrewboyson | 71:736a5747ade1 | 40 | Add state TCB_SEND_ACK_WAIT |
andrewboyson | 71:736a5747ade1 | 41 | Add ackdBytes to TCB so that can tell if sentBytes has been acked or not; if so then send the next; if not and within timeout then wait; if not and RTO then send again |
andrewboyson | 71:736a5747ade1 | 42 | |
andrewboyson | 71:736a5747ade1 | 43 | State |
andrewboyson | 71:736a5747ade1 | 44 | ===== |
andrewboyson | 72:19457bba58d0 | 45 | State Received Do New state |
andrewboyson | 72:19457bba58d0 | 46 | TCB_EMPTY SYN record ISN TCB_SYN_RECEIVED |
andrewboyson | 72:19457bba58d0 | 47 | TCB_SYN_RECEIVED ACK TCB_ESTABLISHED |
andrewboyson | 72:19457bba58d0 | 48 | TCB_ESTABLISHED |
andrewboyson | 72:19457bba58d0 | 49 | TCB_ACK_WAIT |
andrewboyson | 72:19457bba58d0 | 50 | TCB_FIN_WAIT |
andrewboyson | 72:19457bba58d0 | 51 | |
andrewboyson | 72:19457bba58d0 | 52 | State |
andrewboyson | 71:736a5747ade1 | 53 | TCB_EMPTY do nothing |
andrewboyson | 71:736a5747ade1 | 54 | TCB_SYN_RECEIVED if (TCB.sent == 0) or (TCB.sent == 1 and TCB.ackd == 0 and RTO) then send SYN ACK and ISN. |
andrewboyson | 71:736a5747ade1 | 55 | TCB_ESTABLISHED if (!TCB.finished) then send from TCB.sent. if RTO and TCB.ackd < TCB.sent then resend TCB.ackd |
andrewboyson | 72:19457bba58d0 | 56 | TCB_ACK_WAIT |
andrewboyson | 71:736a5747ade1 | 57 | TCB_FIN_WAIT |