Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

Revision:
142:a8c0890a58d1
Parent:
131:774f7f367031
Child:
144:6bd5c54efc7d
diff -r 25047f31dbab -r a8c0890a58d1 tcp/tcprecv.c
--- a/tcp/tcprecv.c	Sat Apr 27 09:24:44 2019 +0000
+++ b/tcp/tcprecv.c	Wed May 08 12:15:13 2019 +0000
@@ -15,7 +15,7 @@
 #include   "https.h"
 #include     "led.h"
 #include "mstimer.h"
-#include   "fault.h"
+#include "restart.h"
 
 static void log(void (*traceback)(void), char* fmt, ...)
 {
@@ -112,8 +112,8 @@
 
 int TcpHandleReceivedPacket(void (*traceback)(void), int sizeRx, void* pPacketRx, int* pSizeTx, void* pPacketTx, int ipType, int remArIndex, int locIpScope)
 {
-    int lastFaultPoint = FaultPoint;
-    FaultPoint = FAULT_POINT_TcpHandleReceivedPacket;
+    int lastRestartPoint = RestartPoint;
+    RestartPoint = FAULT_POINT_TcpHandleReceivedPacket;
     
     int action = DO_NOTHING;
     bool traceRequested = false;
@@ -123,10 +123,10 @@
     if (remArIndex < 0)
     {
         log(traceback, "invalid remote AR index %d -> ignored packet", remArIndex);
-        FaultPoint = lastFaultPoint;
+        RestartPoint = lastRestartPoint;
         return DO_NOTHING;
     }
-    FaultPoint += 100;
+    RestartPoint += 100;
     
     int dataLength =   sizeRx - TcpHdrSizeGet();
     int locMss     = *pSizeTx - TcpHdrSizeGet();
@@ -138,7 +138,7 @@
     if (TcpHdrFIN) seqLengthRcvd += 1;          //Add one to acknowledge the FIN
     
     //Filter out unwanted links
-    FaultPoint++;
+    RestartPoint++;
     switch (TcpHdrDstPort)
     {
         case 80:
@@ -162,19 +162,19 @@
         default: //Send reset if unknown port
             log(traceback, "unhandled local port %hu -> sent reset", TcpHdrDstPort);
             action = sendResetFromPacket(pSizeTx, pPacketTx, ipType, remArIndex, locIpScope, seqLengthRcvd);
-            FaultPoint = lastFaultPoint;
+            RestartPoint = lastRestartPoint;
             return action;
     }
     
     //Get the Transmission Control Block
-    FaultPoint++;
+    RestartPoint++;
     struct tcb* pTcb = TcbGetExisting(ipType, remArIndex, locIpScope, TcpHdrSrcPort, TcpHdrDstPort);
     if (!pTcb) pTcb = TcbGetEmpty();
     if (!pTcb) //send reset if no more tcbs are available
     {
         log(traceback, "no more tcbs available -> sent reset");
         action = sendResetFromPacket(pSizeTx, pPacketTx, ipType, remArIndex, locIpScope, seqLengthRcvd);
-        FaultPoint = lastFaultPoint;
+        RestartPoint = lastRestartPoint;
         return action;
     }
     pTcb->timeLastRcvd     = MsTimerCount;
@@ -186,7 +186,7 @@
     pTcb->window           = TcpHdrWindow;
     
     //Handle request to reset
-    FaultPoint++;
+    RestartPoint++;
     if (TcpHdrRST)
     {
         if (pTcb->state)
@@ -194,12 +194,12 @@
             log(traceback, "received reset -> reaped TCB");
             pTcb->state = TCB_EMPTY;
         }
-        FaultPoint = lastFaultPoint;
+        RestartPoint = lastRestartPoint;
         return DO_NOTHING;        //Don't reply
     }
     
     //Handle request to synchronise
-    FaultPoint++;
+    RestartPoint++;
     if (TcpHdrSYN)
     {
         if (pTcb->state)
@@ -207,7 +207,7 @@
             log(traceback, "received a SYN on an open connection -> sent reset");
             pTcb->state = TCB_EMPTY;
             action = TcpSendReset(pSizeTx, pPacketTx, pTcb);
-            FaultPoint = lastFaultPoint;
+            RestartPoint = lastRestartPoint;
             return action;
         }
         else
@@ -217,19 +217,19 @@
     }
     
     //Handle non SYN packet on an empty connection
-    FaultPoint++;
+    RestartPoint++;
     if (!TcpHdrSYN && !pTcb->state)
     {
 
         log(traceback, "non SYN packet received on a closed connection -> sent reset");
         pTcb->state = TCB_EMPTY;
         action = sendResetFromPacket(pSizeTx, pPacketTx, ipType, remArIndex, locIpScope, seqLengthRcvd);
-        FaultPoint = lastFaultPoint;
+        RestartPoint = lastRestartPoint;
         return action;
     }
     
     //Check if the acks of bytes sent has progressed and reset the timer
-    FaultPoint++;
+    RestartPoint++;
     uint32_t ackRcvdFromRem = TcpHdrACK ? TcpHdrAckNum - pTcb->locIsn : 0;
     if (ackRcvdFromRem > pTcb->bytesAckdByRem)
     {
@@ -238,7 +238,7 @@
     }
 
     //Record the number of bytes acked by the remote host
-    FaultPoint++;
+    RestartPoint++;
     pTcb->bytesAckdByRem = ackRcvdFromRem;
 
     /* If the connection is in a synchronized state
@@ -247,7 +247,7 @@
     acknowledgment segment containing the current send-sequence number
     and an acknowledgment indicating the next sequence number expected
     to be received, and the connection remains in the same state.*/
-    FaultPoint++;
+    RestartPoint++;
     uint32_t seqRcvdFromRem = TcpHdrSeqNum - pTcb->remIsn;
     if (seqRcvdFromRem != pTcb->bytesAckdToRem)
     {
@@ -257,30 +257,30 @@
             log(traceback, "seq rcvd is %d and last seq ackd was %d -> resent last ACK", seqRcvdFromRem, pTcb->bytesAckdToRem);
         }
         action = TcpResendLastAck(pSizeTx, pPacketTx, pTcb);
-        FaultPoint = lastFaultPoint;
+        RestartPoint = lastRestartPoint;
         return action;
     }
     //Ignore data before established
-    FaultPoint++;
+    RestartPoint++;
     if (pTcb->state != TCB_ESTABLISHED && dataLength)
     {
         log(traceback, "data received before connection established -> sent reset");
         pTcb->state = TCB_EMPTY;
         action = TcpSendReset(pSizeTx, pPacketTx, pTcb);
-        FaultPoint = lastFaultPoint;
+        RestartPoint = lastRestartPoint;
         return action;
     }
     
     //Handle FIN
-    FaultPoint++;
+    RestartPoint++;
     if (TcpHdrFIN) pTcb->rcvdFin = true; //When reply is all sent only a passive close is needed
     
     //From now on there are no errors so display traceback if requested
-    FaultPoint++;
+    RestartPoint++;
     if (traceRequested && NetTraceStack) traceback();
     
     //Record the number of bytes received from the remote host
-    FaultPoint++;
+    RestartPoint++;
     pTcb->bytesRcvdFromRem += seqLengthRcvd;
 
     switch (pTcb->state) //This is the state of the connection BEFORE this packet arrived
@@ -310,9 +310,9 @@
             
     }
     
-    FaultPoint++;
+    RestartPoint++;
     action = TcpSend(pSizeTx, pPacketTx, pTcb);
 
-    FaultPoint = lastFaultPoint;
+    RestartPoint = lastRestartPoint;
     return action;
 }