亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tftp.c

?? MCF523X系列處理器初始化代碼,對開發523X些列freescale處理器有非常重要的意思
?? C
字號:
/*
 * File:		tftp.c
 * Purpose:		Trivial File Transfer Protocol driver for reading a file
 * 				from a remote host.
 *
 * Notes:		See RFC 1350
 *
 * Modifications:
 *
 */

#include "src/init/m523xevb.h"
#include "src/init/stdlib.h"
#include "src/ethernet/nif.h"
#include "src/ethernet/tftp/udp.h"
#include "src/ethernet/tftp/ip.h"
#include "src/ethernet/tftp/timer.h"
#include "src/ethernet/tftp/tftp.h"

/********************************************************************/

/* The one and only TFTP connection */
TFTP_Connection tcxn;

/* Progress Indicators */
char hash[] = {'-','\\','|','/'};
int ihash = 0;

/********************************************************************/
static int
tftp_rwrq (void)
{
	NBUF *pNbuf;
	RWRQ *rwrq;
	int i;

	pNbuf = tcxn.nif->tx_alloc();

	/* Make sure I grabbed a valid Tx buffer */
	if (pNbuf == NULL)
	{
		#if defined(DEBUG_PRINT)
			printf("TFTP: tftp_rwrq() couldn't allocate Tx buffer\n");
		#endif
		return 0;
	}

	rwrq = (RWRQ *)&pNbuf->data[TFTP_HDR_OFFSET];

	/* Indicate a R/WRQ */
	rwrq->opcode = tcxn.dir;

	/* Copy in filename */
	strcpy(&rwrq->filename_mode[0], tcxn.file);
	i = strlen(tcxn.file) + 1;

	/* Indicate transfer type */
	strcpy (&rwrq->filename_mode[i], OCTET);

	pNbuf->length = (uint16)(i + strlen(OCTET) + 1 + 2);

	return udp_send(tcxn.nif,
					tcxn.server_ip,
					tcxn.my_port,
					tcxn.server_port,
					pNbuf);
}

/********************************************************************/
static int
tftp_ack (uint16 blocknum)
{
	ACK *ack;
	NBUF *pNbuf;

	pNbuf = tcxn.nif->tx_alloc();

	/* Make sure I grabbed a valid Tx buffer */
	if (pNbuf == NULL)
	{
		#if defined(DEBUG_PRINT)
			printf("TFTP: tftp_ack() couldn't allocate Tx buffer\n");
		#endif
		return 0;
	}

	ack = (ACK *)&pNbuf->data[TFTP_HDR_OFFSET];
	ack->opcode = TFTP_ACK;
	ack->blocknum = blocknum;

	pNbuf->length = 4;

	return udp_send(tcxn.nif,
					tcxn.server_ip,
					tcxn.my_port,
					tcxn.server_port,
					pNbuf);
}

/********************************************************************/
static int
tftp_error (uint16 error_code, uint16 server_port)
{
	ERROR *err;
	NBUF *pNbuf;

	pNbuf = tcxn.nif->tx_alloc();

	/* Make sure I grabbed a valid Tx buffer */
	if (pNbuf == NULL)
	{
		#if defined(DEBUG_PRINT)
			printf("TFTP: tftp_error() couldn't allocate Tx buffer\n");
		#endif
		return 0;
	}

	err = (ERROR *)&pNbuf->data[TFTP_HDR_OFFSET];
	err->opcode = TFTP_ERROR;
	err->code = error_code;
	err->msg[0] = '\0';

	pNbuf->length = 5;

	return udp_send(tcxn.nif,
					tcxn.server_ip,
					tcxn.my_port,
					server_port,
					pNbuf);
}

