net: remove switch/case in NetLoop()
Instead of having a big switch/case for every protocol, do the right things in the individual functions before callong NetLoop(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
8fe37b4e2e
commit
a3a5927110
|
@ -145,6 +145,7 @@ U_BOOT_CMD_END
|
||||||
* after loading?
|
* after loading?
|
||||||
* @note This command is available only, if enabled in the menuconfig.
|
* @note This command is available only, if enabled in the menuconfig.
|
||||||
*/
|
*/
|
||||||
|
extern void DhcpRequest(void);
|
||||||
|
|
||||||
#ifdef CONFIG_NET_DHCP
|
#ifdef CONFIG_NET_DHCP
|
||||||
static int do_dhcp (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
static int do_dhcp (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
|
@ -154,7 +155,10 @@ static int do_dhcp (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
if (NetLoopInit(DHCP) < 0)
|
if (NetLoopInit(DHCP) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if ((size = NetLoop(DHCP)) < 0)
|
NetOurIP = 0;
|
||||||
|
DhcpRequest(); /* Basically same as BOOTP */
|
||||||
|
|
||||||
|
if ((size = NetLoop()) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* NetLoop ok, update environment */
|
/* NetLoop ok, update environment */
|
||||||
|
@ -192,6 +196,9 @@ U_BOOT_CMD_END
|
||||||
|
|
||||||
int net_store_fd;
|
int net_store_fd;
|
||||||
|
|
||||||
|
extern void TftpStart(void); /* Begin TFTP get */
|
||||||
|
extern void NfsStart(void);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
|
netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -223,7 +230,17 @@ netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
if (NetLoopInit(proto) < 0)
|
if (NetLoopInit(proto) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if ((size = NetLoop(proto)) < 0) {
|
switch (proto) {
|
||||||
|
case TFTP:
|
||||||
|
TftpStart();
|
||||||
|
break;
|
||||||
|
case NFS:
|
||||||
|
NfsStart();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((size = NetLoop()) < 0) {
|
||||||
rcode = size;
|
rcode = size;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -265,7 +282,7 @@ static int do_cdp (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
if (NetLoopInit(CDP) < 0)
|
if (NetLoopInit(CDP) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
r = NetLoop(CDP);
|
r = NetLoop();
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
printf("cdp failed; perhaps not a CISCO switch?\n");
|
printf("cdp failed; perhaps not a CISCO switch?\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -318,7 +318,7 @@ extern int NetTimeOffset; /* offset time from UTC */
|
||||||
int NetLoopInit(proto_t);
|
int NetLoopInit(proto_t);
|
||||||
|
|
||||||
/* Do the work */
|
/* Do the work */
|
||||||
int NetLoop(proto_t);
|
int NetLoop(void);
|
||||||
|
|
||||||
/* Shutdown adapters and cleanup */
|
/* Shutdown adapters and cleanup */
|
||||||
void NetStop(void);
|
void NetStop(void);
|
||||||
|
|
|
@ -67,7 +67,6 @@ ulong seed1, seed2; /* seed for random BOOTP delay */
|
||||||
extern void BootpRequest (void);
|
extern void BootpRequest (void);
|
||||||
|
|
||||||
/****************** DHCP Support *********************/
|
/****************** DHCP Support *********************/
|
||||||
extern void DhcpRequest(void);
|
|
||||||
|
|
||||||
/* DHCP States */
|
/* DHCP States */
|
||||||
typedef enum { INIT,
|
typedef enum { INIT,
|
||||||
|
|
52
net/net.c
52
net/net.c
|
@ -299,7 +299,7 @@ int NetLoopInit(proto_t protocol)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NetLoop(proto_t protocol)
|
int NetLoop(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Start the ball rolling with the given start function. From
|
* Start the ball rolling with the given start function. From
|
||||||
|
@ -307,56 +307,6 @@ int NetLoop(proto_t protocol)
|
||||||
* packets and timer events.
|
* packets and timer events.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch (protocol) {
|
|
||||||
#ifdef CONFIG_NET_TFTP
|
|
||||||
case TFTP:
|
|
||||||
/* always use ARP to get server ethernet address */
|
|
||||||
TftpStart();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_DHCP
|
|
||||||
case DHCP:
|
|
||||||
/* Start with a clean slate... */
|
|
||||||
NetOurIP = 0;
|
|
||||||
DhcpRequest(); /* Basically same as BOOTP */
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_BOOTP
|
|
||||||
case BOOTP:
|
|
||||||
BootpRequest ();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_RARP
|
|
||||||
case RARP:
|
|
||||||
NetOurIP = 0;
|
|
||||||
RarpTry = 0;
|
|
||||||
RarpRequest ();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_PING
|
|
||||||
case PING:
|
|
||||||
PingStart();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_NFS
|
|
||||||
case NFS:
|
|
||||||
NfsStart();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NETCONSOLE
|
|
||||||
case NETCONS:
|
|
||||||
NcStart();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_SNTP
|
|
||||||
case SNTP:
|
|
||||||
SntpStart();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetBootFileXferSize = 0;
|
NetBootFileXferSize = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -100,7 +100,9 @@ int do_ping (cmd_tbl_t *cmdtp, int argc, char *argv[])
|
||||||
if (NetLoopInit(PING) < 0)
|
if (NetLoopInit(PING) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (NetLoop(PING) < 0) {
|
PingStart();
|
||||||
|
|
||||||
|
if (NetLoop() < 0) {
|
||||||
printf("ping failed; host %s is not alive\n", argv[1]);
|
printf("ping failed; host %s is not alive\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,9 @@ RarpRequest (void)
|
||||||
uchar *pkt;
|
uchar *pkt;
|
||||||
ARP_t * rarp;
|
ARP_t * rarp;
|
||||||
|
|
||||||
|
NetOurIP = 0;
|
||||||
|
RarpTry = 0;
|
||||||
|
|
||||||
printf("RARP broadcast %d\n", ++RarpTry);
|
printf("RARP broadcast %d\n", ++RarpTry);
|
||||||
pkt = NetTxPacket;
|
pkt = NetTxPacket;
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,9 @@ int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||||
if (NetLoopInit(SNTP) < 0)
|
if (NetLoopInit(SNTP) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (NetLoop(SNTP) < 0) {
|
SntpStart();
|
||||||
|
|
||||||
|
if (NetLoop() < 0) {
|
||||||
printf("SNTP failed: host %s not responding\n", argv[1]);
|
printf("SNTP failed: host %s not responding\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,6 @@
|
||||||
* Global functions and variables.
|
* Global functions and variables.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* tftp.c */
|
|
||||||
extern void TftpStart (void); /* Begin TFTP get */
|
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
||||||
#endif /* __TFTP_H__ */
|
#endif /* __TFTP_H__ */
|
||||||
|
|
Loading…
Reference in New Issue