Esempio n. 1
0
static void TftpTimeout(void)
{
	puts("T ");
	NetSetTimeout(TIMEOUT * CFG_HZ, TftpTimeout);
	TftpdSend();
}
Esempio n. 2
0
static void TftpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
{
	ushort proto;
	int i;
	static int ledcount=0,ledstate=1;
	
	if (dest != TftpOurPort) 
	{
		return;
	}
	/* don't care the packets that donot send to TFTP port */
	
	if (TftpState != STATE_RRQ && src != TftpServerPort)
	{
		return;
	}
	
	if (len < 2)
	{
		return;
	}
	

	#if 0
	if (0==ledcount%64)/*the led flicker when packet received*/
		{
			ledstate+=1;
			ledstate%=2;
		}
	if(0==ledstate%2)
		LEDON(11);
	else
		LEDOFF(11);
	++ledcount;
	if (0xffffff==i)
		i=0;
	#endif
	len -= 2;
	/* warning: don't use increment (++) in ntohs() macros!! */
	proto = *((ushort *)pkt)++;
	
	switch (ntohs(proto))
	{
	case TFTP_RRQ:

		printf("\n Get read request from:(");
		print_IPaddr(TempServerIP);
		printf(")\n");
		NetCopyIP(&NetServerIP,&TempServerIP);
		TftpServerPort = src;
		TftpBlock = 1;
		TftpBlockWrapOffset = 0;		
		TftpState = STATE_RRQ;
		
		for (i=0; i<13; i++) 
		{
			if (*((uint8_t *)pkt)++ != asuslink[i])
				break;
		}
		if (i==13) 
		{ /* it's the firmware transmitting situation */
			/* here get the IP address from the first packet. */
			NetOurIP = (*((uint8_t *)pkt)++) & 0x000000ff;
			NetOurIP<<=8;
			NetOurIP|= (*((uint8_t *)pkt)++) & 0x000000ff;
			NetOurIP<<=8;
			NetOurIP|= (*((uint8_t *)pkt)++) & 0x000000ff;
			NetOurIP<<=8;
			NetOurIP|= (*((uint8_t *)pkt)++) & 0x000000ff;
		}
		else
		{
			for (i=0; i<13; i++)
			{
				if (*((uint8_t *)pkt)++ != maclink[i])
					break;
			}
			if(i==13)
			{
				/* here get the IP address from the first packet. */
				NetOurIP = (*((uint8_t *)pkt)++)& 0x000000ff;
				NetOurIP<<=8;
				NetOurIP|=(*((uint8_t *)pkt)++)& 0x000000ff;
				NetOurIP<<=8;
				NetOurIP|=(*((uint8_t *)pkt)++)& 0x000000ff;
				NetOurIP<<=8;
				NetOurIP|=(*((uint8_t *)pkt)++)& 0x000000ff;
			}
		}
		
		TftpdSend();//send a vacant Data packet as a ACK
		break;
		
	case TFTP_WRQ:
		TftpServerPort = src;
		TftpBlock = 0;
		TftpState = STATE_WRQ;
		TftpdSend();
		break;
		
	case TFTP_DATA:
		if (len < 2)
			return;
		len -= 2;
		TftpBlock = ntohs(*(ushort *)pkt);
		/*
		* RFC1350 specifies that the first data packet will
		* have sequence number 1. If we receive a sequence
		* number of 0 this means that there was a wrap
		* around of the (16 bit) counter.
		*/
		if (TftpBlock == 0)
		{
			printf("\n\t %lu MB reveived\n\t ", TftpBlockWrapOffset>>20);
		} 
		else 
		{
			if (((TftpBlock - 1) % 10) == 0) 
static void TftpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
{
	ushort proto;
	int i;

	if (dest != TftpOurPort)
	{
		return;
	}
	/* don't care the packets that donot send to TFTP port */

	if (TftpState != STATE_RRQ && src != TftpServerPort)
	{
		return;
	}

	if (len < 2)
	{
		return;
	}

	len -= 2;
	/* warning: don't use increment (++) in ntohs() macros!! */
	proto = *((ushort *)pkt)++;

	switch (ntohs(proto))
	{
	case TFTP_RRQ:

		printf("\n Get read request from:(");
		print_IPaddr(TempServerIP);
		printf(")\n");
		NetCopyIP(&NetServerIP,&TempServerIP);
		TftpServerPort = src;
		TftpBlock = 1;
		TftpBlockWrapOffset = 0;
		TftpState = STATE_RRQ;
		TftpdSend();//send a vacant Data packet as a ACK
		break;

	case TFTP_WRQ:
		TftpServerPort = src;
		TftpBlock = 0;
		TftpState = STATE_WRQ;
		TftpdSend();
		break;

	case TFTP_DATA:
		if (len < 2)
			return;
		len -= 2;
		TftpBlock = ntohs(*(ushort *)pkt);
		/*
		* RFC1350 specifies that the first data packet will
		* have sequence number 1. If we receive a sequence
		* number of 0 this means that there was a wrap
		* around of the (16 bit) counter.
		*/
		if (TftpBlock == 0)
		{
			printf("\n\t %lu MB reveived\n\t ", TftpBlockWrapOffset>>20);
		}
		else
		{
			if (((TftpBlock - 1) % 10) == 0)