From fbe4b5cbdea438ccec0d93de443f367f3ba46196 Mon Sep 17 00:00:00 2001 From: wdenk Date: Mon, 6 Oct 2003 21:55:32 +0000 Subject: * Update TRAB auto update code * Make fatload set filesize environment variable fix potential buffer overlow problem * enable basic / medium / high-end configurations for PPChameleonEVB board; fix NAND code * enable TFTP client code to specify to the server the desired timeout value (see RFC-2349) --- net/tftp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'net/tftp.c') diff --git a/net/tftp.c b/net/tftp.c index 1154cb9120..049df6830a 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -15,7 +15,7 @@ #if (CONFIG_COMMANDS & CFG_CMD_NET) #define WELL_KNOWN_PORT 69 /* Well known TFTP port # */ -#define TIMEOUT 2 /* Seconds to timeout for a lost pkt */ +#define TIMEOUT 5 /* Seconds to timeout for a lost pkt */ #ifndef CONFIG_NET_RETRY_COUNT # define TIMEOUT_COUNT 10 /* # of timeouts before giving up */ #else @@ -32,6 +32,7 @@ #define TFTP_DATA 3 #define TFTP_ACK 4 #define TFTP_ERROR 5 +#define TFTP_OACK 6 static int TftpServerPort; /* The UDP port at their end */ @@ -44,6 +45,7 @@ static int TftpState; #define STATE_DATA 2 #define STATE_TOO_LARGE 3 #define STATE_BAD_MAGIC 4 +#define STATE_OACK 5 #define DEFAULT_NAME_LEN (8 + 4 + 1) static char default_filename[DEFAULT_NAME_LEN]; @@ -113,10 +115,18 @@ TftpSend (void) pkt += strlen(tftp_filename) + 1; strcpy ((char *)pkt, "octet"); pkt += 5 /*strlen("octet")*/ + 1; + strcpy ((char *)pkt, "timeout"); + pkt += 7 /*strlen("timeout")*/ + 1; + sprintf((char *)pkt, "%d", TIMEOUT); +#ifdef ET_DEBUG + printf("send option \"timeout %s\"\n", (char *)pkt); +#endif + pkt += strlen((char *)pkt) + 1; len = pkt - xp; break; case STATE_DATA: + case STATE_OACK: xp = pkt; *((ushort *)pkt)++ = htons(TFTP_ACK); *((ushort *)pkt)++ = htons(TftpBlock); @@ -173,6 +183,14 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len) default: break; + case TFTP_OACK: +#ifdef ET_DEBUG + printf("Got OACK: %s %s\n", pkt, pkt+strlen(pkt)+1); +#endif + TftpState = STATE_OACK; + TftpServerPort = src; + TftpSend (); /* Send ACK */ + break; case TFTP_DATA: if (len < 2) return; @@ -184,7 +202,13 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len) puts ("\n\t "); } +#ifdef ET_DEBUG if (TftpState == STATE_RRQ) { + printf("Server did not acknowledge timeout option!\n"); + } +#endif + + if (TftpState == STATE_RRQ || TftpState == STATE_OACK) { TftpState = STATE_DATA; TftpServerPort = src; TftpLastBlock = 0; @@ -305,6 +329,7 @@ TftpStart (void) TftpTimeoutCount = 0; TftpState = STATE_RRQ; TftpOurPort = 1024 + (get_timer(0) % 3072); + TftpBlock = 0; /* zero out server ether in case the server ip has changed */ memset(NetServerEther, 0, 6); -- cgit v1.2.3