tftp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * Copyright 1994, 1995, 2000 Neil Russell.
  3. * (See License)
  4. * Copyright 2000, 2001 DENX Software Engineering, Wolfgang Denk, wd@denx.de
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <net.h>
  9. #include "tftp.h"
  10. #include "bootp.h"
  11. #undef ET_DEBUG
  12. #if defined(CONFIG_CMD_NET)
  13. #define WELL_KNOWN_PORT 69 /* Well known TFTP port # */
  14. #define TIMEOUT 5000UL /* Millisecs to timeout for lost pkt */
  15. #ifndef CONFIG_NET_RETRY_COUNT
  16. # define TIMEOUT_COUNT 10 /* # of timeouts before giving up */
  17. #else
  18. # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT * 2)
  19. #endif
  20. /* (for checking the image size) */
  21. #define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */
  22. /*
  23. * TFTP operations.
  24. */
  25. #define TFTP_RRQ 1
  26. #define TFTP_WRQ 2
  27. #define TFTP_DATA 3
  28. #define TFTP_ACK 4
  29. #define TFTP_ERROR 5
  30. #define TFTP_OACK 6
  31. static ulong TftpTimeoutMSecs = TIMEOUT;
  32. static int TftpTimeoutCountMax = TIMEOUT_COUNT;
  33. /*
  34. * These globals govern the timeout behavior when attempting a connection to a
  35. * TFTP server. TftpRRQTimeoutMSecs specifies the number of milliseconds to
  36. * wait for the server to respond to initial connection. Second global,
  37. * TftpRRQTimeoutCountMax, gives the number of such connection retries.
  38. * TftpRRQTimeoutCountMax must be non-negative and TftpRRQTimeoutMSecs must be
  39. * positive. The globals are meant to be set (and restored) by code needing
  40. * non-standard timeout behavior when initiating a TFTP transfer.
  41. */
  42. ulong TftpRRQTimeoutMSecs = TIMEOUT;
  43. int TftpRRQTimeoutCountMax = TIMEOUT_COUNT;
  44. static IPaddr_t TftpServerIP;
  45. static int TftpServerPort; /* The UDP port at their end */
  46. static int TftpOurPort; /* The UDP port at our end */
  47. static int TftpTimeoutCount;
  48. static ulong TftpBlock; /* packet sequence number */
  49. static ulong TftpLastBlock; /* last packet sequence number received */
  50. static ulong TftpBlockWrap; /* count of sequence number wraparounds */
  51. static ulong TftpBlockWrapOffset; /* memory offset due to wrapping */
  52. static int TftpState;
  53. #define STATE_RRQ 1
  54. #define STATE_DATA 2
  55. #define STATE_TOO_LARGE 3
  56. #define STATE_BAD_MAGIC 4
  57. #define STATE_OACK 5
  58. #define TFTP_BLOCK_SIZE 512 /* default TFTP block size */
  59. #define TFTP_SEQUENCE_SIZE ((ulong)(1<<16)) /* sequence number is 16 bit */
  60. #define DEFAULT_NAME_LEN (8 + 4 + 1)
  61. static char default_filename[DEFAULT_NAME_LEN];
  62. #ifndef CONFIG_TFTP_FILE_NAME_MAX_LEN
  63. #define MAX_LEN 128
  64. #else
  65. #define MAX_LEN CONFIG_TFTP_FILE_NAME_MAX_LEN
  66. #endif
  67. static char tftp_filename[MAX_LEN];
  68. #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
  69. extern flash_info_t flash_info[];
  70. #endif
  71. /* 512 is poor choice for ethernet, MTU is typically 1500.
  72. * Minus eth.hdrs thats 1468. Can get 2x better throughput with
  73. * almost-MTU block sizes. At least try... fall back to 512 if need be.
  74. */
  75. #define TFTP_MTU_BLOCKSIZE 1468
  76. static unsigned short TftpBlkSize=TFTP_BLOCK_SIZE;
  77. static unsigned short TftpBlkSizeOption=TFTP_MTU_BLOCKSIZE;
  78. #ifdef CONFIG_MCAST_TFTP
  79. #include <malloc.h>
  80. #define MTFTP_BITMAPSIZE 0x1000
  81. static unsigned *Bitmap;
  82. static int PrevBitmapHole,Mapsize=MTFTP_BITMAPSIZE;
  83. static uchar ProhibitMcast=0, MasterClient=0;
  84. static uchar Multicast=0;
  85. extern IPaddr_t Mcast_addr;
  86. static int Mcast_port;
  87. static ulong TftpEndingBlock; /* can get 'last' block before done..*/
  88. static void parse_multicast_oack(char *pkt,int len);
  89. static void
  90. mcast_cleanup(void)
  91. {
  92. if (Mcast_addr) eth_mcast_join(Mcast_addr, 0);
  93. if (Bitmap) free(Bitmap);
  94. Bitmap=NULL;
  95. Mcast_addr = Multicast = Mcast_port = 0;
  96. TftpEndingBlock = -1;
  97. }
  98. #endif /* CONFIG_MCAST_TFTP */
  99. static __inline__ void
  100. store_block (unsigned block, uchar * src, unsigned len)
  101. {
  102. ulong offset = block * TftpBlkSize + TftpBlockWrapOffset;
  103. ulong newsize = offset + len;
  104. #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
  105. int i, rc = 0;
  106. for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; i++) {
  107. /* start address in flash? */
  108. if (flash_info[i].flash_id == FLASH_UNKNOWN)
  109. continue;
  110. if (load_addr + offset >= flash_info[i].start[0]) {
  111. rc = 1;
  112. break;
  113. }
  114. }
  115. if (rc) { /* Flash is destination for this packet */
  116. rc = flash_write ((char *)src, (ulong)(load_addr+offset), len);
  117. if (rc) {
  118. flash_perror (rc);
  119. NetState = NETLOOP_FAIL;
  120. return;
  121. }
  122. }
  123. else
  124. #endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */
  125. {
  126. (void)memcpy((void *)(load_addr + offset), src, len);
  127. }
  128. #ifdef CONFIG_MCAST_TFTP
  129. if (Multicast)
  130. ext2_set_bit(block, Bitmap);
  131. #endif
  132. if (NetBootFileXferSize < newsize)
  133. NetBootFileXferSize = newsize;
  134. }
  135. static void TftpSend (void);
  136. static void TftpTimeout (void);
  137. /**********************************************************************/
  138. static void
  139. TftpSend (void)
  140. {
  141. volatile uchar * pkt;
  142. volatile uchar * xp;
  143. int len = 0;
  144. volatile ushort *s;
  145. #ifdef CONFIG_MCAST_TFTP
  146. /* Multicast TFTP.. non-MasterClients do not ACK data. */
  147. if (Multicast
  148. && (TftpState == STATE_DATA)
  149. && (MasterClient == 0))
  150. return;
  151. #endif
  152. /*
  153. * We will always be sending some sort of packet, so
  154. * cobble together the packet headers now.
  155. */
  156. pkt = NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE;
  157. switch (TftpState) {
  158. case STATE_RRQ:
  159. xp = pkt;
  160. s = (ushort *)pkt;
  161. *s++ = htons(TFTP_RRQ);
  162. pkt = (uchar *)s;
  163. strcpy ((char *)pkt, tftp_filename);
  164. pkt += strlen(tftp_filename) + 1;
  165. strcpy ((char *)pkt, "octet");
  166. pkt += 5 /*strlen("octet")*/ + 1;
  167. strcpy ((char *)pkt, "timeout");
  168. pkt += 7 /*strlen("timeout")*/ + 1;
  169. sprintf((char *)pkt, "%lu", TIMEOUT / 1000);
  170. #ifdef ET_DEBUG
  171. printf("send option \"timeout %s\"\n", (char *)pkt);
  172. #endif
  173. pkt += strlen((char *)pkt) + 1;
  174. /* try for more effic. blk size */
  175. pkt += sprintf((char *)pkt,"blksize%c%d%c",
  176. 0,TftpBlkSizeOption,0);
  177. #ifdef CONFIG_MCAST_TFTP
  178. /* Check all preconditions before even trying the option */
  179. if (!ProhibitMcast
  180. && (Bitmap=malloc(Mapsize))
  181. && eth_get_dev()->mcast) {
  182. free(Bitmap);
  183. Bitmap=NULL;
  184. pkt += sprintf((char *)pkt,"multicast%c%c",0,0);
  185. }
  186. #endif /* CONFIG_MCAST_TFTP */
  187. len = pkt - xp;
  188. break;
  189. case STATE_OACK:
  190. #ifdef CONFIG_MCAST_TFTP
  191. /* My turn! Start at where I need blocks I missed.*/
  192. if (Multicast)
  193. TftpBlock=ext2_find_next_zero_bit(Bitmap,(Mapsize*8),0);
  194. /*..falling..*/
  195. #endif
  196. case STATE_DATA:
  197. xp = pkt;
  198. s = (ushort *)pkt;
  199. *s++ = htons(TFTP_ACK);
  200. *s++ = htons(TftpBlock);
  201. pkt = (uchar *)s;
  202. len = pkt - xp;
  203. break;
  204. case STATE_TOO_LARGE:
  205. xp = pkt;
  206. s = (ushort *)pkt;
  207. *s++ = htons(TFTP_ERROR);
  208. *s++ = htons(3);
  209. pkt = (uchar *)s;
  210. strcpy ((char *)pkt, "File too large");
  211. pkt += 14 /*strlen("File too large")*/ + 1;
  212. len = pkt - xp;
  213. break;
  214. case STATE_BAD_MAGIC:
  215. xp = pkt;
  216. s = (ushort *)pkt;
  217. *s++ = htons(TFTP_ERROR);
  218. *s++ = htons(2);
  219. pkt = (uchar *)s;
  220. strcpy ((char *)pkt, "File has bad magic");
  221. pkt += 18 /*strlen("File has bad magic")*/ + 1;
  222. len = pkt - xp;
  223. break;
  224. }
  225. NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
  226. }
  227. static void
  228. TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
  229. {
  230. ushort proto;
  231. ushort *s;
  232. int i;
  233. if (dest != TftpOurPort) {
  234. #ifdef CONFIG_MCAST_TFTP
  235. if (Multicast
  236. && (!Mcast_port || (dest != Mcast_port)))
  237. #endif
  238. return;
  239. }
  240. if (TftpState != STATE_RRQ && src != TftpServerPort) {
  241. return;
  242. }
  243. if (len < 2) {
  244. return;
  245. }
  246. len -= 2;
  247. /* warning: don't use increment (++) in ntohs() macros!! */
  248. s = (ushort *)pkt;
  249. proto = *s++;
  250. pkt = (uchar *)s;
  251. switch (ntohs(proto)) {
  252. case TFTP_RRQ:
  253. case TFTP_WRQ:
  254. case TFTP_ACK:
  255. break;
  256. default:
  257. break;
  258. case TFTP_OACK:
  259. #ifdef ET_DEBUG
  260. printf("Got OACK: %s %s\n", pkt, pkt+strlen(pkt)+1);
  261. #endif
  262. TftpState = STATE_OACK;
  263. TftpServerPort = src;
  264. /*
  265. * Check for 'blksize' option.
  266. * Careful: "i" is signed, "len" is unsigned, thus
  267. * something like "len-8" may give a *huge* number
  268. */
  269. for (i=0; i+8<len; i++) {
  270. if (strcmp ((char*)pkt+i,"blksize") == 0) {
  271. TftpBlkSize = (unsigned short)
  272. simple_strtoul((char*)pkt+i+8,NULL,10);
  273. #ifdef ET_DEBUG
  274. printf ("Blocksize ack: %s, %d\n",
  275. (char*)pkt+i+8,TftpBlkSize);
  276. #endif
  277. break;
  278. }
  279. }
  280. #ifdef CONFIG_MCAST_TFTP
  281. parse_multicast_oack((char *)pkt,len-1);
  282. if ((Multicast) && (!MasterClient))
  283. TftpState = STATE_DATA; /* passive.. */
  284. else
  285. #endif
  286. TftpSend (); /* Send ACK */
  287. break;
  288. case TFTP_DATA:
  289. if (len < 2)
  290. return;
  291. len -= 2;
  292. TftpBlock = ntohs(*(ushort *)pkt);
  293. /*
  294. * RFC1350 specifies that the first data packet will
  295. * have sequence number 1. If we receive a sequence
  296. * number of 0 this means that there was a wrap
  297. * around of the (16 bit) counter.
  298. */
  299. if (TftpBlock == 0) {
  300. TftpBlockWrap++;
  301. TftpBlockWrapOffset += TftpBlkSize * TFTP_SEQUENCE_SIZE;
  302. printf ("\n\t %lu MB received\n\t ", TftpBlockWrapOffset>>20);
  303. } else {
  304. if (((TftpBlock - 1) % 10) == 0) {
  305. putc ('#');
  306. } else if ((TftpBlock % (10 * HASHES_PER_LINE)) == 0) {
  307. puts ("\n\t ");
  308. }
  309. }
  310. #ifdef ET_DEBUG
  311. if (TftpState == STATE_RRQ) {
  312. puts ("Server did not acknowledge timeout option!\n");
  313. }
  314. #endif
  315. if (TftpState == STATE_RRQ || TftpState == STATE_OACK) {
  316. /* first block received */
  317. TftpState = STATE_DATA;
  318. TftpServerPort = src;
  319. TftpLastBlock = 0;
  320. TftpBlockWrap = 0;
  321. TftpBlockWrapOffset = 0;
  322. #ifdef CONFIG_MCAST_TFTP
  323. if (Multicast) { /* start!=1 common if mcast */
  324. TftpLastBlock = TftpBlock - 1;
  325. } else
  326. #endif
  327. if (TftpBlock != 1) { /* Assertion */
  328. printf ("\nTFTP error: "
  329. "First block is not block 1 (%ld)\n"
  330. "Starting again\n\n",
  331. TftpBlock);
  332. NetStartAgain ();
  333. break;
  334. }
  335. }
  336. if (TftpBlock == TftpLastBlock) {
  337. /*
  338. * Same block again; ignore it.
  339. */
  340. break;
  341. }
  342. TftpLastBlock = TftpBlock;
  343. TftpTimeoutMSecs = TIMEOUT;
  344. TftpTimeoutCountMax = TIMEOUT_COUNT;
  345. NetSetTimeout (TftpTimeoutMSecs, TftpTimeout);
  346. store_block (TftpBlock - 1, pkt + 2, len);
  347. /*
  348. * Acknoledge the block just received, which will prompt
  349. * the server for the next one.
  350. */
  351. #ifdef CONFIG_MCAST_TFTP
  352. /* if I am the MasterClient, actively calculate what my next
  353. * needed block is; else I'm passive; not ACKING
  354. */
  355. if (Multicast) {
  356. if (len < TftpBlkSize) {
  357. TftpEndingBlock = TftpBlock;
  358. } else if (MasterClient) {
  359. TftpBlock = PrevBitmapHole =
  360. ext2_find_next_zero_bit(
  361. Bitmap,
  362. (Mapsize*8),
  363. PrevBitmapHole);
  364. if (TftpBlock > ((Mapsize*8) - 1)) {
  365. printf ("tftpfile too big\n");
  366. /* try to double it and retry */
  367. Mapsize<<=1;
  368. mcast_cleanup();
  369. NetStartAgain ();
  370. return;
  371. }
  372. TftpLastBlock = TftpBlock;
  373. }
  374. }
  375. #endif
  376. TftpSend ();
  377. #ifdef CONFIG_MCAST_TFTP
  378. if (Multicast) {
  379. if (MasterClient && (TftpBlock >= TftpEndingBlock)) {
  380. puts ("\nMulticast tftp done\n");
  381. mcast_cleanup();
  382. NetState = NETLOOP_SUCCESS;
  383. }
  384. }
  385. else
  386. #endif
  387. if (len < TftpBlkSize) {
  388. /*
  389. * We received the whole thing. Try to
  390. * run it.
  391. */
  392. puts ("\ndone\n");
  393. NetState = NETLOOP_SUCCESS;
  394. }
  395. break;
  396. case TFTP_ERROR:
  397. printf ("\nTFTP error: '%s' (%d)\n",
  398. pkt + 2, ntohs(*(ushort *)pkt));
  399. puts ("Starting again\n\n");
  400. #ifdef CONFIG_MCAST_TFTP
  401. mcast_cleanup();
  402. #endif
  403. NetStartAgain ();
  404. break;
  405. }
  406. }
  407. static void
  408. TftpTimeout (void)
  409. {
  410. if (++TftpTimeoutCount > TftpTimeoutCountMax) {
  411. puts ("\nRetry count exceeded; starting again\n");
  412. #ifdef CONFIG_MCAST_TFTP
  413. mcast_cleanup();
  414. #endif
  415. NetStartAgain ();
  416. } else {
  417. puts ("T ");
  418. NetSetTimeout (TftpTimeoutMSecs, TftpTimeout);
  419. TftpSend ();
  420. }
  421. }
  422. void
  423. TftpStart (void)
  424. {
  425. #ifdef CONFIG_TFTP_PORT
  426. char *ep; /* Environment pointer */
  427. #endif
  428. TftpServerIP = NetServerIP;
  429. if (BootFile[0] == '\0') {
  430. sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
  431. NetOurIP & 0xFF,
  432. (NetOurIP >> 8) & 0xFF,
  433. (NetOurIP >> 16) & 0xFF,
  434. (NetOurIP >> 24) & 0xFF );
  435. strncpy(tftp_filename, default_filename, MAX_LEN);
  436. tftp_filename[MAX_LEN-1] = 0;
  437. printf ("*** Warning: no boot file name; using '%s'\n",
  438. tftp_filename);
  439. } else {
  440. char *p = strchr (BootFile, ':');
  441. if (p == NULL) {
  442. strncpy(tftp_filename, BootFile, MAX_LEN);
  443. tftp_filename[MAX_LEN-1] = 0;
  444. } else {
  445. TftpServerIP = string_to_ip (BootFile);
  446. strncpy(tftp_filename, p + 1, MAX_LEN);
  447. tftp_filename[MAX_LEN-1] = 0;
  448. }
  449. }
  450. #if defined(CONFIG_NET_MULTI)
  451. printf ("Using %s device\n", eth_get_name());
  452. #endif
  453. printf("TFTP from server %pI4"
  454. "; our IP address is %pI4", &TftpServerIP, &NetOurIP);
  455. /* Check if we need to send across this subnet */
  456. if (NetOurGatewayIP && NetOurSubnetMask) {
  457. IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
  458. IPaddr_t ServerNet = TftpServerIP & NetOurSubnetMask;
  459. if (OurNet != ServerNet)
  460. printf("; sending through gateway %pI4", &NetOurGatewayIP);
  461. }
  462. putc ('\n');
  463. printf ("Filename '%s'.", tftp_filename);
  464. if (NetBootFileSize) {
  465. printf (" Size is 0x%x Bytes = ", NetBootFileSize<<9);
  466. print_size (NetBootFileSize<<9, "");
  467. }
  468. putc ('\n');
  469. printf ("Load address: 0x%lx\n", load_addr);
  470. puts ("Loading: *\b");
  471. TftpTimeoutMSecs = TftpRRQTimeoutMSecs;
  472. TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
  473. NetSetTimeout (TftpTimeoutMSecs, TftpTimeout);
  474. NetSetHandler (TftpHandler);
  475. TftpServerPort = WELL_KNOWN_PORT;
  476. TftpTimeoutCount = 0;
  477. TftpState = STATE_RRQ;
  478. /* Use a pseudo-random port unless a specific port is set */
  479. TftpOurPort = 1024 + (get_timer(0) % 3072);
  480. #ifdef CONFIG_TFTP_PORT
  481. if ((ep = getenv("tftpdstp")) != NULL) {
  482. TftpServerPort = simple_strtol(ep, NULL, 10);
  483. }
  484. if ((ep = getenv("tftpsrcp")) != NULL) {
  485. TftpOurPort= simple_strtol(ep, NULL, 10);
  486. }
  487. #endif
  488. TftpBlock = 0;
  489. /* zero out server ether in case the server ip has changed */
  490. memset(NetServerEther, 0, 6);
  491. /* Revert TftpBlkSize to dflt */
  492. TftpBlkSize = TFTP_BLOCK_SIZE;
  493. #ifdef CONFIG_MCAST_TFTP
  494. mcast_cleanup();
  495. #endif
  496. TftpSend ();
  497. }
  498. #ifdef CONFIG_MCAST_TFTP
  499. /* Credits: atftp project.
  500. */
  501. /* pick up BcastAddr, Port, and whether I am [now] the master-client. *
  502. * Frame:
  503. * +-------+-----------+---+-------~~-------+---+
  504. * | opc | multicast | 0 | addr, port, mc | 0 |
  505. * +-------+-----------+---+-------~~-------+---+
  506. * The multicast addr/port becomes what I listen to, and if 'mc' is '1' then
  507. * I am the new master-client so must send ACKs to DataBlocks. If I am not
  508. * master-client, I'm a passive client, gathering what DataBlocks I may and
  509. * making note of which ones I got in my bitmask.
  510. * In theory, I never go from master->passive..
  511. * .. this comes in with pkt already pointing just past opc
  512. */
  513. static void parse_multicast_oack(char *pkt, int len)
  514. {
  515. int i;
  516. IPaddr_t addr;
  517. char *mc_adr, *port, *mc;
  518. mc_adr=port=mc=NULL;
  519. /* march along looking for 'multicast\0', which has to start at least
  520. * 14 bytes back from the end.
  521. */
  522. for (i=0;i<len-14;i++)
  523. if (strcmp (pkt+i,"multicast") == 0)
  524. break;
  525. if (i >= (len-14)) /* non-Multicast OACK, ign. */
  526. return;
  527. i+=10; /* strlen multicast */
  528. mc_adr = pkt+i;
  529. for (;i<len;i++) {
  530. if (*(pkt+i) == ',') {
  531. *(pkt+i) = '\0';
  532. if (port) {
  533. mc = pkt+i+1;
  534. break;
  535. } else {
  536. port = pkt+i+1;
  537. }
  538. }
  539. }
  540. if (!port || !mc_adr || !mc ) return;
  541. if (Multicast && MasterClient) {
  542. printf ("I got a OACK as master Client, WRONG!\n");
  543. return;
  544. }
  545. /* ..I now accept packets destined for this MCAST addr, port */
  546. if (!Multicast) {
  547. if (Bitmap) {
  548. printf ("Internal failure! no mcast.\n");
  549. free(Bitmap);
  550. Bitmap=NULL;
  551. ProhibitMcast=1;
  552. return ;
  553. }
  554. /* I malloc instead of pre-declare; so that if the file ends
  555. * up being too big for this bitmap I can retry
  556. */
  557. if (!(Bitmap = malloc (Mapsize))) {
  558. printf ("No Bitmap, no multicast. Sorry.\n");
  559. ProhibitMcast=1;
  560. return;
  561. }
  562. memset (Bitmap,0,Mapsize);
  563. PrevBitmapHole = 0;
  564. Multicast = 1;
  565. }
  566. addr = string_to_ip(mc_adr);
  567. if (Mcast_addr != addr) {
  568. if (Mcast_addr)
  569. eth_mcast_join(Mcast_addr, 0);
  570. if (eth_mcast_join(Mcast_addr=addr, 1)) {
  571. printf ("Fail to set mcast, revert to TFTP\n");
  572. ProhibitMcast=1;
  573. mcast_cleanup();
  574. NetStartAgain();
  575. }
  576. }
  577. MasterClient = (unsigned char)simple_strtoul((char *)mc,NULL,10);
  578. Mcast_port = (unsigned short)simple_strtoul(port,NULL,10);
  579. printf ("Multicast: %s:%d [%d]\n", mc_adr, Mcast_port, MasterClient);
  580. return;
  581. }
  582. #endif /* Multicast TFTP */
  583. #endif