IPaddr_t sip, unsigned src,
unsigned len)
{
- NetState = NETLOOP_SUCCESS; /* got arp reply - quit net loop */
+ net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */
}
static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
unsigned len)
{
if (input_size)
- NetState = NETLOOP_SUCCESS; /* got input - quit net loop */
+ net_set_state(NETLOOP_SUCCESS); /* got input - quit net loop */
}
static void nc_timeout(void)
{
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
}
void NcStart(void)
extern ushort NetOurVLAN; /* Our VLAN */
extern ushort NetOurNativeVLAN; /* Our Native VLAN */
-extern int NetState; /* Network loop state */
-#define NETLOOP_CONTINUE 1
-#define NETLOOP_RESTART 2
-#define NETLOOP_SUCCESS 3
-#define NETLOOP_FAIL 4
-
extern int NetRestartWrap; /* Tried all network devices */
enum proto_t {
extern void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */
extern void NetSetTimeout(ulong, thand_f *);/* Set timeout handler */
+/* Network loop state */
+enum net_loop_state {
+ NETLOOP_CONTINUE,
+ NETLOOP_RESTART,
+ NETLOOP_SUCCESS,
+ NETLOOP_FAIL
+};
+static inline void net_set_state(enum net_loop_state state)
+{
+ extern enum net_loop_state net_state;
+
+ net_state = state;
+}
+
/* Transmit "NetTxPacket" */
static inline void NetSendPacket(uchar *pkt, int len)
{
if (!CDPOK)
NetStartAgain();
else
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
}
static void
DnsTimeout(void)
{
puts("Timeout\n");
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
}
static void
/* Received 0 answers */
if (header->nanswers == 0) {
puts("DNS: host not found\n");
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
return;
}
/* We sent query class 1, query type 1 */
if (&p[5] > e || get_unaligned_be16(p+1) != DNS_A_RECORD) {
puts("DNS: response was not an A record\n");
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
return;
}
puts("server responded with invalid IP number\n");
}
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
}
void
void (*push_packet)(void *, int len) = 0;
#endif
/* Network loop state */
-int NetState;
+enum net_loop_state net_state;
/* Tried all network devices */
int NetRestartWrap;
/* Network loop restarted */
* Just use BOOTP/RARP to configure system;
* Do not use TFTP to load the bootfile.
*/
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
return;
}
#if defined(CONFIG_CMD_NFS)
restart:
memcpy(NetOurEther, eth_get_dev()->enetaddr, 6);
- NetState = NETLOOP_CONTINUE;
+ net_set_state(NETLOOP_CONTINUE);
/*
* Start the ball rolling with the given start function. From
/*
* Main packet reception loop. Loop receiving packets until
- * someone sets `NetState' to a state that terminates.
+ * someone sets `net_state' to a state that terminates.
*/
for (;;) {
WATCHDOG_RESET();
}
- switch (NetState) {
+ switch (net_state) {
case NETLOOP_RESTART:
NetRestarted = 1;
case NETLOOP_FAIL:
goto done;
+
+ case NETLOOP_CONTINUE:
+ continue;
}
}
static void
startAgainTimeout(void)
{
- NetState = NETLOOP_RESTART;
+ net_set_state(NETLOOP_RESTART);
}
static void
if ((!retry_forever) && (NetTryCount >= retrycnt)) {
eth_halt();
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
return;
}
NetSetTimeout(10000UL, startAgainTimeout);
NetSetHandler(startAgainHandler);
} else {
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
}
} else {
- NetState = NETLOOP_RESTART;
+ net_set_state(NETLOOP_RESTART);
}
}
static char dirfh[NFS_FHSIZE]; /* file handle of directory */
static char filefh[NFS_FHSIZE]; /* file handle of kernel image */
-static int NfsDownloadState;
+static enum net_loop_state nfs_download_state;
static IPaddr_t NfsServerIP;
static int NfsSrvMountPort;
static int NfsSrvNfsPort;
case STATE_UMOUNT_REQ:
if (nfs_umountall_reply(pkt, len)) {
puts("*** ERROR: Cannot umount\n");
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
} else {
puts("\ndone\n");
- NetState = NfsDownloadState;
+ net_set_state(nfs_download_state);
}
break;
NfsSend();
} else {
if (!rlen)
- NfsDownloadState = NETLOOP_SUCCESS;
+ nfs_download_state = NETLOOP_SUCCESS;
NfsState = STATE_UMOUNT_REQ;
NfsSend();
}
NfsStart(void)
{
debug("%s\n", __func__);
- NfsDownloadState = NETLOOP_FAIL;
+ nfs_download_state = NETLOOP_FAIL;
NfsServerIP = NetServerIP;
nfs_path = (char *)nfs_path_buff;
if (nfs_path == NULL) {
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
puts("*** ERROR: Fail allocate memory\n");
return;
}
static void ping_timeout(void)
{
eth_halt();
- NetState = NETLOOP_FAIL; /* we did not get the reply */
+ net_set_state(NETLOOP_FAIL); /* we did not get the reply */
}
void ping_start(void)
case ICMP_ECHO_REPLY:
src_ip = NetReadIP((void *)&ip->ip_src);
if (src_ip == NetPingIP)
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
return;
case ICMP_ECHO_REQUEST:
debug("Got ICMP ECHO REQUEST, return "
SntpTimeout(void)
{
puts("Timeout\n");
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
return;
}
tm.tm_year, tm.tm_mon, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
}
void
rc = flash_write((char *)src, (ulong)(load_addr+offset), len);
if (rc) {
flash_perror(rc);
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
return;
}
} else
}
#endif
puts("\ndone\n");
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
}
static void
if (MasterClient && (TftpBlock >= TftpEndingBlock)) {
puts("\nMulticast tftp done\n");
mcast_cleanup();
- NetState = NETLOOP_SUCCESS;
+ net_set_state(NETLOOP_SUCCESS);
}
} else
#endif
case TFTP_ERR_ACCESS_DENIED:
puts("Not retrying...\n");
eth_halt();
- NetState = NETLOOP_FAIL;
+ net_set_state(NETLOOP_FAIL);
break;
case TFTP_ERR_UNDEFINED:
case TFTP_ERR_DISK_FULL: