scsc: Pick WiFi/BT MAC address from utag
authorsunyue5 <sunyue5@motorola.com>
Tue, 31 Jul 2018 09:36:01 +0000 (17:36 +0800)
committerxiest1 <xiest1@lenovo.com>
Tue, 5 Nov 2019 09:30:15 +0000 (17:30 +0800)
Priority as following
Wifi:
1. Utag
2. Mac file
3. Samsung efs
4. Generate with Moto OUI and SoC uid
BT:
1. Utag
2. Samsung efs
3. Module parameter bluetooth_address
4. Generate with Moto OUI and SoC uid

Change-Id: Ia9d803d622f5293dc409f9887b3b9b7e85c4b381
Signed-off-by: sunyue5 <sunyue5@motorola.com>
Reviewed-on: https://gerrit.mot.com/1238038
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

drivers/misc/samsung/scsc_bt/scsc_bt_module.c
drivers/net/wireless/scsc/mgt.c
include/scsc/kic/slsi_kic_prim.h

index 6b87644a8a9bf6191f64b810a9f271038ba23daa..9c07f7c72fd485d63dabaf1f2693cb829081fc9f 100755 (executable)
@@ -604,6 +604,7 @@ static int setup_bhcs(struct scsc_service *service,
        int err = 0;
        unsigned char *conf_ptr;
        const struct firmware *firm = NULL;
+       struct device_node *chosen_node = NULL; //IKKANE-6
        /* Fill the configuration information */
        bhcs->version = BHCS_VERSION;
        bhcs->bsmhcp_protocol_offset = protocol_ref;
@@ -733,6 +734,43 @@ static int setup_bhcs(struct scsc_service *service,
        }
 #endif
 
+//BEGIN IKKANE-6
+#ifdef MOTO_UTAGS_MAC
+       //Moto, read MACs from bootparams
+       chosen_node = of_find_node_by_name(NULL, "chosen");
+       if (!chosen_node) {
+               SCSC_TAG_ERR(BT_COMMON, "%s: get chosen node read failed\n", __func__);
+       } else {
+               int len=0;
+               const char *cmd_line = NULL;
+               cmd_line = of_get_property(chosen_node, "bootargs", &len);
+               if (!cmd_line || len <= 0) {
+                       SCSC_TAG_ERR(BT_COMMON, "%s: get bt MACs bootargs failed\n", __func__);
+               } else {
+                       char * mac_idx = NULL;
+                       mac_idx = strstr(cmd_line, BT_MAC_BOOTARG);
+                       if (mac_idx == NULL) {
+                               SCSC_TAG_ERR(BT_COMMON, "%s: " BT_MAC_BOOTARG " not present in bootargs", __func__);
+                       } else {
+                               char macStr[MACSTRLEN+1] = {0};
+                               u32 u[SCSC_BT_ADDR_LEN] = {0};
+                               // extract MAC from boot params
+                               mac_idx += strlen(WIFI_MAC_BOOTARG);
+                               memcpy(macStr, mac_idx, MACSTRLEN);
+                               sscanf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X",
+                                       u[0], u[1], u[2], u[3], u[4], u[5]);
+                               bhcs->bluetooth_address_lap =
+                                       (u[3] << 16) | (u[4] << 8) | u[5];
+                               bhcs->bluetooth_address_uap = u[2];
+                               bhcs->bluetooth_address_nap = (u[0] << 8) | u[1];
+                               SCSC_TAG_ERR(BT_COMMON,, "BT MAC address loaded from utag: %02X:%02X:%02X:%02X:%02X:%02X\n",
+                                       u[0], u[1], u[2], u[3], u[4], u[5]);
+                       }
+               }
+       }
+#endif
+//END IKKANE-6
+
 #ifdef CONFIG_SCSC_DEBUG
        SCSC_TAG_DEBUG(BT_COMMON, "Bluetooth address: %04X:%02X:%06X\n",
                       bhcs->bluetooth_address_nap,
@@ -2152,15 +2190,22 @@ static int __init scsc_bt_module_init(void)
        spin_lock_init(&bt_service.avdtp_detect.lock);
        spin_lock_init(&bt_service.avdtp_detect.fw_write_lock);
 
-#ifdef CONFIG_ARCH_EXYNOS
+//BEGIN IKKANE-6
+#ifdef MOTO_UTAGS_MAC
+       sprintf(bluetooth_address_fallback, "F0:D7:AA:%02X:%02X:%02X",
+               (exynos_soc_info.unique_id & 0xFF0000000000) >> 40,
+               (exynos_soc_info.unique_id & 0x00FF00000000) >> 32,
+               (exynos_soc_info.unique_id & 0x0000FF000000) >> 24);
+#elif CONFIG_ARCH_EXYNOS
        sprintf(bluetooth_address_fallback, "%02X:%02X:%02X:%02X:%02X:%02X",
-              (exynos_soc_info.unique_id & 0x000000FF0000) >> 16,
-              (exynos_soc_info.unique_id & 0x00000000FF00) >> 8,
-              (exynos_soc_info.unique_id & 0x0000000000FF) >> 0,
-              (exynos_soc_info.unique_id & 0xFF0000000000) >> 40,
-              (exynos_soc_info.unique_id & 0x00FF00000000) >> 32,
-              (exynos_soc_info.unique_id & 0x0000FF000000) >> 24);
+               (exynos_soc_info.unique_id & 0x000000FF0000) >> 16,
+               (exynos_soc_info.unique_id & 0x00000000FF00) >> 8,
+               (exynos_soc_info.unique_id & 0x0000000000FF) >> 0,
+               (exynos_soc_info.unique_id & 0xFF0000000000) >> 40,
+               (exynos_soc_info.unique_id & 0x00FF00000000) >> 32,
+               (exynos_soc_info.unique_id & 0x0000FF000000) >> 24);
 #endif
