From patchwork Mon Apr 10 15:33:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olliver Schinagl X-Patchwork-Id: 749092 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3w1vZ61fyTz9sNk for ; Tue, 11 Apr 2017 01:42:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=schinagl.nl header.i=@schinagl.nl header.b="IbBqqZXD"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id BFD1FC21CA8; Mon, 10 Apr 2017 15:36:00 +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=KHOP_BIG_TO_CC, 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 D38D4C21C89; Mon, 10 Apr 2017 15:34:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2DF62C21C1F; Mon, 10 Apr 2017 15:34:11 +0000 (UTC) Received: from 7of9.schinagl.nl (7of9.schinagl.nl [62.251.20.244]) by lists.denx.de (Postfix) with ESMTPS id BD647C21C1F for ; Mon, 10 Apr 2017 15:34:11 +0000 (UTC) Received: from um-mbp-306.cloud.ultimaker.com (static-98-101-100-159.thenetworkfactory.nl [159.100.101.98]) by 7of9.schinagl.nl (Postfix) with ESMTPA id 7A30AAC88A; Mon, 10 Apr 2017 17:34:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=schinagl.nl; s=7of9; t=1491838448; bh=MF1FGcPmWg/sXRymyrlRKDlalqupG3Mg/R8+dXZFcDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IbBqqZXDAIrxKyVmFvEDsi/j45zcdJc8a3Mi+yZqVNk6zPW/F6XZ1jOkk/xVQMTgP TgRlqxXPzr6TwNIg2sQuFdmo+1ZTbzxE/wSmUKPrQk71CXF/J5O5kw/VN+yS7Ab+OB KMSnuYAHEdSMINEUzG0SKQSEqGN1vp0sA5GiiL9E= From: Olliver Schinagl To: Jagan Teki , Maxime Ripard , Simon Glass , Joe Hershberger Date: Mon, 10 Apr 2017 17:33:39 +0200 Message-Id: <20170410153356.2664-5-oliver@schinagl.nl> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410153356.2664-1-oliver@schinagl.nl> References: <20170410153356.2664-1-oliver@schinagl.nl> X-Mailman-Approved-At: Mon, 10 Apr 2017 15:34:41 +0000 Cc: Mugunthan V N , Marcus Cooper , Philipp Tomsich , Stefan Roese , u-boot@lists.denx.de, Aleksei Mamlin , Ian Campbell , Bernhard Nortmann , dev@linux-sunxi.org, Andre Przywara , Phil Han , Hans de Goede , Zoltan Herpai , Olliver Schinagl , Jelle de Jong Subject: [U-Boot] [PATCHv2 04/21] net: core: Add function to check/set MAC locality 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" Universally administered and locally administered addresses are distinguished by setting the second-least-significant bit of the first octet of the address. Having a function to check and set this U/L bit from a function makes it nice for boards that want to generate their own mac address to ensure they are locally administered. Signed-off-by: Olliver Schinagl --- include/net.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/include/net.h b/include/net.h index b4af8eaae4..b1d6f05a76 100644 --- a/include/net.h +++ b/include/net.h @@ -779,6 +779,28 @@ static inline int is_multicast_ethaddr(const u8 *addr) return 0x01 & addr[0]; } +/** + * is_local_ethaddr - Determine if the Ethernet address is a locally + * administered MAC address. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is a locally administered address. + */ +static inline int is_local_ethaddr(const u8 *addr) +{ + return 0x02 & addr[0]; +} + +/** + * set_local_ethaddr - Make the supplied Ethernet address a locally + * administered one. + * @addr: Pointer to a six-byte array containing the Ethernet address + */ +static inline void set_local_ethaddr(u8 *addr) +{ + addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ +} + /* * is_broadcast_ethaddr - Determine if the Ethernet address is broadcast * @addr: Pointer to a six-byte array containing the Ethernet address @@ -823,7 +845,7 @@ static inline void net_random_ethaddr(uchar *addr) addr[i] = rand_r(&seed); addr[0] &= 0xfe; /* clear multicast bit */ - addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ + set_local_ethaddr(addr); } /* Convert an IP address to a string */