diff --git a/arch/arm/mach-msm/board-htcleo-wifi-nvs.c b/arch/arm/mach-msm/board-htcleo-wifi-nvs.c index 008325eb..8aeccb25 100644 --- a/arch/arm/mach-msm/board-htcleo-wifi-nvs.c +++ b/arch/arm/mach-msm/board-htcleo-wifi-nvs.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include "board-htcleo.h" @@ -84,16 +83,25 @@ EXPORT_SYMBOL(get_wifi_nvs_ram); static int parse_tag_msm_wifi(void) { - uint32_t id1, id2, id3, sid1, sid2, sid3; + uint32_t id1, id2, sid1, sid2, sid3; uint32_t id_base = 0xef260; - id1 = readl(MSM_SHARED_RAM_BASE + id_base + 0x0); - id2 = readl(MSM_SHARED_RAM_BASE + id_base + 0x4); - id3 = readl(MSM_SHARED_RAM_BASE + id_base + 0x8); - sid1 = crc32(~0, &id1, 4); - sid2 = crc32(~0, &id2, 4); - sid3 = crc32(~0, &id3, 4); - sprintf(nvs_mac_addr, "macaddr=00:23:76:%2x:%2x:%2x\n", sid1 % 0xff, sid2 % 0xff, sid3 % 0xff); - pr_info("Device Wifi Mac Address: %s\n", nvs_mac_addr); + /* read Serial Number SN (IMEI = TAC.SN) */ + id1 = readl(MSM_SHARED_RAM_BASE + id_base + 0x8); + id2 = readl(MSM_SHARED_RAM_BASE + id_base + 0xc); + /* Xor SN with TAC (yes only two differents TAC for the HD2 */ + id1 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x0); + id2 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x4); + /* Xor with CID of operator too further mix the Serial */ + id1 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x10); + id2 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x14); + + /* repack the SN part from IMEI (id) into three bytes using low nibbles */ + sid1 = ((id1 << 4) & 0xf0) | ((id1 >> 8) & 0xf); + sid2 = ((id1 >> 12) & 0xf0) | ((id1 >> 24) & 0xf); + sid3 = ((id2 << 4) & 0xf0) | ((id2 >> 8) & 0xf); + + sprintf(nvs_mac_addr, "macaddr=00:23:76:%02x:%02x:%02x\n", sid1, sid2, sid3); + pr_info("Device WiFi MAC Address: %s\n", nvs_mac_addr); return 0; } diff --git a/arch/arm/mach-msm/board-htcleo.c b/arch/arm/mach-msm/board-htcleo.c index 01d66fac..7ea2ff5c 100644 --- a/arch/arm/mach-msm/board-htcleo.c +++ b/arch/arm/mach-msm/board-htcleo.c @@ -15,7 +15,6 @@ * */ -#include #include #include #include @@ -565,16 +564,25 @@ MODULE_PARM_DESC(bdaddr, "bluetooth address"); static int parse_tag_bdaddr(void) { - uint32_t id1, id2, id3, sid1, sid2, sid3; + uint32_t id1, id2, sid1, sid2, sid3; uint32_t id_base = 0xef260; - id1 = readl(MSM_SHARED_RAM_BASE + id_base + 0x0); - id2 = readl(MSM_SHARED_RAM_BASE + id_base + 0x4); - id3 = readl(MSM_SHARED_RAM_BASE + id_base + 0x8); - sid1 = crc32(~0, &id1, 4); - sid2 = crc32(~0, &id2, 4); - sid3 = crc32(~0, &id3, 4); - sprintf(bdaddr, "00:23:76:%2X:%2X:%2X", sid3 % 0xff, sid2 % 0xff, sid1 % 0xff); - pr_info("Device Bluetooth Mac Address: %s\n", bdaddr); + /* read Serial Number SN (IMEI = TAC.SN) */ + id1 = readl(MSM_SHARED_RAM_BASE + id_base + 0x8); + id2 = readl(MSM_SHARED_RAM_BASE + id_base + 0xc); + /* Xor SN with TAC (yes only two differents TAC for the HD2 */ + id1 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x0); + id2 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x4); + /* Xor with CID of operator too further mix the Serial */ + id1 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x10); + id2 ^= readl(MSM_SHARED_RAM_BASE + id_base + 0x14); + + /* repack the SN part from IMEI (id) into three bytes using low nibbles */ + sid1 = ((id1 << 4) & 0xf0) | ((id1 >> 8) & 0xf); + sid2 = ((id1 >> 12) & 0xf0) | ((id1 >> 24) & 0xf); + sid3 = ((id2 << 4) & 0xf0) | ((id2 >> 8) & 0xf); + + sprintf(bdaddr, "00:23:76:%02x:%02x:%02x", sid3, sid2, sid1); + pr_info("Device Bluetooth MAC Address: %s\n", bdaddr); return 0; } /* end AOSP style interface */