implement ping using new network stack
[barebox-mini2440.git] / commands / net.c
blob949963ffdcb1d212f7eaf8d1cbc3a48fb78db226
1 /*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
24 /**
25 * @file
26 * @brief tftp, rarpboot, dhcp, nfs, cdp - Boot support
29 #include <common.h>
30 #include <command.h>
31 #include <environment.h>
32 #include <driver.h>
33 #include <net.h>
34 #include <fs.h>
35 #include <errno.h>
36 #include <libbb.h>
38 void netboot_update_env(void)
40 struct eth_device *eth_current = eth_get_current();
41 char tmp[22];
42 IPaddr_t net_gateway_ip = NetOurGatewayIP;
43 IPaddr_t net_ip = NetOurIP;
44 IPaddr_t net_server_ip = NetServerIP;
45 IPaddr_t netmask = NetOurSubnetMask;
47 if (net_gateway_ip)
48 dev_set_param_ip(&eth_current->dev, "gateway", net_gateway_ip);
50 if (netmask)
51 dev_set_param_ip(&eth_current->dev, "netmask", netmask);
54 if (NetOurHostName[0])
55 setenv ("hostname", NetOurHostName);
57 if (NetOurRootPath[0])
58 setenv ("rootpath", NetOurRootPath);
60 if (net_ip)
61 dev_set_param_ip(&eth_current->dev, "ipaddr", net_ip);
63 if (net_server_ip)
64 dev_set_param_ip(&eth_current->dev, "serverip", net_server_ip);
66 if (NetOurDNSIP) {
67 ip_to_string (NetOurDNSIP, tmp);
68 setenv ("dnsip", tmp);
70 #ifdef CONFIG_BOOTP_DNS2
71 if (NetOurDNS2IP) {
72 ip_to_string (NetOurDNS2IP, tmp);
73 setenv ("dnsip2", tmp);
75 #endif
76 if (NetOurNISDomain[0])
77 setenv ("domain", NetOurNISDomain);
80 #ifdef CONFIG_NET_RARP
81 extern void RarpRequest(void);
83 static int do_rarpb(struct command *cmdtp, int argc, char *argv[])
85 int size;
87 if (NetLoopInit(RARP) < 0)
88 return 1;
90 NetOurIP = 0;
91 RarpRequest(); /* Basically same as BOOTP */
93 if ((size = NetLoop()) < 0)
94 return 1;
96 /* NetLoop ok, update environment */
97 netboot_update_env();
99 return 0;
102 BAREBOX_CMD_START(rarpboot)
103 .cmd = do_rarpb,
104 .usage = "boot image via network using rarp/tftp protocol",
105 BAREBOX_CMD_HELP("[loadAddress] [bootfilename]\n")
106 BAREBOX_CMD_END
107 #endif /* CONFIG_NET_RARP */
109 static int do_ethact(struct command *cmdtp, int argc, char *argv[])
111 struct eth_device *edev;
113 if (argc == 1) {
114 edev = eth_get_current();
115 if (edev)
116 printf("%s%d\n", edev->dev.name, edev->dev.id);
117 return 0;
120 if (argc != 2)
121 return COMMAND_ERROR_USAGE;
123 edev = eth_get_byname(argv[1]);
124 if (edev)
125 eth_set_current(edev);
126 else {
127 printf("no such net device: %s\n", argv[1]);
128 return 1;
131 return 0;
134 static const __maybe_unused char cmd_ethact_help[] =
135 "Usage: ethact [ethx]\n";
137 BAREBOX_CMD_START(ethact)
138 .cmd = do_ethact,
139 .usage = "set current ethernet device",
140 BAREBOX_CMD_HELP(cmd_ethact_help)
141 BAREBOX_CMD_END