summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/arp.c137
-rw-r--r--net/arp.h22
-rw-r--r--net/bootp.c373
-rw-r--r--net/bootp.h39
-rw-r--r--net/cdp.c88
-rw-r--r--net/cdp.h2
-rw-r--r--net/dns.c72
-rw-r--r--net/dns.h2
-rw-r--r--net/eth.c666
-rw-r--r--net/link_local.c83
-rw-r--r--net/net.c493
-rw-r--r--net/nfs.c241
-rw-r--r--net/nfs.h2
-rw-r--r--net/ping.c49
-rw-r--r--net/rarp.c45
-rw-r--r--net/rarp.h6
-rw-r--r--net/sntp.c48
-rw-r--r--net/sntp.h2
-rw-r--r--net/tftp.c595
-rw-r--r--net/tftp.h8
20 files changed, 1723 insertions, 1250 deletions
diff --git a/net/arp.c b/net/arp.c
index 21ed31b..b865570 100644
--- a/net/arp.c
+++ b/net/arp.c
@@ -27,43 +27,43 @@
# define ARP_TIMEOUT_COUNT CONFIG_NET_RETRY_COUNT
#endif
-IPaddr_t NetArpWaitPacketIP;
-static IPaddr_t NetArpWaitReplyIP;
+struct in_addr net_arp_wait_packet_ip;
+static struct in_addr net_arp_wait_reply_ip;
/* MAC address of waiting packet's destination */
-uchar *NetArpWaitPacketMAC;
-int NetArpWaitTxPacketSize;
-ulong NetArpWaitTimerStart;
-int NetArpWaitTry;
+uchar *arp_wait_packet_ethaddr;
+int arp_wait_tx_packet_size;
+ulong arp_wait_timer_start;
+int arp_wait_try;
-static uchar *NetArpTxPacket; /* THE ARP transmit packet */
-static uchar NetArpPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
+static uchar *arp_tx_packet; /* THE ARP transmit packet */
+static uchar arp_tx_packet_buf[PKTSIZE_ALIGN + PKTALIGN];
-void ArpInit(void)
+void arp_init(void)
{
/* XXX problem with bss workaround */
- NetArpWaitPacketMAC = NULL;
- NetArpWaitPacketIP = 0;
- NetArpWaitReplyIP = 0;
- NetArpWaitTxPacketSize = 0;
- NetArpTxPacket = &NetArpPacketBuf[0] + (PKTALIGN - 1);
- NetArpTxPacket -= (ulong)NetArpTxPacket % PKTALIGN;
+ arp_wait_packet_ethaddr = NULL;
+ net_arp_wait_packet_ip.s_addr = 0;
+ net_arp_wait_reply_ip.s_addr = 0;
+ arp_wait_tx_packet_size = 0;
+ arp_tx_packet = &arp_tx_packet_buf[0] + (PKTALIGN - 1);
+ arp_tx_packet -= (ulong)arp_tx_packet % PKTALIGN;
}
-void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther,
- IPaddr_t targetIP)
+void arp_raw_request(struct in_addr source_ip, const uchar *target_ethaddr,
+ struct in_addr target_ip)
{
uchar *pkt;
struct arp_hdr *arp;
int eth_hdr_size;
- debug_cond(DEBUG_DEV_PKT, "ARP broadcast %d\n", NetArpWaitTry);
+ debug_cond(DEBUG_DEV_PKT, "ARP broadcast %d\n", arp_wait_try);
- pkt = NetArpTxPacket;
+ pkt = arp_tx_packet;
- eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_ARP);
+ eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_ARP);
pkt += eth_hdr_size;
- arp = (struct arp_hdr *) pkt;
+ arp = (struct arp_hdr *)pkt;
arp->ar_hrd = htons(ARP_ETHER);
arp->ar_pro = htons(PROT_IP);
@@ -71,59 +71,59 @@ void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther,
arp->ar_pln = ARP_PLEN;
arp->ar_op = htons(ARPOP_REQUEST);
- memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN); /* source ET addr */
- NetWriteIP(&arp->ar_spa, sourceIP); /* source IP addr */
- memcpy(&arp->ar_tha, targetEther, ARP_HLEN); /* target ET addr */
- NetWriteIP(&arp->ar_tpa, targetIP); /* target IP addr */
+ memcpy(&arp->ar_sha, net_ethaddr, ARP_HLEN); /* source ET addr */
+ net_write_ip(&arp->ar_spa, source_ip); /* source IP addr */
+ memcpy(&arp->ar_tha, target_ethaddr, ARP_HLEN); /* target ET addr */
+ net_write_ip(&arp->ar_tpa, target_ip); /* target IP addr */
- NetSendPacket(NetArpTxPacket, eth_hdr_size + ARP_HDR_SIZE);
+ net_send_packet(arp_tx_packet, eth_hdr_size + ARP_HDR_SIZE);
}
-void ArpRequest(void)
+void arp_request(void)
{
- if ((NetArpWaitPacketIP & NetOurSubnetMask) !=
- (NetOurIP & NetOurSubnetMask)) {
- if (NetOurGatewayIP == 0) {
+ if ((net_arp_wait_packet_ip.s_addr & net_netmask.s_addr) !=
+ (net_ip.s_addr & net_netmask.s_addr)) {
+ if (net_gateway.s_addr == 0) {
puts("## Warning: gatewayip needed but not set\n");
- NetArpWaitReplyIP = NetArpWaitPacketIP;
+ net_arp_wait_reply_ip = net_arp_wait_packet_ip;
} else {
- NetArpWaitReplyIP = NetOurGatewayIP;
+ net_arp_wait_reply_ip = net_gateway;
}
} else {
- NetArpWaitReplyIP = NetArpWaitPacketIP;
+ net_arp_wait_reply_ip = net_arp_wait_packet_ip;
}
- arp_raw_request(NetOurIP, NetEtherNullAddr, NetArpWaitReplyIP);
+ arp_raw_request(net_ip, net_null_ethaddr, net_arp_wait_reply_ip);
}
-void ArpTimeoutCheck(void)
+void arp_timeout_check(void)
{
ulong t;
- if (!NetArpWaitPacketIP)
+ if (!net_arp_wait_packet_ip.s_addr)
return;
t = get_timer(0);
/* check for arp timeout */
- if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT) {
- NetArpWaitTry++;
+ if ((t - arp_wait_timer_start) > ARP_TIMEOUT) {
+ arp_wait_try++;
- if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) {
+ if (arp_wait_try >= ARP_TIMEOUT_COUNT) {
puts("\nARP Retry count exceeded; starting again\n");
- NetArpWaitTry = 0;
- NetStartAgain();
+ arp_wait_try = 0;
+ net_start_again();
} else {
- NetArpWaitTimerStart = t;
- ArpRequest();
+ arp_wait_timer_start = t;
+ arp_request();
}
}
}
-void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
+void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
{
struct arp_hdr *arp;
- IPaddr_t reply_ip_addr;
+ struct in_addr reply_ip_addr;
uchar *pkt;
int eth_hdr_size;
@@ -152,10 +152,10 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
if (arp->ar_pln != ARP_PLEN)
return;
- if (NetOurIP == 0)
+ if (net_ip.s_addr == 0)
return;
- if (NetReadIP(&arp->ar_tpa) != NetOurIP)
+ if (net_read_ip(&arp->ar_tpa).s_addr != net_ip.s_addr)
return;
switch (ntohs(arp->ar_op)) {
@@ -167,9 +167,9 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
pkt += eth_hdr_size;
arp->ar_op = htons(ARPOP_REPLY);
memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN);
- NetCopyIP(&arp->ar_tpa, &arp->ar_spa);
- memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN);
- NetCopyIP(&arp->ar_spa, &NetOurIP);
+ net_copy_ip(&arp->ar_tpa, &arp->ar_spa);
+ memcpy(&arp->ar_sha, net_ethaddr, ARP_HLEN);
+ net_copy_ip(&arp->ar_spa, &net_ip);
#ifdef CONFIG_CMD_LINK_LOCAL
/*
@@ -180,53 +180,52 @@ void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
* reply to ARP request so that our reply will overwrite
* the arp-proxy's instead of the other way around.
*/
- if ((NetReadIP(&arp->ar_tpa) & NetOurSubnetMask) !=
- (NetReadIP(&arp->ar_spa) & NetOurSubnetMask))
+ if ((net_read_ip(&arp->ar_tpa).s_addr & net_netmask.s_addr) !=
+ (net_read_ip(&arp->ar_spa).s_addr & net_netmask.s_addr))
udelay(5000);
#endif
- NetSendPacket((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
+ net_send_packet((uchar *)et, eth_hdr_size + ARP_HDR_SIZE);
return;
case ARPOP_REPLY: /* arp reply */
/* are we waiting for a reply */
- if (!NetArpWaitPacketIP)
+ if (!net_arp_wait_packet_ip.s_addr)
break;
#ifdef CONFIG_KEEP_SERVERADDR
- if (NetServerIP == NetArpWaitPacketIP) {
+ if (net_server_ip.s_addr == net_arp_wait_packet_ip.s_addr) {
char buf[20];
sprintf(buf, "%pM", &arp->ar_sha);
setenv("serveraddr", buf);
}
#endif
- reply_ip_addr = NetReadIP(&arp->ar_spa);
+ reply_ip_addr = net_read_ip(&arp->ar_spa);
/* matched waiting packet's address */
- if (reply_ip_addr == NetArpWaitReplyIP) {
+ if (reply_ip_addr.s_addr == net_arp_wait_reply_ip.s_addr) {
debug_cond(DEBUG_DEV_PKT,
- "Got ARP REPLY, set eth addr (%pM)\n",
- arp->ar_data);
+ "Got ARP REPLY, set eth addr (%pM)\n",
+ arp->ar_data);
/* save address for later use */
- if (NetArpWaitPacketMAC != NULL)
- memcpy(NetArpWaitPacketMAC,
+ if (arp_wait_packet_ethaddr != NULL)
+ memcpy(arp_wait_packet_ethaddr,
&arp->ar_sha, ARP_HLEN);
net_get_arp_handler()((uchar *)arp, 0, reply_ip_addr,
- 0, len);
+ 0, len);
/* set the mac address in the waiting packet's header
and transmit it */
- memcpy(((struct ethernet_hdr *)NetTxPacket)->et_dest,
- &arp->ar_sha, ARP_HLEN);
- NetSendPacket(NetTxPacket, NetArpWaitTxPacketSize);
+ memcpy(((struct ethernet_hdr *)net_tx_packet)->et_dest,
+ &arp->ar_sha, ARP_HLEN);
+ net_send_packet(net_tx_packet, arp_wait_tx_packet_size);
/* no arp request pending now */
- NetArpWaitPacketIP = 0;
- NetArpWaitTxPacketSize = 0;
- NetArpWaitPacketMAC = NULL;
-
+ net_arp_wait_packet_ip.s_addr = 0;
+ arp_wait_tx_packet_size = 0;
+ arp_wait_packet_ethaddr = NULL;
}
return;
default:
diff --git a/net/arp.h b/net/arp.h
index 3a0a13a..43c6296 100644
--- a/net/arp.h
+++ b/net/arp.h
@@ -14,18 +14,18 @@
#include <common.h>
-extern IPaddr_t NetArpWaitPacketIP;
+extern struct in_addr net_arp_wait_packet_ip;
/* MAC address of waiting packet's destination */
-extern uchar *NetArpWaitPacketMAC;
-extern int NetArpWaitTxPacketSize;
-extern ulong NetArpWaitTimerStart;
-extern int NetArpWaitTry;
+extern uchar *arp_wait_packet_ethaddr;
+extern int arp_wait_tx_packet_size;
+extern ulong arp_wait_timer_start;
+extern int arp_wait_try;
-void ArpInit(void);
-void ArpRequest(void);
-void arp_raw_request(IPaddr_t sourceIP, const uchar *targetEther,
- IPaddr_t targetIP);
-void ArpTimeoutCheck(void);
-void ArpReceive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len);
+void arp_init(void);
+void arp_request(void);
+void arp_raw_request(struct in_addr source_ip, const uchar *targetEther,
+ struct in_addr target_ip);
+void arp_timeout_check(void);
+void arp_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len);
#endif /* __ARP_H__ */
diff --git a/net/bootp.c b/net/bootp.c
index 8106601..43466af 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -51,18 +51,21 @@
#define CONFIG_BOOTP_ID_CACHE_SIZE 4
#endif
-ulong bootp_ids[CONFIG_BOOTP_ID_CACHE_SIZE];
+u32 bootp_ids[CONFIG_BOOTP_ID_CACHE_SIZE];
unsigned int bootp_num_ids;
-int BootpTry;
+int bootp_try;
ulong bootp_start;
ulong bootp_timeout;
+char net_nis_domain[32] = {0,}; /* Our NIS domain */
+char net_hostname[32] = {0,}; /* Our hostname */
+char net_root_path[64] = {0,}; /* Our bootpath */
#if defined(CONFIG_CMD_DHCP)
static dhcp_state_t dhcp_state = INIT;
-static unsigned long dhcp_leasetime;
-static IPaddr_t NetDHCPServerIP;
-static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len);
+static u32 dhcp_leasetime;
+static struct in_addr dhcp_server_ip;
+static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len);
/* For Debug */
#if 0
@@ -106,14 +109,14 @@ static bool bootp_match_id(ulong id)
return false;
}
-static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
+static int check_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len)
{
- struct Bootp_t *bp = (struct Bootp_t *) pkt;
+ struct bootp_hdr *bp = (struct bootp_hdr *)pkt;
int retval = 0;
if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
retval = -1;
- else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE)
+ else if (len < sizeof(struct bootp_hdr) - OPT_FIELD_SIZE)
retval = -2;
else if (bp->bp_op != OP_BOOTREQUEST &&
bp->bp_op != OP_BOOTREPLY &&
@@ -125,7 +128,7 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
retval = -4;
else if (bp->bp_hlen != HWL_ETHER)
retval = -5;
- else if (!bootp_match_id(NetReadLong((ulong *)&bp->bp_id)))
+ else if (!bootp_match_id(net_read_u32(&bp->bp_id)))
retval = -6;
debug("Filtering pkt = %d\n", retval);
@@ -136,28 +139,30 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
/*
* Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
*/
-static void BootpCopyNetParams(struct Bootp_t *bp)
+static void store_net_params(struct bootp_hdr *bp)
{
#if !defined(CONFIG_BOOTP_SERVERIP)
- IPaddr_t tmp_ip;
+ struct in_addr tmp_ip;
- NetCopyIP(&tmp_ip, &bp->bp_siaddr);
- if (tmp_ip != 0)
- NetCopyIP(&NetServerIP, &bp->bp_siaddr);
- memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
+ net_copy_ip(&tmp_ip, &bp->bp_siaddr);
+ if (tmp_ip.s_addr != 0)
+ net_copy_ip(&net_server_ip, &bp->bp_siaddr);
+ memcpy(net_server_ethaddr,
+ ((struct ethernet_hdr *)net_rx_packet)->et_src, 6);
if (strlen(bp->bp_file) > 0)
- copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
+ copy_filename(net_boot_file_name, bp->bp_file,
+ sizeof(net_boot_file_name));
- debug("Bootfile: %s\n", BootFile);
+ debug("net_boot_file_name: %s\n", net_boot_file_name);
/* Propagate to environment:
* don't delete exising entry when BOOTP / DHCP reply does
* not contain a new value
*/
- if (*BootFile)
- setenv("bootfile", BootFile);
+ if (*net_boot_file_name)
+ setenv("bootfile", net_boot_file_name);
#endif
- NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
+ net_copy_ip(&net_ip, &bp->bp_yiaddr);
}
static int truncate_sz(const char *name, int maxlen, int curlen)
@@ -172,38 +177,40 @@ static int truncate_sz(const char *name, int maxlen, int curlen)
#if !defined(CONFIG_CMD_DHCP)
-static void BootpVendorFieldProcess(u8 *ext)
+static void bootp_process_vendor_field(u8 *ext)
{
int size = *(ext + 1);
debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
- *(ext + 1));
+ *(ext + 1));
- NetBootFileSize = 0;
+ net_boot_file_expected_size_in_blocks = 0;
switch (*ext) {
/* Fixed length fields */
case 1: /* Subnet mask */
- if (NetOurSubnetMask == 0)
- NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
+ if (net_netmask.s_addr == 0)
+ net_copy_ip(&net_netmask, (struct in_addr *)(ext + 2));
break;
case 2: /* Time offset - Not yet supported */
break;
/* Variable length fields */
case 3: /* Gateways list */
- if (NetOurGatewayIP == 0)
- NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
+ if (net_gateway.s_addr == 0)
+ net_copy_ip(&net_gateway, (struct in_addr *)(ext + 2));
break;
case 4: /* Time server - Not yet supported */
break;
case 5: /* IEN-116 name server - Not yet supported */
break;
case 6:
- if (NetOurDNSIP == 0)
- NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2));
+ if (net_dns_server.s_addr == 0)
+ net_copy_ip(&net_dns_server,
+ (struct in_addr *)(ext + 2));
#if defined(CONFIG_BOOTP_DNS2)
- if ((NetOurDNS2IP == 0) && (size > 4))
- NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
+ if ((net_dns_server2.s_addr == 0) && (size > 4))
+ net_copy_ip(&net_dns_server2,
+ (struct in_addr *)(ext + 2 + 4));
#endif
break;
case 7: /* Log server - Not yet supported */
@@ -217,18 +224,20 @@ static void BootpVendorFieldProcess(u8 *ext)
case 11: /* RPL server - Not yet supported */
break;
case 12: /* Host name */
- if (NetOurHostName[0] == 0) {
+ if (net_hostname[0] == 0) {
size = truncate_sz("Host Name",
- sizeof(NetOurHostName), size);
- memcpy(&NetOurHostName, ext + 2, size);
- NetOurHostName[size] = 0;
+ sizeof(net_hostname), size);
+ memcpy(&net_hostname, ext + 2, size);
+ net_hostname[size] = 0;
}
break;
case 13: /* Boot file size */
if (size == 2)
- NetBootFileSize = ntohs(*(ushort *) (ext + 2));
+ net_boot_file_expected_size_in_blocks =
+ ntohs(*(ushort *)(ext + 2));
else if (size == 4)
- NetBootFileSize = ntohl(*(ulong *) (ext + 2));
+ net_boot_file_expected_size_in_blocks =
+ ntohl(*(ulong *)(ext + 2));
break;
case 14: /* Merit dump file - Not yet supported */
break;
@@ -237,11 +246,11 @@ static void BootpVendorFieldProcess(u8 *ext)
case 16: /* Swap server - Not yet supported */
break;
case 17: /* Root path */
- if (NetOurRootPath[0] == 0) {
+ if (net_root_path[0] == 0) {
size = truncate_sz("Root Path",
- sizeof(NetOurRootPath), size);
- memcpy(&NetOurRootPath, ext + 2, size);
- NetOurRootPath[size] = 0;
+ sizeof(net_root_path), size);
+ memcpy(&net_root_path, ext + 2, size);
+ net_root_path[size] = 0;
}
break;
case 18: /* Extension path - Not yet supported */
@@ -253,16 +262,16 @@ static void BootpVendorFieldProcess(u8 *ext)
break;
/* IP host layer fields */
case 40: /* NIS Domain name */
- if (NetOurNISDomain[0] == 0) {
+ if (net_nis_domain[0] == 0) {
size = truncate_sz("NIS Domain Name",
- sizeof(NetOurNISDomain), size);
- memcpy(&NetOurNISDomain, ext + 2, size);
- NetOurNISDomain[size] = 0;
+ sizeof(net_nis_domain), size);
+ memcpy(&net_nis_domain, ext + 2, size);
+ net_nis_domain[size] = 0;
}
break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
case 42: /* NTP server IP */
- NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2));
+ net_copy_ip(&net_ntp_server, (struct in_addr *)(ext + 2));
break;
#endif
/* Application layer fields */
@@ -276,7 +285,7 @@ static void BootpVendorFieldProcess(u8 *ext)
}
}
-static void BootpVendorProcess(u8 *ext, int size)
+static void bootp_process_vendor(u8 *ext, int size)
{
u8 *end = ext + size;
@@ -290,54 +299,51 @@ static void BootpVendorProcess(u8 *ext, int size)
ext += ext[1] + 2;
if (ext <= end)
- BootpVendorFieldProcess(opt);
+ bootp_process_vendor_field(opt);
}
}
debug("[BOOTP] Received fields:\n");
- if (NetOurSubnetMask)
- debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
+ if (net_netmask.s_addr)
+ debug("net_netmask : %pI4\n", &net_netmask);
- if (NetOurGatewayIP)
- debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
+ if (net_gateway.s_addr)
+ debug("net_gateway : %pI4", &net_gateway);
- if (NetBootFileSize)
- debug("NetBootFileSize : %d\n", NetBootFileSize);
+ if (net_boot_file_expected_size_in_blocks)
+ debug("net_boot_file_expected_size_in_blocks : %d\n",
+ net_boot_file_expected_size_in_blocks);
- if (NetOurHostName[0])
- debug("NetOurHostName : %s\n", NetOurHostName);
+ if (net_hostname[0])
+ debug("net_hostname : %s\n", net_hostname);
- if (NetOurRootPath[0])
- debug("NetOurRootPath : %s\n", NetOurRootPath);
+ if (net_root_path[0])
+ debug("net_root_path : %s\n", net_root_path);
- if (NetOurNISDomain[0])
- debug("NetOurNISDomain : %s\n", NetOurNISDomain);
-
- if (NetBootFileSize)
- debug("NetBootFileSize: %d\n", NetBootFileSize);
+ if (net_nis_domain[0])
+ debug("net_nis_domain : %s\n", net_nis_domain);
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
- if (NetNtpServerIP)
- debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
+ if (net_ntp_server)
+ debug("net_ntp_server : %pI4\n", &net_ntp_server);
#endif
}
/*
* Handle a BOOTP received packet.
*/
-static void
-BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void bootp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
- struct Bootp_t *bp;
+ struct bootp_hdr *bp;
debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
- src, dest, len, sizeof(struct Bootp_t));
+ src, dest, len, sizeof(struct bootp_hdr));
- bp = (struct Bootp_t *)pkt;
+ bp = (struct bootp_hdr *)pkt;
/* Filter out pkts we don't want */
- if (BootpCheckPkt(pkt, dest, src, len))
+ if (check_packet(pkt, dest, src, len))
return;
/*
@@ -347,13 +353,13 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
#endif
- BootpCopyNetParams(bp); /* Store net parameters from reply */
+ store_net_params(bp); /* Store net parameters from reply */
/* Retrieve extended information (we must parse the vendor area) */
- if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
- BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
+ if (net_read_u32((u32 *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
+ bootp_process_vendor((uchar *)&bp->bp_vend[4], len);
- NetSetTimeout(0, (thand_f *)0);
+ net_set_timeout_handler(0, (thand_f *)0);
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop");
debug("Got good BOOTP\n");
@@ -365,8 +371,7 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
/*
* Timeout on BOOTP/DHCP request.
*/
-static void
-BootpTimeout(void)
+static void bootp_timeout_handler(void)
{
ulong time_taken = get_timer(bootp_start);
@@ -376,14 +381,14 @@ BootpTimeout(void)
net_set_state(NETLOOP_FAIL);
#else
puts("\nRetry time exceeded; starting again\n");
- NetStartAgain();
+ net_start_again();
#endif
} else {
bootp_timeout *= 2;
if (bootp_timeout > 2000)
bootp_timeout = 2000;
- NetSetTimeout(bootp_timeout, BootpTimeout);
- BootpRequest();
+ net_set_timeout_handler(bootp_timeout, bootp_timeout_handler);
+ bootp_request();
}
}
@@ -400,8 +405,8 @@ BootpTimeout(void)
* Initialize BOOTP extension fields in the request.
*/
#if defined(CONFIG_CMD_DHCP)
-static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
- IPaddr_t RequestedIP)
+static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
+ struct in_addr requested_ip)
{
u8 *start = e;
u8 *cnt;
@@ -431,8 +436,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
*e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8;
*e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
- if (ServerID) {
- int tmp = ntohl(ServerID);
+ if (server_ip.s_addr) {
+ int tmp = ntohl(server_ip.s_addr);
*e++ = 54; /* ServerID */
*e++ = 4;
@@ -442,8 +447,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
*e++ = tmp & 0xff;
}
- if (RequestedIP) {
- int tmp = ntohl(RequestedIP);
+ if (requested_ip.s_addr) {
+ int tmp = ntohl(requested_ip.s_addr);
*e++ = 50; /* Requested IP */
*e++ = 4;
@@ -561,7 +566,7 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
/*
* Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
*/
-static int BootpExtended(u8 *e)
+static int bootp_extended(u8 *e)
{
u8 *start = e;
@@ -643,25 +648,26 @@ static int BootpExtended(u8 *e)
}
#endif
-void BootpReset(void)
+void bootp_reset(void)
{
bootp_num_ids = 0;
- BootpTry = 0;
+ bootp_try = 0;
bootp_start = get_timer(0);
bootp_timeout = 250;
}
-void
-BootpRequest(void)
+void bootp_request(void)
{
uchar *pkt, *iphdr;
- struct Bootp_t *bp;
+ struct bootp_hdr *bp;
int extlen, pktlen, iplen;
int eth_hdr_size;
#ifdef CONFIG_BOOTP_RANDOM_DELAY
ulong rand_ms;
#endif
- ulong BootpID;
+ u32 bootp_id;
+ struct in_addr zero_ip;
+ struct in_addr bcast_ip;
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
#if defined(CONFIG_CMD_DHCP)
@@ -669,11 +675,11 @@ BootpRequest(void)
#endif
#ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
- if (BootpTry == 0)
+ if (bootp_try == 0)
srand_mac();
- if (BootpTry <= 2) /* Start with max 1024 * 1ms */
- rand_ms = rand() >> (22 - BootpTry);
+ if (bootp_try <= 2) /* Start with max 1024 * 1ms */
+ rand_ms = rand() >> (22 - bootp_try);
else /* After 3rd BOOTP request max 8192 * 1ms */
rand_ms = rand() >> 19;
@@ -682,11 +688,11 @@ BootpRequest(void)
#endif /* CONFIG_BOOTP_RANDOM_DELAY */
- printf("BOOTP broadcast %d\n", ++BootpTry);
- pkt = NetTxPacket;
+ printf("BOOTP broadcast %d\n", ++bootp_try);
+ pkt = net_tx_packet;
memset((void *)pkt, 0, PKTSIZE);
- eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_IP);
pkt += eth_hdr_size;
/*
@@ -697,42 +703,44 @@ BootpRequest(void)
* C. Hallinan, DS4.COM, Inc.
*/
/* net_set_udp_header(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
- sizeof (struct Bootp_t)); */
+ sizeof (struct bootp_hdr)); */
iphdr = pkt; /* We need this later for net_set_udp_header() */
pkt += IP_UDP_HDR_SIZE;
- bp = (struct Bootp_t *)pkt;
+ bp = (struct bootp_hdr *)pkt;
bp->bp_op = OP_BOOTREQUEST;
bp->bp_htype = HWT_ETHER;
bp->bp_hlen = HWL_ETHER;
bp->bp_hops = 0;
bp->bp_secs = htons(get_timer(0) / 1000);
- NetWriteIP(&bp->bp_ciaddr, 0);
- NetWriteIP(&bp->bp_yiaddr, 0);
- NetWriteIP(&bp->bp_siaddr, 0);
- NetWriteIP(&bp->bp_giaddr, 0);
- memcpy(bp->bp_chaddr, NetOurEther, 6);
- copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file));
+ zero_ip.s_addr = 0;
+ net_write_ip(&bp->bp_ciaddr, zero_ip);
+ net_write_ip(&bp->bp_yiaddr, zero_ip);
+ net_write_ip(&bp->bp_siaddr, zero_ip);
+ net_write_ip(&bp->bp_giaddr, zero_ip);
+ memcpy(bp->bp_chaddr, net_ethaddr, 6);
+ copy_filename(bp->bp_file, net_boot_file_name, sizeof(bp->bp_file));
/* Request additional information from the BOOTP/DHCP server */
#if defined(CONFIG_CMD_DHCP)
- extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
+ extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_DISCOVER, zero_ip,
+ zero_ip);
#else
- extlen = BootpExtended((u8 *)bp->bp_vend);
+ extlen = bootp_extended((u8 *)bp->bp_vend);
#endif
/*
* Bootp ID is the lower 4 bytes of our ethernet address
* plus the current time in ms.
*/
- BootpID = ((ulong)NetOurEther[2] << 24)
- | ((ulong)NetOurEther[3] << 16)
- | ((ulong)NetOurEther[4] << 8)
- | (ulong)NetOurEther[5];
- BootpID += get_timer(0);
- BootpID = htonl(BootpID);
- bootp_add_id(BootpID);
- NetCopyLong(&bp->bp_id, &BootpID);
+ bootp_id = ((u32)net_ethaddr[2] << 24)
+ | ((u32)net_ethaddr[3] << 16)
+ | ((u32)net_ethaddr[4] << 8)
+ | (u32)net_ethaddr[5];
+ bootp_id += get_timer(0);
+ bootp_id = htonl(bootp_id);
+ bootp_add_id(bootp_id);
+ net_copy_u32(&bp->bp_id, &bootp_id);
/*
* Calculate proper packet lengths taking into account the
@@ -740,20 +748,21 @@ BootpRequest(void)
*/
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
- net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
- NetSetTimeout(bootp_timeout, BootpTimeout);
+ bcast_ip.s_addr = 0xFFFFFFFFL;
+ net_set_udp_header(iphdr, bcast_ip, PORT_BOOTPS, PORT_BOOTPC, iplen);
+ net_set_timeout_handler(bootp_timeout, bootp_timeout_handler);
#if defined(CONFIG_CMD_DHCP)
dhcp_state = SELECTING;
- net_set_udp_handler(DhcpHandler);
+ net_set_udp_handler(dhcp_handler);
#else
- net_set_udp_handler(BootpHandler);
+ net_set_udp_handler(bootp_handler);
#endif
- NetSendPacket(NetTxPacket, pktlen);
+ net_send_packet(net_tx_packet, pktlen);
}
#if defined(CONFIG_CMD_DHCP)
-static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
+static void dhcp_process_options(uchar *popt, struct bootp_hdr *bp)
{
uchar *end = popt + BOOTP_HDR_SIZE;
int oplen, size;
@@ -765,53 +774,53 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
oplen = *(popt + 1);
switch (*popt) {
case 1:
- NetCopyIP(&NetOurSubnetMask, (popt + 2));
+ net_copy_ip(&net_netmask, (popt + 2));
break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
case 2: /* Time offset */
- to_ptr = &NetTimeOffset;
- NetCopyLong((ulong *)to_ptr, (ulong *)(popt + 2));
- NetTimeOffset = ntohl(NetTimeOffset);
+ to_ptr = &net_ntp_time_offset;
+ net_copy_u32((u32 *)to_ptr, (u32 *)(popt + 2));
+ net_ntp_time_offset = ntohl(net_ntp_time_offset);
break;
#endif
case 3:
- NetCopyIP(&NetOurGatewayIP, (popt + 2));
+ net_copy_ip(&net_gateway, (popt + 2));
break;
case 6:
- NetCopyIP(&NetOurDNSIP, (popt + 2));
+ net_copy_ip(&net_dns_server, (popt + 2));
#if defined(CONFIG_BOOTP_DNS2)
if (*(popt + 1) > 4)
- NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4));
+ net_copy_ip(&net_dns_server2, (popt + 2 + 4));
#endif
break;
case 12:
size = truncate_sz("Host Name",
- sizeof(NetOurHostName), oplen);
- memcpy(&NetOurHostName, popt + 2, size);
- NetOurHostName[size] = 0;
+ sizeof(net_hostname), oplen);
+ memcpy(&net_hostname, popt + 2, size);
+ net_hostname[size] = 0;
break;
case 15: /* Ignore Domain Name Option */
break;
case 17:
size = truncate_sz("Root Path",
- sizeof(NetOurRootPath), oplen);
- memcpy(&NetOurRootPath, popt + 2, size);
- NetOurRootPath[size] = 0;
+ sizeof(net_root_path), oplen);
+ memcpy(&net_root_path, popt + 2, size);
+ net_root_path[size] = 0;
break;
case 28: /* Ignore Broadcast Address Option */
break;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
case 42: /* NTP server IP */
- NetCopyIP(&NetNtpServerIP, (popt + 2));
+ net_copy_ip(&net_ntp_server, (popt + 2));
break;
#endif
case 51:
- NetCopyLong(&dhcp_leasetime, (ulong *) (popt + 2));
+ net_copy_u32(&dhcp_leasetime, (u32 *)(popt + 2));
break;
case 53: /* Ignore Message Type Option */
break;
case 54:
- NetCopyIP(&NetDHCPServerIP, (popt + 2));
+ net_copy_ip(&dhcp_server_ip, (popt + 2));
break;
case 58: /* Ignore Renewal Time Option */
break;
@@ -840,7 +849,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
* to me
*/
printf("*** WARNING: using vendor "
- "optional boot file\n");
+ "optional boot file\n");
memcpy(bp->bp_file, popt + 2, size);
bp->bp_file[size] = '\0';
}
@@ -851,16 +860,16 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
break;
#endif
printf("*** Unhandled DHCP Option in OFFER/ACK:"
- " %d\n", *popt);
+ " %d\n", *popt);
break;
}
popt += oplen + 2; /* Process next option */
}
}
-static int DhcpMessageType(unsigned char *popt)
+static int dhcp_message_type(unsigned char *popt)
{
- if (NetReadLong((ulong *)popt) != htonl(BOOTP_VENDOR_MAGIC))
+ if (net_read_u32((u32 *)popt) != htonl(BOOTP_VENDOR_MAGIC))
return -1;
popt += 4;
@@ -872,25 +881,27 @@ static int DhcpMessageType(unsigned char *popt)
return -1;
}
-static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
+static void dhcp_send_request_packet(struct bootp_hdr *bp_offer)
{
uchar *pkt, *iphdr;
- struct Bootp_t *bp;
+ struct bootp_hdr *bp;
int pktlen, iplen, extlen;
int eth_hdr_size;
- IPaddr_t OfferedIP;
+ struct in_addr offered_ip;
+ struct in_addr zero_ip;
+ struct in_addr bcast_ip;
- debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
- pkt = NetTxPacket;
+ debug("dhcp_send_request_packet: Sending DHCPREQUEST\n");
+ pkt = net_tx_packet;
memset((void *)pkt, 0, PKTSIZE);
- eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
+ eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_IP);
pkt += eth_hdr_size;
iphdr = pkt; /* We'll need this later to set proper pkt size */
pkt += IP_UDP_HDR_SIZE;
- bp = (struct Bootp_t *)pkt;
+ bp = (struct bootp_hdr *)pkt;
bp->bp_op = OP_BOOTREQUEST;
bp->bp_htype = HWT_ETHER;
bp->bp_hlen = HWL_ETHER;
@@ -903,54 +914,55 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
* RFC3046 requires Relay Agents to discard packets with
* nonzero and offered giaddr
*/
- NetWriteIP(&bp->bp_giaddr, 0);
+ zero_ip.s_addr = 0;
+ net_write_ip(&bp->bp_giaddr, zero_ip);
- memcpy(bp->bp_chaddr, NetOurEther, 6);
+ memcpy(bp->bp_chaddr, net_ethaddr, 6);
/*
* ID is the id of the OFFER packet
*/
- NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
+ net_copy_u32(&bp->bp_id, &bp_offer->bp_id);
/*
* Copy options from OFFER packet if present
*/
/* Copy offered IP into the parameters request list */
- NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
- extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
- NetDHCPServerIP, OfferedIP);
+ net_copy_ip(&offered_ip, &bp_offer->bp_yiaddr);
+ extlen = dhcp_extended((u8 *)bp->bp_vend, DHCP_REQUEST,
+ dhcp_server_ip, offered_ip);
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
- net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
+ bcast_ip.s_addr = 0xFFFFFFFFL;
+ net_set_udp_header(iphdr, bcast_ip, PORT_BOOTPS, PORT_BOOTPC, iplen);
#ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
#endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
- NetSendPacket(NetTxPacket, pktlen);
+ net_send_packet(net_tx_packet, pktlen);
}
/*
* Handle DHCP received packets.
*/
-static void
-DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
- struct Bootp_t *bp = (struct Bootp_t *)pkt;
+ struct bootp_hdr *bp = (struct bootp_hdr *)pkt;
debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
- src, dest, len, dhcp_state);
+ src, dest, len, dhcp_state);
/* Filter out pkts we don't want */
- if (BootpCheckPkt(pkt, dest, src, len))
+ if (check_packet(pkt, dest, src, len))
return;
- debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state:"
- " %d\n", src, dest, len, dhcp_state);
+ debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: "
+ "%d\n", src, dest, len, dhcp_state);
switch (dhcp_state) {
case SELECTING:
@@ -970,12 +982,12 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
debug("TRANSITIONING TO REQUESTING STATE\n");
dhcp_state = REQUESTING;
- if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
+ if (net_read_u32((u32 *)&bp->bp_vend[0]) ==
htonl(BOOTP_VENDOR_MAGIC))
- DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
+ dhcp_process_options((u8 *)&bp->bp_vend[4], bp);
- NetSetTimeout(5000, BootpTimeout);
- DhcpSendRequestPkt(bp);
+ net_set_timeout_handler(5000, bootp_timeout_handler);
+ dhcp_send_request_packet(bp);
#ifdef CONFIG_SYS_BOOTFILE_PREFIX
}
#endif /* CONFIG_SYS_BOOTFILE_PREFIX */
@@ -985,17 +997,17 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
case REQUESTING:
debug("DHCP State: REQUESTING\n");
- if (DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK) {
- if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
+ if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK) {
+ if (net_read_u32((u32 *)&bp->bp_vend[0]) ==
htonl(BOOTP_VENDOR_MAGIC))
- DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
+ dhcp_process_options((u8 *)&bp->bp_vend[4], bp);
/* Store net params from reply */
- BootpCopyNetParams(bp);
+ store_net_params(bp);
dhcp_state = BOUND;
printf("DHCP client bound to address %pI4 (%lu ms)\n",
- &NetOurIP, get_timer(bootp_start));
+ &net_ip, get_timer(bootp_start));
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP,
- "bootp_stop");
+ "bootp_stop");
net_auto_load();
return;
@@ -1008,11 +1020,10 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
puts("DHCP: INVALID STATE\n");
break;
}
-
}
-void DhcpRequest(void)
+void dhcp_request(void)
{
- BootpRequest();
+ bootp_request();
}
#endif /* CONFIG_CMD_DHCP */
diff --git a/net/bootp.h b/net/bootp.h
index 3b95a0a..fcb0a64 100644
--- a/net/bootp.h
+++ b/net/bootp.h
@@ -29,29 +29,29 @@ extern u8 *dhcp_vendorex_proc(u8 *e); /*rtn next e if mine,else NULL */
#define OPT_FIELD_SIZE 64
#endif
-struct Bootp_t {
- uchar bp_op; /* Operation */
+struct bootp_hdr {
+ u8 bp_op; /* Operation */
# define OP_BOOTREQUEST 1
# define OP_BOOTREPLY 2
- uchar bp_htype; /* Hardware type */
+ u8 bp_htype; /* Hardware type */
# define HWT_ETHER 1
- uchar bp_hlen; /* Hardware address length */
+ u8 bp_hlen; /* Hardware address length */
# define HWL_ETHER 6
- uchar bp_hops; /* Hop count (gateway thing) */
- ulong bp_id; /* Transaction ID */
- ushort bp_secs; /* Seconds since boot */
- ushort bp_spare1; /* Alignment */
- IPaddr_t bp_ciaddr; /* Client IP address */
- IPaddr_t bp_yiaddr; /* Your (client) IP address */
- IPaddr_t bp_siaddr; /* Server IP address */
- IPaddr_t bp_giaddr; /* Gateway IP address */
- uchar bp_chaddr[16]; /* Client hardware address */
+ u8 bp_hops; /* Hop count (gateway thing) */
+ u32 bp_id; /* Transaction ID */
+ u16 bp_secs; /* Seconds since boot */
+ u16 bp_spare1; /* Alignment */
+ struct in_addr bp_ciaddr; /* Client IP address */
+ struct in_addr bp_yiaddr; /* Your (client) IP address */
+ struct in_addr bp_siaddr; /* Server IP address */
+ struct in_addr bp_giaddr; /* Gateway IP address */
+ u8 bp_chaddr[16]; /* Client hardware address */
char bp_sname[64]; /* Server host name */
char bp_file[128]; /* Boot file name */
char bp_vend[OPT_FIELD_SIZE]; /* Vendor information */
};
-#define BOOTP_HDR_SIZE sizeof(struct Bootp_t)
+#define BOOTP_HDR_SIZE sizeof(struct bootp_hdr)
/**********************************************************************/
/*
@@ -59,17 +59,16 @@ struct Bootp_t {
*/
/* bootp.c */
-extern ulong BootpID; /* ID of cur BOOTP request */
-extern char BootFile[128]; /* Boot file name */
-extern int BootpTry;
+extern u32 bootp_id; /* ID of cur BOOTP request */
+extern int bootp_try;
/* Send a BOOTP request */
-extern void BootpReset(void);
-extern void BootpRequest(void);
+void bootp_reset(void);
+void bootp_request(void);
/****************** DHCP Support *********************/
-extern void DhcpRequest(void);
+void dhcp_request(void);
/* DHCP States */
typedef enum { INIT,
diff --git a/net/cdp.c b/net/cdp.c
index 2d8fa03..f9ccf53 100644
--- a/net/cdp.c
+++ b/net/cdp.c
@@ -18,7 +18,7 @@
#include "cdp.h"
/* Ethernet bcast address */
-const uchar NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
+const u8 net_cdp_ethaddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
#define CDP_DEVICE_ID_TLV 0x0001
#define CDP_ADDRESS_TLV 0x0002
@@ -36,17 +36,16 @@ const uchar NetCDPAddr[6] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
#define CDP_TIMEOUT 250UL /* one packet every 250ms */
-static int CDPSeq;
-static int CDPOK;
+static int cdp_seq;
+static int cdp_ok;
-ushort CDPNativeVLAN;
-ushort CDPApplianceVLAN;
+ushort cdp_native_vlan;
+ushort cdp_appliance_vlan;
-static const uchar CDP_SNAP_hdr[8] = {
+static const uchar cdp_snap_hdr[8] = {
0xAA, 0xAA, 0x03, 0x00, 0x00, 0x0C, 0x20, 0x00 };
-static ushort
-CDP_compute_csum(const uchar *buff, ushort len)
+static ushort cdp_compute_csum(const uchar *buff, ushort len)
{
ushort csum;
int odd;
@@ -104,8 +103,7 @@ CDP_compute_csum(const uchar *buff, ushort len)
return csum;
}
-static int
-CDPSendTrigger(void)
+static int cdp_send_trigger(void)
{
uchar *pkt;
ushort *s;
@@ -118,20 +116,20 @@ CDPSendTrigger(void)
char buf[32];
#endif
- pkt = NetTxPacket;
+ pkt = net_tx_packet;
et = (struct ethernet_hdr *)pkt;
/* NOTE: trigger sent not on any VLAN */
/* form ethernet header */
- memcpy(et->et_dest, NetCDPAddr, 6);
- memcpy(et->et_src, NetOurEther, 6);
+ memcpy(et->et_dest, net_cdp_ethaddr, 6);
+ memcpy(et->et_src, net_ethaddr, 6);
pkt += ETHER_HDR_SIZE;
/* SNAP header */
- memcpy((uchar *)pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr));
- pkt += sizeof(CDP_SNAP_hdr);
+ memcpy((uchar *)pkt, cdp_snap_hdr, sizeof(cdp_snap_hdr));
+ pkt += sizeof(cdp_snap_hdr);
/* CDP header */
*pkt++ = 0x02; /* CDP version 2 */
@@ -145,7 +143,7 @@ CDPSendTrigger(void)
#ifdef CONFIG_CDP_DEVICE_ID
*s++ = htons(CDP_DEVICE_ID_TLV);
*s++ = htons(CONFIG_CDP_DEVICE_ID);
- sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%pm", NetOurEther);
+ sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%pm", net_ethaddr);
memcpy((uchar *)s, buf, 16);
s += 16 / 2;
#endif
@@ -207,34 +205,33 @@ CDPSendTrigger(void)
#endif
/* length of ethernet packet */
- len = (uchar *)s - ((uchar *)NetTxPacket + ETHER_HDR_SIZE);
+ len = (uchar *)s - ((uchar *)net_tx_packet + ETHER_HDR_SIZE);
et->et_protlen = htons(len);
- len = ETHER_HDR_SIZE + sizeof(CDP_SNAP_hdr);
- chksum = CDP_compute_csum((uchar *)NetTxPacket + len,
- (uchar *)s - (NetTxPacket + len));
+ len = ETHER_HDR_SIZE + sizeof(cdp_snap_hdr);
+ chksum = cdp_compute_csum((uchar *)net_tx_packet + len,
+ (uchar *)s - (net_tx_packet + len));
if (chksum == 0)
chksum = 0xFFFF;
*cp = htons(chksum);
- NetSendPacket(NetTxPacket, (uchar *)s - NetTxPacket);
+ net_send_packet(net_tx_packet, (uchar *)s - net_tx_packet);
return 0;
}
-static void
-CDPTimeout(void)
+static void cdp_timeout_handler(void)
{
- CDPSeq++;
+ cdp_seq++;
- if (CDPSeq < 3) {
- NetSetTimeout(CDP_TIMEOUT, CDPTimeout);
- CDPSendTrigger();
+ if (cdp_seq < 3) {
+ net_set_timeout_handler(CDP_TIMEOUT, cdp_timeout_handler);
+ cdp_send_trigger();
return;
}
/* if not OK try again */
- if (!CDPOK)
- NetStartAgain();
+ if (!cdp_ok)
+ net_start_again();
else
net_set_state(NETLOOP_SUCCESS);
}
@@ -247,15 +244,15 @@ void cdp_receive(const uchar *pkt, unsigned len)
ushort vlan, nvlan;
/* minimum size? */
- if (len < sizeof(CDP_SNAP_hdr) + 4)
+ if (len < sizeof(cdp_snap_hdr) + 4)
goto pkt_short;
/* check for valid CDP SNAP header */
- if (memcmp(pkt, CDP_SNAP_hdr, sizeof(CDP_SNAP_hdr)) != 0)
+ if (memcmp(pkt, cdp_snap_hdr, sizeof(cdp_snap_hdr)) != 0)
return;
- pkt += sizeof(CDP_SNAP_hdr);
- len -= sizeof(CDP_SNAP_hdr);
+ pkt += sizeof(cdp_snap_hdr);
+ len -= sizeof(cdp_snap_hdr);
/* Version of CDP protocol must be >= 2 and TTL != 0 */
if (pkt[0] < 0x02 || pkt[1] == 0)
@@ -269,7 +266,7 @@ void cdp_receive(const uchar *pkt, unsigned len)
printf("**WARNING: CDP packet received with a protocol version "
"%d > 2\n", pkt[0] & 0xff);
- if (CDP_compute_csum(pkt, len) != 0)
+ if (cdp_compute_csum(pkt, len) != 0)
return;
pkt += 4;
@@ -340,28 +337,27 @@ void cdp_receive(const uchar *pkt, unsigned len)
}
}
- CDPApplianceVLAN = vlan;
- CDPNativeVLAN = nvlan;
+ cdp_appliance_vlan = vlan;
+ cdp_native_vlan = nvlan;
- CDPOK = 1;
+ cdp_ok = 1;
return;
- pkt_short:
+pkt_short:
printf("** CDP packet is too short\n");
return;
}
-void
-CDPStart(void)
+void cdp_start(void)
{
printf("Using %s device\n", eth_get_name());
- CDPSeq = 0;
- CDPOK = 0;
+ cdp_seq = 0;
+ cdp_ok = 0;
- CDPNativeVLAN = htons(-1);
- CDPApplianceVLAN = htons(-1);
+ cdp_native_vlan = htons(-1);
+ cdp_appliance_vlan = htons(-1);
- NetSetTimeout(CDP_TIMEOUT, CDPTimeout);
+ net_set_timeout_handler(CDP_TIMEOUT, cdp_timeout_handler);
- CDPSendTrigger();
+ cdp_send_trigger();
}
diff --git a/net/cdp.h b/net/cdp.h
index 95e4ce0..83475c9 100644
--- a/net/cdp.h
+++ b/net/cdp.h
@@ -14,7 +14,7 @@
#ifndef __CDP_H__
#define __CDP_H__
-void CDPStart(void);
+void cdp_start(void);
/* Process a received CDP packet */
void cdp_receive(const uchar *pkt, unsigned len);
diff --git a/net/dns.c b/net/dns.c
index dd45320..7017bac 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -5,7 +5,7 @@
* Copyright (c) 2009 Robin Getz <rgetz@blackfin.uclinux.org>
*
* This is a simple DNS implementation for U-Boot. It will use the first IP
- * in the DNS response as NetServerIP. This can then be used for any other
+ * in the DNS response as net_server_ip. This can then be used for any other
* network related activities.
*
* The packet handling is partly based on TADNS, original copyrights
@@ -29,13 +29,12 @@
#include "dns.h"
-char *NetDNSResolve; /* The host to resolve */
-char *NetDNSenvvar; /* The envvar to store the answer in */
+char *net_dns_resolve; /* The host to resolve */
+char *net_dns_env_var; /* The envvar to store the answer in */
-static int DnsOurPort;
+static int dns_our_port;
-static void
-DnsSend(void)
+static void dns_send(void)
{
struct header *header;
int n, name_len;
@@ -44,11 +43,12 @@ DnsSend(void)
const char *name;
enum dns_query_type qtype = DNS_A_RECORD;
- name = NetDNSResolve;
- pkt = p = (uchar *)(NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE);
+ name = net_dns_resolve;
+ pkt = (uchar *)(net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE);
+ p = pkt;
/* Prepare DNS packet header */
- header = (struct header *) pkt;
+ header = (struct header *)pkt;
header->tid = 1;
header->flags = htons(0x100); /* standard query */
header->nqueries = htons(1); /* Just one query */
@@ -58,7 +58,7 @@ DnsSend(void)
/* Encode DNS name */
name_len = strlen(name);
- p = (uchar *) &header->data; /* For encoding host name into packet */
+ p = (uchar *)&header->data; /* For encoding host name into packet */
do {
s = strchr(name, '.');
@@ -87,41 +87,40 @@ DnsSend(void)
n = p - pkt; /* Total packet length */
debug("Packet size %d\n", n);
- DnsOurPort = random_port();
+ dns_our_port = random_port();
- NetSendUDPPacket(NetServerEther, NetOurDNSIP, DNS_SERVICE_PORT,
- DnsOurPort, n);
+ net_send_udp_packet(net_server_ethaddr, net_dns_server,
+ DNS_SERVICE_PORT, dns_our_port, n);
debug("DNS packet sent\n");
}
-static void
-DnsTimeout(void)
+static void dns_timeout_handler(void)
{
puts("Timeout\n");
net_set_state(NETLOOP_FAIL);
}
-static void
-DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
+static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
struct header *header;
const unsigned char *p, *e, *s;
u16 type, i;
int found, stop, dlen;
- char IPStr[22];
- IPaddr_t IPAddress;
+ char ip_str[22];
+ struct in_addr ip_addr;
debug("%s\n", __func__);
- if (dest != DnsOurPort)
+ if (dest != dns_our_port)
return;
for (i = 0; i < len; i += 4)
debug("0x%p - 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
- pkt+i, pkt[i], pkt[i+1], pkt[i+2], pkt[i+3]);
+ pkt+i, pkt[i], pkt[i+1], pkt[i+2], pkt[i+3]);
/* We sent one query. We want to have a single answer: */
- header = (struct header *) pkt;
+ header = (struct header *)pkt;
if (ntohs(header->nqueries) != 1)
return;
@@ -150,7 +149,6 @@ DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
/* Loop through the answers, we want A type answer */
for (found = stop = 0; !stop && &p[12] < e; ) {
-
/* Skip possible name in CNAME answer */
if (*p != 0xc0) {
while (*p && &p[12] < e)
@@ -169,7 +167,8 @@ DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
p += 12 + dlen;
} else if (type == DNS_A_RECORD) {
debug("Found A-record\n");
- found = stop = 1;
+ found = 1;
+ stop = 1;
} else {
debug("Unknown type\n");
stop = 1;
@@ -177,33 +176,32 @@ DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
}
if (found && &p[12] < e) {
-
dlen = get_unaligned_be16(p+10);
p += 12;
- memcpy(&IPAddress, p, 4);
+ memcpy(&ip_addr, p, 4);
if (p + dlen <= e) {
- ip_to_string(IPAddress, IPStr);
- printf("%s\n", IPStr);
- if (NetDNSenvvar)
- setenv(NetDNSenvvar, IPStr);
- } else
+ ip_to_string(ip_addr, ip_str);
+ printf("%s\n", ip_str);
+ if (net_dns_env_var)
+ setenv(net_dns_env_var, ip_str);
+ } else {
puts("server responded with invalid IP number\n");
+ }
}
net_set_state(NETLOOP_SUCCESS);
}
-void
-DnsStart(void)
+void dns_start(void)
{
debug("%s\n", __func__);
- NetSetTimeout(DNS_TIMEOUT, DnsTimeout);
- net_set_udp_handler(DnsHandler);
+ net_set_timeout_handler(DNS_TIMEOUT, dns_timeout_handler);
+ net_set_udp_handler(dns_handler);
/* Clear a previous MAC address, the server IP might have changed. */
- memset(NetServerEther, 0, sizeof(NetServerEther));
+ memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr));
- DnsSend();
+ dns_send();
}
diff --git a/net/dns.h b/net/dns.h
index dbc3890..c4e96af 100644
--- a/net/dns.h
+++ b/net/dns.h
@@ -31,6 +31,6 @@ struct header {
unsigned char data[1]; /* Data, variable length */
};
-extern void DnsStart(void); /* Begin DNS */
+void dns_start(void); /* Begin DNS */
#endif
diff --git a/net/eth.c b/net/eth.c
index eac4f7b..8e6acfe 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -1,16 +1,21 @@
/*
- * (C) Copyright 2001-2010
+ * (C) Copyright 2001-2015
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ * Joe Hershberger, National Instruments
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <command.h>
+#include <dm.h>
#include <net.h>
#include <miiphy.h>
#include <phy.h>
#include <asm/errno.h>
+#include <dm/device-internal.h>
+
+DECLARE_GLOBAL_DATA_PTR;
void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
{
@@ -27,7 +32,7 @@ void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
int eth_getenv_enetaddr(char *name, uchar *enetaddr)
{
eth_parse_enetaddr(getenv(name), enetaddr);
- return is_valid_ether_addr(enetaddr);
+ return is_valid_ethaddr(enetaddr);
}
int eth_setenv_enetaddr(char *name, const uchar *enetaddr)
@@ -55,15 +60,28 @@ static inline int eth_setenv_enetaddr_by_index(const char *base_name, int index,
return eth_setenv_enetaddr(enetvar, enetaddr);
}
+static void eth_env_init(void)
+{
+ const char *s;
+
+ s = getenv("bootfile");
+ if (s != NULL)
+ copy_filename(net_boot_file_name, s,
+ sizeof(net_boot_file_name));
+}
static int eth_mac_skip(int index)
{
char enetvar[15];
char *skip_state;
+
sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
- return ((skip_state = getenv(enetvar)) != NULL);
+ skip_state = getenv(enetvar);
+ return skip_state != NULL;
}
+static void eth_current_changed(void);
+
/*
* CPU and board-specific Ethernet initializations. Aliased function
* signals caller to move on
@@ -75,6 +93,472 @@ static int __def_eth_init(bd_t *bis)
int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
+static void eth_common_init(void)
+{
+ bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
+#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
+ miiphy_init();
+#endif
+
+#ifdef CONFIG_PHYLIB
+ phy_init();
+#endif
+
+ eth_env_init();
+
+ /*
+ * If board-specific initialization exists, call it.
+ * If not, call a CPU-specific one
+ */
+ if (board_eth_init != __def_eth_init) {
+ if (board_eth_init(gd->bd) < 0)
+ printf("Board Net Initialization Failed\n");
+ } else if (cpu_eth_init != __def_eth_init) {
+ if (cpu_eth_init(gd->bd) < 0)
+ printf("CPU Net Initialization Failed\n");
+ } else {
+ printf("Net Initialization Skipped\n");
+ }
+}
+
+#ifdef CONFIG_DM_ETH
+/**
+ * struct eth_device_priv - private structure for each Ethernet device
+ *
+ * @state: The state of the Ethernet MAC driver (defined by enum eth_state_t)
+ */
+struct eth_device_priv {
+ enum eth_state_t state;
+};
+
+/**
+ * struct eth_uclass_priv - The structure attached to the uclass itself
+ *
+ * @current: The Ethernet device that the network functions are using
+ */
+struct eth_uclass_priv {
+ struct udevice *current;
+};
+
+/* eth_errno - This stores the most recent failure code from DM functions */
+static int eth_errno;
+
+static struct eth_uclass_priv *eth_get_uclass_priv(void)
+{
+ struct uclass *uc;
+
+ uclass_get(UCLASS_ETH, &uc);
+ assert(uc);
+ return uc->priv;
+}
+
+static void eth_set_current_to_next(void)
+{
+ struct eth_uclass_priv *uc_priv;
+
+ uc_priv = eth_get_uclass_priv();
+ if (uc_priv->current)
+ uclass_next_device(&uc_priv->current);
+ if (!uc_priv->current)
+ uclass_first_device(UCLASS_ETH, &uc_priv->current);
+}
+
+/*
+ * Typically this will simply return the active device.
+ * In the case where the most recent active device was unset, this will attempt
+ * to return the first device. If that device doesn't exist or fails to probe,
+ * this function will return NULL.
+ */
+struct udevice *eth_get_dev(void)
+{
+ struct eth_uclass_priv *uc_priv;
+
+ uc_priv = eth_get_uclass_priv();
+ if (!uc_priv->current)
+ eth_errno = uclass_first_device(UCLASS_ETH,
+ &uc_priv->current);
+ return uc_priv->current;
+}
+
+/*
+ * Typically this will just store a device pointer.
+ * In case it was not probed, we will attempt to do so.
+ * dev may be NULL to unset the active device.
+ */
+static void eth_set_dev(struct udevice *dev)
+{
+ if (dev && !device_active(dev))
+ eth_errno = device_probe(dev);
+ eth_get_uclass_priv()->current = dev;
+}
+
+/*
+ * Find the udevice that either has the name passed in as devname or has an
+ * alias named devname.
+ */
+struct udevice *eth_get_dev_by_name(const char *devname)
+{
+ int seq = -1;
+ char *endp = NULL;
+ const char *startp = NULL;
+ struct udevice *it;
+ struct uclass *uc;
+
+ /* Must be longer than 3 to be an alias */
+ if (strlen(devname) > strlen("eth")) {
+ startp = devname + strlen("eth");
+ seq = simple_strtoul(startp, &endp, 10);
+ }
+
+ uclass_get(UCLASS_ETH, &uc);
+ uclass_foreach_dev(it, uc) {
+ /*
+ * We need the seq to be valid, so try to probe it.
+ * If the probe fails, the seq will not match since it will be
+ * -1 instead of what we are looking for.
+ * We don't care about errors from probe here. Either they won't
+ * match an alias or it will match a literal name and we'll pick
+ * up the error when we try to probe again in eth_set_dev().
+ */
+ device_probe(it);
+ /*
+ * Check for the name or the sequence number to match
+ */
+ if (strcmp(it->name, devname) == 0 ||
+ (endp > startp && it->seq == seq))
+ return it;
+ }
+
+ return NULL;
+}
+
+unsigned char *eth_get_ethaddr(void)
+{
+ struct eth_pdata *pdata;
+
+ if (eth_get_dev()) {
+ pdata = eth_get_dev()->platdata;
+ return pdata->enetaddr;
+ }
+
+ return NULL;
+}
+
+/* Set active state without calling start on the driver */
+int eth_init_state_only(void)
+{
+ struct udevice *current;
+ struct eth_device_priv *priv;
+
+ current = eth_get_dev();
+ if (!current || !device_active(current))
+ return -EINVAL;
+
+ priv = current->uclass_priv;
+ priv->state = ETH_STATE_ACTIVE;
+
+ return 0;
+}
+
+/* Set passive state without calling stop on the driver */
+void eth_halt_state_only(void)
+{
+ struct udevice *current;
+ struct eth_device_priv *priv;
+
+ current = eth_get_dev();
+ if (!current || !device_active(current))
+ return;
+
+ priv = current->uclass_priv;
+ priv->state = ETH_STATE_PASSIVE;
+}
+
+int eth_get_dev_index(void)
+{
+ if (eth_get_dev())
+ return eth_get_dev()->seq;
+ return -1;
+}
+
+int eth_init(void)
+{
+ struct udevice *current;
+ struct udevice *old_current;
+ int ret = -ENODEV;
+
+ current = eth_get_dev();
+ if (!current) {
+ printf("No ethernet found.\n");
+ return -ENODEV;
+ }
+
+ old_current = current;
+ do {
+ debug("Trying %s\n", current->name);
+
+ if (device_active(current)) {
+ uchar env_enetaddr[6];
+ struct eth_pdata *pdata = current->platdata;
+
+ /* Sync environment with network device */
+ if (eth_getenv_enetaddr_by_index("eth", current->seq,
+ env_enetaddr))
+ memcpy(pdata->enetaddr, env_enetaddr, 6);
+ else
+ memset(pdata->enetaddr, 0, 6);
+
+ ret = eth_get_ops(current)->start(current);
+ if (ret >= 0) {
+ struct eth_device_priv *priv =
+ current->uclass_priv;
+
+ priv->state = ETH_STATE_ACTIVE;
+ return 0;
+ }
+ } else {
+ ret = eth_errno;
+ }
+
+ debug("FAIL\n");
+
+ /*
+ * If ethrotate is enabled, this will change "current",
+ * otherwise we will drop out of this while loop immediately
+ */
+ eth_try_another(0);
+ /* This will ensure the new "current" attempted to probe */
+ current = eth_get_dev();
+ } while (old_current != current);
+
+ return ret;
+}
+
+void eth_halt(void)
+{
+ struct udevice *current;
+ struct eth_device_priv *priv;
+
+ current = eth_get_dev();
+ if (!current || !device_active(current))
+ return;
+
+ eth_get_ops(current)->stop(current);
+ priv = current->uclass_priv;
+ priv->state = ETH_STATE_PASSIVE;
+}
+
+int eth_send(void *packet, int length)
+{
+ struct udevice *current;
+ int ret;
+
+ current = eth_get_dev();
+ if (!current)
+ return -ENODEV;
+
+ if (!device_active(current))
+ return -EINVAL;
+
+ ret = eth_get_ops(current)->send(current, packet, length);
+ if (ret < 0) {
+ /* We cannot completely return the error at present */
+ debug("%s: send() returned error %d\n", __func__, ret);
+ }
+ return ret;
+}
+
+int eth_rx(void)
+{
+ struct udevice *current;
+ uchar *packet;
+ int ret;
+ int i;
+
+ current = eth_get_dev();
+ if (!current)
+ return -ENODEV;
+
+ if (!device_active(current))
+ return -EINVAL;
+
+ /* Process up to 32 packets at one time */
+ for (i = 0; i < 32; i++) {
+ ret = eth_get_ops(current)->recv(current, &packet);
+ if (ret > 0)
+ net_process_received_packet(packet, ret);
+ if (ret >= 0 && eth_get_ops(current)->free_pkt)
+ eth_get_ops(current)->free_pkt(current, packet, ret);
+ if (ret <= 0)
+ break;
+ }
+ if (ret == -EAGAIN)
+ ret = 0;
+ if (ret < 0) {
+ /* We cannot completely return the error at present */
+ debug("%s: recv() returned error %d\n", __func__, ret);
+ }
+ return ret;
+}
+
+static int eth_write_hwaddr(struct udevice *dev)
+{
+ struct eth_pdata *pdata = dev->platdata;
+ int ret = 0;
+
+ if (!dev || !device_active(dev))
+ return -EINVAL;
+
+ /* seq is valid since the device is active */
+ if (eth_get_ops(dev)->write_hwaddr && !eth_mac_skip(dev->seq)) {
+ if (!is_valid_ethaddr(pdata->enetaddr)) {
+ printf("\nError: %s address %pM illegal value\n",
+ dev->name, pdata->enetaddr);
+ return -EINVAL;
+ }
+
+ ret = eth_get_ops(dev)->write_hwaddr(dev);
+ if (ret)
+ printf("\nWarning: %s failed to set MAC address\n",
+ dev->name);
+ }
+
+ return ret;
+}
+
+int eth_initialize(void)
+{
+ int num_devices = 0;
+ struct udevice *dev;
+
+ eth_common_init();
+
+ /*
+ * Devices need to write the hwaddr even if not started so that Linux
+ * will have access to the hwaddr that u-boot stored for the device.
+ * This is accomplished by attempting to probe each device and calling
+ * their write_hwaddr() operation.
+ */
+ uclass_first_device(UCLASS_ETH, &dev);
+ if (!dev) {
+ printf("No ethernet found.\n");
+ bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
+ } else {
+ char *ethprime = getenv("ethprime");
+ struct udevice *prime_dev = NULL;
+
+ if (ethprime)
+ prime_dev = eth_get_dev_by_name(ethprime);
+ if (prime_dev) {
+ eth_set_dev(prime_dev);
+ eth_current_changed();
+ } else {
+ eth_set_dev(NULL);
+ }
+
+ bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
+ do {
+ if (num_devices)
+ printf(", ");
+
+ printf("eth%d: %s", dev->seq, dev->name);
+
+ if (ethprime && dev == prime_dev)
+ printf(" [PRIME]");
+
+ eth_write_hwaddr(dev);
+
+ uclass_next_device(&dev);
+ num_devices++;
+ } while (dev);
+
+ putc('\n');
+ }
+
+ return num_devices;
+}
+
+static int eth_post_bind(struct udevice *dev)
+{
+ if (strchr(dev->name, ' ')) {
+ printf("\nError: eth device name \"%s\" has a space!\n",
+ dev->name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int eth_pre_unbind(struct udevice *dev)
+{
+ /* Don't hang onto a pointer that is going away */
+ if (dev == eth_get_uclass_priv()->current)
+ eth_set_dev(NULL);
+
+ return 0;
+}
+
+static int eth_post_probe(struct udevice *dev)
+{
+ struct eth_device_priv *priv = dev->uclass_priv;
+ struct eth_pdata *pdata = dev->platdata;
+ unsigned char env_enetaddr[6];
+
+ priv->state = ETH_STATE_INIT;
+
+ /* Check if the device has a MAC address in ROM */
+ if (eth_get_ops(dev)->read_rom_hwaddr)
+ eth_get_ops(dev)->read_rom_hwaddr(dev);
+
+ eth_getenv_enetaddr_by_index("eth", dev->seq, env_enetaddr);
+ if (!is_zero_ethaddr(env_enetaddr)) {
+ if (!is_zero_ethaddr(pdata->enetaddr) &&
+ memcmp(pdata->enetaddr, env_enetaddr, 6)) {
+ printf("\nWarning: %s MAC addresses don't match:\n",
+ dev->name);
+ printf("Address in SROM is %pM\n",
+ pdata->enetaddr);
+ printf("Address in environment is %pM\n",
+ env_enetaddr);
+ }
+
+ /* Override the ROM MAC address */
+ memcpy(pdata->enetaddr, env_enetaddr, 6);
+ } else if (is_valid_ethaddr(pdata->enetaddr)) {
+ eth_setenv_enetaddr_by_index("eth", dev->seq, pdata->enetaddr);
+ printf("\nWarning: %s using MAC address from ROM\n",
+ dev->name);
+ } else if (is_zero_ethaddr(pdata->enetaddr)) {
+ printf("\nError: %s address not set.\n",
+ dev->name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int eth_pre_remove(struct udevice *dev)
+{
+ eth_get_ops(dev)->stop(dev);
+
+ return 0;
+}
+
+UCLASS_DRIVER(eth) = {
+ .name = "eth",
+ .id = UCLASS_ETH,
+ .post_bind = eth_post_bind,
+ .pre_unbind = eth_pre_unbind,
+ .post_probe = eth_post_probe,
+ .pre_remove = eth_pre_remove,
+ .priv_auto_alloc_size = sizeof(struct eth_uclass_priv),
+ .per_device_auto_alloc_size = sizeof(struct eth_device_priv),
+ .flags = DM_UC_FLAG_SEQ_ALIAS,
+};
+#endif
+
+#ifndef CONFIG_DM_ETH
+
#ifdef CONFIG_API
static struct {
uchar data[PKTSIZE];
@@ -87,6 +571,16 @@ static unsigned int eth_rcv_current, eth_rcv_last;
static struct eth_device *eth_devices;
struct eth_device *eth_current;
+static void eth_set_current_to_next(void)
+{
+ eth_current = eth_current->next;
+}
+
+static void eth_set_dev(struct eth_device *dev)
+{
+ eth_current = dev;
+}
+
struct eth_device *eth_get_dev_by_name(const char *devname)
{
struct eth_device *dev, *target_dev;
@@ -137,27 +631,6 @@ int eth_get_dev_index(void)
return eth_current->index;
}
-static void eth_current_changed(void)
-{
- char *act = getenv("ethact");
- /* update current ethernet name */
- if (eth_current) {
- if (act == NULL || strcmp(act, eth_current->name) != 0)
- setenv("ethact", eth_current->name);
- }
- /*
- * remove the variable completely if there is no active
- * interface
- */
- else if (act != NULL)
- setenv("ethact", NULL);
-}
-
-static int eth_address_set(unsigned char *addr)
-{
- return memcmp(addr, "\0\0\0\0\0\0", 6);
-}
-
int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
int eth_number)
{
@@ -166,39 +639,40 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr);
- if (eth_address_set(env_enetaddr)) {
- if (eth_address_set(dev->enetaddr) &&
- memcmp(dev->enetaddr, env_enetaddr, 6)) {
+ if (!is_zero_ethaddr(env_enetaddr)) {
+ if (!is_zero_ethaddr(dev->enetaddr) &&
+ memcmp(dev->enetaddr, env_enetaddr, 6)) {
printf("\nWarning: %s MAC addresses don't match:\n",
- dev->name);
+ dev->name);
printf("Address in SROM is %pM\n",
- dev->enetaddr);
+ dev->enetaddr);
printf("Address in environment is %pM\n",
- env_enetaddr);
+ env_enetaddr);
}
memcpy(dev->enetaddr, env_enetaddr, 6);
- } else if (is_valid_ether_addr(dev->enetaddr)) {
+ } else if (is_valid_ethaddr(dev->enetaddr)) {
eth_setenv_enetaddr_by_index(base_name, eth_number,
dev->enetaddr);
printf("\nWarning: %s using MAC address from net device\n",
- dev->name);
- } else if (!(eth_address_set(dev->enetaddr))) {
+ dev->name);
+ } else if (is_zero_ethaddr(dev->enetaddr)) {
printf("\nError: %s address not set.\n",
dev->name);
return -EINVAL;
}
if (dev->write_hwaddr && !eth_mac_skip(eth_number)) {
- if (!is_valid_ether_addr(dev->enetaddr)) {
+ if (!is_valid_ethaddr(dev->enetaddr)) {
printf("\nError: %s address %pM illegal value\n",
- dev->name, dev->enetaddr);
+ dev->name, dev->enetaddr);
return -EINVAL;
}
ret = dev->write_hwaddr(dev);
if (ret)
- printf("\nWarning: %s failed to set MAC address\n", dev->name);
+ printf("\nWarning: %s failed to set MAC address\n",
+ dev->name);
}
return ret;
@@ -212,7 +686,8 @@ int eth_register(struct eth_device *dev)
assert(strlen(dev->name) < sizeof(dev->name));
if (!eth_devices) {
- eth_current = eth_devices = dev;
+ eth_devices = dev;
+ eth_current = dev;
eth_current_changed();
} else {
for (d = eth_devices; d->next != eth_devices; d = d->next)
@@ -233,7 +708,7 @@ int eth_unregister(struct eth_device *dev)
/* No device */
if (!eth_devices)
- return -1;
+ return -ENODEV;
for (cur = eth_devices; cur->next != eth_devices && cur->next != dev;
cur = cur->next)
@@ -241,7 +716,7 @@ int eth_unregister(struct eth_device *dev)
/* Device not found */
if (cur->next != dev)
- return -1;
+ return -ENODEV;
cur->next = dev->next;
@@ -256,43 +731,13 @@ int eth_unregister(struct eth_device *dev)
return 0;
}
-static void eth_env_init(bd_t *bis)
-{
- const char *s;
-
- if ((s = getenv("bootfile")) != NULL)
- copy_filename(BootFile, s, sizeof(BootFile));
-}
-
-int eth_initialize(bd_t *bis)
+int eth_initialize(void)
{
int num_devices = 0;
+
eth_devices = NULL;
eth_current = NULL;
-
- bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
-#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
- miiphy_init();
-#endif
-
-#ifdef CONFIG_PHYLIB
- phy_init();
-#endif
-
- eth_env_init(bis);
-
- /*
- * If board-specific initialization exists, call it.
- * If not, call a CPU-specific one
- */
- if (board_eth_init != __def_eth_init) {
- if (board_eth_init(bis) < 0)
- printf("Board Net Initialization Failed\n");
- } else if (cpu_eth_init != __def_eth_init) {
- if (cpu_eth_init(bis) < 0)
- printf("CPU Net Initialization Failed\n");
- } else
- printf("Net Initialization Skipped\n");
+ eth_common_init();
if (!eth_devices) {
puts("No ethernet found.\n");
@@ -335,14 +780,14 @@ int eth_initialize(bd_t *bis)
* mcast_addr: multicast ipaddr from which multicast Mac is made
* join: 1=join, 0=leave.
*/
-int eth_mcast_join(IPaddr_t mcast_ip, u8 join)
+int eth_mcast_join(struct in_addr mcast_ip, int join)
{
u8 mcast_mac[6];
if (!eth_current || !eth_current->mcast)
return -1;
- mcast_mac[5] = htonl(mcast_ip) & 0xff;
- mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff;
- mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f;
+ mcast_mac[5] = htonl(mcast_ip.s_addr) & 0xff;
+ mcast_mac[4] = (htonl(mcast_ip.s_addr)>>8) & 0xff;
+ mcast_mac[3] = (htonl(mcast_ip.s_addr)>>16) & 0x7f;
mcast_mac[2] = 0x5e;
mcast_mac[1] = 0x0;
mcast_mac[0] = 0x1;
@@ -376,13 +821,13 @@ u32 ether_crc(size_t len, unsigned char const *p)
#endif
-int eth_init(bd_t *bis)
+int eth_init(void)
{
struct eth_device *old_current, *dev;
if (!eth_current) {
puts("No ethernet found.\n");
- return -1;
+ return -ENODEV;
}
/* Sync environment with network devices */
@@ -401,7 +846,7 @@ int eth_init(bd_t *bis)
do {
debug("Trying %s\n", eth_current->name);
- if (eth_current->init(eth_current, bis) >= 0) {
+ if (eth_current->init(eth_current, gd->bd) >= 0) {
eth_current->state = ETH_STATE_ACTIVE;
return 0;
@@ -411,7 +856,7 @@ int eth_init(bd_t *bis)
eth_try_another(0);
} while (old_current != eth_current);
- return -1;
+ return -ETIMEDOUT;
}
void eth_halt(void)
@@ -427,7 +872,7 @@ void eth_halt(void)
int eth_send(void *packet, int length)
{
if (!eth_current)
- return -1;
+ return -ENODEV;
return eth_current->send(eth_current, packet, length);
}
@@ -435,10 +880,11 @@ int eth_send(void *packet, int length)
int eth_rx(void)
{
if (!eth_current)
- return -1;
+ return -ENODEV;
return eth_current->recv(eth_current);
}
+#endif /* ifndef CONFIG_DM_ETH */
#ifdef CONFIG_API
static void eth_save_packet(void *packet, int length)
@@ -484,9 +930,25 @@ int eth_receive(void *packet, int length)
}
#endif /* CONFIG_API */
+static void eth_current_changed(void)
+{
+ char *act = getenv("ethact");
+ /* update current ethernet name */
+ if (eth_get_dev()) {
+ if (act == NULL || strcmp(act, eth_get_name()) != 0)
+ setenv("ethact", eth_get_name());
+ }
+ /*
+ * remove the variable completely if there is no active
+ * interface
+ */
+ else if (act != NULL)
+ setenv("ethact", NULL);
+}
+
void eth_try_another(int first_restart)
{
- static struct eth_device *first_failed;
+ static void *first_failed;
char *ethrotate;
/*
@@ -497,48 +959,50 @@ void eth_try_another(int first_restart)
if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
return;
- if (!eth_current)
+ if (!eth_get_dev())
return;
if (first_restart)
- first_failed = eth_current;
+ first_failed = eth_get_dev();
- eth_current = eth_current->next;
+ eth_set_current_to_next();
eth_current_changed();
- if (first_failed == eth_current)
- NetRestartWrap = 1;
+ if (first_failed == eth_get_dev())
+ net_restart_wrap = 1;
}
void eth_set_current(void)
{
static char *act;
static int env_changed_id;
- struct eth_device *old_current;
int env_id;
- if (!eth_current) /* XXX no current */
- return;
-
env_id = get_env_id();
if ((act == NULL) || (env_changed_id != env_id)) {
act = getenv("ethact");
env_changed_id = env_id;
}
- if (act != NULL) {
- old_current = eth_current;
- do {
- if (strcmp(eth_current->name, act) == 0)
- return;
- eth_current = eth_current->next;
- } while (old_current != eth_current);
+
+ if (act == NULL) {
+ char *ethprime = getenv("ethprime");
+ void *dev = NULL;
+
+ if (ethprime)
+ dev = eth_get_dev_by_name(ethprime);
+ if (dev)
+ eth_set_dev(dev);
+ else
+ eth_set_dev(NULL);
+ } else {
+ eth_set_dev(eth_get_dev_by_name(act));
}
eth_current_changed();
}
-char *eth_get_name(void)
+const char *eth_get_name(void)
{
- return eth_current ? eth_current->name : "unknown";
+ return eth_get_dev() ? eth_get_dev()->name : "unknown";
}
diff --git a/net/link_local.c b/net/link_local.c
index 4152fae..27851b6 100644
--- a/net/link_local.c
+++ b/net/link_local.c
@@ -49,7 +49,7 @@ static enum ll_state_t {
DISABLED
} state = DISABLED;
-static IPaddr_t ip;
+static struct in_addr ip;
static int timeout_ms = -1;
static unsigned deadline_ms;
static unsigned conflicts;
@@ -64,14 +64,16 @@ static void link_local_timeout(void);
* Pick a random link local IP address on 169.254/16, except that
* the first and last 256 addresses are reserved.
*/
-static IPaddr_t pick(void)
+static struct in_addr pick(void)
{
unsigned tmp;
+ struct in_addr ip;
do {
tmp = rand_r(&seed) & IN_CLASSB_HOST;
} while (tmp > (IN_CLASSB_HOST - 0x0200));
- return (IPaddr_t) htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
+ ip.s_addr = htonl((LINKLOCAL_ADDR + 0x0100) + tmp);
+ return ip;
}
/**
@@ -95,23 +97,24 @@ static void configure_wait(void)
deadline_ms = MONOTONIC_MS() + timeout_ms;
debug_cond(DEBUG_DEV_PKT, "...wait %d %s nprobes=%u, nclaims=%u\n",
- timeout_ms, eth_get_name(), nprobes, nclaims);
+ timeout_ms, eth_get_name(), nprobes, nclaims);
- NetSetTimeout(timeout_ms, link_local_timeout);
+ net_set_timeout_handler(timeout_ms, link_local_timeout);
}
void link_local_start(void)
{
- ip = getenv_IPaddr("llipaddr");
- if (ip != 0 && (ntohl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
+ ip = getenv_ip("llipaddr");
+ if (ip.s_addr != 0 &&
+ (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
puts("invalid link address");
net_set_state(NETLOOP_FAIL);
return;
}
- NetOurSubnetMask = IN_CLASSB_NET;
+ net_netmask.s_addr = IN_CLASSB_NET;
seed = seed_mac();
- if (ip == 0)
+ if (ip.s_addr == 0)
ip = pick();
state = PROBE;
@@ -131,10 +134,12 @@ static void link_local_timeout(void)
/* timeouts in the PROBE state mean no conflicting ARP packets
have been received, so we can progress through the states */
if (nprobes < PROBE_NUM) {
+ struct in_addr zero_ip = {.s_addr = 0};
+
nprobes++;
debug_cond(DEBUG_LL_STATE, "probe/%u %s@%pI4\n",
- nprobes, eth_get_name(), &ip);
- arp_raw_request(0, NetEtherNullAddr, ip);
+ nprobes, eth_get_name(), &ip);
+ arp_raw_request(zero_ip, net_null_ethaddr, ip);
timeout_ms = PROBE_MIN * 1000;
timeout_ms += random_delay_ms(PROBE_MAX - PROBE_MIN);
} else {
@@ -142,8 +147,8 @@ static void link_local_timeout(void)
state = ANNOUNCE;
nclaims = 0;
debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
- nclaims, eth_get_name(), &ip);
- arp_raw_request(ip, NetOurEther, ip);
+ nclaims, eth_get_name(), &ip);
+ arp_raw_request(ip, net_ethaddr, ip);
timeout_ms = ANNOUNCE_INTERVAL * 1000;
}
break;
@@ -154,8 +159,8 @@ static void link_local_timeout(void)
state = ANNOUNCE;
nclaims = 0;
debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
- nclaims, eth_get_name(), &ip);
- arp_raw_request(ip, NetOurEther, ip);
+ nclaims, eth_get_name(), &ip);
+ arp_raw_request(ip, net_ethaddr, ip);
timeout_ms = ANNOUNCE_INTERVAL * 1000;
break;
case ANNOUNCE:
@@ -165,19 +170,19 @@ static void link_local_timeout(void)
if (nclaims < ANNOUNCE_NUM) {
nclaims++;
debug_cond(DEBUG_LL_STATE, "announce/%u %s@%pI4\n",
- nclaims, eth_get_name(), &ip);
- arp_raw_request(ip, NetOurEther, ip);
+ nclaims, eth_get_name(), &ip);
+ arp_raw_request(ip, net_ethaddr, ip);
timeout_ms = ANNOUNCE_INTERVAL * 1000;
} else {
/* Switch to monitor state */
state = MONITOR;
printf("Successfully assigned %pI4\n", &ip);
- NetCopyIP(&NetOurIP, &ip);
+ net_copy_ip(&net_ip, &ip);
ready = 1;
conflicts = 0;
timeout_ms = -1;
/* Never timeout in the monitor state */
- NetSetTimeout(0, NULL);
+ net_set_timeout_handler(0, NULL);
/* NOTE: all other exit paths should deconfig ... */
net_set_state(NETLOOP_SUCCESS);
@@ -206,7 +211,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
{
int source_ip_conflict;
int target_ip_conflict;
- IPaddr_t null_ip = 0;
+ struct in_addr null_ip = {.s_addr = 0};
if (state == DISABLED)
return;
@@ -219,7 +224,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
/* Current time is greater than the expected timeout
time. This should never happen */
debug_cond(DEBUG_LL_STATE,
- "missed an expected timeout\n");
+ "missed an expected timeout\n");
timeout_ms = 0;
} else {
debug_cond(DEBUG_INT_STATE, "adjusting timeout\n");
@@ -234,9 +239,8 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
* FIXME: links routinely go down;
*/
bb_error_msg("iface %s is down", eth_get_name());
- if (ready) {
+ if (ready)
run(argv, "deconfig", &ip);
- }
return EXIT_FAILURE;
}
continue;
@@ -244,18 +248,17 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
#endif
debug_cond(DEBUG_INT_STATE, "%s recv arp type=%d, op=%d,\n",
- eth_get_name(), ntohs(arp->ar_pro),
- ntohs(arp->ar_op));
+ eth_get_name(), ntohs(arp->ar_pro),
+ ntohs(arp->ar_op));
debug_cond(DEBUG_INT_STATE, "\tsource=%pM %pI4\n",
- &arp->ar_sha,
- &arp->ar_spa);
+ &arp->ar_sha,
+ &arp->ar_spa);
debug_cond(DEBUG_INT_STATE, "\ttarget=%pM %pI4\n",
- &arp->ar_tha,
- &arp->ar_tpa);
+ &arp->ar_tha,
+ &arp->ar_tpa);
- if (arp->ar_op != htons(ARPOP_REQUEST)
- && arp->ar_op != htons(ARPOP_REPLY)
- ) {
+ if (arp->ar_op != htons(ARPOP_REQUEST) &&
+ arp->ar_op != htons(ARPOP_REPLY)) {
configure_wait();
return;
}
@@ -263,11 +266,9 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
source_ip_conflict = 0;
target_ip_conflict = 0;
- if (memcmp(&arp->ar_spa, &ip, ARP_PLEN) == 0
- && memcmp(&arp->ar_sha, NetOurEther, ARP_HLEN) != 0
- ) {
+ if (memcmp(&arp->ar_spa, &ip, ARP_PLEN) == 0 &&
+ memcmp(&arp->ar_sha, net_ethaddr, ARP_HLEN) != 0)
source_ip_conflict = 1;
- }
/*
* According to RFC 3927, section 2.2.1:
@@ -279,13 +280,13 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
if (arp->ar_op == htons(ARPOP_REQUEST) &&
memcmp(&arp->ar_spa, &null_ip, ARP_PLEN) == 0 &&
memcmp(&arp->ar_tpa, &ip, ARP_PLEN) == 0 &&
- memcmp(&arp->ar_sha, NetOurEther, ARP_HLEN) != 0) {
+ memcmp(&arp->ar_sha, net_ethaddr, ARP_HLEN) != 0) {
target_ip_conflict = 1;
}
debug_cond(DEBUG_NET_PKT,
- "state = %d, source ip conflict = %d, target ip conflict = "
- "%d\n", state, source_ip_conflict, target_ip_conflict);
+ "state = %d, source ip conflict = %d, target ip conflict = "
+ "%d\n", state, source_ip_conflict, target_ip_conflict);
switch (state) {
case PROBE:
case ANNOUNCE:
@@ -313,7 +314,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
debug("monitor conflict -- defending\n");
state = DEFEND;
timeout_ms = DEFEND_INTERVAL * 1000;
- arp_raw_request(ip, NetOurEther, ip);
+ arp_raw_request(ip, net_ethaddr, ip);
}
break;
case DEFEND:
@@ -322,7 +323,7 @@ void link_local_receive_arp(struct arp_hdr *arp, int len)
state = PROBE;
debug("defend conflict -- starting over\n");
ready = 0;
- NetOurIP = 0;
+ net_ip.s_addr = 0;
/* restart the whole protocol */
ip = pick();
diff --git a/net/net.c b/net/net.c
index b60ce62..a365df0 100644
--- a/net/net.c
+++ b/net/net.c
@@ -84,6 +84,7 @@
#include <common.h>
#include <command.h>
#include <environment.h>
+#include <errno.h>
#include <net.h>
#if defined(CONFIG_STATUS_LED)
#include <miiphy.h>
@@ -111,82 +112,74 @@ DECLARE_GLOBAL_DATA_PTR;
/** BOOTP EXTENTIONS **/
/* Our subnet mask (0=unknown) */
-IPaddr_t NetOurSubnetMask;
+struct in_addr net_netmask;
/* Our gateways IP address */
-IPaddr_t NetOurGatewayIP;
+struct in_addr net_gateway;
/* Our DNS IP address */
-IPaddr_t NetOurDNSIP;
+struct in_addr net_dns_server;
#if defined(CONFIG_BOOTP_DNS2)
/* Our 2nd DNS IP address */
-IPaddr_t NetOurDNS2IP;
+struct in_addr net_dns_server2;
#endif
-/* Our NIS domain */
-char NetOurNISDomain[32] = {0,};
-/* Our hostname */
-char NetOurHostName[32] = {0,};
-/* Our bootpath */
-char NetOurRootPath[64] = {0,};
-/* Our bootfile size in blocks */
-ushort NetBootFileSize;
#ifdef CONFIG_MCAST_TFTP /* Multicast TFTP */
-IPaddr_t Mcast_addr;
+struct in_addr net_mcast_addr;
#endif
/** END OF BOOTP EXTENTIONS **/
-/* The actual transferred size of the bootfile (in bytes) */
-ulong NetBootFileXferSize;
/* Our ethernet address */
-uchar NetOurEther[6];
+u8 net_ethaddr[6];
/* Boot server enet address */
-uchar NetServerEther[6];
+u8 net_server_ethaddr[6];
/* Our IP addr (0 = unknown) */
-IPaddr_t NetOurIP;
+struct in_addr net_ip;
/* Server IP addr (0 = unknown) */
-IPaddr_t NetServerIP;
+struct in_addr net_server_ip;
/* Current receive packet */
-uchar *NetRxPacket;
+uchar *net_rx_packet;
/* Current rx packet length */
-int NetRxPacketLen;
+int net_rx_packet_len;
/* IP packet ID */
-unsigned NetIPID;
+static unsigned net_ip_id;
/* Ethernet bcast address */
-uchar NetBcastAddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-uchar NetEtherNullAddr[6];
+const u8 net_bcast_ethaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+const u8 net_null_ethaddr[6];
#ifdef CONFIG_API
-void (*push_packet)(void *, int len) = 0;
+void (*push_packet)(void *, int len) = 0;
#endif
/* Network loop state */
enum net_loop_state net_state;
/* Tried all network devices */
-int NetRestartWrap;
+int net_restart_wrap;
/* Network loop restarted */
-static int NetRestarted;
+static int net_restarted;
/* At least one device configured */
-static int NetDevExists;
+static int net_dev_exists;
/* XXX in both little & big endian machines 0xFFFF == ntohs(-1) */
/* default is without VLAN */
-ushort NetOurVLAN = 0xFFFF;
+ushort net_our_vlan = 0xFFFF;
/* ditto */
-ushort NetOurNativeVLAN = 0xFFFF;
+ushort net_native_vlan = 0xFFFF;
/* Boot File name */
-char BootFile[128];
+char net_boot_file_name[128];
+/* The actual transferred size of the bootfile (in bytes) */
+u32 net_boot_file_size;
+/* Boot file size in blocks as reported by the DHCP server */
+u32 net_boot_file_expected_size_in_blocks;
#if defined(CONFIG_CMD_SNTP)
/* NTP server IP address */
-IPaddr_t NetNtpServerIP;
+struct in_addr net_ntp_server;
/* offset time from UTC */
-int NetTimeOffset;
+int net_ntp_time_offset;
#endif
-static uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
-
-/* Receive packet */
-uchar *NetRxPackets[PKTBUFSRX];
-
+static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
+/* Receive packets */
+uchar *net_rx_packets[PKTBUFSRX];
/* Current UDP RX packet handler */
static rxhand_f *udp_packet_handler;
/* Current ARP RX packet handler */
@@ -196,17 +189,17 @@ static rxhand_f *arp_packet_handler;
static rxhand_icmp_f *packet_icmp_handler;
#endif
/* Current timeout handler */
-static thand_f *timeHandler;
+static thand_f *time_handler;
/* Time base value */
-static ulong timeStart;
+static ulong time_start;
/* Current timeout value */
-static ulong timeDelta;
+static ulong time_delta;
/* THE transmit packet */
-uchar *NetTxPacket;
+uchar *net_tx_packet;
static int net_check_prereq(enum proto_t protocol);
-static int NetTryCount;
+static int net_try_count;
int __maybe_unused net_busy_flag;
@@ -218,7 +211,8 @@ static int on_bootfile(const char *name, const char *value, enum env_op op,
switch (op) {
case env_op_create:
case env_op_overwrite:
- copy_filename(BootFile, value, sizeof(BootFile));
+ copy_filename(net_boot_file_name, value,
+ sizeof(net_boot_file_name));
break;
default:
break;
@@ -241,7 +235,7 @@ void net_auto_load(void)
/*
* Use NFS to load the bootfile.
*/
- NfsStart();
+ nfs_start();
return;
}
#endif
@@ -253,29 +247,29 @@ void net_auto_load(void)
net_set_state(NETLOOP_SUCCESS);
return;
}
- TftpStart(TFTPGET);
+ tftp_start(TFTPGET);
}
-static void NetInitLoop(void)
+static void net_init_loop(void)
{
static int env_changed_id;
int env_id = get_env_id();
/* update only when the environment has changed */
if (env_changed_id != env_id) {
- NetOurIP = getenv_IPaddr("ipaddr");
- NetOurGatewayIP = getenv_IPaddr("gatewayip");
- NetOurSubnetMask = getenv_IPaddr("netmask");
- NetServerIP = getenv_IPaddr("serverip");
- NetOurNativeVLAN = getenv_VLAN("nvlan");
- NetOurVLAN = getenv_VLAN("vlan");
+ net_ip = getenv_ip("ipaddr");
+ net_gateway = getenv_ip("gatewayip");
+ net_netmask = getenv_ip("netmask");
+ net_server_ip = getenv_ip("serverip");
+ net_native_vlan = getenv_vlan("nvlan");
+ net_our_vlan = getenv_vlan("vlan");
#if defined(CONFIG_CMD_DNS)
- NetOurDNSIP = getenv_IPaddr("dnsip");
+ net_dns_server = getenv_ip("dnsip");
#endif
env_changed_id = env_id;
}
if (eth_get_dev())
- memcpy(NetOurEther, eth_get_dev()->enetaddr, 6);
+ memcpy(net_ethaddr, eth_get_ethaddr(), 6);
return;
}
@@ -284,7 +278,7 @@ static void net_clear_handlers(void)
{
net_set_udp_handler(NULL);
net_set_arp_handler(NULL);
- NetSetTimeout(0, NULL);
+ net_set_timeout_handler(0, NULL);
}
static void net_cleanup_loop(void)
@@ -302,19 +296,20 @@ void net_init(void)
*/
int i;
- NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
- NetTxPacket -= (ulong)NetTxPacket % PKTALIGN;
- for (i = 0; i < PKTBUFSRX; i++)
- NetRxPackets[i] = NetTxPacket + (i + 1) * PKTSIZE_ALIGN;
-
- ArpInit();
+ net_tx_packet = &net_pkt_buf[0] + (PKTALIGN - 1);
+ net_tx_packet -= (ulong)net_tx_packet % PKTALIGN;
+ for (i = 0; i < PKTBUFSRX; i++) {
+ net_rx_packets[i] = net_tx_packet +
+ (i + 1) * PKTSIZE_ALIGN;
+ }
+ arp_init();
net_clear_handlers();
/* Only need to setup buffer pointers once. */
first_call = 0;
}
- NetInitLoop();
+ net_init_loop();
}
/**********************************************************************/
@@ -322,28 +317,28 @@ void net_init(void)
* Main network processing loop.
*/
-int NetLoop(enum proto_t protocol)
+int net_loop(enum proto_t protocol)
{
- bd_t *bd = gd->bd;
- int ret = -1;
+ int ret = -EINVAL;
- NetRestarted = 0;
- NetDevExists = 0;
- NetTryCount = 1;
- debug_cond(DEBUG_INT_STATE, "--- NetLoop Entry\n");
+ net_restarted = 0;
+ net_dev_exists = 0;
+ net_try_count = 1;
+ debug_cond(DEBUG_INT_STATE, "--- net_loop Entry\n");
bootstage_mark_name(BOOTSTAGE_ID_ETH_START, "eth_start");
net_init();
if (eth_is_on_demand_init() || protocol != NETCONS) {
eth_halt();
eth_set_current();
- if (eth_init(bd) < 0) {
+ ret = eth_init();
+ if (ret < 0) {
eth_halt();
- return -1;
+ return ret;
}
- } else
- eth_init_state_only(bd);
-
+ } else {
+ eth_init_state_only();
+ }
restart:
#ifdef CONFIG_USB_KEYBOARD
net_busy_flag = 0;
@@ -355,54 +350,54 @@ restart:
* here on, this code is a state machine driven by received
* packets and timer events.
*/
- debug_cond(DEBUG_INT_STATE, "--- NetLoop Init\n");
- NetInitLoop();
+ debug_cond(DEBUG_INT_STATE, "--- net_loop Init\n");
+ net_init_loop();
switch (net_check_prereq(protocol)) {
case 1:
/* network not configured */
eth_halt();
- return -1;
+ return -ENODEV;
case 2:
/* network device not configured */
break;
case 0:
- NetDevExists = 1;
- NetBootFileXferSize = 0;
+ net_dev_exists = 1;
+ net_boot_file_size = 0;
switch (protocol) {
case TFTPGET:
#ifdef CONFIG_CMD_TFTPPUT
case TFTPPUT:
#endif
/* always use ARP to get server ethernet address */
- TftpStart(protocol);
+ tftp_start(protocol);
break;
#ifdef CONFIG_CMD_TFTPSRV
case TFTPSRV:
- TftpStartServer();
+ tftp_start_server();
break;
#endif
#if defined(CONFIG_CMD_DHCP)
case DHCP:
- BootpReset();
- NetOurIP = 0;
- DhcpRequest(); /* Basically same as BOOTP */
+ bootp_reset();
+ net_ip.s_addr = 0;
+ dhcp_request(); /* Basically same as BOOTP */
break;
#endif
case BOOTP:
- BootpReset();
- NetOurIP = 0;
- BootpRequest();
+ bootp_reset();
+ net_ip.s_addr = 0;
+ bootp_request();
break;
#if defined(CONFIG_CMD_RARP)
case RARP:
- RarpTry = 0;
- NetOurIP = 0;
- RarpRequest();
+ rarp_try = 0;
+ net_ip.s_addr = 0;
+ rarp_request();
break;
#endif
#if defined(CONFIG_CMD_PING)
@@ -412,27 +407,27 @@ restart:
#endif
#if defined(CONFIG_CMD_NFS)
case NFS:
- NfsStart();
+ nfs_start();
break;
#endif
#if defined(CONFIG_CMD_CDP)
case CDP:
- CDPStart();
+ cdp_start();
break;
#endif
-#if defined (CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD)
+#if defined(CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD)
case NETCONS:
- NcStart();
+ nc_start();
break;
#endif
#if defined(CONFIG_CMD_SNTP)
case SNTP:
- SntpStart();
+ sntp_start();
break;
#endif
#if defined(CONFIG_CMD_DNS)
case DNS:
- DnsStart();
+ dns_start();
break;
#endif
#if defined(CONFIG_CMD_LINK_LOCAL)
@@ -476,6 +471,8 @@ restart:
/*
* Check the ethernet for a new packet. The ethernet
* receive routine will process it.
+ * Most drivers return the most recent packet size, but not
+ * errors that may have happened.
*/
eth_rx();
@@ -484,7 +481,7 @@ restart:
*/
if (ctrlc()) {
/* cancel any ARP that may not have completed */
- NetArpWaitPacketIP = 0;
+ net_arp_wait_packet_ip.s_addr = 0;
net_cleanup_loop();
eth_halt();
@@ -494,17 +491,18 @@ restart:
puts("\nAbort\n");
/* include a debug print as well incase the debug
messages are directed to stderr */
- debug_cond(DEBUG_INT_STATE, "--- NetLoop Abort!\n");
+ debug_cond(DEBUG_INT_STATE, "--- net_loop Abort!\n");
goto done;
}
- ArpTimeoutCheck();
+ arp_timeout_check();
/*
* Check for a timeout, and run the timeout handler
* if we have one.
*/
- if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) {
+ if (time_handler &&
+ ((get_timer(0) - time_start) > time_delta)) {
thand_f *x;
#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
@@ -515,33 +513,32 @@ restart:
* Echo the inverted link state to the fault LED.
*/
if (miiphy_link(eth_get_dev()->name,
- CONFIG_SYS_FAULT_MII_ADDR)) {
+ CONFIG_SYS_FAULT_MII_ADDR))
status_led_set(STATUS_LED_RED, STATUS_LED_OFF);
- } else {
+ else
status_led_set(STATUS_LED_RED, STATUS_LED_ON);
- }
#endif /* CONFIG_SYS_FAULT_ECHO_LINK_DOWN, ... */
#endif /* CONFIG_MII, ... */
- debug_cond(DEBUG_INT_STATE, "--- NetLoop timeout\n");
- x = timeHandler;
- timeHandler = (thand_f *)0;
+ debug_cond(DEBUG_INT_STATE, "--- net_loop timeout\n");
+ x = time_handler;
+ time_handler = (thand_f *)0;
(*x)();
}
+ if (net_state == NETLOOP_FAIL)
+ ret = net_start_again();
switch (net_state) {
-
case NETLOOP_RESTART:
- NetRestarted = 1;
+ net_restarted = 1;
goto restart;
case NETLOOP_SUCCESS:
net_cleanup_loop();
- if (NetBootFileXferSize > 0) {
- printf("Bytes transferred = %ld (%lx hex)\n",
- NetBootFileXferSize,
- NetBootFileXferSize);
- setenv_hex("filesize", NetBootFileXferSize);
+ if (net_boot_file_size > 0) {
+ printf("Bytes transferred = %d (%x hex)\n",
+ net_boot_file_size, net_boot_file_size);
+ setenv_hex("filesize", net_boot_file_size);
setenv_hex("fileaddr", load_addr);
}
if (protocol != NETCONS)
@@ -551,15 +548,15 @@ restart:
eth_set_last_protocol(protocol);
- ret = NetBootFileXferSize;
- debug_cond(DEBUG_INT_STATE, "--- NetLoop Success!\n");
+ ret = net_boot_file_size;
+ debug_cond(DEBUG_INT_STATE, "--- net_loop Success!\n");
goto done;
case NETLOOP_FAIL:
net_cleanup_loop();
/* Invalidate the last protocol */
eth_set_last_protocol(BOOTP);
- debug_cond(DEBUG_INT_STATE, "--- NetLoop Fail!\n");
+ debug_cond(DEBUG_INT_STATE, "--- net_loop Fail!\n");
goto done;
case NETLOOP_CONTINUE:
@@ -581,17 +578,17 @@ done:
/**********************************************************************/
-static void
-startAgainTimeout(void)
+static void start_again_timeout_handler(void)
{
net_set_state(NETLOOP_RESTART);
}
-void NetStartAgain(void)
+int net_start_again(void)
{
char *nretry;
int retry_forever = 0;
unsigned long retrycnt = 0;
+ int ret;
nretry = getenv("netretry");
if (nretry) {
@@ -603,26 +600,33 @@ void NetStartAgain(void)
retrycnt = 1;
else
retrycnt = simple_strtoul(nretry, NULL, 0);
- } else
- retry_forever = 1;
+ } else {
+ retrycnt = 0;
+ retry_forever = 0;
+ }
- if ((!retry_forever) && (NetTryCount >= retrycnt)) {
+ if ((!retry_forever) && (net_try_count >= retrycnt)) {
eth_halt();
net_set_state(NETLOOP_FAIL);
- return;
+ /*
+ * We don't provide a way for the protocol to return an error,
+ * but this is almost always the reason.
+ */
+ return -ETIMEDOUT;
}
- NetTryCount++;
+ net_try_count++;
eth_halt();
#if !defined(CONFIG_NET_DO_NOT_TRY_ANOTHER)
- eth_try_another(!NetRestarted);
+ eth_try_another(!net_restarted);
#endif
- eth_init(gd->bd);
- if (NetRestartWrap) {
- NetRestartWrap = 0;
- if (NetDevExists) {
- NetSetTimeout(10000UL, startAgainTimeout);
+ ret = eth_init();
+ if (net_restart_wrap) {
+ net_restart_wrap = 0;
+ if (net_dev_exists) {
+ net_set_timeout_handler(10000UL,
+ start_again_timeout_handler);
net_set_udp_handler(NULL);
} else {
net_set_state(NETLOOP_FAIL);
@@ -630,6 +634,7 @@ void NetStartAgain(void)
} else {
net_set_state(NETLOOP_RESTART);
}
+ return ret;
}
/**********************************************************************/
@@ -638,7 +643,7 @@ void NetStartAgain(void)
*/
static void dummy_handler(uchar *pkt, unsigned dport,
- IPaddr_t sip, unsigned sport,
+ struct in_addr sip, unsigned sport,
unsigned len)
{
}
@@ -650,7 +655,7 @@ rxhand_f *net_get_udp_handler(void)
void net_set_udp_handler(rxhand_f *f)
{
- debug_cond(DEBUG_INT_STATE, "--- NetLoop UDP handler set (%p)\n", f);
+ debug_cond(DEBUG_INT_STATE, "--- net_loop UDP handler set (%p)\n", f);
if (f == NULL)
udp_packet_handler = dummy_handler;
else
@@ -664,7 +669,7 @@ rxhand_f *net_get_arp_handler(void)
void net_set_arp_handler(rxhand_f *f)
{
- debug_cond(DEBUG_INT_STATE, "--- NetLoop ARP handler set (%p)\n", f);
+ debug_cond(DEBUG_INT_STATE, "--- net_loop ARP handler set (%p)\n", f);
if (f == NULL)
arp_packet_handler = dummy_handler;
else
@@ -678,69 +683,68 @@ void net_set_icmp_handler(rxhand_icmp_f *f)
}
#endif
-void
-NetSetTimeout(ulong iv, thand_f *f)
+void net_set_timeout_handler(ulong iv, thand_f *f)
{
if (iv == 0) {
debug_cond(DEBUG_INT_STATE,
- "--- NetLoop timeout handler cancelled\n");
- timeHandler = (thand_f *)0;
+ "--- net_loop timeout handler cancelled\n");
+ time_handler = (thand_f *)0;
} else {
debug_cond(DEBUG_INT_STATE,
- "--- NetLoop timeout handler set (%p)\n", f);
- timeHandler = f;
- timeStart = get_timer(0);
- timeDelta = iv * CONFIG_SYS_HZ / 1000;
+ "--- net_loop timeout handler set (%p)\n", f);
+ time_handler = f;
+ time_start = get_timer(0);
+ time_delta = iv * CONFIG_SYS_HZ / 1000;
}
}
-int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
+int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport,
int payload_len)
{
uchar *pkt;
int eth_hdr_size;
int pkt_hdr_size;
- /* make sure the NetTxPacket is initialized (NetInit() was called) */
- assert(NetTxPacket != NULL);
- if (NetTxPacket == NULL)
+ /* make sure the net_tx_packet is initialized (net_init() was called) */
+ assert(net_tx_packet != NULL);
+ if (net_tx_packet == NULL)
return -1;
/* convert to new style broadcast */
- if (dest == 0)
- dest = 0xFFFFFFFF;
+ if (dest.s_addr == 0)
+ dest.s_addr = 0xFFFFFFFF;
/* if broadcast, make the ether address a broadcast and don't do ARP */
- if (dest == 0xFFFFFFFF)
- ether = NetBcastAddr;
+ if (dest.s_addr == 0xFFFFFFFF)
+ ether = (uchar *)net_bcast_ethaddr;
- pkt = (uchar *)NetTxPacket;
+ pkt = (uchar *)net_tx_packet;
- eth_hdr_size = NetSetEther(pkt, ether, PROT_IP);
+ eth_hdr_size = net_set_ether(pkt, ether, PROT_IP);
pkt += eth_hdr_size;
net_set_udp_header(pkt, dest, dport, sport, payload_len);
pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE;
/* if MAC address was not discovered yet, do an ARP request */
- if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
+ if (memcmp(ether, net_null_ethaddr, 6) == 0) {
debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &dest);
/* save the ip and eth addr for the packet to send after arp */
- NetArpWaitPacketIP = dest;
- NetArpWaitPacketMAC = ether;
+ net_arp_wait_packet_ip = dest;
+ arp_wait_packet_ethaddr = ether;
/* size of the waiting packet */
- NetArpWaitTxPacketSize = pkt_hdr_size + payload_len;
+ arp_wait_tx_packet_size = pkt_hdr_size + payload_len;
/* and do the ARP request */
- NetArpWaitTry = 1;
- NetArpWaitTimerStart = get_timer(0);
- ArpRequest();
+ arp_wait_try = 1;
+ arp_wait_timer_start = get_timer(0);
+ arp_request();
return 1; /* waiting */
} else {
debug_cond(DEBUG_DEV_PKT, "sending UDP to %pI4/%pM\n",
- &dest, ether);
- NetSendPacket(NetTxPacket, pkt_hdr_size + payload_len);
+ &dest, ether);
+ net_send_packet(net_tx_packet, pkt_hdr_size + payload_len);
return 0; /* transmitted */
}
}
@@ -778,7 +782,7 @@ struct hole {
u16 unused;
};
-static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp)
+static struct ip_udp_hdr *__net_defragment(struct ip_udp_hdr *ip, int *lenp)
{
static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
static u16 first_hole, total_len;
@@ -898,17 +902,19 @@ static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp)
return localip;
}
-static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)
+static inline struct ip_udp_hdr *net_defragment(struct ip_udp_hdr *ip,
+ int *lenp)
{
u16 ip_off = ntohs(ip->ip_off);
if (!(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)))
return ip; /* not a fragment */
- return __NetDefragment(ip, lenp);
+ return __net_defragment(ip, lenp);
}
#else /* !CONFIG_IP_DEFRAG */
-static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)
+static inline struct ip_udp_hdr *net_defragment(struct ip_udp_hdr *ip,
+ int *lenp)
{
u16 ip_off = ntohs(ip->ip_off);
if (!(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)))
@@ -924,7 +930,7 @@ static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)
* @parma ip IP packet containing the ICMP
*/
static void receive_icmp(struct ip_udp_hdr *ip, int len,
- IPaddr_t src_ip, struct ethernet_hdr *et)
+ struct in_addr src_ip, struct ethernet_hdr *et)
{
struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
@@ -933,7 +939,7 @@ static void receive_icmp(struct ip_udp_hdr *ip, int len,
if (icmph->code != ICMP_REDIR_HOST)
return;
printf(" ICMP Host Redirect to %pI4 ",
- &icmph->un.gateway);
+ &icmph->un.gateway);
break;
default:
#if defined(CONFIG_CMD_PING)
@@ -942,20 +948,20 @@ static void receive_icmp(struct ip_udp_hdr *ip, int len,
#ifdef CONFIG_CMD_TFTPPUT
if (packet_icmp_handler)
packet_icmp_handler(icmph->type, icmph->code,
- ntohs(ip->udp_dst), src_ip, ntohs(ip->udp_src),
- icmph->un.data, ntohs(ip->udp_len));
+ ntohs(ip->udp_dst), src_ip,
+ ntohs(ip->udp_src), icmph->un.data,
+ ntohs(ip->udp_len));
#endif
break;
}
}
-void
-NetReceive(uchar *inpkt, int len)
+void net_process_received_packet(uchar *in_packet, int len)
{
struct ethernet_hdr *et;
struct ip_udp_hdr *ip;
- IPaddr_t dst_ip;
- IPaddr_t src_ip;
+ struct in_addr dst_ip;
+ struct in_addr src_ip;
int eth_proto;
#if defined(CONFIG_CMD_CDP)
int iscdp;
@@ -964,9 +970,9 @@ NetReceive(uchar *inpkt, int len)
debug_cond(DEBUG_NET_PKT, "packet received\n");
- NetRxPacket = inpkt;
- NetRxPacketLen = len;
- et = (struct ethernet_hdr *)inpkt;
+ net_rx_packet = in_packet;
+ net_rx_packet_len = len;
+ et = (struct ethernet_hdr *)in_packet;
/* too small packet? */
if (len < ETHER_HDR_SIZE)
@@ -974,7 +980,7 @@ NetReceive(uchar *inpkt, int len)
#ifdef CONFIG_API
if (push_packet) {
- (*push_packet)(inpkt, len);
+ (*push_packet)(in_packet, len);
return;
}
#endif
@@ -984,10 +990,10 @@ NetReceive(uchar *inpkt, int len)
iscdp = is_cdp_packet(et->et_dest);
#endif
- myvlanid = ntohs(NetOurVLAN);
+ myvlanid = ntohs(net_our_vlan);
if (myvlanid == (ushort)-1)
myvlanid = VLAN_NONE;
- mynvlanid = ntohs(NetOurNativeVLAN);
+ mynvlanid = ntohs(net_native_vlan);
if (mynvlanid == (ushort)-1)
mynvlanid = VLAN_NONE;
@@ -1001,11 +1007,11 @@ NetReceive(uchar *inpkt, int len)
*/
eth_proto = ntohs(et802->et_prot);
- ip = (struct ip_udp_hdr *)(inpkt + E802_HDR_SIZE);
+ ip = (struct ip_udp_hdr *)(in_packet + E802_HDR_SIZE);
len -= E802_HDR_SIZE;
} else if (eth_proto != PROT_VLAN) { /* normal packet */
- ip = (struct ip_udp_hdr *)(inpkt + ETHER_HDR_SIZE);
+ ip = (struct ip_udp_hdr *)(in_packet + ETHER_HDR_SIZE);
len -= ETHER_HDR_SIZE;
} else { /* VLAN packet */
@@ -1019,7 +1025,7 @@ NetReceive(uchar *inpkt, int len)
return;
/* if no VLAN active */
- if ((ntohs(NetOurVLAN) & VLAN_IDMASK) == VLAN_NONE
+ if ((ntohs(net_our_vlan) & VLAN_IDMASK) == VLAN_NONE
#if defined(CONFIG_CMD_CDP)
&& iscdp == 0
#endif
@@ -1030,7 +1036,7 @@ NetReceive(uchar *inpkt, int len)
vlanid = cti & VLAN_IDMASK;
eth_proto = ntohs(vet->vet_type);
- ip = (struct ip_udp_hdr *)(inpkt + VLAN_ETHER_HDR_SIZE);
+ ip = (struct ip_udp_hdr *)(in_packet + VLAN_ETHER_HDR_SIZE);
len -= VLAN_ETHER_HDR_SIZE;
}
@@ -1052,9 +1058,8 @@ NetReceive(uchar *inpkt, int len)
}
switch (eth_proto) {
-
case PROT_ARP:
- ArpReceive(et, ip, len);
+ arp_receive(et, ip, len);
break;
#ifdef CONFIG_CMD_RARP
@@ -1067,7 +1072,7 @@ NetReceive(uchar *inpkt, int len)
/* Before we start poking the header, make sure it is there */
if (len < IP_UDP_HDR_SIZE) {
debug("len bad %d < %lu\n", len,
- (ulong)IP_UDP_HDR_SIZE);
+ (ulong)IP_UDP_HDR_SIZE);
return;
}
/* Check the packet length */
@@ -1077,7 +1082,7 @@ NetReceive(uchar *inpkt, int len)
}
len = ntohs(ip->ip_len);
debug_cond(DEBUG_NET_PKT, "len=%d, v=%02x\n",
- len, ip->ip_hl_v & 0xff);
+ len, ip->ip_hl_v & 0xff);
/* Can't deal with anything except IPv4 */
if ((ip->ip_hl_v & 0xf0) != 0x40)
@@ -1091,21 +1096,22 @@ NetReceive(uchar *inpkt, int len)
return;
}
/* If it is not for us, ignore it */
- dst_ip = NetReadIP(&ip->ip_dst);
- if (NetOurIP && dst_ip != NetOurIP && dst_ip != 0xFFFFFFFF) {
+ dst_ip = net_read_ip(&ip->ip_dst);
+ if (net_ip.s_addr && dst_ip.s_addr != net_ip.s_addr &&
+ dst_ip.s_addr != 0xFFFFFFFF) {
#ifdef CONFIG_MCAST_TFTP
- if (Mcast_addr != dst_ip)
+ if (net_mcast_addr != dst_ip)
#endif
return;
}
/* Read source IP address for later use */
- src_ip = NetReadIP(&ip->ip_src);
+ src_ip = net_read_ip(&ip->ip_src);
/*
* The function returns the unchanged packet if it's not
* a fragment, and either the complete packet or NULL if
* it is a fragment (if !CONFIG_IP_DEFRAG, it returns NULL)
*/
- ip = NetDefragment(ip, &len);
+ ip = net_defragment(ip, &len);
if (!ip)
return;
/*
@@ -1137,8 +1143,8 @@ NetReceive(uchar *inpkt, int len)
}
debug_cond(DEBUG_DEV_PKT,
- "received UDP (to=%pI4, from=%pI4, len=%d)\n",
- &dst_ip, &src_ip, len);
+ "received UDP (to=%pI4, from=%pI4, len=%d)\n",
+ &dst_ip, &src_ip, len);
#ifdef CONFIG_UDP_CHECKSUM
if (ip->udp_xsum != 0) {
@@ -1148,13 +1154,13 @@ NetReceive(uchar *inpkt, int len)
xsum = ip->ip_p;
xsum += (ntohs(ip->udp_len));
- xsum += (ntohl(ip->ip_src) >> 16) & 0x0000ffff;
- xsum += (ntohl(ip->ip_src) >> 0) & 0x0000ffff;
- xsum += (ntohl(ip->ip_dst) >> 16) & 0x0000ffff;
- xsum += (ntohl(ip->ip_dst) >> 0) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_src.s_addr) >> 16) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_src.s_addr) >> 0) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_dst.s_addr) >> 16) & 0x0000ffff;
+ xsum += (ntohl(ip->ip_dst.s_addr) >> 0) & 0x0000ffff;
sumlen = ntohs(ip->udp_len);
- sumptr = (ushort *) &(ip->udp_src);
+ sumptr = (ushort *)&(ip->udp_src);
while (sumlen > 1) {
ushort sumdata;
@@ -1166,7 +1172,7 @@ NetReceive(uchar *inpkt, int len)
if (sumlen > 0) {
ushort sumdata;
- sumdata = *(unsigned char *) sumptr;
+ sumdata = *(unsigned char *)sumptr;
sumdata = (sumdata << 8) & 0xff00;
xsum += sumdata;
}
@@ -1176,33 +1182,31 @@ NetReceive(uchar *inpkt, int len)
}
if ((xsum != 0x00000000) && (xsum != 0x0000ffff)) {
printf(" UDP wrong checksum %08lx %08x\n",
- xsum, ntohs(ip->udp_xsum));
+ xsum, ntohs(ip->udp_xsum));
return;
}
}
#endif
-
-#if defined (CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD)
+#if defined(CONFIG_NETCONSOLE) && !(CONFIG_SPL_BUILD)
nc_input_packet((uchar *)ip + IP_UDP_HDR_SIZE,
- src_ip,
- ntohs(ip->udp_dst),
- ntohs(ip->udp_src),
- ntohs(ip->udp_len) - UDP_HDR_SIZE);
+ src_ip,
+ ntohs(ip->udp_dst),
+ ntohs(ip->udp_src),
+ ntohs(ip->udp_len) - UDP_HDR_SIZE);
#endif
/*
- * IP header OK. Pass the packet to the current handler.
+ * IP header OK. Pass the packet to the current handler.
*/
(*udp_packet_handler)((uchar *)ip + IP_UDP_HDR_SIZE,
- ntohs(ip->udp_dst),
- src_ip,
- ntohs(ip->udp_src),
- ntohs(ip->udp_len) - UDP_HDR_SIZE);
+ ntohs(ip->udp_dst),
+ src_ip,
+ ntohs(ip->udp_src),
+ ntohs(ip->udp_len) - UDP_HDR_SIZE);
break;
}
}
-
/**********************************************************************/
static int net_check_prereq(enum proto_t protocol)
@@ -1211,7 +1215,7 @@ static int net_check_prereq(enum proto_t protocol)
/* Fall through */
#if defined(CONFIG_CMD_PING)
case PING:
- if (NetPingIP == 0) {
+ if (net_ping_ip.s_addr == 0) {
puts("*** ERROR: ping address not given\n");
return 1;
}
@@ -1219,7 +1223,7 @@ static int net_check_prereq(enum proto_t protocol)
#endif
#if defined(CONFIG_CMD_SNTP)
case SNTP:
- if (NetNtpServerIP == 0) {
+ if (net_ntp_server.s_addr == 0) {
puts("*** ERROR: NTP server address not given\n");
return 1;
}
@@ -1227,7 +1231,7 @@ static int net_check_prereq(enum proto_t protocol)
#endif
#if defined(CONFIG_CMD_DNS)
case DNS:
- if (NetOurDNSIP == 0) {
+ if (net_dns_server.s_addr == 0) {
puts("*** ERROR: DNS server address not given\n");
return 1;
}
@@ -1236,9 +1240,10 @@ static int net_check_prereq(enum proto_t protocol)
#if defined(CONFIG_CMD_NFS)
case NFS:
#endif
+ /* Fall through */
case TFTPGET:
case TFTPPUT:
- if (NetServerIP == 0) {
+ if (net_server_ip.s_addr == 0) {
puts("*** ERROR: `serverip' not set\n");
return 1;
}
@@ -1250,7 +1255,7 @@ common:
case NETCONS:
case TFTPSRV:
- if (NetOurIP == 0) {
+ if (net_ip.s_addr == 0) {
puts("*** ERROR: `ipaddr' not set\n");
return 1;
}
@@ -1263,7 +1268,7 @@ common:
case CDP:
case DHCP:
case LINKLOCAL:
- if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
+ if (memcmp(net_ethaddr, "\0\0\0\0\0\0", 6) == 0) {
int num = eth_get_dev_index();
switch (num) {
@@ -1275,11 +1280,11 @@ common:
break;
default:
printf("*** ERROR: `eth%daddr' not set\n",
- num);
+ num);
break;
}
- NetStartAgain();
+ net_start_again();
return 2;
}
/* Fall through */
@@ -1291,11 +1296,11 @@ common:
/**********************************************************************/
int
-NetEthHdrSize(void)
+net_eth_hdr_size(void)
{
ushort myvlanid;
- myvlanid = ntohs(NetOurVLAN);
+ myvlanid = ntohs(net_our_vlan);
if (myvlanid == (ushort)-1)
myvlanid = VLAN_NONE;
@@ -1303,18 +1308,17 @@ NetEthHdrSize(void)
VLAN_ETHER_HDR_SIZE;
}
-int
-NetSetEther(uchar *xet, uchar * addr, uint prot)
+int net_set_ether(uchar *xet, const uchar *dest_ethaddr, uint prot)
{
struct ethernet_hdr *et = (struct ethernet_hdr *)xet;
ushort myvlanid;
- myvlanid = ntohs(NetOurVLAN);
+ myvlanid = ntohs(net_our_vlan);
if (myvlanid == (ushort)-1)
myvlanid = VLAN_NONE;
- memcpy(et->et_dest, addr, 6);
- memcpy(et->et_src, NetOurEther, 6);
+ memcpy(et->et_dest, dest_ethaddr, 6);
+ memcpy(et->et_src, net_ethaddr, 6);
if ((myvlanid & VLAN_IDMASK) == VLAN_NONE) {
et->et_protlen = htons(prot);
return ETHER_HDR_SIZE;
@@ -1334,7 +1338,7 @@ int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot)
ushort protlen;
memcpy(et->et_dest, addr, 6);
- memcpy(et->et_src, NetOurEther, 6);
+ memcpy(et->et_src, net_ethaddr, 6);
protlen = ntohs(et->et_protlen);
if (protlen == PROT_VLAN) {
struct vlan_ethernet_hdr *vet =
@@ -1352,7 +1356,7 @@ int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot)
}
}
-void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source)
+void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source)
{
struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
@@ -1363,17 +1367,17 @@ void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source)
ip->ip_hl_v = 0x45;
ip->ip_tos = 0;
ip->ip_len = htons(IP_HDR_SIZE);
- ip->ip_id = htons(NetIPID++);
+ ip->ip_id = htons(net_ip_id++);
ip->ip_off = htons(IP_FLAGS_DFRAG); /* Don't fragment */
ip->ip_ttl = 255;
ip->ip_sum = 0;
/* already in network byte order */
- NetCopyIP((void *)&ip->ip_src, &source);
+ net_copy_ip((void *)&ip->ip_src, &source);
/* already in network byte order */
- NetCopyIP((void *)&ip->ip_dst, &dest);
+ net_copy_ip((void *)&ip->ip_dst, &dest);
}
-void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, int sport,
+void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, int sport,
int len)
{
struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
@@ -1386,7 +1390,7 @@ void net_set_udp_header(uchar *pkt, IPaddr_t dest, int dport, int sport,
if (len & 1)
pkt[IP_UDP_HDR_SIZE + len] = 0;
- net_set_ip_header(pkt, dest, NetOurIP);
+ net_set_ip_header(pkt, dest, net_ip);
ip->ip_len = htons(IP_UDP_HDR_SIZE + len);
ip->ip_p = IPPROTO_UDP;
ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
@@ -1423,17 +1427,18 @@ unsigned int random_port(void)
}
#endif
-void ip_to_string(IPaddr_t x, char *s)
+void ip_to_string(struct in_addr x, char *s)
{
- x = ntohl(x);
+ x.s_addr = ntohl(x.s_addr);
sprintf(s, "%d.%d.%d.%d",
- (int) ((x >> 24) & 0xff),
- (int) ((x >> 16) & 0xff),
- (int) ((x >> 8) & 0xff), (int) ((x >> 0) & 0xff)
+ (int) ((x.s_addr >> 24) & 0xff),
+ (int) ((x.s_addr >> 16) & 0xff),
+ (int) ((x.s_addr >> 8) & 0xff),
+ (int) ((x.s_addr >> 0) & 0xff)
);
}
-void VLAN_to_string(ushort x, char *s)
+void vlan_to_string(ushort x, char *s)
{
x = ntohs(x);
@@ -1446,7 +1451,7 @@ void VLAN_to_string(ushort x, char *s)
sprintf(s, "%d", x & VLAN_IDMASK);
}
-ushort string_to_VLAN(const char *s)
+ushort string_to_vlan(const char *s)
{
ushort id;
@@ -1461,7 +1466,7 @@ ushort string_to_VLAN(const char *s)
return htons(id);
}
-ushort getenv_VLAN(char *var)
+ushort getenv_vlan(char *var)
{
- return string_to_VLAN(getenv(var));
+ return string_to_vlan(getenv(var));
}
diff --git a/net/nfs.c b/net/nfs.c
index 381b75f..78968d8 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -26,6 +26,7 @@
#include <command.h>
#include <net.h>
#include <malloc.h>
+#include <mapmem.h>
#include "nfs.h"
#include "bootp.h"
@@ -50,12 +51,12 @@ static char dirfh[NFS_FHSIZE]; /* file handle of directory */
static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
static enum net_loop_state nfs_download_state;
-static IPaddr_t NfsServerIP;
-static int NfsSrvMountPort;
-static int NfsSrvNfsPort;
-static int NfsOurPort;
-static int NfsTimeoutCount;
-static int NfsState;
+static struct in_addr nfs_server_ip;
+static int nfs_server_mount_port;
+static int nfs_server_port;
+static int nfs_our_port;
+static int nfs_timeout_count;
+static int nfs_state;
#define STATE_PRCLOOKUP_PROG_MOUNT_REQ 1
#define STATE_PRCLOOKUP_PROG_NFS_REQ 2
#define STATE_MOUNT_REQ 3
@@ -69,8 +70,7 @@ static char *nfs_filename;
static char *nfs_path;
static char nfs_path_buff[2048];
-static inline int
-store_block(uchar *src, unsigned offset, unsigned len)
+static inline int store_block(uchar *src, unsigned offset, unsigned len)
{
ulong newsize = offset + len;
#ifdef CONFIG_SYS_DIRECT_FLASH_NFS
@@ -93,16 +93,18 @@ store_block(uchar *src, unsigned offset, unsigned len)
} else
#endif /* CONFIG_SYS_DIRECT_FLASH_NFS */
{
- (void)memcpy((void *)(load_addr + offset), src, len);
+ void *ptr = map_sysmem(load_addr + offset, len);
+
+ memcpy(ptr, src, len);
+ unmap_sysmem(ptr);
}
- if (NetBootFileXferSize < (offset+len))
- NetBootFileXferSize = newsize;
+ if (net_boot_file_size < (offset + len))
+ net_boot_file_size = newsize;
return 0;
}
-static char*
-basename(char *path)
+static char *basename(char *path)
{
char *fname;
@@ -117,8 +119,7 @@ basename(char *path)
return fname;
}
-static char*
-dirname(char *path)
+static char *dirname(char *path)
{
char *fname;
@@ -174,8 +175,7 @@ static long *rpc_add_credentials(long *p)
/**************************************************************************
RPC_LOOKUP - Lookup RPC Port numbers
**************************************************************************/
-static void
-rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
+static void rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
{
struct rpc_t pkt;
unsigned long id;
@@ -197,25 +197,24 @@ rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen)
pktlen = (char *)p + datalen*sizeof(uint32_t) - (char *)&pkt;
- memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE,
- (char *)&pkt, pktlen);
+ memcpy((char *)net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE,
+ (char *)&pkt, pktlen);
if (rpc_prog == PROG_PORTMAP)
sport = SUNRPC_PORT;
else if (rpc_prog == PROG_MOUNT)
- sport = NfsSrvMountPort;
+ sport = nfs_server_mount_port;
else
- sport = NfsSrvNfsPort;
+ sport = nfs_server_port;
- NetSendUDPPacket(NetServerEther, NfsServerIP, sport, NfsOurPort,
- pktlen);
+ net_send_udp_packet(net_server_ethaddr, nfs_server_ip, sport,
+ nfs_our_port, pktlen);
}
/**************************************************************************
RPC_LOOKUP - Lookup RPC Port numbers
**************************************************************************/
-static void
-rpc_lookup_req(int prog, int ver)
+static void rpc_lookup_req(int prog, int ver)
{
uint32_t data[16];
@@ -232,8 +231,7 @@ rpc_lookup_req(int prog, int ver)
/**************************************************************************
NFS_MOUNT - Mount an NFS Filesystem
**************************************************************************/
-static void
-nfs_mount_req(char *path)
+static void nfs_mount_req(char *path)
{
uint32_t data[1024];
uint32_t *p;
@@ -259,14 +257,13 @@ nfs_mount_req(char *path)
/**************************************************************************
NFS_UMOUNTALL - Unmount all our NFS Filesystems on the Server
**************************************************************************/
-static void
-nfs_umountall_req(void)
+static void nfs_umountall_req(void)
{
uint32_t data[1024];
uint32_t *p;
int len;
- if ((NfsSrvMountPort == -1) || (!fs_mounted))
+ if ((nfs_server_mount_port == -1) || (!fs_mounted))
/* Nothing mounted, nothing to umount */
return;
@@ -285,8 +282,7 @@ nfs_umountall_req(void)
* In case of successful readlink(), the dirname is manipulated,
* so that inside the nfs() function a recursion can be done.
**************************************************************************/
-static void
-nfs_readlink_req(void)
+static void nfs_readlink_req(void)
{
uint32_t data[1024];
uint32_t *p;
@@ -306,8 +302,7 @@ nfs_readlink_req(void)
/**************************************************************************
NFS_LOOKUP - Lookup Pathname
**************************************************************************/
-static void
-nfs_lookup_req(char *fname)
+static void nfs_lookup_req(char *fname)
{
uint32_t data[1024];
uint32_t *p;
@@ -335,8 +330,7 @@ nfs_lookup_req(char *fname)
/**************************************************************************
NFS_READ - Read File on NFS Server
**************************************************************************/
-static void
-nfs_read_req(int offset, int readlen)
+static void nfs_read_req(int offset, int readlen)
{
uint32_t data[1024];
uint32_t *p;
@@ -359,13 +353,11 @@ nfs_read_req(int offset, int readlen)
/**************************************************************************
RPC request dispatcher
**************************************************************************/
-
-static void
-NfsSend(void)
+static void nfs_send(void)
{
debug("%s\n", __func__);
- switch (NfsState) {
+ switch (nfs_state) {
case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
rpc_lookup_req(PROG_MOUNT, 1);
break;
@@ -394,8 +386,7 @@ NfsSend(void)
Handlers for the reply from server
**************************************************************************/
-static int
-rpc_lookup_reply(int prog, uchar *pkt, unsigned len)
+static int rpc_lookup_reply(int prog, uchar *pkt, unsigned len)
{
struct rpc_t rpc_pkt;
@@ -415,18 +406,17 @@ rpc_lookup_reply(int prog, uchar *pkt, unsigned len)
switch (prog) {
case PROG_MOUNT:
- NfsSrvMountPort = ntohl(rpc_pkt.u.reply.data[0]);
+ nfs_server_mount_port = ntohl(rpc_pkt.u.reply.data[0]);
break;
case PROG_NFS:
- NfsSrvNfsPort = ntohl(rpc_pkt.u.reply.data[0]);
+ nfs_server_port = ntohl(rpc_pkt.u.reply.data[0]);
break;
}
return 0;
}
-static int
-nfs_mount_reply(uchar *pkt, unsigned len)
+static int nfs_mount_reply(uchar *pkt, unsigned len)
{
struct rpc_t rpc_pkt;
@@ -451,8 +441,7 @@ nfs_mount_reply(uchar *pkt, unsigned len)
return 0;
}
-static int
-nfs_umountall_reply(uchar *pkt, unsigned len)
+static int nfs_umountall_reply(uchar *pkt, unsigned len)
{
struct rpc_t rpc_pkt;
@@ -476,8 +465,7 @@ nfs_umountall_reply(uchar *pkt, unsigned len)
return 0;
}
-static int
-nfs_lookup_reply(uchar *pkt, unsigned len)
+static int nfs_lookup_reply(uchar *pkt, unsigned len)
{
struct rpc_t rpc_pkt;
@@ -501,8 +489,7 @@ nfs_lookup_reply(uchar *pkt, unsigned len)
return 0;
}
-static int
-nfs_readlink_reply(uchar *pkt, unsigned len)
+static int nfs_readlink_reply(uchar *pkt, unsigned len)
{
struct rpc_t rpc_pkt;
int rlen;
@@ -529,7 +516,7 @@ nfs_readlink_reply(uchar *pkt, unsigned len)
strcat(nfs_path, "/");
pathlen = strlen(nfs_path);
memcpy(nfs_path + pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]),
- rlen);
+ rlen);
nfs_path[pathlen + rlen] = 0;
} else {
memcpy(nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
@@ -538,8 +525,7 @@ nfs_readlink_reply(uchar *pkt, unsigned len)
return 0;
}
-static int
-nfs_read_reply(uchar *pkt, unsigned len)
+static int nfs_read_reply(uchar *pkt, unsigned len)
{
struct rpc_t rpc_pkt;
int rlen;
@@ -581,67 +567,66 @@ nfs_read_reply(uchar *pkt, unsigned len)
/**************************************************************************
Interfaces of U-BOOT
**************************************************************************/
-
-static void
-NfsTimeout(void)
+static void nfs_timeout_handler(void)
{
- if (++NfsTimeoutCount > NFS_RETRY_COUNT) {
+ if (++nfs_timeout_count > NFS_RETRY_COUNT) {
puts("\nRetry count exceeded; starting again\n");
- NetStartAgain();
+ net_start_again();
} else {
puts("T ");
- NetSetTimeout(nfs_timeout + NFS_TIMEOUT * NfsTimeoutCount,
- NfsTimeout);
- NfsSend();
+ net_set_timeout_handler(nfs_timeout +
+ NFS_TIMEOUT * nfs_timeout_count,
+ nfs_timeout_handler);
+ nfs_send();
}
}
-static void
-NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
+static void nfs_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
int rlen;
int reply;
debug("%s\n", __func__);
- if (dest != NfsOurPort)
+ if (dest != nfs_our_port)
return;
- switch (NfsState) {
+ switch (nfs_state) {
case STATE_PRCLOOKUP_PROG_MOUNT_REQ:
if (rpc_lookup_reply(PROG_MOUNT, pkt, len) == -NFS_RPC_DROP)
break;
- NfsState = STATE_PRCLOOKUP_PROG_NFS_REQ;
- NfsSend();
+ nfs_state = STATE_PRCLOOKUP_PROG_NFS_REQ;
+ nfs_send();
break;
case STATE_PRCLOOKUP_PROG_NFS_REQ:
if (rpc_lookup_reply(PROG_NFS, pkt, len) == -NFS_RPC_DROP)
break;
- NfsState = STATE_MOUNT_REQ;
- NfsSend();
+ nfs_state = STATE_MOUNT_REQ;
+ nfs_send();
break;
case STATE_MOUNT_REQ:
reply = nfs_mount_reply(pkt, len);
- if (reply == -NFS_RPC_DROP)
+ if (reply == -NFS_RPC_DROP) {
break;
- else if (reply == -NFS_RPC_ERR) {
+ } else if (reply == -NFS_RPC_ERR) {
puts("*** ERROR: Cannot mount\n");
/* just to be sure... */
- NfsState = STATE_UMOUNT_REQ;
- NfsSend();
+ nfs_state = STATE_UMOUNT_REQ;
+ nfs_send();
} else {
- NfsState = STATE_LOOKUP_REQ;
- NfsSend();
+ nfs_state = STATE_LOOKUP_REQ;
+ nfs_send();
}
break;
case STATE_UMOUNT_REQ:
reply = nfs_umountall_reply(pkt, len);
- if (reply == -NFS_RPC_DROP)
+ if (reply == -NFS_RPC_DROP) {
break;
- else if (reply == -NFS_RPC_ERR) {
+ } else if (reply == -NFS_RPC_ERR) {
puts("*** ERROR: Cannot umount\n");
net_set_state(NETLOOP_FAIL);
} else {
@@ -652,66 +637,65 @@ NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
case STATE_LOOKUP_REQ:
reply = nfs_lookup_reply(pkt, len);
- if (reply == -NFS_RPC_DROP)
+ if (reply == -NFS_RPC_DROP) {
break;
- else if (reply == -NFS_RPC_ERR) {
+ } else if (reply == -NFS_RPC_ERR) {
puts("*** ERROR: File lookup fail\n");
- NfsState = STATE_UMOUNT_REQ;
- NfsSend();
+ nfs_state = STATE_UMOUNT_REQ;
+ nfs_send();
} else {
- NfsState = STATE_READ_REQ;
+ nfs_state = STATE_READ_REQ;
nfs_offset = 0;
nfs_len = NFS_READ_SIZE;
- NfsSend();
+ nfs_send();
}
break;
case STATE_READLINK_REQ:
reply = nfs_readlink_reply(pkt, len);
- if (reply == -NFS_RPC_DROP)
+ if (reply == -NFS_RPC_DROP) {
break;
- else if (reply == -NFS_RPC_ERR) {
+ } else if (reply == -NFS_RPC_ERR) {
puts("*** ERROR: Symlink fail\n");
- NfsState = STATE_UMOUNT_REQ;
- NfsSend();
+ nfs_state = STATE_UMOUNT_REQ;
+ nfs_send();
} else {
debug("Symlink --> %s\n", nfs_path);
nfs_filename = basename(nfs_path);
nfs_path = dirname(nfs_path);
- NfsState = STATE_MOUNT_REQ;
- NfsSend();
+ nfs_state = STATE_MOUNT_REQ;
+ nfs_send();
}
break;
case STATE_READ_REQ:
rlen = nfs_read_reply(pkt, len);
- NetSetTimeout(nfs_timeout, NfsTimeout);
+ net_set_timeout_handler(nfs_timeout, nfs_timeout_handler);
if (rlen > 0) {
nfs_offset += rlen;
- NfsSend();
+ nfs_send();
} else if ((rlen == -NFSERR_ISDIR) || (rlen == -NFSERR_INVAL)) {
/* symbolic link */
- NfsState = STATE_READLINK_REQ;
- NfsSend();
+ nfs_state = STATE_READLINK_REQ;
+ nfs_send();
} else {
if (!rlen)
nfs_download_state = NETLOOP_SUCCESS;
- NfsState = STATE_UMOUNT_REQ;
- NfsSend();
+ nfs_state = STATE_UMOUNT_REQ;
+ nfs_send();
}
break;
}
}
-void
-NfsStart(void)
+void nfs_start(void)
{
debug("%s\n", __func__);
nfs_download_state = NETLOOP_FAIL;
- NfsServerIP = NetServerIP;
+ nfs_server_ip = net_server_ip;
nfs_path = (char *)nfs_path_buff;
if (nfs_path == NULL) {
@@ -720,27 +704,27 @@ NfsStart(void)
return;
}
- if (BootFile[0] == '\0') {
+ if (net_boot_file_name[0] == '\0') {
sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
- NetOurIP & 0xFF,
- (NetOurIP >> 8) & 0xFF,
- (NetOurIP >> 16) & 0xFF,
- (NetOurIP >> 24) & 0xFF);
+ net_ip.s_addr & 0xFF,
+ (net_ip.s_addr >> 8) & 0xFF,
+ (net_ip.s_addr >> 16) & 0xFF,
+ (net_ip.s_addr >> 24) & 0xFF);
strcpy(nfs_path, default_filename);
printf("*** Warning: no boot file name; using '%s'\n",
- nfs_path);
+ nfs_path);
} else {
- char *p = BootFile;
+ char *p = net_boot_file_name;
p = strchr(p, ':');
if (p != NULL) {
- NfsServerIP = string_to_ip(BootFile);
+ nfs_server_ip = string_to_ip(net_boot_file_name);
++p;
strcpy(nfs_path, p);
} else {
- strcpy(nfs_path, BootFile);
+ strcpy(nfs_path, net_boot_file_name);
}
}
@@ -749,39 +733,42 @@ NfsStart(void)
printf("Using %s device\n", eth_get_name());
- printf("File transfer via NFS from server %pI4"
- "; our IP address is %pI4", &NfsServerIP, &NetOurIP);
+ printf("File transfer via NFS from server %pI4; our IP address is %pI4",
+ &nfs_server_ip, &net_ip);
/* Check if we need to send across this subnet */
- if (NetOurGatewayIP && NetOurSubnetMask) {
- IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
- IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask;
+ if (net_gateway.s_addr && net_netmask.s_addr) {
+ struct in_addr our_net;
+ struct in_addr server_net;
- if (OurNet != ServerNet)
+ our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
+ server_net.s_addr = net_server_ip.s_addr & net_netmask.s_addr;
+ if (our_net.s_addr != server_net.s_addr)
printf("; sending through gateway %pI4",
- &NetOurGatewayIP);
+ &net_gateway);
}
printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
- if (NetBootFileSize) {
- printf(" Size is 0x%x Bytes = ", NetBootFileSize<<9);
- print_size(NetBootFileSize<<9, "");
+ if (net_boot_file_expected_size_in_blocks) {
+ printf(" Size is 0x%x Bytes = ",
+ net_boot_file_expected_size_in_blocks << 9);
+ print_size(net_boot_file_expected_size_in_blocks << 9, "");
}
printf("\nLoad address: 0x%lx\n"
"Loading: *\b", load_addr);
- NetSetTimeout(nfs_timeout, NfsTimeout);
- net_set_udp_handler(NfsHandler);
+ net_set_timeout_handler(nfs_timeout, nfs_timeout_handler);
+ net_set_udp_handler(nfs_handler);
- NfsTimeoutCount = 0;
- NfsState = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
+ nfs_timeout_count = 0;
+ nfs_state = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
- /*NfsOurPort = 4096 + (get_ticks() % 3072);*/
+ /*nfs_our_port = 4096 + (get_ticks() % 3072);*/
/*FIX ME !!!*/
- NfsOurPort = 1000;
+ nfs_our_port = 1000;
/* zero out server ether in case the server ip has changed */
- memset(NetServerEther, 0, 6);
+ memset(net_server_ethaddr, 0, 6);
- NfsSend();
+ nfs_send();
}
diff --git a/net/nfs.h b/net/nfs.h
index 53451db..d69b422 100644
--- a/net/nfs.h
+++ b/net/nfs.h
@@ -69,7 +69,7 @@ struct rpc_t {
} reply;
} u;
};
-extern void NfsStart(void); /* Begin NFS */
+void nfs_start(void); /* Begin NFS */
/**********************************************************************/
diff --git a/net/ping.c b/net/ping.c
index 366f518..9508cf1 100644
--- a/net/ping.c
+++ b/net/ping.c
@@ -12,12 +12,12 @@
#include "ping.h"
#include "arp.h"
-static ushort PingSeqNo;
+static ushort ping_seq_number;
/* The ip address to ping */
-IPaddr_t NetPingIP;
+struct in_addr net_ping_ip;
-static void set_icmp_header(uchar *pkt, IPaddr_t dest)
+static void set_icmp_header(uchar *pkt, struct in_addr dest)
{
/*
* Construct an IP and ICMP header.
@@ -25,7 +25,7 @@ static void set_icmp_header(uchar *pkt, IPaddr_t dest)
struct ip_hdr *ip = (struct ip_hdr *)pkt;
struct icmp_hdr *icmp = (struct icmp_hdr *)(pkt + IP_HDR_SIZE);
- net_set_ip_header(pkt, dest, NetOurIP);
+ net_set_ip_header(pkt, dest, net_ip);
ip->ip_len = htons(IP_ICMP_HDR_SIZE);
ip->ip_p = IPPROTO_ICMP;
@@ -35,7 +35,7 @@ static void set_icmp_header(uchar *pkt, IPaddr_t dest)
icmp->code = 0;
icmp->checksum = 0;
icmp->un.echo.id = 0;
- icmp->un.echo.sequence = htons(PingSeqNo++);
+ icmp->un.echo.sequence = htons(ping_seq_number++);
icmp->checksum = compute_ip_checksum(icmp, ICMP_HDR_SIZE);
}
@@ -46,26 +46,26 @@ static int ping_send(void)
/* XXX always send arp request */
- debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &NetPingIP);
+ debug_cond(DEBUG_DEV_PKT, "sending ARP for %pI4\n", &net_ping_ip);
- NetArpWaitPacketIP = NetPingIP;
+ net_arp_wait_packet_ip = net_ping_ip;
- eth_hdr_size = NetSetEther(NetTxPacket, NetEtherNullAddr, PROT_IP);
- pkt = (uchar *)NetTxPacket + eth_hdr_size;
+ eth_hdr_size = net_set_ether(net_tx_packet, net_null_ethaddr, PROT_IP);
+ pkt = (uchar *)net_tx_packet + eth_hdr_size;
- set_icmp_header(pkt, NetPingIP);
+ set_icmp_header(pkt, net_ping_ip);
/* size of the waiting packet */
- NetArpWaitTxPacketSize = eth_hdr_size + IP_ICMP_HDR_SIZE;
+ arp_wait_tx_packet_size = eth_hdr_size + IP_ICMP_HDR_SIZE;
/* and do the ARP request */
- NetArpWaitTry = 1;
- NetArpWaitTimerStart = get_timer(0);
- ArpRequest();
+ arp_wait_try = 1;
+ arp_wait_timer_start = get_timer(0);
+ arp_request();
return 1; /* waiting */
}
-static void ping_timeout(void)
+static void ping_timeout_handler(void)
{
eth_halt();
net_set_state(NETLOOP_FAIL); /* we did not get the reply */
@@ -74,7 +74,7 @@ static void ping_timeout(void)
void ping_start(void)
{
printf("Using %s device\n", eth_get_name());
- NetSetTimeout(10000UL, ping_timeout);
+ net_set_timeout_handler(10000UL, ping_timeout_handler);
ping_send();
}
@@ -82,31 +82,32 @@ void ping_start(void)
void ping_receive(struct ethernet_hdr *et, struct ip_udp_hdr *ip, int len)
{
struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
- IPaddr_t src_ip;
+ struct in_addr src_ip;
int eth_hdr_size;
switch (icmph->type) {
case ICMP_ECHO_REPLY:
- src_ip = NetReadIP((void *)&ip->ip_src);
- if (src_ip == NetPingIP)
+ src_ip = net_read_ip((void *)&ip->ip_src);
+ if (src_ip.s_addr == net_ping_ip.s_addr)
net_set_state(NETLOOP_SUCCESS);
return;
case ICMP_ECHO_REQUEST:
eth_hdr_size = net_update_ether(et, et->et_src, PROT_IP);
- debug_cond(DEBUG_DEV_PKT, "Got ICMP ECHO REQUEST, return "
- "%d bytes\n", eth_hdr_size + len);
+ debug_cond(DEBUG_DEV_PKT,
+ "Got ICMP ECHO REQUEST, return %d bytes\n",
+ eth_hdr_size + len);
ip->ip_sum = 0;
ip->ip_off = 0;
- NetCopyIP((void *)&ip->ip_dst, &ip->ip_src);
- NetCopyIP((void *)&ip->ip_src, &NetOurIP);
+ net_copy_ip((void *)&ip->ip_dst, &ip->ip_src);
+ net_copy_ip((void *)&ip->ip_src, &net_ip);
ip->ip_sum = compute_ip_checksum(ip, IP_HDR_SIZE);
icmph->type = ICMP_ECHO_REPLY;
icmph->checksum = 0;
icmph->checksum = compute_ip_checksum(icmph, len - IP_HDR_SIZE);
- NetSendPacket((uchar *)et, eth_hdr_size + len);
+ net_send_packet((uchar *)et, eth_hdr_size + len);
return;
/* default:
return;*/
diff --git a/net/rarp.c b/net/rarp.c
index a8e0851..4ce2f37 100644
--- a/net/rarp.c
+++ b/net/rarp.c
@@ -20,7 +20,7 @@
#define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
#endif
-int RarpTry;
+int rarp_try;
/*
* Handle a RARP received packet.
@@ -37,16 +37,15 @@ void rarp_receive(struct ip_udp_hdr *ip, unsigned len)
}
if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
- (ntohs(arp->ar_hrd) != ARP_ETHER) ||
- (ntohs(arp->ar_pro) != PROT_IP) ||
- (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
-
+ (ntohs(arp->ar_hrd) != ARP_ETHER) ||
+ (ntohs(arp->ar_pro) != PROT_IP) ||
+ (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
puts("invalid RARP header\n");
} else {
- NetCopyIP(&NetOurIP, &arp->ar_data[16]);
- if (NetServerIP == 0)
- NetCopyIP(&NetServerIP, &arp->ar_data[6]);
- memcpy(NetServerEther, &arp->ar_data[0], 6);
+ net_copy_ip(&net_ip, &arp->ar_data[16]);
+ if (net_server_ip.s_addr == 0)
+ net_copy_ip(&net_server_ip, &arp->ar_data[6]);
+ memcpy(net_server_ethaddr, &arp->ar_data[0], 6);
debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
net_auto_load();
}
@@ -56,28 +55,28 @@ void rarp_receive(struct ip_udp_hdr *ip, unsigned len)
/*
* Timeout on BOOTP request.
*/
-static void RarpTimeout(void)
+static void rarp_timeout_handler(void)
{
- if (RarpTry >= TIMEOUT_COUNT) {
+ if (rarp_try >= TIMEOUT_COUNT) {
puts("\nRetry count exceeded; starting again\n");
- NetStartAgain();
+ net_start_again();
} else {
- NetSetTimeout(TIMEOUT, RarpTimeout);
- RarpRequest();
+ net_set_timeout_handler(TIMEOUT, rarp_timeout_handler);
+ rarp_request();
}
}
-void RarpRequest(void)
+void rarp_request(void)
{
uchar *pkt;
struct arp_hdr *rarp;
int eth_hdr_size;
- printf("RARP broadcast %d\n", ++RarpTry);
- pkt = NetTxPacket;
+ printf("RARP broadcast %d\n", ++rarp_try);
+ pkt = net_tx_packet;
- eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_RARP);
+ eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_RARP);
pkt += eth_hdr_size;
rarp = (struct arp_hdr *)pkt;
@@ -87,14 +86,14 @@ void RarpRequest(void)
rarp->ar_hln = 6;
rarp->ar_pln = 4;
rarp->ar_op = htons(RARPOP_REQUEST);
- memcpy(&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */
- memcpy(&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */
+ memcpy(&rarp->ar_data[0], net_ethaddr, 6); /* source ET addr */
+ memcpy(&rarp->ar_data[6], &net_ip, 4); /* source IP addr */
/* dest ET addr = source ET addr ??*/
- memcpy(&rarp->ar_data[10], NetOurEther, 6);
+ memcpy(&rarp->ar_data[10], net_ethaddr, 6);
/* dest IP addr set to broadcast */
memset(&rarp->ar_data[16], 0xff, 4);
- NetSendPacket(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE);
+ net_send_packet(net_tx_packet, eth_hdr_size + ARP_HDR_SIZE);
- NetSetTimeout(TIMEOUT, RarpTimeout);
+ net_set_timeout_handler(TIMEOUT, rarp_timeout_handler);
}
diff --git a/net/rarp.h b/net/rarp.h
index 93e1889..1ca8833 100644
--- a/net/rarp.h
+++ b/net/rarp.h
@@ -17,11 +17,11 @@
* Global functions and variables.
*/
-extern int RarpTry;
+extern int rarp_try;
/* Process the receipt of a RARP packet */
-extern void rarp_receive(struct ip_udp_hdr *ip, unsigned len);
-extern void RarpRequest(void); /* Send a RARP request */
+void rarp_receive(struct ip_udp_hdr *ip, unsigned len);
+void rarp_request(void); /* Send a RARP request */
/**********************************************************************/
diff --git a/net/sntp.c b/net/sntp.c
index 5de1952..6422eef 100644
--- a/net/sntp.c
+++ b/net/sntp.c
@@ -14,10 +14,9 @@
#define SNTP_TIMEOUT 10000UL
-static int SntpOurPort;
+static int sntp_our_port;
-static void
-SntpSend(void)
+static void sntp_send(void)
{
struct sntp_pkt_t pkt;
int pktlen = SNTP_PACKET_LEN;
@@ -31,62 +30,63 @@ SntpSend(void)
pkt.vn = NTP_VERSION;
pkt.mode = NTP_MODE_CLIENT;
- memcpy((char *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE,
- (char *)&pkt, pktlen);
+ memcpy((char *)net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE,
+ (char *)&pkt, pktlen);
- SntpOurPort = 10000 + (get_timer(0) % 4096);
+ sntp_our_port = 10000 + (get_timer(0) % 4096);
sport = NTP_SERVICE_PORT;
- NetSendUDPPacket(NetServerEther, NetNtpServerIP, sport, SntpOurPort,
- pktlen);
+ net_send_udp_packet(net_server_ethaddr, net_ntp_server, sport,
+ sntp_our_port, pktlen);
}
-static void
-SntpTimeout(void)
+static void sntp_timeout_handler(void)
{
puts("Timeout\n");
net_set_state(NETLOOP_FAIL);
return;
}
-static void
-SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
+#ifdef CONFIG_TIMESTAMP
struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
struct rtc_time tm;
ulong seconds;
+#endif
debug("%s\n", __func__);
- if (dest != SntpOurPort)
+ if (dest != sntp_our_port)
return;
+#ifdef CONFIG_TIMESTAMP
/*
- * As the RTC's used in U-Boot sepport second resolution only
+ * As the RTC's used in U-Boot support second resolution only
* we simply ignore the sub-second field.
*/
memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
- to_tm(ntohl(seconds) - 2208988800UL + NetTimeOffset, &tm);
+ to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm);
#if defined(CONFIG_CMD_DATE)
rtc_set(&tm);
#endif
printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
- tm.tm_year, tm.tm_mon, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
+ tm.tm_year, tm.tm_mon, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
+#endif
net_set_state(NETLOOP_SUCCESS);
}
-void
-SntpStart(void)
+void sntp_start(void)
{
debug("%s\n", __func__);
- NetSetTimeout(SNTP_TIMEOUT, SntpTimeout);
- net_set_udp_handler(SntpHandler);
- memset(NetServerEther, 0, sizeof(NetServerEther));
+ net_set_timeout_handler(SNTP_TIMEOUT, sntp_timeout_handler);
+ net_set_udp_handler(sntp_handler);
+ memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr));
- SntpSend();
+ sntp_send();
}
diff --git a/net/sntp.h b/net/sntp.h
index bf5bf0b..6a9c6bb 100644
--- a/net/sntp.h
+++ b/net/sntp.h
@@ -53,6 +53,6 @@ struct sntp_pkt_t {
unsigned long long transmit_timestamp;
};
-extern void SntpStart(void); /* Begin SNTP */
+void sntp_start(void); /* Begin SNTP */
#endif /* __SNTP_H__ */
diff --git a/net/tftp.c b/net/tftp.c
index 0a2c533..3e99e73 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -8,6 +8,7 @@
#include <common.h>
#include <command.h>
+#include <mapmem.h>
#include <net.h>
#include "tftp.h"
#include "bootp.h"
@@ -38,21 +39,21 @@
#define TFTP_ERROR 5
#define TFTP_OACK 6
-static ulong TftpTimeoutMSecs = TIMEOUT;
-static int TftpTimeoutCountMax = TIMEOUT_COUNT;
+static ulong timeout_ms = TIMEOUT;
+static int timeout_count_max = TIMEOUT_COUNT;
static ulong time_start; /* Record time we started tftp */
/*
* These globals govern the timeout behavior when attempting a connection to a
- * TFTP server. TftpRRQTimeoutMSecs specifies the number of milliseconds to
+ * TFTP server. tftp_timeout_ms specifies the number of milliseconds to
* wait for the server to respond to initial connection. Second global,
- * TftpRRQTimeoutCountMax, gives the number of such connection retries.
- * TftpRRQTimeoutCountMax must be non-negative and TftpRRQTimeoutMSecs must be
+ * tftp_timeout_count_max, gives the number of such connection retries.
+ * tftp_timeout_count_max must be non-negative and tftp_timeout_ms must be
* positive. The globals are meant to be set (and restored) by code needing
* non-standard timeout behavior when initiating a TFTP transfer.
*/
-ulong TftpRRQTimeoutMSecs = TIMEOUT;
-int TftpRRQTimeoutCountMax = TIMEOUT_COUNT;
+ulong tftp_timeout_ms = TIMEOUT;
+int tftp_timeout_count_max = TIMEOUT_COUNT;
enum {
TFTP_ERR_UNDEFINED = 0,
@@ -64,32 +65,34 @@ enum {
TFTP_ERR_FILE_ALREADY_EXISTS = 6,
};
-static IPaddr_t TftpRemoteIP;
+static struct in_addr tftp_remote_ip;
/* The UDP port at their end */
-static int TftpRemotePort;
+static int tftp_remote_port;
/* The UDP port at our end */
-static int TftpOurPort;
-static int TftpTimeoutCount;
+static int tftp_our_port;
+static int timeout_count;
/* packet sequence number */
-static ulong TftpBlock;
+static ulong tftp_cur_block;
/* last packet sequence number received */
-static ulong TftpLastBlock;
+static ulong tftp_prev_block;
/* count of sequence number wraparounds */
-static ulong TftpBlockWrap;
+static ulong tftp_block_wrap;
/* memory offset due to wrapping */
-static ulong TftpBlockWrapOffset;
-static int TftpState;
+static ulong tftp_block_wrap_offset;
+static int tftp_state;
#ifdef CONFIG_TFTP_TSIZE
/* The file size reported by the server */
-static int TftpTsize;
+static int tftp_tsize;
/* The number of hashes we printed */
-static short TftpNumchars;
+static short tftp_tsize_num_hash;
#endif
#ifdef CONFIG_CMD_TFTPPUT
-static int TftpWriting; /* 1 if writing, else 0 */
-static int TftpFinalBlock; /* 1 if we have sent the last block */
+/* 1 if writing, else 0 */
+static int tftp_put_active;
+/* 1 if we have sent the last block */
+static int tftp_put_final_block_sent;
#else
-#define TftpWriting 0
+#define tftp_put_active 0
#endif
#define STATE_SEND_RRQ 1
@@ -127,39 +130,42 @@ static char tftp_filename[MAX_LEN];
#define TFTP_MTU_BLOCKSIZE 1468
#endif
-static unsigned short TftpBlkSize = TFTP_BLOCK_SIZE;
-static unsigned short TftpBlkSizeOption = TFTP_MTU_BLOCKSIZE;
+static unsigned short tftp_block_size = TFTP_BLOCK_SIZE;
+static unsigned short tftp_block_size_option = TFTP_MTU_BLOCKSIZE;
#ifdef CONFIG_MCAST_TFTP
#include <malloc.h>
#define MTFTP_BITMAPSIZE 0x1000
-static unsigned *Bitmap;
-static int PrevBitmapHole, Mapsize = MTFTP_BITMAPSIZE;
-static uchar ProhibitMcast, MasterClient;
-static uchar Multicast;
-static int Mcast_port;
-static ulong TftpEndingBlock; /* can get 'last' block before done..*/
+static unsigned *tftp_mcast_bitmap;
+static int tftp_mcast_prev_hole;
+static int tftp_mcast_bitmap_size = MTFTP_BITMAPSIZE;
+static int tftp_mcast_disabled;
+static int tftp_mcast_master_client;
+static int tftp_mcast_active;
+static int tftp_mcast_port;
+/* can get 'last' block before done..*/
+static ulong tftp_mcast_ending_block;
static void parse_multicast_oack(char *pkt, int len);
-static void
-mcast_cleanup(void)
+static void mcast_cleanup(void)
{
- if (Mcast_addr)
- eth_mcast_join(Mcast_addr, 0);
- if (Bitmap)
- free(Bitmap);
- Bitmap = NULL;
- Mcast_addr = Multicast = Mcast_port = 0;
- TftpEndingBlock = -1;
+ if (net_mcast_addr)
+ eth_mcast_join(net_mcast_addr, 0);
+ if (tftp_mcast_bitmap)
+ free(tftp_mcast_bitmap);
+ tftp_mcast_bitmap = NULL;
+ net_mcast_addr.s_addr = 0;
+ tftp_mcast_active = 0;
+ tftp_mcast_port = 0;
+ tftp_mcast_ending_block = -1;
}
#endif /* CONFIG_MCAST_TFTP */
-static inline void
-store_block(int block, uchar *src, unsigned len)
+static inline void store_block(int block, uchar *src, unsigned len)
{
- ulong offset = block * TftpBlkSize + TftpBlockWrapOffset;
+ ulong offset = block * tftp_block_size + tftp_block_wrap_offset;
ulong newsize = offset + len;
#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
int i, rc = 0;
@@ -184,25 +190,28 @@ store_block(int block, uchar *src, unsigned len)
} else
#endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */
{
- (void)memcpy((void *)(load_addr + offset), src, len);
+ void *ptr = map_sysmem(load_addr + offset, len);
+
+ memcpy(ptr, src, len);
+ unmap_sysmem(ptr);
}
#ifdef CONFIG_MCAST_TFTP
- if (Multicast)
- ext2_set_bit(block, Bitmap);
+ if (tftp_mcast_active)
+ ext2_set_bit(block, tftp_mcast_bitmap);
#endif
- if (NetBootFileXferSize < newsize)
- NetBootFileXferSize = newsize;
+ if (net_boot_file_size < newsize)
+ net_boot_file_size = newsize;
}
/* Clear our state ready for a new transfer */
static void new_transfer(void)
{
- TftpLastBlock = 0;
- TftpBlockWrap = 0;
- TftpBlockWrapOffset = 0;
+ tftp_prev_block = 0;
+ tftp_block_wrap = 0;
+ tftp_block_wrap_offset = 0;
#ifdef CONFIG_CMD_TFTPPUT
- TftpFinalBlock = 0;
+ tftp_put_final_block_sent = 0;
#endif
}
@@ -218,38 +227,39 @@ static void new_transfer(void)
static int load_block(unsigned block, uchar *dst, unsigned len)
{
/* We may want to get the final block from the previous set */
- ulong offset = ((int)block - 1) * len + TftpBlockWrapOffset;
+ ulong offset = ((int)block - 1) * len + tftp_block_wrap_offset;
ulong tosend = len;
- tosend = min(NetBootFileXferSize - offset, tosend);
+ tosend = min(net_boot_file_size - offset, tosend);
(void)memcpy(dst, (void *)(save_addr + offset), tosend);
debug("%s: block=%d, offset=%ld, len=%d, tosend=%ld\n", __func__,
- block, offset, len, tosend);
+ block, offset, len, tosend);
return tosend;
}
#endif
-static void TftpSend(void);
-static void TftpTimeout(void);
+static void tftp_send(void);
+static void tftp_timeout_handler(void);
/**********************************************************************/
static void show_block_marker(void)
{
#ifdef CONFIG_TFTP_TSIZE
- if (TftpTsize) {
- ulong pos = TftpBlock * TftpBlkSize + TftpBlockWrapOffset;
+ if (tftp_tsize) {
+ ulong pos = tftp_cur_block * tftp_block_size +
+ tftp_block_wrap_offset;
- while (TftpNumchars < pos * 50 / TftpTsize) {
+ while (tftp_tsize_num_hash < pos * 50 / tftp_tsize) {
putc('#');
- TftpNumchars++;
+ tftp_tsize_num_hash++;
}
} else
#endif
{
- if (((TftpBlock - 1) % 10) == 0)
+ if (((tftp_cur_block - 1) % 10) == 0)
putc('#');
- else if ((TftpBlock % (10 * HASHES_PER_LINE)) == 0)
+ else if ((tftp_cur_block % (10 * HASHES_PER_LINE)) == 0)
puts("\n\t ");
}
}
@@ -265,7 +275,7 @@ static void restart(const char *msg)
#ifdef CONFIG_MCAST_TFTP
mcast_cleanup();
#endif
- NetStartAgain();
+ net_start_again();
}
/*
@@ -281,10 +291,10 @@ static void update_block_number(void)
* number of 0 this means that there was a wrap
* around of the (16 bit) counter.
*/
- if (TftpBlock == 0 && TftpLastBlock != 0) {
- TftpBlockWrap++;
- TftpBlockWrapOffset += TftpBlkSize * TFTP_SEQUENCE_SIZE;
- TftpTimeoutCount = 0; /* we've done well, reset thhe timeout */
+ if (tftp_cur_block == 0 && tftp_prev_block != 0) {
+ tftp_block_wrap++;
+ tftp_block_wrap_offset += tftp_block_size * TFTP_SEQUENCE_SIZE;
+ timeout_count = 0; /* we've done well, reset the timeout */
} else {
show_block_marker();
}
@@ -295,25 +305,24 @@ static void tftp_complete(void)
{
#ifdef CONFIG_TFTP_TSIZE
/* Print hash marks for the last packet received */
- while (TftpTsize && TftpNumchars < 49) {
+ while (tftp_tsize && tftp_tsize_num_hash < 49) {
putc('#');
- TftpNumchars++;
+ tftp_tsize_num_hash++;
}
puts(" ");
- print_size(TftpTsize, "");
+ print_size(tftp_tsize, "");
#endif
time_start = get_timer(time_start);
if (time_start > 0) {
puts("\n\t "); /* Line up with "Loading: " */
- print_size(NetBootFileXferSize /
+ print_size(net_boot_file_size /
time_start * 1000, "/s");
}
puts("\ndone\n");
net_set_state(NETLOOP_SUCCESS);
}
-static void
-TftpSend(void)
+static void tftp_send(void)
{
uchar *pkt;
uchar *xp;
@@ -322,24 +331,23 @@ TftpSend(void)
#ifdef CONFIG_MCAST_TFTP
/* Multicast TFTP.. non-MasterClients do not ACK data. */
- if (Multicast
- && (TftpState == STATE_DATA)
- && (MasterClient == 0))
+ if (tftp_mcast_active && tftp_state == STATE_DATA &&
+ tftp_mcast_master_client == 0)
return;
#endif
/*
* We will always be sending some sort of packet, so
* cobble together the packet headers now.
*/
- pkt = NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE;
+ pkt = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
- switch (TftpState) {
+ switch (tftp_state) {
case STATE_SEND_RRQ:
case STATE_SEND_WRQ:
xp = pkt;
s = (ushort *)pkt;
#ifdef CONFIG_CMD_TFTPPUT
- *s++ = htons(TftpState == STATE_SEND_RRQ ? TFTP_RRQ :
+ *s++ = htons(tftp_state == STATE_SEND_RRQ ? TFTP_RRQ :
TFTP_WRQ);
#else
*s++ = htons(TFTP_RRQ);
@@ -351,23 +359,23 @@ TftpSend(void)
pkt += 5 /*strlen("octet")*/ + 1;
strcpy((char *)pkt, "timeout");
pkt += 7 /*strlen("timeout")*/ + 1;
- sprintf((char *)pkt, "%lu", TftpTimeoutMSecs / 1000);
+ sprintf((char *)pkt, "%lu", timeout_ms / 1000);
debug("send option \"timeout %s\"\n", (char *)pkt);
pkt += strlen((char *)pkt) + 1;
#ifdef CONFIG_TFTP_TSIZE
- pkt += sprintf((char *)pkt, "tsize%c%lu%c",
- 0, NetBootFileXferSize, 0);
+ pkt += sprintf((char *)pkt, "tsize%c%u%c",
+ 0, net_boot_file_size, 0);
#endif
/* try for more effic. blk size */
pkt += sprintf((char *)pkt, "blksize%c%d%c",
- 0, TftpBlkSizeOption, 0);
+ 0, tftp_block_size_option, 0);
#ifdef CONFIG_MCAST_TFTP
/* Check all preconditions before even trying the option */
- if (!ProhibitMcast) {
- Bitmap = malloc(Mapsize);
- if (Bitmap && eth_get_dev()->mcast) {
- free(Bitmap);
- Bitmap = NULL;
+ if (!tftp_mcast_disabled) {
+ tftp_mcast_bitmap = malloc(tftp_mcast_bitmap_size);
+ if (tftp_mcast_bitmap && eth_get_dev()->mcast) {
+ free(tftp_mcast_bitmap);
+ tftp_mcast_bitmap = NULL;
pkt += sprintf((char *)pkt, "multicast%c%c",
0, 0);
}
@@ -378,11 +386,12 @@ TftpSend(void)
case STATE_OACK:
#ifdef CONFIG_MCAST_TFTP
- /* My turn! Start at where I need blocks I missed.*/
- if (Multicast)
- TftpBlock = ext2_find_next_zero_bit(Bitmap,
- (Mapsize*8), 0);
- /*..falling..*/
+ /* My turn! Start at where I need blocks I missed. */
+ if (tftp_mcast_active)
+ tftp_cur_block = ext2_find_next_zero_bit(
+ tftp_mcast_bitmap,
+ tftp_mcast_bitmap_size * 8, 0);
+ /* fall through */
#endif
case STATE_RECV_WRQ:
@@ -390,16 +399,16 @@ TftpSend(void)
xp = pkt;
s = (ushort *)pkt;
s[0] = htons(TFTP_ACK);
- s[1] = htons(TftpBlock);
+ s[1] = htons(tftp_cur_block);
pkt = (uchar *)(s + 2);
#ifdef CONFIG_CMD_TFTPPUT
- if (TftpWriting) {
- int toload = TftpBlkSize;
- int loaded = load_block(TftpBlock, pkt, toload);
+ if (tftp_put_active) {
+ int toload = tftp_block_size;
+ int loaded = load_block(tftp_cur_block, pkt, toload);
s[0] = htons(TFTP_DATA);
pkt += loaded;
- TftpFinalBlock = (loaded < toload);
+ tftp_put_final_block_sent = (loaded < toload);
}
#endif
len = pkt - xp;
@@ -429,13 +438,14 @@ TftpSend(void)
break;
}
- NetSendUDPPacket(NetServerEther, TftpRemoteIP, TftpRemotePort,
- TftpOurPort, len);
+ net_send_udp_packet(net_server_ethaddr, tftp_remote_ip,
+ tftp_remote_port, tftp_our_port, len);
}
#ifdef CONFIG_CMD_TFTPPUT
static void icmp_handler(unsigned type, unsigned code, unsigned dest,
- IPaddr_t sip, unsigned src, uchar *pkt, unsigned len)
+ struct in_addr sip, unsigned src, uchar *pkt,
+ unsigned len)
{
if (type == ICMP_NOT_REACH && code == ICMP_NOT_REACH_PORT) {
/* Oh dear the other end has gone away */
@@ -444,23 +454,22 @@ static void icmp_handler(unsigned type, unsigned code, unsigned dest,
}
#endif
-static void
-TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
- unsigned len)
+static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
+ unsigned src, unsigned len)
{
__be16 proto;
__be16 *s;
int i;
- if (dest != TftpOurPort) {
+ if (dest != tftp_our_port) {
#ifdef CONFIG_MCAST_TFTP
- if (Multicast
- && (!Mcast_port || (dest != Mcast_port)))
+ if (tftp_mcast_active &&
+ (!tftp_mcast_port || dest != tftp_mcast_port))
#endif
return;
}
- if (TftpState != STATE_SEND_RRQ && src != TftpRemotePort &&
- TftpState != STATE_RECV_WRQ && TftpState != STATE_SEND_WRQ)
+ if (tftp_state != STATE_SEND_RRQ && src != tftp_remote_port &&
+ tftp_state != STATE_RECV_WRQ && tftp_state != STATE_SEND_WRQ)
return;
if (len < 2)
@@ -471,14 +480,13 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
proto = *s++;
pkt = (uchar *)s;
switch (ntohs(proto)) {
-
case TFTP_RRQ:
break;
case TFTP_ACK:
#ifdef CONFIG_CMD_TFTPPUT
- if (TftpWriting) {
- if (TftpFinalBlock) {
+ if (tftp_put_active) {
+ if (tftp_put_final_block_sent) {
tftp_complete();
} else {
/*
@@ -486,12 +494,12 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
* count to wrap just like the other end!
*/
int block = ntohs(*s);
- int ack_ok = (TftpBlock == block);
+ int ack_ok = (tftp_cur_block == block);
- TftpBlock = (unsigned short)(block + 1);
+ tftp_cur_block = (unsigned short)(block + 1);
update_block_number();
if (ack_ok)
- TftpSend(); /* Send next data block */
+ tftp_send(); /* Send next data block */
}
}
#endif
@@ -503,102 +511,99 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
#ifdef CONFIG_CMD_TFTPSRV
case TFTP_WRQ:
debug("Got WRQ\n");
- TftpRemoteIP = sip;
- TftpRemotePort = src;
- TftpOurPort = 1024 + (get_timer(0) % 3072);
+ tftp_remote_ip = sip;
+ tftp_remote_port = src;
+ tftp_our_port = 1024 + (get_timer(0) % 3072);
new_transfer();
- TftpSend(); /* Send ACK(0) */
+ tftp_send(); /* Send ACK(0) */
break;
#endif
case TFTP_OACK:
debug("Got OACK: %s %s\n",
- pkt,
- pkt + strlen((char *)pkt) + 1);
- TftpState = STATE_OACK;
- TftpRemotePort = src;
+ pkt, pkt + strlen((char *)pkt) + 1);
+ tftp_state = STATE_OACK;
+ tftp_remote_port = src;
/*
* Check for 'blksize' option.
* Careful: "i" is signed, "len" is unsigned, thus
* something like "len-8" may give a *huge* number
*/
for (i = 0; i+8 < len; i++) {
- if (strcmp((char *)pkt+i, "blksize") == 0) {
- TftpBlkSize = (unsigned short)
- simple_strtoul((char *)pkt+i+8, NULL,
- 10);
+ if (strcmp((char *)pkt + i, "blksize") == 0) {
+ tftp_block_size = (unsigned short)
+ simple_strtoul((char *)pkt + i + 8,
+ NULL, 10);
debug("Blocksize ack: %s, %d\n",
- (char *)pkt+i+8, TftpBlkSize);
+ (char *)pkt + i + 8, tftp_block_size);
}
#ifdef CONFIG_TFTP_TSIZE
if (strcmp((char *)pkt+i, "tsize") == 0) {
- TftpTsize = simple_strtoul((char *)pkt+i+6,
+ tftp_tsize = simple_strtoul((char *)pkt + i + 6,
NULL, 10);
debug("size = %s, %d\n",
- (char *)pkt+i+6, TftpTsize);
+ (char *)pkt + i + 6, tftp_tsize);
}
#endif
}
#ifdef CONFIG_MCAST_TFTP
- parse_multicast_oack((char *)pkt, len-1);
- if ((Multicast) && (!MasterClient))
- TftpState = STATE_DATA; /* passive.. */
+ parse_multicast_oack((char *)pkt, len - 1);
+ if ((tftp_mcast_active) && (!tftp_mcast_master_client))
+ tftp_state = STATE_DATA; /* passive.. */
else
#endif
#ifdef CONFIG_CMD_TFTPPUT
- if (TftpWriting) {
+ if (tftp_put_active) {
/* Get ready to send the first block */
- TftpState = STATE_DATA;
- TftpBlock++;
+ tftp_state = STATE_DATA;
+ tftp_cur_block++;
}
#endif
- TftpSend(); /* Send ACK or first data block */
+ tftp_send(); /* Send ACK or first data block */
break;
case TFTP_DATA:
if (len < 2)
return;
len -= 2;
- TftpBlock = ntohs(*(__be16 *)pkt);
+ tftp_cur_block = ntohs(*(__be16 *)pkt);
update_block_number();
- if (TftpState == STATE_SEND_RRQ)
+ if (tftp_state == STATE_SEND_RRQ)
debug("Server did not acknowledge timeout option!\n");
- if (TftpState == STATE_SEND_RRQ || TftpState == STATE_OACK ||
- TftpState == STATE_RECV_WRQ) {
+ if (tftp_state == STATE_SEND_RRQ || tftp_state == STATE_OACK ||
+ tftp_state == STATE_RECV_WRQ) {
/* first block received */
- TftpState = STATE_DATA;
- TftpRemotePort = src;
+ tftp_state = STATE_DATA;
+ tftp_remote_port = src;
new_transfer();
#ifdef CONFIG_MCAST_TFTP
- if (Multicast) { /* start!=1 common if mcast */
- TftpLastBlock = TftpBlock - 1;
+ if (tftp_mcast_active) { /* start!=1 common if mcast */
+ tftp_prev_block = tftp_cur_block - 1;
} else
#endif
- if (TftpBlock != 1) { /* Assertion */
- printf("\nTFTP error: "
- "First block is not block 1 (%ld)\n"
- "Starting again\n\n",
- TftpBlock);
- NetStartAgain();
+ if (tftp_cur_block != 1) { /* Assertion */
+ puts("\nTFTP error: ");
+ printf("First block is not block 1 (%ld)\n",
+ tftp_cur_block);
+ puts("Starting again\n\n");
+ net_start_again();
break;
}
}
- if (TftpBlock == TftpLastBlock) {
- /*
- * Same block again; ignore it.
- */
+ if (tftp_cur_block == tftp_prev_block) {
+ /* Same block again; ignore it. */
break;
}
- TftpLastBlock = TftpBlock;
- TftpTimeoutCountMax = TIMEOUT_COUNT;
- NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
+ tftp_prev_block = tftp_cur_block;
+ timeout_count_max = TIMEOUT_COUNT;
+ net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
- store_block(TftpBlock - 1, pkt + 2, len);
+ store_block(tftp_cur_block - 1, pkt + 2, len);
/*
* Acknowledge the block just received, which will prompt
@@ -608,39 +613,41 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
/* if I am the MasterClient, actively calculate what my next
* needed block is; else I'm passive; not ACKING
*/
- if (Multicast) {
- if (len < TftpBlkSize) {
- TftpEndingBlock = TftpBlock;
- } else if (MasterClient) {
- TftpBlock = PrevBitmapHole =
- ext2_find_next_zero_bit(
- Bitmap,
- (Mapsize*8),
- PrevBitmapHole);
- if (TftpBlock > ((Mapsize*8) - 1)) {
- printf("tftpfile too big\n");
+ if (tftp_mcast_active) {
+ if (len < tftp_block_size) {
+ tftp_mcast_ending_block = tftp_cur_block;
+ } else if (tftp_mcast_master_client) {
+ tftp_mcast_prev_hole = ext2_find_next_zero_bit(
+ tftp_mcast_bitmap,
+ tftp_mcast_bitmap_size * 8,
+ tftp_mcast_prev_hole);
+ tftp_cur_block = tftp_mcast_prev_hole;
+ if (tftp_cur_block >
+ ((tftp_mcast_bitmap_size * 8) - 1)) {
+ debug("tftpfile too big\n");
/* try to double it and retry */
- Mapsize <<= 1;
+ tftp_mcast_bitmap_size <<= 1;
mcast_cleanup();
- NetStartAgain();
+ net_start_again();
return;
}
- TftpLastBlock = TftpBlock;
+ tftp_prev_block = tftp_cur_block;
}
}
#endif
- TftpSend();
+ tftp_send();
#ifdef CONFIG_MCAST_TFTP
- if (Multicast) {
- if (MasterClient && (TftpBlock >= TftpEndingBlock)) {
+ if (tftp_mcast_active) {
+ if (tftp_mcast_master_client &&
+ (tftp_cur_block >= tftp_mcast_ending_block)) {
puts("\nMulticast tftp done\n");
mcast_cleanup();
net_set_state(NETLOOP_SUCCESS);
}
} else
#endif
- if (len < TftpBlkSize)
+ if (len < tftp_block_size)
tftp_complete();
break;
@@ -665,7 +672,7 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
#ifdef CONFIG_MCAST_TFTP
mcast_cleanup();
#endif
- NetStartAgain();
+ net_start_again();
break;
}
break;
@@ -673,21 +680,20 @@ TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
}
-static void
-TftpTimeout(void)
+static void tftp_timeout_handler(void)
{
- if (++TftpTimeoutCount > TftpTimeoutCountMax) {
+ if (++timeout_count > timeout_count_max) {
restart("Retry count exceeded");
} else {
puts("T ");
- NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
- if (TftpState != STATE_RECV_WRQ)
- TftpSend();
+ net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
+ if (tftp_state != STATE_RECV_WRQ)
+ tftp_send();
}
}
-void TftpStart(enum proto_t protocol)
+void tftp_start(enum proto_t protocol)
{
char *ep; /* Environment pointer */
@@ -697,45 +703,44 @@ void TftpStart(enum proto_t protocol)
*/
ep = getenv("tftpblocksize");
if (ep != NULL)
- TftpBlkSizeOption = simple_strtol(ep, NULL, 10);
+ tftp_block_size_option = simple_strtol(ep, NULL, 10);
ep = getenv("tftptimeout");
if (ep != NULL)
- TftpTimeoutMSecs = simple_strtol(ep, NULL, 10);
+ timeout_ms = simple_strtol(ep, NULL, 10);
- if (TftpTimeoutMSecs < 1000) {
- printf("TFTP timeout (%ld ms) too low, "
- "set minimum = 1000 ms\n",
- TftpTimeoutMSecs);
- TftpTimeoutMSecs = 1000;
+ if (timeout_ms < 1000) {
+ printf("TFTP timeout (%ld ms) too low, set min = 1000 ms\n",
+ timeout_ms);
+ timeout_ms = 1000;
}
debug("TFTP blocksize = %i, timeout = %ld ms\n",
- TftpBlkSizeOption, TftpTimeoutMSecs);
+ tftp_block_size_option, timeout_ms);
- TftpRemoteIP = NetServerIP;
- if (BootFile[0] == '\0') {
+ tftp_remote_ip = net_server_ip;
+ if (net_boot_file_name[0] == '\0') {
sprintf(default_filename, "%02X%02X%02X%02X.img",
- NetOurIP & 0xFF,
- (NetOurIP >> 8) & 0xFF,
- (NetOurIP >> 16) & 0xFF,
- (NetOurIP >> 24) & 0xFF);
+ net_ip.s_addr & 0xFF,
+ (net_ip.s_addr >> 8) & 0xFF,
+ (net_ip.s_addr >> 16) & 0xFF,
+ (net_ip.s_addr >> 24) & 0xFF);
strncpy(tftp_filename, default_filename, MAX_LEN);
- tftp_filename[MAX_LEN-1] = 0;
+ tftp_filename[MAX_LEN - 1] = 0;
printf("*** Warning: no boot file name; using '%s'\n",
- tftp_filename);
+ tftp_filename);
} else {
- char *p = strchr(BootFile, ':');
+ char *p = strchr(net_boot_file_name, ':');
if (p == NULL) {
- strncpy(tftp_filename, BootFile, MAX_LEN);
- tftp_filename[MAX_LEN-1] = 0;
+ strncpy(tftp_filename, net_boot_file_name, MAX_LEN);
+ tftp_filename[MAX_LEN - 1] = 0;
} else {
- TftpRemoteIP = string_to_ip(BootFile);
+ tftp_remote_ip = string_to_ip(net_boot_file_name);
strncpy(tftp_filename, p + 1, MAX_LEN);
- tftp_filename[MAX_LEN-1] = 0;
+ tftp_filename[MAX_LEN - 1] = 0;
}
}
@@ -744,124 +749,127 @@ void TftpStart(enum proto_t protocol)
#ifdef CONFIG_CMD_TFTPPUT
protocol == TFTPPUT ? "to" : "from",
#else
- "from",
+ "from",
#endif
- &TftpRemoteIP, &NetOurIP);
+ &tftp_remote_ip, &net_ip);
/* Check if we need to send across this subnet */
- if (NetOurGatewayIP && NetOurSubnetMask) {
- IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
- IPaddr_t RemoteNet = TftpRemoteIP & NetOurSubnetMask;
-
- if (OurNet != RemoteNet)
- printf("; sending through gateway %pI4",
- &NetOurGatewayIP);
+ if (net_gateway.s_addr && net_netmask.s_addr) {
+ struct in_addr our_net;
+ struct in_addr remote_net;
+
+ our_net.s_addr = net_ip.s_addr & net_netmask.s_addr;
+ remote_net.s_addr = tftp_remote_ip.s_addr & net_netmask.s_addr;
+ if (our_net.s_addr != remote_net.s_addr)
+ printf("; sending through gateway %pI4", &net_gateway);
}
putc('\n');
printf("Filename '%s'.", tftp_filename);
- if (NetBootFileSize) {
- printf(" Size is 0x%x Bytes = ", NetBootFileSize<<9);
- print_size(NetBootFileSize<<9, "");
+ if (net_boot_file_expected_size_in_blocks) {
+ printf(" Size is 0x%x Bytes = ",
+ net_boot_file_expected_size_in_blocks << 9);
+ print_size(net_boot_file_expected_size_in_blocks << 9, "");
}
putc('\n');
#ifdef CONFIG_CMD_TFTPPUT
- TftpWriting = (protocol == TFTPPUT);
- if (TftpWriting) {
+ tftp_put_active = (protocol == TFTPPUT);
+ if (tftp_put_active) {
printf("Save address: 0x%lx\n", save_addr);
printf("Save size: 0x%lx\n", save_size);
- NetBootFileXferSize = save_size;
+ net_boot_file_size = save_size;
puts("Saving: *\b");
- TftpState = STATE_SEND_WRQ;
+ tftp_state = STATE_SEND_WRQ;
new_transfer();
} else
#endif
{
printf("Load address: 0x%lx\n", load_addr);
puts("Loading: *\b");
- TftpState = STATE_SEND_RRQ;
+ tftp_state = STATE_SEND_RRQ;
}
time_start = get_timer(0);
- TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
+ timeout_count_max = tftp_timeout_count_max;
- NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
- net_set_udp_handler(TftpHandler);
+ net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
+ net_set_udp_handler(tftp_handler);
#ifdef CONFIG_CMD_TFTPPUT
net_set_icmp_handler(icmp_handler);
#endif
- TftpRemotePort = WELL_KNOWN_PORT;
- TftpTimeoutCount = 0;
+ tftp_remote_port = WELL_KNOWN_PORT;
+ timeout_count = 0;
/* Use a pseudo-random port unless a specific port is set */
- TftpOurPort = 1024 + (get_timer(0) % 3072);
+ tftp_our_port = 1024 + (get_timer(0) % 3072);
#ifdef CONFIG_TFTP_PORT
ep = getenv("tftpdstp");
if (ep != NULL)
- TftpRemotePort = simple_strtol(ep, NULL, 10);
+ tftp_remote_port = simple_strtol(ep, NULL, 10);
ep = getenv("tftpsrcp");
if (ep != NULL)
- TftpOurPort = simple_strtol(ep, NULL, 10);
+ tftp_our_port = simple_strtol(ep, NULL, 10);
#endif
- TftpBlock = 0;
+ tftp_cur_block = 0;
/* zero out server ether in case the server ip has changed */
- memset(NetServerEther, 0, 6);
- /* Revert TftpBlkSize to dflt */
- TftpBlkSize = TFTP_BLOCK_SIZE;
+ memset(net_server_ethaddr, 0, 6);
+ /* Revert tftp_block_size to dflt */
+ tftp_block_size = TFTP_BLOCK_SIZE;
#ifdef CONFIG_MCAST_TFTP
mcast_cleanup();
#endif
#ifdef CONFIG_TFTP_TSIZE
- TftpTsize = 0;
- TftpNumchars = 0;
+ tftp_tsize = 0;
+ tftp_tsize_num_hash = 0;
#endif
- TftpSend();
+ tftp_send();
}
#ifdef CONFIG_CMD_TFTPSRV
-void
-TftpStartServer(void)
+void tftp_start_server(void)
{
tftp_filename[0] = 0;
printf("Using %s device\n", eth_get_name());
- printf("Listening for TFTP transfer on %pI4\n", &NetOurIP);
+ printf("Listening for TFTP transfer on %pI4\n", &net_ip);
printf("Load address: 0x%lx\n", load_addr);
puts("Loading: *\b");
- TftpTimeoutCountMax = TIMEOUT_COUNT;
- TftpTimeoutCount = 0;
- TftpTimeoutMSecs = TIMEOUT;
- NetSetTimeout(TftpTimeoutMSecs, TftpTimeout);
+ timeout_count_max = TIMEOUT_COUNT;
+ timeout_count = 0;
+ timeout_ms = TIMEOUT;
+ net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
- /* Revert TftpBlkSize to dflt */
- TftpBlkSize = TFTP_BLOCK_SIZE;
- TftpBlock = 0;
- TftpOurPort = WELL_KNOWN_PORT;
+ /* Revert tftp_block_size to dflt */
+ tftp_block_size = TFTP_BLOCK_SIZE;
+ tftp_cur_block = 0;
+ tftp_our_port = WELL_KNOWN_PORT;
#ifdef CONFIG_TFTP_TSIZE
- TftpTsize = 0;
- TftpNumchars = 0;
+ tftp_tsize = 0;
+ tftp_tsize_num_hash = 0;
#endif
- TftpState = STATE_RECV_WRQ;
- net_set_udp_handler(TftpHandler);
+ tftp_state = STATE_RECV_WRQ;
+ net_set_udp_handler(tftp_handler);
/* zero out server ether in case the server ip has changed */
- memset(NetServerEther, 0, 6);
+ memset(net_server_ethaddr, 0, 6);
}
#endif /* CONFIG_CMD_TFTPSRV */
#ifdef CONFIG_MCAST_TFTP
-/* Credits: atftp project.
+/*
+ * Credits: atftp project.
*/
-/* pick up BcastAddr, Port, and whether I am [now] the master-client. *
+/*
+ * Pick up BcastAddr, Port, and whether I am [now] the master-client.
* Frame:
* +-------+-----------+---+-------~~-------+---+
* | opc | multicast | 0 | addr, port, mc | 0 |
@@ -876,75 +884,80 @@ TftpStartServer(void)
static void parse_multicast_oack(char *pkt, int len)
{
int i;
- IPaddr_t addr;
- char *mc_adr, *port, *mc;
-
- mc_adr = port = mc = NULL;
+ struct in_addr addr;
+ char *mc_adr;
+ char *port;
+ char *mc;
+
+ mc_adr = NULL;
+ port = NULL;
+ mc = NULL;
/* march along looking for 'multicast\0', which has to start at least
* 14 bytes back from the end.
*/
- for (i = 0; i < len-14; i++)
- if (strcmp(pkt+i, "multicast") == 0)
+ for (i = 0; i < len - 14; i++)
+ if (strcmp(pkt + i, "multicast") == 0)
break;
- if (i >= (len-14)) /* non-Multicast OACK, ign. */
+ if (i >= (len - 14)) /* non-Multicast OACK, ign. */
return;
i += 10; /* strlen multicast */
- mc_adr = pkt+i;
+ mc_adr = pkt + i;
for (; i < len; i++) {
- if (*(pkt+i) == ',') {
- *(pkt+i) = '\0';
+ if (*(pkt + i) == ',') {
+ *(pkt + i) = '\0';
if (port) {
- mc = pkt+i+1;
+ mc = pkt + i + 1;
break;
} else {
- port = pkt+i+1;
+ port = pkt + i + 1;
}
}
}
if (!port || !mc_adr || !mc)
return;
- if (Multicast && MasterClient) {
+ if (tftp_mcast_active && tftp_mcast_master_client) {
printf("I got a OACK as master Client, WRONG!\n");
return;
}
/* ..I now accept packets destined for this MCAST addr, port */
- if (!Multicast) {
- if (Bitmap) {
+ if (!tftp_mcast_active) {
+ if (tftp_mcast_bitmap) {
printf("Internal failure! no mcast.\n");
- free(Bitmap);
- Bitmap = NULL;
- ProhibitMcast = 1;
- return ;
+ free(tftp_mcast_bitmap);
+ tftp_mcast_bitmap = NULL;
+ tftp_mcast_disabled = 1;
+ return;
}
/* I malloc instead of pre-declare; so that if the file ends
* up being too big for this bitmap I can retry
*/
- Bitmap = malloc(Mapsize);
- if (!Bitmap) {
- printf("No Bitmap, no multicast. Sorry.\n");
- ProhibitMcast = 1;
+ tftp_mcast_bitmap = malloc(tftp_mcast_bitmap_size);
+ if (!tftp_mcast_bitmap) {
+ printf("No bitmap, no multicast. Sorry.\n");
+ tftp_mcast_disabled = 1;
return;
}
- memset(Bitmap, 0, Mapsize);
- PrevBitmapHole = 0;
- Multicast = 1;
+ memset(tftp_mcast_bitmap, 0, tftp_mcast_bitmap_size);
+ tftp_mcast_prev_hole = 0;
+ tftp_mcast_active = 1;
}
addr = string_to_ip(mc_adr);
- if (Mcast_addr != addr) {
- if (Mcast_addr)
- eth_mcast_join(Mcast_addr, 0);
- Mcast_addr = addr;
- if (eth_mcast_join(Mcast_addr, 1)) {
+ if (net_mcast_addr.s_addr != addr.s_addr) {
+ if (net_mcast_addr.s_addr)
+ eth_mcast_join(net_mcast_addr, 0);
+ net_mcast_addr = addr;
+ if (eth_mcast_join(net_mcast_addr, 1)) {
printf("Fail to set mcast, revert to TFTP\n");
- ProhibitMcast = 1;
+ tftp_mcast_disabled = 1;
mcast_cleanup();
- NetStartAgain();
+ net_start_again();
}
}
- MasterClient = (unsigned char)simple_strtoul((char *)mc, NULL, 10);
- Mcast_port = (unsigned short)simple_strtoul(port, NULL, 10);
- printf("Multicast: %s:%d [%d]\n", mc_adr, Mcast_port, MasterClient);
+ tftp_mcast_master_client = simple_strtoul((char *)mc, NULL, 10);
+ tftp_mcast_port = (unsigned short)simple_strtoul(port, NULL, 10);
+ printf("Multicast: %s:%d [%d]\n", mc_adr, tftp_mcast_port,
+ tftp_mcast_master_client);
return;
}
diff --git a/net/tftp.h b/net/tftp.h
index 2b686e3..c411c9b 100644
--- a/net/tftp.h
+++ b/net/tftp.h
@@ -16,14 +16,14 @@
*/
/* tftp.c */
-void TftpStart(enum proto_t protocol); /* Begin TFTP get/put */
+void tftp_start(enum proto_t protocol); /* Begin TFTP get/put */
#ifdef CONFIG_CMD_TFTPSRV
-extern void TftpStartServer(void); /* Wait for incoming TFTP put */
+void tftp_start_server(void); /* Wait for incoming TFTP put */
#endif
-extern ulong TftpRRQTimeoutMSecs;
-extern int TftpRRQTimeoutCountMax;
+extern ulong tftp_timeout_ms;
+extern int tftp_timeout_count_max;
/**********************************************************************/