⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tftpmain.c

📁 s3c44b0x上实现的ucos+tftp
💻 C
字号:
#include "skbuff.h"
#include "eth.h"
#include "arp.h"
#include "ip.h"
#include "udp.h"
#include "utils.h"
#include "DataType.h"
#include "44B.h"
#include "os_cpu.h"

int DownLoadEnd;
int DownLoadOnly;
int arp_count=0;
unsigned long LoadLength;	
unsigned long load_addr = 0x8000;
struct sk_buff *skb_g;
struct sk_buff *skb_g_check;
extern int SemGet;
extern int total_packet;
extern int rd_p;
extern int wr_p;
extern void Uart_Printf(char *fmt,...);
extern struct sk_buff skbuff[50];
//extern void  OSTimeDly (INT16U)
//extern OS_EVENT RandomSem;
//extern int RandomSem;
extern void RandomSemGet(void);
int net_handle(void)
{
	//struct sk_buff *skb;
	struct ethhdr *eth_hdr;
	int rslt;
	//skb = alloc_skb(ETH_FRAME_LEN);
	//Uart_Printf("net_handle is running\n");
	//OS_ENTER_CRITICAL();
	rslt = eth_rcv();
	//OS_EXIT_CRITICAL();
	if (rslt != -1) {
		eth_hdr = (struct ethhdr *)(skb_g->data);
		skb_pull(skb_g,ETH_HLEN);
	
		//Uart_Printf("\n----%x", eth_hdr->h_proto);
	    //608->0806 arp ;8->0800 ip
	    //#define ETH_P_IP	0x0800		/* Internet Protocol packet	*/
		//#define ETH_P_ARP	0x0806		/* Address Resolution packet */
		if (ntohs(eth_hdr->h_proto) == ETH_P_ARP)
		{
			//Uart_Printf("arp\n");	
			//arp_count++;
			//Uart_Printf("任务接收到%x个arp包\n",arp_count);
			arp_rcv_packet(skb_g);		
		}

		else if(ntohs(eth_hdr->h_proto) == ETH_P_IP)
		{
			//Uart_Printf("ip\n");						
		 	ip_rcv_packet(skb_g);		 		
		}
	}
	//free_skb(skb);

	return 0;
}

void packet_check(void)
{
	int i;
	struct ethhdr *eth_hdr;
	//struct iphdr *ip_hdr;
	for(i=0;i<total_packet;i++)
	{
		skb_g_check = (struct sk_buff *)&skbuff[i];
		eth_hdr = (struct ethhdr *)(skb_g_check->data);
		//skb_pull(skb_g,ETH_HLEN);
		//Uart_Printf("%x号",i);
		//Uart_Printf("数据包类型-->%x\n",eth_hdr->h_proto);
		//检测到的包全是arp是因为没有对arp给回应,所以不停的发arp包过来
		//if(ntohs(eth_hdr->h_proto) == ETH_P_IP)
		//{
		//	ip_hdr = (struct iphdr *)(skb_g->data);
		//	if(ip_hdr->protocol == ICMP)
		//	{
		//		Uart_Printf("该IP包是个icmp包\n");
		//	}
		//}
	}
}

void tftp_main(unsigned long ip, unsigned long addr, int method)
{
	unsigned char eth_addr[ETH_ALEN];
    //unsigned char *s = (unsigned char *)&ip;
    int i;
    //void (*fp)(U32, U32);
    //fp = (void (*)(U32, U32))0xc008000;
	//Uart_Printf("Mini TFTP Server 1.0 (IP : %d.%d.%d.%d PORT: %d)\n", s[3], s[2], s[1], s[0], TFTP);
	Uart_Printf("*************Mini TFTP Server 1.0*************\n");
	load_addr = addr;
	DownLoadEnd = 0;
	DownLoadOnly = method;
	LoadLength = 0;
	
	//Uart_Printf("Load image file from host\n");
	//Uart_Printf("Type tftp -i %d.%d.%d.%d put filename at the host PC\n", s[3], s[2], s[1], s[0]);
	//Uart_Printf("Press ESC key to exit\n");					
	
	eth_init();
	//Uart_Printf("eth_init\n");	
	eth_get_addr(eth_addr);
	//Uart_Printf("eth_get_addr\n");
	arp_init();
	//Uart_Printf("arp_init\n");
	ip_init(ip);	
	//Uart_Printf("ip_init\n");
	udp_init();
	//Uart_Printf("udp_init\n");

	arp_add_entry(eth_addr,ip);
	//Uart_Printf("arp_add_entry\n");

	while(1){
		RandomSemGet();
		//Uart_Printf("接收到信号量,开始接收数据包,^_^!\n");
		//Uart_Printf("total_packet1-->%x!\n",total_packet);
		//packet_check();
		while(total_packet!=0){
			//Uart_Printf("执行BUFF_LEN次net_handle!\n");
			//Uart_Printf("nethandle执行了%x次!\n",++i);
			net_handle();			
		}
		//if(DownLoadEnd)
		//{
		//	Uart_Printf("Download end\n");			
		//	(*fp)(0, 178);
		//}
		
		//Uart_Printf("total_packet2-->%x!\n",total_packet);
		//Uart_Printf("rd_p-->%x!\n",rd_p);
		//Uart_Printf("wr_p-->%x!\n",wr_p);
		//SemGet=0;
		//rINTMSK=~(BIT_GLOBAL|BIT_TIMER0|BIT_EINT1);	//start timer INT
		//rI_ISPC=BIT_TIMER0|BIT_EINT1;
		//Uart_Printf("net_handle is running\n");
		//OSTimeDly(5);//不延时循环会死掉
		//if (kbhit()&&(getch()==ESC_KEY))
		//{
		//	putch('\n');
		//	return 0;
		//}
		//if(DownLoadEnd)
		//{
		//	puts("Download end\n");
		//	return LoadLength;
		//}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -