?? ethernet.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 *)ðernet_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 + -