msm: htcleo: implemented the real unique WiFi/Bluetooth MAC address to solve the MAC address collisions. (Credit to Franck78 <fbourdonnec@chez.com>)

WiFi MAC address collisions: http://forum.xda-developers.com/showthread.php?t=1275095
This commit is contained in:
tytung 2012-05-09 00:27:33 +08:00
parent f13c2b648a
commit 54c05e087a
2 changed files with 36 additions and 20 deletions

View File

@ -25,7 +25,6 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/blktrans.h>
#include <mach/msm_iomap.h>
#include <linux/crc32.h>
#include <linux/io.h>
#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;
}

View File

@ -15,7 +15,6 @@
*
*/
#include <linux/crc32.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
@ -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 */