📄 at91emac.c
字号:
pData = (char *)(tdList[i].addr & 0xFFFFFFFC);
switch (SWAP16(*pFrameType)) {
case PROT_ARP: /* ARP Packet format*/
pArpOp = (unsigned short *) (pData + 20);
if (SWAP16(*pArpOp) == ARP_REQUEST) {
/* ARP REPLY operation*/
*pArpOp = SWAP16(ARP_REPLY);
/* Fill the dest address and src address*/
for (i = 0; i <6; i++) {
/* swap ethernet dest address and ethernet src address*/
pData[i] = pData[i+6];
pData[i+6] = OurEmacAddr[i];
/* swap sender ethernet address and target ethernet address*/
pData[i+22] = OurEmacAddr[i];
pData[i+32] = pData[i+6];
}
/* swap sender IP address and target IP address*/
for (i = 0; i<4; i++) {
pData[i+38] = pData[i+28];
pData[i+28] = OurIpAddr[i];
}
if (!(*AT91C_EMAC_TSR & AT91C_EMAC_BNQ))
return AT91C_NO_IPPACKET;
*AT91C_EMAC_TSR |= AT91C_EMAC_COMP;
*AT91C_EMAC_TAR = (unsigned int)pData;
*AT91C_EMAC_TCR = 0x40;
}
break; /* case PROT_ARP*/
case PROT_IP: /* IP protocol frame*/
pIpHeader = (AT91PS_IPheader)(pData + 14);
pIcmpEcho = (AT91PS_IcmpEchoHdr)((char *)pIpHeader + 20);
memcpy(pHeader, pIpHeader,sizeof(AT91S_IPheader));
#if AT91C_DISPLAY_ALL_IPHEADER
status = AT91C_IPPACKET;
#endif
switch(pIpHeader->ip_p) {
case PROT_ICMP:
/* set the status variable to display in main.c only ICMP packets*/
status = AT91C_IPPACKET;
/* if ICMP_ECHO_REQUEST ==> resp = ICMP_ECHO_REPLY*/
if(pIcmpEcho->type == ICMP_ECHO_REQUEST) {
pIcmpEcho->type = ICMP_ECHO_REPLY;
pIcmpEcho->code = 0;
pIcmpEcho->cksum = 0;
/* Checksum of the ICMP Message */
icmp_len = (SWAP16(pIpHeader->ip_len) - 20)/(sizeof(unsigned short));
pIcmpEcho->cksum = SWAP16(AT91F_IcmpChksum((unsigned short *) pIcmpEcho, icmp_len));
/* Swap IP Dest address and IP Source address*/
for(i = 0; i <4; i++) {
pIpHeader->ip_dst[i] = pIpHeader->ip_src[i];
pIpHeader->ip_src[i] = OurIpAddr[i];
}
/* Swap Eth Dest address and Eth Source address*/
for(i = 0; i <6; i++) {
pData[i] = pData[i + 6];
pData[i+6] = OurEmacAddr[i];
}
/* send the echo_reply*/
*AT91C_EMAC_TSR |= AT91C_EMAC_COMP;
*AT91C_EMAC_TAR = (unsigned int)pData;
*AT91C_EMAC_TCR = SWAP16(pIpHeader->ip_len)+ 14;
}
break; /* case PROT_ICMP*/
default:
break;
}
break; /* case PROT_IP*/
default:
break;
}/* switch (SWAP16(*pFrameType))*/
/* process the packet*/
tdList[process].addr &= ~0x01;
return status;
}
/***************************************************************************
*
* AT91RmEndLoad - initialize the driver and device
*
* This routine initializes the driver and the device to an operational state.
* All of the device-specific parameters are passed in the <initStr>.
* If this routine is called with an empty but allocated string, it puts the
* name of this device (that is, "dc") into the <initStr> and returns 0.
* If the string is allocated but not empty, this routine tries to load
* the device.
*
* RETURNS: An END object pointer or NULL on error.
*/
END_OBJ* AT91RmEndLoad
(
char* initStr /* String to be parse by the driver. */
)
{
DRV_CTRL *pDrvCtrl;
char eAdrs[EADDR_LEN]; /* ethernet address */
#if 0
if (initStr == NULL)
{
DRV_LOG (DRV_DEBUG_LOAD, "dec21x40EndLoad: NULL initStr\r\n",
0,0,0,0,0,0);
return (NULL);
}
if (initStr[0] == '\0')
{
bcopy((char *)DRV_NAME, initStr, DRV_NAME_LEN);
return (0);
}
/* Allocate a control structure for this device */
pDrvCtrl = calloc (sizeof(DRV_CTRL), 1);
if (pDrvCtrl == NULL)
{
DRV_LOG (DRV_DEBUG_LOAD,"%s - Failed to allocate control structure\n",
(int)DRV_NAME, 0,0,0,0,0 );
return (NULL);
}
pDrvCtrl->flags = 0;
pDrvCtrl->intrConnect = FALSE;
pDrvCtrl->mediaCount = 0xff;
pDrvCtrl->homePNAPhyValuesFound = FALSE;
pDrvCtrl->offset = 0;
if (dec21x40InitParse (pDrvCtrl, initStr) == ERROR)
{
DRV_LOG (DRV_DEBUG_INIT, "%s - Failed to parse initialization"
"parameters\n",
(int)DRV_NAME,0,0,0,0,0);
return (NULL);
}
if (END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ*)pDrvCtrl, DRV_NAME,
pDrvCtrl->unit, &netFuncs,
"dec21x40 Enhanced Network Driver") == ERROR)
{
DRV_LOG (DRV_DEBUG_INIT, "%s%d - Failed to initialize END object\n",
(int)DRV_NAME, pDrvCtrl->unit, 0,0,0,0);
return (NULL);
}
if (dec21x40InitMem (pDrvCtrl) == ERROR)
{
DRV_LOG (DRV_DEBUG_INIT, "dec21x40InitMem failed",0,0,0,0,0,0);
goto error;
}
/* decode non-register user flags */
if (pDrvCtrl->usrFlags & DEC_USR_XEA)
DRV_FLAGS_SET (DEC_BSP_EADRS);
switch (pDrvCtrl->usrFlags & DEC_USR_VER_MSK)
{
case DEC_USR_21143 :
DRV_FLAGS_SET (DEC_21143);
break;
case DEC_USR_21140 :
DRV_FLAGS_SET (DEC_21140);
break;
case DEC_USR_21145 :
DRV_FLAGS_SET (DEC_21145);
break;
default :
DRV_FLAGS_SET (DEC_21040);
break;
}
if (dec21x40EnetAddrGet (pDrvCtrl, eAdrs) == ERROR)
{
DRV_LOG (DRV_DEBUG_INIT, "%s%d - Failed to read ethernet address\n",
(int)DRV_NAME, pDrvCtrl->unit,0,0,0,0);
goto error;
}
DRV_LOG (DRV_DEBUG_LOAD,
"ENET: %x:%x:%x:%x:%x:%x\n",
eAdrs[0], eAdrs[1], eAdrs[2], eAdrs[3], eAdrs[4], eAdrs[5]);
#ifdef INCLUDE_RFC_1213
/* Old RFC 1213 mib2 interface */
/* Initialize MIB-II entries */
if (END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd,
(UINT8*) eAdrs, 6,
ETHERMTU, DEC_SPEED_DEF) == ERROR)
{
DRV_LOG (DRV_DEBUG_INIT, "%s%d - MIB-II initializations failed\n",
(int)DRV_NAME, pDrvCtrl->unit,0,0,0,0);
goto error;
}
/* Mark the device ready with default flags */
END_OBJ_READY (&pDrvCtrl->endObj,
IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);
#else
/* New RFC 2233 mib2 interface */
/* Initialize MIB-II entries (for RFC 2233 ifXTable) */
pDrvCtrl->endObj.pMib2Tbl = m2IfAlloc(M2_ifType_ethernet_csmacd,
(UINT8*) eAdrs, 6,
ETHERMTU, DEC_SPEED_DEF,
DRV_NAME, pDrvCtrl->unit);
if (pDrvCtrl->endObj.pMib2Tbl == NULL)
{
printf ("%s%d - MIB-II initializations failed\n",
DRV_NAME, pDrvCtrl->unit);
goto error;
}
/*
* Set the RFC2233 flag bit in the END object flags field and
* install the counter update routines.
*/
#if defined(END_MIB_2233)
pDrvCtrl->endObj.flags |= END_MIB_2233;
#endif /* defined(END_MIB_2233) */
m2IfPktCountRtnInstall(pDrvCtrl->endObj.pMib2Tbl, m2If8023PacketCount);
/*
* Make a copy of the data in mib2Tbl struct as well. We do this
* mainly for backward compatibility issues. There might be some
* code that might be referencing the END pointer and might
* possibly do lookups on the mib2Tbl, which will cause all sorts
* of problems.
*/
bcopy ((char *)&pDrvCtrl->endObj.pMib2Tbl->m2Data.mibIfTbl,
(char *)&pDrvCtrl->endObj.mib2Tbl, sizeof (M2_INTERFACETBL));
/* Mark the device ready with default flags */
#if defined(END_MIB_2233)
END_OBJ_READY (&pDrvCtrl->endObj, IFF_NOTRAILERS | IFF_MULTICAST |
IFF_BROADCAST | END_MIB_2233);
#else /* !defined(END_MIB_2233) */
END_OBJ_READY (&pDrvCtrl->endObj, IFF_NOTRAILERS | IFF_MULTICAST |
IFF_BROADCAST);
#endif /* !defined(END_MIB_2233) */
#endif /* INCLUDE_RFC_1213 */
return (&pDrvCtrl->endObj);
/* Handle error cases */
error:
dec21x40Unload (pDrvCtrl);
return (NULL);
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -