OSDN Git Service

Read Bluetooth address from system property ro.bt.bdaddr_path
authorNick Pelly <npelly@google.com>
Wed, 21 Oct 2009 17:01:10 +0000 (10:01 -0700)
committerNick Pelly <npelly@google.com>
Wed, 21 Oct 2009 18:16:31 +0000 (11:16 -0700)
Change-Id: I1d308818099636354448708c8a7d4c13219f504d

brcm_patchram_plus/Android.mk
brcm_patchram_plus/brcm_patchram_plus.c

index 03dbe6b..3f4e8c7 100644 (file)
@@ -12,6 +12,8 @@ LOCAL_SRC_FILES := brcm_patchram_plus.c
 
 LOCAL_MODULE := brcm_patchram_plus
 
+LOCAL_SHARED_LIBRARIES := libcutils
+
 include $(BUILD_EXECUTABLE)
 
 endif
index e4bd55b..7875d37 100644 (file)
 **                 For Android, this program invoked using a 
 **                 "system(2)" call from the beginning of the bt_enable
 **                 function inside the file 
-**                 mydroid/system/bluetooth/bluedroid/bluetooth.c.
+**                 system/bluetooth/bluedroid/bluetooth.c.
 **
+**                 If the Android system property "ro.bt.bcm_bdaddr_path" is
+**                 set, then the bd_addr will be read from this path.
+**                 This is overridden by --bd_addr on the command line.
 **  
 ******************************************************************************/
 
@@ -71,6 +74,8 @@
 #include <string.h>
 #include <signal.h>
 
+#include <cutils/properties.h>
+
 #ifndef N_HCI
 #define N_HCI  15
 #endif
@@ -105,8 +110,7 @@ unsigned char hci_update_baud_rate[] = { 0x01, 0x18, 0xfc, 0x06, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00 };
 
 unsigned char hci_write_bd_addr[] = { 0x01, 0x01, 0xfc, 0x06, 
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00 };
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
 unsigned char hci_write_sleep_mode[] = { 0x01, 0x27, 0xfc, 0x0c, 
        0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
@@ -208,9 +212,9 @@ parse_bdaddr(char *optarg)
        int bd_addr[6];
        int i;
 
-       sscanf(optarg, "%02x%02x%02x%02x%02x%02x", 
-               &bd_addr[0], &bd_addr[1], &bd_addr[2],
-               &bd_addr[3], &bd_addr[4], &bd_addr[5]);
+       sscanf(optarg, "%02X:%02X:%02X:%02X:%02X:%02X",
+               &bd_addr[5], &bd_addr[4], &bd_addr[3],
+               &bd_addr[2], &bd_addr[1], &bd_addr[0]);
 
        for (i = 0; i < 6; i++) {
                hci_write_bd_addr[4 + i] = bd_addr[i];
@@ -499,9 +503,46 @@ proc_enable_hci()
        return;
 }
 
+void
+read_default_bdaddr()
+{
+       int sz;
+       int fd;
+       char path[PROPERTY_VALUE_MAX];
+       char bdaddr[18];
+
+       property_get("ro.bt.bdaddr_path", path, "");
+       if (path[0] == 0)
+               return;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0) {
+               fprintf(stderr, "open(%s) failed: %s (%d)", path, strerror(errno),
+                               errno);
+               return;
+       }
+
+       sz = read(fd, bdaddr, sizeof(bdaddr));
+       if (sz < 0) {
+               fprintf(stderr, "read(%s) failed: %s (%d)", path, strerror(errno),
+                               errno);
+               close(fd);
+               return;
+       } else if (sz != sizeof(bdaddr)) {
+               fprintf(stderr, "read(%s) unexpected size %d", path, sz);
+               close(fd);
+               return;
+       }
+
+       printf("Read default bdaddr of %s\n", bdaddr);
+       parse_bdaddr(bdaddr);
+}
+
 int
 main (int argc, char **argv)
 {
+       read_default_bdaddr();
+
        parse_cmd_line(argc, argv);
 
        if (uart_fd < 0) {