diff options
author | Steve Kondik <steve@cyngn.com> | 2015-04-03 10:01:36 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-04-03 10:01:36 -0700 |
commit | 46b0924bd81047a1dc40221ab41863d9c7394afe (patch) | |
tree | e56469c69526016e7e05dfb6311cb79299edfa45 | |
parent | 4e51c71101777f03fee8c437b9048878d9cf7524 (diff) | |
parent | 42bbdbd7ed2a2db670811f03a3ccdc4cb1df5696 (diff) | |
download | android_hardware_qcom_bt-stable/cm-12.1-YOG3C.tar.gz android_hardware_qcom_bt-stable/cm-12.1-YOG3C.tar.bz2 android_hardware_qcom_bt-stable/cm-12.1-YOG3C.zip |
Merge branch 'LA.BF64.1.2.1_rb2.6' of git://codeaurora.org/platform/hardware/qcom/bt into cm-12.1stable/cm-12.1-YOG3C
Change-Id: I24e18d22de213f84128d4536ac0d20a253c9afa6
-rw-r--r-- | libbt-vendor/Android.mk | 2 | ||||
-rw-r--r-- | libbt-vendor/src/bt_vendor_qcom.c | 72 |
2 files changed, 72 insertions, 2 deletions
diff --git a/libbt-vendor/Android.mk b/libbt-vendor/Android.mk index 32e3379..d45cbfb 100644 --- a/libbt-vendor/Android.mk +++ b/libbt-vendor/Android.mk @@ -67,6 +67,8 @@ LOCAL_CFLAGS += -DBT_NV_SUPPORT LOCAL_SHARED_LIBRARIES += libbtnv endif +#LOCAL_CFLAGS += -DREAD_BT_ADDR_FROM_PROP + include $(LOCAL_PATH)/vnd_buildcfg.mk include $(BUILD_SHARED_LIBRARY) diff --git a/libbt-vendor/src/bt_vendor_qcom.c b/libbt-vendor/src/bt_vendor_qcom.c index 1cb7bb2..e6bd805 100644 --- a/libbt-vendor/src/bt_vendor_qcom.c +++ b/libbt-vendor/src/bt_vendor_qcom.c @@ -25,6 +25,7 @@ ******************************************************************************/ #define LOG_TAG "bt_vendor" +#define BLUETOOTH_MAC_ADDR_BOOT_PROPERTY "ro.boot.btmacaddr" #include <utils/Log.h> #include <cutils/properties.h> @@ -529,7 +530,32 @@ static int init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr) return 0; } - +#ifdef READ_BT_ADDR_FROM_PROP +static bool validate_tok(char* bdaddr_tok) { + int i = 0; + bool ret; + + if (strlen(bdaddr_tok) != 2) { + ret = FALSE; + ALOGE("Invalid token length"); + } else { + ret = TRUE; + for (i=0; i<2; i++) { + if ((bdaddr_tok[i] >= '0' && bdaddr_tok[i] <= '9') || + (bdaddr_tok[i] >= 'A' && bdaddr_tok[i] <= 'F') || + (bdaddr_tok[i] >= 'a' && bdaddr_tok[i] <= 'f')) { + ret = TRUE; + ALOGV("%s: tok %s @ %d is good", __func__, bdaddr_tok, i); + } else { + ret = FALSE; + ALOGE("invalid character in tok: %s at ind: %d", bdaddr_tok, i); + break; + } + } + } + return ret; +} +#endif /*READ_BT_ADDR_FROM_PROP*/ int connect_to_local_socket(char* name) { socklen_t len; int sk = -1; @@ -584,6 +610,13 @@ static int op(bt_vendor_opcode_t opcode, void *param) bool is_ant_req = false; char wipower_status[PROPERTY_VALUE_MAX]; char bt_version[PROPERTY_VALUE_MAX]; + bool ignore_boot_prop = TRUE; +#ifdef READ_BT_ADDR_FROM_PROP + int i = 0; + static char bd_addr[PROPERTY_VALUE_MAX]; + uint8_t local_bd_addr_from_prop[6]; + char* tok; +#endif ALOGV("bt-vendor : op for %d", opcode); @@ -718,8 +751,43 @@ static int op(bt_vendor_opcode_t opcode, void *param) ALOGV("rome_soc_init is started"); property_set("wc_transport.soc_initialized", "0"); #ifdef BT_NV_SUPPORT +#ifdef READ_BT_ADDR_FROM_PROP + /*Give priority to read BD address from boot property*/ + ignore_boot_prop = FALSE; + if (property_get(BLUETOOTH_MAC_ADDR_BOOT_PROPERTY, bd_addr, NULL)) { + ALOGV("BD address read from Boot property: %s\n", bd_addr); + tok = strtok(bd_addr, ":"); + while (tok != NULL) { + ALOGV("bd add [%d]: %d ", i, strtol(tok, NULL, 16)); + if (i>=6) { + ALOGE("bd property of invalid length"); + ignore_boot_prop = TRUE; + break; + } + if (!validate_tok(tok)) { + ALOGE("Invalid token in BD address"); + ignore_boot_prop = TRUE; + break; + } + local_bd_addr_from_prop[5-i] = strtol(tok, NULL, 16); + tok = strtok(NULL, ":"); + i++; + } + if (i == 6 && !ignore_boot_prop) { + ALOGV("Valid BD address read from prop"); + memcpy(vnd_local_bd_addr, local_bd_addr_from_prop, sizeof(vnd_local_bd_addr)); + ignore_boot_prop = FALSE; + } else { + ALOGE("There are not enough tokens in BD addr"); + ignore_boot_prop = TRUE; + } + } else { + ALOGE("BD address boot property not set"); + ignore_boot_prop = TRUE; + } +#endif //READ_BT_ADDR_FROM_PROP /* Always read BD address from NV file */ - if(!bt_vendor_nv_read(1, vnd_local_bd_addr)) + if(ignore_boot_prop && !bt_vendor_nv_read(1, vnd_local_bd_addr)) { /* Since the BD address is configured in boot time We should not be here */ ALOGI("Failed to read BD address. Use the one from bluedroid stack/ftm"); |