msm: htcleo: export the real WiFi and Bluetooth MAC addresses.

(Credits go to marc1706)
This commit is contained in:
tytung 2012-06-01 01:16:20 +08:00 committed by milaq
parent b9788bd14a
commit c0e5d2e3af
4 changed files with 46 additions and 74 deletions

View File

@ -28,13 +28,17 @@
#include <linux/io.h>
#include "board-htcleo.h"
#include <mach/board-htcleo-mac.h>
#define NVS_MAX_SIZE 0x800U
#define NVS_MACADDR_SIZE 0x1AU
#define WLAN_SKB_BUF_NUM 16
/*
* wifi mac address will be parsed in msm_nand_probe
* see drivers/mtd/devices/htcleo_nand.c
*/
static struct proc_dir_entry *wifi_calibration;
static unsigned char nvs_mac_addr[NVS_MACADDR_SIZE];
char nvs_mac_addr[NVS_MACADDR_SIZE];
static unsigned char *hardcoded_nvs =
"sromrev=3\n"\
"vendid=0x14e4\n"\
@ -81,43 +85,7 @@ unsigned char *get_wifi_nvs_ram( void )
}
EXPORT_SYMBOL(get_wifi_nvs_ram);
static void parse_tag_msm_wifi(void)
{
uint32_t id1, id2, sid1, sid2, sid3;
uint32_t id_base = 0xef260;
/* 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);
}
static int parse_tag_msm_wifi_from_spl(void)
{
uint32_t id1, id2, id3, id4, id5, id6;
uint32_t id_base = 0xFC028; //real mac offset found in spl for haret.exe on WM
id1 = readl(MSM_SPLHOOD_BASE + id_base + 0x0);
id2 = readl(MSM_SPLHOOD_BASE + id_base + 0x1);
id3 = readl(MSM_SPLHOOD_BASE + id_base + 0x2);
id4 = readl(MSM_SPLHOOD_BASE + id_base + 0x3);
id5 = readl(MSM_SPLHOOD_BASE + id_base + 0x4);
id6 = readl(MSM_SPLHOOD_BASE + id_base + 0x5);
sprintf(nvs_mac_addr, "macaddr=%2x:%2x:%2x:%2x:%2x:%2x\n", id1 & 0xff, id2 & 0xff, id3 & 0xff, id4 & 0xff, id5 & 0xff, id6 & 0xff);
pr_info("Device Real Wifi Mac Address: %s\n", nvs_mac_addr);
return 0;
}
static unsigned wifi_get_nvs_size( void )
{
@ -159,11 +127,6 @@ static int wifi_calibration_read_proc(char *page, char **start, off_t off,
static int __init wifi_nvs_init(void)
{
pr_info("%s\n", __func__);
if (htcleo_is_nand_boot()) {
parse_tag_msm_wifi();
} else {
parse_tag_msm_wifi_from_spl();
}
wifi_calibration = create_proc_entry("calibration", 0444, NULL);
if (wifi_calibration != NULL) {
wifi_calibration->size = wifi_get_nvs_size();

View File

@ -64,6 +64,7 @@
#include <linux/msm_kgsl.h>
#endif
#include <mach/board-htcleo-mac.h>
#include <mach/board-htcleo-microp.h>
#include "board-htcleo.h"
@ -535,35 +536,14 @@ static struct platform_device msm_camera_sensor_s5k3e2fx =
///////////////////////////////////////////////////////////////////////
/* AOSP style interface */
#define BDADDR_STR_SIZE 18
static char bdaddr[BDADDR_STR_SIZE];
/*
* bluetooth mac address will be parsed in msm_nand_probe
* see drivers/mtd/devices/htcleo_nand.c
*/
char bdaddr[BDADDR_STR_SIZE];
module_param_string(bdaddr, bdaddr, sizeof(bdaddr), 0400);
MODULE_PARM_DESC(bdaddr, "bluetooth address");
static void parse_tag_bdaddr(void)
{
uint32_t id1, id2, sid1, sid2, sid3;
uint32_t id_base = 0xef260;
/* 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);
}
/* end AOSP style interface */
#ifdef CONFIG_SERIAL_MSM_HS
static struct msm_serial_hs_platform_data msm_uart_dm1_pdata = {
@ -1081,8 +1061,6 @@ static void __init htcleo_init(void)
config_gpio_table(bt_gpio_table, ARRAY_SIZE(bt_gpio_table));
parse_tag_bdaddr();
htcleo_audio_init();
msm_device_i2c_init();

View File

@ -0,0 +1,27 @@
/* arch/arm/mach-msm/include/mach/board-htcleo-mac.h
*
* Copyright (C) 2012 Marc Alexander.
* Author: Marc Alexander<admin@m-a-styles.de>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*/
#ifndef __ARCH_ARM_MACH_MSM_BOARD_HTCLEO_MAC_H
#define __ARCH_ARM_MACH_MSM_BOARD_HTCLEO_MAC_H
#define NVS_MACADDR_SIZE 0x1AU
extern char nvs_mac_addr[NVS_MACADDR_SIZE];
#define BDADDR_STR_SIZE 18
extern char bdaddr[BDADDR_STR_SIZE]; /* AOSP style */
#endif

View File

@ -39,6 +39,7 @@
#include <asm/mach/flash.h>
#include <mach/dma.h>
#include <mach/board-htcleo-mac.h>
unsigned crci_mask;
@ -1863,8 +1864,9 @@ void scanmac(struct mtd_info *mtd)
printk("%s: error: read(%d) failed at %#llx\n",__func__,ops.retlen, addr);
goto out;
}
printk("%s: candidate for wifi mac=%02x:%02x:%02x:%02x:%02x:%02x\n",__func__,
sprintf(nvs_mac_addr, "macaddr=%02x:%02x:%02x:%02x:%02x:%02x\n",
iobuf[40],iobuf[41],iobuf[42],iobuf[43],iobuf[44],iobuf[45]);
pr_info("Device WiFi MAC Address: %s\n", nvs_mac_addr);
addr = ((loff_t) 505*0x20000 + 6*0x800);
ret = msm_nand_read_oob(mtd, addr, &ops);
@ -1874,9 +1876,11 @@ void scanmac(struct mtd_info *mtd)
printk("%s: error: read(%d) failed at %#llx\n",__func__,ops.retlen, addr);
goto out;
}
printk("%s: candidate for bluetooth mac=%02x:%02x:%02x:%02x:%02x:%02x\n",__func__,
iobuf[5],iobuf[4],iobuf[3],iobuf[2],iobuf[1],iobuf[0]);
// BT MAC for AOSP ROMs
sprintf(bdaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
iobuf[5],iobuf[4],iobuf[3],iobuf[2],iobuf[1],iobuf[0]);
pr_info("Device Bluetooth MAC Address: %s\n", bdaddr);
ret = 0;
out: