From owner-svn-src-head@freebsd.org Sat Sep 3 15:28:10 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8B7BEBCE69E; Sat, 3 Sep 2016 15:28:10 +0000 (UTC) (envelope-from jmcneill@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5E5C123F; Sat, 3 Sep 2016 15:28:10 +0000 (UTC) (envelope-from jmcneill@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u83FS93m017462; Sat, 3 Sep 2016 15:28:09 GMT (envelope-from jmcneill@FreeBSD.org) Received: (from jmcneill@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u83FS91u017461; Sat, 3 Sep 2016 15:28:09 GMT (envelope-from jmcneill@FreeBSD.org) Message-Id: <201609031528.u83FS91u017461@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jmcneill set sender to jmcneill@FreeBSD.org using -f From: Jared McNeill Date: Sat, 3 Sep 2016 15:28:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305354 - head/sys/arm/allwinner X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Sep 2016 15:28:10 -0000 Author: jmcneill Date: Sat Sep 3 15:28:09 2016 New Revision: 305354 URL: https://svnweb.freebsd.org/changeset/base/305354 Log: Use the root key in the Security ID EFUSE (when valid) to generate a MAC address instead of creating a random one each boot. Modified: head/sys/arm/allwinner/if_awg.c Modified: head/sys/arm/allwinner/if_awg.c ============================================================================== --- head/sys/arm/allwinner/if_awg.c Sat Sep 3 15:26:28 2016 (r305353) +++ head/sys/arm/allwinner/if_awg.c Sat Sep 3 15:28:09 2016 (r305354) @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -1277,6 +1278,7 @@ awg_get_eaddr(device_t dev, uint8_t *ead { struct awg_softc *sc; uint32_t maclo, machi, rnd; + u_char rootkey[16]; sc = device_get_softc(dev); @@ -1285,9 +1287,19 @@ awg_get_eaddr(device_t dev, uint8_t *ead if (maclo == 0xffffffff && machi == 0xffff) { /* MAC address in hardware is invalid, create one */ - rnd = arc4random(); - maclo = 0x00f2 | (rnd & 0xffff0000); - machi = rnd & 0xffff; + if (aw_sid_get_rootkey(rootkey) == 0 && + (rootkey[3] | rootkey[12] | rootkey[13] | rootkey[14] | + rootkey[15]) != 0) { + /* MAC address is derived from the root key in SID */ + maclo = (rootkey[13] << 24) | (rootkey[12] << 16) | + (rootkey[3] << 8) | 0x02; + machi = (rootkey[15] << 8) | rootkey[14]; + } else { + /* Create one */ + rnd = arc4random(); + maclo = 0x00f2 | (rnd & 0xffff0000); + machi = rnd & 0xffff; + } } eaddr[0] = maclo & 0xff;