+//END IKKANE-6
 
 #ifdef CONFIG_SCSC_ANT
        SCSC_TAG_DEBUG(BT_COMMON, "dev=%u class=%p\n",
index fe1de7f1abe9d6bd7a1ebafbefd9e49f68ba235d..81bf1f9e31c567bd8505c85c5215ef46393b86bf 100755 (executable)
@@ -209,19 +209,58 @@ void slsi_get_hw_mac_address(struct slsi_dev *sdev, u8 *addr)
        u32                   u[ETH_ALEN];
        char                  path_name[MX_WLAN_FILE_PATH_LEN_MAX];
        int                   r;
-       bool                  valid = false;
-
-       /* Module parameter override */
-       r = sscanf(mac_addr_override, "%02X:%02X:%02X:%02X:%02X:%02X", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]);
-       if (r != ETH_ALEN) {
-               SLSI_ERR(sdev, "mac_addr modparam set, but format is incorrect (should be e.g. xx:xx:xx:xx:xx:xx)\n");
-               goto mac_sysfs;
-       }
-       for (i = 0; i < ETH_ALEN; i++) {
-               if (u[i] != 0xff)
-                       valid = true;
-               addr[i] = u[i] & 0xff;
+       bool                  valid = false;
+//BEGIN IKKANE-6
+#ifdef MOTO_UTAGS_MAC
+       struct device_node *chosen_node = NULL;
+       //Moto, read MACs from bootparams
+       chosen_node = of_find_node_by_name(NULL, "chosen");
+       if (!chosen_node) {
+               SLSI_ERR(sdev, "%s: get chosen node read failed\n", __func__);
+               goto mac_ss;
+       } else {
+               int len=0;
+               const char *cmd_line = NULL;
+               cmd_line = of_get_property(chosen_node, "bootargs", &len);
+               if (!cmd_line || len <= 0) {
+                       SLSI_ERR(sdev, "%s: get wlan MACs bootargs failed\n", __func__);
+                       goto mac_ss;
+               } else {
+                       char * mac_idx = NULL;
+                       mac_idx = strstr(cmd_line, WIFI_MAC_BOOTARG);
+                       if (mac_idx == NULL) {
+                               SLSI_ERR(sdev, "%s: " WIFI_MAC_BOOTARG " not present in bootargs", __func__);
+                               goto mac_ss;
+                       } else {
+                               char macStr[MACSTRLEN+1] = {0};
+                               // extract MAC from boot params
+                               mac_idx += strlen(WIFI_MAC_BOOTARG);
+                               memcpy(macStr, mac_idx, MACSTRLEN);
+                               sscanf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X",
+                                       u[0], u[1], u[2], u[3], u[4], u[5]);
+                               for (i = 0; i < ETH_ALEN; i++)
+                                       addr[i] = u[i] & 0xff;
+                               SLSI_INFO(sdev, "WiFi MAC address loaded from utag: %02X:%02X:%02X:%02X:%02X:%02X\n",
+                                       u[0], u[1], u[2], u[3], u[4], u[5]);
+                       }
+               }
        }
+       return;
+mac_ss:
+#endif
+//END IKKANE-6
+
+        /* Module parameter override */
+        r = sscanf(mac_addr_override, "%02X:%02X:%02X:%02X:%02X:%02X", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]);
+        if (r != ETH_ALEN) {
+                SLSI_ERR(sdev, "mac_addr modparam set, but format is incorrect (should be e.g. xx:xx:xx:xx:xx:xx)\n");
+                goto mac_sysfs;
+        }
+        for (i = 0; i < ETH_ALEN; i++) {
+                if (u[i] != 0xff)
+                        valid = true;
+                addr[i] = u[i] & 0xff;
+        }
 
        /* If the override is valid, use it */
        if (valid) {
@@ -314,6 +353,15 @@ mac_default:
        mx140_file_release_conf(sdev->maxwell_core, e);
 
        SLSI_ETHER_COPY(addr, SLSI_DEFAULT_HW_MAC_ADDR);
+//BEGIN IKKANE-6
+#ifdef MOTO_UTAGS_MAC
+       /* Motorola OUI */
+       addr[0] = 0xF0;
+       addr[1] = 0xD7;
+       addr[2] = 0xAA;
+#endif
+//END IKKANE-6
+
 #ifdef CONFIG_ARCH_EXYNOS
        /* Randomise MAC address from the soc uid */
        addr[3] = (exynos_soc_info.unique_id & 0xFF0000000000) >> 40;
index cdee9c0f57ad738c7c47e330bc025eecd5859f22..437c350572fa459261a0b5bf39376b8f16fc863a 100755 (executable)
 extern "C" {
 #endif
 
+//BEGIN IKKANE-6
+#define MOTO_UTAGS_MAC 1
+#include <linux/of.h>
+#include <linux/of_address.h>
+#define WIFI_MAC_BOOTARG "androidboot.wifimacaddr="
+#define BT_MAC_BOOTARG "androidboot.btmacaddr="
+#define MACSTRLEN 17
+//END IKKANE-6
 
 #define SLSI_KIC_INTERFACE_VERSION_MAJOR 1
 #define SLSI_KIC_INTERFACE_VERSION_MINOR 0