/********************************************************************/
void
tftp_handler (NIF *nif, NBUF *pNbuf, int hdr_offset)
{
	union TFTPpacket *tftp_pkt;
	udp_frame_hdr *udpframe;
	static int cnt;
	(void) nif;

	/* Accessing shared memory here, disable interrupts */
	asm_set_ipl(6);

	tftp_pkt = (union TFTPpacket *)&pNbuf->data[hdr_offset];
	udpframe = (udp_frame_hdr *)&pNbuf->data[hdr_offset - UDP_HDR_SIZE];
	
	switch (tftp_pkt->generic.opcode)
	{
		case TFTP_DATA:
			if (tftp_pkt->data.blocknum == tcxn.exp_blocknum)
			{	
				/* This is the block expected */
				if (tftp_pkt->data.blocknum == 1)
				{	/* This is the first data block received */

					/* Save the server's transfer ID */
					tcxn.server_port = UDP_SOURCE(udpframe);

					/* Mark the connection as open */
					tcxn.open = TRUE;

					/* Point to the first character in the buffer */
					tcxn.next_char = tftp_pkt->data.data;

					/* Start progress indicator */
					printf("%c",hash[0]);
					cnt = 0;
				}
				else
				{	/* Check the server's transfer ID */
					if (tcxn.server_port != UDP_SOURCE(udpframe))
					{
						#if defined(DEBUG_PRINT)
							printf("TFTP: Invalid server port: %d\n", \
									UDP_SOURCE(udpframe));
						#endif

						/*Send ERROR packet to source */
						tftp_error(TFTP_ERR_TID, UDP_SOURCE(udpframe));
						break;
					}
				}

				/* Add the payload to my data buffer */
				if (tcxn.pkt_data.bytes == 0)
				{
					pNbuf->length -= 4;

					/* Copy data to buffer */
					memcpy (tcxn.pkt_data.data,
							&pNbuf->data[hdr_offset+4],
							pNbuf->length);
					tcxn.pkt_data.bytes = pNbuf->length;

					/* Update number of the next block expected */
					tcxn.exp_blocknum++;

					/* Increment number of bytes received counter */
					tcxn.bytes_recv += pNbuf->length;

					/* Is this the last packet? */
					if (pNbuf->length < TFTP_PKTSIZE)
					{
						/* Mark the connection as closed */
						tcxn.open = FALSE;

						/* ACK the last packet now */
						tftp_ack(tftp_pkt->data.blocknum);
					}

					/* Update progress indicator */
					if (++cnt == 10)
					{
						ihash = (ihash + 1) % 4;
						printf("\b%c",hash[ihash]);
						cnt = 0;
					}
				}
			}
			else
			{
				#if defined(DEBUG_PRINT)
					/* This is NOT the block expected */
					printf("Exp: %d, ", tcxn.exp_blocknum);
					printf("Rcv: %d\n", tftp_pkt->data.blocknum);
				#endif
			}
			break;
		case TFTP_ERROR:
			printf("\nTFTP Error #%d: ",tftp_pkt->error.code);
			printf("%s\n",tftp_pkt->error.msg);
			tcxn.error = TRUE;
			break;
		case TFTP_RRQ:
			printf("\nTFTP Read Request\n");
			break;
		case TFTP_WRQ:
			printf("\nTFTP Write Request\n");
			break;
		case TFTP_ACK:
			if (tftp_pkt->ack.blocknum == tcxn.exp_blocknum)
			{
				if (tftp_pkt->data.blocknum == 0)
				{	/* This is the first ACK received */

					/* Save the server's transfer ID */
					tcxn.server_port = UDP_SOURCE(udpframe);

					/* Mark the connection as open */
					tcxn.open = TRUE;
				}
				else
				{	/* Check the server's transfer ID */
					if (tcxn.server_port != UDP_SOURCE(udpframe))
					{
						#if defined(DEBUG_PRINT)
							printf("TFTP: Invalid server port: %d\n", \
									UDP_SOURCE(udpframe));
						#endif

						/*Send ERROR packet to source */
						tftp_error(TFTP_ERR_TID, UDP_SOURCE(udpframe));
						break;
					}
				}

				tcxn.exp_blocknum++;
			}
			else
			{
				#if defined(DEBUG_PRINT)
					/* This is NOT the block number expected */
					printf("ACK Exp: %d, ", tcxn.exp_blocknum);
					printf("ACK Rcv: %d\n", tftp_pkt->ack.blocknum);
				#endif
			}
			break;
		default:
			break;
	}

	/* Re-enable interrupts now */
	asm_set_ipl(0);
}

