blob: f8942aed280c684f291516a54a5bdb63eee6a19e [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
Luca Ceresoli2f094132011-05-14 05:49:56 +00002 * Copyright 1994, 1995, 2000 Neil Russell.
3 * (See License)
4 * Copyright 2000, 2001 DENX Software Engineering, Wolfgang Denk, wd@denx.de
Luca Ceresolie59e3562011-05-17 00:03:39 +00005 * Copyright 2011 Comelit Group SpA,
6 * Luca Ceresoli <luca.ceresoli@comelit.it>
wdenkfe8c2802002-11-03 00:38:21 +00007 */
8
9#include <common.h>
10#include <command.h>
Joe Hershberger55d5fd92015-03-22 17:09:08 -050011#include <mapmem.h>
wdenkfe8c2802002-11-03 00:38:21 +000012#include <net.h>
Lukasz Majewski34696952015-08-24 00:21:43 +020013#include <net/tftp.h>
wdenkfe8c2802002-11-03 00:38:21 +000014#include "bootp.h"
Joe Hershberger13dfe942012-05-15 08:59:12 +000015#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
16#include <flash.h>
17#endif
wdenkfe8c2802002-11-03 00:38:21 +000018
Luca Ceresoli2f094132011-05-14 05:49:56 +000019/* Well known TFTP port # */
20#define WELL_KNOWN_PORT 69
21/* Millisecs to timeout for lost pkt */
Bin Mengaf2ca592015-08-27 22:25:51 -070022#define TIMEOUT 5000UL
wdenkfe8c2802002-11-03 00:38:21 +000023#ifndef CONFIG_NET_RETRY_COUNT
Luca Ceresoli2f094132011-05-14 05:49:56 +000024/* # of timeouts before giving up */
Bin Mengaf2ca592015-08-27 22:25:51 -070025# define TIMEOUT_COUNT 10
wdenkfe8c2802002-11-03 00:38:21 +000026#else
27# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT * 2)
28#endif
Luca Ceresoli2f094132011-05-14 05:49:56 +000029/* Number of "loading" hashes per line (for checking the image size) */
30#define HASHES_PER_LINE 65
wdenkfe8c2802002-11-03 00:38:21 +000031
32/*
33 * TFTP operations.
34 */
35#define TFTP_RRQ 1
36#define TFTP_WRQ 2
37#define TFTP_DATA 3
38#define TFTP_ACK 4
39#define TFTP_ERROR 5
wdenkfbe4b5c2003-10-06 21:55:32 +000040#define TFTP_OACK 6
wdenkfe8c2802002-11-03 00:38:21 +000041
Sanjeev N9908fc32017-09-05 15:18:54 +053042DECLARE_GLOBAL_DATA_PTR;
Joe Hershberger8885c5f2015-04-08 01:41:07 -050043static ulong timeout_ms = TIMEOUT;
44static int timeout_count_max = TIMEOUT_COUNT;
Simon Glass85b19802012-10-11 13:57:36 +000045static ulong time_start; /* Record time we started tftp */
Bartlomiej Siekae83cc062008-10-01 15:26:29 +020046
47/*
48 * These globals govern the timeout behavior when attempting a connection to a
Joe Hershberger8885c5f2015-04-08 01:41:07 -050049 * TFTP server. tftp_timeout_ms specifies the number of milliseconds to
Bartlomiej Siekae83cc062008-10-01 15:26:29 +020050 * wait for the server to respond to initial connection. Second global,
Joe Hershberger8885c5f2015-04-08 01:41:07 -050051 * tftp_timeout_count_max, gives the number of such connection retries.
52 * tftp_timeout_count_max must be non-negative and tftp_timeout_ms must be
Bartlomiej Siekae83cc062008-10-01 15:26:29 +020053 * positive. The globals are meant to be set (and restored) by code needing
54 * non-standard timeout behavior when initiating a TFTP transfer.
55 */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050056ulong tftp_timeout_ms = TIMEOUT;
57int tftp_timeout_count_max = TIMEOUT_COUNT;
Bartlomiej Siekae83cc062008-10-01 15:26:29 +020058
Remy Bohmeraafda382009-10-28 22:13:40 +010059enum {
60 TFTP_ERR_UNDEFINED = 0,
61 TFTP_ERR_FILE_NOT_FOUND = 1,
62 TFTP_ERR_ACCESS_DENIED = 2,
63 TFTP_ERR_DISK_FULL = 3,
64 TFTP_ERR_UNEXPECTED_OPCODE = 4,
65 TFTP_ERR_UNKNOWN_TRANSFER_ID = 5,
66 TFTP_ERR_FILE_ALREADY_EXISTS = 6,
67};
68
Joe Hershberger049a95a2015-04-08 01:41:01 -050069static struct in_addr tftp_remote_ip;
Luca Ceresoli2f094132011-05-14 05:49:56 +000070/* The UDP port at their end */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050071static int tftp_remote_port;
Luca Ceresoli2f094132011-05-14 05:49:56 +000072/* The UDP port at our end */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050073static int tftp_our_port;
74static int timeout_count;
Luca Ceresoli2f094132011-05-14 05:49:56 +000075/* packet sequence number */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050076static ulong tftp_cur_block;
Luca Ceresoli2f094132011-05-14 05:49:56 +000077/* last packet sequence number received */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050078static ulong tftp_prev_block;
Luca Ceresoli2f094132011-05-14 05:49:56 +000079/* count of sequence number wraparounds */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050080static ulong tftp_block_wrap;
Luca Ceresoli2f094132011-05-14 05:49:56 +000081/* memory offset due to wrapping */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050082static ulong tftp_block_wrap_offset;
83static int tftp_state;
Robin Getz4fccb812009-08-20 10:50:20 -040084#ifdef CONFIG_TFTP_TSIZE
Luca Ceresoli2f094132011-05-14 05:49:56 +000085/* The file size reported by the server */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050086static int tftp_tsize;
Luca Ceresoli2f094132011-05-14 05:49:56 +000087/* The number of hashes we printed */
Joe Hershberger8885c5f2015-04-08 01:41:07 -050088static short tftp_tsize_num_hash;
Robin Getz4fccb812009-08-20 10:50:20 -040089#endif
Simon Glass1fb7cd42011-10-24 18:00:07 +000090#ifdef CONFIG_CMD_TFTPPUT
Joe Hershberger8885c5f2015-04-08 01:41:07 -050091/* 1 if writing, else 0 */
92static int tftp_put_active;
93/* 1 if we have sent the last block */
94static int tftp_put_final_block_sent;
Simon Glass1fb7cd42011-10-24 18:00:07 +000095#else
Joe Hershberger8885c5f2015-04-08 01:41:07 -050096#define tftp_put_active 0
Simon Glass1fb7cd42011-10-24 18:00:07 +000097#endif
wdenk3f85ce22004-02-23 16:11:30 +000098
Luca Ceresolie3fb0ab2011-05-17 00:03:38 +000099#define STATE_SEND_RRQ 1
wdenkfe8c2802002-11-03 00:38:21 +0000100#define STATE_DATA 2
101#define STATE_TOO_LARGE 3
102#define STATE_BAD_MAGIC 4
wdenkfbe4b5c2003-10-06 21:55:32 +0000103#define STATE_OACK 5
Luca Ceresolie59e3562011-05-17 00:03:39 +0000104#define STATE_RECV_WRQ 6
Simon Glass1fb7cd42011-10-24 18:00:07 +0000105#define STATE_SEND_WRQ 7
wdenkfe8c2802002-11-03 00:38:21 +0000106
Luca Ceresoli2f094132011-05-14 05:49:56 +0000107/* default TFTP block size */
108#define TFTP_BLOCK_SIZE 512
109/* sequence number is 16 bit */
110#define TFTP_SEQUENCE_SIZE ((ulong)(1<<16))
wdenk3f85ce22004-02-23 16:11:30 +0000111
wdenkfe8c2802002-11-03 00:38:21 +0000112#define DEFAULT_NAME_LEN (8 + 4 + 1)
113static char default_filename[DEFAULT_NAME_LEN];
Jean-Christophe PLAGNIOL-VILLARDa93907c2008-01-18 01:14:03 +0100114
115#ifndef CONFIG_TFTP_FILE_NAME_MAX_LEN
116#define MAX_LEN 128
117#else
118#define MAX_LEN CONFIG_TFTP_FILE_NAME_MAX_LEN
119#endif
120
121static char tftp_filename[MAX_LEN];
wdenkfe8c2802002-11-03 00:38:21 +0000122
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200123/* 512 is poor choice for ethernet, MTU is typically 1500.
124 * Minus eth.hdrs thats 1468. Can get 2x better throughput with
David Updegraff53a5c422007-06-11 10:41:07 -0500125 * almost-MTU block sizes. At least try... fall back to 512 if need be.
Alessandro Rubini89ba81d2009-08-07 13:59:06 +0200126 * (but those using CONFIG_IP_DEFRAG may want to set a larger block in cfg file)
David Updegraff53a5c422007-06-11 10:41:07 -0500127 */
Alessandro Rubini89ba81d2009-08-07 13:59:06 +0200128#ifdef CONFIG_TFTP_BLOCKSIZE
129#define TFTP_MTU_BLOCKSIZE CONFIG_TFTP_BLOCKSIZE
130#else
David Updegraff53a5c422007-06-11 10:41:07 -0500131#define TFTP_MTU_BLOCKSIZE 1468
Alessandro Rubini89ba81d2009-08-07 13:59:06 +0200132#endif
133
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500134static unsigned short tftp_block_size = TFTP_BLOCK_SIZE;
135static unsigned short tftp_block_size_option = TFTP_MTU_BLOCKSIZE;
David Updegraff53a5c422007-06-11 10:41:07 -0500136
137#ifdef CONFIG_MCAST_TFTP
138#include <malloc.h>
139#define MTFTP_BITMAPSIZE 0x1000
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500140static unsigned *tftp_mcast_bitmap;
141static int tftp_mcast_prev_hole;
142static int tftp_mcast_bitmap_size = MTFTP_BITMAPSIZE;
143static int tftp_mcast_disabled;
144static int tftp_mcast_master_client;
145static int tftp_mcast_active;
146static int tftp_mcast_port;
147/* can get 'last' block before done..*/
148static ulong tftp_mcast_ending_block;
David Updegraff53a5c422007-06-11 10:41:07 -0500149
Luca Ceresolic718b142011-05-14 05:49:57 +0000150static void parse_multicast_oack(char *pkt, int len);
David Updegraff53a5c422007-06-11 10:41:07 -0500151
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500152static void mcast_cleanup(void)
David Updegraff53a5c422007-06-11 10:41:07 -0500153{
Joe Hershberger049a95a2015-04-08 01:41:01 -0500154 if (net_mcast_addr)
155 eth_mcast_join(net_mcast_addr, 0);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500156 if (tftp_mcast_bitmap)
157 free(tftp_mcast_bitmap);
158 tftp_mcast_bitmap = NULL;
Joe Hershberger049a95a2015-04-08 01:41:01 -0500159 net_mcast_addr.s_addr = 0;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500160 tftp_mcast_active = 0;
161 tftp_mcast_port = 0;
162 tftp_mcast_ending_block = -1;
David Updegraff53a5c422007-06-11 10:41:07 -0500163}
164
165#endif /* CONFIG_MCAST_TFTP */
166
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500167static inline void store_block(int block, uchar *src, unsigned len)
wdenkfe8c2802002-11-03 00:38:21 +0000168{
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500169 ulong offset = block * tftp_block_size + tftp_block_wrap_offset;
wdenk3f85ce22004-02-23 16:11:30 +0000170 ulong newsize = offset + len;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200171#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
wdenkfe8c2802002-11-03 00:38:21 +0000172 int i, rc = 0;
173
Luca Ceresolic718b142011-05-14 05:49:57 +0000174 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
wdenkfe8c2802002-11-03 00:38:21 +0000175 /* start address in flash? */
Jochen Friedrichbe1b0d22008-09-02 11:24:59 +0200176 if (flash_info[i].flash_id == FLASH_UNKNOWN)
177 continue;
wdenkfe8c2802002-11-03 00:38:21 +0000178 if (load_addr + offset >= flash_info[i].start[0]) {
179 rc = 1;
180 break;
181 }
182 }
183
184 if (rc) { /* Flash is destination for this packet */
Luca Ceresolic718b142011-05-14 05:49:57 +0000185 rc = flash_write((char *)src, (ulong)(load_addr+offset), len);
wdenkfe8c2802002-11-03 00:38:21 +0000186 if (rc) {
Luca Ceresolic718b142011-05-14 05:49:57 +0000187 flash_perror(rc);
Joe Hershberger22f6e992012-05-23 07:59:14 +0000188 net_set_state(NETLOOP_FAIL);
wdenkfe8c2802002-11-03 00:38:21 +0000189 return;
190 }
Joe Hershberger13dfe942012-05-15 08:59:12 +0000191 } else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200192#endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */
wdenkfe8c2802002-11-03 00:38:21 +0000193 {
Sanjeev N9908fc32017-09-05 15:18:54 +0530194 /*
195 * The file to be tftp'ed should not overwrite the
196 * code/stack area.
197 */
Kathiravan T3527e1e2017-12-15 14:31:40 +0530198#ifdef CONFIG_IPQ806X
199 if ((load_addr + newsize) >= IPQ_TFTP_MAX_ADDR) {
200#else
Sanjeev N9908fc32017-09-05 15:18:54 +0530201 if (((load_addr + newsize) >= CONFIG_SYS_SDRAM_END) ||
202 (((load_addr + newsize) >= CONFIG_IPQ_FDT_HIGH) &&
203 ((load_addr + newsize) < CONFIG_TZ_END_ADDR))) {
Kathiravan T3527e1e2017-12-15 14:31:40 +0530204#endif /* CONFIG_IPQ806X */
Sanjeev N9908fc32017-09-05 15:18:54 +0530205 puts("\nError file size too large\n");
206 net_set_state(NETLOOP_FAIL);
207 return;
208 }
Joe Hershberger55d5fd92015-03-22 17:09:08 -0500209 void *ptr = map_sysmem(load_addr + offset, len);
210
211 memcpy(ptr, src, len);
212 unmap_sysmem(ptr);
wdenkfe8c2802002-11-03 00:38:21 +0000213 }
David Updegraff53a5c422007-06-11 10:41:07 -0500214#ifdef CONFIG_MCAST_TFTP
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500215 if (tftp_mcast_active)
216 ext2_set_bit(block, tftp_mcast_bitmap);
David Updegraff53a5c422007-06-11 10:41:07 -0500217#endif
wdenkfe8c2802002-11-03 00:38:21 +0000218
Joe Hershberger14111572015-04-08 01:41:02 -0500219 if (net_boot_file_size < newsize)
220 net_boot_file_size = newsize;
wdenkfe8c2802002-11-03 00:38:21 +0000221}
222
Simon Glasse4cde2f2011-10-24 18:00:04 +0000223/* Clear our state ready for a new transfer */
Simon Glass165099e2011-10-27 06:24:28 +0000224static void new_transfer(void)
Simon Glasse4cde2f2011-10-24 18:00:04 +0000225{
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500226 tftp_prev_block = 0;
227 tftp_block_wrap = 0;
228 tftp_block_wrap_offset = 0;
Simon Glasse4cde2f2011-10-24 18:00:04 +0000229#ifdef CONFIG_CMD_TFTPPUT
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500230 tftp_put_final_block_sent = 0;
Simon Glasse4cde2f2011-10-24 18:00:04 +0000231#endif
232}
233
Simon Glass1fb7cd42011-10-24 18:00:07 +0000234#ifdef CONFIG_CMD_TFTPPUT
235/**
236 * Load the next block from memory to be sent over tftp.
237 *
238 * @param block Block number to send
239 * @param dst Destination buffer for data
240 * @param len Number of bytes in block (this one and every other)
241 * @return number of bytes loaded
242 */
243static int load_block(unsigned block, uchar *dst, unsigned len)
244{
245 /* We may want to get the final block from the previous set */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500246 ulong offset = ((int)block - 1) * len + tftp_block_wrap_offset;
Simon Glass1fb7cd42011-10-24 18:00:07 +0000247 ulong tosend = len;
248
Joe Hershberger14111572015-04-08 01:41:02 -0500249 tosend = min(net_boot_file_size - offset, tosend);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000250 (void)memcpy(dst, (void *)(save_addr + offset), tosend);
251 debug("%s: block=%d, offset=%ld, len=%d, tosend=%ld\n", __func__,
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500252 block, offset, len, tosend);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000253 return tosend;
254}
255#endif
256
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500257static void tftp_send(void);
258static void tftp_timeout_handler(void);
wdenkfe8c2802002-11-03 00:38:21 +0000259
260/**********************************************************************/
261
Simon Glassf5329bb2011-10-24 18:00:03 +0000262static void show_block_marker(void)
263{
264#ifdef CONFIG_TFTP_TSIZE
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500265 if (tftp_tsize) {
266 ulong pos = tftp_cur_block * tftp_block_size +
267 tftp_block_wrap_offset;
Max Krummenacher7628afe2015-08-05 17:17:05 +0200268 if (pos > tftp_tsize)
269 pos = tftp_tsize;
Simon Glassf5329bb2011-10-24 18:00:03 +0000270
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500271 while (tftp_tsize_num_hash < pos * 50 / tftp_tsize) {
Simon Glassf5329bb2011-10-24 18:00:03 +0000272 putc('#');
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500273 tftp_tsize_num_hash++;
Simon Glassf5329bb2011-10-24 18:00:03 +0000274 }
Simon Glass1fb7cd42011-10-24 18:00:07 +0000275 } else
Simon Glassf5329bb2011-10-24 18:00:03 +0000276#endif
Simon Glass1fb7cd42011-10-24 18:00:07 +0000277 {
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500278 if (((tftp_cur_block - 1) % 10) == 0)
Simon Glassf5329bb2011-10-24 18:00:03 +0000279 putc('#');
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500280 else if ((tftp_cur_block % (10 * HASHES_PER_LINE)) == 0)
Simon Glassf5329bb2011-10-24 18:00:03 +0000281 puts("\n\t ");
282 }
283}
284
Simon Glasse4cde2f2011-10-24 18:00:04 +0000285/**
286 * restart the current transfer due to an error
287 *
288 * @param msg Message to print for user
289 */
290static void restart(const char *msg)
291{
292 printf("\n%s; starting again\n", msg);
293#ifdef CONFIG_MCAST_TFTP
294 mcast_cleanup();
295#endif
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500296 net_start_again();
Simon Glasse4cde2f2011-10-24 18:00:04 +0000297}
298
299/*
300 * Check if the block number has wrapped, and update progress
301 *
302 * TODO: The egregious use of global variables in this file should be tidied.
303 */
304static void update_block_number(void)
305{
306 /*
307 * RFC1350 specifies that the first data packet will
308 * have sequence number 1. If we receive a sequence
309 * number of 0 this means that there was a wrap
310 * around of the (16 bit) counter.
311 */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500312 if (tftp_cur_block == 0 && tftp_prev_block != 0) {
313 tftp_block_wrap++;
314 tftp_block_wrap_offset += tftp_block_size * TFTP_SEQUENCE_SIZE;
315 timeout_count = 0; /* we've done well, reset the timeout */
Simon Glasse4cde2f2011-10-24 18:00:04 +0000316 } else {
317 show_block_marker();
318 }
319}
320
Simon Glassf5329bb2011-10-24 18:00:03 +0000321/* The TFTP get or put is complete */
322static void tftp_complete(void)
323{
324#ifdef CONFIG_TFTP_TSIZE
325 /* Print hash marks for the last packet received */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500326 while (tftp_tsize && tftp_tsize_num_hash < 49) {
Simon Glassf5329bb2011-10-24 18:00:03 +0000327 putc('#');
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500328 tftp_tsize_num_hash++;
Simon Glassf5329bb2011-10-24 18:00:03 +0000329 }
Simon Glass8104f542014-10-10 07:30:21 -0600330 puts(" ");
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500331 print_size(tftp_tsize, "");
Simon Glassf5329bb2011-10-24 18:00:03 +0000332#endif
Simon Glass85b19802012-10-11 13:57:36 +0000333 time_start = get_timer(time_start);
334 if (time_start > 0) {
335 puts("\n\t "); /* Line up with "Loading: " */
Joe Hershberger14111572015-04-08 01:41:02 -0500336 print_size(net_boot_file_size /
Simon Glass85b19802012-10-11 13:57:36 +0000337 time_start * 1000, "/s");
338 }
Simon Glassf5329bb2011-10-24 18:00:03 +0000339 puts("\ndone\n");
Joe Hershberger22f6e992012-05-23 07:59:14 +0000340 net_set_state(NETLOOP_SUCCESS);
Simon Glassf5329bb2011-10-24 18:00:03 +0000341}
342
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500343static void tftp_send(void)
wdenkfe8c2802002-11-03 00:38:21 +0000344{
Simon Glass1fb7cd42011-10-24 18:00:07 +0000345 uchar *pkt;
Joe Hershbergerdb288a92012-05-15 08:59:04 +0000346 uchar *xp;
347 int len = 0;
348 ushort *s;
wdenkfe8c2802002-11-03 00:38:21 +0000349
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200350#ifdef CONFIG_MCAST_TFTP
David Updegraff53a5c422007-06-11 10:41:07 -0500351 /* Multicast TFTP.. non-MasterClients do not ACK data. */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500352 if (tftp_mcast_active && tftp_state == STATE_DATA &&
353 tftp_mcast_master_client == 0)
David Updegraff53a5c422007-06-11 10:41:07 -0500354 return;
355#endif
wdenkfe8c2802002-11-03 00:38:21 +0000356 /*
357 * We will always be sending some sort of packet, so
358 * cobble together the packet headers now.
359 */
Joe Hershberger1203fcc2015-04-08 01:41:05 -0500360 pkt = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
wdenkfe8c2802002-11-03 00:38:21 +0000361
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500362 switch (tftp_state) {
Luca Ceresolie3fb0ab2011-05-17 00:03:38 +0000363 case STATE_SEND_RRQ:
Simon Glass1fb7cd42011-10-24 18:00:07 +0000364 case STATE_SEND_WRQ:
wdenkfe8c2802002-11-03 00:38:21 +0000365 xp = pkt;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200366 s = (ushort *)pkt;
Simon Glass8c6914f2011-10-27 06:24:29 +0000367#ifdef CONFIG_CMD_TFTPPUT
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500368 *s++ = htons(tftp_state == STATE_SEND_RRQ ? TFTP_RRQ :
Simon Glass1fb7cd42011-10-24 18:00:07 +0000369 TFTP_WRQ);
Simon Glass8c6914f2011-10-27 06:24:29 +0000370#else
371 *s++ = htons(TFTP_RRQ);
372#endif
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200373 pkt = (uchar *)s;
Luca Ceresolic718b142011-05-14 05:49:57 +0000374 strcpy((char *)pkt, tftp_filename);
wdenkfe8c2802002-11-03 00:38:21 +0000375 pkt += strlen(tftp_filename) + 1;
Luca Ceresolic718b142011-05-14 05:49:57 +0000376 strcpy((char *)pkt, "octet");
wdenkfe8c2802002-11-03 00:38:21 +0000377 pkt += 5 /*strlen("octet")*/ + 1;
Luca Ceresolic718b142011-05-14 05:49:57 +0000378 strcpy((char *)pkt, "timeout");
wdenkfbe4b5c2003-10-06 21:55:32 +0000379 pkt += 7 /*strlen("timeout")*/ + 1;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500380 sprintf((char *)pkt, "%lu", timeout_ms / 1000);
Robin Getz0ebf04c2009-07-23 03:01:03 -0400381 debug("send option \"timeout %s\"\n", (char *)pkt);
wdenkfbe4b5c2003-10-06 21:55:32 +0000382 pkt += strlen((char *)pkt) + 1;
Robin Getz4fccb812009-08-20 10:50:20 -0400383#ifdef CONFIG_TFTP_TSIZE
Joe Hershberger14111572015-04-08 01:41:02 -0500384 pkt += sprintf((char *)pkt, "tsize%c%u%c",
385 0, net_boot_file_size, 0);
Robin Getz4fccb812009-08-20 10:50:20 -0400386#endif
David Updegraff53a5c422007-06-11 10:41:07 -0500387 /* try for more effic. blk size */
Luca Ceresolic718b142011-05-14 05:49:57 +0000388 pkt += sprintf((char *)pkt, "blksize%c%d%c",
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500389 0, tftp_block_size_option, 0);
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200390#ifdef CONFIG_MCAST_TFTP
David Updegraff53a5c422007-06-11 10:41:07 -0500391 /* Check all preconditions before even trying the option */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500392 if (!tftp_mcast_disabled) {
393 tftp_mcast_bitmap = malloc(tftp_mcast_bitmap_size);
394 if (tftp_mcast_bitmap && eth_get_dev()->mcast) {
395 free(tftp_mcast_bitmap);
396 tftp_mcast_bitmap = NULL;
Joe Hershberger13dfe942012-05-15 08:59:12 +0000397 pkt += sprintf((char *)pkt, "multicast%c%c",
398 0, 0);
399 }
David Updegraff53a5c422007-06-11 10:41:07 -0500400 }
401#endif /* CONFIG_MCAST_TFTP */
wdenkfe8c2802002-11-03 00:38:21 +0000402 len = pkt - xp;
403 break;
404
wdenkfbe4b5c2003-10-06 21:55:32 +0000405 case STATE_OACK:
David Updegraff53a5c422007-06-11 10:41:07 -0500406#ifdef CONFIG_MCAST_TFTP
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500407 /* My turn! Start at where I need blocks I missed. */
408 if (tftp_mcast_active)
409 tftp_cur_block = ext2_find_next_zero_bit(
410 tftp_mcast_bitmap,
411 tftp_mcast_bitmap_size * 8, 0);
412 /* fall through */
David Updegraff53a5c422007-06-11 10:41:07 -0500413#endif
Luca Ceresolie59e3562011-05-17 00:03:39 +0000414
415 case STATE_RECV_WRQ:
David Updegraff53a5c422007-06-11 10:41:07 -0500416 case STATE_DATA:
wdenkfe8c2802002-11-03 00:38:21 +0000417 xp = pkt;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200418 s = (ushort *)pkt;
Simon Glass1fb7cd42011-10-24 18:00:07 +0000419 s[0] = htons(TFTP_ACK);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500420 s[1] = htons(tftp_cur_block);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000421 pkt = (uchar *)(s + 2);
422#ifdef CONFIG_CMD_TFTPPUT
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500423 if (tftp_put_active) {
424 int toload = tftp_block_size;
425 int loaded = load_block(tftp_cur_block, pkt, toload);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000426
427 s[0] = htons(TFTP_DATA);
428 pkt += loaded;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500429 tftp_put_final_block_sent = (loaded < toload);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000430 }
431#endif
wdenkfe8c2802002-11-03 00:38:21 +0000432 len = pkt - xp;
433 break;
434
435 case STATE_TOO_LARGE:
436 xp = pkt;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200437 s = (ushort *)pkt;
438 *s++ = htons(TFTP_ERROR);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000439 *s++ = htons(3);
440
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200441 pkt = (uchar *)s;
Luca Ceresolic718b142011-05-14 05:49:57 +0000442 strcpy((char *)pkt, "File too large");
wdenkfe8c2802002-11-03 00:38:21 +0000443 pkt += 14 /*strlen("File too large")*/ + 1;
444 len = pkt - xp;
445 break;
446
447 case STATE_BAD_MAGIC:
448 xp = pkt;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200449 s = (ushort *)pkt;
450 *s++ = htons(TFTP_ERROR);
451 *s++ = htons(2);
452 pkt = (uchar *)s;
Luca Ceresolic718b142011-05-14 05:49:57 +0000453 strcpy((char *)pkt, "File has bad magic");
wdenkfe8c2802002-11-03 00:38:21 +0000454 pkt += 18 /*strlen("File has bad magic")*/ + 1;
455 len = pkt - xp;
456 break;
457 }
458
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500459 net_send_udp_packet(net_server_ethaddr, tftp_remote_ip,
460 tftp_remote_port, tftp_our_port, len);
wdenkfe8c2802002-11-03 00:38:21 +0000461}
462
Simon Glass39bccd22011-10-26 14:18:38 +0000463#ifdef CONFIG_CMD_TFTPPUT
Simon Glass1fb7cd42011-10-24 18:00:07 +0000464static void icmp_handler(unsigned type, unsigned code, unsigned dest,
Joe Hershberger049a95a2015-04-08 01:41:01 -0500465 struct in_addr sip, unsigned src, uchar *pkt,
466 unsigned len)
Simon Glass1fb7cd42011-10-24 18:00:07 +0000467{
468 if (type == ICMP_NOT_REACH && code == ICMP_NOT_REACH_PORT) {
469 /* Oh dear the other end has gone away */
Sham Muthayyan35c87902018-01-18 14:09:05 +0530470 printf("TFTP server dies: print the pkt buffer\n");
471 print_buffer(0, pkt, 1, len, 0);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000472 restart("TFTP server died");
473 }
474}
Simon Glass39bccd22011-10-26 14:18:38 +0000475#endif
Simon Glass1fb7cd42011-10-24 18:00:07 +0000476
Joe Hershberger049a95a2015-04-08 01:41:01 -0500477static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
478 unsigned src, unsigned len)
wdenkfe8c2802002-11-03 00:38:21 +0000479{
Kim Phillips61fdd4f2013-01-16 18:09:19 -0600480 __be16 proto;
481 __be16 *s;
Wolfgang Denkff13ac82007-08-30 14:42:15 +0200482 int i;
wdenkfe8c2802002-11-03 00:38:21 +0000483
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500484 if (dest != tftp_our_port) {
David Updegraff53a5c422007-06-11 10:41:07 -0500485#ifdef CONFIG_MCAST_TFTP
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500486 if (tftp_mcast_active &&
487 (!tftp_mcast_port || dest != tftp_mcast_port))
David Updegraff53a5c422007-06-11 10:41:07 -0500488#endif
Luca Ceresoli0bdd8ac2011-05-14 05:50:02 +0000489 return;
wdenkfe8c2802002-11-03 00:38:21 +0000490 }
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500491 if (tftp_state != STATE_SEND_RRQ && src != tftp_remote_port &&
492 tftp_state != STATE_RECV_WRQ && tftp_state != STATE_SEND_WRQ)
wdenkfe8c2802002-11-03 00:38:21 +0000493 return;
wdenkfe8c2802002-11-03 00:38:21 +0000494
Luca Ceresoli7bc325a2011-05-14 05:50:00 +0000495 if (len < 2)
wdenkfe8c2802002-11-03 00:38:21 +0000496 return;
wdenkfe8c2802002-11-03 00:38:21 +0000497 len -= 2;
498 /* warning: don't use increment (++) in ntohs() macros!! */
Kim Phillips61fdd4f2013-01-16 18:09:19 -0600499 s = (__be16 *)pkt;
Wolfgang Denk7bc5ee02005-08-26 01:36:03 +0200500 proto = *s++;
501 pkt = (uchar *)s;
wdenkfe8c2802002-11-03 00:38:21 +0000502 switch (ntohs(proto)) {
wdenkfe8c2802002-11-03 00:38:21 +0000503 case TFTP_RRQ:
wdenkfe8c2802002-11-03 00:38:21 +0000504 break;
Simon Glass1fb7cd42011-10-24 18:00:07 +0000505
506 case TFTP_ACK:
507#ifdef CONFIG_CMD_TFTPPUT
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500508 if (tftp_put_active) {
509 if (tftp_put_final_block_sent) {
Simon Glass1fb7cd42011-10-24 18:00:07 +0000510 tftp_complete();
511 } else {
512 /*
513 * Move to the next block. We want our block
514 * count to wrap just like the other end!
515 */
516 int block = ntohs(*s);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500517 int ack_ok = (tftp_cur_block == block);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000518
Ajay Kishore3491df22016-09-15 15:29:02 +0530519 tftp_prev_block = tftp_cur_block;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500520 tftp_cur_block = (unsigned short)(block + 1);
Simon Glass1fb7cd42011-10-24 18:00:07 +0000521 update_block_number();
522 if (ack_ok)
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500523 tftp_send(); /* Send next data block */
Simon Glass1fb7cd42011-10-24 18:00:07 +0000524 }
525 }
526#endif
527 break;
528
wdenkfe8c2802002-11-03 00:38:21 +0000529 default:
530 break;
531
Luca Ceresolie59e3562011-05-17 00:03:39 +0000532#ifdef CONFIG_CMD_TFTPSRV
533 case TFTP_WRQ:
534 debug("Got WRQ\n");
Joe Hershberger049a95a2015-04-08 01:41:01 -0500535 tftp_remote_ip = sip;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500536 tftp_remote_port = src;
537 tftp_our_port = 1024 + (get_timer(0) % 3072);
Simon Glasse4cde2f2011-10-24 18:00:04 +0000538 new_transfer();
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500539 tftp_send(); /* Send ACK(0) */
Luca Ceresolie59e3562011-05-17 00:03:39 +0000540 break;
541#endif
542
wdenkfbe4b5c2003-10-06 21:55:32 +0000543 case TFTP_OACK:
Wolfgang Denkd3717082009-08-10 09:59:10 +0200544 debug("Got OACK: %s %s\n",
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500545 pkt, pkt + strlen((char *)pkt) + 1);
546 tftp_state = STATE_OACK;
Sham Muthayyan35c87902018-01-18 14:09:05 +0530547 if (tftp_remote_port != src) {
548 printf("\nGot TFTP_OACK: TFTP remote port: changes from %d to %d\n",
549 tftp_remote_port, src);
550 tftp_remote_port = src;
551 }
Wolfgang Denk60174742007-08-31 10:01:51 +0200552 /*
553 * Check for 'blksize' option.
554 * Careful: "i" is signed, "len" is unsigned, thus
555 * something like "len-8" may give a *huge* number
556 */
Luca Ceresolic718b142011-05-14 05:49:57 +0000557 for (i = 0; i+8 < len; i++) {
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500558 if (strcmp((char *)pkt + i, "blksize") == 0) {
559 tftp_block_size = (unsigned short)
560 simple_strtoul((char *)pkt + i + 8,
561 NULL, 10);
Robin Getz0ebf04c2009-07-23 03:01:03 -0400562 debug("Blocksize ack: %s, %d\n",
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500563 (char *)pkt + i + 8, tftp_block_size);
Wolfgang Denkff13ac82007-08-30 14:42:15 +0200564 }
Robin Getz4fccb812009-08-20 10:50:20 -0400565#ifdef CONFIG_TFTP_TSIZE
Luca Ceresoli2e320252011-05-14 05:49:58 +0000566 if (strcmp((char *)pkt+i, "tsize") == 0) {
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500567 tftp_tsize = simple_strtoul((char *)pkt + i + 6,
Luca Ceresoli2f094132011-05-14 05:49:56 +0000568 NULL, 10);
Robin Getz4fccb812009-08-20 10:50:20 -0400569 debug("size = %s, %d\n",
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500570 (char *)pkt + i + 6, tftp_tsize);
Robin Getz4fccb812009-08-20 10:50:20 -0400571 }
572#endif
David Updegraff53a5c422007-06-11 10:41:07 -0500573 }
574#ifdef CONFIG_MCAST_TFTP
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500575 parse_multicast_oack((char *)pkt, len - 1);
576 if ((tftp_mcast_active) && (!tftp_mcast_master_client))
577 tftp_state = STATE_DATA; /* passive.. */
David Updegraff53a5c422007-06-11 10:41:07 -0500578 else
579#endif
Simon Glass1fb7cd42011-10-24 18:00:07 +0000580#ifdef CONFIG_CMD_TFTPPUT
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500581 if (tftp_put_active) {
Simon Glass1fb7cd42011-10-24 18:00:07 +0000582 /* Get ready to send the first block */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500583 tftp_state = STATE_DATA;
584 tftp_cur_block++;
Simon Glass1fb7cd42011-10-24 18:00:07 +0000585 }
586#endif
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500587 tftp_send(); /* Send ACK or first data block */
wdenkfbe4b5c2003-10-06 21:55:32 +0000588 break;
wdenkfe8c2802002-11-03 00:38:21 +0000589 case TFTP_DATA:
590 if (len < 2)
591 return;
592 len -= 2;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500593 tftp_cur_block = ntohs(*(__be16 *)pkt);
wdenk3f85ce22004-02-23 16:11:30 +0000594
Simon Glasse4cde2f2011-10-24 18:00:04 +0000595 update_block_number();
wdenkfe8c2802002-11-03 00:38:21 +0000596
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500597 if (tftp_state == STATE_SEND_RRQ)
Robin Getz0ebf04c2009-07-23 03:01:03 -0400598 debug("Server did not acknowledge timeout option!\n");
wdenkfbe4b5c2003-10-06 21:55:32 +0000599
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500600 if (tftp_state == STATE_SEND_RRQ || tftp_state == STATE_OACK ||
601 tftp_state == STATE_RECV_WRQ) {
wdenk3f85ce22004-02-23 16:11:30 +0000602 /* first block received */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500603 tftp_state = STATE_DATA;
Sham Muthayyan35c87902018-01-18 14:09:05 +0530604 if (tftp_remote_port != src) {
605 printf("\nGot TFTP_DATA: TFTP remote port: changes from %d to %d\n",
606 tftp_remote_port, src);
607 tftp_remote_port = src;
608 }
Simon Glasse4cde2f2011-10-24 18:00:04 +0000609 new_transfer();
wdenkfe8c2802002-11-03 00:38:21 +0000610
David Updegraff53a5c422007-06-11 10:41:07 -0500611#ifdef CONFIG_MCAST_TFTP
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500612 if (tftp_mcast_active) { /* start!=1 common if mcast */
613 tftp_prev_block = tftp_cur_block - 1;
David Updegraff53a5c422007-06-11 10:41:07 -0500614 } else
615#endif
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500616 if (tftp_cur_block != 1) { /* Assertion */
617 puts("\nTFTP error: ");
618 printf("First block is not block 1 (%ld)\n",
619 tftp_cur_block);
620 puts("Starting again\n\n");
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500621 net_start_again();
wdenkfe8c2802002-11-03 00:38:21 +0000622 break;
623 }
624 }
625
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500626 if (tftp_cur_block == tftp_prev_block) {
627 /* Same block again; ignore it. */
wdenkfe8c2802002-11-03 00:38:21 +0000628 break;
629 }
630
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500631 tftp_prev_block = tftp_cur_block;
Albert ARIBAUD \(3ADEV\)f5fb7342015-10-12 00:02:57 +0200632 timeout_count_max = tftp_timeout_count_max;
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500633 net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
wdenkfe8c2802002-11-03 00:38:21 +0000634
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500635 store_block(tftp_cur_block - 1, pkt + 2, len);
wdenkfe8c2802002-11-03 00:38:21 +0000636
637 /*
Luca Ceresoli4d69e982011-05-17 00:03:41 +0000638 * Acknowledge the block just received, which will prompt
Luca Ceresoli20478ce2011-05-17 00:03:37 +0000639 * the remote for the next one.
wdenkfe8c2802002-11-03 00:38:21 +0000640 */
David Updegraff53a5c422007-06-11 10:41:07 -0500641#ifdef CONFIG_MCAST_TFTP
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200642 /* if I am the MasterClient, actively calculate what my next
643 * needed block is; else I'm passive; not ACKING
Jean-Christophe PLAGNIOL-VILLARDa93907c2008-01-18 01:14:03 +0100644 */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500645 if (tftp_mcast_active) {
646 if (len < tftp_block_size) {
647 tftp_mcast_ending_block = tftp_cur_block;
648 } else if (tftp_mcast_master_client) {
649 tftp_mcast_prev_hole = ext2_find_next_zero_bit(
650 tftp_mcast_bitmap,
651 tftp_mcast_bitmap_size * 8,
652 tftp_mcast_prev_hole);
653 tftp_cur_block = tftp_mcast_prev_hole;
654 if (tftp_cur_block >
655 ((tftp_mcast_bitmap_size * 8) - 1)) {
656 debug("tftpfile too big\n");
David Updegraff53a5c422007-06-11 10:41:07 -0500657 /* try to double it and retry */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500658 tftp_mcast_bitmap_size <<= 1;
David Updegraff53a5c422007-06-11 10:41:07 -0500659 mcast_cleanup();
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500660 net_start_again();
David Updegraff53a5c422007-06-11 10:41:07 -0500661 return;
662 }
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500663 tftp_prev_block = tftp_cur_block;
David Updegraff53a5c422007-06-11 10:41:07 -0500664 }
665 }
666#endif
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500667 tftp_send();
wdenkfe8c2802002-11-03 00:38:21 +0000668
David Updegraff53a5c422007-06-11 10:41:07 -0500669#ifdef CONFIG_MCAST_TFTP
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500670 if (tftp_mcast_active) {
671 if (tftp_mcast_master_client &&
672 (tftp_cur_block >= tftp_mcast_ending_block)) {
Luca Ceresolic718b142011-05-14 05:49:57 +0000673 puts("\nMulticast tftp done\n");
David Updegraff53a5c422007-06-11 10:41:07 -0500674 mcast_cleanup();
Joe Hershberger22f6e992012-05-23 07:59:14 +0000675 net_set_state(NETLOOP_SUCCESS);
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200676 }
Joe Hershberger13dfe942012-05-15 08:59:12 +0000677 } else
David Updegraff53a5c422007-06-11 10:41:07 -0500678#endif
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500679 if (len < tftp_block_size)
Simon Glassf5329bb2011-10-24 18:00:03 +0000680 tftp_complete();
wdenkfe8c2802002-11-03 00:38:21 +0000681 break;
682
683 case TFTP_ERROR:
Luca Ceresolic718b142011-05-14 05:49:57 +0000684 printf("\nTFTP error: '%s' (%d)\n",
Kim Phillips61fdd4f2013-01-16 18:09:19 -0600685 pkt + 2, ntohs(*(__be16 *)pkt));
Remy Bohmeraafda382009-10-28 22:13:40 +0100686
Kim Phillips61fdd4f2013-01-16 18:09:19 -0600687 switch (ntohs(*(__be16 *)pkt)) {
Remy Bohmeraafda382009-10-28 22:13:40 +0100688 case TFTP_ERR_FILE_NOT_FOUND:
689 case TFTP_ERR_ACCESS_DENIED:
690 puts("Not retrying...\n");
691 eth_halt();
Joe Hershberger22f6e992012-05-23 07:59:14 +0000692 net_set_state(NETLOOP_FAIL);
Remy Bohmeraafda382009-10-28 22:13:40 +0100693 break;
694 case TFTP_ERR_UNDEFINED:
695 case TFTP_ERR_DISK_FULL:
696 case TFTP_ERR_UNEXPECTED_OPCODE:
697 case TFTP_ERR_UNKNOWN_TRANSFER_ID:
698 case TFTP_ERR_FILE_ALREADY_EXISTS:
699 default:
700 puts("Starting again\n\n");
David Updegraff53a5c422007-06-11 10:41:07 -0500701#ifdef CONFIG_MCAST_TFTP
Remy Bohmeraafda382009-10-28 22:13:40 +0100702 mcast_cleanup();
David Updegraff53a5c422007-06-11 10:41:07 -0500703#endif
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500704 net_start_again();
Remy Bohmeraafda382009-10-28 22:13:40 +0100705 break;
706 }
wdenkfe8c2802002-11-03 00:38:21 +0000707 break;
708 }
709}
710
711
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500712static void tftp_timeout_handler(void)
wdenkfe8c2802002-11-03 00:38:21 +0000713{
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500714 if (++timeout_count > timeout_count_max) {
Simon Glasse4cde2f2011-10-24 18:00:04 +0000715 restart("Retry count exceeded");
wdenkfe8c2802002-11-03 00:38:21 +0000716 } else {
Luca Ceresolic718b142011-05-14 05:49:57 +0000717 puts("T ");
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500718 net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500719 if (tftp_state != STATE_RECV_WRQ)
720 tftp_send();
wdenkfe8c2802002-11-03 00:38:21 +0000721 }
722}
723
724
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500725void tftp_start(enum proto_t protocol)
wdenkfe8c2802002-11-03 00:38:21 +0000726{
Albert ARIBAUD \(3ADEV\)f5fb7342015-10-12 00:02:57 +0200727#if CONFIG_NET_TFTP_VARS
Wolfgang Denkecb0ccd2005-09-24 22:37:32 +0200728 char *ep; /* Environment pointer */
Alessandro Rubini89ba81d2009-08-07 13:59:06 +0200729
Wolfgang Denkc96f86e2010-01-17 23:55:53 +0100730 /*
731 * Allow the user to choose TFTP blocksize and timeout.
732 * TFTP protocol has a minimal timeout of 1 second.
733 */
Albert ARIBAUD \(3ADEV\)f5fb7342015-10-12 00:02:57 +0200734
Luca Ceresoli2cb53602011-05-14 05:49:59 +0000735 ep = getenv("tftpblocksize");
736 if (ep != NULL)
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500737 tftp_block_size_option = simple_strtol(ep, NULL, 10);
Wolfgang Denkc96f86e2010-01-17 23:55:53 +0100738
Luca Ceresoli2cb53602011-05-14 05:49:59 +0000739 ep = getenv("tftptimeout");
740 if (ep != NULL)
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500741 timeout_ms = simple_strtol(ep, NULL, 10);
Wolfgang Denkc96f86e2010-01-17 23:55:53 +0100742
Bin Mengaf2ca592015-08-27 22:25:51 -0700743 if (timeout_ms < 1000) {
744 printf("TFTP timeout (%ld ms) too low, set min = 1000 ms\n",
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500745 timeout_ms);
Bin Mengaf2ca592015-08-27 22:25:51 -0700746 timeout_ms = 1000;
Wolfgang Denkc96f86e2010-01-17 23:55:53 +0100747 }
748
Albert ARIBAUD \(3ADEV\)f5fb7342015-10-12 00:02:57 +0200749 ep = getenv("tftptimeoutcountmax");
750 if (ep != NULL)
751 tftp_timeout_count_max = simple_strtol(ep, NULL, 10);
752
753 if (tftp_timeout_count_max < 0) {
754 printf("TFTP timeout count max (%d ms) negative, set to 0\n",
755 tftp_timeout_count_max);
756 tftp_timeout_count_max = 0;
757 }
758#endif
759
Wolfgang Denkc96f86e2010-01-17 23:55:53 +0100760 debug("TFTP blocksize = %i, timeout = %ld ms\n",
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500761 tftp_block_size_option, timeout_ms);
Wolfgang Denkecb0ccd2005-09-24 22:37:32 +0200762
Joe Hershberger049a95a2015-04-08 01:41:01 -0500763 tftp_remote_ip = net_server_ip;
Joe Hershberger14111572015-04-08 01:41:02 -0500764 if (net_boot_file_name[0] == '\0') {
Matthias Weisserea45cb02011-12-03 03:29:44 +0000765 sprintf(default_filename, "%02X%02X%02X%02X.img",
Joe Hershberger049a95a2015-04-08 01:41:01 -0500766 net_ip.s_addr & 0xFF,
767 (net_ip.s_addr >> 8) & 0xFF,
768 (net_ip.s_addr >> 16) & 0xFF,
769 (net_ip.s_addr >> 24) & 0xFF);
Jean-Christophe PLAGNIOL-VILLARDa93907c2008-01-18 01:14:03 +0100770
771 strncpy(tftp_filename, default_filename, MAX_LEN);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500772 tftp_filename[MAX_LEN - 1] = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000773
Luca Ceresolic718b142011-05-14 05:49:57 +0000774 printf("*** Warning: no boot file name; using '%s'\n",
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500775 tftp_filename);
wdenkfe8c2802002-11-03 00:38:21 +0000776 } else {
Joe Hershberger14111572015-04-08 01:41:02 -0500777 char *p = strchr(net_boot_file_name, ':');
Jean-Christophe PLAGNIOL-VILLARDa93907c2008-01-18 01:14:03 +0100778
779 if (p == NULL) {
Joe Hershberger14111572015-04-08 01:41:02 -0500780 strncpy(tftp_filename, net_boot_file_name, MAX_LEN);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500781 tftp_filename[MAX_LEN - 1] = 0;
Jean-Christophe PLAGNIOL-VILLARDa93907c2008-01-18 01:14:03 +0100782 } else {
Joe Hershberger14111572015-04-08 01:41:02 -0500783 tftp_remote_ip = string_to_ip(net_boot_file_name);
Peter Tyser6a86bb62008-12-01 16:29:38 -0600784 strncpy(tftp_filename, p + 1, MAX_LEN);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500785 tftp_filename[MAX_LEN - 1] = 0;
Jean-Christophe PLAGNIOL-VILLARDa93907c2008-01-18 01:14:03 +0100786 }
wdenkfe8c2802002-11-03 00:38:21 +0000787 }
788
Luca Ceresolic718b142011-05-14 05:49:57 +0000789 printf("Using %s device\n", eth_get_name());
Simon Glass1fb7cd42011-10-24 18:00:07 +0000790 printf("TFTP %s server %pI4; our IP address is %pI4",
Simon Glass8c6914f2011-10-27 06:24:29 +0000791#ifdef CONFIG_CMD_TFTPPUT
792 protocol == TFTPPUT ? "to" : "from",
793#else
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500794 "from",
Simon Glass8c6914f2011-10-27 06:24:29 +0000795#endif
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500796 &tftp_remote_ip, &net_ip);
wdenkfe8c2802002-11-03 00:38:21 +0000797
798 /* Check if we need to send across this subnet */
Joe Hershberger049a95a2015-04-08 01:41:01 -0500799 if (net_gateway.s_addr && net_netmask.s_addr) {
800 struct in_addr our_net;
801 struct in_addr remote_net;
wdenkfe8c2802002-11-03 00:38:21 +0000802
Joe Hershberger049a95a2015-04-08 01:41:01 -0500803 our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
804 remote_net.s_addr = tftp_remote_ip.s_addr & net_netmask.s_addr;
805 if (our_net.s_addr != remote_net.s_addr)
806 printf("; sending through gateway %pI4", &net_gateway);
wdenkfe8c2802002-11-03 00:38:21 +0000807 }
Luca Ceresolic718b142011-05-14 05:49:57 +0000808 putc('\n');
wdenkfe8c2802002-11-03 00:38:21 +0000809
Luca Ceresolic718b142011-05-14 05:49:57 +0000810 printf("Filename '%s'.", tftp_filename);
wdenkfe8c2802002-11-03 00:38:21 +0000811
Joe Hershberger14111572015-04-08 01:41:02 -0500812 if (net_boot_file_expected_size_in_blocks) {
813 printf(" Size is 0x%x Bytes = ",
814 net_boot_file_expected_size_in_blocks << 9);
815 print_size(net_boot_file_expected_size_in_blocks << 9, "");
wdenkfe8c2802002-11-03 00:38:21 +0000816 }
817
Luca Ceresolic718b142011-05-14 05:49:57 +0000818 putc('\n');
Simon Glass1fb7cd42011-10-24 18:00:07 +0000819#ifdef CONFIG_CMD_TFTPPUT
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500820 tftp_put_active = (protocol == TFTPPUT);
821 if (tftp_put_active) {
Simon Glass1fb7cd42011-10-24 18:00:07 +0000822 printf("Save address: 0x%lx\n", save_addr);
823 printf("Save size: 0x%lx\n", save_size);
Joe Hershberger14111572015-04-08 01:41:02 -0500824 net_boot_file_size = save_size;
Simon Glass1fb7cd42011-10-24 18:00:07 +0000825 puts("Saving: *\b");
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500826 tftp_state = STATE_SEND_WRQ;
Simon Glass1fb7cd42011-10-24 18:00:07 +0000827 new_transfer();
828 } else
829#endif
830 {
831 printf("Load address: 0x%lx\n", load_addr);
Sanjeev N9908fc32017-09-05 15:18:54 +0530832 /*
833 * Do not load files to the reserved region or the
834 * region where linux is executed.
835 */
Kathiravan T3527e1e2017-12-15 14:31:40 +0530836#ifdef CONFIG_IPQ806X
837 if ((load_addr < IPQ_TFTP_MIN_ADDR) ||
838 (load_addr >= IPQ_TFTP_MAX_ADDR)) {
839#else
Sanjeev N9908fc32017-09-05 15:18:54 +0530840 if ((load_addr < IPQ_TFTP_MIN_ADDR) ||
841 (load_addr >= CONFIG_SYS_SDRAM_END) ||
842 ((load_addr >= CONFIG_IPQ_FDT_HIGH) &&
843 (load_addr < CONFIG_TZ_END_ADDR))) {
Kathiravan T3527e1e2017-12-15 14:31:40 +0530844#endif /* CONFIG_IPQ806X */
Sanjeev N9908fc32017-09-05 15:18:54 +0530845 puts("\nError specified load address not allowed\n");
846 net_set_state(NETLOOP_FAIL);
847 return;
848 }
Simon Glass1fb7cd42011-10-24 18:00:07 +0000849 puts("Loading: *\b");
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500850 tftp_state = STATE_SEND_RRQ;
Simon Glass1fb7cd42011-10-24 18:00:07 +0000851 }
wdenkfe8c2802002-11-03 00:38:21 +0000852
Simon Glass85b19802012-10-11 13:57:36 +0000853 time_start = get_timer(0);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500854 timeout_count_max = tftp_timeout_count_max;
Bartlomiej Siekae83cc062008-10-01 15:26:29 +0200855
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500856 net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
Joe Hershberger049a95a2015-04-08 01:41:01 -0500857 net_set_udp_handler(tftp_handler);
Simon Glass39bccd22011-10-26 14:18:38 +0000858#ifdef CONFIG_CMD_TFTPPUT
Simon Glass1fb7cd42011-10-24 18:00:07 +0000859 net_set_icmp_handler(icmp_handler);
Simon Glass39bccd22011-10-26 14:18:38 +0000860#endif
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500861 tftp_remote_port = WELL_KNOWN_PORT;
862 timeout_count = 0;
Wolfgang Denkecb0ccd2005-09-24 22:37:32 +0200863 /* Use a pseudo-random port unless a specific port is set */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500864 tftp_our_port = 1024 + (get_timer(0) % 3072);
David Updegraff53a5c422007-06-11 10:41:07 -0500865
Wolfgang Denkecb0ccd2005-09-24 22:37:32 +0200866#ifdef CONFIG_TFTP_PORT
Luca Ceresoli2cb53602011-05-14 05:49:59 +0000867 ep = getenv("tftpdstp");
Luca Ceresoli7bc325a2011-05-14 05:50:00 +0000868 if (ep != NULL)
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500869 tftp_remote_port = simple_strtol(ep, NULL, 10);
Luca Ceresoli2cb53602011-05-14 05:49:59 +0000870 ep = getenv("tftpsrcp");
Luca Ceresoli7bc325a2011-05-14 05:50:00 +0000871 if (ep != NULL)
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500872 tftp_our_port = simple_strtol(ep, NULL, 10);
Wolfgang Denkecb0ccd2005-09-24 22:37:32 +0200873#endif
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500874 tftp_cur_block = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000875
wdenk73a8b272003-06-05 19:27:42 +0000876 /* zero out server ether in case the server ip has changed */
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500877 memset(net_server_ethaddr, 0, 6);
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500878 /* Revert tftp_block_size to dflt */
879 tftp_block_size = TFTP_BLOCK_SIZE;
David Updegraff53a5c422007-06-11 10:41:07 -0500880#ifdef CONFIG_MCAST_TFTP
Jean-Christophe PLAGNIOL-VILLARDa93907c2008-01-18 01:14:03 +0100881 mcast_cleanup();
David Updegraff53a5c422007-06-11 10:41:07 -0500882#endif
Robin Getz4fccb812009-08-20 10:50:20 -0400883#ifdef CONFIG_TFTP_TSIZE
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500884 tftp_tsize = 0;
885 tftp_tsize_num_hash = 0;
Robin Getz4fccb812009-08-20 10:50:20 -0400886#endif
wdenk73a8b272003-06-05 19:27:42 +0000887
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500888 tftp_send();
wdenkfe8c2802002-11-03 00:38:21 +0000889}
890
Luca Ceresolie59e3562011-05-17 00:03:39 +0000891#ifdef CONFIG_CMD_TFTPSRV
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500892void tftp_start_server(void)
Luca Ceresolie59e3562011-05-17 00:03:39 +0000893{
894 tftp_filename[0] = 0;
895
Luca Ceresolie59e3562011-05-17 00:03:39 +0000896 printf("Using %s device\n", eth_get_name());
Joe Hershberger049a95a2015-04-08 01:41:01 -0500897 printf("Listening for TFTP transfer on %pI4\n", &net_ip);
Luca Ceresolie59e3562011-05-17 00:03:39 +0000898 printf("Load address: 0x%lx\n", load_addr);
899
900 puts("Loading: *\b");
901
Albert ARIBAUD \(3ADEV\)f5fb7342015-10-12 00:02:57 +0200902 timeout_count_max = tftp_timeout_count_max;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500903 timeout_count = 0;
904 timeout_ms = TIMEOUT;
Joe Hershbergerbc0571f2015-04-08 01:41:21 -0500905 net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
Luca Ceresolie59e3562011-05-17 00:03:39 +0000906
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500907 /* Revert tftp_block_size to dflt */
908 tftp_block_size = TFTP_BLOCK_SIZE;
909 tftp_cur_block = 0;
910 tftp_our_port = WELL_KNOWN_PORT;
Luca Ceresolie59e3562011-05-17 00:03:39 +0000911
912#ifdef CONFIG_TFTP_TSIZE
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500913 tftp_tsize = 0;
914 tftp_tsize_num_hash = 0;
Luca Ceresolie59e3562011-05-17 00:03:39 +0000915#endif
916
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500917 tftp_state = STATE_RECV_WRQ;
Joe Hershberger049a95a2015-04-08 01:41:01 -0500918 net_set_udp_handler(tftp_handler);
Andrew Ruder8e525332013-10-22 19:10:28 -0500919
920 /* zero out server ether in case the server ip has changed */
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500921 memset(net_server_ethaddr, 0, 6);
Luca Ceresolie59e3562011-05-17 00:03:39 +0000922}
923#endif /* CONFIG_CMD_TFTPSRV */
924
David Updegraff53a5c422007-06-11 10:41:07 -0500925#ifdef CONFIG_MCAST_TFTP
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500926/*
927 * Credits: atftp project.
David Updegraff53a5c422007-06-11 10:41:07 -0500928 */
929
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500930/*
931 * Pick up BcastAddr, Port, and whether I am [now] the master-client.
David Updegraff53a5c422007-06-11 10:41:07 -0500932 * Frame:
933 * +-------+-----------+---+-------~~-------+---+
934 * | opc | multicast | 0 | addr, port, mc | 0 |
935 * +-------+-----------+---+-------~~-------+---+
936 * The multicast addr/port becomes what I listen to, and if 'mc' is '1' then
937 * I am the new master-client so must send ACKs to DataBlocks. If I am not
938 * master-client, I'm a passive client, gathering what DataBlocks I may and
939 * making note of which ones I got in my bitmask.
940 * In theory, I never go from master->passive..
941 * .. this comes in with pkt already pointing just past opc
942 */
943static void parse_multicast_oack(char *pkt, int len)
944{
Luca Ceresolic718b142011-05-14 05:49:57 +0000945 int i;
Joe Hershberger049a95a2015-04-08 01:41:01 -0500946 struct in_addr addr;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500947 char *mc_adr;
948 char *port;
949 char *mc;
David Updegraff53a5c422007-06-11 10:41:07 -0500950
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500951 mc_adr = NULL;
952 port = NULL;
953 mc = NULL;
David Updegraff53a5c422007-06-11 10:41:07 -0500954 /* march along looking for 'multicast\0', which has to start at least
955 * 14 bytes back from the end.
956 */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500957 for (i = 0; i < len - 14; i++)
958 if (strcmp(pkt + i, "multicast") == 0)
David Updegraff53a5c422007-06-11 10:41:07 -0500959 break;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500960 if (i >= (len - 14)) /* non-Multicast OACK, ign. */
David Updegraff53a5c422007-06-11 10:41:07 -0500961 return;
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200962
Luca Ceresolic718b142011-05-14 05:49:57 +0000963 i += 10; /* strlen multicast */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500964 mc_adr = pkt + i;
Luca Ceresolic718b142011-05-14 05:49:57 +0000965 for (; i < len; i++) {
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500966 if (*(pkt + i) == ',') {
967 *(pkt + i) = '\0';
David Updegraff53a5c422007-06-11 10:41:07 -0500968 if (port) {
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500969 mc = pkt + i + 1;
David Updegraff53a5c422007-06-11 10:41:07 -0500970 break;
971 } else {
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500972 port = pkt + i + 1;
David Updegraff53a5c422007-06-11 10:41:07 -0500973 }
974 }
975 }
Luca Ceresoli6d2231e2011-05-14 05:50:01 +0000976 if (!port || !mc_adr || !mc)
977 return;
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500978 if (tftp_mcast_active && tftp_mcast_master_client) {
Luca Ceresolic718b142011-05-14 05:49:57 +0000979 printf("I got a OACK as master Client, WRONG!\n");
David Updegraff53a5c422007-06-11 10:41:07 -0500980 return;
981 }
982 /* ..I now accept packets destined for this MCAST addr, port */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500983 if (!tftp_mcast_active) {
984 if (tftp_mcast_bitmap) {
Luca Ceresolic718b142011-05-14 05:49:57 +0000985 printf("Internal failure! no mcast.\n");
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500986 free(tftp_mcast_bitmap);
987 tftp_mcast_bitmap = NULL;
988 tftp_mcast_disabled = 1;
989 return;
David Updegraff53a5c422007-06-11 10:41:07 -0500990 }
991 /* I malloc instead of pre-declare; so that if the file ends
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200992 * up being too big for this bitmap I can retry
993 */
Joe Hershberger8885c5f2015-04-08 01:41:07 -0500994 tftp_mcast_bitmap = malloc(tftp_mcast_bitmap_size);
995 if (!tftp_mcast_bitmap) {
996 printf("No bitmap, no multicast. Sorry.\n");
997 tftp_mcast_disabled = 1;
David Updegraff53a5c422007-06-11 10:41:07 -0500998 return;
999 }
Joe Hershberger8885c5f2015-04-08 01:41:07 -05001000 memset(tftp_mcast_bitmap, 0, tftp_mcast_bitmap_size);
1001 tftp_mcast_prev_hole = 0;
1002 tftp_mcast_active = 1;
David Updegraff53a5c422007-06-11 10:41:07 -05001003 }
1004 addr = string_to_ip(mc_adr);
Joe Hershberger049a95a2015-04-08 01:41:01 -05001005 if (net_mcast_addr.s_addr != addr.s_addr) {
1006 if (net_mcast_addr.s_addr)
1007 eth_mcast_join(net_mcast_addr, 0);
1008 net_mcast_addr = addr;
1009 if (eth_mcast_join(net_mcast_addr, 1)) {
Luca Ceresolic718b142011-05-14 05:49:57 +00001010 printf("Fail to set mcast, revert to TFTP\n");
Joe Hershberger8885c5f2015-04-08 01:41:07 -05001011 tftp_mcast_disabled = 1;
David Updegraff53a5c422007-06-11 10:41:07 -05001012 mcast_cleanup();
Joe Hershbergerbc0571f2015-04-08 01:41:21 -05001013 net_start_again();
David Updegraff53a5c422007-06-11 10:41:07 -05001014 }
1015 }
Joe Hershberger8885c5f2015-04-08 01:41:07 -05001016 tftp_mcast_master_client = simple_strtoul((char *)mc, NULL, 10);
1017 tftp_mcast_port = (unsigned short)simple_strtoul(port, NULL, 10);
1018 printf("Multicast: %s:%d [%d]\n", mc_adr, tftp_mcast_port,
1019 tftp_mcast_master_client);
David Updegraff53a5c422007-06-11 10:41:07 -05001020 return;
1021}
1022
1023#endif /* Multicast TFTP */