Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

Revision:
184:ad80a63e3002
Parent:
170:96c637dc3f52
--- a/udp/tftp/tftp.c	Tue Jan 12 19:10:22 2021 +0000
+++ b/udp/tftp/tftp.c	Thu Jan 14 13:41:02 2021 +0000
@@ -4,6 +4,8 @@
 #include     "log.h"
 #include     "net.h"
 #include  "action.h"
+#include     "eth.h"
+#include    "dhcp.h"
 #include     "udp.h"
 #include     "dns.h"
 #include    "tftp.h"
@@ -65,7 +67,7 @@
 bool       TftpSendRequestsViaIp4 = false;
 uint32_t   TftpServerIp4;
 char       TftpServerIp6[16];
-int        TftpWriteStatus = TFTP_WRITE_STATUS_NONE;
+int        TftpWriteStatus = TFTP_WRITE_STATUS_UNAVAILABLE;
 char       TftpServerName[DNS_MAX_LABEL_LENGTH+1];
 char       TftpFileName  [DNS_MAX_LABEL_LENGTH+1];
 
@@ -200,7 +202,7 @@
 {
     static uint32_t writeStartMs = 0;
     
-    if (TftpWriteStatus == TFTP_WRITE_STATUS_NONE) writeStartMs = MsTimerCount;
+    if (TftpWriteStatus == TFTP_WRITE_STATUS_NONE || TftpWriteStatus == TFTP_WRITE_STATUS_UNAVAILABLE) writeStartMs = MsTimerCount;
     
     if (MsTimerRelative(writeStartMs, WRITE_TIMEOUT_MS))
     {
@@ -227,6 +229,17 @@
 }
 int TftpPollForPacketToSend(int type, void* pPacket, int* pSize)
 {
+    if (type == ETH_IPV4)
+    {
+        if (!DhcpLocalIp)
+        {
+            TftpWriteStatus = TFTP_WRITE_STATUS_UNAVAILABLE;
+        }
+        else
+        {
+            if (TftpWriteStatus == TFTP_WRITE_STATUS_UNAVAILABLE) TftpWriteStatus = TFTP_WRITE_STATUS_NONE;
+        }
+    }
     if (isTimedOut()                                                 ) { TftpWriteStatus = TFTP_WRITE_STATUS_NONE; return DO_NOTHING; }
     if (TftpWriteStatus != TFTP_WRITE_STATUS_REQUEST                 ) {                                           return DO_NOTHING; }
     if (!isOkToGo()                                                  ) { TftpWriteStatus = TFTP_WRITE_STATUS_NONE; return DO_NOTHING; }