/********************************************************************/
void
tftp_end (int success)
{
	if (success && !tcxn.error)
	{
		printf("\bTFTP download successful\n");
		printf("Read %d bytes (%d blocks)\n",	\
			tcxn.bytes_recv, tcxn.exp_blocknum - 1);
	}
	else
	{
		printf("\bErrors in TFTP download.\n");
		printf("Read %d bytes (%d blocks)\n",	\
			tcxn.bytes_recv, tcxn.exp_blocknum - 1);
	}
    tcxn.nif->stop(tcxn.nif);
	udp_free_port(tcxn.my_port);
}

/********************************************************************/
int
tftp_write (NIF *nif, char *fn, IP_ADDR_P server, uint32 begin, uint32 end)
{
	DATA *data;
	NBUF *pNbuf;

	uint32 i, retries, bytes_to_send;
	uint16 blocknum, this_size;
	uint8 success, *current;

	if (fn == 0 || server == 0 || end < begin)
		return 0;

	/* Setup initial connection status */
	tcxn.nif = nif;
	tcxn.file = fn;
	tcxn.server_ip[0] = server[0];
	tcxn.server_ip[1] = server[1];
	tcxn.server_ip[2] = server[2];
	tcxn.server_ip[3] = server[3];
	tcxn.server_port = UDP_PORT_TFTP;
	tcxn.exp_blocknum = 0;
	tcxn.dir = TFTP_WRQ;
	tcxn.open = FALSE;
	tcxn.bytes_sent = 0;
	tcxn.error = FALSE;

	/* Reset the Ethernet Controller */
	tcxn.nif->reset(tcxn.nif);
	tcxn.nif->start(tcxn.nif);

	/* Use Mac address as pseudo-random port */
	udp_prime_port((uint16)((nif->hwa[4] << 8) | nif->hwa[5]));
	tcxn.my_port = udp_obtain_free_port();
	udp_bind_port(tcxn.my_port,&tftp_handler);

	retries = 4;
	success = FALSE;

	while (--retries)
	{
		/* Make the TFTP Read/Write Request */
		if (!tftp_rwrq())
		{
			tcxn.error = TRUE;
			tftp_end(FALSE);
			return FALSE;
		}
	
		/* Enable interrupts so we can get a packet */
		asm_set_ipl(0);

		timer_set_secs(TIMER_NETWORK, TFTP_TIMEOUT);
		while (timer_get_reference(TIMER_NETWORK))
		{
			/* Has the server responded */
			if (tcxn.open)
			{
				success = TRUE;
				break;
			}
		}

		/* Disable interrupts */
		asm_set_ipl(6);

		/* If the connection is open, we are done here */
		if (success || tcxn.error)
			break;
	}
	if (!retries)
	{
		printf("TFTP could not make connection to server.\n");
	    tcxn.nif->stop(tcxn.nif);
		udp_free_port(tcxn.my_port);
		return FALSE;
	}
	else if (tcxn.error)
	{
		printf("\bErrors in TFTP upload.\n");
	    tcxn.nif->stop(tcxn.nif);
		udp_free_port(tcxn.my_port);
		return FALSE;
	}

	bytes_to_send = end - begin;
	current = (uint8 *)begin;
	blocknum = 1;
	retries = 4;
	success = FALSE;

	while (--retries)
	{
		pNbuf = tcxn.nif->tx_alloc();

		/* Make sure I grabbed a valid Tx buffer */
		if (pNbuf == NULL)
		{
			#if defined(DEBUG_PRINT)
				printf("TFTP: tftp_write() couldn't allocate Tx buffer\n");
			#endif
			return FALSE;
		}

		/* Build the packet */
		data = (DATA *)&pNbuf->data[TFTP_HDR_OFFSET];
		data->blocknum = blocknum;
		data->opcode = TFTP_DATA;
	
		this_size = (bytes_to_send > TFTP_PKTSIZE) ? \
					TFTP_PKTSIZE : (uint16)bytes_to_send;

		for (i = 0; i < this_size; i++)
		{
			data->data[i] = current[i];
		}

		/* Set the packet length */
		pNbuf->length = (uint16)(4 + this_size);

		/* Send the packet */
		udp_send(tcxn.nif, tcxn.server_ip, tcxn.my_port, tcxn.server_port, pNbuf);

		/* Enable interrupts so we can get an ACK */
		asm_set_ipl(0);

		timer_set_secs(TIMER_NETWORK, TFTP_TIMEOUT);
		while (timer_get_reference(TIMER_NETWORK))
		{
			/* Has the server responded */
			if ((tcxn.exp_blocknum - 1) == blocknum)
			{
				success = TRUE;
				break;
			}
		}

		/* Disable interrupts */
		asm_set_ipl(6);

		/* TFTP Write Compeleted successfully */
		if (success && (this_size < TFTP_PKTSIZE))
		{
			tcxn.bytes_sent += this_size;
			break;
		}
			
		if (tcxn.error)
			break;

		/* If an ACK was received, keep sending packets */
		if (success)
		{
			tcxn.bytes_sent += TFTP_PKTSIZE;
			bytes_to_send -= TFTP_PKTSIZE;
			current += TFTP_PKTSIZE;
			blocknum++;
			retries = 4;
			success = FALSE;
		}
	}
	if (tcxn.error)
	{
		printf("TFTP lost connection to server.\n");
		printf("Sent %d bytes (%d blocks)\n",	\
			tcxn.bytes_sent, tcxn.exp_blocknum - 1);
		tcxn.nif->stop(tcxn.nif);
		udp_free_port(tcxn.my_port);
		return FALSE;
	}
	else
	{
		printf("\bTFTP upload successful\n");
		printf("Sent %d bytes (%d blocks)\n",	\
			tcxn.bytes_sent, tcxn.exp_blocknum - 1);
		tcxn.nif->stop(tcxn.nif);
		udp_free_port(tcxn.my_port);
		return TRUE;
	}
}

