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

📄 ethernet.c

📁 基于lm3s8962的UDP实验
💻 C
字号:
#define ETHERNET_GLOBALS
#include <includes.h>
uint8 My_Ip_1ID[4]=MY_IP_1ID;
uint8 My_Gateway_1ID[4]=MY_GATEWAY_1ID;
uint8 MY_IP_MARK_1ID[4]=IP_MARK_1ID;
uint8 MY_MAC_1ID[6]=My_Mac_1ID;//MAC地址
#if (MAX_NET_PORT>=2)
uint8 My_Ip_2ID[4]=MY_IP_2ID;
uint8 My_Gateway_2ID[4]=MY_GATEWAY_2ID;
uint8 MY_IP_MARK_2ID[4]=IP_MARK_2ID;
uint8 MY_MAC_2ID[6]=My_Mac_2ID;//MAC地址
#endif
/**********************************************************************
**函数原型:unsigned char Send_ethernet_Frame(struct _pkst *TxdData,unsigned char * de_mac,unsigned char PROTOCOL)
**入口参数:*TxdData 	: 发送结构指针
**		   * de_mac     : MAC地址指针
**		NextProtocal 	: 下一层协议,例如IP协议或ARP协议(如:IP_PACKED、ARP_PACKED)
**出口参数:	unsigned char 
**返 回 值:	1
**说    明:	为IP、ARP数据包产生ETHERNET包头,并发送。
************************************************************************/
uint8 Send_ethernet_Frame	(
					 struct _pkst *TxdData,//结构指针
					 uint8 * de_mac,			//对方的MAC地址指针
					 uint8 PROTOCOL,			//IP协议或ARP协议
					 uint8	num
				 )  
{ //如果没有MAC地址,就发送一个ARP包。得到MAC地址再发。
ipethernet ethernet_head; //ETHERNET处理缓存区	 
//ipethernet的结构体为DestMacId(目的网卡MAC)  SourceMacId(源网卡MAC) NextProtocal(下层协议)
struct _pkst PKethernet;
	/**************************获取目的网卡的MAC****************************************/
	ethernet_head.DestMacId[0]=*de_mac;	
	de_mac++;
	ethernet_head.DestMacId[1]=*de_mac;
	de_mac++;
	ethernet_head.DestMacId[2]=*de_mac;
	de_mac++;
	ethernet_head.DestMacId[3]=*de_mac;
	de_mac++;
	ethernet_head.DestMacId[4]=*de_mac;
	de_mac++;
	ethernet_head.DestMacId[5]=*de_mac;
	/************************获取源网卡的MAC********************************************/
	ethernet_head.SourceMacId[0]=NetPort[num].My_Mac[0];
	ethernet_head.SourceMacId[1]=NetPort[num].My_Mac[1];
	ethernet_head.SourceMacId[2]=NetPort[num].My_Mac[2];
	ethernet_head.SourceMacId[3]=NetPort[num].My_Mac[3];
	ethernet_head.SourceMacId[4]=NetPort[num].My_Mac[4];
	ethernet_head.SourceMacId[5]=NetPort[num].My_Mac[5];
#ifdef Little_End
	if(PROTOCOL==IP_PACKED)//如果是IP包,就设为0X0800
		ethernet_head.NextProtocal=0X0008;
	else if(PROTOCOL==ARP_PACKED)//如果是ARP包,就设为0X0806
		ethernet_head.NextProtocal=0X0608;//0X0806;
#endif
#ifdef Big_End
	if(PROTOCOL==IP_PACKED)//如果是IP包,就设为0X0800
		ethernet_head.NextProtocal=0X0800;
	else if(PROTOCOL==ARP_PACKED)//如果是ARP包,就设为0X0806
		ethernet_head.NextProtocal=0X0806;//0X0806;
#endif
	PKethernet.STPTR=TxdData;//指向前一个结构数组
	PKethernet.length=14;			//ETHERNET报头的长度
	PKethernet.DAPTR=(uint8 EX_RAM *)&ethernet_head;//ETHERNET报头的指针
	OS_ENTER_CRITICAL();//保护
	switch(num)
	{
	case 0: 
		Send_Packet(&PKethernet);//发送该帧
		break;
	case 1: 
		break;
	case 2: 
		break;
	default:
		break;
	}
	OS_EXIT_CRITICAL();//恢复
	return(1);
}
/**********************************************************************
**函数原型:    uint8 Send_Ip_To_LLC(struct _pkst *TxdData,unsigned char * de_ip)
**入口参数:

⌨️ 快捷键说明

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