From patchwork Fri Sep 8 13:53:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720817 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp778891wrp; Fri, 8 Sep 2023 06:56:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjpDlAiWf50Z8Mo+qCLKqgcmtMgeDJQSvtkMEd2HmdT8SlYuFmQCYSuQsN8H675goH9coA X-Received: by 2002:a1c:7716:0:b0:3fb:b248:67c with SMTP id t22-20020a1c7716000000b003fbb248067cmr2330315wmi.22.1694181376203; Fri, 08 Sep 2023 06:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181376; cv=none; d=google.com; s=arc-20160816; b=D+4lJ/41Hiz8sx9Cczy5hHJPchcqC/X8wfUqgqtQtCg7mzBWlEcli7eL7fm5D5XiIO wHzESMTxQ+/MARcs1iGvyvkDiRhjckNq0TCHK0jjjnyjuV/9a+3ncZitSf/LrVp8fazv 5DsdYeC7xpSQm01TX3Q6MWWGXGwn18V6MXAj4BMVURq+mZlHi0+YfswLD25FMlfJ/a3C 3Y9DqzMgfkltEMLa4VdJuRBirF42SzXSu0mMUuW0I/F5hBa2Ka0yuBScAT3sG9qUKLUi JDaqQPT1jbn4+CNg/uKM7naowWDUpFB6q4E9e6uk1C9cvAQUxn2TxFzQx5VF1K7DKhee sc7Q== 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=fdgneGqqiBGx6Qr+uBbt0uaj/QAsGJ1j6vG1ulncYAM=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=M7LhBmWFkLyXIwnWmvzCcdeE+hAbIYMyBHD/+v8UaQ8OA99OScFo28FhmkBmac4raI UojpvhtpZtzCUMaXdzV69j3S2vSmCzPTMGnJOZ4WDC4/PaqmbqduR1Gxl3TipRIlfuZY o5MXzjtGcWxlbbhO1VxRLMcksIWVoiYX4JZpU0+uJ0tERsh642UYBc5kAmL3pREbFx8V 3sNfX58VNabm6U5KjRzCKU4H84VMmUkItFfcFIUxReuf8NySBrkwjIgbGcdYBSrUyssV X9R/QZuJ21o1W0ollGAFCZC9U7jw1Vp3JmC4xct002UQp6acE52BQ1owQYVfwz+cJdYi Mozw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jF+3ZcZ1; 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 k17-20020a7bc411000000b003fefa7678b2si2280356wmi.81.2023.09.08.06.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:16 -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=jF+3ZcZ1; 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 2B4E086A34; Fri, 8 Sep 2023 15:55:45 +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="jF+3ZcZ1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C502986A63; Fri, 8 Sep 2023 15:55:43 +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-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) (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 0DA6386A49 for ; Fri, 8 Sep 2023 15:55:40 +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-x236.google.com with SMTP id 38308e7fff4ca-2ba1e9b1fa9so36857891fa.3 for ; Fri, 08 Sep 2023 06:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181339; x=1694786139; darn=lists.denx.de; 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=fdgneGqqiBGx6Qr+uBbt0uaj/QAsGJ1j6vG1ulncYAM=; b=jF+3ZcZ1nNd98zXC5XSY5CTqqf5rEqLfFYUnXW5I5oaSyzcK5Y7xjg5E2pILclONMj SCVyUVqXr9VJ2fHnX6pRqD12TO3yuh9iNTixI671Q72qjAGe3KPhj2RyQCl7BfZzAECQ CcizQh1Xv080dUuxontRVT+EEH5kXDkH6406dcPhhZRFNq3FJFY+OmHhiP9Hzf+KeNxQ 1UpcrMjZiaSZgospTI3niPhgbRn6GRanhiGgERhlg+DKUkkzjbA/7x5tFv8B33YzliZZ LV9m5aTThcvfUaMHc9zugmpn475ggIorwGxZFULylVw6Np0DEyiG4rxj80dU5uIjDwh+ wwfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181339; x=1694786139; 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=fdgneGqqiBGx6Qr+uBbt0uaj/QAsGJ1j6vG1ulncYAM=; b=wnfZTyaHGfvxXk9NboIAsiVXvSQAyuirtzOG/47GJmao7UMfvDZipl8GD980e2gBfn q/mk8MbSoeA1RkJG56ViwYcKe0SJ3newC9K+bEimiIfWyO5WLVnDzNa+kq8MyYRoCOLD b6aJSQ4szYQS4x/zLZdLtuXacrTUfKtlyHVA2Zzncwr+RbtKeWDsdrL6t53vDhSvuS/4 Mng4/9nwMry5QaMnrxUcjWapaMahipuFRH1nE9lbpwMbXKOKY9RH3GKYHAr6Pyfzc664 Js1TUiOxV1IqmTEhaSpAQ41Rka/9ENbC3dn9UfC/HiPJIKCOW7oxJ1PN1AzsKpQVbIfD J9MA== X-Gm-Message-State: AOJu0Yx7VGvDdcOIRGP67mm7MLlJWm87qU9O0RQjr+Tb/xLwLonm4wJZ cKZT2FkrEdCtedbSd3r6nguRqiPpdZQkdrfkd0r/+A== X-Received: by 2002:a2e:9206:0:b0:2be:3ca8:bdc9 with SMTP id k6-20020a2e9206000000b002be3ca8bdc9mr1810804ljg.49.1694181339127; Fri, 08 Sep 2023 06:55:39 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:38 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 04/15] net/lwip: implement dhcp cmd Date: Fri, 8 Sep 2023 19:53:09 +0600 Message-Id: <20230908135320.7066-5-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 U-Boot recently got support for an alternative network stack using LWIP. Replace dhcp command with the LWIP variant while keeping the output and error messages identical. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 12 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.c diff --git a/include/net/lwip.h b/include/net/lwip.h index ab3db1a214..6a8fcef392 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -17,3 +17,15 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, * Other value < 0, if error */ int ulwip_dns(char *name, char *varname); + +/** + * ulwip_dhcp() - create the DHCP request to obtain IP address. + * + * 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. + * + * Returns: 0 if success + * Other value < 0, if error +*/ +int ulwip_dhcp(void); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 5d8d5527c6..a3a33b7f71 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -63,4 +63,5 @@ obj-$(CONFIG_NET) += lwip-external/src/netif/ethernet.o obj-$(CONFIG_NET) += port/if.o obj-$(CONFIG_NET) += port/sys-arch.o +obj-y += apps/dhcp/lwip-dhcp.o obj-y += 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..68334a02bb --- /dev/null +++ b/net/lwip/apps/dhcp/lwip-dhcp.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include + +#include +#include +#include "lwip/timeouts.h" + +#include +#include + +#define DHCP_WAIT_MS 2000 + +static void dhcp_tmo(void *arg) +{ + struct netif *netif = (struct netif *)arg; + struct dhcp *dhcp; + int err = 0; + + dhcp = netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); + if (!dhcp) + return; + + switch (dhcp->state) { + case DHCP_STATE_BOUND: + err += env_set("bootfile", dhcp->boot_file_name); + err += env_set("ipaddr", ip4addr_ntoa(&dhcp->offered_ip_addr)); + err += env_set("netmask", ip4addr_ntoa(&dhcp->offered_sn_mask)); + err += env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr)); + if (err) + log_err("error update envs\n"); + log_info("DHCP client bound to address %s\n", ip4addr_ntoa(&dhcp->offered_ip_addr)); + break; + default: + return; + } +} + +int ulwip_dhcp(void) +{ + struct netif *netif; + int eth_idx; + + eth_idx = eth_get_dev_index(); + if (eth_idx < 0) + return -EPERM; + + netif = netif_get_by_index(eth_idx + 1); + if (!netif) + return -ENOENT; + + sys_timeout(DHCP_WAIT_MS, dhcp_tmo, netif); + + return dhcp_start(netif) ? 0 : -EPERM; +}