From patchwork Tue Mar 29 17:44:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Cieslakiewicz X-Patchwork-Id: 603102 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (caladan.dune.hu [78.24.191.180]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qZJFH2T6Gz9sC3 for ; Wed, 30 Mar 2016 04:49:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=wp.pl header.i=@wp.pl header.b=xrKOc534; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 38A5AB911A3; Tue, 29 Mar 2016 19:48:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: ** X-Spam-Status: No, score=2.4 required=5.0 tests=FREEMAIL_FROM,RDNS_NONE, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Tue, 29 Mar 2016 19:48:49 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 07650B91199 for ; Tue, 29 Mar 2016 19:48:47 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .wp. - helo: .mx4. - helo-domain: .mx4.) FROM/MX_MATCHES_NOT_HELO(DOMAIN)=1; rate: -4 Received: from mx4.wp.pl (unknown [212.77.101.12]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Tue, 29 Mar 2016 19:48:46 +0200 (CEST) Received: (wp-smtpd smtp.wp.pl 8832 invoked from network); 29 Mar 2016 19:48:40 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1459273720; bh=D701LeTIIk204NEeT+bKv3FSftEUWnrR1xsZq02nQ04=; h=From:To:Cc:Subject; b=xrKOc5344CB0lksmhKL/apY95RDLWhE/xD3wUh4Z5lB+a/qPs/4diAMnqbQNY/opu jqicCq5bd2+mLpLj+Ttio8OCttd1PmgDsy9kCFSGSxZqzFfap2FKDKltykn97Zc4VE AJoOXm/9vnpOcd8WgJE2XN7VAWsxD9z/EHatVk1g= Received: from 89-71-134-133.dynamic.chello.pl (HELO kosmio) (michal.cieslakiewicz@[89.71.134.133]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP for ; 29 Mar 2016 19:48:40 +0200 Date: Tue, 29 Mar 2016 19:44:22 +0200 From: Michal To: "openwrt-devel@lists.openwrt.org" Message-ID: <20160329194422.15bc835c@kosmio> In-Reply-To: <20160329194142.1987dafe@kosmio> References: <20160329194142.1987dafe@kosmio> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-slackware-linux-gnu) MIME-Version: 1.0 X-WP-MailID: 5f79722aa67c6a814756052753a72b8e X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [YcMU] Subject: [OpenWrt-Devel] [PATCH 1/2] ar71xx: WNR2200: fix for random WLAN MAC X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" From: Michal Cieslakiewicz Date: Sat, 26 Mar 2016 18:17:45 +0100 Subject: [PATCH 1/2] ar71xx: WNR2200: fix for random WLAN MAC Fix for invalid/random/duplicate WLAN MAC address in WNR2200. Permanent platform MAC is calculated and assigned during system startup. WLAN MAC follows wired Ethernet interface addresses. Signed-off-by: Michal Cieslakiewicz --- .../ar71xx/files/arch/mips/ath79/mach-wnr2200.c | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c index 5d23f21..37ffc4c 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-wnr2200.c @@ -12,6 +12,7 @@ #include #include +#include /* for max() macro */ #include @@ -45,6 +46,7 @@ #define WNR2200_MAC0_OFFSET 0 #define WNR2200_MAC1_OFFSET 6 #define WNR2200_PCIE_CALDATA_OFFSET 0x1000 +#define WNR2200_WMAC_OFFSET 0x108c /* wireless MAC is inside ART */ static struct gpio_led wnr2200_leds_gpio[] __initdata = { { @@ -102,9 +104,40 @@ static struct gpio_led wnr2200_leds_gpio[] __initdata = { } }; +/* + * For WNR2200 ART flash area used for WLAN MAC is usually empty (0xff) + * so ath9k driver uses random MAC instead each time module is loaded. + * OpenWrt's original fix was to copy eth1 address to WLAN interface. + * New solution does not duplicate hardware addresses and is taken from + * WNR2000v3 code. It assigns permanent WLAN MAC equal to ethN's MAC + * plus 1, so network interfaces get sequential addresses. + * If ART wireless MAC address field has been filled by user, use it. + */ +static void __init wnr2200_get_wmac(u8 *wmac_gen_addr, int mac0_art_offset, + int mac1_art_offset, int wmac_art_offset) +{ + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000); + u8 *eth0_mac_addr = (u8 *) (art + mac0_art_offset); + u8 *eth1_mac_addr = (u8 *) (art + mac1_art_offset); + u8 *wlan_mac_addr = (u8 *) (art + wmac_art_offset); + + /* only 0xff if all bits are set - address is invalid, empty area */ + if ((wlan_mac_addr[0] & wlan_mac_addr[1] & wlan_mac_addr[2] & + wlan_mac_addr[3] & wlan_mac_addr[4] & wlan_mac_addr[5]) == 0xff) { + memcpy(wmac_gen_addr, eth0_mac_addr, 5); + wmac_gen_addr[5] = max(eth0_mac_addr[5], eth1_mac_addr[5]) + 1; + + /* Avoid potential conflict in case max(0xff,0x00)+1==0x00 */ + if (!wmac_gen_addr[5]) + wmac_gen_addr[5] = 1; + } else + memcpy(wmac_gen_addr, wlan_mac_addr, 6); +} + static void __init wnr2200_setup(void) { u8 *art = (u8 *) KSEG1ADDR(0x1fff0000); + u8 wlan_mac_addr[6]; ath79_register_mdio(0, 0x0); @@ -121,8 +154,10 @@ static void __init wnr2200_setup(void) ath79_register_eth(1); ath79_register_m25p80(NULL); - ap91_pci_init(art + WNR2200_PCIE_CALDATA_OFFSET, - art + WNR2200_MAC1_OFFSET); + + wnr2200_get_wmac(wlan_mac_addr, WNR2200_MAC0_OFFSET, + WNR2200_MAC1_OFFSET, WNR2200_WMAC_OFFSET); + ap91_pci_init(art + WNR2200_PCIE_CALDATA_OFFSET, wlan_mac_addr); ath79_register_leds_gpio(-1, ARRAY_SIZE(wnr2200_leds_gpio), wnr2200_leds_gpio);