From patchwork Mon Apr 23 17:47:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lothar Felten X-Patchwork-Id: 903085 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="H+fYXfjB"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40VDT36xW9z9rxs for ; Tue, 24 Apr 2018 03:48:07 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9C406C21E12; Mon, 23 Apr 2018 17:48:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B6E45C21C57; Mon, 23 Apr 2018 17:47:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E0C7BC21C57; Mon, 23 Apr 2018 17:47:57 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by lists.denx.de (Postfix) with ESMTPS id 77E43C21C2C for ; Mon, 23 Apr 2018 17:47:57 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id q3-v6so33602370wrj.6 for ; Mon, 23 Apr 2018 10:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RO6hSMC+clv3vap5FcJ8MFOC03Bd5o+5qCK8100z1jY=; b=H+fYXfjBPhB5bFMZ01IMSDtcRlAX6WbUa56MI+VZiAHZ8qY3hmsb6qOYjN97ERyn8w qB8eJx8uncBfAlDKFUPFIMP2xgAtndooO/Uaiy2k0M10UMsZmstiNVr+8WiMMhNXyRvH U3Zc5Pz5ugZ46d5jISvKMqEAOkN/XM6V57g2tJ+KkNzB5T7zXa14MmFPcDg9FbG41Bkq oncbsfQJm1IWnYsmS0IOROhW6hQqL8OBEP0WPdZWMQVyasuigiwM8ewwUIgGw9yFxMOS aTFGYAA9W4Ubf4HRNwenKAwajr/65IQxHMxolg8aQIcPB+WCaXSp5Vj2pV08z2o1yEx8 pbPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RO6hSMC+clv3vap5FcJ8MFOC03Bd5o+5qCK8100z1jY=; b=aMP8kVre5Ol6tFsz8CdF31Ya8HE8dK880RURpTbOcCZQh1scLh/QLEvJVRpvFzEVdK sHx+MACnibeFzqbg8m9QQIuda4tj8Zud5kWq57KoZUwqJjKwCSvtsVzy41YHdCqA8vaz 5oE6kwHZm78IIkDwRHIIrbJTWbYRkEipGeg2LJhzZupm/Uu480WcpNHd+RlfV/y23Z87 U7wmQP7AhS33q85iGOVxGlhRIcFAVKM6ouYhvQo2oGWOJwTrm80Mdu3nEE7mu4YT8Se3 OMDmrmoj/QBIGxMjWJ49H83CcTe8a+itTCFxWTrKeagIyMa7nEoBP1U3M775HHWS7+aZ bbmQ== X-Gm-Message-State: ALQs6tC1p3GmVHSKAMrZjhVhIXp91sb7BFikIHcbrNvXV4npeCSkC5kO T0zFxdG+1+nueryu99gRlnpoFfPS X-Google-Smtp-Source: AIpwx48o8+ITHlyqyN4z4aDisM2SXP1WoGuMddWWjbZUSsT9RXdYOZ4jExEZcjomq1Fo2h+yPjJvRA== X-Received: by 10.80.246.149 with SMTP id d21mr22652509edn.142.1524505676900; Mon, 23 Apr 2018 10:47:56 -0700 (PDT) Received: from z620.fritz.box (94-139-42-112.dsl.billi.be. [94.139.42.112]) by smtp.googlemail.com with ESMTPSA id f11sm7488773edf.68.2018.04.23.10.47.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 10:47:55 -0700 (PDT) From: Lothar Felten To: u-boot@lists.denx.de Date: Mon, 23 Apr 2018 19:47:45 +0200 Message-Id: <20180423174746.4888-1-lothar.felten@gmail.com> X-Mailer: git-send-email 2.14.1 Cc: maxime.ripard@bootlin.com, yauheni.kaliuta@redhat.com, joe.hershberger@ni.com, jkridner@beagleboard.org, judge.packham@gmail.com Subject: [U-Boot] [PATCH 1/2] [RFC]new command: wol - Wake on LAN X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch adds a new command 'wol': It waits for an incoming Wake-on-LAN packet or times out if no WoL packed is received. If the WoL packet contains a password, it is saved in the environment variable 'wolpassword' using the etherwake format (dot separated decimals). Intended use case: a networked device should boot an alternate image. It's attached to a network on a client site, modifying the DHCP server configuration or setup of a tftp server is not allowed. After power on the device waits a few seconds for a WoL packet. If a packet is received, the device boots the alternate image. Otherwise it boots the default image. This method is a simple way to interact with a system via network even if only the MAC address is known. Tools to send WoL packets are available on all common platforms. Signed-off-by: Lothar Felten --- net/wol.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/wol.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 net/wol.c create mode 100644 net/wol.h diff --git a/net/wol.c b/net/wol.c new file mode 100644 index 0000000000..0cedbaed85 --- /dev/null +++ b/net/wol.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 Lothar Felten, lothar.felten@gmail.com + */ + +#include +#include +#include +#include "wol.h" + +/* + * Handle a received wake-on-lan packet. + */ +void wol_receive(struct ip_udp_hdr *ip, unsigned int len) +{ + char buf[4]; + int i; + struct wol_hdr *wol; + + wol = (struct wol_hdr *)ip; + + if (len < 102) + return; + + for (i = 0; i < 6; i++) + if (wol->wol_sync[i] != 0xff) + return; + + for (i = 0; i < 16; i++) + if (memcmp(&wol->wol_dest[i * 6], net_ethaddr, 6) != 0) + return; + + /* save the optional password using the etherwake format */ + if (len >= 106) { + sprintf(buf, "%i.%i.%i.%i", + wol->wol_passwd[0], wol->wol_passwd[1], + wol->wol_passwd[2], wol->wol_passwd[3]); + env_set("wolpassword", buf); + } + net_set_state(NETLOOP_SUCCESS); +} + +static void wol_timeout_handler(void) +{ + eth_halt(); + net_set_state(NETLOOP_FAIL); +} + +void wol_start(void) +{ + ulong timeout = env_get_ulong("woltimeout", 10, 5); + + net_set_timeout_handler(timeout * 1000, wol_timeout_handler); +} diff --git a/net/wol.h b/net/wol.h new file mode 100644 index 0000000000..e34767c733 --- /dev/null +++ b/net/wol.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2018 Lothar Felten, lothar.felten@gmail.com + */ + +#if defined(CONFIG_CMD_WOL) + +#ifndef __WOL_H__ +#define __WOL_H__ + +#include + +/**********************************************************************/ + +/* + * Wake-on-LAN header. + */ +struct wol_hdr { + u8 wol_sync[6]; /* sync bytes */ + u8 wol_dest[16 * 6]; /* 16x destination MAC address */ + u8 wol_passwd[4]; /* optional password */ +}; + +/* + * Initialize wol (beginning of netloop) + */ +void wol_start(void); + +/* + * Deal with the receipt of a wol packet + * + * @param ip IP header in the packet + * @param len Packet length + */ +void wol_receive(struct ip_udp_hdr *ip, unsigned int len); + +/**********************************************************************/ + +#endif /* __WOL_H__ */ +#endif