ARP支持
原文件:文件net.c的NetReceive()函数

代码位置:搜索“case ARPOP_REPLY:”行并且找到其return;语句。

修改:

ifdef CONFIG_NETCONSOLE以下修改为:

ifdef CONFIG_NETCONSOLE

(*packetHandler)(0, 0, 0, 0);

endif

/** if Arp response by TFTP,
 ** send "TFTP Read Request"
 ** packet immediately */
extern int TftpStarted;
if (1 == TftpStarted) 
{
    NetArpWaitPacketIP = 0;
    NetArpWaitTxPacketSize = 0;
    NetArpWaitPacketMAC = NULL;
    TftpSend();
}
else if (NetArpWaitTxPacketSize)
{
    NetSendUDPPacket(NetArpWaitPacketMAC,
                     NetArpWaitPacketIP,
                     NetArpWaitDPort,        // 注
                     NetArpWaitSPort,
                     NetArpWaitTxPacketSize);
    NetArpWaitPacketIP = 0;
    NetArpWaitTxPacketSize = 0;
    NetArpWaitPacketMAC = NULL;
}
else
{
    /* no arp request pending now */
}

注:NetArpWaitDPort和NetArpWaitSPort都是新定义的全局变量。当然,也需要在NetSendUDPPacket将这两个值赋值。

UDP校验和支持
U-boot默认不用UDP校验和(置零)。但是在OS X中,UDP校验和不正确的话,UDP包将会被系统丢弃。所以需要添加如下:

位置:文件net.c中的NetSetIp()函数

修改:
首先,在NetSetIp()中的“ip->udp_xsum = 0;”后面加上:

unsigned int tmpSum = 0;
tmpSum = NetUdpCksum(ip, len);
ip->udp_xsum = htons((ushort)(~tmpSum));
然后,在前面添加Cksum函数:

define DB_UDP_XSUM(x)

unsigned NetUdpCksum(IP_t *ip, int len)
{

ulong xsum = 0;
uchar *data;
len += 8;

ip->udp_xsum = 0;

/* sum IP data */
data = &(ip->src);
xsum += ((ulong)(*(data + 0))) << 8;
xsum += ((ulong)(*(data + 1))) << 0;
xsum += ((ulong)(*(data + 2))) << 8;
xsum += ((ulong)(*(data + 3))) << 0;
xsum += ((ulong)(*(data + 4))) << 8;
xsum += ((ulong)(*(data + 5))) << 0;
xsum += ((ulong)(*(data + 6))) << 8;
xsum += ((ulong)(*(data + 7))) << 0;
DB_UDP_XSUM(printf("sum: 0x%04X IP\n", xsum));

/* sum IP protocol */
xsum += (ushort)(ip->ip_p);

/* sum UDP length */
data = &(ip->udp_len);

已注销
1 声望1 粉丝