-static IPaddr_t TftpServerIP;
-static int TftpServerPort; /* The UDP port at their end */
-static int TftpOurPort; /* The UDP port at our end */
-static int TftpTimeoutCount;
-static ulong TftpBlock; /* packet sequence number */
-static ulong TftpLastBlock; /* last packet sequence number received */
-static ulong TftpBlockWrap; /* count of sequence number wraparounds */
-static ulong TftpBlockWrapOffset; /* memory offset due to wrapping */
-static int TftpState;
-
-#define STATE_RRQ 1
+static ulong timeout_ms = TIMEOUT;
+static int timeout_count_max = TIMEOUT_COUNT;
+static ulong time_start; /* Record time we started tftp */
+
+/*
+ * These globals govern the timeout behavior when attempting a connection to a
+ * TFTP server. tftp_timeout_ms specifies the number of milliseconds to
+ * wait for the server to respond to initial connection. Second global,
+ * tftp_timeout_count_max, gives the number of such connection retries.
+ * tftp_timeout_count_max must be non-negative and tftp_timeout_ms must be
+ * positive. The globals are meant to be set (and restored) by code needing
+ * non-standard timeout behavior when initiating a TFTP transfer.
+ */
+ulong tftp_timeout_ms = TIMEOUT;
+int tftp_timeout_count_max = TIMEOUT_COUNT;
+
+enum {
+ TFTP_ERR_UNDEFINED = 0,
+ TFTP_ERR_FILE_NOT_FOUND = 1,
+ TFTP_ERR_ACCESS_DENIED = 2,
+ TFTP_ERR_DISK_FULL = 3,
+ TFTP_ERR_UNEXPECTED_OPCODE = 4,
+ TFTP_ERR_UNKNOWN_TRANSFER_ID = 5,
+ TFTP_ERR_FILE_ALREADY_EXISTS = 6,
+};
+
+static struct in_addr tftp_remote_ip;
+/* The UDP port at their end */
+static int tftp_remote_port;
+/* The UDP port at our end */
+static int tftp_our_port;
+static int timeout_count;
+/* packet sequence number */
+static ulong tftp_cur_block;
+/* last packet sequence number received */
+static ulong tftp_prev_block;
+/* count of sequence number wraparounds */
+static ulong tftp_block_wrap;
+/* memory offset due to wrapping */
+static ulong tftp_block_wrap_offset;
+static int tftp_state;
+#ifdef CONFIG_TFTP_TSIZE
+/* The file size reported by the server */
+static int tftp_tsize;
+/* The number of hashes we printed */
+static short tftp_tsize_num_hash;
+#endif
+#ifdef CONFIG_CMD_TFTPPUT
+/* 1 if writing, else 0 */
+static int tftp_put_active;
+/* 1 if we have sent the last block */
+static int tftp_put_final_block_sent;
+#else
+#define tftp_put_active 0
+#endif
+
+#define STATE_SEND_RRQ 1