diff options
author | Jessica Wagantall <jwagantall@cyngn.com> | 2016-04-19 14:52:01 -0700 |
---|---|---|
committer | Jessica Wagantall <jwagantall@cyngn.com> | 2016-04-19 14:52:01 -0700 |
commit | 5320f7cc30ffd6965c133283dfdd915b0eed873d (patch) | |
tree | 39cf490001ee53551df489339cc84eca8f4bf871 | |
parent | bdcf617f317d0bd16bf2b2d2bd7f295e4a89cd1b (diff) | |
parent | 3ddadd2c27e6a22e2d2b205e9ff73d13e0c35cc5 (diff) | |
download | android_system_bt-5320f7cc30ffd6965c133283dfdd915b0eed873d.tar.gz android_system_bt-5320f7cc30ffd6965c133283dfdd915b0eed873d.tar.bz2 android_system_bt-5320f7cc30ffd6965c133283dfdd915b0eed873d.zip |
Merge tag 'android-6.0.1_r30' into HEAD
Android 6.0.1 release 30
RM-234
Change-Id: Ib49a88726f2df18ca5ecf04fae4e2d2d31ef9a82
-rw-r--r-- | btif/src/bluetooth.c | 5 | ||||
-rw-r--r-- | device/include/interop.h | 14 | ||||
-rw-r--r-- | device/include/interop_database.h | 2 | ||||
-rw-r--r-- | device/src/interop.c | 120 | ||||
-rw-r--r-- | device/test/interop_test.cpp | 20 | ||||
-rw-r--r-- | main/bte_main.c | 5 |
6 files changed, 157 insertions, 9 deletions
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index 5563b8075..8c8a6cb39 100644 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c @@ -55,9 +55,10 @@ #include "btsnoop.h" #include "btsnoop_mem.h" #include "bt_utils.h" -#include "osi/include/osi.h" +#include "device/include/interop.h" #include "osi/include/allocation_tracker.h" #include "osi/include/log.h" +#include "osi/include/osi.h" #include "stack_manager.h" #include "btif_config.h" #include "l2cdefs.h" @@ -557,6 +558,8 @@ static const bt_interface_t bluetoothInterface = { #else NULL, #endif + interop_database_clear, + interop_database_add, }; const bt_interface_t* bluetooth__get_bluetooth_interface () diff --git a/device/include/interop.h b/device/include/interop.h index 48aaf9066..bc7a94324 100644 --- a/device/include/interop.h +++ b/device/include/interop.h @@ -22,11 +22,13 @@ #include "btcore/include/bdaddr.h" +static const char INTEROP_MODULE[] = "interop_module"; + typedef enum { // Disable secure connections // This is for pre BT 4.1/2 devices that do not handle secure mode // very well. - INTEROP_DISABLE_LE_SECURE_CONNECTIONS, + INTEROP_DISABLE_LE_SECURE_CONNECTIONS = 0, // Some devices have proven problematic during the pairing process, often // requiring multiple retries to complete pairing. To avoid degrading the user @@ -80,3 +82,13 @@ bool interop_name_match(const interop_feature_t feature, const char *addr); // where more information is not available. bool interop_manufacturer_match(const interop_feature_t feature, uint16_t manufacturer); +// are performed on |addr|. +bool interop_match(const interop_feature_t feature, const bt_bdaddr_t *addr); + +// Add a dynamic interop database entry for a device matching the first |length| bytes +// of |addr|, implementing the workaround identified by |feature|. |addr| may not be +// null and |length| must be greater than 0 and less than sizeof(bt_bdaddr_t). +void interop_database_add(const interop_feature_t feature, const bt_bdaddr_t *addr, size_t length); + +// Clear the dynamic portion of the interoperability workaround database. +void interop_database_clear(void); diff --git a/device/include/interop_database.h b/device/include/interop_database.h index c044db194..2abf326f6 100644 --- a/device/include/interop_database.h +++ b/device/include/interop_database.h @@ -22,7 +22,7 @@ typedef struct { bt_bdaddr_t addr; - uint8_t len; + size_t length; interop_feature_t feature; } interop_addr_t; diff --git a/device/src/interop.c b/device/src/interop.c index 32d819844..e8f32236e 100644 --- a/device/src/interop.c +++ b/device/src/interop.c @@ -21,13 +21,78 @@ #include <assert.h> #include <string.h> // For memcmp +#include "btcore/include/module.h" #include "device/include/interop.h" #include "device/include/interop_database.h" +#include "osi/include/allocator.h" +#include "osi/include/list.h" #include "osi/include/log.h" #define CASE_RETURN_STR(const) case const: return #const; -static const char* interop_feature_string(const interop_feature_t feature) { +static list_t *interop_list = NULL; + +static const char* interop_feature_string_(const interop_feature_t feature); +static void interop_free_entry_(void *data); +static void interop_lazy_init_(void); +static bool interop_match_fixed_(const interop_feature_t feature, const bt_bdaddr_t *addr); +static bool interop_match_dynamic_(const interop_feature_t feature, const bt_bdaddr_t *addr); + +// Interface functions + +bool interop_match(const interop_feature_t feature, const bt_bdaddr_t *addr) { + assert(addr); + + if (interop_match_fixed_(feature, addr) || interop_match_dynamic_(feature, addr)) { + char bdstr[20] = {0}; + LOG_WARN("%s() Device %s is a match for interop workaround %s.", + __func__, bdaddr_to_string(addr, bdstr, sizeof(bdstr)), + interop_feature_string_(feature)); + return true; + } + + return false; +} + +void interop_database_add(const interop_feature_t feature, const bt_bdaddr_t *addr, size_t length) { + assert(addr); + assert(length > 0); + assert(length < sizeof(bt_bdaddr_t)); + + interop_addr_t *entry = osi_calloc(sizeof(interop_addr_t)); + memcpy(&entry->addr, addr, length); + entry->feature = feature; + entry->length = length; + + interop_lazy_init_(); + list_append(interop_list, entry); +} + +void interop_database_clear() { + if (interop_list) + list_clear(interop_list); +} + +// Module life-cycle functions + +static future_t *interop_clean_up(void) { + list_free(interop_list); + interop_list = NULL; + return future_new_immediate(FUTURE_SUCCESS); +} + +const module_t interop_module = { + .name = INTEROP_MODULE, + .init = NULL, + .start_up = NULL, + .shut_down = NULL, + .clean_up = interop_clean_up, + .dependencies = {NULL}, +}; + +// Local functions + +static const char* interop_feature_string_(const interop_feature_t feature) { switch (feature) { CASE_RETURN_STR(INTEROP_DISABLE_LE_SECURE_CONNECTIONS) CASE_RETURN_STR(INTEROP_AUTO_RETRY_PAIRING) @@ -41,7 +106,10 @@ static const char* interop_feature_string(const interop_feature_t feature) { return "UNKNOWN"; } -// Interface functions +static void interop_free_entry_(void *data) { + interop_addr_t *entry = (interop_addr_t *)data; + osi_free(entry); +} bool interop_addr_match(const interop_feature_t feature, const bt_bdaddr_t *addr) { assert(addr); @@ -50,10 +118,50 @@ bool interop_addr_match(const interop_feature_t feature, const bt_bdaddr_t *addr for (size_t i = 0; i != db_size; ++i) { if (feature == interop_addr_database[i].feature && - memcmp(addr, &interop_addr_database[i].addr, interop_addr_database[i].len) == 0) { + memcmp(addr, &interop_addr_database[i].addr, interop_addr_database[i].length) == 0) { char bdstr[20] = {0}; LOG_WARN("%s() Device %s is a match for interop addr workaround %s", __func__, - bdaddr_to_string(addr, bdstr, sizeof(bdstr)), interop_feature_string(feature)); + bdaddr_to_string(addr, bdstr, sizeof(bdstr)), interop_feature_string_(feature)); + return true; + } + } + + return false; +} + +static void interop_lazy_init_(void) { + if (interop_list == NULL) { + interop_list = list_new(interop_free_entry_); + } +} + +static bool interop_match_dynamic_(const interop_feature_t feature, const bt_bdaddr_t *addr) { + if (interop_list == NULL || list_length(interop_list) == 0) + return false; + + const list_node_t *node = list_begin(interop_list); + while (node != list_end(interop_list)) { + interop_addr_t *entry = list_node(node); + assert(entry); + + if (feature == entry->feature && memcmp(addr, &entry->addr, entry->length) == 0) + return true; + + node = list_next(node); + } + return false; +} + +static bool interop_match_fixed_(const interop_feature_t feature, const bt_bdaddr_t *addr) { + assert(addr); + + const size_t db_size = sizeof(interop_addr_database) / sizeof(interop_addr_t); + for (size_t i = 0; i != db_size; ++i) { + if (feature == interop_addr_database[i].feature && + memcmp(addr, &interop_addr_database[i].addr, interop_addr_database[i].length) == 0) { + char bdstr[20] = {0}; + LOG_WARN("%s() Device %s is a match for interop workaround %s", __func__, + bdaddr_to_string(addr, bdstr, sizeof(bdstr)), interop_feature_string_(feature)); return true; } } @@ -71,7 +179,7 @@ bool interop_name_match(const interop_feature_t feature, const char *name) { strncmp(name, interop_name_database[i].name, strlen(name)) == 0) { char bdstr[20] = {0}; LOG_WARN("%s() Device with name: %s is a match for interop name workaround %s", __func__, - name, interop_feature_string(feature)); + name, interop_feature_string_(feature)); return true; } } @@ -89,7 +197,7 @@ bool interop_manufacturer_match(const interop_feature_t feature, uint16_t manufa manufacturer == interop_manufctr_database[i].manufacturer) { char bdstr[20] = {0}; LOG_WARN("%s() Device with manufacturer id: %d is a match for interop manufacturer " - "workaround %s", __func__, manufacturer, interop_feature_string(feature)); + "workaround %s", __func__, manufacturer, interop_feature_string_(feature)); return true; } } diff --git a/device/test/interop_test.cpp b/device/test/interop_test.cpp index 2be436f97..9ad0a49a8 100644 --- a/device/test/interop_test.cpp +++ b/device/test/interop_test.cpp @@ -42,3 +42,23 @@ TEST(InteropTest, test_lookup_miss) { EXPECT_FALSE(interop_addr_match(INTEROP_AUTO_RETRY_PAIRING, &test_address)); } +TEST(InteropTest, test_dynamic) { + bt_bdaddr_t test_address; + + string_to_bdaddr("11:22:33:44:55:66", &test_address); + EXPECT_FALSE(interop_match(INTEROP_DISABLE_LE_SECURE_CONNECTIONS, &test_address)); + + interop_database_add(INTEROP_DISABLE_LE_SECURE_CONNECTIONS, &test_address, 3); + EXPECT_TRUE(interop_match(INTEROP_DISABLE_LE_SECURE_CONNECTIONS, &test_address)); + EXPECT_FALSE(interop_match(INTEROP_AUTO_RETRY_PAIRING, &test_address)); + + string_to_bdaddr("66:55:44:33:22:11", &test_address); + EXPECT_FALSE(interop_match(INTEROP_AUTO_RETRY_PAIRING, &test_address)); + + interop_database_add(INTEROP_AUTO_RETRY_PAIRING, &test_address, 3); + EXPECT_TRUE(interop_match(INTEROP_AUTO_RETRY_PAIRING, &test_address)); + EXPECT_FALSE(interop_match(INTEROP_DISABLE_LE_SECURE_CONNECTIONS, &test_address)); + + interop_database_clear(); + EXPECT_FALSE(interop_match(INTEROP_AUTO_RETRY_PAIRING, &test_address)); +} diff --git a/main/bte_main.c b/main/bte_main.c index 648e46cd1..bd0e65c6e 100644 --- a/main/bte_main.c +++ b/main/bte_main.c @@ -45,6 +45,9 @@ #include "bt_utils.h" #include "btcore/include/counter.h" #include "btcore/include/module.h" +#include "device/include/interop.h" +#include "hci_layer.h" +#include "osi/include/alarm.h" #include "osi/include/fixed_queue.h" #include "osi/include/future.h" #include "gki.h" @@ -97,6 +100,7 @@ void bte_main_boot_entry(void) { module_init(get_module(GKI_MODULE)); module_init(get_module(COUNTER_MODULE)); + module_init(get_module(INTEROP_MODULE)); hci = hci_layer_get_interface(); if (!hci) @@ -136,6 +140,7 @@ void bte_main_shutdown() module_clean_up(get_module(STACK_CONFIG_MODULE)); + module_clean_up(get_module(INTEROP_MODULE)); module_clean_up(get_module(COUNTER_MODULE)); module_clean_up(get_module(GKI_MODULE)); } |