support realtek uart bt mac from flash
authorxxh <xxh@rock-chips.com>
Tue, 23 May 2017 07:55:45 +0000 (15:55 +0800)
committerXu Xuehui <xxh@rock-chips.com>
Tue, 23 May 2017 08:19:07 +0000 (16:19 +0800)
Change-Id: Ic3497eabf9f9b4fc5dcd5c3e66c4ed7d959da538

rtkbt/code/bt/btif/src/btif_core.c
rtkbt/code/libbt-vendor/uart/include/bt_vendor_rtk.h
rtkbt/code/libbt-vendor/uart/src/hardware.c

index fc99f193b87e03d76b9eff872f1bb6035321af24..665c5ae01852c679d947e6b74caae36950877d97 100755 (executable)
@@ -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))
     {
index 254606b6987212905ae3745c349644a72116163e..b75b994c6f60d6eea970b4c59e891ba45e5b2bf7 100755 (executable)
@@ -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
index d58f867916f73d03c3282c951959ba7a04a666c5..e9c47bfb030d467541b35119567802c3f2633ce5 100755 (executable)
@@ -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;
 }