From patchwork Mon Aug 14 13:32:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 713476 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp1242415wrp; Mon, 14 Aug 2023 06:36:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcqmrPPpT7HTWCYjtuX2Y1Ungk5wWsaq2eIUkCggQYC5XC6ytxNIpkof5D2jdWduIqV0e1 X-Received: by 2002:a1c:6a14:0:b0:3f5:fff8:d4f3 with SMTP id f20-20020a1c6a14000000b003f5fff8d4f3mr8400499wmc.7.1692020184395; Mon, 14 Aug 2023 06:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692020184; cv=none; d=google.com; s=arc-20160816; b=WSi9WP5F0m2OuE6g7JzoZm/Lq00ibn6zT7h35DwPHEs0/muox5e50ciiCGteBdwZYc BDXmXqYswSK9A+yzzENPOSrXufEKSQWyMHUD77ryLu1aoQjMas7rTdkGU/zmKjz++ayU 5oTZdA2j7qiP8LggjsRdHAObRr/Le7LVJHEvbh6CkJyiKt7CsD3Ubsd++sgT7FzeQwmq JEG50We9UKUdkujwh1As3wZLh2yN7FwaD7XBaatdtALEDwPbUlhQslcFzYS8AoAy1EMN PB9biYHHRie+ZQ7N1WYz/N9Y3WpSuyJR1iQHbPqEXVAAFO5rtKNB/SkpyBihD7HSzkVm iWWg== 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=FCdrkSEZz2ulQnFDbsrAAqsQyeCAsLOWYHNH6n7RMAU=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=bnoZYA5uIB5u0U7DJxwrQ0lzmxRHVFFUiGSMtMAwJmeJsdsmPV9EN5Ezh3gsySVI3h d78ssFQoBeVx8prYwW97ZbsDi+HnTj/5tsMEN41eB2B1kg7fCYHtBfDmGBet8KY4pZgN Cfl7yXDD9J737AI8do5bFLlp2kk4LjEfRhYmBiq3iiCMWw+iqlS9y3ARzD4eZDEdcKzc g30lemTN7bNS7KMXwAz8a4yc5LOsOF9MS+uGtHAXbltXmLEkM9yQbldUS67Zswb68X4A 3+knMS4ezw8BiLLFMK3TN6rQ9u4psSbj8bGZ4vnGvvMWadcBA2ubneous6XAVWldtpge wXSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dwHN/drd"; 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 a18-20020a05600c349200b003fe24da4947si5842022wmq.17.2023.08.14.06.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:36:24 -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="dwHN/drd"; 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 81E3D86989; Mon, 14 Aug 2023 15:35:33 +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="dwHN/drd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A42CD807B4; Mon, 14 Aug 2023 15:35:31 +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 A3B9E8696D for ; Mon, 14 Aug 2023 15:35:29 +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-2b9c907bc68so63249901fa.2 for ; Mon, 14 Aug 2023 06:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692020129; x=1692624929; 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=FCdrkSEZz2ulQnFDbsrAAqsQyeCAsLOWYHNH6n7RMAU=; b=dwHN/drd/8kB3EtMpqTyLKFOxJ1voc3NxG976ADAQT8enSnYxAaiK8VKrp+AP8XIz8 6X9uN4k48z6Q0XmQkZbcE0zu+iUkuIhwHYZRxUZk4aLQZ1yxJ96/oIjCN2jQwCPMRtj9 /Z+SN84YwPpmadMPrMpPSP8bDumtzhLHxGNnjskT2/cBUJ+Q0xoaAjhVn+NTPe9nbh7j zH4p4eSNaqaVsSOXPGXahul64OGTWEUKvv+bQZKR53qTlufV5yEEU83j6dMymEL+OUYd mZseDH5p09ze6uOUxPHf3/I65dKjpqjwwhaJF8lcWUG4Vx143j/N7Nd/H3DFWVMjd0zl 8JrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692020129; x=1692624929; 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=FCdrkSEZz2ulQnFDbsrAAqsQyeCAsLOWYHNH6n7RMAU=; b=YUH2erLtnpO2G9YNOcBqQ5H2NAW0Pa3G6nFaCgoQKXXiZCVzQ01WkPVBMBGUaG35oM dpsTQUOPJzskkTWFzoe0YWoPDE03HQKAg8LVXKCG23Inmgi3/zu/5JU8arI3uJVUDiuF bRbzvTLvMcGLIBxZ/zEo84vMPklpAmcsw8YCcgAoPGomtPof0JNBoimDZvpS8umY2ssu FJjHwZJySoEJJxG1ukyMDgKZX/dgHAk3zVBKhZict3cmuqDjPrlPc3A2BziGmqRSZ1Fv lOcwheAVuLZWPuu3ywU5KoYRdJHHtYfoHOzMgFeYthrSmo6kBzpGa8EDqBLWerUtb2BD nM6w== X-Gm-Message-State: AOJu0YzNteAGk1WW1Ua47POMtbMDMNs0nYy8xd55GfapEpN/16WKG3OB QoNjFLRHzpYG38R0TESbht59YJISBRB6uCXoYPA= X-Received: by 2002:a2e:9f41:0:b0:2b9:4413:864e with SMTP id v1-20020a2e9f41000000b002b94413864emr6380340ljk.53.1692020128773; Mon, 14 Aug 2023 06:35:28 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:35: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: [PATCHv6 07/14] net/lwip: implement ping cmd Date: Mon, 14 Aug 2023 19:32:46 +0600 Message-Id: <20230814133253.4150-8-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 ping 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. ping uses lwIP contrib/apps/ping/ping.c code. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 28 ++++++++++++++++++++++++- net/lwip/Makefile | 1 + net/lwip/apps/ping/Makefile | 11 ++++++++++ net/lwip/apps/ping/lwip_ping.c | 37 ++++++++++++++++++++++++++++++++++ net/lwip/apps/ping/lwip_ping.h | 15 ++++++++++++++ net/lwip/apps/ping/ping.h | 19 +++++++++++++++++ 6 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 net/lwip/apps/ping/Makefile create mode 100644 net/lwip/apps/ping/lwip_ping.c create mode 100644 net/lwip/apps/ping/lwip_ping.h create mode 100644 net/lwip/apps/ping/ping.h diff --git a/include/net/lwip.h b/include/net/lwip.h index f1f2c94fc2..e928676b36 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -2,7 +2,8 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); - +int do_lwip_ping(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); /* * This function creates the DNS request to resolve a domain host name. Function * can return immediately if previous request was cached or it might require @@ -38,3 +39,28 @@ int ulwip_dhcp(void); * !0 if error */ int ulwip_wget(ulong addr, char *url); + +/** + * ulwip_tftp() - load file with tftp + * + * Load file with tftp to specific address + * + * @param addr - address to store downloaded file + * @param filename - file name on remote tftp server to download + * + * + * @return 0 if success, !0 if error + */ +int ulwip_tftp(ulong addr, const char *filename); + +/* +* This function creates the ping for address provided in parameters. +* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping(char *ping_addr); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 4c6df94807..8b3e843426 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -67,5 +67,6 @@ 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 +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/ diff --git a/net/lwip/apps/ping/Makefile b/net/lwip/apps/ping/Makefile new file mode 100644 index 0000000000..dc63feb7b5 --- /dev/null +++ b/net/lwip/apps/ping/Makefile @@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip +ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c $(obj)/ping.c + +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o diff --git a/net/lwip/apps/ping/lwip_ping.c b/net/lwip/apps/ping/lwip_ping.c new file mode 100644 index 0000000000..611fcaf591 --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo(void) +{ + + log_err("ping failed; host %s is not alive\n", ipaddr_ntoa(&ip_target)); + return 1; +} + +int ulwip_ping(char *ping_addr) +{ + int err; + + err = ipaddr_aton(ping_addr, &ip_target); + if (!err) { + log_err("wrong ping addr string \"%s\" \n", ping_addr); + return -1; + } + + ulwip_set_tmo(ulwip_ping_tmo); + + ping_init(&ip_target); + ping_send_now(); + + return 0; +} diff --git a/net/lwip/apps/ping/lwip_ping.h b/net/lwip/apps/ping/lwip_ping.h new file mode 100644 index 0000000000..0374f07d9e --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include + +void ping_raw_init(void); +void ping_send_now(void); + +#endif /* LWIP_PING_H */ diff --git a/net/lwip/apps/ping/ping.h b/net/lwip/apps/ping/ping.h new file mode 100644 index 0000000000..006a18c658 --- /dev/null +++ b/net/lwip/apps/ping/ping.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1 /* ping_time is under ifdef*/ +#define PING_RESULT(cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \ + ulwip_exit(-1); \ + } \ + } while (0); + +void ping_init(const ip_addr_t *ping_addr);