From patchwork Mon Aug 14 13:32:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 713473 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp1242143wrp; Mon, 14 Aug 2023 06:35:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKE8A9wwDbnUCi696jKHAM855LXOI1X7jxiDtz18OnNOpbn9EOMw/qVs5l44kC2RmD+80y X-Received: by 2002:a7b:cd02:0:b0:3fa:98c3:7dbd with SMTP id f2-20020a7bcd02000000b003fa98c37dbdmr7929176wmj.41.1692020156112; Mon, 14 Aug 2023 06:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692020156; cv=none; d=google.com; s=arc-20160816; b=LgYqI4aSPOW7eeLwwZgFmFM9GMPiRpA9eXjS5dXl8RLxFzS8lB83HFmbspScqVhV+d DdE+4gqZM2ptRqd9RodkY4zXfO1c07V1Ci8OB0ZOZZxQM30kC+ZzbGeJEic1j4KTvpWu hw/A7u7Q2wLK+jkRXROV8MH4iVOuRCYWGbwo/4Z3asr13YEiVXUsl/HqOmcad+iOLpOI rvJCcE9qxwSB74rKilMrA7HNRsiXzk3tUw4rUfqrNEcdNbDWF7Be8TjUn22fhhXh9BP5 Oe/tE8LNfn6NrN0xclIcG5UJSEAWeWv8RXWeyxlaPnhOE95SUSmDDNIRNTrAoyaI3wfJ qAqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L7zsyex9fOzbWeSrWQFiL7vIBUfwnNHuf3/vMzio0Y8=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=XtwWHCVr3HoyQIcLmmeF/7ulb9TAYk5/EJ8xiqsBJ6tGdJlg3N6McndOznwp0hutPk 1KuMjT/Fgk0XZcjOIkmle9LneizJyVMKLHVoMf5L69tgnYXEtBmGMiost7DlvxlXE8g7 snKFklVzjnvFkQqqTDpGI9nRcgRu4p7XN+9YO4OoKbZgzUtcfsju/YnLhsuU2ECcwFOQ mJs7koBcP+/fQd3FW5BE+Dh3OCsXjDO4aAho64zKc+MEVGl2gD6DC5M//Q80dyvwGg0a RRjvdsRHbq1dUX2ZWYT+PNgyYbRS7WEsftlohybdUxT4fWHOoWCLf997mPUL84QlLnRA dzAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YiEMq8Wn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id s12-20020a05600c384c00b003fe5c40ed47si5824711wmr.1.2023.08.14.06.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:35:56 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YiEMq8Wn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A727C86979; Mon, 14 Aug 2023 15:35:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YiEMq8Wn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A17FC86979; Mon, 14 Aug 2023 15:35:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B2209807B3 for ; Mon, 14 Aug 2023 15:35:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b9d07a8d84so67981091fa.3 for ; Mon, 14 Aug 2023 06:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692020121; x=1692624921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L7zsyex9fOzbWeSrWQFiL7vIBUfwnNHuf3/vMzio0Y8=; b=YiEMq8WnOCxmb92NpiNUfKccN4rNOUmYfQW+tf7I6UqO9/nKFtq6OdfLGaNHFJ6TJc oBvhQ5hW6TSJz4SmEzGSyeRSqRiMOPHJIJDy2QjO9LlEkAPKay+asSFYMANBhslNoh88 Im9gXfnDMzkUfuQL4sIEDcBRO1t55KT8b+gPayzNgOolXOvKSFAO2HB4nYEHTlfjqKFl 9hXwEOOwh+x+KSKQGjoM4QR48ScWSDw9wi8Y8FXN3Dk1EBgqDZwBUgVZ6pXoyknEVZvB dK/vwyfBqilYn3ZzgqVBt4OlPd9J6QeTNT7kKRehmqXQvTiI0Jt2HmY6Ar3eXh/2BBCF AY/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692020121; x=1692624921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L7zsyex9fOzbWeSrWQFiL7vIBUfwnNHuf3/vMzio0Y8=; b=Lp5oAmPmnFMN6/HPv+t8f6wtkUtvWY4MMwVSg3w96rsvU3V75dzVQNT8POFOrcnoYB YE1MxZaLSthzfpL9D14lTV4rh+9HO3U8k1LXAYaw7/zK6C3rIcpti2fqnQwOJEqOnprh gN5jYZTlBJ83c/CbO8skAUZtzQsjNmNvJHSwyJg3svy1RHAFBheqOc+TBckiJ9z4xQ+h sgjt8PpxXK+NOvq+MxwjrLH9j90BV+g6d+fhfkx8k3omlSOi6Khia6xEEw8jTKRoZEzW W/KkumqHj9r6NmOdhXhMEo+F/bSzcDzYWKEIpU7cMLJ40h8uzR2XpgEuFswfpVcPNLh9 Jo4Q== X-Gm-Message-State: AOJu0YyHM6acS2L6DXhwFgXnyeJgI74LD1iWJu5FStnyqU+c0+wjb191 utpmqs+E4DpWN3aghx8AmXNq/60dRcfpj66Ii1Q= X-Received: by 2002:a2e:320c:0:b0:2b9:b9c8:99 with SMTP id y12-20020a2e320c000000b002b9b9c80099mr7364513ljy.22.1692020120872; Mon, 14 Aug 2023 06:35:20 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z24-20020a2e9658000000b002b9415597d0sm2411102ljh.78.2023.08.14.06.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:35:20 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org, Maxim Uvarov Subject: [PATCHv6 04/14] net/lwip: implement dhcp cmd Date: Mon, 14 Aug 2023 19:32:43 +0600 Message-Id: <20230814133253.4150-5-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230814133253.4150-1-maxim.uvarov@linaro.org> References: <20230814133253.4150-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement function for dhcp command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.c diff --git a/include/net/lwip.h b/include/net/lwip.h index c83b5c8231..2f035280eb 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, * Other value < 0, if error */ int ulwip_dns(char *name, char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If DHCP server +* returns file name, this file will be downloaded with tftp. After this +* function you need to invoke the polling loop to process network communication. +* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp(void); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 6d2c00605b..59323fb325 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -65,4 +65,5 @@ obj-$(CONFIG_NET) += $(LWIPDIR)/netif/ethernet.o obj-$(CONFIG_NET) += port/if.o obj-$(CONFIG_NET) += port/sys-arch.o +obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o diff --git a/net/lwip/apps/dhcp/lwip-dhcp.c b/net/lwip/apps/dhcp/lwip-dhcp.c new file mode 100644 index 0000000000..fb7431b248 --- /dev/null +++ b/net/lwip/apps/dhcp/lwip-dhcp.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include + +#include +#include + +#include + +static struct dhcp dhcp; + +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr", ip4addr_ntoa(&dhcp.offered_ip_addr)); + env_set("netmask", ip4addr_ntoa(&dhcp.offered_sn_mask)); + env_set("serverip", ip4addr_ntoa(&dhcp.server_ip_addr)); + printf("DHCP client bound to address %s\n", ip4addr_ntoa(&dhcp.offered_ip_addr)); + break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void) +{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1); + + if (!netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP)) + dhcp_set_struct(netif, &dhcp); + + err = dhcp_start(netif); + if (err) + printf("dhcp_start error %d\n", err); + + return err; +}