Exemple #1
0
/*
 *	Handle a BOOTP received packet.
 */
static void
BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
	     unsigned len)
{
	struct Bootp_t *bp;

	debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
		src, dest, len, sizeof(struct Bootp_t));

	bp = (struct Bootp_t *)pkt;

	/* Filter out pkts we don't want */
	if (BootpCheckPkt(pkt, dest, src, len))
		return;

	/*
	 *	Got a good BOOTP reply.	 Copy the data into our variables.
	 */
#ifdef CONFIG_STATUS_LED
	status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
#endif

	BootpCopyNetParams(bp);		/* Store net parameters from reply */

	/* Retrieve extended information (we must parse the vendor area) */
	if (NetReadLong((uint *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
		BootpVendorProcess((uchar *)&bp->bp_vend[4], len);

	NetSetTimeout(0, (thand_f *)0);
	bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop");

	debug("Got good BOOTP\n");

	net_auto_load();
}
void
RarpRequest (void)
{
	int i;
	volatile uchar *pkt;
	ARP_t *	rarp;

	printf("RARP broadcast %d\n", ++RarpTry);
	pkt = NetTxPacket;

	pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);

	rarp = (ARP_t *)pkt;

	rarp->ar_hrd = htons (ARP_ETHER);
	rarp->ar_pro = htons (PROT_IP);
	rarp->ar_hln = 6;
	rarp->ar_pln = 4;
	rarp->ar_op  = htons (RARPOP_REQUEST);
	memcpy (&rarp->ar_data[0],  NetOurEther, 6);	/* source ET addr */
	memcpy (&rarp->ar_data[6],  &NetOurIP,   4);	/* source IP addr */
	memcpy (&rarp->ar_data[10], NetOurEther, 6);	/* dest ET addr = source ET addr ??*/
	/* dest. IP addr set to broadcast */
	for (i = 0; i <= 3; i++) {
		rarp->ar_data[16 + i] = 0xff;
	}

	NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);

	NetSetTimeout(TIMEOUT, RarpTimeout);
	NetSetHandler(RarpHandler);
}
int
flash_erase(flash_info_t *info, int s_first, int s_last)
{
    int i, sector_size = info->size/info->sector_count;

    printf("\nFirst %#x last %#x sector size %#x\n",
           s_first, s_last, sector_size);

#if (defined(CONFIG_WNDR3700U_LED) || defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(FIRMWARE_RECOVER_FROM_TFTP_SERVER)
    NetSetTimeout (CFG_HZ/10,Update_LedSet);
#endif
    for (i = s_first; i <= s_last; i++) {
        printf("\b\b\b\b%4d", i);
#if (defined(CONFIG_WNDR3700U_LED) || defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(FIRMWARE_RECOVER_FROM_TFTP_SERVER)
        if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) {
            thand_f *x;
            x = timeHandler;
            timeHandler = (thand_f *)0;
            (*x)();
        }
#endif
        ar7100_spi_sector_erase(i * sector_size);
    }
    ar7100_spi_done();
    printf("\n");

    return 0;
}
void ping_start(void)
{
	printf("Using %s device\n", eth_get_name());
	NetSetTimeout(10000UL, ping_timeout);

	ping_send();
}
Exemple #5
0
int BootMeRequest(IPaddr_t server_ip, const void *buf, size_t len, int timeout)
{
	bootme_init(server_ip);
	bootme_timeout = timeout * 1000;
	bootme_timed_out = 0;
	NetSetTimeout(bootme_timeout, bootme_timeout_handler);
	return bootme_send_frame(buf, len);
}
Exemple #6
0
/*
 *	Timeout on BOOTP/DHCP request.
 */