/********************************************************************/
int
tftp_read (NIF *nif, char *fn, IP_ADDR_P server)
{
	uint32 retries;
	uint8 success;

	/* Disable interrupts */
	asm_set_ipl(6);

	if (fn == 0 || server == 0)
		return 0;

	/* Setup initial connection status */
	tcxn.nif = nif;
	tcxn.file = fn;
	tcxn.server_ip[0] = server[0];
	tcxn.server_ip[1] = server[1];
	tcxn.server_ip[2] = server[2];
	tcxn.server_ip[3] = server[3];
	tcxn.server_port = UDP_PORT_TFTP;
	tcxn.exp_blocknum = 1;
	tcxn.dir = TFTP_RRQ;
	tcxn.open = FALSE;
	tcxn.bytes_recv = 0;
	tcxn.pkt_data.bytes = 0;
	tcxn.error = FALSE;

	/* Reset the Ethernet Controller */
	tcxn.nif->reset(tcxn.nif);
	tcxn.nif->start(tcxn.nif);

	/* Use Mac address as pseudo-random port */
	udp_prime_port((uint16)((nif->hwa[4] << 8) | nif->hwa[5]));
	tcxn.my_port = udp_obtain_free_port();
	udp_bind_port(tcxn.my_port,&tftp_handler);

	retries = 4;
	success = FALSE;

	while (--retries)
	{
		/* Make the TFTP Read/Write Request */
		if (!tftp_rwrq())
		{
			tcxn.error = TRUE;
			tftp_end(FALSE);
			return FALSE;
		}
	
		/* Enable interrupts so we can get a packet */
		asm_set_ipl(0);

		timer_set_secs(TIMER_NETWORK, TFTP_TIMEOUT);
		while (timer_get_reference(TIMER_NETWORK))
		{
			/* Has the server responded */
			if (tcxn.bytes_recv)
			{
				success = TRUE;
				break;
			}
		}

		/* Disable interrupts */
		asm_set_ipl(6);

		/* If the connection is open, we are done here */
		if (success || tcxn.error)
			break;
	}
	if (!retries)
	{
		printf("TFTP could not make connection to server.\n");
		tftp_end(FALSE);
		return FALSE;
	}
	else if (tcxn.error)
	{
		tftp_end(FALSE);
		return FALSE;
	}
	else
	{
		/* Enable interrupts so we can receive more packets */
		asm_set_ipl(0);
		return TRUE;
	}
}

