From patchwork Wed Aug 2 14:06:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 709168 Delivered-To: patch@linaro.org Received: by 2002:a5d:55c5:0:b0:317:2194:b2bc with SMTP id i5csp930821wrw; Wed, 2 Aug 2023 07:10:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlHcPgCURLjV2PuiyWBiACIREfwDCD1SmtfD1n8pyUhFvYF8ovd/hJp7eIH3Hu24cjq1tm6y X-Received: by 2002:a05:6000:1011:b0:314:9dc:4c4 with SMTP id a17-20020a056000101100b0031409dc04c4mr5387652wrx.2.1690985407769; Wed, 02 Aug 2023 07:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690985407; cv=none; d=google.com; s=arc-20160816; b=wajlmHdh5ThekfUPByoq2ae9Ngtl1+ED1Dm2Irn+y7HiRavt+XfuucTHKf/h/Bx3v2 CfOqghkhdL0qLBdowehpkj4PVzsmwhXPUXw06/qa9bGZ2ApKOfh4QhDfjGP7vWL2mo2g GpLFn3SYHmJ99bXED5Bw6IwxTncLJszRaGBLzzdosoCOgF1gvFuk8YKJ+HvUWtkoJjVd PYqrSDQlwxte6npGbOWRgxQyrL6V3roAYIYp9t6HFSSAsNb+S5cWGK/73lD5yblv2J/5 Wb2I7HE56lS4iGt6pZgIv9HWxokXcyYUxH4Gov1Ef7e5H0AP+FtT1Q3ircpgKLAcaxnp e0Pg== 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=/5mLJAASP+i8nv1Dp+2u+nsxVpCk4btvYJw/79VkTOQ=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=OEoADr9oGjIAcpm34PIIMRXISCdYiCD92pkEDQmgsUAs5BqaaPoEuZtoTbn3jDHz2A 9aEZ6VjtUERH6MRD0zitpVVtWo0Tjo525Zs8o6UgVrIPICOnVng35aD58JIfrVu+TzQY XVZhqnt9KIi9Xs1HU3OpajBg4H0PnRxOrq8373Z7zezSmMEl5m/B3wHQxB99xFFr35gM HHDGuRgE97TmF3XydoII0aDdTr3KbImkb6tr3bwoC+J1fdA2Yd1ImLhMGtFhxtNAThdK tizcWrAqTySUVWuF/SQ6N/zbBOlJsMDhuUjOoa5Wg6Eid1ldKephVNJuFRF1/uN82rbY ZseQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wLzvm89X; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id z11-20020a5d654b000000b0031776c6a74esi5999369wrv.290.2023.08.02.07.10.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:10:07 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wLzvm89X; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 0834286934; Wed, 2 Aug 2023 16:09:36 +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="wLzvm89X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2CCF286ACB; Wed, 2 Aug 2023 16:09:34 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) (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 BD59786A8C for ; Wed, 2 Aug 2023 16:09:30 +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-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fe216edaf7so1264812e87.0 for ; Wed, 02 Aug 2023 07:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690985370; x=1691590170; 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=/5mLJAASP+i8nv1Dp+2u+nsxVpCk4btvYJw/79VkTOQ=; b=wLzvm89X7v28DpZj1kAkezXU4M16ka3ChOkli5i+l1LFsuzrWKbg/t3ip4PNfVEiiY HqZil1DdhwADa+JV+/ygnjM3s6ubTnHFTYxNAVto/gMAYt3cS8+G2hmcjHdhs9nFi7Dj GDIohuSDL/sOrmG9YL/c9TINcs3jnQwVnaZoXhlFwsi149EEuuk47sFEWQ1EMWL+z1WJ jQBHIw/+R2XuewY4kdUGneAPIwkrDJrTj+Lg1S3W1B1qcDkqa+xFURBL1WHjkXBGcQa7 5p/9u30kHxqtgg16Wi4sQm0DLKyxRNLCciInrMr6XT0SOqfLG9TG70c+7JmpAvYZSQZk TuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690985370; x=1691590170; 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=/5mLJAASP+i8nv1Dp+2u+nsxVpCk4btvYJw/79VkTOQ=; b=Nwwk7akuR/yumAjq3TjcIzSXGjHlZNXPeP7LlpV4leVbKTqwdnJk1IVpfhit2fH/yn iCNX59OfOjtfEBAc53vSEddgs4sOpUaU0oLw07geuNjZLKqgU4LBeUL9e/kcQbYK/VUY 6ndlBVXRy1NrLF1Rf45tmI9OEuSXgg6YbLfIM4FwE9mfRZ5iGo8xDVaJ2hpFFnPRhJj5 EtcjQGuEiRmBr57j5kFE00aRL6/3H7lh+ApdJuQZWgnIuP57p6MZtbs5fx56KbP4GIQu J3cLuQO9mHKYXDxy4i4jRKexXsYsHqrYCNquulo1NanxUA9cKIc3kfSbGYQR0O6HWIUp rn1Q== X-Gm-Message-State: ABy/qLbwpT5ynCdnL2YRfr52otEgu9mkQWMLh55sXOdD5q9Eb414+Oxz WVhfskIBIg16pUMR8hkFgX+58bXaKXNJoV1KjeZH8Q== X-Received: by 2002:a05:6512:2528:b0:4fd:c8fb:eb71 with SMTP id be40-20020a056512252800b004fdc8fbeb71mr2057114lfb.11.1690985369921; Wed, 02 Aug 2023 07:09:29 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id a12-20020a056512020c00b004fbbef8d4dbsm2982026lfo.121.2023.08.02.07.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:09:28 -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: [PATCHv5 04/13] net/lwip: implement dhcp cmd Date: Wed, 2 Aug 2023 20:06:49 +0600 Message-Id: <20230802140658.10319-5-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230802140658.10319-1-maxim.uvarov@linaro.org> References: <20230802140658.10319-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 Signed-off-by: Maxim Uvarov --- lib/lwip/Makefile | 1 + lib/lwip/apps/dhcp/lwip-dhcp.c | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 lib/lwip/apps/dhcp/lwip-dhcp.c diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile index 2815662093..a3521a9d18 100644 --- a/lib/lwip/Makefile +++ b/lib/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/lib/lwip/apps/dhcp/lwip-dhcp.c b/lib/lwip/apps/dhcp/lwip-dhcp.c new file mode 100644 index 0000000000..9fda43db9f --- /dev/null +++ b/lib/lwip/apps/dhcp/lwip-dhcp.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include + +#include +#include + +#include "../../../lwip/ulwip.h" + +static struct dhcp dhcp; +static bool dhcp_is_set; + +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 (!dhcp_is_set) { + dhcp_set_struct(netif, &dhcp); + dhcp_is_set = true; + } + err = dhcp_start(netif); + if (err) + printf("dhcp_start error %d\n", err); + + return err; +}