From patchwork Tue Jun 12 14:28:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Pisati X-Patchwork-Id: 928349 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.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 414sh24Xc5z9s5N; Wed, 13 Jun 2018 00:28:50 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1fSkHr-0002sz-Rc; Tue, 12 Jun 2018 14:28:43 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1fSkHp-0002sK-8v for kernel-team@lists.ubuntu.com; Tue, 12 Jun 2018 14:28:41 +0000 Received: from 1.general.ppisati.uk.vpn ([10.172.193.134] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fSkHp-0008VQ-0p for kernel-team@lists.ubuntu.com; Tue, 12 Jun 2018 14:28:41 +0000 From: Paolo Pisati To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/2] SAUCE: wcn36xx: read MAC from file or randomly generate one Date: Tue, 12 Jun 2018 16:28:39 +0200 Message-Id: <1528813720-7936-2-git-send-email-paolo.pisati@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528813720-7936-1-git-send-email-paolo.pisati@canonical.com> References: <1528813720-7936-1-git-send-email-paolo.pisati@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: http://bugs.launchpad.net/bugs/1776491 Signed-off-by: Paolo Pisati --- drivers/net/wireless/ath/wcn36xx/Kconfig | 9 ++++++ drivers/net/wireless/ath/wcn36xx/main.c | 38 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/wcn36xx/Kconfig b/drivers/net/wireless/ath/wcn36xx/Kconfig index 20bf967a70b9..44d34a80fad4 100644 --- a/drivers/net/wireless/ath/wcn36xx/Kconfig +++ b/drivers/net/wireless/ath/wcn36xx/Kconfig @@ -16,3 +16,12 @@ config WCN36XX_DEBUGFS Enabled debugfs support If unsure, say Y to make it easier to debug problems. + +config WCN36XX_SNAPDRAGON_HACKS + bool "Dragonboard 410c WCN36XX MAC address generation hacks" + default n + depends on WCN36XX + ---help--- + Upon probe, WCN36XX will try to read its MAC address from + a file located at /lib/firmware/wlan/macaddr0. If the file + is not present, it will randomly generate a new MAC address. diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c index fcc98d4f9f9e..ed0b9736f9ae 100644 --- a/drivers/net/wireless/ath/wcn36xx/main.c +++ b/drivers/net/wireless/ath/wcn36xx/main.c @@ -1265,6 +1265,14 @@ static int wcn36xx_probe(struct platform_device *pdev) void *wcnss; int ret; const u8 *addr; +#ifdef CONFIG_WCN36XX_SNAPDRAGON_HACKS + int status; + const struct firmware *addr_file = NULL; + u8 tmp[18], _addr[ETH_ALEN]; + static const u8 qcom_oui[3] = {0x00, 0x0A, 0xF5}; + static const char *files = {"wlan/macaddr0"}; +#endif + wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n"); @@ -1298,7 +1306,35 @@ static int wcn36xx_probe(struct platform_device *pdev) wcn36xx_err("invalid local-mac-address\n"); ret = -EINVAL; goto out_wq; - } else if (addr) { + } +#ifdef CONFIG_WCN36XX_SNAPDRAGON_HACKS + else if (addr == NULL) { + addr = _addr; + status = request_firmware(&addr_file, files, &pdev->dev); + + if (status < 0) { + /* Assign a random mac with Qualcomm oui */ + dev_err(&pdev->dev, "Failed (%d) to read macaddress" + "file %s, using a random address instead", status, files); + memcpy(addr, qcom_oui, 3); + get_random_bytes(addr + 3, 3); + } else { + memset(tmp, 0, sizeof(tmp)); + memcpy(tmp, addr_file->data, sizeof(tmp) - 1); + sscanf(tmp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + &addr[0], + &addr[1], + &addr[2], + &addr[3], + &addr[4], + &addr[5]); + + release_firmware(addr_file); + } + } +#endif + + if (addr) { wcn36xx_info("mac address: %pM\n", addr); SET_IEEE80211_PERM_ADDR(wcn->hw, addr); }