/********************************************************************/
int
tftp_in_char (void)
{
	int retries, success;
	int ch;
	
	/* Accessing shared memory here, disable interrupts */
	asm_set_ipl(6);

	if (tcxn.pkt_data.bytes)
	{	/* The current buffer isn't exhausted yet */
		tcxn.pkt_data.bytes--;
		ch = *tcxn.next_char++;
	}
	else
	{
		/* Make sure the connection is still open */
		if (!tcxn.open)
			return -1;
	
		retries = 6;
		success = FALSE;

		while (--retries)
		{
			/* ACK the last packet received */
			tftp_ack((uint16)(tcxn.exp_blocknum - 1));

			/* Enable interrupts so we can get a packet */
			asm_set_ipl(0);

			timer_set_secs(TIMER_NETWORK, TFTP_TIMEOUT);
			while (timer_get_reference(TIMER_NETWORK))
			{
				/* Has the server sent another DATA packet? */
				if (tcxn.pkt_data.bytes)
				{
					success = TRUE;
					break;
				}
			}

			/* Disable interrupts */
			asm_set_ipl(6);

			if (success)
				break;
		}
		if (!retries)
		{	
			/* Error: Lost connection to server */
			printf("TFTP lost connection to server.\n");
			/* Send error packet to stifle the server */
			tftp_error(TFTP_ERR_ILL, tcxn.server_port);
			tcxn.open = FALSE;
			tcxn.error = TRUE;
			return -1;
		}
		else
		{	/* Server sent more data */
			tcxn.pkt_data.bytes--;
			tcxn.next_char = tcxn.pkt_data.data;
			ch = *tcxn.next_char++;
		}
	}
	/* Enable interrupts so we can receive more packets */
	asm_set_ipl(0);

	return ch;
}