static void BootpTimeout(void){
	if(BootpTry >= TIMEOUT_COUNT){
		puts("\n## Error: retry count exceeded, starting again!\n\n");
		NetStartAgain();
	} else {
		NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout);
		BootpRequest();
	}
}
Exemple #7
0
void
TftpStart (void)
{
	struct timestamp now;
	time_get(&now);

#ifdef ET_DEBUG
	printf ("\nServer ethernet address %02x:%02x:%02x:%02x:%02x:%02x\n",
		NetServerEther[0],
		NetServerEther[1],
		NetServerEther[2],
		NetServerEther[3],
		NetServerEther[4],
		NetServerEther[5]
	);
#endif /* DEBUG */

	printf ("TFTP from server %s", inet_ntoa(NetServerIP));
	printf ("; our IP address is %s", inet_ntoa(NetOurIP));


	// Check if we need to send across this subnet
	if (NetOurGatewayIP && NetOurSubnetMask) {
	    IPaddr_t OurNet 	= NetOurIP    & NetOurSubnetMask;
	    IPaddr_t ServerNet 	= NetServerIP & NetOurSubnetMask;

	    if (OurNet != ServerNet) {
		printf ("; sending through gateway ");
		print_IPaddr (NetOurGatewayIP) ;
	    }
	}
	printf("\n");

	printf ("Filename '%s'.", tftp_filename);

	if (NetBootFileSize) {
	    printf (" Size is %d%s kB => %x Bytes", NetBootFileSize/2, (NetBootFileSize%2) ? ".5" : "",	NetBootFileSize<<9);
	}

	printf("\n");

	printf ("Load address: 0x%lx\n\n", get_board_desc()->memctrl_membase);
	printf ("Press Ctrl-C to abort...\n");
	printf ("Loading: *\b");


	NetSetTimeout (TIMEOUT * 1000, TftpTimeout);
	NetSetHandler (TftpHandler);

	TftpServerPort = WELL_KNOWN_PORT;
	TftpTimeoutCount = 0;
	TftpState = STATE_RRQ;
	TftpOurPort = 1024 + (now.usec % 3072); //FIXED

	TftpSend ();
}
Exemple #8
0
void
DnsStart(void)
{
	debug("%s\n", __func__);

	NetSetTimeout(DNS_TIMEOUT, DnsTimeout);
	NetSetHandler(DnsHandler);

	DnsSend();
}
Exemple #9
0
/*
 *	Timeout on BOOTP/DHCP request.
 */
static void
BootpTimeout(void)
{
	if (BootpTry >= TIMEOUT_COUNT) {
		puts ("\nRetry count exceeded; starting again\n");
		NetStartAgain ();
	} else {
		NetSetTimeout (TIMEOUT, BootpTimeout);
		BootpRequest ();
	}
}
Exemple #10
0
void
SntpStart (void)
{
	debug ("%s\n", __FUNCTION__);

	NetSetTimeout (SNTP_TIMEOUT, SntpTimeout);
	NetSetHandler(SntpHandler);
	memset (NetServerEther, 0, 6);

	SntpSend ();
}
Exemple #11
0
/*
 *	Handle a BOOTP received packet.
 */
static void
BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
{
	Bootp_t *bp;
	char	*s;

	debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
		src, dest, len, sizeof (Bootp_t));

	bp = (Bootp_t *)pkt;

	if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
		return;

	/*
	 *	Got a good BOOTP reply.	 Copy the data into our variables.
	 */
#ifdef CONFIG_STATUS_LED
	status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
