From 4ab996301845782af40751c3ac3315ae3c6a29a2 Mon Sep 17 00:00:00 2001 From: xxh Date: Tue, 23 May 2017 15:55:45 +0800 Subject: [PATCH] support realtek uart bt mac from flash Change-Id: Ic3497eabf9f9b4fc5dcd5c3e66c4ed7d959da538 --- rtkbt/code/bt/btif/src/btif_core.c | 53 +++++++++---------- .../libbt-vendor/uart/include/bt_vendor_rtk.h | 2 +- rtkbt/code/libbt-vendor/uart/src/hardware.c | 33 +++++++----- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/rtkbt/code/bt/btif/src/btif_core.c b/rtkbt/code/bt/btif/src/btif_core.c index fc99f19..665c5ae 100755 --- a/rtkbt/code/bt/btif/src/btif_core.c +++ b/rtkbt/code/bt/btif/src/btif_core.c @@ -401,9 +401,33 @@ static void btif_fetch_local_bdaddr(bt_bdaddr_t *local_addr) char val[PROPERTY_VALUE_MAX] = {0}; uint8_t valid_bda = FALSE; int val_size = 0; - + int vflash_fd; const uint8_t null_bdaddr[BD_ADDR_LEN] = {0,0,0,0,0,0}; + if ((vflash_fd = open("/dev/vflash", O_RDONLY)) != -1) + { + char bd_addr[6] = {0}; + BTIF_TRACE_ERROR("Get local bdaddr from vflash"); + #define VFLASH_READ_BDA 0x01 + if(ioctl(vflash_fd, VFLASH_READ_BDA, (unsigned long)bd_addr) >= 0 + && memcmp(bd_addr, null_bdaddr, BD_ADDR_LEN) != 0) + { + local_addr->address[0] = bd_addr[5]; + local_addr->address[1] = bd_addr[4]; + local_addr->address[2] = bd_addr[3]; + local_addr->address[3] = bd_addr[2]; + local_addr->address[4] = bd_addr[1]; + local_addr->address[5] = bd_addr[0]; + //local_addr->address[0] = local_addr->address[0] << 1; + valid_bda = TRUE; + BTIF_TRACE_DEBUG("Got Factory BDA %02X:%02X:%02X:%02X:%02X:%02X", + local_addr->address[0], local_addr->address[1], local_addr->address[2], + local_addr->address[3], local_addr->address[4], local_addr->address[5]); + } + + close(vflash_fd); + } + if (!valid_bda) { int ret; char bd_addr[6] = {0}; @@ -441,33 +465,6 @@ static void btif_fetch_local_bdaddr(bt_bdaddr_t *local_addr) bt_addr_vendor_storage_read_or_write(1, bd_addr, 6); } } - - if (!valid_bda) {// cmy@2012-11-28: Get local bdaddr from vflash - int vflash_fd = open("/dev/vflash", O_RDONLY); - if (vflash_fd > 0) - { - char bd_addr[6] = {0}; - BTIF_TRACE_ERROR("Get local bdaddr from vflash"); - #define VFLASH_READ_BDA 0x01 - if(ioctl(vflash_fd, VFLASH_READ_BDA, (unsigned long)bd_addr) >= 0 - && memcmp(bd_addr, null_bdaddr, BD_ADDR_LEN) != 0) - { - local_addr->address[0] = bd_addr[5]; - local_addr->address[1] = bd_addr[4]; - local_addr->address[2] = bd_addr[3]; - local_addr->address[3] = bd_addr[2]; - local_addr->address[4] = bd_addr[1]; - local_addr->address[5] = bd_addr[0]; - - //local_addr->address[0] = local_addr->address[0] << 1; - valid_bda = TRUE; - BTIF_TRACE_ERROR("Got Factory BDA %02X:%02X:%02X:%02X:%02X:%02X", - local_addr->address[0], local_addr->address[1], local_addr->address[2], - local_addr->address[3], local_addr->address[4], local_addr->address[5]); - } - close(vflash_fd); - } - } /* Get local bdaddr storage path from property */ if (!valid_bda && osi_property_get(PROPERTY_BT_BDADDR_PATH, val, NULL)) { diff --git a/rtkbt/code/libbt-vendor/uart/include/bt_vendor_rtk.h b/rtkbt/code/libbt-vendor/uart/include/bt_vendor_rtk.h index 254606b..b75b994 100755 --- a/rtkbt/code/libbt-vendor/uart/include/bt_vendor_rtk.h +++ b/rtkbt/code/libbt-vendor/uart/include/bt_vendor_rtk.h @@ -78,7 +78,7 @@ * firmware patchram (.hcd) file. */ #ifndef USE_CONTROLLER_BDADDR -#define USE_CONTROLLER_BDADDR TRUE //FALSE +#define USE_CONTROLLER_BDADDR FALSE //FALSE #endif /* sleep mode diff --git a/rtkbt/code/libbt-vendor/uart/src/hardware.c b/rtkbt/code/libbt-vendor/uart/src/hardware.c index d58f867..e9c47bf 100755 --- a/rtkbt/code/libbt-vendor/uart/src/hardware.c +++ b/rtkbt/code/libbt-vendor/uart/src/hardware.c @@ -231,7 +231,7 @@ typedef struct /****************************************************************************** ** Externs ******************************************************************************/ - +static char mac_addr[6]={0}; void hw_config_cback(void *p_evt_buf); extern uint8_t vnd_local_bd_addr[BD_ADDR_LEN]; @@ -585,18 +585,18 @@ static int getmacaddr(unsigned char * addr) char data[256], *str; int addr_fd; - if ((addr_fd = open("/data/misc/bluetooth/bdaddr", O_RDONLY)) != -1) - { - memset(data, 0, sizeof(data)); - read(addr_fd, data, 17); - for (i = 0,str = data; i < 6; i++) { - addr[5-i] = (unsigned char)strtoul(str, &str, 16); - str++; - } - close(addr_fd); - return 0; - } +#if (USE_CONTROLLER_BDADDR == TRUE) return -1; +#else +// the mac in config is revert ,so we need revert + addr[0]=mac_addr[5]; + addr[1]=mac_addr[4]; + addr[2]=mac_addr[3]; + addr[3]=mac_addr[2]; + addr[4]=mac_addr[1]; + addr[5]=mac_addr[0]; + return 0; +#endif } static inline int getAltSettings(patch_info *patch_entry, unsigned short *offset, int max_group_cnt) @@ -766,7 +766,14 @@ uint32_t rtk_parse_config_file(unsigned char** config_buf, size_t* filelen, uint i += temp; entry = (struct rtk_bt_vendor_config_entry*)((uint8_t*)entry + temp); } - +#if (USE_CONTROLLER_BDADDR == FALSE) + ALOGE("rtk_parse_config_file : %02X:%02X:%02X:%02X:%02X:%02X", + bt_addr[0], bt_addr[1], + bt_addr[2], bt_addr[3], + bt_addr[4], bt_addr[5]); +//bt_addr normal + memcpy(mac_addr,bt_addr,6); +#endif return baudrate; } -- 2.20.1