diff options
author | Wadim Egorov <w.egorov@phytec.de> | 2015-06-03 11:19:02 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-06-05 13:32:39 +0200 |
commit | e9bd26c7a7167b5e36696373ef8381a2caaff4a6 (patch) | |
tree | 421b58ffa1705d7e392c2706f9fab8b6bca3c597 /commands/dhcp.c | |
parent | f6c5578eaf42eab8c6723ee9a25aa38dab651ff9 (diff) | |
download | barebox-e9bd26c7a7167b5e36696373ef8381a2caaff4a6.tar.gz barebox-e9bd26c7a7167b5e36696373ef8381a2caaff4a6.tar.xz |
net: dhcp: Split dhcp funcionality & add dhcp command
dhcp/bootp was bound to the command functionality.
This patch splits the dhcp command.
We are now able to use bootp without a shell.
This patch adds also a check for environment variables and globalvar.
So only when ENVIRONMENT_VARIABLES and GLOBALVAR is set, all received
dhcp data will be stored.
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/dhcp.c')
-rw-r--r-- | commands/dhcp.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/commands/dhcp.c b/commands/dhcp.c new file mode 100644 index 0000000000..eb98bfc2a7 --- /dev/null +++ b/commands/dhcp.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2015 PHYTEC Messtechnik GmbH, + * Author: Wadim Egorov <w.egorov@phytec.de> + * + * Based on work of Sascha Hauer <s.hauer@pengutronix.de>. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <common.h> +#include <command.h> +#include <complete.h> +#include <environment.h> +#include <getopt.h> +#include <dhcp.h> + +static int do_dhcp(int argc, char *argv[]) +{ + int ret, opt; + int retries = DHCP_DEFAULT_RETRY; + struct dhcp_req_param dhcp_param; + + memset(&dhcp_param, 0, sizeof(struct dhcp_req_param)); + getenv_uint("global.dhcp.retries", &retries); + + while ((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) { + switch (opt) { + case 'H': + dhcp_param.hostname = optarg; + break; + case 'v': + dhcp_param.vendor_id = optarg; + break; + case 'c': + dhcp_param.client_id = optarg; + break; + case 'u': + dhcp_param.client_uuid = optarg; + break; + case 'U': + dhcp_param.user_class = optarg; + break; + case 'r': + retries = simple_strtoul(optarg, NULL, 10); + break; + } + } + + if (!retries) { + printf("retries is set to zero, set it to %d\n", DHCP_DEFAULT_RETRY); + retries = DHCP_DEFAULT_RETRY; + } + + ret = dhcp(retries, &dhcp_param); + + return ret; +} + +BAREBOX_CMD_HELP_START(dhcp) +BAREBOX_CMD_HELP_TEXT("Options:") +BAREBOX_CMD_HELP_OPT("-H HOSTNAME", "hostname to send to the DHCP server") +BAREBOX_CMD_HELP_OPT("-v ID\t", "DHCP Vendor ID (code 60) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-c ID\t", "DHCP Client ID (code 61) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-u UUID\t", "DHCP Client UUID (code 97) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-U CLASS", "DHCP User class (code 77) submitted in DHCP requests") +BAREBOX_CMD_HELP_OPT("-r RETRY", "retry limit (default 20)"); +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(dhcp) + .cmd = do_dhcp, + BAREBOX_CMD_DESC("DHCP client to obtain IP or boot params") + BAREBOX_CMD_OPTS("[-HvcuUr]") + BAREBOX_CMD_GROUP(CMD_GRP_NET) + BAREBOX_CMD_HELP(cmd_dhcp_help) + BAREBOX_CMD_COMPLETE(empty_complete) +BAREBOX_CMD_END |