[1/2] SAUCE: wcn36xx: read MAC from file or randomly generate one

Message ID 1528813720-7936-2-git-send-email-paolo.pisati@canonical.com
State New
Headers show
Series
  • arm64: snapdragon: wcn36xx MAC
Related show

Commit Message

Paolo Pisati June 12, 2018, 2:28 p.m.
BugLink: http://bugs.launchpad.net/bugs/1776491

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
---
 drivers/net/wireless/ath/wcn36xx/Kconfig |  9 ++++++
 drivers/net/wireless/ath/wcn36xx/main.c  | 38 +++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletion(-)

Comments

Stefan Bader June 13, 2018, 2:48 p.m. | #1
On 12.06.2018 16:28, Paolo Pisati wrote:

Subject should, iirc be "UBUNTU: SAUCE: ...". Also, please add more of the
description of the change into the commit message. Its a pain to always have to
follow some link or read code to know what a commit does and why. Does not have
to be the long story but a bit more than nothing would help.
The config change, ok, there is probably not much more to say about that one
beyond the one line.
> BugLink: http://bugs.launchpad.net/bugs/1776491
> 
> Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
> ---
>  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);
>  	}
>
Paolo Pisati June 14, 2018, 10:07 a.m. | #2
Ok, i'm sending a V2.

On Wed, Jun 13, 2018 at 4:48 PM, Stefan Bader
<stefan.bader@canonical.com> wrote:
> On 12.06.2018 16:28, Paolo Pisati wrote:
>
> Subject should, iirc be "UBUNTU: SAUCE: ...". Also, please add more of the
> description of the change into the commit message. Its a pain to always have to
> follow some link or read code to know what a commit does and why. Does not have
> to be the long story but a bit more than nothing would help.
> The config change, ok, there is probably not much more to say about that one
> beyond the one line.

Patch

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);
 	}