#endif

	BootpCopyNetParams(bp);		/* Store net parameters from reply */

	/* Retrieve extended information (we must parse the vendor area) */
	if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
		BootpVendorProcess((uchar *)&bp->bp_vend[4], len);

	NetSetTimeout(0, (thand_f *)0);

	debug("Got good BOOTP\n");

	if ((s = getenv("autoload")) != NULL) {
		if (*s == 'n') {
			/*
			 * Just use BOOTP to configure system;
			 * Do not use TFTP to load the bootfile.
			 */
			NetState = NETLOOP_SUCCESS;
			return;
#if defined(CONFIG_CMD_NFS)
		} else if (strcmp(s, "NFS") == 0) {
			/*
			 * Use NFS to load the bootfile.
			 */
			NfsStart();
			return;
#endif
		}
	}

	struct NetTask tftp_task;
	BootpDeriveTaskTftp(&tftp_task, bp);
	TftpStart(&tftp_task);
}
Exemple #12
0
static void TftpTimeout (void)
{
	if (++TftpTimeoutCount >= TIMEOUT_COUNT) {
		printf ("\nRetry count exceeded; starting again\n");
		NetStartAgain ();
	} else {
		printf ("T ");
		NetSetTimeout (TIMEOUT * 1000, TftpTimeout);
		TftpSend ();
	}
}
Exemple #13
0
/*
 *	Timeout on BOOTP request.
 */
static void
RarpTimeout(void)
{
	if (RarpTry >= TIMEOUT_COUNT) {
		puts ("\nRetry count exceeded; starting again\n");
		NetStartAgain ();
	} else {
		NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout);
		RarpRequest ();
	}
}
Exemple #14
0
void SntpStart(void){
#ifdef DEBUG
	printf("%s\n", __FUNCTION__);
#endif

	NetSetTimeout(SNTP_TIMEOUT * CFG_HZ, SntpTimeout);
	NetSetHandler(SntpHandler);

	memset(NetServerEther, 0, 6);

	SntpSend();
}
Exemple #15
0
static void
TftpTimeout(void)
{
	if (++TftpTimeoutCount > TftpTimeoutCountMax) {
		restart("Retry count exceeded");
	} else {
		puts("T ");
		NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
		if (TftpState != STATE_RECV_WRQ)
			TftpSend();
	}
}
Exemple #16
0
static void
NfsTimeout (void)
{
	if ( ++NfsTimeoutCount > NFS_RETRY_COUNT ) {
		puts ("\nRetry count exceeded; starting again\n");
		NetStartAgain ();
	} else {
		puts("T ");
		NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
		NfsSend ();
	}
}
static void _tftpd_open()
{
	NetSetTimeout(TIMEOUT * CFG_HZ * 2, TftpdTimeout);
    	NetSetHandler(TftpHandler);
	
	TftpOurPort = PORT_TFTP;
	TftpTimeoutCount = 0;
	TftpState = STATE_RRQ;
	TftpBlock = 0;
	
	/* zero out server ether in case the server ip has changed */
	memset(NetServerEther, 0, 6);
}
Exemple #18
0
void NcStart (void)
{
	if (!output_packet_len || memcmp (nc_ether, NetEtherNullAddr, 6)) {
		/* going to check for input packet */
		NetSetHandler (nc_handler);
		NetSetTimeout (net_timeout, nc_timeout);
	} else {
		/* send arp request */
		uchar *pkt;
		NetSetHandler (nc_wait_arp_handler);
		pkt = (uchar *) NetTxPacket + NetEthHdrSize () + IP_HDR_SIZE;
		memcpy (pkt, output_packet, output_packet_len);
		NetSendUDPPacket (nc_ether, nc_ip, nc_port, nc_port, output_packet_len);
	}
}
Exemple #19
0
/*
 *	Timeout on BOOTP/DHCP request.
 */
