diff options
author | Victor Hsu <hsuvictor@google.com> | 2021-11-19 16:17:09 +0800 |
---|---|---|
committer | Victor Hsu <hsuvictor@google.com> | 2021-12-13 17:03:07 +0800 |
commit | 382c14c273a6df27518e102a7aad2ba6be714588 (patch) | |
tree | 0a14799c986376655e816c5f677e73a929d18786 | |
parent | 680a154f041761cf8772509f135415962513fe62 (diff) | |
download | cnss2-382c14c273a6df27518e102a7aad2ba6be714588.tar.gz |
wcn6740: Mac address provision
Add google_wlan_mac module to read provisioned
platform Mac address and assign to WLAN driver
Bug: 206341009
Signed-off-by: Victor Hsu <hsuvictor@google.com>
Change-Id: I682cc8136456daab05572d53bef1e674807c0823
-rw-r--r-- | Kbuild | 3 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | wlan_mac/Kconfig | 8 | ||||
-rw-r--r-- | wlan_mac/Makefile | 5 | ||||
-rw-r--r-- | wlan_mac/google_wlan_mac.c | 110 |
5 files changed, 129 insertions, 0 deletions
@@ -41,4 +41,7 @@ KBUILD_CPPFLAGS += -DCONFIG_QRTR_NODE_ID=$(CONFIG_QRTR_NODE_ID) KBUILD_CPPFLAGS += -DCONFIG_QRTR_WAKEUP_MS=$(CONFIG_QRTR_WAKEUP_MS) obj-$(CONFIG_QRTR) += qrtr/ +# WLAN_MAC +obj-$(CONFIG_GOOGLE_WLAN_MAC) += wlan_mac/ + KBUILD_CPPFLAGS += -I$(WLAN_PLATFORM_ROOT)/inc @@ -33,6 +33,9 @@ KBUILD_OPTIONS += CONFIG_QRTR_MHI=m KBUILD_OPTIONS += CONFIG_QRTR_NODE_ID=1 KBUILD_OPTIONS += CONFIG_QRTR_WAKEUP_MS=0 +# WLAN_MAC +KBUILD_OPTIONS += CONFIG_GOOGLE_WLAN_MAC=m + endif all: diff --git a/wlan_mac/Kconfig b/wlan_mac/Kconfig new file mode 100644 index 0000000..d27fe52 --- /dev/null +++ b/wlan_mac/Kconfig @@ -0,0 +1,8 @@ +# +# google set wlan mac +# +config GOOGLE_WLAN_MAC + tristate "Read MAC address from device tree" + default n + help + Say Y here if you want the GOOGLE WLAN MAC features diff --git a/wlan_mac/Makefile b/wlan_mac/Makefile new file mode 100644 index 0000000..c79eee1 --- /dev/null +++ b/wlan_mac/Makefile @@ -0,0 +1,5 @@ +# +# google set wlan mac address +# +#ccflags-y += -I$(WLAN_PLATFORM_ROOT)/inc +obj-$(CONFIG_GOOGLE_WLAN_MAC) += google_wlan_mac.o diff --git a/wlan_mac/google_wlan_mac.c b/wlan_mac/google_wlan_mac.c new file mode 100644 index 0000000..ee37056 --- /dev/null +++ b/wlan_mac/google_wlan_mac.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <asm/setup.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/string.h> +#include <linux/export.h> +#include <linux/of.h> +#include <linux/random.h> +#include <linux/slab.h> +#include <linux/uaccess.h> +#include "cnss_utils.h" + +#define CDB_PATH "/chosen/config" +#define WIFI_MAC "wlan_mac1" + +static void set_wifi_mac(void) +{ + u8 mac[6] = {0}; + unsigned int size; + unsigned char *mac_addr = NULL; + struct device_node *node; + unsigned int mac_found = 0; + + node = of_find_node_by_path(CDB_PATH); + if (!node) { + pr_err("[WLAN] CDB Node not created under %s", CDB_PATH); + } else { + mac_addr = (unsigned char *) + of_get_property(node, WIFI_MAC, &size); + } + + /* In case Missing Provisioned MAC Address, exit with error */ + if (!mac_addr) { + pr_err("[WLAN] Missing Provisioned MAC address\n"); + return; + } + + /* Start decoding MAC Address + * Note that 2 formats are supported for now + * AA:BB:CC:DD:EE:FF (with separating colons) and + * AABBCCDDEEFF (without separating colons) */ + if (sscanf(mac_addr, + "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], + &mac[5]) == 6) { + mac_found = 1; + } else if (sscanf(mac_addr, + "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], + &mac[5]) == 6) { + mac_found = 1; + } + + /* Make sure Address decoding succeeds */ + if (!mac_found) { + pr_err("[WLAN] Invalid format for Provisioned MAC Address\n"); + return; + } + + /* Make sure Provisioned MAC Address is globally Administered */ + if (mac[0] & 2) { + pr_err("[WLAN] Invalid Provisioned MAC Address\n"); + return; + } + + /* Send provisioned MAC Address to the platform driver */ + if (cnss_utils_set_wlan_mac_address(mac, sizeof(mac)) != 0) { + pr_err("[WLAN] set wlan mac address failed\n"); + return; + } + + /* Now derive the derived mac address + * by flipping the locally administred bit */ + mac[0] = mac[0] | 2; + + if (cnss_utils_set_wlan_derived_mac_address(mac, sizeof(mac)) != 0) { + pr_err("[WLAN] set wlan derived mac address failed\n"); + return; + } + + return; +} + +static int __init wifi_mac_init(void) +{ + set_wifi_mac(); + + return 0; +} + +late_initcall(wifi_mac_init); + +MODULE_AUTHOR("Google"); +MODULE_DESCRIPTION("Google set wlan mac"); +MODULE_LICENSE("GPL v2"); +MODULE_SOFTDEP("pre: cnss2"); |