/********************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
激情综合亚洲精品| 国产精品美女久久久久aⅴ| 亚洲第一会所有码转帖| 91成人在线观看喷潮| 亚洲欧美一区二区三区久本道91| 国产1区2区3区精品美女| 国产午夜精品福利| aaa国产一区| 亚洲图片有声小说| 欧美一区二区三区色| 激情丁香综合五月| 国产日韩精品一区二区浪潮av| 国产·精品毛片| 一区二区在线电影| 欧美一区二区播放| 国产suv一区二区三区88区| 日韩一区中文字幕| 337p亚洲精品色噜噜狠狠| 国产在线播放一区三区四| 国产精品黄色在线观看| 欧美日韩dvd在线观看| 久久99精品久久久| 自拍偷在线精品自拍偷无码专区| 欧美色爱综合网| 狠狠色狠狠色综合| 亚洲精品v日韩精品| 精品国产乱码久久久久久免费| 成人精品免费视频| 日韩成人免费电影| 亚洲视频你懂的| 欧美成人三级在线| 99久久国产免费看| 久久精品国产99国产| 18涩涩午夜精品.www| 欧美一区二区女人| 99国内精品久久| 久久国产精品色| 一区二区三区 在线观看视频| 欧美电影免费提供在线观看| 99免费精品视频| 久久国产精品99精品国产| 亚洲人成影院在线观看| 日韩欧美国产小视频| 色999日韩国产欧美一区二区| 精彩视频一区二区| 五月天激情综合| 亚洲欧洲99久久| 精品久久国产字幕高潮| 欧美亚洲综合一区| 99视频在线精品| 国内精品写真在线观看| 亚洲va中文字幕| 亚洲色图一区二区三区| 久久久精品蜜桃| 欧美一级二级三级乱码| 在线免费精品视频| www.一区二区| 国产激情一区二区三区四区 | 免费观看一级特黄欧美大片| 国产精品久久久久毛片软件| 久久蜜桃一区二区| 91精品国产91久久综合桃花| 91福利小视频| av影院午夜一区| 国产98色在线|日韩| 国产一区二区三区观看| 精品一区免费av| 日本亚洲三级在线| 天堂影院一区二区| 亚洲va国产天堂va久久en| 一区二区三区高清不卡| 亚洲免费视频成人| 亚洲精品国产高清久久伦理二区| 中文字幕中文字幕在线一区| 国产清纯白嫩初高生在线观看91| 精品国产露脸精彩对白| 日韩欧美第一区| 欧美成人欧美edvon| 日韩一区二区在线免费观看| 这里是久久伊人| 91精品久久久久久久久99蜜臂| 欧美日韩1区2区| 91精品国产品国语在线不卡| 欧美一级艳片视频免费观看| 欧美一区二区三区在线看| 日韩女优毛片在线| 精品剧情在线观看| 国产丝袜欧美中文另类| 国产午夜精品一区二区三区四区| 国产日韩影视精品| 椎名由奈av一区二区三区| 亚洲美女免费在线| 亚洲综合小说图片| 婷婷开心久久网| 久久疯狂做爰流白浆xx| 国产成a人亚洲| 97久久超碰精品国产| 欧美视频一二三区| 日韩写真欧美这视频| 2020国产精品自拍| 成人欧美一区二区三区| 一区二区三区.www| 极品少妇一区二区| 99re亚洲国产精品| 欧美日韩久久久一区| 欧美成人video| 17c精品麻豆一区二区免费| 午夜精品久久久久久久久久久| 免费观看91视频大全| 国产91精品一区二区麻豆亚洲| 91国模大尺度私拍在线视频| 日韩一区二区三区在线| 中文字幕精品一区| 午夜影视日本亚洲欧洲精品| 国产一区二区三区四区在线观看| 99久久精品免费看国产免费软件| 欧美精选一区二区| 国产欧美日韩综合| 亚洲v精品v日韩v欧美v专区| 国产精品白丝jk黑袜喷水| 在线这里只有精品| 久久久国产午夜精品| 亚洲一区二三区| 国产成人亚洲综合a∨猫咪| 91免费视频观看| 久久久精品日韩欧美| 亚洲香肠在线观看| 从欧美一区二区三区| 91麻豆精品国产91久久久更新时间| 国产日韩综合av| 日韩av电影天堂| 色综合视频在线观看| 久久久久久亚洲综合| 亚欧色一区w666天堂| 成人精品高清在线| 精品欧美一区二区久久| 一二三四区精品视频| 懂色av一区二区三区蜜臀| 欧美一区二区免费观在线| 亚洲毛片av在线| 国产91精品入口| 精品99999| 丝袜国产日韩另类美女| 91在线观看下载| 久久久美女毛片| 蜜乳av一区二区三区| 欧美视频在线播放| 亚洲欧美日韩国产另类专区| 国产成人午夜高潮毛片| 日韩欧美国产电影| 日韩中文字幕av电影| 欧美性做爰猛烈叫床潮| 最新高清无码专区| 国产成人av一区| 亚洲精品在线免费观看视频| 丝袜亚洲另类欧美| 欧美在线免费视屏| 亚洲狼人国产精品| 99久久精品免费看国产免费软件| 国产欧美日韩在线| 国产福利一区在线观看| 久久亚洲精品小早川怜子| 美女一区二区视频| 日韩女优av电影| 奇米精品一区二区三区四区| 欧美精品在线观看一区二区| 亚洲成av人片在线| 欧美少妇bbb| 日日欢夜夜爽一区| 欧美一区二区精品久久911| 日本少妇一区二区| 日韩欧美一级二级| 国内精品在线播放| 国产日韩欧美一区二区三区乱码 | 国模一区二区三区白浆| 欧美大片国产精品| 国精产品一区一区三区mba桃花 | 国产亚洲精品7777| 成人一区二区三区| 一区视频在线播放| 色婷婷av久久久久久久| 一区二区三区色| 欧美日韩视频不卡| 日产精品久久久久久久性色| 日韩一本二本av| 国产成人av电影在线观看| 一色屋精品亚洲香蕉网站| 欧美这里有精品| 日韩电影免费在线看| 亚洲最大成人综合| 欧美福利视频一区| 国产麻豆精品theporn| 国产精品三级av| 欧洲中文字幕精品| 免费一级片91| 欧美激情一区二区三区不卡| 色一区在线观看| 美女国产一区二区三区| 中文字幕乱码久久午夜不卡| 欧美亚一区二区|