Skip to content
Snippets Groups Projects
net.c 29.6 KiB
Newer Older
Wolfgang Denk's avatar
Wolfgang Denk committed
/*
 *	Copied from Linux Monitor (LiMon) - Networking.
 *
 *	Copyright 1994 - 2000 Neil Russell.
 *	(See License)
 *	Copyright 2000 Roland Borde
 *	Copyright 2000 Paolo Scaffardi
 *	Copyright 2000-2002 Wolfgang Denk, wd@denx.de
 */

/*
 * General Desription:
 *
 * The user interface supports commands for BOOTP, RARP, and TFTP.
 * Also, we support ARP internally. Depending on available data,
 * these interact as follows:
 *
 * BOOTP:
 *
 *	Prerequisites:	- own ethernet address
 *	We want:	- own IP address
 *			- TFTP server IP address
 *			- name of bootfile
 *	Next step:	ARP
 *
 * RARP:
 *
 *	Prerequisites:	- own ethernet address
 *	We want:	- own IP address
 *			- TFTP server IP address
 *	Next step:	ARP
 *
 * ARP:
 *
 *	Prerequisites:	- own ethernet address
 *			- own IP address
 *			- TFTP server IP address
 *	We want:	- TFTP server ethernet address
 *	Next step:	TFTP
 *
 * DHCP:
 *
Wolfgang Denk's avatar
Wolfgang Denk committed
 *     Prerequisites:	- own ethernet address
 *     We want:		- IP, Netmask, ServerIP, Gateway IP
 *			- bootfilename, lease time
 *     Next step:	- TFTP
Wolfgang Denk's avatar
Wolfgang Denk committed
 *
 * TFTP:
 *
 *	Prerequisites:	- own ethernet address
 *			- own IP address
 *			- TFTP server IP address
 *			- TFTP server ethernet address
 *			- name of bootfile (if unknown, we use a default name
 *			  derived from our own IP address)
 *	We want:	- load the boot file
 *	Next step:	none
 *
 * NFS:
 *
 *	Prerequisites:	- own ethernet address
 *			- own IP address
 *			- name of bootfile (if unknown, we use a default name
 *			  derived from our own IP address)
 *	We want:	- load the boot file
 *	Next step:	none
Wolfgang Denk's avatar
Wolfgang Denk committed
 *	Prerequisites:	- own ethernet address
 *			- own IP address
 *	We want:	- network time
 *	Next step:	none
Wolfgang Denk's avatar
Wolfgang Denk committed
 */


#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <linux/compiler.h>
Wolfgang Denk's avatar
Wolfgang Denk committed
#include <net.h>
#include "arp.h"
Wolfgang Denk's avatar
Wolfgang Denk committed
#include "bootp.h"
#include "tftp.h"
#include "rarp.h"
#include "nfs.h"
#ifdef CONFIG_STATUS_LED
#include <status_led.h>
#include <miiphy.h>
#endif
#if defined(CONFIG_CMD_SNTP)
#include "sntp.h"
#endif
#include "cdp.h"
Robin Getz's avatar
Robin Getz committed
#if defined(CONFIG_CMD_DNS)
#include "dns.h"
#endif
#include "ping.h"
Wolfgang Denk's avatar
Wolfgang Denk committed

Wolfgang Denk's avatar
Wolfgang Denk committed
/** BOOTP EXTENTIONS **/

/* Our subnet mask (0=unknown) */
IPaddr_t	NetOurSubnetMask;
/* Our gateways IP address */
IPaddr_t	NetOurGatewayIP;
/* Our DNS IP address */
IPaddr_t	NetOurDNSIP;
#if defined(CONFIG_BOOTP_DNS2)
/* Our 2nd DNS IP address */
IPaddr_t	NetOurDNS2IP;
#endif
/* Our NIS domain */
char		NetOurNISDomain[32] = {0,};
char		NetOurHostName[32] = {0,};
char		NetOurRootPath[64] = {0,};
/* Our bootfile size in blocks */
ushort		NetBootFileSize;
Wolfgang Denk's avatar
Wolfgang Denk committed

David Updegraff's avatar
David Updegraff committed
#ifdef CONFIG_MCAST_TFTP	/* Multicast TFTP */
IPaddr_t Mcast_addr;
#endif

Wolfgang Denk's avatar
Wolfgang Denk committed
/** END OF BOOTP EXTENTIONS **/

/* The actual transferred size of the bootfile (in bytes) */
ulong		NetBootFileXferSize;
/* Our ethernet address */
uchar		NetOurEther[6];
/* Boot server enet address */
uchar		NetServerEther[6];
/* Our IP addr (0 = unknown) */
IPaddr_t	NetOurIP;
/* Server IP addr (0 = unknown) */
IPaddr_t	NetServerIP;
/* Current receive packet */
uchar *NetRxPacket;
/* Current rx packet length */
int		NetRxPacketLen;
/* IP packet ID */
unsigned	NetIPID;
/* Ethernet bcast address */
uchar		NetBcastAddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
uchar		NetEtherNullAddr[6];
#ifdef CONFIG_API
void		(*push_packet)(void *, int len) = 0;
/* Network loop state */
int		NetState;
/* Tried all network devices */
int		NetRestartWrap;
/* Network loop restarted */
static int	NetRestarted;
/* At least one device configured */
static int	NetDevExists;
Wolfgang Denk's avatar
Wolfgang Denk committed

Wolfgang Denk's avatar
Wolfgang Denk committed
/* XXX in both little & big endian machines 0xFFFF == ntohs(-1) */
/* default is without VLAN */
ushort		NetOurVLAN = 0xFFFF;
/* ditto */
ushort		NetOurNativeVLAN = 0xFFFF;
/* Boot File name */
char		BootFile[128];
Wolfgang Denk's avatar
Wolfgang Denk committed

#if defined(CONFIG_CMD_SNTP)
/* NTP server IP address */
IPaddr_t	NetNtpServerIP;
/* offset time from UTC */
int		NetTimeOffset;
uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
Wolfgang Denk's avatar
Wolfgang Denk committed

/* Receive packet */
uchar *NetRxPackets[PKTBUFSRX];
Wolfgang Denk's avatar
Wolfgang Denk committed

/* Current RX packet handler */
static rxhand_f *packetHandler;
#ifdef CONFIG_CMD_TFTPPUT
static rxhand_icmp_f *packet_icmp_handler;	/* Current ICMP rx handler */
/* Current timeout handler */
static thand_f *timeHandler;
/* Time base value */
static ulong	timeStart;
/* Current timeout value */
static ulong	timeDelta;
/* THE transmit packet */
uchar *NetTxPacket;
Wolfgang Denk's avatar
Wolfgang Denk committed

static int net_check_prereq(enum proto_t protocol);
Wolfgang Denk's avatar
Wolfgang Denk committed

static int NetTryCount;

/**********************************************************************/

Loading
Loading full blame...