drivers: mtd: devices: htcleo_nand: find the real unique WiFi and Bluetooth MAC addresses.

(Credits go to Franck78 <fbourdonnec@chez.com>)

http://forum.xda-developers.com/showpost.php?p=26556691&postcount=3
This commit is contained in:
tytung 2012-06-01 00:21:07 +08:00 committed by milaq
parent 44f4738129
commit 4548f8ea32

View File

@ -1835,6 +1835,116 @@ static int param_get_page_size(char *buffer, struct kernel_param *kp)
}
module_param_call(pagesize, NULL, param_get_page_size, NULL, S_IRUGO);
int is_htc_mac (int pattern)
{
/* HTC blocks to find :
00:09:2D
00:23:76
18:87:76
1C:B0:94
38:E7:D8
64:A7:69
7C:61:93
90:21:55
A0:F4:50
A8:26:D9
D4:20:6D
D8:B3:77
E8:99:C4
F8:DB:F7 */
static int nums[] = {
0x00092D,0x2D0900,
0x002376,0x762300,
0x188776,0x768718,
0x1CB094,0x94B01C,
0x38E7D8,0xD8E738,
0x64A769,0x69A764,
0x7C6193,0x93617C,
0x902155,0x552190,
0xA0F450,0x50F4A0,
0xA826D9,0xD926A8,
0xD4206D,0x6D20D4,
0xD8B377,0x77B3D8,
0xE899C4,0xC499E8,
0xF8DBF7,0xF7DBF8};
int i;
for (i=0; i< (sizeof(nums)/sizeof(nums[0])); i++) {
if (nums[i] == pattern) return 1;
}
return 0;
}
void scanmac(struct mtd_info *mtd)
{
unsigned char *iobuf;
int ret;
loff_t addr;
struct mtd_oob_ops ops;
int i,j,k;
iobuf = kmalloc(2048/*mtd->erasesize*/, GFP_KERNEL);
if (!iobuf) {
/*ret = -ENOMEM;*/
printk("%s: error: cannot allocate memory\n",__func__);
return;
}
ops.mode = MTD_OOB_PLACE;
ops.len = 2048;
ops.datbuf = iobuf;
ops.ooblen = 0;
ops.oobbuf = NULL;
ops.retlen = 0;
/* block 505 page 6 contains as good candidate */
addr = ((loff_t) 505*0x20000 + 6*2048);
ret = msm_nand_read_oob(mtd, addr, &ops);
if (ret == -EUCLEAN)
ret = 0;
if (ret || ops.retlen != 2048 ) {
printk("%s: error: read(%d) failed at %#llx\n",__func__,ops.retlen, addr);
goto out;
}
printk("%s: Prefered candidate mac=%02x:%02x:%02x:%02x:%02x:%02x\n",__func__,
iobuf[5],iobuf[4],iobuf[3],iobuf[2],iobuf[1],iobuf[0]);
/* now lets walk looking for HTC mac in the first reserved blocks of NAND */
/* NUM_PROTECTED_BLOCKS=0x212 but Parttiontable starts at 0x219 */
/* I think 400 is ok, I have already eliminated 0 - 157 with false positive */
/* If my guess is correct, only 505 will match ;-) */
for (i=158; i<0x219; i++) {
for (j=0; j<64; j++) {
addr = ((loff_t) i*0x20000 + j*2048);
ret = msm_nand_read_oob(mtd, addr, &ops);
if (ret == -EUCLEAN)
ret = 0;
if (ret || ops.retlen != 2048 ) {
printk("%s: error: read(%d) failed at %#llx\n",__func__,ops.retlen, addr);
break;
}
/* check */
for (k=0; k<2045; k++) {
if (is_htc_mac( (iobuf[k+0]<<16) + (iobuf[k+1]<<8) + iobuf[k+2])) {
printk("Mac candidate at block:%d page:%d offset:%d:\n",i,j,k);
k >>= 4;
k <<= 4;
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, &iobuf[k], 16);
k += 16;
}
}
}/*j*/
}/*i*/
ret = 0;
out:
kfree(iobuf);
if (ret)
printk("Find MAc Error %d occurred\n", ret);
return;
}
/**
* msm_nand_scan - [msm_nand Interface] Scan for the msm_nand device
* @param mtd MTD device structure
@ -2000,6 +2110,7 @@ int msm_nand_scan(struct mtd_info *mtd, int maxchips)
/* msm_nand_unlock_all(mtd); */
/* return this->scan_bbt(mtd); */
scanmac(mtd);
#if VERBOSE
for (i=0;i<nand_info->block_count;i++)