static void
BootpTimeout(void)
{
	if (BootpTry >= TIMEOUT_COUNT) {
#ifdef CONFIG_BOOTP_MAY_FAIL
		puts("\nRetry count exceeded\n");
		NetSetState(NETLOOP_FAIL);
#else
		puts("\nRetry count exceeded; starting again\n");
		NetStartAgain();
#endif
	} else {
		NetSetTimeout(TIMEOUT, BootpTimeout);
		BootpRequest();
	}
}
Exemple #20
0
static void configure_wait(void)
{
	if (timeout_ms == -1)
		return;

	/* poll, being ready to adjust current timeout */
	if (!timeout_ms)
		timeout_ms = random_delay_ms(PROBE_WAIT);

	/* set deadline_ms to the point in time when we timeout */
	deadline_ms = MONOTONIC_MS() + timeout_ms;

	debug_cond(DEBUG_DEV_PKT, "...wait %d %s nprobes=%u, nclaims=%u\n",
			timeout_ms, eth_get_name(), nprobes, nclaims);

	NetSetTimeout(timeout_ms, link_local_timeout);
}
Exemple #21
0
int BootMeDebugStart(bootme_hand_f *handler)
{
	int ret;

	bootme_packet_handler = handler;

	bootme_init(bootme_ip);
	bootme_state = BOOTME_DEBUG;
	bootme_timeout = 3 * 1000;
	NetSetTimeout(bootme_timeout, bootme_timeout_handler);

	ret = NetLoop(BOOTME);
	if (ret < 0)
		return BOOTME_ERROR;
	if (bootme_timed_out)
		return BOOTME_DONE;
	return bootme_state;
}
Exemple #22
0
void NetStartAgain(void)
{
	char *nretry;
	int retry_forever = 0;
	unsigned long retrycnt = 0;

	nretry = getenv("netretry");
	if (nretry) {
		if (!strcmp(nretry, "yes"))
			retry_forever = 1;
		else if (!strcmp(nretry, "no"))
			retrycnt = 0;
		else if (!strcmp(nretry, "once"))
			retrycnt = 1;
		else
			retrycnt = simple_strtoul(nretry, NULL, 0);
	} else
		retry_forever = 1;

	if ((!retry_forever) && (NetTryCount >= retrycnt)) {
		eth_halt();
		net_set_state(NETLOOP_FAIL);
		return;
	}

	NetTryCount++;

	eth_halt();
#if !defined(CONFIG_NET_DO_NOT_TRY_ANOTHER)
	eth_try_another(!NetRestarted);
#endif
	eth_init(gd->bd);
	if (NetRestartWrap) {
		NetRestartWrap = 0;
		if (NetDevExists) {
			NetSetTimeout(10000UL, startAgainTimeout);
			net_set_udp_handler(NULL);
		} else {
			net_set_state(NETLOOP_FAIL);
		}
	} else {
		net_set_state(NETLOOP_RESTART);
	}
}
Exemple #23
0
/*
 *	Timeout on BOOTP/DHCP request.
 */
static void
BootpTimeout(void)
{
	ulong time_taken = get_timer(bootp_start);

	if (time_taken >= TIMEOUT_MS) {
#ifdef CONFIG_BOOTP_MAY_FAIL
		puts("\nRetry time exceeded\n");
		net_set_state(NETLOOP_FAIL);
#else
		puts("\nRetry time exceeded; starting again\n");
		NetStartAgain();
#endif
	} else {
		bootp_timeout *= 2;
		if (bootp_timeout > 2000)
			bootp_timeout = 2000;
		NetSetTimeout(bootp_timeout, BootpTimeout);
		BootpRequest();
	}
}
Exemple #24
0
void BootmeStart(void)
{
	if (bootme_state != BOOTME_DOWNLOAD)
		check_net_config();

	if (output_packet_len == 0 ||
		memcmp(bootme_ether, NetEtherNullAddr, ETH_ALEN) != 0) {
		/* wait for incoming packet */
		net_set_udp_handler(bootme_handler);
		bootme_timed_out = 0;
		NetSetTimeout(bootme_timeout, bootme_timeout_handler);
	} else {
		/* send ARP request */
		uchar *pkt;

		net_set_arp_handler(bootme_wait_arp_handler);
		assert(NetTxPacket != NULL);
		pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
		memcpy(pkt, output_packet, output_packet_len);
		NetSendUDPPacket(bootme_ether, bootme_ip, bootme_dst_port,
				bootme_src_port, output_packet_len);
	}
}
Exemple #25
0
int network_update( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
{
	int i;
	setup_pkt_recvd=0;
	NetSetTimeout(TIMEOUT * CFG_HZ, NbootTimeout);
	NetSetHandler(NBootHandler);
	
	dm9k_phy_retry_times=1000;
	eth_init(gd->bd);
	eth_rx();
	if (setup_pkt_recvd)
	{

		front_puts("TFTP");
		if (NetLoop (TFTP) <= 0)
			return 1;
			
		front_puts("BURN");
		burn_flash_img( 0, 0, 0, 0);
		do_reset (NULL, 0, 0, NULL);
	}
	return 0;
}
Exemple #26
0
static void
TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
	    unsigned len)
{
	__be16 proto;
	__be16 *s;
	int i;

	if (dest != TftpOurPort) {
#ifdef CONFIG_MCAST_TFTP
		if (Multicast
		 && (!Mcast_port || (dest != Mcast_port)))
#endif
			return;
	}
	if (TftpState != STATE_SEND_RRQ && src != TftpRemotePort &&
	    TftpState != STATE_RECV_WRQ && TftpState != STATE_SEND_WRQ)
		return;

	if (len < 2)
		return;
	len -= 2;
	/* warning: don't use increment (++) in ntohs() macros!! */
	s = (__be16 *)pkt;
	proto = *s++;
	pkt = (uchar *)s;
	switch (ntohs(proto)) {

	case TFTP_RRQ:
		break;

	case TFTP_ACK:
#ifdef CONFIG_CMD_TFTPPUT
		if (TftpWriting) {
			if (TftpFinalBlock) {
				tftp_complete();
			} else {
				/*
				 * Move to the next block. We want our block
				 * count to wrap just like the other end!
				 */
				int block = ntohs(*s);
				int ack_ok = (TftpBlock == block);

				TftpBlock = (unsigned short)(block + 1);
				update_block_number();
				if (ack_ok)
					TftpSend(); /* Send next data block */
			}
		}
#endif
		break;

	default:
		break;

#ifdef CONFIG_CMD_TFTPSRV
	case TFTP_WRQ:
		debug("Got WRQ\n");
		TftpRemoteIP = sip;
		TftpRemotePort = src;
		TftpOurPort = 1024 + (get_timer(0) % 3072);
		new_transfer();
		TftpSend(); /* Send ACK(0) */
		break;
#endif

	case TFTP_OACK:
		debug("Got OACK: %s %s\n",
			pkt,
			pkt + strlen((char *)pkt) + 1);
		TftpState = STATE_OACK;
		TftpRemotePort = src;
		/*
		 * Check for 'blksize' option.
		 * Careful: "i" is signed, "len" is unsigned, thus
		 * something like "len-8" may give a *huge* number
		 */
		for (i = 0; i+8 < len; i++) {
			if (strcmp((char *)pkt+i, "blksize") == 0) {
				TftpBlkSize = (unsigned short)
					simple_strtoul((char *)pkt+i+8, NULL,
						       10);
				debug("Blocksize ack: %s, %d\n",
					(char *)pkt+i+8, TftpBlkSize);
			}
#ifdef CONFIG_TFTP_TSIZE
			if (strcmp((char *)pkt+i, "tsize") == 0) {
				TftpTsize = simple_strtoul((char *)pkt+i+6,
							   NULL, 10);
				debug("size = %s, %d\n",
					 (char *)pkt+i+6, TftpTsize);
			}
#endif
		}
#ifdef CONFIG_MCAST_TFTP
		parse_multicast_oack((char *)pkt, len-1);
		if ((Multicast) && (!MasterClient))
			TftpState = STATE_DATA;	/* passive.. */
		else
#endif
#ifdef CONFIG_CMD_TFTPPUT
		if (TftpWriting) {
			/* Get ready to send the first block */
			TftpState = STATE_DATA;
			TftpBlock++;
		}
#endif
		TftpSend(); /* Send ACK or first data block */
		break;
	case TFTP_DATA:
		if (len < 2)
			return;
		len -= 2;
		TftpBlock = ntohs(*(__be16 *)pkt);

		update_block_number();

		if (TftpState == STATE_SEND_RRQ)
			debug("Server did not acknowledge timeout option!\n");

		if (TftpState == STATE_SEND_RRQ || TftpState == STATE_OACK ||
		    TftpState == STATE_RECV_WRQ) {
			/* first block received */
			TftpState = STATE_DATA;
			TftpRemotePort = src;
			new_transfer();

#ifdef CONFIG_MCAST_TFTP
			if (Multicast) { /* start!=1 common if mcast */
				TftpLastBlock = TftpBlock - 1;
			} else
#endif
			if (TftpBlock != 1) {	/* Assertion */
				printf("\nTFTP error: "
				       "First block is not block 1 (%ld)\n"
				       "Starting again\n\n",
					TftpBlock);
				NetStartAgain();
				break;
			}
		}

		if (TftpBlock == TftpLastBlock) {
			/*
			 *	Same block again; ignore it.
			 */
			break;
		}

		TftpLastBlock = TftpBlock;
		TftpTimeoutCountMax = TIMEOUT_COUNT;
		NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);

		store_block(TftpBlock - 1, pkt + 2, len);

		/*
		 *	Acknowledge the block just received, which will prompt
		 *	the remote for the next one.
		 */
#ifdef CONFIG_MCAST_TFTP
		/* if I am the MasterClient, actively calculate what my next
		 * needed block is; else I'm passive; not ACKING
		 */
		if (Multicast) {
			if (len < TftpBlkSize)  {
				TftpEndingBlock = TftpBlock;
			} else if (MasterClient) {
				TftpBlock = PrevBitmapHole =
					ext2_find_next_zero_bit(
						Bitmap,
						(Mapsize*8),
						PrevBitmapHole);
				if (TftpBlock > ((Mapsize*8) - 1)) {
					printf("tftpfile too big\n");
					/* try to double it and retry */
					Mapsize <<= 1;
					mcast_cleanup();
					NetStartAgain();
					return;
				}
				TftpLastBlock = TftpBlock;
			}
		}
#endif
		TftpSend();

#ifdef CONFIG_MCAST_TFTP
		if (Multicast) {
			if (MasterClient && (TftpBlock >= TftpEndingBlock)) {
				puts("\nMulticast tftp done\n");
				mcast_cleanup();
				net_set_state(NETLOOP_SUCCESS);
			}
		} else
#endif
		if (len < TftpBlkSize)
			tftp_complete();
		break;

	case TFTP_ERROR:
		printf("\nTFTP error: '%s' (%d)\n",
		       pkt + 2, ntohs(*(__be16 *)pkt));

		switch (ntohs(*(__be16 *)pkt)) {
		case TFTP_ERR_FILE_NOT_FOUND:
		case TFTP_ERR_ACCESS_DENIED:
			puts("Not retrying...\n");
			eth_halt();
			net_set_state(NETLOOP_FAIL);
			break;
		case TFTP_ERR_UNDEFINED:
		case TFTP_ERR_DISK_FULL:
		case TFTP_ERR_UNEXPECTED_OPCODE:
		case TFTP_ERR_UNKNOWN_TRANSFER_ID:
		case TFTP_ERR_FILE_ALREADY_EXISTS:
		default:
			puts("Starting again\n\n");
#ifdef CONFIG_MCAST_TFTP
			mcast_cleanup();
#endif
			NetStartAgain();
			break;
		}
		break;
	}
}
Exemple #27
0
static void
NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
{
	int rlen;

	debug("%s\n", __func__);

	if (dest != NfsOurPort) return;

	switch (NfsState) {
	case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
		rpc_lookup_reply (PROG_MOUNT, pkt, len);
		NfsState = STATE_PRCLOOKUP_PROG_NFS_REQ;
		NfsSend ();
		break;

	case STATE_PRCLOOKUP_PROG_NFS_REQ:
		rpc_lookup_reply (PROG_NFS, pkt, len);
		NfsState = STATE_MOUNT_REQ;
		NfsSend ();
		break;

	case STATE_MOUNT_REQ:
		if (nfs_mount_reply(pkt, len)) {
			puts ("*** ERROR: Cannot mount\n");
			/* just to be sure... */
			NfsState = STATE_UMOUNT_REQ;
			NfsSend ();
		} else {
			NfsState = STATE_LOOKUP_REQ;
			NfsSend ();
		}
		break;

	case STATE_UMOUNT_REQ:
		if (nfs_umountall_reply(pkt, len)) {
			puts ("*** ERROR: Cannot umount\n");
			NetState = NETLOOP_FAIL;
		} else {
			puts ("\ndone\n");
			NetState = NfsDownloadState;
		}
		break;

	case STATE_LOOKUP_REQ:
		if (nfs_lookup_reply(pkt, len)) {
			puts ("*** ERROR: File lookup fail\n");
			NfsState = STATE_UMOUNT_REQ;
			NfsSend ();
		} else {
			NfsState = STATE_READ_REQ;
			nfs_offset = 0;
			nfs_len = NFS_READ_SIZE;
			NfsSend ();
		}
		break;

	case STATE_READLINK_REQ:
		if (nfs_readlink_reply(pkt, len)) {
			puts ("*** ERROR: Symlink fail\n");
			NfsState = STATE_UMOUNT_REQ;
			NfsSend ();
		} else {
			debug("Symlink --> %s\n", nfs_path);
			nfs_filename = basename (nfs_path);
			nfs_path     = dirname (nfs_path);

			NfsState = STATE_MOUNT_REQ;
			NfsSend ();
		}
		break;

	case STATE_READ_REQ:
		rlen = nfs_read_reply (pkt, len);
		NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
		if (rlen > 0) {
			nfs_offset += rlen;
			NfsSend ();
		}
		else if ((rlen == -NFSERR_ISDIR)||(rlen == -NFSERR_INVAL)) {
			/* symbolic link */
			NfsState = STATE_READLINK_REQ;
			NfsSend ();
		} else {
			if ( ! rlen ) NfsDownloadState = NETLOOP_SUCCESS;
			NfsState = STATE_UMOUNT_REQ;
			NfsSend ();
		}
		break;
	}
}
Exemple #28
0
static void bootme_handler(uchar *pkt, unsigned dest_port, IPaddr_t src_ip,
			unsigned src_port, unsigned len)
{
	uchar *eth_pkt = pkt;
	unsigned eth_len = len;
	static char cursor = '|';
	enum bootme_state last_state = BOOTME_INIT;
#if 1
	debug("received packet of len %d from %pI4:%d to port %d\n",
		len, &src_ip, src_port, dest_port);
	ce_dump_block(pkt, len);
#endif
	if (!bootme_packet_handler) {
		printf("No packet handler set for BOOTME protocol; dropping packet\n");
		return;
	}
	if (dest_port != bootme_src_port || !len)
		return; /* not for us */

	printf("%c\x08", cursor);
	cursor = next_cursor(cursor);

	if (is_broadcast(bootme_ip)) {
		bootme_ip = src_ip;
	} else if (src_ip != bootme_ip) {
		debug("src_ip %pI4 does not match destination IP %pI4\n",
			&src_ip, &bootme_ip);
		return; /* not from our server */
	}

	last_state = bootme_state;
	bootme_dst_port = src_port;
	debug("bootme_dst_port set to %d\n", bootme_dst_port);
	if (bootme_state == BOOTME_INIT) {
		bootme_src_port = EDBG_SVC_PORT;
		debug("%s: bootme_src_port set to %d\n", __func__, bootme_src_port);
	}
	bootme_state = bootme_packet_handler(eth_pkt, eth_len);
	debug("bootme_packet_handler() returned %d\n", bootme_state);
	if (bootme_state != last_state)
		debug("bootme_state: %d -> %d\n", last_state, bootme_state);
	switch (bootme_state) {
	case BOOTME_INIT:
		break;

	case BOOTME_DOWNLOAD:
		if (last_state != BOOTME_INIT)
			NetBootFileXferSize += len - 4;
		/* fallthru */
	case BOOTME_DEBUG:
		if (last_state == BOOTME_INIT) {
			bootme_timeout = 3 * 1000;
		}
		NetSetTimeout(bootme_timeout, bootme_timeout_handler);
		break;

	case BOOTME_DONE:
		net_set_state(NETLOOP_SUCCESS);
		bootme_packet_handler = NULL;
		break;

	case BOOTME_ERROR:
		net_set_state(NETLOOP_FAIL);
		bootme_packet_handler = NULL;
	}
}
static void TftpdTimeout(void)
{
	puts("D ");
	NetSetTimeout(TIMEOUT * CFG_HZ, TftpdTimeout);
}
Exemple #30
0
static void link_local_timeout(void)
{
	switch (state) {
	case PROBE:
		/* timeouts in the PROBE state mean no conflicting ARP packets
		   have been received, so we can progress through the states */
		if (nprobes < PROBE_NUM) {
			nprobes++;
			debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n",
					nprobes, eth_get_name(), &ip);
			arp_raw_request(0, NetEtherNullAddr, ip);
			timeout_ms = PROBE_MIN * 1000;
			timeout_ms += random_delay_ms(PROBE_MAX - PROBE_MIN);
		} else {
			/* Switch to announce state */
			state = ANNOUNCE;
			nclaims = 0;
			debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
					nclaims, eth_get_name(), &ip);
			arp_raw_request(ip, NetOurEther, ip);
			timeout_ms = ANNOUNCE_INTERVAL * 1000;
		}
		break;
	case RATE_LIMIT_PROBE:
		/* timeouts in the RATE_LIMIT_PROBE state mean no conflicting
		   ARP packets have been received, so we can move immediately
		   to the announce state */
		state = ANNOUNCE;
		nclaims = 0;
		debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
				nclaims, eth_get_name(), &ip);
		arp_raw_request(ip, NetOurEther, ip);
		timeout_ms = ANNOUNCE_INTERVAL * 1000;
		break;
	case ANNOUNCE:
		/* timeouts in the ANNOUNCE state mean no conflicting ARP
		   packets have been received, so we can progress through
		   the states */
		if (nclaims < ANNOUNCE_NUM) {
			nclaims++;
			debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
					nclaims, eth_get_name(), &ip);
			arp_raw_request(ip, NetOurEther, ip);
			timeout_ms = ANNOUNCE_INTERVAL * 1000;
		} else {
			/* Switch to monitor state */
			state = MONITOR;
			printf("Successfully assigned %pI4\n", &ip);
			NetCopyIP(&NetOurIP, &ip);
			ready = 1;
			conflicts = 0;
			timeout_ms = -1;
			/* Never timeout in the monitor state */
			NetSetTimeout(0, NULL);

			/* NOTE: all other exit paths should deconfig ... */
			net_set_state(NETLOOP_SUCCESS);
			return;
		}
		break;
	case DEFEND:
		/* We won!  No ARP replies, so just go back to monitor */
		state = MONITOR;
		timeout_ms = -1;
		conflicts = 0;
		break;
	default:
		/* Invalid, should never happen.  Restart the whole protocol */
		state = PROBE;
		ip = pick();
		timeout_ms = 0;
		nprobes = 0;
		nclaims = 0;
		break;
	}
	configure_wait();
}